@flexkit/studio 0.0.25 → 0.0.27

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-REAMGMQL.js +2 -0
  2. package/dist/{asset-HOJ43RVO.js.map → asset-REAMGMQL.js.map} +1 -1
  3. package/dist/astro.js +1 -1
  4. package/dist/{chunk-OXTER7HO.js → chunk-27Y2SQ67.js} +2 -2
  5. package/dist/{chunk-OXTER7HO.js.map → chunk-27Y2SQ67.js.map} +1 -1
  6. package/dist/{chunk-SW6NNU5D.js → chunk-2FFSI7IK.js} +2 -2
  7. package/dist/chunk-2FFSI7IK.js.map +1 -0
  8. package/dist/chunk-2PEDKE5Z.js +2 -0
  9. package/dist/chunk-2PEDKE5Z.js.map +1 -0
  10. package/dist/chunk-553TQFSU.js +2 -0
  11. package/dist/chunk-553TQFSU.js.map +1 -0
  12. package/dist/{chunk-FPK7J4BP.js → chunk-7GBAYC7G.js} +2 -2
  13. package/dist/chunk-7GBAYC7G.js.map +1 -0
  14. package/dist/{chunk-53TUQIKJ.js → chunk-AALMEPYG.js} +2 -2
  15. package/dist/chunk-AALMEPYG.js.map +1 -0
  16. package/dist/{chunk-V2UTZEJQ.js → chunk-CWHDJ7Q4.js} +2 -2
  17. package/dist/{chunk-V2UTZEJQ.js.map → chunk-CWHDJ7Q4.js.map} +1 -1
  18. package/dist/{chunk-6MOUYNN4.js → chunk-KGYH74NA.js} +2 -2
  19. package/dist/chunk-KGYH74NA.js.map +1 -0
  20. package/dist/chunk-KR7CLPY2.js +2 -0
  21. package/dist/chunk-KR7CLPY2.js.map +1 -0
  22. package/dist/{chunk-ND3OZVR5.js → chunk-NNRD7YZU.js} +2 -2
  23. package/dist/chunk-NNRD7YZU.js.map +1 -0
  24. package/dist/{chunk-PEYW7XOU.js → chunk-OEWYLKO7.js} +2 -2
  25. package/dist/chunk-OEWYLKO7.js.map +1 -0
  26. package/dist/{chunk-Z5CZVKD4.js → chunk-QXCD5JR4.js} +2 -2
  27. package/dist/chunk-QXCD5JR4.js.map +1 -0
  28. package/dist/{chunk-YXRNHQPG.js → chunk-TBCSVE5L.js} +2 -2
  29. package/dist/{chunk-YXRNHQPG.js.map → chunk-TBCSVE5L.js.map} +1 -1
  30. package/dist/{chunk-PCZI6VXG.js → chunk-UKLE7J3K.js} +2 -2
  31. package/dist/chunk-UUGIVWK4.js +2 -0
  32. package/dist/chunk-UUGIVWK4.js.map +1 -0
  33. package/dist/chunk-WDRCARCP.js +3 -0
  34. package/dist/{chunk-ZBV4BY36.js.map → chunk-WDRCARCP.js.map} +1 -1
  35. package/dist/{chunk-V7UK6RMM.js → chunk-X3S7TRCM.js} +2 -2
  36. package/dist/{chunk-V7UK6RMM.js.map → chunk-X3S7TRCM.js.map} +1 -1
  37. package/dist/chunk-XU2JGXYC.js +2 -0
  38. package/dist/chunk-XU2JGXYC.js.map +1 -0
  39. package/dist/{chunk-5CKMFBWH.js → chunk-YW2EEXMV.js} +2 -2
  40. package/dist/chunk-YW2EEXMV.js.map +1 -0
  41. package/dist/{chunk-RVGMKQPC.js → chunk-ZSJAPCIZ.js} +2 -2
  42. package/dist/chunk-ZSJAPCIZ.js.map +1 -0
  43. package/dist/{chunk-7XBIC5RC.js → chunk-ZSSNAIMU.js} +2 -2
  44. package/dist/{chunk-7XBIC5RC.js.map → chunk-ZSSNAIMU.js.map} +1 -1
  45. package/dist/datetime-TWONUNXS.js +2 -0
  46. package/dist/{datetime-VZJ7XF33.js.map → datetime-TWONUNXS.js.map} +1 -1
  47. package/dist/index.css +45 -13
  48. package/dist/index.d.ts +38 -14
  49. package/dist/index.js +270 -231
  50. package/dist/index.js.map +1 -1
  51. package/dist/nextjs.js +1 -1
  52. package/dist/{project-selector-UDFHGEZI.js → project-selector-X6YVZYKL.js} +2 -2
  53. package/dist/{project-selector-UDFHGEZI.js.map → project-selector-X6YVZYKL.js.map} +1 -1
  54. package/dist/{search-MG2W4GGN.js → search-6ASIDGYA.js} +2 -2
  55. package/dist/{search-MG2W4GGN.js.map → search-6ASIDGYA.js.map} +1 -1
  56. package/dist/switch-KVO3JRNX.js +2 -0
  57. package/dist/{switch-FBS75HI4.js.map → switch-KVO3JRNX.js.map} +1 -1
  58. package/dist/tanstack-start.js +1 -1
  59. package/dist/text-ODG7ABSW.js +2 -0
  60. package/dist/{text-RZOXKHWE.js.map → text-ODG7ABSW.js.map} +1 -1
  61. package/dist/textarea-M4YPSJEC.js +2 -0
  62. package/dist/{textarea-OUJM7E6O.js.map → textarea-M4YPSJEC.js.map} +1 -1
  63. package/dist/{types.d-B-SE1ihC.d.ts → types.d-DiA0h3ut.d.ts} +37 -7
  64. package/dist/ui.d.ts +3 -2
  65. package/dist/ui.js +1 -1
  66. package/dist/ui.js.map +1 -1
  67. package/dist/{user-nav-E7MLJ36Y.js → user-nav-O5G4M2VA.js} +2 -2
  68. package/dist/{user-nav-E7MLJ36Y.js.map → user-nav-O5G4M2VA.js.map} +1 -1
  69. package/package.json +1 -1
  70. package/dist/asset-HOJ43RVO.js +0 -2
  71. package/dist/chunk-53TUQIKJ.js.map +0 -1
  72. package/dist/chunk-5CKMFBWH.js.map +0 -1
  73. package/dist/chunk-6MOUYNN4.js.map +0 -1
  74. package/dist/chunk-6YHHL4XI.js +0 -2
  75. package/dist/chunk-6YHHL4XI.js.map +0 -1
  76. package/dist/chunk-7WR64NTK.js +0 -2
  77. package/dist/chunk-7WR64NTK.js.map +0 -1
  78. package/dist/chunk-FPK7J4BP.js.map +0 -1
  79. package/dist/chunk-I4C65MUI.js +0 -2
  80. package/dist/chunk-I4C65MUI.js.map +0 -1
  81. package/dist/chunk-JHDZP6RC.js +0 -2
  82. package/dist/chunk-JHDZP6RC.js.map +0 -1
  83. package/dist/chunk-ND3OZVR5.js.map +0 -1
  84. package/dist/chunk-PEYW7XOU.js.map +0 -1
  85. package/dist/chunk-RVGMKQPC.js.map +0 -1
  86. package/dist/chunk-SW6NNU5D.js.map +0 -1
  87. package/dist/chunk-SXZZFHMJ.js +0 -2
  88. package/dist/chunk-SXZZFHMJ.js.map +0 -1
  89. package/dist/chunk-Z5CZVKD4.js.map +0 -1
  90. package/dist/chunk-ZBV4BY36.js +0 -3
  91. package/dist/datetime-VZJ7XF33.js +0 -2
  92. package/dist/switch-FBS75HI4.js +0 -2
  93. package/dist/text-RZOXKHWE.js +0 -2
  94. package/dist/textarea-OUJM7E6O.js +0 -2
