@flexkit/studio 0.0.33 → 0.0.34
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/{chunk-MLYKIVZC.js → chunk-JH4MVD36.js} +2 -2
- package/dist/{chunk-MLYKIVZC.js.map → chunk-JH4MVD36.js.map} +1 -1
- package/dist/{chunk-2OBWJ6UY.js → chunk-LIV5RBWJ.js} +2 -2
- package/dist/chunk-LIV5RBWJ.js.map +1 -0
- package/dist/{chunk-ORY5DLME.js → chunk-WJ4ORIXF.js} +2 -2
- package/dist/{chunk-ORY5DLME.js.map → chunk-WJ4ORIXF.js.map} +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.js +32 -32
- package/dist/index.js.map +1 -1
- package/dist/{search-FTC7ELZX.js → search-KIII5N7I.js} +2 -2
- package/dist/{search-FTC7ELZX.js.map → search-KIII5N7I.js.map} +1 -1
- package/dist/{types.d-C12xWeN_.d.ts → types.d-9Gbw_A9L.d.ts} +32 -29
- package/dist/ui.d.ts +3 -3
- package/dist/ui.js +1 -1
- package/dist/ui.js.map +1 -1
- package/dist/{user-nav-Z7GBLYQA.js → user-nav-6UKDSUF3.js} +2 -2
- package/dist/{user-nav-Z7GBLYQA.js.map → user-nav-6UKDSUF3.js.map} +1 -1
- package/package.json +3 -1
- package/dist/chunk-2OBWJ6UY.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}from'./chunk-MGXHZDFZ.js';import {a as a$b}from'./chunk-D4XLXU2H.js';import {a as a$d}from'./chunk-D62TAYLI.js';import {a as a$a}from'./chunk-JAARDXQZ.js';import {a,b as b$7}from'./chunk-FPH4YETF.js';import {a as a$e}from'./chunk-AEBTHXEP.js';import {a as a$c}from'./chunk-CCI3FGPF.js';import'./chunk-F2ILIHAU.js';import {h,i,j,k,l,n,o,p,s,t,q,u,x as x$1,f as f$3,c as c$8,d as d$3,g as g$3}from'./chunk-PXB5QSHN.js';import {a as a$7}from'./chunk-7GBAYC7G.js';import'./chunk-OEWYLKO7.js';import {a as a$8,b as b$5,c as c$4,e as e$3}from'./chunk-YW2EEXMV.js';import {d as d$2,c as c$2,e as e$4,b as b$9,a as a$i,f as f$4}from'./chunk-MLYKIVZC.js';export{c as useAppContext,d as useAppDispatch,f as useSearch}from'./chunk-MLYKIVZC.js';import {w,x,c as c$5,b as b$6,n as n$1,p as p$1,q as q$1,s as s$1,u as u$1,t as t$1,r}from'./chunk-KHPTVIYT.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$2,f as f$1,g as g$1}from'./chunk-XU2JGXYC.js';import {b,a as a$j}from'./chunk-ORY5DLME.js';export{b as useAuth}from'./chunk-ORY5DLME.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$2,m,a as a$h,l as l$1,i as i$2,b as b$b,r as r$1}from'./chunk-JCHD4EGB.js';import {d,a as a$f,b as b$8,e as e$5,c as c$7}from'./chunk-2OBWJ6UY.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-2OBWJ6UY.js';import {b as b$4,c as c$6,a as a$l}from'./chunk-WDRCARCP.js';export{b as IMAGES_BASE_URL}from'./chunk-WDRCARCP.js';import {b as b$3,a as a$9}from'./chunk-EYGOJ2ZN.js';import {a as a$g,b as b$a}from'./chunk-WIUPQHZ5.js';import {a as a$4}from'./chunk-GFDWGYUR.js';import {a as a$6}from'./chunk-VUAFNQK7.js';export{a as DefaultValueSwitch}from'./chunk-VUAFNQK7.js';import'./chunk-KGYH74NA.js';import {b as b$1,c,e,f,h as h$1,g,i as i$1,j as j$1,a as a$k}from'./chunk-FVFRTCEB.js';import {a as a$1}from'./chunk-O2QMYUPS.js';import*as Lo from'react';import {lazy,createContext,memo,forwardRef,useMemo,useState,useRef,useEffect,useImperativeHandle,createElement,useId,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,uniq,omit,pick,toPairs,props}from'ramda';import ic,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,PencilIcon,Trash2Icon,Settings2,RefreshCw,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as vo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,NetworkStatus,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import $r from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import Hd from'react-markdown';import {useReactTable,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function ho(){let[e,t]=useState(false),{theme:n,setTheme:o}=b$b();return useEffect(()=>{t(true);},[]),e?jsxs(c$8,{size:"sm",type:"single",value:n,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{o("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{o("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{o("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function yo(){let{resolvedTheme:e}=b$b();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var oc=cva("fk:relative fk:w-full fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:[&>svg~*]:pl-7 fk:[&>svg+div]:translate-y-[-3px] fk:[&>svg]:absolute fk:[&>svg]:left-4 fk:[&>svg]:top-4 fk:[&>svg]:text-foreground",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:border-none fk:text-destructive fk:bg-destructive-foreground fk:[&>svg]:text-destructive"}},defaultVariants:{variant:"default"}});function ye({className:e,variant:t,...n}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$1(oc({variant:t}),e),...n})}function qe({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$1("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ve({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$1("fk:text-sm fk:[&_p]:leading-relaxed",e),...t})}var fc=vo.object({email:vo.email({error:"Please enter a valid email address"})});function fr({projectId:e$1,setIsEmailLogin:t}){let[n,o]=useState(false),[r,i]=useState(false),{mutate:s}=useSWRConfig(),a=useForm({resolver:zodResolver(fc),defaultValues:{email:""}}),c$1=new URL(c$6(e$1).loginOtpSend,a$l),{data:l,error:u,isLoading:f}=ic(r?c$1.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:a.getValues("email")})}).then(v=>v.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),m=l&&"error"in l&&l.error.code,p=l&&"token"in l,d=l&&"token"in l?l.token:"";useEffect(()=>{if(!p)return;let h=0,v=setInterval(()=>{if(h>100){clearInterval(v),o(true);return}let y=new URL(c$6(e$1).loginOtpConfirm,a$l),b="/api/flexkit/set-token";fetch(`${y.href}?email=${encodeURIComponent(a.getValues("email"))}&token=${encodeURIComponent(d)}`).then(E=>{E.status===200&&E.json().then(A=>{fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:A.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(v);}},[a,p,e$1,d]);function g$1(){o(false),i(true),s(c$1.href);}return jsx("div",{className:"fk:w-full",children:p?jsx(ye,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(ve,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:a.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b$1,{...a,children:jsxs("form",{onSubmit:h=>{a.handleSubmit(g$1)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[m==="not_exists"&&jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${encodeURIComponent(a.getValues("email"))}`,children:"Sign up?"})]})}),m==="unknown_error"||u?jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."," "]})}):null,n?jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:a.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$7,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i$1,{})]})}),jsxs(b$3,{"aria-disabled":f,className:"fk:w-full",type:"submit",disabled:!!f,children:[f?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function ps({projectId:e}){let{projects:t}=d(),[n,o]=useState(t.find(g=>g.projectId===e)??t[0]),[r,i]=useState(false),{data:s,error:a,isLoading:c}=ic(c$6(e).authProviders,g=>fetch(g,{mode:"cors"}).then(h=>h.json())),[l,u]=b(),f=new Date().getFullYear(),m=useLocation(),p=m.state?.from?.pathname??m.pathname,d$2=p.includes(n.projectId)?`${location.origin}${p}`:`${location.origin}${b$a(n.basePath,n.projectId)}`;if(a)throw new Error("Error fetching auth providers");return c||l||!s?jsx(yo,{}):u.user?.id?jsx(Navigate,{replace:true,state:{from:m},to:n.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$k,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:n.projectId,onValueChange:g=>{o(t.find(h=>h.projectId===g)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":n.title,children:n.title})}),jsx(e$1,{children:t.map(g=>jsx(g$1,{value:g.projectId,children:g.title},g.projectId))})]})]}):null,r?jsx(fr,{projectId:e,setIsEmailLogin:i}):jsxs(Fragment,{children:[jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-sm fk:text-left fk:text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk:flex fk:flex-col fk:space-y-6",children:[s.providers.map(g=>jsx(b$3,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:gc({url:g.url,projectId:n.projectId,basePath:"/api/flexkit/get-token",fromPath:d$2}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",f]})]}),jsx(ho,{})]})})]})}function gc({projectId:e,url:t,basePath:n,fromPath:o}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${n}`),r.set("projectId",e),r.set("redirect",o),`${t}?${r.toString()}`}var kc=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],hc={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},bo=class e extends Error{code;constructor(t,n){super(n??hc[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,n){return new e(t,n)}};function dr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:kc.includes(t)}function gs(e){if(dr(e))return e.code}var yc={developer:true,owner:true};function ks(e){return !!(e&&yc[e])}function hs(e){return `/api/flexkit/${e}/tools/dev-connect/tick`}var mr=2e3,bc=1e4,pr=false;async function Cc(e){try{let t=await fetch(e,{credentials:"same-origin",method:"POST"});if(t.status!==200)return !1;let n=await t.json();return typeof n.job=="string"&&n.job.length>0}catch{return false}}function ys({projectId:e,role:t}){return useEffect(()=>{if(!ks(t)||!e)return;let n=false,o=mr,r,i=hs(e);function s(l){n||document.hidden||(r!==void 0&&window.clearTimeout(r),r=window.setTimeout(()=>{a();},l));}async function a(){if(n||document.hidden)return;if(pr){s(o);return}pr=true;let l=await Cc(i);pr=false,l?o=mr:o=Math.min(o*2,bc),s(o);}function c(){if(document.hidden){r!==void 0&&(window.clearTimeout(r),r=void 0);return}o=mr,a();}return a(),document.addEventListener("visibilitychange",c),()=>{n=true,document.removeEventListener("visibilitychange",c),r!==void 0&&window.clearTimeout(r);}},[e,t]),null}function ws({apps:e,version:t}){let[n,o]=useState(0),[r,i]=useState(e),[s,a]=useState([]),c=useRef(null),l=useLocation(),{projectId:u}=useParams(),f=e.find(p=>l.pathname.includes(`/${u}/${p.name}`))?.name,m$1=e.find(p=>l.pathname.includes(`/${u}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(c.current===null)return;let p=new ResizeObserver(()=>{o(c.current?.offsetHeight??0);});return p.observe(c.current),function(){p.disconnect();}},[f]),useEffect(()=>{let p=Math.floor(n/48)-2,d=e.slice(0,p);if(!d.find(h=>h.name===m$1)){let h=e.find(v=>v.name===m$1);d.pop(),h&&d.push(h);}let g=e.filter(h=>!d.includes(h));i(d),a(g);},[e,m$1,n]),f===void 0&&m$1?jsx(Navigate,{to:`${l.pathname}/${m$1}`}):jsx(a$8,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:c,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:p.name,children:p.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:p.title})})]})},p.name))}),s.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:s.map(p=>jsx(h$2,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$2,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${u}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(m,{}),jsx(h$2,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var Pc={"navbar.logo":lazy(()=>import('./logo-B6ZKLGM7.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-X6YVZYKL.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-FTC7ELZX.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-Z7GBLYQA.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-TACKLQJH.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-M3DRK7LU.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-YF4K2VBM.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-ZVPFS73O.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-SQXG7XJT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-HAYTKNMY.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-DDEWTNLB.js').then(({DateTime:e})=>({default:e}))),"previewFields.select":lazy(()=>import('./select-H3JHOCWR.js').then(({Select:e})=>({default:e})))};function Ln(e){let{getContributionPointConfig:t}=d(),[n,...o]=e.split("."),r=Pc[e],i=t(n,o);return i?.length>0?i[0]?.component:r}function xs({projectId:e,projects:t}){let{resolvedTheme:n}=b$b(),o=Ln("navbar.logo"),r=Ln("navbar.projectSelector"),i=Ln("navbar.search"),s=Ln("navbar.userNav"),a=t.find(m=>m.projectId===e)??t[0],{basePath:c,schema:l}=a,u=useNavigate();function f(m){startTransition(()=>{u(b$a(c,e,"desk","list",m.entityNamePlural)+`?id=${m.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-14 fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-30",children:[jsx(Suspense,{fallback:null,children:jsx(o,{theme:n,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:f,projectId:e,schema:l},e)})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(s,{projectId:e})})})]})}function Es({version:e}){let{contributions:t,projects:n}=d(),[o,r]=b(),{projectId:i}=useParams(),s=find(propEq(i??"","projectId"))(n);if(!s)throw new bo("PROJECT_NOT_FOUND");let{scopes:a}=s,{apps:c}=t,l=d$2(),u=useLocation();return useEffect(()=>{if(a){let f=a.find(p=>p.isDefault)||a[0],m="";typeof localStorage<"u"&&(m=localStorage.getItem(`${a$i}${i}`)??""),l({type:"setScope",payload:{projectId:i,scope:m||f.name}});}},[u]),o?jsx(yo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(xs,{projectId:i??"",projects:n}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(ws,{apps:c,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{}),jsx(ys,{projectId:i??"",role:r.user.role})]}):jsx(ps,{projectId:i??""})}function Ns(e){return e?"cause"in e:false}function Xt(e){if(!e)return null;if(ServerError.is(e))return e;if(Ns(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Ds(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Wt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function wo(e){if(!e)return null;let t=Rs(e).filter(n=>!qc(n));return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(n=>`- ${n}`)].join(`
|
|
2
|
-
`)}function Fs(e,t){return e?Rs(e).some(n=>n.includes(`Cannot query field "${t}"`)):false}function Rs(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ts).map(({message:r})=>r);let t=Ds(e);if(t&&Mn(t))return [t];let n=Xt(e);if(n?.statusCode!==400)return [];let o=Wt(n.bodyText)??Hc(n)??Uc(e);return o?Array.isArray(o.errors)?o.errors.filter(Ts).map(r=>r.message):typeof o.message=="string"&&Mn(o.message)?[o.message]:typeof o.error=="string"&&Mn(o.error)?[o.error]:[]:[]}function Hc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Uc(e){if(!Ns(e))return null;let{cause:t}=e,n=Ds(t);if(n&&Mn(n))return {message:n};if(!t||typeof t!="object")return null;let{result:o}=t;return o&&typeof o=="object"?o:null}function Ts(e){if(!e||typeof e!="object")return false;let{extensions:t,message:n}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof n=="string"?true:typeof n=="string"&&Mn(n)}function Mn(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}function qc(e){return /Cannot query field "[_A-Za-z][_0-9A-Za-z]*Total" on type "Query"/.test(e)}var ru=ApolloProvider,Ls=createContext(void 0);function Kt(){let e=useContext(Ls);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function iu(e){return new ErrorLink(({error:t})=>{let n=wo(t);if(n){e(n);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:s})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${s}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let o=Xt(t);if(o?.statusCode===400){let r=Wt(o.bodyText),i=null;if(r&&typeof r=="object"){let{error:s,errors:a,message:c}=r;if(typeof c=="string")i=c;else if(Array.isArray(a)){let[l]=a;if(l&&typeof l.message=="string"){let{message:u}=l;i=u;}}else typeof s=="string"?i=s:i=JSON.stringify(r);}else i=o.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.warn(`[Network error]: ${o.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function su(e,t){return from([iu(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function au(e,t){return new ApolloClient({link:su(e??"",t),cache:new InMemoryCache({dataIdFromObject:n=>n._id?n._id:defaultDataIdFromObject(n)})})}function Ms({children:e}){let{currentProjectId:t}=d(),[n,o]=useState(null),r=useMemo(()=>({schemaErrorMessage:n,setSchemaErrorMessage:o}),[n]),i=useMemo(()=>au(t,o),[t]);return jsx(Ls.Provider,{value:r,children:jsx(ru,{client:i,children:e})})}function _s({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function hr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function lu({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$1("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function $s({className:e,size:t="default",...n}){return jsxs(hr,{children:[jsx(lu,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$1("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...n})]})}function Os({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$1("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Vs({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$1("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Bs({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$1("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function zs({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$1("fk:text-sm fk:text-muted-foreground",e),...t})}function js({className:e,variant:t="default",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$1(e),...o})})}function Hs({className:e,variant:t="outline",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$1(e),...o})})}function _n({options:e}){let[t,n]=useState(false),[o,r]=useState(false),[i,s]=useState(false);useEffect(()=>{n(true);},[]);function a(){n(false),i||e.dialogActionCancel?.(),i&&s(false);}async function c(){r(true),s(true),n(false),await new Promise(l=>{globalThis.setTimeout(l,150);});try{let l=e.dialogActionSubmit?.();l&&typeof l.then=="function"&&await l;}finally{r(false);}}return jsx(_s,{onOpenChange:a,open:t,children:jsx(hr,{children:jsxs($s,{className:"sm:max-w-[425px]",children:[jsxs(Os,{children:[jsx(Bs,{children:e.dialogTitle}),jsx(zs,{children:e.dialogMessage})]}),jsxs(Vs,{children:[jsx(Hs,{disabled:o,onClick:a,children:e.dialogCancelTitle}),jsxs(js,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:o,onClick:c,children:[o?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Gs=createContext([]),Qs=createContext(()=>{});function mu(e,t){let n=t.type;switch(t._id||(t._id=Date.now().toString()),n){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(o=>o._id!==t._id);default:throw Error(`Unknown action: ${n}`)}}function Xs({children:e}){let[t,n]=useReducer(mu,[]);return jsx(Gs.Provider,{value:t,children:jsx(Qs.Provider,{value:n,children:e})})}function Ws(){return useContext(Gs)}function pe(){return useContext(Qs)}function
|
|
1
|
+
import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}from'./chunk-MGXHZDFZ.js';import {a as a$b}from'./chunk-D4XLXU2H.js';import {a as a$d}from'./chunk-D62TAYLI.js';import {a as a$a}from'./chunk-JAARDXQZ.js';import {a,b as b$7}from'./chunk-FPH4YETF.js';import {a as a$e}from'./chunk-AEBTHXEP.js';import {a as a$c}from'./chunk-CCI3FGPF.js';import'./chunk-F2ILIHAU.js';import {h,i,j,k,l,n,o,p,s,t,q,u,x as x$1,f as f$3,c as c$8,d as d$3,g as g$3}from'./chunk-PXB5QSHN.js';import {a as a$7}from'./chunk-7GBAYC7G.js';import'./chunk-OEWYLKO7.js';import {a as a$8,b as b$5,c as c$4,e as e$3}from'./chunk-YW2EEXMV.js';import {d as d$2,c as c$2,e as e$4,b as b$9,a as a$i,f as f$4}from'./chunk-JH4MVD36.js';export{c as useAppContext,d as useAppDispatch,f as useSearch}from'./chunk-JH4MVD36.js';import {w,x,c as c$5,b as b$6,n as n$1,p as p$1,q as q$1,s as s$1,u as u$1,t as t$1,r}from'./chunk-KHPTVIYT.js';import {a as a$5,d as d$1,c as c$1,e as e$1,b as b$2,f as f$1,g as g$1}from'./chunk-XU2JGXYC.js';import {b,a as a$j}from'./chunk-WJ4ORIXF.js';export{b as useAuth}from'./chunk-WJ4ORIXF.js';import {c as c$3,e as e$2,f as f$2,g as g$2,h as h$2,m,a as a$h,l as l$1,i as i$2,b as b$b,r as r$1}from'./chunk-JCHD4EGB.js';import {d,a as a$f,b as b$8,e as e$5,c as c$7}from'./chunk-LIV5RBWJ.js';export{a as assetSchema,b as tagSchema,d as useConfig}from'./chunk-LIV5RBWJ.js';import {b as b$4,c as c$6,a as a$l}from'./chunk-WDRCARCP.js';export{b as IMAGES_BASE_URL}from'./chunk-WDRCARCP.js';import {b as b$3,a as a$9}from'./chunk-EYGOJ2ZN.js';import {a as a$g,b as b$a}from'./chunk-WIUPQHZ5.js';import {a as a$4}from'./chunk-GFDWGYUR.js';import {a as a$6}from'./chunk-VUAFNQK7.js';export{a as DefaultValueSwitch}from'./chunk-VUAFNQK7.js';import'./chunk-KGYH74NA.js';import {b as b$1,c,e,f,h as h$1,g,i as i$1,j as j$1,a as a$k}from'./chunk-FVFRTCEB.js';import {a as a$1}from'./chunk-O2QMYUPS.js';import*as Lo from'react';import {lazy,createContext,memo,forwardRef,useMemo,useState,useRef,useEffect,useImperativeHandle,createElement,useId,useCallback,useContext,Fragment as Fragment$1,useReducer,Suspense,startTransition}from'react';import {debug}from'debug';import {useParams,createBrowserRouter,RouterProvider,useRouteError,useLocation,Outlet,useNavigate,Navigate,NavLink,Link as Link$1,isRouteErrorResponse}from'react-router-dom';export{Outlet,useLocation,useParams}from'react-router-dom';import {find,propEq,equals,uniqBy,prop,map,uniq,omit,pick,toPairs,props}from'ramda';import ic,{useSWRConfig}from'swr';import {Text,CheckSquare,Heading1,Heading2,Heading3,List,ListOrdered,TextQuote,Code,ImageIcon,Youtube,Twitter,AlertTriangle,Image,Upload,Search,File,Ellipsis,Download,Copy,RefreshCwOff,Maximize2,X,Calendar,ChevronsUpDown,Link,TextIcon,ChevronDown,Check,Trash,SigmaIcon,BoldIcon,ItalicIcon,UnderlineIcon,StrikethroughIcon,CodeIcon,ChevronLeftIcon,ChevronRightIcon,ChevronDownIcon,ArrowUp,ArrowDown,TrashIcon,RefreshCcwDot,CheckCheck,ArrowDownWideNarrow,WrapText,StepForward,Trash2,AlertCircle,CirclePlus,PencilIcon,Trash2Icon,Settings2,RefreshCw,Loader2,MoreHorizontal,Settings,Wrench,PackageCheck,PackageX,Moon,Sun,Monitor,Mail,LoaderCircle}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useForm}from'react-hook-form';import*as vo from'zod';import {z}from'zod';import {zodResolver}from'@hookform/resolvers/zod';import {cva}from'class-variance-authority';import {gql,NetworkStatus,ApolloClient,InMemoryCache,defaultDataIdFromObject,from,HttpLink}from'@apollo/client';export{gql}from'@apollo/client';import {useLazyQuery,useApolloClient,useMutation,useQuery,ApolloProvider}from'@apollo/client/react';import {ErrorLink}from'@apollo/client/link/error';import {ServerError,CombinedGraphQLErrors,CombinedProtocolErrors}from'@apollo/client/errors';import {Popover,AlertDialog}from'radix-ui';import {toast}from'sonner';import {v4}from'uuid';import $r from'bytes';import {defaultStyles,FileIcon}from'react-file-icon';import {format}from'date-fns';import {getDefaultClassNames,DayPicker}from'react-day-picker';import {createSuggestionItems,Command,renderItems,EditorRoot,EditorContent,EditorCommand,EditorCommandEmpty,EditorCommandList,EditorCommandItem,ImageResizer,handleImageDrop,handleImagePaste,handleCommandNavigation,useEditor,removeAIHighlight,EditorBubble,EditorBubbleItem,addAIHighlight,getPrevText}from'novel';import {useDebouncedCallback}from'use-debounce';import {useCompletion}from'@ai-sdk/react';import Hd from'react-markdown';import {useReactTable,getSortedRowModel,getPaginationRowModel,getFilteredRowModel,getCoreRowModel,flexRender}from'@tanstack/react-table';export{flexRender,getCoreRowModel,getFacetedRowModel,getFacetedUniqueValues,getFilteredRowModel,getPaginationRowModel,getSortedRowModel,useReactTable}from'@tanstack/react-table';import {useVirtualizer}from'@tanstack/react-virtual';export{useVirtualizer}from'@tanstack/react-virtual';function ho(){let[e,t]=useState(false),{theme:n,setTheme:o}=b$b();return useEffect(()=>{t(true);},[]),e?jsxs(c$8,{size:"sm",type:"single",value:n,children:[jsx(d$3,{"aria-label":"Set dark mode",onClick:()=>{o("dark");},value:"dark",children:jsx(Moon,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set light mode",onClick:()=>{o("light");},value:"light",children:jsx(Sun,{className:"fk:h-4 fk:w-4"})}),jsx(d$3,{"aria-label":"Set system mode",onClick:()=>{o("system");},value:"system",children:jsx(Monitor,{className:"fk:h-4 fk:w-4"})})]}):null}function yo(){let{resolvedTheme:e}=b$b();return jsx("div",{className:"fk:flex fk:w-full fk:h-full fk:justify-center fk:items-center fk:bg-background",children:jsxs("div",{className:"fk:flex fk:flex-col fk:items-center",children:[e==="dark"?jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"#020817"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"white"})]}):jsxs("svg",{className:"fk:h-8 fk:w-8 fk:animate-bounce",fill:"none",viewBox:"0 0 48 48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"white"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"#020817"})]}),jsx("div",{className:"fk:text-foreground fk:text-center fk:mt-4 fk:animate-pulse",children:"Loading..."})]})})}var oc=cva("fk:relative fk:w-full fk:rounded-lg fk:border fk:px-4 fk:py-3 fk:[&>svg~*]:pl-7 fk:[&>svg+div]:translate-y-[-3px] fk:[&>svg]:absolute fk:[&>svg]:left-4 fk:[&>svg]:top-4 fk:[&>svg]:text-foreground",{variants:{variant:{default:"fk:bg-card fk:text-card-foreground",destructive:"fk:border-none fk:text-destructive fk:bg-destructive-foreground fk:[&>svg]:text-destructive"}},defaultVariants:{variant:"default"}});function ye({className:e,variant:t,...n}){return jsx("div",{"data-slot":"alert",role:"alert",className:a$1(oc({variant:t}),e),...n})}function qe({className:e,...t}){return jsx("div",{"data-slot":"alert-title",className:a$1("fk:col-start-2 fk:line-clamp-1 fk:min-h-4 fk:font-medium fk:tracking-tight",e),...t})}function ve({className:e,...t}){return jsx("div",{"data-slot":"alert-description",className:a$1("fk:text-sm fk:[&_p]:leading-relaxed",e),...t})}var fc=vo.object({email:vo.email({error:"Please enter a valid email address"})});function fr({projectId:e$1,setIsEmailLogin:t}){let[n,o]=useState(false),[r,i]=useState(false),{mutate:s}=useSWRConfig(),a=useForm({resolver:zodResolver(fc),defaultValues:{email:""}}),c$1=new URL(c$6(e$1).loginOtpSend,a$l),{data:l,error:u,isLoading:f}=ic(r?c$1.href:null,h=>fetch(h,{method:"POST",mode:"cors",body:JSON.stringify({email:a.getValues("email")})}).then(v=>v.json()),{revalidateIfStale:false,revalidateOnFocus:false,revalidateOnReconnect:false,shouldRetryOnError:false}),m=l&&"error"in l&&l.error.code,p=l&&"token"in l,d=l&&"token"in l?l.token:"";useEffect(()=>{if(!p)return;let h=0,v=setInterval(()=>{if(h>100){clearInterval(v),o(true);return}let y=new URL(c$6(e$1).loginOtpConfirm,a$l),b="/api/flexkit/set-token";fetch(`${y.href}?email=${encodeURIComponent(a.getValues("email"))}&token=${encodeURIComponent(d)}`).then(E=>{E.status===200&&E.json().then(A=>{fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sid:A.sid})}).then(()=>{window.location.reload();}).catch(()=>{});}).catch(()=>{});}).catch(()=>{}),h++;},3e3);return ()=>{clearInterval(v);}},[a,p,e$1,d]);function g$1(){o(false),i(true),s(c$1.href);}return jsx("div",{className:"fk:w-full",children:p?jsx(ye,{className:"fk:dark:bg-foreground fk:dark:text-background",variant:"default",children:jsxs(ve,{children:["Keep this window open and in a new tab open the link we just sent to:"," ",jsx("strong",{children:a.getValues("email")})," (",jsx(b$3,{className:"fk:p-0 fk:hover:underline fk:text-link",onClick:()=>{window.location.reload();},variant:"link",children:"undo"}),")"]})}):jsx(b$1,{...a,children:jsxs("form",{onSubmit:h=>{a.handleSubmit(g$1)(h);},className:"fk:w-full fk:space-y-3 fk:mb-10",children:[m==="not_exists"&&jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["There is no Flexkit account associated with this email address."," ",jsx("a",{className:"fk:text-black/90 fk:dark:text-white/90 fk:underline",href:`https://flexkit.io/signup/email?email=${encodeURIComponent(a.getValues("email"))}`,children:"Sign up?"})]})}),m==="unknown_error"||u?jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["There was an unknown error, please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."," "]})}):null,n?jsx(ye,{variant:"destructive",children:jsxs(ve,{children:["The email verification link may have expired. Please"," ",jsx(b$3,{className:"fk:p-0 fk:hover:underline",onClick:()=>{window.location.reload();},variant:"link",children:"try again"}),"."]})}):null,jsx(c,{control:a.control,defaultValue:"",name:"email",render:({field:h})=>jsxs(e,{children:[jsx(g,{children:jsx(a$7,{"aria-label":"Email Address",autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",className:"w-full",placeholder:"Email Address",spellCheck:false,type:"email",...h})}),jsx(i$1,{})]})}),jsxs(b$3,{"aria-disabled":f,className:"fk:w-full",type:"submit",disabled:!!f,children:[f?jsx(Loader2,{className:"fk:h-5 fk:w-5 fk:mr-2 fk:animate-spin"}):jsx(Mail,{className:"fk:w-5 fk:h-5 fk:mr-2"}),"Continue with Email"]}),jsx(b$3,{className:"fk:w-full fk:text-link",onClick:()=>{t(false);},variant:"link",children:"\u2190 Other Login options"})]})})})}function ps({projectId:e}){let{projects:t}=d(),[n,o]=useState(t.find(g=>g.projectId===e)??t[0]),[r,i]=useState(false),{data:s,error:a,isLoading:c}=ic(c$6(e).authProviders,g=>fetch(g,{mode:"cors"}).then(h=>h.json())),[l,u]=b(),f=new Date().getFullYear(),m=useLocation(),p=m.state?.from?.pathname??m.pathname,d$2=p.includes(n.projectId)?`${location.origin}${p}`:`${location.origin}${b$a(n.basePath,n.projectId)}`;if(a)throw new Error("Error fetching auth providers");return c||l||!s?jsx(yo,{}):u.user?.id?jsx(Navigate,{replace:true,state:{from:m},to:n.basePath}):jsxs(Fragment,{children:[jsxs("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:[jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsxs("div",{className:"fk:mx-auto fk:flex fk:flex-col fk:justify-center fk:sm:w-[350px]",children:[jsx("h1",{className:"fk:mb-4 fk:text-2xl fk:text-center fk:font-medium fk:tracking-tight",children:"Login to Flexkit Studio"}),t.length>1?jsxs("div",{className:"fk:flex-col fk:space-y-2 fk:mb-3",children:[jsx(a$k,{className:"fk:text-sm fk:font-normal fk:text-left fk:text-muted-foreground",htmlFor:"project",children:"Select project"}),jsxs(a$5,{defaultValue:n.projectId,onValueChange:g=>{o(t.find(h=>h.projectId===g)??t[0]);},children:[jsx(d$1,{className:"fk:mb-4 fk:w-full fk:h-9 fk:py-1",id:"project",children:jsx(c$1,{"aria-label":n.title,children:n.title})}),jsx(e$1,{children:t.map(g=>jsx(g$1,{value:g.projectId,children:g.title},g.projectId))})]})]}):null,r?jsx(fr,{projectId:e,setIsEmailLogin:i}):jsxs(Fragment,{children:[jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-sm fk:text-left fk:text-muted-foreground",children:"Choose login provider"}),jsxs("div",{className:"fk:flex fk:flex-col fk:space-y-6",children:[s.providers.map(g=>jsx(b$3,{asChild:true,className:`fk:${g.button.color} fk:${g.button.backgroundColor} fk:hover:${g.button.colorHover} fk:hover:${g.button.backgroundColorHover}`,type:"button",variant:g.button.variant,children:jsxs("a",{href:gc({url:g.url,projectId:n.projectId,basePath:"/api/flexkit/get-token",fromPath:d$2}),children:[g.button.iconUrl?jsx("img",{alt:g.title,className:"fk:w-[20px] fk:h-[20px] fk:mr-2",src:g.button.iconUrl}):null,g.title]})},g.name)),jsx(b$3,{className:"fk:mt-4! fk:text-sm fk:text-center fk:text-link",onClick:()=>{i(true);},variant:"link",children:"Continue with Email \u2192"})]})]}),jsxs("div",{className:"fk:flex fk:flex-col fk:items-center fk:pt-8",children:[jsxs("svg",{className:"fk:w-28",fill:"none",viewBox:"0 0 191 42",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M59.2923 38.5263H52.7518V19.433H49.5653V12.9332H52.7518V11.7145C52.7518 10.1373 53.0471 8.65569 53.638 7.26967C54.245 5.88368 55.0677 4.68089 56.1058 3.66131C57.16 2.62579 58.3817 1.81331 59.7713 1.22386C61.1609 0.618477 62.6464 0.315788 64.2276 0.315788H69.1388V6.81564H64.2276C63.5247 6.81564 62.8698 6.9431 62.2628 7.19798C61.6719 7.43696 61.1528 7.77948 60.7057 8.22554C60.2746 8.65569 59.9311 9.17344 59.6756 9.77882C59.4201 10.3683 59.2923 11.0135 59.2923 11.7145V12.9332H67.3182V19.433H59.2923V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M78.6099 38.5263H71.9802V0.315788H78.6099V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M93.8922 32.3923C94.146 32.4723 94.3998 32.5283 94.6536 32.5604C94.9074 32.5765 95.1615 32.5842 95.4153 32.5842C96.0497 32.5842 96.6606 32.4964 97.2476 32.3203C97.8346 32.1445 98.3817 31.8966 98.8896 31.5768C99.4131 31.2409 99.8732 30.841 100.27 30.3772C100.682 29.8973 101.015 29.3695 101.269 28.7937L106.029 33.616C105.426 34.4797 104.728 35.2553 103.934 35.9432C103.157 36.6308 102.308 37.2145 101.388 37.6944C100.484 38.1743 99.5241 38.534 98.5089 38.7741C97.5094 39.03 96.4782 39.1579 95.4153 39.1579C93.6225 39.1579 91.933 38.822 90.3465 38.1502C88.7759 37.4784 87.3957 36.5427 86.2058 35.3434C85.0319 34.1438 84.1038 32.7202 83.4218 31.0729C82.7395 29.4095 82.3983 27.5862 82.3983 25.6029C82.3983 23.5717 82.7395 21.7164 83.4218 20.037C84.1038 18.3576 85.0319 16.9262 86.2058 15.7426C87.3957 14.5591 88.7759 13.6394 90.3465 12.9836C91.933 12.3279 93.6225 12 95.4153 12C96.4782 12 97.5173 12.128 98.5325 12.3839C99.548 12.6398 100.508 13.0076 101.412 13.4875C102.332 13.9673 103.189 14.5591 103.982 15.2628C104.775 15.9505 105.473 16.7263 106.076 17.5899L93.8922 32.3923ZM97.2237 18.8854C96.9224 18.7735 96.6208 18.7015 96.3195 18.6695C96.0338 18.6375 95.7325 18.6215 95.4153 18.6215C94.5267 18.6215 93.6859 18.7895 92.8927 19.1253C92.1154 19.4452 91.4334 19.9091 90.8461 20.5168C90.2751 21.1246 89.823 21.8603 89.4898 22.724C89.1566 23.5717 88.9902 24.5313 88.9902 25.6029C88.9902 25.8428 88.9981 26.1147 89.0138 26.4186C89.0457 26.7225 89.0852 27.0344 89.133 27.3543C89.1965 27.6582 89.2679 27.9541 89.347 28.2419C89.4263 28.5298 89.5296 28.7858 89.6565 29.0097L97.2237 18.8854Z",fill:"currentColor"}),jsx("path",{d:"M132.911 38.5263H124.926L119.833 30.6401L114.693 38.5263H106.707L116.055 25.3265L106.707 12.6316H114.693L119.833 20.0129L124.926 12.6316H132.911L123.539 25.3265L132.911 38.5263Z",fill:"currentColor"}),jsx("path",{d:"M143.002 38.5263H136.383V0.315788H143.002V24.0898L151.557 12.9976H159.114L150.57 23.6485L159.114 38.5263H151.557L146.335 29.2367L143.002 34.0243V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M169.848 5.93416C169.848 6.54038 169.727 7.10672 169.486 7.63317C169.262 8.15962 168.949 8.62224 168.547 9.02108C168.146 9.40396 167.672 9.71505 167.126 9.95433C166.596 10.1777 166.026 10.2893 165.416 10.2893C164.806 10.2893 164.228 10.1777 163.682 9.95433C163.152 9.71505 162.686 9.40396 162.285 9.02108C161.9 8.62224 161.586 8.15962 161.346 7.63317C161.121 7.10672 161.008 6.54038 161.008 5.93416C161.008 5.34388 161.121 4.78553 161.346 4.25908C161.586 3.71666 161.9 3.25403 162.285 2.87115C162.686 2.47232 163.152 2.16124 163.682 1.93789C164.228 1.6986 164.806 1.57895 165.416 1.57895C166.026 1.57895 166.596 1.6986 167.126 1.93789C167.672 2.16124 168.146 2.47232 168.547 2.87115C168.949 3.25403 169.262 3.71666 169.486 4.25908C169.727 4.78553 169.848 5.34388 169.848 5.93416ZM168.716 38.5263H162.092V12.8977H168.716V38.5263Z",fill:"currentColor"}),jsx("path",{d:"M186.938 38.5263C185.368 38.5263 183.892 38.2319 182.512 37.6429C181.131 37.0378 179.918 36.2178 178.871 35.183C177.839 34.1323 177.022 32.9145 176.419 31.5294C175.832 30.1442 175.539 28.6635 175.539 27.0874V19.4932H172.374V12.9976H175.539V0.315788H182.012V12.9976H189.106V19.4932H182.012V27.0874C182.012 27.772 182.139 28.4168 182.393 29.0218C182.646 29.6108 182.996 30.1282 183.44 30.574C183.884 31.0198 184.408 31.378 185.01 31.6487C185.613 31.9034 186.256 32.0308 186.938 32.0308H189.106V38.5263H186.938Z",fill:"currentColor"}),jsx("path",{d:"M19.8893 2.21053C34.8062 2.21053 39.7785 7.18421 39.7785 22.1053C39.7785 37.0263 34.8062 42 19.8893 42C4.97231 42 0 37.0263 0 22.1053C0 7.18421 4.97231 2.21053 19.8893 2.21053ZM14.7093 10.1053H7.26116L15.9804 21.9654L7.26116 34.2973H14.7093L17.4445 30.1161V14.0271L14.7093 10.1053ZM32.285 10.1053H24.8237L21.7835 14.4979V29.5995L24.8237 34.2973H32.285L23.528 21.9654L32.285 10.1053Z",fill:"currentColor"})]}),jsxs("ul",{className:"fk:flex fk:w-full fk:mt-4 fk:justify-center fk:text-xs fk:text-muted-foreground",children:[jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io",children:"flexkit.io"})}),jsx("li",{className:"fk:pr-6 fk:after:content-['|'] fk:after:pl-6",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/docs",children:"Docs"})}),jsx("li",{className:"",children:jsx("a",{className:"fk:underline-offset-4 fk:hover:text-primary",href:"https://www.flexkit.io/privacy-policy",children:"Privacy Policy"})})]})]})]})}),jsx("div",{className:"fk:hidden fk:text-white! fk:bg-bitbucket! fk:hover:bg-bitbucket-hover!"}),jsx("div",{className:"fk:hidden fk:bg-github! fk:hover:bg-github-hover!"}),jsx("div",{className:"fk:hidden fk:text-muted-foreground! fk:bg-white! fk:hover:bg-accent!"})]}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",f]})]}),jsx(ho,{})]})})]})}function gc({projectId:e,url:t,basePath:n,fromPath:o}){let r=new URLSearchParams;return r.set("origin",`${location.origin}${n}`),r.set("projectId",e),r.set("redirect",o),`${t}?${r.toString()}`}var kc=["PROJECT_PAUSED","PROJECT_NOT_FOUND","READ_ONLY_MODE","UNKNOWN_ERROR"],hc={PROJECT_PAUSED:"This project has been paused.",PROJECT_NOT_FOUND:"The requested project ID was not found",READ_ONLY_MODE:"This project is currently in read only mode and changes cannot be saved",UNKNOWN_ERROR:"Sorry, an unexpected error has occurred. Please try again"},bo=class e extends Error{code;constructor(t,n){super(n??hc[t]),this.name="FlexkitError",this.code=t,Object.setPrototypeOf&&Object.setPrototypeOf(this,new.target.prototype);}static from(t,n){return new e(t,n)}};function dr(e){if(!(e instanceof Error))return false;let t=e.code;return typeof t!="string"?false:kc.includes(t)}function gs(e){if(dr(e))return e.code}var yc={developer:true,owner:true};function ks(e){return !!(e&&yc[e])}function hs(e){return `/api/flexkit/${e}/tools/dev-connect/tick`}var mr=2e3,bc=1e4,pr=false;async function Cc(e){try{let t=await fetch(e,{credentials:"same-origin",method:"POST"});if(t.status!==200)return !1;let n=await t.json();return typeof n.job=="string"&&n.job.length>0}catch{return false}}function ys({projectId:e,role:t}){return useEffect(()=>{if(!ks(t)||!e)return;let n=false,o=mr,r,i=hs(e);function s(l){n||document.hidden||(r!==void 0&&window.clearTimeout(r),r=window.setTimeout(()=>{a();},l));}async function a(){if(n||document.hidden)return;if(pr){s(o);return}pr=true;let l=await Cc(i);pr=false,l?o=mr:o=Math.min(o*2,bc),s(o);}function c(){if(document.hidden){r!==void 0&&(window.clearTimeout(r),r=void 0);return}o=mr,a();}return a(),document.addEventListener("visibilitychange",c),()=>{n=true,document.removeEventListener("visibilitychange",c),r!==void 0&&window.clearTimeout(r);}},[e,t]),null}function ws({apps:e,version:t}){let[n,o]=useState(0),[r,i]=useState(e),[s,a]=useState([]),c=useRef(null),l=useLocation(),{projectId:u}=useParams(),f=e.find(p=>l.pathname.includes(`/${u}/${p.name}`))?.name,m$1=e.find(p=>l.pathname.includes(`/${u}/${p.name}`))?.name??e[0]?.name;return useEffect(()=>{if(c.current===null)return;let p=new ResizeObserver(()=>{o(c.current?.offsetHeight??0);});return p.observe(c.current),function(){p.disconnect();}},[f]),useEffect(()=>{let p=Math.floor(n/48)-2,d=e.slice(0,p);if(!d.find(h=>h.name===m$1)){let h=e.find(v=>v.name===m$1);d.pop(),h&&d.push(h);}let g=e.filter(h=>!d.includes(h));i(d),a(g);},[e,m$1,n]),f===void 0&&m$1?jsx(Navigate,{to:`${l.pathname}/${m$1}`}):jsx(a$8,{children:jsxs("div",{className:"fk:flex fk:flex-col fk:h-full fk:w-12 fk:bg-muted",ref:c,children:[jsxs("div",{className:"fk:grow",children:[jsx("div",{className:"fk:grid fk:grid-cols-1 fk:w-12 fk:h-auto",children:r.map(p=>jsx(b$3,{asChild:true,className:"fk:h-12 fk:w-12",variant:"ghost",children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,className:"fk:h-12 fk:p-2 fk:rounded-none fk:border-2 fk:border-transparent! fk:data-[state=active]:border-l-foreground! fk:focus-visible:outline-hidden fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0 fk:focus-visible:border-2! fk:focus-visible:border-ring! fk:focus-visible:rounded-xs",children:jsx(NavLink,{className:"fk:text-muted-foreground fk:aria-[current]:text-foreground fk:aria-[current]:bg-background fk:aria-[current]:border-l-white!",to:p.name,children:p.icon})}),jsx(e$3,{side:"right",children:jsx("p",{children:p.title})})]})},p.name))}),s.length>0&&jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(MoreHorizontal,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"View additional apps"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Additional apps"})})]})})}),jsx(f$2,{align:"start",className:"fk:w-56",side:"right",children:s.map(p=>jsx(h$2,{asChild:true,children:jsx(NavLink,{to:p.name,children:p.title})},p.name))})]})]}),jsxs(c$3,{children:[jsx(b$5,{children:jsx(e$2,{asChild:true,children:jsxs(c$4,{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:w-12 fk:p-0 fk:data-[state=open]:bg-muted fk:text-muted-foreground fk:transition-colors fk:focus-visible:outline-hidden fk:focus-visible:border-2 fk:focus-visible:border-ring fk:focus-visible:rounded-xs",children:[jsx(Settings,{className:"fk:w-5 fk:h-5",strokeWidth:1.5}),jsx("span",{className:"fk:sr-only",children:"Settings menu"}),jsx(e$3,{side:"right",children:jsx("p",{children:"Settings menu"})})]})})}),jsxs(f$2,{align:"start",className:"fk:w-60",side:"right",children:[jsx(h$2,{asChild:true,children:jsxs(Link$1,{to:`https://flexkit.io/dashboard/*/${u}`,target:"_blank",rel:"noopener noreferrer",children:[jsx(Wrench,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Manage project"})]})}),jsx(m,{}),jsx(h$2,{disabled:t.isCurrent,onSelect:()=>{t.isCurrent;},children:t.isCurrent?jsxs(Fragment,{children:[jsx(PackageCheck,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current]})]}):jsxs(Fragment,{children:[jsx(PackageX,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsxs("span",{children:["Version ",t.current,".",jsx("br",{}),"Upgrade to ",t.latest]})]})})]})]})]})})}var Pc={"navbar.logo":lazy(()=>import('./logo-B6ZKLGM7.js').then(({Logo:e})=>({default:e}))),"navbar.projectSelector":lazy(()=>import('./project-selector-X6YVZYKL.js').then(({ProjectSelector:e})=>({default:e}))),"navbar.search":lazy(()=>import('./search-KIII5N7I.js').then(({Search:e})=>({default:e}))),"navbar.userNav":lazy(()=>import('./user-nav-6UKDSUF3.js').then(({UserNav:e})=>({default:e}))),"formFields.switch":lazy(()=>import('./switch-TACKLQJH.js').then(({Switch:e})=>({default:e}))),"formFields.text":lazy(()=>import('./text-M3DRK7LU.js').then(({Text:e})=>({default:e}))),"formFields.textarea":lazy(()=>import('./textarea-YF4K2VBM.js').then(({Textarea:e})=>({default:e}))),"previewFields.boolean":lazy(()=>import('./boolean-MTD44LXP.js').then(({Boolean:e})=>({default:e}))),"previewFields.asset":lazy(()=>import('./asset-ZVPFS73O.js').then(({Asset:e})=>({default:e}))),"previewFields.text":lazy(()=>import('./text-SQXG7XJT.js').then(({Text:e})=>({default:e}))),"previewFields.editor":lazy(()=>import('./editor-HAYTKNMY.js').then(({Editor:e})=>({default:e}))),"previewFields.datetime":lazy(()=>import('./datetime-DDEWTNLB.js').then(({DateTime:e})=>({default:e}))),"previewFields.select":lazy(()=>import('./select-H3JHOCWR.js').then(({Select:e})=>({default:e})))};function Ln(e){let{getContributionPointConfig:t}=d(),[n,...o]=e.split("."),r=Pc[e],i=t(n,o);return i?.length>0?i[0]?.component:r}function Ss({projectId:e,projects:t}){let{resolvedTheme:n}=b$b(),o=Ln("navbar.logo"),r=Ln("navbar.projectSelector"),i=Ln("navbar.search"),s=Ln("navbar.userNav"),a=t.find(m=>m.projectId===e)??t[0],{basePath:c,schema:l}=a,u=useNavigate();function f(m){startTransition(()=>{u(b$a(c,e,"desk","list",m.entityNamePlural)+`?id=${m.entityId}`);});}return jsxs("div",{className:"fk:flex fk:basis-14 fk:min-h-14 fk:px-3 fk:gap-x-4 fk:border-b fk:border-border fk:z-30",children:[jsx(Suspense,{fallback:null,children:jsx(o,{theme:n,title:"Flexkit Studio"})}),jsxs("div",{className:"fk:flex fk:grow fk:shrink fk:items-center fk:gap-x-4 px-4",children:[jsx(Suspense,{fallback:null,children:jsx(r,{projectId:e,projects:t})}),jsx(Suspense,{fallback:null,children:jsx(i,{onSelect:f,projectId:e,schema:l},e)})]}),jsx("div",{className:"fk:flex fk:items-center",children:jsx(Suspense,{fallback:null,children:jsx(s,{projectId:e})})})]})}function Es({version:e}){let{contributions:t,projects:n}=d(),[o,r]=b(),{projectId:i}=useParams(),s=find(propEq(i??"","projectId"))(n);if(!s)throw new bo("PROJECT_NOT_FOUND");let{scopes:a}=s,{apps:c}=t,l=d$2(),u=useLocation();return useEffect(()=>{if(a){let f=a.find(p=>p.isDefault)||a[0],m="";typeof localStorage<"u"&&(m=localStorage.getItem(`${a$i}${i}`)??""),l({type:"setScope",payload:{projectId:i,scope:m||f.name}});}},[u]),o?jsx(yo,{}):r.user?.id?jsxs(Fragment,{children:[jsxs("div",{className:"fk:flex fk:flex-col fk:h-full flexkit-studio","vaul-drawer-wrapper":"",children:[jsx(Ss,{projectId:i??"",projects:n}),jsxs("div",{className:"fk:flex fk:h-full fk:max-h-[calc(100%-3.5rem)] fk:border-t fk:border-border fk:grow shrink",children:[jsx(ws,{apps:c,version:e}),jsx(Outlet,{})]})]}),jsx(f$3,{}),jsx(ys,{projectId:i??"",role:r.user.role})]}):jsx(ps,{projectId:i??""})}function Ns(e){return e?"cause"in e:false}function Xt(e){if(!e)return null;if(ServerError.is(e))return e;if(Ns(e)){let t=e.cause;if(ServerError.is(t))return t}return null}function Ds(e){if(!e||typeof e!="object")return null;let{message:t}=e;return typeof t=="string"?t:null}function Wt(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function wo(e){if(!e)return null;let t=Rs(e).filter(n=>!qc(n));return t.length===0?null:["The deployed schema is out of sync with your local Flexkit schema.","Run `flexkit deploy` using the CLI to apply your latest schema changes.",...t.map(n=>`- ${n}`)].join(`
|
|
2
|
+
`)}function Fs(e,t){return e?Rs(e).some(n=>n.includes(`Cannot query field "${t}"`)):false}function Rs(e){if(CombinedGraphQLErrors.is(e))return e.errors.filter(Ts).map(({message:r})=>r);let t=Ds(e);if(t&&Mn(t))return [t];let n=Xt(e);if(n?.statusCode!==400)return [];let o=Wt(n.bodyText)??Hc(n)??Uc(e);return o?Array.isArray(o.errors)?o.errors.filter(Ts).map(r=>r.message):typeof o.message=="string"&&Mn(o.message)?[o.message]:typeof o.error=="string"&&Mn(o.error)?[o.error]:[]:[]}function Hc(e){let{result:t}=e;return !t||typeof t!="object"?null:t}function Uc(e){if(!Ns(e))return null;let{cause:t}=e,n=Ds(t);if(n&&Mn(n))return {message:n};if(!t||typeof t!="object")return null;let{result:o}=t;return o&&typeof o=="object"?o:null}function Ts(e){if(!e||typeof e!="object")return false;let{extensions:t,message:n}=e;return t?.code==="GRAPHQL_VALIDATION_FAILED"&&typeof n=="string"?true:typeof n=="string"&&Mn(n)}function Mn(e){return e.startsWith("Cannot query field ")||e.startsWith("Unknown type ")||e.startsWith('Cannot query field "')||e.includes("GRAPHQL_VALIDATION_FAILED")}function qc(e){return /Cannot query field "[_A-Za-z][_0-9A-Za-z]*Total" on type "Query"/.test(e)}var ru=ApolloProvider,Ls=createContext(void 0);function Kt(){let e=useContext(Ls);if(!e)throw new Error("useGraphQLError must be used within GraphQLProvider");return e}function iu(e){return new ErrorLink(({error:t})=>{let n=wo(t);if(n){e(n);return}CombinedGraphQLErrors.is(t)?t.errors.forEach(({message:r,locations:i,path:s})=>{console.warn(`[GraphQL error]: Message: ${r}, Location: ${i}, Path: ${s}`);}):CombinedProtocolErrors.is(t)&&t.errors.forEach(({message:r,extensions:i})=>{console.warn(`[Protocol error]: Message: ${r}, Extensions: ${JSON.stringify(i)}`);});let o=Xt(t);if(o?.statusCode===400){let r=Wt(o.bodyText),i=null;if(r&&typeof r=="object"){let{error:s,errors:a,message:c}=r;if(typeof c=="string")i=c;else if(Array.isArray(a)){let[l]=a;if(l&&typeof l.message=="string"){let{message:u}=l;i=u;}}else typeof s=="string"?i=s:i=JSON.stringify(r);}else i=o.bodyText;e(i??"There is an error in your Flexkit schema (flexkit.config.ts).");}if(o){console.warn(`[Network error]: ${o.message}`);return}t&&console.warn(`[Network error]: ${t.message}`);})}function su(e,t){return from([iu(t),new HttpLink({uri:`/api/flexkit/${e}/graphql`})])}function au(e,t){return new ApolloClient({link:su(e??"",t),cache:new InMemoryCache({dataIdFromObject:n=>n._id?n._id:defaultDataIdFromObject(n)})})}function Ms({children:e}){let{currentProjectId:t}=d(),[n,o]=useState(null),r=useMemo(()=>({schemaErrorMessage:n,setSchemaErrorMessage:o}),[n]),i=useMemo(()=>au(t,o),[t]);return jsx(Ls.Provider,{value:r,children:jsx(ru,{client:i,children:e})})}function _s({...e}){return jsx(AlertDialog.Root,{"data-slot":"alert-dialog",...e})}function hr({...e}){return jsx(AlertDialog.Portal,{"data-slot":"alert-dialog-portal",...e})}function lu({className:e,...t}){return jsx(AlertDialog.Overlay,{"data-slot":"alert-dialog-overlay",className:a$1("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...t})}function $s({className:e,size:t="default",...n}){return jsxs(hr,{children:[jsx(lu,{}),jsx(AlertDialog.Content,{"data-slot":"alert-dialog-content","data-size":t,className:a$1("fk:group/alert-dialog-content fk:fixed fk:top-[50%] fk:left-[50%] fk:z-50 fk:grid fk:w-full fk:max-w-[calc(100%-2rem)] fk:translate-x-[-50%] fk:translate-y-[-50%] fk:gap-4 fk:rounded-lg fk:border fk:bg-background fk:p-6 fk:shadow-lg fk:duration-200 fk:data-[size=sm]:max-w-xs fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95 fk:data-[size=default]:sm:max-w-lg",e),...n})]})}function Os({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-header",className:a$1("fk:grid fk:grid-rows-[auto_1fr] fk:place-items-center fk:gap-1.5 fk:text-center fk:has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] fk:has-data-[slot=alert-dialog-media]:gap-x-6 fk:sm:group-data-[size=default]/alert-dialog-content:place-items-start fk:sm:group-data-[size=default]/alert-dialog-content:text-left fk:sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",e),...t})}function Vs({className:e,...t}){return jsx("div",{"data-slot":"alert-dialog-footer",className:a$1("fk:flex fk:flex-col-reverse fk:gap-2 fk:group-data-[size=sm]/alert-dialog-content:grid fk:group-data-[size=sm]/alert-dialog-content:grid-cols-2 fk:sm:flex-row fk:sm:justify-end",e),...t})}function Bs({className:e,...t}){return jsx(AlertDialog.Title,{"data-slot":"alert-dialog-title",className:a$1("fk:text-lg fk:font-semibold fk:sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",e),...t})}function zs({className:e,...t}){return jsx(AlertDialog.Description,{"data-slot":"alert-dialog-description",className:a$1("fk:text-sm fk:text-muted-foreground",e),...t})}function js({className:e,variant:t="default",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Action,{"data-slot":"alert-dialog-action",className:a$1(e),...o})})}function Hs({className:e,variant:t="outline",size:n="default",...o}){return jsx(b$3,{variant:t,size:n,asChild:true,children:jsx(AlertDialog.Cancel,{"data-slot":"alert-dialog-cancel",className:a$1(e),...o})})}function _n({options:e}){let[t,n]=useState(false),[o,r]=useState(false),[i,s]=useState(false);useEffect(()=>{n(true);},[]);function a(){n(false),i||e.dialogActionCancel?.(),i&&s(false);}async function c(){r(true),s(true),n(false),await new Promise(l=>{globalThis.setTimeout(l,150);});try{let l=e.dialogActionSubmit?.();l&&typeof l.then=="function"&&await l;}finally{r(false);}}return jsx(_s,{onOpenChange:a,open:t,children:jsx(hr,{children:jsxs($s,{className:"sm:max-w-[425px]",children:[jsxs(Os,{children:[jsx(Bs,{children:e.dialogTitle}),jsx(zs,{children:e.dialogMessage})]}),jsxs(Vs,{children:[jsx(Hs,{disabled:o,onClick:a,children:e.dialogCancelTitle}),jsxs(js,{className:a$9({variant:e.isDestructive?"destructive":"default"}),disabled:o,onClick:c,children:[o?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,e.dialogActionLabel]})]})]})})})}var Gs=createContext([]),Qs=createContext(()=>{});function mu(e,t){let n=t.type;switch(t._id||(t._id=Date.now().toString()),n){case "DeleteEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "AddEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditEntity":return uniqBy(props(["type","_id"]),[...e,t]);case "EditRelationship":return uniqBy(props(["type","_id"]),[...e,t]);case "AlertDialog":return uniqBy(props(["type","_id"]),[...e,t]);case "Dismiss":return e.filter(o=>o._id!==t._id);default:throw Error(`Unknown action: ${n}`)}}function Xs({children:e}){let[t,n]=useReducer(mu,[]);return jsx(Gs.Provider,{value:t,children:jsx(Qs.Provider,{value:n,children:e})})}function Ws(){return useContext(Gs)}function pe(){return useContext(Qs)}function xt(){let[e,t]=useState(false),[n,o]=useState(gql`
|
|
3
3
|
mutation updateEntity($any: Any) {
|
|
4
4
|
any
|
|
5
5
|
}
|
|
6
|
-
`),[r,i]=useState({}),[s,{data:a,loading:c,error:l}]=useMutation(n,r),u=Xt(l),{isProjectDisabled:f,isProjectReadOnly:m}=(()=>{if(u?.statusCode===403){let p=Wt(u.bodyText);if(p&&typeof p.code=="string"){if(p.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(p.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(s(),t(false));},[e,s]),[t,o,i,{data:a,loading:c,error:l,isProjectDisabled:f,isProjectReadOnly:m}]}function be(e){return e.dataType==="asset"?"global":e.scope}function Vn(e){if(!e)return {};let t={};for(let[n,o]of Object.entries(e))t[n]=o?.value;return t}function
|
|
6
|
+
`),[r,i]=useState({}),[s,{data:a,loading:c,error:l}]=useMutation(n,r),u=Xt(l),{isProjectDisabled:f,isProjectReadOnly:m}=(()=>{if(u?.statusCode===403){let p=Wt(u.bodyText);if(p&&typeof p.code=="string"){if(p.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(p.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();return useEffect(()=>{e&&(s(),t(false));},[e,s]),[t,o,i,{data:a,loading:c,error:l,isProjectDisabled:f,isProjectReadOnly:m}]}function be(e){return e.dataType==="asset"?"global":e.scope}function Vn(e){if(!e)return {};let t={};for(let[n,o]of Object.entries(e))t[n]=o?.value;return t}function St(e,t){return typeof e=="function"?!!e(t):e===true}function br(e){return e===true}var So=25,yu=3,Ys=3,vu=["id","string"],bu=["date","datetime","duration","time"],wr=`_id
|
|
7
7
|
originalFilename
|
|
8
8
|
mimeType
|
|
9
9
|
path
|
|
@@ -11,7 +11,7 @@ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}
|
|
|
11
11
|
size
|
|
12
12
|
height
|
|
13
13
|
width
|
|
14
|
-
lqip`,
|
|
14
|
+
lqip`,xr=`_id
|
|
15
15
|
originalFilename
|
|
16
16
|
mimeType
|
|
17
17
|
path
|
|
@@ -20,7 +20,7 @@ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}
|
|
|
20
20
|
height
|
|
21
21
|
width`,Cu=`_id
|
|
22
22
|
path
|
|
23
|
-
url`;function Bn(e){return e?be(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function
|
|
23
|
+
url`;function Bn(e){return e?be(e)==="relationship"&&e.relationship?.mode==="multiple"&&e.relationship.entity==="_asset":false}function Sr(e,t){return !e||!Bn(e)?false:t?.name!==b$8.name||e.name!=="assets"}function Eo(e){return e?.dataType==="asset"||e?.inputType==="asset"}function Ao(e){let t=e,n=t?.edges??[],o=t?.aggregate?.count?.nodes??n.length;return n.reduce((r,i,s)=>(i.node&&r.push({...i.node,sortOrder:i.properties?.sortOrder??s,totalCount:o}),r),[]).sort((r,i)=>(r.sortOrder??Number.MAX_SAFE_INTEGER)-(i.sortOrder??Number.MAX_SAFE_INTEGER))}function zn(e){return e.reduce((t,n,o)=>n._id?{...t,[n._id]:n.sortOrder??o}:t,{})}function Et(e){return Array.isArray(e)?e[0]??null:e??null}function wu(e,t){return t?Cu:e?wr:xr}function ea(e,t=true,n=true,o=So,r=false){let i=t?` properties {
|
|
24
24
|
sortOrder
|
|
25
25
|
}
|
|
26
26
|
`:"",s=wu(n,r),a=t?`(first: ${o}, sort: [{ edge: { sortOrder: ASC } }])`:`(first: ${o})`;return ` ${e}Connection${a} {
|
|
@@ -42,8 +42,8 @@ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
`}function
|
|
46
|
-
`:Er(e,"(where: $where)"):""}function
|
|
45
|
+
`}function xu(e,t,n){return t?n==="total"?` ${e}Total
|
|
46
|
+
`:Er(e,"(where: $where)"):""}function Su(e,t,n,o=false){if(!e)return "";let r=t==="default"?"":`${t}
|
|
47
47
|
`;if(Eo(e))return o?` ${e.name} {
|
|
48
48
|
_id
|
|
49
49
|
path
|
|
@@ -69,7 +69,7 @@ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}
|
|
|
69
69
|
`}function Eu(e,t,n){return e?.attributes.reduce((o,r)=>{let i=t==="default"?"":`${t}
|
|
70
70
|
`;if(Eo(r))return `${o}
|
|
71
71
|
${r.name} {
|
|
72
|
-
${
|
|
72
|
+
${xr}
|
|
73
73
|
}
|
|
74
74
|
`;if(be(r)==="local")return `${o}
|
|
75
75
|
${r.name} {
|
|
@@ -89,13 +89,13 @@ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}
|
|
|
89
89
|
${r.relationship.field} ${c}}
|
|
90
90
|
`}return `${o}
|
|
91
91
|
${r.name}
|
|
92
|
-
`},"")??""}function Au(e){let t={};for(let n of e)t[n.name]=n;return t}function Ks(e){return e?e.name==="url"?true:!(br(e.hidden)||e.name==="lqip"):false}function Tu(e,t){if(!Array.isArray(e)||e.length===0)return;let[n]=e;if(!n||typeof n!="object")return;let[o]=Object.keys(n);if(!o||["_id","_createdAt","_updatedAt"].includes(o))return;let r=t?.attributes.find(i=>i.name===o);if(!(!r||be(r)!=="global"||r.dataType==="asset"))return {NOT:{[o]:{eq:null}}}}function jn(e,t,n,o){let r=o?.selection??"full",i=o?.includeCount??true,s=o?.countMode??"aggregate",a="(where: $where, limit: $limit, offset: $offset, sort: $sort)",c=rt(n,e),l=c?.name??e,u=c?.attributes??[],f=Au(u),m=`$where: ${l}Where, $limit: Int, $offset: Int, $sort: [${l}Sort!]`,p=o?.operationName??`Get${ot(e)}`;if(!c)throw new Error(`Entity '${l}' not found in the schema`);if(u.length===0)throw new Error(`Entity '${l}' has no attributes defined in the schema`);let d=Te("global",u).filter(
|
|
93
|
-
`),g=Hn(u),h=Te(["local"],u).filter(
|
|
92
|
+
`},"")??""}function Au(e){let t={};for(let n of e)t[n.name]=n;return t}function Ks(e){return e?e.name==="url"?true:!(br(e.hidden)||e.name==="lqip"):false}function Tu(e,t){if(!Array.isArray(e)||e.length===0)return;let[n]=e;if(!n||typeof n!="object")return;let[o]=Object.keys(n);if(!o||["_id","_createdAt","_updatedAt"].includes(o))return;let r=t?.attributes.find(i=>i.name===o);if(!(!r||be(r)!=="global"||r.dataType==="asset"))return {NOT:{[o]:{eq:null}}}}function jn(e,t,n,o){let r=o?.selection??"full",i=o?.includeCount??true,s=o?.countMode??"aggregate",a="(where: $where, limit: $limit, offset: $offset, sort: $sort)",c=rt(n,e),l=c?.name??e,u=c?.attributes??[],f=Au(u),m=`$where: ${l}Where, $limit: Int, $offset: Int, $sort: [${l}Sort!]`,p=o?.operationName??`Get${ot(e)}`;if(!c)throw new Error(`Entity '${l}' not found in the schema`);if(u.length===0)throw new Error(`Entity '${l}' has no attributes defined in the schema`);let d=Te("global",u).filter(S=>S==="_updatedAt"?false:r==="list"?Ks(f[S]):true).join(`
|
|
93
|
+
`),g=Hn(u),h=Te(["local"],u).filter(S=>r!=="list"?true:Ks(f[S])),v=h.reduce((S,D)=>`${S}
|
|
94
94
|
${D} {
|
|
95
95
|
_id
|
|
96
96
|
default
|
|
97
97
|
}
|
|
98
|
-
`,""),y=h.reduce((
|
|
98
|
+
`,""),y=h.reduce((S,D)=>`${S}
|
|
99
99
|
${D} {
|
|
100
100
|
_id
|
|
101
101
|
default
|
|
@@ -111,24 +111,24 @@ import'./index.css';import {a as a$3}from'./chunk-N2T6MKPV.js';import {a as a$2}
|
|
|
111
111
|
size
|
|
112
112
|
height
|
|
113
113
|
width
|
|
114
|
-
lqip`);let A=g.reduce((
|
|
114
|
+
lqip`);let A=g.reduce((S,D)=>`${S}
|
|
115
115
|
${D} {
|
|
116
116
|
${E}
|
|
117
117
|
}
|
|
118
|
-
`,""),N=u.filter(
|
|
119
|
-
${ea(D.name,
|
|
118
|
+
`,""),N=u.filter(S=>be(S)==="relationship").reduce((S,D)=>{if(r==="list"&&br(D.hidden))return S;if(Bn(D))return `${S}
|
|
119
|
+
${ea(D.name,Sr(D,c),r!=="list",r==="list"?yu:So,r==="list")}`;let $=find(propEq(D.relationship?.entity,"name"))(n);if(r==="list"){let V=e$4($),R=Su(V,t,n,true),B=D.relationship?.mode==="single"?1:3;return `${S}
|
|
120
120
|
${D.name} (limit: ${B}, offset: 0) {
|
|
121
121
|
_id
|
|
122
122
|
${R} }
|
|
123
|
-
`}let O=Eu($,t,n);return `${Er(D.name).trim()}${
|
|
123
|
+
`}let O=Eu($,t,n);return `${Er(D.name).trim()}${S}
|
|
124
124
|
${D.name} (limit: 25, offset: 0) { _id ${O}}
|
|
125
125
|
`},"");return {queryEntityName:e,query:`query ${p}(${m}) {
|
|
126
|
-
`+
|
|
126
|
+
`+xu(e,i,s)+` ${e}${a} {
|
|
127
127
|
_id
|
|
128
128
|
_updatedAt
|
|
129
129
|
${d} ${b} ${A} ${N}}
|
|
130
130
|
}
|
|
131
|
-
`}}function To(e,t,n,o){let i=rt(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=na(n,e),a=n[e],c=(u,f)=>{let m=f.name;return u.slice(0,3).map(p=>{if(be(f)!=="local")return p[m];let d=Et(p[m]);return d?.[t]??d?.default}).join(", ")},l=a.map(u=>{let{_id:f}=u,m=typeof u._updatedAt=="string"?u._updatedAt:"",p=Te("global",i).filter(v=>v!=="_updatedAt").reduce((v,y)=>({...v,[y]:u[y]}),{}),d=Te("local",i).reduce((v,y)=>{let b=Et(u[y]);return {...v,[y]:b?.[t]?b[t]:b?.default}},{}),g=Hn(i).reduce((v,y)=>({...v,[y]:Et(u[y])}),{}),h=Te(["relationship"],i).reduce((v,y)=>{let b=find(propEq(y,"name"))(i),E=b.relationship?.entity??"",A=find(propEq(E,"name"))(o),F=e$4(A),N=u[y];if(Bn(b)){let V=Ao(u[`${y}Connection`]);return {...v,[y]:V}}if(!F)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);let
|
|
131
|
+
`}}function To(e,t,n,o){let i=rt(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=na(n,e),a=n[e],c=(u,f)=>{let m=f.name;return u.slice(0,3).map(p=>{if(be(f)!=="local")return p[m];let d=Et(p[m]);return d?.[t]??d?.default}).join(", ")},l=a.map(u=>{let{_id:f}=u,m=typeof u._updatedAt=="string"?u._updatedAt:"",p=Te("global",i).filter(v=>v!=="_updatedAt").reduce((v,y)=>({...v,[y]:u[y]}),{}),d=Te("local",i).reduce((v,y)=>{let b=Et(u[y]);return {...v,[y]:b?.[t]?b[t]:b?.default}},{}),g=Hn(i).reduce((v,y)=>({...v,[y]:Et(u[y])}),{}),h=Te(["relationship"],i).reduce((v,y)=>{let b=find(propEq(y,"name"))(i),E=b.relationship?.entity??"",A=find(propEq(E,"name"))(o),F=e$4(A),N=u[y];if(Bn(b)){let V=Ao(u[`${y}Connection`]);return {...v,[y]:V}}if(!F)throw new Error(`There is an error in the schema for the relationship attribute "${y}"`);let S=F.name,D=be(F);if(b.relationship?.mode==="multiple"){let V=Array.isArray(N)?N:[];return {...v,[y]:c(V,F)}}let $=Et(N);if(D==="global")return {...v,[y]:$?.[S]};let O=Et($?.[S]);return {...v,[y]:O?.[t]??O?.default}},{});return {_id:f,...p,...d,...g,...h,_updatedAt:m}});return {count:s,results:l}}function oa(e,t,n,o){let i=rt(o,e)?.attributes??[];if(i.length===0)return {count:0,results:[]};let s=na(n,e),c=n[e].map(l=>{let u=Te("global",i).reduce((d,g)=>({...d,[g]:{value:l[g],disabled:false,scope:"default",_id:""}}),{}),f=Te("local",i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),v=Et(l[g]);return {...d,[g]:{value:v?Nu(v,t):null,disabled:!!(v&&v[t]===null&&be(h)==="local"&&t!=="default"),scope:t,_id:v?v._id:null}}},{}),m=Hn(i).reduce((d,g)=>({...d,[g]:{value:Et(l[g]),disabled:false,scope:"default",_id:""}}),{}),p=Te(["relationship"],i).reduce((d,g)=>{let h=find(propEq(g,"name"))(i),v=l[g],y=h.relationship?.mode==="single"?Et(v):v,b=y?._id,E=ta(l[`${g}Connection`]);if(Bn(h)){let A=Ao(l[`${g}Connection`]);return {...d,[g]:{count:E,_id:b,knownAssetSortOrders:zn(A),value:A,disabled:false,scope:t}}}return {...d,[g]:{count:E,_id:b,value:y,disabled:false,scope:t}}},{});return {...u,...f,...m,...p}});return {count:s,results:c}}function Nu(e,t){return Array.isArray(e)?e.reduce((n,o)=>{if(o[t]??o.default){let r={_id:o._id,disabled:o.scope===null&&t!=="default",scope:t,value:o[t]??o.default};n.push(r);}return n},[]):e[t]??e.default??null}function Ar(e,t,n,o,r,i,s){let a=rt(o,e),c=a?.name??e,l=a?.attributes??[],u=Jn(e);if(l.length===0)return "";let f=ra(l,i,s?.currentUser),m=ia(l,f),p=Ru(t,l,f,n),d=Du(l,r,f),g=Pu(l,r,f),h=e,v=s?.responseFields??aa(o,e,n);return `mutation ${`Update${ot(e)}`}($where: ${c}Where) {
|
|
132
132
|
update${u}(
|
|
133
133
|
where: $where
|
|
134
134
|
update: {${m}${p}${d}${g}
|
|
@@ -139,7 +139,7 @@ ${R} }
|
|
|
139
139
|
${v} }
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
`}function ra(e,t,n){let o=Vn(t),r=e.map(s=>
|
|
142
|
+
`}function ra(e,t,n){let o=Vn(t),r=e.map(s=>St(s.readOnly,{record:o,value:o[s.name],currentUser:n})?s.name:"").filter(Boolean),i=omit(r,t);return pick(e.map(s=>s.name),i)}function Te(e,t){return Array.isArray(e)?e.reduce((o,r)=>o.concat(Te(r,t)),[]):t.filter(o=>be(o)===e&&o.inputType!=="asset").map(o=>o.name)}function Hn(e){return e.filter(Eo).map(n=>n.name)}function ia(e,t,n="update"){let o=pick(Te("global",e),t);return toPairs(o).reduce((i,[s,a])=>{let c=find(propEq(s,"name"))(e),l=Array.isArray(a?.value)?null:a?.value??null,u=Tr(c.dataType,l);return n==="create"&&(u===null||u==="")?i:n==="update"?`${i}
|
|
143
143
|
${s}: { set: ${u} }`:`${i}
|
|
144
144
|
${s}: ${u}`},"")}function Cr(e){return !e?._id||!e.path?"":e._id}function Du(e,t,n){let o=pick(Hn(e),n);return toPairs(o).reduce((s,[a,c])=>{let l=Cr(c.value),u=Cr(t[a]?.value);if(l===u)return s;let f=u?` {
|
|
145
145
|
disconnect: [{
|
|
@@ -257,7 +257,7 @@ ${sa(e)} ]
|
|
|
257
257
|
_id
|
|
258
258
|
${n}
|
|
259
259
|
}
|
|
260
|
-
`,""),c+=a.reduce((l,u)=>{let f=find(propEq(u,"name"))(r),m=f?.relationship?.mode??"single";if(Bn(f))return `${l}${ea(u,
|
|
260
|
+
`,""),c+=a.reduce((l,u)=>{let f=find(propEq(u,"name"))(r),m=f?.relationship?.mode??"single";if(Bn(f))return `${l}${ea(u,Sr(f,o))}`;let p=f?.relationship?.entity??"",g=find(propEq(p,"name"))(e)?.attributes??[],h=f?.relationship?.field??"[invalid_relationship_field_name_in_schema]",v=find(propEq(h,"name"))(g),y=be(v),b="";if(m==="single"&&(y==="global"&&(b=` ${u} {
|
|
261
261
|
_id
|
|
262
262
|
${h}
|
|
263
263
|
}
|
|
@@ -275,7 +275,7 @@ ${sa(e)} ]
|
|
|
275
275
|
${n}
|
|
276
276
|
}
|
|
277
277
|
`;if(be(F)==="relationship"){let N=n==="default"?"":`${n}
|
|
278
|
-
`,
|
|
278
|
+
`,S=find(propEq(F.relationship?.entity,"name"))(e),D=find(propEq(F.relationship?.field,"name"))(S?.attributes??[]),$=be(D)==="local"?`{
|
|
279
279
|
_id
|
|
280
280
|
default
|
|
281
281
|
${N}}
|
|
@@ -284,7 +284,7 @@ ${sa(e)} ]
|
|
|
284
284
|
`;if(F.relationship?.field)return `${A} ${F.name} (limit: ${Ys}, offset: 0) {
|
|
285
285
|
${F.relationship.field} ${$}}
|
|
286
286
|
`}return Eo(F)?`${A} ${F.name} {
|
|
287
|
-
${
|
|
287
|
+
${xr}
|
|
288
288
|
}
|
|
289
289
|
`:`${A} ${F.name}
|
|
290
290
|
`},"");b=Er(u)+` ${u} (limit: 25, offset: 0) {
|
|
@@ -360,7 +360,7 @@ ${h} ]
|
|
|
360
360
|
`:"";return `${i}
|
|
361
361
|
${s}: {
|
|
362
362
|
${g} }`}return `${i}
|
|
363
|
-
`},"")}function la({relatedEntityName:e,scope:t,schema:n}){let r=find(propEq(e,"name"))(n)?.plural??"";return r?jn(r,t,n,{selection:"list",operationName:`GetRelated${ot(r)}`}):{queryEntityName:"",query:""}}function ca({attributeName:e,entityName:t,entityNamePlural:n,schema:o}){let r=rt(o,n),i=find(propEq(e,"name"))(r?.attributes??[]),s=
|
|
363
|
+
`},"")}function la({relatedEntityName:e,scope:t,schema:n}){let r=find(propEq(e,"name"))(n)?.plural??"";return r?jn(r,t,n,{selection:"list",operationName:`GetRelated${ot(r)}`}):{queryEntityName:"",query:""}}function ca({attributeName:e,entityName:t,entityNamePlural:n,schema:o}){let r=rt(o,n),i=find(propEq(e,"name"))(r?.attributes??[]),s=Sr(i,r),a=s?` properties {
|
|
364
364
|
sortOrder
|
|
365
365
|
}
|
|
366
366
|
`:"",c=s?"(first: $first, sort: [{ edge: { sortOrder: ASC } }])":"(first: $first)",l=`Get${ot(t)}AssetConnection`;return {queryEntityName:n,query:`query ${l}($where: ${t}Where, $first: Int) {
|
|
@@ -379,22 +379,22 @@ ${h} ]
|
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
`}}var Jn=e=>e.charAt(0).toUpperCase()+e.slice(1);function ot(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(Jn).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function rt(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}function ua(e,t,n){if(!e||typeof e!="object")return {};let o=rt(n,t);if(!o)return {};let r=`update${Jn(t)}`,i=e[r];if(!i||typeof i!="object")return {};let s=i[t],a=Array.isArray(s)?s[0]:void 0;return !a||typeof a!="object"?{}:o.attributes.reduce((c,l)=>{if(be(l)!=="local")return c;let f=Et(a[l.name])?._id;return typeof f!="string"||f.length===0?c:{...c,[l.name]:f}},{})}var No=null,Dr=new Set,fa=[],Fr=new Set,Rr=new Set,Pr=new Set;function Ke(e,t){if(e==="_asset"||e==="_assets")return `Get${ot(a$f.plural)}`;let n=t.find(i=>i.plural===e),o=t.find(i=>i.name===e),r=n?.plural??o?.plural??e;return `Get${ot(r)}`}function da(e){return Fr.add(e),()=>{Fr.delete(e);}}function ma(e){return Rr.add(e),()=>{Rr.delete(e);}}function pa(e){return Pr.add(e),()=>{Pr.delete(e);}}function Do(e,t,n){let o=new Set(n.filter(Boolean));if(o.size>0)for(let r of Rr)r(t,o);return At(e,t)}function ga(e,t){let n=t.filter(o=>!!o._id);if(n.length!==0)for(let o of Pr)o(e,n);}function At(e,t){return Dr.add(t),new Promise((n,o)=>{fa.push({resolve:n,reject:o}),No&&clearTimeout(No),No=setTimeout(()=>{let r=new Set(Dr),i=fa.splice(0);Dr.clear(),No=null,Promise.all([...Fr].map(s=>Promise.resolve(s(r)))).then(()=>{for(let{resolve:s}of i)s();}).catch(s=>{console.error("Error refreshing entity lists:",s);for(let{reject:a}of i)a(s);});},50);})}function Ir({action:e}){let{projects:t,currentProjectId:n}=d(),{schema:o}=find(propEq(n??"","projectId"))(t),r=useApolloClient(),[i,s,a]=
|
|
382
|
+
`}}var Jn=e=>e.charAt(0).toUpperCase()+e.slice(1);function ot(e){let t=e.split(/[^0-9A-Za-z]+/).filter(Boolean).map(Jn).join("");return t?/^[A-Za-z_]/.test(t)?t:`Entity${t}`:"Entity"}function rt(e,t){return t==="_assets"?a$f:find(propEq(t,"plural"))(e)}function ua(e,t,n){if(!e||typeof e!="object")return {};let o=rt(n,t);if(!o)return {};let r=`update${Jn(t)}`,i=e[r];if(!i||typeof i!="object")return {};let s=i[t],a=Array.isArray(s)?s[0]:void 0;return !a||typeof a!="object"?{}:o.attributes.reduce((c,l)=>{if(be(l)!=="local")return c;let f=Et(a[l.name])?._id;return typeof f!="string"||f.length===0?c:{...c,[l.name]:f}},{})}var No=null,Dr=new Set,fa=[],Fr=new Set,Rr=new Set,Pr=new Set;function Ke(e,t){if(e==="_asset"||e==="_assets")return `Get${ot(a$f.plural)}`;let n=t.find(i=>i.plural===e),o=t.find(i=>i.name===e),r=n?.plural??o?.plural??e;return `Get${ot(r)}`}function da(e){return Fr.add(e),()=>{Fr.delete(e);}}function ma(e){return Rr.add(e),()=>{Rr.delete(e);}}function pa(e){return Pr.add(e),()=>{Pr.delete(e);}}function Do(e,t,n){let o=new Set(n.filter(Boolean));if(o.size>0)for(let r of Rr)r(t,o);return At(e,t)}function ga(e,t){let n=t.filter(o=>!!o._id);if(n.length!==0)for(let o of Pr)o(e,n);}function At(e,t){return Dr.add(t),new Promise((n,o)=>{fa.push({resolve:n,reject:o}),No&&clearTimeout(No),No=setTimeout(()=>{let r=new Set(Dr),i=fa.splice(0);Dr.clear(),No=null,Promise.all([...Fr].map(s=>Promise.resolve(s(r)))).then(()=>{for(let{resolve:s}of i)s();}).catch(s=>{console.error("Error refreshing entity lists:",s);for(let{reject:a}of i)a(s);});},50);})}function Ir({action:e}){let{projects:t,currentProjectId:n}=d(),{schema:o}=find(propEq(n??"","projectId"))(t),r=useApolloClient(),[i,s,a]=xt(),c=pe(),l=useRef(false),u=Array.isArray(e.payload.entityId)?e.payload.entityId:[e.payload.entityId],f=e.payload.entityName==="_asset"?"asset":e.payload.entityName.toLowerCase(),m=!!e.payload.silent,p=u.length>1;if(useEffect(()=>{!m||l.current||(l.current=true,g());},[m]),m)return jsx(Fragment,{});let d$1={dialogTitle:p?`Delete ${u.length} ${f}s`:`Delete ${f}`,dialogMessage:p?`Are you sure you want to delete the selected ${f}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${f}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:()=>g()};function g(){let h=Un(e.payload.entityName,o,u);return new Promise((v,y)=>{s(gql`
|
|
383
383
|
${h}
|
|
384
|
-
`),a({variables:{where:qn(u)},update(b){for(let E of u)b.evict({id:E});},onCompleted:()=>{toast.success(p?"Items successfully deleted.":"Item successfully deleted."),Do(r,Ke(e.payload.entityName,o),u),c({type:"Dismiss",_id:e._id,payload:{}}),v();},onError:b=>{y(b);}}),i(true);})}return jsx(_n,{options:d$1})}var ha=createContext({isDirty:false,setIsDirty:e=>{}}),ya=({children:e})=>{let[t,n]=useState(false),o=useMemo(()=>({isDirty:t,setIsDirty:i=>{n(i);}}),[t,n]);return jsx(ha.Provider,{value:o,children:e})};function yn(){return useContext(ha)}function Lr(e,t){return !t||t.length===0||e===void 0?true:e.some(n=>t.includes(n))}function vn(e,t){return e.filter(n=>Lr(t,n.spaces))}function ef(e,t){return e.filter(n=>Lr(t,n.spaces)).map(n=>({...n,attributes:vn(n.attributes,t)}))}var va=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];function of(e,t){if(!e.type)return true;let n=t?t.split(",").map(o=>o.trim()).filter(Boolean):va;return n.length===0?true:n.some(o=>o.endsWith("/*")?e.type.startsWith(o.slice(0,-1)):e.type===o)}async function Mr(e,t){let n=new URLSearchParams({filename:e.name}),o=await fetch(`${c$6(t).assets}?${n.toString()}`,{method:"POST",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!o.ok)throw new Error(`Upload failed for ${e.name}`);let r=await o.json(),i={_id:r._id,path:r.path??"",originalFilename:r.originalFilename??e.name,size:r.size??e.size,mimeType:r.mimeType??e.type,lqip:r.lqip??"",width:r.width??0,height:r.height??0};return {pathname:i.path,lqip:i.lqip||void 0,originalFilename:i.originalFilename,size:i.size,mimeType:i.mimeType,width:i.width||void 0,height:i.height||void 0,_id:i._id,asset:i}}async function ba(e,t){let{projectId:n,accept:o,maxBytes:r=4*1024*1024,onUploadStart:i}=t,s=[];for(let a of Array.from(e)){if(a.size>r){toast.error(`File size too big (max ${(r/(1024*1024)).toFixed(0)}MB): ${a.name}`);continue}if(!of(a,o)){toast.error(`Unsupported file type: ${a.name}`);continue}s.push(a);}if(s.length===0)return [];i?.();try{let a=await Promise.all(s.map(async c=>Mr(c,n)));return a.length>0&&toast.success(`Uploaded ${a.length} file${a.length>1?"s":""}`),a}catch(a){return console.error(a),toast.error("Upload failed. Please try again."),[]}}async function rf(e){let{accept:t,multiple:n=true}=e,o=document.createElement("input");o.type="file",o.accept=t??va.join(","),o.multiple=n,o.style.display="none",document.body.appendChild(o);try{let r=await new Promise(i=>{o.addEventListener("change",()=>i(o.files),{once:!0}),o.addEventListener("cancel",()=>i(null),{once:!0}),o.click();});return !r||r.length===0?[]:ba(r,e)}finally{document.body.removeChild(o);}}function Gn(){let e=useApolloClient();return useCallback(async t=>{let n=t.files?await ba(t.files,t):await rf(t);return n.length>0&&await At(e,"GetAssets").catch(o=>{console.error("Error refreshing asset lists after upload:",o);}),n},[e])}function bn(e,t,n){useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o);}},[t,e,n]),useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("focusin",o),()=>{document.removeEventListener("mousedown",o);}},[t,e]);}function Na({control:e$1,entityId:t,fieldSchema:n$1,getValues:o,readOnly:r,setValue:i}){let{name:s,label:a,options:c$1}=n$1,{projectId:l$1}=useParams(),u=pe(),f$1=d$2(),{relationships:m$1}=c$2(),[p,d]=useState(false),g$1=useRef(null),h=useRef(null),v=useRef(null),[y,b]=useState(null),[E,A]=useState(false),[F,N]=useState(false),x=useId(),D=useId();bn(h,d,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let C=m$1[D]?.connect;if(!C||v.current===C._id)return;let k=hf(C.value);if(!k)return;let _=o(s);v.current=C._id,b(null),i(s,{..._,value:k});},[o,s,D,m$1,i]);function $(C){if(!C)return;let k={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(k[C])return k[C];let _=C.split("/");if(_.length===2){let[,U]=_;return U.includes("svg")?"svg":U.toLowerCase()}}function O(C,k){if(C&&C.includes(".")){let U=C.split(".").pop();if(U)return U.toLowerCase()}let _=$(k);return _||"file"}async function V(C,k){if(r||!C)return;let _=$r("4MB");if(C.size>(_??0)){toast.error("File size too big (max 4MB)");return}let U=C.type.startsWith("image/");if(v.current=null,U){let W=new FileReader;W.onload=se=>{b(se.target?.result);},W.readAsDataURL(C);}else b(null);N(true);try{let W=await Mr(C,l$1);i(s,{...o(s),value:W.asset});}catch(W){console.error(W),b(null),i(s,{...o(s),value:{_id:k?.value?._id}});}finally{N(false);}}function R(C){r||(C.stopPropagation(),v.current=null,i(s,{...o(s),_id:"",value:{_id:o(s)?.value?._id}}));}function B(C,k){C.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function Z(C){C.preventDefault(),C.stopPropagation(),!r&&g$1.current?.click();}function te(C){if(C.preventDefault(),C.stopPropagation(),r)return;d(false);let k=o(s)?.value,_=v.current??yf(k),U=_?{_id:_,value:k}:void 0;f$1({type:"setRelationship",payload:{[D]:{connect:U,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:c$1?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:U,relationshipId:D,mode:"single"}});},0);}function M(C,k){C.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:s,render:({field:C})=>jsxs(e,{children:[jsx(f,{htmlFor:x,children:a}),c$1?.comment?jsx(h$1,{children:c$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${s}`,"aria-expanded":p,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${p?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${E?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),h.current?.focus(),h.current?.click(),d(true);},onKeyDown:k=>{k.key==="Enter"&&d(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false));},onDragOver:k=>{r||(k.preventDefault(),k.stopPropagation(),A(true));},onDragEnter:k=>{r||(k.preventDefault(),k.stopPropagation(),A(true));},onDragLeave:k=>{r||(k.preventDefault(),k.stopPropagation(),A(false));},onDrop:k=>{if(k.preventDefault(),k.stopPropagation(),A(false),r)return;let _=k.dataTransfer.files&&k.dataTransfer.files[0];V(_,C.value);},ref:h,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!C.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",disabled:r,id:x,onClick:Z,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",disabled:r,onClick:te,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,C.value?.value?.path&&!p?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=C.value?.value,_=k?.mimeType,U=k?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let se=O(k.originalFilename,k.mimeType),oe=defaultStyles[se];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:se,...oe||{}})})})(),$r((C.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(C.value?.value).mimeType,(C.value?.value).width&&(C.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(C.value?.value).width,"x",(C.value?.value).height,"px"]}):null]}):null,!C.value?.value?.path&&y&&jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("img",{src:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!C.value?.value?.path&&!y&&F?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("div",{className:"fk:w-7 fk:h-7 fk:mr-2 fk:rounded-sm fk:bg-muted fk:flex fk:items-center fk:justify-center",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,C.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$2,{disabled:r,onClick:Z,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$2,{disabled:r,onClick:te,children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$2,{onClick:k=>M(k,C.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$2,{onClick:k=>B(k,C.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$2,{disabled:r,onClick:R,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!p&&(C.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(h.current?.focus(),h.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),p&&(C.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(l,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:d,open:p&&(!!C.value?.value?.path||!!y),children:jsx(n,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${s}`,children:C.value?.value?.path?(()=>{let k=C.value?.value,_=k?.mimeType,U=k?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let se=O(k.originalFilename,k.mimeType),oe=defaultStyles[se];return jsxs("div",{className:"fk:w-full fk:h-full fk:rounded-md fk:bg-muted/40 fk:flex fk:flex-col fk:items-center fk:justify-center fk:text-muted-foreground",children:[jsx("div",{className:"fk:w-16 fk:h-16 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:se,...oe||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",$r(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),F?jsx("div",{className:"fk:absolute fk:m-0! fk:top-0 fk:left-0 fk:right-0 fk:bottom-0 fk:w-full fk:bg-muted-foreground/5 fk:overflow-hidden",children:jsx("div",{className:"fk:animate-progress fk:w-full fk:h-full fk:bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:c$1?.accept?c$1.accept:"image/*",className:"fk:hidden",disabled:r,id:`file-upload-${s}`,onChange:k=>{let _=k.currentTarget.files&&k.currentTarget.files[0];V(_,C.value);},ref:g$1,type:"file"}),jsx(i$1,{})]})})}function hf(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 yf(e){return !e?._id||e._id.includes(":")?"":e._id}function Da({control:e$1,fieldSchema:t,readOnly:n,setValue:o}){let{name:r,label:i,options:s,dataType:a}=t,c$1=useId();function l(f,m){let p=f.currentTarget.value,d;p===""?d="":(d=a==="float"?parseFloat(p):parseInt(p,10),isNaN(d)&&(d="")),o(r,{...m,value:d});}function u(f,m){o(r,{...m,disabled:f});}return jsx(c,{control:e$1,name:r,render:({field:f$1})=>jsxs(e,{children:[jsx(f,{htmlFor:c$1,children:i}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsx(a$7,{className:"fk:w-full fk:mt-0.75",disabled:n||f$1.value?.disabled,id:c$1,...f$1,onChange:m=>{l(m,f$1.value);},step:a==="float"?"any":"1",type:"number",value:f$1.value?.value??""})}),jsx(a$6,{checked:f$1.value?.disabled??false,disabled:n,onChange:m=>{u(m,f$1.value);},scope:f$1.value?.scope}),jsx(i$1,{})]})})}function Cn({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function wn({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Bt({className:e,align:t="center",sideOffset:n=4,...o}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:n,className:a$1("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...o})})}function Ra({className:e,classNames:t,showOutsideDays:n=true,captionLayout:o="label",buttonVariant:r="ghost",formatters:i,components:s,...a}){let c=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:n,className:a$1("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:o,formatters:{formatMonthDropdown:l=>l.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$1("w-fit",c.root),months:a$1("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",c.months),month:a$1("fk:flex fk:w-full fk:flex-col fk:gap-4",c.month),nav:a$1("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",c.nav),button_previous:a$1(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",c.button_previous),button_next:a$1(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",c.button_next),month_caption:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",c.month_caption),dropdowns:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",c.dropdowns),dropdown_root:a$1("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",c.dropdown_root),dropdown:a$1("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",c.dropdown),caption_label:a$1("fk:font-medium fk:select-none",o==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",c.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$1("fk:flex",c.weekdays),weekday:a$1("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",c.weekday),week:a$1("fk:mt-2 fk:flex fk:w-full",c.week),week_number_header:a$1("fk:w-(--cell-size) fk:select-none",c.week_number_header),week_number:a$1("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",c.week_number),day:a$1("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",a.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",c.day),range_start:a$1("fk:rounded-l-md fk:bg-accent",c.range_start),range_middle:a$1("fk:rounded-none",c.range_middle),range_end:a$1("fk:rounded-r-md fk:bg-accent",c.range_end),today:a$1("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",c.today),outside:a$1("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",c.outside),disabled:a$1("fk:text-muted-foreground fk:opacity-50",c.disabled),hidden:a$1("invisible",c.hidden),...t},components:{Root:({className:l,rootRef:u,...f})=>jsx("div",{"data-slot":"calendar",ref:u,className:a$1(l),...f}),Chevron:({className:l,orientation:u,...f})=>u==="left"?jsx(ChevronLeftIcon,{className:a$1("size-4",l),...f}):u==="right"?jsx(ChevronRightIcon,{className:a$1("size-4",l),...f}):jsx(ChevronDownIcon,{className:a$1("size-4",l),...f}),DayButton:Ef,WeekNumber:({children:l,...u})=>jsx("td",{...u,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:l})}),...s},...a})}function Ef({className:e,day:t,modifiers:n,...o}){let r=getDefaultClassNames(),i=Lo.useRef(null);return Lo.useEffect(()=>{n.focused&&i.current?.focus();},[n.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:a$1("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...o})}function Pa({control:e$1,fieldSchema:t,getValues:n,readOnly:o,setValue:r}){let{name:i,label:s,options:a}=t,c$1=useId();function l(m,p){r(i,{...p,value:m?m.toISOString():""});}function u(m,p){r(i,{...p,disabled:m});}function f$1(m){m.preventDefault(),r(i,{...n(i),value:void 0});}return jsx(c,{control:e$1,name:i,render:({field:m})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:c$1,children:s}),a?.comment?jsx(h$1,{children:a.comment}):null,jsx(g,{children:jsxs(Cn,{children:[jsx(wn,{asChild:true,children:jsx(b$3,{className:a$1("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!m.value?.value&&"fk:text-muted-foreground"),disabled:o||m.value?.disabled,id:c$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:m.value?.value?format(new Date(m.value.value),"PPP")+" at "+format(new Date(m.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[m.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:p=>{p.stopPropagation(),f$1(p);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(Bt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Ra,{mode:"single",selected:m.value?.value?new Date(m.value.value):void 0,onSelect:p=>l(p,m.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$7,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let d=p.target.value,[g,h]=d.split(":"),v=m.value?.value?new Date(m.value.value):new Date;v.setHours(parseInt(g)),v.setMinutes(parseInt(h)),r(i,{...m.value,value:v.toISOString()});},type:"time",value:m.value?.value?format(new Date(m.value.value),"HH:mm"):""})]})]})]})}),jsx(a$6,{checked:m.value?.disabled??false,disabled:o,onChange:p=>{u(p,m.value);},scope:m.value?.scope}),jsx(i$1,{})]})})}function Ve(e){return e??null}var Vr=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let n=document.createElement("input");n.type="file",n.accept="image/*",n.onchange=async()=>{n.files?.length;},n.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(n??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:n??""}).run():n!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(n??"")?e.chain().focus().deleteRange(t).setTweet({src:n??""}).run():n!==null&&alert("Please enter a correct Twitter Link");}}]),Ia=Command.configure({suggestion:{items:()=>Vr,render:renderItems}});var Ma=[{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"}],_a=[{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)"}],$a=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=Ma.find(({color:i})=>n.isActive("textStyle",{color:i})),r=_a.find(({color:i})=>n.isActive("highlight",{color:i}));return jsxs(Cn,{modal:true,open:e,onOpenChange:t,children:[jsx(wn,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:o?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(Bt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),Ma.map(({name:i,color:s})=>jsx(EditorBubbleItem,{onSelect:()=>{n.commands.unsetColor(),i!=="Default"&&n.chain().focus().setColor(s||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:s},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),_a.map(({name:i,color:s})=>jsxs(EditorBubbleItem,{onSelect:()=>{n.commands.unsetHighlight(),i!=="Default"&&n.chain().focus().setHighlight({color:s}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:s},children:"A"}),jsx("span",{children:i})]}),n.isActive("highlight",{color:s})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Zf(e){try{return new URL(e),!0}catch{return false}}function Yf(e){if(Zf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Va=({open:e,onOpenChange:t})=>{let n=useRef(null),{editor:o}=useEditor();return useEffect(()=>{n.current?.focus();}),o?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$1("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":o.isActive("link")}),children:"Link"})]})}),jsx(Bt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let s=i[0],a=Yf(s.value);a&&(o.chain().focus().setLink({href:a}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:n,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:o.getAttributes("link").href||""}),o.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{o.chain().focus().unsetLink().run(),n.current&&(n.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var za=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleHeading({level:3}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleBlockquote().run();},isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],ja=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=za.filter(r=>r.isActive(n)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:o.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:za.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),o.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var Ua=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:n,to:o}=e.state.selection,r=e.state.doc.textBetween(n,o);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$1("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var qa=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:n=>n!=null&&n.isActive("bold"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:n=>n!=null&&n.isActive("italic"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:n=>n!=null&&n.isActive("underline"),command:n=>n?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:n=>n!=null&&n.isActive("strike"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:n=>n!=null&&n.isActive("code"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleCode().run();},icon:CodeIcon}].map(n=>jsx(EditorBubbleItem,{onSelect:o=>{n.command(o);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:o=>o.preventDefault(),variant:"ghost",children:jsx(n.icon,{className:a$1("fk:h-4 fk:w-4",{"fk:text-blue-500":n.isActive(e)})})})},n.name))}):null};function Qn({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var Cd=()=>jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-0.5",children:[jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-500 [animation-delay:-0.3s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 [animation-delay:-0.15s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600"})]}),Ja=Cd;function Hr({completion:e,onDiscard:t}){let{editor:n}=useEditor();return n?jsxs(Fragment,{children:[jsxs(s$1,{children:[jsxs(u$1,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt({from:o.from,to:o.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(u$1,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt(o.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(t$1,{}),jsx(s$1,{children:jsxs(u$1,{onSelect:t,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var Md=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function qr({onSelect:e}){let{editor:t}=useEditor();return t?jsxs(Fragment,{children:[jsx(s$1,{heading:"Edit or review selection",children:Md.map(n=>jsxs(u$1,{onSelect:o=>{let r=t.state.selection.content(),i=t.storage.markdown.serializer.serialize(r.content);e(i,o);},className:"fk:flex fk:gap-2 fk:px-4",value:n.value,children:[jsx(n.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),n.label]},n.value))}),jsx(t$1,{}),jsx(s$1,{heading:"Use AI to do more",children:jsxs(u$1,{onSelect:()=>{let n=t.state.selection.from,o=getPrevText(t,n);e(o,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function Qa({onOpenChange:e}){let{editor:t}=useEditor(),[n,o]=useState(""),{projectId:r}=useParams(),{completion:i,complete:s,isLoading:a}=useCompletion({api:c$6(r).completion,fetch:async(l,u)=>{let f=await fetch(l,u);if(f.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return f},onError:l=>{l.message!=="FK_AI_RATE_LIMIT"&&toast.error(l.message);}}),c=i.length>0;return t?jsxs(n$1,{className:"fk:w-[350px]",children:[c&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(w,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(Hd,{children:i})})})}),a&&jsxs("div",{className:"fk:flex fk:h-12 fk:w-full fk:items-center fk:px-4 fk:text-sm fk:font-medium fk:text-muted-foreground fk:text-pink-600",children:[jsx(Qn,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 "}),"AI is thinking",jsx("div",{className:"fk:ml-2 fk:mt-1",children:jsx(Ja,{})})]}),!a&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(p$1,{value:n,onValueChange:o,autoFocus:true,placeholder:c?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return s(i,{body:{option:"zap",command:n}}).then(()=>o(""));let l=t.state.selection.content(),u=t.storage.markdown.serializer.serialize(l.content);s(u,{body:{option:"zap",command:n}}).then(()=>o(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(q$1,{children:c?jsx(Hr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(qr,{onSelect:(l,u)=>s(l,{body:{option:u}})})})]})]}):null}function Gr({children:e,open:t,onOpenChange:n}){let{editor:o}=useEditor();return useEffect(()=>{o&&(t||removeAIHighlight(o));},[o,t]),o?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{n(false),o.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(Qa,{open:t,onOpenChange:n}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),n(true);},size:"sm",children:[jsx(Qn,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var am=[...a,Ia];function Wa(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 lm(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let n=JSON.parse(t);if(Wa(n))return n}catch{return}}if(Wa(e))return e}function Qr({control:e$1,defaultValue:t,fieldSchema:n,readOnly:o,setValue:r}){let{name:i,label:s,options:a}=n,[c$1,l]=useState(false),[u,f$1]=useState(false),[m,p]=useState(false),[d,g$1]=useState(false),h=useDebouncedCallback((b,E)=>{let A=b.getJSON();r(i,{...E,value:JSON.stringify(A)});},300);function v(b,E){r(i,{...E,disabled:b});}let y=b=>(console.log("Image uploader not yet implemented",b),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:i,render:({field:b})=>jsxs(e,{children:[jsx(f,{children:s}),a?.comment?jsx(h$1,{children:a.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-5xl fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:!o&&!b.value?.disabled,editorProps:{handleDOMEvents:{keydown:(E,A)=>handleCommandNavigation(A)},handlePaste:(E,A)=>handleImagePaste(E,A,y),handleDrop:(E,A,F,N)=>handleImageDrop(E,A,N,y),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:am,initialContent:lm(b.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:E})=>{h(E,b.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Vr.map(E=>jsxs(EditorCommandItem,{value:E.title,onCommand:A=>E.command?.(A),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted",children:[jsx("div",{className:"fk:flex fk:h-10 fk:w-10 fk:items-center fk:justify-center fk:rounded-md fk:border fk:border-muted fk:bg-background",children:E.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:E.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:E.description})]})]},E.title))})]}),jsxs(Gr,{open:c$1,onOpenChange:l,children:[jsx(c$5,{orientation:"vertical"}),jsx(ja,{open:u,onOpenChange:f$1}),jsx(c$5,{orientation:"vertical"}),jsx(Va,{open:m,onOpenChange:p}),jsx(c$5,{orientation:"vertical"}),jsx(Ua,{}),jsx(c$5,{orientation:"vertical"}),jsx(qa,{}),jsx(c$5,{orientation:"vertical"}),jsx($a,{open:d,onOpenChange:g$1})]})]},`${i}:${b.value?.scope??t.scope}:${String(b.value?.disabled??t.disabled)}`)})}),jsx(a$6,{checked:b.value?.disabled??false,disabled:o,onChange:E=>{v(E,b.value);},scope:b.value?.scope}),jsx(i$1,{})]})})}var ym=xo;function Zr({control:e$1,defaultValue:t,entityId:n$1,entityName:o,entityNamePlural:r,fieldSchema:i,readOnly:s,schema:a,setValue:c$1}){let{name:l$1,label:u,options:f$1,relationship:m}=i,{projectId:p}=useParams(),d=pe(),g$1=d$2(),{relationships:h}=c$2(),v=Gn(),y=useId(),b=useId(),E=useRef(null),A=useRef([]),F=useRef(null),N=useRef([]),x=useRef(""),D=useRef(t.knownAssetSortOrders??{}),[$,O]=useState(false),V=useMemo(()=>Cm(t.value),[t.value]),[R,B]=useState(V),[Z,te]=useState(()=>Object.keys(t.knownAssetSortOrders??zn(V)).length),[M,C]=useState(()=>Math.max(t.count??0,V[0]?.totalCount??0,V.length)),k=useMemo(()=>ca({attributeName:l$1,entityName:o,entityNamePlural:r,schema:a}),[o,r,l$1,a]),[_,{loading:U}]=useLazyQuery(gql`
|
|
384
|
+
`),a({variables:{where:qn(u)},update(b){for(let E of u)b.evict({id:E});},onCompleted:()=>{toast.success(p?"Items successfully deleted.":"Item successfully deleted."),Do(r,Ke(e.payload.entityName,o),u),c({type:"Dismiss",_id:e._id,payload:{}}),v();},onError:b=>{y(b);}}),i(true);})}return jsx(_n,{options:d$1})}var ha=createContext({isDirty:false,setIsDirty:e=>{}}),ya=({children:e})=>{let[t,n]=useState(false),o=useMemo(()=>({isDirty:t,setIsDirty:i=>{n(i);}}),[t,n]);return jsx(ha.Provider,{value:o,children:e})};function yn(){return useContext(ha)}function Lr(e,t){return !t||t.length===0||e===void 0?true:e.some(n=>t.includes(n))}function vn(e,t){return e.filter(n=>Lr(t,n.spaces))}function ef(e,t){return e.filter(n=>Lr(t,n.spaces)).map(n=>({...n,attributes:vn(n.attributes,t)}))}var va=["image/jpeg","image/png","image/webp","image/vnd.microsoft.icon","image/bmp","image/gif","image/tiff","image/svg+xml","image/avif","image/heic","image/heif","image/heic-sequence","image/heif-sequence","image/apng","audio/aac","audio/mpeg","audio/wav","audio/webm","audio/midi","audio/x-midi","audio/ogg","video/x-msvideo","video/mp4","video/mpeg","video/webm","video/quicktime","video/ogg","video/mp2t","video/3gpp","video/3gpp2","application/x-7z-compressed","application/zip","application/vnd.amazon.ebook","application/octet-stream","application/epub+zip","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-fontobject","application/gzip","application/x-gzip","application/java-archive","application/json","application/ld+json","text/javascript","application/vnd.oasis.opendocument.presentation","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.text","application/ogg","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.rar","application/x-tar","application/vnd.visio","application/xhtml+xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/xml"];function of(e,t){if(!e.type)return true;let n=t?t.split(",").map(o=>o.trim()).filter(Boolean):va;return n.length===0?true:n.some(o=>o.endsWith("/*")?e.type.startsWith(o.slice(0,-1)):e.type===o)}async function Mr(e,t){let n=new URLSearchParams({filename:e.name}),o=await fetch(`${c$6(t).assets}?${n.toString()}`,{method:"POST",headers:{"Content-Type":e.type||"application/octet-stream"},body:e});if(!o.ok)throw new Error(`Upload failed for ${e.name}`);let r=await o.json(),i={_id:r._id,path:r.path??"",originalFilename:r.originalFilename??e.name,size:r.size??e.size,mimeType:r.mimeType??e.type,lqip:r.lqip??"",width:r.width??0,height:r.height??0};return {pathname:i.path,lqip:i.lqip||void 0,originalFilename:i.originalFilename,size:i.size,mimeType:i.mimeType,width:i.width||void 0,height:i.height||void 0,_id:i._id,asset:i}}async function ba(e,t){let{projectId:n,accept:o,maxBytes:r=4*1024*1024,onUploadStart:i}=t,s=[];for(let a of Array.from(e)){if(a.size>r){toast.error(`File size too big (max ${(r/(1024*1024)).toFixed(0)}MB): ${a.name}`);continue}if(!of(a,o)){toast.error(`Unsupported file type: ${a.name}`);continue}s.push(a);}if(s.length===0)return [];i?.();try{let a=await Promise.all(s.map(async c=>Mr(c,n)));return a.length>0&&toast.success(`Uploaded ${a.length} file${a.length>1?"s":""}`),a}catch(a){return console.error(a),toast.error("Upload failed. Please try again."),[]}}async function rf(e){let{accept:t,multiple:n=true}=e,o=document.createElement("input");o.type="file",o.accept=t??va.join(","),o.multiple=n,o.style.display="none",document.body.appendChild(o);try{let r=await new Promise(i=>{o.addEventListener("change",()=>i(o.files),{once:!0}),o.addEventListener("cancel",()=>i(null),{once:!0}),o.click();});return !r||r.length===0?[]:ba(r,e)}finally{document.body.removeChild(o);}}function Gn(){let e=useApolloClient();return useCallback(async t=>{let n=t.files?await ba(t.files,t):await rf(t);return n.length>0&&await At(e,"GetAssets").catch(o=>{console.error("Error refreshing asset lists after upload:",o);}),n},[e])}function bn(e,t,n){useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o);}},[t,e,n]),useEffect(()=>{function o(r){if(e.current&&!e.current.contains(r.target)){if(n){let i=Array.from(document.querySelectorAll(n));for(let s of i)if(s.contains(r.target))return}t(false);}}return document.addEventListener("focusin",o),()=>{document.removeEventListener("mousedown",o);}},[t,e]);}function Na({control:e$1,entityId:t,fieldSchema:n$1,getValues:o,readOnly:r,setValue:i}){let{name:s,label:a,options:c$1}=n$1,{projectId:l$1}=useParams(),u=pe(),f$1=d$2(),{relationships:m$1}=c$2(),[p,d]=useState(false),g$1=useRef(null),h=useRef(null),v=useRef(null),[y,b]=useState(null),[E,A]=useState(false),[F,N]=useState(false),S=useId(),D=useId();bn(h,d,"[data-radix-popper-content-wrapper]"),useEffect(()=>{let C=m$1[D]?.connect;if(!C||v.current===C._id)return;let k=hf(C.value);if(!k)return;let _=o(s);v.current=C._id,b(null),i(s,{..._,value:k});},[o,s,D,m$1,i]);function $(C){if(!C)return;let k={"application/pdf":"pdf","application/zip":"zip","application/x-zip-compressed":"zip","application/json":"json","text/csv":"csv","text/plain":"txt","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","application/vnd.apple.keynote":"key","application/vnd.apple.numbers":"numbers","application/vnd.apple.pages":"pages","application/x-7z-compressed":"7z","application/x-rar-compressed":"rar","application/xml":"xml","video/mp4":"mp4","video/quicktime":"mov","audio/mpeg":"mp3","audio/wav":"wav"};if(k[C])return k[C];let _=C.split("/");if(_.length===2){let[,U]=_;return U.includes("svg")?"svg":U.toLowerCase()}}function O(C,k){if(C&&C.includes(".")){let U=C.split(".").pop();if(U)return U.toLowerCase()}let _=$(k);return _||"file"}async function V(C,k){if(r||!C)return;let _=$r("4MB");if(C.size>(_??0)){toast.error("File size too big (max 4MB)");return}let U=C.type.startsWith("image/");if(v.current=null,U){let W=new FileReader;W.onload=se=>{b(se.target?.result);},W.readAsDataURL(C);}else b(null);N(true);try{let W=await Mr(C,l$1);i(s,{...o(s),value:W.asset});}catch(W){console.error(W),b(null),i(s,{...o(s),value:{_id:k?.value?._id}});}finally{N(false);}}function R(C){r||(C.stopPropagation(),v.current=null,i(s,{...o(s),_id:"",value:{_id:o(s)?.value?._id}}));}function B(C,k){C.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&navigator.clipboard.writeText(`${b$4}${k.value.path}`);}function Z(C){C.preventDefault(),C.stopPropagation(),!r&&g$1.current?.click();}function te(C){if(C.preventDefault(),C.stopPropagation(),r)return;d(false);let k=o(s)?.value,_=v.current??yf(k),U=_?{_id:_,value:k}:void 0;f$1({type:"setRelationship",payload:{[D]:{connect:U,disconnect:[]}}}),window.setTimeout(()=>{u({type:"EditRelationship",payload:{assetAccept:c$1?.accept,connectedEntitiesCount:0,entityId:t,entityName:"_asset",initialAssetPath:k?.path,initialConnection:U,relationshipId:D,mode:"single"}});},0);}function M(C,k){C.stopPropagation(),k?.value&&typeof k.value=="object"&&"path"in k.value&&window.open(`${b$4}${k.value.path}?download=1`,"_blank");}return jsx(c,{control:e$1,name:s,render:({field:C})=>jsxs(e,{children:[jsx(f,{htmlFor:S,children:a}),c$1?.comment?jsx(h$1,{children:c$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-[2.5rem] fk:text-sm",children:jsxs("div",{"aria-controls":`image-dropdown-${s}`,"aria-expanded":p,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:overflow-hidden fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${p?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""} ${E?"fk:border-dashed fk:border-2 fk:border-emerald-500 fk:bg-green-50":"fk:border-input fk:bg-background"}`,onClick:k=>{k.preventDefault(),k.stopPropagation(),h.current?.focus(),h.current?.click(),d(true);},onKeyDown:k=>{k.key==="Enter"&&d(true),k.key==="Escape"&&(k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false));},onDragOver:k=>{r||(k.preventDefault(),k.stopPropagation(),A(true));},onDragEnter:k=>{r||(k.preventDefault(),k.stopPropagation(),A(true));},onDragLeave:k=>{r||(k.preventDefault(),k.stopPropagation(),A(false));},onDrop:k=>{if(k.preventDefault(),k.stopPropagation(),A(false),r)return;let _=k.dataTransfer.files&&k.dataTransfer.files[0];V(_,C.value);},ref:h,role:"combobox",tabIndex:0,children:[jsxs("div",{className:"fk:flex fk:w-full fk:space-x-2",children:[!C.value?.value?.path&&!y?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsxs("div",{className:"fk:flex fk:h-full fk:items-center fk:text-muted-foreground fk:text-sm fk:font-light",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"})," Drag or paste file here"]}),jsxs(b$3,{className:"fk:ml-auto fk:h-7 fk:rounded-sm fk:text-muted-foreground",disabled:r,id:S,onClick:Z,variant:"ghost",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Upload"]}),jsxs(b$3,{className:"fk:ml-2 fk:h-7 fk:rounded-sm fk:text-muted-foreground",disabled:r,onClick:te,variant:"ghost",children:[jsx(Search,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select"]})]}):null,C.value?.value?.path&&!p?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[(()=>{let k=C.value?.value,_=k?.mimeType,U=k?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:object-scale-down",src:`${b$4}${k.path}?w=128&h=128&f=webp`,alt:"Uploaded"});let se=O(k.originalFilename,k.mimeType),oe=defaultStyles[se];return jsx("div",{className:"fk:w-8 fk:h-8 fk:mr-2 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:se,...oe||{}})})})(),$r((C.value?.value).size),jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(C.value?.value).mimeType,(C.value?.value).width&&(C.value?.value).height?jsxs(Fragment,{children:[jsx("span",{className:"fk:block fk:w-px fk:h-5 fk:mx-2 fk:bg-border"}),(C.value?.value).width,"x",(C.value?.value).height,"px"]}):null]}):null,!C.value?.value?.path&&y&&jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("img",{src:y,alt:"Preview",className:"fk:mr-2 fk:mt-0.5 fk:rounded-sm fk:h-7 fk:w-7 rounded-md object-cover"}),"Loading image..."]}),!C.value?.value?.path&&!y&&F?jsxs("div",{className:"fk:flex fk:h-9 fk:w-full fk:px-3 fk:pt-0.5 fk:items-center",children:[jsx("div",{className:"fk:w-7 fk:h-7 fk:mr-2 fk:rounded-sm fk:bg-muted fk:flex fk:items-center fk:justify-center",children:jsx(File,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})}),"Uploading file..."]}):null,C.value?.value?.path?jsx("div",{className:"fk:absolute fk:top-0 fk:right-10",children:jsxs(c$3,{modal:false,children:[jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(e$2,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:ml-auto fk:mt-[0.1875rem] fk:rounded-sm",onClick:k=>{k.stopPropagation();},onPointerDown:k=>{k.stopPropagation();},size:"icon",variant:"ghost",children:jsx(Ellipsis,{className:"fk:h-4 fk:w-4"})})})}),jsx(e$3,{children:jsx("p",{children:"Show actions"})})]})}),jsxs(f$2,{className:"fk:w-48",children:[jsxs(g$2,{children:[jsxs(h$2,{disabled:r,onClick:Z,children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Upload"})]}),jsxs(h$2,{disabled:r,onClick:te,children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Select asset"})]})]}),jsx(m,{}),jsxs(g$2,{children:[jsxs(h$2,{onClick:k=>M(k,C.value),children:[jsx(Download,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Download"})]}),jsxs(h$2,{onClick:k=>B(k,C.value),children:[jsx(Copy,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Copy URL"})]})]}),jsx(m,{}),jsxs(h$2,{disabled:r,onClick:R,children:[jsx(RefreshCwOff,{className:"fk:mr-2 fk:h-4 fk:w-4"}),jsx("span",{children:"Clear field"})]})]})]})}):null,jsx(Fragment,{children:!p&&(C.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onKeyDown:k=>{k.key==="Enter"&&(h.current?.focus(),h.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})}):null}),p&&(C.value?.value?.path||y)?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-[0.1875rem] fk:top-[0.1875rem] fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:k=>{k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false);},onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),h.current?.blur(),d(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):null]}),jsx(l,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:d,open:p&&(!!C.value?.value?.path||!!y),children:jsx(n,{className:"fk:w-full",children:jsx("div",{className:"fk:flex fk:w-full fk:h-[30vh]",id:`image-dropdown-${s}`,children:C.value?.value?.path?(()=>{let k=C.value?.value,_=k?.mimeType,U=k?.path||"";if(!!(_&&_.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(U)))return jsx("img",{className:"fk:w-full fk:rounded-md fk:object-scale-down",src:`${b$4}${k.path}?w=624&h=624&f=webp`,alt:"Uploaded"});let se=O(k.originalFilename,k.mimeType),oe=defaultStyles[se];return jsxs("div",{className:"fk:w-full fk:h-full fk:rounded-md fk:bg-muted/40 fk:flex fk:flex-col fk:items-center fk:justify-center fk:text-muted-foreground",children:[jsx("div",{className:"fk:w-16 fk:h-16 fk:rounded-sm fk:bg-transparent fk:flex fk:items-center fk:justify-center fk:[&>svg]:h-full fk:[&>svg]:w-auto",children:jsx(FileIcon,{extension:se,...oe||{}})}),jsxs("div",{className:"fk:mt-3 fk:text-sm",children:[k.originalFilename||"File"," \xB7 ",$r(k.size)," \xB7 ",k.mimeType]}),jsx("div",{className:"fk:mt-1 fk:text-xs",children:"Preview not available"})]})})():null})})}),F?jsx("div",{className:"fk:absolute fk:m-0! fk:top-0 fk:left-0 fk:right-0 fk:bottom-0 fk:w-full fk:bg-muted-foreground/5 fk:overflow-hidden",children:jsx("div",{className:"fk:animate-progress fk:w-full fk:h-full fk:bg-muted-foreground/10"})}):null]})}),jsx("input",{accept:c$1?.accept?c$1.accept:"image/*",className:"fk:hidden",disabled:r,id:`file-upload-${s}`,onChange:k=>{let _=k.currentTarget.files&&k.currentTarget.files[0];V(_,C.value);},ref:g$1,type:"file"}),jsx(i$1,{})]})})}function hf(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 yf(e){return !e?._id||e._id.includes(":")?"":e._id}function Da({control:e$1,fieldSchema:t,readOnly:n,setValue:o}){let{name:r,label:i,options:s,dataType:a}=t,c$1=useId();function l(f,m){let p=f.currentTarget.value,d;p===""?d="":(d=a==="float"?parseFloat(p):parseInt(p,10),isNaN(d)&&(d="")),o(r,{...m,value:d});}function u(f,m){o(r,{...m,disabled:f});}return jsx(c,{control:e$1,name:r,render:({field:f$1})=>jsxs(e,{children:[jsx(f,{htmlFor:c$1,children:i}),s?.comment?jsx(h$1,{children:s.comment}):null,jsx(g,{children:jsx(a$7,{className:"fk:w-full fk:mt-0.75",disabled:n||f$1.value?.disabled,id:c$1,...f$1,onChange:m=>{l(m,f$1.value);},step:a==="float"?"any":"1",type:"number",value:f$1.value?.value??""})}),jsx(a$6,{checked:f$1.value?.disabled??false,disabled:n,onChange:m=>{u(m,f$1.value);},scope:f$1.value?.scope}),jsx(i$1,{})]})})}function Cn({...e}){return jsx(Popover.Root,{"data-slot":"popover",...e})}function wn({...e}){return jsx(Popover.Trigger,{"data-slot":"popover-trigger",...e})}function Bt({className:e,align:t="center",sideOffset:n=4,...o}){return jsx(Popover.Portal,{children:jsx(Popover.Content,{"data-slot":"popover-content",align:t,sideOffset:n,className:a$1("fk:z-50 fk:w-72 fk:origin-(--radix-popover-content-transform-origin) fk:rounded-md fk:border fk:bg-popover fk:p-4 fk:text-popover-foreground fk:shadow-md fk:outline-hidden fk:data-[side=bottom]:slide-in-from-top-2 fk:data-[side=left]:slide-in-from-right-2 fk:data-[side=right]:slide-in-from-left-2 fk:data-[side=top]:slide-in-from-bottom-2 fk:data-[state=closed]:animate-out fk:data-[state=closed]:fade-out-0 fk:data-[state=closed]:zoom-out-95 fk:data-[state=open]:animate-in fk:data-[state=open]:fade-in-0 fk:data-[state=open]:zoom-in-95",e),...o})})}function Ra({className:e,classNames:t,showOutsideDays:n=true,captionLayout:o="label",buttonVariant:r="ghost",formatters:i,components:s,...a}){let c=getDefaultClassNames();return jsx(DayPicker,{showOutsideDays:n,className:a$1("fk:group/calendar fk:bg-background fk:p-3 fk:[--cell-size:--spacing(8)] fk:in-data-[slot=card-content]:bg-transparent fk:in-data-[slot=popover-content]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,e),captionLayout:o,formatters:{formatMonthDropdown:l=>l.toLocaleString("default",{month:"short"}),...i},classNames:{root:a$1("w-fit",c.root),months:a$1("fk:relative fk:flex fk:flex-col fk:gap-4 fk:md:flex-row",c.months),month:a$1("fk:flex fk:w-full fk:flex-col fk:gap-4",c.month),nav:a$1("fk:absolute fk:inset-x-0 fk:top-0 fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",c.nav),button_previous:a$1(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",c.button_previous),button_next:a$1(a$9({variant:r}),"fk:size-(--cell-size) fk:p-0 fk:select-none fk:aria-disabled:opacity-50",c.button_next),month_caption:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:px-(--cell-size)",c.month_caption),dropdowns:a$1("fk:flex fk:h-(--cell-size) fk:w-full fk:items-center fk:justify-center fk:gap-1.5 fk:text-sm fk:font-medium",c.dropdowns),dropdown_root:a$1("fk:relative fk:rounded-md fk:border fk:border-input fk:shadow-xs fk:has-focus:border-ring fk:has-focus:ring-[3px] fk:has-focus:ring-ring/50",c.dropdown_root),dropdown:a$1("fk:absolute fk:inset-0 fk:bg-popover fk:opacity-0",c.dropdown),caption_label:a$1("fk:font-medium fk:select-none",o==="label"?"fk:text-sm":"fk:flex fk:h-8 fk:items-center fk:gap-1 fk:rounded-md fk:pr-1 fk:pl-2 fk:text-sm fk:[&>svg]:size-3.5 fk:[&>svg]:text-muted-foreground",c.caption_label),table:"fk:w-full fk:border-collapse",weekdays:a$1("fk:flex",c.weekdays),weekday:a$1("fk:flex-1 fk:rounded-md fk:text-[0.8rem] fk:font-normal fk:text-muted-foreground fk:select-none",c.weekday),week:a$1("fk:mt-2 fk:flex fk:w-full",c.week),week_number_header:a$1("fk:w-(--cell-size) fk:select-none",c.week_number_header),week_number:a$1("fk:text-[0.8rem] fk:text-muted-foreground fk:select-none",c.week_number),day:a$1("fk:group/day fk:relative fk:aspect-square fk:h-full fk:w-full fk:p-0 fk:text-center fk:select-none fk:[&:last-child[data-selected=true]_button]:rounded-r-md",a.showWeekNumber?"fk:[&:nth-child(2)[data-selected=true]_button]:rounded-l-md":"fk:[&:first-child[data-selected=true]_button]:rounded-l-md",c.day),range_start:a$1("fk:rounded-l-md fk:bg-accent",c.range_start),range_middle:a$1("fk:rounded-none",c.range_middle),range_end:a$1("fk:rounded-r-md fk:bg-accent",c.range_end),today:a$1("fk:rounded-md fk:bg-accent fk:text-accent-foreground fk:data-[selected=true]:rounded-none",c.today),outside:a$1("fk:text-muted-foreground fk:aria-selected:text-muted-foreground",c.outside),disabled:a$1("fk:text-muted-foreground fk:opacity-50",c.disabled),hidden:a$1("invisible",c.hidden),...t},components:{Root:({className:l,rootRef:u,...f})=>jsx("div",{"data-slot":"calendar",ref:u,className:a$1(l),...f}),Chevron:({className:l,orientation:u,...f})=>u==="left"?jsx(ChevronLeftIcon,{className:a$1("size-4",l),...f}):u==="right"?jsx(ChevronRightIcon,{className:a$1("size-4",l),...f}):jsx(ChevronDownIcon,{className:a$1("size-4",l),...f}),DayButton:Ef,WeekNumber:({children:l,...u})=>jsx("td",{...u,children:jsx("div",{className:"fk:flex fk:size-(--cell-size) fk:items-center fk:justify-center fk:text-center",children:l})}),...s},...a})}function Ef({className:e,day:t,modifiers:n,...o}){let r=getDefaultClassNames(),i=Lo.useRef(null);return Lo.useEffect(()=>{n.focused&&i.current?.focus();},[n.focused]),jsx(b$3,{ref:i,variant:"ghost",size:"icon","data-day":t.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:a$1("fk:flex fk:aspect-square fk:size-auto fk:w-full fk:min-w-(--cell-size) fk:flex-col fk:gap-1 fk:leading-none fk:font-normal fk:group-data-[focused=true]/day:relative fk:group-data-[focused=true]/day:z-10 fk:group-data-[focused=true]/day:border-ring fk:group-data-[focused=true]/day:ring-[3px] fk:group-data-[focused=true]/day:ring-ring/50 fk:data-[range-end=true]:rounded-md fk:data-[range-end=true]:rounded-r-md fk:data-[range-end=true]:bg-primary fk:data-[range-end=true]:text-primary-foreground fk:data-[range-middle=true]:rounded-none fk:data-[range-middle=true]:bg-accent fk:data-[range-middle=true]:text-accent-foreground fk:data-[range-start=true]:rounded-md fk:data-[range-start=true]:rounded-l-md fk:data-[range-start=true]:bg-primary fk:data-[range-start=true]:text-primary-foreground fk:data-[selected-single=true]:bg-primary fk:data-[selected-single=true]:text-primary-foreground fk:dark:hover:text-accent-foreground fk:[&>span]:text-xs fk:[&>span]:opacity-70",r.day,e),...o})}function Pa({control:e$1,fieldSchema:t,getValues:n,readOnly:o,setValue:r}){let{name:i,label:s,options:a}=t,c$1=useId();function l(m,p){r(i,{...p,value:m?m.toISOString():""});}function u(m,p){r(i,{...p,disabled:m});}function f$1(m){m.preventDefault(),r(i,{...n(i),value:void 0});}return jsx(c,{control:e$1,name:i,render:({field:m})=>jsxs(e,{onKeyDown:p=>{p.key==="Escape"&&(p.preventDefault(),p.stopPropagation());},children:[jsx(f,{htmlFor:c$1,children:s}),a?.comment?jsx(h$1,{children:a.comment}):null,jsx(g,{children:jsxs(Cn,{children:[jsx(wn,{asChild:true,children:jsx(b$3,{className:a$1("fk:w-full fk:justify-start fk:h-10 fk:text-left fk:font-normal fk:hover:bg-transparent fk:relative",!m.value?.value&&"fk:text-muted-foreground"),disabled:o||m.value?.disabled,id:c$1,variant:"outline",children:jsxs("div",{className:"fk:flex fk:items-center fk:w-full",children:[jsx("span",{className:"fk:grow",children:m.value?.value?format(new Date(m.value.value),"PPP")+" at "+format(new Date(m.value.value),"HH:mm"):"Pick a date and time"}),jsxs("div",{className:"fk:flex fk:items-center fk:gap-1",children:[m.value?.value&&jsx("span",{className:"fk:p-2 fk:text-muted-foreground fk:hover:text-accent-foreground fk:cursor-pointer",onClick:p=>{p.stopPropagation(),f$1(p);},role:"button","aria-label":"Clear date",children:jsx(X,{className:"fk:h-4 fk:w-4"})}),jsx(Calendar,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground fk:hover:text-accent-foreground"})]})]})})}),jsxs(Bt,{className:"fk:w-auto fk:p-0",align:"start",children:[jsx(Ra,{mode:"single",selected:m.value?.value?new Date(m.value.value):void 0,onSelect:p=>l(p,m.value),initialFocus:true}),jsxs("div",{className:"fk:p-3 fk:border-t fk:border-border",children:[jsx("label",{htmlFor:"time",className:"fk:text-sm fk:font-medium",children:"Time"}),jsx(a$7,{className:"fk:mt-1 fk:w-[90px]",id:"time",onChange:p=>{let d=p.target.value,[g,h]=d.split(":"),v=m.value?.value?new Date(m.value.value):new Date;v.setHours(parseInt(g)),v.setMinutes(parseInt(h)),r(i,{...m.value,value:v.toISOString()});},type:"time",value:m.value?.value?format(new Date(m.value.value),"HH:mm"):""})]})]})]})}),jsx(a$6,{checked:m.value?.disabled??false,disabled:o,onChange:p=>{u(p,m.value);},scope:m.value?.scope}),jsx(i$1,{})]})})}function Ve(e){return e??null}var Vr=createSuggestionItems([{title:"Text",description:"Just start typing with plain text.",searchTerms:["p","paragraph"],icon:jsx(Text,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").run();}},{title:"To-do List",description:"Track tasks with a to-do list.",searchTerms:["todo","task","list","check","checkbox"],icon:jsx(CheckSquare,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).toggleTaskList().run();}},{title:"Heading 1",description:"Big section heading.",searchTerms:["title","big","large"],icon:jsx(Heading1,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:1}).run();}},{title:"Heading 2",description:"Medium section heading.",searchTerms:["subtitle","medium"],icon:jsx(Heading2,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:2}).run();}},{title:"Heading 3",description:"Small section heading.",searchTerms:["subtitle","small"],icon:jsx(Heading3,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).setNode("heading",{level:3}).run();}},{title:"Bullet List",description:"Create a simple bullet list.",searchTerms:["unordered","point"],icon:jsx(List,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleBulletList().run();}},{title:"Numbered List",description:"Create a list with numbering.",searchTerms:["ordered"],icon:jsx(ListOrdered,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleOrderedList().run();}},{title:"Quote",description:"Capture a quote.",searchTerms:["blockquote"],icon:jsx(TextQuote,{size:18}),command:({editor:e,range:t})=>{let n=Ve(e);n&&n.chain().focus().deleteRange(t).toggleNode("paragraph","paragraph").toggleBlockquote().run();}},{title:"Code",description:"Capture a code snippet.",searchTerms:["codeblock"],icon:jsx(Code,{size:18}),command:({editor:e,range:t})=>e.chain().focus().deleteRange(t).toggleCodeBlock().run()},{title:"Image",description:"Upload an image from your computer.",searchTerms:["photo","picture","media"],icon:jsx(ImageIcon,{size:18}),command:({editor:e,range:t})=>{e.chain().focus().deleteRange(t).run();let n=document.createElement("input");n.type="file",n.accept="image/*",n.onchange=async()=>{n.files?.length;},n.click();}},{title:"Youtube",description:"Embed a Youtube video.",searchTerms:["video","youtube","embed"],icon:jsx(Youtube,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Youtube Video Link");new RegExp(/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/).test(n??"")?e.chain().focus().deleteRange(t).setYoutubeVideo({src:n??""}).run():n!==null&&alert("Please enter a correct Youtube Video Link");}},{title:"Twitter",description:"Embed a Tweet.",searchTerms:["twitter","embed"],icon:jsx(Twitter,{size:18}),command:({editor:e,range:t})=>{let n=prompt("Please enter Twitter Link");new RegExp(/^https?:\/\/(www\.)?x\.com\/([a-zA-Z0-9_]{1,15})(\/status\/(\d+))?(\/\S*)?$/).test(n??"")?e.chain().focus().deleteRange(t).setTweet({src:n??""}).run():n!==null&&alert("Please enter a correct Twitter Link");}}]),Ia=Command.configure({suggestion:{items:()=>Vr,render:renderItems}});var Ma=[{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"}],_a=[{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)"}],$a=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=Ma.find(({color:i})=>n.isActive("textStyle",{color:i})),r=_a.find(({color:i})=>n.isActive("highlight",{color:i}));return jsxs(Cn,{modal:true,open:e,onOpenChange:t,children:[jsx(wn,{asChild:true,children:jsxs(b$3,{size:"sm",className:"fk:gap-2 fk:rounded-none",variant:"ghost",children:[jsx("span",{className:"fk:rounded-xs fk:px-1",style:{color:o?.color,backgroundColor:r?.color},children:"A"}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsxs(Bt,{sideOffset:5,className:"fk:my-1 fk:flex fk:max-h-80 fk:w-48 fk:flex-col fk:overflow-hidden fk:overflow-y-auto fk:rounded-sm fk:border fk:p-1 fk:shadow-xl ",align:"start",children:[jsxs("div",{className:"fk:flex fk:flex-col",children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Color"}),Ma.map(({name:i,color:s})=>jsx(EditorBubbleItem,{onSelect:()=>{n.commands.unsetColor(),i!=="Default"&&n.chain().focus().setColor(s||"").run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{color:s},children:"A"}),jsx("span",{children:i})]})},i))]}),jsxs("div",{children:[jsx("div",{className:"fk:my-1 fk:px-2 fk:text-sm fk:font-semibold fk:text-muted-foreground",children:"Background"}),_a.map(({name:i,color:s})=>jsxs(EditorBubbleItem,{onSelect:()=>{n.commands.unsetHighlight(),i!=="Default"&&n.chain().focus().setHighlight({color:s}).run(),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:gap-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:px-2 fk:py-px fk:font-medium",style:{backgroundColor:s},children:"A"}),jsx("span",{children:i})]}),n.isActive("highlight",{color:s})&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},i))]})]})]})};function Zf(e){try{return new URL(e),!0}catch{return false}}function Yf(e){if(Zf(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}}var Va=({open:e,onOpenChange:t})=>{let n=useRef(null),{editor:o}=useEditor();return useEffect(()=>{n.current?.focus();}),o?jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2 fk:rounded-none fk:border-none",children:[jsx("p",{className:"fk:text-base",children:"\u2197"}),jsx("p",{className:a$1("fk:underline fk:decoration-stone-400 fk:underline-offset-4",{"fk:text-blue-500":o.isActive("link")}),children:"Link"})]})}),jsx(Bt,{align:"start",className:"fk:w-60 fk:p-0",sideOffset:10,children:jsxs("form",{onSubmit:r=>{let i=r.currentTarget;r.preventDefault();let s=i[0],a=Yf(s.value);a&&(o.chain().focus().setLink({href:a}).run(),t(false));},className:"fk:flex fk:p-1",children:[jsx("input",{ref:n,type:"text",placeholder:"Paste a link",className:"fk:flex-1 fk:bg-background fk:p-1 fk:text-sm fk:outline-hidden",defaultValue:o.getAttributes("link").href||""}),o.getAttributes("link").href?jsx(b$3,{size:"icon",variant:"outline",type:"button",className:"fk:flex fk:h-8 fk:items-center fk:rounded-xs fk:p-1 fk:text-red-600 fk:transition-all fk:hover:bg-red-100 fk:dark:hover:bg-red-800",onClick:()=>{o.chain().focus().unsetLink().run(),n.current&&(n.current.value=""),t(false);},children:jsx(Trash,{className:"fk:h-4 fk:w-4"})}):jsx(b$3,{size:"icon",className:"fk:h-8",children:jsx(Check,{className:"fk:h-4 fk:w-4"})})]})})]}):null};var za=[{name:"Text",icon:TextIcon,command:e=>e?.chain().focus().clearNodes().run(),isActive:e=>e!=null&&e.isActive("paragraph")&&!e.isActive("bulletList")&&!e.isActive("orderedList")},{name:"Heading 1",icon:Heading1,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleHeading({level:1}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:1})},{name:"Heading 2",icon:Heading2,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleHeading({level:2}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:2})},{name:"Heading 3",icon:Heading3,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleHeading({level:3}).run();},isActive:e=>e!=null&&e.isActive("heading",{level:3})},{name:"To-do List",icon:CheckSquare,command:e=>e?.chain().focus().clearNodes().toggleTaskList().run(),isActive:e=>e!=null&&e.isActive("taskItem")},{name:"Bullet List",icon:ListOrdered,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleBulletList().run();},isActive:e=>e!=null&&e.isActive("bulletList")},{name:"Numbered List",icon:ListOrdered,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleOrderedList().run();},isActive:e=>e!=null&&e.isActive("orderedList")},{name:"Quote",icon:TextQuote,command:e=>{let t=Ve(e);t&&t.chain().focus().clearNodes().toggleBlockquote().run();},isActive:e=>e!=null&&e.isActive("blockquote")},{name:"Code",icon:Code,command:e=>e?.chain().focus().clearNodes().toggleCodeBlock().run(),isActive:e=>e!=null&&e.isActive("codeBlock")}],ja=({open:e,onOpenChange:t})=>{let{editor:n}=useEditor();if(!n)return null;let o=za.filter(r=>r.isActive(n)).pop()??{name:"Multiple"};return jsxs(Popover.Root,{modal:true,open:e,onOpenChange:t,children:[jsx(Popover.Trigger,{asChild:true,className:"fk:gap-2 fk:rounded-none fk:border-none fk:hover:bg-muted fk:focus:ring-0",children:jsxs(b$3,{size:"sm",variant:"ghost",className:"fk:gap-2",children:[jsx("span",{className:"fk:whitespace-nowrap fk:text-sm",children:o.name}),jsx(ChevronDown,{className:"fk:h-4 fk:w-4"})]})}),jsx(Popover.Content,{sideOffset:5,align:"start",className:"fk:w-48 fk:p-1",children:za.map(r=>jsxs(EditorBubbleItem,{onSelect:i=>{r.command(i),t(false);},className:"fk:flex fk:cursor-pointer fk:items-center fk:justify-between fk:rounded-xs fk:px-2 fk:py-1 fk:text-sm fk:hover:bg-muted",children:[jsxs("div",{className:"fk:flex fk:items-center fk:space-x-2",children:[jsx("div",{className:"fk:rounded-xs fk:border fk:p-1",children:jsx(r.icon,{className:"fk:h-3 fk:w-3"})}),jsx("span",{children:r.name})]}),o.name===r.name&&jsx(Check,{className:"fk:h-4 fk:w-4"})]},r.name))})]})};var Ua=()=>{let{editor:e}=useEditor();return e?jsx(b$3,{variant:"ghost",size:"sm",className:"fk:rounded-none fk:w-12",onClick:t=>{if(e.isActive("math"))e.chain().focus().unsetLatex().run();else {let{from:n,to:o}=e.state.selection,r=e.state.doc.textBetween(n,o);if(!r)return;e.chain().focus().setLatex({latex:r}).run();}},children:jsx(SigmaIcon,{className:a$1("fk:size-4",{"fk:text-blue-500":e.isActive("math")}),strokeWidth:2.3})}):null};var qa=()=>{let{editor:e}=useEditor();return e?jsx("div",{className:"fk:flex",children:[{name:"bold",isActive:n=>n!=null&&n.isActive("bold"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleBold().run();},icon:BoldIcon},{name:"italic",isActive:n=>n!=null&&n.isActive("italic"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleItalic().run();},icon:ItalicIcon},{name:"underline",isActive:n=>n!=null&&n.isActive("underline"),command:n=>n?.chain().focus().toggleUnderline().run(),icon:UnderlineIcon},{name:"strike",isActive:n=>n!=null&&n.isActive("strike"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleStrike().run();},icon:StrikethroughIcon},{name:"code",isActive:n=>n!=null&&n.isActive("code"),command:n=>{let o=Ve(n);o&&o.chain().focus().toggleCode().run();},icon:CodeIcon}].map(n=>jsx(EditorBubbleItem,{onSelect:o=>{n.command(o);},children:jsx(b$3,{size:"sm",className:"fk:rounded-none",onClick:o=>o.preventDefault(),variant:"ghost",children:jsx(n.icon,{className:a$1("fk:h-4 fk:w-4",{"fk:text-blue-500":n.isActive(e)})})})},n.name))}):null};function Qn({className:e}){return jsxs("svg",{width:"469",height:"469",viewBox:"0 0 469 469",fill:"none",xmlns:"http://www.w3.org/2000/svg",shapeRendering:"geometricPrecision",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5",className:e,children:[jsx("title",{children:"Magic AI icon"}),jsx("path",{d:"M237.092 62.3004L266.754 71.4198C267.156 71.5285 267.51 71.765 267.765 72.0934C268.02 72.4218 268.161 72.8243 268.166 73.2399C268.172 73.6555 268.042 74.0616 267.796 74.3967C267.55 74.7318 267.201 74.9777 266.803 75.097L237.141 84.3145C236.84 84.4058 236.566 84.5699 236.344 84.7922C236.121 85.0146 235.957 85.2883 235.866 85.5893L226.747 115.252C226.638 115.653 226.401 116.008 226.073 116.263C225.745 116.517 225.342 116.658 224.926 116.664C224.511 116.669 224.105 116.539 223.77 116.293C223.435 116.047 223.189 115.699 223.069 115.301L213.852 85.6383C213.761 85.3374 213.597 85.0636 213.374 84.8412C213.152 84.6189 212.878 84.4548 212.577 84.3635L182.914 75.2441C182.513 75.1354 182.158 74.8989 181.904 74.5705C181.649 74.2421 181.508 73.8396 181.503 73.424C181.497 73.0084 181.627 72.6023 181.873 72.2672C182.119 71.9321 182.467 71.6863 182.865 71.5669L212.528 62.3494C212.829 62.2582 213.103 62.0941 213.325 61.8717C213.547 61.6494 213.712 61.3756 213.803 61.0747L222.922 31.4121C223.031 31.0109 223.267 30.656 223.596 30.4013C223.924 30.1465 224.327 30.0057 224.742 30.0002C225.158 29.9946 225.564 30.1247 225.899 30.3706C226.234 30.6165 226.48 30.9649 226.599 31.363L235.817 61.0257C235.908 61.3266 236.072 61.6003 236.295 61.8227C236.517 62.0451 236.791 62.2091 237.092 62.3004Z",fill:"currentColor"}),jsx("path",{d:"M155.948 155.848L202.771 168.939C203.449 169.131 204.045 169.539 204.47 170.101C204.895 170.663 205.125 171.348 205.125 172.052C205.125 172.757 204.895 173.442 204.47 174.004C204.045 174.566 203.449 174.974 202.771 175.166L155.899 188.06C155.361 188.209 154.87 188.496 154.475 188.891C154.079 189.286 153.793 189.777 153.644 190.316L140.553 237.138C140.361 237.816 139.953 238.413 139.391 238.838C138.829 239.262 138.144 239.492 137.44 239.492C136.735 239.492 136.05 239.262 135.488 238.838C134.927 238.413 134.519 237.816 134.327 237.138L121.432 190.267C121.283 189.728 120.997 189.237 120.601 188.842C120.206 188.446 119.715 188.16 119.177 188.011L72.3537 174.92C71.676 174.728 71.0795 174.32 70.6547 173.759C70.2299 173.197 70 172.512 70 171.807C70 171.103 70.2299 170.418 70.6547 169.856C71.0795 169.294 71.676 168.886 72.3537 168.694L119.226 155.799C119.764 155.65 120.255 155.364 120.65 154.969C121.046 154.573 121.332 154.082 121.481 153.544L134.572 106.721C134.764 106.043 135.172 105.447 135.734 105.022C136.295 104.597 136.981 104.367 137.685 104.367C138.389 104.367 139.075 104.597 139.637 105.022C140.198 105.447 140.606 106.043 140.798 106.721L153.693 153.593C153.842 154.131 154.128 154.622 154.524 155.018C154.919 155.413 155.41 155.699 155.948 155.848Z",fill:"currentColor"}),jsx("path",{d:"M386.827 289.992C404.33 292.149 403.84 305.828 386.876 307.299C346.623 310.829 298.869 316.271 282.199 360.005C274.844 379.192 269.942 403.2 267.49 432.029C267.427 432.846 267.211 433.626 266.856 434.319C266.501 435.012 266.015 435.602 265.431 436.05C254.988 444.041 251.212 434.186 250.183 425.606C239.2 332.353 214.588 316.909 124.668 306.122C123.892 306.031 123.151 305.767 122.504 305.35C121.857 304.933 121.322 304.375 120.942 303.72C116.399 295.679 119.324 291.038 129.718 289.796C224.688 278.47 236.062 262.83 250.183 169.331C252.177 156.355 257.259 154.083 265.431 162.516C266.51 163.593 267.202 165.099 267.392 166.782C279.257 258.564 293.328 278.617 386.827 289.992Z",fill:"currentColor"})]})}var Cd=()=>jsxs("div",{className:"fk:flex fk:items-center fk:justify-center fk:gap-0.5",children:[jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-500 [animation-delay:-0.3s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600 [animation-delay:-0.15s]"}),jsx("div",{className:"fk:h-1.5 fk:w-1.5 fk:animate-bounce fk:rounded-full fk:bg-pink-600"})]}),Ja=Cd;function Hr({completion:e,onDiscard:t}){let{editor:n}=useEditor();return n?jsxs(Fragment,{children:[jsxs(s$1,{children:[jsxs(u$1,{className:"fk:gap-2 fk:px-4",value:"replace",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt({from:o.from,to:o.to},e).run();},children:[jsx(Check,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Replace selection"]}),jsxs(u$1,{className:"fk:gap-2 fk:px-4",value:"insert",onSelect:()=>{let{selection:o}=n.view.state;n.chain().focus().insertContentAt(o.to+1,e).run();},children:[jsx(TextQuote,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Insert below"]})]}),jsx(t$1,{}),jsx(s$1,{children:jsxs(u$1,{onSelect:t,value:"thrash",className:"fk:gap-2 fk:px-4",children:[jsx(TrashIcon,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"}),"Discard"]})})]}):null}var Md=[{value:"improve",label:"Improve writing",icon:RefreshCcwDot},{value:"fix",label:"Fix grammar",icon:CheckCheck},{value:"shorter",label:"Make shorter",icon:ArrowDownWideNarrow},{value:"longer",label:"Make longer",icon:WrapText}];function qr({onSelect:e}){let{editor:t}=useEditor();return t?jsxs(Fragment,{children:[jsx(s$1,{heading:"Edit or review selection",children:Md.map(n=>jsxs(u$1,{onSelect:o=>{let r=t.state.selection.content(),i=t.storage.markdown.serializer.serialize(r.content);e(i,o);},className:"fk:flex fk:gap-2 fk:px-4",value:n.value,children:[jsx(n.icon,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),n.label]},n.value))}),jsx(t$1,{}),jsx(s$1,{heading:"Use AI to do more",children:jsxs(u$1,{onSelect:()=>{let n=t.state.selection.from,o=getPrevText(t,n);e(o,"continue");},value:"continue",className:"fk:gap-2 fk:px-4",children:[jsx(StepForward,{className:"fk:h-4 fk:w-4 fk:text-foreground"}),"Continue writing"]})})]}):null}function Qa({onOpenChange:e}){let{editor:t}=useEditor(),[n,o]=useState(""),{projectId:r}=useParams(),{completion:i,complete:s,isLoading:a}=useCompletion({api:c$6(r).completion,fetch:async(l,u)=>{let f=await fetch(l,u);if(f.status===429)throw toast.error("You have reached your request limit for the day."),new Error("FK_AI_RATE_LIMIT");return f},onError:l=>{l.message!=="FK_AI_RATE_LIMIT"&&toast.error(l.message);}}),c=i.length>0;return t?jsxs(n$1,{className:"fk:w-[350px]",children:[c&&jsx("div",{className:"fk:flex fk:max-h-[400px]",children:jsx(w,{children:jsx("div",{className:"fk:prose fk:p-2 fk:px-4 fk:prose-sm",children:jsx(Hd,{children:i})})})}),a&&jsxs("div",{className:"fk:flex fk:h-12 fk:w-full fk:items-center fk:px-4 fk:text-sm fk:font-medium fk:text-muted-foreground fk:text-pink-600",children:[jsx(Qn,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:shrink-0 "}),"AI is thinking",jsx("div",{className:"fk:ml-2 fk:mt-1",children:jsx(Ja,{})})]}),!a&&jsxs(Fragment,{children:[jsxs("div",{className:"fk:relative",children:[jsx(p$1,{value:n,onValueChange:o,autoFocus:true,placeholder:c?"Tell AI what to do next":"Ask AI to edit or generate...",onFocus:()=>addAIHighlight(t)}),jsx(b$3,{size:"icon",className:"fk:absolute fk:right-2 fk:top-1/2 fk:h-6 w-6 fk:-translate-y-1/2 fk:rounded-full fk:bg-pink-600 fk:hover:bg-pink-800",onClick:()=>{if(i)return s(i,{body:{option:"zap",command:n}}).then(()=>o(""));let l=t.state.selection.content(),u=t.storage.markdown.serializer.serialize(l.content);s(u,{body:{option:"zap",command:n}}).then(()=>o(""));},children:jsx(ArrowUp,{className:"fk:h-4 fk:w-4"})})]}),jsx(q$1,{children:c?jsx(Hr,{onDiscard:()=>{t.chain().unsetHighlight().focus().run(),e(false);},completion:i}):jsx(qr,{onSelect:(l,u)=>s(l,{body:{option:u}})})})]})]}):null}function Gr({children:e,open:t,onOpenChange:n}){let{editor:o}=useEditor();return useEffect(()=>{o&&(t||removeAIHighlight(o));},[o,t]),o?jsxs(EditorBubble,{tippyOptions:{placement:t?"bottom-start":"top",onHidden:()=>{n(false),o.chain().unsetHighlight().run();}},className:"fk:flex fk:w-fit fk:max-w-[90vw] fk:overflow-hidden fk:rounded-md fk:border fk:border-muted fk:bg-background fk:shadow-xl",children:[t&&jsx(Qa,{open:t,onOpenChange:n}),!t&&jsxs(Fragment$1,{children:[jsxs(b$3,{className:"fk:gap-1 fk:rounded-none fk:text-pink-600",variant:"ghost",onClick:r=>{r.preventDefault(),n(true);},size:"sm",children:[jsx(Qn,{className:"fk:h-5 fk:w-5"}),"Ask AI"]}),e]})]}):null}var am=[...a,Ia];function Wa(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 lm(e){if(typeof e=="string"){let t=e.trim();if(!t)return;try{let n=JSON.parse(t);if(Wa(n))return n}catch{return}}if(Wa(e))return e}function Qr({control:e$1,defaultValue:t,fieldSchema:n,readOnly:o,setValue:r}){let{name:i,label:s,options:a}=n,[c$1,l]=useState(false),[u,f$1]=useState(false),[m,p]=useState(false),[d,g$1]=useState(false),h=useDebouncedCallback((b,E)=>{let A=b.getJSON();r(i,{...E,value:JSON.stringify(A)});},300);function v(b,E){r(i,{...E,disabled:b});}let y=b=>(console.log("Image uploader not yet implemented",b),Promise.resolve("https://via.placeholder.com/150"));return jsx(c,{control:e$1,name:i,render:({field:b})=>jsxs(e,{children:[jsx(f,{children:s}),a?.comment?jsx(h$1,{children:a.comment}):null,jsx(g,{children:jsx(EditorRoot,{children:jsxs(EditorContent,{className:"fk:relative fk:w-full fk:max-w-5xl fk:rounded-md fk:border fk:border-input fk:ring-offset-background fk:focus-within:outline-hidden fk:focus-within:ring-2 fk:focus-within:ring-ring fk:focus-within:ring-offset-2",editable:!o&&!b.value?.disabled,editorProps:{handleDOMEvents:{keydown:(E,A)=>handleCommandNavigation(A)},handlePaste:(E,A)=>handleImagePaste(E,A,y),handleDrop:(E,A,F,N)=>handleImageDrop(E,A,N,y),attributes:{class:"fk:prose prose-lg fk:dark:prose-invert fk:prose-headings:font-title fk:min-h-[150px] fk:font-default fk:rounded-md fk:focus:outline-hidden fk:max-w-full fk:bg-background "}},extensions:am,initialContent:lm(b.value?.value??t.value),immediatelyRender:true,onUpdate:({editor:E})=>{h(E,b.value);},slotAfter:jsx(ImageResizer,{}),children:[jsxs(EditorCommand,{className:"fk:z-50 fk:h-auto fk:max-h-[330px] fk:overflow-y-auto fk:rounded-md fk:border fk:border-muted fk:bg-background fk:px-1 fk:py-2 fk:shadow-md fk:transition-all fk:pointer-events-auto",children:[jsx(EditorCommandEmpty,{className:"fk:px-2 fk:text-muted-foreground",children:"No results"}),jsx(EditorCommandList,{children:Vr.map(E=>jsxs(EditorCommandItem,{value:E.title,onCommand:A=>E.command?.(A),className:"fk:flex fk:w-full fk:items-center fk:space-x-2 fk:rounded-md fk:px-2 fk:py-1 fk:text-left fk:text-sm fk:hover:bg-muted fk:aria-selected:bg-muted",children:[jsx("div",{className:"fk:flex fk:h-10 fk:w-10 fk:items-center fk:justify-center fk:rounded-md fk:border fk:border-muted fk:bg-background",children:E.icon}),jsxs("div",{children:[jsx("p",{className:"fk:font-medium",children:E.title}),jsx("p",{className:"fk:text-xs fk:text-muted-foreground",children:E.description})]})]},E.title))})]}),jsxs(Gr,{open:c$1,onOpenChange:l,children:[jsx(c$5,{orientation:"vertical"}),jsx(ja,{open:u,onOpenChange:f$1}),jsx(c$5,{orientation:"vertical"}),jsx(Va,{open:m,onOpenChange:p}),jsx(c$5,{orientation:"vertical"}),jsx(Ua,{}),jsx(c$5,{orientation:"vertical"}),jsx(qa,{}),jsx(c$5,{orientation:"vertical"}),jsx($a,{open:d,onOpenChange:g$1})]})]},`${i}:${b.value?.scope??t.scope}:${String(b.value?.disabled??t.disabled)}`)})}),jsx(a$6,{checked:b.value?.disabled??false,disabled:o,onChange:E=>{v(E,b.value);},scope:b.value?.scope}),jsx(i$1,{})]})})}var ym=So;function Zr({control:e$1,defaultValue:t,entityId:n$1,entityName:o,entityNamePlural:r,fieldSchema:i,readOnly:s,schema:a,setValue:c$1}){let{name:l$1,label:u,options:f$1,relationship:m}=i,{projectId:p}=useParams(),d=pe(),g$1=d$2(),{relationships:h}=c$2(),v=Gn(),y=useId(),b=useId(),E=useRef(null),A=useRef([]),F=useRef(null),N=useRef([]),S=useRef(""),D=useRef(t.knownAssetSortOrders??{}),[$,O]=useState(false),V=useMemo(()=>Cm(t.value),[t.value]),[R,B]=useState(V),[Z,te]=useState(()=>Object.keys(t.knownAssetSortOrders??zn(V)).length),[M,C]=useState(()=>Math.max(t.count??0,V[0]?.totalCount??0,V.length)),k=useMemo(()=>ca({attributeName:l$1,entityName:o,entityNamePlural:r,schema:a}),[o,r,l$1,a]),[_,{loading:U}]=useLazyQuery(gql`
|
|
385
385
|
${k.query}
|
|
386
|
-
`);bn(E,O),useEffect(()=>{let L=Nt(V);A.current=V.map(Y=>Y._id),N.current=[];let G={...t.knownAssetSortOrders??{},...zn(V)};D.current=G,te(Object.keys(G).length),C(Math.max(t.count??0,V[0]?.totalCount??0,V.length)),B(Y=>{let j=Nt(Y);return L===""&&j!==""&&x.current===j||j===L?Y:(x.current=L,V)});},[t.count,t.knownAssetSortOrders,V]),useEffect(()=>{let L=h[b]?.connect;if(!L)return;let G=L.map((S,P)=>el(S.value,S.sortOrder??P)).filter(S=>!!S),Y=Nt(G),j=Nt(R),ee=F.current;ee===j&&Y!==ee||(F.current=null,Y!==j&&B(G));},[b,h,R]),useEffect(()=>{let L=Nt(R);if(x.current===L)return;let G=R.map((ee,S)=>({_id:ee._id,sortOrder:S,value:{...ee,sortOrder:S}})),Y=R.map(ee=>ee._id),j=N.current.filter(ee=>!Y.includes(ee));x.current=L,g$1({type:"setRelationship",payload:{[b]:{connect:G,disconnect:j}}}),c$1(l$1,{...t,knownAssetSortOrders:D.current,relationships:{connect:G,disconnect:j},value:R});},[g$1,t,l$1,b,R,c$1]);let W=Math.max(M,Z),se=!!n$1&&W>Z,oe=useCallback(()=>{if(!n$1||U||!se)return;let L=Z+ym;_({variables:{where:{_id:{eq:n$1}},first:L}}).then(G=>{let Y=G.data?.[r],ee=(Array.isArray(Y)?Y[0]:void 0)?.[`${l$1}Connection`],S=Ao(ee),P=S[0]?.totalCount;if(typeof P=="number"&&C(P),S.length===0){C(Z);return}let H=Object.keys(D.current).length,le={...D.current,...zn(S)},ce=Object.keys(le).length;D.current=le,te(ce),(S.length<L||ce<=H)&&C(ce);for(let Q of S)A.current.includes(Q._id)||(A.current=[...A.current,Q._id]);B(Q=>{let on=new Set(Q.map(lo=>lo._id)),rn=new Set(N.current),Fn=S.filter(lo=>!on.has(lo._id)&&!rn.has(lo._id));if(Fn.length===0)return x.current="",[...Q];let Li=[...Q,...Fn];return F.current=Nt(Li),Li});}).catch(G=>{console.error("Error fetching more assets:",G);});},[n$1,r,_,se,U,Z,l$1]);function J(L){L.preventDefault(),L.stopPropagation(),!s&&d({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(R.length,W),entityName:m?.entity??"_asset",entityId:n$1,relationshipId:b,mode:"multiple",assetAccept:f$1?.accept}});}async function ae(L){if(L.preventDefault(),L.stopPropagation(),s)return;let G=await v({projectId:p,accept:f$1?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(Y=>{let j=new Set(Y.map(P=>P._id)),ee=G.map((P,H)=>({...P.asset,sortOrder:Y.length+H})).filter(P=>!j.has(P._id)),S=Wr([...Y,...ee]);return F.current=Nt(S),S});}function ke(L){B(G=>{let Y=Wr(G.filter(j=>j._id!==L));return A.current.includes(L)&&!N.current.includes(L)&&(N.current=[...N.current,L]),F.current=Nt(Y),Y});}function z(L,G){B(Y=>{let j=Y.findIndex(le=>le._id===L),ee=j+G;if(j<0||ee<0||ee>=Y.length)return Y;let S=[...Y],[P]=S.splice(j,1);if(!P)return Y;S.splice(ee,0,P);let H=Wr(S);return F.current=Nt(H),H});}let q=Math.max(R.length,W),he=R.slice(0,8);return jsx(c,{control:e$1,defaultValue:t,name:l$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:y,children:u}),f$1?.comment?jsx(h$1,{children:f$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${l$1}`,"aria-expanded":$,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${$?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),E.current?.focus(),O(true);},ref:E,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[$&&R.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[q," ",q===1?"asset":"assets",se?` (${R.length} loaded)`:""," selected"]}):R.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[he.map(L=>jsx(vm,{asset:L},L._id)),!$&&q>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",q-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:y,onClick:L=>{L.preventDefault(),L.stopPropagation(),O(G=>!G);},size:"icon",variant:"ghost",children:$?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:$?"Close":"Expand field"})})]})})]}),jsx(l,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:O,open:$,children:jsx(n,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${l$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",disabled:s,onClick:J,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",disabled:s,onClick:L=>{ae(L);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),R.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:R.map((L,G)=>jsx(bm,{asset:L,index:G,isFirst:G===0,isLast:G===R.length-1,moveAsset:z,readOnly:s,removeAsset:ke},L._id))}),se?jsx("div",{className:"fk:flex fk:justify-center fk:py-3 fk:pr-3",children:jsx(b$3,{className:"fk:h-8",disabled:U,onClick:L=>{L.preventDefault(),L.stopPropagation(),oe();},type:"button",variant:"outline",children:U?"Loading\u2026":`Load more (${Z} of ${W})`})}):null]}):null]})})})]})})}),jsx(i$1,{})]})})}function vm({asset:e}){return tl(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function bm({asset:e,index:t,isFirst:n,isLast:o,moveAsset:r,readOnly:i,removeAsset:s}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:tl(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:i||n,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:i||o,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",disabled:i,onClick:()=>s(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Cm(e){return Array.isArray(e)?e.map((t,n)=>el(t,n)).filter(t=>!!t).sort((t,n)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Nt(e){return e.map((t,n)=>`${t._id}:${t.sortOrder??n}`).join("|")}function Wr(e){return e.map((t,n)=>({...t,sortOrder:n}))}function el(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let n=e;return {_id:String(n._id??""),path:String(n.path??""),originalFilename:String(n.originalFilename??""),size:Number(n.size??0),mimeType:String(n.mimeType??""),lqip:String(n.lqip??""),width:Number(n.width??0),height:Number(n.height??0),sortOrder:n.sortOrder??t,totalCount:typeof n.totalCount=="number"?n.totalCount:void 0}}function tl(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function ol({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function zo({column:e,title:t,className:n}){if(!e.getCanSort())return jsx("div",{className:a$1("fk:flex fk:items-center",n),children:t});let o=e.getIsSorted()==="asc",r=e.getIsSorted()==="desc";return jsxs("div",{className:a$1("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",n),children:[jsx("span",{className:"fk:truncate",children:t}),jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsx("button",{"aria-label":`Sort ${t}`,className:"fk:inline-flex fk:shrink-0 fk:items-center fk:justify-center fk:rounded-sm fk:p-0.5 fk:text-muted-foreground fk:outline-hidden fk:hover:bg-accent fk:hover:text-accent-foreground fk:focus-visible:ring-1 fk:focus-visible:ring-ring",type:"button",children:jsx(ChevronDown,{className:"fk:h-3.5 fk:w-3.5"})})}),jsxs(f$2,{align:"end",className:"fk:w-44",children:[jsxs(h$2,{"aria-checked":o,className:a$1(o&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(o){e.clearSorting();return}e.toggleSorting(false);},role:"menuitemcheckbox",children:[jsx(ArrowUp,{className:a$1("fk:h-4 fk:w-4",o&&"fk:text-white")}),"Sort Ascending"]}),jsxs(h$2,{"aria-checked":r,className:a$1(r&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(r){e.clearSorting();return}e.toggleSorting(true);},role:"menuitemcheckbox",children:[jsx(ArrowDown,{className:a$1("fk:h-4 fk:w-4",r&&"fk:text-white")}),"Sort Descending"]})]})]})]})}var Em=new Set(["text","number","datetime","switch","select"]);function Yn({attributesSchema:e,checkboxSelect:t,actionsComponent:n,enableColumnSorting:o=false}){let{getContributionPointConfig:r}=d(),[,i]=b(),s=vn(e,i.user?.spaces),a={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"select",switch:"boolean",text:"text",textarea:"text"},c={boolean:a$b,date:a$a,datetime:a$e,editor:b$7,asset:a$d,number:a$a,relationship:a$a,select:a$c,switch:a$b,text:a$a,textarea:a$a,tags:ol},l=s.map(d=>{if(d.name==="_updatedAt")return null;let g=(d.inputType==="relationship"&&d.relationship?.entity==="_asset"?"asset":void 0)??d.previewType??a[d.inputType],h=r("previewFields",[g])?.[0]?.component??c[g]??c.text;if(d.hidden===true)return null;let v=g==="tags",y=o&&d.scope==="global"&&Em.has(d.inputType);return {accessorKey:d.name,filterFn:(b,E,A)=>v?true:(Array.isArray(A)?A:[A]).includes(b.getValue(E)),header:({column:b})=>y?jsx(zo,{column:b,title:d.label}):jsx("div",{className:"fk:flex fk:items-center",children:d.label}),cell:({row:b})=>{let E=h;return g==="select"?jsx(E,{value:b.getValue(d.name),options:d.options}):g==="assetPreviewField"?jsx(E,{value:b.original}):jsx(E,{value:b.getValue(d.name)})},enableSorting:y,enableHiding:true,meta:{label:d.label},size:d.options?.size??150}}).filter(d=>d!==null),u={id:"actions",cell:({row:d})=>n?n(d):null,size:80},f={accessorKey:"_updatedAt",header:({column:d})=>o?jsx(zo,{column:d,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:d})=>jsx(a$e,{value:d.getValue("_updatedAt")}),enableSorting:o,enableHiding:false,meta:{label:"Updated At"},size:220},m={id:"select",cell:({row:d,table:g})=>jsx(j$1,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:h=>{g.toggleAllPageRowsSelected(false),d.toggleSelected(!!h);}}),enableSorting:false,enableHiding:false,size:50},p={id:"select",header:({table:d})=>jsx(j$1,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:d.getIsAllPageRowsSelected()||d.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:g=>{d.toggleAllPageRowsSelected(!!g);}}),cell:({row:d})=>jsx(j$1,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:g=>{d.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[m]:[],...t==="multiple"?[p]:[],...n?[u]:[],...l,f]}var Im=36,Lm=15,il=40;function ll(e){if(!e)return;let t=e.split(/\s+/);if(t.includes("fk:h-20"))return 80;if(t.includes("fk:h-10"))return 40;if(t.includes("fk:h-9"))return 36}function Mm(e,t){return e??ll(t)??Im}function _m(e){return Math.max(600,e)}function eo({classNames:e,columns:t$1,data:n,entityName:o$1,hasMore:r=false,initialSelectionState:i,isLoadingMore:s$1=false,onEntitySelectionChange:a,onLoadMore:c,onScroll:l,onSortingChange:u$1,pageSize:f,rowHeightEstimate:m,rowAdditionState:p$1,rowDeletionState:d,scrollToTopKey:g,sorting:h,toolbarComponent:v}){let y=useRef(null),{schemaErrorMessage:b}=Kt(),[E,A]=useState(i??{}),[F,N]=useState({}),[x,D]=useState([]),[$,O]=useState([]),V=h??$;useEffect(()=>{y.current?.scrollTo({top:0});},[o$1,g]),useEffect(()=>{if(!i)return;let z=Object.keys(E).sort().join(","),q=Object.keys(i).sort().join(",");z!==q&&A(i);},[i,E]);function R(z){if(u$1){u$1(z);return}O(z);}let B=useReactTable({data:n,columns:t$1,state:{sorting:V,columnVisibility:F,rowSelection:E,columnFilters:x},initialState:{pagination:{pageSize:f??50}},enableRowSelection:true,onRowSelectionChange:ae,onSortingChange:R,onColumnFiltersChange:D,onColumnVisibilityChange:N,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:z=>z._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:z=>Om(z,d,p$1)}}),{rows:Z}=B.getRowModel(),te=Mm(m,e?.row),M=ll(e?.row)!=null,C=useVirtualizer({count:Z.length,estimateSize:()=>te,getItemKey:z=>Z[z]?.id??z,getScrollElement:()=>y.current,overscan:Lm,scrollMargin:il}),k=C.getVirtualItems(),{paddingTop:_,paddingBottom:U}=$m(k,C.getTotalSize(),il),W=useRef(c),se=useRef(r),oe=useRef(s$1);W.current=c,se.current=r,oe.current=s$1;let J=useCallback(z=>{if(!W.current||!se.current||oe.current)return;let q=z??y.current;if(!q)return;let{scrollHeight:he,scrollTop:L,clientHeight:G}=q;he-L-G>=_m(G)||(oe.current=true,W.current());},[]);useEffect(()=>{J();},[J,Z.length,r,s$1]);function ae(z){let q=Object.keys(typeof z=="function"?z(E):z);A(z),a?.(q);}function ke(z){l?.(z),J(z.currentTarget);}return b?jsx(Fragment,{}):jsxs("div",{className:a$1("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:min-w-0 fk:flex-col fk:gap-4",e?.wrapper),children:[v&&v(B),jsx("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1 fk:-mb-px",children:jsx(a$8,{delayDuration:400,children:jsxs(o,{className:a$1("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:ke,ref:y,children:[jsx(p,{className:"fk:sticky fk:top-0 fk:z-20 fk:grid",children:B.getHeaderGroups().map(z=>jsx(s,{className:"fk:flex fk:w-full",children:z.headers.map(q=>jsxs(t,{className:a$1("fk:flex fk:items-center",q.column.id==="actions"&&"fk:pl-0"),colSpan:q.colSpan,style:q.getSize()?{width:`${q.getSize().toString()}px`}:{},children:[q.isPlaceholder?null:flexRender(q.column.columnDef.header,q.getContext()),s$1?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-10.25 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-4",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null]},q.id))},z.id))}),jsx(q,{className:"fk:grid fk:relative",children:Z.length===0?jsx(s,{children:jsx(u,{className:"fk:h-24 fk:text-center",colSpan:t$1.length,children:"No results."})}):jsxs(Fragment,{children:[_>0?jsx(sl,{height:_}):null,k.map(z=>{let q=Z[z.index];return jsx(s,{className:a$1(B.options.meta.getRowBackground(q),"fk:flex fk:w-full fk:overflow-hidden fk:transition-none",!M&&m==null&&"fk:h-9",e?.row),"data-index":z.index,"data-state":q.getIsSelected()&&"selected",style:{height:`${te.toString()}px`},children:q.getVisibleCells().map(he=>jsx(u,{className:a$1("fk:flex fk:items-center fk:truncate",he.column.id==="actions"&&"fk:pl-1!"),style:{width:he.column.getSize()},children:flexRender(he.column.columnDef.cell,he.getContext())},he.id))},z.key)}),U>0?jsx(sl,{height:U}):null]})})]})})})]})}function $m(e,t,n){if(e.length===0)return {paddingTop:0,paddingBottom:0};let o=e[0]?.start??0,r=e[e.length-1]?.end??0;return {paddingTop:Math.max(0,o-n),paddingBottom:Math.max(0,t-(r-n))}}function sl({height:e}){return jsx("tr",{"aria-hidden":true,className:"fk:pointer-events-none fk:border-0",style:{display:"block",height:`${e.toString()}px`},children:jsx("td",{className:"fk:p-0 fk:border-0"})})}function Om(e,t,n){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":n?.some(o=>o._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function cl({action:e,row:t}){let n=t.original._id;function o(){e(n);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:o,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var Km=25;function ni({control:e$1,defaultScope:t,defaultValue:n$1,entityId:o,entityName:r,fieldSchema:i,readOnly:s,schema:a,scope:c$1,setValue:l$1}){let[u,f$1]=useState(false),m=useRef(null);bn(m,f$1);let[p,d]=useState([]),{name:g$1,label:h,options:v,relationship:y}=i,b=y?.entity??g$1,E=pe(),A=d$2(),{relationships:F}=c$2(),N=useId(),x=useId(),D=find(propEq(b,"name"))(a),$=D?.attributes??[],V=find(propEq(r,"name"))(a)?.name??"",R,B=$.find(S=>S.relationship?.entity===V);B&&(R=B.name);let Z=e$4(D)?.name??"",te=useMemo(()=>n$1.value?Ym({data:n$1.value,defaultScope:t,relationshipEntitySchema:D,scope:c$1}):[],[t,n$1,Z,D,c$1]),M=la({relatedEntityName:b,scope:c$1,schema:a}),k=p.length?p.slice(0,12).map(S=>S[Z]):[],_=Math.max(p.length,n$1.count??0)>k.length,[U,{loading:W,data:se}]=useLazyQuery(gql`
|
|
386
|
+
`);bn(E,O),useEffect(()=>{let L=Nt(V);A.current=V.map(Y=>Y._id),N.current=[];let G={...t.knownAssetSortOrders??{},...zn(V)};D.current=G,te(Object.keys(G).length),C(Math.max(t.count??0,V[0]?.totalCount??0,V.length)),B(Y=>{let j=Nt(Y);return L===""&&j!==""&&S.current===j||j===L?Y:(S.current=L,V)});},[t.count,t.knownAssetSortOrders,V]),useEffect(()=>{let L=h[b]?.connect;if(!L)return;let G=L.map((x,P)=>el(x.value,x.sortOrder??P)).filter(x=>!!x),Y=Nt(G),j=Nt(R),ee=F.current;ee===j&&Y!==ee||(F.current=null,Y!==j&&B(G));},[b,h,R]),useEffect(()=>{let L=Nt(R);if(S.current===L)return;let G=R.map((ee,x)=>({_id:ee._id,sortOrder:x,value:{...ee,sortOrder:x}})),Y=R.map(ee=>ee._id),j=N.current.filter(ee=>!Y.includes(ee));S.current=L,g$1({type:"setRelationship",payload:{[b]:{connect:G,disconnect:j}}}),c$1(l$1,{...t,knownAssetSortOrders:D.current,relationships:{connect:G,disconnect:j},value:R});},[g$1,t,l$1,b,R,c$1]);let W=Math.max(M,Z),se=!!n$1&&W>Z,oe=useCallback(()=>{if(!n$1||U||!se)return;let L=Z+ym;_({variables:{where:{_id:{eq:n$1}},first:L}}).then(G=>{let Y=G.data?.[r],ee=(Array.isArray(Y)?Y[0]:void 0)?.[`${l$1}Connection`],x=Ao(ee),P=x[0]?.totalCount;if(typeof P=="number"&&C(P),x.length===0){C(Z);return}let H=Object.keys(D.current).length,le={...D.current,...zn(x)},ce=Object.keys(le).length;D.current=le,te(ce),(x.length<L||ce<=H)&&C(ce);for(let Q of x)A.current.includes(Q._id)||(A.current=[...A.current,Q._id]);B(Q=>{let on=new Set(Q.map(lo=>lo._id)),rn=new Set(N.current),Fn=x.filter(lo=>!on.has(lo._id)&&!rn.has(lo._id));if(Fn.length===0)return S.current="",[...Q];let Li=[...Q,...Fn];return F.current=Nt(Li),Li});}).catch(G=>{console.error("Error fetching more assets:",G);});},[n$1,r,_,se,U,Z,l$1]);function J(L){L.preventDefault(),L.stopPropagation(),!s&&d({type:"EditRelationship",payload:{connectedEntitiesCount:Math.max(R.length,W),entityName:m?.entity??"_asset",entityId:n$1,relationshipId:b,mode:"multiple",assetAccept:f$1?.accept}});}async function ae(L){if(L.preventDefault(),L.stopPropagation(),s)return;let G=await v({projectId:p,accept:f$1?.accept??"image/*",multiple:true,maxBytes:4*1024*1024});B(Y=>{let j=new Set(Y.map(P=>P._id)),ee=G.map((P,H)=>({...P.asset,sortOrder:Y.length+H})).filter(P=>!j.has(P._id)),x=Wr([...Y,...ee]);return F.current=Nt(x),x});}function ke(L){B(G=>{let Y=Wr(G.filter(j=>j._id!==L));return A.current.includes(L)&&!N.current.includes(L)&&(N.current=[...N.current,L]),F.current=Nt(Y),Y});}function z(L,G){B(Y=>{let j=Y.findIndex(le=>le._id===L),ee=j+G;if(j<0||ee<0||ee>=Y.length)return Y;let x=[...Y],[P]=x.splice(j,1);if(!P)return Y;x.splice(ee,0,P);let H=Wr(x);return F.current=Nt(H),H});}let q=Math.max(R.length,W),he=R.slice(0,8);return jsx(c,{control:e$1,defaultValue:t,name:l$1,render:()=>jsxs(e,{children:[jsx(f,{htmlFor:y,children:u}),f$1?.comment?jsx(h$1,{children:f$1.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-h-9.5 fk:text-sm",children:jsx("div",{"aria-controls":`asset-relationship-dropdown-${l$1}`,"aria-expanded":$,className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:px-2.5 fk:py-0.5 fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${$?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:L=>{L.preventDefault(),L.stopPropagation(),E.current?.focus(),O(true);},ref:E,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:items-center fk:gap-2 fk:pr-9",children:[$&&R.length>0?jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[q," ",q===1?"asset":"assets",se?` (${R.length} loaded)`:""," selected"]}):R.length>0?jsxs("div",{className:"fk:flex fk:min-h-9 fk:flex-wrap fk:gap-2",children:[he.map(L=>jsx(vm,{asset:L},L._id)),!$&&q>8?jsxs("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted fk:text-xs fk:text-muted-foreground",children:["+",q-8]}):null]}):jsxs("div",{className:"fk:flex fk:h-9 fk:items-center fk:text-muted-foreground",children:[jsx(Image,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Select or upload assets"]}),jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:y,onClick:L=>{L.preventDefault(),L.stopPropagation(),O(G=>!G);},size:"icon",variant:"ghost",children:$?jsx(X,{className:"fk:h-4 fk:w-4"}):jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:$?"Close":"Expand field"})})]})})]}),jsx(l,{className:"fk:w-full fk:space-y-2 fk:ml-0!",onOpenChange:O,open:$,children:jsx(n,{className:"fk:w-full",children:jsxs("div",{className:"fk:flex fk:h-[350px] fk:flex-col fk:gap-3",id:`asset-relationship-dropdown-${l$1}`,children:[jsxs("div",{className:"fk:flex fk:gap-2",children:[jsxs(b$3,{className:"fk:h-8",disabled:s,onClick:J,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Select assets"]}),jsxs(b$3,{className:"fk:h-8",disabled:s,onClick:L=>{ae(L);},variant:"outline",children:[jsx(Upload,{className:"fk:h-4 fk:w-4 fk:mr-2"}),"Upload assets"]})]}),R.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:R.map((L,G)=>jsx(bm,{asset:L,index:G,isFirst:G===0,isLast:G===R.length-1,moveAsset:z,readOnly:s,removeAsset:ke},L._id))}),se?jsx("div",{className:"fk:flex fk:justify-center fk:py-3 fk:pr-3",children:jsx(b$3,{className:"fk:h-8",disabled:U,onClick:L=>{L.preventDefault(),L.stopPropagation(),oe();},type:"button",variant:"outline",children:U?"Loading\u2026":`Load more (${Z} of ${W})`})}):null]}):null]})})})]})})}),jsx(i$1,{})]})})}function vm({asset:e}){return tl(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-9 fk:w-9 fk:rounded-sm fk:bg-muted fk:object-cover",src:`${b$4}${e.path}?w=128&h=128&f=webp`}):jsx("div",{className:"fk:flex fk:h-9 fk:w-9 fk:items-center fk:justify-center fk:rounded-sm fk:bg-muted",children:jsx(Image,{className:"fk:h-4 fk:w-4 fk:text-muted-foreground"})})}function bm({asset:e,index:t,isFirst:n,isLast:o,moveAsset:r,readOnly:i,removeAsset:s}){return jsxs("div",{className:"fk:relative fk:rounded-md fk:border fk:border-input fk:bg-background fk:p-2",children:[jsx("div",{className:"fk:aspect-square fk:overflow-hidden fk:rounded-sm fk:bg-muted",children:tl(e)?jsx("img",{alt:e.originalFilename||"Asset",className:"fk:h-full fk:w-full fk:object-cover",src:`${b$4}${e.path}?w=320&h=320&f=webp`}):jsx("div",{className:"fk:flex fk:h-full fk:w-full fk:items-center fk:justify-center",children:jsx(Image,{className:"fk:h-8 fk:w-8 fk:text-muted-foreground"})})}),jsxs("div",{className:"fk:mt-2 fk:truncate fk:text-xs",title:e.originalFilename,children:[t+1,". ",e.originalFilename||e.path]}),jsxs("div",{className:"fk:mt-2 fk:flex fk:gap-1",children:[jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:i||n,onClick:()=>r(e._id,-1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowUp,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:h-7 fk:w-7",disabled:i||o,onClick:()=>r(e._id,1),size:"icon",type:"button",variant:"ghost",children:jsx(ArrowDown,{className:"fk:h-3.5 fk:w-3.5"})}),jsx(b$3,{className:"fk:ml-auto fk:h-7 fk:w-7",disabled:i,onClick:()=>s(e._id),size:"icon",type:"button",variant:"ghost",children:jsx(X,{className:"fk:h-3.5 fk:w-3.5"})})]})]})}function Cm(e){return Array.isArray(e)?e.map((t,n)=>el(t,n)).filter(t=>!!t).sort((t,n)=>(t.sortOrder??Number.MAX_SAFE_INTEGER)-(n.sortOrder??Number.MAX_SAFE_INTEGER)):[]}function Nt(e){return e.map((t,n)=>`${t._id}:${t.sortOrder??n}`).join("|")}function Wr(e){return e.map((t,n)=>({...t,sortOrder:n}))}function el(e,t){if(!e||typeof e!="object"||!("_id"in e)||!("path"in e))return null;let n=e;return {_id:String(n._id??""),path:String(n.path??""),originalFilename:String(n.originalFilename??""),size:Number(n.size??0),mimeType:String(n.mimeType??""),lqip:String(n.lqip??""),width:Number(n.width??0),height:Number(n.height??0),sortOrder:n.sortOrder??t,totalCount:typeof n.totalCount=="number"?n.totalCount:void 0}}function tl(e){return !!(e.mimeType&&e.mimeType.startsWith("image/")||/\.(png|jpe?g|gif|webp|avif|svg)$/i.test(e.path))}function ol({value:e}){return !e||!e.split(",").length?null:jsx("div",{className:"fk:flex fk:flex-wrap fk:gap-1 fk:max-w-full truncate",children:e.split(",").map(t=>jsx(b$6,{className:"fk:px-2.5 fk:py-0 fk:font-normal fk:text-[0.6875rem] fk:leading-4",variant:"secondary",children:t},t))})}function zo({column:e,title:t,className:n}){if(!e.getCanSort())return jsx("div",{className:a$1("fk:flex fk:items-center",n),children:t});let o=e.getIsSorted()==="asc",r=e.getIsSorted()==="desc";return jsxs("div",{className:a$1("fk:flex fk:w-full fk:items-center fk:justify-between fk:gap-1",n),children:[jsx("span",{className:"fk:truncate",children:t}),jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsx("button",{"aria-label":`Sort ${t}`,className:"fk:inline-flex fk:shrink-0 fk:items-center fk:justify-center fk:rounded-sm fk:p-0.5 fk:text-muted-foreground fk:outline-hidden fk:hover:bg-accent fk:hover:text-accent-foreground fk:focus-visible:ring-1 fk:focus-visible:ring-ring",type:"button",children:jsx(ChevronDown,{className:"fk:h-3.5 fk:w-3.5"})})}),jsxs(f$2,{align:"end",className:"fk:w-44",children:[jsxs(h$2,{"aria-checked":o,className:a$1(o&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(o){e.clearSorting();return}e.toggleSorting(false);},role:"menuitemcheckbox",children:[jsx(ArrowUp,{className:a$1("fk:h-4 fk:w-4",o&&"fk:text-white")}),"Sort Ascending"]}),jsxs(h$2,{"aria-checked":r,className:a$1(r&&"fk:bg-accent fk:text-accent-foreground"),onSelect:()=>{if(r){e.clearSorting();return}e.toggleSorting(true);},role:"menuitemcheckbox",children:[jsx(ArrowDown,{className:a$1("fk:h-4 fk:w-4",r&&"fk:text-white")}),"Sort Descending"]})]})]})]})}var Em=new Set(["text","number","datetime","switch","select"]);function Yn({attributesSchema:e,checkboxSelect:t,actionsComponent:n,enableColumnSorting:o=false}){let{getContributionPointConfig:r}=d(),[,i]=b(),s=vn(e,i.user?.spaces),a={datetime:"datetime",editor:"editor",asset:"asset",number:"text",relationship:"text",select:"select",switch:"boolean",text:"text",textarea:"text"},c={boolean:a$b,date:a$a,datetime:a$e,editor:b$7,asset:a$d,number:a$a,relationship:a$a,select:a$c,switch:a$b,text:a$a,textarea:a$a,tags:ol},l=s.map(d=>{if(d.name==="_updatedAt")return null;let g=(d.inputType==="relationship"&&d.relationship?.entity==="_asset"?"asset":void 0)??d.previewType??a[d.inputType],h=r("previewFields",[g])?.[0]?.component??c[g]??c.text;if(d.hidden===true)return null;let v=g==="tags",y=o&&d.scope==="global"&&Em.has(d.inputType);return {accessorKey:d.name,filterFn:(b,E,A)=>v?true:(Array.isArray(A)?A:[A]).includes(b.getValue(E)),header:({column:b})=>y?jsx(zo,{column:b,title:d.label}):jsx("div",{className:"fk:flex fk:items-center",children:d.label}),cell:({row:b})=>{let E=h;return g==="select"?jsx(E,{value:b.getValue(d.name),options:d.options}):g==="assetPreviewField"?jsx(E,{value:b.original}):jsx(E,{value:b.getValue(d.name)})},enableSorting:y,enableHiding:true,meta:{label:d.label},size:d.options?.size??150}}).filter(d=>d!==null),u={id:"actions",cell:({row:d})=>n?n(d):null,size:80},f={accessorKey:"_updatedAt",header:({column:d})=>o?jsx(zo,{column:d,title:"Updated At"}):jsx("div",{className:"fk:flex fk:items-center",children:"Updated At"}),cell:({row:d})=>jsx(a$e,{value:d.getValue("_updatedAt")}),enableSorting:o,enableHiding:false,meta:{label:"Updated At"},size:220},m={id:"select",cell:({row:d,table:g})=>jsx(j$1,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:h=>{g.toggleAllPageRowsSelected(false),d.toggleSelected(!!h);}}),enableSorting:false,enableHiding:false,size:50},p={id:"select",header:({table:d})=>jsx(j$1,{className:"fk:dark:bg-white/15","aria-label":"Select all",checked:d.getIsAllPageRowsSelected()||d.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:g=>{d.toggleAllPageRowsSelected(!!g);}}),cell:({row:d})=>jsx(j$1,{"aria-label":"Select row",checked:d.getIsSelected(),onCheckedChange:g=>{d.toggleSelected(!!g);}}),enableSorting:false,enableHiding:false,size:50};return [...t==="single"?[m]:[],...t==="multiple"?[p]:[],...n?[u]:[],...l,f]}var Im=36,Lm=15,il=40;function ll(e){if(!e)return;let t=e.split(/\s+/);if(t.includes("fk:h-20"))return 80;if(t.includes("fk:h-10"))return 40;if(t.includes("fk:h-9"))return 36}function Mm(e,t){return e??ll(t)??Im}function _m(e){return Math.max(600,e)}function eo({classNames:e,columns:t$1,data:n,entityName:o$1,hasMore:r=false,initialSelectionState:i,isLoadingMore:s$1=false,onEntitySelectionChange:a,onLoadMore:c,onScroll:l,onSortingChange:u$1,pageSize:f,rowHeightEstimate:m,rowAdditionState:p$1,rowDeletionState:d,scrollToTopKey:g,sorting:h,toolbarComponent:v}){let y=useRef(null),{schemaErrorMessage:b}=Kt(),[E,A]=useState(i??{}),[F,N]=useState({}),[S,D]=useState([]),[$,O]=useState([]),V=h??$;useEffect(()=>{y.current?.scrollTo({top:0});},[o$1,g]),useEffect(()=>{if(!i)return;let z=Object.keys(E).sort().join(","),q=Object.keys(i).sort().join(",");z!==q&&A(i);},[i,E]);function R(z){if(u$1){u$1(z);return}O(z);}let B=useReactTable({data:n,columns:t$1,state:{sorting:V,columnVisibility:F,rowSelection:E,columnFilters:S},initialState:{pagination:{pageSize:f??50}},enableRowSelection:true,onRowSelectionChange:ae,onSortingChange:R,onColumnFiltersChange:D,onColumnVisibilityChange:N,getCoreRowModel:getCoreRowModel(),getFilteredRowModel:getFilteredRowModel(),getPaginationRowModel:getPaginationRowModel(),getSortedRowModel:getSortedRowModel(),getRowId:z=>z._id,manualFiltering:true,manualPagination:true,manualSorting:true,meta:{getRowBackground:z=>Om(z,d,p$1)}}),{rows:Z}=B.getRowModel(),te=Mm(m,e?.row),M=ll(e?.row)!=null,C=useVirtualizer({count:Z.length,estimateSize:()=>te,getItemKey:z=>Z[z]?.id??z,getScrollElement:()=>y.current,overscan:Lm,scrollMargin:il}),k=C.getVirtualItems(),{paddingTop:_,paddingBottom:U}=$m(k,C.getTotalSize(),il),W=useRef(c),se=useRef(r),oe=useRef(s$1);W.current=c,se.current=r,oe.current=s$1;let J=useCallback(z=>{if(!W.current||!se.current||oe.current)return;let q=z??y.current;if(!q)return;let{scrollHeight:he,scrollTop:L,clientHeight:G}=q;he-L-G>=_m(G)||(oe.current=true,W.current());},[]);useEffect(()=>{J();},[J,Z.length,r,s$1]);function ae(z){let q=Object.keys(typeof z=="function"?z(E):z);A(z),a?.(q);}function ke(z){l?.(z),J(z.currentTarget);}return b?jsx(Fragment,{}):jsxs("div",{className:a$1("fk:flex fk:h-full fk:min-h-0 fk:w-full fk:min-w-0 fk:flex-col fk:gap-4",e?.wrapper),children:[v&&v(B),jsx("div",{className:"fk:relative fk:min-h-0 fk:min-w-0 fk:flex-1 fk:-mb-px",children:jsx(a$8,{delayDuration:400,children:jsxs(o,{className:a$1("fk:grid fk:pb-20",e?.table),containerClassName:e?.tableContainer,onScroll:ke,ref:y,children:[jsx(p,{className:"fk:sticky fk:top-0 fk:z-20 fk:grid",children:B.getHeaderGroups().map(z=>jsx(s,{className:"fk:flex fk:w-full",children:z.headers.map(q=>jsxs(t,{className:a$1("fk:flex fk:items-center",q.column.id==="actions"&&"fk:pl-0"),colSpan:q.colSpan,style:q.getSize()?{width:`${q.getSize().toString()}px`}:{},children:[q.isPlaceholder?null:flexRender(q.column.columnDef.header,q.getContext()),s$1?jsx("div",{"aria-hidden":true,className:"fk:pointer-events-none fk:absolute fk:top-10.25 fk:right-px fk:left-px fk:z-20 fk:h-0.5 fk:overflow-hidden fk:opacity-4",children:jsx("div",{className:"fk:animate-progress fk:h-full fk:w-full fk:bg-foreground"})}):null]},q.id))},z.id))}),jsx(q,{className:"fk:grid fk:relative",children:Z.length===0?jsx(s,{children:jsx(u,{className:"fk:h-24 fk:text-center",colSpan:t$1.length,children:"No results."})}):jsxs(Fragment,{children:[_>0?jsx(sl,{height:_}):null,k.map(z=>{let q=Z[z.index];return jsx(s,{className:a$1(B.options.meta.getRowBackground(q),"fk:flex fk:w-full fk:overflow-hidden fk:transition-none",!M&&m==null&&"fk:h-9",e?.row),"data-index":z.index,"data-state":q.getIsSelected()&&"selected",style:{height:`${te.toString()}px`},children:q.getVisibleCells().map(he=>jsx(u,{className:a$1("fk:flex fk:items-center fk:truncate",he.column.id==="actions"&&"fk:pl-1!"),style:{width:he.column.getSize()},children:flexRender(he.column.columnDef.cell,he.getContext())},he.id))},z.key)}),U>0?jsx(sl,{height:U}):null]})})]})})})]})}function $m(e,t,n){if(e.length===0)return {paddingTop:0,paddingBottom:0};let o=e[0]?.start??0,r=e[e.length-1]?.end??0;return {paddingTop:Math.max(0,o-n),paddingBottom:Math.max(0,t-(r-n))}}function sl({height:e}){return jsx("tr",{"aria-hidden":true,className:"fk:pointer-events-none fk:border-0",style:{display:"block",height:`${e.toString()}px`},children:jsx("td",{className:"fk:p-0 fk:border-0"})})}function Om(e,t,n){return t?.includes(e.original._id)?"fk:bg-row-removed fk:hover:bg-row-removed-hover":n?.some(o=>o._id===e.original._id)?"fk:bg-row-added fk:hover:bg-row-added-hover":""}function cl({action:e,row:t}){let n=t.original._id;function o(){e(n);}return jsx("div",{className:"fk:flex fk:items-center",children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:o,variant:"ghost",children:[jsx(Trash2,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]})})}var Km=25;function ni({control:e$1,defaultScope:t,defaultValue:n$1,entityId:o,entityName:r,fieldSchema:i,readOnly:s,schema:a,scope:c$1,setValue:l$1}){let[u,f$1]=useState(false),m=useRef(null);bn(m,f$1);let[p,d]=useState([]),{name:g$1,label:h,options:v,relationship:y}=i,b=y?.entity??g$1,E=pe(),A=d$2(),{relationships:F}=c$2(),N=useId(),S=useId(),D=find(propEq(b,"name"))(a),$=D?.attributes??[],V=find(propEq(r,"name"))(a)?.name??"",R,B=$.find(x=>x.relationship?.entity===V);B&&(R=B.name);let Z=e$4(D)?.name??"",te=useMemo(()=>n$1.value?Ym({data:n$1.value,defaultScope:t,relationshipEntitySchema:D,scope:c$1}):[],[t,n$1,Z,D,c$1]),M=la({relatedEntityName:b,scope:c$1,schema:a}),k=p.length?p.slice(0,12).map(x=>x[Z]):[],_=Math.max(p.length,n$1.count??0)>k.length,[U,{loading:W,data:se}]=useLazyQuery(gql`
|
|
387
387
|
${M.query}
|
|
388
|
-
`),oe=Yn({attributesSchema:D?.attributes??[],actionsComponent:s?void 0:S=>Zm({appDispatch:A,relationshipId:x,relationships:F,row:S,setRows:d})});useEffect(()=>{d(te),n$1.value!==""&&A({type:"setRelationship",payload:{[x]:{connect:[],disconnect:[]}}});},[A,se,te,x,n$1,c$1]),useEffect(()=>{l$1(g$1,{...n$1,relationships:F[x]});},[n$1,F,x,l$1,g$1]),useEffect(()=>{let P=(F[x]?.connect??[]).map(({value:H})=>H);d(uniqBy(prop("_id"),[...P,...te]));},[se,n$1.count,te,F,x]);let J=F[x]?.connect??[],ae=F[x]?.disconnect??[],ke=new Set(te.map(S=>S._id)),z=new Set(ae),q=J.filter(S=>!ke.has(S._id)||z.has(S._id)).length,he=ae.length,L=n$1.count??0,G=Math.max(0,Math.max(L,te.length)+q-he),Y=L>0&&p.length>0&&p.length<L,j=useCallback(()=>{W||U({variables:{limit:Km,offset:p.length,where:R?{[R]:{some:{_id:{eq:o}}}}:{}}}).then(({data:S})=>{if(!S)return;let P=To(D?.plural??"",c$1,S,a);d(uniqBy(prop("_id"),[...te,...P.results]));}).catch(S=>{console.error("Error fetching more data:",S);});},[R,o,U,te,W,D?.plural,p.length,a,c$1]);function ee(S){S.preventDefault(),!s&&E({type:"EditRelationship",payload:{connectedEntitiesCount:te.length,connectionName:R,entityName:b,entityId:o,relationshipId:x,mode:y?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:n$1,name:g$1,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:N,children:h}),v?.comment?jsx(h$1,{children:v.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${g$1}`,"aria-expanded":u,className:`fk:relative fk:flex fk:w-full fk:min-w-0 fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:S=>{S.preventDefault(),S.stopPropagation(),m.current?.focus(),m.current?.click(),f$1(true);},onKeyDown:S=>{S.key==="Enter"&&f$1(true),S.key==="Escape"&&(S.preventDefault(),S.stopPropagation(),m.current?.blur(),f$1(false));},ref:m,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:items-start fk:gap-2",children:[u?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-[0.1875rem]",disabled:s,onClick:ee,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",D?.menu?.label??D?.plural]}):jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-wrap fk:grow fk:overflow-hidden fk:pb-1.5",children:[k.map(S=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:max-w-60 fk:justify-start fk:rounded-xs",title:S,variant:"secondary",children:jsx("span",{className:"fk:min-w-0 fk:truncate",children:S})},S)),_?jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",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:[u?jsxs("span",{className:"fk:text-sm fk:font-normal fk:text-muted-foreground",children:[G.toLocaleString()," ",G===1?"record":"records"]}):null,u?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:S=>{S.preventDefault(),S.stopPropagation(),m.current?.blur(),f$1(false);},onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),S.stopPropagation(),m.current?.blur(),f$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:N,onKeyDown:S=>{S.key==="Enter"&&(m.current?.focus(),m.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]})]}),jsx(l,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:f$1,open:u,children:jsx(n,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${g$1}`,children:jsx(eo,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:oe,data:p,entityName:r,hasMore:Y,isLoadingMore:W&&p.length>0,onLoadMore:j,rowAdditionState:F[x]?.connect,rowDeletionState:F[x]?.disconnect})})})})]})})}),jsx(i$1,{})]})})}function Zm({appDispatch:e,relationshipId:t,relationships:n,row:o,setRows:r}){function i(s){let a=n[t]?.connect??[],c=typeof find(propEq(s,"_id"),a)=="object",l=n[t]?.disconnect?.includes(s),u=c?n[t]?.disconnect??[]:uniq([...n[t]?.disconnect??[],s]);c&&r(f=>f.filter(m=>m._id!==s)),e({type:"setRelationship",payload:{[t]:{connect:a.filter(f=>f._id!==s),disconnect:l?n[t]?.disconnect?.filter(f=>f!==s)??[]:u}}});}return jsx(cl,{action:i,row:o})}function Ym({data:e,defaultScope:t,relationshipEntitySchema:n,scope:o}){if(!Array.isArray(e))return [];let r=i=>{let a=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";if(a){let c=i[a],l=Array.isArray(c)?c[0]:c;return l&&typeof l=="object"?l[o]??l[t]??"":l}return i[o]??i[t]};return e.map(i=>map(s=>{if(Array.isArray(s)){let a=s;return a.length===0?"":a.length===1?r(a[0]):a.slice(0,3).map(r).join(", ")}return s&&typeof s!="string"&&s.__typename?r(s):s},i))}function oi({control:e$1,defaultScope:t,defaultValue:n,entityId:o,fieldSchema:r,getValues:i,readOnly:s,schema:a,scope:c$1,setValue:l}){let[u,f$1]=useState(false),{name:m,label:p,options:d,relationship:g$1}=r,h=g$1?.entity??m,v=pe(),y=d$2(),b=useId(),{relationships:E}=c$2(),A=useId(),F=find(propEq(h,"name"))(a),N=e$4(F)?.name;useEffect(()=>{let $=n.value;if($===""||typeof $=="boolean"||typeof $=="number")return;let O={_id:String(n._id),value:$},V={type:"setRelationship",payload:{[A]:{connect:O,disconnect:[]}}};y(V);},[y,A,n,c$1]),useEffect(()=>{l(m,{...i(m),...E[A]?.connect??""});},[n,m,E,A,l]);function x($){$.preventDefault(),!s&&v({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:h,entityId:o,relationshipId:A,mode:g$1?.mode??"single"}});}function D($){if(s)return;let O={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};$.preventDefault(),y(O),l(m,{...i(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:n,name:m,render:({field:$})=>{let O=$.value?.value,V="";if(N&&O&&typeof O=="object"&&!Array.isArray(O)&&O[N]){let R=O[N],B=Array.isArray(R)?R[0]:R;typeof B=="string"?V=B:V=B?.[c$1]??B?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:b,children:p}),d?.comment?jsx(h$1,{children:d.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$7,{className:"fk:h-9.5 fk:py-1.75 fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",disabled:s,id:b,onBlur:()=>{f$1(false);},onClick:x,onFocus:()=>{f$1(true);},onKeyDown:R=>{R.key==="Enter"&&x(R);},readOnly:true,type:"text",value:V}),V?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",disabled:s,onClick:D,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",disabled:s,onClick:x,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i$1,{})]})}})}function ri(e){let{fieldSchema:t}=e,{relationship:n}=t;if(n?.mode==="single")return jsx(oi,{...e});if(n?.mode==="multiple"){if(n.entity==="_asset")return jsx(Zr,{...e});let o={relationshipEntityName:t.relationship?.entity,...e};return jsx(ni,{...o})}return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var kl="flexkit-select-option:";function ii(e){return `${kl}${encodeURIComponent(e)}`}function ap(e){return decodeURIComponent(e.slice(kl.length))}function hl({control:e$2,fieldSchema:t,readOnly:n,setValue:o}){let{name:r,label:i,options:s}=t;function a(l,u){let m=t.dataType==="int"&&!isNaN(Number(l))?Number(l):l;o(r,{...u,value:m});}function c$2(l,u){o(r,{...u,disabled:l});}return jsx(c,{control:e$2,name:r,render:({field:l})=>jsxs(e,{children:[jsx(f,{children:i}),s?.comment?jsx(h$1,{children:s.comment}):null,jsxs(a$5,{defaultValue:l.value?.value===void 0||l.value.value===null?void 0:ii(String(l.value.value)),disabled:n||l.value?.disabled,onValueChange:u=>{a(ap(u),l.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:s?.placeholder})})}),jsx(e$1,{children:s?.list?.map(u=>"groupLabel"in u?jsxs(b$2,{children:[jsx(f$1,{children:u.groupLabel}),u.items.map(f=>jsx(g$1,{value:ii(f.value),children:f.label},f.label))]},u.groupLabel):jsx(g$1,{value:ii(u.value),children:u.label},u.label))})]}),jsx(a$6,{checked:l.value?.disabled??false,disabled:n,onChange:u=>{c$2(u,l.value);},scope:l.value?.scope}),jsx(i$1,{})]})})}function li({inputType:e,label:t}){return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}var tn="all",ci={name:"all",title:"All fields"};function up(e){return typeof e.group=="string"?[e.group]:Array.isArray(e.group)?e.group:[]}function ui(e,t){return t==="all"?true:up(e).includes(t)}function fi(e,t){return t.length===0?true:t.some(n=>ui(e,n.name))}function di(e,t){if(!e||e.length===0)return [];let n=e.find(s=>s.name==="all"),o=e.filter(s=>s.name!=="all");return [{...ci,...n},...o].filter(s=>!xt(s.hidden,t))}function mi(e){let t=e.find(o=>o.default);if(t)return t.name;let n=e.find(o=>o.name!=="all");return n?n.name:"all"}function wp(e,t){let n=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:n}}function Sp({currentScope:e,defaultScope:t,entityId:n,entityName:o,entityNamePlural:r,formData:i$1,schema:s,setIsDirty:a,onSubmit:c},l){let u=find(propEq(o,"name"))(s),[,f]=b(),m=f.user?.spaces,p=useMemo(()=>vn(u?.attributes??[],m),[u,m]),d$1=useMemo(()=>i$1||p.reduce((M,C)=>({...M,[C.name]:wp(C,t)}),{}),[t,i$1,p]),h$1=useForm({defaultValues:d$1,resolver:async(M,C,k)=>{let _=Vn(M),U=di(u?.groups,{record:_,value:_,currentUser:f.user}),W={};for(let oe of p){if(typeof oe.validation>"u")continue;let J={record:_,value:_[oe.name],currentUser:f.user};xt(oe.hidden,J)||xt(oe.readOnly,J)||fi(oe,U)&&(W[oe.name]=z.object({value:oe.validation(z).or(z.any().refine(()=>false,{error:oe.label?`${oe.label} is required`:"Required field"}))}));}return zodResolver(z.object(W))(M,C,k)},values:i$1,mode:"onBlur",criteriaMode:"all"}),{control:v,getValues:y,handleSubmit:b$2,setValue:E,watch:A,trigger:F}=h$1,N=A(),x$1=Vn(N),D=useMemo(()=>di(u?.groups,{record:x$1,value:x$1,currentUser:f.user}),[f.user,u?.groups,x$1]),[$,O]=useState(()=>mi(D)),{getContributionPointConfig:V}=d(),R=useRef(i$1),B=useRef(false);useEffect(()=>{B.current||(R.current=i$1);},[i$1]);let Z={datetime:Pa,editor:Qr,asset:Na,number:Da,relationship:ri,select:hl,switch:a$4,text:a$3,textarea:a$2};if(useImperativeHandle(l,()=>({submit(){F().then(()=>{b$2(()=>{let M=y();B.current=true,R.current=M,a(false),c(M,i$1);})();});},hasErrors(){B.current=false,R.current=i$1,a(true);},hasDataChanged(){return vl(y(),R.current)},markAsSaved(){B.current=true,R.current=y(),a(false);},applyLocalAttributeIds(M){let C=y(),k={...C};for(let[_,U]of Object.entries(M)){let W=C[_];!W||W._id||!U||(k[_]={...W,_id:U});}B.current=true,R.current=k;for(let[_,U]of Object.entries(k))U!==C[_]&&E(_,U,{shouldDirty:false,shouldTouch:false,shouldValidate:false});a(false);}})),useEffect(()=>{let M=A(()=>{a(vl(y(),R.current));});return ()=>{M.unsubscribe();}},[i$1,y,a,A]),useEffect(()=>{D.length!==0&&(D.some(M=>M.name===$)||O(mi(D)));},[$,D]),!u||u.attributes.length===0)return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Error"}),jsxs(ve,{children:["No attributes found in the schema for entity ",jsx("strong",{children:o})]})]});let te=M=>{if(M.name==="_id")return null;let C={record:x$1,value:x$1[M.name],currentUser:f.user};if(xt(M.hidden,C))return null;let k=xt(M.readOnly,C),_=V("formFields",[M.inputType])?.[0]?.component??Z[M.inputType];return _?createElement(_,{key:M.name,control:v,defaultScope:t,defaultValue:d$1[M.name],entityId:n,entityName:o,entityNamePlural:r,fieldSchema:M,getValues:y,readOnly:k,schema:s,scope:e,setValue:E}):jsx(li,{inputType:M.inputType,label:M.label},M.name)};return jsx(b$1,{...h$1,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-5",onSubmit:M=>{M.preventDefault();},children:D.length>0?jsxs(h,{onValueChange:O,value:$,children:[jsx("div",{className:"fk:sticky fk:top-0 fk:z-10 fk:bg-background fk:py-1 fk:mb-6",children:jsxs(w,{className:"fk:w-full fk:**:data-[slot=scroll-area-viewport]:h-auto fk:[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:hidden",children:[jsx(i,{className:"fk:h-9 fk:w-max fk:flex-nowrap fk:justify-start fk:border fk:border-border",children:D.map(M=>jsxs(j,{className:"fk:shrink-0 fk:px-4 fk:dark:data-[state=active]:border-transparent! fk:dark:data-[state=active]:bg-background",value:M.name,children:[M.icon,M.title]},M.name))}),jsx(x,{orientation:"horizontal"})]})}),jsx(k,{className:"fk:gap-8",value:$,children:p.map(M=>{if(!fi(M,D))return null;let C=ui(M,$),k=te(M);return k?jsx("div",{className:C?void 0:"fk:hidden",children:k},M.name):null})})]}):p.map(M=>te(M))})})}var Xo=memo(forwardRef(Sp));function vl(e,t){if(!t)return Object.keys(e).some(s=>e[s]?.value!==""&&e[s]?.value!==void 0);let n=s=>typeof s=="object"&&s!==null?"path"in s?s.path:"_id"in s?s._id:"":s??"",o=(s,a)=>s<a?-1:1,r=Object.keys(t).sort((s,a)=>o(s,a)).filter(s=>s!=="_updatedAt").reduce((s,a)=>({...s,[a]:{value:n(t[a].value),disabled:t[a].disabled,relationships:t[a].relationships}}),{}),i=Object.keys(e).sort((s,a)=>o(s,a)).filter(s=>s!=="_updatedAt").reduce((s,a)=>({...s,[a]:{value:n(e[a]?.value),disabled:e[a]?.disabled??false,relationships:Object.keys(e[a]?.relationships?.connect??{}).length||e[a]?.relationships?.disconnect?.length?e[a]?.relationships:void 0}}),{});return !equals(r,i)}function bl(e){return e?e!=="viewer":true}function Ft(){let[,e]=b();return bl(e.user?.role)}function hi({action:e,depth:t,isFocused:n}){let{entityName:o}=e.payload,r=useRef(null),i=Ft(),[,s]=b(),{projects:a,currentProjectId:c}=d(),{schema:l,scopes:u}=find(propEq(c??"","projectId"))(a),f=u?.find(R=>R.isDefault)?.name??"default",p=find(propEq(o,"name"))(l)?.plural??o,{scope:d$1}=c$2(),g=pe(),h=useApolloClient(),[v,y,b$1,E]=St(),{isDirty:A,setIsDirty:F}=yn(),[N,x]=useState(false);useEffect(()=>{E.error&&r.current?.hasErrors();},[E.error]);function D(){return A?(g({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{g({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{F(false),g({type:"Dismiss",_id:"unsavedChanges",payload:{}}),x(true);}}}}),false):true}let $=useCallback(R=>{g({type:"Dismiss",_id:R,payload:{}});},[g]),O=useCallback(()=>{r.current?.submit();},[r]),V=useCallback(R=>{let B=v4(),Z=Nr(p,l,R,B,{currentUser:s.user});y(gql`
|
|
388
|
+
`),oe=Yn({attributesSchema:D?.attributes??[],actionsComponent:s?void 0:x=>Zm({appDispatch:A,relationshipId:S,relationships:F,row:x,setRows:d})});useEffect(()=>{d(te),n$1.value!==""&&A({type:"setRelationship",payload:{[S]:{connect:[],disconnect:[]}}});},[A,se,te,S,n$1,c$1]),useEffect(()=>{l$1(g$1,{...n$1,relationships:F[S]});},[n$1,F,S,l$1,g$1]),useEffect(()=>{let P=(F[S]?.connect??[]).map(({value:H})=>H);d(uniqBy(prop("_id"),[...P,...te]));},[se,n$1.count,te,F,S]);let J=F[S]?.connect??[],ae=F[S]?.disconnect??[],ke=new Set(te.map(x=>x._id)),z=new Set(ae),q=J.filter(x=>!ke.has(x._id)||z.has(x._id)).length,he=ae.length,L=n$1.count??0,G=Math.max(0,Math.max(L,te.length)+q-he),Y=L>0&&p.length>0&&p.length<L,j=useCallback(()=>{W||U({variables:{limit:Km,offset:p.length,where:R?{[R]:{some:{_id:{eq:o}}}}:{}}}).then(({data:x})=>{if(!x)return;let P=To(D?.plural??"",c$1,x,a);d(uniqBy(prop("_id"),[...te,...P.results]));}).catch(x=>{console.error("Error fetching more data:",x);});},[R,o,U,te,W,D?.plural,p.length,a,c$1]);function ee(x){x.preventDefault(),!s&&E({type:"EditRelationship",payload:{connectedEntitiesCount:te.length,connectionName:R,entityName:b,entityId:o,relationshipId:S,mode:y?.mode??"multiple"}});}return jsx(c,{control:e$1,defaultValue:n$1,name:g$1,render:()=>jsxs(e,{className:"fk:min-w-0",children:[jsx(f,{htmlFor:N,children:h}),v?.comment?jsx(h$1,{children:v.comment}):null,jsx(g,{className:"fk:flex fk:flex-col fk:w-full fk:min-w-0 fk:min-h-9.5 fk:pl-3 fk:pr-3 fk:py-0.5 fk:text-sm",children:jsx("div",{"aria-controls":`relationship-dropdown-${g$1}`,"aria-expanded":u,className:`fk:relative fk:flex fk:w-full fk:min-w-0 fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:focus-visible:outline-hidden fk:ring-offset-background fk:focus-visible:ring-2 fk:focus-visible:ring-ring fk:focus-visible:ring-offset-2 ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,onClick:x=>{x.preventDefault(),x.stopPropagation(),m.current?.focus(),m.current?.click(),f$1(true);},onKeyDown:x=>{x.key==="Enter"&&f$1(true),x.key==="Escape"&&(x.preventDefault(),x.stopPropagation(),m.current?.blur(),f$1(false));},ref:m,role:"combobox",tabIndex:0,children:jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:flex-col",children:[jsxs("div",{className:"fk:flex fk:w-full fk:min-w-0 fk:items-start fk:gap-2",children:[u?jsxs(b$3,{className:"fk:h-8 fk:mr-auto fk:mt-[0.1875rem]",disabled:s,onClick:ee,variant:"outline",children:[jsx(Link,{className:"fk:h-4 fk:w-4 fk:mr-2"})," Link to a record from"," ",D?.menu?.label??D?.plural]}):jsxs("span",{className:"fk:flex fk:min-w-0 fk:flex-wrap fk:grow fk:overflow-hidden fk:pb-1.5",children:[k.map(x=>jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:max-w-60 fk:justify-start fk:rounded-xs",title:x,variant:"secondary",children:jsx("span",{className:"fk:min-w-0 fk:truncate",children:x})},x)),_?jsx(b$6,{className:"fk:mr-2 fk:mt-1.5 fk:rounded-xs",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:[u?jsxs("span",{className:"fk:text-sm fk:font-normal fk:text-muted-foreground",children:[G.toLocaleString()," ",G===1?"record":"records"]}):null,u?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",onClick:x=>{x.preventDefault(),x.stopPropagation(),m.current?.blur(),f$1(false);},onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),x.stopPropagation(),m.current?.blur(),f$1(false));},size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Close"})})]})}):jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",id:N,onKeyDown:x=>{x.key==="Enter"&&(m.current?.focus(),m.current?.click());},size:"icon",variant:"ghost",children:jsx(Maximize2,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Expand field"})})]})})]})]}),jsx(l,{className:"fk:w-full fk:min-w-0 fk:space-y-2 fk:ml-0!",onOpenChange:f$1,open:u,children:jsx(n,{className:"fk:w-full fk:min-w-0",children:jsx("div",{className:"fk:mt-3 fk:mb-2 fk:w-full fk:min-w-0",id:`relationship-dropdown-${g$1}`,children:jsx(eo,{classNames:{wrapper:"fk:h-[17.5rem] fk:min-h-0 fk:min-w-0 fk:gap-0",table:"fk:pb-0"},columns:oe,data:p,entityName:r,hasMore:Y,isLoadingMore:W&&p.length>0,onLoadMore:j,rowAdditionState:F[S]?.connect,rowDeletionState:F[S]?.disconnect})})})})]})})}),jsx(i$1,{})]})})}function Zm({appDispatch:e,relationshipId:t,relationships:n,row:o,setRows:r}){function i(s){let a=n[t]?.connect??[],c=typeof find(propEq(s,"_id"),a)=="object",l=n[t]?.disconnect?.includes(s),u=c?n[t]?.disconnect??[]:uniq([...n[t]?.disconnect??[],s]);c&&r(f=>f.filter(m=>m._id!==s)),e({type:"setRelationship",payload:{[t]:{connect:a.filter(f=>f._id!==s),disconnect:l?n[t]?.disconnect?.filter(f=>f!==s)??[]:u}}});}return jsx(cl,{action:i,row:o})}function Ym({data:e,defaultScope:t,relationshipEntitySchema:n,scope:o}){if(!Array.isArray(e))return [];let r=i=>{let a=find(propEq(i.__typename,"name"))(n?.attributes??[])?.relationship?.field??"";if(a){let c=i[a],l=Array.isArray(c)?c[0]:c;return l&&typeof l=="object"?l[o]??l[t]??"":l}return i[o]??i[t]};return e.map(i=>map(s=>{if(Array.isArray(s)){let a=s;return a.length===0?"":a.length===1?r(a[0]):a.slice(0,3).map(r).join(", ")}return s&&typeof s!="string"&&s.__typename?r(s):s},i))}function oi({control:e$1,defaultScope:t,defaultValue:n,entityId:o,fieldSchema:r,getValues:i,readOnly:s,schema:a,scope:c$1,setValue:l}){let[u,f$1]=useState(false),{name:m,label:p,options:d,relationship:g$1}=r,h=g$1?.entity??m,v=pe(),y=d$2(),b=useId(),{relationships:E}=c$2(),A=useId(),F=find(propEq(h,"name"))(a),N=e$4(F)?.name;useEffect(()=>{let $=n.value;if($===""||typeof $=="boolean"||typeof $=="number")return;let O={_id:String(n._id),value:$},V={type:"setRelationship",payload:{[A]:{connect:O,disconnect:[]}}};y(V);},[y,A,n,c$1]),useEffect(()=>{l(m,{...i(m),...E[A]?.connect??""});},[n,m,E,A,l]);function S($){$.preventDefault(),!s&&v({type:"EditRelationship",payload:{connectedEntitiesCount:0,entityName:h,entityId:o,relationshipId:A,mode:g$1?.mode??"single"}});}function D($){if(s)return;let O={type:"setRelationship",payload:{[A]:{connect:[],disconnect:[]}}};$.preventDefault(),y(O),l(m,{...i(m),_id:"",value:void 0});}return jsx(c,{control:e$1,defaultValue:n,name:m,render:({field:$})=>{let O=$.value?.value,V="";if(N&&O&&typeof O=="object"&&!Array.isArray(O)&&O[N]){let R=O[N],B=Array.isArray(R)?R[0]:R;typeof B=="string"?V=B:V=B?.[c$1]??B?.[t]??"";}return jsxs(e,{children:[jsx(f,{htmlFor:b,children:p}),d?.comment?jsx(h$1,{children:d.comment}):null,jsx(g,{className:"fk:flex fk:w-full fk:items-center fk:space-x-2",children:jsxs("div",{className:`fk:relative fk:flex fk:w-full fk:items-start fk:space-x-2 fk:rounded-md fk:border fk:border-input fk:bg-background fk:ring-offset-background ${u?"fk:outline-hidden fk:ring-2 fk:ring-ring fk:ring-offset-2":""}`,children:[jsx(a$7,{className:"fk:h-9.5 fk:py-1.75 fk:caret-transparent fk:border-0 fk:focus-visible:ring-0 fk:focus-visible:ring-offset-0",disabled:s,id:b,onBlur:()=>{f$1(false);},onClick:S,onFocus:()=>{f$1(true);},onKeyDown:R=>{R.key==="Enter"&&S(R);},readOnly:true,type:"text",value:V}),V?jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-10 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",disabled:s,onClick:D,size:"icon",variant:"ghost",children:jsx(X,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Clear"})})]})}):null,jsx(a$8,{children:jsxs(b$5,{children:[jsx(c$4,{asChild:true,children:jsx(b$3,{className:"fk:absolute fk:right-0.75 fk:top-0.75 fk:h-8 fk:w-8 fk:rounded-sm fk:text-muted-foreground",disabled:s,onClick:S,size:"icon",variant:"ghost",children:jsx(ChevronsUpDown,{className:"fk:h-4 fk:w-4"})})}),jsx(e$3,{children:jsx("p",{children:"Open"})})]})})]})}),jsx(i$1,{})]})}})}function ri(e){let{fieldSchema:t}=e,{relationship:n}=t;if(n?.mode==="single")return jsx(oi,{...e});if(n?.mode==="multiple"){if(n.entity==="_asset")return jsx(Zr,{...e});let o={relationshipEntityName:t.relationship?.entity,...e};return jsx(ni,{...o})}return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:'Incorrect "mode" for relationship field. It should be "single" or "multiple". Please check the schema configuration.'})]})}var kl="flexkit-select-option:";function ii(e){return `${kl}${encodeURIComponent(e)}`}function ap(e){return decodeURIComponent(e.slice(kl.length))}function hl({control:e$2,fieldSchema:t,readOnly:n,setValue:o}){let{name:r,label:i,options:s}=t;function a(l,u){let m=t.dataType==="int"&&!isNaN(Number(l))?Number(l):l;o(r,{...u,value:m});}function c$2(l,u){o(r,{...u,disabled:l});}return jsx(c,{control:e$2,name:r,render:({field:l})=>jsxs(e,{children:[jsx(f,{children:i}),s?.comment?jsx(h$1,{children:s.comment}):null,jsxs(a$5,{defaultValue:l.value?.value===void 0||l.value.value===null?void 0:ii(String(l.value.value)),disabled:n||l.value?.disabled,onValueChange:u=>{a(ap(u),l.value);},children:[jsx(g,{children:jsx(d$1,{children:jsx(c$1,{placeholder:s?.placeholder})})}),jsx(e$1,{children:s?.list?.map(u=>"groupLabel"in u?jsxs(b$2,{children:[jsx(f$1,{children:u.groupLabel}),u.items.map(f=>jsx(g$1,{value:ii(f.value),children:f.label},f.label))]},u.groupLabel):jsx(g$1,{value:ii(u.value),children:u.label},u.label))})]}),jsx(a$6,{checked:l.value?.disabled??false,disabled:n,onChange:u=>{c$2(u,l.value);},scope:l.value?.scope}),jsx(i$1,{})]})})}function li({inputType:e,label:t}){return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"h-4 w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:`Incorrect inputType: "${e}" for the "${t}" attribute. Please check the schema configuration.`})]})}var tn="all",ci={name:"all",title:"All fields"};function up(e){return typeof e.group=="string"?[e.group]:Array.isArray(e.group)?e.group:[]}function ui(e,t){return t==="all"?true:up(e).includes(t)}function fi(e,t){return t.length===0?true:t.some(n=>ui(e,n.name))}function di(e,t){if(!e||e.length===0)return [];let n=e.find(s=>s.name==="all"),o=e.filter(s=>s.name!=="all");return [{...ci,...n},...o].filter(s=>!St(s.hidden,t))}function mi(e){let t=e.find(o=>o.default);if(t)return t.name;let n=e.find(o=>o.name!=="all");return n?n.name:"all"}function wp(e,t){let n=e.dataType==="asset"||e.scope==="relationship"?"":e.defaultValue??"";return {disabled:false,scope:t,value:n}}function xp({currentScope:e,defaultScope:t,entityId:n,entityName:o,entityNamePlural:r,formData:i$1,schema:s,setIsDirty:a,onSubmit:c},l){let u=find(propEq(o,"name"))(s),[,f]=b(),m=f.user?.spaces,p=useMemo(()=>vn(u?.attributes??[],m),[u,m]),d$1=useMemo(()=>i$1||p.reduce((M,C)=>({...M,[C.name]:wp(C,t)}),{}),[t,i$1,p]),h$1=useForm({defaultValues:d$1,resolver:async(M,C,k)=>{let _=Vn(M),U=di(u?.groups,{record:_,value:_,currentUser:f.user}),W={};for(let oe of p){if(typeof oe.validation>"u")continue;let J={record:_,value:_[oe.name],currentUser:f.user};St(oe.hidden,J)||St(oe.readOnly,J)||fi(oe,U)&&(W[oe.name]=z.object({value:oe.validation(z).or(z.any().refine(()=>false,{error:oe.label?`${oe.label} is required`:"Required field"}))}));}return zodResolver(z.object(W))(M,C,k)},values:i$1,mode:"onBlur",criteriaMode:"all"}),{control:v,getValues:y,handleSubmit:b$2,setValue:E,watch:A,trigger:F}=h$1,N=A(),S=Vn(N),D=useMemo(()=>di(u?.groups,{record:S,value:S,currentUser:f.user}),[f.user,u?.groups,S]),[$,O]=useState(()=>mi(D)),{getContributionPointConfig:V}=d(),R=useRef(i$1),B=useRef(false);useEffect(()=>{B.current||(R.current=i$1);},[i$1]);let Z={datetime:Pa,editor:Qr,asset:Na,number:Da,relationship:ri,select:hl,switch:a$4,text:a$3,textarea:a$2};if(useImperativeHandle(l,()=>({submit(){F().then(()=>{b$2(()=>{let M=y();B.current=true,R.current=M,a(false),c(M,i$1);})();});},hasErrors(){B.current=false,R.current=i$1,a(true);},hasDataChanged(){return vl(y(),R.current)},markAsSaved(){B.current=true,R.current=y(),a(false);},applyLocalAttributeIds(M){let C=y(),k={...C};for(let[_,U]of Object.entries(M)){let W=C[_];!W||W._id||!U||(k[_]={...W,_id:U});}B.current=true,R.current=k;for(let[_,U]of Object.entries(k))U!==C[_]&&E(_,U,{shouldDirty:false,shouldTouch:false,shouldValidate:false});a(false);}})),useEffect(()=>{let M=A(()=>{a(vl(y(),R.current));});return ()=>{M.unsubscribe();}},[i$1,y,a,A]),useEffect(()=>{D.length!==0&&(D.some(M=>M.name===$)||O(mi(D)));},[$,D]),!u||u.attributes.length===0)return jsxs(ye,{variant:"destructive",children:[jsx(AlertTriangle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Error"}),jsxs(ve,{children:["No attributes found in the schema for entity ",jsx("strong",{children:o})]})]});let te=M=>{if(M.name==="_id")return null;let C={record:S,value:S[M.name],currentUser:f.user};if(St(M.hidden,C))return null;let k=St(M.readOnly,C),_=V("formFields",[M.inputType])?.[0]?.component??Z[M.inputType];return _?createElement(_,{key:M.name,control:v,defaultScope:t,defaultValue:d$1[M.name],entityId:n,entityName:o,entityNamePlural:r,fieldSchema:M,getValues:y,readOnly:k,schema:s,scope:e,setValue:E}):jsx(li,{inputType:M.inputType,label:M.label},M.name)};return jsx(b$1,{...h$1,children:jsx("form",{className:"fk:flex fk:flex-col fk:gap-5",onSubmit:M=>{M.preventDefault();},children:D.length>0?jsxs(h,{onValueChange:O,value:$,children:[jsx("div",{className:"fk:sticky fk:top-0 fk:z-10 fk:bg-background fk:py-1 fk:mb-6",children:jsxs(w,{className:"fk:w-full fk:**:data-[slot=scroll-area-viewport]:h-auto fk:[&_[data-slot=scroll-area-scrollbar][data-orientation=vertical]]:hidden",children:[jsx(i,{className:"fk:h-9 fk:w-max fk:flex-nowrap fk:justify-start fk:border fk:border-border",children:D.map(M=>jsxs(j,{className:"fk:shrink-0 fk:px-4 fk:dark:data-[state=active]:border-transparent! fk:dark:data-[state=active]:bg-background",value:M.name,children:[M.icon,M.title]},M.name))}),jsx(x,{orientation:"horizontal"})]})}),jsx(k,{className:"fk:gap-8",value:$,children:p.map(M=>{if(!fi(M,D))return null;let C=ui(M,$),k=te(M);return k?jsx("div",{className:C?void 0:"fk:hidden",children:k},M.name):null})})]}):p.map(M=>te(M))})})}var Xo=memo(forwardRef(xp));function vl(e,t){if(!t)return Object.keys(e).some(s=>e[s]?.value!==""&&e[s]?.value!==void 0);let n=s=>typeof s=="object"&&s!==null?"path"in s?s.path:"_id"in s?s._id:"":s??"",o=(s,a)=>s<a?-1:1,r=Object.keys(t).sort((s,a)=>o(s,a)).filter(s=>s!=="_updatedAt").reduce((s,a)=>({...s,[a]:{value:n(t[a].value),disabled:t[a].disabled,relationships:t[a].relationships}}),{}),i=Object.keys(e).sort((s,a)=>o(s,a)).filter(s=>s!=="_updatedAt").reduce((s,a)=>({...s,[a]:{value:n(e[a]?.value),disabled:e[a]?.disabled??false,relationships:Object.keys(e[a]?.relationships?.connect??{}).length||e[a]?.relationships?.disconnect?.length?e[a]?.relationships:void 0}}),{});return !equals(r,i)}function bl(e){return e?e!=="viewer":true}function Ft(){let[,e]=b();return bl(e.user?.role)}function hi({action:e,depth:t,isFocused:n}){let{entityName:o}=e.payload,r=useRef(null),i=Ft(),[,s]=b(),{projects:a,currentProjectId:c}=d(),{schema:l,scopes:u}=find(propEq(c??"","projectId"))(a),f=u?.find(R=>R.isDefault)?.name??"default",p=find(propEq(o,"name"))(l)?.plural??o,{scope:d$1}=c$2(),g=pe(),h=useApolloClient(),[v,y,b$1,E]=xt(),{isDirty:A,setIsDirty:F}=yn(),[N,S]=useState(false);useEffect(()=>{E.error&&r.current?.hasErrors();},[E.error]);function D(){return A?(g({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{g({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{F(false),g({type:"Dismiss",_id:"unsavedChanges",payload:{}}),S(true);}}}}),false):true}let $=useCallback(R=>{g({type:"Dismiss",_id:R,payload:{}});},[g]),O=useCallback(()=>{r.current?.submit();},[r]),V=useCallback(R=>{let B=v4(),Z=Nr(p,l,R,B,{currentUser:s.user});y(gql`
|
|
389
389
|
${Z}
|
|
390
|
-
`),b$1({onCompleted:()=>{At(h,Ke(p,l)),$(e._id),toast.success("Your changes have been saved.");}}),v(true);},[e._id,h,s.user,p,$,v,l,y,b$1]);return jsx(g$3,{actions:jsx(x$1,{disabled:!i,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{O();},variant:"default",children:[E.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:D,depth:t,forceClose:N,isFocused:n,onClose:()=>{$(e._id);},title:`Add ${o}`,children:jsx(Xo,{currentScope:d$1,defaultScope:f,entityName:o,entityNamePlural:p,onSubmit:V,ref:r,schema:l,setIsDirty:F})})}function ro({entityNamePlural:e,schema:t,scope:n,variables:o,isForm:r,selection:i="full"}){let[s,a]=useState({count:0,results:[]}),[c,l]=useState(false),[u,f]=useState(false),[m,p]=useState(null),d=useRef(false),g=useRef(false),h=useRef(0),v=useRef(null),y=useRef(null),b=`${e}Total`,E=rt(t,e),F=o?.where===void 0&&(E?.spaces?.length??0)===0&&(m?.field!==b||m.schema!==t)?"total":"aggregate",N=jn(e,n,t,{selection:i,countMode:F}),
|
|
390
|
+
`),b$1({onCompleted:()=>{At(h,Ke(p,l)),$(e._id),toast.success("Your changes have been saved.");}}),v(true);},[e._id,h,s.user,p,$,v,l,y,b$1]);return jsx(g$3,{actions:jsx(x$1,{disabled:!i,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!i,onClick:()=>{O();},variant:"default",children:[E.loading?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})}),beforeClose:D,depth:t,forceClose:N,isFocused:n,onClose:()=>{$(e._id);},title:`Add ${o}`,children:jsx(Xo,{currentScope:d$1,defaultScope:f,entityName:o,entityNamePlural:p,onSubmit:V,ref:r,schema:l,setIsDirty:F})})}function ro({entityNamePlural:e,schema:t,scope:n,variables:o,isForm:r,selection:i="full"}){let[s,a]=useState({count:0,results:[]}),[c,l]=useState(false),[u,f]=useState(false),[m,p]=useState(null),d=useRef(false),g=useRef(false),h=useRef(0),v=useRef(null),y=useRef(null),b=`${e}Total`,E=rt(t,e),F=o?.where===void 0&&(E?.spaces?.length??0)===0&&(m?.field!==b||m.schema!==t)?"total":"aggregate",N=jn(e,n,t,{selection:i,countMode:F}),S=useMemo(()=>gql`
|
|
391
391
|
${N.query}
|
|
392
392
|
`,[N.query]),D=jn(e,n,t,{selection:i,includeCount:false}),$=useMemo(()=>gql`
|
|
393
393
|
${D.query}
|
|
394
|
-
`,[D.query]),{schemaErrorMessage:O,setSchemaErrorMessage:V}=Kt(),{loading:R,data:B,fetchMore:Z,refetch:te,error:M,networkStatus:C}=useQuery(
|
|
394
|
+
`,[D.query]),{schemaErrorMessage:O,setSchemaErrorMessage:V}=Kt(),{loading:R,data:B,fetchMore:Z,refetch:te,error:M,networkStatus:C}=useQuery(S,{variables:o,notifyOnNetworkStatusChange:true}),k=useRef(Z),_=useRef(te),U=useRef($),W=useRef(C),se=useRef(o);k.current=Z,_.current=te,U.current=$,se.current=o;let oe=Fs(M,b),J=F==="total"&&oe,ae=oe?void 0:M,ke=oe&&!B?.[e],z=Xt(ae),q=wo(ae),{isProjectDisabled:he,isProjectReadOnly:L}=(()=>{if(z?.statusCode===403){let j=Wt(z.bodyText);if(j&&typeof j.code=="string"){if(j.code==="PROJECT_PAUSED")return {isProjectDisabled:true,isProjectReadOnly:false};if(j.code==="READ_ONLY_MODE")return {isProjectDisabled:false,isProjectReadOnly:true}}return {isProjectDisabled:true,isProjectReadOnly:false}}return {isProjectDisabled:false,isProjectReadOnly:false}})();useEffect(()=>{J&&p({field:b,schema:t});},[t,J,b]);let G=useCallback(j=>{if(d.current||g.current)return;d.current=true,l(true);let{limit:ee}=j.variables,x=h.current;k.current({...j,query:U.current,variables:{...se.current,...j.variables,offset:x,limit:ee}}).then(({data:P})=>{let H=oo({data:P,entityNamePlural:e,isForm:r,schema:t,scope:n}),le=H.results.length;h.current=x+(le===0?0:Math.min(le,ee)),a(ce=>{let Q=uniqBy(prop("_id"),[...ce.results,...H.results]);return Q.length===ce.results.length?{count:ce.results.length,results:ce.results}:{count:H.count||ce.count,results:Q}});}).catch(P=>{console.error("Error fetching more data:",P);}).finally(()=>{d.current=false,l(false);});},[e,r,t,n]),Y=useCallback(j=>{if(g.current)return Promise.resolve();let ee=j?.preserve===true;return g.current=true,d.current=false,l(false),ee||(v.current=null,y.current=null,h.current=0,f(true),a({count:0,results:[]})),_.current().then(({data:x})=>{let P=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),H=oo({data:x,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=P,y.current=null,h.current=Zo(o)+H.results.length,a(H);}).catch(x=>{console.error("Error reloading data:",x);}).finally(()=>{g.current=false,f(false);})},[e,r,t,n,i,o]);return useEffect(()=>{if(q){V(q);return}B&&O&&!ae&&V(null);},[B,ae,O,q,V]),useEffect(()=>{if(ae||q||ke)return;let j=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o});if(v.current===j)return;if(R&&y.current!==j){y.current=j,h.current=0,a({count:0,results:[]});return}if(R)return;let ee=oo({data:B,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=j,y.current=null,h.current=Zo(o)+ee.results.length,a(ee);},[B,ae,e,r,R,ke,t,q,n,i,o]),useEffect(()=>{let j=W.current;if(W.current=C,ae||q||g.current||ke||j!==NetworkStatus.refetch||C!==NetworkStatus.ready||!B)return;let ee=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),x=oo({data:B,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=ee,y.current=null,h.current=Zo(o)+x.results.length,a(x);},[B,ae,e,r,ke,C,t,q,n,i,o]),useEffect(()=>{if(r)return;let j=`Get${ot(e)}`,ee=da(H=>{if(!(!H.has(j)||d.current||g.current))return _.current().then(({data:le})=>{let ce=JSON.stringify({entityNamePlural:e,scope:n,selection:i,variables:o}),Q=oo({data:le,entityNamePlural:e,isForm:r,schema:t,scope:n});v.current=ce,y.current=null,h.current=Zo(o)+Q.results.length,a(Q);}).catch(le=>{console.error("Error soft-refreshing entity list:",le);})}),x=ma((H,le)=>{H===j&&a(ce=>{let Q=ce.results.filter(rn=>{let Fn=typeof rn._id=="string"?rn._id:void 0;return !Fn||!le.has(Fn)}),on=ce.results.length-Q.length;return on===0?ce:{count:Math.max(0,ce.count-on),results:Q}});}),P=pa((H,le)=>{H===j&&a(ce=>_p(ce,le,o?.sort));});return ()=>{ee(),x(),P();}},[e,r,t,n,i,o]),{isLoading:R&&C!==NetworkStatus.refetch||u||ke,isLoadingMore:c,fetchMore:G,reload:Y,count:s.count,data:s.results,isProjectDisabled:he,isProjectReadOnly:L,schemaErrorMessage:O}}function Zo(e){let t=e?.offset;return typeof t=="number"&&Number.isFinite(t)?t:0}function oo(e){let t=e.entityNamePlural;return e.data?.[t]?e.isForm?oa(e.entityNamePlural,e.scope,e.data,e.schema):To(e.entityNamePlural,e.scope,e.data,e.schema):{count:0,results:[]}}function _p(e,t,n){let o=new Map(t.map(s=>[s._id,s])),r=false,i=e.results.map(s=>{let a=typeof s._id=="string"?s._id:void 0;if(!a)return s;let c=o.get(a);return c?(r=true,{...s,...c.attributes}):s});return r?{count:e.count,results:$p(i,n)}:e}function $p(e,t){if(!Array.isArray(t)||t.length===0)return e;let[n]=t;if(!n||typeof n!="object")return e;let[o]=Object.entries(n),[r,i]=o??[];if(!r||i!=="ASC"&&i!=="DESC")return e;let s=i==="DESC"?-1:1;return [...e].sort((a,c)=>{let l=a[r],u=c[r],f=typeof l=="string"?l:"",m=typeof u=="string"?u:"";return f.localeCompare(m)*s})}function Tl(){return jsxs(ye,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Read Only Mode"}),jsxs(ve,{children:["This project is currently in read only mode and changes cannot be saved. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/read-only-mode",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function bi({handleSave:e,isLoading:t}){let{isDirty:n}=yn(),o=Ft();return jsx(x$1,{disabled:!o,children:jsxs(b$3,{className:"fk:px-8 fk:min-w-32",disabled:!n||!o,onClick:()=>{e();},variant:"default",children:[t?jsx(Loader2,{className:"fk:h-4 fk:w-4 fk:mr-2 fk:animate-spin"}):null,"Save"]})})}function Ci(){return jsx(Fragment,{children:Array.from({length:10},(t,n)=>n++).map(t=>jsxs("div",{className:"fk:mt-3 fk:mb-6.5",children:[jsx(r$1,{className:"fk:w-full fk:h-[45px]"}),jsxs("div",{className:"fk:flex fk:mt-2 fk:ml-4",children:[jsx(r$1,{className:"fk:w-5 fk:mr-2"}),jsx(r$1,{className:"fk:w-[140px] fk:h-[20px]"})]})]},t))})}function Si({action:e,depth:t,isFocused:n}){let{entityId:o,entityNamePlural:r}=e.payload,i=useRef(null),{projects:s,currentProjectId:a}=d(),{schema:c,scopes:l}=useCallback(()=>find(propEq(a??"","projectId"))(s),[a,s])(),u=l?.find(J=>J.isDefault)?.name??"default",f=find(propEq(r,"plural"))(c),m=f?.name??r,{scope:p}=c$2(),[d$3,g]=useState(p),h=pe(),v=d$2(),y=useApolloClient(),[b$1,E,A,F]=xt(),{isDirty:N,setIsDirty:S}=yn(),[D,$]=useState(false),[,O]=b(),V=useCallback(J=>{S(J);},[S]);useEffect(()=>{F.error&&i.current?.hasErrors();},[F.error]);let R=useCallback(()=>N?(h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"Are you sure you want to leave? There are unsaved changes. If you leave, your changes will be lost.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{S(false),h({type:"Dismiss",_id:"unsavedChanges",payload:{}}),$(true);}}}}),false):true,[h,N,S]),B=useCallback(J=>{h({type:"Dismiss",_id:J,payload:{}});},[h]),Z=useCallback(()=>{i.current?.submit();},[i]);function te(J){if(N){h({type:"AlertDialog",_id:"unsavedChanges",payload:{options:{dialogTitle:"Unsaved Changes",dialogMessage:"You have unsaved changes. Switching scopes will discard them.",dialogCancelTitle:"Stay Here",dialogActionLabel:"Discard Changes",dialogActionCancel:()=>{g(d$3),h({type:"Dismiss",_id:"unsavedChanges",payload:{}});},dialogActionSubmit:()=>{h({type:"Dismiss",_id:"unsavedChanges",payload:{}}),g(J),v({type:"setScope",payload:{projectId:a,scope:J}});}}}});return}g(J),v({type:"setScope",payload:{projectId:a,scope:J}});}let{isLoading:M,data:C}=ro({entityNamePlural:r,schema:c,scope:d$3,variables:{where:{_id:{eq:o}}},isForm:true}),k=useCallback((J,ae)=>{if(!ae)return;let ke=Ar(r,o,d$3,c,ae,J,{currentUser:O.user});E(gql`
|
|
395
395
|
${ke}
|
|
396
|
-
`),A({variables:{where:{_id:{eq:o}}},onCompleted:z=>{i.current?.applyLocalAttributeIds(ua(z,r,c)),At(y,Ke(r,c)),toast.success("Your changes have been saved.");}}),b$1(true);},[y,O.user,d$3,o,r,b$1,c,E,A]),_=C,U=_.length>0,W=M&&!U;function se(J,ae){let ke=e$4(J),z=ke?.name,q=ke?.relationship?.field!==void 0;if(!ae.length||!z)return "";if(!q||!ke?.relationship?.field)return ae[0][z]?.value;let he=ae[0][z]?.value?.[ke.relationship.field],L=Array.isArray(he)?he[0]:he;if(L&&typeof L=="object"){let G=L;return G[d$3]??G.default??""}return L??""}let oe=U&&f?se(f,_):"";return jsx(g$3,{actions:jsxs(Fragment,{children:[l&&l.length>1?jsxs(a$5,{onValueChange:J=>{te(J);},value:d$3,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(d$3,"name"))(l).label})]}),jsx(e$1,{children:l.map(J=>jsx(g$1,{value:J.name,children:J.label},J.name))})]}):null,jsx(bi,{handleSave:Z,isLoading:F.loading})]}),beforeClose:R,depth:t,forceClose:D,isFocused:n,onClose:()=>{B(e._id);},onFormChange:()=>{},title:oe,children:W||!U?jsx(Ci,{}):jsxs(Fragment,{children:[F.isProjectReadOnly?jsx(Tl,{}):null,jsx(Xo,{currentScope:d$3,defaultScope:u,entityId:o,entityName:m,entityNamePlural:r,formData:_[0],onSubmit:k,ref:i,schema:c,setIsDirty:V})]})})}var Ml=25;function Kp(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Ti({action:e,depth:t,isFocused:n}){let o=pe(),r=d$2(),{relationships:i,scope:s}=c$2(),{assetAccept:a,connectedEntitiesCount:c,connectionName:l,entityId:u,entityName:f,initialAssetPath:m,initialConnection:p,mode:d$1,relationshipId:g}=e.payload,{projects:h,currentProjectId:v}=d(),{schema:y}=find(propEq(v??"","projectId"))(h),b=find(propEq(f,"name"))(y),E=b?.plural??"",A=i[g],F=Gn(),N=f==="_asset",x=N?"asset":b?.menu?.label??f.toLowerCase(),D=N&&d$1==="single"?"Select asset":`Select ${N?"assets":x}`,$=d$1==="single"?"Upload asset":"Upload assets",[O,V]=useState([]),R=[];if(p)R=[{id:p._id,value:p.value}];else if(A?.connect){let P=A.connect;R=[{id:P._id,value:P.value}];}let B=d$1==="single"?R:A?.connect?.map(P=>({id:P._id,value:P.value}))||[],[Z,te]=useState(B),M=useMemo(()=>{let P=[];return N&&P.push({NOT:{path:{eq:null}}}),d$1==="multiple"&&l&&u&&P.push({[l]:{none:{_id:{eq:u}}}}),O.length>0&&P.push({OR:O.map(H=>({_id:{eq:H._id}}))}),P.length===0?{}:P.length===1?P[0]:{AND:P}},[l,u,N,d$1,O]),{count:C,data:k,fetchMore:_,isLoading:U,isLoadingMore:W}=ro({entityNamePlural:E,schema:y,scope:s,variables:{offset:0,limit:Ml,where:M,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),se=!!k?.length,oe=U&&!se,J=k?.length??0,ae=C-c,ke=ae>0&&J>0&&J<ae,z=Yn({attributesSchema:b?.attributes??[],checkboxSelect:d$1}),q=Array(5).fill({}),he=Kp(z);useEffect(()=>{if(d$1!=="single"||Z.length>0||!m||!k?.length)return;let P=k.find(H=>H.path===m);!P?._id||typeof P._id!="string"||te([{id:P._id,value:P}]);},[k,m,d$1,Z.length]);let L=useCallback(P=>{o({type:"Dismiss",_id:P,payload:{}});},[o]),G=useCallback(()=>{_({variables:{offset:0,limit:Ml,where:M}});},[M,_]);function Y(){let P;if(d$1==="single"){let[H]=Z;P={_id:H?.id??"",value:H?.value??null};}d$1==="multiple"&&(P=Z?.map((H,le)=>({_id:H.id??"",...N?{sortOrder:le}:{},value:H.value}))),r({type:"setRelationship",payload:{[g]:{connect:P,disconnect:A?.disconnect??[]}}}),L(e._id);}function j(P){if(d$1==="multiple"){te(le=>{let ce=new Map(le.map(Q=>[Q.id,Q]));return P.map(Q=>{if(ce.has(Q))return ce.get(Q);let on=k?.find(rn=>rn._id===Q);return {id:Q,value:on}})});return}let H=P[P.length-1];te(H?le=>{if(le.length===1&&le[0].id===H)return le;let ce=k?.find(Q=>Q._id===H);return [{id:H,value:ce}]}:[]);}function ee(){o({type:"AddEntity",payload:{entityName:f}});}async function S(){let P=await F({projectId:v,accept:a??"image/*",multiple:d$1==="multiple",maxBytes:4194304});te(H=>{if(d$1==="single"){let[Q]=P;return Q?[{id:Q._id,value:Q.asset}]:H}let le=new Set(H.map(Q=>Q.id)),ce=P.filter(Q=>!le.has(Q._id)).map(Q=>({id:Q._id,value:Q.asset}));return [...H,...ce]});}return jsx(g$3,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Y();},variant:"default",children:"Select"}),N?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{ee();},variant:"outline",children:`Create ${x}`}),N?jsxs(b$3,{className:"fk:px-8",onClick:()=>{S();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),$]}):null]}),depth:t,isFocused:n,onClose:()=>{L(e._id);},title:D,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(eo,{columns:oe?he:z,data:oe?q:k??[],entityName:b?.name??"",hasMore:ke,initialSelectionState:Z?.reduce((P,H)=>({...P,...H.id?{[H.id]:true}:{}}),{}),isLoadingMore:W,onEntitySelectionChange:j,onLoadMore:G,toolbarComponent:()=>jsx(Zp,{entityNamePlural:E,projectId:v??"",setSearchResultIds:V})})})})}function Zp({entityNamePlural:e,projectId:t,setSearchResultIds:n}){let[o,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[s,a]=useState(i),{results:c,isLoading:l}=f$4(t,s),u=useRef(null),f=useMemo(()=>Yp(p=>{a({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(c){let p=JSON.stringify(c.map(g=>g._id).sort()),d=u.current?JSON.stringify(u.current.map(g=>g._id).sort()):"";p!==d&&(u.current=[...c],n(c.map(g=>({_id:g._id}))));}},[c,n]);function m(p){let{value:d}=p.target;r(d),f(d);}return jsxs("div",{className:"fk:relative fk:w-full",children:[l?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$7,{className:"fk:w-full fk:pl-11!",onChange:m,placeholder:"Search",value:o})]})}function Yp(e,t=300){let n;return (...o)=>{clearTimeout(n),n=setTimeout(()=>e(...o),t);}}function $l(){let e=Ws(),t=e.filter(o=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===o.type)),n=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(o=>{switch(o.type){case "AlertDialog":{let{payload:r}=o;return jsx(_n,{options:r.options},o._id)}case "DeleteEntity":return jsx(Ir,{action:o},o._id);case "AddEntity":return jsx(hi,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditEntity":return jsx(xi,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditRelationship":return jsx(Ti,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);default:return null}})})}function Ol({config:e}){let[t]=e,{basePath:n,projectId:o}=t,r=a$g(n);return window.location.pathname===r&&(window.location.href=b$a(r,o)),jsx(a$j,{children:jsx(c$7,{config:e,children:jsxs(Ms,{children:[jsx(ya,{children:jsx($l,{})}),jsx(Outlet,{})]})})})}function Vl(){let e=useRouteError(),t=new Date().getFullYear();function n(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):dr(e)?gs(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:n()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(ho,{})]})})]})}function Di(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ye,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:t})]})}var pg=RouterProvider;function gg({config:e}){let[t,n]=useState(false),o=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(u=>Bl(u)):[Bl(e)],[i]=r,s=a$g(i?.basePath),a=e$5(r);if(useEffect(()=>{n(true);},[]),!t)return null;let c=[{path:s,element:jsx(Ol,{config:r}),errorElement:jsx(Vl,{}),children:[{path:":projectId",element:jsx(Es,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:a.map(u=>({path:u.name,element:u.component,errorElement:jsx(Di,{}),children:u.routes?.map(f=>({path:f.path,element:f.component,errorElement:jsx(Di,{}),children:f.children?.map(m=>({path:m.path,element:m.component}))}))}))}]}],l=createBrowserRouter(c);return o("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Xs,{children:jsx(pg,{router:l})})})})}function Bl(e){return {basePath:a$g(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,plugins:e.plugins,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function hg(){return jsxs(ye,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Project Paused"}),jsxs(ve,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function vg(){let{schemaErrorMessage:e}=Kt();if(!e)return jsx(Fragment,{});let[t,n,...o]=e.split(`
|
|
397
|
-
`);return jsxs(ye,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Schema mismatch"}),jsxs(ve,{children:[jsx("p",{children:t}),n?jsx("p",{className:"fk:mt-1",children:n}):null,o.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:o.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function Cg(e){return e}function wg(e,t){if(e.dataType==="asset"&&e.scope!==void 0&&e.scope!=="global")throw new Error(`Attribute "${e.name}" in entity "${t}" uses dataType "asset" but scope "${e.scope}". Asset attributes must use scope "global" or omit scope.`)}function Sg(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function
|
|
398
|
-
${
|
|
399
|
-
`),d$3({variables:{where:qn(N)},update(O){for(let V of N)O.evict({id:V});},onCompleted:()=>{D();},onError:O=>{$(O);}}),m(true);});}function F(){let N=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${y.length} ${N}${y.length>1?"s":""}`,dialogMessage:y.length>1?`Are you sure you want to delete the selected ${N}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${N}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{h(true);try{let
|
|
396
|
+
`),A({variables:{where:{_id:{eq:o}}},onCompleted:z=>{i.current?.applyLocalAttributeIds(ua(z,r,c)),At(y,Ke(r,c)),toast.success("Your changes have been saved.");}}),b$1(true);},[y,O.user,d$3,o,r,b$1,c,E,A]),_=C,U=_.length>0,W=M&&!U;function se(J,ae){let ke=e$4(J),z=ke?.name,q=ke?.relationship?.field!==void 0;if(!ae.length||!z)return "";if(!q||!ke?.relationship?.field)return ae[0][z]?.value;let he=ae[0][z]?.value?.[ke.relationship.field],L=Array.isArray(he)?he[0]:he;if(L&&typeof L=="object"){let G=L;return G[d$3]??G.default??""}return L??""}let oe=U&&f?se(f,_):"";return jsx(g$3,{actions:jsxs(Fragment,{children:[l&&l.length>1?jsxs(a$5,{onValueChange:J=>{te(J);},value:d$3,children:[jsxs(d$1,{className:"fk:w-[12rem] fk:h-9",id:"project",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:\xA0"}),jsx(c$1,{children:find(propEq(d$3,"name"))(l).label})]}),jsx(e$1,{children:l.map(J=>jsx(g$1,{value:J.name,children:J.label},J.name))})]}):null,jsx(bi,{handleSave:Z,isLoading:F.loading})]}),beforeClose:R,depth:t,forceClose:D,isFocused:n,onClose:()=>{B(e._id);},onFormChange:()=>{},title:oe,children:W||!U?jsx(Ci,{}):jsxs(Fragment,{children:[F.isProjectReadOnly?jsx(Tl,{}):null,jsx(Xo,{currentScope:d$3,defaultScope:u,entityId:o,entityName:m,entityNamePlural:r,formData:_[0],onSubmit:k,ref:i,schema:c,setIsDirty:V})]})})}var Ml=25;function Kp(e){return e.map(t=>({...t,cell:()=>jsx(r$1,{className:"fk:h-4 fk:w-full",style:{marginTop:"7px",marginBottom:"6px"}})}))}function Ti({action:e,depth:t,isFocused:n}){let o=pe(),r=d$2(),{relationships:i,scope:s}=c$2(),{assetAccept:a,connectedEntitiesCount:c,connectionName:l,entityId:u,entityName:f,initialAssetPath:m,initialConnection:p,mode:d$1,relationshipId:g}=e.payload,{projects:h,currentProjectId:v}=d(),{schema:y}=find(propEq(v??"","projectId"))(h),b=find(propEq(f,"name"))(y),E=b?.plural??"",A=i[g],F=Gn(),N=f==="_asset",S=N?"asset":b?.menu?.label??f.toLowerCase(),D=N&&d$1==="single"?"Select asset":`Select ${N?"assets":S}`,$=d$1==="single"?"Upload asset":"Upload assets",[O,V]=useState([]),R=[];if(p)R=[{id:p._id,value:p.value}];else if(A?.connect){let P=A.connect;R=[{id:P._id,value:P.value}];}let B=d$1==="single"?R:A?.connect?.map(P=>({id:P._id,value:P.value}))||[],[Z,te]=useState(B),M=useMemo(()=>{let P=[];return N&&P.push({NOT:{path:{eq:null}}}),d$1==="multiple"&&l&&u&&P.push({[l]:{none:{_id:{eq:u}}}}),O.length>0&&P.push({OR:O.map(H=>({_id:{eq:H._id}}))}),P.length===0?{}:P.length===1?P[0]:{AND:P}},[l,u,N,d$1,O]),{count:C,data:k,fetchMore:_,isLoading:U,isLoadingMore:W}=ro({entityNamePlural:E,schema:y,scope:s,variables:{offset:0,limit:Ml,where:M,sort:[{_updatedAt:"DESC"},{_id:"DESC"}]},selection:"list"}),se=!!k?.length,oe=U&&!se,J=k?.length??0,ae=C-c,ke=ae>0&&J>0&&J<ae,z=Yn({attributesSchema:b?.attributes??[],checkboxSelect:d$1}),q=Array(5).fill({}),he=Kp(z);useEffect(()=>{if(d$1!=="single"||Z.length>0||!m||!k?.length)return;let P=k.find(H=>H.path===m);!P?._id||typeof P._id!="string"||te([{id:P._id,value:P}]);},[k,m,d$1,Z.length]);let L=useCallback(P=>{o({type:"Dismiss",_id:P,payload:{}});},[o]),G=useCallback(()=>{_({variables:{offset:0,limit:Ml,where:M}});},[M,_]);function Y(){let P;if(d$1==="single"){let[H]=Z;P={_id:H?.id??"",value:H?.value??null};}d$1==="multiple"&&(P=Z?.map((H,le)=>({_id:H.id??"",...N?{sortOrder:le}:{},value:H.value}))),r({type:"setRelationship",payload:{[g]:{connect:P,disconnect:A?.disconnect??[]}}}),L(e._id);}function j(P){if(d$1==="multiple"){te(le=>{let ce=new Map(le.map(Q=>[Q.id,Q]));return P.map(Q=>{if(ce.has(Q))return ce.get(Q);let on=k?.find(rn=>rn._id===Q);return {id:Q,value:on}})});return}let H=P[P.length-1];te(H?le=>{if(le.length===1&&le[0].id===H)return le;let ce=k?.find(Q=>Q._id===H);return [{id:H,value:ce}]}:[]);}function ee(){o({type:"AddEntity",payload:{entityName:f}});}async function x(){let P=await F({projectId:v,accept:a??"image/*",multiple:d$1==="multiple",maxBytes:4194304});te(H=>{if(d$1==="single"){let[Q]=P;return Q?[{id:Q._id,value:Q.asset}]:H}let le=new Set(H.map(Q=>Q.id)),ce=P.filter(Q=>!le.has(Q._id)).map(Q=>({id:Q._id,value:Q.asset}));return [...H,...ce]});}return jsx(g$3,{actions:jsxs(Fragment,{children:[jsx(b$3,{className:"fk:px-8",onClick:()=>{Y();},variant:"default",children:"Select"}),N?null:jsx(b$3,{className:"fk:px-8",onClick:()=>{ee();},variant:"outline",children:`Create ${S}`}),N?jsxs(b$3,{className:"fk:px-8",onClick:()=>{x();},variant:"outline",children:[jsx(Upload,{className:"fk:mr-2 fk:h-4 fk:w-4"}),$]}):null]}),depth:t,isFocused:n,onClose:()=>{L(e._id);},title:D,children:jsx("div",{className:"fk:h-[calc(100vh-10rem)] fk:min-h-0",children:jsx(eo,{columns:oe?he:z,data:oe?q:k??[],entityName:b?.name??"",hasMore:ke,initialSelectionState:Z?.reduce((P,H)=>({...P,...H.id?{[H.id]:true}:{}}),{}),isLoadingMore:W,onEntitySelectionChange:j,onLoadMore:G,toolbarComponent:()=>jsx(Zp,{entityNamePlural:E,projectId:v??"",setSearchResultIds:V})})})})}function Zp({entityNamePlural:e,projectId:t,setSearchResultIds:n}){let[o,r]=useState(""),i=useMemo(()=>({searchRequests:{searches:[{collection:e}]},commonParams:{q:""}}),[e]),[s,a]=useState(i),{results:c,isLoading:l}=f$4(t,s),u=useRef(null),f=useMemo(()=>Yp(p=>{a({...i,commonParams:{q:p}});},300),[i]);useEffect(()=>{if(c){let p=JSON.stringify(c.map(g=>g._id).sort()),d=u.current?JSON.stringify(u.current.map(g=>g._id).sort()):"";p!==d&&(u.current=[...c],n(c.map(g=>({_id:g._id}))));}},[c,n]);function m(p){let{value:d}=p.target;r(d),f(d);}return jsxs("div",{className:"fk:relative fk:w-full",children:[l?jsx(LoaderCircle,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50 fk:animate-spin"}):jsx(Search,{className:"fk:absolute fk:left-4 fk:top-3 fk:h-4 fk:w-4 fk:shrink-0 fk:opacity-50"}),jsx(a$7,{className:"fk:w-full fk:pl-11!",onChange:m,placeholder:"Search",value:o})]})}function Yp(e,t=300){let n;return (...o)=>{clearTimeout(n),n=setTimeout(()=>e(...o),t);}}function $l(){let e=Ws(),t=e.filter(o=>["AddEntity","EditEntity","EditRelationship"].some(r=>r===o.type)),n=t[t.length-1]?._id;return jsx(Fragment,{children:e.map(o=>{switch(o.type){case "AlertDialog":{let{payload:r}=o;return jsx(_n,{options:r.options},o._id)}case "DeleteEntity":return jsx(Ir,{action:o},o._id);case "AddEntity":return jsx(hi,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditEntity":return jsx(Si,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);case "EditRelationship":return jsx(Ti,{action:o,depth:t.length-1,isFocused:o._id===n},o._id);default:return null}})})}function Ol({config:e}){let[t]=e,{basePath:n,projectId:o}=t,r=a$g(n);return window.location.pathname===r&&(window.location.href=b$a(r,o)),jsx(a$j,{children:jsx(c$7,{config:e,children:jsxs(Ms,{children:[jsx(ya,{children:jsx($l,{})}),jsx(Outlet,{})]})})})}function Vl(){let e=useRouteError(),t=new Date().getFullYear();function n(){return isRouteErrorResponse(e)?e.status===404?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-7xl fk:text-center fk:font-bold fk:tracking-tight",children:"404"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Page not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.statusText})})]}):dr(e)?gs(e)==="PROJECT_NOT_FOUND"?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Project not found"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"The requested project ID was not found"})]}):jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred. Please try again."})]}):e instanceof Error?jsxs(Fragment,{children:[jsx("h1",{className:"fk:mb-4 fk:text-4xl fk:text-center fk:font-bold fk:tracking-tight",children:"Oops!"}),jsx("p",{className:"fk:mt-2 fk:mb-2 fk:text-base fk:text-center fk:text-muted-foreground",children:"Sorry, an unexpected error has occurred:"}),jsx("p",{className:"fk:text-base fk:text-center",children:jsx("i",{children:e.message})})]}):null}return jsxs(Fragment,{children:[jsx("div",{className:"fk:container fk:relative fk:h-[calc(100vh-3rem)] fk:flex fk:items-center fk:justify-center fk:lg:px-0",children:jsx("div",{className:"fk:w-full fk:lg:p-8",children:jsx("div",{className:"fk:mx-auto fk:flex fk:w-full fk:flex-col fk:justify-center fk:sm:w-[350px]",children:n()})})}),jsx("div",{className:"fk:flex fk:justify-center fk:items-center fk:h-12 fk:text-xs fk:text-muted-foreground fk:border-t fk:border-accent",children:jsxs("div",{className:"fk:container fk:flex",children:[jsxs("div",{className:"fk:flex fk:items-center fk:mr-auto",children:[jsxs("svg",{className:"fk:h-5 fk:w-5 fk:mr-3 fk:text-black fk:dark:text-white",fill:"none",height:"48",viewBox:"0 0 48 48",width:"48",xmlns:"http://www.w3.org/2000/svg",children:[jsx("path",{d:"M7 8H41V40H7V8Z",fill:"none"}),jsx("path",{d:"M24 0C42 0 48 6 48 24C48 42 42 48 24 48C6 48 0 42 0 24C0 6 6 0 24 0ZM17.7494 9.52381H8.7619L19.2833 23.8313L8.7619 38.7078H17.7494L21.0499 33.6639V14.2549L17.7494 9.52381ZM38.9577 9.52381H29.9542L26.2857 14.8229V33.0406L29.9542 38.7078H38.9577L28.3908 23.8313L38.9577 9.52381Z",fill:"currentColor"})]}),jsxs("p",{className:"fk:flex fk:items-center",children:["\xA9 ",t]})]}),jsx(ho,{})]})})]})}function Di(){let e=useRouteError(),t=e instanceof Error?e.message:"An unexpected error has occurred. Please try refreshing the page.";return jsxs(ye,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Error"}),jsx(ve,{children:t})]})}var pg=RouterProvider;function gg({config:e}){let[t,n]=useState(false),o=debug("core:flexkit-studio"),r=Array.isArray(e)?e.map(u=>Bl(u)):[Bl(e)],[i]=r,s=a$g(i?.basePath),a=e$5(r);if(useEffect(()=>{n(true);},[]),!t)return null;let c=[{path:s,element:jsx(Ol,{config:r}),errorElement:jsx(Vl,{}),children:[{path:":projectId",element:jsx(Es,{version:{current:"1.0.0",latest:"1.0.0",isCurrent:true}}),children:a.map(u=>({path:u.name,element:u.component,errorElement:jsx(Di,{}),children:u.routes?.map(f=>({path:f.path,element:f.component,errorElement:jsx(Di,{}),children:f.children?.map(m=>({path:m.path,element:m.component}))}))}))}]}],l=createBrowserRouter(c);return o("Init Studio"),jsx(a$h,{attribute:"class",defaultTheme:"system",disableTransitionOnChange:true,enableSystem:true,children:jsx(b$9,{children:jsx(Xs,{children:jsx(pg,{router:l})})})})}function Bl(e){return {basePath:a$g(e.basePath),menuGroups:e.menuGroups??[],icon:e.icon,extensions:e.extensions,projectId:e.projectId,title:e.title,schema:e.schema,scopes:e.scopes}}function hg(){return jsxs(ye,{variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Project Paused"}),jsxs(ve,{children:["This project has been paused. To troubleshoot this error, please"," ",jsx("a",{className:"fk:text-blue-500 fk:underline",href:"https://flexkit.io/docs/errors/project-paused",target:"_blank",rel:"noopener noreferrer",children:"follow these steps"}),"."]})]})}function vg(){let{schemaErrorMessage:e}=Kt();if(!e)return jsx(Fragment,{});let[t,n,...o]=e.split(`
|
|
397
|
+
`);return jsxs(ye,{className:"fk:mb-4",variant:"destructive",children:[jsx(AlertCircle,{className:"fk:h-4 fk:w-4"}),jsx(qe,{children:"Schema mismatch"}),jsxs(ve,{children:[jsx("p",{children:t}),n?jsx("p",{className:"fk:mt-1",children:n}):null,o.length>0?jsx("ul",{className:"fk:mt-2 fk:list-disc fk:pl-4",children:o.map(r=>jsx("li",{children:r.replace(/^- /,"")},r))}):null]})]})}function Cg(e){return e}function wg(e){return e}function xg(e,t){if(e.dataType==="asset"&&e.scope!==void 0&&e.scope!=="global")throw new Error(`Attribute "${e.name}" in entity "${t}" uses dataType "asset" but scope "${e.scope}". Asset attributes must use scope "global" or omit scope.`)}function Sg(e){return e.dataType!=="asset"?e:{...e,scope:"global"}}function Eg(e){let t=e.display?e.attributes.find(n=>n.name===e.display):e.attributes[0];if(e.display&&!t)throw new Error(`Entity "${e.name}" sets display to "${e.display}", but no attribute has that name.`);if(!(!t||(t.spaces??[]).length===0))throw new Error(`Entity "${e.name}" cannot use space-bound attribute "${t.name}" as its display field.`)}function Hl(e){return e.attributes.forEach(t=>{xg(t,e.name);}),Eg(e),{...e,attributes:e.attributes.map(Sg)}}function Ag(e){return Hl(e)}function Dg(e){let t=useApolloClient(),{currentProjectSchema:n}=d();return useCallback(async()=>{n&&await At(t,Ke(e,n));},[t,e,n])}function Rg(e){let{currentProjectSchema:t}=d();return useCallback(n=>{t&&ga(Ke(e,t),n);},[e,t])}function Lg({column:e,title:t,options:n}){let o=new Set(e?.getFilterValue());return jsxs(Cn,{children:[jsx(wn,{asChild:true,children:jsxs(b$3,{variant:"outline",size:"sm",className:"fk:h-8 fk:border-dashed",children:[jsx(CirclePlus,{className:"fk:mr-2 fk:h-4 fk:w-4"}),t,o?.size>0&&jsxs(Fragment,{children:[jsx(c$5,{orientation:"vertical",className:"fk:mx-2 fk:h-4"}),jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal fk:lg:hidden",children:o.size}),jsx("div",{className:"fk:space-x-1 fk:lg:flex",children:o.size>2?jsxs(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:[o.size," selected"]}):n.filter(r=>o.has(r.value)).map(r=>jsx(b$6,{variant:"secondary",className:"fk:rounded-xs fk:px-1 fk:font-normal",children:r.label},r.value))})]})]})}),jsx(Bt,{className:"fk:w-50 fk:p-0",align:"start",children:jsxs(n$1,{children:[jsx(p$1,{placeholder:t}),jsxs(q$1,{children:[jsx(r,{children:"No results found."}),jsx(s$1,{children:n.map(r=>{let i=o.has(r.value);return jsxs(u$1,{onSelect:()=>{i?o.delete(r.value):o.add(r.value);let s=Array.from(o);e?.setFilterValue(s.length?s:void 0);},children:[jsx("div",{className:a$1("fk:mr-2 fk:flex fk:h-4 fk:w-4 fk:items-center fk:justify-center fk:rounded-xs fk:border fk:border-primary",i?"fk:bg-primary fk:text-primary-foreground":"fk:opacity-50 fk:[&_svg]:invisible"),children:jsx(Check,{className:a$1("fk:size-3.5",i?"fk:text-primary-foreground":"fk:text-muted-foreground")})}),r.icon&&jsx(r.icon,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:text-muted-foreground"}),jsx("span",{children:r.label})]},r.value)})}),o.size>0&&jsxs(Fragment,{children:[jsx(t$1,{}),jsx(s$1,{children:jsx(u$1,{onSelect:()=>e?.setFilterValue(void 0),className:"fk:justify-center fk:text-center",children:"Clear filters"})})]})]})]})})]})}function _g({entityName:e,entityNamePlural:t,row:n,options:o={canDelete:true,canEdit:true}}){let r=pe(),i=Ft(),s=n.original._id,a=(o.canDelete??true)&&i,c=o.canEdit??true;function l(){r({type:"EditEntity",payload:{entityId:s,entityNamePlural:t}});}function u(){r({type:"DeleteEntity",payload:{entityId:s,entityName:e}});}return jsxs("div",{className:"fk:flex",children:[c&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:l,variant:"ghost",children:[jsx(PencilIcon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Edit"})]}),a&&!c&&jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0 fk:mr-1",onClick:u,variant:"ghost",children:[jsx(Trash2Icon,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Delete"})]}),c&&a&&jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:flex fk:h-7 fk:w-7 fk:p-0",variant:"ghost",children:[jsx(Ellipsis,{className:"fk:h-4 fk:w-4"}),jsx("span",{className:"fk:sr-only",children:"Additional actions"})]})}),jsxs(f$2,{align:"end",className:"w-[160px]",children:[jsxs(h$2,{onClick:l,children:[jsx(PencilIcon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Edit"]}),jsx(m,{}),jsxs(h$2,{className:"fk:text-destructive",onClick:u,children:[jsx(Trash2Icon,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete"]})]})]})]})}function Ri({table:e}){let[t]=e.getState().sorting;if(!t)return null;let o=e.getColumn(t.id)?.columnDef.meta?.label??t.id,r=t.desc?"desc":"asc";return jsxs(b$3,{"aria-label":`Clear sorting by ${o}`,className:"fk:h-8 fk:px-2 fk:lg:px-3 fk:text-success fk:border-none",onClick:()=>{e.resetSorting();},size:"sm",variant:"outline",children:["Sorted by ",o," ",r,jsx(X,{className:"fk:ml-1 fk:h-4 fk:w-4"})]})}function Ii({table:e}){return jsxs(c$3,{children:[jsx(e$2,{asChild:true,children:jsxs(b$3,{className:"fk:hidden fk:h-8 fk:lg:flex",size:"sm",variant:"outline",children:[jsx(Settings2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"View"]})}),jsxs(f$2,{align:"end",className:"fk:w-[150px]",children:[jsx(l$1,{children:"Toggle columns"}),jsx(m,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>jsx(i$2,{checked:t.getIsVisible(),className:"capitalize",onCheckedChange:n=>{t.toggleVisibility(!!n);},children:t.id},t.id))]})]})}function Gg({entityName:e,isReloading:t=false,onReload:n,table:o}){let r=pe(),i=d$2(),s=c$2(),a=useApolloClient(),{projects:c,currentProjectId:l}=d(),{schema:u,scopes:f}=find(propEq(l??"","projectId"))(c),[m,p,d$3]=xt(),[g,h]=useState(false),v=Ft(),y=o.getSelectedRowModel().rows.map(N=>N.original._id);function b(){r({type:"AddEntity",payload:{entityName:e}});}function E(N){i({type:"setScope",payload:{projectId:l,scope:N}});}async function A(N){if(N.length===0)return;let S=Un(e,u,N);await new Promise((D,$)=>{p(gql`
|
|
398
|
+
${S}
|
|
399
|
+
`),d$3({variables:{where:qn(N)},update(O){for(let V of N)O.evict({id:V});},onCompleted:()=>{D();},onError:O=>{$(O);}}),m(true);});}function F(){let N=e==="_asset"?"asset":e.toLowerCase();r({type:"AlertDialog",payload:{options:{dialogTitle:`Delete ${y.length} ${N}${y.length>1?"s":""}`,dialogMessage:y.length>1?`Are you sure you want to delete the selected ${N}s? They will be deleted permanently.`:`Are you sure you want to delete the selected ${N}? The item will be deleted permanently.`,dialogCancelTitle:"Cancel",dialogActionLabel:"Delete",isDestructive:true,dialogActionSubmit:async()=>{h(true);try{let S=[...y];await A(S),o.resetRowSelection(),await Do(a,Ke(e,u),S),toast.success(S.length>1?"Items successfully deleted.":"Item successfully deleted.");}catch{toast.error("Failed to delete selected items.");}finally{h(false);}},dialogActionCancel:()=>{}}}});}return jsxs("div",{className:"fk:flex fk:items-center fk:justify-between",children:[jsxs("div",{className:"fk:flex fk:flex-1 fk:items-center fk:space-x-2",children:[f&&f.length>0?jsxs(a$5,{defaultValue:s.scope,onValueChange:N=>{E(N);},value:s.scope,children:[jsxs(d$1,{className:"fk:w-48!",id:"project",size:"sm",children:[jsx("span",{className:"fk:text-muted-foreground",children:"Scope:"}),jsx(c$1,{children:(find(propEq(s.scope??"","name"))(f)||null)?.label})]}),jsx(e$1,{children:f.map(N=>jsx(g$1,{value:N.name,children:N.label},N.name))})]}):null,jsx(Ii,{table:o}),n?jsx(b$3,{"aria-label":"Reload",className:"fk:h-8",disabled:g||t,onClick:n,size:"icon-sm",variant:"outline",children:jsx(RefreshCw,{className:t?"fk:animate-spin":void 0})}):null,jsx(Ri,{table:o})]}),y.length>0?jsx(x$1,{disabled:!v,children:jsxs(b$3,{className:"fk:h-8 fk:mr-2 fk:lg:flex",disabled:g||!v,onClick:F,size:"sm",variant:"destructive",children:[g?jsx(Loader2,{className:"fk:mr-2 fk:h-4 fk:w-4 fk:animate-spin"}):jsx(Trash2,{className:"fk:mr-2 fk:h-4 fk:w-4"}),"Delete (",y.length,")"]})}):null,jsx(x$1,{disabled:!v,children:jsx(b$3,{className:"fk:ml-auto fk:h-8 fk:lg:flex",disabled:g||!v,onClick:b,size:"sm",variant:"default",children:"Create"})})]})}export{ci as ALL_FIELDS_GROUP,tn as ALL_FIELDS_GROUP_NAME,eo as DataTable,zo as DataTableColumnHeader,Lg as DataTableFacetedFilter,_g as DataTableRowActions,Ri as DataTableSortedBy,Gg as DataTableToolbar,Ii as DataTableViewOptions,gg as FlexkitStudio,hg as ProjectDisabled,vg as SchemaError,Lr as canAccessSpaces,bl as canMutateData,Cg as defineConfig,Ag as defineEntity,wg as defineExtension,vn as filterAttributesForSpaces,ef as filterEntitiesForSpaces,Nr as getEntityCreateMutation,Un as getEntityDeleteMutation,qn as getEntityDeleteWhere,jn as getEntityQuery,rt as getEntitySchema,Ar as getEntityUpdateMutation,Tu as getSortNotNullWhere,Ft as useCanMutate,pe as useDispatch,xt as useEntityMutation,ro as useEntityQuery,Kt as useGraphQLError,Yn as useGridColumnsDefinition,Rg as usePatchEntityList,Dg as useRefreshEntityList,Gn as useUploadAssets};//# sourceMappingURL=index.js.map
|
|
400
400
|
//# sourceMappingURL=index.js.map
|