@overmap-ai/forms 1.0.17-blur-updates.1 → 1.0.17-blur-updates.2
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.
|
@@ -7,7 +7,7 @@ interface FormRendererProps {
|
|
|
7
7
|
/** Initial values of the form */
|
|
8
8
|
values?: FormValues;
|
|
9
9
|
/** The function to call when the form values change */
|
|
10
|
-
onValuesChange?: (
|
|
10
|
+
onValuesChange?: (allValues: FormValues, changedValues: FormValues) => void;
|
|
11
11
|
onSubmit?: (values: FormValues) => Promise<void> | void;
|
|
12
12
|
/** @default "Submit" */
|
|
13
13
|
submitText?: string;
|
package/dist/forms.js
CHANGED
|
@@ -3448,9 +3448,9 @@ const ve = (t) => Object.keys(t).length > 0, vn = (t, n) => {
|
|
|
3448
3448
|
[e.description]
|
|
3449
3449
|
), S = N(
|
|
3450
3450
|
(R, T) => {
|
|
3451
|
-
r == null || r({ [R]: T });
|
|
3451
|
+
r == null || r({ ...C.values, [R]: T }, { [R]: T });
|
|
3452
3452
|
},
|
|
3453
|
-
[r]
|
|
3453
|
+
[C.values, r]
|
|
3454
3454
|
), L = dt(e.fields, { formId: g, disabled: f, onValuesChange: S });
|
|
3455
3455
|
return X(() => {
|
|
3456
3456
|
w && c && c(), d && d(w);
|
package/dist/forms.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(x,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("react"),require("formik"),require("react-dom"),require("react-icons/ri"),require("lodash.get"),require("lodash.set"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("qr-scanner"),require("lodash.clonedeep"),require("react-sketch-canvas")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","react","formik","react-dom","react-icons/ri","lodash.get","lodash.set","@hello-pangea/dnd","@overmap-ai/core","qr-scanner","lodash.clonedeep","react-sketch-canvas"],i):(x=typeof globalThis<"u"?globalThis:x||self,i(x.forms={},x.jsxRuntime,x.blocks,x.React,x.formik,x.ReactDOM,x.ri,x.get,x.set,x.dnd,x.core,x.QrScannerAPI,x.cloneDeep,x.reactSketchCanvas))})(this,function(x,i,c,d,V,pn,$,K,gt,re,ie,Hr,Gr,Xr){"use strict";var Ro=Object.defineProperty;var ea=(x,i,c)=>i in x?Ro(x,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):x[i]=c;var T=(x,i,c)=>ea(x,typeof i!="symbol"?i+"":i,c);function mn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,r.get?r:{enumerable:!0,get:()=>t[e]})}}return n.default=t,Object.freeze(n)}const v=mn(d),Kr=mn(pn),vt=d.memo(t=>{const{selectedColor:n,allColors:e,onFinish:r,trigger:o}=t,a=d.useCallback(s=>()=>{r(s)},[r]);return i.jsxs(c.Popover.Root,{children:[i.jsx(c.Popover.Trigger,{children:o}),i.jsx(c.Popover.Content,{size:"sm",children:i.jsx("div",{className:"grid w-max grid-cols-7 gap-x-1 gap-y-1",children:e.map(s=>i.jsx(c.IconButton,{onClick:a(s),style:{backgroundColor:s},type:"button",variant:"solid","aria-label":s,children:n===s&&i.jsx(c.RiIcon,{icon:"RiCheckLine"})},s))})})]})});vt.displayName="ColorPicker";function gn(t){var n,e,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var o=t.length;for(n=0;n<o;n++)t[n]&&(e=gn(t[n]))&&(r&&(r+=" "),r+=e)}else for(e in t)t[e]&&(r&&(r+=" "),r+=e);return r}function Qr(){for(var t,n,e=0,r="",o=arguments.length;e<o;e++)(t=arguments[e])&&(n=gn(t))&&(r&&(r+=" "),r+=n);return r}const ve=Qr,vn=["image/jpeg","image/png","image/svg+xml"],yn=["text/csv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],bn=["application/pdf"],$e=d.memo(t=>{const{fileType:n}=t,e=d.useMemo(()=>yn.includes(n)?i.jsx(c.RiIcon,{icon:"RiFileExcelLine"}):bn.includes(n)?i.jsx(c.RiIcon,{icon:"RiFilePdfLine"}):vn.includes(n)?i.jsx(c.RiIcon,{icon:"RiFileImageLine"}):i.jsx(c.RiIcon,{icon:"RiFileLine"}),[n]);return i.jsx("div",{className:"h-max w-max",children:e})});$e.displayName="FileIcon";const yt=d.memo(d.forwardRef((t,n)=>{const{file:e,className:r,error:o,rightSlot:a,...s}=t;return i.jsxs("div",{className:ve(r,"flex h-8 w-full items-center gap-2 rounded-md border border-(--base-a6) bg-(--base-2) text-sm py-1 px-2 h-max",{"text-(--gray-11)":o}),ref:n,...s,children:[o?i.jsx(c.RiIcon,{icon:"RiFileWarningLine"}):i.jsx($e,{fileType:(e==null?void 0:e.type)??""}),o||(e?i.jsx(c.Text,{className:"truncate",children:e.name}):i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(c.Spinner,{})})),a]})}));yt.displayName="FileCard";const ke=500,ye=1e4,de={danger:"danger",warning:"warning",info:"base",success:"success"},Yr={boolean:"RiCheckboxCircleLine",date:"RiCalendarLine","multi-string":"RiListCheck",number:"RiHashtag",qr:"RiQrCodeLine","multi-select":"RiCheckboxLine",select:"RiMenuFoldLine",string:"RiInputField",text:"RiAlignJustify",upload:"RiUpload2Line",custom:"RiCodeSSlashLine",section:"RiFolderLine"};class bt{constructor(n){T(this,"type");T(this,"identifier");T(this,"description");const{description:e=null,identifier:r,type:o}=n;this.identifier=r,this.description=e,this.type=o}getId(){return this.identifier}static deserialize(n){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}const H={label:"",description:"",required:!1};class k extends bt{constructor(e){const{label:r,required:o,image:a,fieldValidators:s=[],formValidators:l=[],...m}=e;super(m);T(this,"required");T(this,"formValidators");T(this,"fieldValidators");T(this,"label");T(this,"image");T(this,"onlyValidateAfterTouched",!0);this.label=r,this.required=o,this.image=a,this.fieldValidators=s,this.formValidators=l}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,r){if(this.required&&this.isBlank(e))return"This field is required.";for(const o of this.getFieldValidators()){const a=o(e);if(a)return a}if(r)for(const o of this.getFormValidators()){const a=o(e,r);if(a)return a}}_serialize(){return{...super._serialize(),label:this.label,required:this.required,image:this.image}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}encodeValueToJson(e){return JSON.stringify(e)}decodeJsonToValue(e){return JSON.parse(e)}}T(k,"fieldTypeName"),T(k,"fieldTypeDescription");const G=t=>{const{id:n,field:e,formId:r,size:o,showInputOnly:a,onValuesChange:s,...l}=t,[m,u,f]=V.useField(e.getId()),{touched:h}=u,g=u.error??e.description,C=u.error?"danger":void 0,w=n??`${r}-${e.getId()}-input`,p=`${w}-label`,y=e.required?`${e.label} *`:e.label,E=d.useMemo(()=>({...m,onChange:S=>{f.setValue(S,!1).then(),s==null||s(e.getId(),S),(h||!e.onlyValidateAfterTouched)&&f.setError(e.getError(S))},onBlur:S=>{f.setTouched(!0,!1).then(),f.setError(e.getError(S))}}),[e,m,f,s,h]);return[{helpText:g,size:o,severity:C,inputId:w,labelId:p,label:y,showInputOnly:a,fieldProps:E,helpers:f,field:e,touched:h},{...l,"aria-labelledby":p}]},Cn=d.createContext(()=>{throw new Error("No ImageViewerProvider found")}),Ue=()=>d.useContext(Cn);function oe(t,n,{checkForDefaultPrevented:e=!0}={}){return function(o){if(t==null||t(o),e===!1||!o.defaultPrevented)return n==null?void 0:n(o)}}function wn(t,n){if(typeof t=="function")return t(n);t!=null&&(t.current=n)}function In(...t){return n=>{let e=!1;const r=t.map(o=>{const a=wn(o,n);return!e&&typeof a=="function"&&(e=!0),a});if(e)return()=>{for(let o=0;o<r.length;o++){const a=r[o];typeof a=="function"?a():wn(t[o],null)}}}}function ue(...t){return v.useCallback(In(...t),t)}function Jr(t,n){const e=v.createContext(n),r=a=>{const{children:s,...l}=a,m=v.useMemo(()=>l,Object.values(l));return i.jsx(e.Provider,{value:m,children:s})};r.displayName=t+"Provider";function o(a){const s=v.useContext(e);if(s)return s;if(n!==void 0)return n;throw new Error(`\`${a}\` must be used within \`${t}\``)}return[r,o]}function Zr(t,n=[]){let e=[];function r(a,s){const l=v.createContext(s),m=e.length;e=[...e,s];const u=h=>{var E;const{scope:g,children:C,...w}=h,p=((E=g==null?void 0:g[t])==null?void 0:E[m])||l,y=v.useMemo(()=>w,Object.values(w));return i.jsx(p.Provider,{value:y,children:C})};u.displayName=a+"Provider";function f(h,g){var p;const C=((p=g==null?void 0:g[t])==null?void 0:p[m])||l,w=v.useContext(C);if(w)return w;if(s!==void 0)return s;throw new Error(`\`${h}\` must be used within \`${a}\``)}return[u,f]}const o=()=>{const a=e.map(s=>v.createContext(s));return function(l){const m=(l==null?void 0:l[t])||a;return v.useMemo(()=>({[`__scope${t}`]:{...l,[t]:m}}),[l,m])}};return o.scopeName=t,[r,Rr(o,...n)]}function Rr(...t){const n=t[0];if(t.length===1)return n;const e=()=>{const r=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(a){const s=r.reduce((l,{useScope:m,scopeName:u})=>{const h=m(a)[`__scope${u}`];return{...l,...h}},{});return v.useMemo(()=>({[`__scope${n.scopeName}`]:s}),[s])}};return e.scopeName=n.scopeName,e}var je=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ei=v.useId||(()=>{}),ti=0;function Ct(t){const[n,e]=v.useState(ei());return je(()=>{e(r=>r??String(ti++))},[t]),t||(n?`radix-${n}`:"")}function fe(t){const n=v.useRef(t);return v.useEffect(()=>{n.current=t}),v.useMemo(()=>(...e)=>{var r;return(r=n.current)==null?void 0:r.call(n,...e)},[])}function ni({prop:t,defaultProp:n,onChange:e=()=>{}}){const[r,o]=ri({defaultProp:n,onChange:e}),a=t!==void 0,s=a?t:r,l=fe(e),m=v.useCallback(u=>{if(a){const h=typeof u=="function"?u(t):u;h!==t&&l(h)}else o(u)},[a,t,o,l]);return[s,m]}function ri({defaultProp:t,onChange:n}){const e=v.useState(t),[r]=e,o=v.useRef(r),a=fe(n);return v.useEffect(()=>{o.current!==r&&(a(r),o.current=r)},[r,o,a]),e}var wt=v.forwardRef((t,n)=>{const{children:e,...r}=t,o=v.Children.toArray(e),a=o.find(oi);if(a){const s=a.props.children,l=o.map(m=>m===a?v.Children.count(s)>1?v.Children.only(null):v.isValidElement(s)?s.props.children:null:m);return i.jsx(It,{...r,ref:n,children:v.isValidElement(s)?v.cloneElement(s,void 0,l):null})}return i.jsx(It,{...r,ref:n,children:e})});wt.displayName="Slot";var It=v.forwardRef((t,n)=>{const{children:e,...r}=t;if(v.isValidElement(e)){const o=si(e);return v.cloneElement(e,{...ai(r,e.props),ref:n?In(n,o):o})}return v.Children.count(e)>1?v.Children.only(null):null});It.displayName="SlotClone";var ii=({children:t})=>i.jsx(i.Fragment,{children:t});function oi(t){return v.isValidElement(t)&&t.type===ii}function ai(t,n){const e={...n};for(const r in n){const o=t[r],a=n[r];/^on[A-Z]/.test(r)?o&&a?e[r]=(...l)=>{a(...l),o(...l)}:o&&(e[r]=o):r==="style"?e[r]={...o,...a}:r==="className"&&(e[r]=[o,a].filter(Boolean).join(" "))}return{...t,...e}}function si(t){var r,o;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,e=n&&"isReactWarning"in n&&n.isReactWarning;return e?t.ref:(n=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,e=n&&"isReactWarning"in n&&n.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var li=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],ne=li.reduce((t,n)=>{const e=v.forwardRef((r,o)=>{const{asChild:a,...s}=r,l=a?wt:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(l,{...s,ref:o})});return e.displayName=`Primitive.${n}`,{...t,[n]:e}},{});function ci(t,n){t&&Kr.flushSync(()=>t.dispatchEvent(n))}function di(t,n=globalThis==null?void 0:globalThis.document){const e=fe(t);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&e(o)};return n.addEventListener("keydown",r,{capture:!0}),()=>n.removeEventListener("keydown",r,{capture:!0})},[e,n])}var ui="DismissableLayer",xt="dismissableLayer.update",fi="dismissableLayer.pointerDownOutside",hi="dismissableLayer.focusOutside",xn,En=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Sn=v.forwardRef((t,n)=>{const{disableOutsidePointerEvents:e=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:a,onInteractOutside:s,onDismiss:l,...m}=t,u=v.useContext(En),[f,h]=v.useState(null),g=(f==null?void 0:f.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,C]=v.useState({}),w=ue(n,F=>h(F)),p=Array.from(u.layers),[y]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),E=p.indexOf(y),I=f?p.indexOf(f):-1,b=u.layersWithOutsidePointerEventsDisabled.size>0,S=I>=E,N=gi(F=>{const L=F.target,A=[...u.branches].some(O=>O.contains(L));!S||A||(o==null||o(F),s==null||s(F),F.defaultPrevented||l==null||l())},g),D=vi(F=>{const L=F.target;[...u.branches].some(O=>O.contains(L))||(a==null||a(F),s==null||s(F),F.defaultPrevented||l==null||l())},g);return di(F=>{I===u.layers.size-1&&(r==null||r(F),!F.defaultPrevented&&l&&(F.preventDefault(),l()))},g),v.useEffect(()=>{if(f)return e&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(xn=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(f)),u.layers.add(f),Tn(),()=>{e&&u.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=xn)}},[f,g,e,u]),v.useEffect(()=>()=>{f&&(u.layers.delete(f),u.layersWithOutsidePointerEventsDisabled.delete(f),Tn())},[f,u]),v.useEffect(()=>{const F=()=>C({});return document.addEventListener(xt,F),()=>document.removeEventListener(xt,F)},[]),i.jsx(ne.div,{...m,ref:w,style:{pointerEvents:b?S?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,D.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,N.onPointerDownCapture)})});Sn.displayName=ui;var pi="DismissableLayerBranch",mi=v.forwardRef((t,n)=>{const e=v.useContext(En),r=v.useRef(null),o=ue(n,r);return v.useEffect(()=>{const a=r.current;if(a)return e.branches.add(a),()=>{e.branches.delete(a)}},[e.branches]),i.jsx(ne.div,{...t,ref:o})});mi.displayName=pi;function gi(t,n=globalThis==null?void 0:globalThis.document){const e=fe(t),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const a=l=>{if(l.target&&!r.current){let m=function(){Nn(fi,e,u,{discrete:!0})};const u={originalEvent:l};l.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=m,n.addEventListener("click",o.current,{once:!0})):m()}else n.removeEventListener("click",o.current);r.current=!1},s=window.setTimeout(()=>{n.addEventListener("pointerdown",a)},0);return()=>{window.clearTimeout(s),n.removeEventListener("pointerdown",a),n.removeEventListener("click",o.current)}},[n,e]),{onPointerDownCapture:()=>r.current=!0}}function vi(t,n=globalThis==null?void 0:globalThis.document){const e=fe(t),r=v.useRef(!1);return v.useEffect(()=>{const o=a=>{a.target&&!r.current&&Nn(hi,e,{originalEvent:a},{discrete:!1})};return n.addEventListener("focusin",o),()=>n.removeEventListener("focusin",o)},[n,e]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Tn(){const t=new CustomEvent(xt);document.dispatchEvent(t)}function Nn(t,n,e,{discrete:r}){const o=e.originalEvent.target,a=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:e});n&&o.addEventListener(t,n,{once:!0}),r?ci(o,a):o.dispatchEvent(a)}var Et="focusScope.autoFocusOnMount",St="focusScope.autoFocusOnUnmount",Fn={bubbles:!1,cancelable:!0},yi="FocusScope",Ln=v.forwardRef((t,n)=>{const{loop:e=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:a,...s}=t,[l,m]=v.useState(null),u=fe(o),f=fe(a),h=v.useRef(null),g=ue(n,p=>m(p)),C=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let p=function(b){if(C.paused||!l)return;const S=b.target;l.contains(S)?h.current=S:ae(h.current,{select:!0})},y=function(b){if(C.paused||!l)return;const S=b.relatedTarget;S!==null&&(l.contains(S)||ae(h.current,{select:!0}))},E=function(b){if(document.activeElement===document.body)for(const N of b)N.removedNodes.length>0&&ae(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",y);const I=new MutationObserver(E);return l&&I.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",y),I.disconnect()}}},[r,l,C.paused]),v.useEffect(()=>{if(l){An.add(C);const p=document.activeElement;if(!l.contains(p)){const E=new CustomEvent(Et,Fn);l.addEventListener(Et,u),l.dispatchEvent(E),E.defaultPrevented||(bi(Ei(Dn(l)),{select:!0}),document.activeElement===p&&ae(l))}return()=>{l.removeEventListener(Et,u),setTimeout(()=>{const E=new CustomEvent(St,Fn);l.addEventListener(St,f),l.dispatchEvent(E),E.defaultPrevented||ae(p??document.body,{select:!0}),l.removeEventListener(St,f),An.remove(C)},0)}}},[l,u,f,C]);const w=v.useCallback(p=>{if(!e&&!r||C.paused)return;const y=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,E=document.activeElement;if(y&&E){const I=p.currentTarget,[b,S]=Ci(I);b&&S?!p.shiftKey&&E===S?(p.preventDefault(),e&&ae(b,{select:!0})):p.shiftKey&&E===b&&(p.preventDefault(),e&&ae(S,{select:!0})):E===I&&p.preventDefault()}},[e,r,C.paused]);return i.jsx(ne.div,{tabIndex:-1,...s,ref:g,onKeyDown:w})});Ln.displayName=yi;function bi(t,{select:n=!1}={}){const e=document.activeElement;for(const r of t)if(ae(r,{select:n}),document.activeElement!==e)return}function Ci(t){const n=Dn(t),e=Mn(n,t),r=Mn(n.reverse(),t);return[e,r]}function Dn(t){const n=[],e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)n.push(e.currentNode);return n}function Mn(t,n){for(const e of t)if(!wi(e,{upTo:n}))return e}function wi(t,{upTo:n}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(n!==void 0&&t===n)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Ii(t){return t instanceof HTMLInputElement&&"select"in t}function ae(t,{select:n=!1}={}){if(t&&t.focus){const e=document.activeElement;t.focus({preventScroll:!0}),t!==e&&Ii(t)&&n&&t.select()}}var An=xi();function xi(){let t=[];return{add(n){const e=t[0];n!==e&&(e==null||e.pause()),t=Pn(t,n),t.unshift(n)},remove(n){var e;t=Pn(t,n),(e=t[0])==null||e.resume()}}}function Pn(t,n){const e=[...t],r=e.indexOf(n);return r!==-1&&e.splice(r,1),e}function Ei(t){return t.filter(n=>n.tagName!=="A")}var Si="Portal",On=v.forwardRef((t,n)=>{var l;const{container:e,...r}=t,[o,a]=v.useState(!1);je(()=>a(!0),[]);const s=e||o&&((l=globalThis==null?void 0:globalThis.document)==null?void 0:l.body);return s?pn.createPortal(i.jsx(ne.div,{...r,ref:n}),s):null});On.displayName=Si;function Ti(t,n){return v.useReducer((e,r)=>n[e][r]??e,t)}var We=t=>{const{present:n,children:e}=t,r=Ni(n),o=typeof e=="function"?e({present:r.isPresent}):v.Children.only(e),a=ue(r.ref,Fi(o));return typeof e=="function"||r.isPresent?v.cloneElement(o,{ref:a}):null};We.displayName="Presence";function Ni(t){const[n,e]=v.useState(),r=v.useRef({}),o=v.useRef(t),a=v.useRef("none"),s=t?"mounted":"unmounted",[l,m]=Ti(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const u=qe(r.current);a.current=l==="mounted"?u:"none"},[l]),je(()=>{const u=r.current,f=o.current;if(f!==t){const g=a.current,C=qe(u);t?m("MOUNT"):C==="none"||(u==null?void 0:u.display)==="none"?m("UNMOUNT"):m(f&&g!==C?"ANIMATION_OUT":"UNMOUNT"),o.current=t}},[t,m]),je(()=>{if(n){let u;const f=n.ownerDocument.defaultView??window,h=C=>{const p=qe(r.current).includes(C.animationName);if(C.target===n&&p&&(m("ANIMATION_END"),!o.current)){const y=n.style.animationFillMode;n.style.animationFillMode="forwards",u=f.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=y)})}},g=C=>{C.target===n&&(a.current=qe(r.current))};return n.addEventListener("animationstart",g),n.addEventListener("animationcancel",h),n.addEventListener("animationend",h),()=>{f.clearTimeout(u),n.removeEventListener("animationstart",g),n.removeEventListener("animationcancel",h),n.removeEventListener("animationend",h)}}else m("ANIMATION_END")},[n,m]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:v.useCallback(u=>{u&&(r.current=getComputedStyle(u)),e(u)},[])}}function qe(t){return(t==null?void 0:t.animationName)||"none"}function Fi(t){var r,o;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,e=n&&"isReactWarning"in n&&n.isReactWarning;return e?t.ref:(n=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,e=n&&"isReactWarning"in n&&n.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Tt=0;function Li(){v.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??Bn()),document.body.insertAdjacentElement("beforeend",t[1]??Bn()),Tt++,()=>{Tt===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(n=>n.remove()),Tt--}},[])}function Bn(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var Z=function(){return Z=Object.assign||function(n){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},Z.apply(this,arguments)};function zn(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(e[r[o]]=t[r[o]]);return e}function Di(t,n,e){if(e||arguments.length===2)for(var r=0,o=n.length,a;r<o;r++)(a||!(r in n))&&(a||(a=Array.prototype.slice.call(n,0,r)),a[r]=n[r]);return t.concat(a||Array.prototype.slice.call(n))}typeof SuppressedError=="function"&&SuppressedError;var He="right-scroll-bar-position",Ge="width-before-scroll-bar",Mi="with-scroll-bars-hidden",Ai="--removed-body-scroll-bar-size";function Nt(t,n){return typeof t=="function"?t(n):t&&(t.current=n),t}function Pi(t,n){var e=d.useState(function(){return{value:t,callback:n,facade:{get current(){return e.value},set current(r){var o=e.value;o!==r&&(e.value=r,e.callback(r,o))}}}})[0];return e.callback=n,e.facade}var Oi=typeof window<"u"?v.useLayoutEffect:v.useEffect,_n=new WeakMap;function Bi(t,n){var e=Pi(null,function(r){return t.forEach(function(o){return Nt(o,r)})});return Oi(function(){var r=_n.get(e);if(r){var o=new Set(r),a=new Set(t),s=e.current;o.forEach(function(l){a.has(l)||Nt(l,null)}),a.forEach(function(l){o.has(l)||Nt(l,s)})}_n.set(e,t)},[t]),e}function zi(t){return t}function _i(t,n){n===void 0&&(n=zi);var e=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:t},useMedium:function(a){var s=n(a,r);return e.push(s),function(){e=e.filter(function(l){return l!==s})}},assignSyncMedium:function(a){for(r=!0;e.length;){var s=e;e=[],s.forEach(a)}e={push:function(l){return a(l)},filter:function(){return e}}},assignMedium:function(a){r=!0;var s=[];if(e.length){var l=e;e=[],l.forEach(a),s=e}var m=function(){var f=s;s=[],f.forEach(a)},u=function(){return Promise.resolve().then(m)};u(),e={push:function(f){s.push(f),u()},filter:function(f){return s=s.filter(f),e}}}};return o}function Vi(t){t===void 0&&(t={});var n=_i(null);return n.options=Z({async:!0,ssr:!1},t),n}var Vn=function(t){var n=t.sideCar,e=zn(t,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,Z({},e))};Vn.isSideCarExport=!0;function $i(t,n){return t.useMedium(n),Vn}var $n=Vi(),Ft=function(){},Xe=v.forwardRef(function(t,n){var e=v.useRef(null),r=v.useState({onScrollCapture:Ft,onWheelCapture:Ft,onTouchMoveCapture:Ft}),o=r[0],a=r[1],s=t.forwardProps,l=t.children,m=t.className,u=t.removeScrollBar,f=t.enabled,h=t.shards,g=t.sideCar,C=t.noIsolation,w=t.inert,p=t.allowPinchZoom,y=t.as,E=y===void 0?"div":y,I=t.gapMode,b=zn(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=g,N=Bi([e,n]),D=Z(Z({},b),o);return v.createElement(v.Fragment,null,f&&v.createElement(S,{sideCar:$n,removeScrollBar:u,shards:h,noIsolation:C,inert:w,setCallbacks:a,allowPinchZoom:!!p,lockRef:e,gapMode:I}),s?v.cloneElement(v.Children.only(l),Z(Z({},D),{ref:N})):v.createElement(E,Z({},D,{className:m,ref:N}),l))});Xe.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Xe.classNames={fullWidth:Ge,zeroRight:He};var ki=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ui(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var n=ki();return n&&t.setAttribute("nonce",n),t}function ji(t,n){t.styleSheet?t.styleSheet.cssText=n:t.appendChild(document.createTextNode(n))}function Wi(t){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(t)}var qi=function(){var t=0,n=null;return{add:function(e){t==0&&(n=Ui())&&(ji(n,e),Wi(n)),t++},remove:function(){t--,!t&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},Hi=function(){var t=qi();return function(n,e){v.useEffect(function(){return t.add(n),function(){t.remove()}},[n&&e])}},kn=function(){var t=Hi(),n=function(e){var r=e.styles,o=e.dynamic;return t(r,o),null};return n},Gi={left:0,top:0,right:0,gap:0},Lt=function(t){return parseInt(t||"",10)||0},Xi=function(t){var n=window.getComputedStyle(document.body),e=n[t==="padding"?"paddingLeft":"marginLeft"],r=n[t==="padding"?"paddingTop":"marginTop"],o=n[t==="padding"?"paddingRight":"marginRight"];return[Lt(e),Lt(r),Lt(o)]},Ki=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Gi;var n=Xi(t),e=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-e+n[2]-n[0])}},Qi=kn(),be="data-scroll-locked",Yi=function(t,n,e,r){var o=t.left,a=t.top,s=t.right,l=t.gap;return e===void 0&&(e="margin"),`
|
|
1
|
+
(function(E,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("react"),require("formik"),require("react-dom"),require("react-icons/ri"),require("lodash.get"),require("lodash.set"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("qr-scanner"),require("lodash.clonedeep"),require("react-sketch-canvas")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","react","formik","react-dom","react-icons/ri","lodash.get","lodash.set","@hello-pangea/dnd","@overmap-ai/core","qr-scanner","lodash.clonedeep","react-sketch-canvas"],i):(E=typeof globalThis<"u"?globalThis:E||self,i(E.forms={},E.jsxRuntime,E.blocks,E.React,E.formik,E.ReactDOM,E.ri,E.get,E.set,E.dnd,E.core,E.QrScannerAPI,E.cloneDeep,E.reactSketchCanvas))})(this,function(E,i,c,d,V,pn,$,K,gt,re,ie,Hr,Gr,Xr){"use strict";var Ro=Object.defineProperty;var ea=(E,i,c)=>i in E?Ro(E,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):E[i]=c;var T=(E,i,c)=>ea(E,typeof i!="symbol"?i+"":i,c);function mn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,r.get?r:{enumerable:!0,get:()=>t[e]})}}return n.default=t,Object.freeze(n)}const v=mn(d),Kr=mn(pn),vt=d.memo(t=>{const{selectedColor:n,allColors:e,onFinish:r,trigger:o}=t,a=d.useCallback(s=>()=>{r(s)},[r]);return i.jsxs(c.Popover.Root,{children:[i.jsx(c.Popover.Trigger,{children:o}),i.jsx(c.Popover.Content,{size:"sm",children:i.jsx("div",{className:"grid w-max grid-cols-7 gap-x-1 gap-y-1",children:e.map(s=>i.jsx(c.IconButton,{onClick:a(s),style:{backgroundColor:s},type:"button",variant:"solid","aria-label":s,children:n===s&&i.jsx(c.RiIcon,{icon:"RiCheckLine"})},s))})})]})});vt.displayName="ColorPicker";function gn(t){var n,e,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var o=t.length;for(n=0;n<o;n++)t[n]&&(e=gn(t[n]))&&(r&&(r+=" "),r+=e)}else for(e in t)t[e]&&(r&&(r+=" "),r+=e);return r}function Qr(){for(var t,n,e=0,r="",o=arguments.length;e<o;e++)(t=arguments[e])&&(n=gn(t))&&(r&&(r+=" "),r+=n);return r}const ve=Qr,vn=["image/jpeg","image/png","image/svg+xml"],yn=["text/csv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],bn=["application/pdf"],$e=d.memo(t=>{const{fileType:n}=t,e=d.useMemo(()=>yn.includes(n)?i.jsx(c.RiIcon,{icon:"RiFileExcelLine"}):bn.includes(n)?i.jsx(c.RiIcon,{icon:"RiFilePdfLine"}):vn.includes(n)?i.jsx(c.RiIcon,{icon:"RiFileImageLine"}):i.jsx(c.RiIcon,{icon:"RiFileLine"}),[n]);return i.jsx("div",{className:"h-max w-max",children:e})});$e.displayName="FileIcon";const yt=d.memo(d.forwardRef((t,n)=>{const{file:e,className:r,error:o,rightSlot:a,...s}=t;return i.jsxs("div",{className:ve(r,"flex h-8 w-full items-center gap-2 rounded-md border border-(--base-a6) bg-(--base-2) text-sm py-1 px-2 h-max",{"text-(--gray-11)":o}),ref:n,...s,children:[o?i.jsx(c.RiIcon,{icon:"RiFileWarningLine"}):i.jsx($e,{fileType:(e==null?void 0:e.type)??""}),o||(e?i.jsx(c.Text,{className:"truncate",children:e.name}):i.jsx("div",{className:"flex w-full justify-center",children:i.jsx(c.Spinner,{})})),a]})}));yt.displayName="FileCard";const ke=500,ye=1e4,de={danger:"danger",warning:"warning",info:"base",success:"success"},Yr={boolean:"RiCheckboxCircleLine",date:"RiCalendarLine","multi-string":"RiListCheck",number:"RiHashtag",qr:"RiQrCodeLine","multi-select":"RiCheckboxLine",select:"RiMenuFoldLine",string:"RiInputField",text:"RiAlignJustify",upload:"RiUpload2Line",custom:"RiCodeSSlashLine",section:"RiFolderLine"};class bt{constructor(n){T(this,"type");T(this,"identifier");T(this,"description");const{description:e=null,identifier:r,type:o}=n;this.identifier=r,this.description=e,this.type=o}getId(){return this.identifier}static deserialize(n){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}const H={label:"",description:"",required:!1};class k extends bt{constructor(e){const{label:r,required:o,image:a,fieldValidators:s=[],formValidators:l=[],...m}=e;super(m);T(this,"required");T(this,"formValidators");T(this,"fieldValidators");T(this,"label");T(this,"image");T(this,"onlyValidateAfterTouched",!0);this.label=r,this.required=o,this.image=a,this.fieldValidators=s,this.formValidators=l}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,r){if(this.required&&this.isBlank(e))return"This field is required.";for(const o of this.getFieldValidators()){const a=o(e);if(a)return a}if(r)for(const o of this.getFormValidators()){const a=o(e,r);if(a)return a}}_serialize(){return{...super._serialize(),label:this.label,required:this.required,image:this.image}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}encodeValueToJson(e){return JSON.stringify(e)}decodeJsonToValue(e){return JSON.parse(e)}}T(k,"fieldTypeName"),T(k,"fieldTypeDescription");const G=t=>{const{id:n,field:e,formId:r,size:o,showInputOnly:a,onValuesChange:s,...l}=t,[m,u,f]=V.useField(e.getId()),{touched:h}=u,g=u.error??e.description,C=u.error?"danger":void 0,w=n??`${r}-${e.getId()}-input`,p=`${w}-label`,y=e.required?`${e.label} *`:e.label,x=d.useMemo(()=>({...m,onChange:S=>{f.setValue(S,!1).then(),s==null||s(e.getId(),S),(h||!e.onlyValidateAfterTouched)&&f.setError(e.getError(S))},onBlur:S=>{f.setTouched(!0,!1).then(),f.setError(e.getError(S))}}),[e,m,f,s,h]);return[{helpText:g,size:o,severity:C,inputId:w,labelId:p,label:y,showInputOnly:a,fieldProps:x,helpers:f,field:e,touched:h},{...l,"aria-labelledby":p}]},Cn=d.createContext(()=>{throw new Error("No ImageViewerProvider found")}),Ue=()=>d.useContext(Cn);function oe(t,n,{checkForDefaultPrevented:e=!0}={}){return function(o){if(t==null||t(o),e===!1||!o.defaultPrevented)return n==null?void 0:n(o)}}function wn(t,n){if(typeof t=="function")return t(n);t!=null&&(t.current=n)}function In(...t){return n=>{let e=!1;const r=t.map(o=>{const a=wn(o,n);return!e&&typeof a=="function"&&(e=!0),a});if(e)return()=>{for(let o=0;o<r.length;o++){const a=r[o];typeof a=="function"?a():wn(t[o],null)}}}}function ue(...t){return v.useCallback(In(...t),t)}function Jr(t,n){const e=v.createContext(n),r=a=>{const{children:s,...l}=a,m=v.useMemo(()=>l,Object.values(l));return i.jsx(e.Provider,{value:m,children:s})};r.displayName=t+"Provider";function o(a){const s=v.useContext(e);if(s)return s;if(n!==void 0)return n;throw new Error(`\`${a}\` must be used within \`${t}\``)}return[r,o]}function Zr(t,n=[]){let e=[];function r(a,s){const l=v.createContext(s),m=e.length;e=[...e,s];const u=h=>{var x;const{scope:g,children:C,...w}=h,p=((x=g==null?void 0:g[t])==null?void 0:x[m])||l,y=v.useMemo(()=>w,Object.values(w));return i.jsx(p.Provider,{value:y,children:C})};u.displayName=a+"Provider";function f(h,g){var p;const C=((p=g==null?void 0:g[t])==null?void 0:p[m])||l,w=v.useContext(C);if(w)return w;if(s!==void 0)return s;throw new Error(`\`${h}\` must be used within \`${a}\``)}return[u,f]}const o=()=>{const a=e.map(s=>v.createContext(s));return function(l){const m=(l==null?void 0:l[t])||a;return v.useMemo(()=>({[`__scope${t}`]:{...l,[t]:m}}),[l,m])}};return o.scopeName=t,[r,Rr(o,...n)]}function Rr(...t){const n=t[0];if(t.length===1)return n;const e=()=>{const r=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(a){const s=r.reduce((l,{useScope:m,scopeName:u})=>{const h=m(a)[`__scope${u}`];return{...l,...h}},{});return v.useMemo(()=>({[`__scope${n.scopeName}`]:s}),[s])}};return e.scopeName=n.scopeName,e}var je=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ei=v.useId||(()=>{}),ti=0;function Ct(t){const[n,e]=v.useState(ei());return je(()=>{e(r=>r??String(ti++))},[t]),t||(n?`radix-${n}`:"")}function fe(t){const n=v.useRef(t);return v.useEffect(()=>{n.current=t}),v.useMemo(()=>(...e)=>{var r;return(r=n.current)==null?void 0:r.call(n,...e)},[])}function ni({prop:t,defaultProp:n,onChange:e=()=>{}}){const[r,o]=ri({defaultProp:n,onChange:e}),a=t!==void 0,s=a?t:r,l=fe(e),m=v.useCallback(u=>{if(a){const h=typeof u=="function"?u(t):u;h!==t&&l(h)}else o(u)},[a,t,o,l]);return[s,m]}function ri({defaultProp:t,onChange:n}){const e=v.useState(t),[r]=e,o=v.useRef(r),a=fe(n);return v.useEffect(()=>{o.current!==r&&(a(r),o.current=r)},[r,o,a]),e}var wt=v.forwardRef((t,n)=>{const{children:e,...r}=t,o=v.Children.toArray(e),a=o.find(oi);if(a){const s=a.props.children,l=o.map(m=>m===a?v.Children.count(s)>1?v.Children.only(null):v.isValidElement(s)?s.props.children:null:m);return i.jsx(It,{...r,ref:n,children:v.isValidElement(s)?v.cloneElement(s,void 0,l):null})}return i.jsx(It,{...r,ref:n,children:e})});wt.displayName="Slot";var It=v.forwardRef((t,n)=>{const{children:e,...r}=t;if(v.isValidElement(e)){const o=si(e);return v.cloneElement(e,{...ai(r,e.props),ref:n?In(n,o):o})}return v.Children.count(e)>1?v.Children.only(null):null});It.displayName="SlotClone";var ii=({children:t})=>i.jsx(i.Fragment,{children:t});function oi(t){return v.isValidElement(t)&&t.type===ii}function ai(t,n){const e={...n};for(const r in n){const o=t[r],a=n[r];/^on[A-Z]/.test(r)?o&&a?e[r]=(...l)=>{a(...l),o(...l)}:o&&(e[r]=o):r==="style"?e[r]={...o,...a}:r==="className"&&(e[r]=[o,a].filter(Boolean).join(" "))}return{...t,...e}}function si(t){var r,o;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,e=n&&"isReactWarning"in n&&n.isReactWarning;return e?t.ref:(n=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,e=n&&"isReactWarning"in n&&n.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var li=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],ne=li.reduce((t,n)=>{const e=v.forwardRef((r,o)=>{const{asChild:a,...s}=r,l=a?wt:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(l,{...s,ref:o})});return e.displayName=`Primitive.${n}`,{...t,[n]:e}},{});function ci(t,n){t&&Kr.flushSync(()=>t.dispatchEvent(n))}function di(t,n=globalThis==null?void 0:globalThis.document){const e=fe(t);v.useEffect(()=>{const r=o=>{o.key==="Escape"&&e(o)};return n.addEventListener("keydown",r,{capture:!0}),()=>n.removeEventListener("keydown",r,{capture:!0})},[e,n])}var ui="DismissableLayer",xt="dismissableLayer.update",fi="dismissableLayer.pointerDownOutside",hi="dismissableLayer.focusOutside",xn,En=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Sn=v.forwardRef((t,n)=>{const{disableOutsidePointerEvents:e=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:a,onInteractOutside:s,onDismiss:l,...m}=t,u=v.useContext(En),[f,h]=v.useState(null),g=(f==null?void 0:f.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,C]=v.useState({}),w=ue(n,F=>h(F)),p=Array.from(u.layers),[y]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=p.indexOf(y),I=f?p.indexOf(f):-1,b=u.layersWithOutsidePointerEventsDisabled.size>0,S=I>=x,N=gi(F=>{const L=F.target,A=[...u.branches].some(O=>O.contains(L));!S||A||(o==null||o(F),s==null||s(F),F.defaultPrevented||l==null||l())},g),D=vi(F=>{const L=F.target;[...u.branches].some(O=>O.contains(L))||(a==null||a(F),s==null||s(F),F.defaultPrevented||l==null||l())},g);return di(F=>{I===u.layers.size-1&&(r==null||r(F),!F.defaultPrevented&&l&&(F.preventDefault(),l()))},g),v.useEffect(()=>{if(f)return e&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(xn=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(f)),u.layers.add(f),Tn(),()=>{e&&u.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=xn)}},[f,g,e,u]),v.useEffect(()=>()=>{f&&(u.layers.delete(f),u.layersWithOutsidePointerEventsDisabled.delete(f),Tn())},[f,u]),v.useEffect(()=>{const F=()=>C({});return document.addEventListener(xt,F),()=>document.removeEventListener(xt,F)},[]),i.jsx(ne.div,{...m,ref:w,style:{pointerEvents:b?S?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,D.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,D.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,N.onPointerDownCapture)})});Sn.displayName=ui;var pi="DismissableLayerBranch",mi=v.forwardRef((t,n)=>{const e=v.useContext(En),r=v.useRef(null),o=ue(n,r);return v.useEffect(()=>{const a=r.current;if(a)return e.branches.add(a),()=>{e.branches.delete(a)}},[e.branches]),i.jsx(ne.div,{...t,ref:o})});mi.displayName=pi;function gi(t,n=globalThis==null?void 0:globalThis.document){const e=fe(t),r=v.useRef(!1),o=v.useRef(()=>{});return v.useEffect(()=>{const a=l=>{if(l.target&&!r.current){let m=function(){Nn(fi,e,u,{discrete:!0})};const u={originalEvent:l};l.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=m,n.addEventListener("click",o.current,{once:!0})):m()}else n.removeEventListener("click",o.current);r.current=!1},s=window.setTimeout(()=>{n.addEventListener("pointerdown",a)},0);return()=>{window.clearTimeout(s),n.removeEventListener("pointerdown",a),n.removeEventListener("click",o.current)}},[n,e]),{onPointerDownCapture:()=>r.current=!0}}function vi(t,n=globalThis==null?void 0:globalThis.document){const e=fe(t),r=v.useRef(!1);return v.useEffect(()=>{const o=a=>{a.target&&!r.current&&Nn(hi,e,{originalEvent:a},{discrete:!1})};return n.addEventListener("focusin",o),()=>n.removeEventListener("focusin",o)},[n,e]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Tn(){const t=new CustomEvent(xt);document.dispatchEvent(t)}function Nn(t,n,e,{discrete:r}){const o=e.originalEvent.target,a=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:e});n&&o.addEventListener(t,n,{once:!0}),r?ci(o,a):o.dispatchEvent(a)}var Et="focusScope.autoFocusOnMount",St="focusScope.autoFocusOnUnmount",Fn={bubbles:!1,cancelable:!0},yi="FocusScope",Ln=v.forwardRef((t,n)=>{const{loop:e=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:a,...s}=t,[l,m]=v.useState(null),u=fe(o),f=fe(a),h=v.useRef(null),g=ue(n,p=>m(p)),C=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let p=function(b){if(C.paused||!l)return;const S=b.target;l.contains(S)?h.current=S:ae(h.current,{select:!0})},y=function(b){if(C.paused||!l)return;const S=b.relatedTarget;S!==null&&(l.contains(S)||ae(h.current,{select:!0}))},x=function(b){if(document.activeElement===document.body)for(const N of b)N.removedNodes.length>0&&ae(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",y);const I=new MutationObserver(x);return l&&I.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",y),I.disconnect()}}},[r,l,C.paused]),v.useEffect(()=>{if(l){An.add(C);const p=document.activeElement;if(!l.contains(p)){const x=new CustomEvent(Et,Fn);l.addEventListener(Et,u),l.dispatchEvent(x),x.defaultPrevented||(bi(Ei(Dn(l)),{select:!0}),document.activeElement===p&&ae(l))}return()=>{l.removeEventListener(Et,u),setTimeout(()=>{const x=new CustomEvent(St,Fn);l.addEventListener(St,f),l.dispatchEvent(x),x.defaultPrevented||ae(p??document.body,{select:!0}),l.removeEventListener(St,f),An.remove(C)},0)}}},[l,u,f,C]);const w=v.useCallback(p=>{if(!e&&!r||C.paused)return;const y=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,x=document.activeElement;if(y&&x){const I=p.currentTarget,[b,S]=Ci(I);b&&S?!p.shiftKey&&x===S?(p.preventDefault(),e&&ae(b,{select:!0})):p.shiftKey&&x===b&&(p.preventDefault(),e&&ae(S,{select:!0})):x===I&&p.preventDefault()}},[e,r,C.paused]);return i.jsx(ne.div,{tabIndex:-1,...s,ref:g,onKeyDown:w})});Ln.displayName=yi;function bi(t,{select:n=!1}={}){const e=document.activeElement;for(const r of t)if(ae(r,{select:n}),document.activeElement!==e)return}function Ci(t){const n=Dn(t),e=Mn(n,t),r=Mn(n.reverse(),t);return[e,r]}function Dn(t){const n=[],e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)n.push(e.currentNode);return n}function Mn(t,n){for(const e of t)if(!wi(e,{upTo:n}))return e}function wi(t,{upTo:n}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(n!==void 0&&t===n)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Ii(t){return t instanceof HTMLInputElement&&"select"in t}function ae(t,{select:n=!1}={}){if(t&&t.focus){const e=document.activeElement;t.focus({preventScroll:!0}),t!==e&&Ii(t)&&n&&t.select()}}var An=xi();function xi(){let t=[];return{add(n){const e=t[0];n!==e&&(e==null||e.pause()),t=Pn(t,n),t.unshift(n)},remove(n){var e;t=Pn(t,n),(e=t[0])==null||e.resume()}}}function Pn(t,n){const e=[...t],r=e.indexOf(n);return r!==-1&&e.splice(r,1),e}function Ei(t){return t.filter(n=>n.tagName!=="A")}var Si="Portal",On=v.forwardRef((t,n)=>{var l;const{container:e,...r}=t,[o,a]=v.useState(!1);je(()=>a(!0),[]);const s=e||o&&((l=globalThis==null?void 0:globalThis.document)==null?void 0:l.body);return s?pn.createPortal(i.jsx(ne.div,{...r,ref:n}),s):null});On.displayName=Si;function Ti(t,n){return v.useReducer((e,r)=>n[e][r]??e,t)}var We=t=>{const{present:n,children:e}=t,r=Ni(n),o=typeof e=="function"?e({present:r.isPresent}):v.Children.only(e),a=ue(r.ref,Fi(o));return typeof e=="function"||r.isPresent?v.cloneElement(o,{ref:a}):null};We.displayName="Presence";function Ni(t){const[n,e]=v.useState(),r=v.useRef({}),o=v.useRef(t),a=v.useRef("none"),s=t?"mounted":"unmounted",[l,m]=Ti(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const u=qe(r.current);a.current=l==="mounted"?u:"none"},[l]),je(()=>{const u=r.current,f=o.current;if(f!==t){const g=a.current,C=qe(u);t?m("MOUNT"):C==="none"||(u==null?void 0:u.display)==="none"?m("UNMOUNT"):m(f&&g!==C?"ANIMATION_OUT":"UNMOUNT"),o.current=t}},[t,m]),je(()=>{if(n){let u;const f=n.ownerDocument.defaultView??window,h=C=>{const p=qe(r.current).includes(C.animationName);if(C.target===n&&p&&(m("ANIMATION_END"),!o.current)){const y=n.style.animationFillMode;n.style.animationFillMode="forwards",u=f.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=y)})}},g=C=>{C.target===n&&(a.current=qe(r.current))};return n.addEventListener("animationstart",g),n.addEventListener("animationcancel",h),n.addEventListener("animationend",h),()=>{f.clearTimeout(u),n.removeEventListener("animationstart",g),n.removeEventListener("animationcancel",h),n.removeEventListener("animationend",h)}}else m("ANIMATION_END")},[n,m]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:v.useCallback(u=>{u&&(r.current=getComputedStyle(u)),e(u)},[])}}function qe(t){return(t==null?void 0:t.animationName)||"none"}function Fi(t){var r,o;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,e=n&&"isReactWarning"in n&&n.isReactWarning;return e?t.ref:(n=(o=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:o.get,e=n&&"isReactWarning"in n&&n.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Tt=0;function Li(){v.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??Bn()),document.body.insertAdjacentElement("beforeend",t[1]??Bn()),Tt++,()=>{Tt===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(n=>n.remove()),Tt--}},[])}function Bn(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var Z=function(){return Z=Object.assign||function(n){for(var e,r=1,o=arguments.length;r<o;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},Z.apply(this,arguments)};function zn(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(t);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(e[r[o]]=t[r[o]]);return e}function Di(t,n,e){if(e||arguments.length===2)for(var r=0,o=n.length,a;r<o;r++)(a||!(r in n))&&(a||(a=Array.prototype.slice.call(n,0,r)),a[r]=n[r]);return t.concat(a||Array.prototype.slice.call(n))}typeof SuppressedError=="function"&&SuppressedError;var He="right-scroll-bar-position",Ge="width-before-scroll-bar",Mi="with-scroll-bars-hidden",Ai="--removed-body-scroll-bar-size";function Nt(t,n){return typeof t=="function"?t(n):t&&(t.current=n),t}function Pi(t,n){var e=d.useState(function(){return{value:t,callback:n,facade:{get current(){return e.value},set current(r){var o=e.value;o!==r&&(e.value=r,e.callback(r,o))}}}})[0];return e.callback=n,e.facade}var Oi=typeof window<"u"?v.useLayoutEffect:v.useEffect,_n=new WeakMap;function Bi(t,n){var e=Pi(null,function(r){return t.forEach(function(o){return Nt(o,r)})});return Oi(function(){var r=_n.get(e);if(r){var o=new Set(r),a=new Set(t),s=e.current;o.forEach(function(l){a.has(l)||Nt(l,null)}),a.forEach(function(l){o.has(l)||Nt(l,s)})}_n.set(e,t)},[t]),e}function zi(t){return t}function _i(t,n){n===void 0&&(n=zi);var e=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:t},useMedium:function(a){var s=n(a,r);return e.push(s),function(){e=e.filter(function(l){return l!==s})}},assignSyncMedium:function(a){for(r=!0;e.length;){var s=e;e=[],s.forEach(a)}e={push:function(l){return a(l)},filter:function(){return e}}},assignMedium:function(a){r=!0;var s=[];if(e.length){var l=e;e=[],l.forEach(a),s=e}var m=function(){var f=s;s=[],f.forEach(a)},u=function(){return Promise.resolve().then(m)};u(),e={push:function(f){s.push(f),u()},filter:function(f){return s=s.filter(f),e}}}};return o}function Vi(t){t===void 0&&(t={});var n=_i(null);return n.options=Z({async:!0,ssr:!1},t),n}var Vn=function(t){var n=t.sideCar,e=zn(t,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,Z({},e))};Vn.isSideCarExport=!0;function $i(t,n){return t.useMedium(n),Vn}var $n=Vi(),Ft=function(){},Xe=v.forwardRef(function(t,n){var e=v.useRef(null),r=v.useState({onScrollCapture:Ft,onWheelCapture:Ft,onTouchMoveCapture:Ft}),o=r[0],a=r[1],s=t.forwardProps,l=t.children,m=t.className,u=t.removeScrollBar,f=t.enabled,h=t.shards,g=t.sideCar,C=t.noIsolation,w=t.inert,p=t.allowPinchZoom,y=t.as,x=y===void 0?"div":y,I=t.gapMode,b=zn(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=g,N=Bi([e,n]),D=Z(Z({},b),o);return v.createElement(v.Fragment,null,f&&v.createElement(S,{sideCar:$n,removeScrollBar:u,shards:h,noIsolation:C,inert:w,setCallbacks:a,allowPinchZoom:!!p,lockRef:e,gapMode:I}),s?v.cloneElement(v.Children.only(l),Z(Z({},D),{ref:N})):v.createElement(x,Z({},D,{className:m,ref:N}),l))});Xe.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Xe.classNames={fullWidth:Ge,zeroRight:He};var ki=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ui(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var n=ki();return n&&t.setAttribute("nonce",n),t}function ji(t,n){t.styleSheet?t.styleSheet.cssText=n:t.appendChild(document.createTextNode(n))}function Wi(t){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(t)}var qi=function(){var t=0,n=null;return{add:function(e){t==0&&(n=Ui())&&(ji(n,e),Wi(n)),t++},remove:function(){t--,!t&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},Hi=function(){var t=qi();return function(n,e){v.useEffect(function(){return t.add(n),function(){t.remove()}},[n&&e])}},kn=function(){var t=Hi(),n=function(e){var r=e.styles,o=e.dynamic;return t(r,o),null};return n},Gi={left:0,top:0,right:0,gap:0},Lt=function(t){return parseInt(t||"",10)||0},Xi=function(t){var n=window.getComputedStyle(document.body),e=n[t==="padding"?"paddingLeft":"marginLeft"],r=n[t==="padding"?"paddingTop":"marginTop"],o=n[t==="padding"?"paddingRight":"marginRight"];return[Lt(e),Lt(r),Lt(o)]},Ki=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Gi;var n=Xi(t),e=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-e+n[2]-n[0])}},Qi=kn(),be="data-scroll-locked",Yi=function(t,n,e,r){var o=t.left,a=t.top,s=t.right,l=t.gap;return e===void 0&&(e="margin"),`
|
|
2
2
|
.`.concat(Mi,` {
|
|
3
3
|
overflow: hidden `).concat(r,`;
|
|
4
4
|
padding-right: `).concat(l,"px ").concat(r,`;
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
body[`).concat(be,`] {
|
|
36
36
|
`).concat(Ai,": ").concat(l,`px;
|
|
37
37
|
}
|
|
38
|
-
`)},Un=function(){var t=parseInt(document.body.getAttribute(be)||"0",10);return isFinite(t)?t:0},Ji=function(){v.useEffect(function(){return document.body.setAttribute(be,(Un()+1).toString()),function(){var t=Un()-1;t<=0?document.body.removeAttribute(be):document.body.setAttribute(be,t.toString())}},[])},Zi=function(t){var n=t.noRelative,e=t.noImportant,r=t.gapMode,o=r===void 0?"margin":r;Ji();var a=v.useMemo(function(){return Ki(o)},[o]);return v.createElement(Qi,{styles:Yi(a,!n,o,e?"":"!important")})},Dt=!1;if(typeof window<"u")try{var Ke=Object.defineProperty({},"passive",{get:function(){return Dt=!0,!0}});window.addEventListener("test",Ke,Ke),window.removeEventListener("test",Ke,Ke)}catch{Dt=!1}var Ce=Dt?{passive:!1}:!1,Ri=function(t){return t.tagName==="TEXTAREA"},jn=function(t,n){if(!(t instanceof Element))return!1;var e=window.getComputedStyle(t);return e[n]!=="hidden"&&!(e.overflowY===e.overflowX&&!Ri(t)&&e[n]==="visible")},eo=function(t){return jn(t,"overflowY")},to=function(t){return jn(t,"overflowX")},Wn=function(t,n){var e=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=qn(t,r);if(o){var a=Hn(t,r),s=a[1],l=a[2];if(s>l)return!0}r=r.parentNode}while(r&&r!==e.body);return!1},no=function(t){var n=t.scrollTop,e=t.scrollHeight,r=t.clientHeight;return[n,e,r]},ro=function(t){var n=t.scrollLeft,e=t.scrollWidth,r=t.clientWidth;return[n,e,r]},qn=function(t,n){return t==="v"?eo(n):to(n)},Hn=function(t,n){return t==="v"?no(n):ro(n)},io=function(t,n){return t==="h"&&n==="rtl"?-1:1},oo=function(t,n,e,r,o){var a=io(t,window.getComputedStyle(n).direction),s=a*r,l=e.target,m=n.contains(l),u=!1,f=s>0,h=0,g=0;do{var C=Hn(t,l),w=C[0],p=C[1],y=C[2],
|
|
38
|
+
`)},Un=function(){var t=parseInt(document.body.getAttribute(be)||"0",10);return isFinite(t)?t:0},Ji=function(){v.useEffect(function(){return document.body.setAttribute(be,(Un()+1).toString()),function(){var t=Un()-1;t<=0?document.body.removeAttribute(be):document.body.setAttribute(be,t.toString())}},[])},Zi=function(t){var n=t.noRelative,e=t.noImportant,r=t.gapMode,o=r===void 0?"margin":r;Ji();var a=v.useMemo(function(){return Ki(o)},[o]);return v.createElement(Qi,{styles:Yi(a,!n,o,e?"":"!important")})},Dt=!1;if(typeof window<"u")try{var Ke=Object.defineProperty({},"passive",{get:function(){return Dt=!0,!0}});window.addEventListener("test",Ke,Ke),window.removeEventListener("test",Ke,Ke)}catch{Dt=!1}var Ce=Dt?{passive:!1}:!1,Ri=function(t){return t.tagName==="TEXTAREA"},jn=function(t,n){if(!(t instanceof Element))return!1;var e=window.getComputedStyle(t);return e[n]!=="hidden"&&!(e.overflowY===e.overflowX&&!Ri(t)&&e[n]==="visible")},eo=function(t){return jn(t,"overflowY")},to=function(t){return jn(t,"overflowX")},Wn=function(t,n){var e=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=qn(t,r);if(o){var a=Hn(t,r),s=a[1],l=a[2];if(s>l)return!0}r=r.parentNode}while(r&&r!==e.body);return!1},no=function(t){var n=t.scrollTop,e=t.scrollHeight,r=t.clientHeight;return[n,e,r]},ro=function(t){var n=t.scrollLeft,e=t.scrollWidth,r=t.clientWidth;return[n,e,r]},qn=function(t,n){return t==="v"?eo(n):to(n)},Hn=function(t,n){return t==="v"?no(n):ro(n)},io=function(t,n){return t==="h"&&n==="rtl"?-1:1},oo=function(t,n,e,r,o){var a=io(t,window.getComputedStyle(n).direction),s=a*r,l=e.target,m=n.contains(l),u=!1,f=s>0,h=0,g=0;do{var C=Hn(t,l),w=C[0],p=C[1],y=C[2],x=p-y-a*w;(w||x)&&qn(t,l)&&(h+=x,g+=w),l instanceof ShadowRoot?l=l.host:l=l.parentNode}while(!m&&l!==document.body||m&&(n.contains(l)||n===l));return(f&&Math.abs(h)<1||!f&&Math.abs(g)<1)&&(u=!0),u},Qe=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},Gn=function(t){return[t.deltaX,t.deltaY]},Xn=function(t){return t&&"current"in t?t.current:t},ao=function(t,n){return t[0]===n[0]&&t[1]===n[1]},so=function(t){return`
|
|
39
39
|
.block-interactivity-`.concat(t,` {pointer-events: none;}
|
|
40
40
|
.allow-interactivity-`).concat(t,` {pointer-events: all;}
|
|
41
|
-
`)},lo=0,we=[];function co(t){var n=v.useRef([]),e=v.useRef([0,0]),r=v.useRef(),o=v.useState(lo++)[0],a=v.useState(kn)[0],s=v.useRef(t);v.useEffect(function(){s.current=t},[t]),v.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(o));var p=Di([t.lockRef.current],(t.shards||[]).map(Xn),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[t.inert,t.lockRef.current,t.shards]);var l=v.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!s.current.allowPinchZoom;var
|
|
41
|
+
`)},lo=0,we=[];function co(t){var n=v.useRef([]),e=v.useRef([0,0]),r=v.useRef(),o=v.useState(lo++)[0],a=v.useState(kn)[0],s=v.useRef(t);v.useEffect(function(){s.current=t},[t]),v.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(o));var p=Di([t.lockRef.current],(t.shards||[]).map(Xn),!0).filter(Boolean);return p.forEach(function(y){return y.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),p.forEach(function(y){return y.classList.remove("allow-interactivity-".concat(o))})}}},[t.inert,t.lockRef.current,t.shards]);var l=v.useCallback(function(p,y){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!s.current.allowPinchZoom;var x=Qe(p),I=e.current,b="deltaX"in p?p.deltaX:I[0]-x[0],S="deltaY"in p?p.deltaY:I[1]-x[1],N,D=p.target,F=Math.abs(b)>Math.abs(S)?"h":"v";if("touches"in p&&F==="h"&&D.type==="range")return!1;var L=Wn(F,D);if(!L)return!0;if(L?N=F:(N=F==="v"?"h":"v",L=Wn(F,D)),!L)return!1;if(!r.current&&"changedTouches"in p&&(b||S)&&(r.current=N),!N)return!0;var A=r.current||N;return oo(A,y,p,A==="h"?b:S)},[]),m=v.useCallback(function(p){var y=p;if(!(!we.length||we[we.length-1]!==a)){var x="deltaY"in y?Gn(y):Qe(y),I=n.current.filter(function(N){return N.name===y.type&&(N.target===y.target||y.target===N.shadowParent)&&ao(N.delta,x)})[0];if(I&&I.should){y.cancelable&&y.preventDefault();return}if(!I){var b=(s.current.shards||[]).map(Xn).filter(Boolean).filter(function(N){return N.contains(y.target)}),S=b.length>0?l(y,b[0]):!s.current.noIsolation;S&&y.cancelable&&y.preventDefault()}}},[]),u=v.useCallback(function(p,y,x,I){var b={name:p,delta:y,target:x,should:I,shadowParent:uo(x)};n.current.push(b),setTimeout(function(){n.current=n.current.filter(function(S){return S!==b})},1)},[]),f=v.useCallback(function(p){e.current=Qe(p),r.current=void 0},[]),h=v.useCallback(function(p){u(p.type,Gn(p),p.target,l(p,t.lockRef.current))},[]),g=v.useCallback(function(p){u(p.type,Qe(p),p.target,l(p,t.lockRef.current))},[]);v.useEffect(function(){return we.push(a),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:g}),document.addEventListener("wheel",m,Ce),document.addEventListener("touchmove",m,Ce),document.addEventListener("touchstart",f,Ce),function(){we=we.filter(function(p){return p!==a}),document.removeEventListener("wheel",m,Ce),document.removeEventListener("touchmove",m,Ce),document.removeEventListener("touchstart",f,Ce)}},[]);var C=t.removeScrollBar,w=t.inert;return v.createElement(v.Fragment,null,w?v.createElement(a,{styles:so(o)}):null,C?v.createElement(Zi,{gapMode:t.gapMode}):null)}function uo(t){for(var n=null;t!==null;)t instanceof ShadowRoot&&(n=t.host,t=t.host),t=t.parentNode;return n}const fo=$i($n,co);var Kn=v.forwardRef(function(t,n){return v.createElement(Xe,Z({},t,{ref:n,sideCar:fo}))});Kn.classNames=Xe.classNames;var ho=function(t){if(typeof document>"u")return null;var n=Array.isArray(t)?t[0]:t;return n.ownerDocument.body},Ie=new WeakMap,Ye=new WeakMap,Je={},Mt=0,Qn=function(t){return t&&(t.host||Qn(t.parentNode))},po=function(t,n){return n.map(function(e){if(t.contains(e))return e;var r=Qn(e);return r&&t.contains(r)?r:(console.error("aria-hidden",e,"in not contained inside",t,". Doing nothing"),null)}).filter(function(e){return!!e})},mo=function(t,n,e,r){var o=po(n,Array.isArray(t)?t:[t]);Je[e]||(Je[e]=new WeakMap);var a=Je[e],s=[],l=new Set,m=new Set(o),u=function(h){!h||l.has(h)||(l.add(h),u(h.parentNode))};o.forEach(u);var f=function(h){!h||m.has(h)||Array.prototype.forEach.call(h.children,function(g){if(l.has(g))f(g);else try{var C=g.getAttribute(r),w=C!==null&&C!=="false",p=(Ie.get(g)||0)+1,y=(a.get(g)||0)+1;Ie.set(g,p),a.set(g,y),s.push(g),p===1&&w&&Ye.set(g,!0),y===1&&g.setAttribute(e,"true"),w||g.setAttribute(r,"true")}catch(x){console.error("aria-hidden: cannot operate on ",g,x)}})};return f(n),l.clear(),Mt++,function(){s.forEach(function(h){var g=Ie.get(h)-1,C=a.get(h)-1;Ie.set(h,g),a.set(h,C),g||(Ye.has(h)||h.removeAttribute(r),Ye.delete(h)),C||h.removeAttribute(e)}),Mt--,Mt||(Ie=new WeakMap,Ie=new WeakMap,Ye=new WeakMap,Je={})}},go=function(t,n,e){e===void 0&&(e="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),o=ho(t);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),mo(r,o,e,"aria-hidden")):function(){return null}},At="Dialog",[Yn,ta]=Zr(At),[vo,Q]=Yn(At),Jn=t=>{const{__scopeDialog:n,children:e,open:r,defaultOpen:o,onOpenChange:a,modal:s=!0}=t,l=v.useRef(null),m=v.useRef(null),[u=!1,f]=ni({prop:r,defaultProp:o,onChange:a});return i.jsx(vo,{scope:n,triggerRef:l,contentRef:m,contentId:Ct(),titleId:Ct(),descriptionId:Ct(),open:u,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:s,children:e})};Jn.displayName=At;var Zn="DialogTrigger",Rn=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,o=Q(Zn,e),a=ue(n,o.triggerRef);return i.jsx(ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Bt(o.open),...r,ref:a,onClick:oe(t.onClick,o.onOpenToggle)})});Rn.displayName=Zn;var Pt="DialogPortal",[yo,er]=Yn(Pt,{forceMount:void 0}),tr=t=>{const{__scopeDialog:n,forceMount:e,children:r,container:o}=t,a=Q(Pt,n);return i.jsx(yo,{scope:n,forceMount:e,children:v.Children.map(r,s=>i.jsx(We,{present:e||a.open,children:i.jsx(On,{asChild:!0,container:o,children:s})}))})};tr.displayName=Pt;var Ze="DialogOverlay",nr=v.forwardRef((t,n)=>{const e=er(Ze,t.__scopeDialog),{forceMount:r=e.forceMount,...o}=t,a=Q(Ze,t.__scopeDialog);return a.modal?i.jsx(We,{present:r||a.open,children:i.jsx(bo,{...o,ref:n})}):null});nr.displayName=Ze;var bo=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,o=Q(Ze,e);return i.jsx(Kn,{as:wt,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(ne.div,{"data-state":Bt(o.open),...r,ref:n,style:{pointerEvents:"auto",...r.style}})})}),he="DialogContent",rr=v.forwardRef((t,n)=>{const e=er(he,t.__scopeDialog),{forceMount:r=e.forceMount,...o}=t,a=Q(he,t.__scopeDialog);return i.jsx(We,{present:r||a.open,children:a.modal?i.jsx(Co,{...o,ref:n}):i.jsx(wo,{...o,ref:n})})});rr.displayName=he;var Co=v.forwardRef((t,n)=>{const e=Q(he,t.__scopeDialog),r=v.useRef(null),o=ue(n,e.contentRef,r);return v.useEffect(()=>{const a=r.current;if(a)return go(a)},[]),i.jsx(ir,{...t,ref:o,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:oe(t.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=e.triggerRef.current)==null||s.focus()}),onPointerDownOutside:oe(t.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:oe(t.onFocusOutside,a=>a.preventDefault())})}),wo=v.forwardRef((t,n)=>{const e=Q(he,t.__scopeDialog),r=v.useRef(!1),o=v.useRef(!1);return i.jsx(ir,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,l;(s=t.onCloseAutoFocus)==null||s.call(t,a),a.defaultPrevented||(r.current||(l=e.triggerRef.current)==null||l.focus(),a.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:a=>{var m,u;(m=t.onInteractOutside)==null||m.call(t,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const s=a.target;((u=e.triggerRef.current)==null?void 0:u.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&o.current&&a.preventDefault()}})}),ir=v.forwardRef((t,n)=>{const{__scopeDialog:e,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:a,...s}=t,l=Q(he,e),m=v.useRef(null),u=ue(n,m);return Li(),i.jsxs(i.Fragment,{children:[i.jsx(Ln,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:a,children:i.jsx(Sn,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Bt(l.open),...s,ref:u,onDismiss:()=>l.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(Eo,{titleId:l.titleId}),i.jsx(To,{contentRef:m,descriptionId:l.descriptionId})]})]})}),Ot="DialogTitle",Io=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,o=Q(Ot,e);return i.jsx(ne.h2,{id:o.titleId,...r,ref:n})});Io.displayName=Ot;var or="DialogDescription",xo=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,o=Q(or,e);return i.jsx(ne.p,{id:o.descriptionId,...r,ref:n})});xo.displayName=or;var ar="DialogClose",sr=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,o=Q(ar,e);return i.jsx(ne.button,{type:"button",...r,ref:n,onClick:oe(t.onClick,()=>o.onOpenChange(!1))})});sr.displayName=ar;function Bt(t){return t?"open":"closed"}var lr="DialogTitleWarning",[na,cr]=Jr(lr,{contentName:he,titleName:Ot,docsSlug:"dialog"}),Eo=({titleId:t})=>{const n=cr(lr),e=`\`${n.contentName}\` requires a \`${n.titleName}\` for the component to be accessible for screen reader users.
|
|
42
42
|
|
|
43
43
|
If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
44
44
|
|
|
45
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},So="DialogDescriptionWarning",To=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${cr(So).contentName}}.`;return v.useEffect(()=>{var a;const o=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},zt=Jn,No=Rn,_t=tr,Vt=nr,$t=rr,dr=sr,Re=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},et={exports:{}},Fo=et.exports,ur;function Lo(){return ur||(ur=1,function(t,n){(function(e,r){r()})(Fo,function(){function e(u,f){return typeof f>"u"?f={autoBom:!1}:typeof f!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),f={autoBom:!f}),f.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(u.type)?new Blob(["\uFEFF",u],{type:u.type}):u}function r(u,f,h){var g=new XMLHttpRequest;g.open("GET",u),g.responseType="blob",g.onload=function(){m(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function o(u){var f=new XMLHttpRequest;f.open("HEAD",u,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(u){try{u.dispatchEvent(new MouseEvent("click"))}catch{var f=document.createEvent("MouseEvents");f.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),u.dispatchEvent(f)}}var s=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof Re=="object"&&Re.global===Re?Re:void 0,l=s.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),m=s.saveAs||(typeof window!="object"||window!==s?function(){}:"download"in HTMLAnchorElement.prototype&&!l?function(u,f,h){var g=s.URL||s.webkitURL,C=document.createElement("a");f=f||u.name||"download",C.download=f,C.rel="noopener",typeof u=="string"?(C.href=u,C.origin===location.origin?a(C):o(C.href)?r(u,f,h):a(C,C.target="_blank")):(C.href=g.createObjectURL(u),setTimeout(function(){g.revokeObjectURL(C.href)},4e4),setTimeout(function(){a(C)},0))}:"msSaveOrOpenBlob"in navigator?function(u,f,h){if(f=f||u.name||"download",typeof u!="string")navigator.msSaveOrOpenBlob(e(u,h),f);else if(o(u))r(u,f,h);else{var g=document.createElement("a");g.href=u,g.target="_blank",setTimeout(function(){a(g)})}}:function(u,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof u=="string")return r(u,f,h);var C=u.type==="application/octet-stream",w=/constructor/i.test(s.HTMLElement)||s.safari,p=/CriOS\/[\d]+/.test(navigator.userAgent);if((p||C&&w||l)&&typeof FileReader<"u"){var y=new FileReader;y.onloadend=function(){var b=y.result;b=p?b:b.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=b:location=b,g=null},y.readAsDataURL(u)}else{var E=s.URL||s.webkitURL,I=E.createObjectURL(u);g?g.location=I:location.href=I,g=null,setTimeout(function(){E.revokeObjectURL(I)},4e4)}});s.saveAs=m.saveAs=m,t.exports=m})}(et)),et.exports}var kt=Lo();const Ut=d.memo(t=>{const{file:n,onClose:e}=t,r=d.useRef(null),o=d.useCallback(()=>{var l;if(!r.current)return;const s=document.createElement("canvas");s.width=r.current.width,s.height=r.current.height,(l=s.getContext("2d"))==null||l.drawImage(r.current,0,0,r.current.width,r.current.height),s.toBlob(m=>{m&&navigator.clipboard.write([new ClipboardItem({"image/png":m})])},"image/png")},[]),a=d.useCallback(()=>{kt.saveAs(n,n.name)},[n]);return i.jsx(zt,{open:!0,onOpenChange:e,children:i.jsx(_t,{children:i.jsx(Vt,{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:i.jsxs($t,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:s=>s.preventDefault(),children:[i.jsxs(c.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[i.jsxs(c.Tooltip.Root,{children:[i.jsx(c.Tooltip.Trigger,{children:i.jsx(c.IconButton,{onClick:o,"aria-label":"copy to clipboard",children:i.jsx(c.RiIcon,{icon:"RiFileCopyLine"})})}),i.jsx(c.Tooltip.Content,{size:"sm",children:"Copy"})]}),i.jsxs(c.Tooltip.Root,{children:[i.jsx(c.Tooltip.Trigger,{children:i.jsx(c.IconButton,{onClick:a,"aria-label":"download",children:i.jsx(c.RiIcon,{icon:"RiDownload2Line"})})}),i.jsx(c.Tooltip.Content,{size:"sm",children:"Download"})]}),i.jsx(c.Separator,{orientation:"vertical",size:"sm"}),i.jsx(dr,{asChild:!0,children:i.jsx(c.IconButton,{onClick:e,"aria-label":"close",children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})})})]}),i.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:i.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});Ut.displayName="ImageViewer";const fr=d.memo(t=>{const{children:n}=t,[e,r]=d.useState(null),o=d.useCallback(()=>{r(null)},[]),a=d.useCallback(m=>{r(m(o))},[o]),s=d.useCallback(()=>{e&&(e.onClose&&e.onClose(),o())},[o,e]),l=d.useMemo(()=>a,[a]);return i.jsxs(Cn.Provider,{value:l,children:[n,e&&i.jsx(Ut,{file:e.file,onClose:s})]})});fr.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:o,inputId:a,labelId:s,image:l}=t,[m,u]=d.useState(void 0),f=Ue(),h=o?de[o]:"base";d.useEffect(()=>{l instanceof Promise?l.then(u).catch(console.error):u(l)},[l]);const g=m?URL.createObjectURL(m):void 0,C=d.useCallback(()=>{m&&f(()=>({file:m}))},[f,m]);return i.jsxs("div",{className:"flex flex-col gap-1",children:[m&&i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:g,alt:m.name,onClick:C}),i.jsx("label",{className:ve(n,"flex flex-col gap-1 w-max"),htmlFor:a,children:i.jsx(c.Text,{accentColor:h,size:"sm",id:s,weight:"medium",children:e})}),r]})},jt=t=>{const{helpText:n,children:e,severity:r}=t,o=r?de[r]:"base";return i.jsxs("div",{className:"flex flex-col gap-1",children:[e,!!n&&i.jsx("div",{className:"flex flex-col w-full",children:i.jsx(c.Text,{accentColor:o,size:"xs",children:n})})]})},J=t=>{const{children:n,...e}=t;return i.jsx(jt,{...e,children:n})},Do=[!0,"true"],Wt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onBlur:g,onChange:C}=u,w=a?null:l,p=a?"":m,y=Do.includes(u.value),E=d.useCallback(()=>{g(y)},[g,y]);return i.jsx(J,{helpText:w,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:p,image:a?void 0:s.image,className:"items-center flex-row-reverse justify-end gap-2",children:i.jsx(c.Checkbox.Root,{id:n,name:h,value:y.toString(),checked:y,onCheckedChange:C,onBlur:E,size:"sm",accentColor:"primary",variant:"surface",...f,children:i.jsx(c.Checkbox.Indicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})})})})})});Wt.displayName="BooleanInput";const hr={...H,type:"boolean"},Ee=class Ee extends k{constructor(e){super({...e,type:"boolean"});T(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}getValueFromChangeEvent(e){return typeof e=="boolean"?e:e.target.checked}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Ee(e)}getInput(e){return i.jsx(Wt,{...e,field:this})}};T(Ee,"fieldTypeName","Checkbox"),T(Ee,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),T(Ee,"Icon",$.RiCheckboxCircleLine);let xe=Ee;const qt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onChange:g,onBlur:C}=u,[w,p]=d.useState(!1),y=a?null:l,E=a?"":m,I=u.value?new Date(u.value):void 0,b=d.useCallback(N=>{N&&g(N.toISOString()),p(!1)},[g]),S=d.useCallback(N=>{p(N),N||C(u.value)},[u.value,C]);return i.jsx(J,{helpText:y,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:E,image:a?void 0:s.image,children:i.jsxs(c.Popover.Root,{open:w,onOpenChange:S,children:[i.jsx(c.Popover.Trigger,{asChild:!0,children:i.jsxs(c.Button,{id:n,name:h,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...f,children:[I?I.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",i.jsx(c.RiIcon,{icon:"RiArrowDownSLine"})]})}),i.jsx(c.Popover.Content,{align:"start",children:i.jsx(c.DayPicker,{required:!1,mode:"single",variant:"solid",selected:I,onSelect:b})})]})})})});qt.displayName="DateInput";const pr={...H,type:"date"},Se=class Se extends k{constructor(e){super({...e,type:"date"});T(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return e.target.value}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new Se(e)}getInput(e){return i.jsx(qt,{field:this,...e})}};T(Se,"fieldTypeName","Date"),T(Se,"fieldTypeDescription","Allows specifying a date."),T(Se,"Icon",$.RiCalendarLine);let tt=Se;const mr=d.memo(t=>{const{field:n,...e}=t,[{value:r}]=V.useField(n.options.clonedFieldIdentifier),o=d.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?ut(a):null},[n.options,r]);return Ht(o,e)});mr.displayName="FieldInputCloner";const Mo={...H,type:"custom"};class nt extends k{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 i.jsx(r,{field:this,...e})}}T(nt,"fieldTypeName","Custom"),T(nt,"fieldTypeDescription","Allows re-rendering of field already in the form");class Ao extends nt{constructor(n){super(n,mr)}}const Ht=(t,n)=>d.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),Be=(t,n)=>{const e=d.useMemo(()=>t.map(r=>i.jsx(d.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return i.jsx("div",{className:"flex flex-col gap-4",children:e})},pe=t=>t.type==="section",rt=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Po=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const o of n)o.type==="section"?(e.length>0&&(r.push(rt(`AUTO_section-${n.indexOf(o)}`,e)),e=[]),r.push(o)):e.push(o);return e.length>0&&r.push(rt("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Gt(t,n,e){const r=Array.from(t),[o]=r.splice(n,1);if(!o)throw new Error("Could not find field to reorder.");return r.splice(e,0,o),r}function gr(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function it(t,n){const e=Array.from(t);return e.splice(n,1),e}const Xt=(t,n)=>{const e=new Date;return`${ie.slugify(n)}-${e.getTime()}`},vr=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=vr(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},yr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),ot=(t,n,e,r,o)=>{const{label:a}=e,s={...e,identifier:Xt(null,a)},l=K(r,t);if(l===void 0)throw new Error("Parent path must point to an existing field.");if(!Array.isArray(l))throw new Error("Parent path must point to an array.");const m=gr(l,n,s);o(t,m).then()},Oo=(t,n,e)=>{const r={...rt(),label:""};ot("fields",t,r,n,e)},Kt=()=>{const{showError:t}=c.useToast(),n=d.useCallback((r,o,a,s,l,m)=>{const u=r[o];if(!u)throw new Error("Could not find section context.");let f=typeof u.conditionIndex<"u"?Math.max(u.conditionIndex+1,s):s;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==s){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}m("fields",Gt(l.fields,a,f))},[t]),e=d.useCallback((r,o,a,s,l,m,u)=>{var f;if(!(r!=null&&r.fields)||!s)throw new Error("Could not find section with fields.");if(r.identifier===s.identifier)u(`fields.${o}.fields`,Gt(r.fields,a,m)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=s.condition)==null?void 0:f.identifier)===h.identifier){t({title:"Could not reorder field",description:"Field must be above the section whose condition references it."});return}u(`fields.${o}.fields`,it(r.fields,a)).then(),u(`fields.${l}.fields`,gr(s.fields,m,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},Qt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),h=a?null:l,g=a?"":m,{name:C,onChange:w,onBlur:p}=u,y=d.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),E=`${n}-droppable`,{disabled:I}=f,[b,S]=d.useState(""),[N,D]=d.useState(""),F=N||h,L=d.useCallback(P=>{w(P),p(P)},[w,p]),A=d.useCallback(P=>{y.findIndex(W=>W===P.target.value.trim())>=0?D("All options must be unique"):P.target.value?D(""):D("Option cannot be empty"),S(P.target.value)},[S,y]),O=d.useCallback(()=>{if(N)return;if(!b.trim()){D("Option cannot be empty");return}const P=b.trim();L([...y,P]),S("")},[b,N,L,y]),q=d.useCallback(P=>{P.key==="Enter"&&(P.preventDefault(),O())},[O]),ee=d.useCallback(P=>{L(it(y,P))},[y,L]),z=d.useCallback(P=>{if(!P.destination)return;const W=P.source.index,le=P.destination.index;L(Gt(y,W,le))},[L,y]),X=d.useCallback(()=>{p(y)},[p,y]);return i.jsx(re.DragDropContext,{onDragEnd:z,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(J,{helpText:F,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:g,image:a?void 0:s.image,children:(!I||y.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx(c.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:i.jsx(c.Input.Field,{value:b,onChange:A,onKeyDown:q,id:n,placeholder:s.placeholder,onBlur:X,name:C,...f})}),i.jsx(c.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!N||I,onClick:O,children:i.jsx(c.RiIcon,{icon:"RiAddLine"})})]})})}),i.jsx(re.Droppable,{droppableId:E,children:P=>i.jsxs("div",{className:"flex flex-col",...P.droppableProps,ref:P.innerRef,children:[y.map((W,le)=>i.jsx(re.Draggable,{draggableId:`${W}-draggable`,index:le,isDragDisabled:I,children:({draggableProps:te,dragHandleProps:ce,innerRef:Oe})=>i.jsxs(c.Badge,{...ce,...te,ref:Oe,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[i.jsx("span",{children:typeof W=="object"&&"label"in W?W.label:W}),i.jsx(c.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:I,onClick:()=>{ee(le)},children:i.jsx(c.RiIcon,{icon:"RiCloseLargeLine"})})]})},W)),P.placeholder]})})]})})});Qt.displayName="MultiStringInput";const br={...H,type:"multi-string",minimum_length:0,maximum_length:null},Te=class Te extends k{constructor(e){const{minimum_length:r,maximum_length:o,placeholder:a,...s}=e;super({...s,type:"multi-string"});T(this,"minLength");T(this,"maxLength");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.minLength=r??0,this.maxLength=o??1/0,this.placeholder=a??"Press enter to add a new option"}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return i.jsx(Qt,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(r=>{if(Array.isArray(r)&&r.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(r=>{if(Array.isArray(r)&&r.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new Te(e)}};T(Te,"fieldTypeName","Multi-string"),T(Te,"fieldTypeDescription","Allows the user to provide multiple unique strings."),T(Te,"Icon",$.RiListCheck);let ze=Te;const Yt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=G(t),{name:C,onBlur:w,onChange:p,value:y}=u,E=a?null:l,I=a?"":m,[b,S]=d.useState("");d.useLayoutEffect(()=>{S(y)},[y]);const N=d.useCallback(F=>{const L=Number.parseFloat(F.target.value),A=Number.isNaN(L)?"":L;S(A),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(A))},[s,h,f]),D=d.useCallback(()=>{p(b),w(b)},[b,w,p]);return i.jsx(J,{helpText:E,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:i.jsx(c.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:i.jsx(c.Input.Field,{id:n,name:C,onChange:N,onBlur:D,value:b,type:"number",min:s.minimum,max:s.maximum,step:s.integers?1:.1,placeholder:s.placeholder,...g})})})})});Yt.displayName="NumberInput";const Cr={...H,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},wr=t=>"fields"in t,R=class R extends k{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:o=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:s="Enter a number",...l}=e;super({...l,type:"number"});T(this,"minimum");T(this,"maximum");T(this,"integers");T(this,"placeholder");this.minimum=r,this.maximum=o,this.integers=a,this.placeholder=s}getValueFromChangeEvent(e){const r=Number.parseFloat(e.target.value);return Number.isNaN(r)?"":r}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new R({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new R({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new xe({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,o=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof o=="number"&&e.push(a=>{if(typeof a=="number"&&a>o)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(a=>{if(typeof a=="number"&&!Number.isInteger(a))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new R(e)}getInput(e){return i.jsx(Yt,{field:this,...e})}};T(R,"fieldTypeName","Number"),T(R,"fieldTypeDescription","Allows specifying a number within a given range."),T(R,"Icon",$.RiHashtag),T(R,"_validateMin",e=>(r,o)=>{const a=wr(o)?K(o,e):o;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),T(R,"_validateMax",e=>(r,o)=>{const a=wr(o)?K(o,e):o;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let se=R;const Jt=d.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:o,size:a,severity:s,showInputOnly:l,field:m,fieldProps:u},f]=G(t),{name:h,onBlur:g,onChange:C,value:w}=u,[p,y]=d.useState(!1),E=l?null:o,I=l?"":r,b=d.useCallback(D=>{C(D),y(!1)},[C]),S=d.useCallback(()=>{C("")},[C]),N=d.useCallback(D=>{y(D),D||g(w)},[g,w]);return i.jsx(J,{helpText:E,severity:s,children:i.jsxs(Y,{size:a,severity:s,inputId:n,labelId:e,label:I,image:l?void 0:m.image,className:"flex-col items-start justify-start gap-2",children:[i.jsxs("div",{className:"flex w-max items-center gap-1",children:[i.jsxs(zt,{open:p,onOpenChange:N,children:[i.jsx(No,{asChild:!0,children:i.jsxs(c.Button,{id:n,name:h,type:"button",variant:"soft",size:"sm",accentColor:"base",...f,children:[i.jsx(c.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),i.jsxs(_t,{children:[i.jsx(Vt,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),i.jsx($t,{className:"fixed inset-0",children:i.jsx(Zt,{onQrScan:b})})]})]}),w&&i.jsx(c.RiIcon,{icon:"RiCheckLine",className:"align-bottom text-(--primary-a11)"})]}),!!w&&i.jsx(c.Card,{className:"max-w-full w-max",size:"sm",children:i.jsxs("div",{className:"max-w-full w-max flex justify-between gap-2",children:[i.jsx("code",{className:"bg-(--base-a3) truncate text-sm",children:w}),i.jsx(c.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:S,children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})})]})})]})})});Jt.displayName="QrInput";const Zt=d.memo(t=>{const{onQrScan:n}=t,e=d.useRef(null),[r,o]=d.useState(!1);return d.useEffect(()=>{if(!e.current)return;const a=new Hr(e.current,s=>{const l=s.data;n(l),a.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});o(!0),a.start().finally(()=>{o(!1)})},[n]),i.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[i.jsx("div",{className:"absolute top-0 flex w-full p-2",children:i.jsx(dr,{asChild:!0,children:i.jsx(c.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})})})}),i.jsxs("div",{className:"relative max-h-full max-w-full",children:[i.jsx("video",{className:"size-full",ref:e}),r&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:i.jsx(c.Spinner,{})})]})]})});Zt.displayName="QrScanner";const Ir={...H,type:"qr"},Ne=class Ne extends k{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 Ne(e)}getInput(e){return i.jsx(Jt,{...e,field:this})}};T(Ne,"fieldTypeName","QR"),T(Ne,"fieldTypeDescription","Used for scanning/reading QR codes."),T(Ne,"Icon",$.RiQrCodeLine);let at=Ne;class xr extends k{constructor(e){const{placeholder:r="",...o}=e;super(o);T(this,"options");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(s=>(typeof s=="string"&&(s={label:s,value:s}),a.add(s.label),s)),a.size!==e.options.length&&console.error(`${e.options.length-a.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options,placeholder:this.placeholder}}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ze({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const Bo=t=>t?Array.isArray(t)?t:[t]:[],Rt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onChange:g,onBlur:C}=u,w=a?null:l,p=a?"":m,y=d.useMemo(()=>Bo(u.value),[u.value]),E=d.useCallback(b=>{g(b),C(b)},[C,g]),I=d.useCallback(b=>{b||C(y)},[y,C]);return i.jsx(J,{helpText:w,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:p,image:a?void 0:s.image,children:i.jsxs(c.Menu.Root,{onOpenChange:I,align:"start",children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsxs(c.Button,{id:n,name:h,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...f,children:[i.jsx("span",{className:"truncate",children:y.length>0?y.join(", "):s.placeholder}),i.jsx(c.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),i.jsx(c.Menu.Content,{children:i.jsx(c.Menu.Scroll,{children:i.jsxs(c.Menu.MultiSelectGroup,{values:y,onValuesChange:E,children:[i.jsxs(c.Menu.SelectAllItem,{children:[i.jsx(c.Menu.CheckboxItemIndicator,{children:b=>b?i.jsx(c.RiIcon,{icon:"RiSubtractLine"}):i.jsx(c.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),s.options.map(b=>i.jsxs(c.Menu.MultiSelectItem,{value:b.value,children:[i.jsx(c.Menu.SelectedIndicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})}),b.label]},b.value))]})})})]})})})});Rt.displayName="MultiSelectInput";const Er={...H,type:"multi-select",options:[]},Fe=class Fe extends xr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}getValueFromChangeEvent(n){if(Array.isArray(n))return n;throw new Error("Expected an array.")}isBlank(n){return super.isBlank(n)||n.length===0}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Fe(n)}getInput(n){return i.jsx(Rt,{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",$.RiCheckboxLine);let _e=Fe;const en=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onChange:g,onBlur:C,value:w}=u,p=a?null:l,y=a?"":m,E=d.useCallback(b=>{b&&(g(b),C(b))},[C,g]),I=d.useMemo(()=>s.options.find(b=>b.value===w),[s.options,w]);return i.jsx(J,{helpText:p,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:y,image:a?void 0:s.image,children:i.jsxs(c.Menu.Root,{align:"start",children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsxs(c.Button,{id:n,name:h,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...f,children:[i.jsx("span",{className:"truncate",children:I?I.label:s.placeholder}),i.jsx(c.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),i.jsx(c.Menu.Content,{children:i.jsx(c.Menu.Scroll,{children:i.jsx(c.Menu.SelectGroup,{required:!0,value:w,onValueChange:E,children:s.options.map(b=>i.jsxs(c.Menu.SelectItem,{value:b.value,children:[i.jsx(c.Menu.SelectedIndicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})}),b.label]},b.value))})})})]})})})});en.displayName="SelectInput";const Sr={...H,type:"select",options:[]},Le=class Le extends xr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}getValueFromChangeEvent(n){return typeof n=="string"?n:n.target.value}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new Le(n)}getInput(n){return i.jsx(en,{field:this,...n})}};T(Le,"fieldTypeName","Dropdown"),T(Le,"fieldTypeDescription","Allows the user to select a single option from a list of options."),T(Le,"Icon",$.RiMenuFoldLine);let Ve=Le;const Tr=t=>"fields"in t;class st extends k{constructor(e){const{minLength:r,maxLength:o,placeholder:a="",...s}=e;super(s);T(this,"minLength");T(this,"maxLength");T(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=o?Math.max(o,0):ye,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:`${r}minimum_length`,minimum:0,maximum:100,formValidators:[this._validateMin(e)],integers:!0}),showDirectly:!1},{field:new se({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:ye,formValidators:[this._validateMax(e)],integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(r=>{if(this.minLength&&(!r||r.length<this.minLength))return!this.required&&!r?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(r=>{if(typeof r=="string"&&this.maxLength&&r.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}}T(st,"_validateMin",e=>(r,o)=>{const a=Tr(o)?K(o,e):o;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),T(st,"_validateMax",e=>(r,o)=>{if(typeof r!="number")return null;const{minimum_length:a}=Tr(o)?K(o,e):o;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const tn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=G(t),{name:C,onBlur:w,onChange:p,value:y}=u,E=a?null:l,I=a?"":m,[b,S]=d.useState("");d.useLayoutEffect(()=>{S(y)},[y]);const N=d.useCallback(F=>{S(F.target.value),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),D=d.useCallback(()=>{p(b),w(b)},[b,w,p]);return i.jsx(J,{helpText:E,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:i.jsx(c.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:i.jsx(c.Input.Field,{id:n,name:C,value:b,type:s.inputType,placeholder:s.placeholder,onChange:N,onBlur:D,...g})})})})});tn.displayName="StringInput";const Nr={...H,type:"string",maximum_length:ke,input_type:"text"},De=class De extends st{constructor(e){const{inputType:r="text",...o}=e,a=e.maxLength?Math.min(ke,e.maxLength):ke,s=e.minLength?Math.min(e.minLength,a):void 0;super({...o,maxLength:a,minLength:s,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:o,input_type:a,...s}=e;return new De({...s,maxLength:r,minLength:o,inputType:a,placeholder:"Enter a short description"})}getInput(e){return i.jsx(tn,{field:this,...e})}};T(De,"fieldTypeName","Short Text"),T(De,"fieldTypeDescription",`Short text fields can hold up to ${ke} characters on a single line.`),T(De,"Icon",$.RiInputField);let lt=De;const nn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=G(t),{name:C,onBlur:w,onChange:p,value:y}=u,E=a?null:l,I=a?"":m,[b,S]=d.useState("");d.useLayoutEffect(()=>{S(y)},[y]);const N=d.useCallback(F=>{S(F.target.value),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),D=d.useCallback(()=>{p(b),w(b)},[b,w,p]);return i.jsx(J,{helpText:E,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:i.jsx(c.TextArea,{id:n,value:b,name:C,onChange:N,onBlur:D,className:"field-sizing-content min-h-12",placeholder:s.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...g})})})});nn.displayName="TextInput";const Fr={...H,type:"text",maximum_length:ye},Me=class Me extends st{constructor(n){const e=n.maxLength?Math.min(ye,n.maxLength):ye,r=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:r,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:r,...o}=n;return new Me({...o,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return i.jsx(nn,{field:this,...n})}};T(Me,"fieldTypeName","Paragraph"),T(Me,"fieldTypeDescription",`Paragraph fields can hold up to ${ye} characters and can have multiple lines.`),T(Me,"Icon",$.RiAlignJustify);let ct=Me;const Lr=d.memo(d.forwardRef((t,n)=>{const{file:e,alt:r,error:o,rightSlot:a,className:s,...l}=t;return i.jsxs("div",{className:ve(s,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...l,children:[!e&&!o&&i.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:i.jsx(c.Spinner,{})}),i.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!o&&i.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),i.jsxs("div",{className:ve("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[o?i.jsx(c.RiIcon,{icon:"RiFileWarningLine"}):e&&i.jsx($e,{fileType:e.type}),i.jsx(c.Text,{className:"truncate",size:"sm",children:o??(e==null?void 0:e.name)}),a]})]})})),zo=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)},Dr=d.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:o,helpText:a,showInputOnly:s,field:l,fieldProps:m},u]=G(t),{name:f,value:h,onChange:g,onBlur:C}=m;let[{label:w}]=G(t);w=s?"":w;const p=d.useRef(null),y=d.useMemo(()=>s?null:a||(l.maxFileSize?`Maximum file size: ${l.maxFileSize}MB`:null),[l.maxFileSize,a,s]),E=d.useCallback(()=>{var L;(L=p.current)==null||L.click()},[]),I=d.useCallback(()=>{if(!p.current)return;const L=p.current.files;if(!L){C([]);return}const A=Array.from(L),O=[...h,...A];g(O),C(O)},[C,g,h]),b=d.useCallback(L=>{const A=[...h];A.splice(L,1),g(A)},[h,g]);d.useEffect(()=>{if(!p.current)return;const L=new AbortController;return p.current.addEventListener("cancel",()=>{C([])},{signal:L.signal}),()=>{L.abort()}},[C,h]);const S=h?"Select new files":"Select files",N=h?"Select new file":"Select a file",D=l.maxFiles>1?S:N;return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(J,{helpText:y,severity:o,children:i.jsxs(Y,{size:r,severity:o,inputId:n,labelId:e,label:w,image:s?void 0:l.image,children:[i.jsx("div",{className:"flex gap-2",children:i.jsxs(c.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:E,id:"upload-input-upload-button",type:"button",...u,children:[i.jsx(c.RiIcon,{icon:"RiUpload2Line"})," ",D]})}),i.jsx("input",{id:n,name:f,type:"file",ref:p,accept:(F=l.extensions)==null?void 0:F.join(","),multiple:l.maxFiles>1,className:"hidden",onChange:I,value:""})]})}),Array.isArray(h)&&h.length>0&&i.jsx("div",{className:"flex h-max flex-col gap-2",children:h.map((L,A)=>i.jsx(Mr,{field:l,file:L,onRemove:()=>{b(A)},disabled:u.disabled},A))})]})});Dr.displayName="UploadInput";const Mr=d.memo(t=>{const{file:n,field:e,onRemove:r,disabled:o}=t,[a,s]=d.useState(null),l=Ue(),m=d.useMemo(()=>a&&e.getError([a]),[e,a]),{url:u,name:f}=d.useMemo(()=>{let p=null,y,E;return a!=null&&a.type.startsWith("image/")&&(p=URL.createObjectURL(a)),a?(y=a.name,E=zo(a.size)):(y="Downloading...",E="..."),{url:p,name:y,size:E}},[a]);d.useEffect(()=>{n instanceof Promise?n.then(s).catch(console.error):s(n)},[n]);const h=d.useCallback(p=>{if(p.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const y=new Blob([a]);kt.saveAs(y,f)},[f,a]),g=d.useCallback(p=>{p.stopPropagation(),r()},[r]),C=d.useCallback(()=>{a&&l(p=>({file:a,onDelete:o?void 0:()=>{r(),p()}}))},[o,r,l,a]),w=d.useMemo(()=>i.jsxs(c.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(c.IconButton,{"aria-label":`Download ${f}`,type:"button",onClick:h,disabled:!a,children:i.jsx(c.RiIcon,{icon:"RiDownload2Line"})}),!o&&i.jsx(c.IconButton,{type:"button","aria-label":`Remove ${f}`,disabled:o,onClick:g,children:i.jsx(c.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[o,g,h,f,a]);return u?i.jsx(Lr,{className:"cursor-pointer",onClick:C,file:a,error:m??void 0,rightSlot:w}):i.jsx(yt,{file:a,error:m??void 0,rightSlot:w})});Mr.displayName="DisplayFile";const _o={...H,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1},Ae=class Ae extends k{constructor(e){const{extensions:r,maximum_files:o,maximum_size:a,...s}=e;super({...s,type:"upload"});T(this,"extensions");T(this,"maxFileSize");T(this,"maxFiles");T(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof a=="number"?a:void 0,this.maxFiles=Math.max(typeof o=="number"?o:1,1),this.extensions=r}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:`${r}maximum_files`,integers:!0}),showDirectly:!1},{field:new se({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${dt}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:dt,integers:!0}),showDirectly:!1},{field:new _e({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??dt,o=r*1e3*1e3,a=this.maxFiles||1;return e.push(s=>{if(s&&s.some(l=>l.size>o))return`Files must be at most ${r}MB.`}),e.push(s=>{if(s&&s.length>a)return`You can only upload ${a} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new Ae(e)}getInput(e){return i.jsx(Dr,{field:this,...e})}};T(Ae,"fieldTypeName","Upload"),T(Ae,"fieldTypeDescription","Allows a file to be uploaded."),T(Ae,"Icon",$.RiUpload2Line);let rn=Ae;const on={date:tt,number:se,boolean:xe,select:Ve,string:lt,text:ct,custom:nt,upload:rn,qr:at,"multi-string":ze,"multi-select":_e},Vo={date:pr,number:Cr,boolean:hr,select:Sr,string:Nr,text:Fr,custom:Mo,upload:_o,qr:Ir,"multi-string":br,"multi-select":Er},dt=50,$o=dt*1e3*1e3,an=t=>{const n=t.type;return on[n].deserialize(t)},ut=t=>t.type==="section"?U.deserialize(t):an(t);function Ar(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>ut(r)),meta:{readonly:e}}}function sn(t){const n=[];for(const e of t.fields)if(e instanceof U)for(const r of e.fields)n.push(r);else{if(!(e instanceof k))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function ko(t,n){const e=sn(t),r={};for(const o of e){const a=n[o.identifier]??null;a!==null?r[o.identifier]=o.decodeJsonToValue(a):r[o.identifier]=a}return r}function Uo(t,n){const e=sn(t),r={};for(const o of e){const a=n[o.identifier];r[o.identifier]=o.encodeValueToJson(a)}return r}function ft(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function ln(t,n){if(!t)return!0;if(ft(n)||ft(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(o=>typeof o=="string"?o:o.value):n,r=Array.isArray(t.value)?t.value.map(o=>typeof o=="string"?o:o.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const o of r)if(!e.includes(o))return!1;return!0}return r===n}const Pr=d.memo(t=>{const{field:n,...e}=t,{label:r,description:o,fields:a,condition:s}=n,{values:l,setFieldValue:m}=V.useFormikContext(),u=s!=null&&s.identifier?K(l,s.identifier):void 0,f=d.useMemo(()=>u===void 0||ln(s,u),[s,u]);d.useEffect(()=>{if(!f)for(const g of a)m(g.getId(),"").then()},[f,a,m]);const h=Be(a,e);return f?i.jsx(c.Card,{variant:"soft",children:i.jsxs("div",{className:"flex flex-col gap-4",children:[(r||o)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex flex-col",children:[i.jsx(c.Heading,{size:"md",children:r}),i.jsx(c.Text,{accentColor:"base",children:o})]}),i.jsx(c.Separator,{size:"full"})]}),h]})}):null});Pr.displayName="FieldSectionLayout";const Pe=class Pe extends bt{constructor(e){const{label:r=null,fields:o,condition:a=null,conditional:s,...l}=e;super({...l,type:"section"});T(this,"label");T(this,"fields");T(this,"condition");this.fields=o,this.condition=a,this.label=r,s===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const o=r&&`${r}.`;return[{field:new xe({label:"Conditionally render section",identifier:`${o}conditional`,required:!1}),showDirectly:!0},{field:new Pe({label:"Conditional settings",identifier:`${o}conditional-settings`,condition:{identifier:`${o}conditional`,value:!0},fields:[new Ve({label:"Field",description:"The field to use for the condition.",options:e.map(a=>!a.label||a.type==="upload"?null:{label:a.label,value:a.identifier}).filter(a=>!!a),identifier:`${o}condition.identifier`,required:!0}),new Ao({label:"Value",identifier:`${o}condition.value`,required:!0,clonedFieldIdentifier:`${o}condition.identifier`,getFieldToClone(a){if(!a)return null;const s=e.find(l=>l.identifier===a);return s?{...s,label:"Value",identifier:`${o}condition.value`,description:"The value to compare against.",required:s.type!=="boolean"}:(console.error("Could not find field with identifier",a),null)}})]}),showDirectly:!1}]}static deserialize(e){if(e.type!=="section")throw new Error("Invalid type");if(!Array.isArray(e.fields))throw new Error(`Invalid fields: ${e.fields} (not an array)`);const r=e.fields.map(an);return new Pe({...e,fields:r})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const r={};for(const o of this.fields){const a=o.getId(),s=o.getError(K(e,a),e);s&>(r,o.getId(),s)}return r}getInput(e){return i.jsx(Pr,{field:this,...e})}};T(Pe,"fieldTypeName","Section"),T(Pe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let U=Pe;const me=t=>Object.keys(t).length>0,ht=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof U){if(r.condition){const{identifier:o}=r.condition;if(!ln(r.condition,K(n,o)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof k))throw new Error("Invalid field type");const o=r.getId(),a=r.getError(K(n,o),n);a&>(e,o,a)}if(me(e))return e},jo=[null,void 0],pt=(t,n)=>t.reduce((e,r)=>r instanceof U?{...e,...pt(r.fields,n)}:(jo.includes(K(e,r.getId()))&>(e,r.getId(),""),e),Gr(n)),Wo=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Or=d.memo(d.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:o,onSubmit:a=Wo,submitText:s="Submit",cancelText:l,onCancel:m,onDirty:u,onDirtyChange:f,hideTitle:h=!e.title,hideDescription:g,className:C,buttonProps:w}=t,{readonly:p}=e.meta,y=d.useMemo(()=>crypto.randomUUID(),[]),E=V.useFormik({initialValues:pt(e.fields,r),onSubmit:a,validate:F=>ht(e,F),validateOnBlur:!1,validateOnChange:!1}),{dirty:I}=E,b=d.useMemo(()=>typeof e.title=="string"?i.jsx(c.Heading,{size:"md",children:e.title}):e.title,[e.title]),S=d.useMemo(()=>typeof e.description=="string"?i.jsx(c.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),N=d.useCallback((F,L)=>{o==null||o({[F]:L})},[o]),D=Be(e.fields,{formId:y,disabled:p,onValuesChange:N});return d.useEffect(()=>{I&&u&&u(),f&&f(I)},[I,u,f]),i.jsx(V.FormikProvider,{value:E,children:i.jsxs("form",{id:y,ref:n,className:ve(C,"flex flex-col gap-2"),onSubmit:E.handleSubmit,children:[!h&&i.jsx(c.Card,{variant:"soft",children:i.jsxs("div",{className:"flex flex-col gap-1",children:[b,!g&&S]})}),D,!p&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&i.jsxs(c.Button,{accentColor:de.danger,...w,type:"button",onClick:m,children:[i.jsx(c.RiIcon,{icon:"RiCloseLine"}),l]}),i.jsxs(c.Button,{...w,type:"submit",disabled:!E.isValid,accentColor:"success",children:[i.jsx(c.RiIcon,{icon:"RiCheckLine"}),s]})]})]})})})),ge=d.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=V.useFormikContext(),[o,a,s]=V.useField(n),l=d.useMemo(()=>{const m=u=>{s.setValue(u,!1)};return e({value:o.value,meta:a,setValue:m,patchValue:()=>{r()}})},[e,o.value,a,r,s]);return i.jsx(i.Fragment,{children:l})});ge.displayName="PatchField";const qo=d.memo(d.forwardRef((t,n)=>{const{children:e,schema:r,values:o,onPatch:a,onError:s,requiresDiff:l=!0,onDirtyChange:m,...u}=t,f=d.useMemo(()=>pt(r.fields,o),[r.fields,o]),h=d.useCallback(I=>{const b={};for(const S in I){const N=I[S];N!==f[S]&&N!==void 0&&(b[S]=N)}return b},[f]),g=d.useCallback(I=>{const b=h(I);l&&!me(b)||a(b)},[h,a,l]),C=d.useCallback(I=>{const b=ht(r,I);if(b&&s(b),m){const S=h(I);m(me(S))}return b},[r,m,s,h]),w=V.useFormik({initialValues:f,onSubmit:g,validate:C,validateOnBlur:!1,validateOnChange:!1}),p=d.useCallback(()=>{if(m){const I=h(w.values);me(I)&&m(!0)}},[w.values,h,m]),{errors:y,resetForm:E}=w;return d.useEffect(()=>{me(y)&&E({values:f,errors:{}})},[y,f,E]),i.jsx(V.FormikProvider,{value:w,children:i.jsx("form",{...u,ref:n,onSubmit:w.handleSubmit,onChange:p,children:e})})})),mt="form-builder",Ho=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],cn={...on,section:U},Go=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const o in e)e[o].disabled=!1;return e;case"hold":for(const o in e)(r=e[o])!=null&&r.conditionFields.has(n.fieldId)&&(e[o].disabled=!0);return e;case"update":return n.state}},Xo=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const o of r.fields)if(o.identifier===n)return e}}},Br=t=>{var e,r,o;const n={};for(let a=0;a<t.length;a++){const s=t[a];if(!s)throw new Error("Field is undefined.");const l=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,m=new Set(l);(r=s.condition)!=null&&r.identifier&&m.add(s.condition.identifier),n[s.identifier]={disabled:!1,conditionFields:m,conditionIndex:Xo(t,(o=s.condition)==null?void 0:o.identifier),index:a,label:s.label}}return n},dn=d.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:o,duplicate:a,move:s,upload:l}=t;if(e!=="section"&&!l)throw new Error("Upload function prop must be defined for non-section fields.");const{values:m}=V.useFormikContext(),u=d.useRef(null),f=d.useMemo(()=>{const h=[{Icon:$.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:$.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:o}}),e!=="section"&&h.unshift({Icon:$.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=u.current)==null||g.click()}}}),(r===void 0&&n!==m.fields.length-1||r!==void 0&&(r<m.fields.length-1||n!==m.fields[r].fields.length-1))&&h.unshift({Icon:$.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{s("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:$.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{s("up")}}}),h},[a,n,s,o,r,e,m.fields]);return i.jsxs(i.Fragment,{children:[i.jsx(c.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:f.map(h=>i.jsx(c.IconButton,{type:"button","aria-label":h.text,...h.buttonProps,children:i.jsx(h.Icon,{})},h.key))}),i.jsx("div",{className:"sm:hidden",children:i.jsxs(c.Menu.Root,{children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsx(c.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:i.jsx(c.RiIcon,{icon:"RiMore2Line"})})}),i.jsx(c.Menu.Content,{children:f.map(h=>{var g;return i.jsxs(c.Menu.Item,{onClick:(g=h.buttonProps)==null?void 0:g.onClick,children:[i.jsx(h.Icon,{}),h.text]},h.key)})})]})}),e!=="section"&&i.jsx("input",{style:{display:"none"},ref:u,type:"file",accept:"image/*",onChange:l})]})});dn.displayName="FieldActions";const un=d.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return i.jsxs(c.Popover.Root,{children:[i.jsx(c.Popover.Trigger,{asChild:!0,children:i.jsxs(c.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:de.danger},children:[i.jsx(c.RiIcon,{icon:"RiSettings2Line"}),i.jsx("span",{children:"Settings"})]},"settings")}),i.jsx(c.Popover.Content,{size:"sm",...r,children:i.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});un.displayName="FieldSettingsPopover";const zr=(t=()=>null)=>d.useMemo(()=>Ho.map(n=>n.map(e=>{const r=on[e],o=r.Icon;return{children:r.fieldTypeName,icon:i.jsx(o,{}),value:e,onSelect:()=>{t(e)}}})),[t]),fn=d.memo(t=>{var Oe,hn,jr,Wr,qr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:o}=t,{values:a,setFieldValue:s,errors:l}=V.useFormikContext(),m=zr(),u=Ue(),f=d.useRef(null),h=576,[g,C]=d.useState(f.current&&f.current.getBoundingClientRect().width>=h);d.useEffect(()=>{const M=f.current;if(M){const B=new ResizeObserver(j=>{j[0]&&C(j[0].contentRect.width>=h)});return B.observe(M),()=>{B.disconnect()}}},[]);const[w,p]=d.useState(void 0);d.useEffect(()=>{pe(r)?p(void 0):r.image instanceof Promise?r.image.then(p).catch(console.error):p(r.image)},[r]);const y=w?URL.createObjectURL(w):void 0,E=d.useCallback(M=>{M.stopPropagation();const{image:B,...j}=r;s(`${n}.${e}`,j).then()},[e,r,n,s]);d.useEffect(()=>{pe(r)&&!r.conditional&&s(`${n}.${e}.condition`,null).then()},[e,r,n,s]);const I=d.useMemo(()=>{var M,B;return pe(r)?(B=vr(a.fields,(M=r.condition)==null?void 0:M.identifier))==null?void 0:B.label:void 0},[r,a.fields]),b=pe(r)?Array.isArray((Oe=r.condition)==null?void 0:Oe.value)?"contains all of":"equals":void 0;let S;if(pe(r)){if(ft((hn=r.condition)==null?void 0:hn.value))throw new Error("File values are not supported for conditions.");S=Array.isArray((jr=r.condition)==null?void 0:jr.value)?r.condition.value.map(M=>typeof M=="string"?M:M.label).join(", "):(qr=(Wr=r.condition)==null?void 0:Wr.value)==null?void 0:qr.toString()}const N=d.useCallback(M=>{M.target.parentNode instanceof HTMLElement&&(M.target.parentNode.dataset.replicatedValue=M.target.value)},[]),D=d.useCallback(M=>{M.target.parentNode instanceof HTMLElement&&(M.target.parentNode.dataset.replicatedValue=M.target.value)},[]),F=r.type,L=cn[F],[A,O]=d.useMemo(()=>{let M=[],B=[];if(L===U){if(o===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const j=L.getFieldCreationSchema(o,`${n}.${e}`);M=M.concat(j.filter(_=>_.showDirectly).map(_=>_.field)),B=B.concat(j.filter(_=>!_.showDirectly).map(_=>_.field))}else{if(!(L.prototype instanceof k))throw new Error(`Field must be an instance of BaseField. Got ${L.toString()}.`);const j=L.getFieldCreationSchema(`${n}.${e}`);g?(M=[...M,...j.filter(_=>_.showDirectly).map(_=>_.field)],B=[...B,...j.filter(_=>!_.showDirectly).map(_=>_.field)]):B=[...B,...j.map(_=>_.field)]}return[M,B]},[L,o,n,e,g]),q=Be(A,{formId:mt,disabled:!1,...L===U&&{size:"sm"}}),ee=Be(O,{formId:mt,disabled:!1});let z=O.length>0;pe(r)&&O.length>0&&(z=r.conditional);const X=O.some(M=>{const B=K(l,L===U?`${n}.${e}.condition`:M.getId());return B&&(typeof B!="object"||me(B))}),P=X?de.danger:void 0,W=d.useMemo(()=>ut(r),[r]),le=Ht(W,{formId:mt,showInputOnly:!1}),te=d.useMemo(()=>m.flat().find(M=>M.value===F),[m,F]),ce=d.useCallback(()=>{w&&u(()=>({file:w}))},[u,w]);return i.jsx("div",{className:"flex grow items-center w-full",ref:f,children:i.jsxs("div",{className:"flex w-full flex-col gap-2",children:[L===U&&(A.length>0||z)&&i.jsxs("div",{className:"flex flex-col gap-2",children:[q,z&&i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(un,{popoverInputs:ee,hasError:X,align:"start"}),pe(r)&&r.conditional&&i.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":P,children:i.jsxs("em",{children:["Display only if ",i.jsx("strong",{children:I})," ",b," ",i.jsx("strong",{children:S})]})})]})]}),L!==U&&i.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs(c.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[te==null?void 0:te.icon,te==null?void 0:te.children]}),i.jsx(ge,{name:`${n}.${e}.required`,render:({setValue:M,value:B})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c.Checkbox.Root,{checked:B,onCheckedChange:M,size:"sm",children:i.jsx(c.Checkbox.Indicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})})}),i.jsx(c.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),z&&i.jsx(un,{popoverInputs:ee,hasError:X,align:"end"})]}),w&&i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:y,alt:w.name,onClick:ce}),i.jsx(c.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:i.jsx(c.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),i.jsx(ge,{name:`${n}.${e}.label`,render:({setValue:M,value:B})=>i.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:F==="section"?"Enter a section label (optional)":"Enter your question",value:B,onChange:j=>{M(j.target.value)},onInput:N,maxLength:200})}),i.jsx(ge,{name:`${n}.${e}.description`,render:({setValue:M,value:B})=>i.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${F==="section"?"section":"field"} description (optional)`,value:B,onChange:j=>{M(j.target.value)},onInput:D,maxLength:1e3})}),L!==U&&A.length>0&&i.jsx("div",{className:"w-full",children:q}),L!==U&&i.jsxs(c.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[i.jsxs(c.HoverCard.Root,{children:[i.jsx(c.HoverCard.Trigger,{asChild:!0,children:i.jsx(c.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:i.jsx(c.RiIcon,{icon:"RiEyeLine"})})}),i.jsx(c.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."})]}),i.jsx("div",{className:"grow h-max",children:le})]})]})})});fn.displayName="FieldBuilder";const _r=d.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:o}=t,{setFieldValue:a,values:s}=V.useFormikContext(),{reorderField:l}=Kt(),{showInfo:m,showError:u}=c.useToast(),f=`fields.${r}.fields`,h=d.useMemo(()=>({index:e,parentPath:f,initial:n}),[n,e,f]),g=d.useCallback(()=>{const p=n.label||"Unlabelled field",y={...n,label:p};ot(f,e+1,y,s,a),m({title:"Field duplicated",description:`The field "${p}" has been duplicated`})},[n,f,e,s,a,m]),C=d.useCallback(p=>{const y=r,E=s.fields[y];let I=r,b=p==="up"?e-1:e+1;p==="up"&&e===0?(I=r-1,b=s.fields[I].fields.length):p==="down"&&e===E.fields.length-1&&(I=r+1,b=0);const S=s.fields[I];l(E,y,e,S,I,b,a)},[r,s.fields,e,l,a]),w=d.useCallback(p=>{const{files:y}=p.target;if(!y||y.length!==1)return;const E=y.item(0);if(E){if(E.size>$o){u({title:"File upload error",description:`The file ${E.name} exceeded the maximum file size`});return}a(`${f}.${e}`,{...n,image:E}).then()}},[n,e,f,a,u]);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:p=>i.jsx(c.Card,{ref:p.innerRef,...p.draggableProps,...p.dragHandleProps,className:"mb-4",children:i.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[i.jsx(fn,{...h}),i.jsx(dn,{index:e,type:n.type,sectionIndex:r,remove:o,duplicate:g,move:C,upload:w})]})})})});_r.displayName="FieldWithActions";const Vr=d.memo(t=>{var S;const{field:n,index:e,dropState:r,fieldsOnly:o}=t,a=(S=r[n.identifier])==null?void 0:S.disabled,{setFieldValue:s,values:l}=V.useFormikContext(),m=c.useAlertDialog(),{reorderSection:u}=Kt(),{showInfo:f}=c.useToast(),h=d.useCallback((N,D)=>{for(const F of N){const L=D.indexOf(F);s(`fields.${L}.condition`,null).then(),s(`fields.${L}.conditional`,!1).then()}},[s]),g=d.useCallback(N=>{var L;const D=n.fields[N];if(!D)throw new Error("Could not find field to remove.");const F=[];for(const A of l.fields)((L=A.condition)==null?void 0:L.identifier)===D.identifier&&F.push(A);return{removing:D,affectedSections:F,action:()=>s(`fields.${e}.fields`,it(n.fields,N))}},[n.fields,l.fields,s,e]),C=d.useCallback(N=>{const{affectedSections:D,action:F,removing:L}=g(N),A=()=>{F().then(),h(D,l.fields)};if(D.length>0){const O=D.map(q=>q.label).join(", ");m({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${O} section(s).`,action:"Remove",onAction:A});return}A()},[g,h,l.fields,m]),w=d.useCallback(()=>{const D=n.fields.map((z,X)=>g(X)).flatMap(z=>z.affectedSections),F=D.length?"Remove fields and conditions?":"Remove fields?",L=n.fields.length,A=D.map(z=>z.label).join(", "),O=D.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${A}`:`Deleting this section will remove the ${L} field(s) it contains.`,q=it(l.fields,e),ee=()=>s("fields",q);if(D.length>0){m({title:F,description:O,action:"Remove",onAction:()=>{ee().then(()=>{h(D,q)})}});return}ee().then()},[n.fields,l.fields,e,g,s,m,h]),p=d.useCallback(N=>{const D=N==="up"?e-1:e+1;u(r,n.identifier,e,D,l,s)},[e,u,r,n.identifier,l,s]),y=d.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:yr(l.fields,e)}),[n,e,l.fields]),E=d.useCallback(()=>{const N=n.label||"Untitled section",D=n.fields.map(L=>({...L,identifier:Xt(null,L.label)})),F={...n,label:N,fields:D};ot("fields",e+1,F,l,s),f({title:"Section duplicated",description:`The section "${N}" has been duplicated.`})},[n,e,l,s,f]),I=d.useCallback(N=>{ot(`fields.${e}.fields`,n.fields.length,Vo[N],l,s)},[e,n.fields.length,l,s]),b=zr(I);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:N=>i.jsx(c.Card,{ref:N.innerRef,...N.draggableProps,...N.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:i.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[i.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!o&&i.jsx(fn,{...y}),i.jsx(re.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:a,children:D=>i.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:D.innerRef,...D.droppableProps,children:[n.fields.map((F,L)=>i.jsx(_r,{field:F,index:L,sectionIndex:e,remove:()=>{C(L)}},F.identifier)),D.placeholder,i.jsxs(c.Menu.Root,{children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsxs(c.Button,{type:"button",variant:"soft",size:"sm",children:[i.jsx(c.RiIcon,{icon:"RiAddLine"})," Add field"]})}),i.jsx(c.Menu.Content,{children:b.flat().map(F=>i.jsxs(c.Menu.Item,{onSelect:F.onSelect,children:[F.icon,F.children]},F.value))})]})]})})]}),!o&&i.jsx(dn,{index:e,type:n.type,remove:w,duplicate:E,move:p})]})})})});Vr.displayName="FieldSectionWithActions";const $r=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},kr=d.memo(t=>{const{fieldsOnly:n}=t,{values:e,setFieldValue:r}=V.useFormikContext(),[o,a]=d.useReducer(Go,e.fields,Br),{reorderSection:s,reorderField:l}=Kt();d.useEffect(()=>{a({type:"update",state:Br(e.fields)})},[a,e.fields]);const m=d.useCallback(h=>{h.type==="SECTION"&&a({type:"hold",fieldId:h.draggableId})},[]),u=d.useCallback(h=>{const{source:g,destination:C,type:w,reason:p,draggableId:y}=h;if(a({type:"release"}),!C||p==="CANCEL")return;if(w==="ROOT"){s(o,y,g.index,C.index,e,r);return}if(w!=="SECTION")throw new Error("Unexpected droppable type.");const[E,I]=$r(e.fields,g.droppableId)??[],[b,S]=$r(e.fields,C.droppableId)??[];l(E,I,g.index,b,S,C.index,r)},[e,l,r,s,o]),f=d.useCallback(h=>{Oo(h+1,e,r)},[e,r]);return i.jsx(re.DragDropContext,{onDragStart:m,onDragEnd:u,children:i.jsx(re.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>i.jsxs("div",{className:"flex flex-col gap-0",ref:h.innerRef,...h.droppableProps,children:[e.fields.map((g,C)=>i.jsxs(d.Fragment,{children:[i.jsx(Vr,{field:g,index:C,dropState:o,fieldsOnly:n}),!n&&C!==e.fields.length-1&&i.jsxs(c.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{f(C)},children:[i.jsx(c.RiIcon,{icon:"RiAddLine"})," Add section"]})]},g.identifier)),i.jsxs(c.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{f(e.fields.length)},children:[i.jsx(c.RiIcon,{icon:"RiAddLine"})," Add section"]}),h.placeholder]})})})});kr.displayName="FieldsEditor";const Ko=()=>{alert("This is a form preview, your data will not be saved.")},Qo=d.memo(d.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:o,initialTitle:a,showExplainerText:s=!0,showFormTitle:l=!0,fieldsOnly:m=!1,showTabs:u=!0,tabsListClassName:f,hydrateRevisionWithImages:h}=t,{showError:g}=c.useToast(),C=d.useCallback(I=>{const b={};I.title||(b.title="Title is required."),(!I.fields||I.fields.length===0)&&(b.fields="At least one field is required.");let S=[];for(const[D,F]of I.fields.entries()){const A=cn.section.getFieldCreationSchema(yr(I.fields,D),`fields.${D}`).map(O=>O.field);S=[...S,...A];for(const[O,q]of F.fields.entries()){const z=cn[q.type].getFieldCreationSchema(`fields.${D}.fields.${O}`).map(X=>X.field);S=[...S,...z]}}const N=ht({fields:S},I);if(N&&(b.fields=N.fields),me(b))return g({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),b},[g]),w=d.useMemo(()=>({title:a??"",description:"",fields:[{...rt(Xt(null,"")),label:""}]}),[a]),p=o?h(o):void 0,y=V.useFormik({initialValues:Po(p)??w,validate:C,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),E=d.useMemo(()=>Ar(y.values),[y.values]);return i.jsx(c.Tabs.Root,{ref:n,defaultValue:"edit",children:i.jsxs("div",{className:"flex flex-col gap-2",children:[u&&i.jsxs(c.Tabs.List,{className:ve("sticky top-0 z-[2000] flex bg-(--color-background)",f),children:[i.jsx(c.Tabs.Trigger,{className:"grow",value:"edit",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),i.jsx(c.Tabs.Trigger,{className:"grow",value:"preview",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),i.jsxs(c.Tabs.Content,{value:"edit",children:[s&&i.jsxs(c.Text,{children:["Create your form using various field types. Sections can be"," ",i.jsx("strong",{children:"conditionally rendered"})," based on"," ",i.jsx("strong",{children:"answers to fields in preceding sections. "})]}),i.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:mt,onSubmit:y.handleSubmit,children:[i.jsxs(V.FormikProvider,{value:y,children:[l&&i.jsxs(i.Fragment,{children:[i.jsx(ge,{name:"title",render:({setValue:I,value:b,meta:S})=>i.jsx(jt,{severity:"danger",helpText:S.error??null,children:i.jsx(c.Input.Root,{variant:"outline",size:"md",accentColor:S.error?de.danger:"primary",children:i.jsx(c.Input.Field,{placeholder:"Form title",value:b,onChange:N=>{I(N.target.value)},maxLength:100})})})}),i.jsx(ge,{name:"description",render:({setValue:I,value:b})=>i.jsx(c.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:b,onChange:S=>{I(S.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),i.jsx(kr,{fieldsOnly:m}),i.jsx("span",{"data-accent-color":de.danger,className:"text-xs text-(--accent-a11)",children:typeof y.errors.fields=="string"&&y.errors.fields})]}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&i.jsx(c.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),i.jsx(c.Button,{type:"submit",children:"Save form"})]})]})]}),i.jsx(c.Tabs.Content,{value:"preview",children:i.jsx(Or,{schema:E,onSubmit:Ko,hideTitle:!l})})]})})})),Yo=Object.values(ie.Colors),Jo=1;async function Zo(t,n,e,r){const o=t.getContext("2d",{}),a=new Image(r.width,r.height),s=new Image(r.width,r.height),l=new ie.DeferredPromise;return a.onload=function(){o.drawImage(a,0,0,r.width,r.height),s.src=URL.createObjectURL(e),s.onload=async function(){o.drawImage(s,0,0,r.width,r.height);const m=t.toDataURL("image/jpeg",Jo),u=await ie.fileToBlob(m),f=new File([u],n.name,{type:"image/jpeg"});l.resolve(f)}},a.src=URL.createObjectURL(n),l}const Ur=d.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:o,dirty:a,onDirty:s}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const l=d.useRef(null),m=d.useRef(null),[u,f]=d.useState(ie.Colors.red),[h,g]=d.useState(null),[C,w]=d.useState(!1),[p,y]=d.useState(!1),E=d.useRef(null),I=c.useSize(E);d.useEffect(()=>{const z=new Image;z.onload=function(){g({width:z.naturalWidth,height:z.naturalHeight})},z.src=URL.createObjectURL(n)},[n]),d.useEffect(()=>{!p&&(I!=null&&I.width)&&I.height&&y(!0)},[I,p]);const b=d.useCallback(async()=>{a||e();const z=l.current;if(!z)return;if(!h)throw new Error("Original image size not loaded yet");const X=await z.exportImage("png"),P=new Image(h.width,h.height);P.onload=async function(){const W=await ie.fileToBlob(X),le=new File([W],n.name,{type:n.type}),te=m.current,ce=await Zo(te,n,le,h);ce.objectURL=URL.createObjectURL(ce);const Oe=await ie.hashFile(n);await ie.hashFile(ce)!==Oe&&r(ce),w(!1),e()},w(!0),P.src=X},[a,n,e,r,h]),S=d.useCallback(()=>{o(n)},[n,o]),N=d.useCallback(()=>{e()},[e]),D=d.useCallback(()=>{s(!0)},[s]),F=d.useCallback(()=>{l.current&&l.current.redo()},[]),L=d.useCallback(()=>{l.current&&l.current.undo()},[]),A=d.useCallback(()=>{l.current&&(s(!1),l.current.clearCanvas())},[s]),O=d.useCallback(z=>{l.current&&l.current.eraseMode(z)},[]),q=d.useCallback(()=>{b()},[b]),ee=d.useCallback(()=>{kt.saveAs(n,n.name)},[n]);return i.jsx(zt,{open:!0,onOpenChange:e,children:i.jsxs(_t,{children:[i.jsx(Vt,{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":""}),i.jsxs($t,{className:"absolute inset-0 py-12","data-floating-content":"",children:[i.jsx(c.ButtonGroup,{className:"flex w-full gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",size:"md",variant:"soft",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx(c.IconButton,{"aria-label":"close",onClick:N,children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})}),i.jsx(c.IconButton,{"aria-label":`Download ${n.name}`,onClick:ee,children:i.jsx(c.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(vt,{selectedColor:u,allColors:Yo,onFinish:f,trigger:i.jsx(c.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:u},children:" "})}),i.jsx(c.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:O,children:i.jsx(c.RiIcon,{icon:"RiEraserFill"})}),i.jsx(c.Separator,{orientation:"vertical",size:"full"}),i.jsx(c.IconButton,{"aria-label":"undo",onClick:L,children:i.jsx(c.RiIcon,{icon:"RiArrowGoBackLine"})}),i.jsx(c.IconButton,{"aria-label":"undo",onClick:F,children:i.jsx(c.RiIcon,{icon:"RiArrowGoForwardLine"})}),i.jsx(c.IconButton,{"aria-label":"undo all",onClick:A,children:i.jsx(c.RiIcon,{icon:"RiLoopLeftLine"})})]}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(c.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:q,children:i.jsx(c.RiIcon,{icon:"RiSaveLine"})}),i.jsx(c.IconButton,{"aria-label":"Delete attachment",onClick:S,children:i.jsx(c.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})}),h&&i.jsx("canvas",{id:"attachment-markup-canvas",className:"hidden",ref:m,width:h.width,height:h.height}),i.jsxs("div",{className:"relative size-full flex items-center justify-center p-4 overflow-hidden",children:[i.jsx("img",{className:"max-w-full max-h-full invisible absolute",alt:"Photo attachment",ref:E,src:n.objectURL}),C?i.jsx(c.Spinner,{}):i.jsx(Xr.ReactSketchCanvas,{className:"max-w-full max-h-full aspect-square",backgroundImage:n.objectURL,ref:l,onStroke:D,strokeColor:u},p?"1":"0")]})]})]})})});Ur.displayName="AttachmentEditor",x.BaseField=k,x.BaseFormElement=bt,x.BooleanField=xe,x.BooleanInput=Wt,x.ColorPicker=vt,x.DateField=tt,x.DateInput=qt,x.FieldSection=U,x.FileCard=yt,x.FileIcon=$e,x.FormBuilder=Qo,x.FormRenderer=Or,x.ImageCard=Lr,x.ImageMarkup=Ur,x.ImageViewer=Ut,x.ImageViewerProvider=fr,x.InputWithHelpText=jt,x.InputWithLabel=Y,x.InputWithLabelAndHelpText=J,x.MultiSelectField=_e,x.MultiSelectInput=Rt,x.MultiStringField=ze,x.MultiStringInput=Qt,x.NumberField=se,x.NumberInput=Yt,x.PatchField=ge,x.PatchFormProvider=qo,x.QrField=at,x.QrInput=Jt,x.QrScanner=Zt,x.SUPPORTED_IMAGE_FILE_TYPES=vn,x.SUPPORTED_PDF_FILE_TYPES=bn,x.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=yn,x.SelectField=Ve,x.SelectInput=en,x.StringField=lt,x.StringInput=tn,x.TextField=ct,x.TextInput=nn,x.decodeFormValues=ko,x.deserialize=ut,x.deserializeField=an,x.emptyBaseField=H,x.emptyBooleanField=hr,x.emptyDateField=pr,x.emptyMultiSelectField=Er,x.emptyMultiStringField=br,x.emptyNumberField=Cr,x.emptyQrField=Ir,x.emptySelectField=Sr,x.emptyStringField=Nr,x.emptyTextField=Fr,x.encodeFormValues=Uo,x.fieldIcons=Yr,x.flattenFields=sn,x.formRevisionToSchema=Ar,x.initialFormValues=pt,x.isConditionMet=ln,x.useFieldInput=Ht,x.useFieldInputs=Be,x.useFormikInput=G,x.useImageViewer=Ue,x.validateForm=ht,x.valueIsFile=ft,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
|
45
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},So="DialogDescriptionWarning",To=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${cr(So).contentName}}.`;return v.useEffect(()=>{var a;const o=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},zt=Jn,No=Rn,_t=tr,Vt=nr,$t=rr,dr=sr,Re=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},et={exports:{}},Fo=et.exports,ur;function Lo(){return ur||(ur=1,function(t,n){(function(e,r){r()})(Fo,function(){function e(u,f){return typeof f>"u"?f={autoBom:!1}:typeof f!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),f={autoBom:!f}),f.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(u.type)?new Blob(["\uFEFF",u],{type:u.type}):u}function r(u,f,h){var g=new XMLHttpRequest;g.open("GET",u),g.responseType="blob",g.onload=function(){m(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function o(u){var f=new XMLHttpRequest;f.open("HEAD",u,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(u){try{u.dispatchEvent(new MouseEvent("click"))}catch{var f=document.createEvent("MouseEvents");f.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),u.dispatchEvent(f)}}var s=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof Re=="object"&&Re.global===Re?Re:void 0,l=s.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),m=s.saveAs||(typeof window!="object"||window!==s?function(){}:"download"in HTMLAnchorElement.prototype&&!l?function(u,f,h){var g=s.URL||s.webkitURL,C=document.createElement("a");f=f||u.name||"download",C.download=f,C.rel="noopener",typeof u=="string"?(C.href=u,C.origin===location.origin?a(C):o(C.href)?r(u,f,h):a(C,C.target="_blank")):(C.href=g.createObjectURL(u),setTimeout(function(){g.revokeObjectURL(C.href)},4e4),setTimeout(function(){a(C)},0))}:"msSaveOrOpenBlob"in navigator?function(u,f,h){if(f=f||u.name||"download",typeof u!="string")navigator.msSaveOrOpenBlob(e(u,h),f);else if(o(u))r(u,f,h);else{var g=document.createElement("a");g.href=u,g.target="_blank",setTimeout(function(){a(g)})}}:function(u,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof u=="string")return r(u,f,h);var C=u.type==="application/octet-stream",w=/constructor/i.test(s.HTMLElement)||s.safari,p=/CriOS\/[\d]+/.test(navigator.userAgent);if((p||C&&w||l)&&typeof FileReader<"u"){var y=new FileReader;y.onloadend=function(){var b=y.result;b=p?b:b.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=b:location=b,g=null},y.readAsDataURL(u)}else{var x=s.URL||s.webkitURL,I=x.createObjectURL(u);g?g.location=I:location.href=I,g=null,setTimeout(function(){x.revokeObjectURL(I)},4e4)}});s.saveAs=m.saveAs=m,t.exports=m})}(et)),et.exports}var kt=Lo();const Ut=d.memo(t=>{const{file:n,onClose:e}=t,r=d.useRef(null),o=d.useCallback(()=>{var l;if(!r.current)return;const s=document.createElement("canvas");s.width=r.current.width,s.height=r.current.height,(l=s.getContext("2d"))==null||l.drawImage(r.current,0,0,r.current.width,r.current.height),s.toBlob(m=>{m&&navigator.clipboard.write([new ClipboardItem({"image/png":m})])},"image/png")},[]),a=d.useCallback(()=>{kt.saveAs(n,n.name)},[n]);return i.jsx(zt,{open:!0,onOpenChange:e,children:i.jsx(_t,{children:i.jsx(Vt,{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:i.jsxs($t,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:s=>s.preventDefault(),children:[i.jsxs(c.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[i.jsxs(c.Tooltip.Root,{children:[i.jsx(c.Tooltip.Trigger,{children:i.jsx(c.IconButton,{onClick:o,"aria-label":"copy to clipboard",children:i.jsx(c.RiIcon,{icon:"RiFileCopyLine"})})}),i.jsx(c.Tooltip.Content,{size:"sm",children:"Copy"})]}),i.jsxs(c.Tooltip.Root,{children:[i.jsx(c.Tooltip.Trigger,{children:i.jsx(c.IconButton,{onClick:a,"aria-label":"download",children:i.jsx(c.RiIcon,{icon:"RiDownload2Line"})})}),i.jsx(c.Tooltip.Content,{size:"sm",children:"Download"})]}),i.jsx(c.Separator,{orientation:"vertical",size:"sm"}),i.jsx(dr,{asChild:!0,children:i.jsx(c.IconButton,{onClick:e,"aria-label":"close",children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})})})]}),i.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:i.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});Ut.displayName="ImageViewer";const fr=d.memo(t=>{const{children:n}=t,[e,r]=d.useState(null),o=d.useCallback(()=>{r(null)},[]),a=d.useCallback(m=>{r(m(o))},[o]),s=d.useCallback(()=>{e&&(e.onClose&&e.onClose(),o())},[o,e]),l=d.useMemo(()=>a,[a]);return i.jsxs(Cn.Provider,{value:l,children:[n,e&&i.jsx(Ut,{file:e.file,onClose:s})]})});fr.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:o,inputId:a,labelId:s,image:l}=t,[m,u]=d.useState(void 0),f=Ue(),h=o?de[o]:"base";d.useEffect(()=>{l instanceof Promise?l.then(u).catch(console.error):u(l)},[l]);const g=m?URL.createObjectURL(m):void 0,C=d.useCallback(()=>{m&&f(()=>({file:m}))},[f,m]);return i.jsxs("div",{className:"flex flex-col gap-1",children:[m&&i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:g,alt:m.name,onClick:C}),i.jsx("label",{className:ve(n,"flex flex-col gap-1 w-max"),htmlFor:a,children:i.jsx(c.Text,{accentColor:h,size:"sm",id:s,weight:"medium",children:e})}),r]})},jt=t=>{const{helpText:n,children:e,severity:r}=t,o=r?de[r]:"base";return i.jsxs("div",{className:"flex flex-col gap-1",children:[e,!!n&&i.jsx("div",{className:"flex flex-col w-full",children:i.jsx(c.Text,{accentColor:o,size:"xs",children:n})})]})},J=t=>{const{children:n,...e}=t;return i.jsx(jt,{...e,children:n})},Do=[!0,"true"],Wt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onBlur:g,onChange:C}=u,w=a?null:l,p=a?"":m,y=Do.includes(u.value),x=d.useCallback(()=>{g(y)},[g,y]);return i.jsx(J,{helpText:w,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:p,image:a?void 0:s.image,className:"items-center flex-row-reverse justify-end gap-2",children:i.jsx(c.Checkbox.Root,{id:n,name:h,value:y.toString(),checked:y,onCheckedChange:C,onBlur:x,size:"sm",accentColor:"primary",variant:"surface",...f,children:i.jsx(c.Checkbox.Indicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})})})})})});Wt.displayName="BooleanInput";const hr={...H,type:"boolean"},Ee=class Ee extends k{constructor(e){super({...e,type:"boolean"});T(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}getValueFromChangeEvent(e){return typeof e=="boolean"?e:e.target.checked}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Ee(e)}getInput(e){return i.jsx(Wt,{...e,field:this})}};T(Ee,"fieldTypeName","Checkbox"),T(Ee,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),T(Ee,"Icon",$.RiCheckboxCircleLine);let xe=Ee;const qt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onChange:g,onBlur:C}=u,[w,p]=d.useState(!1),y=a?null:l,x=a?"":m,I=u.value?new Date(u.value):void 0,b=d.useCallback(N=>{N&&g(N.toISOString()),p(!1)},[g]),S=d.useCallback(N=>{p(N),N||C(u.value)},[u.value,C]);return i.jsx(J,{helpText:y,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:i.jsxs(c.Popover.Root,{open:w,onOpenChange:S,children:[i.jsx(c.Popover.Trigger,{asChild:!0,children:i.jsxs(c.Button,{id:n,name:h,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...f,children:[I?I.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",i.jsx(c.RiIcon,{icon:"RiArrowDownSLine"})]})}),i.jsx(c.Popover.Content,{align:"start",children:i.jsx(c.DayPicker,{required:!1,mode:"single",variant:"solid",selected:I,onSelect:b})})]})})})});qt.displayName="DateInput";const pr={...H,type:"date"},Se=class Se extends k{constructor(e){super({...e,type:"date"});T(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return e.target.value}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new Se(e)}getInput(e){return i.jsx(qt,{field:this,...e})}};T(Se,"fieldTypeName","Date"),T(Se,"fieldTypeDescription","Allows specifying a date."),T(Se,"Icon",$.RiCalendarLine);let tt=Se;const mr=d.memo(t=>{const{field:n,...e}=t,[{value:r}]=V.useField(n.options.clonedFieldIdentifier),o=d.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?ut(a):null},[n.options,r]);return Ht(o,e)});mr.displayName="FieldInputCloner";const Mo={...H,type:"custom"};class nt extends k{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 i.jsx(r,{field:this,...e})}}T(nt,"fieldTypeName","Custom"),T(nt,"fieldTypeDescription","Allows re-rendering of field already in the form");class Ao extends nt{constructor(n){super(n,mr)}}const Ht=(t,n)=>d.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),Be=(t,n)=>{const e=d.useMemo(()=>t.map(r=>i.jsx(d.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return i.jsx("div",{className:"flex flex-col gap-4",children:e})},pe=t=>t.type==="section",rt=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Po=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const o of n)o.type==="section"?(e.length>0&&(r.push(rt(`AUTO_section-${n.indexOf(o)}`,e)),e=[]),r.push(o)):e.push(o);return e.length>0&&r.push(rt("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Gt(t,n,e){const r=Array.from(t),[o]=r.splice(n,1);if(!o)throw new Error("Could not find field to reorder.");return r.splice(e,0,o),r}function gr(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function it(t,n){const e=Array.from(t);return e.splice(n,1),e}const Xt=(t,n)=>{const e=new Date;return`${ie.slugify(n)}-${e.getTime()}`},vr=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=vr(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},yr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),ot=(t,n,e,r,o)=>{const{label:a}=e,s={...e,identifier:Xt(null,a)},l=K(r,t);if(l===void 0)throw new Error("Parent path must point to an existing field.");if(!Array.isArray(l))throw new Error("Parent path must point to an array.");const m=gr(l,n,s);o(t,m).then()},Oo=(t,n,e)=>{const r={...rt(),label:""};ot("fields",t,r,n,e)},Kt=()=>{const{showError:t}=c.useToast(),n=d.useCallback((r,o,a,s,l,m)=>{const u=r[o];if(!u)throw new Error("Could not find section context.");let f=typeof u.conditionIndex<"u"?Math.max(u.conditionIndex+1,s):s;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==s){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}m("fields",Gt(l.fields,a,f))},[t]),e=d.useCallback((r,o,a,s,l,m,u)=>{var f;if(!(r!=null&&r.fields)||!s)throw new Error("Could not find section with fields.");if(r.identifier===s.identifier)u(`fields.${o}.fields`,Gt(r.fields,a,m)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=s.condition)==null?void 0:f.identifier)===h.identifier){t({title:"Could not reorder field",description:"Field must be above the section whose condition references it."});return}u(`fields.${o}.fields`,it(r.fields,a)).then(),u(`fields.${l}.fields`,gr(s.fields,m,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},Qt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),h=a?null:l,g=a?"":m,{name:C,onChange:w,onBlur:p}=u,y=d.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),x=`${n}-droppable`,{disabled:I}=f,[b,S]=d.useState(""),[N,D]=d.useState(""),F=N||h,L=d.useCallback(P=>{w(P),p(P)},[w,p]),A=d.useCallback(P=>{y.findIndex(W=>W===P.target.value.trim())>=0?D("All options must be unique"):P.target.value?D(""):D("Option cannot be empty"),S(P.target.value)},[S,y]),O=d.useCallback(()=>{if(N)return;if(!b.trim()){D("Option cannot be empty");return}const P=b.trim();L([...y,P]),S("")},[b,N,L,y]),q=d.useCallback(P=>{P.key==="Enter"&&(P.preventDefault(),O())},[O]),ee=d.useCallback(P=>{L(it(y,P))},[y,L]),z=d.useCallback(P=>{if(!P.destination)return;const W=P.source.index,le=P.destination.index;L(Gt(y,W,le))},[L,y]),X=d.useCallback(()=>{p(y)},[p,y]);return i.jsx(re.DragDropContext,{onDragEnd:z,children:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(J,{helpText:F,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:g,image:a?void 0:s.image,children:(!I||y.length===0)&&i.jsxs("div",{className:"flex gap-2",children:[i.jsx(c.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:i.jsx(c.Input.Field,{value:b,onChange:A,onKeyDown:q,id:n,placeholder:s.placeholder,onBlur:X,name:C,...f})}),i.jsx(c.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!N||I,onClick:O,children:i.jsx(c.RiIcon,{icon:"RiAddLine"})})]})})}),i.jsx(re.Droppable,{droppableId:x,children:P=>i.jsxs("div",{className:"flex flex-col",...P.droppableProps,ref:P.innerRef,children:[y.map((W,le)=>i.jsx(re.Draggable,{draggableId:`${W}-draggable`,index:le,isDragDisabled:I,children:({draggableProps:te,dragHandleProps:ce,innerRef:Oe})=>i.jsxs(c.Badge,{...ce,...te,ref:Oe,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[i.jsx("span",{children:typeof W=="object"&&"label"in W?W.label:W}),i.jsx(c.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:I,onClick:()=>{ee(le)},children:i.jsx(c.RiIcon,{icon:"RiCloseLargeLine"})})]})},W)),P.placeholder]})})]})})});Qt.displayName="MultiStringInput";const br={...H,type:"multi-string",minimum_length:0,maximum_length:null},Te=class Te extends k{constructor(e){const{minimum_length:r,maximum_length:o,placeholder:a,...s}=e;super({...s,type:"multi-string"});T(this,"minLength");T(this,"maxLength");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.minLength=r??0,this.maxLength=o??1/0,this.placeholder=a??"Press enter to add a new option"}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return i.jsx(Qt,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(r=>{if(Array.isArray(r)&&r.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(r=>{if(Array.isArray(r)&&r.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new Te(e)}};T(Te,"fieldTypeName","Multi-string"),T(Te,"fieldTypeDescription","Allows the user to provide multiple unique strings."),T(Te,"Icon",$.RiListCheck);let ze=Te;const Yt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=G(t),{name:C,onBlur:w,onChange:p,value:y}=u,x=a?null:l,I=a?"":m,[b,S]=d.useState("");d.useLayoutEffect(()=>{S(y)},[y]);const N=d.useCallback(F=>{const L=Number.parseFloat(F.target.value),A=Number.isNaN(L)?"":L;S(A),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(A))},[s,h,f]),D=d.useCallback(()=>{p(b),w(b)},[b,w,p]);return i.jsx(J,{helpText:x,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:i.jsx(c.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:i.jsx(c.Input.Field,{id:n,name:C,onChange:N,onBlur:D,value:b,type:"number",min:s.minimum,max:s.maximum,step:s.integers?1:.1,placeholder:s.placeholder,...g})})})})});Yt.displayName="NumberInput";const Cr={...H,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},wr=t=>"fields"in t,R=class R extends k{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:o=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:s="Enter a number",...l}=e;super({...l,type:"number"});T(this,"minimum");T(this,"maximum");T(this,"integers");T(this,"placeholder");this.minimum=r,this.maximum=o,this.integers=a,this.placeholder=s}getValueFromChangeEvent(e){const r=Number.parseFloat(e.target.value);return Number.isNaN(r)?"":r}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new R({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new R({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new xe({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,o=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof o=="number"&&e.push(a=>{if(typeof a=="number"&&a>o)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(a=>{if(typeof a=="number"&&!Number.isInteger(a))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new R(e)}getInput(e){return i.jsx(Yt,{field:this,...e})}};T(R,"fieldTypeName","Number"),T(R,"fieldTypeDescription","Allows specifying a number within a given range."),T(R,"Icon",$.RiHashtag),T(R,"_validateMin",e=>(r,o)=>{const a=wr(o)?K(o,e):o;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),T(R,"_validateMax",e=>(r,o)=>{const a=wr(o)?K(o,e):o;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let se=R;const Jt=d.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:o,size:a,severity:s,showInputOnly:l,field:m,fieldProps:u},f]=G(t),{name:h,onBlur:g,onChange:C,value:w}=u,[p,y]=d.useState(!1),x=l?null:o,I=l?"":r,b=d.useCallback(D=>{C(D),y(!1)},[C]),S=d.useCallback(()=>{C("")},[C]),N=d.useCallback(D=>{y(D),D||g(w)},[g,w]);return i.jsx(J,{helpText:x,severity:s,children:i.jsxs(Y,{size:a,severity:s,inputId:n,labelId:e,label:I,image:l?void 0:m.image,className:"flex-col items-start justify-start gap-2",children:[i.jsxs("div",{className:"flex w-max items-center gap-1",children:[i.jsxs(zt,{open:p,onOpenChange:N,children:[i.jsx(No,{asChild:!0,children:i.jsxs(c.Button,{id:n,name:h,type:"button",variant:"soft",size:"sm",accentColor:"base",...f,children:[i.jsx(c.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),i.jsxs(_t,{children:[i.jsx(Vt,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),i.jsx($t,{className:"fixed inset-0",children:i.jsx(Zt,{onQrScan:b})})]})]}),w&&i.jsx(c.RiIcon,{icon:"RiCheckLine",className:"align-bottom text-(--primary-a11)"})]}),!!w&&i.jsx(c.Card,{className:"max-w-full w-max",size:"sm",children:i.jsxs("div",{className:"max-w-full w-max flex justify-between gap-2",children:[i.jsx("code",{className:"bg-(--base-a3) truncate text-sm",children:w}),i.jsx(c.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:S,children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})})]})})]})})});Jt.displayName="QrInput";const Zt=d.memo(t=>{const{onQrScan:n}=t,e=d.useRef(null),[r,o]=d.useState(!1);return d.useEffect(()=>{if(!e.current)return;const a=new Hr(e.current,s=>{const l=s.data;n(l),a.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});o(!0),a.start().finally(()=>{o(!1)})},[n]),i.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[i.jsx("div",{className:"absolute top-0 flex w-full p-2",children:i.jsx(dr,{asChild:!0,children:i.jsx(c.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})})})}),i.jsxs("div",{className:"relative max-h-full max-w-full",children:[i.jsx("video",{className:"size-full",ref:e}),r&&i.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:i.jsx(c.Spinner,{})})]})]})});Zt.displayName="QrScanner";const Ir={...H,type:"qr"},Ne=class Ne extends k{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 Ne(e)}getInput(e){return i.jsx(Jt,{...e,field:this})}};T(Ne,"fieldTypeName","QR"),T(Ne,"fieldTypeDescription","Used for scanning/reading QR codes."),T(Ne,"Icon",$.RiQrCodeLine);let at=Ne;class xr extends k{constructor(e){const{placeholder:r="",...o}=e;super(o);T(this,"options");T(this,"onlyValidateAfterTouched",!1);T(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(s=>(typeof s=="string"&&(s={label:s,value:s}),a.add(s.label),s)),a.size!==e.options.length&&console.error(`${e.options.length-a.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options,placeholder:this.placeholder}}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new ze({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const Bo=t=>t?Array.isArray(t)?t:[t]:[],Rt=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onChange:g,onBlur:C}=u,w=a?null:l,p=a?"":m,y=d.useMemo(()=>Bo(u.value),[u.value]),x=d.useCallback(b=>{g(b),C(b)},[C,g]),I=d.useCallback(b=>{b||C(y)},[y,C]);return i.jsx(J,{helpText:w,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:p,image:a?void 0:s.image,children:i.jsxs(c.Menu.Root,{onOpenChange:I,align:"start",children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsxs(c.Button,{id:n,name:h,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...f,children:[i.jsx("span",{className:"truncate",children:y.length>0?y.join(", "):s.placeholder}),i.jsx(c.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),i.jsx(c.Menu.Content,{children:i.jsx(c.Menu.Scroll,{children:i.jsxs(c.Menu.MultiSelectGroup,{values:y,onValuesChange:x,children:[i.jsxs(c.Menu.SelectAllItem,{children:[i.jsx(c.Menu.CheckboxItemIndicator,{children:b=>b?i.jsx(c.RiIcon,{icon:"RiSubtractLine"}):i.jsx(c.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),s.options.map(b=>i.jsxs(c.Menu.MultiSelectItem,{value:b.value,children:[i.jsx(c.Menu.SelectedIndicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})}),b.label]},b.value))]})})})]})})})});Rt.displayName="MultiSelectInput";const Er={...H,type:"multi-select",options:[]},Fe=class Fe extends xr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}getValueFromChangeEvent(n){if(Array.isArray(n))return n;throw new Error("Expected an array.")}isBlank(n){return super.isBlank(n)||n.length===0}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Fe(n)}getInput(n){return i.jsx(Rt,{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",$.RiCheckboxLine);let _e=Fe;const en=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=G(t),{name:h,onChange:g,onBlur:C,value:w}=u,p=a?null:l,y=a?"":m,x=d.useCallback(b=>{b&&(g(b),C(b))},[C,g]),I=d.useMemo(()=>s.options.find(b=>b.value===w),[s.options,w]);return i.jsx(J,{helpText:p,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:y,image:a?void 0:s.image,children:i.jsxs(c.Menu.Root,{align:"start",children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsxs(c.Button,{id:n,name:h,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...f,children:[i.jsx("span",{className:"truncate",children:I?I.label:s.placeholder}),i.jsx(c.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),i.jsx(c.Menu.Content,{children:i.jsx(c.Menu.Scroll,{children:i.jsx(c.Menu.SelectGroup,{required:!0,value:w,onValueChange:x,children:s.options.map(b=>i.jsxs(c.Menu.SelectItem,{value:b.value,children:[i.jsx(c.Menu.SelectedIndicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})}),b.label]},b.value))})})})]})})})});en.displayName="SelectInput";const Sr={...H,type:"select",options:[]},Le=class Le extends xr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}getValueFromChangeEvent(n){return typeof n=="string"?n:n.target.value}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new Le(n)}getInput(n){return i.jsx(en,{field:this,...n})}};T(Le,"fieldTypeName","Dropdown"),T(Le,"fieldTypeDescription","Allows the user to select a single option from a list of options."),T(Le,"Icon",$.RiMenuFoldLine);let Ve=Le;const Tr=t=>"fields"in t;class st extends k{constructor(e){const{minLength:r,maxLength:o,placeholder:a="",...s}=e;super(s);T(this,"minLength");T(this,"maxLength");T(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=o?Math.max(o,0):ye,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:`${r}minimum_length`,minimum:0,maximum:100,formValidators:[this._validateMin(e)],integers:!0}),showDirectly:!1},{field:new se({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:ye,formValidators:[this._validateMax(e)],integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(r=>{if(this.minLength&&(!r||r.length<this.minLength))return!this.required&&!r?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(r=>{if(typeof r=="string"&&this.maxLength&&r.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}}T(st,"_validateMin",e=>(r,o)=>{const a=Tr(o)?K(o,e):o;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),T(st,"_validateMax",e=>(r,o)=>{if(typeof r!="number")return null;const{minimum_length:a}=Tr(o)?K(o,e):o;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const tn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=G(t),{name:C,onBlur:w,onChange:p,value:y}=u,x=a?null:l,I=a?"":m,[b,S]=d.useState("");d.useLayoutEffect(()=>{S(y)},[y]);const N=d.useCallback(F=>{S(F.target.value),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),D=d.useCallback(()=>{p(b),w(b)},[b,w,p]);return i.jsx(J,{helpText:x,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:i.jsx(c.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:i.jsx(c.Input.Field,{id:n,name:C,value:b,type:s.inputType,placeholder:s.placeholder,onChange:N,onBlur:D,...g})})})})});tn.displayName="StringInput";const Nr={...H,type:"string",maximum_length:ke,input_type:"text"},De=class De extends st{constructor(e){const{inputType:r="text",...o}=e,a=e.maxLength?Math.min(ke,e.maxLength):ke,s=e.minLength?Math.min(e.minLength,a):void 0;super({...o,maxLength:a,minLength:s,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:o,input_type:a,...s}=e;return new De({...s,maxLength:r,minLength:o,inputType:a,placeholder:"Enter a short description"})}getInput(e){return i.jsx(tn,{field:this,...e})}};T(De,"fieldTypeName","Short Text"),T(De,"fieldTypeDescription",`Short text fields can hold up to ${ke} characters on a single line.`),T(De,"Icon",$.RiInputField);let lt=De;const nn=d.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:o,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=G(t),{name:C,onBlur:w,onChange:p,value:y}=u,x=a?null:l,I=a?"":m,[b,S]=d.useState("");d.useLayoutEffect(()=>{S(y)},[y]);const N=d.useCallback(F=>{S(F.target.value),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),D=d.useCallback(()=>{p(b),w(b)},[b,w,p]);return i.jsx(J,{helpText:x,severity:o,children:i.jsx(Y,{size:r,severity:o,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:i.jsx(c.TextArea,{id:n,value:b,name:C,onChange:N,onBlur:D,className:"field-sizing-content min-h-12",placeholder:s.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...g})})})});nn.displayName="TextInput";const Fr={...H,type:"text",maximum_length:ye},Me=class Me extends st{constructor(n){const e=n.maxLength?Math.min(ye,n.maxLength):ye,r=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:r,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:r,...o}=n;return new Me({...o,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return i.jsx(nn,{field:this,...n})}};T(Me,"fieldTypeName","Paragraph"),T(Me,"fieldTypeDescription",`Paragraph fields can hold up to ${ye} characters and can have multiple lines.`),T(Me,"Icon",$.RiAlignJustify);let ct=Me;const Lr=d.memo(d.forwardRef((t,n)=>{const{file:e,alt:r,error:o,rightSlot:a,className:s,...l}=t;return i.jsxs("div",{className:ve(s,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...l,children:[!e&&!o&&i.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:i.jsx(c.Spinner,{})}),i.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!o&&i.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),i.jsxs("div",{className:ve("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[o?i.jsx(c.RiIcon,{icon:"RiFileWarningLine"}):e&&i.jsx($e,{fileType:e.type}),i.jsx(c.Text,{className:"truncate",size:"sm",children:o??(e==null?void 0:e.name)}),a]})]})})),zo=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)},Dr=d.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:o,helpText:a,showInputOnly:s,field:l,fieldProps:m},u]=G(t),{name:f,value:h,onChange:g,onBlur:C}=m;let[{label:w}]=G(t);w=s?"":w;const p=d.useRef(null),y=d.useMemo(()=>s?null:a||(l.maxFileSize?`Maximum file size: ${l.maxFileSize}MB`:null),[l.maxFileSize,a,s]),x=d.useCallback(()=>{var L;(L=p.current)==null||L.click()},[]),I=d.useCallback(()=>{if(!p.current)return;const L=p.current.files;if(!L){C([]);return}const A=Array.from(L),O=[...h,...A];g(O),C(O)},[C,g,h]),b=d.useCallback(L=>{const A=[...h];A.splice(L,1),g(A)},[h,g]);d.useEffect(()=>{if(!p.current)return;const L=new AbortController;return p.current.addEventListener("cancel",()=>{C([])},{signal:L.signal}),()=>{L.abort()}},[C,h]);const S=h?"Select new files":"Select files",N=h?"Select new file":"Select a file",D=l.maxFiles>1?S:N;return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx(J,{helpText:y,severity:o,children:i.jsxs(Y,{size:r,severity:o,inputId:n,labelId:e,label:w,image:s?void 0:l.image,children:[i.jsx("div",{className:"flex gap-2",children:i.jsxs(c.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:x,id:"upload-input-upload-button",type:"button",...u,children:[i.jsx(c.RiIcon,{icon:"RiUpload2Line"})," ",D]})}),i.jsx("input",{id:n,name:f,type:"file",ref:p,accept:(F=l.extensions)==null?void 0:F.join(","),multiple:l.maxFiles>1,className:"hidden",onChange:I,value:""})]})}),Array.isArray(h)&&h.length>0&&i.jsx("div",{className:"flex h-max flex-col gap-2",children:h.map((L,A)=>i.jsx(Mr,{field:l,file:L,onRemove:()=>{b(A)},disabled:u.disabled},A))})]})});Dr.displayName="UploadInput";const Mr=d.memo(t=>{const{file:n,field:e,onRemove:r,disabled:o}=t,[a,s]=d.useState(null),l=Ue(),m=d.useMemo(()=>a&&e.getError([a]),[e,a]),{url:u,name:f}=d.useMemo(()=>{let p=null,y,x;return a!=null&&a.type.startsWith("image/")&&(p=URL.createObjectURL(a)),a?(y=a.name,x=zo(a.size)):(y="Downloading...",x="..."),{url:p,name:y,size:x}},[a]);d.useEffect(()=>{n instanceof Promise?n.then(s).catch(console.error):s(n)},[n]);const h=d.useCallback(p=>{if(p.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const y=new Blob([a]);kt.saveAs(y,f)},[f,a]),g=d.useCallback(p=>{p.stopPropagation(),r()},[r]),C=d.useCallback(()=>{a&&l(p=>({file:a,onDelete:o?void 0:()=>{r(),p()}}))},[o,r,l,a]),w=d.useMemo(()=>i.jsxs(c.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[i.jsx(c.IconButton,{"aria-label":`Download ${f}`,type:"button",onClick:h,disabled:!a,children:i.jsx(c.RiIcon,{icon:"RiDownload2Line"})}),!o&&i.jsx(c.IconButton,{type:"button","aria-label":`Remove ${f}`,disabled:o,onClick:g,children:i.jsx(c.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[o,g,h,f,a]);return u?i.jsx(Lr,{className:"cursor-pointer",onClick:C,file:a,error:m??void 0,rightSlot:w}):i.jsx(yt,{file:a,error:m??void 0,rightSlot:w})});Mr.displayName="DisplayFile";const _o={...H,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1},Ae=class Ae extends k{constructor(e){const{extensions:r,maximum_files:o,maximum_size:a,...s}=e;super({...s,type:"upload"});T(this,"extensions");T(this,"maxFileSize");T(this,"maxFiles");T(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof a=="number"?a:void 0,this.maxFiles=Math.max(typeof o=="number"?o:1,1),this.extensions=r}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:`${r}maximum_files`,integers:!0}),showDirectly:!1},{field:new se({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${dt}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:dt,integers:!0}),showDirectly:!1},{field:new _e({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??dt,o=r*1e3*1e3,a=this.maxFiles||1;return e.push(s=>{if(s&&s.some(l=>l.size>o))return`Files must be at most ${r}MB.`}),e.push(s=>{if(s&&s.length>a)return`You can only upload ${a} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new Ae(e)}getInput(e){return i.jsx(Dr,{field:this,...e})}};T(Ae,"fieldTypeName","Upload"),T(Ae,"fieldTypeDescription","Allows a file to be uploaded."),T(Ae,"Icon",$.RiUpload2Line);let rn=Ae;const on={date:tt,number:se,boolean:xe,select:Ve,string:lt,text:ct,custom:nt,upload:rn,qr:at,"multi-string":ze,"multi-select":_e},Vo={date:pr,number:Cr,boolean:hr,select:Sr,string:Nr,text:Fr,custom:Mo,upload:_o,qr:Ir,"multi-string":br,"multi-select":Er},dt=50,$o=dt*1e3*1e3,an=t=>{const n=t.type;return on[n].deserialize(t)},ut=t=>t.type==="section"?U.deserialize(t):an(t);function Ar(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>ut(r)),meta:{readonly:e}}}function sn(t){const n=[];for(const e of t.fields)if(e instanceof U)for(const r of e.fields)n.push(r);else{if(!(e instanceof k))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function ko(t,n){const e=sn(t),r={};for(const o of e){const a=n[o.identifier]??null;a!==null?r[o.identifier]=o.decodeJsonToValue(a):r[o.identifier]=a}return r}function Uo(t,n){const e=sn(t),r={};for(const o of e){const a=n[o.identifier];r[o.identifier]=o.encodeValueToJson(a)}return r}function ft(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function ln(t,n){if(!t)return!0;if(ft(n)||ft(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(o=>typeof o=="string"?o:o.value):n,r=Array.isArray(t.value)?t.value.map(o=>typeof o=="string"?o:o.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const o of r)if(!e.includes(o))return!1;return!0}return r===n}const Pr=d.memo(t=>{const{field:n,...e}=t,{label:r,description:o,fields:a,condition:s}=n,{values:l,setFieldValue:m}=V.useFormikContext(),u=s!=null&&s.identifier?K(l,s.identifier):void 0,f=d.useMemo(()=>u===void 0||ln(s,u),[s,u]);d.useEffect(()=>{if(!f)for(const g of a)m(g.getId(),"").then()},[f,a,m]);const h=Be(a,e);return f?i.jsx(c.Card,{variant:"soft",children:i.jsxs("div",{className:"flex flex-col gap-4",children:[(r||o)&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex flex-col",children:[i.jsx(c.Heading,{size:"md",children:r}),i.jsx(c.Text,{accentColor:"base",children:o})]}),i.jsx(c.Separator,{size:"full"})]}),h]})}):null});Pr.displayName="FieldSectionLayout";const Pe=class Pe extends bt{constructor(e){const{label:r=null,fields:o,condition:a=null,conditional:s,...l}=e;super({...l,type:"section"});T(this,"label");T(this,"fields");T(this,"condition");this.fields=o,this.condition=a,this.label=r,s===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const o=r&&`${r}.`;return[{field:new xe({label:"Conditionally render section",identifier:`${o}conditional`,required:!1}),showDirectly:!0},{field:new Pe({label:"Conditional settings",identifier:`${o}conditional-settings`,condition:{identifier:`${o}conditional`,value:!0},fields:[new Ve({label:"Field",description:"The field to use for the condition.",options:e.map(a=>!a.label||a.type==="upload"?null:{label:a.label,value:a.identifier}).filter(a=>!!a),identifier:`${o}condition.identifier`,required:!0}),new Ao({label:"Value",identifier:`${o}condition.value`,required:!0,clonedFieldIdentifier:`${o}condition.identifier`,getFieldToClone(a){if(!a)return null;const s=e.find(l=>l.identifier===a);return s?{...s,label:"Value",identifier:`${o}condition.value`,description:"The value to compare against.",required:s.type!=="boolean"}:(console.error("Could not find field with identifier",a),null)}})]}),showDirectly:!1}]}static deserialize(e){if(e.type!=="section")throw new Error("Invalid type");if(!Array.isArray(e.fields))throw new Error(`Invalid fields: ${e.fields} (not an array)`);const r=e.fields.map(an);return new Pe({...e,fields:r})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const r={};for(const o of this.fields){const a=o.getId(),s=o.getError(K(e,a),e);s&>(r,o.getId(),s)}return r}getInput(e){return i.jsx(Pr,{field:this,...e})}};T(Pe,"fieldTypeName","Section"),T(Pe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let U=Pe;const me=t=>Object.keys(t).length>0,ht=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof U){if(r.condition){const{identifier:o}=r.condition;if(!ln(r.condition,K(n,o)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof k))throw new Error("Invalid field type");const o=r.getId(),a=r.getError(K(n,o),n);a&>(e,o,a)}if(me(e))return e},jo=[null,void 0],pt=(t,n)=>t.reduce((e,r)=>r instanceof U?{...e,...pt(r.fields,n)}:(jo.includes(K(e,r.getId()))&>(e,r.getId(),""),e),Gr(n)),Wo=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Or=d.memo(d.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:o,onSubmit:a=Wo,submitText:s="Submit",cancelText:l,onCancel:m,onDirty:u,onDirtyChange:f,hideTitle:h=!e.title,hideDescription:g,className:C,buttonProps:w}=t,{readonly:p}=e.meta,y=d.useMemo(()=>crypto.randomUUID(),[]),x=V.useFormik({initialValues:pt(e.fields,r),onSubmit:a,validate:F=>ht(e,F),validateOnBlur:!1,validateOnChange:!1}),{dirty:I}=x,b=d.useMemo(()=>typeof e.title=="string"?i.jsx(c.Heading,{size:"md",children:e.title}):e.title,[e.title]),S=d.useMemo(()=>typeof e.description=="string"?i.jsx(c.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),N=d.useCallback((F,L)=>{o==null||o({...x.values,[F]:L},{[F]:L})},[x.values,o]),D=Be(e.fields,{formId:y,disabled:p,onValuesChange:N});return d.useEffect(()=>{I&&u&&u(),f&&f(I)},[I,u,f]),i.jsx(V.FormikProvider,{value:x,children:i.jsxs("form",{id:y,ref:n,className:ve(C,"flex flex-col gap-2"),onSubmit:x.handleSubmit,children:[!h&&i.jsx(c.Card,{variant:"soft",children:i.jsxs("div",{className:"flex flex-col gap-1",children:[b,!g&&S]})}),D,!p&&i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&i.jsxs(c.Button,{accentColor:de.danger,...w,type:"button",onClick:m,children:[i.jsx(c.RiIcon,{icon:"RiCloseLine"}),l]}),i.jsxs(c.Button,{...w,type:"submit",disabled:!x.isValid,accentColor:"success",children:[i.jsx(c.RiIcon,{icon:"RiCheckLine"}),s]})]})]})})})),ge=d.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=V.useFormikContext(),[o,a,s]=V.useField(n),l=d.useMemo(()=>{const m=u=>{s.setValue(u,!1)};return e({value:o.value,meta:a,setValue:m,patchValue:()=>{r()}})},[e,o.value,a,r,s]);return i.jsx(i.Fragment,{children:l})});ge.displayName="PatchField";const qo=d.memo(d.forwardRef((t,n)=>{const{children:e,schema:r,values:o,onPatch:a,onError:s,requiresDiff:l=!0,onDirtyChange:m,...u}=t,f=d.useMemo(()=>pt(r.fields,o),[r.fields,o]),h=d.useCallback(I=>{const b={};for(const S in I){const N=I[S];N!==f[S]&&N!==void 0&&(b[S]=N)}return b},[f]),g=d.useCallback(I=>{const b=h(I);l&&!me(b)||a(b)},[h,a,l]),C=d.useCallback(I=>{const b=ht(r,I);if(b&&s(b),m){const S=h(I);m(me(S))}return b},[r,m,s,h]),w=V.useFormik({initialValues:f,onSubmit:g,validate:C,validateOnBlur:!1,validateOnChange:!1}),p=d.useCallback(()=>{if(m){const I=h(w.values);me(I)&&m(!0)}},[w.values,h,m]),{errors:y,resetForm:x}=w;return d.useEffect(()=>{me(y)&&x({values:f,errors:{}})},[y,f,x]),i.jsx(V.FormikProvider,{value:w,children:i.jsx("form",{...u,ref:n,onSubmit:w.handleSubmit,onChange:p,children:e})})})),mt="form-builder",Ho=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],cn={...on,section:U},Go=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const o in e)e[o].disabled=!1;return e;case"hold":for(const o in e)(r=e[o])!=null&&r.conditionFields.has(n.fieldId)&&(e[o].disabled=!0);return e;case"update":return n.state}},Xo=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const o of r.fields)if(o.identifier===n)return e}}},Br=t=>{var e,r,o;const n={};for(let a=0;a<t.length;a++){const s=t[a];if(!s)throw new Error("Field is undefined.");const l=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,m=new Set(l);(r=s.condition)!=null&&r.identifier&&m.add(s.condition.identifier),n[s.identifier]={disabled:!1,conditionFields:m,conditionIndex:Xo(t,(o=s.condition)==null?void 0:o.identifier),index:a,label:s.label}}return n},dn=d.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:o,duplicate:a,move:s,upload:l}=t;if(e!=="section"&&!l)throw new Error("Upload function prop must be defined for non-section fields.");const{values:m}=V.useFormikContext(),u=d.useRef(null),f=d.useMemo(()=>{const h=[{Icon:$.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:$.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:o}}),e!=="section"&&h.unshift({Icon:$.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=u.current)==null||g.click()}}}),(r===void 0&&n!==m.fields.length-1||r!==void 0&&(r<m.fields.length-1||n!==m.fields[r].fields.length-1))&&h.unshift({Icon:$.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{s("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:$.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{s("up")}}}),h},[a,n,s,o,r,e,m.fields]);return i.jsxs(i.Fragment,{children:[i.jsx(c.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:f.map(h=>i.jsx(c.IconButton,{type:"button","aria-label":h.text,...h.buttonProps,children:i.jsx(h.Icon,{})},h.key))}),i.jsx("div",{className:"sm:hidden",children:i.jsxs(c.Menu.Root,{children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsx(c.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:i.jsx(c.RiIcon,{icon:"RiMore2Line"})})}),i.jsx(c.Menu.Content,{children:f.map(h=>{var g;return i.jsxs(c.Menu.Item,{onClick:(g=h.buttonProps)==null?void 0:g.onClick,children:[i.jsx(h.Icon,{}),h.text]},h.key)})})]})}),e!=="section"&&i.jsx("input",{style:{display:"none"},ref:u,type:"file",accept:"image/*",onChange:l})]})});dn.displayName="FieldActions";const un=d.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return i.jsxs(c.Popover.Root,{children:[i.jsx(c.Popover.Trigger,{asChild:!0,children:i.jsxs(c.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:de.danger},children:[i.jsx(c.RiIcon,{icon:"RiSettings2Line"}),i.jsx("span",{children:"Settings"})]},"settings")}),i.jsx(c.Popover.Content,{size:"sm",...r,children:i.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});un.displayName="FieldSettingsPopover";const zr=(t=()=>null)=>d.useMemo(()=>Ho.map(n=>n.map(e=>{const r=on[e],o=r.Icon;return{children:r.fieldTypeName,icon:i.jsx(o,{}),value:e,onSelect:()=>{t(e)}}})),[t]),fn=d.memo(t=>{var Oe,hn,jr,Wr,qr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:o}=t,{values:a,setFieldValue:s,errors:l}=V.useFormikContext(),m=zr(),u=Ue(),f=d.useRef(null),h=576,[g,C]=d.useState(f.current&&f.current.getBoundingClientRect().width>=h);d.useEffect(()=>{const M=f.current;if(M){const B=new ResizeObserver(j=>{j[0]&&C(j[0].contentRect.width>=h)});return B.observe(M),()=>{B.disconnect()}}},[]);const[w,p]=d.useState(void 0);d.useEffect(()=>{pe(r)?p(void 0):r.image instanceof Promise?r.image.then(p).catch(console.error):p(r.image)},[r]);const y=w?URL.createObjectURL(w):void 0,x=d.useCallback(M=>{M.stopPropagation();const{image:B,...j}=r;s(`${n}.${e}`,j).then()},[e,r,n,s]);d.useEffect(()=>{pe(r)&&!r.conditional&&s(`${n}.${e}.condition`,null).then()},[e,r,n,s]);const I=d.useMemo(()=>{var M,B;return pe(r)?(B=vr(a.fields,(M=r.condition)==null?void 0:M.identifier))==null?void 0:B.label:void 0},[r,a.fields]),b=pe(r)?Array.isArray((Oe=r.condition)==null?void 0:Oe.value)?"contains all of":"equals":void 0;let S;if(pe(r)){if(ft((hn=r.condition)==null?void 0:hn.value))throw new Error("File values are not supported for conditions.");S=Array.isArray((jr=r.condition)==null?void 0:jr.value)?r.condition.value.map(M=>typeof M=="string"?M:M.label).join(", "):(qr=(Wr=r.condition)==null?void 0:Wr.value)==null?void 0:qr.toString()}const N=d.useCallback(M=>{M.target.parentNode instanceof HTMLElement&&(M.target.parentNode.dataset.replicatedValue=M.target.value)},[]),D=d.useCallback(M=>{M.target.parentNode instanceof HTMLElement&&(M.target.parentNode.dataset.replicatedValue=M.target.value)},[]),F=r.type,L=cn[F],[A,O]=d.useMemo(()=>{let M=[],B=[];if(L===U){if(o===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const j=L.getFieldCreationSchema(o,`${n}.${e}`);M=M.concat(j.filter(_=>_.showDirectly).map(_=>_.field)),B=B.concat(j.filter(_=>!_.showDirectly).map(_=>_.field))}else{if(!(L.prototype instanceof k))throw new Error(`Field must be an instance of BaseField. Got ${L.toString()}.`);const j=L.getFieldCreationSchema(`${n}.${e}`);g?(M=[...M,...j.filter(_=>_.showDirectly).map(_=>_.field)],B=[...B,...j.filter(_=>!_.showDirectly).map(_=>_.field)]):B=[...B,...j.map(_=>_.field)]}return[M,B]},[L,o,n,e,g]),q=Be(A,{formId:mt,disabled:!1,...L===U&&{size:"sm"}}),ee=Be(O,{formId:mt,disabled:!1});let z=O.length>0;pe(r)&&O.length>0&&(z=r.conditional);const X=O.some(M=>{const B=K(l,L===U?`${n}.${e}.condition`:M.getId());return B&&(typeof B!="object"||me(B))}),P=X?de.danger:void 0,W=d.useMemo(()=>ut(r),[r]),le=Ht(W,{formId:mt,showInputOnly:!1}),te=d.useMemo(()=>m.flat().find(M=>M.value===F),[m,F]),ce=d.useCallback(()=>{w&&u(()=>({file:w}))},[u,w]);return i.jsx("div",{className:"flex grow items-center w-full",ref:f,children:i.jsxs("div",{className:"flex w-full flex-col gap-2",children:[L===U&&(A.length>0||z)&&i.jsxs("div",{className:"flex flex-col gap-2",children:[q,z&&i.jsxs("div",{className:"flex items-center gap-4",children:[i.jsx(un,{popoverInputs:ee,hasError:X,align:"start"}),pe(r)&&r.conditional&&i.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":P,children:i.jsxs("em",{children:["Display only if ",i.jsx("strong",{children:I})," ",b," ",i.jsx("strong",{children:S})]})})]})]}),L!==U&&i.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[i.jsxs("div",{className:"flex gap-2 items-center",children:[i.jsxs(c.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[te==null?void 0:te.icon,te==null?void 0:te.children]}),i.jsx(ge,{name:`${n}.${e}.required`,render:({setValue:M,value:B})=>i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c.Checkbox.Root,{checked:B,onCheckedChange:M,size:"sm",children:i.jsx(c.Checkbox.Indicator,{children:i.jsx(c.RiIcon,{icon:"RiCheckLine"})})}),i.jsx(c.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),z&&i.jsx(un,{popoverInputs:ee,hasError:X,align:"end"})]}),w&&i.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[i.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:y,alt:w.name,onClick:ce}),i.jsx(c.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:"base","aria-label":"delete",onClick:x,size:"sm",children:i.jsx(c.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),i.jsx(ge,{name:`${n}.${e}.label`,render:({setValue:M,value:B})=>i.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:F==="section"?"Enter a section label (optional)":"Enter your question",value:B,onChange:j=>{M(j.target.value)},onInput:N,maxLength:200})}),i.jsx(ge,{name:`${n}.${e}.description`,render:({setValue:M,value:B})=>i.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${F==="section"?"section":"field"} description (optional)`,value:B,onChange:j=>{M(j.target.value)},onInput:D,maxLength:1e3})}),L!==U&&A.length>0&&i.jsx("div",{className:"w-full",children:q}),L!==U&&i.jsxs(c.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[i.jsxs(c.HoverCard.Root,{children:[i.jsx(c.HoverCard.Trigger,{asChild:!0,children:i.jsx(c.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:i.jsx(c.RiIcon,{icon:"RiEyeLine"})})}),i.jsx(c.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."})]}),i.jsx("div",{className:"grow h-max",children:le})]})]})})});fn.displayName="FieldBuilder";const _r=d.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:o}=t,{setFieldValue:a,values:s}=V.useFormikContext(),{reorderField:l}=Kt(),{showInfo:m,showError:u}=c.useToast(),f=`fields.${r}.fields`,h=d.useMemo(()=>({index:e,parentPath:f,initial:n}),[n,e,f]),g=d.useCallback(()=>{const p=n.label||"Unlabelled field",y={...n,label:p};ot(f,e+1,y,s,a),m({title:"Field duplicated",description:`The field "${p}" has been duplicated`})},[n,f,e,s,a,m]),C=d.useCallback(p=>{const y=r,x=s.fields[y];let I=r,b=p==="up"?e-1:e+1;p==="up"&&e===0?(I=r-1,b=s.fields[I].fields.length):p==="down"&&e===x.fields.length-1&&(I=r+1,b=0);const S=s.fields[I];l(x,y,e,S,I,b,a)},[r,s.fields,e,l,a]),w=d.useCallback(p=>{const{files:y}=p.target;if(!y||y.length!==1)return;const x=y.item(0);if(x){if(x.size>$o){u({title:"File upload error",description:`The file ${x.name} exceeded the maximum file size`});return}a(`${f}.${e}`,{...n,image:x}).then()}},[n,e,f,a,u]);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:p=>i.jsx(c.Card,{ref:p.innerRef,...p.draggableProps,...p.dragHandleProps,className:"mb-4",children:i.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[i.jsx(fn,{...h}),i.jsx(dn,{index:e,type:n.type,sectionIndex:r,remove:o,duplicate:g,move:C,upload:w})]})})})});_r.displayName="FieldWithActions";const Vr=d.memo(t=>{var S;const{field:n,index:e,dropState:r,fieldsOnly:o}=t,a=(S=r[n.identifier])==null?void 0:S.disabled,{setFieldValue:s,values:l}=V.useFormikContext(),m=c.useAlertDialog(),{reorderSection:u}=Kt(),{showInfo:f}=c.useToast(),h=d.useCallback((N,D)=>{for(const F of N){const L=D.indexOf(F);s(`fields.${L}.condition`,null).then(),s(`fields.${L}.conditional`,!1).then()}},[s]),g=d.useCallback(N=>{var L;const D=n.fields[N];if(!D)throw new Error("Could not find field to remove.");const F=[];for(const A of l.fields)((L=A.condition)==null?void 0:L.identifier)===D.identifier&&F.push(A);return{removing:D,affectedSections:F,action:()=>s(`fields.${e}.fields`,it(n.fields,N))}},[n.fields,l.fields,s,e]),C=d.useCallback(N=>{const{affectedSections:D,action:F,removing:L}=g(N),A=()=>{F().then(),h(D,l.fields)};if(D.length>0){const O=D.map(q=>q.label).join(", ");m({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${O} section(s).`,action:"Remove",onAction:A});return}A()},[g,h,l.fields,m]),w=d.useCallback(()=>{const D=n.fields.map((z,X)=>g(X)).flatMap(z=>z.affectedSections),F=D.length?"Remove fields and conditions?":"Remove fields?",L=n.fields.length,A=D.map(z=>z.label).join(", "),O=D.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${A}`:`Deleting this section will remove the ${L} field(s) it contains.`,q=it(l.fields,e),ee=()=>s("fields",q);if(D.length>0){m({title:F,description:O,action:"Remove",onAction:()=>{ee().then(()=>{h(D,q)})}});return}ee().then()},[n.fields,l.fields,e,g,s,m,h]),p=d.useCallback(N=>{const D=N==="up"?e-1:e+1;u(r,n.identifier,e,D,l,s)},[e,u,r,n.identifier,l,s]),y=d.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:yr(l.fields,e)}),[n,e,l.fields]),x=d.useCallback(()=>{const N=n.label||"Untitled section",D=n.fields.map(L=>({...L,identifier:Xt(null,L.label)})),F={...n,label:N,fields:D};ot("fields",e+1,F,l,s),f({title:"Section duplicated",description:`The section "${N}" has been duplicated.`})},[n,e,l,s,f]),I=d.useCallback(N=>{ot(`fields.${e}.fields`,n.fields.length,Vo[N],l,s)},[e,n.fields.length,l,s]),b=zr(I);return i.jsx(re.Draggable,{draggableId:n.identifier,index:e,children:N=>i.jsx(c.Card,{ref:N.innerRef,...N.draggableProps,...N.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:i.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[i.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!o&&i.jsx(fn,{...y}),i.jsx(re.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:a,children:D=>i.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:D.innerRef,...D.droppableProps,children:[n.fields.map((F,L)=>i.jsx(_r,{field:F,index:L,sectionIndex:e,remove:()=>{C(L)}},F.identifier)),D.placeholder,i.jsxs(c.Menu.Root,{children:[i.jsx(c.Menu.ClickTrigger,{children:i.jsxs(c.Button,{type:"button",variant:"soft",size:"sm",children:[i.jsx(c.RiIcon,{icon:"RiAddLine"})," Add field"]})}),i.jsx(c.Menu.Content,{children:b.flat().map(F=>i.jsxs(c.Menu.Item,{onSelect:F.onSelect,children:[F.icon,F.children]},F.value))})]})]})})]}),!o&&i.jsx(dn,{index:e,type:n.type,remove:w,duplicate:x,move:p})]})})})});Vr.displayName="FieldSectionWithActions";const $r=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},kr=d.memo(t=>{const{fieldsOnly:n}=t,{values:e,setFieldValue:r}=V.useFormikContext(),[o,a]=d.useReducer(Go,e.fields,Br),{reorderSection:s,reorderField:l}=Kt();d.useEffect(()=>{a({type:"update",state:Br(e.fields)})},[a,e.fields]);const m=d.useCallback(h=>{h.type==="SECTION"&&a({type:"hold",fieldId:h.draggableId})},[]),u=d.useCallback(h=>{const{source:g,destination:C,type:w,reason:p,draggableId:y}=h;if(a({type:"release"}),!C||p==="CANCEL")return;if(w==="ROOT"){s(o,y,g.index,C.index,e,r);return}if(w!=="SECTION")throw new Error("Unexpected droppable type.");const[x,I]=$r(e.fields,g.droppableId)??[],[b,S]=$r(e.fields,C.droppableId)??[];l(x,I,g.index,b,S,C.index,r)},[e,l,r,s,o]),f=d.useCallback(h=>{Oo(h+1,e,r)},[e,r]);return i.jsx(re.DragDropContext,{onDragStart:m,onDragEnd:u,children:i.jsx(re.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>i.jsxs("div",{className:"flex flex-col gap-0",ref:h.innerRef,...h.droppableProps,children:[e.fields.map((g,C)=>i.jsxs(d.Fragment,{children:[i.jsx(Vr,{field:g,index:C,dropState:o,fieldsOnly:n}),!n&&C!==e.fields.length-1&&i.jsxs(c.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{f(C)},children:[i.jsx(c.RiIcon,{icon:"RiAddLine"})," Add section"]})]},g.identifier)),i.jsxs(c.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{f(e.fields.length)},children:[i.jsx(c.RiIcon,{icon:"RiAddLine"})," Add section"]}),h.placeholder]})})})});kr.displayName="FieldsEditor";const Ko=()=>{alert("This is a form preview, your data will not be saved.")},Qo=d.memo(d.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:o,initialTitle:a,showExplainerText:s=!0,showFormTitle:l=!0,fieldsOnly:m=!1,showTabs:u=!0,tabsListClassName:f,hydrateRevisionWithImages:h}=t,{showError:g}=c.useToast(),C=d.useCallback(I=>{const b={};I.title||(b.title="Title is required."),(!I.fields||I.fields.length===0)&&(b.fields="At least one field is required.");let S=[];for(const[D,F]of I.fields.entries()){const A=cn.section.getFieldCreationSchema(yr(I.fields,D),`fields.${D}`).map(O=>O.field);S=[...S,...A];for(const[O,q]of F.fields.entries()){const z=cn[q.type].getFieldCreationSchema(`fields.${D}.fields.${O}`).map(X=>X.field);S=[...S,...z]}}const N=ht({fields:S},I);if(N&&(b.fields=N.fields),me(b))return g({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),b},[g]),w=d.useMemo(()=>({title:a??"",description:"",fields:[{...rt(Xt(null,"")),label:""}]}),[a]),p=o?h(o):void 0,y=V.useFormik({initialValues:Po(p)??w,validate:C,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),x=d.useMemo(()=>Ar(y.values),[y.values]);return i.jsx(c.Tabs.Root,{ref:n,defaultValue:"edit",children:i.jsxs("div",{className:"flex flex-col gap-2",children:[u&&i.jsxs(c.Tabs.List,{className:ve("sticky top-0 z-[2000] flex bg-(--color-background)",f),children:[i.jsx(c.Tabs.Trigger,{className:"grow",value:"edit",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),i.jsx(c.Tabs.Trigger,{className:"grow",value:"preview",children:i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),i.jsxs(c.Tabs.Content,{value:"edit",children:[s&&i.jsxs(c.Text,{children:["Create your form using various field types. Sections can be"," ",i.jsx("strong",{children:"conditionally rendered"})," based on"," ",i.jsx("strong",{children:"answers to fields in preceding sections. "})]}),i.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:mt,onSubmit:y.handleSubmit,children:[i.jsxs(V.FormikProvider,{value:y,children:[l&&i.jsxs(i.Fragment,{children:[i.jsx(ge,{name:"title",render:({setValue:I,value:b,meta:S})=>i.jsx(jt,{severity:"danger",helpText:S.error??null,children:i.jsx(c.Input.Root,{variant:"outline",size:"md",accentColor:S.error?de.danger:"primary",children:i.jsx(c.Input.Field,{placeholder:"Form title",value:b,onChange:N=>{I(N.target.value)},maxLength:100})})})}),i.jsx(ge,{name:"description",render:({setValue:I,value:b})=>i.jsx(c.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:b,onChange:S=>{I(S.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),i.jsx(kr,{fieldsOnly:m}),i.jsx("span",{"data-accent-color":de.danger,className:"text-xs text-(--accent-a11)",children:typeof y.errors.fields=="string"&&y.errors.fields})]}),i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&i.jsx(c.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),i.jsx(c.Button,{type:"submit",children:"Save form"})]})]})]}),i.jsx(c.Tabs.Content,{value:"preview",children:i.jsx(Or,{schema:x,onSubmit:Ko,hideTitle:!l})})]})})})),Yo=Object.values(ie.Colors),Jo=1;async function Zo(t,n,e,r){const o=t.getContext("2d",{}),a=new Image(r.width,r.height),s=new Image(r.width,r.height),l=new ie.DeferredPromise;return a.onload=function(){o.drawImage(a,0,0,r.width,r.height),s.src=URL.createObjectURL(e),s.onload=async function(){o.drawImage(s,0,0,r.width,r.height);const m=t.toDataURL("image/jpeg",Jo),u=await ie.fileToBlob(m),f=new File([u],n.name,{type:"image/jpeg"});l.resolve(f)}},a.src=URL.createObjectURL(n),l}const Ur=d.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:o,dirty:a,onDirty:s}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const l=d.useRef(null),m=d.useRef(null),[u,f]=d.useState(ie.Colors.red),[h,g]=d.useState(null),[C,w]=d.useState(!1),[p,y]=d.useState(!1),x=d.useRef(null),I=c.useSize(x);d.useEffect(()=>{const z=new Image;z.onload=function(){g({width:z.naturalWidth,height:z.naturalHeight})},z.src=URL.createObjectURL(n)},[n]),d.useEffect(()=>{!p&&(I!=null&&I.width)&&I.height&&y(!0)},[I,p]);const b=d.useCallback(async()=>{a||e();const z=l.current;if(!z)return;if(!h)throw new Error("Original image size not loaded yet");const X=await z.exportImage("png"),P=new Image(h.width,h.height);P.onload=async function(){const W=await ie.fileToBlob(X),le=new File([W],n.name,{type:n.type}),te=m.current,ce=await Zo(te,n,le,h);ce.objectURL=URL.createObjectURL(ce);const Oe=await ie.hashFile(n);await ie.hashFile(ce)!==Oe&&r(ce),w(!1),e()},w(!0),P.src=X},[a,n,e,r,h]),S=d.useCallback(()=>{o(n)},[n,o]),N=d.useCallback(()=>{e()},[e]),D=d.useCallback(()=>{s(!0)},[s]),F=d.useCallback(()=>{l.current&&l.current.redo()},[]),L=d.useCallback(()=>{l.current&&l.current.undo()},[]),A=d.useCallback(()=>{l.current&&(s(!1),l.current.clearCanvas())},[s]),O=d.useCallback(z=>{l.current&&l.current.eraseMode(z)},[]),q=d.useCallback(()=>{b()},[b]),ee=d.useCallback(()=>{kt.saveAs(n,n.name)},[n]);return i.jsx(zt,{open:!0,onOpenChange:e,children:i.jsxs(_t,{children:[i.jsx(Vt,{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":""}),i.jsxs($t,{className:"absolute inset-0 py-12","data-floating-content":"",children:[i.jsx(c.ButtonGroup,{className:"flex w-full gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",size:"md",variant:"soft",children:i.jsxs("div",{className:"grid w-full grid-cols-3",children:[i.jsxs("div",{className:"flex gap-2",children:[i.jsx(c.IconButton,{"aria-label":"close",onClick:N,children:i.jsx(c.RiIcon,{icon:"RiCloseLine"})}),i.jsx(c.IconButton,{"aria-label":`Download ${n.name}`,onClick:ee,children:i.jsx(c.RiIcon,{icon:"RiDownload2Line"})})]}),i.jsxs("div",{className:"flex items-center justify-center gap-2",children:[i.jsx(vt,{selectedColor:u,allColors:Yo,onFinish:f,trigger:i.jsx(c.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:u},children:" "})}),i.jsx(c.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:O,children:i.jsx(c.RiIcon,{icon:"RiEraserFill"})}),i.jsx(c.Separator,{orientation:"vertical",size:"full"}),i.jsx(c.IconButton,{"aria-label":"undo",onClick:L,children:i.jsx(c.RiIcon,{icon:"RiArrowGoBackLine"})}),i.jsx(c.IconButton,{"aria-label":"undo",onClick:F,children:i.jsx(c.RiIcon,{icon:"RiArrowGoForwardLine"})}),i.jsx(c.IconButton,{"aria-label":"undo all",onClick:A,children:i.jsx(c.RiIcon,{icon:"RiLoopLeftLine"})})]}),i.jsxs("div",{className:"flex justify-end gap-2",children:[i.jsx(c.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:q,children:i.jsx(c.RiIcon,{icon:"RiSaveLine"})}),i.jsx(c.IconButton,{"aria-label":"Delete attachment",onClick:S,children:i.jsx(c.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})}),h&&i.jsx("canvas",{id:"attachment-markup-canvas",className:"hidden",ref:m,width:h.width,height:h.height}),i.jsxs("div",{className:"relative size-full flex items-center justify-center p-4 overflow-hidden",children:[i.jsx("img",{className:"max-w-full max-h-full invisible absolute",alt:"Photo attachment",ref:x,src:n.objectURL}),C?i.jsx(c.Spinner,{}):i.jsx(Xr.ReactSketchCanvas,{className:"max-w-full max-h-full aspect-square",backgroundImage:n.objectURL,ref:l,onStroke:D,strokeColor:u},p?"1":"0")]})]})]})})});Ur.displayName="AttachmentEditor",E.BaseField=k,E.BaseFormElement=bt,E.BooleanField=xe,E.BooleanInput=Wt,E.ColorPicker=vt,E.DateField=tt,E.DateInput=qt,E.FieldSection=U,E.FileCard=yt,E.FileIcon=$e,E.FormBuilder=Qo,E.FormRenderer=Or,E.ImageCard=Lr,E.ImageMarkup=Ur,E.ImageViewer=Ut,E.ImageViewerProvider=fr,E.InputWithHelpText=jt,E.InputWithLabel=Y,E.InputWithLabelAndHelpText=J,E.MultiSelectField=_e,E.MultiSelectInput=Rt,E.MultiStringField=ze,E.MultiStringInput=Qt,E.NumberField=se,E.NumberInput=Yt,E.PatchField=ge,E.PatchFormProvider=qo,E.QrField=at,E.QrInput=Jt,E.QrScanner=Zt,E.SUPPORTED_IMAGE_FILE_TYPES=vn,E.SUPPORTED_PDF_FILE_TYPES=bn,E.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=yn,E.SelectField=Ve,E.SelectInput=en,E.StringField=lt,E.StringInput=tn,E.TextField=ct,E.TextInput=nn,E.decodeFormValues=ko,E.deserialize=ut,E.deserializeField=an,E.emptyBaseField=H,E.emptyBooleanField=hr,E.emptyDateField=pr,E.emptyMultiSelectField=Er,E.emptyMultiStringField=br,E.emptyNumberField=Cr,E.emptyQrField=Ir,E.emptySelectField=Sr,E.emptyStringField=Nr,E.emptyTextField=Fr,E.encodeFormValues=Uo,E.fieldIcons=Yr,E.flattenFields=sn,E.formRevisionToSchema=Ar,E.initialFormValues=pt,E.isConditionMet=ln,E.useFieldInput=Ht,E.useFieldInputs=Be,E.useFormikInput=G,E.useImageViewer=Ue,E.validateForm=ht,E.valueIsFile=ft,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|