package/dist/index.js CHANGED
@@ -1,37 +1,98 @@
1
- import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}from'./chunk-JHDZP6RC.js';import {a as a$a}from'./chunk-D4XLXU2H.js';import {a as a$b}from'./chunk-V2UTZEJQ.js';import {a as a$9}from'./chunk-4KGH7PU7.js';import {a,b as b$7}from'./chunk-7NQ6QCJD.js';import {a as a$c}from'./chunk-SXZZFHMJ.js';import {g as g$3,h as h$2,i as i$1,l,m as m$1,j,n,f as f$3,c as c$7,d as d$3}from'./chunk-RVGMKQPC.js';import {a as a$6}from'./chunk-FPK7J4BP.js';import'./chunk-PEYW7XOU.js';import {a as a$7,b as b$5,c as c$4,e as e$3}from'./chunk-5CKMFBWH.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$1,f as f$1,g as g$1}from'./chunk-7WR64NTK.js';import {d as d$2,c as c$2,b as b$9,a as a$h,e as e$5}from'./chunk-I4C65MUI.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-I4C65MUI.js';import {v,b as b$6,m as m$2,o,p,r,t,s,q}from'./chunk-ND3OZVR5.js';import {b as b$a,a as a$i}from'./chunk-7XBIC5RC.js';export{b as useAuth}from'./chunk-7XBIC5RC.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$1,m,a as a$g,l as l$1,i as i$2,b as b$c,r as r$1}from'./chunk-YXRNHQPG.js';import {d,a as a$e,b as b$8,e as e$4,c as c$6}from'./chunk-6YHHL4XI.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-6YHHL4XI.js';import {b as b$4,c as c$5,a as a$k}from'./chunk-ZBV4BY36.js';export{b as IMAGES_BASE_URL}from'./chunk-ZBV4BY36.js';import {b as b$3,a as a$8}from'./chunk-EYGOJ2ZN.js';import {a as a$f,b as b$b}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-V7UK6RMM.js';import {b as b$2,a as a$d}from'./chunk-Z5CZVKD4.js';export{b as DefaultValueSwitch}from'./chunk-Z5CZVKD4.js';import'./chunk-6MOUYNN4.js';import {b,c,e,f,h,g,i,a as a$j}from'./chunk-53TUQIKJ.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as rn from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,filter,uniq,omit,pick,toPairs,props}from'ramda';import Bs,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image as Image$1,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,Pencil,Settings2,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Qo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Collapsible,Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import {Drawer}from'vaul';import Qn from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import md from'react-markdown';import {useReactTable,getFacetedUniqueValues,getFacetedRowModel,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function qo(){let[e,t]=useState(false),{theme:o,setTheme:n}=b$c();return useEffect(()=>{t(true);},[]),e?jsxs(c$7,{size:"sm",type:"single",value:o,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{n("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{n("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{n("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function Jo(){let{resolvedTheme:e}=b$c();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var Os=cva("fk:relative fk:grid fk:w-full fk:grid-cols-[0_1fr] fk:items-start fk:gap-y-0.5 fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:text-sm fk:has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] fk:has-[>svg]:gap-x-3 fk:[&>svg]:size-4 fk:[&>svg]:translate-y-0.5 fk:[&>svg]:text-current",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:bg-card fk:text-destructive fk:*:data-[slot=alert-description]:text-destructive/90 fk:[&>svg]:text-current"}},defaultVariants:{variant:"default"}});function re({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(Os({variant:t}),e),...o})}function Te({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$4("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ie({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:col-start-2 fk:grid fk:justify-items-start fk:gap-1 fk:text-sm fk:text-muted-foreground fk:[&_p]:leading-relaxed",e),...t})}var Js=Qo.object({email:Qo.string().email({message:"Please enter a valid email address"})});function Nn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Js),defaultValues:{email:""}}),f=new URL(c$5(e$1).loginOtpSend,a$k),{data:u,error:c$1,isLoading:l}=Bs(r?f.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),d=u&&"error"in u&&u.error.code,m=u&&"token"in u,g$1=u&&"token"in u?u.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let v=new URL(c$5(e$1).loginOtpConfirm,a$k),x="/api/flexkit/set-token";fetch(`${v.href}?email=${s.getValues("email")}&token=${g$1}`).then(A=>{A.status===200&&A.json().then(S=>{fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:S.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,m,e$1,g$1]);function p(){n(false),i$1(true),a(f.href);}return jsx("div",{className:"fk:w-full",children:m?jsx(re,{variant:"success",children:jsxs(ie,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:s.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:dark:text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(p)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[d==="not_exists"&&jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),d==="unknown_error"||c$1?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$6,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":l,className:"fk:w-full",type:"submit",disabled:!!l,children:[l?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function di({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(p=>p.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:f}=Bs(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(h=>h.json())),[u,c]=b$a(),l=new Date().getFullYear(),d$2=useLocation(),m=d$2.state?.from?.pathname??d$2.pathname,g=m.includes(o.projectId)?`${location.origin}${m}`:`${location.origin}${b$b(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return f||u||!a?jsx(Jo,{}):c.user?.id?jsx(Navigate,{replace:true,state:{from:d$2},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$j,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:o.projectId,onValueChange:p=>{n(t.find(h=>h.projectId===p)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":o.title,children:o.title})}),jsx(e$1,{children:t.map(p=>jsx(g$1,{value:p.projectId,children:p.title},p.projectId))})]})]}):null,r?jsx(Nn,{projectId:e,setIsEmailLogin:i}):jsxs(Fragment,{children:[jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-sm fk:text-left fk:text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk:flex fk:flex-col fk:space-y-6",children:[a.providers.map(p=>jsx(b$3,{asChild:true,className:`fk:${p.button.color} fk:${p.button.backgroundColor} fk:hover:${p.button.colorHover} fk:hover:${p.button.backgroundColorHover}`,type:"button",variant:p.button.variant,children:jsxs("a",{href:Ws({url:p.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:g}),children:[p.button.iconUrl?jsx("img",{alt:p.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:p.button.iconUrl}):null,p.title]})},p.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",l]})]}),jsx(qo,{})]})})]})}function Ws({projectId:e,url:t,basePath:o,fromPath:n}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${o}`),r.set("projectId",e),r.set("redirect",n),`${t}?${r.toString()}`}var Zs=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Ys={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},Xo=class e extends Error{code;constructor(t,o){super(o??Ys[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,o){return new e(t,o)}};function Pn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Zs.includes(t)}function ui(e){if(Pn(e))return e.code}function ki({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),f=useRef(null),u=useLocation(),{projectId:c}=useParams(),l=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name,d=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(f.current===null)return;let m=new ResizeObserver(()=>{n(f.current?.offsetHeight??0);});return m.observe(f.current),function(){m.disconnect();}},[l]),useEffect(()=>{let m=Math.floor(o/48)-2,g=e.slice(0,m);if(!g.find(h=>h.name===d)){let h=e.find(y=>y.name===d);g.pop(),h&&g.push(h);}let p=e.filter(h=>!g.includes(h));i(g),s(p);},[e,d,o]),l===void 0&&d?jsx(Navigate,{to:`${u.pathname}/${d}`}):jsx(a$7,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:f,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(m=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:m.name,children:m.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:m.title})})]})},m.name))}),a.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:a.map(m=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:m.name,children:m.title})},m.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${c}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(m,{}),jsx(h$1,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var cl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-UDFHGEZI.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-MG2W4GGN.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-E7MLJ36Y.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-FBS75HI4.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-RZOXKHWE.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-OUJM7E6O.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-HOJ43RVO.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-FIBUDNGR.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-NFRMIYVJ.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-VZJ7XF33.js').then(({DateTime:e})=>({default:e})))};function uo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=cl[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function yi({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=uo("navbar.logo"),r=uo("navbar.projectSelector"),i=uo("navbar.search"),a=uo("navbar.userNav"),s=t.find(d=>d.projectId===e)??t[0],{basePath:f,schema:u}=s,c=useNavigate();function l(d){startTransition(()=>{c(b$b(f,e,"desk","list",d.entityNamePlural)+`?id=${d.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-[3.5rem] fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:l,projectId:e,schema:u})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function vi({version:e}){let{contributions:t,projects:o}=d(),[n,r]=b$a(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(o);if(!a)throw new Xo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:f}=t,u=d$2(),c=useLocation();return useEffect(()=>{if(s){let l=s.find(m=>m.isDefault)||s[0],d="";typeof localStorage<"u"&&(d=localStorage.getItem(`${a$h}${i}`)??""),u({type:"setScope",payload:{projectId:i,scope:d||l.name}});}},[c]),n?jsx(Jo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(yi,{projectId:i??"",projects:o}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(ki,{apps:f,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(di,{projectId:i??""})}function Ci(e){return e?"cause"in e:false}function At(e){if(!e)return null;if(ServerError.is(e))return e;if(Ci(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function xi(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function St(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Wo(e){if(!e)return null;let t=bl(e);return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(o=>`- ${o}`)].join(`
2
- `)}function bl(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(wi).map(({message:r})=>r);let t=xi(e);if(t&&mo(t))return [t];let o=At(e);if(o?.statusCode!==400)return [];let n=St(o.bodyText)??wl(o)??Cl(e);return n?Array.isArray(n.errors)?n.errors.filter(wi).map(r=>r.message):typeof n.message=="string"&&mo(n.message)?[n.message]:typeof n.error=="string"&&mo(n.error)?[n.error]:[]:[]}function wl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Cl(e){if(!Ci(e))return null;let{cause:t}=e,o=xi(t);if(o&&mo(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function wi(e){if(!e||typeof e!="object")return false;let{extensions:t,message:o}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof o=="string"?true:typeof o=="string"&&mo(o)}function mo(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Ll=ApolloProvider,Ai=createContext(void 0);function Tt(){let e=useContext(Ai);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function _l(e){return new ErrorLink(({error:t})=>{let o=Wo(t);if(o){e(o);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:a})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let n=At(t);if(n?.statusCode===400){let r=St(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:f}=r;if(typeof f=="string")i=f;else if(Array.isArray(s)){let[u]=s;if(u&&typeof u.message=="string"){let{message:c}=u;i=c;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=n.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(n){console.warn(`[Network error]: ${n.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function Ol(e,t){return from([_l(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Vl(e,t){return new ApolloClient({link:Ol(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Si({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(Ai.Provider,{value:r,children:jsx(Ll,{client:Vl(t,n),children:e})})}function Ti({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function In({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Bl({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Di({className:e,size:t="default",...o}){return jsxs(In,{children:[jsx(Bl,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...o})]})}function Ni({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$4("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Pi({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$4("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Ri({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$4("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Fi({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Ii({className:e,variant:t="default",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...n})})}function Mi({className:e,variant:t="outline",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...n})})}function po({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function f(){r(true);try{let u=e.dialogActionSubmit?.();u&&typeof u.then=="function"&&await u;}finally{a(true),o(false),r(false);}}return jsx(Ti,{onOpenChange:s,open:t,children:jsx(In,{children:jsxs(Di,{className:"sm:max-w-[425px]",children:[jsxs(Ni,{children:[jsx(Ri,{children:e.dialogTitle}),jsx(Fi,{children:e.dialogMessage})]}),jsxs(Pi,{children:[jsx(Mi,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Ii,{className:a$8({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:f,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Oi=createContext([]),Vi=createContext(()=>{});function ql(e,t){let o=t.type;switch(t._id||(t._id=Date.now().toString()),o){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(n=>n._id!==t._id);default:throw Error(`Unknown action: ${o}`)}}function Bi({children:e}){let[t,o]=useReducer(ql,[]);return jsx(Oi.Provider,{value:t,children:jsx(Vi.Provider,{value:o,children:e})})}function zi(){return useContext(Oi)}function ae(){return useContext(Vi)}var Gl=["id","string"],Wl=["date","datetime","duration","time"],Zl=`_id
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`
3
+ mutation updateEntity($any: Any) {
4
+ any
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
3
7
  originalFilename
4
8
  mimeType
5
9
  path
6
10
  size
7
11
  height
8
12
  width
9
- lqip`;function ho(e){return e?.scope==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset"}function Hi(e,t){return !e||!ho(e)?false:t?.name!==b$8.name||e.name!=="assets"}function $n(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ui(e){return (e?.edges??[]).reduce((o,n,r)=>(n.node&&o.push({...n.node,sortOrder:n.properties?.sortOrder??r}),o),[]).sort((o,n)=>(o.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER))}function qi(e,t=true){let o=t?` properties {
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 {
10
14
  sortOrder
11
15
  }
12
- `:"";return ` ${e}Aggregate {
13
- count
14
- }
15
- ${e}Connection {
16
+ `:"";return ` ${e}Connection {
17
+ aggregate {
18
+ count {
19
+ nodes
20
+ }
21
+ }
16
22
  edges {
17
23
  `+o+` node {
18
- ${Zl}
24
+ ${oa}
19
25
  }
20
26
  }
21
27
  }
22
- `}function Nt(e,t,o){let n="(where: $where, options: $options)",r=Pt(o,e),i=r?.name??e,a=r?.attributes??[],s=`$where: ${i}Where, $options: ${i}Options`,f=`Get${Ht(e)}`;if(!r)throw new Error(`Entity '${i}' not found in the schema`);if(a.length===0)throw new Error(`Entity '${i}' has no attributes defined in the schema`);let u=oe("global",a).join(`
23
- `),c=en(a),l=oe(["local"],a),d=l.reduce((v,x)=>`${v}
28
+ `}function Hn(e){return e?.aggregate?.count?.nodes??0}function on(e,t=""){return ` ${e}Connection${t} {
29
+ aggregate {
30
+ count {
31
+ nodes
32
+ }
33
+ }
34
+ }
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}
38
+ }
39
+ `;if(ne(e)==="local")return ` ${e.name} {
40
+ _id
41
+ default
42
+ ${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"?`{
45
+ _id
46
+ default
47
+ ${n}}
48
+ `:"";return e.relationship?.mode==="single"?` ${e.name} {
49
+ ${r} ${a}}
50
+ `:` ${e.name} (limit: 3, offset: 0) {
51
+ ${r} ${a}}
52
+ `}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}
55
+ ${r.name} {
56
+ _id
57
+ originalFilename
58
+ mimeType
59
+ path
60
+ size
61
+ height
62
+ width
63
+ lqip
64
+ }
65
+ `;if(ne(r)==="local")return `${n}
66
+ ${r.name} {
67
+ _id
68
+ default
69
+ ${i}
70
+ }
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"?`{
72
+ _id
73
+ default
74
+ ${i}}
75
+ `:"";if(r.relationship?.mode==="single")return `${n}
76
+ ${r.name} {
77
+ ${r.relationship.field} ${f}}
78
+ `;if(r.relationship?.field)return `${n}
79
+ ${r.name} (limit: 25, offset: 0) {
80
+ ${r.relationship.field} ${f}}
81
+ `}return `${n}
82
+ ${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}
24
85
  ${x} {
25
86
  _id
26
87
  default
27
88
  }
28
- `,""),m=l.reduce((v,x)=>`${v}
89
+ `,""),p=u.reduce((k,x)=>`${k}
29
90
  ${x} {
30
91
  _id
31
92
  default
32
93
  ${t}
33
94
  }
34
- `,""),g=t==="default"?d:m,p=c.reduce((v,x)=>`${v}
95
+ `,""),w=t==="default"?g:p,v=l.reduce((k,x)=>`${k}
35
96
  ${x} {
36
97
  _id
37
98
  originalFilename
@@ -42,194 +103,173 @@ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}
42
103
  width
43
104
  lqip
44
105
  }
45
- `,""),y=filter(propEq("relationship","scope"))(a).reduce((v,x)=>{if(ho(x))return `${v}
46
- ${qi(x.name,Hi(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.attributes.reduce((b,E)=>{let D=t==="default"?"":`${t}
47
- `;if($n(E))return `${b}
48
- ${E.name} {
49
- _id
50
- originalFilename
51
- mimeType
52
- path
53
- size
54
- height
55
- width
56
- lqip
57
- }
58
- `;if(E.scope==="local")return `${b}
59
- ${E.name} {
60
- _id
61
- default
62
- ${D}
63
- }
64
- `;if(E.scope==="relationship"){let B=find(propEq(E.relationship?.entity,"name"))(o),F=find(propEq(E.relationship?.field,"name"))(B?.attributes??[]).scope==="local"?`{
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) {
65
109
  _id
66
- default
67
- ${D}}
68
- `:"";if(E.relationship?.mode==="single")return `${b}
69
- ${E.name} {
70
- ${E.relationship.field} ${F}}
71
- `;if(E.relationship?.field)return `${b}
72
- ${E.name} (options: {limit: 25, offset: 0}) {
73
- ${E.relationship.field} ${F}}
74
- `}return `${b}
75
- ${E.name}
76
- `},"");return `${x.name}Aggregate {
77
- count
78
- }${v}
79
- ${x.name} (options: {limit: 25, offset: 0}) { _id ${S??""}}
80
- `},"");return {queryEntityName:e,query:`query ${f}(${s}) {
81
- ${e}Aggregate {
82
- count
83
- }
84
- ${e}${n} {
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} {
85
115
  _id
86
- ${u} ${g} ${p} ${y}}
116
+ _updatedAt
117
+ ${m} ${w} ${v} ${C}}
87
118
  }
88
- `}}function Ko(e,t,o,n){let i=Pt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],s=o[e],f=(c,l)=>{let d=l.name;return c.slice(0,3).map(m=>l.scope==="local"?m[d]?.[t]??m[d].default:m[d]).join(", ")},u=s.map(c=>{let{_id:l}=c,d=oe("global",i).reduce((h,y)=>({...h,[y]:c[y]}),{}),m=oe("local",i).reduce((h,y)=>{let v=c[y];return {...h,[y]:v?.[t]?v[t]:v?.default}},{}),g=en(i).reduce((h,y)=>({...h,[y]:c[y]}),{}),p=oe(["relationship"],i).reduce((h,y)=>{let v=find(propEq(y,"name"))(i),x=v.relationship?.entity??"",A=find(propEq(x,"name"))(n),S=cc(A?.attributes??[]),b=S?.name??"",E=S?.scope??"global",D=c[y];if(ho(v)){let z=Ui(c[`${y}Connection`]);return {...h,[y]:z}}if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);if(Array.isArray(D))return {...h,[y]:f(D,S)};let B=E==="global"?D?.[b]:D?.[b]?.[t]??D?.[b]?.default;return {...h,[y]:B}},{});return {_id:l,...d,...m,...g,...p}});return {count:a,results:u}}function Ji(e,t,o,n){let i=Pt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],f=o[e].map(u=>{let c=oe("global",i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),l=oe("local",i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p];return {...g,[p]:{value:y?Yl(y,t):null,disabled:!!(y&&y[t]===null&&h.scope==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),d=en(i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),m=oe(["relationship"],i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p],v=y?._id,x=u[`${p}Aggregate`].count,A=ho(h)?Ui(u[`${p}Connection`]):y;return {...g,[p]:{count:x,_id:v,value:A,disabled:false,scope:t}}},{});return {...c,...l,...d,...m}});return {count:a,results:f}}function Yl(e,t){return Array.isArray(e)?e.reduce((o,n)=>{if(n[t]??n.default){let r={_id:n._id,disabled:n.scope===null&&t!=="default",scope:t,value:n[t]??n.default};o.push(r);}return o},[]):e[t]??e.default??null}function Ln(e,t,o,n,r,i){let a=Pt(n,e),s=a?.name??e,f=a?.attributes??[],u=vo(e);if(f.length===0)return "";let c=_n(f,i),l=On(f,c),d=ec(t,f,c,o),m=Kl(t,f,c),g=tc(f,r,c),p=e,h=Bn(n,e,o);return `mutation ${`Update${Ht(e)}`}($where: ${s}Where) {
89
- update${u}(
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}(
90
121
  where: $where
91
- update: {${l}${d}${m}${g}
122
+ update: {${m}${l}${u}${g}
92
123
  }
93
124
  ) {
94
125
  ${p} {
95
126
  _id
96
- ${h} }
127
+ ${w} }
97
128
  }
98
129
  }
99
- `}function _n(e,t){let o=e.map(r=>r.isEditable===false?r.name:"").filter(Boolean),n=omit(o,t);return pick(e.map(r=>r.name),n)}function oe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(oe(r,t)),[]):t.filter(n=>n.scope===e&&n.inputType!=="asset").map(n=>n.name)}function en(e){return e.filter($n).map(o=>o.name)}function On(e,t){let o=pick(oe("global",e),t);return toPairs(o).reduce((r,[i,a])=>{let s=find(propEq(i,"name"))(e),f=Array.isArray(a?.value)?null:a?.value??null,u=Vn(s.dataType,f);return `${r}
100
- ${i}: ${u}`},"")}function Kl(e,t,o){let n=pick(en(t),o);return toPairs(n).reduce((a,[s,f])=>{let u=f.value,c=Yo(u?.path),l=u?.size?u.size:"null",d=Yo(u?.mimeType),m=Yo(u?.originalFilename),g=u?.height?u.height:"null",p=u?.width?u.width:"null",h=Yo(u?.lqip);return c?f.value?._id?`${a}
101
- ${s}: {
102
- update: {
103
- node: {
104
- mimeType: ${d}
105
- originalFilename: ${m}
106
- path: ${c}
107
- size: ${l}
108
- height: ${g}
109
- width: ${p}
110
- lqip: ${h}
111
- }
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?` {
133
+ disconnect: [{
134
+ where: {
135
+ node: {
136
+ _id: { eq: ${pe(d)} }
137
+ }
138
+ }
139
+ }]
140
+ }
141
+ `:"",l=c?` {
142
+ connect: [{
143
+ where: {
144
+ node: {
145
+ _id: { eq: ${pe(c)} }
146
+ }
147
+ }
148
+ }]
112
149
  }
113
- }`:`${a}
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}
114
153
  ${s}: {
115
- create: {
116
- node: {
117
- _id: ${ke(`${e}:${s}`)}
118
- mimeType: ${d}
119
- originalFilename: ${m}
120
- path: ${c}
121
- size: ${l}
122
- height: ${g}
123
- width: ${p}
124
- lqip: ${h}
154
+ connect: [{
155
+ where: {
156
+ node: {
157
+ _id: { eq: ${pe(f)} }
158
+ }
125
159
  }
126
- }
127
- }`:a},"")}function ec(e,t,o,n){let r=pick(oe("local",t),o);return toPairs(r).reduce((s,[f,u])=>{let c=find(propEq(f,"name"))(t),{dataType:l}=c,d=u.disabled||Array.isArray(u.value)?"null":Vn(l,u.value);return u._id?`${s}
128
- ${f}: {
160
+ }]
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}: [{
129
163
  update: {
130
164
  node: {
131
- ${n}: ${d}
165
+ ${n}: { set: ${l} }
132
166
  }
133
167
  }
134
- }`:d?`${s}
135
- ${f}: {
168
+ }]`:l?`${a}
169
+ ${f}: [{
136
170
  create: {
137
171
  node: {
138
- _id: ${ke(`${e}:${f}`)}
139
- _type: "${l}"
140
- ${n}: ${d}
172
+ _id: ${pe(`${e}:${f}`)}
173
+ _type: "${m}"
174
+ ${n}: ${l}
141
175
  }
142
176
  }
143
- }`:s},"")}function tc(e,t,o){let n=pick(oe("relationship",e),o);return toPairs(n).reduce((a,[s,f])=>{let u=find(propEq(s,"name"))(e),{inputType:c,relationship:l}=u;if(c==="relationship"&&l?.mode==="single"){let d=t[s]._id??"",m=f._id??"";if(d===m)return a;let g=d?`disconnect: {
144
- where: {
145
- node: {
146
- _id: ${ke(d)}
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?` {
178
+ disconnect: [{
179
+ where: {
180
+ node: {
181
+ _id: { eq: ${pe(l)} }
182
+ }
147
183
  }
148
- }
184
+ }]
149
185
  }
150
- `:"",p=m?`connect: {
151
- where: {
152
- node: {
153
- _id: ${ke(m)}
186
+ `:"",p=u?` {
187
+ connect: [{
188
+ where: {
189
+ node: {
190
+ _id: { eq: ${pe(u)} }
191
+ }
154
192
  }
155
- }
193
+ }]
156
194
  }
157
- `:"";return `${a}
158
- ${s}: {
159
- ${p} ${g} }`}if(c==="relationship"&&l?.mode==="multiple"){if(l.entity==="_asset")return `${a}${oc(s,t[s],f)}`;let d=f.relationships?.disconnect?.reduce((y,v)=>`${y} {
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} {
160
198
  node: {
161
- _id: ${ke(v)}
199
+ _id: { eq: ${pe(E)} }
162
200
  }
163
201
  }
164
- `,""),g=(f.relationships?.connect??[]).reduce((y,v)=>`${y} {
165
- _id: ${ke(v._id)}
166
- }
167
- `,""),p=d?`disconnect: {
202
+ `,""),g=(f.relationships?.connect??[]).map(v=>pe(v._id)).join(", "),p=l?`disconnect: {
168
203
  where: {
169
204
  OR: [
170
- ${d} ]
205
+ ${l} ]
171
206
  }
172
207
  }
173
- `:"",h=g?`connect: {
208
+ `:"",w=g?`connect: {
174
209
  where: {
175
210
  node: {
176
- OR: [
177
- ${g} ]
211
+ _id: { in: [${g}] }
178
212
  }
179
213
  }
180
214
  }
181
- `:"";return !p&&!h?a:`${a}
182
- ${s}: {
183
- ${p} ${h} }`}return `${a}
184
- `},"")}function oc(e,t,o){let r=(o.relationships?.connect??[]).map((l,d)=>({...l,sortOrder:l.sortOrder??d})),i=r.map(l=>l._id),a=nc(t),s=uniq(o.relationships?.disconnect??[]).filter(l=>l&&!i.includes(l)),f=r.filter(l=>{let d=a[l._id];return d===void 0||d!==l.sortOrder}),u=rc(s),c=ic(f);return !u&&!c?"":`
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?"":`
185
219
  ${e}: [
186
- ${u}${c} ]`}function nc(e){let t=e?.value;return Array.isArray(t)?t.reduce((o,n,r)=>{if(typeof n!="object"||!n||!("_id"in n))return o;let{_id:i}=n;if(typeof i!="string"||i.length===0)return o;let a="sortOrder"in n&&typeof n.sortOrder=="number"?n.sortOrder:r;return {...o,[i]:a}},{}):{}}function rc(e){return e.length===0?"":` {
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?"":` {
187
221
  disconnect: [
188
222
  ${e.reduce((o,n)=>`${o} {
189
- where: { node: { _id: ${ke(n)} } }
223
+ where: { node: { _id: { eq: ${pe(n)} } } }
190
224
  }
191
225
  `,"")} ]
192
226
  }
193
- `}function ic(e){return e.length===0?"":` {
227
+ `}function Nc(e){return e.length===0?"":` {
194
228
  connect: [
195
- ${Qi(e)} ]
229
+ ${la(e)} ]
196
230
  }
197
- `}function Qi(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
198
- where: { node: { _id: ${ke(o._id)} } }
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)} } } }
199
233
  edge: { sortOrder: ${r} }
200
234
  }
201
- `},"")}function Vn(e,t){return Wl.includes(e)?t?.toString()?ke(t.toString()):null:Gl.includes(e)?ke(t?.toString()??"null"):t?.toString()??null}function Yo(e){return e?ke(e):"null"}function ke(e){return JSON.stringify(e)}function Bn(e,t,o){let n=Pt(e,t),r=n?.attributes??[],i=oe("global",r),a=oe("local",r),s=oe("relationship",r),f=i.reduce((u,c)=>`${u}${c}
202
- `,"");return f+=a.reduce((u,c)=>`${u} ${c} {
235
+ `},"")}function Pc(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
236
+ update: {
237
+ where: { node: { _id: { eq: ${pe(n._id)} } } }
238
+ edge: { sortOrder: { set: ${i} } }
239
+ }
240
+ }
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} {
203
243
  _id
204
244
  ${o}
205
245
  }
206
- `,""),f+=s.reduce((u,c)=>{let l=find(propEq(c,"name"))(r),d=l?.relationship?.mode??"single";if(ho(l))return `${u}${qi(c,Hi(l,n))}`;let m=l?.relationship?.entity??"",p=find(propEq(m,"name"))(e)?.attributes??[],h=l?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(h,"name"))(p).scope,x="";if(d==="single"&&(v==="global"&&(x=` ${c} {
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} {
207
247
  _id
208
- ${h}
248
+ ${w}
209
249
  }
210
- `),v==="local"&&(x=` ${c} {
250
+ `),E==="local"&&(C=` ${d} {
211
251
  _id
212
- ${h} {
252
+ ${w} {
213
253
  _id
214
254
  default
215
255
  ${o}
216
256
  }
217
257
  }
218
- `)),d==="multiple"&&p.length){let A=p.reduce((S,b)=>{if(b.scope==="local")return `${S} ${b.name} {
258
+ `)),l==="multiple"&&p.length){let k=p.reduce((x,P)=>{if(ne(P)==="local")return `${x} ${P.name} {
219
259
  _id
220
260
  default
221
261
  ${o}
222
262
  }
223
- `;if(b.scope==="relationship"){let E=o==="default"?"":`${o}
224
- `,D=find(propEq(b.relationship?.entity,"name"))(e),z=find(propEq(b.relationship?.field,"name"))(D?.attributes??[]).scope==="local"?`{
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"?`{
225
265
  _id
226
266
  default
227
- ${E}}
228
- `:"";if(b.relationship?.mode==="single")return `${S} ${b.name} {
229
- ${b.relationship.field} ${z}}
230
- `;if(b.relationship?.field)return `${S} ${b.name} (options: {limit: 25, offset: 0}) {
231
- ${b.relationship.field} ${z}}
232
- `}return $n(b)?`${S} ${b.name} {
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} {
233
273
  _id
234
274
  originalFilename
235
275
  mimeType
@@ -239,13 +279,10 @@ ${Qi(e)} ]
239
279
  width
240
280
  lqip
241
281
  }
242
- `:`${S} ${b.name}
243
- `},"");x=` ${c}Aggregate {
244
- count
245
- }
246
- ${c} (options: {limit: 25, offset: 0}) {
247
- ${A} }
248
- `;}return `${u}${x}`},""),f}function yo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=vo(n?.plural??""),a=ac(r,o),s=`Delete${Ht(n?.plural??e)}`;return e==="_asset"?`mutation ${s}($where: ${e}Where) {
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) {
249
286
  delete_assets(
250
287
  where: $where
251
288
  ) {
@@ -253,144 +290,146 @@ ${A} }
253
290
  relationshipsDeleted
254
291
  }
255
292
  }
256
- `:`mutation ${s}($where: ${e}Where) {
293
+ `:`mutation ${a}($where: ${e}Where) {
257
294
  delete${i}(
258
295
  where: $where
259
- ${a?` delete: {
260
- ${a}
296
+ ${s?` delete: {
297
+ ${s}
261
298
  }
262
299
  `:""} ) {
263
300
  nodesDeleted
264
301
  relationshipsDeleted
265
302
  }
266
303
  }
267
- `}function ac(e,t){return oe("local",e).reduce((r,i)=>`${r}
268
- ${i}: {
304
+ `}function Rc(e,t){return ae("local",e).reduce((r,i)=>`${r}
305
+ ${i}: [{
269
306
  where: {
270
307
  node: {
271
- _id: ${ke(`${t}:${i}`)}
308
+ _id: { eq: ${pe(`${t}:${i}`)} }
272
309
  }
273
310
  }
274
- }`,"")}function zn(e,t,o,n){let r=Pt(t,e),i=r?.attributes??[],a=vo(r?.plural??"");if(i.length===0)return "";let s=_n(i,o),f=On(i,s),u=sc(i,s,"default",n),c=lc(i,s),l=e,d=Bn(t,l,"default");return `mutation ${`Create${Ht(e)}`} {
275
- create${a}(
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}(
276
313
  input: [{
277
- _id: ${ke(n)} ${f} ${u}
278
- ${c}
314
+ _id: ${pe(n)} ${f} ${c}
315
+ ${d}
316
+ ${m}
279
317
  }]
280
318
  ) {
281
319
  ${l} {
282
320
  _id
283
- ${d} }
321
+ ${u} }
284
322
  }
285
323
  }
286
- `}function sc(e,t,o,n){let r=pick(oe("local",e),t);return toPairs(r).reduce((s,[f,u])=>{if(!u?.value)return s;let c=find(propEq(f,"name"))(e),l=Array.isArray(u.value)?"null":Vn(c.dataType,u.value);return `${s}
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}
287
325
  ${f}: {
288
- create: {
326
+ create: [{
289
327
  node: {
290
- _id: ${ke(`${n}:${f}`)}
291
- _type: "${c.dataType}"
292
- ${o}: ${l}
328
+ _id: ${pe(`${n}:${f}`)}
329
+ _type: "${d.dataType}"
330
+ ${o}: ${m}
293
331
  }
294
- }
295
- }`},"")}function lc(e,t){let o=pick(oe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let f=find(propEq(a,"name"))(e),{inputType:u,relationship:c}=f;if(u==="relationship"&&c?.mode==="single"){let m=`connect: {
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: [{
296
334
  where: {
297
335
  node: {
298
- _id: ${ke(s._id??"")}
336
+ _id: { eq: ${pe(a._id??"")} }
299
337
  }
300
338
  }
301
- }
339
+ }]
302
340
  `;return `${i}
303
- ${a}: {
304
- ${m} }`}let l=u==="relationship"&&c?.mode==="multiple",d=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(l&&d){let m=s.relationships?.connect??[];if(c?.entity==="_asset"){let h=Qi(m.map((y,v)=>({...y,sortOrder:y.sortOrder??v})));return `${i}
305
- ${a}: {
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}: {
306
344
  connect: [
307
- ${h} ]
308
- }`}let g=m.reduce((h,y)=>`${h} {
309
- _id: ${ke(y._id)}
310
- }
311
- `,""),p=g?`connect: {
345
+ ${w} ]
346
+ }`}let g=u.map(w=>pe(w._id)).join(", "),p=g?`connect: {
312
347
  where: {
313
348
  node: {
314
- OR: [
315
- ${g} ]
349
+ _id: { in: [${g}] }
316
350
  }
317
351
  }
318
352
  }
319
353
  `:"";return `${i}
320
- ${a}: {
354
+ ${s}: {
321
355
  ${p} }`}return `${i}
322
- `},"")}function cc(e){return e.find(t=>t.isPrimary)??e[0]}function Xi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, options: $options)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $options: ${t}Options`,f=i?.plural??"",u=`GetRelated${Ht(f||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let c=oe("global",a).join(`
323
- `),l=oe(["local"],a),d=l.reduce((y,v)=>`${y}
324
- ${v} {
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} {
325
359
  _id
326
360
  default
327
361
  }
328
- `,""),m=l.reduce((y,v)=>`${y}
329
- ${v} {
362
+ `,""),u=m.reduce((C,k)=>`${C}
363
+ ${k} {
330
364
  _id
331
365
  default
332
366
  ${o}
333
367
  }
334
- `,""),g=o==="default"?d:m,h=filter(propEq("relationship","scope"))(a).reduce((y,v)=>{let A=find(propEq(v.relationship?.entity,"name"))(n)?.attributes.reduce((S,b)=>{let E=o==="default"?"":`${o}
335
- `;if(b.scope==="local")return `${S}
368
+ `,""),g=o==="default"?l:u,w=Yt(s).reduce((C,k)=>`${C}
369
+ ${k} {
370
+ _id
371
+ originalFilename
372
+ mimeType
373
+ path
374
+ size
375
+ height
376
+ width
377
+ lqip
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
391
+ }
392
+ `;if(ne(b)==="local")return `${D}
336
393
  ${b.name} {
337
394
  _id
338
395
  default
339
- ${E}}
340
- `;if(b.scope==="relationship"){let D=find(propEq(b.relationship?.entity,"name"))(n),z=find(propEq(b.relationship?.field,"name"))(D?.attributes??[]).scope==="local"?`{
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"?`{
341
398
  _id
342
399
  default
343
- ${E}}
344
- `:"";if(b.relationship?.mode==="single")return `${S}
400
+ ${L}}
401
+ `:"";if(b.relationship?.mode==="single")return `${D}
345
402
  ${b.name} {
346
- ${b.relationship.field} ${z}}
347
- `;if(b.relationship?.field)return `${S}
348
- ${b.name} (options: {limit: 25, offset: 0}) {
349
- ${b.relationship.field} ${z}}
350
- `}return `${S}
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}
351
408
  ${b.name}
352
- `},"");return `${y}
353
- ${v.name} (options: {limit: 25, offset: 0}) { _id ${A??""}}
354
- `},"");return {queryEntityName:f,query:`query ${u}(${s}) {
355
- ${e}Aggregate(where: $where) {
356
- count
357
- }
358
- ${f}${r} {
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} {
359
413
  _id
360
- ${c} ${g} ${h} }
361
- }
362
- `}}function jn(){return v4()}function Gi(e,t=jn()){let{attributes:o}=a$e,n=vo(a$e.plural),r=_n(o,e),i=On(o,r),a=a$e.plural,s=Bn([a$e,b$8],a,"default");return `mutation ${`Create${Ht(a$e.plural)}`} {
363
- create${n}(
364
- input: [{
365
- _id: ${ke(t)} ${i} }]
366
- ) {
367
- ${a} {
368
- _id
369
- ${s} }
370
- }
414
+ _updatedAt
415
+ ${d} ${g} ${w} ${E} }
371
416
  }
372
- `}var vo=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ht(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(vo).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function Pt(e,t){return t==="_assets"?a$e:find(propEq(t,"plural"))(e)}function Zi(){let e=useApolloClient();return async t=>{let o=jn(),n=Gi(t,o);return await e.mutate({mutation:gql`
373
- ${n}
374
- `}),mc(t,o)}}function mc(e,t){return {_id:t,path:String(e.path?.value??""),originalFilename:String(e.originalFilename?.value??""),size:Number(e.size?.value??0),mimeType:String(e.mimeType?.value??""),lqip:String(e.lqip?.value??""),width:Number(e.width?.value??0),height:Number(e.height?.value??0)}}function tt(){let[e,t]=useState(false),[o,n]=useState(gql`
375
- mutation updateEntity($any: Any) {
376
- any
377
- }
378
- `),[r,i]=useState({}),[a,{data:s,loading:f,error:u}]=useMutation(o,r),c=At(u),{isProjectDisabled:l,isProjectReadOnly:d}=(()=>{if(c?.statusCode===403){let m=St(c.bodyText);if(m&&typeof m.code=="string"){if(m.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(m.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,n,i,{data:s,loading:f,error:u,isProjectDisabled:l,isProjectReadOnly:d}]}function Un({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,a]=tt(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{u();},0),jsx(Fragment,{});let f={dialogTitle:`Delete ${s}`,dialogMessage:`Are you sure you want to delete the selected ${s}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>u()};function u(){let c=e.payload.entityId,l=yo(e.payload.entityName,n,c);return new Promise(d=>{i(gql`
379
- ${l}
380
- `),a({variables:{where:{_id:c}},update(m){m.evict({id:c});},onCompleted:()=>{toast.success("Item successfully deleted."),d();}}),r(true);})}return jsx(po,{options:f})}var vc=Drawer.Portal;function ea({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function bc({...e}){return jsx(vc,{...e})}function wc({className:e,...t}){return jsx(Drawer.Overlay,{"data-slot":"drawer-overlay",className:a$4("fk:fixed fk:inset-0 fk:z-50 fk:bg-overlay/75 fk:backdrop-blur-[1px] fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0",e),...t})}function ta({className:e,children:t,...o}){return jsxs(bc,{children:[jsx(wc,{}),jsxs(Drawer.Content,{"data-slot":"drawer-content",className:a$4("fk:group/drawer-content fk:fixed fk:z-50 fk:flex fk:h-auto fk:flex-col fk:bg-background","fk:data-[vaul-drawer-direction=top]:inset-x-0 fk:data-[vaul-drawer-direction=top]:top-0 fk:data-[vaul-drawer-direction=top]:mb-24 fk:data-[vaul-drawer-direction=top]:max-h-[80vh] fk:data-[vaul-drawer-direction=top]:rounded-b-lg fk:data-[vaul-drawer-direction=top]:border-b","fk:data-[vaul-drawer-direction=bottom]:inset-x-0 fk:data-[vaul-drawer-direction=bottom]:bottom-0 fk:data-[vaul-drawer-direction=bottom]:mt-24 fk:data-[vaul-drawer-direction=bottom]:max-h-[80vh] fk:data-[vaul-drawer-direction=bottom]:rounded-t-lg fk:data-[vaul-drawer-direction=bottom]:border-t","fk:data-[vaul-drawer-direction=right]:inset-y-0 fk:data-[vaul-drawer-direction=right]:right-0 fk:data-[vaul-drawer-direction=right]:w-full fk:data-[vaul-drawer-direction=right]:max-w-[clamp(40vw,95vw,60rem)] fk:data-[vaul-drawer-direction=right]:border-l fk:rounded-l-[20px]","fk:data-[vaul-drawer-direction=left]:inset-y-0 fk:data-[vaul-drawer-direction=left]:left-0 fk:data-[vaul-drawer-direction=left]:w-3/4 fk:data-[vaul-drawer-direction=left]:border-r fk:data-[vaul-drawer-direction=left]:sm:max-w-sm",e),...o,children:[jsx("div",{className:a$4("fk:absolute fk:z-10 fk:hidden fk:shrink-0 fk:rounded-full fk:bg-muted","fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:top-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:block fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=top]/drawer-content:bottom-4 fk:group-data-[vaul-drawer-direction=top]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:block fk:group-data-[vaul-drawer-direction=top]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=top]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=right]/drawer-content:left-3 fk:group-data-[vaul-drawer-direction=right]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:block fk:group-data-[vaul-drawer-direction=right]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=right]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:-translate-y-1/2","fk:group-data-[vaul-drawer-direction=left]/drawer-content:right-4 fk:group-data-[vaul-drawer-direction=left]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:block fk:group-data-[vaul-drawer-direction=left]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=left]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:-translate-y-1/2")}),t]})]})}function oa({className:e,...t}){return jsx("div",{"data-slot":"drawer-header",className:a$4("fk:flex fk:gap-2.5 fk:p-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center fk:group-data-[vaul-drawer-direction=top]/drawer-content:text-center fk:md:text-left",e),...t})}function na({className:e,...t}){return jsx(Drawer.Title,{"data-slot":"drawer-title",className:a$4("fk:flex fk:items-center fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",e),...t})}function ra({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Rt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[f,u]=useState(false),c=n*(50/n),l=useCallback(()=>{(!t||t())&&(u(false),setTimeout(()=>{a();},150));},[t,a,u]),d=useCallback(m=>{m.key==="Escape"&&r&&l();},[l,r]);return useEffect(()=>{u(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",d,false),()=>{globalThis.document.removeEventListener("keydown",d,false);}),[d]),jsx(ea,{direction:"right",dismissible:false,onClose:()=>{l();},open:f,children:jsxs(ta,{style:r?{}:{maxWidth:`calc(100% - ${c.toString()}px)`},children:[jsxs(oa,{className:"fk:px-10",children:[jsx(na,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(ra,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:l,size:"icon",variant:"ghost",children:[jsx(X,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Close"})]})]}),jsx(g$3,{}),jsx("div",{className:"fk:min-h-0 fk:px-10 fk:pt-6 fk:h-full fk:overflow-y-auto fk:pb-16","data-vaul-no-drag":true,children:o})]})})}var sa=createContext({isDirty:false,setIsDirty:e=>{}}),la=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(sa.Provider,{value:n,children:e})};function qt(){return useContext(sa)}function Jt({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function Qt({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}function Xt(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n);}},[t,e,o]),useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}function ya({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:f$1}=useParams(),u=ae(),c$1=d$2(),{relationships:l}=c$2(),[d,m$1]=useState(false),g$1=useRef(null),p=useRef(null),h$2=useRef(null),[y,v]=useState(null),[x,A]=useState(false),[S,b]=useState(false),E=useId(),D=useId();Xt(p,m$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let w=l[D]?.connect;if(!w||h$2.current===w._id)return;let k=Bc(w.value);if(!k)return;let P=n(i$1);h$2.current=w._id,v(null),r(i$1,{...P,value:k});},[n,i$1,D,l,r]);function B(w){if(!w)return;let k={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(k[w])return k[w];let P=w.split("/");if(P.length===2){let[,R]=P;return R.includes("svg")?"svg":R.toLowerCase()}}function z(w,k){if(w&&w.includes(".")){let R=w.split(".").pop();if(R)return R.toLowerCase()}let P=B(k);return P||"file"}async function F(w,k){if(!w)return;let P=Qn("4MB");if(w.size>(P??0)){toast.error("File size too big (max 4MB)");return}let R=w.type.startsWith("image/");if(h$2.current=null,R){let q=new FileReader;q.onload=G=>{let ne=new Image;v(G.target?.result),ne.onload=function(){r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,width:ne.width,height:ne.height}});},ne.src=q.result;},q.readAsDataURL(w);}else v(null);b(true);try{let G=await(await fetch(c$5(f$1).upload,{method:"POST",headers:{"Content-Type":w?.type||"application/octet-stream"},body:w})).json();r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,path:G.pathname,originalFilename:w.name,size:w.size,mimeType:w.type,lqip:G.lqip,...R?{}:{width:void 0,height:void 0}}});}catch(q){console.error(q),v(null),r(i$1,{...n(i$1)?.value,value:{_id:k?.value?._id}});}finally{b(false);}}function H(w){w.stopPropagation(),h$2.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function te(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function I(w){w.preventDefault(),w.stopPropagation(),g$1.current?.click();}function M(w){w.preventDefault(),w.stopPropagation(),m$1(false);let k=n(i$1)?.value,P=h$2.current??zc(k),R=P?{_id:P,value:k}:void 0;c$1({type:"setRelationship",payload:{[D]:{connect:R,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:R,relationshipId:D,mode:"single"}});},0);}function L(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$1,render:({field:w})=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${i$1}`,"aria-expanded":d,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${d?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${x?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.focus(),p.current?.click(),m$1(true);},onKeyDown:k=>{k.key==="Enter"&&m$1(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),A(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),A(false);let P=k.dataTransfer.files&&k.dataTransfer.files[0];F(P,w.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!w.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",id:E,onClick:I,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",onClick:M,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,w.value?.value?.path&&!d?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})})})(),Qn((w.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).mimeType,(w.value?.value).width&&(w.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).width,"x",(w.value?.value).height,"px"]}):null]}):null,!w.value?.value?.path&&y&&jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("img",{src:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!w.value?.value?.path&&!y&&S?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("div",{className:"fk:w-7 fk:h-7 fk:mr-2 fk:rounded-sm fk:bg-muted fk:flex fk:items-center fk:justify-center",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,w.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$1,{onClick:I,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:M,children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$1,{onClick:k=>L(k,w.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>te(k,w.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$1,{onClick:H,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!d&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(p.current?.focus(),p.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),d&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:d&&(!!w.value?.value?.path||!!y),children:jsx(Qt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:w.value?.value?.path?(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];return jsxs("div",{className:"fk:w-full fk:h-full fk:rounded-md fk:bg-muted/40 fk:flex fk:flex-col fk:items-center fk:justify-center fk:text-muted-foreground",children:[jsx("div",{className:"fk:w-16 fk:h-16 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Qn(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),S?jsx("div",{className:"fk:absolute fk:m-0! fk:top-0 fk:left-0 fk:right-0 fk:bottom-0 fk:w-full fk:bg-muted-foreground/5 fk:overflow-hidden",children:jsx("div",{className:"fk:animate-progress fk:w-full fk:h-full fk:bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:s?.accept?s.accept:"image/*",className:"fk:hidden",id:`file-upload-${i$1}`,onChange:k=>{let P=k.currentTarget.files&&k.currentTarget.files[0];F(P,w.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function Bc(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function zc(e){return !e?._id||e._id.includes(":")?"":e._id}function va({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,f$1=useId();function u(l,d){let m=l.currentTarget.value,g;m===""?g="":(g=s==="float"?parseFloat(m):parseInt(m,10),isNaN(g)&&(g="")),o(n,{...d,value:g});}function c$1(l,d){o(n,{...d,disabled:l});}return jsx(c,{control:e$1,name:n,render:({field:l})=>jsxs(e,{children:[jsx(f,{htmlFor:f$1,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$6,{className:`fk:w-full fk:mt-[0.1875rem] ${!l.value?.scope||l.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||l.value?.disabled,id:f$1,...l,onChange:d=>{u(d,l.value);},step:s==="float"?"any":"1",type:"number",value:l.value?.value??""})}),jsx(b$2,{checked:l.value?.disabled??false,onChange:d=>{c$1(d,l.value);},scope:l.value?.scope}),jsx(i,{})]})})}function Gt({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function Wt({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function kt({className:e,align:t="center",sideOffset:o=4,...n}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:a$4("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...n})})}function wa({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let f=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$4("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:u=>u.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",f.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",f.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",f.month),nav:a$4("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",f.nav),button_previous:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_previous),button_next:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_next),month_caption:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",f.month_caption),dropdowns:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",f.dropdowns),dropdown_root:a$4("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",f.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",f.dropdown),caption_label:a$4("fk:font-medium fk:select-none",n==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",f.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",f.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",f.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",f.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",f.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",f.week_number),day:a$4("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",s.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",f.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",f.range_start),range_middle:a$4("fk:rounded-none",f.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",f.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",f.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",f.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",f.disabled),hidden:a$4("invisible",f.hidden),...t},components:{Root:({className:u,rootRef:c,...l})=>jsx("div",{"data-slot":"calendar",ref:c,className:a$4(u),...l}),Chevron:({className:u,orientation:c,...l})=>c==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",u),...l}):c==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",u),...l}):jsx(ChevronDownIcon,{className:a$4("size-4",u),...l}),DayButton:Xc,WeekNumber:({children:u,...c})=>jsx("td",{...c,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:u})}),...a},...s})}function Xc({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=rn.useRef(null);return rn.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":o.selected&&!o.range_start&&!o.range_end&&!o.range_middle,"data-range-start":o.range_start,"data-range-end":o.range_end,"data-range-middle":o.range_middle,className:a$4("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...n})}function Ca({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,f$1=useId();function u(d,m){n(r,{...m,value:d?d.toISOString():""});}function c$1(d,m){n(r,{...m,disabled:d});}function l(d){d.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:d})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:f$1,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(Gt,{children:[jsx(Wt,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!d.value?.value&&"fk:text-muted-foreground",!d.value?.scope||d.value.scope==="default"?"fk:mb-3":""),disabled:a===false||d.value?.disabled,id:f$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:d.value?.value?format(new Date(d.value.value),"PPP")+" at "+format(new Date(d.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[d.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:m=>{m.stopPropagation(),l(m);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(kt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(wa,{mode:"single",selected:d.value?.value?new Date(d.value.value):void 0,onSelect:m=>u(m,d.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:m=>{let g=m.target.value,[p,h]=g.split(":"),y=d.value?.value?new Date(d.value.value):new Date;y.setHours(parseInt(p)),y.setMinutes(parseInt(h)),n(r,{...d.value,value:y.toISOString()});},type:"time",value:d.value?.value?format(new Date(d.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:d.value?.disabled??false,onChange:m=>{c$1(m,d.value);},scope:d.value?.scope}),jsx(i,{})]})})}function Ce(e){return e??null}var Gn=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let o=document.createElement("input");o.type="file",o.accept="image/*",o.onchange=async()=>{o.files?.length;},o.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(o??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:o??""}).run():o!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(o??"")?e.chain().focus().deleteRange(t).setTweet({src:o??""}).run():o!==null&&alert("Please enter a correct Twitter Link");}}]),xa=Command.configure({suggestion:{items:()=>Gn,render:renderItems}});var Aa=[{name:"Default",color:"var(--novel-black)"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Yellow",color:"#EAB308"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],Sa=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],Ta=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Aa.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Sa.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(Gt,{modal:true,open:e,onOpenChange:t,children:[jsx(Wt,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(kt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),Aa.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:a},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),Sa.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:a},children:"A"}),jsx("span",{children:i})]}),o.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Cf(e){try{return new URL(e),!0}catch{return false}}function xf(e){if(Cf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Na=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$4("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(kt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let a=i[0],s=xf(a.value);s&&(n.chain().focus().setLink({href:s}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:o,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:n.getAttributes("link").href||""}),n.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{n.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var Ra=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:3}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleBlockquote().run();},isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],Fa=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ra.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:n.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:Ra.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),n.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var Ma=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:n}=e.state.selection,r=e.state.doc.textBetween(o,n);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$4("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var $a=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:o=>o!=null&&o.isActive("underline"),command:o=>o?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:o=>o!=null&&o.isActive("strike"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleCode().run();},icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:n=>{o.command(n);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:n=>n.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a$4("fk:h-4 fk:w-4",{"fk:text-blue-500":o.isActive(e)})})})},o.name))}):null};function bo({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var qf=()=>jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-0.5",children:[jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-500 [animation-delay:-0.3s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 [animation-delay:-0.15s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600"})]}),La=qf;function Kn({completion:e,onDiscard:t$1}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r,{children:[jsxs(t,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:n}=o.view.state;o.chain().focus().insertContentAt({from:n.from,to:n.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(t,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:n}=o.view.state;o.chain().focus().insertContentAt(n.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r,{children:jsxs(t,{onSelect:t$1,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var id=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function tr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:id.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,n);},className:"fk:flex fk:gap-2 fk:px-4",value:o.value,children:[jsx(o.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),o.label]},o.value))}),jsx(s,{}),jsx(r,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let o=t$1.state.selection.from,n=getPrevText(t$1,o);e(n,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function Oa({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(u,c)=>{let l=await fetch(u,c);if(l.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return l},onError:u=>{u.message!=="FK_AI_RATE_LIMIT"&&toast.error(u.message);}}),f=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[f&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(v,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(md,{children:i})})})}),s&&jsxs("div",{className:"fk:flex fk:h-12 fk:w-full fk:items-center fk:px-4 fk:text-sm fk:font-medium fk:text-muted-foreground fk:text-pink-600",children:[jsx(bo,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 "}),"AI is thinking",jsx("div",{className:"fk:ml-2 fk:mt-1",children:jsx(La,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:f?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let u=t.state.selection.content(),c=t.storage.markdown.serializer.serialize(u.content);a(c,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:f?jsx(Kn,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(tr,{onSelect:(u,c)=>a(u,{body:{option:c}})})})]})]}):null}function nr({children:e,open:t,onOpenChange:o}){let{editor:n}=useEditor();return useEffect(()=>{n&&(t||removeAIHighlight(n));},[n,t]),n?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),n.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(Oa,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),o(true);},size:"sm",children:[jsx(bo,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Rd=[...a,xa];function Ba(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function Fd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(Ba(o))return o}catch{return}}if(Ba(e))return e}function rr({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[f$1,u]=useState(false),[c$1,l]=useState(false),[d,m]=useState(false),[g$1,p]=useState(false),h$1=useDebouncedCallback((x,A)=>{let S=x.getJSON();n(r,{...A,value:JSON.stringify(S)});},300);function y(x,A){n(r,{...A,disabled:x});}let v=x=>(console.log("Image uploader not yet implemented",x),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:x})=>jsxs(e,{children:[jsx(f,{children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-screen-lg fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:a!==false&&!x.value?.disabled,editorProps:{handleDOMEvents:{keydown:(A,S)=>handleCommandNavigation(S)},handlePaste:(A,S)=>handleImagePaste(A,S,v),handleDrop:(A,S,b,E)=>handleImageDrop(A,S,E,v),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:Rd,initialContent:Fd(x.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:A})=>{h$1(A,x.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Gn.map(A=>jsxs(EditorCommandItem,{value:A.title,onCommand:S=>A.command?.(S),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted",children:[jsx("div",{className:"fk:flex fk:h-10 fk:w-10 fk:items-center fk:justify-center fk:rounded-md fk:border fk:border-muted fk:bg-background",children:A.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:A.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:A.description})]})]},A.title))})]}),jsxs(nr,{open:f$1,onOpenChange:u,children:[jsx(g$3,{orientation:"vertical"}),jsx(Fa,{open:c$1,onOpenChange:l}),jsx(g$3,{orientation:"vertical"}),jsx(Na,{open:d,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(Ma,{}),jsx(g$3,{orientation:"vertical"}),jsx($a,{}),jsx(g$3,{orientation:"vertical"}),jsx(Ta,{open:g$1,onOpenChange:p})]})]},`${r}:${x.value?.scope??t.scope}:${String(x.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:x.value?.disabled??false,onChange:A=>{y(A,x.value);},scope:x.value?.scope}),jsx(i,{})]})})}var Id=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];async function Md(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:i=4*1024*1024}=e,a=document.createElement("input");a.type="file";let s=n??Id.join(",");a.accept=s,a.multiple=r,a.style.display="none",document.body.appendChild(a);try{let f=await new Promise(d=>{a.onchange=()=>d(a.files),a.click();});if(!f||f.length===0)return [];let u=[];for(let d of Array.from(f)){if(d.size>i){toast.error(`File size too big (max ${(i/(1024*1024)).toFixed(0)}MB): ${d.name}`);continue}u.push(d);}let c=c$5(o).upload,l=await Promise.all(u.map(async d=>{let m=await $d(d),g=await fetch(c,{method:"POST",headers:{"Content-Type":d.type||"application/octet-stream"},body:d});if(!g.ok)throw new Error(`Upload failed for ${d.name}`);let p=await g.json(),h={pathname:p.pathname,lqip:p.lqip,originalFilename:d.name,size:d.size,mimeType:d.type,width:m?.width,height:m?.height},y=t?await t(h,o):Ld(h);return {...h,_id:y._id,asset:y}}));return l.length>0&&toast.success(`Uploaded ${l.length} file${l.length>1?"s":""}`),l}catch(f){return console.error(f),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(a);}}async function $d(e){return e.type.startsWith("image/")?new Promise(o=>{let n=new FileReader;n.onload=()=>{let r=new Image;r.onload=()=>{o({width:r.width,height:r.height});},r.onerror=()=>o(null),r.src=n.result;},n.onerror=()=>o(null),n.readAsDataURL(e);}):null}function Eo(){let e=Zi();return async t=>Md(t,async o=>{let n={path:{_id:"",disabled:false,scope:"default",value:o.pathname},originalFilename:{_id:"",disabled:false,scope:"default",value:o.originalFilename},size:{_id:"",disabled:false,scope:"default",value:o.size},lqip:{_id:"",disabled:false,scope:"default",value:o.lqip},mimeType:{_id:"",disabled:false,scope:"default",value:o.mimeType},...typeof o.width=="number"?{width:{_id:"",disabled:false,scope:"default",value:o.width}}:{},...typeof o.height=="number"?{height:{_id:"",disabled:false,scope:"default",value:o.height}}:{}};return e(n)})}function Ld(e){return {_id:"",path:e.pathname,originalFilename:e.originalFilename,size:e.size,mimeType:e.mimeType,lqip:e.lqip??"",width:e.width??0,height:e.height??0}}function cr({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:f$1}=n,{projectId:u}=useParams(),c$1=ae(),l=d$2(),{relationships:d}=c$2(),m=Eo(),g$1=useId(),p=useId(),h$1=useRef(null),y=useRef([]),v$1=useRef(null),x=useRef([]),A=useRef(""),[S,b]=useState(false),E=useMemo(()=>Jd(t.value),[t.value]),[D,B]=useState(E);Xt(h$1,b),useEffect(()=>{let I=bt(E);y.current=E.map(M=>M._id),x.current=[],B(M=>{let L=bt(M);return I===""&&L!==""&&A.current===L||L===I?M:(A.current=I,E)});},[E]),useEffect(()=>{let I=d[p]?.connect;if(!I)return;let M=I.map((P,R)=>Ua(P.value,P.sortOrder??R)).filter(P=>!!P),L=bt(M),w=bt(D),k=v$1.current;k===w&&L!==k||(v$1.current=null,L!==w&&B(M));},[p,d,D]),useEffect(()=>{let I=bt(D);if(A.current===I)return;let M=D.map((k,P)=>({_id:k._id,sortOrder:P,value:{...k,sortOrder:P}})),L=D.map(k=>k._id),w=x.current.filter(k=>!L.includes(k));A.current=I,l({type:"setRelationship",payload:{[p]:{connect:M,disconnect:w}}}),r(i$1,{...t,relationships:{connect:M,disconnect:w},value:D});},[l,t,i$1,p,D,r]);function z(I){I.preventDefault(),I.stopPropagation(),c$1({type:"EditRelationship",payload:{connectedEntitiesCount:D.length,entityName:f$1?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function F(I){I.preventDefault(),I.stopPropagation();let M=await m({projectId:u,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(L=>{let w=new Set(L.map(R=>R._id)),k=M.map((R,q)=>({...R.asset,sortOrder:L.length+q})).filter(R=>!w.has(R._id)),P=sr([...L,...k]);return v$1.current=bt(P),P});}function H(I){B(M=>{let L=sr(M.filter(w=>w._id!==I));return y.current.includes(I)&&!x.current.includes(I)&&(x.current=[...x.current,I]),v$1.current=bt(L),L});}function te(I,M){B(L=>{let w=L.findIndex(G=>G._id===I),k=w+M;if(w<0||k<0||k>=L.length)return L;let P=[...L],[R]=P.splice(w,1);if(!R)return L;P.splice(k,0,R);let q=sr(P);return v$1.current=bt(q),q});}return jsx(c,{control:e$1,defaultValue:t,name:i$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:g$1,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${i$1}`,"aria-expanded":S,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${S?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:I=>{I.preventDefault(),I.stopPropagation(),h$1.current?.focus(),b(true);},ref:h$1,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[S&&D.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[D.length," ",D.length===1?"asset":"assets"," selected"]}):D.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[D.slice(0,8).map(I=>jsx(Ud,{asset:I},I._id)),!S&&D.length>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",D.length-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:g$1,onClick:I=>{I.preventDefault(),I.stopPropagation(),b(M=>!M);},size:"icon",variant:"ghost",children:S?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:S?"Close":"Expand field"})})]})})]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:b,open:S,children:jsx(Qt,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${i$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:z,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",onClick:I=>{F(I);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),D.length>0?jsx(v,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:D.map((I,M)=>jsx(qd,{asset:I,index:M,isFirst:M===0,isLast:M===D.length-1,moveAsset:te,removeAsset:H},I._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Ud({asset:e}){return qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image$1,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function qd({asset:e,index:t,isFirst:o,isLast:n,moveAsset:r,removeAsset:i}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image$1,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:o,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:n,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",onClick:()=>i(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Jd(e){return Array.isArray(e)?e.map((t,o)=>Ua(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function bt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function sr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Ua(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let o=e;return {_id:String(o._id??""),path:String(o.path??""),originalFilename:String(o.originalFilename??""),size:Number(o.size??0),mimeType:String(o.mimeType??""),lqip:String(o.lqip??""),width:Number(o.width??0),height:Number(o.height??0),sortOrder:o.sortOrder??t}}function qa(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Qa({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function To({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=d(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},i={boolean:a$a,date:a$9,datetime:a$c,editor:b$7,asset:a$b,number:a$9,relationship:a$9,select:a$9,switch:a$a,text:a$9,textarea:a$9,tags:Qa},a=e.map(c=>{let l=(c.inputType==="relationship"&&c.relationship?.entity==="_asset"?"asset":void 0)??c.previewType??r[c.inputType],d=n("previewFields",[l])?.[0]?.component??i[l]??i.text;if(c.isHidden)return null;let m=l==="tags";return {accessorKey:c.name,filterFn:(g,p,h)=>m?true:(Array.isArray(h)?h:[h]).includes(g.getValue(p)),header:()=>jsx("div",{className:"fk:flex fk:items-center",children:c.label}),cell:({row:g})=>jsx(d,{value:g.getValue(c.name)}),enableSorting:false,enableHiding:true,size:c.options?.size??150}}).filter(c=>c!==null),s={id:"actions",cell:({row:c})=>o?o(c):null,size:80},f={id:"select",cell:({row:c,table:l})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:d=>{l.toggleAllPageRowsSelected(false),c.toggleSelected(!!d);}}),enableSorting:false,enableHiding:false,size:50},u={id:"select",header:({table:c})=>jsx(a$d,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:c.getIsAllPageRowsSelected()||c.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:l=>{c.toggleAllPageRowsSelected(!!l);}}),cell:({row:c})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:l=>{c.toggleSelected(!!l);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[f]:[],...t==="multiple"?[u]:[],...o?[s]:[],...a]}function nu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function Do({classNames:e,columns:t,data:o,initialSelectionState:n$1,onEntitySelectionChange:r,onScroll:i,pageSize:a,rowHeightEstimate:s,rowAdditionState:f,rowDeletionState:u,toolbarComponent:c}){let l$1=useRef(null),{schemaErrorMessage:d}=Tt(),[m,g]=useState(n$1??{}),[p,h]=useState({}),[y,v]=useState([]),[x,A]=useState([]);useEffect(()=>{if(!n$1)return;let F=Object.keys(m).sort().join(","),H=Object.keys(n$1).sort().join(",");F!==H&&g(n$1);},[n$1,m]);let S=useReactTable({data:o,columns:t,state:{sorting:x,columnVisibility:p,rowSelection:m,columnFilters:y},initialState:{pagination:{pageSize:a??25}},enableRowSelection:true,onRowSelectionChange:z,onSortingChange:A,onColumnFiltersChange:v,onColumnVisibilityChange:h,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:F=>F._id,manualPagination:true,meta:{getRowBackground:F=>ru(F,u,f)}}),{rows:b}=S.getRowModel(),E=useVirtualizer({count:b.length,estimateSize:()=>s??nu(e?.row)??45,getScrollElement:()=>l$1.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?F=>F.getBoundingClientRect().height:void 0,overscan:5}),D=E.getVirtualItems(),B=E.getTotalSize();function z(F){let H=Object.keys(typeof F=="function"?F(m):F);g(F),r?.(H);}return d?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:flex-col fk:gap-4",e?.wrapper),children:[c&&c(S),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:-mb-px",children:jsxs(h$2,{className:a$4("fk:grid fk:pb-20",e?.table),onScroll:i,ref:l$1,children:[jsx(i$1,{className:"fk:grid",children:S.getHeaderGroups().map(F=>jsx(l,{className:"fk:flex fk:w-full",children:F.headers.map(H=>jsx(m$1,{className:a$4("fk:flex fk:items-center",H.column.id==="actions"&&"fk:pl-0"),colSpan:H.colSpan,style:H.getSize()?{width:`${H.getSize().toString()}px`}:{},children:H.isPlaceholder?null:flexRender(H.column.columnDef.header,H.getContext())},H.id))},F.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${B.toString()}px`},children:D.length?D.map(F=>{let H=b[F.index];return jsx(l,{className:`${S.options.meta.getRowBackground(H)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":F.index,"data-state":H.getIsSelected()&&"selected",ref:E.measureElement,style:{transform:`translateY(${F.start.toString()}px)`},children:H.getVisibleCells().map(te=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",te.column.id==="actions"&&"fk:pl-0!"),style:{width:te.column.getSize()},children:flexRender(te.column.columnDef.cell,te.getContext())},te.id))},F.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function ru(e,t,o){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Wa({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var yu=25;function ur({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:f$1,setValue:u}){let[c$1,l]=useState(false),d=useRef(null);Xt(d,l);let[m,g$1]=useState([]),{name:p,label:h$1,options:y,relationship:v}=a,x=v?.entity??p,A=ae(),S=d$2(),{relationships:b}=c$2(),E=useId(),D=useId(),B=find(propEq(x,"name"))(s),z=B?.attributes??[],H=find(propEq(r,"name"))(s)?.name??"",te=find(propEq(r,"name"))(z)?.relationship?.mode,I,L=z.find(_=>_.relationship?.entity===H)?.relationship?.mode,w=te==="single"?r:i$1;L&&(I=L==="single"?`${w}Connection_NOT`:`${w}Connection_NONE`);let k=bu(z),P=useMemo(()=>o.value?wu({data:o.value,defaultScope:t,primaryAttributeName:k,relationshipEntitySchema:B,scope:f$1}):[],[t,o,k,B,f$1]),R=Xi({attributeName:p,relatedEntityName:x,scope:f$1,schema:s}),q=m.length?m.slice(0,12).map(_=>_[k]):[],[G,{loading:ne,data:qe}]=useLazyQuery(gql`
381
- ${R.query}
382
- `),ao=To({attributesSchema:B?.attributes??[],actionsComponent:_=>vu({appDispatch:S,relationshipId:D,relationships:b,row:_,setRows:g$1})});useEffect(()=>{g$1(P),o.value!==""&&S({type:"setRelationship",payload:{[D]:{connect:[],disconnect:[]}}});},[S,qe,P,D,o,f$1]),useEffect(()=>{u(p,{...o,relationships:b[D]});},[o,b,D,u,p]),useEffect(()=>{let Mt=(b[D]?.connect??[]).map(({value:so})=>so);g$1(uniqBy(prop("_id"),[...Mt,...P]));},[qe,o.count,P,b,D]);let yn=useCallback(_=>{let Mt=o.count??0;if(!_||Mt===0||m.length===0)return;let{scrollHeight:so,scrollTop:vn,clientHeight:bn}=_;so-vn-bn<200&&!ne&&m.length<Mt&&G({variables:{options:{limit:yu,offset:m.length},where:{productsConnection_SOME:{node:{_id:n}}}}}).then(({data:$})=>{if(!$)return;let U=Ko(B?.plural??"",f$1,$,s);g$1(uniqBy(prop("_id"),[...P,...U.results]));}).catch($=>{console.error("Error fetching more data:",$);});},[o.count,n,G,P,ne,B?.plural,m.length,s,f$1]);function $o(_){_.preventDefault(),A({type:"EditRelationship",payload:{connectedEntitiesCount:P.length,connectionName:I,entityName:x,entityId:n,relationshipId:D,mode:v?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:h$1}),y?.comment?jsx(h,{children:y.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.375rem] fk:pl-3 fk:pr-10 fk:py-0.5 fk:text-sm",children:jsxs("div",{"aria-controls":`relationship-dropdown-${p}`,"aria-expanded":c$1,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.focus(),d.current?.click(),l(true);},onKeyDown:_=>{_.key==="Enter"&&l(true),_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},ref:d,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[c$1?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:$o,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",B?.menu?.label??B?.plural]}):jsx("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:q.map(_=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:_},_))}),c$1?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false);},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:E,onKeyDown:_=>{_.key==="Enter"&&(d.current?.focus(),d.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:l,open:c$1,children:jsx(Qt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:mt-3 fk:mb-2",id:`relationship-dropdown-${p}`,children:jsx(Do,{classNames:{table:"fk:max-h-[17.5rem]"},columns:ao,data:m,entityName:r,onScroll:_=>{yn(_.target);},rowAdditionState:b[D]?.connect,rowDeletionState:b[D]?.disconnect})})})})]})}),jsx(i,{})]})})}function vu({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],f=typeof find(propEq(a,"_id"),s)=="object",u=o[t]?.disconnect?.includes(a),c=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&r(l=>l.filter(d=>d._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(l=>l._id!==a),disconnect:u?o[t]?.disconnect?.filter(l=>l!==a)??[]:c}}});}return jsx(Wa,{action:i,row:n})}function bu(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function wu({data:e,defaultScope:t,primaryAttributeName:o,relationshipEntitySchema:n,scope:r}){return Array.isArray(e)?e.map(i=>map(a=>{if(a&&typeof a!="string"&&!Array.isArray(a)&&a.__typename){let f=find(propEq(a.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";return f?a[f]?.[r]??a[f]?.[t]??a[f]:a[r]??a[t]}return Array.isArray(a)?a.slice(0,3).map(f=>f[o]?.[r]??f[o]?.[t]).join(", "):a},i)):[]}function mr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:f$1}){let[u,c$1]=useState(false),{name:l,label:d,options:m,relationship:g$1}=r,p=g$1?.entity??l,h$1=ae(),y=d$2(),v=useId(),{relationships:x}=c$2(),A=useId(),S=find(propEq(p,"name"))(a),E=Tu(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[A]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,A,o,s]),useEffect(()=>{f$1(l,{...i$1(l),...x[A]?.connect??""});},[o,l,x,A,f$1]);function D(z){z.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:A,mode:g$1?.mode??"single"}});}function B(z){let F={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};z.preventDefault(),y(F),f$1(l,{...i$1(l),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:l,render:({field:z})=>{let F=z.value?.value,H="";return F&&typeof F=="object"&&!Array.isArray(F)&&F[E]&&(H=F[E]?.[s]??F[E]?.[t]??F[E]),jsxs(e,{children:[jsx(f,{htmlFor:v,children:d}),m?.comment?jsx(h,{children:m.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$6,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:v,onBlur:()=>{c$1(false);},onClick:D,onFocus:()=>{c$1(true);},onKeyDown:te=>{te.key==="Enter"&&D(te);},readOnly:true,type:"text",value:H}),H?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:B,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:D,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i,{})]})}})}function Tu(e){return e.find(t=>t.isPrimary)??e[0]}function pr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(mr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(cr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(ur,{...n})}return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function ns({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(u,c){let d=t.dataType==="int"&&!isNaN(Number(u))?Number(u):u;o(n,{...c,value:d});}function f$2(u,c){o(n,{...c,disabled:u});}return jsx(c,{control:e$2,name:n,render:({field:u})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:u.value?.value?String(u.value.value):void 0,disabled:i$1===false||u.value?.disabled,onValueChange:c=>{s(c,u.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(c=>"groupLabel"in c?jsxs(b$1,{children:[jsx(f$1,{children:c.groupLabel}),c.items.map(l=>jsx(g$1,{value:l.value,children:l.label},l.label))]},c.groupLabel):jsx(g$1,{value:c.value,children:c.label},c.label))})]}),jsx(b$2,{checked:u.value?.disabled??false,onChange:c=>{f$2(c,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function hr({inputType:e,label:t}){return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Hu({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:f},u){let c=find(propEq(n,"name"))(a),l=useMemo(()=>c?.attributes??[],[c]),d$1=useMemo(()=>z.object(l.reduce((b,E)=>typeof E.validation>"u"?b:{...b,[E.name]:z.object({value:E.validation(z).or(z.any().refine(()=>false,{message:E.label?`${E.label} is required`:"Required field"}))})},{})),[l]),m=useForm({resolver:zodResolver(d$1),values:i,mode:"onBlur",criteriaMode:"all"}),{control:g,getValues:p,handleSubmit:h,setValue:y,watch:v,trigger:x}=m,{getContributionPointConfig:A}=d(),S={datetime:Ca,editor:rr,asset:ya,number:va,relationship:pr,select:ns,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(u,()=>({submit(){x().then(()=>{h(()=>{s(false),f(p(),i);})();});},hasErrors(){s(true);},hasDataChanged(){return is(p(),i)}})),useEffect(()=>{let b=v(E=>{s(is(E,i));});return ()=>{b.unsubscribe();}},[i,s,v]),!c||c.attributes.length===0?jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsxs(ie,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...m,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:l.map(b=>{if(b.name==="_id")return null;let E=A("formFields",[b.inputType])?.[0]?.component??S[b.inputType];return E?createElement(E,{key:b.name,control:g,defaultScope:t,defaultValue:i?i[b.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:b,getValues:p,schema:a,scope:e,setValue:y}):jsx(hr,{inputType:b.inputType,label:b.label},b.name)})})})}var pn=memo(forwardRef(Hu));function is(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let o=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",n=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(e[s]?.value),disabled:e[s]?.disabled??false,relationships:Object.keys(e[s]?.relationships?.connect??{}).length||e[s]?.relationships?.disconnect?.length?e[s]?.relationships:void 0}}),{});return !equals(r,i)}function br({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:a}=d(),{schema:s,scopes:f}=find(propEq(a??"","projectId"))(i),u=f?.find(E=>E.isDefault)?.name??"default",l=find(propEq(n,"name"))(s)?.plural??n,{scope:d$1}=c$2(),m=ae(),[g,p,h,y]=tt(),{setIsDirty:v}=qt();useEffect(()=>{y.error&&r.current?.hasErrors();},[y.error]);function x(){return r.current?.hasDataChanged()?(m({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{m({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{m({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let A=useCallback(E=>{m({type:"Dismiss",_id:E,payload:{}});},[m]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(E=>{let D=v4(),B=zn(l,s,E,D),z=Nt(l,d$1,s),F=gql`
383
- ${z.query}
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}
384
423
  `;p(gql`
385
- ${B}
386
- `),h({refetchQueries:[F],onCompleted:()=>{A(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,l,A,g,s,p,d$1,h]);return jsx(Rt,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",onClick:()=>{S();},variant:"default",children:[y.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]}),beforeClose:x,depth:t,isFocused:o,onClose:()=>{A(e._id);},title:`Add ${n}`,children:jsx(pn,{currentScope:d$1,defaultScope:u,entityName:n,entityNamePlural:l,onSubmit:b,ref:r,schema:s,setIsDirty:v})})}function Ro({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r}){let[i,a]=useState({count:0,results:[]}),s=Nt(e,o,t),{schemaErrorMessage:f,setSchemaErrorMessage:u}=Tt(),{loading:c,data:l,fetchMore:d,error:m}=useQuery(gql`
387
- ${s.query}
388
- `,{variables:n}),g=At(m),p=Wo(m),{isProjectDisabled:h,isProjectReadOnly:y}=(()=>{if(g?.statusCode===403){let A=St(g.bodyText);if(A&&typeof A.code=="string"){if(A.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(A.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),v=useCallback(()=>ds({data:l,entityNamePlural:e,isForm:r,schema:t,scope:o}),[l,e,r,t,o]);function x(A){d(A).then(({data:S})=>{let b=ds({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});a(E=>({count:b.count,results:uniqBy(prop("_id"),[...E.results,...b.results])}));}).catch(S=>{console.error("Error fetching more data:",S);});}return useEffect(()=>{if(p){u(p);return}l&&f&&!m&&u(null);},[l,m,f,p,u]),useEffect(()=>{m||p||a(v);},[m,v,p]),{isLoading:c,fetchMore:x,count:i.count,data:i.results,isProjectDisabled:h,isProjectReadOnly:y,schemaErrorMessage:f}}function ds(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Ji(e.entityNamePlural,e.scope,e.data,e.schema):Ko(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function ms(){return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Read Only Mode"}),jsxs(ie,{children:["This project is currently in read only mode and changes cannot be saved. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/read-only-mode",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function Cr({handleSave:e,isLoading:t}){let{isDirty:o}=qt();return jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}function xr(){return jsx(Fragment,{children:Array.from({length:10},(t,o)=>o++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$1,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(r$1,{className:"fk:w-5 fk:mr-2"}),jsx(r$1,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function Sr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:f,scopes:u}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),c=u?.find(R=>R.isDefault)?.name??"default",l=find(propEq(r,"plural"))(f),d$3=l?.name??r,{scope:m}=c$2(),[g,p]=useState(m),h=ae(),y=d$2(),[v,x,A,S]=tt(),{setIsDirty:b}=qt(),E=useCallback(R=>{b(R);},[b]);useEffect(()=>{S.error&&i.current?.hasErrors();},[S.error]);let D=useCallback(()=>i.current?.hasDataChanged()?(h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[h,e._id]),B=useCallback(R=>{h({type:"Dismiss",_id:R,payload:{}});},[h]),z=useCallback(()=>{i.current?.submit();},[i]);function F(R){if(i.current?.hasDataChanged()){h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{p(g),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}}}});return}p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}let H=useCallback((R,q)=>{if(!q)return;let G=Ln(r,n,g,f,q,R),ne=Nt(r,g,f),qe=gql`
389
- ${ne.query}
390
- `;x(gql`
391
- ${G}
392
- `),A({variables:{where:{_id:n}},refetchQueries:[{query:qe,variables:{where:{_id:n}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),v(true);},[g,n,r,v,f,x,A]),{isLoading:te,data:I}=Ro({entityNamePlural:r,schema:f,scope:g,variables:{where:{_id:n}},isForm:true}),M=I,L=M.length>0,w=te&&!L;function k(R,q){let G=R?.attributes.find(ao=>ao.isPrimary)??R?.attributes[0],ne=G.name,qe=G?.relationship?.field!==void 0;return q.length?qe&&G?.relationship?.field?q[0][ne]?.value?.[G.relationship.field]:q[0][ne]?.value:""}let P=L&&l?k(l,M):"";return jsx(Rt,{actions:jsxs(Fragment,{children:[u&&u.length>1?jsxs(a$5,{onValueChange:R=>{F(R);},value:g,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(g,"name"))(u).label})]}),jsx(e$1,{children:u.map(R=>jsx(g$1,{value:R.name,children:R.label},R.name))})]}):null,jsx(Cr,{handleSave:z,isLoading:S.loading})]}),beforeClose:D,depth:t,isFocused:o,onClose:()=>{B(e._id);},onFormChange:()=>{},title:P,children:w||!L?jsx(xr,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(ms,{}):null,jsx(pn,{currentScope:g,defaultScope:c,entityId:n,entityName:d$3,entityNamePlural:r,formData:M[0],onSubmit:H,ref:i,schema:f,setIsDirty:E})]})})}var bs=25;function gm(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Nr({action:e,depth:t,isFocused:o}){let n=ae(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:f,connectionName:u,entityId:c,entityName:l,initialAssetPath:d$1,initialConnection:m,mode:g,relationshipId:p}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:v}=find(propEq(y??"","projectId"))(h),x=find(propEq(l,"name"))(v),A=x?.plural??"",S=i[p],b=Eo(),E=l==="_asset",D=E?"asset":x?.menu?.label??l.toLowerCase(),B=E&&g==="single"?"Select asset":`Select ${E?"assets":D}`,z=g==="single"?"Upload asset":"Upload assets",[F,H]=useState([]),te=[];if(m)te=[{id:m._id,value:m.value}];else if(S?.connect){let $=S.connect;te=[{id:$._id,value:$.value}];}let I=g==="single"?te:S?.connect?.map($=>({id:$._id,value:$.value}))||[],[M,L]=useState(I),w=useMemo(()=>{let $=u?{[u]:{node:{_id:c}}}:{},U=E?{NOT:{path:null}}:{};return g==="multiple"?{...U,...$,OR:F}:{...U,OR:F}},[u,c,E,g,F]),{count:k,data:P,fetchMore:R,isLoading:q}=Ro({entityNamePlural:A,schema:v,scope:a,variables:{options:{offset:0,limit:bs},where:w}}),G=!!P?.length,ne=q&&!G,qe=To({attributesSchema:x?.attributes??[],checkboxSelect:g}),ao=Array(5).fill({}),yn=gm(qe);useEffect(()=>{if(g!=="single"||M.length>0||!d$1||!P?.length)return;let $=P.find(U=>U.path===d$1);!$?._id||typeof $._id!="string"||L([{id:$._id,value:$}]);},[P,d$1,g,M.length]);let $o=useCallback($=>{n({type:"Dismiss",_id:$,payload:{}});},[n]),_=useCallback($=>{let U=P?.length??0,Fe=k-f;if($&&Fe>0&&U>0){let{scrollHeight:it,scrollTop:K,clientHeight:wn}=$;it-K-wn<500&&!q&&U<Fe&&R({variables:{options:{offset:U,limit:bs},where:w}});}},[w,f,k,P?.length,R,q]);function Mt(){let $;if(g==="single"){let[U]=M;$={_id:U?.id??"",value:U?.value??null};}g==="multiple"&&($=M?.map((U,Fe)=>({_id:U.id??"",...E?{sortOrder:Fe}:{},value:U.value}))),r({type:"setRelationship",payload:{[p]:{connect:$,disconnect:S?.disconnect??[]}}}),$o(e._id);}function so($){if(g==="multiple"){L(Fe=>{let it=new Map(Fe.map(K=>[K.id,K]));return $.map(K=>{if(it.has(K))return it.get(K);let wn=P?.find(Ps=>Ps._id===K);return {id:K,value:wn}})});return}let U=$[$.length-1];L(U?Fe=>{if(Fe.length===1&&Fe[0].id===U)return Fe;let it=P?.find(K=>K._id===U);return [{id:U,value:it}]}:[]);}function vn(){n({type:"AddEntity",payload:{entityName:l}});}async function bn(){let $=await b({projectId:y,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});L(U=>{if(g==="single"){let[K]=$;return K?[{id:K._id,value:K.asset}]:U}let Fe=new Set(U.map(K=>K.id)),it=$.filter(K=>!Fe.has(K._id)).map(K=>({id:K._id,value:K.asset}));return [...U,...it]});}return jsx(Rt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Mt();},variant:"default",children:"Select"}),E?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{vn();},variant:"outline",children:`Create ${D}`}),E?jsxs(b$3,{className:"fk:px-8",onClick:()=>{bn();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),z]}):null]}),depth:t,isFocused:o,onClose:()=>{$o(e._id);},title:B,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Do,{columns:ne?yn:qe,data:ne?ao:P??[],entityName:x?.name??"",initialSelectionState:M?.reduce(($,U)=>({...$,...U.id?{[U.id]:true}:{}}),{}),onEntitySelectionChange:so,onScroll:$=>{_($.target);},toolbarComponent:()=>jsx(km,{entityNamePlural:A,projectId:y??"",setSearchResultIds:H})})})})}function km({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:f,isLoading:u}=e$5(t,a),c=useRef(null),l=useMemo(()=>hm(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(f){let m=JSON.stringify(f.map(p=>p._id).sort()),g=c.current?JSON.stringify(c.current.map(p=>p._id).sort()):"";m!==g&&(c.current=[...f],o(f.map(p=>({_id:p._id}))));}},[f,o]);function d(m){let{value:g}=m.target;r(g),l(g);}return jsxs("div",{className:"fk:relative fk:w-full",children:[u?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$6,{className:"fk:w-full fk:pl-11!",onChange:d,placeholder:"Search",value:n})]})}function hm(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Cs(){let e=zi(),t=e.filter(n=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===n.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(n=>{switch(n.type){case "AlertDialog":{let{payload:r}=n;return jsx(po,{options:r.options},n._id)}case "DeleteEntity":return jsx(Un,{action:n},n._id);case "AddEntity":return jsx(br,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Sr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(Nr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function xs({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$f(o);return window.location.pathname===r&&(window.location.href=b$b(r,n)),jsx(a$i,{children:jsx(c$6,{config:e,children:jsxs(Si,{children:[jsx(la,{children:jsx(Cs,{})}),jsx(Outlet,{})]})})})}function Es(){let e=useRouteError(),t=new Date().getFullYear();function o(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):Pn(e)?ui(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:o()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(qo,{})]})})]})}function Rr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:t})]})}var Fm=RouterProvider;function Im({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(c=>As(c)):[As(e)],[i]=r,a=a$f(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let f=[{path:a,element:jsx(xs,{config:r}),errorElement:jsx(Es,{}),children:[{path:":projectId",element:jsx(vi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(c=>({path:c.name,element:c.component,errorElement:jsx(Rr,{}),children:c.routes?.map(l=>({path:l.path,element:l.component,errorElement:jsx(Rr,{}),children:l.children?.map(d=>({path:d.path,element:d.component}))}))}))}]}],u=createBrowserRouter(f);return n("Init Studio"),jsx(a$g,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Bi,{children:jsx(Fm,{router:u})})})})}function As(e){return {basePath:a$f(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function $m(){return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Project Paused"}),jsxs(ie,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function _m(){let{schemaErrorMessage:e}=Tt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
393
- `);return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Schema mismatch"}),jsxs(ie,{children:[jsx("p",{children:t}),o?jsx("p",{className:"fk:mt-1",children:o}):null,n.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:n.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function Vm(e){return e}function Bm(e){return e}function Hm({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(Gt,{children:[jsx(Wt,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk:h-8 fk:border-dashed",children:[jsx(CirclePlus,{className:"fk:mr-2 fk:h-4 fk:w-4"}),t$1,r$1?.size>0&&jsxs(Fragment,{children:[jsx(g$3,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:r$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[r$1.size," selected"]}):o$1.filter(i=>r$1.has(i.value)).map(i=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:i.label},i.value))})]})]})}),jsx(kt,{className:"fk:w-[200px] fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(i=>{let a=r$1.has(i.value);return jsxs(t,{onSelect:()=>{a?r$1.delete(i.value):r$1.add(i.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$4("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",a?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),i.icon&&jsx(i.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:i.label}),n?.get(i.value)&&jsx("span",{className:"fk:ml-auto fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:font-mono fk:text-xs",children:n.get(i.value)})]},i.value)})}),r$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function Qm({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=ae(),i=o.original._id;function a(){r({type:"EditEntity",payload:{entityId:i,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:i,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[n.canEdit&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:a,variant:"ghost",children:[jsx(Pencil,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),n.canDelete&&!n.canEdit&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:s,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),n.canEdit&&n.canDelete&&jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Additional actions"})]})}),jsxs(f$2,{align:"end",className:"w-[160px]",children:[jsx(h$1,{onClick:a,children:"Edit"}),jsx(m,{}),jsx(h$1,{onClick:s,children:"Delete"})]})]})]})}function Mr({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function Km({entityName:e,table:t}){let o=ae(),n=d$2(),r=c$2(),{projects:i,currentProjectId:a}=d(),{scopes:s}=find(propEq(a??"","projectId"))(i),[f,u,c]=tt(),[l,d$3]=useState(false),m=t.getSelectedRowModel().rows.map(v=>v.original._id);function g(){o({type:"AddEntity",payload:{entityName:e}});}function p(v){n({type:"setScope",payload:{projectId:a,scope:v}});}async function h(v){let{schema:x}=find(propEq(a??"","projectId"))(i),A=yo(e,x,v);await new Promise(S=>{u(gql`
394
- ${A}
395
- `),c({variables:{where:{_id:v}},update(b){b.evict({id:v});},onCompleted:()=>{S();}}),f(true);});}function y(){let v=e==="_asset"?"asset":e.toLowerCase();o({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${m.length} ${v}${m.length>1?"s":""}`,dialogMessage:m.length>1?`Are you sure you want to delete the selected ${v}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${v}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{d$3(true);try{for(let x of m)await h(x);t.resetRowSelection(),toast.success(m.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{d$3(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[s&&s.length>0?jsxs(a$5,{defaultValue:r.scope,onValueChange:v=>{p(v);},value:r.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(e$1,{children:s.map(v=>jsx(g$1,{value:v.name,children:v.label},v.name))})]}):null,jsx(Mr,{table:t})]}),m.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:l,onClick:y,size:"sm",variant:"destructive",children:[l?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",m.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:l,onClick:g,size:"sm",variant:"default",children:"Create"})]})}export{Do as DataTable,Hm as DataTableFacetedFilter,Qm as DataTableRowActions,Km as DataTableToolbar,Mr as DataTableViewOptions,Im as FlexkitStudio,$m as ProjectDisabled,_m as SchemaError,Vm as defineConfig,Bm as defineEntity,zn as getEntityCreateMutation,yo as getEntityDeleteMutation,Nt as getEntityQuery,Pt as getEntitySchema,Ln as getEntityUpdateMutation,ae as useDispatch,tt as useEntityMutation,Ro as useEntityQuery,Tt as useGraphQLError,To as useGridColumnsDefinition,Eo as useUploadAssets};//# sourceMappingURL=index.js.map
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`
433
+ ${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
396
435
  //# sourceMappingURL=index.js.map