@flexkit/studio 0.0.28 → 0.0.30

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 (61) hide show
  1. package/dist/asset-TS7J5GA5.js +2 -0
  2. package/dist/{asset-REAMGMQL.js.map → asset-TS7J5GA5.js.map} +1 -1
  3. package/dist/chunk-73RMWG53.js +2 -0
  4. package/dist/{chunk-X3S7TRCM.js.map → chunk-73RMWG53.js.map} +1 -1
  5. package/dist/chunk-DWK4NNLB.js +2 -0
  6. package/dist/chunk-DWK4NNLB.js.map +1 -0
  7. package/dist/chunk-FVFRTCEB.js +2 -0
  8. package/dist/chunk-FVFRTCEB.js.map +1 -0
  9. package/dist/chunk-HAQICAOQ.js +2 -0
  10. package/dist/chunk-HAQICAOQ.js.map +1 -0
  11. package/dist/chunk-IXO2LU47.js +2 -0
  12. package/dist/{chunk-TBCSVE5L.js.map → chunk-IXO2LU47.js.map} +1 -1
  13. package/dist/{chunk-NNRD7YZU.js → chunk-LL2Z4TD3.js} +2 -2
  14. package/dist/{chunk-NNRD7YZU.js.map → chunk-LL2Z4TD3.js.map} +1 -1
  15. package/dist/chunk-MC6VZLKC.js +2 -0
  16. package/dist/chunk-MC6VZLKC.js.map +1 -0
  17. package/dist/chunk-N52AF6GE.js +2 -0
  18. package/dist/chunk-N52AF6GE.js.map +1 -0
  19. package/dist/chunk-WXMCINGZ.js +2 -0
  20. package/dist/{chunk-27Y2SQ67.js.map → chunk-WXMCINGZ.js.map} +1 -1
  21. package/dist/chunk-YA4ACPM5.js +2 -0
  22. package/dist/{chunk-KR7CLPY2.js.map → chunk-YA4ACPM5.js.map} +1 -1
  23. package/dist/index.css +814 -42
  24. package/dist/index.d.ts +39 -4
  25. package/dist/index.js +196 -194
  26. package/dist/index.js.map +1 -1
  27. package/dist/{search-YRDOJUQO.js → search-UFFZBRQV.js} +2 -2
  28. package/dist/{search-YRDOJUQO.js.map → search-UFFZBRQV.js.map} +1 -1
  29. package/dist/switch-AFZGXSR3.js +2 -0
  30. package/dist/{switch-KVO3JRNX.js.map → switch-AFZGXSR3.js.map} +1 -1
  31. package/dist/text-2RL2L5FT.js +2 -0
  32. package/dist/{text-ODG7ABSW.js.map → text-2RL2L5FT.js.map} +1 -1
  33. package/dist/textarea-2A4TLWZS.js +2 -0
  34. package/dist/{textarea-M4YPSJEC.js.map → textarea-2A4TLWZS.js.map} +1 -1
  35. package/dist/{types.d-DiQPwK_q.d.ts → types.d-CX3kDxFZ.d.ts} +45 -4
  36. package/dist/ui.d.ts +467 -4
  37. package/dist/ui.js +6 -1
  38. package/dist/ui.js.map +1 -1
  39. package/dist/user-nav-4JKIFZLB.js +2 -0
  40. package/dist/user-nav-4JKIFZLB.js.map +1 -0
  41. package/package.json +17 -1
  42. package/dist/asset-REAMGMQL.js +0 -2
  43. package/dist/chunk-27Y2SQ67.js +0 -2
  44. package/dist/chunk-AALMEPYG.js +0 -2
  45. package/dist/chunk-AALMEPYG.js.map +0 -1
  46. package/dist/chunk-CWHDJ7Q4.js +0 -2
  47. package/dist/chunk-CWHDJ7Q4.js.map +0 -1
  48. package/dist/chunk-KR7CLPY2.js +0 -2
  49. package/dist/chunk-M5AH5ERI.js +0 -2
  50. package/dist/chunk-M5AH5ERI.js.map +0 -1
  51. package/dist/chunk-QXCD5JR4.js +0 -2
  52. package/dist/chunk-QXCD5JR4.js.map +0 -1
  53. package/dist/chunk-TBCSVE5L.js +0 -2
  54. package/dist/chunk-X3S7TRCM.js +0 -2
  55. package/dist/chunk-ZSJAPCIZ.js +0 -2
  56. package/dist/chunk-ZSJAPCIZ.js.map +0 -1
  57. package/dist/switch-KVO3JRNX.js +0 -2
  58. package/dist/text-ODG7ABSW.js +0 -2
  59. package/dist/textarea-M4YPSJEC.js +0 -2
  60. package/dist/user-nav-QYO4X7CQ.js +0 -2
  61. package/dist/user-nav-QYO4X7CQ.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,104 +1,97 @@
