@flexkit/studio 0.0.24 → 0.0.26

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 (34) hide show
  1. package/dist/asset-HOJ43RVO.js +2 -0
  2. package/dist/{asset-IVSDPVJK.js.map → asset-HOJ43RVO.js.map} +1 -1
  3. package/dist/astro.js +1 -1
  4. package/dist/{chunk-N6WEYKSZ.js → chunk-7XBIC5RC.js} +2 -2
  5. package/dist/{chunk-N6WEYKSZ.js.map → chunk-7XBIC5RC.js.map} +1 -1
  6. package/dist/chunk-AOVXSAH5.js +2 -0
  7. package/dist/chunk-AOVXSAH5.js.map +1 -0
  8. package/dist/{chunk-2ORQKJKI.js → chunk-I4C65MUI.js} +2 -2
  9. package/dist/{chunk-2ORQKJKI.js.map → chunk-I4C65MUI.js.map} +1 -1
  10. package/dist/{chunk-3S65434F.js → chunk-PCZI6VXG.js} +21 -2
  11. package/dist/{chunk-HSPSTCNK.js → chunk-V2UTZEJQ.js} +2 -2
  12. package/dist/{chunk-HSPSTCNK.js.map → chunk-V2UTZEJQ.js.map} +1 -1
  13. package/dist/chunk-ZBV4BY36.js +3 -0
  14. package/dist/chunk-ZBV4BY36.js.map +1 -0
  15. package/dist/index.d.ts +6 -8
  16. package/dist/index.js +172 -171
  17. package/dist/index.js.map +1 -1
  18. package/dist/nextjs.js +1 -1
  19. package/dist/{project-selector-UDFHGEZI.js → project-selector-TWMWLTCH.js} +2 -2
  20. package/dist/{project-selector-UDFHGEZI.js.map → project-selector-TWMWLTCH.js.map} +1 -1
  21. package/dist/{search-NEEMYDKE.js → search-MG2W4GGN.js} +2 -2
  22. package/dist/{search-NEEMYDKE.js.map → search-MG2W4GGN.js.map} +1 -1
  23. package/dist/tanstack-start.js +1 -1
  24. package/dist/{types.d-B-SE1ihC.d.ts → types.d-Da7sP-Fn.d.ts} +9 -4
  25. package/dist/ui.d.ts +1 -1
  26. package/dist/ui.js +1 -1
  27. package/dist/{user-nav-QJ3GVNLW.js → user-nav-E7MLJ36Y.js} +2 -2
  28. package/dist/{user-nav-QJ3GVNLW.js.map → user-nav-E7MLJ36Y.js.map} +1 -1
  29. package/package.json +1 -1
  30. package/dist/asset-IVSDPVJK.js +0 -2
  31. package/dist/chunk-7WR64NTK.js +0 -2
  32. package/dist/chunk-7WR64NTK.js.map +0 -1
  33. package/dist/chunk-CHRDKNUF.js +0 -3
  34. package/dist/chunk-CHRDKNUF.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,37 +1,46 @@
