@flexkit/studio 0.0.26 → 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 (93) 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-AOVXSAH5.js → chunk-XU2JGXYC.js} +2 -2
  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 +35 -9
  49. package/dist/index.js +237 -199
  50. package/dist/index.js.map +1 -1
  51. package/dist/nextjs.js +1 -1
  52. package/dist/{project-selector-TWMWLTCH.js → project-selector-X6YVZYKL.js} +2 -2
  53. package/dist/{project-selector-TWMWLTCH.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-Da7sP-Fn.d.ts → types.d-DiA0h3ut.d.ts} +32 -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-AOVXSAH5.js.map +0 -1
  77. package/dist/chunk-FPK7J4BP.js.map +0 -1
  78. package/dist/chunk-I4C65MUI.js +0 -2
  79. package/dist/chunk-I4C65MUI.js.map +0 -1
  80. package/dist/chunk-JHDZP6RC.js +0 -2
  81. package/dist/chunk-JHDZP6RC.js.map +0 -1
  82. package/dist/chunk-ND3OZVR5.js.map +0 -1
  83. package/dist/chunk-PEYW7XOU.js.map +0 -1
  84. package/dist/chunk-RVGMKQPC.js.map +0 -1
  85. package/dist/chunk-SW6NNU5D.js.map +0 -1
  86. package/dist/chunk-SXZZFHMJ.js +0 -2
  87. package/dist/chunk-SXZZFHMJ.js.map +0 -1
  88. package/dist/chunk-Z5CZVKD4.js.map +0 -1
  89. package/dist/chunk-ZBV4BY36.js +0 -3
  90. package/dist/datetime-VZJ7XF33.js +0 -2
  91. package/dist/switch-FBS75HI4.js +0 -2
  92. package/dist/text-RZOXKHWE.js +0 -2
  93. package/dist/textarea-OUJM7E6O.js +0 -2