1
- import'./index.css';import {a as a$2}from'./chunk-27Y2SQ67.js';import {a as a$1}from'./chunk-KR7CLPY2.js';import {a as a$a}from'./chunk-D4XLXU2H.js';import {a as a$c}from'./chunk-CWHDJ7Q4.js';import {a as a$9}from'./chunk-CPUC4QXH.js';import {a,b as b$7}from'./chunk-EOCJR5EY.js';import {a as a$d}from'./chunk-R7N3MDOP.js';import {a as a$b}from'./chunk-W3TUEJJL.js';import'./chunk-ZEZ6TRCO.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-ZSJAPCIZ.js';import {a as a$6}from'./chunk-7GBAYC7G.js';import'./chunk-OEWYLKO7.js';import {a as a$7,b as b$5,c as c$4,e as e$3}from'./chunk-YW2EEXMV.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-XU2JGXYC.js';import {d as d$2,c as c$2,b as b$9,a as a$i,e as e$5}from'./chunk-WZ533Y4O.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-WZ533Y4O.js';import {v,b as b$6,m as m$2,o,p,r,t,s,q}from'./chunk-NNRD7YZU.js';import {b as b$a,a as a$j}from'./chunk-M5AH5ERI.js';export{b as useAuth}from'./chunk-M5AH5ERI.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$h,l as l$1,i as i$2,b as b$c,r as r$1}from'./chunk-TBCSVE5L.js';import {d,b as b$8,a as a$f,e as e$4,c as c$6}from'./chunk-V6R4AWQS.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-V6R4AWQS.js';import {b as b$4,c as c$5,a as a$l}from'./chunk-WDRCARCP.js';export{b as IMAGES_BASE_URL}from'./chunk-WDRCARCP.js';import {b as b$3,a as a$8}from'./chunk-EYGOJ2ZN.js';import {a as a$g,b as b$b}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-X3S7TRCM.js';import {b as b$2,a as a$e}from'./chunk-QXCD5JR4.js';export{b as DefaultValueSwitch}from'./chunk-QXCD5JR4.js';import'./chunk-KGYH74NA.js';import {b,c,e,f,h,g,i,a as a$k}from'./chunk-AALMEPYG.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as gn from'react';import {lazy,createContext,memo,forwardRef,useMemo,useRef,useEffect,useImperativeHandle,createElement,useId,useState,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,uniq,omit,pick,toPairs,props}from'ramda';import Al,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,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,PencilIcon,Trash2Icon,Settings2,RefreshCw,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 tn from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,NetworkStatus,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 mr 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 iu from'react-markdown';import {useReactTable,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 Yo(){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 en(){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 El=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 de({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(El({variant:t}),e),...o})}function Le({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 ue({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 Fl=tn.object({email:tn.email({error:"Please enter a valid email address"})});function Hn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Fl),defaultValues:{email:""}}),f=new URL(c$5(e$1).loginOtpSend,a$l),{data:c$1,error:d,isLoading:m}=Al(r?f.href:null,v=>fetch(v,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(h=>h.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),l=c$1&&"error"in c$1&&c$1.error.code,u=c$1&&"token"in c$1,g$1=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!u)return;let v=0,h=setInterval(()=>{if(v>100){clearInterval(h),n(true);return}let x=new URL(c$5(e$1).loginOtpConfirm,a$l),b="/api/flexkit/set-token";fetch(`${x.href}?email=${s.getValues("email")}&token=${g$1}`).then(w=>{w.status===200&&w.json().then(T=>{fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:T.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),v++;},3e3);return ()=>{clearInterval(h);}},[s,u,e$1,g$1]);function p(){n(false),i$1(true),a(f.href);}return jsx("div",{className:"fk:w-full",children:u?jsx(de,{variant:"default",children:jsxs(ue,{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:v=>{s.handleSubmit(p)(v);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[l==="not_exists"&&jsx(de,{variant:"destructive",children:jsxs(ue,{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?"})]})}),l==="unknown_error"||d?jsx(de,{variant:"destructive",children:jsxs(ue,{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(de,{variant:"destructive",children:jsxs(ue,{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:v})=>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",...v})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":m,className:"fk:w-full",type:"submit",disabled:!!m,children:[m?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function $i({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}=Al(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(v=>v.json())),[c,d$2]=b$a(),m=new Date().getFullYear(),l=useLocation(),u=l.state?.from?.pathname??l.pathname,g=u.includes(o.projectId)?`${location.origin}${u}`:`${location.origin}${b$b(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return f||c||!a?jsx(en,{}):d$2.user?.id?jsx(Navigate,{replace:true,state:{from:l},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center 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$k,{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(v=>v.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(Hn,{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:$l({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 ",m]})]}),jsx(Yo,{})]})})]})}function $l({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 _l=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Ol={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"},on=class e extends Error{code;constructor(t,o){super(o??Ol[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 qn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:_l.includes(t)}function _i(e){if(qn(e))return e.code}function zi({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),f=useRef(null),c=useLocation(),{projectId:d}=useParams(),m$1=e.find(u=>c.pathname.includes(`/${d}/${u.name}`))?.name,l=e.find(u=>c.pathname.includes(`/${d}/${u.name}`))?.name??e[0]?.name;return useEffect(()=>{if(f.current===null)return;let u=new ResizeObserver(()=>{n(f.current?.offsetHeight??0);});return u.observe(f.current),function(){u.disconnect();}},[m$1]),useEffect(()=>{let u=Math.floor(o/48)-2,g=e.slice(0,u);if(!g.find(v=>v.name===l)){let v=e.find(h=>h.name===l);g.pop(),v&&g.push(v);}let p=e.filter(v=>!g.includes(v));i(g),s(p);},[e,l,o]),m$1===void 0&&l?jsx(Navigate,{to:`${c.pathname}/${l}`}):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(u=>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:u.name,children:u.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:u.title})})]})},u.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(u=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:u.name,children:u.title})},u.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/*/${d}`,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 Gl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-X6YVZYKL.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-YRDOJUQO.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-QYO4X7CQ.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-KVO3JRNX.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-ODG7ABSW.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-M4YPSJEC.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-REAMGMQL.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-6F4QTCNT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-YIRZQR3D.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-NQTYGZIC.js').then(({DateTime:e})=>({default:e}))),"previewFields.select":lazy(()=>import('./select-A6I27JQU.js').then(({Select:e})=>({default:e})))};function xo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=Gl[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function Hi({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=xo("navbar.logo"),r=xo("navbar.projectSelector"),i=xo("navbar.search"),a=xo("navbar.userNav"),s=t.find(l=>l.projectId===e)??t[0],{basePath:f,schema:c}=s,d=useNavigate();function m(l){startTransition(()=>{d(b$b(f,e,"desk","list",l.entityNamePlural)+`?id=${l.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-[3.5rem] fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:m,projectId:e,schema:c})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function qi({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 on("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:f}=t,c=d$2(),d$1=useLocation();return useEffect(()=>{if(s){let m=s.find(u=>u.isDefault)||s[0],l="";typeof localStorage<"u"&&(l=localStorage.getItem(`${a$i}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:l||m.name}});}},[d$1]),n?jsx(en,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(Hi,{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(zi,{apps:f,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx($i,{projectId:i??""})}function Xi(e){return e?"cause"in e:false}function _t(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 Qi(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Ot(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function rn(e){if(!e)return null;let t=ac(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 ac(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ji).map(({message:r})=>r);let t=Qi(e);if(t&&Eo(t))return [t];let o=_t(e);if(o?.statusCode!==400)return [];let n=Ot(o.bodyText)??sc(o)??lc(e);return n?Array.isArray(n.errors)?n.errors.filter(Ji).map(r=>r.message):typeof n.message=="string"&&Eo(n.message)?[n.message]:typeof n.error=="string"&&Eo(n.error)?[n.error]:[]:[]}function sc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function lc(e){if(!Xi(e))return null;let{cause:t}=e,o=Qi(t);if(o&&Eo(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function Ji(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"&&Eo(o)}function Eo(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var wc=ApolloProvider,Zi=createContext(void 0);function Vt(){let e=useContext(Zi);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function Cc(e){return new ErrorLink(({error:t})=>{let o=rn(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=_t(t);if(n?.statusCode===400){let r=Ot(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[c]=s;if(c&&typeof c.message=="string"){let{message:d}=c;i=d;}}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 xc(e,t){return from([Cc(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Ec(e,t){return new ApolloClient({link:xc(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Ki({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]),i=useMemo(()=>Ec(t,n),[t]);return jsx(Zi.Provider,{value:r,children:jsx(wc,{client:i,children:e})})}function Yi({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function Xn({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Sc({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 ea({className:e,size:t="default",...o}){return jsxs(Xn,{children:[jsx(Sc,{}),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 ta({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 oa({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 na({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 ra({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 ia({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 aa({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 So({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 c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{a(true),o(false),r(false);}}return jsx(Yi,{onOpenChange:s,open:t,children:jsx(Xn,{children:jsxs(ea,{className:"sm:max-w-[425px]",children:[jsxs(ta,{children:[jsx(na,{children:e.dialogTitle}),jsx(ra,{children:e.dialogMessage})]}),jsxs(oa,{children:[jsx(aa,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(ia,{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 fa=createContext([]),da=createContext(()=>{});function Pc(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 ua({children:e}){let[t,o]=useReducer(Pc,[]);return jsx(fa.Provider,{value:t,children:jsx(da.Provider,{value:o,children:e})})}function ma(){return useContext(fa)}function ae(){return useContext(da)}function ut(){let[e,t]=useState(false),[o,n]=useState(gql`
1
+ import'./index.css';import {a as a$2}from'./chunk-WXMCINGZ.js';import {a as a$1}from'./chunk-YA4ACPM5.js';import {a as a$b}from'./chunk-D4XLXU2H.js';import {a as a$d}from'./chunk-N52AF6GE.js';import {a as a$a}from'./chunk-CPUC4QXH.js';import {a,b as b$7}from'./chunk-EOCJR5EY.js';import {a as a$e}from'./chunk-R7N3MDOP.js';import {a as a$c}from'./chunk-W3TUEJJL.js';import'./chunk-ZEZ6TRCO.js';import {i as i$1,k,g as g$3,l,m as m$1,p,q,n,r,u,f as f$3,c as c$7,d as d$3,h as h$2}from'./chunk-MC6VZLKC.js';import {a as a$7}from'./chunk-7GBAYC7G.js';import'./chunk-OEWYLKO7.js';import {a as a$8,b as b$5,c as c$4,e as e$3}from'./chunk-YW2EEXMV.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$2,f as f$1,g as g$1}from'./chunk-XU2JGXYC.js';import {d as d$2,c as c$2,b as b$9,a as a$i,e as e$5}from'./chunk-WZ533Y4O.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-WZ533Y4O.js';import {v,b as b$6,m as m$2,o,p as p$1,r as r$1,t,s,q as q$1}from'./chunk-LL2Z4TD3.js';import {b,a as a$j}from'./chunk-DWK4NNLB.js';export{b as useAuth}from'./chunk-DWK4NNLB.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$h,l as l$1,i as i$2,b as b$b,r as r$2}from'./chunk-IXO2LU47.js';import {d,a as a$f,b as b$8,e as e$4,c as c$6}from'./chunk-V6R4AWQS.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-V6R4AWQS.js';import {b as b$4,c as c$5,a as a$l}from'./chunk-WDRCARCP.js';export{b as IMAGES_BASE_URL}from'./chunk-WDRCARCP.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-73RMWG53.js';import {a as a$6}from'./chunk-HAQICAOQ.js';export{a as DefaultValueSwitch}from'./chunk-HAQICAOQ.js';import'./chunk-KGYH74NA.js';import {b as b$1,c,e,f,h,g,i,j,a as a$k}from'./chunk-FVFRTCEB.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as Do from'react';import {lazy,createContext,memo,forwardRef,useMemo,useRef,useEffect,useImperativeHandle,createElement,useId,useState,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,uniq,omit,pick,toPairs,props}from'ramda';import Dl,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,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,PencilIcon,Trash2Icon,Settings2,RefreshCw,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 fo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,NetworkStatus,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 {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import Dr 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 rd from'react-markdown';import {useReactTable,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 lo(){let[e,t]=useState(false),{theme:n,setTheme:o}=b$b();return useEffect(()=>{t(true);},[]),e?jsxs(c$7,{size:"sm",type:"single",value:n,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{o("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{o("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{o("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function co(){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 Tl=cva("fk:relative fk:w-full fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:[&>svg~*]:pl-7 fk:[&>svg+div]:translate-y-[-3px] fk:[&>svg]:absolute fk:[&>svg]:left-4 fk:[&>svg]:top-4 fk:[&>svg]:text-foreground",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:border-none fk:text-destructive fk:bg-destructive-foreground fk:[&>svg]:text-destructive"}},defaultVariants:{variant:"default"}});function ke({className:e,variant:t,...n}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(Tl({variant:t}),e),...n})}function ze({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 he({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:text-sm fk:[&_p]:leading-relaxed",e),...t})}var $l=fo.object({email:fo.email({error:"Please enter a valid email address"})});function ar({projectId:e$1,setIsEmailLogin:t}){let[n,o]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver($l),defaultValues:{email:""}}),l=new URL(c$5(e$1).loginOtpSend,a$l),{data:c$1,error:f,isLoading:m}=Dl(r?l.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}),u=c$1&&"error"in c$1&&c$1.error.code,p=c$1&&"token"in c$1,d=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!p)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),o(true);return}let C=new URL(c$5(e$1).loginOtpConfirm,a$l),v="/api/flexkit/set-token";fetch(`${C.href}?email=${encodeURIComponent(s.getValues("email"))}&token=${encodeURIComponent(d)}`).then(b=>{b.status===200&&b.json().then(D=>{fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:D.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,p,e$1,d]);function g$1(){o(false),i$1(true),a(l.href);}return jsx("div",{className:"fk:w-full",children:p?jsx(ke,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(he,{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:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b$1,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(g$1)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[u==="not_exists"&&jsx(ke,{variant:"destructive",children:jsxs(he,{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=${encodeURIComponent(s.getValues("email"))}`,children:"Sign up?"})]})}),u==="unknown_error"||f?jsx(ke,{variant:"destructive",children:jsxs(he,{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,n?jsx(ke,{variant:"destructive",children:jsxs(he,{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$7,{"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":m,className:"fk:w-full",type:"submit",disabled:!!m,children:[m?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function Zi({projectId:e}){let{projects:t}=d(),[n,o]=useState(t.find(g=>g.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:l}=Dl(c$5(e).authProviders,g=>fetch(g,{mode:"cors"}).then(h=>h.json())),[c,f]=b(),m=new Date().getFullYear(),u=useLocation(),p=u.state?.from?.pathname??u.pathname,d$2=p.includes(n.projectId)?`${location.origin}${p}`:`${location.origin}${b$a(n.basePath,n.projectId)}`;if(s)throw new Error("Error fetching auth providers");return l||c||!a?jsx(co,{}):f.user?.id?jsx(Navigate,{replace:true,state:{from:u},to:n.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$k,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:n.projectId,onValueChange:g=>{o(t.find(h=>h.projectId===g)??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":n.title,children:n.title})}),jsx(e$1,{children:t.map(g=>jsx(g$1,{value:g.projectId,children:g.title},g.projectId))})]})]}):null,r?jsx(ar,{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(g=>jsx(b$3,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:Vl({url:g.url,projectId:n.projectId,basePath:"/api/flexkit/get-token",fromPath:d$2}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.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 ",m]})]}),jsx(lo,{})]})})]})}function Vl({projectId:e,url:t,basePath:n,fromPath:o}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${n}`),r.set("projectId",e),r.set("redirect",o),`${t}?${r.toString()}`}var Bl=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],zl={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"},uo=class e extends Error{code;constructor(t,n){super(n??zl[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,n){return new e(t,n)}};function sr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Bl.includes(t)}function Ki(e){if(sr(e))return e.code}function na({apps:e,version:t}){let[n,o]=useState(0),[r,i]=useState(e),[a,s]=useState([]),l=useRef(null),c=useLocation(),{projectId:f}=useParams(),m$1=e.find(p=>c.pathname.includes(`/${f}/${p.name}`))?.name,u=e.find(p=>c.pathname.includes(`/${f}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(l.current===null)return;let p=new ResizeObserver(()=>{o(l.current?.offsetHeight??0);});return p.observe(l.current),function(){p.disconnect();}},[m$1]),useEffect(()=>{let p=Math.floor(n/48)-2,d=e.slice(0,p);if(!d.find(h=>h.name===u)){let h=e.find(y=>y.name===u);d.pop(),h&&d.push(h);}let g=e.filter(h=>!d.includes(h));i(d),s(g);},[e,u,n]),m$1===void 0&&u?jsx(Navigate,{to:`${c.pathname}/${u}`}):jsx(a$8,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:l,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$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:p.name,children:p.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:p.title})})]})},p.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(p=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.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/*/${f}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(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 Kl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-X6YVZYKL.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-UFFZBRQV.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-4JKIFZLB.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-AFZGXSR3.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-2RL2L5FT.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-2A4TLWZS.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-TS7J5GA5.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-6F4QTCNT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-YIRZQR3D.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-NQTYGZIC.js').then(({DateTime:e})=>({default:e}))),"previewFields.select":lazy(()=>import('./select-A6I27JQU.js').then(({Select:e})=>({default:e})))};function Dn(e){let{getContributionPointConfig:t}=d(),[n,...o]=e.split("."),r=Kl[e],i=t(n,o);return i?.length>0?i[0]?.component:r}function ra({projectId:e,projects:t}){let{resolvedTheme:n}=b$b(),o=Dn("navbar.logo"),r=Dn("navbar.projectSelector"),i=Dn("navbar.search"),a=Dn("navbar.userNav"),s=t.find(u=>u.projectId===e)??t[0],{basePath:l,schema:c}=s,f=useNavigate();function m(u){startTransition(()=>{f(b$a(l,e,"desk","list",u.entityNamePlural)+`?id=${u.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(o,{theme:n,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:m,projectId:e,schema:c})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function ia({version:e}){let{contributions:t,projects:n}=d(),[o,r]=b(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(n);if(!a)throw new uo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:l}=t,c=d$2(),f=useLocation();return useEffect(()=>{if(s){let m=s.find(p=>p.isDefault)||s[0],u="";typeof localStorage<"u"&&(u=localStorage.getItem(`${a$i}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:u||m.name}});}},[f]),o?jsx(co,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(ra,{projectId:i??"",projects:n}),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(na,{apps:l,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(Zi,{projectId:i??""})}function la(e){return e?"cause"in e:false}function qt(e){if(!e)return null;if(ServerError.is(e))return e;if(la(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function ca(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Ut(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function po(e){if(!e)return null;let t=cc(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(n=>`- ${n}`)].join(`
2
+ `)}function cc(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(sa).map(({message:r})=>r);let t=ca(e);if(t&&Rn(t))return [t];let n=qt(e);if(n?.statusCode!==400)return [];let o=Ut(n.bodyText)??fc(n)??uc(e);return o?Array.isArray(o.errors)?o.errors.filter(sa).map(r=>r.message):typeof o.message=="string"&&Rn(o.message)?[o.message]:typeof o.error=="string"&&Rn(o.error)?[o.error]:[]:[]}function fc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function uc(e){if(!la(e))return null;let{cause:t}=e,n=ca(t);if(n&&Rn(n))return {message:n};if(!t||typeof t!="object")return null;let{result:o}=t;return o&&typeof o=="object"?o:null}function sa(e){if(!e||typeof e!="object")return false;let{extensions:t,message:n}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof n=="string"?true:typeof n=="string"&&Rn(n)}function Rn(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Sc=ApolloProvider,da=createContext(void 0);function Jt(){let e=useContext(da);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function Ec(e){return new ErrorLink(({error:t})=>{let n=po(t);if(n){e(n);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 o=qt(t);if(o?.statusCode===400){let r=Ut(o.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:l}=r;if(typeof l=="string")i=l;else if(Array.isArray(s)){let[c]=s;if(c&&typeof c.message=="string"){let{message:f}=c;i=f;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=o.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.warn(`[Network error]: ${o.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function Ac(e,t){return from([Ec(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Tc(e,t){return new ApolloClient({link:Ac(e??"",t),cache:new InMemoryCache({dataIdFromObject:n=>n._id?n._id:defaultDataIdFromObject(n)})})}function ma({children:e}){let{currentProjectId:t}=d(),[n,o]=useState(null),r=useMemo(()=>({schemaErrorMessage:n,setSchemaErrorMessage:o}),[n]),i=useMemo(()=>Tc(t,o),[t]);return jsx(da.Provider,{value:r,children:jsx(Sc,{client:i,children:e})})}function pa({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function fr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Nc({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 ga({className:e,size:t="default",...n}){return jsxs(fr,{children:[jsx(Nc,{}),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),...n})]})}function ka({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 ha({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 ya({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 va({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 ba({className:e,variant:t="default",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...o})})}function Ca({className:e,variant:t="outline",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...o})})}function Pn({options:e}){let[t,n]=useState(false),[o,r]=useState(false),[i,a]=useState(false);useEffect(()=>{n(true);},[]);function s(){n(false),i||e.dialogActionCancel?.(),i&&a(false);}async function l(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{a(true),n(false),r(false);}}return jsx(pa,{onOpenChange:s,open:t,children:jsx(fr,{children:jsxs(ga,{className:"sm:max-w-[425px]",children:[jsxs(ka,{children:[jsx(ya,{children:e.dialogTitle}),jsx(va,{children:e.dialogMessage})]}),jsxs(ha,{children:[jsx(Ca,{disabled:o,onClick:s,children:e.dialogCancelTitle}),jsxs(ba,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:o,onClick:l,children:[o?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Ea=createContext([]),Aa=createContext(()=>{});function Fc(e,t){let n=t.type;switch(t._id||(t._id=Date.now().toString()),n){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(o=>o._id!==t._id);default:throw Error(`Unknown action: ${n}`)}}function Ta({children:e}){let[t,n]=useReducer(Fc,[]);return jsx(Ea.Provider,{value:t,children:jsx(Aa.Provider,{value:n,children:e})})}function Na(){return useContext(Ea)}function de(){return useContext(Aa)}function vt(){let[e,t]=useState(false),[n,o]=useState(gql`
3
3
  mutation updateEntity($any: Any) {
4
4
  any
5
5
  }
6
- `),[r,i]=useState({}),[a,{data:s,loading:f,error:c}]=useMutation(o,r),d=_t(c),{isProjectDisabled:m,isProjectReadOnly:l}=(()=>{if(d?.statusCode===403){let u=Ot(d.bodyText);if(u&&typeof u.code=="string"){if(u.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(u.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:c,isProjectDisabled:m,isProjectReadOnly:l}]}function se(e){return e.dataType==="asset"?"global":e.scope}var Mc=["id","string"],$c=["date","datetime","duration","time"],ga=`_id
6
+ `),[r,i]=useState({}),[a,{data:s,loading:l,error:c}]=useMutation(n,r),f=qt(c),{isProjectDisabled:m,isProjectReadOnly:u}=(()=>{if(f?.statusCode===403){let p=Ut(f.bodyText);if(p&&typeof p.code=="string"){if(p.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(p.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,o,i,{data:s,loading:l,error:c,isProjectDisabled:m,isProjectReadOnly:u}]}function ue(e){return e.dataType==="asset"?"global":e.scope}var yo=25,Oc=3,ko=3,Vc=["id","string"],Bc=["date","datetime","duration","time"],gr=`_id
7
7
  originalFilename
8
8
  mimeType
9
9
  path
10
10
  size
11
11
  height
12
12
  width
13
- lqip`,_c=`_id
13
+ lqip`,vo=`_id
14
14
  originalFilename
15
15
  mimeType
16
16
  path
17
17
  size
18
18
  height
19
- width`;function oo(e){return e?se(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function Kn(e,t){return !e||!oo(e)?false:t?.name!==b$8.name||e.name!=="assets"}function Do(e){return e?.dataType==="asset"||e?.inputType==="asset"}function ka(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 xt(e){return Array.isArray(e)?e[0]??null:e??null}function Yn(e,t=true,o=true){let n=t?` properties {
19
+ width`;function un(e){return e?ue(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function bo(e,t){return !e||!un(e)?false:t?.name!==b$8.name||e.name!=="assets"}function Ln(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Co(e){let t=e,n=t?.edges??[],o=t?.aggregate?.count?.nodes??n.length;return n.reduce((r,i,a)=>(i.node&&r.push({...i.node,sortOrder:i.properties?.sortOrder??a,totalCount:o}),r),[]).sort((r,i)=>(r.sortOrder??Number.MAX_SAFE_INTEGER)-(i.sortOrder??Number.MAX_SAFE_INTEGER))}function $n(e){return e.reduce((t,n,o)=>n._id?{...t,[n._id]:n.sortOrder??o}:t,{})}function bt(e){return Array.isArray(e)?e[0]??null:e??null}function kr(e,t=true,n=true,o=yo){let r=t?` properties {
20
20
  sortOrder
21
21
  }
22
- `:"",r=o?ga:_c;return ` ${e}Connection {
22
+ `:"",i=n?gr:vo,a=t?`(first: ${o}, sort: [{ edge: { sortOrder: ASC } }])`:`(first: ${o})`;return ` ${e}Connection${a} {
23
23
  aggregate {
24
24
  count {
25
25
  nodes
26
26
  }
27
27
  }
28
28
  edges {
29
- `+n+` node {
30
- ${r}
29
+ `+r+` node {
30
+ ${i}
31
31
  }
32
32
  }
33
33
  }
34
- `}function Wn(e){return e?.aggregate?.count?.nodes??0}function sn(e,t=""){return ` ${e}Connection${t} {
34
+ `}function mr(e){return e?.aggregate?.count?.nodes??0}function ho(e,t=""){return ` ${e}Connection${t} {
35
35
  aggregate {
36
36
  count {
37
37
  nodes
38
38
  }
39
39
  }
40
40
  }
41
- `}function ha(e){return e.find(t=>t.isPrimary)??e[0]}function Oc(e,t,o){if(!e)return "";let n=t==="default"?"":`${t}
42
- `;if(Do(e))return ` ${e.name} {
43
- ${ga}
41
+ `}function Ra(e){return e.find(t=>t.isPrimary)??e[0]}function zc(e,t,n){if(!e)return "";let o=t==="default"?"":`${t}
42
+ `;if(Ln(e))return ` ${e.name} {
43
+ ${gr}
44
44
  }
45
- `;if(se(e)==="local")return ` ${e.name} {
45
+ `;if(ue(e)==="local")return ` ${e.name} {
46
46
  _id
47
47
  default
48
- ${n}}
49
- `;if(se(e)==="relationship"){let r=e.relationship?.field;if(!r)return ` ${e.name}
50
- `;let i=find(propEq(e.relationship?.entity,"name"))(o),a=find(propEq(r,"name"))(i?.attributes??[]),s=a&&se(a)==="local"?`{
48
+ ${o}}
49
+ `;if(ue(e)==="relationship"){let r=e.relationship?.field;if(!r)return ` ${e.name}
50
+ `;let i=find(propEq(e.relationship?.entity,"name"))(n),a=find(propEq(r,"name"))(i?.attributes??[]),s=a&&ue(a)==="local"?`{
51
51
  _id
52
52
  default
53
- ${n}}
53
+ ${o}}
54
54
  `:"";return e.relationship?.mode==="single"?` ${e.name} {
55
55
  ${r} ${s}}
56
56
  `:` ${e.name} (limit: 3, offset: 0) {
57
57
  ${r} ${s}}
58
58
  `}return ` ${e.name}
59
- `}function Vc(e,t,o){return e?.attributes.reduce((n,r)=>{let i=t==="default"?"":`${t}
60
- `;if(Do(r))return `${n}
59
+ `}function jc(e,t,n){return e?.attributes.reduce((o,r)=>{let i=t==="default"?"":`${t}
60
+ `;if(Ln(r))return `${o}
61
61
  ${r.name} {
62
- _id
63
- originalFilename
64
- mimeType
65
- path
66
- size
67
- height
68
- width
69
- lqip
62
+ ${vo}
70
63
  }
71
- `;if(se(r)==="local")return `${n}
64
+ `;if(ue(r)==="local")return `${o}
72
65
  ${r.name} {
73
66
  _id
74
67
  default
75
68
  ${i}
76
69
  }
77
- `;if(se(r)==="relationship"){let a=find(propEq(r.relationship?.entity,"name"))(o),s=find(propEq(r.relationship?.field,"name"))(a?.attributes??[]),f=se(s)==="local"?`{
70
+ `;if(ue(r)==="relationship"){let a=find(propEq(r.relationship?.entity,"name"))(n),s=find(propEq(r.relationship?.field,"name"))(a?.attributes??[]),l=ue(s)==="local"?`{
78
71
  _id
79
72
  default
80
73
  ${i}}
81
- `:"";if(r.relationship?.mode==="single")return `${n}
74
+ `:"";if(r.relationship?.mode==="single")return `${o}
82
75
  ${r.name} {
83
- ${r.relationship.field} ${f}}
84
- `;if(r.relationship?.field)return `${n}
85
- ${r.name} (limit: 25, offset: 0) {
86
- ${r.relationship.field} ${f}}
87
- `}return `${n}
76
+ ${r.relationship.field} ${l}}
77
+ `;if(r.relationship?.field)return `${o}
78
+ ${r.name} (limit: ${ko}, offset: 0) {
79
+ ${r.relationship.field} ${l}}
80
+ `}return `${o}
88
81
  ${r.name}
89
- `},"")??""}function er(e,t,o,n){let r=n?.selection??"full",i="(where: $where, limit: $limit, offset: $offset, sort: $sort)",a=zt(o,e),s=a?.name??e,f=a?.attributes??[],c=`$where: ${s}Where, $limit: Int, $offset: Int, $sort: [${s}Sort!]`,d=`Get${Ye(e)}`;if(!a)throw new Error(`Entity '${s}' not found in the schema`);if(f.length===0)throw new Error(`Entity '${s}' has no attributes defined in the schema`);let m=fe("global",f).filter(T=>!(T==="_updatedAt"||r==="list"&&T==="lqip")).join(`
90
- `),l=no(f),u=fe(["local"],f),g=u.reduce((T,y)=>`${T}
91
- ${y} {
82
+ `},"")??""}function wo(e,t,n,o){let r=o?.selection??"full",i=o?.includeCount??true,a="(where: $where, limit: $limit, offset: $offset, sort: $sort)",s=Ct(n,e),l=s?.name??e,c=s?.attributes??[],f=`$where: ${l}Where, $limit: Int, $offset: Int, $sort: [${l}Sort!]`,m=`Get${nt(e)}`;if(!s)throw new Error(`Entity '${l}' not found in the schema`);if(c.length===0)throw new Error(`Entity '${l}' has no attributes defined in the schema`);let u=pe("global",c).filter(E=>!(E==="_updatedAt"||r==="list"&&E==="lqip")).join(`
83
+ `),p=dn(c),d=pe(["local"],c),g=d.reduce((E,w)=>`${E}
84
+ ${w} {
92
85
  _id
93
86
  default
94
87
  }
95
- `,""),p=u.reduce((T,y)=>`${T}
96
- ${y} {
88
+ `,""),h=d.reduce((E,w)=>`${E}
89
+ ${w} {
97
90
  _id
98
91
  default
99
92
  ${t}
100
93
  }
101
- `,""),v=t==="default"?g:p,h=r==="list"?`_id
94
+ `,""),y=t==="default"?g:h,C=r==="list"?`_id
102
95
  originalFilename
103
96
  mimeType
104
97
  path
@@ -111,192 +104,185 @@ import'./index.css';import {a as a$2}from'./chunk-27Y2SQ67.js';import {a as a$1}
111
104
  size
112
105
  height
113
106
  width
114
- lqip`,x=l.reduce((T,y)=>`${T}
115
- ${y} {
116
- ${h}
107
+ lqip`,v=p.reduce((E,w)=>`${E}
108
+ ${w} {
109
+ ${C}
117
110
  }
118
- `,""),w=f.filter(T=>se(T)==="relationship").reduce((T,y)=>{if(oo(y))return `${T}
119
- ${Yn(y.name,Kn(y,a),r!=="list")}`;let N=find(propEq(y.relationship?.entity,"name"))(o);if(r==="list"){let D=ha(N?.attributes??[]),L=Oc(D,t,o),z=y.relationship?.mode==="single"?1:3;return `${T}
120
- ${y.name} (limit: ${z}, offset: 0) {
111
+ `,""),D=c.filter(E=>ue(E)==="relationship").reduce((E,w)=>{if(un(w))return `${E}
112
+ ${kr(w.name,bo(w,s),r!=="list",r==="list"?Oc:yo)}`;let x=find(propEq(w.relationship?.entity,"name"))(n);if(r==="list"){let M=Ra(x?.attributes??[]),A=zc(M,t,n),R=w.relationship?.mode==="single"?1:3;return `${E}
113
+ ${w.name} (limit: ${R}, offset: 0) {
121
114
  _id
122
- ${L} }
123
- `}let S=Vc(N,t,o);return `${sn(y.name).trim()}${T}
124
- ${y.name} (limit: 25, offset: 0) { _id ${S}}
125
- `},"");return {queryEntityName:e,query:`query ${d}(${c}) {
126
- `+sn(e,"(where: $where)")+` ${e}${i} {
115
+ ${A} }
116
+ `}let $=jc(x,t,n);return `${ho(w.name).trim()}${E}
117
+ ${w.name} (limit: 25, offset: 0) { _id ${$}}
118
+ `},"");return {queryEntityName:e,query:`query ${m}(${f}) {
119
+ `+(i?ho(e,"(where: $where)"):"")+` ${e}${a} {
127
120
  _id
128
121
  _updatedAt
129
- ${m} ${v} ${x} ${w}}
122
+ ${u} ${y} ${v} ${D}}
130
123
  }
131
- `}}function ln(e,t,o,n){let i=zt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=Wn(o[`${e}Connection`]),s=o[e],f=(d,m)=>{let l=m.name;return d.slice(0,3).map(u=>{if(se(m)!=="local")return u[l];let g=xt(u[l]);return g?.[t]??g?.default}).join(", ")},c=s.map(d=>{let{_id:m}=d,l=typeof d._updatedAt=="string"?d._updatedAt:"",u=fe("global",i).filter(h=>h!=="_updatedAt").reduce((h,x)=>({...h,[x]:d[x]}),{}),g=fe("local",i).reduce((h,x)=>{let b=xt(d[x]);return {...h,[x]:b?.[t]?b[t]:b?.default}},{}),p=no(i).reduce((h,x)=>({...h,[x]:xt(d[x])}),{}),v=fe(["relationship"],i).reduce((h,x)=>{let b=find(propEq(x,"name"))(i),w=b.relationship?.entity??"",T=find(propEq(w,"name"))(n),y=ha(T?.attributes??[]),N=d[x];if(oo(b)){let X=ka(d[`${x}Connection`]);return {...h,[x]:X}}if(!y)throw new Error(`There is an error in the schema for the relationship attribute "${x}"`);let S=y.name,D=se(y);if(b.relationship?.mode==="multiple"){let X=Array.isArray(N)?N:[];return {...h,[x]:f(X,y)}}let L=xt(N);if(D==="global")return {...h,[x]:L?.[S]};let z=xt(L?.[S]);return {...h,[x]:z?.[t]??z?.default}},{});return {_id:m,...u,...g,...p,...v,_updatedAt:l}});return {count:a,results:c}}function ya(e,t,o,n){let i=zt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=Wn(o[`${e}Connection`]),f=o[e].map(c=>{let d=fe("global",i).reduce((g,p)=>({...g,[p]:{value:c[p],disabled:false,scope:"default",_id:""}}),{}),m=fe("local",i).reduce((g,p)=>{let v=find(propEq(p,"name"))(i),h=xt(c[p]);return {...g,[p]:{value:h?Bc(h,t):null,disabled:!!(h&&h[t]===null&&se(v)==="local"&&t!=="default"),scope:t,_id:h?h._id:null}}},{}),l=no(i).reduce((g,p)=>({...g,[p]:{value:xt(c[p]),disabled:false,scope:"default",_id:""}}),{}),u=fe(["relationship"],i).reduce((g,p)=>{let v=find(propEq(p,"name"))(i),h=c[p],x=v.relationship?.mode==="single"?xt(h):h,b=x?._id,w=Wn(c[`${p}Connection`]),T=oo(v)?ka(c[`${p}Connection`]):x;return {...g,[p]:{count:w,_id:b,value:T,disabled:false,scope:t}}},{});return {...d,...m,...l,...u}});return {count:a,results:f}}function Bc(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 tr(e,t,o,n,r,i,a){let s=zt(n,e),f=s?.name??e,c=s?.attributes??[],d=cn(e);if(c.length===0)return "";let m=va(c,i),l=ba(c,m),u=Hc(t,c,m,o),g=zc(c,r,m),p=qc(c,r,m),v=e,h=a?.responseFields??Ca(n,e,o);return `mutation ${`Update${Ye(e)}`}($where: ${f}Where) {
132
- update${d}(
124
+ `}}function xo(e,t,n,o){let i=Ct(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=mr(n[`${e}Connection`]),s=n[e],l=(f,m)=>{let u=m.name;return f.slice(0,3).map(p=>{if(ue(m)!=="local")return p[u];let d=bt(p[u]);return d?.[t]??d?.default}).join(", ")},c=s.map(f=>{let{_id:m}=f,u=typeof f._updatedAt=="string"?f._updatedAt:"",p=pe("global",i).filter(y=>y!=="_updatedAt").reduce((y,C)=>({...y,[C]:f[C]}),{}),d=pe("local",i).reduce((y,C)=>{let v=bt(f[C]);return {...y,[C]:v?.[t]?v[t]:v?.default}},{}),g=dn(i).reduce((y,C)=>({...y,[C]:bt(f[C])}),{}),h=pe(["relationship"],i).reduce((y,C)=>{let v=find(propEq(C,"name"))(i),b=v.relationship?.entity??"",D=find(propEq(b,"name"))(o),E=Ra(D?.attributes??[]),w=f[C];if(un(v)){let R=Co(f[`${C}Connection`]);return {...y,[C]:R}}if(!E)throw new Error(`There is an error in the schema for the relationship attribute "${C}"`);let x=E.name,$=ue(E);if(v.relationship?.mode==="multiple"){let R=Array.isArray(w)?w:[];return {...y,[C]:l(R,E)}}let M=bt(w);if($==="global")return {...y,[C]:M?.[x]};let A=bt(M?.[x]);return {...y,[C]:A?.[t]??A?.default}},{});return {_id:m,...p,...d,...g,...h,_updatedAt:u}});return {count:a,results:c}}function Pa(e,t,n,o){let i=Ct(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=mr(n[`${e}Connection`]),l=n[e].map(c=>{let f=pe("global",i).reduce((d,g)=>({...d,[g]:{value:c[g],disabled:false,scope:"default",_id:""}}),{}),m=pe("local",i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),y=bt(c[g]);return {...d,[g]:{value:y?Hc(y,t):null,disabled:!!(y&&y[t]===null&&ue(h)==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),u=dn(i).reduce((d,g)=>({...d,[g]:{value:bt(c[g]),disabled:false,scope:"default",_id:""}}),{}),p=pe(["relationship"],i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),y=c[g],C=h.relationship?.mode==="single"?bt(y):y,v=C?._id,b=mr(c[`${g}Connection`]);if(un(h)){let D=Co(c[`${g}Connection`]);return {...d,[g]:{count:b,_id:v,knownAssetSortOrders:$n(D),value:D,disabled:false,scope:t}}}return {...d,[g]:{count:b,_id:v,value:C,disabled:false,scope:t}}},{});return {...f,...m,...u,...p}});return {count:a,results:l}}function Hc(e,t){return Array.isArray(e)?e.reduce((n,o)=>{if(o[t]??o.default){let r={_id:o._id,disabled:o.scope===null&&t!=="default",scope:t,value:o[t]??o.default};n.push(r);}return n},[]):e[t]??e.default??null}function hr(e,t,n,o,r,i,a){let s=Ct(o,e),l=s?.name??e,c=s?.attributes??[],f=On(e);if(c.length===0)return "";let m=Ia(c,i),u=Fa(c,m),p=Jc(t,c,m,n),d=qc(c,r,m),g=Qc(c,r,m),h=e,y=a?.responseFields??$a(o,e,n);return `mutation ${`Update${nt(e)}`}($where: ${l}Where) {
125
+ update${f}(
133
126
  where: $where
134
- update: {${l}${u}${g}${p}
127
+ update: {${u}${p}${d}${g}
135
128
  }
136
129
  ) {
137
- ${v} {
130
+ ${h} {
138
131
  _id
139
- ${h} }
132
+ ${y} }
140
133
  }
141
134
  }
142
- `}function va(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 fe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(fe(r,t)),[]):t.filter(n=>se(n)===e&&n.inputType!=="asset").map(n=>n.name)}function no(e){return e.filter(Do).map(o=>o.name)}function ba(e,t,o="update"){let n=pick(fe("global",e),t);return toPairs(n).reduce((i,[a,s])=>{let f=find(propEq(a,"name"))(e),c=Array.isArray(s?.value)?null:s?.value??null,d=or(f.dataType,c);return o==="create"&&(d===null||d==="")?i:o==="update"?`${i}
143
- ${a}: { set: ${d} }`:`${i}
144
- ${a}: ${d}`},"")}function Zn(e){return !e?._id||!e.path?"":e._id}function zc(e,t,o){let n=pick(no(e),o);return toPairs(n).reduce((a,[s,f])=>{let c=Zn(f.value),d=Zn(t[s]?.value);if(c===d)return a;let m=d?` {
135
+ `}function Ia(e,t){let n=e.map(r=>r.isEditable===false?r.name:"").filter(Boolean),o=omit(n,t);return pick(e.map(r=>r.name),o)}function pe(e,t){return Array.isArray(e)?e.reduce((o,r)=>o.concat(pe(r,t)),[]):t.filter(o=>ue(o)===e&&o.inputType!=="asset").map(o=>o.name)}function dn(e){return e.filter(Ln).map(n=>n.name)}function Fa(e,t,n="update"){let o=pick(pe("global",e),t);return toPairs(o).reduce((i,[a,s])=>{let l=find(propEq(a,"name"))(e),c=Array.isArray(s?.value)?null:s?.value??null,f=yr(l.dataType,c);return n==="create"&&(f===null||f==="")?i:n==="update"?`${i}
136
+ ${a}: { set: ${f} }`:`${i}
137
+ ${a}: ${f}`},"")}function pr(e){return !e?._id||!e.path?"":e._id}function qc(e,t,n){let o=pick(dn(e),n);return toPairs(o).reduce((a,[s,l])=>{let c=pr(l.value),f=pr(t[s]?.value);if(c===f)return a;let m=f?` {
145
138
  disconnect: [{
146
139
  where: {
147
140
  node: {
148
- _id: { eq: ${ye(d)} }
141
+ _id: { eq: ${Se(f)} }
149
142
  }
150
143
  }
151
144
  }]
152
145
  }
153
- `:"",l=c?` {
146
+ `:"",u=c?` {
154
147
  connect: [{
155
148
  where: {
156
149
  node: {
157
- _id: { eq: ${ye(c)} }
150
+ _id: { eq: ${Se(c)} }
158
151
  }
159
152
  }
160
153
  }]
161
154
  }
162
155
  `:"";return `${a}
163
156
  ${s}: [
164
- ${m}${l} ]`},"")}function jc(e,t){let o=pick(no(e),t);return toPairs(o).reduce((i,[a,s])=>{let f=Zn(s.value);return f?`${i}
157
+ ${m}${u} ]`},"")}function Uc(e,t){let n=pick(dn(e),t);return toPairs(n).reduce((i,[a,s])=>{let l=pr(s.value);return l?`${i}
165
158
  ${a}: {
166
159
  connect: [{
167
160
  where: {
168
161
  node: {
169
- _id: { eq: ${ye(f)} }
162
+ _id: { eq: ${Se(l)} }
170
163
  }
171
164
  }
172
165
  }]
173
- }`:i},"")}function Hc(e,t,o,n){let r=pick(fe("local",t),o);return toPairs(r).reduce((s,[f,c])=>{let d=find(propEq(f,"name"))(t),{dataType:m}=d,l=c.disabled||Array.isArray(c.value)?"null":or(m,c.value);return c._id?`${s}
174
- ${f}: [{
166
+ }`:i},"")}function Jc(e,t,n,o){let r=pick(pe("local",t),n);return toPairs(r).reduce((s,[l,c])=>{let f=find(propEq(l,"name"))(t),{dataType:m}=f,u=c.disabled||Array.isArray(c.value)?"null":yr(m,c.value);return c._id?`${s}
167
+ ${l}: [{
175
168
  update: {
176
169
  node: {
177
- ${n}: { set: ${l} }
170
+ ${o}: { set: ${u} }
178
171
  }
179
172
  }
180
- }]`:l?`${s}
181
- ${f}: [{
173
+ }]`:c.disabled||Array.isArray(c.value)||c.value===void 0||c.value===null||c.value===""||u===null||u===""?s:`${s}
174
+ ${l}: [{
182
175
  create: {
183
176
  node: {
184
- _id: ${ye(`${e}:${f}`)}
177
+ _id: ${Se(`${e}:${l}`)}
185
178
  _type: "${m}"
186
- ${n}: ${l}
179
+ ${o}: ${u}
187
180
  }
188
181
  }
189
- }]`:s},"")}function qc(e,t,o){let n=pick(fe("relationship",e),o);return toPairs(n).reduce((a,[s,f])=>{let c=find(propEq(s,"name"))(e),{inputType:d,relationship:m}=c;if(d==="relationship"&&m?.mode==="single"){let l=t[s]._id??"",u=f._id??"";if(l===u)return a;let g=l?` {
182
+ }]`},"")}function Qc(e,t,n){let o=pick(pe("relationship",e),n);return toPairs(o).reduce((a,[s,l])=>{let c=find(propEq(s,"name"))(e),{inputType:f,relationship:m}=c;if(f==="relationship"&&m?.mode==="single"){let u=t[s]._id??"",p=l._id??"";if(u===p)return a;let d=u?` {
190
183
  disconnect: [{
191
184
  where: {
192
185
  node: {
193
- _id: { eq: ${ye(l)} }
186
+ _id: { eq: ${Se(u)} }
194
187
  }
195
188
  }
196
189
  }]
197
190
  }
198
- `:"",p=u?` {
191
+ `:"",g=p?` {
199
192
  connect: [{
200
193
  where: {
201
194
  node: {
202
- _id: { eq: ${ye(u)} }
195
+ _id: { eq: ${Se(p)} }
203
196
  }
204
197
  }
205
198
  }]
206
199
  }
207
200
  `:"";return `${a}
208
201
  ${s}: [
209
- ${g}${p} ]`}if(d==="relationship"&&m?.mode==="multiple"){if(m.entity==="_asset")return `${a}${Uc(s,t[s],f)}`;let l=uniq(f.relationships?.disconnect??[]).filter(Boolean),g=(f.relationships?.connect??[]).map(h=>ye(h._id)).join(", "),p=l.length?` {
202
+ ${d}${g} ]`}if(f==="relationship"&&m?.mode==="multiple"){if(m.entity==="_asset")return `${a}${Xc(s,t[s],l)}`;let u=uniq(l.relationships?.disconnect??[]).filter(Boolean),d=(l.relationships?.connect??[]).map(y=>Se(y._id)).join(", "),g=u.length?` {
210
203
  disconnect: [
211
- ${l.map(h=>` {
204
+ ${u.map(y=>` {
212
205
  where: {
213
206
  node: {
214
- _id: { eq: ${ye(h)} }
207
+ _id: { eq: ${Se(y)} }
215
208
  }
216
209
  }
217
210
  }
218
211
  `).join("")} ]
219
212
  }
220
- `:"",v=g?` {
213
+ `:"",h=d?` {
221
214
  connect: [{
222
215
  where: {
223
216
  node: {
224
- _id: { in: [${g}] }
217
+ _id: { in: [${d}] }
225
218
  }
226
219
  }
227
220
  }]
228
221
  }
229
- `:"";return !p&&!v?a:`${a}
222
+ `:"";return !g&&!h?a:`${a}
230
223
  ${s}: [
231
- ${p}${v} ]`}return `${a}
232
- `},"")}function Uc(e,t,o){let r=(o.relationships?.connect??[]).map((u,g)=>({...u,sortOrder:u.sortOrder??g})),i=r.map(u=>u._id),a=Jc(t),s=uniq(o.relationships?.disconnect??[]).filter(u=>u&&!i.includes(u)),f=r.filter(u=>a[u._id]===void 0),c=r.filter(u=>{let g=a[u._id];return g!==void 0&&g!==u.sortOrder}),d=Xc(s),m=Qc(f),l=Gc(c);return !d&&!m&&!l?"":`
224
+ ${g}${h} ]`}return `${a}
225
+ `},"")}function Xc(e,t,n){let r=(n.relationships?.connect??[]).map((p,d)=>({...p,sortOrder:p.sortOrder??d})),i=r.map(p=>p._id),a={...Gc(t),...t?.knownAssetSortOrders??{},...n.knownAssetSortOrders??{}},s=uniq(n.relationships?.disconnect??[]).filter(p=>p&&!i.includes(p)),l=r.filter(p=>a[p._id]===void 0),c=r.filter(p=>{let d=a[p._id];return d!==void 0&&d!==p.sortOrder}),f=Wc(s),m=Zc(l),u=Kc(c);return !f&&!m&&!u?"":`
233
226
  ${e}: [
234
- ${d}${m}${l} ]`}function Jc(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 Xc(e){return e.length===0?"":` {
227
+ ${f}${m}${u} ]`}function Gc(e){let t=e?.value;return Array.isArray(t)?t.reduce((n,o,r)=>{if(typeof o!="object"||!o||!("_id"in o))return n;let{_id:i}=o;if(typeof i!="string"||i.length===0)return n;let a="sortOrder"in o&&typeof o.sortOrder=="number"?o.sortOrder:r;return {...n,[i]:a}},{}):{}}function Wc(e){return e.length===0?"":` {
235
228
  disconnect: [
236
- ${e.reduce((o,n)=>`${o} {
237
- where: { node: { _id: { eq: ${ye(n)} } } }
229
+ ${e.reduce((n,o)=>`${n} {
230
+ where: { node: { _id: { eq: ${Se(o)} } } }
238
231
  }
239
232
  `,"")} ]
240
233
  }
241
- `}function Qc(e){return e.length===0?"":` {
234
+ `}function Zc(e){return e.length===0?"":` {
242
235
  connect: [
243
- ${wa(e)} ]
236
+ ${La(e)} ]
244
237
  }
245
- `}function wa(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
246
- where: { node: { _id: { eq: ${ye(o._id)} } } }
238
+ `}function La(e){return e.reduce((t,n,o)=>{let r=n.sortOrder??o;return `${t} {
239
+ where: { node: { _id: { eq: ${Se(n._id)} } } }
247
240
  edge: { sortOrder: ${r} }
248
241
  }
249
- `},"")}function Gc(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
242
+ `},"")}function Kc(e){return e.length===0?"":e.reduce((n,o,r)=>{let i=o.sortOrder??r;return `${n} {
250
243
  update: {
251
- where: { node: { _id: { eq: ${ye(n._id)} } } }
244
+ where: { node: { _id: { eq: ${Se(o._id)} } } }
252
245
  edge: { sortOrder: { set: ${i} } }
253
246
  }
254
247
  }
255
- `},"")}function or(e,t){return $c.includes(e)?t?.toString()?ye(t.toString()):null:Mc.includes(e)?ye(t?.toString()??"null"):t==null||t===""?null:t.toString()}function ye(e){return JSON.stringify(e)}function Ca(e,t,o){let n=zt(e,t),r=n?.attributes??[],i=fe("global",r),a=fe("local",r),s=fe("relationship",r),f=i.reduce((c,d)=>`${c}${d}
256
- `,"");return f+=a.reduce((c,d)=>`${c} ${d} {
248
+ `},"")}function yr(e,t){return Bc.includes(e)?t?.toString()?Se(t.toString()):null:Vc.includes(e)?t==null?null:Se(t.toString()):t==null||t===""?null:t.toString()}function Se(e){return JSON.stringify(e)}function $a(e,t,n){let o=Ct(e,t),r=o?.attributes??[],i=pe("global",r),a=pe("local",r),s=pe("relationship",r),l=i.reduce((c,f)=>`${c}${f}
249
+ `,"");return l+=a.reduce((c,f)=>`${c} ${f} {
257
250
  _id
258
- ${o}
251
+ ${n}
259
252
  }
260
- `,""),f+=s.reduce((c,d)=>{let m=find(propEq(d,"name"))(r),l=m?.relationship?.mode??"single";if(oo(m))return `${c}${Yn(d,Kn(m,n))}`;let u=m?.relationship?.entity??"",p=find(propEq(u,"name"))(e)?.attributes??[],v=m?.relationship?.field??"[invalid_relationship_field_name_in_schema]",h=find(propEq(v,"name"))(p),x=se(h),b="";if(l==="single"&&(x==="global"&&(b=` ${d} {
253
+ `,""),l+=s.reduce((c,f)=>{let m=find(propEq(f,"name"))(r),u=m?.relationship?.mode??"single";if(un(m))return `${c}${kr(f,bo(m,o))}`;let p=m?.relationship?.entity??"",g=find(propEq(p,"name"))(e)?.attributes??[],h=m?.relationship?.field??"[invalid_relationship_field_name_in_schema]",y=find(propEq(h,"name"))(g),C=ue(y),v="";if(u==="single"&&(C==="global"&&(v=` ${f} {
261
254
  _id
262
- ${v}
255
+ ${h}
263
256
  }
264
- `),x==="local"&&(b=` ${d} {
257
+ `),C==="local"&&(v=` ${f} {
265
258
  _id
266
- ${v} {
259
+ ${h} {
267
260
  _id
268
261
  default
269
- ${o}
262
+ ${n}
270
263
  }
271
264
  }
272
- `)),l==="multiple"&&p.length){let w=p.reduce((T,y)=>{if(se(y)==="local")return `${T} ${y.name} {
265
+ `)),u==="multiple"&&g.length){let b=g.reduce((D,E)=>{if(ue(E)==="local")return `${D} ${E.name} {
273
266
  _id
274
267
  default
275
- ${o}
268
+ ${n}
276
269
  }
277
- `;if(se(y)==="relationship"){let N=o==="default"?"":`${o}
278
- `,S=find(propEq(y.relationship?.entity,"name"))(e),D=find(propEq(y.relationship?.field,"name"))(S?.attributes??[]),L=se(D)==="local"?`{
270
+ `;if(ue(E)==="relationship"){let w=n==="default"?"":`${n}
271
+ `,x=find(propEq(E.relationship?.entity,"name"))(e),$=find(propEq(E.relationship?.field,"name"))(x?.attributes??[]),M=ue($)==="local"?`{
279
272
  _id
280
273
  default
281
- ${N}}
282
- `:"";if(y.relationship?.mode==="single")return `${T} ${y.name} {
283
- ${y.relationship.field} ${L}}
284
- `;if(y.relationship?.field)return `${T} ${y.name} (limit: 25, offset: 0) {
285
- ${y.relationship.field} ${L}}
286
- `}return Do(y)?`${T} ${y.name} {
287
- _id
288
- originalFilename
289
- mimeType
290
- path
291
- size
292
- height
293
- width
294
- lqip
274
+ ${w}}
275
+ `:"";if(E.relationship?.mode==="single")return `${D} ${E.name} {
276
+ ${E.relationship.field} ${M}}
277
+ `;if(E.relationship?.field)return `${D} ${E.name} (limit: ${ko}, offset: 0) {
278
+ ${E.relationship.field} ${M}}
279
+ `}return Ln(E)?`${D} ${E.name} {
280
+ ${vo}
295
281
  }
296
- `:`${T} ${y.name}
297
- `},"");b=sn(d)+` ${d} (limit: 25, offset: 0) {
298
- ${w} }
299
- `;}return `${c}${b}`},""),f}function No(e,t,o){let n=typeof o=="string"?[o]:[...o],r=find(propEq(e,"name"))(t),i=r?.attributes??[],a=cn(r?.plural??""),s=Wc(i,n),f=`Delete${Ye(r?.plural??e)}`;return e==="_asset"?`mutation ${f}($where: ${e}Where) {
282
+ `:`${D} ${E.name}
283
+ `},"");v=ho(f)+` ${f} (limit: 25, offset: 0) {
284
+ ${b} }
285
+ `;}return `${c}${v}`},""),l}function Mn(e,t,n){let o=typeof n=="string"?[n]:[...n],r=find(propEq(e,"name"))(t),i=r?.attributes??[],a=On(r?.plural??""),s=Yc(i,o),l=`Delete${nt(r?.plural??e)}`;return e==="_asset"?`mutation ${l}($where: ${e}Where) {
300
286
  delete_assets(
301
287
  where: $where
302
288
  ) {
@@ -304,7 +290,7 @@ ${w} }
304
290
  relationshipsDeleted
305
291
  }
306
292
  }
307
- `:`mutation ${f}($where: ${e}Where) {
293
+ `:`mutation ${l}($where: ${e}Where) {
308
294
  delete${a}(
309
295
  where: $where
310
296
  ${s?` delete: {
@@ -315,72 +301,72 @@ ${s?` delete: {
315
301
  relationshipsDeleted
316
302
  }
317
303
  }
318
- `}function Po(e){let t=typeof e=="string"?[e]:[...e];return t.length===1?{_id:{eq:t[0]}}:{_id:{in:t}}}function Wc(e,t){return fe("local",e).reduce((r,i)=>{let a=t.map(f=>ye(`${f}:${i}`)).join(", "),s=t.length===1?`_id: { eq: ${a} }`:`_id: { in: [${a}] }`;return `${r}
304
+ `}function _n(e){let t=typeof e=="string"?[e]:[...e];return t.length===1?{_id:{eq:t[0]}}:{_id:{in:t}}}function Yc(e,t){return pe("local",e).reduce((r,i)=>{let a=t.map(l=>Se(`${l}:${i}`)).join(", "),s=t.length===1?`_id: { eq: ${a} }`:`_id: { in: [${a}] }`;return `${r}
319
305
  ${i}: [{
320
306
  where: {
321
307
  node: {
322
308
  ${s}
323
309
  }
324
310
  }
325
- }]`},"")}function nr(e,t,o,n){let r=zt(t,e),i=r?.attributes??[],a=cn(r?.plural??"");if(i.length===0)return "";let s=va(i,o),f=ba(i,s,"create"),c=Zc(i,s,"default",n),d=jc(i,s),m=Kc(i,s),l=e,u=Ca(t,l,"default");return `mutation ${`Create${Ye(e)}`} {
311
+ }]`},"")}function vr(e,t,n,o){let r=Ct(t,e),i=r?.attributes??[],a=On(r?.plural??"");if(i.length===0)return "";let s=Ia(i,n),l=Fa(i,s,"create"),c=ef(i,s,"default",o),f=Uc(i,s),m=tf(i,s),u=e,p=$a(t,u,"default");return `mutation ${`Create${nt(e)}`} {
326
312
  create${a}(
327
313
  input: [{
328
- _id: ${ye(n)} ${f} ${c}
329
- ${d}
314
+ _id: ${Se(o)} ${l} ${c}
315
+ ${f}
330
316
  ${m}
331
317
  }]
332
318
  ) {
333
- ${l} {
319
+ ${u} {
334
320
  _id
335
- ${u} }
321
+ ${p} }
336
322
  }
337
323
  }
338
- `}function Zc(e,t,o,n){let r=pick(fe("local",e),t);return toPairs(r).reduce((s,[f,c])=>{if(c?.value===void 0||c.value===null||c.value==="")return s;let d=find(propEq(f,"name"))(e),m=Array.isArray(c.value)?"null":or(d.dataType,c.value);return `${s}
339
- ${f}: {
324
+ `}function ef(e,t,n,o){let r=pick(pe("local",e),t);return toPairs(r).reduce((s,[l,c])=>{if(c?.value===void 0||c.value===null||c.value==="")return s;let f=find(propEq(l,"name"))(e),m=Array.isArray(c.value)?"null":yr(f.dataType,c.value);return `${s}
325
+ ${l}: {
340
326
  create: [{
341
327
  node: {
342
- _id: ${ye(`${n}:${f}`)}
343
- _type: "${d.dataType}"
344
- ${o}: ${m}
328
+ _id: ${Se(`${o}:${l}`)}
329
+ _type: "${f.dataType}"
330
+ ${n}: ${m}
345
331
  }
346
332
  }]
347
- }`},"")}function Kc(e,t){let o=pick(fe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let f=find(propEq(a,"name"))(e),{inputType:c,relationship:d}=f;if(c==="relationship"&&d?.mode==="single"){if(!s._id)return i;let u=`connect: [{
333
+ }`},"")}function tf(e,t){let n=pick(pe("relationship",e),t);return toPairs(n).reduce((i,[a,s])=>{let l=find(propEq(a,"name"))(e),{inputType:c,relationship:f}=l;if(c==="relationship"&&f?.mode==="single"){if(!s._id)return i;let p=`connect: [{
348
334
  where: {
349
335
  node: {
350
- _id: { eq: ${ye(s._id)} }
336
+ _id: { eq: ${Se(s._id)} }
351
337
  }
352
338
  }
353
339
  }]
354
340
  `;return `${i}
355
341
  ${a}: {
356
- ${u} }`}let m=c==="relationship"&&d?.mode==="multiple",l=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(m&&l){let u=s.relationships?.connect??[];if(d?.entity==="_asset"){let v=wa(u.map((h,x)=>({...h,sortOrder:h.sortOrder??x})));return `${i}
342
+ ${p} }`}let m=c==="relationship"&&f?.mode==="multiple",u=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(m&&u){let p=s.relationships?.connect??[];if(f?.entity==="_asset"){let h=La(p.map((y,C)=>({...y,sortOrder:y.sortOrder??C})));return `${i}
357
343
  ${a}: {
358
344
  connect: [
359
- ${v} ]
360
- }`}let g=u.map(v=>ye(v._id)).join(", "),p=g?`connect: {
345
+ ${h} ]
346
+ }`}let d=p.map(h=>Se(h._id)).join(", "),g=d?`connect: {
361
347
  where: {
362
348
  node: {
363
- _id: { in: [${g}] }
349
+ _id: { in: [${d}] }
364
350
  }
365
351
  }
366
352
  }
367
353
  `:"";return `${i}
368
354
  ${a}: {
369
- ${p} }`}return `${i}
370
- `},"")}function xa({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, limit: $limit, offset: $offset, sort: $sort)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $limit: Int, $offset: Int, $sort: [${t}Sort!]`,f=i?.plural??"",c=`GetRelated${Ye(f||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let d=fe("global",a).filter(b=>b!=="_updatedAt").join(`
371
- `),m=fe(["local"],a),l=m.reduce((b,w)=>`${b}
372
- ${w} {
355
+ ${g} }`}return `${i}
356
+ `},"")}function Ma({attributeName:e,relatedEntityName:t,scope:n,schema:o}){let r="(where: $where, limit: $limit, offset: $offset, sort: $sort)",i=find(propEq(t,"name"))(o),a=i?.attributes??[],s=`$where: ${t}Where, $limit: Int, $offset: Int, $sort: [${t}Sort!]`,l=i?.plural??"",c=`GetRelated${nt(l||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let f=pe("global",a).filter(v=>v!=="_updatedAt").join(`
357
+ `),m=pe(["local"],a),u=m.reduce((v,b)=>`${v}
358
+ ${b} {
373
359
  _id
374
360
  default
375
361
  }
376
- `,""),u=m.reduce((b,w)=>`${b}
377
- ${w} {
362
+ `,""),p=m.reduce((v,b)=>`${v}
363
+ ${b} {
378
364
  _id
379
365
  default
380
- ${o}
366
+ ${n}
381
367
  }
382
- `,""),g=o==="default"?l:u,v=no(a).reduce((b,w)=>`${b}
383
- ${w} {
368
+ `,""),d=n==="default"?u:p,h=dn(a).reduce((v,b)=>`${v}
369
+ ${b} {
384
370
  _id
385
371
  originalFilename
386
372
  mimeType
@@ -390,56 +376,72 @@ ${v} ]
390
376
  width
391
377
  lqip
392
378
  }
393
- `,""),x=a.filter(b=>se(b)==="relationship").reduce((b,w)=>{if(oo(w))return `${b}
394
- ${Yn(w.name,Kn(w,i))}`;let y=find(propEq(w.relationship?.entity,"name"))(n)?.attributes.reduce((N,S)=>{let D=o==="default"?"":`${o}
395
- `;if(Do(S))return `${N}
396
- ${S.name} {
397
- _id
398
- originalFilename
399
- mimeType
400
- path
401
- size
402
- height
403
- width
404
- lqip
379
+ `,""),C=a.filter(v=>ue(v)==="relationship").reduce((v,b)=>{if(un(b))return `${v}
380
+ ${kr(b.name,bo(b,i))}`;let E=find(propEq(b.relationship?.entity,"name"))(o)?.attributes.reduce((w,x)=>{let $=n==="default"?"":`${n}
381
+ `;if(Ln(x))return `${w}
382
+ ${x.name} {
383
+ ${vo}
405
384
  }
406
- `;if(se(S)==="local")return `${N}
407
- ${S.name} {
385
+ `;if(ue(x)==="local")return `${w}
386
+ ${x.name} {
408
387
  _id
409
388
  default
410
- ${D}}
411
- `;if(se(S)==="relationship"){let L=find(propEq(S.relationship?.entity,"name"))(n),z=find(propEq(S.relationship?.field,"name"))(L?.attributes??[]),X=se(z)==="local"?`{
389
+ ${$}}
390
+ `;if(ue(x)==="relationship"){let M=find(propEq(x.relationship?.entity,"name"))(o),A=find(propEq(x.relationship?.field,"name"))(M?.attributes??[]),R=ue(A)==="local"?`{
412
391
  _id
413
392
  default
414
- ${D}}
415
- `:"";if(S.relationship?.mode==="single")return `${N}
416
- ${S.name} {
417
- ${S.relationship.field} ${X}}
418
- `;if(S.relationship?.field)return `${N}
419
- ${S.name} (limit: 25, offset: 0) {
420
- ${S.relationship.field} ${X}}
421
- `}return `${N}
422
- ${S.name}
423
- `},"");return `${b}
424
- ${w.name} (limit: 25, offset: 0) { _id ${y??""}}
425
- `},"");return {queryEntityName:f,query:`query ${c}(${s}) {
426
- `+sn(e,"(where: $where)")+` ${f}${r} {
393
+ ${$}}
394
+ `:"";if(x.relationship?.mode==="single")return `${w}
395
+ ${x.name} {
396
+ ${x.relationship.field} ${R}}
397
+ `;if(x.relationship?.field)return `${w}
398
+ ${x.name} (limit: ${ko}, offset: 0) {
399
+ ${x.relationship.field} ${R}}
400
+ `}return `${w}
401
+ ${x.name}
402
+ `},"");return `${v}
403
+ ${b.name} (limit: ${ko}, offset: 0) { _id ${E??""}}
404
+ `},"");return {queryEntityName:l,query:`query ${c}(${s}) {
405
+ `+ho(e,"(where: $where)")+` ${l}${r} {
427
406
  _id
428
407
  _updatedAt
429
- ${d} ${g} ${v} ${x} }
408
+ ${f} ${d} ${h} ${C} }
409
+ }
410
+ `}}function _a({attributeName:e,entityName:t,entityNamePlural:n,schema:o}){let r=Ct(o,n),i=find(propEq(e,"name"))(r?.attributes??[]),a=bo(i,r),s=a?` properties {
411
+ sortOrder
412
+ }
413
+ `:"",l=a?"(first: $first, sort: [{ edge: { sortOrder: ASC } }])":"(first: $first)",c=`Get${nt(t)}AssetConnection`;return {queryEntityName:n,query:`query ${c}($where: ${t}Where, $first: Int) {
414
+ ${n}(where: $where) {
415
+ ${e}Connection${l} {
416
+ aggregate {
417
+ count {
418
+ nodes
419
+ }
420
+ }
421
+ edges {
422
+ `+s+` node {
423
+ ${gr}
424
+ }
425
+ }
426
+ }
427
+ }
430
428
  }
431
- `}}var cn=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ye(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(cn).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function zt(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}var fn=null,rr=new Set,Ea=[],ir=new Set,ar=new Set,sr=new Set;function Ve(e,t){if(e==="_asset"||e==="_assets")return `Get${Ye(a$f.plural)}`;let o=t.find(i=>i.plural===e),n=t.find(i=>i.name===e),r=o?.plural??n?.plural??e;return `Get${Ye(r)}`}function Sa(e){return ir.add(e),()=>{ir.delete(e);}}function Aa(e){return ar.add(e),()=>{ar.delete(e);}}function Ta(e){return sr.add(e),()=>{sr.delete(e);}}function dn(e,t,o){let n=new Set(o.filter(Boolean));if(n.size>0)for(let r of ar)r(t,n);return mt(e,t)}function Da(e,t){let o=t.filter(n=>!!n._id);if(o.length!==0)for(let n of sr)n(e,o);}function mt(e,t){return rr.add(t),new Promise((o,n)=>{Ea.push({resolve:o,reject:n}),fn&&clearTimeout(fn),fn=setTimeout(()=>{let r=new Set(rr),i=Ea.splice(0);rr.clear(),fn=null,Promise.all([...ir].map(a=>Promise.resolve(a(r)))).then(()=>{for(let{resolve:a}of i)a();}).catch(a=>{console.error("Error refreshing entity lists:",a);for(let{reject:s}of i)s(a);});},50);})}function lr({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),r=useApolloClient(),[i,a,s]=ut(),f=ae(),c=useRef(false),d$1=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],m=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),l=!!e.payload.silent,u=d$1.length>1;if(useEffect(()=>{!l||c.current||(c.current=true,p());},[l]),l)return jsx(Fragment,{});let g={dialogTitle:u?`Delete ${d$1.length} ${m}s`:`Delete ${m}`,dialogMessage:u?`Are you sure you want to delete the selected ${m}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${m}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>p()};function p(){let v=No(e.payload.entityName,n,d$1);return new Promise((h,x)=>{a(gql`
432
- ${v}
433
- `),s({variables:{where:Po(d$1)},update(b){for(let w of d$1)b.evict({id:w});},onCompleted:()=>{toast.success(u?"Items successfully deleted.":"Item successfully deleted."),dn(r,Ve(e.payload.entityName,n),d$1),f({type:"Dismiss",_id:e._id,payload:{}}),h();},onError:b=>{x(b);}}),i(true);})}return jsx(So,{options:g})}var lf=Drawer.Portal;function Ra({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function cf({...e}){return jsx(lf,{...e})}function ff({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 Fa({className:e,children:t,...o}){return jsxs(cf,{children:[jsx(ff,{}),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 Ia({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 La({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 Ma({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function jt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[f,c]=useState(false),d=n*(50/n),m=useCallback(()=>{(!t||t())&&(c(false),setTimeout(()=>{a();},150));},[t,a,c]),l=useCallback(u=>{u.key==="Escape"&&r&&m();},[m,r]);return useEffect(()=>{c(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",l,false),()=>{globalThis.document.removeEventListener("keydown",l,false);}),[l]),jsx(Ra,{direction:"right",dismissible:false,onClose:()=>{m();},open:f,children:jsxs(Fa,{style:r?{}:{maxWidth:`calc(100% - ${d.toString()}px)`},children:[jsxs(Ia,{className:"fk:px-10",children:[jsx(La,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(Ma,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:m,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 Oa=createContext({isDirty:false,setIsDirty:e=>{}}),Va=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(Oa.Provider,{value:n,children:e})};function io(){return useContext(Oa)}function ao({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function so({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}var bf=["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 dr(e,t){let o=new URLSearchParams({filename:e.name}),n=await fetch(`${c$5(t).assets}?${o.toString()}`,{method:"POST",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!n.ok)throw new Error(`Upload failed for ${e.name}`);let r=await n.json(),i={_id:r._id,path:r.path??"",originalFilename:r.originalFilename??e.name,size:r.size??e.size,mimeType:r.mimeType??e.type,lqip:r.lqip??"",width:r.width??0,height:r.height??0};return {pathname:i.path,lqip:i.lqip||void 0,originalFilename:i.originalFilename,size:i.size,mimeType:i.mimeType,width:i.width||void 0,height:i.height||void 0,_id:i._id,asset:i}}async function wf(e){let{projectId:t,accept:o,multiple:n=true,maxBytes:r=4*1024*1024}=e,i=document.createElement("input");i.type="file";let a=o??bf.join(",");i.accept=a,i.multiple=n,i.style.display="none",document.body.appendChild(i);try{let s=await new Promise(d=>{i.onchange=()=>d(i.files),i.click();});if(!s||s.length===0)return [];let f=[];for(let d of Array.from(s)){if(d.size>r){toast.error(`File size too big (max ${(r/(1024*1024)).toFixed(0)}MB): ${d.name}`);continue}f.push(d);}let c=await Promise.all(f.map(async d=>dr(d,t)));return c.length>0&&toast.success(`Uploaded ${c.length} file${c.length>1?"s":""}`),c}catch(s){return console.error(s),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}function Ro(){let e=useApolloClient();return useCallback(async t=>{let o=await wf(t);return o.length>0&&await mt(e,"GetAssets").catch(n=>{console.error("Error refreshing asset lists after upload:",n);}),o},[e])}function lo(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 Ga({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:f$1}=useParams(),c$1=ae(),d=d$2(),{relationships:m$1}=c$2(),[l,u]=useState(false),g$1=useRef(null),p=useRef(null),v=useRef(null),[h$2,x]=useState(null),[b,w]=useState(false),[T,y]=useState(false),N=useId(),S=useId();lo(p,u,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let C=m$1[S]?.connect;if(!C||v.current===C._id)return;let k=If(C.value);if(!k)return;let I=n(i$1);v.current=C._id,x(null),r(i$1,{...I,value:k});},[n,i$1,S,m$1,r]);function D(C){if(!C)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[C])return k[C];let I=C.split("/");if(I.length===2){let[,F]=I;return F.includes("svg")?"svg":F.toLowerCase()}}function L(C,k){if(C&&C.includes(".")){let F=C.split(".").pop();if(F)return F.toLowerCase()}let I=D(k);return I||"file"}async function z(C,k){if(!C)return;let I=mr("4MB");if(C.size>(I??0)){toast.error("File size too big (max 4MB)");return}let F=C.type.startsWith("image/");if(v.current=null,F){let B=new FileReader;B.onload=M=>{x(M.target?.result);},B.readAsDataURL(C);}else x(null);y(true);try{let B=await dr(C,f$1);r(i$1,{...n(i$1),value:B.asset});}catch(B){console.error(B),x(null),r(i$1,{...n(i$1),value:{_id:k?.value?._id}});}finally{y(false);}}function X$1(C){C.stopPropagation(),v.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function Q(C,k){C.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function P(C){C.preventDefault(),C.stopPropagation(),g$1.current?.click();}function _(C){C.preventDefault(),C.stopPropagation(),u(false);let k=n(i$1)?.value,I=v.current??Lf(k),F=I?{_id:I,value:k}:void 0;d({type:"setRelationship",payload:{[S]:{connect:F,disconnect:[]}}}),window.setTimeout(()=>{c$1({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:F,relationshipId:S,mode:"single"}});},0);}function O(C,k){C.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:C})=>jsxs(e,{children:[jsx(f,{htmlFor:N,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":l,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 ${l?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${b?"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(),u(true);},onKeyDown:k=>{k.key==="Enter"&&u(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),u(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),w(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),w(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),w(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),w(false);let I=k.dataTransfer.files&&k.dataTransfer.files[0];z(I,C.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!C.value?.value?.path&&!h$2?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,{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:N,onClick:P,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:_,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,C.value?.value?.path&&!l?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=C.value?.value,I=k?.mimeType,F=k?.path||"";if(!!(I&&I.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(F)))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 M=L(k.originalFilename,k.mimeType),Z=defaultStyles[M];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:M,...Z||{}})})})(),mr((C.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(C.value?.value).mimeType,(C.value?.value).width&&(C.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(C.value?.value).width,"x",(C.value?.value).height,"px"]}):null]}):null,!C.value?.value?.path&&h$2&&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:h$2,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..."]}),!C.value?.value?.path&&!h$2&&T?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,C.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:P,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:_,children:[jsx(Image,{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=>O(k,C.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>Q(k,C.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:X$1,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!l&&(C.value?.value?.path||h$2)?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}),l&&(C.value?.value?.path||h$2)?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(),u(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),u(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(ao,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:u,open:l&&(!!C.value?.value?.path||!!h$2),children:jsx(so,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:C.value?.value?.path?(()=>{let k=C.value?.value,I=k?.mimeType,F=k?.path||"";if(!!(I&&I.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(F)))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 M=L(k.originalFilename,k.mimeType),Z=defaultStyles[M];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:M,...Z||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",mr(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),T?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 I=k.currentTarget.files&&k.currentTarget.files[0];z(I,C.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function If(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 Lf(e){return !e?._id||e._id.includes(":")?"":e._id}function Wa({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,f$1=useId();function c$1(m,l){let u=m.currentTarget.value,g;u===""?g="":(g=s==="float"?parseFloat(u):parseInt(u,10),isNaN(g)&&(g="")),o(n,{...l,value:g});}function d(m,l){o(n,{...l,disabled:m});}return jsx(c,{control:e$1,name:n,render:({field:m})=>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] ${!m.value?.scope||m.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||m.value?.disabled,id:f$1,...m,onChange:l=>{c$1(l,m.value);},step:s==="float"?"any":"1",type:"number",value:m.value?.value??""})}),jsx(b$2,{checked:m.value?.disabled??false,onChange:l=>{d(l,m.value);},scope:m.value?.scope}),jsx(i,{})]})})}function co({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function fo({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Tt({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 Ka({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:c=>c.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:c,rootRef:d,...m})=>jsx("div",{"data-slot":"calendar",ref:d,className:a$4(c),...m}),Chevron:({className:c,orientation:d,...m})=>d==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",c),...m}):d==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",c),...m}):jsx(ChevronDownIcon,{className:a$4("size-4",c),...m}),DayButton:zf,WeekNumber:({children:c,...d})=>jsx("td",{...d,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:c})}),...a},...s})}function zf({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=gn.useRef(null);return gn.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 Ya({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,f$1=useId();function c$1(l,u){n(r,{...u,value:l?l.toISOString():""});}function d(l,u){n(r,{...u,disabled:l});}function m(l){l.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:l})=>jsxs(e,{onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),u.stopPropagation());},children:[jsx(f,{htmlFor:f$1,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(co,{children:[jsx(fo,{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",!l.value?.value&&"fk:text-muted-foreground",!l.value?.scope||l.value.scope==="default"?"fk:mb-3":""),disabled:a===false||l.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:l.value?.value?format(new Date(l.value.value),"PPP")+" at "+format(new Date(l.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[l.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:u=>{u.stopPropagation(),m(u);},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(Tt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Ka,{mode:"single",selected:l.value?.value?new Date(l.value.value):void 0,onSelect:u=>c$1(u,l.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:u=>{let g=u.target.value,[p,v]=g.split(":"),h=l.value?.value?new Date(l.value.value):new Date;h.setHours(parseInt(p)),h.setMinutes(parseInt(v)),n(r,{...l.value,value:h.toISOString()});},type:"time",value:l.value?.value?format(new Date(l.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:l.value?.disabled??false,onChange:u=>{d(u,l.value);},scope:l.value?.scope}),jsx(i,{})]})})}function Ne(e){return e??null}var gr=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=Ne(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=Ne(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=Ne(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");}}]),es=Command.configure({suggestion:{items:()=>gr,render:renderItems}});var os=[{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"}],ns=[{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)"}],rs=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=os.find(({color:i})=>o.isActive("textStyle",{color:i})),r=ns.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(co,{modal:true,open:e,onOpenChange:t,children:[jsx(fo,{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(Tt,{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"}),os.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"}),ns.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 pd(e){try{return new URL(e),!0}catch{return false}}function gd(e){if(pd(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var as=({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(Tt,{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=gd(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 ls=[{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=Ne(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=Ne(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=Ne(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=Ne(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ne(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ne(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")}],cs=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=ls.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:ls.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 ds=()=>{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 us=()=>{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=Ne(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=Ne(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=Ne(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=Ne(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 Fo({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 _d=()=>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"})]}),ms=_d;function vr({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 Zd=[{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 wr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:Zd.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 gs({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(c,d)=>{let m=await fetch(c,d);if(m.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return m},onError:c=>{c.message!=="FK_AI_RATE_LIMIT"&&toast.error(c.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(iu,{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(Fo,{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(ms,{})})]}),!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 c=t.state.selection.content(),d=t.storage.markdown.serializer.serialize(c.content);a(d,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:f?jsx(vr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(wr,{onSelect:(c,d)=>a(c,{body:{option:d}})})})]})]}):null}function xr({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(gs,{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(Fo,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var xu=[...a,es];function hs(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 Eu(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(hs(o))return o}catch{return}}if(hs(e))return e}function Er({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[f$1,c$1]=useState(false),[d,m]=useState(false),[l,u]=useState(false),[g$1,p]=useState(false),v=useDebouncedCallback((b,w)=>{let T=b.getJSON();n(r,{...w,value:JSON.stringify(T)});},300);function h$1(b,w){n(r,{...w,disabled:b});}let x=b=>(console.log("Image uploader not yet implemented",b),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:b})=>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&&!b.value?.disabled,editorProps:{handleDOMEvents:{keydown:(w,T)=>handleCommandNavigation(T)},handlePaste:(w,T)=>handleImagePaste(w,T,x),handleDrop:(w,T,y,N)=>handleImageDrop(w,T,N,x),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:xu,initialContent:Eu(b.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:w})=>{v(w,b.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:gr.map(w=>jsxs(EditorCommandItem,{value:w.title,onCommand:T=>w.command?.(T),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:w.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:w.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:w.description})]})]},w.title))})]}),jsxs(xr,{open:f$1,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx(cs,{open:d,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(as,{open:l,onOpenChange:u}),jsx(g$3,{orientation:"vertical"}),jsx(ds,{}),jsx(g$3,{orientation:"vertical"}),jsx(us,{}),jsx(g$3,{orientation:"vertical"}),jsx(rs,{open:g$1,onOpenChange:p})]})]},`${r}:${b.value?.scope??t.scope}:${String(b.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:b.value?.disabled??false,onChange:w=>{h$1(w,b.value);},scope:b.value?.scope}),jsx(i,{})]})})}function Dr({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:f$1}=n,{projectId:c$1}=useParams(),d=ae(),m=d$2(),{relationships:l}=c$2(),u=Ro(),g$1=useId(),p=useId(),v$1=useRef(null),h$1=useRef([]),x=useRef(null),b=useRef([]),w=useRef(""),[T,y]=useState(false),N=useMemo(()=>Lu(t.value),[t.value]),[S,D]=useState(N);lo(v$1,y),useEffect(()=>{let P=Rt(N);h$1.current=N.map(_=>_._id),b.current=[],D(_=>{let O=Rt(_);return P===""&&O!==""&&w.current===O||O===P?_:(w.current=P,N)});},[N]),useEffect(()=>{let P=l[p]?.connect;if(!P)return;let _=P.map((I,F)=>ws(I.value,I.sortOrder??F)).filter(I=>!!I),O=Rt(_),C=Rt(S),k=x.current;k===C&&O!==k||(x.current=null,O!==C&&D(_));},[p,l,S]),useEffect(()=>{let P=Rt(S);if(w.current===P)return;let _=S.map((k,I)=>({_id:k._id,sortOrder:I,value:{...k,sortOrder:I}})),O=S.map(k=>k._id),C=b.current.filter(k=>!O.includes(k));w.current=P,m({type:"setRelationship",payload:{[p]:{connect:_,disconnect:C}}}),r(i$1,{...t,relationships:{connect:_,disconnect:C},value:S});},[m,t,i$1,p,S,r]);function L(P){P.preventDefault(),P.stopPropagation(),d({type:"EditRelationship",payload:{connectedEntitiesCount:S.length,entityName:f$1?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function z(P){P.preventDefault(),P.stopPropagation();let _=await u({projectId:c$1,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});D(O=>{let C=new Set(O.map(F=>F._id)),k=_.map((F,B)=>({...F.asset,sortOrder:O.length+B})).filter(F=>!C.has(F._id)),I=Ar([...O,...k]);return x.current=Rt(I),I});}function X$1(P){D(_=>{let O=Ar(_.filter(C=>C._id!==P));return h$1.current.includes(P)&&!b.current.includes(P)&&(b.current=[...b.current,P]),x.current=Rt(O),O});}function Q(P,_){D(O=>{let C=O.findIndex(M=>M._id===P),k=C+_;if(C<0||k<0||k>=O.length)return O;let I=[...O],[F]=I.splice(C,1);if(!F)return O;I.splice(k,0,F);let B=Ar(I);return x.current=Rt(B),B});}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":T,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 ${T?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:P=>{P.preventDefault(),P.stopPropagation(),v$1.current?.focus(),y(true);},ref:v$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:[T&&S.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[S.length," ",S.length===1?"asset":"assets"," selected"]}):S.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[S.slice(0,8).map(P=>jsx(Fu,{asset:P},P._id)),!T&&S.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:["+",S.length-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{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:P=>{P.preventDefault(),P.stopPropagation(),y(_=>!_);},size:"icon",variant:"ghost",children:T?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:T?"Close":"Expand field"})})]})})]}),jsx(ao,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:y,open:T,children:jsx(so,{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:L,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:P=>{z(P);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),S.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:S.map((P,_)=>jsx(Iu,{asset:P,index:_,isFirst:_===0,isLast:_===S.length-1,moveAsset:Q,removeAsset:X$1},P._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Fu({asset:e}){return Cs(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,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function Iu({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:Cs(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,{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 Lu(e){return Array.isArray(e)?e.map((t,o)=>ws(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Rt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function Ar(e){return e.map((t,o)=>({...t,sortOrder:o}))}function ws(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 Cs(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Es({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 wn({column:e,title:t,className:o}){if(!e.getCanSort())return jsx("div",{className:a$4("fk:flex fk:items-center",o),children:t});let n=e.getIsSorted()==="asc",r=e.getIsSorted()==="desc";return jsxs("div",{className:a$4("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",o),children:[jsx("span",{className:"fk:truncate",children:t}),jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsx("button",{"aria-label":`Sort ${t}`,className:"fk:inline-flex fk:shrink-0 fk:items-center fk:justify-center fk:rounded-sm fk:p-0.5 fk:text-muted-foreground fk:outline-hidden fk:hover:bg-accent fk:hover:text-accent-foreground fk:focus-visible:ring-1 fk:focus-visible:ring-ring",type:"button",children:jsx(ChevronDown,{className:"fk:h-3.5 fk:w-3.5"})})}),jsxs(f$2,{align:"end",className:"fk:w-44",children:[jsxs(h$1,{"aria-checked":n,className:a$4(n&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(n){e.clearSorting();return}e.toggleSorting(false);},role:"menuitemcheckbox",children:[jsx(ArrowUp,{className:a$4("fk:h-4 fk:w-4",n&&"fk:text-white")}),"Sort Ascending"]}),jsxs(h$1,{"aria-checked":r,className:a$4(r&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(r){e.clearSorting();return}e.toggleSorting(true);},role:"menuitemcheckbox",children:[jsx(ArrowDown,{className:a$4("fk:h-4 fk:w-4",r&&"fk:text-white")}),"Sort Descending"]})]})]})]})}var Ou=new Set(["text","textarea","number","datetime","switch","select","editor"]);function Oo({attributesSchema:e,checkboxSelect:t,actionsComponent:o,enableColumnSorting:n=false}){let{getContributionPointConfig:r}=d(),i={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"select",switch:"boolean",text:"text",textarea:"text"},a={boolean:a$a,date:a$9,datetime:a$d,editor:b$7,asset:a$c,number:a$9,relationship:a$9,select:a$b,switch:a$a,text:a$9,textarea:a$9,tags:Es},s=e.map(l=>{if(l.name==="_updatedAt")return null;let u=(l.inputType==="relationship"&&l.relationship?.entity==="_asset"?"asset":void 0)??l.previewType??i[l.inputType],g=r("previewFields",[u])?.[0]?.component??a[u]??a.text;if(l.isHidden)return null;let p=u==="tags",v=n&&l.scope==="global"&&Ou.has(l.inputType);return {accessorKey:l.name,filterFn:(h,x,b)=>p?true:(Array.isArray(b)?b:[b]).includes(h.getValue(x)),header:({column:h})=>v?jsx(wn,{column:h,title:l.label}):jsx("div",{className:"fk:flex fk:items-center",children:l.label}),cell:({row:h})=>{let x=g;return u==="select"?jsx(x,{value:h.getValue(l.name),options:l.options}):jsx(x,{value:h.getValue(l.name)})},enableSorting:v,enableHiding:true,meta:{label:l.label},size:l.options?.size??150}}).filter(l=>l!==null),f={id:"actions",cell:({row:l})=>o?o(l):null,size:80},c={accessorKey:"_updatedAt",header:({column:l})=>n?jsx(wn,{column:l,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:l})=>jsx(a$d,{value:l.getValue("_updatedAt")}),enableSorting:n,enableHiding:false,meta:{label:"Updated At"},size:220},d$1={id:"select",cell:({row:l,table:u})=>jsx(a$e,{"aria-label":"Select row",checked:l.getIsSelected(),onCheckedChange:g=>{u.toggleAllPageRowsSelected(false),l.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50},m={id:"select",header:({table:l})=>jsx(a$e,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:l.getIsAllPageRowsSelected()||l.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:u=>{l.toggleAllPageRowsSelected(!!u);}}),cell:({row:l})=>jsx(a$e,{"aria-label":"Select row",checked:l.getIsSelected(),onCheckedChange:u=>{l.toggleSelected(!!u);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[d$1]:[],...t==="multiple"?[m]:[],...o?[f]:[],...s,c]}var Ju=36;function As(e){if(!e)return;let t=e.split(/\s+/);if(t.includes("fk:h-20"))return 80;if(t.includes("fk:h-10"))return 40;if(t.includes("fk:h-9"))return 36}function Xu(e,t){return e??As(t)??Ju}function Qu(e){return Math.max(600,e)}function Vo({classNames:e,columns:t,data:o,entityName:n$1,hasMore:r=false,initialSelectionState:i,isLoadingMore:a=false,onEntitySelectionChange:s,onLoadMore:f,onScroll:c,onSortingChange:d,pageSize:m,rowHeightEstimate:l$1,rowAdditionState:u,rowDeletionState:g,scrollToTopKey:p,sorting:v,toolbarComponent:h}){let x=useRef(null),{schemaErrorMessage:b}=Vt(),[w,T]=useState(i??{}),[y,N]=useState({}),[S,D]=useState([]),[L,z]=useState([]),X=v??L;useEffect(()=>{x.current?.scrollTo({top:0});},[n$1,p]),useEffect(()=>{if(!i)return;let V=Object.keys(w).sort().join(","),U=Object.keys(i).sort().join(",");V!==U&&T(i);},[i,w]);function Q(V){if(d){d(V);return}z(V);}let P=useReactTable({data:o,columns:t,state:{sorting:X,columnVisibility:y,rowSelection:w,columnFilters:S},initialState:{pagination:{pageSize:m??50}},enableRowSelection:true,onRowSelectionChange:re,onSortingChange:Q,onColumnFiltersChange:D,onColumnVisibilityChange:N,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:V=>V._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:V=>Gu(V,g,u)}}),{rows:_}=P.getRowModel(),O=Xu(l$1,e?.row),C=As(e?.row)!=null,k=useVirtualizer({count:_.length,estimateSize:()=>O,getScrollElement:()=>x.current,overscan:5}),I=k.getVirtualItems(),F=k.getTotalSize(),B=useRef(f),M=useRef(r),Z=useRef(a);B.current=f,M.current=r,Z.current=a;let K=useCallback(V=>{if(!B.current||!M.current||Z.current)return;let U=V??x.current;if(!U)return;let{scrollHeight:$,scrollTop:Ge,clientHeight:Mt}=U;$-Ge-Mt>=Qu(Mt)||(Z.current=true,B.current());},[]);useEffect(()=>{K();},[K,_.length,r,a]);function re(V){let U=Object.keys(typeof V=="function"?V(w):V);T(V),s?.(U);}function ne(V){c?.(V),K(V.currentTarget);}return b?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:min-w-0 fk:flex-col fk:gap-4",e?.wrapper),children:[h&&h(P),jsx("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1 fk:-mb-px",children:jsxs(h$2,{className:a$4("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:ne,ref:x,children:[jsx(i$1,{className:"fk:sticky fk:top-0 fk:z-10 fk:grid",children:P.getHeaderGroups().map(V=>jsx(l,{className:"fk:flex fk:w-full",children:V.headers.map(U=>jsxs(m$1,{className:a$4("fk:flex fk:items-center",U.column.id==="actions"&&"fk:pl-0"),colSpan:U.colSpan,style:U.getSize()?{width:`${U.getSize().toString()}px`}:{},children:[U.isPlaceholder?null:flexRender(U.column.columnDef.header,U.getContext()),a?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-10.25 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-4",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null]},U.id))},V.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${F.toString()}px`},children:I.length?I.map(V=>{let U=_[V.index];return jsx(l,{className:a$4(P.options.meta.getRowBackground(U),"fk:flex fk:absolute fk:w-full fk:overflow-hidden",!C&&l$1==null&&"fk:h-9",e?.row),"data-index":V.index,"data-state":U.getIsSelected()&&"selected",style:{height:`${O.toString()}px`,transform:`translateY(${V.start.toString()}px)`},children:U.getVisibleCells().map($=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",$.column.id==="actions"&&"fk:pl-1!"),style:{width:$.column.getSize()},children:flexRender($.column.columnDef.cell,$.getContext())},$.id))},V.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function Gu(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 Ts({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var cm=25;function Ir({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:f$1,setValue:c$1}){let[d,m]=useState(false),l=useRef(null);lo(l,m);let[u,g$1]=useState([]),{name:p,label:v,options:h$1,relationship:x}=a,b=x?.entity??p,w=ae(),T=d$2(),{relationships:y}=c$2(),N=useId(),S=useId(),D=find(propEq(b,"name"))(s),L=D?.attributes??[],X$1=find(propEq(r,"name"))(s)?.name??"",Q,P=L.find($=>$.relationship?.entity===X$1);P&&(Q=P.name);let _=dm(L),O=useMemo(()=>o.value?um({data:o.value,defaultScope:t,relationshipEntitySchema:D,scope:f$1}):[],[t,o,_,D,f$1]),C=xa({attributeName:p,relatedEntityName:b,scope:f$1,schema:s}),I=u.length?u.slice(0,12).map($=>$[_]):[],F=Math.max(u.length,o.count??0)>I.length,[B,{loading:M,data:Z}]=useLazyQuery(gql`
434
- ${C.query}
435
- `),K=Oo({attributesSchema:D?.attributes??[],actionsComponent:$=>fm({appDispatch:T,relationshipId:S,relationships:y,row:$,setRows:g$1})});useEffect(()=>{g$1(O),o.value!==""&&T({type:"setRelationship",payload:{[S]:{connect:[],disconnect:[]}}});},[T,Z,O,S,o,f$1]),useEffect(()=>{c$1(p,{...o,relationships:y[S]});},[o,y,S,c$1,p]),useEffect(()=>{let Ge=(y[S]?.connect??[]).map(({value:Mt})=>Mt);g$1(uniqBy(prop("_id"),[...Ge,...O]));},[Z,o.count,O,y,S]);let re=o.count??0,ne=re>0&&u.length>0&&u.length<re,V=useCallback(()=>{M||B({variables:{limit:cm,offset:u.length,where:Q?{[Q]:{some:{_id:{eq:n}}}}:{}}}).then(({data:$})=>{if(!$)return;let Ge=ln(D?.plural??"",f$1,$,s);g$1(uniqBy(prop("_id"),[...O,...Ge.results]));}).catch($=>{console.error("Error fetching more data:",$);});},[Q,n,B,O,M,D?.plural,u.length,s,f$1]);function U($){$.preventDefault(),w({type:"EditRelationship",payload:{connectedEntitiesCount:O.length,connectionName:Q,entityName:b,entityId:n,relationshipId:S,mode:x?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:N,children:v}),h$1?.comment?jsx(h,{children:h$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${p}`,"aria-expanded":d,className:`fk:relative fk:flex fk:w-full fk:min-w-0 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 ${d?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:$=>{$.preventDefault(),$.stopPropagation(),l.current?.focus(),l.current?.click(),m(true);},onKeyDown:$=>{$.key==="Enter"&&m(true),$.key==="Escape"&&($.preventDefault(),$.stopPropagation(),l.current?.blur(),m(false));},ref:l,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[d?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:U,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",D?.menu?.label??D?.plural]}):jsxs("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:[I.map($=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:$},$)),F?jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:"\u2026"}):null]}),d?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(),l.current?.blur(),m(false);},onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),$.stopPropagation(),l.current?.blur(),m(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:N,onKeyDown:$=>{$.key==="Enter"&&(l.current?.focus(),l.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(ao,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:m,open:d,children:jsx(so,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${p}`,children:jsx(Vo,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:K,data:u,entityName:r,hasMore:ne,isLoadingMore:M&&u.length>0,onLoadMore:V,rowAdditionState:y[S]?.connect,rowDeletionState:y[S]?.disconnect})})})})]})})}),jsx(i,{})]})})}function fm({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",c=o[t]?.disconnect?.includes(a),d=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&r(m=>m.filter(l=>l._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(m=>m._id!==a),disconnect:c?o[t]?.disconnect?.filter(m=>m!==a)??[]:d}}});}return jsx(Ts,{action:i,row:n})}function dm(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function um({data:e,defaultScope:t,relationshipEntitySchema:o,scope:n}){if(!Array.isArray(e))return [];let r=i=>{let s=find(propEq(i.__typename,"name"))(o?.attributes??[])?.relationship?.field??"";if(s){let f=i[s],c=Array.isArray(f)?f[0]:f;return c&&typeof c=="object"?c[n]??c[t]??"":c}return i[n]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let s=a;return s.length===0?"":s.length===1?r(s[0]):s.slice(0,3).map(r).join(", ")}return a&&typeof a!="string"&&a.__typename?r(a):a},i))}function Lr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:f$1}){let[c$1,d]=useState(false),{name:m,label:l,options:u,relationship:g$1}=r,p=g$1?.entity??m,v=ae(),h$1=d$2(),x=useId(),{relationships:b}=c$2(),w=useId(),T=find(propEq(p,"name"))(a),N=ym(T?.attributes??[]).name;useEffect(()=>{o.value!==""&&h$1({type:"setRelationship",payload:{[w]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[h$1,w,o,s]),useEffect(()=>{f$1(m,{...i$1(m),...b[w]?.connect??""});},[o,m,b,w,f$1]);function S(L){L.preventDefault(),v({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:w,mode:g$1?.mode??"single"}});}function D(L){let z={type:"setRelationship",payload:{[w]:{connect:[],disconnect:[]}}};L.preventDefault(),h$1(z),f$1(m,{...i$1(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:m,render:({field:L})=>{let z=L.value?.value,X$1="";if(z&&typeof z=="object"&&!Array.isArray(z)&&z[N]){let Q=z[N],P=Array.isArray(Q)?Q[0]:Q;typeof P=="string"?X$1=P:X$1=P?.[s]??P?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:x,children:l}),u?.comment?jsx(h,{children:u.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${c$1?"fk:outline-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:x,onBlur:()=>{d(false);},onClick:S,onFocus:()=>{d(true);},onKeyDown:Q=>{Q.key==="Enter"&&S(Q);},readOnly:true,type:"text",value:X$1}),X$1?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:D,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:S,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 ym(e){return e.find(t=>t.isPrimary)??e[0]}function Mr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(Lr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(Dr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(Ir,{...n})}return jsxs(de,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Le,{children:"Error"}),jsx(ue,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var Ls="flexkit-select-option:";function $r(e){return `${Ls}${encodeURIComponent(e)}`}function wm(e){return decodeURIComponent(e.slice(Ls.length))}function Ms({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(c,d){let l=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;o(n,{...d,value:l});}function f$2(c,d){o(n,{...d,disabled:c});}return jsx(c,{control:e$2,name:n,render:({field:c})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:c.value?.value===void 0||c.value.value===null?void 0:$r(String(c.value.value)),disabled:i$1===false||c.value?.disabled,onValueChange:d=>{s(wm(d),c.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(d=>"groupLabel"in d?jsxs(b$1,{children:[jsx(f$1,{children:d.groupLabel}),d.items.map(m=>jsx(g$1,{value:$r(m.value),children:m.label},m.label))]},d.groupLabel):jsx(g$1,{value:$r(d.value),children:d.label},d.label))})]}),jsx(b$2,{checked:c.value?.disabled??false,onChange:d=>{f$2(d,c.value);},scope:c.value?.scope}),jsx(i,{})]})})}function Vr({inputType:e,label:t}){return jsxs(de,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Le,{children:"Error"}),jsx(ue,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Lm(e,t){let o=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:o}}function Mm({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:f},c){let d$1=find(propEq(n,"name"))(a),m=useMemo(()=>d$1?.attributes??[],[d$1]),l=useMemo(()=>i||m.reduce((D,L)=>({...D,[L.name]:Lm(L,t)}),{}),[t,i,m]),u=useMemo(()=>{let D={};for(let L of m)typeof L.validation>"u"||(D[L.name]=z.object({value:L.validation(z).or(z.any().refine(()=>false,{error:L.label?`${L.label} is required`:"Required field"}))}));return z.object(D)},[m]),g=useForm({defaultValues:l,resolver:zodResolver(u),values:i,mode:"onBlur",criteriaMode:"all"}),{control:p,getValues:v,handleSubmit:h,setValue:x,watch:b$1,trigger:w}=g,{getContributionPointConfig:T}=d(),y=useRef(i),N=useRef(false);useEffect(()=>{N.current||(y.current=i);},[i]);let S={datetime:Ya,editor:Er,asset:Ga,number:Wa,relationship:Mr,select:Ms,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){w().then(()=>{h(()=>{let D=v();N.current=true,y.current=D,s(false),f(D,i);})();});},hasErrors(){N.current=false,y.current=i,s(true);},hasDataChanged(){return Os(v(),y.current)},markAsSaved(){N.current=true,y.current=v(),s(false);}})),useEffect(()=>{let D=b$1(()=>{s(Os(v(),y.current));});return ()=>{D.unsubscribe();}},[i,v,s,b$1]),!d$1||d$1.attributes.length===0?jsxs(de,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Le,{children:"Error"}),jsxs(ue,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...g,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:m.map(D=>{if(D.name==="_id")return null;let L=T("formFields",[D.inputType])?.[0]?.component??S[D.inputType];return L?createElement(L,{key:D.name,control:p,defaultScope:t,defaultValue:l[D.name],entityId:o,entityName:n,entityNamePlural:r,fieldSchema:D,getValues:v,schema:a,scope:e,setValue:x}):jsx(Vr,{inputType:D.inputType,label:D.label},D.name)})})})}var Dn=memo(forwardRef(Mm));function Os(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 Hr({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),c=f?.find(D=>D.isDefault)?.name??"default",m=find(propEq(n,"name"))(s)?.plural??n,{scope:l}=c$2(),u=ae(),g=useApolloClient(),[p,v,h,x]=ut(),{isDirty:b,setIsDirty:w}=io();useEffect(()=>{x.error&&r.current?.hasErrors();},[x.error]);function T(){return b?(u({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:()=>{u({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{u({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let y=useCallback(D=>{u({type:"Dismiss",_id:D,payload:{}});},[u]),N=useCallback(()=>{r.current?.submit();},[r]),S=useCallback(D=>{let L=v4(),z=nr(m,s,D,L);v(gql`
436
- ${z}
437
- `),h({onCompleted:()=>{mt(g,Ve(m,s)),y(e._id),toast.success("Your changes have been saved.");}}),p(true);},[e._id,g,m,y,p,s,v,h]);return jsx(jt,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",onClick:()=>{N();},variant:"default",children:[x.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]}),beforeClose:T,depth:t,isFocused:o,onClose:()=>{y(e._id);},title:`Add ${n}`,children:jsx(Dn,{currentScope:l,defaultScope:c,entityName:n,entityNamePlural:m,onSubmit:S,ref:r,schema:s,setIsDirty:w})})}function zo({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r,selection:i="full"}){let[a,s]=useState({count:0,results:[]}),[f,c]=useState(false),[d,m]=useState(false),l=useRef(false),u=useRef(false),g=useRef(0),p=useRef(null),v=useRef(null),h=er(e,o,t,{selection:i}),x=useMemo(()=>gql`
438
- ${h.query}
439
- `,[h.query]),{schemaErrorMessage:b,setSchemaErrorMessage:w}=Vt(),{loading:T,data:y,fetchMore:N,refetch:S,error:D,networkStatus:L}=useQuery(x,{variables:n,notifyOnNetworkStatusChange:true}),z=useRef(N),X=useRef(S),Q=useRef(L);z.current=N,X.current=S;let P=_t(D),_=rn(D),{isProjectDisabled:O,isProjectReadOnly:C}=(()=>{if(P?.statusCode===403){let F=Ot(P.bodyText);if(F&&typeof F.code=="string"){if(F.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(F.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),k=useCallback(F=>{if(l.current||u.current)return;l.current=true,c(true);let B=F.variables.limit,M=g.current;z.current({...F,variables:{...F.variables,offset:M,limit:B}}).then(({data:Z})=>{let K=Bo({data:Z,entityNamePlural:e,isForm:r,schema:t,scope:o}),re=K.results.length;g.current=M+(re===0?0:Math.min(re,B)),s(ne=>{let V=uniqBy(prop("_id"),[...ne.results,...K.results]);return V.length===ne.results.length?{count:ne.results.length,results:ne.results}:{count:K.count,results:V}});}).catch(Z=>{console.error("Error fetching more data:",Z);}).finally(()=>{l.current=false,c(false);});},[e,r,t,o]),I=useCallback(()=>{u.current||(u.current=true,l.current=false,c(false),p.current=null,v.current=null,g.current=0,m(true),s({count:0,results:[]}),X.current().then(({data:F})=>{let B=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n}),M=Bo({data:F,entityNamePlural:e,isForm:r,schema:t,scope:o});p.current=B,v.current=null,g.current=Pn(n)+M.results.length,s(M);}).catch(F=>{console.error("Error reloading data:",F);}).finally(()=>{u.current=false,m(false);}));},[e,r,t,o,i,n]);return useEffect(()=>{if(_){w(_);return}y&&b&&!D&&w(null);},[y,D,b,_,w]),useEffect(()=>{if(D||_)return;let F=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n});if(p.current===F)return;if(T&&v.current!==F){v.current=F,g.current=0,s({count:0,results:[]});return}if(T)return;let B=Bo({data:y,entityNamePlural:e,isForm:r,schema:t,scope:o});p.current=F,v.current=null,g.current=Pn(n)+B.results.length,s(B);},[y,e,D,r,T,t,_,o,i,n]),useEffect(()=>{let F=Q.current;if(Q.current=L,D||_||u.current||F!==NetworkStatus.refetch||L!==NetworkStatus.ready||!y)return;let B=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n}),M=Bo({data:y,entityNamePlural:e,isForm:r,schema:t,scope:o});p.current=B,v.current=null,g.current=Pn(n)+M.results.length,s(M);},[y,e,D,r,L,t,_,o,i,n]),useEffect(()=>{if(r)return;let F=`Get${Ye(e)}`,B=Sa(K=>{if(!(!K.has(F)||l.current||u.current))return X.current().then(({data:re})=>{let ne=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n}),V=Bo({data:re,entityNamePlural:e,isForm:r,schema:t,scope:o});p.current=ne,v.current=null,g.current=Pn(n)+V.results.length,s(V);}).catch(re=>{console.error("Error soft-refreshing entity list:",re);})}),M=Aa((K,re)=>{K===F&&s(ne=>{let V=ne.results.filter($=>{let Ge=typeof $._id=="string"?$._id:void 0;return !Ge||!re.has(Ge)}),U=ne.results.length-V.length;return U===0?ne:{count:Math.max(0,ne.count-U),results:V}});}),Z=Ta((K,re)=>{K===F&&s(ne=>Gm(ne,re,n?.sort));});return ()=>{B(),M(),Z();}},[e,r,t,o,i,n]),{isLoading:T&&L!==NetworkStatus.refetch||d,isLoadingMore:f,fetchMore:k,reload:I,count:a.count,data:a.results,isProjectDisabled:O,isProjectReadOnly:C,schemaErrorMessage:b}}function Pn(e){let t=e?.offset;return typeof t=="number"&&Number.isFinite(t)?t:0}function Bo(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?ya(e.entityNamePlural,e.scope,e.data,e.schema):ln(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function Gm(e,t,o){let n=new Map(t.map(a=>[a._id,a])),r=false,i=e.results.map(a=>{let s=typeof a._id=="string"?a._id:void 0;if(!s)return a;let f=n.get(s);return f?(r=true,{...a,...f.attributes}):a});return r?{count:e.count,results:Wm(i,o)}:e}function Wm(e,t){if(!Array.isArray(t)||t.length===0)return e;let o=t[0];if(!o||typeof o!="object")return e;let[n,r]=Object.entries(o)[0]??[];if(!n||r!=="ASC"&&r!=="DESC")return e;let i=r==="DESC"?-1:1;return [...e].sort((a,s)=>{let f=a[n],c=s[n],d=typeof f=="string"?f:"",m=typeof c=="string"?c:"";return d.localeCompare(m)*i})}function qs(){return jsxs(de,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Le,{children:"Read Only Mode"}),jsxs(ue,{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}=io();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 Qr(){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 Zr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:f,scopes:c}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),d$3=c?.find(M=>M.isDefault)?.name??"default",m=find(propEq(r,"plural"))(f),l=m?.name??r,{scope:u}=c$2(),[g,p]=useState(u),v=ae(),h=d$2(),x=useApolloClient(),[b,w,T,y]=ut(),{isDirty:N,setIsDirty:S}=io(),D=useCallback(M=>{S(M);},[S]);useEffect(()=>{y.error&&i.current?.hasErrors();},[y.error]);let L=useCallback(()=>N?(v({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:()=>{v({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{v({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[e._id,v,N]),z=useCallback(M=>{v({type:"Dismiss",_id:M,payload:{}});},[v]),X=useCallback(()=>{i.current?.submit();},[i]);function Q(M){if(N){v({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),v({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(M),h({type:"setScope",payload:{projectId:s,scope:M}});}}}});return}p(M),h({type:"setScope",payload:{projectId:s,scope:M}});}let P=useCallback((M,Z)=>{if(!Z)return;let K=tr(r,n,g,f,Z,M);w(gql`
429
+ `}}var On=e=>e.charAt(0).toUpperCase()+e.slice(1);function nt(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(On).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function Ct(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}function Oa(e,t,n){if(!e||typeof e!="object")return {};let o=Ct(n,t);if(!o)return {};let r=`update${On(t)}`,i=e[r];if(!i||typeof i!="object")return {};let a=i[t],s=Array.isArray(a)?a[0]:void 0;return !s||typeof s!="object"?{}:o.attributes.reduce((l,c)=>{if(ue(c)!=="local")return l;let m=bt(s[c.name])?._id;return typeof m!="string"||m.length===0?l:{...l,[c.name]:m}},{})}var So=null,br=new Set,Va=[],Cr=new Set,wr=new Set,xr=new Set;function Ge(e,t){if(e==="_asset"||e==="_assets")return `Get${nt(a$f.plural)}`;let n=t.find(i=>i.plural===e),o=t.find(i=>i.name===e),r=n?.plural??o?.plural??e;return `Get${nt(r)}`}function Ba(e){return Cr.add(e),()=>{Cr.delete(e);}}function za(e){return wr.add(e),()=>{wr.delete(e);}}function ja(e){return xr.add(e),()=>{xr.delete(e);}}function Eo(e,t,n){let o=new Set(n.filter(Boolean));if(o.size>0)for(let r of wr)r(t,o);return wt(e,t)}function Ha(e,t){let n=t.filter(o=>!!o._id);if(n.length!==0)for(let o of xr)o(e,n);}function wt(e,t){return br.add(t),new Promise((n,o)=>{Va.push({resolve:n,reject:o}),So&&clearTimeout(So),So=setTimeout(()=>{let r=new Set(br),i=Va.splice(0);br.clear(),So=null,Promise.all([...Cr].map(a=>Promise.resolve(a(r)))).then(()=>{for(let{resolve:a}of i)a();}).catch(a=>{console.error("Error refreshing entity lists:",a);for(let{reject:s}of i)s(a);});},50);})}function Sr({action:e}){let{projects:t,currentProjectId:n}=d(),{schema:o}=find(propEq(n??"","projectId"))(t),r=useApolloClient(),[i,a,s]=vt(),l=de(),c=useRef(false),f=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],m=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),u=!!e.payload.silent,p=f.length>1;if(useEffect(()=>{!u||c.current||(c.current=true,g());},[u]),u)return jsx(Fragment,{});let d$1={dialogTitle:p?`Delete ${f.length} ${m}s`:`Delete ${m}`,dialogMessage:p?`Are you sure you want to delete the selected ${m}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${m}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>g()};function g(){let h=Mn(e.payload.entityName,o,f);return new Promise((y,C)=>{a(gql`
430
+ ${h}
431
+ `),s({variables:{where:_n(f)},update(v){for(let b of f)v.evict({id:b});},onCompleted:()=>{toast.success(p?"Items successfully deleted.":"Item successfully deleted."),Eo(r,Ge(e.payload.entityName,o),f),l({type:"Dismiss",_id:e._id,payload:{}}),y();},onError:v=>{C(v);}}),i(true);})}return jsx(Pn,{options:d$1})}var Ua=createContext({isDirty:false,setIsDirty:e=>{}}),Ja=({children:e})=>{let[t,n]=useState(false),o=useMemo(()=>({isDirty:t,setIsDirty:i=>{n(i);}}),[t,n]);return jsx(Ua.Provider,{value:o,children:e})};function mn(){return useContext(Ua)}function Er(e,t){return !t||t.length===0||e===void 0?true:e.some(n=>t.includes(n))}function pn(e,t){return e.filter(n=>Er(t,n.spaces))}function kf(e,t){return e.filter(n=>Er(t,n.spaces)).map(n=>({...n,attributes:pn(n.attributes,t)}))}var vf=["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 Tr(e,t){let n=new URLSearchParams({filename:e.name}),o=await fetch(`${c$5(t).assets}?${n.toString()}`,{method:"POST",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!o.ok)throw new Error(`Upload failed for ${e.name}`);let r=await o.json(),i={_id:r._id,path:r.path??"",originalFilename:r.originalFilename??e.name,size:r.size??e.size,mimeType:r.mimeType??e.type,lqip:r.lqip??"",width:r.width??0,height:r.height??0};return {pathname:i.path,lqip:i.lqip||void 0,originalFilename:i.originalFilename,size:i.size,mimeType:i.mimeType,width:i.width||void 0,height:i.height||void 0,_id:i._id,asset:i}}async function bf(e){let{projectId:t,accept:n,multiple:o=true,maxBytes:r=4*1024*1024}=e,i=document.createElement("input");i.type="file";let a=n??vf.join(",");i.accept=a,i.multiple=o,i.style.display="none",document.body.appendChild(i);try{let s=await new Promise(f=>{i.onchange=()=>f(i.files),i.click();});if(!s||s.length===0)return [];let l=[];for(let f of Array.from(s)){if(f.size>r){toast.error(`File size too big (max ${(r/(1024*1024)).toFixed(0)}MB): ${f.name}`);continue}l.push(f);}let c=await Promise.all(l.map(async f=>Tr(f,t)));return c.length>0&&toast.success(`Uploaded ${c.length} file${c.length>1?"s":""}`),c}catch(s){return console.error(s),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}function Vn(){let e=useApolloClient();return useCallback(async t=>{let n=await bf(t);return n.length>0&&await wt(e,"GetAssets").catch(o=>{console.error("Error refreshing asset lists after upload:",o);}),n},[e])}function gn(e,t,n){useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o);}},[t,e,n]),useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",o),()=>{document.removeEventListener("mousedown",o);}},[t,e]);}function es({control:e$1,entityId:t,fieldSchema:n,getValues:o,setValue:r}){let{name:i$2,label:a,options:s}=n,{projectId:l}=useParams(),c$1=de(),f$1=d$2(),{relationships:m$1}=c$2(),[u,p]=useState(false),d=useRef(null),g$1=useRef(null),h$2=useRef(null),[y,C]=useState(null),[v,b]=useState(false),[D,E]=useState(false),w=useId(),x=useId();gn(g$1,p,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let T=m$1[x]?.connect;if(!T||h$2.current===T._id)return;let k=If(T.value);if(!k)return;let V=o(i$2);h$2.current=T._id,C(null),r(i$2,{...V,value:k});},[o,i$2,x,m$1,r]);function $(T){if(!T)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[T])return k[T];let V=T.split("/");if(V.length===2){let[,W]=V;return W.includes("svg")?"svg":W.toLowerCase()}}function M(T,k){if(T&&T.includes(".")){let W=T.split(".").pop();if(W)return W.toLowerCase()}let V=$(k);return V||"file"}async function A(T,k){if(!T)return;let V=Dr("4MB");if(T.size>(V??0)){toast.error("File size too big (max 4MB)");return}let W=T.type.startsWith("image/");if(h$2.current=null,W){let ee=new FileReader;ee.onload=_=>{C(_.target?.result);},ee.readAsDataURL(T);}else C(null);E(true);try{let ee=await Tr(T,l);r(i$2,{...o(i$2),value:ee.asset});}catch(ee){console.error(ee),C(null),r(i$2,{...o(i$2),value:{_id:k?.value?._id}});}finally{E(false);}}function R(T){T.stopPropagation(),h$2.current=null,r(i$2,{...o(i$2),_id:"",value:{_id:o(i$2)?.value?._id}});}function j(T,k){T.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function H(T){T.preventDefault(),T.stopPropagation(),d.current?.click();}function G(T){T.preventDefault(),T.stopPropagation(),p(false);let k=o(i$2)?.value,V=h$2.current??Ff(k),W=V?{_id:V,value:k}:void 0;f$1({type:"setRelationship",payload:{[x]:{connect:W,disconnect:[]}}}),window.setTimeout(()=>{c$1({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:W,relationshipId:x,mode:"single"}});},0);}function Z(T,k){T.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$2,render:({field:T})=>jsxs(e,{children:[jsx(f,{htmlFor:w,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$2}`,"aria-expanded":u,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 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${v?"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(),g$1.current?.focus(),g$1.current?.click(),p(true);},onKeyDown:k=>{k.key==="Enter"&&p(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),p(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),b(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),b(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),b(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),b(false);let V=k.dataTransfer.files&&k.dataTransfer.files[0];A(V,T.value);},ref:g$1,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!T.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,{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:w,onClick:H,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:G,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,T.value?.value?.path&&!u?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=T.value?.value,V=k?.mimeType,W=k?.path||"";if(!!(V&&V.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(W)))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 _=M(k.originalFilename,k.mimeType),B=defaultStyles[_];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:_,...B||{}})})})(),Dr((T.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(T.value?.value).mimeType,(T.value?.value).width&&(T.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(T.value?.value).width,"x",(T.value?.value).height,"px"]}):null]}):null,!T.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..."]}),!T.value?.value?.path&&!y&&D?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,T.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$8,{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:H,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:G,children:[jsx(Image,{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=>Z(k,T.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>j(k,T.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:R,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!u&&(T.value?.value?.path||y)?jsx(a$8,{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"&&(g$1.current?.focus(),g$1.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}),u&&(T.value?.value?.path||y)?jsx(a$8,{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(),g$1.current?.blur(),p(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),p(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(i$1,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:p,open:u&&(!!T.value?.value?.path||!!y),children:jsx(k,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$2}`,children:T.value?.value?.path?(()=>{let k=T.value?.value,V=k?.mimeType,W=k?.path||"";if(!!(V&&V.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(W)))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 _=M(k.originalFilename,k.mimeType),B=defaultStyles[_];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:_,...B||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Dr(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),D?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$2}`,onChange:k=>{let V=k.currentTarget.files&&k.currentTarget.files[0];A(V,T.value);},ref:d,type:"file"}),jsx(i,{})]})})}function If(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 Ff(e){return !e?._id||e._id.includes(":")?"":e._id}function ts({control:e$1,fieldSchema:t,setValue:n}){let{name:o,label:r,isEditable:i$1,options:a,dataType:s}=t,l=useId();function c$1(m,u){let p=m.currentTarget.value,d;p===""?d="":(d=s==="float"?parseFloat(p):parseInt(p,10),isNaN(d)&&(d="")),n(o,{...u,value:d});}function f$1(m,u){n(o,{...u,disabled:m});}return jsx(c,{control:e$1,name:o,render:({field:m})=>jsxs(e,{children:[jsx(f,{htmlFor:l,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$7,{className:`fk:w-full fk:mt-[0.1875rem] ${!m.value?.scope||m.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||m.value?.disabled,id:l,...m,onChange:u=>{c$1(u,m.value);},step:s==="float"?"any":"1",type:"number",value:m.value?.value??""})}),jsx(a$6,{checked:m.value?.disabled??false,onChange:u=>{f$1(u,m.value);},scope:m.value?.scope}),jsx(i,{})]})})}function kn({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function hn({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Mt({className:e,align:t="center",sideOffset:n=4,...o}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:n,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),...o})})}function os({className:e,classNames:t,showOutsideDays:n=true,captionLayout:o="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let l=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:n,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:o,formatters:{formatMonthDropdown:c=>c.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",l.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",l.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",l.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",l.nav),button_previous:a$4(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",l.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",l.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)",l.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",l.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",l.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",l.dropdown),caption_label:a$4("fk:font-medium fk:select-none",o==="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",l.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",l.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",l.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",l.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",l.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",l.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",l.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",l.range_start),range_middle:a$4("fk:rounded-none",l.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",l.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",l.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",l.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",l.disabled),hidden:a$4("invisible",l.hidden),...t},components:{Root:({className:c,rootRef:f,...m})=>jsx("div",{"data-slot":"calendar",ref:f,className:a$4(c),...m}),Chevron:({className:c,orientation:f,...m})=>f==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",c),...m}):f==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",c),...m}):jsx(ChevronDownIcon,{className:a$4("size-4",c),...m}),DayButton:Bf,WeekNumber:({children:c,...f})=>jsx("td",{...f,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:c})}),...a},...s})}function Bf({className:e,day:t,modifiers:n,...o}){let r=getDefaultClassNames(),i=Do.useRef(null);return Do.useEffect(()=>{n.focused&&i.current?.focus();},[n.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.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),...o})}function rs({control:e$1,fieldSchema:t,getValues:n,setValue:o}){let{name:r,label:i$1,isEditable:a,options:s}=t,l=useId();function c$1(u,p){o(r,{...p,value:u?u.toISOString():""});}function f$1(u,p){o(r,{...p,disabled:u});}function m(u){u.preventDefault(),o(r,{...n(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:u})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:l,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(kn,{children:[jsx(hn,{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",!u.value?.value&&"fk:text-muted-foreground",!u.value?.scope||u.value.scope==="default"?"fk:mb-3":""),disabled:a===false||u.value?.disabled,id:l,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:u.value?.value?format(new Date(u.value.value),"PPP")+" at "+format(new Date(u.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[u.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:p=>{p.stopPropagation(),m(p);},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(Mt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(os,{mode:"single",selected:u.value?.value?new Date(u.value.value):void 0,onSelect:p=>c$1(p,u.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$7,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let d=p.target.value,[g,h]=d.split(":"),y=u.value?.value?new Date(u.value.value):new Date;y.setHours(parseInt(g)),y.setMinutes(parseInt(h)),o(r,{...u.value,value:y.toISOString()});},type:"time",value:u.value?.value?format(new Date(u.value.value),"HH:mm"):""})]})]})]})}),jsx(a$6,{checked:u.value?.disabled??false,onChange:p=>{f$1(p,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function $e(e){return e??null}var Pr=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 n=$e(e);n&&n.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 n=$e(e);n&&n.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 n=$e(e);n&&n.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 n=document.createElement("input");n.type="file",n.accept="image/*",n.onchange=async()=>{n.files?.length;},n.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(n??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:n??""}).run():n!==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 n=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(n??"")?e.chain().focus().deleteRange(t).setTweet({src:n??""}).run():n!==null&&alert("Please enter a correct Twitter Link");}}]),is=Command.configure({suggestion:{items:()=>Pr,render:renderItems}});var ss=[{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"}],ls=[{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)"}],cs=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=ss.find(({color:i})=>n.isActive("textStyle",{color:i})),r=ls.find(({color:i})=>n.isActive("highlight",{color:i}));return jsxs(kn,{modal:true,open:e,onOpenChange:t,children:[jsx(hn,{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:o?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(Mt,{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"}),ss.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{n.commands.unsetColor(),i!=="Default"&&n.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"}),ls.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{n.commands.unsetHighlight(),i!=="Default"&&n.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})]}),n.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function mu(e){try{return new URL(e),!0}catch{return false}}function pu(e){if(mu(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var us=({open:e,onOpenChange:t})=>{let n=useRef(null),{editor:o}=useEditor();return useEffect(()=>{n.current?.focus();}),o?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":o.isActive("link")}),children:"Link"})]})}),jsx(Mt,{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=pu(a.value);s&&(o.chain().focus().setLink({href:s}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:n,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:o.getAttributes("link").href||""}),o.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:()=>{o.chain().focus().unsetLink().run(),n.current&&(n.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 ms=[{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=$e(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=$e(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=$e(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=$e(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=$e(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")}],ps=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=ms.filter(r=>r.isActive(n)).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:o.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:ms.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})]}),o.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var ks=()=>{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:n,to:o}=e.state.selection,r=e.state.doc.textBetween(n,o);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 hs=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:n=>n!=null&&n.isActive("bold"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:n=>n!=null&&n.isActive("italic"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:n=>n!=null&&n.isActive("underline"),command:n=>n?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:n=>n!=null&&n.isActive("strike"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:n=>n!=null&&n.isActive("code"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleCode().run();},icon:CodeIcon}].map(n=>jsx(EditorBubbleItem,{onSelect:o=>{n.command(o);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:o=>o.preventDefault(),variant:"ghost",children:jsx(n.icon,{className:a$4("fk:h-4 fk:w-4",{"fk:text-blue-500":n.isActive(e)})})})},n.name))}):null};function Bn({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 Mu=()=>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"})]}),ys=Mu;function $r({completion:e,onDiscard:t$1}){let{editor:n}=useEditor();return n?jsxs(Fragment,{children:[jsxs(r$1,{children:[jsxs(t,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt({from:o.from,to:o.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:o}=n.view.state;n.chain().focus().insertContentAt(o.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r$1,{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 Wu=[{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 _r({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r$1,{heading:"Edit or review selection",children:Wu.map(n=>jsxs(t,{onSelect:o=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,o);},className:"fk:flex fk:gap-2 fk:px-4",value:n.value,children:[jsx(n.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),n.label]},n.value))}),jsx(s,{}),jsx(r$1,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let n=t$1.state.selection.from,o=getPrevText(t$1,n);e(o,"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 bs({onOpenChange:e}){let{editor:t}=useEditor(),[n,o$1]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(c,f)=>{let m=await fetch(c,f);if(m.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return m},onError:c=>{c.message!=="FK_AI_RATE_LIMIT"&&toast.error(c.message);}}),l=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[l&&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(rd,{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(Bn,{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(ys,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:n,onValueChange:o$1,autoFocus:true,placeholder:l?"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:n}}).then(()=>o$1(""));let c=t.state.selection.content(),f=t.storage.markdown.serializer.serialize(c.content);a(f,{body:{option:"zap",command:n}}).then(()=>o$1(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p$1,{children:l?jsx($r,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(_r,{onSelect:(c,f)=>a(c,{body:{option:f}})})})]})]}):null}function Vr({children:e,open:t,onOpenChange:n}){let{editor:o}=useEditor();return useEffect(()=>{o&&(t||removeAIHighlight(o));},[o,t]),o?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{n(false),o.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(bs,{open:t,onOpenChange:n}),!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(),n(true);},size:"sm",children:[jsx(Bn,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var wd=[...a,is];function ws(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 xd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let n=JSON.parse(t);if(ws(n))return n}catch{return}}if(ws(e))return e}function Br({control:e$1,defaultValue:t,fieldSchema:n,setValue:o}){let{name:r,label:i$1,isEditable:a,options:s}=n,[l,c$1]=useState(false),[f$1,m]=useState(false),[u,p]=useState(false),[d,g$1]=useState(false),h$1=useDebouncedCallback((v,b)=>{let D=v.getJSON();o(r,{...b,value:JSON.stringify(D)});},300);function y(v,b){o(r,{...b,disabled:v});}let C=v=>(console.log("Image uploader not yet implemented",v),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:v})=>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&&!v.value?.disabled,editorProps:{handleDOMEvents:{keydown:(b,D)=>handleCommandNavigation(D)},handlePaste:(b,D)=>handleImagePaste(b,D,C),handleDrop:(b,D,E,w)=>handleImageDrop(b,D,w,C),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:wd,initialContent:xd(v.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:b})=>{h$1(b,v.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:Pr.map(b=>jsxs(EditorCommandItem,{value:b.title,onCommand:D=>b.command?.(D),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:b.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:b.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:b.description})]})]},b.title))})]}),jsxs(Vr,{open:l,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx(ps,{open:f$1,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(us,{open:u,onOpenChange:p}),jsx(g$3,{orientation:"vertical"}),jsx(ks,{}),jsx(g$3,{orientation:"vertical"}),jsx(hs,{}),jsx(g$3,{orientation:"vertical"}),jsx(cs,{open:d,onOpenChange:g$1})]})]},`${r}:${v.value?.scope??t.scope}:${String(v.value?.disabled??t.disabled)}`)})}),jsx(a$6,{checked:v.value?.disabled??false,onChange:b=>{y(b,v.value);},scope:v.value?.scope}),jsx(i,{})]})})}var Fd=yo;function qr({control:e$1,defaultValue:t,entityId:n,entityName:o,entityNamePlural:r,fieldSchema:i$2,schema:a,setValue:s}){let{name:l,label:c$1,options:f$1,relationship:m}=i$2,{projectId:u}=useParams(),p=de(),d=d$2(),{relationships:g$1}=c$2(),h$1=Vn(),y=useId(),C=useId(),v$1=useRef(null),b=useRef([]),D=useRef(null),E=useRef([]),w=useRef(""),x=useRef(t.knownAssetSortOrders??{}),[$,M]=useState(false),A=useMemo(()=>Md(t.value),[t.value]),[R,j]=useState(A),[H,G]=useState(()=>Object.keys(t.knownAssetSortOrders??$n(A)).length),[Z,T]=useState(()=>Math.max(t.count??0,A[0]?.totalCount??0,A.length)),k$1=useMemo(()=>_a({attributeName:l,entityName:o,entityNamePlural:r,schema:a}),[o,r,l,a]),[V,{loading:W}]=useLazyQuery(gql`
432
+ ${k$1.query}
433
+ `);gn(v$1,M),useEffect(()=>{let I=St(A);b.current=A.map(Q=>Q._id),E.current=[];let U={...t.knownAssetSortOrders??{},...$n(A)};x.current=U,G(Object.keys(U).length),T(Math.max(t.count??0,A[0]?.totalCount??0,A.length)),j(Q=>{let se=St(Q);return I===""&&se!==""&&w.current===se||se===I?Q:(w.current=I,A)});},[t.count,t.knownAssetSortOrders,A]),useEffect(()=>{let I=g$1[C]?.connect;if(!I)return;let U=I.map((le,_e)=>As(le.value,le.sortOrder??_e)).filter(le=>!!le),Q=St(U),se=St(R),ge=D.current;ge===se&&Q!==ge||(D.current=null,Q!==se&&j(U));},[C,g$1,R]),useEffect(()=>{let I=St(R);if(w.current===I)return;let U=R.map((ge,le)=>({_id:ge._id,sortOrder:le,value:{...ge,sortOrder:le}})),Q=R.map(ge=>ge._id),se=E.current.filter(ge=>!Q.includes(ge));w.current=I,d({type:"setRelationship",payload:{[C]:{connect:U,disconnect:se}}}),s(l,{...t,knownAssetSortOrders:x.current,relationships:{connect:U,disconnect:se},value:R});},[d,t,l,C,R,s]);let ee=Math.max(Z,H),_=!!n&&ee>H,B=useCallback(()=>{if(!n||W||!_)return;let I=H+Fd;V({variables:{where:{_id:{eq:n}},first:I}}).then(U=>{let Q=U.data?.[r],ge=(Array.isArray(Q)?Q[0]:void 0)?.[`${l}Connection`],le=Co(ge),_e=le[0]?.totalCount;if(typeof _e=="number"&&T(_e),le.length===0){T(H);return}let z=Object.keys(x.current).length,ne={...x.current,...$n(le)},je=Object.keys(ne).length;x.current=ne,G(je),(le.length<I||je<=z)&&T(je);for(let He of le)b.current.includes(He._id)||(b.current=[...b.current,He._id]);j(He=>{let fe=new Set(He.map(Yn=>Yn._id)),Wo=new Set(E.current),Kn=le.filter(Yn=>!fe.has(Yn._id)&&!Wo.has(Yn._id));if(Kn.length===0)return w.current="",[...He];let wi=[...He,...Kn];return D.current=St(wi),wi});}).catch(U=>{console.error("Error fetching more assets:",U);});},[n,r,V,_,W,H,l]);function K(I){I.preventDefault(),I.stopPropagation(),p({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(R.length,ee),entityName:m?.entity??"_asset",entityId:n,relationshipId:C,mode:"multiple",assetAccept:f$1?.accept}});}async function te(I){I.preventDefault(),I.stopPropagation();let U=await h$1({projectId:u,accept:f$1?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});j(Q=>{let se=new Set(Q.map(_e=>_e._id)),ge=U.map((_e,z)=>({..._e.asset,sortOrder:Q.length+z})).filter(_e=>!se.has(_e._id)),le=jr([...Q,...ge]);return D.current=St(le),le});}function ye(I){j(U=>{let Q=jr(U.filter(se=>se._id!==I));return b.current.includes(I)&&!E.current.includes(I)&&(E.current=[...E.current,I]),D.current=St(Q),Q});}function L(I,U){j(Q=>{let se=Q.findIndex(ne=>ne._id===I),ge=se+U;if(se<0||ge<0||ge>=Q.length)return Q;let le=[...Q],[_e]=le.splice(se,1);if(!_e)return Q;le.splice(ge,0,_e);let z=jr(le);return D.current=St(z),z});}let O=Math.max(R.length,ee),P=R.slice(0,8);return jsx(c,{control:e$1,defaultValue:t,name:l,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:y,children:c$1}),f$1?.comment?jsx(h,{children:f$1.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-${l}`,"aria-expanded":$,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 ${$?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:I=>{I.preventDefault(),I.stopPropagation(),v$1.current?.focus(),M(true);},ref:v$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:[$&&R.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[O," ",O===1?"asset":"assets",_?` (${R.length} loaded)`:""," selected"]}):R.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[P.map(I=>jsx(Ld,{asset:I},I._id)),!$&&O>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:["+",O-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$8,{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:y,onClick:I=>{I.preventDefault(),I.stopPropagation(),M(U=>!U);},size:"icon",variant:"ghost",children:$?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:$?"Close":"Expand field"})})]})})]}),jsx(i$1,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:M,open:$,children:jsx(k,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${l}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:K,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=>{te(I);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),R.length>0?jsxs(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:R.map((I,U)=>jsx($d,{asset:I,index:U,isFirst:U===0,isLast:U===R.length-1,moveAsset:L,removeAsset:ye},I._id))}),_?jsx("div",{className:"fk:flex fk:justify-center fk:py-3 fk:pr-3",children:jsx(b$3,{className:"fk:h-8",disabled:W,onClick:I=>{I.preventDefault(),I.stopPropagation(),B();},type:"button",variant:"outline",children:W?"Loading\u2026":`Load more (${H} of ${ee})`})}):null]}):null]})})})]})})}),jsx(i,{})]})})}function Ld({asset:e}){return Ts(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,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function $d({asset:e,index:t,isFirst:n,isLast:o,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:Ts(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,{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:n,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:o,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 Md(e){return Array.isArray(e)?e.map((t,n)=>As(t,n)).filter(t=>!!t).sort((t,n)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function St(e){return e.map((t,n)=>`${t._id}:${t.sortOrder??n}`).join("|")}function jr(e){return e.map((t,n)=>({...t,sortOrder:n}))}function As(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let n=e;return {_id:String(n._id??""),path:String(n.path??""),originalFilename:String(n.originalFilename??""),size:Number(n.size??0),mimeType:String(n.mimeType??""),lqip:String(n.lqip??""),width:Number(n.width??0),height:Number(n.height??0),sortOrder:n.sortOrder??t,totalCount:typeof n.totalCount=="number"?n.totalCount:void 0}}function Ts(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Ds({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 Mo({column:e,title:t,className:n}){if(!e.getCanSort())return jsx("div",{className:a$4("fk:flex fk:items-center",n),children:t});let o=e.getIsSorted()==="asc",r=e.getIsSorted()==="desc";return jsxs("div",{className:a$4("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",n),children:[jsx("span",{className:"fk:truncate",children:t}),jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsx("button",{"aria-label":`Sort ${t}`,className:"fk:inline-flex fk:shrink-0 fk:items-center fk:justify-center fk:rounded-sm fk:p-0.5 fk:text-muted-foreground fk:outline-hidden fk:hover:bg-accent fk:hover:text-accent-foreground fk:focus-visible:ring-1 fk:focus-visible:ring-ring",type:"button",children:jsx(ChevronDown,{className:"fk:h-3.5 fk:w-3.5"})})}),jsxs(f$2,{align:"end",className:"fk:w-44",children:[jsxs(h$1,{"aria-checked":o,className:a$4(o&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(o){e.clearSorting();return}e.toggleSorting(false);},role:"menuitemcheckbox",children:[jsx(ArrowUp,{className:a$4("fk:h-4 fk:w-4",o&&"fk:text-white")}),"Sort Ascending"]}),jsxs(h$1,{"aria-checked":r,className:a$4(r&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(r){e.clearSorting();return}e.toggleSorting(true);},role:"menuitemcheckbox",children:[jsx(ArrowDown,{className:a$4("fk:h-4 fk:w-4",r&&"fk:text-white")}),"Sort Descending"]})]})]})]})}var Bd=new Set(["text","textarea","number","datetime","switch","select","editor"]);function Un({attributesSchema:e,checkboxSelect:t,actionsComponent:n,enableColumnSorting:o=false}){let{getContributionPointConfig:r}=d(),[,i]=b(),a=pn(e,i.user?.spaces),s={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"select",switch:"boolean",text:"text",textarea:"text"},l={boolean:a$b,date:a$a,datetime:a$e,editor:b$7,asset:a$d,number:a$a,relationship:a$a,select:a$c,switch:a$b,text:a$a,textarea:a$a,tags:Ds},c=a.map(d=>{if(d.name==="_updatedAt")return null;let g=(d.inputType==="relationship"&&d.relationship?.entity==="_asset"?"asset":void 0)??d.previewType??s[d.inputType],h=r("previewFields",[g])?.[0]?.component??l[g]??l.text;if(d.isHidden)return null;let y=g==="tags",C=o&&d.scope==="global"&&Bd.has(d.inputType);return {accessorKey:d.name,filterFn:(v,b,D)=>y?true:(Array.isArray(D)?D:[D]).includes(v.getValue(b)),header:({column:v})=>C?jsx(Mo,{column:v,title:d.label}):jsx("div",{className:"fk:flex fk:items-center",children:d.label}),cell:({row:v})=>{let b=h;return g==="select"?jsx(b,{value:v.getValue(d.name),options:d.options}):jsx(b,{value:v.getValue(d.name)})},enableSorting:C,enableHiding:true,meta:{label:d.label},size:d.options?.size??150}}).filter(d=>d!==null),f={id:"actions",cell:({row:d})=>n?n(d):null,size:80},m={accessorKey:"_updatedAt",header:({column:d})=>o?jsx(Mo,{column:d,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:d})=>jsx(a$e,{value:d.getValue("_updatedAt")}),enableSorting:o,enableHiding:false,meta:{label:"Updated At"},size:220},u={id:"select",cell:({row:d,table:g})=>jsx(j,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:h=>{g.toggleAllPageRowsSelected(false),d.toggleSelected(!!h);}}),enableSorting:false,enableHiding:false,size:50},p={id:"select",header:({table:d})=>jsx(j,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:d.getIsAllPageRowsSelected()||d.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:g=>{d.toggleAllPageRowsSelected(!!g);}}),cell:({row:d})=>jsx(j,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:g=>{d.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[u]:[],...t==="multiple"?[p]:[],...n?[f]:[],...c,m]}var Xd=36;function Ps(e){if(!e)return;let t=e.split(/\s+/);if(t.includes("fk:h-20"))return 80;if(t.includes("fk:h-10"))return 40;if(t.includes("fk:h-9"))return 36}function Gd(e,t){return e??Ps(t)??Xd}function Wd(e){return Math.max(600,e)}function Jn({classNames:e,columns:t,data:n$1,entityName:o,hasMore:r$1=false,initialSelectionState:i,isLoadingMore:a=false,onEntitySelectionChange:s,onLoadMore:l$1,onScroll:c,onSortingChange:f,pageSize:m,rowHeightEstimate:u,rowAdditionState:p$1,rowDeletionState:d,scrollToTopKey:g,sorting:h,toolbarComponent:y}){let C=useRef(null),{schemaErrorMessage:v}=Jt(),[b,D]=useState(i??{}),[E,w]=useState({}),[x,$]=useState([]),[M,A]=useState([]),R=h??M;useEffect(()=>{C.current?.scrollTo({top:0});},[o,g]),useEffect(()=>{if(!i)return;let L=Object.keys(b).sort().join(","),O=Object.keys(i).sort().join(",");L!==O&&D(i);},[i,b]);function j(L){if(f){f(L);return}A(L);}let H=useReactTable({data:n$1,columns:t,state:{sorting:R,columnVisibility:E,rowSelection:b,columnFilters:x},initialState:{pagination:{pageSize:m??50}},enableRowSelection:true,onRowSelectionChange:te,onSortingChange:j,onColumnFiltersChange:$,onColumnVisibilityChange:w,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:L=>L._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:L=>Zd(L,d,p$1)}}),{rows:G}=H.getRowModel(),Z=Gd(u,e?.row),T=Ps(e?.row)!=null,k=useVirtualizer({count:G.length,estimateSize:()=>Z,getScrollElement:()=>C.current,overscan:5}),V=k.getVirtualItems(),W=k.getTotalSize(),ee=useRef(l$1),_=useRef(r$1),B=useRef(a);ee.current=l$1,_.current=r$1,B.current=a;let K=useCallback(L=>{if(!ee.current||!_.current||B.current)return;let O=L??C.current;if(!O)return;let{scrollHeight:P,scrollTop:I,clientHeight:U}=O;P-I-U>=Wd(U)||(B.current=true,ee.current());},[]);useEffect(()=>{K();},[K,G.length,r$1,a]);function te(L){let O=Object.keys(typeof L=="function"?L(b):L);D(L),s?.(O);}function ye(L){c?.(L),K(L.currentTarget);}return v?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:min-w-0 fk:flex-col fk:gap-4",e?.wrapper),children:[y&&y(H),jsx("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1 fk:-mb-px",children:jsxs(l,{className:a$4("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:ye,ref:C,children:[jsx(m$1,{className:"fk:sticky fk:top-0 fk:z-10 fk:grid",children:H.getHeaderGroups().map(L=>jsx(p,{className:"fk:flex fk:w-full",children:L.headers.map(O=>jsxs(q,{className:a$4("fk:flex fk:items-center",O.column.id==="actions"&&"fk:pl-0"),colSpan:O.colSpan,style:O.getSize()?{width:`${O.getSize().toString()}px`}:{},children:[O.isPlaceholder?null:flexRender(O.column.columnDef.header,O.getContext()),a?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-10.25 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-4",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null]},O.id))},L.id))}),jsx(n,{className:"fk:grid fk:relative",style:{height:`${W.toString()}px`},children:V.length?V.map(L=>{let O=G[L.index];return jsx(p,{className:a$4(H.options.meta.getRowBackground(O),"fk:flex fk:absolute fk:w-full fk:overflow-hidden",!T&&u==null&&"fk:h-9",e?.row),"data-index":L.index,"data-state":O.getIsSelected()&&"selected",style:{height:`${Z.toString()}px`,transform:`translateY(${L.start.toString()}px)`},children:O.getVisibleCells().map(P=>jsx(r,{className:a$4("fk:flex fk:items-center fk:truncate",P.column.id==="actions"&&"fk:pl-1!"),style:{width:P.column.getSize()},children:flexRender(P.column.columnDef.cell,P.getContext())},P.id))},L.key)}):jsx(p,{children:jsx(r,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function Zd(e,t,n){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":n?.some(o=>o._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Is({action:e,row:t}){let n=t.original._id;function o(){e(n);}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:o,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var um=25;function Gr({control:e$1,defaultScope:t,defaultValue:n,entityId:o,entityName:r,entityNamePlural:i$2,fieldSchema:a,schema:s,scope:l,setValue:c$1}){let[f$1,m]=useState(false),u=useRef(null);gn(u,m);let[p,d]=useState([]),{name:g$1,label:h$1,options:y,relationship:C}=a,v=C?.entity??g$1,b=de(),D=d$2(),{relationships:E}=c$2(),w=useId(),x=useId(),$=find(propEq(v,"name"))(s),M=$?.attributes??[],R=find(propEq(r,"name"))(s)?.name??"",j,H=M.find(P=>P.relationship?.entity===R);H&&(j=H.name);let G=mm(M),Z=useMemo(()=>n.value?pm({data:n.value,defaultScope:t,relationshipEntitySchema:$,scope:l}):[],[t,n,G,$,l]),T=Ma({attributeName:g$1,relatedEntityName:v,scope:l,schema:s}),V=p.length?p.slice(0,12).map(P=>P[G]):[],W=Math.max(p.length,n.count??0)>V.length,[ee,{loading:_,data:B}]=useLazyQuery(gql`
434
+ ${T.query}
435
+ `),K=Un({attributesSchema:$?.attributes??[],actionsComponent:P=>dm({appDispatch:D,relationshipId:x,relationships:E,row:P,setRows:d})});useEffect(()=>{d(Z),n.value!==""&&D({type:"setRelationship",payload:{[x]:{connect:[],disconnect:[]}}});},[D,B,Z,x,n,l]),useEffect(()=>{c$1(g$1,{...n,relationships:E[x]});},[n,E,x,c$1,g$1]),useEffect(()=>{let I=(E[x]?.connect??[]).map(({value:U})=>U);d(uniqBy(prop("_id"),[...I,...Z]));},[B,n.count,Z,E,x]);let te=n.count??0,ye=te>0&&p.length>0&&p.length<te,L=useCallback(()=>{_||ee({variables:{limit:um,offset:p.length,where:j?{[j]:{some:{_id:{eq:o}}}}:{}}}).then(({data:P})=>{if(!P)return;let I=xo($?.plural??"",l,P,s);d(uniqBy(prop("_id"),[...Z,...I.results]));}).catch(P=>{console.error("Error fetching more data:",P);});},[j,o,ee,Z,_,$?.plural,p.length,s,l]);function O(P){P.preventDefault(),b({type:"EditRelationship",payload:{connectedEntitiesCount:Z.length,connectionName:j,entityName:v,entityId:o,relationshipId:x,mode:C?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:n,name:g$1,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:w,children:h$1}),y?.comment?jsx(h,{children:y.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${g$1}`,"aria-expanded":f$1,className:`fk:relative fk:flex fk:w-full fk:min-w-0 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 ${f$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:P=>{P.preventDefault(),P.stopPropagation(),u.current?.focus(),u.current?.click(),m(true);},onKeyDown:P=>{P.key==="Enter"&&m(true),P.key==="Escape"&&(P.preventDefault(),P.stopPropagation(),u.current?.blur(),m(false));},ref:u,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[f$1?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:O,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",$?.menu?.label??$?.plural]}):jsxs("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:[V.map(P=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:P},P)),W?jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:"\u2026"}):null]}),f$1?jsx(a$8,{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:P=>{P.preventDefault(),P.stopPropagation(),u.current?.blur(),m(false);},onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),P.stopPropagation(),u.current?.blur(),m(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$8,{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:w,onKeyDown:P=>{P.key==="Enter"&&(u.current?.focus(),u.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(i$1,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:m,open:f$1,children:jsx(k,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${g$1}`,children:jsx(Jn,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:K,data:p,entityName:r,hasMore:ye,isLoadingMore:_&&p.length>0,onLoadMore:L,rowAdditionState:E[x]?.connect,rowDeletionState:E[x]?.disconnect})})})})]})})}),jsx(i,{})]})})}function dm({appDispatch:e,relationshipId:t,relationships:n,row:o,setRows:r}){function i(a){let s=n[t]?.connect??[],l=typeof find(propEq(a,"_id"),s)=="object",c=n[t]?.disconnect?.includes(a),f=l?n[t]?.disconnect??[]:uniq([...n[t]?.disconnect??[],a]);l&&r(m=>m.filter(u=>u._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(m=>m._id!==a),disconnect:c?n[t]?.disconnect?.filter(m=>m!==a)??[]:f}}});}return jsx(Is,{action:i,row:o})}function mm(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function pm({data:e,defaultScope:t,relationshipEntitySchema:n,scope:o}){if(!Array.isArray(e))return [];let r=i=>{let s=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";if(s){let l=i[s],c=Array.isArray(l)?l[0]:l;return c&&typeof c=="object"?c[o]??c[t]??"":c}return i[o]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let s=a;return s.length===0?"":s.length===1?r(s[0]):s.slice(0,3).map(r).join(", ")}return a&&typeof a!="string"&&a.__typename?r(a):a},i))}function Wr({control:e$1,defaultScope:t,defaultValue:n,entityId:o,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:l}){let[c$1,f$1]=useState(false),{name:m,label:u,options:p,relationship:d}=r,g$1=d?.entity??m,h$1=de(),y=d$2(),C=useId(),{relationships:v}=c$2(),b=useId(),D=find(propEq(g$1,"name"))(a),w=bm(D?.attributes??[]).name;useEffect(()=>{n.value!==""&&y({type:"setRelationship",payload:{[b]:{connect:{_id:String(n._id),value:n.value},disconnect:[]}}});},[y,b,n,s]),useEffect(()=>{l(m,{...i$1(m),...v[b]?.connect??""});},[n,m,v,b,l]);function x(M){M.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:g$1,entityId:o,relationshipId:b,mode:d?.mode??"single"}});}function $(M){let A={type:"setRelationship",payload:{[b]:{connect:[],disconnect:[]}}};M.preventDefault(),y(A),l(m,{...i$1(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:n,name:m,render:({field:M})=>{let A=M.value?.value,R="";if(A&&typeof A=="object"&&!Array.isArray(A)&&A[w]){let j=A[w],H=Array.isArray(j)?j[0]:j;typeof H=="string"?R=H:R=H?.[s]??H?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:C,children:u}),p?.comment?jsx(h,{children:p.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$7,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:C,onBlur:()=>{f$1(false);},onClick:x,onFocus:()=>{f$1(true);},onKeyDown:j=>{j.key==="Enter"&&x(j);},readOnly:true,type:"text",value:R}),R?jsx(a$8,{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:$,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$8,{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:x,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 bm(e){return e.find(t=>t.isPrimary)??e[0]}function Zr(e){let{fieldSchema:t}=e,{relationship:n}=t;if(n?.mode==="single")return jsx(Wr,{...e});if(n?.mode==="multiple"){if(n.entity==="_asset")return jsx(qr,{...e});let o={relationshipEntityName:t.relationship?.entity,...e};return jsx(Gr,{...o})}return jsxs(ke,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(ze,{children:"Error"}),jsx(he,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var Vs="flexkit-select-option:";function Kr(e){return `${Vs}${encodeURIComponent(e)}`}function xm(e){return decodeURIComponent(e.slice(Vs.length))}function Bs({control:e$2,fieldSchema:t,setValue:n}){let{name:o,label:r,isEditable:i$1,options:a}=t;function s(c,f){let u=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;n(o,{...f,value:u});}function l(c,f){n(o,{...f,disabled:c});}return jsx(c,{control:e$2,name:o,render:({field:c})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:c.value?.value===void 0||c.value.value===null?void 0:Kr(String(c.value.value)),disabled:i$1===false||c.value?.disabled,onValueChange:f=>{s(xm(f),c.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(f=>"groupLabel"in f?jsxs(b$2,{children:[jsx(f$1,{children:f.groupLabel}),f.items.map(m=>jsx(g$1,{value:Kr(m.value),children:m.label},m.label))]},f.groupLabel):jsx(g$1,{value:Kr(f.value),children:f.label},f.label))})]}),jsx(a$6,{checked:c.value?.disabled??false,onChange:f=>{l(f,c.value);},scope:c.value?.scope}),jsx(i,{})]})})}function ti({inputType:e,label:t}){return jsxs(ke,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(ze,{children:"Error"}),jsx(he,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Mm(e,t){let n=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:n}}function _m({currentScope:e,defaultScope:t,entityId:n,entityName:o,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:l},c){let f=find(propEq(o,"name"))(a),[,m]=b(),u=m.user?.spaces,p=useMemo(()=>pn(f?.attributes??[],u),[f,u]),d$1=useMemo(()=>i||p.reduce((A,R)=>({...A,[R.name]:Mm(R,t)}),{}),[t,i,p]),g=useMemo(()=>{let A={};for(let R of p)typeof R.validation>"u"||(A[R.name]=z.object({value:R.validation(z).or(z.any().refine(()=>false,{error:R.label?`${R.label} is required`:"Required field"}))}));return z.object(A)},[p]),h=useForm({defaultValues:d$1,resolver:zodResolver(g),values:i,mode:"onBlur",criteriaMode:"all"}),{control:y,getValues:C,handleSubmit:v,setValue:b$2,watch:D,trigger:E}=h,{getContributionPointConfig:w}=d(),x=useRef(i),$=useRef(false);useEffect(()=>{$.current||(x.current=i);},[i]);let M={datetime:rs,editor:Br,asset:es,number:ts,relationship:Zr,select:Bs,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){E().then(()=>{v(()=>{let A=C();$.current=true,x.current=A,s(false),l(A,i);})();});},hasErrors(){$.current=false,x.current=i,s(true);},hasDataChanged(){return Hs(C(),x.current)},markAsSaved(){$.current=true,x.current=C(),s(false);},applyLocalAttributeIds(A){let R=C(),j={...R};for(let[H,G]of Object.entries(A)){let Z=R[H];!Z||Z._id||!G||(j[H]={...Z,_id:G});}$.current=true,x.current=j;for(let[H,G]of Object.entries(j))G!==R[H]&&b$2(H,G,{shouldDirty:false,shouldTouch:false,shouldValidate:false});s(false);}})),useEffect(()=>{let A=D(()=>{s(Hs(C(),x.current));});return ()=>{A.unsubscribe();}},[i,C,s,D]),!f||f.attributes.length===0?jsxs(ke,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Error"}),jsxs(he,{children:["No attributes found in the schema for entity ",jsx("strong",{children:o})]})]}):jsx(b$1,{...h,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:p.map(A=>{if(A.name==="_id")return null;let R=w("formFields",[A.inputType])?.[0]?.component??M[A.inputType];return R?createElement(R,{key:A.name,control:y,defaultScope:t,defaultValue:d$1[A.name],entityId:n,entityName:o,entityNamePlural:r,fieldSchema:A,getValues:C,schema:a,scope:e,setValue:b$2}):jsx(ti,{inputType:A.inputType,label:A.label},A.name)})})})}var Ho=memo(forwardRef(_m));function Hs(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let n=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",o=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>o(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:n(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>o(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:n(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 Us(e){return e?e!=="viewer":true}function Et(){let[,e]=b();return Us(e.user?.role)}function ri({action:e,depth:t,isFocused:n}){let{entityName:o}=e.payload,r=useRef(null),i=Et(),{projects:a,currentProjectId:s}=d(),{schema:l,scopes:c}=find(propEq(s??"","projectId"))(a),f=c?.find(M=>M.isDefault)?.name??"default",u$1=find(propEq(o,"name"))(l)?.plural??o,{scope:p}=c$2(),d$1=de(),g=useApolloClient(),[h,y,C,v]=vt(),{isDirty:b,setIsDirty:D}=mn();useEffect(()=>{v.error&&r.current?.hasErrors();},[v.error]);function E(){return b?(d$1({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:()=>{d$1({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{d$1({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let w=useCallback(M=>{d$1({type:"Dismiss",_id:M,payload:{}});},[d$1]),x=useCallback(()=>{r.current?.submit();},[r]),$=useCallback(M=>{let A=v4(),R=vr(u$1,l,M,A);y(gql`
436
+ ${R}
437
+ `),C({onCompleted:()=>{wt(g,Ge(u$1,l)),w(e._id),toast.success("Your changes have been saved.");}}),h(true);},[e._id,g,u$1,w,h,l,y,C]);return jsx(h$2,{actions:jsx(u,{disabled:!i,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{x();},variant:"default",children:[v.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:E,depth:t,isFocused:n,onClose:()=>{w(e._id);},title:`Add ${o}`,children:jsx(Ho,{currentScope:p,defaultScope:f,entityName:o,entityNamePlural:u$1,onSubmit:$,ref:r,schema:l,setIsDirty:D})})}function Xn({entityNamePlural:e,schema:t,scope:n,variables:o,isForm:r,selection:i="full"}){let[a,s]=useState({count:0,results:[]}),[l,c]=useState(false),[f,m]=useState(false),u=useRef(false),p=useRef(false),d=useRef(0),g=useRef(null),h=useRef(null),y=wo(e,n,t,{selection:i}),C=useMemo(()=>gql`
438
+ ${y.query}
439
+ `,[y.query]),v=wo(e,n,t,{selection:i,includeCount:false}),b=useMemo(()=>gql`
440
+ ${v.query}
441
+ `,[v.query]),{schemaErrorMessage:D,setSchemaErrorMessage:E}=Jt(),{loading:w,data:x,fetchMore:$,refetch:M,error:A,networkStatus:R}=useQuery(C,{variables:o,notifyOnNetworkStatusChange:true}),j=useRef($),H=useRef(M),G=useRef(b),Z=useRef(R);j.current=$,H.current=M,G.current=b;let T=qt(A),k=po(A),{isProjectDisabled:V,isProjectReadOnly:W}=(()=>{if(T?.statusCode===403){let B=Ut(T.bodyText);if(B&&typeof B.code=="string"){if(B.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(B.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),ee=useCallback(B=>{if(u.current||p.current)return;u.current=true,c(true);let K=B.variables.limit,te=d.current;j.current({...B,query:G.current,variables:{...B.variables,offset:te,limit:K}}).then(({data:ye})=>{let L=Qn({data:ye,entityNamePlural:e,isForm:r,schema:t,scope:n}),O=L.results.length;d.current=te+(O===0?0:Math.min(O,K)),s(P=>{let I=uniqBy(prop("_id"),[...P.results,...L.results]);return I.length===P.results.length?{count:P.results.length,results:P.results}:{count:L.count||P.count,results:I}});}).catch(ye=>{console.error("Error fetching more data:",ye);}).finally(()=>{u.current=false,c(false);});},[e,r,t,n]),_=useCallback(B=>{if(p.current)return Promise.resolve();let K=B?.preserve===true;return p.current=true,u.current=false,c(false),K||(g.current=null,h.current=null,d.current=0,m(true),s({count:0,results:[]})),H.current().then(({data:te})=>{let ye=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),L=Qn({data:te,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=ye,h.current=null,d.current=Jo(o)+L.results.length,s(L);}).catch(te=>{console.error("Error reloading data:",te);}).finally(()=>{p.current=false,m(false);})},[e,r,t,n,i,o]);return useEffect(()=>{if(k){E(k);return}x&&D&&!A&&E(null);},[x,A,D,k,E]),useEffect(()=>{if(A||k)return;let B=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o});if(g.current===B)return;if(w&&h.current!==B){h.current=B,d.current=0,s({count:0,results:[]});return}if(w)return;let K=Qn({data:x,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=B,h.current=null,d.current=Jo(o)+K.results.length,s(K);},[x,e,A,r,w,t,k,n,i,o]),useEffect(()=>{let B=Z.current;if(Z.current=R,A||k||p.current||B!==NetworkStatus.refetch||R!==NetworkStatus.ready||!x)return;let K=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),te=Qn({data:x,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=K,h.current=null,d.current=Jo(o)+te.results.length,s(te);},[x,e,A,r,R,t,k,n,i,o]),useEffect(()=>{if(r)return;let B=`Get${nt(e)}`,K=Ba(L=>{if(!(!L.has(B)||u.current||p.current))return H.current().then(({data:O})=>{let P=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),I=Qn({data:O,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=P,h.current=null,d.current=Jo(o)+I.results.length,s(I);}).catch(O=>{console.error("Error soft-refreshing entity list:",O);})}),te=za((L,O)=>{L===B&&s(P=>{let I=P.results.filter(Q=>{let se=typeof Q._id=="string"?Q._id:void 0;return !se||!O.has(se)}),U=P.results.length-I.length;return U===0?P:{count:Math.max(0,P.count-U),results:I}});}),ye=ja((L,O)=>{L===B&&s(P=>Gm(P,O,o?.sort));});return ()=>{K(),te(),ye();}},[e,r,t,n,i,o]),{isLoading:w&&R!==NetworkStatus.refetch||f,isLoadingMore:l,fetchMore:ee,reload:_,count:a.count,data:a.results,isProjectDisabled:V,isProjectReadOnly:W,schemaErrorMessage:D}}function Jo(e){let t=e?.offset;return typeof t=="number"&&Number.isFinite(t)?t:0}function Qn(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Pa(e.entityNamePlural,e.scope,e.data,e.schema):xo(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function Gm(e,t,n){let o=new Map(t.map(a=>[a._id,a])),r=false,i=e.results.map(a=>{let s=typeof a._id=="string"?a._id:void 0;if(!s)return a;let l=o.get(s);return l?(r=true,{...a,...l.attributes}):a});return r?{count:e.count,results:Wm(i,n)}:e}function Wm(e,t){if(!Array.isArray(t)||t.length===0)return e;let n=t[0];if(!n||typeof n!="object")return e;let[o,r]=Object.entries(n)[0]??[];if(!o||r!=="ASC"&&r!=="DESC")return e;let i=r==="DESC"?-1:1;return [...e].sort((a,s)=>{let l=a[o],c=s[o],f=typeof l=="string"?l:"",m=typeof c=="string"?c:"";return f.localeCompare(m)*i})}function Ks(){return jsxs(ke,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Read Only Mode"}),jsxs(he,{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 li({handleSave:e,isLoading:t}){let{isDirty:n}=mn(),o=Et();return jsx(u,{disabled:!o,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!n||!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 ci(){return jsx(Fragment,{children:Array.from({length:10},(t,n)=>n++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$2,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(r$2,{className:"fk:w-5 fk:mr-2"}),jsx(r$2,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function di({action:e,depth:t,isFocused:n}){let{entityId:o,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:l,scopes:c}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),f=c?.find(_=>_.isDefault)?.name??"default",m=find(propEq(r,"plural"))(l),u=m?.name??r,{scope:p}=c$2(),[d$3,g]=useState(p),h=de(),y=d$2(),C=useApolloClient(),[v,b,D,E]=vt(),{isDirty:w,setIsDirty:x}=mn(),$=useCallback(_=>{x(_);},[x]);useEffect(()=>{E.error&&i.current?.hasErrors();},[E.error]);let M=useCallback(()=>w?(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,[e._id,h,w]),A=useCallback(_=>{h({type:"Dismiss",_id:_,payload:{}});},[h]),R=useCallback(()=>{i.current?.submit();},[i]);function j(_){if(w){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:()=>{g(d$3),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{g(_),y({type:"setScope",payload:{projectId:s,scope:_}});}}}});return}g(_),y({type:"setScope",payload:{projectId:s,scope:_}});}let{isLoading:H,data:G}=Xn({entityNamePlural:r,schema:l,scope:d$3,variables:{where:{_id:{eq:o}}},isForm:true}),Z=useCallback((_,B)=>{if(!B)return;let K=hr(r,o,d$3,l,B,_);b(gql`
440
442
  ${K}
441
- `),T({variables:{where:{_id:{eq:n}}},onCompleted:()=>{i.current?.markAsSaved(),mt(x,Ve(r,f)),toast.success("Your changes have been saved.");}}),b(true);},[x,g,n,r,b,f,w,T]),{isLoading:_,data:O}=zo({entityNamePlural:r,schema:f,scope:g,variables:{where:{_id:{eq:n}}},isForm:true}),C=O,k=C.length>0,I=_&&!k;function F(M,Z){let K=M?.attributes.find($=>$.isPrimary)??M?.attributes[0],re=K.name,ne=K?.relationship?.field!==void 0;if(!Z.length)return "";if(!ne||!K?.relationship?.field)return Z[0][re]?.value;let V=Z[0][re]?.value?.[K.relationship.field],U=Array.isArray(V)?V[0]:V;if(U&&typeof U=="object"){let $=U;return $[g]??$.default??""}return U??""}let B=k&&m?F(m,C):"";return jsx(jt,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:M=>{Q(M);},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"))(c).label})]}),jsx(e$1,{children:c.map(M=>jsx(g$1,{value:M.name,children:M.label},M.name))})]}):null,jsx(Xr,{handleSave:X,isLoading:y.loading})]}),beforeClose:L,depth:t,isFocused:o,onClose:()=>{z(e._id);},onFormChange:()=>{},title:B,children:I||!k?jsx(Qr,{}):jsxs(Fragment,{children:[y.isProjectReadOnly?jsx(qs,{}):null,jsx(Dn,{currentScope:g,defaultScope:d$3,entityId:n,entityName:l,entityNamePlural:r,formData:C[0],onSubmit:P,ref:i,schema:f,setIsDirty:D})]})})}var Ws=25;function up(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function ei({action:e,depth:t,isFocused:o}){let n=ae(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:f,connectionName:c,entityId:d$1,entityName:m,initialAssetPath:l,initialConnection:u,mode:g,relationshipId:p}=e.payload,{projects:v,currentProjectId:h}=d(),{schema:x}=find(propEq(h??"","projectId"))(v),b=find(propEq(m,"name"))(x),w=b?.plural??"",T=i[p],y=Ro(),N=m==="_asset",S=N?"asset":b?.menu?.label??m.toLowerCase(),D=N&&g==="single"?"Select asset":`Select ${N?"assets":S}`,L=g==="single"?"Upload asset":"Upload assets",[z,X]=useState([]),Q=[];if(u)Q=[{id:u._id,value:u.value}];else if(T?.connect){let q=T.connect;Q=[{id:q._id,value:q.value}];}let P=g==="single"?Q:T?.connect?.map(q=>({id:q._id,value:q.value}))||[],[_,O]=useState(P),C=useMemo(()=>{let q=[];return N&&q.push({NOT:{path:{eq:null}}}),g==="multiple"&&c&&d$1&&q.push({[c]:{none:{_id:{eq:d$1}}}}),z.length>0&&q.push({OR:z.map(ie=>({_id:{eq:ie._id}}))}),q.length===0?{}:q.length===1?q[0]:{AND:q}},[c,d$1,N,g,z]),{count:k,data:I,fetchMore:F,isLoading:B,isLoadingMore:M}=zo({entityNamePlural:w,schema:x,scope:a,variables:{offset:0,limit:Ws,where:C,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]}}),Z=!!I?.length,K=B&&!Z,re=I?.length??0,ne=k-f,V=ne>0&&re>0&&re<ne,U=Oo({attributesSchema:b?.attributes??[],checkboxSelect:g}),$=Array(5).fill({}),Ge=up(U);useEffect(()=>{if(g!=="single"||_.length>0||!l||!I?.length)return;let q=I.find(ie=>ie.path===l);!q?._id||typeof q._id!="string"||O([{id:q._id,value:q}]);},[I,l,g,_.length]);let Mt=useCallback(q=>{n({type:"Dismiss",_id:q,payload:{}});},[n]),si=useCallback(()=>{F({variables:{offset:0,limit:Ws,where:C}});},[C,F]);function dl(){let q;if(g==="single"){let[ie]=_;q={_id:ie?.id??"",value:ie?.value??null};}g==="multiple"&&(q=_?.map((ie,nt)=>({_id:ie.id??"",...N?{sortOrder:nt}:{},value:ie.value}))),r({type:"setRelationship",payload:{[p]:{connect:q,disconnect:T?.disconnect??[]}}}),Mt(e._id);}function ul(q){if(g==="multiple"){O(nt=>{let Xt=new Map(nt.map(ce=>[ce.id,ce]));return q.map(ce=>{if(Xt.has(ce))return Xt.get(ce);let gl=I?.find(kl=>kl._id===ce);return {id:ce,value:gl}})});return}let ie=q[q.length-1];O(ie?nt=>{if(nt.length===1&&nt[0].id===ie)return nt;let Xt=I?.find(ce=>ce._id===ie);return [{id:ie,value:Xt}]}:[]);}function ml(){n({type:"AddEntity",payload:{entityName:m}});}async function pl(){let q=await y({projectId:h,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});O(ie=>{if(g==="single"){let[ce]=q;return ce?[{id:ce._id,value:ce.asset}]:ie}let nt=new Set(ie.map(ce=>ce.id)),Xt=q.filter(ce=>!nt.has(ce._id)).map(ce=>({id:ce._id,value:ce.asset}));return [...ie,...Xt]});}return jsx(jt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{dl();},variant:"default",children:"Select"}),N?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{ml();},variant:"outline",children:`Create ${S}`}),N?jsxs(b$3,{className:"fk:px-8",onClick:()=>{pl();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),L]}):null]}),depth:t,isFocused:o,onClose:()=>{Mt(e._id);},title:D,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Vo,{columns:K?Ge:U,data:K?$:I??[],entityName:b?.name??"",hasMore:V,initialSelectionState:_?.reduce((q,ie)=>({...q,...ie.id?{[ie.id]:true}:{}}),{}),isLoadingMore:M,onEntitySelectionChange:ul,onLoadMore:si,toolbarComponent:()=>jsx(mp,{entityNamePlural:w,projectId:h??"",setSearchResultIds:X})})})})}function mp({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:c}=e$5(t,a),d=useRef(null),m=useMemo(()=>pp(u=>{s({...i,commonParams:{q:u}});},300),[i]);useEffect(()=>{if(f){let u=JSON.stringify(f.map(p=>p._id).sort()),g=d.current?JSON.stringify(d.current.map(p=>p._id).sort()):"";u!==g&&(d.current=[...f],o(f.map(p=>({_id:p._id}))));}},[f,o]);function l(u){let{value:g}=u.target;r(g),m(g);}return jsxs("div",{className:"fk:relative fk:w-full",children:[c?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$6,{className:"fk:w-full fk:pl-11!",onChange:l,placeholder:"Search",value:n})]})}function pp(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Ks(){let e=ma(),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(So,{options:r.options},n._id)}case "DeleteEntity":return jsx(lr,{action:n},n._id);case "AddEntity":return jsx(Hr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Zr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(ei,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Ys({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$g(o);return window.location.pathname===r&&(window.location.href=b$b(r,n)),jsx(a$j,{children:jsx(c$6,{config:e,children:jsxs(Ki,{children:[jsx(Va,{children:jsx(Ks,{})}),jsx(Outlet,{})]})})})}function el(){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})})]}):qn(e)?_i(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(Yo,{})]})})]})}function oi(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(de,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Le,{children:"Error"}),jsx(ue,{children:t})]})}var Np=RouterProvider;function Pp({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(d=>tl(d)):[tl(e)],[i]=r,a=a$g(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let f=[{path:a,element:jsx(Ys,{config:r}),errorElement:jsx(el,{}),children:[{path:":projectId",element:jsx(qi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(d=>({path:d.name,element:d.component,errorElement:jsx(oi,{}),children:d.routes?.map(m=>({path:m.path,element:m.component,errorElement:jsx(oi,{}),children:m.children?.map(l=>({path:l.path,element:l.component}))}))}))}]}],c=createBrowserRouter(f);return n("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(ua,{children:jsx(Np,{router:c})})})})}function tl(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 Fp(){return jsxs(de,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Le,{children:"Project Paused"}),jsxs(ue,{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 Lp(){let{schemaErrorMessage:e}=Vt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
442
- `);return jsxs(de,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Le,{children:"Schema mismatch"}),jsxs(ue,{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 $p(e){return e}function _p(e,t){if(e.dataType==="asset"&&e.scope!==void 0&&e.scope!=="global")throw new Error(`Attribute "${e.name}" in entity "${t}" uses dataType "asset" but scope "${e.scope}". Asset attributes must use scope "global" or omit scope.`)}function Op(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function rl(e){return e.attributes.forEach(t=>{_p(t,e.name);}),{...e,attributes:e.attributes.map(Op)}}function Vp(e){return rl(e)}function jp(e){let t=useApolloClient(),{currentProjectSchema:o}=d();return useCallback(async()=>{o&&await mt(t,Ve(e,o));},[t,e,o])}function qp(e){let{currentProjectSchema:t}=d();return useCallback(o=>{t&&Da(Ve(e,t),o);},[e,t])}function Xp({column:e,title:t$1,options:o$1}){let n=new Set(e?.getFilterValue());return jsxs(co,{children:[jsx(fo,{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,n?.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:n.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:n.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[n.size," selected"]}):o$1.filter(r=>n.has(r.value)).map(r=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:r.label},r.value))})]})]})}),jsx(Tt,{className:"fk:w-50 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(r=>{let i=n.has(r.value);return jsxs(t,{onSelect:()=>{i?n.delete(r.value):n.add(r.value);let a=Array.from(n);e?.setFilterValue(a.length?a: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",i?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),r.icon&&jsx(r.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:r.label})]},r.value)})}),n.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 Gp({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(PencilIcon,{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(Trash2Icon,{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:[jsxs(h$1,{onClick:a,children:[jsx(PencilIcon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Edit"]}),jsx(m,{}),jsxs(h$1,{className:"fk:text-destructive",onClick:s,children:[jsx(Trash2Icon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete"]})]})]})]})}function ri({table:e}){let[t]=e.getState().sorting;if(!t)return null;let n=e.getColumn(t.id)?.columnDef.meta?.label??t.id,r=t.desc?"desc":"asc";return jsxs(b$3,{"aria-label":`Clear sorting by ${n}`,className:"fk:h-8 fk:px-2 fk:lg:px-3 fk:text-success fk:border-none",onClick:()=>{e.resetSorting();},size:"sm",variant:"outline",children:["Sorted by ",n," ",r,jsx(X,{className:"fk:ml-1 fk:h-4 fk:w-4"})]})}function ai({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 ag({entityName:e,isReloading:t=false,onReload:o,table:n}){let r=ae(),i=d$2(),a=c$2(),s=useApolloClient(),{projects:f,currentProjectId:c}=d(),{schema:d$3,scopes:m}=find(propEq(c??"","projectId"))(f),[l,u,g]=ut(),[p,v]=useState(false),h=n.getSelectedRowModel().rows.map(y=>y.original._id);function x(){r({type:"AddEntity",payload:{entityName:e}});}function b(y){i({type:"setScope",payload:{projectId:c,scope:y}});}async function w(y){if(y.length===0)return;let N=No(e,d$3,y);await new Promise((S,D)=>{u(gql`
443
- ${N}
444
- `),g({variables:{where:Po(y)},update(L){for(let z of y)L.evict({id:z});},onCompleted:()=>{S();},onError:L=>{D(L);}}),l(true);});}function T(){let y=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${h.length} ${y}${h.length>1?"s":""}`,dialogMessage:h.length>1?`Are you sure you want to delete the selected ${y}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${y}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{v(true);try{let N=[...h];await w(N),n.resetRowSelection(),await dn(s,Ve(e,d$3),N),toast.success(N.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{v(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:[m&&m.length>0?jsxs(a$5,{defaultValue:a.scope,onValueChange:y=>{b(y);},value:a.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(a.scope??"","name"))(m)||null)?.label})]}),jsx(e$1,{children:m.map(y=>jsx(g$1,{value:y.name,children:y.label},y.name))})]}):null,jsx(ai,{table:n}),o?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:p||t,onClick:o,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(ri,{table:n})]}),h.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:p,onClick:T,size:"sm",variant:"destructive",children:[p?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 (",h.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:p,onClick:x,size:"sm",variant:"default",children:"Create"})]})}export{Vo as DataTable,wn as DataTableColumnHeader,Xp as DataTableFacetedFilter,Gp as DataTableRowActions,ri as DataTableSortedBy,ag as DataTableToolbar,ai as DataTableViewOptions,Pp as FlexkitStudio,Fp as ProjectDisabled,Lp as SchemaError,$p as defineConfig,Vp as defineEntity,nr as getEntityCreateMutation,No as getEntityDeleteMutation,Po as getEntityDeleteWhere,er as getEntityQuery,zt as getEntitySchema,tr as getEntityUpdateMutation,ae as useDispatch,ut as useEntityMutation,zo as useEntityQuery,Vt as useGraphQLError,Oo as useGridColumnsDefinition,qp as usePatchEntityList,jp as useRefreshEntityList,Ro as useUploadAssets};//# sourceMappingURL=index.js.map
443
+ `),D({variables:{where:{_id:{eq:o}}},onCompleted:te=>{i.current?.applyLocalAttributeIds(Oa(te,r,l)),wt(C,Ge(r,l)),toast.success("Your changes have been saved.");}}),v(true);},[C,d$3,o,r,v,l,b,D]),T=G,k=T.length>0,V=H&&!k;function W(_,B){let K=_?.attributes.find(P=>P.isPrimary)??_?.attributes[0],te=K.name,ye=K?.relationship?.field!==void 0;if(!B.length)return "";if(!ye||!K?.relationship?.field)return B[0][te]?.value;let L=B[0][te]?.value?.[K.relationship.field],O=Array.isArray(L)?L[0]:L;if(O&&typeof O=="object"){let P=O;return P[d$3]??P.default??""}return O??""}let ee=k&&m?W(m,T):"";return jsx(h$2,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:_=>{j(_);},value:d$3,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(d$3,"name"))(c).label})]}),jsx(e$1,{children:c.map(_=>jsx(g$1,{value:_.name,children:_.label},_.name))})]}):null,jsx(li,{handleSave:R,isLoading:E.loading})]}),beforeClose:M,depth:t,isFocused:n,onClose:()=>{A(e._id);},onFormChange:()=>{},title:ee,children:V||!k?jsx(ci,{}):jsxs(Fragment,{children:[E.isProjectReadOnly?jsx(Ks,{}):null,jsx(Ho,{currentScope:d$3,defaultScope:f,entityId:o,entityName:u,entityNamePlural:r,formData:T[0],onSubmit:Z,ref:i,schema:l,setIsDirty:$})]})})}var il=25;function up(e){return e.map(t=>({...t,cell:()=>jsx(r$2,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function gi({action:e,depth:t,isFocused:n}){let o=de(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:l,connectionName:c,entityId:f,entityName:m,initialAssetPath:u,initialConnection:p,mode:d$1,relationshipId:g}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:C}=find(propEq(y??"","projectId"))(h),v=find(propEq(m,"name"))(C),b=v?.plural??"",D=i[g],E=Vn(),w=m==="_asset",x=w?"asset":v?.menu?.label??m.toLowerCase(),$=w&&d$1==="single"?"Select asset":`Select ${w?"assets":x}`,M=d$1==="single"?"Upload asset":"Upload assets",[A,R]=useState([]),j=[];if(p)j=[{id:p._id,value:p.value}];else if(D?.connect){let z=D.connect;j=[{id:z._id,value:z.value}];}let H=d$1==="single"?j:D?.connect?.map(z=>({id:z._id,value:z.value}))||[],[G,Z]=useState(H),T=useMemo(()=>{let z=[];return w&&z.push({NOT:{path:{eq:null}}}),d$1==="multiple"&&c&&f&&z.push({[c]:{none:{_id:{eq:f}}}}),A.length>0&&z.push({OR:A.map(ne=>({_id:{eq:ne._id}}))}),z.length===0?{}:z.length===1?z[0]:{AND:z}},[c,f,w,d$1,A]),{count:k,data:V,fetchMore:W,isLoading:ee,isLoadingMore:_}=Xn({entityNamePlural:b,schema:C,scope:a,variables:{offset:0,limit:il,where:T,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),B=!!V?.length,K=ee&&!B,te=V?.length??0,ye=k-l,L=ye>0&&te>0&&te<ye,O=Un({attributesSchema:v?.attributes??[],checkboxSelect:d$1}),P=Array(5).fill({}),I=up(O);useEffect(()=>{if(d$1!=="single"||G.length>0||!u||!V?.length)return;let z=V.find(ne=>ne.path===u);!z?._id||typeof z._id!="string"||Z([{id:z._id,value:z}]);},[V,u,d$1,G.length]);let U=useCallback(z=>{o({type:"Dismiss",_id:z,payload:{}});},[o]),Q=useCallback(()=>{W({variables:{offset:0,limit:il,where:T}});},[T,W]);function se(){let z;if(d$1==="single"){let[ne]=G;z={_id:ne?.id??"",value:ne?.value??null};}d$1==="multiple"&&(z=G?.map((ne,je)=>({_id:ne.id??"",...w?{sortOrder:je}:{},value:ne.value}))),r({type:"setRelationship",payload:{[g]:{connect:z,disconnect:D?.disconnect??[]}}}),U(e._id);}function ge(z){if(d$1==="multiple"){Z(je=>{let He=new Map(je.map(fe=>[fe.id,fe]));return z.map(fe=>{if(He.has(fe))return He.get(fe);let Wo=V?.find(Kn=>Kn._id===fe);return {id:fe,value:Wo}})});return}let ne=z[z.length-1];Z(ne?je=>{if(je.length===1&&je[0].id===ne)return je;let He=V?.find(fe=>fe._id===ne);return [{id:ne,value:He}]}:[]);}function le(){o({type:"AddEntity",payload:{entityName:m}});}async function _e(){let z=await E({projectId:y,accept:s??"image/*",multiple:d$1==="multiple",maxBytes:4194304});Z(ne=>{if(d$1==="single"){let[fe]=z;return fe?[{id:fe._id,value:fe.asset}]:ne}let je=new Set(ne.map(fe=>fe.id)),He=z.filter(fe=>!je.has(fe._id)).map(fe=>({id:fe._id,value:fe.asset}));return [...ne,...He]});}return jsx(h$2,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{se();},variant:"default",children:"Select"}),w?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{le();},variant:"outline",children:`Create ${x}`}),w?jsxs(b$3,{className:"fk:px-8",onClick:()=>{_e();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),M]}):null]}),depth:t,isFocused:n,onClose:()=>{U(e._id);},title:$,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Jn,{columns:K?I:O,data:K?P:V??[],entityName:v?.name??"",hasMore:L,initialSelectionState:G?.reduce((z,ne)=>({...z,...ne.id?{[ne.id]:true}:{}}),{}),isLoadingMore:_,onEntitySelectionChange:ge,onLoadMore:Q,toolbarComponent:()=>jsx(dp,{entityNamePlural:b,projectId:y??"",setSearchResultIds:R})})})})}function dp({entityNamePlural:e,projectId:t,setSearchResultIds:n}){let[o,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:l,isLoading:c}=e$5(t,a),f=useRef(null),m=useMemo(()=>mp(p=>{s({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(l){let p=JSON.stringify(l.map(g=>g._id).sort()),d=f.current?JSON.stringify(f.current.map(g=>g._id).sort()):"";p!==d&&(f.current=[...l],n(l.map(g=>({_id:g._id}))));}},[l,n]);function u(p){let{value:d}=p.target;r(d),m(d);}return jsxs("div",{className:"fk:relative fk:w-full",children:[c?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$7,{className:"fk:w-full fk:pl-11!",onChange:u,placeholder:"Search",value:o})]})}function mp(e,t=300){let n;return (...o)=>{clearTimeout(n),n=setTimeout(()=>e(...o),t);}}function sl(){let e=Na(),t=e.filter(o=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===o.type)),n=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(o=>{switch(o.type){case "AlertDialog":{let{payload:r}=o;return jsx(Pn,{options:r.options},o._id)}case "DeleteEntity":return jsx(Sr,{action:o},o._id);case "AddEntity":return jsx(ri,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditEntity":return jsx(di,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditRelationship":return jsx(gi,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);default:return null}})})}function ll({config:e}){let[t]=e,{basePath:n,projectId:o}=t,r=a$g(n);return window.location.pathname===r&&(window.location.href=b$a(r,o)),jsx(a$j,{children:jsx(c$6,{config:e,children:jsxs(ma,{children:[jsx(Ja,{children:jsx(sl,{})}),jsx(Outlet,{})]})})})}function cl(){let e=useRouteError(),t=new Date().getFullYear();function n(){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})})]}):sr(e)?Ki(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:n()})})}),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(lo,{})]})})]})}function hi(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ke,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Error"}),jsx(he,{children:t})]})}var Np=RouterProvider;function Dp({config:e}){let[t,n]=useState(false),o=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(f=>fl(f)):[fl(e)],[i]=r,a=a$g(i?.basePath),s=e$4(r);if(useEffect(()=>{n(true);},[]),!t)return null;let l=[{path:a,element:jsx(ll,{config:r}),errorElement:jsx(cl,{}),children:[{path:":projectId",element:jsx(ia,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(f=>({path:f.name,element:f.component,errorElement:jsx(hi,{}),children:f.routes?.map(m=>({path:m.path,element:m.component,errorElement:jsx(hi,{}),children:m.children?.map(u=>({path:u.path,element:u.component}))}))}))}]}],c=createBrowserRouter(l);return o("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Ta,{children:jsx(Np,{router:c})})})})}function fl(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 Pp(){return jsxs(ke,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Project Paused"}),jsxs(he,{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 Fp(){let{schemaErrorMessage:e}=Jt();if(!e)return jsx(Fragment,{});let[t,n,...o]=e.split(`
444
+ `);return jsxs(ke,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Schema mismatch"}),jsxs(he,{children:[jsx("p",{children:t}),n?jsx("p",{className:"fk:mt-1",children:n}):null,o.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:o.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function $p(e){return e}function Mp(e,t){if(e.dataType==="asset"&&e.scope!==void 0&&e.scope!=="global")throw new Error(`Attribute "${e.name}" in entity "${t}" uses dataType "asset" but scope "${e.scope}". Asset attributes must use scope "global" or omit scope.`)}function _p(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function ml(e){return e.attributes.forEach(t=>{Mp(t,e.name);}),{...e,attributes:e.attributes.map(_p)}}function Op(e){return ml(e)}function zp(e){let t=useApolloClient(),{currentProjectSchema:n}=d();return useCallback(async()=>{n&&await wt(t,Ge(e,n));},[t,e,n])}function Hp(e){let{currentProjectSchema:t}=d();return useCallback(n=>{t&&Ha(Ge(e,t),n);},[e,t])}function Jp({column:e,title:t$1,options:n}){let o$1=new Set(e?.getFilterValue());return jsxs(kn,{children:[jsx(hn,{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,o$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:o$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:o$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[o$1.size," selected"]}):n.filter(r=>o$1.has(r.value)).map(r=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:r.label},r.value))})]})]})}),jsx(Mt,{className:"fk:w-50 fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p$1,{children:[jsx(q$1,{children:"No results found."}),jsx(r$1,{children:n.map(r=>{let i=o$1.has(r.value);return jsxs(t,{onSelect:()=>{i?o$1.delete(r.value):o$1.add(r.value);let a=Array.from(o$1);e?.setFilterValue(a.length?a: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",i?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("fk:size-3.5",i?"fk:text-primary-foreground":"fk:text-muted-foreground")})}),r.icon&&jsx(r.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:r.label})]},r.value)})}),o$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r$1,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function Xp({entityName:e,entityNamePlural:t,row:n,options:o={canDelete:true,canEdit:true}}){let r=de(),i=Et(),a=n.original._id,s=(o.canDelete??true)&&i,l=o.canEdit??true;function c(){r({type:"EditEntity",payload:{entityId:a,entityNamePlural:t}});}function f(){r({type:"DeleteEntity",payload:{entityId:a,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[l&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:c,variant:"ghost",children:[jsx(PencilIcon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),s&&!l&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:f,variant:"ghost",children:[jsx(Trash2Icon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),l&&s&&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:[jsxs(h$1,{onClick:c,children:[jsx(PencilIcon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Edit"]}),jsx(m,{}),jsxs(h$1,{className:"fk:text-destructive",onClick:f,children:[jsx(Trash2Icon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete"]})]})]})]})}function vi({table:e}){let[t]=e.getState().sorting;if(!t)return null;let o=e.getColumn(t.id)?.columnDef.meta?.label??t.id,r=t.desc?"desc":"asc";return jsxs(b$3,{"aria-label":`Clear sorting by ${o}`,className:"fk:h-8 fk:px-2 fk:lg:px-3 fk:text-success fk:border-none",onClick:()=>{e.resetSorting();},size:"sm",variant:"outline",children:["Sorted by ",o," ",r,jsx(X,{className:"fk:ml-1 fk:h-4 fk:w-4"})]})}function Ci({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:n=>{t.toggleVisibility(!!n);},children:t.id},t.id))]})]})}function ig({entityName:e,isReloading:t=false,onReload:n,table:o}){let r=de(),i=d$2(),a=c$2(),s=useApolloClient(),{projects:l,currentProjectId:c}=d(),{schema:f,scopes:m}=find(propEq(c??"","projectId"))(l),[u$1,p,d$3]=vt(),[g,h]=useState(false),y=Et(),C=o.getSelectedRowModel().rows.map(w=>w.original._id);function v(){r({type:"AddEntity",payload:{entityName:e}});}function b(w){i({type:"setScope",payload:{projectId:c,scope:w}});}async function D(w){if(w.length===0)return;let x=Mn(e,f,w);await new Promise(($,M)=>{p(gql`
445
+ ${x}
446
+ `),d$3({variables:{where:_n(w)},update(A){for(let R of w)A.evict({id:R});},onCompleted:()=>{$();},onError:A=>{M(A);}}),u$1(true);});}function E(){let w=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${C.length} ${w}${C.length>1?"s":""}`,dialogMessage:C.length>1?`Are you sure you want to delete the selected ${w}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${w}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{h(true);try{let x=[...C];await D(x),o.resetRowSelection(),await Eo(s,Ge(e,f),x),toast.success(x.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{h(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:[m&&m.length>0?jsxs(a$5,{defaultValue:a.scope,onValueChange:w=>{b(w);},value:a.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(a.scope??"","name"))(m)||null)?.label})]}),jsx(e$1,{children:m.map(w=>jsx(g$1,{value:w.name,children:w.label},w.name))})]}):null,jsx(Ci,{table:o}),n?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:g||t,onClick:n,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(vi,{table:o})]}),C.length>0?jsx(u,{disabled:!y,children:jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:g||!y,onClick:E,size:"sm",variant:"destructive",children:[g?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 (",C.length,")"]})}):null,jsx(u,{disabled:!y,children:jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:g||!y,onClick:v,size:"sm",variant:"default",children:"Create"})})]})}export{Jn as DataTable,Mo as DataTableColumnHeader,Jp as DataTableFacetedFilter,Xp as DataTableRowActions,vi as DataTableSortedBy,ig as DataTableToolbar,Ci as DataTableViewOptions,Dp as FlexkitStudio,Pp as ProjectDisabled,Fp as SchemaError,Er as canAccessSpaces,Us as canMutateData,$p as defineConfig,Op as defineEntity,pn as filterAttributesForSpaces,kf as filterEntitiesForSpaces,vr as getEntityCreateMutation,Mn as getEntityDeleteMutation,_n as getEntityDeleteWhere,wo as getEntityQuery,Ct as getEntitySchema,hr as getEntityUpdateMutation,Et as useCanMutate,de as useDispatch,vt as useEntityMutation,Xn as useEntityQuery,Jt as useGraphQLError,Un as useGridColumnsDefinition,Hp as usePatchEntityList,zp as useRefreshEntityList,Vn as useUploadAssets};//# sourceMappingURL=index.js.map
445
447
  //# sourceMappingURL=index.js.map