@flexkit/studio 0.2.2 → 0.2.4
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.
- package/dist/activity-nav-button-AESIPODJ.js +2 -0
- package/dist/activity-nav-button-AESIPODJ.js.map +1 -0
- package/dist/chat-page-S2YGOKO5.js +4 -0
- package/dist/{chat-page-YWENJEUP.js.map → chat-page-S2YGOKO5.js.map} +1 -1
- package/dist/chunk-2AHDTE5T.js +2 -0
- package/dist/{chunk-OFLU53AC.js.map → chunk-2AHDTE5T.js.map} +1 -1
- package/dist/chunk-32ZU4MLE.js +2 -0
- package/dist/{chunk-ODORXGGY.js.map → chunk-32ZU4MLE.js.map} +1 -1
- package/dist/chunk-3C2EG3SI.js +2 -0
- package/dist/{chunk-GW37ZTR2.js.map → chunk-3C2EG3SI.js.map} +1 -1
- package/dist/chunk-3TGCCDOR.js +2 -0
- package/dist/chunk-3TGCCDOR.js.map +1 -0
- package/dist/chunk-6NRQMG26.js +2 -0
- package/dist/chunk-6NRQMG26.js.map +1 -0
- package/dist/{chunk-LYGHDJ5A.js → chunk-6RDPFMLK.js} +2 -2
- package/dist/{chunk-LYGHDJ5A.js.map → chunk-6RDPFMLK.js.map} +1 -1
- package/dist/chunk-CKNFYN3O.js +3 -0
- package/dist/chunk-CKNFYN3O.js.map +1 -0
- package/dist/chunk-J2G4C6I5.js +2 -0
- package/dist/chunk-J2G4C6I5.js.map +1 -0
- package/dist/{chunk-7ZDMZVDA.js → chunk-KWS3NAYS.js} +5 -5
- package/dist/{chunk-7ZDMZVDA.js.map → chunk-KWS3NAYS.js.map} +1 -1
- package/dist/chunk-LN55VJ35.js +3 -0
- package/dist/chunk-LN55VJ35.js.map +1 -0
- package/dist/{chunk-Z6IEBNKV.js → chunk-NOFQHWES.js} +2 -2
- package/dist/{chunk-Z6IEBNKV.js.map → chunk-NOFQHWES.js.map} +1 -1
- package/dist/chunk-NYKATVPZ.js +4 -0
- package/dist/{chunk-3FIKCGSP.js.map → chunk-NYKATVPZ.js.map} +1 -1
- package/dist/chunk-PWQPA2QL.js +2 -0
- package/dist/chunk-PWQPA2QL.js.map +1 -0
- package/dist/chunk-SVZY7ZZD.js +8 -0
- package/dist/chunk-SVZY7ZZD.js.map +1 -0
- package/dist/chunk-TWMX2IQ2.js +3 -0
- package/dist/chunk-TWMX2IQ2.js.map +1 -0
- package/dist/chunk-U45E5X3H.js +2 -0
- package/dist/chunk-U45E5X3H.js.map +1 -0
- package/dist/chunk-USNXQOMJ.js +2 -0
- package/dist/chunk-USNXQOMJ.js.map +1 -0
- package/dist/chunk-YCCFUGWJ.js +7 -0
- package/dist/chunk-YCCFUGWJ.js.map +1 -0
- package/dist/index.css +41 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/list-PNKQAYUK.js +2 -0
- package/dist/{list-3K2PBGML.js.map → list-PNKQAYUK.js.map} +1 -1
- package/dist/logo-JAWR6P43.js +2 -0
- package/dist/logo-JAWR6P43.js.map +1 -0
- package/dist/pages-KHFSZ3PH.js +3 -0
- package/dist/pages-KHFSZ3PH.js.map +1 -0
- package/dist/plugin-pages-SE52XFFW.js +2 -0
- package/dist/{plugin-pages-Q77CBW45.js.map → plugin-pages-SE52XFFW.js.map} +1 -1
- package/dist/root-44ZJLA4E.js +2 -0
- package/dist/root-44ZJLA4E.js.map +1 -0
- package/dist/root-BH3PQS2H.js +31 -0
- package/dist/{root-EZWV5VA4.js.map → root-BH3PQS2H.js.map} +1 -1
- package/dist/root-LFQA2VSE.js +2 -0
- package/dist/{root-4TME2KMP.js.map → root-LFQA2VSE.js.map} +1 -1
- package/dist/{root-4ZVGVCYY.js → root-X5NDURAN.js} +10 -10
- package/dist/{root-4ZVGVCYY.js.map → root-X5NDURAN.js.map} +1 -1
- package/dist/search-Q65IC67C.js +2 -0
- package/dist/{search-7NX232AW.js.map → search-Q65IC67C.js.map} +1 -1
- package/dist/skills-pages-TWOIIU5J.js +2 -0
- package/dist/{skills-pages-SMJ4EWZW.js.map → skills-pages-TWOIIU5J.js.map} +1 -1
- package/dist/spec-renderer-EX7SCFWH.js +2 -0
- package/dist/{spec-renderer-5YGDRF52.js.map → spec-renderer-EX7SCFWH.js.map} +1 -1
- package/dist/ui.js +1 -1
- package/dist/user-nav-QZTYBG45.js +2 -0
- package/dist/user-nav-QZTYBG45.js.map +1 -0
- package/package.json +3 -3
- package/dist/chat-page-YWENJEUP.js +0 -4
- package/dist/chunk-2FQWBOU6.js +0 -6
- package/dist/chunk-2FQWBOU6.js.map +0 -1
- package/dist/chunk-3FIKCGSP.js +0 -4
- package/dist/chunk-4BX7OJJ6.js +0 -2
- package/dist/chunk-4BX7OJJ6.js.map +0 -1
- package/dist/chunk-5DHOBLAE.js +0 -2
- package/dist/chunk-5DHOBLAE.js.map +0 -1
- package/dist/chunk-66N44IKJ.js +0 -3
- package/dist/chunk-66N44IKJ.js.map +0 -1
- package/dist/chunk-GW37ZTR2.js +0 -2
- package/dist/chunk-H6TOYVW2.js +0 -3
- package/dist/chunk-H6TOYVW2.js.map +0 -1
- package/dist/chunk-ODORXGGY.js +0 -2
- package/dist/chunk-OFLU53AC.js +0 -2
- package/dist/chunk-YIGEER6B.js +0 -7
- package/dist/chunk-YIGEER6B.js.map +0 -1
- package/dist/list-3K2PBGML.js +0 -2
- package/dist/logo-MU7MGYDH.js +0 -3
- package/dist/logo-MU7MGYDH.js.map +0 -1
- package/dist/pages-BDZ4ZXBS.js +0 -3
- package/dist/pages-BDZ4ZXBS.js.map +0 -1
- package/dist/plugin-pages-Q77CBW45.js +0 -2
- package/dist/root-4TME2KMP.js +0 -2
- package/dist/root-EZWV5VA4.js +0 -31
- package/dist/root-YKNISFWH.js +0 -2
- package/dist/root-YKNISFWH.js.map +0 -1
- package/dist/search-7NX232AW.js +0 -2
- package/dist/skills-pages-SMJ4EWZW.js +0 -2
- package/dist/spec-renderer-5YGDRF52.js +0 -2
- package/dist/user-nav-QZFCICK3.js +0 -2
- package/dist/user-nav-QZFCICK3.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import'./index.css';import {a as a$6}from'./chunk-AKQ6ELDX.js';export{a as DataTableRowActions,c as DataTableToolbar,b as DataTableViewOptions}from'./chunk-3FIKCGSP.js';import {c as c$3,b as b$4}from'./chunk-Z6IEBNKV.js';export{a as usePatchEntityList,c as useUploadAssets}from'./chunk-Z6IEBNKV.js';import {a as a$8}from'./chunk-LYGHDJ5A.js';export{a as useSearch}from'./chunk-LYGHDJ5A.js';export{a as DataTableFacetedFilter}from'./chunk-GW37ZTR2.js';import {D,A,c as c$4,l as l$1,b as b$2,k as k$1,J,f as f$1,x as x$1,a as a$2,y,r as r$2,o as o$3,t as t$2,z as z$1,u as u$1,C,g as g$4,n as n$1,j as j$2,h as h$3,p as p$2,i as i$1}from'./chunk-7ZDMZVDA.js';export{x as DataTable,I as DataTableColumnHeader,B as DataTableSortedBy,v as ProjectDisabled,w as SchemaError,j as getEntityCreateMutation,h as getEntityDeleteMutation,i as getEntityDeleteWhere,e as getEntityQuery,m as getEntitySchema,g as getEntityUpdateMutation,d as getSortNotNullWhere,A as useDispatch,C as useEntityMutation,u as useEntityQuery,s as useGraphQLError,J as useGridColumnsDefinition}from'./chunk-7ZDMZVDA.js';import {d as d$1,c as c$1,e as e$2,b as b$5,a as a$4}from'./chunk-P6BZ4QP7.js';export{c as useAppContext,d as useAppDispatch}from'./chunk-P6BZ4QP7.js';import {b as b$8}from'./chunk-7SK5YPHT.js';export{a as canMutateData,b as useCanMutate}from'./chunk-7SK5YPHT.js';import {b}from'./chunk-2DXR5NJV.js';export{a as canAccessSpaces,b as filterAttributesForSpaces,c as filterEntitiesForSpaces}from'./chunk-2DXR5NJV.js';import {f as f$2,a as a$5,e as e$5}from'./chunk-66N44IKJ.js';export{b as assetSchema,c as tagSchema,f as useConfig}from'./chunk-66N44IKJ.js';import {h,c as c$2,e as e$3,d as d$3,b as b$7,a as a$7,f as f$3,g as g$3}from'./chunk-NNA4MLFC.js';export{c as IMAGES_BASE_URL,h as useAuth}from'./chunk-NNA4MLFC.js';import {Wc,Xc,Yc,g,la as la$1,ma as ma$1,na as na$1,aa as aa$1,oa as oa$1,h as h$1,j,k,m,l,pa,n,s,ca as ca$1,K,L,M,O,p,r,t,u,v as v$1,o as o$1,ua,e as e$4,c as c$6,d as d$4,sa,ra}from'./chunk-YIGEER6B.js';import {w,x,v,b as b$3,m as m$1,o as o$2,p as p$1,r as r$1,t as t$1,s as s$1}from'./chunk-ODORXGGY.js';import {e as e$1,g as g$2,h as h$2,i,j as j$1,o,t as t$3}from'./chunk-SZEGGBOC.js';import {d as d$2,c as c$5,a as a$3,b as b$6}from'./chunk-5DHOBLAE.js';import {a,d,c,e,b as b$1,f,g as g$1}from'./chunk-HDOIOXMP.js';import {a as a$1}from'./chunk-O2QMYUPS.js';import*as Oo from'react';import {lazy,createContext,memo,forwardRef,useMemo,useState,useRef,useEffect,useImperativeHandle,createElement,useId,useCallback,Fragment as Fragment$1,Suspense,startTransition,Component,useContext}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useLocation,useRouteError,Link as Link$1,useHref,Navigate,useNavigate,NavLink,isRouteErrorResponse,createPath,useRoutes,Outlet}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,Trash2,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,AlertCircle,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Loader2,Mail,FolderOpen,LoaderCircle}from'lucide-react';import Fs,{useSWRConfig}from'swr';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Io from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {gql}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient}from'@apollo/client/react';import {v4}from'uuid';import {find,propEq,equals,uniqBy,prop,map,uniq}from'ramda';import xr 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 Ec from'react-markdown';export{defineConfig,defineEntity}from'@flexkit/schema';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';export{useVirtualizer}from'@tanstack/react-virtual';function Fo(){let[e,t]=useState(false),{theme:o,setTheme:r}=b$6();return useEffect(()=>{t(true);},[]),e?jsxs(c$6,{size:"sm",type:"single",value:o,children:[jsx(d$4,{"aria-label":"Set dark mode",onClick:()=>{r("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$4,{"aria-label":"Set light mode",onClick:()=>{r("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$4,{"aria-label":"Set system mode",onClick:()=>{r("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}var Ls=Io.object({email:Io.email({error:"Please enter a valid email address"})});function cr({projectId:e,redirectTo:t,setIsEmailLogin:o}){let r=useRef(t);r.current=t;function n$1(){r.current?window.location.assign(r.current):window.location.reload();}let[i,a]=useState(false),[c,f]=useState(false),{mutate:s$1}=useSWRConfig(),l$1=useForm({resolver:zodResolver(Ls),defaultValues:{email:""}}),u=e===void 0?d$3.otpSend:new URL(e$3(e).loginOtpSend,b$7).href,d=e===void 0?d$3.otpConfirm:new URL(e$3(e).loginOtpConfirm,b$7).href,{data:p,error:k,isLoading:A}=Fs(c?u:null,g=>fetch(g,{method:"POST",mode:"cors",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:l$1.getValues("email")})}).then(N=>N.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),b=p&&"error"in p&&p.error.code,E=p&&"token"in p,T=p&&"token"in p?p.token:"";useEffect(()=>{if(!E)return;let g=0,N=setInterval(()=>{if(g>100){clearInterval(N),a(true);return}let O="/api/flexkit/set-token";fetch(`${d}?email=${encodeURIComponent(l$1.getValues("email"))}&token=${encodeURIComponent(T)}`,{credentials:"same-origin"}).then(M=>{M.status===200&&M.json().then(D=>{fetch(O,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:D.sid})}).then(()=>{n$1();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),g++;},3e3);return ()=>{clearInterval(N);}},[d,l$1,E,T]);function y(){a(false),f(true),s$1(u);}return jsx("div",{className:"fk:w-full",children:E?jsx(Wc,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(Yc,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:l$1.getValues("email")})," (",jsx(d$2,{className:"fk:p-0 fk:hover:underline fk:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(g,{...l$1,children:jsxs("form",{onSubmit:g=>{l$1.handleSubmit(y)(g);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[b==="not_exists"&&jsx(Wc,{variant:"destructive",children:jsxs(Yc,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${encodeURIComponent(l$1.getValues("email"))}`,children:"Sign up?"})]})}),b==="unknown_error"||k?jsx(Wc,{variant:"destructive",children:jsxs(Yc,{children:["There was an unknown error, please"," ",jsx(d$2,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."," "]})}):null,i?jsx(Wc,{variant:"destructive",children:jsxs(Yc,{children:["The email verification link may have expired. Please"," ",jsx(d$2,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(h$1,{control:l$1.control,defaultValue:"",name:"email",render:({field:g})=>jsxs(j,{children:[jsx(l,{children:jsx(s,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...g})}),jsx(n,{})]})}),jsxs(d$2,{"aria-disabled":A,className:"fk:w-full",type:"submit",disabled:!!A,children:[A?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(d$2,{className:"fk:w-full fk:text-link",onClick:()=>{o(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function Do({projectId:e$1}){let t=e$1===void 0,{projectIds:o,projects:r}=f$2(),[n,i]=useState(e$1===void 0?"":o.includes(e$1)?e$1:o[0]??e$1),a$1=useHref(`/${n}`),[c$1,f]=useState(false),s=t?d$3.authProviders:e$3(n).authProviders,{data:l,error:u,isLoading:d$1}=Fs(s,g=>fetch(g,{mode:"cors",credentials:"same-origin"}).then(N=>N.json())),[p,k]=h(),A=new Date().getFullYear(),b=useLocation(),E=b.state?.from?.pathname??b.pathname,T=useHref(E),y=t||E.includes(n)?`${location.origin}${T}`:`${location.origin}${a$1}`;if(u)throw new Error("Error fetching auth providers");return d$1||!t&&p||!l?jsx(a$5,{}):!t&&k.user?.id?jsx(Navigate,{replace:true,state:{from:b},to:"/"}):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&&o.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(e$4,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a,{defaultValue:n,onValueChange:g=>{i(g);},children:[jsx(d,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c,{"aria-label":a$6(n,r),children:a$6(n,r)})}),jsx(e,{children:o.map(g=>jsx(g$1,{value:g,children:a$6(g,r)},g))})]})]}):null,c$1?jsx(cr,{projectId:t?void 0:n,redirectTo:y,setIsEmailLogin:f},n):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:[l.providers.map(g=>jsx(d$2,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:Bs({url:g.url,projectId:t?void 0:n,basePath:"/api/flexkit/get-token",fromPath:y}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.name)),jsx(d$2,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{f(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 ",A]})]}),jsx(Fo,{})]})})]})}function Bs({projectId:e,url:t,basePath:o,fromPath:r}){let n=new URLSearchParams;return n.set("origin",`${location.origin}${o}`),e&&n.set("projectId",e),n.set("redirect",r),`${t}?${n.toString()}`}var ei="flexkit-studio:lastProjectId";function ti(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function oi(e=ti()){try{let t=e?.getItem(ei);return t&&t.trim()?t:null}catch{return null}}function ri(e,t=ti()){try{t?.setItem(ei,e);}catch{}}function ni(e,t){return t&&e.includes(t)?t:e[0]}var js=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Vs={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"},To=class e extends Error{code;constructor(t,o){super(o??Vs[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 mr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:js.includes(t)}function ii(e){if(mr(e))return e.code}function Po(e){return {locations:{},order:[],projectId:e}}function ai(e){try{return decodeURIComponent(e)}catch{return e}}function ao(e,t){let[o,r]=e.split("/").filter(Boolean);if(!(o===void 0||ai(o)!==t))return r===void 0?void 0:ai(r)}function si(e,t,o,r){let n=e.projectId===t?e:Po(t);return n.locations[o]===r?n:{locations:{...n.locations,[o]:r},order:n.order.includes(o)?n.order:[...n.order,o],projectId:t}}function mi({activeApp:e,apps:t,sessions:o$1,version:r}){let[n,i]=useState(0),[a,c]=useState(t),[f,s]=useState([]),l=useRef(null),u=useLocation(),{projectId:d=""}=useParams(),p=ao(u.pathname,d),k=e??t[0]?.name;function A(b){let E=o$1.locations[b.name];return E?createPath(E):`/${d}/${b.name}`}return useEffect(()=>{if(l.current===null)return;let b=new ResizeObserver(()=>{i(l.current?.offsetHeight??0);});return b.observe(l.current),function(){b.disconnect();}},[e]),useEffect(()=>{let b=Math.floor(n/48)-2,E=t.slice(0,b);if(!E.find(y=>y.name===k)){let y=t.find(g=>g.name===k);E.pop(),y&&E.push(y);}let T=t.filter(y=>!E.includes(y));c(E),s(T);},[t,k,n]),p===void 0&&k?jsx(Navigate,{replace:true,to:`${u.pathname.replace(/\/$/,"")}/${k}`}):jsx(K,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:l,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:a.map(b=>jsx(d$2,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(L,{children:[jsx(M,{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 fk:corner-squircle",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:A(b),children:b.icon})}),jsx(O,{side:"right",children:jsx("p",{children:b.title})})]})},b.name))}),f.length>0&&jsxs(e$1,{children:[jsx(L,{children:jsx(g$2,{asChild:true,children:jsxs(M,{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(O,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(h$2,{align:"start",className:"fk:w-56",side:"right",children:f.map(b=>jsx(j$1,{asChild:true,children:jsx(NavLink,{to:A(b),children:b.title})},b.name))})]})]}),jsxs(e$1,{children:[jsx(L,{children:jsx(g$2,{asChild:true,children:jsxs(M,{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(O,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(h$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(j$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${d}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(o,{}),jsx(j$1,{disabled:r.isCurrent,onSelect:()=>{r.isCurrent;},children:r.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",r.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",r.current,".",jsx("br",{}),"Upgrade to ",r.latest]})]})})]})]})]})})}function tl({error:e}){let t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(Wc,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Xc,{children:"Error"}),jsx(Yc,{children:t})]})}var dr=class extends Component{state={error:null,hasError:false};static getDerivedStateFromError(t){return {error:t,hasError:true}}componentDidCatch(t,o){console.error("Flexkit Studio app error",t,o.componentStack);}componentDidUpdate(t){this.state.hasError&&t.resetKey!==this.props.resetKey&&this.setState({error:null,hasError:false});}render(){return this.state.hasError?jsx(tl,{error:this.state.error}):this.props.children}};function pr({children:e}){let{pathname:t,search:o}=useLocation();return jsx(dr,{resetKey:`${t}${o}`,children:e})}function di(e,t){let o=useLocation(),[r,n]=useState(()=>Po(t)),i=ao(o.pathname,t),a=i!==void 0&&e.some(f=>f.name===i)?i:void 0,c=a?si(r,t,a,o):r.projectId===t?r:Po(t);return c!==r&&n(c),{activeApp:a,sessions:c}}function pi(e){return {children:e.children?.map(pi),element:jsx(pr,{children:e.component}),path:e.path}}function sl({app:e,location:t}){let o=useMemo(()=>[{children:e.routes?.map(pi),element:jsx(pr,{children:e.component}),path:e.name}],[e]);return useRoutes(o,t)}function ll({segment:e}){return jsx("div",{className:"fk:flex fk:h-full fk:grow fk:items-center fk:justify-center fk:p-8",children:jsxs(Wc,{className:"fk:max-w-lg",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Xc,{children:"App not found"}),jsxs(Yc,{children:['There is no Studio app named "',e,'".']})]})})}function ki({activeApp:e,apps:t,sessions:o}){let r=useLocation(),n=ao(r.pathname,o.projectId);return jsxs(Fragment,{children:[o.order.map(i=>{let a=t.find(s=>s.name===i),c=o.locations[i];if(!a||!c)return null;let f=i===e;return jsx("div",{"aria-hidden":f?void 0:true,"data-studio-app":i,style:{display:f?"contents":"none"},children:jsx(sl,{app:a,location:c})},i)}),e===void 0&&n!==void 0?jsx(ll,{segment:n}):null]})}var ul=lazy(()=>import('./logo-MU7MGYDH.js').then(({Logo:e})=>({default:e}))),dl=lazy(()=>import('./project-selector-72VM6SUI.js').then(({ProjectSelector:e})=>({default:e}))),pl=lazy(()=>import('./search-7NX232AW.js').then(({Search:e})=>({default:e}))),kl=lazy(()=>import('./user-nav-QZFCICK3.js').then(({UserNav:e})=>({default:e})));function hi({projectId:e,projectIds:t,projectSummaries:o=[],projects:r}){let{resolvedTheme:n}=b$6(),i=r.find(l=>l.projectId===e),a=o.find(l=>l.id===e),c=i?.schema??[],f=useNavigate();function s(l){startTransition(()=>{f(`/${e}/desk/list/${l.entityNamePlural}?id=${l.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-14 fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-30",children:[jsx(Suspense,{fallback:null,children:jsx(ul,{theme:n,title:i?.title??a?.name??"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(dl,{projectId:e,projectIds:t,projectSummaries:o,projects:r})}),jsx(Suspense,{fallback:null,children:jsx(pl,{onSelect:s,projectId:e,schema:c},e)})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(kl,{projectId:e})})})]})}function yi({projectId:e,error:t,showHomeLink:o=false}){let r=t.status===404,n=t.status===401||t.status===403,i=r?"No deployed schema":n?"No access to this project":"Could not load the project schema",a=r?`Project "${e}" has no deployed schema yet. Run \`flexkit deploy\` from the folder containing its flexkit.config.ts.`:n?`Your account is not a member of project "${e}". Ask a project owner to invite you.`:`${t.message} (project "${e}").`;return jsx("div",{className:"fk:flex fk:h-full fk:items-center fk:justify-center fk:p-8",children:jsxs(Wc,{className:"fk:max-w-lg",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Xc,{children:i}),jsxs(Yc,{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx("span",{children:a}),o?jsx(Link$1,{className:"fk:underline fk:underline-offset-4",to:"/",children:"Back to your projects"}):null]})]})})}function bi({version:e}){let{apps:t,currentProject:o,isLoadingSchemas:r,mode:n,projectIds:i,projects:a,projectSummaries:c,schemaErrors:f}=f$2(),[s,l]=h(),{projectId:u=""}=useParams(),d=o?.scopes,p=d$1(),k=useLocation(),A=i.includes(u),b=di(t,u);if(useEffect(()=>{if(d&&d.length>0){let T=d.find(g=>g.isDefault)??d[0],y="";typeof localStorage<"u"&&(y=localStorage.getItem(`${a$4}${u}`)??""),p({type:"setScope",payload:{projectId:u,scope:y||T.name}});}},[p,k,u,d]),useEffect(()=>{n==="hosted"&&A&&o&&ri(u);},[o,A,n,u]),!A){if(n==="projects")throw new To("PROJECT_NOT_FOUND");return jsx(yi,{error:{status:403,message:"No access to this project"},projectId:u,showHomeLink:true})}if(s)return jsx(a$5,{});if(!l.user?.id)return jsx(Do,{projectId:n==="hosted"?void 0:u});if(r)return jsx(a$5,{});let E=f[u];return jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(hi,{projectId:u,projectIds:i,projectSummaries:c,projects:a}),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(mi,{apps:t,version:e,...b}),o?jsx(ki,{apps:t,...b}):jsx(yi,{error:E??{status:0,message:"The project schema is not available."},projectId:u,showHomeLink:n==="hosted"})]})]}),jsx(ua,{})]})}async function xl(){try{let e=await fetch(d$3.me,{credentials:"same-origin"});return e.status===401?{kind:"anonymous"}:e.ok?{kind:"ready",data:await e.json()}:{kind:"error",message:`Flexkit answered ${String(e.status)} while loading your projects.`}}catch(e){return {kind:"error",message:e instanceof Error?e.message:"Flexkit is not reachable."}}}function wl(e){return e?e.kind==="anonymous"?{status:"anonymous"}:e.kind==="error"?{status:"error",message:e.message}:{status:"ready",projects:e.data.projects,user:e.data.user}:{status:"loading"}}function Ci(){let{data:e}=Fs("hosted-session",xl,{revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false});return wl(e)}function xi({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function gr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Sl({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$1("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function wi({className:e,size:t="default",...o}){return jsxs(gr,{children:[jsx(Sl,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$1("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg fk:corner-squircle",e),...o})]})}function Si({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$1("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Ai({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$1("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Ni({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$1("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function Ei({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$1("fk:text-sm fk:text-muted-foreground",e),...t})}function Fi({className:e,variant:t="default",size:o="default",...r}){return jsx(d$2,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$1(e),...r})})}function Ii({className:e,variant:t="outline",size:o="default",...r}){return jsx(d$2,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$1(e),...r})})}function fo({options:e}){let[t,o]=useState(false),[r,n]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function c(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function f(){n(true),a(true),o(false),await new Promise(s=>{globalThis.setTimeout(s,150);});try{let s=e.dialogActionSubmit?.();s&&typeof s.then=="function"&&await s;}finally{n(false);}}return jsx(xi,{onOpenChange:c,open:t,children:jsx(gr,{children:jsxs(wi,{className:"sm:max-w-[425px]",children:[jsxs(Si,{children:[jsx(Ni,{children:e.dialogTitle}),jsx(Ei,{children:e.dialogMessage})]}),jsxs(Ai,{children:[jsx(Ii,{disabled:r,onClick:c,children:e.dialogCancelTitle}),jsxs(Fi,{className:c$5({variant:e.isDestructive?"destructive":"default"}),disabled:r,onClick:f,children:[r?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}function vr({action:e}){let{currentProject:t}=f$2(),o=t?.schema??[],r=useApolloClient(),[n,i,a]=C(),c=A(),f=useRef(false),s=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],l=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),u=!!e.payload.silent,d=s.length>1;if(useEffect(()=>{!u||f.current||(f.current=true,k());},[u]),u)return jsx(Fragment,{});let p={dialogTitle:d?`Delete ${s.length} ${l}s`:`Delete ${l}`,dialogMessage:d?`Are you sure you want to delete the selected ${l}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${l}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>k()};function k(){let A=h$3(e.payload.entityName,o,s);return new Promise((b,E)=>{i(gql`
|
|
1
|
+
import'./index.css';import {a as a$8}from'./chunk-AKQ6ELDX.js';import {a as a$9,h as h$4}from'./chunk-3TGCCDOR.js';import {f as f$4,g as g$5}from'./chunk-CKNFYN3O.js';import {a as a$c}from'./chunk-TWMX2IQ2.js';export{a as DataTableRowActions,c as DataTableToolbar,b as DataTableViewOptions}from'./chunk-NYKATVPZ.js';import {c as c$4,b as b$6}from'./chunk-NOFQHWES.js';export{a as usePatchEntityList,c as useUploadAssets}from'./chunk-NOFQHWES.js';import {a as a$b}from'./chunk-6RDPFMLK.js';export{a as useSearch}from'./chunk-6RDPFMLK.js';export{a as DataTableFacetedFilter}from'./chunk-3C2EG3SI.js';import {D,A,c as c$5,l as l$1,b as b$4,k as k$1,J,f as f$1,x as x$1,a as a$4,y,r as r$2,o as o$3,t as t$2,z as z$1,u as u$1,C,g as g$4,n as n$1,j as j$2,h as h$3,p as p$2,i as i$1}from'./chunk-KWS3NAYS.js';export{x as DataTable,I as DataTableColumnHeader,B as DataTableSortedBy,v as ProjectDisabled,w as SchemaError,j as getEntityCreateMutation,h as getEntityDeleteMutation,i as getEntityDeleteWhere,e as getEntityQuery,m as getEntitySchema,g as getEntityUpdateMutation,d as getSortNotNullWhere,A as useDispatch,C as useEntityMutation,u as useEntityQuery,s as useGraphQLError,J as useGridColumnsDefinition}from'./chunk-KWS3NAYS.js';import {d as d$1,c as c$1,e as e$3,b as b$7,a as a$6}from'./chunk-P6BZ4QP7.js';export{c as useAppContext,d as useAppDispatch}from'./chunk-P6BZ4QP7.js';import {b as b$a}from'./chunk-7SK5YPHT.js';export{a as canMutateData,b as useCanMutate}from'./chunk-7SK5YPHT.js';import {b}from'./chunk-2DXR5NJV.js';export{a as canAccessSpaces,b as filterAttributesForSpaces,c as filterEntitiesForSpaces}from'./chunk-2DXR5NJV.js';import {f as f$2,a as a$7,e as e$6}from'./chunk-LN55VJ35.js';export{b as assetSchema,c as tagSchema,f as useConfig}from'./chunk-LN55VJ35.js';import {h,c as c$2,e as e$4,d as d$2,b as b$9,a as a$a,f as f$3,g as g$3}from'./chunk-NNA4MLFC.js';export{c as IMAGES_BASE_URL,h as useAuth}from'./chunk-NNA4MLFC.js';import {Rc,Sc,Tc,g,ga,ha as ha$1,ia as ia$1,X,ja as ja$1,h as h$1,j,k,m,l,ka as ka$1,n,s,Z,p,r,t,u,v as v$1,o as o$1,pa as pa$1,e as e$5,c as c$6,d as d$3,na as na$1,ma as ma$1}from'./chunk-YCCFUGWJ.js';import {w,x,v,b as b$5,m as m$1,o as o$2,p as p$1,r as r$1,t as t$1,s as s$1}from'./chunk-32ZU4MLE.js';import {a,d,c,e,b as b$1,f,g as g$1}from'./chunk-HDOIOXMP.js';import {e as e$1,g as g$2,h as h$2,i,j as j$1,o,t as t$3}from'./chunk-SZEGGBOC.js';import {a as a$5,b as b$8}from'./chunk-U45E5X3H.js';import {a as a$1,b as b$3,c as c$3,e as e$2}from'./chunk-USNXQOMJ.js';import {b as b$2,a as a$3}from'./chunk-6NRQMG26.js';import {a as a$2}from'./chunk-O2QMYUPS.js';import*as Bo from'react';import {lazy,createContext,memo,forwardRef,useMemo,useState,useRef,useEffect,useImperativeHandle,createElement,useId,useCallback,Fragment as Fragment$1,Suspense,startTransition,Component,useContext}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useLocation,useRouteError,Link as Link$1,useHref,Navigate,useNavigate,NavLink,isRouteErrorResponse,createPath,useRoutes,Outlet}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X as X$1,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,Trash2,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,AlertCircle,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Loader2,Mail,FolderOpen,LoaderCircle}from'lucide-react';import Os,{useSWRConfig}from'swr';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as Do from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {gql}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient}from'@apollo/client/react';import {v4}from'uuid';import {find,propEq,equals,uniqBy,prop,map,uniq}from'ramda';import Ar 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 Gc from'react-markdown';export{defineConfig,defineEntity}from'@flexkit/schema';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';export{useVirtualizer}from'@tanstack/react-virtual';function To(){let[e,t]=useState(false),{theme:o,setTheme:r}=b$8();return useEffect(()=>{t(true);},[]),e?jsxs(c$6,{size:"sm",type:"single",value:o,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{r("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{r("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{r("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}var $s=Do.object({email:Do.email({error:"Please enter a valid email address"})});function ur({projectId:e,redirectTo:t,setIsEmailLogin:o}){let r=useRef(t);r.current=t;function n$1(){r.current?window.location.assign(r.current):window.location.reload();}let[i,a]=useState(false),[c,f]=useState(false),{mutate:s$1}=useSWRConfig(),l$1=useForm({resolver:zodResolver($s),defaultValues:{email:""}}),m=e===void 0?d$2.otpSend:new URL(e$4(e).loginOtpSend,b$9).href,d=e===void 0?d$2.otpConfirm:new URL(e$4(e).loginOtpConfirm,b$9).href,{data:p,error:k,isLoading:A}=Os(c?m:null,g=>fetch(g,{method:"POST",mode:"cors",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:l$1.getValues("email")})}).then(N=>N.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),b=p&&"error"in p&&p.error.code,E=p&&"token"in p,D=p&&"token"in p?p.token:"";useEffect(()=>{if(!E)return;let g=0,N=setInterval(()=>{if(g>100){clearInterval(N),a(true);return}let O="/api/flexkit/set-token";fetch(`${d}?email=${encodeURIComponent(l$1.getValues("email"))}&token=${encodeURIComponent(D)}`,{credentials:"same-origin"}).then(M=>{M.status===200&&M.json().then(T=>{fetch(O,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:T.sid})}).then(()=>{n$1();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),g++;},3e3);return ()=>{clearInterval(N);}},[d,l$1,E,D]);function y(){a(false),f(true),s$1(m);}return jsx("div",{className:"fk:w-full",children:E?jsx(Rc,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(Tc,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:l$1.getValues("email")})," (",jsx(b$2,{className:"fk:p-0 fk:hover:underline fk:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(g,{...l$1,children:jsxs("form",{onSubmit:g=>{l$1.handleSubmit(y)(g);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[b==="not_exists"&&jsx(Rc,{variant:"destructive",children:jsxs(Tc,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${encodeURIComponent(l$1.getValues("email"))}`,children:"Sign up?"})]})}),b==="unknown_error"||k?jsx(Rc,{variant:"destructive",children:jsxs(Tc,{children:["There was an unknown error, please"," ",jsx(b$2,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."," "]})}):null,i?jsx(Rc,{variant:"destructive",children:jsxs(Tc,{children:["The email verification link may have expired. Please"," ",jsx(b$2,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(h$1,{control:l$1.control,defaultValue:"",name:"email",render:({field:g})=>jsxs(j,{children:[jsx(l,{children:jsx(s,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...g})}),jsx(n,{})]})}),jsxs(b$2,{"aria-disabled":A,className:"fk:w-full",type:"submit",disabled:!!A,children:[A?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$2,{className:"fk:w-full fk:text-link",onClick:()=>{o(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function Po({projectId:e$1}){let t=e$1===void 0,{projectIds:o,projects:r}=f$2(),[n,i]=useState(e$1===void 0?"":o.includes(e$1)?e$1:o[0]??e$1),a$1=useHref(`/${n}`),[c$1,f]=useState(false),s=t?d$2.authProviders:e$4(n).authProviders,{data:l,error:m,isLoading:d$1}=Os(s,g=>fetch(g,{mode:"cors",credentials:"same-origin"}).then(N=>N.json())),[p,k]=h(),A=new Date().getFullYear(),b=useLocation(),E=b.state?.from?.pathname??b.pathname,D=useHref(E),y=t||E.includes(n)?`${location.origin}${D}`:`${location.origin}${a$1}`;if(m)throw new Error("Error fetching auth providers");return d$1||!t&&p||!l?jsx(a$7,{}):!t&&k.user?.id?jsx(Navigate,{replace:true,state:{from:b},to:"/"}):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&&o.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(e$5,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a,{defaultValue:n,onValueChange:g=>{i(g);},children:[jsx(d,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c,{"aria-label":a$8(n,r),children:a$8(n,r)})}),jsx(e,{children:o.map(g=>jsx(g$1,{value:g,children:a$8(g,r)},g))})]})]}):null,c$1?jsx(ur,{projectId:t?void 0:n,redirectTo:y,setIsEmailLogin:f},n):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:[l.providers.map(g=>jsx(b$2,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:Xs({url:g.url,projectId:t?void 0:n,basePath:"/api/flexkit/get-token",fromPath:y}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.name)),jsx(b$2,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{f(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 ",A]})]}),jsx(To,{})]})})]})}function Xs({projectId:e,url:t,basePath:o,fromPath:r}){let n=new URLSearchParams;return n.set("origin",`${location.origin}${o}`),e&&n.set("projectId",e),n.set("redirect",r),`${t}?${n.toString()}`}var si="flexkit-studio:lastProjectId";function li(){try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}function fi(e=li()){try{let t=e?.getItem(si);return t&&t.trim()?t:null}catch{return null}}function ci(e,t=li()){try{t?.setItem(si,e);}catch{}}function mi(e,t){return t&&e.includes(t)?t:e[0]}var Gs=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],Zs={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"},Ro=class e extends Error{code;constructor(t,o){super(o??Zs[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 dr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:Gs.includes(t)}function ui(e){if(dr(e))return e.code}var el=3e4,pi="flexkit:activity-watermark:";function tl(e){try{return localStorage.getItem(`${pi}${e}`)}catch{return null}}function ol(e,t){try{localStorage.setItem(`${pi}${e}`,t);}catch{}}function rl(){return typeof Notification<"u"&&Notification.permission==="granted"}var Lo=192,di=null;function nl(){return di??=(async()=>{try{let e=document.createElement("canvas");e.width=Lo,e.height=Lo;let t=e.getContext("2d");return t?(t.scale(Lo/48,Lo/48),t.fillStyle="white",t.fillRect(7,8,34,32),t.fillStyle="#020817",t.fill(new Path2D(a$c)),e.toDataURL("image/png")):void 0}catch{return}})(),di}function il(){return document.visibilityState==="hidden"||!document.hasFocus()}function al(e,t){let o=new AbortController;return typeof navigator>"u"||!("locks"in navigator)?(t(o.signal),()=>o.abort()):(navigator.locks.request(e,{signal:o.signal},async()=>{o.signal.aborted||(t(o.signal),await new Promise(r=>o.signal.addEventListener("abort",()=>r(),{once:true})));}).catch(()=>{}),()=>o.abort())}function ki({projectId:e}){let t=useNavigate(),o=useRef(t),{mutate:r}=useSWRConfig();return o.current=t,useEffect(()=>{if(e)return al(`flexkit-activity-notifier:${e}`,n=>{let i=tl(e);async function a(){let f;try{f=await f$4(g$5(e).activitySummary(i));}catch{return}if(n.aborted)return;let s=h$4({newItems:f.newItems,since:i});if({since:i}=s,ol(e,s.since),r(g$5(e).activitySummary(),f,{revalidate:false}),!il()||!rl())return;let l=s.notifications.length>0?await nl():void 0;for(let m of s.notifications){let d=new Notification(m.title,{body:m.body,icon:l,tag:m.tag});d.onclick=()=>{window.focus(),o.current(`/${e}/ai/${m.path}`),d.close();};}}a();let c=setInterval(()=>{a();},el);n.addEventListener("abort",()=>clearInterval(c));})},[r,e]),null}function Mo(e){return {locations:{},order:[],projectId:e}}function gi(e){try{return decodeURIComponent(e)}catch{return e}}function ao(e,t){let[o,r]=e.split("/").filter(Boolean);if(!(o===void 0||gi(o)!==t))return r===void 0?void 0:gi(r)}function hi(e,t,o,r){let n=e.projectId===t?e:Mo(t);return n.locations[o]===r?n:{locations:{...n.locations,[o]:r},order:n.order.includes(o)?n.order:[...n.order,o],projectId:t}}function Ci({activeApp:e,apps:t,sessions:o$1,version:r}){let[n,i]=useState(0),[a,c]=useState(t),[f,s]=useState([]),l=useRef(null),m=useLocation(),{projectId:d=""}=useParams(),p=ao(m.pathname,d),k=e??t[0]?.name;function A(b){let E=o$1.locations[b.name];return E?createPath(E):`/${d}/${b.name}`}return useEffect(()=>{if(l.current===null)return;let b=new ResizeObserver(()=>{i(l.current?.offsetHeight??0);});return b.observe(l.current),function(){b.disconnect();}},[e]),useEffect(()=>{let b=Math.floor(n/48)-2,E=t.slice(0,b);if(!E.find(y=>y.name===k)){let y=t.find(g=>g.name===k);E.pop(),y&&E.push(y);}let D=t.filter(y=>!E.includes(y));c(E),s(D);},[t,k,n]),p===void 0&&k?jsx(Navigate,{replace:true,to:`${m.pathname.replace(/\/$/,"")}/${k}`}):jsx(a$1,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:l,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:a.map(b=>jsx(b$2,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$3,{children:[jsx(c$3,{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 fk:corner-squircle",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:A(b),children:b.icon})}),jsx(e$2,{side:"right",children:jsx("p",{children:b.title})})]})},b.name))}),f.length>0&&jsxs(e$1,{children:[jsx(b$3,{children:jsx(g$2,{asChild:true,children:jsxs(c$3,{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$2,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(h$2,{align:"start",className:"fk:w-56",side:"right",children:f.map(b=>jsx(j$1,{asChild:true,children:jsx(NavLink,{to:A(b),children:b.title})},b.name))})]})]}),jsxs(e$1,{children:[jsx(b$3,{children:jsx(g$2,{asChild:true,children:jsxs(c$3,{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$2,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(h$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(j$1,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${d}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(o,{}),jsx(j$1,{disabled:r.isCurrent,onSelect:()=>{r.isCurrent;},children:r.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",r.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",r.current,".",jsx("br",{}),"Upgrade to ",r.latest]})]})})]})]})]})})}function Cl({error:e}){let t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(Rc,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Sc,{children:"Error"}),jsx(Tc,{children:t})]})}var kr=class extends Component{state={error:null,hasError:false};static getDerivedStateFromError(t){return {error:t,hasError:true}}componentDidCatch(t,o){console.error("Flexkit Studio app error",t,o.componentStack);}componentDidUpdate(t){this.state.hasError&&t.resetKey!==this.props.resetKey&&this.setState({error:null,hasError:false});}render(){return this.state.hasError?jsx(Cl,{error:this.state.error}):this.props.children}};function gr({children:e}){let{pathname:t,search:o}=useLocation();return jsx(kr,{resetKey:`${t}${o}`,children:e})}function wi(e,t){let o=useLocation(),[r,n]=useState(()=>Mo(t)),i=ao(o.pathname,t),a=i!==void 0&&e.some(f=>f.name===i)?i:void 0,c=a?hi(r,t,a,o):r.projectId===t?r:Mo(t);return c!==r&&n(c),{activeApp:a,sessions:c}}function Si(e){return {children:e.children?.map(Si),element:jsx(gr,{children:e.component}),path:e.path}}function El({app:e,location:t}){let o=useMemo(()=>[{children:e.routes?.map(Si),element:jsx(gr,{children:e.component}),path:e.name}],[e]);return useRoutes(o,t)}function Fl({segment:e}){return jsx("div",{className:"fk:flex fk:h-full fk:grow fk:items-center fk:justify-center fk:p-8",children:jsxs(Rc,{className:"fk:max-w-lg",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Sc,{children:"App not found"}),jsxs(Tc,{children:['There is no Studio app named "',e,'".']})]})})}function Ai({activeApp:e,apps:t,sessions:o}){let r=useLocation(),n=ao(r.pathname,o.projectId);return jsxs(Fragment,{children:[o.order.map(i=>{let a=t.find(s=>s.name===i),c=o.locations[i];if(!a||!c)return null;let f=i===e;return jsx("div",{"aria-hidden":f?void 0:true,"data-studio-app":i,style:{display:f?"contents":"none"},children:jsx(a$9.Provider,{value:f,children:jsx(El,{app:a,location:c})})},i)}),e===void 0&&n!==void 0?jsx(Fl,{segment:n}):null]})}var Pl=lazy(()=>import('./logo-JAWR6P43.js').then(({Logo:e})=>({default:e}))),Rl=lazy(()=>import('./project-selector-72VM6SUI.js').then(({ProjectSelector:e})=>({default:e}))),Ll=lazy(()=>import('./search-Q65IC67C.js').then(({Search:e})=>({default:e}))),Ml=lazy(()=>import('./activity-nav-button-AESIPODJ.js').then(({ActivityNavButton:e})=>({default:e}))),_l=lazy(()=>import('./user-nav-QZTYBG45.js').then(({UserNav:e})=>({default:e})));function Ni({projectId:e,projectIds:t,projectSummaries:o=[],projects:r}){let{resolvedTheme:n}=b$8(),i=r.find(l=>l.projectId===e),a=o.find(l=>l.id===e),c=i?.schema??[],f=useNavigate();function s(l){startTransition(()=>{f(`/${e}/desk/list/${l.entityNamePlural}?id=${l.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-14 fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-30",children:[jsx(Suspense,{fallback:null,children:jsx(Pl,{theme:n,title:i?.title??a?.name??"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(Rl,{projectId:e,projectIds:t,projectSummaries:o,projects:r})}),jsx(Suspense,{fallback:null,children:jsx(Ll,{onSelect:s,projectId:e,schema:c},e)})]}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-x-4",children:[jsx(Suspense,{fallback:null,children:jsx(Ml,{projectId:e})}),jsx(Suspense,{fallback:null,children:jsx(_l,{projectId:e})})]})]})}function Fi({projectId:e,error:t,showHomeLink:o=false}){let r=t.status===404,n=t.status===401||t.status===403,i=r?"No deployed schema":n?"No access to this project":"Could not load the project schema",a=r?`Project "${e}" has no deployed schema yet. Run \`flexkit deploy\` from the folder containing its flexkit.config.ts.`:n?`Your account is not a member of project "${e}". Ask a project owner to invite you.`:`${t.message} (project "${e}").`;return jsx("div",{className:"fk:flex fk:h-full fk:items-center fk:justify-center fk:p-8",children:jsxs(Rc,{className:"fk:max-w-lg",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Sc,{children:i}),jsxs(Tc,{className:"fk:flex fk:flex-col fk:gap-2",children:[jsx("span",{children:a}),o?jsx(Link$1,{className:"fk:underline fk:underline-offset-4",to:"/",children:"Back to your projects"}):null]})]})})}function Ii({version:e}){let{apps:t,currentProject:o,isLoadingSchemas:r,mode:n,projectIds:i,projects:a,projectSummaries:c,schemaErrors:f}=f$2(),[s,l]=h(),{projectId:m=""}=useParams(),d=o?.scopes,p=d$1(),k=useLocation(),A=i.includes(m),b=wi(t,m);if(useEffect(()=>{if(d&&d.length>0){let D=d.find(g=>g.isDefault)??d[0],y="";typeof localStorage<"u"&&(y=localStorage.getItem(`${a$6}${m}`)??""),p({type:"setScope",payload:{projectId:m,scope:y||D.name}});}},[p,k,m,d]),useEffect(()=>{n==="hosted"&&A&&o&&ci(m);},[o,A,n,m]),!A){if(n==="projects")throw new Ro("PROJECT_NOT_FOUND");return jsx(Fi,{error:{status:403,message:"No access to this project"},projectId:m,showHomeLink:true})}if(s)return jsx(a$7,{});if(!l.user?.id)return jsx(Po,{projectId:n==="hosted"?void 0:m});if(r)return jsx(a$7,{});let E=f[m];return jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(Ni,{projectId:m,projectIds:i,projectSummaries:c,projects:a}),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(Ci,{apps:t,version:e,...b}),o?jsx(Ai,{apps:t,...b}):jsx(Fi,{error:E??{status:0,message:"The project schema is not available."},projectId:m,showHomeLink:n==="hosted"})]})]}),jsx(ki,{projectId:m}),jsx(pa$1,{})]})}async function $l(){try{let e=await fetch(d$2.me,{credentials:"same-origin"});return e.status===401?{kind:"anonymous"}:e.ok?{kind:"ready",data:await e.json()}:{kind:"error",message:`Flexkit answered ${String(e.status)} while loading your projects.`}}catch(e){return {kind:"error",message:e instanceof Error?e.message:"Flexkit is not reachable."}}}function ql(e){return e?e.kind==="anonymous"?{status:"anonymous"}:e.kind==="error"?{status:"error",message:e.message}:{status:"ready",projects:e.data.projects,user:e.data.user}:{status:"loading"}}function Ti(){let{data:e}=Os("hosted-session",$l,{revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false});return ql(e)}function Di({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function yr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function Jl({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$2("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 Pi({className:e,size:t="default",...o}){return jsxs(yr,{children:[jsx(Jl,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$2("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 fk:corner-squircle",e),...o})]})}function Ri({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$2("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 Li({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$2("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 Mi({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$2("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 _i({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$2("fk:text-sm fk:text-muted-foreground",e),...t})}function Oi({className:e,variant:t="default",size:o="default",...r}){return jsx(b$2,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$2(e),...r})})}function Bi({className:e,variant:t="outline",size:o="default",...r}){return jsx(b$2,{variant:t,size:o,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$2(e),...r})})}function mo({options:e}){let[t,o]=useState(false),[r,n]=useState(false),[i,a]=useState(false);useEffect(()=>{o(true);},[]);function c(){o(false),i||e.dialogActionCancel?.(),i&&a(false);}async function f(){n(true),a(true),o(false),await new Promise(s=>{globalThis.setTimeout(s,150);});try{let s=e.dialogActionSubmit?.();s&&typeof s.then=="function"&&await s;}finally{n(false);}}return jsx(Di,{onOpenChange:c,open:t,children:jsx(yr,{children:jsxs(Pi,{className:"sm:max-w-[425px]",children:[jsxs(Ri,{children:[jsx(Mi,{children:e.dialogTitle}),jsx(_i,{children:e.dialogMessage})]}),jsxs(Li,{children:[jsx(Bi,{disabled:r,onClick:c,children:e.dialogCancelTitle}),jsxs(Oi,{className:a$3({variant:e.isDestructive?"destructive":"default"}),disabled:r,onClick:f,children:[r?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}function Cr({action:e}){let{currentProject:t}=f$2(),o=t?.schema??[],r=useApolloClient(),[n,i,a]=C(),c=A(),f=useRef(false),s=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],l=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),m=!!e.payload.silent,d=s.length>1;if(useEffect(()=>{!m||f.current||(f.current=true,k());},[m]),m)return jsx(Fragment,{});let p={dialogTitle:d?`Delete ${s.length} ${l}s`:`Delete ${l}`,dialogMessage:d?`Are you sure you want to delete the selected ${l}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${l}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>k()};function k(){let A=h$3(e.payload.entityName,o,s);return new Promise((b,E)=>{i(gql`
|
|
2
2
|
${A}
|
|
3
|
-
`),a({variables:{where:i$1(s)},update(T){for(let y of s)T.evict({id:y});},onCompleted:()=>{toast.success(d?"Items successfully deleted.":"Item successfully deleted."),p$2(r,o$3(e.payload.entityName,o),s),c({type:"Dismiss",_id:e._id,payload:{}}),b();},onError:T=>{E(T);}}),n(true);})}return jsx(fo,{options:p})}var Ti=createContext({isDirty:false,setIsDirty:e=>{}}),Pi=({children:e})=>{let[t,o]=useState(false),r=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(Ti.Provider,{value:r,children:e})};function Vt(){return useContext(Ti)}function Fe({scope:e,checked:t,disabled:o,onChange:r}){let n=useId();return !e||e==="default"?null:jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx(o$1,{checked:t,disabled:o,id:n,onCheckedChange:r}),jsx("label",{className:"fk:text-xs fk:font-normal fk:leading-none fk:peer-disabled:cursor-not-allowed fk:peer-disabled:opacity-70",htmlFor:n,children:"Use default value"})]})}function yr({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a}=t,c=useId();function f(l,u){r(n$1,{...u,value:l.currentTarget.value});}function s$1(l,u){r(n$1,{...u,disabled:l});}return jsx(h$1,{control:e,name:n$1,render:({field:l$1})=>jsxs(j,{children:[jsx(k,{htmlFor:c,children:i}),a?.comment?jsx(m,{children:a.comment}):null,jsx(l,{children:jsx(s,{className:"fk:w-full fk:mt-0.75",disabled:o||l$1.value?.disabled,id:c,...l$1,onChange:u=>{f(u,l$1.value);},value:l$1.value?.value||""})}),jsx(Fe,{checked:l$1.value?.disabled??false,disabled:o,onChange:u=>{s$1(u,l$1.value);},scope:l$1.value?.scope}),jsx(n,{})]})})}function Li({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a}=t;function c(s,l){r(n$1,{...l,value:s});}function f(s,l){r(n$1,{...l,disabled:s});}return jsx(h$1,{control:e,name:n$1,render:({field:s})=>jsxs(j,{children:[jsxs("div",{className:"fk:flex fk:flex-row fk:items-center fk:justify-between fk:rounded-lg fk:border fk:border-input fk:p-3 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 fk:disabled:cursor-not-allowed fk:disabled:opacity-50 fk:corner-squircle",children:[jsxs("div",{className:"fk:space-y-0.5",children:[jsx(k,{children:i}),a?.comment?jsx(m,{children:a.comment}):null]}),jsx(l,{children:jsx(ca$1,{checked:s.value?.value?!!s.value.value:false,disabled:o||s.value?.disabled,onCheckedChange:l=>{c(l,s.value);}})})]}),jsx(Fe,{checked:s.value?.disabled??false,disabled:o,onChange:l=>{f(l,s.value);},scope:s.value?.scope}),jsx(n,{})]})})}function zt(e,t,o){useEffect(()=>{function r(n){if(e.current&&!e.current.contains(n.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(n.target))return}t(false);}}return document.addEventListener("mousedown",r),()=>{document.removeEventListener("mousedown",r);}},[t,e,o]),useEffect(()=>{function r(n){if(e.current&&!e.current.contains(n.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(n.target))return}t(false);}}return document.addEventListener("focusin",r),()=>{document.removeEventListener("mousedown",r);}},[t,e]);}function Hi({control:e,entityId:t,fieldSchema:o$1,getValues:r$1,readOnly:n$1,setValue:i$1}){let{name:a,label:c,options:f}=o$1,{projectId:s}=useParams(),l$1=A(),u=d$1(),{relationships:d}=c$1(),[p$1,k$1]=useState(false),A$1=useRef(null),b=useRef(null),E=useRef(null),[T,y]=useState(null),[g,N]=useState(false),[O$1,M$1]=useState(false),D=useId(),B=useId();zt(b,k$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let h=d[B]?.connect;if(!h||E.current===h._id)return;let m=ef(h.value);if(!m)return;let _=r$1(a);E.current=h._id,y(null),i$1(a,{..._,value:m});},[r$1,a,B,d,i$1]);function $(h){if(!h)return;let m={"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(m[h])return m[h];let _=h.split("/");if(_.length===2){let[,G]=_;return G.includes("svg")?"svg":G.toLowerCase()}}function V(h,m){if(h&&h.includes(".")){let G=h.split(".").pop();if(G)return G.toLowerCase()}let _=$(m);return _||"file"}async function R(h,m){if(n$1||!h)return;let _=xr("4MB");if(h.size>(_??0)){toast.error("File size too big (max 4MB)");return}let G=h.type.startsWith("image/");if(E.current=null,G){let le=new FileReader;le.onload=ue=>{y(ue.target?.result);},le.readAsDataURL(h);}else y(null);M$1(true);try{let le=await b$4(h,s);i$1(a,{...r$1(a),value:le.asset});}catch(le){console.error(le),y(null),i$1(a,{...r$1(a),value:{_id:m?.value?._id}});}finally{M$1(false);}}function P(h){n$1||(h.stopPropagation(),E.current=null,i$1(a,{...r$1(a),_id:"",value:{_id:r$1(a)?.value?._id}}));}function K$1(h,m){h.stopPropagation(),m?.value&&typeof m.value=="object"&&"path"in m.value&&navigator.clipboard.writeText(`${c$2}${m.value.path}`);}function C(h){h.preventDefault(),h.stopPropagation(),!n$1&&A$1.current?.click();}function L$1(h){if(h.preventDefault(),h.stopPropagation(),n$1)return;k$1(false);let m=r$1(a)?.value,_=E.current??tf(m),G=_?{_id:_,value:m}:void 0;u({type:"setRelationship",payload:{[B]:{connect:G,disconnect:[]}}}),window.setTimeout(()=>{l$1({type:"EditRelationship",payload:{assetAccept:f?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:m?.path,initialConnection:G,relationshipId:B,mode:"single"}});},0);}function H(h,m){h.stopPropagation(),m?.value&&typeof m.value=="object"&&"path"in m.value&&window.open(`${c$2}${m.value.path}?download=1`,"_blank");}return jsx(h$1,{control:e,name:a,render:({field:h})=>jsxs(j,{children:[jsx(k,{htmlFor:D,children:c}),f?.comment?jsx(m,{children:f.comment}):null,jsx(l,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${a}`,"aria-expanded":p$1,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${p$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${g?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"} fk:corner-squircle`,onClick:m=>{m.preventDefault(),m.stopPropagation(),b.current?.focus(),b.current?.click(),k$1(true);},onKeyDown:m=>{m.key==="Enter"&&k$1(true),m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),b.current?.blur(),k$1(false));},onDragOver:m=>{n$1||(m.preventDefault(),m.stopPropagation(),N(true));},onDragEnter:m=>{n$1||(m.preventDefault(),m.stopPropagation(),N(true));},onDragLeave:m=>{n$1||(m.preventDefault(),m.stopPropagation(),N(false));},onDrop:m=>{if(m.preventDefault(),m.stopPropagation(),N(false),n$1)return;let _=m.dataTransfer.files&&m.dataTransfer.files[0];R(_,h.value);},ref:b,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!h.value?.value?.path&&!T?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(d$2,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:n$1,id:D,onClick:C,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(d$2,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:n$1,onClick:L$1,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,h.value?.value?.path&&!p$1?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let m=h.value?.value,_=m?.mimeType,G=m?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(G)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down fk:corner-squircle",src:`${c$2}${m.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let ue=V(m.originalFilename,m.mimeType),Be=defaultStyles[ue];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 fk:corner-squircle",children:jsx(FileIcon,{extension:ue,...Be||{}})})})(),xr((h.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(h.value?.value).mimeType,(h.value?.value).width&&(h.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(h.value?.value).width,"x",(h.value?.value).height,"px"]}):null]}):null,!h.value?.value?.path&&T&&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:T,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover fk:corner-squircle"}),"Loading image..."]}),!h.value?.value?.path&&!T&&O$1?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 fk:corner-squircle",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,h.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(e$1,{modal:false,children:[jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(g$2,{asChild:true,children:jsx(d$2,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm fk:corner-squircle",onClick:m=>{m.stopPropagation();},onPointerDown:m=>{m.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(O,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(h$2,{className:"fk:w-48",children:[jsxs(i,{children:[jsxs(j$1,{disabled:n$1,onClick:C,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(j$1,{disabled:n$1,onClick:L$1,children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(o,{}),jsxs(i,{children:[jsxs(j$1,{onClick:m=>H(m,h.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(j$1,{onClick:m=>K$1(m,h.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(o,{}),jsxs(j$1,{disabled:n$1,onClick:P,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!p$1&&(h.value?.value?.path||T)?jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(d$2,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",onKeyDown:m=>{m.key==="Enter"&&(b.current?.focus(),b.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(O,{children:jsx("p",{children:"Expand field"})})]})}):null}),p$1&&(h.value?.value?.path||T)?jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(d$2,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",onClick:m=>{m.preventDefault(),m.stopPropagation(),b.current?.blur(),k$1(false);},onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),m.stopPropagation(),b.current?.blur(),k$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(O,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(p,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:k$1,open:p$1&&(!!h.value?.value?.path||!!T),children:jsx(r,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${a}`,children:h.value?.value?.path?(()=>{let m=h.value?.value,_=m?.mimeType,G=m?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(G)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down fk:corner-squircle",src:`${c$2}${m.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let ue=V(m.originalFilename,m.mimeType),Be=defaultStyles[ue];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 fk:corner-squircle",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 fk:corner-squircle",children:jsx(FileIcon,{extension:ue,...Be||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[m.originalFilename||"File"," \xB7 ",xr(m.size)," \xB7 ",m.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),O$1?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:f?.accept?f.accept:"image/*",className:"fk:hidden",disabled:n$1,id:`file-upload-${a}`,onChange:m=>{let _=m.currentTarget.files&&m.currentTarget.files[0];R(_,h.value);},ref:A$1,type:"file"}),jsx(n,{})]})})}function ef(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 tf(e){return !e?._id||e._id.includes(":")?"":e._id}function qi({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a,dataType:c}=t,f=useId();function s$1(u,d){let p=u.currentTarget.value,k;p===""?k="":(k=c==="float"?parseFloat(p):parseInt(p,10),isNaN(k)&&(k="")),r(n$1,{...d,value:k});}function l$1(u,d){r(n$1,{...d,disabled:u});}return jsx(h$1,{control:e,name:n$1,render:({field:u})=>jsxs(j,{children:[jsx(k,{htmlFor:f,children:i}),a?.comment?jsx(m,{children:a.comment}):null,jsx(l,{children:jsx(s,{className:"fk:w-full fk:mt-0.75",disabled:o||u.value?.disabled,id:f,...u,onChange:d=>{s$1(d,u.value);},step:c==="float"?"any":"1",type:"number",value:u.value?.value??""})}),jsx(Fe,{checked:u.value?.disabled??false,disabled:o,onChange:d=>{l$1(d,u.value);},scope:u.value?.scope}),jsx(n,{})]})})}function Ji({className:e,classNames:t,showOutsideDays:o=true,captionLayout:r="label",buttonVariant:n="ghost",formatters:i,components:a,...c}){let f=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$1("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:r,formatters:{formatMonthDropdown:s=>s.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$1("w-fit",f.root),months:a$1("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",f.months),month:a$1("fk:flex fk:w-full fk:flex-col fk:gap-4",f.month),nav:a$1("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",f.nav),button_previous:a$1(c$5({variant:n}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_previous),button_next:a$1(c$5({variant:n}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_next),month_caption:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",f.month_caption),dropdowns:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",f.dropdowns),dropdown_root:a$1("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50 fk:corner-squircle",f.dropdown_root),dropdown:a$1("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",f.dropdown),caption_label:a$1("fk:font-medium fk:select-none",r==="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 fk:corner-squircle",f.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$1("fk:flex",f.weekdays),weekday:a$1("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none fk:corner-squircle",f.weekday),week:a$1("fk:mt-2 fk:flex fk:w-full",f.week),week_number_header:a$1("fk:w-(--cell-size) fk:select-none",f.week_number_header),week_number:a$1("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",f.week_number),day:a$1("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",c.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$1("fk:rounded-l-md fk:bg-accent fk:corner-squircle",f.range_start),range_middle:a$1("fk:rounded-none fk:corner-squircle",f.range_middle),range_end:a$1("fk:rounded-r-md fk:bg-accent fk:corner-squircle",f.range_end),today:a$1("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none fk:corner-squircle",f.today),outside:a$1("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",f.outside),disabled:a$1("fk:text-muted-foreground fk:opacity-50",f.disabled),hidden:a$1("invisible",f.hidden),...t},components:{Root:({className:s,rootRef:l,...u})=>jsx("div",{"data-slot":"calendar",ref:l,className:a$1(s),...u}),Chevron:({className:s,orientation:l,...u})=>l==="left"?jsx(ChevronLeftIcon,{className:a$1("size-4",s),...u}):l==="right"?jsx(ChevronRightIcon,{className:a$1("size-4",s),...u}):jsx(ChevronDownIcon,{className:a$1("size-4",s),...u}),DayButton:ff,WeekNumber:({children:s,...l})=>jsx("td",{...l,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:s})}),...a},...c})}function ff({className:e,day:t,modifiers:o,...r}){let n=getDefaultClassNames(),i=Oo.useRef(null);return Oo.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(d$2,{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$1("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",n.day,e),...r})}function Ui({control:e,fieldSchema:t$1,getValues:o,readOnly:r,setValue:n$1}){let{name:i,label:a,options:c}=t$1,f=useId();function s$1(d,p){n$1(i,{...p,value:d?d.toISOString():""});}function l$1(d,p){n$1(i,{...p,disabled:d});}function u$1(d){d.preventDefault(),n$1(i,{...o(i),value:void 0});}return jsx(h$1,{control:e,name:i,render:({field:d})=>jsxs(j,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(k,{htmlFor:f,children:a}),c?.comment?jsx(m,{children:c.comment}):null,jsx(l,{children:jsxs(t,{children:[jsx(u,{asChild:true,children:jsx(d$2,{className:a$1("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"),disabled:r||d.value?.disabled,id:f,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:p=>{p.stopPropagation(),u$1(p);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(v$1,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Ji,{mode:"single",selected:d.value?.value?new Date(d.value.value):void 0,onSelect:p=>s$1(p,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(s,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let k=p.target.value,[A,b]=k.split(":"),E=d.value?.value?new Date(d.value.value):new Date;E.setHours(parseInt(A)),E.setMinutes(parseInt(b)),n$1(i,{...d.value,value:E.toISOString()});},type:"time",value:d.value?.value?format(new Date(d.value.value),"HH:mm"):""})]})]})]})}),jsx(Fe,{checked:d.value?.disabled??false,disabled:r,onChange:p=>{l$1(p,d.value);},scope:d.value?.scope}),jsx(n,{})]})})}function Ce(e){return e??null}var Sr=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");}}]),Xi=Command.configure({suggestion:{items:()=>Sr,render:renderItems}});var Zi=[{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"}],Wi=[{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)"}],Qi=({open:e,onOpenChange:t$1})=>{let{editor:o}=useEditor();if(!o)return null;let r=Zi.find(({color:i})=>o.isActive("textStyle",{color:i})),n=Wi.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(t,{modal:true,open:e,onOpenChange:t$1,children:[jsx(u,{asChild:true,children:jsxs(d$2,{size:"sm",className:"fk:gap-2 fk:rounded-none fk:corner-squircle",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1 fk:corner-squircle",style:{color:r?.color,backgroundColor:n?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(v$1,{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 fk:corner-squircle",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"}),Zi.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t$1(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 fk:corner-squircle",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"}),Wi.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t$1(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 fk:corner-squircle",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 _f(e){try{return new URL(e),!0}catch{return false}}function Of(e){if(_f(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Yi=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:r}=useEditor();return useEffect(()=>{o.current?.focus();}),r?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(d$2,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none fk:corner-squircle",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$1("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":r.isActive("link")}),children:"Link"})]})}),jsx(v$1,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:n=>{let i=n.currentTarget;n.preventDefault();let a=i[0],c=Of(a.value);c&&(r.chain().focus().setLink({href:c}).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:r.getAttributes("link").href||""}),r.getAttributes("link").href?jsx(d$2,{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 fk:corner-squircle",onClick:()=>{r.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(d$2,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var ta=[{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")}],oa=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let r=ta.filter(n=>n.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 fk:corner-squircle",children:jsxs(d$2,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:r.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:ta.map(n=>jsxs(EditorBubbleItem,{onSelect:i=>{n.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 fk:corner-squircle",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 fk:corner-squircle",children:jsx(n.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:n.name})]}),r.name===n.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},n.name))})]})};var na=()=>{let{editor:e}=useEditor();return e?jsx(d$2,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12 fk:corner-squircle",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:r}=e.state.selection,n=e.state.doc.textBetween(o,r);if(!n)return;e.chain().focus().setLatex({latex:n}).run();}},children:jsx(SigmaIcon,{className:a$1("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var ia=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let r=Ce(o);r&&r.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let r=Ce(o);r&&r.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 r=Ce(o);r&&r.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let r=Ce(o);r&&r.chain().focus().toggleCode().run();},icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:r=>{o.command(r);},children:jsx(d$2,{size:"sm",className:"fk:rounded-none fk:corner-squircle",onClick:r=>r.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a$1("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 ic=()=>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] fk:corner-squircle"}),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] fk:corner-squircle"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 fk:corner-squircle"})]}),aa=ic;function Fr({completion:e,onDiscard:t}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r$1,{children:[jsxs(t$1,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:r}=o.view.state;o.chain().focus().insertContentAt({from:r.from,to:r.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(t$1,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:r}=o.view.state;o.chain().focus().insertContentAt(r.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s$1,{}),jsx(r$1,{children:jsxs(t$1,{onSelect:t,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var yc=[{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 Dr({onSelect:e}){let{editor:t}=useEditor();return t?jsxs(Fragment,{children:[jsx(r$1,{heading:"Edit or review selection",children:yc.map(o=>jsxs(t$1,{onSelect:r=>{let n=t.state.selection.content(),i=t.storage.markdown.serializer.serialize(n.content);e(i,r);},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$1,{}),jsx(r$1,{heading:"Use AI to do more",children:jsxs(t$1,{onSelect:()=>{let o=t.state.selection.from,r=getPrevText(t,o);e(r,"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 la({onOpenChange:e}){let{editor:t}=useEditor(),[o,r]=useState(""),{projectId:n}=useParams(),{completion:i,complete:a,isLoading:c}=useCompletion({api:e$3(n).completion,fetch:async(s,l)=>{let u=await fetch(s,l);if(u.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return u},onError:s=>{s.message!=="FK_AI_RATE_LIMIT"&&toast.error(s.message);}}),f=i.length>0;return t?jsxs(m$1,{className:"fk:w-[350px]",children:[f&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(w,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(Ec,{children:i})})})}),c&&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(aa,{})})]}),!c&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o$2,{value:o,onValueChange:r,autoFocus:true,placeholder:f?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(d$2,{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 fk:corner-squircle",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o}}).then(()=>r(""));let s=t.state.selection.content(),l=t.storage.markdown.serializer.serialize(s.content);a(l,{body:{option:"zap",command:o}}).then(()=>r(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p$1,{children:f?jsx(Fr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(Dr,{onSelect:(s,l)=>a(s,{body:{option:l}})})})]})]}):null}function Pr({children:e,open:t,onOpenChange:o}){let{editor:r}=useEditor();return useEffect(()=>{r&&(t||removeAIHighlight(r));},[r,t]),r?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),r.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 fk:corner-squircle",children:[t&&jsx(la,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(d$2,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600 fk:corner-squircle",variant:"ghost",onClick:n=>{n.preventDefault(),o(true);},size:"sm",children:[jsx(co,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var Jc=[...D,Xi];function ca(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 Uc(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(ca(o))return o}catch{return}}if(ca(e))return e}function Rr({control:e,defaultValue:t,fieldSchema:o,readOnly:r,setValue:n$1}){let{name:i,label:a,options:c}=o,[f,s]=useState(false),[l$1,u]=useState(false),[d,p]=useState(false),[k$1,A]=useState(false),b=useDebouncedCallback((y,g)=>{let N=y.getJSON();n$1(i,{...g,value:JSON.stringify(N)});},300);function E(y,g){n$1(i,{...g,disabled:y});}let T=y=>(console.log("Image uploader not yet implemented",y),Promise.resolve("https://via.placeholder.com/150"));return jsx(h$1,{control:e,name:i,render:({field:y})=>jsxs(j,{children:[jsx(k,{children:a}),c?.comment?jsx(m,{children:c.comment}):null,jsx(l,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-5xl fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2 fk:corner-squircle",editable:!r&&!y.value?.disabled,editorProps:{handleDOMEvents:{keydown:(g,N)=>handleCommandNavigation(N)},handlePaste:(g,N)=>handleImagePaste(g,N,T),handleDrop:(g,N,O,M)=>handleImageDrop(g,N,M,T),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:corner-squirclefk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:Jc,initialContent:Uc(y.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:g})=>{b(g,y.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 fk:corner-squircle",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Sr.map(g=>jsxs(EditorCommandItem,{value:g.title,onCommand:N=>g.command?.(N),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted fk:corner-squircle",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 fk:corner-squircle",children:g.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:g.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:g.description})]})]},g.title))})]}),jsxs(Pr,{open:f,onOpenChange:s,children:[jsx(v,{orientation:"vertical"}),jsx(oa,{open:l$1,onOpenChange:u}),jsx(v,{orientation:"vertical"}),jsx(Yi,{open:d,onOpenChange:p}),jsx(v,{orientation:"vertical"}),jsx(na,{}),jsx(v,{orientation:"vertical"}),jsx(ia,{}),jsx(v,{orientation:"vertical"}),jsx(Qi,{open:k$1,onOpenChange:A})]})]},`${i}:${y.value?.scope??t.scope}:${String(y.value?.disabled??t.disabled)}`)})}),jsx(Fe,{checked:y.value?.disabled??false,disabled:r,onChange:g=>{E(g,y.value);},scope:y.value?.scope}),jsx(n,{})]})})}function ma({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a}=t;function c(s,l){r(n$1,{...l,value:s.currentTarget.value});}function f(s,l){r(n$1,{...l,disabled:s});}return jsx(h$1,{control:e,name:n$1,render:({field:s})=>jsxs(j,{children:[jsxs("div",{className:"fk:flex",children:[jsxs("div",{className:"fk:full-w fk:grid fk:gap-2",children:[jsx(k,{children:i}),a?.comment?jsx(m,{children:a.comment}):null]}),jsx("div",{className:"fk:h-full fk:self-end fk:ml-auto"})]}),jsx(l,{children:jsx(pa,{className:"fk:w-full fk:mt-0.75",disabled:o||s.value?.disabled,...s,onChange:l=>{c(l,s.value);},value:s.value?.value||""})}),jsx(Fe,{checked:s.value?.disabled??false,disabled:o,onChange:l=>{f(l,s.value);},scope:s.value?.scope}),jsx(n,{})]})})}var om=a$2;function Br({control:e,defaultValue:t,entityId:o,entityName:r$1,entityNamePlural:n$1,fieldSchema:i,readOnly:a,schema:c,setValue:f}){let{name:s,label:l$2,options:u,relationship:d}=i,{projectId:p$1}=useParams(),k$1=A(),A$1=d$1(),{relationships:b}=c$1(),E=c$3(),T=useId(),y=useId(),g=useRef(null),N=useRef([]),O$1=useRef(null),M$1=useRef([]),D=useRef(""),B=useRef(t.knownAssetSortOrders??{}),[$,V]=useState(false),R=useMemo(()=>im(t.value),[t.value]),[P,K$1]=useState(R),[C,L$1]=useState(()=>Object.keys(t.knownAssetSortOrders??c$4(R)).length),[H,h]=useState(()=>Math.max(t.count??0,R[0]?.totalCount??0,R.length)),m$1=useMemo(()=>l$1({attributeName:s,entityName:r$1,entityNamePlural:n$1,schema:c}),[r$1,n$1,s,c]),[_,{loading:G}]=useLazyQuery(gql`
|
|
4
|
-
${
|
|
5
|
-
`);zt(g,V),useEffect(()=>{let S=
|
|
3
|
+
`),a({variables:{where:i$1(s)},update(D){for(let y of s)D.evict({id:y});},onCompleted:()=>{toast.success(d?"Items successfully deleted.":"Item successfully deleted."),p$2(r,o$3(e.payload.entityName,o),s),c({type:"Dismiss",_id:e._id,payload:{}}),b();},onError:D=>{E(D);}}),n(true);})}return jsx(mo,{options:p})}var Vi=createContext({isDirty:false,setIsDirty:e=>{}}),zi=({children:e})=>{let[t,o]=useState(false),r=useMemo(()=>({isDirty:t,setIsDirty:i=>{o(i);}}),[t,o]);return jsx(Vi.Provider,{value:r,children:e})};function Vt(){return useContext(Vi)}function Ie({scope:e,checked:t,disabled:o,onChange:r}){let n=useId();return !e||e==="default"?null:jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx(o$1,{checked:t,disabled:o,id:n,onCheckedChange:r}),jsx("label",{className:"fk:text-xs fk:font-normal fk:leading-none fk:peer-disabled:cursor-not-allowed fk:peer-disabled:opacity-70",htmlFor:n,children:"Use default value"})]})}function xr({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a}=t,c=useId();function f(l,m){r(n$1,{...m,value:l.currentTarget.value});}function s$1(l,m){r(n$1,{...m,disabled:l});}return jsx(h$1,{control:e,name:n$1,render:({field:l$1})=>jsxs(j,{children:[jsx(k,{htmlFor:c,children:i}),a?.comment?jsx(m,{children:a.comment}):null,jsx(l,{children:jsx(s,{className:"fk:w-full fk:mt-0.75",disabled:o||l$1.value?.disabled,id:c,...l$1,onChange:m=>{f(m,l$1.value);},value:l$1.value?.value||""})}),jsx(Ie,{checked:l$1.value?.disabled??false,disabled:o,onChange:m=>{s$1(m,l$1.value);},scope:l$1.value?.scope}),jsx(n,{})]})})}function $i({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a}=t;function c(s,l){r(n$1,{...l,value:s});}function f(s,l){r(n$1,{...l,disabled:s});}return jsx(h$1,{control:e,name:n$1,render:({field:s})=>jsxs(j,{children:[jsxs("div",{className:"fk:flex fk:flex-row fk:items-center fk:justify-between fk:rounded-lg fk:border fk:border-input fk:p-3 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 fk:disabled:cursor-not-allowed fk:disabled:opacity-50 fk:corner-squircle",children:[jsxs("div",{className:"fk:space-y-0.5",children:[jsx(k,{children:i}),a?.comment?jsx(m,{children:a.comment}):null]}),jsx(l,{children:jsx(Z,{checked:s.value?.value?!!s.value.value:false,disabled:o||s.value?.disabled,onCheckedChange:l=>{c(l,s.value);}})})]}),jsx(Ie,{checked:s.value?.disabled??false,disabled:o,onChange:l=>{f(l,s.value);},scope:s.value?.scope}),jsx(n,{})]})})}function zt(e,t,o){useEffect(()=>{function r(n){if(e.current&&!e.current.contains(n.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(n.target))return}t(false);}}return document.addEventListener("mousedown",r),()=>{document.removeEventListener("mousedown",r);}},[t,e,o]),useEffect(()=>{function r(n){if(e.current&&!e.current.contains(n.target)){if(o){let i=Array.from(document.querySelectorAll(o));for(let a of i)if(a.contains(n.target))return}t(false);}}return document.addEventListener("focusin",r),()=>{document.removeEventListener("mousedown",r);}},[t,e]);}function Ki({control:e,entityId:t,fieldSchema:o$1,getValues:r$1,readOnly:n$1,setValue:i$1}){let{name:a,label:c,options:f}=o$1,{projectId:s}=useParams(),l$1=A(),m$1=d$1(),{relationships:d}=c$1(),[p$1,k$1]=useState(false),A$1=useRef(null),b=useRef(null),E=useRef(null),[D,y]=useState(null),[g,N]=useState(false),[O,M]=useState(false),T=useId(),B=useId();zt(b,k$1,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let h=d[B]?.connect;if(!h||E.current===h._id)return;let u=xf(h.value);if(!u)return;let _=r$1(a);E.current=h._id,y(null),i$1(a,{..._,value:u});},[r$1,a,B,d,i$1]);function q(h){if(!h)return;let u={"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(u[h])return u[h];let _=h.split("/");if(_.length===2){let[,G]=_;return G.includes("svg")?"svg":G.toLowerCase()}}function V(h,u){if(h&&h.includes(".")){let G=h.split(".").pop();if(G)return G.toLowerCase()}let _=q(u);return _||"file"}async function R(h,u){if(n$1||!h)return;let _=Ar("4MB");if(h.size>(_??0)){toast.error("File size too big (max 4MB)");return}let G=h.type.startsWith("image/");if(E.current=null,G){let le=new FileReader;le.onload=ue=>{y(ue.target?.result);},le.readAsDataURL(h);}else y(null);M(true);try{let le=await b$6(h,s);i$1(a,{...r$1(a),value:le.asset});}catch(le){console.error(le),y(null),i$1(a,{...r$1(a),value:{_id:u?.value?._id}});}finally{M(false);}}function P(h){n$1||(h.stopPropagation(),E.current=null,i$1(a,{...r$1(a),_id:"",value:{_id:r$1(a)?.value?._id}}));}function Q(h,u){h.stopPropagation(),u?.value&&typeof u.value=="object"&&"path"in u.value&&navigator.clipboard.writeText(`${c$2}${u.value.path}`);}function C(h){h.preventDefault(),h.stopPropagation(),!n$1&&A$1.current?.click();}function L(h){if(h.preventDefault(),h.stopPropagation(),n$1)return;k$1(false);let u=r$1(a)?.value,_=E.current??wf(u),G=_?{_id:_,value:u}:void 0;m$1({type:"setRelationship",payload:{[B]:{connect:G,disconnect:[]}}}),window.setTimeout(()=>{l$1({type:"EditRelationship",payload:{assetAccept:f?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:u?.path,initialConnection:G,relationshipId:B,mode:"single"}});},0);}function H(h,u){h.stopPropagation(),u?.value&&typeof u.value=="object"&&"path"in u.value&&window.open(`${c$2}${u.value.path}?download=1`,"_blank");}return jsx(h$1,{control:e,name:a,render:({field:h})=>jsxs(j,{children:[jsx(k,{htmlFor:T,children:c}),f?.comment?jsx(m,{children:f.comment}):null,jsx(l,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${a}`,"aria-expanded":p$1,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${p$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${g?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"} fk:corner-squircle`,onClick:u=>{u.preventDefault(),u.stopPropagation(),b.current?.focus(),b.current?.click(),k$1(true);},onKeyDown:u=>{u.key==="Enter"&&k$1(true),u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),b.current?.blur(),k$1(false));},onDragOver:u=>{n$1||(u.preventDefault(),u.stopPropagation(),N(true));},onDragEnter:u=>{n$1||(u.preventDefault(),u.stopPropagation(),N(true));},onDragLeave:u=>{n$1||(u.preventDefault(),u.stopPropagation(),N(false));},onDrop:u=>{if(u.preventDefault(),u.stopPropagation(),N(false),n$1)return;let _=u.dataTransfer.files&&u.dataTransfer.files[0];R(_,h.value);},ref:b,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!h.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:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$2,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:n$1,id:T,onClick:C,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$2,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:n$1,onClick:L,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,h.value?.value?.path&&!p$1?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let u=h.value?.value,_=u?.mimeType,G=u?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(G)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down fk:corner-squircle",src:`${c$2}${u.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let ue=V(u.originalFilename,u.mimeType),Be=defaultStyles[ue];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 fk:corner-squircle",children:jsx(FileIcon,{extension:ue,...Be||{}})})})(),Ar((h.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(h.value?.value).mimeType,(h.value?.value).width&&(h.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(h.value?.value).width,"x",(h.value?.value).height,"px"]}):null]}):null,!h.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:[jsx("img",{src:D,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover fk:corner-squircle"}),"Loading image..."]}),!h.value?.value?.path&&!D&&O?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 fk:corner-squircle",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,h.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(e$1,{modal:false,children:[jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(g$2,{asChild:true,children:jsx(b$2,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm fk:corner-squircle",onClick:u=>{u.stopPropagation();},onPointerDown:u=>{u.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$2,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(h$2,{className:"fk:w-48",children:[jsxs(i,{children:[jsxs(j$1,{disabled:n$1,onClick:C,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(j$1,{disabled:n$1,onClick:L,children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(o,{}),jsxs(i,{children:[jsxs(j$1,{onClick:u=>H(u,h.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(j$1,{onClick:u=>Q(u,h.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(o,{}),jsxs(j$1,{disabled:n$1,onClick:P,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!p$1&&(h.value?.value?.path||D)?jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",onKeyDown:u=>{u.key==="Enter"&&(b.current?.focus(),b.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Expand field"})})]})}):null}),p$1&&(h.value?.value?.path||D)?jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",onClick:u=>{u.preventDefault(),u.stopPropagation(),b.current?.blur(),k$1(false);},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),u.stopPropagation(),b.current?.blur(),k$1(false));},size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(p,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:k$1,open:p$1&&(!!h.value?.value?.path||!!D),children:jsx(r,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${a}`,children:h.value?.value?.path?(()=>{let u=h.value?.value,_=u?.mimeType,G=u?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(G)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down fk:corner-squircle",src:`${c$2}${u.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let ue=V(u.originalFilename,u.mimeType),Be=defaultStyles[ue];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 fk:corner-squircle",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 fk:corner-squircle",children:jsx(FileIcon,{extension:ue,...Be||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[u.originalFilename||"File"," \xB7 ",Ar(u.size)," \xB7 ",u.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),O?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:f?.accept?f.accept:"image/*",className:"fk:hidden",disabled:n$1,id:`file-upload-${a}`,onChange:u=>{let _=u.currentTarget.files&&u.currentTarget.files[0];R(_,h.value);},ref:A$1,type:"file"}),jsx(n,{})]})})}function xf(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 wf(e){return !e?._id||e._id.includes(":")?"":e._id}function Qi({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a,dataType:c}=t,f=useId();function s$1(m,d){let p=m.currentTarget.value,k;p===""?k="":(k=c==="float"?parseFloat(p):parseInt(p,10),isNaN(k)&&(k="")),r(n$1,{...d,value:k});}function l$1(m,d){r(n$1,{...d,disabled:m});}return jsx(h$1,{control:e,name:n$1,render:({field:m$1})=>jsxs(j,{children:[jsx(k,{htmlFor:f,children:i}),a?.comment?jsx(m,{children:a.comment}):null,jsx(l,{children:jsx(s,{className:"fk:w-full fk:mt-0.75",disabled:o||m$1.value?.disabled,id:f,...m$1,onChange:d=>{s$1(d,m$1.value);},step:c==="float"?"any":"1",type:"number",value:m$1.value?.value??""})}),jsx(Ie,{checked:m$1.value?.disabled??false,disabled:o,onChange:d=>{l$1(d,m$1.value);},scope:m$1.value?.scope}),jsx(n,{})]})})}function ea({className:e,classNames:t,showOutsideDays:o=true,captionLayout:r="label",buttonVariant:n="ghost",formatters:i,components:a,...c}){let f=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:o,className:a$2("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:r,formatters:{formatMonthDropdown:s=>s.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$2("w-fit",f.root),months:a$2("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",f.months),month:a$2("fk:flex fk:w-full fk:flex-col fk:gap-4",f.month),nav:a$2("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$2(a$3({variant:n}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_previous),button_next:a$2(a$3({variant:n}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",f.button_next),month_caption:a$2("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",f.month_caption),dropdowns:a$2("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$2("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 fk:corner-squircle",f.dropdown_root),dropdown:a$2("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",f.dropdown),caption_label:a$2("fk:font-medium fk:select-none",r==="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 fk:corner-squircle",f.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$2("fk:flex",f.weekdays),weekday:a$2("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none fk:corner-squircle",f.weekday),week:a$2("fk:mt-2 fk:flex fk:w-full",f.week),week_number_header:a$2("fk:w-(--cell-size) fk:select-none",f.week_number_header),week_number:a$2("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",f.week_number),day:a$2("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",c.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$2("fk:rounded-l-md fk:bg-accent fk:corner-squircle",f.range_start),range_middle:a$2("fk:rounded-none fk:corner-squircle",f.range_middle),range_end:a$2("fk:rounded-r-md fk:bg-accent fk:corner-squircle",f.range_end),today:a$2("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none fk:corner-squircle",f.today),outside:a$2("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",f.outside),disabled:a$2("fk:text-muted-foreground fk:opacity-50",f.disabled),hidden:a$2("invisible",f.hidden),...t},components:{Root:({className:s,rootRef:l,...m})=>jsx("div",{"data-slot":"calendar",ref:l,className:a$2(s),...m}),Chevron:({className:s,orientation:l,...m})=>l==="left"?jsx(ChevronLeftIcon,{className:a$2("size-4",s),...m}):l==="right"?jsx(ChevronRightIcon,{className:a$2("size-4",s),...m}):jsx(ChevronDownIcon,{className:a$2("size-4",s),...m}),DayButton:Tf,WeekNumber:({children:s,...l})=>jsx("td",{...l,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:s})}),...a},...c})}function Tf({className:e,day:t,modifiers:o,...r}){let n=getDefaultClassNames(),i=Bo.useRef(null);return Bo.useEffect(()=>{o.focused&&i.current?.focus();},[o.focused]),jsx(b$2,{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$2("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",n.day,e),...r})}function ta({control:e,fieldSchema:t$1,getValues:o,readOnly:r,setValue:n$1}){let{name:i,label:a,options:c}=t$1,f=useId();function s$1(d,p){n$1(i,{...p,value:d?d.toISOString():""});}function l$1(d,p){n$1(i,{...p,disabled:d});}function m$1(d){d.preventDefault(),n$1(i,{...o(i),value:void 0});}return jsx(h$1,{control:e,name:i,render:({field:d})=>jsxs(j,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(k,{htmlFor:f,children:a}),c?.comment?jsx(m,{children:c.comment}):null,jsx(l,{children:jsxs(t,{children:[jsx(u,{asChild:true,children:jsx(b$2,{className:a$2("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"),disabled:r||d.value?.disabled,id:f,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:p=>{p.stopPropagation(),m$1(p);},role:"button","aria-label":"Clear date",children:jsx(X$1,{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(v$1,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(ea,{mode:"single",selected:d.value?.value?new Date(d.value.value):void 0,onSelect:p=>s$1(p,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(s,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let k=p.target.value,[A,b]=k.split(":"),E=d.value?.value?new Date(d.value.value):new Date;E.setHours(parseInt(A)),E.setMinutes(parseInt(b)),n$1(i,{...d.value,value:E.toISOString()});},type:"time",value:d.value?.value?format(new Date(d.value.value),"HH:mm"):""})]})]})]})}),jsx(Ie,{checked:d.value?.disabled??false,disabled:r,onChange:p=>{l$1(p,d.value);},scope:d.value?.scope}),jsx(n,{})]})})}function Ce(e){return e??null}var Er=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");}}]),oa=Command.configure({suggestion:{items:()=>Er,render:renderItems}});var na=[{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"}],ia=[{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)"}],aa=({open:e,onOpenChange:t$1})=>{let{editor:o}=useEditor();if(!o)return null;let r=na.find(({color:i})=>o.isActive("textStyle",{color:i})),n=ia.find(({color:i})=>o.isActive("highlight",{color:i}));return jsxs(t,{modal:true,open:e,onOpenChange:t$1,children:[jsx(u,{asChild:true,children:jsxs(b$2,{size:"sm",className:"fk:gap-2 fk:rounded-none fk:corner-squircle",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1 fk:corner-squircle",style:{color:r?.color,backgroundColor:n?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(v$1,{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 fk:corner-squircle",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"}),na.map(({name:i,color:a})=>jsx(EditorBubbleItem,{onSelect:()=>{o.commands.unsetColor(),i!=="Default"&&o.chain().focus().setColor(a||"").run(),t$1(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 fk:corner-squircle",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"}),ia.map(({name:i,color:a})=>jsxs(EditorBubbleItem,{onSelect:()=>{o.commands.unsetHighlight(),i!=="Default"&&o.chain().focus().setHighlight({color:a}).run(),t$1(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 fk:corner-squircle",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 rc(e){try{return new URL(e),!0}catch{return false}}function nc(e){if(rc(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var la=({open:e,onOpenChange:t})=>{let o=useRef(null),{editor:r}=useEditor();return useEffect(()=>{o.current?.focus();}),r?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$2,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none fk:corner-squircle",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$2("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":r.isActive("link")}),children:"Link"})]})}),jsx(v$1,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:n=>{let i=n.currentTarget;n.preventDefault();let a=i[0],c=nc(a.value);c&&(r.chain().focus().setLink({href:c}).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:r.getAttributes("link").href||""}),r.getAttributes("link").href?jsx(b$2,{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 fk:corner-squircle",onClick:()=>{r.chain().focus().unsetLink().run(),o.current&&(o.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$2,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var ca=[{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")}],ma=({open:e,onOpenChange:t})=>{let{editor:o}=useEditor();if(!o)return null;let r=ca.filter(n=>n.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 fk:corner-squircle",children:jsxs(b$2,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:r.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:ca.map(n=>jsxs(EditorBubbleItem,{onSelect:i=>{n.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 fk:corner-squircle",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 fk:corner-squircle",children:jsx(n.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:n.name})]}),r.name===n.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},n.name))})]})};var da=()=>{let{editor:e}=useEditor();return e?jsx(b$2,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12 fk:corner-squircle",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:o,to:r}=e.state.selection,n=e.state.doc.textBetween(o,r);if(!n)return;e.chain().focus().setLatex({latex:n}).run();}},children:jsx(SigmaIcon,{className:a$2("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var pa=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:o=>o!=null&&o.isActive("bold"),command:o=>{let r=Ce(o);r&&r.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:o=>o!=null&&o.isActive("italic"),command:o=>{let r=Ce(o);r&&r.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 r=Ce(o);r&&r.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:o=>o!=null&&o.isActive("code"),command:o=>{let r=Ce(o);r&&r.chain().focus().toggleCode().run();},icon:CodeIcon}].map(o=>jsx(EditorBubbleItem,{onSelect:r=>{o.command(r);},children:jsx(b$2,{size:"sm",className:"fk:rounded-none fk:corner-squircle",onClick:r=>r.preventDefault(),variant:"ghost",children:jsx(o.icon,{className:a$2("fk:h-4 fk:w-4",{"fk:text-blue-500":o.isActive(e)})})})},o.name))}):null};function uo({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 Nc=()=>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] fk:corner-squircle"}),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] fk:corner-squircle"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 fk:corner-squircle"})]}),ka=Nc;function Dr({completion:e,onDiscard:t}){let{editor:o}=useEditor();return o?jsxs(Fragment,{children:[jsxs(r$1,{children:[jsxs(t$1,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:r}=o.view.state;o.chain().focus().insertContentAt({from:r.from,to:r.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(t$1,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:r}=o.view.state;o.chain().focus().insertContentAt(r.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(s$1,{}),jsx(r$1,{children:jsxs(t$1,{onSelect:t,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var Vc=[{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}=useEditor();return t?jsxs(Fragment,{children:[jsx(r$1,{heading:"Edit or review selection",children:Vc.map(o=>jsxs(t$1,{onSelect:r=>{let n=t.state.selection.content(),i=t.storage.markdown.serializer.serialize(n.content);e(i,r);},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$1,{}),jsx(r$1,{heading:"Use AI to do more",children:jsxs(t$1,{onSelect:()=>{let o=t.state.selection.from,r=getPrevText(t,o);e(r,"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 ha({onOpenChange:e}){let{editor:t}=useEditor(),[o,r]=useState(""),{projectId:n}=useParams(),{completion:i,complete:a,isLoading:c}=useCompletion({api:e$4(n).completion,fetch:async(s,l)=>{let m=await fetch(s,l);if(m.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return m},onError:s=>{s.message!=="FK_AI_RATE_LIMIT"&&toast.error(s.message);}}),f=i.length>0;return t?jsxs(m$1,{className:"fk:w-[350px]",children:[f&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(w,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(Gc,{children:i})})})}),c&&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(uo,{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(ka,{})})]}),!c&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(o$2,{value:o,onValueChange:r,autoFocus:true,placeholder:f?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$2,{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 fk:corner-squircle",onClick:()=>{if(i)return a(i,{body:{option:"zap",command:o}}).then(()=>r(""));let s=t.state.selection.content(),l=t.storage.markdown.serializer.serialize(s.content);a(l,{body:{option:"zap",command:o}}).then(()=>r(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(p$1,{children:f?jsx(Dr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(Rr,{onSelect:(s,l)=>a(s,{body:{option:l}})})})]})]}):null}function Mr({children:e,open:t,onOpenChange:o}){let{editor:r}=useEditor();return useEffect(()=>{r&&(t||removeAIHighlight(r));},[r,t]),r?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{o(false),r.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 fk:corner-squircle",children:[t&&jsx(ha,{open:t,onOpenChange:o}),!t&&jsxs(Fragment$1,{children:[jsxs(b$2,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600 fk:corner-squircle",variant:"ghost",onClick:n=>{n.preventDefault(),o(true);},size:"sm",children:[jsx(uo,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var um=[...D,oa];function ya(e){if(!e||typeof e!="object")return false;let t=e;return !(typeof t.type!="string"&&typeof t.type<"u"||!Array.isArray(t.content)&&typeof t.content<"u")}function dm(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let o=JSON.parse(t);if(ya(o))return o}catch{return}}if(ya(e))return e}function _r({control:e,defaultValue:t,fieldSchema:o,readOnly:r,setValue:n$1}){let{name:i,label:a,options:c}=o,[f,s]=useState(false),[l$1,m$1]=useState(false),[d,p]=useState(false),[k$1,A]=useState(false),b=useDebouncedCallback((y,g)=>{let N=y.getJSON();n$1(i,{...g,value:JSON.stringify(N)});},300);function E(y,g){n$1(i,{...g,disabled:y});}let D=y=>(console.log("Image uploader not yet implemented",y),Promise.resolve("https://via.placeholder.com/150"));return jsx(h$1,{control:e,name:i,render:({field:y})=>jsxs(j,{children:[jsx(k,{children:a}),c?.comment?jsx(m,{children:c.comment}):null,jsx(l,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-5xl fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2 fk:corner-squircle",editable:!r&&!y.value?.disabled,editorProps:{handleDOMEvents:{keydown:(g,N)=>handleCommandNavigation(N)},handlePaste:(g,N)=>handleImagePaste(g,N,D),handleDrop:(g,N,O,M)=>handleImageDrop(g,N,M,D),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:corner-squirclefk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:um,initialContent:dm(y.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:g})=>{b(g,y.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 fk:corner-squircle",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Er.map(g=>jsxs(EditorCommandItem,{value:g.title,onCommand:N=>g.command?.(N),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted fk:corner-squircle",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 fk:corner-squircle",children:g.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:g.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:g.description})]})]},g.title))})]}),jsxs(Mr,{open:f,onOpenChange:s,children:[jsx(v,{orientation:"vertical"}),jsx(ma,{open:l$1,onOpenChange:m$1}),jsx(v,{orientation:"vertical"}),jsx(la,{open:d,onOpenChange:p}),jsx(v,{orientation:"vertical"}),jsx(da,{}),jsx(v,{orientation:"vertical"}),jsx(pa,{}),jsx(v,{orientation:"vertical"}),jsx(aa,{open:k$1,onOpenChange:A})]})]},`${i}:${y.value?.scope??t.scope}:${String(y.value?.disabled??t.disabled)}`)})}),jsx(Ie,{checked:y.value?.disabled??false,disabled:r,onChange:g=>{E(g,y.value);},scope:y.value?.scope}),jsx(n,{})]})})}function ba({control:e,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a}=t;function c(s,l){r(n$1,{...l,value:s.currentTarget.value});}function f(s,l){r(n$1,{...l,disabled:s});}return jsx(h$1,{control:e,name:n$1,render:({field:s})=>jsxs(j,{children:[jsxs("div",{className:"fk:flex",children:[jsxs("div",{className:"fk:full-w fk:grid fk:gap-2",children:[jsx(k,{children:i}),a?.comment?jsx(m,{children:a.comment}):null]}),jsx("div",{className:"fk:h-full fk:self-end fk:ml-auto"})]}),jsx(l,{children:jsx(ka$1,{className:"fk:w-full fk:mt-0.75",disabled:o||s.value?.disabled,...s,onChange:l=>{c(l,s.value);},value:s.value?.value||""})}),jsx(Ie,{checked:s.value?.disabled??false,disabled:o,onChange:l=>{f(l,s.value);},scope:s.value?.scope}),jsx(n,{})]})})}var wm=a$4;function zr({control:e,defaultValue:t,entityId:o,entityName:r$1,entityNamePlural:n$1,fieldSchema:i,readOnly:a,schema:c,setValue:f}){let{name:s,label:l$2,options:m$1,relationship:d}=i,{projectId:p$1}=useParams(),k$1=A(),A$1=d$1(),{relationships:b}=c$1(),E=c$4(),D=useId(),y=useId(),g=useRef(null),N=useRef([]),O=useRef(null),M=useRef([]),T=useRef(""),B=useRef(t.knownAssetSortOrders??{}),[q,V]=useState(false),R=useMemo(()=>Nm(t.value),[t.value]),[P,Q]=useState(R),[C,L]=useState(()=>Object.keys(t.knownAssetSortOrders??c$5(R)).length),[H,h]=useState(()=>Math.max(t.count??0,R[0]?.totalCount??0,R.length)),u=useMemo(()=>l$1({attributeName:s,entityName:r$1,entityNamePlural:n$1,schema:c}),[r$1,n$1,s,c]),[_,{loading:G}]=useLazyQuery(gql`
|
|
4
|
+
${u.query}
|
|
5
|
+
`);zt(g,V),useEffect(()=>{let S=rt(R);N.current=R.map(U=>U._id),M.current=[];let $={...t.knownAssetSortOrders??{},...c$5(R)};B.current=$,L(Object.keys($).length),h(Math.max(t.count??0,R[0]?.totalCount??0,R.length)),Q(U=>{let ie=rt(U);return S===""&&ie!==""&&T.current===ie||ie===S?U:(T.current=S,R)});},[t.count,t.knownAssetSortOrders,R]),useEffect(()=>{let S=b[y]?.connect;if(!S)return;let $=S.map((x,F)=>Sa(x.value,x.sortOrder??F)).filter(x=>!!x),U=rt($),ie=rt(P),fe=O.current;fe===ie&&U!==fe||(O.current=null,U!==ie&&Q($));},[y,b,P]),useEffect(()=>{let S=rt(P);if(T.current===S)return;let $=P.map((fe,x)=>({_id:fe._id,sortOrder:x,value:{...fe,sortOrder:x}})),U=P.map(fe=>fe._id),ie=M.current.filter(fe=>!U.includes(fe));T.current=S,A$1({type:"setRelationship",payload:{[y]:{connect:$,disconnect:ie}}}),f(s,{...t,knownAssetSortOrders:B.current,relationships:{connect:$,disconnect:ie},value:P});},[A$1,t,s,y,P,f]);let le=Math.max(H,C),ue=!!o&&le>C,Be=useCallback(()=>{if(!o||G||!ue)return;let S=C+wm;_({variables:{where:{_id:{eq:o}},first:S}}).then($=>{let U=$.data?.[n$1],fe=(Array.isArray(U)?U[0]:void 0)?.[`${s}Connection`],x=b$4(fe),F=x[0]?.totalCount;if(typeof F=="number"&&h(F),x.length===0){h(C);return}let X=Object.keys(B.current).length,Pe={...B.current,...c$5(x)},Ze=Object.keys(Pe).length;B.current=Pe,L(Ze),(x.length<S||Ze<=X)&&h(Ze);for(let W of x)N.current.includes(W._id)||(N.current=[...N.current,W._id]);Q(W=>{let er=new Set(W.map(bo=>bo._id)),tr=new Set(M.current),kn=x.filter(bo=>!er.has(bo._id)&&!tr.has(bo._id));if(kn.length===0)return T.current="",[...W];let gn=[...W,...kn];return O.current=rt(gn),gn});}).catch($=>{console.error("Error fetching more assets:",$);});},[o,n$1,_,ue,G,C,s]);function Z(S){S.preventDefault(),S.stopPropagation(),!a&&k$1({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(P.length,le),entityName:d?.entity??"_asset",entityId:o,relationshipId:y,mode:"multiple",assetAccept:m$1?.accept}});}async function De(S){if(S.preventDefault(),S.stopPropagation(),a)return;let $=await E({projectId:p$1,accept:m$1?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});Q(U=>{let ie=new Set(U.map(F=>F._id)),fe=$.map((F,X)=>({...F.asset,sortOrder:U.length+X})).filter(F=>!ie.has(F._id)),x=jr([...U,...fe]);return O.current=rt(x),x});}function je(S){Q($=>{let U=jr($.filter(ie=>ie._id!==S));return N.current.includes(S)&&!M.current.includes(S)&&(M.current=[...M.current,S]),O.current=rt(U),U});}function Ve(S,$){Q(U=>{let ie=U.findIndex(Pe=>Pe._id===S),fe=ie+$;if(ie<0||fe<0||fe>=U.length)return U;let x=[...U],[F]=x.splice(ie,1);if(!F)return U;x.splice(fe,0,F);let X=jr(x);return O.current=rt(X),X});}let Ge=Math.max(P.length,le),Ye=P.slice(0,8);return jsx(h$1,{control:e,defaultValue:t,name:s,render:()=>jsxs(j,{children:[jsx(k,{htmlFor:D,children:l$2}),m$1?.comment?jsx(m,{children:m$1.comment}):null,jsx(l,{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-${s}`,"aria-expanded":q,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 ${q?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} fk:corner-squircle`,onClick:S=>{S.preventDefault(),S.stopPropagation(),g.current?.focus(),V(true);},ref:g,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:[q&&P.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[Ge," ",Ge===1?"asset":"assets",ue?` (${P.length} loaded)`:""," selected"]}):P.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[Ye.map(S=>jsx(Sm,{asset:S},S._id)),!q&&Ge>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 fk:corner-squircle",children:["+",Ge-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",id:D,onClick:S=>{S.preventDefault(),S.stopPropagation(),V($=>!$);},size:"icon",variant:"ghost",children:q?jsx(X$1,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:q?"Close":"Expand field"})})]})})]}),jsx(p,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:V,open:q,children:jsx(r,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${s}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$2,{className:"fk:h-8",disabled:a,onClick:Z,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$2,{className:"fk:h-8",disabled:a,onClick:S=>{De(S);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),P.length>0?jsxs(w,{className:"fk:min-h-0 fk:flex-1",children:[jsx("div",{className:"fk:grid fk:grid-cols-[repeat(auto-fill,minmax(8rem,1fr))] fk:gap-3 fk:pr-3",children:P.map((S,$)=>jsx(Am,{asset:S,index:$,isFirst:$===0,isLast:$===P.length-1,moveAsset:Ve,readOnly:a,removeAsset:je},S._id))}),ue?jsx("div",{className:"fk:flex fk:justify-center fk:py-3 fk:pr-3",children:jsx(b$2,{className:"fk:h-8",disabled:G,onClick:S=>{S.preventDefault(),S.stopPropagation(),Be();},type:"button",variant:"outline",children:G?"Loading\u2026":`Load more (${C} of ${le})`})}):null]}):null]})})})]})})}),jsx(n,{})]})})}function Sm({asset:e}){return Aa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover fk:corner-squircle",src:`${c$2}${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 fk:corner-squircle",children:jsx(Image,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function Am({asset:e,index:t,isFirst:o,isLast:r,moveAsset:n,readOnly:i,removeAsset:a}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2 fk:corner-squircle",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted fk:corner-squircle",children:Aa(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${c$2}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$2,{className:"fk:h-7 fk:w-7",disabled:i||o,onClick:()=>n(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$2,{className:"fk:h-7 fk:w-7",disabled:i||r,onClick:()=>n(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$2,{className:"fk:ml-auto fk:h-7 fk:w-7",disabled:i,onClick:()=>a(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X$1,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Nm(e){return Array.isArray(e)?e.map((t,o)=>Sa(t,o)).filter(t=>!!t).sort((t,o)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(o.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function rt(e){return e.map((t,o)=>`${t._id}:${t.sortOrder??o}`).join("|")}function jr(e){return e.map((t,o)=>({...t,sortOrder:o}))}function Sa(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let o=e;return {_id:String(o._id??""),path:String(o.path??""),originalFilename:String(o.originalFilename??""),size:Number(o.size??0),mimeType:String(o.mimeType??""),lqip:String(o.lqip??""),width:Number(o.width??0),height:Number(o.height??0),sortOrder:o.sortOrder??t,totalCount:typeof o.totalCount=="number"?o.totalCount:void 0}}function Aa(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function Na({action:e,row:t}){let o=t.original._id;function r(){e(o);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$2,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:r,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var jm=25;function qr({control:e,defaultScope:t,defaultValue:o,entityId:r$1,entityName:n$1,fieldSchema:i,readOnly:a,schema:c,scope:f,setValue:s}){let[l$1,m$1]=useState(false),d=useRef(null);zt(d,m$1);let[p$1,k$2]=useState([]),{name:A$1,label:b,options:E,relationship:D}=i,y=D?.entity??A$1,g=A(),N=d$1(),{relationships:O}=c$1(),M=useId(),T=useId(),B=find(propEq(y,"name"))(c),q=B?.attributes??[],R=find(propEq(n$1,"name"))(c)?.name??"",P,Q=q.find(x=>x.relationship?.entity===R);Q&&(P=Q.name);let C=e$3(B)?.name??"",L=useMemo(()=>o.value?zm({data:o.value,defaultScope:t,relationshipEntitySchema:B,scope:f}):[],[t,o,C,B,f]),H=k$1({attributeName:A$1,relatedEntityName:y,scope:f,schema:c}),u=p$1.length?p$1.slice(0,12).map(x=>x[C]):[],_=Math.max(p$1.length,o.count??0)>u.length,[G,{loading:le,data:ue}]=useLazyQuery(gql`
|
|
6
6
|
${H.query}
|
|
7
|
-
`),Be=J({attributesSchema:B?.attributes??[],actionsComponent:a?void 0:x=>ym({appDispatch:N,relationshipId:D,relationships:O$1,row:x,setRows:k$2})});useEffect(()=>{k$2(L$1),o.value!==""&&N({type:"setRelationship",payload:{[D]:{connect:[],disconnect:[]}}});},[N,ue,L$1,D,o,f]),useEffect(()=>{s(A$1,{...o,relationships:O$1[D]});},[o,O$1,D,s,A$1]),useEffect(()=>{let F=(O$1[D]?.connect??[]).map(({value:X})=>X);k$2(uniqBy(prop("_id"),[...F,...L$1]));},[ue,o.count,L$1,O$1,D]);let Z=O$1[D]?.connect??[],De=O$1[D]?.disconnect??[],je=new Set(L$1.map(x=>x._id)),Ve=new Set(De),Ge=Z.filter(x=>!je.has(x._id)||Ve.has(x._id)).length,Ke=De.length,S=o.count??0,q=Math.max(0,Math.max(S,L$1.length)+Ge-Ke),U=S>0&&p$1.length>0&&p$1.length<S,ie=useCallback(()=>{le||G({variables:{limit:vm,offset:p$1.length,where:P?{[P]:{some:{_id:{eq:r$1}}}}:{}}}).then(({data:x})=>{if(!x)return;let F=f$1(B?.plural??"",f,x,c);k$2(uniqBy(prop("_id"),[...L$1,...F.results]));}).catch(x=>{console.error("Error fetching more data:",x);});},[P,r$1,G,L$1,le,B?.plural,p$1.length,c,f]);function fe(x){x.preventDefault(),!a&&g({type:"EditRelationship",payload:{connectedEntitiesCount:L$1.length,connectionName:P,entityName:y,entityId:r$1,relationshipId:D,mode:T?.mode??"multiple"}});}return jsx(h$1,{control:e,defaultValue:o,name:A$1,render:()=>jsxs(j,{className:"fk:min-w-0",children:[jsx(k,{htmlFor:M$1,children:b}),E?.comment?jsx(m,{children:E.comment}):null,jsx(l,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${A$1}`,"aria-expanded":l$1,className:`fk:relative fk:flex fk:w-full fk:min-w-0 fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${l$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} fk:corner-squircle`,onClick:x=>{x.preventDefault(),x.stopPropagation(),d.current?.focus(),d.current?.click(),u(true);},onKeyDown:x=>{x.key==="Enter"&&u(true),x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),d.current?.blur(),u(false));},ref:d,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:items-start fk:gap-2",children:[l$1?jsxs(d$2,{className:"fk:h-8 fk:mr-auto fk:mt-[0.1875rem]",disabled:a,onClick:fe,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]}):jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-wrap fk:grow fk:overflow-hidden fk:pb-1.5",children:[m$1.map(x=>jsx(b$3,{className:"fk:mr-2 fk:mt-1.5 fk:max-w-60 fk:justify-start fk:rounded-xs fk:corner-squircle",title:x,variant:"secondary",children:jsx("span",{className:"fk:min-w-0 fk:truncate",children:x})},x)),_?jsx(b$3,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs fk:corner-squircle",variant:"secondary",children:"\u2026"}):null]}),jsxs("div",{className:"fk:mt-[0.1875rem] fk:ml-auto fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[l$1?jsxs("span",{className:"fk:text-sm fk:font-normal fk:text-muted-foreground",children:[q.toLocaleString()," ",q===1?"record":"records"]}):null,l$1?jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(d$2,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",onClick:x=>{x.preventDefault(),x.stopPropagation(),d.current?.blur(),u(false);},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),x.stopPropagation(),d.current?.blur(),u(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(O,{children:jsx("p",{children:"Close"})})]})}):jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(d$2,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",id:M$1,onKeyDown:x=>{x.key==="Enter"&&(d.current?.focus(),d.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(O,{children:jsx("p",{children:"Expand field"})})]})})]})]}),jsx(p,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:u,open:l$1,children:jsx(r,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${A$1}`,children:jsx(x$1,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:Be,data:p$1,entityName:n$1,hasMore:U,isLoadingMore:le&&p$1.length>0,onLoadMore:ie,rowAdditionState:O$1[D]?.connect,rowDeletionState:O$1[D]?.disconnect})})})})]})})}),jsx(n,{})]})})}function ym({appDispatch:e,relationshipId:t,relationships:o,row:r,setRows:n}){function i(a){let c=o[t]?.connect??[],f=typeof find(propEq(a,"_id"),c)=="object",s=o[t]?.disconnect?.includes(a),l=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&n(u=>u.filter(d=>d._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:c.filter(u=>u._id!==a),disconnect:s?o[t]?.disconnect?.filter(u=>u!==a)??[]:l}}});}return jsx(ha,{action:i,row:r})}function bm({data:e,defaultScope:t,relationshipEntitySchema:o,scope:r}){if(!Array.isArray(e))return [];let n=i=>{let c=find(propEq(i.__typename,"name"))(o?.attributes??[])?.relationship?.field??"";if(c){let f=i[c],s=Array.isArray(f)?f[0]:f;return s&&typeof s=="object"?s[r]??s[t]??"":s}return i[r]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let c=a;return c.length===0?"":c.length===1?n(c[0]):c.slice(0,3).map(n).join(", ")}return a&&typeof a!="string"&&a.__typename?n(a):a},i))}function Hr({control:e,defaultScope:t,defaultValue:o,entityId:r,fieldSchema:n$1,getValues:i,readOnly:a,schema:c,scope:f,setValue:s$1}){let[l$1,u]=useState(false),{name:d,label:p,options:k$1,relationship:A$1}=n$1,b=A$1?.entity??d,E=A(),T=d$1(),y=useId(),{relationships:g}=c$1(),N=useId(),O$1=find(propEq(b,"name"))(c),M$1=e$2(O$1)?.name;useEffect(()=>{let $=o.value;if($===""||typeof $=="boolean"||typeof $=="number")return;let V={_id:String(o._id),value:$},R={type:"setRelationship",payload:{[N]:{connect:V,disconnect:[]}}};T(R);},[T,N,o,f]),useEffect(()=>{s$1(d,{...i(d),...g[N]?.connect??""});},[o,d,g,N,s$1]);function D($){$.preventDefault(),!a&&E({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:b,entityId:r,relationshipId:N,mode:A$1?.mode??"single"}});}function B($){if(a)return;let V={type:"setRelationship",payload:{[N]:{connect:[],disconnect:[]}}};$.preventDefault(),T(V),s$1(d,{...i(d),_id:"",value:void 0});}return jsx(h$1,{control:e,defaultValue:o,name:d,render:({field:$})=>{let V=$.value?.value,R="";if(M$1&&V&&typeof V=="object"&&!Array.isArray(V)&&V[M$1]){let P=V[M$1],K=Array.isArray(P)?P[0]:P;typeof K=="string"?R=K:R=K?.[f]??K?.[t]??"";}return jsxs(j,{children:[jsx(k,{htmlFor:y,children:p}),k$1?.comment?jsx(m,{children:k$1.comment}):null,jsx(l,{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 ${l$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} fk:corner-squircle`,children:[jsx(s,{className:"fk:h-9.5 fk:py-1.75 fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",disabled:a,id:y,onBlur:()=>{u(false);},onClick:D,onFocus:()=>{u(true);},onKeyDown:P=>{P.key==="Enter"&&D(P);},readOnly:true,type:"text",value:R}),R?jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(d$2,{className:"fk:absolute fk:right-10 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:a,onClick:B,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(O,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(K,{children:jsxs(L,{children:[jsx(M,{asChild:true,children:jsx(d$2,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:a,onClick:D,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(O,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(n,{})]})}})}function qr(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(Hr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(Br,{...e});let r={relationshipEntityName:t.relationship?.entity,...e};return jsx(zr,{...r})}return jsxs(Wc,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Xc,{children:"Error"}),jsx(Yc,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var Sa="flexkit-select-option:";function $r(e){return `${Sa}${encodeURIComponent(e)}`}function Fm(e){return decodeURIComponent(e.slice(Sa.length))}function Aa({control:e$1,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a$1}=t;function c$1(s,l){let d=t.dataType==="int"&&!isNaN(Number(s))?Number(s):s;r(n$1,{...l,value:d});}function f$1(s,l){r(n$1,{...l,disabled:s});}return jsx(h$1,{control:e$1,name:n$1,render:({field:s})=>jsxs(j,{children:[jsx(k,{children:i}),a$1?.comment?jsx(m,{children:a$1.comment}):null,jsxs(a,{defaultValue:s.value?.value===void 0||s.value.value===null?void 0:$r(String(s.value.value)),disabled:o||s.value?.disabled,onValueChange:l=>{c$1(Fm(l),s.value);},children:[jsx(l,{children:jsx(d,{children:jsx(c,{placeholder:a$1?.placeholder})})}),jsx(e,{children:a$1?.list?.map(l=>"groupLabel"in l?jsxs(b$1,{children:[jsx(f,{children:l.groupLabel}),l.items.map(u=>jsx(g$1,{value:$r(u.value),children:u.label},u.label))]},l.groupLabel):jsx(g$1,{value:$r(l.value),children:l.label},l.label))})]}),jsx(Fe,{checked:s.value?.disabled??false,disabled:o,onChange:l=>{f$1(l,s.value);},scope:s.value?.scope}),jsx(n,{})]})})}var xt="all",Ur={name:"all",title:"All fields"};function Im(e){return typeof e.group=="string"?[e.group]:Array.isArray(e.group)?e.group:[]}function Xr(e,t){return t==="all"?true:Im(e).includes(t)}function Gr(e,t){return t.length===0?true:t.some(o=>Xr(e,o.name))}function Zr(e){if(!e||e.length===0)return [];let t=e.find(i=>i.name==="all"),o=e.filter(i=>i.name!=="all");return [{...Ur,...t},...o].filter(i=>i.hidden!==true)}function Wr(e){let t=e.find(r=>r.default);if(t)return t.name;let o=e.find(r=>r.name!=="all");return o?o.name:"all"}function Ta(e,t){return Ut(e,t)}var Na=new Set;function Kr(e){Na.has(e)||(Na.add(e),console.warn(`[flexkit] validation keyword "${e}" is not supported by the Studio form and was ignored.`));}var Dm=new Set(["type","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","enum","const","properties","required","additionalProperties","items","minItems","maxItems","anyOf","oneOf","not","description","title","$schema"]),Tm={email:"must be a valid email address",uri:"must be a valid URL",uuid:"must be a valid UUID","date-time":"must be a valid date and time",date:"must be a valid date",time:"must be a valid time"};function ko(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ea(e){return e===null?z.null():typeof e=="string"||typeof e=="number"||typeof e=="boolean"?z.literal(e):z.any().refine(t=>JSON.stringify(t)===JSON.stringify(e))}function Qr(e,t){return e.length===0?z.any():e.length===1?e[0]:z.union(e,{error:`${t} is invalid`})}function Pm(e,t){let o=z.string({error:`${t} must be text`}),r=typeof e.format=="string"?e.format:void 0,n=r?Tm[r]??`must match the ${r} format`:"has an invalid format";if(typeof e.minLength=="number"){let i=e.minLength;o=o.min(i,{error:i<=1?`${t} is required`:`${t} must be at least ${String(i)} characters`});}if(typeof e.maxLength=="number"&&(o=o.max(e.maxLength,{error:`${t} must be at most ${String(e.maxLength)} characters`})),typeof e.pattern=="string")try{o=o.regex(new RegExp(e.pattern),{error:`${t} ${n}`});}catch{Kr(`pattern:${e.pattern}`);}return o}var Fa=new Set([Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]);function Ia(e,t,o){let r=z.number({error:`${t} must be a number`});o&&(r=r.int({error:`${t} must be a whole number`}));let n=typeof e.minimum=="number"&&!Fa.has(e.minimum)?e.minimum:void 0,i=typeof e.maximum=="number"&&!Fa.has(e.maximum)?e.maximum:void 0,a=n!==void 0&&i!==void 0?`${t} must be between ${String(n)} and ${String(i)}`:void 0;return n!==void 0&&(r=r.min(n,{error:a??`${t} must be at least ${String(n)}`})),i!==void 0&&(r=r.max(i,{error:a??`${t} must be at most ${String(i)}`})),typeof e.exclusiveMinimum=="number"&&(r=r.gt(e.exclusiveMinimum,{error:`${t} must be greater than ${String(e.exclusiveMinimum)}`})),typeof e.exclusiveMaximum=="number"&&(r=r.lt(e.exclusiveMaximum,{error:`${t} must be less than ${String(e.exclusiveMaximum)}`})),typeof e.multipleOf=="number"&&(r=r.multipleOf(e.multipleOf,{error:`${t} must be a multiple of ${String(e.multipleOf)}`})),r}function Rm(e,t){let o=z.array(ko(e.items)?Ut(e.items,t):z.any(),{error:`${t} must be a list`});return typeof e.minItems=="number"&&(o=o.min(e.minItems,{error:e.minItems<=1?`${t} is required`:`${t} needs at least ${String(e.minItems)} items`})),typeof e.maxItems=="number"&&(o=o.max(e.maxItems,{error:`${t} allows at most ${String(e.maxItems)} items`})),o}function Lm(e,t){let o=ko(e.properties)?e.properties:{},r=new Set(Array.isArray(e.required)?e.required.filter(i=>typeof i=="string"):[]),n={};for(let[i,a]of Object.entries(o)){let c=ko(a)?Ut(a,`${t} ${i}`):z.any();n[i]=r.has(i)?c:c.optional();}return z.object(n,{error:`${t} is required`})}function Da(e,t,o){switch(e){case "string":return Pm(t,o);case "integer":return Ia(t,o,true);case "number":return Ia(t,o,false);case "boolean":return z.boolean({error:`${o} must be yes or no`});case "null":return z.null();case "array":return Rm(t,o);case "object":return Lm(t,o);default:return typeof e=="string"&&Kr(`type:${e}`),z.any()}}function Ut(e,t){for(let r of Object.keys(e))Dm.has(r)||Kr(r);if(e.const!==void 0)return Ea(e.const);if(Array.isArray(e.enum))return Qr(e.enum.map(r=>Ea(r)),t);let o=Array.isArray(e.anyOf)?e.anyOf:Array.isArray(e.oneOf)?e.oneOf:void 0;if(o){let r=o.filter(ko),n=r.findIndex(i=>i.type==="null");if(n!==-1&&r.length===2){let i=r[n===0?1:0];return Ut(i,t).nullable()}return Qr(r.map(i=>Ut(i,t)),t)}if(ko(e.not)){let r=Ut(e.not,t);return z.any().refine(n=>!r.safeParse(n).success,{error:`${t} is invalid`})}return Array.isArray(e.type)?Qr(e.type.map(r=>Da(r,e,t)),t):Da(e.type,e,t)}function Pa(e,t){return z.any().superRefine((o,r)=>{let n=e.safeParse(o);if(n.success)return;let i=o==null||o==="";r.addIssue({code:"custom",message:i?`${t} is required`:n.error.issues[0]?.message??`${t} is invalid`});})}var Ma=new Set;function Um(e,t){let o=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:o}}function Xm({currentScope:e,defaultScope:t,entityId:o,entityName:r,entityNamePlural:n,formData:i,schema:a,setIsDirty:c,onSubmit:f},s){let l=find(propEq(r,"name"))(a),[,u]=h(),d=u.user?.spaces,p=useMemo(()=>b(l?.attributes??[],d),[l,d]),k=useMemo(()=>i||p.reduce((C,L)=>({...C,[L.name]:Um(L,t)}),{}),[t,i,p]),A=useMemo(()=>{let C=Zr(l?.groups),L={};for(let H of p){if(H.validation===void 0||H.hidden===true||H.readOnly===true||!Gr(H,C))continue;let h=H.label||H.name;L[H.name]=z.object({value:Pa(Ta(H.validation,h),h)});}return zodResolver(z.object(L))},[l?.groups,p]),E=useForm({defaultValues:k,resolver:(C,L,H)=>A(C,L,H),values:i,mode:"onBlur",criteriaMode:"all"}),{control:T,getValues:y,handleSubmit:g$1,setValue:N,watch:O,trigger:M}=E;O();let D=useMemo(()=>Zr(l?.groups),[l?.groups]),[B,$]=useState(()=>Wr(D)),V=useRef(i),R=useRef(false);useEffect(()=>{R.current||(V.current=i);},[i]);let P={datetime:Ui,editor:Rr,asset:Hi,number:qi,relationship:qr,select:Aa,switch:Li,text:yr,textarea:ma};if(useImperativeHandle(s,()=>({submit(){M().then(()=>{g$1(()=>{let C=y();R.current=true,V.current=C,c(false),f(C,i);})();});},hasErrors(){R.current=false,V.current=i,c(true);},hasDataChanged(){return _a(y(),V.current)},markAsSaved(){R.current=true,V.current=y(),c(false);},applyLocalAttributeIds(C){let L=y(),H={...L};for(let[h,m]of Object.entries(C)){let _=L[h];!_||_._id||!m||(H[h]={..._,_id:m});}R.current=true,V.current=H;for(let[h,m]of Object.entries(H))m!==L[h]&&N(h,m,{shouldDirty:false,shouldTouch:false,shouldValidate:false});c(false);}})),useEffect(()=>{let C=O(()=>{c(_a(y(),V.current));});return ()=>{C.unsubscribe();}},[i,y,c,O]),useEffect(()=>{D.length!==0&&(D.some(C=>C.name===B)||$(Wr(D)));},[B,D]),!l||l.attributes.length===0)return jsxs(Wc,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Xc,{children:"Error"}),jsxs(Yc,{children:["No attributes found in the schema for entity ",jsx("strong",{children:r})]})]});let K=C=>{if(C.name==="_id"||C.hidden===true)return null;let L=C.readOnly===true,H=P[C.inputType];return !H&&!Ma.has(C.inputType)&&(Ma.add(C.inputType),console.warn(`[flexkit] Unknown inputType "${C.inputType}" on "${C.name}"; rendering a text field.`)),createElement(H??yr,{key:C.name,control:T,defaultScope:t,defaultValue:k[C.name],entityId:o,entityName:r,entityNamePlural:n,fieldSchema:C,getValues:y,readOnly:L,schema:a,scope:e,setValue:N})};return jsx(g,{...E,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-5",onSubmit:C=>{C.preventDefault();},children:D.length>0?jsxs(la$1,{onValueChange:$,value:B,children:[jsx("div",{className:"fk:sticky fk:top-0 fk:z-10 fk:bg-background fk:py-1 fk:mb-6",children:jsxs(w,{className:"fk:w-full fk:**:data-[slot=scroll-area-viewport]:h-auto fk:[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:hidden fk:**:data-[slot=scroll-area-viewport]:p-1 fk:**:data-[slot=scroll-area-viewport]:-ml-1 fk:**:data-[slot=scroll-area-viewport]:-mt-1",children:[jsx(ma$1,{className:"fk:h-9 fk:w-max fk:flex-nowrap fk:justify-start",children:D.map(C=>jsxs(na$1,{value:C.name,children:[C.icon?jsx(aa$1,{name:C.icon}):null,C.title]},C.name))}),jsx(x,{orientation:"horizontal"})]})}),jsx(oa$1,{className:"fk:gap-8",value:B,children:p.map(C=>{if(!Gr(C,D))return null;let L=Xr(C,B),H=K(C);return H?jsx("div",{className:L?void 0:"fk:hidden",children:H},C.name):null})})]}):p.map(C=>K(C))})})}var Go=memo(forwardRef(Xm));function _a(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??"",r=(a,c)=>a<c?-1:1,n=Object.keys(t).sort((a,c)=>r(a,c)).filter(a=>a!=="_updatedAt").reduce((a,c)=>({...a,[c]:{value:o(t[c].value),disabled:t[c].disabled,relationships:t[c].relationships}}),{}),i=Object.keys(e).sort((a,c)=>r(a,c)).filter(a=>a!=="_updatedAt").reduce((a,c)=>({...a,[c]:{value:o(e[c]?.value),disabled:e[c]?.disabled??false,relationships:Object.keys(e[c]?.relationships?.connect??{}).length||e[c]?.relationships?.disconnect?.length?e[c]?.relationships:void 0}}),{});return !equals(n,i)}function tn({action:e,depth:t,isFocused:o}){let{entityName:r}=e.payload,n=useRef(null),i=b$8(),[,a]=h(),{currentProject:c}=f$2(),f=useMemo(()=>c?.schema??[],[c]),l=c?.scopes?.find(R=>R.isDefault)?.name??"default",d=find(propEq(r,"name"))(f)?.plural??r,{scope:p}=c$1(),k=A(),A$1=useApolloClient(),[b,E,T,y]=C(),{isDirty:g,setIsDirty:N}=Vt(),[O,M]=useState(false);useEffect(()=>{y.error&&n.current?.hasErrors();},[y.error]);function D(){return g?(k({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:()=>{k({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{N(false),k({type:"Dismiss",_id:"unsavedChanges",payload:{}}),M(true);}}}}),false):true}let B=useCallback(R=>{k({type:"Dismiss",_id:R,payload:{}});},[k]),$=useCallback(()=>{n.current?.submit();},[n]),V=useCallback(R=>{let P=v4(),K=j$2(d,f,R,P,{currentUser:a.user});E(gql`
|
|
8
|
-
${
|
|
9
|
-
`),
|
|
7
|
+
`),Be=J({attributesSchema:B?.attributes??[],actionsComponent:a?void 0:x=>Vm({appDispatch:N,relationshipId:T,relationships:O,row:x,setRows:k$2})});useEffect(()=>{k$2(L),o.value!==""&&N({type:"setRelationship",payload:{[T]:{connect:[],disconnect:[]}}});},[N,ue,L,T,o,f]),useEffect(()=>{s(A$1,{...o,relationships:O[T]});},[o,O,T,s,A$1]),useEffect(()=>{let F=(O[T]?.connect??[]).map(({value:X})=>X);k$2(uniqBy(prop("_id"),[...F,...L]));},[ue,o.count,L,O,T]);let Z=O[T]?.connect??[],De=O[T]?.disconnect??[],je=new Set(L.map(x=>x._id)),Ve=new Set(De),Ge=Z.filter(x=>!je.has(x._id)||Ve.has(x._id)).length,Ye=De.length,S=o.count??0,$=Math.max(0,Math.max(S,L.length)+Ge-Ye),U=S>0&&p$1.length>0&&p$1.length<S,ie=useCallback(()=>{le||G({variables:{limit:jm,offset:p$1.length,where:P?{[P]:{some:{_id:{eq:r$1}}}}:{}}}).then(({data:x})=>{if(!x)return;let F=f$1(B?.plural??"",f,x,c);k$2(uniqBy(prop("_id"),[...L,...F.results]));}).catch(x=>{console.error("Error fetching more data:",x);});},[P,r$1,G,L,le,B?.plural,p$1.length,c,f]);function fe(x){x.preventDefault(),!a&&g({type:"EditRelationship",payload:{connectedEntitiesCount:L.length,connectionName:P,entityName:y,entityId:r$1,relationshipId:T,mode:D?.mode??"multiple"}});}return jsx(h$1,{control:e,defaultValue:o,name:A$1,render:()=>jsxs(j,{className:"fk:min-w-0",children:[jsx(k,{htmlFor:M,children:b}),E?.comment?jsx(m,{children:E.comment}):null,jsx(l,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${A$1}`,"aria-expanded":l$1,className:`fk:relative fk:flex fk:w-full fk:min-w-0 fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${l$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} fk:corner-squircle`,onClick:x=>{x.preventDefault(),x.stopPropagation(),d.current?.focus(),d.current?.click(),m$1(true);},onKeyDown:x=>{x.key==="Enter"&&m$1(true),x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),d.current?.blur(),m$1(false));},ref:d,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:items-start fk:gap-2",children:[l$1?jsxs(b$2,{className:"fk:h-8 fk:mr-auto fk:mt-[0.1875rem]",disabled:a,onClick:fe,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]}):jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-wrap fk:grow fk:overflow-hidden fk:pb-1.5",children:[u.map(x=>jsx(b$5,{className:"fk:mr-2 fk:mt-1.5 fk:max-w-60 fk:justify-start fk:rounded-xs fk:corner-squircle",title:x,variant:"secondary",children:jsx("span",{className:"fk:min-w-0 fk:truncate",children:x})},x)),_?jsx(b$5,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs fk:corner-squircle",variant:"secondary",children:"\u2026"}):null]}),jsxs("div",{className:"fk:mt-[0.1875rem] fk:ml-auto fk:flex fk:shrink-0 fk:items-center fk:gap-2",children:[l$1?jsxs("span",{className:"fk:text-sm fk:font-normal fk:text-muted-foreground",children:[$.toLocaleString()," ",$===1?"record":"records"]}):null,l$1?jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",onClick:x=>{x.preventDefault(),x.stopPropagation(),d.current?.blur(),m$1(false);},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),x.stopPropagation(),d.current?.blur(),m$1(false));},size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Close"})})]})}):jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",id:M,onKeyDown:x=>{x.key==="Enter"&&(d.current?.focus(),d.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Expand field"})})]})})]})]}),jsx(p,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:m$1,open:l$1,children:jsx(r,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${A$1}`,children:jsx(x$1,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:Be,data:p$1,entityName:n$1,hasMore:U,isLoadingMore:le&&p$1.length>0,onLoadMore:ie,rowAdditionState:O[T]?.connect,rowDeletionState:O[T]?.disconnect})})})})]})})}),jsx(n,{})]})})}function Vm({appDispatch:e,relationshipId:t,relationships:o,row:r,setRows:n}){function i(a){let c=o[t]?.connect??[],f=typeof find(propEq(a,"_id"),c)=="object",s=o[t]?.disconnect?.includes(a),l=f?o[t]?.disconnect??[]:uniq([...o[t]?.disconnect??[],a]);f&&n(m=>m.filter(d=>d._id!==a)),e({type:"setRelationship",payload:{[t]:{connect:c.filter(m=>m._id!==a),disconnect:s?o[t]?.disconnect?.filter(m=>m!==a)??[]:l}}});}return jsx(Na,{action:i,row:r})}function zm({data:e,defaultScope:t,relationshipEntitySchema:o,scope:r}){if(!Array.isArray(e))return [];let n=i=>{let c=find(propEq(i.__typename,"name"))(o?.attributes??[])?.relationship?.field??"";if(c){let f=i[c],s=Array.isArray(f)?f[0]:f;return s&&typeof s=="object"?s[r]??s[t]??"":s}return i[r]??i[t]};return e.map(i=>map(a=>{if(Array.isArray(a)){let c=a;return c.length===0?"":c.length===1?n(c[0]):c.slice(0,3).map(n).join(", ")}return a&&typeof a!="string"&&a.__typename?n(a):a},i))}function Jr({control:e,defaultScope:t,defaultValue:o,entityId:r,fieldSchema:n$1,getValues:i,readOnly:a,schema:c,scope:f,setValue:s$1}){let[l$1,m$1]=useState(false),{name:d,label:p,options:k$1,relationship:A$1}=n$1,b=A$1?.entity??d,E=A(),D=d$1(),y=useId(),{relationships:g}=c$1(),N=useId(),O=find(propEq(b,"name"))(c),M=e$3(O)?.name;useEffect(()=>{let q=o.value;if(q===""||typeof q=="boolean"||typeof q=="number")return;let V={_id:String(o._id),value:q},R={type:"setRelationship",payload:{[N]:{connect:V,disconnect:[]}}};D(R);},[D,N,o,f]),useEffect(()=>{s$1(d,{...i(d),...g[N]?.connect??""});},[o,d,g,N,s$1]);function T(q){q.preventDefault(),!a&&E({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:b,entityId:r,relationshipId:N,mode:A$1?.mode??"single"}});}function B(q){if(a)return;let V={type:"setRelationship",payload:{[N]:{connect:[],disconnect:[]}}};q.preventDefault(),D(V),s$1(d,{...i(d),_id:"",value:void 0});}return jsx(h$1,{control:e,defaultValue:o,name:d,render:({field:q})=>{let V=q.value?.value,R="";if(M&&V&&typeof V=="object"&&!Array.isArray(V)&&V[M]){let P=V[M],Q=Array.isArray(P)?P[0]:P;typeof Q=="string"?R=Q:R=Q?.[f]??Q?.[t]??"";}return jsxs(j,{children:[jsx(k,{htmlFor:y,children:p}),k$1?.comment?jsx(m,{children:k$1.comment}):null,jsx(l,{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 ${l$1?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} fk:corner-squircle`,children:[jsx(s,{className:"fk:h-9.5 fk:py-1.75 fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",disabled:a,id:y,onBlur:()=>{m$1(false);},onClick:T,onFocus:()=>{m$1(true);},onKeyDown:P=>{P.key==="Enter"&&T(P);},readOnly:true,type:"text",value:R}),R?jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:absolute fk:right-10 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:a,onClick:B,size:"icon",variant:"ghost",children:jsx(X$1,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$1,{children:jsxs(b$3,{children:[jsx(c$3,{asChild:true,children:jsx(b$2,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground fk:corner-squircle",disabled:a,onClick:T,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$2,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(n,{})]})}})}function Ur(e){let{fieldSchema:t}=e,{relationship:o}=t;if(o?.mode==="single")return jsx(Jr,{...e});if(o?.mode==="multiple"){if(o.entity==="_asset")return jsx(zr,{...e});let r={relationshipEntityName:t.relationship?.entity,...e};return jsx(qr,{...r})}return jsxs(Rc,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(Sc,{children:"Error"}),jsx(Tc,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var Ra="flexkit-select-option:";function Xr(e){return `${Ra}${encodeURIComponent(e)}`}function Zm(e){return decodeURIComponent(e.slice(Ra.length))}function La({control:e$1,fieldSchema:t,readOnly:o,setValue:r}){let{name:n$1,label:i,options:a$1}=t;function c$1(s,l){let d=t.dataType==="int"&&!isNaN(Number(s))?Number(s):s;r(n$1,{...l,value:d});}function f$1(s,l){r(n$1,{...l,disabled:s});}return jsx(h$1,{control:e$1,name:n$1,render:({field:s})=>jsxs(j,{children:[jsx(k,{children:i}),a$1?.comment?jsx(m,{children:a$1.comment}):null,jsxs(a,{defaultValue:s.value?.value===void 0||s.value.value===null?void 0:Xr(String(s.value.value)),disabled:o||s.value?.disabled,onValueChange:l=>{c$1(Zm(l),s.value);},children:[jsx(l,{children:jsx(d,{children:jsx(c,{placeholder:a$1?.placeholder})})}),jsx(e,{children:a$1?.list?.map(l=>"groupLabel"in l?jsxs(b$1,{children:[jsx(f,{children:l.groupLabel}),l.items.map(m=>jsx(g$1,{value:Xr(m.value),children:m.label},m.label))]},l.groupLabel):jsx(g$1,{value:Xr(l.value),children:l.label},l.label))})]}),jsx(Ie,{checked:s.value?.disabled??false,disabled:o,onChange:l=>{f$1(l,s.value);},scope:s.value?.scope}),jsx(n,{})]})})}var xt="all",Zr={name:"all",title:"All fields"};function Wm(e){return typeof e.group=="string"?[e.group]:Array.isArray(e.group)?e.group:[]}function Wr(e,t){return t==="all"?true:Wm(e).includes(t)}function Kr(e,t){return t.length===0?true:t.some(o=>Wr(e,o.name))}function Qr(e){if(!e||e.length===0)return [];let t=e.find(i=>i.name==="all"),o=e.filter(i=>i.name!=="all");return [{...Zr,...t},...o].filter(i=>i.hidden!==true)}function Yr(e){let t=e.find(r=>r.default);if(t)return t.name;let o=e.find(r=>r.name!=="all");return o?o.name:"all"}function Va(e,t){return Ut(e,t)}var Ma=new Set;function tn(e){Ma.has(e)||(Ma.add(e),console.warn(`[flexkit] validation keyword "${e}" is not supported by the Studio form and was ignored.`));}var Km=new Set(["type","minLength","maxLength","pattern","format","minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","enum","const","properties","required","additionalProperties","items","minItems","maxItems","anyOf","oneOf","not","description","title","$schema"]),Qm={email:"must be a valid email address",uri:"must be a valid URL",uuid:"must be a valid UUID","date-time":"must be a valid date and time",date:"must be a valid date",time:"must be a valid time"};function ho(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function _a(e){return e===null?z.null():typeof e=="string"||typeof e=="number"||typeof e=="boolean"?z.literal(e):z.any().refine(t=>JSON.stringify(t)===JSON.stringify(e))}function en(e,t){return e.length===0?z.any():e.length===1?e[0]:z.union(e,{error:`${t} is invalid`})}function Ym(e,t){let o=z.string({error:`${t} must be text`}),r=typeof e.format=="string"?e.format:void 0,n=r?Qm[r]??`must match the ${r} format`:"has an invalid format";if(typeof e.minLength=="number"){let i=e.minLength;o=o.min(i,{error:i<=1?`${t} is required`:`${t} must be at least ${String(i)} characters`});}if(typeof e.maxLength=="number"&&(o=o.max(e.maxLength,{error:`${t} must be at most ${String(e.maxLength)} characters`})),typeof e.pattern=="string")try{o=o.regex(new RegExp(e.pattern),{error:`${t} ${n}`});}catch{tn(`pattern:${e.pattern}`);}return o}var Oa=new Set([Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER]);function Ba(e,t,o){let r=z.number({error:`${t} must be a number`});o&&(r=r.int({error:`${t} must be a whole number`}));let n=typeof e.minimum=="number"&&!Oa.has(e.minimum)?e.minimum:void 0,i=typeof e.maximum=="number"&&!Oa.has(e.maximum)?e.maximum:void 0,a=n!==void 0&&i!==void 0?`${t} must be between ${String(n)} and ${String(i)}`:void 0;return n!==void 0&&(r=r.min(n,{error:a??`${t} must be at least ${String(n)}`})),i!==void 0&&(r=r.max(i,{error:a??`${t} must be at most ${String(i)}`})),typeof e.exclusiveMinimum=="number"&&(r=r.gt(e.exclusiveMinimum,{error:`${t} must be greater than ${String(e.exclusiveMinimum)}`})),typeof e.exclusiveMaximum=="number"&&(r=r.lt(e.exclusiveMaximum,{error:`${t} must be less than ${String(e.exclusiveMaximum)}`})),typeof e.multipleOf=="number"&&(r=r.multipleOf(e.multipleOf,{error:`${t} must be a multiple of ${String(e.multipleOf)}`})),r}function eu(e,t){let o=z.array(ho(e.items)?Ut(e.items,t):z.any(),{error:`${t} must be a list`});return typeof e.minItems=="number"&&(o=o.min(e.minItems,{error:e.minItems<=1?`${t} is required`:`${t} needs at least ${String(e.minItems)} items`})),typeof e.maxItems=="number"&&(o=o.max(e.maxItems,{error:`${t} allows at most ${String(e.maxItems)} items`})),o}function tu(e,t){let o=ho(e.properties)?e.properties:{},r=new Set(Array.isArray(e.required)?e.required.filter(i=>typeof i=="string"):[]),n={};for(let[i,a]of Object.entries(o)){let c=ho(a)?Ut(a,`${t} ${i}`):z.any();n[i]=r.has(i)?c:c.optional();}return z.object(n,{error:`${t} is required`})}function ja(e,t,o){switch(e){case "string":return Ym(t,o);case "integer":return Ba(t,o,true);case "number":return Ba(t,o,false);case "boolean":return z.boolean({error:`${o} must be yes or no`});case "null":return z.null();case "array":return eu(t,o);case "object":return tu(t,o);default:return typeof e=="string"&&tn(`type:${e}`),z.any()}}function Ut(e,t){for(let r of Object.keys(e))Km.has(r)||tn(r);if(e.const!==void 0)return _a(e.const);if(Array.isArray(e.enum))return en(e.enum.map(r=>_a(r)),t);let o=Array.isArray(e.anyOf)?e.anyOf:Array.isArray(e.oneOf)?e.oneOf:void 0;if(o){let r=o.filter(ho),n=r.findIndex(i=>i.type==="null");if(n!==-1&&r.length===2){let i=r[n===0?1:0];return Ut(i,t).nullable()}return en(r.map(i=>Ut(i,t)),t)}if(ho(e.not)){let r=Ut(e.not,t);return z.any().refine(n=>!r.safeParse(n).success,{error:`${t} is invalid`})}return Array.isArray(e.type)?en(e.type.map(r=>ja(r,e,t)),t):ja(e.type,e,t)}function za(e,t){return z.any().superRefine((o,r)=>{let n=e.safeParse(o);if(n.success)return;let i=o==null||o==="";r.addIssue({code:"custom",message:i?`${t} is required`:n.error.issues[0]?.message??`${t} is invalid`});})}var qa=new Set;function du(e,t){let o=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:o}}function pu({currentScope:e,defaultScope:t,entityId:o,entityName:r,entityNamePlural:n,formData:i,schema:a,setIsDirty:c,onSubmit:f},s){let l=find(propEq(r,"name"))(a),[,m]=h(),d=m.user?.spaces,p=useMemo(()=>b(l?.attributes??[],d),[l,d]),k=useMemo(()=>i||p.reduce((C,L)=>({...C,[L.name]:du(L,t)}),{}),[t,i,p]),A=useMemo(()=>{let C=Qr(l?.groups),L={};for(let H of p){if(H.validation===void 0||H.hidden===true||H.readOnly===true||!Kr(H,C))continue;let h=H.label||H.name;L[H.name]=z.object({value:za(Va(H.validation,h),h)});}return zodResolver(z.object(L))},[l?.groups,p]),E=useForm({defaultValues:k,resolver:(C,L,H)=>A(C,L,H),values:i,mode:"onBlur",criteriaMode:"all"}),{control:D,getValues:y,handleSubmit:g$1,setValue:N,watch:O,trigger:M}=E;O();let T=useMemo(()=>Qr(l?.groups),[l?.groups]),[B,q]=useState(()=>Yr(T)),V=useRef(i),R=useRef(false);useEffect(()=>{R.current||(V.current=i);},[i]);let P={datetime:ta,editor:_r,asset:Ki,number:Qi,relationship:Ur,select:La,switch:$i,text:xr,textarea:ba};if(useImperativeHandle(s,()=>({submit(){M().then(()=>{g$1(()=>{let C=y();R.current=true,V.current=C,c(false),f(C,i);})();});},hasErrors(){R.current=false,V.current=i,c(true);},hasDataChanged(){return Ja(y(),V.current)},markAsSaved(){R.current=true,V.current=y(),c(false);},applyLocalAttributeIds(C){let L=y(),H={...L};for(let[h,u]of Object.entries(C)){let _=L[h];!_||_._id||!u||(H[h]={..._,_id:u});}R.current=true,V.current=H;for(let[h,u]of Object.entries(H))u!==L[h]&&N(h,u,{shouldDirty:false,shouldTouch:false,shouldValidate:false});c(false);}})),useEffect(()=>{let C=O(()=>{c(Ja(y(),V.current));});return ()=>{C.unsubscribe();}},[i,y,c,O]),useEffect(()=>{T.length!==0&&(T.some(C=>C.name===B)||q(Yr(T)));},[B,T]),!l||l.attributes.length===0)return jsxs(Rc,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(Sc,{children:"Error"}),jsxs(Tc,{children:["No attributes found in the schema for entity ",jsx("strong",{children:r})]})]});let Q=C=>{if(C.name==="_id"||C.hidden===true)return null;let L=C.readOnly===true,H=P[C.inputType];return !H&&!qa.has(C.inputType)&&(qa.add(C.inputType),console.warn(`[flexkit] Unknown inputType "${C.inputType}" on "${C.name}"; rendering a text field.`)),createElement(H??xr,{key:C.name,control:D,defaultScope:t,defaultValue:k[C.name],entityId:o,entityName:r,entityNamePlural:n,fieldSchema:C,getValues:y,readOnly:L,schema:a,scope:e,setValue:N})};return jsx(g,{...E,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-5",onSubmit:C=>{C.preventDefault();},children:T.length>0?jsxs(ga,{onValueChange:q,value:B,children:[jsx("div",{className:"fk:sticky fk:top-0 fk:z-10 fk:bg-background fk:py-1 fk:mb-6",children:jsxs(w,{className:"fk:w-full fk:**:data-[slot=scroll-area-viewport]:h-auto fk:[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:hidden fk:**:data-[slot=scroll-area-viewport]:p-1 fk:**:data-[slot=scroll-area-viewport]:-ml-1 fk:**:data-[slot=scroll-area-viewport]:-mt-1",children:[jsx(ha$1,{className:"fk:h-9 fk:w-max fk:flex-nowrap fk:justify-start",children:T.map(C=>jsxs(ia$1,{value:C.name,children:[C.icon?jsx(X,{name:C.icon}):null,C.title]},C.name))}),jsx(x,{orientation:"horizontal"})]})}),jsx(ja$1,{className:"fk:gap-8",value:B,children:p.map(C=>{if(!Kr(C,T))return null;let L=Wr(C,B),H=Q(C);return H?jsx("div",{className:L?void 0:"fk:hidden",children:H},C.name):null})})]}):p.map(C=>Q(C))})})}var Zo=memo(forwardRef(pu));function Ja(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??"",r=(a,c)=>a<c?-1:1,n=Object.keys(t).sort((a,c)=>r(a,c)).filter(a=>a!=="_updatedAt").reduce((a,c)=>({...a,[c]:{value:o(t[c].value),disabled:t[c].disabled,relationships:t[c].relationships}}),{}),i=Object.keys(e).sort((a,c)=>r(a,c)).filter(a=>a!=="_updatedAt").reduce((a,c)=>({...a,[c]:{value:o(e[c]?.value),disabled:e[c]?.disabled??false,relationships:Object.keys(e[c]?.relationships?.connect??{}).length||e[c]?.relationships?.disconnect?.length?e[c]?.relationships:void 0}}),{});return !equals(n,i)}function nn({action:e,depth:t,isFocused:o}){let{entityName:r}=e.payload,n=useRef(null),i=b$a(),[,a]=h(),{currentProject:c}=f$2(),f=useMemo(()=>c?.schema??[],[c]),l=c?.scopes?.find(R=>R.isDefault)?.name??"default",d=find(propEq(r,"name"))(f)?.plural??r,{scope:p}=c$1(),k=A(),A$1=useApolloClient(),[b,E,D,y]=C(),{isDirty:g,setIsDirty:N}=Vt(),[O,M]=useState(false);useEffect(()=>{y.error&&n.current?.hasErrors();},[y.error]);function T(){return g?(k({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:()=>{k({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{N(false),k({type:"Dismiss",_id:"unsavedChanges",payload:{}}),M(true);}}}}),false):true}let B=useCallback(R=>{k({type:"Dismiss",_id:R,payload:{}});},[k]),q=useCallback(()=>{n.current?.submit();},[n]),V=useCallback(R=>{let P=v4(),Q=j$2(d,f,R,P,{currentUser:a.user});E(gql`
|
|
8
|
+
${Q}
|
|
9
|
+
`),D({onCompleted:()=>{r$2(A$1,o$3(d,f)),B(e._id),toast.success("Your changes have been saved.");}}),b(true);},[e._id,A$1,a.user,d,B,b,f,E,D]);return jsx(na$1,{actions:jsx(ma$1,{disabled:!i,children:jsxs(b$2,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{q();},variant:"default",children:[y.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:T,depth:t,forceClose:O,isFocused:o,onClose:()=>{B(e._id);},title:`Add ${r}`,children:jsx(Zo,{currentScope:p,defaultScope:l,entityName:r,entityNamePlural:d,onSubmit:V,ref:n,schema:f,setIsDirty:N})})}function Xa(){return jsxs(Rc,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Sc,{children:"Read Only Mode"}),jsxs(Tc,{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 sn({handleSave:e,isLoading:t}){let{isDirty:o}=Vt(),r=b$a();return jsx(ma$1,{disabled:!r,children:jsxs(b$2,{className:"fk:px-8 fk:min-w-32",disabled:!o||!r,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})})}function ln(){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(t$3,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(t$3,{className:"fk:w-5 fk:mr-2"}),jsx(t$3,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function fn({action:e$1,depth:t,isFocused:o}){let{entityId:r,entityNamePlural:n}=e$1.payload,i=useRef(null),{currentProject:a$1,currentProjectId:c$2}=f$2(),f=useMemo(()=>a$1?.schema??[],[a$1]),s=a$1?.scopes,l=s?.find(Z=>Z.isDefault)?.name??"default",m=find(propEq(n,"plural"))(f),d$2=m?.name??n,{scope:p}=c$1(),[k,A$1]=useState(p),b=A(),E=d$1(),D=useApolloClient(),[y,g,N,O]=C(),{isDirty:M,setIsDirty:T}=Vt(),[B,q]=useState(false),[,V]=h(),R=useCallback(Z=>{T(Z);},[T]);useEffect(()=>{O.error&&i.current?.hasErrors();},[O.error]);let P=useCallback(()=>M?(b({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:()=>{b({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{T(false),b({type:"Dismiss",_id:"unsavedChanges",payload:{}}),q(true);}}}}),false):true,[b,M,T]),Q=useCallback(Z=>{b({type:"Dismiss",_id:Z,payload:{}});},[b]),C$1=useCallback(()=>{i.current?.submit();},[i]);function L(Z){if(M){b({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:()=>{A$1(k),b({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{b({type:"Dismiss",_id:"unsavedChanges",payload:{}}),A$1(Z),E({type:"setScope",payload:{projectId:c$2,scope:Z}});}}}});return}A$1(Z),E({type:"setScope",payload:{projectId:c$2,scope:Z}});}let{isLoading:H,data:h$1}=u$1({entityNamePlural:n,schema:f,scope:k,variables:{where:{_id:{eq:r}}},isForm:true,includeCount:false}),u=useCallback((Z,De)=>{if(!De)return;let je=g$4(n,r,k,f,De,Z,{currentUser:V.user});g(gql`
|
|
10
10
|
${je}
|
|
11
|
-
`),N({variables:{where:{_id:{eq:r}}},onCompleted:Ve=>{i.current?.applyLocalAttributeIds(n$1(Ve,n,f)),r$2(T,o$3(n,f)),toast.success("Your changes have been saved.");}}),y(true);},[T,V.user,k,r,n,y,f,g,N]),_=h$1,G=_.length>0,le=H&&!G;function ue(Z,De){let je=e$2(Z),Ve=je?.name,Ge=je?.relationship?.field!==void 0;if(!De.length||!Ve)return "";if(!Ge||!je?.relationship?.field)return De[0][Ve]?.value;let Ke=De[0][Ve]?.value?.[je.relationship.field],S=Array.isArray(Ke)?Ke[0]:Ke;if(S&&typeof S=="object"){let q=S;return q[k]??q.default??""}return S??""}let Be=G&&u?ue(u,_):"";return jsx(sa,{actions:jsxs(Fragment,{children:[s&&s.length>1?jsxs(a,{onValueChange:Z=>{L(Z);},value:k,children:[jsxs(d,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c,{children:find(propEq(k,"name"))(s).label})]}),jsx(e,{children:s.map(Z=>jsx(g$1,{value:Z.name,children:Z.label},Z.name))})]}):null,jsx(rn,{handleSave:C$1,isLoading:O.loading})]}),beforeClose:P,depth:t,forceClose:B,isFocused:o,onClose:()=>{K(e$1._id);},onFormChange:()=>{},title:Be,children:le||!G?jsx(nn,{}):jsxs(Fragment,{children:[O.isProjectReadOnly?jsx(Ba,{}):null,jsx(Go,{currentScope:k,defaultScope:l,entityId:r,entityName:d$2,entityNamePlural:n,formData:_[0],onSubmit:m,ref:i,schema:f,setIsDirty:R})]})})}var Ua=25;function xu(e){return e.map(t=>({...t,cell:()=>jsx(t$3,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function fn({action:e,depth:t,isFocused:o}){let r=A(),n=d$1(),{relationships:i,scope:a}=c$1(),{assetAccept:c,connectedEntitiesCount:f,connectionName:s,entityId:l,entityName:u,initialAssetPath:d,initialConnection:p,mode:k,relationshipId:A$1}=e.payload,{currentProject:b,currentProjectId:E}=f$2(),T=b?.schema??[],y=find(propEq(u,"name"))(T),g=y?.plural??"",N=i[A$1],O=c$3(),M=u==="_asset",D=M?"asset":y?.menu?.label??u.toLowerCase(),B=M&&k==="single"?"Select asset":`Select ${M?"assets":D}`,$=k==="single"?"Upload asset":"Upload assets",[V,R]=useState([]),P=[];if(p)P=[{id:p._id,value:p.value}];else if(N?.connect){let F=N.connect;P=[{id:F._id,value:F.value}];}let K=k==="single"?P:N?.connect?.map(F=>({id:F._id,value:F.value}))||[],[C,L]=useState(K),H=useMemo(()=>{let F=[];return M&&F.push({NOT:{path:{eq:null}}}),k==="multiple"&&s&&l&&F.push({[s]:{none:{_id:{eq:l}}}}),V.length>0&&F.push({OR:V.map(X=>({_id:{eq:X._id}}))}),F.length===0?{}:F.length===1?F[0]:{AND:F}},[s,l,M,k,V]),{count:h,data:m,fetchMore:_,isLoading:G,isLoadingMore:le}=u$1({entityNamePlural:g,schema:T,scope:a,variables:{offset:0,limit:Ua,where:H,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),ue=!!m?.length,Be=G&&!ue,Z=m?.length??0,De=h-f,je=De>0&&Z>0&&Z<De,Ve=J({attributesSchema:y?.attributes??[],checkboxSelect:k}),Ge=Array(5).fill({}),Ke=xu(Ve);useEffect(()=>{if(k!=="single"||C.length>0||!d||!m?.length)return;let F=m.find(X=>X.path===d);!F?._id||typeof F._id!="string"||L([{id:F._id,value:F}]);},[m,d,k,C.length]);let S=useCallback(F=>{r({type:"Dismiss",_id:F,payload:{}});},[r]),q=useCallback(()=>{_({variables:{offset:0,limit:Ua,where:H}});},[H,_]);function U(){let F;if(k==="single"){let[X]=C;F={_id:X?.id??"",value:X?.value??null};}k==="multiple"&&(F=C?.map((X,Te)=>({_id:X.id??"",...M?{sortOrder:Te}:{},value:X.value}))),n({type:"setRelationship",payload:{[A$1]:{connect:F,disconnect:N?.disconnect??[]}}}),S(e._id);}function ie(F){if(k==="multiple"){L(Te=>{let Ze=new Map(Te.map(W=>[W.id,W]));return F.map(W=>{if(Ze.has(W))return Ze.get(W);let Yo=m?.find(er=>er._id===W);return {id:W,value:Yo}})});return}let X=F[F.length-1];L(X?Te=>{if(Te.length===1&&Te[0].id===X)return Te;let Ze=m?.find(W=>W._id===X);return [{id:X,value:Ze}]}:[]);}function fe(){r({type:"AddEntity",payload:{entityName:u}});}async function x(){let F=await O({projectId:E,accept:c??"image/*",multiple:k==="multiple",maxBytes:4194304});L(X=>{if(k==="single"){let[W]=F;return W?[{id:W._id,value:W.asset}]:X}let Te=new Set(X.map(W=>W.id)),Ze=F.filter(W=>!Te.has(W._id)).map(W=>({id:W._id,value:W.asset}));return [...X,...Ze]});}return jsx(sa,{actions:jsxs(Fragment,{children:[jsx(d$2,{className:"fk:px-8",onClick:()=>{U();},variant:"default",children:"Select"}),M?null:jsx(d$2,{className:"fk:px-8",onClick:()=>{fe();},variant:"outline",children:`Create ${D}`}),M?jsxs(d$2,{className:"fk:px-8",onClick:()=>{x();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),$]}):null]}),depth:t,isFocused:o,onClose:()=>{S(e._id);},title:B,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(x$1,{columns:Be?Ke:Ve,data:Be?Ge:m??[],entityName:y?.name??"",hasMore:je,initialSelectionState:C?.reduce((F,X)=>({...F,...X.id?{[X.id]:true}:{}}),{}),isLoadingMore:le,onEntitySelectionChange:ie,onLoadMore:q,toolbarComponent:()=>jsx(wu,{entityNamePlural:g,projectId:E??"",setSearchResultIds:R})})})})}function wu({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[r,n]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,c]=useState(i),{results:f,isLoading:s$1}=a$8(t,a),l=useRef(null),u=useMemo(()=>Su(p=>{c({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(f){let p=JSON.stringify(f.map(A=>A._id).sort()),k=l.current?JSON.stringify(l.current.map(A=>A._id).sort()):"";p!==k&&(l.current=[...f],o(f.map(A=>({_id:A._id}))));}},[f,o]);function d(p){let{value:k}=p.target;n(k),u(k);}return jsxs("div",{className:"fk:relative fk:w-full",children:[s$1?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(s,{className:"fk:w-full fk:pl-11!",onChange:d,placeholder:"Search",value:r})]})}function Su(e,t=300){let o;return (...r)=>{clearTimeout(o),o=setTimeout(()=>e(...r),t);}}function Ga(){let e=z$1(),t=e.filter(r=>["AddEntity","EditEntity","EditRelationship"].some(n=>n===r.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(r=>{switch(r.type){case "AlertDialog":{let{payload:n}=r;return jsx(fo,{options:n.options},r._id)}case "DeleteEntity":return jsx(vr,{action:r},r._id);case "AddEntity":return jsx(tn,{action:r,depth:t.length-1,isFocused:r._id===o},r._id);case "EditEntity":return jsx(an,{action:r,depth:t.length-1,isFocused:r._id===o},r._id);case "EditRelationship":return jsx(fn,{action:r,depth:t.length-1,isFocused:r._id===o},r._id);default:return null}})})}function Za({user:e}){let t=useHref("/");return jsx("div",{className:"fk:flex fk:h-full fk:min-h-screen fk:items-center fk:justify-center fk:p-8 fk:bg-background",children:jsxs("div",{className:"fk:flex fk:max-w-md fk:flex-col fk:items-center fk:gap-4 fk:text-center",children:[jsx(FolderOpen,{className:"fk:h-10 fk:w-10 fk:text-muted-foreground"}),jsx("h1",{className:"fk:text-xl fk:font-medium",children:"No projects yet"}),jsxs("p",{className:"fk:text-sm fk:text-muted-foreground",children:[e.email," is not a member of any Flexkit project. Create one in the Dashboard, or ask a project owner to invite you, then come back here."]}),jsxs("div",{className:"fk:flex fk:gap-3",children:[jsx(d$2,{asChild:true,children:jsx("a",{href:`https://${a$7}/dashboard`,children:"Open Dashboard"})}),jsx(d$2,{onClick:()=>{f$3(t);},variant:"outline",children:"Sign out"})]})]})})}var Qa=Navigate;function Ka({mode:e,projectIds:t,projectSummaries:o,userId:r}){return jsx(g$3,{mode:e,children:jsx(e$5,{mode:e,projectIds:t,projectSummaries:o,userId:r,children:jsxs(t$2,{children:[jsx(Pi,{children:jsx(Ga,{})}),jsx(Outlet,{})]})})})}function Pu({projectIds:e}){let t=useLocation(),[o]=e;return t.pathname==="/"&&o?jsx(Qa,{replace:true,to:`/${o}`}):jsx(Ka,{mode:"projects",projectIds:e})}function Ru({message:e}){return jsx("div",{className:"fk:flex fk:h-full fk:min-h-screen fk:items-center fk:justify-center fk:p-8 fk:bg-background",children:jsxs(Wc,{className:"fk:max-w-lg",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Xc,{children:"Could not load your projects"}),jsxs(Yc,{className:"fk:flex fk:flex-col fk:gap-3",children:[jsx("span",{children:e}),jsx(d$2,{className:"fk:self-start",onClick:()=>{window.location.reload();},size:"sm",variant:"outline",children:"Try again"})]})]})})}function Lu(){let e=Ci(),t=useLocation();if(e.status==="loading")return jsx(a$5,{});if(e.status==="anonymous")return jsx(Do,{});if(e.status==="error")return jsx(Ru,{message:e.message});let o=e.projects.map(r=>r.id);if(o.length===0)return jsx(Za,{user:e.user});if(t.pathname==="/"){let r=ni(o,oi());return jsx(Qa,{replace:true,to:`/${r??""}`})}return jsx(Ka,{mode:"hosted",projectIds:o,projectSummaries:e.projects,userId:e.user.id})}function Ya({projectIds:e}){return e===void 0?jsx(Lu,{}):jsx(Pu,{projectIds:e})}function es(e){return !e||e==="/"?"/":`/${e.replace(/^\/+|\/+$/g,"")}`}function ts(){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})})]}):mr(e)?ii(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(Fo,{})]})})]})}var Hu=RouterProvider;function qu({projectIds:e,basename:t}){let[o,r]=useState(false),n=debug("core:flexkit-studio");if(useEffect(()=>{r(true);},[]),!o)return null;if(e!==void 0&&e.length===0)throw new Error('FlexkitStudio needs at least one project id: <FlexkitStudio projectIds={["..."]} />. Omit the prop for hosted mode.');let a=createBrowserRouter([{path:"/",element:jsx(Ya,{projectIds:e}),errorElement:jsx(ts,{}),children:[{path:":projectId/*",element:jsx(bi,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}})}]}],{basename:es(t)});return n("Init Studio"),jsx(a$3,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$5,{children:jsx(y,{children:jsx(Hu,{router:a})})})})}function Uu(e){let t=useApolloClient(),{currentProjectSchema:o}=f$2();return useCallback(async()=>{o&&await r$2(t,o$3(e,o));},[t,e,o])}
|
|
12
|
-
export{
|
|
11
|
+
`),N({variables:{where:{_id:{eq:r}}},onCompleted:Ve=>{i.current?.applyLocalAttributeIds(n$1(Ve,n,f)),r$2(D,o$3(n,f)),toast.success("Your changes have been saved.");}}),y(true);},[D,V.user,k,r,n,y,f,g,N]),_=h$1,G=_.length>0,le=H&&!G;function ue(Z,De){let je=e$3(Z),Ve=je?.name,Ge=je?.relationship?.field!==void 0;if(!De.length||!Ve)return "";if(!Ge||!je?.relationship?.field)return De[0][Ve]?.value;let Ye=De[0][Ve]?.value?.[je.relationship.field],S=Array.isArray(Ye)?Ye[0]:Ye;if(S&&typeof S=="object"){let $=S;return $[k]??$.default??""}return S??""}let Be=G&&m?ue(m,_):"";return jsx(na$1,{actions:jsxs(Fragment,{children:[s&&s.length>1?jsxs(a,{onValueChange:Z=>{L(Z);},value:k,children:[jsxs(d,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c,{children:find(propEq(k,"name"))(s).label})]}),jsx(e,{children:s.map(Z=>jsx(g$1,{value:Z.name,children:Z.label},Z.name))})]}):null,jsx(sn,{handleSave:C$1,isLoading:O.loading})]}),beforeClose:P,depth:t,forceClose:B,isFocused:o,onClose:()=>{Q(e$1._id);},onFormChange:()=>{},title:Be,children:le||!G?jsx(ln,{}):jsxs(Fragment,{children:[O.isProjectReadOnly?jsx(Xa,{}):null,jsx(Zo,{currentScope:k,defaultScope:l,entityId:r,entityName:d$2,entityNamePlural:n,formData:_[0],onSubmit:u,ref:i,schema:f,setIsDirty:R})]})})}var ts=25;function $u(e){return e.map(t=>({...t,cell:()=>jsx(t$3,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function un({action:e,depth:t,isFocused:o}){let r=A(),n=d$1(),{relationships:i,scope:a}=c$1(),{assetAccept:c,connectedEntitiesCount:f,connectionName:s,entityId:l,entityName:m,initialAssetPath:d,initialConnection:p,mode:k,relationshipId:A$1}=e.payload,{currentProject:b,currentProjectId:E}=f$2(),D=b?.schema??[],y=find(propEq(m,"name"))(D),g=y?.plural??"",N=i[A$1],O=c$4(),M=m==="_asset",T=M?"asset":y?.menu?.label??m.toLowerCase(),B=M&&k==="single"?"Select asset":`Select ${M?"assets":T}`,q=k==="single"?"Upload asset":"Upload assets",[V,R]=useState([]),P=[];if(p)P=[{id:p._id,value:p.value}];else if(N?.connect){let F=N.connect;P=[{id:F._id,value:F.value}];}let Q=k==="single"?P:N?.connect?.map(F=>({id:F._id,value:F.value}))||[],[C,L]=useState(Q),H=useMemo(()=>{let F=[];return M&&F.push({NOT:{path:{eq:null}}}),k==="multiple"&&s&&l&&F.push({[s]:{none:{_id:{eq:l}}}}),V.length>0&&F.push({OR:V.map(X=>({_id:{eq:X._id}}))}),F.length===0?{}:F.length===1?F[0]:{AND:F}},[s,l,M,k,V]),{count:h,data:u,fetchMore:_,isLoading:G,isLoadingMore:le}=u$1({entityNamePlural:g,schema:D,scope:a,variables:{offset:0,limit:ts,where:H,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),ue=!!u?.length,Be=G&&!ue,Z=u?.length??0,De=h-f,je=De>0&&Z>0&&Z<De,Ve=J({attributesSchema:y?.attributes??[],checkboxSelect:k}),Ge=Array(5).fill({}),Ye=$u(Ve);useEffect(()=>{if(k!=="single"||C.length>0||!d||!u?.length)return;let F=u.find(X=>X.path===d);!F?._id||typeof F._id!="string"||L([{id:F._id,value:F}]);},[u,d,k,C.length]);let S=useCallback(F=>{r({type:"Dismiss",_id:F,payload:{}});},[r]),$=useCallback(()=>{_({variables:{offset:0,limit:ts,where:H}});},[H,_]);function U(){let F;if(k==="single"){let[X]=C;F={_id:X?.id??"",value:X?.value??null};}k==="multiple"&&(F=C?.map((X,Pe)=>({_id:X.id??"",...M?{sortOrder:Pe}:{},value:X.value}))),n({type:"setRelationship",payload:{[A$1]:{connect:F,disconnect:N?.disconnect??[]}}}),S(e._id);}function ie(F){if(k==="multiple"){L(Pe=>{let Ze=new Map(Pe.map(W=>[W.id,W]));return F.map(W=>{if(Ze.has(W))return Ze.get(W);let er=u?.find(tr=>tr._id===W);return {id:W,value:er}})});return}let X=F[F.length-1];L(X?Pe=>{if(Pe.length===1&&Pe[0].id===X)return Pe;let Ze=u?.find(W=>W._id===X);return [{id:X,value:Ze}]}:[]);}function fe(){r({type:"AddEntity",payload:{entityName:m}});}async function x(){let F=await O({projectId:E,accept:c??"image/*",multiple:k==="multiple",maxBytes:4194304});L(X=>{if(k==="single"){let[W]=F;return W?[{id:W._id,value:W.asset}]:X}let Pe=new Set(X.map(W=>W.id)),Ze=F.filter(W=>!Pe.has(W._id)).map(W=>({id:W._id,value:W.asset}));return [...X,...Ze]});}return jsx(na$1,{actions:jsxs(Fragment,{children:[jsx(b$2,{className:"fk:px-8",onClick:()=>{U();},variant:"default",children:"Select"}),M?null:jsx(b$2,{className:"fk:px-8",onClick:()=>{fe();},variant:"outline",children:`Create ${T}`}),M?jsxs(b$2,{className:"fk:px-8",onClick:()=>{x();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),q]}):null]}),depth:t,isFocused:o,onClose:()=>{S(e._id);},title:B,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(x$1,{columns:Be?Ye:Ve,data:Be?Ge:u??[],entityName:y?.name??"",hasMore:je,initialSelectionState:C?.reduce((F,X)=>({...F,...X.id?{[X.id]:true}:{}}),{}),isLoadingMore:le,onEntitySelectionChange:ie,onLoadMore:$,toolbarComponent:()=>jsx(qu,{entityNamePlural:g,projectId:E??"",setSearchResultIds:R})})})})}function qu({entityNamePlural:e,projectId:t,setSearchResultIds:o}){let[r,n]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[a,c]=useState(i),{results:f,isLoading:s$1}=a$b(t,a),l=useRef(null),m=useMemo(()=>Ju(p=>{c({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(f){let p=JSON.stringify(f.map(A=>A._id).sort()),k=l.current?JSON.stringify(l.current.map(A=>A._id).sort()):"";p!==k&&(l.current=[...f],o(f.map(A=>({_id:A._id}))));}},[f,o]);function d(p){let{value:k}=p.target;n(k),m(k);}return jsxs("div",{className:"fk:relative fk:w-full",children:[s$1?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(s,{className:"fk:w-full fk:pl-11!",onChange:d,placeholder:"Search",value:r})]})}function Ju(e,t=300){let o;return (...r)=>{clearTimeout(o),o=setTimeout(()=>e(...r),t);}}function rs(){let e=z$1(),t=e.filter(r=>["AddEntity","EditEntity","EditRelationship"].some(n=>n===r.type)),o=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(r=>{switch(r.type){case "AlertDialog":{let{payload:n}=r;return jsx(mo,{options:n.options},r._id)}case "DeleteEntity":return jsx(Cr,{action:r},r._id);case "AddEntity":return jsx(nn,{action:r,depth:t.length-1,isFocused:r._id===o},r._id);case "EditEntity":return jsx(fn,{action:r,depth:t.length-1,isFocused:r._id===o},r._id);case "EditRelationship":return jsx(un,{action:r,depth:t.length-1,isFocused:r._id===o},r._id);default:return null}})})}function ns({user:e}){let t=useHref("/");return jsx("div",{className:"fk:flex fk:h-full fk:min-h-screen fk:items-center fk:justify-center fk:p-8 fk:bg-background",children:jsxs("div",{className:"fk:flex fk:max-w-md fk:flex-col fk:items-center fk:gap-4 fk:text-center",children:[jsx(FolderOpen,{className:"fk:h-10 fk:w-10 fk:text-muted-foreground"}),jsx("h1",{className:"fk:text-xl fk:font-medium",children:"No projects yet"}),jsxs("p",{className:"fk:text-sm fk:text-muted-foreground",children:[e.email," is not a member of any Flexkit project. Create one in the Dashboard, or ask a project owner to invite you, then come back here."]}),jsxs("div",{className:"fk:flex fk:gap-3",children:[jsx(b$2,{asChild:true,children:jsx("a",{href:`https://${a$a}/dashboard`,children:"Open Dashboard"})}),jsx(b$2,{onClick:()=>{f$3(t);},variant:"outline",children:"Sign out"})]})]})})}var as=Navigate;function ss({mode:e,projectIds:t,projectSummaries:o,userId:r}){return jsx(g$3,{mode:e,children:jsx(e$6,{mode:e,projectIds:t,projectSummaries:o,userId:r,children:jsxs(t$2,{children:[jsx(zi,{children:jsx(rs,{})}),jsx(Outlet,{})]})})})}function Yu({projectIds:e}){let t=useLocation(),[o]=e;return t.pathname==="/"&&o?jsx(as,{replace:true,to:`/${o}`}):jsx(ss,{mode:"projects",projectIds:e})}function ed({message:e}){return jsx("div",{className:"fk:flex fk:h-full fk:min-h-screen fk:items-center fk:justify-center fk:p-8 fk:bg-background",children:jsxs(Rc,{className:"fk:max-w-lg",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(Sc,{children:"Could not load your projects"}),jsxs(Tc,{className:"fk:flex fk:flex-col fk:gap-3",children:[jsx("span",{children:e}),jsx(b$2,{className:"fk:self-start",onClick:()=>{window.location.reload();},size:"sm",variant:"outline",children:"Try again"})]})]})})}function td(){let e=Ti(),t=useLocation();if(e.status==="loading")return jsx(a$7,{});if(e.status==="anonymous")return jsx(Po,{});if(e.status==="error")return jsx(ed,{message:e.message});let o=e.projects.map(r=>r.id);if(o.length===0)return jsx(ns,{user:e.user});if(t.pathname==="/"){let r=mi(o,fi());return jsx(as,{replace:true,to:`/${r??""}`})}return jsx(ss,{mode:"hosted",projectIds:o,projectSummaries:e.projects,userId:e.user.id})}function ls({projectIds:e}){return e===void 0?jsx(td,{}):jsx(Yu,{projectIds:e})}function fs(e){return !e||e==="/"?"/":`/${e.replace(/^\/+|\/+$/g,"")}`}function cs(){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})})]}):dr(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(To,{})]})})]})}var fd=RouterProvider;function cd({projectIds:e,basename:t}){let[o,r]=useState(false),n=debug("core:flexkit-studio");if(useEffect(()=>{r(true);},[]),!o)return null;if(e!==void 0&&e.length===0)throw new Error('FlexkitStudio needs at least one project id: <FlexkitStudio projectIds={["..."]} />. Omit the prop for hosted mode.');let a=createBrowserRouter([{path:"/",element:jsx(ls,{projectIds:e}),errorElement:jsx(cs,{}),children:[{path:":projectId/*",element:jsx(Ii,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}})}]}],{basename:fs(t)});return n("Init Studio"),jsx(a$5,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$7,{children:jsx(y,{children:jsx(fd,{router:a})})})})}function dd(e){let t=useApolloClient(),{currentProjectSchema:o}=f$2();return useCallback(async()=>{o&&await r$2(t,o$3(e,o));},[t,e,o])}
|
|
12
|
+
export{Zr as ALL_FIELDS_GROUP,xt as ALL_FIELDS_GROUP_NAME,Ie as DefaultValueSwitch,cd as FlexkitStudio,dd as useRefreshEntityList};//# sourceMappingURL=index.js.map
|
|
13
13
|
//# sourceMappingURL=index.js.map
|