1
- import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}from'./chunk-JHDZP6RC.js';import {a as a$a}from'./chunk-D4XLXU2H.js';import {a as a$b}from'./chunk-HSPSTCNK.js';import {a as a$9}from'./chunk-4KGH7PU7.js';import {a,b as b$7}from'./chunk-7NQ6QCJD.js';import {a as a$c}from'./chunk-SXZZFHMJ.js';import {g as g$3,h as h$2,i as i$1,l,m as m$1,j,n,f as f$3,c as c$7,d as d$3}from'./chunk-RVGMKQPC.js';import {a as a$6}from'./chunk-FPK7J4BP.js';import'./chunk-PEYW7XOU.js';import {a as a$7,b as b$5,c as c$4,e as e$3}from'./chunk-5CKMFBWH.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$1,f as f$1,g as g$1}from'./chunk-7WR64NTK.js';import {d as d$2,c as c$2,b as b$9,a as a$h,e as e$5}from'./chunk-2ORQKJKI.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-2ORQKJKI.js';import {v,b as b$6,m as m$2,o,p,r,t,s,q}from'./chunk-ND3OZVR5.js';import {b as b$a,a as a$i}from'./chunk-N6WEYKSZ.js';export{b as useAuth}from'./chunk-N6WEYKSZ.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$1,m,a as a$g,l as l$1,i as i$2,b as b$c,r as r$1}from'./chunk-YXRNHQPG.js';import {d,a as a$e,b as b$8,e as e$4,c as c$6}from'./chunk-6YHHL4XI.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-6YHHL4XI.js';import {b as b$4,c as c$5,a as a$k}from'./chunk-CHRDKNUF.js';export{b as IMAGES_BASE_URL}from'./chunk-CHRDKNUF.js';import {b as b$3,a as a$8}from'./chunk-EYGOJ2ZN.js';import {a as a$f,b as b$b}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-V7UK6RMM.js';import {b as b$2,a as a$d}from'./chunk-Z5CZVKD4.js';export{b as DefaultValueSwitch}from'./chunk-Z5CZVKD4.js';import'./chunk-6MOUYNN4.js';import {b,c,e,f,h,g,i,a as a$j}from'./chunk-53TUQIKJ.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as rn from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,filter,uniq,omit,pick,toPairs,props}from'ramda';import Bs,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image as Image$1,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,Pencil,Settings2,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Qo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Collapsible,Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import {Drawer}from'vaul';import Qn from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import md from'react-markdown';import {useReactTable,getFacetedUniqueValues,getFacetedRowModel,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function qo(){let[e,t]=useState(false),{theme:o,setTheme:n}=b$c();return useEffect(()=>{t(true);},[]),e?jsxs(c$7,{size:"sm",type:"single",value:o,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{n("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{n("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{n("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function Jo(){let{resolvedTheme:e}=b$c();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var Os=cva("fk:relative fk:grid fk:w-full fk:grid-cols-[0_1fr] fk:items-start fk:gap-y-0.5 fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:text-sm fk:has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] fk:has-[>svg]:gap-x-3 fk:[&>svg]:size-4 fk:[&>svg]:translate-y-0.5 fk:[&>svg]:text-current",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:bg-card fk:text-destructive fk:*:data-[slot=alert-description]:text-destructive/90 fk:[&>svg]:text-current"}},defaultVariants:{variant:"default"}});function re({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(Os({variant:t}),e),...o})}function Te({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$4("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ie({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:col-start-2 fk:grid fk:justify-items-start fk:gap-1 fk:text-sm fk:text-muted-foreground fk:[&_p]:leading-relaxed",e),...t})}var Js=Qo.object({email:Qo.string().email({message:"Please enter a valid email address"})});function Nn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Js),defaultValues:{email:""}}),f=new URL(c$5(e$1).loginOtpSend,a$k),{data:u,error:c$1,isLoading:l}=Bs(r?f.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),d=u&&"error"in u&&u.error.code,m=u&&"token"in u,g$1=u&&"token"in u?u.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let v=new URL(c$5(e$1).loginOtpConfirm,a$k),x="/api/flexkit/set-token";fetch(`${v.href}?email=${s.getValues("email")}&token=${g$1}`).then(A=>{A.status===200&&A.json().then(S=>{fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:S.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,m,e$1,g$1]);function p(){n(false),i$1(true),a(f.href);}return jsx("div",{className:"fk:w-full",children:m?jsx(re,{variant:"success",children:jsxs(ie,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:s.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:dark:text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(p)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[d==="not_exists"&&jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),d==="unknown_error"||c$1?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(re,{variant:"destructive",children:jsxs(ie,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$6,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":l,className:"fk:w-full",type:"submit",disabled:!!l,children:[l?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function di({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(p=>p.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:f}=Bs(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(h=>h.json())),[u,c]=b$a(),l=new Date().getFullYear(),d$2=useLocation(),m=d$2.state?.from?.pathname??d$2.pathname,g=m.includes(o.projectId)?`${location.origin}${m}`:`${location.origin}${b$b(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return f||u||!a?jsx(Jo,{}):c.user?.id?jsx(Navigate,{replace:true,state:{from:d$2},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$j,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:o.projectId,onValueChange:p=>{n(t.find(h=>h.projectId===p)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":o.title,children:o.title})}),jsx(e$1,{children:t.map(p=>jsx(g$1,{value:p.projectId,children:p.title},p.projectId))})]})]}):null,r?jsx(Nn,{projectId:e,setIsEmailLogin:i}):jsxs(Fragment,{children:[jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-sm fk:text-left fk:text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk:flex fk:flex-col fk:space-y-6",children:[a.providers.map(p=>jsx(b$3,{asChild:true,className:`fk:${p.button.color} fk:${p.button.backgroundColor} fk:hover:${p.button.colorHover} fk:hover:${p.button.backgroundColorHover}`,type:"button",variant:p.button.variant,children:jsxs("a",{href:Ws({url:p.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:g}),children:[p.button.iconUrl?jsx("img",{alt:p.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:p.button.iconUrl}):null,p.title]})},p.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",l]})]}),jsx(qo,{})]})})]})}function Ws({projectId:e,url:t,basePath:o,fromPath:n}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${o}`),r.set("projectId",e),r.set("redirect",n),`${t}?${r.toString()}`}var Zs=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Ys={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},Xo=class e extends Error{code;constructor(t,o){super(o??Ys[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,o){return new e(t,o)}};function Pn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Zs.includes(t)}function ui(e){if(Pn(e))return e.code}function ki({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),f=useRef(null),u=useLocation(),{projectId:c}=useParams(),l=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name,d=e.find(m=>u.pathname.includes(`/${c}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(f.current===null)return;let m=new ResizeObserver(()=>{n(f.current?.offsetHeight??0);});return m.observe(f.current),function(){m.disconnect();}},[l]),useEffect(()=>{let m=Math.floor(o/48)-2,g=e.slice(0,m);if(!g.find(h=>h.name===d)){let h=e.find(y=>y.name===d);g.pop(),h&&g.push(h);}let p=e.filter(h=>!g.includes(h));i(g),s(p);},[e,d,o]),l===void 0&&d?jsx(Navigate,{to:`${u.pathname}/${d}`}):jsx(a$7,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:f,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(m=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:m.name,children:m.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:m.title})})]})},m.name))}),a.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:a.map(m=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:m.name,children:m.title})},m.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${c}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(m,{}),jsx(h$1,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var cl={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-UDFHGEZI.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-NEEMYDKE.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-QJ3GVNLW.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-FBS75HI4.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-RZOXKHWE.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-OUJM7E6O.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-IVSDPVJK.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-FIBUDNGR.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-NFRMIYVJ.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-VZJ7XF33.js').then(({DateTime:e})=>({default:e})))};function uo(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=cl[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function yi({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=uo("navbar.logo"),r=uo("navbar.projectSelector"),i=uo("navbar.search"),a=uo("navbar.userNav"),s=t.find(d=>d.projectId===e)??t[0],{basePath:f,schema:u}=s,c=useNavigate();function l(d){startTransition(()=>{c(b$b(f,e,"desk","list",d.entityNamePlural)+`?id=${d.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-[3.5rem] fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:l,projectId:e,schema:u})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function vi({version:e}){let{contributions:t,projects:o}=d(),[n,r]=b$a(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(o);if(!a)throw new Xo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:f}=t,u=d$2(),c=useLocation();return useEffect(()=>{if(s){let l=s.find(m=>m.isDefault)||s[0],d="";typeof localStorage<"u"&&(d=localStorage.getItem(`${a$h}${i}`)??""),u({type:"setScope",payload:{projectId:i,scope:d||l.name}});}},[c]),n?jsx(Jo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(yi,{projectId:i??"",projects:o}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(ki,{apps:f,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(di,{projectId:i??""})}function Ci(e){return e?"cause"in e:false}function At(e){if(!e)return null;if(ServerError.is(e))return e;if(Ci(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function xi(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function St(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Wo(e){if(!e)return null;let t=bl(e);return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(o=>`- ${o}`)].join(`
2
- `)}function bl(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(wi).map(({message:r})=>r);let t=xi(e);if(t&&mo(t))return [t];let o=At(e);if(o?.statusCode!==400)return [];let n=St(o.bodyText)??wl(o)??Cl(e);return n?Array.isArray(n.errors)?n.errors.filter(wi).map(r=>r.message):typeof n.message=="string"&&mo(n.message)?[n.message]:typeof n.error=="string"&&mo(n.error)?[n.error]:[]:[]}function wl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Cl(e){if(!Ci(e))return null;let{cause:t}=e,o=xi(t);if(o&&mo(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function wi(e){if(!e||typeof e!="object")return false;let{extensions:t,message:o}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof o=="string"?true:typeof o=="string"&&mo(o)}function mo(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Ll=ApolloProvider,Ai=createContext(void 0);function Tt(){let e=useContext(Ai);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function _l(e){return new ErrorLink(({error:t})=>{let o=Wo(t);if(o){e(o);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:a})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let n=At(t);if(n?.statusCode===400){let r=St(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:f}=r;if(typeof f=="string")i=f;else if(Array.isArray(s)){let[u]=s;if(u&&typeof u.message=="string"){let{message:c}=u;i=c;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=n.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(n){console.warn(`[Network error]: ${n.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function Ol(e,t){return from([_l(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Vl(e,t){return new ApolloClient({link:Ol(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Si({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(Ai.Provider,{value:r,children:jsx(Ll,{client:Vl(t,n),children:e})})}function Ti({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function In({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Bl({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Di({className:e,size:t="default",...o}){return jsxs(In,{children:[jsx(Bl,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...o})]})}function Ni({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$4("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Pi({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$4("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Ri({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$4("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Fi({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Ii({className:e,variant:t="default",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...n})})}function Mi({className:e,variant:t="outline",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...n})})}function po({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function f(){r(true);try{let u=e.dialogActionSubmit?.();u&&typeof u.then=="function"&&await u;}finally{a(true),o(false),r(false);}}return jsx(Ti,{onOpenChange:s,open:t,children:jsx(In,{children:jsxs(Di,{className:"sm:max-w-[425px]",children:[jsxs(Ni,{children:[jsx(Ri,{children:e.dialogTitle}),jsx(Fi,{children:e.dialogMessage})]}),jsxs(Pi,{children:[jsx(Mi,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Ii,{className:a$8({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:f,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Oi=createContext([]),Vi=createContext(()=>{});function ql(e,t){let o=t.type;switch(t._id||(t._id=Date.now().toString()),o){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(n=>n._id!==t._id);default:throw Error(`Unknown action: ${o}`)}}function Bi({children:e}){let[t,o]=useReducer(ql,[]);return jsx(Oi.Provider,{value:t,children:jsx(Vi.Provider,{value:o,children:e})})}function zi(){return useContext(Oi)}function ae(){return useContext(Vi)}var Gl=["id","string"],Wl=["date","datetime","duration","time"],Zl=`_id
1
+ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}from'./chunk-JHDZP6RC.js';import {a as a$a}from'./chunk-D4XLXU2H.js';import {a as a$b}from'./chunk-V2UTZEJQ.js';import {a as a$9}from'./chunk-4KGH7PU7.js';import {a,b as b$7}from'./chunk-7NQ6QCJD.js';import {a as a$c}from'./chunk-SXZZFHMJ.js';import {g as g$3,h as h$2,i as i$1,l,m as m$1,j,n,f as f$3,c as c$7,d as d$3}from'./chunk-RVGMKQPC.js';import {a as a$6}from'./chunk-FPK7J4BP.js';import'./chunk-PEYW7XOU.js';import {a as a$7,b as b$5,c as c$4,e as e$3}from'./chunk-5CKMFBWH.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$1,f as f$1,g as g$1}from'./chunk-AOVXSAH5.js';import {d as d$2,c as c$2,b as b$9,a as a$h,e as e$5}from'./chunk-I4C65MUI.js';export{c as useAppContext,d as useAppDispatch,e as useSearch}from'./chunk-I4C65MUI.js';import {v,b as b$6,m as m$2,o,p,r,t,s,q}from'./chunk-ND3OZVR5.js';import {b as b$a,a as a$i}from'./chunk-7XBIC5RC.js';export{b as useAuth}from'./chunk-7XBIC5RC.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$1,m,a as a$g,l as l$1,i as i$2,b as b$c,r as r$1}from'./chunk-YXRNHQPG.js';import {d,a as a$e,b as b$8,e as e$4,c as c$6}from'./chunk-6YHHL4XI.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-6YHHL4XI.js';import {b as b$4,c as c$5,a as a$k}from'./chunk-ZBV4BY36.js';export{b as IMAGES_BASE_URL}from'./chunk-ZBV4BY36.js';import {b as b$3,a as a$8}from'./chunk-EYGOJ2ZN.js';import {a as a$f,b as b$b}from'./chunk-WIUPQHZ5.js';import {a as a$3}from'./chunk-V7UK6RMM.js';import {b as b$2,a as a$d}from'./chunk-Z5CZVKD4.js';export{b as DefaultValueSwitch}from'./chunk-Z5CZVKD4.js';import'./chunk-6MOUYNN4.js';import {b,c,e,f,h,g,i,a as a$j}from'./chunk-53TUQIKJ.js';import {a as a$4}from'./chunk-O2QMYUPS.js';import*as rn from'react';import {lazy,createContext,memo,forwardRef,useMemo,useImperativeHandle,useEffect,createElement,useId,useState,useRef,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,uniq,omit,pick,toPairs,props}from'ramda';import qs,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image as Image$1,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,Pencil,Settings2,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Jo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Collapsible,Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import {Drawer}from'vaul';import Wn from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import yd from'react-markdown';import {useReactTable,getFacetedUniqueValues,getFacetedRowModel,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function qo(){let[e,t]=useState(false),{theme:o,setTheme:n}=b$c();return useEffect(()=>{t(true);},[]),e?jsxs(c$7,{size:"sm",type:"single",value:o,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{n("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{n("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{n("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function Uo(){let{resolvedTheme:e}=b$c();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var js=cva("fk:relative fk:grid fk:w-full fk:grid-cols-[0_1fr] fk:items-start fk:gap-y-0.5 fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:text-sm fk:has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] fk:has-[>svg]:gap-x-3 fk:[&>svg]:size-4 fk:[&>svg]:translate-y-0.5 fk:[&>svg]:text-current",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:bg-card fk:text-destructive fk:*:data-[slot=alert-description]:text-destructive/90 fk:[&>svg]:text-current"}},defaultVariants:{variant:"default"}});function ne({className:e,variant:t,...o}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$4(js({variant:t}),e),...o})}function De({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$4("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function re({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$4("fk:col-start-2 fk:grid fk:justify-items-start fk:gap-1 fk:text-sm fk:text-muted-foreground fk:[&_p]:leading-relaxed",e),...t})}var Ws=Jo.object({email:Jo.string().email({message:"Please enter a valid email address"})});function Rn({projectId:e$1,setIsEmailLogin:t}){let[o,n]=useState(false),[r,i$1]=useState(false),{mutate:a}=useSWRConfig(),s=useForm({resolver:zodResolver(Ws),defaultValues:{email:""}}),d=new URL(c$5(e$1).loginOtpSend,a$k),{data:c$1,error:l,isLoading:f}=qs(r?d.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:s.getValues("email")})}).then(y=>y.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),u=c$1&&"error"in c$1&&c$1.error.code,m=c$1&&"token"in c$1,g$1=c$1&&"token"in c$1?c$1.token:"";useEffect(()=>{if(!m)return;let h=0,y=setInterval(()=>{if(h>100){clearInterval(y),n(true);return}let v=new URL(c$5(e$1).loginOtpConfirm,a$k),x="/api/flexkit/set-token";fetch(`${v.href}?email=${s.getValues("email")}&token=${g$1}`).then(E=>{E.status===200&&E.json().then(S=>{fetch(x,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:S.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(y);}},[s,m,e$1,g$1]);function p(){n(false),i$1(true),a(d.href);}return jsx("div",{className:"fk:w-full",children:m?jsx(ne,{variant:"success",children:jsxs(re,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:s.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:dark:text-background",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b,{...s,children:jsxs("form",{onSubmit:h=>{s.handleSubmit(p)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[u==="not_exists"&&jsx(ne,{variant:"destructive",children:jsxs(re,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${s.getValues("email")}`,children:"Sign up?"})]})}),u==="unknown_error"||l?jsx(ne,{variant:"destructive",children:jsxs(re,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"Try again"}),"."," "]})}):null,o?jsx(ne,{variant:"destructive",children:jsxs(re,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:s.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$6,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i,{})]})}),jsxs(b$3,{"aria-disabled":f,className:"fk:w-full",type:"submit",disabled:!!f,children:[f?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function pi({projectId:e}){let{projects:t}=d(),[o,n]=useState(t.find(p=>p.projectId===e)??t[0]),[r,i]=useState(false),{data:a,error:s,isLoading:d$2}=qs(c$5(e).authProviders,p=>fetch(p,{mode:"cors"}).then(h=>h.json())),[c,l]=b$a(),f=new Date().getFullYear(),u=useLocation(),m=u.state?.from?.pathname??u.pathname,g=m.includes(o.projectId)?`${location.origin}${m}`:`${location.origin}${b$b(o.basePath,o.projectId)}`;if(s)throw new Error("Error fetching auth providers");return d$2||c||!a?jsx(Uo,{}):l.user?.id?jsx(Navigate,{replace:true,state:{from:u},to:o.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$j,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:o.projectId,onValueChange:p=>{n(t.find(h=>h.projectId===p)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":o.title,children:o.title})}),jsx(e$1,{children:t.map(p=>jsx(g$1,{value:p.projectId,children:p.title},p.projectId))})]})]}):null,r?jsx(Rn,{projectId:e,setIsEmailLogin:i}):jsxs(Fragment,{children:[jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-sm fk:text-left fk:text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk:flex fk:flex-col fk:space-y-6",children:[a.providers.map(p=>jsx(b$3,{asChild:true,className:`fk:${p.button.color} fk:${p.button.backgroundColor} fk:hover:${p.button.colorHover} fk:hover:${p.button.backgroundColorHover}`,type:"button",variant:p.button.variant,children:jsxs("a",{href:el({url:p.url,projectId:o.projectId,basePath:"/api/flexkit/get-token",fromPath:g}),children:[p.button.iconUrl?jsx("img",{alt:p.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:p.button.iconUrl}):null,p.title]})},p.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",f]})]}),jsx(qo,{})]})})]})}function el({projectId:e,url:t,basePath:o,fromPath:n}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${o}`),r.set("projectId",e),r.set("redirect",n),`${t}?${r.toString()}`}var tl=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],ol={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},Qo=class e extends Error{code;constructor(t,o){super(o??ol[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,o){return new e(t,o)}};function Fn(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:tl.includes(t)}function gi(e){if(Fn(e))return e.code}function vi({apps:e,version:t}){let[o,n]=useState(0),[r,i]=useState(e),[a,s]=useState([]),d=useRef(null),c=useLocation(),{projectId:l}=useParams(),f=e.find(m=>c.pathname.includes(`/${l}/${m.name}`))?.name,u=e.find(m=>c.pathname.includes(`/${l}/${m.name}`))?.name??e[0]?.name;return useEffect(()=>{if(d.current===null)return;let m=new ResizeObserver(()=>{n(d.current?.offsetHeight??0);});return m.observe(d.current),function(){m.disconnect();}},[f]),useEffect(()=>{let m=Math.floor(o/48)-2,g=e.slice(0,m);if(!g.find(h=>h.name===u)){let h=e.find(y=>y.name===u);g.pop(),h&&g.push(h);}let p=e.filter(h=>!g.includes(h));i(g),s(p);},[e,u,o]),f===void 0&&u?jsx(Navigate,{to:`${c.pathname}/${u}`}):jsx(a$7,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:d,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(m=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:m.name,children:m.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:m.title})})]})},m.name))}),a.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:a.map(m=>jsx(h$1,{asChild:true,children:jsx(NavLink,{to:m.name,children:m.title})},m.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${l}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(m,{}),jsx(h$1,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var ml={"navbar.logo":lazy(()=>import('./logo-GCKKZP62.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-TWMWLTCH.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-MG2W4GGN.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-E7MLJ36Y.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-FBS75HI4.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-RZOXKHWE.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-OUJM7E6O.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-HOJ43RVO.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-FIBUDNGR.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-NFRMIYVJ.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-VZJ7XF33.js').then(({DateTime:e})=>({default:e})))};function po(e){let{getContributionPointConfig:t}=d(),[o,...n]=e.split("."),r=ml[e],i=t(o,n);return i?.length>0?i[0]?.component:r}function wi({projectId:e,projects:t}){let{resolvedTheme:o}=b$c(),n=po("navbar.logo"),r=po("navbar.projectSelector"),i=po("navbar.search"),a=po("navbar.userNav"),s=t.find(u=>u.projectId===e)??t[0],{basePath:d,schema:c}=s,l=useNavigate();function f(u){startTransition(()=>{l(b$b(d,e,"desk","list",u.entityNamePlural)+`?id=${u.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-[3.5rem] fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-20",children:[jsx(Suspense,{fallback:null,children:jsx(n,{theme:o,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:f,projectId:e,schema:c})})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(a,{projectId:e})})})]})}function Ci({version:e}){let{contributions:t,projects:o}=d(),[n,r]=b$a(),{projectId:i}=useParams(),a=find(propEq(i??"","projectId"))(o);if(!a)throw new Qo("PROJECT_NOT_FOUND");let{scopes:s}=a,{apps:d$1}=t,c=d$2(),l=useLocation();return useEffect(()=>{if(s){let f=s.find(m=>m.isDefault)||s[0],u="";typeof localStorage<"u"&&(u=localStorage.getItem(`${a$h}${i}`)??""),c({type:"setScope",payload:{projectId:i,scope:u||f.name}});}},[l]),n?jsx(Uo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(wi,{projectId:i??"",projects:o}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(vi,{apps:d$1,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{})]}):jsx(pi,{projectId:i??""})}function Si(e){return e?"cause"in e:false}function Dt(e){if(!e)return null;if(ServerError.is(e))return e;if(Si(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Ai(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Pt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function Go(e){if(!e)return null;let t=El(e);return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(o=>`- ${o}`)].join(`
2
+ `)}function El(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ei).map(({message:r})=>r);let t=Ai(e);if(t&&go(t))return [t];let o=Dt(e);if(o?.statusCode!==400)return [];let n=Pt(o.bodyText)??Sl(o)??Al(e);return n?Array.isArray(n.errors)?n.errors.filter(Ei).map(r=>r.message):typeof n.message=="string"&&go(n.message)?[n.message]:typeof n.error=="string"&&go(n.error)?[n.error]:[]:[]}function Sl(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Al(e){if(!Si(e))return null;let{cause:t}=e,o=Ai(t);if(o&&go(o))return {message:o};if(!t||typeof t!="object")return null;let{result:n}=t;return n&&typeof n=="object"?n:null}function Ei(e){if(!e||typeof e!="object")return false;let{extensions:t,message:o}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof o=="string"?true:typeof o=="string"&&go(o)}function go(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}var Bl=ApolloProvider,Ni=createContext(void 0);function Rt(){let e=useContext(Ni);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function zl(e){return new ErrorLink(({error:t})=>{let o=Go(t);if(o){e(o);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:a})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${a}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let n=Dt(t);if(n?.statusCode===400){let r=Pt(n.bodyText),i=null;if(r&&typeof r=="object"){let{error:a,errors:s,message:d}=r;if(typeof d=="string")i=d;else if(Array.isArray(s)){let[c]=s;if(c&&typeof c.message=="string"){let{message:l}=c;i=l;}}else typeof a=="string"?i=a:i=JSON.stringify(r);}else i=n.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(n){console.warn(`[Network error]: ${n.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function jl(e,t){return from([zl(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function Hl(e,t){return new ApolloClient({link:jl(e??"",t),cache:new InMemoryCache({dataIdFromObject:o=>o._id?o._id:defaultDataIdFromObject(o)})})}function Di({children:e}){let{currentProjectId:t}=d(),[o,n]=useState(null),r=useMemo(()=>({schemaErrorMessage:o,setSchemaErrorMessage:n}),[o]);return jsx(Ni.Provider,{value:r,children:jsx(Bl,{client:Hl(t,n),children:e})})}function Pi({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function Mn({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function ql({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$4("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function Ri({className:e,size:t="default",...o}){return jsxs(Mn,{children:[jsx(ql,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$4("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...o})]})}function Fi({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$4("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Ii({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$4("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function $i({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$4("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Mi({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Li({className:e,variant:t="default",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$4(e),...n})})}function _i({className:e,variant:t="outline",size:o="default",...n}){return jsx(b$3,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$4(e),...n})})}function ko({options:e}){let[t,o]=useState(false),[n,r]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function s(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function d(){r(true);try{let c=e.dialogActionSubmit?.();c&&typeof c.then=="function"&&await c;}finally{a(true),o(false),r(false);}}return jsx(Pi,{onOpenChange:s,open:t,children:jsx(Mn,{children:jsxs(Ri,{className:"sm:max-w-[425px]",children:[jsxs(Fi,{children:[jsx($i,{children:e.dialogTitle}),jsx(Mi,{children:e.dialogMessage})]}),jsxs(Ii,{children:[jsx(_i,{disabled:n,onClick:s,children:e.dialogCancelTitle}),jsxs(Li,{className:a$8({variant:e.isDestructive?"destructive":"default"}),disabled:n,onClick:d,children:[n?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var zi=createContext([]),ji=createContext(()=>{});function Gl(e,t){let o=t.type;switch(t._id||(t._id=Date.now().toString()),o){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(n=>n._id!==t._id);default:throw Error(`Unknown action: ${o}`)}}function Hi({children:e}){let[t,o]=useReducer(Gl,[]);return jsx(zi.Provider,{value:t,children:jsx(ji.Provider,{value:o,children:e})})}function qi(){return useContext(zi)}function ie(){return useContext(ji)}function ue(e){return e.dataType==="asset"?"global":e.scope}var Kl=["id","string"],ec=["date","datetime","duration","time"],tc=`_id
3
3
  originalFilename
4
4
  mimeType
5
5
  path
6
6
  size
7
7
  height
8
8
  width
9
- lqip`;function ho(e){return e?.scope==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset"}function Hi(e,t){return !e||!ho(e)?false:t?.name!==b$8.name||e.name!=="assets"}function $n(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ui(e){return (e?.edges??[]).reduce((o,n,r)=>(n.node&&o.push({...n.node,sortOrder:n.properties?.sortOrder??r}),o),[]).sort((o,n)=>(o.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER))}function qi(e,t=true){let o=t?` properties {
9
+ lqip`;function vo(e){return e?ue(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function Ui(e,t){return !e||!vo(e)?false:t?.name!==b$8.name||e.name!=="assets"}function On(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ji(e){return (e?.edges??[]).reduce((o,n,r)=>(n.node&&o.push({...n.node,sortOrder:n.properties?.sortOrder??r}),o),[]).sort((o,n)=>(o.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER))}function ht(e){return Array.isArray(e)?e[0]??null:e??null}function Qi(e,t=true){let o=t?` properties {
10
10
  sortOrder
11
11
  }
12
- `:"";return ` ${e}Aggregate {
13
- count
14
- }
15
- ${e}Connection {
12
+ `:"";return ` ${e}Connection {
13
+ aggregate {
14
+ count {
15
+ nodes
16
+ }
17
+ }
16
18
  edges {
17
19
  `+o+` node {
18
- ${Zl}
20
+ ${tc}
21
+ }
22
+ }
23
+ }
24
+ `}function _n(e){return e?.aggregate?.count?.nodes??0}function Yo(e,t=""){return ` ${e}Connection${t} {
25
+ aggregate {
26
+ count {
27
+ nodes
19
28
  }
20
29
  }
21
30
  }
22
- `}function Nt(e,t,o){let n="(where: $where, options: $options)",r=Pt(o,e),i=r?.name??e,a=r?.attributes??[],s=`$where: ${i}Where, $options: ${i}Options`,f=`Get${Ht(e)}`;if(!r)throw new Error(`Entity '${i}' not found in the schema`);if(a.length===0)throw new Error(`Entity '${i}' has no attributes defined in the schema`);let u=oe("global",a).join(`
23
- `),c=en(a),l=oe(["local"],a),d=l.reduce((v,x)=>`${v}
31
+ `}function It(e,t,o){let n="(where: $where, limit: $limit, offset: $offset, sort: $sort)",r=$t(o,e),i=r?.name??e,a=r?.attributes??[],s=`$where: ${i}Where, $limit: Int, $offset: Int, $sort: [${i}Sort!]`,d=`Get${Qt(e)}`;if(!r)throw new Error(`Entity '${i}' not found in the schema`);if(a.length===0)throw new Error(`Entity '${i}' has no attributes defined in the schema`);let c=oe("global",a).join(`
32
+ `),l=en(a),f=oe(["local"],a),u=f.reduce((v,x)=>`${v}
24
33
  ${x} {
25
34
  _id
26
35
  default
27
36
  }
28
- `,""),m=l.reduce((v,x)=>`${v}
37
+ `,""),m=f.reduce((v,x)=>`${v}
29
38
  ${x} {
30
39
  _id
31
40
  default
32
41
  ${t}
33
42
  }
34
- `,""),g=t==="default"?d:m,p=c.reduce((v,x)=>`${v}
43
+ `,""),g=t==="default"?u:m,p=l.reduce((v,x)=>`${v}
35
44
  ${x} {
36
45
  _id
37
46
  originalFilename
@@ -42,10 +51,10 @@ import'./index.css';import {a as a$2}from'./chunk-OXTER7HO.js';import {a as a$1}
42
51
  width
43
52
  lqip
44
53
  }
45
- `,""),y=filter(propEq("relationship","scope"))(a).reduce((v,x)=>{if(ho(x))return `${v}
46
- ${qi(x.name,Hi(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.attributes.reduce((b,E)=>{let D=t==="default"?"":`${t}
47
- `;if($n(E))return `${b}
48
- ${E.name} {
54
+ `,""),y=a.filter(v=>ue(v)==="relationship").reduce((v,x)=>{if(vo(x))return `${v}
55
+ ${Qi(x.name,Ui(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.attributes.reduce((b,A)=>{let N=t==="default"?"":`${t}
56
+ `;if(On(A))return `${b}
57
+ ${A.name} {
49
58
  _id
50
59
  originalFilename
51
60
  mimeType
@@ -55,40 +64,35 @@ ${qi(x.name,Hi(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
55
64
  width
56
65
  lqip
57
66
  }
58
- `;if(E.scope==="local")return `${b}
59
- ${E.name} {
67
+ `;if(ue(A)==="local")return `${b}
68
+ ${A.name} {
60
69
  _id
61
70
  default
62
- ${D}
71
+ ${N}
63
72
  }
64
- `;if(E.scope==="relationship"){let B=find(propEq(E.relationship?.entity,"name"))(o),F=find(propEq(E.relationship?.field,"name"))(B?.attributes??[]).scope==="local"?`{
73
+ `;if(ue(A)==="relationship"){let _=find(propEq(A.relationship?.entity,"name"))(o),B=find(propEq(A.relationship?.field,"name"))(_?.attributes??[]),I=ue(B)==="local"?`{
65
74
  _id
66
75
  default
67
- ${D}}
68
- `:"";if(E.relationship?.mode==="single")return `${b}
69
- ${E.name} {
70
- ${E.relationship.field} ${F}}
71
- `;if(E.relationship?.field)return `${b}
72
- ${E.name} (options: {limit: 25, offset: 0}) {
73
- ${E.relationship.field} ${F}}
76
+ ${N}}
77
+ `:"";if(A.relationship?.mode==="single")return `${b}
78
+ ${A.name} {
79
+ ${A.relationship.field} ${I}}
80
+ `;if(A.relationship?.field)return `${b}
81
+ ${A.name} (limit: 25, offset: 0) {
82
+ ${A.relationship.field} ${I}}
74
83
  `}return `${b}
75
- ${E.name}
76
- `},"");return `${x.name}Aggregate {
77
- count
78
- }${v}
79
- ${x.name} (options: {limit: 25, offset: 0}) { _id ${S??""}}
80
- `},"");return {queryEntityName:e,query:`query ${f}(${s}) {
81
- ${e}Aggregate {
82
- count
83
- }
84
- ${e}${n} {
84
+ ${A.name}
85
+ `},"");return `${Yo(x.name).trim()}${v}
86
+ ${x.name} (limit: 25, offset: 0) { _id ${S??""}}
87
+ `},"");return {queryEntityName:e,query:`query ${d}(${s}) {
88
+ `+Yo(e)+` ${e}${n} {
85
89
  _id
86
- ${u} ${g} ${p} ${y}}
90
+ ${c} ${g} ${p} ${y}}
87
91
  }
88
- `}}function Ko(e,t,o,n){let i=Pt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],s=o[e],f=(c,l)=>{let d=l.name;return c.slice(0,3).map(m=>l.scope==="local"?m[d]?.[t]??m[d].default:m[d]).join(", ")},u=s.map(c=>{let{_id:l}=c,d=oe("global",i).reduce((h,y)=>({...h,[y]:c[y]}),{}),m=oe("local",i).reduce((h,y)=>{let v=c[y];return {...h,[y]:v?.[t]?v[t]:v?.default}},{}),g=en(i).reduce((h,y)=>({...h,[y]:c[y]}),{}),p=oe(["relationship"],i).reduce((h,y)=>{let v=find(propEq(y,"name"))(i),x=v.relationship?.entity??"",A=find(propEq(x,"name"))(n),S=cc(A?.attributes??[]),b=S?.name??"",E=S?.scope??"global",D=c[y];if(ho(v)){let z=Ui(c[`${y}Connection`]);return {...h,[y]:z}}if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);if(Array.isArray(D))return {...h,[y]:f(D,S)};let B=E==="global"?D?.[b]:D?.[b]?.[t]??D?.[b]?.default;return {...h,[y]:B}},{});return {_id:l,...d,...m,...g,...p}});return {count:a,results:u}}function Ji(e,t,o,n){let i=Pt(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let{count:a}=o[`${e}Aggregate`],f=o[e].map(u=>{let c=oe("global",i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),l=oe("local",i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p];return {...g,[p]:{value:y?Yl(y,t):null,disabled:!!(y&&y[t]===null&&h.scope==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),d=en(i).reduce((g,p)=>({...g,[p]:{value:u[p],disabled:false,scope:"default",_id:""}}),{}),m=oe(["relationship"],i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=u[p],v=y?._id,x=u[`${p}Aggregate`].count,A=ho(h)?Ui(u[`${p}Connection`]):y;return {...g,[p]:{count:x,_id:v,value:A,disabled:false,scope:t}}},{});return {...c,...l,...d,...m}});return {count:a,results:f}}function Yl(e,t){return Array.isArray(e)?e.reduce((o,n)=>{if(n[t]??n.default){let r={_id:n._id,disabled:n.scope===null&&t!=="default",scope:t,value:n[t]??n.default};o.push(r);}return o},[]):e[t]??e.default??null}function Ln(e,t,o,n,r,i){let a=Pt(n,e),s=a?.name??e,f=a?.attributes??[],u=vo(e);if(f.length===0)return "";let c=_n(f,i),l=On(f,c),d=ec(t,f,c,o),m=Kl(t,f,c),g=tc(f,r,c),p=e,h=Bn(n,e,o);return `mutation ${`Update${Ht(e)}`}($where: ${s}Where) {
89
- update${u}(
92
+ `}}function Ko(e,t,o,n){let i=$t(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=_n(o[`${e}Connection`]),s=o[e],d=(l,f)=>{let u=f.name;return l.slice(0,3).map(m=>{if(ue(f)!=="local")return m[u];let g=ht(m[u]);return g?.[t]??g?.default}).join(", ")},c=s.map(l=>{let{_id:f}=l,u=oe("global",i).reduce((h,y)=>({...h,[y]:l[y]}),{}),m=oe("local",i).reduce((h,y)=>{let v=ht(l[y]);return {...h,[y]:v?.[t]?v[t]:v?.default}},{}),g=en(i).reduce((h,y)=>({...h,[y]:ht(l[y])}),{}),p=oe(["relationship"],i).reduce((h,y)=>{let v=find(propEq(y,"name"))(i),x=v.relationship?.entity??"",E=find(propEq(x,"name"))(n),S=pc(E?.attributes??[]),b=S?.name??"",A=S?ue(S):"global",N=l[y];if(vo(v)){let I=Ji(l[`${y}Connection`]);return {...h,[y]:I}}if(!b)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);if(v.relationship?.mode==="multiple"){let I=Array.isArray(N)?N:[];return {...h,[y]:d(I,S)}}let _=ht(N);if(A==="global")return {...h,[y]:_?.[b]};let B=ht(_?.[b]);return {...h,[y]:B?.[t]??B?.default}},{});return {_id:f,...u,...m,...g,...p}});return {count:a,results:c}}function Xi(e,t,o,n){let i=$t(n,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let a=_n(o[`${e}Connection`]),d=o[e].map(c=>{let l=oe("global",i).reduce((g,p)=>({...g,[p]:{value:c[p],disabled:false,scope:"default",_id:""}}),{}),f=oe("local",i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=ht(c[p]);return {...g,[p]:{value:y?oc(y,t):null,disabled:!!(y&&y[t]===null&&ue(h)==="local"&&t!=="default"),scope:t,_id:y?y._id:null}}},{}),u=en(i).reduce((g,p)=>({...g,[p]:{value:ht(c[p]),disabled:false,scope:"default",_id:""}}),{}),m=oe(["relationship"],i).reduce((g,p)=>{let h=find(propEq(p,"name"))(i),y=c[p],v=h.relationship?.mode==="single"?ht(y):y,x=v?._id,E=_n(c[`${p}Connection`]),S=vo(h)?Ji(c[`${p}Connection`]):v;return {...g,[p]:{count:E,_id:x,value:S,disabled:false,scope:t}}},{});return {...l,...f,...u,...m}});return {count:a,results:d}}function oc(e,t){return Array.isArray(e)?e.reduce((o,n)=>{if(n[t]??n.default){let r={_id:n._id,disabled:n.scope===null&&t!=="default",scope:t,value:n[t]??n.default};o.push(r);}return o},[]):e[t]??e.default??null}function Vn(e,t,o,n,r,i){let a=$t(n,e),s=a?.name??e,d=a?.attributes??[],c=wo(e);if(d.length===0)return "";let l=Bn(d,i),f=zn(d,l),u=rc(t,d,l,o),m=nc(t,d,l),g=ic(d,r,l),p=e,h=Hn(n,e,o);return `mutation ${`Update${Qt(e)}`}($where: ${s}Where) {
93
+ update${c}(
90
94
  where: $where
91
- update: {${l}${d}${m}${g}
95
+ update: {${f}${u}${m}${g}
92
96
  }
93
97
  ) {
94
98
  ${p} {
@@ -96,118 +100,125 @@ ${qi(x.name,Hi(x,r))}`;let S=find(propEq(x.relationship?.entity,"name"))(o)?.att
96
100
  ${h} }
97
101
  }
98
102
  }
99
- `}function _n(e,t){let o=e.map(r=>r.isEditable===false?r.name:"").filter(Boolean),n=omit(o,t);return pick(e.map(r=>r.name),n)}function oe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(oe(r,t)),[]):t.filter(n=>n.scope===e&&n.inputType!=="asset").map(n=>n.name)}function en(e){return e.filter($n).map(o=>o.name)}function On(e,t){let o=pick(oe("global",e),t);return toPairs(o).reduce((r,[i,a])=>{let s=find(propEq(i,"name"))(e),f=Array.isArray(a?.value)?null:a?.value??null,u=Vn(s.dataType,f);return `${r}
100
- ${i}: ${u}`},"")}function Kl(e,t,o){let n=pick(en(t),o);return toPairs(n).reduce((a,[s,f])=>{let u=f.value,c=Yo(u?.path),l=u?.size?u.size:"null",d=Yo(u?.mimeType),m=Yo(u?.originalFilename),g=u?.height?u.height:"null",p=u?.width?u.width:"null",h=Yo(u?.lqip);return c?f.value?._id?`${a}
101
- ${s}: {
103
+ `}function Bn(e,t){let o=e.map(r=>r.isEditable===false?r.name:"").filter(Boolean),n=omit(o,t);return pick(e.map(r=>r.name),n)}function oe(e,t){return Array.isArray(e)?e.reduce((n,r)=>n.concat(oe(r,t)),[]):t.filter(n=>ue(n)===e&&n.inputType!=="asset").map(n=>n.name)}function en(e){return e.filter(On).map(o=>o.name)}function zn(e,t,o="update"){let n=pick(oe("global",e),t);return toPairs(n).reduce((i,[a,s])=>{let d=find(propEq(a,"name"))(e),c=Array.isArray(s?.value)?null:s?.value??null,l=jn(d.dataType,c);return o==="update"?`${i}
104
+ ${a}: { set: ${l} }`:`${i}
105
+ ${a}: ${l}`},"")}function nc(e,t,o){let n=pick(en(t),o);return toPairs(n).reduce((a,[s,d])=>{let c=d.value,l=Zo(c?.path),f=c?.size?c.size:"null",u=Zo(c?.mimeType),m=Zo(c?.originalFilename),g=c?.height?c.height:"null",p=c?.width?c.width:"null",h=Zo(c?.lqip);return l?d.value?._id?`${a}
106
+ ${s}: [{
102
107
  update: {
103
108
  node: {
104
- mimeType: ${d}
105
- originalFilename: ${m}
106
- path: ${c}
107
- size: ${l}
108
- height: ${g}
109
- width: ${p}
110
- lqip: ${h}
109
+ mimeType: { set: ${u} }
110
+ originalFilename: { set: ${m} }
111
+ path: { set: ${l} }
112
+ size: { set: ${f} }
113
+ height: { set: ${g} }
114
+ width: { set: ${p} }
115
+ lqip: { set: ${h} }
111
116
  }
112
117
  }
113
- }`:`${a}
114
- ${s}: {
118
+ }]`:`${a}
119
+ ${s}: [{
115
120
  create: {
116
121
  node: {
117
- _id: ${ke(`${e}:${s}`)}
118
- mimeType: ${d}
122
+ _id: ${me(`${e}:${s}`)}
123
+ mimeType: ${u}
119
124
  originalFilename: ${m}
120
- path: ${c}
121
- size: ${l}
125
+ path: ${l}
126
+ size: ${f}
122
127
  height: ${g}
123
128
  width: ${p}
124
129
  lqip: ${h}
125
130
  }
126
131
  }
127
- }`:a},"")}function ec(e,t,o,n){let r=pick(oe("local",t),o);return toPairs(r).reduce((s,[f,u])=>{let c=find(propEq(f,"name"))(t),{dataType:l}=c,d=u.disabled||Array.isArray(u.value)?"null":Vn(l,u.value);return u._id?`${s}
128
- ${f}: {
132
+ }]`:a},"")}function rc(e,t,o,n){let r=pick(oe("local",t),o);return toPairs(r).reduce((s,[d,c])=>{let l=find(propEq(d,"name"))(t),{dataType:f}=l,u=c.disabled||Array.isArray(c.value)?"null":jn(f,c.value);return c._id?`${s}
133
+ ${d}: [{
129
134
  update: {
130
135
  node: {
131
- ${n}: ${d}
136
+ ${n}: { set: ${u} }
132
137
  }
133
138
  }
134
- }`:d?`${s}
135
- ${f}: {
139
+ }]`:u?`${s}
140
+ ${d}: [{
136
141
  create: {
137
142
  node: {
138
- _id: ${ke(`${e}:${f}`)}
139
- _type: "${l}"
140
- ${n}: ${d}
143
+ _id: ${me(`${e}:${d}`)}
144
+ _type: "${f}"
145
+ ${n}: ${u}
141
146
  }
142
147
  }
143
- }`:s},"")}function tc(e,t,o){let n=pick(oe("relationship",e),o);return toPairs(n).reduce((a,[s,f])=>{let u=find(propEq(s,"name"))(e),{inputType:c,relationship:l}=u;if(c==="relationship"&&l?.mode==="single"){let d=t[s]._id??"",m=f._id??"";if(d===m)return a;let g=d?`disconnect: {
144
- where: {
145
- node: {
146
- _id: ${ke(d)}
148
+ }]`:s},"")}function ic(e,t,o){let n=pick(oe("relationship",e),o);return toPairs(n).reduce((a,[s,d])=>{let c=find(propEq(s,"name"))(e),{inputType:l,relationship:f}=c;if(l==="relationship"&&f?.mode==="single"){let u=t[s]._id??"",m=d._id??"";if(u===m)return a;let g=u?` {
149
+ disconnect: [{
150
+ where: {
151
+ node: {
152
+ _id: { eq: ${me(u)} }
153
+ }
147
154
  }
148
- }
155
+ }]
149
156
  }
150
- `:"",p=m?`connect: {
151
- where: {
152
- node: {
153
- _id: ${ke(m)}
157
+ `:"",p=m?` {
158
+ connect: [{
159
+ where: {
160
+ node: {
161
+ _id: { eq: ${me(m)} }
162
+ }
154
163
  }
155
- }
164
+ }]
156
165
  }
157
166
  `:"";return `${a}
158
- ${s}: {
159
- ${p} ${g} }`}if(c==="relationship"&&l?.mode==="multiple"){if(l.entity==="_asset")return `${a}${oc(s,t[s],f)}`;let d=f.relationships?.disconnect?.reduce((y,v)=>`${y} {
167
+ ${s}: [
168
+ ${g}${p} ]`}if(l==="relationship"&&f?.mode==="multiple"){if(f.entity==="_asset")return `${a}${ac(s,t[s],d)}`;let u=d.relationships?.disconnect?.reduce((y,v)=>`${y} {
160
169
  node: {
161
- _id: ${ke(v)}
170
+ _id: { eq: ${me(v)} }
162
171
  }
163
172
  }
164
- `,""),g=(f.relationships?.connect??[]).reduce((y,v)=>`${y} {
165
- _id: ${ke(v._id)}
166
- }
167
- `,""),p=d?`disconnect: {
173
+ `,""),g=(d.relationships?.connect??[]).map(y=>me(y._id)).join(", "),p=u?`disconnect: {
168
174
  where: {
169
175
  OR: [
170
- ${d} ]
176
+ ${u} ]
171
177
  }
172
178
  }
173
179
  `:"",h=g?`connect: {
174
180
  where: {
175
181
  node: {
176
- OR: [
177
- ${g} ]
182
+ _id: { in: [${g}] }
178
183
  }
179
184
  }
180
185
  }
181
186
  `:"";return !p&&!h?a:`${a}
182
187
  ${s}: {
183
188
  ${p} ${h} }`}return `${a}
184
- `},"")}function oc(e,t,o){let r=(o.relationships?.connect??[]).map((l,d)=>({...l,sortOrder:l.sortOrder??d})),i=r.map(l=>l._id),a=nc(t),s=uniq(o.relationships?.disconnect??[]).filter(l=>l&&!i.includes(l)),f=r.filter(l=>{let d=a[l._id];return d===void 0||d!==l.sortOrder}),u=rc(s),c=ic(f);return !u&&!c?"":`
189
+ `},"")}function ac(e,t,o){let r=(o.relationships?.connect??[]).map((m,g)=>({...m,sortOrder:m.sortOrder??g})),i=r.map(m=>m._id),a=sc(t),s=uniq(o.relationships?.disconnect??[]).filter(m=>m&&!i.includes(m)),d=r.filter(m=>a[m._id]===void 0),c=r.filter(m=>{let g=a[m._id];return g!==void 0&&g!==m.sortOrder}),l=lc(s),f=cc(d),u=fc(c);return !l&&!f&&!u?"":`
185
190
  ${e}: [
186
- ${u}${c} ]`}function nc(e){let t=e?.value;return Array.isArray(t)?t.reduce((o,n,r)=>{if(typeof n!="object"||!n||!("_id"in n))return o;let{_id:i}=n;if(typeof i!="string"||i.length===0)return o;let a="sortOrder"in n&&typeof n.sortOrder=="number"?n.sortOrder:r;return {...o,[i]:a}},{}):{}}function rc(e){return e.length===0?"":` {
191
+ ${l}${f}${u} ]`}function sc(e){let t=e?.value;return Array.isArray(t)?t.reduce((o,n,r)=>{if(typeof n!="object"||!n||!("_id"in n))return o;let{_id:i}=n;if(typeof i!="string"||i.length===0)return o;let a="sortOrder"in n&&typeof n.sortOrder=="number"?n.sortOrder:r;return {...o,[i]:a}},{}):{}}function lc(e){return e.length===0?"":` {
187
192
  disconnect: [
188
193
  ${e.reduce((o,n)=>`${o} {
189
- where: { node: { _id: ${ke(n)} } }
194
+ where: { node: { _id: { eq: ${me(n)} } } }
190
195
  }
191
196
  `,"")} ]
192
197
  }
193
- `}function ic(e){return e.length===0?"":` {
198
+ `}function cc(e){return e.length===0?"":` {
194
199
  connect: [
195
- ${Qi(e)} ]
200
+ ${Gi(e)} ]
196
201
  }
197
- `}function Qi(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
198
- where: { node: { _id: ${ke(o._id)} } }
202
+ `}function Gi(e){return e.reduce((t,o,n)=>{let r=o.sortOrder??n;return `${t} {
203
+ where: { node: { _id: { eq: ${me(o._id)} } } }
199
204
  edge: { sortOrder: ${r} }
200
205
  }
201
- `},"")}function Vn(e,t){return Wl.includes(e)?t?.toString()?ke(t.toString()):null:Gl.includes(e)?ke(t?.toString()??"null"):t?.toString()??null}function Yo(e){return e?ke(e):"null"}function ke(e){return JSON.stringify(e)}function Bn(e,t,o){let n=Pt(e,t),r=n?.attributes??[],i=oe("global",r),a=oe("local",r),s=oe("relationship",r),f=i.reduce((u,c)=>`${u}${c}
202
- `,"");return f+=a.reduce((u,c)=>`${u} ${c} {
206
+ `},"")}function fc(e){return e.length===0?"":e.reduce((o,n,r)=>{let i=n.sortOrder??r;return `${o} {
207
+ update: {
208
+ where: { node: { _id: { eq: ${me(n._id)} } } }
209
+ edge: { sortOrder: { set: ${i} } }
210
+ }
211
+ }
212
+ `},"")}function jn(e,t){return ec.includes(e)?t?.toString()?me(t.toString()):null:Kl.includes(e)?me(t?.toString()??"null"):t?.toString()??null}function Zo(e){return e?me(e):"null"}function me(e){return JSON.stringify(e)}function Hn(e,t,o){let n=$t(e,t),r=n?.attributes??[],i=oe("global",r),a=oe("local",r),s=oe("relationship",r),d=i.reduce((c,l)=>`${c}${l}
213
+ `,"");return d+=a.reduce((c,l)=>`${c} ${l} {
203
214
  _id
204
215
  ${o}
205
216
  }
206
- `,""),f+=s.reduce((u,c)=>{let l=find(propEq(c,"name"))(r),d=l?.relationship?.mode??"single";if(ho(l))return `${u}${qi(c,Hi(l,n))}`;let m=l?.relationship?.entity??"",p=find(propEq(m,"name"))(e)?.attributes??[],h=l?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(h,"name"))(p).scope,x="";if(d==="single"&&(v==="global"&&(x=` ${c} {
217
+ `,""),d+=s.reduce((c,l)=>{let f=find(propEq(l,"name"))(r),u=f?.relationship?.mode??"single";if(vo(f))return `${c}${Qi(l,Ui(f,n))}`;let m=f?.relationship?.entity??"",p=find(propEq(m,"name"))(e)?.attributes??[],h=f?.relationship?.field??"[invalid_relationship_field_name_in_schema]",y=find(propEq(h,"name"))(p),v=ue(y),x="";if(u==="single"&&(v==="global"&&(x=` ${l} {
207
218
  _id
208
219
  ${h}
209
220
  }
210
- `),v==="local"&&(x=` ${c} {
221
+ `),v==="local"&&(x=` ${l} {
211
222
  _id
212
223
  ${h} {
213
224
  _id
@@ -215,21 +226,21 @@ ${Qi(e)} ]
215
226
  ${o}
216
227
  }
217
228
  }
218
- `)),d==="multiple"&&p.length){let A=p.reduce((S,b)=>{if(b.scope==="local")return `${S} ${b.name} {
229
+ `)),u==="multiple"&&p.length){let E=p.reduce((S,b)=>{if(ue(b)==="local")return `${S} ${b.name} {
219
230
  _id
220
231
  default
221
232
  ${o}
222
233
  }
223
- `;if(b.scope==="relationship"){let E=o==="default"?"":`${o}
224
- `,D=find(propEq(b.relationship?.entity,"name"))(e),z=find(propEq(b.relationship?.field,"name"))(D?.attributes??[]).scope==="local"?`{
234
+ `;if(ue(b)==="relationship"){let A=o==="default"?"":`${o}
235
+ `,N=find(propEq(b.relationship?.entity,"name"))(e),_=find(propEq(b.relationship?.field,"name"))(N?.attributes??[]),B=ue(_)==="local"?`{
225
236
  _id
226
237
  default
227
- ${E}}
238
+ ${A}}
228
239
  `:"";if(b.relationship?.mode==="single")return `${S} ${b.name} {
229
- ${b.relationship.field} ${z}}
230
- `;if(b.relationship?.field)return `${S} ${b.name} (options: {limit: 25, offset: 0}) {
231
- ${b.relationship.field} ${z}}
232
- `}return $n(b)?`${S} ${b.name} {
240
+ ${b.relationship.field} ${B}}
241
+ `;if(b.relationship?.field)return `${S} ${b.name} (limit: 25, offset: 0) {
242
+ ${b.relationship.field} ${B}}
243
+ `}return On(b)?`${S} ${b.name} {
233
244
  _id
234
245
  originalFilename
235
246
  mimeType
@@ -240,12 +251,9 @@ ${Qi(e)} ]
240
251
  lqip
241
252
  }
242
253
  `:`${S} ${b.name}
243
- `},"");x=` ${c}Aggregate {
244
- count
245
- }
246
- ${c} (options: {limit: 25, offset: 0}) {
247
- ${A} }
248
- `;}return `${u}${x}`},""),f}function yo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=vo(n?.plural??""),a=ac(r,o),s=`Delete${Ht(n?.plural??e)}`;return e==="_asset"?`mutation ${s}($where: ${e}Where) {
254
+ `},"");x=Yo(l)+` ${l} (limit: 25, offset: 0) {
255
+ ${E} }
256
+ `;}return `${c}${x}`},""),d}function bo(e,t,o){let n=find(propEq(e,"name"))(t),r=n?.attributes??[],i=wo(n?.plural??""),a=dc(r,o),s=`Delete${Qt(n?.plural??e)}`;return e==="_asset"?`mutation ${s}($where: ${e}Where) {
249
257
  delete_assets(
250
258
  where: $where
251
259
  ) {
@@ -264,133 +272,126 @@ ${a?` delete: {
264
272
  relationshipsDeleted
265
273
  }
266
274
  }
267
- `}function ac(e,t){return oe("local",e).reduce((r,i)=>`${r}
268
- ${i}: {
275
+ `}function dc(e,t){return oe("local",e).reduce((r,i)=>`${r}
276
+ ${i}: [{
269
277
  where: {
270
278
  node: {
271
- _id: ${ke(`${t}:${i}`)}
279
+ _id: { eq: ${me(`${t}:${i}`)} }
272
280
  }
273
281
  }
274
- }`,"")}function zn(e,t,o,n){let r=Pt(t,e),i=r?.attributes??[],a=vo(r?.plural??"");if(i.length===0)return "";let s=_n(i,o),f=On(i,s),u=sc(i,s,"default",n),c=lc(i,s),l=e,d=Bn(t,l,"default");return `mutation ${`Create${Ht(e)}`} {
282
+ }]`,"")}function qn(e,t,o,n){let r=$t(t,e),i=r?.attributes??[],a=wo(r?.plural??"");if(i.length===0)return "";let s=Bn(i,o),d=zn(i,s,"create"),c=uc(i,s,"default",n),l=mc(i,s),f=e,u=Hn(t,f,"default");return `mutation ${`Create${Qt(e)}`} {
275
283
  create${a}(
276
284
  input: [{
277
- _id: ${ke(n)} ${f} ${u}
278
- ${c}
285
+ _id: ${me(n)} ${d} ${c}
286
+ ${l}
279
287
  }]
280
288
  ) {
281
- ${l} {
289
+ ${f} {
282
290
  _id
283
- ${d} }
291
+ ${u} }
284
292
  }
285
293
  }
286
- `}function sc(e,t,o,n){let r=pick(oe("local",e),t);return toPairs(r).reduce((s,[f,u])=>{if(!u?.value)return s;let c=find(propEq(f,"name"))(e),l=Array.isArray(u.value)?"null":Vn(c.dataType,u.value);return `${s}
287
- ${f}: {
288
- create: {
294
+ `}function uc(e,t,o,n){let r=pick(oe("local",e),t);return toPairs(r).reduce((s,[d,c])=>{if(!c?.value)return s;let l=find(propEq(d,"name"))(e),f=Array.isArray(c.value)?"null":jn(l.dataType,c.value);return `${s}
295
+ ${d}: {
296
+ create: [{
289
297
  node: {
290
- _id: ${ke(`${n}:${f}`)}
291
- _type: "${c.dataType}"
292
- ${o}: ${l}
298
+ _id: ${me(`${n}:${d}`)}
299
+ _type: "${l.dataType}"
300
+ ${o}: ${f}
293
301
  }
294
- }
295
- }`},"")}function lc(e,t){let o=pick(oe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let f=find(propEq(a,"name"))(e),{inputType:u,relationship:c}=f;if(u==="relationship"&&c?.mode==="single"){let m=`connect: {
302
+ }]
303
+ }`},"")}function mc(e,t){let o=pick(oe("relationship",e),t);return toPairs(o).reduce((i,[a,s])=>{let d=find(propEq(a,"name"))(e),{inputType:c,relationship:l}=d;if(c==="relationship"&&l?.mode==="single"){let m=`connect: [{
296
304
  where: {
297
305
  node: {
298
- _id: ${ke(s._id??"")}
306
+ _id: { eq: ${me(s._id??"")} }
299
307
  }
300
308
  }
301
- }
309
+ }]
302
310
  `;return `${i}
303
311
  ${a}: {
304
- ${m} }`}let l=u==="relationship"&&c?.mode==="multiple",d=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(l&&d){let m=s.relationships?.connect??[];if(c?.entity==="_asset"){let h=Qi(m.map((y,v)=>({...y,sortOrder:y.sortOrder??v})));return `${i}
312
+ ${m} }`}let f=c==="relationship"&&l?.mode==="multiple",u=Array.isArray(s.relationships?.connect)&&s.relationships.connect.length>0;if(f&&u){let m=s.relationships?.connect??[];if(l?.entity==="_asset"){let h=Gi(m.map((y,v)=>({...y,sortOrder:y.sortOrder??v})));return `${i}
305
313
  ${a}: {
306
314
  connect: [
307
315
  ${h} ]
308
- }`}let g=m.reduce((h,y)=>`${h} {
309
- _id: ${ke(y._id)}
310
- }
311
- `,""),p=g?`connect: {
316
+ }`}let g=m.map(h=>me(h._id)).join(", "),p=g?`connect: {
312
317
  where: {
313
318
  node: {
314
- OR: [
315
- ${g} ]
319
+ _id: { in: [${g}] }
316
320
  }
317
321
  }
318
322
  }
319
323
  `:"";return `${i}
320
324
  ${a}: {
321
325
  ${p} }`}return `${i}
322
- `},"")}function cc(e){return e.find(t=>t.isPrimary)??e[0]}function Xi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, options: $options)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $options: ${t}Options`,f=i?.plural??"",u=`GetRelated${Ht(f||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let c=oe("global",a).join(`
323
- `),l=oe(["local"],a),d=l.reduce((y,v)=>`${y}
326
+ `},"")}function pc(e){return e.find(t=>t.isPrimary)??e[0]}function Wi({attributeName:e,relatedEntityName:t,scope:o,schema:n}){let r="(where: $where, limit: $limit, offset: $offset, sort: $sort)",i=find(propEq(t,"name"))(n),a=i?.attributes??[],s=`$where: ${t}Where, $limit: Int, $offset: Int, $sort: [${t}Sort!]`,d=i?.plural??"",c=`GetRelated${Qt(d||t)}`;if(a.length===0)return {queryEntityName:"",query:""};let l=oe("global",a).join(`
327
+ `),f=oe(["local"],a),u=f.reduce((y,v)=>`${y}
324
328
  ${v} {
325
329
  _id
326
330
  default
327
331
  }
328
- `,""),m=l.reduce((y,v)=>`${y}
332
+ `,""),m=f.reduce((y,v)=>`${y}
329
333
  ${v} {
330
334
  _id
331
335
  default
332
336
  ${o}
333
337
  }
334
- `,""),g=o==="default"?d:m,h=filter(propEq("relationship","scope"))(a).reduce((y,v)=>{let A=find(propEq(v.relationship?.entity,"name"))(n)?.attributes.reduce((S,b)=>{let E=o==="default"?"":`${o}
335
- `;if(b.scope==="local")return `${S}
338
+ `,""),g=o==="default"?u:m,h=a.filter(y=>ue(y)==="relationship").reduce((y,v)=>{let E=find(propEq(v.relationship?.entity,"name"))(n)?.attributes.reduce((S,b)=>{let A=o==="default"?"":`${o}
339
+ `;if(ue(b)==="local")return `${S}
336
340
  ${b.name} {
337
341
  _id
338
342
  default
339
- ${E}}
340
- `;if(b.scope==="relationship"){let D=find(propEq(b.relationship?.entity,"name"))(n),z=find(propEq(b.relationship?.field,"name"))(D?.attributes??[]).scope==="local"?`{
343
+ ${A}}
344
+ `;if(ue(b)==="relationship"){let N=find(propEq(b.relationship?.entity,"name"))(n),_=find(propEq(b.relationship?.field,"name"))(N?.attributes??[]),B=ue(_)==="local"?`{
341
345
  _id
342
346
  default
343
- ${E}}
347
+ ${A}}
344
348
  `:"";if(b.relationship?.mode==="single")return `${S}
345
349
  ${b.name} {
346
- ${b.relationship.field} ${z}}
350
+ ${b.relationship.field} ${B}}
347
351
  `;if(b.relationship?.field)return `${S}
348
- ${b.name} (options: {limit: 25, offset: 0}) {
349
- ${b.relationship.field} ${z}}
352
+ ${b.name} (limit: 25, offset: 0) {
353
+ ${b.relationship.field} ${B}}
350
354
  `}return `${S}
351
355
  ${b.name}
352
356
  `},"");return `${y}
353
- ${v.name} (options: {limit: 25, offset: 0}) { _id ${A??""}}
354
- `},"");return {queryEntityName:f,query:`query ${u}(${s}) {
355
- ${e}Aggregate(where: $where) {
356
- count
357
- }
358
- ${f}${r} {
357
+ ${v.name} (limit: 25, offset: 0) { _id ${E??""}}
358
+ `},"");return {queryEntityName:d,query:`query ${c}(${s}) {
359
+ `+Yo(e,"(where: $where)")+` ${d}${r} {
359
360
  _id
360
- ${c} ${g} ${h} }
361
+ ${l} ${g} ${h} }
361
362
  }
362
- `}}function jn(){return v4()}function Gi(e,t=jn()){let{attributes:o}=a$e,n=vo(a$e.plural),r=_n(o,e),i=On(o,r),a=a$e.plural,s=Bn([a$e,b$8],a,"default");return `mutation ${`Create${Ht(a$e.plural)}`} {
363
+ `}}function Un(){return v4()}function Zi(e,t=Un()){let{attributes:o}=a$e,n=wo(a$e.plural),r=Bn(o,e),i=zn(o,r,"create"),a=a$e.plural,s=Hn([a$e,b$8],a,"default");return `mutation ${`Create${Qt(a$e.plural)}`} {
363
364
  create${n}(
364
365
  input: [{
365
- _id: ${ke(t)} ${i} }]
366
+ _id: ${me(t)} ${i} }]
366
367
  ) {
367
368
  ${a} {
368
369
  _id
369
370
  ${s} }
370
371
  }
371
372
  }
372
- `}var vo=e=>e.charAt(0).toUpperCase()+e.slice(1);function Ht(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(vo).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function Pt(e,t){return t==="_assets"?a$e:find(propEq(t,"plural"))(e)}function Zi(){let e=useApolloClient();return async t=>{let o=jn(),n=Gi(t,o);return await e.mutate({mutation:gql`
373
+ `}var wo=e=>e.charAt(0).toUpperCase()+e.slice(1);function Qt(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(wo).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function $t(e,t){return t==="_assets"?a$e:find(propEq(t,"plural"))(e)}function Ki(){let e=useApolloClient();return async t=>{let o=Un(),n=Zi(t,o);return await e.mutate({mutation:gql`
373
374
  ${n}
374
- `}),mc(t,o)}}function mc(e,t){return {_id:t,path:String(e.path?.value??""),originalFilename:String(e.originalFilename?.value??""),size:Number(e.size?.value??0),mimeType:String(e.mimeType?.value??""),lqip:String(e.lqip?.value??""),width:Number(e.width?.value??0),height:Number(e.height?.value??0)}}function tt(){let[e,t]=useState(false),[o,n]=useState(gql`
375
+ `}),yc(t,o)}}function yc(e,t){return {_id:t,path:String(e.path?.value??""),originalFilename:String(e.originalFilename?.value??""),size:Number(e.size?.value??0),mimeType:String(e.mimeType?.value??""),lqip:String(e.lqip?.value??""),width:Number(e.width?.value??0),height:Number(e.height?.value??0)}}function rt(){let[e,t]=useState(false),[o,n]=useState(gql`
375
376
  mutation updateEntity($any: Any) {
376
377
  any
377
378
  }
378
- `),[r,i]=useState({}),[a,{data:s,loading:f,error:u}]=useMutation(o,r),c=At(u),{isProjectDisabled:l,isProjectReadOnly:d}=(()=>{if(c?.statusCode===403){let m=St(c.bodyText);if(m&&typeof m.code=="string"){if(m.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(m.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,n,i,{data:s,loading:f,error:u,isProjectDisabled:l,isProjectReadOnly:d}]}function Un({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,a]=tt(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{u();},0),jsx(Fragment,{});let f={dialogTitle:`Delete ${s}`,dialogMessage:`Are you sure you want to delete the selected ${s}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>u()};function u(){let c=e.payload.entityId,l=yo(e.payload.entityName,n,c);return new Promise(d=>{i(gql`
379
- ${l}
380
- `),a({variables:{where:{_id:c}},update(m){m.evict({id:c});},onCompleted:()=>{toast.success("Item successfully deleted."),d();}}),r(true);})}return jsx(po,{options:f})}var vc=Drawer.Portal;function ea({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function bc({...e}){return jsx(vc,{...e})}function wc({className:e,...t}){return jsx(Drawer.Overlay,{"data-slot":"drawer-overlay",className:a$4("fk:fixed fk:inset-0 fk:z-50 fk:bg-overlay/75 fk:backdrop-blur-[1px] fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0",e),...t})}function ta({className:e,children:t,...o}){return jsxs(bc,{children:[jsx(wc,{}),jsxs(Drawer.Content,{"data-slot":"drawer-content",className:a$4("fk:group/drawer-content fk:fixed fk:z-50 fk:flex fk:h-auto fk:flex-col fk:bg-background","fk:data-[vaul-drawer-direction=top]:inset-x-0 fk:data-[vaul-drawer-direction=top]:top-0 fk:data-[vaul-drawer-direction=top]:mb-24 fk:data-[vaul-drawer-direction=top]:max-h-[80vh] fk:data-[vaul-drawer-direction=top]:rounded-b-lg fk:data-[vaul-drawer-direction=top]:border-b","fk:data-[vaul-drawer-direction=bottom]:inset-x-0 fk:data-[vaul-drawer-direction=bottom]:bottom-0 fk:data-[vaul-drawer-direction=bottom]:mt-24 fk:data-[vaul-drawer-direction=bottom]:max-h-[80vh] fk:data-[vaul-drawer-direction=bottom]:rounded-t-lg fk:data-[vaul-drawer-direction=bottom]:border-t","fk:data-[vaul-drawer-direction=right]:inset-y-0 fk:data-[vaul-drawer-direction=right]:right-0 fk:data-[vaul-drawer-direction=right]:w-full fk:data-[vaul-drawer-direction=right]:max-w-[clamp(40vw,95vw,60rem)] fk:data-[vaul-drawer-direction=right]:border-l fk:rounded-l-[20px]","fk:data-[vaul-drawer-direction=left]:inset-y-0 fk:data-[vaul-drawer-direction=left]:left-0 fk:data-[vaul-drawer-direction=left]:w-3/4 fk:data-[vaul-drawer-direction=left]:border-r fk:data-[vaul-drawer-direction=left]:sm:max-w-sm",e),...o,children:[jsx("div",{className:a$4("fk:absolute fk:z-10 fk:hidden fk:shrink-0 fk:rounded-full fk:bg-muted","fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:top-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:block fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=top]/drawer-content:bottom-4 fk:group-data-[vaul-drawer-direction=top]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:block fk:group-data-[vaul-drawer-direction=top]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=top]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=right]/drawer-content:left-3 fk:group-data-[vaul-drawer-direction=right]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:block fk:group-data-[vaul-drawer-direction=right]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=right]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:-translate-y-1/2","fk:group-data-[vaul-drawer-direction=left]/drawer-content:right-4 fk:group-data-[vaul-drawer-direction=left]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:block fk:group-data-[vaul-drawer-direction=left]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=left]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:-translate-y-1/2")}),t]})]})}function oa({className:e,...t}){return jsx("div",{"data-slot":"drawer-header",className:a$4("fk:flex fk:gap-2.5 fk:p-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center fk:group-data-[vaul-drawer-direction=top]/drawer-content:text-center fk:md:text-left",e),...t})}function na({className:e,...t}){return jsx(Drawer.Title,{"data-slot":"drawer-title",className:a$4("fk:flex fk:items-center fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",e),...t})}function ra({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Rt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[f,u]=useState(false),c=n*(50/n),l=useCallback(()=>{(!t||t())&&(u(false),setTimeout(()=>{a();},150));},[t,a,u]),d=useCallback(m=>{m.key==="Escape"&&r&&l();},[l,r]);return useEffect(()=>{u(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",d,false),()=>{globalThis.document.removeEventListener("keydown",d,false);}),[d]),jsx(ea,{direction:"right",dismissible:false,onClose:()=>{l();},open:f,children:jsxs(ta,{style:r?{}:{maxWidth:`calc(100% - ${c.toString()}px)`},children:[jsxs(oa,{className:"fk:px-10",children:[jsx(na,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(ra,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:l,size:"icon",variant:"ghost",children:[jsx(X,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Close"})]})]}),jsx(g$3,{}),jsx("div",{className:"fk:min-h-0 fk:px-10 fk:pt-6 fk:h-full fk:overflow-y-auto fk:pb-16","data-vaul-no-drag":true,children:o})]})})}var sa=createContext({isDirty:false,setIsDirty:e=>{}}),la=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(sa.Provider,{value:n,children:e})};function qt(){return useContext(sa)}function Jt({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function Qt({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}function Xt(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n);}},[t,e,o]),useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}function ya({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:f$1}=useParams(),u=ae(),c$1=d$2(),{relationships:l}=c$2(),[d,m$1]=useState(false),g$1=useRef(null),p=useRef(null),h$2=useRef(null),[y,v]=useState(null),[x,A]=useState(false),[S,b]=useState(false),E=useId(),D=useId();Xt(p,m$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let w=l[D]?.connect;if(!w||h$2.current===w._id)return;let k=Bc(w.value);if(!k)return;let P=n(i$1);h$2.current=w._id,v(null),r(i$1,{...P,value:k});},[n,i$1,D,l,r]);function B(w){if(!w)return;let k={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(k[w])return k[w];let P=w.split("/");if(P.length===2){let[,R]=P;return R.includes("svg")?"svg":R.toLowerCase()}}function z(w,k){if(w&&w.includes(".")){let R=w.split(".").pop();if(R)return R.toLowerCase()}let P=B(k);return P||"file"}async function F(w,k){if(!w)return;let P=Qn("4MB");if(w.size>(P??0)){toast.error("File size too big (max 4MB)");return}let R=w.type.startsWith("image/");if(h$2.current=null,R){let q=new FileReader;q.onload=G=>{let ne=new Image;v(G.target?.result),ne.onload=function(){r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,width:ne.width,height:ne.height}});},ne.src=q.result;},q.readAsDataURL(w);}else v(null);b(true);try{let G=await(await fetch(c$5(f$1).upload,{method:"POST",headers:{"Content-Type":w?.type||"application/octet-stream"},body:w})).json();r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,path:G.pathname,originalFilename:w.name,size:w.size,mimeType:w.type,lqip:G.lqip,...R?{}:{width:void 0,height:void 0}}});}catch(q){console.error(q),v(null),r(i$1,{...n(i$1)?.value,value:{_id:k?.value?._id}});}finally{b(false);}}function H(w){w.stopPropagation(),h$2.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function te(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function I(w){w.preventDefault(),w.stopPropagation(),g$1.current?.click();}function M(w){w.preventDefault(),w.stopPropagation(),m$1(false);let k=n(i$1)?.value,P=h$2.current??zc(k),R=P?{_id:P,value:k}:void 0;c$1({type:"setRelationship",payload:{[D]:{connect:R,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:R,relationshipId:D,mode:"single"}});},0);}function L(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$1,render:({field:w})=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${i$1}`,"aria-expanded":d,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${d?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${x?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.focus(),p.current?.click(),m$1(true);},onKeyDown:k=>{k.key==="Enter"&&m$1(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),A(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),A(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),A(false);let P=k.dataTransfer.files&&k.dataTransfer.files[0];F(P,w.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!w.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",id:E,onClick:I,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",onClick:M,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,w.value?.value?.path&&!d?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})})})(),Qn((w.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).mimeType,(w.value?.value).width&&(w.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).width,"x",(w.value?.value).height,"px"]}):null]}):null,!w.value?.value?.path&&y&&jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("img",{src:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!w.value?.value?.path&&!y&&S?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("div",{className:"fk:w-7 fk:h-7 fk:mr-2 fk:rounded-sm fk:bg-muted fk:flex fk:items-center fk:justify-center",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,w.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$1,{onClick:I,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:M,children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$1,{onClick:k=>L(k,w.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>te(k,w.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$1,{onClick:H,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!d&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(p.current?.focus(),p.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),d&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:d&&(!!w.value?.value?.path||!!y),children:jsx(Qt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:w.value?.value?.path?(()=>{let k=w.value?.value,P=k?.mimeType,R=k?.path||"";if(!!(P&&P.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(R)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let G=z(k.originalFilename,k.mimeType),ne=defaultStyles[G];return jsxs("div",{className:"fk:w-full fk:h-full fk:rounded-md fk:bg-muted/40 fk:flex fk:flex-col fk:items-center fk:justify-center fk:text-muted-foreground",children:[jsx("div",{className:"fk:w-16 fk:h-16 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ne||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Qn(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),S?jsx("div",{className:"fk:absolute fk:m-0! fk:top-0 fk:left-0 fk:right-0 fk:bottom-0 fk:w-full fk:bg-muted-foreground/5 fk:overflow-hidden",children:jsx("div",{className:"fk:animate-progress fk:w-full fk:h-full fk:bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:s?.accept?s.accept:"image/*",className:"fk:hidden",id:`file-upload-${i$1}`,onChange:k=>{let P=k.currentTarget.files&&k.currentTarget.files[0];F(P,w.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function Bc(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function zc(e){return !e?._id||e._id.includes(":")?"":e._id}function va({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,f$1=useId();function u(l,d){let m=l.currentTarget.value,g;m===""?g="":(g=s==="float"?parseFloat(m):parseInt(m,10),isNaN(g)&&(g="")),o(n,{...d,value:g});}function c$1(l,d){o(n,{...d,disabled:l});}return jsx(c,{control:e$1,name:n,render:({field:l})=>jsxs(e,{children:[jsx(f,{htmlFor:f$1,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$6,{className:`fk:w-full fk:mt-[0.1875rem] ${!l.value?.scope||l.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||l.value?.disabled,id:f$1,...l,onChange:d=>{u(d,l.value);},step:s==="float"?"any":"1",type:"number",value:l.value?.value??""})}),jsx(b$2,{checked:l.value?.disabled??false,onChange:d=>{c$1(d,l.value);},scope:l.value?.scope}),jsx(i,{})]})})}function Gt({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function Wt({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function kt({className:e,align:t="center",sideOffset:o=4,...n}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:a$4("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...n})})}function wa({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let f=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$4("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:u=>u.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",f.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",f.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",f.month),nav:a$4("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",f.nav),button_previous:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_previous),button_next:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_next),month_caption:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",f.month_caption),dropdowns:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",f.dropdowns),dropdown_root:a$4("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",f.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",f.dropdown),caption_label:a$4("fk:font-medium fk:select-none",n==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",f.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",f.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",f.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",f.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",f.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",f.week_number),day:a$4("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",s.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",f.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",f.range_start),range_middle:a$4("fk:rounded-none",f.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",f.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",f.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",f.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",f.disabled),hidden:a$4("invisible",f.hidden),...t},components:{Root:({className:u,rootRef:c,...l})=>jsx("div",{"data-slot":"calendar",ref:c,className:a$4(u),...l}),Chevron:({className:u,orientation:c,...l})=>c==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",u),...l}):c==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",u),...l}):jsx(ChevronDownIcon,{className:a$4("size-4",u),...l}),DayButton:Xc,WeekNumber:({children:u,...c})=>jsx("td",{...c,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:u})}),...a},...s})}function Xc({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=rn.useRef(null);return rn.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":o.selected&&!o.range_start&&!o.range_end&&!o.range_middle,"data-range-start":o.range_start,"data-range-end":o.range_end,"data-range-middle":o.range_middle,className:a$4("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...n})}function Ca({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,f$1=useId();function u(d,m){n(r,{...m,value:d?d.toISOString():""});}function c$1(d,m){n(r,{...m,disabled:d});}function l(d){d.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:d})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:f$1,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(Gt,{children:[jsx(Wt,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!d.value?.value&&"fk:text-muted-foreground",!d.value?.scope||d.value.scope==="default"?"fk:mb-3":""),disabled:a===false||d.value?.disabled,id:f$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:d.value?.value?format(new Date(d.value.value),"PPP")+" at "+format(new Date(d.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[d.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:m=>{m.stopPropagation(),l(m);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(kt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(wa,{mode:"single",selected:d.value?.value?new Date(d.value.value):void 0,onSelect:m=>u(m,d.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:m=>{let g=m.target.value,[p,h]=g.split(":"),y=d.value?.value?new Date(d.value.value):new Date;y.setHours(parseInt(p)),y.setMinutes(parseInt(h)),n(r,{...d.value,value:y.toISOString()});},type:"time",value:d.value?.value?format(new Date(d.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:d.value?.disabled??false,onChange:m=>{c$1(m,d.value);},scope:d.value?.scope}),jsx(i,{})]})})}function Ce(e){return e??null}var Gn=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let o=Ce(e);o&&o.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let o=document.createElement("input");o.type="file",o.accept="image/*",o.onchange=async()=>{o.files?.length;},o.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(o??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:o??""}).run():o!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(o??"")?e.chain().focus().deleteRange(t).setTweet({src:o??""}).run():o!==null&&alert("Please enter a correct Twitter Link");}}]),xa=Command.configure({suggestion:{items:()=>Gn,render:renderItems}});var Aa=[{name:"Default",color:"var(--novel-black)"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Yellow",color:"#EAB308"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],Sa=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],Ta=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Aa.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Sa.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(Gt,{modal:true,open:e,onOpenChange:t,children:[jsx(Wt,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(kt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),Aa.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:a},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),Sa.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:a},children:"A"}),jsx("span",{children:i})]}),o.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Cf(e){try{return new URL(e),!0}catch{return false}}function xf(e){if(Cf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Na=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$4("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(kt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let a=i[0],s=xf(a.value);s&&(n.chain().focus().setLink({href:s}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:o,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:n.getAttributes("link").href||""}),n.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{n.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var Ra=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleHeading({level:3}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ce(e);t&&t.chain().focus().clearNodes().toggleBlockquote().run();},isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],Fa=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ra.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:n.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:Ra.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),n.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var Ma=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:n}=e.state.selection,r=e.state.doc.textBetween(o,n);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$4("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var $a=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:o=>o!=null&&o.isActive("underline"),command:o=>o?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:o=>o!=null&&o.isActive("strike"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=Ce(o);n&&n.chain().focus().toggleCode().run();},icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:n=>{o.command(n);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:n=>n.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a$4("fk:h-4 fk:w-4",{"fk:text-blue-500":o.isActive(e)})})})},o.name))}):null};function bo({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var qf=()=>jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-0.5",children:[jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-500 [animation-delay:-0.3s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 [animation-delay:-0.15s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600"})]}),La=qf;function Kn({completion:e,onDiscard:t$1}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r,{children:[jsxs(t,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:n}=o.view.state;o.chain().focus().insertContentAt({from:n.from,to:n.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(t,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:n}=o.view.state;o.chain().focus().insertContentAt(n.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r,{children:jsxs(t,{onSelect:t$1,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var id=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function tr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:id.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,n);},className:"fk:flex fk:gap-2 fk:px-4",value:o.value,children:[jsx(o.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),o.label]},o.value))}),jsx(s,{}),jsx(r,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let o=t$1.state.selection.from,n=getPrevText(t$1,o);e(n,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function Oa({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(u,c)=>{let l=await fetch(u,c);if(l.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return l},onError:u=>{u.message!=="FK_AI_RATE_LIMIT"&&toast.error(u.message);}}),f=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[f&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(v,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(md,{children:i})})})}),s&&jsxs("div",{className:"fk:flex fk:h-12 fk:w-full fk:items-center fk:px-4 fk:text-sm fk:font-medium fk:text-muted-foreground fk:text-pink-600",children:[jsx(bo,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 "}),"AI is thinking",jsx("div",{className:"fk:ml-2 fk:mt-1",children:jsx(La,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:f?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let u=t.state.selection.content(),c=t.storage.markdown.serializer.serialize(u.content);a(c,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:f?jsx(Kn,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(tr,{onSelect:(u,c)=>a(u,{body:{option:c}})})})]})]}):null}function nr({children:e,open:t,onOpenChange:o}){let{editor:n}=useEditor();return useEffect(()=>{n&&(t||removeAIHighlight(n));},[n,t]),n?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),n.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(Oa,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),o(true);},size:"sm",children:[jsx(bo,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Rd=[...a,xa];function Ba(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function Fd(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(Ba(o))return o}catch{return}}if(Ba(e))return e}function rr({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[f$1,u]=useState(false),[c$1,l]=useState(false),[d,m]=useState(false),[g$1,p]=useState(false),h$1=useDebouncedCallback((x,A)=>{let S=x.getJSON();n(r,{...A,value:JSON.stringify(S)});},300);function y(x,A){n(r,{...A,disabled:x});}let v=x=>(console.log("Image uploader not yet implemented",x),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:x})=>jsxs(e,{children:[jsx(f,{children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-screen-lg fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:a!==false&&!x.value?.disabled,editorProps:{handleDOMEvents:{keydown:(A,S)=>handleCommandNavigation(S)},handlePaste:(A,S)=>handleImagePaste(A,S,v),handleDrop:(A,S,b,E)=>handleImageDrop(A,S,E,v),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:Rd,initialContent:Fd(x.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:A})=>{h$1(A,x.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Gn.map(A=>jsxs(EditorCommandItem,{value:A.title,onCommand:S=>A.command?.(S),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted",children:[jsx("div",{className:"fk:flex fk:h-10 fk:w-10 fk:items-center fk:justify-center fk:rounded-md fk:border fk:border-muted fk:bg-background",children:A.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:A.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:A.description})]})]},A.title))})]}),jsxs(nr,{open:f$1,onOpenChange:u,children:[jsx(g$3,{orientation:"vertical"}),jsx(Fa,{open:c$1,onOpenChange:l}),jsx(g$3,{orientation:"vertical"}),jsx(Na,{open:d,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(Ma,{}),jsx(g$3,{orientation:"vertical"}),jsx($a,{}),jsx(g$3,{orientation:"vertical"}),jsx(Ta,{open:g$1,onOpenChange:p})]})]},`${r}:${x.value?.scope??t.scope}:${String(x.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:x.value?.disabled??false,onChange:A=>{y(A,x.value);},scope:x.value?.scope}),jsx(i,{})]})})}var Id=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];async function Md(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:i=4*1024*1024}=e,a=document.createElement("input");a.type="file";let s=n??Id.join(",");a.accept=s,a.multiple=r,a.style.display="none",document.body.appendChild(a);try{let f=await new Promise(d=>{a.onchange=()=>d(a.files),a.click();});if(!f||f.length===0)return [];let u=[];for(let d of Array.from(f)){if(d.size>i){toast.error(`File size too big (max ${(i/(1024*1024)).toFixed(0)}MB): ${d.name}`);continue}u.push(d);}let c=c$5(o).upload,l=await Promise.all(u.map(async d=>{let m=await $d(d),g=await fetch(c,{method:"POST",headers:{"Content-Type":d.type||"application/octet-stream"},body:d});if(!g.ok)throw new Error(`Upload failed for ${d.name}`);let p=await g.json(),h={pathname:p.pathname,lqip:p.lqip,originalFilename:d.name,size:d.size,mimeType:d.type,width:m?.width,height:m?.height},y=t?await t(h,o):Ld(h);return {...h,_id:y._id,asset:y}}));return l.length>0&&toast.success(`Uploaded ${l.length} file${l.length>1?"s":""}`),l}catch(f){return console.error(f),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(a);}}async function $d(e){return e.type.startsWith("image/")?new Promise(o=>{let n=new FileReader;n.onload=()=>{let r=new Image;r.onload=()=>{o({width:r.width,height:r.height});},r.onerror=()=>o(null),r.src=n.result;},n.onerror=()=>o(null),n.readAsDataURL(e);}):null}function Eo(){let e=Zi();return async t=>Md(t,async o=>{let n={path:{_id:"",disabled:false,scope:"default",value:o.pathname},originalFilename:{_id:"",disabled:false,scope:"default",value:o.originalFilename},size:{_id:"",disabled:false,scope:"default",value:o.size},lqip:{_id:"",disabled:false,scope:"default",value:o.lqip},mimeType:{_id:"",disabled:false,scope:"default",value:o.mimeType},...typeof o.width=="number"?{width:{_id:"",disabled:false,scope:"default",value:o.width}}:{},...typeof o.height=="number"?{height:{_id:"",disabled:false,scope:"default",value:o.height}}:{}};return e(n)})}function Ld(e){return {_id:"",path:e.pathname,originalFilename:e.originalFilename,size:e.size,mimeType:e.mimeType,lqip:e.lqip??"",width:e.width??0,height:e.height??0}}function cr({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:f$1}=n,{projectId:u}=useParams(),c$1=ae(),l=d$2(),{relationships:d}=c$2(),m=Eo(),g$1=useId(),p=useId(),h$1=useRef(null),y=useRef([]),v$1=useRef(null),x=useRef([]),A=useRef(""),[S,b]=useState(false),E=useMemo(()=>Jd(t.value),[t.value]),[D,B]=useState(E);Xt(h$1,b),useEffect(()=>{let I=bt(E);y.current=E.map(M=>M._id),x.current=[],B(M=>{let L=bt(M);return I===""&&L!==""&&A.current===L||L===I?M:(A.current=I,E)});},[E]),useEffect(()=>{let I=d[p]?.connect;if(!I)return;let M=I.map((P,R)=>Ua(P.value,P.sortOrder??R)).filter(P=>!!P),L=bt(M),w=bt(D),k=v$1.current;k===w&&L!==k||(v$1.current=null,L!==w&&B(M));},[p,d,D]),useEffect(()=>{let I=bt(D);if(A.current===I)return;let M=D.map((k,P)=>({_id:k._id,sortOrder:P,value:{...k,sortOrder:P}})),L=D.map(k=>k._id),w=x.current.filter(k=>!L.includes(k));A.current=I,l({type:"setRelationship",payload:{[p]:{connect:M,disconnect:w}}}),r(i$1,{...t,relationships:{connect:M,disconnect:w},value:D});},[l,t,i$1,p,D,r]);function z(I){I.preventDefault(),I.stopPropagation(),c$1({type:"EditRelationship",payload:{connectedEntitiesCount:D.length,entityName:f$1?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function F(I){I.preventDefault(),I.stopPropagation();let M=await m({projectId:u,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(L=>{let w=new Set(L.map(R=>R._id)),k=M.map((R,q)=>({...R.asset,sortOrder:L.length+q})).filter(R=>!w.has(R._id)),P=sr([...L,...k]);return v$1.current=bt(P),P});}function H(I){B(M=>{let L=sr(M.filter(w=>w._id!==I));return y.current.includes(I)&&!x.current.includes(I)&&(x.current=[...x.current,I]),v$1.current=bt(L),L});}function te(I,M){B(L=>{let w=L.findIndex(G=>G._id===I),k=w+M;if(w<0||k<0||k>=L.length)return L;let P=[...L],[R]=P.splice(w,1);if(!R)return L;P.splice(k,0,R);let q=sr(P);return v$1.current=bt(q),q});}return jsx(c,{control:e$1,defaultValue:t,name:i$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:g$1,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${i$1}`,"aria-expanded":S,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${S?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:I=>{I.preventDefault(),I.stopPropagation(),h$1.current?.focus(),b(true);},ref:h$1,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[S&&D.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[D.length," ",D.length===1?"asset":"assets"," selected"]}):D.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[D.slice(0,8).map(I=>jsx(Ud,{asset:I},I._id)),!S&&D.length>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",D.length-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:g$1,onClick:I=>{I.preventDefault(),I.stopPropagation(),b(M=>!M);},size:"icon",variant:"ghost",children:S?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:S?"Close":"Expand field"})})]})})]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:b,open:S,children:jsx(Qt,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${i$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:z,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",onClick:I=>{F(I);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),D.length>0?jsx(v,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:D.map((I,M)=>jsx(qd,{asset:I,index:M,isFirst:M===0,isLast:M===D.length-1,moveAsset:te,removeAsset:H},I._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Ud({asset:e}){return qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image$1,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function qd({asset:e,index:t,isFirst:o,isLast:n,moveAsset:r,removeAsset:i}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image$1,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:o,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:n,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",onClick:()=>i(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Jd(e){return Array.isArray(e)?e.map((t,o)=>Ua(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function bt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function sr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Ua(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let o=e;return {_id:String(o._id??""),path:String(o.path??""),originalFilename:String(o.originalFilename??""),size:Number(o.size??0),mimeType:String(o.mimeType??""),lqip:String(o.lqip??""),width:Number(o.width??0),height:Number(o.height??0),sortOrder:o.sortOrder??t}}function qa(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Qa({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function To({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=d(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},i={boolean:a$a,date:a$9,datetime:a$c,editor:b$7,asset:a$b,number:a$9,relationship:a$9,select:a$9,switch:a$a,text:a$9,textarea:a$9,tags:Qa},a=e.map(c=>{let l=(c.inputType==="relationship"&&c.relationship?.entity==="_asset"?"asset":void 0)??c.previewType??r[c.inputType],d=n("previewFields",[l])?.[0]?.component??i[l]??i.text;if(c.isHidden)return null;let m=l==="tags";return {accessorKey:c.name,filterFn:(g,p,h)=>m?true:(Array.isArray(h)?h:[h]).includes(g.getValue(p)),header:()=>jsx("div",{className:"fk:flex fk:items-center",children:c.label}),cell:({row:g})=>jsx(d,{value:g.getValue(c.name)}),enableSorting:false,enableHiding:true,size:c.options?.size??150}}).filter(c=>c!==null),s={id:"actions",cell:({row:c})=>o?o(c):null,size:80},f={id:"select",cell:({row:c,table:l})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:d=>{l.toggleAllPageRowsSelected(false),c.toggleSelected(!!d);}}),enableSorting:false,enableHiding:false,size:50},u={id:"select",header:({table:c})=>jsx(a$d,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:c.getIsAllPageRowsSelected()||c.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:l=>{c.toggleAllPageRowsSelected(!!l);}}),cell:({row:c})=>jsx(a$d,{"aria-label":"Select row",checked:c.getIsSelected(),onCheckedChange:l=>{c.toggleSelected(!!l);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[f]:[],...t==="multiple"?[u]:[],...o?[s]:[],...a]}function nu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function Do({classNames:e,columns:t,data:o,initialSelectionState:n$1,onEntitySelectionChange:r,onScroll:i,pageSize:a,rowHeightEstimate:s,rowAdditionState:f,rowDeletionState:u,toolbarComponent:c}){let l$1=useRef(null),{schemaErrorMessage:d}=Tt(),[m,g]=useState(n$1??{}),[p,h]=useState({}),[y,v]=useState([]),[x,A]=useState([]);useEffect(()=>{if(!n$1)return;let F=Object.keys(m).sort().join(","),H=Object.keys(n$1).sort().join(",");F!==H&&g(n$1);},[n$1,m]);let S=useReactTable({data:o,columns:t,state:{sorting:x,columnVisibility:p,rowSelection:m,columnFilters:y},initialState:{pagination:{pageSize:a??25}},enableRowSelection:true,onRowSelectionChange:z,onSortingChange:A,onColumnFiltersChange:v,onColumnVisibilityChange:h,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:F=>F._id,manualPagination:true,meta:{getRowBackground:F=>ru(F,u,f)}}),{rows:b}=S.getRowModel(),E=useVirtualizer({count:b.length,estimateSize:()=>s??nu(e?.row)??45,getScrollElement:()=>l$1.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?F=>F.getBoundingClientRect().height:void 0,overscan:5}),D=E.getVirtualItems(),B=E.getTotalSize();function z(F){let H=Object.keys(typeof F=="function"?F(m):F);g(F),r?.(H);}return d?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:flex-col fk:gap-4",e?.wrapper),children:[c&&c(S),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:-mb-px",children:jsxs(h$2,{className:a$4("fk:grid fk:pb-20",e?.table),onScroll:i,ref:l$1,children:[jsx(i$1,{className:"fk:grid",children:S.getHeaderGroups().map(F=>jsx(l,{className:"fk:flex fk:w-full",children:F.headers.map(H=>jsx(m$1,{className:a$4("fk:flex fk:items-center",H.column.id==="actions"&&"fk:pl-0"),colSpan:H.colSpan,style:H.getSize()?{width:`${H.getSize().toString()}px`}:{},children:H.isPlaceholder?null:flexRender(H.column.columnDef.header,H.getContext())},H.id))},F.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${B.toString()}px`},children:D.length?D.map(F=>{let H=b[F.index];return jsx(l,{className:`${S.options.meta.getRowBackground(H)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":F.index,"data-state":H.getIsSelected()&&"selected",ref:E.measureElement,style:{transform:`translateY(${F.start.toString()}px)`},children:H.getVisibleCells().map(te=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",te.column.id==="actions"&&"fk:pl-0!"),style:{width:te.column.getSize()},children:flexRender(te.column.columnDef.cell,te.getContext())},te.id))},F.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function ru(e,t,o){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Wa({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var yu=25;function ur({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:f$1,setValue:u}){let[c$1,l]=useState(false),d=useRef(null);Xt(d,l);let[m,g$1]=useState([]),{name:p,label:h$1,options:y,relationship:v}=a,x=v?.entity??p,A=ae(),S=d$2(),{relationships:b}=c$2(),E=useId(),D=useId(),B=find(propEq(x,"name"))(s),z=B?.attributes??[],H=find(propEq(r,"name"))(s)?.name??"",te=find(propEq(r,"name"))(z)?.relationship?.mode,I,L=z.find(_=>_.relationship?.entity===H)?.relationship?.mode,w=te==="single"?r:i$1;L&&(I=L==="single"?`${w}Connection_NOT`:`${w}Connection_NONE`);let k=bu(z),P=useMemo(()=>o.value?wu({data:o.value,defaultScope:t,primaryAttributeName:k,relationshipEntitySchema:B,scope:f$1}):[],[t,o,k,B,f$1]),R=Xi({attributeName:p,relatedEntityName:x,scope:f$1,schema:s}),q=m.length?m.slice(0,12).map(_=>_[k]):[],[G,{loading:ne,data:qe}]=useLazyQuery(gql`
381
- ${R.query}
382
- `),ao=To({attributesSchema:B?.attributes??[],actionsComponent:_=>vu({appDispatch:S,relationshipId:D,relationships:b,row:_,setRows:g$1})});useEffect(()=>{g$1(P),o.value!==""&&S({type:"setRelationship",payload:{[D]:{connect:[],disconnect:[]}}});},[S,qe,P,D,o,f$1]),useEffect(()=>{u(p,{...o,relationships:b[D]});},[o,b,D,u,p]),useEffect(()=>{let Mt=(b[D]?.connect??[]).map(({value:so})=>so);g$1(uniqBy(prop("_id"),[...Mt,...P]));},[qe,o.count,P,b,D]);let yn=useCallback(_=>{let Mt=o.count??0;if(!_||Mt===0||m.length===0)return;let{scrollHeight:so,scrollTop:vn,clientHeight:bn}=_;so-vn-bn<200&&!ne&&m.length<Mt&&G({variables:{options:{limit:yu,offset:m.length},where:{productsConnection_SOME:{node:{_id:n}}}}}).then(({data:$})=>{if(!$)return;let U=Ko(B?.plural??"",f$1,$,s);g$1(uniqBy(prop("_id"),[...P,...U.results]));}).catch($=>{console.error("Error fetching more data:",$);});},[o.count,n,G,P,ne,B?.plural,m.length,s,f$1]);function $o(_){_.preventDefault(),A({type:"EditRelationship",payload:{connectedEntitiesCount:P.length,connectionName:I,entityName:x,entityId:n,relationshipId:D,mode:v?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:E,children:h$1}),y?.comment?jsx(h,{children:y.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.375rem] fk:pl-3 fk:pr-10 fk:py-0.5 fk:text-sm",children:jsxs("div",{"aria-controls":`relationship-dropdown-${p}`,"aria-expanded":c$1,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.focus(),d.current?.click(),l(true);},onKeyDown:_=>{_.key==="Enter"&&l(true),_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},ref:d,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[c$1?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:$o,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",B?.menu?.label??B?.plural]}):jsx("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:q.map(_=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:_},_))}),c$1?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:_=>{_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false);},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),_.stopPropagation(),d.current?.blur(),l(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:E,onKeyDown:_=>{_.key==="Enter"&&(d.current?.focus(),d.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Jt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:l,open:c$1,children:jsx(Qt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:mt-3 fk:mb-2",id:`relationship-dropdown-${p}`,children:jsx(Do,{classNames:{table:"fk:max-h-[17.5rem]"},columns:ao,data:m,entityName:r,onScroll:_=>{yn(_.target);},rowAdditionState:b[D]?.connect,rowDeletionState:b[D]?.disconnect})})})})]})}),jsx(i,{})]})})}function vu({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],f=typeof find(propEq(a,"_id"),s)=="object",u=o[t]?.disconnect?.includes(a),c=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&r(l=>l.filter(d=>d._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(l=>l._id!==a),disconnect:u?o[t]?.disconnect?.filter(l=>l!==a)??[]:c}}});}return jsx(Wa,{action:i,row:n})}function bu(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function wu({data:e,defaultScope:t,primaryAttributeName:o,relationshipEntitySchema:n,scope:r}){return Array.isArray(e)?e.map(i=>map(a=>{if(a&&typeof a!="string"&&!Array.isArray(a)&&a.__typename){let f=find(propEq(a.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";return f?a[f]?.[r]??a[f]?.[t]??a[f]:a[r]??a[t]}return Array.isArray(a)?a.slice(0,3).map(f=>f[o]?.[r]??f[o]?.[t]).join(", "):a},i)):[]}function mr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:f$1}){let[u,c$1]=useState(false),{name:l,label:d,options:m,relationship:g$1}=r,p=g$1?.entity??l,h$1=ae(),y=d$2(),v=useId(),{relationships:x}=c$2(),A=useId(),S=find(propEq(p,"name"))(a),E=Tu(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[A]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,A,o,s]),useEffect(()=>{f$1(l,{...i$1(l),...x[A]?.connect??""});},[o,l,x,A,f$1]);function D(z){z.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:A,mode:g$1?.mode??"single"}});}function B(z){let F={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};z.preventDefault(),y(F),f$1(l,{...i$1(l),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:l,render:({field:z})=>{let F=z.value?.value,H="";return F&&typeof F=="object"&&!Array.isArray(F)&&F[E]&&(H=F[E]?.[s]??F[E]?.[t]??F[E]),jsxs(e,{children:[jsx(f,{htmlFor:v,children:d}),m?.comment?jsx(h,{children:m.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$6,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:v,onBlur:()=>{c$1(false);},onClick:D,onFocus:()=>{c$1(true);},onKeyDown:te=>{te.key==="Enter"&&D(te);},readOnly:true,type:"text",value:H}),H?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:B,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:D,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i,{})]})}})}function Tu(e){return e.find(t=>t.isPrimary)??e[0]}function pr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(mr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(cr,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(ur,{...n})}return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function ns({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(u,c){let d=t.dataType==="int"&&!isNaN(Number(u))?Number(u):u;o(n,{...c,value:d});}function f$2(u,c){o(n,{...c,disabled:u});}return jsx(c,{control:e$2,name:n,render:({field:u})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:u.value?.value?String(u.value.value):void 0,disabled:i$1===false||u.value?.disabled,onValueChange:c=>{s(c,u.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(c=>"groupLabel"in c?jsxs(b$1,{children:[jsx(f$1,{children:c.groupLabel}),c.items.map(l=>jsx(g$1,{value:l.value,children:l.label},l.label))]},c.groupLabel):jsx(g$1,{value:c.value,children:c.label},c.label))})]}),jsx(b$2,{checked:u.value?.disabled??false,onChange:c=>{f$2(c,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function hr({inputType:e,label:t}){return jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Hu({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:f},u){let c=find(propEq(n,"name"))(a),l=useMemo(()=>c?.attributes??[],[c]),d$1=useMemo(()=>z.object(l.reduce((b,E)=>typeof E.validation>"u"?b:{...b,[E.name]:z.object({value:E.validation(z).or(z.any().refine(()=>false,{message:E.label?`${E.label} is required`:"Required field"}))})},{})),[l]),m=useForm({resolver:zodResolver(d$1),values:i,mode:"onBlur",criteriaMode:"all"}),{control:g,getValues:p,handleSubmit:h,setValue:y,watch:v,trigger:x}=m,{getContributionPointConfig:A}=d(),S={datetime:Ca,editor:rr,asset:ya,number:va,relationship:pr,select:ns,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(u,()=>({submit(){x().then(()=>{h(()=>{s(false),f(p(),i);})();});},hasErrors(){s(true);},hasDataChanged(){return is(p(),i)}})),useEffect(()=>{let b=v(E=>{s(is(E,i));});return ()=>{b.unsubscribe();}},[i,s,v]),!c||c.attributes.length===0?jsxs(re,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsxs(ie,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...m,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:l.map(b=>{if(b.name==="_id")return null;let E=A("formFields",[b.inputType])?.[0]?.component??S[b.inputType];return E?createElement(E,{key:b.name,control:g,defaultScope:t,defaultValue:i?i[b.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:b,getValues:p,schema:a,scope:e,setValue:y}):jsx(hr,{inputType:b.inputType,label:b.label},b.name)})})})}var pn=memo(forwardRef(Hu));function is(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let o=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",n=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(e[s]?.value),disabled:e[s]?.disabled??false,relationships:Object.keys(e[s]?.relationships?.connect??{}).length||e[s]?.relationships?.disconnect?.length?e[s]?.relationships:void 0}}),{});return !equals(r,i)}function br({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:a}=d(),{schema:s,scopes:f}=find(propEq(a??"","projectId"))(i),u=f?.find(E=>E.isDefault)?.name??"default",l=find(propEq(n,"name"))(s)?.plural??n,{scope:d$1}=c$2(),m=ae(),[g,p,h,y]=tt(),{setIsDirty:v}=qt();useEffect(()=>{y.error&&r.current?.hasErrors();},[y.error]);function x(){return r.current?.hasDataChanged()?(m({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{m({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{m({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let A=useCallback(E=>{m({type:"Dismiss",_id:E,payload:{}});},[m]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(E=>{let D=v4(),B=zn(l,s,E,D),z=Nt(l,d$1,s),F=gql`
383
- ${z.query}
379
+ `),[r,i]=useState({}),[a,{data:s,loading:d,error:c}]=useMutation(o,r),l=Dt(c),{isProjectDisabled:f,isProjectReadOnly:u}=(()=>{if(l?.statusCode===403){let m=Pt(l.bodyText);if(m&&typeof m.code=="string"){if(m.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(m.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(a(),t(false));},[e,a]),[t,n,i,{data:s,loading:d,error:c,isProjectDisabled:f,isProjectReadOnly:u}]}function Qn({action:e}){let{projects:t,currentProjectId:o}=d(),{schema:n}=find(propEq(o??"","projectId"))(t),[r,i,a]=rt(),s=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase();if(e.payload.silent)return setTimeout(()=>{c();},0),jsx(Fragment,{});let d$1={dialogTitle:`Delete ${s}`,dialogMessage:`Are you sure you want to delete the selected ${s}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>c()};function c(){let l=e.payload.entityId,f=bo(e.payload.entityName,n,l);return new Promise(u=>{i(gql`
380
+ ${f}
381
+ `),a({variables:{where:{_id:{eq:l}}},update(m){m.evict({id:l});},onCompleted:()=>{toast.success("Item successfully deleted."),u();}}),r(true);})}return jsx(ko,{options:d$1})}var Ec=Drawer.Portal;function oa({...e}){return jsx(Drawer.Root,{"data-slot":"drawer",...e})}function Sc({...e}){return jsx(Ec,{...e})}function Ac({className:e,...t}){return jsx(Drawer.Overlay,{"data-slot":"drawer-overlay",className:a$4("fk:fixed fk:inset-0 fk:z-50 fk:bg-overlay/75 fk:backdrop-blur-[1px] fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0",e),...t})}function na({className:e,children:t,...o}){return jsxs(Sc,{children:[jsx(Ac,{}),jsxs(Drawer.Content,{"data-slot":"drawer-content",className:a$4("fk:group/drawer-content fk:fixed fk:z-50 fk:flex fk:h-auto fk:flex-col fk:bg-background","fk:data-[vaul-drawer-direction=top]:inset-x-0 fk:data-[vaul-drawer-direction=top]:top-0 fk:data-[vaul-drawer-direction=top]:mb-24 fk:data-[vaul-drawer-direction=top]:max-h-[80vh] fk:data-[vaul-drawer-direction=top]:rounded-b-lg fk:data-[vaul-drawer-direction=top]:border-b","fk:data-[vaul-drawer-direction=bottom]:inset-x-0 fk:data-[vaul-drawer-direction=bottom]:bottom-0 fk:data-[vaul-drawer-direction=bottom]:mt-24 fk:data-[vaul-drawer-direction=bottom]:max-h-[80vh] fk:data-[vaul-drawer-direction=bottom]:rounded-t-lg fk:data-[vaul-drawer-direction=bottom]:border-t","fk:data-[vaul-drawer-direction=right]:inset-y-0 fk:data-[vaul-drawer-direction=right]:right-0 fk:data-[vaul-drawer-direction=right]:w-full fk:data-[vaul-drawer-direction=right]:max-w-[clamp(40vw,95vw,60rem)] fk:data-[vaul-drawer-direction=right]:border-l fk:rounded-l-[20px]","fk:data-[vaul-drawer-direction=left]:inset-y-0 fk:data-[vaul-drawer-direction=left]:left-0 fk:data-[vaul-drawer-direction=left]:w-3/4 fk:data-[vaul-drawer-direction=left]:border-r fk:data-[vaul-drawer-direction=left]:sm:max-w-sm",e),...o,children:[jsx("div",{className:a$4("fk:absolute fk:z-10 fk:hidden fk:shrink-0 fk:rounded-full fk:bg-muted","fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:top-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:block fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=top]/drawer-content:bottom-4 fk:group-data-[vaul-drawer-direction=top]/drawer-content:left-1/2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:block fk:group-data-[vaul-drawer-direction=top]/drawer-content:h-2 fk:group-data-[vaul-drawer-direction=top]/drawer-content:w-[100px] fk:group-data-[vaul-drawer-direction=top]/drawer-content:-translate-x-1/2","fk:group-data-[vaul-drawer-direction=right]/drawer-content:left-3 fk:group-data-[vaul-drawer-direction=right]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:block fk:group-data-[vaul-drawer-direction=right]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=right]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=right]/drawer-content:-translate-y-1/2","fk:group-data-[vaul-drawer-direction=left]/drawer-content:right-4 fk:group-data-[vaul-drawer-direction=left]/drawer-content:top-1/2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:block fk:group-data-[vaul-drawer-direction=left]/drawer-content:h-[100px] fk:group-data-[vaul-drawer-direction=left]/drawer-content:w-2 fk:group-data-[vaul-drawer-direction=left]/drawer-content:-translate-y-1/2")}),t]})]})}function ra({className:e,...t}){return jsx("div",{"data-slot":"drawer-header",className:a$4("fk:flex fk:gap-2.5 fk:p-4 fk:group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center fk:group-data-[vaul-drawer-direction=top]/drawer-content:text-center fk:md:text-left",e),...t})}function ia({className:e,...t}){return jsx(Drawer.Title,{"data-slot":"drawer-title",className:a$4("fk:flex fk:items-center fk:text-lg fk:font-semibold fk:leading-none fk:tracking-tight",e),...t})}function aa({className:e,...t}){return jsx(Drawer.Description,{"data-slot":"drawer-description",className:a$4("fk:text-sm fk:text-muted-foreground",e),...t})}function Mt({actions:e,beforeClose:t,children:o,depth:n,isFocused:r,onFormChange:i,onClose:a,title:s}){let[d,c]=useState(false),l=n*(50/n),f=useCallback(()=>{(!t||t())&&(c(false),setTimeout(()=>{a();},150));},[t,a,c]),u=useCallback(m=>{m.key==="Escape"&&r&&f();},[f,r]);return useEffect(()=>{c(true),globalThis.document.body.classList.add("fk-drawer-fix");},[]),useEffect(()=>(globalThis.document.addEventListener("keydown",u,false),()=>{globalThis.document.removeEventListener("keydown",u,false);}),[u]),jsx(oa,{direction:"right",dismissible:false,onClose:()=>{f();},open:d,children:jsxs(na,{style:r?{}:{maxWidth:`calc(100% - ${l.toString()}px)`},children:[jsxs(ra,{className:"fk:px-10",children:[jsx(ia,{className:"fk:w-full",children:s||jsx(r$1,{className:"fk:h-5 fk:w-[120px]"})}),jsx(aa,{className:"fk:sr-only",children:s||"Loading form"}),e,jsxs(b$3,{className:"",onClick:f,size:"icon",variant:"ghost",children:[jsx(X,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Close"})]})]}),jsx(g$3,{}),jsx("div",{className:"fk:min-h-0 fk:px-10 fk:pt-6 fk:h-full fk:overflow-y-auto fk:pb-16","data-vaul-no-drag":true,children:o})]})})}var ca=createContext({isDirty:false,setIsDirty:e=>{}}),fa=({children:e})=>{let[t,o]=useState(false),n=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(ca.Provider,{value:n,children:e})};function Gt(){return useContext(ca)}function Wt({...e}){return jsx(Collapsible.Root,{"data-slot":"collapsible",...e})}function Zt({...e}){return jsx(Collapsible.CollapsibleContent,{"data-slot":"collapsible-content",...e})}function Yt(e,t,o){useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",n),()=>{document.removeEventListener("mousedown",n);}},[t,e,o]),useEffect(()=>{function n(r){if(e.current&&!e.current.contains(r.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(r.target))return}t(false);}}return document.addEventListener("focusin",n),()=>{document.removeEventListener("mousedown",n);}},[t,e]);}function ba({control:e$1,entityId:t,fieldSchema:o,getValues:n,setValue:r}){let{name:i$1,label:a,options:s}=o,{projectId:d}=useParams(),c$1=ie(),l=d$2(),{relationships:f$1}=c$2(),[u,m$1]=useState(false),g$1=useRef(null),p=useRef(null),h$2=useRef(null),[y,v]=useState(null),[x,E]=useState(false),[S,b]=useState(false),A=useId(),N=useId();Yt(p,m$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let w=f$1[N]?.connect;if(!w||h$2.current===w._id)return;let k=Uc(w.value);if(!k)return;let R=n(i$1);h$2.current=w._id,v(null),r(i$1,{...R,value:k});},[n,i$1,N,f$1,r]);function _(w){if(!w)return;let k={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(k[w])return k[w];let R=w.split("/");if(R.length===2){let[,P]=R;return P.includes("svg")?"svg":P.toLowerCase()}}function B(w,k){if(w&&w.includes(".")){let P=w.split(".").pop();if(P)return P.toLowerCase()}let R=_(k);return R||"file"}async function I(w,k){if(!w)return;let R=Wn("4MB");if(w.size>(R??0)){toast.error("File size too big (max 4MB)");return}let P=w.type.startsWith("image/");if(h$2.current=null,P){let U=new FileReader;U.onload=G=>{let ae=new Image;v(G.target?.result),ae.onload=function(){r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,width:ae.width,height:ae.height}});},ae.src=U.result;},U.readAsDataURL(w);}else v(null);b(true);try{let G=await(await fetch(c$5(d).upload,{method:"POST",headers:{"Content-Type":w?.type||"application/octet-stream"},body:w})).json();r(i$1,{...n(i$1)?.value,value:{...n(i$1)?.value,path:G.pathname,originalFilename:w.name,size:w.size,mimeType:w.type,lqip:G.lqip,...P?{}:{width:void 0,height:void 0}}});}catch(U){console.error(U),v(null),r(i$1,{...n(i$1)?.value,value:{_id:k?.value?._id}});}finally{b(false);}}function j(w){w.stopPropagation(),h$2.current=null,r(i$1,{...n(i$1),_id:"",value:{_id:n(i$1)?.value?._id}});}function q(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function F(w){w.preventDefault(),w.stopPropagation(),g$1.current?.click();}function M(w){w.preventDefault(),w.stopPropagation(),m$1(false);let k=n(i$1)?.value,R=h$2.current??Jc(k),P=R?{_id:R,value:k}:void 0;l({type:"setRelationship",payload:{[N]:{connect:P,disconnect:[]}}}),window.setTimeout(()=>{c$1({type:"EditRelationship",payload:{assetAccept:s?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:P,relationshipId:N,mode:"single"}});},0);}function $(w,k){w.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:i$1,render:({field:w})=>jsxs(e,{children:[jsx(f,{htmlFor:A,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${i$1}`,"aria-expanded":u,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${x?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.focus(),p.current?.click(),m$1(true);},onKeyDown:k=>{k.key==="Enter"&&m$1(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},onDragOver:k=>{k.preventDefault(),k.stopPropagation(),E(true);},onDragEnter:k=>{k.preventDefault(),k.stopPropagation(),E(true);},onDragLeave:k=>{k.preventDefault(),k.stopPropagation(),E(false);},onDrop:k=>{k.preventDefault(),k.stopPropagation(),E(false);let R=k.dataTransfer.files&&k.dataTransfer.files[0];I(R,w.value);},ref:p,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!w.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",id:A,onClick:F,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",onClick:M,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,w.value?.value?.path&&!u?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=w.value?.value,R=k?.mimeType,P=k?.path||"";if(!!(R&&R.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(P)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let G=B(k.originalFilename,k.mimeType),ae=defaultStyles[G];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ae||{}})})})(),Wn((w.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).mimeType,(w.value?.value).width&&(w.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(w.value?.value).width,"x",(w.value?.value).height,"px"]}):null]}):null,!w.value?.value?.path&&y&&jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("img",{src:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!w.value?.value?.path&&!y&&S?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("div",{className:"fk:w-7 fk:h-7 fk:mr-2 fk:rounded-sm fk:bg-muted fk:flex fk:items-center fk:justify-center",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,w.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$1,{onClick:F,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$1,{onClick:M,children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$1,{onClick:k=>$(k,w.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$1,{onClick:k=>q(k,w.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$1,{onClick:j,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!u&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(p.current?.focus(),p.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),u&&(w.value?.value?.path||y)?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),p.current?.blur(),m$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(Wt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:u&&(!!w.value?.value?.path||!!y),children:jsx(Zt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${i$1}`,children:w.value?.value?.path?(()=>{let k=w.value?.value,R=k?.mimeType,P=k?.path||"";if(!!(R&&R.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(P)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let G=B(k.originalFilename,k.mimeType),ae=defaultStyles[G];return jsxs("div",{className:"fk:w-full fk:h-full fk:rounded-md fk:bg-muted/40 fk:flex fk:flex-col fk:items-center fk:justify-center fk:text-muted-foreground",children:[jsx("div",{className:"fk:w-16 fk:h-16 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:G,...ae||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",Wn(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),S?jsx("div",{className:"fk:absolute fk:m-0! fk:top-0 fk:left-0 fk:right-0 fk:bottom-0 fk:w-full fk:bg-muted-foreground/5 fk:overflow-hidden",children:jsx("div",{className:"fk:animate-progress fk:w-full fk:h-full fk:bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:s?.accept?s.accept:"image/*",className:"fk:hidden",id:`file-upload-${i$1}`,onChange:k=>{let R=k.currentTarget.files&&k.currentTarget.files[0];I(R,w.value);},ref:g$1,type:"file"}),jsx(i,{})]})})}function Uc(e){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let t=e;return {_id:String(t._id??""),path:String(t.path??""),originalFilename:String(t.originalFilename??""),size:Number(t.size??0),mimeType:String(t.mimeType??""),lqip:String(t.lqip??""),width:Number(t.width??0),height:Number(t.height??0)}}function Jc(e){return !e?._id||e._id.includes(":")?"":e._id}function wa({control:e$1,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a,dataType:s}=t,d=useId();function c$1(f,u){let m=f.currentTarget.value,g;m===""?g="":(g=s==="float"?parseFloat(m):parseInt(m,10),isNaN(g)&&(g="")),o(n,{...u,value:g});}function l(f,u){o(n,{...u,disabled:f});}return jsx(c,{control:e$1,name:n,render:({field:f$1})=>jsxs(e,{children:[jsx(f,{htmlFor:d,children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsx(g,{children:jsx(a$6,{className:`fk:w-full fk:mt-[0.1875rem] ${!f$1.value?.scope||f$1.value.scope==="default"?"fk:mb-3":""}`,disabled:i$1===false||f$1.value?.disabled,id:d,...f$1,onChange:u=>{c$1(u,f$1.value);},step:s==="float"?"any":"1",type:"number",value:f$1.value?.value??""})}),jsx(b$2,{checked:f$1.value?.disabled??false,onChange:u=>{l(u,f$1.value);},scope:f$1.value?.scope}),jsx(i,{})]})})}function Kt({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function eo({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function bt({className:e,align:t="center",sideOffset:o=4,...n}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:o,className:a$4("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...n})})}function xa({className:e,classNames:t,showOutsideDays:o=true,captionLayout:n="label",buttonVariant:r="ghost",formatters:i,components:a,...s}){let d=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$4("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:n,formatters:{formatMonthDropdown:c=>c.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$4("w-fit",d.root),months:a$4("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",d.months),month:a$4("fk:flex fk:w-full fk:flex-col fk:gap-4",d.month),nav:a$4("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",d.nav),button_previous:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",d.button_previous),button_next:a$4(a$8({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",d.button_next),month_caption:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",d.month_caption),dropdowns:a$4("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",d.dropdowns),dropdown_root:a$4("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",d.dropdown_root),dropdown:a$4("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",d.dropdown),caption_label:a$4("fk:font-medium fk:select-none",n==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",d.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$4("fk:flex",d.weekdays),weekday:a$4("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",d.weekday),week:a$4("fk:mt-2 fk:flex fk:w-full",d.week),week_number_header:a$4("fk:w-(--cell-size) fk:select-none",d.week_number_header),week_number:a$4("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",d.week_number),day:a$4("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",s.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",d.day),range_start:a$4("fk:rounded-l-md fk:bg-accent",d.range_start),range_middle:a$4("fk:rounded-none",d.range_middle),range_end:a$4("fk:rounded-r-md fk:bg-accent",d.range_end),today:a$4("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",d.today),outside:a$4("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",d.outside),disabled:a$4("fk:text-muted-foreground fk:opacity-50",d.disabled),hidden:a$4("invisible",d.hidden),...t},components:{Root:({className:c,rootRef:l,...f})=>jsx("div",{"data-slot":"calendar",ref:l,className:a$4(c),...f}),Chevron:({className:c,orientation:l,...f})=>l==="left"?jsx(ChevronLeftIcon,{className:a$4("size-4",c),...f}):l==="right"?jsx(ChevronRightIcon,{className:a$4("size-4",c),...f}):jsx(ChevronDownIcon,{className:a$4("size-4",c),...f}),DayButton:Kc,WeekNumber:({children:c,...l})=>jsx("td",{...l,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:c})}),...a},...s})}function Kc({className:e,day:t,modifiers:o,...n}){let r=getDefaultClassNames(),i=rn.useRef(null);return rn.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":o.selected&&!o.range_start&&!o.range_end&&!o.range_middle,"data-range-start":o.range_start,"data-range-end":o.range_end,"data-range-middle":o.range_middle,className:a$4("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...n})}function Ea({control:e$1,fieldSchema:t,getValues:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=t,d=useId();function c$1(u,m){n(r,{...m,value:u?u.toISOString():""});}function l(u,m){n(r,{...m,disabled:u});}function f$1(u){u.preventDefault(),n(r,{...o(r),value:void 0});}return jsx(c,{control:e$1,name:r,render:({field:u})=>jsxs(e,{onKeyDown:m=>{m.key==="Escape"&&(m.preventDefault(),m.stopPropagation());},children:[jsx(f,{htmlFor:d,children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsxs(Kt,{children:[jsx(eo,{asChild:true,children:jsx(b$3,{className:a$4("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!u.value?.value&&"fk:text-muted-foreground",!u.value?.scope||u.value.scope==="default"?"fk:mb-3":""),disabled:a===false||u.value?.disabled,id:d,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:u.value?.value?format(new Date(u.value.value),"PPP")+" at "+format(new Date(u.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[u.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:m=>{m.stopPropagation(),f$1(m);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(bt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(xa,{mode:"single",selected:u.value?.value?new Date(u.value.value):void 0,onSelect:m=>c$1(m,u.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$6,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:m=>{let g=m.target.value,[p,h]=g.split(":"),y=u.value?.value?new Date(u.value.value):new Date;y.setHours(parseInt(p)),y.setMinutes(parseInt(h)),n(r,{...u.value,value:y.toISOString()});},type:"time",value:u.value?.value?format(new Date(u.value.value),"HH:mm"):""})]})]})]})}),jsx(b$2,{checked:u.value?.disabled??false,onChange:m=>{l(m,u.value);},scope:u.value?.scope}),jsx(i,{})]})})}function xe(e){return e??null}var Yn=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let o=xe(e);o&&o.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let o=xe(e);o&&o.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let o=xe(e);o&&o.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let o=document.createElement("input");o.type="file",o.accept="image/*",o.onchange=async()=>{o.files?.length;},o.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(o??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:o??""}).run():o!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let o=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(o??"")?e.chain().focus().deleteRange(t).setTweet({src:o??""}).run():o!==null&&alert("Please enter a correct Twitter Link");}}]),Sa=Command.configure({suggestion:{items:()=>Yn,render:renderItems}});var Ta=[{name:"Default",color:"var(--novel-black)"},{name:"Purple",color:"#9333EA"},{name:"Red",color:"#E00000"},{name:"Yellow",color:"#EAB308"},{name:"Blue",color:"#2563EB"},{name:"Green",color:"#008A00"},{name:"Orange",color:"#FFA500"},{name:"Pink",color:"#BA4081"},{name:"Gray",color:"#A8A29E"}],Na=[{name:"Default",color:"var(--novel-highlight-default)"},{name:"Purple",color:"var(--novel-highlight-purple)"},{name:"Red",color:"var(--novel-highlight-red)"},{name:"Yellow",color:"var(--novel-highlight-yellow)"},{name:"Blue",color:"var(--novel-highlight-blue)"},{name:"Green",color:"var(--novel-highlight-green)"},{name:"Orange",color:"var(--novel-highlight-orange)"},{name:"Pink",color:"var(--novel-highlight-pink)"},{name:"Gray",color:"var(--novel-highlight-gray)"}],Da=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ta.find(({color:i})=>o.isActive("textStyle",{color:i})),r=Na.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(Kt,{modal:true,open:e,onOpenChange:t,children:[jsx(eo,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:n?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(bt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),Ta.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:a},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),Na.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:a},children:"A"}),jsx("span",{children:i})]}),o.isActive("highlight",{color:a})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Tf(e){try{return new URL(e),!0}catch{return false}}function Nf(e){if(Tf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Ra=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:n}=useEditor();return useEffect(()=>{o.current?.focus();}),n?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$4("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":n.isActive("link")}),children:"Link"})]})}),jsx(bt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let a=i[0],s=Nf(a.value);s&&(n.chain().focus().setLink({href:s}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:o,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:n.getAttributes("link").href||""}),n.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{n.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var Ia=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleHeading({level:3}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=xe(e);t&&t.chain().focus().clearNodes().toggleBlockquote().run();},isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],$a=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let n=Ia.filter(r=>r.isActive(o)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:n.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:Ia.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),n.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var La=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:n}=e.state.selection,r=e.state.doc.textBetween(o,n);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$4("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var _a=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let n=xe(o);n&&n.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let n=xe(o);n&&n.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:o=>o!=null&&o.isActive("underline"),command:o=>o?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:o=>o!=null&&o.isActive("strike"),command:o=>{let n=xe(o);n&&n.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let n=xe(o);n&&n.chain().focus().toggleCode().run();},icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:n=>{o.command(n);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:n=>n.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a$4("fk:h-4 fk:w-4",{"fk:text-blue-500":o.isActive(e)})})})},o.name))}):null};function Co({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var Wf=()=>jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-0.5",children:[jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-500 [animation-delay:-0.3s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 [animation-delay:-0.15s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600"})]}),Oa=Wf;function or({completion:e,onDiscard:t$1}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r,{children:[jsxs(t,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:n}=o.view.state;o.chain().focus().insertContentAt({from:n.from,to:n.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(t,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:n}=o.view.state;o.chain().focus().insertContentAt(n.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s,{}),jsx(r,{children:jsxs(t,{onSelect:t$1,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var fd=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function rr({onSelect:e}){let{editor:t$1}=useEditor();return t$1?jsxs(Fragment,{children:[jsx(r,{heading:"Edit or review selection",children:fd.map(o=>jsxs(t,{onSelect:n=>{let r=t$1.state.selection.content(),i=t$1.storage.markdown.serializer.serialize(r.content);e(i,n);},className:"fk:flex fk:gap-2 fk:px-4",value:o.value,children:[jsx(o.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),o.label]},o.value))}),jsx(s,{}),jsx(r,{heading:"Use AI to do more",children:jsxs(t,{onSelect:()=>{let o=t$1.state.selection.from,n=getPrevText(t$1,o);e(n,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function Ba({onOpenChange:e}){let{editor:t}=useEditor(),[o$1,n]=useState(""),{projectId:r}=useParams(),{completion:i,complete:a,isLoading:s}=useCompletion({api:c$5(r).completion,fetch:async(c,l)=>{let f=await fetch(c,l);if(f.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return f},onError:c=>{c.message!=="FK_AI_RATE_LIMIT"&&toast.error(c.message);}}),d=i.length>0;return t?jsxs(m$2,{className:"fk:w-[350px]",children:[d&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(v,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(yd,{children:i})})})}),s&&jsxs("div",{className:"fk:flex fk:h-12 fk:w-full fk:items-center fk:px-4 fk:text-sm fk:font-medium fk:text-muted-foreground fk:text-pink-600",children:[jsx(Co,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 "}),"AI is thinking",jsx("div",{className:"fk:ml-2 fk:mt-1",children:jsx(Oa,{})})]}),!s&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o,{value:o$1,onValueChange:n,autoFocus:true,placeholder:d?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o$1}}).then(()=>n(""));let c=t.state.selection.content(),l=t.storage.markdown.serializer.serialize(c.content);a(l,{body:{option:"zap",command:o$1}}).then(()=>n(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p,{children:d?jsx(or,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(rr,{onSelect:(c,l)=>a(c,{body:{option:l}})})})]})]}):null}function ar({children:e,open:t,onOpenChange:o}){let{editor:n}=useEditor();return useEffect(()=>{n&&(t||removeAIHighlight(n));},[n,t]),n?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),n.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(Ba,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),o(true);},size:"sm",children:[jsx(Co,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Ld=[...a,Sa];function ja(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function _d(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(ja(o))return o}catch{return}}if(ja(e))return e}function sr({control:e$1,defaultValue:t,fieldSchema:o,setValue:n}){let{name:r,label:i$1,isEditable:a,options:s}=o,[d,c$1]=useState(false),[l,f$1]=useState(false),[u,m]=useState(false),[g$1,p]=useState(false),h$1=useDebouncedCallback((x,E)=>{let S=x.getJSON();n(r,{...E,value:JSON.stringify(S)});},300);function y(x,E){n(r,{...E,disabled:x});}let v=x=>(console.log("Image uploader not yet implemented",x),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:r,render:({field:x})=>jsxs(e,{children:[jsx(f,{children:i$1}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-screen-lg fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:a!==false&&!x.value?.disabled,editorProps:{handleDOMEvents:{keydown:(E,S)=>handleCommandNavigation(S)},handlePaste:(E,S)=>handleImagePaste(E,S,v),handleDrop:(E,S,b,A)=>handleImageDrop(E,S,A,v),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:Ld,initialContent:_d(x.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:E})=>{h$1(E,x.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Yn.map(E=>jsxs(EditorCommandItem,{value:E.title,onCommand:S=>E.command?.(S),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted",children:[jsx("div",{className:"fk:flex fk:h-10 fk:w-10 fk:items-center fk:justify-center fk:rounded-md fk:border fk:border-muted fk:bg-background",children:E.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:E.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:E.description})]})]},E.title))})]}),jsxs(ar,{open:d,onOpenChange:c$1,children:[jsx(g$3,{orientation:"vertical"}),jsx($a,{open:l,onOpenChange:f$1}),jsx(g$3,{orientation:"vertical"}),jsx(Ra,{open:u,onOpenChange:m}),jsx(g$3,{orientation:"vertical"}),jsx(La,{}),jsx(g$3,{orientation:"vertical"}),jsx(_a,{}),jsx(g$3,{orientation:"vertical"}),jsx(Da,{open:g$1,onOpenChange:p})]})]},`${r}:${x.value?.scope??t.scope}:${String(x.value?.disabled??t.disabled)}`)})}),jsx(b$2,{checked:x.value?.disabled??false,onChange:E=>{y(E,x.value);},scope:x.value?.scope}),jsx(i,{})]})})}var Od=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];async function Vd(e,t){let{projectId:o,accept:n,multiple:r=true,maxBytes:i=4*1024*1024}=e,a=document.createElement("input");a.type="file";let s=n??Od.join(",");a.accept=s,a.multiple=r,a.style.display="none",document.body.appendChild(a);try{let d=await new Promise(u=>{a.onchange=()=>u(a.files),a.click();});if(!d||d.length===0)return [];let c=[];for(let u of Array.from(d)){if(u.size>i){toast.error(`File size too big (max ${(i/(1024*1024)).toFixed(0)}MB): ${u.name}`);continue}c.push(u);}let l=c$5(o).upload,f=await Promise.all(c.map(async u=>{let m=await Bd(u),g=await fetch(l,{method:"POST",headers:{"Content-Type":u.type||"application/octet-stream"},body:u});if(!g.ok)throw new Error(`Upload failed for ${u.name}`);let p=await g.json(),h={pathname:p.pathname,lqip:p.lqip,originalFilename:u.name,size:u.size,mimeType:u.type,width:m?.width,height:m?.height},y=t?await t(h,o):zd(h);return {...h,_id:y._id,asset:y}}));return f.length>0&&toast.success(`Uploaded ${f.length} file${f.length>1?"s":""}`),f}catch(d){return console.error(d),toast.error("Upload failed. Please try again."),[]}finally{document.body.removeChild(a);}}async function Bd(e){return e.type.startsWith("image/")?new Promise(o=>{let n=new FileReader;n.onload=()=>{let r=new Image;r.onload=()=>{o({width:r.width,height:r.height});},r.onerror=()=>o(null),r.src=n.result;},n.onerror=()=>o(null),n.readAsDataURL(e);}):null}function Ao(){let e=Ki();return async t=>Vd(t,async o=>{let n={path:{_id:"",disabled:false,scope:"default",value:o.pathname},originalFilename:{_id:"",disabled:false,scope:"default",value:o.originalFilename},size:{_id:"",disabled:false,scope:"default",value:o.size},lqip:{_id:"",disabled:false,scope:"default",value:o.lqip},mimeType:{_id:"",disabled:false,scope:"default",value:o.mimeType},...typeof o.width=="number"?{width:{_id:"",disabled:false,scope:"default",value:o.width}}:{},...typeof o.height=="number"?{height:{_id:"",disabled:false,scope:"default",value:o.height}}:{}};return e(n)})}function zd(e){return {_id:"",path:e.pathname,originalFilename:e.originalFilename,size:e.size,mimeType:e.mimeType,lqip:e.lqip??"",width:e.width??0,height:e.height??0}}function ur({control:e$1,defaultValue:t,entityId:o,fieldSchema:n,setValue:r}){let{name:i$1,label:a,options:s,relationship:d}=n,{projectId:c$1}=useParams(),l=ie(),f$1=d$2(),{relationships:u}=c$2(),m=Ao(),g$1=useId(),p=useId(),h$1=useRef(null),y=useRef([]),v$1=useRef(null),x=useRef([]),E=useRef(""),[S,b]=useState(false),A=useMemo(()=>Zd(t.value),[t.value]),[N,_]=useState(A);Yt(h$1,b),useEffect(()=>{let F=Et(A);y.current=A.map(M=>M._id),x.current=[],_(M=>{let $=Et(M);return F===""&&$!==""&&E.current===$||$===F?M:(E.current=F,A)});},[A]),useEffect(()=>{let F=u[p]?.connect;if(!F)return;let M=F.map((R,P)=>Ja(R.value,R.sortOrder??P)).filter(R=>!!R),$=Et(M),w=Et(N),k=v$1.current;k===w&&$!==k||(v$1.current=null,$!==w&&_(M));},[p,u,N]),useEffect(()=>{let F=Et(N);if(E.current===F)return;let M=N.map((k,R)=>({_id:k._id,sortOrder:R,value:{...k,sortOrder:R}})),$=N.map(k=>k._id),w=x.current.filter(k=>!$.includes(k));E.current=F,f$1({type:"setRelationship",payload:{[p]:{connect:M,disconnect:w}}}),r(i$1,{...t,relationships:{connect:M,disconnect:w},value:N});},[f$1,t,i$1,p,N,r]);function B(F){F.preventDefault(),F.stopPropagation(),l({type:"EditRelationship",payload:{connectedEntitiesCount:N.length,entityName:d?.entity??"_asset",entityId:o,relationshipId:p,mode:"multiple",assetAccept:s?.accept}});}async function I(F){F.preventDefault(),F.stopPropagation();let M=await m({projectId:c$1,accept:s?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});_($=>{let w=new Set($.map(P=>P._id)),k=M.map((P,U)=>({...P.asset,sortOrder:$.length+U})).filter(P=>!w.has(P._id)),R=fr([...$,...k]);return v$1.current=Et(R),R});}function j(F){_(M=>{let $=fr(M.filter(w=>w._id!==F));return y.current.includes(F)&&!x.current.includes(F)&&(x.current=[...x.current,F]),v$1.current=Et($),$});}function q(F,M){_($=>{let w=$.findIndex(G=>G._id===F),k=w+M;if(w<0||k<0||k>=$.length)return $;let R=[...$],[P]=R.splice(w,1);if(!P)return $;R.splice(k,0,P);let U=fr(R);return v$1.current=Et(U),U});}return jsx(c,{control:e$1,defaultValue:t,name:i$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:g$1,children:a}),s?.comment?jsx(h,{children:s.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${i$1}`,"aria-expanded":S,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${S?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:F=>{F.preventDefault(),F.stopPropagation(),h$1.current?.focus(),b(true);},ref:h$1,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[S&&N.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[N.length," ",N.length===1?"asset":"assets"," selected"]}):N.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[N.slice(0,8).map(F=>jsx(Gd,{asset:F},F._id)),!S&&N.length>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",N.length-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image$1,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:g$1,onClick:F=>{F.preventDefault(),F.stopPropagation(),b(M=>!M);},size:"icon",variant:"ghost",children:S?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:S?"Close":"Expand field"})})]})})]}),jsx(Wt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:b,open:S,children:jsx(Zt,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${i$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",onClick:B,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",onClick:F=>{I(F);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),N.length>0?jsx(v,{className:"fk:min-h-0 fk:flex-1",children:jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:N.map((F,M)=>jsx(Wd,{asset:F,index:M,isFirst:M===0,isLast:M===N.length-1,moveAsset:q,removeAsset:j},F._id))})}):null]})})})]})})}),jsx(i,{})]})})}function Gd({asset:e}){return Qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image$1,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function Wd({asset:e,index:t,isFirst:o,isLast:n,moveAsset:r,removeAsset:i}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:Qa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image$1,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:o,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:n,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",onClick:()=>i(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Zd(e){return Array.isArray(e)?e.map((t,o)=>Ja(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Et(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function fr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Ja(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let o=e;return {_id:String(o._id??""),path:String(o.path??""),originalFilename:String(o.originalFilename??""),size:Number(o.size??0),mimeType:String(o.mimeType??""),lqip:String(o.lqip??""),width:Number(o.width??0),height:Number(o.height??0),sortOrder:o.sortOrder??t}}function Qa(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Ga({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function Do({attributesSchema:e,checkboxSelect:t,actionsComponent:o}){let{getContributionPointConfig:n}=d(),r={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"text",switch:"boolean",text:"text",textarea:"text"},i={boolean:a$a,date:a$9,datetime:a$c,editor:b$7,asset:a$b,number:a$9,relationship:a$9,select:a$9,switch:a$a,text:a$9,textarea:a$9,tags:Ga},a=e.map(l=>{let f=(l.inputType==="relationship"&&l.relationship?.entity==="_asset"?"asset":void 0)??l.previewType??r[l.inputType],u=n("previewFields",[f])?.[0]?.component??i[f]??i.text;if(l.isHidden)return null;let m=f==="tags";return {accessorKey:l.name,filterFn:(g,p,h)=>m?true:(Array.isArray(h)?h:[h]).includes(g.getValue(p)),header:()=>jsx("div",{className:"fk:flex fk:items-center",children:l.label}),cell:({row:g})=>jsx(u,{value:g.getValue(l.name)}),enableSorting:false,enableHiding:true,size:l.options?.size??150}}).filter(l=>l!==null),s={id:"actions",cell:({row:l})=>o?o(l):null,size:80},d$1={id:"select",cell:({row:l,table:f})=>jsx(a$d,{"aria-label":"Select row",checked:l.getIsSelected(),onCheckedChange:u=>{f.toggleAllPageRowsSelected(false),l.toggleSelected(!!u);}}),enableSorting:false,enableHiding:false,size:50},c={id:"select",header:({table:l})=>jsx(a$d,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:l.getIsAllPageRowsSelected()||l.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:f=>{l.toggleAllPageRowsSelected(!!f);}}),cell:({row:l})=>jsx(a$d,{"aria-label":"Select row",checked:l.getIsSelected(),onCheckedChange:f=>{l.toggleSelected(!!f);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[d$1]:[],...t==="multiple"?[c]:[],...o?[s]:[],...a]}function lu(e){if(!e)return;if(e.split(/\s+/).includes("fk:h-20"))return 80}function Po({classNames:e,columns:t,data:o,initialSelectionState:n$1,onEntitySelectionChange:r,onScroll:i,pageSize:a,rowHeightEstimate:s,rowAdditionState:d,rowDeletionState:c,toolbarComponent:l$1}){let f=useRef(null),{schemaErrorMessage:u}=Rt(),[m,g]=useState(n$1??{}),[p,h]=useState({}),[y,v]=useState([]),[x,E]=useState([]);useEffect(()=>{if(!n$1)return;let I=Object.keys(m).sort().join(","),j=Object.keys(n$1).sort().join(",");I!==j&&g(n$1);},[n$1,m]);let S=useReactTable({data:o,columns:t,state:{sorting:x,columnVisibility:p,rowSelection:m,columnFilters:y},initialState:{pagination:{pageSize:a??25}},enableRowSelection:true,onRowSelectionChange:B,onSortingChange:E,onColumnFiltersChange:v,onColumnVisibilityChange:h,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getFacetedRowModel:getFacetedRowModel(),getFacetedUniqueValues:getFacetedUniqueValues(),getRowId:I=>I._id,manualPagination:true,meta:{getRowBackground:I=>cu(I,c,d)}}),{rows:b}=S.getRowModel(),A=useVirtualizer({count:b.length,estimateSize:()=>s??lu(e?.row)??45,getScrollElement:()=>f.current,measureElement:typeof window<"u"&&navigator.userAgent.includes("Firefox")?I=>I.getBoundingClientRect().height:void 0,overscan:5}),N=A.getVirtualItems(),_=A.getTotalSize();function B(I){let j=Object.keys(typeof I=="function"?I(m):I);g(I),r?.(j);}return u?jsx(Fragment,{}):jsxs("div",{className:a$4("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:flex-col fk:gap-4",e?.wrapper),children:[l$1&&l$1(S),jsx("div",{className:"fk:min-h-0 fk:flex-1 fk:-mb-px",children:jsxs(h$2,{className:a$4("fk:grid fk:pb-20",e?.table),onScroll:i,ref:f,children:[jsx(i$1,{className:"fk:grid",children:S.getHeaderGroups().map(I=>jsx(l,{className:"fk:flex fk:w-full",children:I.headers.map(j=>jsx(m$1,{className:a$4("fk:flex fk:items-center",j.column.id==="actions"&&"fk:pl-0"),colSpan:j.colSpan,style:j.getSize()?{width:`${j.getSize().toString()}px`}:{},children:j.isPlaceholder?null:flexRender(j.column.columnDef.header,j.getContext())},j.id))},I.id))}),jsx(j,{className:"fk:grid fk:relative",style:{height:`${_.toString()}px`},children:N.length?N.map(I=>{let j=b[I.index];return jsx(l,{className:`${S.options.meta.getRowBackground(j)} fk:flex fk:absolute fk:w-full ${e?.row??""}`,"data-index":I.index,"data-state":j.getIsSelected()&&"selected",ref:A.measureElement,style:{transform:`translateY(${I.start.toString()}px)`},children:j.getVisibleCells().map(q=>jsx(n,{className:a$4("fk:flex fk:items-center fk:truncate",q.column.id==="actions"&&"fk:pl-0!"),style:{width:q.column.getSize()},children:flexRender(q.column.columnDef.cell,q.getContext())},q.id))},I.key)}):jsx(l,{children:jsx(n,{className:"fk:h-24 fk:text-center",colSpan:t.length,children:"No results."})})})]})})]})}function cu(e,t,o){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":o?.some(n=>n._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function Ya({action:e,row:t}){let o=t.original._id;function n(){e(o);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:n,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var xu=25;function gr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,entityName:r,entityNamePlural:i$1,fieldSchema:a,schema:s,scope:d,setValue:c$1}){let[l,f$1]=useState(false),u=useRef(null);Yt(u,f$1);let[m,g$1]=useState([]),{name:p,label:h$1,options:y,relationship:v}=a,x=v?.entity??p,E=ie(),S=d$2(),{relationships:b}=c$2(),A=useId(),N=useId(),_=find(propEq(x,"name"))(s),B=_?.attributes??[],j=find(propEq(r,"name"))(s)?.name??"",q,F=B.find(L=>L.relationship?.entity===j);F&&(q=F.name);let M=Su(B),$=useMemo(()=>o.value?Au({data:o.value,defaultScope:t,relationshipEntitySchema:_,scope:d}):[],[t,o,M,_,d]),w=Wi({attributeName:p,relatedEntityName:x,scope:d,schema:s}),k=m.length?m.slice(0,12).map(L=>L[M]):[],[R,{loading:P,data:U}]=useLazyQuery(gql`
382
+ ${w.query}
383
+ `),G=Do({attributesSchema:_?.attributes??[],actionsComponent:L=>Eu({appDispatch:S,relationshipId:N,relationships:b,row:L,setRows:g$1})});useEffect(()=>{g$1($),o.value!==""&&S({type:"setRelationship",payload:{[N]:{connect:[],disconnect:[]}}});},[S,U,$,N,o,d]),useEffect(()=>{c$1(p,{...o,relationships:b[N]});},[o,b,N,c$1,p]),useEffect(()=>{let _e=(b[N]?.connect??[]).map(({value:Oe})=>Oe);g$1(uniqBy(prop("_id"),[..._e,...$]));},[U,o.count,$,b,N]);let ae=useCallback(L=>{let _e=o.count??0;if(!L||_e===0||m.length===0)return;let{scrollHeight:Oe,scrollTop:bn,clientHeight:wn}=L;Oe-bn-wn<200&&!P&&m.length<_e&&R({variables:{limit:xu,offset:m.length,where:q?{[q]:{some:{_id:{eq:n}}}}:{}}}).then(({data:Ot})=>{if(!Ot)return;let Cn=Ko(_?.plural??"",d,Ot,s);g$1(uniqBy(prop("_id"),[...$,...Cn.results]));}).catch(Ot=>{console.error("Error fetching more data:",Ot);});},[q,o.count,n,R,$,P,_?.plural,m.length,s,d]);function lt(L){L.preventDefault(),E({type:"EditRelationship",payload:{connectedEntitiesCount:$.length,connectionName:q,entityName:x,entityId:n,relationshipId:N,mode:v?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:o,name:p,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:A,children:h$1}),y?.comment?jsx(h,{children:y.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.375rem] fk:pl-3 fk:pr-10 fk:py-0.5 fk:text-sm",children:jsxs("div",{"aria-controls":`relationship-dropdown-${p}`,"aria-expanded":l,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${l?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),u.current?.focus(),u.current?.click(),f$1(true);},onKeyDown:L=>{L.key==="Enter"&&f$1(true),L.key==="Escape"&&(L.preventDefault(),L.stopPropagation(),u.current?.blur(),f$1(false));},ref:u,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[l?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-2",onClick:lt,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",_?.menu?.label??_?.plural]}):jsx("span",{className:"fk:flex fk:flex-wrap fk:grow fk:pb-1.5",children:k.map(L=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",variant:"secondary",children:L},L))}),l?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:L=>{L.preventDefault(),L.stopPropagation(),u.current?.blur(),f$1(false);},onKeyDown:L=>{L.key==="Enter"&&(L.preventDefault(),L.stopPropagation(),u.current?.blur(),f$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:A,onKeyDown:L=>{L.key==="Enter"&&(u.current?.focus(),u.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]}),jsx(Wt,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:f$1,open:l,children:jsx(Zt,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:mt-3 fk:mb-2",id:`relationship-dropdown-${p}`,children:jsx(Po,{classNames:{table:"fk:max-h-[17.5rem]"},columns:G,data:m,entityName:r,onScroll:L=>{ae(L.target);},rowAdditionState:b[N]?.connect,rowDeletionState:b[N]?.disconnect})})})})]})}),jsx(i,{})]})})}function Eu({appDispatch:e,relationshipId:t,relationships:o,row:n,setRows:r}){function i(a){let s=o[t]?.connect??[],d=typeof find(propEq(a,"_id"),s)=="object",c=o[t]?.disconnect?.includes(a),l=d?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);d&&r(f=>f.filter(u=>u._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:s.filter(f=>f._id!==a),disconnect:c?o[t]?.disconnect?.filter(f=>f!==a)??[]:l}}});}return jsx(Ya,{action:i,row:n})}function Su(e){return e.find(t=>t.isPrimary)?.name??e[0]?.name}function Au({data:e,defaultScope:t,relationshipEntitySchema:o,scope:n}){if(!Array.isArray(e))return [];let r=i=>{let s=find(propEq(i.__typename,"name"))(o?.attributes??[])?.relationship?.field??"";if(s){let d=i[s],c=Array.isArray(d)?d[0]:d;return c&&typeof c=="object"?c[n]??c[t]??"":c}return i[n]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let s=a;return s.length===0?"":s.length===1?r(s[0]):s.slice(0,3).map(r).join(", ")}return a&&typeof a!="string"&&a.__typename?r(a):a},i))}function kr({control:e$1,defaultScope:t,defaultValue:o,entityId:n,fieldSchema:r,getValues:i$1,schema:a,scope:s,setValue:d}){let[c$1,l]=useState(false),{name:f$1,label:u,options:m,relationship:g$1}=r,p=g$1?.entity??f$1,h$1=ie(),y=d$2(),v=useId(),{relationships:x}=c$2(),E=useId(),S=find(propEq(p,"name"))(a),A=Fu(S?.attributes??[]).name;useEffect(()=>{o.value!==""&&y({type:"setRelationship",payload:{[E]:{connect:{_id:String(o._id),value:o.value},disconnect:[]}}});},[y,E,o,s]),useEffect(()=>{d(f$1,{...i$1(f$1),...x[E]?.connect??""});},[o,f$1,x,E,d]);function N(B){B.preventDefault(),h$1({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:p,entityId:n,relationshipId:E,mode:g$1?.mode??"single"}});}function _(B){let I={type:"setRelationship",payload:{[E]:{connect:[],disconnect:[]}}};B.preventDefault(),y(I),d(f$1,{...i$1(f$1),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:o,name:f$1,render:({field:B})=>{let I=B.value?.value,j="";if(I&&typeof I=="object"&&!Array.isArray(I)&&I[A]){let q=I[A],F=Array.isArray(q)?q[0]:q;typeof F=="string"?j=F:j=F?.[s]??F?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:v,children:u}),m?.comment?jsx(h,{children:m.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${c$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$6,{className:"fk:h-[2.375rem] fk:py-[0.4375rem] fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",id:v,onBlur:()=>{l(false);},onClick:N,onFocus:()=>{l(true);},onKeyDown:q=>{q.key==="Enter"&&N(q);},readOnly:true,type:"text",value:j}),j?jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:_,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$7,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:N,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i,{})]})}})}function Fu(e){return e.find(t=>t.isPrimary)??e[0]}function hr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(kr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(ur,{...e});let n={relationshipEntityName:t.relationship?.entity,...e};return jsx(gr,{...n})}return jsxs(ne,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(De,{children:"Error"}),jsx(re,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}function is({control:e$2,fieldSchema:t,setValue:o}){let{name:n,label:r,isEditable:i$1,options:a}=t;function s(c,l){let u=t.dataType==="int"&&!isNaN(Number(c))?Number(c):c;o(n,{...l,value:u});}function d(c,l){o(n,{...l,disabled:c});}return jsx(c,{control:e$2,name:n,render:({field:c})=>jsxs(e,{children:[jsx(f,{children:r}),a?.comment?jsx(h,{children:a.comment}):null,jsxs(a$5,{defaultValue:c.value?.value?String(c.value.value):void 0,disabled:i$1===false||c.value?.disabled,onValueChange:l=>{s(l,c.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:a?.placeholder})})}),jsx(e$1,{children:a?.list?.map(l=>"groupLabel"in l?jsxs(b$1,{children:[jsx(f$1,{children:l.groupLabel}),l.items.map(f=>jsx(g$1,{value:f.value,children:f.label},f.label))]},l.groupLabel):jsx(g$1,{value:l.value,children:l.label},l.label))})]}),jsx(b$2,{checked:c.value?.disabled??false,onChange:l=>{d(l,c.value);},scope:c.value?.scope}),jsx(i,{})]})})}function br({inputType:e,label:t}){return jsxs(ne,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(De,{children:"Error"}),jsx(re,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}function Xu({currentScope:e,defaultScope:t,entityId:o,entityName:n,entityNamePlural:r,formData:i,schema:a,setIsDirty:s,onSubmit:d$1},c){let l=find(propEq(n,"name"))(a),f=useMemo(()=>l?.attributes??[],[l]),u=useMemo(()=>z.object(f.reduce((b,A)=>typeof A.validation>"u"?b:{...b,[A.name]:z.object({value:A.validation(z).or(z.any().refine(()=>false,{message:A.label?`${A.label} is required`:"Required field"}))})},{})),[f]),m=useForm({resolver:zodResolver(u),values:i,mode:"onBlur",criteriaMode:"all"}),{control:g,getValues:p,handleSubmit:h,setValue:y,watch:v,trigger:x}=m,{getContributionPointConfig:E}=d(),S={datetime:Ea,editor:sr,asset:ba,number:wa,relationship:hr,select:is,switch:a$3,text:a$2,textarea:a$1};return useImperativeHandle(c,()=>({submit(){x().then(()=>{h(()=>{s(false),d$1(p(),i);})();});},hasErrors(){s(true);},hasDataChanged(){return ss(p(),i)}})),useEffect(()=>{let b=v(A=>{s(ss(A,i));});return ()=>{b.unsubscribe();}},[i,s,v]),!l||l.attributes.length===0?jsxs(ne,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Error"}),jsxs(re,{children:["No attributes found in the schema for entity ",jsx("strong",{children:n})]})]}):jsx(b,{...m,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-y-5",children:f.map(b=>{if(b.name==="_id")return null;let A=E("formFields",[b.inputType])?.[0]?.component??S[b.inputType];return A?createElement(A,{key:b.name,control:g,defaultScope:t,defaultValue:i?i[b.name]:{value:"",disabled:false,scope:t},entityId:o,entityName:n,entityNamePlural:r,fieldSchema:b,getValues:p,schema:a,scope:e,setValue:y}):jsx(br,{inputType:b.inputType,label:b.label},b.name)})})})}var kn=memo(forwardRef(Xu));function ss(e,t){if(!t)return Object.keys(e).some(a=>e[a]?.value!==""&&e[a]?.value!==void 0);let o=a=>typeof a=="object"&&a!==null?"path"in a?a.path:"_id"in a?a._id:"":a??"",n=(a,s)=>a<s?-1:1,r=Object.keys(t).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(t[s].value),disabled:t[s].disabled,relationships:t[s].relationships}}),{}),i=Object.keys(e).sort((a,s)=>n(a,s)).filter(a=>a!=="_updatedAt").reduce((a,s)=>({...a,[s]:{value:o(e[s]?.value),disabled:e[s]?.disabled??false,relationships:Object.keys(e[s]?.relationships?.connect??{}).length||e[s]?.relationships?.disconnect?.length?e[s]?.relationships:void 0}}),{});return !equals(r,i)}function xr({action:e,depth:t,isFocused:o}){let{entityName:n}=e.payload,r=useRef(null),{projects:i,currentProjectId:a}=d(),{schema:s,scopes:d$1}=find(propEq(a??"","projectId"))(i),c=d$1?.find(A=>A.isDefault)?.name??"default",f=find(propEq(n,"name"))(s)?.plural??n,{scope:u}=c$2(),m=ie(),[g,p,h,y]=rt(),{setIsDirty:v}=Gt();useEffect(()=>{y.error&&r.current?.hasErrors();},[y.error]);function x(){return r.current?.hasDataChanged()?(m({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{m({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{m({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true}let E=useCallback(A=>{m({type:"Dismiss",_id:A,payload:{}});},[m]),S=useCallback(()=>{r.current?.submit();},[r]),b=useCallback(A=>{let N=v4(),_=qn(f,s,A,N),B=It(f,u,s),I=gql`
384
+ ${B.query}
384
385
  `;p(gql`
385
- ${B}
386
- `),h({refetchQueries:[F],onCompleted:()=>{A(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,l,A,g,s,p,d$1,h]);return jsx(Rt,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",onClick:()=>{S();},variant:"default",children:[y.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]}),beforeClose:x,depth:t,isFocused:o,onClose:()=>{A(e._id);},title:`Add ${n}`,children:jsx(pn,{currentScope:d$1,defaultScope:u,entityName:n,entityNamePlural:l,onSubmit:b,ref:r,schema:s,setIsDirty:v})})}function Ro({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r}){let[i,a]=useState({count:0,results:[]}),s=Nt(e,o,t),{schemaErrorMessage:f,setSchemaErrorMessage:u}=Tt(),{loading:c,data:l,fetchMore:d,error:m}=useQuery(gql`
386
+ ${_}
387
+ `),h({refetchQueries:[I],onCompleted:()=>{E(e._id),toast.success("Your changes have been saved.");}}),g(true);},[e._id,f,E,g,s,p,u,h]);return jsx(Mt,{actions:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",onClick:()=>{S();},variant:"default",children:[y.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]}),beforeClose:x,depth:t,isFocused:o,onClose:()=>{E(e._id);},title:`Add ${n}`,children:jsx(kn,{currentScope:u,defaultScope:c,entityName:n,entityNamePlural:f,onSubmit:b,ref:r,schema:s,setIsDirty:v})})}function Ro({entityNamePlural:e,schema:t,scope:o,variables:n,isForm:r}){let[i,a]=useState({count:0,results:[]}),s=It(e,o,t),{schemaErrorMessage:d,setSchemaErrorMessage:c}=Rt(),{loading:l,data:f,fetchMore:u,error:m}=useQuery(gql`
387
388
  ${s.query}
388
- `,{variables:n}),g=At(m),p=Wo(m),{isProjectDisabled:h,isProjectReadOnly:y}=(()=>{if(g?.statusCode===403){let A=St(g.bodyText);if(A&&typeof A.code=="string"){if(A.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(A.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),v=useCallback(()=>ds({data:l,entityNamePlural:e,isForm:r,schema:t,scope:o}),[l,e,r,t,o]);function x(A){d(A).then(({data:S})=>{let b=ds({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});a(E=>({count:b.count,results:uniqBy(prop("_id"),[...E.results,...b.results])}));}).catch(S=>{console.error("Error fetching more data:",S);});}return useEffect(()=>{if(p){u(p);return}l&&f&&!m&&u(null);},[l,m,f,p,u]),useEffect(()=>{m||p||a(v);},[m,v,p]),{isLoading:c,fetchMore:x,count:i.count,data:i.results,isProjectDisabled:h,isProjectReadOnly:y,schemaErrorMessage:f}}function ds(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Ji(e.entityNamePlural,e.scope,e.data,e.schema):Ko(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function ms(){return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Read Only Mode"}),jsxs(ie,{children:["This project is currently in read only mode and changes cannot be saved. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/read-only-mode",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function Cr({handleSave:e,isLoading:t}){let{isDirty:o}=qt();return jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}function xr(){return jsx(Fragment,{children:Array.from({length:10},(t,o)=>o++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$1,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(r$1,{className:"fk:w-5 fk:mr-2"}),jsx(r$1,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function Sr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:f,scopes:u}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),c=u?.find(R=>R.isDefault)?.name??"default",l=find(propEq(r,"plural"))(f),d$3=l?.name??r,{scope:m}=c$2(),[g,p]=useState(m),h=ae(),y=d$2(),[v,x,A,S]=tt(),{setIsDirty:b}=qt(),E=useCallback(R=>{b(R);},[b]);useEffect(()=>{S.error&&i.current?.hasErrors();},[S.error]);let D=useCallback(()=>i.current?.hasDataChanged()?(h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[h,e._id]),B=useCallback(R=>{h({type:"Dismiss",_id:R,payload:{}});},[h]),z=useCallback(()=>{i.current?.submit();},[i]);function F(R){if(i.current?.hasDataChanged()){h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{p(g),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}}}});return}p(R),y({type:"setScope",payload:{projectId:s,scope:R}});}let H=useCallback((R,q)=>{if(!q)return;let G=Ln(r,n,g,f,q,R),ne=Nt(r,g,f),qe=gql`
389
- ${ne.query}
389
+ `,{variables:n}),g=Dt(m),p=Go(m),{isProjectDisabled:h,isProjectReadOnly:y}=(()=>{if(g?.statusCode===403){let E=Pt(g.bodyText);if(E&&typeof E.code=="string"){if(E.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(E.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})(),v=useCallback(()=>ms({data:f,entityNamePlural:e,isForm:r,schema:t,scope:o}),[f,e,r,t,o]);function x(E){u(E).then(({data:S})=>{let b=ms({data:S,entityNamePlural:e,isForm:r,schema:t,scope:o});a(A=>({count:b.count,results:uniqBy(prop("_id"),[...A.results,...b.results])}));}).catch(S=>{console.error("Error fetching more data:",S);});}return useEffect(()=>{if(p){c(p);return}f&&d&&!m&&c(null);},[f,m,d,p,c]),useEffect(()=>{m||p||a(v);},[m,v,p]),{isLoading:l,fetchMore:x,count:i.count,data:i.results,isProjectDisabled:h,isProjectReadOnly:y,schemaErrorMessage:d}}function ms(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?Xi(e.entityNamePlural,e.scope,e.data,e.schema):Ko(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function gs(){return jsxs(ne,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Read Only Mode"}),jsxs(re,{children:["This project is currently in read only mode and changes cannot be saved. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/read-only-mode",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function Sr({handleSave:e,isLoading:t}){let{isDirty:o}=Gt();return jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}function Ar(){return jsx(Fragment,{children:Array.from({length:10},(t,o)=>o++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$1,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(r$1,{className:"fk:w-5 fk:mr-2"}),jsx(r$1,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function Dr({action:e,depth:t,isFocused:o}){let{entityId:n,entityNamePlural:r}=e.payload,i=useRef(null),{projects:a,currentProjectId:s}=d(),{schema:d$3,scopes:c}=useCallback(()=>find(propEq(s??"","projectId"))(a),[s,a])(),l=c?.find(P=>P.isDefault)?.name??"default",f=find(propEq(r,"plural"))(d$3),u=f?.name??r,{scope:m}=c$2(),[g,p]=useState(m),h=ie(),y=d$2(),[v,x,E,S]=rt(),{setIsDirty:b}=Gt(),A=useCallback(P=>{b(P);},[b]);useEffect(()=>{S.error&&i.current?.hasErrors();},[S.error]);let N=useCallback(()=>i.current?.hasDataChanged()?(h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:e._id,payload:{}});}}}}),false):true,[h,e._id]),_=useCallback(P=>{h({type:"Dismiss",_id:P,payload:{}});},[h]),B=useCallback(()=>{i.current?.submit();},[i]);function I(P){if(i.current?.hasDataChanged()){h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{p(g),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{p(P),y({type:"setScope",payload:{projectId:s,scope:P}});}}}});return}p(P),y({type:"setScope",payload:{projectId:s,scope:P}});}let j=useCallback((P,U)=>{if(!U)return;let G=Vn(r,n,g,d$3,U,P),ae=It(r,g,d$3),lt=gql`
390
+ ${ae.query}
390
391
  `;x(gql`
391
392
  ${G}
392
- `),A({variables:{where:{_id:n}},refetchQueries:[{query:qe,variables:{where:{_id:n}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),v(true);},[g,n,r,v,f,x,A]),{isLoading:te,data:I}=Ro({entityNamePlural:r,schema:f,scope:g,variables:{where:{_id:n}},isForm:true}),M=I,L=M.length>0,w=te&&!L;function k(R,q){let G=R?.attributes.find(ao=>ao.isPrimary)??R?.attributes[0],ne=G.name,qe=G?.relationship?.field!==void 0;return q.length?qe&&G?.relationship?.field?q[0][ne]?.value?.[G.relationship.field]:q[0][ne]?.value:""}let P=L&&l?k(l,M):"";return jsx(Rt,{actions:jsxs(Fragment,{children:[u&&u.length>1?jsxs(a$5,{onValueChange:R=>{F(R);},value:g,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(g,"name"))(u).label})]}),jsx(e$1,{children:u.map(R=>jsx(g$1,{value:R.name,children:R.label},R.name))})]}):null,jsx(Cr,{handleSave:z,isLoading:S.loading})]}),beforeClose:D,depth:t,isFocused:o,onClose:()=>{B(e._id);},onFormChange:()=>{},title:P,children:w||!L?jsx(xr,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(ms,{}):null,jsx(pn,{currentScope:g,defaultScope:c,entityId:n,entityName:d$3,entityNamePlural:r,formData:M[0],onSubmit:H,ref:i,schema:f,setIsDirty:E})]})})}var bs=25;function gm(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Nr({action:e,depth:t,isFocused:o}){let n=ae(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:f,connectionName:u,entityId:c,entityName:l,initialAssetPath:d$1,initialConnection:m,mode:g,relationshipId:p}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:v}=find(propEq(y??"","projectId"))(h),x=find(propEq(l,"name"))(v),A=x?.plural??"",S=i[p],b=Eo(),E=l==="_asset",D=E?"asset":x?.menu?.label??l.toLowerCase(),B=E&&g==="single"?"Select asset":`Select ${E?"assets":D}`,z=g==="single"?"Upload asset":"Upload assets",[F,H]=useState([]),te=[];if(m)te=[{id:m._id,value:m.value}];else if(S?.connect){let $=S.connect;te=[{id:$._id,value:$.value}];}let I=g==="single"?te:S?.connect?.map($=>({id:$._id,value:$.value}))||[],[M,L]=useState(I),w=useMemo(()=>{let $=u?{[u]:{node:{_id:c}}}:{},U=E?{NOT:{path:null}}:{};return g==="multiple"?{...U,...$,OR:F}:{...U,OR:F}},[u,c,E,g,F]),{count:k,data:P,fetchMore:R,isLoading:q}=Ro({entityNamePlural:A,schema:v,scope:a,variables:{options:{offset:0,limit:bs},where:w}}),G=!!P?.length,ne=q&&!G,qe=To({attributesSchema:x?.attributes??[],checkboxSelect:g}),ao=Array(5).fill({}),yn=gm(qe);useEffect(()=>{if(g!=="single"||M.length>0||!d$1||!P?.length)return;let $=P.find(U=>U.path===d$1);!$?._id||typeof $._id!="string"||L([{id:$._id,value:$}]);},[P,d$1,g,M.length]);let $o=useCallback($=>{n({type:"Dismiss",_id:$,payload:{}});},[n]),_=useCallback($=>{let U=P?.length??0,Fe=k-f;if($&&Fe>0&&U>0){let{scrollHeight:it,scrollTop:K,clientHeight:wn}=$;it-K-wn<500&&!q&&U<Fe&&R({variables:{options:{offset:U,limit:bs},where:w}});}},[w,f,k,P?.length,R,q]);function Mt(){let $;if(g==="single"){let[U]=M;$={_id:U?.id??"",value:U?.value??null};}g==="multiple"&&($=M?.map((U,Fe)=>({_id:U.id??"",...E?{sortOrder:Fe}:{},value:U.value}))),r({type:"setRelationship",payload:{[p]:{connect:$,disconnect:S?.disconnect??[]}}}),$o(e._id);}function so($){if(g==="multiple"){L(Fe=>{let it=new Map(Fe.map(K=>[K.id,K]));return $.map(K=>{if(it.has(K))return it.get(K);let wn=P?.find(Ps=>Ps._id===K);return {id:K,value:wn}})});return}let U=$[$.length-1];L(U?Fe=>{if(Fe.length===1&&Fe[0].id===U)return Fe;let it=P?.find(K=>K._id===U);return [{id:U,value:it}]}:[]);}function vn(){n({type:"AddEntity",payload:{entityName:l}});}async function bn(){let $=await b({projectId:y,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});L(U=>{if(g==="single"){let[K]=$;return K?[{id:K._id,value:K.asset}]:U}let Fe=new Set(U.map(K=>K.id)),it=$.filter(K=>!Fe.has(K._id)).map(K=>({id:K._id,value:K.asset}));return [...U,...it]});}return jsx(Rt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Mt();},variant:"default",children:"Select"}),E?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{vn();},variant:"outline",children:`Create ${D}`}),E?jsxs(b$3,{className:"fk:px-8",onClick:()=>{bn();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),z]}):null]}),depth:t,isFocused:o,onClose:()=>{$o(e._id);},title:B,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Do,{columns:ne?yn:qe,data:ne?ao:P??[],entityName:x?.name??"",initialSelectionState:M?.reduce(($,U)=>({...$,...U.id?{[U.id]:true}:{}}),{}),onEntitySelectionChange:so,onScroll:$=>{_($.target);},toolbarComponent:()=>jsx(km,{entityNamePlural:A,projectId:y??"",setSearchResultIds:H})})})})}function km({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:f,isLoading:u}=e$5(t,a),c=useRef(null),l=useMemo(()=>hm(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(f){let m=JSON.stringify(f.map(p=>p._id).sort()),g=c.current?JSON.stringify(c.current.map(p=>p._id).sort()):"";m!==g&&(c.current=[...f],o(f.map(p=>({_id:p._id}))));}},[f,o]);function d(m){let{value:g}=m.target;r(g),l(g);}return jsxs("div",{className:"fk:relative fk:w-full",children:[u?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$6,{className:"fk:w-full fk:pl-11!",onChange:d,placeholder:"Search",value:n})]})}function hm(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Cs(){let e=zi(),t=e.filter(n=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===n.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(n=>{switch(n.type){case "AlertDialog":{let{payload:r}=n;return jsx(po,{options:r.options},n._id)}case "DeleteEntity":return jsx(Un,{action:n},n._id);case "AddEntity":return jsx(br,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Sr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(Nr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function xs({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$f(o);return window.location.pathname===r&&(window.location.href=b$b(r,n)),jsx(a$i,{children:jsx(c$6,{config:e,children:jsxs(Si,{children:[jsx(la,{children:jsx(Cs,{})}),jsx(Outlet,{})]})})})}function Es(){let e=useRouteError(),t=new Date().getFullYear();function o(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):Pn(e)?ui(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:o()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(qo,{})]})})]})}function Rr(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Error"}),jsx(ie,{children:t})]})}var Fm=RouterProvider;function Im({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(c=>As(c)):[As(e)],[i]=r,a=a$f(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let f=[{path:a,element:jsx(xs,{config:r}),errorElement:jsx(Es,{}),children:[{path:":projectId",element:jsx(vi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(c=>({path:c.name,element:c.component,errorElement:jsx(Rr,{}),children:c.routes?.map(l=>({path:l.path,element:l.component,errorElement:jsx(Rr,{}),children:l.children?.map(d=>({path:d.path,element:d.component}))}))}))}]}],u=createBrowserRouter(f);return n("Init Studio"),jsx(a$g,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Bi,{children:jsx(Fm,{router:u})})})})}function As(e){return {basePath:a$f(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function $m(){return jsxs(re,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Project Paused"}),jsxs(ie,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function _m(){let{schemaErrorMessage:e}=Tt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
393
- `);return jsxs(re,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Te,{children:"Schema mismatch"}),jsxs(ie,{children:[jsx("p",{children:t}),o?jsx("p",{className:"fk:mt-1",children:o}):null,n.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:n.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function Vm(e){return e}function Bm(e){return e}function Hm({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(Gt,{children:[jsx(Wt,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk:h-8 fk:border-dashed",children:[jsx(CirclePlus,{className:"fk:mr-2 fk:h-4 fk:w-4"}),t$1,r$1?.size>0&&jsxs(Fragment,{children:[jsx(g$3,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:r$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[r$1.size," selected"]}):o$1.filter(i=>r$1.has(i.value)).map(i=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:i.label},i.value))})]})]})}),jsx(kt,{className:"fk:w-[200px] fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(i=>{let a=r$1.has(i.value);return jsxs(t,{onSelect:()=>{a?r$1.delete(i.value):r$1.add(i.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$4("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",a?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),i.icon&&jsx(i.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:i.label}),n?.get(i.value)&&jsx("span",{className:"fk:ml-auto fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:font-mono fk:text-xs",children:n.get(i.value)})]},i.value)})}),r$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function Qm({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=ae(),i=o.original._id;function a(){r({type:"EditEntity",payload:{entityId:i,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:i,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[n.canEdit&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:a,variant:"ghost",children:[jsx(Pencil,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),n.canDelete&&!n.canEdit&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:s,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),n.canEdit&&n.canDelete&&jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Additional actions"})]})}),jsxs(f$2,{align:"end",className:"w-[160px]",children:[jsx(h$1,{onClick:a,children:"Edit"}),jsx(m,{}),jsx(h$1,{onClick:s,children:"Delete"})]})]})]})}function Mr({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function Km({entityName:e,table:t}){let o=ae(),n=d$2(),r=c$2(),{projects:i,currentProjectId:a}=d(),{scopes:s}=find(propEq(a??"","projectId"))(i),[f,u,c]=tt(),[l,d$3]=useState(false),m=t.getSelectedRowModel().rows.map(v=>v.original._id);function g(){o({type:"AddEntity",payload:{entityName:e}});}function p(v){n({type:"setScope",payload:{projectId:a,scope:v}});}async function h(v){let{schema:x}=find(propEq(a??"","projectId"))(i),A=yo(e,x,v);await new Promise(S=>{u(gql`
394
- ${A}
395
- `),c({variables:{where:{_id:v}},update(b){b.evict({id:v});},onCompleted:()=>{S();}}),f(true);});}function y(){let v=e==="_asset"?"asset":e.toLowerCase();o({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${m.length} ${v}${m.length>1?"s":""}`,dialogMessage:m.length>1?`Are you sure you want to delete the selected ${v}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${v}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{d$3(true);try{for(let x of m)await h(x);t.resetRowSelection(),toast.success(m.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{d$3(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[s&&s.length>0?jsxs(a$5,{defaultValue:r.scope,onValueChange:v=>{p(v);},value:r.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(e$1,{children:s.map(v=>jsx(g$1,{value:v.name,children:v.label},v.name))})]}):null,jsx(Mr,{table:t})]}),m.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:l,onClick:y,size:"sm",variant:"destructive",children:[l?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",m.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:l,onClick:g,size:"sm",variant:"default",children:"Create"})]})}export{Do as DataTable,Hm as DataTableFacetedFilter,Qm as DataTableRowActions,Km as DataTableToolbar,Mr as DataTableViewOptions,Im as FlexkitStudio,$m as ProjectDisabled,_m as SchemaError,Vm as defineConfig,Bm as defineEntity,zn as getEntityCreateMutation,yo as getEntityDeleteMutation,Nt as getEntityQuery,Pt as getEntitySchema,Ln as getEntityUpdateMutation,ae as useDispatch,tt as useEntityMutation,Ro as useEntityQuery,Tt as useGraphQLError,To as useGridColumnsDefinition,Eo as useUploadAssets};//# sourceMappingURL=index.js.map
393
+ `),E({variables:{where:{_id:{eq:n}}},refetchQueries:[{query:lt,variables:{where:{_id:{eq:n}}}}],onCompleted:()=>{toast.success("Your changes have been saved.");}}),v(true);},[g,n,r,v,d$3,x,E]),{isLoading:q,data:F}=Ro({entityNamePlural:r,schema:d$3,scope:g,variables:{where:{_id:{eq:n}}},isForm:true}),M=F,$=M.length>0,w=q&&!$;function k(P,U){let G=P?.attributes.find(Oe=>Oe.isPrimary)??P?.attributes[0],ae=G.name,lt=G?.relationship?.field!==void 0;if(!U.length)return "";if(!lt||!G?.relationship?.field)return U[0][ae]?.value;let L=U[0][ae]?.value?.[G.relationship.field],_e=Array.isArray(L)?L[0]:L;if(_e&&typeof _e=="object"){let Oe=_e;return Oe[g]??Oe.default??""}return _e??""}let R=$&&f?k(f,M):"";return jsx(Mt,{actions:jsxs(Fragment,{children:[c&&c.length>1?jsxs(a$5,{onValueChange:P=>{I(P);},value:g,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(g,"name"))(c).label})]}),jsx(e$1,{children:c.map(P=>jsx(g$1,{value:P.name,children:P.label},P.name))})]}):null,jsx(Sr,{handleSave:B,isLoading:S.loading})]}),beforeClose:N,depth:t,isFocused:o,onClose:()=>{_(e._id);},onFormChange:()=>{},title:R,children:w||!$?jsx(Ar,{}):jsxs(Fragment,{children:[S.isProjectReadOnly?jsx(gs,{}):null,jsx(kn,{currentScope:g,defaultScope:l,entityId:n,entityName:u,entityNamePlural:r,formData:M[0],onSubmit:j,ref:i,schema:d$3,setIsDirty:A})]})})}var Cs=25;function bm(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Fr({action:e,depth:t,isFocused:o}){let n=ie(),r=d$2(),{relationships:i,scope:a}=c$2(),{assetAccept:s,connectedEntitiesCount:d$1,connectionName:c,entityId:l,entityName:f,initialAssetPath:u,initialConnection:m,mode:g,relationshipId:p}=e.payload,{projects:h,currentProjectId:y}=d(),{schema:v}=find(propEq(y??"","projectId"))(h),x=find(propEq(f,"name"))(v),E=x?.plural??"",S=i[p],b=Ao(),A=f==="_asset",N=A?"asset":x?.menu?.label??f.toLowerCase(),_=A&&g==="single"?"Select asset":`Select ${A?"assets":N}`,B=g==="single"?"Upload asset":"Upload assets",[I,j]=useState([]),q=[];if(m)q=[{id:m._id,value:m.value}];else if(S?.connect){let z=S.connect;q=[{id:z._id,value:z.value}];}let F=g==="single"?q:S?.connect?.map(z=>({id:z._id,value:z.value}))||[],[M,$]=useState(F),w=useMemo(()=>{let z=c?{[c]:{none:{_id:{eq:l}}}}:{},J=A?{NOT:{path:{eq:null}}}:{},Ee={OR:I.map(je=>({_id:{eq:je._id}}))};return g==="multiple"?{...J,...z,...Ee}:{...J,...Ee}},[c,l,A,g,I]),{count:k,data:R,fetchMore:P,isLoading:U}=Ro({entityNamePlural:E,schema:v,scope:a,variables:{offset:0,limit:Cs,where:w}}),G=!!R?.length,ae=U&&!G,lt=Do({attributesSchema:x?.attributes??[],checkboxSelect:g}),L=Array(5).fill({}),_e=bm(lt);useEffect(()=>{if(g!=="single"||M.length>0||!u||!R?.length)return;let z=R.find(J=>J.path===u);!z?._id||typeof z._id!="string"||$([{id:z._id,value:z}]);},[R,u,g,M.length]);let Oe=useCallback(z=>{n({type:"Dismiss",_id:z,payload:{}});},[n]),bn=useCallback(z=>{let J=R?.length??0,Ee=k-d$1;if(z&&Ee>0&&J>0){let{scrollHeight:je,scrollTop:ee,clientHeight:xn}=z;je-ee-xn<500&&!U&&J<Ee&&P({variables:{offset:J,limit:Cs,where:w}});}},[w,d$1,k,R?.length,P,U]);function wn(){let z;if(g==="single"){let[J]=M;z={_id:J?.id??"",value:J?.value??null};}g==="multiple"&&(z=M?.map((J,Ee)=>({_id:J.id??"",...A?{sortOrder:Ee}:{},value:J.value}))),r({type:"setRelationship",payload:{[p]:{connect:z,disconnect:S?.disconnect??[]}}}),Oe(e._id);}function Ot(z){if(g==="multiple"){$(Ee=>{let je=new Map(Ee.map(ee=>[ee.id,ee]));return z.map(ee=>{if(je.has(ee))return je.get(ee);let xn=R?.find($s=>$s._id===ee);return {id:ee,value:xn}})});return}let J=z[z.length-1];$(J?Ee=>{if(Ee.length===1&&Ee[0].id===J)return Ee;let je=R?.find(ee=>ee._id===J);return [{id:J,value:je}]}:[]);}function Cn(){n({type:"AddEntity",payload:{entityName:f}});}async function Is(){let z=await b({projectId:y,accept:s??"image/*",multiple:g==="multiple",maxBytes:4194304});$(J=>{if(g==="single"){let[ee]=z;return ee?[{id:ee._id,value:ee.asset}]:J}let Ee=new Set(J.map(ee=>ee.id)),je=z.filter(ee=>!Ee.has(ee._id)).map(ee=>({id:ee._id,value:ee.asset}));return [...J,...je]});}return jsx(Mt,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{wn();},variant:"default",children:"Select"}),A?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{Cn();},variant:"outline",children:`Create ${N}`}),A?jsxs(b$3,{className:"fk:px-8",onClick:()=>{Is();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),B]}):null]}),depth:t,isFocused:o,onClose:()=>{Oe(e._id);},title:_,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(Po,{columns:ae?_e:lt,data:ae?L:R??[],entityName:x?.name??"",initialSelectionState:M?.reduce((z,J)=>({...z,...J.id?{[J.id]:true}:{}}),{}),onEntitySelectionChange:Ot,onScroll:z=>{bn(z.target);},toolbarComponent:()=>jsx(wm,{entityNamePlural:E,projectId:y??"",setSearchResultIds:j})})})})}function wm({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[n,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,s]=useState(i),{results:d,isLoading:c}=e$5(t,a),l=useRef(null),f=useMemo(()=>Cm(m=>{s({...i,commonParams:{q:m}});},300),[i]);useEffect(()=>{if(d){let m=JSON.stringify(d.map(p=>p._id).sort()),g=l.current?JSON.stringify(l.current.map(p=>p._id).sort()):"";m!==g&&(l.current=[...d],o(d.map(p=>({_id:p._id}))));}},[d,o]);function u(m){let{value:g}=m.target;r(g),f(g);}return jsxs("div",{className:"fk:relative fk:w-full",children:[c?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$6,{className:"fk:w-full fk:pl-11!",onChange:u,placeholder:"Search",value:n})]})}function Cm(e,t=300){let o;return (...n)=>{clearTimeout(o),o=setTimeout(()=>e(...n),t);}}function Es(){let e=qi(),t=e.filter(n=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===n.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(n=>{switch(n.type){case "AlertDialog":{let{payload:r}=n;return jsx(ko,{options:r.options},n._id)}case "DeleteEntity":return jsx(Qn,{action:n},n._id);case "AddEntity":return jsx(xr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditEntity":return jsx(Dr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);case "EditRelationship":return jsx(Fr,{action:n,depth:t.length-1,isFocused:n._id===o},n._id);default:return null}})})}function Ss({config:e}){let[t]=e,{basePath:o,projectId:n}=t,r=a$f(o);return window.location.pathname===r&&(window.location.href=b$b(r,n)),jsx(a$i,{children:jsx(c$6,{config:e,children:jsxs(Di,{children:[jsx(fa,{children:jsx(Es,{})}),jsx(Outlet,{})]})})})}function As(){let e=useRouteError(),t=new Date().getFullYear();function o(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):Fn(e)?gi(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:o()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(qo,{})]})})]})}function $r(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ne,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Error"}),jsx(re,{children:t})]})}var _m=RouterProvider;function Om({config:e}){let[t,o]=useState(false),n=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(l=>Ts(l)):[Ts(e)],[i]=r,a=a$f(i?.basePath),s=e$4(r);if(useEffect(()=>{o(true);},[]),!t)return null;let d=[{path:a,element:jsx(Ss,{config:r}),errorElement:jsx(As,{}),children:[{path:":projectId",element:jsx(Ci,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:s.map(l=>({path:l.name,element:l.component,errorElement:jsx($r,{}),children:l.routes?.map(f=>({path:f.path,element:f.component,errorElement:jsx($r,{}),children:f.children?.map(u=>({path:u.path,element:u.component}))}))}))}]}],c=createBrowserRouter(d);return n("Init Studio"),jsx(a$g,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Hi,{children:jsx(_m,{router:c})})})})}function Ts(e){return {basePath:a$f(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function Bm(){return jsxs(ne,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Project Paused"}),jsxs(re,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function jm(){let{schemaErrorMessage:e}=Rt();if(!e)return jsx(Fragment,{});let[t,o,...n]=e.split(`
394
+ `);return jsxs(ne,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(De,{children:"Schema mismatch"}),jsxs(re,{children:[jsx("p",{children:t}),o?jsx("p",{className:"fk:mt-1",children:o}):null,n.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:n.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function qm(e){return e}function Um(e,t){if(e.dataType==="asset"&&e.scope!==void 0&&e.scope!=="global")throw new Error(`Attribute "${e.name}" in entity "${t}" uses dataType "asset" but scope "${e.scope}". Asset attributes must use scope "global" or omit scope.`)}function Jm(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function Ps(e){return e.attributes.forEach(t=>{Um(t,e.name);}),{...e,attributes:e.attributes.map(Jm)}}function Qm(e){return Ps(e)}function Wm({column:e,title:t$1,options:o$1}){let n=e?.getFacetedUniqueValues(),r$1=new Set(e?.getFilterValue());return jsxs(Kt,{children:[jsx(eo,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk:h-8 fk:border-dashed",children:[jsx(CirclePlus,{className:"fk:mr-2 fk:h-4 fk:w-4"}),t$1,r$1?.size>0&&jsxs(Fragment,{children:[jsx(g$3,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:r$1.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:r$1.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[r$1.size," selected"]}):o$1.filter(i=>r$1.has(i.value)).map(i=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:i.label},i.value))})]})]})}),jsx(bt,{className:"fk:w-[200px] fk:p-0",align:"start",children:jsxs(m$2,{children:[jsx(o,{placeholder:t$1}),jsxs(p,{children:[jsx(q,{children:"No results found."}),jsx(r,{children:o$1.map(i=>{let a=r$1.has(i.value);return jsxs(t,{onSelect:()=>{a?r$1.delete(i.value):r$1.add(i.value);let s=Array.from(r$1);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$4("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",a?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$4("h-4 w-4")})}),i.icon&&jsx(i.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:i.label}),n?.get(i.value)&&jsx("span",{className:"fk:ml-auto fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:font-mono fk:text-xs",children:n.get(i.value)})]},i.value)})}),r$1.size>0&&jsxs(Fragment,{children:[jsx(s,{}),jsx(r,{children:jsx(t,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function ep({entityName:e,entityNamePlural:t,row:o,options:n={canDelete:true,canEdit:true}}){let r=ie(),i=o.original._id;function a(){r({type:"EditEntity",payload:{entityId:i,entityNamePlural:t}});}function s(){r({type:"DeleteEntity",payload:{entityId:i,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[n.canEdit&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:a,variant:"ghost",children:[jsx(Pencil,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),n.canDelete&&!n.canEdit&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:s,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),n.canEdit&&n.canDelete&&jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Additional actions"})]})}),jsxs(f$2,{align:"end",className:"w-[160px]",children:[jsx(h$1,{onClick:a,children:"Edit"}),jsx(m,{}),jsx(h$1,{onClick:s,children:"Delete"})]})]})]})}function _r({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:o=>{t.toggleVisibility(!!o);},children:t.id},t.id))]})]})}function ap({entityName:e,table:t}){let o=ie(),n=d$2(),r=c$2(),{projects:i,currentProjectId:a}=d(),{scopes:s}=find(propEq(a??"","projectId"))(i),[d$3,c,l]=rt(),[f,u]=useState(false),m=t.getSelectedRowModel().rows.map(v=>v.original._id);function g(){o({type:"AddEntity",payload:{entityName:e}});}function p(v){n({type:"setScope",payload:{projectId:a,scope:v}});}async function h(v){let{schema:x}=find(propEq(a??"","projectId"))(i),E=bo(e,x,v);await new Promise(S=>{c(gql`
395
+ ${E}
396
+ `),l({variables:{where:{_id:{eq:v}}},update(b){b.evict({id:v});},onCompleted:()=>{S();}}),d$3(true);});}function y(){let v=e==="_asset"?"asset":e.toLowerCase();o({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${m.length} ${v}${m.length>1?"s":""}`,dialogMessage:m.length>1?`Are you sure you want to delete the selected ${v}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${v}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{u(true);try{for(let x of m)await h(x);t.resetRowSelection(),toast.success(m.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{u(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[s&&s.length>0?jsxs(a$5,{defaultValue:r.scope,onValueChange:v=>{p(v);},value:r.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(r.scope??"","name"))(s)||null)?.label})]}),jsx(e$1,{children:s.map(v=>jsx(g$1,{value:v.name,children:v.label},v.name))})]}):null,jsx(_r,{table:t})]}),m.length>0?jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:f,onClick:y,size:"sm",variant:"destructive",children:[f?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",m.length,")"]}):null,jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:f,onClick:g,size:"sm",variant:"default",children:"Create"})]})}export{Po as DataTable,Wm as DataTableFacetedFilter,ep as DataTableRowActions,ap as DataTableToolbar,_r as DataTableViewOptions,Om as FlexkitStudio,Bm as ProjectDisabled,jm as SchemaError,qm as defineConfig,Qm as defineEntity,qn as getEntityCreateMutation,bo as getEntityDeleteMutation,It as getEntityQuery,$t as getEntitySchema,Vn as getEntityUpdateMutation,ie as useDispatch,rt as useEntityMutation,Ro as useEntityQuery,Rt as useGraphQLError,Do as useGridColumnsDefinition,Ao as useUploadAssets};//# sourceMappingURL=index.js.map
396
397
  //# sourceMappingURL=index.js.map