@flexkit/studio 0.0.27 → 0.0.29

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 (94) 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-7MSX5T2Z.js +2 -0
  6. package/dist/chunk-7MSX5T2Z.js.map +1 -0
  7. package/dist/chunk-CPUC4QXH.js +2 -0
  8. package/dist/chunk-CPUC4QXH.js.map +1 -0
  9. package/dist/chunk-DWK4NNLB.js +2 -0
  10. package/dist/chunk-DWK4NNLB.js.map +1 -0
  11. package/dist/chunk-EOCJR5EY.js +2 -0
  12. package/dist/chunk-EOCJR5EY.js.map +1 -0
  13. package/dist/chunk-FVFRTCEB.js +2 -0
  14. package/dist/chunk-FVFRTCEB.js.map +1 -0
  15. package/dist/chunk-HAQICAOQ.js +2 -0
  16. package/dist/chunk-HAQICAOQ.js.map +1 -0
  17. package/dist/chunk-IXO2LU47.js +2 -0
  18. package/dist/{chunk-TBCSVE5L.js.map → chunk-IXO2LU47.js.map} +1 -1
  19. package/dist/{chunk-NNRD7YZU.js → chunk-LL2Z4TD3.js} +2 -2
  20. package/dist/{chunk-NNRD7YZU.js.map → chunk-LL2Z4TD3.js.map} +1 -1
  21. package/dist/chunk-N52AF6GE.js +2 -0
  22. package/dist/chunk-N52AF6GE.js.map +1 -0
  23. package/dist/chunk-R7N3MDOP.js +2 -0
  24. package/dist/chunk-R7N3MDOP.js.map +1 -0
  25. package/dist/chunk-V6R4AWQS.js +2 -0
  26. package/dist/chunk-V6R4AWQS.js.map +1 -0
  27. package/dist/chunk-W3TUEJJL.js +2 -0
  28. package/dist/chunk-W3TUEJJL.js.map +1 -0
  29. package/dist/chunk-WXMCINGZ.js +2 -0
  30. package/dist/{chunk-27Y2SQ67.js.map → chunk-WXMCINGZ.js.map} +1 -1
  31. package/dist/{chunk-2PEDKE5Z.js → chunk-WZ533Y4O.js} +2 -2
  32. package/dist/{chunk-2PEDKE5Z.js.map → chunk-WZ533Y4O.js.map} +1 -1
  33. package/dist/chunk-YA4ACPM5.js +2 -0
  34. package/dist/{chunk-KR7CLPY2.js.map → chunk-YA4ACPM5.js.map} +1 -1
  35. package/dist/chunk-ZEZ6TRCO.js +2 -0
  36. package/dist/chunk-ZEZ6TRCO.js.map +1 -0
  37. package/dist/datetime-NQTYGZIC.js +2 -0
  38. package/dist/{datetime-TWONUNXS.js.map → datetime-NQTYGZIC.js.map} +1 -1
  39. package/dist/editor-YIRZQR3D.js +2 -0
  40. package/dist/{editor-NFRMIYVJ.js.map → editor-YIRZQR3D.js.map} +1 -1
  41. package/dist/index.css +222 -44
  42. package/dist/index.d.ts +75 -9
  43. package/dist/index.js +221 -209
  44. package/dist/index.js.map +1 -1
  45. package/dist/{search-6ASIDGYA.js → search-UFFZBRQV.js} +2 -2
  46. package/dist/{search-6ASIDGYA.js.map → search-UFFZBRQV.js.map} +1 -1
  47. package/dist/select-A6I27JQU.js +2 -0
  48. package/dist/select-A6I27JQU.js.map +1 -0
  49. package/dist/switch-AFZGXSR3.js +2 -0
  50. package/dist/{switch-KVO3JRNX.js.map → switch-AFZGXSR3.js.map} +1 -1
  51. package/dist/text-2RL2L5FT.js +2 -0
  52. package/dist/{text-FIBUDNGR.js.map → text-2RL2L5FT.js.map} +1 -1
  53. package/dist/text-6F4QTCNT.js +2 -0
  54. package/dist/{text-ODG7ABSW.js.map → text-6F4QTCNT.js.map} +1 -1
  55. package/dist/textarea-2A4TLWZS.js +2 -0
  56. package/dist/{textarea-M4YPSJEC.js.map → textarea-2A4TLWZS.js.map} +1 -1
  57. package/dist/{types.d-DiA0h3ut.d.ts → types.d-6y0oZ2Hh.d.ts} +36 -4
  58. package/dist/ui.d.ts +16 -4
  59. package/dist/ui.js +1 -1
  60. package/dist/ui.js.map +1 -1
  61. package/dist/user-nav-4JKIFZLB.js +2 -0
  62. package/dist/user-nav-4JKIFZLB.js.map +1 -0
  63. package/package.json +5 -3
  64. package/dist/asset-REAMGMQL.js +0 -2
  65. package/dist/chunk-27Y2SQ67.js +0 -2
  66. package/dist/chunk-4KGH7PU7.js +0 -2
  67. package/dist/chunk-4KGH7PU7.js.map +0 -1
  68. package/dist/chunk-553TQFSU.js +0 -2
  69. package/dist/chunk-553TQFSU.js.map +0 -1
  70. package/dist/chunk-7NQ6QCJD.js +0 -2
  71. package/dist/chunk-7NQ6QCJD.js.map +0 -1
  72. package/dist/chunk-AALMEPYG.js +0 -2
  73. package/dist/chunk-AALMEPYG.js.map +0 -1
  74. package/dist/chunk-CWHDJ7Q4.js +0 -2
  75. package/dist/chunk-CWHDJ7Q4.js.map +0 -1
  76. package/dist/chunk-KR7CLPY2.js +0 -2
  77. package/dist/chunk-QXCD5JR4.js +0 -2
  78. package/dist/chunk-QXCD5JR4.js.map +0 -1
  79. package/dist/chunk-TBCSVE5L.js +0 -2
  80. package/dist/chunk-UUGIVWK4.js +0 -2
  81. package/dist/chunk-UUGIVWK4.js.map +0 -1
  82. package/dist/chunk-X3S7TRCM.js +0 -2
  83. package/dist/chunk-ZSJAPCIZ.js +0 -2
  84. package/dist/chunk-ZSJAPCIZ.js.map +0 -1
  85. package/dist/chunk-ZSSNAIMU.js +0 -2
  86. package/dist/chunk-ZSSNAIMU.js.map +0 -1
  87. package/dist/datetime-TWONUNXS.js +0 -2
  88. package/dist/editor-NFRMIYVJ.js +0 -2
  89. package/dist/switch-KVO3JRNX.js +0 -2
  90. package/dist/text-FIBUDNGR.js +0 -2
  91. package/dist/text-ODG7ABSW.js +0 -2
  92. package/dist/textarea-M4YPSJEC.js +0 -2
  93. package/dist/user-nav-O5G4M2VA.js +0 -2
  94. package/dist/user-nav-O5G4M2VA.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,288 +1,288 @@
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$b}from'./chunk-CWHDJ7Q4.js';import {a as a$9}from'./chunk-4KGH7PU7.js';import {a,b as b$7}from'./chunk-7NQ6QCJD.js';import {a as a$c}from'./chunk-553TQFSU.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$h,e as e$5}from'./chunk-2PEDKE5Z.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-2PEDKE5Z.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$i}from'./chunk-ZSSNAIMU.js';export{b as useAuth}from'./chunk-ZSSNAIMU.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$1,m,a as a$g,l as l$1,i as i$2,b as b$c,r as r$1}from'./chunk-TBCSVE5L.js';import {d,b as b$8,a as a$e,e as e$4,c as c$6}from'./chunk-UUGIVWK4.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-UUGIVWK4.js';import {b as b$4,c as c$5,a as a$k}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$f,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$d}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$j}from'./chunk-AALMEPYG.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as cn from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,uniq,omit,pick,toPairs,props}from'ramda';import sl,{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 Zo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Collapsible,Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import {Drawer}from'vaul';import tr 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 Vd from'react-markdown';import {useReactTable,getFacetedUniqueValues,getFacetedRowModel,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function Go(){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 Wo(){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 il=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 se({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(il({variant:t}),e),...o})}function Fe({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 le({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 ml=Zo.object({email:Zo.string().email({message:"Please enter a valid email address"})});function Ln({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:s}=useSWRConfig(),a=useForm({resolver:zodResolver(ml),defaultValues:{email:""}}),f=new URL(c$5(e$1).loginOtpSend,a$k),{data:c$1,error:d,isLoading:m}=sl(r?f.href:null,w=>fetch(w,{method:"POST",mode:"cors",body:JSON.stringify({email:a.getValues("email")})}).then(v=>v.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 w=0,v=setInterval(()=>{if(w>100){clearInterval(v),n(true);return}let E=new URL(c$5(e$1).loginOtpConfirm,a$k),C="/api/flexkit/set-token";fetch(`${E.href}?email=${a.getValues("email")}&token=${g$1}`).then(k=>{k.status===200&&k.json().then(x=>{fetch(C,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:x.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),w++;},3e3);return ()=>{clearInterval(v);}},[a,u,e$1,g$1]);function p(){n(false),i$1(true),s(f.href);}return jsx("div",{className:"fk:w-full",children:u?jsx(se,{variant:"success",children:jsxs(le,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:a.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,{...a,children:jsxs("form",{onSubmit:w=>{a.handleSubmit(p)(w);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[l==="not_exists"&&jsx(se,{variant:"destructive",children:jsxs(le,{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=${a.getValues("email")}`,children:"Sign up?"})]})}),l==="unknown_error"||d?jsx(se,{variant:"destructive",children:jsxs(le,{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(se,{variant:"destructive",children:jsxs(le,{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:a.control,defaultValue:"",name:"email",render:({field:w})=>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",...w})}),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 Si({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(p=>p.projectId===e)??t[0]),[r,i]=useState(false),{data:s,error:a,isLoading:f}=sl(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(w=>w.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(a)throw new Error("Error fetching auth providers");return f||c||!s?jsx(Wo,{}):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$j,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:o.projectId,onValueChange:p=>{n(t.find(w=>w.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(Ln,{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:[s.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:hl({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(Go,{})]})})]})}function hl({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 yl=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],vl={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"},Ko=class e extends Error{code;constructor(t,o){super(o??vl[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 _n(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:yl.includes(t)}function Ei(e){if(_n(e))return e.code}function Ni({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[s,a]=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(w=>w.name===l)){let w=e.find(v=>v.name===l);g.pop(),w&&g.push(w);}let p=e.filter(w=>!g.includes(w));i(g),a(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))}),s.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:s.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 Pl={"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-6ASIDGYA.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-O5G4M2VA.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-FIBUDNGR.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-NFRMIYVJ.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-TWONUNXS.js').then(({DateTime:e})=>({default:e})))};function vo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=Pl[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function Ri({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=vo("navbar.logo"),r=vo("navbar.projectSelector"),i=vo("navbar.search"),s=vo("navbar.userNav"),a=t.find(l=>l.projectId===e)??t[0],{basePath:f,schema:c}=a,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(s,{projectId:e})})})]})}function Fi({version:e}){let{contributions:t,projects:o}=d(),[n,r]=b$a(),{projectId:i}=useParams(),s=find(propEq(i??"","projectId"))(o);if(!s)throw new Ko("PROJECT_NOT_FOUND");let{scopes:a}=s,{apps:f}=t,c=d$2(),d$1=useLocation();return useEffect(()=>{if(a){let m=a.find(u=>u.isDefault)||a[0],l="";typeof localStorage<"u"&&(l=localStorage.getItem(`${a$h}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:l||m.name}});}},[d$1]),n?jsx(Wo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(Ri,{projectId: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(Ni,{apps:f,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(Si,{projectId:i??""})}function $i(e){return e?"cause"in e:false}function Ft(e){if(!e)return null;if(ServerError.is(e))return e;if($i(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Li(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function It(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function en(e){if(!e)return null;let t=zl(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 zl(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Mi).map(({message:r})=>r);let t=Li(e);if(t&&bo(t))return [t];let o=Ft(e);if(o?.statusCode!==400)return [];let n=It(o.bodyText)??jl(o)??Hl(e);return n?Array.isArray(n.errors)?n.errors.filter(Mi).map(r=>r.message):typeof n.message=="string"&&bo(n.message)?[n.message]:typeof n.error=="string"&&bo(n.error)?[n.error]:[]:[]}function jl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Hl(e){if(!$i(e))return null;let{cause:t}=e,o=Li(t);if(o&&bo(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function Mi(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"&&bo(o)}function bo(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var oc=ApolloProvider,Vi=createContext(void 0);function Mt(){let e=useContext(Vi);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function nc(e){return new ErrorLink(({error:t})=>{let o=en(t);if(o){e(o);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:s})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${s}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let n=Ft(t);if(n?.statusCode===400){let r=It(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:s,errors:a,message:f}=r;if(typeof f=="string")i=f;else if(Array.isArray(a)){let[c]=a;if(c&&typeof c.message=="string"){let{message:d}=c;i=d;}}else typeof s=="string"?i=s: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 rc(e,t){return from([nc(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function ic(e,t){return new ApolloClient({link:rc(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Bi({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]),i=useMemo(()=>ic(t,n),[t]);return jsx(Vi.Provider,{value:r,children:jsx(oc,{client:i,children:e})})}function zi({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function Bn({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function ac({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 ji({className:e,size:t="default",...o}){return jsxs(Bn,{children:[jsx(ac,{}),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 Hi({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 qi({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 Ui({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 Ji({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 Xi({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 Qi({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 wo({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[i,s]=useState(false);useEffect(()=>{o(true);},[]);function a(){o(false),i||e.dialogActionCancel?.(),i&&s(false);}async function f(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{s(true),o(false),r(false);}}return jsx(zi,{onOpenChange:a,open:t,children:jsx(Bn,{children:jsxs(ji,{className:"sm:max-w-[425px]",children:[jsxs(Hi,{children:[jsx(Ui,{children:e.dialogTitle}),jsx(Ji,{children:e.dialogMessage})]}),jsxs(qi,{children:[jsx(Qi,{disabled:n,onClick:a,children:e.dialogCancelTitle}),jsxs(Xi,{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 Ki=createContext([]),Yi=createContext(()=>{});function dc(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 ea({children:e}){let[t,o]=useReducer(dc,[]);return jsx(Ki.Provider,{value:t,children:jsx(Yi.Provider,{value:o,children:e})})}function ta(){return useContext(Ki)}function oe(){return useContext(Yi)}function st(){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 {g as g$3,h as h$2,i as i$1,l,m as m$1,j,n,q as q$1,f as f$3,c as c$7,d as d$3}from'./chunk-7MSX5T2Z.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,r,t,s,q}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$1}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 as j$1,a as a$k}from'./chunk-FVFRTCEB.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as Fn 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 Hl,{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 pn 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 Ir 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 xd 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 dn(){let[e,t]=useState(false),{theme:o,setTheme:n}=b$b();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 mn(){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 zl=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,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(zl({variant:t}),e),...o})}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 Gl=pn.object({email:pn.email({error:"Please enter a valid email address"})});function cr({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Gl),defaultValues:{email:""}}),l=new URL(c$5(e$1).loginOtpSend,a$l),{data:c$1,error:f,isLoading:d}=Hl(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,m=c$1&&"token"in c$1,p=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let w=new URL(c$5(e$1).loginOtpConfirm,a$l),v="/api/flexkit/set-token";fetch(`${w.href}?email=${encodeURIComponent(s.getValues("email"))}&token=${encodeURIComponent(p)}`).then(b=>{b.status===200&&b.json().then(N=>{fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:N.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,m,e$1,p]);function g$1(){n(false),i$1(true),a(l.href);}return jsx("div",{className:"fk:w-full",children:m?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,o?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":d,className:"fk:w-full",type:"submit",disabled:!!d,children:[d?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 ta({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(g=>g.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:l}=Hl(c$5(e).authProviders,g=>fetch(g,{mode:"cors"}).then(h=>h.json())),[c,f]=b(),d$2=new Date().getFullYear(),u=useLocation(),m=u.state?.from?.pathname??u.pathname,p=m.includes(o.projectId)?`${location.origin}${m}`:`${location.origin}${b$a(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return l||c||!a?jsx(mn,{}):f.user?.id?jsx(Navigate,{replace:true,state:{from:u},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:g=>{n(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":o.title,children:o.title})}),jsx(e$1,{children:t.map(g=>jsx(g$1,{value:g.projectId,children:g.title},g.projectId))})]})]}):null,r?jsx(cr,{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:Yl({url:g.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:p}),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 ",d$2]})]}),jsx(dn,{})]})})]})}function Yl({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 ec=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],tc={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"},gn=class e extends Error{code;constructor(t,o){super(o??tc[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 fr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:ec.includes(t)}function oa(e){if(fr(e))return e.code}function aa({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),l=useRef(null),c=useLocation(),{projectId:f}=useParams(),d=e.find(m=>c.pathname.includes(`/${f}/${m.name}`))?.name,u=e.find(m=>c.pathname.includes(`/${f}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(l.current===null)return;let m=new ResizeObserver(()=>{n(l.current?.offsetHeight??0);});return m.observe(l.current),function(){m.disconnect();}},[d]),useEffect(()=>{let m=Math.floor(o/48)-2,p=e.slice(0,m);if(!p.find(h=>h.name===u)){let h=e.find(y=>y.name===u);p.pop(),h&&p.push(h);}let g=e.filter(h=>!p.includes(h));i(p),s(g);},[e,u,o]),d===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(m=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:m.name,children:m.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:m.title})})]})},m.name))}),a.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:a.map(m=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:m.name,children:m.title})},m.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${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 dc={"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 Fo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=dc[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function la({projectId:e,projects:t}){let{resolvedTheme:o}=b$b(),n=Fo("navbar.logo"),r=Fo("navbar.projectSelector"),i=Fo("navbar.search"),a=Fo("navbar.userNav"),s=t.find(u=>u.projectId===e)??t[0],{basePath:l,schema:c}=s,f=useNavigate();function d(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(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:d,projectId:e,schema:c})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function ca({version:e}){let{contributions:t,projects:o}=d(),[n,r]=b(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(o);if(!a)throw new gn("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:l}=t,c=d$2(),f=useLocation();return useEffect(()=>{if(s){let d=s.find(m=>m.isDefault)||s[0],u="";typeof localStorage<"u"&&(u=localStorage.getItem(`${a$i}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:u||d.name}});}},[f]),n?jsx(mn,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(la,{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(aa,{apps:l,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(ta,{projectId:i??""})}function da(e){return e?"cause"in e:false}function Qt(e){if(!e)return null;if(ServerError.is(e))return e;if(da(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function ma(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Xt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function hn(e){if(!e)return null;let t=xc(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 xc(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(ua).map(({message:r})=>r);let t=ma(e);if(t&&Io(t))return [t];let o=Qt(e);if(o?.statusCode!==400)return [];let n=Xt(o.bodyText)??Sc(o)??Ec(e);return n?Array.isArray(n.errors)?n.errors.filter(ua).map(r=>r.message):typeof n.message=="string"&&Io(n.message)?[n.message]:typeof n.error=="string"&&Io(n.error)?[n.error]:[]:[]}function Sc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Ec(e){if(!da(e))return null;let{cause:t}=e,o=ma(t);if(o&&Io(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function ua(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"&&Io(o)}function Io(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Oc=ApolloProvider,ka=createContext(void 0);function Gt(){let e=useContext(ka);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function Vc(e){return new ErrorLink(({error:t})=>{let o=hn(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=Qt(t);if(n?.statusCode===400){let r=Xt(n.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=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 Bc(e,t){return from([Vc(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function zc(e,t){return new ApolloClient({link:Bc(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function ha({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]),i=useMemo(()=>zc(t,n),[t]);return jsx(ka.Provider,{value:r,children:jsx(Oc,{client:i,children:e})})}function ya({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function mr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function jc({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 va({className:e,size:t="default",...o}){return jsxs(mr,{children:[jsx(jc,{}),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 ba({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 wa({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 Ca({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 xa({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 Sa({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 Ea({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 Lo({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 l(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{a(true),o(false),r(false);}}return jsx(ya,{onOpenChange:s,open:t,children:jsx(mr,{children:jsxs(va,{className:"sm:max-w-[425px]",children:[jsxs(ba,{children:[jsx(Ca,{children:e.dialogTitle}),jsx(xa,{children:e.dialogMessage})]}),jsxs(wa,{children:[jsx(Ea,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Sa,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:l,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Na=createContext([]),Pa=createContext(()=>{});function Qc(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 Ra({children:e}){let[t,o]=useReducer(Qc,[]);return jsx(Na.Provider,{value:t,children:jsx(Pa.Provider,{value:o,children:e})})}function Fa(){return useContext(Na)}function de(){return useContext(Pa)}function bt(){let[e,t]=useState(false),[o,n]=useState(gql`
3
3
  mutation updateEntity($any: Any) {
4
4
  any
5
5
  }
6
- `),[r,i]=useState({}),[s,{data:a,loading:f,error:c}]=useMutation(o,r),d=Ft(c),{isProjectDisabled:m,isProjectReadOnly:l}=(()=>{if(d?.statusCode===403){let u=It(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&&(s(),t(false));},[e,s]),[t,n,i,{data:a,loading:f,error:c,isProjectDisabled:m,isProjectReadOnly:l}]}function ne(e){return e.dataType==="asset"?"global":e.scope}var hc=["id","string"],yc=["date","datetime","duration","time"],oa=`_id
6
+ `),[r,i]=useState({}),[a,{data:s,loading:l,error:c}]=useMutation(o,r),f=Qt(c),{isProjectDisabled:d,isProjectReadOnly:u}=(()=>{if(f?.statusCode===403){let m=Xt(f.bodyText);if(m&&typeof m.code=="string"){if(m.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(m.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,n,i,{data:s,loading:l,error:c,isProjectDisabled:d,isProjectReadOnly:u}]}function ue(e){return e.dataType==="asset"?"global":e.scope}var wn=25,Kc=3,vn=3,Yc=["id","string"],ef=["date","datetime","duration","time"],yr=`_id
7
7
  originalFilename
8
8
  mimeType
9
9
  path
10
10
  size
11
11
  height
12
12
  width
13
- lqip`;function Kt(e){return e?ne(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function Un(e,t){return !e||!Kt(e)?false:t?.name!==b$8.name||e.name!=="assets"}function So(e){return e?.dataType==="asset"||e?.inputType==="asset"}function na(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 vt(e){return Array.isArray(e)?e[0]??null:e??null}function Jn(e,t=true){let o=t?` properties {
13
+ lqip`,Cn=`_id
14
+ originalFilename
15
+ mimeType
16
+ path
17
+ size
18
+ height
19
+ width`;function fo(e){return e?ue(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function xn(e,t){return !e||!fo(e)?false:t?.name!==b$8.name||e.name!=="assets"}function _o(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Sn(e){let t=e,o=t?.edges??[],n=t?.aggregate?.count?.nodes??o.length;return o.reduce((r,i,a)=>(i.node&&r.push({...i.node,sortOrder:i.properties?.sortOrder??a,totalCount:n}),r),[]).sort((r,i)=>(r.sortOrder??Number.MAX_SAFE_INTEGER)-(i.sortOrder??Number.MAX_SAFE_INTEGER))}function Oo(e){return e.reduce((t,o,n)=>o._id?{...t,[o._id]:o.sortOrder??n}:t,{})}function wt(e){return Array.isArray(e)?e[0]??null:e??null}function vr(e,t=true,o=true,n=wn){let r=t?` properties {
14
20
  sortOrder
15
21
  }
16
- `:"";return ` ${e}Connection {
22
+ `:"",i=o?yr:Cn,a=t?`(first: ${n}, sort: [{ edge: { sortOrder: ASC } }])`:`(first: ${n})`;return ` ${e}Connection${a} {
17
23
  aggregate {
18
24
  count {
19
25
  nodes
20
26
  }
21
27
  }
22
28
  edges {
23
- `+o+` node {
24
- ${oa}
29
+ `+r+` node {
30
+ ${i}
25
31
  }
26
32
  }
27
33
  }
28
- `}function Hn(e){return e?.aggregate?.count?.nodes??0}function on(e,t=""){return ` ${e}Connection${t} {
34
+ `}function kr(e){return e?.aggregate?.count?.nodes??0}function bn(e,t=""){return ` ${e}Connection${t} {
29
35
  aggregate {
30
36
  count {
31
37
  nodes
32
38
  }
33
39
  }
34
40
  }
35
- `}function ra(e){return e.find(t=>t.isPrimary)??e[0]}function vc(e,t,o){if(!e)return "";let n=t==="default"?"":`${t}
36
- `;if(So(e))return ` ${e.name} {
37
- ${oa}
41
+ `}function La(e){return e.find(t=>t.isPrimary)??e[0]}function tf(e,t,o){if(!e)return "";let n=t==="default"?"":`${t}
42
+ `;if(_o(e))return ` ${e.name} {
43
+ ${yr}
38
44
  }
39
- `;if(ne(e)==="local")return ` ${e.name} {
45
+ `;if(ue(e)==="local")return ` ${e.name} {
40
46
  _id
41
47
  default
42
48
  ${n}}
43
- `;if(ne(e)==="relationship"){let r=e.relationship?.field;if(!r)return ` ${e.name}
44
- `;let i=find(propEq(e.relationship?.entity,"name"))(o),s=find(propEq(r,"name"))(i?.attributes??[]),a=s&&ne(s)==="local"?`{
49
+ `;if(ue(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&&ue(a)==="local"?`{
45
51
  _id
46
52
  default
47
53
  ${n}}
48
54
  `:"";return e.relationship?.mode==="single"?` ${e.name} {
49
- ${r} ${a}}
55
+ ${r} ${s}}
50
56
  `:` ${e.name} (limit: 3, offset: 0) {
51
- ${r} ${a}}
57
+ ${r} ${s}}
52
58
  `}return ` ${e.name}
53
- `}function bc(e,t,o){return e?.attributes.reduce((n,r)=>{let i=t==="default"?"":`${t}
54
- `;if(So(r))return `${n}
59
+ `}function of(e,t,o){return e?.attributes.reduce((n,r)=>{let i=t==="default"?"":`${t}
60
+ `;if(_o(r))return `${n}
55
61
  ${r.name} {
56
- _id
57
- originalFilename
58
- mimeType
59
- path
60
- size
61
- height
62
- width
63
- lqip
62
+ ${Cn}
64
63
  }
65
- `;if(ne(r)==="local")return `${n}
64
+ `;if(ue(r)==="local")return `${n}
66
65
  ${r.name} {
67
66
  _id
68
67
  default
69
68
  ${i}
70
69
  }
71
- `;if(ne(r)==="relationship"){let s=find(propEq(r.relationship?.entity,"name"))(o),a=find(propEq(r.relationship?.field,"name"))(s?.attributes??[]),f=ne(a)==="local"?`{
70
+ `;if(ue(r)==="relationship"){let a=find(propEq(r.relationship?.entity,"name"))(o),s=find(propEq(r.relationship?.field,"name"))(a?.attributes??[]),l=ue(s)==="local"?`{
72
71
  _id
73
72
  default
74
73
  ${i}}
75
74
  `:"";if(r.relationship?.mode==="single")return `${n}
76
75
  ${r.name} {
77
- ${r.relationship.field} ${f}}
76
+ ${r.relationship.field} ${l}}
78
77
  `;if(r.relationship?.field)return `${n}
79
- ${r.name} (limit: 25, offset: 0) {
80
- ${r.relationship.field} ${f}}
78
+ ${r.name} (limit: ${vn}, offset: 0) {
79
+ ${r.relationship.field} ${l}}
81
80
  `}return `${n}
82
81
  ${r.name}
83
- `},"")??""}function Lt(e,t,o,n){let r=n?.selection??"full",i="(where: $where, limit: $limit, offset: $offset, sort: $sort)",s=_t(o,e),a=s?.name??e,f=s?.attributes??[],c=`$where: ${a}Where, $limit: Int, $offset: Int, $sort: [${a}Sort!]`,d=`Get${Ao(e)}`;if(!s)throw new Error(`Entity '${a}' not found in the schema`);if(f.length===0)throw new Error(`Entity '${a}' has no attributes defined in the schema`);let m=ae("global",f).filter(k=>k!=="_updatedAt").join(`
84
- `),l=Yt(f),u=ae(["local"],f),g=u.reduce((k,x)=>`${k}
85
- ${x} {
82
+ `},"")??""}function En(e,t,o,n){let r=n?.selection??"full",i=n?.includeCount??true,a="(where: $where, limit: $limit, offset: $offset, sort: $sort)",s=Ct(o,e),l=s?.name??e,c=s?.attributes??[],f=`$where: ${l}Where, $limit: Int, $offset: Int, $sort: [${l}Sort!]`,d=`Get${ot(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(A=>!(A==="_updatedAt"||r==="list"&&A==="lqip")).join(`
83
+ `),m=uo(c),p=pe(["local"],c),g=p.reduce((A,C)=>`${A}
84
+ ${C} {
86
85
  _id
87
86
  default
88
87
  }
89
- `,""),p=u.reduce((k,x)=>`${k}
90
- ${x} {
88
+ `,""),h=p.reduce((A,C)=>`${A}
89
+ ${C} {
91
90
  _id
92
91
  default
93
92
  ${t}
94
93
  }
95
- `,""),w=t==="default"?g:p,v=l.reduce((k,x)=>`${k}
96
- ${x} {
97
- _id
94
+ `,""),y=t==="default"?g:h,w=r==="list"?`_id
95
+ originalFilename
96
+ mimeType
97
+ path
98
+ size
99
+ height
100
+ width`:`_id
98
101
  originalFilename
99
102
  mimeType
100
103
  path
101
104
  size
102
105
  height
103
106
  width
104
- lqip
107
+ lqip`,v=m.reduce((A,C)=>`${A}
108
+ ${C} {
109
+ ${w}
105
110
  }
106
- `,""),C=f.filter(k=>ne(k)==="relationship").reduce((k,x)=>{if(Kt(x))return `${k}
107
- ${Jn(x.name,Un(x,s))}`;let P=find(propEq(x.relationship?.entity,"name"))(o);if(r==="list"){let b=ra(P?.attributes??[]),L=vc(b,t,o),B=x.relationship?.mode==="single"?1:3;return `${k}
108
- ${x.name} (limit: ${B}, offset: 0) {
111
+ `,""),N=c.filter(A=>ue(A)==="relationship").reduce((A,C)=>{if(fo(C))return `${A}
112
+ ${vr(C.name,xn(C,s),r!=="list",r==="list"?Kc:wn)}`;let S=find(propEq(C.relationship?.entity,"name"))(o);if(r==="list"){let M=La(S?.attributes??[]),T=tf(M,t,o),P=C.relationship?.mode==="single"?1:3;return `${A}
113
+ ${C.name} (limit: ${P}, offset: 0) {
109
114
  _id
110
- ${L} }
111
- `}let D=bc(P,t,o);return `${on(x.name).trim()}${k}
112
- ${x.name} (limit: 25, offset: 0) { _id ${D}}
113
- `},"");return {queryEntityName:e,query:`query ${d}(${c}) {
114
- `+on(e)+` ${e}${i} {
115
+ ${T} }
116
+ `}let $=of(S,t,o);return `${bn(C.name).trim()}${A}
117
+ ${C.name} (limit: 25, offset: 0) { _id ${$}}
118
+ `},"");return {queryEntityName:e,query:`query ${d}(${f}) {
119
+ `+(i?bn(e,"(where: $where)"):"")+` ${e}${a} {
115
120
  _id
116
121
  _updatedAt
117
- ${m} ${w} ${v} ${C}}
122
+ ${u} ${y} ${v} ${N}}
118
123
  }
119
- `}}function nn(e,t,o,n){let i=_t(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=Hn(o[`${e}Connection`]),a=o[e],f=(d,m)=>{let l=m.name;return d.slice(0,3).map(u=>{if(ne(m)!=="local")return u[l];let g=vt(u[l]);return g?.[t]??g?.default}).join(", ")},c=a.map(d=>{let{_id:m}=d,l=typeof d._updatedAt=="string"?d._updatedAt:"",u=ae("global",i).filter(v=>v!=="_updatedAt").reduce((v,E)=>({...v,[E]:d[E]}),{}),g=ae("local",i).reduce((v,E)=>{let C=vt(d[E]);return {...v,[E]:C?.[t]?C[t]:C?.default}},{}),p=Yt(i).reduce((v,E)=>({...v,[E]:vt(d[E])}),{}),w=ae(["relationship"],i).reduce((v,E)=>{let C=find(propEq(E,"name"))(i),k=C.relationship?.entity??"",x=find(propEq(k,"name"))(n),P=ra(x?.attributes??[]),D=d[E];if(Kt(C)){let q=na(d[`${E}Connection`]);return {...v,[E]:q}}if(!P)throw new Error(`There is an error in the schema for the relationship attribute "${E}"`);let b=P.name,L=ne(P);if(C.relationship?.mode==="multiple"){let q=Array.isArray(D)?D:[];return {...v,[E]:f(q,P)}}let B=vt(D);if(L==="global")return {...v,[E]:B?.[b]};let H=vt(B?.[b]);return {...v,[E]:H?.[t]??H?.default}},{});return {_id:m,...u,...g,...p,...w,_updatedAt:l}});return {count:s,results:c}}function ia(e,t,o,n){let i=_t(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=Hn(o[`${e}Connection`]),f=o[e].map(c=>{let d=ae("global",i).reduce((g,p)=>({...g,[p]:{value:c[p],disabled:false,scope:"default",_id:""}}),{}),m=ae("local",i).reduce((g,p)=>{let w=find(propEq(p,"name"))(i),v=vt(c[p]);return {...g,[p]:{value:v?wc(v,t):null,disabled:!!(v&&v[t]===null&&ne(w)==="local"&&t!=="default"),scope:t,_id:v?v._id:null}}},{}),l=Yt(i).reduce((g,p)=>({...g,[p]:{value:vt(c[p]),disabled:false,scope:"default",_id:""}}),{}),u=ae(["relationship"],i).reduce((g,p)=>{let w=find(propEq(p,"name"))(i),v=c[p],E=w.relationship?.mode==="single"?vt(v):v,C=E?._id,k=Hn(c[`${p}Connection`]),x=Kt(w)?na(c[`${p}Connection`]):E;return {...g,[p]:{count:k,_id:C,value:x,disabled:false,scope:t}}},{});return {...d,...m,...l,...u}});return {count:s,results:f}}function wc(e,t){return Array.isArray(e)?e.reduce((o,n)=>{if(n[t]??n.default){let r={_id:n._id,disabled:n.scope===null&&t!=="default",scope:t,value:n[t]??n.default};o.push(r);}return o},[]):e[t]??e.default??null}function Xn(e,t,o,n,r,i){let s=_t(n,e),a=s?.name??e,f=s?.attributes??[],c=rn(e);if(f.length===0)return "";let d=aa(f,i),m=sa(f,d),l=Sc(t,f,d,o),u=Cc(f,r,d),g=Ec(f,r,d),p=e,w=ca(n,e,o);return `mutation ${`Update${Ao(e)}`}($where: ${a}Where) {
120
- update${c}(
124
+ `}}function An(e,t,o,n){let i=Ct(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=kr(o[`${e}Connection`]),s=o[e],l=(f,d)=>{let u=d.name;return f.slice(0,3).map(m=>{if(ue(d)!=="local")return m[u];let p=wt(m[u]);return p?.[t]??p?.default}).join(", ")},c=s.map(f=>{let{_id:d}=f,u=typeof f._updatedAt=="string"?f._updatedAt:"",m=pe("global",i).filter(y=>y!=="_updatedAt").reduce((y,w)=>({...y,[w]:f[w]}),{}),p=pe("local",i).reduce((y,w)=>{let v=wt(f[w]);return {...y,[w]:v?.[t]?v[t]:v?.default}},{}),g=uo(i).reduce((y,w)=>({...y,[w]:wt(f[w])}),{}),h=pe(["relationship"],i).reduce((y,w)=>{let v=find(propEq(w,"name"))(i),b=v.relationship?.entity??"",N=find(propEq(b,"name"))(n),A=La(N?.attributes??[]),C=f[w];if(fo(v)){let P=Sn(f[`${w}Connection`]);return {...y,[w]:P}}if(!A)throw new Error(`There is an error in the schema for the relationship attribute "${w}"`);let S=A.name,$=ue(A);if(v.relationship?.mode==="multiple"){let P=Array.isArray(C)?C:[];return {...y,[w]:l(P,A)}}let M=wt(C);if($==="global")return {...y,[w]:M?.[S]};let T=wt(M?.[S]);return {...y,[w]:T?.[t]??T?.default}},{});return {_id:d,...m,...p,...g,...h,_updatedAt:u}});return {count:a,results:c}}function $a(e,t,o,n){let i=Ct(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=kr(o[`${e}Connection`]),l=o[e].map(c=>{let f=pe("global",i).reduce((p,g)=>({...p,[g]:{value:c[g],disabled:false,scope:"default",_id:""}}),{}),d=pe("local",i).reduce((p,g)=>{let h=find(propEq(g,"name"))(i),y=wt(c[g]);return {...p,[g]:{value:y?nf(y,t):null,disabled:!!(y&&y[t]===null&&ue(h)==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),u=uo(i).reduce((p,g)=>({...p,[g]:{value:wt(c[g]),disabled:false,scope:"default",_id:""}}),{}),m=pe(["relationship"],i).reduce((p,g)=>{let h=find(propEq(g,"name"))(i),y=c[g],w=h.relationship?.mode==="single"?wt(y):y,v=w?._id,b=kr(c[`${g}Connection`]);if(fo(h)){let N=Sn(c[`${g}Connection`]);return {...p,[g]:{count:b,_id:v,knownAssetSortOrders:Oo(N),value:N,disabled:false,scope:t}}}return {...p,[g]:{count:b,_id:v,value:w,disabled:false,scope:t}}},{});return {...f,...d,...u,...m}});return {count:a,results:l}}function nf(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 br(e,t,o,n,r,i,a){let s=Ct(n,e),l=s?.name??e,c=s?.attributes??[],f=zo(e);if(c.length===0)return "";let d=Ma(c,i),u=_a(c,d),m=sf(t,c,d,o),p=rf(c,r,d),g=lf(c,r,d),h=e,y=a?.responseFields??Va(n,e,o);return `mutation ${`Update${ot(e)}`}($where: ${l}Where) {
125
+ update${f}(
121
126
  where: $where
122
- update: {${m}${l}${u}${g}
127
+ update: {${u}${m}${p}${g}
123
128
  }
124
129
  ) {
125
- ${p} {
130
+ ${h} {
126
131
  _id
127
- ${w} }
132
+ ${y} }
128
133
  }
129
134
  }
130
- `}function aa(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 ae(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(ae(r,t)),[]):t.filter(n=>ne(n)===e&&n.inputType!=="asset").map(n=>n.name)}function Yt(e){return e.filter(So).map(o=>o.name)}function sa(e,t,o="update"){let n=pick(ae("global",e),t);return toPairs(n).reduce((i,[s,a])=>{let f=find(propEq(s,"name"))(e),c=Array.isArray(a?.value)?null:a?.value??null,d=Qn(f.dataType,c);return o==="update"?`${i}
131
- ${s}: { set: ${d} }`:`${i}
132
- ${s}: ${d}`},"")}function qn(e){return !e?._id||!e.path?"":e._id}function Cc(e,t,o){let n=pick(Yt(e),o);return toPairs(n).reduce((s,[a,f])=>{let c=qn(f.value),d=qn(t[a]?.value);if(c===d)return s;let m=d?` {
135
+ `}function Ma(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 pe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(pe(r,t)),[]):t.filter(n=>ue(n)===e&&n.inputType!=="asset").map(n=>n.name)}function uo(e){return e.filter(_o).map(o=>o.name)}function _a(e,t,o="update"){let n=pick(pe("global",e),t);return toPairs(n).reduce((i,[a,s])=>{let l=find(propEq(a,"name"))(e),c=Array.isArray(s?.value)?null:s?.value??null,f=wr(l.dataType,c);return o==="create"&&(f===null||f==="")?i:o==="update"?`${i}
136
+ ${a}: { set: ${f} }`:`${i}
137
+ ${a}: ${f}`},"")}function hr(e){return !e?._id||!e.path?"":e._id}function rf(e,t,o){let n=pick(uo(e),o);return toPairs(n).reduce((a,[s,l])=>{let c=hr(l.value),f=hr(t[s]?.value);if(c===f)return a;let d=f?` {
133
138
  disconnect: [{
134
139
  where: {
135
140
  node: {
136
- _id: { eq: ${pe(d)} }
141
+ _id: { eq: ${Se(f)} }
137
142
  }
138
143
  }
139
144
  }]
140
145
  }
141
- `:"",l=c?` {
146
+ `:"",u=c?` {
142
147
  connect: [{
143
148
  where: {
144
149
  node: {
145
- _id: { eq: ${pe(c)} }
150
+ _id: { eq: ${Se(c)} }
146
151
  }
147
152
  }
148
153
  }]
149
154
  }
150
- `:"";return `${s}
151
- ${a}: [
152
- ${m}${l} ]`},"")}function xc(e,t){let o=pick(Yt(e),t);return toPairs(o).reduce((i,[s,a])=>{let f=qn(a.value);return f?`${i}
153
- ${s}: {
155
+ `:"";return `${a}
156
+ ${s}: [
157
+ ${d}${u} ]`},"")}function af(e,t){let o=pick(uo(e),t);return toPairs(o).reduce((i,[a,s])=>{let l=hr(s.value);return l?`${i}
158
+ ${a}: {
154
159
  connect: [{
155
160
  where: {
156
161
  node: {
157
- _id: { eq: ${pe(f)} }
162
+ _id: { eq: ${Se(l)} }
158
163
  }
159
164
  }
160
165
  }]
161
- }`:i},"")}function Sc(e,t,o,n){let r=pick(ae("local",t),o);return toPairs(r).reduce((a,[f,c])=>{let d=find(propEq(f,"name"))(t),{dataType:m}=d,l=c.disabled||Array.isArray(c.value)?"null":Qn(m,c.value);return c._id?`${a}
162
- ${f}: [{
166
+ }`:i},"")}function sf(e,t,o,n){let r=pick(pe("local",t),o);return toPairs(r).reduce((s,[l,c])=>{let f=find(propEq(l,"name"))(t),{dataType:d}=f,u=c.disabled||Array.isArray(c.value)?"null":wr(d,c.value);return c._id?`${s}
167
+ ${l}: [{
163
168
  update: {
164
169
  node: {
165
- ${n}: { set: ${l} }
170
+ ${n}: { set: ${u} }
166
171
  }
167
172
  }
168
- }]`:l?`${a}
169
- ${f}: [{
173
+ }]`:c.disabled||Array.isArray(c.value)||c.value===void 0||c.value===null||c.value===""||u===null||u===""?s:`${s}
174
+ ${l}: [{
170
175
  create: {
171
176
  node: {
172
- _id: ${pe(`${e}:${f}`)}
173
- _type: "${m}"
174
- ${n}: ${l}
177
+ _id: ${Se(`${e}:${l}`)}
178
+ _type: "${d}"
179
+ ${n}: ${u}
175
180
  }
176
181
  }
177
- }]`:a},"")}function Ec(e,t,o){let n=pick(ae("relationship",e),o);return toPairs(n).reduce((s,[a,f])=>{let c=find(propEq(a,"name"))(e),{inputType:d,relationship:m}=c;if(d==="relationship"&&m?.mode==="single"){let l=t[a]._id??"",u=f._id??"";if(l===u)return s;let g=l?` {
182
+ }]`},"")}function lf(e,t,o){let n=pick(pe("relationship",e),o);return toPairs(n).reduce((a,[s,l])=>{let c=find(propEq(s,"name"))(e),{inputType:f,relationship:d}=c;if(f==="relationship"&&d?.mode==="single"){let u=t[s]._id??"",m=l._id??"";if(u===m)return a;let p=u?` {
178
183
  disconnect: [{
179
184
  where: {
180
185
  node: {
181
- _id: { eq: ${pe(l)} }
186
+ _id: { eq: ${Se(u)} }
182
187
  }
183
188
  }
184
189
  }]
185
190
  }
186
- `:"",p=u?` {
191
+ `:"",g=m?` {
187
192
  connect: [{
188
193
  where: {
189
194
  node: {
190
- _id: { eq: ${pe(u)} }
195
+ _id: { eq: ${Se(m)} }
191
196
  }
192
197
  }
193
198
  }]
194
199
  }
195
- `:"";return `${s}
196
- ${a}: [
197
- ${g}${p} ]`}if(d==="relationship"&&m?.mode==="multiple"){if(m.entity==="_asset")return `${s}${Ac(a,t[a],f)}`;let l=f.relationships?.disconnect?.reduce((v,E)=>`${v} {
200
+ `:"";return `${a}
201
+ ${s}: [
202
+ ${p}${g} ]`}if(f==="relationship"&&d?.mode==="multiple"){if(d.entity==="_asset")return `${a}${cf(s,t[s],l)}`;let u=uniq(l.relationships?.disconnect??[]).filter(Boolean),p=(l.relationships?.connect??[]).map(y=>Se(y._id)).join(", "),g=u.length?` {
203
+ disconnect: [
204
+ ${u.map(y=>` {
205
+ where: {
198
206
  node: {
199
- _id: { eq: ${pe(E)} }
207
+ _id: { eq: ${Se(y)} }
200
208
  }
201
209
  }
202
- `,""),g=(f.relationships?.connect??[]).map(v=>pe(v._id)).join(", "),p=l?`disconnect: {
203
- where: {
204
- OR: [
205
- ${l} ]
206
- }
210
+ }
211
+ `).join("")} ]
207
212
  }
208
- `:"",w=g?`connect: {
209
- where: {
210
- node: {
211
- _id: { in: [${g}] }
213
+ `:"",h=p?` {
214
+ connect: [{
215
+ where: {
216
+ node: {
217
+ _id: { in: [${p}] }
218
+ }
212
219
  }
213
- }
220
+ }]
214
221
  }
215
- `:"";return !p&&!w?s:`${s}
216
- ${a}: {
217
- ${p} ${w} }`}return `${s}
218
- `},"")}function Ac(e,t,o){let r=(o.relationships?.connect??[]).map((u,g)=>({...u,sortOrder:u.sortOrder??g})),i=r.map(u=>u._id),s=Dc(t),a=uniq(o.relationships?.disconnect??[]).filter(u=>u&&!i.includes(u)),f=r.filter(u=>s[u._id]===void 0),c=r.filter(u=>{let g=s[u._id];return g!==void 0&&g!==u.sortOrder}),d=Tc(a),m=Nc(f),l=Pc(c);return !d&&!m&&!l?"":`
222
+ `:"";return !g&&!h?a:`${a}
223
+ ${s}: [
224
+ ${g}${h} ]`}return `${a}
225
+ `},"")}function cf(e,t,o){let r=(o.relationships?.connect??[]).map((m,p)=>({...m,sortOrder:m.sortOrder??p})),i=r.map(m=>m._id),a={...ff(t),...t?.knownAssetSortOrders??{},...o.knownAssetSortOrders??{}},s=uniq(o.relationships?.disconnect??[]).filter(m=>m&&!i.includes(m)),l=r.filter(m=>a[m._id]===void 0),c=r.filter(m=>{let p=a[m._id];return p!==void 0&&p!==m.sortOrder}),f=uf(s),d=df(l),u=mf(c);return !f&&!d&&!u?"":`
219
226
  ${e}: [
220
- ${d}${m}${l} ]`}function Dc(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 s="sortOrder"in n&&typeof n.sortOrder=="number"?n.sortOrder:r;return {...o,[i]:s}},{}):{}}function Tc(e){return e.length===0?"":` {
227
+ ${f}${d}${u} ]`}function ff(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 uf(e){return e.length===0?"":` {
221
228
  disconnect: [
222
229
  ${e.reduce((o,n)=>`${o} {
223
- where: { node: { _id: { eq: ${pe(n)} } } }
230
+ where: { node: { _id: { eq: ${Se(n)} } } }
224
231
  }
225
232
  `,"")} ]
226
233
  }
227
- `}function Nc(e){return e.length===0?"":` {
234
+ `}function df(e){return e.length===0?"":` {
228
235
  connect: [
229
- ${la(e)} ]
236
+ ${Oa(e)} ]
230
237
  }
231
- `}function la(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
232
- where: { node: { _id: { eq: ${pe(o._id)} } } }
238
+ `}function Oa(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
239
+ where: { node: { _id: { eq: ${Se(o._id)} } } }
233
240
  edge: { sortOrder: ${r} }
234
241
  }
235
- `},"")}function Pc(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
242
+ `},"")}function mf(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
236
243
  update: {
237
- where: { node: { _id: { eq: ${pe(n._id)} } } }
244
+ where: { node: { _id: { eq: ${Se(n._id)} } } }
238
245
  edge: { sortOrder: { set: ${i} } }
239
246
  }
240
247
  }
241
- `},"")}function Qn(e,t){return yc.includes(e)?t?.toString()?pe(t.toString()):null:hc.includes(e)?pe(t?.toString()??"null"):t?.toString()??null}function pe(e){return JSON.stringify(e)}function ca(e,t,o){let n=_t(e,t),r=n?.attributes??[],i=ae("global",r),s=ae("local",r),a=ae("relationship",r),f=i.reduce((c,d)=>`${c}${d}
242
- `,"");return f+=s.reduce((c,d)=>`${c} ${d} {
248
+ `},"")}function wr(e,t){return ef.includes(e)?t?.toString()?Se(t.toString()):null:Yc.includes(e)?t==null?null:Se(t.toString()):t==null||t===""?null:t.toString()}function Se(e){return JSON.stringify(e)}function Va(e,t,o){let n=Ct(e,t),r=n?.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} {
243
250
  _id
244
251
  ${o}
245
252
  }
246
- `,""),f+=a.reduce((c,d)=>{let m=find(propEq(d,"name"))(r),l=m?.relationship?.mode??"single";if(Kt(m))return `${c}${Jn(d,Un(m,n))}`;let u=m?.relationship?.entity??"",p=find(propEq(u,"name"))(e)?.attributes??[],w=m?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(w,"name"))(p),E=ne(v),C="";if(l==="single"&&(E==="global"&&(C=` ${d} {
253
+ `,""),l+=s.reduce((c,f)=>{let d=find(propEq(f,"name"))(r),u=d?.relationship?.mode??"single";if(fo(d))return `${c}${vr(f,xn(d,n))}`;let m=d?.relationship?.entity??"",g=find(propEq(m,"name"))(e)?.attributes??[],h=d?.relationship?.field??"[invalid_relationship_field_name_in_schema]",y=find(propEq(h,"name"))(g),w=ue(y),v="";if(u==="single"&&(w==="global"&&(v=` ${f} {
247
254
  _id
248
- ${w}
255
+ ${h}
249
256
  }
250
- `),E==="local"&&(C=` ${d} {
257
+ `),w==="local"&&(v=` ${f} {
251
258
  _id
252
- ${w} {
259
+ ${h} {
253
260
  _id
254
261
  default
255
262
  ${o}
256
263
  }
257
264
  }
258
- `)),l==="multiple"&&p.length){let k=p.reduce((x,P)=>{if(ne(P)==="local")return `${x} ${P.name} {
265
+ `)),u==="multiple"&&g.length){let b=g.reduce((N,A)=>{if(ue(A)==="local")return `${N} ${A.name} {
259
266
  _id
260
267
  default
261
268
  ${o}
262
269
  }
263
- `;if(ne(P)==="relationship"){let D=o==="default"?"":`${o}
264
- `,b=find(propEq(P.relationship?.entity,"name"))(e),L=find(propEq(P.relationship?.field,"name"))(b?.attributes??[]),B=ne(L)==="local"?`{
270
+ `;if(ue(A)==="relationship"){let C=o==="default"?"":`${o}
271
+ `,S=find(propEq(A.relationship?.entity,"name"))(e),$=find(propEq(A.relationship?.field,"name"))(S?.attributes??[]),M=ue($)==="local"?`{
265
272
  _id
266
273
  default
267
- ${D}}
268
- `:"";if(P.relationship?.mode==="single")return `${x} ${P.name} {
269
- ${P.relationship.field} ${B}}
270
- `;if(P.relationship?.field)return `${x} ${P.name} (limit: 25, offset: 0) {
271
- ${P.relationship.field} ${B}}
272
- `}return So(P)?`${x} ${P.name} {
273
- _id
274
- originalFilename
275
- mimeType
276
- path
277
- size
278
- height
279
- width
280
- lqip
274
+ ${C}}
275
+ `:"";if(A.relationship?.mode==="single")return `${N} ${A.name} {
276
+ ${A.relationship.field} ${M}}
277
+ `;if(A.relationship?.field)return `${N} ${A.name} (limit: ${vn}, offset: 0) {
278
+ ${A.relationship.field} ${M}}
279
+ `}return _o(A)?`${N} ${A.name} {
280
+ ${Cn}
281
281
  }
282
- `:`${x} ${P.name}
283
- `},"");C=on(d)+` ${d} (limit: 25, offset: 0) {
284
- ${k} }
285
- `;}return `${c}${C}`},""),f}function Eo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=rn(n?.plural??""),s=Rc(r,o),a=`Delete${Ao(n?.plural??e)}`;return e==="_asset"?`mutation ${a}($where: ${e}Where) {
282
+ `:`${N} ${A.name}
283
+ `},"");v=bn(f)+` ${f} (limit: 25, offset: 0) {
284
+ ${b} }
285
+ `;}return `${c}${v}`},""),l}function Vo(e,t,o){let n=typeof o=="string"?[o]:[...o],r=find(propEq(e,"name"))(t),i=r?.attributes??[],a=zo(r?.plural??""),s=pf(i,n),l=`Delete${ot(r?.plural??e)}`;return e==="_asset"?`mutation ${l}($where: ${e}Where) {
286
286
  delete_assets(
287
287
  where: $where
288
288
  ) {
@@ -290,8 +290,8 @@ ${k} }
290
290
  relationshipsDeleted
291
291
  }
292
292
  }
293
- `:`mutation ${a}($where: ${e}Where) {
294
- delete${i}(
293
+ `:`mutation ${l}($where: ${e}Where) {
294
+ delete${a}(
295
295
  where: $where
296
296
  ${s?` delete: {
297
297
  ${s}
@@ -301,72 +301,72 @@ ${s?` delete: {
301
301
  relationshipsDeleted
302
302
  }
303
303
  }
304
- `}function Rc(e,t){return ae("local",e).reduce((r,i)=>`${r}
304
+ `}function Bo(e){let t=typeof e=="string"?[e]:[...e];return t.length===1?{_id:{eq:t[0]}}:{_id:{in:t}}}function pf(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}
305
305
  ${i}: [{
306
306
  where: {
307
307
  node: {
308
- _id: { eq: ${pe(`${t}:${i}`)} }
308
+ ${s}
309
309
  }
310
310
  }
311
- }]`,"")}function Gn(e,t,o,n){let r=_t(t,e),i=r?.attributes??[],s=rn(r?.plural??"");if(i.length===0)return "";let a=aa(i,o),f=sa(i,a,"create"),c=Fc(i,a,"default",n),d=xc(i,a),m=Ic(i,a),l=e,u=ca(t,l,"default");return `mutation ${`Create${Ao(e)}`} {
312
- create${s}(
311
+ }]`},"")}function Cr(e,t,o,n){let r=Ct(t,e),i=r?.attributes??[],a=zo(r?.plural??"");if(i.length===0)return "";let s=Ma(i,o),l=_a(i,s,"create"),c=gf(i,s,"default",n),f=af(i,s),d=kf(i,s),u=e,m=Va(t,u,"default");return `mutation ${`Create${ot(e)}`} {
312
+ create${a}(
313
313
  input: [{
314
- _id: ${pe(n)} ${f} ${c}
314
+ _id: ${Se(n)} ${l} ${c}
315
+ ${f}
315
316
  ${d}
316
- ${m}
317
317
  }]
318
318
  ) {
319
- ${l} {
319
+ ${u} {
320
320
  _id
321
- ${u} }
321
+ ${m} }
322
322
  }
323
323
  }
324
- `}function Fc(e,t,o,n){let r=pick(ae("local",e),t);return toPairs(r).reduce((a,[f,c])=>{if(c?.value===void 0||c.value===null||c.value==="")return a;let d=find(propEq(f,"name"))(e),m=Array.isArray(c.value)?"null":Qn(d.dataType,c.value);return `${a}
325
- ${f}: {
324
+ `}function gf(e,t,o,n){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),d=Array.isArray(c.value)?"null":wr(f.dataType,c.value);return `${s}
325
+ ${l}: {
326
326
  create: [{
327
327
  node: {
328
- _id: ${pe(`${n}:${f}`)}
329
- _type: "${d.dataType}"
330
- ${o}: ${m}
328
+ _id: ${Se(`${n}:${l}`)}
329
+ _type: "${f.dataType}"
330
+ ${o}: ${d}
331
331
  }
332
332
  }]
333
- }`},"")}function Ic(e,t){let o=pick(ae("relationship",e),t);return toPairs(o).reduce((i,[s,a])=>{let f=find(propEq(s,"name"))(e),{inputType:c,relationship:d}=f;if(c==="relationship"&&d?.mode==="single"){let u=`connect: [{
333
+ }`},"")}function kf(e,t){let o=pick(pe("relationship",e),t);return toPairs(o).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 m=`connect: [{
334
334
  where: {
335
335
  node: {
336
- _id: { eq: ${pe(a._id??"")} }
336
+ _id: { eq: ${Se(s._id)} }
337
337
  }
338
338
  }
339
339
  }]
340
340
  `;return `${i}
341
- ${s}: {
342
- ${u} }`}let m=c==="relationship"&&d?.mode==="multiple",l=Array.isArray(a.relationships?.connect)&&a.relationships.connect.length>0;if(m&&l){let u=a.relationships?.connect??[];if(d?.entity==="_asset"){let w=la(u.map((v,E)=>({...v,sortOrder:v.sortOrder??E})));return `${i}
343
- ${s}: {
341
+ ${a}: {
342
+ ${m} }`}let d=c==="relationship"&&f?.mode==="multiple",u=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(d&&u){let m=s.relationships?.connect??[];if(f?.entity==="_asset"){let h=Oa(m.map((y,w)=>({...y,sortOrder:y.sortOrder??w})));return `${i}
343
+ ${a}: {
344
344
  connect: [
345
- ${w} ]
346
- }`}let g=u.map(w=>pe(w._id)).join(", "),p=g?`connect: {
345
+ ${h} ]
346
+ }`}let p=m.map(h=>Se(h._id)).join(", "),g=p?`connect: {
347
347
  where: {
348
348
  node: {
349
- _id: { in: [${g}] }
349
+ _id: { in: [${p}] }
350
350
  }
351
351
  }
352
352
  }
353
353
  `:"";return `${i}
354
- ${s}: {
355
- ${p} }`}return `${i}
356
- `},"")}function fa({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, limit: $limit, offset: $offset, sort: $sort)",i=find(propEq(t,"name"))(n),s=i?.attributes??[],a=`$where: ${t}Where, $limit: Int, $offset: Int, $sort: [${t}Sort!]`,f=i?.plural??"",c=`GetRelated${Ao(f||t)}`;if(s.length===0)return {queryEntityName:"",query:""};let d=ae("global",s).filter(C=>C!=="_updatedAt").join(`
357
- `),m=ae(["local"],s),l=m.reduce((C,k)=>`${C}
358
- ${k} {
354
+ ${a}: {
355
+ ${g} }`}return `${i}
356
+ `},"")}function Ba({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!]`,l=i?.plural??"",c=`GetRelated${ot(l||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let f=pe("global",a).filter(v=>v!=="_updatedAt").join(`
357
+ `),d=pe(["local"],a),u=d.reduce((v,b)=>`${v}
358
+ ${b} {
359
359
  _id
360
360
  default
361
361
  }
362
- `,""),u=m.reduce((C,k)=>`${C}
363
- ${k} {
362
+ `,""),m=d.reduce((v,b)=>`${v}
363
+ ${b} {
364
364
  _id
365
365
  default
366
366
  ${o}
367
367
  }
368
- `,""),g=o==="default"?l:u,w=Yt(s).reduce((C,k)=>`${C}
369
- ${k} {
368
+ `,""),p=o==="default"?u:m,h=uo(a).reduce((v,b)=>`${v}
369
+ ${b} {
370
370
  _id
371
371
  originalFilename
372
372
  mimeType
@@ -376,60 +376,72 @@ ${w} ]
376
376
  width
377
377
  lqip
378
378
  }
379
- `,""),E=s.filter(C=>ne(C)==="relationship").reduce((C,k)=>{if(Kt(k))return `${C}
380
- ${Jn(k.name,Un(k,i))}`;let P=find(propEq(k.relationship?.entity,"name"))(n)?.attributes.reduce((D,b)=>{let L=o==="default"?"":`${o}
381
- `;if(So(b))return `${D}
382
- ${b.name} {
383
- _id
384
- originalFilename
385
- mimeType
386
- path
387
- size
388
- height
389
- width
390
- lqip
379
+ `,""),w=a.filter(v=>ue(v)==="relationship").reduce((v,b)=>{if(fo(b))return `${v}
380
+ ${vr(b.name,xn(b,i))}`;let A=find(propEq(b.relationship?.entity,"name"))(n)?.attributes.reduce((C,S)=>{let $=o==="default"?"":`${o}
381
+ `;if(_o(S))return `${C}
382
+ ${S.name} {
383
+ ${Cn}
391
384
  }
392
- `;if(ne(b)==="local")return `${D}
393
- ${b.name} {
385
+ `;if(ue(S)==="local")return `${C}
386
+ ${S.name} {
394
387
  _id
395
388
  default
396
- ${L}}
397
- `;if(ne(b)==="relationship"){let B=find(propEq(b.relationship?.entity,"name"))(n),H=find(propEq(b.relationship?.field,"name"))(B?.attributes??[]),q=ne(H)==="local"?`{
389
+ ${$}}
390
+ `;if(ue(S)==="relationship"){let M=find(propEq(S.relationship?.entity,"name"))(n),T=find(propEq(S.relationship?.field,"name"))(M?.attributes??[]),P=ue(T)==="local"?`{
398
391
  _id
399
392
  default
400
- ${L}}
401
- `:"";if(b.relationship?.mode==="single")return `${D}
402
- ${b.name} {
403
- ${b.relationship.field} ${q}}
404
- `;if(b.relationship?.field)return `${D}
405
- ${b.name} (limit: 25, offset: 0) {
406
- ${b.relationship.field} ${q}}
407
- `}return `${D}
408
- ${b.name}
409
- `},"");return `${C}
410
- ${k.name} (limit: 25, offset: 0) { _id ${P??""}}
411
- `},"");return {queryEntityName:f,query:`query ${c}(${a}) {
412
- `+on(e,"(where: $where)")+` ${f}${r} {
393
+ ${$}}
394
+ `:"";if(S.relationship?.mode==="single")return `${C}
395
+ ${S.name} {
396
+ ${S.relationship.field} ${P}}
397
+ `;if(S.relationship?.field)return `${C}
398
+ ${S.name} (limit: ${vn}, offset: 0) {
399
+ ${S.relationship.field} ${P}}
400
+ `}return `${C}
401
+ ${S.name}
402
+ `},"");return `${v}
403
+ ${b.name} (limit: ${vn}, offset: 0) { _id ${A??""}}
404
+ `},"");return {queryEntityName:l,query:`query ${c}(${s}) {
405
+ `+bn(e,"(where: $where)")+` ${l}${r} {
413
406
  _id
414
407
  _updatedAt
415
- ${d} ${g} ${w} ${E} }
408
+ ${f} ${p} ${h} ${w} }
409
+ }
410
+ `}}function za({attributeName:e,entityName:t,entityNamePlural:o,schema:n}){let r=Ct(n,o),i=find(propEq(e,"name"))(r?.attributes??[]),a=xn(i,r),s=a?` properties {
411
+ sortOrder
412
+ }
413
+ `:"",l=a?"(first: $first, sort: [{ edge: { sortOrder: ASC } }])":"(first: $first)",c=`Get${ot(t)}AssetConnection`;return {queryEntityName:o,query:`query ${c}($where: ${t}Where, $first: Int) {
414
+ ${o}(where: $where) {
415
+ ${e}Connection${l} {
416
+ aggregate {
417
+ count {
418
+ nodes
419
+ }
420
+ }
421
+ edges {
422
+ `+s+` node {
423
+ ${yr}
424
+ }
425
+ }
426
+ }
427
+ }
416
428
  }
417
- `}}var rn=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ao(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(rn).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function _t(e,t){return t==="_assets"?a$e:find(propEq(t,"plural"))(e)}function Wn({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,s]=st(),a=oe(),f=useRef(false),c=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),d$1=!!e.payload.silent;if(useEffect(()=>{!d$1||f.current||(f.current=true,l());},[d$1]),d$1)return jsx(Fragment,{});let m={dialogTitle:`Delete ${c}`,dialogMessage:`Are you sure you want to delete the selected ${c}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>l()};function l(){let u=e.payload.entityId,g=Eo(e.payload.entityName,n,u);return new Promise(p=>{i(gql`
418
- ${g}
419
- `),s({variables:{where:{_id:{eq:u}}},update(w){w.evict({id:u});},onCompleted:()=>{toast.success("Item successfully deleted."),d$1&&a({type:"Dismiss",_id:e._id,payload:{}}),p();}}),r(true);})}return jsx(wo,{options:m})}var zc=Drawer.Portal;function ma({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function jc({...e}){return jsx(zc,{...e})}function Hc({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 pa({className:e,children:t,...o}){return jsxs(jc,{children:[jsx(Hc,{}),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 ga({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 ka({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 ha({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Ot({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:s,title:a}){let[f,c]=useState(false),d=n*(50/n),m=useCallback(()=>{(!t||t())&&(c(false),setTimeout(()=>{s();},150));},[t,s,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(ma,{direction:"right",dismissible:false,onClose:()=>{m();},open:f,children:jsxs(pa,{style:r?{}:{maxWidth:`calc(100% - ${d.toString()}px)`},children:[jsxs(ga,{className:"fk:px-10",children:[jsx(ka,{className:"fk:w-full",children:a||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(ha,{className:"fk:sr-only",children:a||"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 ba=createContext({isDirty:false,setIsDirty:e=>{}}),wa=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(ba.Provider,{value:n,children:e})};function to(){return useContext(ba)}function oo({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function no({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}var Yc=["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 Yn(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 ef(e){let{projectId:t,accept:o,multiple:n=true,maxBytes:r=4*1024*1024}=e,i=document.createElement("input");i.type="file";let s=o??Yc.join(",");i.accept=s,i.multiple=n,i.style.display="none",document.body.appendChild(i);try{let a=await new Promise(d=>{i.onchange=()=>d(i.files),i.click();});if(!a||a.length===0)return [];let f=[];for(let d of Array.from(a)){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=>Yn(d,t)));return c.length>0&&toast.success(`Uploaded ${c.length} file${c.length>1?"s":""}`),c}catch(a){return console.error(a),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}function Do(){let e=useApolloClient();return useCallback(async t=>{let o=await ef(t);return o.length>0&&await e.refetchQueries({include:"active",onQueryUpdated:n=>n.queryName==="GetAssets"}).catch(n=>{console.error("Error refreshing asset lists after upload:",n);}),o},[e])}function ro(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 s of i)if(s.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 s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}function Ra({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:s,options:a}=o,{projectId:f$1}=useParams(),c$1=oe(),d=d$2(),{relationships:m$1}=c$2(),[l,u]=useState(false),g$1=useRef(null),p=useRef(null),w=useRef(null),[v,E]=useState(null),[C,k]=useState(false),[x,P]=useState(false),D=useId(),b=useId();ro(p,u,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let y=m$1[b]?.connect;if(!y||w.current===y._id)return;let h=mf(y.value);if(!h)return;let F=n(i$1);w.current=y._id,E(null),r(i$1,{...F,value:h});},[n,i$1,b,m$1,r]);function L(y){if(!y)return;let h={"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(h[y])return h[y];let F=y.split("/");if(F.length===2){let[,T]=F;return T.includes("svg")?"svg":T.toLowerCase()}}function B(y,h){if(y&&y.includes(".")){let T=y.split(".").pop();if(T)return T.toLowerCase()}let F=L(h);return F||"file"}async function H(y,h){if(!y)return;let F=tr("4MB");if(y.size>(F??0)){toast.error("File size too big (max 4MB)");return}let T=y.type.startsWith("image/");if(w.current=null,T){let z=new FileReader;z.onload=Q=>{E(Q.target?.result);},z.readAsDataURL(y);}else E(null);P(true);try{let z=await Yn(y,f$1);r(i$1,{...n(i$1),value:z.asset});}catch(z){console.error(z),E(null),r(i$1,{...n(i$1),value:{_id:h?.value?._id}});}finally{P(false);}}function q(y){y.stopPropagation(),w.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function X$1(y,h){y.stopPropagation(),h?.value&&typeof h.value=="object"&&"path"in h.value&&navigator.clipboard.writeText(`${b$4}${h.value.path}`);}function R(y){y.preventDefault(),y.stopPropagation(),g$1.current?.click();}function M(y){y.preventDefault(),y.stopPropagation(),u(false);let h=n(i$1)?.value,F=w.current??pf(h),T=F?{_id:F,value:h}:void 0;d({type:"setRelationship",payload:{[b]:{connect:T,disconnect:[]}}}),window.setTimeout(()=>{c$1({type:"EditRelationship",payload:{assetAccept:a?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:h?.path,initialConnection:T,relationshipId:b,mode:"single"}});},0);}function I(y,h){y.stopPropagation(),h?.value&&typeof h.value=="object"&&"path"in h.value&&window.open(`${b$4}${h.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$1,render:({field:y})=>jsxs(e,{children:[jsx(f,{htmlFor:D,children:s}),a?.comment?jsx(h,{children:a.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":""} ${C?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:h=>{h.preventDefault(),h.stopPropagation(),p.current?.focus(),p.current?.click(),u(true);},onKeyDown:h=>{h.key==="Enter"&&u(true),h.key==="Escape"&&(h.preventDefault(),h.stopPropagation(),p.current?.blur(),u(false));},onDragOver:h=>{h.preventDefault(),h.stopPropagation(),k(true);},onDragEnter:h=>{h.preventDefault(),h.stopPropagation(),k(true);},onDragLeave:h=>{h.preventDefault(),h.stopPropagation(),k(false);},onDrop:h=>{h.preventDefault(),h.stopPropagation(),k(false);let F=h.dataTransfer.files&&h.dataTransfer.files[0];H(F,y.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!y.value?.value?.path&&!v?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:D,onClick:R,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",onClick:M,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,y.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 h=y.value?.value,F=h?.mimeType,T=h?.path||"";if(!!(F&&F.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(T)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${h.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let Q=B(h.originalFilename,h.mimeType),De=defaultStyles[Q];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:Q,...De||{}})})})(),tr((y.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(y.value?.value).mimeType,(y.value?.value).width&&(y.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(y.value?.value).width,"x",(y.value?.value).height,"px"]}):null]}):null,!y.value?.value?.path&&v&&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:v,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..."]}),!y.value?.value?.path&&!v&&x?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,y.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:h=>{h.stopPropagation();},onPointerDown:h=>{h.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:R,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:M,children:[jsx(Image,{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:h=>I(h,y.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:h=>X$1(h,y.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:q,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!l&&(y.value?.value?.path||v)?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:h=>{h.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&&(y.value?.value?.path||v)?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:h=>{h.preventDefault(),h.stopPropagation(),p.current?.blur(),u(false);},onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),h.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(oo,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:u,open:l&&(!!y.value?.value?.path||!!v),children:jsx(no,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:y.value?.value?.path?(()=>{let h=y.value?.value,F=h?.mimeType,T=h?.path||"";if(!!(F&&F.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(T)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${h.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let Q=B(h.originalFilename,h.mimeType),De=defaultStyles[Q];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:Q,...De||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[h.originalFilename||"File"," \xB7 ",tr(h.size)," \xB7 ",h.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),x?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:a?.accept?a.accept:"image/*",className:"fk:hidden",id:`file-upload-${i$1}`,onChange:h=>{let F=h.currentTarget.files&&h.currentTarget.files[0];H(F,y.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function mf(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 pf(e){return !e?._id||e._id.includes(":")?"":e._id}function Fa({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:s,dataType:a}=t,f$1=useId();function c$1(m,l){let u=m.currentTarget.value,g;u===""?g="":(g=a==="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}),s?.comment?jsx(h,{children:s.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:a==="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 io({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function ao({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function xt({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 Ma({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:s,...a}){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",a.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:wf,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})}),...s},...a})}function wf({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=cn.useRef(null);return cn.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 $a({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:s,options:a}=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}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsxs(io,{children:[jsx(ao,{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:s===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(xt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Ma,{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,w]=g.split(":"),v=l.value?.value?new Date(l.value.value):new Date;v.setHours(parseInt(p)),v.setMinutes(parseInt(w)),n(r,{...l.value,value:v.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 Ae(e){return e??null}var nr=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=Ae(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=Ae(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=Ae(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");}}]),La=Command.configure({suggestion:{items:()=>nr,render:renderItems}});var Oa=[{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"}],Va=[{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)"}],Ba=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Oa.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Va.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(io,{modal:true,open:e,onOpenChange:t,children:[jsx(ao,{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(xt,{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"}),Oa.map(({name:i,color:s})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(s||"").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:s},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"}),Va.map(({name:i,color:s})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:s}).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:s},children:"A"}),jsx("span",{children:i})]}),o.isActive("highlight",{color:s})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Qf(e){try{return new URL(e),!0}catch{return false}}function Gf(e){if(Qf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var ja=({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(xt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let s=i[0],a=Gf(s.value);a&&(n.chain().focus().setLink({href:a}).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 qa=[{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=Ae(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=Ae(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=Ae(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=Ae(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ae(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ae(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")}],Ua=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=qa.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:qa.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 Xa=()=>{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 Qa=()=>{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=Ae(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=Ae(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=Ae(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=Ae(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 To({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 hd=()=>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"})]}),Ga=hd;function sr({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 Rd=[{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 cr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:Rd.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 Za({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:s,isLoading:a}=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(Vd,{children:i})})})}),a&&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(To,{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(Ga,{})})]}),!a&&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 s(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let c=t.state.selection.content(),d=t.storage.markdown.serializer.serialize(c.content);s(d,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:f?jsx(sr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(cr,{onSelect:(c,d)=>s(c,{body:{option:d}})})})]})]}):null}function dr({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(Za,{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(To,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var nu=[...a,La];function Ya(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 ru(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(Ya(o))return o}catch{return}}if(Ya(e))return e}function ur({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:s,options:a}=o,[f$1,c$1]=useState(false),[d,m]=useState(false),[l,u]=useState(false),[g$1,p]=useState(false),w=useDebouncedCallback((C,k)=>{let x=C.getJSON();n(r,{...k,value:JSON.stringify(x)});},300);function v(C,k){n(r,{...k,disabled:C});}let E=C=>(console.log("Image uploader not yet implemented",C),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:C})=>jsxs(e,{children:[jsx(f,{children:i$1}),a?.comment?jsx(h,{children:a.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:s!==false&&!C.value?.disabled,editorProps:{handleDOMEvents:{keydown:(k,x)=>handleCommandNavigation(x)},handlePaste:(k,x)=>handleImagePaste(k,x,E),handleDrop:(k,x,P,D)=>handleImageDrop(k,x,D,E),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:nu,initialContent:ru(C.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:k})=>{w(k,C.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:nr.map(k=>jsxs(EditorCommandItem,{value:k.title,onCommand:x=>k.command?.(x),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm 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:k.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:k.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:k.description})]})]},k.title))})]}),jsxs(dr,{open:f$1,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx(Ua,{open:d,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(ja,{open:l,onOpenChange:u}),jsx(g$3,{orientation:"vertical"}),jsx(Xa,{}),jsx(g$3,{orientation:"vertical"}),jsx(Qa,{}),jsx(g$3,{orientation:"vertical"}),jsx(Ba,{open:g$1,onOpenChange:p})]})]},`${r}:${C.value?.scope??t.scope}:${String(C.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:C.value?.disabled??false,onChange:k=>{v(k,C.value);},scope:C.value?.scope}),jsx(i,{})]})})}function kr({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:s,options:a,relationship:f$1}=n,{projectId:c$1}=useParams(),d=oe(),m=d$2(),{relationships:l}=c$2(),u=Do(),g$1=useId(),p=useId(),w=useRef(null),v$1=useRef([]),E=useRef(null),C=useRef([]),k=useRef(""),[x,P]=useState(false),D=useMemo(()=>pu(t.value),[t.value]),[b,L]=useState(D);ro(w,P),useEffect(()=>{let R=Dt(D);v$1.current=D.map(M=>M._id),C.current=[],L(M=>{let I=Dt(M);return R===""&&I!==""&&k.current===I||I===R?M:(k.current=R,D)});},[D]),useEffect(()=>{let R=l[p]?.connect;if(!R)return;let M=R.map((F,T)=>ns(F.value,F.sortOrder??T)).filter(F=>!!F),I=Dt(M),y=Dt(b),h=E.current;h===y&&I!==h||(E.current=null,I!==y&&L(M));},[p,l,b]),useEffect(()=>{let R=Dt(b);if(k.current===R)return;let M=b.map((h,F)=>({_id:h._id,sortOrder:F,value:{...h,sortOrder:F}})),I=b.map(h=>h._id),y=C.current.filter(h=>!I.includes(h));k.current=R,m({type:"setRelationship",payload:{[p]:{connect:M,disconnect:y}}}),r(i$1,{...t,relationships:{connect:M,disconnect:y},value:b});},[m,t,i$1,p,b,r]);function B(R){R.preventDefault(),R.stopPropagation(),d({type:"EditRelationship",payload:{connectedEntitiesCount:b.length,entityName:f$1?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:a?.accept}});}async function H(R){R.preventDefault(),R.stopPropagation();let M=await u({projectId:c$1,accept:a?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});L(I=>{let y=new Set(I.map(T=>T._id)),h=M.map((T,z)=>({...T.asset,sortOrder:I.length+z})).filter(T=>!y.has(T._id)),F=pr([...I,...h]);return E.current=Dt(F),F});}function q(R){L(M=>{let I=pr(M.filter(y=>y._id!==R));return v$1.current.includes(R)&&!C.current.includes(R)&&(C.current=[...C.current,R]),E.current=Dt(I),I});}function X$1(R,M){L(I=>{let y=I.findIndex(Q=>Q._id===R),h=y+M;if(y<0||h<0||h>=I.length)return I;let F=[...I],[T]=F.splice(y,1);if(!T)return I;F.splice(h,0,T);let z=pr(F);return E.current=Dt(z),z});}return jsx(c,{control:e$1,defaultValue:t,name:i$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:g$1,children:s}),a?.comment?jsx(h,{children:a.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":x,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 ${x?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:R=>{R.preventDefault(),R.stopPropagation(),w.current?.focus(),P(true);},ref:w,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:[x&&b.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[b.length," ",b.length===1?"asset":"assets"," selected"]}):b.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[b.slice(0,8).map(R=>jsx(uu,{asset:R},R._id)),!x&&b.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:["+",b.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:R=>{R.preventDefault(),R.stopPropagation(),P(M=>!M);},size:"icon",variant:"ghost",children:x?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:x?"Close":"Expand field"})})]})})]}),jsx(oo,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:P,open:x,children:jsx(no,{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:B,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:R=>{H(R);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),b.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:b.map((R,M)=>jsx(mu,{asset:R,index:M,isFirst:M===0,isLast:M===b.length-1,moveAsset:X$1,removeAsset:q},R._id))})}):null]})})})]})})}),jsx(i,{})]})})}function uu({asset:e}){return rs(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 mu({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:rs(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 pu(e){return Array.isArray(e)?e.map((t,o)=>ns(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Dt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function pr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function ns(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 rs(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function as({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 gn({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 yu=new Set(["text","textarea","number","datetime","switch","select","editor"]);function Mo({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:"text",switch:"boolean",text:"text",textarea:"text"},s={boolean:a$a,date:a$9,datetime:a$c,editor:b$7,asset:a$b,number:a$9,relationship:a$9,select:a$9,switch:a$a,text:a$9,textarea:a$9,tags:as},a=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??s[u]??s.text;if(l.isHidden)return null;let p=u==="tags",w=n&&l.scope==="global"&&yu.has(l.inputType);return {accessorKey:l.name,filterFn:(v,E,C)=>p?true:(Array.isArray(C)?C:[C]).includes(v.getValue(E)),header:({column:v})=>w?jsx(gn,{column:v,title:l.label}):jsx("div",{className:"fk:flex fk:items-center",children:l.label}),cell:({row:v})=>jsx(g,{value:v.getValue(l.name)}),enableSorting:w,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(gn,{column:l,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:l})=>jsx(a$c,{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$d,{"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$d,{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$d,{"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]:[],...a,c]}function Tu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function Nu(e){return Math.max(600,e)}function $o({classNames:e,columns:t,data:o,entityName:n$1,hasMore:r=false,initialSelectionState:i,isLoadingMore:s=false,onEntitySelectionChange:a,onLoadMore:f,onScroll:c,onSortingChange:d,pageSize:m,rowHeightEstimate:l$1,rowAdditionState:u,rowDeletionState:g,scrollToTopKey:p,sorting:w,toolbarComponent:v}){let E=useRef(null),{schemaErrorMessage:C}=Mt(),[k,x]=useState(i??{}),[P,D]=useState({}),[b,L]=useState([]),[B,H]=useState([]),q=w??B;useEffect(()=>{E.current?.scrollTo({top:0});},[n$1,p]),useEffect(()=>{if(!i)return;let $=Object.keys(k).sort().join(","),U=Object.keys(i).sort().join(",");$!==U&&x(i);},[i,k]);function X($){if(d){d($);return}H($);}let R=useReactTable({data:o,columns:t,state:{sorting:q,columnVisibility:P,rowSelection:k,columnFilters:b},initialState:{pagination:{pageSize:m??25}},enableRowSelection:true,onRowSelectionChange:De,onSortingChange:X,onColumnFiltersChange:L,onColumnVisibilityChange:D,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:$=>$._id,manualPagination:true,manualSorting:true,meta:{getRowBackground:$=>Pu($,g,u)}}),{rows:M}=R.getRowModel(),I=useVirtualizer({count:M.length,estimateSize:()=>l$1??Tu(e?.row)??45,getScrollElement:()=>E.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?$=>$.getBoundingClientRect().height:void 0,overscan:5}),y=I.getVirtualItems(),h=I.getTotalSize(),F=useRef(f),T=useRef(r),z=useRef(s);F.current=f,T.current=r,z.current=s;let Q=useCallback($=>{if(!F.current||!T.current||z.current)return;let U=$??E.current;if(!U)return;let{scrollHeight:ve,scrollTop:Ht,clientHeight:_}=U;ve-Ht-_>=Nu(_)||F.current();},[]);useEffect(()=>{Q();},[Q,M.length,r,s]);function De($){let U=Object.keys(typeof $=="function"?$(k):$);x($),a?.(U);}function Xe($){c?.($),Q($.currentTarget);}return C?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:[v&&v(R),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:Xe,ref:E,children:[jsx(i$1,{className:"fk:sticky fk:top-0 fk:z-10 fk:grid",children:R.getHeaderGroups().map($=>jsx(l,{className:"fk:flex fk:w-full",children:$.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()),s?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))},$.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${h.toString()}px`},children:y.length?y.map($=>{let U=M[$.index];return jsx(l,{className:`${R.options.meta.getRowBackground(U)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":$.index,"data-state":U.getIsSelected()&&"selected",ref:I.measureElement,style:{transform:`translateY(${$.start.toString()}px)`},children:U.getVisibleCells().map(ve=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",ve.column.id==="actions"&&"fk:pl-1!"),style:{width:ve.column.getSize()},children:flexRender(ve.column.columnDef.cell,ve.getContext())},ve.id))},$.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function Pu(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 ls({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 qu=25;function wr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:s,schema:a,scope:f$1,setValue:c$1}){let[d,m]=useState(false),l=useRef(null);ro(l,m);let[u,g$1]=useState([]),{name:p,label:w,options:v,relationship:E}=s,C=E?.entity??p,k=oe(),x=d$2(),{relationships:P}=c$2(),D=useId(),b=useId(),L=find(propEq(C,"name"))(a),B=L?.attributes??[],q=find(propEq(r,"name"))(a)?.name??"",X$1,R=B.find(_=>_.relationship?.entity===q);R&&(X$1=R.name);let M=Ju(B),I=useMemo(()=>o.value?Xu({data:o.value,defaultScope:t,relationshipEntitySchema:L,scope:f$1}):[],[t,o,M,L,f$1]),y=fa({attributeName:p,relatedEntityName:C,scope:f$1,schema:a}),F=u.length?u.slice(0,12).map(_=>_[M]):[],T=Math.max(u.length,o.count??0)>F.length,[z,{loading:Q,data:De}]=useLazyQuery(gql`
420
- ${y.query}
421
- `),Xe=Mo({attributesSchema:L?.attributes??[],actionsComponent:_=>Uu({appDispatch:x,relationshipId:b,relationships:P,row:_,setRows:g$1})});useEffect(()=>{g$1(I),o.value!==""&&x({type:"setRelationship",payload:{[b]:{connect:[],disconnect:[]}}});},[x,De,I,b,o,f$1]),useEffect(()=>{c$1(p,{...o,relationships:P[b]});},[o,P,b,c$1,p]),useEffect(()=>{let qt=(P[b]?.connect??[]).map(({value:Bo})=>Bo);g$1(uniqBy(prop("_id"),[...qt,...I]));},[De,o.count,I,P,b]);let $=o.count??0,U=$>0&&u.length>0&&u.length<$,ve=useCallback(()=>{Q||z({variables:{limit:qu,offset:u.length,where:X$1?{[X$1]:{some:{_id:{eq:n}}}}:{}}}).then(({data:_})=>{if(!_)return;let qt=nn(L?.plural??"",f$1,_,a);g$1(uniqBy(prop("_id"),[...I,...qt.results]));}).catch(_=>{console.error("Error fetching more data:",_);});},[X$1,n,z,I,Q,L?.plural,u.length,a,f$1]);function Ht(_){_.preventDefault(),k({type:"EditRelationship",payload:{connectedEntitiesCount:I.length,connectionName:X$1,entityName:C,entityId:n,relationshipId:b,mode:E?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:D,children:w}),v?.comment?jsx(h,{children:v.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:Ht,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",L?.menu?.label??L?.plural]}):jsxs("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:[F.map(_=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:_},_)),T?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:D,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(oo,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:m,open:d,children:jsx(no,{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($o,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:Xe,data:u,entityName:r,hasMore:U,isLoadingMore:Q&&u.length>0,onLoadMore:ve,rowAdditionState:P[b]?.connect,rowDeletionState:P[b]?.disconnect})})})})]})})}),jsx(i,{})]})})}function Uu({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(s){let a=o[t]?.connect??[],f=typeof find(propEq(s,"_id"),a)=="object",c=o[t]?.disconnect?.includes(s),d=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],s]);f&&r(m=>m.filter(l=>l._id!==s)),e({type:"setRelationship",payload:{[t]:{connect:a.filter(m=>m._id!==s),disconnect:c?o[t]?.disconnect?.filter(m=>m!==s)??[]:d}}});}return jsx(ls,{action:i,row:n})}function Ju(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function Xu({data:e,defaultScope:t,relationshipEntitySchema:o,scope:n}){if(!Array.isArray(e))return [];let r=i=>{let a=find(propEq(i.__typename,"name"))(o?.attributes??[])?.relationship?.field??"";if(a){let f=i[a],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(s=>{if(Array.isArray(s)){let a=s;return a.length===0?"":a.length===1?r(a[0]):a.slice(0,3).map(r).join(", ")}return s&&typeof s!="string"&&s.__typename?r(s):s},i))}function Cr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:s,scope:a,setValue:f$1}){let[c$1,d]=useState(false),{name:m,label:l,options:u,relationship:g$1}=r,p=g$1?.entity??m,w=oe(),v=d$2(),E=useId(),{relationships:C}=c$2(),k=useId(),x=find(propEq(p,"name"))(s),D=Yu(x?.attributes??[]).name;useEffect(()=>{o.value!==""&&v({type:"setRelationship",payload:{[k]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[v,k,o,a]),useEffect(()=>{f$1(m,{...i$1(m),...C[k]?.connect??""});},[o,m,C,k,f$1]);function b(B){B.preventDefault(),w({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:k,mode:g$1?.mode??"single"}});}function L(B){let H={type:"setRelationship",payload:{[k]:{connect:[],disconnect:[]}}};B.preventDefault(),v(H),f$1(m,{...i$1(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:m,render:({field:B})=>{let H=B.value?.value,q="";if(H&&typeof H=="object"&&!Array.isArray(H)&&H[D]){let X=H[D],R=Array.isArray(X)?X[0]:X;typeof R=="string"?q=R:q=R?.[a]??R?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:E,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:E,onBlur:()=>{d(false);},onClick:b,onFocus:()=>{d(true);},onKeyDown:X=>{X.key==="Enter"&&b(X);},readOnly:true,type:"text",value:q}),q?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:L,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:b,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 Yu(e){return e.find(t=>t.isPrimary)??e[0]}function xr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(Cr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(kr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(wr,{...n})}return jsxs(se,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Fe,{children:"Error"}),jsx(le,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var gs="flexkit-select-option:";function Sr(e){return `${gs}${encodeURIComponent(e)}`}function om(e){return decodeURIComponent(e.slice(gs.length))}function ks({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:s}=t;function a(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}),s?.comment?jsx(h,{children:s.comment}):null,jsxs(a$5,{defaultValue:c.value?.value===void 0||c.value.value===null?void 0:Sr(String(c.value.value)),disabled:i$1===false||c.value?.disabled,onValueChange:d=>{a(om(d),c.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:s?.placeholder})})}),jsx(e$1,{children:s?.list?.map(d=>"groupLabel"in d?jsxs(b$1,{children:[jsx(f$1,{children:d.groupLabel}),d.items.map(m=>jsx(g$1,{value:Sr(m.value),children:m.label},m.label))]},d.groupLabel):jsx(g$1,{value:Sr(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 Dr({inputType:e,label:t}){return jsxs(se,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Fe,{children:"Error"}),jsx(le,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function km(e,t){let o=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:o}}function hm({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:s,setIsDirty:a,onSubmit:f},c){let d$1=find(propEq(n,"name"))(s),m=useMemo(()=>d$1?.attributes??[],[d$1]),l=useMemo(()=>i||m.reduce((D,b)=>({...D,[b.name]:km(b,t)}),{}),[t,i,m]),u=useMemo(()=>z.object(m.reduce((D,b)=>typeof b.validation>"u"?D:{...D,[b.name]:z.object({value:b.validation(z).or(z.any().refine(()=>false,{message:b.label?`${b.label} is required`:"Required field"}))})},{})),[m]),g=useForm({defaultValues:l,resolver:zodResolver(u),values:i,mode:"onBlur",criteriaMode:"all"}),{control:p,getValues:w,handleSubmit:v,setValue:E,watch:C,trigger:k}=g,{getContributionPointConfig:x}=d(),P={datetime:$a,editor:ur,asset:Ra,number:Fa,relationship:xr,select:ks,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){k().then(()=>{v(()=>{a(false),f(w(),i);})();});},hasErrors(){a(true);},hasDataChanged(){return hs(w(),i)}})),useEffect(()=>{let D=C(b=>{a(hs(b,i));});return ()=>{D.unsubscribe();}},[i,a,C]),!d$1||d$1.attributes.length===0?jsxs(se,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Fe,{children:"Error"}),jsxs(le,{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 b=x("formFields",[D.inputType])?.[0]?.component??P[D.inputType];return b?createElement(b,{key:D.name,control:p,defaultScope:t,defaultValue:l[D.name],entityId:o,entityName:n,entityNamePlural:r,fieldSchema:D,getValues:w,schema:s,scope:e,setValue:E}):jsx(Dr,{inputType:D.inputType,label:D.label},D.name)})})})}var Cn=memo(forwardRef(hm));function hs(e,t){if(!t)return Object.keys(e).some(s=>e[s]?.value!==""&&e[s]?.value!==void 0);let o=s=>typeof s=="object"&&s!==null?"path"in s?s.path:"_id"in s?s._id:"":s??"",n=(s,a)=>s<a?-1:1,r=Object.keys(t).sort((s,a)=>n(s,a)).filter(s=>s!=="_updatedAt").reduce((s,a)=>({...s,[a]:{value:o(t[a].value),disabled:t[a].disabled,relationships:t[a].relationships}}),{}),i=Object.keys(e).sort((s,a)=>n(s,a)).filter(s=>s!=="_updatedAt").reduce((s,a)=>({...s,[a]:{value:o(e[a]?.value),disabled:e[a]?.disabled??false,relationships:Object.keys(e[a]?.relationships?.connect??{}).length||e[a]?.relationships?.disconnect?.length?e[a]?.relationships:void 0}}),{});return !equals(r,i)}function Rr({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:s}=d(),{schema:a,scopes:f}=find(propEq(s??"","projectId"))(i),c=f?.find(D=>D.isDefault)?.name??"default",m=find(propEq(n,"name"))(a)?.plural??n,{scope:l}=c$2(),u=oe(),[g,p,w,v]=st(),{setIsDirty:E}=to();useEffect(()=>{v.error&&r.current?.hasErrors();},[v.error]);function C(){return r.current?.hasDataChanged()?(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 k=useCallback(D=>{u({type:"Dismiss",_id:D,payload:{}});},[u]),x=useCallback(()=>{r.current?.submit();},[r]),P=useCallback(D=>{let b=v4(),L=Gn(m,a,D,b),B=Lt(m,l,a),H=gql`
422
- ${B.query}
423
- `;p(gql`
424
- ${L}
425
- `),w({refetchQueries:[H],onCompleted:()=>{k(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,m,k,g,a,p,l,w]);return jsx(Ot,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",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:C,depth:t,isFocused:o,onClose:()=>{k(e._id);},title:`Add ${n}`,children:jsx(Cn,{currentScope:l,defaultScope:c,entityName:n,entityNamePlural:m,onSubmit:P,ref:r,schema:a,setIsDirty:E})})}function Lo({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r,selection:i="full"}){let[s,a]=useState({count:0,results:[]}),[f,c]=useState(false),[d,m]=useState(false),l=useRef(false),u=useRef(false),g=useRef(null),p=useRef(null),w=Lt(e,o,t,{selection:i}),v=useMemo(()=>gql`
426
- ${w.query}
427
- `,[w.query]),{schemaErrorMessage:E,setSchemaErrorMessage:C}=Mt(),{loading:k,data:x,fetchMore:P,refetch:D,error:b}=useQuery(v,{variables:n}),L=useRef(P),B=useRef(D);L.current=P,B.current=D;let H=Ft(b),q=en(b),{isProjectDisabled:X,isProjectReadOnly:R}=(()=>{if(H?.statusCode===403){let y=It(H.bodyText);if(y&&typeof y.code=="string"){if(y.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(y.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),M=useCallback(y=>{l.current||u.current||(l.current=true,c(true),L.current(y).then(({data:h})=>{let F=Ir({data:h,entityNamePlural:e,isForm:r,schema:t,scope:o});a(T=>{let z=uniqBy(prop("_id"),[...T.results,...F.results]);return z.length===T.results.length?{count:T.results.length,results:T.results}:{count:F.count,results:z}});}).catch(h=>{console.error("Error fetching more data:",h);}).finally(()=>{l.current=false,c(false);}));},[e,r,t,o]),I=useCallback(()=>{u.current||(u.current=true,l.current=false,c(false),g.current=null,p.current=null,m(true),a({count:0,results:[]}),B.current().then(({data:y})=>{let h=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n});g.current=h,p.current=null,a(Ir({data:y,entityNamePlural:e,isForm:r,schema:t,scope:o}));}).catch(y=>{console.error("Error reloading data:",y);}).finally(()=>{u.current=false,m(false);}));},[e,r,t,o,i,n]);return useEffect(()=>{if(q){C(q);return}x&&E&&!b&&C(null);},[x,b,E,q,C]),useEffect(()=>{if(b||q)return;let y=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n});if(g.current!==y){if(k&&p.current!==y){p.current=y,a({count:0,results:[]});return}k||(g.current=y,p.current=null,a(Ir({data:x,entityNamePlural:e,isForm:r,schema:t,scope:o})));}},[x,e,b,r,k,t,q,o,i,n]),{isLoading:k||d,isLoadingMore:f,fetchMore:M,reload:I,count:s.count,data:s.results,isProjectDisabled:X,isProjectReadOnly:R,schemaErrorMessage:E}}function Ir(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?ia(e.entityNamePlural,e.scope,e.data,e.schema):nn(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function Es(){return jsxs(se,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Fe,{children:"Read Only Mode"}),jsxs(le,{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 $r({handleSave:e,isLoading:t}){let{isDirty:o}=to();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 Lr(){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 Vr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:s,currentProjectId:a}=d(),{schema:f,scopes:c}=useCallback(()=>find(propEq(a??"","projectId"))(s),[a,s])(),d$3=c?.find(T=>T.isDefault)?.name??"default",m=find(propEq(r,"plural"))(f),l=m?.name??r,{scope:u}=c$2(),[g,p]=useState(u),w=oe(),v=d$2(),[E,C,k,x]=st(),{setIsDirty:P}=to(),D=useCallback(T=>{P(T);},[P]);useEffect(()=>{x.error&&i.current?.hasErrors();},[x.error]);let b=useCallback(()=>i.current?.hasDataChanged()?(w({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:()=>{w({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{w({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[w,e._id]),L=useCallback(T=>{w({type:"Dismiss",_id:T,payload:{}});},[w]),B=useCallback(()=>{i.current?.submit();},[i]);function H(T){if(i.current?.hasDataChanged()){w({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),w({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(T),v({type:"setScope",payload:{projectId:a,scope:T}});}}}});return}p(T),v({type:"setScope",payload:{projectId:a,scope:T}});}let q=useCallback((T,z)=>{if(!z)return;let Q=Xn(r,n,g,f,z,T),De=Lt(r,g,f),Xe=gql`
428
- ${De.query}
429
- `;C(gql`
430
- ${Q}
431
- `),k({variables:{where:{_id:{eq:n}}},refetchQueries:[{query:Xe,variables:{where:{_id:{eq:n}}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),E(true);},[g,n,r,E,f,C,k]),{isLoading:X,data:R}=Lo({entityNamePlural:r,schema:f,scope:g,variables:{where:{_id:{eq:n}}},isForm:true}),M=R,I=M.length>0,y=X&&!I;function h(T,z){let Q=T?.attributes.find(ve=>ve.isPrimary)??T?.attributes[0],De=Q.name,Xe=Q?.relationship?.field!==void 0;if(!z.length)return "";if(!Xe||!Q?.relationship?.field)return z[0][De]?.value;let $=z[0][De]?.value?.[Q.relationship.field],U=Array.isArray($)?$[0]:$;if(U&&typeof U=="object"){let ve=U;return ve[g]??ve.default??""}return U??""}let F=I&&m?h(m,M):"";return jsx(Ot,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:T=>{H(T);},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(T=>jsx(g$1,{value:T.name,children:T.label},T.name))})]}):null,jsx($r,{handleSave:B,isLoading:x.loading})]}),beforeClose:b,depth:t,isFocused:o,onClose:()=>{L(e._id);},onFormChange:()=>{},title:F,children:y||!I?jsx(Lr,{}):jsxs(Fragment,{children:[x.isProjectReadOnly?jsx(Es,{}):null,jsx(Cn,{currentScope:g,defaultScope:d$3,entityId:n,entityName:l,entityNamePlural:r,formData:M[0],onSubmit:q,ref:i,schema:f,setIsDirty:D})]})})}var Fs=25;function jm(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function jr({action:e,depth:t,isFocused:o}){let n=oe(),r=d$2(),{relationships:i,scope:s}=c$2(),{assetAccept:a,connectedEntitiesCount:f,connectionName:c,entityId:d$1,entityName:m,initialAssetPath:l,initialConnection:u,mode:g,relationshipId:p}=e.payload,{projects:w,currentProjectId:v}=d(),{schema:E}=find(propEq(v??"","projectId"))(w),C=find(propEq(m,"name"))(E),k=C?.plural??"",x=i[p],P=Do(),D=m==="_asset",b=D?"asset":C?.menu?.label??m.toLowerCase(),L=D&&g==="single"?"Select asset":`Select ${D?"assets":b}`,B=g==="single"?"Upload asset":"Upload assets",[H,q]=useState([]),X=[];if(u)X=[{id:u._id,value:u.value}];else if(x?.connect){let J=x.connect;X=[{id:J._id,value:J.value}];}let R=g==="single"?X:x?.connect?.map(J=>({id:J._id,value:J.value}))||[],[M,I]=useState(R),y=useMemo(()=>{let J=c?{[c]:{none:{_id:{eq:d$1}}}}:{},te=D?{NOT:{path:{eq:null}}}:{},Le={OR:H.map(ut=>({_id:{eq:ut._id}}))};return g==="multiple"?{...te,...J,...Le}:{...te,...Le}},[c,d$1,D,g,H]),{count:h,data:F,fetchMore:T,isLoading:z,isLoadingMore:Q}=Lo({entityNamePlural:k,schema:E,scope:s,variables:{offset:0,limit:Fs,where:y,sort:[{_updatedAt:"DESC"}]}}),De=!!F?.length,Xe=z&&!De,$=F?.length??0,U=h-f,ve=U>0&&$>0&&$<U,Ht=Mo({attributesSchema:C?.attributes??[],checkboxSelect:g}),_=Array(5).fill({}),qt=jm(Ht);useEffect(()=>{if(g!=="single"||M.length>0||!l||!F?.length)return;let J=F.find(te=>te.path===l);!J?._id||typeof J._id!="string"||I([{id:J._id,value:J}]);},[F,l,g,M.length]);let Bo=useCallback(J=>{n({type:"Dismiss",_id:J,payload:{}});},[n]),Us=useCallback(()=>{T({variables:{offset:$,limit:Fs,where:y}});},[y,T,$]);function Js(){let J;if(g==="single"){let[te]=M;J={_id:te?.id??"",value:te?.value??null};}g==="multiple"&&(J=M?.map((te,Le)=>({_id:te.id??"",...D?{sortOrder:Le}:{},value:te.value}))),r({type:"setRelationship",payload:{[p]:{connect:J,disconnect:x?.disconnect??[]}}}),Bo(e._id);}function Xs(J){if(g==="multiple"){I(Le=>{let ut=new Map(Le.map(ie=>[ie.id,ie]));return J.map(ie=>{if(ut.has(ie))return ut.get(ie);let Ws=F?.find(Zs=>Zs._id===ie);return {id:ie,value:Ws}})});return}let te=J[J.length-1];I(te?Le=>{if(Le.length===1&&Le[0].id===te)return Le;let ut=F?.find(ie=>ie._id===te);return [{id:te,value:ut}]}:[]);}function Qs(){n({type:"AddEntity",payload:{entityName:m}});}async function Gs(){let J=await P({projectId:v,accept:a??"image/*",multiple:g==="multiple",maxBytes:4194304});I(te=>{if(g==="single"){let[ie]=J;return ie?[{id:ie._id,value:ie.asset}]:te}let Le=new Set(te.map(ie=>ie.id)),ut=J.filter(ie=>!Le.has(ie._id)).map(ie=>({id:ie._id,value:ie.asset}));return [...te,...ut]});}return jsx(Ot,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Js();},variant:"default",children:"Select"}),D?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{Qs();},variant:"outline",children:`Create ${b}`}),D?jsxs(b$3,{className:"fk:px-8",onClick:()=>{Gs();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),B]}):null]}),depth:t,isFocused:o,onClose:()=>{Bo(e._id);},title:L,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx($o,{columns:Xe?qt:Ht,data:Xe?_:F??[],entityName:C?.name??"",hasMore:ve,initialSelectionState:M?.reduce((J,te)=>({...J,...te.id?{[te.id]:true}:{}}),{}),isLoadingMore:Q,onEntitySelectionChange:Xs,onLoadMore:Us,toolbarComponent:()=>jsx(Hm,{entityNamePlural:k,projectId:v??"",setSearchResultIds:q})})})})}function Hm({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[s,a]=useState(i),{results:f,isLoading:c}=e$5(t,s),d=useRef(null),m=useMemo(()=>qm(u=>{a({...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 qm(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Ms(){let e=ta(),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(wo,{options:r.options},n._id)}case "DeleteEntity":return jsx(Wn,{action:n},n._id);case "AddEntity":return jsx(Rr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Vr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(jr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function $s({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$f(o);return window.location.pathname===r&&(window.location.href=b$b(r,n)),jsx(a$i,{children:jsx(c$6,{config:e,children:jsxs(Bi,{children:[jsx(wa,{children:jsx(Ms,{})}),jsx(Outlet,{})]})})})}function Ls(){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})})]}):_n(e)?Ei(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(Go,{})]})})]})}function qr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(se,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Fe,{children:"Error"}),jsx(le,{children:t})]})}var ip=RouterProvider;function ap({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(d=>_s(d)):[_s(e)],[i]=r,s=a$f(i?.basePath),a=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let f=[{path:s,element:jsx($s,{config:r}),errorElement:jsx(Ls,{}),children:[{path:":projectId",element:jsx(Fi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:a.map(d=>({path:d.name,element:d.component,errorElement:jsx(qr,{}),children:d.routes?.map(m=>({path:m.path,element:m.component,errorElement:jsx(qr,{}),children:m.children?.map(l=>({path:l.path,element:l.component}))}))}))}]}],c=createBrowserRouter(f);return n("Init Studio"),jsx(a$g,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(ea,{children:jsx(ip,{router:c})})})})}function _s(e){return {basePath:a$f(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function lp(){return jsxs(se,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Fe,{children:"Project Paused"}),jsxs(le,{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}=Mt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
432
- `);return jsxs(se,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Fe,{children:"Schema mismatch"}),jsxs(le,{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 up(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 pp(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function Bs(e){return e.attributes.forEach(t=>{mp(t,e.name);}),{...e,attributes:e.attributes.map(pp)}}function gp(e){return Bs(e)}function yp({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(io,{children:[jsx(ao,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk:h-8 fk:border-dashed",children:[jsx(CirclePlus,{className:"fk:mr-2 fk:h-4 fk:w-4"}),t$1,r$1?.size>0&&jsxs(Fragment,{children:[jsx(g$3,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:r$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[r$1.size," selected"]}):o$1.filter(i=>r$1.has(i.value)).map(i=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:i.label},i.value))})]})]})}),jsx(xt,{className:"fk:w-[200px] fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(i=>{let s=r$1.has(i.value);return jsxs(t,{onSelect:()=>{s?r$1.delete(i.value):r$1.add(i.value);let a=Array.from(r$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",s?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),i.icon&&jsx(i.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:i.label}),n?.get(i.value)&&jsx("span",{className:"fk:ml-auto fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:font-mono fk:text-xs",children:n.get(i.value)})]},i.value)})}),r$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function bp({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=oe(),i=o.original._id;function s(){r({type:"EditEntity",payload:{entityId:i,entityNamePlural:t}});}function a(){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:s,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:a,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:s,children:[jsx(PencilIcon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Edit"]}),jsx(m,{}),jsxs(h$1,{className:"fk:text-destructive",onClick:a,children:[jsx(Trash2Icon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete"]})]})]})]})}function Jr({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 Qr({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 Pp({entityName:e,isReloading:t=false,onReload:o,table:n}){let r=oe(),i=d$2(),s=c$2(),{projects:a,currentProjectId:f}=d(),{scopes:c}=find(propEq(f??"","projectId"))(a),[d$3,m,l]=st(),[u,g]=useState(false),p=n.getSelectedRowModel().rows.map(k=>k.original._id);function w(){r({type:"AddEntity",payload:{entityName:e}});}function v(k){i({type:"setScope",payload:{projectId:f,scope:k}});}async function E(k){let{schema:x}=find(propEq(f??"","projectId"))(a),P=Eo(e,x,k);await new Promise(D=>{m(gql`
429
+ `}}var zo=e=>e.charAt(0).toUpperCase()+e.slice(1);function ot(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(zo).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 ja(e,t,o){if(!e||typeof e!="object")return {};let n=Ct(o,t);if(!n)return {};let r=`update${zo(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"?{}:n.attributes.reduce((l,c)=>{if(ue(c)!=="local")return l;let d=wt(s[c.name])?._id;return typeof d!="string"||d.length===0?l:{...l,[c.name]:d}},{})}var Tn=null,xr=new Set,Ha=[],Sr=new Set,Er=new Set,Ar=new Set;function Ge(e,t){if(e==="_asset"||e==="_assets")return `Get${ot(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${ot(r)}`}function qa(e){return Sr.add(e),()=>{Sr.delete(e);}}function Ua(e){return Er.add(e),()=>{Er.delete(e);}}function Ja(e){return Ar.add(e),()=>{Ar.delete(e);}}function Dn(e,t,o){let n=new Set(o.filter(Boolean));if(n.size>0)for(let r of Er)r(t,n);return xt(e,t)}function Qa(e,t){let o=t.filter(n=>!!n._id);if(o.length!==0)for(let n of Ar)n(e,o);}function xt(e,t){return xr.add(t),new Promise((o,n)=>{Ha.push({resolve:o,reject:n}),Tn&&clearTimeout(Tn),Tn=setTimeout(()=>{let r=new Set(xr),i=Ha.splice(0);xr.clear(),Tn=null,Promise.all([...Sr].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 Tr({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),r=useApolloClient(),[i,a,s]=bt(),l=de(),c=useRef(false),f=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],d$1=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),u=!!e.payload.silent,m=f.length>1;if(useEffect(()=>{!u||c.current||(c.current=true,g());},[u]),u)return jsx(Fragment,{});let p={dialogTitle:m?`Delete ${f.length} ${d$1}s`:`Delete ${d$1}`,dialogMessage:m?`Are you sure you want to delete the selected ${d$1}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${d$1}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>g()};function g(){let h=Vo(e.payload.entityName,n,f);return new Promise((y,w)=>{a(gql`
430
+ ${h}
431
+ `),s({variables:{where:Bo(f)},update(v){for(let b of f)v.evict({id:b});},onCompleted:()=>{toast.success(m?"Items successfully deleted.":"Item successfully deleted."),Dn(r,Ge(e.payload.entityName,n),f),l({type:"Dismiss",_id:e._id,payload:{}}),y();},onError:v=>{w(v);}}),i(true);})}return jsx(Lo,{options:p})}var Ef=Drawer.Portal;function Wa({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function Af({...e}){return jsx(Ef,{...e})}function Tf({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 Za({className:e,children:t,...o}){return jsxs(Af,{children:[jsx(Tf,{}),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 Ka({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 Ya({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 es({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Zt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[l,c]=useState(false),f=n*(50/n),d=useCallback(()=>{(!t||t())&&(c(false),setTimeout(()=>{a();},150));},[t,a,c]),u=useCallback(m=>{m.key==="Escape"&&r&&d();},[d,r]);return useEffect(()=>{c(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",u,false),()=>{globalThis.document.removeEventListener("keydown",u,false);}),[u]),jsx(Wa,{direction:"right",dismissible:false,onClose:()=>{d();},open:l,children:jsxs(Za,{style:r?{}:{maxWidth:`calc(100% - ${f.toString()}px)`},children:[jsxs(Ka,{className:"fk:px-10",children:[jsx(Ya,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(es,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:d,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 ns=createContext({isDirty:false,setIsDirty:e=>{}}),rs=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(ns.Provider,{value:n,children:e})};function po(){return useContext(ns)}function Nr(e,t){return !t||t.length===0||e===void 0?true:e.some(o=>t.includes(o))}function go(e,t){return e.filter(o=>Nr(t,o.spaces))}function $f(e,t){return e.filter(o=>Nr(t,o.spaces)).map(o=>({...o,attributes:go(o.attributes,t)}))}function ko({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function ho({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}var Of=["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 Rr(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 Vf(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??Of.join(",");i.accept=a,i.multiple=n,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=>Rr(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 jo(){let e=useApolloClient();return useCallback(async t=>{let o=await Vf(t);return o.length>0&&await xt(e,"GetAssets").catch(n=>{console.error("Error refreshing asset lists after upload:",n);}),o},[e])}function yo(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 ps({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:l}=useParams(),c$1=de(),f$1=d$2(),{relationships:d}=c$2(),[u,m$1]=useState(false),p=useRef(null),g$1=useRef(null),h$2=useRef(null),[y,w]=useState(null),[v,b]=useState(false),[N,A]=useState(false),C=useId(),S=useId();yo(g$1,m$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let D=d[S]?.connect;if(!D||h$2.current===D._id)return;let k=Zf(D.value);if(!k)return;let V=n(i$1);h$2.current=D._id,w(null),r(i$1,{...V,value:k});},[n,i$1,S,d,r]);function $(D){if(!D)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[D])return k[D];let V=D.split("/");if(V.length===2){let[,W]=V;return W.includes("svg")?"svg":W.toLowerCase()}}function M(D,k){if(D&&D.includes(".")){let W=D.split(".").pop();if(W)return W.toLowerCase()}let V=$(k);return V||"file"}async function T(D,k){if(!D)return;let V=Ir("4MB");if(D.size>(V??0)){toast.error("File size too big (max 4MB)");return}let W=D.type.startsWith("image/");if(h$2.current=null,W){let ee=new FileReader;ee.onload=_=>{w(_.target?.result);},ee.readAsDataURL(D);}else w(null);A(true);try{let ee=await Rr(D,l);r(i$1,{...n(i$1),value:ee.asset});}catch(ee){console.error(ee),w(null),r(i$1,{...n(i$1),value:{_id:k?.value?._id}});}finally{A(false);}}function P(D){D.stopPropagation(),h$2.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function j(D,k){D.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function H(D){D.preventDefault(),D.stopPropagation(),p.current?.click();}function G(D){D.preventDefault(),D.stopPropagation(),m$1(false);let k=n(i$1)?.value,V=h$2.current??Kf(k),W=V?{_id:V,value:k}:void 0;f$1({type:"setRelationship",payload:{[S]:{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:S,mode:"single"}});},0);}function Z(D,k){D.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:D})=>jsxs(e,{children:[jsx(f,{htmlFor:C,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":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(),m$1(true);},onKeyDown:k=>{k.key==="Enter"&&m$1(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),m$1(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];T(V,D.value);},ref:g$1,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!D.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:C,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,D.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=D.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||{}})})})(),Ir((D.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(D.value?.value).mimeType,(D.value?.value).width&&(D.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(D.value?.value).width,"x",(D.value?.value).height,"px"]}):null]}):null,!D.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..."]}),!D.value?.value?.path&&!y&&N?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,D.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,D.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,D.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:P,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!u&&(D.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&&(D.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(),m$1(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),m$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(ko,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:u&&(!!D.value?.value?.path||!!y),children:jsx(ho,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:D.value?.value?.path?(()=>{let k=D.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 ",Ir(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),N?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 V=k.currentTarget.files&&k.currentTarget.files[0];T(V,D.value);},ref:p,type:"file"}),jsx(i,{})]})})}function Zf(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 Kf(e){return !e?._id||e._id.includes(":")?"":e._id}function gs({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,l=useId();function c$1(d,u){let m=d.currentTarget.value,p;m===""?p="":(p=s==="float"?parseFloat(m):parseInt(m,10),isNaN(p)&&(p="")),o(n,{...u,value:p});}function f$1(d,u){o(n,{...u,disabled:d});}return jsx(c,{control:e$1,name:n,render:({field:d})=>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] ${!d.value?.scope||d.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||d.value?.disabled,id:l,...d,onChange:u=>{c$1(u,d.value);},step:s==="float"?"any":"1",type:"number",value:d.value?.value??""})}),jsx(a$6,{checked:d.value?.disabled??false,onChange:u=>{f$1(u,d.value);},scope:d.value?.scope}),jsx(i,{})]})})}function vo({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function bo({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Vt({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 hs({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let l=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",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",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",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,...d})=>jsx("div",{"data-slot":"calendar",ref:f,className:a$4(c),...d}),Chevron:({className:c,orientation:f,...d})=>f==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",c),...d}):f==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",c),...d}):jsx(ChevronDownIcon,{className:a$4("size-4",c),...d}),DayButton:iu,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 iu({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=Fn.useRef(null);return Fn.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 ys({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,l=useId();function c$1(u,m){n(r,{...m,value:u?u.toISOString():""});}function f$1(u,m){n(r,{...m,disabled:u});}function d(u){u.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:u})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:l,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(vo,{children:[jsx(bo,{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:m=>{m.stopPropagation(),d(m);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(Vt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(hs,{mode:"single",selected:u.value?.value?new Date(u.value.value):void 0,onSelect:m=>c$1(m,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:m=>{let p=m.target.value,[g,h]=p.split(":"),y=u.value?.value?new Date(u.value.value):new Date;y.setHours(parseInt(g)),y.setMinutes(parseInt(h)),n(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:m=>{f$1(m,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function $e(e){return e??null}var $r=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=$e(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=$e(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=$e(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");}}]),vs=Command.configure({suggestion:{items:()=>$r,render:renderItems}});var ws=[{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"}],Cs=[{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)"}],xs=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=ws.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Cs.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(vo,{modal:true,open:e,onOpenChange:t,children:[jsx(bo,{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(Vt,{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"}),ws.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"}),Cs.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 Fu(e){try{return new URL(e),!0}catch{return false}}function Iu(e){if(Fu(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Es=({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(Vt,{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=Iu(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 Ts=[{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")}],Ds=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ts.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:Ts.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 Ps=()=>{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 Rs=()=>{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=$e(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=$e(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=$e(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=$e(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 Ho({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 td=()=>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"})]}),Fs=td;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 gd=[{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 zr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:gd.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 Ls({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,f)=>{let d=await fetch(c,f);if(d.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return d},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(xd,{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(Ho,{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(Fs,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,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:o$1}}).then(()=>n(""));let c=t.state.selection.content(),f=t.storage.markdown.serializer.serialize(c.content);a(f,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:l?jsx(Vr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(zr,{onSelect:(c,f)=>a(c,{body:{option:f}})})})]})]}):null}function Hr({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(Ls,{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(Ho,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var zd=[...a,vs];function Ms(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 jd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(Ms(o))return o}catch{return}}if(Ms(e))return e}function qr({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[l,c$1]=useState(false),[f$1,d]=useState(false),[u,m]=useState(false),[p,g$1]=useState(false),h$1=useDebouncedCallback((v,b)=>{let N=v.getJSON();n(r,{...b,value:JSON.stringify(N)});},300);function y(v,b){n(r,{...b,disabled:v});}let w=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,N)=>handleCommandNavigation(N)},handlePaste:(b,N)=>handleImagePaste(b,N,w),handleDrop:(b,N,A,C)=>handleImageDrop(b,N,C,w),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:zd,initialContent:jd(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:$r.map(b=>jsxs(EditorCommandItem,{value:b.title,onCommand:N=>b.command?.(N),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(Hr,{open:l,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx(Ds,{open:f$1,onOpenChange:d}),jsx(g$3,{orientation:"vertical"}),jsx(Es,{open:u,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(Ps,{}),jsx(g$3,{orientation:"vertical"}),jsx(Rs,{}),jsx(g$3,{orientation:"vertical"}),jsx(xs,{open:p,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 Kd=wn;function Xr({control:e$1,defaultValue:t,entityId:o,entityName:n,entityNamePlural:r,fieldSchema:i$1,schema:a,setValue:s}){let{name:l,label:c$1,options:f$1,relationship:d}=i$1,{projectId:u}=useParams(),m=de(),p=d$2(),{relationships:g$1}=c$2(),h$1=jo(),y=useId(),w=useId(),v$1=useRef(null),b=useRef([]),N=useRef(null),A=useRef([]),C=useRef(""),S=useRef(t.knownAssetSortOrders??{}),[$,M]=useState(false),T=useMemo(()=>tm(t.value),[t.value]),[P,j]=useState(T),[H,G]=useState(()=>Object.keys(t.knownAssetSortOrders??Oo(T)).length),[Z,D]=useState(()=>Math.max(t.count??0,T[0]?.totalCount??0,T.length)),k=useMemo(()=>za({attributeName:l,entityName:n,entityNamePlural:r,schema:a}),[n,r,l,a]),[V,{loading:W}]=useLazyQuery(gql`
432
+ ${k.query}
433
+ `);yo(v$1,M),useEffect(()=>{let F=Et(T);b.current=T.map(Q=>Q._id),A.current=[];let U={...t.knownAssetSortOrders??{},...Oo(T)};S.current=U,G(Object.keys(U).length),D(Math.max(t.count??0,T[0]?.totalCount??0,T.length)),j(Q=>{let se=Et(Q);return F===""&&se!==""&&C.current===se||se===F?Q:(C.current=F,T)});},[t.count,t.knownAssetSortOrders,T]),useEffect(()=>{let F=g$1[w]?.connect;if(!F)return;let U=F.map((le,_e)=>Bs(le.value,le.sortOrder??_e)).filter(le=>!!le),Q=Et(U),se=Et(P),ge=N.current;ge===se&&Q!==ge||(N.current=null,Q!==se&&j(U));},[w,g$1,P]),useEffect(()=>{let F=Et(P);if(C.current===F)return;let U=P.map((ge,le)=>({_id:ge._id,sortOrder:le,value:{...ge,sortOrder:le}})),Q=P.map(ge=>ge._id),se=A.current.filter(ge=>!Q.includes(ge));C.current=F,p({type:"setRelationship",payload:{[w]:{connect:U,disconnect:se}}}),s(l,{...t,knownAssetSortOrders:S.current,relationships:{connect:U,disconnect:se},value:P});},[p,t,l,w,P,s]);let ee=Math.max(Z,H),_=!!o&&ee>H,B=useCallback(()=>{if(!o||W||!_)return;let F=H+Kd;V({variables:{where:{_id:{eq:o}},first:F}}).then(U=>{let Q=U.data?.[r],ge=(Array.isArray(Q)?Q[0]:void 0)?.[`${l}Connection`],le=Sn(ge),_e=le[0]?.totalCount;if(typeof _e=="number"&&D(_e),le.length===0){D(H);return}let z=Object.keys(S.current).length,oe={...S.current,...Oo(le)},je=Object.keys(oe).length;S.current=oe,G(je),(le.length<F||je<=z)&&D(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(on=>on._id)),Yn=new Set(A.current),tn=le.filter(on=>!fe.has(on._id)&&!Yn.has(on._id));if(tn.length===0)return C.current="",[...He];let Ai=[...He,...tn];return N.current=Et(Ai),Ai});}).catch(U=>{console.error("Error fetching more assets:",U);});},[o,r,V,_,W,H,l]);function K(F){F.preventDefault(),F.stopPropagation(),m({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(P.length,ee),entityName:d?.entity??"_asset",entityId:o,relationshipId:w,mode:"multiple",assetAccept:f$1?.accept}});}async function te(F){F.preventDefault(),F.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 N.current=Et(le),le});}function ye(F){j(U=>{let Q=Jr(U.filter(se=>se._id!==F));return b.current.includes(F)&&!A.current.includes(F)&&(A.current=[...A.current,F]),N.current=Et(Q),Q});}function L(F,U){j(Q=>{let se=Q.findIndex(oe=>oe._id===F),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 N.current=Et(z),z});}let O=Math.max(P.length,ee),R=P.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:F=>{F.preventDefault(),F.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:[$&&P.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[O," ",O===1?"asset":"assets",_?` (${P.length} loaded)`:""," selected"]}):P.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[R.map(F=>jsx(Yd,{asset:F},F._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:F=>{F.preventDefault(),F.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(ko,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:M,open:$,children:jsx(ho,{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:F=>{te(F);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),P.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:P.map((F,U)=>jsx(em,{asset:F,index:U,isFirst:U===0,isLast:U===P.length-1,moveAsset:L,removeAsset:ye},F._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:F=>{F.preventDefault(),F.stopPropagation(),B();},type:"button",variant:"outline",children:W?"Loading\u2026":`Load more (${H} of ${ee})`})}):null]}):null]})})})]})})}),jsx(i,{})]})})}function Yd({asset:e}){return zs(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 em({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:zs(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 tm(e){return Array.isArray(e)?e.map((t,o)=>Bs(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Et(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function Jr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Bs(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,totalCount:typeof o.totalCount=="number"?o.totalCount:void 0}}function zs(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Hs({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 Vn({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 im=new Set(["text","textarea","number","datetime","switch","select","editor"]);function Xo({attributesSchema:e,checkboxSelect:t,actionsComponent:o,enableColumnSorting:n=false}){let{getContributionPointConfig:r}=d(),[,i]=b(),a=go(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:Hs},c=a.map(p=>{if(p.name==="_updatedAt")return null;let g=(p.inputType==="relationship"&&p.relationship?.entity==="_asset"?"asset":void 0)??p.previewType??s[p.inputType],h=r("previewFields",[g])?.[0]?.component??l[g]??l.text;if(p.isHidden)return null;let y=g==="tags",w=n&&p.scope==="global"&&im.has(p.inputType);return {accessorKey:p.name,filterFn:(v,b,N)=>y?true:(Array.isArray(N)?N:[N]).includes(v.getValue(b)),header:({column:v})=>w?jsx(Vn,{column:v,title:p.label}):jsx("div",{className:"fk:flex fk:items-center",children:p.label}),cell:({row:v})=>{let b=h;return g==="select"?jsx(b,{value:v.getValue(p.name),options:p.options}):jsx(b,{value:v.getValue(p.name)})},enableSorting:w,enableHiding:true,meta:{label:p.label},size:p.options?.size??150}}).filter(p=>p!==null),f={id:"actions",cell:({row:p})=>o?o(p):null,size:80},d$1={accessorKey:"_updatedAt",header:({column:p})=>n?jsx(Vn,{column:p,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:p})=>jsx(a$e,{value:p.getValue("_updatedAt")}),enableSorting:n,enableHiding:false,meta:{label:"Updated At"},size:220},u={id:"select",cell:({row:p,table:g})=>jsx(j$1,{"aria-label":"Select row",checked:p.getIsSelected(),onCheckedChange:h=>{g.toggleAllPageRowsSelected(false),p.toggleSelected(!!h);}}),enableSorting:false,enableHiding:false,size:50},m={id:"select",header:({table:p})=>jsx(j$1,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:p.getIsAllPageRowsSelected()||p.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:g=>{p.toggleAllPageRowsSelected(!!g);}}),cell:({row:p})=>jsx(j$1,{"aria-label":"Select row",checked:p.getIsSelected(),onCheckedChange:g=>{p.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[u]:[],...t==="multiple"?[m]:[],...o?[f]:[],...c,d$1]}var mm=36;function Us(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 pm(e,t){return e??Us(t)??mm}function gm(e){return Math.max(600,e)}function Go({classNames:e,columns:t,data:o,entityName:n$1,hasMore:r=false,initialSelectionState:i,isLoadingMore:a=false,onEntitySelectionChange:s,onLoadMore:l$1,onScroll:c,onSortingChange:f,pageSize:d,rowHeightEstimate:u,rowAdditionState:m,rowDeletionState:p,scrollToTopKey:g,sorting:h,toolbarComponent:y}){let w=useRef(null),{schemaErrorMessage:v}=Gt(),[b,N]=useState(i??{}),[A,C]=useState({}),[S,$]=useState([]),[M,T]=useState([]),P=h??M;useEffect(()=>{w.current?.scrollTo({top:0});},[n$1,g]),useEffect(()=>{if(!i)return;let L=Object.keys(b).sort().join(","),O=Object.keys(i).sort().join(",");L!==O&&N(i);},[i,b]);function j$1(L){if(f){f(L);return}T(L);}let H=useReactTable({data:o,columns:t,state:{sorting:P,columnVisibility:A,rowSelection:b,columnFilters:S},initialState:{pagination:{pageSize:d??50}},enableRowSelection:true,onRowSelectionChange:te,onSortingChange:j$1,onColumnFiltersChange:$,onColumnVisibilityChange:C,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:L=>L._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:L=>km(L,p,m)}}),{rows:G}=H.getRowModel(),Z=pm(u,e?.row),D=Us(e?.row)!=null,k=useVirtualizer({count:G.length,estimateSize:()=>Z,getScrollElement:()=>w.current,overscan:5}),V=k.getVirtualItems(),W=k.getTotalSize(),ee=useRef(l$1),_=useRef(r),B=useRef(a);ee.current=l$1,_.current=r,B.current=a;let K=useCallback(L=>{if(!ee.current||!_.current||B.current)return;let O=L??w.current;if(!O)return;let{scrollHeight:R,scrollTop:F,clientHeight:U}=O;R-F-U>=gm(U)||(B.current=true,ee.current());},[]);useEffect(()=>{K();},[K,G.length,r,a]);function te(L){let O=Object.keys(typeof L=="function"?L(b):L);N(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(h$2,{className:a$4("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:ye,ref:w,children:[jsx(i$1,{className:"fk:sticky fk:top-0 fk:z-10 fk:grid",children:H.getHeaderGroups().map(L=>jsx(l,{className:"fk:flex fk:w-full",children:L.headers.map(O=>jsxs(m$1,{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(j,{className:"fk:grid fk:relative",style:{height:`${W.toString()}px`},children:V.length?V.map(L=>{let O=G[L.index];return jsx(l,{className:a$4(H.options.meta.getRowBackground(O),"fk:flex fk:absolute fk:w-full fk:overflow-hidden",!D&&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(R=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",R.column.id==="actions"&&"fk:pl-1!"),style:{width:R.column.getSize()},children:flexRender(R.column.columnDef.cell,R.getContext())},R.id))},L.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function km(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 Js({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var Pm=25;function Yr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:l,setValue:c$1}){let[f$1,d]=useState(false),u=useRef(null);yo(u,d);let[m,p]=useState([]),{name:g$1,label:h$1,options:y,relationship:w}=a,v=w?.entity??g$1,b=de(),N=d$2(),{relationships:A}=c$2(),C=useId(),S=useId(),$=find(propEq(v,"name"))(s),M=$?.attributes??[],P=find(propEq(r,"name"))(s)?.name??"",j,H=M.find(R=>R.relationship?.entity===P);H&&(j=H.name);let G=Fm(M),Z=useMemo(()=>o.value?Im({data:o.value,defaultScope:t,relationshipEntitySchema:$,scope:l}):[],[t,o,G,$,l]),D=Ba({attributeName:g$1,relatedEntityName:v,scope:l,schema:s}),V=m.length?m.slice(0,12).map(R=>R[G]):[],W=Math.max(m.length,o.count??0)>V.length,[ee,{loading:_,data:B}]=useLazyQuery(gql`
434
+ ${D.query}
435
+ `),K=Xo({attributesSchema:$?.attributes??[],actionsComponent:R=>Rm({appDispatch:N,relationshipId:S,relationships:A,row:R,setRows:p})});useEffect(()=>{p(Z),o.value!==""&&N({type:"setRelationship",payload:{[S]:{connect:[],disconnect:[]}}});},[N,B,Z,S,o,l]),useEffect(()=>{c$1(g$1,{...o,relationships:A[S]});},[o,A,S,c$1,g$1]),useEffect(()=>{let F=(A[S]?.connect??[]).map(({value:U})=>U);p(uniqBy(prop("_id"),[...F,...Z]));},[B,o.count,Z,A,S]);let te=o.count??0,ye=te>0&&m.length>0&&m.length<te,L=useCallback(()=>{_||ee({variables:{limit:Pm,offset:m.length,where:j?{[j]:{some:{_id:{eq:n}}}}:{}}}).then(({data:R})=>{if(!R)return;let F=An($?.plural??"",l,R,s);p(uniqBy(prop("_id"),[...Z,...F.results]));}).catch(R=>{console.error("Error fetching more data:",R);});},[j,n,ee,Z,_,$?.plural,m.length,s,l]);function O(R){R.preventDefault(),b({type:"EditRelationship",payload:{connectedEntitiesCount:Z.length,connectionName:j,entityName:v,entityId:n,relationshipId:S,mode:w?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:g$1,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:C,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:R=>{R.preventDefault(),R.stopPropagation(),u.current?.focus(),u.current?.click(),d(true);},onKeyDown:R=>{R.key==="Enter"&&d(true),R.key==="Escape"&&(R.preventDefault(),R.stopPropagation(),u.current?.blur(),d(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(R=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:R},R)),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:R=>{R.preventDefault(),R.stopPropagation(),u.current?.blur(),d(false);},onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),R.stopPropagation(),u.current?.blur(),d(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:C,onKeyDown:R=>{R.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(ko,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:d,open:f$1,children:jsx(ho,{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(Go,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:K,data:m,entityName:r,hasMore:ye,isLoadingMore:_&&m.length>0,onLoadMore:L,rowAdditionState:A[S]?.connect,rowDeletionState:A[S]?.disconnect})})})})]})})}),jsx(i,{})]})})}function Rm({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],l=typeof find(propEq(a,"_id"),s)=="object",c=o[t]?.disconnect?.includes(a),f=l?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);l&&r(d=>d.filter(u=>u._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(d=>d._id!==a),disconnect:c?o[t]?.disconnect?.filter(d=>d!==a)??[]:f}}});}return jsx(Js,{action:i,row:n})}function Fm(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function Im({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 l=i[s],c=Array.isArray(l)?l[0]:l;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 ei({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:l}){let[c$1,f$1]=useState(false),{name:d,label:u,options:m,relationship:p}=r,g$1=p?.entity??d,h$1=de(),y=d$2(),w=useId(),{relationships:v}=c$2(),b=useId(),N=find(propEq(g$1,"name"))(a),C=Vm(N?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[b]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,b,o,s]),useEffect(()=>{l(d,{...i$1(d),...v[b]?.connect??""});},[o,d,v,b,l]);function S(M){M.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:g$1,entityId:n,relationshipId:b,mode:p?.mode??"single"}});}function $(M){let T={type:"setRelationship",payload:{[b]:{connect:[],disconnect:[]}}};M.preventDefault(),y(T),l(d,{...i$1(d),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:d,render:({field:M})=>{let T=M.value?.value,P="";if(T&&typeof T=="object"&&!Array.isArray(T)&&T[C]){let j=T[C],H=Array.isArray(j)?j[0]:j;typeof H=="string"?P=H:P=H?.[s]??H?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:w,children:u}),m?.comment?jsx(h,{children:m.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${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:w,onBlur:()=>{f$1(false);},onClick:S,onFocus:()=>{f$1(true);},onKeyDown:j=>{j.key==="Enter"&&S(j);},readOnly:true,type:"text",value:P}),P?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: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 Vm(e){return e.find(t=>t.isPrimary)??e[0]}function ti(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(ei,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(Xr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(Yr,{...n})}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 Ys="flexkit-select-option:";function oi(e){return `${Ys}${encodeURIComponent(e)}`}function jm(e){return decodeURIComponent(e.slice(Ys.length))}function el({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(c,f){let u=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;o(n,{...f,value:u});}function l(c,f){o(n,{...f,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:oi(String(c.value.value)),disabled:i$1===false||c.value?.disabled,onValueChange:f=>{s(jm(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(d=>jsx(g$1,{value:oi(d.value),children:d.label},d.label))]},f.groupLabel):jsx(g$1,{value:oi(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 ii({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 tp(e,t){let o=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:o}}function op({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:l},c){let f=find(propEq(n,"name"))(a),[,d$1]=b(),u=d$1.user?.spaces,m=useMemo(()=>go(f?.attributes??[],u),[f,u]),p=useMemo(()=>i||m.reduce((T,P)=>({...T,[P.name]:tp(P,t)}),{}),[t,i,m]),g=useMemo(()=>{let T={};for(let P of m)typeof P.validation>"u"||(T[P.name]=z.object({value:P.validation(z).or(z.any().refine(()=>false,{error:P.label?`${P.label} is required`:"Required field"}))}));return z.object(T)},[m]),h=useForm({defaultValues:p,resolver:zodResolver(g),values:i,mode:"onBlur",criteriaMode:"all"}),{control:y,getValues:w,handleSubmit:v,setValue:b$2,watch:N,trigger:A}=h,{getContributionPointConfig:C}=d(),S=useRef(i),$=useRef(false);useEffect(()=>{$.current||(S.current=i);},[i]);let M={datetime:ys,editor:qr,asset:ps,number:gs,relationship:ti,select:el,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){A().then(()=>{v(()=>{let T=w();$.current=true,S.current=T,s(false),l(T,i);})();});},hasErrors(){$.current=false,S.current=i,s(true);},hasDataChanged(){return nl(w(),S.current)},markAsSaved(){$.current=true,S.current=w(),s(false);},applyLocalAttributeIds(T){let P=w(),j={...P};for(let[H,G]of Object.entries(T)){let Z=P[H];!Z||Z._id||!G||(j[H]={...Z,_id:G});}$.current=true,S.current=j;for(let[H,G]of Object.entries(j))G!==P[H]&&b$2(H,G,{shouldDirty:false,shouldTouch:false,shouldValidate:false});s(false);}})),useEffect(()=>{let T=N(()=>{s(nl(w(),S.current));});return ()=>{T.unsubscribe();}},[i,w,s,N]),!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:n})]})]}):jsx(b$1,{...h,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:m.map(T=>{if(T.name==="_id")return null;let P=C("formFields",[T.inputType])?.[0]?.component??M[T.inputType];return P?createElement(P,{key:T.name,control:y,defaultScope:t,defaultValue:p[T.name],entityId:o,entityName:n,entityNamePlural:r,fieldSchema:T,getValues:w,schema:a,scope:e,setValue:b$2}):jsx(ii,{inputType:T.inputType,label:T.label},T.name)})})})}var Jn=memo(forwardRef(op));function nl(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 il(e){return e?e!=="viewer":true}function At(){let[,e]=b();return il(e.user?.role)}function li({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),i=At(),{projects:a,currentProjectId:s}=d(),{schema:l,scopes:c}=find(propEq(s??"","projectId"))(a),f=c?.find(M=>M.isDefault)?.name??"default",u=find(propEq(n,"name"))(l)?.plural??n,{scope:m}=c$2(),p=de(),g=useApolloClient(),[h,y,w,v]=bt(),{isDirty:b,setIsDirty:N}=po();useEffect(()=>{v.error&&r.current?.hasErrors();},[v.error]);function A(){return b?(p({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{p({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let C=useCallback(M=>{p({type:"Dismiss",_id:M,payload:{}});},[p]),S=useCallback(()=>{r.current?.submit();},[r]),$=useCallback(M=>{let T=v4(),P=Cr(u,l,M,T);y(gql`
433
436
  ${P}
434
- `),l({variables:{where:{_id:{eq:k}}},update(b){b.evict({id:k});},onCompleted:()=>{D();}}),d$3(true);});}function C(){let k=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${p.length} ${k}${p.length>1?"s":""}`,dialogMessage:p.length>1?`Are you sure you want to delete the selected ${k}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${k}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{g(true);try{for(let x of p)await E(x);n.resetRowSelection(),toast.success(p.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{g(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:[c&&c.length>0?jsxs(a$5,{defaultValue:s.scope,onValueChange:k=>{v(k);},value:s.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(s.scope??"","name"))(c)||null)?.label})]}),jsx(e$1,{children:c.map(k=>jsx(g$1,{value:k.name,children:k.label},k.name))})]}):null,jsx(Qr,{table:n}),o?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:u||t,onClick:o,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(Jr,{table:n})]}),p.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:u,onClick:C,size:"sm",variant:"destructive",children:[u?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",p.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:u,onClick:w,size:"sm",variant:"default",children:"Create"})]})}export{$o as DataTable,gn as DataTableColumnHeader,yp as DataTableFacetedFilter,bp as DataTableRowActions,Jr as DataTableSortedBy,Pp as DataTableToolbar,Qr as DataTableViewOptions,ap as FlexkitStudio,lp as ProjectDisabled,fp as SchemaError,up as defineConfig,gp as defineEntity,Gn as getEntityCreateMutation,Eo as getEntityDeleteMutation,Lt as getEntityQuery,_t as getEntitySchema,Xn as getEntityUpdateMutation,oe as useDispatch,st as useEntityMutation,Lo as useEntityQuery,Mt as useGraphQLError,Mo as useGridColumnsDefinition,Do as useUploadAssets};//# sourceMappingURL=index.js.map
437
+ `),w({onCompleted:()=>{xt(g,Ge(u,l)),C(e._id),toast.success("Your changes have been saved.");}}),h(true);},[e._id,g,u,C,h,l,y,w]);return jsx(Zt,{actions:jsx(q$1,{disabled:!i,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{S();},variant:"default",children:[v.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:A,depth:t,isFocused:o,onClose:()=>{C(e._id);},title:`Add ${n}`,children:jsx(Jn,{currentScope:m,defaultScope:f,entityName:n,entityNamePlural:u,onSubmit:$,ref:r,schema:l,setIsDirty:N})})}function Zo({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r,selection:i="full"}){let[a,s]=useState({count:0,results:[]}),[l,c]=useState(false),[f,d]=useState(false),u=useRef(false),m=useRef(false),p=useRef(0),g=useRef(null),h=useRef(null),y=En(e,o,t,{selection:i}),w=useMemo(()=>gql`
438
+ ${y.query}
439
+ `,[y.query]),v=En(e,o,t,{selection:i,includeCount:false}),b=useMemo(()=>gql`
440
+ ${v.query}
441
+ `,[v.query]),{schemaErrorMessage:N,setSchemaErrorMessage:A}=Gt(),{loading:C,data:S,fetchMore:$,refetch:M,error:T,networkStatus:P}=useQuery(w,{variables:n,notifyOnNetworkStatusChange:true}),j=useRef($),H=useRef(M),G=useRef(b),Z=useRef(P);j.current=$,H.current=M,G.current=b;let D=Qt(T),k=hn(T),{isProjectDisabled:V,isProjectReadOnly:W}=(()=>{if(D?.statusCode===403){let B=Xt(D.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||m.current)return;u.current=true,c(true);let K=B.variables.limit,te=p.current;j.current({...B,query:G.current,variables:{...B.variables,offset:te,limit:K}}).then(({data:ye})=>{let L=Wo({data:ye,entityNamePlural:e,isForm:r,schema:t,scope:o}),O=L.results.length;p.current=te+(O===0?0:Math.min(O,K)),s(R=>{let F=uniqBy(prop("_id"),[...R.results,...L.results]);return F.length===R.results.length?{count:R.results.length,results:R.results}:{count:L.count||R.count,results:F}});}).catch(ye=>{console.error("Error fetching more data:",ye);}).finally(()=>{u.current=false,c(false);});},[e,r,t,o]),_=useCallback(B=>{if(m.current)return Promise.resolve();let K=B?.preserve===true;return m.current=true,u.current=false,c(false),K||(g.current=null,h.current=null,p.current=0,d(true),s({count:0,results:[]})),H.current().then(({data:te})=>{let ye=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n}),L=Wo({data:te,entityNamePlural:e,isForm:r,schema:t,scope:o});g.current=ye,h.current=null,p.current=Gn(n)+L.results.length,s(L);}).catch(te=>{console.error("Error reloading data:",te);}).finally(()=>{m.current=false,d(false);})},[e,r,t,o,i,n]);return useEffect(()=>{if(k){A(k);return}S&&N&&!T&&A(null);},[S,T,N,k,A]),useEffect(()=>{if(T||k)return;let B=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n});if(g.current===B)return;if(C&&h.current!==B){h.current=B,p.current=0,s({count:0,results:[]});return}if(C)return;let K=Wo({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});g.current=B,h.current=null,p.current=Gn(n)+K.results.length,s(K);},[S,e,T,r,C,t,k,o,i,n]),useEffect(()=>{let B=Z.current;if(Z.current=P,T||k||m.current||B!==NetworkStatus.refetch||P!==NetworkStatus.ready||!S)return;let K=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n}),te=Wo({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});g.current=K,h.current=null,p.current=Gn(n)+te.results.length,s(te);},[S,e,T,r,P,t,k,o,i,n]),useEffect(()=>{if(r)return;let B=`Get${ot(e)}`,K=qa(L=>{if(!(!L.has(B)||u.current||m.current))return H.current().then(({data:O})=>{let R=JSON.stringify({entityNamePlural:e,scope:o,selection:i,variables:n}),F=Wo({data:O,entityNamePlural:e,isForm:r,schema:t,scope:o});g.current=R,h.current=null,p.current=Gn(n)+F.results.length,s(F);}).catch(O=>{console.error("Error soft-refreshing entity list:",O);})}),te=Ua((L,O)=>{L===B&&s(R=>{let F=R.results.filter(Q=>{let se=typeof Q._id=="string"?Q._id:void 0;return !se||!O.has(se)}),U=R.results.length-F.length;return U===0?R:{count:Math.max(0,R.count-U),results:F}});}),ye=Ja((L,O)=>{L===B&&s(R=>pp(R,O,n?.sort));});return ()=>{K(),te(),ye();}},[e,r,t,o,i,n]),{isLoading:C&&P!==NetworkStatus.refetch||f,isLoadingMore:l,fetchMore:ee,reload:_,count:a.count,data:a.results,isProjectDisabled:V,isProjectReadOnly:W,schemaErrorMessage:N}}function Gn(e){let t=e?.offset;return typeof t=="number"&&Number.isFinite(t)?t:0}function Wo(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?$a(e.entityNamePlural,e.scope,e.data,e.schema):An(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function pp(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 l=n.get(s);return l?(r=true,{...a,...l.attributes}):a});return r?{count:e.count,results:gp(i,o)}:e}function gp(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 l=a[n],c=s[n],f=typeof l=="string"?l:"",d=typeof c=="string"?c:"";return f.localeCompare(d)*i})}function dl(){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 di({handleSave:e,isLoading:t}){let{isDirty:o}=po(),n=At();return jsx(q$1,{disabled:!n,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!o||!n,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})})}function mi(){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 ki({action:e,depth:t,isFocused:o}){let{entityId:n,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",d$3=find(propEq(r,"plural"))(l),u=d$3?.name??r,{scope:m}=c$2(),[p,g]=useState(m),h=de(),y=d$2(),w=useApolloClient(),[v,b,N,A]=bt(),{isDirty:C,setIsDirty:S}=po(),$=useCallback(_=>{S(_);},[S]);useEffect(()=>{A.error&&i.current?.hasErrors();},[A.error]);let M=useCallback(()=>C?(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,C]),T=useCallback(_=>{h({type:"Dismiss",_id:_,payload:{}});},[h]),P=useCallback(()=>{i.current?.submit();},[i]);function j(_){if(C){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(p),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}=Zo({entityNamePlural:r,schema:l,scope:p,variables:{where:{_id:{eq:n}}},isForm:true}),Z=useCallback((_,B)=>{if(!B)return;let K=br(r,n,p,l,B,_);b(gql`
442
+ ${K}
443
+ `),N({variables:{where:{_id:{eq:n}}},onCompleted:te=>{i.current?.applyLocalAttributeIds(ja(te,r,l)),xt(w,Ge(r,l)),toast.success("Your changes have been saved.");}}),v(true);},[w,p,n,r,v,l,b,N]),D=G,k=D.length>0,V=H&&!k;function W(_,B){let K=_?.attributes.find(R=>R.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 R=O;return R[p]??R.default??""}return O??""}let ee=k&&d$3?W(d$3,D):"";return jsx(Zt,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:_=>{j(_);},value:p,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(p,"name"))(c).label})]}),jsx(e$1,{children:c.map(_=>jsx(g$1,{value:_.name,children:_.label},_.name))})]}):null,jsx(di,{handleSave:P,isLoading:A.loading})]}),beforeClose:M,depth:t,isFocused:o,onClose:()=>{T(e._id);},onFormChange:()=>{},title:ee,children:V||!k?jsx(mi,{}):jsxs(Fragment,{children:[A.isProjectReadOnly?jsx(dl,{}):null,jsx(Jn,{currentScope:p,defaultScope:f,entityId:n,entityName:u,entityNamePlural:r,formData:D[0],onSubmit:Z,ref:i,schema:l,setIsDirty:$})]})})}var vl=25;function Pp(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function vi({action:e,depth:t,isFocused:o}){let n=de(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:l,connectionName:c,entityId:f,entityName:d$1,initialAssetPath:u,initialConnection:m,mode:p,relationshipId:g}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:w}=find(propEq(y??"","projectId"))(h),v=find(propEq(d$1,"name"))(w),b=v?.plural??"",N=i[g],A=jo(),C=d$1==="_asset",S=C?"asset":v?.menu?.label??d$1.toLowerCase(),$=C&&p==="single"?"Select asset":`Select ${C?"assets":S}`,M=p==="single"?"Upload asset":"Upload assets",[T,P]=useState([]),j=[];if(m)j=[{id:m._id,value:m.value}];else if(N?.connect){let z=N.connect;j=[{id:z._id,value:z.value}];}let H=p==="single"?j:N?.connect?.map(z=>({id:z._id,value:z.value}))||[],[G,Z]=useState(H),D=useMemo(()=>{let z=[];return C&&z.push({NOT:{path:{eq:null}}}),p==="multiple"&&c&&f&&z.push({[c]:{none:{_id:{eq:f}}}}),T.length>0&&z.push({OR:T.map(oe=>({_id:{eq:oe._id}}))}),z.length===0?{}:z.length===1?z[0]:{AND:z}},[c,f,C,p,T]),{count:k,data:V,fetchMore:W,isLoading:ee,isLoadingMore:_}=Zo({entityNamePlural:b,schema:w,scope:a,variables:{offset:0,limit:vl,where:D,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=Xo({attributesSchema:v?.attributes??[],checkboxSelect:p}),R=Array(5).fill({}),F=Pp(O);useEffect(()=>{if(p!=="single"||G.length>0||!u||!V?.length)return;let z=V.find(oe=>oe.path===u);!z?._id||typeof z._id!="string"||Z([{id:z._id,value:z}]);},[V,u,p,G.length]);let U=useCallback(z=>{n({type:"Dismiss",_id:z,payload:{}});},[n]),Q=useCallback(()=>{W({variables:{offset:0,limit:vl,where:D}});},[D,W]);function se(){let z;if(p==="single"){let[oe]=G;z={_id:oe?.id??"",value:oe?.value??null};}p==="multiple"&&(z=G?.map((oe,je)=>({_id:oe.id??"",...C?{sortOrder:je}:{},value:oe.value}))),r({type:"setRelationship",payload:{[g]:{connect:z,disconnect:N?.disconnect??[]}}}),U(e._id);}function ge(z){if(p==="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 Yn=V?.find(tn=>tn._id===fe);return {id:fe,value:Yn}})});return}let oe=z[z.length-1];Z(oe?je=>{if(je.length===1&&je[0].id===oe)return je;let He=V?.find(fe=>fe._id===oe);return [{id:oe,value:He}]}:[]);}function le(){n({type:"AddEntity",payload:{entityName:d$1}});}async function _e(){let z=await A({projectId:y,accept:s??"image/*",multiple:p==="multiple",maxBytes:4194304});Z(oe=>{if(p==="single"){let[fe]=z;return fe?[{id:fe._id,value:fe.asset}]:oe}let je=new Set(oe.map(fe=>fe.id)),He=z.filter(fe=>!je.has(fe._id)).map(fe=>({id:fe._id,value:fe.asset}));return [...oe,...He]});}return jsx(Zt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{se();},variant:"default",children:"Select"}),C?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{le();},variant:"outline",children:`Create ${S}`}),C?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:o,onClose:()=>{U(e._id);},title:$,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Go,{columns:K?F:O,data:K?R:V??[],entityName:v?.name??"",hasMore:L,initialSelectionState:G?.reduce((z,oe)=>({...z,...oe.id?{[oe.id]:true}:{}}),{}),isLoadingMore:_,onEntitySelectionChange:ge,onLoadMore:Q,toolbarComponent:()=>jsx(Rp,{entityNamePlural:b,projectId:y??"",setSearchResultIds:P})})})})}function Rp({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,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),d=useMemo(()=>Fp(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(l){let m=JSON.stringify(l.map(g=>g._id).sort()),p=f.current?JSON.stringify(f.current.map(g=>g._id).sort()):"";m!==p&&(f.current=[...l],o(l.map(g=>({_id:g._id}))));}},[l,o]);function u(m){let{value:p}=m.target;r(p),d(p);}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:n})]})}function Fp(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function wl(){let e=Fa(),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(Lo,{options:r.options},n._id)}case "DeleteEntity":return jsx(Tr,{action:n},n._id);case "AddEntity":return jsx(li,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(ki,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(vi,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Cl({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$g(o);return window.location.pathname===r&&(window.location.href=b$a(r,n)),jsx(a$j,{children:jsx(c$6,{config:e,children:jsxs(ha,{children:[jsx(rs,{children:jsx(wl,{})}),jsx(Outlet,{})]})})})}function xl(){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})})]}):fr(e)?oa(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(dn,{})]})})]})}function wi(){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 Qp=RouterProvider;function Xp({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(f=>Sl(f)):[Sl(e)],[i]=r,a=a$g(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let l=[{path:a,element:jsx(Cl,{config:r}),errorElement:jsx(xl,{}),children:[{path:":projectId",element:jsx(ca,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(f=>({path:f.name,element:f.component,errorElement:jsx(wi,{}),children:f.routes?.map(d=>({path:d.path,element:d.component,errorElement:jsx(wi,{}),children:d.children?.map(u=>({path:u.path,element:u.component}))}))}))}]}],c=createBrowserRouter(l);return n("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Ra,{children:jsx(Qp,{router:c})})})})}function Sl(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 Wp(){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 Kp(){let{schemaErrorMessage:e}=Gt();if(!e)return jsx(Fragment,{});let[t,o,...n]=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}),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 eg(e){return e}function tg(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 og(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function Tl(e){return e.attributes.forEach(t=>{tg(t,e.name);}),{...e,attributes:e.attributes.map(og)}}function ng(e){return Tl(e)}function ag(e){let t=useApolloClient(),{currentProjectSchema:o}=d();return useCallback(async()=>{o&&await xt(t,Ge(e,o));},[t,e,o])}function lg(e){let{currentProjectSchema:t}=d();return useCallback(o=>{t&&Qa(Ge(e,t),o);},[e,t])}function ug({column:e,title:t$1,options:o$1}){let n=new Set(e?.getFilterValue());return jsxs(vo,{children:[jsx(bo,{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(Vt,{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("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)})}),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 mg({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=de(),i=At(),a=o.original._id,s=(n.canDelete??true)&&i,l=n.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 xi({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 Ei({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 Sg({entityName:e,isReloading:t=false,onReload:o,table:n}){let r=de(),i=d$2(),a=c$2(),s=useApolloClient(),{projects:l,currentProjectId:c}=d(),{schema:f,scopes:d$3}=find(propEq(c??"","projectId"))(l),[u,m,p]=bt(),[g,h]=useState(false),y=At(),w=n.getSelectedRowModel().rows.map(C=>C.original._id);function v(){r({type:"AddEntity",payload:{entityName:e}});}function b(C){i({type:"setScope",payload:{projectId:c,scope:C}});}async function N(C){if(C.length===0)return;let S=Vo(e,f,C);await new Promise(($,M)=>{m(gql`
445
+ ${S}
446
+ `),p({variables:{where:Bo(C)},update(T){for(let P of C)T.evict({id:P});},onCompleted:()=>{$();},onError:T=>{M(T);}}),u(true);});}function A(){let C=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${w.length} ${C}${w.length>1?"s":""}`,dialogMessage:w.length>1?`Are you sure you want to delete the selected ${C}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${C}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{h(true);try{let S=[...w];await N(S),n.resetRowSelection(),await Dn(s,Ge(e,f),S),toast.success(S.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:[d$3&&d$3.length>0?jsxs(a$5,{defaultValue:a.scope,onValueChange:C=>{b(C);},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"))(d$3)||null)?.label})]}),jsx(e$1,{children:d$3.map(C=>jsx(g$1,{value:C.name,children:C.label},C.name))})]}):null,jsx(Ei,{table:n}),o?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:g||t,onClick:o,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(xi,{table:n})]}),w.length>0?jsx(q$1,{disabled:!y,children:jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:g||!y,onClick:A,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 (",w.length,")"]})}):null,jsx(q$1,{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{Go as DataTable,Vn as DataTableColumnHeader,ug as DataTableFacetedFilter,mg as DataTableRowActions,xi as DataTableSortedBy,Sg as DataTableToolbar,Ei as DataTableViewOptions,Xp as FlexkitStudio,Wp as ProjectDisabled,Kp as SchemaError,Nr as canAccessSpaces,il as canMutateData,eg as defineConfig,ng as defineEntity,go as filterAttributesForSpaces,$f as filterEntitiesForSpaces,Cr as getEntityCreateMutation,Vo as getEntityDeleteMutation,Bo as getEntityDeleteWhere,En as getEntityQuery,Ct as getEntitySchema,br as getEntityUpdateMutation,At as useCanMutate,de as useDispatch,bt as useEntityMutation,Zo as useEntityQuery,Gt as useGraphQLError,Xo as useGridColumnsDefinition,lg as usePatchEntityList,ag as useRefreshEntityList,jo as useUploadAssets};//# sourceMappingURL=index.js.map
435
447
  //# sourceMappingURL=index.js.map