@overmap-ai/forms 1.0.3 → 1.0.4-conditional-arrows.3

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.
@@ -1 +1 @@
1
- (function(x,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("formik"),require("react"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("lodash.get"),require("lodash.set")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","formik","react","@hello-pangea/dnd","@overmap-ai/core","lodash.get","lodash.set"],n):(x=typeof globalThis<"u"?globalThis:x||self,n(x.forms={},x.jsxRuntime,x.blocks,x.formik,x.React,x.dnd,x.core,x.get,x.set))})(this,function(x,n,s,D,c,U,F,J,ze){"use strict";var kt=Object.defineProperty;var Rt=(x,n,s)=>n in x?kt(x,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):x[n]=s;var m=(x,n,s)=>(Rt(x,typeof n!="symbol"?n+"":n,s),s);class je{constructor(i){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=i;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(i){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}}}class $ extends je{constructor(e){const{label:t,required:r,fieldValidators:o=[],formValidators:a=[],...u}=e;super(u);m(this,"required");m(this,"formValidators");m(this,"fieldValidators");m(this,"label");m(this,"onlyValidateAfterTouched",!0);this.label=t,this.required=r,this.fieldValidators=o,this.formValidators=a}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,t){if(this.required&&this.isBlank(e))return"This field is required.";for(const r of this.getFieldValidators()){const o=r(e);if(o)return o}if(t)for(const r of this.getFormValidators()){const o=r(e,t);if(o)return o}}_serialize(){return{...super._serialize(),label:this.label,required:this.required}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}}m($,"fieldTypeName"),m($,"fieldTypeDescription");const he={description:"_description_17zed_1"},N=l=>{const{label:i,children:e,severity:t,inputId:r,labelId:o,flexProps:a}=l;return n.jsx(s.Flex,{direction:"column",gap:"1",asChild:!0,...a,children:n.jsxs("label",{htmlFor:r,children:[n.jsx(s.Text,{severity:t,id:o,children:i}),e]})})},W=l=>{const{helpText:i,children:e,severity:t}=l;return n.jsxs(s.Flex,{direction:"column",gap:"1",children:[e,n.jsx(s.Flex,{direction:"column",children:n.jsx(s.Text,{size:"1",severity:t,className:he.description,children:i})})]})},j=l=>{const{id:i,field:e,formId:t,...r}=l,[o,a,u]=D.useField(e.getId()),{touched:d}=a,h=a.error??e.description,f=a.error?"danger":void 0,p=i??`${t}-${e.getId()}-input`,y=`${p}-label`,g=e.required?`${e.label} *`:e.label,v=c.useMemo(()=>({...o,onChange:C=>{const w=e.getValueFromChangeEvent(C);u.setValue(w,!1).then(),(d||!e.onlyValidateAfterTouched)&&u.setError(e.getError(w))},onBlur:C=>{u.setTouched(!0,!1).then(),u.setError(e.getError(e.getValueFromChangeEvent(C)))}}),[e,o,u,d]);return[{helpText:h,severity:f,inputId:p,labelId:y,label:g,fieldProps:v,helpers:u,field:e},{...r,"aria-labelledby":y}]},ht=[!0,"true"],He=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i),h=s.useSeverityColor(r),f=ht.includes(u.value);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:n.jsx(s.Checkbox,{...d,...u,id:e,color:h,value:f.toString(),checked:f,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),R=class R extends ${constructor(e){super({...e,type:"boolean"});m(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 R(e)}getInput(e){return n.jsx(He,{...e,field:this})}};m(R,"fieldTypeName","Checkbox"),m(R,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(R,"Icon",s.CheckCircledIcon);let Q=R;const Ue=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),f=s.useSeverityColor(r);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...h,...u,type:"number",id:e,min:d.minimum,max:d.maximum,step:d.integers?1:.1,color:f})})})}),_=class _ extends ${constructor(e){const{minimum:t=Number.MIN_SAFE_INTEGER,maximum:r=Number.MAX_SAFE_INTEGER,integers:o=!1,...a}=e;super({...a,type:"number"});m(this,"minimum");m(this,"maximum");m(this,"integers");this.minimum=t,this.maximum=r,this.integers=o}getValueFromChangeEvent(e){const t=Number.parseFloat(e.target.value);return Number.isNaN(t)?"":t}static getFieldCreationSchema(){return[new _({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:"minimum",formValidators:[this._validateMin]}),new _({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:"maximum",formValidators:[this._validateMax]}),new Q({label:"Integers",description:"Whole numbers only",required:!1,identifier:"integers"})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.minimum,r=this.maximum;return typeof t=="number"&&e.push(o=>{if(typeof o=="number"&&o<t)return`Must be at least ${this.minimum}.`}),typeof r=="number"&&e.push(o=>{if(typeof o=="number"&&o>r)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(o=>{if(typeof o=="number"&&!Number.isInteger(o))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new _(e)}getInput(e){return n.jsx(Ue,{field:this,...e})}};m(_,"fieldTypeName","Number"),m(_,"fieldTypeDescription","Allows specifying a number within a given range."),m(_,"Icon",s.FontFamilyIcon),m(_,"_validateMin",(e,t)=>typeof t.maximum=="number"&&typeof e=="number"&&t.maximum<e?"Minimum cannot be greater than minimum.":null),m(_,"_validateMax",(e,t)=>typeof t.minimum=="number"&&typeof e=="number"&&t.minimum>e?"Maximum cannot be less than minimum.":null);let G=_;const Ge=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i),h=s.useSeverityColor(r),f=u.value?u.value.split("T")[0]:"";return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...d,...u,type:"date",id:e,color:h,value:f})})})}),ee=class ee extends ${constructor(e){super({...e,type:"date"});m(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return new Date(e.target.value).toISOString()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new ee(e)}getInput(e){return n.jsx(Ge,{field:this,...e})}};m(ee,"fieldTypeName","Date"),m(ee,"fieldTypeDescription","Allows specifying a date."),m(ee,"Icon",s.CalendarIcon);let me=ee;class ge extends ${constructor(e){const{minLength:t,maxLength:r=5e3,...o}=e;super(o);m(this,"minLength");m(this,"maxLength");this.minLength=t?Math.max(t,0):void 0,this.maxLength=r?Math.max(r,0):5e3}static getFieldCreationSchema(){return[new G({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new G({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:"maximum_length",minimum:1,maximum:5e3,formValidators:[this._validateMax],integers:!0})]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(t=>{if(this.minLength&&(!t||t.length<this.minLength))return!this.required&&!t?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(t=>{if(typeof t=="string"&&this.maxLength&&t.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}}}m(ge,"_validateMin",(e,t)=>typeof t.maximum_length=="number"&&typeof e=="number"&&t.maximum_length<e?"Minimum cannot be greater than maximum.":null),m(ge,"_validateMax",(e,t)=>{if(typeof e!="number")return null;const{minimum_length:r}=t;return typeof r!="number"?null:r>e?"Maximum cannot be less than minimum.":null});const Ke=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),f=s.useSeverityColor(r);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...h,...u,type:d.inputType,id:e,color:f})})})}),te=class te extends ge{constructor(e){const{inputType:t="text",...r}=e,o=e.maxLength?Math.min(500,e.maxLength):500,a=e.minLength?Math.min(e.minLength,o):void 0;super({...r,maxLength:o,minLength:a,type:"string"});m(this,"inputType");this.inputType=t}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:t,minimum_length:r,input_type:o,...a}=e;return new te({...a,maxLength:t,minLength:r,inputType:o})}getInput(e){return n.jsx(Ke,{field:this,...e})}};m(te,"fieldTypeName","Short Text"),m(te,"fieldTypeDescription","Short text fields can hold up to 500 characters on a single line."),m(te,"Icon",s.InputIcon);let Z=te;const Ye=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextArea,{...d,...u,resize:"vertical",id:e,severity:r})})})}),ie=class ie extends ge{constructor(i){const e=i.maxLength?Math.min(5e3,i.maxLength):5e3,t=i.minLength?Math.min(i.minLength,e):void 0;super({...i,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=i;return new ie({...r,maxLength:e,minLength:t})}getInput(i){return n.jsx(Ye,{field:this,...i})}};m(ie,"fieldTypeName","Paragraph"),m(ie,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ie,"Icon",s.RowsIcon);let k=ie;const Qe=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),{onChange:f,onBlur:p}=u,y=c.useMemo(()=>d.options.map(v=>({value:v.value,itemContent:v.label})),[d.options]),g=c.useCallback(v=>{f(v),p(v)},[f,p]);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.Select,{items:y,...u,onValueChange:g,placeholder:"Select one...",id:e,severity:r,...h})})})}),ye=(l="",i=[])=>({type:"section",fields:i,identifier:l,label:null,condition:null,conditional:!1}),mt=l=>{if(!l)return;const i=l.fields;let e=[];const t=[];for(const r of i)r.type==="section"?(e.length>0&&(t.push(ye(`AUTO_section-${i.indexOf(r)}`,e)),e=[]),t.push(r)):e.push(r);return e.length>0&&t.push(ye("AUTO_section-last",e)),{...l,fields:t,description:l.description??""}};function Ee(l,i,e){const t=Array.from(l),[r]=t.splice(i,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function gt(l,i,e){const t=Array.from(l);return t[i]=e,t}function Xe(l,i,e){const t=Array.from(l??[]);return t.splice(i,0,e),t}function xe(l,i){const e=Array.from(l);return e.splice(i,1),e}const Je=(l,i)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(i)}-${e.getTime()}`},Ze=(l,i)=>{if(!i)return null;for(const e of l)if(e.type==="section"){const t=Ze(e.fields,i);if(t)return t}else if(e.identifier===i)return e;return null},ve=(l,i)=>l.filter((e,t)=>t<i).flatMap(e=>e.fields),ke=l=>l.flatMap(i=>i.type==="section"?[...i.fields.map(e=>e.label),i.label]:i.label).filter(i=>i!==null),Me=(l,i)=>{let e=1,t=`${l} (${e})`;for(;i.includes(t);)t=`${l} (${++e})`;return t},Re=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i),h=s.useSeverityColor(r),f=c.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:p,onBlur:y}=u,g=`${e}-droppable`,{disabled:v}=d,[I,S]=c.useState(""),[C,w]=c.useState(""),M=C||o,A=C?"red":h,b=c.useCallback(E=>{p(E),y(E)},[p,y]),P=c.useCallback(E=>{f.findIndex(O=>O.value===E.target.value.trim())>=0?w("All options must be unique"):E.target.value?w(""):w("Option cannot be empty"),S(E.target.value)},[S,f]),B=c.useCallback(()=>{if(C)return;if(!I.trim())return w("Option cannot be empty");const E=I.trim();b([...f,{value:E,label:E}]),S("")},[I,C,b,f]),X=c.useCallback(E=>{E.key==="Enter"&&(E.preventDefault(),B())},[B]),H=c.useCallback(E=>{b(xe(f,E))},[f,b]),Y=c.useCallback(E=>{if(!E.destination)return;const O=E.source.index,T=E.destination.index;b(Ee(f,O,T))},[b,f]);return n.jsx(U.DragDropContext,{onDragEnd:Y,children:n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:M,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:(!v||f.length===0)&&n.jsxs(s.Flex,{gap:"2",children:[n.jsx(s.Box,{grow:"1",children:n.jsx(s.TextField.Input,{placeholder:"Press enter to add a new option",...d,...u,value:I,onChange:P,onKeyDown:X,id:e,color:A,onBlur:void 0})}),n.jsx(s.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:B,children:n.jsx(s.PlusIcon,{})})]})})}),n.jsx(U.Droppable,{droppableId:g,children:E=>n.jsxs(s.Flex,{...E.droppableProps,ref:E.innerRef,direction:"column",children:[f.map((O,T)=>n.jsx(U.Draggable,{draggableId:`${O.value}-draggable`,index:T,isDragDisabled:v,children:({draggableProps:z,dragHandleProps:V,innerRef:L})=>n.jsx(s.Flex,{...V,...z,ref:L,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:n.jsxs(s.Badge,{color:"gray",size:"2",children:[n.jsx("span",{children:O.label}),n.jsx(s.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>H(T),children:n.jsx(s.Cross1Icon,{})})]})})},O.value)),E.placeholder]})})]})})}),ne=class ne extends ${constructor(e){const{minimum_length:t,maximum_length:r,...o}=e;super({...o,type:"multi-string"});m(this,"minLength");m(this,"maxLength");m(this,"onlyValidateAfterTouched",!1);this.minLength=t??0,this.maxLength=r??1/0}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return n.jsx(Re,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(t=>{if(Array.isArray(t)&&t.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(t=>{if(Array.isArray(t)&&t.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new ne(e)}};m(ne,"fieldTypeName","Multi-string"),m(ne,"fieldTypeDescription","Allows the user to provide multiple unique strings."),m(ne,"Icon",s.ListBulletIcon);let ae=ne;class et extends ${constructor(e){super(e);m(this,"options");m(this,"onlyValidateAfterTouched",!1);const t=new Set;this.options=e.options.map(r=>(typeof r=="string"&&(r={label:r,value:r}),t.add(r.label),r)),t.size!==e.options.length&&console.error(`${e.options.length-t.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options}}static getFieldCreationSchema(){return[new ae({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:"options",minimum_length:2,maximum_length:20})]}}const re=class re extends et{constructor(i){super({...i,type:"select"})}getValueFromChangeEvent(i){return typeof i=="string"?i:i.target.value}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="select")throw new Error("Type mismatch.");return new re(i)}getInput(i){return n.jsx(Qe,{field:this,...i})}};m(re,"fieldTypeName","Dropdown"),m(re,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(re,"Icon",s.DropdownMenuIcon);let de=re;const yt=l=>l?Array.isArray(l)?l:[l]:[],tt=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),{onChange:f,onBlur:p}=u,y=c.useMemo(()=>yt(u.value),[u.value]),g=c.useCallback(v=>{f(v),p(v)},[f,p]);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.MultiSelect,{value:y,onValueChange:g,options:d.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...h})})})}),se=class se extends et{constructor(i){super({...i,type:"multi-select"})}getValueFromChangeEvent(i){if(Array.isArray(i))return i;throw new Error("Expected an array.")}isBlank(i){return super.isBlank(i)||i.length===0}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="multi-select")throw new Error("Type mismatch.");return new se(i)}getInput(i){return n.jsx(tt,{field:this,...i})}};m(se,"fieldTypeName","Multi-select"),m(se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(se,"Icon",s.CheckboxIcon);let ce=se;const xt=c.memo(function({field:i,...e}){const[{value:t}]=D.useField(i.options.clonedFieldIdentifier),r=c.useMemo(()=>{const o=i.options.getFieldToClone(t);return o?ue(o):null},[i.options,t]);return fe(r,e)});class we extends ${constructor(e,t){super({...e,type:"custom"});m(this,"Component");m(this,"options");this.options=e,this.Component=t}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const t=this.Component;return n.jsx(t,{field:this,...e})}}m(we,"fieldTypeName","Custom"),m(we,"fieldTypeDescription","Allows re-rendering of field already in the form");class vt extends we{constructor(i){super(i,xt)}}const wt=c.memo(function(i){const{field:e,...t}=i,{label:r,description:o,fields:a,condition:u}=e,{values:d,setFieldValue:h}=D.useFormikContext(),f=u!=null&&u.identifier?J(d,u.identifier):void 0,p=c.useMemo(()=>$e(u,f),[u,f]);c.useEffect(()=>{if(!p)for(const g of a)h(g.getId(),"").then()},[p,a,h]);const y=Be(a,t);return p?r?n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:"column",gap:"3",children:[n.jsxs(s.Flex,{direction:"column",children:[n.jsx(s.Heading,{as:"h3",size:"3",children:r}),n.jsx(s.Text,{className:he.description,children:o})]}),y]})}):y:null}),oe=class oe extends je{constructor(e){const{label:t=null,fields:r,condition:o=null,conditional:a,...u}=e;super({...u,type:"section"});m(this,"label");m(this,"fields");m(this,"condition");this.fields=r,this.condition=o,this.label=t,a===!1&&(this.condition=null)}static getFieldCreationSchema(e){return e.length===0?[]:[new Q({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new oe({label:"Conditional settings",identifier:"conditional-settings",condition:{identifier:"conditional",value:!0},fields:[new de({label:"Field",description:"The field to use for the condition.",options:e.map(t=>!t.label||t.type==="upload"?null:{label:t.label,value:t.identifier}).filter(t=>!!t),identifier:"condition.identifier",required:!0}),new vt({label:"Value",identifier:"condition.value",required:!0,clonedFieldIdentifier:"condition.identifier",getFieldToClone(t){if(!t)return null;const r=e.find(o=>o.identifier===t);return r?{...r,label:"Value",identifier:"condition.value",description:"The value to compare against.",required:r.type!=="boolean"}:(console.error("Could not find field with identifier",t),null)}})]})]}static deserialize(e){var r;if(e.type!=="section")throw new Error("Invalid type");const t=((r=e.fields)==null?void 0:r.map(De))??[];return new oe({...e,fields:t})}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 t={};for(const r of this.fields){const o=r.getId(),a=r.getError(J(e,o),e);a&&ze(t,r.getId(),a)}return t}getInput(e){return n.jsx(wt,{field:this,...e})}};m(oe,"fieldTypeName","Section"),m(oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let K=oe;const Ft={previewImage:"_previewImage_1ig84_1"},Ae=l=>{const i=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<i.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:i[t]}).format(e)},It=c.memo(function(i){var A;const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),{onChange:f}=u,p=s.useSeverityColor(r),y=c.useRef(null),{value:g}=u,v=c.useMemo(()=>o||(d.maxFileSize?`Maximum file size: ${Ae(d.maxFileSize)}`:null),[d.maxFileSize,o]),I=c.useCallback(()=>{var b;(b=y.current)==null||b.click()},[]),S=c.useCallback(b=>{const P=[...g];P.splice(b,1),f({target:{files:P}})},[g,f]),C=g?"Select new files":"Select files",w=g?"Select new file":"Select a file",M=d.maxFiles>1?C:w;return n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:v,severity:r,children:n.jsxs(N,{severity:r,inputId:e,labelId:t,label:a,children:[n.jsx(s.Flex,{direction:"row",gap:"2",children:n.jsx(s.Box,{width:"max-content",asChild:!0,children:n.jsxs(s.Button,{...h,onClick:I,children:[n.jsx(s.UploadIcon,{})," ",M]})})}),n.jsx("input",{...h,type:"file",ref:y,id:e,accept:(A=d.extensions)==null?void 0:A.join(","),multiple:d.maxFiles>1,color:p,style:{display:"none"},...u,value:""})]})}),Array.isArray(g)&&g.length>0&&n.jsx(s.Flex,{direction:"column",gap:"2",children:g.map((b,P)=>n.jsx(bt,{field:d,file:b,onRemove:()=>S(P),disabled:h.disabled},P))})]})}),bt=c.memo(function({file:i,field:e,onRemove:t,disabled:r}){const[o,a]=c.useState(null),u=c.useMemo(()=>o&&e.getError([o]),[e,o]),{url:d,name:h,size:f}=c.useMemo(()=>{let p=null,y,g;return o!=null&&o.type.startsWith("image/")&&(p=URL.createObjectURL(o)),o?(y=o.name,g=Ae(o.size)):(y="Downloading...",g="..."),{url:p,name:y,size:g}},[o]);return c.useEffect(()=>{i instanceof Promise?i.then(a):a(i)},[i]),n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[n.jsxs(s.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[n.jsx(s.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${h}`,disabled:r,onClick:t,children:n.jsx(s.Cross1Icon,{})}),n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsx(s.Text,{children:h}),n.jsx(s.Text,{size:"1",children:f}),u&&n.jsx(s.Text,{size:"1",severity:"danger",children:u})]})]}),d&&n.jsx("img",{className:Ft.previewImage,src:d,alt:h})]})})}),it=50*1024*1024,le=class le extends ${constructor(e){const{extensions:t,maximum_files:r,maximum_size:o,...a}=e;super({...a,type:"upload"});m(this,"extensions");m(this,"maxFileSize");m(this,"maxFiles");m(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof o=="number"?o:void 0,this.maxFiles=Math.max(typeof r=="number"?r:1,1),this.extensions=t}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(){return[new G({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:"maximum_files"}),new G({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum:it,integers:!0}),new ce({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:"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)"}]})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.maxFileSize??it,r=this.maxFiles??1;return e.push(o=>{if(o&&o.some(a=>a.size>t))return`Files must be at most ${Ae(t)}.`}),e.push(o=>{if(o&&o.length>r)return`You can only upload ${r} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new le(e)}getInput(e){return n.jsx(It,{field:this,...e})}};m(le,"fieldTypeName","Upload"),m(le,"fieldTypeDescription","Allows a file to be uploaded."),m(le,"Icon",s.UploadIcon);let Pe=le;const Le={date:me,number:G,boolean:Q,select:de,string:Z,text:k,custom:we,upload:Pe,"multi-string":ae,"multi-select":ce},De=l=>{const i=l.type;return Le[i].deserialize(l)},ue=l=>l.type==="section"?K.deserialize(l):De(l);function Ve(l,i={}){const{readonly:e=!1}=i;return{title:l.title,description:l.description,fields:l.fields.map(t=>ue(t)),meta:{readonly:e}}}function Fe(l){return!!(Array.isArray(l)&&l.some(i=>i instanceof File||i instanceof Promise))}function $e(l,i){if(!l)return!0;if(Fe(i)||Fe(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(i)?i.map(r=>typeof r=="string"?r:r.value):i,t=Array.isArray(l.value)?l.value.map(r=>typeof r=="string"?r:r.value):l.value;if(Array.isArray(t)&&Array.isArray(e)){for(const r of t)if(!e.includes(r))return!1;return!0}return t===i}const fe=(l,i)=>c.useMemo(()=>!i||!l?null:l.getInput(i),[l,i]),Be=(l,i)=>{const e=c.useMemo(()=>l.map(t=>n.jsx("div",{children:t.getInput(i)},t.getId())),[l,i]);return n.jsx(s.Flex,{direction:"column",gap:"2",children:e})},Ie=l=>Object.keys(l).length>0,nt=async(l,i)=>{const e={};for(const t of l.fields)if(t instanceof K){if(t.condition){const{identifier:r}=t.condition;if(!$e(t.condition,J(i,r)))continue}Object.assign(e,t.getErrors(i))}else{if(!(t instanceof $))throw new Error("Invalid field type");const r=t.getId(),o=t.getError(J(i,r),i);o&&ze(e,r,o)}if(Ie(e))return e},Ct=[null,void 0],_e=(l,i)=>l.reduce((e,t)=>t instanceof K?{...e,..._e(t.fields,i)}:(Ct.includes(J(e,t.getId()))&&ze(e,t.getId(),""),e),i),Tt=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},be=c.memo(c.forwardRef((l,i)=>{const{schema:e,values:t={},onSubmit:r=Tt,submitText:o="Submit",cancelText:a,onCancel:u,onDirty:d,hideTitle:h=!e.title,hideDescription:f,className:p}=l,{readonly:y}=e.meta,g=c.useMemo(()=>crypto.randomUUID(),[]),v=D.useFormik({initialValues:_e(e.fields,t),onSubmit:r,validate:M=>nt(e,M),validateOnBlur:!1,validateOnChange:!1}),{dirty:I}=v,S=c.useMemo(()=>typeof e.title=="string"?n.jsx(s.Heading,{children:e.title}):e.title,[e.title]),C=c.useMemo(()=>typeof e.description=="string"?n.jsx(s.Text,{className:he.description,children:e.description}):e.description,[e.description]),w=Be(e.fields,{formId:g,disabled:y});return c.useEffect(()=>{I&&d&&d()},[I,d]),n.jsx(D.FormikProvider,{value:v,children:n.jsx(s.Flex,{ref:i,direction:"column",gap:"2",className:p,asChild:!0,children:n.jsxs("form",{id:g,onSubmit:v.handleSubmit,children:[!h&&n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[S,!f&&C]})}),w,!y&&n.jsxs(s.Flex,{justify:"end",gap:"2",children:[a&&n.jsx(s.Button,{type:"button",variant:"soft",onClick:u,children:a}),n.jsx(s.Button,{type:"submit",disabled:!v.isValid,children:o})]})]})})})})),St=c.memo(c.forwardRef((l,i)=>{const{submission:e,showFormDescription:t=!1,showFormTitle:r=!0}=l,o=F.useAppSelector(F.selectFormRevision(e.form_revision)),{sdk:a}=F.useSDK();if(!o)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const u=c.useMemo(()=>Ve(o,{readonly:!0}),[o]),d=c.useMemo(()=>{const h=F.selectSubmissionAttachments(e.offline_id)(a.store.getState())??[],f={};for(const p of h){const y=a.files.fetchFileFromUrl(p.file,p.file_sha1,p.file_name).then(v=>{if(!v.success)throw new Error(`Failed to download attachment ${p.file_name}.`);return v.body}),g=f[p.field_identifier];g?g.push(y):f[p.field_identifier]=[y]}return{...e.values,...f}},[a.files,a.store,e.offline_id,e.values]);return n.jsx(be,{ref:i,schema:u,values:d,hideDescription:!t,hideTitle:!r})})),rt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},Oe="organization:",qe="user:",zt=c.memo(c.forwardRef((l,i)=>{const{maxResults:e=20,...t}=l,[r,o]=c.useState(""),[a,u]=c.useState(""),{sdk:d}=F.useSDK(),h=c.useMemo(()=>{const w={maxResults:e,searchTerm:r};return a&&(a.startsWith(Oe)?w.owner_organization=parseInt(a.slice(Oe.length)):a.startsWith(qe)&&(w.owner_user=parseInt(a.slice(qe.length)))),w},[r,e,a]),f=F.useAppSelector(F.selectFilteredUserForms(h))??[],p=F.useAppSelector(F.selectUserFormMapping),y=c.useCallback(w=>{w.favorite?d.userForms.unfavorite(w.offline_id).then():d.userForms.favorite(w.offline_id).then()},[d]),g=c.useMemo(()=>{const w=d.store.getState(),M={};for(const A of Object.values(p)){const b=F.selectOrganization(A.owner_organization||-1)(w);b&&(M[`${Oe}${b.id}`]=b.name);const P=F.selectUser(A.owner_user||-1)(w);P&&(M[`${qe}${P.id}`]=P.username)}return Object.entries(M).map(([A,b])=>({itemContent:b,value:A}))},[p,d.store]),v=c.useCallback(w=>{o(w.currentTarget.value)},[]),S=(F.useAppSelector(F.selectNumberOfUserForms)||0)-f.length,C=f.length==e&&S>0?`Only the first ${e} results are shown (${S} hidden)`:S>0&&`${S} hidden forms`;return n.jsxs(s.Flex,{ref:i,direction:"column",gap:"2",children:[n.jsxs(s.Flex,{gap:"2",grow:"1",children:[n.jsx(s.Box,{grow:"1",asChild:!0,children:n.jsx(s.TextField.Root,{size:"3",children:n.jsx(s.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),n.jsx(s.Select,{items:g,value:a,onValueChange:u,placeholder:"Owner",size:"large"})]}),f.length>0&&n.jsx(s.ButtonList.Root,{children:f.map(w=>n.jsx(Et,{...t,form:w,handleToggleFavorite:()=>y(w)},w.offline_id))}),n.jsx(s.Box,{px:"3",children:n.jsx(s.Text,{size:"2",severity:"info",children:C})})]})})),Et=l=>{var y;const{form:i,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,o=(y=F.useAppSelector(F.selectOrganization(i.owner_organization||-1)))==null?void 0:y.name,a=F.useAppSelector(F.selectUser(i.owner_user||-1)),u=F.useAppSelector(F.selectCurrentUser).id,d=!!a&&a.id===u,h=o??(d?"You":a==null?void 0:a.username)??"Unknown",f=c.useCallback(g=>{g.stopPropagation(),r()},[r]),p=n.jsx(s.ButtonList.Item,{onClick:()=>e(i),asChild:!0,children:n.jsxs(s.Flex,{justify:"between",gap:"2",py:"2",px:"3",...s.divButtonProps,children:[n.jsxs(s.Flex,{grow:"1",align:"center",gap:"2",children:[n.jsx(s.IconButton,{className:F.classNames(i.favorite?rt.favoriteIcon:rt.regularIcon),variant:"ghost",onClick:f,"aria-label":i.favorite?"Favorite form":"Standard form",disabled:!t,children:i.favorite?n.jsx(s.StarFilledIcon,{}):n.jsx(s.StarIcon,{})}),n.jsx(s.Text,{noWrap:!0,children:i.latestRevision.title}),i.latestRevision.description&&n.jsx(s.QuestionMarkCircledIcon,{})]}),h&&n.jsxs(s.Flex,{align:"center",gap:"2",children:[n.jsx(s.PersonIcon,{})," ",h]})]})});return i.latestRevision.description?n.jsx(s.Tooltip,{content:i.latestRevision.description,children:p},i.offline_id):p},st={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Mt=c.memo(function(i){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:o,rowDecorator:a}=i,u=F.useAppSelector(F.selectCurrentUser),d=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:u.id)),h=Ne(e),f=F.isToday(h)?h.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):F.getLocalDateString(h),p=F.useAppSelector(F.selectFormRevision(e.form_revision));if(!p)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const y=(w=F.useAppSelector(F.selectLatestFormRevision(p.form)))==null?void 0:w.revision,g=F.useFileSrc({file:(d==null?void 0:d.profile.file)??null,fileSha1:(d==null?void 0:d.profile.file_sha1)??null}),v=(d==null?void 0:d.username.charAt(0).toUpperCase())??"?",I=p.revision===y,S=c.useCallback(()=>{t&&t({submission:e})},[e,t]),C=n.jsx(s.ButtonList.Item,{onClick:S,asChild:!0,children:n.jsxs(s.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[n.jsxs(s.Flex,{gap:"2",align:"center",className:st.stopHorizontalOverflow,children:[n.jsx(s.Avatar,{src:g,size:"1",fallback:v}),n.jsx(s.Text,{size:"2",noWrap:!0,children:o==="creator"?(d||u).username:p.title})]}),n.jsxs(s.Flex,{gap:"2",align:"center",children:[!r&&(p.revision?n.jsx(s.Badge,{variant:"soft",severity:I?"primary":"info",children:r?p.revision.toString():`Revision #${p.revision}`}):!!y&&n.jsx(s.Badge,{children:"Original"})),n.jsx(s.Text,{size:"2",noWrap:!0,children:f})]})]})});return a?a(e,C):C}),Ne=l=>{const i="created_at"in l?l.created_at:l.submitted_at;return new Date(i)},At=c.memo(function(i){const{formId:e,submissions:t,compact:r=!1,className:o,after:a,variant:u="outline",...d}=i;if(!!e==!!t)throw new Error("Either formId or submissions must be provided, but not both.");const h=F.useAppSelector(t?()=>t:F.selectSubmissionsForForm(e)),f=c.useMemo(()=>h==null?void 0:h.sort((p,y)=>Ne(y).getTime()-Ne(p).getTime()),[h]);return n.jsx(s.ButtonList.Root,{className:F.classNames(st.submissionsContainer,o),size:"small",variant:u,before:!r&&n.jsxs(s.Text,{severity:"info",children:["There are ",((h==null?void 0:h.length)||0).toString()," submissions of this form."]}),after:a,children:f==null?void 0:f.map((p,y)=>n.jsx(Mt,{submission:p,compact:r,...d},y))})}),Pt=c.memo(function(i){const{name:e,render:t}=i,{submitForm:r}=D.useFormikContext(),[o,a,u]=D.useField(e);return c.useMemo(()=>{const d=h=>u.setValue(h,!1);return t({value:o.value,setValue:d,patchValue:r})},[r,u,o.value,t])}),Lt=c.memo(c.forwardRef((l,i)=>{const{children:e,schema:t,values:r,onPatch:o,onError:a,...u}=l,d=c.useMemo(()=>_e(t.fields,r),[t.fields,r]),h=c.useCallback(v=>{const I={};for(const S in v){const C=v[S];C!==d[S]&&C!==void 0&&(I[S]=C)}Ie(I)&&o(I)},[d,o]),f=c.useCallback(async v=>{const I=await nt(t,v);return I&&a(I),I},[t,a]),p=D.useFormik({initialValues:d,onSubmit:h,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:y,resetForm:g}=p;return c.useEffect(()=>{Ie(y)&&g({values:d,errors:{}})},[y,d,g]),n.jsx(D.FormikProvider,{value:p,children:n.jsx("form",{...u,ref:i,onSubmit:p.handleSubmit,children:e})})})),ot={...Le,section:K},Dt=c.memo(function(i){const{field:e,setFieldType:t}=i,r=e.fieldTypeName,o=e.fieldTypeDescription,a=e.Icon;return n.jsxs(s.Flex,{gap:"4",align:"center",children:[n.jsx(s.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:n.jsxs(s.Flex,{gap:"3",align:"center",grow:"1",children:[n.jsx(a,{}),r]})}),n.jsx(s.Text,{children:o})]})}),lt=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],Vt=lt.length-1,$t=c.memo(function(i){const{setFieldType:e}=i;return n.jsx(s.Flex,{direction:"column",gap:"3",children:lt.map((t,r)=>n.jsxs(s.Flex,{direction:"column",gap:"3",children:[n.jsx(s.Flex,{direction:"column",gap:"2",children:t.map(o=>n.jsx(Dt,{field:Le[o],setFieldType:()=>e(o)},o))}),r<Vt&&n.jsx(s.Separator,{size:"4"})]},r))})}),Bt=l=>i=>{if(!(!i||typeof i!="string")&&l.includes(i.trim()))return"This name is already taken."},_t=(l,i)=>{const e=[new Z({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[Bt(l)]}),new k({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return i==="section"?e:[...e,new Q({label:"Required",description:null,required:!1,identifier:"required"})]},Ot=c.memo(function(i){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:o,conditionalSourceFields:a}=i,u=ot[e],d=D.useFormikContext(),h=c.useMemo(()=>{const f=ke(d.values.fields).filter(y=>y!==(o==null?void 0:o.label));let p=_t(f,e);if(u===K){if(a===void 0)throw new Error("Conditional source fields must be provided when changing sections.");p=p.concat(u.getFieldCreationSchema(a))}else{if(!(u.prototype instanceof $))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);p=[...p,...u.getFieldCreationSchema()]}return{fields:p,meta:{readonly:!1},title:null}},[d.values.fields,e,u,o==null?void 0:o.label,a]);return n.jsx(be,{schema:h,values:o,onSubmit:r,cancelText:o?void 0:"Back",onCancel:t})}),pe=c.memo(function(i){const{parentPath:e,index:t,children:r,initial:o,editing:a,conditionalSourceFields:u}=i,[d,h]=c.useState(),f=(o==null?void 0:o.type)??d,p=f?ot[f].fieldTypeName:void 0,{setFieldValue:y,values:g}=D.useFormikContext();if(a&&!o)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!a&&!o,I=v?"Choose a field type":`${p} settings`,S=v?"Select a field type to add to this section.":(p==null?void 0:p.toLowerCase())==="section"?"Customize your section":`Customize your ${p==null?void 0:p.toLowerCase()} field.`,C=c.useCallback(()=>h(void 0),[]),w=c.useCallback(b=>{h(void 0),b()},[]),M=c.useCallback((b,P)=>{const{label:B}=b;if(!f)throw new Error("Field type must be selected before creating a field.");if(!B||typeof B!="string")throw new Error("Label must be provided before creating a field.");const X=ue({type:f,...b,identifier:Je(b.identifier,B)}).serialize(),H=J(g,e);if(H===void 0)throw new Error("Parent path must point to an existing field.");let Y;if(!Array.isArray(H))throw new Error("Parent path must point to an array.");a?Y=gt(H,t,X):Y=Xe(H,t,X),y(e,Y).then(),P()},[a,f,g,e,y,t]),A=c.useCallback(b=>v?n.jsx($t,{setFieldType:h}):n.jsx(Ot,{conditionalSourceFields:u,handleCancel:C,handleCreateField:P=>M(P,b),fieldType:f,defaultField:o}),[u,C,M,o,v,f]);return n.jsx(s.Dialog,{onCloseInterrupt:w,title:I,description:S,content:A,children:r})}),at=({children:l})=>n.jsx(n.Fragment,{children:l}),dt=(l,i)=>({initial:l?i:"none",sm:l?"none":i}),ct=c.memo(function(i){const{remove:e,dragHandleProps:t,editProps:r,insertAfterProps:o,duplicateProps:a}=i,u=c.useMemo(()=>[{Wrapper:pe,wrapperProps:r,Icon:s.Pencil1Icon,text:"Edit"},{Icon:s.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:pe,wrapperProps:a,Icon:s.CopyIcon,text:"Duplicate"},{Wrapper:pe,wrapperProps:o,Icon:s.PlusIcon,text:"Add after"},{Icon:d=>n.jsx("div",{...d,children:n.jsx(s.DragHandleDots2Icon,{})}),text:"Reorder",disableOnMobile:!0,buttonProps:{...t,asChild:!0}}],[t,a,r,o,e]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Flex,{gap:"4",display:dt(!1,"flex"),children:u.map(d=>{const h=d.Wrapper??at;return n.jsx(h,{...d.wrapperProps,children:n.jsx(s.IconButton,{type:"button",variant:"ghost","aria-label":d.text,...d.buttonProps,children:n.jsx(d.Icon,{})})},d.text)})}),n.jsx(s.Box,{display:dt(!0,"block"),children:n.jsx(s.DropdownMenu,{trigger:n.jsx(s.IconButton,{variant:"ghost","aria-label":"Actions menu",children:n.jsx(s.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(d=>{var f;if(d.disableOnMobile)return null;const h=d.Wrapper??at;return{...d.buttonProps,onSelect:(f=d.buttonProps)==null?void 0:f.onClick,content:n.jsx(h,{...d.wrapperProps,children:n.jsxs(s.Flex,{gap:"2",align:"center",children:[n.jsx(d.Icon,{}),d.text]})})}}).filter(d=>d!==null)})})]})}),Ce="form-builder",qt=c.memo(function(i){const{field:e,index:t,sectionIndex:r,takenLabels:o,remove:a}=i,u=c.useMemo(()=>ue(e),[e]),d=fe(u,{formId:Ce,disabled:!0}),h=c.useCallback(g=>{if(g.label===null)throw new Error(`Expected a label for field ${g.identifier}`);return{...g,label:Me(g.label,o),identifier:""}},[o]),f=c.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),p=c.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:h(e)}),[h,e,t,r]),y=c.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:g=>n.jsx(s.Card,{ref:g.innerRef,...g.draggableProps,...g.dragHandleProps,mb:"4",children:n.jsxs(s.Flex,{gap:"4",justify:"between",align:"center",children:[d,n.jsx(ct,{remove:a,editProps:f,duplicateProps:p,insertAfterProps:y,dragHandleProps:g.dragHandleProps})]})})})}),Nt=c.memo(function(i){var P,B,X,H,Y,E,O;const{field:e,index:t,dropState:r}=i,o=(P=r[e.identifier])==null?void 0:P.disabled,{setFieldValue:a,values:u}=D.useFormikContext(),d=s.useAlertDialog(),h=ke(u.fields),f=c.useCallback((T,z)=>{for(const V of T){const L=z.indexOf(V);a(`fields.${L}.condition`,null).then(),a(`fields.${L}.conditional`,!1).then()}},[a]),p=c.useCallback(T=>{var L;const z=e.fields[T];if(!z)throw new Error("Could not find field to remove.");const V=[];for(const q of u.fields)((L=q.condition)==null?void 0:L.identifier)===z.identifier&&V.push(q);return{removing:z,affectedSections:V,action:()=>a(`fields.${t}.fields`,xe(e.fields,T))}},[e.fields,u.fields,a,t]),y=c.useCallback(T=>{const{affectedSections:z,action:V,removing:L}=p(T),q=()=>{V().then(),f(z,u.fields)};if(z.length>0){const We=z.map(Te=>Te.label).join(", ");return d({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${We} section(s).`,severity:"danger",actionText:"Remove",onAction:q})}q()},[p,f,u.fields,d]),g=c.useCallback(()=>{const z=e.fields.map((Se,Zt)=>p(Zt)).flatMap(Se=>Se.affectedSections),V=z.length?"Remove fields and conditions?":"Remove fields?",L=e.fields.length,q=z.map(Se=>Se.label).join(", "),We=z.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${q}`:`Deleting this section will remove the ${L} field(s) it contains.`,Te=xe(u.fields,t),pt=()=>a("fields",Te);if(z.length>0)return d({title:V,description:We,severity:"danger",actionText:"Remove",onAction:()=>{pt().then(()=>{f(z,Te)})}});pt().then()},[e.fields,u.fields,t,p,a,d,f]),v=c.useCallback(T=>{if(T.label===null)throw new Error(`Expected a label for field ${T.identifier}`);const z=Me(T.label,h),V=T.fields.map(L=>{const q=Me(L.label,h);return{...L,label:q,identifier:Je(void 0,q)}});return{...T,label:z,fields:V,identifier:""}},[h]),I=c.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:ve(u.fields,t)}),[e,t,u.fields]),S=c.useMemo(()=>({index:t+1,parentPath:"fields",initial:ye(),conditionalSourceFields:ve(u.fields,t+1)}),[t,u.fields]),C=c.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),w=c.useMemo(()=>({index:t+1,parentPath:"fields",initial:v(e),conditionalSourceFields:ve(u.fields,t+1)}),[v,e,t,u.fields]),M=c.useMemo(()=>{var T,z;return(z=Ze(u.fields,(T=e.condition)==null?void 0:T.identifier))==null?void 0:z.label},[(B=e.condition)==null?void 0:B.identifier,u.fields]),A=Array.isArray((X=e.condition)==null?void 0:X.value)?"contains all of":"equals";if(Fe((H=e.condition)==null?void 0:H.value))throw new Error("File values are not supported for conditions.");const b=Array.isArray((Y=e.condition)==null?void 0:Y.value)?(E=e.condition)==null?void 0:E.value.map(T=>typeof T=="string"?T:T.label).join(", "):(O=e.condition)==null?void 0:O.value.toString();return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:T=>n.jsx(s.Card,{ref:T.innerRef,...T.draggableProps,...T.dragHandleProps,mb:"4",children:n.jsxs(s.Flex,{gap:"3",justify:"between",align:"center",children:[n.jsxs(s.Flex,{direction:"column",gap:"2",grow:"1",children:[n.jsxs(s.Flex,{direction:"column",children:[n.jsx(s.Heading,{as:"h3",size:"3",children:e.label}),n.jsx(s.Text,{className:he.description,children:e.description})]}),e.condition&&n.jsx(s.Text,{size:"1",children:n.jsxs(s.Em,{children:["Display only if ",n.jsx(s.Strong,{children:M})," ",A," ",n.jsx(s.Strong,{children:b})]})}),n.jsx(U.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:o,children:z=>n.jsxs(s.Flex,{ref:z.innerRef,...z.droppableProps,direction:"column",gap:"0",children:[e.fields.map((V,L)=>n.jsx(qt,{field:V,index:L,sectionIndex:t,remove:()=>y(L),takenLabels:h},V.identifier)),z.placeholder,n.jsx(pe,{...C,children:n.jsxs(s.Button,{type:"button",variant:"outline",children:[n.jsx(s.PlusIcon,{})," Add a field"]})})]})})]}),n.jsx(ct,{remove:g,insertAfterProps:S,dragHandleProps:T.dragHandleProps,editProps:I,duplicateProps:w})]})})})}),Wt=(l,i)=>{var t;const e={...l};switch(i.type){case"release":for(const r in e)e[r].disabled=!1;return e;case"hold":for(const r in e)(t=e[r])!=null&&t.conditionFields.has(i.fieldId)&&(e[r].disabled=!0);return e;case"update":return i.state}},jt=(l,i)=>{if(i)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===i)return e}}},ut=l=>{var e,t,r;const i={};for(let o=0;o<l.length;o++){const a=l[o];if(!a)throw new Error("Field is undefined.");const u=o>0?(e=i[l[o-1].identifier])==null?void 0:e.conditionFields:void 0,d=new Set(u);(t=a.condition)!=null&&t.identifier&&d.add(a.condition.identifier),i[a.identifier]={disabled:!1,conditionFields:d,conditionIndex:jt(l,(r=a.condition)==null?void 0:r.identifier),index:o,label:a.label}}return i},ft=(l,i)=>{for(const[e,t]of Object.entries(l))if(t.identifier===i)return[t,e]},Ht=c.memo(function(){const{values:i,setFieldValue:e}=D.useFormikContext(),[t,r]=c.useReducer(Wt,i.fields,ut),{showInfo:o}=s.useToast();c.useEffect(()=>{r({type:"update",state:ut(i.fields)})},[r,i.fields]);const a=c.useCallback(h=>{h.type==="SECTION"&&r({type:"hold",fieldId:h.draggableId})},[]),u=c.useCallback(h=>{const{source:f,destination:p,type:y,reason:g,draggableId:v}=h;if(r({type:"release"}),!p||g==="CANCEL")return;if(y==="ROOT"){const M=t[v];if(!M)throw new Error("Could not find section context.");let A=typeof M.conditionIndex<"u"?Math.max(M.conditionIndex+1,p.index):p.index;for(const b of Object.values(t))b.conditionIndex===f.index&&(A=Math.min(A,b.index-1));return A!=p.index&&o({title:"Reordered sections",description:"Sections with conditions must be below the fields they reference."}),e("fields",Ee(i.fields,f.index,A))}if(y!=="SECTION")throw new Error("Unexpected droppable type.");const[I,S]=ft(i.fields,f.droppableId)??[],[C,w]=ft(i.fields,p.droppableId)??[];if(!(I!=null&&I.fields)||!C)throw new Error("Could not find section with fields.");if(I.identifier===C.identifier)e(`fields.${S}.fields`,Ee(I.fields,f.index,p.index)).then();else{const M=I.fields[f.index];if(!M)throw new Error("Could not find field to reorder.");e(`fields.${S}.fields`,xe(I.fields,f.index)).then(),e(`fields.${w}.fields`,Xe(C.fields,p.index,M)).then()}},[i.fields,e,t,o]),d=c.useMemo(()=>({index:i.fields.length,parentPath:"fields",initial:ye(),conditionalSourceFields:ve(i.fields,i.fields.length)}),[i.fields]);return n.jsx(U.DragDropContext,{onDragStart:a,onDragEnd:u,children:n.jsx(U.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>n.jsxs(s.Flex,{ref:h.innerRef,...h.droppableProps,direction:"column",gap:"0",children:[i.fields.map((f,p)=>n.jsx(Nt,{field:f,index:p,dropState:t},f.label)),h.placeholder,n.jsx(pe,{...d,children:n.jsxs(s.Button,{type:"button",variant:"outline",children:[n.jsx(s.PlusIcon,{})," Add a section"]})})]})})})}),Ut={title:"",description:"",fields:[]},Gt=new Z({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Kt={formId:Ce,placeholder:"Give your form a title."},Yt=new k({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),Qt={formId:Ce,placeholder:"Explain the purpose of this form."},Xt=()=>{alert("This is a form preview, your data will not be saved.")},Jt=c.memo(c.forwardRef((l,i)=>{const{onCancel:e,onSave:t,revision:r}=l,o=r?"Edit form":"Create a new form",{heading:a=o}=l,u=c.useCallback(g=>{const v={};if(g.title||(v.title="Title is required."),(!g.fields||g.fields.length===0)&&(v.fields="At least one field is required."),Ie(v))return v},[]),d=D.useFormik({initialValues:mt(r)??Ut,validate:u,onSubmit:g=>t(g),validateOnChange:!1,validateOnBlur:!1}),h=c.useMemo(()=>Ve(d.values),[d.values]),f=fe(Gt,Kt),p=fe(Yt,Qt),y=c.useMemo(()=>typeof a=="object"?a:n.jsx(s.Heading,{children:a}),[a]);return n.jsx(s.Tabs.Root,{ref:i,defaultValue:"edit",children:n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Trigger,{value:"edit",children:"Edit"}),n.jsx(s.Tabs.Trigger,{value:"preview",children:"Preview"})]}),n.jsxs(s.Tabs.Content,{value:"edit",children:[y,n.jsxs(s.Text,{children:["Add a new form field by clicking a + button. Specify options for each field, then drag and drop to rearrange them. You can see what a submitted form might look like in the"," ",n.jsx("em",{children:"Preview"})," tab, but"," ",n.jsx("strong",{children:"field values entered on this page will not be saved."})]}),n.jsx(s.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:n.jsxs("form",{id:Ce,onSubmit:d.handleSubmit,children:[n.jsxs(D.FormikProvider,{value:d,children:[f,p,n.jsx(Ht,{}),n.jsx(s.Text,{severity:"danger",size:"1",children:typeof d.errors.fields=="string"&&d.errors.fields})]}),n.jsxs(s.Flex,{justify:"end",gap:"2",children:[n.jsx(s.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),n.jsx(s.Button,{type:"submit",disabled:!d.isValid,children:"Save"})]})]})})]}),n.jsx(s.Tabs.Content,{value:"preview",children:n.jsx(be,{schema:h,onSubmit:Xt})})]})})}));x.BooleanField=Q,x.BooleanInput=He,x.DateField=me,x.DateInput=Ge,x.FieldSection=K,x.FormBrowser=zt,x.FormBuilder=Jt,x.FormRenderer=be,x.FormSubmissionBrowser=At,x.FormSubmissionViewer=St,x.MultiSelectField=ce,x.MultiSelectInput=tt,x.MultiStringField=ae,x.MultiStringInput=Re,x.NumberField=G,x.NumberInput=Ue,x.PatchField=Pt,x.PatchFormProvider=Lt,x.SelectField=de,x.SelectInput=Qe,x.StringField=Z,x.StringInput=Ke,x.TextField=k,x.TextInput=Ye,x.deserialize=ue,x.deserializeField=De,x.formRevisionToSchema=Ve,x.isConditionMet=$e,x.useFieldInput=fe,x.useFieldInputs=Be,x.valueIsFile=Fe,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
1
+ (function(v,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("formik"),require("react"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("lodash.get"),require("lodash.set")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","formik","react","@hello-pangea/dnd","@overmap-ai/core","lodash.get","lodash.set"],n):(v=typeof globalThis<"u"?globalThis:v||self,n(v.forms={},v.jsxRuntime,v.blocks,v.formik,v.React,v.dnd,v.core,v.get,v.set))})(this,function(v,n,o,D,c,j,b,Z,Pe){"use strict";var ri=Object.defineProperty;var si=(v,n,o)=>n in v?ri(v,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):v[n]=o;var m=(v,n,o)=>(si(v,typeof n!="symbol"?n+"":n,o),o);class Ke{constructor(i){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=i;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(i){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}}}class B extends Ke{constructor(e){const{label:t,required:r,fieldValidators:s=[],formValidators:d=[],...u}=e;super(u);m(this,"required");m(this,"formValidators");m(this,"fieldValidators");m(this,"label");m(this,"onlyValidateAfterTouched",!0);this.label=t,this.required=r,this.fieldValidators=s,this.formValidators=d}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,t){if(this.required&&this.isBlank(e))return"This field is required.";for(const r of this.getFieldValidators()){const s=r(e);if(s)return s}if(t)for(const r of this.getFormValidators()){const s=r(e,t);if(s)return s}}_serialize(){return{...super._serialize(),label:this.label,required:this.required}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}}m(B,"fieldTypeName"),m(B,"fieldTypeDescription");const de={description:"_description_9dewt_1",fieldsContainer:"_fieldsContainer_9dewt_5"},q=l=>{const{label:i,children:e,severity:t,inputId:r,labelId:s,flexProps:d}=l;return n.jsx(o.Flex,{direction:"column",gap:"1",asChild:!0,...d,children:n.jsxs("label",{htmlFor:r,children:[n.jsx(o.Text,{severity:t,id:s,children:i}),e]})})},W=l=>{const{helpText:i,children:e,severity:t}=l;return n.jsxs(o.Flex,{direction:"column",gap:"1",children:[e,n.jsx(o.Flex,{direction:"column",children:n.jsx(o.Text,{size:"1",severity:t,className:de.description,children:i})})]})},H=l=>{const{id:i,field:e,formId:t,...r}=l,[s,d,u]=D.useField(e.getId()),{touched:a}=d,f=d.error??e.description,h=d.error?"danger":void 0,p=i??`${t}-${e.getId()}-input`,g=`${p}-label`,y=e.required?`${e.label} *`:e.label,x=c.useMemo(()=>({...s,onChange:I=>{const w=e.getValueFromChangeEvent(I);u.setValue(w,!1).then(),(a||!e.onlyValidateAfterTouched)&&u.setError(e.getError(w))},onBlur:I=>{u.setTouched(!0,!1).then(),u.setError(e.getError(e.getValueFromChangeEvent(I)))}}),[e,s,u,a]);return[{helpText:f,severity:h,inputId:p,labelId:g,label:y,fieldProps:x,helpers:u,field:e},{...r,"aria-labelledby":g}]},vt=[!0,"true"],Ye=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u},a]=H(i),f=o.useSeverityColor(r),h=vt.includes(u.value);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:n.jsx(o.Checkbox,{...a,...u,id:e,color:f,value:h.toString(),checked:h,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),ee=class ee extends B{constructor(e){super({...e,type:"boolean"});m(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 n.jsx(Ye,{...e,field:this})}};m(ee,"fieldTypeName","Checkbox"),m(ee,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(ee,"Icon",o.CheckCircledIcon);let X=ee;const Qe=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u,field:a},f]=H(i),h=o.useSeverityColor(r);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:n.jsx(o.TextField.Input,{...f,...u,type:"number",id:e,min:a.minimum,max:a.maximum,step:a.integers?1:.1,color:h})})})}),O=class O extends B{constructor(e){const{minimum:t=Number.MIN_SAFE_INTEGER,maximum:r=Number.MAX_SAFE_INTEGER,integers:s=!1,...d}=e;super({...d,type:"number"});m(this,"minimum");m(this,"maximum");m(this,"integers");this.minimum=t,this.maximum=r,this.integers=s}getValueFromChangeEvent(e){const t=Number.parseFloat(e.target.value);return Number.isNaN(t)?"":t}static getFieldCreationSchema(){return[new O({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:"minimum",formValidators:[this._validateMin]}),new O({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:"maximum",formValidators:[this._validateMax]}),new X({label:"Integers",description:"Whole numbers only",required:!1,identifier:"integers"})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.minimum,r=this.maximum;return typeof t=="number"&&e.push(s=>{if(typeof s=="number"&&s<t)return`Must be at least ${this.minimum}.`}),typeof r=="number"&&e.push(s=>{if(typeof s=="number"&&s>r)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(s=>{if(typeof s=="number"&&!Number.isInteger(s))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new O(e)}getInput(e){return n.jsx(Qe,{field:this,...e})}};m(O,"fieldTypeName","Number"),m(O,"fieldTypeDescription","Allows specifying a number within a given range."),m(O,"Icon",o.FontFamilyIcon),m(O,"_validateMin",(e,t)=>typeof t.maximum=="number"&&typeof e=="number"&&t.maximum<e?"Minimum cannot be greater than minimum.":null),m(O,"_validateMax",(e,t)=>typeof t.minimum=="number"&&typeof e=="number"&&t.minimum>e?"Maximum cannot be less than minimum.":null);let U=O;const Xe=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u},a]=H(i),f=o.useSeverityColor(r),h=u.value?u.value.split("T")[0]:"";return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:n.jsx(o.TextField.Input,{...a,...u,type:"date",id:e,color:f,value:h})})})}),te=class te extends B{constructor(e){super({...e,type:"date"});m(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return new Date(e.target.value).toISOString()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new te(e)}getInput(e){return n.jsx(Xe,{field:this,...e})}};m(te,"fieldTypeName","Date"),m(te,"fieldTypeDescription","Allows specifying a date."),m(te,"Icon",o.CalendarIcon);let ge=te;class ye extends B{constructor(e){const{minLength:t,maxLength:r=5e3,...s}=e;super(s);m(this,"minLength");m(this,"maxLength");this.minLength=t?Math.max(t,0):void 0,this.maxLength=r?Math.max(r,0):5e3}static getFieldCreationSchema(){return[new U({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new U({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:"maximum_length",minimum:1,maximum:5e3,formValidators:[this._validateMax],integers:!0})]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(t=>{if(this.minLength&&(!t||t.length<this.minLength))return!this.required&&!t?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(t=>{if(typeof t=="string"&&this.maxLength&&t.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}}}m(ye,"_validateMin",(e,t)=>typeof t.maximum_length=="number"&&typeof e=="number"&&t.maximum_length<e?"Minimum cannot be greater than maximum.":null),m(ye,"_validateMax",(e,t)=>{if(typeof e!="number")return null;const{minimum_length:r}=t;return typeof r!="number"?null:r>e?"Maximum cannot be less than minimum.":null});const Je=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u,field:a},f]=H(i),h=o.useSeverityColor(r);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:n.jsx(o.TextField.Input,{...f,...u,type:a.inputType,id:e,color:h})})})}),ie=class ie extends ye{constructor(e){const{inputType:t="text",...r}=e,s=e.maxLength?Math.min(500,e.maxLength):500,d=e.minLength?Math.min(e.minLength,s):void 0;super({...r,maxLength:s,minLength:d,type:"string"});m(this,"inputType");this.inputType=t}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:t,minimum_length:r,input_type:s,...d}=e;return new ie({...d,maxLength:t,minLength:r,inputType:s})}getInput(e){return n.jsx(Je,{field:this,...e})}};m(ie,"fieldTypeName","Short Text"),m(ie,"fieldTypeDescription","Short text fields can hold up to 500 characters on a single line."),m(ie,"Icon",o.InputIcon);let k=ie;const Ze=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u},a]=H(i);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:n.jsx(o.TextArea,{...a,...u,resize:"vertical",id:e,severity:r})})})}),ne=class ne extends ye{constructor(i){const e=i.maxLength?Math.min(5e3,i.maxLength):5e3,t=i.minLength?Math.min(i.minLength,e):void 0;super({...i,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=i;return new ne({...r,maxLength:e,minLength:t})}getInput(i){return n.jsx(Ze,{field:this,...i})}};m(ne,"fieldTypeName","Paragraph"),m(ne,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ne,"Icon",o.RowsIcon);let R=ne;const ke=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u,field:a},f]=H(i),{onChange:h,onBlur:p}=u,g=c.useMemo(()=>a.options.map(x=>({value:x.value,itemContent:x.label})),[a.options]),y=c.useCallback(x=>{h(x),p(x)},[h,p]);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:n.jsx(o.Select,{items:g,...u,onValueChange:y,placeholder:"Select one...",id:e,severity:r,...f})})})}),xe=(l="",i=[])=>({type:"section",fields:i,identifier:l,label:null,condition:null,conditional:!1}),wt=l=>{if(!l)return;const i=l.fields;let e=[];const t=[];for(const r of i)r.type==="section"?(e.length>0&&(t.push(xe(`AUTO_section-${i.indexOf(r)}`,e)),e=[]),t.push(r)):e.push(r);return e.length>0&&t.push(xe("AUTO_section-last",e)),{...l,fields:t,description:l.description??""}};function Le(l,i,e){const t=Array.from(l),[r]=t.splice(i,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function Ft(l,i,e){const t=Array.from(l);return t[i]=e,t}function Re(l,i,e){const t=Array.from(l??[]);return t.splice(i,0,e),t}function ve(l,i){const e=Array.from(l);return e.splice(i,1),e}const et=(l,i)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${b.slugify(i)}-${e.getTime()}`},tt=(l,i)=>{if(!i)return null;for(const e of l)if(e.type==="section"){const t=tt(e.fields,i);if(t)return t}else if(e.identifier===i)return e;return null},we=(l,i)=>l.filter((e,t)=>t<i).flatMap(e=>e.fields),it=l=>l.flatMap(i=>i.type==="section"?[...i.fields.map(e=>e.label),i.label]:i.label).filter(i=>i!==null),De=(l,i)=>{let e=1,t=`${l} (${e})`;for(;i.includes(t);)t=`${l} (${++e})`;return t},nt=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u},a]=H(i),f=o.useSeverityColor(r),h=c.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:p,onBlur:g}=u,y=`${e}-droppable`,{disabled:x}=a,[T,S]=c.useState(""),[I,w]=c.useState(""),A=I||s,V=I?"red":f,F=c.useCallback(E=>{p(E),g(E)},[p,g]),M=c.useCallback(E=>{h.findIndex(N=>N.value===E.target.value.trim())>=0?w("All options must be unique"):E.target.value?w(""):w("Option cannot be empty"),S(E.target.value)},[S,h]),$=c.useCallback(()=>{if(I)return;if(!T.trim())return w("Option cannot be empty");const E=T.trim();F([...h,{value:E,label:E}]),S("")},[T,I,F,h]),K=c.useCallback(E=>{E.key==="Enter"&&(E.preventDefault(),$())},[$]),Y=c.useCallback(E=>{F(ve(h,E))},[h,F]),Q=c.useCallback(E=>{if(!E.destination)return;const N=E.source.index,J=E.destination.index;F(Le(h,N,J))},[F,h]);return n.jsx(j.DragDropContext,{onDragEnd:Q,children:n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:A,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:(!x||h.length===0)&&n.jsxs(o.Flex,{gap:"2",children:[n.jsx(o.Box,{grow:"1",children:n.jsx(o.TextField.Input,{placeholder:"Press enter to add a new option",...a,...u,value:T,onChange:M,onKeyDown:K,id:e,color:V,onBlur:void 0})}),n.jsx(o.IconButton,{type:"button","aria-label":"Add option",disabled:!!I||x,onClick:$,children:n.jsx(o.PlusIcon,{})})]})})}),n.jsx(j.Droppable,{droppableId:y,children:E=>n.jsxs(o.Flex,{...E.droppableProps,ref:E.innerRef,direction:"column",children:[h.map((N,J)=>n.jsx(j.Draggable,{draggableId:`${N.value}-draggable`,index:J,isDragDisabled:x,children:({draggableProps:Se,dragHandleProps:ze,innerRef:Ee})=>n.jsx(o.Flex,{...ze,...Se,ref:Ee,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:n.jsxs(o.Badge,{color:"gray",size:"2",children:[n.jsx("span",{children:N.label}),n.jsx(o.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:x,onClick:()=>Y(J),children:n.jsx(o.Cross1Icon,{})})]})})},N.value)),E.placeholder]})})]})})}),re=class re extends B{constructor(e){const{minimum_length:t,maximum_length:r,...s}=e;super({...s,type:"multi-string"});m(this,"minLength");m(this,"maxLength");m(this,"onlyValidateAfterTouched",!1);this.minLength=t??0,this.maxLength=r??1/0}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return n.jsx(nt,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(t=>{if(Array.isArray(t)&&t.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(t=>{if(Array.isArray(t)&&t.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 re(e)}};m(re,"fieldTypeName","Multi-string"),m(re,"fieldTypeDescription","Allows the user to provide multiple unique strings."),m(re,"Icon",o.ListBulletIcon);let ce=re;class rt extends B{constructor(e){super(e);m(this,"options");m(this,"onlyValidateAfterTouched",!1);const t=new Set;this.options=e.options.map(r=>(typeof r=="string"&&(r={label:r,value:r}),t.add(r.label),r)),t.size!==e.options.length&&console.error(`${e.options.length-t.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options}}static getFieldCreationSchema(){return[new ce({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:"options",minimum_length:2,maximum_length:20})]}}const se=class se extends rt{constructor(i){super({...i,type:"select"})}getValueFromChangeEvent(i){return typeof i=="string"?i:i.target.value}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="select")throw new Error("Type mismatch.");return new se(i)}getInput(i){return n.jsx(ke,{field:this,...i})}};m(se,"fieldTypeName","Dropdown"),m(se,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(se,"Icon",o.DropdownMenuIcon);let ue=se;const bt=l=>l?Array.isArray(l)?l:[l]:[],st=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u,field:a},f]=H(i),{onChange:h,onBlur:p}=u,g=c.useMemo(()=>bt(u.value),[u.value]),y=c.useCallback(x=>{h(x),p(x)},[h,p]);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:d,children:n.jsx(o.MultiSelect,{value:g,onValueChange:y,options:a.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...f})})})}),oe=class oe extends rt{constructor(i){super({...i,type:"multi-select"})}getValueFromChangeEvent(i){if(Array.isArray(i))return i;throw new Error("Expected an array.")}isBlank(i){return super.isBlank(i)||i.length===0}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="multi-select")throw new Error("Type mismatch.");return new oe(i)}getInput(i){return n.jsx(st,{field:this,...i})}};m(oe,"fieldTypeName","Multi-select"),m(oe,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(oe,"Icon",o.CheckboxIcon);let fe=oe;const It=c.memo(function({field:i,...e}){const[{value:t}]=D.useField(i.options.clonedFieldIdentifier),r=c.useMemo(()=>{const s=i.options.getFieldToClone(t);return s?pe(s):null},[i.options,t]);return he(r,e)});class Fe extends B{constructor(e,t){super({...e,type:"custom"});m(this,"Component");m(this,"options");this.options=e,this.Component=t}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const t=this.Component;return n.jsx(t,{field:this,...e})}}m(Fe,"fieldTypeName","Custom"),m(Fe,"fieldTypeDescription","Allows re-rendering of field already in the form");class Ct extends Fe{constructor(i){super(i,It)}}const Tt=c.memo(function(i){const{field:e,...t}=i,{label:r,description:s,fields:d,condition:u}=e,{values:a,setFieldValue:f}=D.useFormikContext(),h=u!=null&&u.identifier?Z(a,u.identifier):void 0,p=c.useMemo(()=>Ne(u,h),[u,h]);c.useEffect(()=>{if(!p)for(const y of d)f(y.getId(),"").then()},[p,d,f]);const g=qe(d,t);return p?r?n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:"column",gap:"3",children:[n.jsxs(o.Flex,{direction:"column",children:[n.jsx(o.Heading,{as:"h3",size:"3",children:r}),n.jsx(o.Text,{className:de.description,children:s})]}),g]})}):g:null}),le=class le extends Ke{constructor(e){const{label:t=null,fields:r,condition:s=null,conditional:d,...u}=e;super({...u,type:"section"});m(this,"label");m(this,"fields");m(this,"condition");this.fields=r,this.condition=s,this.label=t,d===!1&&(this.condition=null)}static getFieldCreationSchema(e){return e.length===0?[]:[new X({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new le({label:"Conditional settings",identifier:"conditional-settings",condition:{identifier:"conditional",value:!0},fields:[new ue({label:"Field",description:"The field to use for the condition.",options:e.map(t=>!t.label||t.type==="upload"?null:{label:t.label,value:t.identifier}).filter(t=>!!t),identifier:"condition.identifier",required:!0}),new Ct({label:"Value",identifier:"condition.value",required:!0,clonedFieldIdentifier:"condition.identifier",getFieldToClone(t){if(!t)return null;const r=e.find(s=>s.identifier===t);return r?{...r,label:"Value",identifier:"condition.value",description:"The value to compare against.",required:r.type!=="boolean"}:(console.error("Could not find field with identifier",t),null)}})]})]}static deserialize(e){var r;if(e.type!=="section")throw new Error("Invalid type");const t=((r=e.fields)==null?void 0:r.map(_e))??[];return new le({...e,fields:t})}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 t={};for(const r of this.fields){const s=r.getId(),d=r.getError(Z(e,s),e);d&&Pe(t,r.getId(),d)}return t}getInput(e){return n.jsx(Tt,{field:this,...e})}};m(le,"fieldTypeName","Section"),m(le,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let G=le;const St={previewImage:"_previewImage_1ig84_1"},Ve=l=>{const i=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<i.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:i[t]}).format(e)},zt=c.memo(function(i){var V;const[{inputId:e,labelId:t,severity:r,helpText:s,label:d,fieldProps:u,field:a},f]=H(i),{onChange:h}=u,p=o.useSeverityColor(r),g=c.useRef(null),{value:y}=u,x=c.useMemo(()=>s||(a.maxFileSize?`Maximum file size: ${Ve(a.maxFileSize)}`:null),[a.maxFileSize,s]),T=c.useCallback(()=>{var F;(F=g.current)==null||F.click()},[]),S=c.useCallback(F=>{const M=[...y];M.splice(F,1),h({target:{files:M}})},[y,h]),I=y?"Select new files":"Select files",w=y?"Select new file":"Select a file",A=a.maxFiles>1?I:w;return n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:x,severity:r,children:n.jsxs(q,{severity:r,inputId:e,labelId:t,label:d,children:[n.jsx(o.Flex,{direction:"row",gap:"2",children:n.jsx(o.Box,{width:"max-content",asChild:!0,children:n.jsxs(o.Button,{...f,onClick:T,children:[n.jsx(o.UploadIcon,{})," ",A]})})}),n.jsx("input",{...f,type:"file",ref:g,id:e,accept:(V=a.extensions)==null?void 0:V.join(","),multiple:a.maxFiles>1,color:p,style:{display:"none"},...u,value:""})]})}),Array.isArray(y)&&y.length>0&&n.jsx(o.Flex,{direction:"column",gap:"2",children:y.map((F,M)=>n.jsx(Et,{field:a,file:F,onRemove:()=>S(M),disabled:f.disabled},M))})]})}),Et=c.memo(function({file:i,field:e,onRemove:t,disabled:r}){const[s,d]=c.useState(null),u=c.useMemo(()=>s&&e.getError([s]),[e,s]),{url:a,name:f,size:h}=c.useMemo(()=>{let p=null,g,y;return s!=null&&s.type.startsWith("image/")&&(p=URL.createObjectURL(s)),s?(g=s.name,y=Ve(s.size)):(g="Downloading...",y="..."),{url:p,name:g,size:y}},[s]);return c.useEffect(()=>{i instanceof Promise?i.then(d):d(i)},[i]),n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[n.jsxs(o.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[n.jsx(o.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${f}`,disabled:r,onClick:t,children:n.jsx(o.Cross1Icon,{})}),n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsx(o.Text,{children:f}),n.jsx(o.Text,{size:"1",children:h}),u&&n.jsx(o.Text,{size:"1",severity:"danger",children:u})]})]}),a&&n.jsx("img",{className:St.previewImage,src:a,alt:f})]})})}),ot=50*1024*1024,ae=class ae extends B{constructor(e){const{extensions:t,maximum_files:r,maximum_size:s,...d}=e;super({...d,type:"upload"});m(this,"extensions");m(this,"maxFileSize");m(this,"maxFiles");m(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof s=="number"?s:void 0,this.maxFiles=Math.max(typeof r=="number"?r:1,1),this.extensions=t}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(){return[new U({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:"maximum_files"}),new U({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum:ot,integers:!0}),new fe({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:"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)"}]})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.maxFileSize??ot,r=this.maxFiles??1;return e.push(s=>{if(s&&s.some(d=>d.size>t))return`Files must be at most ${Ve(t)}.`}),e.push(s=>{if(s&&s.length>r)return`You can only upload ${r} 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 n.jsx(zt,{field:this,...e})}};m(ae,"fieldTypeName","Upload"),m(ae,"fieldTypeDescription","Allows a file to be uploaded."),m(ae,"Icon",o.UploadIcon);let $e=ae;const Be={date:ge,number:U,boolean:X,select:ue,string:k,text:R,custom:Fe,upload:$e,"multi-string":ce,"multi-select":fe},_e=l=>{const i=l.type;return Be[i].deserialize(l)},pe=l=>l.type==="section"?G.deserialize(l):_e(l);function Oe(l,i={}){const{readonly:e=!1}=i;return{title:l.title,description:l.description,fields:l.fields.map(t=>pe(t)),meta:{readonly:e}}}function be(l){return!!(Array.isArray(l)&&l.some(i=>i instanceof File||i instanceof Promise))}function Ne(l,i){if(!l)return!0;if(be(i)||be(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(i)?i.map(r=>typeof r=="string"?r:r.value):i,t=Array.isArray(l.value)?l.value.map(r=>typeof r=="string"?r:r.value):l.value;if(Array.isArray(t)&&Array.isArray(e)){for(const r of t)if(!e.includes(r))return!1;return!0}return t===i}const he=(l,i)=>c.useMemo(()=>!i||!l?null:l.getInput(i),[l,i]),qe=(l,i)=>{const e=c.useMemo(()=>l.map(t=>n.jsx("div",{children:t.getInput(i)},t.getId())),[l,i]);return n.jsx(o.Flex,{direction:"column",gap:"2",children:e})},Ie=l=>Object.keys(l).length>0,lt=async(l,i)=>{const e={};for(const t of l.fields)if(t instanceof G){if(t.condition){const{identifier:r}=t.condition;if(!Ne(t.condition,Z(i,r)))continue}Object.assign(e,t.getErrors(i))}else{if(!(t instanceof B))throw new Error("Invalid field type");const r=t.getId(),s=t.getError(Z(i,r),i);s&&Pe(e,r,s)}if(Ie(e))return e},Mt=[null,void 0],We=(l,i)=>l.reduce((e,t)=>t instanceof G?{...e,...We(t.fields,i)}:(Mt.includes(Z(e,t.getId()))&&Pe(e,t.getId(),""),e),i),At=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Ce=c.memo(c.forwardRef((l,i)=>{const{schema:e,values:t={},onSubmit:r=At,submitText:s="Submit",cancelText:d,onCancel:u,onDirty:a,hideTitle:f=!e.title,hideDescription:h,className:p}=l,{readonly:g}=e.meta,y=c.useMemo(()=>crypto.randomUUID(),[]),x=D.useFormik({initialValues:We(e.fields,t),onSubmit:r,validate:A=>lt(e,A),validateOnBlur:!1,validateOnChange:!1}),{dirty:T}=x,S=c.useMemo(()=>typeof e.title=="string"?n.jsx(o.Heading,{children:e.title}):e.title,[e.title]),I=c.useMemo(()=>typeof e.description=="string"?n.jsx(o.Text,{className:de.description,children:e.description}):e.description,[e.description]),w=qe(e.fields,{formId:y,disabled:g});return c.useEffect(()=>{T&&a&&a()},[T,a]),n.jsx(D.FormikProvider,{value:x,children:n.jsx(o.Flex,{ref:i,direction:"column",gap:"2",className:p,asChild:!0,children:n.jsxs("form",{id:y,onSubmit:x.handleSubmit,children:[!f&&n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[S,!h&&I]})}),w,!g&&n.jsxs(o.Flex,{justify:"end",gap:"2",children:[d&&n.jsx(o.Button,{type:"button",variant:"soft",onClick:u,children:d}),n.jsx(o.Button,{type:"submit",disabled:!x.isValid,children:s})]})]})})})})),Pt=c.memo(c.forwardRef((l,i)=>{const{submission:e,showFormDescription:t=!1,showFormTitle:r=!0}=l,s=b.useAppSelector(b.selectFormRevision(e.form_revision)),{sdk:d}=b.useSDK();if(!s)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const u=c.useMemo(()=>Oe(s,{readonly:!0}),[s]),a=c.useMemo(()=>{const f=b.selectSubmissionAttachments(e.offline_id)(d.store.getState())??[],h={};for(const p of f){const g=d.files.fetchFileFromUrl(p.file,p.file_sha1,p.file_name).then(x=>{if(!x.success)throw new Error(`Failed to download attachment ${p.file_name}.`);return x.body}),y=h[p.field_identifier];y?y.push(g):h[p.field_identifier]=[g]}return{...e.values,...h}},[d.files,d.store,e.offline_id,e.values]);return n.jsx(Ce,{ref:i,schema:u,values:a,hideDescription:!t,hideTitle:!r})})),at={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},He="organization:",je="user:",Lt=c.memo(c.forwardRef((l,i)=>{const{maxResults:e=20,...t}=l,[r,s]=c.useState(""),[d,u]=c.useState(""),{sdk:a}=b.useSDK(),f=c.useMemo(()=>{const w={maxResults:e,searchTerm:r};return d&&(d.startsWith(He)?w.owner_organization=parseInt(d.slice(He.length)):d.startsWith(je)&&(w.owner_user=parseInt(d.slice(je.length)))),w},[r,e,d]),h=b.useAppSelector(b.selectFilteredUserForms(f))??[],p=b.useAppSelector(b.selectUserFormMapping),g=c.useCallback(w=>{w.favorite?a.userForms.unfavorite(w.offline_id).then():a.userForms.favorite(w.offline_id).then()},[a]),y=c.useMemo(()=>{const w=a.store.getState(),A={};for(const V of Object.values(p)){const F=b.selectOrganization(V.owner_organization||-1)(w);F&&(A[`${He}${F.id}`]=F.name);const M=b.selectUser(V.owner_user||-1)(w);M&&(A[`${je}${M.id}`]=M.username)}return Object.entries(A).map(([V,F])=>({itemContent:F,value:V}))},[p,a.store]),x=c.useCallback(w=>{s(w.currentTarget.value)},[]),S=(b.useAppSelector(b.selectNumberOfUserForms)||0)-h.length,I=h.length==e&&S>0?`Only the first ${e} results are shown (${S} hidden)`:S>0&&`${S} hidden forms`;return n.jsxs(o.Flex,{ref:i,direction:"column",gap:"2",children:[n.jsxs(o.Flex,{gap:"2",grow:"1",children:[n.jsx(o.Box,{grow:"1",asChild:!0,children:n.jsx(o.TextField.Root,{size:"3",children:n.jsx(o.TextField.Input,{placeholder:"Filter",value:r,onChange:x})})}),n.jsx(o.Select,{items:y,value:d,onValueChange:u,placeholder:"Owner",size:"large"})]}),h.length>0&&n.jsx(o.ButtonList.Root,{children:h.map(w=>n.jsx(Dt,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),n.jsx(o.Box,{px:"3",children:n.jsx(o.Text,{size:"2",severity:"info",children:I})})]})})),Dt=l=>{var g;const{form:i,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,s=(g=b.useAppSelector(b.selectOrganization(i.owner_organization||-1)))==null?void 0:g.name,d=b.useAppSelector(b.selectUser(i.owner_user||-1)),u=b.useAppSelector(b.selectCurrentUser).id,a=!!d&&d.id===u,f=s??(a?"You":d==null?void 0:d.username)??"Unknown",h=c.useCallback(y=>{y.stopPropagation(),r()},[r]),p=n.jsx(o.ButtonList.Item,{onClick:()=>e(i),asChild:!0,children:n.jsxs(o.Flex,{justify:"between",gap:"2",py:"2",px:"3",...o.divButtonProps,children:[n.jsxs(o.Flex,{grow:"1",align:"center",gap:"2",children:[n.jsx(o.IconButton,{className:b.classNames(i.favorite?at.favoriteIcon:at.regularIcon),variant:"ghost",onClick:h,"aria-label":i.favorite?"Favorite form":"Standard form",disabled:!t,children:i.favorite?n.jsx(o.StarFilledIcon,{}):n.jsx(o.StarIcon,{})}),n.jsx(o.Text,{noWrap:!0,children:i.latestRevision.title}),i.latestRevision.description&&n.jsx(o.QuestionMarkCircledIcon,{})]}),f&&n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsx(o.PersonIcon,{})," ",f]})]})});return i.latestRevision.description?n.jsx(o.Tooltip,{content:i.latestRevision.description,children:p},i.offline_id):p},dt={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Vt=c.memo(function(i){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:s,rowDecorator:d}=i,u=b.useAppSelector(b.selectCurrentUser),a=b.useAppSelector(b.selectUser("created_by"in e?e.created_by:u.id)),f=Ue(e),h=b.isToday(f)?f.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):b.getLocalDateString(f),p=b.useAppSelector(b.selectFormRevision(e.form_revision));if(!p)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const g=(w=b.useAppSelector(b.selectLatestFormRevision(p.form)))==null?void 0:w.revision,y=b.useFileSrc({file:(a==null?void 0:a.profile.file)??null,fileSha1:(a==null?void 0:a.profile.file_sha1)??null}),x=(a==null?void 0:a.username.charAt(0).toUpperCase())??"?",T=p.revision===g,S=c.useCallback(()=>{t&&t({submission:e})},[e,t]),I=n.jsx(o.ButtonList.Item,{onClick:S,asChild:!0,children:n.jsxs(o.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[n.jsxs(o.Flex,{gap:"2",align:"center",className:dt.stopHorizontalOverflow,children:[n.jsx(o.Avatar,{src:y,size:"1",fallback:x}),n.jsx(o.Text,{size:"2",noWrap:!0,children:s==="creator"?(a||u).username:p.title})]}),n.jsxs(o.Flex,{gap:"2",align:"center",children:[!r&&(p.revision?n.jsx(o.Badge,{variant:"soft",severity:T?"primary":"info",children:r?p.revision.toString():`Revision #${p.revision}`}):!!g&&n.jsx(o.Badge,{children:"Original"})),n.jsx(o.Text,{size:"2",noWrap:!0,children:h})]})]})});return d?d(e,I):I}),Ue=l=>{const i="created_at"in l?l.created_at:l.submitted_at;return new Date(i)},$t=c.memo(function(i){const{formId:e,submissions:t,compact:r=!1,className:s,after:d,variant:u="outline",...a}=i;if(!!e==!!t)throw new Error("Either formId or submissions must be provided, but not both.");const f=b.useAppSelector(t?()=>t:b.selectSubmissionsForForm(e)),h=c.useMemo(()=>f==null?void 0:f.sort((p,g)=>Ue(g).getTime()-Ue(p).getTime()),[f]);return n.jsx(o.ButtonList.Root,{className:b.classNames(dt.submissionsContainer,s),size:"small",variant:u,before:!r&&n.jsxs(o.Text,{severity:"info",children:["There are ",((f==null?void 0:f.length)||0).toString()," submissions of this form."]}),after:d,children:h==null?void 0:h.map((p,g)=>n.jsx(Vt,{submission:p,compact:r,...a},g))})}),Bt=c.memo(function(i){const{name:e,render:t}=i,{submitForm:r}=D.useFormikContext(),[s,d,u]=D.useField(e);return c.useMemo(()=>{const a=f=>u.setValue(f,!1);return t({value:s.value,setValue:a,patchValue:r})},[r,u,s.value,t])}),_t=c.memo(c.forwardRef((l,i)=>{const{children:e,schema:t,values:r,onPatch:s,onError:d,...u}=l,a=c.useMemo(()=>We(t.fields,r),[t.fields,r]),f=c.useCallback(x=>{const T={};for(const S in x){const I=x[S];I!==a[S]&&I!==void 0&&(T[S]=I)}Ie(T)&&s(T)},[a,s]),h=c.useCallback(async x=>{const T=await lt(t,x);return T&&d(T),T},[t,d]),p=D.useFormik({initialValues:a,onSubmit:f,validate:h,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:y}=p;return c.useEffect(()=>{Ie(g)&&y({values:a,errors:{}})},[g,a,y]),n.jsx(D.FormikProvider,{value:p,children:n.jsx("form",{...u,ref:i,onSubmit:p.handleSubmit,children:e})})})),ct={...Be,section:G},Ot=c.memo(function(i){const{field:e,setFieldType:t}=i,r=e.fieldTypeName,s=e.fieldTypeDescription,d=e.Icon;return n.jsxs(o.Flex,{gap:"4",align:"center",children:[n.jsx(o.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:n.jsxs(o.Flex,{gap:"3",align:"center",grow:"1",children:[n.jsx(d,{}),r]})}),n.jsx(o.Text,{children:s})]})}),ut=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],Nt=ut.length-1,qt=c.memo(function(i){const{setFieldType:e}=i;return n.jsx(o.Flex,{direction:"column",gap:"3",children:ut.map((t,r)=>n.jsxs(o.Flex,{direction:"column",gap:"3",children:[n.jsx(o.Flex,{direction:"column",gap:"2",children:t.map(s=>n.jsx(Ot,{field:Be[s],setFieldType:()=>e(s)},s))}),r<Nt&&n.jsx(o.Separator,{size:"4"})]},r))})}),Wt=l=>i=>{if(!(!i||typeof i!="string")&&l.includes(i.trim()))return"This name is already taken."},Ht=(l,i)=>{const e=[new k({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[Wt(l)]}),new R({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return i==="section"?e:[...e,new X({label:"Required",description:null,required:!1,identifier:"required"})]},jt=c.memo(function(i){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:s,conditionalSourceFields:d}=i,u=ct[e],a=D.useFormikContext(),f=c.useMemo(()=>{const h=it(a.values.fields).filter(g=>g!==(s==null?void 0:s.label));let p=Ht(h,e);if(u===G){if(d===void 0)throw new Error("Conditional source fields must be provided when changing sections.");p=p.concat(u.getFieldCreationSchema(d))}else{if(!(u.prototype instanceof B))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);p=[...p,...u.getFieldCreationSchema()]}return{fields:p,meta:{readonly:!1},title:null}},[a.values.fields,e,u,s==null?void 0:s.label,d]);return n.jsx(Ce,{schema:f,values:s,onSubmit:r,cancelText:s?void 0:"Back",onCancel:t})}),me=c.memo(function(i){const{parentPath:e,index:t,children:r,initial:s,editing:d,conditionalSourceFields:u}=i,[a,f]=c.useState(),h=(s==null?void 0:s.type)??a,p=h?ct[h].fieldTypeName:void 0,{setFieldValue:g,values:y}=D.useFormikContext();if(d&&!s)throw new Error("Initial field must be provided if editing is true.");const x=!h&&!d&&!s,T=x?"Choose a field type":`${p} settings`,S=x?"Select a field type to add to this section.":(p==null?void 0:p.toLowerCase())==="section"?"Customize your section":`Customize your ${p==null?void 0:p.toLowerCase()} field.`,I=c.useCallback(()=>f(void 0),[]),w=c.useCallback(F=>{f(void 0),F()},[]),A=c.useCallback((F,M)=>{const{label:$}=F;if(!h)throw new Error("Field type must be selected before creating a field.");if(!$||typeof $!="string")throw new Error("Label must be provided before creating a field.");const K=pe({type:h,...F,identifier:et(F.identifier,$)}).serialize(),Y=Z(y,e);if(Y===void 0)throw new Error("Parent path must point to an existing field.");let Q;if(!Array.isArray(Y))throw new Error("Parent path must point to an array.");d?Q=Ft(Y,t,K):Q=Re(Y,t,K),g(e,Q).then(),M()},[d,h,y,e,g,t]),V=c.useCallback(F=>x?n.jsx(qt,{setFieldType:f}):n.jsx(jt,{conditionalSourceFields:u,handleCancel:I,handleCreateField:M=>A(M,F),fieldType:h,defaultField:s}),[u,I,A,s,x,h]);return n.jsx(o.Dialog,{onCloseInterrupt:w,title:T,description:S,content:V,children:r})}),ft=({children:l})=>n.jsx(n.Fragment,{children:l}),pt=(l,i)=>({initial:l?i:"none",sm:l?"none":i}),ht=c.memo(function(i){const{remove:e,dragHandleProps:t,editProps:r,insertAfterProps:s,duplicateProps:d}=i,u=c.useMemo(()=>[{Wrapper:me,wrapperProps:r,Icon:o.Pencil1Icon,text:"Edit"},{Icon:o.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:me,wrapperProps:d,Icon:o.CopyIcon,text:"Duplicate"},{Wrapper:me,wrapperProps:s,Icon:o.PlusIcon,text:"Add after"},{Icon:a=>n.jsx("div",{...a,children:n.jsx(o.DragHandleDots2Icon,{})}),text:"Reorder",disableOnMobile:!0,buttonProps:{...t,asChild:!0}}],[t,d,r,s,e]);return n.jsxs(n.Fragment,{children:[n.jsx(o.Flex,{gap:"4",display:pt(!1,"flex"),children:u.map(a=>{const f=a.Wrapper??ft;return n.jsx(f,{...a.wrapperProps,children:n.jsx(o.IconButton,{type:"button",variant:"ghost","aria-label":a.text,...a.buttonProps,children:n.jsx(a.Icon,{})})},a.text)})}),n.jsx(o.Box,{display:pt(!0,"block"),children:n.jsx(o.DropdownMenu,{trigger:n.jsx(o.IconButton,{variant:"ghost","aria-label":"Actions menu",children:n.jsx(o.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(a=>{var h;if(a.disableOnMobile)return null;const f=a.Wrapper??ft;return{...a.buttonProps,onSelect:(h=a.buttonProps)==null?void 0:h.onClick,content:n.jsx(f,{...a.wrapperProps,children:n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(a.Icon,{}),a.text]})})}}).filter(a=>a!==null)})})]})}),Te="form-builder",Ut=c.memo(function(i){const{field:e,index:t,sectionIndex:r,takenLabels:s,remove:d,getFieldNodeMap:u}=i,a=c.useMemo(()=>pe(e),[e]),f=he(a,{formId:Te,disabled:!0}),h=c.useCallback(x=>{if(x.label===null)throw new Error(`Expected a label for field ${x.identifier}`);return{...x,label:De(x.label,s),identifier:""}},[s]),p=c.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),g=c.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:h(e)}),[h,e,t,r]),y=c.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return n.jsx(j.Draggable,{draggableId:e.identifier,index:t,children:x=>n.jsx(o.Card,{ref:x.innerRef,...x.draggableProps,...x.dragHandleProps,mb:"4",children:n.jsxs(o.Flex,{ref:T=>{const S=u();T?S.set(e.identifier,T):S.delete(e.identifier)},gap:"4",justify:"between",align:"center",children:[f,n.jsx(ht,{remove:d,editProps:p,duplicateProps:g,insertAfterProps:y,dragHandleProps:x.dragHandleProps})]})})})}),Gt=c.memo(function(i){const{start:e,end:t}=i;if(e===void 0||t===void 0)return null;const r=20,s={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y)},d=Math.abs(t.x-e.x)+r*2,u=Math.abs(t.y-e.y);return n.jsxs("svg",{width:d,height:u,style:{backgroundColor:"#eee",transform:`translate(${s.x}px, ${s.y}px)`},children:[n.jsx("line",{stroke:"black",strokeWidth:2,x1:e.x-s.x-r,y1:t.y-s.y,x2:t.x-s.x,y2:t.y-s.y}),n.jsx("line",{stroke:"black",strokeWidth:2,x1:e.x-s.x-r,y1:e.y-s.y,x2:e.x-s.x-r,y2:t.y-s.y}),n.jsx("line",{stroke:"black",strokeWidth:2,x1:e.x-s.x,y1:e.y-s.y,x2:t.x-s.x-r,y2:e.y-s.y})]})}),Kt=c.memo(function(i){var Q,E,N,J,Se,ze,Ee,yt;const{field:e,index:t,dropState:r,getFieldNodeMap:s}=i,d=c.useRef(null),u=(Q=r[e.identifier])==null?void 0:Q.disabled,{setFieldValue:a,values:f}=D.useFormikContext(),h=o.useAlertDialog(),p=it(f.fields),g=c.useCallback((C,z)=>{for(const L of C){const P=z.indexOf(L);a(`fields.${P}.condition`,null).then(),a(`fields.${P}.conditional`,!1).then()}},[a]),y=c.useCallback(C=>{var P;const z=e.fields[C];if(!z)throw new Error("Could not find field to remove.");const L=[];for(const _ of f.fields)((P=_.condition)==null?void 0:P.identifier)===z.identifier&&L.push(_);return{removing:z,affectedSections:L,action:()=>a(`fields.${t}.fields`,ve(e.fields,C))}},[e.fields,f.fields,a,t]),x=c.useCallback(C=>{const{affectedSections:z,action:L,removing:P}=y(C),_=()=>{L().then(),g(z,f.fields)};if(z.length>0){const Ge=z.map(Me=>Me.label).join(", ");return h({title:"Remove condition?",description:`${P.label} is being used as a condition, deleting it will remove the condition from the ${Ge} section(s).`,severity:"danger",actionText:"Remove",onAction:_})}_()},[y,g,f.fields,h]),T=c.useCallback(()=>{const z=e.fields.map((Ae,ni)=>y(ni)).flatMap(Ae=>Ae.affectedSections),L=z.length?"Remove fields and conditions?":"Remove fields?",P=e.fields.length,_=z.map(Ae=>Ae.label).join(", "),Ge=z.length?`Deleting this section will remove the ${P} field(s) it contains and will remove the conditions from following sections: ${_}`:`Deleting this section will remove the ${P} field(s) it contains.`,Me=ve(f.fields,t),xt=()=>a("fields",Me);if(z.length>0)return h({title:L,description:Ge,severity:"danger",actionText:"Remove",onAction:()=>{xt().then(()=>{g(z,Me)})}});xt().then()},[e.fields,f.fields,t,y,a,h,g]),S=c.useCallback(C=>{if(C.label===null)throw new Error(`Expected a label for field ${C.identifier}`);const z=De(C.label,p),L=C.fields.map(P=>{const _=De(P.label,p);return{...P,label:_,identifier:et(void 0,_)}});return{...C,label:z,fields:L,identifier:""}},[p]),I=c.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:we(f.fields,t)}),[e,t,f.fields]),w=c.useMemo(()=>({index:t+1,parentPath:"fields",initial:xe(),conditionalSourceFields:we(f.fields,t+1)}),[t,f.fields]),A=c.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),V=c.useMemo(()=>({index:t+1,parentPath:"fields",initial:S(e),conditionalSourceFields:we(f.fields,t+1)}),[S,e,t,f.fields]),F=c.useMemo(()=>{var C,z;return(z=tt(f.fields,(C=e.condition)==null?void 0:C.identifier))==null?void 0:z.label},[(E=e.condition)==null?void 0:E.identifier,f.fields]),M=Array.isArray((N=e.condition)==null?void 0:N.value)?"contains all of":"equals";if(be((J=e.condition)==null?void 0:J.value))throw new Error("File values are not supported for conditions.");const $=Array.isArray((Se=e.condition)==null?void 0:Se.value)?(ze=e.condition)==null?void 0:ze.value.map(C=>typeof C=="string"?C:C.label).join(", "):(Ee=e.condition)==null?void 0:Ee.value.toString();console.log(e),console.log(d.current,(yt=d.current)==null?void 0:yt.getBoundingClientRect());const K=c.useCallback(C=>{if(console.log("in callback",C),C){const{top:z,bottom:L,left:P}=C.getBoundingClientRect();return{x:P,y:(L-z)/2}}},[]),Y=c.useCallback(C=>{const L=s().get(C);return K(L)},[s,K]);return n.jsx(j.Draggable,{draggableId:e.identifier,index:t,children:C=>n.jsxs(o.Card,{ref:C.innerRef,...C.draggableProps,...C.dragHandleProps,mb:"4",children:[e.condition&&n.jsx(Gt,{start:K(d.current),end:Y(e.condition.identifier)}),n.jsxs(o.Flex,{ref:d,gap:"3",justify:"between",align:"center",children:[n.jsxs(o.Flex,{direction:"column",gap:"2",grow:"1",children:[n.jsxs(o.Flex,{direction:"column",children:[n.jsx(o.Heading,{as:"h3",size:"3",children:e.label}),n.jsx(o.Text,{className:de.description,children:e.description})]}),e.condition&&n.jsx(o.Text,{size:"1",children:n.jsxs(o.Em,{children:["Display only if ",n.jsx(o.Strong,{children:F})," ",M," ",n.jsx(o.Strong,{children:$})]})}),n.jsx(j.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:u,children:z=>n.jsxs(o.Flex,{ref:z.innerRef,...z.droppableProps,direction:"column",gap:"0",children:[e.fields.map((L,P)=>n.jsx(Ut,{field:L,index:P,sectionIndex:t,remove:()=>x(P),takenLabels:p,getFieldNodeMap:s},L.identifier)),z.placeholder,n.jsx(me,{...A,children:n.jsxs(o.Button,{type:"button",variant:"outline",children:[n.jsx(o.PlusIcon,{})," Add a field"]})})]})})]}),n.jsx(ht,{remove:T,insertAfterProps:w,dragHandleProps:C.dragHandleProps,editProps:I,duplicateProps:V})]})]})})}),Yt=(l,i)=>{var t;const e={...l};switch(i.type){case"release":for(const r in e)e[r].disabled=!1;return e;case"hold":for(const r in e)(t=e[r])!=null&&t.conditionFields.has(i.fieldId)&&(e[r].disabled=!0);return e;case"update":return i.state}},Qt=(l,i)=>{if(i)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===i)return e}}},mt=l=>{var e,t,r;const i={};for(let s=0;s<l.length;s++){const d=l[s];if(!d)throw new Error("Field is undefined.");const u=s>0?(e=i[l[s-1].identifier])==null?void 0:e.conditionFields:void 0,a=new Set(u);(t=d.condition)!=null&&t.identifier&&a.add(d.condition.identifier),i[d.identifier]={disabled:!1,conditionFields:a,conditionIndex:Qt(l,(r=d.condition)==null?void 0:r.identifier),index:s,label:d.label}}return i},gt=(l,i)=>{for(const[e,t]of Object.entries(l))if(t.identifier===i)return[t,e]},Xt=c.memo(function(){const{values:i,setFieldValue:e}=D.useFormikContext(),t=c.useRef(null),[r,s]=c.useReducer(Yt,i.fields,mt),{showInfo:d}=o.useToast();c.useEffect(()=>{s({type:"update",state:mt(i.fields)})},[s,i.fields]);const u=c.useCallback(p=>{p.type==="SECTION"&&s({type:"hold",fieldId:p.draggableId})},[]),a=c.useCallback(p=>{const{source:g,destination:y,type:x,reason:T,draggableId:S}=p;if(s({type:"release"}),!y||T==="CANCEL")return;if(x==="ROOT"){const F=r[S];if(!F)throw new Error("Could not find section context.");let M=typeof F.conditionIndex<"u"?Math.max(F.conditionIndex+1,y.index):y.index;for(const $ of Object.values(r))$.conditionIndex===g.index&&(M=Math.min(M,$.index-1));return M!=y.index&&d({title:"Reordered sections",description:"Sections with conditions must be below the fields they reference."}),e("fields",Le(i.fields,g.index,M))}if(x!=="SECTION")throw new Error("Unexpected droppable type.");const[I,w]=gt(i.fields,g.droppableId)??[],[A,V]=gt(i.fields,y.droppableId)??[];if(!(I!=null&&I.fields)||!A)throw new Error("Could not find section with fields.");if(I.identifier===A.identifier)e(`fields.${w}.fields`,Le(I.fields,g.index,y.index)).then();else{const F=I.fields[g.index];if(!F)throw new Error("Could not find field to reorder.");e(`fields.${w}.fields`,ve(I.fields,g.index)).then(),e(`fields.${V}.fields`,Re(A.fields,y.index,F)).then()}},[i.fields,e,r,d]),f=c.useMemo(()=>({index:i.fields.length,parentPath:"fields",initial:xe(),conditionalSourceFields:we(i.fields,i.fields.length)}),[i.fields]),h=()=>(t.current===null&&(t.current=new Map),t.current);return n.jsx(j.DragDropContext,{onDragStart:u,onDragEnd:a,children:n.jsx(j.Droppable,{droppableId:"droppable",type:"ROOT",children:p=>n.jsxs(o.Flex,{ref:p.innerRef,...p.droppableProps,className:de.fieldsContainer,direction:"column",gap:"0",children:[i.fields.map((g,y)=>n.jsx(Kt,{field:g,index:y,dropState:r,getFieldNodeMap:h},g.label)),p.placeholder,n.jsx(me,{...f,children:n.jsxs(o.Button,{type:"button",variant:"outline",children:[n.jsx(o.PlusIcon,{})," Add a section"]})})]})})})}),Jt={title:"",description:"",fields:[]},Zt=new k({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),kt={formId:Te,placeholder:"Give your form a title."},Rt=new R({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),ei={formId:Te,placeholder:"Explain the purpose of this form."},ti=()=>{alert("This is a form preview, your data will not be saved.")},ii=c.memo(c.forwardRef((l,i)=>{const{onCancel:e,onSave:t,revision:r}=l,s=r?"Edit form":"Create a new form",{heading:d=s}=l,u=c.useCallback(y=>{const x={};if(y.title||(x.title="Title is required."),(!y.fields||y.fields.length===0)&&(x.fields="At least one field is required."),Ie(x))return x},[]),a=D.useFormik({initialValues:wt(r)??Jt,validate:u,onSubmit:y=>t(y),validateOnChange:!1,validateOnBlur:!1}),f=c.useMemo(()=>Oe(a.values),[a.values]),h=he(Zt,kt),p=he(Rt,ei),g=c.useMemo(()=>typeof d=="object"?d:n.jsx(o.Heading,{children:d}),[d]);return n.jsx(o.Tabs.Root,{ref:i,defaultValue:"edit",children:n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsxs(o.Tabs.List,{children:[n.jsx(o.Tabs.Trigger,{value:"edit",children:"Edit"}),n.jsx(o.Tabs.Trigger,{value:"preview",children:"Preview"})]}),n.jsxs(o.Tabs.Content,{value:"edit",children:[g,n.jsxs(o.Text,{children:["Add a new form field by clicking a + button. Specify options for each field, then drag and drop to rearrange them. You can see what a submitted form might look like in the"," ",n.jsx("em",{children:"Preview"})," tab, but"," ",n.jsx("strong",{children:"field values entered on this page will not be saved."})]}),n.jsx(o.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:n.jsxs("form",{id:Te,onSubmit:a.handleSubmit,children:[n.jsxs(D.FormikProvider,{value:a,children:[h,p,n.jsx(Xt,{}),n.jsx(o.Text,{severity:"danger",size:"1",children:typeof a.errors.fields=="string"&&a.errors.fields})]}),n.jsxs(o.Flex,{justify:"end",gap:"2",children:[n.jsx(o.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),n.jsx(o.Button,{type:"submit",disabled:!a.isValid,children:"Save"})]})]})})]}),n.jsx(o.Tabs.Content,{value:"preview",children:n.jsx(Ce,{schema:f,onSubmit:ti})})]})})}));v.BooleanField=X,v.BooleanInput=Ye,v.DateField=ge,v.DateInput=Xe,v.FieldSection=G,v.FormBrowser=Lt,v.FormBuilder=ii,v.FormRenderer=Ce,v.FormSubmissionBrowser=$t,v.FormSubmissionViewer=Pt,v.MultiSelectField=fe,v.MultiSelectInput=st,v.MultiStringField=ce,v.MultiStringInput=nt,v.NumberField=U,v.NumberInput=Qe,v.PatchField=Bt,v.PatchFormProvider=_t,v.SelectField=ue,v.SelectInput=ke,v.StringField=k,v.StringInput=Je,v.TextField=R,v.TextInput=Ze,v.deserialize=pe,v.deserializeField=_e,v.formRevisionToSchema=Oe,v.isConditionMet=Ne,v.useFieldInput=he,v.useFieldInputs=qe,v.valueIsFile=be,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- ._description_17zed_1{white-space:pre-line}._previewImage_1ig84_1{max-height:100px;border-radius:max(var(--radius-2),var(--radius-4));flex-basis:50%;object-fit:cover}._favoriteIcon_1bixi_1._favoriteIcon_1bixi_1{color:var(--yellow-a9)}._favoriteIcon_1bixi_1._favoriteIcon_1bixi_1:hover:not(:disabled){background-color:transparent;color:var(--gray-a9)}._regularIcon_1bixi_9._regularIcon_1bixi_9:hover:not(:disabled){color:var(--yellow-a9);background-color:transparent}._submissionsContainer_9iirt_1{overflow-y:auto;max-height:min(369px,100vh - 200px)}._stopHorizontalOverflow_9iirt_6{min-width:0}
1
+ ._description_9dewt_1{white-space:pre-line}._fieldsContainer_9dewt_5{padding-left:40px}._previewImage_1ig84_1{max-height:100px;border-radius:max(var(--radius-2),var(--radius-4));flex-basis:50%;object-fit:cover}._favoriteIcon_1bixi_1._favoriteIcon_1bixi_1{color:var(--yellow-a9)}._favoriteIcon_1bixi_1._favoriteIcon_1bixi_1:hover:not(:disabled){background-color:transparent;color:var(--gray-a9)}._regularIcon_1bixi_9._regularIcon_1bixi_9:hover:not(:disabled){color:var(--yellow-a9);background-color:transparent}._submissionsContainer_9iirt_1{overflow-y:auto;max-height:min(369px,100vh - 200px)}._stopHorizontalOverflow_9iirt_6{min-width:0}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Form functionality for Overmap",
4
4
  "author": "Wôrdn Inc.",
5
5
  "license": "UNLICENSED",
6
- "version": "1.0.3",
6
+ "version": "1.0.4-conditional-arrows.3",
7
7
  "type": "module",
8
8
  "main": "dist/forms.umd.cjs",
9
9
  "module": "dist/forms.js",