@overmap-ai/forms 1.0.17-blank-value-updates.4 → 1.0.17-blank-value-updates.6
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 +3 -3
- package/dist/forms.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/forms.js
CHANGED
|
@@ -1767,7 +1767,7 @@ let Ge = Ae;
|
|
|
1767
1767
|
const ji = O((t) => {
|
|
1768
1768
|
const [{ inputId: n, labelId: e, size: i, severity: r, showInputOnly: o, field: s, helpText: l, label: m, fieldProps: c }, d] = Z(t), { name: u, onChange: h, onBlur: y } = c, [b, f] = U(!1), v = o ? null : l, w = o ? "" : m, x = c.value ? new Date(c.value) : void 0, g = S(
|
|
1769
1769
|
(E) => {
|
|
1770
|
-
E
|
|
1770
|
+
h(E == null ? void 0 : E.toISOString()), f(!1);
|
|
1771
1771
|
},
|
|
1772
1772
|
[h]
|
|
1773
1773
|
), I = S(
|
|
@@ -2575,7 +2575,7 @@ let vt = Me;
|
|
|
2575
2575
|
const tr = O((t) => {
|
|
2576
2576
|
const [{ inputId: n, labelId: e, size: i, severity: r, showInputOnly: o, field: s, helpText: l, label: m, fieldProps: c }, d] = Z(t), { name: u, onChange: h, onBlur: y, value: b } = c, f = o ? null : l, v = o ? "" : m, w = S(
|
|
2577
2577
|
(g) => {
|
|
2578
|
-
g
|
|
2578
|
+
h(g ?? void 0), y(g ?? void 0);
|
|
2579
2579
|
},
|
|
2580
2580
|
[y, h]
|
|
2581
2581
|
), x = k(() => s.options.find((g) => g.value === b), [s.options, b]);
|
|
@@ -2606,7 +2606,7 @@ const tr = O((t) => {
|
|
|
2606
2606
|
]
|
|
2607
2607
|
}
|
|
2608
2608
|
) }),
|
|
2609
|
-
/* @__PURE__ */ a(B.Content, { children: /* @__PURE__ */ a(B.Scroll, { children: /* @__PURE__ */ a(B.SelectGroup, { required: !
|
|
2609
|
+
/* @__PURE__ */ a(B.Content, { children: /* @__PURE__ */ a(B.Scroll, { children: /* @__PURE__ */ a(B.SelectGroup, { required: !1, value: b ?? null, onValueChange: w, children: s.options.map((g) => /* @__PURE__ */ C(B.SelectItem, { value: g.value, children: [
|
|
2610
2610
|
/* @__PURE__ */ a(B.SelectedIndicator, { children: /* @__PURE__ */ a(F, { icon: "RiCheckLine" }) }),
|
|
2611
2611
|
g.label
|
|
2612
2612
|
] }, g.value)) }) }) })
|
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},Oo="DialogDescriptionWarning",Bo=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hr(Oo).contentName}}.`;return v.useEffect(()=>{var a;const i=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&i&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},$t=tr,zo=rr,kt=or,jt=ar,Wt=sr,pr=ur,tt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},nt={exports:{}},_o=nt.exports,mr;function Vo(){return mr||(mr=1,function(t,n){(function(e,r){r()})(_o,function(){function e(u,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(u.type)?new Blob(["\uFEFF",u],{type:u.type}):u}function r(u,f,h){var g=new XMLHttpRequest;g.open("GET",u),g.responseType="blob",g.onload=function(){m(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function i(u){var f=new XMLHttpRequest;f.open("HEAD",u,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(u){try{u.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),u.dispatchEvent(f)}}var s=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof tt=="object"&&tt.global===tt?tt:void 0,l=s.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),m=s.saveAs||(typeof window!="object"||window!==s?function(){}:"download"in HTMLAnchorElement.prototype&&!l?function(u,f,h){var g=s.URL||s.webkitURL,C=document.createElement("a");f=f||u.name||"download",C.download=f,C.rel="noopener",typeof u=="string"?(C.href=u,C.origin===location.origin?a(C):i(C.href)?r(u,f,h):a(C,C.target="_blank")):(C.href=g.createObjectURL(u),setTimeout(function(){g.revokeObjectURL(C.href)},4e4),setTimeout(function(){a(C)},0))}:"msSaveOrOpenBlob"in navigator?function(u,f,h){if(f=f||u.name||"download",typeof u!="string")navigator.msSaveOrOpenBlob(e(u,h),f);else if(i(u))r(u,f,h);else{var g=document.createElement("a");g.href=u,g.target="_blank",setTimeout(function(){a(g)})}}:function(u,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof u=="string")return r(u,f,h);var C=u.type==="application/octet-stream",w=/constructor/i.test(s.HTMLElement)||s.safari,p=/CriOS\/[\d]+/.test(navigator.userAgent);if((p||C&&w||l)&&typeof FileReader<"u"){var b=new FileReader;b.onloadend=function(){var y=b.result;y=p?y:y.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=y:location=y,g=null},b.readAsDataURL(u)}else{var I=s.URL||s.webkitURL,x=I.createObjectURL(u);g?g.location=x:location.href=x,g=null,setTimeout(function(){I.revokeObjectURL(x)},4e4)}});s.saveAs=m.saveAs=m,t.exports=m})}(nt)),nt.exports}var qt=Vo();const Ht=c.memo(t=>{const{file:n,onClose:e}=t,r=c.useRef(null),i=c.useCallback(()=>{var l;if(!r.current)return;const s=document.createElement("canvas");s.width=r.current.width,s.height=r.current.height,(l=s.getContext("2d"))==null||l.drawImage(r.current,0,0,r.current.width,r.current.height),s.toBlob(m=>{m&&navigator.clipboard.write([new ClipboardItem({"image/png":m})])},"image/png")},[]),a=c.useCallback(()=>{qt.saveAs(n,n.name)},[n]);return o.jsx($t,{open:!0,onOpenChange:e,children:o.jsx(kt,{children:o.jsx(jt,{className:"bg-(--color-background) fixed inset-0 data-[state='open']:fade-in-0 data-[state='open']:zoom-in-95 data-[state='closed']:animate-out data-[state='closed']:fade-out-0 data-[state='closed']:zoom-out-95 data-[state='open']:animate-in","data-floating-content":"",children:o.jsxs(Wt,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:s=>s.preventDefault(),children:[o.jsxs(d.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[o.jsxs(d.Tooltip.Root,{children:[o.jsx(d.Tooltip.Trigger,{asChild:!0,children:o.jsx(d.IconButton,{onClick:i,"aria-label":"copy to clipboard",children:o.jsx(d.RiIcon,{icon:"RiFileCopyLine"})})}),o.jsx(d.Tooltip.Content,{size:"sm",children:"Copy"})]}),o.jsxs(d.Tooltip.Root,{children:[o.jsx(d.Tooltip.Trigger,{asChild:!0,children:o.jsx(d.IconButton,{onClick:a,"aria-label":"download",children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})})}),o.jsx(d.Tooltip.Content,{size:"sm",children:"Download"})]}),o.jsx(d.Separator,{orientation:"vertical",size:"sm"}),o.jsx(pr,{asChild:!0,children:o.jsx(d.IconButton,{onClick:e,"aria-label":"close",children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),o.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:o.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});Ht.displayName="ImageViewer";const gr=c.memo(t=>{const{children:n}=t,[e,r]=c.useState(null),i=c.useCallback(()=>{r(null)},[]),a=c.useCallback(m=>{r(m(i))},[i]),s=c.useCallback(()=>{e&&(e.onClose&&e.onClose(),i())},[i,e]),l=c.useMemo(()=>a,[a]);return o.jsxs(En.Provider,{value:l,children:[n,e&&o.jsx(Ht,{file:e.file,onClose:s})]})});gr.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:i,inputId:a,labelId:s,image:l}=t,[m,u]=c.useState(void 0),f=We(),h=i?ue[i]:"base";c.useEffect(()=>{l instanceof Promise?l.then(u).catch(console.error):u(l)},[l]);const g=m?URL.createObjectURL(m):void 0,C=c.useCallback(()=>{m&&f(()=>({file:m}))},[f,m]);return o.jsxs("div",{className:"flex flex-col gap-1",children:[m&&o.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:g,alt:m.name,onClick:C}),o.jsx("label",{className:ye(n,"flex flex-col gap-1 w-max max-w-full"),htmlFor:a,children:o.jsx(d.Text,{accentColor:h,size:"sm",id:s,weight:"medium",className:"text-wrap",children:e})}),r]})},Gt=t=>{const{helpText:n,children:e,severity:r}=t,i=r?ue[r]:"base";return o.jsxs("div",{className:"flex flex-col gap-1",children:[e,!!n&&o.jsx("div",{className:"flex flex-col w-full",children:o.jsx(d.Text,{accentColor:i,size:"xs",children:n})})]})},J=t=>{const{children:n,...e}=t;return o.jsx(Gt,{...e,children:n})},Xt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onBlur:g,onChange:C,value:w}=u,p=a?null:l,b=a?"":m,I=c.useCallback(y=>{C(!!y),g(!!y)},[g,C]),x=c.useCallback(()=>{g(w)},[g,w]);return o.jsx(J,{helpText:p,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:a?void 0:s.image,className:"items-center flex-row-reverse justify-end gap-2",children:o.jsx(d.Checkbox.Root,{id:n,name:h,checked:w??!1,onCheckedChange:I,onBlur:x,size:"sm",accentColor:"primary",variant:"surface",...f,children:o.jsx(d.Checkbox.Indicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})})})})})});Xt.displayName="BooleanInput";const vr={...X,type:"boolean"},Se=class Se extends j{constructor(e){super({...e,type:"boolean"});N(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Se(e)}getInput(e){return o.jsx(Xt,{...e,field:this})}};N(Se,"fieldTypeName","Checkbox"),N(Se,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),N(Se,"Icon",H.RiCheckboxCircleLine);let Ee=Se;const Kt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C}=u,[w,p]=c.useState(!1),b=a?null:l,I=a?"":m,x=u.value?new Date(u.value):void 0,y=c.useCallback(S=>{S&&g(S.toISOString()),p(!1)},[g]),T=c.useCallback(S=>{p(S),S||C(u.value)},[u.value,C]);return o.jsx(J,{helpText:b,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:o.jsxs(d.Popover.Root,{open:w,onOpenChange:T,children:[o.jsx(d.Popover.Trigger,{asChild:!0,children:o.jsxs(d.Button,{id:n,name:h,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...f,children:[x?x.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",o.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),o.jsx(d.Popover.Content,{align:"start",children:o.jsx(d.DayPicker,{required:!1,mode:"single",variant:"solid",selected:x,onSelect:y})})]})})})});Kt.displayName="DateInput";const yr={...X,type:"date"},Te=class Te extends j{constructor(e){super({...e,type:"date"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new Te(e)}getInput(e){return o.jsx(Kt,{field:this,...e})}};N(Te,"fieldTypeName","Date"),N(Te,"fieldTypeDescription","Allows specifying a date."),N(Te,"Icon",H.RiCalendarLine);let rt=Te;const br=c.memo(t=>{const{field:n,...e}=t,[{value:r}]=k.useField(n.options.clonedFieldIdentifier),i=c.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?pt(a):null},[n.options,r]);return Qt(i,e)});br.displayName="FieldInputCloner";const Uo={...X,type:"custom"};class it extends j{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 o.jsx(r,{field:this,...e})}}N(it,"fieldTypeName","Custom"),N(it,"fieldTypeDescription","Allows re-rendering of field already in the form");class $o extends it{constructor(n){super(n,br)}}const Qt=(t,n)=>c.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),ze=(t,n)=>{const e=c.useMemo(()=>t.map(r=>o.jsx(c.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return o.jsx("div",{className:"flex flex-col gap-4",children:e})},Yt=[];let ot;const ko=new Uint8Array(16);function jo(){if(!ot&&(ot=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ot))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ot(ko)}const V=[];for(let t=0;t<256;++t)V.push((t+256).toString(16).slice(1));function Wo(t,n=0){return V[t[n+0]]+V[t[n+1]]+V[t[n+2]]+V[t[n+3]]+"-"+V[t[n+4]]+V[t[n+5]]+"-"+V[t[n+6]]+V[t[n+7]]+"-"+V[t[n+8]]+V[t[n+9]]+"-"+V[t[n+10]]+V[t[n+11]]+V[t[n+12]]+V[t[n+13]]+V[t[n+14]]+V[t[n+15]]}const Cr={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qo(t,n,e){if(Cr.randomUUID&&!t)return Cr.randomUUID();t=t||{};const r=t.random||(t.rng||jo)();return r[6]=r[6]&15|64,r[8]=r[8]&63|128,Wo(r)}const me=t=>t.type==="section",at=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Ho=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const i of n)i.type==="section"?(e.length>0&&(r.push(at(`AUTO_section-${n.indexOf(i)}`,e)),e=[]),r.push(i)):e.push(i);return e.length>0&&r.push(at("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Jt(t,n,e){const r=Array.from(t),[i]=r.splice(n,1);if(!i)throw new Error("Could not find field to reorder.");return r.splice(e,0,i),r}function wr(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function st(t,n){const e=Array.from(t);return e.splice(n,1),e}const Zt=()=>qo(),Ir=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=Ir(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},xr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),lt=(t,n,e,r,i)=>{const a={...e,identifier:Zt()},s=R(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 l=wr(s,n,a);i(t,l).then()},Go=(t,n,e)=>{const r={...at(),label:""};lt("fields",t,r,n,e)},Rt=()=>{const{showError:t}=d.useToast(),n=c.useCallback((r,i,a,s,l,m)=>{const u=r[i];if(!u)throw new Error("Could not find section context.");let f=typeof u.conditionIndex<"u"?Math.max(u.conditionIndex+1,s):s;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==s){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}m("fields",Jt(l.fields,a,f))},[t]),e=c.useCallback((r,i,a,s,l,m,u)=>{var f;if(!(r!=null&&r.fields)||!s)throw new Error("Could not find section with fields.");if(r.identifier===s.identifier)u(`fields.${i}.fields`,Jt(r.fields,a,m)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=s.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}u(`fields.${i}.fields`,st(r.fields,a)).then(),u(`fields.${l}.fields`,wr(s.fields,m,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},en=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),h=a?null:l,g=a?"":m,{name:C,onChange:w,onBlur:p}=u,b=`${n}-droppable`,{disabled:I}=f,x=u.value??Yt,[y,T]=c.useState(""),[S,L]=c.useState(""),F=S||h,D=c.useCallback(A=>{w(A),p(A)},[w,p]),M=c.useCallback(A=>{x&&x.findIndex(q=>q===A.target.value.trim())>=0?L("All options must be unique"):A.target.value?L(""):L("Option cannot be empty"),T(A.target.value)},[T,x]),O=c.useCallback(()=>{if(S)return;if(!y.trim()){L("Option cannot be empty");return}const A=y.trim();D([...x,A]),T("")},[y,S,D,x]),_=c.useCallback(A=>{A.key==="Enter"&&(A.preventDefault(),O())},[O]),U=c.useCallback(A=>{D(st(x,A))},[x,D]),B=c.useCallback(A=>{if(!A.destination)return;const q=A.source.index,le=A.destination.index;D(Jt(x,q,le))},[D,x]),Z=c.useCallback(()=>{p(x)},[p,x]);return o.jsx(ie.DragDropContext,{onDragEnd:B,children:o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx(J,{helpText:F,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:g,image:a?void 0:s.image,children:(!I||x.length===0)&&o.jsxs("div",{className:"flex gap-2",children:[o.jsx(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{value:y,onChange:M,onKeyDown:_,id:n,placeholder:s.placeholder,onBlur:Z,name:C,...f})}),o.jsx(d.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!S||I,onClick:O,children:o.jsx(d.RiIcon,{icon:"RiAddLine"})})]})})}),o.jsx(ie.Droppable,{droppableId:b,children:A=>o.jsxs("div",{className:"flex flex-col",...A.droppableProps,ref:A.innerRef,children:[x.map((q,le)=>o.jsx(ie.Draggable,{draggableId:`${q}-draggable`,index:le,isDragDisabled:I,children:({draggableProps:ne,dragHandleProps:ce,innerRef:Be})=>o.jsxs(d.Badge,{...ce,...ne,ref:Be,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[o.jsx("span",{children:typeof q=="object"&&"label"in q?q.label:q}),o.jsx(d.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:I,onClick:()=>{U(le)},children:o.jsx(d.RiIcon,{icon:"RiCloseLargeLine"})})]})},q)),A.placeholder]})})]})})});en.displayName="MultiStringInput";const Er={...X,type:"multi-string",minimum_length:0,maximum_length:null},Ne=class Ne extends j{constructor(e){const{minimum_length:r,maximum_length:i,placeholder:a,...s}=e;super({...s,type:"multi-string"});N(this,"minLength");N(this,"maxLength");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.minLength=r??0,this.maxLength=i??1/0,this.placeholder=a??"Press enter to add a new option"}getInput(e){return o.jsx(en,{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==null?void 0:e.length)===0}isEqual(e,r){return e===void 0&&r===void 0?!0:e===void 0||r===void 0?!1:e.every(i=>r.includes(i))&&r.every(i=>e.includes(i))}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 Ne(e)}};N(Ne,"fieldTypeName","Multi-string"),N(Ne,"fieldTypeDescription","Allows the user to provide multiple unique strings."),N(Ne,"Icon",H.RiListCheck);let _e=Ne;const tn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{const D=F.target.valueAsNumber,M=Number.isNaN(D)?void 0:D;T(M),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(M))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{id:n,name:C,onChange:S,onBlur:L,value:y??"",type:"number",min:s.minimum,max:s.maximum,step:s.integers?1:.1,placeholder:s.placeholder,...g})})})})});tn.displayName="NumberInput";const Sr={...X,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Tr=t=>"fields"in t,te=class te extends j{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:i=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:s="Enter a number",...l}=e;super({...l,type:"number"});N(this,"minimum");N(this,"maximum");N(this,"integers");N(this,"placeholder");this.minimum=r,this.maximum=i,this.integers=a,this.placeholder=s}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new te({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new te({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new Ee({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,i=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof i=="number"&&e.push(a=>{if(typeof a=="number"&&a>i)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 te(e)}getInput(e){return o.jsx(tn,{field:this,...e})}};N(te,"fieldTypeName","Number"),N(te,"fieldTypeDescription","Allows specifying a number within a given range."),N(te,"Icon",H.RiHashtag),N(te,"_validateMin",e=>(r,i)=>{const a=Tr(i)?R(i,e):i;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),N(te,"_validateMax",e=>(r,i)=>{const a=Tr(i)?R(i,e):i;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let se=te;const nn=c.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:i,size:a,severity:s,showInputOnly:l,field:m,fieldProps:u},f]=K(t),{name:h,onBlur:g,onChange:C,value:w}=u,[p,b]=c.useState(!1),I=l?null:i,x=l?"":r,y=c.useCallback(L=>{C(L),b(!1)},[C]),T=c.useCallback(()=>{C("")},[C]),S=c.useCallback(L=>{b(L),L||g(w)},[g,w]);return o.jsx(J,{helpText:I,severity:s,children:o.jsxs(Y,{size:a,severity:s,inputId:n,labelId:e,label:x,image:l?void 0:m.image,className:"flex-col items-start justify-start gap-2",children:[o.jsxs("div",{className:"flex w-max items-center gap-1",children:[o.jsxs($t,{open:p,onOpenChange:S,children:[o.jsx(zo,{asChild:!0,children:o.jsxs(d.Button,{id:n,name:h,type:"button",variant:"soft",size:"sm",accentColor:"base",...f,children:[o.jsx(d.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),o.jsxs(kt,{children:[o.jsx(jt,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),o.jsx(Wt,{className:"fixed inset-0",children:o.jsx(rn,{onQrScan:y})})]})]}),w&&o.jsx(d.RiIcon,{icon:"RiCheckLine",className:"align-bottom text-(--primary-a11)"})]}),!!w&&o.jsx(d.Card,{className:"max-w-full w-max",size:"sm",children:o.jsxs("div",{className:"max-w-full w-max flex justify-between gap-2",children:[o.jsx("code",{className:"bg-(--base-a3) truncate text-sm",children:w}),o.jsx(d.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:T,children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})]})})]})})});nn.displayName="QrInput";const rn=c.memo(t=>{const{onQrScan:n}=t,e=c.useRef(null),[r,i]=c.useState(!1);return c.useEffect(()=>{if(!e.current)return;const a=new ei(e.current,s=>{const l=s.data;n(l),a.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});i(!0),a.start().finally(()=>{i(!1)})},[n]),o.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[o.jsx("div",{className:"absolute top-0 flex w-full p-2",children:o.jsx(pr,{asChild:!0,children:o.jsx(d.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})})}),o.jsxs("div",{className:"relative max-h-full max-w-full",children:[o.jsx("video",{className:"size-full",ref:e}),r&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:o.jsx(d.Spinner,{})})]})]})});rn.displayName="QrScanner";const Nr={...X,type:"qr"},Fe=class Fe extends j{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 Fe(e)}getInput(e){return o.jsx(nn,{...e,field:this})}};N(Fe,"fieldTypeName","QR"),N(Fe,"fieldTypeDescription","Used for scanning/reading QR codes."),N(Fe,"Icon",H.RiQrCodeLine);let ct=Fe;class Fr extends j{constructor(e){const{placeholder:r="",...i}=e;super(i);N(this,"options");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(s=>(typeof s=="string"&&(s={label:s,value:s}),a.add(s.label),s)),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 on=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C}=u,w=a?null:l,p=a?"":m,b=u.value??Yt,I=c.useCallback(y=>{const T=y.length>0?y:void 0;g(T),C(T)},[C,g]),x=c.useCallback(y=>{y||C(b)},[b,C]);return o.jsx(J,{helpText:w,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:p,image:a?void 0:s.image,children:o.jsxs(d.Menu.Root,{onOpenChange:x,align:"start",children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{id:n,name:h,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...f,children:[o.jsx("span",{className:"truncate",children:b&&b.length>0?b.join(", "):s.placeholder}),o.jsx(d.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),o.jsx(d.Menu.Content,{children:o.jsx(d.Menu.Scroll,{children:o.jsxs(d.Menu.MultiSelectGroup,{values:b,onValuesChange:I,children:[o.jsxs(d.Menu.SelectAllItem,{children:[o.jsx(d.Menu.CheckboxItemIndicator,{children:y=>y?o.jsx(d.RiIcon,{icon:"RiSubtractLine"}):o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),s.options.map(y=>o.jsxs(d.Menu.MultiSelectItem,{value:y.value,children:[o.jsx(d.Menu.SelectedIndicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))]})})})]})})})});on.displayName="MultiSelectInput";const Lr={...X,type:"multi-select",options:[]},Le=class Le extends Fr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}isBlank(n){return super.isBlank(n)||(n==null?void 0:n.length)===0}isEqual(n,e){return n===void 0&&e===void 0?!0:n===void 0||e===void 0?!1:n.every(r=>e.includes(r))&&e.every(r=>n.includes(r))}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Le(n)}getInput(n){return o.jsx(on,{field:this,...n})}};N(Le,"fieldTypeName","Multi-select"),N(Le,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),N(Le,"Icon",H.RiCheckboxLine);let Ve=Le;const an=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C,value:w}=u,p=a?null:l,b=a?"":m,I=c.useCallback(y=>{y&&(g(y),C(y))},[C,g]),x=c.useMemo(()=>s.options.find(y=>y.value===w),[s.options,w]);return o.jsx(J,{helpText:p,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:a?void 0:s.image,children:o.jsxs(d.Menu.Root,{align:"start",children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{id:n,name:h,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...f,children:[o.jsx("span",{className:"truncate",children:x?x.label:s.placeholder}),o.jsx(d.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),o.jsx(d.Menu.Content,{children:o.jsx(d.Menu.Scroll,{children:o.jsx(d.Menu.SelectGroup,{required:!0,value:w,onValueChange:I,children:s.options.map(y=>o.jsxs(d.Menu.SelectItem,{value:y.value,children:[o.jsx(d.Menu.SelectedIndicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))})})})]})})})});an.displayName="SelectInput";const Dr={...X,type:"select",options:[]},De=class De extends Fr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new De(n)}getInput(n){return o.jsx(an,{field:this,...n})}};N(De,"fieldTypeName","Dropdown"),N(De,"fieldTypeDescription","Allows the user to select a single option from a list of options."),N(De,"Icon",H.RiMenuFoldLine);let Ue=De;const Mr=t=>"fields"in t;class dt extends j{constructor(e){const{minLength:r,maxLength:i,placeholder:a="",...s}=e;super(s);N(this,"minLength");N(this,"maxLength");N(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=i?Math.max(i,0):be,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({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 se({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:be,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(dt,"_validateMin",e=>(r,i)=>{const a=Mr(i)?R(i,e):i;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),N(dt,"_validateMax",e=>(r,i)=>{if(typeof r!="number")return null;const{minimum_length:a}=Mr(i)?R(i,e):i;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const sn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{T(F.target.value||void 0),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{id:n,className:"truncate",name:C,value:y??"",type:s.inputType,placeholder:s.placeholder,onChange:S,onBlur:L,...g})})})})});sn.displayName="StringInput";const Pr={...X,type:"string",maximum_length:je,input_type:"text"},Me=class Me extends dt{constructor(e){const{inputType:r="text",...i}=e,a=e.maxLength?Math.min(je,e.maxLength):je,s=e.minLength?Math.min(e.minLength,a):void 0;super({...i,maxLength:a,minLength:s,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:i,input_type:a,...s}=e;return new Me({...s,maxLength:r,minLength:i,inputType:a,placeholder:"Enter a short description"})}getInput(e){return o.jsx(sn,{field:this,...e})}};N(Me,"fieldTypeName","Short Text"),N(Me,"fieldTypeDescription",`Short text fields can hold up to ${je} characters on a single line.`),N(Me,"Icon",H.RiInputField);let ut=Me;const ln=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{T(F.target.value||void 0),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.TextArea,{id:n,value:y??"",name:C,onChange:S,onBlur:L,className:"field-sizing-content min-h-12",placeholder:s.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...g})})})});ln.displayName="TextInput";const Ar={...X,type:"text",maximum_length:be},Pe=class Pe extends dt{constructor(n){const e=n.maxLength?Math.min(be,n.maxLength):be,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,...i}=n;return new Pe({...i,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return o.jsx(ln,{field:this,...n})}};N(Pe,"fieldTypeName","Paragraph"),N(Pe,"fieldTypeDescription",`Paragraph fields can hold up to ${be} characters and can have multiple lines.`),N(Pe,"Icon",H.RiAlignJustify);let ft=Pe;const Or=c.memo(c.forwardRef((t,n)=>{const{file:e,alt:r,error:i,rightSlot:a,className:s,...l}=t;return o.jsxs("div",{className:ye(s,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...l,children:[!e&&!i&&o.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:o.jsx(d.Spinner,{})}),o.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!i&&o.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),o.jsxs("div",{className:ye("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[i?o.jsx(d.RiIcon,{icon:"RiFileWarningLine"}):e&&o.jsx(ke,{fileType:e.type}),o.jsx(d.Text,{className:"truncate",size:"sm",children:i??(e==null?void 0:e.name)}),a]})]})})),Xo=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)},Br=c.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:i,helpText:a,showInputOnly:s,field:l,fieldProps:m},u]=K(t),{name:f,onChange:h,onBlur:g}=m;let[{label:C}]=K(t);C=s?"":C;const w=m.value??Yt,p=c.useRef(null),b=c.useMemo(()=>s?null:a||(l.maxFileSize?`Maximum file size: ${l.maxFileSize}MB`:null),[l.maxFileSize,a,s]),I=c.useCallback(()=>{var D;(D=p.current)==null||D.click()},[]),x=c.useCallback(()=>{if(!p.current)return;const D=p.current.files;if(!D){g([]);return}const M=Array.from(D),O=[...w,...M];h(O),g(O)},[g,h,w]),y=c.useCallback(D=>{const M=[...w];M.splice(D,1),h(M.length>0?M:void 0)},[w,h]);c.useEffect(()=>{if(!p.current)return;const D=new AbortController;return p.current.addEventListener("cancel",()=>{g(void 0)},{signal:D.signal}),()=>{D.abort()}},[g,w]);const T=w?"Select new files":"Select files",S=w?"Select new file":"Select a file",L=l.maxFiles>1?T:S;return o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx(J,{helpText:b,severity:i,children:o.jsxs(Y,{size:r,severity:i,inputId:n,labelId:e,label:C,image:s?void 0:l.image,children:[o.jsx("div",{className:"flex gap-2",children:o.jsxs(d.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:I,id:"upload-input-upload-button",type:"button",...u,children:[o.jsx(d.RiIcon,{icon:"RiUpload2Line"})," ",L]})}),o.jsx("input",{id:n,name:f,type:"file",ref:p,accept:(F=l.extensions)==null?void 0:F.join(","),multiple:l.maxFiles>1,className:"hidden",onChange:x,value:""})]})}),Array.isArray(w)&&w.length>0&&o.jsx("div",{className:"flex h-max flex-col gap-2",children:w.map((D,M)=>o.jsx(zr,{field:l,file:D,onRemove:()=>{y(M)},disabled:u.disabled},M))})]})});Br.displayName="UploadInput";const zr=c.memo(t=>{const{file:n,field:e,onRemove:r,disabled:i}=t,[a,s]=c.useState(null),l=We(),m=c.useMemo(()=>a&&e.getError([a]),[e,a]),{url:u,name:f}=c.useMemo(()=>{let p=null,b,I;return a!=null&&a.type.startsWith("image/")&&(p=URL.createObjectURL(a)),a?(b=a.name,I=Xo(a.size)):(b="Downloading...",I="..."),{url:p,name:b,size:I}},[a]);c.useEffect(()=>{n instanceof Promise?n.then(s).catch(console.error):s(n)},[n]);const h=c.useCallback(p=>{if(p.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const b=new Blob([a]);qt.saveAs(b,f)},[f,a]),g=c.useCallback(p=>{p.stopPropagation(),r()},[r]),C=c.useCallback(()=>{a&&l(p=>({file:a,onDelete:i?void 0:()=>{r(),p()}}))},[i,r,l,a]),w=c.useMemo(()=>o.jsxs(d.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[o.jsx(d.IconButton,{"aria-label":`Download ${f}`,type:"button",onClick:h,disabled:!a,children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})}),!i&&o.jsx(d.IconButton,{type:"button","aria-label":`Remove ${f}`,disabled:i,onClick:g,children:o.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[i,g,h,f,a]);return u?o.jsx(Or,{className:"cursor-pointer",onClick:C,file:a,error:m??void 0,rightSlot:w}):o.jsx(It,{file:a,error:m??void 0,rightSlot:w})});zr.displayName="DisplayFile";const Ko={...X,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1};function _r(t,n){return t.name===n.name&&t.size===n.size&&t.type===n.type}const Ae=class Ae extends j{constructor(e){const{extensions:r,maximum_files:i,maximum_size:a,...s}=e;super({...s,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 i=="number"?i:1,1),this.extensions=r}isBlank(e){return super.isBlank(e)||(e==null?void 0:e.length)===0}isEqual(e,r){return e===void 0&&r===void 0?!0:!(e===void 0||r===void 0||!e.every(i=>r.some(a=>_r(i,a)))||!r.every(i=>e.some(a=>_r(a,i))))}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({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 se({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${ht}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:ht,integers:!0}),showDirectly:!1},{field:new Ve({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??ht,i=r*1e3*1e3,a=this.maxFiles||1;return e.push(s=>{if(s&&s.some(l=>l.size>i))return`Files must be at most ${r}MB.`}),e.push(s=>{if(s&&s.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 Ae(e)}getInput(e){return o.jsx(Br,{field:this,...e})}};N(Ae,"fieldTypeName","Upload"),N(Ae,"fieldTypeDescription","Allows a file to be uploaded."),N(Ae,"Icon",H.RiUpload2Line);let cn=Ae;const dn={date:rt,number:se,boolean:Ee,select:Ue,string:ut,text:ft,custom:it,upload:cn,qr:ct,"multi-string":_e,"multi-select":Ve},Qo={date:yr,number:Sr,boolean:vr,select:Dr,string:Pr,text:Ar,custom:Uo,upload:Ko,qr:Nr,"multi-string":Er,"multi-select":Lr},ht=50,Yo=ht*1e3*1e3,un=t=>{const n=t.type;return dn[n].deserialize(t)},pt=t=>t.type==="section"?W.deserialize(t):un(t);function Vr(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>pt(r)),meta:{readonly:e}}}function mt(t){const n=[];for(const e of t.fields)if(e instanceof W)for(const r of e.fields)n.push(r);else{if(!(e instanceof j))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Ur(t){const n=mt(t),e={};for(const r of n)e[r.identifier]=r;return e}function Jo(t,n){const e=mt(t),r={};for(const i of e){const a=n[i.identifier]??null;a!==null?r[i.identifier]=i.decodeJsonToValue(a):r[i.identifier]=a}return r}function Zo(t,n){const e=mt(t),r={};for(const i of e){const a=n[i.identifier];r[i.identifier]=i.encodeValueToJson(a)}return r}function gt(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function fn(t,n){if(!t)return!0;if(gt(n)||gt(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(i=>typeof i=="string"?i:i.value):n,r=Array.isArray(t.value)?t.value.map(i=>typeof i=="string"?i:i.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const i of r)if(!e.includes(i))return!1;return!0}return r===n}const $r=c.memo(t=>{const{field:n,...e}=t,{label:r,description:i,fields:a,condition:s}=n,{values:l,setFieldValue:m}=k.useFormikContext(),u=s!=null&&s.identifier?R(l,s.identifier):void 0,f=c.useMemo(()=>u===void 0||fn(s,u),[s,u]);c.useEffect(()=>{if(!f)for(const g of a)m(g.getId(),"").then()},[f,a,m]);const h=ze(a,e);return f?o.jsx(d.Card,{variant:"soft",children:o.jsxs("div",{className:"flex flex-col gap-4",children:[(r||i)&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex flex-col",children:[o.jsx(d.Heading,{size:"md",children:r}),o.jsx(d.Text,{accentColor:"base",children:i})]}),o.jsx(d.Separator,{size:"full"})]}),h]})}):null});$r.displayName="FieldSectionLayout";const Oe=class Oe extends xt{constructor(e){const{label:r=null,fields:i,condition:a=null,conditional:s,...l}=e;super({...l,type:"section"});N(this,"label");N(this,"fields");N(this,"condition");this.fields=i,this.condition=a,this.label=r,s===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const i=r&&`${r}.`;return[{field:new Ee({label:"Conditionally render section",identifier:`${i}conditional`,required:!1}),showDirectly:!0},{field:new Oe({label:"Conditional settings",identifier:`${i}conditional-settings`,condition:{identifier:`${i}conditional`,value:!0},fields:[new Ue({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:`${i}condition.identifier`,required:!0}),new $o({label:"Value",identifier:`${i}condition.value`,required:!0,clonedFieldIdentifier:`${i}condition.identifier`,getFieldToClone(a){if(!a)return null;const s=e.find(l=>l.identifier===a);return s?{...s,label:"Value",identifier:`${i}condition.value`,description:"The value to compare against.",required:s.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(un);return new Oe({...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 i of this.fields){const a=i.getId(),s=i.getError(R(e,a),e);s&&$e(r,i.getId(),s)}return r}getInput(e){return o.jsx($r,{field:this,...e})}};N(Oe,"fieldTypeName","Section"),N(Oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let W=Oe;const ge=t=>Object.keys(t).length>0,vt=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof W){if(r.condition){const{identifier:i}=r.condition;if(!fn(r.condition,R(n,i)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof j))throw new Error("Invalid field type");const i=r.getId(),a=r.getError(R(n,i),n);a&&$e(e,i,a)}if(ge(e))return e},yt=(t,n)=>t.reduce((e,r)=>{if(r instanceof W)return{...e,...yt(r.fields,n)};const i=r.getId();return $e(e,i,e[i]??void 0),e},ti(n)),kr=(t,n,e)=>t.reduce((r,i)=>{if(i instanceof W)return{...r,...kr(i.fields,n,e)};if(i instanceof j){const a=i.getId(),s=n[a],l=e[a];i.isEqual(s,l)||$e(r,a,l)}return r},{}),jr=c.memo(c.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:i,onSubmit:a,submitText:s="Submit",cancelText:l,onCancel:m,onDirty:u,onDirtyChange:f,hideTitle:h=!e.title,hideDescription:g,className:C,buttonProps:w,enableReinitialize:p=!1,excludeUnchangedFields:b=!1}=t,{readonly:I}=e.meta,x=c.useId(),y=c.useMemo(()=>yt(e.fields,r),[e.fields,r]),T=c.useCallback(_=>{a==null||a(b?kr(e.fields,y,_):_)},[b,y,a,e.fields]),S=k.useFormik({initialValues:y,onSubmit:T,validate:_=>vt(e,_),validateOnBlur:!1,validateOnChange:!1,enableReinitialize:p}),{dirty:L}=S,F=c.useMemo(()=>typeof e.title=="string"?o.jsx(d.Heading,{size:"md",children:e.title}):e.title,[e.title]),D=c.useMemo(()=>typeof e.description=="string"?o.jsx(d.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),M=c.useCallback((_,U)=>{Ur(e)[_].isEqual(y[_],U)||i==null||i({...S.values,[_]:U},{[_]:U})},[S.values,y,i,e]),O=ze(e.fields,{formId:x,disabled:I,onValuesChange:M});return c.useEffect(()=>{L&&u&&u(),f&&f(L)},[L,u,f]),o.jsx(k.FormikProvider,{value:S,children:o.jsxs("form",{id:x,ref:n,className:ye(C,"flex flex-col gap-2"),onSubmit:S.handleSubmit,children:[!h&&o.jsx(d.Card,{variant:"soft",children:o.jsxs("div",{className:"flex flex-col gap-1",children:[F,!g&&D]})}),O,!I&&o.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&o.jsxs(d.Button,{accentColor:ue.danger,...w,type:"button",onClick:m,children:[o.jsx(d.RiIcon,{icon:"RiCloseLine"}),l]}),o.jsxs(d.Button,{...w,type:"submit",disabled:!S.isValid,accentColor:"success",children:[o.jsx(d.RiIcon,{icon:"RiCheckLine"}),s]})]})]})})})),ve=c.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=k.useFormikContext(),[i,a,s]=k.useField(n),l=c.useMemo(()=>{const m=u=>{s.setValue(u,!1)};return e({value:i.value,meta:a,setValue:m,patchValue:()=>{r()}})},[e,i.value,a,r,s]);return o.jsx(o.Fragment,{children:l})});ve.displayName="PatchField";const Ro=c.memo(c.forwardRef((t,n)=>{const{children:e,schema:r,values:i,onPatch:a,onError:s,requiresDiff:l=!0,onDirtyChange:m,...u}=t,f=c.useMemo(()=>yt(r.fields,i),[r.fields,i]),h=c.useCallback(x=>{const y={};for(const T in x){const S=x[T];S!==f[T]&&S!==void 0&&(y[T]=S)}return y},[f]),g=c.useCallback(x=>{const y=h(x);l&&!ge(y)||a(y)},[h,a,l]),C=c.useCallback(x=>{const y=vt(r,x);if(y&&s(y),m){const T=h(x);m(ge(T))}return y},[r,m,s,h]),w=k.useFormik({initialValues:f,onSubmit:g,validate:C,validateOnBlur:!1,validateOnChange:!1}),p=c.useCallback(()=>{if(m){const x=h(w.values);ge(x)&&m(!0)}},[w.values,h,m]),{errors:b,resetForm:I}=w;return c.useEffect(()=>{ge(b)&&I({values:f,errors:{}})},[b,f,I]),o.jsx(k.FormikProvider,{value:w,children:o.jsx("form",{...u,ref:n,onSubmit:w.handleSubmit,onChange:p,children:e})})})),bt="form-builder",ea=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],hn={...dn,section:W},Ct=c.createContext({}),ta=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const i in e)e[i].disabled=!1;return e;case"hold":for(const i in e)(r=e[i])!=null&&r.conditionFields.has(n.fieldId)&&(e[i].disabled=!0);return e;case"update":return n.state}},na=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const i of r.fields)if(i.identifier===n)return e}}},Wr=t=>{var e,r,i;const n={};for(let a=0;a<t.length;a++){const s=t[a];if(!s)throw new Error("Field is undefined.");const l=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,m=new Set(l);(r=s.condition)!=null&&r.identifier&&m.add(s.condition.identifier),n[s.identifier]={disabled:!1,conditionFields:m,conditionIndex:na(t,(i=s.condition)==null?void 0:i.identifier),index:a,label:s.label}}return n},pn=c.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:i,duplicate:a,move:s,upload:l}=t;if(e!=="section"&&!l)throw new Error("Upload function prop must be defined for non-section fields.");const{values:m}=k.useFormikContext(),u=c.useRef(null),f=c.useMemo(()=>{const h=[{Icon:H.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:H.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:i}}),e!=="section"&&h.unshift({Icon:H.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=u.current)==null||g.click()}}}),(r===void 0&&n!==m.fields.length-1||r!==void 0&&(r<m.fields.length-1||n!==m.fields[r].fields.length-1))&&h.unshift({Icon:H.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{s("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:H.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{s("up")}}}),h},[a,n,s,i,r,e,m.fields]);return o.jsxs(o.Fragment,{children:[o.jsx(d.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:f.map(h=>o.jsx(d.IconButton,{type:"button","aria-label":h.text,...h.buttonProps,children:o.jsx(h.Icon,{})},h.key))}),o.jsx("div",{className:"sm:hidden",children:o.jsxs(d.Menu.Root,{children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsx(d.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:o.jsx(d.RiIcon,{icon:"RiMore2Line"})})}),o.jsx(d.Menu.Content,{children:f.map(h=>{var g;return o.jsxs(d.Menu.Item,{onClick:(g=h.buttonProps)==null?void 0:g.onClick,children:[o.jsx(h.Icon,{}),h.text]},h.key)})})]})}),e!=="section"&&o.jsx("input",{style:{display:"none"},ref:u,type:"file",accept:"image/*",onChange:l})]})});pn.displayName="FieldActions";const mn=c.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return o.jsxs(d.Popover.Root,{children:[o.jsx(d.Popover.Trigger,{asChild:!0,children:o.jsxs(d.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:ue.danger},children:[o.jsx(d.RiIcon,{icon:"RiSettings2Line"}),o.jsx("span",{children:"Settings"})]},"settings")}),o.jsx(d.Popover.Content,{size:"sm",...r,children:o.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});mn.displayName="FieldSettingsPopover";const qr=(t=()=>null)=>c.useMemo(()=>ea.map(n=>n.map(e=>{const r=dn[e],i=r.Icon;return{children:r.fieldTypeName,icon:o.jsx(i,{}),value:e,onSelect:()=>{t(e)}}})),[t]),Hr=576,gn=c.memo(t=>{var Be,vn,Jr,Zr,Rr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:i}=t,{values:a,setFieldValue:s,errors:l}=k.useFormikContext(),m=qr(),u=We(),{disableRequiredFields:f}=c.use(Ct),h=c.useRef(null),[g,C]=c.useState(h.current&&h.current.getBoundingClientRect().width>=Hr);c.useEffect(()=>{const P=h.current;if(P){const z=new ResizeObserver(G=>{G[0]&&C(G[0].contentRect.width>=Hr)});return z.observe(P),()=>{z.disconnect()}}},[]);const[w,p]=c.useState(void 0);c.useEffect(()=>{me(r)?p(void 0):r.image instanceof Promise?r.image.then(p).catch(console.error):p(r.image)},[r]);const b=w?URL.createObjectURL(w):void 0,I=c.useCallback(P=>{P.stopPropagation();const{image:z,...G}=r;s(`${n}.${e}`,G).then()},[e,r,n,s]);c.useEffect(()=>{me(r)&&!r.conditional&&s(`${n}.${e}.condition`,null).then()},[e,r,n,s]);const x=c.useMemo(()=>{var P,z;return me(r)?(z=Ir(a.fields,(P=r.condition)==null?void 0:P.identifier))==null?void 0:z.label:void 0},[r,a.fields]),y=me(r)?Array.isArray((Be=r.condition)==null?void 0:Be.value)?"contains all of":"equals":void 0;let T;if(me(r)){if(gt((vn=r.condition)==null?void 0:vn.value))throw new Error("File values are not supported for conditions.");T=Array.isArray((Jr=r.condition)==null?void 0:Jr.value)?r.condition.value.map(P=>typeof P=="string"?P:P.label).join(", "):(Rr=(Zr=r.condition)==null?void 0:Zr.value)==null?void 0:Rr.toString()}const S=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),L=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),F=r.type,D=hn[F],[M,O]=c.useMemo(()=>{let P=[],z=[];if(D===W){if(i===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const G=D.getFieldCreationSchema(i,`${n}.${e}`);P=P.concat(G.filter($=>$.showDirectly).map($=>$.field)),z=z.concat(G.filter($=>!$.showDirectly).map($=>$.field))}else{if(!(D.prototype instanceof j))throw new Error(`Field must be an instance of BaseField. Got ${D.toString()}.`);const G=D.getFieldCreationSchema(`${n}.${e}`);g?(P=[...P,...G.filter($=>$.showDirectly).map($=>$.field)],z=[...z,...G.filter($=>!$.showDirectly).map($=>$.field)]):z=[...z,...G.map($=>$.field)]}return[P,z]},[D,i,n,e,g]),_=ze(M,{formId:bt,disabled:!1,...D===W&&{size:"sm"}}),U=ze(O,{formId:bt,disabled:!1});let B=O.length>0;me(r)&&O.length>0&&(B=r.conditional);const Z=O.some(P=>{const z=R(l,D===W?`${n}.${e}.condition`:P.getId());return z&&(typeof z!="object"||ge(z))}),A=Z?ue.danger:void 0,q=c.useMemo(()=>pt(r),[r]),le=Qt(q,{formId:bt,showInputOnly:!1}),ne=c.useMemo(()=>m.flat().find(P=>P.value===F),[m,F]),ce=c.useCallback(()=>{w&&u(()=>({file:w}))},[u,w]);return o.jsx("div",{className:"flex grow items-center w-full",ref:h,children:o.jsxs("div",{className:"flex w-full flex-col gap-2",children:[D===W&&(M.length>0||B)&&o.jsxs("div",{className:"flex flex-col gap-2",children:[_,B&&o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(mn,{popoverInputs:U,hasError:Z,align:"start"}),me(r)&&r.conditional&&o.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":A,children:o.jsxs("em",{children:["Display only if ",o.jsx("strong",{children:x})," ",y," ",o.jsx("strong",{children:T})]})})]})]}),D!==W&&o.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[o.jsxs("div",{className:"flex gap-2 items-center",children:[o.jsxs(d.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[ne==null?void 0:ne.icon,ne==null?void 0:ne.children]}),!f&&o.jsx(ve,{name:`${n}.${e}.required`,render:({setValue:P,value:z})=>o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.Checkbox.Root,{checked:z,onCheckedChange:P,size:"sm",children:o.jsx(d.Checkbox.Indicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})})}),o.jsx(d.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),B&&o.jsx(mn,{popoverInputs:U,hasError:Z,align:"end"})]}),w&&o.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[o.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:b,alt:w.name,onClick:ce}),o.jsx(d.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:"base","aria-label":"delete",onClick:I,size:"sm",children:o.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),o.jsx(ve,{name:`${n}.${e}.label`,render:({setValue:P,value:z})=>o.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:F==="section"?"Enter a section label (optional)":"Enter your question",value:z,onChange:G=>{P(G.target.value)},onInput:S,maxLength:200})}),o.jsx(ve,{name:`${n}.${e}.description`,render:({setValue:P,value:z})=>o.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${F==="section"?"section":"field"} description (optional)`,value:z,onChange:G=>{P(G.target.value)},onInput:L,maxLength:1e3})}),D!==W&&M.length>0&&o.jsx("div",{className:"w-full",children:_}),D!==W&&o.jsxs(d.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[o.jsxs(d.HoverCard.Root,{children:[o.jsx(d.HoverCard.Trigger,{asChild:!0,children:o.jsx(d.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:o.jsx(d.RiIcon,{icon:"RiEyeLine"})})}),o.jsx(d.HoverCard.Content,{className:"w-[225px]",size:"sm",align:"start",children:"This is a preview of the field as it will be rendered in the form."})]}),o.jsx("div",{className:"grow h-max",children:le})]})]})})});gn.displayName="FieldBuilder";const Gr=c.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:i}=t,{setFieldValue:a,values:s}=k.useFormikContext(),{reorderField:l}=Rt(),{showInfo:m,showError:u}=d.useToast(),f=`fields.${r}.fields`,h=c.useMemo(()=>({index:e,parentPath:f,initial:n}),[n,e,f]),g=c.useCallback(()=>{const p=n.label||"Unlabelled field",b={...n,label:p};lt(f,e+1,b,s,a),m({title:"Field duplicated",description:`The field "${p}" has been duplicated`})},[n,f,e,s,a,m]),C=c.useCallback(p=>{const b=r,I=s.fields[b];let x=r,y=p==="up"?e-1:e+1;p==="up"&&e===0?(x=r-1,y=s.fields[x].fields.length):p==="down"&&e===I.fields.length-1&&(x=r+1,y=0);const T=s.fields[x];l(I,b,e,T,x,y,a)},[r,s.fields,e,l,a]),w=c.useCallback(p=>{const{files:b}=p.target;if(!b||b.length!==1)return;const I=b.item(0);if(I){if(I.size>Yo){u({title:"File upload error",description:`The file ${I.name} exceeded the maximum file size`});return}a(`${f}.${e}`,{...n,image:I}).then()}},[n,e,f,a,u]);return o.jsx(ie.Draggable,{draggableId:n.identifier,index:e,children:p=>o.jsx(d.Card,{ref:p.innerRef,...p.draggableProps,...p.dragHandleProps,className:"mb-4",children:o.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[o.jsx(gn,{...h}),o.jsx(pn,{index:e,type:n.type,sectionIndex:r,remove:i,duplicate:g,move:C,upload:w})]})})})});Gr.displayName="FieldWithActions";const Xr=c.memo(t=>{var T;const{field:n,index:e,dropState:r}=t,i=(T=r[n.identifier])==null?void 0:T.disabled,{setFieldValue:a,values:s}=k.useFormikContext(),l=d.useAlertDialog(),{reorderSection:m}=Rt(),{showInfo:u}=d.useToast(),{fieldsOnly:f}=c.use(Ct),h=c.useCallback((S,L)=>{for(const F of S){const D=L.indexOf(F);a(`fields.${D}.condition`,null).then(),a(`fields.${D}.conditional`,!1).then()}},[a]),g=c.useCallback(S=>{var D;const L=n.fields[S];if(!L)throw new Error("Could not find field to remove.");const F=[];for(const M of s.fields)((D=M.condition)==null?void 0:D.identifier)===L.identifier&&F.push(M);return{removing:L,affectedSections:F,action:()=>a(`fields.${e}.fields`,st(n.fields,S))}},[n.fields,s.fields,a,e]),C=c.useCallback(S=>{const{affectedSections:L,action:F,removing:D}=g(S),M=()=>{F().then(),h(L,s.fields)};if(L.length>0){const O=L.map(_=>_.label).join(", ");l({title:"Remove condition?",description:`${D.label} is being used as a condition, deleting it will remove the condition from the ${O} section(s).`,action:"Remove",onAction:M});return}M()},[g,h,s.fields,l]),w=c.useCallback(()=>{const L=n.fields.map((B,Z)=>g(Z)).flatMap(B=>B.affectedSections),F=L.length?"Remove fields and conditions?":"Remove fields?",D=n.fields.length,M=L.map(B=>B.label).join(", "),O=L.length?`Deleting this section will remove the ${D} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${D} field(s) it contains.`,_=st(s.fields,e),U=()=>a("fields",_);if(L.length>0){l({title:F,description:O,action:"Remove",onAction:()=>{U().then(()=>{h(L,_)})}});return}U().then()},[n.fields,s.fields,e,g,a,l,h]),p=c.useCallback(S=>{const L=S==="up"?e-1:e+1;m(r,n.identifier,e,L,s,a)},[e,m,r,n.identifier,s,a]),b=c.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:xr(s.fields,e)}),[n,e,s.fields]),I=c.useCallback(()=>{const S=n.label||"Untitled section",L=n.fields.map(D=>({...D,identifier:Zt()})),F={...n,label:S,fields:L};lt("fields",e+1,F,s,a),u({title:"Section duplicated",description:`The section "${S}" has been duplicated.`})},[n,e,s,a,u]),x=c.useCallback(S=>{lt(`fields.${e}.fields`,n.fields.length,Qo[S],s,a)},[e,n.fields.length,s,a]),y=qr(x);return o.jsx(ie.Draggable,{draggableId:n.identifier,index:e,children:S=>o.jsx(d.Card,{ref:S.innerRef,...S.draggableProps,...S.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:o.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[o.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!f&&o.jsx(gn,{...b}),o.jsx(ie.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:i,children:L=>o.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:L.innerRef,...L.droppableProps,children:[n.fields.map((F,D)=>o.jsx(Gr,{field:F,index:D,sectionIndex:e,remove:()=>{C(D)}},F.identifier)),L.placeholder,o.jsxs(d.Menu.Root,{children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add field"]})}),o.jsx(d.Menu.Content,{children:y.flat().map(F=>o.jsxs(d.Menu.Item,{onSelect:F.onSelect,children:[F.icon,F.children]},F.value))})]})]})})]}),!f&&o.jsx(pn,{index:e,type:n.type,remove:w,duplicate:I,move:p})]})})})});Xr.displayName="FieldSectionWithActions";const Kr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Qr=c.memo(()=>{const{values:t,setFieldValue:n}=k.useFormikContext(),[e,r]=c.useReducer(ta,t.fields,Wr),{reorderSection:i,reorderField:a}=Rt(),{fieldsOnly:s}=c.use(Ct);c.useEffect(()=>{r({type:"update",state:Wr(t.fields)})},[r,t.fields]);const l=c.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),m=c.useCallback(f=>{const{source:h,destination:g,type:C,reason:w,draggableId:p}=f;if(r({type:"release"}),!g||w==="CANCEL")return;if(C==="ROOT"){i(e,p,h.index,g.index,t,n);return}if(C!=="SECTION")throw new Error("Unexpected droppable type.");const[b,I]=Kr(t.fields,h.droppableId)??[],[x,y]=Kr(t.fields,g.droppableId)??[];a(b,I,h.index,x,y,g.index,n)},[t,a,n,i,e]),u=c.useCallback(f=>{Go(f+1,t,n)},[t,n]);return o.jsx(ie.DragDropContext,{onDragStart:l,onDragEnd:m,children:o.jsx(ie.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>o.jsxs("div",{className:"flex flex-col gap-0",ref:f.innerRef,...f.droppableProps,children:[t.fields.map((h,g)=>o.jsxs(c.Fragment,{children:[o.jsx(Xr,{field:h,index:g,dropState:e,fieldsOnly:s}),!s&&g!==t.fields.length-1&&o.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{u(g)},children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]})]},h.identifier)),o.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{u(t.fields.length)},children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]}),f.placeholder]})})})});Qr.displayName="FieldsEditor";const ra=c.memo(c.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:i,initialTitle:a,showExplainerText:s=!0,showFormTitle:l=!0,fieldsOnly:m=!1,showTabs:u=!0,disableRequiredFields:f=!1,tabsListClassName:h,hydrateRevisionWithImages:g}=t,{showError:C}=d.useToast(),w=c.useCallback(T=>{const S={};T.title||(S.title="Title is required."),(!T.fields||T.fields.length===0)&&(S.fields="At least one field is required.");let L=[];for(const[D,M]of T.fields.entries()){const _=hn.section.getFieldCreationSchema(xr(T.fields,D),`fields.${D}`).map(U=>U.field);L=[...L,..._];for(const[U,B]of M.fields.entries()){const A=hn[B.type].getFieldCreationSchema(`fields.${D}.fields.${U}`).map(q=>q.field);L=[...L,...A]}}const F=vt({fields:L},T);if(F&&(S.fields=F.fields),ge(S))return C({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),S},[C]),p=c.useMemo(()=>({title:a??"",description:"",fields:[{...at(Zt()),label:""}]}),[a]),b=i?g(i):void 0,I=k.useFormik({initialValues:Ho(b)??p,validate:w,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),x=c.useMemo(()=>Vr(I.values),[I.values]),y=c.useMemo(()=>({disableRequiredFields:f,fieldsOnly:m}),[f,m]);return o.jsx(Ct,{value:y,children:o.jsx(d.Tabs.Root,{ref:n,defaultValue:"edit",children:o.jsxs("div",{className:"flex flex-col gap-2",children:[u&&o.jsxs(d.Tabs.List,{className:ye("sticky top-0 z-[2000] flex bg-(--color-background)",h),children:[o.jsx(d.Tabs.Trigger,{className:"grow",value:"edit",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),o.jsx(d.Tabs.Trigger,{className:"grow",value:"preview",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),o.jsxs(d.Tabs.Content,{value:"edit",children:[s&&o.jsxs(d.Text,{children:["Create your form using various field types. Sections can be"," ",o.jsx("strong",{children:"conditionally rendered"})," based on"," ",o.jsx("strong",{children:"answers to fields in preceding sections. "})]}),o.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:bt,onSubmit:I.handleSubmit,children:[o.jsxs(k.FormikProvider,{value:I,children:[l&&o.jsxs(o.Fragment,{children:[o.jsx(ve,{name:"title",render:({setValue:T,value:S,meta:L})=>o.jsx(Gt,{severity:"danger",helpText:L.error??null,children:o.jsx(d.Input.Root,{variant:"outline",size:"md",accentColor:L.error?ue.danger:"primary",children:o.jsx(d.Input.Field,{placeholder:"Form title",value:S,onChange:F=>{T(F.target.value)},maxLength:100})})})}),o.jsx(ve,{name:"description",render:({setValue:T,value:S})=>o.jsx(d.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:S,onChange:L=>{T(L.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),o.jsx(Qr,{}),o.jsx("span",{"data-accent-color":ue.danger,className:"text-xs text-(--accent-a11)",children:typeof I.errors.fields=="string"&&I.errors.fields})]}),o.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&o.jsx(d.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),o.jsx(d.Button,{type:"submit",children:"Save form"})]})]})]}),o.jsx(d.Tabs.Content,{value:"preview",children:o.jsx(jr,{schema:x,hideTitle:!l})})]})})})})),ia=Object.values(de.Colors),oa=1;async function aa(t,n,e,r){const i=t.getContext("2d",{}),a=new Image(r.width,r.height),s=new Image(r.width,r.height),l=new de.DeferredPromise;return a.onload=function(){i.drawImage(a,0,0,r.width,r.height),s.src=URL.createObjectURL(e),s.onload=async function(){i.drawImage(s,0,0,r.width,r.height);const m=t.toDataURL("image/jpeg",oa),u=await de.fileToBlob(m),f=new File([u],n.name,{type:"image/jpeg"});l.resolve(f)}},a.src=URL.createObjectURL(n),l}const Yr=c.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:i,dirty:a,onDirty:s}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const l=c.useRef(null),m=c.useRef(null),[u,f]=c.useState(de.Colors.red),[h,g]=c.useState(null),[C,w]=c.useState(!1),[p,b]=c.useState(!1),I=c.useRef(null),x=d.useSize(I);c.useEffect(()=>{const B=new Image;B.onload=function(){g({width:B.naturalWidth,height:B.naturalHeight})},B.src=URL.createObjectURL(n)},[n]),c.useEffect(()=>{!p&&(x!=null&&x.width)&&x.height&&b(!0)},[x,p]);const y=c.useCallback(async()=>{a||e();const B=l.current;if(!B)return;if(!h)throw new Error("Original image size not loaded yet");const Z=await B.exportImage("png"),A=new Image(h.width,h.height);A.onload=async function(){const q=await de.fileToBlob(Z),le=new File([q],n.name,{type:n.type}),ne=m.current,ce=await aa(ne,n,le,h);ce.objectURL=URL.createObjectURL(ce);const Be=await de.hashFile(n);await de.hashFile(ce)!==Be&&r(ce),w(!1),e()},w(!0),A.src=Z},[a,n,e,r,h]),T=c.useCallback(()=>{i(n)},[n,i]),S=c.useCallback(()=>{e()},[e]),L=c.useCallback(()=>{s(!0)},[s]),F=c.useCallback(()=>{l.current&&l.current.redo()},[]),D=c.useCallback(()=>{l.current&&l.current.undo()},[]),M=c.useCallback(()=>{l.current&&(s(!1),l.current.clearCanvas())},[s]),O=c.useCallback(B=>{l.current&&l.current.eraseMode(B)},[]),_=c.useCallback(()=>{y()},[y]),U=c.useCallback(()=>{qt.saveAs(n,n.name)},[n]);return o.jsx($t,{open:!0,onOpenChange:e,children:o.jsxs(kt,{children:[o.jsx(jt,{className:"bg-(--color-background) fixed inset-0 data-[state='open']:fade-in-0 data-[state='open']:zoom-in-95 data-[state='closed']:animate-out data-[state='closed']:fade-out-0 data-[state='closed']:zoom-out-95 data-[state='open']:animate-in","data-floating-content":""}),o.jsxs(Wt,{className:"absolute inset-0 py-12","data-floating-content":"",children:[o.jsx(d.ButtonGroup,{className:"flex w-full gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",size:"md",variant:"soft",children:o.jsxs("div",{className:"grid w-full grid-cols-3",children:[o.jsxs("div",{className:"flex gap-2",children:[o.jsx(d.IconButton,{"aria-label":"close",onClick:S,children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})}),o.jsx(d.IconButton,{"aria-label":`Download ${n.name}`,onClick:U,children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})})]}),o.jsxs("div",{className:"flex items-center justify-center gap-2",children:[o.jsx(wt,{selectedColor:u,allColors:ia,onFinish:f,trigger:o.jsx(d.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:u},children:" "})}),o.jsx(d.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:O,children:o.jsx(d.RiIcon,{icon:"RiEraserFill"})}),o.jsx(d.Separator,{orientation:"vertical",size:"full"}),o.jsx(d.IconButton,{"aria-label":"undo",onClick:D,children:o.jsx(d.RiIcon,{icon:"RiArrowGoBackLine"})}),o.jsx(d.IconButton,{"aria-label":"undo",onClick:F,children:o.jsx(d.RiIcon,{icon:"RiArrowGoForwardLine"})}),o.jsx(d.IconButton,{"aria-label":"undo all",onClick:M,children:o.jsx(d.RiIcon,{icon:"RiLoopLeftLine"})})]}),o.jsxs("div",{className:"flex justify-end gap-2",children:[o.jsx(d.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:_,children:o.jsx(d.RiIcon,{icon:"RiSaveLine"})}),o.jsx(d.IconButton,{"aria-label":"Delete attachment",onClick:T,children:o.jsx(d.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})}),h&&o.jsx("canvas",{id:"attachment-markup-canvas",className:"hidden",ref:m,width:h.width,height:h.height}),o.jsxs("div",{className:"relative size-full flex items-center justify-center p-4 overflow-hidden",children:[o.jsx("img",{className:"max-w-full max-h-full invisible absolute",alt:"Photo attachment",ref:I,src:n.objectURL}),C?o.jsx(d.Spinner,{}):o.jsx(ni.ReactSketchCanvas,{className:"max-w-full max-h-full aspect-square",backgroundImage:n.objectURL,ref:l,onStroke:L,strokeColor:u},p?"1":"0")]})]})]})})});Yr.displayName="AttachmentEditor",E.BaseField=j,E.BaseFormElement=xt,E.BooleanField=Ee,E.BooleanInput=Xt,E.ColorPicker=wt,E.DateField=rt,E.DateInput=Kt,E.FieldSection=W,E.FileCard=It,E.FileIcon=ke,E.FormBuilder=ra,E.FormRenderer=jr,E.ImageCard=Or,E.ImageMarkup=Yr,E.ImageViewer=Ht,E.ImageViewerProvider=gr,E.InputWithHelpText=Gt,E.InputWithLabel=Y,E.InputWithLabelAndHelpText=J,E.MultiSelectField=Ve,E.MultiSelectInput=on,E.MultiStringField=_e,E.MultiStringInput=en,E.NumberField=se,E.NumberInput=tn,E.PatchField=ve,E.PatchFormProvider=Ro,E.QrField=ct,E.QrInput=nn,E.QrScanner=rn,E.SUPPORTED_IMAGE_FILE_TYPES=wn,E.SUPPORTED_PDF_FILE_TYPES=xn,E.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=In,E.SelectField=Ue,E.SelectInput=an,E.StringField=ut,E.StringInput=sn,E.TextField=ft,E.TextInput=ln,E.decodeFormValues=Jo,E.deserialize=pt,E.deserializeField=un,E.emptyBaseField=X,E.emptyBooleanField=vr,E.emptyDateField=yr,E.emptyMultiSelectField=Lr,E.emptyMultiStringField=Er,E.emptyNumberField=Sr,E.emptyQrField=Nr,E.emptySelectField=Dr,E.emptyStringField=Pr,E.emptyTextField=Ar,E.encodeFormValues=Zo,E.fieldIcons=oi,E.flattenFields=mt,E.formRevisionToSchema=Vr,E.getFieldsMapping=Ur,E.initialFormValues=yt,E.isConditionMet=fn,E.useFieldInput=Qt,E.useFieldInputs=ze,E.useFormikInput=K,E.useImageViewer=We,E.validateForm=vt,E.valueIsFile=gt,Object.defineProperty(E,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},Oo="DialogDescriptionWarning",Bo=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hr(Oo).contentName}}.`;return v.useEffect(()=>{var a;const i=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&i&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},$t=tr,zo=rr,kt=or,jt=ar,Wt=sr,pr=ur,tt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},nt={exports:{}},_o=nt.exports,mr;function Vo(){return mr||(mr=1,function(t,n){(function(e,r){r()})(_o,function(){function e(u,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(u.type)?new Blob(["\uFEFF",u],{type:u.type}):u}function r(u,f,h){var g=new XMLHttpRequest;g.open("GET",u),g.responseType="blob",g.onload=function(){m(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function i(u){var f=new XMLHttpRequest;f.open("HEAD",u,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(u){try{u.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),u.dispatchEvent(f)}}var s=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof tt=="object"&&tt.global===tt?tt:void 0,l=s.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),m=s.saveAs||(typeof window!="object"||window!==s?function(){}:"download"in HTMLAnchorElement.prototype&&!l?function(u,f,h){var g=s.URL||s.webkitURL,C=document.createElement("a");f=f||u.name||"download",C.download=f,C.rel="noopener",typeof u=="string"?(C.href=u,C.origin===location.origin?a(C):i(C.href)?r(u,f,h):a(C,C.target="_blank")):(C.href=g.createObjectURL(u),setTimeout(function(){g.revokeObjectURL(C.href)},4e4),setTimeout(function(){a(C)},0))}:"msSaveOrOpenBlob"in navigator?function(u,f,h){if(f=f||u.name||"download",typeof u!="string")navigator.msSaveOrOpenBlob(e(u,h),f);else if(i(u))r(u,f,h);else{var g=document.createElement("a");g.href=u,g.target="_blank",setTimeout(function(){a(g)})}}:function(u,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof u=="string")return r(u,f,h);var C=u.type==="application/octet-stream",w=/constructor/i.test(s.HTMLElement)||s.safari,p=/CriOS\/[\d]+/.test(navigator.userAgent);if((p||C&&w||l)&&typeof FileReader<"u"){var b=new FileReader;b.onloadend=function(){var y=b.result;y=p?y:y.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=y:location=y,g=null},b.readAsDataURL(u)}else{var I=s.URL||s.webkitURL,x=I.createObjectURL(u);g?g.location=x:location.href=x,g=null,setTimeout(function(){I.revokeObjectURL(x)},4e4)}});s.saveAs=m.saveAs=m,t.exports=m})}(nt)),nt.exports}var qt=Vo();const Ht=c.memo(t=>{const{file:n,onClose:e}=t,r=c.useRef(null),i=c.useCallback(()=>{var l;if(!r.current)return;const s=document.createElement("canvas");s.width=r.current.width,s.height=r.current.height,(l=s.getContext("2d"))==null||l.drawImage(r.current,0,0,r.current.width,r.current.height),s.toBlob(m=>{m&&navigator.clipboard.write([new ClipboardItem({"image/png":m})])},"image/png")},[]),a=c.useCallback(()=>{qt.saveAs(n,n.name)},[n]);return o.jsx($t,{open:!0,onOpenChange:e,children:o.jsx(kt,{children:o.jsx(jt,{className:"bg-(--color-background) fixed inset-0 data-[state='open']:fade-in-0 data-[state='open']:zoom-in-95 data-[state='closed']:animate-out data-[state='closed']:fade-out-0 data-[state='closed']:zoom-out-95 data-[state='open']:animate-in","data-floating-content":"",children:o.jsxs(Wt,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:s=>s.preventDefault(),children:[o.jsxs(d.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[o.jsxs(d.Tooltip.Root,{children:[o.jsx(d.Tooltip.Trigger,{asChild:!0,children:o.jsx(d.IconButton,{onClick:i,"aria-label":"copy to clipboard",children:o.jsx(d.RiIcon,{icon:"RiFileCopyLine"})})}),o.jsx(d.Tooltip.Content,{size:"sm",children:"Copy"})]}),o.jsxs(d.Tooltip.Root,{children:[o.jsx(d.Tooltip.Trigger,{asChild:!0,children:o.jsx(d.IconButton,{onClick:a,"aria-label":"download",children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})})}),o.jsx(d.Tooltip.Content,{size:"sm",children:"Download"})]}),o.jsx(d.Separator,{orientation:"vertical",size:"sm"}),o.jsx(pr,{asChild:!0,children:o.jsx(d.IconButton,{onClick:e,"aria-label":"close",children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),o.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:o.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});Ht.displayName="ImageViewer";const gr=c.memo(t=>{const{children:n}=t,[e,r]=c.useState(null),i=c.useCallback(()=>{r(null)},[]),a=c.useCallback(m=>{r(m(i))},[i]),s=c.useCallback(()=>{e&&(e.onClose&&e.onClose(),i())},[i,e]),l=c.useMemo(()=>a,[a]);return o.jsxs(En.Provider,{value:l,children:[n,e&&o.jsx(Ht,{file:e.file,onClose:s})]})});gr.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:i,inputId:a,labelId:s,image:l}=t,[m,u]=c.useState(void 0),f=We(),h=i?ue[i]:"base";c.useEffect(()=>{l instanceof Promise?l.then(u).catch(console.error):u(l)},[l]);const g=m?URL.createObjectURL(m):void 0,C=c.useCallback(()=>{m&&f(()=>({file:m}))},[f,m]);return o.jsxs("div",{className:"flex flex-col gap-1",children:[m&&o.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:g,alt:m.name,onClick:C}),o.jsx("label",{className:ye(n,"flex flex-col gap-1 w-max max-w-full"),htmlFor:a,children:o.jsx(d.Text,{accentColor:h,size:"sm",id:s,weight:"medium",className:"text-wrap",children:e})}),r]})},Gt=t=>{const{helpText:n,children:e,severity:r}=t,i=r?ue[r]:"base";return o.jsxs("div",{className:"flex flex-col gap-1",children:[e,!!n&&o.jsx("div",{className:"flex flex-col w-full",children:o.jsx(d.Text,{accentColor:i,size:"xs",children:n})})]})},J=t=>{const{children:n,...e}=t;return o.jsx(Gt,{...e,children:n})},Xt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onBlur:g,onChange:C,value:w}=u,p=a?null:l,b=a?"":m,I=c.useCallback(y=>{C(!!y),g(!!y)},[g,C]),x=c.useCallback(()=>{g(w)},[g,w]);return o.jsx(J,{helpText:p,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:a?void 0:s.image,className:"items-center flex-row-reverse justify-end gap-2",children:o.jsx(d.Checkbox.Root,{id:n,name:h,checked:w??!1,onCheckedChange:I,onBlur:x,size:"sm",accentColor:"primary",variant:"surface",...f,children:o.jsx(d.Checkbox.Indicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})})})})})});Xt.displayName="BooleanInput";const vr={...X,type:"boolean"},Se=class Se extends j{constructor(e){super({...e,type:"boolean"});N(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Se(e)}getInput(e){return o.jsx(Xt,{...e,field:this})}};N(Se,"fieldTypeName","Checkbox"),N(Se,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),N(Se,"Icon",H.RiCheckboxCircleLine);let Ee=Se;const Kt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C}=u,[w,p]=c.useState(!1),b=a?null:l,I=a?"":m,x=u.value?new Date(u.value):void 0,y=c.useCallback(S=>{g(S==null?void 0:S.toISOString()),p(!1)},[g]),T=c.useCallback(S=>{p(S),S||C(u.value)},[u.value,C]);return o.jsx(J,{helpText:b,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:o.jsxs(d.Popover.Root,{open:w,onOpenChange:T,children:[o.jsx(d.Popover.Trigger,{asChild:!0,children:o.jsxs(d.Button,{id:n,name:h,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...f,children:[x?x.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",o.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),o.jsx(d.Popover.Content,{align:"start",children:o.jsx(d.DayPicker,{required:!1,mode:"single",variant:"solid",selected:x,onSelect:y})})]})})})});Kt.displayName="DateInput";const yr={...X,type:"date"},Te=class Te extends j{constructor(e){super({...e,type:"date"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new Te(e)}getInput(e){return o.jsx(Kt,{field:this,...e})}};N(Te,"fieldTypeName","Date"),N(Te,"fieldTypeDescription","Allows specifying a date."),N(Te,"Icon",H.RiCalendarLine);let rt=Te;const br=c.memo(t=>{const{field:n,...e}=t,[{value:r}]=k.useField(n.options.clonedFieldIdentifier),i=c.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?pt(a):null},[n.options,r]);return Qt(i,e)});br.displayName="FieldInputCloner";const Uo={...X,type:"custom"};class it extends j{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 o.jsx(r,{field:this,...e})}}N(it,"fieldTypeName","Custom"),N(it,"fieldTypeDescription","Allows re-rendering of field already in the form");class $o extends it{constructor(n){super(n,br)}}const Qt=(t,n)=>c.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),ze=(t,n)=>{const e=c.useMemo(()=>t.map(r=>o.jsx(c.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return o.jsx("div",{className:"flex flex-col gap-4",children:e})},Yt=[];let ot;const ko=new Uint8Array(16);function jo(){if(!ot&&(ot=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ot))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ot(ko)}const V=[];for(let t=0;t<256;++t)V.push((t+256).toString(16).slice(1));function Wo(t,n=0){return V[t[n+0]]+V[t[n+1]]+V[t[n+2]]+V[t[n+3]]+"-"+V[t[n+4]]+V[t[n+5]]+"-"+V[t[n+6]]+V[t[n+7]]+"-"+V[t[n+8]]+V[t[n+9]]+"-"+V[t[n+10]]+V[t[n+11]]+V[t[n+12]]+V[t[n+13]]+V[t[n+14]]+V[t[n+15]]}const Cr={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qo(t,n,e){if(Cr.randomUUID&&!t)return Cr.randomUUID();t=t||{};const r=t.random||(t.rng||jo)();return r[6]=r[6]&15|64,r[8]=r[8]&63|128,Wo(r)}const me=t=>t.type==="section",at=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Ho=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const i of n)i.type==="section"?(e.length>0&&(r.push(at(`AUTO_section-${n.indexOf(i)}`,e)),e=[]),r.push(i)):e.push(i);return e.length>0&&r.push(at("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Jt(t,n,e){const r=Array.from(t),[i]=r.splice(n,1);if(!i)throw new Error("Could not find field to reorder.");return r.splice(e,0,i),r}function wr(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function st(t,n){const e=Array.from(t);return e.splice(n,1),e}const Zt=()=>qo(),Ir=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=Ir(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},xr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),lt=(t,n,e,r,i)=>{const a={...e,identifier:Zt()},s=R(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 l=wr(s,n,a);i(t,l).then()},Go=(t,n,e)=>{const r={...at(),label:""};lt("fields",t,r,n,e)},Rt=()=>{const{showError:t}=d.useToast(),n=c.useCallback((r,i,a,s,l,m)=>{const u=r[i];if(!u)throw new Error("Could not find section context.");let f=typeof u.conditionIndex<"u"?Math.max(u.conditionIndex+1,s):s;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==s){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}m("fields",Jt(l.fields,a,f))},[t]),e=c.useCallback((r,i,a,s,l,m,u)=>{var f;if(!(r!=null&&r.fields)||!s)throw new Error("Could not find section with fields.");if(r.identifier===s.identifier)u(`fields.${i}.fields`,Jt(r.fields,a,m)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=s.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}u(`fields.${i}.fields`,st(r.fields,a)).then(),u(`fields.${l}.fields`,wr(s.fields,m,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},en=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),h=a?null:l,g=a?"":m,{name:C,onChange:w,onBlur:p}=u,b=`${n}-droppable`,{disabled:I}=f,x=u.value??Yt,[y,T]=c.useState(""),[S,L]=c.useState(""),F=S||h,D=c.useCallback(A=>{w(A),p(A)},[w,p]),M=c.useCallback(A=>{x&&x.findIndex(q=>q===A.target.value.trim())>=0?L("All options must be unique"):A.target.value?L(""):L("Option cannot be empty"),T(A.target.value)},[T,x]),O=c.useCallback(()=>{if(S)return;if(!y.trim()){L("Option cannot be empty");return}const A=y.trim();D([...x,A]),T("")},[y,S,D,x]),_=c.useCallback(A=>{A.key==="Enter"&&(A.preventDefault(),O())},[O]),U=c.useCallback(A=>{D(st(x,A))},[x,D]),B=c.useCallback(A=>{if(!A.destination)return;const q=A.source.index,le=A.destination.index;D(Jt(x,q,le))},[D,x]),Z=c.useCallback(()=>{p(x)},[p,x]);return o.jsx(ie.DragDropContext,{onDragEnd:B,children:o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx(J,{helpText:F,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:g,image:a?void 0:s.image,children:(!I||x.length===0)&&o.jsxs("div",{className:"flex gap-2",children:[o.jsx(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{value:y,onChange:M,onKeyDown:_,id:n,placeholder:s.placeholder,onBlur:Z,name:C,...f})}),o.jsx(d.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!S||I,onClick:O,children:o.jsx(d.RiIcon,{icon:"RiAddLine"})})]})})}),o.jsx(ie.Droppable,{droppableId:b,children:A=>o.jsxs("div",{className:"flex flex-col",...A.droppableProps,ref:A.innerRef,children:[x.map((q,le)=>o.jsx(ie.Draggable,{draggableId:`${q}-draggable`,index:le,isDragDisabled:I,children:({draggableProps:ne,dragHandleProps:ce,innerRef:Be})=>o.jsxs(d.Badge,{...ce,...ne,ref:Be,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[o.jsx("span",{children:typeof q=="object"&&"label"in q?q.label:q}),o.jsx(d.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:I,onClick:()=>{U(le)},children:o.jsx(d.RiIcon,{icon:"RiCloseLargeLine"})})]})},q)),A.placeholder]})})]})})});en.displayName="MultiStringInput";const Er={...X,type:"multi-string",minimum_length:0,maximum_length:null},Ne=class Ne extends j{constructor(e){const{minimum_length:r,maximum_length:i,placeholder:a,...s}=e;super({...s,type:"multi-string"});N(this,"minLength");N(this,"maxLength");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.minLength=r??0,this.maxLength=i??1/0,this.placeholder=a??"Press enter to add a new option"}getInput(e){return o.jsx(en,{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==null?void 0:e.length)===0}isEqual(e,r){return e===void 0&&r===void 0?!0:e===void 0||r===void 0?!1:e.every(i=>r.includes(i))&&r.every(i=>e.includes(i))}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 Ne(e)}};N(Ne,"fieldTypeName","Multi-string"),N(Ne,"fieldTypeDescription","Allows the user to provide multiple unique strings."),N(Ne,"Icon",H.RiListCheck);let _e=Ne;const tn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{const D=F.target.valueAsNumber,M=Number.isNaN(D)?void 0:D;T(M),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(M))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{id:n,name:C,onChange:S,onBlur:L,value:y??"",type:"number",min:s.minimum,max:s.maximum,step:s.integers?1:.1,placeholder:s.placeholder,...g})})})})});tn.displayName="NumberInput";const Sr={...X,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Tr=t=>"fields"in t,te=class te extends j{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:i=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:s="Enter a number",...l}=e;super({...l,type:"number"});N(this,"minimum");N(this,"maximum");N(this,"integers");N(this,"placeholder");this.minimum=r,this.maximum=i,this.integers=a,this.placeholder=s}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new te({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new te({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new Ee({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,i=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof i=="number"&&e.push(a=>{if(typeof a=="number"&&a>i)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 te(e)}getInput(e){return o.jsx(tn,{field:this,...e})}};N(te,"fieldTypeName","Number"),N(te,"fieldTypeDescription","Allows specifying a number within a given range."),N(te,"Icon",H.RiHashtag),N(te,"_validateMin",e=>(r,i)=>{const a=Tr(i)?R(i,e):i;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),N(te,"_validateMax",e=>(r,i)=>{const a=Tr(i)?R(i,e):i;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let se=te;const nn=c.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:i,size:a,severity:s,showInputOnly:l,field:m,fieldProps:u},f]=K(t),{name:h,onBlur:g,onChange:C,value:w}=u,[p,b]=c.useState(!1),I=l?null:i,x=l?"":r,y=c.useCallback(L=>{C(L),b(!1)},[C]),T=c.useCallback(()=>{C("")},[C]),S=c.useCallback(L=>{b(L),L||g(w)},[g,w]);return o.jsx(J,{helpText:I,severity:s,children:o.jsxs(Y,{size:a,severity:s,inputId:n,labelId:e,label:x,image:l?void 0:m.image,className:"flex-col items-start justify-start gap-2",children:[o.jsxs("div",{className:"flex w-max items-center gap-1",children:[o.jsxs($t,{open:p,onOpenChange:S,children:[o.jsx(zo,{asChild:!0,children:o.jsxs(d.Button,{id:n,name:h,type:"button",variant:"soft",size:"sm",accentColor:"base",...f,children:[o.jsx(d.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),o.jsxs(kt,{children:[o.jsx(jt,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),o.jsx(Wt,{className:"fixed inset-0",children:o.jsx(rn,{onQrScan:y})})]})]}),w&&o.jsx(d.RiIcon,{icon:"RiCheckLine",className:"align-bottom text-(--primary-a11)"})]}),!!w&&o.jsx(d.Card,{className:"max-w-full w-max",size:"sm",children:o.jsxs("div",{className:"max-w-full w-max flex justify-between gap-2",children:[o.jsx("code",{className:"bg-(--base-a3) truncate text-sm",children:w}),o.jsx(d.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:T,children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})]})})]})})});nn.displayName="QrInput";const rn=c.memo(t=>{const{onQrScan:n}=t,e=c.useRef(null),[r,i]=c.useState(!1);return c.useEffect(()=>{if(!e.current)return;const a=new ei(e.current,s=>{const l=s.data;n(l),a.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});i(!0),a.start().finally(()=>{i(!1)})},[n]),o.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[o.jsx("div",{className:"absolute top-0 flex w-full p-2",children:o.jsx(pr,{asChild:!0,children:o.jsx(d.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})})}),o.jsxs("div",{className:"relative max-h-full max-w-full",children:[o.jsx("video",{className:"size-full",ref:e}),r&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:o.jsx(d.Spinner,{})})]})]})});rn.displayName="QrScanner";const Nr={...X,type:"qr"},Fe=class Fe extends j{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 Fe(e)}getInput(e){return o.jsx(nn,{...e,field:this})}};N(Fe,"fieldTypeName","QR"),N(Fe,"fieldTypeDescription","Used for scanning/reading QR codes."),N(Fe,"Icon",H.RiQrCodeLine);let ct=Fe;class Fr extends j{constructor(e){const{placeholder:r="",...i}=e;super(i);N(this,"options");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(s=>(typeof s=="string"&&(s={label:s,value:s}),a.add(s.label),s)),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 on=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C}=u,w=a?null:l,p=a?"":m,b=u.value??Yt,I=c.useCallback(y=>{const T=y.length>0?y:void 0;g(T),C(T)},[C,g]),x=c.useCallback(y=>{y||C(b)},[b,C]);return o.jsx(J,{helpText:w,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:p,image:a?void 0:s.image,children:o.jsxs(d.Menu.Root,{onOpenChange:x,align:"start",children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{id:n,name:h,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...f,children:[o.jsx("span",{className:"truncate",children:b&&b.length>0?b.join(", "):s.placeholder}),o.jsx(d.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),o.jsx(d.Menu.Content,{children:o.jsx(d.Menu.Scroll,{children:o.jsxs(d.Menu.MultiSelectGroup,{values:b,onValuesChange:I,children:[o.jsxs(d.Menu.SelectAllItem,{children:[o.jsx(d.Menu.CheckboxItemIndicator,{children:y=>y?o.jsx(d.RiIcon,{icon:"RiSubtractLine"}):o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),s.options.map(y=>o.jsxs(d.Menu.MultiSelectItem,{value:y.value,children:[o.jsx(d.Menu.SelectedIndicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))]})})})]})})})});on.displayName="MultiSelectInput";const Lr={...X,type:"multi-select",options:[]},Le=class Le extends Fr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}isBlank(n){return super.isBlank(n)||(n==null?void 0:n.length)===0}isEqual(n,e){return n===void 0&&e===void 0?!0:n===void 0||e===void 0?!1:n.every(r=>e.includes(r))&&e.every(r=>n.includes(r))}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Le(n)}getInput(n){return o.jsx(on,{field:this,...n})}};N(Le,"fieldTypeName","Multi-select"),N(Le,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),N(Le,"Icon",H.RiCheckboxLine);let Ve=Le;const an=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C,value:w}=u,p=a?null:l,b=a?"":m,I=c.useCallback(y=>{g(y??void 0),C(y??void 0)},[C,g]),x=c.useMemo(()=>s.options.find(y=>y.value===w),[s.options,w]);return o.jsx(J,{helpText:p,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:a?void 0:s.image,children:o.jsxs(d.Menu.Root,{align:"start",children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{id:n,name:h,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...f,children:[o.jsx("span",{className:"truncate",children:x?x.label:s.placeholder}),o.jsx(d.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),o.jsx(d.Menu.Content,{children:o.jsx(d.Menu.Scroll,{children:o.jsx(d.Menu.SelectGroup,{required:!1,value:w??null,onValueChange:I,children:s.options.map(y=>o.jsxs(d.Menu.SelectItem,{value:y.value,children:[o.jsx(d.Menu.SelectedIndicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))})})})]})})})});an.displayName="SelectInput";const Dr={...X,type:"select",options:[]},De=class De extends Fr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new De(n)}getInput(n){return o.jsx(an,{field:this,...n})}};N(De,"fieldTypeName","Dropdown"),N(De,"fieldTypeDescription","Allows the user to select a single option from a list of options."),N(De,"Icon",H.RiMenuFoldLine);let Ue=De;const Mr=t=>"fields"in t;class dt extends j{constructor(e){const{minLength:r,maxLength:i,placeholder:a="",...s}=e;super(s);N(this,"minLength");N(this,"maxLength");N(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=i?Math.max(i,0):be,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({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 se({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:be,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(dt,"_validateMin",e=>(r,i)=>{const a=Mr(i)?R(i,e):i;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),N(dt,"_validateMax",e=>(r,i)=>{if(typeof r!="number")return null;const{minimum_length:a}=Mr(i)?R(i,e):i;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const sn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{T(F.target.value||void 0),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{id:n,className:"truncate",name:C,value:y??"",type:s.inputType,placeholder:s.placeholder,onChange:S,onBlur:L,...g})})})})});sn.displayName="StringInput";const Pr={...X,type:"string",maximum_length:je,input_type:"text"},Me=class Me extends dt{constructor(e){const{inputType:r="text",...i}=e,a=e.maxLength?Math.min(je,e.maxLength):je,s=e.minLength?Math.min(e.minLength,a):void 0;super({...i,maxLength:a,minLength:s,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:i,input_type:a,...s}=e;return new Me({...s,maxLength:r,minLength:i,inputType:a,placeholder:"Enter a short description"})}getInput(e){return o.jsx(sn,{field:this,...e})}};N(Me,"fieldTypeName","Short Text"),N(Me,"fieldTypeDescription",`Short text fields can hold up to ${je} characters on a single line.`),N(Me,"Icon",H.RiInputField);let ut=Me;const ln=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{T(F.target.value||void 0),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.TextArea,{id:n,value:y??"",name:C,onChange:S,onBlur:L,className:"field-sizing-content min-h-12",placeholder:s.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...g})})})});ln.displayName="TextInput";const Ar={...X,type:"text",maximum_length:be},Pe=class Pe extends dt{constructor(n){const e=n.maxLength?Math.min(be,n.maxLength):be,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,...i}=n;return new Pe({...i,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return o.jsx(ln,{field:this,...n})}};N(Pe,"fieldTypeName","Paragraph"),N(Pe,"fieldTypeDescription",`Paragraph fields can hold up to ${be} characters and can have multiple lines.`),N(Pe,"Icon",H.RiAlignJustify);let ft=Pe;const Or=c.memo(c.forwardRef((t,n)=>{const{file:e,alt:r,error:i,rightSlot:a,className:s,...l}=t;return o.jsxs("div",{className:ye(s,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...l,children:[!e&&!i&&o.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:o.jsx(d.Spinner,{})}),o.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!i&&o.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),o.jsxs("div",{className:ye("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[i?o.jsx(d.RiIcon,{icon:"RiFileWarningLine"}):e&&o.jsx(ke,{fileType:e.type}),o.jsx(d.Text,{className:"truncate",size:"sm",children:i??(e==null?void 0:e.name)}),a]})]})})),Xo=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)},Br=c.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:i,helpText:a,showInputOnly:s,field:l,fieldProps:m},u]=K(t),{name:f,onChange:h,onBlur:g}=m;let[{label:C}]=K(t);C=s?"":C;const w=m.value??Yt,p=c.useRef(null),b=c.useMemo(()=>s?null:a||(l.maxFileSize?`Maximum file size: ${l.maxFileSize}MB`:null),[l.maxFileSize,a,s]),I=c.useCallback(()=>{var D;(D=p.current)==null||D.click()},[]),x=c.useCallback(()=>{if(!p.current)return;const D=p.current.files;if(!D){g([]);return}const M=Array.from(D),O=[...w,...M];h(O),g(O)},[g,h,w]),y=c.useCallback(D=>{const M=[...w];M.splice(D,1),h(M.length>0?M:void 0)},[w,h]);c.useEffect(()=>{if(!p.current)return;const D=new AbortController;return p.current.addEventListener("cancel",()=>{g(void 0)},{signal:D.signal}),()=>{D.abort()}},[g,w]);const T=w?"Select new files":"Select files",S=w?"Select new file":"Select a file",L=l.maxFiles>1?T:S;return o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx(J,{helpText:b,severity:i,children:o.jsxs(Y,{size:r,severity:i,inputId:n,labelId:e,label:C,image:s?void 0:l.image,children:[o.jsx("div",{className:"flex gap-2",children:o.jsxs(d.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:I,id:"upload-input-upload-button",type:"button",...u,children:[o.jsx(d.RiIcon,{icon:"RiUpload2Line"})," ",L]})}),o.jsx("input",{id:n,name:f,type:"file",ref:p,accept:(F=l.extensions)==null?void 0:F.join(","),multiple:l.maxFiles>1,className:"hidden",onChange:x,value:""})]})}),Array.isArray(w)&&w.length>0&&o.jsx("div",{className:"flex h-max flex-col gap-2",children:w.map((D,M)=>o.jsx(zr,{field:l,file:D,onRemove:()=>{y(M)},disabled:u.disabled},M))})]})});Br.displayName="UploadInput";const zr=c.memo(t=>{const{file:n,field:e,onRemove:r,disabled:i}=t,[a,s]=c.useState(null),l=We(),m=c.useMemo(()=>a&&e.getError([a]),[e,a]),{url:u,name:f}=c.useMemo(()=>{let p=null,b,I;return a!=null&&a.type.startsWith("image/")&&(p=URL.createObjectURL(a)),a?(b=a.name,I=Xo(a.size)):(b="Downloading...",I="..."),{url:p,name:b,size:I}},[a]);c.useEffect(()=>{n instanceof Promise?n.then(s).catch(console.error):s(n)},[n]);const h=c.useCallback(p=>{if(p.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const b=new Blob([a]);qt.saveAs(b,f)},[f,a]),g=c.useCallback(p=>{p.stopPropagation(),r()},[r]),C=c.useCallback(()=>{a&&l(p=>({file:a,onDelete:i?void 0:()=>{r(),p()}}))},[i,r,l,a]),w=c.useMemo(()=>o.jsxs(d.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[o.jsx(d.IconButton,{"aria-label":`Download ${f}`,type:"button",onClick:h,disabled:!a,children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})}),!i&&o.jsx(d.IconButton,{type:"button","aria-label":`Remove ${f}`,disabled:i,onClick:g,children:o.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[i,g,h,f,a]);return u?o.jsx(Or,{className:"cursor-pointer",onClick:C,file:a,error:m??void 0,rightSlot:w}):o.jsx(It,{file:a,error:m??void 0,rightSlot:w})});zr.displayName="DisplayFile";const Ko={...X,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1};function _r(t,n){return t.name===n.name&&t.size===n.size&&t.type===n.type}const Ae=class Ae extends j{constructor(e){const{extensions:r,maximum_files:i,maximum_size:a,...s}=e;super({...s,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 i=="number"?i:1,1),this.extensions=r}isBlank(e){return super.isBlank(e)||(e==null?void 0:e.length)===0}isEqual(e,r){return e===void 0&&r===void 0?!0:!(e===void 0||r===void 0||!e.every(i=>r.some(a=>_r(i,a)))||!r.every(i=>e.some(a=>_r(a,i))))}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({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 se({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${ht}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:ht,integers:!0}),showDirectly:!1},{field:new Ve({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??ht,i=r*1e3*1e3,a=this.maxFiles||1;return e.push(s=>{if(s&&s.some(l=>l.size>i))return`Files must be at most ${r}MB.`}),e.push(s=>{if(s&&s.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 Ae(e)}getInput(e){return o.jsx(Br,{field:this,...e})}};N(Ae,"fieldTypeName","Upload"),N(Ae,"fieldTypeDescription","Allows a file to be uploaded."),N(Ae,"Icon",H.RiUpload2Line);let cn=Ae;const dn={date:rt,number:se,boolean:Ee,select:Ue,string:ut,text:ft,custom:it,upload:cn,qr:ct,"multi-string":_e,"multi-select":Ve},Qo={date:yr,number:Sr,boolean:vr,select:Dr,string:Pr,text:Ar,custom:Uo,upload:Ko,qr:Nr,"multi-string":Er,"multi-select":Lr},ht=50,Yo=ht*1e3*1e3,un=t=>{const n=t.type;return dn[n].deserialize(t)},pt=t=>t.type==="section"?W.deserialize(t):un(t);function Vr(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>pt(r)),meta:{readonly:e}}}function mt(t){const n=[];for(const e of t.fields)if(e instanceof W)for(const r of e.fields)n.push(r);else{if(!(e instanceof j))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Ur(t){const n=mt(t),e={};for(const r of n)e[r.identifier]=r;return e}function Jo(t,n){const e=mt(t),r={};for(const i of e){const a=n[i.identifier]??null;a!==null?r[i.identifier]=i.decodeJsonToValue(a):r[i.identifier]=a}return r}function Zo(t,n){const e=mt(t),r={};for(const i of e){const a=n[i.identifier];r[i.identifier]=i.encodeValueToJson(a)}return r}function gt(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function fn(t,n){if(!t)return!0;if(gt(n)||gt(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(i=>typeof i=="string"?i:i.value):n,r=Array.isArray(t.value)?t.value.map(i=>typeof i=="string"?i:i.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const i of r)if(!e.includes(i))return!1;return!0}return r===n}const $r=c.memo(t=>{const{field:n,...e}=t,{label:r,description:i,fields:a,condition:s}=n,{values:l,setFieldValue:m}=k.useFormikContext(),u=s!=null&&s.identifier?R(l,s.identifier):void 0,f=c.useMemo(()=>u===void 0||fn(s,u),[s,u]);c.useEffect(()=>{if(!f)for(const g of a)m(g.getId(),"").then()},[f,a,m]);const h=ze(a,e);return f?o.jsx(d.Card,{variant:"soft",children:o.jsxs("div",{className:"flex flex-col gap-4",children:[(r||i)&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex flex-col",children:[o.jsx(d.Heading,{size:"md",children:r}),o.jsx(d.Text,{accentColor:"base",children:i})]}),o.jsx(d.Separator,{size:"full"})]}),h]})}):null});$r.displayName="FieldSectionLayout";const Oe=class Oe extends xt{constructor(e){const{label:r=null,fields:i,condition:a=null,conditional:s,...l}=e;super({...l,type:"section"});N(this,"label");N(this,"fields");N(this,"condition");this.fields=i,this.condition=a,this.label=r,s===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const i=r&&`${r}.`;return[{field:new Ee({label:"Conditionally render section",identifier:`${i}conditional`,required:!1}),showDirectly:!0},{field:new Oe({label:"Conditional settings",identifier:`${i}conditional-settings`,condition:{identifier:`${i}conditional`,value:!0},fields:[new Ue({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:`${i}condition.identifier`,required:!0}),new $o({label:"Value",identifier:`${i}condition.value`,required:!0,clonedFieldIdentifier:`${i}condition.identifier`,getFieldToClone(a){if(!a)return null;const s=e.find(l=>l.identifier===a);return s?{...s,label:"Value",identifier:`${i}condition.value`,description:"The value to compare against.",required:s.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(un);return new Oe({...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 i of this.fields){const a=i.getId(),s=i.getError(R(e,a),e);s&&$e(r,i.getId(),s)}return r}getInput(e){return o.jsx($r,{field:this,...e})}};N(Oe,"fieldTypeName","Section"),N(Oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let W=Oe;const ge=t=>Object.keys(t).length>0,vt=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof W){if(r.condition){const{identifier:i}=r.condition;if(!fn(r.condition,R(n,i)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof j))throw new Error("Invalid field type");const i=r.getId(),a=r.getError(R(n,i),n);a&&$e(e,i,a)}if(ge(e))return e},yt=(t,n)=>t.reduce((e,r)=>{if(r instanceof W)return{...e,...yt(r.fields,n)};const i=r.getId();return $e(e,i,e[i]??void 0),e},ti(n)),kr=(t,n,e)=>t.reduce((r,i)=>{if(i instanceof W)return{...r,...kr(i.fields,n,e)};if(i instanceof j){const a=i.getId(),s=n[a],l=e[a];i.isEqual(s,l)||$e(r,a,l)}return r},{}),jr=c.memo(c.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:i,onSubmit:a,submitText:s="Submit",cancelText:l,onCancel:m,onDirty:u,onDirtyChange:f,hideTitle:h=!e.title,hideDescription:g,className:C,buttonProps:w,enableReinitialize:p=!1,excludeUnchangedFields:b=!1}=t,{readonly:I}=e.meta,x=c.useId(),y=c.useMemo(()=>yt(e.fields,r),[e.fields,r]),T=c.useCallback(_=>{a==null||a(b?kr(e.fields,y,_):_)},[b,y,a,e.fields]),S=k.useFormik({initialValues:y,onSubmit:T,validate:_=>vt(e,_),validateOnBlur:!1,validateOnChange:!1,enableReinitialize:p}),{dirty:L}=S,F=c.useMemo(()=>typeof e.title=="string"?o.jsx(d.Heading,{size:"md",children:e.title}):e.title,[e.title]),D=c.useMemo(()=>typeof e.description=="string"?o.jsx(d.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),M=c.useCallback((_,U)=>{Ur(e)[_].isEqual(y[_],U)||i==null||i({...S.values,[_]:U},{[_]:U})},[S.values,y,i,e]),O=ze(e.fields,{formId:x,disabled:I,onValuesChange:M});return c.useEffect(()=>{L&&u&&u(),f&&f(L)},[L,u,f]),o.jsx(k.FormikProvider,{value:S,children:o.jsxs("form",{id:x,ref:n,className:ye(C,"flex flex-col gap-2"),onSubmit:S.handleSubmit,children:[!h&&o.jsx(d.Card,{variant:"soft",children:o.jsxs("div",{className:"flex flex-col gap-1",children:[F,!g&&D]})}),O,!I&&o.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&o.jsxs(d.Button,{accentColor:ue.danger,...w,type:"button",onClick:m,children:[o.jsx(d.RiIcon,{icon:"RiCloseLine"}),l]}),o.jsxs(d.Button,{...w,type:"submit",disabled:!S.isValid,accentColor:"success",children:[o.jsx(d.RiIcon,{icon:"RiCheckLine"}),s]})]})]})})})),ve=c.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=k.useFormikContext(),[i,a,s]=k.useField(n),l=c.useMemo(()=>{const m=u=>{s.setValue(u,!1)};return e({value:i.value,meta:a,setValue:m,patchValue:()=>{r()}})},[e,i.value,a,r,s]);return o.jsx(o.Fragment,{children:l})});ve.displayName="PatchField";const Ro=c.memo(c.forwardRef((t,n)=>{const{children:e,schema:r,values:i,onPatch:a,onError:s,requiresDiff:l=!0,onDirtyChange:m,...u}=t,f=c.useMemo(()=>yt(r.fields,i),[r.fields,i]),h=c.useCallback(x=>{const y={};for(const T in x){const S=x[T];S!==f[T]&&S!==void 0&&(y[T]=S)}return y},[f]),g=c.useCallback(x=>{const y=h(x);l&&!ge(y)||a(y)},[h,a,l]),C=c.useCallback(x=>{const y=vt(r,x);if(y&&s(y),m){const T=h(x);m(ge(T))}return y},[r,m,s,h]),w=k.useFormik({initialValues:f,onSubmit:g,validate:C,validateOnBlur:!1,validateOnChange:!1}),p=c.useCallback(()=>{if(m){const x=h(w.values);ge(x)&&m(!0)}},[w.values,h,m]),{errors:b,resetForm:I}=w;return c.useEffect(()=>{ge(b)&&I({values:f,errors:{}})},[b,f,I]),o.jsx(k.FormikProvider,{value:w,children:o.jsx("form",{...u,ref:n,onSubmit:w.handleSubmit,onChange:p,children:e})})})),bt="form-builder",ea=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],hn={...dn,section:W},Ct=c.createContext({}),ta=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const i in e)e[i].disabled=!1;return e;case"hold":for(const i in e)(r=e[i])!=null&&r.conditionFields.has(n.fieldId)&&(e[i].disabled=!0);return e;case"update":return n.state}},na=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const i of r.fields)if(i.identifier===n)return e}}},Wr=t=>{var e,r,i;const n={};for(let a=0;a<t.length;a++){const s=t[a];if(!s)throw new Error("Field is undefined.");const l=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,m=new Set(l);(r=s.condition)!=null&&r.identifier&&m.add(s.condition.identifier),n[s.identifier]={disabled:!1,conditionFields:m,conditionIndex:na(t,(i=s.condition)==null?void 0:i.identifier),index:a,label:s.label}}return n},pn=c.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:i,duplicate:a,move:s,upload:l}=t;if(e!=="section"&&!l)throw new Error("Upload function prop must be defined for non-section fields.");const{values:m}=k.useFormikContext(),u=c.useRef(null),f=c.useMemo(()=>{const h=[{Icon:H.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:H.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:i}}),e!=="section"&&h.unshift({Icon:H.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=u.current)==null||g.click()}}}),(r===void 0&&n!==m.fields.length-1||r!==void 0&&(r<m.fields.length-1||n!==m.fields[r].fields.length-1))&&h.unshift({Icon:H.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{s("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:H.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{s("up")}}}),h},[a,n,s,i,r,e,m.fields]);return o.jsxs(o.Fragment,{children:[o.jsx(d.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:f.map(h=>o.jsx(d.IconButton,{type:"button","aria-label":h.text,...h.buttonProps,children:o.jsx(h.Icon,{})},h.key))}),o.jsx("div",{className:"sm:hidden",children:o.jsxs(d.Menu.Root,{children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsx(d.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:o.jsx(d.RiIcon,{icon:"RiMore2Line"})})}),o.jsx(d.Menu.Content,{children:f.map(h=>{var g;return o.jsxs(d.Menu.Item,{onClick:(g=h.buttonProps)==null?void 0:g.onClick,children:[o.jsx(h.Icon,{}),h.text]},h.key)})})]})}),e!=="section"&&o.jsx("input",{style:{display:"none"},ref:u,type:"file",accept:"image/*",onChange:l})]})});pn.displayName="FieldActions";const mn=c.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return o.jsxs(d.Popover.Root,{children:[o.jsx(d.Popover.Trigger,{asChild:!0,children:o.jsxs(d.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:ue.danger},children:[o.jsx(d.RiIcon,{icon:"RiSettings2Line"}),o.jsx("span",{children:"Settings"})]},"settings")}),o.jsx(d.Popover.Content,{size:"sm",...r,children:o.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});mn.displayName="FieldSettingsPopover";const qr=(t=()=>null)=>c.useMemo(()=>ea.map(n=>n.map(e=>{const r=dn[e],i=r.Icon;return{children:r.fieldTypeName,icon:o.jsx(i,{}),value:e,onSelect:()=>{t(e)}}})),[t]),Hr=576,gn=c.memo(t=>{var Be,vn,Jr,Zr,Rr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:i}=t,{values:a,setFieldValue:s,errors:l}=k.useFormikContext(),m=qr(),u=We(),{disableRequiredFields:f}=c.use(Ct),h=c.useRef(null),[g,C]=c.useState(h.current&&h.current.getBoundingClientRect().width>=Hr);c.useEffect(()=>{const P=h.current;if(P){const z=new ResizeObserver(G=>{G[0]&&C(G[0].contentRect.width>=Hr)});return z.observe(P),()=>{z.disconnect()}}},[]);const[w,p]=c.useState(void 0);c.useEffect(()=>{me(r)?p(void 0):r.image instanceof Promise?r.image.then(p).catch(console.error):p(r.image)},[r]);const b=w?URL.createObjectURL(w):void 0,I=c.useCallback(P=>{P.stopPropagation();const{image:z,...G}=r;s(`${n}.${e}`,G).then()},[e,r,n,s]);c.useEffect(()=>{me(r)&&!r.conditional&&s(`${n}.${e}.condition`,null).then()},[e,r,n,s]);const x=c.useMemo(()=>{var P,z;return me(r)?(z=Ir(a.fields,(P=r.condition)==null?void 0:P.identifier))==null?void 0:z.label:void 0},[r,a.fields]),y=me(r)?Array.isArray((Be=r.condition)==null?void 0:Be.value)?"contains all of":"equals":void 0;let T;if(me(r)){if(gt((vn=r.condition)==null?void 0:vn.value))throw new Error("File values are not supported for conditions.");T=Array.isArray((Jr=r.condition)==null?void 0:Jr.value)?r.condition.value.map(P=>typeof P=="string"?P:P.label).join(", "):(Rr=(Zr=r.condition)==null?void 0:Zr.value)==null?void 0:Rr.toString()}const S=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),L=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),F=r.type,D=hn[F],[M,O]=c.useMemo(()=>{let P=[],z=[];if(D===W){if(i===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const G=D.getFieldCreationSchema(i,`${n}.${e}`);P=P.concat(G.filter($=>$.showDirectly).map($=>$.field)),z=z.concat(G.filter($=>!$.showDirectly).map($=>$.field))}else{if(!(D.prototype instanceof j))throw new Error(`Field must be an instance of BaseField. Got ${D.toString()}.`);const G=D.getFieldCreationSchema(`${n}.${e}`);g?(P=[...P,...G.filter($=>$.showDirectly).map($=>$.field)],z=[...z,...G.filter($=>!$.showDirectly).map($=>$.field)]):z=[...z,...G.map($=>$.field)]}return[P,z]},[D,i,n,e,g]),_=ze(M,{formId:bt,disabled:!1,...D===W&&{size:"sm"}}),U=ze(O,{formId:bt,disabled:!1});let B=O.length>0;me(r)&&O.length>0&&(B=r.conditional);const Z=O.some(P=>{const z=R(l,D===W?`${n}.${e}.condition`:P.getId());return z&&(typeof z!="object"||ge(z))}),A=Z?ue.danger:void 0,q=c.useMemo(()=>pt(r),[r]),le=Qt(q,{formId:bt,showInputOnly:!1}),ne=c.useMemo(()=>m.flat().find(P=>P.value===F),[m,F]),ce=c.useCallback(()=>{w&&u(()=>({file:w}))},[u,w]);return o.jsx("div",{className:"flex grow items-center w-full",ref:h,children:o.jsxs("div",{className:"flex w-full flex-col gap-2",children:[D===W&&(M.length>0||B)&&o.jsxs("div",{className:"flex flex-col gap-2",children:[_,B&&o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(mn,{popoverInputs:U,hasError:Z,align:"start"}),me(r)&&r.conditional&&o.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":A,children:o.jsxs("em",{children:["Display only if ",o.jsx("strong",{children:x})," ",y," ",o.jsx("strong",{children:T})]})})]})]}),D!==W&&o.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[o.jsxs("div",{className:"flex gap-2 items-center",children:[o.jsxs(d.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[ne==null?void 0:ne.icon,ne==null?void 0:ne.children]}),!f&&o.jsx(ve,{name:`${n}.${e}.required`,render:({setValue:P,value:z})=>o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.Checkbox.Root,{checked:z,onCheckedChange:P,size:"sm",children:o.jsx(d.Checkbox.Indicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})})}),o.jsx(d.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),B&&o.jsx(mn,{popoverInputs:U,hasError:Z,align:"end"})]}),w&&o.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[o.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:b,alt:w.name,onClick:ce}),o.jsx(d.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:"base","aria-label":"delete",onClick:I,size:"sm",children:o.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),o.jsx(ve,{name:`${n}.${e}.label`,render:({setValue:P,value:z})=>o.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:F==="section"?"Enter a section label (optional)":"Enter your question",value:z,onChange:G=>{P(G.target.value)},onInput:S,maxLength:200})}),o.jsx(ve,{name:`${n}.${e}.description`,render:({setValue:P,value:z})=>o.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${F==="section"?"section":"field"} description (optional)`,value:z,onChange:G=>{P(G.target.value)},onInput:L,maxLength:1e3})}),D!==W&&M.length>0&&o.jsx("div",{className:"w-full",children:_}),D!==W&&o.jsxs(d.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[o.jsxs(d.HoverCard.Root,{children:[o.jsx(d.HoverCard.Trigger,{asChild:!0,children:o.jsx(d.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:o.jsx(d.RiIcon,{icon:"RiEyeLine"})})}),o.jsx(d.HoverCard.Content,{className:"w-[225px]",size:"sm",align:"start",children:"This is a preview of the field as it will be rendered in the form."})]}),o.jsx("div",{className:"grow h-max",children:le})]})]})})});gn.displayName="FieldBuilder";const Gr=c.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:i}=t,{setFieldValue:a,values:s}=k.useFormikContext(),{reorderField:l}=Rt(),{showInfo:m,showError:u}=d.useToast(),f=`fields.${r}.fields`,h=c.useMemo(()=>({index:e,parentPath:f,initial:n}),[n,e,f]),g=c.useCallback(()=>{const p=n.label||"Unlabelled field",b={...n,label:p};lt(f,e+1,b,s,a),m({title:"Field duplicated",description:`The field "${p}" has been duplicated`})},[n,f,e,s,a,m]),C=c.useCallback(p=>{const b=r,I=s.fields[b];let x=r,y=p==="up"?e-1:e+1;p==="up"&&e===0?(x=r-1,y=s.fields[x].fields.length):p==="down"&&e===I.fields.length-1&&(x=r+1,y=0);const T=s.fields[x];l(I,b,e,T,x,y,a)},[r,s.fields,e,l,a]),w=c.useCallback(p=>{const{files:b}=p.target;if(!b||b.length!==1)return;const I=b.item(0);if(I){if(I.size>Yo){u({title:"File upload error",description:`The file ${I.name} exceeded the maximum file size`});return}a(`${f}.${e}`,{...n,image:I}).then()}},[n,e,f,a,u]);return o.jsx(ie.Draggable,{draggableId:n.identifier,index:e,children:p=>o.jsx(d.Card,{ref:p.innerRef,...p.draggableProps,...p.dragHandleProps,className:"mb-4",children:o.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[o.jsx(gn,{...h}),o.jsx(pn,{index:e,type:n.type,sectionIndex:r,remove:i,duplicate:g,move:C,upload:w})]})})})});Gr.displayName="FieldWithActions";const Xr=c.memo(t=>{var T;const{field:n,index:e,dropState:r}=t,i=(T=r[n.identifier])==null?void 0:T.disabled,{setFieldValue:a,values:s}=k.useFormikContext(),l=d.useAlertDialog(),{reorderSection:m}=Rt(),{showInfo:u}=d.useToast(),{fieldsOnly:f}=c.use(Ct),h=c.useCallback((S,L)=>{for(const F of S){const D=L.indexOf(F);a(`fields.${D}.condition`,null).then(),a(`fields.${D}.conditional`,!1).then()}},[a]),g=c.useCallback(S=>{var D;const L=n.fields[S];if(!L)throw new Error("Could not find field to remove.");const F=[];for(const M of s.fields)((D=M.condition)==null?void 0:D.identifier)===L.identifier&&F.push(M);return{removing:L,affectedSections:F,action:()=>a(`fields.${e}.fields`,st(n.fields,S))}},[n.fields,s.fields,a,e]),C=c.useCallback(S=>{const{affectedSections:L,action:F,removing:D}=g(S),M=()=>{F().then(),h(L,s.fields)};if(L.length>0){const O=L.map(_=>_.label).join(", ");l({title:"Remove condition?",description:`${D.label} is being used as a condition, deleting it will remove the condition from the ${O} section(s).`,action:"Remove",onAction:M});return}M()},[g,h,s.fields,l]),w=c.useCallback(()=>{const L=n.fields.map((B,Z)=>g(Z)).flatMap(B=>B.affectedSections),F=L.length?"Remove fields and conditions?":"Remove fields?",D=n.fields.length,M=L.map(B=>B.label).join(", "),O=L.length?`Deleting this section will remove the ${D} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${D} field(s) it contains.`,_=st(s.fields,e),U=()=>a("fields",_);if(L.length>0){l({title:F,description:O,action:"Remove",onAction:()=>{U().then(()=>{h(L,_)})}});return}U().then()},[n.fields,s.fields,e,g,a,l,h]),p=c.useCallback(S=>{const L=S==="up"?e-1:e+1;m(r,n.identifier,e,L,s,a)},[e,m,r,n.identifier,s,a]),b=c.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:xr(s.fields,e)}),[n,e,s.fields]),I=c.useCallback(()=>{const S=n.label||"Untitled section",L=n.fields.map(D=>({...D,identifier:Zt()})),F={...n,label:S,fields:L};lt("fields",e+1,F,s,a),u({title:"Section duplicated",description:`The section "${S}" has been duplicated.`})},[n,e,s,a,u]),x=c.useCallback(S=>{lt(`fields.${e}.fields`,n.fields.length,Qo[S],s,a)},[e,n.fields.length,s,a]),y=qr(x);return o.jsx(ie.Draggable,{draggableId:n.identifier,index:e,children:S=>o.jsx(d.Card,{ref:S.innerRef,...S.draggableProps,...S.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:o.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[o.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!f&&o.jsx(gn,{...b}),o.jsx(ie.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:i,children:L=>o.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:L.innerRef,...L.droppableProps,children:[n.fields.map((F,D)=>o.jsx(Gr,{field:F,index:D,sectionIndex:e,remove:()=>{C(D)}},F.identifier)),L.placeholder,o.jsxs(d.Menu.Root,{children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add field"]})}),o.jsx(d.Menu.Content,{children:y.flat().map(F=>o.jsxs(d.Menu.Item,{onSelect:F.onSelect,children:[F.icon,F.children]},F.value))})]})]})})]}),!f&&o.jsx(pn,{index:e,type:n.type,remove:w,duplicate:I,move:p})]})})})});Xr.displayName="FieldSectionWithActions";const Kr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Qr=c.memo(()=>{const{values:t,setFieldValue:n}=k.useFormikContext(),[e,r]=c.useReducer(ta,t.fields,Wr),{reorderSection:i,reorderField:a}=Rt(),{fieldsOnly:s}=c.use(Ct);c.useEffect(()=>{r({type:"update",state:Wr(t.fields)})},[r,t.fields]);const l=c.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),m=c.useCallback(f=>{const{source:h,destination:g,type:C,reason:w,draggableId:p}=f;if(r({type:"release"}),!g||w==="CANCEL")return;if(C==="ROOT"){i(e,p,h.index,g.index,t,n);return}if(C!=="SECTION")throw new Error("Unexpected droppable type.");const[b,I]=Kr(t.fields,h.droppableId)??[],[x,y]=Kr(t.fields,g.droppableId)??[];a(b,I,h.index,x,y,g.index,n)},[t,a,n,i,e]),u=c.useCallback(f=>{Go(f+1,t,n)},[t,n]);return o.jsx(ie.DragDropContext,{onDragStart:l,onDragEnd:m,children:o.jsx(ie.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>o.jsxs("div",{className:"flex flex-col gap-0",ref:f.innerRef,...f.droppableProps,children:[t.fields.map((h,g)=>o.jsxs(c.Fragment,{children:[o.jsx(Xr,{field:h,index:g,dropState:e,fieldsOnly:s}),!s&&g!==t.fields.length-1&&o.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{u(g)},children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]})]},h.identifier)),o.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{u(t.fields.length)},children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]}),f.placeholder]})})})});Qr.displayName="FieldsEditor";const ra=c.memo(c.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:i,initialTitle:a,showExplainerText:s=!0,showFormTitle:l=!0,fieldsOnly:m=!1,showTabs:u=!0,disableRequiredFields:f=!1,tabsListClassName:h,hydrateRevisionWithImages:g}=t,{showError:C}=d.useToast(),w=c.useCallback(T=>{const S={};T.title||(S.title="Title is required."),(!T.fields||T.fields.length===0)&&(S.fields="At least one field is required.");let L=[];for(const[D,M]of T.fields.entries()){const _=hn.section.getFieldCreationSchema(xr(T.fields,D),`fields.${D}`).map(U=>U.field);L=[...L,..._];for(const[U,B]of M.fields.entries()){const A=hn[B.type].getFieldCreationSchema(`fields.${D}.fields.${U}`).map(q=>q.field);L=[...L,...A]}}const F=vt({fields:L},T);if(F&&(S.fields=F.fields),ge(S))return C({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),S},[C]),p=c.useMemo(()=>({title:a??"",description:"",fields:[{...at(Zt()),label:""}]}),[a]),b=i?g(i):void 0,I=k.useFormik({initialValues:Ho(b)??p,validate:w,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),x=c.useMemo(()=>Vr(I.values),[I.values]),y=c.useMemo(()=>({disableRequiredFields:f,fieldsOnly:m}),[f,m]);return o.jsx(Ct,{value:y,children:o.jsx(d.Tabs.Root,{ref:n,defaultValue:"edit",children:o.jsxs("div",{className:"flex flex-col gap-2",children:[u&&o.jsxs(d.Tabs.List,{className:ye("sticky top-0 z-[2000] flex bg-(--color-background)",h),children:[o.jsx(d.Tabs.Trigger,{className:"grow",value:"edit",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),o.jsx(d.Tabs.Trigger,{className:"grow",value:"preview",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),o.jsxs(d.Tabs.Content,{value:"edit",children:[s&&o.jsxs(d.Text,{children:["Create your form using various field types. Sections can be"," ",o.jsx("strong",{children:"conditionally rendered"})," based on"," ",o.jsx("strong",{children:"answers to fields in preceding sections. "})]}),o.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:bt,onSubmit:I.handleSubmit,children:[o.jsxs(k.FormikProvider,{value:I,children:[l&&o.jsxs(o.Fragment,{children:[o.jsx(ve,{name:"title",render:({setValue:T,value:S,meta:L})=>o.jsx(Gt,{severity:"danger",helpText:L.error??null,children:o.jsx(d.Input.Root,{variant:"outline",size:"md",accentColor:L.error?ue.danger:"primary",children:o.jsx(d.Input.Field,{placeholder:"Form title",value:S,onChange:F=>{T(F.target.value)},maxLength:100})})})}),o.jsx(ve,{name:"description",render:({setValue:T,value:S})=>o.jsx(d.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:S,onChange:L=>{T(L.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),o.jsx(Qr,{}),o.jsx("span",{"data-accent-color":ue.danger,className:"text-xs text-(--accent-a11)",children:typeof I.errors.fields=="string"&&I.errors.fields})]}),o.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&o.jsx(d.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),o.jsx(d.Button,{type:"submit",children:"Save form"})]})]})]}),o.jsx(d.Tabs.Content,{value:"preview",children:o.jsx(jr,{schema:x,hideTitle:!l})})]})})})})),ia=Object.values(de.Colors),oa=1;async function aa(t,n,e,r){const i=t.getContext("2d",{}),a=new Image(r.width,r.height),s=new Image(r.width,r.height),l=new de.DeferredPromise;return a.onload=function(){i.drawImage(a,0,0,r.width,r.height),s.src=URL.createObjectURL(e),s.onload=async function(){i.drawImage(s,0,0,r.width,r.height);const m=t.toDataURL("image/jpeg",oa),u=await de.fileToBlob(m),f=new File([u],n.name,{type:"image/jpeg"});l.resolve(f)}},a.src=URL.createObjectURL(n),l}const Yr=c.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:i,dirty:a,onDirty:s}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const l=c.useRef(null),m=c.useRef(null),[u,f]=c.useState(de.Colors.red),[h,g]=c.useState(null),[C,w]=c.useState(!1),[p,b]=c.useState(!1),I=c.useRef(null),x=d.useSize(I);c.useEffect(()=>{const B=new Image;B.onload=function(){g({width:B.naturalWidth,height:B.naturalHeight})},B.src=URL.createObjectURL(n)},[n]),c.useEffect(()=>{!p&&(x!=null&&x.width)&&x.height&&b(!0)},[x,p]);const y=c.useCallback(async()=>{a||e();const B=l.current;if(!B)return;if(!h)throw new Error("Original image size not loaded yet");const Z=await B.exportImage("png"),A=new Image(h.width,h.height);A.onload=async function(){const q=await de.fileToBlob(Z),le=new File([q],n.name,{type:n.type}),ne=m.current,ce=await aa(ne,n,le,h);ce.objectURL=URL.createObjectURL(ce);const Be=await de.hashFile(n);await de.hashFile(ce)!==Be&&r(ce),w(!1),e()},w(!0),A.src=Z},[a,n,e,r,h]),T=c.useCallback(()=>{i(n)},[n,i]),S=c.useCallback(()=>{e()},[e]),L=c.useCallback(()=>{s(!0)},[s]),F=c.useCallback(()=>{l.current&&l.current.redo()},[]),D=c.useCallback(()=>{l.current&&l.current.undo()},[]),M=c.useCallback(()=>{l.current&&(s(!1),l.current.clearCanvas())},[s]),O=c.useCallback(B=>{l.current&&l.current.eraseMode(B)},[]),_=c.useCallback(()=>{y()},[y]),U=c.useCallback(()=>{qt.saveAs(n,n.name)},[n]);return o.jsx($t,{open:!0,onOpenChange:e,children:o.jsxs(kt,{children:[o.jsx(jt,{className:"bg-(--color-background) fixed inset-0 data-[state='open']:fade-in-0 data-[state='open']:zoom-in-95 data-[state='closed']:animate-out data-[state='closed']:fade-out-0 data-[state='closed']:zoom-out-95 data-[state='open']:animate-in","data-floating-content":""}),o.jsxs(Wt,{className:"absolute inset-0 py-12","data-floating-content":"",children:[o.jsx(d.ButtonGroup,{className:"flex w-full gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",size:"md",variant:"soft",children:o.jsxs("div",{className:"grid w-full grid-cols-3",children:[o.jsxs("div",{className:"flex gap-2",children:[o.jsx(d.IconButton,{"aria-label":"close",onClick:S,children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})}),o.jsx(d.IconButton,{"aria-label":`Download ${n.name}`,onClick:U,children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})})]}),o.jsxs("div",{className:"flex items-center justify-center gap-2",children:[o.jsx(wt,{selectedColor:u,allColors:ia,onFinish:f,trigger:o.jsx(d.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:u},children:" "})}),o.jsx(d.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:O,children:o.jsx(d.RiIcon,{icon:"RiEraserFill"})}),o.jsx(d.Separator,{orientation:"vertical",size:"full"}),o.jsx(d.IconButton,{"aria-label":"undo",onClick:D,children:o.jsx(d.RiIcon,{icon:"RiArrowGoBackLine"})}),o.jsx(d.IconButton,{"aria-label":"undo",onClick:F,children:o.jsx(d.RiIcon,{icon:"RiArrowGoForwardLine"})}),o.jsx(d.IconButton,{"aria-label":"undo all",onClick:M,children:o.jsx(d.RiIcon,{icon:"RiLoopLeftLine"})})]}),o.jsxs("div",{className:"flex justify-end gap-2",children:[o.jsx(d.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:_,children:o.jsx(d.RiIcon,{icon:"RiSaveLine"})}),o.jsx(d.IconButton,{"aria-label":"Delete attachment",onClick:T,children:o.jsx(d.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})}),h&&o.jsx("canvas",{id:"attachment-markup-canvas",className:"hidden",ref:m,width:h.width,height:h.height}),o.jsxs("div",{className:"relative size-full flex items-center justify-center p-4 overflow-hidden",children:[o.jsx("img",{className:"max-w-full max-h-full invisible absolute",alt:"Photo attachment",ref:I,src:n.objectURL}),C?o.jsx(d.Spinner,{}):o.jsx(ni.ReactSketchCanvas,{className:"max-w-full max-h-full aspect-square",backgroundImage:n.objectURL,ref:l,onStroke:L,strokeColor:u},p?"1":"0")]})]})]})})});Yr.displayName="AttachmentEditor",E.BaseField=j,E.BaseFormElement=xt,E.BooleanField=Ee,E.BooleanInput=Xt,E.ColorPicker=wt,E.DateField=rt,E.DateInput=Kt,E.FieldSection=W,E.FileCard=It,E.FileIcon=ke,E.FormBuilder=ra,E.FormRenderer=jr,E.ImageCard=Or,E.ImageMarkup=Yr,E.ImageViewer=Ht,E.ImageViewerProvider=gr,E.InputWithHelpText=Gt,E.InputWithLabel=Y,E.InputWithLabelAndHelpText=J,E.MultiSelectField=Ve,E.MultiSelectInput=on,E.MultiStringField=_e,E.MultiStringInput=en,E.NumberField=se,E.NumberInput=tn,E.PatchField=ve,E.PatchFormProvider=Ro,E.QrField=ct,E.QrInput=nn,E.QrScanner=rn,E.SUPPORTED_IMAGE_FILE_TYPES=wn,E.SUPPORTED_PDF_FILE_TYPES=xn,E.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=In,E.SelectField=Ue,E.SelectInput=an,E.StringField=ut,E.StringInput=sn,E.TextField=ft,E.TextInput=ln,E.decodeFormValues=Jo,E.deserialize=pt,E.deserializeField=un,E.emptyBaseField=X,E.emptyBooleanField=vr,E.emptyDateField=yr,E.emptyMultiSelectField=Lr,E.emptyMultiStringField=Er,E.emptyNumberField=Sr,E.emptyQrField=Nr,E.emptySelectField=Dr,E.emptyStringField=Pr,E.emptyTextField=Ar,E.encodeFormValues=Zo,E.fieldIcons=oi,E.flattenFields=mt,E.formRevisionToSchema=Vr,E.getFieldsMapping=Ur,E.initialFormValues=yt,E.isConditionMet=fn,E.useFieldInput=Qt,E.useFieldInputs=ze,E.useFormikInput=K,E.useImageViewer=We,E.validateForm=vt,E.valueIsFile=gt,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|