@overmap-ai/forms 1.0.18 → 1.0.19
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
|
@@ -2514,9 +2514,9 @@ const Ki = P((t) => {
|
|
|
2514
2514
|
onDecodeResult: i,
|
|
2515
2515
|
onError: r
|
|
2516
2516
|
});
|
|
2517
|
-
return /* @__PURE__ */ E("div", { className: "relative flex h-full w-full flex-col justify-center gap-
|
|
2518
|
-
/* @__PURE__ */ l("div", { className: "
|
|
2519
|
-
/* @__PURE__ */ l("div", { className: "relative
|
|
2517
|
+
return /* @__PURE__ */ E("div", { className: "relative flex h-full w-full flex-col justify-center overflow-hidden p-4 gap-4 bg-(--color-background)", children: [
|
|
2518
|
+
/* @__PURE__ */ l("div", { className: "flex w-full", children: /* @__PURE__ */ l(_i, { asChild: !0, children: /* @__PURE__ */ l(J, { "aria-label": "close", variant: "soft", accentColor: "base", children: /* @__PURE__ */ l(L, { icon: "RiCloseLine" }) }) }) }),
|
|
2519
|
+
/* @__PURE__ */ l("div", { className: "relative grow w-full max-h-full overflow-hidden", children: /* @__PURE__ */ l("video", { className: "rotate-y-180 size-full", ref: o }) })
|
|
2520
2520
|
] });
|
|
2521
2521
|
});
|
|
2522
2522
|
Ki.displayName = "QrScanner";
|
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 g.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},Vo="DialogDescriptionWarning",$o=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hr(Vo).contentName}}.`;return g.useEffect(()=>{var o;const i=(o=t.current)==null?void 0:o.getAttribute("aria-describedby");n&&i&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},pr=tr,Uo=rr,mr=or,gr=sr,vr=lr,yr=ur;const jt=c.memo(t=>{const{file:n,onClose:e}=t,r=c.useRef(null),i=c.useCallback(()=>{var a;if(!r.current)return;const l=document.createElement("canvas");l.width=r.current.width,l.height=r.current.height,(a=l.getContext("2d"))==null||a.drawImage(r.current,0,0,r.current.width,r.current.height),l.toBlob(h=>{h&&navigator.clipboard.write([new ClipboardItem({"image/png":h})])},"image/png")},[]),o=c.useCallback(()=>{mn.saveAs(n,n.name)},[n]);return s.jsx(pr,{open:!0,onOpenChange:e,children:s.jsx(mr,{children:s.jsx(gr,{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:s.jsxs(vr,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:l=>l.preventDefault(),children:[s.jsxs(d.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[s.jsxs(d.Tooltip.Root,{children:[s.jsx(d.Tooltip.Trigger,{asChild:!0,children:s.jsx(d.IconButton,{onClick:i,"aria-label":"copy to clipboard",children:s.jsx(d.RiIcon,{icon:"RiFileCopyLine"})})}),s.jsx(d.Tooltip.Content,{size:"sm",children:"Copy"})]}),s.jsxs(d.Tooltip.Root,{children:[s.jsx(d.Tooltip.Trigger,{asChild:!0,children:s.jsx(d.IconButton,{onClick:o,"aria-label":"download",children:s.jsx(d.RiIcon,{icon:"RiDownload2Line"})})}),s.jsx(d.Tooltip.Content,{size:"sm",children:"Download"})]}),s.jsx(d.Separator,{orientation:"vertical",size:"sm"}),s.jsx(yr,{asChild:!0,children:s.jsx(d.IconButton,{onClick:e,"aria-label":"close",children:s.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),s.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:s.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});jt.displayName="ImageViewer";const br=c.memo(t=>{const{children:n}=t,[e,r]=c.useState(null),i=c.useCallback(()=>{r(null)},[]),o=c.useCallback(h=>{r(h(i))},[i]),l=c.useCallback(()=>{e&&(e.onClose&&e.onClose(),i())},[i,e]),a=c.useMemo(()=>o,[o]);return s.jsxs(En.Provider,{value:a,children:[n,e&&s.jsx(jt,{file:e.file,onClose:l})]})});br.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:i,inputId:o,labelId:l,image:a}=t,[h,p]=c.useState(void 0),m=Xe(),f=i?ie[i]:"base";c.useEffect(()=>{a instanceof Promise?a.then(p).catch(console.error):p(a)},[a]);const v=h?URL.createObjectURL(h):void 0,I=c.useCallback(()=>{h&&m(()=>({file:h}))},[m,h]);return s.jsxs("div",{className:"flex flex-col gap-1",children:[h&&s.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:v,alt:h.name,onClick:I}),s.jsx("label",{className:ge.cx(n,"flex flex-col gap-1 w-max max-w-full"),htmlFor:o,children:s.jsx(d.Text,{accentColor:f,size:"sm",id:l,weight:"medium",className:"text-wrap",children:e})}),r]})},K=t=>{const{children:n,...e}=t;return s.jsx(Ft,{...e,children:n})},Ht=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),f=o?null:a,v=o?"":h,{name:I,onChange:w,onBlur:u}=p,b=`${n}-droppable`,{disabled:E}=m,S=p.value??xt,[y,F]=c.useState(""),[x,D]=c.useState(""),N=x||f,L=c.useCallback(z=>{w(z),u(z)},[w,u]),M=c.useCallback(z=>{S&&S.findIndex(Z=>Z===z.target.value.trim())>=0?D("All options must be unique"):z.target.value?D(""):D("Option cannot be empty"),F(z.target.value)},[F,S]),A=c.useCallback(()=>{if(x)return;if(!y.trim()){D("Option cannot be empty");return}const z=y.trim();L([...S,z]),F("")},[y,x,L,S]),O=c.useCallback(z=>{z.key==="Enter"&&(z.preventDefault(),A())},[A]),_=c.useCallback(z=>{L(He(S,z))},[S,L]),X=c.useCallback(z=>{if(!z.destination)return;const Z=z.source.index,ze=z.destination.index;L(Et(S,Z,ze))},[L,S]),ne=c.useCallback(()=>{u(S)},[u,S]);return s.jsx(re.DragDropContext,{onDragEnd:X,children:s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(K,{helpText:N,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:v,image:o?void 0:l.image,children:(!E||S.length===0)&&s.jsxs("div",{className:"flex gap-2",children:[s.jsx(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:s.jsx(d.Input.Field,{value:y,onChange:M,onKeyDown:O,id:n,placeholder:l.placeholder,onBlur:ne,name:I,...m})}),s.jsx(d.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!x||E,onClick:A,children:s.jsx(d.RiIcon,{icon:"RiAddLine"})})]})})}),s.jsx(re.Droppable,{droppableId:b,children:z=>s.jsxs("div",{className:"flex flex-col",...z.droppableProps,ref:z.innerRef,children:[S.map((Z,ze)=>s.jsx(re.Draggable,{draggableId:`${Z}-draggable`,index:ze,isDragDisabled:E,children:({draggableProps:ae,dragHandleProps:hn,innerRef:Ct})=>s.jsxs(d.Badge,{...hn,...ae,ref:Ct,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[s.jsx("span",{className:"truncate",children:typeof Z=="object"&&"label"in Z?Z.label:Z}),s.jsx(d.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:E,onClick:()=>{_(ze)},children:s.jsx(d.RiIcon,{icon:"RiCloseLargeLine"})})]})},Z)),z.placeholder]})})]})})});Ht.displayName="MultiStringInput";const Cr={...H,type:"multi-string",minimum_length:0,maximum_length:null},Ee=class Ee extends V{constructor(e){const{minimum_length:r,maximum_length:i,placeholder:o,...l}=e;super({...l,type:"multi-string"});T(this,"minLength");T(this,"maxLength");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.minLength=r??0,this.maxLength=i??1/0,this.placeholder=o??"Press enter to add a new option"}getInput(e){return s.jsx(Ht,{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 Ee(e)}};T(Ee,"fieldTypeName","Multi-string"),T(Ee,"fieldTypeDescription","Allows the user to provide multiple unique strings."),T(Ee,"Icon",k.RiListCheck);let Ie=Ee;class Gt extends V{constructor(e){const{placeholder:r="",...i}=e;super(i);T(this,"options");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.placeholder=r;const o=new Set;this.options=e.options.map(l=>(typeof l=="string"&&(l={label:l,value:l}),o.add(l.label),l)),o.size!==e.options.length&&console.error(`${e.options.length-o.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 Ie({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const Xt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onBlur:v,onChange:I,value:w}=p,u=o?null:a,b=o?"":h,E=c.useCallback(y=>{I(!!y),v(!!y)},[v,I]),S=c.useCallback(()=>{v(w)},[v,w]);return s.jsx(K,{helpText:u,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:o?void 0:l.image,className:"items-center flex-row-reverse justify-end gap-2",children:s.jsx(d.Checkbox.Root,{id:n,name:f,checked:w??!1,onCheckedChange:E,onBlur:S,size:"sm",accentColor:"primary",variant:"surface",...m,children:s.jsx(d.Checkbox.Indicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})})})})})});Xt.displayName="BooleanInput";const wr={...H,type:"boolean"},Se=class Se extends V{constructor(e){super({...e,type:"boolean"});T(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 s.jsx(Xt,{...e,field:this})}};T(Se,"fieldTypeName","Checkbox"),T(Se,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),T(Se,"Icon",k.RiCheckboxCircleLine);let xe=Se;const Wo={...H,type:"custom"};class ot extends V{constructor(e,r){super({...e,type:"custom"});T(this,"Component");T(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 s.jsx(r,{field:this,...e})}}T(ot,"fieldTypeName","Custom"),T(ot,"fieldTypeDescription","Allows re-rendering of field already in the form");const Yt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I}=p,[w,u]=c.useState(!1),b=o?null:a,E=o?"":h,S=p.value?new Date(p.value):void 0,y=c.useCallback(x=>{v(x==null?void 0:x.toISOString()),u(!1)},[v]),F=c.useCallback(x=>{u(x),x||I(p.value)},[p.value,I]);return s.jsx(K,{helpText:b,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:E,image:o?void 0:l.image,children:s.jsxs(d.Popover.Root,{open:w,onOpenChange:F,children:[s.jsx(d.Popover.Trigger,{asChild:!0,children:s.jsxs(d.Button,{id:n,name:f,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...m,children:[S?S.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",s.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),s.jsx(d.Popover.Content,{align:"start",children:s.jsx(d.DayPicker,{required:!1,mode:"single",variant:"solid",selected:S,onSelect:y})})]})})})});Yt.displayName="DateInput";const Ir={...H,type:"date"},Te=class Te extends V{constructor(e){super({...e,type:"date"});T(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 s.jsx(Yt,{field:this,...e})}};T(Te,"fieldTypeName","Date"),T(Te,"fieldTypeDescription","Allows specifying a date."),T(Te,"Icon",k.RiCalendarLine);let st=Te;const Kt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I}=p,w=o?null:a,u=o?"":h,b=p.value??xt,E=c.useCallback(y=>{const F=y.length>0?y:void 0;v(F),I(F)},[I,v]),S=c.useCallback(y=>{y||I(b)},[b,I]);return s.jsx(K,{helpText:w,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:u,image:o?void 0:l.image,children:s.jsxs(d.Menu.Root,{onOpenChange:S,align:"start",children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsxs(d.Button,{id:n,name:f,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...m,children:[s.jsx("span",{className:"truncate",children:b&&b.length>0?b.join(", "):l.placeholder}),s.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),s.jsx(d.Menu.Content,{children:s.jsx(d.Menu.Scroll,{children:s.jsxs(d.Menu.MultiSelectGroup,{values:b,onValuesChange:E,children:[s.jsxs(d.Menu.SelectAllItem,{children:[s.jsx(d.Menu.CheckboxItemIndicator,{children:y=>y?s.jsx(d.RiIcon,{icon:"RiSubtractLine"}):s.jsx(d.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),l.options.map(y=>s.jsxs(d.Menu.MultiSelectItem,{value:y.value,children:[s.jsx(d.Menu.SelectedIndicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))]})})})]})})})});Kt.displayName="MultiSelectInput";const xr={...H,type:"multi-select",options:[]},Fe=class Fe extends Gt{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 Fe(n)}getInput(n){return s.jsx(Kt,{field:this,...n})}};T(Fe,"fieldTypeName","Multi-select"),T(Fe,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),T(Fe,"Icon",k.RiCheckboxLine);let Be=Fe;const Zt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p,touched:m,helpers:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,E=o?null:a,S=o?"":h,[y,F]=c.useState(void 0);c.useEffect(()=>{F(b)},[b]);const x=c.useCallback(N=>{const L=N.target.valueAsNumber,M=Number.isNaN(L)?void 0:L;F(M),(m||!l.onlyValidateAfterTouched)&&f.setError(l.getError(M))},[l,f,m]),D=c.useCallback(()=>{u(y),w(y)},[y,w,u]);return s.jsx(K,{helpText:E,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:S,image:o?void 0:l.image,children:s.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:s.jsx(d.Input.Field,{id:n,name:I,onChange:x,onBlur:D,value:y??"",type:"number",min:l.minimum,max:l.maximum,step:l.integers?1:.1,placeholder:l.placeholder,...v})})})})});Zt.displayName="NumberInput";const Er={...H,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Sr=t=>"fields"in t,ee=class ee extends V{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:i=Number.MAX_SAFE_INTEGER,integers:o=!1,placeholder:l="Enter a number",...a}=e;super({...a,type:"number"});T(this,"minimum");T(this,"maximum");T(this,"integers");T(this,"placeholder");this.minimum=r,this.maximum=i,this.integers=o,this.placeholder=l}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ee({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new ee({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new xe({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(o=>{if(typeof o=="number"&&o<r)return`Must be at least ${this.minimum}.`}),typeof i=="number"&&e.push(o=>{if(typeof o=="number"&&o>i)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(o=>{if(typeof o=="number"&&!Number.isInteger(o))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 ee(e)}getInput(e){return s.jsx(Zt,{field:this,...e})}};T(ee,"fieldTypeName","Number"),T(ee,"fieldTypeDescription","Allows specifying a number within a given range."),T(ee,"Icon",k.RiHashtag),T(ee,"_validateMin",e=>(r,i)=>{const o=Sr(i)?Q(i,e):i;return typeof o.maximum=="number"&&typeof r=="number"&&o.maximum<r?"Minimum cannot be greater than minimum.":null}),T(ee,"_validateMax",e=>(r,i)=>{const o=Sr(i)?Q(i,e):i;return typeof o.minimum=="number"&&typeof r=="number"&&o.minimum>r?"Maximum cannot be less than minimum.":null});let le=ee;const Jt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I,value:w}=p,u=o?null:a,b=o?"":h,E=c.useCallback(y=>{v(y??void 0),I(y??void 0)},[I,v]),S=c.useCallback(()=>{v(void 0),I(void 0)},[I,v]);return s.jsx(K,{helpText:u,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:o?void 0:l.image,children:s.jsxs(d.RadioGroup.Root,{id:n,name:f,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:"sm",value:w??"",onValueChange:E,...m,children:[l.options.map(y=>s.jsxs("label",{className:"flex gap-2 items-center min-w-0",children:[s.jsx(d.RadioGroup.Item,{value:y.value,children:s.jsx(d.RadioGroup.Indicator,{children:s.jsx(d.RiIcon,{icon:"RiCircleFill"})})},y.value),s.jsx(d.Text,{size:"sm",accentColor:"base",className:"truncate",children:y.label})]})),!!w&&s.jsxs(d.Button,{onClick:S,className:"w-max -mx-2",type:"button",variant:"ghost",accentColor:"base",size:"sm",children:[s.jsx(d.RiIcon,{icon:"RiCloseLine"})," Clear"]})]})})})});Jt.displayName="SelectInput";const Tr={...H,type:"radio",options:[]},Ne=class Ne extends V{constructor(e){const{options:r,...i}=e;super({...i,type:"radio"});T(this,"options");T(this,"onlyValidateAfterTouched",!1);const o=new Set;this.options=r.map(l=>(typeof l=="string"&&(l={label:l,value:l}),o.add(l.label),l)),o.size!==r.length&&console.error(`${r.length-o.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,r)}serialize(){return{...super._serialize(),options:this.options}}static deserialize(e){if(e.type!=="radio")throw new Error("Type mismatch.");return new Ne(e)}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new Ie({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}getInput(e){return s.jsx(Jt,{field:this,...e})}};T(Ne,"fieldTypeName","Option list"),T(Ne,"fieldTypeDescription","Allows the user to select a single option from a list of options."),T(Ne,"Icon",k.RiRadioButtonFill);let lt=Ne;const Qt=c.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:i,size:o,severity:l,showInputOnly:a,field:h,fieldProps:p,helpers:m,touched:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,[E,S]=c.useState(!1),y=a?null:i,F=a?"":r,[x,D]=c.useState(void 0);c.useEffect(()=>{D(b)},[b]);const N=c.useCallback(_=>{D(_.target.value||void 0),(f||!h.onlyValidateAfterTouched)&&m.setError(h.getError(_.target.value))},[h,m,f]),L=c.useCallback(()=>{u(x),w(x)},[x,w,u]),M=c.useCallback(_=>{u(_),S(!1)},[u]),A=c.useCallback(()=>{u(void 0)},[u]),O=c.useCallback(_=>{S(_),_||w(b)},[w,b]);return s.jsx(K,{helpText:y,severity:l,children:s.jsx(Y,{size:o,severity:l,inputId:n,labelId:e,label:F,image:a?void 0:h.image,className:"flex-col items-start justify-start gap-2",children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsxs(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:[s.jsx(d.Input.Field,{id:n,className:"truncate",name:I,value:x??"",type:"text",placeholder:"Enter a qr or barcode",onChange:N,onBlur:L,...v}),!!b&&s.jsx(d.Input.Slot,{children:s.jsx(d.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"xs",onClick:A,children:s.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),s.jsxs(pr,{open:E,onOpenChange:O,children:[s.jsx(Uo,{asChild:!0,children:s.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",accentColor:"base",children:[s.jsx(d.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),s.jsxs(mr,{children:[s.jsx(gr,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),s.jsx(vr,{className:"fixed inset-0",children:s.jsx(Rt,{onScan:M})})]})]})]})})})});Qt.displayName="QrInput";const Rt=c.memo(t=>{const{onScan:n}=t,{showError:e}=d.useToast(),r=c.useCallback(l=>{n(l.getText())},[n]),i=c.useCallback(()=>{e({title:"Scan Error",description:"An unknown error occurred while scanning."})},[e]),{ref:o}=ti.useZxing({onDecodeResult:r,onError:i});return s.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[s.jsx("div",{className:"absolute top-0 flex w-full p-2",children:s.jsx(yr,{asChild:!0,children:s.jsx(d.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:s.jsx(d.RiIcon,{icon:"RiCloseLine"})})})}),s.jsx("div",{className:"relative max-h-full max-w-full **:stroke-(--primary-indicator)",children:s.jsx("video",{className:"rotate-y-180 size-full",ref:o})})]})});Rt.displayName="QrScanner";const Fr={...H,type:"qr"},Le=class Le extends V{constructor(e){super({...e,type:"qr"});T(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="qr")throw new Error("Type mismatch.");return new Le(e)}getInput(e){return s.jsx(Qt,{...e,field:this})}};T(Le,"fieldTypeName","Scan"),T(Le,"fieldTypeDescription","Used for scanning/reading QR and barcodes."),T(Le,"Icon",k.RiFullscreenLine);let at=Le;const en=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I,value:w}=p,u=o?null:a,b=o?"":h,E=c.useCallback(y=>{v(y),I(y)},[I,v]),S=c.useMemo(()=>l.options.find(y=>y.value===w),[l.options,w]);return s.jsx(K,{helpText:u,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:o?void 0:l.image,children:s.jsxs(d.Menu.Root,{align:"start",children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsxs(d.Button,{id:n,name:f,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...m,children:[s.jsx("span",{className:"truncate",children:S?S.label:l.placeholder}),s.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),s.jsx(d.Menu.Content,{children:s.jsx(d.Menu.Scroll,{children:s.jsx(d.Menu.SelectGroup,{required:!1,value:w??void 0,onValueChange:E,children:l.options.map(y=>s.jsxs(d.Menu.SelectItem,{value:y.value,children:[s.jsx(d.Menu.SelectedIndicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))})})})]})})})});en.displayName="SelectInput";const Nr={...H,type:"select",options:[]},De=class De extends Gt{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 s.jsx(en,{field:this,...n})}};T(De,"fieldTypeName","Dropdown"),T(De,"fieldTypeDescription","Allows the user to select a single option from a list of options."),T(De,"Icon",k.RiMenuFoldLine);let _e=De;const Ve=500,he=1e4,Lr=t=>"fields"in t;class $e extends V{constructor(e){const{minLength:r,maxLength:i,placeholder:o="",...l}=e;super(l);T(this,"minLength");T(this,"maxLength");T(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=i?Math.max(i,0):he,this.placeholder=o}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new le({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 le({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:he,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}}}T($e,"_validateMin",e=>(r,i)=>{const o=Lr(i)?Q(i,e):i;return typeof o.maximum_length=="number"&&typeof r=="number"&&o.maximum_length<r?"Minimum cannot be greater than maximum.":null}),T($e,"_validateMax",e=>(r,i)=>{if(typeof r!="number")return null;const{minimum_length:o}=Lr(i)?Q(i,e):i;return typeof o!="number"?null:o>r?"Maximum cannot be less than minimum.":null});const tn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p,touched:m,helpers:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,E=o?null:a,S=o?"":h,[y,F]=c.useState(void 0);c.useEffect(()=>{F(b)},[b]);const x=c.useCallback(N=>{F(N.target.value||void 0),(m||!l.onlyValidateAfterTouched)&&f.setError(l.getError(N.target.value))},[l,f,m]),D=c.useCallback(()=>{u(y),w(y)},[y,w,u]);return s.jsx(K,{helpText:E,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:S,image:o?void 0:l.image,children:s.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:s.jsx(d.Input.Field,{id:n,className:"truncate",name:I,value:y??"",type:l.inputType,placeholder:l.placeholder,onChange:x,onBlur:D,...v})})})})});tn.displayName="StringInput";const Dr={...H,type:"string",maximum_length:Ve,input_type:"text"},Me=class Me extends $e{constructor(e){const{inputType:r="text",...i}=e,o=e.maxLength?Math.min(Ve,e.maxLength):Ve,l=e.minLength?Math.min(e.minLength,o):void 0;super({...i,maxLength:o,minLength:l,type:"string"});T(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:o,...l}=e;return new Me({...l,maxLength:r,minLength:i,inputType:o,placeholder:"Enter a short description"})}getInput(e){return s.jsx(tn,{field:this,...e})}};T(Me,"fieldTypeName","Short Text"),T(Me,"fieldTypeDescription",`Short text fields can hold up to ${Ve} characters on a single line.`),T(Me,"Icon",k.RiInputField);let ct=Me;const nn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p,touched:m,helpers:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,E=o?null:a,S=o?"":h,[y,F]=c.useState(void 0);c.useEffect(()=>{F(b)},[b]);const x=c.useCallback(N=>{F(N.target.value||void 0),(m||!l.onlyValidateAfterTouched)&&f.setError(l.getError(N.target.value))},[l,f,m]),D=c.useCallback(()=>{u(y),w(y)},[y,w,u]);return s.jsx(K,{helpText:E,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:S,image:o?void 0:l.image,children:s.jsx(d.TextArea,{id:n,value:y??"",name:I,onChange:x,onBlur:D,className:"field-sizing-content min-h-12",placeholder:l.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...v})})})});nn.displayName="TextInput";const Mr={...H,type:"text",maximum_length:he},Pe=class Pe extends $e{constructor(n){const e=n.maxLength?Math.min(he,n.maxLength):he,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 s.jsx(nn,{field:this,...n})}};T(Pe,"fieldTypeName","Paragraph"),T(Pe,"fieldTypeDescription",`Paragraph fields can hold up to ${he} characters and can have multiple lines.`),T(Pe,"Icon",k.RiAlignJustify);let dt=Pe;const Pr=c.memo(c.forwardRef((t,n)=>{const{file:e,alt:r,error:i,rightSlot:o,className:l,...a}=t;return s.jsxs("div",{className:ge.cx(l,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...a,children:[!e&&!i&&s.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:s.jsx(d.Spinner,{})}),s.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!i&&s.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),s.jsxs("div",{className:ge.cx("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[i?s.jsx(d.RiIcon,{icon:"RiFileWarningLine"}):e&&s.jsx(ke,{fileType:e.type}),s.jsx(d.Text,{className:"truncate",size:"sm",children:i??(e==null?void 0:e.name)}),o]})]})})),ko=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)},rn=c.memo(t=>{var N;const[{inputId:n,labelId:e,size:r,severity:i,helpText:o,showInputOnly:l,field:a,fieldProps:h},p]=G(t),{name:m,onChange:f,onBlur:v}=h;let[{label:I}]=G(t);I=l?"":I;const w=h.value??xt,u=c.useRef(null),b=c.useMemo(()=>l?null:o||(a.maxFileSize?`Maximum file size: ${a.maxFileSize}MB`:null),[a.maxFileSize,o,l]),E=c.useCallback(()=>{var L;(L=u.current)==null||L.click()},[]),S=c.useCallback(()=>{if(!u.current)return;const L=u.current.files;if(!L){v([]);return}const M=Array.from(L),A=[...w,...M];f(A),v(A)},[v,f,w]),y=c.useCallback(L=>{const M=[...w];M.splice(L,1),f(M.length>0?M:void 0)},[w,f]);c.useEffect(()=>{if(!u.current)return;const L=new AbortController;return u.current.addEventListener("cancel",()=>{v(void 0)},{signal:L.signal}),()=>{L.abort()}},[v,w]);const D=a.maxFiles>1?"Select files":"Select a file";return s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(K,{helpText:b,severity:i,children:s.jsxs(Y,{size:r,severity:i,inputId:n,labelId:e,label:I,image:l?void 0:a.image,children:[s.jsx("div",{className:"flex gap-2",children:s.jsxs(d.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:E,id:"upload-input-upload-button",type:"button",...p,children:[s.jsx(d.RiIcon,{icon:"RiUpload2Line"})," ",D]})}),s.jsx("input",{id:n,name:m,type:"file",ref:u,accept:(N=a.extensions)==null?void 0:N.join(","),multiple:a.maxFiles>1,className:"hidden",onChange:S,value:""})]})}),Array.isArray(w)&&w.length>0&&s.jsx("div",{className:"flex h-max flex-col gap-2",children:w.map((L,M)=>s.jsx(Ar,{field:a,file:L,onRemove:()=>{y(M)},disabled:p.disabled},M))})]})});rn.displayName="UploadInput";const Ar=c.memo(t=>{const{file:n,field:e,onRemove:r,disabled:i}=t,[o,l]=c.useState(null),a=Xe(),h=c.useMemo(()=>o&&e.getError([o]),[e,o]),{url:p,name:m}=c.useMemo(()=>{let u=null,b,E;return o!=null&&o.type.startsWith("image/")&&(u=URL.createObjectURL(o)),o?(b=o.name,E=ko(o.size)):(b="Downloading...",E="..."),{url:u,name:b,size:E}},[o]);c.useEffect(()=>{n instanceof Promise?n.then(l).catch(console.error):l(n)},[n]);const f=c.useCallback(u=>{if(u.stopPropagation(),!o)throw new Error("Cannot download a file that is not resolved.");const b=new Blob([o]);mn.saveAs(b,m)},[m,o]),v=c.useCallback(u=>{u.stopPropagation(),r()},[r]),I=c.useCallback(()=>{o&&a(u=>({file:o,onDelete:i?void 0:()=>{r(),u()}}))},[i,r,a,o]),w=c.useMemo(()=>s.jsxs(d.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[s.jsx(d.IconButton,{"aria-label":`Download ${m}`,type:"button",onClick:f,disabled:!o,children:s.jsx(d.RiIcon,{icon:"RiDownload2Line"})}),!i&&s.jsx(d.IconButton,{type:"button","aria-label":`Remove ${m}`,disabled:i,onClick:v,children:s.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[i,v,f,m,o]);return p?s.jsx(Pr,{className:"cursor-pointer",onClick:I,file:o,error:h??void 0,rightSlot:w}):s.jsx(wt,{file:o,error:h??void 0,rightSlot:w})});Ar.displayName="DisplayFile";const Or={...H,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1};function zr(t,n){return t.name===n.name&&t.size===n.size&&t.type===n.type}const Ae=class Ae extends V{constructor(e){const{extensions:r,maximum_files:i,maximum_size:o,...l}=e;super({...l,type:"upload"});T(this,"extensions");T(this,"maxFileSize");T(this,"maxFiles");T(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof o=="number"?o: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(o=>zr(i,o)))||!r.every(i=>e.some(o=>zr(o,i))))}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new le({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 le({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${Ue}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:Ue,integers:!0}),showDirectly:!1},{field:new Be({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??Ue,i=r*1e3*1e3,o=this.maxFiles||1;return e.push(l=>{if(l&&l.some(a=>a.size>i))return`Files must be at most ${r}MB.`}),e.push(l=>{if(l&&l.length>o)return`You can only upload ${o} 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 s.jsx(rn,{field:this,...e})}};T(Ae,"fieldTypeName","Upload"),T(Ae,"fieldTypeDescription","Allows a file to be uploaded."),T(Ae,"Icon",k.RiUpload2Line);let ut=Ae;const ft={date:st,number:le,boolean:xe,select:_e,string:ct,text:dt,custom:ot,upload:ut,qr:at,"multi-string":Ie,"multi-select":Be,radio:lt},Br={date:Ir,number:Er,boolean:wr,select:Nr,string:Dr,text:Mr,custom:Wo,upload:Or,qr:Fr,"multi-string":Cr,"multi-select":xr,radio:Tr},qo={boolean:"RiCheckboxCircleLine",date:"RiCalendarLine","multi-string":"RiListCheck",number:"RiHashtag",qr:"RiFullscreenLine","multi-select":"RiCheckboxLine",select:"RiMenuFoldLine",string:"RiInputField",text:"RiAlignJustify",upload:"RiUpload2Line",custom:"RiCodeSSlashLine",section:"RiFolderLine",radio:"RiRadioButtonFill"},Ue=50,_r=Ue*1e3,Vr=_r*1e3,$r=c.memo(t=>{const{field:n,...e}=t,[{value:r}]=W.useField(n.options.clonedFieldIdentifier),i=c.useMemo(()=>{const o=n.options.getFieldToClone(r);return o?ht(o):null},[n.options,r]);return ln(i,e)});$r.displayName="FieldInputCloner";class jo extends ot{constructor(n){super(n,$r)}}const on=t=>{const n=t.type;return ft[n].deserialize(t)},ht=t=>t.type==="section"?q.deserialize(t):on(t);function Ur(t){return t.map(n=>ht(n))}function pt(t){const n=[];for(const e of t)if(e instanceof q)for(const r of e.fields)n.push(r);else{if(!(e instanceof V))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Wr(t){const n=pt(t),e={};for(const r of n)e[r.identifier]=r;return e}function Ho(t,n){const e=pt(t),r={};for(const i of e){const o=n[i.identifier]??null;o!==null?r[i.identifier]=i.decodeJsonToValue(o):r[i.identifier]=o}return r}function Go(t,n){const e=pt(t),r={};for(const i of e){const o=n[i.identifier];r[i.identifier]=i.encodeValueToJson(o)}return r}function mt(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function sn(t,n){if(!t)return!0;if(mt(n)||mt(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 ln=(t,n)=>c.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),We=(t,n)=>{const e=c.useMemo(()=>t.map(r=>s.jsx(c.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return s.jsx("div",{className:"flex flex-col gap-4",children:e})},an=c.memo(t=>{const{field:n,...e}=t,{label:r,description:i,fields:o,condition:l}=n,{values:a,setFieldValue:h}=W.useFormikContext(),p=l!=null&&l.identifier?Q(a,l.identifier):void 0,m=c.useMemo(()=>sn(l,p),[l,p]);c.useEffect(()=>{if(!m)for(const v of o)h(v.getId(),"").then()},[m,o,h]);const f=We(o,e);return m?s.jsx(d.Card,{variant:"soft",children:s.jsxs("div",{className:"flex flex-col gap-4",children:[(r||i)&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx(d.Heading,{size:"md",children:r}),s.jsx(d.Text,{accentColor:"base",children:i})]}),s.jsx(d.Separator,{size:"full"})]}),f]})}):null});an.displayName="FieldSectionLayout";const Oe=class Oe extends It{constructor(e){const{label:r=null,fields:i,condition:o=null,conditional:l,...a}=e;super({...a,type:"section"});T(this,"label");T(this,"fields");T(this,"condition");this.fields=i,this.condition=o,this.label=r,l===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const i=r&&`${r}.`;return[{field:new xe({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 _e({label:"Field",description:"The field to use for the condition.",options:e.map(o=>!o.label||o.type==="upload"?null:{label:o.label,value:o.identifier}).filter(o=>!!o),identifier:`${i}condition.identifier`,required:!0}),new jo({label:"Value",identifier:`${i}condition.value`,required:!0,clonedFieldIdentifier:`${i}condition.identifier`,getFieldToClone(o){if(!o)return null;const l=e.find(a=>a.identifier===o);return l?{...l,label:"Value",identifier:`${i}condition.value`,description:"The value to compare against.",required:l.type!=="boolean"}:(console.error("Could not find field with identifier",o),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(on);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 o=i.getId(),l=i.getError(Q(e,o),e);l&&ve(r,i.getId(),l)}return r}getInput(e){return s.jsx(an,{field:this,...e})}};T(Oe,"fieldTypeName","Section"),T(Oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let q=Oe;const pe=t=>Object.keys(t).length>0,gt=(t,n)=>{const e={};for(const r of t)if(r instanceof q){if(r.condition){const{identifier:i}=r.condition;if(!sn(r.condition,Q(n,i)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof V))throw new Error("Invalid field type");const i=r.getId(),o=r.getError(Q(n,i),n);o&&ve(e,i,o)}if(pe(e))return e},vt=(t,n)=>t.reduce((e,r)=>{if(r instanceof q)return{...e,...vt(r.fields,n)};const i=r.getId(),o=e[i];switch(o){case"":ve(e,i,void 0);break;case[]:ve(e,i,void 0);break;default:ve(e,i,o??void 0)}return e},ni(n)),kr=(t,n,e)=>t.reduce((r,i)=>{if(i instanceof q)return{...r,...kr(i.fields,n,e)};if(i instanceof V){const o=i.getId(),l=n[o],a=e[o];i.isEqual(l,a)||ve(r,o,a)}return r},{}),qr=c.memo(c.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:i,onSubmit:o,submitText:l="Submit",cancelText:a,onCancel:h,onDirty:p,onDirtyChange:m,hideTitle:f=!e.title,hideDescription:v,className:I,buttonProps:w,enableReinitialize:u=!1,excludeUnchangedFields:b=!1}=t,{readonly:E}=e.meta,S=c.useId(),y=c.useMemo(()=>vt(e.fields,r),[e.fields,r]),F=c.useCallback(O=>{o==null||o(b?kr(e.fields,y,O):O)},[b,y,o,e.fields]),x=W.useFormik({initialValues:y,onSubmit:F,validate:O=>gt(e.fields,O),validateOnBlur:!1,validateOnChange:!1,enableReinitialize:u}),{dirty:D}=x,N=c.useMemo(()=>typeof e.title=="string"?s.jsx(d.Heading,{size:"md",children:e.title}):e.title,[e.title]),L=c.useMemo(()=>typeof e.description=="string"?s.jsx(d.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),M=c.useCallback((O,_)=>{Wr(e.fields)[O].isEqual(y[O],_)||i==null||i({...x.values,[O]:_},{[O]:_})},[x.values,y,i,e.fields]),A=We(e.fields,{formId:S,disabled:E,onValuesChange:M});return c.useEffect(()=>{D&&p&&p(),m&&m(D)},[D,p,m]),s.jsx(W.FormikProvider,{value:x,children:s.jsxs("form",{id:S,ref:n,className:ge.cx(I,"flex flex-col gap-2"),onSubmit:x.handleSubmit,children:[!f&&s.jsx(d.Card,{variant:"soft",children:s.jsxs("div",{className:"flex flex-col gap-1",children:[N,!v&&L]})}),A,!E&&s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a&&s.jsxs(d.Button,{accentColor:ie.danger,...w,type:"button",onClick:h,children:[s.jsx(d.RiIcon,{icon:"RiCloseLine"}),a]}),s.jsxs(d.Button,{...w,type:"submit",disabled:!x.isValid,accentColor:"success",children:[s.jsx(d.RiIcon,{icon:"RiCheckLine"}),l]})]})]})})})),me=c.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=W.useFormikContext(),[i,o,l]=W.useField(n),a=c.useMemo(()=>{const h=p=>{l.setValue(p,!1)};return e({value:i.value,meta:o,setValue:h,patchValue:()=>{r()}})},[e,i.value,o,r,l]);return s.jsx(s.Fragment,{children:a})});me.displayName="PatchField";const Xo=c.memo(c.forwardRef((t,n)=>{const{children:e,schema:r,values:i,onPatch:o,onError:l,requiresDiff:a=!0,onDirtyChange:h,...p}=t,m=c.useMemo(()=>vt(r.fields,i),[r.fields,i]),f=c.useCallback(S=>{const y={};for(const F in S){const x=S[F];x!==m[F]&&x!==void 0&&(y[F]=x)}return y},[m]),v=c.useCallback(S=>{const y=f(S);a&&!pe(y)||o(y)},[f,o,a]),I=c.useCallback(S=>{const y=gt(r.fields,S);if(y&&l(y),h){const F=f(S);h(pe(F))}return y},[r.fields,h,l,f]),w=W.useFormik({initialValues:m,onSubmit:v,validate:I,validateOnBlur:!1,validateOnChange:!1}),u=c.useCallback(()=>{if(h){const S=f(w.values);pe(S)&&h(!0)}},[w.values,f,h]),{errors:b,resetForm:E}=w;return c.useEffect(()=>{pe(b)&&E({values:m,errors:{}})},[b,m,E]),s.jsx(W.FormikProvider,{value:w,children:s.jsx("form",{...p,ref:n,onSubmit:w.handleSubmit,onChange:u,children:e})})})),yt="form-builder",Yo=[["string","text"],["select","multi-select","upload","qr","radio"],["boolean","date","number","multi-string"]],cn={...ft,section:q},bt=c.createContext({}),Ko=(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}},Zo=(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}}},jr=t=>{var e,r,i;const n={};for(let o=0;o<t.length;o++){const l=t[o];if(!l)throw new Error("Field is undefined.");const a=o>0?(e=n[t[o-1].identifier])==null?void 0:e.conditionFields:void 0,h=new Set(a);(r=l.condition)!=null&&r.identifier&&h.add(l.condition.identifier),n[l.identifier]={disabled:!1,conditionFields:h,conditionIndex:Zo(t,(i=l.condition)==null?void 0:i.identifier),index:o,label:l.label}}return n},dn=c.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:i,duplicate:o,move:l,upload:a}=t;if(e!=="section"&&!a)throw new Error("Upload function prop must be defined for non-section fields.");const{values:h}=W.useFormikContext(),p=c.useRef(null),m=c.useMemo(()=>{const f=[{Icon:k.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:o}}];return f.push({Icon:k.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:i}}),e!=="section"&&f.unshift({Icon:k.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var v;(v=p.current)==null||v.click()}}}),(r===void 0&&n!==h.fields.length-1||r!==void 0&&(r<h.fields.length-1||n!==h.fields[r].fields.length-1))&&f.unshift({Icon:k.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{l("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&f.unshift({Icon:k.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{l("up")}}}),f},[o,n,l,i,r,e,h.fields]);return s.jsxs(s.Fragment,{children:[s.jsx(d.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:m.map(f=>s.jsx(d.IconButton,{type:"button","aria-label":f.text,...f.buttonProps,children:s.jsx(f.Icon,{})},f.key))}),s.jsx("div",{className:"sm:hidden",children:s.jsxs(d.Menu.Root,{children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsx(d.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:s.jsx(d.RiIcon,{icon:"RiMore2Line"})})}),s.jsx(d.Menu.Content,{children:m.map(f=>{var v;return s.jsxs(d.Menu.Item,{onClick:(v=f.buttonProps)==null?void 0:v.onClick,children:[s.jsx(f.Icon,{}),f.text]},f.key)})})]})}),e!=="section"&&s.jsx("input",{style:{display:"none"},ref:p,type:"file",accept:"image/*",onChange:a})]})});dn.displayName="FieldActions";const un=c.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return s.jsxs(d.Popover.Root,{children:[s.jsx(d.Popover.Trigger,{asChild:!0,children:s.jsxs(d.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:ie.danger},children:[s.jsx(d.RiIcon,{icon:"RiSettings2Line"}),s.jsx("span",{children:"Settings"})]},"settings")}),s.jsx(d.Popover.Content,{size:"sm",...r,children:s.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});un.displayName="FieldSettingsPopover";const Hr=(t=()=>null)=>c.useMemo(()=>Yo.map(n=>n.map(e=>{const r=ft[e],i=r.Icon;return{children:r.fieldTypeName,icon:s.jsx(i,{}),value:e,onSelect:()=>{t(e)}}})),[t]),Gr=576,fn=c.memo(t=>{var Ct,Jr,Qr,Rr,ei;const{parentPath:n,index:e,initial:r,conditionalSourceFields:i}=t,{values:o,setFieldValue:l,errors:a}=W.useFormikContext(),h=Hr(),p=Xe(),{disableRequiredFields:m}=c.use(bt),f=c.useRef(null),[v,I]=c.useState(f.current&&f.current.getBoundingClientRect().width>=Gr);c.useEffect(()=>{const P=f.current;if(P){const B=new ResizeObserver(j=>{j[0]&&I(j[0].contentRect.width>=Gr)});return B.observe(P),()=>{B.disconnect()}}},[]);const[w,u]=c.useState(void 0);c.useEffect(()=>{ce(r)?u(void 0):r.image instanceof Promise?r.image.then(u).catch(console.error):u(r.image)},[r]);const b=w?URL.createObjectURL(w):void 0,E=c.useCallback(P=>{P.stopPropagation();const{image:B,...j}=r;l(`${n}.${e}`,j).then()},[e,r,n,l]);c.useEffect(()=>{ce(r)&&!r.conditional&&l(`${n}.${e}.condition`,null).then()},[e,r,n,l]);const S=c.useMemo(()=>{var P,B;return ce(r)?(B=In(o.fields,(P=r.condition)==null?void 0:P.identifier))==null?void 0:B.label:void 0},[r,o.fields]),y=ce(r)?Array.isArray((Ct=r.condition)==null?void 0:Ct.value)?"contains all of":"equals":void 0;let F;if(ce(r)){if(mt((Jr=r.condition)==null?void 0:Jr.value))throw new Error("File values are not supported for conditions.");F=Array.isArray((Qr=r.condition)==null?void 0:Qr.value)?r.condition.value.map(P=>typeof P=="string"?P:P.label).join(", "):(ei=(Rr=r.condition)==null?void 0:Rr.value)==null?void 0:ei.toString()}const x=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),D=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),N=r.type,L=cn[N],[M,A]=c.useMemo(()=>{let P=[],B=[];if(L===q){if(i===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const j=L.getFieldCreationSchema(i,`${n}.${e}`);P=P.concat(j.filter(U=>U.showDirectly).map(U=>U.field)),B=B.concat(j.filter(U=>!U.showDirectly).map(U=>U.field))}else{if(!(L.prototype instanceof V))throw new Error(`Field must be an instance of BaseField. Got ${L.toString()}.`);const j=L.getFieldCreationSchema(`${n}.${e}`);v?(P=[...P,...j.filter(U=>U.showDirectly).map(U=>U.field)],B=[...B,...j.filter(U=>!U.showDirectly).map(U=>U.field)]):B=[...B,...j.map(U=>U.field)]}return[P,B]},[L,i,n,e,v]),O=We(M,{formId:yt,disabled:!1,...L===q&&{size:"sm"}}),_=We(A,{formId:yt,disabled:!1});let X=A.length>0;ce(r)&&A.length>0&&(X=r.conditional);const ne=A.some(P=>{const B=Q(a,L===q?`${n}.${e}.condition`:P.getId());return B&&(typeof B!="object"||pe(B))}),z=ne?ie.danger:void 0,Z=c.useMemo(()=>ht(r),[r]),ze=ln(Z,{formId:yt,showInputOnly:!1}),ae=c.useMemo(()=>h.flat().find(P=>P.value===N),[h,N]),hn=c.useCallback(()=>{w&&p(()=>({file:w}))},[p,w]);return s.jsx("div",{className:"flex grow items-center w-full",ref:f,children:s.jsxs("div",{className:"flex w-full flex-col gap-2",children:[L===q&&(M.length>0||X)&&s.jsxs("div",{className:"flex flex-col gap-2",children:[O,X&&s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(un,{popoverInputs:_,hasError:ne,align:"start"}),ce(r)&&r.conditional&&s.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":z,children:s.jsxs("em",{children:["Display only if ",s.jsx("strong",{children:S})," ",y," ",s.jsx("strong",{children:F})]})})]})]}),L!==q&&s.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[s.jsxs("div",{className:"flex gap-2 items-center",children:[s.jsxs(d.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[ae==null?void 0:ae.icon,ae==null?void 0:ae.children]}),!m&&s.jsx(me,{name:`${n}.${e}.required`,render:({setValue:P,value:B})=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(d.Checkbox.Root,{checked:B,onCheckedChange:P,size:"sm",children:s.jsx(d.Checkbox.Indicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})})}),s.jsx(d.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),X&&s.jsx(un,{popoverInputs:_,hasError:ne,align:"end"})]}),w&&s.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[s.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:b,alt:w.name,onClick:hn}),s.jsx(d.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:"base","aria-label":"delete",onClick:E,size:"sm",children:s.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),s.jsx(me,{name:`${n}.${e}.label`,render:({setValue:P,value:B})=>s.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:N==="section"?"Enter a section label (optional)":"Enter your question",value:B,onChange:j=>{P(j.target.value)},onInput:x,maxLength:200})}),s.jsx(me,{name:`${n}.${e}.description`,render:({setValue:P,value:B})=>s.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${N==="section"?"section":"field"} description (optional)`,value:B,onChange:j=>{P(j.target.value)},onInput:D,maxLength:1e3})}),L!==q&&M.length>0&&s.jsx("div",{className:"w-full",children:O}),L!==q&&s.jsxs(d.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[s.jsxs(d.HoverCard.Root,{children:[s.jsx(d.HoverCard.Trigger,{asChild:!0,children:s.jsx(d.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:s.jsx(d.RiIcon,{icon:"RiEyeLine"})})}),s.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."})]}),s.jsx("div",{className:"grow h-max min-w-0",children:ze})]})]})})});fn.displayName="FieldBuilder";const Xr=c.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:i}=t,{setFieldValue:o,values:l}=W.useFormikContext(),{reorderField:a}=Tt(),{showInfo:h,showError:p}=d.useToast(),m=`fields.${r}.fields`,f=c.useMemo(()=>({index:e,parentPath:m,initial:n}),[n,e,m]),v=c.useCallback(()=>{const u=n.label||"Unlabelled field",b={...n,label:u};Ge(m,e+1,b,l,o),h({title:"Field duplicated",description:`The field "${u}" has been duplicated`})},[n,m,e,l,o,h]),I=c.useCallback(u=>{const b=r,E=l.fields[b];let S=r,y=u==="up"?e-1:e+1;u==="up"&&e===0?(S=r-1,y=l.fields[S].fields.length):u==="down"&&e===E.fields.length-1&&(S=r+1,y=0);const F=l.fields[S];a(E,b,e,F,S,y,o)},[r,l.fields,e,a,o]),w=c.useCallback(u=>{const{files:b}=u.target;if(!b||b.length!==1)return;const E=b.item(0);if(E){if(E.size>Vr){p({title:"File upload error",description:`The file ${E.name} exceeded the maximum file size`});return}o(`${m}.${e}`,{...n,image:E}).then()}},[n,e,m,o,p]);return s.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:u=>s.jsx(d.Card,{ref:u.innerRef,...u.draggableProps,...u.dragHandleProps,className:"mb-4",children:s.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[s.jsx(fn,{...f}),s.jsx(dn,{index:e,type:n.type,sectionIndex:r,remove:i,duplicate:v,move:I,upload:w})]})})})});Xr.displayName="FieldWithActions";const Yr=c.memo(t=>{var F;const{field:n,index:e,dropState:r}=t,i=(F=r[n.identifier])==null?void 0:F.disabled,{setFieldValue:o,values:l}=W.useFormikContext(),a=d.useAlertDialog(),{reorderSection:h}=Tt(),{showInfo:p}=d.useToast(),{fieldsOnly:m}=c.use(bt),f=c.useCallback((x,D)=>{for(const N of x){const L=D.indexOf(N);o(`fields.${L}.condition`,null).then(),o(`fields.${L}.conditional`,!1).then()}},[o]),v=c.useCallback(x=>{var L;const D=n.fields[x];if(!D)throw new Error("Could not find field to remove.");const N=[];for(const M of l.fields)((L=M.condition)==null?void 0:L.identifier)===D.identifier&&N.push(M);return{removing:D,affectedSections:N,action:()=>o(`fields.${e}.fields`,He(n.fields,x))}},[n.fields,l.fields,o,e]),I=c.useCallback(x=>{const{affectedSections:D,action:N,removing:L}=v(x),M=()=>{N().then(),f(D,l.fields)};if(D.length>0){const A=D.map(O=>O.label).join(", ");a({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${A} section(s).`,action:"Remove",onAction:M});return}M()},[v,f,l.fields,a]),w=c.useCallback(()=>{const D=n.fields.map((X,ne)=>v(ne)).flatMap(X=>X.affectedSections),N=D.length?"Remove fields and conditions?":"Remove fields?",L=n.fields.length,M=D.map(X=>X.label).join(", "),A=D.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${L} field(s) it contains.`,O=He(l.fields,e),_=()=>o("fields",O);if(D.length>0){a({title:N,description:A,action:"Remove",onAction:()=>{_().then(()=>{f(D,O)})}});return}_().then()},[n.fields,l.fields,e,v,o,a,f]),u=c.useCallback(x=>{const D=x==="up"?e-1:e+1;h(r,n.identifier,e,D,l,o)},[e,h,r,n.identifier,l,o]),b=c.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:xn(l.fields,e)}),[n,e,l.fields]),E=c.useCallback(()=>{const x=n.label||"Untitled section",D=n.fields.map(L=>({...L,identifier:St()})),N={...n,label:x,fields:D};Ge("fields",e+1,N,l,o),p({title:"Section duplicated",description:`The section "${x}" has been duplicated.`})},[n,e,l,o,p]),S=c.useCallback(x=>{Ge(`fields.${e}.fields`,n.fields.length,Br[x],l,o)},[e,n.fields.length,l,o]),y=Hr(S);return s.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:x=>s.jsx(d.Card,{ref:x.innerRef,...x.draggableProps,...x.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[s.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!m&&s.jsx(fn,{...b}),s.jsx(re.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:i,children:D=>s.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:D.innerRef,...D.droppableProps,children:[n.fields.map((N,L)=>s.jsx(Xr,{field:N,index:L,sectionIndex:e,remove:()=>{I(L)}},N.identifier)),D.placeholder,s.jsxs(d.Menu.Root,{children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",children:[s.jsx(d.RiIcon,{icon:"RiAddLine"})," Add field"]})}),s.jsx(d.Menu.Content,{children:y.flat().map(N=>s.jsxs(d.Menu.Item,{onSelect:N.onSelect,children:[N.icon,N.children]},N.value))})]})]})})]}),!m&&s.jsx(dn,{index:e,type:n.type,remove:w,duplicate:E,move:u})]})})})});Yr.displayName="FieldSectionWithActions";const Kr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Zr=c.memo(()=>{const{values:t,setFieldValue:n}=W.useFormikContext(),[e,r]=c.useReducer(Ko,t.fields,jr),{reorderSection:i,reorderField:o}=Tt(),{fieldsOnly:l}=c.use(bt);c.useEffect(()=>{r({type:"update",state:jr(t.fields)})},[r,t.fields]);const a=c.useCallback(m=>{m.type==="SECTION"&&r({type:"hold",fieldId:m.draggableId})},[]),h=c.useCallback(m=>{const{source:f,destination:v,type:I,reason:w,draggableId:u}=m;if(r({type:"release"}),!v||w==="CANCEL")return;if(I==="ROOT"){i(e,u,f.index,v.index,t,n);return}if(I!=="SECTION")throw new Error("Unexpected droppable type.");const[b,E]=Kr(t.fields,f.droppableId)??[],[S,y]=Kr(t.fields,v.droppableId)??[];o(b,E,f.index,S,y,v.index,n)},[t,o,n,i,e]),p=c.useCallback(m=>{ci(m+1,t,n)},[t,n]);return s.jsx(re.DragDropContext,{onDragStart:a,onDragEnd:h,children:s.jsx(re.Droppable,{droppableId:"droppable",type:"ROOT",children:m=>s.jsxs("div",{className:"flex flex-col gap-0",ref:m.innerRef,...m.droppableProps,children:[t.fields.map((f,v)=>s.jsxs(c.Fragment,{children:[s.jsx(Yr,{field:f,index:v,dropState:e,fieldsOnly:l}),!l&&v!==t.fields.length-1&&s.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{p(v)},children:[s.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]})]},f.identifier)),s.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{p(t.fields.length)},children:[s.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]}),m.placeholder]})})})});Zr.displayName="FieldsEditor";const Jo=c.memo(c.forwardRef((t,n)=>{const{onCancel:e,onSave:r,initialTitle:i,initialDescription:o,initialFields:l,showExplainerText:a=!0,showFormTitle:h=!0,fieldsOnly:p=!1,showTabs:m=!0,disableRequiredFields:f=!1,tabsListClassName:v}=t,{showError:I}=d.useToast(),w=c.useCallback(y=>{const F={};y.title||(F.title="Title is required."),(!y.fields||y.fields.length===0)&&(F.fields="At least one field is required.");let x=[];for(const[N,L]of y.fields.entries()){const A=cn.section.getFieldCreationSchema(xn(y.fields,N),`fields.${N}`).map(O=>O.field);x=[...x,...A];for(const[O,_]of L.fields.entries()){const ne=cn[_.type].getFieldCreationSchema(`fields.${N}.fields.${O}`).map(z=>z.field);x=[...x,...ne]}}const D=gt(x,y);if(D&&(F.fields=D.fields),pe(F))return I({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),F},[I]),u=c.useMemo(()=>({title:i??"",description:o??"",fields:l?ai(l):[{...je(St()),label:""}]}),[o,l,i]),b=W.useFormik({initialValues:u,validate:w,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),E=c.useMemo(()=>({title:b.values.title,description:b.values.description,fields:Ur(b.values.fields),meta:{readonly:!1}}),[b.values]),S=c.useMemo(()=>({disableRequiredFields:f,fieldsOnly:p}),[f,p]);return s.jsx(bt,{value:S,children:s.jsx(d.Tabs.Root,{ref:n,defaultValue:"edit",children:s.jsxs("div",{className:"flex flex-col gap-2",children:[m&&s.jsxs(d.Tabs.List,{className:ge.cx("sticky top-0 z-[2000] flex bg-(--color-background)",v),children:[s.jsx(d.Tabs.Trigger,{className:"grow",value:"edit",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(d.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),s.jsx(d.Tabs.Trigger,{className:"grow",value:"preview",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(d.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),s.jsxs(d.Tabs.Content,{value:"edit",children:[a&&s.jsxs(d.Text,{children:["Create your form using various field types. Sections can be"," ",s.jsx("strong",{children:"conditionally rendered"})," based on"," ",s.jsx("strong",{children:"answers to fields in preceding sections. "})]}),s.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:yt,onSubmit:b.handleSubmit,children:[s.jsxs(W.FormikProvider,{value:b,children:[h&&s.jsxs(s.Fragment,{children:[s.jsx(me,{name:"title",render:({setValue:y,value:F,meta:x})=>s.jsx(Ft,{severity:"danger",helpText:x.error??null,children:s.jsx(d.Input.Root,{variant:"outline",size:"md",accentColor:x.error?ie.danger:"primary",children:s.jsx(d.Input.Field,{placeholder:"Form title",value:F,onChange:D=>{y(D.target.value)},maxLength:100})})})}),s.jsx(me,{name:"description",render:({setValue:y,value:F})=>s.jsx(d.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:F,onChange:x=>{y(x.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),s.jsx(Zr,{}),s.jsx("span",{"data-accent-color":ie.danger,className:"text-xs text-(--accent-a11)",children:typeof b.errors.fields=="string"&&b.errors.fields})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&s.jsx(d.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),s.jsx(d.Button,{type:"submit",children:"Save form"})]})]})]}),s.jsx(d.Tabs.Content,{value:"preview",children:s.jsx(qr,{schema:E,hideTitle:!h})})]})})})}));C.BaseField=V,C.BaseFormElement=It,C.BaseSelectField=Gt,C.BooleanField=xe,C.BooleanInput=Xt,C.DateField=st,C.DateInput=Yt,C.FieldSection=q,C.FieldSectionLayout=an,C.FieldTypeToClsMapping=ft,C.FieldTypeToEmptyFieldMapping=Br,C.FileCard=wt,C.FileIcon=ke,C.FormBuilder=Jo,C.FormRenderer=qr,C.ImageCard=Pr,C.ImageViewer=jt,C.ImageViewerProvider=br,C.InputWithHelpText=Ft,C.InputWithLabel=Y,C.InputWithLabelAndHelpText=K,C.LONG_TEXT_FIELD_MAX_LENGTH=he,C.MultiSelectField=Be,C.MultiSelectInput=Kt,C.MultiStringField=Ie,C.MultiStringInput=Ht,C.NumberField=le,C.NumberInput=Zt,C.PatchField=me,C.PatchFormProvider=Xo,C.RadioField=lt,C.RadioInput=Jt,C.SEVERITY_COLOR_MAPPING=ie,C.SHORT_TEXT_FIELD_MAX_LENGTH=Ve,C.SUPPORTED_IMAGE_FILE_TYPES=vn,C.SUPPORTED_PDF_FILE_TYPES=bn,C.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=yn,C.ScanField=at,C.ScanInput=Qt,C.Scanner=Rt,C.SelectField=_e,C.SelectInput=en,C.StringField=ct,C.StringInput=tn,C.StringOrTextField=$e,C.TextField=dt,C.TextInput=nn,C.UploadField=ut,C.UploadInput=rn,C.decodeFieldValues=Ho,C.deserialize=ht,C.deserializeField=on,C.deserializeFields=Ur,C.emptyBaseField=H,C.emptyBooleanField=wr,C.emptyDateField=Ir,C.emptyMultiSelectField=xr,C.emptyMultiStringField=Cr,C.emptyNumberField=Er,C.emptyRadioField=Tr,C.emptyScanField=Fr,C.emptySelectField=Nr,C.emptyStringField=Dr,C.emptyTextField=Mr,C.emptyUploadField=Or,C.encodeFieldValues=Go,C.fieldIcons=qo,C.flattenFields=pt,C.getFieldsMapping=Wr,C.initializeFormValues=vt,C.isConditionMet=sn,C.maxFileSizeB=Vr,C.maxFileSizeKB=_r,C.maxFileSizeMB=Ue,C.useFieldInput=ln,C.useFieldInputs=We,C.useFormikInput=G,C.useImageViewer=Xe,C.validateFields=gt,C.valueIsFile=mt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
45
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return g.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},Vo="DialogDescriptionWarning",$o=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hr(Vo).contentName}}.`;return g.useEffect(()=>{var o;const i=(o=t.current)==null?void 0:o.getAttribute("aria-describedby");n&&i&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},pr=tr,Uo=rr,mr=or,gr=sr,vr=lr,yr=ur;const jt=c.memo(t=>{const{file:n,onClose:e}=t,r=c.useRef(null),i=c.useCallback(()=>{var a;if(!r.current)return;const l=document.createElement("canvas");l.width=r.current.width,l.height=r.current.height,(a=l.getContext("2d"))==null||a.drawImage(r.current,0,0,r.current.width,r.current.height),l.toBlob(h=>{h&&navigator.clipboard.write([new ClipboardItem({"image/png":h})])},"image/png")},[]),o=c.useCallback(()=>{mn.saveAs(n,n.name)},[n]);return s.jsx(pr,{open:!0,onOpenChange:e,children:s.jsx(mr,{children:s.jsx(gr,{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:s.jsxs(vr,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:l=>l.preventDefault(),children:[s.jsxs(d.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[s.jsxs(d.Tooltip.Root,{children:[s.jsx(d.Tooltip.Trigger,{asChild:!0,children:s.jsx(d.IconButton,{onClick:i,"aria-label":"copy to clipboard",children:s.jsx(d.RiIcon,{icon:"RiFileCopyLine"})})}),s.jsx(d.Tooltip.Content,{size:"sm",children:"Copy"})]}),s.jsxs(d.Tooltip.Root,{children:[s.jsx(d.Tooltip.Trigger,{asChild:!0,children:s.jsx(d.IconButton,{onClick:o,"aria-label":"download",children:s.jsx(d.RiIcon,{icon:"RiDownload2Line"})})}),s.jsx(d.Tooltip.Content,{size:"sm",children:"Download"})]}),s.jsx(d.Separator,{orientation:"vertical",size:"sm"}),s.jsx(yr,{asChild:!0,children:s.jsx(d.IconButton,{onClick:e,"aria-label":"close",children:s.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),s.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:s.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});jt.displayName="ImageViewer";const br=c.memo(t=>{const{children:n}=t,[e,r]=c.useState(null),i=c.useCallback(()=>{r(null)},[]),o=c.useCallback(h=>{r(h(i))},[i]),l=c.useCallback(()=>{e&&(e.onClose&&e.onClose(),i())},[i,e]),a=c.useMemo(()=>o,[o]);return s.jsxs(En.Provider,{value:a,children:[n,e&&s.jsx(jt,{file:e.file,onClose:l})]})});br.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:i,inputId:o,labelId:l,image:a}=t,[h,p]=c.useState(void 0),m=Xe(),f=i?ie[i]:"base";c.useEffect(()=>{a instanceof Promise?a.then(p).catch(console.error):p(a)},[a]);const v=h?URL.createObjectURL(h):void 0,I=c.useCallback(()=>{h&&m(()=>({file:h}))},[m,h]);return s.jsxs("div",{className:"flex flex-col gap-1",children:[h&&s.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:v,alt:h.name,onClick:I}),s.jsx("label",{className:ge.cx(n,"flex flex-col gap-1 w-max max-w-full"),htmlFor:o,children:s.jsx(d.Text,{accentColor:f,size:"sm",id:l,weight:"medium",className:"text-wrap",children:e})}),r]})},K=t=>{const{children:n,...e}=t;return s.jsx(Ft,{...e,children:n})},Ht=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),f=o?null:a,v=o?"":h,{name:I,onChange:w,onBlur:u}=p,b=`${n}-droppable`,{disabled:E}=m,S=p.value??xt,[y,F]=c.useState(""),[x,D]=c.useState(""),N=x||f,L=c.useCallback(z=>{w(z),u(z)},[w,u]),M=c.useCallback(z=>{S&&S.findIndex(Z=>Z===z.target.value.trim())>=0?D("All options must be unique"):z.target.value?D(""):D("Option cannot be empty"),F(z.target.value)},[F,S]),A=c.useCallback(()=>{if(x)return;if(!y.trim()){D("Option cannot be empty");return}const z=y.trim();L([...S,z]),F("")},[y,x,L,S]),O=c.useCallback(z=>{z.key==="Enter"&&(z.preventDefault(),A())},[A]),_=c.useCallback(z=>{L(He(S,z))},[S,L]),X=c.useCallback(z=>{if(!z.destination)return;const Z=z.source.index,ze=z.destination.index;L(Et(S,Z,ze))},[L,S]),ne=c.useCallback(()=>{u(S)},[u,S]);return s.jsx(re.DragDropContext,{onDragEnd:X,children:s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(K,{helpText:N,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:v,image:o?void 0:l.image,children:(!E||S.length===0)&&s.jsxs("div",{className:"flex gap-2",children:[s.jsx(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:s.jsx(d.Input.Field,{value:y,onChange:M,onKeyDown:O,id:n,placeholder:l.placeholder,onBlur:ne,name:I,...m})}),s.jsx(d.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!x||E,onClick:A,children:s.jsx(d.RiIcon,{icon:"RiAddLine"})})]})})}),s.jsx(re.Droppable,{droppableId:b,children:z=>s.jsxs("div",{className:"flex flex-col",...z.droppableProps,ref:z.innerRef,children:[S.map((Z,ze)=>s.jsx(re.Draggable,{draggableId:`${Z}-draggable`,index:ze,isDragDisabled:E,children:({draggableProps:ae,dragHandleProps:hn,innerRef:Ct})=>s.jsxs(d.Badge,{...hn,...ae,ref:Ct,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[s.jsx("span",{className:"truncate",children:typeof Z=="object"&&"label"in Z?Z.label:Z}),s.jsx(d.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:E,onClick:()=>{_(ze)},children:s.jsx(d.RiIcon,{icon:"RiCloseLargeLine"})})]})},Z)),z.placeholder]})})]})})});Ht.displayName="MultiStringInput";const Cr={...H,type:"multi-string",minimum_length:0,maximum_length:null},Ee=class Ee extends V{constructor(e){const{minimum_length:r,maximum_length:i,placeholder:o,...l}=e;super({...l,type:"multi-string"});T(this,"minLength");T(this,"maxLength");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.minLength=r??0,this.maxLength=i??1/0,this.placeholder=o??"Press enter to add a new option"}getInput(e){return s.jsx(Ht,{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 Ee(e)}};T(Ee,"fieldTypeName","Multi-string"),T(Ee,"fieldTypeDescription","Allows the user to provide multiple unique strings."),T(Ee,"Icon",k.RiListCheck);let Ie=Ee;class Gt extends V{constructor(e){const{placeholder:r="",...i}=e;super(i);T(this,"options");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.placeholder=r;const o=new Set;this.options=e.options.map(l=>(typeof l=="string"&&(l={label:l,value:l}),o.add(l.label),l)),o.size!==e.options.length&&console.error(`${e.options.length-o.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 Ie({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const Xt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onBlur:v,onChange:I,value:w}=p,u=o?null:a,b=o?"":h,E=c.useCallback(y=>{I(!!y),v(!!y)},[v,I]),S=c.useCallback(()=>{v(w)},[v,w]);return s.jsx(K,{helpText:u,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:o?void 0:l.image,className:"items-center flex-row-reverse justify-end gap-2",children:s.jsx(d.Checkbox.Root,{id:n,name:f,checked:w??!1,onCheckedChange:E,onBlur:S,size:"sm",accentColor:"primary",variant:"surface",...m,children:s.jsx(d.Checkbox.Indicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})})})})})});Xt.displayName="BooleanInput";const wr={...H,type:"boolean"},Se=class Se extends V{constructor(e){super({...e,type:"boolean"});T(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 s.jsx(Xt,{...e,field:this})}};T(Se,"fieldTypeName","Checkbox"),T(Se,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),T(Se,"Icon",k.RiCheckboxCircleLine);let xe=Se;const Wo={...H,type:"custom"};class ot extends V{constructor(e,r){super({...e,type:"custom"});T(this,"Component");T(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 s.jsx(r,{field:this,...e})}}T(ot,"fieldTypeName","Custom"),T(ot,"fieldTypeDescription","Allows re-rendering of field already in the form");const Yt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I}=p,[w,u]=c.useState(!1),b=o?null:a,E=o?"":h,S=p.value?new Date(p.value):void 0,y=c.useCallback(x=>{v(x==null?void 0:x.toISOString()),u(!1)},[v]),F=c.useCallback(x=>{u(x),x||I(p.value)},[p.value,I]);return s.jsx(K,{helpText:b,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:E,image:o?void 0:l.image,children:s.jsxs(d.Popover.Root,{open:w,onOpenChange:F,children:[s.jsx(d.Popover.Trigger,{asChild:!0,children:s.jsxs(d.Button,{id:n,name:f,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...m,children:[S?S.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",s.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),s.jsx(d.Popover.Content,{align:"start",children:s.jsx(d.DayPicker,{required:!1,mode:"single",variant:"solid",selected:S,onSelect:y})})]})})})});Yt.displayName="DateInput";const Ir={...H,type:"date"},Te=class Te extends V{constructor(e){super({...e,type:"date"});T(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 s.jsx(Yt,{field:this,...e})}};T(Te,"fieldTypeName","Date"),T(Te,"fieldTypeDescription","Allows specifying a date."),T(Te,"Icon",k.RiCalendarLine);let st=Te;const Kt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I}=p,w=o?null:a,u=o?"":h,b=p.value??xt,E=c.useCallback(y=>{const F=y.length>0?y:void 0;v(F),I(F)},[I,v]),S=c.useCallback(y=>{y||I(b)},[b,I]);return s.jsx(K,{helpText:w,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:u,image:o?void 0:l.image,children:s.jsxs(d.Menu.Root,{onOpenChange:S,align:"start",children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsxs(d.Button,{id:n,name:f,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...m,children:[s.jsx("span",{className:"truncate",children:b&&b.length>0?b.join(", "):l.placeholder}),s.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),s.jsx(d.Menu.Content,{children:s.jsx(d.Menu.Scroll,{children:s.jsxs(d.Menu.MultiSelectGroup,{values:b,onValuesChange:E,children:[s.jsxs(d.Menu.SelectAllItem,{children:[s.jsx(d.Menu.CheckboxItemIndicator,{children:y=>y?s.jsx(d.RiIcon,{icon:"RiSubtractLine"}):s.jsx(d.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),l.options.map(y=>s.jsxs(d.Menu.MultiSelectItem,{value:y.value,children:[s.jsx(d.Menu.SelectedIndicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))]})})})]})})})});Kt.displayName="MultiSelectInput";const xr={...H,type:"multi-select",options:[]},Fe=class Fe extends Gt{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 Fe(n)}getInput(n){return s.jsx(Kt,{field:this,...n})}};T(Fe,"fieldTypeName","Multi-select"),T(Fe,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),T(Fe,"Icon",k.RiCheckboxLine);let Be=Fe;const Zt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p,touched:m,helpers:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,E=o?null:a,S=o?"":h,[y,F]=c.useState(void 0);c.useEffect(()=>{F(b)},[b]);const x=c.useCallback(N=>{const L=N.target.valueAsNumber,M=Number.isNaN(L)?void 0:L;F(M),(m||!l.onlyValidateAfterTouched)&&f.setError(l.getError(M))},[l,f,m]),D=c.useCallback(()=>{u(y),w(y)},[y,w,u]);return s.jsx(K,{helpText:E,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:S,image:o?void 0:l.image,children:s.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:s.jsx(d.Input.Field,{id:n,name:I,onChange:x,onBlur:D,value:y??"",type:"number",min:l.minimum,max:l.maximum,step:l.integers?1:.1,placeholder:l.placeholder,...v})})})})});Zt.displayName="NumberInput";const Er={...H,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Sr=t=>"fields"in t,ee=class ee extends V{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:i=Number.MAX_SAFE_INTEGER,integers:o=!1,placeholder:l="Enter a number",...a}=e;super({...a,type:"number"});T(this,"minimum");T(this,"maximum");T(this,"integers");T(this,"placeholder");this.minimum=r,this.maximum=i,this.integers=o,this.placeholder=l}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ee({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new ee({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new xe({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(o=>{if(typeof o=="number"&&o<r)return`Must be at least ${this.minimum}.`}),typeof i=="number"&&e.push(o=>{if(typeof o=="number"&&o>i)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(o=>{if(typeof o=="number"&&!Number.isInteger(o))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 ee(e)}getInput(e){return s.jsx(Zt,{field:this,...e})}};T(ee,"fieldTypeName","Number"),T(ee,"fieldTypeDescription","Allows specifying a number within a given range."),T(ee,"Icon",k.RiHashtag),T(ee,"_validateMin",e=>(r,i)=>{const o=Sr(i)?Q(i,e):i;return typeof o.maximum=="number"&&typeof r=="number"&&o.maximum<r?"Minimum cannot be greater than minimum.":null}),T(ee,"_validateMax",e=>(r,i)=>{const o=Sr(i)?Q(i,e):i;return typeof o.minimum=="number"&&typeof r=="number"&&o.minimum>r?"Maximum cannot be less than minimum.":null});let le=ee;const Jt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I,value:w}=p,u=o?null:a,b=o?"":h,E=c.useCallback(y=>{v(y??void 0),I(y??void 0)},[I,v]),S=c.useCallback(()=>{v(void 0),I(void 0)},[I,v]);return s.jsx(K,{helpText:u,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:o?void 0:l.image,children:s.jsxs(d.RadioGroup.Root,{id:n,name:f,className:"flex flex-col gap-1",accentColor:"base",variant:"surface",size:"sm",value:w??"",onValueChange:E,...m,children:[l.options.map(y=>s.jsxs("label",{className:"flex gap-2 items-center min-w-0",children:[s.jsx(d.RadioGroup.Item,{value:y.value,children:s.jsx(d.RadioGroup.Indicator,{children:s.jsx(d.RiIcon,{icon:"RiCircleFill"})})},y.value),s.jsx(d.Text,{size:"sm",accentColor:"base",className:"truncate",children:y.label})]})),!!w&&s.jsxs(d.Button,{onClick:S,className:"w-max -mx-2",type:"button",variant:"ghost",accentColor:"base",size:"sm",children:[s.jsx(d.RiIcon,{icon:"RiCloseLine"})," Clear"]})]})})})});Jt.displayName="SelectInput";const Tr={...H,type:"radio",options:[]},Ne=class Ne extends V{constructor(e){const{options:r,...i}=e;super({...i,type:"radio"});T(this,"options");T(this,"onlyValidateAfterTouched",!1);const o=new Set;this.options=r.map(l=>(typeof l=="string"&&(l={label:l,value:l}),o.add(l.label),l)),o.size!==r.length&&console.error(`${r.length-o.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,r)}serialize(){return{...super._serialize(),options:this.options}}static deserialize(e){if(e.type!=="radio")throw new Error("Type mismatch.");return new Ne(e)}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new Ie({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}getInput(e){return s.jsx(Jt,{field:this,...e})}};T(Ne,"fieldTypeName","Option list"),T(Ne,"fieldTypeDescription","Allows the user to select a single option from a list of options."),T(Ne,"Icon",k.RiRadioButtonFill);let lt=Ne;const Qt=c.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:i,size:o,severity:l,showInputOnly:a,field:h,fieldProps:p,helpers:m,touched:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,[E,S]=c.useState(!1),y=a?null:i,F=a?"":r,[x,D]=c.useState(void 0);c.useEffect(()=>{D(b)},[b]);const N=c.useCallback(_=>{D(_.target.value||void 0),(f||!h.onlyValidateAfterTouched)&&m.setError(h.getError(_.target.value))},[h,m,f]),L=c.useCallback(()=>{u(x),w(x)},[x,w,u]),M=c.useCallback(_=>{u(_),S(!1)},[u]),A=c.useCallback(()=>{u(void 0)},[u]),O=c.useCallback(_=>{S(_),_||w(b)},[w,b]);return s.jsx(K,{helpText:y,severity:l,children:s.jsx(Y,{size:o,severity:l,inputId:n,labelId:e,label:F,image:a?void 0:h.image,className:"flex-col items-start justify-start gap-2",children:s.jsxs("div",{className:"flex w-full items-center gap-2",children:[s.jsxs(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:[s.jsx(d.Input.Field,{id:n,className:"truncate",name:I,value:x??"",type:"text",placeholder:"Enter a qr or barcode",onChange:N,onBlur:L,...v}),!!b&&s.jsx(d.Input.Slot,{children:s.jsx(d.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"xs",onClick:A,children:s.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),s.jsxs(pr,{open:E,onOpenChange:O,children:[s.jsx(Uo,{asChild:!0,children:s.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",accentColor:"base",children:[s.jsx(d.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),s.jsxs(mr,{children:[s.jsx(gr,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),s.jsx(vr,{className:"fixed inset-0",children:s.jsx(Rt,{onScan:M})})]})]})]})})})});Qt.displayName="QrInput";const Rt=c.memo(t=>{const{onScan:n}=t,{showError:e}=d.useToast(),r=c.useCallback(l=>{n(l.getText())},[n]),i=c.useCallback(()=>{e({title:"Scan Error",description:"An unknown error occurred while scanning."})},[e]),{ref:o}=ti.useZxing({onDecodeResult:r,onError:i});return s.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center overflow-hidden p-4 gap-4 bg-(--color-background)",children:[s.jsx("div",{className:"flex w-full",children:s.jsx(yr,{asChild:!0,children:s.jsx(d.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:s.jsx(d.RiIcon,{icon:"RiCloseLine"})})})}),s.jsx("div",{className:"relative grow w-full max-h-full overflow-hidden",children:s.jsx("video",{className:"rotate-y-180 size-full",ref:o})})]})});Rt.displayName="QrScanner";const Fr={...H,type:"qr"},Le=class Le extends V{constructor(e){super({...e,type:"qr"});T(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="qr")throw new Error("Type mismatch.");return new Le(e)}getInput(e){return s.jsx(Qt,{...e,field:this})}};T(Le,"fieldTypeName","Scan"),T(Le,"fieldTypeDescription","Used for scanning/reading QR and barcodes."),T(Le,"Icon",k.RiFullscreenLine);let at=Le;const en=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p},m]=G(t),{name:f,onChange:v,onBlur:I,value:w}=p,u=o?null:a,b=o?"":h,E=c.useCallback(y=>{v(y),I(y)},[I,v]),S=c.useMemo(()=>l.options.find(y=>y.value===w),[l.options,w]);return s.jsx(K,{helpText:u,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:o?void 0:l.image,children:s.jsxs(d.Menu.Root,{align:"start",children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsxs(d.Button,{id:n,name:f,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...m,children:[s.jsx("span",{className:"truncate",children:S?S.label:l.placeholder}),s.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),s.jsx(d.Menu.Content,{children:s.jsx(d.Menu.Scroll,{children:s.jsx(d.Menu.SelectGroup,{required:!1,value:w??void 0,onValueChange:E,children:l.options.map(y=>s.jsxs(d.Menu.SelectItem,{value:y.value,children:[s.jsx(d.Menu.SelectedIndicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))})})})]})})})});en.displayName="SelectInput";const Nr={...H,type:"select",options:[]},De=class De extends Gt{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 s.jsx(en,{field:this,...n})}};T(De,"fieldTypeName","Dropdown"),T(De,"fieldTypeDescription","Allows the user to select a single option from a list of options."),T(De,"Icon",k.RiMenuFoldLine);let _e=De;const Ve=500,he=1e4,Lr=t=>"fields"in t;class $e extends V{constructor(e){const{minLength:r,maxLength:i,placeholder:o="",...l}=e;super(l);T(this,"minLength");T(this,"maxLength");T(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=i?Math.max(i,0):he,this.placeholder=o}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new le({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 le({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:he,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}}}T($e,"_validateMin",e=>(r,i)=>{const o=Lr(i)?Q(i,e):i;return typeof o.maximum_length=="number"&&typeof r=="number"&&o.maximum_length<r?"Minimum cannot be greater than maximum.":null}),T($e,"_validateMax",e=>(r,i)=>{if(typeof r!="number")return null;const{minimum_length:o}=Lr(i)?Q(i,e):i;return typeof o!="number"?null:o>r?"Maximum cannot be less than minimum.":null});const tn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p,touched:m,helpers:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,E=o?null:a,S=o?"":h,[y,F]=c.useState(void 0);c.useEffect(()=>{F(b)},[b]);const x=c.useCallback(N=>{F(N.target.value||void 0),(m||!l.onlyValidateAfterTouched)&&f.setError(l.getError(N.target.value))},[l,f,m]),D=c.useCallback(()=>{u(y),w(y)},[y,w,u]);return s.jsx(K,{helpText:E,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:S,image:o?void 0:l.image,children:s.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:s.jsx(d.Input.Field,{id:n,className:"truncate",name:I,value:y??"",type:l.inputType,placeholder:l.placeholder,onChange:x,onBlur:D,...v})})})})});tn.displayName="StringInput";const Dr={...H,type:"string",maximum_length:Ve,input_type:"text"},Me=class Me extends $e{constructor(e){const{inputType:r="text",...i}=e,o=e.maxLength?Math.min(Ve,e.maxLength):Ve,l=e.minLength?Math.min(e.minLength,o):void 0;super({...i,maxLength:o,minLength:l,type:"string"});T(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:o,...l}=e;return new Me({...l,maxLength:r,minLength:i,inputType:o,placeholder:"Enter a short description"})}getInput(e){return s.jsx(tn,{field:this,...e})}};T(Me,"fieldTypeName","Short Text"),T(Me,"fieldTypeDescription",`Short text fields can hold up to ${Ve} characters on a single line.`),T(Me,"Icon",k.RiInputField);let ct=Me;const nn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:o,field:l,helpText:a,label:h,fieldProps:p,touched:m,helpers:f},v]=G(t),{name:I,onBlur:w,onChange:u,value:b}=p,E=o?null:a,S=o?"":h,[y,F]=c.useState(void 0);c.useEffect(()=>{F(b)},[b]);const x=c.useCallback(N=>{F(N.target.value||void 0),(m||!l.onlyValidateAfterTouched)&&f.setError(l.getError(N.target.value))},[l,f,m]),D=c.useCallback(()=>{u(y),w(y)},[y,w,u]);return s.jsx(K,{helpText:E,severity:i,children:s.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:S,image:o?void 0:l.image,children:s.jsx(d.TextArea,{id:n,value:y??"",name:I,onChange:x,onBlur:D,className:"field-sizing-content min-h-12",placeholder:l.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...v})})})});nn.displayName="TextInput";const Mr={...H,type:"text",maximum_length:he},Pe=class Pe extends $e{constructor(n){const e=n.maxLength?Math.min(he,n.maxLength):he,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 s.jsx(nn,{field:this,...n})}};T(Pe,"fieldTypeName","Paragraph"),T(Pe,"fieldTypeDescription",`Paragraph fields can hold up to ${he} characters and can have multiple lines.`),T(Pe,"Icon",k.RiAlignJustify);let dt=Pe;const Pr=c.memo(c.forwardRef((t,n)=>{const{file:e,alt:r,error:i,rightSlot:o,className:l,...a}=t;return s.jsxs("div",{className:ge.cx(l,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...a,children:[!e&&!i&&s.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:s.jsx(d.Spinner,{})}),s.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!i&&s.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),s.jsxs("div",{className:ge.cx("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[i?s.jsx(d.RiIcon,{icon:"RiFileWarningLine"}):e&&s.jsx(ke,{fileType:e.type}),s.jsx(d.Text,{className:"truncate",size:"sm",children:i??(e==null?void 0:e.name)}),o]})]})})),ko=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)},rn=c.memo(t=>{var N;const[{inputId:n,labelId:e,size:r,severity:i,helpText:o,showInputOnly:l,field:a,fieldProps:h},p]=G(t),{name:m,onChange:f,onBlur:v}=h;let[{label:I}]=G(t);I=l?"":I;const w=h.value??xt,u=c.useRef(null),b=c.useMemo(()=>l?null:o||(a.maxFileSize?`Maximum file size: ${a.maxFileSize}MB`:null),[a.maxFileSize,o,l]),E=c.useCallback(()=>{var L;(L=u.current)==null||L.click()},[]),S=c.useCallback(()=>{if(!u.current)return;const L=u.current.files;if(!L){v([]);return}const M=Array.from(L),A=[...w,...M];f(A),v(A)},[v,f,w]),y=c.useCallback(L=>{const M=[...w];M.splice(L,1),f(M.length>0?M:void 0)},[w,f]);c.useEffect(()=>{if(!u.current)return;const L=new AbortController;return u.current.addEventListener("cancel",()=>{v(void 0)},{signal:L.signal}),()=>{L.abort()}},[v,w]);const D=a.maxFiles>1?"Select files":"Select a file";return s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(K,{helpText:b,severity:i,children:s.jsxs(Y,{size:r,severity:i,inputId:n,labelId:e,label:I,image:l?void 0:a.image,children:[s.jsx("div",{className:"flex gap-2",children:s.jsxs(d.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:E,id:"upload-input-upload-button",type:"button",...p,children:[s.jsx(d.RiIcon,{icon:"RiUpload2Line"})," ",D]})}),s.jsx("input",{id:n,name:m,type:"file",ref:u,accept:(N=a.extensions)==null?void 0:N.join(","),multiple:a.maxFiles>1,className:"hidden",onChange:S,value:""})]})}),Array.isArray(w)&&w.length>0&&s.jsx("div",{className:"flex h-max flex-col gap-2",children:w.map((L,M)=>s.jsx(Ar,{field:a,file:L,onRemove:()=>{y(M)},disabled:p.disabled},M))})]})});rn.displayName="UploadInput";const Ar=c.memo(t=>{const{file:n,field:e,onRemove:r,disabled:i}=t,[o,l]=c.useState(null),a=Xe(),h=c.useMemo(()=>o&&e.getError([o]),[e,o]),{url:p,name:m}=c.useMemo(()=>{let u=null,b,E;return o!=null&&o.type.startsWith("image/")&&(u=URL.createObjectURL(o)),o?(b=o.name,E=ko(o.size)):(b="Downloading...",E="..."),{url:u,name:b,size:E}},[o]);c.useEffect(()=>{n instanceof Promise?n.then(l).catch(console.error):l(n)},[n]);const f=c.useCallback(u=>{if(u.stopPropagation(),!o)throw new Error("Cannot download a file that is not resolved.");const b=new Blob([o]);mn.saveAs(b,m)},[m,o]),v=c.useCallback(u=>{u.stopPropagation(),r()},[r]),I=c.useCallback(()=>{o&&a(u=>({file:o,onDelete:i?void 0:()=>{r(),u()}}))},[i,r,a,o]),w=c.useMemo(()=>s.jsxs(d.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[s.jsx(d.IconButton,{"aria-label":`Download ${m}`,type:"button",onClick:f,disabled:!o,children:s.jsx(d.RiIcon,{icon:"RiDownload2Line"})}),!i&&s.jsx(d.IconButton,{type:"button","aria-label":`Remove ${m}`,disabled:i,onClick:v,children:s.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[i,v,f,m,o]);return p?s.jsx(Pr,{className:"cursor-pointer",onClick:I,file:o,error:h??void 0,rightSlot:w}):s.jsx(wt,{file:o,error:h??void 0,rightSlot:w})});Ar.displayName="DisplayFile";const Or={...H,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1};function zr(t,n){return t.name===n.name&&t.size===n.size&&t.type===n.type}const Ae=class Ae extends V{constructor(e){const{extensions:r,maximum_files:i,maximum_size:o,...l}=e;super({...l,type:"upload"});T(this,"extensions");T(this,"maxFileSize");T(this,"maxFiles");T(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof o=="number"?o: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(o=>zr(i,o)))||!r.every(i=>e.some(o=>zr(o,i))))}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new le({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 le({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${Ue}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:Ue,integers:!0}),showDirectly:!1},{field:new Be({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??Ue,i=r*1e3*1e3,o=this.maxFiles||1;return e.push(l=>{if(l&&l.some(a=>a.size>i))return`Files must be at most ${r}MB.`}),e.push(l=>{if(l&&l.length>o)return`You can only upload ${o} 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 s.jsx(rn,{field:this,...e})}};T(Ae,"fieldTypeName","Upload"),T(Ae,"fieldTypeDescription","Allows a file to be uploaded."),T(Ae,"Icon",k.RiUpload2Line);let ut=Ae;const ft={date:st,number:le,boolean:xe,select:_e,string:ct,text:dt,custom:ot,upload:ut,qr:at,"multi-string":Ie,"multi-select":Be,radio:lt},Br={date:Ir,number:Er,boolean:wr,select:Nr,string:Dr,text:Mr,custom:Wo,upload:Or,qr:Fr,"multi-string":Cr,"multi-select":xr,radio:Tr},qo={boolean:"RiCheckboxCircleLine",date:"RiCalendarLine","multi-string":"RiListCheck",number:"RiHashtag",qr:"RiFullscreenLine","multi-select":"RiCheckboxLine",select:"RiMenuFoldLine",string:"RiInputField",text:"RiAlignJustify",upload:"RiUpload2Line",custom:"RiCodeSSlashLine",section:"RiFolderLine",radio:"RiRadioButtonFill"},Ue=50,_r=Ue*1e3,Vr=_r*1e3,$r=c.memo(t=>{const{field:n,...e}=t,[{value:r}]=W.useField(n.options.clonedFieldIdentifier),i=c.useMemo(()=>{const o=n.options.getFieldToClone(r);return o?ht(o):null},[n.options,r]);return ln(i,e)});$r.displayName="FieldInputCloner";class jo extends ot{constructor(n){super(n,$r)}}const on=t=>{const n=t.type;return ft[n].deserialize(t)},ht=t=>t.type==="section"?q.deserialize(t):on(t);function Ur(t){return t.map(n=>ht(n))}function pt(t){const n=[];for(const e of t)if(e instanceof q)for(const r of e.fields)n.push(r);else{if(!(e instanceof V))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Wr(t){const n=pt(t),e={};for(const r of n)e[r.identifier]=r;return e}function Ho(t,n){const e=pt(t),r={};for(const i of e){const o=n[i.identifier]??null;o!==null?r[i.identifier]=i.decodeJsonToValue(o):r[i.identifier]=o}return r}function Go(t,n){const e=pt(t),r={};for(const i of e){const o=n[i.identifier];r[i.identifier]=i.encodeValueToJson(o)}return r}function mt(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function sn(t,n){if(!t)return!0;if(mt(n)||mt(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 ln=(t,n)=>c.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),We=(t,n)=>{const e=c.useMemo(()=>t.map(r=>s.jsx(c.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return s.jsx("div",{className:"flex flex-col gap-4",children:e})},an=c.memo(t=>{const{field:n,...e}=t,{label:r,description:i,fields:o,condition:l}=n,{values:a,setFieldValue:h}=W.useFormikContext(),p=l!=null&&l.identifier?Q(a,l.identifier):void 0,m=c.useMemo(()=>sn(l,p),[l,p]);c.useEffect(()=>{if(!m)for(const v of o)h(v.getId(),"").then()},[m,o,h]);const f=We(o,e);return m?s.jsx(d.Card,{variant:"soft",children:s.jsxs("div",{className:"flex flex-col gap-4",children:[(r||i)&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col",children:[s.jsx(d.Heading,{size:"md",children:r}),s.jsx(d.Text,{accentColor:"base",children:i})]}),s.jsx(d.Separator,{size:"full"})]}),f]})}):null});an.displayName="FieldSectionLayout";const Oe=class Oe extends It{constructor(e){const{label:r=null,fields:i,condition:o=null,conditional:l,...a}=e;super({...a,type:"section"});T(this,"label");T(this,"fields");T(this,"condition");this.fields=i,this.condition=o,this.label=r,l===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const i=r&&`${r}.`;return[{field:new xe({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 _e({label:"Field",description:"The field to use for the condition.",options:e.map(o=>!o.label||o.type==="upload"?null:{label:o.label,value:o.identifier}).filter(o=>!!o),identifier:`${i}condition.identifier`,required:!0}),new jo({label:"Value",identifier:`${i}condition.value`,required:!0,clonedFieldIdentifier:`${i}condition.identifier`,getFieldToClone(o){if(!o)return null;const l=e.find(a=>a.identifier===o);return l?{...l,label:"Value",identifier:`${i}condition.value`,description:"The value to compare against.",required:l.type!=="boolean"}:(console.error("Could not find field with identifier",o),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(on);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 o=i.getId(),l=i.getError(Q(e,o),e);l&&ve(r,i.getId(),l)}return r}getInput(e){return s.jsx(an,{field:this,...e})}};T(Oe,"fieldTypeName","Section"),T(Oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let q=Oe;const pe=t=>Object.keys(t).length>0,gt=(t,n)=>{const e={};for(const r of t)if(r instanceof q){if(r.condition){const{identifier:i}=r.condition;if(!sn(r.condition,Q(n,i)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof V))throw new Error("Invalid field type");const i=r.getId(),o=r.getError(Q(n,i),n);o&&ve(e,i,o)}if(pe(e))return e},vt=(t,n)=>t.reduce((e,r)=>{if(r instanceof q)return{...e,...vt(r.fields,n)};const i=r.getId(),o=e[i];switch(o){case"":ve(e,i,void 0);break;case[]:ve(e,i,void 0);break;default:ve(e,i,o??void 0)}return e},ni(n)),kr=(t,n,e)=>t.reduce((r,i)=>{if(i instanceof q)return{...r,...kr(i.fields,n,e)};if(i instanceof V){const o=i.getId(),l=n[o],a=e[o];i.isEqual(l,a)||ve(r,o,a)}return r},{}),qr=c.memo(c.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:i,onSubmit:o,submitText:l="Submit",cancelText:a,onCancel:h,onDirty:p,onDirtyChange:m,hideTitle:f=!e.title,hideDescription:v,className:I,buttonProps:w,enableReinitialize:u=!1,excludeUnchangedFields:b=!1}=t,{readonly:E}=e.meta,S=c.useId(),y=c.useMemo(()=>vt(e.fields,r),[e.fields,r]),F=c.useCallback(O=>{o==null||o(b?kr(e.fields,y,O):O)},[b,y,o,e.fields]),x=W.useFormik({initialValues:y,onSubmit:F,validate:O=>gt(e.fields,O),validateOnBlur:!1,validateOnChange:!1,enableReinitialize:u}),{dirty:D}=x,N=c.useMemo(()=>typeof e.title=="string"?s.jsx(d.Heading,{size:"md",children:e.title}):e.title,[e.title]),L=c.useMemo(()=>typeof e.description=="string"?s.jsx(d.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),M=c.useCallback((O,_)=>{Wr(e.fields)[O].isEqual(y[O],_)||i==null||i({...x.values,[O]:_},{[O]:_})},[x.values,y,i,e.fields]),A=We(e.fields,{formId:S,disabled:E,onValuesChange:M});return c.useEffect(()=>{D&&p&&p(),m&&m(D)},[D,p,m]),s.jsx(W.FormikProvider,{value:x,children:s.jsxs("form",{id:S,ref:n,className:ge.cx(I,"flex flex-col gap-2"),onSubmit:x.handleSubmit,children:[!f&&s.jsx(d.Card,{variant:"soft",children:s.jsxs("div",{className:"flex flex-col gap-1",children:[N,!v&&L]})}),A,!E&&s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a&&s.jsxs(d.Button,{accentColor:ie.danger,...w,type:"button",onClick:h,children:[s.jsx(d.RiIcon,{icon:"RiCloseLine"}),a]}),s.jsxs(d.Button,{...w,type:"submit",disabled:!x.isValid,accentColor:"success",children:[s.jsx(d.RiIcon,{icon:"RiCheckLine"}),l]})]})]})})})),me=c.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=W.useFormikContext(),[i,o,l]=W.useField(n),a=c.useMemo(()=>{const h=p=>{l.setValue(p,!1)};return e({value:i.value,meta:o,setValue:h,patchValue:()=>{r()}})},[e,i.value,o,r,l]);return s.jsx(s.Fragment,{children:a})});me.displayName="PatchField";const Xo=c.memo(c.forwardRef((t,n)=>{const{children:e,schema:r,values:i,onPatch:o,onError:l,requiresDiff:a=!0,onDirtyChange:h,...p}=t,m=c.useMemo(()=>vt(r.fields,i),[r.fields,i]),f=c.useCallback(S=>{const y={};for(const F in S){const x=S[F];x!==m[F]&&x!==void 0&&(y[F]=x)}return y},[m]),v=c.useCallback(S=>{const y=f(S);a&&!pe(y)||o(y)},[f,o,a]),I=c.useCallback(S=>{const y=gt(r.fields,S);if(y&&l(y),h){const F=f(S);h(pe(F))}return y},[r.fields,h,l,f]),w=W.useFormik({initialValues:m,onSubmit:v,validate:I,validateOnBlur:!1,validateOnChange:!1}),u=c.useCallback(()=>{if(h){const S=f(w.values);pe(S)&&h(!0)}},[w.values,f,h]),{errors:b,resetForm:E}=w;return c.useEffect(()=>{pe(b)&&E({values:m,errors:{}})},[b,m,E]),s.jsx(W.FormikProvider,{value:w,children:s.jsx("form",{...p,ref:n,onSubmit:w.handleSubmit,onChange:u,children:e})})})),yt="form-builder",Yo=[["string","text"],["select","multi-select","upload","qr","radio"],["boolean","date","number","multi-string"]],cn={...ft,section:q},bt=c.createContext({}),Ko=(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}},Zo=(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}}},jr=t=>{var e,r,i;const n={};for(let o=0;o<t.length;o++){const l=t[o];if(!l)throw new Error("Field is undefined.");const a=o>0?(e=n[t[o-1].identifier])==null?void 0:e.conditionFields:void 0,h=new Set(a);(r=l.condition)!=null&&r.identifier&&h.add(l.condition.identifier),n[l.identifier]={disabled:!1,conditionFields:h,conditionIndex:Zo(t,(i=l.condition)==null?void 0:i.identifier),index:o,label:l.label}}return n},dn=c.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:i,duplicate:o,move:l,upload:a}=t;if(e!=="section"&&!a)throw new Error("Upload function prop must be defined for non-section fields.");const{values:h}=W.useFormikContext(),p=c.useRef(null),m=c.useMemo(()=>{const f=[{Icon:k.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:o}}];return f.push({Icon:k.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:i}}),e!=="section"&&f.unshift({Icon:k.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var v;(v=p.current)==null||v.click()}}}),(r===void 0&&n!==h.fields.length-1||r!==void 0&&(r<h.fields.length-1||n!==h.fields[r].fields.length-1))&&f.unshift({Icon:k.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{l("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&f.unshift({Icon:k.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{l("up")}}}),f},[o,n,l,i,r,e,h.fields]);return s.jsxs(s.Fragment,{children:[s.jsx(d.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:m.map(f=>s.jsx(d.IconButton,{type:"button","aria-label":f.text,...f.buttonProps,children:s.jsx(f.Icon,{})},f.key))}),s.jsx("div",{className:"sm:hidden",children:s.jsxs(d.Menu.Root,{children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsx(d.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:s.jsx(d.RiIcon,{icon:"RiMore2Line"})})}),s.jsx(d.Menu.Content,{children:m.map(f=>{var v;return s.jsxs(d.Menu.Item,{onClick:(v=f.buttonProps)==null?void 0:v.onClick,children:[s.jsx(f.Icon,{}),f.text]},f.key)})})]})}),e!=="section"&&s.jsx("input",{style:{display:"none"},ref:p,type:"file",accept:"image/*",onChange:a})]})});dn.displayName="FieldActions";const un=c.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return s.jsxs(d.Popover.Root,{children:[s.jsx(d.Popover.Trigger,{asChild:!0,children:s.jsxs(d.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:ie.danger},children:[s.jsx(d.RiIcon,{icon:"RiSettings2Line"}),s.jsx("span",{children:"Settings"})]},"settings")}),s.jsx(d.Popover.Content,{size:"sm",...r,children:s.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});un.displayName="FieldSettingsPopover";const Hr=(t=()=>null)=>c.useMemo(()=>Yo.map(n=>n.map(e=>{const r=ft[e],i=r.Icon;return{children:r.fieldTypeName,icon:s.jsx(i,{}),value:e,onSelect:()=>{t(e)}}})),[t]),Gr=576,fn=c.memo(t=>{var Ct,Jr,Qr,Rr,ei;const{parentPath:n,index:e,initial:r,conditionalSourceFields:i}=t,{values:o,setFieldValue:l,errors:a}=W.useFormikContext(),h=Hr(),p=Xe(),{disableRequiredFields:m}=c.use(bt),f=c.useRef(null),[v,I]=c.useState(f.current&&f.current.getBoundingClientRect().width>=Gr);c.useEffect(()=>{const P=f.current;if(P){const B=new ResizeObserver(j=>{j[0]&&I(j[0].contentRect.width>=Gr)});return B.observe(P),()=>{B.disconnect()}}},[]);const[w,u]=c.useState(void 0);c.useEffect(()=>{ce(r)?u(void 0):r.image instanceof Promise?r.image.then(u).catch(console.error):u(r.image)},[r]);const b=w?URL.createObjectURL(w):void 0,E=c.useCallback(P=>{P.stopPropagation();const{image:B,...j}=r;l(`${n}.${e}`,j).then()},[e,r,n,l]);c.useEffect(()=>{ce(r)&&!r.conditional&&l(`${n}.${e}.condition`,null).then()},[e,r,n,l]);const S=c.useMemo(()=>{var P,B;return ce(r)?(B=In(o.fields,(P=r.condition)==null?void 0:P.identifier))==null?void 0:B.label:void 0},[r,o.fields]),y=ce(r)?Array.isArray((Ct=r.condition)==null?void 0:Ct.value)?"contains all of":"equals":void 0;let F;if(ce(r)){if(mt((Jr=r.condition)==null?void 0:Jr.value))throw new Error("File values are not supported for conditions.");F=Array.isArray((Qr=r.condition)==null?void 0:Qr.value)?r.condition.value.map(P=>typeof P=="string"?P:P.label).join(", "):(ei=(Rr=r.condition)==null?void 0:Rr.value)==null?void 0:ei.toString()}const x=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),D=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),N=r.type,L=cn[N],[M,A]=c.useMemo(()=>{let P=[],B=[];if(L===q){if(i===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const j=L.getFieldCreationSchema(i,`${n}.${e}`);P=P.concat(j.filter(U=>U.showDirectly).map(U=>U.field)),B=B.concat(j.filter(U=>!U.showDirectly).map(U=>U.field))}else{if(!(L.prototype instanceof V))throw new Error(`Field must be an instance of BaseField. Got ${L.toString()}.`);const j=L.getFieldCreationSchema(`${n}.${e}`);v?(P=[...P,...j.filter(U=>U.showDirectly).map(U=>U.field)],B=[...B,...j.filter(U=>!U.showDirectly).map(U=>U.field)]):B=[...B,...j.map(U=>U.field)]}return[P,B]},[L,i,n,e,v]),O=We(M,{formId:yt,disabled:!1,...L===q&&{size:"sm"}}),_=We(A,{formId:yt,disabled:!1});let X=A.length>0;ce(r)&&A.length>0&&(X=r.conditional);const ne=A.some(P=>{const B=Q(a,L===q?`${n}.${e}.condition`:P.getId());return B&&(typeof B!="object"||pe(B))}),z=ne?ie.danger:void 0,Z=c.useMemo(()=>ht(r),[r]),ze=ln(Z,{formId:yt,showInputOnly:!1}),ae=c.useMemo(()=>h.flat().find(P=>P.value===N),[h,N]),hn=c.useCallback(()=>{w&&p(()=>({file:w}))},[p,w]);return s.jsx("div",{className:"flex grow items-center w-full",ref:f,children:s.jsxs("div",{className:"flex w-full flex-col gap-2",children:[L===q&&(M.length>0||X)&&s.jsxs("div",{className:"flex flex-col gap-2",children:[O,X&&s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(un,{popoverInputs:_,hasError:ne,align:"start"}),ce(r)&&r.conditional&&s.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":z,children:s.jsxs("em",{children:["Display only if ",s.jsx("strong",{children:S})," ",y," ",s.jsx("strong",{children:F})]})})]})]}),L!==q&&s.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[s.jsxs("div",{className:"flex gap-2 items-center",children:[s.jsxs(d.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[ae==null?void 0:ae.icon,ae==null?void 0:ae.children]}),!m&&s.jsx(me,{name:`${n}.${e}.required`,render:({setValue:P,value:B})=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(d.Checkbox.Root,{checked:B,onCheckedChange:P,size:"sm",children:s.jsx(d.Checkbox.Indicator,{children:s.jsx(d.RiIcon,{icon:"RiCheckLine"})})}),s.jsx(d.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),X&&s.jsx(un,{popoverInputs:_,hasError:ne,align:"end"})]}),w&&s.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[s.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:b,alt:w.name,onClick:hn}),s.jsx(d.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:"base","aria-label":"delete",onClick:E,size:"sm",children:s.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),s.jsx(me,{name:`${n}.${e}.label`,render:({setValue:P,value:B})=>s.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:N==="section"?"Enter a section label (optional)":"Enter your question",value:B,onChange:j=>{P(j.target.value)},onInput:x,maxLength:200})}),s.jsx(me,{name:`${n}.${e}.description`,render:({setValue:P,value:B})=>s.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${N==="section"?"section":"field"} description (optional)`,value:B,onChange:j=>{P(j.target.value)},onInput:D,maxLength:1e3})}),L!==q&&M.length>0&&s.jsx("div",{className:"w-full",children:O}),L!==q&&s.jsxs(d.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[s.jsxs(d.HoverCard.Root,{children:[s.jsx(d.HoverCard.Trigger,{asChild:!0,children:s.jsx(d.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:s.jsx(d.RiIcon,{icon:"RiEyeLine"})})}),s.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."})]}),s.jsx("div",{className:"grow h-max min-w-0",children:ze})]})]})})});fn.displayName="FieldBuilder";const Xr=c.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:i}=t,{setFieldValue:o,values:l}=W.useFormikContext(),{reorderField:a}=Tt(),{showInfo:h,showError:p}=d.useToast(),m=`fields.${r}.fields`,f=c.useMemo(()=>({index:e,parentPath:m,initial:n}),[n,e,m]),v=c.useCallback(()=>{const u=n.label||"Unlabelled field",b={...n,label:u};Ge(m,e+1,b,l,o),h({title:"Field duplicated",description:`The field "${u}" has been duplicated`})},[n,m,e,l,o,h]),I=c.useCallback(u=>{const b=r,E=l.fields[b];let S=r,y=u==="up"?e-1:e+1;u==="up"&&e===0?(S=r-1,y=l.fields[S].fields.length):u==="down"&&e===E.fields.length-1&&(S=r+1,y=0);const F=l.fields[S];a(E,b,e,F,S,y,o)},[r,l.fields,e,a,o]),w=c.useCallback(u=>{const{files:b}=u.target;if(!b||b.length!==1)return;const E=b.item(0);if(E){if(E.size>Vr){p({title:"File upload error",description:`The file ${E.name} exceeded the maximum file size`});return}o(`${m}.${e}`,{...n,image:E}).then()}},[n,e,m,o,p]);return s.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:u=>s.jsx(d.Card,{ref:u.innerRef,...u.draggableProps,...u.dragHandleProps,className:"mb-4",children:s.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[s.jsx(fn,{...f}),s.jsx(dn,{index:e,type:n.type,sectionIndex:r,remove:i,duplicate:v,move:I,upload:w})]})})})});Xr.displayName="FieldWithActions";const Yr=c.memo(t=>{var F;const{field:n,index:e,dropState:r}=t,i=(F=r[n.identifier])==null?void 0:F.disabled,{setFieldValue:o,values:l}=W.useFormikContext(),a=d.useAlertDialog(),{reorderSection:h}=Tt(),{showInfo:p}=d.useToast(),{fieldsOnly:m}=c.use(bt),f=c.useCallback((x,D)=>{for(const N of x){const L=D.indexOf(N);o(`fields.${L}.condition`,null).then(),o(`fields.${L}.conditional`,!1).then()}},[o]),v=c.useCallback(x=>{var L;const D=n.fields[x];if(!D)throw new Error("Could not find field to remove.");const N=[];for(const M of l.fields)((L=M.condition)==null?void 0:L.identifier)===D.identifier&&N.push(M);return{removing:D,affectedSections:N,action:()=>o(`fields.${e}.fields`,He(n.fields,x))}},[n.fields,l.fields,o,e]),I=c.useCallback(x=>{const{affectedSections:D,action:N,removing:L}=v(x),M=()=>{N().then(),f(D,l.fields)};if(D.length>0){const A=D.map(O=>O.label).join(", ");a({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${A} section(s).`,action:"Remove",onAction:M});return}M()},[v,f,l.fields,a]),w=c.useCallback(()=>{const D=n.fields.map((X,ne)=>v(ne)).flatMap(X=>X.affectedSections),N=D.length?"Remove fields and conditions?":"Remove fields?",L=n.fields.length,M=D.map(X=>X.label).join(", "),A=D.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${L} field(s) it contains.`,O=He(l.fields,e),_=()=>o("fields",O);if(D.length>0){a({title:N,description:A,action:"Remove",onAction:()=>{_().then(()=>{f(D,O)})}});return}_().then()},[n.fields,l.fields,e,v,o,a,f]),u=c.useCallback(x=>{const D=x==="up"?e-1:e+1;h(r,n.identifier,e,D,l,o)},[e,h,r,n.identifier,l,o]),b=c.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:xn(l.fields,e)}),[n,e,l.fields]),E=c.useCallback(()=>{const x=n.label||"Untitled section",D=n.fields.map(L=>({...L,identifier:St()})),N={...n,label:x,fields:D};Ge("fields",e+1,N,l,o),p({title:"Section duplicated",description:`The section "${x}" has been duplicated.`})},[n,e,l,o,p]),S=c.useCallback(x=>{Ge(`fields.${e}.fields`,n.fields.length,Br[x],l,o)},[e,n.fields.length,l,o]),y=Hr(S);return s.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:x=>s.jsx(d.Card,{ref:x.innerRef,...x.draggableProps,...x.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[s.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!m&&s.jsx(fn,{...b}),s.jsx(re.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:i,children:D=>s.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:D.innerRef,...D.droppableProps,children:[n.fields.map((N,L)=>s.jsx(Xr,{field:N,index:L,sectionIndex:e,remove:()=>{I(L)}},N.identifier)),D.placeholder,s.jsxs(d.Menu.Root,{children:[s.jsx(d.Menu.ClickTrigger,{children:s.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",children:[s.jsx(d.RiIcon,{icon:"RiAddLine"})," Add field"]})}),s.jsx(d.Menu.Content,{children:y.flat().map(N=>s.jsxs(d.Menu.Item,{onSelect:N.onSelect,children:[N.icon,N.children]},N.value))})]})]})})]}),!m&&s.jsx(dn,{index:e,type:n.type,remove:w,duplicate:E,move:u})]})})})});Yr.displayName="FieldSectionWithActions";const Kr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Zr=c.memo(()=>{const{values:t,setFieldValue:n}=W.useFormikContext(),[e,r]=c.useReducer(Ko,t.fields,jr),{reorderSection:i,reorderField:o}=Tt(),{fieldsOnly:l}=c.use(bt);c.useEffect(()=>{r({type:"update",state:jr(t.fields)})},[r,t.fields]);const a=c.useCallback(m=>{m.type==="SECTION"&&r({type:"hold",fieldId:m.draggableId})},[]),h=c.useCallback(m=>{const{source:f,destination:v,type:I,reason:w,draggableId:u}=m;if(r({type:"release"}),!v||w==="CANCEL")return;if(I==="ROOT"){i(e,u,f.index,v.index,t,n);return}if(I!=="SECTION")throw new Error("Unexpected droppable type.");const[b,E]=Kr(t.fields,f.droppableId)??[],[S,y]=Kr(t.fields,v.droppableId)??[];o(b,E,f.index,S,y,v.index,n)},[t,o,n,i,e]),p=c.useCallback(m=>{ci(m+1,t,n)},[t,n]);return s.jsx(re.DragDropContext,{onDragStart:a,onDragEnd:h,children:s.jsx(re.Droppable,{droppableId:"droppable",type:"ROOT",children:m=>s.jsxs("div",{className:"flex flex-col gap-0",ref:m.innerRef,...m.droppableProps,children:[t.fields.map((f,v)=>s.jsxs(c.Fragment,{children:[s.jsx(Yr,{field:f,index:v,dropState:e,fieldsOnly:l}),!l&&v!==t.fields.length-1&&s.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{p(v)},children:[s.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]})]},f.identifier)),s.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{p(t.fields.length)},children:[s.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]}),m.placeholder]})})})});Zr.displayName="FieldsEditor";const Jo=c.memo(c.forwardRef((t,n)=>{const{onCancel:e,onSave:r,initialTitle:i,initialDescription:o,initialFields:l,showExplainerText:a=!0,showFormTitle:h=!0,fieldsOnly:p=!1,showTabs:m=!0,disableRequiredFields:f=!1,tabsListClassName:v}=t,{showError:I}=d.useToast(),w=c.useCallback(y=>{const F={};y.title||(F.title="Title is required."),(!y.fields||y.fields.length===0)&&(F.fields="At least one field is required.");let x=[];for(const[N,L]of y.fields.entries()){const A=cn.section.getFieldCreationSchema(xn(y.fields,N),`fields.${N}`).map(O=>O.field);x=[...x,...A];for(const[O,_]of L.fields.entries()){const ne=cn[_.type].getFieldCreationSchema(`fields.${N}.fields.${O}`).map(z=>z.field);x=[...x,...ne]}}const D=gt(x,y);if(D&&(F.fields=D.fields),pe(F))return I({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),F},[I]),u=c.useMemo(()=>({title:i??"",description:o??"",fields:l?ai(l):[{...je(St()),label:""}]}),[o,l,i]),b=W.useFormik({initialValues:u,validate:w,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),E=c.useMemo(()=>({title:b.values.title,description:b.values.description,fields:Ur(b.values.fields),meta:{readonly:!1}}),[b.values]),S=c.useMemo(()=>({disableRequiredFields:f,fieldsOnly:p}),[f,p]);return s.jsx(bt,{value:S,children:s.jsx(d.Tabs.Root,{ref:n,defaultValue:"edit",children:s.jsxs("div",{className:"flex flex-col gap-2",children:[m&&s.jsxs(d.Tabs.List,{className:ge.cx("sticky top-0 z-[2000] flex bg-(--color-background)",v),children:[s.jsx(d.Tabs.Trigger,{className:"grow",value:"edit",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(d.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),s.jsx(d.Tabs.Trigger,{className:"grow",value:"preview",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(d.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),s.jsxs(d.Tabs.Content,{value:"edit",children:[a&&s.jsxs(d.Text,{children:["Create your form using various field types. Sections can be"," ",s.jsx("strong",{children:"conditionally rendered"})," based on"," ",s.jsx("strong",{children:"answers to fields in preceding sections. "})]}),s.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:yt,onSubmit:b.handleSubmit,children:[s.jsxs(W.FormikProvider,{value:b,children:[h&&s.jsxs(s.Fragment,{children:[s.jsx(me,{name:"title",render:({setValue:y,value:F,meta:x})=>s.jsx(Ft,{severity:"danger",helpText:x.error??null,children:s.jsx(d.Input.Root,{variant:"outline",size:"md",accentColor:x.error?ie.danger:"primary",children:s.jsx(d.Input.Field,{placeholder:"Form title",value:F,onChange:D=>{y(D.target.value)},maxLength:100})})})}),s.jsx(me,{name:"description",render:({setValue:y,value:F})=>s.jsx(d.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:F,onChange:x=>{y(x.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),s.jsx(Zr,{}),s.jsx("span",{"data-accent-color":ie.danger,className:"text-xs text-(--accent-a11)",children:typeof b.errors.fields=="string"&&b.errors.fields})]}),s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&s.jsx(d.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),s.jsx(d.Button,{type:"submit",children:"Save form"})]})]})]}),s.jsx(d.Tabs.Content,{value:"preview",children:s.jsx(qr,{schema:E,hideTitle:!h})})]})})})}));C.BaseField=V,C.BaseFormElement=It,C.BaseSelectField=Gt,C.BooleanField=xe,C.BooleanInput=Xt,C.DateField=st,C.DateInput=Yt,C.FieldSection=q,C.FieldSectionLayout=an,C.FieldTypeToClsMapping=ft,C.FieldTypeToEmptyFieldMapping=Br,C.FileCard=wt,C.FileIcon=ke,C.FormBuilder=Jo,C.FormRenderer=qr,C.ImageCard=Pr,C.ImageViewer=jt,C.ImageViewerProvider=br,C.InputWithHelpText=Ft,C.InputWithLabel=Y,C.InputWithLabelAndHelpText=K,C.LONG_TEXT_FIELD_MAX_LENGTH=he,C.MultiSelectField=Be,C.MultiSelectInput=Kt,C.MultiStringField=Ie,C.MultiStringInput=Ht,C.NumberField=le,C.NumberInput=Zt,C.PatchField=me,C.PatchFormProvider=Xo,C.RadioField=lt,C.RadioInput=Jt,C.SEVERITY_COLOR_MAPPING=ie,C.SHORT_TEXT_FIELD_MAX_LENGTH=Ve,C.SUPPORTED_IMAGE_FILE_TYPES=vn,C.SUPPORTED_PDF_FILE_TYPES=bn,C.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=yn,C.ScanField=at,C.ScanInput=Qt,C.Scanner=Rt,C.SelectField=_e,C.SelectInput=en,C.StringField=ct,C.StringInput=tn,C.StringOrTextField=$e,C.TextField=dt,C.TextInput=nn,C.UploadField=ut,C.UploadInput=rn,C.decodeFieldValues=Ho,C.deserialize=ht,C.deserializeField=on,C.deserializeFields=Ur,C.emptyBaseField=H,C.emptyBooleanField=wr,C.emptyDateField=Ir,C.emptyMultiSelectField=xr,C.emptyMultiStringField=Cr,C.emptyNumberField=Er,C.emptyRadioField=Tr,C.emptyScanField=Fr,C.emptySelectField=Nr,C.emptyStringField=Dr,C.emptyTextField=Mr,C.emptyUploadField=Or,C.encodeFieldValues=Go,C.fieldIcons=qo,C.flattenFields=pt,C.getFieldsMapping=Wr,C.initializeFormValues=vt,C.isConditionMet=sn,C.maxFileSizeB=Vr,C.maxFileSizeKB=_r,C.maxFileSizeMB=Ue,C.useFieldInput=ln,C.useFieldInputs=We,C.useFormikInput=G,C.useImageViewer=Xe,C.validateFields=gt,C.valueIsFile=mt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|