@flexkit/studio 0.0.30 → 0.0.32

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 (110) hide show
  1. package/README.md +2 -2
  2. package/dist/asset-ZVPFS73O.js +2 -0
  3. package/dist/{asset-TS7J5GA5.js.map → asset-ZVPFS73O.js.map} +1 -1
  4. package/dist/astro.d.ts +5 -3
  5. package/dist/astro.js +8 -3
  6. package/dist/chunk-5FHCSAK2.js +2 -0
  7. package/dist/chunk-5FHCSAK2.js.map +1 -0
  8. package/dist/{chunk-R7N3MDOP.js → chunk-AEBTHXEP.js} +2 -2
  9. package/dist/{chunk-R7N3MDOP.js.map → chunk-AEBTHXEP.js.map} +1 -1
  10. package/dist/{chunk-W3TUEJJL.js → chunk-CCI3FGPF.js} +2 -2
  11. package/dist/{chunk-W3TUEJJL.js.map → chunk-CCI3FGPF.js.map} +1 -1
  12. package/dist/chunk-D62TAYLI.js +2 -0
  13. package/dist/chunk-D62TAYLI.js.map +1 -0
  14. package/dist/{chunk-UKLE7J3K.js → chunk-E7G46743.js} +139 -16
  15. package/dist/chunk-F2ILIHAU.js +2 -0
  16. package/dist/chunk-F2ILIHAU.js.map +1 -0
  17. package/dist/{chunk-EOCJR5EY.js → chunk-FPH4YETF.js} +2 -2
  18. package/dist/{chunk-EOCJR5EY.js.map → chunk-FPH4YETF.js.map} +1 -1
  19. package/dist/chunk-GFDWGYUR.js +2 -0
  20. package/dist/chunk-GFDWGYUR.js.map +1 -0
  21. package/dist/{chunk-CPUC4QXH.js → chunk-JAARDXQZ.js} +2 -2
  22. package/dist/{chunk-CPUC4QXH.js.map → chunk-JAARDXQZ.js.map} +1 -1
  23. package/dist/{chunk-IXO2LU47.js → chunk-JCHD4EGB.js} +2 -2
  24. package/dist/{chunk-IXO2LU47.js.map → chunk-JCHD4EGB.js.map} +1 -1
  25. package/dist/chunk-KHPTVIYT.js +2 -0
  26. package/dist/chunk-KHPTVIYT.js.map +1 -0
  27. package/dist/{chunk-DWK4NNLB.js → chunk-LKBCPAXQ.js} +2 -2
  28. package/dist/{chunk-DWK4NNLB.js.map → chunk-LKBCPAXQ.js.map} +1 -1
  29. package/dist/chunk-MGXHZDFZ.js +2 -0
  30. package/dist/chunk-MGXHZDFZ.js.map +1 -0
  31. package/dist/chunk-N2T6MKPV.js +2 -0
  32. package/dist/chunk-N2T6MKPV.js.map +1 -0
  33. package/dist/chunk-PXB5QSHN.js +2 -0
  34. package/dist/chunk-PXB5QSHN.js.map +1 -0
  35. package/dist/chunk-QSROLDUU.js +2 -0
  36. package/dist/chunk-QSROLDUU.js.map +1 -0
  37. package/dist/chunk-VHNQDP7Q.js +616 -0
  38. package/dist/chunk-VUAFNQK7.js +2 -0
  39. package/dist/chunk-VUAFNQK7.js.map +1 -0
  40. package/dist/chunk-XFY7MZJN.js +2 -0
  41. package/dist/chunk-XFY7MZJN.js.map +1 -0
  42. package/dist/{core-handler-XAVVKLhV.d.ts → core-handler-C3xC98bN.d.ts} +3 -0
  43. package/dist/datetime-DDEWTNLB.js +2 -0
  44. package/dist/{datetime-NQTYGZIC.js.map → datetime-DDEWTNLB.js.map} +1 -1
  45. package/dist/editor-HAYTKNMY.js +2 -0
  46. package/dist/{editor-YIRZQR3D.js.map → editor-HAYTKNMY.js.map} +1 -1
  47. package/dist/index.css +163 -44
  48. package/dist/index.d.ts +22 -21
  49. package/dist/index.js +157 -210
  50. package/dist/index.js.map +1 -1
  51. package/dist/logo-B6ZKLGM7.js +3 -0
  52. package/dist/logo-B6ZKLGM7.js.map +1 -0
  53. package/dist/nextjs.d.ts +40 -12
  54. package/dist/nextjs.js +8 -3
  55. package/dist/search-X5V3YOTZ.js +2 -0
  56. package/dist/search-X5V3YOTZ.js.map +1 -0
  57. package/dist/select-H3JHOCWR.js +2 -0
  58. package/dist/{select-A6I27JQU.js.map → select-H3JHOCWR.js.map} +1 -1
  59. package/dist/switch-TACKLQJH.js +2 -0
  60. package/dist/{switch-AFZGXSR3.js.map → switch-TACKLQJH.js.map} +1 -1
  61. package/dist/tanstack-start.d.ts +6 -4
  62. package/dist/tanstack-start.js +17 -12
  63. package/dist/text-M3DRK7LU.js +2 -0
  64. package/dist/{text-2RL2L5FT.js.map → text-M3DRK7LU.js.map} +1 -1
  65. package/dist/text-SQXG7XJT.js +2 -0
  66. package/dist/{text-6F4QTCNT.js.map → text-SQXG7XJT.js.map} +1 -1
  67. package/dist/textarea-YF4K2VBM.js +2 -0
  68. package/dist/{textarea-2A4TLWZS.js.map → textarea-YF4K2VBM.js.map} +1 -1
  69. package/dist/tools.d.ts +78 -0
  70. package/dist/tools.js +60 -0
  71. package/dist/types-U28Ppixq.d.ts +56 -0
  72. package/dist/{types.d-CX3kDxFZ.d.ts → types.d-710RgZFw.d.ts} +85 -7
  73. package/dist/ui.d.ts +21 -5
  74. package/dist/ui.js +5 -5
  75. package/dist/ui.js.map +1 -1
  76. package/dist/{user-nav-4JKIFZLB.js → user-nav-XVY7JTX6.js} +2 -2
  77. package/dist/{user-nav-4JKIFZLB.js.map → user-nav-XVY7JTX6.js.map} +1 -1
  78. package/package.json +7 -3
  79. package/dist/asset-TS7J5GA5.js +0 -2
  80. package/dist/chunk-73RMWG53.js +0 -2
  81. package/dist/chunk-73RMWG53.js.map +0 -1
  82. package/dist/chunk-HAQICAOQ.js +0 -2
  83. package/dist/chunk-HAQICAOQ.js.map +0 -1
  84. package/dist/chunk-LL2Z4TD3.js +0 -2
  85. package/dist/chunk-LL2Z4TD3.js.map +0 -1
  86. package/dist/chunk-MC6VZLKC.js +0 -2
  87. package/dist/chunk-MC6VZLKC.js.map +0 -1
  88. package/dist/chunk-N52AF6GE.js +0 -2
  89. package/dist/chunk-N52AF6GE.js.map +0 -1
  90. package/dist/chunk-V6R4AWQS.js +0 -2
  91. package/dist/chunk-V6R4AWQS.js.map +0 -1
  92. package/dist/chunk-WXMCINGZ.js +0 -2
  93. package/dist/chunk-WXMCINGZ.js.map +0 -1
  94. package/dist/chunk-WZ533Y4O.js +0 -2
  95. package/dist/chunk-WZ533Y4O.js.map +0 -1
  96. package/dist/chunk-YA4ACPM5.js +0 -2
  97. package/dist/chunk-YA4ACPM5.js.map +0 -1
  98. package/dist/chunk-ZEZ6TRCO.js +0 -2
  99. package/dist/chunk-ZEZ6TRCO.js.map +0 -1
  100. package/dist/datetime-NQTYGZIC.js +0 -2
  101. package/dist/editor-YIRZQR3D.js +0 -2
  102. package/dist/logo-GCKKZP62.js +0 -3
  103. package/dist/logo-GCKKZP62.js.map +0 -1
  104. package/dist/search-UFFZBRQV.js +0 -2
  105. package/dist/search-UFFZBRQV.js.map +0 -1
  106. package/dist/select-A6I27JQU.js +0 -2
  107. package/dist/switch-AFZGXSR3.js +0 -2
  108. package/dist/text-2RL2L5FT.js +0 -2
  109. package/dist/text-6F4QTCNT.js +0 -2
  110. package/dist/textarea-2A4TLWZS.js +0 -2
