@overmap-ai/forms 1.0.17-master.5 → 1.0.17-master.7
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/forms.js +209 -213
- package/dist/forms.umd.cjs +1 -1
- package/package.json +4 -4
package/dist/forms.umd.cjs
CHANGED
|
@@ -42,4 +42,4 @@
|
|
|
42
42
|
|
|
43
43
|
If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
44
44
|
|
|
45
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},Mo="DialogDescriptionWarning",Ao=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${fr(Mo).contentName}}.`;return v.useEffect(()=>{var a;const o=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},Pe=nr,Me=or,Ae=ar,Oe=lr;const Re=500,ye=1e4,ne={danger:"danger",warning:"warning",info:"base",success:"success"},kt={xs:"0",sm:"768px",md:"1024px",lg:"1024px",xl:"1280px"},Vt=d.memo(t=>{const{file:n,onClose:e,onDelete:r}=t,{md:o}=u.useViewportSize(kt),a=d.useRef(null),l=d.useRef(null),s=d.useRef(null),p=d.useCallback(()=>{if(!l.current||!a.current||!s.current)return;const h=s.current.height-l.current.clientHeight,g=s.current.width-l.current.clientWidth;h>=0||g>=0?g>h?(a.current.style.width=`${l.current.clientWidth}px`,a.current.style.height="unset"):(a.current.style.height=`${l.current.clientHeight}px`,a.current.style.width="unset"):(a.current.style.width=`${s.current.width}px`,a.current.style.height=`${s.current.height}px`)},[]),c=d.useCallback(()=>{r&&r(n)},[n,r]),f=d.useCallback(()=>{j.downloadFile(n)},[n]);return d.useLayoutEffect(()=>{const h=new Image;h.onload=()=>{s.current={width:h.width,height:h.height},p()},h.src=URL.createObjectURL(n)},[p,n]),d.useLayoutEffect(()=>{if(!l.current)return;const h=new ResizeObserver(()=>{p()});return h.observe(l.current),()=>{h.disconnect()}},[p]),i.jsx(Pe,{open:!0,onOpenChange:e,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs("div",{className:"flex h-full w-full flex-col",children:[i.jsx("div",{className:"flex h-max w-full items-center bg-(--color-background) p-2",children:i.jsx(u.ButtonGroup,{className:"w-full",accentColor:"base",variant:"soft",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex justify-start gap-2 items-center",children:[i.jsx(u.IconButton,{onClick:e,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{onClick:f,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsx("div",{className:"flex justify-center",children:i.jsx(_e,{file:n,accentColor:"base",truncateLength:o?void 0:25})}),i.jsx("div",{className:"flex justify-end",children:!!r&&i.jsx(u.IconButton,{onClick:c,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})})]})})}),i.jsx("div",{className:"h-full w-full overflow-hidden p-5",children:i.jsx("div",{className:"flex h-full w-full items-center justify-center overflow-hidden",ref:l,children:i.jsx("img",{ref:a,src:URL.createObjectURL(n),alt:""})})})]})})]})})});Vt.displayName="ImageViewer";const jt=["application/pdf"];yt.pdfjs.GlobalWorkerOptions.workerSrc=new URL("pdfjs-dist/build/pdf.worker.min.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:bt&&bt.tagName.toUpperCase()==="SCRIPT"&&bt.src||new URL("forms.umd.cjs",document.baseURI).href).toString();const Oo={initial:.6,xs:.8,sm:.9,md:1,lg:1.1,xl:1.1},Ut=d.memo(t=>{const{file:n,onDelete:e,onClose:r}=t,[o,a]=d.useState(null),[l,s]=d.useState(0),[p,c]=d.useState(!1),{lg:f,size:h}=u.useViewportSize(kt);d.useEffect(()=>{s(0),c(!1),a(null)},[n]);const g=d.useCallback(b=>{s(0),a(b)},[]),y=d.useCallback(()=>{c(!0)},[]),x=d.useCallback(()=>{!o||l===o.numPages-1||s(b=>b+1)},[l,o]),m=d.useCallback(()=>{j.downloadFile(n)},[n]),w=d.useCallback(()=>{l!==0&&s(b=>b-1)},[l]),E=d.useCallback(()=>{e&&e(n)},[n,e]);return i.jsx(Pe,{open:!0,onOpenChange:r,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs("div",{className:"flex h-full w-full flex-col items-center",children:[i.jsx("div",{className:"h-max w-full shrink-0 items-center bg-(--color-background) p-2",children:i.jsx(u.ButtonGroup,{className:"flex items-center gap-1",variant:"soft",accentColor:"base",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"w-full gap-2 flex items-center",children:[i.jsx(u.IconButton,{onClick:r,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{onClick:m,"aria-label":"download",children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsx("div",{className:"flex justify-center",children:i.jsx(_e,{file:n,accentColor:"base",truncateLength:f?void 0:25})}),i.jsx("div",{className:"flex justify-end",children:!!e&&i.jsx(u.IconButton,{onClick:E,"aria-label":"delete",children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})})]})})}),i.jsxs("div",{className:"relative flex h-full w-full flex-col items-center gap-2 p-3",children:[!o&&!p&&i.jsx(hr,{}),i.jsx("div",{className:"flex h-max max-h-full w-max max-w-full flex-col items-center justify-center overflow-auto [scrollbar-color:var(--base-6)_transparent] [scrollbar-width:thin]",children:i.jsxs(yt.Document,{className:"relative",file:n,onLoadSuccess:g,onLoadError:y,error:"",loading:"",children:[i.jsx(yt.Page,{scale:Oo[h],pageIndex:l}),!!o&&!p&&i.jsx("div",{className:"absolute top-0 z-[2] flex w-full justify-center py-2",children:i.jsxs(u.ButtonGroup,{variant:"solid",accentColor:"base",size:"sm",children:[i.jsx(u.IconButton,{onClick:w,"aria-label":"previous page",children:i.jsx(u.RiIcon,{icon:"RiArrowLeftLine"})}),i.jsxs(u.Badge,{accentColor:"base",style:{borderRadius:0},variant:"solid",children:[l+1,"/",o.numPages]}),i.jsx(u.IconButton,{onClick:x,"aria-label":"next-page",children:i.jsx(u.RiIcon,{icon:"RiArrowRightLine"})})]})})]})}),p&&i.jsx(pr,{})]})]})})]})})});Ut.displayName="PDFViewer";const hr=d.memo(()=>i.jsx("div",{className:"absolute flex h-full w-full items-center justify-center",children:i.jsx(u.Spinner,{})}));hr.displayName="SpinnerComponent";const pr=d.memo(()=>i.jsxs("div",{className:"flex h-[70%] w-[40%] flex-col items-center justify-center rounded-md border border-(--base-a6) bg-(--base-2)",children:[i.jsx(u.RiIcon,{icon:"RiFileWarningLine",size:40}),i.jsx("span",{className:"text-sm font-light text-(--accent-a11)","data-accent-color":"base",children:"Failed to load"})]}));pr.displayName="ErrorComponent";const Wt=["text/csv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],qt=d.memo(t=>{const{file:n,onClose:e,onDelete:r}=t,{md:o}=u.useViewportSize(kt),[a,l]=d.useState([]),[s,p]=d.useState({}),[c,f]=d.useState(),[h,g]=d.useState({rowLabels:[],columnLabels:[],data:[[]]}),y=d.useMemo(()=>d.lazy(()=>import("react-spreadsheet")),[]);d.useEffect(()=>{n.arrayBuffer().then(b=>{const{SheetNames:S,Sheets:I}=En.read(b);l(S),p(I),f(S[0])})},[n]),d.useEffect(()=>{if(!c)return;const b=s[c],S=En.utils.sheet_to_json(b),I=Object.keys(S[0]??{}).splice(1),F=S.map(T=>Object.values(T)[0]),L=S.map(T=>I.map(M=>({value:T[M],readOnly:!0})));g({rowLabels:F,columnLabels:I,data:L})},[c,s]);const x=d.useCallback(()=>{r&&r(n)},[n,r]),m=d.useCallback(()=>{j.downloadFile(n)},[n]),w=d.useCallback(()=>{if(!c)throw new Error(`Expected an activeSheet, got ${c}`);const b=a.indexOf(c);if(b<0)throw new Error(`Expected activeSheet to be present in sheets, ${c} not found in ${a.join(", ")}`);b!==a.length-1&&f(a[b+1])},[c,a]),E=d.useCallback(()=>{if(!c)throw new Error(`Expected an activeSheet, got ${c}`);const b=a.indexOf(c);if(b<0)throw new Error(`Expected activeSheet to be present in sheets, ${c} not found in ${a.join(", ")}`);b!==0&&f(a[b-1])},[c,a]);return i.jsx(Pe,{open:!0,onOpenChange:e,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden",children:[i.jsx("div",{className:"h-max w-full shrink-0 bg-(--color-background) p-2",children:i.jsx(u.ButtonGroup,{size:"md",variant:"soft",accentColor:"base",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx(u.IconButton,{onClick:e,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{onClick:m,"aria-label":"download",children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsx("div",{className:"flex justify-center",children:i.jsx(_e,{file:n,accentColor:"base",truncateLength:o?void 0:25})}),i.jsx("div",{className:"flex justify-end gap-2",children:!!r&&i.jsx(u.IconButton,{"aria-label":"delete",onClick:x,children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})})]})})}),i.jsx("div",{className:"flex h-full w-full flex-col items-center gap-3 overflow-hidden p-2",children:i.jsxs(d.Suspense,{fallback:i.jsx(u.Spinner,{}),children:[i.jsx("div",{className:"flex h-max max-h-[calc(100%-50px)] w-max max-w-full overflow-auto [scrollbar-color:var(--base-6)_transparent] [scrollbar-width:thin]",children:i.jsx(y,{className:"z-[1] h-full",data:h.data,rowLabels:h.rowLabels,columnLabels:h.columnLabels})}),i.jsx("div",{className:"flex h-max shrink-0 bg-(--base-2)",children:i.jsxs(u.ButtonGroup,{className:"flex items-center",variant:"solid",accentColor:"base",size:"sm",children:[i.jsx(u.IconButton,{"aria-label":"previous",onClick:E,children:i.jsx(u.RiIcon,{icon:"RiArrowLeftLine"})}),i.jsx(u.Badge,{variant:"solid",size:"sm",style:{borderRadius:0},accentColor:"base",children:c}),i.jsx(u.IconButton,{"aria-label":"next",onClick:w,children:i.jsx(u.RiIcon,{icon:"RiArrowRightLine"})})]})})]})})]})})]})})});qt.displayName="SpreadsheetViewer";const Be=d.memo(t=>{const{fileType:n}=t,e=d.useMemo(()=>Wt.includes(n)?i.jsx(u.RiIcon,{icon:"RiFileExcelLine"}):jt.includes(n)?i.jsx(u.RiIcon,{icon:"RiFilePdfLine"}):xt.includes(n)?i.jsx(u.RiIcon,{icon:"RiFileImageLine"}):i.jsx(u.RiIcon,{icon:"RiFileLine"}),[n]);return i.jsx("div",{className:"h-max w-max",children:e})});Be.displayName="FileIcon";const _e=d.memo(t=>{const{file:n,truncateLength:e,hideName:r=!1,...o}=t,a=d.useMemo(()=>e!==void 0?j.truncate(n.name,e):n.name,[n.name,e]);return i.jsxs(u.Badge,{...o,children:[i.jsx(Be,{fileType:n.type}),!r&&a]})});_e.displayName="FileBadge";function mr(t){var n,e,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var o=t.length;for(n=0;n<o;n++)t[n]&&(e=mr(t[n]))&&(r&&(r+=" "),r+=e)}else for(e in t)t[e]&&(r&&(r+=" "),r+=e);return r}function Bo(){for(var t,n,e=0,r="",o=arguments.length;e<o;e++)(t=arguments[e])&&(n=mr(t))&&(r&&(r+=" "),r+=n);return r}const we=Bo,Ht=d.memo(d.forwardRef((t,n)=>{const{file:e,className:r,error:o,truncateLength:a,rightSlot:l,...s}=t,p=d.useMemo(()=>{if(e)return a!==void 0?j.truncate(e.name,a):e.name},[e,a]);return i.jsxs("div",{className:we(r,"flex h-5 w-full items-center gap-2 rounded-md border border-(--base-a6) bg-(--base-2) text-sm py-1 px-2 h-max",{"text-(--gray-11)":o}),ref:n,...s,children:[o?i.jsx(u.RiIcon,{icon:"RiFileWarningLine"}):i.jsx(Be,{fileType:(e==null?void 0:e.type)??""}),o||(e?p:i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(u.Spinner,{})})),l]})}));Ht.displayName="FileCard";const Gt=d.createContext(()=>{throw new Error("No FileViewerProvider found")}),gr=()=>d.useContext(Gt),vr=d.memo(t=>{const{children:n}=t,[e,r]=d.useState(null),[o,a]=d.useState(null),l=d.useCallback(()=>{r(null),a(null)},[]),s=d.useCallback(f=>{r(f(l))},[l]),p=d.useCallback(()=>{e&&(e.onClose&&e.onClose(),l())},[l,e]);d.useEffect(()=>{if(!e)return;const{file:f}=e;if(Wt.includes(f.type)){a("spreadsheet");return}if(jt.includes(f.type)){a("pdf");return}if(xt.includes(f.type)){a("image");return}},[e]);const c=d.useMemo(()=>s,[s]);return i.jsxs(Gt.Provider,{value:c,children:[n,e&&i.jsxs(i.Fragment,{children:[o==="spreadsheet"&&i.jsx(qt,{file:e.file,onDelete:e.onDelete,onClose:p}),o==="pdf"&&i.jsx(Ut,{file:e.file,onDelete:e.onDelete,onClose:p}),o==="image"&&i.jsx(Vt,{file:e.file,onDelete:e.onDelete,onClose:p})]})]})});vr.displayName="FileViewerProvider";class Kt{constructor(n){N(this,"type");N(this,"identifier");N(this,"description");const{description:e=null,identifier:r,type:o}=n;this.identifier=r,this.description=e,this.type=o}getId(){return this.identifier}static deserialize(n){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}const G={label:"",description:"",required:!1};class W extends Kt{constructor(e){const{label:r,required:o,image:a,fieldValidators:l=[],formValidators:s=[],...p}=e;super(p);N(this,"required");N(this,"formValidators");N(this,"fieldValidators");N(this,"label");N(this,"image");N(this,"onlyValidateAfterTouched",!0);this.label=r,this.required=o,this.image=a,this.fieldValidators=l,this.formValidators=s}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,r){if(this.required&&this.isBlank(e))return"This field is required.";for(const o of this.getFieldValidators()){const a=o(e);if(a)return a}if(r)for(const o of this.getFormValidators()){const a=o(e,r);if(a)return a}}_serialize(){return{...super._serialize(),label:this.label,required:this.required,image:this.image}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}encodeValueToJson(e){return JSON.stringify(e)}decodeJsonToValue(e){return JSON.parse(e)}}N(W,"fieldTypeName"),N(W,"fieldTypeDescription");const z=t=>{const{id:n,field:e,formId:r,size:o,showInputOnly:a,internal:l,...s}=t,[p,c,f]=V.useField(e.getId()),{touched:h}=c,g=c.error??e.description,y=c.error?"danger":void 0,x=n??`${r}-${e.getId()}-input`,m=`${x}-label`,w=e.required?`${e.label} *`:e.label,E=d.useMemo(()=>({...p,onChange:I=>{const F=e.getValueFromChangeEvent(I);f.setValue(F,!1).then(),(h||!e.onlyValidateAfterTouched)&&f.setError(e.getError(F))},onBlur:I=>{f.setTouched(!0,!1).then(),f.setError(e.getError(e.getValueFromChangeEvent(I)))}}),[e,p,f,h]);return console.debug("severity",y),[{helpText:g,size:o,severity:y,inputId:x,labelId:m,label:w,showInputOnly:a,internal:l,fieldProps:E,helpers:f,field:e},{...s,"aria-labelledby":m}]};var et=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function _o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var tt={exports:{}},zo=tt.exports,yr;function $o(){return yr||(yr=1,function(t,n){(function(e,r){r()})(zo,function(){function e(c,f){return typeof f>"u"?f={autoBom:!1}:typeof f!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),f={autoBom:!f}),f.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(c.type)?new Blob(["\uFEFF",c],{type:c.type}):c}function r(c,f,h){var g=new XMLHttpRequest;g.open("GET",c),g.responseType="blob",g.onload=function(){p(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function o(c){var f=new XMLHttpRequest;f.open("HEAD",c,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(c){try{c.dispatchEvent(new MouseEvent("click"))}catch{var f=document.createEvent("MouseEvents");f.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),c.dispatchEvent(f)}}var l=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof et=="object"&&et.global===et?et:void 0,s=l.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),p=l.saveAs||(typeof window!="object"||window!==l?function(){}:"download"in HTMLAnchorElement.prototype&&!s?function(c,f,h){var g=l.URL||l.webkitURL,y=document.createElement("a");f=f||c.name||"download",y.download=f,y.rel="noopener",typeof c=="string"?(y.href=c,y.origin===location.origin?a(y):o(y.href)?r(c,f,h):a(y,y.target="_blank")):(y.href=g.createObjectURL(c),setTimeout(function(){g.revokeObjectURL(y.href)},4e4),setTimeout(function(){a(y)},0))}:"msSaveOrOpenBlob"in navigator?function(c,f,h){if(f=f||c.name||"download",typeof c!="string")navigator.msSaveOrOpenBlob(e(c,h),f);else if(o(c))r(c,f,h);else{var g=document.createElement("a");g.href=c,g.target="_blank",setTimeout(function(){a(g)})}}:function(c,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof c=="string")return r(c,f,h);var y=c.type==="application/octet-stream",x=/constructor/i.test(l.HTMLElement)||l.safari,m=/CriOS\/[\d]+/.test(navigator.userAgent);if((m||y&&x||s)&&typeof FileReader<"u"){var w=new FileReader;w.onloadend=function(){var S=w.result;S=m?S:S.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=S:location=S,g=null},w.readAsDataURL(c)}else{var E=l.URL||l.webkitURL,b=E.createObjectURL(c);g?g.location=b:location.href=b,g=null,setTimeout(function(){E.revokeObjectURL(b)},4e4)}});l.saveAs=p.saveAs=p,t.exports=p})}(tt)),tt.exports}var wr=$o();const ko=_o(wr),Xt=d.memo(t=>{const{file:n,url:e,name:r,setShowPreview:o}=t,a=d.useCallback(l=>{l.stopPropagation();const s=new Blob([n]);ko(s,r)},[r,n]);return i.jsxs(i.Fragment,{children:[i.jsx("button",{className:"fixed top-0 left-0 z-[5000] h-full w-full bg-[rgba(0,0,0,0.85)] bg-black",type:"button",onClick:()=>{o(!1)},children:i.jsx("img",{className:"absolute top-[50%] left-[50%] z-[5001] max-h-[calc(100%-120px)] max-w-svw translate-x-[-50%] translate-y-[50%] object-contain",src:e,alt:r,onClick:l=>{l.stopPropagation()}})}),i.jsxs("div",{className:"fixed top-0 left-0 z-[5001] flex w-full items-center bg-(--color-background)",children:[i.jsx(u.IconButton,{className:"min-w-[50px]",variant:"soft","aria-label":"Exit preview",onClick:()=>{o(!1)},children:i.jsx(u.RiIcon,{icon:"RiArrowLeftLine"})}),i.jsx("span",{className:"grow text-center",children:r}),i.jsx(u.IconButton,{className:"min-w-[50px]",variant:"soft","aria-label":`Download ${r}`,onClick:a,children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]})]})});Xt.displayName="FullScreenImagePreview";const Q=t=>{const{className:n,label:e,children:r,size:o,severity:a,inputId:l,labelId:s,image:p}=t,[c,f]=d.useState(void 0),[h,g]=d.useState(!1),y=a?ne[a]:"base";console.debug(a,y),d.useEffect(()=>{p instanceof Promise?p.then(f).catch(console.error):f(p)},[p]);const x=c?URL.createObjectURL(c):void 0;return i.jsxs("div",{className:"flex flex-col gap-2",children:[c&&i.jsxs(i.Fragment,{children:[i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:x,alt:c.name,onClick:()=>{g(!0)}}),h&&i.jsx(Xt,{file:c,url:x,name:c.name,setShowPreview:g})]}),i.jsxs("label",{className:we(n,"flex flex-col gap-1"),htmlFor:l,children:[i.jsx(u.Text,{accentColor:y,size:o,id:s,weight:"medium",children:e}),r]})]})},Qt=t=>{const{helpText:n,children:e,severity:r}=t,o=r?ne[r]:"base";return i.jsxs("div",{className:"flex flex-col gap-1",children:[e,i.jsx("div",{className:"flex flex-col w-full",children:i.jsx(u.Text,{accentColor:o,size:"xs",children:n})})]})},Y=t=>{const{children:n,...e}=t;return i.jsx(Qt,{...e,children:n})},Vo=[!0,"true"],Yt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);c=a?null:c,f=a?"":f;const h=Vo.includes(s.value);return i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,className:"align-center flex-row-reverse justify-end gap-2",children:i.jsx(u.Checkbox.Root,{...p,...s,id:n,accentColor:"base",value:h.toString(),checked:h,onCheckedChange:s.onChange,onChange:void 0,onBlur:void 0,variant:"surface",children:i.jsx(u.Checkbox.Indicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})})})})})});Yt.displayName="BooleanInput";const br={...G,type:"boolean"},Ce=class Ce extends W{constructor(e){super({...e,type:"boolean"});N(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}getValueFromChangeEvent(e){return typeof e=="boolean"?e:e.target.checked}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Ce(e)}getInput(e){return i.jsx(Yt,{...e,field:this})}};N(Ce,"fieldTypeName","Checkbox"),N(Ce,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),N(Ce,"Icon",U.RiCheckboxCircleLine);let be=Ce;const Jt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);c=a?null:c,f=a?"":f;const h=s.value?s.value.split("T")[0]:"";return i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,type:"date",id:n,value:h})})})})});Jt.displayName="DateInput";const Cr={...G,type:"date"},xe=class xe extends W{constructor(e){super({...e,type:"date"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return new Date(e.target.value).toISOString()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new xe(e)}getInput(e){return i.jsx(Jt,{field:this,...e})}};N(xe,"fieldTypeName","Date"),N(xe,"fieldTypeDescription","Allows specifying a date."),N(xe,"Icon",U.RiCalendarLine);let nt=xe;const xr=d.memo(t=>{const{field:n,...e}=t,[{value:r}]=V.useField(n.options.clonedFieldIdentifier),o=d.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?ft(a):null},[n.options,r]);return Zt(o,e)});xr.displayName="FieldInputCloner";const jo={...G,type:"custom"};class rt extends W{constructor(e,r){super({...e,type:"custom"});N(this,"Component");N(this,"options");this.options=e,this.Component=r}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const r=this.Component;return i.jsx(r,{field:this,...e})}}N(rt,"fieldTypeName","Custom"),N(rt,"fieldTypeDescription","Allows re-rendering of field already in the form");class Uo extends rt{constructor(n){super(n,xr)}}const Zt=(t,n)=>d.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),ze=(t,n)=>{const e=d.useMemo(()=>t.map(r=>i.jsx("div",{children:r.getInput(n)},r.getId())),[t,n]);return i.jsx("div",{className:"flex flex-col gap-2",children:e})},it=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Wo=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const o of n)o.type==="section"?(e.length>0&&(r.push(it(`AUTO_section-${n.indexOf(o)}`,e)),e=[]),r.push(o)):e.push(o);return e.length>0&&r.push(it("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Rt(t,n,e){const r=Array.from(t),[o]=r.splice(n,1);if(!o)throw new Error("Could not find field to reorder.");return r.splice(e,0,o),r}function Ir(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function ot(t,n){const e=Array.from(t);return e.splice(n,1),e}const en=(t,n)=>{const e=new Date;return`${j.slugify(n)}-${e.getTime()}`},Er=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=Er(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},Sr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),at=(t,n,e,r,o)=>{const{label:a}=e,l={...e,identifier:en(null,a)},s=K(r,t);if(s===void 0)throw new Error("Parent path must point to an existing field.");if(!Array.isArray(s))throw new Error("Parent path must point to an array.");const p=Ir(s,n,l);o(t,p).then()},qo=(t,n,e)=>{const r={...it(),label:""};at("fields",t,r,n,e)},tn=()=>{const{showError:t}=u.useToast(),n=d.useCallback((r,o,a,l,s,p)=>{const c=r[o];if(!c)throw new Error("Could not find section context.");let f=typeof c.conditionIndex<"u"?Math.max(c.conditionIndex+1,l):l;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==l){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}p("fields",Rt(s.fields,a,f))},[t]),e=d.useCallback((r,o,a,l,s,p,c)=>{var f;if(!(r!=null&&r.fields)||!l)throw new Error("Could not find section with fields.");if(r.identifier===l.identifier)c(`fields.${o}.fields`,Rt(r.fields,a,p)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=l.condition)==null?void 0:f.identifier)===h.identifier){t({title:"Could not reorder field",description:"Field must be above the section whose condition references it."});return}c(`fields.${o}.fields`,ot(r.fields,a)).then(),c(`fields.${s}.fields`,Ir(l.fields,p,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},nn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);c=a?null:c,f=a?"":f;const h=d.useMemo(()=>Array.isArray(s.value)?s.value:[],[s.value]),{onChange:g,onBlur:y}=s,x=`${n}-droppable`,{disabled:m}=p,[w,E]=d.useState(""),[b,S]=d.useState(""),I=b||c,F=d.useCallback(P=>{g(P),y(P)},[g,y]),L=d.useCallback(P=>{h.findIndex(B=>B===P.target.value.trim())>=0?S("All options must be unique"):P.target.value?S(""):S("Option cannot be empty"),E(P.target.value)},[E,h]),T=d.useCallback(()=>{if(b)return;if(!w.trim()){S("Option cannot be empty");return}const P=w.trim();F([...h,P]),E("")},[w,b,F,h]),M=d.useCallback(P=>{P.key==="Enter"&&(P.preventDefault(),T())},[T]),A=d.useCallback(P=>{F(ot(h,P))},[h,F]),$=d.useCallback(P=>{if(!P.destination)return;const B=P.source.index,_=P.destination.index;F(Rt(h,B,_))},[F,h]);return i.jsx(re.DragDropContext,{onDragEnd:$,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Y,{helpText:I,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:(!m||h.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx("div",{className:"grow",children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,...s,value:w,onChange:L,onKeyDown:M,id:n,placeholder:l.placeholder,onBlur:void 0})})}),i.jsx(u.IconButton,{type:"button","aria-label":"Add option",disabled:!!b||m,onClick:T,children:i.jsx(u.RiIcon,{icon:"RiAddLine"})})]})})}),i.jsx(re.Droppable,{droppableId:x,children:P=>i.jsxs("div",{className:"flex flex-col",...P.droppableProps,ref:P.innerRef,children:[h.map((B,_)=>i.jsx(re.Draggable,{draggableId:`${B}-draggable`,index:_,isDragDisabled:m,children:({draggableProps:ee,dragHandleProps:le,innerRef:je})=>i.jsxs(u.Badge,{...le,...ee,ref:je,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"md",variant:"soft",children:[i.jsx("span",{children:typeof B=="object"&&"label"in B?B.label:B}),i.jsx(u.IconButton,{size:"sm",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:m,onClick:()=>{A(_)},children:i.jsx(u.RiIcon,{icon:"RiCloseLargeLine"})})]})},B)),P.placeholder]})})]})})});nn.displayName="MultiStringInput";const Nr={...G,type:"multi-string",minimum_length:0,maximum_length:null},Ie=class Ie extends W{constructor(e){const{minimum_length:r,maximum_length:o,placeholder:a,...l}=e;super({...l,type:"multi-string"});N(this,"minLength");N(this,"maxLength");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.minLength=r??0,this.maxLength=o??1/0,this.placeholder=a??"Press enter to add a new option"}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return i.jsx(nn,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(r=>{if(Array.isArray(r)&&r.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(r=>{if(Array.isArray(r)&&r.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new Ie(e)}};N(Ie,"fieldTypeName","Multi-string"),N(Ie,"fieldTypeDescription","Allows the user to provide multiple unique strings."),N(Ie,"Icon",U.RiListCheck);let $e=Ie;const rn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);return c=a?null:c,f=a?"":f,i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,...s,type:"number",id:n,placeholder:l.placeholder,min:l.minimum,max:l.maximum,step:l.integers?1:.1})})})})});rn.displayName="NumberInput";const Fr={...G,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Tr=t=>"fields"in t,R=class R extends W{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:o=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:l="Enter a number",...s}=e;super({...s,type:"number"});N(this,"minimum");N(this,"maximum");N(this,"integers");N(this,"placeholder");this.minimum=r,this.maximum=o,this.integers=a,this.placeholder=l}getValueFromChangeEvent(e){const r=Number.parseFloat(e.target.value);return Number.isNaN(r)?"":r}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new R({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new R({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new be({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,o=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof o=="number"&&e.push(a=>{if(typeof a=="number"&&a>o)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(a=>{if(typeof a=="number"&&!Number.isInteger(a))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new R(e)}getInput(e){return i.jsx(rn,{field:this,...e})}};N(R,"fieldTypeName","Number"),N(R,"fieldTypeDescription","Allows specifying a number within a given range."),N(R,"Icon",U.RiHashtag),N(R,"_validateMin",e=>(r,o)=>{const a=Tr(o)?K(o,e):o;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),N(R,"_validateMax",e=>(r,o)=>{const a=Tr(o)?K(o,e):o;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let ae=R;const on=d.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:o,size:a,severity:l,showInputOnly:s,field:p,fieldProps:c},f]=z(t),[h,g]=d.useState(!1),y=c.value,x=d.useCallback(b=>{c.onChange({target:{value:b}}),g(!1)},[c]),m=d.useCallback(()=>{c.onChange({target:{value:""}})},[c]),w=d.useCallback(()=>{g(!0)},[]),E=d.useCallback(()=>{g(!1)},[]);return i.jsx(Y,{helpText:o,severity:l,children:i.jsxs(Q,{size:a,severity:l,inputId:n,labelId:e,label:r,image:s?void 0:p.image,className:"flex-col items-start justify-start gap-1",children:[i.jsx(Pe,{open:h,onOpenChange:g,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),i.jsx(Oe,{className:"fixed inset-0",children:i.jsx(an,{onQrScan:x,onClose:E})})]})}),i.jsxs("div",{className:"flex w-max items-center gap-1",children:[i.jsxs(u.Button,{...f,variant:"soft",onClick:w,type:"button",children:[i.jsx(u.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]}),y&&i.jsx("span",{className:"text-xs text-(--accent-a11)","data-accent-color":"primary",children:i.jsx(u.RiIcon,{icon:"RiCheckLine",style:{verticalAlign:"bottom"}})})]}),!!y&&i.jsx(u.Card,{children:i.jsxs("div",{className:"w-max items-center gap-2",children:[i.jsx("code",{className:"bg-(--base-a3)",children:y}),i.jsx(u.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:m,children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})})]})})]})})});on.displayName="QrInput";const an=d.memo(t=>{const{onQrScan:n,onClose:e}=t,r=d.useRef(null),[o,a]=d.useState(!1);return d.useEffect(()=>{if(!r.current)return;const l=new Zr(r.current,s=>{const p=s.data;n(p),l.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});a(!0),l.start().finally(()=>{a(!1)})},[n]),i.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[i.jsx("div",{className:"absolute top-0 flex w-full p-2",children:i.jsx(u.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",onClick:e,children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})})}),i.jsxs("div",{className:"relative max-h-full max-w-full",children:[i.jsx("video",{ref:r,style:{width:"100%",height:"100%"}}),o&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:i.jsx(u.Spinner,{})})]})]})});an.displayName="QrScanner";const Lr={...G,type:"qr"},Ee=class Ee extends W{constructor(e){super({...e,type:"qr"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="qr")throw new Error("Type mismatch.");return new Ee(e)}getInput(e){return i.jsx(on,{...e,field:this})}};N(Ee,"fieldTypeName","QR"),N(Ee,"fieldTypeDescription","Used for scanning/reading QR codes."),N(Ee,"Icon",U.RiQrCodeLine);let lt=Ee;class Dr extends W{constructor(e){const{placeholder:r="",...o}=e;super(o);N(this,"options");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(l=>(typeof l=="string"&&(l={label:l,value:l}),a.add(l.label),l)),a.size!==e.options.length&&console.error(`${e.options.length-a.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options,placeholder:this.placeholder}}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new $e({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const Ho=t=>t?Array.isArray(t)?t:[t]:[],ln=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t),{onChange:c,onBlur:f}=s;let[{helpText:h,label:g}]=z(t);h=a?null:h,g=a?"":g;const y=d.useMemo(()=>Ho(s.value),[s.value]),x=d.useCallback(m=>{c(m),f(m)},[c,f]);return i.jsx(Y,{helpText:h,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:g,image:a?void 0:l.image,children:i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsxs(u.Button,{id:n,className:"!justify-between",name:s.name,variant:"surface",type:"button",accentColor:"base",...p,children:[y.length>0?y.join(", "):l.placeholder,i.jsx(u.RiIcon,{icon:"RiArrowDownSLine"})]})}),i.jsx(u.Menu.Content,{children:i.jsxs(u.Menu.MultiSelectGroup,{values:y,onValuesChange:x,children:[i.jsxs(u.Menu.SelectAllItem,{allValues:l.options.map(({value:m})=>m),children:[i.jsx(u.Menu.SelectAllIndicator,{children:m=>m?i.jsx(u.RiIcon,{icon:"RiSubtractLine"}):i.jsx(u.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),l.options.map(m=>i.jsxs(u.Menu.MultiSelectItem,{value:m.value,children:[i.jsx(u.Menu.SelectedIndicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})}),m.label]},m.value))]})})]})})})});ln.displayName="MultiSelectInput";const Pr={...G,type:"multi-select",options:[]},Se=class Se extends Dr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}getValueFromChangeEvent(n){if(Array.isArray(n))return n;throw new Error("Expected an array.")}isBlank(n){return super.isBlank(n)||n.length===0}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Se(n)}getInput(n){return i.jsx(ln,{field:this,...n})}};N(Se,"fieldTypeName","Multi-select"),N(Se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),N(Se,"Icon",U.RiCheckboxLine);let ke=Se;const sn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t),{onChange:c,onBlur:f}=s;let[{helpText:h,label:g}]=z(t);h=a?null:h,g=a?"":g;const y=d.useCallback(m=>{c(m),f(m)},[c,f]),x=d.useMemo(()=>l.options.find(m=>m.value===s.value),[l.options,s.value]);return i.jsx(Y,{helpText:h,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:g,image:a?void 0:l.image,children:i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsxs(u.Button,{...s,className:"!justify-between",id:n,name:s.name,accentColor:"base",variant:"surface",type:"button",...p,children:[x?x.label:l.placeholder,i.jsx(u.RiIcon,{icon:"RiArrowDownSLine"})]})}),i.jsx(u.Menu.Content,{children:i.jsx(u.Menu.SelectGroup,{value:s.value,onValueChange:y,children:l.options.map(m=>i.jsxs(u.Menu.SelectItem,{value:m.value,children:[i.jsx(u.Menu.SelectedIndicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})}),m.label]},m.value))})})]})})})});sn.displayName="SelectInput";const Mr={...G,type:"select",options:[]},Ne=class Ne extends Dr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}getValueFromChangeEvent(n){return typeof n=="string"?n:n.target.value}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new Ne(n)}getInput(n){return i.jsx(sn,{field:this,...n})}};N(Ne,"fieldTypeName","Dropdown"),N(Ne,"fieldTypeDescription","Allows the user to select a single option from a list of options."),N(Ne,"Icon",U.RiMenuFoldLine);let Ve=Ne;const Ar=t=>"fields"in t;class st extends W{constructor(e){const{minLength:r,maxLength:o,placeholder:a="",...l}=e;super(l);N(this,"minLength");N(this,"maxLength");N(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=o?Math.max(o,0):ye,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ae({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:`${r}minimum_length`,minimum:0,maximum:100,formValidators:[this._validateMin(e)],integers:!0}),showDirectly:!1},{field:new ae({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:ye,formValidators:[this._validateMax(e)],integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(r=>{if(this.minLength&&(!r||r.length<this.minLength))return!this.required&&!r?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(r=>{if(typeof r=="string"&&this.maxLength&&r.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}}N(st,"_validateMin",e=>(r,o)=>{const a=Ar(o)?K(o,e):o;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),N(st,"_validateMax",e=>(r,o)=>{if(typeof r!="number")return null;const{minimum_length:a}=Ar(o)?K(o,e):o;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const cn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);return c=a?null:c,f=a?"":f,i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,...s,type:l.inputType,id:n,placeholder:l.placeholder})})})})});cn.displayName="StringInput";const Or={...G,type:"string",maximum_length:Re,input_type:"text"},Fe=class Fe extends st{constructor(e){const{inputType:r="text",...o}=e,a=e.maxLength?Math.min(Re,e.maxLength):Re,l=e.minLength?Math.min(e.minLength,a):void 0;super({...o,maxLength:a,minLength:l,type:"string"});N(this,"inputType");this.inputType=r}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:r,minimum_length:o,input_type:a,...l}=e;return new Fe({...l,maxLength:r,minLength:o,inputType:a,placeholder:"Enter a short description"})}getInput(e){return i.jsx(cn,{field:this,...e})}};N(Fe,"fieldTypeName","Short Text"),N(Fe,"fieldTypeDescription",`Short text fields can hold up to ${Re} characters on a single line.`),N(Fe,"Icon",U.RiInputField);let ct=Fe;const dn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);return c=a?null:c,f=a?"":f,i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.TextArea,{...p,...s,className:"field-sizing-content",resize:"vertical",id:n,placeholder:l.placeholder,accentColor:"base",variant:"surface"})})})});dn.displayName="TextInput";const Br={...G,type:"text",maximum_length:ye},Te=class Te extends st{constructor(n){const e=n.maxLength?Math.min(ye,n.maxLength):ye,r=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:r,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:r,...o}=n;return new Te({...o,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return i.jsx(dn,{field:this,...n})}};N(Te,"fieldTypeName","Paragraph"),N(Te,"fieldTypeDescription",`Paragraph fields can hold up to ${ye} characters and can have multiple lines.`),N(Te,"Icon",U.RiAlignJustify);let dt=Te;const _r=d.memo(d.forwardRef((t,n)=>{const{file:e,alt:r,error:o,rightSlot:a,className:l,truncateLength:s,...p}=t,c=d.useRef(null),f=d.useRef(null),h=u.useSize(c);d.useLayoutEffect(()=>{!f.current||!h||(f.current.style.height=`${h.height*4}px`)},[h]);const g=d.useMemo(()=>{if(e)return s!==void 0?j.truncate(e.name,s):e.name},[e,s]);return i.jsxs("div",{className:we(l,"relative flex h-max w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...p,children:[!e&&!o&&i.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:i.jsx(u.Spinner,{})}),i.jsx("div",{ref:f,className:"-m-4 flex max-w-full items-center justify-center overflow-hidden bg-clip-padding",children:e&&!o&&i.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),i.jsxs("div",{className:we("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),ref:c,children:[o?i.jsx(u.RiIcon,{icon:"RiFileWarningLine"}):e&&i.jsx(Be,{fileType:e.type}),o??g,a]})]})})),Go=t=>{const n=["byte","kilobyte","megabyte"];let e=t,r=0;for(;e>1e3&&r<n.length-1;)e/=1e3,r++;return new Intl.NumberFormat([],{maximumFractionDigits:Math.max(0,r-1),style:"unit",unit:n[r]}).format(e)},zr=d.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:o,helpText:a,showInputOnly:l,field:s,fieldProps:p},c]=z(t),{onChange:f}=p;let[{label:h}]=z(t);h=l?"":h;const g=o?ne[o]:void 0,y=d.useRef(null),{value:x}=p,m=d.useMemo(()=>l?null:a||(s.maxFileSize?`Maximum file size: ${s.maxFileSize}MB`:null),[s.maxFileSize,a,l]),w=d.useCallback(()=>{var L;(L=y.current)==null||L.click()},[]),E=d.useCallback(L=>{const T=[...x];T.splice(L,1),f({target:{files:T}})},[x,f]),b=x?"Select new files":"Select files",S=x?"Select new file":"Select a file",I=s.maxFiles>1?b:S;return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Y,{helpText:m,severity:o,children:i.jsxs(Q,{size:r,severity:o,inputId:n,labelId:e,label:h,image:l?void 0:s.image,children:[i.jsx("div",{className:"flex gap-2",children:i.jsxs(u.Button,{...c,className:"w-max",variant:"soft",onClick:w,id:"upload-input-upload-button",type:"button",children:[i.jsx(u.RiIcon,{icon:"RiUpload2Line"})," ",I]})}),i.jsx("input",{...c,type:"file",ref:y,id:n,accept:(F=s.extensions)==null?void 0:F.join(","),multiple:s.maxFiles>1,color:g,style:{display:"none"},...p,value:""})]})}),Array.isArray(x)&&x.length>0&&i.jsx("div",{className:"flex h-max flex-col gap-2",children:x.map((L,T)=>i.jsx($r,{field:s,file:L,onRemove:()=>{E(T)},disabled:c.disabled},T))})]})});zr.displayName="UploadInput";const $r=d.memo(t=>{const{file:n,field:e,onRemove:r,disabled:o}=t,[a,l]=d.useState(null),s=gr(),p=d.useMemo(()=>a&&e.getError([a]),[e,a]),{url:c,name:f}=d.useMemo(()=>{let m=null,w,E;return a!=null&&a.type.startsWith("image/")&&(m=URL.createObjectURL(a)),a?(w=a.name,E=Go(a.size)):(w="Downloading...",E="..."),{url:m,name:w,size:E}},[a]);d.useEffect(()=>{n instanceof Promise?n.then(l).catch(console.error):l(n)},[n]);const h=d.useCallback(m=>{if(m.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const w=new Blob([a]);wr.saveAs(w,f)},[f,a]),g=d.useCallback(m=>{m.stopPropagation(),r()},[r]),y=d.useCallback(()=>{a&&s(m=>({file:a,onDelete:o?void 0:()=>{r(),m()}}))},[o,r,s,a]),x=d.useMemo(()=>i.jsxs(u.ButtonGroup,{variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(u.IconButton,{"aria-label":`Download ${f}`,onClick:h,disabled:!a,children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})}),!o&&i.jsx(u.IconButton,{"aria-label":`Remove ${f}`,disabled:o,onClick:g,children:i.jsx(u.RiIcon,{icon:"RiCloseLargeLine"})})]}),[o,g,h,f,a]);return c?i.jsx(_r,{style:{cursor:"pointer"},onClick:y,file:a,error:p??void 0,rightSlot:x}):i.jsx(Ht,{style:{cursor:"pointer"},onClick:y,file:a,error:p??void 0,rightSlot:x})});$r.displayName="DisplayFile";const Ko={...G,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1},Le=class Le extends W{constructor(e){const{extensions:r,maximum_files:o,maximum_size:a,...l}=e;super({...l,type:"upload"});N(this,"extensions");N(this,"maxFileSize");N(this,"maxFiles");N(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof a=="number"?a:void 0,this.maxFiles=Math.max(typeof o=="number"?o:1,1),this.extensions=r}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ae({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:`${r}maximum_files`,integers:!0}),showDirectly:!1},{field:new ae({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${ut}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:ut,integers:!0}),showDirectly:!1},{field:new ke({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:`${r}extensions`,options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.maxFileSize??ut,o=r*1e3*1e3,a=this.maxFiles||1;return e.push(l=>{if(l&&l.some(s=>s.size>o))return`Files must be at most ${r}MB.`}),e.push(l=>{if(l&&l.length>a)return`You can only upload ${a} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new Le(e)}getInput(e){return i.jsx(zr,{field:this,...e})}};N(Le,"fieldTypeName","Upload"),N(Le,"fieldTypeDescription","Allows a file to be uploaded."),N(Le,"Icon",U.RiUpload2Line);let un=Le;const fn={date:nt,number:ae,boolean:be,select:Ve,string:ct,text:dt,custom:rt,upload:un,qr:lt,"multi-string":$e,"multi-select":ke},Xo={date:Cr,number:Fr,boolean:br,select:Mr,string:Or,text:Br,custom:jo,upload:Ko,qr:Lr,"multi-string":Nr,"multi-select":Pr},ut=50,Qo=ut*1e3*1e3,hn=t=>{const n=t.type;return fn[n].deserialize(t)},ft=t=>t.type==="section"?q.deserialize(t):hn(t);function kr(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>ft(r)),meta:{readonly:e}}}function pn(t){const n=[];for(const e of t.fields)if(e instanceof q)for(const r of e.fields)n.push(r);else{if(!(e instanceof W))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Yo(t,n){const e=pn(t),r={};for(const o of e){const a=n[o.identifier]??null;a!==null?r[o.identifier]=o.decodeJsonToValue(a):r[o.identifier]=a}return r}function Jo(t,n){const e=pn(t),r={};for(const o of e){const a=n[o.identifier];r[o.identifier]=o.encodeValueToJson(a)}return r}function ht(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function mn(t,n){if(!t)return!0;if(ht(n)||ht(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(o=>typeof o=="string"?o:o.value):n,r=Array.isArray(t.value)?t.value.map(o=>typeof o=="string"?o:o.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const o of r)if(!e.includes(o))return!1;return!0}return r===n}const Vr=d.memo(t=>{const{field:n,...e}=t,{label:r,description:o,fields:a,condition:l}=n,{values:s,setFieldValue:p}=V.useFormikContext(),c=l!=null&&l.identifier?K(s,l.identifier):void 0,f=d.useMemo(()=>c===void 0||mn(l,c),[l,c]);d.useEffect(()=>{if(!f)for(const g of a)p(g.getId(),"").then()},[f,a,p]);const h=ze(a,e);return f?i.jsx(u.Card,{children:i.jsxs("div",{className:"flex flex-col gap-6",children:[i.jsxs("div",{className:"flex flex-col",children:[i.jsx(u.Heading,{size:"lg",children:r}),i.jsx(u.Text,{accentColor:"base",children:o})]}),h]})}):null});Vr.displayName="FieldSectionLayout";const De=class De extends Kt{constructor(e){const{label:r=null,fields:o,condition:a=null,conditional:l,...s}=e;super({...s,type:"section"});N(this,"label");N(this,"fields");N(this,"condition");this.fields=o,this.condition=a,this.label=r,l===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const o=r&&`${r}.`;return[{field:new be({label:"Conditionally render section",identifier:`${o}conditional`,required:!1}),showDirectly:!0},{field:new De({label:"Conditional settings",identifier:`${o}conditional-settings`,condition:{identifier:`${o}conditional`,value:!0},fields:[new Ve({label:"Field",description:"The field to use for the condition.",options:e.map(a=>!a.label||a.type==="upload"?null:{label:a.label,value:a.identifier}).filter(a=>!!a),identifier:`${o}condition.identifier`,required:!0}),new Uo({label:"Value",identifier:`${o}condition.value`,required:!0,clonedFieldIdentifier:`${o}condition.identifier`,getFieldToClone(a){if(!a)return null;const l=e.find(s=>s.identifier===a);return l?{...l,label:"Value",identifier:`${o}condition.value`,description:"The value to compare against.",required:l.type!=="boolean"}:(console.error("Could not find field with identifier",a),null)}})]}),showDirectly:!1}]}static deserialize(e){if(e.type!=="section")throw new Error("Invalid type");if(!Array.isArray(e.fields))throw new Error(`Invalid fields: ${e.fields} (not an array)`);const r=e.fields.map(hn);return new De({...e,fields:r})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const r={};for(const o of this.fields){const a=o.getId(),l=o.getError(K(e,a),e);l&&wt(r,o.getId(),l)}return r}getInput(e){return i.jsx(Vr,{field:this,...e})}};N(De,"fieldTypeName","Section"),N(De,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let q=De;const ue=t=>Object.keys(t).length>0,pt=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof q){if(r.condition){const{identifier:o}=r.condition;if(!mn(r.condition,K(n,o)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof W))throw new Error("Invalid field type");const o=r.getId(),a=r.getError(K(n,o),n);a&&wt(e,o,a)}if(ue(e))return e},Zo=[null,void 0],mt=(t,n)=>t.reduce((e,r)=>r instanceof q?{...e,...mt(r.fields,n)}:(Zo.includes(K(e,r.getId()))&&wt(e,r.getId(),""),e),Rr(n)),Ro=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},jr=d.memo(d.forwardRef((t,n)=>{const{schema:e,values:r={},onSubmit:o=Ro,submitText:a="Submit",cancelText:l,onCancel:s,onDirty:p,onDirtyChange:c,hideTitle:f=!e.title,hideDescription:h,className:g,buttonProps:y}=t,{readonly:x}=e.meta,m=d.useMemo(()=>crypto.randomUUID(),[]),w=V.useFormik({initialValues:mt(e.fields,r),onSubmit:o,validate:F=>pt(e,F),validateOnBlur:!1,validateOnChange:!1}),{dirty:E}=w,b=d.useMemo(()=>typeof e.title=="string"?i.jsx(u.Heading,{size:"lg",children:e.title}):e.title,[e.title]),S=d.useMemo(()=>typeof e.description=="string"?i.jsx(u.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),I=ze(e.fields,{formId:m,disabled:x});return d.useEffect(()=>{E&&p&&p(),c&&c(E)},[E,p,c]),i.jsx(V.FormikProvider,{value:w,children:i.jsxs("form",{id:m,ref:n,className:we(g,"flex flex-col gap-2"),onSubmit:w.handleSubmit,children:[!f&&i.jsx(u.Card,{children:i.jsxs("div",{className:"flex flex-col gap-1",children:[b,!h&&S]})}),I,!x&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&i.jsxs(u.Button,{accentColor:ne.danger,...y,type:"button",onClick:s,children:[i.jsx(u.RiIcon,{icon:"RiCloseLine"}),l]}),i.jsxs(u.Button,{...y,type:"submit",disabled:!w.isValid,accentColor:"success",children:[i.jsx(u.RiIcon,{icon:"RiCheckLine"}),a]})]})]})})})),fe=d.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=V.useFormikContext(),[o,a,l]=V.useField(n),s=d.useMemo(()=>{const p=c=>{l.setValue(c,!1)};return e({value:o.value,meta:a,setValue:p,patchValue:()=>{r()}})},[e,o.value,a,r,l]);return i.jsx(i.Fragment,{children:s})});fe.displayName="PatchField";const ea=d.memo(d.forwardRef((t,n)=>{const{children:e,schema:r,values:o,onPatch:a,onError:l,requiresDiff:s=!0,onDirtyChange:p,...c}=t,f=d.useMemo(()=>mt(r.fields,o),[r.fields,o]),h=d.useCallback(b=>{const S={};for(const I in b){const F=b[I];F!==f[I]&&F!==void 0&&(S[I]=F)}return S},[f]),g=d.useCallback(b=>{const S=h(b);s&&!ue(S)||a(S)},[h,a,s]),y=d.useCallback(b=>{const S=pt(r,b);if(S&&l(S),p){const I=h(b);p(ue(I))}return S},[r,p,l,h]),x=V.useFormik({initialValues:f,onSubmit:g,validate:y,validateOnBlur:!1,validateOnChange:!1}),m=d.useCallback(()=>{if(p){const b=h(x.values);ue(b)&&p(!0)}},[x.values,h,p]),{errors:w,resetForm:E}=x;return d.useEffect(()=>{ue(w)&&E({values:f,errors:{}})},[w,f,E]),i.jsx(V.FormikProvider,{value:x,children:i.jsx("form",{...c,ref:n,onSubmit:x.handleSubmit,onChange:m,children:e})})})),gt="form-builder",ta=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],gn={...fn,section:q},na=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const o in e)e[o].disabled=!1;return e;case"hold":for(const o in e)(r=e[o])!=null&&r.conditionFields.has(n.fieldId)&&(e[o].disabled=!0);return e;case"update":return n.state}},ra=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const o of r.fields)if(o.identifier===n)return e}}},Ur=t=>{var e,r,o;const n={};for(let a=0;a<t.length;a++){const l=t[a];if(!l)throw new Error("Field is undefined.");const s=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,p=new Set(s);(r=l.condition)!=null&&r.identifier&&p.add(l.condition.identifier),n[l.identifier]={disabled:!1,conditionFields:p,conditionIndex:ra(t,(o=l.condition)==null?void 0:o.identifier),index:a,label:l.label}}return n},vn=d.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:o,duplicate:a,move:l,upload:s}=t;if(e!=="section"&&!s)throw new Error("Upload function prop must be defined for non-section fields.");const{values:p}=V.useFormikContext(),c=d.useRef(null),f=d.useMemo(()=>{const h=[{Icon:U.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:U.RiDeleteBin2Line,key:"delete",text:"Delete",buttonProps:{onClick:o}}),e!=="section"&&h.unshift({Icon:U.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=c.current)==null||g.click()}}}),(r===void 0&&n!==p.fields.length-1||r!==void 0&&(r<p.fields.length-1||n!==p.fields[r].fields.length-1))&&h.unshift({Icon:U.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{l("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:U.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{l("up")}}}),h},[a,n,l,o,r,e,p.fields]);return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"mx-2 flex hidden flex-col gap-5 sm:block",children:f.map(h=>{const g=h.Icon;return i.jsx(u.IconButton,{type:"button",variant:"ghost",accentColor:h.key.startsWith("move")?"base":void 0,"aria-label":h.text,...h.buttonProps,children:i.jsx(g,{})},h.key)})}),i.jsx("div",{className:"sm:hidden",children:i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsx(u.IconButton,{variant:"ghost","aria-label":"Actions menu",children:i.jsx(u.RiIcon,{icon:"RiMore2Line"})})}),i.jsx(u.Menu.Content,{children:f.map(h=>{var y;const g=h.Icon;return i.jsxs(u.Menu.Item,{onClick:(y=h.buttonProps)==null?void 0:y.onClick,children:[i.jsx(g,{}),h.text]},h.key)})})]})}),e!=="section"&&i.jsx("input",{style:{display:"none"},ref:c,type:"file",accept:"image/*",onChange:s})]})});vn.displayName="FieldActions";const Wr=(t=()=>null)=>d.useMemo(()=>ta.map(n=>n.map(e=>{const r=fn[e],o=r.Icon;return{children:r.fieldTypeName,icon:i.jsx(o,{}),value:e,onSelect:()=>{t(e)}}})),[t]),he=t=>t.type==="section",yn=d.memo(t=>{const{popoverInputs:n,hasError:e}=t;return i.jsxs(u.Popover.Root,{children:[i.jsx(u.Popover.Trigger,{children:i.jsxs(u.Button,{variant:"soft",size:"sm","aria-label":"settings",...e&&{color:ne.danger},children:[i.jsx(u.RiIcon,{icon:"RiSettings2Line"}),i.jsx("span",{children:"Settings"})]},"settings")}),i.jsx(u.Popover.Content,{size:"sm",children:i.jsx("div",{className:"flex max-w-[240px] flex-col",children:n})})]})});yn.displayName="FieldSettingsPopover";const wn=d.memo(t=>{var vt,xn,Qr,Yr,Jr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:o}=t,{values:a,setFieldValue:l,errors:s}=V.useFormikContext(),p=Wr(),c=d.useRef(null),f=576,[h,g]=d.useState(c.current&&c.current.getBoundingClientRect().width>=f);d.useEffect(()=>{const D=c.current;if(D){const O=new ResizeObserver(H=>{H[0]&&g(H[0].contentRect.width>=f)});return O.observe(D),()=>{O.disconnect()}}},[]);const[y,x]=d.useState(void 0),[m,w]=d.useState(!1);d.useEffect(()=>{he(r)?x(void 0):r.image instanceof Promise?r.image.then(x).catch(console.error):x(r.image)},[r]);const E=y?URL.createObjectURL(y):void 0,b=d.useCallback(D=>{D.stopPropagation();const{image:O,...H}=r;l(`${n}.${e}`,H).then()},[e,r,n,l]);d.useEffect(()=>{he(r)&&!r.conditional&&l(`${n}.${e}.condition`,null).then()},[e,r,n,l]);const S=d.useMemo(()=>{var D,O;return he(r)?(O=Er(a.fields,(D=r.condition)==null?void 0:D.identifier))==null?void 0:O.label:void 0},[r,a.fields]),I=he(r)?Array.isArray((vt=r.condition)==null?void 0:vt.value)?"contains all of":"equals":void 0;let F;if(he(r)){if(ht((xn=r.condition)==null?void 0:xn.value))throw new Error("File values are not supported for conditions.");F=Array.isArray((Qr=r.condition)==null?void 0:Qr.value)?r.condition.value.map(D=>typeof D=="string"?D:D.label).join(", "):(Jr=(Yr=r.condition)==null?void 0:Yr.value)==null?void 0:Jr.toString()}const L=d.useCallback(D=>{D.target.parentNode instanceof HTMLElement&&(D.target.parentNode.dataset.replicatedValue=D.target.value)},[]),T=d.useCallback(D=>{D.target.parentNode instanceof HTMLElement&&(D.target.parentNode.dataset.replicatedValue=D.target.value)},[]),M=r.type,A=gn[M],[$,P]=d.useMemo(()=>{let D=[],O=[];if(A===q){if(o===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const H=A.getFieldCreationSchema(o,`${n}.${e}`);D=D.concat(H.filter(k=>k.showDirectly).map(k=>k.field)),O=O.concat(H.filter(k=>!k.showDirectly).map(k=>k.field))}else{if(!(A.prototype instanceof W))throw new Error(`Field must be an instance of BaseField. Got ${A.toString()}.`);const H=A.getFieldCreationSchema(`${n}.${e}`);h?(D=[...D,...H.filter(k=>k.showDirectly).map(k=>k.field)],O=[...O,...H.filter(k=>!k.showDirectly).map(k=>k.field)]):O=[...O,...H.map(k=>k.field)]}return[D,O]},[A,o,n,e,h]),B=ze($,{formId:gt,disabled:!1,internal:!0,...A===q&&{size:"sm"}}),_=ze(P,{formId:gt,disabled:!1});let ee=P.length>0;he(r)&&P.length>0&&(ee=r.conditional);const le=P.some(D=>{const O=K(s,A===q?`${n}.${e}.condition`:D.getId());return O&&(typeof O!="object"||ue(O))}),je=le?ne.danger:void 0,bn=d.useMemo(()=>ft(r),[r]),Cn=Zt(bn,{formId:gt,showInputOnly:!1}),J=d.useMemo(()=>p.flat().find(D=>D.value===M),[p,M]);return i.jsx("div",{className:"flex grow items-center w-full",ref:c,children:i.jsxs("div",{className:"flex w-full flex-col gap-4",children:[A===q&&i.jsxs("div",{className:"flex flex-col gap-2",children:[$.length>0&&B,i.jsxs("div",{className:"flex items-center gap-4",children:[ee&&i.jsx(yn,{popoverInputs:_,hasError:le}),he(r)&&r.conditional&&i.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":je,children:i.jsxs("em",{children:["Display only if ",i.jsx("strong",{children:S})," ",I," ",i.jsx("strong",{children:F})]})})]})]}),A!==q&&i.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs(u.Badge,{accentColor:"base",variant:"soft",children:[J==null?void 0:J.icon,J==null?void 0:J.children]}),i.jsx(fe,{name:`${n}.${e}.required`,render:({setValue:D,value:O})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u.Checkbox.Root,{checked:O,onCheckedChange:D,children:i.jsx(u.Checkbox.Indicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})})}),i.jsx(u.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),ee&&i.jsx(yn,{popoverInputs:_,hasError:le})]}),y&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:E,alt:y.name,onClick:()=>{w(!0)}}),i.jsx(u.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:ne.danger,"aria-label":"delete",onClick:b,children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})]}),m&&i.jsx(Xt,{file:y,url:E,name:y.name,setShowPreview:w})]}),i.jsx(fe,{name:`${n}.${e}.label`,render:({setValue:D,value:O})=>i.jsx("input",{className:"bg-transparent outline-none text-base",placeholder:M==="section"?"Enter a section label (optional)":"Enter your question",value:O,onChange:H=>{D(H.target.value)},onInput:L,maxLength:200})}),i.jsx(fe,{name:`${n}.${e}.description`,render:({setValue:D,value:O})=>i.jsx("textarea",{className:"bg-transparent outline-none text-base field-sizing-content grow",placeholder:`Enter a ${M==="section"?"section":"field"} description (optional)`,value:O,onChange:H=>{D(H.target.value)},onInput:T,maxLength:1e3})}),A!==q&&$.length>0&&i.jsx("div",{className:"w-full",children:B}),A!==q&&i.jsxs(i.Fragment,{children:[i.jsx(u.Separator,{size:"full"}),i.jsxs(u.Card,{className:"flex flex-col gap-2 bg-(--accent-a2)",children:[i.jsx(u.Text,{accentColor:"base",children:"Field preview"}),i.jsx("div",{children:Cn})]})]})]})})});wn.displayName="FieldBuilder";const qr=d.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:o}=t,{setFieldValue:a,values:l}=V.useFormikContext(),{reorderField:s}=tn(),{showError:p}=u.useToast(),c=`fields.${r}.fields`,f=d.useMemo(()=>({index:e,parentPath:c,initial:n}),[n,e,c]),h=d.useCallback(()=>{const x=n.label??"Unlabelled field",m={...n,label:x};at(c,e+1,m,l,a)},[n,c,e,l,a]),g=d.useCallback(x=>{const m=r,w=l.fields[m];let E=r,b=x==="up"?e-1:e+1;x==="up"&&e===0?(E=r-1,b=l.fields[E].fields.length):x==="down"&&e===w.fields.length-1&&(E=r+1,b=0);const S=l.fields[E];s(w,m,e,S,E,b,a)},[r,l.fields,e,s,a]),y=d.useCallback(x=>{const{files:m}=x.target;if(!m||m.length!==1)return;const w=m.item(0);if(w){if(w.size>Qo){p({title:"File upload error",description:`The file ${w.name} exceeded the maximum file size`});return}a(`${c}.${e}`,{...n,image:w}).then()}},[n,e,c,a,p]);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:x=>i.jsx(u.Card,{ref:x.innerRef,...x.draggableProps,...x.dragHandleProps,className:"mb-4",children:i.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[i.jsx(wn,{...f}),i.jsx(vn,{index:e,type:n.type,sectionIndex:r,remove:o,duplicate:h,move:g,upload:y})]})})})});qr.displayName="FieldWithActions";const Hr=d.memo(t=>{var S;const{field:n,index:e,dropState:r,fieldsOnly:o}=t,a=(S=r[n.identifier])==null?void 0:S.disabled,{setFieldValue:l,values:s}=V.useFormikContext(),p=u.useAlertDialog(),{reorderSection:c}=tn(),f=d.useCallback((I,F)=>{for(const L of I){const T=F.indexOf(L);l(`fields.${T}.condition`,null).then(),l(`fields.${T}.conditional`,!1).then()}},[l]),h=d.useCallback(I=>{var T;const F=n.fields[I];if(!F)throw new Error("Could not find field to remove.");const L=[];for(const M of s.fields)((T=M.condition)==null?void 0:T.identifier)===F.identifier&&L.push(M);return{removing:F,affectedSections:L,action:()=>l(`fields.${e}.fields`,ot(n.fields,I))}},[n.fields,s.fields,l,e]),g=d.useCallback(I=>{const{affectedSections:F,action:L,removing:T}=h(I),M=()=>{L().then(),f(F,s.fields)};if(F.length>0){const A=F.map($=>$.label).join(", ");p({title:"Remove condition?",description:`${T.label} is being used as a condition, deleting it will remove the condition from the ${A} section(s).`,action:"Remove",onAction:M});return}M()},[h,f,s.fields,p]),y=d.useCallback(()=>{const F=n.fields.map((B,_)=>h(_)).flatMap(B=>B.affectedSections),L=F.length?"Remove fields and conditions?":"Remove fields?",T=n.fields.length,M=F.map(B=>B.label).join(", "),A=F.length?`Deleting this section will remove the ${T} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${T} field(s) it contains.`,$=ot(s.fields,e),P=()=>l("fields",$);if(F.length>0){p({title:L,description:A,action:"Remove",onAction:()=>{P().then(()=>{f(F,$)})}});return}P().then()},[n.fields,s.fields,e,h,l,p,f]),x=d.useCallback(I=>{const F=I==="up"?e-1:e+1;c(r,n.identifier,e,F,s,l)},[e,c,r,n.identifier,s,l]),m=d.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:Sr(s.fields,e)}),[n,e,s.fields]),w=d.useCallback(()=>{const I=n.label??"Untitled section",F=n.fields.map(T=>({...T,identifier:en(null,T.label)})),L={...n,label:I,fields:F};at("fields",e+1,L,s,l)},[n,e,s,l]),E=d.useCallback(I=>{at(`fields.${e}.fields`,n.fields.length,Xo[I],s,l)},[e,n.fields.length,s,l]),b=Wr(E);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:I=>i.jsx(u.Card,{ref:I.innerRef,...I.draggableProps,...I.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:i.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[i.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!o&&i.jsx(wn,{...m}),i.jsx(re.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:a,children:F=>i.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:F.innerRef,...F.droppableProps,children:[n.fields.map((L,T)=>i.jsx(qr,{field:L,index:T,sectionIndex:e,remove:()=>{g(T)}},L.identifier)),F.placeholder,i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsxs(u.Button,{type:"button",variant:"solid",children:[i.jsx(u.RiIcon,{icon:"RiAddLine"})," Add field"]})}),i.jsx(u.Menu.Content,{children:b.flat().map(L=>i.jsxs(u.Menu.Item,{onSelect:L.onSelect,children:[L.icon,L.children]},L.value))})]})]})})]}),!o&&i.jsx(vn,{index:e,type:n.type,remove:y,duplicate:w,move:x})]})})})});Hr.displayName="FieldSectionWithActions";const Gr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Kr=d.memo(t=>{const{fieldsOnly:n}=t,{values:e,setFieldValue:r}=V.useFormikContext(),[o,a]=d.useReducer(na,e.fields,Ur),{reorderSection:l,reorderField:s}=tn();d.useEffect(()=>{a({type:"update",state:Ur(e.fields)})},[a,e.fields]);const p=d.useCallback(h=>{h.type==="SECTION"&&a({type:"hold",fieldId:h.draggableId})},[]),c=d.useCallback(h=>{const{source:g,destination:y,type:x,reason:m,draggableId:w}=h;if(a({type:"release"}),!y||m==="CANCEL")return;if(x==="ROOT"){l(o,w,g.index,y.index,e,r);return}if(x!=="SECTION")throw new Error("Unexpected droppable type.");const[E,b]=Gr(e.fields,g.droppableId)??[],[S,I]=Gr(e.fields,y.droppableId)??[];s(E,b,g.index,S,I,y.index,r)},[e,s,r,l,o]),f=d.useCallback(h=>{qo(h+1,e,r)},[e,r]);return i.jsx(re.DragDropContext,{onDragStart:p,onDragEnd:c,children:i.jsx(re.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>i.jsxs("div",{className:"flex flex-col gap-0",ref:h.innerRef,...h.droppableProps,children:[e.fields.map((g,y)=>i.jsxs(d.Fragment,{children:[i.jsx(Hr,{field:g,index:y,dropState:o,fieldsOnly:n}),!n&&y!==e.fields.length-1&&i.jsxs(u.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",onClick:()=>{f(y)},children:[i.jsx(u.RiIcon,{icon:"RiAddLine"})," Add section"]})]},g.identifier)),i.jsxs(u.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",onClick:()=>{f(e.fields.length)},children:[i.jsx(u.RiIcon,{icon:"RiAddLine"})," Add section"]}),h.placeholder]})})})});Kr.displayName="FieldsEditor";const ia=()=>{alert("This is a form preview, your data will not be saved.")},oa=d.memo(d.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:o,initialTitle:a,showExplainerText:l=!0,showFormTitle:s=!0,fieldsOnly:p=!1,showTabs:c=!0,tabsListClassName:f,hydrateRevisionWithImages:h}=t,{showError:g}=u.useToast(),y=d.useCallback(b=>{const S={};b.title||(S.title="Title is required."),(!b.fields||b.fields.length===0)&&(S.fields="At least one field is required.");let I=[];for(const[L,T]of b.fields.entries()){const A=gn.section.getFieldCreationSchema(Sr(b.fields,L),`fields.${L}`).map($=>$.field);I=[...I,...A];for(const[$,P]of T.fields.entries()){const _=gn[P.type].getFieldCreationSchema(`fields.${L}.fields.${$}`).map(ee=>ee.field);I=[...I,..._]}}const F=pt({fields:I},b);if(F&&(S.fields=F.fields),ue(S))return g({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),S},[g]),x=d.useMemo(()=>({title:a??"",description:"",fields:[{...it(en(null,"")),label:""}]}),[a]),m=o?h(o):void 0,w=V.useFormik({initialValues:Wo(m)??x,validate:y,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),E=d.useMemo(()=>kr(w.values),[w.values]);return i.jsx(u.Tabs.Root,{ref:n,defaultValue:"edit",children:i.jsxs("div",{className:"flex flex-col gap-2",children:[c&&i.jsxs(u.Tabs.List,{className:we("sticky top-0 z-[2000] flex bg-(--color-background)",f),children:[i.jsx(u.Tabs.Trigger,{className:"grow",value:"edit",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),i.jsx(u.Tabs.Trigger,{className:"grow",value:"preview",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),i.jsxs(u.Tabs.Content,{value:"edit",children:[l&&i.jsxs("span",{children:["Create your form using various field types. Sections can be"," ",i.jsx("strong",{children:"conditionally rendered"})," based on"," ",i.jsx("strong",{children:"answers to fields in preceding sections. "})]}),i.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:gt,onSubmit:w.handleSubmit,children:[i.jsxs(V.FormikProvider,{value:w,children:[s&&i.jsxs(i.Fragment,{children:[i.jsx(fe,{name:"title",render:({setValue:b,value:S,meta:I})=>i.jsx(Qt,{severity:"danger",helpText:I.error??null,children:i.jsx(u.Input.Root,{variant:"outline",size:"lg",accentColor:I.error?ne.danger:"primary",children:i.jsx(u.Input.Field,{placeholder:"Form title",value:S,onChange:F=>{b(F.target.value)},maxLength:100})})})}),i.jsx(fe,{name:"description",render:({setValue:b,value:S})=>i.jsx(u.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:S,onChange:I=>{b(I.target.value)},resize:"vertical",maxLength:1e3})})]}),i.jsx(Kr,{fieldsOnly:p}),i.jsx("span",{"data-accent-color":ne.danger,className:"text-xs text-(--accent-a11)",children:typeof w.errors.fields=="string"&&w.errors.fields})]}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&i.jsx(u.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),i.jsx(u.Button,{type:"submit",children:"Save form"})]})]})]}),i.jsx(u.Tabs.Content,{value:"preview",children:i.jsx(jr,{schema:E,onSubmit:ia,hideTitle:!s})})]})})})),aa=Object.values(j.Colors),la=1;async function sa(t,n,e,r){const o=t.getContext("2d",{}),a=new Image(r.width,r.height),l=new Image(r.width,r.height),s=new j.DeferredPromise;return a.onload=function(){o.drawImage(a,0,0,r.width,r.height),l.src=URL.createObjectURL(e),l.onload=async function(){o.drawImage(l,0,0,r.width,r.height);const p=t.toDataURL("image/jpeg",la),c=await j.fileToBlob(p),f=new File([c],n.name,{type:"image/jpeg"});s.resolve(f)}},a.src=URL.createObjectURL(n),s}const Xr=d.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:o,dirty:a,onDirty:l}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const s=d.useRef(null),p=d.useRef(null),[c,f]=d.useState(j.Colors.red),[h,g]=d.useState(null),[y,x]=d.useState(!1),[m,w]=d.useState(!1),E=d.useRef(null),b=u.useSize(E);d.useEffect(()=>{const _=new Image;_.onload=function(){g({width:_.naturalWidth,height:_.naturalHeight})},_.src=URL.createObjectURL(n)},[n]),d.useEffect(()=>{!m&&(b!=null&&b.width)&&b.height&&w(!0)},[b,m]);const S=d.useCallback(async()=>{a||e();const _=s.current;if(!_)return;if(!h)throw new Error("Original image size not loaded yet");const ee=await _.exportImage("png"),le=new Image(h.width,h.height);le.onload=async function(){const je=await j.fileToBlob(ee),bn=new File([je],n.name,{type:n.type}),Cn=p.current,J=await sa(Cn,n,bn,h);J.objectURL=URL.createObjectURL(J);const vt=await j.hashFile(n);await j.hashFile(J)!==vt&&r(J),x(!1),e()},x(!0),le.src=ee},[a,n,e,r,h]),I=d.useCallback(()=>{o(n)},[n,o]),F=d.useCallback(()=>{e()},[e]),L=d.useCallback(()=>{l(!0)},[l]),T=d.useCallback(()=>{s.current&&s.current.redo()},[]),M=d.useCallback(()=>{s.current&&s.current.undo()},[]),A=d.useCallback(()=>{s.current&&(l(!1),s.current.clearCanvas())},[l]),$=d.useCallback(_=>{s.current&&s.current.eraseMode(_)},[]),P=d.useCallback(()=>{S()},[S]),B=d.useCallback(()=>{j.downloadFile(n)},[n]);return i.jsx(Pe,{open:!0,onOpenChange:e,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs(i.Fragment,{children:[h&&i.jsx("canvas",{style:{display:"none"},id:"attachment-markup-canvas",ref:p,width:h.width,height:h.height}),i.jsxs("div",{className:"relative flex h-full w-full flex-col",children:[i.jsx("div",{className:"flex h-8 w-full items-center bg-(--color-background) px-2",children:i.jsx(u.ButtonGroup,{accentColor:"base",size:"md",variant:"soft",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx(u.IconButton,{"aria-label":"close",onClick:F,children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{"aria-label":`Download ${n.name}`,onClick:B,children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(Ct,{selectedColor:c,allColors:aa,onFinish:f,trigger:i.jsx(u.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:c},children:" "})}),i.jsx(u.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:$,children:i.jsx(u.RiIcon,{icon:"RiEraserFill"})}),i.jsx(u.Separator,{orientation:"vertical",size:"full"}),i.jsx(u.IconButton,{"aria-label":"undo",onClick:M,children:i.jsx(u.RiIcon,{icon:"RiArrowGoBackLine"})}),i.jsx(u.IconButton,{"aria-label":"undo",onClick:T,children:i.jsx(u.RiIcon,{icon:"RiArrowGoForwardLine"})}),i.jsx(u.IconButton,{"aria-label":"undo all",onClick:A,children:i.jsx(u.RiIcon,{icon:"RiLoopLeftLine"})})]}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(u.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:P,children:i.jsx(u.RiIcon,{icon:"RiSaveLine"})}),i.jsx(u.IconButton,{"aria-label":"Delete attachment",onClick:I,children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})})}),i.jsxs("div",{className:"relative flex w-full grow items-center justify-center p-4",children:[i.jsx("img",{className:"translate-xmax-h-[calc(100%-130px)] pointer-events-none invisible absolute top-[50%] left-[50%] max-w-svw translate-x-[-50%] translate-y-[-50%] object-contain",alt:"Photo attachment",ref:E,src:n.objectURL}),y?i.jsx(u.Spinner,{}):i.jsx(ei.ReactSketchCanvas,{backgroundImage:n.objectURL,ref:s,width:`${(b==null?void 0:b.width)||0}px`,height:`${(b==null?void 0:b.height)||0}px`,onStroke:L,strokeColor:c},m?"1":"0")]})]})]})})]})})});Xr.displayName="AttachmentEditor",C.BaseField=W,C.BaseFormElement=Kt,C.BooleanField=be,C.BooleanInput=Yt,C.ColorPicker=Ct,C.DateField=nt,C.DateInput=Jt,C.FieldSection=q,C.FileBadge=_e,C.FileCard=Ht,C.FileIcon=Be,C.FileViewerContext=Gt,C.FileViewerProvider=vr,C.FormBuilder=oa,C.FormRenderer=jr,C.ImageCard=_r,C.ImageMarkup=Xr,C.ImageViewer=Vt,C.InputWithHelpText=Qt,C.InputWithLabel=Q,C.InputWithLabelAndHelpText=Y,C.MultiSelectField=ke,C.MultiSelectInput=ln,C.MultiStringField=$e,C.MultiStringInput=nn,C.NumberField=ae,C.NumberInput=rn,C.PDFViewer=Ut,C.PatchField=fe,C.PatchFormProvider=ea,C.QrField=lt,C.QrInput=on,C.QrScanner=an,C.SUPPORTED_IMAGE_FILE_TYPES=xt,C.SUPPORTED_PDF_FILE_TYPES=jt,C.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=Wt,C.SelectField=Ve,C.SelectInput=sn,C.SpreadsheetViewer=qt,C.StringField=ct,C.StringInput=cn,C.TextField=dt,C.TextInput=dn,C.decodeFormValues=Yo,C.deserialize=ft,C.deserializeField=hn,C.emptyBaseField=G,C.emptyBooleanField=br,C.emptyDateField=Cr,C.emptyMultiSelectField=Pr,C.emptyMultiStringField=Nr,C.emptyNumberField=Fr,C.emptyQrField=Lr,C.emptySelectField=Mr,C.emptyStringField=Or,C.emptyTextField=Br,C.encodeFormValues=Jo,C.flattenFields=pn,C.formRevisionToSchema=kr,C.initialFormValues=mt,C.isConditionMet=mn,C.useFieldInput=Zt,C.useFieldInputs=ze,C.useFileViewer=gr,C.useFormikInput=z,C.validateForm=pt,C.valueIsFile=ht,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
45
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},Mo="DialogDescriptionWarning",Ao=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${fr(Mo).contentName}}.`;return v.useEffect(()=>{var a;const o=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},Pe=nr,Me=or,Ae=ar,Oe=lr;const Re=500,ye=1e4,ne={danger:"danger",warning:"warning",info:"base",success:"success"},kt={xs:"0",sm:"768px",md:"1024px",lg:"1024px",xl:"1280px"},Vt=d.memo(t=>{const{file:n,onClose:e,onDelete:r}=t,{md:o}=u.useViewportSize(kt),a=d.useRef(null),l=d.useRef(null),s=d.useRef(null),p=d.useCallback(()=>{if(!l.current||!a.current||!s.current)return;const h=s.current.height-l.current.clientHeight,g=s.current.width-l.current.clientWidth;h>=0||g>=0?g>h?(a.current.style.width=`${l.current.clientWidth}px`,a.current.style.height="unset"):(a.current.style.height=`${l.current.clientHeight}px`,a.current.style.width="unset"):(a.current.style.width=`${s.current.width}px`,a.current.style.height=`${s.current.height}px`)},[]),c=d.useCallback(()=>{r&&r(n)},[n,r]),f=d.useCallback(()=>{j.downloadFile(n)},[n]);return d.useLayoutEffect(()=>{const h=new Image;h.onload=()=>{s.current={width:h.width,height:h.height},p()},h.src=URL.createObjectURL(n)},[p,n]),d.useLayoutEffect(()=>{if(!l.current)return;const h=new ResizeObserver(()=>{p()});return h.observe(l.current),()=>{h.disconnect()}},[p]),i.jsx(Pe,{open:!0,onOpenChange:e,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs("div",{className:"flex h-full w-full flex-col",children:[i.jsx("div",{className:"flex h-max w-full items-center bg-(--color-background) p-2",children:i.jsx(u.ButtonGroup,{className:"w-full",accentColor:"base",variant:"soft",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex justify-start gap-2 items-center",children:[i.jsx(u.IconButton,{onClick:e,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{onClick:f,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsx("div",{className:"flex justify-center",children:i.jsx(_e,{file:n,accentColor:"base",truncateLength:o?void 0:25})}),i.jsx("div",{className:"flex justify-end",children:!!r&&i.jsx(u.IconButton,{onClick:c,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})})]})})}),i.jsx("div",{className:"h-full w-full overflow-hidden p-5",children:i.jsx("div",{className:"flex h-full w-full items-center justify-center overflow-hidden",ref:l,children:i.jsx("img",{ref:a,src:URL.createObjectURL(n),alt:""})})})]})})]})})});Vt.displayName="ImageViewer";const jt=["application/pdf"];yt.pdfjs.GlobalWorkerOptions.workerSrc=new URL("pdfjs-dist/build/pdf.worker.min.js",typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:bt&&bt.tagName.toUpperCase()==="SCRIPT"&&bt.src||new URL("forms.umd.cjs",document.baseURI).href).toString();const Oo={initial:.6,xs:.8,sm:.9,md:1,lg:1.1,xl:1.1},Ut=d.memo(t=>{const{file:n,onDelete:e,onClose:r}=t,[o,a]=d.useState(null),[l,s]=d.useState(0),[p,c]=d.useState(!1),{lg:f,size:h}=u.useViewportSize(kt);d.useEffect(()=>{s(0),c(!1),a(null)},[n]);const g=d.useCallback(b=>{s(0),a(b)},[]),y=d.useCallback(()=>{c(!0)},[]),x=d.useCallback(()=>{!o||l===o.numPages-1||s(b=>b+1)},[l,o]),m=d.useCallback(()=>{j.downloadFile(n)},[n]),w=d.useCallback(()=>{l!==0&&s(b=>b-1)},[l]),E=d.useCallback(()=>{e&&e(n)},[n,e]);return i.jsx(Pe,{open:!0,onOpenChange:r,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs("div",{className:"flex h-full w-full flex-col items-center",children:[i.jsx("div",{className:"h-max w-full shrink-0 items-center bg-(--color-background) p-2",children:i.jsx(u.ButtonGroup,{className:"flex items-center gap-1",variant:"soft",accentColor:"base",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"w-full gap-2 flex items-center",children:[i.jsx(u.IconButton,{onClick:r,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{onClick:m,"aria-label":"download",children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsx("div",{className:"flex justify-center",children:i.jsx(_e,{file:n,accentColor:"base",truncateLength:f?void 0:25})}),i.jsx("div",{className:"flex justify-end",children:!!e&&i.jsx(u.IconButton,{onClick:E,"aria-label":"delete",children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})})]})})}),i.jsxs("div",{className:"relative flex h-full w-full flex-col items-center gap-2 p-3",children:[!o&&!p&&i.jsx(hr,{}),i.jsx("div",{className:"flex h-max max-h-full w-max max-w-full flex-col items-center justify-center overflow-auto [scrollbar-color:var(--base-6)_transparent] [scrollbar-width:thin]",children:i.jsxs(yt.Document,{className:"relative",file:n,onLoadSuccess:g,onLoadError:y,error:"",loading:"",children:[i.jsx(yt.Page,{scale:Oo[h],pageIndex:l}),!!o&&!p&&i.jsx("div",{className:"absolute top-0 z-[2] flex w-full justify-center py-2",children:i.jsxs(u.ButtonGroup,{variant:"solid",accentColor:"base",size:"sm",children:[i.jsx(u.IconButton,{onClick:w,"aria-label":"previous page",children:i.jsx(u.RiIcon,{icon:"RiArrowLeftLine"})}),i.jsxs(u.Badge,{accentColor:"base",style:{borderRadius:0},variant:"solid",children:[l+1,"/",o.numPages]}),i.jsx(u.IconButton,{onClick:x,"aria-label":"next-page",children:i.jsx(u.RiIcon,{icon:"RiArrowRightLine"})})]})})]})}),p&&i.jsx(pr,{})]})]})})]})})});Ut.displayName="PDFViewer";const hr=d.memo(()=>i.jsx("div",{className:"absolute flex h-full w-full items-center justify-center",children:i.jsx(u.Spinner,{})}));hr.displayName="SpinnerComponent";const pr=d.memo(()=>i.jsxs("div",{className:"flex h-[70%] w-[40%] flex-col items-center justify-center rounded-md border border-(--base-a6) bg-(--base-2)",children:[i.jsx(u.RiIcon,{icon:"RiFileWarningLine",size:40}),i.jsx("span",{className:"text-sm font-light text-(--accent-a11)","data-accent-color":"base",children:"Failed to load"})]}));pr.displayName="ErrorComponent";const Wt=["text/csv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],qt=d.memo(t=>{const{file:n,onClose:e,onDelete:r}=t,{md:o}=u.useViewportSize(kt),[a,l]=d.useState([]),[s,p]=d.useState({}),[c,f]=d.useState(),[h,g]=d.useState({rowLabels:[],columnLabels:[],data:[[]]}),y=d.useMemo(()=>d.lazy(()=>import("react-spreadsheet")),[]);d.useEffect(()=>{n.arrayBuffer().then(b=>{const{SheetNames:S,Sheets:I}=En.read(b);l(S),p(I),f(S[0])})},[n]),d.useEffect(()=>{if(!c)return;const b=s[c],S=En.utils.sheet_to_json(b),I=Object.keys(S[0]??{}).splice(1),F=S.map(T=>Object.values(T)[0]),L=S.map(T=>I.map(M=>({value:T[M],readOnly:!0})));g({rowLabels:F,columnLabels:I,data:L})},[c,s]);const x=d.useCallback(()=>{r&&r(n)},[n,r]),m=d.useCallback(()=>{j.downloadFile(n)},[n]),w=d.useCallback(()=>{if(!c)throw new Error(`Expected an activeSheet, got ${c}`);const b=a.indexOf(c);if(b<0)throw new Error(`Expected activeSheet to be present in sheets, ${c} not found in ${a.join(", ")}`);b!==a.length-1&&f(a[b+1])},[c,a]),E=d.useCallback(()=>{if(!c)throw new Error(`Expected an activeSheet, got ${c}`);const b=a.indexOf(c);if(b<0)throw new Error(`Expected activeSheet to be present in sheets, ${c} not found in ${a.join(", ")}`);b!==0&&f(a[b-1])},[c,a]);return i.jsx(Pe,{open:!0,onOpenChange:e,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs("div",{className:"flex h-full w-full flex-col overflow-hidden",children:[i.jsx("div",{className:"h-max w-full shrink-0 bg-(--color-background) p-2",children:i.jsx(u.ButtonGroup,{size:"md",variant:"soft",accentColor:"base",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsx(u.IconButton,{onClick:e,"aria-label":"close",children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{onClick:m,"aria-label":"download",children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsx("div",{className:"flex justify-center",children:i.jsx(_e,{file:n,accentColor:"base",truncateLength:o?void 0:25})}),i.jsx("div",{className:"flex justify-end gap-2",children:!!r&&i.jsx(u.IconButton,{"aria-label":"delete",onClick:x,children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})})]})})}),i.jsx("div",{className:"flex h-full w-full flex-col items-center gap-3 overflow-hidden p-2",children:i.jsxs(d.Suspense,{fallback:i.jsx(u.Spinner,{}),children:[i.jsx("div",{className:"flex h-max max-h-[calc(100%-50px)] w-max max-w-full overflow-auto [scrollbar-color:var(--base-6)_transparent] [scrollbar-width:thin]",children:i.jsx(y,{className:"z-[1] h-full",data:h.data,rowLabels:h.rowLabels,columnLabels:h.columnLabels})}),i.jsx("div",{className:"flex h-max shrink-0 bg-(--base-2)",children:i.jsxs(u.ButtonGroup,{className:"flex items-center",variant:"solid",accentColor:"base",size:"sm",children:[i.jsx(u.IconButton,{"aria-label":"previous",onClick:E,children:i.jsx(u.RiIcon,{icon:"RiArrowLeftLine"})}),i.jsx(u.Badge,{variant:"solid",size:"sm",style:{borderRadius:0},accentColor:"base",children:c}),i.jsx(u.IconButton,{"aria-label":"next",onClick:w,children:i.jsx(u.RiIcon,{icon:"RiArrowRightLine"})})]})})]})})]})})]})})});qt.displayName="SpreadsheetViewer";const Be=d.memo(t=>{const{fileType:n}=t,e=d.useMemo(()=>Wt.includes(n)?i.jsx(u.RiIcon,{icon:"RiFileExcelLine"}):jt.includes(n)?i.jsx(u.RiIcon,{icon:"RiFilePdfLine"}):xt.includes(n)?i.jsx(u.RiIcon,{icon:"RiFileImageLine"}):i.jsx(u.RiIcon,{icon:"RiFileLine"}),[n]);return i.jsx("div",{className:"h-max w-max",children:e})});Be.displayName="FileIcon";const _e=d.memo(t=>{const{file:n,truncateLength:e,hideName:r=!1,...o}=t,a=d.useMemo(()=>e!==void 0?j.truncate(n.name,e):n.name,[n.name,e]);return i.jsxs(u.Badge,{...o,children:[i.jsx(Be,{fileType:n.type}),!r&&a]})});_e.displayName="FileBadge";function mr(t){var n,e,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var o=t.length;for(n=0;n<o;n++)t[n]&&(e=mr(t[n]))&&(r&&(r+=" "),r+=e)}else for(e in t)t[e]&&(r&&(r+=" "),r+=e);return r}function Bo(){for(var t,n,e=0,r="",o=arguments.length;e<o;e++)(t=arguments[e])&&(n=mr(t))&&(r&&(r+=" "),r+=n);return r}const we=Bo,Ht=d.memo(d.forwardRef((t,n)=>{const{file:e,className:r,error:o,truncateLength:a,rightSlot:l,...s}=t,p=d.useMemo(()=>{if(e)return a!==void 0?j.truncate(e.name,a):e.name},[e,a]);return i.jsxs("div",{className:we(r,"flex h-5 w-full items-center gap-2 rounded-md border border-(--base-a6) bg-(--base-2) text-sm py-1 px-2 h-max",{"text-(--gray-11)":o}),ref:n,...s,children:[o?i.jsx(u.RiIcon,{icon:"RiFileWarningLine"}):i.jsx(Be,{fileType:(e==null?void 0:e.type)??""}),o||(e?p:i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(u.Spinner,{})})),l]})}));Ht.displayName="FileCard";const Gt=d.createContext(()=>{throw new Error("No FileViewerProvider found")}),gr=()=>d.useContext(Gt),vr=d.memo(t=>{const{children:n}=t,[e,r]=d.useState(null),[o,a]=d.useState(null),l=d.useCallback(()=>{r(null),a(null)},[]),s=d.useCallback(f=>{r(f(l))},[l]),p=d.useCallback(()=>{e&&(e.onClose&&e.onClose(),l())},[l,e]);d.useEffect(()=>{if(!e)return;const{file:f}=e;if(Wt.includes(f.type)){a("spreadsheet");return}if(jt.includes(f.type)){a("pdf");return}if(xt.includes(f.type)){a("image");return}},[e]);const c=d.useMemo(()=>s,[s]);return i.jsxs(Gt.Provider,{value:c,children:[n,e&&i.jsxs(i.Fragment,{children:[o==="spreadsheet"&&i.jsx(qt,{file:e.file,onDelete:e.onDelete,onClose:p}),o==="pdf"&&i.jsx(Ut,{file:e.file,onDelete:e.onDelete,onClose:p}),o==="image"&&i.jsx(Vt,{file:e.file,onDelete:e.onDelete,onClose:p})]})]})});vr.displayName="FileViewerProvider";class Kt{constructor(n){N(this,"type");N(this,"identifier");N(this,"description");const{description:e=null,identifier:r,type:o}=n;this.identifier=r,this.description=e,this.type=o}getId(){return this.identifier}static deserialize(n){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}const G={label:"",description:"",required:!1};class W extends Kt{constructor(e){const{label:r,required:o,image:a,fieldValidators:l=[],formValidators:s=[],...p}=e;super(p);N(this,"required");N(this,"formValidators");N(this,"fieldValidators");N(this,"label");N(this,"image");N(this,"onlyValidateAfterTouched",!0);this.label=r,this.required=o,this.image=a,this.fieldValidators=l,this.formValidators=s}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,r){if(this.required&&this.isBlank(e))return"This field is required.";for(const o of this.getFieldValidators()){const a=o(e);if(a)return a}if(r)for(const o of this.getFormValidators()){const a=o(e,r);if(a)return a}}_serialize(){return{...super._serialize(),label:this.label,required:this.required,image:this.image}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}encodeValueToJson(e){return JSON.stringify(e)}decodeJsonToValue(e){return JSON.parse(e)}}N(W,"fieldTypeName"),N(W,"fieldTypeDescription");const z=t=>{const{id:n,field:e,formId:r,size:o,showInputOnly:a,internal:l,...s}=t,[p,c,f]=V.useField(e.getId()),{touched:h}=c,g=c.error??e.description,y=c.error?"danger":void 0,x=n??`${r}-${e.getId()}-input`,m=`${x}-label`,w=e.required?`${e.label} *`:e.label,E=d.useMemo(()=>({...p,onChange:I=>{const F=e.getValueFromChangeEvent(I);f.setValue(F,!1).then(),(h||!e.onlyValidateAfterTouched)&&f.setError(e.getError(F))},onBlur:I=>{f.setTouched(!0,!1).then(),f.setError(e.getError(e.getValueFromChangeEvent(I)))}}),[e,p,f,h]);return console.debug("severity",y),[{helpText:g,size:o,severity:y,inputId:x,labelId:m,label:w,showInputOnly:a,internal:l,fieldProps:E,helpers:f,field:e},{...s,"aria-labelledby":m}]};var et=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function _o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var tt={exports:{}},zo=tt.exports,yr;function $o(){return yr||(yr=1,function(t,n){(function(e,r){r()})(zo,function(){function e(c,f){return typeof f>"u"?f={autoBom:!1}:typeof f!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),f={autoBom:!f}),f.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(c.type)?new Blob(["\uFEFF",c],{type:c.type}):c}function r(c,f,h){var g=new XMLHttpRequest;g.open("GET",c),g.responseType="blob",g.onload=function(){p(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function o(c){var f=new XMLHttpRequest;f.open("HEAD",c,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(c){try{c.dispatchEvent(new MouseEvent("click"))}catch{var f=document.createEvent("MouseEvents");f.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),c.dispatchEvent(f)}}var l=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof et=="object"&&et.global===et?et:void 0,s=l.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),p=l.saveAs||(typeof window!="object"||window!==l?function(){}:"download"in HTMLAnchorElement.prototype&&!s?function(c,f,h){var g=l.URL||l.webkitURL,y=document.createElement("a");f=f||c.name||"download",y.download=f,y.rel="noopener",typeof c=="string"?(y.href=c,y.origin===location.origin?a(y):o(y.href)?r(c,f,h):a(y,y.target="_blank")):(y.href=g.createObjectURL(c),setTimeout(function(){g.revokeObjectURL(y.href)},4e4),setTimeout(function(){a(y)},0))}:"msSaveOrOpenBlob"in navigator?function(c,f,h){if(f=f||c.name||"download",typeof c!="string")navigator.msSaveOrOpenBlob(e(c,h),f);else if(o(c))r(c,f,h);else{var g=document.createElement("a");g.href=c,g.target="_blank",setTimeout(function(){a(g)})}}:function(c,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof c=="string")return r(c,f,h);var y=c.type==="application/octet-stream",x=/constructor/i.test(l.HTMLElement)||l.safari,m=/CriOS\/[\d]+/.test(navigator.userAgent);if((m||y&&x||s)&&typeof FileReader<"u"){var w=new FileReader;w.onloadend=function(){var S=w.result;S=m?S:S.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=S:location=S,g=null},w.readAsDataURL(c)}else{var E=l.URL||l.webkitURL,b=E.createObjectURL(c);g?g.location=b:location.href=b,g=null,setTimeout(function(){E.revokeObjectURL(b)},4e4)}});l.saveAs=p.saveAs=p,t.exports=p})}(tt)),tt.exports}var wr=$o();const ko=_o(wr),Xt=d.memo(t=>{const{file:n,url:e,name:r,setShowPreview:o}=t,a=d.useCallback(l=>{l.stopPropagation();const s=new Blob([n]);ko(s,r)},[r,n]);return i.jsxs(i.Fragment,{children:[i.jsx("button",{className:"fixed top-0 left-0 z-[5000] h-full w-full bg-[rgba(0,0,0,0.85)] bg-black",type:"button",onClick:()=>{o(!1)},children:i.jsx("img",{className:"absolute top-[50%] left-[50%] z-[5001] max-h-[calc(100%-120px)] max-w-svw translate-x-[-50%] translate-y-[50%] object-contain",src:e,alt:r,onClick:l=>{l.stopPropagation()}})}),i.jsxs("div",{className:"fixed top-0 left-0 z-[5001] flex w-full items-center bg-(--color-background)",children:[i.jsx(u.IconButton,{className:"min-w-[50px]",variant:"soft","aria-label":"Exit preview",onClick:()=>{o(!1)},children:i.jsx(u.RiIcon,{icon:"RiArrowLeftLine"})}),i.jsx("span",{className:"grow text-center",children:r}),i.jsx(u.IconButton,{className:"min-w-[50px]",variant:"soft","aria-label":`Download ${r}`,onClick:a,children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]})]})});Xt.displayName="FullScreenImagePreview";const Q=t=>{const{className:n,label:e,children:r,size:o,severity:a,inputId:l,labelId:s,image:p}=t,[c,f]=d.useState(void 0),[h,g]=d.useState(!1),y=a?ne[a]:"base";console.debug(a,y),d.useEffect(()=>{p instanceof Promise?p.then(f).catch(console.error):f(p)},[p]);const x=c?URL.createObjectURL(c):void 0;return i.jsxs("div",{className:"flex flex-col gap-2",children:[c&&i.jsxs(i.Fragment,{children:[i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:x,alt:c.name,onClick:()=>{g(!0)}}),h&&i.jsx(Xt,{file:c,url:x,name:c.name,setShowPreview:g})]}),i.jsxs("label",{className:we(n,"flex flex-col gap-1"),htmlFor:l,children:[i.jsx(u.Text,{accentColor:y,size:o,id:s,weight:"medium",children:e}),r]})]})},Qt=t=>{const{helpText:n,children:e,severity:r}=t,o=r?ne[r]:"base";return i.jsxs("div",{className:"flex flex-col gap-1",children:[e,i.jsx("div",{className:"flex flex-col w-full",children:i.jsx(u.Text,{accentColor:o,size:"xs",children:n})})]})},Y=t=>{const{children:n,...e}=t;return i.jsx(Qt,{...e,children:n})},Vo=[!0,"true"],Yt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);c=a?null:c,f=a?"":f;const h=Vo.includes(s.value);return i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,className:"align-center flex-row-reverse justify-end gap-2",children:i.jsx(u.Checkbox.Root,{...p,...s,id:n,accentColor:"base",value:h.toString(),checked:h,onCheckedChange:s.onChange,onChange:void 0,onBlur:void 0,variant:"surface",children:i.jsx(u.Checkbox.Indicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})})})})})});Yt.displayName="BooleanInput";const br={...G,type:"boolean"},Ce=class Ce extends W{constructor(e){super({...e,type:"boolean"});N(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}getValueFromChangeEvent(e){return typeof e=="boolean"?e:e.target.checked}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Ce(e)}getInput(e){return i.jsx(Yt,{...e,field:this})}};N(Ce,"fieldTypeName","Checkbox"),N(Ce,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),N(Ce,"Icon",U.RiCheckboxCircleLine);let be=Ce;const Jt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);c=a?null:c,f=a?"":f;const h=s.value?s.value.split("T")[0]:"";return i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,type:"date",id:n,value:h})})})})});Jt.displayName="DateInput";const Cr={...G,type:"date"},xe=class xe extends W{constructor(e){super({...e,type:"date"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return new Date(e.target.value).toISOString()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new xe(e)}getInput(e){return i.jsx(Jt,{field:this,...e})}};N(xe,"fieldTypeName","Date"),N(xe,"fieldTypeDescription","Allows specifying a date."),N(xe,"Icon",U.RiCalendarLine);let nt=xe;const xr=d.memo(t=>{const{field:n,...e}=t,[{value:r}]=V.useField(n.options.clonedFieldIdentifier),o=d.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?ft(a):null},[n.options,r]);return Zt(o,e)});xr.displayName="FieldInputCloner";const jo={...G,type:"custom"};class rt extends W{constructor(e,r){super({...e,type:"custom"});N(this,"Component");N(this,"options");this.options=e,this.Component=r}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const r=this.Component;return i.jsx(r,{field:this,...e})}}N(rt,"fieldTypeName","Custom"),N(rt,"fieldTypeDescription","Allows re-rendering of field already in the form");class Uo extends rt{constructor(n){super(n,xr)}}const Zt=(t,n)=>d.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),ze=(t,n)=>{const e=d.useMemo(()=>t.map(r=>i.jsx("div",{children:r.getInput(n)},r.getId())),[t,n]);return i.jsx("div",{className:"flex flex-col gap-2",children:e})},it=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Wo=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const o of n)o.type==="section"?(e.length>0&&(r.push(it(`AUTO_section-${n.indexOf(o)}`,e)),e=[]),r.push(o)):e.push(o);return e.length>0&&r.push(it("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Rt(t,n,e){const r=Array.from(t),[o]=r.splice(n,1);if(!o)throw new Error("Could not find field to reorder.");return r.splice(e,0,o),r}function Ir(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function ot(t,n){const e=Array.from(t);return e.splice(n,1),e}const en=(t,n)=>{const e=new Date;return`${j.slugify(n)}-${e.getTime()}`},Er=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=Er(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},Sr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),at=(t,n,e,r,o)=>{const{label:a}=e,l={...e,identifier:en(null,a)},s=K(r,t);if(s===void 0)throw new Error("Parent path must point to an existing field.");if(!Array.isArray(s))throw new Error("Parent path must point to an array.");const p=Ir(s,n,l);o(t,p).then()},qo=(t,n,e)=>{const r={...it(),label:""};at("fields",t,r,n,e)},tn=()=>{const{showError:t}=u.useToast(),n=d.useCallback((r,o,a,l,s,p)=>{const c=r[o];if(!c)throw new Error("Could not find section context.");let f=typeof c.conditionIndex<"u"?Math.max(c.conditionIndex+1,l):l;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==l){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}p("fields",Rt(s.fields,a,f))},[t]),e=d.useCallback((r,o,a,l,s,p,c)=>{var f;if(!(r!=null&&r.fields)||!l)throw new Error("Could not find section with fields.");if(r.identifier===l.identifier)c(`fields.${o}.fields`,Rt(r.fields,a,p)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=l.condition)==null?void 0:f.identifier)===h.identifier){t({title:"Could not reorder field",description:"Field must be above the section whose condition references it."});return}c(`fields.${o}.fields`,ot(r.fields,a)).then(),c(`fields.${s}.fields`,Ir(l.fields,p,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},nn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);c=a?null:c,f=a?"":f;const h=d.useMemo(()=>Array.isArray(s.value)?s.value:[],[s.value]),{onChange:g,onBlur:y}=s,x=`${n}-droppable`,{disabled:m}=p,[w,E]=d.useState(""),[b,S]=d.useState(""),I=b||c,F=d.useCallback(P=>{g(P),y(P)},[g,y]),L=d.useCallback(P=>{h.findIndex(B=>B===P.target.value.trim())>=0?S("All options must be unique"):P.target.value?S(""):S("Option cannot be empty"),E(P.target.value)},[E,h]),T=d.useCallback(()=>{if(b)return;if(!w.trim()){S("Option cannot be empty");return}const P=w.trim();F([...h,P]),E("")},[w,b,F,h]),M=d.useCallback(P=>{P.key==="Enter"&&(P.preventDefault(),T())},[T]),A=d.useCallback(P=>{F(ot(h,P))},[h,F]),$=d.useCallback(P=>{if(!P.destination)return;const B=P.source.index,_=P.destination.index;F(Rt(h,B,_))},[F,h]);return i.jsx(re.DragDropContext,{onDragEnd:$,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Y,{helpText:I,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:(!m||h.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx("div",{className:"grow",children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,...s,value:w,onChange:L,onKeyDown:M,id:n,placeholder:l.placeholder,onBlur:void 0})})}),i.jsx(u.IconButton,{type:"button","aria-label":"Add option",disabled:!!b||m,onClick:T,children:i.jsx(u.RiIcon,{icon:"RiAddLine"})})]})})}),i.jsx(re.Droppable,{droppableId:x,children:P=>i.jsxs("div",{className:"flex flex-col",...P.droppableProps,ref:P.innerRef,children:[h.map((B,_)=>i.jsx(re.Draggable,{draggableId:`${B}-draggable`,index:_,isDragDisabled:m,children:({draggableProps:ee,dragHandleProps:le,innerRef:je})=>i.jsxs(u.Badge,{...le,...ee,ref:je,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"md",variant:"soft",children:[i.jsx("span",{children:typeof B=="object"&&"label"in B?B.label:B}),i.jsx(u.IconButton,{size:"sm",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:m,onClick:()=>{A(_)},children:i.jsx(u.RiIcon,{icon:"RiCloseLargeLine"})})]})},B)),P.placeholder]})})]})})});nn.displayName="MultiStringInput";const Nr={...G,type:"multi-string",minimum_length:0,maximum_length:null},Ie=class Ie extends W{constructor(e){const{minimum_length:r,maximum_length:o,placeholder:a,...l}=e;super({...l,type:"multi-string"});N(this,"minLength");N(this,"maxLength");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.minLength=r??0,this.maxLength=o??1/0,this.placeholder=a??"Press enter to add a new option"}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return i.jsx(nn,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(r=>{if(Array.isArray(r)&&r.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(r=>{if(Array.isArray(r)&&r.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new Ie(e)}};N(Ie,"fieldTypeName","Multi-string"),N(Ie,"fieldTypeDescription","Allows the user to provide multiple unique strings."),N(Ie,"Icon",U.RiListCheck);let $e=Ie;const rn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);return c=a?null:c,f=a?"":f,i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,...s,type:"number",id:n,placeholder:l.placeholder,min:l.minimum,max:l.maximum,step:l.integers?1:.1})})})})});rn.displayName="NumberInput";const Fr={...G,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Tr=t=>"fields"in t,R=class R extends W{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:o=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:l="Enter a number",...s}=e;super({...s,type:"number"});N(this,"minimum");N(this,"maximum");N(this,"integers");N(this,"placeholder");this.minimum=r,this.maximum=o,this.integers=a,this.placeholder=l}getValueFromChangeEvent(e){const r=Number.parseFloat(e.target.value);return Number.isNaN(r)?"":r}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new R({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new R({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new be({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,o=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof o=="number"&&e.push(a=>{if(typeof a=="number"&&a>o)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(a=>{if(typeof a=="number"&&!Number.isInteger(a))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new R(e)}getInput(e){return i.jsx(rn,{field:this,...e})}};N(R,"fieldTypeName","Number"),N(R,"fieldTypeDescription","Allows specifying a number within a given range."),N(R,"Icon",U.RiHashtag),N(R,"_validateMin",e=>(r,o)=>{const a=Tr(o)?K(o,e):o;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),N(R,"_validateMax",e=>(r,o)=>{const a=Tr(o)?K(o,e):o;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let ae=R;const on=d.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:o,size:a,severity:l,showInputOnly:s,field:p,fieldProps:c},f]=z(t),[h,g]=d.useState(!1),y=c.value,x=d.useCallback(b=>{c.onChange({target:{value:b}}),g(!1)},[c]),m=d.useCallback(()=>{c.onChange({target:{value:""}})},[c]),w=d.useCallback(()=>{g(!0)},[]),E=d.useCallback(()=>{g(!1)},[]);return i.jsx(Y,{helpText:o,severity:l,children:i.jsxs(Q,{size:a,severity:l,inputId:n,labelId:e,label:r,image:s?void 0:p.image,className:"flex-col items-start justify-start gap-1",children:[i.jsx(Pe,{open:h,onOpenChange:g,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),i.jsx(Oe,{className:"fixed inset-0",children:i.jsx(an,{onQrScan:x,onClose:E})})]})}),i.jsxs("div",{className:"flex w-max items-center gap-1",children:[i.jsxs(u.Button,{...f,variant:"soft",onClick:w,type:"button",children:[i.jsx(u.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]}),y&&i.jsx("span",{className:"text-xs text-(--accent-a11)","data-accent-color":"primary",children:i.jsx(u.RiIcon,{icon:"RiCheckLine",style:{verticalAlign:"bottom"}})})]}),!!y&&i.jsx(u.Card,{children:i.jsxs("div",{className:"w-max items-center gap-2",children:[i.jsx("code",{className:"bg-(--base-a3)",children:y}),i.jsx(u.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:m,children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})})]})})]})})});on.displayName="QrInput";const an=d.memo(t=>{const{onQrScan:n,onClose:e}=t,r=d.useRef(null),[o,a]=d.useState(!1);return d.useEffect(()=>{if(!r.current)return;const l=new Zr(r.current,s=>{const p=s.data;n(p),l.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});a(!0),l.start().finally(()=>{a(!1)})},[n]),i.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[i.jsx("div",{className:"absolute top-0 flex w-full p-2",children:i.jsx(u.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",onClick:e,children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})})}),i.jsxs("div",{className:"relative max-h-full max-w-full",children:[i.jsx("video",{ref:r,style:{width:"100%",height:"100%"}}),o&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:i.jsx(u.Spinner,{})})]})]})});an.displayName="QrScanner";const Lr={...G,type:"qr"},Ee=class Ee extends W{constructor(e){super({...e,type:"qr"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="qr")throw new Error("Type mismatch.");return new Ee(e)}getInput(e){return i.jsx(on,{...e,field:this})}};N(Ee,"fieldTypeName","QR"),N(Ee,"fieldTypeDescription","Used for scanning/reading QR codes."),N(Ee,"Icon",U.RiQrCodeLine);let lt=Ee;class Dr extends W{constructor(e){const{placeholder:r="",...o}=e;super(o);N(this,"options");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(l=>(typeof l=="string"&&(l={label:l,value:l}),a.add(l.label),l)),a.size!==e.options.length&&console.error(`${e.options.length-a.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options,placeholder:this.placeholder}}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new $e({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const Ho=t=>t?Array.isArray(t)?t:[t]:[],ln=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t),{onChange:c,onBlur:f}=s;let[{helpText:h,label:g}]=z(t);h=a?null:h,g=a?"":g;const y=d.useMemo(()=>Ho(s.value),[s.value]),x=d.useCallback(m=>{c(m),f(m)},[c,f]);return i.jsx(Y,{helpText:h,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:g,image:a?void 0:l.image,children:i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsxs(u.Button,{id:n,className:"!justify-between",name:s.name,variant:"surface",type:"button",accentColor:"base",...p,children:[y.length>0?y.join(", "):l.placeholder,i.jsx(u.RiIcon,{icon:"RiArrowDownSLine"})]})}),i.jsx(u.Menu.Content,{children:i.jsxs(u.Menu.MultiSelectGroup,{values:y,onValuesChange:x,children:[i.jsxs(u.Menu.SelectAllItem,{allValues:l.options.map(({value:m})=>m),children:[i.jsx(u.Menu.SelectAllIndicator,{children:m=>m?i.jsx(u.RiIcon,{icon:"RiSubtractLine"}):i.jsx(u.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),l.options.map(m=>i.jsxs(u.Menu.MultiSelectItem,{value:m.value,children:[i.jsx(u.Menu.SelectedIndicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})}),m.label]},m.value))]})})]})})})});ln.displayName="MultiSelectInput";const Pr={...G,type:"multi-select",options:[]},Se=class Se extends Dr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}getValueFromChangeEvent(n){if(Array.isArray(n))return n;throw new Error("Expected an array.")}isBlank(n){return super.isBlank(n)||n.length===0}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Se(n)}getInput(n){return i.jsx(ln,{field:this,...n})}};N(Se,"fieldTypeName","Multi-select"),N(Se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),N(Se,"Icon",U.RiCheckboxLine);let ke=Se;const sn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t),{onChange:c,onBlur:f}=s;let[{helpText:h,label:g}]=z(t);h=a?null:h,g=a?"":g;const y=d.useCallback(m=>{c(m),f(m)},[c,f]),x=d.useMemo(()=>l.options.find(m=>m.value===s.value),[l.options,s.value]);return i.jsx(Y,{helpText:h,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:g,image:a?void 0:l.image,children:i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsxs(u.Button,{...s,className:"!justify-between",id:n,name:s.name,accentColor:"base",variant:"surface",type:"button",...p,children:[x?x.label:l.placeholder,i.jsx(u.RiIcon,{icon:"RiArrowDownSLine"})]})}),i.jsx(u.Menu.Content,{children:i.jsx(u.Menu.SelectGroup,{value:s.value,onValueChange:y,children:l.options.map(m=>i.jsxs(u.Menu.SelectItem,{value:m.value,children:[i.jsx(u.Menu.SelectedIndicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})}),m.label]},m.value))})})]})})})});sn.displayName="SelectInput";const Mr={...G,type:"select",options:[]},Ne=class Ne extends Dr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}getValueFromChangeEvent(n){return typeof n=="string"?n:n.target.value}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new Ne(n)}getInput(n){return i.jsx(sn,{field:this,...n})}};N(Ne,"fieldTypeName","Dropdown"),N(Ne,"fieldTypeDescription","Allows the user to select a single option from a list of options."),N(Ne,"Icon",U.RiMenuFoldLine);let Ve=Ne;const Ar=t=>"fields"in t;class st extends W{constructor(e){const{minLength:r,maxLength:o,placeholder:a="",...l}=e;super(l);N(this,"minLength");N(this,"maxLength");N(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=o?Math.max(o,0):ye,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ae({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:`${r}minimum_length`,minimum:0,maximum:100,formValidators:[this._validateMin(e)],integers:!0}),showDirectly:!1},{field:new ae({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:ye,formValidators:[this._validateMax(e)],integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(r=>{if(this.minLength&&(!r||r.length<this.minLength))return!this.required&&!r?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(r=>{if(typeof r=="string"&&this.maxLength&&r.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}}N(st,"_validateMin",e=>(r,o)=>{const a=Ar(o)?K(o,e):o;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),N(st,"_validateMax",e=>(r,o)=>{if(typeof r!="number")return null;const{minimum_length:a}=Ar(o)?K(o,e):o;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const cn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);return c=a?null:c,f=a?"":f,i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.Input.Root,{accentColor:"base",variant:"surface",children:i.jsx(u.Input.Field,{...p,...s,type:l.inputType,id:n,placeholder:l.placeholder})})})})});cn.displayName="StringInput";const Or={...G,type:"string",maximum_length:Re,input_type:"text"},Fe=class Fe extends st{constructor(e){const{inputType:r="text",...o}=e,a=e.maxLength?Math.min(Re,e.maxLength):Re,l=e.minLength?Math.min(e.minLength,a):void 0;super({...o,maxLength:a,minLength:l,type:"string"});N(this,"inputType");this.inputType=r}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:r,minimum_length:o,input_type:a,...l}=e;return new Fe({...l,maxLength:r,minLength:o,inputType:a,placeholder:"Enter a short description"})}getInput(e){return i.jsx(cn,{field:this,...e})}};N(Fe,"fieldTypeName","Short Text"),N(Fe,"fieldTypeDescription",`Short text fields can hold up to ${Re} characters on a single line.`),N(Fe,"Icon",U.RiInputField);let ct=Fe;const dn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:l,fieldProps:s},p]=z(t);let[{helpText:c,label:f}]=z(t);return c=a?null:c,f=a?"":f,i.jsx(Y,{helpText:c,severity:o,children:i.jsx(Q,{size:r,severity:o,inputId:n,labelId:e,label:f,image:a?void 0:l.image,children:i.jsx(u.TextArea,{...p,...s,className:"field-sizing-content",resize:"vertical",id:n,placeholder:l.placeholder,accentColor:"base",variant:"surface"})})})});dn.displayName="TextInput";const Br={...G,type:"text",maximum_length:ye},Te=class Te extends st{constructor(n){const e=n.maxLength?Math.min(ye,n.maxLength):ye,r=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:r,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:r,...o}=n;return new Te({...o,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return i.jsx(dn,{field:this,...n})}};N(Te,"fieldTypeName","Paragraph"),N(Te,"fieldTypeDescription",`Paragraph fields can hold up to ${ye} characters and can have multiple lines.`),N(Te,"Icon",U.RiAlignJustify);let dt=Te;const _r=d.memo(d.forwardRef((t,n)=>{const{file:e,alt:r,error:o,rightSlot:a,className:l,truncateLength:s,...p}=t,c=d.useRef(null),f=d.useRef(null),h=u.useSize(c);d.useLayoutEffect(()=>{!f.current||!h||(f.current.style.height=`${h.height*4}px`)},[h]);const g=d.useMemo(()=>{if(e)return s!==void 0?j.truncate(e.name,s):e.name},[e,s]);return i.jsxs("div",{className:we(l,"relative flex h-max w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...p,children:[!e&&!o&&i.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:i.jsx(u.Spinner,{})}),i.jsx("div",{ref:f,className:"-m-4 flex max-w-full items-center justify-center overflow-hidden bg-clip-padding",children:e&&!o&&i.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),i.jsxs("div",{className:we("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),ref:c,children:[o?i.jsx(u.RiIcon,{icon:"RiFileWarningLine"}):e&&i.jsx(Be,{fileType:e.type}),o??g,a]})]})})),Go=t=>{const n=["byte","kilobyte","megabyte"];let e=t,r=0;for(;e>1e3&&r<n.length-1;)e/=1e3,r++;return new Intl.NumberFormat([],{maximumFractionDigits:Math.max(0,r-1),style:"unit",unit:n[r]}).format(e)},zr=d.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:o,helpText:a,showInputOnly:l,field:s,fieldProps:p},c]=z(t),{onChange:f}=p;let[{label:h}]=z(t);h=l?"":h;const g=o?ne[o]:void 0,y=d.useRef(null),{value:x}=p,m=d.useMemo(()=>l?null:a||(s.maxFileSize?`Maximum file size: ${s.maxFileSize}MB`:null),[s.maxFileSize,a,l]),w=d.useCallback(()=>{var L;(L=y.current)==null||L.click()},[]),E=d.useCallback(L=>{const T=[...x];T.splice(L,1),f({target:{files:T}})},[x,f]),b=x?"Select new files":"Select files",S=x?"Select new file":"Select a file",I=s.maxFiles>1?b:S;return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(Y,{helpText:m,severity:o,children:i.jsxs(Q,{size:r,severity:o,inputId:n,labelId:e,label:h,image:l?void 0:s.image,children:[i.jsx("div",{className:"flex gap-2",children:i.jsxs(u.Button,{...c,className:"w-max",variant:"soft",onClick:w,id:"upload-input-upload-button",type:"button",children:[i.jsx(u.RiIcon,{icon:"RiUpload2Line"})," ",I]})}),i.jsx("input",{...c,type:"file",ref:y,id:n,accept:(F=s.extensions)==null?void 0:F.join(","),multiple:s.maxFiles>1,color:g,style:{display:"none"},...p,value:""})]})}),Array.isArray(x)&&x.length>0&&i.jsx("div",{className:"flex h-max flex-col gap-2",children:x.map((L,T)=>i.jsx($r,{field:s,file:L,onRemove:()=>{E(T)},disabled:c.disabled},T))})]})});zr.displayName="UploadInput";const $r=d.memo(t=>{const{file:n,field:e,onRemove:r,disabled:o}=t,[a,l]=d.useState(null),s=gr(),p=d.useMemo(()=>a&&e.getError([a]),[e,a]),{url:c,name:f}=d.useMemo(()=>{let m=null,w,E;return a!=null&&a.type.startsWith("image/")&&(m=URL.createObjectURL(a)),a?(w=a.name,E=Go(a.size)):(w="Downloading...",E="..."),{url:m,name:w,size:E}},[a]);d.useEffect(()=>{n instanceof Promise?n.then(l).catch(console.error):l(n)},[n]);const h=d.useCallback(m=>{if(m.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const w=new Blob([a]);wr.saveAs(w,f)},[f,a]),g=d.useCallback(m=>{m.stopPropagation(),r()},[r]),y=d.useCallback(()=>{a&&s(m=>({file:a,onDelete:o?void 0:()=>{r(),m()}}))},[o,r,s,a]),x=d.useMemo(()=>i.jsxs(u.ButtonGroup,{variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(u.IconButton,{"aria-label":`Download ${f}`,onClick:h,disabled:!a,children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})}),!o&&i.jsx(u.IconButton,{"aria-label":`Remove ${f}`,disabled:o,onClick:g,children:i.jsx(u.RiIcon,{icon:"RiCloseLargeLine"})})]}),[o,g,h,f,a]);return c?i.jsx(_r,{style:{cursor:"pointer"},onClick:y,file:a,error:p??void 0,rightSlot:x}):i.jsx(Ht,{style:{cursor:"pointer"},onClick:y,file:a,error:p??void 0,rightSlot:x})});$r.displayName="DisplayFile";const Ko={...G,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1},Le=class Le extends W{constructor(e){const{extensions:r,maximum_files:o,maximum_size:a,...l}=e;super({...l,type:"upload"});N(this,"extensions");N(this,"maxFileSize");N(this,"maxFiles");N(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof a=="number"?a:void 0,this.maxFiles=Math.max(typeof o=="number"?o:1,1),this.extensions=r}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ae({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:`${r}maximum_files`,integers:!0}),showDirectly:!1},{field:new ae({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${ut}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:ut,integers:!0}),showDirectly:!1},{field:new ke({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:`${r}extensions`,options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.maxFileSize??ut,o=r*1e3*1e3,a=this.maxFiles||1;return e.push(l=>{if(l&&l.some(s=>s.size>o))return`Files must be at most ${r}MB.`}),e.push(l=>{if(l&&l.length>a)return`You can only upload ${a} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new Le(e)}getInput(e){return i.jsx(zr,{field:this,...e})}};N(Le,"fieldTypeName","Upload"),N(Le,"fieldTypeDescription","Allows a file to be uploaded."),N(Le,"Icon",U.RiUpload2Line);let un=Le;const fn={date:nt,number:ae,boolean:be,select:Ve,string:ct,text:dt,custom:rt,upload:un,qr:lt,"multi-string":$e,"multi-select":ke},Xo={date:Cr,number:Fr,boolean:br,select:Mr,string:Or,text:Br,custom:jo,upload:Ko,qr:Lr,"multi-string":Nr,"multi-select":Pr},ut=50,Qo=ut*1e3*1e3,hn=t=>{const n=t.type;return fn[n].deserialize(t)},ft=t=>t.type==="section"?q.deserialize(t):hn(t);function kr(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>ft(r)),meta:{readonly:e}}}function pn(t){const n=[];for(const e of t.fields)if(e instanceof q)for(const r of e.fields)n.push(r);else{if(!(e instanceof W))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Yo(t,n){const e=pn(t),r={};for(const o of e){const a=n[o.identifier]??null;a!==null?r[o.identifier]=o.decodeJsonToValue(a):r[o.identifier]=a}return r}function Jo(t,n){const e=pn(t),r={};for(const o of e){const a=n[o.identifier];r[o.identifier]=o.encodeValueToJson(a)}return r}function ht(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function mn(t,n){if(!t)return!0;if(ht(n)||ht(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(o=>typeof o=="string"?o:o.value):n,r=Array.isArray(t.value)?t.value.map(o=>typeof o=="string"?o:o.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const o of r)if(!e.includes(o))return!1;return!0}return r===n}const Vr=d.memo(t=>{const{field:n,...e}=t,{label:r,description:o,fields:a,condition:l}=n,{values:s,setFieldValue:p}=V.useFormikContext(),c=l!=null&&l.identifier?K(s,l.identifier):void 0,f=d.useMemo(()=>c===void 0||mn(l,c),[l,c]);d.useEffect(()=>{if(!f)for(const g of a)p(g.getId(),"").then()},[f,a,p]);const h=ze(a,e);return f?i.jsx(u.Card,{children:i.jsxs("div",{className:"flex flex-col gap-6",children:[i.jsxs("div",{className:"flex flex-col",children:[i.jsx(u.Heading,{size:"lg",children:r}),i.jsx(u.Text,{accentColor:"base",children:o})]}),h]})}):null});Vr.displayName="FieldSectionLayout";const De=class De extends Kt{constructor(e){const{label:r=null,fields:o,condition:a=null,conditional:l,...s}=e;super({...s,type:"section"});N(this,"label");N(this,"fields");N(this,"condition");this.fields=o,this.condition=a,this.label=r,l===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const o=r&&`${r}.`;return[{field:new be({label:"Conditionally render section",identifier:`${o}conditional`,required:!1}),showDirectly:!0},{field:new De({label:"Conditional settings",identifier:`${o}conditional-settings`,condition:{identifier:`${o}conditional`,value:!0},fields:[new Ve({label:"Field",description:"The field to use for the condition.",options:e.map(a=>!a.label||a.type==="upload"?null:{label:a.label,value:a.identifier}).filter(a=>!!a),identifier:`${o}condition.identifier`,required:!0}),new Uo({label:"Value",identifier:`${o}condition.value`,required:!0,clonedFieldIdentifier:`${o}condition.identifier`,getFieldToClone(a){if(!a)return null;const l=e.find(s=>s.identifier===a);return l?{...l,label:"Value",identifier:`${o}condition.value`,description:"The value to compare against.",required:l.type!=="boolean"}:(console.error("Could not find field with identifier",a),null)}})]}),showDirectly:!1}]}static deserialize(e){if(e.type!=="section")throw new Error("Invalid type");if(!Array.isArray(e.fields))throw new Error(`Invalid fields: ${e.fields} (not an array)`);const r=e.fields.map(hn);return new De({...e,fields:r})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const r={};for(const o of this.fields){const a=o.getId(),l=o.getError(K(e,a),e);l&&wt(r,o.getId(),l)}return r}getInput(e){return i.jsx(Vr,{field:this,...e})}};N(De,"fieldTypeName","Section"),N(De,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let q=De;const ue=t=>Object.keys(t).length>0,pt=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof q){if(r.condition){const{identifier:o}=r.condition;if(!mn(r.condition,K(n,o)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof W))throw new Error("Invalid field type");const o=r.getId(),a=r.getError(K(n,o),n);a&&wt(e,o,a)}if(ue(e))return e},Zo=[null,void 0],mt=(t,n)=>t.reduce((e,r)=>r instanceof q?{...e,...mt(r.fields,n)}:(Zo.includes(K(e,r.getId()))&&wt(e,r.getId(),""),e),Rr(n)),Ro=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},jr=d.memo(d.forwardRef((t,n)=>{const{schema:e,values:r={},onSubmit:o=Ro,submitText:a="Submit",cancelText:l,onCancel:s,onDirty:p,onDirtyChange:c,hideTitle:f=!e.title,hideDescription:h,className:g,buttonProps:y}=t,{readonly:x}=e.meta,m=d.useMemo(()=>crypto.randomUUID(),[]),w=V.useFormik({initialValues:mt(e.fields,r),onSubmit:o,validate:F=>pt(e,F),validateOnBlur:!1,validateOnChange:!1}),{dirty:E}=w,b=d.useMemo(()=>typeof e.title=="string"?i.jsx(u.Heading,{size:"lg",children:e.title}):e.title,[e.title]),S=d.useMemo(()=>typeof e.description=="string"?i.jsx(u.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),I=ze(e.fields,{formId:m,disabled:x});return d.useEffect(()=>{E&&p&&p(),c&&c(E)},[E,p,c]),i.jsx(V.FormikProvider,{value:w,children:i.jsxs("form",{id:m,ref:n,className:we(g,"flex flex-col gap-2"),onSubmit:w.handleSubmit,children:[!f&&i.jsx(u.Card,{children:i.jsxs("div",{className:"flex flex-col gap-1",children:[b,!h&&S]})}),I,!x&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&i.jsxs(u.Button,{accentColor:ne.danger,...y,type:"button",onClick:s,children:[i.jsx(u.RiIcon,{icon:"RiCloseLine"}),l]}),i.jsxs(u.Button,{...y,type:"submit",disabled:!w.isValid,accentColor:"success",children:[i.jsx(u.RiIcon,{icon:"RiCheckLine"}),a]})]})]})})})),fe=d.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=V.useFormikContext(),[o,a,l]=V.useField(n),s=d.useMemo(()=>{const p=c=>{l.setValue(c,!1)};return e({value:o.value,meta:a,setValue:p,patchValue:()=>{r()}})},[e,o.value,a,r,l]);return i.jsx(i.Fragment,{children:s})});fe.displayName="PatchField";const ea=d.memo(d.forwardRef((t,n)=>{const{children:e,schema:r,values:o,onPatch:a,onError:l,requiresDiff:s=!0,onDirtyChange:p,...c}=t,f=d.useMemo(()=>mt(r.fields,o),[r.fields,o]),h=d.useCallback(b=>{const S={};for(const I in b){const F=b[I];F!==f[I]&&F!==void 0&&(S[I]=F)}return S},[f]),g=d.useCallback(b=>{const S=h(b);s&&!ue(S)||a(S)},[h,a,s]),y=d.useCallback(b=>{const S=pt(r,b);if(S&&l(S),p){const I=h(b);p(ue(I))}return S},[r,p,l,h]),x=V.useFormik({initialValues:f,onSubmit:g,validate:y,validateOnBlur:!1,validateOnChange:!1}),m=d.useCallback(()=>{if(p){const b=h(x.values);ue(b)&&p(!0)}},[x.values,h,p]),{errors:w,resetForm:E}=x;return d.useEffect(()=>{ue(w)&&E({values:f,errors:{}})},[w,f,E]),i.jsx(V.FormikProvider,{value:x,children:i.jsx("form",{...c,ref:n,onSubmit:x.handleSubmit,onChange:m,children:e})})})),gt="form-builder",ta=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],gn={...fn,section:q},na=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const o in e)e[o].disabled=!1;return e;case"hold":for(const o in e)(r=e[o])!=null&&r.conditionFields.has(n.fieldId)&&(e[o].disabled=!0);return e;case"update":return n.state}},ra=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const o of r.fields)if(o.identifier===n)return e}}},Ur=t=>{var e,r,o;const n={};for(let a=0;a<t.length;a++){const l=t[a];if(!l)throw new Error("Field is undefined.");const s=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,p=new Set(s);(r=l.condition)!=null&&r.identifier&&p.add(l.condition.identifier),n[l.identifier]={disabled:!1,conditionFields:p,conditionIndex:ra(t,(o=l.condition)==null?void 0:o.identifier),index:a,label:l.label}}return n},vn=d.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:o,duplicate:a,move:l,upload:s}=t;if(e!=="section"&&!s)throw new Error("Upload function prop must be defined for non-section fields.");const{values:p}=V.useFormikContext(),c=d.useRef(null),f=d.useMemo(()=>{const h=[{Icon:U.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:U.RiDeleteBin2Line,key:"delete",text:"Delete",buttonProps:{onClick:o}}),e!=="section"&&h.unshift({Icon:U.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=c.current)==null||g.click()}}}),(r===void 0&&n!==p.fields.length-1||r!==void 0&&(r<p.fields.length-1||n!==p.fields[r].fields.length-1))&&h.unshift({Icon:U.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{l("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:U.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{l("up")}}}),h},[a,n,l,o,r,e,p.fields]);return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"mx-2 hidden flex-col gap-5 sm:flex",children:f.map(h=>i.jsx(u.IconButton,{type:"button",variant:"ghost",accentColor:h.key.startsWith("move")?"base":void 0,"aria-label":h.text,...h.buttonProps,children:i.jsx(h.Icon,{})},h.key))}),i.jsx("div",{className:"sm:hidden",children:i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsx(u.IconButton,{variant:"ghost","aria-label":"Actions menu",children:i.jsx(u.RiIcon,{icon:"RiMore2Line"})})}),i.jsx(u.Menu.Content,{children:f.map(h=>{var g;return i.jsxs(u.Menu.Item,{onClick:(g=h.buttonProps)==null?void 0:g.onClick,children:[i.jsx(h.Icon,{}),h.text]},h.key)})})]})}),e!=="section"&&i.jsx("input",{style:{display:"none"},ref:c,type:"file",accept:"image/*",onChange:s})]})});vn.displayName="FieldActions";const Wr=(t=()=>null)=>d.useMemo(()=>ta.map(n=>n.map(e=>{const r=fn[e],o=r.Icon;return{children:r.fieldTypeName,icon:i.jsx(o,{}),value:e,onSelect:()=>{t(e)}}})),[t]),he=t=>t.type==="section",yn=d.memo(t=>{const{popoverInputs:n,hasError:e}=t;return i.jsxs(u.Popover.Root,{children:[i.jsx(u.Popover.Trigger,{children:i.jsxs(u.Button,{variant:"soft",size:"sm","aria-label":"settings",...e&&{color:ne.danger},children:[i.jsx(u.RiIcon,{icon:"RiSettings2Line"}),i.jsx("span",{children:"Settings"})]},"settings")}),i.jsx(u.Popover.Content,{size:"sm",children:i.jsx("div",{className:"flex max-w-[240px] flex-col",children:n})})]})});yn.displayName="FieldSettingsPopover";const wn=d.memo(t=>{var vt,xn,Qr,Yr,Jr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:o}=t,{values:a,setFieldValue:l,errors:s}=V.useFormikContext(),p=Wr(),c=d.useRef(null),f=576,[h,g]=d.useState(c.current&&c.current.getBoundingClientRect().width>=f);d.useEffect(()=>{const D=c.current;if(D){const O=new ResizeObserver(H=>{H[0]&&g(H[0].contentRect.width>=f)});return O.observe(D),()=>{O.disconnect()}}},[]);const[y,x]=d.useState(void 0),[m,w]=d.useState(!1);d.useEffect(()=>{he(r)?x(void 0):r.image instanceof Promise?r.image.then(x).catch(console.error):x(r.image)},[r]);const E=y?URL.createObjectURL(y):void 0,b=d.useCallback(D=>{D.stopPropagation();const{image:O,...H}=r;l(`${n}.${e}`,H).then()},[e,r,n,l]);d.useEffect(()=>{he(r)&&!r.conditional&&l(`${n}.${e}.condition`,null).then()},[e,r,n,l]);const S=d.useMemo(()=>{var D,O;return he(r)?(O=Er(a.fields,(D=r.condition)==null?void 0:D.identifier))==null?void 0:O.label:void 0},[r,a.fields]),I=he(r)?Array.isArray((vt=r.condition)==null?void 0:vt.value)?"contains all of":"equals":void 0;let F;if(he(r)){if(ht((xn=r.condition)==null?void 0:xn.value))throw new Error("File values are not supported for conditions.");F=Array.isArray((Qr=r.condition)==null?void 0:Qr.value)?r.condition.value.map(D=>typeof D=="string"?D:D.label).join(", "):(Jr=(Yr=r.condition)==null?void 0:Yr.value)==null?void 0:Jr.toString()}const L=d.useCallback(D=>{D.target.parentNode instanceof HTMLElement&&(D.target.parentNode.dataset.replicatedValue=D.target.value)},[]),T=d.useCallback(D=>{D.target.parentNode instanceof HTMLElement&&(D.target.parentNode.dataset.replicatedValue=D.target.value)},[]),M=r.type,A=gn[M],[$,P]=d.useMemo(()=>{let D=[],O=[];if(A===q){if(o===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const H=A.getFieldCreationSchema(o,`${n}.${e}`);D=D.concat(H.filter(k=>k.showDirectly).map(k=>k.field)),O=O.concat(H.filter(k=>!k.showDirectly).map(k=>k.field))}else{if(!(A.prototype instanceof W))throw new Error(`Field must be an instance of BaseField. Got ${A.toString()}.`);const H=A.getFieldCreationSchema(`${n}.${e}`);h?(D=[...D,...H.filter(k=>k.showDirectly).map(k=>k.field)],O=[...O,...H.filter(k=>!k.showDirectly).map(k=>k.field)]):O=[...O,...H.map(k=>k.field)]}return[D,O]},[A,o,n,e,h]),B=ze($,{formId:gt,disabled:!1,internal:!0,...A===q&&{size:"sm"}}),_=ze(P,{formId:gt,disabled:!1});let ee=P.length>0;he(r)&&P.length>0&&(ee=r.conditional);const le=P.some(D=>{const O=K(s,A===q?`${n}.${e}.condition`:D.getId());return O&&(typeof O!="object"||ue(O))}),je=le?ne.danger:void 0,bn=d.useMemo(()=>ft(r),[r]),Cn=Zt(bn,{formId:gt,showInputOnly:!1}),J=d.useMemo(()=>p.flat().find(D=>D.value===M),[p,M]);return i.jsx("div",{className:"flex grow items-center w-full",ref:c,children:i.jsxs("div",{className:"flex w-full flex-col gap-4",children:[A===q&&i.jsxs("div",{className:"flex flex-col gap-2",children:[$.length>0&&B,i.jsxs("div",{className:"flex items-center gap-4",children:[ee&&i.jsx(yn,{popoverInputs:_,hasError:le}),he(r)&&r.conditional&&i.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":je,children:i.jsxs("em",{children:["Display only if ",i.jsx("strong",{children:S})," ",I," ",i.jsx("strong",{children:F})]})})]})]}),A!==q&&i.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs(u.Badge,{accentColor:"base",variant:"soft",children:[J==null?void 0:J.icon,J==null?void 0:J.children]}),i.jsx(fe,{name:`${n}.${e}.required`,render:({setValue:D,value:O})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u.Checkbox.Root,{checked:O,onCheckedChange:D,children:i.jsx(u.Checkbox.Indicator,{children:i.jsx(u.RiIcon,{icon:"RiCheckLine"})})}),i.jsx(u.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),ee&&i.jsx(yn,{popoverInputs:_,hasError:le})]}),y&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:E,alt:y.name,onClick:()=>{w(!0)}}),i.jsx(u.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:ne.danger,"aria-label":"delete",onClick:b,children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})]}),m&&i.jsx(Xt,{file:y,url:E,name:y.name,setShowPreview:w})]}),i.jsx(fe,{name:`${n}.${e}.label`,render:({setValue:D,value:O})=>i.jsx("input",{className:"bg-transparent outline-none text-base",placeholder:M==="section"?"Enter a section label (optional)":"Enter your question",value:O,onChange:H=>{D(H.target.value)},onInput:L,maxLength:200})}),i.jsx(fe,{name:`${n}.${e}.description`,render:({setValue:D,value:O})=>i.jsx("textarea",{className:"bg-transparent outline-none text-base field-sizing-content grow",placeholder:`Enter a ${M==="section"?"section":"field"} description (optional)`,value:O,onChange:H=>{D(H.target.value)},onInput:T,maxLength:1e3})}),A!==q&&$.length>0&&i.jsx("div",{className:"w-full",children:B}),A!==q&&i.jsxs(i.Fragment,{children:[i.jsx(u.Separator,{size:"full"}),i.jsxs(u.Card,{className:"flex flex-col gap-2 bg-(--accent-a2)",children:[i.jsx(u.Text,{accentColor:"base",children:"Field preview"}),i.jsx("div",{children:Cn})]})]})]})})});wn.displayName="FieldBuilder";const qr=d.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:o}=t,{setFieldValue:a,values:l}=V.useFormikContext(),{reorderField:s}=tn(),{showError:p}=u.useToast(),c=`fields.${r}.fields`,f=d.useMemo(()=>({index:e,parentPath:c,initial:n}),[n,e,c]),h=d.useCallback(()=>{const x=n.label??"Unlabelled field",m={...n,label:x};at(c,e+1,m,l,a)},[n,c,e,l,a]),g=d.useCallback(x=>{const m=r,w=l.fields[m];let E=r,b=x==="up"?e-1:e+1;x==="up"&&e===0?(E=r-1,b=l.fields[E].fields.length):x==="down"&&e===w.fields.length-1&&(E=r+1,b=0);const S=l.fields[E];s(w,m,e,S,E,b,a)},[r,l.fields,e,s,a]),y=d.useCallback(x=>{const{files:m}=x.target;if(!m||m.length!==1)return;const w=m.item(0);if(w){if(w.size>Qo){p({title:"File upload error",description:`The file ${w.name} exceeded the maximum file size`});return}a(`${c}.${e}`,{...n,image:w}).then()}},[n,e,c,a,p]);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:x=>i.jsx(u.Card,{ref:x.innerRef,...x.draggableProps,...x.dragHandleProps,className:"mb-4",children:i.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[i.jsx(wn,{...f}),i.jsx(vn,{index:e,type:n.type,sectionIndex:r,remove:o,duplicate:h,move:g,upload:y})]})})})});qr.displayName="FieldWithActions";const Hr=d.memo(t=>{var S;const{field:n,index:e,dropState:r,fieldsOnly:o}=t,a=(S=r[n.identifier])==null?void 0:S.disabled,{setFieldValue:l,values:s}=V.useFormikContext(),p=u.useAlertDialog(),{reorderSection:c}=tn(),f=d.useCallback((I,F)=>{for(const L of I){const T=F.indexOf(L);l(`fields.${T}.condition`,null).then(),l(`fields.${T}.conditional`,!1).then()}},[l]),h=d.useCallback(I=>{var T;const F=n.fields[I];if(!F)throw new Error("Could not find field to remove.");const L=[];for(const M of s.fields)((T=M.condition)==null?void 0:T.identifier)===F.identifier&&L.push(M);return{removing:F,affectedSections:L,action:()=>l(`fields.${e}.fields`,ot(n.fields,I))}},[n.fields,s.fields,l,e]),g=d.useCallback(I=>{const{affectedSections:F,action:L,removing:T}=h(I),M=()=>{L().then(),f(F,s.fields)};if(F.length>0){const A=F.map($=>$.label).join(", ");p({title:"Remove condition?",description:`${T.label} is being used as a condition, deleting it will remove the condition from the ${A} section(s).`,action:"Remove",onAction:M});return}M()},[h,f,s.fields,p]),y=d.useCallback(()=>{const F=n.fields.map((B,_)=>h(_)).flatMap(B=>B.affectedSections),L=F.length?"Remove fields and conditions?":"Remove fields?",T=n.fields.length,M=F.map(B=>B.label).join(", "),A=F.length?`Deleting this section will remove the ${T} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${T} field(s) it contains.`,$=ot(s.fields,e),P=()=>l("fields",$);if(F.length>0){p({title:L,description:A,action:"Remove",onAction:()=>{P().then(()=>{f(F,$)})}});return}P().then()},[n.fields,s.fields,e,h,l,p,f]),x=d.useCallback(I=>{const F=I==="up"?e-1:e+1;c(r,n.identifier,e,F,s,l)},[e,c,r,n.identifier,s,l]),m=d.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:Sr(s.fields,e)}),[n,e,s.fields]),w=d.useCallback(()=>{const I=n.label??"Untitled section",F=n.fields.map(T=>({...T,identifier:en(null,T.label)})),L={...n,label:I,fields:F};at("fields",e+1,L,s,l)},[n,e,s,l]),E=d.useCallback(I=>{at(`fields.${e}.fields`,n.fields.length,Xo[I],s,l)},[e,n.fields.length,s,l]),b=Wr(E);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:I=>i.jsx(u.Card,{ref:I.innerRef,...I.draggableProps,...I.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:i.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[i.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!o&&i.jsx(wn,{...m}),i.jsx(re.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:a,children:F=>i.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:F.innerRef,...F.droppableProps,children:[n.fields.map((L,T)=>i.jsx(qr,{field:L,index:T,sectionIndex:e,remove:()=>{g(T)}},L.identifier)),F.placeholder,i.jsxs(u.Menu.Root,{children:[i.jsx(u.Menu.ClickTrigger,{children:i.jsxs(u.Button,{type:"button",variant:"solid",children:[i.jsx(u.RiIcon,{icon:"RiAddLine"})," Add field"]})}),i.jsx(u.Menu.Content,{children:b.flat().map(L=>i.jsxs(u.Menu.Item,{onSelect:L.onSelect,children:[L.icon,L.children]},L.value))})]})]})})]}),!o&&i.jsx(vn,{index:e,type:n.type,remove:y,duplicate:w,move:x})]})})})});Hr.displayName="FieldSectionWithActions";const Gr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Kr=d.memo(t=>{const{fieldsOnly:n}=t,{values:e,setFieldValue:r}=V.useFormikContext(),[o,a]=d.useReducer(na,e.fields,Ur),{reorderSection:l,reorderField:s}=tn();d.useEffect(()=>{a({type:"update",state:Ur(e.fields)})},[a,e.fields]);const p=d.useCallback(h=>{h.type==="SECTION"&&a({type:"hold",fieldId:h.draggableId})},[]),c=d.useCallback(h=>{const{source:g,destination:y,type:x,reason:m,draggableId:w}=h;if(a({type:"release"}),!y||m==="CANCEL")return;if(x==="ROOT"){l(o,w,g.index,y.index,e,r);return}if(x!=="SECTION")throw new Error("Unexpected droppable type.");const[E,b]=Gr(e.fields,g.droppableId)??[],[S,I]=Gr(e.fields,y.droppableId)??[];s(E,b,g.index,S,I,y.index,r)},[e,s,r,l,o]),f=d.useCallback(h=>{qo(h+1,e,r)},[e,r]);return i.jsx(re.DragDropContext,{onDragStart:p,onDragEnd:c,children:i.jsx(re.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>i.jsxs("div",{className:"flex flex-col gap-0",ref:h.innerRef,...h.droppableProps,children:[e.fields.map((g,y)=>i.jsxs(d.Fragment,{children:[i.jsx(Hr,{field:g,index:y,dropState:o,fieldsOnly:n}),!n&&y!==e.fields.length-1&&i.jsxs(u.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",onClick:()=>{f(y)},children:[i.jsx(u.RiIcon,{icon:"RiAddLine"})," Add section"]})]},g.identifier)),i.jsxs(u.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",onClick:()=>{f(e.fields.length)},children:[i.jsx(u.RiIcon,{icon:"RiAddLine"})," Add section"]}),h.placeholder]})})})});Kr.displayName="FieldsEditor";const ia=()=>{alert("This is a form preview, your data will not be saved.")},oa=d.memo(d.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:o,initialTitle:a,showExplainerText:l=!0,showFormTitle:s=!0,fieldsOnly:p=!1,showTabs:c=!0,tabsListClassName:f,hydrateRevisionWithImages:h}=t,{showError:g}=u.useToast(),y=d.useCallback(b=>{const S={};b.title||(S.title="Title is required."),(!b.fields||b.fields.length===0)&&(S.fields="At least one field is required.");let I=[];for(const[L,T]of b.fields.entries()){const A=gn.section.getFieldCreationSchema(Sr(b.fields,L),`fields.${L}`).map($=>$.field);I=[...I,...A];for(const[$,P]of T.fields.entries()){const _=gn[P.type].getFieldCreationSchema(`fields.${L}.fields.${$}`).map(ee=>ee.field);I=[...I,..._]}}const F=pt({fields:I},b);if(F&&(S.fields=F.fields),ue(S))return g({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),S},[g]),x=d.useMemo(()=>({title:a??"",description:"",fields:[{...it(en(null,"")),label:""}]}),[a]),m=o?h(o):void 0,w=V.useFormik({initialValues:Wo(m)??x,validate:y,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),E=d.useMemo(()=>kr(w.values),[w.values]);return i.jsx(u.Tabs.Root,{ref:n,defaultValue:"edit",children:i.jsxs("div",{className:"flex flex-col gap-2",children:[c&&i.jsxs(u.Tabs.List,{className:we("sticky top-0 z-[2000] flex bg-(--color-background)",f),children:[i.jsx(u.Tabs.Trigger,{className:"grow",value:"edit",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),i.jsx(u.Tabs.Trigger,{className:"grow",value:"preview",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(u.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),i.jsxs(u.Tabs.Content,{value:"edit",children:[l&&i.jsxs("span",{children:["Create your form using various field types. Sections can be"," ",i.jsx("strong",{children:"conditionally rendered"})," based on"," ",i.jsx("strong",{children:"answers to fields in preceding sections. "})]}),i.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:gt,onSubmit:w.handleSubmit,children:[i.jsxs(V.FormikProvider,{value:w,children:[s&&i.jsxs(i.Fragment,{children:[i.jsx(fe,{name:"title",render:({setValue:b,value:S,meta:I})=>i.jsx(Qt,{severity:"danger",helpText:I.error??null,children:i.jsx(u.Input.Root,{variant:"outline",size:"lg",accentColor:I.error?ne.danger:"primary",children:i.jsx(u.Input.Field,{placeholder:"Form title",value:S,onChange:F=>{b(F.target.value)},maxLength:100})})})}),i.jsx(fe,{name:"description",render:({setValue:b,value:S})=>i.jsx(u.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:S,onChange:I=>{b(I.target.value)},resize:"vertical",maxLength:1e3})})]}),i.jsx(Kr,{fieldsOnly:p}),i.jsx("span",{"data-accent-color":ne.danger,className:"text-xs text-(--accent-a11)",children:typeof w.errors.fields=="string"&&w.errors.fields})]}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&i.jsx(u.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),i.jsx(u.Button,{type:"submit",children:"Save form"})]})]})]}),i.jsx(u.Tabs.Content,{value:"preview",children:i.jsx(jr,{schema:E,onSubmit:ia,hideTitle:!s})})]})})})),aa=Object.values(j.Colors),la=1;async function sa(t,n,e,r){const o=t.getContext("2d",{}),a=new Image(r.width,r.height),l=new Image(r.width,r.height),s=new j.DeferredPromise;return a.onload=function(){o.drawImage(a,0,0,r.width,r.height),l.src=URL.createObjectURL(e),l.onload=async function(){o.drawImage(l,0,0,r.width,r.height);const p=t.toDataURL("image/jpeg",la),c=await j.fileToBlob(p),f=new File([c],n.name,{type:"image/jpeg"});s.resolve(f)}},a.src=URL.createObjectURL(n),s}const Xr=d.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:o,dirty:a,onDirty:l}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const s=d.useRef(null),p=d.useRef(null),[c,f]=d.useState(j.Colors.red),[h,g]=d.useState(null),[y,x]=d.useState(!1),[m,w]=d.useState(!1),E=d.useRef(null),b=u.useSize(E);d.useEffect(()=>{const _=new Image;_.onload=function(){g({width:_.naturalWidth,height:_.naturalHeight})},_.src=URL.createObjectURL(n)},[n]),d.useEffect(()=>{!m&&(b!=null&&b.width)&&b.height&&w(!0)},[b,m]);const S=d.useCallback(async()=>{a||e();const _=s.current;if(!_)return;if(!h)throw new Error("Original image size not loaded yet");const ee=await _.exportImage("png"),le=new Image(h.width,h.height);le.onload=async function(){const je=await j.fileToBlob(ee),bn=new File([je],n.name,{type:n.type}),Cn=p.current,J=await sa(Cn,n,bn,h);J.objectURL=URL.createObjectURL(J);const vt=await j.hashFile(n);await j.hashFile(J)!==vt&&r(J),x(!1),e()},x(!0),le.src=ee},[a,n,e,r,h]),I=d.useCallback(()=>{o(n)},[n,o]),F=d.useCallback(()=>{e()},[e]),L=d.useCallback(()=>{l(!0)},[l]),T=d.useCallback(()=>{s.current&&s.current.redo()},[]),M=d.useCallback(()=>{s.current&&s.current.undo()},[]),A=d.useCallback(()=>{s.current&&(l(!1),s.current.clearCanvas())},[l]),$=d.useCallback(_=>{s.current&&s.current.eraseMode(_)},[]),P=d.useCallback(()=>{S()},[S]),B=d.useCallback(()=>{j.downloadFile(n)},[n]);return i.jsx(Pe,{open:!0,onOpenChange:e,children:i.jsxs(Me,{children:[i.jsx(Ae,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)","data-floating-content":""}),i.jsx(Oe,{className:"fixed inset-0","data-floating-content":"",children:i.jsxs(i.Fragment,{children:[h&&i.jsx("canvas",{style:{display:"none"},id:"attachment-markup-canvas",ref:p,width:h.width,height:h.height}),i.jsxs("div",{className:"relative flex h-full w-full flex-col",children:[i.jsx("div",{className:"flex h-8 w-full items-center bg-(--color-background) px-2",children:i.jsx(u.ButtonGroup,{accentColor:"base",size:"md",variant:"soft",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx(u.IconButton,{"aria-label":"close",onClick:F,children:i.jsx(u.RiIcon,{icon:"RiCloseLine"})}),i.jsx(u.IconButton,{"aria-label":`Download ${n.name}`,onClick:B,children:i.jsx(u.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(Ct,{selectedColor:c,allColors:aa,onFinish:f,trigger:i.jsx(u.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:c},children:" "})}),i.jsx(u.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:$,children:i.jsx(u.RiIcon,{icon:"RiEraserFill"})}),i.jsx(u.Separator,{orientation:"vertical",size:"full"}),i.jsx(u.IconButton,{"aria-label":"undo",onClick:M,children:i.jsx(u.RiIcon,{icon:"RiArrowGoBackLine"})}),i.jsx(u.IconButton,{"aria-label":"undo",onClick:T,children:i.jsx(u.RiIcon,{icon:"RiArrowGoForwardLine"})}),i.jsx(u.IconButton,{"aria-label":"undo all",onClick:A,children:i.jsx(u.RiIcon,{icon:"RiLoopLeftLine"})})]}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(u.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:P,children:i.jsx(u.RiIcon,{icon:"RiSaveLine"})}),i.jsx(u.IconButton,{"aria-label":"Delete attachment",onClick:I,children:i.jsx(u.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})})}),i.jsxs("div",{className:"relative flex w-full grow items-center justify-center p-4",children:[i.jsx("img",{className:"translate-xmax-h-[calc(100%-130px)] pointer-events-none invisible absolute top-[50%] left-[50%] max-w-svw translate-x-[-50%] translate-y-[-50%] object-contain",alt:"Photo attachment",ref:E,src:n.objectURL}),y?i.jsx(u.Spinner,{}):i.jsx(ei.ReactSketchCanvas,{backgroundImage:n.objectURL,ref:s,width:`${(b==null?void 0:b.width)||0}px`,height:`${(b==null?void 0:b.height)||0}px`,onStroke:L,strokeColor:c},m?"1":"0")]})]})]})})]})})});Xr.displayName="AttachmentEditor",C.BaseField=W,C.BaseFormElement=Kt,C.BooleanField=be,C.BooleanInput=Yt,C.ColorPicker=Ct,C.DateField=nt,C.DateInput=Jt,C.FieldSection=q,C.FileBadge=_e,C.FileCard=Ht,C.FileIcon=Be,C.FileViewerContext=Gt,C.FileViewerProvider=vr,C.FormBuilder=oa,C.FormRenderer=jr,C.ImageCard=_r,C.ImageMarkup=Xr,C.ImageViewer=Vt,C.InputWithHelpText=Qt,C.InputWithLabel=Q,C.InputWithLabelAndHelpText=Y,C.MultiSelectField=ke,C.MultiSelectInput=ln,C.MultiStringField=$e,C.MultiStringInput=nn,C.NumberField=ae,C.NumberInput=rn,C.PDFViewer=Ut,C.PatchField=fe,C.PatchFormProvider=ea,C.QrField=lt,C.QrInput=on,C.QrScanner=an,C.SUPPORTED_IMAGE_FILE_TYPES=xt,C.SUPPORTED_PDF_FILE_TYPES=jt,C.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=Wt,C.SelectField=Ve,C.SelectInput=sn,C.SpreadsheetViewer=qt,C.StringField=ct,C.StringInput=cn,C.TextField=dt,C.TextInput=dn,C.decodeFormValues=Yo,C.deserialize=ft,C.deserializeField=hn,C.emptyBaseField=G,C.emptyBooleanField=br,C.emptyDateField=Cr,C.emptyMultiSelectField=Pr,C.emptyMultiStringField=Nr,C.emptyNumberField=Fr,C.emptyQrField=Lr,C.emptySelectField=Mr,C.emptyStringField=Or,C.emptyTextField=Br,C.encodeFormValues=Jo,C.flattenFields=pn,C.formRevisionToSchema=kr,C.initialFormValues=mt,C.isConditionMet=mn,C.useFieldInput=Zt,C.useFieldInputs=ze,C.useFileViewer=gr,C.useFormikInput=z,C.validateForm=pt,C.valueIsFile=ht,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@overmap-ai/forms",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.17-master.
|
|
4
|
+
"version": "1.0.17-master.7",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/forms.umd.cjs",
|
|
7
7
|
"module": "dist/forms.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"build-storybook": "storybook build"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@overmap-ai/blocks": "1.0.31-tailwind-components.
|
|
24
|
+
"@overmap-ai/blocks": "1.0.31-tailwind-components.44",
|
|
25
25
|
"@overmap-ai/core": "1.0.60-forms-removal.3",
|
|
26
26
|
"react": ">=18.2.0 <20.0.0",
|
|
27
27
|
"react-dom": ">=18.2.0 <20.0.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@chromatic-com/storybook": "^3.2.4",
|
|
32
32
|
"@eslint/js": "^9.19.0",
|
|
33
|
-
"@overmap-ai/blocks": "1.0.31-tailwind-components.
|
|
33
|
+
"@overmap-ai/blocks": "1.0.31-tailwind-components.44",
|
|
34
34
|
"@overmap-ai/core": "1.0.60-forms-removal.9",
|
|
35
35
|
"@radix-ui/colors": "^3.0.0",
|
|
36
36
|
"@storybook/addon-a11y": "^8.5.3",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"lodash.get": "^4.4.2",
|
|
89
89
|
"lodash.set": "^4.3.2",
|
|
90
90
|
"qr-scanner": "^1.4.2",
|
|
91
|
-
"react-icons": "^5.
|
|
91
|
+
"react-icons": "^5.5.0",
|
|
92
92
|
"react-pdf": "^9.2.1",
|
|
93
93
|
"react-sketch-canvas": "^6.2.0",
|
|
94
94
|
"react-spreadsheet": "^0.9.5",
|