@overmap-ai/forms 1.0.3-form-improvements.7 → 1.0.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.
package/dist/forms.js CHANGED
@@ -1584,7 +1584,7 @@ const Pe = (s, i) => v(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1584
1584
  }), Oe = "form-builder", un = S(function(i) {
1585
1585
  const { field: e, index: t, sectionIndex: n, takenLabels: o, remove: l } = i, c = v(() => Me(e), [e]), a = Pe(c, { formId: Oe, disabled: !0 }), f = T(
1586
1586
  (p) => {
1587
- if (p.label == null)
1587
+ if (p.label === null)
1588
1588
  throw new Error(`Expected a label for field ${p.identifier}`);
1589
1589
  return { ...p, label: He(p.label, o), identifier: "" };
1590
1590
  },
@@ -1703,7 +1703,7 @@ const Pe = (s, i) => v(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1703
1703
  d
1704
1704
  ]), g = T(
1705
1705
  (C) => {
1706
- if (C.label == null)
1706
+ if (C.label === null)
1707
1707
  throw new Error(`Expected a label for field ${C.identifier}`);
1708
1708
  const E = He(C.label, f), $ = C.fields.map((k) => {
1709
1709
  const N = He(k.label, f);
@@ -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(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"})});
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-form-improvements.7",
6
+ "version": "1.0.3",
7
7
  "type": "module",
8
8
  "main": "dist/forms.umd.cjs",
9
9
  "module": "dist/forms.js",