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