package/dist/index.js CHANGED
@@ -1,12 +1,16 @@
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-AOVXSAH5.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,uniq,omit,pick,toPairs,props}from'ramda';import qs,{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 Jo 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 Wn 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 yd 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 Uo(){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 js=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 ne({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(js({variant:t}),e),...o})}function De({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 re({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 Ws=Jo.object({email:Jo.string().email({message:"Please enter a valid email address"})});function Rn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Ws),defaultValues:{email:""}}),d=new URL(c$5(e$1).loginOtpSend,a$k),{data:c$1,error:l,isLoading:f}=qs(r?d.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),u=c$1&&"error"in c$1&&c$1.error.code,m=c$1&&"token"in c$1,g$1=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let 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(E=>{E.status===200&&E.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(d.href);}return jsx("div",{className:"fk:w-full",children:m?jsx(ne,{variant:"success",children:jsxs(re,{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:[u==="not_exists"&&jsx(ne,{variant:"destructive",children:jsxs(re,{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?"})]})}),u==="unknown_error"||l?jsx(ne,{variant:"destructive",children:jsxs(re,{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(ne,{variant:"destructive",children:jsxs(re,{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":f,className:"fk:w-full",type:"submit",disabled:!!f,children:[f?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 pi({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:d$2}=qs(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(h=>h.json())),[c,l]=b$a(),f=new Date().getFullYear(),u=useLocation(),m=u.state?.from?.pathname??u.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 d$2||c||!a?jsx(Uo,{}):l.user?.id?jsx(Navigate,{replace:true,state:{from:u},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$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(Rn,{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:el({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 ",f]})]}),jsx(qo,{})]})})]})}function el({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 tl=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],ol={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},Qo=class e extends Error{code;constructor(t,o){super(o??ol[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,o){return new e(t,o)}};function Fn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:tl.includes(t)}function gi(e){if(Fn(e))return e.code}function vi({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),d=useRef(null),c=useLocation(),{projectId:l}=useParams(),f=e.find(m=>c.pathname.includes(`/${l}/${m.name}`))?.name,u=e.find(m=>c.pathname.includes(`/${l}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(d.current===null)return;let m=new ResizeObserver(()=>{n(d.current?.offsetHeight??0);});return m.observe(d.current),function(){m.disconnect();}},[f]),useEffect(()=>{let m=Math.floor(o/48)-2,g=e.slice(0,m);if(!g.find(h=>h.name===u)){let h=e.find(y=>y.name===u);g.pop(),h&&g.push(h);}let p=e.filter(h=>!g.includes(h));i(g),s(p);},[e,u,o]),f===void 0&&u?jsx(Navigate,{to:`${c.pathname}/${u}`}):jsx(a$7,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:d,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/*/${l}`,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 ml={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-TWMWLTCH.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 po(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=ml[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function wi({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=po("navbar.logo"),r=po("navbar.projectSelector"),i=po("navbar.search"),a=po("navbar.userNav"),s=t.find(u=>u.projectId===e)??t[0],{basePath:d,schema:c}=s,l=useNavigate();function f(u){startTransition(()=>{l(b$b(d,e,"desk","list",u.entityNamePlural)+`?id=${u.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-[3.5rem] fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:f,projectId:e,schema:c})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function Ci({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 Qo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:d$1}=t,c=d$2(),l=useLocation();return useEffect(()=>{if(s){let f=s.find(m=>m.isDefault)||s[0],u="";typeof localStorage<"u"&&(u=localStorage.getItem(`${a$h}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:u||f.name}});}},[l]),n?jsx(Uo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(wi,{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(vi,{apps:d$1,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(pi,{projectId:i??""})}function Si(e){return e?"cause"in e:false}function Dt(e){if(!e)return null;if(ServerError.is(e))return e;if(Si(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Ai(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Pt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Go(e){if(!e)return null;let t=El(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 El(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ei).map(({message:r})=>r);let t=Ai(e);if(t&&go(t))return [t];let o=Dt(e);if(o?.statusCode!==400)return [];let n=Pt(o.bodyText)??Sl(o)??Al(e);return n?Array.isArray(n.errors)?n.errors.filter(Ei).map(r=>r.message):typeof n.message=="string"&&go(n.message)?[n.message]:typeof n.error=="string"&&go(n.error)?[n.error]:[]:[]}function Sl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Al(e){if(!Si(e))return null;let{cause:t}=e,o=Ai(t);if(o&&go(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function Ei(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"&&go(o)}function go(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Bl=ApolloProvider,Ni=createContext(void 0);function Rt(){let e=useContext(Ni);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function zl(e){return new ErrorLink(({error:t})=>{let o=Go(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=Dt(t);if(n?.statusCode===400){let r=Pt(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:d}=r;if(typeof d=="string")i=d;else if(Array.isArray(s)){let[c]=s;if(c&&typeof c.message=="string"){let{message:l}=c;i=l;}}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 jl(e,t){return from([zl(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Hl(e,t){return new ApolloClient({link:jl(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Di({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(Ni.Provider,{value:r,children:jsx(Bl,{client:Hl(t,n),children:e})})}function Pi({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function Mn({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function ql({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ri({className:e,size:t="default",...o}){return jsxs(Mn,{children:[jsx(ql,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...o})]})}function Fi({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 Ii({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 $i({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 Mi({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 Li({className:e,variant:t="default",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...n})})}function _i({className:e,variant:t="outline",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...n})})}function ko({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 d(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{a(true),o(false),r(false);}}return jsx(Pi,{onOpenChange:s,open:t,children:jsx(Mn,{children:jsxs(Ri,{className:"sm:max-w-[425px]",children:[jsxs(Fi,{children:[jsx($i,{children:e.dialogTitle}),jsx(Mi,{children:e.dialogMessage})]}),jsxs(Ii,{children:[jsx(_i,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Li,{className:a$8({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:d,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var zi=createContext([]),ji=createContext(()=>{});function Gl(e,t){let o=t.type;switch(t._id||(t._id=Date.now().toString()),o){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(n=>n._id!==t._id);default:throw Error(`Unknown action: ${o}`)}}function Hi({children:e}){let[t,o]=useReducer(Gl,[]);return jsx(zi.Provider,{value:t,children:jsx(ji.Provider,{value:o,children:e})})}function qi(){return useContext(zi)}function ie(){return useContext(ji)}function ue(e){return e.dataType==="asset"?"global":e.scope}var Kl=["id","string"],ec=["date","datetime","duration","time"],tc=`_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 vo(e){return e?ue(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function Ui(e,t){return !e||!vo(e)?false:t?.name!==b$8.name||e.name!=="assets"}function On(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ji(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 ht(e){return Array.isArray(e)?e[0]??null:e??null}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
16
  `:"";return ` ${e}Connection {
@@ -17,30 +21,78 @@ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}
17
21
  }
18
22
  edges {
19
23
  `+o+` node {
20
- ${tc}
24
+ ${oa}
21
25
  }
22
26
  }
23
27
  }
24
- `}function _n(e){return e?.aggregate?.count?.nodes??0}function Yo(e,t=""){return ` ${e}Connection${t} {
28
+ `}function Hn(e){return e?.aggregate?.count?.nodes??0}function on(e,t=""){return ` ${e}Connection${t} {
25
29
  aggregate {
26
30
  count {
27
31
  nodes
28
32
  }
29
33
  }
30
34
  }
31
- `}function It(e,t,o){let n="(where: $where, limit: $limit, offset: $offset, sort: $sort)",r=$t(o,e),i=r?.name??e,a=r?.attributes??[],s=`$where: ${i}Where, $limit: Int, $offset: Int, $sort: [${i}Sort!]`,d=`Get${Qt(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 c=oe("global",a).join(`
32
- `),l=en(a),f=oe(["local"],a),u=f.reduce((v,x)=>`${v}
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}
33
85
  ${x} {
34
86
  _id
35
87
  default
36
88
  }
37
- `,""),m=f.reduce((v,x)=>`${v}
89
+ `,""),p=u.reduce((k,x)=>`${k}
38
90
  ${x} {
39
91
  _id
40
92
  default
41
93
  ${t}
42
94
  }
43
- `,""),g=t==="default"?u:m,p=l.reduce((v,x)=>`${v}
95
+ `,""),w=t==="default"?g:p,v=l.reduce((k,x)=>`${k}
44
96
  ${x} {
45
97
  _id
46
98
  originalFilename
@@ -51,196 +103,173 @@ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}
51
103
  width
52
104
  lqip
53
105
  }
54
- `,""),y=a.filter(v=>ue(v)==="relationship").reduce((v,x)=>{if(vo(x))return `${v}
55
- ${Qi(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.attributes.reduce((b,A)=>{let N=t==="default"?"":`${t}
56
- `;if(On(A))return `${b}
57
- ${A.name} {
58
- _id
59
- originalFilename
60
- mimeType
61
- path
62
- size
63
- height
64
- width
65
- lqip
66
- }
67
- `;if(ue(A)==="local")return `${b}
68
- ${A.name} {
69
- _id
70
- default
71
- ${N}
72
- }
73
- `;if(ue(A)==="relationship"){let _=find(propEq(A.relationship?.entity,"name"))(o),B=find(propEq(A.relationship?.field,"name"))(_?.attributes??[]),I=ue(B)==="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) {
74
109
  _id
75
- default
76
- ${N}}
77
- `:"";if(A.relationship?.mode==="single")return `${b}
78
- ${A.name} {
79
- ${A.relationship.field} ${I}}
80
- `;if(A.relationship?.field)return `${b}
81
- ${A.name} (limit: 25, offset: 0) {
82
- ${A.relationship.field} ${I}}
83
- `}return `${b}
84
- ${A.name}
85
- `},"");return `${Yo(x.name).trim()}${v}
86
- ${x.name} (limit: 25, offset: 0) { _id ${S??""}}
87
- `},"");return {queryEntityName:e,query:`query ${d}(${s}) {
88
- `+Yo(e)+` ${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} {
89
115
  _id
90
- ${c} ${g} ${p} ${y}}
116
+ _updatedAt
117
+ ${m} ${w} ${v} ${C}}
91
118
  }
92
- `}}function Ko(e,t,o,n){let i=$t(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=_n(o[`${e}Connection`]),s=o[e],d=(l,f)=>{let u=f.name;return l.slice(0,3).map(m=>{if(ue(f)!=="local")return m[u];let g=ht(m[u]);return g?.[t]??g?.default}).join(", ")},c=s.map(l=>{let{_id:f}=l,u=oe("global",i).reduce((h,y)=>({...h,[y]:l[y]}),{}),m=oe("local",i).reduce((h,y)=>{let v=ht(l[y]);return {...h,[y]:v?.[t]?v[t]:v?.default}},{}),g=en(i).reduce((h,y)=>({...h,[y]:ht(l[y])}),{}),p=oe(["relationship"],i).reduce((h,y)=>{let v=find(propEq(y,"name"))(i),x=v.relationship?.entity??"",E=find(propEq(x,"name"))(n),S=pc(E?.attributes??[]),b=S?.name??"",A=S?ue(S):"global",N=l[y];if(vo(v)){let I=Ji(l[`${y}Connection`]);return {...h,[y]:I}}if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);if(v.relationship?.mode==="multiple"){let I=Array.isArray(N)?N:[];return {...h,[y]:d(I,S)}}let _=ht(N);if(A==="global")return {...h,[y]:_?.[b]};let B=ht(_?.[b]);return {...h,[y]:B?.[t]??B?.default}},{});return {_id:f,...u,...m,...g,...p}});return {count:a,results:c}}function Xi(e,t,o,n){let i=$t(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=_n(o[`${e}Connection`]),d=o[e].map(c=>{let l=oe("global",i).reduce((g,p)=>({...g,[p]:{value:c[p],disabled:false,scope:"default",_id:""}}),{}),f=oe("local",i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=ht(c[p]);return {...g,[p]:{value:y?oc(y,t):null,disabled:!!(y&&y[t]===null&&ue(h)==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),u=en(i).reduce((g,p)=>({...g,[p]:{value:ht(c[p]),disabled:false,scope:"default",_id:""}}),{}),m=oe(["relationship"],i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=c[p],v=h.relationship?.mode==="single"?ht(y):y,x=v?._id,E=_n(c[`${p}Connection`]),S=vo(h)?Ji(c[`${p}Connection`]):v;return {...g,[p]:{count:E,_id:x,value:S,disabled:false,scope:t}}},{});return {...l,...f,...u,...m}});return {count:a,results:d}}function oc(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 Vn(e,t,o,n,r,i){let a=$t(n,e),s=a?.name??e,d=a?.attributes??[],c=wo(e);if(d.length===0)return "";let l=Bn(d,i),f=zn(d,l),u=rc(t,d,l,o),m=nc(t,d,l),g=ic(d,r,l),p=e,h=Hn(n,e,o);return `mutation ${`Update${Qt(e)}`}($where: ${s}Where) {
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) {
93
120
  update${c}(
94
121
  where: $where
95
- update: {${f}${u}${m}${g}
122
+ update: {${m}${l}${u}${g}
96
123
  }
97
124
  ) {
98
125
  ${p} {
99
126
  _id
100
- ${h} }
127
+ ${w} }
101
128
  }
102
129
  }
103
- `}function Bn(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=>ue(n)===e&&n.inputType!=="asset").map(n=>n.name)}function en(e){return e.filter(On).map(o=>o.name)}function zn(e,t,o="update"){let n=pick(oe("global",e),t);return toPairs(n).reduce((i,[a,s])=>{let d=find(propEq(a,"name"))(e),c=Array.isArray(s?.value)?null:s?.value??null,l=jn(d.dataType,c);return o==="update"?`${i}
104
- ${a}: { set: ${l} }`:`${i}
105
- ${a}: ${l}`},"")}function nc(e,t,o){let n=pick(en(t),o);return toPairs(n).reduce((a,[s,d])=>{let c=d.value,l=Zo(c?.path),f=c?.size?c.size:"null",u=Zo(c?.mimeType),m=Zo(c?.originalFilename),g=c?.height?c.height:"null",p=c?.width?c.width:"null",h=Zo(c?.lqip);return l?d.value?._id?`${a}
106
- ${s}: [{
107
- update: {
108
- node: {
109
- mimeType: { set: ${u} }
110
- originalFilename: { set: ${m} }
111
- path: { set: ${l} }
112
- size: { set: ${f} }
113
- height: { set: ${g} }
114
- width: { set: ${p} }
115
- lqip: { set: ${h} }
116
- }
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
+ }]
117
140
  }
118
- }]`:`${a}
119
- ${s}: [{
120
- create: {
121
- node: {
122
- _id: ${me(`${e}:${s}`)}
123
- mimeType: ${u}
124
- originalFilename: ${m}
125
- path: ${l}
126
- size: ${f}
127
- height: ${g}
128
- width: ${p}
129
- lqip: ${h}
130
- }
141
+ `:"",l=c?` {
142
+ connect: [{
143
+ where: {
144
+ node: {
145
+ _id: { eq: ${pe(c)} }
146
+ }
147
+ }
148
+ }]
131
149
  }
132
- }]`:a},"")}function rc(e,t,o,n){let r=pick(oe("local",t),o);return toPairs(r).reduce((s,[d,c])=>{let l=find(propEq(d,"name"))(t),{dataType:f}=l,u=c.disabled||Array.isArray(c.value)?"null":jn(f,c.value);return c._id?`${s}
133
- ${d}: [{
150
+ `:"";return `${s}
151
+ ${a}: [
152
+ ${m}${l} ]`},"")}function xc(e,t){let o=pick(Yt(e),t);return toPairs(o).reduce((i,[s,a])=>{let f=qn(a.value);return f?`${i}
153
+ ${s}: {
154
+ connect: [{
155
+ where: {
156
+ node: {
157
+ _id: { eq: ${pe(f)} }
158
+ }
159
+ }
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}: [{
134
163
  update: {
135
164
  node: {
136
- ${n}: { set: ${u} }
165
+ ${n}: { set: ${l} }
137
166
  }
138
167
  }
139
- }]`:u?`${s}
140
- ${d}: [{
168
+ }]`:l?`${a}
169
+ ${f}: [{
141
170
  create: {
142
171
  node: {
143
- _id: ${me(`${e}:${d}`)}
144
- _type: "${f}"
145
- ${n}: ${u}
172
+ _id: ${pe(`${e}:${f}`)}
173
+ _type: "${m}"
174
+ ${n}: ${l}
146
175
  }
147
176
  }
148
- }]`:s},"")}function ic(e,t,o){let n=pick(oe("relationship",e),o);return toPairs(n).reduce((a,[s,d])=>{let c=find(propEq(s,"name"))(e),{inputType:l,relationship:f}=c;if(l==="relationship"&&f?.mode==="single"){let u=t[s]._id??"",m=d._id??"";if(u===m)return a;let g=u?` {
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?` {
149
178
  disconnect: [{
150
179
  where: {
151
180
  node: {
152
- _id: { eq: ${me(u)} }
181
+ _id: { eq: ${pe(l)} }
153
182
  }
154
183
  }
155
184
  }]
156
185
  }
157
- `:"",p=m?` {
186
+ `:"",p=u?` {
158
187
  connect: [{
159
188
  where: {
160
189
  node: {
161
- _id: { eq: ${me(m)} }
190
+ _id: { eq: ${pe(u)} }
162
191
  }
163
192
  }
164
193
  }]
165
194
  }
166
- `:"";return `${a}
167
- ${s}: [
168
- ${g}${p} ]`}if(l==="relationship"&&f?.mode==="multiple"){if(f.entity==="_asset")return `${a}${ac(s,t[s],d)}`;let u=d.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} {
169
198
  node: {
170
- _id: { eq: ${me(v)} }
199
+ _id: { eq: ${pe(E)} }
171
200
  }
172
201
  }
173
- `,""),g=(d.relationships?.connect??[]).map(y=>me(y._id)).join(", "),p=u?`disconnect: {
202
+ `,""),g=(f.relationships?.connect??[]).map(v=>pe(v._id)).join(", "),p=l?`disconnect: {
174
203
  where: {
175
204
  OR: [
176
- ${u} ]
205
+ ${l} ]
177
206
  }
178
207
  }
179
- `:"",h=g?`connect: {
208
+ `:"",w=g?`connect: {
180
209
  where: {
181
210
  node: {
182
211
  _id: { in: [${g}] }
183
212
  }
184
213
  }
185
214
  }
186
- `:"";return !p&&!h?a:`${a}
187
- ${s}: {
188
- ${p} ${h} }`}return `${a}
189
- `},"")}function ac(e,t,o){let r=(o.relationships?.connect??[]).map((m,g)=>({...m,sortOrder:m.sortOrder??g})),i=r.map(m=>m._id),a=sc(t),s=uniq(o.relationships?.disconnect??[]).filter(m=>m&&!i.includes(m)),d=r.filter(m=>a[m._id]===void 0),c=r.filter(m=>{let g=a[m._id];return g!==void 0&&g!==m.sortOrder}),l=lc(s),f=cc(d),u=fc(c);return !l&&!f&&!u?"":`
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?"":`
190
219
  ${e}: [
191
- ${l}${f}${u} ]`}function sc(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 lc(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?"":` {
192
221
  disconnect: [
193
222
  ${e.reduce((o,n)=>`${o} {
194
- where: { node: { _id: { eq: ${me(n)} } } }
223
+ where: { node: { _id: { eq: ${pe(n)} } } }
195
224
  }
196
225
  `,"")} ]
197
226
  }
198
- `}function cc(e){return e.length===0?"":` {
227
+ `}function Nc(e){return e.length===0?"":` {
199
228
  connect: [
200
- ${Gi(e)} ]
229
+ ${la(e)} ]
201
230
  }
202
- `}function Gi(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
203
- where: { node: { _id: { eq: ${me(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)} } } }
204
233
  edge: { sortOrder: ${r} }
205
234
  }
206
- `},"")}function fc(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
235
+ `},"")}function Pc(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
207
236
  update: {
208
- where: { node: { _id: { eq: ${me(n._id)} } } }
237
+ where: { node: { _id: { eq: ${pe(n._id)} } } }
209
238
  edge: { sortOrder: { set: ${i} } }
210
239
  }
211
240
  }
212
- `},"")}function jn(e,t){return ec.includes(e)?t?.toString()?me(t.toString()):null:Kl.includes(e)?me(t?.toString()??"null"):t?.toString()??null}function Zo(e){return e?me(e):"null"}function me(e){return JSON.stringify(e)}function Hn(e,t,o){let n=$t(e,t),r=n?.attributes??[],i=oe("global",r),a=oe("local",r),s=oe("relationship",r),d=i.reduce((c,l)=>`${c}${l}
213
- `,"");return d+=a.reduce((c,l)=>`${c} ${l} {
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} {
214
243
  _id
215
244
  ${o}
216
245
  }
217
- `,""),d+=s.reduce((c,l)=>{let f=find(propEq(l,"name"))(r),u=f?.relationship?.mode??"single";if(vo(f))return `${c}${Qi(l,Ui(f,n))}`;let m=f?.relationship?.entity??"",p=find(propEq(m,"name"))(e)?.attributes??[],h=f?.relationship?.field??"[invalid_relationship_field_name_in_schema]",y=find(propEq(h,"name"))(p),v=ue(y),x="";if(u==="single"&&(v==="global"&&(x=` ${l} {
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} {
218
247
  _id
219
- ${h}
248
+ ${w}
220
249
  }
221
- `),v==="local"&&(x=` ${l} {
250
+ `),E==="local"&&(C=` ${d} {
222
251
  _id
223
- ${h} {
252
+ ${w} {
224
253
  _id
225
254
  default
226
255
  ${o}
227
256
  }
228
257
  }
229
- `)),u==="multiple"&&p.length){let E=p.reduce((S,b)=>{if(ue(b)==="local")return `${S} ${b.name} {
258
+ `)),l==="multiple"&&p.length){let k=p.reduce((x,P)=>{if(ne(P)==="local")return `${x} ${P.name} {
230
259
  _id
231
260
  default
232
261
  ${o}
233
262
  }
234
- `;if(ue(b)==="relationship"){let A=o==="default"?"":`${o}
235
- `,N=find(propEq(b.relationship?.entity,"name"))(e),_=find(propEq(b.relationship?.field,"name"))(N?.attributes??[]),B=ue(_)==="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"?`{
236
265
  _id
237
266
  default
238
- ${A}}
239
- `:"";if(b.relationship?.mode==="single")return `${S} ${b.name} {
240
- ${b.relationship.field} ${B}}
241
- `;if(b.relationship?.field)return `${S} ${b.name} (limit: 25, offset: 0) {
242
- ${b.relationship.field} ${B}}
243
- `}return On(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} {
244
273
  _id
245
274
  originalFilename
246
275
  mimeType
@@ -250,10 +279,10 @@ ${Gi(e)} ]
250
279
  width
251
280
  lqip
252
281
  }
253
- `:`${S} ${b.name}
254
- `},"");x=Yo(l)+` ${l} (limit: 25, offset: 0) {
255
- ${E} }
256
- `;}return `${c}${x}`},""),d}function bo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=wo(n?.plural??""),a=dc(r,o),s=`Delete${Qt(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) {
257
286
  delete_assets(
258
287
  where: $where
259
288
  ) {
@@ -261,59 +290,60 @@ ${E} }
261
290
  relationshipsDeleted
262
291
  }
263
292
  }
264
- `:`mutation ${s}($where: ${e}Where) {
293
+ `:`mutation ${a}($where: ${e}Where) {
265
294
  delete${i}(
266
295
  where: $where
267
- ${a?` delete: {
268
- ${a}
296
+ ${s?` delete: {
297
+ ${s}
269
298
  }
270
299
  `:""} ) {
271
300
  nodesDeleted
272
301
  relationshipsDeleted
273
302
  }
274
303
  }
275
- `}function dc(e,t){return oe("local",e).reduce((r,i)=>`${r}
304
+ `}function Rc(e,t){return ae("local",e).reduce((r,i)=>`${r}
276
305
  ${i}: [{
277
306
  where: {
278
307
  node: {
279
- _id: { eq: ${me(`${t}:${i}`)} }
308
+ _id: { eq: ${pe(`${t}:${i}`)} }
280
309
  }
281
310
  }
282
- }]`,"")}function qn(e,t,o,n){let r=$t(t,e),i=r?.attributes??[],a=wo(r?.plural??"");if(i.length===0)return "";let s=Bn(i,o),d=zn(i,s,"create"),c=uc(i,s,"default",n),l=mc(i,s),f=e,u=Hn(t,f,"default");return `mutation ${`Create${Qt(e)}`} {
283
- 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}(
284
313
  input: [{
285
- _id: ${me(n)} ${d} ${c}
286
- ${l}
314
+ _id: ${pe(n)} ${f} ${c}
315
+ ${d}
316
+ ${m}
287
317
  }]
288
318
  ) {
289
- ${f} {
319
+ ${l} {
290
320
  _id
291
321
  ${u} }
292
322
  }
293
323
  }
294
- `}function uc(e,t,o,n){let r=pick(oe("local",e),t);return toPairs(r).reduce((s,[d,c])=>{if(!c?.value)return s;let l=find(propEq(d,"name"))(e),f=Array.isArray(c.value)?"null":jn(l.dataType,c.value);return `${s}
295
- ${d}: {
324
+ `}function Fc(e,t,o,n){let r=pick(ae("local",e),t);return toPairs(r).reduce((a,[f,c])=>{if(c?.value===void 0||c.value===null||c.value==="")return a;let d=find(propEq(f,"name"))(e),m=Array.isArray(c.value)?"null":Qn(d.dataType,c.value);return `${a}
325
+ ${f}: {
296
326
  create: [{
297
327
  node: {
298
- _id: ${me(`${n}:${d}`)}
299
- _type: "${l.dataType}"
300
- ${o}: ${f}
328
+ _id: ${pe(`${n}:${f}`)}
329
+ _type: "${d.dataType}"
330
+ ${o}: ${m}
301
331
  }
302
332
  }]
303
- }`},"")}function mc(e,t){let o=pick(oe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let d=find(propEq(a,"name"))(e),{inputType:c,relationship:l}=d;if(c==="relationship"&&l?.mode==="single"){let m=`connect: [{
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: [{
304
334
  where: {
305
335
  node: {
306
- _id: { eq: ${me(s._id??"")} }
336
+ _id: { eq: ${pe(a._id??"")} }
307
337
  }
308
338
  }
309
339
  }]
310
340
  `;return `${i}
311
- ${a}: {
312
- ${m} }`}let f=c==="relationship"&&l?.mode==="multiple",u=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(f&&u){let m=s.relationships?.connect??[];if(l?.entity==="_asset"){let h=Gi(m.map((y,v)=>({...y,sortOrder:y.sortOrder??v})));return `${i}
313
- ${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}: {
314
344
  connect: [
315
- ${h} ]
316
- }`}let g=m.map(h=>me(h._id)).join(", "),p=g?`connect: {
345
+ ${w} ]
346
+ }`}let g=u.map(w=>pe(w._id)).join(", "),p=g?`connect: {
317
347
  where: {
318
348
  node: {
319
349
  _id: { in: [${g}] }
@@ -321,77 +351,85 @@ ${h} ]
321
351
  }
322
352
  }
323
353
  `:"";return `${i}
324
- ${a}: {
354
+ ${s}: {
325
355
  ${p} }`}return `${i}
326
- `},"")}function pc(e){return e.find(t=>t.isPrimary)??e[0]}function Wi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, limit: $limit, offset: $offset, sort: $sort)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $limit: Int, $offset: Int, $sort: [${t}Sort!]`,d=i?.plural??"",c=`GetRelated${Qt(d||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let l=oe("global",a).join(`
327
- `),f=oe(["local"],a),u=f.reduce((y,v)=>`${y}
328
- ${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} {
329
359
  _id
330
360
  default
331
361
  }
332
- `,""),m=f.reduce((y,v)=>`${y}
333
- ${v} {
362
+ `,""),u=m.reduce((C,k)=>`${C}
363
+ ${k} {
334
364
  _id
335
365
  default
336
366
  ${o}
337
367
  }
338
- `,""),g=o==="default"?u:m,h=a.filter(y=>ue(y)==="relationship").reduce((y,v)=>{let E=find(propEq(v.relationship?.entity,"name"))(n)?.attributes.reduce((S,b)=>{let A=o==="default"?"":`${o}
339
- `;if(ue(b)==="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}
340
393
  ${b.name} {
341
394
  _id
342
395
  default
343
- ${A}}
344
- `;if(ue(b)==="relationship"){let N=find(propEq(b.relationship?.entity,"name"))(n),_=find(propEq(b.relationship?.field,"name"))(N?.attributes??[]),B=ue(_)==="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"?`{
345
398
  _id
346
399
  default
347
- ${A}}
348
- `:"";if(b.relationship?.mode==="single")return `${S}
400
+ ${L}}
401
+ `:"";if(b.relationship?.mode==="single")return `${D}
349
402
  ${b.name} {
350
- ${b.relationship.field} ${B}}
351
- `;if(b.relationship?.field)return `${S}
403
+ ${b.relationship.field} ${q}}
404
+ `;if(b.relationship?.field)return `${D}
352
405
  ${b.name} (limit: 25, offset: 0) {
353
- ${b.relationship.field} ${B}}
354
- `}return `${S}
406
+ ${b.relationship.field} ${q}}
407
+ `}return `${D}
355
408
  ${b.name}
356
- `},"");return `${y}
357
- ${v.name} (limit: 25, offset: 0) { _id ${E??""}}
358
- `},"");return {queryEntityName:d,query:`query ${c}(${s}) {
359
- `+Yo(e,"(where: $where)")+` ${d}${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} {
360
413
  _id
361
- ${l} ${g} ${h} }
414
+ _updatedAt
415
+ ${d} ${g} ${w} ${E} }
362
416
  }
363
- `}}function Un(){return v4()}function Zi(e,t=Un()){let{attributes:o}=a$e,n=wo(a$e.plural),r=Bn(o,e),i=zn(o,r,"create"),a=a$e.plural,s=Hn([a$e,b$8],a,"default");return `mutation ${`Create${Qt(a$e.plural)}`} {
364
- create${n}(
365
- input: [{
366
- _id: ${me(t)} ${i} }]
367
- ) {
368
- ${a} {
369
- _id
370
- ${s} }
371
- }
372
- }
373
- `}var wo=e=>e.charAt(0).toUpperCase()+e.slice(1);function Qt(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(wo).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 Ki(){let e=useApolloClient();return async t=>{let o=Un(),n=Zi(t,o);return await e.mutate({mutation:gql`
374
- ${n}
375
- `}),yc(t,o)}}function yc(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 rt(){let[e,t]=useState(false),[o,n]=useState(gql`
376
- mutation updateEntity($any: Any) {
377
- any
378
- }
379
- `),[r,i]=useState({}),[a,{data:s,loading:d,error:c}]=useMutation(o,r),l=Dt(c),{isProjectDisabled:f,isProjectReadOnly:u}=(()=>{if(l?.statusCode===403){let m=Pt(l.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:d,error:c,isProjectDisabled:f,isProjectReadOnly:u}]}function Qn({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,a]=rt(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{c();},0),jsx(Fragment,{});let d$1={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:()=>c()};function c(){let l=e.payload.entityId,f=bo(e.payload.entityName,n,l);return new Promise(u=>{i(gql`
380
- ${f}
381
- `),a({variables:{where:{_id:{eq:l}}},update(m){m.evict({id:l});},onCompleted:()=>{toast.success("Item successfully deleted."),u();}}),r(true);})}return jsx(ko,{options:d$1})}var Ec=Drawer.Portal;function oa({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function Sc({...e}){return jsx(Ec,{...e})}function Ac({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 na({className:e,children:t,...o}){return jsxs(Sc,{children:[jsx(Ac,{}),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 ra({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 ia({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 aa({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Mt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[d,c]=useState(false),l=n*(50/n),f=useCallback(()=>{(!t||t())&&(c(false),setTimeout(()=>{a();},150));},[t,a,c]),u=useCallback(m=>{m.key==="Escape"&&r&&f();},[f,r]);return useEffect(()=>{c(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",u,false),()=>{globalThis.document.removeEventListener("keydown",u,false);}),[u]),jsx(oa,{direction:"right",dismissible:false,onClose:()=>{f();},open:d,children:jsxs(na,{style:r?{}:{maxWidth:`calc(100% - ${l.toString()}px)`},children:[jsxs(ra,{className:"fk:px-10",children:[jsx(ia,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(aa,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:f,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 ca=createContext({isDirty:false,setIsDirty:e=>{}}),fa=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(ca.Provider,{value:n,children:e})};function Gt(){return useContext(ca)}function Wt({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function Zt({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}function Yt(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 ba({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:d}=useParams(),c$1=ie(),l=d$2(),{relationships:f$1}=c$2(),[u,m$1]=useState(false),g$1=useRef(null),p=useRef(null),h$2=useRef(null),[y,v]=useState(null),[x,E]=useState(false),[S,b]=useState(false),A=useId(),N=useId();Yt(p,m$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let w=f$1[N]?.connect;if(!w||h$2.current===w._id)return;let k=Uc(w.value);if(!k)return;let R=n(i$1);h$2.current=w._id,v(null),r(i$1,{...R,value:k});},[n,i$1,N,f$1,r]);function _(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 R=w.split("/");if(R.length===2){let[,P]=R;return P.includes("svg")?"svg":P.toLowerCase()}}function B(w,k){if(w&&w.includes(".")){let P=w.split(".").pop();if(P)return P.toLowerCase()}let R=_(k);return R||"file"}async function I(w,k){if(!w)return;let R=Wn("4MB");if(w.size>(R??0)){toast.error("File size too big (max 4MB)");return}let P=w.type.startsWith("image/");if(h$2.current=null,P){let U=new FileReader;U.onload=G=>{let ae=new Image;v(G.target?.result),ae.onload=function(){r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,width:ae.width,height:ae.height}});},ae.src=U.result;},U.readAsDataURL(w);}else v(null);b(true);try{let G=await(await fetch(c$5(d).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,...P?{}:{width:void 0,height:void 0}}});}catch(U){console.error(U),v(null),r(i$1,{...n(i$1)?.value,value:{_id:k?.value?._id}});}finally{b(false);}}function j(w){w.stopPropagation(),h$2.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function q(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function F(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,R=h$2.current??Jc(k),P=R?{_id:R,value:k}:void 0;l({type:"setRelationship",payload:{[N]:{connect:P,disconnect:[]}}}),window.setTimeout(()=>{c$1({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:P,relationshipId:N,mode:"single"}});},0);}function $(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:A,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${i$1}`,"aria-expanded":u,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${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(),E(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),E(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),E(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),E(false);let R=k.dataTransfer.files&&k.dataTransfer.files[0];I(R,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:A,onClick:F,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-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&&!u?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=w.value?.value,R=k?.mimeType,P=k?.path||"";if(!!(R&&R.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(P)))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=B(k.originalFilename,k.mimeType),ae=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,...ae||{}})})})(),Wn((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:F,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=>$(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=>q(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:j,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!u&&(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}),u&&(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(Wt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:u&&(!!w.value?.value?.path||!!y),children:jsx(Zt,{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,R=k?.mimeType,P=k?.path||"";if(!!(R&&R.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(P)))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=B(k.originalFilename,k.mimeType),ae=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,...ae||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Wn(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 R=k.currentTarget.files&&k.currentTarget.files[0];I(R,w.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function Uc(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 Jc(e){return !e?._id||e._id.includes(":")?"":e._id}function wa({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,d=useId();function c$1(f,u){let m=f.currentTarget.value,g;m===""?g="":(g=s==="float"?parseFloat(m):parseInt(m,10),isNaN(g)&&(g="")),o(n,{...u,value:g});}function l(f,u){o(n,{...u,disabled:f});}return jsx(c,{control:e$1,name:n,render:({field:f$1})=>jsxs(e,{children:[jsx(f,{htmlFor:d,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$6,{className:`fk:w-full fk:mt-[0.1875rem] ${!f$1.value?.scope||f$1.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||f$1.value?.disabled,id:d,...f$1,onChange:u=>{c$1(u,f$1.value);},step:s==="float"?"any":"1",type:"number",value:f$1.value?.value??""})}),jsx(b$2,{checked:f$1.value?.disabled??false,onChange:u=>{l(u,f$1.value);},scope:f$1.value?.scope}),jsx(i,{})]})})}function Kt({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function eo({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function bt({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 xa({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let d=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",d.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",d.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",d.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",d.nav),button_previous:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",d.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",d.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)",d.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",d.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",d.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",d.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",d.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",d.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",d.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",d.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",d.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",d.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",d.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",d.range_start),range_middle:a$4("fk:rounded-none",d.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",d.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",d.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",d.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",d.disabled),hidden:a$4("invisible",d.hidden),...t},components:{Root:({className:c,rootRef:l,...f})=>jsx("div",{"data-slot":"calendar",ref:l,className:a$4(c),...f}),Chevron:({className:c,orientation:l,...f})=>l==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",c),...f}):l==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",c),...f}):jsx(ChevronDownIcon,{className:a$4("size-4",c),...f}),DayButton:Kc,WeekNumber:({children:c,...l})=>jsx("td",{...l,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:c})}),...a},...s})}function Kc({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 Ea({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,d=useId();function c$1(u,m){n(r,{...m,value:u?u.toISOString():""});}function l(u,m){n(r,{...m,disabled:u});}function f$1(u){u.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:u})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:d,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(Kt,{children:[jsx(eo,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!u.value?.value&&"fk:text-muted-foreground",!u.value?.scope||u.value.scope==="default"?"fk:mb-3":""),disabled:a===false||u.value?.disabled,id:d,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:u.value?.value?format(new Date(u.value.value),"PPP")+" at "+format(new Date(u.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[u.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:m=>{m.stopPropagation(),f$1(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(bt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(xa,{mode:"single",selected:u.value?.value?new Date(u.value.value):void 0,onSelect:m=>c$1(m,u.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:m=>{let g=m.target.value,[p,h]=g.split(":"),y=u.value?.value?new Date(u.value.value):new Date;y.setHours(parseInt(p)),y.setMinutes(parseInt(h)),n(r,{...u.value,value:y.toISOString()});},type:"time",value:u.value?.value?format(new Date(u.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:u.value?.disabled??false,onChange:m=>{l(m,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function xe(e){return e??null}var Yn=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=xe(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=xe(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=xe(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");}}]),Sa=Command.configure({suggestion:{items:()=>Yn,render:renderItems}});var Ta=[{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"}],Na=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],Da=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ta.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Na.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(Kt,{modal:true,open:e,onOpenChange:t,children:[jsx(eo,{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(bt,{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"}),Ta.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"}),Na.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 Tf(e){try{return new URL(e),!0}catch{return false}}function Nf(e){if(Tf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Ra=({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(bt,{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=Nf(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 Ia=[{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=xe(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=xe(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=xe(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=xe(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=xe(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")}],$a=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ia.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:Ia.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 La=()=>{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=xe(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=xe(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=xe(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=xe(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 Co({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 Wf=()=>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"})]}),Oa=Wf;function or({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 fd=[{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 rr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:fd.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 Ba({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(c,l)=>{let f=await fetch(c,l);if(f.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return f},onError:c=>{c.message!=="FK_AI_RATE_LIMIT"&&toast.error(c.message);}}),d=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[d&&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(yd,{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(Co,{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(Oa,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:d?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let c=t.state.selection.content(),l=t.storage.markdown.serializer.serialize(c.content);a(l,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:d?jsx(or,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(rr,{onSelect:(c,l)=>a(c,{body:{option:l}})})})]})]}):null}function ar({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(Ba,{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(Co,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Ld=[...a,Sa];function ja(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 _d(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(ja(o))return o}catch{return}}if(ja(e))return e}function sr({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[d,c$1]=useState(false),[l,f$1]=useState(false),[u,m]=useState(false),[g$1,p]=useState(false),h$1=useDebouncedCallback((x,E)=>{let S=x.getJSON();n(r,{...E,value:JSON.stringify(S)});},300);function y(x,E){n(r,{...E,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:(E,S)=>handleCommandNavigation(S)},handlePaste:(E,S)=>handleImagePaste(E,S,v),handleDrop:(E,S,b,A)=>handleImageDrop(E,S,A,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:Ld,initialContent:_d(x.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:E})=>{h$1(E,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:Yn.map(E=>jsxs(EditorCommandItem,{value:E.title,onCommand:S=>E.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:E.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:E.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:E.description})]})]},E.title))})]}),jsxs(ar,{open:d,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx($a,{open:l,onOpenChange:f$1}),jsx(g$3,{orientation:"vertical"}),jsx(Ra,{open:u,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(La,{}),jsx(g$3,{orientation:"vertical"}),jsx(_a,{}),jsx(g$3,{orientation:"vertical"}),jsx(Da,{open:g$1,onOpenChange:p})]})]},`${r}:${x.value?.scope??t.scope}:${String(x.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:x.value?.disabled??false,onChange:E=>{y(E,x.value);},scope:x.value?.scope}),jsx(i,{})]})})}var Od=["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 Vd(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??Od.join(",");a.accept=s,a.multiple=r,a.style.display="none",document.body.appendChild(a);try{let d=await new Promise(u=>{a.onchange=()=>u(a.files),a.click();});if(!d||d.length===0)return [];let c=[];for(let u of Array.from(d)){if(u.size>i){toast.error(`File size too big (max ${(i/(1024*1024)).toFixed(0)}MB): ${u.name}`);continue}c.push(u);}let l=c$5(o).upload,f=await Promise.all(c.map(async u=>{let m=await Bd(u),g=await fetch(l,{method:"POST",headers:{"Content-Type":u.type||"application/octet-stream"},body:u});if(!g.ok)throw new Error(`Upload failed for ${u.name}`);let p=await g.json(),h={pathname:p.pathname,lqip:p.lqip,originalFilename:u.name,size:u.size,mimeType:u.type,width:m?.width,height:m?.height},y=t?await t(h,o):zd(h);return {...h,_id:y._id,asset:y}}));return f.length>0&&toast.success(`Uploaded ${f.length} file${f.length>1?"s":""}`),f}catch(d){return console.error(d),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(a);}}async function Bd(e){return e.type.startsWith("image/")?new Promise(o=>{let n=new FileReader;n.onload=()=>{let r=new Image;r.onload=()=>{o({width:r.width,height:r.height});},r.onerror=()=>o(null),r.src=n.result;},n.onerror=()=>o(null),n.readAsDataURL(e);}):null}function Ao(){let e=Ki();return async t=>Vd(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 zd(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 ur({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:d}=n,{projectId:c$1}=useParams(),l=ie(),f$1=d$2(),{relationships:u}=c$2(),m=Ao(),g$1=useId(),p=useId(),h$1=useRef(null),y=useRef([]),v$1=useRef(null),x=useRef([]),E=useRef(""),[S,b]=useState(false),A=useMemo(()=>Zd(t.value),[t.value]),[N,_]=useState(A);Yt(h$1,b),useEffect(()=>{let F=Et(A);y.current=A.map(M=>M._id),x.current=[],_(M=>{let $=Et(M);return F===""&&$!==""&&E.current===$||$===F?M:(E.current=F,A)});},[A]),useEffect(()=>{let F=u[p]?.connect;if(!F)return;let M=F.map((R,P)=>Ja(R.value,R.sortOrder??P)).filter(R=>!!R),$=Et(M),w=Et(N),k=v$1.current;k===w&&$!==k||(v$1.current=null,$!==w&&_(M));},[p,u,N]),useEffect(()=>{let F=Et(N);if(E.current===F)return;let M=N.map((k,R)=>({_id:k._id,sortOrder:R,value:{...k,sortOrder:R}})),$=N.map(k=>k._id),w=x.current.filter(k=>!$.includes(k));E.current=F,f$1({type:"setRelationship",payload:{[p]:{connect:M,disconnect:w}}}),r(i$1,{...t,relationships:{connect:M,disconnect:w},value:N});},[f$1,t,i$1,p,N,r]);function B(F){F.preventDefault(),F.stopPropagation(),l({type:"EditRelationship",payload:{connectedEntitiesCount:N.length,entityName:d?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function I(F){F.preventDefault(),F.stopPropagation();let M=await m({projectId:c$1,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});_($=>{let w=new Set($.map(P=>P._id)),k=M.map((P,U)=>({...P.asset,sortOrder:$.length+U})).filter(P=>!w.has(P._id)),R=fr([...$,...k]);return v$1.current=Et(R),R});}function j(F){_(M=>{let $=fr(M.filter(w=>w._id!==F));return y.current.includes(F)&&!x.current.includes(F)&&(x.current=[...x.current,F]),v$1.current=Et($),$});}function q(F,M){_($=>{let w=$.findIndex(G=>G._id===F),k=w+M;if(w<0||k<0||k>=$.length)return $;let R=[...$],[P]=R.splice(w,1);if(!P)return $;R.splice(k,0,P);let U=fr(R);return v$1.current=Et(U),U});}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:F=>{F.preventDefault(),F.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&&N.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[N.length," ",N.length===1?"asset":"assets"," selected"]}):N.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[N.slice(0,8).map(F=>jsx(Gd,{asset:F},F._id)),!S&&N.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:["+",N.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:F=>{F.preventDefault(),F.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(Wt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:b,open:S,children:jsx(Zt,{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:F=>{I(F);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),N.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:N.map((F,M)=>jsx(Wd,{asset:F,index:M,isFirst:M===0,isLast:M===N.length-1,moveAsset:q,removeAsset:j},F._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Gd({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 Wd({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 Zd(e){return Array.isArray(e)?e.map((t,o)=>Ja(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Et(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function fr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Ja(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 Ga({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function Do({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=d(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},i={boolean:a$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:Ga},a=e.map(l=>{let f=(l.inputType==="relationship"&&l.relationship?.entity==="_asset"?"asset":void 0)??l.previewType??r[l.inputType],u=n("previewFields",[f])?.[0]?.component??i[f]??i.text;if(l.isHidden)return null;let m=f==="tags";return {accessorKey:l.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:l.label}),cell:({row:g})=>jsx(u,{value:g.getValue(l.name)}),enableSorting:false,enableHiding:true,size:l.options?.size??150}}).filter(l=>l!==null),s={id:"actions",cell:({row:l})=>o?o(l):null,size:80},d$1={id:"select",cell:({row:l,table:f})=>jsx(a$d,{"aria-label":"Select row",checked:l.getIsSelected(),onCheckedChange:u=>{f.toggleAllPageRowsSelected(false),l.toggleSelected(!!u);}}),enableSorting:false,enableHiding:false,size:50},c={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:f=>{l.toggleAllPageRowsSelected(!!f);}}),cell:({row:l})=>jsx(a$d,{"aria-label":"Select row",checked:l.getIsSelected(),onCheckedChange:f=>{l.toggleSelected(!!f);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[d$1]:[],...t==="multiple"?[c]:[],...o?[s]:[],...a]}function lu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function Po({classNames:e,columns:t,data:o,initialSelectionState:n$1,onEntitySelectionChange:r,onScroll:i,pageSize:a,rowHeightEstimate:s,rowAdditionState:d,rowDeletionState:c,toolbarComponent:l$1}){let f=useRef(null),{schemaErrorMessage:u}=Rt(),[m,g]=useState(n$1??{}),[p,h]=useState({}),[y,v]=useState([]),[x,E]=useState([]);useEffect(()=>{if(!n$1)return;let I=Object.keys(m).sort().join(","),j=Object.keys(n$1).sort().join(",");I!==j&&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:B,onSortingChange:E,onColumnFiltersChange:v,onColumnVisibilityChange:h,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:I=>I._id,manualPagination:true,meta:{getRowBackground:I=>cu(I,c,d)}}),{rows:b}=S.getRowModel(),A=useVirtualizer({count:b.length,estimateSize:()=>s??lu(e?.row)??45,getScrollElement:()=>f.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?I=>I.getBoundingClientRect().height:void 0,overscan:5}),N=A.getVirtualItems(),_=A.getTotalSize();function B(I){let j=Object.keys(typeof I=="function"?I(m):I);g(I),r?.(j);}return u?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:[l$1&&l$1(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:f,children:[jsx(i$1,{className:"fk:grid",children:S.getHeaderGroups().map(I=>jsx(l,{className:"fk:flex fk:w-full",children:I.headers.map(j=>jsx(m$1,{className:a$4("fk:flex fk:items-center",j.column.id==="actions"&&"fk:pl-0"),colSpan:j.colSpan,style:j.getSize()?{width:`${j.getSize().toString()}px`}:{},children:j.isPlaceholder?null:flexRender(j.column.columnDef.header,j.getContext())},j.id))},I.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${_.toString()}px`},children:N.length?N.map(I=>{let j=b[I.index];return jsx(l,{className:`${S.options.meta.getRowBackground(j)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":I.index,"data-state":j.getIsSelected()&&"selected",ref:A.measureElement,style:{transform:`translateY(${I.start.toString()}px)`},children:j.getVisibleCells().map(q=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",q.column.id==="actions"&&"fk:pl-0!"),style:{width:q.column.getSize()},children:flexRender(q.column.columnDef.cell,q.getContext())},q.id))},I.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function cu(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 Ya({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 xu=25;function gr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:d,setValue:c$1}){let[l,f$1]=useState(false),u=useRef(null);Yt(u,f$1);let[m,g$1]=useState([]),{name:p,label:h$1,options:y,relationship:v}=a,x=v?.entity??p,E=ie(),S=d$2(),{relationships:b}=c$2(),A=useId(),N=useId(),_=find(propEq(x,"name"))(s),B=_?.attributes??[],j=find(propEq(r,"name"))(s)?.name??"",q,F=B.find(L=>L.relationship?.entity===j);F&&(q=F.name);let M=Su(B),$=useMemo(()=>o.value?Au({data:o.value,defaultScope:t,relationshipEntitySchema:_,scope:d}):[],[t,o,M,_,d]),w=Wi({attributeName:p,relatedEntityName:x,scope:d,schema:s}),k=m.length?m.slice(0,12).map(L=>L[M]):[],[R,{loading:P,data:U}]=useLazyQuery(gql`
382
- ${w.query}
383
- `),G=Do({attributesSchema:_?.attributes??[],actionsComponent:L=>Eu({appDispatch:S,relationshipId:N,relationships:b,row:L,setRows:g$1})});useEffect(()=>{g$1($),o.value!==""&&S({type:"setRelationship",payload:{[N]:{connect:[],disconnect:[]}}});},[S,U,$,N,o,d]),useEffect(()=>{c$1(p,{...o,relationships:b[N]});},[o,b,N,c$1,p]),useEffect(()=>{let _e=(b[N]?.connect??[]).map(({value:Oe})=>Oe);g$1(uniqBy(prop("_id"),[..._e,...$]));},[U,o.count,$,b,N]);let ae=useCallback(L=>{let _e=o.count??0;if(!L||_e===0||m.length===0)return;let{scrollHeight:Oe,scrollTop:bn,clientHeight:wn}=L;Oe-bn-wn<200&&!P&&m.length<_e&&R({variables:{limit:xu,offset:m.length,where:q?{[q]:{some:{_id:{eq:n}}}}:{}}}).then(({data:Ot})=>{if(!Ot)return;let Cn=Ko(_?.plural??"",d,Ot,s);g$1(uniqBy(prop("_id"),[...$,...Cn.results]));}).catch(Ot=>{console.error("Error fetching more data:",Ot);});},[q,o.count,n,R,$,P,_?.plural,m.length,s,d]);function lt(L){L.preventDefault(),E({type:"EditRelationship",payload:{connectedEntitiesCount:$.length,connectionName:q,entityName:x,entityId:n,relationshipId:N,mode:v?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:A,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":l,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 ${l?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),u.current?.focus(),u.current?.click(),f$1(true);},onKeyDown:L=>{L.key==="Enter"&&f$1(true),L.key==="Escape"&&(L.preventDefault(),L.stopPropagation(),u.current?.blur(),f$1(false));},ref:u,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[l?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:lt,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",_?.menu?.label??_?.plural]}):jsx("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:k.map(L=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:L},L))}),l?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:L=>{L.preventDefault(),L.stopPropagation(),u.current?.blur(),f$1(false);},onKeyDown:L=>{L.key==="Enter"&&(L.preventDefault(),L.stopPropagation(),u.current?.blur(),f$1(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:A,onKeyDown:L=>{L.key==="Enter"&&(u.current?.focus(),u.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Wt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:f$1,open:l,children:jsx(Zt,{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(Po,{classNames:{table:"fk:max-h-[17.5rem]"},columns:G,data:m,entityName:r,onScroll:L=>{ae(L.target);},rowAdditionState:b[N]?.connect,rowDeletionState:b[N]?.disconnect})})})})]})}),jsx(i,{})]})})}function Eu({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],d=typeof find(propEq(a,"_id"),s)=="object",c=o[t]?.disconnect?.includes(a),l=d?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);d&&r(f=>f.filter(u=>u._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(f=>f._id!==a),disconnect:c?o[t]?.disconnect?.filter(f=>f!==a)??[]:l}}});}return jsx(Ya,{action:i,row:n})}function Su(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function Au({data:e,defaultScope:t,relationshipEntitySchema:o,scope:n}){if(!Array.isArray(e))return [];let r=i=>{let s=find(propEq(i.__typename,"name"))(o?.attributes??[])?.relationship?.field??"";if(s){let d=i[s],c=Array.isArray(d)?d[0]:d;return c&&typeof c=="object"?c[n]??c[t]??"":c}return i[n]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let s=a;return s.length===0?"":s.length===1?r(s[0]):s.slice(0,3).map(r).join(", ")}return a&&typeof a!="string"&&a.__typename?r(a):a},i))}function kr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:d}){let[c$1,l]=useState(false),{name:f$1,label:u,options:m,relationship:g$1}=r,p=g$1?.entity??f$1,h$1=ie(),y=d$2(),v=useId(),{relationships:x}=c$2(),E=useId(),S=find(propEq(p,"name"))(a),A=Fu(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[E]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,E,o,s]),useEffect(()=>{d(f$1,{...i$1(f$1),...x[E]?.connect??""});},[o,f$1,x,E,d]);function N(B){B.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:E,mode:g$1?.mode??"single"}});}function _(B){let I={type:"setRelationship",payload:{[E]:{connect:[],disconnect:[]}}};B.preventDefault(),y(I),d(f$1,{...i$1(f$1),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:f$1,render:({field:B})=>{let I=B.value?.value,j="";if(I&&typeof I=="object"&&!Array.isArray(I)&&I[A]){let q=I[A],F=Array.isArray(q)?q[0]:q;typeof F=="string"?j=F:j=F?.[s]??F?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:v,children:u}),m?.comment?jsx(h,{children:m.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$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:()=>{l(false);},onClick:N,onFocus:()=>{l(true);},onKeyDown:q=>{q.key==="Enter"&&N(q);},readOnly:true,type:"text",value:j}),j?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:_,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:N,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 Fu(e){return e.find(t=>t.isPrimary)??e[0]}function hr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(kr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(ur,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(gr,{...n})}return jsxs(ne,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(De,{children:"Error"}),jsx(re,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function is({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(c,l){let u=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;o(n,{...l,value:u});}function d(c,l){o(n,{...l,disabled:c});}return jsx(c,{control:e$2,name:n,render:({field:c})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:c.value?.value?String(c.value.value):void 0,disabled:i$1===false||c.value?.disabled,onValueChange:l=>{s(l,c.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(l=>"groupLabel"in l?jsxs(b$1,{children:[jsx(f$1,{children:l.groupLabel}),l.items.map(f=>jsx(g$1,{value:f.value,children:f.label},f.label))]},l.groupLabel):jsx(g$1,{value:l.value,children:l.label},l.label))})]}),jsx(b$2,{checked:c.value?.disabled??false,onChange:l=>{d(l,c.value);},scope:c.value?.scope}),jsx(i,{})]})})}function br({inputType:e,label:t}){return jsxs(ne,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(De,{children:"Error"}),jsx(re,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Xu({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:d$1},c){let l=find(propEq(n,"name"))(a),f=useMemo(()=>l?.attributes??[],[l]),u=useMemo(()=>z.object(f.reduce((b,A)=>typeof A.validation>"u"?b:{...b,[A.name]:z.object({value:A.validation(z).or(z.any().refine(()=>false,{message:A.label?`${A.label} is required`:"Required field"}))})},{})),[f]),m=useForm({resolver:zodResolver(u),values:i,mode:"onBlur",criteriaMode:"all"}),{control:g,getValues:p,handleSubmit:h,setValue:y,watch:v,trigger:x}=m,{getContributionPointConfig:E}=d(),S={datetime:Ea,editor:sr,asset:ba,number:wa,relationship:hr,select:is,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){x().then(()=>{h(()=>{s(false),d$1(p(),i);})();});},hasErrors(){s(true);},hasDataChanged(){return ss(p(),i)}})),useEffect(()=>{let b=v(A=>{s(ss(A,i));});return ()=>{b.unsubscribe();}},[i,s,v]),!l||l.attributes.length===0?jsxs(ne,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Error"}),jsxs(re,{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:f.map(b=>{if(b.name==="_id")return null;let A=E("formFields",[b.inputType])?.[0]?.component??S[b.inputType];return A?createElement(A,{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(br,{inputType:b.inputType,label:b.label},b.name)})})})}var kn=memo(forwardRef(Xu));function ss(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 xr({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:a}=d(),{schema:s,scopes:d$1}=find(propEq(a??"","projectId"))(i),c=d$1?.find(A=>A.isDefault)?.name??"default",f=find(propEq(n,"name"))(s)?.plural??n,{scope:u}=c$2(),m=ie(),[g,p,h,y]=rt(),{setIsDirty:v}=Gt();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 E=useCallback(A=>{m({type:"Dismiss",_id:A,payload:{}});},[m]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(A=>{let N=v4(),_=qn(f,s,A,N),B=It(f,u,s),I=gql`
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`
384
422
  ${B.query}
385
423
  `;p(gql`
386
- ${_}
387
- `),h({refetchQueries:[I],onCompleted:()=>{E(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,f,E,g,s,p,u,h]);return jsx(Mt,{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:()=>{E(e._id);},title:`Add ${n}`,children:jsx(kn,{currentScope:u,defaultScope:c,entityName:n,entityNamePlural:f,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=It(e,o,t),{schemaErrorMessage:d,setSchemaErrorMessage:c}=Rt(),{loading:l,data:f,fetchMore:u,error:m}=useQuery(gql`
388
- ${s.query}
389
- `,{variables:n}),g=Dt(m),p=Go(m),{isProjectDisabled:h,isProjectReadOnly:y}=(()=>{if(g?.statusCode===403){let E=Pt(g.bodyText);if(E&&typeof E.code=="string"){if(E.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(E.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),v=useCallback(()=>ms({data:f,entityNamePlural:e,isForm:r,schema:t,scope:o}),[f,e,r,t,o]);function x(E){u(E).then(({data:S})=>{let b=ms({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});a(A=>({count:b.count,results:uniqBy(prop("_id"),[...A.results,...b.results])}));}).catch(S=>{console.error("Error fetching more data:",S);});}return useEffect(()=>{if(p){c(p);return}f&&d&&!m&&c(null);},[f,m,d,p,c]),useEffect(()=>{m||p||a(v);},[m,v,p]),{isLoading:l,fetchMore:x,count:i.count,data:i.results,isProjectDisabled:h,isProjectReadOnly:y,schemaErrorMessage:d}}function ms(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Xi(e.entityNamePlural,e.scope,e.data,e.schema):Ko(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function gs(){return jsxs(ne,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Read Only Mode"}),jsxs(re,{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 Sr({handleSave:e,isLoading:t}){let{isDirty:o}=Gt();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 Ar(){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 Dr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:d$3,scopes:c}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),l=c?.find(P=>P.isDefault)?.name??"default",f=find(propEq(r,"plural"))(d$3),u=f?.name??r,{scope:m}=c$2(),[g,p]=useState(m),h=ie(),y=d$2(),[v,x,E,S]=rt(),{setIsDirty:b}=Gt(),A=useCallback(P=>{b(P);},[b]);useEffect(()=>{S.error&&i.current?.hasErrors();},[S.error]);let N=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]),_=useCallback(P=>{h({type:"Dismiss",_id:P,payload:{}});},[h]),B=useCallback(()=>{i.current?.submit();},[i]);function I(P){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(P),y({type:"setScope",payload:{projectId:s,scope:P}});}}}});return}p(P),y({type:"setScope",payload:{projectId:s,scope:P}});}let j=useCallback((P,U)=>{if(!U)return;let G=Vn(r,n,g,d$3,U,P),ae=It(r,g,d$3),lt=gql`
390
- ${ae.query}
391
- `;x(gql`
392
- ${G}
393
- `),E({variables:{where:{_id:{eq:n}}},refetchQueries:[{query:lt,variables:{where:{_id:{eq:n}}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),v(true);},[g,n,r,v,d$3,x,E]),{isLoading:q,data:F}=Ro({entityNamePlural:r,schema:d$3,scope:g,variables:{where:{_id:{eq:n}}},isForm:true}),M=F,$=M.length>0,w=q&&!$;function k(P,U){let G=P?.attributes.find(Oe=>Oe.isPrimary)??P?.attributes[0],ae=G.name,lt=G?.relationship?.field!==void 0;if(!U.length)return "";if(!lt||!G?.relationship?.field)return U[0][ae]?.value;let L=U[0][ae]?.value?.[G.relationship.field],_e=Array.isArray(L)?L[0]:L;if(_e&&typeof _e=="object"){let Oe=_e;return Oe[g]??Oe.default??""}return _e??""}let R=$&&f?k(f,M):"";return jsx(Mt,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:P=>{I(P);},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(P=>jsx(g$1,{value:P.name,children:P.label},P.name))})]}):null,jsx(Sr,{handleSave:B,isLoading:S.loading})]}),beforeClose:N,depth:t,isFocused:o,onClose:()=>{_(e._id);},onFormChange:()=>{},title:R,children:w||!$?jsx(Ar,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(gs,{}):null,jsx(kn,{currentScope:g,defaultScope:l,entityId:n,entityName:u,entityNamePlural:r,formData:M[0],onSubmit:j,ref:i,schema:d$3,setIsDirty:A})]})})}var Cs=25;function bm(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Fr({action:e,depth:t,isFocused:o}){let n=ie(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:d$1,connectionName:c,entityId:l,entityName:f,initialAssetPath:u,initialConnection:m,mode:g,relationshipId:p}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:v}=find(propEq(y??"","projectId"))(h),x=find(propEq(f,"name"))(v),E=x?.plural??"",S=i[p],b=Ao(),A=f==="_asset",N=A?"asset":x?.menu?.label??f.toLowerCase(),_=A&&g==="single"?"Select asset":`Select ${A?"assets":N}`,B=g==="single"?"Upload asset":"Upload assets",[I,j]=useState([]),q=[];if(m)q=[{id:m._id,value:m.value}];else if(S?.connect){let z=S.connect;q=[{id:z._id,value:z.value}];}let F=g==="single"?q:S?.connect?.map(z=>({id:z._id,value:z.value}))||[],[M,$]=useState(F),w=useMemo(()=>{let z=c?{[c]:{none:{_id:{eq:l}}}}:{},J=A?{NOT:{path:{eq:null}}}:{},Ee={OR:I.map(je=>({_id:{eq:je._id}}))};return g==="multiple"?{...J,...z,...Ee}:{...J,...Ee}},[c,l,A,g,I]),{count:k,data:R,fetchMore:P,isLoading:U}=Ro({entityNamePlural:E,schema:v,scope:a,variables:{offset:0,limit:Cs,where:w}}),G=!!R?.length,ae=U&&!G,lt=Do({attributesSchema:x?.attributes??[],checkboxSelect:g}),L=Array(5).fill({}),_e=bm(lt);useEffect(()=>{if(g!=="single"||M.length>0||!u||!R?.length)return;let z=R.find(J=>J.path===u);!z?._id||typeof z._id!="string"||$([{id:z._id,value:z}]);},[R,u,g,M.length]);let Oe=useCallback(z=>{n({type:"Dismiss",_id:z,payload:{}});},[n]),bn=useCallback(z=>{let J=R?.length??0,Ee=k-d$1;if(z&&Ee>0&&J>0){let{scrollHeight:je,scrollTop:ee,clientHeight:xn}=z;je-ee-xn<500&&!U&&J<Ee&&P({variables:{offset:J,limit:Cs,where:w}});}},[w,d$1,k,R?.length,P,U]);function wn(){let z;if(g==="single"){let[J]=M;z={_id:J?.id??"",value:J?.value??null};}g==="multiple"&&(z=M?.map((J,Ee)=>({_id:J.id??"",...A?{sortOrder:Ee}:{},value:J.value}))),r({type:"setRelationship",payload:{[p]:{connect:z,disconnect:S?.disconnect??[]}}}),Oe(e._id);}function Ot(z){if(g==="multiple"){$(Ee=>{let je=new Map(Ee.map(ee=>[ee.id,ee]));return z.map(ee=>{if(je.has(ee))return je.get(ee);let xn=R?.find($s=>$s._id===ee);return {id:ee,value:xn}})});return}let J=z[z.length-1];$(J?Ee=>{if(Ee.length===1&&Ee[0].id===J)return Ee;let je=R?.find(ee=>ee._id===J);return [{id:J,value:je}]}:[]);}function Cn(){n({type:"AddEntity",payload:{entityName:f}});}async function Is(){let z=await b({projectId:y,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});$(J=>{if(g==="single"){let[ee]=z;return ee?[{id:ee._id,value:ee.asset}]:J}let Ee=new Set(J.map(ee=>ee.id)),je=z.filter(ee=>!Ee.has(ee._id)).map(ee=>({id:ee._id,value:ee.asset}));return [...J,...je]});}return jsx(Mt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{wn();},variant:"default",children:"Select"}),A?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{Cn();},variant:"outline",children:`Create ${N}`}),A?jsxs(b$3,{className:"fk:px-8",onClick:()=>{Is();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),B]}):null]}),depth:t,isFocused:o,onClose:()=>{Oe(e._id);},title:_,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Po,{columns:ae?_e:lt,data:ae?L:R??[],entityName:x?.name??"",initialSelectionState:M?.reduce((z,J)=>({...z,...J.id?{[J.id]:true}:{}}),{}),onEntitySelectionChange:Ot,onScroll:z=>{bn(z.target);},toolbarComponent:()=>jsx(wm,{entityNamePlural:E,projectId:y??"",setSearchResultIds:j})})})})}function wm({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:d,isLoading:c}=e$5(t,a),l=useRef(null),f=useMemo(()=>Cm(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(d){let m=JSON.stringify(d.map(p=>p._id).sort()),g=l.current?JSON.stringify(l.current.map(p=>p._id).sort()):"";m!==g&&(l.current=[...d],o(d.map(p=>({_id:p._id}))));}},[d,o]);function u(m){let{value:g}=m.target;r(g),f(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:u,placeholder:"Search",value:n})]})}function Cm(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Es(){let e=qi(),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(ko,{options:r.options},n._id)}case "DeleteEntity":return jsx(Qn,{action:n},n._id);case "AddEntity":return jsx(xr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Dr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(Fr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Ss({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(Di,{children:[jsx(fa,{children:jsx(Es,{})}),jsx(Outlet,{})]})})})}function As(){let e=useRouteError(),t=new Date().getFullYear();function o(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):Fn(e)?gi(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 $r(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ne,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Error"}),jsx(re,{children:t})]})}var _m=RouterProvider;function Om({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(l=>Ts(l)):[Ts(e)],[i]=r,a=a$f(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let d=[{path:a,element:jsx(Ss,{config:r}),errorElement:jsx(As,{}),children:[{path:":projectId",element:jsx(Ci,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(l=>({path:l.name,element:l.component,errorElement:jsx($r,{}),children:l.routes?.map(f=>({path:f.path,element:f.component,errorElement:jsx($r,{}),children:f.children?.map(u=>({path:u.path,element:u.component}))}))}))}]}],c=createBrowserRouter(d);return n("Init Studio"),jsx(a$g,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Hi,{children:jsx(_m,{router:c})})})})}function Ts(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 Bm(){return jsxs(ne,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Project Paused"}),jsxs(re,{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 jm(){let{schemaErrorMessage:e}=Rt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
394
- `);return jsxs(ne,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Schema mismatch"}),jsxs(re,{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 qm(e){return e}function Um(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 Jm(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function Ps(e){return e.attributes.forEach(t=>{Um(t,e.name);}),{...e,attributes:e.attributes.map(Jm)}}function Qm(e){return Ps(e)}function Wm({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(Kt,{children:[jsx(eo,{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(bt,{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 ep({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=ie(),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 _r({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 ap({entityName:e,table:t}){let o=ie(),n=d$2(),r=c$2(),{projects:i,currentProjectId:a}=d(),{scopes:s}=find(propEq(a??"","projectId"))(i),[d$3,c,l]=rt(),[f,u]=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),E=bo(e,x,v);await new Promise(S=>{c(gql`
395
- ${E}
396
- `),l({variables:{where:{_id:{eq:v}}},update(b){b.evict({id:v});},onCompleted:()=>{S();}}),d$3(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()=>{u(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{u(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[s&&s.length>0?jsxs(a$5,{defaultValue:r.scope,onValueChange:v=>{p(v);},value:r.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(e$1,{children:s.map(v=>jsx(g$1,{value:v.name,children:v.label},v.name))})]}):null,jsx(_r,{table:t})]}),m.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:f,onClick:y,size:"sm",variant:"destructive",children:[f?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:f,onClick:g,size:"sm",variant:"default",children:"Create"})]})}export{Po as DataTable,Wm as DataTableFacetedFilter,ep as DataTableRowActions,ap as DataTableToolbar,_r as DataTableViewOptions,Om as FlexkitStudio,Bm as ProjectDisabled,jm as SchemaError,qm as defineConfig,Qm as defineEntity,qn as getEntityCreateMutation,bo as getEntityDeleteMutation,It as getEntityQuery,$t as getEntitySchema,Vn as getEntityUpdateMutation,ie as useDispatch,rt as useEntityMutation,Ro as useEntityQuery,Rt as useGraphQLError,Do as useGridColumnsDefinition,Ao 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
397
435
  //# sourceMappingURL=index.js.map