package/dist/index.js CHANGED
@@ -1,189 +1,190 @@
1
- import'./index.css';import {a as a$2}from'./chunk-WXMCINGZ.js';import {a as a$1}from'./chunk-YA4ACPM5.js';import {a as a$b}from'./chunk-D4XLXU2H.js';import {a as a$d}from'./chunk-N52AF6GE.js';import {a as a$a}from'./chunk-CPUC4QXH.js';import {a,b as b$7}from'./chunk-EOCJR5EY.js';import {a as a$e}from'./chunk-R7N3MDOP.js';import {a as a$c}from'./chunk-W3TUEJJL.js';import'./chunk-ZEZ6TRCO.js';import {i as i$1,k,g as g$3,l,m as m$1,p,q,n,r,u,f as f$3,c as c$7,d as d$3,h as h$2}from'./chunk-MC6VZLKC.js';import {a as a$7}from'./chunk-7GBAYC7G.js';import'./chunk-OEWYLKO7.js';import {a as a$8,b as b$5,c as c$4,e as e$3}from'./chunk-YW2EEXMV.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$2,f as f$1,g as g$1}from'./chunk-XU2JGXYC.js';import {d as d$2,c as c$2,b as b$9,a as a$i,e as e$5}from'./chunk-WZ533Y4O.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-WZ533Y4O.js';import {v,b as b$6,m as m$2,o,p as p$1,r as r$1,t,s,q as q$1}from'./chunk-LL2Z4TD3.js';import {b,a as a$j}from'./chunk-DWK4NNLB.js';export{b as useAuth}from'./chunk-DWK4NNLB.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$1,m,a as a$h,l as l$1,i as i$2,b as b$b,r as r$2}from'./chunk-IXO2LU47.js';import {d,a as a$f,b as b$8,e as e$4,c as c$6}from'./chunk-V6R4AWQS.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-V6R4AWQS.js';import {b as b$4,c as c$5,a as a$l}from'./chunk-WDRCARCP.js';export{b as IMAGES_BASE_URL}from'./chunk-WDRCARCP.js';import {b as b$3,a as a$9}from'./chunk-EYGOJ2ZN.js';import {a as a$g,b as b$a}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-73RMWG53.js';import {a as a$6}from'./chunk-HAQICAOQ.js';export{a as DefaultValueSwitch}from'./chunk-HAQICAOQ.js';import'./chunk-KGYH74NA.js';import {b as b$1,c,e,f,h,g,i,j,a as a$k}from'./chunk-FVFRTCEB.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as Do from'react';import {lazy,createContext,memo,forwardRef,useMemo,useRef,useEffect,useImperativeHandle,createElement,useId,useState,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,uniq,omit,pick,toPairs,props}from'ramda';import Dl,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,PencilIcon,Trash2Icon,Settings2,RefreshCw,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as fo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,NetworkStatus,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import Dr from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import rd from'react-markdown';import {useReactTable,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function lo(){let[e,t]=useState(false),{theme:n,setTheme:o}=b$b();return useEffect(()=>{t(true);},[]),e?jsxs(c$7,{size:"sm",type:"single",value:n,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{o("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{o("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{o("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function co(){let{resolvedTheme:e}=b$b();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var Tl=cva("fk:relative fk:w-full fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:[&>svg~*]:pl-7 fk:[&>svg+div]:translate-y-[-3px] fk:[&>svg]:absolute fk:[&>svg]:left-4 fk:[&>svg]:top-4 fk:[&>svg]:text-foreground",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:border-none fk:text-destructive fk:bg-destructive-foreground fk:[&>svg]:text-destructive"}},defaultVariants:{variant:"default"}});function ke({className:e,variant:t,...n}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(Tl({variant:t}),e),...n})}function ze({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$4("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function he({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:text-sm fk:[&_p]:leading-relaxed",e),...t})}var $l=fo.object({email:fo.email({error:"Please enter a valid email address"})});function ar({projectId:e$1,setIsEmailLogin:t}){let[n,o]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver($l),defaultValues:{email:""}}),l=new URL(c$5(e$1).loginOtpSend,a$l),{data:c$1,error:f,isLoading:m}=Dl(r?l.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),u=c$1&&"error"in c$1&&c$1.error.code,p=c$1&&"token"in c$1,d=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!p)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),o(true);return}let C=new URL(c$5(e$1).loginOtpConfirm,a$l),v="/api/flexkit/set-token";fetch(`${C.href}?email=${encodeURIComponent(s.getValues("email"))}&token=${encodeURIComponent(d)}`).then(b=>{b.status===200&&b.json().then(D=>{fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:D.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,p,e$1,d]);function g$1(){o(false),i$1(true),a(l.href);}return jsx("div",{className:"fk:w-full",children:p?jsx(ke,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(he,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:s.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b$1,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(g$1)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[u==="not_exists"&&jsx(ke,{variant:"destructive",children:jsxs(he,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${encodeURIComponent(s.getValues("email"))}`,children:"Sign up?"})]})}),u==="unknown_error"||f?jsx(ke,{variant:"destructive",children:jsxs(he,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."," "]})}):null,n?jsx(ke,{variant:"destructive",children:jsxs(he,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$7,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":m,className:"fk:w-full",type:"submit",disabled:!!m,children:[m?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function Zi({projectId:e}){let{projects:t}=d(),[n,o]=useState(t.find(g=>g.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:l}=Dl(c$5(e).authProviders,g=>fetch(g,{mode:"cors"}).then(h=>h.json())),[c,f]=b(),m=new Date().getFullYear(),u=useLocation(),p=u.state?.from?.pathname??u.pathname,d$2=p.includes(n.projectId)?`${location.origin}${p}`:`${location.origin}${b$a(n.basePath,n.projectId)}`;if(s)throw new Error("Error fetching auth providers");return l||c||!a?jsx(co,{}):f.user?.id?jsx(Navigate,{replace:true,state:{from:u},to:n.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$k,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:n.projectId,onValueChange:g=>{o(t.find(h=>h.projectId===g)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":n.title,children:n.title})}),jsx(e$1,{children:t.map(g=>jsx(g$1,{value:g.projectId,children:g.title},g.projectId))})]})]}):null,r?jsx(ar,{projectId:e,setIsEmailLogin:i}):jsxs(Fragment,{children:[jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-sm fk:text-left fk:text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk:flex fk:flex-col fk:space-y-6",children:[a.providers.map(g=>jsx(b$3,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:Vl({url:g.url,projectId:n.projectId,basePath:"/api/flexkit/get-token",fromPath:d$2}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",m]})]}),jsx(lo,{})]})})]})}function Vl({projectId:e,url:t,basePath:n,fromPath:o}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${n}`),r.set("projectId",e),r.set("redirect",o),`${t}?${r.toString()}`}var Bl=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],zl={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},uo=class e extends Error{code;constructor(t,n){super(n??zl[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,n){return new e(t,n)}};function sr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Bl.includes(t)}function Ki(e){if(sr(e))return e.code}function na({apps:e,version:t}){let[n,o]=useState(0),[r,i]=useState(e),[a,s]=useState([]),l=useRef(null),c=useLocation(),{projectId:f}=useParams(),m$1=e.find(p=>c.pathname.includes(`/${f}/${p.name}`))?.name,u=e.find(p=>c.pathname.includes(`/${f}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(l.current===null)return;let p=new ResizeObserver(()=>{o(l.current?.offsetHeight??0);});return p.observe(l.current),function(){p.disconnect();}},[m$1]),useEffect(()=>{let p=Math.floor(n/48)-2,d=e.slice(0,p);if(!d.find(h=>h.name===u)){let h=e.find(y=>y.name===u);d.pop(),h&&d.push(h);}let g=e.filter(h=>!d.includes(h));i(d),s(g);},[e,u,n]),m$1===void 0&&u?jsx(Navigate,{to:`${c.pathname}/${u}`}):jsx(a$8,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:l,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:p.name,children:p.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:p.title})})]})},p.name))}),a.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:a.map(p=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${f}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(m,{}),jsx(h$1,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var Kl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-X6YVZYKL.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-UFFZBRQV.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-4JKIFZLB.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-AFZGXSR3.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-2RL2L5FT.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-2A4TLWZS.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-TS7J5GA5.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-6F4QTCNT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-YIRZQR3D.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-NQTYGZIC.js').then(({DateTime:e})=>({default:e}))),"previewFields.select":lazy(()=>import('./select-A6I27JQU.js').then(({Select:e})=>({default:e})))};function Dn(e){let{getContributionPointConfig:t}=d(),[n,...o]=e.split("."),r=Kl[e],i=t(n,o);return i?.length>0?i[0]?.component:r}function ra({projectId:e,projects:t}){let{resolvedTheme:n}=b$b(),o=Dn("navbar.logo"),r=Dn("navbar.projectSelector"),i=Dn("navbar.search"),a=Dn("navbar.userNav"),s=t.find(u=>u.projectId===e)??t[0],{basePath:l,schema:c}=s,f=useNavigate();function m(u){startTransition(()=>{f(b$a(l,e,"desk","list",u.entityNamePlural)+`?id=${u.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-[3.5rem] fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-20",children:[jsx(Suspense,{fallback:null,children:jsx(o,{theme:n,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:m,projectId:e,schema:c})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function ia({version:e}){let{contributions:t,projects:n}=d(),[o,r]=b(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(n);if(!a)throw new uo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:l}=t,c=d$2(),f=useLocation();return useEffect(()=>{if(s){let m=s.find(p=>p.isDefault)||s[0],u="";typeof localStorage<"u"&&(u=localStorage.getItem(`${a$i}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:u||m.name}});}},[f]),o?jsx(co,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(ra,{projectId:i??"",projects:n}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(na,{apps:l,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(Zi,{projectId:i??""})}function la(e){return e?"cause"in e:false}function qt(e){if(!e)return null;if(ServerError.is(e))return e;if(la(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function ca(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Ut(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function po(e){if(!e)return null;let t=cc(e);return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(n=>`- ${n}`)].join(`
2
- `)}function cc(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(sa).map(({message:r})=>r);let t=ca(e);if(t&&Rn(t))return [t];let n=qt(e);if(n?.statusCode!==400)return [];let o=Ut(n.bodyText)??fc(n)??uc(e);return o?Array.isArray(o.errors)?o.errors.filter(sa).map(r=>r.message):typeof o.message=="string"&&Rn(o.message)?[o.message]:typeof o.error=="string"&&Rn(o.error)?[o.error]:[]:[]}function fc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function uc(e){if(!la(e))return null;let{cause:t}=e,n=ca(t);if(n&&Rn(n))return {message:n};if(!t||typeof t!="object")return null;let{result:o}=t;return o&&typeof o=="object"?o:null}function sa(e){if(!e||typeof e!="object")return false;let{extensions:t,message:n}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof n=="string"?true:typeof n=="string"&&Rn(n)}function Rn(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Sc=ApolloProvider,da=createContext(void 0);function Jt(){let e=useContext(da);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function Ec(e){return new ErrorLink(({error:t})=>{let n=po(t);if(n){e(n);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:a})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let o=qt(t);if(o?.statusCode===400){let r=Ut(o.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:l}=r;if(typeof l=="string")i=l;else if(Array.isArray(s)){let[c]=s;if(c&&typeof c.message=="string"){let{message:f}=c;i=f;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=o.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.warn(`[Network error]: ${o.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function Ac(e,t){return from([Ec(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Tc(e,t){return new ApolloClient({link:Ac(e??"",t),cache:new InMemoryCache({dataIdFromObject:n=>n._id?n._id:defaultDataIdFromObject(n)})})}function ma({children:e}){let{currentProjectId:t}=d(),[n,o]=useState(null),r=useMemo(()=>({schemaErrorMessage:n,setSchemaErrorMessage:o}),[n]),i=useMemo(()=>Tc(t,o),[t]);return jsx(da.Provider,{value:r,children:jsx(Sc,{client:i,children:e})})}function pa({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function fr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Nc({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function ga({className:e,size:t="default",...n}){return jsxs(fr,{children:[jsx(Nc,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...n})]})}function ka({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$4("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function ha({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$4("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function ya({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$4("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function va({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function ba({className:e,variant:t="default",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...o})})}function Ca({className:e,variant:t="outline",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...o})})}function Pn({options:e}){let[t,n]=useState(false),[o,r]=useState(false),[i,a]=useState(false);useEffect(()=>{n(true);},[]);function s(){n(false),i||e.dialogActionCancel?.(),i&&a(false);}async function l(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{a(true),n(false),r(false);}}return jsx(pa,{onOpenChange:s,open:t,children:jsx(fr,{children:jsxs(ga,{className:"sm:max-w-[425px]",children:[jsxs(ka,{children:[jsx(ya,{children:e.dialogTitle}),jsx(va,{children:e.dialogMessage})]}),jsxs(ha,{children:[jsx(Ca,{disabled:o,onClick:s,children:e.dialogCancelTitle}),jsxs(ba,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:o,onClick:l,children:[o?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Ea=createContext([]),Aa=createContext(()=>{});function Fc(e,t){let n=t.type;switch(t._id||(t._id=Date.now().toString()),n){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(o=>o._id!==t._id);default:throw Error(`Unknown action: ${n}`)}}function Ta({children:e}){let[t,n]=useReducer(Fc,[]);return jsx(Ea.Provider,{value:t,children:jsx(Aa.Provider,{value:n,children:e})})}function Na(){return useContext(Ea)}function de(){return useContext(Aa)}function vt(){let[e,t]=useState(false),[n,o]=useState(gql`
1
+ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}from'./chunk-MGXHZDFZ.js';import {a as a$b}from'./chunk-D4XLXU2H.js';import {a as a$d}from'./chunk-D62TAYLI.js';import {a as a$a}from'./chunk-JAARDXQZ.js';import {a,b as b$7}from'./chunk-FPH4YETF.js';import {a as a$e}from'./chunk-AEBTHXEP.js';import {a as a$c}from'./chunk-CCI3FGPF.js';import'./chunk-F2ILIHAU.js';import {h,i,j,k,l,n,o,p,s,t,q,u,x as x$1,f as f$3,c as c$8,d as d$3,g as g$3}from'./chunk-PXB5QSHN.js';import {a as a$7}from'./chunk-7GBAYC7G.js';import'./chunk-OEWYLKO7.js';import {a as a$8,b as b$5,c as c$4,e as e$3}from'./chunk-YW2EEXMV.js';import {d as d$2,c as c$2,e as e$4,b as b$9,a as a$i,f as f$4}from'./chunk-QSROLDUU.js';export{c as useAppContext,d as useAppDispatch,f as useSearch}from'./chunk-QSROLDUU.js';import {w,x,c as c$5,b as b$6,n as n$1,p as p$1,q as q$1,s as s$1,u as u$1,t as t$1,r}from'./chunk-KHPTVIYT.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$2,f as f$1,g as g$1}from'./chunk-XU2JGXYC.js';import {b,a as a$j}from'./chunk-LKBCPAXQ.js';export{b as useAuth}from'./chunk-LKBCPAXQ.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$2,m,a as a$h,l as l$1,i as i$2,b as b$b,r as r$1}from'./chunk-JCHD4EGB.js';import {d,a as a$f,b as b$8,e as e$5,c as c$7}from'./chunk-5FHCSAK2.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-5FHCSAK2.js';import {b as b$4,c as c$6,a as a$l}from'./chunk-WDRCARCP.js';export{b as IMAGES_BASE_URL}from'./chunk-WDRCARCP.js';import {b as b$3,a as a$9}from'./chunk-EYGOJ2ZN.js';import {a as a$g,b as b$a}from'./chunk-WIUPQHZ5.js';import {a as a$4}from'./chunk-GFDWGYUR.js';import {a as a$6}from'./chunk-VUAFNQK7.js';export{a as DefaultValueSwitch}from'./chunk-VUAFNQK7.js';import'./chunk-KGYH74NA.js';import {b as b$1,c,e,f,h as h$1,g,i as i$1,j as j$1,a as a$k}from'./chunk-FVFRTCEB.js';import {a as a$1}from'./chunk-O2QMYUPS.js';import*as Io from'react';import {lazy,createContext,memo,forwardRef,useMemo,useState,useRef,useEffect,useImperativeHandle,createElement,useId,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 oc,{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 vo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,NetworkStatus,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import $r 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 zd from'react-markdown';import {useReactTable,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function ho(){let[e,t]=useState(false),{theme:n,setTheme:o}=b$b();return useEffect(()=>{t(true);},[]),e?jsxs(c$8,{size:"sm",type:"single",value:n,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{o("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{o("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{o("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function yo(){let{resolvedTheme:e}=b$b();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var tc=cva("fk:relative fk:w-full fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:[&>svg~*]:pl-7 fk:[&>svg+div]:translate-y-[-3px] fk:[&>svg]:absolute fk:[&>svg]:left-4 fk:[&>svg]:top-4 fk:[&>svg]:text-foreground",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:border-none fk:text-destructive fk:bg-destructive-foreground fk:[&>svg]:text-destructive"}},defaultVariants:{variant:"default"}});function ye({className:e,variant:t,...n}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$1(tc({variant:t}),e),...n})}function qe({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$1("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ve({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$1("fk:text-sm fk:[&_p]:leading-relaxed",e),...t})}var cc=vo.object({email:vo.email({error:"Please enter a valid email address"})});function ur({projectId:e$1,setIsEmailLogin:t}){let[n,o]=useState(false),[r,i]=useState(false),{mutate:s}=useSWRConfig(),l=useForm({resolver:zodResolver(cc),defaultValues:{email:""}}),c$1=new URL(c$6(e$1).loginOtpSend,a$l),{data:a,error:u,isLoading:f}=oc(r?c$1.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:l.getValues("email")})}).then(v=>v.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),m=a&&"error"in a&&a.error.code,p=a&&"token"in a,d=a&&"token"in a?a.token:"";useEffect(()=>{if(!p)return;let h=0,v=setInterval(()=>{if(h>100){clearInterval(v),o(true);return}let y=new URL(c$6(e$1).loginOtpConfirm,a$l),C="/api/flexkit/set-token";fetch(`${y.href}?email=${encodeURIComponent(l.getValues("email"))}&token=${encodeURIComponent(d)}`).then(x=>{x.status===200&&x.json().then(A=>{fetch(C,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:A.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(v);}},[l,p,e$1,d]);function g$1(){o(false),i(true),s(c$1.href);}return jsx("div",{className:"fk:w-full",children:p?jsx(ye,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(ve,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:l.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b$1,{...l,children:jsxs("form",{onSubmit:h=>{l.handleSubmit(g$1)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[m==="not_exists"&&jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${encodeURIComponent(l.getValues("email"))}`,children:"Sign up?"})]})}),m==="unknown_error"||u?jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."," "]})}):null,n?jsx(ye,{variant:"destructive",children:jsxs(ve,{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:l.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$7,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i$1,{})]})}),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 ps({projectId:e}){let{projects:t}=d(),[n,o]=useState(t.find(g=>g.projectId===e)??t[0]),[r,i]=useState(false),{data:s,error:l,isLoading:c}=oc(c$6(e).authProviders,g=>fetch(g,{mode:"cors"}).then(h=>h.json())),[a,u]=b(),f=new Date().getFullYear(),m=useLocation(),p=m.state?.from?.pathname??m.pathname,d$2=p.includes(n.projectId)?`${location.origin}${p}`:`${location.origin}${b$a(n.basePath,n.projectId)}`;if(l)throw new Error("Error fetching auth providers");return c||a||!s?jsx(yo,{}):u.user?.id?jsx(Navigate,{replace:true,state:{from:m},to:n.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$k,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:n.projectId,onValueChange:g=>{o(t.find(h=>h.projectId===g)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":n.title,children:n.title})}),jsx(e$1,{children:t.map(g=>jsx(g$1,{value:g.projectId,children:g.title},g.projectId))})]})]}):null,r?jsx(ur,{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(g=>jsx(b$3,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:mc({url:g.url,projectId:n.projectId,basePath:"/api/flexkit/get-token",fromPath:d$2}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",f]})]}),jsx(ho,{})]})})]})}function mc({projectId:e,url:t,basePath:n,fromPath:o}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${n}`),r.set("projectId",e),r.set("redirect",o),`${t}?${r.toString()}`}var pc=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],gc={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"},bo=class e extends Error{code;constructor(t,n){super(n??gc[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,n){return new e(t,n)}};function fr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:pc.includes(t)}function gs(e){if(fr(e))return e.code}var kc={developer:true,owner:true};function ks(e){return !!(e&&kc[e])}function hs(e){return `/api/flexkit/${e}/tools/dev-connect/tick`}var dr=2e3,yc=1e4,mr=false;async function vc(e){try{let t=await fetch(e,{credentials:"same-origin",method:"POST"});if(t.status!==200)return !1;let n=await t.json();return typeof n.job=="string"&&n.job.length>0}catch{return false}}function ys({projectId:e,role:t}){return useEffect(()=>{if(!ks(t)||!e)return;let n=false,o=dr,r,i=hs(e);function s(a){n||document.hidden||(r!==void 0&&window.clearTimeout(r),r=window.setTimeout(()=>{l();},a));}async function l(){if(n||document.hidden)return;if(mr){s(o);return}mr=true;let a=await vc(i);mr=false,a?o=dr:o=Math.min(o*2,yc),s(o);}function c(){if(document.hidden){r!==void 0&&(window.clearTimeout(r),r=void 0);return}o=dr,l();}return l(),document.addEventListener("visibilitychange",c),()=>{n=true,document.removeEventListener("visibilitychange",c),r!==void 0&&window.clearTimeout(r);}},[e,t]),null}function ws({apps:e,version:t}){let[n,o]=useState(0),[r,i]=useState(e),[s,l]=useState([]),c=useRef(null),a=useLocation(),{projectId:u}=useParams(),f=e.find(p=>a.pathname.includes(`/${u}/${p.name}`))?.name,m$1=e.find(p=>a.pathname.includes(`/${u}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(c.current===null)return;let p=new ResizeObserver(()=>{o(c.current?.offsetHeight??0);});return p.observe(c.current),function(){p.disconnect();}},[f]),useEffect(()=>{let p=Math.floor(n/48)-2,d=e.slice(0,p);if(!d.find(h=>h.name===m$1)){let h=e.find(v=>v.name===m$1);d.pop(),h&&d.push(h);}let g=e.filter(h=>!d.includes(h));i(d),l(g);},[e,m$1,n]),f===void 0&&m$1?jsx(Navigate,{to:`${a.pathname}/${m$1}`}):jsx(a$8,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:c,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:p.name,children:p.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:p.title})})]})},p.name))}),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(p=>jsx(h$2,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$2,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${u}`,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$2,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var Rc={"navbar.logo":lazy(()=>import('./logo-B6ZKLGM7.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-X6YVZYKL.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-X5V3YOTZ.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-XVY7JTX6.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-TACKLQJH.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-M3DRK7LU.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-YF4K2VBM.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-ZVPFS73O.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-SQXG7XJT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-HAYTKNMY.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-DDEWTNLB.js').then(({DateTime:e})=>({default:e}))),"previewFields.select":lazy(()=>import('./select-H3JHOCWR.js').then(({Select:e})=>({default:e})))};function Ln(e){let{getContributionPointConfig:t}=d(),[n,...o]=e.split("."),r=Rc[e],i=t(n,o);return i?.length>0?i[0]?.component:r}function Ss({projectId:e,projects:t}){let{resolvedTheme:n}=b$b(),o=Ln("navbar.logo"),r=Ln("navbar.projectSelector"),i=Ln("navbar.search"),s=Ln("navbar.userNav"),l=t.find(m=>m.projectId===e)??t[0],{basePath:c,schema:a}=l,u=useNavigate();function f(m){startTransition(()=>{u(b$a(c,e,"desk","list",m.entityNamePlural)+`?id=${m.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-14 fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-30",children:[jsx(Suspense,{fallback:null,children:jsx(o,{theme:n,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:f,projectId:e,schema:a},e)})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(s,{projectId:e})})})]})}function Es({version:e}){let{contributions:t,projects:n}=d(),[o,r]=b(),{projectId:i}=useParams(),s=find(propEq(i??"","projectId"))(n);if(!s)throw new bo("PROJECT_NOT_FOUND");let{scopes:l}=s,{apps:c}=t,a=d$2(),u=useLocation();return useEffect(()=>{if(l){let f=l.find(p=>p.isDefault)||l[0],m="";typeof localStorage<"u"&&(m=localStorage.getItem(`${a$i}${i}`)??""),a({type:"setScope",payload:{projectId:i,scope:m||f.name}});}},[u]),o?jsx(yo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(Ss,{projectId:i??"",projects:n}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(ws,{apps:c,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{}),jsx(ys,{projectId:i??"",role:r.user.role})]}):jsx(ps,{projectId:i??""})}function Ns(e){return e?"cause"in e:false}function Qt(e){if(!e)return null;if(ServerError.is(e))return e;if(Ns(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Ds(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Xt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function wo(e){if(!e)return null;let t=Fs(e).filter(n=>!Hc(n));return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(n=>`- ${n}`)].join(`
2
+ `)}function Rs(e,t){return e?Fs(e).some(n=>n.includes(`Cannot query field "${t}"`)):false}function Fs(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ts).map(({message:r})=>r);let t=Ds(e);if(t&&Mn(t))return [t];let n=Qt(e);if(n?.statusCode!==400)return [];let o=Xt(n.bodyText)??zc(n)??jc(e);return o?Array.isArray(o.errors)?o.errors.filter(Ts).map(r=>r.message):typeof o.message=="string"&&Mn(o.message)?[o.message]:typeof o.error=="string"&&Mn(o.error)?[o.error]:[]:[]}function zc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function jc(e){if(!Ns(e))return null;let{cause:t}=e,n=Ds(t);if(n&&Mn(n))return {message:n};if(!t||typeof t!="object")return null;let{result:o}=t;return o&&typeof o=="object"?o:null}function Ts(e){if(!e||typeof e!="object")return false;let{extensions:t,message:n}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof n=="string"?true:typeof n=="string"&&Mn(n)}function Mn(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}function Hc(e){return /Cannot query field "[_A-Za-z][_0-9A-Za-z]*Total" on type "Query"/.test(e)}var nu=ApolloProvider,Ls=createContext(void 0);function Wt(){let e=useContext(Ls);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function ou(e){return new ErrorLink(({error:t})=>{let n=wo(t);if(n){e(n);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 o=Qt(t);if(o?.statusCode===400){let r=Xt(o.bodyText),i=null;if(r&&typeof r=="object"){let{error:s,errors:l,message:c}=r;if(typeof c=="string")i=c;else if(Array.isArray(l)){let[a]=l;if(a&&typeof a.message=="string"){let{message:u}=a;i=u;}}else typeof s=="string"?i=s:i=JSON.stringify(r);}else i=o.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.warn(`[Network error]: ${o.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function ru(e,t){return from([ou(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function iu(e,t){return new ApolloClient({link:ru(e??"",t),cache:new InMemoryCache({dataIdFromObject:n=>n._id?n._id:defaultDataIdFromObject(n)})})}function Ms({children:e}){let{currentProjectId:t}=d(),[n,o]=useState(null),r=useMemo(()=>({schemaErrorMessage:n,setSchemaErrorMessage:o}),[n]),i=useMemo(()=>iu(t,o),[t]);return jsx(Ls.Provider,{value:r,children:jsx(nu,{client:i,children:e})})}function _s({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function kr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function su({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$1("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 $s({className:e,size:t="default",...n}){return jsxs(kr,{children:[jsx(su,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$1("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...n})]})}function Os({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$1("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 Vs({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$1("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 Bs({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$1("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 zs({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$1("fk:text-sm fk:text-muted-foreground",e),...t})}function js({className:e,variant:t="default",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$1(e),...o})})}function Hs({className:e,variant:t="outline",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$1(e),...o})})}function _n({options:e}){let[t,n]=useState(false),[o,r]=useState(false),[i,s]=useState(false);useEffect(()=>{n(true);},[]);function l(){n(false),i||e.dialogActionCancel?.(),i&&s(false);}async function c(){r(true),s(true),n(false),await new Promise(a=>{globalThis.setTimeout(a,150);});try{let a=e.dialogActionSubmit?.();a&&typeof a.then=="function"&&await a;}finally{r(false);}}return jsx(_s,{onOpenChange:l,open:t,children:jsx(kr,{children:jsxs($s,{className:"sm:max-w-[425px]",children:[jsxs(Os,{children:[jsx(Bs,{children:e.dialogTitle}),jsx(zs,{children:e.dialogMessage})]}),jsxs(Vs,{children:[jsx(Hs,{disabled:o,onClick:l,children:e.dialogCancelTitle}),jsxs(js,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:o,onClick:c,children:[o?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Gs=createContext([]),Qs=createContext(()=>{});function fu(e,t){let n=t.type;switch(t._id||(t._id=Date.now().toString()),n){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(o=>o._id!==t._id);default:throw Error(`Unknown action: ${n}`)}}function Xs({children:e}){let[t,n]=useReducer(fu,[]);return jsx(Gs.Provider,{value:t,children:jsx(Qs.Provider,{value:n,children:e})})}function Ws(){return useContext(Gs)}function ge(){return useContext(Qs)}function xt(){let[e,t]=useState(false),[n,o]=useState(gql`
3
3
  mutation updateEntity($any: Any) {
4
4
  any
5
5
  }
6
- `),[r,i]=useState({}),[a,{data:s,loading:l,error:c}]=useMutation(n,r),f=qt(c),{isProjectDisabled:m,isProjectReadOnly:u}=(()=>{if(f?.statusCode===403){let p=Ut(f.bodyText);if(p&&typeof p.code=="string"){if(p.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(p.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,o,i,{data:s,loading:l,error:c,isProjectDisabled:m,isProjectReadOnly:u}]}function ue(e){return e.dataType==="asset"?"global":e.scope}var yo=25,Oc=3,ko=3,Vc=["id","string"],Bc=["date","datetime","duration","time"],gr=`_id
6
+ `),[r,i]=useState({}),[s,{data:l,loading:c,error:a}]=useMutation(n,r),u=Qt(a),{isProjectDisabled:f,isProjectReadOnly:m}=(()=>{if(u?.statusCode===403){let p=Xt(u.bodyText);if(p&&typeof p.code=="string"){if(p.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(p.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(s(),t(false));},[e,s]),[t,o,i,{data:l,loading:c,error:a,isProjectDisabled:f,isProjectReadOnly:m}]}function be(e){return e.dataType==="asset"?"global":e.scope}function Vn(e){if(!e)return {};let t={};for(let[n,o]of Object.entries(e))t[n]=o?.value;return t}function St(e,t){return typeof e=="function"?!!e(t):e===true}function vr(e){return e===true}var So=25,ku=3,Ys=3,hu=["id","string"],yu=["date","datetime","duration","time"],Cr=`_id
7
7
  originalFilename
8
8
  mimeType
9
9
  path
10
10
  size
11
11
  height
12
12
  width
13
- lqip`,vo=`_id
13
+ lqip`,wr=`_id
14
14
  originalFilename
15
15
  mimeType
16
16
  path
17
17
  size
18
18
  height
19
- width`;function un(e){return e?ue(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function bo(e,t){return !e||!un(e)?false:t?.name!==b$8.name||e.name!=="assets"}function Ln(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Co(e){let t=e,n=t?.edges??[],o=t?.aggregate?.count?.nodes??n.length;return n.reduce((r,i,a)=>(i.node&&r.push({...i.node,sortOrder:i.properties?.sortOrder??a,totalCount:o}),r),[]).sort((r,i)=>(r.sortOrder??Number.MAX_SAFE_INTEGER)-(i.sortOrder??Number.MAX_SAFE_INTEGER))}function $n(e){return e.reduce((t,n,o)=>n._id?{...t,[n._id]:n.sortOrder??o}:t,{})}function bt(e){return Array.isArray(e)?e[0]??null:e??null}function kr(e,t=true,n=true,o=yo){let r=t?` properties {
19
+ width`,vu=`_id
20
+ path`;function Bn(e){return e?be(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function xr(e,t){return !e||!Bn(e)?false:t?.name!==b$8.name||e.name!=="assets"}function Eo(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ao(e){let t=e,n=t?.edges??[],o=t?.aggregate?.count?.nodes??n.length;return n.reduce((r,i,s)=>(i.node&&r.push({...i.node,sortOrder:i.properties?.sortOrder??s,totalCount:o}),r),[]).sort((r,i)=>(r.sortOrder??Number.MAX_SAFE_INTEGER)-(i.sortOrder??Number.MAX_SAFE_INTEGER))}function zn(e){return e.reduce((t,n,o)=>n._id?{...t,[n._id]:n.sortOrder??o}:t,{})}function Et(e){return Array.isArray(e)?e[0]??null:e??null}function bu(e,t){return t?vu:e?Cr:wr}function ea(e,t=true,n=true,o=So,r=false){let i=t?` properties {
20
21
  sortOrder
21
22
  }
22
- `:"",i=n?gr:vo,a=t?`(first: ${o}, sort: [{ edge: { sortOrder: ASC } }])`:`(first: ${o})`;return ` ${e}Connection${a} {
23
+ `:"",s=bu(n,r),l=t?`(first: ${o}, sort: [{ edge: { sortOrder: ASC } }])`:`(first: ${o})`;return ` ${e}Connection${l} {
23
24
  aggregate {
24
25
  count {
25
26
  nodes
26
27
  }
27
28
  }
28
29
  edges {
29
- `+r+` node {
30
- ${i}
30
+ `+i+` node {
31
+ ${s}
31
32
  }
32
33
  }
33
34
  }
34
- `}function mr(e){return e?.aggregate?.count?.nodes??0}function ho(e,t=""){return ` ${e}Connection${t} {
35
+ `}function ta(e){return e?.aggregate?.count?.nodes??0}function na(e,t){let n=e[`${t}Total`];return typeof n=="number"?n:ta(e[`${t}Connection`])}function Sr(e,t=""){return ` ${e}Connection${t} {
35
36
  aggregate {
36
37
  count {
37
38
  nodes
38
39
  }
39
40
  }
40
41
  }
41
- `}function Ra(e){return e.find(t=>t.isPrimary)??e[0]}function zc(e,t,n){if(!e)return "";let o=t==="default"?"":`${t}
42
- `;if(Ln(e))return ` ${e.name} {
43
- ${gr}
42
+ `}function Cu(e,t,n){return t?n==="total"?` ${e}Total
43
+ `:Sr(e,"(where: $where)"):""}function wu(e,t,n,o=false){if(!e)return "";let r=t==="default"?"":`${t}
44
+ `;if(Eo(e))return o?` ${e.name} {
45
+ _id
46
+ path
47
+ }
48
+ `:` ${e.name} {
49
+ ${Cr}
44
50
  }
45
- `;if(ue(e)==="local")return ` ${e.name} {
51
+ `;if(be(e)==="local")return ` ${e.name} {
46
52
  _id
47
53
  default
48
- ${o}}
49
- `;if(ue(e)==="relationship"){let r=e.relationship?.field;if(!r)return ` ${e.name}
50
- `;let i=find(propEq(e.relationship?.entity,"name"))(n),a=find(propEq(r,"name"))(i?.attributes??[]),s=a&&ue(a)==="local"?`{
54
+ ${r}}
55
+ `;if(be(e)==="relationship"){let i=e.relationship?.field;if(!i)return ` ${e.name}
56
+ `;let s=find(propEq(e.relationship?.entity,"name"))(n),l=find(propEq(i,"name"))(s?.attributes??[]),c=l&&be(l)==="local"?`{
51
57
  _id
52
58
  default
53
- ${o}}
59
+ ${r}}
54
60
  `:"";return e.relationship?.mode==="single"?` ${e.name} {
55
- ${r} ${s}}
61
+ ${i} ${c}}
56
62
  `:` ${e.name} (limit: 3, offset: 0) {
57
- ${r} ${s}}
63
+ ${i} ${c}}
58
64
  `}return ` ${e.name}
59
- `}function jc(e,t,n){return e?.attributes.reduce((o,r)=>{let i=t==="default"?"":`${t}
60
- `;if(Ln(r))return `${o}
65
+ `}function xu(e,t,n){return e?.attributes.reduce((o,r)=>{let i=t==="default"?"":`${t}
66
+ `;if(Eo(r))return `${o}
61
67
  ${r.name} {
62
- ${vo}
68
+ ${wr}
63
69
  }
64
- `;if(ue(r)==="local")return `${o}
70
+ `;if(be(r)==="local")return `${o}
65
71
  ${r.name} {
66
72
  _id
67
73
  default
68
74
  ${i}
69
75
  }
70
- `;if(ue(r)==="relationship"){let a=find(propEq(r.relationship?.entity,"name"))(n),s=find(propEq(r.relationship?.field,"name"))(a?.attributes??[]),l=ue(s)==="local"?`{
76
+ `;if(be(r)==="relationship"){let s=find(propEq(r.relationship?.entity,"name"))(n),l=find(propEq(r.relationship?.field,"name"))(s?.attributes??[]),c=be(l)==="local"?`{
71
77
  _id
72
78
  default
73
79
  ${i}}
74
80
  `:"";if(r.relationship?.mode==="single")return `${o}
75
81
  ${r.name} {
76
- ${r.relationship.field} ${l}}
82
+ ${r.relationship.field} ${c}}
77
83
  `;if(r.relationship?.field)return `${o}
78
- ${r.name} (limit: ${ko}, offset: 0) {
79
- ${r.relationship.field} ${l}}
84
+ ${r.name} (limit: ${Ys}, offset: 0) {
85
+ ${r.relationship.field} ${c}}
80
86
  `}return `${o}
81
87
  ${r.name}
82
- `},"")??""}function wo(e,t,n,o){let r=o?.selection??"full",i=o?.includeCount??true,a="(where: $where, limit: $limit, offset: $offset, sort: $sort)",s=Ct(n,e),l=s?.name??e,c=s?.attributes??[],f=`$where: ${l}Where, $limit: Int, $offset: Int, $sort: [${l}Sort!]`,m=`Get${nt(e)}`;if(!s)throw new Error(`Entity '${l}' not found in the schema`);if(c.length===0)throw new Error(`Entity '${l}' has no attributes defined in the schema`);let u=pe("global",c).filter(E=>!(E==="_updatedAt"||r==="list"&&E==="lqip")).join(`
83
- `),p=dn(c),d=pe(["local"],c),g=d.reduce((E,w)=>`${E}
84
- ${w} {
88
+ `},"")??""}function Su(e){let t={};for(let n of e)t[n.name]=n;return t}function Ks(e){return !(!e||vr(e.hidden)||e.name==="lqip")}function Eu(e,t){if(!Array.isArray(e)||e.length===0)return;let[n]=e;if(!n||typeof n!="object")return;let[o]=Object.keys(n);if(!o||["_id","_createdAt","_updatedAt"].includes(o))return;let r=t?.attributes.find(i=>i.name===o);if(!(!r||be(r)!=="global"||r.dataType==="asset"))return {NOT:{[o]:{eq:null}}}}function jn(e,t,n,o){let r=o?.selection??"full",i=o?.includeCount??true,s=o?.countMode??"aggregate",l="(where: $where, limit: $limit, offset: $offset, sort: $sort)",c=rt(n,e),a=c?.name??e,u=c?.attributes??[],f=Su(u),m=`$where: ${a}Where, $limit: Int, $offset: Int, $sort: [${a}Sort!]`,p=o?.operationName??`Get${ot(e)}`;if(!c)throw new Error(`Entity '${a}' not found in the schema`);if(u.length===0)throw new Error(`Entity '${a}' has no attributes defined in the schema`);let d=Te("global",u).filter(S=>S==="_updatedAt"?false:r==="list"?Ks(f[S]):true).join(`
89
+ `),g=Hn(u),h=Te(["local"],u).filter(S=>r!=="list"?true:Ks(f[S])),v=h.reduce((S,D)=>`${S}
90
+ ${D} {
85
91
  _id
86
92
  default
87
93
  }
88
- `,""),h=d.reduce((E,w)=>`${E}
89
- ${w} {
94
+ `,""),y=h.reduce((S,D)=>`${S}
95
+ ${D} {
90
96
  _id
91
97
  default
92
98
  ${t}
93
99
  }
94
- `,""),y=t==="default"?g:h,C=r==="list"?`_id
95
- originalFilename
96
- mimeType
97
- path
98
- size
99
- height
100
- width`:`_id
100
+ `,""),C=t==="default"?v:y,x=`_id
101
+ path`;r!=="list"&&(x=`_id
101
102
  originalFilename
102
103
  mimeType
103
104
  path
104
105
  size
105
106
  height
106
107
  width
107
- lqip`,v=p.reduce((E,w)=>`${E}
108
- ${w} {
109
- ${C}
108
+ lqip`);let A=g.reduce((S,D)=>`${S}
109
+ ${D} {
110
+ ${x}
110
111
  }
111
- `,""),D=c.filter(E=>ue(E)==="relationship").reduce((E,w)=>{if(un(w))return `${E}
112
- ${kr(w.name,bo(w,s),r!=="list",r==="list"?Oc:yo)}`;let x=find(propEq(w.relationship?.entity,"name"))(n);if(r==="list"){let M=Ra(x?.attributes??[]),A=zc(M,t,n),R=w.relationship?.mode==="single"?1:3;return `${E}
113
- ${w.name} (limit: ${R}, offset: 0) {
112
+ `,""),N=u.filter(S=>be(S)==="relationship").reduce((S,D)=>{if(r==="list"&&vr(D.hidden))return S;if(Bn(D))return `${S}
113
+ ${ea(D.name,xr(D,c),r!=="list",r==="list"?ku:So,r==="list")}`;let $=find(propEq(D.relationship?.entity,"name"))(n);if(r==="list"){let V=e$4($),F=wu(V,t,n,true),B=D.relationship?.mode==="single"?1:3;return `${S}
114
+ ${D.name} (limit: ${B}, offset: 0) {
114
115
  _id
115
- ${A} }
116
- `}let $=jc(x,t,n);return `${ho(w.name).trim()}${E}
117
- ${w.name} (limit: 25, offset: 0) { _id ${$}}
118
- `},"");return {queryEntityName:e,query:`query ${m}(${f}) {
119
- `+(i?ho(e,"(where: $where)"):"")+` ${e}${a} {
116
+ ${F} }
117
+ `}let O=xu($,t,n);return `${Sr(D.name).trim()}${S}
118
+ ${D.name} (limit: 25, offset: 0) { _id ${O}}
119
+ `},"");return {queryEntityName:e,query:`query ${p}(${m}) {
120
+ `+Cu(e,i,s)+` ${e}${l} {
120
121
  _id
121
122
  _updatedAt
122
- ${u} ${y} ${v} ${D}}
123
+ ${d} ${C} ${A} ${N}}
123
124
  }
124
- `}}function xo(e,t,n,o){let i=Ct(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=mr(n[`${e}Connection`]),s=n[e],l=(f,m)=>{let u=m.name;return f.slice(0,3).map(p=>{if(ue(m)!=="local")return p[u];let d=bt(p[u]);return d?.[t]??d?.default}).join(", ")},c=s.map(f=>{let{_id:m}=f,u=typeof f._updatedAt=="string"?f._updatedAt:"",p=pe("global",i).filter(y=>y!=="_updatedAt").reduce((y,C)=>({...y,[C]:f[C]}),{}),d=pe("local",i).reduce((y,C)=>{let v=bt(f[C]);return {...y,[C]:v?.[t]?v[t]:v?.default}},{}),g=dn(i).reduce((y,C)=>({...y,[C]:bt(f[C])}),{}),h=pe(["relationship"],i).reduce((y,C)=>{let v=find(propEq(C,"name"))(i),b=v.relationship?.entity??"",D=find(propEq(b,"name"))(o),E=Ra(D?.attributes??[]),w=f[C];if(un(v)){let R=Co(f[`${C}Connection`]);return {...y,[C]:R}}if(!E)throw new Error(`There is an error in the schema for the relationship attribute "${C}"`);let x=E.name,$=ue(E);if(v.relationship?.mode==="multiple"){let R=Array.isArray(w)?w:[];return {...y,[C]:l(R,E)}}let M=bt(w);if($==="global")return {...y,[C]:M?.[x]};let A=bt(M?.[x]);return {...y,[C]:A?.[t]??A?.default}},{});return {_id:m,...p,...d,...g,...h,_updatedAt:u}});return {count:a,results:c}}function Pa(e,t,n,o){let i=Ct(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=mr(n[`${e}Connection`]),l=n[e].map(c=>{let f=pe("global",i).reduce((d,g)=>({...d,[g]:{value:c[g],disabled:false,scope:"default",_id:""}}),{}),m=pe("local",i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),y=bt(c[g]);return {...d,[g]:{value:y?Hc(y,t):null,disabled:!!(y&&y[t]===null&&ue(h)==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),u=dn(i).reduce((d,g)=>({...d,[g]:{value:bt(c[g]),disabled:false,scope:"default",_id:""}}),{}),p=pe(["relationship"],i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),y=c[g],C=h.relationship?.mode==="single"?bt(y):y,v=C?._id,b=mr(c[`${g}Connection`]);if(un(h)){let D=Co(c[`${g}Connection`]);return {...d,[g]:{count:b,_id:v,knownAssetSortOrders:$n(D),value:D,disabled:false,scope:t}}}return {...d,[g]:{count:b,_id:v,value:C,disabled:false,scope:t}}},{});return {...f,...m,...u,...p}});return {count:a,results:l}}function Hc(e,t){return Array.isArray(e)?e.reduce((n,o)=>{if(o[t]??o.default){let r={_id:o._id,disabled:o.scope===null&&t!=="default",scope:t,value:o[t]??o.default};n.push(r);}return n},[]):e[t]??e.default??null}function hr(e,t,n,o,r,i,a){let s=Ct(o,e),l=s?.name??e,c=s?.attributes??[],f=On(e);if(c.length===0)return "";let m=Ia(c,i),u=Fa(c,m),p=Jc(t,c,m,n),d=qc(c,r,m),g=Qc(c,r,m),h=e,y=a?.responseFields??$a(o,e,n);return `mutation ${`Update${nt(e)}`}($where: ${l}Where) {
125
- update${f}(
125
+ `}}function To(e,t,n,o){let i=rt(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=na(n,e),l=n[e],c=(u,f)=>{let m=f.name;return u.slice(0,3).map(p=>{if(be(f)!=="local")return p[m];let d=Et(p[m]);return d?.[t]??d?.default}).join(", ")},a=l.map(u=>{let{_id:f}=u,m=typeof u._updatedAt=="string"?u._updatedAt:"",p=Te("global",i).filter(v=>v!=="_updatedAt").reduce((v,y)=>({...v,[y]:u[y]}),{}),d=Te("local",i).reduce((v,y)=>{let C=Et(u[y]);return {...v,[y]:C?.[t]?C[t]:C?.default}},{}),g=Hn(i).reduce((v,y)=>({...v,[y]:Et(u[y])}),{}),h=Te(["relationship"],i).reduce((v,y)=>{let C=find(propEq(y,"name"))(i),x=C.relationship?.entity??"",A=find(propEq(x,"name"))(o),R=e$4(A),N=u[y];if(Bn(C)){let V=Ao(u[`${y}Connection`]);return {...v,[y]:V}}if(!R)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);let S=R.name,D=be(R);if(C.relationship?.mode==="multiple"){let V=Array.isArray(N)?N:[];return {...v,[y]:c(V,R)}}let $=Et(N);if(D==="global")return {...v,[y]:$?.[S]};let O=Et($?.[S]);return {...v,[y]:O?.[t]??O?.default}},{});return {_id:f,...p,...d,...g,...h,_updatedAt:m}});return {count:s,results:a}}function oa(e,t,n,o){let i=rt(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=na(n,e),c=n[e].map(a=>{let u=Te("global",i).reduce((d,g)=>({...d,[g]:{value:a[g],disabled:false,scope:"default",_id:""}}),{}),f=Te("local",i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),v=Et(a[g]);return {...d,[g]:{value:v?Au(v,t):null,disabled:!!(v&&v[t]===null&&be(h)==="local"&&t!=="default"),scope:t,_id:v?v._id:null}}},{}),m=Hn(i).reduce((d,g)=>({...d,[g]:{value:Et(a[g]),disabled:false,scope:"default",_id:""}}),{}),p=Te(["relationship"],i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),v=a[g],y=h.relationship?.mode==="single"?Et(v):v,C=y?._id,x=ta(a[`${g}Connection`]);if(Bn(h)){let A=Ao(a[`${g}Connection`]);return {...d,[g]:{count:x,_id:C,knownAssetSortOrders:zn(A),value:A,disabled:false,scope:t}}}return {...d,[g]:{count:x,_id:C,value:y,disabled:false,scope:t}}},{});return {...u,...f,...m,...p}});return {count:s,results:c}}function Au(e,t){return Array.isArray(e)?e.reduce((n,o)=>{if(o[t]??o.default){let r={_id:o._id,disabled:o.scope===null&&t!=="default",scope:t,value:o[t]??o.default};n.push(r);}return n},[]):e[t]??e.default??null}function Er(e,t,n,o,r,i,s){let l=rt(o,e),c=l?.name??e,a=l?.attributes??[],u=Jn(e);if(a.length===0)return "";let f=ra(a,i,s?.currentUser),m=ia(a,f),p=Du(t,a,f,n),d=Tu(a,r,f),g=Ru(a,r,f),h=e,v=s?.responseFields??aa(o,e,n);return `mutation ${`Update${ot(e)}`}($where: ${c}Where) {
126
+ update${u}(
126
127
  where: $where
127
- update: {${u}${p}${d}${g}
128
+ update: {${m}${p}${d}${g}
128
129
  }
129
130
  ) {
130
131
  ${h} {
131
132
  _id
132
- ${y} }
133
+ ${v} }
133
134
  }
134
135
  }
135
- `}function Ia(e,t){let n=e.map(r=>r.isEditable===false?r.name:"").filter(Boolean),o=omit(n,t);return pick(e.map(r=>r.name),o)}function pe(e,t){return Array.isArray(e)?e.reduce((o,r)=>o.concat(pe(r,t)),[]):t.filter(o=>ue(o)===e&&o.inputType!=="asset").map(o=>o.name)}function dn(e){return e.filter(Ln).map(n=>n.name)}function Fa(e,t,n="update"){let o=pick(pe("global",e),t);return toPairs(o).reduce((i,[a,s])=>{let l=find(propEq(a,"name"))(e),c=Array.isArray(s?.value)?null:s?.value??null,f=yr(l.dataType,c);return n==="create"&&(f===null||f==="")?i:n==="update"?`${i}
136
- ${a}: { set: ${f} }`:`${i}
137
- ${a}: ${f}`},"")}function pr(e){return !e?._id||!e.path?"":e._id}function qc(e,t,n){let o=pick(dn(e),n);return toPairs(o).reduce((a,[s,l])=>{let c=pr(l.value),f=pr(t[s]?.value);if(c===f)return a;let m=f?` {
136
+ `}function ra(e,t,n){let o=Vn(t),r=e.map(s=>St(s.readOnly,{record:o,value:o[s.name],currentUser:n})?s.name:"").filter(Boolean),i=omit(r,t);return pick(e.map(s=>s.name),i)}function Te(e,t){return Array.isArray(e)?e.reduce((o,r)=>o.concat(Te(r,t)),[]):t.filter(o=>be(o)===e&&o.inputType!=="asset").map(o=>o.name)}function Hn(e){return e.filter(Eo).map(n=>n.name)}function ia(e,t,n="update"){let o=pick(Te("global",e),t);return toPairs(o).reduce((i,[s,l])=>{let c=find(propEq(s,"name"))(e),a=Array.isArray(l?.value)?null:l?.value??null,u=Ar(c.dataType,a);return n==="create"&&(u===null||u==="")?i:n==="update"?`${i}
137
+ ${s}: { set: ${u} }`:`${i}
138
+ ${s}: ${u}`},"")}function br(e){return !e?._id||!e.path?"":e._id}function Tu(e,t,n){let o=pick(Hn(e),n);return toPairs(o).reduce((s,[l,c])=>{let a=br(c.value),u=br(t[l]?.value);if(a===u)return s;let f=u?` {
138
139
  disconnect: [{
139
140
  where: {
140
141
  node: {
141
- _id: { eq: ${Se(f)} }
142
+ _id: { eq: ${Ae(u)} }
142
143
  }
143
144
  }
144
145
  }]
145
146
  }
146
- `:"",u=c?` {
147
+ `:"",m=a?` {
147
148
  connect: [{
148
149
  where: {
149
150
  node: {
150
- _id: { eq: ${Se(c)} }
151
+ _id: { eq: ${Ae(a)} }
151
152
  }
152
153
  }
153
154
  }]
154
155
  }
155
- `:"";return `${a}
156
- ${s}: [
157
- ${m}${u} ]`},"")}function Uc(e,t){let n=pick(dn(e),t);return toPairs(n).reduce((i,[a,s])=>{let l=pr(s.value);return l?`${i}
158
- ${a}: {
156
+ `:"";return `${s}
157
+ ${l}: [
158
+ ${f}${m} ]`},"")}function Nu(e,t){let n=pick(Hn(e),t);return toPairs(n).reduce((i,[s,l])=>{let c=br(l.value);return c?`${i}
159
+ ${s}: {
159
160
  connect: [{
160
161
  where: {
161
162
  node: {
162
- _id: { eq: ${Se(l)} }
163
+ _id: { eq: ${Ae(c)} }
163
164
  }
164
165
  }
165
166
  }]
166
- }`:i},"")}function Jc(e,t,n,o){let r=pick(pe("local",t),n);return toPairs(r).reduce((s,[l,c])=>{let f=find(propEq(l,"name"))(t),{dataType:m}=f,u=c.disabled||Array.isArray(c.value)?"null":yr(m,c.value);return c._id?`${s}
167
- ${l}: [{
167
+ }`:i},"")}function Du(e,t,n,o){let r=pick(Te("local",t),n);return toPairs(r).reduce((l,[c,a])=>{let u=find(propEq(c,"name"))(t),{dataType:f}=u,m=a.disabled||Array.isArray(a.value)?"null":Ar(f,a.value);return a._id?`${l}
168
+ ${c}: [{
168
169
  update: {
169
170
  node: {
170
- ${o}: { set: ${u} }
171
+ ${o}: { set: ${m} }
171
172
  }
172
173
  }
173
- }]`:c.disabled||Array.isArray(c.value)||c.value===void 0||c.value===null||c.value===""||u===null||u===""?s:`${s}
174
- ${l}: [{
174
+ }]`:a.disabled||Array.isArray(a.value)||a.value===void 0||a.value===null||a.value===""||m===null||m===""?l:`${l}
175
+ ${c}: [{
175
176
  create: {
176
177
  node: {
177
- _id: ${Se(`${e}:${l}`)}
178
- _type: "${m}"
179
- ${o}: ${u}
178
+ _id: ${Ae(`${e}:${c}`)}
179
+ _type: "${f}"
180
+ ${o}: ${m}
180
181
  }
181
182
  }
182
- }]`},"")}function Qc(e,t,n){let o=pick(pe("relationship",e),n);return toPairs(o).reduce((a,[s,l])=>{let c=find(propEq(s,"name"))(e),{inputType:f,relationship:m}=c;if(f==="relationship"&&m?.mode==="single"){let u=t[s]._id??"",p=l._id??"";if(u===p)return a;let d=u?` {
183
+ }]`},"")}function Ru(e,t,n){let o=pick(Te("relationship",e),n);return toPairs(o).reduce((s,[l,c])=>{let a=find(propEq(l,"name"))(e),{inputType:u,relationship:f}=a;if(u==="relationship"&&f?.mode==="single"){let m=t[l]._id??"",p=c._id??"";if(m===p)return s;let d=m?` {
183
184
  disconnect: [{
184
185
  where: {
185
186
  node: {
186
- _id: { eq: ${Se(u)} }
187
+ _id: { eq: ${Ae(m)} }
187
188
  }
188
189
  }
189
190
  }]
@@ -192,19 +193,19 @@ ${m}${u} ]`},"")}function Uc(e,t){let n=pick(dn(e),t);return toPairs(n).red
192
193
  connect: [{
193
194
  where: {
194
195
  node: {
195
- _id: { eq: ${Se(p)} }
196
+ _id: { eq: ${Ae(p)} }
196
197
  }
197
198
  }
198
199
  }]
199
200
  }
200
- `:"";return `${a}
201
- ${s}: [
202
- ${d}${g} ]`}if(f==="relationship"&&m?.mode==="multiple"){if(m.entity==="_asset")return `${a}${Xc(s,t[s],l)}`;let u=uniq(l.relationships?.disconnect??[]).filter(Boolean),d=(l.relationships?.connect??[]).map(y=>Se(y._id)).join(", "),g=u.length?` {
201
+ `:"";return `${s}
202
+ ${l}: [
203
+ ${d}${g} ]`}if(u==="relationship"&&f?.mode==="multiple"){if(f.entity==="_asset")return `${s}${Fu(l,t[l],c)}`;let m=uniq(c.relationships?.disconnect??[]).filter(Boolean),d=(c.relationships?.connect??[]).map(v=>Ae(v._id)).join(", "),g=m.length?` {
203
204
  disconnect: [
204
- ${u.map(y=>` {
205
+ ${m.map(v=>` {
205
206
  where: {
206
207
  node: {
207
- _id: { eq: ${Se(y)} }
208
+ _id: { eq: ${Ae(v)} }
208
209
  }
209
210
  }
210
211
  }
@@ -219,42 +220,42 @@ ${u.map(y=>` {
219
220
  }
220
221
  }]
221
222
  }
222
- `:"";return !g&&!h?a:`${a}
223
- ${s}: [
224
- ${g}${h} ]`}return `${a}
225
- `},"")}function Xc(e,t,n){let r=(n.relationships?.connect??[]).map((p,d)=>({...p,sortOrder:p.sortOrder??d})),i=r.map(p=>p._id),a={...Gc(t),...t?.knownAssetSortOrders??{},...n.knownAssetSortOrders??{}},s=uniq(n.relationships?.disconnect??[]).filter(p=>p&&!i.includes(p)),l=r.filter(p=>a[p._id]===void 0),c=r.filter(p=>{let d=a[p._id];return d!==void 0&&d!==p.sortOrder}),f=Wc(s),m=Zc(l),u=Kc(c);return !f&&!m&&!u?"":`
223
+ `:"";return !g&&!h?s:`${s}
224
+ ${l}: [
225
+ ${g}${h} ]`}return `${s}
226
+ `},"")}function Fu(e,t,n){let r=(n.relationships?.connect??[]).map((p,d)=>({...p,sortOrder:p.sortOrder??d})),i=r.map(p=>p._id),s={...Pu(t),...t?.knownAssetSortOrders??{},...n.knownAssetSortOrders??{}},l=uniq(n.relationships?.disconnect??[]).filter(p=>p&&!i.includes(p)),c=r.filter(p=>s[p._id]===void 0),a=r.filter(p=>{let d=s[p._id];return d!==void 0&&d!==p.sortOrder}),u=Iu(l),f=Lu(c),m=Mu(a);return !u&&!f&&!m?"":`
226
227
  ${e}: [
227
- ${f}${m}${u} ]`}function Gc(e){let t=e?.value;return Array.isArray(t)?t.reduce((n,o,r)=>{if(typeof o!="object"||!o||!("_id"in o))return n;let{_id:i}=o;if(typeof i!="string"||i.length===0)return n;let a="sortOrder"in o&&typeof o.sortOrder=="number"?o.sortOrder:r;return {...n,[i]:a}},{}):{}}function Wc(e){return e.length===0?"":` {
228
+ ${u}${f}${m} ]`}function Pu(e){let t=e?.value;return Array.isArray(t)?t.reduce((n,o,r)=>{if(typeof o!="object"||!o||!("_id"in o))return n;let{_id:i}=o;if(typeof i!="string"||i.length===0)return n;let s="sortOrder"in o&&typeof o.sortOrder=="number"?o.sortOrder:r;return {...n,[i]:s}},{}):{}}function Iu(e){return e.length===0?"":` {
228
229
  disconnect: [
229
230
  ${e.reduce((n,o)=>`${n} {
230
- where: { node: { _id: { eq: ${Se(o)} } } }
231
+ where: { node: { _id: { eq: ${Ae(o)} } } }
231
232
  }
232
233
  `,"")} ]
233
234
  }
234
- `}function Zc(e){return e.length===0?"":` {
235
+ `}function Lu(e){return e.length===0?"":` {
235
236
  connect: [
236
- ${La(e)} ]
237
+ ${sa(e)} ]
237
238
  }
238
- `}function La(e){return e.reduce((t,n,o)=>{let r=n.sortOrder??o;return `${t} {
239
- where: { node: { _id: { eq: ${Se(n._id)} } } }
239
+ `}function sa(e){return e.reduce((t,n,o)=>{let r=n.sortOrder??o;return `${t} {
240
+ where: { node: { _id: { eq: ${Ae(n._id)} } } }
240
241
  edge: { sortOrder: ${r} }
241
242
  }
242
- `},"")}function Kc(e){return e.length===0?"":e.reduce((n,o,r)=>{let i=o.sortOrder??r;return `${n} {
243
+ `},"")}function Mu(e){return e.length===0?"":e.reduce((n,o,r)=>{let i=o.sortOrder??r;return `${n} {
243
244
  update: {
244
- where: { node: { _id: { eq: ${Se(o._id)} } } }
245
+ where: { node: { _id: { eq: ${Ae(o._id)} } } }
245
246
  edge: { sortOrder: { set: ${i} } }
246
247
  }
247
248
  }
248
- `},"")}function yr(e,t){return Bc.includes(e)?t?.toString()?Se(t.toString()):null:Vc.includes(e)?t==null?null:Se(t.toString()):t==null||t===""?null:t.toString()}function Se(e){return JSON.stringify(e)}function $a(e,t,n){let o=Ct(e,t),r=o?.attributes??[],i=pe("global",r),a=pe("local",r),s=pe("relationship",r),l=i.reduce((c,f)=>`${c}${f}
249
- `,"");return l+=a.reduce((c,f)=>`${c} ${f} {
249
+ `},"")}function Ar(e,t){return yu.includes(e)?t?.toString()?Ae(t.toString()):null:hu.includes(e)?t==null?null:Ae(t.toString()):t==null||t===""?null:t.toString()}function Ae(e){return JSON.stringify(e)}function aa(e,t,n){let o=rt(e,t),r=o?.attributes??[],i=Te("global",r),s=Te("local",r),l=Te("relationship",r),c=i.reduce((a,u)=>`${a}${u}
250
+ `,"");return c+=s.reduce((a,u)=>`${a} ${u} {
250
251
  _id
251
252
  ${n}
252
253
  }
253
- `,""),l+=s.reduce((c,f)=>{let m=find(propEq(f,"name"))(r),u=m?.relationship?.mode??"single";if(un(m))return `${c}${kr(f,bo(m,o))}`;let p=m?.relationship?.entity??"",g=find(propEq(p,"name"))(e)?.attributes??[],h=m?.relationship?.field??"[invalid_relationship_field_name_in_schema]",y=find(propEq(h,"name"))(g),C=ue(y),v="";if(u==="single"&&(C==="global"&&(v=` ${f} {
254
+ `,""),c+=l.reduce((a,u)=>{let f=find(propEq(u,"name"))(r),m=f?.relationship?.mode??"single";if(Bn(f))return `${a}${ea(u,xr(f,o))}`;let p=f?.relationship?.entity??"",g=find(propEq(p,"name"))(e)?.attributes??[],h=f?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(h,"name"))(g),y=be(v),C="";if(m==="single"&&(y==="global"&&(C=` ${u} {
254
255
  _id
255
256
  ${h}
256
257
  }
257
- `),C==="local"&&(v=` ${f} {
258
+ `),y==="local"&&(C=` ${u} {
258
259
  _id
259
260
  ${h} {
260
261
  _id
@@ -262,27 +263,27 @@ ${La(e)} ]
262
263
  ${n}
263
264
  }
264
265
  }
265
- `)),u==="multiple"&&g.length){let b=g.reduce((D,E)=>{if(ue(E)==="local")return `${D} ${E.name} {
266
+ `)),m==="multiple"&&g.length){let x=g.reduce((A,R)=>{if(be(R)==="local")return `${A} ${R.name} {
266
267
  _id
267
268
  default
268
269
  ${n}
269
270
  }
270
- `;if(ue(E)==="relationship"){let w=n==="default"?"":`${n}
271
- `,x=find(propEq(E.relationship?.entity,"name"))(e),$=find(propEq(E.relationship?.field,"name"))(x?.attributes??[]),M=ue($)==="local"?`{
271
+ `;if(be(R)==="relationship"){let N=n==="default"?"":`${n}
272
+ `,S=find(propEq(R.relationship?.entity,"name"))(e),D=find(propEq(R.relationship?.field,"name"))(S?.attributes??[]),$=be(D)==="local"?`{
272
273
  _id
273
274
  default
274
- ${w}}
275
- `:"";if(E.relationship?.mode==="single")return `${D} ${E.name} {
276
- ${E.relationship.field} ${M}}
277
- `;if(E.relationship?.field)return `${D} ${E.name} (limit: ${ko}, offset: 0) {
278
- ${E.relationship.field} ${M}}
279
- `}return Ln(E)?`${D} ${E.name} {
280
- ${vo}
275
+ ${N}}
276
+ `:"";if(R.relationship?.mode==="single")return `${A} ${R.name} {
277
+ ${R.relationship.field} ${$}}
278
+ `;if(R.relationship?.field)return `${A} ${R.name} (limit: ${Ys}, offset: 0) {
279
+ ${R.relationship.field} ${$}}
280
+ `}return Eo(R)?`${A} ${R.name} {
281
+ ${wr}
281
282
  }
282
- `:`${D} ${E.name}
283
- `},"");v=ho(f)+` ${f} (limit: 25, offset: 0) {
284
- ${b} }
285
- `;}return `${c}${v}`},""),l}function Mn(e,t,n){let o=typeof n=="string"?[n]:[...n],r=find(propEq(e,"name"))(t),i=r?.attributes??[],a=On(r?.plural??""),s=Yc(i,o),l=`Delete${nt(r?.plural??e)}`;return e==="_asset"?`mutation ${l}($where: ${e}Where) {
283
+ `:`${A} ${R.name}
284
+ `},"");C=Sr(u)+` ${u} (limit: 25, offset: 0) {
285
+ ${x} }
286
+ `;}return `${a}${C}`},""),c}function Un(e,t,n){let o=typeof n=="string"?[n]:[...n],r=find(propEq(e,"name"))(t),i=r?.attributes??[],s=Jn(r?.plural??""),l=_u(i,o),c=`Delete${ot(r?.plural??e)}`;return e==="_asset"?`mutation ${c}($where: ${e}Where) {
286
287
  delete_assets(
287
288
  where: $where
288
289
  ) {
@@ -290,60 +291,60 @@ ${b} }
290
291
  relationshipsDeleted
291
292
  }
292
293
  }
293
- `:`mutation ${l}($where: ${e}Where) {
294
- delete${a}(
294
+ `:`mutation ${c}($where: ${e}Where) {
295
+ delete${s}(
295
296
  where: $where
296
- ${s?` delete: {
297
- ${s}
297
+ ${l?` delete: {
298
+ ${l}
298
299
  }
299
300
  `:""} ) {
300
301
  nodesDeleted
301
302
  relationshipsDeleted
302
303
  }
303
304
  }
304
- `}function _n(e){let t=typeof e=="string"?[e]:[...e];return t.length===1?{_id:{eq:t[0]}}:{_id:{in:t}}}function Yc(e,t){return pe("local",e).reduce((r,i)=>{let a=t.map(l=>Se(`${l}:${i}`)).join(", "),s=t.length===1?`_id: { eq: ${a} }`:`_id: { in: [${a}] }`;return `${r}
305
+ `}function qn(e){let t=typeof e=="string"?[e]:[...e];return t.length===1?{_id:{eq:t[0]}}:{_id:{in:t}}}function _u(e,t){return Te("local",e).reduce((r,i)=>{let s=t.map(c=>Ae(`${c}:${i}`)).join(", "),l=t.length===1?`_id: { eq: ${s} }`:`_id: { in: [${s}] }`;return `${r}
305
306
  ${i}: [{
306
307
  where: {
307
308
  node: {
308
- ${s}
309
+ ${l}
309
310
  }
310
311
  }
311
- }]`},"")}function vr(e,t,n,o){let r=Ct(t,e),i=r?.attributes??[],a=On(r?.plural??"");if(i.length===0)return "";let s=Ia(i,n),l=Fa(i,s,"create"),c=ef(i,s,"default",o),f=Uc(i,s),m=tf(i,s),u=e,p=$a(t,u,"default");return `mutation ${`Create${nt(e)}`} {
312
- create${a}(
312
+ }]`},"")}function Tr(e,t,n,o,r){let i=rt(t,e),s=i?.attributes??[],l=Jn(i?.plural??"");if(s.length===0)return "";let c=ra(s,n,r?.currentUser),a=ia(s,c,"create"),u=$u(s,c,"default",o),f=Nu(s,c),m=Ou(s,c),p=e,d=aa(t,p,"default");return `mutation ${`Create${ot(e)}`} {
313
+ create${l}(
313
314
  input: [{
314
- _id: ${Se(o)} ${l} ${c}
315
+ _id: ${Ae(o)} ${a} ${u}
315
316
  ${f}
316
317
  ${m}
317
318
  }]
318
319
  ) {
319
- ${u} {
320
+ ${p} {
320
321
  _id
321
- ${p} }
322
+ ${d} }
322
323
  }
323
324
  }
324
- `}function ef(e,t,n,o){let r=pick(pe("local",e),t);return toPairs(r).reduce((s,[l,c])=>{if(c?.value===void 0||c.value===null||c.value==="")return s;let f=find(propEq(l,"name"))(e),m=Array.isArray(c.value)?"null":yr(f.dataType,c.value);return `${s}
325
- ${l}: {
325
+ `}function $u(e,t,n,o){let r=pick(Te("local",e),t);return toPairs(r).reduce((l,[c,a])=>{if(a?.value===void 0||a.value===null||a.value==="")return l;let u=find(propEq(c,"name"))(e),f=Array.isArray(a.value)?"null":Ar(u.dataType,a.value);return `${l}
326
+ ${c}: {
326
327
  create: [{
327
328
  node: {
328
- _id: ${Se(`${o}:${l}`)}
329
- _type: "${f.dataType}"
330
- ${n}: ${m}
329
+ _id: ${Ae(`${o}:${c}`)}
330
+ _type: "${u.dataType}"
331
+ ${n}: ${f}
331
332
  }
332
333
  }]
333
- }`},"")}function tf(e,t){let n=pick(pe("relationship",e),t);return toPairs(n).reduce((i,[a,s])=>{let l=find(propEq(a,"name"))(e),{inputType:c,relationship:f}=l;if(c==="relationship"&&f?.mode==="single"){if(!s._id)return i;let p=`connect: [{
334
+ }`},"")}function Ou(e,t){let n=pick(Te("relationship",e),t);return toPairs(n).reduce((i,[s,l])=>{let c=find(propEq(s,"name"))(e),{inputType:a,relationship:u}=c;if(a==="relationship"&&u?.mode==="single"){if(!l._id)return i;let p=`connect: [{
334
335
  where: {
335
336
  node: {
336
- _id: { eq: ${Se(s._id)} }
337
+ _id: { eq: ${Ae(l._id)} }
337
338
  }
338
339
  }
339
340
  }]
340
341
  `;return `${i}
341
- ${a}: {
342
- ${p} }`}let m=c==="relationship"&&f?.mode==="multiple",u=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(m&&u){let p=s.relationships?.connect??[];if(f?.entity==="_asset"){let h=La(p.map((y,C)=>({...y,sortOrder:y.sortOrder??C})));return `${i}
343
- ${a}: {
342
+ ${s}: {
343
+ ${p} }`}let f=a==="relationship"&&u?.mode==="multiple",m=Array.isArray(l.relationships?.connect)&&l.relationships.connect.length>0;if(f&&m){let p=l.relationships?.connect??[];if(u?.entity==="_asset"){let h=sa(p.map((v,y)=>({...v,sortOrder:v.sortOrder??y})));return `${i}
344
+ ${s}: {
344
345
  connect: [
345
346
  ${h} ]
346
- }`}let d=p.map(h=>Se(h._id)).join(", "),g=d?`connect: {
347
+ }`}let d=p.map(h=>Ae(h._id)).join(", "),g=d?`connect: {
347
348
  where: {
348
349
  node: {
349
350
  _id: { in: [${d}] }
@@ -351,97 +352,43 @@ ${h} ]
351
352
  }
352
353
  }
353
354
  `:"";return `${i}
354
- ${a}: {
355
+ ${s}: {
355
356
  ${g} }`}return `${i}
356
- `},"")}function Ma({attributeName:e,relatedEntityName:t,scope:n,schema:o}){let r="(where: $where, limit: $limit, offset: $offset, sort: $sort)",i=find(propEq(t,"name"))(o),a=i?.attributes??[],s=`$where: ${t}Where, $limit: Int, $offset: Int, $sort: [${t}Sort!]`,l=i?.plural??"",c=`GetRelated${nt(l||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let f=pe("global",a).filter(v=>v!=="_updatedAt").join(`
357
- `),m=pe(["local"],a),u=m.reduce((v,b)=>`${v}
358
- ${b} {
359
- _id
360
- default
361
- }
362
- `,""),p=m.reduce((v,b)=>`${v}
363
- ${b} {
364
- _id
365
- default
366
- ${n}
367
- }
368
- `,""),d=n==="default"?u:p,h=dn(a).reduce((v,b)=>`${v}
369
- ${b} {
370
- _id
371
- originalFilename
372
- mimeType
373
- path
374
- size
375
- height
376
- width
377
- lqip
378
- }
379
- `,""),C=a.filter(v=>ue(v)==="relationship").reduce((v,b)=>{if(un(b))return `${v}
380
- ${kr(b.name,bo(b,i))}`;let E=find(propEq(b.relationship?.entity,"name"))(o)?.attributes.reduce((w,x)=>{let $=n==="default"?"":`${n}
381
- `;if(Ln(x))return `${w}
382
- ${x.name} {
383
- ${vo}
384
- }
385
- `;if(ue(x)==="local")return `${w}
386
- ${x.name} {
387
- _id
388
- default
389
- ${$}}
390
- `;if(ue(x)==="relationship"){let M=find(propEq(x.relationship?.entity,"name"))(o),A=find(propEq(x.relationship?.field,"name"))(M?.attributes??[]),R=ue(A)==="local"?`{
391
- _id
392
- default
393
- ${$}}
394
- `:"";if(x.relationship?.mode==="single")return `${w}
395
- ${x.name} {
396
- ${x.relationship.field} ${R}}
397
- `;if(x.relationship?.field)return `${w}
398
- ${x.name} (limit: ${ko}, offset: 0) {
399
- ${x.relationship.field} ${R}}
400
- `}return `${w}
401
- ${x.name}
402
- `},"");return `${v}
403
- ${b.name} (limit: ${ko}, offset: 0) { _id ${E??""}}
404
- `},"");return {queryEntityName:l,query:`query ${c}(${s}) {
405
- `+ho(e,"(where: $where)")+` ${l}${r} {
406
- _id
407
- _updatedAt
408
- ${f} ${d} ${h} ${C} }
409
- }
410
- `}}function _a({attributeName:e,entityName:t,entityNamePlural:n,schema:o}){let r=Ct(o,n),i=find(propEq(e,"name"))(r?.attributes??[]),a=bo(i,r),s=a?` properties {
357
+ `},"")}function la({relatedEntityName:e,scope:t,schema:n}){let r=find(propEq(e,"name"))(n)?.plural??"";return r?jn(r,t,n,{selection:"list",operationName:`GetRelated${ot(r)}`}):{queryEntityName:"",query:""}}function ca({attributeName:e,entityName:t,entityNamePlural:n,schema:o}){let r=rt(o,n),i=find(propEq(e,"name"))(r?.attributes??[]),s=xr(i,r),l=s?` properties {
411
358
  sortOrder
412
359
  }
413
- `:"",l=a?"(first: $first, sort: [{ edge: { sortOrder: ASC } }])":"(first: $first)",c=`Get${nt(t)}AssetConnection`;return {queryEntityName:n,query:`query ${c}($where: ${t}Where, $first: Int) {
360
+ `:"",c=s?"(first: $first, sort: [{ edge: { sortOrder: ASC } }])":"(first: $first)",a=`Get${ot(t)}AssetConnection`;return {queryEntityName:n,query:`query ${a}($where: ${t}Where, $first: Int) {
414
361
  ${n}(where: $where) {
415
- ${e}Connection${l} {
362
+ ${e}Connection${c} {
416
363
  aggregate {
417
364
  count {
418
365
  nodes
419
366
  }
420
367
  }
421
368
  edges {
422
- `+s+` node {
423
- ${gr}
369
+ `+l+` node {
370
+ ${Cr}
424
371
  }
425
372
  }
426
373
  }
427
374
  }
428
375
  }
429
- `}}var On=e=>e.charAt(0).toUpperCase()+e.slice(1);function nt(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(On).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function Ct(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}function Oa(e,t,n){if(!e||typeof e!="object")return {};let o=Ct(n,t);if(!o)return {};let r=`update${On(t)}`,i=e[r];if(!i||typeof i!="object")return {};let a=i[t],s=Array.isArray(a)?a[0]:void 0;return !s||typeof s!="object"?{}:o.attributes.reduce((l,c)=>{if(ue(c)!=="local")return l;let m=bt(s[c.name])?._id;return typeof m!="string"||m.length===0?l:{...l,[c.name]:m}},{})}var So=null,br=new Set,Va=[],Cr=new Set,wr=new Set,xr=new Set;function Ge(e,t){if(e==="_asset"||e==="_assets")return `Get${nt(a$f.plural)}`;let n=t.find(i=>i.plural===e),o=t.find(i=>i.name===e),r=n?.plural??o?.plural??e;return `Get${nt(r)}`}function Ba(e){return Cr.add(e),()=>{Cr.delete(e);}}function za(e){return wr.add(e),()=>{wr.delete(e);}}function ja(e){return xr.add(e),()=>{xr.delete(e);}}function Eo(e,t,n){let o=new Set(n.filter(Boolean));if(o.size>0)for(let r of wr)r(t,o);return wt(e,t)}function Ha(e,t){let n=t.filter(o=>!!o._id);if(n.length!==0)for(let o of xr)o(e,n);}function wt(e,t){return br.add(t),new Promise((n,o)=>{Va.push({resolve:n,reject:o}),So&&clearTimeout(So),So=setTimeout(()=>{let r=new Set(br),i=Va.splice(0);br.clear(),So=null,Promise.all([...Cr].map(a=>Promise.resolve(a(r)))).then(()=>{for(let{resolve:a}of i)a();}).catch(a=>{console.error("Error refreshing entity lists:",a);for(let{reject:s}of i)s(a);});},50);})}function Sr({action:e}){let{projects:t,currentProjectId:n}=d(),{schema:o}=find(propEq(n??"","projectId"))(t),r=useApolloClient(),[i,a,s]=vt(),l=de(),c=useRef(false),f=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],m=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),u=!!e.payload.silent,p=f.length>1;if(useEffect(()=>{!u||c.current||(c.current=true,g());},[u]),u)return jsx(Fragment,{});let d$1={dialogTitle:p?`Delete ${f.length} ${m}s`:`Delete ${m}`,dialogMessage:p?`Are you sure you want to delete the selected ${m}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${m}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>g()};function g(){let h=Mn(e.payload.entityName,o,f);return new Promise((y,C)=>{a(gql`
376
+ `}}var Jn=e=>e.charAt(0).toUpperCase()+e.slice(1);function ot(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(Jn).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function rt(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}function ua(e,t,n){if(!e||typeof e!="object")return {};let o=rt(n,t);if(!o)return {};let r=`update${Jn(t)}`,i=e[r];if(!i||typeof i!="object")return {};let s=i[t],l=Array.isArray(s)?s[0]:void 0;return !l||typeof l!="object"?{}:o.attributes.reduce((c,a)=>{if(be(a)!=="local")return c;let f=Et(l[a.name])?._id;return typeof f!="string"||f.length===0?c:{...c,[a.name]:f}},{})}var No=null,Nr=new Set,fa=[],Dr=new Set,Rr=new Set,Fr=new Set;function Ke(e,t){if(e==="_asset"||e==="_assets")return `Get${ot(a$f.plural)}`;let n=t.find(i=>i.plural===e),o=t.find(i=>i.name===e),r=n?.plural??o?.plural??e;return `Get${ot(r)}`}function da(e){return Dr.add(e),()=>{Dr.delete(e);}}function ma(e){return Rr.add(e),()=>{Rr.delete(e);}}function pa(e){return Fr.add(e),()=>{Fr.delete(e);}}function Do(e,t,n){let o=new Set(n.filter(Boolean));if(o.size>0)for(let r of Rr)r(t,o);return At(e,t)}function ga(e,t){let n=t.filter(o=>!!o._id);if(n.length!==0)for(let o of Fr)o(e,n);}function At(e,t){return Nr.add(t),new Promise((n,o)=>{fa.push({resolve:n,reject:o}),No&&clearTimeout(No),No=setTimeout(()=>{let r=new Set(Nr),i=fa.splice(0);Nr.clear(),No=null,Promise.all([...Dr].map(s=>Promise.resolve(s(r)))).then(()=>{for(let{resolve:s}of i)s();}).catch(s=>{console.error("Error refreshing entity lists:",s);for(let{reject:l}of i)l(s);});},50);})}function Pr({action:e}){let{projects:t,currentProjectId:n}=d(),{schema:o}=find(propEq(n??"","projectId"))(t),r=useApolloClient(),[i,s,l]=xt(),c=ge(),a=useRef(false),u=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],f=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),m=!!e.payload.silent,p=u.length>1;if(useEffect(()=>{!m||a.current||(a.current=true,g());},[m]),m)return jsx(Fragment,{});let d$1={dialogTitle:p?`Delete ${u.length} ${f}s`:`Delete ${f}`,dialogMessage:p?`Are you sure you want to delete the selected ${f}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${f}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>g()};function g(){let h=Un(e.payload.entityName,o,u);return new Promise((v,y)=>{s(gql`
430
377
  ${h}
431
- `),s({variables:{where:_n(f)},update(v){for(let b of f)v.evict({id:b});},onCompleted:()=>{toast.success(p?"Items successfully deleted.":"Item successfully deleted."),Eo(r,Ge(e.payload.entityName,o),f),l({type:"Dismiss",_id:e._id,payload:{}}),y();},onError:v=>{C(v);}}),i(true);})}return jsx(Pn,{options:d$1})}var Ua=createContext({isDirty:false,setIsDirty:e=>{}}),Ja=({children:e})=>{let[t,n]=useState(false),o=useMemo(()=>({isDirty:t,setIsDirty:i=>{n(i);}}),[t,n]);return jsx(Ua.Provider,{value:o,children:e})};function mn(){return useContext(Ua)}function Er(e,t){return !t||t.length===0||e===void 0?true:e.some(n=>t.includes(n))}function pn(e,t){return e.filter(n=>Er(t,n.spaces))}function kf(e,t){return e.filter(n=>Er(t,n.spaces)).map(n=>({...n,attributes:pn(n.attributes,t)}))}var vf=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];async function Tr(e,t){let n=new URLSearchParams({filename:e.name}),o=await fetch(`${c$5(t).assets}?${n.toString()}`,{method:"POST",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!o.ok)throw new Error(`Upload failed for ${e.name}`);let r=await o.json(),i={_id:r._id,path:r.path??"",originalFilename:r.originalFilename??e.name,size:r.size??e.size,mimeType:r.mimeType??e.type,lqip:r.lqip??"",width:r.width??0,height:r.height??0};return {pathname:i.path,lqip:i.lqip||void 0,originalFilename:i.originalFilename,size:i.size,mimeType:i.mimeType,width:i.width||void 0,height:i.height||void 0,_id:i._id,asset:i}}async function bf(e){let{projectId:t,accept:n,multiple:o=true,maxBytes:r=4*1024*1024}=e,i=document.createElement("input");i.type="file";let a=n??vf.join(",");i.accept=a,i.multiple=o,i.style.display="none",document.body.appendChild(i);try{let s=await new Promise(f=>{i.onchange=()=>f(i.files),i.click();});if(!s||s.length===0)return [];let l=[];for(let f of Array.from(s)){if(f.size>r){toast.error(`File size too big (max ${(r/(1024*1024)).toFixed(0)}MB): ${f.name}`);continue}l.push(f);}let c=await Promise.all(l.map(async f=>Tr(f,t)));return c.length>0&&toast.success(`Uploaded ${c.length} file${c.length>1?"s":""}`),c}catch(s){return console.error(s),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}function Vn(){let e=useApolloClient();return useCallback(async t=>{let n=await bf(t);return n.length>0&&await wt(e,"GetAssets").catch(o=>{console.error("Error refreshing asset lists after upload:",o);}),n},[e])}function gn(e,t,n){useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o);}},[t,e,n]),useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",o),()=>{document.removeEventListener("mousedown",o);}},[t,e]);}function es({control:e$1,entityId:t,fieldSchema:n,getValues:o,setValue:r}){let{name:i$2,label:a,options:s}=n,{projectId:l}=useParams(),c$1=de(),f$1=d$2(),{relationships:m$1}=c$2(),[u,p]=useState(false),d=useRef(null),g$1=useRef(null),h$2=useRef(null),[y,C]=useState(null),[v,b]=useState(false),[D,E]=useState(false),w=useId(),x=useId();gn(g$1,p,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let T=m$1[x]?.connect;if(!T||h$2.current===T._id)return;let k=If(T.value);if(!k)return;let V=o(i$2);h$2.current=T._id,C(null),r(i$2,{...V,value:k});},[o,i$2,x,m$1,r]);function $(T){if(!T)return;let k={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(k[T])return k[T];let V=T.split("/");if(V.length===2){let[,W]=V;return W.includes("svg")?"svg":W.toLowerCase()}}function M(T,k){if(T&&T.includes(".")){let W=T.split(".").pop();if(W)return W.toLowerCase()}let V=$(k);return V||"file"}async function A(T,k){if(!T)return;let V=Dr("4MB");if(T.size>(V??0)){toast.error("File size too big (max 4MB)");return}let W=T.type.startsWith("image/");if(h$2.current=null,W){let ee=new FileReader;ee.onload=_=>{C(_.target?.result);},ee.readAsDataURL(T);}else C(null);E(true);try{let ee=await Tr(T,l);r(i$2,{...o(i$2),value:ee.asset});}catch(ee){console.error(ee),C(null),r(i$2,{...o(i$2),value:{_id:k?.value?._id}});}finally{E(false);}}function R(T){T.stopPropagation(),h$2.current=null,r(i$2,{...o(i$2),_id:"",value:{_id:o(i$2)?.value?._id}});}function j(T,k){T.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function H(T){T.preventDefault(),T.stopPropagation(),d.current?.click();}function G(T){T.preventDefault(),T.stopPropagation(),p(false);let k=o(i$2)?.value,V=h$2.current??Ff(k),W=V?{_id:V,value:k}:void 0;f$1({type:"setRelationship",payload:{[x]:{connect:W,disconnect:[]}}}),window.setTimeout(()=>{c$1({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:W,relationshipId:x,mode:"single"}});},0);}function Z(T,k){T.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$2,render:({field:T})=>jsxs(e,{children:[jsx(f,{htmlFor:w,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${i$2}`,"aria-expanded":u,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${v?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),g$1.current?.focus(),g$1.current?.click(),p(true);},onKeyDown:k=>{k.key==="Enter"&&p(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),p(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),b(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),b(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),b(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),b(false);let V=k.dataTransfer.files&&k.dataTransfer.files[0];A(V,T.value);},ref:g$1,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!T.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",id:w,onClick:H,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",onClick:G,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,T.value?.value?.path&&!u?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=T.value?.value,V=k?.mimeType,W=k?.path||"";if(!!(V&&V.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(W)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let _=M(k.originalFilename,k.mimeType),B=defaultStyles[_];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:_,...B||{}})})})(),Dr((T.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(T.value?.value).mimeType,(T.value?.value).width&&(T.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(T.value?.value).width,"x",(T.value?.value).height,"px"]}):null]}):null,!T.value?.value?.path&&y&&jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("img",{src:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!T.value?.value?.path&&!y&&D?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("div",{className:"fk:w-7 fk:h-7 fk:mr-2 fk:rounded-sm fk:bg-muted fk:flex fk:items-center fk:justify-center",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,T.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$1,{onClick:H,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:G,children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$1,{onClick:k=>Z(k,T.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>j(k,T.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$1,{onClick:R,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!u&&(T.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(g$1.current?.focus(),g$1.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),u&&(T.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),p(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),g$1.current?.blur(),p(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(i$1,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:p,open:u&&(!!T.value?.value?.path||!!y),children:jsx(k,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$2}`,children:T.value?.value?.path?(()=>{let k=T.value?.value,V=k?.mimeType,W=k?.path||"";if(!!(V&&V.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(W)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let _=M(k.originalFilename,k.mimeType),B=defaultStyles[_];return jsxs("div",{className:"fk:w-full fk:h-full fk:rounded-md fk:bg-muted/40 fk:flex fk:flex-col fk:items-center fk:justify-center fk:text-muted-foreground",children:[jsx("div",{className:"fk:w-16 fk:h-16 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:_,...B||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Dr(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),D?jsx("div",{className:"fk:absolute fk:m-0! fk:top-0 fk:left-0 fk:right-0 fk:bottom-0 fk:w-full fk:bg-muted-foreground/5 fk:overflow-hidden",children:jsx("div",{className:"fk:animate-progress fk:w-full fk:h-full fk:bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:s?.accept?s.accept:"image/*",className:"fk:hidden",id:`file-upload-${i$2}`,onChange:k=>{let V=k.currentTarget.files&&k.currentTarget.files[0];A(V,T.value);},ref:d,type:"file"}),jsx(i,{})]})})}function If(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function Ff(e){return !e?._id||e._id.includes(":")?"":e._id}function ts({control:e$1,fieldSchema:t,setValue:n}){let{name:o,label:r,isEditable:i$1,options:a,dataType:s}=t,l=useId();function c$1(m,u){let p=m.currentTarget.value,d;p===""?d="":(d=s==="float"?parseFloat(p):parseInt(p,10),isNaN(d)&&(d="")),n(o,{...u,value:d});}function f$1(m,u){n(o,{...u,disabled:m});}return jsx(c,{control:e$1,name:o,render:({field:m})=>jsxs(e,{children:[jsx(f,{htmlFor:l,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$7,{className:`fk:w-full fk:mt-[0.1875rem] ${!m.value?.scope||m.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||m.value?.disabled,id:l,...m,onChange:u=>{c$1(u,m.value);},step:s==="float"?"any":"1",type:"number",value:m.value?.value??""})}),jsx(a$6,{checked:m.value?.disabled??false,onChange:u=>{f$1(u,m.value);},scope:m.value?.scope}),jsx(i,{})]})})}function kn({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function hn({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Mt({className:e,align:t="center",sideOffset:n=4,...o}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:n,className:a$4("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...o})})}function os({className:e,classNames:t,showOutsideDays:n=true,captionLayout:o="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let l=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:n,className:a$4("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:o,formatters:{formatMonthDropdown:c=>c.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",l.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",l.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",l.month),nav:a$4("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",l.nav),button_previous:a$4(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",l.button_previous),button_next:a$4(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",l.button_next),month_caption:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",l.month_caption),dropdowns:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",l.dropdowns),dropdown_root:a$4("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",l.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",l.dropdown),caption_label:a$4("fk:font-medium fk:select-none",o==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",l.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",l.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",l.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",l.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",l.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",l.week_number),day:a$4("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",s.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",l.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",l.range_start),range_middle:a$4("fk:rounded-none",l.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",l.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",l.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",l.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",l.disabled),hidden:a$4("invisible",l.hidden),...t},components:{Root:({className:c,rootRef:f,...m})=>jsx("div",{"data-slot":"calendar",ref:f,className:a$4(c),...m}),Chevron:({className:c,orientation:f,...m})=>f==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",c),...m}):f==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",c),...m}):jsx(ChevronDownIcon,{className:a$4("size-4",c),...m}),DayButton:Bf,WeekNumber:({children:c,...f})=>jsx("td",{...f,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:c})}),...a},...s})}function Bf({className:e,day:t,modifiers:n,...o}){let r=getDefaultClassNames(),i=Do.useRef(null);return Do.useEffect(()=>{n.focused&&i.current?.focus();},[n.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:a$4("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...o})}function rs({control:e$1,fieldSchema:t,getValues:n,setValue:o}){let{name:r,label:i$1,isEditable:a,options:s}=t,l=useId();function c$1(u,p){o(r,{...p,value:u?u.toISOString():""});}function f$1(u,p){o(r,{...p,disabled:u});}function m(u){u.preventDefault(),o(r,{...n(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:u})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:l,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(kn,{children:[jsx(hn,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!u.value?.value&&"fk:text-muted-foreground",!u.value?.scope||u.value.scope==="default"?"fk:mb-3":""),disabled:a===false||u.value?.disabled,id:l,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:u.value?.value?format(new Date(u.value.value),"PPP")+" at "+format(new Date(u.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[u.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:p=>{p.stopPropagation(),m(p);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(Mt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(os,{mode:"single",selected:u.value?.value?new Date(u.value.value):void 0,onSelect:p=>c$1(p,u.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$7,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let d=p.target.value,[g,h]=d.split(":"),y=u.value?.value?new Date(u.value.value):new Date;y.setHours(parseInt(g)),y.setMinutes(parseInt(h)),o(r,{...u.value,value:y.toISOString()});},type:"time",value:u.value?.value?format(new Date(u.value.value),"HH:mm"):""})]})]})]})}),jsx(a$6,{checked:u.value?.disabled??false,onChange:p=>{f$1(p,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function $e(e){return e??null}var Pr=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let n=$e(e);n&&n.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let n=$e(e);n&&n.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let n=$e(e);n&&n.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let n=document.createElement("input");n.type="file",n.accept="image/*",n.onchange=async()=>{n.files?.length;},n.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(n??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:n??""}).run():n!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(n??"")?e.chain().focus().deleteRange(t).setTweet({src:n??""}).run():n!==null&&alert("Please enter a correct Twitter Link");}}]),is=Command.configure({suggestion:{items:()=>Pr,render:renderItems}});var ss=[{name:"Default",color:"var(--novel-black)"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Yellow",color:"#EAB308"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],ls=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],cs=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=ss.find(({color:i})=>n.isActive("textStyle",{color:i})),r=ls.find(({color:i})=>n.isActive("highlight",{color:i}));return jsxs(kn,{modal:true,open:e,onOpenChange:t,children:[jsx(hn,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:o?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(Mt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),ss.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{n.commands.unsetColor(),i!=="Default"&&n.chain().focus().setColor(a||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:a},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),ls.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{n.commands.unsetHighlight(),i!=="Default"&&n.chain().focus().setHighlight({color:a}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:a},children:"A"}),jsx("span",{children:i})]}),n.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function mu(e){try{return new URL(e),!0}catch{return false}}function pu(e){if(mu(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var us=({open:e,onOpenChange:t})=>{let n=useRef(null),{editor:o}=useEditor();return useEffect(()=>{n.current?.focus();}),o?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$4("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":o.isActive("link")}),children:"Link"})]})}),jsx(Mt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let a=i[0],s=pu(a.value);s&&(o.chain().focus().setLink({href:s}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:n,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:o.getAttributes("link").href||""}),o.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{o.chain().focus().unsetLink().run(),n.current&&(n.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var ms=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleHeading({level:3}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=$e(e);t&&t.chain().focus().clearNodes().toggleBlockquote().run();},isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],ps=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=ms.filter(r=>r.isActive(n)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:o.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:ms.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),o.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var ks=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:n,to:o}=e.state.selection,r=e.state.doc.textBetween(n,o);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$4("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var hs=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:n=>n!=null&&n.isActive("bold"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:n=>n!=null&&n.isActive("italic"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:n=>n!=null&&n.isActive("underline"),command:n=>n?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:n=>n!=null&&n.isActive("strike"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:n=>n!=null&&n.isActive("code"),command:n=>{let o=$e(n);o&&o.chain().focus().toggleCode().run();},icon:CodeIcon}].map(n=>jsx(EditorBubbleItem,{onSelect:o=>{n.command(o);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:o=>o.preventDefault(),variant:"ghost",children:jsx(n.icon,{className:a$4("fk:h-4 fk:w-4",{"fk:text-blue-500":n.isActive(e)})})})},n.name))}):null};function Bn({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var Mu=()=>jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-0.5",children:[jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-500 [animation-delay:-0.3s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 [animation-delay:-0.15s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600"})]}),ys=Mu;function $r({completion:e,onDiscard:t$1}){let{editor:n}=useEditor();return n?jsxs(Fragment,{children:[jsxs(r$1,{children:[jsxs(t,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt({from:o.from,to:o.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(t,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt(o.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r$1,{children:jsxs(t,{onSelect:t$1,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var Wu=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function _r({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r$1,{heading:"Edit or review selection",children:Wu.map(n=>jsxs(t,{onSelect:o=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,o);},className:"fk:flex fk:gap-2 fk:px-4",value:n.value,children:[jsx(n.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),n.label]},n.value))}),jsx(s,{}),jsx(r$1,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let n=t$1.state.selection.from,o=getPrevText(t$1,n);e(o,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function bs({onOpenChange:e}){let{editor:t}=useEditor(),[n,o$1]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(c,f)=>{let m=await fetch(c,f);if(m.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return m},onError:c=>{c.message!=="FK_AI_RATE_LIMIT"&&toast.error(c.message);}}),l=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[l&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(v,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(rd,{children:i})})})}),s&&jsxs("div",{className:"fk:flex fk:h-12 fk:w-full fk:items-center fk:px-4 fk:text-sm fk:font-medium fk:text-muted-foreground fk:text-pink-600",children:[jsx(Bn,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 "}),"AI is thinking",jsx("div",{className:"fk:ml-2 fk:mt-1",children:jsx(ys,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:n,onValueChange:o$1,autoFocus:true,placeholder:l?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:n}}).then(()=>o$1(""));let c=t.state.selection.content(),f=t.storage.markdown.serializer.serialize(c.content);a(f,{body:{option:"zap",command:n}}).then(()=>o$1(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p$1,{children:l?jsx($r,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(_r,{onSelect:(c,f)=>a(c,{body:{option:f}})})})]})]}):null}function Vr({children:e,open:t,onOpenChange:n}){let{editor:o}=useEditor();return useEffect(()=>{o&&(t||removeAIHighlight(o));},[o,t]),o?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{n(false),o.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(bs,{open:t,onOpenChange:n}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),n(true);},size:"sm",children:[jsx(Bn,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var wd=[...a,is];function ws(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function xd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let n=JSON.parse(t);if(ws(n))return n}catch{return}}if(ws(e))return e}function Br({control:e$1,defaultValue:t,fieldSchema:n,setValue:o}){let{name:r,label:i$1,isEditable:a,options:s}=n,[l,c$1]=useState(false),[f$1,m]=useState(false),[u,p]=useState(false),[d,g$1]=useState(false),h$1=useDebouncedCallback((v,b)=>{let D=v.getJSON();o(r,{...b,value:JSON.stringify(D)});},300);function y(v,b){o(r,{...b,disabled:v});}let C=v=>(console.log("Image uploader not yet implemented",v),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:v})=>jsxs(e,{children:[jsx(f,{children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-screen-lg fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:a!==false&&!v.value?.disabled,editorProps:{handleDOMEvents:{keydown:(b,D)=>handleCommandNavigation(D)},handlePaste:(b,D)=>handleImagePaste(b,D,C),handleDrop:(b,D,E,w)=>handleImageDrop(b,D,w,C),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:wd,initialContent:xd(v.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:b})=>{h$1(b,v.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Pr.map(b=>jsxs(EditorCommandItem,{value:b.title,onCommand:D=>b.command?.(D),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted",children:[jsx("div",{className:"fk:flex fk:h-10 fk:w-10 fk:items-center fk:justify-center fk:rounded-md fk:border fk:border-muted fk:bg-background",children:b.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:b.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:b.description})]})]},b.title))})]}),jsxs(Vr,{open:l,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx(ps,{open:f$1,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(us,{open:u,onOpenChange:p}),jsx(g$3,{orientation:"vertical"}),jsx(ks,{}),jsx(g$3,{orientation:"vertical"}),jsx(hs,{}),jsx(g$3,{orientation:"vertical"}),jsx(cs,{open:d,onOpenChange:g$1})]})]},`${r}:${v.value?.scope??t.scope}:${String(v.value?.disabled??t.disabled)}`)})}),jsx(a$6,{checked:v.value?.disabled??false,onChange:b=>{y(b,v.value);},scope:v.value?.scope}),jsx(i,{})]})})}var Fd=yo;function qr({control:e$1,defaultValue:t,entityId:n,entityName:o,entityNamePlural:r,fieldSchema:i$2,schema:a,setValue:s}){let{name:l,label:c$1,options:f$1,relationship:m}=i$2,{projectId:u}=useParams(),p=de(),d=d$2(),{relationships:g$1}=c$2(),h$1=Vn(),y=useId(),C=useId(),v$1=useRef(null),b=useRef([]),D=useRef(null),E=useRef([]),w=useRef(""),x=useRef(t.knownAssetSortOrders??{}),[$,M]=useState(false),A=useMemo(()=>Md(t.value),[t.value]),[R,j]=useState(A),[H,G]=useState(()=>Object.keys(t.knownAssetSortOrders??$n(A)).length),[Z,T]=useState(()=>Math.max(t.count??0,A[0]?.totalCount??0,A.length)),k$1=useMemo(()=>_a({attributeName:l,entityName:o,entityNamePlural:r,schema:a}),[o,r,l,a]),[V,{loading:W}]=useLazyQuery(gql`
432
- ${k$1.query}
433
- `);gn(v$1,M),useEffect(()=>{let I=St(A);b.current=A.map(Q=>Q._id),E.current=[];let U={...t.knownAssetSortOrders??{},...$n(A)};x.current=U,G(Object.keys(U).length),T(Math.max(t.count??0,A[0]?.totalCount??0,A.length)),j(Q=>{let se=St(Q);return I===""&&se!==""&&w.current===se||se===I?Q:(w.current=I,A)});},[t.count,t.knownAssetSortOrders,A]),useEffect(()=>{let I=g$1[C]?.connect;if(!I)return;let U=I.map((le,_e)=>As(le.value,le.sortOrder??_e)).filter(le=>!!le),Q=St(U),se=St(R),ge=D.current;ge===se&&Q!==ge||(D.current=null,Q!==se&&j(U));},[C,g$1,R]),useEffect(()=>{let I=St(R);if(w.current===I)return;let U=R.map((ge,le)=>({_id:ge._id,sortOrder:le,value:{...ge,sortOrder:le}})),Q=R.map(ge=>ge._id),se=E.current.filter(ge=>!Q.includes(ge));w.current=I,d({type:"setRelationship",payload:{[C]:{connect:U,disconnect:se}}}),s(l,{...t,knownAssetSortOrders:x.current,relationships:{connect:U,disconnect:se},value:R});},[d,t,l,C,R,s]);let ee=Math.max(Z,H),_=!!n&&ee>H,B=useCallback(()=>{if(!n||W||!_)return;let I=H+Fd;V({variables:{where:{_id:{eq:n}},first:I}}).then(U=>{let Q=U.data?.[r],ge=(Array.isArray(Q)?Q[0]:void 0)?.[`${l}Connection`],le=Co(ge),_e=le[0]?.totalCount;if(typeof _e=="number"&&T(_e),le.length===0){T(H);return}let z=Object.keys(x.current).length,ne={...x.current,...$n(le)},je=Object.keys(ne).length;x.current=ne,G(je),(le.length<I||je<=z)&&T(je);for(let He of le)b.current.includes(He._id)||(b.current=[...b.current,He._id]);j(He=>{let fe=new Set(He.map(Yn=>Yn._id)),Wo=new Set(E.current),Kn=le.filter(Yn=>!fe.has(Yn._id)&&!Wo.has(Yn._id));if(Kn.length===0)return w.current="",[...He];let wi=[...He,...Kn];return D.current=St(wi),wi});}).catch(U=>{console.error("Error fetching more assets:",U);});},[n,r,V,_,W,H,l]);function K(I){I.preventDefault(),I.stopPropagation(),p({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(R.length,ee),entityName:m?.entity??"_asset",entityId:n,relationshipId:C,mode:"multiple",assetAccept:f$1?.accept}});}async function te(I){I.preventDefault(),I.stopPropagation();let U=await h$1({projectId:u,accept:f$1?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});j(Q=>{let se=new Set(Q.map(_e=>_e._id)),ge=U.map((_e,z)=>({..._e.asset,sortOrder:Q.length+z})).filter(_e=>!se.has(_e._id)),le=jr([...Q,...ge]);return D.current=St(le),le});}function ye(I){j(U=>{let Q=jr(U.filter(se=>se._id!==I));return b.current.includes(I)&&!E.current.includes(I)&&(E.current=[...E.current,I]),D.current=St(Q),Q});}function L(I,U){j(Q=>{let se=Q.findIndex(ne=>ne._id===I),ge=se+U;if(se<0||ge<0||ge>=Q.length)return Q;let le=[...Q],[_e]=le.splice(se,1);if(!_e)return Q;le.splice(ge,0,_e);let z=jr(le);return D.current=St(z),z});}let O=Math.max(R.length,ee),P=R.slice(0,8);return jsx(c,{control:e$1,defaultValue:t,name:l,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:y,children:c$1}),f$1?.comment?jsx(h,{children:f$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${l}`,"aria-expanded":$,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${$?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:I=>{I.preventDefault(),I.stopPropagation(),v$1.current?.focus(),M(true);},ref:v$1,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[$&&R.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[O," ",O===1?"asset":"assets",_?` (${R.length} loaded)`:""," selected"]}):R.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[P.map(I=>jsx(Ld,{asset:I},I._id)),!$&&O>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",O-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:y,onClick:I=>{I.preventDefault(),I.stopPropagation(),M(U=>!U);},size:"icon",variant:"ghost",children:$?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:$?"Close":"Expand field"})})]})})]}),jsx(i$1,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:M,open:$,children:jsx(k,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${l}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:K,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",onClick:I=>{te(I);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),R.length>0?jsxs(v,{className:"fk:min-h-0 fk:flex-1",children:[jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:R.map((I,U)=>jsx($d,{asset:I,index:U,isFirst:U===0,isLast:U===R.length-1,moveAsset:L,removeAsset:ye},I._id))}),_?jsx("div",{className:"fk:flex fk:justify-center fk:py-3 fk:pr-3",children:jsx(b$3,{className:"fk:h-8",disabled:W,onClick:I=>{I.preventDefault(),I.stopPropagation(),B();},type:"button",variant:"outline",children:W?"Loading\u2026":`Load more (${H} of ${ee})`})}):null]}):null]})})})]})})}),jsx(i,{})]})})}function Ld({asset:e}){return Ts(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function $d({asset:e,index:t,isFirst:n,isLast:o,moveAsset:r,removeAsset:i}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:Ts(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:n,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:o,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",onClick:()=>i(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Md(e){return Array.isArray(e)?e.map((t,n)=>As(t,n)).filter(t=>!!t).sort((t,n)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function St(e){return e.map((t,n)=>`${t._id}:${t.sortOrder??n}`).join("|")}function jr(e){return e.map((t,n)=>({...t,sortOrder:n}))}function As(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let n=e;return {_id:String(n._id??""),path:String(n.path??""),originalFilename:String(n.originalFilename??""),size:Number(n.size??0),mimeType:String(n.mimeType??""),lqip:String(n.lqip??""),width:Number(n.width??0),height:Number(n.height??0),sortOrder:n.sortOrder??t,totalCount:typeof n.totalCount=="number"?n.totalCount:void 0}}function Ts(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Ds({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function Mo({column:e,title:t,className:n}){if(!e.getCanSort())return jsx("div",{className:a$4("fk:flex fk:items-center",n),children:t});let o=e.getIsSorted()==="asc",r=e.getIsSorted()==="desc";return jsxs("div",{className:a$4("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",n),children:[jsx("span",{className:"fk:truncate",children:t}),jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsx("button",{"aria-label":`Sort ${t}`,className:"fk:inline-flex fk:shrink-0 fk:items-center fk:justify-center fk:rounded-sm fk:p-0.5 fk:text-muted-foreground fk:outline-hidden fk:hover:bg-accent fk:hover:text-accent-foreground fk:focus-visible:ring-1 fk:focus-visible:ring-ring",type:"button",children:jsx(ChevronDown,{className:"fk:h-3.5 fk:w-3.5"})})}),jsxs(f$2,{align:"end",className:"fk:w-44",children:[jsxs(h$1,{"aria-checked":o,className:a$4(o&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(o){e.clearSorting();return}e.toggleSorting(false);},role:"menuitemcheckbox",children:[jsx(ArrowUp,{className:a$4("fk:h-4 fk:w-4",o&&"fk:text-white")}),"Sort Ascending"]}),jsxs(h$1,{"aria-checked":r,className:a$4(r&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(r){e.clearSorting();return}e.toggleSorting(true);},role:"menuitemcheckbox",children:[jsx(ArrowDown,{className:a$4("fk:h-4 fk:w-4",r&&"fk:text-white")}),"Sort Descending"]})]})]})]})}var Bd=new Set(["text","textarea","number","datetime","switch","select","editor"]);function Un({attributesSchema:e,checkboxSelect:t,actionsComponent:n,enableColumnSorting:o=false}){let{getContributionPointConfig:r}=d(),[,i]=b(),a=pn(e,i.user?.spaces),s={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"select",switch:"boolean",text:"text",textarea:"text"},l={boolean:a$b,date:a$a,datetime:a$e,editor:b$7,asset:a$d,number:a$a,relationship:a$a,select:a$c,switch:a$b,text:a$a,textarea:a$a,tags:Ds},c=a.map(d=>{if(d.name==="_updatedAt")return null;let g=(d.inputType==="relationship"&&d.relationship?.entity==="_asset"?"asset":void 0)??d.previewType??s[d.inputType],h=r("previewFields",[g])?.[0]?.component??l[g]??l.text;if(d.isHidden)return null;let y=g==="tags",C=o&&d.scope==="global"&&Bd.has(d.inputType);return {accessorKey:d.name,filterFn:(v,b,D)=>y?true:(Array.isArray(D)?D:[D]).includes(v.getValue(b)),header:({column:v})=>C?jsx(Mo,{column:v,title:d.label}):jsx("div",{className:"fk:flex fk:items-center",children:d.label}),cell:({row:v})=>{let b=h;return g==="select"?jsx(b,{value:v.getValue(d.name),options:d.options}):jsx(b,{value:v.getValue(d.name)})},enableSorting:C,enableHiding:true,meta:{label:d.label},size:d.options?.size??150}}).filter(d=>d!==null),f={id:"actions",cell:({row:d})=>n?n(d):null,size:80},m={accessorKey:"_updatedAt",header:({column:d})=>o?jsx(Mo,{column:d,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:d})=>jsx(a$e,{value:d.getValue("_updatedAt")}),enableSorting:o,enableHiding:false,meta:{label:"Updated At"},size:220},u={id:"select",cell:({row:d,table:g})=>jsx(j,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:h=>{g.toggleAllPageRowsSelected(false),d.toggleSelected(!!h);}}),enableSorting:false,enableHiding:false,size:50},p={id:"select",header:({table:d})=>jsx(j,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:d.getIsAllPageRowsSelected()||d.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:g=>{d.toggleAllPageRowsSelected(!!g);}}),cell:({row:d})=>jsx(j,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:g=>{d.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[u]:[],...t==="multiple"?[p]:[],...n?[f]:[],...c,m]}var Xd=36;function Ps(e){if(!e)return;let t=e.split(/\s+/);if(t.includes("fk:h-20"))return 80;if(t.includes("fk:h-10"))return 40;if(t.includes("fk:h-9"))return 36}function Gd(e,t){return e??Ps(t)??Xd}function Wd(e){return Math.max(600,e)}function Jn({classNames:e,columns:t,data:n$1,entityName:o,hasMore:r$1=false,initialSelectionState:i,isLoadingMore:a=false,onEntitySelectionChange:s,onLoadMore:l$1,onScroll:c,onSortingChange:f,pageSize:m,rowHeightEstimate:u,rowAdditionState:p$1,rowDeletionState:d,scrollToTopKey:g,sorting:h,toolbarComponent:y}){let C=useRef(null),{schemaErrorMessage:v}=Jt(),[b,D]=useState(i??{}),[E,w]=useState({}),[x,$]=useState([]),[M,A]=useState([]),R=h??M;useEffect(()=>{C.current?.scrollTo({top:0});},[o,g]),useEffect(()=>{if(!i)return;let L=Object.keys(b).sort().join(","),O=Object.keys(i).sort().join(",");L!==O&&D(i);},[i,b]);function j(L){if(f){f(L);return}A(L);}let H=useReactTable({data:n$1,columns:t,state:{sorting:R,columnVisibility:E,rowSelection:b,columnFilters:x},initialState:{pagination:{pageSize:m??50}},enableRowSelection:true,onRowSelectionChange:te,onSortingChange:j,onColumnFiltersChange:$,onColumnVisibilityChange:w,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:L=>L._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:L=>Zd(L,d,p$1)}}),{rows:G}=H.getRowModel(),Z=Gd(u,e?.row),T=Ps(e?.row)!=null,k=useVirtualizer({count:G.length,estimateSize:()=>Z,getScrollElement:()=>C.current,overscan:5}),V=k.getVirtualItems(),W=k.getTotalSize(),ee=useRef(l$1),_=useRef(r$1),B=useRef(a);ee.current=l$1,_.current=r$1,B.current=a;let K=useCallback(L=>{if(!ee.current||!_.current||B.current)return;let O=L??C.current;if(!O)return;let{scrollHeight:P,scrollTop:I,clientHeight:U}=O;P-I-U>=Wd(U)||(B.current=true,ee.current());},[]);useEffect(()=>{K();},[K,G.length,r$1,a]);function te(L){let O=Object.keys(typeof L=="function"?L(b):L);D(L),s?.(O);}function ye(L){c?.(L),K(L.currentTarget);}return v?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:min-w-0 fk:flex-col fk:gap-4",e?.wrapper),children:[y&&y(H),jsx("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1 fk:-mb-px",children:jsxs(l,{className:a$4("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:ye,ref:C,children:[jsx(m$1,{className:"fk:sticky fk:top-0 fk:z-10 fk:grid",children:H.getHeaderGroups().map(L=>jsx(p,{className:"fk:flex fk:w-full",children:L.headers.map(O=>jsxs(q,{className:a$4("fk:flex fk:items-center",O.column.id==="actions"&&"fk:pl-0"),colSpan:O.colSpan,style:O.getSize()?{width:`${O.getSize().toString()}px`}:{},children:[O.isPlaceholder?null:flexRender(O.column.columnDef.header,O.getContext()),a?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-10.25 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-4",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null]},O.id))},L.id))}),jsx(n,{className:"fk:grid fk:relative",style:{height:`${W.toString()}px`},children:V.length?V.map(L=>{let O=G[L.index];return jsx(p,{className:a$4(H.options.meta.getRowBackground(O),"fk:flex fk:absolute fk:w-full fk:overflow-hidden",!T&&u==null&&"fk:h-9",e?.row),"data-index":L.index,"data-state":O.getIsSelected()&&"selected",style:{height:`${Z.toString()}px`,transform:`translateY(${L.start.toString()}px)`},children:O.getVisibleCells().map(P=>jsx(r,{className:a$4("fk:flex fk:items-center fk:truncate",P.column.id==="actions"&&"fk:pl-1!"),style:{width:P.column.getSize()},children:flexRender(P.column.columnDef.cell,P.getContext())},P.id))},L.key)}):jsx(p,{children:jsx(r,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function Zd(e,t,n){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":n?.some(o=>o._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Is({action:e,row:t}){let n=t.original._id;function o(){e(n);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:o,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var um=25;function Gr({control:e$1,defaultScope:t,defaultValue:n,entityId:o,entityName:r,entityNamePlural:i$2,fieldSchema:a,schema:s,scope:l,setValue:c$1}){let[f$1,m]=useState(false),u=useRef(null);gn(u,m);let[p,d]=useState([]),{name:g$1,label:h$1,options:y,relationship:C}=a,v=C?.entity??g$1,b=de(),D=d$2(),{relationships:E}=c$2(),w=useId(),x=useId(),$=find(propEq(v,"name"))(s),M=$?.attributes??[],R=find(propEq(r,"name"))(s)?.name??"",j,H=M.find(P=>P.relationship?.entity===R);H&&(j=H.name);let G=mm(M),Z=useMemo(()=>n.value?pm({data:n.value,defaultScope:t,relationshipEntitySchema:$,scope:l}):[],[t,n,G,$,l]),T=Ma({attributeName:g$1,relatedEntityName:v,scope:l,schema:s}),V=p.length?p.slice(0,12).map(P=>P[G]):[],W=Math.max(p.length,n.count??0)>V.length,[ee,{loading:_,data:B}]=useLazyQuery(gql`
434
- ${T.query}
435
- `),K=Un({attributesSchema:$?.attributes??[],actionsComponent:P=>dm({appDispatch:D,relationshipId:x,relationships:E,row:P,setRows:d})});useEffect(()=>{d(Z),n.value!==""&&D({type:"setRelationship",payload:{[x]:{connect:[],disconnect:[]}}});},[D,B,Z,x,n,l]),useEffect(()=>{c$1(g$1,{...n,relationships:E[x]});},[n,E,x,c$1,g$1]),useEffect(()=>{let I=(E[x]?.connect??[]).map(({value:U})=>U);d(uniqBy(prop("_id"),[...I,...Z]));},[B,n.count,Z,E,x]);let te=n.count??0,ye=te>0&&p.length>0&&p.length<te,L=useCallback(()=>{_||ee({variables:{limit:um,offset:p.length,where:j?{[j]:{some:{_id:{eq:o}}}}:{}}}).then(({data:P})=>{if(!P)return;let I=xo($?.plural??"",l,P,s);d(uniqBy(prop("_id"),[...Z,...I.results]));}).catch(P=>{console.error("Error fetching more data:",P);});},[j,o,ee,Z,_,$?.plural,p.length,s,l]);function O(P){P.preventDefault(),b({type:"EditRelationship",payload:{connectedEntitiesCount:Z.length,connectionName:j,entityName:v,entityId:o,relationshipId:x,mode:C?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:n,name:g$1,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:w,children:h$1}),y?.comment?jsx(h,{children:y.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${g$1}`,"aria-expanded":f$1,className:`fk:relative fk:flex fk:w-full fk:min-w-0 fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${f$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:P=>{P.preventDefault(),P.stopPropagation(),u.current?.focus(),u.current?.click(),m(true);},onKeyDown:P=>{P.key==="Enter"&&m(true),P.key==="Escape"&&(P.preventDefault(),P.stopPropagation(),u.current?.blur(),m(false));},ref:u,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[f$1?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:O,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",$?.menu?.label??$?.plural]}):jsxs("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:[V.map(P=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:P},P)),W?jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:"\u2026"}):null]}),f$1?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:P=>{P.preventDefault(),P.stopPropagation(),u.current?.blur(),m(false);},onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),P.stopPropagation(),u.current?.blur(),m(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:w,onKeyDown:P=>{P.key==="Enter"&&(u.current?.focus(),u.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(i$1,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:m,open:f$1,children:jsx(k,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${g$1}`,children:jsx(Jn,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:K,data:p,entityName:r,hasMore:ye,isLoadingMore:_&&p.length>0,onLoadMore:L,rowAdditionState:E[x]?.connect,rowDeletionState:E[x]?.disconnect})})})})]})})}),jsx(i,{})]})})}function dm({appDispatch:e,relationshipId:t,relationships:n,row:o,setRows:r}){function i(a){let s=n[t]?.connect??[],l=typeof find(propEq(a,"_id"),s)=="object",c=n[t]?.disconnect?.includes(a),f=l?n[t]?.disconnect??[]:uniq([...n[t]?.disconnect??[],a]);l&&r(m=>m.filter(u=>u._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(m=>m._id!==a),disconnect:c?n[t]?.disconnect?.filter(m=>m!==a)??[]:f}}});}return jsx(Is,{action:i,row:o})}function mm(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function pm({data:e,defaultScope:t,relationshipEntitySchema:n,scope:o}){if(!Array.isArray(e))return [];let r=i=>{let s=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";if(s){let l=i[s],c=Array.isArray(l)?l[0]:l;return c&&typeof c=="object"?c[o]??c[t]??"":c}return i[o]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let s=a;return s.length===0?"":s.length===1?r(s[0]):s.slice(0,3).map(r).join(", ")}return a&&typeof a!="string"&&a.__typename?r(a):a},i))}function Wr({control:e$1,defaultScope:t,defaultValue:n,entityId:o,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:l}){let[c$1,f$1]=useState(false),{name:m,label:u,options:p,relationship:d}=r,g$1=d?.entity??m,h$1=de(),y=d$2(),C=useId(),{relationships:v}=c$2(),b=useId(),D=find(propEq(g$1,"name"))(a),w=bm(D?.attributes??[]).name;useEffect(()=>{n.value!==""&&y({type:"setRelationship",payload:{[b]:{connect:{_id:String(n._id),value:n.value},disconnect:[]}}});},[y,b,n,s]),useEffect(()=>{l(m,{...i$1(m),...v[b]?.connect??""});},[n,m,v,b,l]);function x(M){M.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:g$1,entityId:o,relationshipId:b,mode:d?.mode??"single"}});}function $(M){let A={type:"setRelationship",payload:{[b]:{connect:[],disconnect:[]}}};M.preventDefault(),y(A),l(m,{...i$1(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:n,name:m,render:({field:M})=>{let A=M.value?.value,R="";if(A&&typeof A=="object"&&!Array.isArray(A)&&A[w]){let j=A[w],H=Array.isArray(j)?j[0]:j;typeof H=="string"?R=H:R=H?.[s]??H?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:C,children:u}),p?.comment?jsx(h,{children:p.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$7,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:C,onBlur:()=>{f$1(false);},onClick:x,onFocus:()=>{f$1(true);},onKeyDown:j=>{j.key==="Enter"&&x(j);},readOnly:true,type:"text",value:R}),R?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:$,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:x,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i,{})]})}})}function bm(e){return e.find(t=>t.isPrimary)??e[0]}function Zr(e){let{fieldSchema:t}=e,{relationship:n}=t;if(n?.mode==="single")return jsx(Wr,{...e});if(n?.mode==="multiple"){if(n.entity==="_asset")return jsx(qr,{...e});let o={relationshipEntityName:t.relationship?.entity,...e};return jsx(Gr,{...o})}return jsxs(ke,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(ze,{children:"Error"}),jsx(he,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var Vs="flexkit-select-option:";function Kr(e){return `${Vs}${encodeURIComponent(e)}`}function xm(e){return decodeURIComponent(e.slice(Vs.length))}function Bs({control:e$2,fieldSchema:t,setValue:n}){let{name:o,label:r,isEditable:i$1,options:a}=t;function s(c,f){let u=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;n(o,{...f,value:u});}function l(c,f){n(o,{...f,disabled:c});}return jsx(c,{control:e$2,name:o,render:({field:c})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:c.value?.value===void 0||c.value.value===null?void 0:Kr(String(c.value.value)),disabled:i$1===false||c.value?.disabled,onValueChange:f=>{s(xm(f),c.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(f=>"groupLabel"in f?jsxs(b$2,{children:[jsx(f$1,{children:f.groupLabel}),f.items.map(m=>jsx(g$1,{value:Kr(m.value),children:m.label},m.label))]},f.groupLabel):jsx(g$1,{value:Kr(f.value),children:f.label},f.label))})]}),jsx(a$6,{checked:c.value?.disabled??false,onChange:f=>{l(f,c.value);},scope:c.value?.scope}),jsx(i,{})]})})}function ti({inputType:e,label:t}){return jsxs(ke,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(ze,{children:"Error"}),jsx(he,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Mm(e,t){let n=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:n}}function _m({currentScope:e,defaultScope:t,entityId:n,entityName:o,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:l},c){let f=find(propEq(o,"name"))(a),[,m]=b(),u=m.user?.spaces,p=useMemo(()=>pn(f?.attributes??[],u),[f,u]),d$1=useMemo(()=>i||p.reduce((A,R)=>({...A,[R.name]:Mm(R,t)}),{}),[t,i,p]),g=useMemo(()=>{let A={};for(let R of p)typeof R.validation>"u"||(A[R.name]=z.object({value:R.validation(z).or(z.any().refine(()=>false,{error:R.label?`${R.label} is required`:"Required field"}))}));return z.object(A)},[p]),h=useForm({defaultValues:d$1,resolver:zodResolver(g),values:i,mode:"onBlur",criteriaMode:"all"}),{control:y,getValues:C,handleSubmit:v,setValue:b$2,watch:D,trigger:E}=h,{getContributionPointConfig:w}=d(),x=useRef(i),$=useRef(false);useEffect(()=>{$.current||(x.current=i);},[i]);let M={datetime:rs,editor:Br,asset:es,number:ts,relationship:Zr,select:Bs,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){E().then(()=>{v(()=>{let A=C();$.current=true,x.current=A,s(false),l(A,i);})();});},hasErrors(){$.current=false,x.current=i,s(true);},hasDataChanged(){return Hs(C(),x.current)},markAsSaved(){$.current=true,x.current=C(),s(false);},applyLocalAttributeIds(A){let R=C(),j={...R};for(let[H,G]of Object.entries(A)){let Z=R[H];!Z||Z._id||!G||(j[H]={...Z,_id:G});}$.current=true,x.current=j;for(let[H,G]of Object.entries(j))G!==R[H]&&b$2(H,G,{shouldDirty:false,shouldTouch:false,shouldValidate:false});s(false);}})),useEffect(()=>{let A=D(()=>{s(Hs(C(),x.current));});return ()=>{A.unsubscribe();}},[i,C,s,D]),!f||f.attributes.length===0?jsxs(ke,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Error"}),jsxs(he,{children:["No attributes found in the schema for entity ",jsx("strong",{children:o})]})]}):jsx(b$1,{...h,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:p.map(A=>{if(A.name==="_id")return null;let R=w("formFields",[A.inputType])?.[0]?.component??M[A.inputType];return R?createElement(R,{key:A.name,control:y,defaultScope:t,defaultValue:d$1[A.name],entityId:n,entityName:o,entityNamePlural:r,fieldSchema:A,getValues:C,schema:a,scope:e,setValue:b$2}):jsx(ti,{inputType:A.inputType,label:A.label},A.name)})})})}var Ho=memo(forwardRef(_m));function Hs(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let n=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",o=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>o(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:n(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>o(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:n(e[s]?.value),disabled:e[s]?.disabled??false,relationships:Object.keys(e[s]?.relationships?.connect??{}).length||e[s]?.relationships?.disconnect?.length?e[s]?.relationships:void 0}}),{});return !equals(r,i)}function Us(e){return e?e!=="viewer":true}function Et(){let[,e]=b();return Us(e.user?.role)}function ri({action:e,depth:t,isFocused:n}){let{entityName:o}=e.payload,r=useRef(null),i=Et(),{projects:a,currentProjectId:s}=d(),{schema:l,scopes:c}=find(propEq(s??"","projectId"))(a),f=c?.find(M=>M.isDefault)?.name??"default",u$1=find(propEq(o,"name"))(l)?.plural??o,{scope:p}=c$2(),d$1=de(),g=useApolloClient(),[h,y,C,v]=vt(),{isDirty:b,setIsDirty:D}=mn();useEffect(()=>{v.error&&r.current?.hasErrors();},[v.error]);function E(){return b?(d$1({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{d$1({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{d$1({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let w=useCallback(M=>{d$1({type:"Dismiss",_id:M,payload:{}});},[d$1]),x=useCallback(()=>{r.current?.submit();},[r]),$=useCallback(M=>{let A=v4(),R=vr(u$1,l,M,A);y(gql`
436
- ${R}
437
- `),C({onCompleted:()=>{wt(g,Ge(u$1,l)),w(e._id),toast.success("Your changes have been saved.");}}),h(true);},[e._id,g,u$1,w,h,l,y,C]);return jsx(h$2,{actions:jsx(u,{disabled:!i,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{x();},variant:"default",children:[v.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:E,depth:t,isFocused:n,onClose:()=>{w(e._id);},title:`Add ${o}`,children:jsx(Ho,{currentScope:p,defaultScope:f,entityName:o,entityNamePlural:u$1,onSubmit:$,ref:r,schema:l,setIsDirty:D})})}function Xn({entityNamePlural:e,schema:t,scope:n,variables:o,isForm:r,selection:i="full"}){let[a,s]=useState({count:0,results:[]}),[l,c]=useState(false),[f,m]=useState(false),u=useRef(false),p=useRef(false),d=useRef(0),g=useRef(null),h=useRef(null),y=wo(e,n,t,{selection:i}),C=useMemo(()=>gql`
438
- ${y.query}
439
- `,[y.query]),v=wo(e,n,t,{selection:i,includeCount:false}),b=useMemo(()=>gql`
440
- ${v.query}
441
- `,[v.query]),{schemaErrorMessage:D,setSchemaErrorMessage:E}=Jt(),{loading:w,data:x,fetchMore:$,refetch:M,error:A,networkStatus:R}=useQuery(C,{variables:o,notifyOnNetworkStatusChange:true}),j=useRef($),H=useRef(M),G=useRef(b),Z=useRef(R);j.current=$,H.current=M,G.current=b;let T=qt(A),k=po(A),{isProjectDisabled:V,isProjectReadOnly:W}=(()=>{if(T?.statusCode===403){let B=Ut(T.bodyText);if(B&&typeof B.code=="string"){if(B.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(B.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),ee=useCallback(B=>{if(u.current||p.current)return;u.current=true,c(true);let K=B.variables.limit,te=d.current;j.current({...B,query:G.current,variables:{...B.variables,offset:te,limit:K}}).then(({data:ye})=>{let L=Qn({data:ye,entityNamePlural:e,isForm:r,schema:t,scope:n}),O=L.results.length;d.current=te+(O===0?0:Math.min(O,K)),s(P=>{let I=uniqBy(prop("_id"),[...P.results,...L.results]);return I.length===P.results.length?{count:P.results.length,results:P.results}:{count:L.count||P.count,results:I}});}).catch(ye=>{console.error("Error fetching more data:",ye);}).finally(()=>{u.current=false,c(false);});},[e,r,t,n]),_=useCallback(B=>{if(p.current)return Promise.resolve();let K=B?.preserve===true;return p.current=true,u.current=false,c(false),K||(g.current=null,h.current=null,d.current=0,m(true),s({count:0,results:[]})),H.current().then(({data:te})=>{let ye=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),L=Qn({data:te,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=ye,h.current=null,d.current=Jo(o)+L.results.length,s(L);}).catch(te=>{console.error("Error reloading data:",te);}).finally(()=>{p.current=false,m(false);})},[e,r,t,n,i,o]);return useEffect(()=>{if(k){E(k);return}x&&D&&!A&&E(null);},[x,A,D,k,E]),useEffect(()=>{if(A||k)return;let B=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o});if(g.current===B)return;if(w&&h.current!==B){h.current=B,d.current=0,s({count:0,results:[]});return}if(w)return;let K=Qn({data:x,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=B,h.current=null,d.current=Jo(o)+K.results.length,s(K);},[x,e,A,r,w,t,k,n,i,o]),useEffect(()=>{let B=Z.current;if(Z.current=R,A||k||p.current||B!==NetworkStatus.refetch||R!==NetworkStatus.ready||!x)return;let K=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),te=Qn({data:x,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=K,h.current=null,d.current=Jo(o)+te.results.length,s(te);},[x,e,A,r,R,t,k,n,i,o]),useEffect(()=>{if(r)return;let B=`Get${nt(e)}`,K=Ba(L=>{if(!(!L.has(B)||u.current||p.current))return H.current().then(({data:O})=>{let P=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),I=Qn({data:O,entityNamePlural:e,isForm:r,schema:t,scope:n});g.current=P,h.current=null,d.current=Jo(o)+I.results.length,s(I);}).catch(O=>{console.error("Error soft-refreshing entity list:",O);})}),te=za((L,O)=>{L===B&&s(P=>{let I=P.results.filter(Q=>{let se=typeof Q._id=="string"?Q._id:void 0;return !se||!O.has(se)}),U=P.results.length-I.length;return U===0?P:{count:Math.max(0,P.count-U),results:I}});}),ye=ja((L,O)=>{L===B&&s(P=>Gm(P,O,o?.sort));});return ()=>{K(),te(),ye();}},[e,r,t,n,i,o]),{isLoading:w&&R!==NetworkStatus.refetch||f,isLoadingMore:l,fetchMore:ee,reload:_,count:a.count,data:a.results,isProjectDisabled:V,isProjectReadOnly:W,schemaErrorMessage:D}}function Jo(e){let t=e?.offset;return typeof t=="number"&&Number.isFinite(t)?t:0}function Qn(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Pa(e.entityNamePlural,e.scope,e.data,e.schema):xo(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function Gm(e,t,n){let o=new Map(t.map(a=>[a._id,a])),r=false,i=e.results.map(a=>{let s=typeof a._id=="string"?a._id:void 0;if(!s)return a;let l=o.get(s);return l?(r=true,{...a,...l.attributes}):a});return r?{count:e.count,results:Wm(i,n)}:e}function Wm(e,t){if(!Array.isArray(t)||t.length===0)return e;let n=t[0];if(!n||typeof n!="object")return e;let[o,r]=Object.entries(n)[0]??[];if(!o||r!=="ASC"&&r!=="DESC")return e;let i=r==="DESC"?-1:1;return [...e].sort((a,s)=>{let l=a[o],c=s[o],f=typeof l=="string"?l:"",m=typeof c=="string"?c:"";return f.localeCompare(m)*i})}function Ks(){return jsxs(ke,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Read Only Mode"}),jsxs(he,{children:["This project is currently in read only mode and changes cannot be saved. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/read-only-mode",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function li({handleSave:e,isLoading:t}){let{isDirty:n}=mn(),o=Et();return jsx(u,{disabled:!o,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!n||!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})})}function ci(){return jsx(Fragment,{children:Array.from({length:10},(t,n)=>n++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$2,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(r$2,{className:"fk:w-5 fk:mr-2"}),jsx(r$2,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function di({action:e,depth:t,isFocused:n}){let{entityId:o,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:l,scopes:c}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),f=c?.find(_=>_.isDefault)?.name??"default",m=find(propEq(r,"plural"))(l),u=m?.name??r,{scope:p}=c$2(),[d$3,g]=useState(p),h=de(),y=d$2(),C=useApolloClient(),[v,b,D,E]=vt(),{isDirty:w,setIsDirty:x}=mn(),$=useCallback(_=>{x(_);},[x]);useEffect(()=>{E.error&&i.current?.hasErrors();},[E.error]);let M=useCallback(()=>w?(h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[e._id,h,w]),A=useCallback(_=>{h({type:"Dismiss",_id:_,payload:{}});},[h]),R=useCallback(()=>{i.current?.submit();},[i]);function j(_){if(w){h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{g(d$3),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{g(_),y({type:"setScope",payload:{projectId:s,scope:_}});}}}});return}g(_),y({type:"setScope",payload:{projectId:s,scope:_}});}let{isLoading:H,data:G}=Xn({entityNamePlural:r,schema:l,scope:d$3,variables:{where:{_id:{eq:o}}},isForm:true}),Z=useCallback((_,B)=>{if(!B)return;let K=hr(r,o,d$3,l,B,_);b(gql`
378
+ `),l({variables:{where:qn(u)},update(C){for(let x of u)C.evict({id:x});},onCompleted:()=>{toast.success(p?"Items successfully deleted.":"Item successfully deleted."),Do(r,Ke(e.payload.entityName,o),u),c({type:"Dismiss",_id:e._id,payload:{}}),v();},onError:C=>{y(C);}}),i(true);})}return jsx(_n,{options:d$1})}var ha=createContext({isDirty:false,setIsDirty:e=>{}}),ya=({children:e})=>{let[t,n]=useState(false),o=useMemo(()=>({isDirty:t,setIsDirty:i=>{n(i);}}),[t,n]);return jsx(ha.Provider,{value:o,children:e})};function yn(){return useContext(ha)}function Ir(e,t){return !t||t.length===0||e===void 0?true:e.some(n=>t.includes(n))}function vn(e,t){return e.filter(n=>Ir(t,n.spaces))}function Zu(e,t){return e.filter(n=>Ir(t,n.spaces)).map(n=>({...n,attributes:vn(n.attributes,t)}))}var tf=["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 Mr(e,t){let n=new URLSearchParams({filename:e.name}),o=await fetch(`${c$6(t).assets}?${n.toString()}`,{method:"POST",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!o.ok)throw new Error(`Upload failed for ${e.name}`);let r=await o.json(),i={_id:r._id,path:r.path??"",originalFilename:r.originalFilename??e.name,size:r.size??e.size,mimeType:r.mimeType??e.type,lqip:r.lqip??"",width:r.width??0,height:r.height??0};return {pathname:i.path,lqip:i.lqip||void 0,originalFilename:i.originalFilename,size:i.size,mimeType:i.mimeType,width:i.width||void 0,height:i.height||void 0,_id:i._id,asset:i}}async function nf(e){let{projectId:t,accept:n,multiple:o=true,maxBytes:r=4*1024*1024}=e,i=document.createElement("input");i.type="file";let s=n??tf.join(",");i.accept=s,i.multiple=o,i.style.display="none",document.body.appendChild(i);try{let l=await new Promise(u=>{i.onchange=()=>u(i.files),i.click();});if(!l||l.length===0)return [];let c=[];for(let u of Array.from(l)){if(u.size>r){toast.error(`File size too big (max ${(r/(1024*1024)).toFixed(0)}MB): ${u.name}`);continue}c.push(u);}let a=await Promise.all(c.map(async u=>Mr(u,t)));return a.length>0&&toast.success(`Uploaded ${a.length} file${a.length>1?"s":""}`),a}catch(l){return console.error(l),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(i);}}function Gn(){let e=useApolloClient();return useCallback(async t=>{let n=await nf(t);return n.length>0&&await At(e,"GetAssets").catch(o=>{console.error("Error refreshing asset lists after upload:",o);}),n},[e])}function bn(e,t,n){useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o);}},[t,e,n]),useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("focusin",o),()=>{document.removeEventListener("mousedown",o);}},[t,e]);}function Aa({control:e$1,entityId:t,fieldSchema:n$1,getValues:o,readOnly:r,setValue:i}){let{name:s,label:l$1,options:c$1}=n$1,{projectId:a}=useParams(),u=ge(),f$1=d$2(),{relationships:m$1}=c$2(),[p,d]=useState(false),g$1=useRef(null),h=useRef(null),v=useRef(null),[y,C]=useState(null),[x,A]=useState(false),[R,N]=useState(false),S=useId(),D=useId();bn(h,d,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let b=m$1[D]?.connect;if(!b||v.current===b._id)return;let k=gf(b.value);if(!k)return;let M=o(s);v.current=b._id,C(null),i(s,{...M,value:k});},[o,s,D,m$1,i]);function $(b){if(!b)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[b])return k[b];let M=b.split("/");if(M.length===2){let[,j]=M;return j.includes("svg")?"svg":j.toLowerCase()}}function O(b,k){if(b&&b.includes(".")){let j=b.split(".").pop();if(j)return j.toLowerCase()}let M=$(k);return M||"file"}async function V(b,k){if(r||!b)return;let M=$r("4MB");if(b.size>(M??0)){toast.error("File size too big (max 4MB)");return}let j=b.type.startsWith("image/");if(v.current=null,j){let Q=new FileReader;Q.onload=se=>{C(se.target?.result);},Q.readAsDataURL(b);}else C(null);N(true);try{let Q=await Mr(b,a);i(s,{...o(s),value:Q.asset});}catch(Q){console.error(Q),C(null),i(s,{...o(s),value:{_id:k?.value?._id}});}finally{N(false);}}function F(b){r||(b.stopPropagation(),v.current=null,i(s,{...o(s),_id:"",value:{_id:o(s)?.value?._id}}));}function B(b,k){b.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function K(b){b.preventDefault(),b.stopPropagation(),!r&&g$1.current?.click();}function ne(b){if(b.preventDefault(),b.stopPropagation(),r)return;d(false);let k=o(s)?.value,M=v.current??kf(k),j=M?{_id:M,value:k}:void 0;f$1({type:"setRelationship",payload:{[D]:{connect:j,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:c$1?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:j,relationshipId:D,mode:"single"}});},0);}function I(b,k){b.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:s,render:({field:b})=>jsxs(e,{children:[jsx(f,{htmlFor:S,children:l$1}),c$1?.comment?jsx(h$1,{children:c$1.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-${s}`,"aria-expanded":p,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 ${p?"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(),h.current?.focus(),h.current?.click(),d(true);},onKeyDown:k=>{k.key==="Enter"&&d(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false));},onDragOver:k=>{r||(k.preventDefault(),k.stopPropagation(),A(true));},onDragEnter:k=>{r||(k.preventDefault(),k.stopPropagation(),A(true));},onDragLeave:k=>{r||(k.preventDefault(),k.stopPropagation(),A(false));},onDrop:k=>{if(k.preventDefault(),k.stopPropagation(),A(false),r)return;let M=k.dataTransfer.files&&k.dataTransfer.files[0];V(M,b.value);},ref:h,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!b.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",disabled:r,id:S,onClick:K,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",disabled:r,onClick:ne,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,b.value?.value?.path&&!p?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=b.value?.value,M=k?.mimeType,j=k?.path||"";if(!!(M&&M.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(j)))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 se=O(k.originalFilename,k.mimeType),oe=defaultStyles[se];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:se,...oe||{}})})})(),$r((b.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(b.value?.value).mimeType,(b.value?.value).width&&(b.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(b.value?.value).width,"x",(b.value?.value).height,"px"]}):null]}):null,!b.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..."]}),!b.value?.value?.path&&!y&&R?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,b.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$2,{disabled:r,onClick:K,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$2,{disabled:r,onClick:ne,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$2,{onClick:k=>I(k,b.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$2,{onClick:k=>B(k,b.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$2,{disabled:r,onClick:F,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!p&&(b.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(h.current?.focus(),h.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}),p&&(b.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(l,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:d,open:p&&(!!b.value?.value?.path||!!y),children:jsx(n,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${s}`,children:b.value?.value?.path?(()=>{let k=b.value?.value,M=k?.mimeType,j=k?.path||"";if(!!(M&&M.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(j)))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 se=O(k.originalFilename,k.mimeType),oe=defaultStyles[se];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:se,...oe||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",$r(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),R?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:c$1?.accept?c$1.accept:"image/*",className:"fk:hidden",disabled:r,id:`file-upload-${s}`,onChange:k=>{let M=k.currentTarget.files&&k.currentTarget.files[0];V(M,b.value);},ref:g$1,type:"file"}),jsx(i$1,{})]})})}function gf(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function kf(e){return !e?._id||e._id.includes(":")?"":e._id}function Ta({control:e$1,fieldSchema:t,readOnly:n,setValue:o}){let{name:r,label:i,options:s,dataType:l}=t,c$1=useId();function a(f,m){let p=f.currentTarget.value,d;p===""?d="":(d=l==="float"?parseFloat(p):parseInt(p,10),isNaN(d)&&(d="")),o(r,{...m,value:d});}function u(f,m){o(r,{...m,disabled:f});}return jsx(c,{control:e$1,name:r,render:({field:f$1})=>jsxs(e,{children:[jsx(f,{htmlFor:c$1,children:i}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsx(a$7,{className:"fk:w-full fk:mt-0.75",disabled:n||f$1.value?.disabled,id:c$1,...f$1,onChange:m=>{a(m,f$1.value);},step:l==="float"?"any":"1",type:"number",value:f$1.value?.value??""})}),jsx(a$6,{checked:f$1.value?.disabled??false,disabled:n,onChange:m=>{u(m,f$1.value);},scope:f$1.value?.scope}),jsx(i$1,{})]})})}function Cn({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function wn({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Vt({className:e,align:t="center",sideOffset:n=4,...o}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:n,className:a$1("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...o})})}function Da({className:e,classNames:t,showOutsideDays:n=true,captionLayout:o="label",buttonVariant:r="ghost",formatters:i,components:s,...l}){let c=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:n,className:a$1("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:o,formatters:{formatMonthDropdown:a=>a.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$1("w-fit",c.root),months:a$1("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",c.months),month:a$1("fk:flex fk:w-full fk:flex-col fk:gap-4",c.month),nav:a$1("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",c.nav),button_previous:a$1(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",c.button_previous),button_next:a$1(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",c.button_next),month_caption:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",c.month_caption),dropdowns:a$1("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",c.dropdowns),dropdown_root:a$1("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",c.dropdown_root),dropdown:a$1("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",c.dropdown),caption_label:a$1("fk:font-medium fk:select-none",o==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",c.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$1("fk:flex",c.weekdays),weekday:a$1("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",c.weekday),week:a$1("fk:mt-2 fk:flex fk:w-full",c.week),week_number_header:a$1("fk:w-(--cell-size) fk:select-none",c.week_number_header),week_number:a$1("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",c.week_number),day:a$1("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",l.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",c.day),range_start:a$1("fk:rounded-l-md fk:bg-accent",c.range_start),range_middle:a$1("fk:rounded-none",c.range_middle),range_end:a$1("fk:rounded-r-md fk:bg-accent",c.range_end),today:a$1("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",c.today),outside:a$1("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",c.outside),disabled:a$1("fk:text-muted-foreground fk:opacity-50",c.disabled),hidden:a$1("invisible",c.hidden),...t},components:{Root:({className:a,rootRef:u,...f})=>jsx("div",{"data-slot":"calendar",ref:u,className:a$1(a),...f}),Chevron:({className:a,orientation:u,...f})=>u==="left"?jsx(ChevronLeftIcon,{className:a$1("size-4",a),...f}):u==="right"?jsx(ChevronRightIcon,{className:a$1("size-4",a),...f}):jsx(ChevronDownIcon,{className:a$1("size-4",a),...f}),DayButton:xf,WeekNumber:({children:a,...u})=>jsx("td",{...u,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:a})}),...s},...l})}function xf({className:e,day:t,modifiers:n,...o}){let r=getDefaultClassNames(),i=Io.useRef(null);return Io.useEffect(()=>{n.focused&&i.current?.focus();},[n.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:a$1("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...o})}function Ra({control:e$1,fieldSchema:t,getValues:n,readOnly:o,setValue:r}){let{name:i,label:s,options:l}=t,c$1=useId();function a(m,p){r(i,{...p,value:m?m.toISOString():""});}function u(m,p){r(i,{...p,disabled:m});}function f$1(m){m.preventDefault(),r(i,{...n(i),value:void 0});}return jsx(c,{control:e$1,name:i,render:({field:m})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:c$1,children:s}),l?.comment?jsx(h$1,{children:l.comment}):null,jsx(g,{children:jsxs(Cn,{children:[jsx(wn,{asChild:true,children:jsx(b$3,{className:a$1("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!m.value?.value&&"fk:text-muted-foreground"),disabled:o||m.value?.disabled,id:c$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:m.value?.value?format(new Date(m.value.value),"PPP")+" at "+format(new Date(m.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[m.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:p=>{p.stopPropagation(),f$1(p);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(Vt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Da,{mode:"single",selected:m.value?.value?new Date(m.value.value):void 0,onSelect:p=>a(p,m.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$7,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let d=p.target.value,[g,h]=d.split(":"),v=m.value?.value?new Date(m.value.value):new Date;v.setHours(parseInt(g)),v.setMinutes(parseInt(h)),r(i,{...m.value,value:v.toISOString()});},type:"time",value:m.value?.value?format(new Date(m.value.value),"HH:mm"):""})]})]})]})}),jsx(a$6,{checked:m.value?.disabled??false,disabled:o,onChange:p=>{u(p,m.value);},scope:m.value?.scope}),jsx(i$1,{})]})})}function Ve(e){return e??null}var Vr=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let n=document.createElement("input");n.type="file",n.accept="image/*",n.onchange=async()=>{n.files?.length;},n.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(n??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:n??""}).run():n!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(n??"")?e.chain().focus().deleteRange(t).setTweet({src:n??""}).run():n!==null&&alert("Please enter a correct Twitter Link");}}]),Fa=Command.configure({suggestion:{items:()=>Vr,render:renderItems}});var Ia=[{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"}],La=[{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)"}],Ma=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=Ia.find(({color:i})=>n.isActive("textStyle",{color:i})),r=La.find(({color:i})=>n.isActive("highlight",{color:i}));return jsxs(Cn,{modal:true,open:e,onOpenChange:t,children:[jsx(wn,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:o?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(Vt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),Ia.map(({name:i,color:s})=>jsx(EditorBubbleItem,{onSelect:()=>{n.commands.unsetColor(),i!=="Default"&&n.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"}),La.map(({name:i,color:s})=>jsxs(EditorBubbleItem,{onSelect:()=>{n.commands.unsetHighlight(),i!=="Default"&&n.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})]}),n.isActive("highlight",{color:s})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Wf(e){try{return new URL(e),!0}catch{return false}}function Kf(e){if(Wf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var $a=({open:e,onOpenChange:t})=>{let n=useRef(null),{editor:o}=useEditor();return useEffect(()=>{n.current?.focus();}),o?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$1("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":o.isActive("link")}),children:"Link"})]})}),jsx(Vt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let s=i[0],l=Kf(s.value);l&&(o.chain().focus().setLink({href:l}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:n,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:o.getAttributes("link").href||""}),o.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{o.chain().focus().unsetLink().run(),n.current&&(n.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var Va=[{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=Ve(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=Ve(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=Ve(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=Ve(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ve(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")}],Ba=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=Va.filter(r=>r.isActive(n)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:o.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:Va.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),o.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var ja=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:n,to:o}=e.state.selection,r=e.state.doc.textBetween(n,o);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$1("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var Ha=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:n=>n!=null&&n.isActive("bold"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:n=>n!=null&&n.isActive("italic"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:n=>n!=null&&n.isActive("underline"),command:n=>n?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:n=>n!=null&&n.isActive("strike"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:n=>n!=null&&n.isActive("code"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleCode().run();},icon:CodeIcon}].map(n=>jsx(EditorBubbleItem,{onSelect:o=>{n.command(o);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:o=>o.preventDefault(),variant:"ghost",children:jsx(n.icon,{className:a$1("fk:h-4 fk:w-4",{"fk:text-blue-500":n.isActive(e)})})})},n.name))}):null};function Qn({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 vd=()=>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"})]}),Ua=vd;function Hr({completion:e,onDiscard:t}){let{editor:n}=useEditor();return n?jsxs(Fragment,{children:[jsxs(s$1,{children:[jsxs(u$1,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt({from:o.from,to:o.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(u$1,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt(o.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(t$1,{}),jsx(s$1,{children:jsxs(u$1,{onSelect:t,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var Id=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function qr({onSelect:e}){let{editor:t}=useEditor();return t?jsxs(Fragment,{children:[jsx(s$1,{heading:"Edit or review selection",children:Id.map(n=>jsxs(u$1,{onSelect:o=>{let r=t.state.selection.content(),i=t.storage.markdown.serializer.serialize(r.content);e(i,o);},className:"fk:flex fk:gap-2 fk:px-4",value:n.value,children:[jsx(n.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),n.label]},n.value))}),jsx(t$1,{}),jsx(s$1,{heading:"Use AI to do more",children:jsxs(u$1,{onSelect:()=>{let n=t.state.selection.from,o=getPrevText(t,n);e(o,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function Ja({onOpenChange:e}){let{editor:t}=useEditor(),[n,o]=useState(""),{projectId:r}=useParams(),{completion:i,complete:s,isLoading:l}=useCompletion({api:c$6(r).completion,fetch:async(a,u)=>{let f=await fetch(a,u);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:a=>{a.message!=="FK_AI_RATE_LIMIT"&&toast.error(a.message);}}),c=i.length>0;return t?jsxs(n$1,{className:"fk:w-[350px]",children:[c&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(w,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(zd,{children:i})})})}),l&&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(Qn,{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(Ua,{})})]}),!l&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(p$1,{value:n,onValueChange:o,autoFocus:true,placeholder:c?"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:n}}).then(()=>o(""));let a=t.state.selection.content(),u=t.storage.markdown.serializer.serialize(a.content);s(u,{body:{option:"zap",command:n}}).then(()=>o(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(q$1,{children:c?jsx(Hr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(qr,{onSelect:(a,u)=>s(a,{body:{option:u}})})})]})]}):null}function Gr({children:e,open:t,onOpenChange:n}){let{editor:o}=useEditor();return useEffect(()=>{o&&(t||removeAIHighlight(o));},[o,t]),o?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{n(false),o.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(Ja,{open:t,onOpenChange:n}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),n(true);},size:"sm",children:[jsx(Qn,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var im=[...a,Fa];function Qa(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 sm(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let n=JSON.parse(t);if(Qa(n))return n}catch{return}}if(Qa(e))return e}function Qr({control:e$1,defaultValue:t,fieldSchema:n,readOnly:o,setValue:r}){let{name:i,label:s,options:l}=n,[c$1,a]=useState(false),[u,f$1]=useState(false),[m,p]=useState(false),[d,g$1]=useState(false),h=useDebouncedCallback((C,x)=>{let A=C.getJSON();r(i,{...x,value:JSON.stringify(A)});},300);function v(C,x){r(i,{...x,disabled:C});}let y=C=>(console.log("Image uploader not yet implemented",C),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:i,render:({field:C})=>jsxs(e,{children:[jsx(f,{children:s}),l?.comment?jsx(h$1,{children:l.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-5xl 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:!o&&!C.value?.disabled,editorProps:{handleDOMEvents:{keydown:(x,A)=>handleCommandNavigation(A)},handlePaste:(x,A)=>handleImagePaste(x,A,y),handleDrop:(x,A,R,N)=>handleImageDrop(x,A,N,y),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:im,initialContent:sm(C.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:x})=>{h(x,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:Vr.map(x=>jsxs(EditorCommandItem,{value:x.title,onCommand:A=>x.command?.(A),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:x.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:x.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:x.description})]})]},x.title))})]}),jsxs(Gr,{open:c$1,onOpenChange:a,children:[jsx(c$5,{orientation:"vertical"}),jsx(Ba,{open:u,onOpenChange:f$1}),jsx(c$5,{orientation:"vertical"}),jsx($a,{open:m,onOpenChange:p}),jsx(c$5,{orientation:"vertical"}),jsx(ja,{}),jsx(c$5,{orientation:"vertical"}),jsx(Ha,{}),jsx(c$5,{orientation:"vertical"}),jsx(Ma,{open:d,onOpenChange:g$1})]})]},`${i}:${C.value?.scope??t.scope}:${String(C.value?.disabled??t.disabled)}`)})}),jsx(a$6,{checked:C.value?.disabled??false,disabled:o,onChange:x=>{v(x,C.value);},scope:C.value?.scope}),jsx(i$1,{})]})})}var km=So;function Zr({control:e$1,defaultValue:t,entityId:n$1,entityName:o,entityNamePlural:r,fieldSchema:i,readOnly:s,schema:l$1,setValue:c$1}){let{name:a,label:u,options:f$1,relationship:m}=i,{projectId:p}=useParams(),d=ge(),g$1=d$2(),{relationships:h}=c$2(),v=Gn(),y=useId(),C=useId(),x=useRef(null),A=useRef([]),R=useRef(null),N=useRef([]),S=useRef(""),D=useRef(t.knownAssetSortOrders??{}),[$,O]=useState(false),V=useMemo(()=>vm(t.value),[t.value]),[F,B]=useState(V),[K,ne]=useState(()=>Object.keys(t.knownAssetSortOrders??zn(V)).length),[I,b]=useState(()=>Math.max(t.count??0,V[0]?.totalCount??0,V.length)),k=useMemo(()=>ca({attributeName:a,entityName:o,entityNamePlural:r,schema:l$1}),[o,r,a,l$1]),[M,{loading:j}]=useLazyQuery(gql`
379
+ ${k.query}
380
+ `);bn(x,O),useEffect(()=>{let L=Nt(V);A.current=V.map(Y=>Y._id),N.current=[];let Z={...t.knownAssetSortOrders??{},...zn(V)};D.current=Z,ne(Object.keys(Z).length),b(Math.max(t.count??0,V[0]?.totalCount??0,V.length)),B(Y=>{let H=Nt(Y);return L===""&&H!==""&&S.current===H||H===L?Y:(S.current=L,V)});},[t.count,t.knownAssetSortOrders,V]),useEffect(()=>{let L=h[C]?.connect;if(!L)return;let Z=L.map((X,_)=>Za(X.value,X.sortOrder??_)).filter(X=>!!X),Y=Nt(Z),H=Nt(F),ee=R.current;ee===H&&Y!==ee||(R.current=null,Y!==H&&B(Z));},[C,h,F]),useEffect(()=>{let L=Nt(F);if(S.current===L)return;let Z=F.map((ee,X)=>({_id:ee._id,sortOrder:X,value:{...ee,sortOrder:X}})),Y=F.map(ee=>ee._id),H=N.current.filter(ee=>!Y.includes(ee));S.current=L,g$1({type:"setRelationship",payload:{[C]:{connect:Z,disconnect:H}}}),c$1(a,{...t,knownAssetSortOrders:D.current,relationships:{connect:Z,disconnect:H},value:F});},[g$1,t,a,C,F,c$1]);let Q=Math.max(I,K),se=!!n$1&&Q>K,oe=useCallback(()=>{if(!n$1||j||!se)return;let L=K+km;M({variables:{where:{_id:{eq:n$1}},first:L}}).then(Z=>{let Y=Z.data?.[r],ee=(Array.isArray(Y)?Y[0]:void 0)?.[`${a}Connection`],X=Ao(ee),_=X[0]?.totalCount;if(typeof _=="number"&&b(_),X.length===0){b(K);return}let U=Object.keys(D.current).length,ae={...D.current,...zn(X)},le=Object.keys(ae).length;D.current=ae,ne(le),(X.length<L||le<=U)&&b(le);for(let J of X)A.current.includes(J._id)||(A.current=[...A.current,J._id]);B(J=>{let on=new Set(J.map(lo=>lo._id)),rn=new Set(N.current),Rn=X.filter(lo=>!on.has(lo._id)&&!rn.has(lo._id));if(Rn.length===0)return S.current="",[...J];let Li=[...J,...Rn];return R.current=Nt(Li),Li});}).catch(Z=>{console.error("Error fetching more assets:",Z);});},[n$1,r,M,se,j,K,a]);function q(L){L.preventDefault(),L.stopPropagation(),!s&&d({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(F.length,Q),entityName:m?.entity??"_asset",entityId:n$1,relationshipId:C,mode:"multiple",assetAccept:f$1?.accept}});}async function ue(L){if(L.preventDefault(),L.stopPropagation(),s)return;let Z=await v({projectId:p,accept:f$1?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(Y=>{let H=new Set(Y.map(_=>_._id)),ee=Z.map((_,U)=>({..._.asset,sortOrder:Y.length+U})).filter(_=>!H.has(_._id)),X=Wr([...Y,...ee]);return R.current=Nt(X),X});}function he(L){B(Z=>{let Y=Wr(Z.filter(H=>H._id!==L));return A.current.includes(L)&&!N.current.includes(L)&&(N.current=[...N.current,L]),R.current=Nt(Y),Y});}function z(L,Z){B(Y=>{let H=Y.findIndex(ae=>ae._id===L),ee=H+Z;if(H<0||ee<0||ee>=Y.length)return Y;let X=[...Y],[_]=X.splice(H,1);if(!_)return Y;X.splice(ee,0,_);let U=Wr(X);return R.current=Nt(U),U});}let E=Math.max(F.length,Q),pe=F.slice(0,8);return jsx(c,{control:e$1,defaultValue:t,name:a,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:y,children:u}),f$1?.comment?jsx(h$1,{children:f$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${a}`,"aria-expanded":$,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${$?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),x.current?.focus(),O(true);},ref:x,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:[$&&F.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[E," ",E===1?"asset":"assets",se?` (${F.length} loaded)`:""," selected"]}):F.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[pe.map(L=>jsx(hm,{asset:L},L._id)),!$&&E>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:["+",E-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:y,onClick:L=>{L.preventDefault(),L.stopPropagation(),O(Z=>!Z);},size:"icon",variant:"ghost",children:$?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:$?"Close":"Expand field"})})]})})]}),jsx(l,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:O,open:$,children:jsx(n,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${a}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",disabled:s,onClick:q,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",disabled:s,onClick:L=>{ue(L);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),F.length>0?jsxs(w,{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:F.map((L,Z)=>jsx(ym,{asset:L,index:Z,isFirst:Z===0,isLast:Z===F.length-1,moveAsset:z,readOnly:s,removeAsset:he},L._id))}),se?jsx("div",{className:"fk:flex fk:justify-center fk:py-3 fk:pr-3",children:jsx(b$3,{className:"fk:h-8",disabled:j,onClick:L=>{L.preventDefault(),L.stopPropagation(),oe();},type:"button",variant:"outline",children:j?"Loading\u2026":`Load more (${K} of ${Q})`})}):null]}):null]})})})]})})}),jsx(i$1,{})]})})}function hm({asset:e}){return Ya(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 ym({asset:e,index:t,isFirst:n,isLast:o,moveAsset:r,readOnly:i,removeAsset:s}){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:Ya(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:i||n,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:i||o,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",disabled:i,onClick:()=>s(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function vm(e){return Array.isArray(e)?e.map((t,n)=>Za(t,n)).filter(t=>!!t).sort((t,n)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Nt(e){return e.map((t,n)=>`${t._id}:${t.sortOrder??n}`).join("|")}function Wr(e){return e.map((t,n)=>({...t,sortOrder:n}))}function Za(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let n=e;return {_id:String(n._id??""),path:String(n.path??""),originalFilename:String(n.originalFilename??""),size:Number(n.size??0),mimeType:String(n.mimeType??""),lqip:String(n.lqip??""),width:Number(n.width??0),height:Number(n.height??0),sortOrder:n.sortOrder??t,totalCount:typeof n.totalCount=="number"?n.totalCount:void 0}}function Ya(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function tl({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 Bo({column:e,title:t,className:n}){if(!e.getCanSort())return jsx("div",{className:a$1("fk:flex fk:items-center",n),children:t});let o=e.getIsSorted()==="asc",r=e.getIsSorted()==="desc";return jsxs("div",{className:a$1("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",n),children:[jsx("span",{className:"fk:truncate",children:t}),jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsx("button",{"aria-label":`Sort ${t}`,className:"fk:inline-flex fk:shrink-0 fk:items-center fk:justify-center fk:rounded-sm fk:p-0.5 fk:text-muted-foreground fk:outline-hidden fk:hover:bg-accent fk:hover:text-accent-foreground fk:focus-visible:ring-1 fk:focus-visible:ring-ring",type:"button",children:jsx(ChevronDown,{className:"fk:h-3.5 fk:w-3.5"})})}),jsxs(f$2,{align:"end",className:"fk:w-44",children:[jsxs(h$2,{"aria-checked":o,className:a$1(o&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(o){e.clearSorting();return}e.toggleSorting(false);},role:"menuitemcheckbox",children:[jsx(ArrowUp,{className:a$1("fk:h-4 fk:w-4",o&&"fk:text-white")}),"Sort Ascending"]}),jsxs(h$2,{"aria-checked":r,className:a$1(r&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(r){e.clearSorting();return}e.toggleSorting(true);},role:"menuitemcheckbox",children:[jsx(ArrowDown,{className:a$1("fk:h-4 fk:w-4",r&&"fk:text-white")}),"Sort Descending"]})]})]})]})}var xm=new Set(["text","number","datetime","switch","select"]);function Yn({attributesSchema:e,checkboxSelect:t,actionsComponent:n,enableColumnSorting:o=false}){let{getContributionPointConfig:r}=d(),[,i]=b(),s=vn(e,i.user?.spaces),l={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"select",switch:"boolean",text:"text",textarea:"text"},c={boolean:a$b,date:a$a,datetime:a$e,editor:b$7,asset:a$d,number:a$a,relationship:a$a,select:a$c,switch:a$b,text:a$a,textarea:a$a,tags:tl},a=s.map(d=>{if(d.name==="_updatedAt")return null;let g=(d.inputType==="relationship"&&d.relationship?.entity==="_asset"?"asset":void 0)??d.previewType??l[d.inputType],h=r("previewFields",[g])?.[0]?.component??c[g]??c.text;if(d.hidden===true)return null;let v=g==="tags",y=o&&d.scope==="global"&&xm.has(d.inputType);return {accessorKey:d.name,filterFn:(C,x,A)=>v?true:(Array.isArray(A)?A:[A]).includes(C.getValue(x)),header:({column:C})=>y?jsx(Bo,{column:C,title:d.label}):jsx("div",{className:"fk:flex fk:items-center",children:d.label}),cell:({row:C})=>{let x=h;return g==="select"?jsx(x,{value:C.getValue(d.name),options:d.options}):jsx(x,{value:C.getValue(d.name)})},enableSorting:y,enableHiding:true,meta:{label:d.label},size:d.options?.size??150}}).filter(d=>d!==null),u={id:"actions",cell:({row:d})=>n?n(d):null,size:80},f={accessorKey:"_updatedAt",header:({column:d})=>o?jsx(Bo,{column:d,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:d})=>jsx(a$e,{value:d.getValue("_updatedAt")}),enableSorting:o,enableHiding:false,meta:{label:"Updated At"},size:220},m={id:"select",cell:({row:d,table:g})=>jsx(j$1,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:h=>{g.toggleAllPageRowsSelected(false),d.toggleSelected(!!h);}}),enableSorting:false,enableHiding:false,size:50},p={id:"select",header:({table:d})=>jsx(j$1,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:d.getIsAllPageRowsSelected()||d.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:g=>{d.toggleAllPageRowsSelected(!!g);}}),cell:({row:d})=>jsx(j$1,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:g=>{d.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[m]:[],...t==="multiple"?[p]:[],...n?[u]:[],...a,f]}var Fm=36,Pm=15,ol=40;function sl(e){if(!e)return;let t=e.split(/\s+/);if(t.includes("fk:h-20"))return 80;if(t.includes("fk:h-10"))return 40;if(t.includes("fk:h-9"))return 36}function Im(e,t){return e??sl(t)??Fm}function Lm(e){return Math.max(600,e)}function eo({classNames:e,columns:t$1,data:n,entityName:o$1,hasMore:r=false,initialSelectionState:i,isLoadingMore:s$1=false,onEntitySelectionChange:l,onLoadMore:c,onScroll:a,onSortingChange:u$1,pageSize:f,rowHeightEstimate:m,rowAdditionState:p$1,rowDeletionState:d,scrollToTopKey:g,sorting:h,toolbarComponent:v}){let y=useRef(null),{schemaErrorMessage:C}=Wt(),[x,A]=useState(i??{}),[R,N]=useState({}),[S,D]=useState([]),[$,O]=useState([]),V=h??$;useEffect(()=>{y.current?.scrollTo({top:0});},[o$1,g]),useEffect(()=>{if(!i)return;let z=Object.keys(x).sort().join(","),E=Object.keys(i).sort().join(",");z!==E&&A(i);},[i,x]);function F(z){if(u$1){u$1(z);return}O(z);}let B=useReactTable({data:n,columns:t$1,state:{sorting:V,columnVisibility:R,rowSelection:x,columnFilters:S},initialState:{pagination:{pageSize:f??50}},enableRowSelection:true,onRowSelectionChange:ue,onSortingChange:F,onColumnFiltersChange:D,onColumnVisibilityChange:N,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:z=>z._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:z=>_m(z,d,p$1)}}),{rows:K}=B.getRowModel(),ne=Im(m,e?.row),I=sl(e?.row)!=null,b=useVirtualizer({count:K.length,estimateSize:()=>ne,getItemKey:z=>K[z]?.id??z,getScrollElement:()=>y.current,overscan:Pm,scrollMargin:ol}),k=b.getVirtualItems(),{paddingTop:M,paddingBottom:j}=Mm(k,b.getTotalSize(),ol),Q=useRef(c),se=useRef(r),oe=useRef(s$1);Q.current=c,se.current=r,oe.current=s$1;let q$1=useCallback(z=>{if(!Q.current||!se.current||oe.current)return;let E=z??y.current;if(!E)return;let{scrollHeight:pe,scrollTop:L,clientHeight:Z}=E;pe-L-Z>=Lm(Z)||(oe.current=true,Q.current());},[]);useEffect(()=>{q$1();},[q$1,K.length,r,s$1]);function ue(z){let E=Object.keys(typeof z=="function"?z(x):z);A(z),l?.(E);}function he(z){a?.(z),q$1(z.currentTarget);}return C?jsx(Fragment,{}):jsxs("div",{className:a$1("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(B),jsx("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1 fk:-mb-px",children:jsx(a$8,{delayDuration:400,children:jsxs(o,{className:a$1("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:he,ref:y,children:[jsx(p,{className:"fk:sticky fk:top-0 fk:z-20 fk:grid",children:B.getHeaderGroups().map(z=>jsx(s,{className:"fk:flex fk:w-full",children:z.headers.map(E=>jsxs(t,{className:a$1("fk:flex fk:items-center",E.column.id==="actions"&&"fk:pl-0"),colSpan:E.colSpan,style:E.getSize()?{width:`${E.getSize().toString()}px`}:{},children:[E.isPlaceholder?null:flexRender(E.column.columnDef.header,E.getContext()),s$1?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]},E.id))},z.id))}),jsx(q,{className:"fk:grid fk:relative",children:K.length===0?jsx(s,{children:jsx(u,{className:"fk:h-24 fk:text-center",colSpan:t$1.length,children:"No results."})}):jsxs(Fragment,{children:[M>0?jsx(rl,{height:M}):null,k.map(z=>{let E=K[z.index];return jsx(s,{className:a$1(B.options.meta.getRowBackground(E),"fk:flex fk:w-full fk:overflow-hidden fk:transition-none",!I&&m==null&&"fk:h-9",e?.row),"data-index":z.index,"data-state":E.getIsSelected()&&"selected",style:{height:`${ne.toString()}px`},children:E.getVisibleCells().map(pe=>jsx(u,{className:a$1("fk:flex fk:items-center fk:truncate",pe.column.id==="actions"&&"fk:pl-1!"),style:{width:pe.column.getSize()},children:flexRender(pe.column.columnDef.cell,pe.getContext())},pe.id))},z.key)}),j>0?jsx(rl,{height:j}):null]})})]})})})]})}function Mm(e,t,n){if(e.length===0)return {paddingTop:0,paddingBottom:0};let o=e[0]?.start??0,r=e[e.length-1]?.end??0;return {paddingTop:Math.max(0,o-n),paddingBottom:Math.max(0,t-(r-n))}}function rl({height:e}){return jsx("tr",{"aria-hidden":true,className:"fk:pointer-events-none fk:border-0",style:{display:"block",height:`${e.toString()}px`},children:jsx("td",{className:"fk:p-0 fk:border-0"})})}function _m(e,t,n){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":n?.some(o=>o._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function al({action:e,row:t}){let n=t.original._id;function o(){e(n);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:o,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var Xm=25;function ni({control:e$1,defaultScope:t,defaultValue:n$1,entityId:o,entityName:r,fieldSchema:i,readOnly:s,schema:l$1,scope:c$1,setValue:a}){let[u,f$1]=useState(false),m=useRef(null);bn(m,f$1);let[p,d]=useState([]),{name:g$1,label:h,options:v,relationship:y}=i,C=y?.entity??g$1,x=ge(),A=d$2(),{relationships:R}=c$2(),N=useId(),S=useId(),D=find(propEq(C,"name"))(l$1),$=D?.attributes??[],V=find(propEq(r,"name"))(l$1)?.name??"",F,B=$.find(E=>E.relationship?.entity===V);B&&(F=B.name);let K=e$4(D)?.name??"",ne=useMemo(()=>n$1.value?Km({data:n$1.value,defaultScope:t,relationshipEntitySchema:D,scope:c$1}):[],[t,n$1,K,D,c$1]),I=la({relatedEntityName:C,scope:c$1,schema:l$1}),k=p.length?p.slice(0,12).map(E=>E[K]):[],M=Math.max(p.length,n$1.count??0)>k.length,[j,{loading:Q,data:se}]=useLazyQuery(gql`
381
+ ${I.query}
382
+ `),oe=Yn({attributesSchema:D?.attributes??[],actionsComponent:s?void 0:E=>Wm({appDispatch:A,relationshipId:S,relationships:R,row:E,setRows:d})});useEffect(()=>{d(ne),n$1.value!==""&&A({type:"setRelationship",payload:{[S]:{connect:[],disconnect:[]}}});},[A,se,ne,S,n$1,c$1]),useEffect(()=>{a(g$1,{...n$1,relationships:R[S]});},[n$1,R,S,a,g$1]),useEffect(()=>{let pe=(R[S]?.connect??[]).map(({value:L})=>L);d(uniqBy(prop("_id"),[...pe,...ne]));},[se,n$1.count,ne,R,S]);let q=n$1.count??0,ue=q>0&&p.length>0&&p.length<q,he=useCallback(()=>{Q||j({variables:{limit:Xm,offset:p.length,where:F?{[F]:{some:{_id:{eq:o}}}}:{}}}).then(({data:E})=>{if(!E)return;let pe=To(D?.plural??"",c$1,E,l$1);d(uniqBy(prop("_id"),[...ne,...pe.results]));}).catch(E=>{console.error("Error fetching more data:",E);});},[F,o,j,ne,Q,D?.plural,p.length,l$1,c$1]);function z(E){E.preventDefault(),!s&&x({type:"EditRelationship",payload:{connectedEntitiesCount:ne.length,connectionName:F,entityName:C,entityId:o,relationshipId:S,mode:y?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:n$1,name:g$1,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:N,children:h}),v?.comment?jsx(h$1,{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-${g$1}`,"aria-expanded":u,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 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:E=>{E.preventDefault(),E.stopPropagation(),m.current?.focus(),m.current?.click(),f$1(true);},onKeyDown:E=>{E.key==="Enter"&&f$1(true),E.key==="Escape"&&(E.preventDefault(),E.stopPropagation(),m.current?.blur(),f$1(false));},ref:m,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:[u?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",disabled:s,onClick:z,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",D?.menu?.label??D?.plural]}):jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-wrap fk:grow fk:overflow-hidden fk:pb-1.5 fk:pr-10",children:[k.map(E=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:max-w-60 fk:justify-start fk:rounded-xs",title:E,variant:"secondary",children:jsx("span",{className:"fk:min-w-0 fk:truncate",children:E})},E)),M?jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:"\u2026"}):null]}),u?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:E=>{E.preventDefault(),E.stopPropagation(),m.current?.blur(),f$1(false);},onKeyDown:E=>{E.key==="Enter"&&(E.preventDefault(),E.stopPropagation(),m.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$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:N,onKeyDown:E=>{E.key==="Enter"&&(m.current?.focus(),m.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(l,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:f$1,open:u,children:jsx(n,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${g$1}`,children:jsx(eo,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:oe,data:p,entityName:r,hasMore:ue,isLoadingMore:Q&&p.length>0,onLoadMore:he,rowAdditionState:R[S]?.connect,rowDeletionState:R[S]?.disconnect})})})})]})})}),jsx(i$1,{})]})})}function Wm({appDispatch:e,relationshipId:t,relationships:n,row:o,setRows:r}){function i(s){let l=n[t]?.connect??[],c=typeof find(propEq(s,"_id"),l)=="object",a=n[t]?.disconnect?.includes(s),u=c?n[t]?.disconnect??[]:uniq([...n[t]?.disconnect??[],s]);c&&r(f=>f.filter(m=>m._id!==s)),e({type:"setRelationship",payload:{[t]:{connect:l.filter(f=>f._id!==s),disconnect:a?n[t]?.disconnect?.filter(f=>f!==s)??[]:u}}});}return jsx(al,{action:i,row:o})}function Km({data:e,defaultScope:t,relationshipEntitySchema:n,scope:o}){if(!Array.isArray(e))return [];let r=i=>{let l=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";if(l){let c=i[l],a=Array.isArray(c)?c[0]:c;return a&&typeof a=="object"?a[o]??a[t]??"":a}return i[o]??i[t]};return e.map(i=>map(s=>{if(Array.isArray(s)){let l=s;return l.length===0?"":l.length===1?r(l[0]):l.slice(0,3).map(r).join(", ")}return s&&typeof s!="string"&&s.__typename?r(s):s},i))}function oi({control:e$1,defaultScope:t,defaultValue:n,entityId:o,fieldSchema:r,getValues:i,readOnly:s,schema:l,scope:c$1,setValue:a}){let[u,f$1]=useState(false),{name:m,label:p,options:d,relationship:g$1}=r,h=g$1?.entity??m,v=ge(),y=d$2(),C=useId(),{relationships:x}=c$2(),A=useId(),R=find(propEq(h,"name"))(l),N=e$4(R)?.name;useEffect(()=>{let $=n.value;if($===""||typeof $=="boolean"||typeof $=="number")return;let O={_id:String(n._id),value:$},V={type:"setRelationship",payload:{[A]:{connect:O,disconnect:[]}}};y(V);},[y,A,n,c$1]),useEffect(()=>{a(m,{...i(m),...x[A]?.connect??""});},[n,m,x,A,a]);function S($){$.preventDefault(),!s&&v({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:h,entityId:o,relationshipId:A,mode:g$1?.mode??"single"}});}function D($){if(s)return;let O={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};$.preventDefault(),y(O),a(m,{...i(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:n,name:m,render:({field:$})=>{let O=$.value?.value,V="";if(N&&O&&typeof O=="object"&&!Array.isArray(O)&&O[N]){let F=O[N],B=Array.isArray(F)?F[0]:F;typeof B=="string"?V=B:V=B?.[c$1]??B?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:C,children:p}),d?.comment?jsx(h$1,{children:d.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$7,{className:"fk:h-9.5 fk:py-1.75 fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",disabled:s,id:C,onBlur:()=>{f$1(false);},onClick:S,onFocus:()=>{f$1(true);},onKeyDown:F=>{F.key==="Enter"&&S(F);},readOnly:true,type:"text",value:V}),V?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",disabled:s,onClick:D,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",disabled:s,onClick:S,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i$1,{})]})}})}function ri(e){let{fieldSchema:t}=e,{relationship:n}=t;if(n?.mode==="single")return jsx(oi,{...e});if(n?.mode==="multiple"){if(n.entity==="_asset")return jsx(Zr,{...e});let o={relationshipEntityName:t.relationship?.entity,...e};return jsx(ni,{...o})}return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var pl="flexkit-select-option:";function ii(e){return `${pl}${encodeURIComponent(e)}`}function ip(e){return decodeURIComponent(e.slice(pl.length))}function gl({control:e$2,fieldSchema:t,readOnly:n,setValue:o}){let{name:r,label:i,options:s}=t;function l(a,u){let m=t.dataType==="int"&&!isNaN(Number(a))?Number(a):a;o(r,{...u,value:m});}function c$2(a,u){o(r,{...u,disabled:a});}return jsx(c,{control:e$2,name:r,render:({field:a})=>jsxs(e,{children:[jsx(f,{children:i}),s?.comment?jsx(h$1,{children:s.comment}):null,jsxs(a$5,{defaultValue:a.value?.value===void 0||a.value.value===null?void 0:ii(String(a.value.value)),disabled:n||a.value?.disabled,onValueChange:u=>{l(ip(u),a.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:s?.placeholder})})}),jsx(e$1,{children:s?.list?.map(u=>"groupLabel"in u?jsxs(b$2,{children:[jsx(f$1,{children:u.groupLabel}),u.items.map(f=>jsx(g$1,{value:ii(f.value),children:f.label},f.label))]},u.groupLabel):jsx(g$1,{value:ii(u.value),children:u.label},u.label))})]}),jsx(a$6,{checked:a.value?.disabled??false,disabled:n,onChange:u=>{c$2(u,a.value);},scope:a.value?.scope}),jsx(i$1,{})]})})}function li({inputType:e,label:t}){return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}var tn="all",ci={name:"all",title:"All fields"};function lp(e){return typeof e.group=="string"?[e.group]:Array.isArray(e.group)?e.group:[]}function ui(e,t){return t==="all"?true:lp(e).includes(t)}function fi(e,t){return t.length===0?true:t.some(n=>ui(e,n.name))}function di(e,t){if(!e||e.length===0)return [];let n=e.find(s=>s.name==="all"),o=e.filter(s=>s.name!=="all");return [{...ci,...n},...o].filter(s=>!St(s.hidden,t))}function mi(e){let t=e.find(o=>o.default);if(t)return t.name;let n=e.find(o=>o.name!=="all");return n?n.name:"all"}function bp(e,t){let n=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:n}}function Cp({currentScope:e,defaultScope:t,entityId:n,entityName:o,entityNamePlural:r,formData:i$1,schema:s,setIsDirty:l,onSubmit:c},a){let u=find(propEq(o,"name"))(s),[,f]=b(),m=f.user?.spaces,p=useMemo(()=>vn(u?.attributes??[],m),[u,m]),d$1=useMemo(()=>i$1||p.reduce((I,b)=>({...I,[b.name]:bp(b,t)}),{}),[t,i$1,p]),h$1=useForm({defaultValues:d$1,resolver:async(I,b,k)=>{let M=Vn(I),j=di(u?.groups,{record:M,value:M,currentUser:f.user}),Q={};for(let oe of p){if(typeof oe.validation>"u")continue;let q={record:M,value:M[oe.name],currentUser:f.user};St(oe.hidden,q)||St(oe.readOnly,q)||fi(oe,j)&&(Q[oe.name]=z.object({value:oe.validation(z).or(z.any().refine(()=>false,{error:oe.label?`${oe.label} is required`:"Required field"}))}));}return zodResolver(z.object(Q))(I,b,k)},values:i$1,mode:"onBlur",criteriaMode:"all"}),{control:v,getValues:y,handleSubmit:C,setValue:x$1,watch:A,trigger:R}=h$1,N=A(),S=Vn(N),D=useMemo(()=>di(u?.groups,{record:S,value:S,currentUser:f.user}),[f.user,u?.groups,S]),[$,O]=useState(()=>mi(D)),{getContributionPointConfig:V}=d(),F=useRef(i$1),B=useRef(false);useEffect(()=>{B.current||(F.current=i$1);},[i$1]);let K={datetime:Ra,editor:Qr,asset:Aa,number:Ta,relationship:ri,select:gl,switch:a$4,text:a$3,textarea:a$2};if(useImperativeHandle(a,()=>({submit(){R().then(()=>{C(()=>{let I=y();B.current=true,F.current=I,l(false),c(I,i$1);})();});},hasErrors(){B.current=false,F.current=i$1,l(true);},hasDataChanged(){return hl(y(),F.current)},markAsSaved(){B.current=true,F.current=y(),l(false);},applyLocalAttributeIds(I){let b=y(),k={...b};for(let[M,j]of Object.entries(I)){let Q=b[M];!Q||Q._id||!j||(k[M]={...Q,_id:j});}B.current=true,F.current=k;for(let[M,j]of Object.entries(k))j!==b[M]&&x$1(M,j,{shouldDirty:false,shouldTouch:false,shouldValidate:false});l(false);}})),useEffect(()=>{let I=A(()=>{l(hl(y(),F.current));});return ()=>{I.unsubscribe();}},[i$1,y,l,A]),useEffect(()=>{D.length!==0&&(D.some(I=>I.name===$)||O(mi(D)));},[$,D]),!u||u.attributes.length===0)return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Error"}),jsxs(ve,{children:["No attributes found in the schema for entity ",jsx("strong",{children:o})]})]});let ne=I=>{if(I.name==="_id")return null;let b={record:S,value:S[I.name],currentUser:f.user};if(St(I.hidden,b))return null;let k=St(I.readOnly,b),M=V("formFields",[I.inputType])?.[0]?.component??K[I.inputType];return M?createElement(M,{key:I.name,control:v,defaultScope:t,defaultValue:d$1[I.name],entityId:n,entityName:o,entityNamePlural:r,fieldSchema:I,getValues:y,readOnly:k,schema:s,scope:e,setValue:x$1}):jsx(li,{inputType:I.inputType,label:I.label},I.name)};return jsx(b$1,{...h$1,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-5",onSubmit:I=>{I.preventDefault();},children:D.length>0?jsxs(h,{onValueChange:O,value:$,children:[jsx("div",{className:"fk:sticky fk:top-0 fk:z-10 fk:bg-background fk:py-1 fk:mb-6",children:jsxs(w,{className:"fk:w-full fk:**:data-[slot=scroll-area-viewport]:h-auto fk:[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:hidden",children:[jsx(i,{className:"fk:h-9 fk:w-max fk:flex-nowrap fk:justify-start fk:border fk:border-border",children:D.map(I=>jsxs(j,{className:"fk:shrink-0 fk:px-4 fk:dark:data-[state=active]:border-transparent! fk:dark:data-[state=active]:bg-background",value:I.name,children:[I.icon,I.title]},I.name))}),jsx(x,{orientation:"horizontal"})]})}),jsx(k,{className:"fk:gap-8",value:$,children:p.map(I=>{if(!fi(I,D))return null;let b=ui(I,$),k=ne(I);return k?jsx("div",{className:b?void 0:"fk:hidden",children:k},I.name):null})})]}):p.map(I=>ne(I))})})}var Qo=memo(forwardRef(Cp));function hl(e,t){if(!t)return Object.keys(e).some(s=>e[s]?.value!==""&&e[s]?.value!==void 0);let n=s=>typeof s=="object"&&s!==null?"path"in s?s.path:"_id"in s?s._id:"":s??"",o=(s,l)=>s<l?-1:1,r=Object.keys(t).sort((s,l)=>o(s,l)).filter(s=>s!=="_updatedAt").reduce((s,l)=>({...s,[l]:{value:n(t[l].value),disabled:t[l].disabled,relationships:t[l].relationships}}),{}),i=Object.keys(e).sort((s,l)=>o(s,l)).filter(s=>s!=="_updatedAt").reduce((s,l)=>({...s,[l]:{value:n(e[l]?.value),disabled:e[l]?.disabled??false,relationships:Object.keys(e[l]?.relationships?.connect??{}).length||e[l]?.relationships?.disconnect?.length?e[l]?.relationships:void 0}}),{});return !equals(r,i)}function yl(e){return e?e!=="viewer":true}function Dt(){let[,e]=b();return yl(e.user?.role)}function hi({action:e,depth:t,isFocused:n}){let{entityName:o}=e.payload,r=useRef(null),i=Dt(),[,s]=b(),{projects:l,currentProjectId:c}=d(),{schema:a,scopes:u}=find(propEq(c??"","projectId"))(l),f=u?.find(F=>F.isDefault)?.name??"default",p=find(propEq(o,"name"))(a)?.plural??o,{scope:d$1}=c$2(),g=ge(),h=useApolloClient(),[v,y,C,x]=xt(),{isDirty:A,setIsDirty:R}=yn(),[N,S]=useState(false);useEffect(()=>{x.error&&r.current?.hasErrors();},[x.error]);function D(){return A?(g({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:()=>{g({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{R(false),g({type:"Dismiss",_id:"unsavedChanges",payload:{}}),S(true);}}}}),false):true}let $=useCallback(F=>{g({type:"Dismiss",_id:F,payload:{}});},[g]),O=useCallback(()=>{r.current?.submit();},[r]),V=useCallback(F=>{let B=v4(),K=Tr(p,a,F,B,{currentUser:s.user});y(gql`
442
383
  ${K}
443
- `),D({variables:{where:{_id:{eq:o}}},onCompleted:te=>{i.current?.applyLocalAttributeIds(Oa(te,r,l)),wt(C,Ge(r,l)),toast.success("Your changes have been saved.");}}),v(true);},[C,d$3,o,r,v,l,b,D]),T=G,k=T.length>0,V=H&&!k;function W(_,B){let K=_?.attributes.find(P=>P.isPrimary)??_?.attributes[0],te=K.name,ye=K?.relationship?.field!==void 0;if(!B.length)return "";if(!ye||!K?.relationship?.field)return B[0][te]?.value;let L=B[0][te]?.value?.[K.relationship.field],O=Array.isArray(L)?L[0]:L;if(O&&typeof O=="object"){let P=O;return P[d$3]??P.default??""}return O??""}let ee=k&&m?W(m,T):"";return jsx(h$2,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:_=>{j(_);},value:d$3,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(d$3,"name"))(c).label})]}),jsx(e$1,{children:c.map(_=>jsx(g$1,{value:_.name,children:_.label},_.name))})]}):null,jsx(li,{handleSave:R,isLoading:E.loading})]}),beforeClose:M,depth:t,isFocused:n,onClose:()=>{A(e._id);},onFormChange:()=>{},title:ee,children:V||!k?jsx(ci,{}):jsxs(Fragment,{children:[E.isProjectReadOnly?jsx(Ks,{}):null,jsx(Ho,{currentScope:d$3,defaultScope:f,entityId:o,entityName:u,entityNamePlural:r,formData:T[0],onSubmit:Z,ref:i,schema:l,setIsDirty:$})]})})}var il=25;function up(e){return e.map(t=>({...t,cell:()=>jsx(r$2,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function gi({action:e,depth:t,isFocused:n}){let o=de(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:l,connectionName:c,entityId:f,entityName:m,initialAssetPath:u,initialConnection:p,mode:d$1,relationshipId:g}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:C}=find(propEq(y??"","projectId"))(h),v=find(propEq(m,"name"))(C),b=v?.plural??"",D=i[g],E=Vn(),w=m==="_asset",x=w?"asset":v?.menu?.label??m.toLowerCase(),$=w&&d$1==="single"?"Select asset":`Select ${w?"assets":x}`,M=d$1==="single"?"Upload asset":"Upload assets",[A,R]=useState([]),j=[];if(p)j=[{id:p._id,value:p.value}];else if(D?.connect){let z=D.connect;j=[{id:z._id,value:z.value}];}let H=d$1==="single"?j:D?.connect?.map(z=>({id:z._id,value:z.value}))||[],[G,Z]=useState(H),T=useMemo(()=>{let z=[];return w&&z.push({NOT:{path:{eq:null}}}),d$1==="multiple"&&c&&f&&z.push({[c]:{none:{_id:{eq:f}}}}),A.length>0&&z.push({OR:A.map(ne=>({_id:{eq:ne._id}}))}),z.length===0?{}:z.length===1?z[0]:{AND:z}},[c,f,w,d$1,A]),{count:k,data:V,fetchMore:W,isLoading:ee,isLoadingMore:_}=Xn({entityNamePlural:b,schema:C,scope:a,variables:{offset:0,limit:il,where:T,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),B=!!V?.length,K=ee&&!B,te=V?.length??0,ye=k-l,L=ye>0&&te>0&&te<ye,O=Un({attributesSchema:v?.attributes??[],checkboxSelect:d$1}),P=Array(5).fill({}),I=up(O);useEffect(()=>{if(d$1!=="single"||G.length>0||!u||!V?.length)return;let z=V.find(ne=>ne.path===u);!z?._id||typeof z._id!="string"||Z([{id:z._id,value:z}]);},[V,u,d$1,G.length]);let U=useCallback(z=>{o({type:"Dismiss",_id:z,payload:{}});},[o]),Q=useCallback(()=>{W({variables:{offset:0,limit:il,where:T}});},[T,W]);function se(){let z;if(d$1==="single"){let[ne]=G;z={_id:ne?.id??"",value:ne?.value??null};}d$1==="multiple"&&(z=G?.map((ne,je)=>({_id:ne.id??"",...w?{sortOrder:je}:{},value:ne.value}))),r({type:"setRelationship",payload:{[g]:{connect:z,disconnect:D?.disconnect??[]}}}),U(e._id);}function ge(z){if(d$1==="multiple"){Z(je=>{let He=new Map(je.map(fe=>[fe.id,fe]));return z.map(fe=>{if(He.has(fe))return He.get(fe);let Wo=V?.find(Kn=>Kn._id===fe);return {id:fe,value:Wo}})});return}let ne=z[z.length-1];Z(ne?je=>{if(je.length===1&&je[0].id===ne)return je;let He=V?.find(fe=>fe._id===ne);return [{id:ne,value:He}]}:[]);}function le(){o({type:"AddEntity",payload:{entityName:m}});}async function _e(){let z=await E({projectId:y,accept:s??"image/*",multiple:d$1==="multiple",maxBytes:4194304});Z(ne=>{if(d$1==="single"){let[fe]=z;return fe?[{id:fe._id,value:fe.asset}]:ne}let je=new Set(ne.map(fe=>fe.id)),He=z.filter(fe=>!je.has(fe._id)).map(fe=>({id:fe._id,value:fe.asset}));return [...ne,...He]});}return jsx(h$2,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{se();},variant:"default",children:"Select"}),w?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{le();},variant:"outline",children:`Create ${x}`}),w?jsxs(b$3,{className:"fk:px-8",onClick:()=>{_e();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),M]}):null]}),depth:t,isFocused:n,onClose:()=>{U(e._id);},title:$,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Jn,{columns:K?I:O,data:K?P:V??[],entityName:v?.name??"",hasMore:L,initialSelectionState:G?.reduce((z,ne)=>({...z,...ne.id?{[ne.id]:true}:{}}),{}),isLoadingMore:_,onEntitySelectionChange:ge,onLoadMore:Q,toolbarComponent:()=>jsx(dp,{entityNamePlural:b,projectId:y??"",setSearchResultIds:R})})})})}function dp({entityNamePlural:e,projectId:t,setSearchResultIds:n}){let[o,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:l,isLoading:c}=e$5(t,a),f=useRef(null),m=useMemo(()=>mp(p=>{s({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(l){let p=JSON.stringify(l.map(g=>g._id).sort()),d=f.current?JSON.stringify(f.current.map(g=>g._id).sort()):"";p!==d&&(f.current=[...l],n(l.map(g=>({_id:g._id}))));}},[l,n]);function u(p){let{value:d}=p.target;r(d),m(d);}return jsxs("div",{className:"fk:relative fk:w-full",children:[c?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$7,{className:"fk:w-full fk:pl-11!",onChange:u,placeholder:"Search",value:o})]})}function mp(e,t=300){let n;return (...o)=>{clearTimeout(n),n=setTimeout(()=>e(...o),t);}}function sl(){let e=Na(),t=e.filter(o=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===o.type)),n=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(o=>{switch(o.type){case "AlertDialog":{let{payload:r}=o;return jsx(Pn,{options:r.options},o._id)}case "DeleteEntity":return jsx(Sr,{action:o},o._id);case "AddEntity":return jsx(ri,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditEntity":return jsx(di,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditRelationship":return jsx(gi,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);default:return null}})})}function ll({config:e}){let[t]=e,{basePath:n,projectId:o}=t,r=a$g(n);return window.location.pathname===r&&(window.location.href=b$a(r,o)),jsx(a$j,{children:jsx(c$6,{config:e,children:jsxs(ma,{children:[jsx(Ja,{children:jsx(sl,{})}),jsx(Outlet,{})]})})})}function cl(){let e=useRouteError(),t=new Date().getFullYear();function n(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):sr(e)?Ki(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:n()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(lo,{})]})})]})}function hi(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ke,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Error"}),jsx(he,{children:t})]})}var Np=RouterProvider;function Dp({config:e}){let[t,n]=useState(false),o=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(f=>fl(f)):[fl(e)],[i]=r,a=a$g(i?.basePath),s=e$4(r);if(useEffect(()=>{n(true);},[]),!t)return null;let l=[{path:a,element:jsx(ll,{config:r}),errorElement:jsx(cl,{}),children:[{path:":projectId",element:jsx(ia,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(f=>({path:f.name,element:f.component,errorElement:jsx(hi,{}),children:f.routes?.map(m=>({path:m.path,element:m.component,errorElement:jsx(hi,{}),children:m.children?.map(u=>({path:u.path,element:u.component}))}))}))}]}],c=createBrowserRouter(l);return o("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Ta,{children:jsx(Np,{router:c})})})})}function fl(e){return {basePath:a$g(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function Pp(){return jsxs(ke,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Project Paused"}),jsxs(he,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function Fp(){let{schemaErrorMessage:e}=Jt();if(!e)return jsx(Fragment,{});let[t,n,...o]=e.split(`
444
- `);return jsxs(ke,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(ze,{children:"Schema mismatch"}),jsxs(he,{children:[jsx("p",{children:t}),n?jsx("p",{className:"fk:mt-1",children:n}):null,o.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:o.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function $p(e){return e}function Mp(e,t){if(e.dataType==="asset"&&e.scope!==void 0&&e.scope!=="global")throw new Error(`Attribute "${e.name}" in entity "${t}" uses dataType "asset" but scope "${e.scope}". Asset attributes must use scope "global" or omit scope.`)}function _p(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function ml(e){return e.attributes.forEach(t=>{Mp(t,e.name);}),{...e,attributes:e.attributes.map(_p)}}function Op(e){return ml(e)}function zp(e){let t=useApolloClient(),{currentProjectSchema:n}=d();return useCallback(async()=>{n&&await wt(t,Ge(e,n));},[t,e,n])}function Hp(e){let{currentProjectSchema:t}=d();return useCallback(n=>{t&&Ha(Ge(e,t),n);},[e,t])}function Jp({column:e,title:t$1,options:n}){let o$1=new Set(e?.getFilterValue());return jsxs(kn,{children:[jsx(hn,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk:h-8 fk:border-dashed",children:[jsx(CirclePlus,{className:"fk:mr-2 fk:h-4 fk:w-4"}),t$1,o$1?.size>0&&jsxs(Fragment,{children:[jsx(g$3,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:o$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:o$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[o$1.size," selected"]}):n.filter(r=>o$1.has(r.value)).map(r=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:r.label},r.value))})]})]})}),jsx(Mt,{className:"fk:w-50 fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p$1,{children:[jsx(q$1,{children:"No results found."}),jsx(r$1,{children:n.map(r=>{let i=o$1.has(r.value);return jsxs(t,{onSelect:()=>{i?o$1.delete(r.value):o$1.add(r.value);let a=Array.from(o$1);e?.setFilterValue(a.length?a:void 0);},children:[jsx("div",{className:a$4("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",i?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("fk:size-3.5",i?"fk:text-primary-foreground":"fk:text-muted-foreground")})}),r.icon&&jsx(r.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:r.label})]},r.value)})}),o$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r$1,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function Xp({entityName:e,entityNamePlural:t,row:n,options:o={canDelete:true,canEdit:true}}){let r=de(),i=Et(),a=n.original._id,s=(o.canDelete??true)&&i,l=o.canEdit??true;function c(){r({type:"EditEntity",payload:{entityId:a,entityNamePlural:t}});}function f(){r({type:"DeleteEntity",payload:{entityId:a,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[l&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:c,variant:"ghost",children:[jsx(PencilIcon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),s&&!l&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:f,variant:"ghost",children:[jsx(Trash2Icon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),l&&s&&jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Additional actions"})]})}),jsxs(f$2,{align:"end",className:"w-[160px]",children:[jsxs(h$1,{onClick:c,children:[jsx(PencilIcon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Edit"]}),jsx(m,{}),jsxs(h$1,{className:"fk:text-destructive",onClick:f,children:[jsx(Trash2Icon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete"]})]})]})]})}function vi({table:e}){let[t]=e.getState().sorting;if(!t)return null;let o=e.getColumn(t.id)?.columnDef.meta?.label??t.id,r=t.desc?"desc":"asc";return jsxs(b$3,{"aria-label":`Clear sorting by ${o}`,className:"fk:h-8 fk:px-2 fk:lg:px-3 fk:text-success fk:border-none",onClick:()=>{e.resetSorting();},size:"sm",variant:"outline",children:["Sorted by ",o," ",r,jsx(X,{className:"fk:ml-1 fk:h-4 fk:w-4"})]})}function Ci({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:n=>{t.toggleVisibility(!!n);},children:t.id},t.id))]})]})}function ig({entityName:e,isReloading:t=false,onReload:n,table:o}){let r=de(),i=d$2(),a=c$2(),s=useApolloClient(),{projects:l,currentProjectId:c}=d(),{schema:f,scopes:m}=find(propEq(c??"","projectId"))(l),[u$1,p,d$3]=vt(),[g,h]=useState(false),y=Et(),C=o.getSelectedRowModel().rows.map(w=>w.original._id);function v(){r({type:"AddEntity",payload:{entityName:e}});}function b(w){i({type:"setScope",payload:{projectId:c,scope:w}});}async function D(w){if(w.length===0)return;let x=Mn(e,f,w);await new Promise(($,M)=>{p(gql`
445
- ${x}
446
- `),d$3({variables:{where:_n(w)},update(A){for(let R of w)A.evict({id:R});},onCompleted:()=>{$();},onError:A=>{M(A);}}),u$1(true);});}function E(){let w=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${C.length} ${w}${C.length>1?"s":""}`,dialogMessage:C.length>1?`Are you sure you want to delete the selected ${w}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${w}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{h(true);try{let x=[...C];await D(x),o.resetRowSelection(),await Eo(s,Ge(e,f),x),toast.success(x.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{h(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[m&&m.length>0?jsxs(a$5,{defaultValue:a.scope,onValueChange:w=>{b(w);},value:a.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(a.scope??"","name"))(m)||null)?.label})]}),jsx(e$1,{children:m.map(w=>jsx(g$1,{value:w.name,children:w.label},w.name))})]}):null,jsx(Ci,{table:o}),n?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:g||t,onClick:n,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(vi,{table:o})]}),C.length>0?jsx(u,{disabled:!y,children:jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:g||!y,onClick:E,size:"sm",variant:"destructive",children:[g?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",C.length,")"]})}):null,jsx(u,{disabled:!y,children:jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:g||!y,onClick:v,size:"sm",variant:"default",children:"Create"})})]})}export{Jn as DataTable,Mo as DataTableColumnHeader,Jp as DataTableFacetedFilter,Xp as DataTableRowActions,vi as DataTableSortedBy,ig as DataTableToolbar,Ci as DataTableViewOptions,Dp as FlexkitStudio,Pp as ProjectDisabled,Fp as SchemaError,Er as canAccessSpaces,Us as canMutateData,$p as defineConfig,Op as defineEntity,pn as filterAttributesForSpaces,kf as filterEntitiesForSpaces,vr as getEntityCreateMutation,Mn as getEntityDeleteMutation,_n as getEntityDeleteWhere,wo as getEntityQuery,Ct as getEntitySchema,hr as getEntityUpdateMutation,Et as useCanMutate,de as useDispatch,vt as useEntityMutation,Xn as useEntityQuery,Jt as useGraphQLError,Un as useGridColumnsDefinition,Hp as usePatchEntityList,zp as useRefreshEntityList,Vn as useUploadAssets};//# sourceMappingURL=index.js.map
384
+ `),C({onCompleted:()=>{At(h,Ke(p,a)),$(e._id),toast.success("Your changes have been saved.");}}),v(true);},[e._id,h,s.user,p,$,v,a,y,C]);return jsx(g$3,{actions:jsx(x$1,{disabled:!i,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{O();},variant:"default",children:[x.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:D,depth:t,forceClose:N,isFocused:n,onClose:()=>{$(e._id);},title:`Add ${o}`,children:jsx(Qo,{currentScope:d$1,defaultScope:f,entityName:o,entityNamePlural:p,onSubmit:V,ref:r,schema:a,setIsDirty:R})})}function ro({entityNamePlural:e,schema:t,scope:n,variables:o,isForm:r,selection:i="full"}){let[s,l]=useState({count:0,results:[]}),[c,a]=useState(false),[u,f]=useState(false),[m,p]=useState(null),d=useRef(false),g=useRef(false),h=useRef(0),v=useRef(null),y=useRef(null),C=`${e}Total`,x=rt(t,e),R=o?.where===void 0&&(x?.spaces?.length??0)===0&&(m?.field!==C||m.schema!==t)?"total":"aggregate",N=jn(e,n,t,{selection:i,countMode:R}),S=useMemo(()=>gql`
385
+ ${N.query}
386
+ `,[N.query]),D=jn(e,n,t,{selection:i,includeCount:false}),$=useMemo(()=>gql`
387
+ ${D.query}
388
+ `,[D.query]),{schemaErrorMessage:O,setSchemaErrorMessage:V}=Wt(),{loading:F,data:B,fetchMore:K,refetch:ne,error:I,networkStatus:b}=useQuery(S,{variables:o,notifyOnNetworkStatusChange:true}),k=useRef(K),M=useRef(ne),j=useRef($),Q=useRef(b),se=useRef(o);k.current=K,M.current=ne,j.current=$,se.current=o;let oe=Rs(I,C),q=R==="total"&&oe,ue=oe?void 0:I,he=oe&&!B?.[e],z=Qt(ue),E=wo(ue),{isProjectDisabled:pe,isProjectReadOnly:L}=(()=>{if(z?.statusCode===403){let H=Xt(z.bodyText);if(H&&typeof H.code=="string"){if(H.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(H.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();useEffect(()=>{q&&p({field:C,schema:t});},[t,q,C]);let Z=useCallback(H=>{if(d.current||g.current)return;d.current=true,a(true);let{limit:ee}=H.variables,X=h.current;k.current({...H,query:j.current,variables:{...se.current,...H.variables,offset:X,limit:ee}}).then(({data:_})=>{let U=oo({data:_,entityNamePlural:e,isForm:r,schema:t,scope:n}),ae=U.results.length;h.current=X+(ae===0?0:Math.min(ae,ee)),l(le=>{let J=uniqBy(prop("_id"),[...le.results,...U.results]);return J.length===le.results.length?{count:le.results.length,results:le.results}:{count:U.count||le.count,results:J}});}).catch(_=>{console.error("Error fetching more data:",_);}).finally(()=>{d.current=false,a(false);});},[e,r,t,n]),Y=useCallback(H=>{if(g.current)return Promise.resolve();let ee=H?.preserve===true;return g.current=true,d.current=false,a(false),ee||(v.current=null,y.current=null,h.current=0,f(true),l({count:0,results:[]})),M.current().then(({data:X})=>{let _=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),U=oo({data:X,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=_,y.current=null,h.current=Ko(o)+U.results.length,l(U);}).catch(X=>{console.error("Error reloading data:",X);}).finally(()=>{g.current=false,f(false);})},[e,r,t,n,i,o]);return useEffect(()=>{if(E){V(E);return}B&&O&&!ue&&V(null);},[B,ue,O,E,V]),useEffect(()=>{if(ue||E||he)return;let H=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o});if(v.current===H)return;if(F&&y.current!==H){y.current=H,h.current=0,l({count:0,results:[]});return}if(F)return;let ee=oo({data:B,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=H,y.current=null,h.current=Ko(o)+ee.results.length,l(ee);},[B,ue,e,r,F,he,t,E,n,i,o]),useEffect(()=>{let H=Q.current;if(Q.current=b,ue||E||g.current||he||H!==NetworkStatus.refetch||b!==NetworkStatus.ready||!B)return;let ee=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),X=oo({data:B,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=ee,y.current=null,h.current=Ko(o)+X.results.length,l(X);},[B,ue,e,r,he,b,t,E,n,i,o]),useEffect(()=>{if(r)return;let H=`Get${ot(e)}`,ee=da(U=>{if(!(!U.has(H)||d.current||g.current))return M.current().then(({data:ae})=>{let le=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),J=oo({data:ae,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=le,y.current=null,h.current=Ko(o)+J.results.length,l(J);}).catch(ae=>{console.error("Error soft-refreshing entity list:",ae);})}),X=ma((U,ae)=>{U===H&&l(le=>{let J=le.results.filter(rn=>{let Rn=typeof rn._id=="string"?rn._id:void 0;return !Rn||!ae.has(Rn)}),on=le.results.length-J.length;return on===0?le:{count:Math.max(0,le.count-on),results:J}});}),_=pa((U,ae)=>{U===H&&l(le=>Lp(le,ae,o?.sort));});return ()=>{ee(),X(),_();}},[e,r,t,n,i,o]),{isLoading:F&&b!==NetworkStatus.refetch||u||he,isLoadingMore:c,fetchMore:Z,reload:Y,count:s.count,data:s.results,isProjectDisabled:pe,isProjectReadOnly:L,schemaErrorMessage:O}}function Ko(e){let t=e?.offset;return typeof t=="number"&&Number.isFinite(t)?t:0}function oo(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?oa(e.entityNamePlural,e.scope,e.data,e.schema):To(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function Lp(e,t,n){let o=new Map(t.map(s=>[s._id,s])),r=false,i=e.results.map(s=>{let l=typeof s._id=="string"?s._id:void 0;if(!l)return s;let c=o.get(l);return c?(r=true,{...s,...c.attributes}):s});return r?{count:e.count,results:Mp(i,n)}:e}function Mp(e,t){if(!Array.isArray(t)||t.length===0)return e;let[n]=t;if(!n||typeof n!="object")return e;let[o]=Object.entries(n),[r,i]=o??[];if(!r||i!=="ASC"&&i!=="DESC")return e;let s=i==="DESC"?-1:1;return [...e].sort((l,c)=>{let a=l[r],u=c[r],f=typeof a=="string"?a:"",m=typeof u=="string"?u:"";return f.localeCompare(m)*s})}function El(){return jsxs(ye,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Read Only Mode"}),jsxs(ve,{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 bi({handleSave:e,isLoading:t}){let{isDirty:n}=yn(),o=Dt();return jsx(x$1,{disabled:!o,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!n||!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})})}function Ci(){return jsx(Fragment,{children:Array.from({length:10},(t,n)=>n++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$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 Si({action:e,depth:t,isFocused:n}){let{entityId:o,entityNamePlural:r}=e.payload,i=useRef(null),{projects:s,currentProjectId:l}=d(),{schema:c,scopes:a}=useCallback(()=>find(propEq(l??"","projectId"))(s),[l,s])(),u=a?.find(q=>q.isDefault)?.name??"default",f=find(propEq(r,"plural"))(c),m=f?.name??r,{scope:p}=c$2(),[d$3,g]=useState(p),h=ge(),v=d$2(),y=useApolloClient(),[C,x,A,R]=xt(),{isDirty:N,setIsDirty:S}=yn(),[D,$]=useState(false),[,O]=b(),V=useCallback(q=>{S(q);},[S]);useEffect(()=>{R.error&&i.current?.hasErrors();},[R.error]);let F=useCallback(()=>N?(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:()=>{S(false),h({type:"Dismiss",_id:"unsavedChanges",payload:{}}),$(true);}}}}),false):true,[h,N,S]),B=useCallback(q=>{h({type:"Dismiss",_id:q,payload:{}});},[h]),K=useCallback(()=>{i.current?.submit();},[i]);function ne(q){if(N){h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{g(d$3),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}}),g(q),v({type:"setScope",payload:{projectId:l,scope:q}});}}}});return}g(q),v({type:"setScope",payload:{projectId:l,scope:q}});}let{isLoading:I,data:b$1}=ro({entityNamePlural:r,schema:c,scope:d$3,variables:{where:{_id:{eq:o}}},isForm:true}),k=useCallback((q,ue)=>{if(!ue)return;let he=Er(r,o,d$3,c,ue,q,{currentUser:O.user});x(gql`
389
+ ${he}
390
+ `),A({variables:{where:{_id:{eq:o}}},onCompleted:z=>{i.current?.applyLocalAttributeIds(ua(z,r,c)),At(y,Ke(r,c)),toast.success("Your changes have been saved.");}}),C(true);},[y,O.user,d$3,o,r,C,c,x,A]),M=b$1,j=M.length>0,Q=I&&!j;function se(q,ue){let he=e$4(q),z=he?.name,E=he?.relationship?.field!==void 0;if(!ue.length||!z)return "";if(!E||!he?.relationship?.field)return ue[0][z]?.value;let pe=ue[0][z]?.value?.[he.relationship.field],L=Array.isArray(pe)?pe[0]:pe;if(L&&typeof L=="object"){let Z=L;return Z[d$3]??Z.default??""}return L??""}let oe=j&&f?se(f,M):"";return jsx(g$3,{actions:jsxs(Fragment,{children:[a&&a.length>1?jsxs(a$5,{onValueChange:q=>{ne(q);},value:d$3,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(d$3,"name"))(a).label})]}),jsx(e$1,{children:a.map(q=>jsx(g$1,{value:q.name,children:q.label},q.name))})]}):null,jsx(bi,{handleSave:K,isLoading:R.loading})]}),beforeClose:F,depth:t,forceClose:D,isFocused:n,onClose:()=>{B(e._id);},onFormChange:()=>{},title:oe,children:Q||!j?jsx(Ci,{}):jsxs(Fragment,{children:[R.isProjectReadOnly?jsx(El,{}):null,jsx(Qo,{currentScope:d$3,defaultScope:u,entityId:o,entityName:m,entityNamePlural:r,formData:M[0],onSubmit:k,ref:i,schema:c,setIsDirty:V})]})})}var Il=25;function Xp(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Ti({action:e,depth:t,isFocused:n}){let o=ge(),r=d$2(),{relationships:i,scope:s}=c$2(),{assetAccept:l,connectedEntitiesCount:c,connectionName:a,entityId:u,entityName:f,initialAssetPath:m,initialConnection:p,mode:d$1,relationshipId:g}=e.payload,{projects:h,currentProjectId:v}=d(),{schema:y}=find(propEq(v??"","projectId"))(h),C=find(propEq(f,"name"))(y),x=C?.plural??"",A=i[g],R=Gn(),N=f==="_asset",S=N?"asset":C?.menu?.label??f.toLowerCase(),D=N&&d$1==="single"?"Select asset":`Select ${N?"assets":S}`,$=d$1==="single"?"Upload asset":"Upload assets",[O,V]=useState([]),F=[];if(p)F=[{id:p._id,value:p.value}];else if(A?.connect){let _=A.connect;F=[{id:_._id,value:_.value}];}let B=d$1==="single"?F:A?.connect?.map(_=>({id:_._id,value:_.value}))||[],[K,ne]=useState(B),I=useMemo(()=>{let _=[];return N&&_.push({NOT:{path:{eq:null}}}),d$1==="multiple"&&a&&u&&_.push({[a]:{none:{_id:{eq:u}}}}),O.length>0&&_.push({OR:O.map(U=>({_id:{eq:U._id}}))}),_.length===0?{}:_.length===1?_[0]:{AND:_}},[a,u,N,d$1,O]),{count:b,data:k,fetchMore:M,isLoading:j,isLoadingMore:Q}=ro({entityNamePlural:x,schema:y,scope:s,variables:{offset:0,limit:Il,where:I,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),se=!!k?.length,oe=j&&!se,q=k?.length??0,ue=b-c,he=ue>0&&q>0&&q<ue,z=Yn({attributesSchema:C?.attributes??[],checkboxSelect:d$1}),E=Array(5).fill({}),pe=Xp(z);useEffect(()=>{if(d$1!=="single"||K.length>0||!m||!k?.length)return;let _=k.find(U=>U.path===m);!_?._id||typeof _._id!="string"||ne([{id:_._id,value:_}]);},[k,m,d$1,K.length]);let L=useCallback(_=>{o({type:"Dismiss",_id:_,payload:{}});},[o]),Z=useCallback(()=>{M({variables:{offset:0,limit:Il,where:I}});},[I,M]);function Y(){let _;if(d$1==="single"){let[U]=K;_={_id:U?.id??"",value:U?.value??null};}d$1==="multiple"&&(_=K?.map((U,ae)=>({_id:U.id??"",...N?{sortOrder:ae}:{},value:U.value}))),r({type:"setRelationship",payload:{[g]:{connect:_,disconnect:A?.disconnect??[]}}}),L(e._id);}function H(_){if(d$1==="multiple"){ne(ae=>{let le=new Map(ae.map(J=>[J.id,J]));return _.map(J=>{if(le.has(J))return le.get(J);let on=k?.find(rn=>rn._id===J);return {id:J,value:on}})});return}let U=_[_.length-1];ne(U?ae=>{if(ae.length===1&&ae[0].id===U)return ae;let le=k?.find(J=>J._id===U);return [{id:U,value:le}]}:[]);}function ee(){o({type:"AddEntity",payload:{entityName:f}});}async function X(){let _=await R({projectId:v,accept:l??"image/*",multiple:d$1==="multiple",maxBytes:4194304});ne(U=>{if(d$1==="single"){let[J]=_;return J?[{id:J._id,value:J.asset}]:U}let ae=new Set(U.map(J=>J.id)),le=_.filter(J=>!ae.has(J._id)).map(J=>({id:J._id,value:J.asset}));return [...U,...le]});}return jsx(g$3,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Y();},variant:"default",children:"Select"}),N?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{ee();},variant:"outline",children:`Create ${S}`}),N?jsxs(b$3,{className:"fk:px-8",onClick:()=>{X();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),$]}):null]}),depth:t,isFocused:n,onClose:()=>{L(e._id);},title:D,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(eo,{columns:oe?pe:z,data:oe?E:k??[],entityName:C?.name??"",hasMore:he,initialSelectionState:K?.reduce((_,U)=>({..._,...U.id?{[U.id]:true}:{}}),{}),isLoadingMore:Q,onEntitySelectionChange:H,onLoadMore:Z,toolbarComponent:()=>jsx(Wp,{entityNamePlural:x,projectId:v??"",setSearchResultIds:V})})})})}function Wp({entityNamePlural:e,projectId:t,setSearchResultIds:n}){let[o,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[s,l]=useState(i),{results:c,isLoading:a}=f$4(t,s),u=useRef(null),f=useMemo(()=>Kp(p=>{l({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(c){let p=JSON.stringify(c.map(g=>g._id).sort()),d=u.current?JSON.stringify(u.current.map(g=>g._id).sort()):"";p!==d&&(u.current=[...c],n(c.map(g=>({_id:g._id}))));}},[c,n]);function m(p){let{value:d}=p.target;r(d),f(d);}return jsxs("div",{className:"fk:relative fk:w-full",children:[a?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$7,{className:"fk:w-full fk:pl-11!",onChange:m,placeholder:"Search",value:o})]})}function Kp(e,t=300){let n;return (...o)=>{clearTimeout(n),n=setTimeout(()=>e(...o),t);}}function Ml(){let e=Ws(),t=e.filter(o=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===o.type)),n=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(o=>{switch(o.type){case "AlertDialog":{let{payload:r}=o;return jsx(_n,{options:r.options},o._id)}case "DeleteEntity":return jsx(Pr,{action:o},o._id);case "AddEntity":return jsx(hi,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditEntity":return jsx(Si,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditRelationship":return jsx(Ti,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);default:return null}})})}function _l({config:e}){let[t]=e,{basePath:n,projectId:o}=t,r=a$g(n);return window.location.pathname===r&&(window.location.href=b$a(r,o)),jsx(a$j,{children:jsx(c$7,{config:e,children:jsxs(Ms,{children:[jsx(ya,{children:jsx(Ml,{})}),jsx(Outlet,{})]})})})}function $l(){let e=useRouteError(),t=new Date().getFullYear();function n(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):fr(e)?gs(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:n()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(ho,{})]})})]})}function Di(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ye,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:t})]})}var dg=RouterProvider;function mg({config:e}){let[t,n]=useState(false),o=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(u=>Ol(u)):[Ol(e)],[i]=r,s=a$g(i?.basePath),l=e$5(r);if(useEffect(()=>{n(true);},[]),!t)return null;let c=[{path:s,element:jsx(_l,{config:r}),errorElement:jsx($l,{}),children:[{path:":projectId",element:jsx(Es,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:l.map(u=>({path:u.name,element:u.component,errorElement:jsx(Di,{}),children:u.routes?.map(f=>({path:f.path,element:f.component,errorElement:jsx(Di,{}),children:f.children?.map(m=>({path:m.path,element:m.component}))}))}))}]}],a=createBrowserRouter(c);return o("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Xs,{children:jsx(dg,{router:a})})})})}function Ol(e){return {basePath:a$g(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function gg(){return jsxs(ye,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Project Paused"}),jsxs(ve,{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 hg(){let{schemaErrorMessage:e}=Wt();if(!e)return jsx(Fragment,{});let[t,n,...o]=e.split(`
391
+ `);return jsxs(ye,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Schema mismatch"}),jsxs(ve,{children:[jsx("p",{children:t}),n?jsx("p",{className:"fk:mt-1",children:n}):null,o.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:o.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function vg(e){return e}function bg(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 Cg(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function wg(e){let t=e.display?e.attributes.find(n=>n.name===e.display):e.attributes[0];if(e.display&&!t)throw new Error(`Entity "${e.name}" sets display to "${e.display}", but no attribute has that name.`);if(!(!t||(t.spaces??[]).length===0))throw new Error(`Entity "${e.name}" cannot use space-bound attribute "${t.name}" as its display field.`)}function zl(e){return e.attributes.forEach(t=>{bg(t,e.name);}),wg(e),{...e,attributes:e.attributes.map(Cg)}}function xg(e){return zl(e)}function Ag(e){let t=useApolloClient(),{currentProjectSchema:n}=d();return useCallback(async()=>{n&&await At(t,Ke(e,n));},[t,e,n])}function Ng(e){let{currentProjectSchema:t}=d();return useCallback(n=>{t&&ga(Ke(e,t),n);},[e,t])}function Fg({column:e,title:t,options:n}){let o=new Set(e?.getFilterValue());return jsxs(Cn,{children:[jsx(wn,{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,o?.size>0&&jsxs(Fragment,{children:[jsx(c$5,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:o.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:o.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[o.size," selected"]}):n.filter(r=>o.has(r.value)).map(r=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:r.label},r.value))})]})]})}),jsx(Vt,{className:"fk:w-50 fk:p-0",align:"start",children:jsxs(n$1,{children:[jsx(p$1,{placeholder:t}),jsxs(q$1,{children:[jsx(r,{children:"No results found."}),jsx(s$1,{children:n.map(r=>{let i=o.has(r.value);return jsxs(u$1,{onSelect:()=>{i?o.delete(r.value):o.add(r.value);let s=Array.from(o);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$1("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",i?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$1("fk:size-3.5",i?"fk:text-primary-foreground":"fk:text-muted-foreground")})}),r.icon&&jsx(r.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:r.label})]},r.value)})}),o.size>0&&jsxs(Fragment,{children:[jsx(t$1,{}),jsx(s$1,{children:jsx(u$1,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function Ig({entityName:e,entityNamePlural:t,row:n,options:o={canDelete:true,canEdit:true}}){let r=ge(),i=Dt(),s=n.original._id,l=(o.canDelete??true)&&i,c=o.canEdit??true;function a(){r({type:"EditEntity",payload:{entityId:s,entityNamePlural:t}});}function u(){r({type:"DeleteEntity",payload:{entityId:s,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[c&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:a,variant:"ghost",children:[jsx(PencilIcon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),l&&!c&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:u,variant:"ghost",children:[jsx(Trash2Icon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),c&&l&&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$2,{onClick:a,children:[jsx(PencilIcon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Edit"]}),jsx(m,{}),jsxs(h$2,{className:"fk:text-destructive",onClick:u,children:[jsx(Trash2Icon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete"]})]})]})]})}function Fi({table:e}){let[t]=e.getState().sorting;if(!t)return null;let o=e.getColumn(t.id)?.columnDef.meta?.label??t.id,r=t.desc?"desc":"asc";return jsxs(b$3,{"aria-label":`Clear sorting by ${o}`,className:"fk:h-8 fk:px-2 fk:lg:px-3 fk:text-success fk:border-none",onClick:()=>{e.resetSorting();},size:"sm",variant:"outline",children:["Sorted by ",o," ",r,jsx(X,{className:"fk:ml-1 fk:h-4 fk:w-4"})]})}function Ii({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:n=>{t.toggleVisibility(!!n);},children:t.id},t.id))]})]})}function Ug({entityName:e,isReloading:t=false,onReload:n,table:o}){let r=ge(),i=d$2(),s=c$2(),l=useApolloClient(),{projects:c,currentProjectId:a}=d(),{schema:u,scopes:f}=find(propEq(a??"","projectId"))(c),[m,p,d$3]=xt(),[g,h]=useState(false),v=Dt(),y=o.getSelectedRowModel().rows.map(N=>N.original._id);function C(){r({type:"AddEntity",payload:{entityName:e}});}function x(N){i({type:"setScope",payload:{projectId:a,scope:N}});}async function A(N){if(N.length===0)return;let S=Un(e,u,N);await new Promise((D,$)=>{p(gql`
392
+ ${S}
393
+ `),d$3({variables:{where:qn(N)},update(O){for(let V of N)O.evict({id:V});},onCompleted:()=>{D();},onError:O=>{$(O);}}),m(true);});}function R(){let N=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${y.length} ${N}${y.length>1?"s":""}`,dialogMessage:y.length>1?`Are you sure you want to delete the selected ${N}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${N}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{h(true);try{let S=[...y];await A(S),o.resetRowSelection(),await Do(l,Ke(e,u),S),toast.success(S.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{h(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[f&&f.length>0?jsxs(a$5,{defaultValue:s.scope,onValueChange:N=>{x(N);},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"))(f)||null)?.label})]}),jsx(e$1,{children:f.map(N=>jsx(g$1,{value:N.name,children:N.label},N.name))})]}):null,jsx(Ii,{table:o}),n?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:g||t,onClick:n,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(Fi,{table:o})]}),y.length>0?jsx(x$1,{disabled:!v,children:jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:g||!v,onClick:R,size:"sm",variant:"destructive",children:[g?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",y.length,")"]})}):null,jsx(x$1,{disabled:!v,children:jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:g||!v,onClick:C,size:"sm",variant:"default",children:"Create"})})]})}export{ci as ALL_FIELDS_GROUP,tn as ALL_FIELDS_GROUP_NAME,eo as DataTable,Bo as DataTableColumnHeader,Fg as DataTableFacetedFilter,Ig as DataTableRowActions,Fi as DataTableSortedBy,Ug as DataTableToolbar,Ii as DataTableViewOptions,mg as FlexkitStudio,gg as ProjectDisabled,hg as SchemaError,Ir as canAccessSpaces,yl as canMutateData,vg as defineConfig,xg as defineEntity,vn as filterAttributesForSpaces,Zu as filterEntitiesForSpaces,Tr as getEntityCreateMutation,Un as getEntityDeleteMutation,qn as getEntityDeleteWhere,jn as getEntityQuery,rt as getEntitySchema,Er as getEntityUpdateMutation,Eu as getSortNotNullWhere,Dt as useCanMutate,ge as useDispatch,xt as useEntityMutation,ro as useEntityQuery,Wt as useGraphQLError,Yn as useGridColumnsDefinition,Ng as usePatchEntityList,Ag as useRefreshEntityList,Gn as useUploadAssets};//# sourceMappingURL=index.js.map
447
394
  //# sourceMappingURL=index.js.map