@overmap-ai/forms 1.0.15 → 1.0.17-blank-value-updates.1

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.
Files changed (155) hide show
  1. package/dist/ColorPicker/ColorPicker.d.ts +10 -0
  2. package/dist/ColorPicker/index.d.ts +1 -0
  3. package/dist/FileCard/FileCard.d.ts +7 -0
  4. package/dist/FileCard/index.d.ts +1 -0
  5. package/dist/FileIcon/FileIcon.d.ts +7 -0
  6. package/dist/FileIcon/index.d.ts +1 -0
  7. package/dist/ImageCard/ImageCard.d.ts +8 -0
  8. package/dist/ImageCard/index.d.ts +1 -0
  9. package/dist/ImageMarkup/ImageMarkup.d.ts +14 -0
  10. package/dist/ImageMarkup/index.d.ts +1 -0
  11. package/dist/ImageViewer/ImageViewer.d.ts +6 -0
  12. package/dist/ImageViewer/ImageViewerProvider.d.ts +2 -0
  13. package/dist/ImageViewer/context.d.ts +3 -0
  14. package/dist/ImageViewer/hooks.d.ts +1 -0
  15. package/dist/ImageViewer/index.d.ts +3 -0
  16. package/dist/ImageViewer/typings.d.ts +4 -0
  17. package/dist/constants.d.ts +1 -0
  18. package/dist/{builder → forms/builder}/DropDispatch.d.ts +2 -2
  19. package/dist/forms/builder/FieldActions.d.ts +13 -0
  20. package/dist/forms/builder/FieldBuilder.d.ts +10 -0
  21. package/dist/forms/builder/FieldSectionWithActions.d.ts +10 -0
  22. package/dist/forms/builder/FieldSettingsPopover.d.ts +8 -0
  23. package/dist/forms/builder/FieldWithActions.d.ts +9 -0
  24. package/dist/forms/builder/FieldsEditor.d.ts +1 -0
  25. package/dist/forms/builder/FormBuilder.d.ts +26 -0
  26. package/dist/forms/builder/constants.d.ts +18 -0
  27. package/dist/forms/builder/context.d.ts +6 -0
  28. package/dist/forms/builder/hooks.d.ts +7 -0
  29. package/dist/forms/builder/index.d.ts +2 -0
  30. package/dist/{builder → forms/builder}/typings.d.ts +5 -4
  31. package/dist/forms/builder/utils.d.ts +24 -0
  32. package/dist/forms/constants.d.ts +5 -0
  33. package/dist/{fields → forms/fields}/BaseField/BaseField.d.ts +23 -10
  34. package/dist/forms/fields/BaseField/hooks.d.ts +394 -0
  35. package/dist/forms/fields/BaseField/index.d.ts +4 -0
  36. package/dist/{fields → forms/fields}/BaseField/layouts.d.ts +11 -5
  37. package/dist/{fields → forms/fields}/BaseField/typings.d.ts +2 -2
  38. package/dist/forms/fields/BooleanField/BooleanField.d.ts +22 -0
  39. package/dist/forms/fields/BooleanField/BooleanInput.d.ts +3 -0
  40. package/dist/forms/fields/BooleanField/index.d.ts +2 -0
  41. package/dist/{fields → forms/fields}/CustomField/CustomField.d.ts +12 -6
  42. package/dist/{fields → forms/fields}/CustomField/FieldInputClonerField/FieldInputCloner.d.ts +2 -3
  43. package/dist/{fields → forms/fields}/CustomField/FieldInputClonerField/FieldInputClonerField.d.ts +3 -3
  44. package/dist/forms/fields/CustomField/FieldInputClonerField/index.d.ts +3 -0
  45. package/dist/forms/fields/CustomField/FieldInputClonerField/typings.d.ts +5 -0
  46. package/dist/forms/fields/CustomField/index.d.ts +1 -0
  47. package/dist/forms/fields/DateField/DateField.d.ts +21 -0
  48. package/dist/forms/fields/DateField/DateInput.d.ts +3 -0
  49. package/dist/forms/fields/DateField/index.d.ts +2 -0
  50. package/dist/{fields → forms/fields}/FieldSection/FieldSection.d.ts +13 -9
  51. package/dist/forms/fields/FieldSection/FieldSectionLayout.d.ts +6 -0
  52. package/dist/forms/fields/FieldSection/index.d.ts +1 -0
  53. package/dist/forms/fields/MultiStringField/MultiStringField.d.ts +40 -0
  54. package/dist/forms/fields/MultiStringField/MultiStringInput.d.ts +7 -0
  55. package/dist/forms/fields/MultiStringField/index.d.ts +2 -0
  56. package/dist/forms/fields/NumberField/NumberField.d.ts +44 -0
  57. package/dist/forms/fields/NumberField/NumberInput.d.ts +3 -0
  58. package/dist/forms/fields/NumberField/index.d.ts +2 -0
  59. package/dist/forms/fields/QrField/QrField.d.ts +21 -0
  60. package/dist/forms/fields/QrField/QrInput.d.ts +8 -0
  61. package/dist/forms/fields/QrField/index.d.ts +2 -0
  62. package/dist/{fields → forms/fields}/SelectField/BaseSelectField.d.ts +12 -5
  63. package/dist/{fields → forms/fields}/SelectField/MultiSelectField.d.ts +15 -8
  64. package/dist/forms/fields/SelectField/MultiSelectInput.d.ts +3 -0
  65. package/dist/{fields → forms/fields}/SelectField/SelectField.d.ts +13 -7
  66. package/dist/forms/fields/SelectField/SelectInput.d.ts +3 -0
  67. package/dist/forms/fields/SelectField/index.d.ts +4 -0
  68. package/dist/forms/fields/StringOrTextFields/StringField/StringField.d.ts +26 -0
  69. package/dist/forms/fields/StringOrTextFields/StringField/StringInput.d.ts +3 -0
  70. package/dist/forms/fields/StringOrTextFields/StringField/index.d.ts +2 -0
  71. package/dist/{fields → forms/fields}/StringOrTextFields/StringOrTextField.d.ts +15 -10
  72. package/dist/forms/fields/StringOrTextFields/TextField/TextField.d.ts +22 -0
  73. package/dist/forms/fields/StringOrTextFields/TextField/TextInput.d.ts +3 -0
  74. package/dist/forms/fields/StringOrTextFields/TextField/index.d.ts +2 -0
  75. package/dist/forms/fields/StringOrTextFields/index.d.ts +2 -0
  76. package/dist/forms/fields/UploadField/UploadField.d.ts +44 -0
  77. package/dist/forms/fields/UploadField/UploadInput.d.ts +3 -0
  78. package/dist/forms/fields/UploadField/index.d.ts +2 -0
  79. package/dist/forms/fields/constants.d.ts +106 -0
  80. package/dist/forms/fields/hooks.d.ts +6 -0
  81. package/dist/forms/fields/index.d.ts +12 -0
  82. package/dist/{fields → forms/fields}/typings.d.ts +10 -7
  83. package/dist/forms/fields/utils.d.ts +18 -0
  84. package/dist/forms/index.d.ts +6 -0
  85. package/dist/forms/renderer/FormRenderer/FormRenderer.d.ts +34 -0
  86. package/dist/forms/renderer/FormRenderer/constants.d.ts +3 -0
  87. package/dist/{renderer → forms/renderer}/PatchForm/Field.d.ts +5 -3
  88. package/dist/forms/renderer/PatchForm/Provider.d.ts +29 -0
  89. package/dist/forms/renderer/PatchForm/index.d.ts +2 -0
  90. package/dist/forms/renderer/index.d.ts +2 -0
  91. package/dist/forms/typings.d.ts +104 -0
  92. package/dist/forms/utils.d.ts +8 -0
  93. package/dist/forms.js +4368 -2452
  94. package/dist/forms.umd.cjs +44 -2777
  95. package/dist/index.d.ts +7 -3
  96. package/package.json +97 -94
  97. package/README.md +0 -12
  98. package/dist/builder/FieldActions.d.ts +0 -12
  99. package/dist/builder/FieldBuilder.d.ts +0 -24
  100. package/dist/builder/FieldSectionWithActions.d.ts +0 -10
  101. package/dist/builder/FieldWithActions.d.ts +0 -11
  102. package/dist/builder/FieldsEditor.d.ts +0 -2
  103. package/dist/builder/FormBuilder.d.ts +0 -15
  104. package/dist/builder/constants.d.ts +0 -1
  105. package/dist/builder/index.d.ts +0 -2
  106. package/dist/builder/utils.d.ts +0 -13
  107. package/dist/fields/BaseField/hooks.d.ts +0 -374
  108. package/dist/fields/BaseField/index.d.ts +0 -4
  109. package/dist/fields/BooleanField/BooleanField.d.ts +0 -17
  110. package/dist/fields/BooleanField/BooleanInput.d.ts +0 -4
  111. package/dist/fields/BooleanField/index.d.ts +0 -2
  112. package/dist/fields/CustomField/FieldInputClonerField/index.d.ts +0 -3
  113. package/dist/fields/CustomField/FieldInputClonerField/typings.d.ts +0 -5
  114. package/dist/fields/CustomField/index.d.ts +0 -1
  115. package/dist/fields/DateField/DateField.d.ts +0 -16
  116. package/dist/fields/DateField/DateInput.d.ts +0 -4
  117. package/dist/fields/DateField/index.d.ts +0 -2
  118. package/dist/fields/FieldSection/FieldSectionLayout.d.ts +0 -7
  119. package/dist/fields/FieldSection/index.d.ts +0 -1
  120. package/dist/fields/MultiStringField/MultiStringField.d.ts +0 -30
  121. package/dist/fields/MultiStringField/MultiStringInput.d.ts +0 -8
  122. package/dist/fields/MultiStringField/index.d.ts +0 -2
  123. package/dist/fields/NumberField/NumberField.d.ts +0 -29
  124. package/dist/fields/NumberField/NumberInput.d.ts +0 -4
  125. package/dist/fields/NumberField/index.d.ts +0 -2
  126. package/dist/fields/SelectField/MultiSelectInput.d.ts +0 -4
  127. package/dist/fields/SelectField/SelectInput.d.ts +0 -4
  128. package/dist/fields/SelectField/index.d.ts +0 -4
  129. package/dist/fields/StringOrTextFields/StringField/StringField.d.ts +0 -19
  130. package/dist/fields/StringOrTextFields/StringField/StringInput.d.ts +0 -4
  131. package/dist/fields/StringOrTextFields/StringField/index.d.ts +0 -2
  132. package/dist/fields/StringOrTextFields/TextField/TextField.d.ts +0 -16
  133. package/dist/fields/StringOrTextFields/TextField/TextInput.d.ts +0 -4
  134. package/dist/fields/StringOrTextFields/TextField/index.d.ts +0 -2
  135. package/dist/fields/StringOrTextFields/index.d.ts +0 -2
  136. package/dist/fields/UploadField/UploadField.d.ts +0 -29
  137. package/dist/fields/UploadField/UploadInput.d.ts +0 -4
  138. package/dist/fields/UploadField/index.d.ts +0 -2
  139. package/dist/fields/constants.d.ts +0 -20
  140. package/dist/fields/hooks.d.ts +0 -6
  141. package/dist/fields/index.d.ts +0 -11
  142. package/dist/fields/utils.d.ts +0 -13
  143. package/dist/forms.js.map +0 -1
  144. package/dist/forms.umd.cjs.map +0 -1
  145. package/dist/renderer/FormBrowser/FormBrowser.d.ts +0 -11
  146. package/dist/renderer/FormRenderer/FormRenderer.d.ts +0 -29
  147. package/dist/renderer/FormSubmissionBrowser/FormSubmissionBrowser.d.ts +0 -28
  148. package/dist/renderer/FormSubmissionViewer/FormSubmissionViewer.d.ts +0 -17
  149. package/dist/renderer/PatchForm/Provider.d.ts +0 -24
  150. package/dist/renderer/PatchForm/index.d.ts +0 -2
  151. package/dist/renderer/index.d.ts +0 -5
  152. package/dist/style.css +0 -34
  153. package/dist/typings.d.ts +0 -17
  154. package/dist/utils.d.ts +0 -7
  155. /package/dist/{fields → forms/fields}/UploadField/utils.d.ts +0 -0
@@ -1,2778 +1,45 @@
1
- (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("@overmap-ai/blocks"), require("formik"), require("react"), require("@radix-ui/react-icons"), require("@radix-ui/themes"), require("linkify-react"), require("@overmap-ai/core"), require("@hello-pangea/dnd"), require("lodash.get"), require("lodash.set"), require("lodash.clonedeep")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "@overmap-ai/blocks", "formik", "react", "@radix-ui/react-icons", "@radix-ui/themes", "linkify-react", "@overmap-ai/core", "@hello-pangea/dnd", "lodash.get", "lodash.set", "lodash.clonedeep"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.forms = {}, global.jsxRuntime, global.blocks, global.formik, global.React, global.reactIcons, global.themes, global.Linkify, global.core, global.dnd, global.get, global.set, global.cloneDeep));
3
- })(this, function(exports2, jsxRuntime, blocks, formik, React, reactIcons, themes, Linkify, core, dnd, get, set, cloneDeep) {
4
- "use strict";var __defProp = Object.defineProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => {
7
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- return value;
9
- };
1
+ (function(E,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("react"),require("formik"),require("react-dom"),require("react-icons/ri"),require("lodash.get"),require("lodash.set"),require("@hello-pangea/dnd"),require("qr-scanner"),require("lodash.clonedeep"),require("@overmap-ai/core"),require("react-sketch-canvas")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","react","formik","react-dom","react-icons/ri","lodash.get","lodash.set","@hello-pangea/dnd","qr-scanner","lodash.clonedeep","@overmap-ai/core","react-sketch-canvas"],o):(E=typeof globalThis<"u"?globalThis:E||self,o(E.forms={},E.jsxRuntime,E.blocks,E.React,E.formik,E.ReactDOM,E.ri,E.get,E.set,E.dnd,E.QrScannerAPI,E.cloneDeep,E.core,E.reactSketchCanvas))})(this,function(E,o,d,c,k,yn,H,R,$e,ie,ei,ti,de,ni){"use strict";var sa=Object.defineProperty;var la=(E,o,d)=>o in E?sa(E,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):E[o]=d;var N=(E,o,d)=>la(E,typeof o!="symbol"?o+"":o,d);function bn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,r.get?r:{enumerable:!0,get:()=>t[e]})}}return n.default=t,Object.freeze(n)}const v=bn(c),ri=bn(yn),wt=c.memo(t=>{const{selectedColor:n,allColors:e,onFinish:r,trigger:i}=t,a=c.useCallback(s=>()=>{r(s)},[r]);return o.jsxs(d.Popover.Root,{children:[o.jsx(d.Popover.Trigger,{children:i}),o.jsx(d.Popover.Content,{size:"sm",children:o.jsx("div",{className:"grid w-max grid-cols-7 gap-x-1 gap-y-1",children:e.map(s=>o.jsx(d.IconButton,{onClick:a(s),style:{backgroundColor:s},type:"button",variant:"solid","aria-label":s,children:n===s&&o.jsx(d.RiIcon,{icon:"RiCheckLine"})},s))})})]})});wt.displayName="ColorPicker";function Cn(t){var n,e,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var i=t.length;for(n=0;n<i;n++)t[n]&&(e=Cn(t[n]))&&(r&&(r+=" "),r+=e)}else for(e in t)t[e]&&(r&&(r+=" "),r+=e);return r}function ii(){for(var t,n,e=0,r="",i=arguments.length;e<i;e++)(t=arguments[e])&&(n=Cn(t))&&(r&&(r+=" "),r+=n);return r}const ye=ii,wn=["image/jpeg","image/png","image/svg+xml"],In=["text/csv","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel"],xn=["application/pdf"],ke=c.memo(t=>{const{fileType:n}=t,e=c.useMemo(()=>In.includes(n)?o.jsx(d.RiIcon,{icon:"RiFileExcelLine"}):xn.includes(n)?o.jsx(d.RiIcon,{icon:"RiFilePdfLine"}):wn.includes(n)?o.jsx(d.RiIcon,{icon:"RiFileImageLine"}):o.jsx(d.RiIcon,{icon:"RiFileLine"}),[n]);return o.jsx("div",{className:"h-max w-max",children:e})});ke.displayName="FileIcon";const It=c.memo(c.forwardRef((t,n)=>{const{file:e,className:r,error:i,rightSlot:a,...s}=t;return o.jsxs("div",{className:ye(r,"flex h-8 w-full items-center gap-2 rounded-md border border-(--base-a6) bg-(--base-2) text-sm py-1 px-2 h-max",{"text-(--gray-11)":i}),ref:n,...s,children:[i?o.jsx(d.RiIcon,{icon:"RiFileWarningLine"}):o.jsx(ke,{fileType:(e==null?void 0:e.type)??""}),i||(e?o.jsx(d.Text,{className:"truncate",children:e.name}):o.jsx("div",{className:"flex w-full justify-center",children:o.jsx(d.Spinner,{})})),a]})}));It.displayName="FileCard";const je=500,be=1e4,ue={danger:"danger",warning:"warning",info:"base",success:"success"},oi={boolean:"RiCheckboxCircleLine",date:"RiCalendarLine","multi-string":"RiListCheck",number:"RiHashtag",qr:"RiQrCodeLine","multi-select":"RiCheckboxLine",select:"RiMenuFoldLine",string:"RiInputField",text:"RiAlignJustify",upload:"RiUpload2Line",custom:"RiCodeSSlashLine",section:"RiFolderLine"};class xt{constructor(n){N(this,"type");N(this,"identifier");N(this,"description");const{description:e=null,identifier:r,type:i}=n;this.identifier=r,this.description=e,this.type=i}getId(){return this.identifier}static deserialize(n){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}const X={label:"",description:"",required:!1};class j extends xt{constructor(e){const{label:r,required:i,image:a,fieldValidators:s=[],formValidators:l=[],...m}=e;super(m);N(this,"required");N(this,"formValidators");N(this,"fieldValidators");N(this,"label");N(this,"image");N(this,"onlyValidateAfterTouched",!0);this.label=r,this.required=i,this.image=a,this.fieldValidators=s,this.formValidators=l}static getFieldCreationSchema(){return[]}isBlank(e){return e===void 0}isEqual(e,r){return e===r}getError(e,r){if(this.required&&this.isBlank(e))return"This field is required.";for(const i of this.getFieldValidators()){const a=i(e);if(a)return a}if(r)for(const i of this.getFormValidators()){const a=i(e,r);if(a)return a}}_serialize(){return{...super._serialize(),label:this.label,required:this.required,image:this.image}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}encodeValueToJson(e){return JSON.stringify(e)}decodeJsonToValue(e){return JSON.parse(e)}}N(j,"fieldTypeName"),N(j,"fieldTypeDescription");const K=t=>{const{id:n,field:e,formId:r,size:i,showInputOnly:a,onValuesChange:s,...l}=t,[m,u,f]=k.useField(e.getId()),{touched:h}=u,g=u.error??e.description,C=u.error?"danger":void 0,w=n??`${r}-${e.getId()}-input`,p=`${w}-label`,b=e.required?`${e.label} *`:e.label,I=c.useMemo(()=>({...m,onChange:T=>{f.setValue(T,!1).then(),s==null||s(e.getId(),T),(h||!e.onlyValidateAfterTouched)&&f.setError(e.getError(T))},onBlur:T=>{f.setTouched(!0,!1).then(),f.setError(e.getError(T))}}),[e,m,f,s,h]);return[{helpText:g,size:i,severity:C,inputId:w,labelId:p,label:b,showInputOnly:a,fieldProps:I,helpers:f,field:e,touched:h},{...l,"aria-labelledby":p}]},En=c.createContext(()=>{throw new Error("No ImageViewerProvider found")}),We=()=>c.useContext(En);function oe(t,n,{checkForDefaultPrevented:e=!0}={}){return function(i){if(t==null||t(i),e===!1||!i.defaultPrevented)return n==null?void 0:n(i)}}function Sn(t,n){if(typeof t=="function")return t(n);t!=null&&(t.current=n)}function Tn(...t){return n=>{let e=!1;const r=t.map(i=>{const a=Sn(i,n);return!e&&typeof a=="function"&&(e=!0),a});if(e)return()=>{for(let i=0;i<r.length;i++){const a=r[i];typeof a=="function"?a():Sn(t[i],null)}}}}function fe(...t){return v.useCallback(Tn(...t),t)}function ai(t,n){const e=v.createContext(n),r=a=>{const{children:s,...l}=a,m=v.useMemo(()=>l,Object.values(l));return o.jsx(e.Provider,{value:m,children:s})};r.displayName=t+"Provider";function i(a){const s=v.useContext(e);if(s)return s;if(n!==void 0)return n;throw new Error(`\`${a}\` must be used within \`${t}\``)}return[r,i]}function si(t,n=[]){let e=[];function r(a,s){const l=v.createContext(s),m=e.length;e=[...e,s];const u=h=>{var I;const{scope:g,children:C,...w}=h,p=((I=g==null?void 0:g[t])==null?void 0:I[m])||l,b=v.useMemo(()=>w,Object.values(w));return o.jsx(p.Provider,{value:b,children:C})};u.displayName=a+"Provider";function f(h,g){var p;const C=((p=g==null?void 0:g[t])==null?void 0:p[m])||l,w=v.useContext(C);if(w)return w;if(s!==void 0)return s;throw new Error(`\`${h}\` must be used within \`${a}\``)}return[u,f]}const i=()=>{const a=e.map(s=>v.createContext(s));return function(l){const m=(l==null?void 0:l[t])||a;return v.useMemo(()=>({[`__scope${t}`]:{...l,[t]:m}}),[l,m])}};return i.scopeName=t,[r,li(i,...n)]}function li(...t){const n=t[0];if(t.length===1)return n;const e=()=>{const r=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const s=r.reduce((l,{useScope:m,scopeName:u})=>{const h=m(a)[`__scope${u}`];return{...l,...h}},{});return v.useMemo(()=>({[`__scope${n.scopeName}`]:s}),[s])}};return e.scopeName=n.scopeName,e}var qe=globalThis!=null&&globalThis.document?v.useLayoutEffect:()=>{},ci=v.useId||(()=>{}),di=0;function Et(t){const[n,e]=v.useState(ci());return qe(()=>{e(r=>r??String(di++))},[t]),t||(n?`radix-${n}`:"")}function he(t){const n=v.useRef(t);return v.useEffect(()=>{n.current=t}),v.useMemo(()=>(...e)=>{var r;return(r=n.current)==null?void 0:r.call(n,...e)},[])}function ui({prop:t,defaultProp:n,onChange:e=()=>{}}){const[r,i]=fi({defaultProp:n,onChange:e}),a=t!==void 0,s=a?t:r,l=he(e),m=v.useCallback(u=>{if(a){const h=typeof u=="function"?u(t):u;h!==t&&l(h)}else i(u)},[a,t,i,l]);return[s,m]}function fi({defaultProp:t,onChange:n}){const e=v.useState(t),[r]=e,i=v.useRef(r),a=he(n);return v.useEffect(()=>{i.current!==r&&(a(r),i.current=r)},[r,i,a]),e}var St=v.forwardRef((t,n)=>{const{children:e,...r}=t,i=v.Children.toArray(e),a=i.find(pi);if(a){const s=a.props.children,l=i.map(m=>m===a?v.Children.count(s)>1?v.Children.only(null):v.isValidElement(s)?s.props.children:null:m);return o.jsx(Tt,{...r,ref:n,children:v.isValidElement(s)?v.cloneElement(s,void 0,l):null})}return o.jsx(Tt,{...r,ref:n,children:e})});St.displayName="Slot";var Tt=v.forwardRef((t,n)=>{const{children:e,...r}=t;if(v.isValidElement(e)){const i=gi(e);return v.cloneElement(e,{...mi(r,e.props),ref:n?Tn(n,i):i})}return v.Children.count(e)>1?v.Children.only(null):null});Tt.displayName="SlotClone";var hi=({children:t})=>o.jsx(o.Fragment,{children:t});function pi(t){return v.isValidElement(t)&&t.type===hi}function mi(t,n){const e={...n};for(const r in n){const i=t[r],a=n[r];/^on[A-Z]/.test(r)?i&&a?e[r]=(...l)=>{a(...l),i(...l)}:i&&(e[r]=i):r==="style"?e[r]={...i,...a}:r==="className"&&(e[r]=[i,a].filter(Boolean).join(" "))}return{...t,...e}}function gi(t){var r,i;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,e=n&&"isReactWarning"in n&&n.isReactWarning;return e?t.ref:(n=(i=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:i.get,e=n&&"isReactWarning"in n&&n.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var vi=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],re=vi.reduce((t,n)=>{const e=v.forwardRef((r,i)=>{const{asChild:a,...s}=r,l=a?St:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),o.jsx(l,{...s,ref:i})});return e.displayName=`Primitive.${n}`,{...t,[n]:e}},{});function yi(t,n){t&&ri.flushSync(()=>t.dispatchEvent(n))}function bi(t,n=globalThis==null?void 0:globalThis.document){const e=he(t);v.useEffect(()=>{const r=i=>{i.key==="Escape"&&e(i)};return n.addEventListener("keydown",r,{capture:!0}),()=>n.removeEventListener("keydown",r,{capture:!0})},[e,n])}var Ci="DismissableLayer",Nt="dismissableLayer.update",wi="dismissableLayer.pointerDownOutside",Ii="dismissableLayer.focusOutside",Nn,Fn=v.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ln=v.forwardRef((t,n)=>{const{disableOutsidePointerEvents:e=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:a,onInteractOutside:s,onDismiss:l,...m}=t,u=v.useContext(Fn),[f,h]=v.useState(null),g=(f==null?void 0:f.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,C]=v.useState({}),w=fe(n,F=>h(F)),p=Array.from(u.layers),[b]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),I=p.indexOf(b),x=f?p.indexOf(f):-1,y=u.layersWithOutsidePointerEventsDisabled.size>0,T=x>=I,S=Si(F=>{const D=F.target,M=[...u.branches].some(O=>O.contains(D));!T||M||(i==null||i(F),s==null||s(F),F.defaultPrevented||l==null||l())},g),L=Ti(F=>{const D=F.target;[...u.branches].some(O=>O.contains(D))||(a==null||a(F),s==null||s(F),F.defaultPrevented||l==null||l())},g);return bi(F=>{x===u.layers.size-1&&(r==null||r(F),!F.defaultPrevented&&l&&(F.preventDefault(),l()))},g),v.useEffect(()=>{if(f)return e&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(Nn=g.body.style.pointerEvents,g.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(f)),u.layers.add(f),Dn(),()=>{e&&u.layersWithOutsidePointerEventsDisabled.size===1&&(g.body.style.pointerEvents=Nn)}},[f,g,e,u]),v.useEffect(()=>()=>{f&&(u.layers.delete(f),u.layersWithOutsidePointerEventsDisabled.delete(f),Dn())},[f,u]),v.useEffect(()=>{const F=()=>C({});return document.addEventListener(Nt,F),()=>document.removeEventListener(Nt,F)},[]),o.jsx(re.div,{...m,ref:w,style:{pointerEvents:y?T?"auto":"none":void 0,...t.style},onFocusCapture:oe(t.onFocusCapture,L.onFocusCapture),onBlurCapture:oe(t.onBlurCapture,L.onBlurCapture),onPointerDownCapture:oe(t.onPointerDownCapture,S.onPointerDownCapture)})});Ln.displayName=Ci;var xi="DismissableLayerBranch",Ei=v.forwardRef((t,n)=>{const e=v.useContext(Fn),r=v.useRef(null),i=fe(n,r);return v.useEffect(()=>{const a=r.current;if(a)return e.branches.add(a),()=>{e.branches.delete(a)}},[e.branches]),o.jsx(re.div,{...t,ref:i})});Ei.displayName=xi;function Si(t,n=globalThis==null?void 0:globalThis.document){const e=he(t),r=v.useRef(!1),i=v.useRef(()=>{});return v.useEffect(()=>{const a=l=>{if(l.target&&!r.current){let m=function(){Mn(wi,e,u,{discrete:!0})};const u={originalEvent:l};l.pointerType==="touch"?(n.removeEventListener("click",i.current),i.current=m,n.addEventListener("click",i.current,{once:!0})):m()}else n.removeEventListener("click",i.current);r.current=!1},s=window.setTimeout(()=>{n.addEventListener("pointerdown",a)},0);return()=>{window.clearTimeout(s),n.removeEventListener("pointerdown",a),n.removeEventListener("click",i.current)}},[n,e]),{onPointerDownCapture:()=>r.current=!0}}function Ti(t,n=globalThis==null?void 0:globalThis.document){const e=he(t),r=v.useRef(!1);return v.useEffect(()=>{const i=a=>{a.target&&!r.current&&Mn(Ii,e,{originalEvent:a},{discrete:!1})};return n.addEventListener("focusin",i),()=>n.removeEventListener("focusin",i)},[n,e]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function Dn(){const t=new CustomEvent(Nt);document.dispatchEvent(t)}function Mn(t,n,e,{discrete:r}){const i=e.originalEvent.target,a=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:e});n&&i.addEventListener(t,n,{once:!0}),r?yi(i,a):i.dispatchEvent(a)}var Ft="focusScope.autoFocusOnMount",Lt="focusScope.autoFocusOnUnmount",Pn={bubbles:!1,cancelable:!0},Ni="FocusScope",An=v.forwardRef((t,n)=>{const{loop:e=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:a,...s}=t,[l,m]=v.useState(null),u=he(i),f=he(a),h=v.useRef(null),g=fe(n,p=>m(p)),C=v.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;v.useEffect(()=>{if(r){let p=function(y){if(C.paused||!l)return;const T=y.target;l.contains(T)?h.current=T:ae(h.current,{select:!0})},b=function(y){if(C.paused||!l)return;const T=y.relatedTarget;T!==null&&(l.contains(T)||ae(h.current,{select:!0}))},I=function(y){if(document.activeElement===document.body)for(const S of y)S.removedNodes.length>0&&ae(l)};document.addEventListener("focusin",p),document.addEventListener("focusout",b);const x=new MutationObserver(I);return l&&x.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",p),document.removeEventListener("focusout",b),x.disconnect()}}},[r,l,C.paused]),v.useEffect(()=>{if(l){zn.add(C);const p=document.activeElement;if(!l.contains(p)){const I=new CustomEvent(Ft,Pn);l.addEventListener(Ft,u),l.dispatchEvent(I),I.defaultPrevented||(Fi(Ai(On(l)),{select:!0}),document.activeElement===p&&ae(l))}return()=>{l.removeEventListener(Ft,u),setTimeout(()=>{const I=new CustomEvent(Lt,Pn);l.addEventListener(Lt,f),l.dispatchEvent(I),I.defaultPrevented||ae(p??document.body,{select:!0}),l.removeEventListener(Lt,f),zn.remove(C)},0)}}},[l,u,f,C]);const w=v.useCallback(p=>{if(!e&&!r||C.paused)return;const b=p.key==="Tab"&&!p.altKey&&!p.ctrlKey&&!p.metaKey,I=document.activeElement;if(b&&I){const x=p.currentTarget,[y,T]=Li(x);y&&T?!p.shiftKey&&I===T?(p.preventDefault(),e&&ae(y,{select:!0})):p.shiftKey&&I===y&&(p.preventDefault(),e&&ae(T,{select:!0})):I===x&&p.preventDefault()}},[e,r,C.paused]);return o.jsx(re.div,{tabIndex:-1,...s,ref:g,onKeyDown:w})});An.displayName=Ni;function Fi(t,{select:n=!1}={}){const e=document.activeElement;for(const r of t)if(ae(r,{select:n}),document.activeElement!==e)return}function Li(t){const n=On(t),e=Bn(n,t),r=Bn(n.reverse(),t);return[e,r]}function On(t){const n=[],e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;e.nextNode();)n.push(e.currentNode);return n}function Bn(t,n){for(const e of t)if(!Di(e,{upTo:n}))return e}function Di(t,{upTo:n}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(n!==void 0&&t===n)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Mi(t){return t instanceof HTMLInputElement&&"select"in t}function ae(t,{select:n=!1}={}){if(t&&t.focus){const e=document.activeElement;t.focus({preventScroll:!0}),t!==e&&Mi(t)&&n&&t.select()}}var zn=Pi();function Pi(){let t=[];return{add(n){const e=t[0];n!==e&&(e==null||e.pause()),t=_n(t,n),t.unshift(n)},remove(n){var e;t=_n(t,n),(e=t[0])==null||e.resume()}}}function _n(t,n){const e=[...t],r=e.indexOf(n);return r!==-1&&e.splice(r,1),e}function Ai(t){return t.filter(n=>n.tagName!=="A")}var Oi="Portal",Vn=v.forwardRef((t,n)=>{var l;const{container:e,...r}=t,[i,a]=v.useState(!1);qe(()=>a(!0),[]);const s=e||i&&((l=globalThis==null?void 0:globalThis.document)==null?void 0:l.body);return s?yn.createPortal(o.jsx(re.div,{...r,ref:n}),s):null});Vn.displayName=Oi;function Bi(t,n){return v.useReducer((e,r)=>n[e][r]??e,t)}var He=t=>{const{present:n,children:e}=t,r=zi(n),i=typeof e=="function"?e({present:r.isPresent}):v.Children.only(e),a=fe(r.ref,_i(i));return typeof e=="function"||r.isPresent?v.cloneElement(i,{ref:a}):null};He.displayName="Presence";function zi(t){const[n,e]=v.useState(),r=v.useRef({}),i=v.useRef(t),a=v.useRef("none"),s=t?"mounted":"unmounted",[l,m]=Bi(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return v.useEffect(()=>{const u=Ge(r.current);a.current=l==="mounted"?u:"none"},[l]),qe(()=>{const u=r.current,f=i.current;if(f!==t){const g=a.current,C=Ge(u);t?m("MOUNT"):C==="none"||(u==null?void 0:u.display)==="none"?m("UNMOUNT"):m(f&&g!==C?"ANIMATION_OUT":"UNMOUNT"),i.current=t}},[t,m]),qe(()=>{if(n){let u;const f=n.ownerDocument.defaultView??window,h=C=>{const p=Ge(r.current).includes(C.animationName);if(C.target===n&&p&&(m("ANIMATION_END"),!i.current)){const b=n.style.animationFillMode;n.style.animationFillMode="forwards",u=f.setTimeout(()=>{n.style.animationFillMode==="forwards"&&(n.style.animationFillMode=b)})}},g=C=>{C.target===n&&(a.current=Ge(r.current))};return n.addEventListener("animationstart",g),n.addEventListener("animationcancel",h),n.addEventListener("animationend",h),()=>{f.clearTimeout(u),n.removeEventListener("animationstart",g),n.removeEventListener("animationcancel",h),n.removeEventListener("animationend",h)}}else m("ANIMATION_END")},[n,m]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:v.useCallback(u=>{u&&(r.current=getComputedStyle(u)),e(u)},[])}}function Ge(t){return(t==null?void 0:t.animationName)||"none"}function _i(t){var r,i;let n=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,e=n&&"isReactWarning"in n&&n.isReactWarning;return e?t.ref:(n=(i=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:i.get,e=n&&"isReactWarning"in n&&n.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Dt=0;function Vi(){v.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??Un()),document.body.insertAdjacentElement("beforeend",t[1]??Un()),Dt++,()=>{Dt===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(n=>n.remove()),Dt--}},[])}function Un(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var ee=function(){return ee=Object.assign||function(n){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a])}return n},ee.apply(this,arguments)};function $n(t,n){var e={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.indexOf(r)<0&&(e[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)n.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(e[r[i]]=t[r[i]]);return e}function Ui(t,n,e){if(e||arguments.length===2)for(var r=0,i=n.length,a;r<i;r++)(a||!(r in n))&&(a||(a=Array.prototype.slice.call(n,0,r)),a[r]=n[r]);return t.concat(a||Array.prototype.slice.call(n))}typeof SuppressedError=="function"&&SuppressedError;var Xe="right-scroll-bar-position",Ke="width-before-scroll-bar",$i="with-scroll-bars-hidden",ki="--removed-body-scroll-bar-size";function Mt(t,n){return typeof t=="function"?t(n):t&&(t.current=n),t}function ji(t,n){var e=c.useState(function(){return{value:t,callback:n,facade:{get current(){return e.value},set current(r){var i=e.value;i!==r&&(e.value=r,e.callback(r,i))}}}})[0];return e.callback=n,e.facade}var Wi=typeof window<"u"?v.useLayoutEffect:v.useEffect,kn=new WeakMap;function qi(t,n){var e=ji(null,function(r){return t.forEach(function(i){return Mt(i,r)})});return Wi(function(){var r=kn.get(e);if(r){var i=new Set(r),a=new Set(t),s=e.current;i.forEach(function(l){a.has(l)||Mt(l,null)}),a.forEach(function(l){i.has(l)||Mt(l,s)})}kn.set(e,t)},[t]),e}function Hi(t){return t}function Gi(t,n){n===void 0&&(n=Hi);var e=[],r=!1,i={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return e.length?e[e.length-1]:t},useMedium:function(a){var s=n(a,r);return e.push(s),function(){e=e.filter(function(l){return l!==s})}},assignSyncMedium:function(a){for(r=!0;e.length;){var s=e;e=[],s.forEach(a)}e={push:function(l){return a(l)},filter:function(){return e}}},assignMedium:function(a){r=!0;var s=[];if(e.length){var l=e;e=[],l.forEach(a),s=e}var m=function(){var f=s;s=[],f.forEach(a)},u=function(){return Promise.resolve().then(m)};u(),e={push:function(f){s.push(f),u()},filter:function(f){return s=s.filter(f),e}}}};return i}function Xi(t){t===void 0&&(t={});var n=Gi(null);return n.options=ee({async:!0,ssr:!1},t),n}var jn=function(t){var n=t.sideCar,e=$n(t,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return v.createElement(r,ee({},e))};jn.isSideCarExport=!0;function Ki(t,n){return t.useMedium(n),jn}var Wn=Xi(),Pt=function(){},Qe=v.forwardRef(function(t,n){var e=v.useRef(null),r=v.useState({onScrollCapture:Pt,onWheelCapture:Pt,onTouchMoveCapture:Pt}),i=r[0],a=r[1],s=t.forwardProps,l=t.children,m=t.className,u=t.removeScrollBar,f=t.enabled,h=t.shards,g=t.sideCar,C=t.noIsolation,w=t.inert,p=t.allowPinchZoom,b=t.as,I=b===void 0?"div":b,x=t.gapMode,y=$n(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),T=g,S=qi([e,n]),L=ee(ee({},y),i);return v.createElement(v.Fragment,null,f&&v.createElement(T,{sideCar:Wn,removeScrollBar:u,shards:h,noIsolation:C,inert:w,setCallbacks:a,allowPinchZoom:!!p,lockRef:e,gapMode:x}),s?v.cloneElement(v.Children.only(l),ee(ee({},L),{ref:S})):v.createElement(I,ee({},L,{className:m,ref:S}),l))});Qe.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Qe.classNames={fullWidth:Ke,zeroRight:Xe};var Qi=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Yi(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var n=Qi();return n&&t.setAttribute("nonce",n),t}function Ji(t,n){t.styleSheet?t.styleSheet.cssText=n:t.appendChild(document.createTextNode(n))}function Zi(t){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(t)}var Ri=function(){var t=0,n=null;return{add:function(e){t==0&&(n=Yi())&&(Ji(n,e),Zi(n)),t++},remove:function(){t--,!t&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},eo=function(){var t=Ri();return function(n,e){v.useEffect(function(){return t.add(n),function(){t.remove()}},[n&&e])}},qn=function(){var t=eo(),n=function(e){var r=e.styles,i=e.dynamic;return t(r,i),null};return n},to={left:0,top:0,right:0,gap:0},At=function(t){return parseInt(t||"",10)||0},no=function(t){var n=window.getComputedStyle(document.body),e=n[t==="padding"?"paddingLeft":"marginLeft"],r=n[t==="padding"?"paddingTop":"marginTop"],i=n[t==="padding"?"paddingRight":"marginRight"];return[At(e),At(r),At(i)]},ro=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return to;var n=no(t),e=document.documentElement.clientWidth,r=window.innerWidth;return{left:n[0],top:n[1],right:n[2],gap:Math.max(0,r-e+n[2]-n[0])}},io=qn(),Ce="data-scroll-locked",oo=function(t,n,e,r){var i=t.left,a=t.top,s=t.right,l=t.gap;return e===void 0&&(e="margin"),`
2
+ .`.concat($i,` {
3
+ overflow: hidden `).concat(r,`;
4
+ padding-right: `).concat(l,"px ").concat(r,`;
5
+ }
6
+ body[`).concat(Ce,`] {
7
+ overflow: hidden `).concat(r,`;
8
+ overscroll-behavior: contain;
9
+ `).concat([n&&"position: relative ".concat(r,";"),e==="margin"&&`
10
+ padding-left: `.concat(i,`px;
11
+ padding-top: `).concat(a,`px;
12
+ padding-right: `).concat(s,`px;
13
+ margin-left:0;
14
+ margin-top:0;
15
+ margin-right: `).concat(l,"px ").concat(r,`;
16
+ `),e==="padding"&&"padding-right: ".concat(l,"px ").concat(r,";")].filter(Boolean).join(""),`
17
+ }
18
+
19
+ .`).concat(Xe,` {
20
+ right: `).concat(l,"px ").concat(r,`;
21
+ }
22
+
23
+ .`).concat(Ke,` {
24
+ margin-right: `).concat(l,"px ").concat(r,`;
25
+ }
26
+
27
+ .`).concat(Xe," .").concat(Xe,` {
28
+ right: 0 `).concat(r,`;
29
+ }
30
+
31
+ .`).concat(Ke," .").concat(Ke,` {
32
+ margin-right: 0 `).concat(r,`;
33
+ }
34
+
35
+ body[`).concat(Ce,`] {
36
+ `).concat(ki,": ").concat(l,`px;
37
+ }
38
+ `)},Hn=function(){var t=parseInt(document.body.getAttribute(Ce)||"0",10);return isFinite(t)?t:0},ao=function(){v.useEffect(function(){return document.body.setAttribute(Ce,(Hn()+1).toString()),function(){var t=Hn()-1;t<=0?document.body.removeAttribute(Ce):document.body.setAttribute(Ce,t.toString())}},[])},so=function(t){var n=t.noRelative,e=t.noImportant,r=t.gapMode,i=r===void 0?"margin":r;ao();var a=v.useMemo(function(){return ro(i)},[i]);return v.createElement(io,{styles:oo(a,!n,i,e?"":"!important")})},Ot=!1;if(typeof window<"u")try{var Ye=Object.defineProperty({},"passive",{get:function(){return Ot=!0,!0}});window.addEventListener("test",Ye,Ye),window.removeEventListener("test",Ye,Ye)}catch{Ot=!1}var we=Ot?{passive:!1}:!1,lo=function(t){return t.tagName==="TEXTAREA"},Gn=function(t,n){if(!(t instanceof Element))return!1;var e=window.getComputedStyle(t);return e[n]!=="hidden"&&!(e.overflowY===e.overflowX&&!lo(t)&&e[n]==="visible")},co=function(t){return Gn(t,"overflowY")},uo=function(t){return Gn(t,"overflowX")},Xn=function(t,n){var e=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var i=Kn(t,r);if(i){var a=Qn(t,r),s=a[1],l=a[2];if(s>l)return!0}r=r.parentNode}while(r&&r!==e.body);return!1},fo=function(t){var n=t.scrollTop,e=t.scrollHeight,r=t.clientHeight;return[n,e,r]},ho=function(t){var n=t.scrollLeft,e=t.scrollWidth,r=t.clientWidth;return[n,e,r]},Kn=function(t,n){return t==="v"?co(n):uo(n)},Qn=function(t,n){return t==="v"?fo(n):ho(n)},po=function(t,n){return t==="h"&&n==="rtl"?-1:1},mo=function(t,n,e,r,i){var a=po(t,window.getComputedStyle(n).direction),s=a*r,l=e.target,m=n.contains(l),u=!1,f=s>0,h=0,g=0;do{var C=Qn(t,l),w=C[0],p=C[1],b=C[2],I=p-b-a*w;(w||I)&&Kn(t,l)&&(h+=I,g+=w),l instanceof ShadowRoot?l=l.host:l=l.parentNode}while(!m&&l!==document.body||m&&(n.contains(l)||n===l));return(f&&Math.abs(h)<1||!f&&Math.abs(g)<1)&&(u=!0),u},Je=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},Yn=function(t){return[t.deltaX,t.deltaY]},Jn=function(t){return t&&"current"in t?t.current:t},go=function(t,n){return t[0]===n[0]&&t[1]===n[1]},vo=function(t){return`
39
+ .block-interactivity-`.concat(t,` {pointer-events: none;}
40
+ .allow-interactivity-`).concat(t,` {pointer-events: all;}
41
+ `)},yo=0,Ie=[];function bo(t){var n=v.useRef([]),e=v.useRef([0,0]),r=v.useRef(),i=v.useState(yo++)[0],a=v.useState(qn)[0],s=v.useRef(t);v.useEffect(function(){s.current=t},[t]),v.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(i));var p=Ui([t.lockRef.current],(t.shards||[]).map(Jn),!0).filter(Boolean);return p.forEach(function(b){return b.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),p.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(i))})}}},[t.inert,t.lockRef.current,t.shards]);var l=v.useCallback(function(p,b){if("touches"in p&&p.touches.length===2||p.type==="wheel"&&p.ctrlKey)return!s.current.allowPinchZoom;var I=Je(p),x=e.current,y="deltaX"in p?p.deltaX:x[0]-I[0],T="deltaY"in p?p.deltaY:x[1]-I[1],S,L=p.target,F=Math.abs(y)>Math.abs(T)?"h":"v";if("touches"in p&&F==="h"&&L.type==="range")return!1;var D=Xn(F,L);if(!D)return!0;if(D?S=F:(S=F==="v"?"h":"v",D=Xn(F,L)),!D)return!1;if(!r.current&&"changedTouches"in p&&(y||T)&&(r.current=S),!S)return!0;var M=r.current||S;return mo(M,b,p,M==="h"?y:T)},[]),m=v.useCallback(function(p){var b=p;if(!(!Ie.length||Ie[Ie.length-1]!==a)){var I="deltaY"in b?Yn(b):Je(b),x=n.current.filter(function(S){return S.name===b.type&&(S.target===b.target||b.target===S.shadowParent)&&go(S.delta,I)})[0];if(x&&x.should){b.cancelable&&b.preventDefault();return}if(!x){var y=(s.current.shards||[]).map(Jn).filter(Boolean).filter(function(S){return S.contains(b.target)}),T=y.length>0?l(b,y[0]):!s.current.noIsolation;T&&b.cancelable&&b.preventDefault()}}},[]),u=v.useCallback(function(p,b,I,x){var y={name:p,delta:b,target:I,should:x,shadowParent:Co(I)};n.current.push(y),setTimeout(function(){n.current=n.current.filter(function(T){return T!==y})},1)},[]),f=v.useCallback(function(p){e.current=Je(p),r.current=void 0},[]),h=v.useCallback(function(p){u(p.type,Yn(p),p.target,l(p,t.lockRef.current))},[]),g=v.useCallback(function(p){u(p.type,Je(p),p.target,l(p,t.lockRef.current))},[]);v.useEffect(function(){return Ie.push(a),t.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:g}),document.addEventListener("wheel",m,we),document.addEventListener("touchmove",m,we),document.addEventListener("touchstart",f,we),function(){Ie=Ie.filter(function(p){return p!==a}),document.removeEventListener("wheel",m,we),document.removeEventListener("touchmove",m,we),document.removeEventListener("touchstart",f,we)}},[]);var C=t.removeScrollBar,w=t.inert;return v.createElement(v.Fragment,null,w?v.createElement(a,{styles:vo(i)}):null,C?v.createElement(so,{gapMode:t.gapMode}):null)}function Co(t){for(var n=null;t!==null;)t instanceof ShadowRoot&&(n=t.host,t=t.host),t=t.parentNode;return n}const wo=Ki(Wn,bo);var Zn=v.forwardRef(function(t,n){return v.createElement(Qe,ee({},t,{ref:n,sideCar:wo}))});Zn.classNames=Qe.classNames;var Io=function(t){if(typeof document>"u")return null;var n=Array.isArray(t)?t[0]:t;return n.ownerDocument.body},xe=new WeakMap,Ze=new WeakMap,Re={},Bt=0,Rn=function(t){return t&&(t.host||Rn(t.parentNode))},xo=function(t,n){return n.map(function(e){if(t.contains(e))return e;var r=Rn(e);return r&&t.contains(r)?r:(console.error("aria-hidden",e,"in not contained inside",t,". Doing nothing"),null)}).filter(function(e){return!!e})},Eo=function(t,n,e,r){var i=xo(n,Array.isArray(t)?t:[t]);Re[e]||(Re[e]=new WeakMap);var a=Re[e],s=[],l=new Set,m=new Set(i),u=function(h){!h||l.has(h)||(l.add(h),u(h.parentNode))};i.forEach(u);var f=function(h){!h||m.has(h)||Array.prototype.forEach.call(h.children,function(g){if(l.has(g))f(g);else try{var C=g.getAttribute(r),w=C!==null&&C!=="false",p=(xe.get(g)||0)+1,b=(a.get(g)||0)+1;xe.set(g,p),a.set(g,b),s.push(g),p===1&&w&&Ze.set(g,!0),b===1&&g.setAttribute(e,"true"),w||g.setAttribute(r,"true")}catch(I){console.error("aria-hidden: cannot operate on ",g,I)}})};return f(n),l.clear(),Bt++,function(){s.forEach(function(h){var g=xe.get(h)-1,C=a.get(h)-1;xe.set(h,g),a.set(h,C),g||(Ze.has(h)||h.removeAttribute(r),Ze.delete(h)),C||h.removeAttribute(e)}),Bt--,Bt||(xe=new WeakMap,xe=new WeakMap,Ze=new WeakMap,Re={})}},So=function(t,n,e){e===void 0&&(e="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),i=Io(t);return i?(r.push.apply(r,Array.from(i.querySelectorAll("[aria-live]"))),Eo(r,i,e,"aria-hidden")):function(){return null}},zt="Dialog",[er,ca]=si(zt),[To,Q]=er(zt),tr=t=>{const{__scopeDialog:n,children:e,open:r,defaultOpen:i,onOpenChange:a,modal:s=!0}=t,l=v.useRef(null),m=v.useRef(null),[u=!1,f]=ui({prop:r,defaultProp:i,onChange:a});return o.jsx(To,{scope:n,triggerRef:l,contentRef:m,contentId:Et(),titleId:Et(),descriptionId:Et(),open:u,onOpenChange:f,onOpenToggle:v.useCallback(()=>f(h=>!h),[f]),modal:s,children:e})};tr.displayName=zt;var nr="DialogTrigger",rr=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,i=Q(nr,e),a=fe(n,i.triggerRef);return o.jsx(re.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":Ut(i.open),...r,ref:a,onClick:oe(t.onClick,i.onOpenToggle)})});rr.displayName=nr;var _t="DialogPortal",[No,ir]=er(_t,{forceMount:void 0}),or=t=>{const{__scopeDialog:n,forceMount:e,children:r,container:i}=t,a=Q(_t,n);return o.jsx(No,{scope:n,forceMount:e,children:v.Children.map(r,s=>o.jsx(He,{present:e||a.open,children:o.jsx(Vn,{asChild:!0,container:i,children:s})}))})};or.displayName=_t;var et="DialogOverlay",ar=v.forwardRef((t,n)=>{const e=ir(et,t.__scopeDialog),{forceMount:r=e.forceMount,...i}=t,a=Q(et,t.__scopeDialog);return a.modal?o.jsx(He,{present:r||a.open,children:o.jsx(Fo,{...i,ref:n})}):null});ar.displayName=et;var Fo=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,i=Q(et,e);return o.jsx(Zn,{as:St,allowPinchZoom:!0,shards:[i.contentRef],children:o.jsx(re.div,{"data-state":Ut(i.open),...r,ref:n,style:{pointerEvents:"auto",...r.style}})})}),pe="DialogContent",sr=v.forwardRef((t,n)=>{const e=ir(pe,t.__scopeDialog),{forceMount:r=e.forceMount,...i}=t,a=Q(pe,t.__scopeDialog);return o.jsx(He,{present:r||a.open,children:a.modal?o.jsx(Lo,{...i,ref:n}):o.jsx(Do,{...i,ref:n})})});sr.displayName=pe;var Lo=v.forwardRef((t,n)=>{const e=Q(pe,t.__scopeDialog),r=v.useRef(null),i=fe(n,e.contentRef,r);return v.useEffect(()=>{const a=r.current;if(a)return So(a)},[]),o.jsx(lr,{...t,ref:i,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:oe(t.onCloseAutoFocus,a=>{var s;a.preventDefault(),(s=e.triggerRef.current)==null||s.focus()}),onPointerDownOutside:oe(t.onPointerDownOutside,a=>{const s=a.detail.originalEvent,l=s.button===0&&s.ctrlKey===!0;(s.button===2||l)&&a.preventDefault()}),onFocusOutside:oe(t.onFocusOutside,a=>a.preventDefault())})}),Do=v.forwardRef((t,n)=>{const e=Q(pe,t.__scopeDialog),r=v.useRef(!1),i=v.useRef(!1);return o.jsx(lr,{...t,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:a=>{var s,l;(s=t.onCloseAutoFocus)==null||s.call(t,a),a.defaultPrevented||(r.current||(l=e.triggerRef.current)==null||l.focus(),a.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:a=>{var m,u;(m=t.onInteractOutside)==null||m.call(t,a),a.defaultPrevented||(r.current=!0,a.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const s=a.target;((u=e.triggerRef.current)==null?void 0:u.contains(s))&&a.preventDefault(),a.detail.originalEvent.type==="focusin"&&i.current&&a.preventDefault()}})}),lr=v.forwardRef((t,n)=>{const{__scopeDialog:e,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...s}=t,l=Q(pe,e),m=v.useRef(null),u=fe(n,m);return Vi(),o.jsxs(o.Fragment,{children:[o.jsx(An,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:o.jsx(Ln,{role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":Ut(l.open),...s,ref:u,onDismiss:()=>l.onOpenChange(!1)})}),o.jsxs(o.Fragment,{children:[o.jsx(Ao,{titleId:l.titleId}),o.jsx(Bo,{contentRef:m,descriptionId:l.descriptionId})]})]})}),Vt="DialogTitle",Mo=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,i=Q(Vt,e);return o.jsx(re.h2,{id:i.titleId,...r,ref:n})});Mo.displayName=Vt;var cr="DialogDescription",Po=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,i=Q(cr,e);return o.jsx(re.p,{id:i.descriptionId,...r,ref:n})});Po.displayName=cr;var dr="DialogClose",ur=v.forwardRef((t,n)=>{const{__scopeDialog:e,...r}=t,i=Q(dr,e);return o.jsx(re.button,{type:"button",...r,ref:n,onClick:oe(t.onClick,()=>i.onOpenChange(!1))})});ur.displayName=dr;function Ut(t){return t?"open":"closed"}var fr="DialogTitleWarning",[da,hr]=ai(fr,{contentName:pe,titleName:Vt,docsSlug:"dialog"}),Ao=({titleId:t})=>{const n=hr(fr),e=`\`${n.contentName}\` requires a \`${n.titleName}\` for the component to be accessible for screen reader users.
10
42
 
11
- class BaseFormElement {
12
- constructor(options) {
13
- __publicField(this, "type");
14
- __publicField(this, "identifier");
15
- __publicField(this, "description");
16
- const { description: description2 = null, identifier, type } = options;
17
- this.identifier = identifier;
18
- this.description = description2;
19
- this.type = type;
20
- }
21
- getId() {
22
- return this.identifier;
23
- }
24
- static deserialize(_data) {
25
- throw new Error(`${this.name} must implement deserialize.`);
26
- }
27
- _serialize() {
28
- if (!this.identifier) {
29
- throw new Error("Field identifier must be set before serializing.");
30
- }
31
- return {
32
- type: this.type,
33
- identifier: this.identifier,
34
- description: this.description
35
- };
36
- }
37
- }
38
- class BaseField extends BaseFormElement {
39
- constructor(options) {
40
- const { label, required, fieldValidators = [], formValidators = [], ...base } = options;
41
- super(base);
42
- __publicField(this, "required");
43
- __publicField(this, "formValidators");
44
- __publicField(this, "fieldValidators");
45
- __publicField(this, "label");
46
- /**
47
- * By default, validation doesn't execute on `onChange` events when editing fields
48
- * until the field has been `touched`. This can be overridden by setting this to `false`
49
- * if you want to validate on every `onChange` event. This is important for fields like booleans
50
- * which don't have a `onBlur` event (which is used to set the `touched` state).
51
- */
52
- __publicField(this, "onlyValidateAfterTouched", true);
53
- this.label = label;
54
- this.required = required;
55
- this.fieldValidators = fieldValidators;
56
- this.formValidators = formValidators;
57
- }
58
- static getFieldCreationSchema() {
59
- return [];
60
- }
61
- isBlank(value) {
62
- return value === null || value === void 0 || value === "";
63
- }
64
- getValueFromChangeEvent(event) {
65
- return event.target.value;
66
- }
67
- getError(value, allValues) {
68
- if (this.required && this.isBlank(value)) {
69
- return "This field is required.";
70
- }
71
- for (const validator of this.getFieldValidators()) {
72
- const error = validator(value);
73
- if (error)
74
- return error;
75
- }
76
- if (allValues) {
77
- for (const validator of this.getFormValidators()) {
78
- const error = validator(value, allValues);
79
- if (error)
80
- return error;
81
- }
82
- }
83
- }
84
- // TODO: We can probably combine _serialize and serialize.
85
- _serialize() {
86
- return {
87
- ...super._serialize(),
88
- label: this.label,
89
- required: this.required
90
- };
91
- }
92
- getFieldValidators() {
93
- return [...this.fieldValidators];
94
- }
95
- getFormValidators() {
96
- return [...this.formValidators];
97
- }
98
- }
99
- __publicField(BaseField, "fieldTypeName");
100
- __publicField(BaseField, "fieldTypeDescription");
101
- const description$1 = "_description_17zed_1";
102
- const styles$4 = {
103
- description: description$1
104
- };
105
- const InputWithLabel = (props) => {
106
- const { label, children, severity, inputId, labelId, flexProps } = props;
107
- return /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "column", gap: "1", asChild: true, ...flexProps, children: /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: inputId, children: [
108
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { severity, id: labelId, children: label }),
109
- children
110
- ] }) });
111
- };
112
- const InputWithLabelAndHelpText = (props) => {
113
- const { helpText, children, severity } = props;
114
- return /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "1", children: [
115
- children,
116
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "column", children: /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "1", severity, className: styles$4.description, children: helpText }) })
117
- ] });
118
- };
119
- const useFormikInput = (props) => {
120
- const { id, field, formId: formId2, ...rest } = props;
121
- const [fieldProps, meta, helpers] = formik.useField(field.getId());
122
- const { touched } = meta;
123
- const helpText = meta.error ?? field.description;
124
- const severity = meta.error ? "danger" : void 0;
125
- const inputId = id ?? `${formId2}-${field.getId()}-input`;
126
- const labelId = `${inputId}-label`;
127
- const label = field.required ? `${field.label} *` : field.label;
128
- const fieldPropsWithValidation = React.useMemo(() => {
129
- const handleChange = (e) => {
130
- const value = field.getValueFromChangeEvent(e);
131
- helpers.setValue(value, false).then();
132
- if (touched || !field.onlyValidateAfterTouched) {
133
- helpers.setError(field.getError(value));
134
- }
135
- };
136
- const handleBlur = (e) => {
137
- helpers.setTouched(true, false).then();
138
- helpers.setError(field.getError(field.getValueFromChangeEvent(e)));
139
- };
140
- return {
141
- ...fieldProps,
142
- onChange: handleChange,
143
- onBlur: handleBlur
144
- };
145
- }, [field, fieldProps, helpers, touched]);
146
- return [
147
- {
148
- helpText,
149
- severity,
150
- inputId,
151
- labelId,
152
- label,
153
- fieldProps: fieldPropsWithValidation,
154
- helpers,
155
- field
156
- },
157
- { ...rest, "aria-labelledby": labelId }
158
- ];
159
- };
160
- const truthyValues = [true, "true"];
161
- const BooleanInput = React.memo(function BooleanInput2(props) {
162
- const [{ inputId, labelId, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
163
- const color = blocks.useSeverityColor(severity);
164
- const value = truthyValues.includes(fieldProps.value);
165
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(
166
- InputWithLabel,
167
- {
168
- severity,
169
- inputId,
170
- labelId,
171
- label,
172
- flexProps: { direction: "row-reverse", justify: "end", align: "center", gap: "2" },
173
- children: /* @__PURE__ */ jsxRuntime.jsx(
174
- blocks.Checkbox,
175
- {
176
- ...rest,
177
- ...fieldProps,
178
- id: inputId,
179
- color,
180
- value: value.toString(),
181
- checked: value,
182
- onCheckedChange: fieldProps.onChange,
183
- onChange: void 0,
184
- onBlur: void 0
185
- }
186
- )
187
- }
188
- ) });
189
- });
190
- const _BooleanField = class _BooleanField extends BaseField {
191
- constructor(options) {
192
- super({ ...options, type: "boolean" });
193
- __publicField(this, "onlyValidateAfterTouched", false);
194
- }
195
- // if a BooleanField is required, `false` is considered blank
196
- isBlank(value) {
197
- return this.required && !value;
198
- }
199
- getValueFromChangeEvent(event) {
200
- if (typeof event === "boolean")
201
- return event;
202
- return event.target.checked;
203
- }
204
- serialize() {
205
- return super._serialize();
206
- }
207
- static deserialize(data) {
208
- if (data.type !== "boolean")
209
- throw new Error("Type mismatch.");
210
- return new _BooleanField(data);
211
- }
212
- getInput(props) {
213
- return /* @__PURE__ */ jsxRuntime.jsx(BooleanInput, { ...props, field: this });
214
- }
215
- };
216
- __publicField(_BooleanField, "fieldTypeName", "Checkbox");
217
- __publicField(_BooleanField, "fieldTypeDescription", "Perfect for both optional and required yes/no questions.");
218
- __publicField(_BooleanField, "Icon", reactIcons.CheckCircledIcon);
219
- let BooleanField = _BooleanField;
220
- const NumberInput$1 = React.memo(function NumberInput2(props) {
221
- const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
222
- const color = blocks.useSeverityColor(severity);
223
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsxRuntime.jsx(
224
- themes.TextField.Input,
225
- {
226
- ...rest,
227
- ...fieldProps,
228
- type: "number",
229
- id: inputId,
230
- min: field.minimum,
231
- max: field.maximum,
232
- step: field.integers ? 1 : 0.1,
233
- color
234
- }
235
- ) }) });
236
- });
237
- const _NumberField = class _NumberField extends BaseField {
238
- constructor(options) {
239
- const {
240
- minimum = Number.MIN_SAFE_INTEGER,
241
- maximum = Number.MAX_SAFE_INTEGER,
242
- integers = false,
243
- ...base
244
- } = options;
245
- super({ ...base, type: "number" });
246
- __publicField(this, "minimum");
247
- __publicField(this, "maximum");
248
- __publicField(this, "integers");
249
- this.minimum = minimum;
250
- this.maximum = maximum;
251
- this.integers = integers;
252
- }
253
- getValueFromChangeEvent(event) {
254
- const number = Number.parseFloat(event.target.value);
255
- if (Number.isNaN(number))
256
- return "";
257
- return number;
258
- }
259
- static getFieldCreationSchema() {
260
- return [
261
- new _NumberField({
262
- label: "Minimum",
263
- description: "Minimum value",
264
- integers: true,
265
- required: false,
266
- identifier: "minimum",
267
- formValidators: [this._validateMin]
268
- }),
269
- new _NumberField({
270
- label: "Maximum",
271
- description: "Maximum value",
272
- integers: true,
273
- required: false,
274
- identifier: "maximum",
275
- formValidators: [this._validateMax]
276
- }),
277
- new BooleanField({
278
- label: "Integers",
279
- description: "Whole numbers only",
280
- required: false,
281
- identifier: "integers"
282
- })
283
- ];
284
- }
285
- getFieldValidators() {
286
- const validators = super.getFieldValidators();
287
- const min = this.minimum;
288
- const max = this.maximum;
289
- if (typeof min === "number") {
290
- validators.push((value) => {
291
- if (typeof value === "number" && value < min) {
292
- return `Must be at least ${this.minimum}.`;
293
- }
294
- });
295
- }
296
- if (typeof max === "number") {
297
- validators.push((value) => {
298
- if (typeof value === "number" && value > max) {
299
- return `Must be at most ${this.maximum}.`;
300
- }
301
- });
302
- }
303
- if (this.integers) {
304
- validators.push((value) => {
305
- if (typeof value === "number" && !Number.isInteger(value)) {
306
- return "Must be a whole number.";
307
- }
308
- });
309
- }
310
- return validators;
311
- }
312
- serialize() {
313
- return {
314
- ...super._serialize(),
315
- minimum: this.minimum,
316
- maximum: this.maximum,
317
- integers: this.integers
318
- };
319
- }
320
- static deserialize(data) {
321
- if (data.type !== "number")
322
- throw new Error("Type mismatch.");
323
- return new _NumberField(data);
324
- }
325
- getInput(props) {
326
- return /* @__PURE__ */ jsxRuntime.jsx(NumberInput$1, { field: this, ...props });
327
- }
328
- };
329
- __publicField(_NumberField, "fieldTypeName", "Number");
330
- __publicField(_NumberField, "fieldTypeDescription", "Allows specifying a number within a given range.");
331
- __publicField(_NumberField, "Icon", reactIcons.FontFamilyIcon);
332
- __publicField(_NumberField, "_validateMin", (value, allValues) => {
333
- if (typeof allValues.maximum === "number" && typeof value === "number" && allValues.maximum < value) {
334
- return "Minimum cannot be greater than minimum.";
335
- }
336
- return null;
337
- });
338
- __publicField(_NumberField, "_validateMax", (value, allValues) => {
339
- if (typeof allValues.minimum === "number" && typeof value === "number" && allValues.minimum > value) {
340
- return "Maximum cannot be less than minimum.";
341
- }
342
- return null;
343
- });
344
- let NumberField = _NumberField;
345
- const DateInput = React.memo(function DateInput2(props) {
346
- const [{ inputId, labelId, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
347
- const color = blocks.useSeverityColor(severity);
348
- const value = fieldProps.value ? fieldProps.value.split("T")[0] : "";
349
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsxRuntime.jsx(themes.TextField.Input, { ...rest, ...fieldProps, type: "date", id: inputId, color, value }) }) });
350
- });
351
- const _DateField = class _DateField extends BaseField {
352
- constructor(options) {
353
- super({ ...options, type: "date" });
354
- __publicField(this, "onlyValidateAfterTouched", false);
355
- }
356
- serialize() {
357
- return super._serialize();
358
- }
359
- getValueFromChangeEvent(event) {
360
- return new Date(event.target.value).toISOString();
361
- }
362
- static deserialize(data) {
363
- if (data.type !== "date")
364
- throw new Error("Type mismatch.");
365
- return new _DateField(data);
366
- }
367
- getInput(props) {
368
- return /* @__PURE__ */ jsxRuntime.jsx(DateInput, { field: this, ...props });
369
- }
370
- };
371
- __publicField(_DateField, "fieldTypeName", "Date");
372
- __publicField(_DateField, "fieldTypeDescription", "Allows specifying a date.");
373
- __publicField(_DateField, "Icon", reactIcons.CalendarIcon);
374
- let DateField = _DateField;
375
- class StringOrTextField extends BaseField {
376
- constructor(options) {
377
- const { minLength, maxLength = 5e3, ...base } = options;
378
- super(base);
379
- __publicField(this, "minLength");
380
- __publicField(this, "maxLength");
381
- this.minLength = minLength ? Math.max(minLength, 0) : void 0;
382
- this.maxLength = maxLength ? Math.max(maxLength, 0) : 5e3;
383
- }
384
- static getFieldCreationSchema() {
385
- return [
386
- // min, max
387
- new NumberField({
388
- label: "Minimum length",
389
- description: "Minimum number of characters",
390
- required: false,
391
- identifier: "minimum_length",
392
- minimum: 0,
393
- maximum: 100,
394
- formValidators: [this._validateMin],
395
- integers: true
396
- }),
397
- new NumberField({
398
- label: "Maximum length",
399
- description: "Maximum number of characters",
400
- required: false,
401
- identifier: "maximum_length",
402
- minimum: 1,
403
- maximum: 5e3,
404
- // TODO: depends on short vs long text
405
- formValidators: [this._validateMax],
406
- // TODO: default: 500 (see: "Short text fields can hold up to 500 characters on a single line.")
407
- integers: true
408
- })
409
- ];
410
- }
411
- getFieldValidators() {
412
- const validators = super.getFieldValidators();
413
- if (this.minLength) {
414
- validators.push((value) => {
415
- if (this.minLength && (!value || value.length < this.minLength)) {
416
- if (!this.required && !value)
417
- return null;
418
- return `Minimum ${this.minLength} character(s).`;
419
- }
420
- });
421
- }
422
- if (this.maxLength) {
423
- validators.push((value) => {
424
- if (typeof value === "string" && this.maxLength && value.length > this.maxLength) {
425
- return `Maximum ${this.maxLength} character(s).`;
426
- }
427
- });
428
- }
429
- return validators;
430
- }
431
- _serialize() {
432
- if (!this.identifier) {
433
- throw new Error("Field identifier must be set before serializing.");
434
- }
435
- return {
436
- ...super._serialize(),
437
- minimum_length: this.minLength,
438
- maximum_length: this.maxLength
439
- };
440
- }
441
- }
442
- /**
443
- * This function validates that the value given for "minimum length" (when creating a new field) is less than or
444
- * equal to the value given for "maximum length".
445
- */
446
- __publicField(StringOrTextField, "_validateMin", (value, allValues) => {
447
- if (typeof allValues.maximum_length === "number" && typeof value === "number" && allValues.maximum_length < value) {
448
- return "Minimum cannot be greater than maximum.";
449
- }
450
- return null;
451
- });
452
- /**
453
- * This function validates that the value given for "maximum length" (when creating a new field) is greater than or
454
- * equal to the value given for "minimum length".
455
- */
456
- __publicField(StringOrTextField, "_validateMax", (value, allValues) => {
457
- if (typeof value !== "number")
458
- return null;
459
- const { minimum_length: minimumLength } = allValues;
460
- if (typeof minimumLength !== "number") {
461
- return null;
462
- }
463
- if (minimumLength > value) {
464
- return "Maximum cannot be less than minimum.";
465
- }
466
- return null;
467
- });
468
- const clickableLinkContainer = "_clickableLinkContainer_1ace7_1";
469
- const TextFieldInputCopy = "_TextFieldInputCopy_1ace7_5";
470
- const styles$3 = {
471
- clickableLinkContainer,
472
- TextFieldInputCopy
473
- };
474
- const StringInput = React.memo(function StringInput2(props) {
475
- const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
476
- const color = blocks.useSeverityColor(severity);
477
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: !rest.disabled ? /* @__PURE__ */ jsxRuntime.jsx(themes.TextField.Input, { ...rest, ...fieldProps, type: field.inputType, id: inputId, color }) : /* @__PURE__ */ jsxRuntime.jsxs(themes.TextField.Root, { className: styles$3.clickableLinkContainer, children: [
478
- /* @__PURE__ */ jsxRuntime.jsx(
479
- "div",
480
- {
481
- className: core.classNames(
482
- "rt-TextFieldInput rt-r-size-2 rt-variant-surface",
483
- styles$3.TextFieldInputCopy
484
- ),
485
- children: /* @__PURE__ */ jsxRuntime.jsx(
486
- Linkify,
487
- {
488
- options: {
489
- target: "_blank",
490
- rel: "noopener"
491
- },
492
- children: fieldProps.value
493
- }
494
- )
495
- }
496
- ),
497
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rt-TextFieldChrome" })
498
- ] }) }) });
499
- });
500
- const _StringField = class _StringField extends StringOrTextField {
501
- constructor(options) {
502
- const { inputType = "text", ...rest } = options;
503
- const maxLength = options.maxLength ? Math.min(500, options.maxLength) : 500;
504
- const minLength = options.minLength ? Math.min(options.minLength, maxLength) : void 0;
505
- super({ ...rest, maxLength, minLength, type: "string" });
506
- __publicField(this, "inputType");
507
- this.inputType = inputType;
508
- }
509
- serialize() {
510
- return { ...super._serialize(), input_type: this.inputType };
511
- }
512
- static deserialize(data) {
513
- if (data.type !== "string")
514
- throw new Error("Type mismatch.");
515
- const { maximum_length, minimum_length, input_type, ...rest } = data;
516
- return new _StringField({ ...rest, maxLength: maximum_length, minLength: minimum_length, inputType: input_type });
517
- }
518
- getInput(props) {
519
- return /* @__PURE__ */ jsxRuntime.jsx(StringInput, { field: this, ...props });
520
- }
521
- };
522
- __publicField(_StringField, "fieldTypeName", "Short Text");
523
- __publicField(_StringField, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line.");
524
- __publicField(_StringField, "Icon", reactIcons.InputIcon);
525
- let StringField = _StringField;
526
- const TextInput = React.memo(function TextInput2(props) {
527
- const [{ inputId, labelId, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
528
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsxRuntime.jsx(blocks.TextArea, { ...rest, ...fieldProps, resize: "vertical", id: inputId, severity }) }) });
529
- });
530
- const _TextField = class _TextField extends StringOrTextField {
531
- constructor(options) {
532
- const maxLength = options.maxLength ? Math.min(5e3, options.maxLength) : 5e3;
533
- const minLength = options.minLength ? Math.min(options.minLength, maxLength) : void 0;
534
- super({ ...options, maxLength, minLength, type: "text" });
535
- }
536
- serialize() {
537
- return super._serialize();
538
- }
539
- static deserialize(data) {
540
- if (data.type !== "text")
541
- throw new Error("Type mismatch.");
542
- const { maximum_length, minimum_length, ...rest } = data;
543
- return new _TextField({ ...rest, maxLength: maximum_length, minLength: minimum_length });
544
- }
545
- getInput(props) {
546
- return /* @__PURE__ */ jsxRuntime.jsx(TextInput, { field: this, ...props });
547
- }
548
- };
549
- __publicField(_TextField, "fieldTypeName", "Paragraph");
550
- __publicField(_TextField, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines.");
551
- __publicField(_TextField, "Icon", reactIcons.RowsIcon);
552
- let TextField = _TextField;
553
- const SelectInput = React.memo(function SelectInput2(props) {
554
- const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
555
- const { onChange, onBlur } = fieldProps;
556
- const options = React.useMemo(
557
- () => field.options.map((option) => ({ value: option.value, itemContent: option.label })),
558
- [field.options]
559
- );
560
- const handleChange = React.useCallback(
561
- (value) => {
562
- onChange(value);
563
- onBlur(value);
564
- },
565
- [onChange, onBlur]
566
- );
567
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsxRuntime.jsx(
568
- blocks.Select,
569
- {
570
- items: options,
571
- ...fieldProps,
572
- onValueChange: handleChange,
573
- placeholder: "Select one...",
574
- id: inputId,
575
- severity,
576
- ...rest
577
- }
578
- ) }) });
579
- });
580
- const emptySection = (id = "", fields = []) => ({
581
- type: "section",
582
- fields,
583
- identifier: id,
584
- label: null,
585
- condition: null,
586
- conditional: false
587
- });
588
- const wrapRootFieldsWithFieldSection = (revision) => {
589
- if (!revision)
590
- return void 0;
591
- const fields = revision.fields;
592
- let pending = [];
593
- const sections = [];
594
- for (const field of fields) {
595
- if (field.type === "section") {
596
- if (pending.length > 0) {
597
- sections.push(emptySection(`AUTO_section-${fields.indexOf(field)}`, pending));
598
- pending = [];
599
- }
600
- sections.push(field);
601
- } else {
602
- pending.push(field);
603
- }
604
- }
605
- if (pending.length > 0) {
606
- sections.push(emptySection("AUTO_section-last", pending));
607
- }
608
- return { ...revision, fields: sections, description: revision.description ?? "" };
609
- };
610
- function reorder(list, source, destination) {
611
- const result = Array.from(list);
612
- const [removed] = result.splice(source, 1);
613
- if (!removed)
614
- throw new Error("Could not find field to reorder.");
615
- result.splice(destination, 0, removed);
616
- return result;
617
- }
618
- function replace(list, index, value) {
619
- const result = Array.from(list);
620
- result[index] = value;
621
- return result;
622
- }
623
- function insert(list, index, value) {
624
- const result = Array.from(list ?? []);
625
- result.splice(index, 0, value);
626
- return result;
627
- }
628
- function remove(list, index) {
629
- const result = Array.from(list);
630
- result.splice(index, 1);
631
- return result;
632
- }
633
- const makeIdentifier = (existing, label) => {
634
- if (typeof existing === "string" && existing.length > 0)
635
- return existing;
636
- const now = /* @__PURE__ */ new Date();
637
- return `${core.slugify(label)}-${now.getTime()}`;
638
- };
639
- const findFieldByIdentifier = (fields, identifier) => {
640
- if (!identifier)
641
- return null;
642
- for (const field of fields) {
643
- if (field.type === "section") {
644
- const result = findFieldByIdentifier(field.fields, identifier);
645
- if (result)
646
- return result;
647
- } else if (field.identifier === identifier) {
648
- return field;
649
- }
650
- }
651
- return null;
652
- };
653
- const makeConditionalSourceFields = (sections, index) => {
654
- return sections.filter((_, i) => i < index).flatMap((field) => field.fields);
655
- };
656
- const getTakenFieldLabels = (fields) => {
657
- return fields.flatMap(
658
- (field) => field.type === "section" ? [...field.fields.map((f) => f.label), field.label] : field.label
659
- ).filter((id) => id !== null);
660
- };
661
- const incrementFieldLabel = (label, takenLabels) => {
662
- let count = 1;
663
- let newLabel = `${label} (${count})`;
664
- while (takenLabels.includes(newLabel)) {
665
- newLabel = `${label} (${++count})`;
666
- }
667
- return newLabel;
668
- };
669
- const MultiStringInput = React.memo(function MultiStringInput2(props) {
670
- const [{ inputId, labelId, severity, helpText, label, fieldProps }, rest] = useFormikInput(props);
671
- const color = blocks.useSeverityColor(severity);
672
- const value = React.useMemo(() => Array.isArray(fieldProps.value) ? fieldProps.value : [], [fieldProps.value]);
673
- const { onChange, onBlur } = fieldProps;
674
- const droppableId = `${inputId}-droppable`;
675
- const { disabled } = rest;
676
- const [intermediateValue, setIntermediateValue] = React.useState("");
677
- const [internalError, setInternalError] = React.useState("");
678
- const updatedHelpText = internalError || helpText;
679
- const updatedColor = internalError ? "red" : color;
680
- const setValueAndTouched = React.useCallback(
681
- (newValue) => {
682
- onChange(newValue);
683
- onBlur(newValue);
684
- },
685
- [onChange, onBlur]
686
- );
687
- const handleChange = React.useCallback(
688
- (e) => {
689
- if (value.findIndex((option) => option.value === e.target.value.trim()) >= 0) {
690
- setInternalError("All options must be unique");
691
- } else if (!e.target.value) {
692
- setInternalError("Option cannot be empty");
693
- } else {
694
- setInternalError("");
695
- }
696
- setIntermediateValue(e.target.value);
697
- },
698
- [setIntermediateValue, value]
699
- );
700
- const addOption = React.useCallback(() => {
701
- if (internalError)
702
- return;
703
- if (!intermediateValue.trim()) {
704
- return setInternalError("Option cannot be empty");
705
- }
706
- const trimmedValue = intermediateValue.trim();
707
- setValueAndTouched([...value, { value: trimmedValue, label: trimmedValue }]);
708
- setIntermediateValue("");
709
- }, [intermediateValue, internalError, setValueAndTouched, value]);
710
- const handleKeyDown = React.useCallback(
711
- (e) => {
712
- if (e.key === "Enter") {
713
- e.preventDefault();
714
- addOption();
715
- }
716
- },
717
- [addOption]
718
- );
719
- const handleDeleteOption = React.useCallback(
720
- (index) => {
721
- setValueAndTouched(remove(value, index));
722
- },
723
- [value, setValueAndTouched]
724
- );
725
- const handleDragEnd = React.useCallback(
726
- (result) => {
727
- if (!result.destination)
728
- return;
729
- const sourceIndex = result.source.index;
730
- const destinationIndex = result.destination.index;
731
- setValueAndTouched(reorder(value, sourceIndex, destinationIndex));
732
- },
733
- [setValueAndTouched, value]
734
- );
735
- return /* @__PURE__ */ jsxRuntime.jsx(dnd.DragDropContext, { onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "2", children: [
736
- /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText: updatedHelpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: (!disabled || value.length === 0) && /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", children: [
737
- /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { grow: "1", children: /* @__PURE__ */ jsxRuntime.jsx(
738
- themes.TextField.Input,
739
- {
740
- placeholder: "Press enter to add a new option",
741
- ...rest,
742
- ...fieldProps,
743
- value: intermediateValue,
744
- onChange: handleChange,
745
- onKeyDown: handleKeyDown,
746
- id: inputId,
747
- color: updatedColor,
748
- onBlur: void 0
749
- }
750
- ) }),
751
- /* @__PURE__ */ jsxRuntime.jsx(
752
- blocks.IconButton,
753
- {
754
- type: "button",
755
- "aria-label": "Add option",
756
- disabled: !!internalError || disabled,
757
- onClick: addOption,
758
- children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {})
759
- }
760
- )
761
- ] }) }) }),
762
- /* @__PURE__ */ jsxRuntime.jsx(dnd.Droppable, { droppableId, children: (droppableProvided) => /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { ...droppableProvided.droppableProps, ref: droppableProvided.innerRef, direction: "column", children: [
763
- value.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
764
- dnd.Draggable,
765
- {
766
- draggableId: `${option.value}-draggable`,
767
- index,
768
- isDragDisabled: disabled,
769
- children: ({ draggableProps, dragHandleProps, innerRef }) => /* @__PURE__ */ jsxRuntime.jsx(
770
- blocks.Flex,
771
- {
772
- ...dragHandleProps,
773
- ...draggableProps,
774
- ref: innerRef,
775
- gap: "2",
776
- align: "center",
777
- justify: "between",
778
- mb: "1",
779
- asChild: true,
780
- children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Badge, { color: "gray", size: "2", children: [
781
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: option.label }),
782
- /* @__PURE__ */ jsxRuntime.jsx(
783
- blocks.IconButton,
784
- {
785
- size: "small",
786
- variant: "ghost",
787
- type: "button",
788
- "aria-label": "Delete option",
789
- severity: "info",
790
- disabled,
791
- onClick: () => handleDeleteOption(index),
792
- children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.Cross1Icon, {})
793
- }
794
- )
795
- ] })
796
- }
797
- )
798
- },
799
- option.value
800
- )),
801
- droppableProvided.placeholder
802
- ] }) })
803
- ] }) });
804
- });
805
- const _MultiStringField = class _MultiStringField extends BaseField {
806
- constructor(options) {
807
- const { minimum_length, maximum_length, ...rest } = options;
808
- super({ ...rest, type: "multi-string" });
809
- __publicField(this, "minLength");
810
- __publicField(this, "maxLength");
811
- __publicField(this, "onlyValidateAfterTouched", false);
812
- this.minLength = minimum_length ?? 0;
813
- this.maxLength = maximum_length ?? Infinity;
814
- }
815
- getValueFromChangeEvent(event) {
816
- if (Array.isArray(event))
817
- return event;
818
- throw new Error("Expected an array.");
819
- }
820
- getInput(props) {
821
- return /* @__PURE__ */ jsxRuntime.jsx(MultiStringInput, { field: this, ...props });
822
- }
823
- serialize() {
824
- return { ...super._serialize(), minimum_length: this.minLength, maximum_length: this.maxLength };
825
- }
826
- isBlank(value) {
827
- return super.isBlank(value) || value.length === 0;
828
- }
829
- getFieldValidators() {
830
- const validators = super.getFieldValidators();
831
- validators.push((value) => {
832
- if (Array.isArray(value) && value.length < this.minLength) {
833
- return `Must have at least ${this.minLength} options.`;
834
- }
835
- });
836
- validators.push((value) => {
837
- if (Array.isArray(value) && value.length > this.maxLength) {
838
- return `Must have at most ${this.maxLength} options.`;
839
- }
840
- });
841
- return validators;
842
- }
843
- static deserialize(data) {
844
- if (data.type !== "multi-string")
845
- throw new Error("Type mismatch.");
846
- return new _MultiStringField(data);
847
- }
848
- };
849
- __publicField(_MultiStringField, "fieldTypeName", "Multi-string");
850
- __publicField(_MultiStringField, "fieldTypeDescription", "Allows the user to provide multiple unique strings.");
851
- __publicField(_MultiStringField, "Icon", reactIcons.ListBulletIcon);
852
- let MultiStringField = _MultiStringField;
853
- class BaseSelectField extends BaseField {
854
- constructor(options) {
855
- super(options);
856
- __publicField(this, "options");
857
- __publicField(this, "onlyValidateAfterTouched", false);
858
- const encounteredIds = /* @__PURE__ */ new Set();
859
- this.options = options.options.map((option) => {
860
- if (typeof option === "string") {
861
- option = { label: option, value: option };
862
- }
863
- encounteredIds.add(option.label);
864
- return option;
865
- });
866
- if (encounteredIds.size !== options.options.length) {
867
- console.error(
868
- `${options.options.length - encounteredIds.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,
869
- options.options
870
- );
871
- }
872
- }
873
- _serialize() {
874
- return {
875
- ...super._serialize(),
876
- options: this.options
877
- };
878
- }
879
- static getFieldCreationSchema() {
880
- return [
881
- new MultiStringField({
882
- label: "Options",
883
- description: "List possible options for the user to select from.",
884
- required: true,
885
- identifier: "options",
886
- minimum_length: 2,
887
- maximum_length: 20
888
- })
889
- ];
890
- }
891
- }
892
- const _SelectField = class _SelectField extends BaseSelectField {
893
- constructor(options) {
894
- super({ ...options, type: "select" });
895
- }
896
- getValueFromChangeEvent(event) {
897
- if (typeof event === "string")
898
- return event;
899
- return event.target.value;
900
- }
901
- serialize() {
902
- return super._serialize();
903
- }
904
- static deserialize(data) {
905
- if (data.type !== "select")
906
- throw new Error("Type mismatch.");
907
- return new _SelectField(data);
908
- }
909
- getInput(props) {
910
- return /* @__PURE__ */ jsxRuntime.jsx(SelectInput, { field: this, ...props });
911
- }
912
- };
913
- __publicField(_SelectField, "fieldTypeName", "Dropdown");
914
- __publicField(_SelectField, "fieldTypeDescription", "Allows the user to select a single option from a list of options.");
915
- __publicField(_SelectField, "Icon", reactIcons.DropdownMenuIcon);
916
- let SelectField = _SelectField;
917
- const parseValueToArray = (value) => {
918
- if (!value)
919
- return [];
920
- if (Array.isArray(value))
921
- return value;
922
- return [value];
923
- };
924
- const MultiSelectInput = React.memo(function MultiSelectInput2(props) {
925
- const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
926
- const { onChange, onBlur } = fieldProps;
927
- const value = React.useMemo(() => parseValueToArray(fieldProps.value), [fieldProps.value]);
928
- const handleChange = React.useCallback(
929
- (value2) => {
930
- onChange(value2);
931
- onBlur(value2);
932
- },
933
- [onChange, onBlur]
934
- );
935
- return /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText, severity, children: /* @__PURE__ */ jsxRuntime.jsx(InputWithLabel, { severity, inputId, labelId, label, children: /* @__PURE__ */ jsxRuntime.jsx(
936
- blocks.MultiSelect,
937
- {
938
- value,
939
- onValueChange: handleChange,
940
- options: field.options,
941
- name: fieldProps.name,
942
- placeholder: "Select one or more...",
943
- id: inputId,
944
- severity,
945
- ...rest
946
- }
947
- ) }) });
948
- });
949
- const _MultiSelectField = class _MultiSelectField extends BaseSelectField {
950
- constructor(options) {
951
- super({ ...options, type: "multi-select" });
952
- }
953
- getValueFromChangeEvent(event) {
954
- if (Array.isArray(event))
955
- return event;
956
- throw new Error("Expected an array.");
957
- }
958
- isBlank(value) {
959
- return super.isBlank(value) || value.length === 0;
960
- }
961
- serialize() {
962
- return super._serialize();
963
- }
964
- static deserialize(data) {
965
- if (data.type !== "multi-select")
966
- throw new Error("Type mismatch.");
967
- return new _MultiSelectField(data);
968
- }
969
- getInput(props) {
970
- return /* @__PURE__ */ jsxRuntime.jsx(MultiSelectInput, { field: this, ...props });
971
- }
972
- };
973
- __publicField(_MultiSelectField, "fieldTypeName", "Multi-select");
974
- __publicField(_MultiSelectField, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options.");
975
- __publicField(_MultiSelectField, "Icon", reactIcons.CheckboxIcon);
976
- let MultiSelectField = _MultiSelectField;
977
- const FieldInputCloner = React.memo(function FieldInputCloner2({ field, ...props }) {
978
- const [{ value: identifier }] = formik.useField(field.options.clonedFieldIdentifier);
979
- const deserializedField = React.useMemo(() => {
980
- const options = field.options.getFieldToClone(identifier);
981
- if (!options)
982
- return null;
983
- return deserialize(options);
984
- }, [field.options, identifier]);
985
- return useFieldInput(deserializedField, props);
986
- });
987
- class CustomField extends BaseField {
988
- constructor(options, Component) {
989
- super({ ...options, type: "custom" });
990
- __publicField(this, "Component");
991
- // identifier of the field whose value is the label of the field to re-render
992
- __publicField(this, "options");
993
- this.options = options;
994
- this.Component = Component;
995
- }
996
- serialize() {
997
- throw new Error("Serializing only supported for public input types.");
998
- }
999
- getInput(props) {
1000
- const CustomInput = this.Component;
1001
- return /* @__PURE__ */ jsxRuntime.jsx(CustomInput, { field: this, ...props });
1002
- }
1003
- }
1004
- __publicField(CustomField, "fieldTypeName", "Custom");
1005
- __publicField(CustomField, "fieldTypeDescription", "Allows re-rendering of field already in the form");
1006
- class FieldInputClonerField extends CustomField {
1007
- constructor(options) {
1008
- super(options, FieldInputCloner);
1009
- }
1010
- }
1011
- const FieldSectionLayout = React.memo(function FieldSectionLayout2(props) {
1012
- const { field: section, ...rest } = props;
1013
- const { label, description: description2, fields, condition } = section;
1014
- const { values, setFieldValue } = formik.useFormikContext();
1015
- const conditionValue = (condition == null ? void 0 : condition.identifier) ? get(values, condition.identifier) : void 0;
1016
- const conditionMet = React.useMemo(() => isConditionMet(condition, conditionValue), [condition, conditionValue]);
1017
- React.useEffect(() => {
1018
- if (!conditionMet) {
1019
- for (const childField of fields) {
1020
- setFieldValue(childField.getId(), "").then();
1021
- }
1022
- }
1023
- }, [conditionMet, fields, setFieldValue]);
1024
- const inputs = useFieldInputs(fields, rest);
1025
- if (!conditionMet) {
1026
- return null;
1027
- }
1028
- if (!label) {
1029
- return inputs;
1030
- }
1031
- return /* @__PURE__ */ jsxRuntime.jsx(themes.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "3", children: [
1032
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", children: [
1033
- /* @__PURE__ */ jsxRuntime.jsx(themes.Heading, { as: "h3", size: "3", children: label }),
1034
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { className: styles$4.description, children: description2 })
1035
- ] }),
1036
- inputs
1037
- ] }) });
1038
- });
1039
- const _FieldSection = class _FieldSection extends BaseFormElement {
1040
- constructor(options) {
1041
- const { label = null, fields, condition = null, conditional, ...base } = options;
1042
- super({ ...base, type: "section" });
1043
- __publicField(this, "label");
1044
- __publicField(this, "fields");
1045
- __publicField(this, "condition");
1046
- this.fields = fields;
1047
- this.condition = condition;
1048
- this.label = label;
1049
- if (conditional === false) {
1050
- this.condition = null;
1051
- }
1052
- }
1053
- static getFieldCreationSchema(options) {
1054
- if (options.length === 0)
1055
- return [];
1056
- return [
1057
- new BooleanField({
1058
- label: "Conditional",
1059
- description: "Conditionally show or hide this section.",
1060
- identifier: "conditional",
1061
- required: false
1062
- }),
1063
- // Declare a section that will hold options for the condition (if any).
1064
- new _FieldSection({
1065
- label: "Conditional settings",
1066
- identifier: "conditional-settings",
1067
- // This section will only be rendered if the above "Conditional" field is checked.
1068
- condition: {
1069
- identifier: "conditional",
1070
- value: true
1071
- },
1072
- // These are the options of the condition.
1073
- fields: [
1074
- // Declare a select field that will be used to select the field against which we will check the
1075
- // condition. This must be selected before the next field is rendered.
1076
- new SelectField({
1077
- label: "Field",
1078
- description: "The field to use for the condition.",
1079
- // The options (for the field against which we will check the condition) are all the labels of
1080
- // the fields in the previous section(s) (or fields declared before with no section) that
1081
- // support conditions. We pass in both the label and the identifier of each supported field. The
1082
- // identifier becomes the value of the option.
1083
- options: options.map((option) => {
1084
- if (!option.label)
1085
- return null;
1086
- if (option.type === "upload")
1087
- return null;
1088
- return {
1089
- label: option.label,
1090
- value: option.identifier
1091
- };
1092
- }).filter((option) => !!option),
1093
- identifier: "condition.identifier",
1094
- required: true
1095
- }),
1096
- // Declare a custom field that will be used to input a value for the condition. The value of the
1097
- // conditional field selected in the previous step must be equal to the value the user inputs into
1098
- // this field for the section to be rendered.
1099
- new FieldInputClonerField({
1100
- label: "Value",
1101
- identifier: "condition.value",
1102
- required: true,
1103
- clonedFieldIdentifier: "condition.identifier",
1104
- getFieldToClone(identifier) {
1105
- if (!identifier) {
1106
- return null;
1107
- }
1108
- const option = options.find((option2) => option2.identifier === identifier);
1109
- if (!option) {
1110
- console.error("Could not find field with identifier", identifier);
1111
- return null;
1112
- }
1113
- return {
1114
- ...option,
1115
- // Override some options to make it make sense in the context and to make it work with the framework.
1116
- label: "Value",
1117
- identifier: "condition.value",
1118
- description: "The value to compare against.",
1119
- required: option.type !== "boolean"
1120
- };
1121
- }
1122
- })
1123
- ]
1124
- })
1125
- ];
1126
- }
1127
- static deserialize(data) {
1128
- var _a;
1129
- if (data.type !== "section")
1130
- throw new Error("Invalid type");
1131
- const fields = ((_a = data.fields) == null ? void 0 : _a.map(deserializeField)) ?? [];
1132
- return new _FieldSection({ ...data, fields });
1133
- }
1134
- conditional() {
1135
- return this.condition !== null;
1136
- }
1137
- serialize() {
1138
- return {
1139
- ...super._serialize(),
1140
- label: this.label,
1141
- condition: this.condition,
1142
- conditional: this.conditional(),
1143
- fields: this.fields.map((field) => field.serialize())
1144
- };
1145
- }
1146
- getErrors(allValues) {
1147
- const errors = {};
1148
- for (const field of this.fields) {
1149
- const id = field.getId();
1150
- const error = field.getError(get(allValues, id), allValues);
1151
- if (error) {
1152
- set(errors, field.getId(), error);
1153
- }
1154
- }
1155
- return errors;
1156
- }
1157
- getInput(props) {
1158
- return /* @__PURE__ */ jsxRuntime.jsx(FieldSectionLayout, { field: this, ...props });
1159
- }
1160
- };
1161
- __publicField(_FieldSection, "fieldTypeName", "Section");
1162
- __publicField(_FieldSection, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
1163
- let FieldSection = _FieldSection;
1164
- const previewImage = "_previewImage_1ig84_1";
1165
- const styles$2 = {
1166
- previewImage
1167
- };
1168
- const convertBytesToLargestUnit = (bytes) => {
1169
- const units = ["byte", "kilobyte", "megabyte"];
1170
- let sizeInUnit = bytes;
1171
- let unitIndex = 0;
1172
- while (sizeInUnit > 1e3 && unitIndex < units.length - 1) {
1173
- sizeInUnit /= 1e3;
1174
- unitIndex++;
1175
- }
1176
- const formatter = new Intl.NumberFormat([], {
1177
- maximumFractionDigits: Math.max(0, unitIndex - 1),
1178
- // 0 for bytes and kilobytes, 1 for megabytes
1179
- style: "unit",
1180
- unit: units[unitIndex]
1181
- });
1182
- return formatter.format(sizeInUnit);
1183
- };
1184
- const NumberInput = React.memo(function NumberInput2(props) {
1185
- var _a;
1186
- const [{ inputId, labelId, severity, helpText, label, fieldProps, field }, rest] = useFormikInput(props);
1187
- const { onChange } = fieldProps;
1188
- const color = blocks.useSeverityColor(severity);
1189
- const input = React.useRef(null);
1190
- const { value } = fieldProps;
1191
- const updatedHelpText = React.useMemo(() => {
1192
- if (helpText)
1193
- return helpText;
1194
- if (field.maxFileSize) {
1195
- return `Maximum file size: ${field.maxFileSize}MB`;
1196
- }
1197
- return null;
1198
- }, [field.maxFileSize, helpText]);
1199
- const handleClick = React.useCallback(() => {
1200
- var _a2;
1201
- (_a2 = input.current) == null ? void 0 : _a2.click();
1202
- }, []);
1203
- const handleRemove = React.useCallback(
1204
- (index) => {
1205
- const files = [...value];
1206
- files.splice(index, 1);
1207
- const event = { target: { files } };
1208
- onChange(event);
1209
- },
1210
- [value, onChange]
1211
- );
1212
- const multipleButtonText = value ? "Select new files" : "Select files";
1213
- const singleButtonText = value ? "Select new file" : "Select a file";
1214
- const buttonText = field.maxFiles > 1 ? multipleButtonText : singleButtonText;
1215
- return /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "2", children: [
1216
- /* @__PURE__ */ jsxRuntime.jsx(InputWithLabelAndHelpText, { helpText: updatedHelpText, severity, children: /* @__PURE__ */ jsxRuntime.jsxs(InputWithLabel, { severity, inputId, labelId, label, children: [
1217
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "row", gap: "2", children: /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { width: "max-content", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { ...rest, onClick: handleClick, children: [
1218
- /* @__PURE__ */ jsxRuntime.jsx(reactIcons.UploadIcon, {}),
1219
- " ",
1220
- buttonText
1221
- ] }) }) }),
1222
- /* @__PURE__ */ jsxRuntime.jsx(
1223
- "input",
1224
- {
1225
- ...rest,
1226
- type: "file",
1227
- ref: input,
1228
- id: inputId,
1229
- accept: (_a = field.extensions) == null ? void 0 : _a.join(","),
1230
- multiple: field.maxFiles > 1,
1231
- color,
1232
- style: { display: "none" },
1233
- ...fieldProps,
1234
- value: ""
1235
- }
1236
- )
1237
- ] }) }),
1238
- Array.isArray(value) && value.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "column", gap: "2", children: value.map((file, index) => /* @__PURE__ */ jsxRuntime.jsx(
1239
- DisplayFile,
1240
- {
1241
- field,
1242
- file,
1243
- onRemove: () => handleRemove(index),
1244
- disabled: rest.disabled
1245
- },
1246
- index
1247
- )) })
1248
- ] });
1249
- });
1250
- const DisplayFile = React.memo(function DisplayFile2({ file, field, onRemove, disabled }) {
1251
- const [resolvedFile, setResolvedFile] = React.useState(null);
1252
- const error = React.useMemo(() => resolvedFile && field.getError([resolvedFile]), [field, resolvedFile]);
1253
- const { url, name, size } = React.useMemo(() => {
1254
- let url2 = null;
1255
- let name2;
1256
- let size2;
1257
- if (resolvedFile == null ? void 0 : resolvedFile.type.startsWith("image/")) {
1258
- url2 = URL.createObjectURL(resolvedFile);
1259
- }
1260
- if (resolvedFile) {
1261
- name2 = resolvedFile.name;
1262
- size2 = convertBytesToLargestUnit(resolvedFile.size);
1263
- } else {
1264
- name2 = "Downloading...";
1265
- size2 = "...";
1266
- }
1267
- return { url: url2, name: name2, size: size2 };
1268
- }, [resolvedFile]);
1269
- React.useEffect(() => {
1270
- if (file instanceof Promise) {
1271
- file.then(setResolvedFile).catch(console.error);
1272
- } else {
1273
- setResolvedFile(file);
1274
- }
1275
- }, [file]);
1276
- return /* @__PURE__ */ jsxRuntime.jsx(themes.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: { initial: "column", sm: "row" }, gap: "3", justify: "between", children: [
1277
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "row", gap: "3", align: "center", grow: "1", shrink: "0", children: [
1278
- /* @__PURE__ */ jsxRuntime.jsx(
1279
- blocks.IconButton,
1280
- {
1281
- severity: "info",
1282
- variant: "outline",
1283
- "aria-label": `Remove ${name}`,
1284
- disabled,
1285
- onClick: onRemove,
1286
- children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.Cross1Icon, {})
1287
- }
1288
- ),
1289
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "1", children: [
1290
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { children: name }),
1291
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "1", children: size }),
1292
- error && /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "1", severity: "danger", children: error })
1293
- ] })
1294
- ] }),
1295
- url && /* @__PURE__ */ jsxRuntime.jsx("img", { className: styles$2.previewImage, src: url, alt: name })
1296
- ] }) });
1297
- });
1298
- const largestSupportedSize = 50;
1299
- const _UploadField = class _UploadField extends BaseField {
1300
- constructor(options) {
1301
- const { extensions, maximum_files, maximum_size, ...base } = options;
1302
- super({ ...base, type: "upload" });
1303
- __publicField(this, "extensions");
1304
- __publicField(this, "maxFileSize");
1305
- __publicField(this, "maxFiles");
1306
- __publicField(this, "onlyValidateAfterTouched", false);
1307
- this.maxFileSize = typeof maximum_size === "number" ? maximum_size : void 0;
1308
- this.maxFiles = Math.max(typeof maximum_files === "number" ? maximum_files : 1, 1);
1309
- this.extensions = extensions;
1310
- }
1311
- getValueFromChangeEvent(event) {
1312
- return Array.from(event.target.files || []);
1313
- }
1314
- isBlank(value) {
1315
- return super.isBlank(value) || value.length === 0;
1316
- }
1317
- static getFieldCreationSchema() {
1318
- return [
1319
- new NumberField({
1320
- label: "How many files can be uploaded?",
1321
- description: "By default, only one file can be uploaded.",
1322
- required: false,
1323
- minimum: 1,
1324
- maximum: 10,
1325
- identifier: "maximum_files",
1326
- integers: true
1327
- }),
1328
- new NumberField({
1329
- // TODO: Default value
1330
- label: "What is the maximum size of each file?",
1331
- description: `Maximum file size in megabytes (between 1MB–${largestSupportedSize}MB).`,
1332
- required: false,
1333
- identifier: "maximum_size",
1334
- minimum: 1,
1335
- maximum: largestSupportedSize,
1336
- integers: true
1337
- }),
1338
- new MultiSelectField({
1339
- label: "Accepted file types",
1340
- description: "Types of allowed files to upload. If left blank, all files will be accepted.",
1341
- required: false,
1342
- identifier: "extensions",
1343
- options: [
1344
- {
1345
- value: "image/*",
1346
- label: "Images"
1347
- },
1348
- {
1349
- value: "audio/*",
1350
- label: "Audio files"
1351
- },
1352
- {
1353
- value: "video/*",
1354
- label: "Videos"
1355
- },
1356
- {
1357
- value: "text/*",
1358
- label: "Text files"
1359
- },
1360
- {
1361
- value: "application/*",
1362
- label: "Application files (includes PDFs and Word documents)"
1363
- }
1364
- ]
1365
- })
1366
- ];
1367
- }
1368
- getFieldValidators() {
1369
- const validators = super.getFieldValidators();
1370
- const maxFileSizeInMB = this.maxFileSize ?? largestSupportedSize;
1371
- const maxFileSizeInB = maxFileSizeInMB * 1e3 * 1e3;
1372
- const maxFiles = this.maxFiles ?? 1;
1373
- validators.push((value) => {
1374
- if (value && value.some((file) => file.size > maxFileSizeInB)) {
1375
- return `Files must be at most ${maxFileSizeInMB}MB.`;
1376
- }
1377
- });
1378
- validators.push((value) => {
1379
- if (value && value.length > maxFiles) {
1380
- return `You can only upload ${maxFiles} files.`;
1381
- }
1382
- });
1383
- return validators;
1384
- }
1385
- serialize() {
1386
- return {
1387
- ...super._serialize(),
1388
- extensions: this.extensions,
1389
- maximum_size: this.maxFileSize,
1390
- maximum_files: this.maxFiles
1391
- };
1392
- }
1393
- static deserialize(data) {
1394
- if (data.type !== "upload")
1395
- throw new Error("Type mismatch.");
1396
- return new _UploadField(data);
1397
- }
1398
- getInput(props) {
1399
- return /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { field: this, ...props });
1400
- }
1401
- };
1402
- __publicField(_UploadField, "fieldTypeName", "Upload");
1403
- __publicField(_UploadField, "fieldTypeDescription", "Allows a file to be uploaded.");
1404
- __publicField(_UploadField, "Icon", reactIcons.UploadIcon);
1405
- let UploadField = _UploadField;
1406
- const FieldTypeToClsMapping = {
1407
- date: DateField,
1408
- number: NumberField,
1409
- boolean: BooleanField,
1410
- select: SelectField,
1411
- string: StringField,
1412
- text: TextField,
1413
- custom: CustomField,
1414
- upload: UploadField,
1415
- // TODO: Underscore
1416
- "multi-string": MultiStringField,
1417
- "multi-select": MultiSelectField
1418
- };
1419
- const deserializeField = (serializedField) => {
1420
- const fieldType = serializedField.type;
1421
- const fieldCls = FieldTypeToClsMapping[fieldType];
1422
- return fieldCls.deserialize(serializedField);
1423
- };
1424
- const deserialize = (serialized) => {
1425
- if (serialized.type === "section") {
1426
- return FieldSection.deserialize(serialized);
1427
- }
1428
- return deserializeField(serialized);
1429
- };
1430
- function formRevisionToSchema(formRevision, meta = {}) {
1431
- const { readonly = false } = meta;
1432
- return {
1433
- title: formRevision.title,
1434
- description: formRevision.description,
1435
- fields: formRevision.fields.map((serializedField) => deserialize(serializedField)),
1436
- meta: { readonly }
1437
- };
1438
- }
1439
- function valueIsFile(v) {
1440
- if (Array.isArray(v) && v.some((v2) => v2 instanceof File || v2 instanceof Promise))
1441
- return true;
1442
- return false;
1443
- }
1444
- function isConditionMet(condition, value) {
1445
- if (!condition)
1446
- return true;
1447
- if (valueIsFile(value) || valueIsFile(condition.value))
1448
- throw new Error("Conditions do not support file uploads");
1449
- const valueAsPrimitive = Array.isArray(value) ? value.map((v) => typeof v === "string" ? v : v.value) : value;
1450
- const valueToCompare = Array.isArray(condition.value) ? condition.value.map((v) => typeof v === "string" ? v : v.value) : condition.value;
1451
- if (Array.isArray(valueToCompare) && Array.isArray(valueAsPrimitive)) {
1452
- for (const v of valueToCompare) {
1453
- if (!valueAsPrimitive.includes(v))
1454
- return false;
1455
- }
1456
- return true;
1457
- }
1458
- return valueToCompare === value;
1459
- }
1460
- const useFieldInput = (field, props) => {
1461
- return React.useMemo(() => {
1462
- if (!props || !field)
1463
- return null;
1464
- return field.getInput(props);
1465
- }, [field, props]);
1466
- };
1467
- const useFieldInputs = (fields, props) => {
1468
- const inputs = React.useMemo(() => {
1469
- return fields.map((field) => {
1470
- return /* @__PURE__ */ jsxRuntime.jsx("div", { children: field.getInput(props) }, field.getId());
1471
- });
1472
- }, [fields, props]);
1473
- return /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "column", gap: "2", children: inputs });
1474
- };
1475
- const hasKeys = (errors) => {
1476
- return Object.keys(errors).length > 0;
1477
- };
1478
- const validateForm = async (schema, form) => {
1479
- const errors = {};
1480
- for (const field of schema.fields) {
1481
- if (field instanceof FieldSection) {
1482
- if (field.condition) {
1483
- const { identifier } = field.condition;
1484
- if (!isConditionMet(field.condition, get(form, identifier))) {
1485
- continue;
1486
- }
1487
- }
1488
- Object.assign(errors, field.getErrors(form));
1489
- } else {
1490
- if (!(field instanceof BaseField)) {
1491
- throw new Error("Invalid field type");
1492
- }
1493
- const id = field.getId();
1494
- const error = field.getError(get(form, id), form);
1495
- if (error)
1496
- set(errors, id, error);
1497
- }
1498
- }
1499
- if (hasKeys(errors))
1500
- return errors;
1501
- };
1502
- const uncontrolledValues = [null, void 0];
1503
- const initialFormValues = (fields, values) => {
1504
- return fields.reduce(
1505
- (acc, field) => {
1506
- if (field instanceof FieldSection) {
1507
- return { ...acc, ...initialFormValues(field.fields, values) };
1508
- }
1509
- if (uncontrolledValues.includes(get(acc, field.getId()))) {
1510
- set(acc, field.getId(), "");
1511
- }
1512
- return acc;
1513
- },
1514
- // TODO: Had to do this because of this error:
1515
- // > Uncaught TypeError: can't define property "description":
1516
- // > Object is not extensible"
1517
- // This means that we can't mutate `acc` because it's frozen for some
1518
- // unknown reason.
1519
- cloneDeep(values)
1520
- );
1521
- };
1522
- const defaultHandleSubmit = () => {
1523
- throw new Error("onSubmit must be provided if form is not readonly.");
1524
- };
1525
- const FormRenderer = React.memo(
1526
- React.forwardRef((props, ref) => {
1527
- const {
1528
- schema,
1529
- values = {},
1530
- onSubmit = defaultHandleSubmit,
1531
- submitText = "Submit",
1532
- cancelText,
1533
- onCancel,
1534
- onDirty,
1535
- onDirtyChange,
1536
- // if the title isn't provided, hide it by default
1537
- hideTitle = !schema.title,
1538
- hideDescription,
1539
- className
1540
- } = props;
1541
- const { readonly } = schema.meta;
1542
- const formId2 = React.useMemo(() => crypto.randomUUID(), []);
1543
- const formik$1 = formik.useFormik({
1544
- initialValues: initialFormValues(schema.fields, values),
1545
- onSubmit,
1546
- validate: (form) => validateForm(schema, form),
1547
- // only validate the entire form on submit
1548
- validateOnBlur: false,
1549
- validateOnChange: false
1550
- });
1551
- const { dirty } = formik$1;
1552
- const Title = React.useMemo(
1553
- () => typeof schema.title === "string" ? /* @__PURE__ */ jsxRuntime.jsx(themes.Heading, { children: schema.title }) : schema.title,
1554
- [schema.title]
1555
- );
1556
- const Description = React.useMemo(
1557
- () => typeof schema.description === "string" ? /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { className: styles$4.description, children: schema.description }) : schema.description,
1558
- [schema.description]
1559
- );
1560
- const inputs = useFieldInputs(schema.fields, { formId: formId2, disabled: readonly });
1561
- React.useEffect(() => {
1562
- if (dirty && onDirty)
1563
- onDirty();
1564
- if (onDirtyChange)
1565
- onDirtyChange(dirty);
1566
- }, [dirty, onDirty, onDirtyChange]);
1567
- return /* @__PURE__ */ jsxRuntime.jsx(formik.FormikProvider, { value: formik$1, children: /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { ref, direction: "column", gap: "2", className, asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { id: formId2, onSubmit: formik$1.handleSubmit, children: [
1568
- !hideTitle && /* @__PURE__ */ jsxRuntime.jsx(themes.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "1", children: [
1569
- Title,
1570
- !hideDescription && Description
1571
- ] }) }),
1572
- inputs,
1573
- !readonly && /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { justify: "end", gap: "2", children: [
1574
- cancelText && /* @__PURE__ */ jsxRuntime.jsx(blocks.Button, { type: "button", variant: "soft", onClick: onCancel, children: cancelText }),
1575
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Button, { type: "submit", disabled: !formik$1.isValid, children: submitText })
1576
- ] })
1577
- ] }) }) });
1578
- })
1579
- );
1580
- const FormSubmissionViewer = React.memo(
1581
- React.forwardRef((props, ref) => {
1582
- const { submission, showFormDescription = false, showFormTitle = true } = props;
1583
- const revision = core.useAppSelector(core.selectFormRevision(submission.form_revision));
1584
- const { sdk } = core.useSDK();
1585
- if (!revision) {
1586
- throw new Error(
1587
- `Could not find revision ${submission.form_revision} for submission ${submission.offline_id}.`
1588
- );
1589
- }
1590
- const schema = React.useMemo(() => {
1591
- return formRevisionToSchema(revision, { readonly: true });
1592
- }, [revision]);
1593
- const submissionValuesWithAttachments = React.useMemo(() => {
1594
- const attachments = core.selectSubmissionAttachments(submission.offline_id)(sdk.store.getState()) ?? [];
1595
- const downloadedAttachments = {};
1596
- for (const attachment of attachments) {
1597
- const promise = sdk.files.fetchFileFromUrl(attachment.file, attachment.file_sha1, attachment.file_name);
1598
- const fieldAttachments = downloadedAttachments[attachment.field_identifier];
1599
- if (fieldAttachments) {
1600
- fieldAttachments.push(promise);
1601
- } else {
1602
- downloadedAttachments[attachment.field_identifier] = [promise];
1603
- }
1604
- }
1605
- return { ...submission.values, ...downloadedAttachments };
1606
- }, [sdk.files, sdk.store, submission.offline_id, submission.values]);
1607
- return /* @__PURE__ */ jsxRuntime.jsx(
1608
- FormRenderer,
1609
- {
1610
- ref,
1611
- schema,
1612
- values: submissionValuesWithAttachments,
1613
- hideDescription: !showFormDescription,
1614
- hideTitle: !showFormTitle
1615
- }
1616
- );
1617
- })
1618
- );
1619
- const favoriteIcon = "_favoriteIcon_1bixi_1";
1620
- const regularIcon = "_regularIcon_1bixi_9";
1621
- const styles$1 = {
1622
- favoriteIcon,
1623
- regularIcon
1624
- };
1625
- const orgOptionPrefix = "organization:";
1626
- const userOptionPrefix = "user:";
1627
- const FormBrowser = React.memo(
1628
- React.forwardRef((props, ref) => {
1629
- const { maxResults = 20, ...entryProps } = props;
1630
- const [filter, setFilter] = React.useState("");
1631
- const [ownerFilter, setOwnerFilter] = React.useState("");
1632
- const { sdk } = core.useSDK();
1633
- const ownerFilterOptions = React.useMemo(() => {
1634
- const ret = { maxResults, searchTerm: filter };
1635
- if (ownerFilter) {
1636
- if (ownerFilter.startsWith(orgOptionPrefix)) {
1637
- ret.owner_organization = parseInt(ownerFilter.slice(orgOptionPrefix.length));
1638
- } else if (ownerFilter.startsWith(userOptionPrefix)) {
1639
- ret.owner_user = parseInt(ownerFilter.slice(userOptionPrefix.length));
1640
- }
1641
- }
1642
- return ret;
1643
- }, [filter, maxResults, ownerFilter]);
1644
- const userForms = core.useAppSelector(core.selectFilteredUserForms(ownerFilterOptions)) ?? [];
1645
- const userFormMapping = core.useAppSelector(core.selectUserFormMapping);
1646
- const handleToggleFavorite = React.useCallback(
1647
- (form) => {
1648
- if (form.favorite) {
1649
- sdk.userForms.unfavorite(form.offline_id).then();
1650
- } else {
1651
- sdk.userForms.favorite(form.offline_id).then();
1652
- }
1653
- },
1654
- [sdk]
1655
- );
1656
- const options = React.useMemo(() => {
1657
- const state = sdk.store.getState();
1658
- const accumulator = {};
1659
- for (const form of Object.values(userFormMapping)) {
1660
- const organization = core.selectOrganization(form.owner_organization || -1)(state);
1661
- if (organization) {
1662
- accumulator[`${orgOptionPrefix}${organization.id}`] = organization.name;
1663
- }
1664
- const user = core.selectUser(form.owner_user || -1)(state);
1665
- if (user) {
1666
- accumulator[`${userOptionPrefix}${user.id}`] = user.username;
1667
- }
1668
- }
1669
- return Object.entries(accumulator).map(([value, label]) => ({ itemContent: label, value }));
1670
- }, [userFormMapping, sdk.store]);
1671
- const handleChange = React.useCallback((e) => {
1672
- setFilter(e.currentTarget.value);
1673
- }, []);
1674
- const numberOfForms = core.useAppSelector(core.selectNumberOfUserForms) || 0;
1675
- const numberOfHiddenForms = numberOfForms - userForms.length;
1676
- const overflowMessage = userForms.length == maxResults && numberOfHiddenForms > 0 ? `Only the first ${maxResults} results are shown (${numberOfHiddenForms} hidden)` : numberOfHiddenForms > 0 && `${numberOfHiddenForms} hidden forms`;
1677
- return /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { ref, direction: "column", gap: "2", children: [
1678
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", grow: "1", children: [
1679
- /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { grow: "1", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(themes.TextField.Root, { size: "3", children: /* @__PURE__ */ jsxRuntime.jsx(themes.TextField.Input, { placeholder: "Filter", value: filter, onChange: handleChange }) }) }),
1680
- /* @__PURE__ */ jsxRuntime.jsx(
1681
- blocks.Select,
1682
- {
1683
- items: options,
1684
- value: ownerFilter,
1685
- onValueChange: setOwnerFilter,
1686
- placeholder: "Owner",
1687
- size: "large"
1688
- }
1689
- )
1690
- ] }),
1691
- userForms.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(blocks.ButtonList.Root, { children: userForms.map((form) => /* @__PURE__ */ jsxRuntime.jsx(
1692
- FormBrowserEntry,
1693
- {
1694
- ...entryProps,
1695
- form,
1696
- handleToggleFavorite: () => handleToggleFavorite(form)
1697
- },
1698
- form.offline_id
1699
- )) }),
1700
- /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { px: "3", children: /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "2", severity: "info", children: overflowMessage }) })
1701
- ] });
1702
- })
1703
- );
1704
- const FormBrowserEntry = (props) => {
1705
- var _a;
1706
- const { form, onSelectForm, isFavoriteEditable, handleToggleFavorite } = props;
1707
- const ownerOrganization = (_a = core.useAppSelector(core.selectOrganization(form.owner_organization || -1))) == null ? void 0 : _a.name;
1708
- const ownerUser = core.useAppSelector(core.selectUser(form.owner_user || -1));
1709
- const currentUserId = core.useAppSelector(core.selectCurrentUser).id;
1710
- const ownedByCurrentUser = !!ownerUser && ownerUser.id === currentUserId;
1711
- const owner = ownerOrganization ?? (ownedByCurrentUser ? "You" : ownerUser == null ? void 0 : ownerUser.username) ?? "Unknown";
1712
- const handleFavoriteClick = React.useCallback(
1713
- (e) => {
1714
- e.stopPropagation();
1715
- handleToggleFavorite();
1716
- },
1717
- [handleToggleFavorite]
1718
- );
1719
- const ret = /* @__PURE__ */ jsxRuntime.jsx(blocks.ButtonList.Item, { onClick: () => onSelectForm(form), asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { justify: "between", gap: "2", py: "2", px: "3", ...blocks.divButtonProps, children: [
1720
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { grow: "1", align: "center", gap: "2", children: [
1721
- /* @__PURE__ */ jsxRuntime.jsx(
1722
- blocks.IconButton,
1723
- {
1724
- className: core.classNames(form.favorite ? styles$1.favoriteIcon : styles$1.regularIcon),
1725
- variant: "ghost",
1726
- onClick: handleFavoriteClick,
1727
- "aria-label": form.favorite ? "Favorite form" : "Standard form",
1728
- disabled: !isFavoriteEditable,
1729
- children: form.favorite ? /* @__PURE__ */ jsxRuntime.jsx(reactIcons.StarFilledIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(reactIcons.StarIcon, {})
1730
- }
1731
- ),
1732
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { noWrap: true, children: form.latestRevision.title }),
1733
- form.latestRevision.description && /* @__PURE__ */ jsxRuntime.jsx(reactIcons.QuestionMarkCircledIcon, {})
1734
- ] }),
1735
- owner && /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { align: "center", gap: "2", children: [
1736
- /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PersonIcon, {}),
1737
- " ",
1738
- owner
1739
- ] })
1740
- ] }) });
1741
- if (form.latestRevision.description) {
1742
- return /* @__PURE__ */ jsxRuntime.jsx(blocks.Tooltip, { content: form.latestRevision.description, children: ret }, form.offline_id);
1743
- }
1744
- return ret;
1745
- };
1746
- const submissionsContainer = "_submissionsContainer_9iirt_1";
1747
- const stopHorizontalOverflow = "_stopHorizontalOverflow_9iirt_6";
1748
- const styles = {
1749
- submissionsContainer,
1750
- stopHorizontalOverflow
1751
- };
1752
- const FormSubmissionBrowserEntry = React.memo(function FormSubmissionBrowserEntry2(props) {
1753
- var _a;
1754
- const { submission, onSubmissionClick, compact, labelType, rowDecorator } = props;
1755
- const currentUser = core.useAppSelector(core.selectCurrentUser);
1756
- const createdBy = core.useAppSelector(core.selectUser("created_by" in submission ? submission.created_by : currentUser.id));
1757
- const dateToUse = getCreatedAtOrSubmittedAtDate(submission);
1758
- const formattedDateTime = core.isToday(dateToUse) ? dateToUse.toLocaleTimeString([], {
1759
- hour: "2-digit",
1760
- minute: "2-digit"
1761
- }) : core.getLocalDateString(dateToUse);
1762
- const revision = core.useAppSelector(core.selectFormRevision(submission.form_revision));
1763
- if (!revision) {
1764
- throw new Error(`Could not find revision ${submission.form_revision} for submission ${submission.offline_id}.`);
1765
- }
1766
- const latestRevisionNumber = (_a = core.useAppSelector(core.selectLatestFormRevision(revision.form))) == null ? void 0 : _a.revision;
1767
- const creatorProfileSrc = core.useFileSrc({
1768
- file: (createdBy == null ? void 0 : createdBy.profile.file) ?? null,
1769
- fileSha1: (createdBy == null ? void 0 : createdBy.profile.file_sha1) ?? null
1770
- });
1771
- const creatorProfileFallback = (createdBy == null ? void 0 : createdBy.username.charAt(0).toUpperCase()) ?? "?";
1772
- const isLatestRevision = revision.revision === latestRevisionNumber;
1773
- const handleClick = React.useCallback(() => {
1774
- if (onSubmissionClick) {
1775
- onSubmissionClick({ submission });
1776
- }
1777
- }, [submission, onSubmissionClick]);
1778
- const row = /* @__PURE__ */ jsxRuntime.jsx(blocks.ButtonList.Item, { onClick: handleClick, asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { grow: "1", width: "100%", p: "2", gap: "2", justify: "between", children: [
1779
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", className: styles.stopHorizontalOverflow, children: [
1780
- /* @__PURE__ */ jsxRuntime.jsx(themes.Avatar, { src: creatorProfileSrc, size: "1", fallback: creatorProfileFallback }),
1781
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "2", noWrap: true, children: labelType === "creator" ? (createdBy || currentUser).username : revision.title })
1782
- ] }),
1783
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
1784
- !compact && (revision.revision ? /* @__PURE__ */ jsxRuntime.jsx(blocks.Badge, { variant: "soft", severity: isLatestRevision ? "primary" : "info", children: compact ? revision.revision.toString() : `Revision #${revision.revision}` }) : !!latestRevisionNumber && /* @__PURE__ */ jsxRuntime.jsx(blocks.Badge, { children: "Original" })),
1785
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "2", noWrap: true, children: formattedDateTime })
1786
- ] })
1787
- ] }) });
1788
- if (rowDecorator) {
1789
- return rowDecorator(submission, row);
1790
- }
1791
- return row;
1792
- });
1793
- const getCreatedAtOrSubmittedAtDate = (submission) => {
1794
- const date = "created_at" in submission ? submission.created_at : submission.submitted_at;
1795
- return new Date(date);
1796
- };
1797
- const FormSubmissionBrowser = React.memo(function FormSubmissionBrowser2(props) {
1798
- const {
1799
- formId: formId2,
1800
- submissions: propSubmissions,
1801
- compact = false,
1802
- className,
1803
- after,
1804
- variant = "outline",
1805
- ...submissionEntryProps
1806
- } = props;
1807
- if (!!formId2 === !!propSubmissions) {
1808
- throw new Error("Either formId or submissions must be provided, but not both.");
1809
- }
1810
- const submissions = core.useAppSelector(
1811
- propSubmissions ? () => propSubmissions : core.selectSubmissionsForForm(formId2)
1812
- );
1813
- const sortedSubmissions = React.useMemo(
1814
- () => submissions == null ? void 0 : submissions.sort((a, b) => {
1815
- return getCreatedAtOrSubmittedAtDate(b).getTime() - getCreatedAtOrSubmittedAtDate(a).getTime();
1816
- }),
1817
- [submissions]
1818
- );
1819
- return /* @__PURE__ */ jsxRuntime.jsx(
1820
- blocks.ButtonList.Root,
1821
- {
1822
- className: core.classNames(styles.submissionsContainer, className),
1823
- size: "small",
1824
- variant,
1825
- before: !compact && /* @__PURE__ */ jsxRuntime.jsxs(blocks.Text, { severity: "info", children: [
1826
- "There are ",
1827
- ((submissions == null ? void 0 : submissions.length) || 0).toString(),
1828
- " submissions of this form."
1829
- ] }),
1830
- after,
1831
- children: sortedSubmissions == null ? void 0 : sortedSubmissions.map((submission, index) => {
1832
- return /* @__PURE__ */ jsxRuntime.jsx(
1833
- FormSubmissionBrowserEntry,
1834
- {
1835
- submission,
1836
- compact,
1837
- ...submissionEntryProps
1838
- },
1839
- index
1840
- );
1841
- })
1842
- }
1843
- );
1844
- });
1845
- const PatchField = React.memo(function PatchField2(props) {
1846
- const { name, render } = props;
1847
- const { submitForm } = formik.useFormikContext();
1848
- const [fieldProps, _meta, helpers] = formik.useField(name);
1849
- return React.useMemo(() => {
1850
- const setValue = (value) => helpers.setValue(value, false);
1851
- return render({
1852
- value: fieldProps.value,
1853
- setValue,
1854
- patchValue: submitForm
1855
- });
1856
- }, [submitForm, helpers, fieldProps.value, render]);
1857
- });
1858
- const PatchFormProvider = React.memo(
1859
- React.forwardRef((props, ref) => {
1860
- const { children, schema, values, onPatch, onError, ...rest } = props;
1861
- const initialValues2 = React.useMemo(() => initialFormValues(schema.fields, values), [schema.fields, values]);
1862
- const handlePatch = React.useCallback(
1863
- (values2) => {
1864
- const diff = {};
1865
- for (const key in values2) {
1866
- const value = values2[key];
1867
- if (value !== initialValues2[key] && value !== void 0) {
1868
- diff[key] = value;
1869
- }
1870
- }
1871
- if (!hasKeys(diff))
1872
- return;
1873
- onPatch(diff);
1874
- },
1875
- [initialValues2, onPatch]
1876
- );
1877
- const validate = React.useCallback(
1878
- async (form) => {
1879
- const error = await validateForm(schema, form);
1880
- if (error) {
1881
- onError(error);
1882
- }
1883
- return error;
1884
- },
1885
- [schema, onError]
1886
- );
1887
- const formik$1 = formik.useFormik({
1888
- initialValues: initialValues2,
1889
- onSubmit: handlePatch,
1890
- validate,
1891
- // only validate the entire form on submit
1892
- validateOnBlur: false,
1893
- validateOnChange: false
1894
- });
1895
- const { errors, resetForm } = formik$1;
1896
- React.useEffect(() => {
1897
- if (hasKeys(errors)) {
1898
- resetForm({ values: initialValues2, errors: {} });
1899
- }
1900
- }, [errors, initialValues2, resetForm]);
1901
- return /* @__PURE__ */ jsxRuntime.jsx(formik.FormikProvider, { value: formik$1, children: /* @__PURE__ */ jsxRuntime.jsx("form", { ...rest, ref, onSubmit: formik$1.handleSubmit, children }) });
1902
- })
1903
- );
1904
- const CompleteFieldTypeToClsMapping = {
1905
- ...FieldTypeToClsMapping,
1906
- section: FieldSection
1907
- };
1908
- const FieldToChoose = React.memo(function FieldToChoose2(props) {
1909
- const { field, setFieldType } = props;
1910
- const typeName = field.fieldTypeName;
1911
- const description2 = field.fieldTypeDescription;
1912
- const Icon = field.Icon;
1913
- return /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "4", align: "center", children: [
1914
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Button, { type: "button", variant: "surface", onClick: setFieldType, style: { width: "135px" }, children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "3", align: "center", grow: "1", children: [
1915
- /* @__PURE__ */ jsxRuntime.jsx(Icon, {}),
1916
- typeName
1917
- ] }) }),
1918
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { children: description2 })
1919
- ] });
1920
- });
1921
- const fieldsToChoose = [
1922
- ["string", "text"],
1923
- ["select", "multi-select", "upload"],
1924
- ["boolean", "date", "number", "multi-string"]
1925
- ];
1926
- const indexOfLastFieldGroup = fieldsToChoose.length - 1;
1927
- const ChooseFieldToAdd = React.memo(function ChooseFieldToAdd2(props) {
1928
- const { setFieldType } = props;
1929
- return /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "column", gap: "3", children: fieldsToChoose.map((fieldGroup, index) => /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "3", children: [
1930
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { direction: "column", gap: "2", children: fieldGroup.map((identifier) => /* @__PURE__ */ jsxRuntime.jsx(
1931
- FieldToChoose,
1932
- {
1933
- field: FieldTypeToClsMapping[identifier],
1934
- setFieldType: () => setFieldType(identifier)
1935
- },
1936
- identifier
1937
- )) }),
1938
- index < indexOfLastFieldGroup && /* @__PURE__ */ jsxRuntime.jsx(blocks.Separator, { size: "4" })
1939
- ] }, index)) });
1940
- });
1941
- const validateNewFieldName = (takenLabels) => {
1942
- return (value) => {
1943
- if (!value || typeof value !== "string")
1944
- return;
1945
- if (takenLabels.includes(value.trim())) {
1946
- return "This name is already taken.";
1947
- }
1948
- };
1949
- };
1950
- const commonFields = (takenLabels, type) => {
1951
- const base = [
1952
- new StringField({
1953
- label: "Label",
1954
- required: true,
1955
- maxLength: 200,
1956
- identifier: "label",
1957
- fieldValidators: [validateNewFieldName(takenLabels)]
1958
- }),
1959
- new TextField({
1960
- label: "Description",
1961
- required: false,
1962
- maxLength: 1e3,
1963
- identifier: "description"
1964
- })
1965
- ];
1966
- if (type === "section")
1967
- return base;
1968
- return [
1969
- ...base,
1970
- new BooleanField({ label: "Required", description: null, required: false, identifier: "required" })
1971
- ];
1972
- };
1973
- const FieldOptionsForm = React.memo(function FieldOptionsForm2(props) {
1974
- const { fieldType, handleCancel, handleCreateField, handleDirtyChange, defaultField, conditionalSourceFields } = props;
1975
- const fieldCls = CompleteFieldTypeToClsMapping[fieldType];
1976
- const formik$1 = formik.useFormikContext();
1977
- const schema = React.useMemo(() => {
1978
- const takenFieldLabels = getTakenFieldLabels(formik$1.values.fields).filter((id) => id !== (defaultField == null ? void 0 : defaultField.label));
1979
- let fields = commonFields(takenFieldLabels, fieldType);
1980
- if (fieldCls === FieldSection) {
1981
- if (conditionalSourceFields === void 0) {
1982
- throw new Error("Conditional source fields must be provided when changing sections.");
1983
- }
1984
- fields = fields.concat(fieldCls.getFieldCreationSchema(conditionalSourceFields));
1985
- } else {
1986
- if (!(fieldCls.prototype instanceof BaseField)) {
1987
- throw new Error(`Field must be an instance of BaseField. Got ${fieldCls}.`);
1988
- }
1989
- fields = [...fields, ...fieldCls.getFieldCreationSchema()];
1990
- }
1991
- return {
1992
- fields,
1993
- meta: { readonly: false },
1994
- // using the dialog title as the form title
1995
- title: null
1996
- };
1997
- }, [formik$1.values.fields, fieldType, fieldCls, defaultField == null ? void 0 : defaultField.label, conditionalSourceFields]);
1998
- return /* @__PURE__ */ jsxRuntime.jsx(
1999
- FormRenderer,
2000
- {
2001
- schema,
2002
- values: defaultField,
2003
- onSubmit: handleCreateField,
2004
- cancelText: defaultField ? void 0 : "Back",
2005
- onCancel: handleCancel,
2006
- onDirtyChange: handleDirtyChange
2007
- }
2008
- );
2009
- });
2010
- const FieldBuilder = React.memo(function FieldBuilder2(props) {
2011
- const { parentPath, index, isOpen, setIsOpen, initial, editing, conditionalSourceFields } = props;
2012
- const [fieldType, setFieldType] = React.useState();
2013
- const [formIsDirty, setFormIsDirty] = React.useState(false);
2014
- const type = (initial == null ? void 0 : initial.type) ?? fieldType;
2015
- const typeName = type ? CompleteFieldTypeToClsMapping[type].fieldTypeName : void 0;
2016
- const { setFieldValue, values } = formik.useFormikContext();
2017
- if (editing && !initial)
2018
- throw new Error("Initial field must be provided if editing is true.");
2019
- const openConfirmDiscardChangesDialog = blocks.useDiscardAlertDialog();
2020
- const showChooseField = !type && !editing && !initial;
2021
- const title2 = showChooseField ? "Choose a field type" : `${typeName} settings`;
2022
- const description2 = showChooseField ? "Select a field type to add to this section." : (typeName == null ? void 0 : typeName.toLowerCase()) === "section" ? "Customize your section" : `Customize your ${typeName == null ? void 0 : typeName.toLowerCase()} field.`;
2023
- const handleCancel = React.useCallback(() => {
2024
- setFieldType(void 0);
2025
- setFormIsDirty(false);
2026
- }, []);
2027
- const handleCloseDialog = React.useCallback(() => {
2028
- if (!formIsDirty) {
2029
- setFieldType(void 0);
2030
- setIsOpen(false);
2031
- } else {
2032
- openConfirmDiscardChangesDialog({
2033
- onDiscard: () => {
2034
- setFieldType(void 0);
2035
- setIsOpen(false);
2036
- }
2037
- });
2038
- }
2039
- }, [formIsDirty, openConfirmDiscardChangesDialog, setIsOpen]);
2040
- const handleCreateField = React.useCallback(
2041
- (form) => {
2042
- const { label } = form;
2043
- if (!type)
2044
- throw new Error("Field type must be selected before creating a field.");
2045
- if (!label || typeof label !== "string")
2046
- throw new Error("Label must be provided before creating a field.");
2047
- const field = deserialize({
2048
- type,
2049
- ...form,
2050
- identifier: makeIdentifier(form.identifier, label)
2051
- }).serialize();
2052
- const parent = get(values, parentPath);
2053
- if (parent === void 0) {
2054
- throw new Error("Parent path must point to an existing field.");
2055
- }
2056
- let newFields;
2057
- if (!Array.isArray(parent))
2058
- throw new Error("Parent path must point to an array.");
2059
- if (editing) {
2060
- newFields = replace(parent, index, field);
2061
- } else {
2062
- newFields = insert(parent, index, field);
2063
- }
2064
- setFieldValue(parentPath, newFields).then();
2065
- setIsOpen(false);
2066
- },
2067
- [type, values, parentPath, editing, setFieldValue, setIsOpen, index]
2068
- );
2069
- const handleDirtyChange = React.useCallback((dirty) => setFormIsDirty(dirty), []);
2070
- const dialogContent = React.useCallback(() => {
2071
- if (showChooseField) {
2072
- return /* @__PURE__ */ jsxRuntime.jsx(ChooseFieldToAdd, { setFieldType });
2073
- }
2074
- return /* @__PURE__ */ jsxRuntime.jsx(
2075
- FieldOptionsForm,
2076
- {
2077
- conditionalSourceFields,
2078
- handleCancel,
2079
- handleCreateField,
2080
- fieldType: type,
2081
- defaultField: initial,
2082
- handleDirtyChange
2083
- }
2084
- );
2085
- }, [conditionalSourceFields, handleCancel, handleCreateField, handleDirtyChange, initial, showChooseField, type]);
2086
- return /* @__PURE__ */ jsxRuntime.jsx(
2087
- blocks.Dialog,
2088
- {
2089
- title: title2,
2090
- description: description2,
2091
- content: dialogContent,
2092
- open: isOpen,
2093
- onOpenChange: handleCloseDialog
2094
- }
2095
- );
2096
- });
2097
- const forMobile = (mobile, display) => ({
2098
- initial: mobile ? display : "none",
2099
- sm: mobile ? "none" : display
2100
- });
2101
- const FieldActions = React.memo(function FieldActions2(props) {
2102
- const { remove: remove2, dragHandleProps, editProps, insertAfterProps, duplicateProps } = props;
2103
- const [isEditDialogOpen, setIsEditDialogOpen] = React.useState(false);
2104
- const [isDuplicateDialogOpen, setIsDuplicateDialogOpen] = React.useState(false);
2105
- const [isAddDialogOpen, setIsAddDialogOpen] = React.useState(false);
2106
- const actions = React.useMemo(
2107
- () => [
2108
- {
2109
- SelectedContent: FieldBuilder,
2110
- selectedContentProps: { ...editProps, isOpen: isEditDialogOpen, setIsOpen: setIsEditDialogOpen },
2111
- Icon: reactIcons.Pencil1Icon,
2112
- text: "Edit",
2113
- buttonProps: { onClick: () => setIsEditDialogOpen(true) }
2114
- },
2115
- {
2116
- Icon: reactIcons.TrashIcon,
2117
- buttonProps: {
2118
- onClick: remove2
2119
- },
2120
- text: "Delete"
2121
- },
2122
- {
2123
- SelectedContent: FieldBuilder,
2124
- selectedContentProps: {
2125
- ...duplicateProps,
2126
- isOpen: isDuplicateDialogOpen,
2127
- setIsOpen: setIsDuplicateDialogOpen
2128
- },
2129
- Icon: reactIcons.CopyIcon,
2130
- text: "Duplicate",
2131
- buttonProps: { onClick: () => setIsDuplicateDialogOpen(true) }
2132
- },
2133
- {
2134
- SelectedContent: FieldBuilder,
2135
- selectedContentProps: { ...insertAfterProps, isOpen: isAddDialogOpen, setIsOpen: setIsAddDialogOpen },
2136
- Icon: reactIcons.PlusIcon,
2137
- text: "Add after",
2138
- buttonProps: { onClick: () => setIsAddDialogOpen(true) }
2139
- },
2140
- {
2141
- // Wrapping icon in a div so that the asChild turns the button into a div
2142
- // so that the drag handle props are not applied to the icon
2143
- // Note: b/c the <button> does not handle the space-press event correctly
2144
- Icon: (props2) => /* @__PURE__ */ jsxRuntime.jsx("div", { ...props2, children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.DragHandleDots2Icon, {}) }),
2145
- text: "Reorder",
2146
- disableOnMobile: true,
2147
- buttonProps: { ...dragHandleProps, asChild: true }
2148
- }
2149
- ],
2150
- [
2151
- dragHandleProps,
2152
- duplicateProps,
2153
- editProps,
2154
- insertAfterProps,
2155
- isAddDialogOpen,
2156
- isDuplicateDialogOpen,
2157
- isEditDialogOpen,
2158
- remove2
2159
- ]
2160
- );
2161
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2162
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { gap: "4", display: forMobile(false, "flex"), children: actions.map((Action) => {
2163
- return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
2164
- /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { type: "button", variant: "ghost", "aria-label": Action.text, ...Action.buttonProps, children: /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}) }),
2165
- Action.SelectedContent && /* @__PURE__ */ jsxRuntime.jsx(Action.SelectedContent, { ...Action.selectedContentProps })
2166
- ] }, Action.text);
2167
- }) }),
2168
- /* @__PURE__ */ jsxRuntime.jsx(themes.Box, { display: forMobile(true, "block"), children: /* @__PURE__ */ jsxRuntime.jsx(
2169
- blocks.DropdownItemMenu,
2170
- {
2171
- trigger: /* @__PURE__ */ jsxRuntime.jsx(blocks.IconButton, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.DotsVerticalIcon, {}) }),
2172
- items: actions.map((Action) => {
2173
- var _a;
2174
- if (Action.disableOnMobile)
2175
- return null;
2176
- return {
2177
- ...Action.buttonProps,
2178
- onSelect: (_a = Action.buttonProps) == null ? void 0 : _a.onClick,
2179
- content: /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [
2180
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "2", align: "center", children: [
2181
- /* @__PURE__ */ jsxRuntime.jsx(Action.Icon, {}),
2182
- Action.text
2183
- ] }),
2184
- Action.SelectedContent && /* @__PURE__ */ jsxRuntime.jsx(Action.SelectedContent, { ...Action.selectedContentProps })
2185
- ] }, Action.text)
2186
- };
2187
- }).filter((x) => x !== null)
2188
- }
2189
- ) })
2190
- ] });
2191
- });
2192
- const formId = "form-builder";
2193
- const FieldWithActions = React.memo(function FieldWithActions2(props) {
2194
- const { field, index, sectionIndex, takenLabels, remove: remove2 } = props;
2195
- const deserializedField = React.useMemo(() => deserialize(field), [field]);
2196
- const input = useFieldInput(deserializedField, { formId, disabled: true });
2197
- const duplicateField = React.useCallback(
2198
- (field2) => {
2199
- const fieldLabel = field2.label ?? "Untitled field";
2200
- return { ...field2, label: incrementFieldLabel(fieldLabel, takenLabels), identifier: "" };
2201
- },
2202
- [takenLabels]
2203
- );
2204
- const editFieldProps = React.useMemo(
2205
- () => ({
2206
- index,
2207
- parentPath: `fields.${sectionIndex}.fields`,
2208
- initial: field,
2209
- editing: true
2210
- }),
2211
- [field, index, sectionIndex]
2212
- );
2213
- const duplicateFieldProps = React.useMemo(
2214
- () => ({
2215
- parentPath: `fields.${sectionIndex}.fields`,
2216
- index: index + 1,
2217
- initial: duplicateField(field)
2218
- }),
2219
- [duplicateField, field, index, sectionIndex]
2220
- );
2221
- const insertAfterProps = React.useMemo(
2222
- () => ({
2223
- parentPath: `fields.${sectionIndex}.fields`,
2224
- index: index + 1,
2225
- initial: void 0
2226
- }),
2227
- [index, sectionIndex]
2228
- );
2229
- return /* @__PURE__ */ jsxRuntime.jsx(dnd.Draggable, { draggableId: field.identifier, index, children: (draggableProvided) => /* @__PURE__ */ jsxRuntime.jsx(
2230
- themes.Card,
2231
- {
2232
- ref: draggableProvided.innerRef,
2233
- ...draggableProvided.draggableProps,
2234
- ...draggableProvided.dragHandleProps,
2235
- mb: "4",
2236
- children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "4", justify: "between", align: "center", children: [
2237
- input,
2238
- /* @__PURE__ */ jsxRuntime.jsx(
2239
- FieldActions,
2240
- {
2241
- remove: remove2,
2242
- editProps: editFieldProps,
2243
- duplicateProps: duplicateFieldProps,
2244
- insertAfterProps,
2245
- dragHandleProps: draggableProvided.dragHandleProps
2246
- }
2247
- )
2248
- ] })
2249
- }
2250
- ) });
2251
- });
2252
- const FieldSectionWithActions = React.memo(function FieldSectionWithActions2(props) {
2253
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2254
- const { field, index: sectionIndex, dropState } = props;
2255
- const isDropDisabled = (_a = dropState[field.identifier]) == null ? void 0 : _a.disabled;
2256
- const [isAddFieldDialogOpen, setIsAddFieldDialogOpen] = React.useState(false);
2257
- const { setFieldValue, values } = formik.useFormikContext();
2258
- const alertDialog = blocks.useAlertDialog();
2259
- const takenFieldLabels = getTakenFieldLabels(values.fields);
2260
- const removeSectionConditions = React.useCallback(
2261
- (sectionsToUpdate, allSections) => {
2262
- for (const section of sectionsToUpdate) {
2263
- const sectionIndex2 = allSections.indexOf(section);
2264
- setFieldValue(`fields.${sectionIndex2}.condition`, null).then();
2265
- setFieldValue(`fields.${sectionIndex2}.conditional`, false).then();
2266
- }
2267
- },
2268
- [setFieldValue]
2269
- );
2270
- const makeRemoveFieldAction = React.useCallback(
2271
- (fieldIndex) => {
2272
- var _a2;
2273
- const removing = field.fields[fieldIndex];
2274
- if (!removing)
2275
- throw new Error("Could not find field to remove.");
2276
- const sectionsWithMatchingCondition = [];
2277
- for (const section of values.fields) {
2278
- if (((_a2 = section.condition) == null ? void 0 : _a2.identifier) === removing.identifier) {
2279
- sectionsWithMatchingCondition.push(section);
2280
- }
2281
- }
2282
- return {
2283
- removing,
2284
- affectedSections: sectionsWithMatchingCondition,
2285
- action: () => setFieldValue(`fields.${sectionIndex}.fields`, remove(field.fields, fieldIndex))
2286
- };
2287
- },
2288
- [field.fields, values.fields, setFieldValue, sectionIndex]
2289
- );
2290
- const removeField = React.useCallback(
2291
- (i) => {
2292
- const { affectedSections, action, removing } = makeRemoveFieldAction(i);
2293
- const cmd = () => {
2294
- action().then();
2295
- removeSectionConditions(affectedSections, values.fields);
2296
- };
2297
- if (affectedSections.length > 0) {
2298
- const labels = affectedSections.map((section) => section.label).join(", ");
2299
- return alertDialog({
2300
- title: "Remove condition?",
2301
- description: `${removing.label} is being used as a condition, deleting it will remove the condition from the ${labels} section(s).`,
2302
- severity: "danger",
2303
- actionText: "Remove",
2304
- onAction: cmd
2305
- });
2306
- }
2307
- cmd();
2308
- },
2309
- [makeRemoveFieldAction, removeSectionConditions, values.fields, alertDialog]
2310
- );
2311
- const removeSection = React.useCallback(() => {
2312
- const fieldSideEffects = field.fields.map((_, i) => makeRemoveFieldAction(i));
2313
- const affectedSections = fieldSideEffects.flatMap((sideEffect) => sideEffect.affectedSections);
2314
- const title2 = affectedSections.length ? "Remove fields and conditions?" : "Remove fields?";
2315
- const numFields = field.fields.length;
2316
- const sectionLabels = affectedSections.map((section) => section.label).join(", ");
2317
- const description2 = affectedSections.length ? `Deleting this section will remove the ${numFields} field(s) it contains and will remove the conditions from following sections: ${sectionLabels}` : `Deleting this section will remove the ${numFields} field(s) it contains.`;
2318
- const updatedSections = remove(values.fields, sectionIndex);
2319
- const cmd = () => setFieldValue("fields", updatedSections);
2320
- if (affectedSections.length > 0) {
2321
- return alertDialog({
2322
- title: title2,
2323
- description: description2,
2324
- severity: "danger",
2325
- actionText: "Remove",
2326
- onAction: () => {
2327
- cmd().then(() => {
2328
- removeSectionConditions(affectedSections, updatedSections);
2329
- });
2330
- }
2331
- });
2332
- }
2333
- cmd().then();
2334
- }, [
2335
- field.fields,
2336
- values.fields,
2337
- sectionIndex,
2338
- makeRemoveFieldAction,
2339
- setFieldValue,
2340
- alertDialog,
2341
- removeSectionConditions
2342
- ]);
2343
- const duplicateSection = React.useCallback(
2344
- (field2) => {
2345
- const fieldLabel = field2.label ?? "Untitled section";
2346
- const newSectionLabel = incrementFieldLabel(fieldLabel, takenFieldLabels);
2347
- const newFields = field2.fields.map((f) => {
2348
- const newLabel = incrementFieldLabel(f.label ?? "Untitled field", takenFieldLabels);
2349
- return {
2350
- ...f,
2351
- label: newLabel,
2352
- identifier: makeIdentifier(void 0, newLabel)
2353
- };
2354
- });
2355
- return { ...field2, label: newSectionLabel, fields: newFields, identifier: "" };
2356
- },
2357
- [takenFieldLabels]
2358
- );
2359
- const editSectionProps = React.useMemo(
2360
- () => ({
2361
- index: sectionIndex,
2362
- parentPath: "fields",
2363
- initial: field,
2364
- editing: true,
2365
- conditionalSourceFields: makeConditionalSourceFields(values.fields, sectionIndex)
2366
- }),
2367
- [field, sectionIndex, values.fields]
2368
- );
2369
- const insertSectionProps = React.useMemo(
2370
- () => ({
2371
- index: sectionIndex + 1,
2372
- parentPath: "fields",
2373
- initial: emptySection(),
2374
- conditionalSourceFields: makeConditionalSourceFields(values.fields, sectionIndex + 1)
2375
- }),
2376
- [sectionIndex, values.fields]
2377
- );
2378
- const insertFieldAtEndOfSection = React.useMemo(
2379
- () => ({
2380
- parentPath: `fields.${sectionIndex}.fields`,
2381
- index: field.fields.length,
2382
- initial: void 0
2383
- }),
2384
- [field.fields.length, sectionIndex]
2385
- );
2386
- const duplicateSectionProps = React.useMemo(
2387
- () => ({
2388
- index: sectionIndex + 1,
2389
- parentPath: "fields",
2390
- initial: duplicateSection(field),
2391
- conditionalSourceFields: makeConditionalSourceFields(values.fields, sectionIndex + 1)
2392
- }),
2393
- [duplicateSection, field, sectionIndex, values.fields]
2394
- );
2395
- const conditionLabel = React.useMemo(
2396
- () => {
2397
- var _a2, _b2;
2398
- return (_b2 = findFieldByIdentifier(values.fields, (_a2 = field.condition) == null ? void 0 : _a2.identifier)) == null ? void 0 : _b2.label;
2399
- },
2400
- [(_b = field.condition) == null ? void 0 : _b.identifier, values.fields]
2401
- );
2402
- const conditionComparison = Array.isArray((_c = field.condition) == null ? void 0 : _c.value) ? "contains all of" : "equals";
2403
- if (valueIsFile((_d = field.condition) == null ? void 0 : _d.value))
2404
- throw new Error("File values are not supported for conditions.");
2405
- const conditionValue = Array.isArray((_e = field.condition) == null ? void 0 : _e.value) ? (_g = (_f = field.condition) == null ? void 0 : _f.value) == null ? void 0 : _g.map((v) => typeof v === "string" ? v : v.label).join(", ") : (_i = (_h = field.condition) == null ? void 0 : _h.value) == null ? void 0 : _i.toString();
2406
- return /* @__PURE__ */ jsxRuntime.jsx(dnd.Draggable, { draggableId: field.identifier, index: sectionIndex, children: (draggableProvided) => /* @__PURE__ */ jsxRuntime.jsx(
2407
- themes.Card,
2408
- {
2409
- ref: draggableProvided.innerRef,
2410
- ...draggableProvided.draggableProps,
2411
- ...draggableProvided.dragHandleProps,
2412
- mb: "4",
2413
- children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { gap: "3", justify: "between", align: "center", children: [
2414
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "2", grow: "1", children: [
2415
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", children: [
2416
- /* @__PURE__ */ jsxRuntime.jsx(themes.Heading, { as: "h3", size: "3", children: field.label }),
2417
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { className: styles$4.description, children: field.description })
2418
- ] }),
2419
- field.condition && /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { size: "1", children: /* @__PURE__ */ jsxRuntime.jsxs(themes.Em, { children: [
2420
- "Display only if ",
2421
- /* @__PURE__ */ jsxRuntime.jsx(themes.Strong, { children: conditionLabel }),
2422
- " ",
2423
- conditionComparison,
2424
- " ",
2425
- /* @__PURE__ */ jsxRuntime.jsx(themes.Strong, { children: conditionValue })
2426
- ] }) }),
2427
- /* @__PURE__ */ jsxRuntime.jsx(dnd.Droppable, { droppableId: field.identifier, type: "SECTION", isDropDisabled, children: (droppableProvided) => /* @__PURE__ */ jsxRuntime.jsxs(
2428
- blocks.Flex,
2429
- {
2430
- ref: droppableProvided.innerRef,
2431
- ...droppableProvided.droppableProps,
2432
- direction: "column",
2433
- gap: "0",
2434
- children: [
2435
- field.fields.map((child, i) => /* @__PURE__ */ jsxRuntime.jsx(
2436
- FieldWithActions,
2437
- {
2438
- field: child,
2439
- index: i,
2440
- sectionIndex,
2441
- remove: () => removeField(i),
2442
- takenLabels: takenFieldLabels
2443
- },
2444
- child.identifier
2445
- )),
2446
- droppableProvided.placeholder,
2447
- /* @__PURE__ */ jsxRuntime.jsxs(
2448
- blocks.Button,
2449
- {
2450
- type: "button",
2451
- variant: "outline",
2452
- onClick: () => setIsAddFieldDialogOpen(true),
2453
- children: [
2454
- /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2455
- " Add a field"
2456
- ]
2457
- }
2458
- ),
2459
- /* @__PURE__ */ jsxRuntime.jsx(
2460
- FieldBuilder,
2461
- {
2462
- ...insertFieldAtEndOfSection,
2463
- isOpen: isAddFieldDialogOpen,
2464
- setIsOpen: setIsAddFieldDialogOpen
2465
- }
2466
- )
2467
- ]
2468
- }
2469
- ) })
2470
- ] }),
2471
- /* @__PURE__ */ jsxRuntime.jsx(
2472
- FieldActions,
2473
- {
2474
- remove: removeSection,
2475
- insertAfterProps: insertSectionProps,
2476
- dragHandleProps: draggableProvided.dragHandleProps,
2477
- editProps: editSectionProps,
2478
- duplicateProps: duplicateSectionProps
2479
- }
2480
- )
2481
- ] })
2482
- }
2483
- ) });
2484
- });
2485
- const reducer = (state, action) => {
2486
- var _a;
2487
- const next = { ...state };
2488
- switch (action.type) {
2489
- case "release":
2490
- for (const sectionId in next) {
2491
- next[sectionId].disabled = false;
2492
- }
2493
- return next;
2494
- case "hold":
2495
- for (const sectionId in next) {
2496
- if ((_a = next[sectionId]) == null ? void 0 : _a.conditionFields.has(action.fieldId)) {
2497
- next[sectionId].disabled = true;
2498
- }
2499
- }
2500
- return next;
2501
- case "update":
2502
- return action.state;
2503
- }
2504
- };
2505
- const getConditionIndex = (fields, identifier) => {
2506
- if (!identifier)
2507
- return void 0;
2508
- for (let i = 0; i < fields.length; i++) {
2509
- const section = fields[i];
2510
- if (!section)
2511
- continue;
2512
- for (const field of section.fields) {
2513
- if (field.identifier === identifier)
2514
- return i;
2515
- }
2516
- }
2517
- };
2518
- const initializer = (fields) => {
2519
- var _a, _b, _c;
2520
- const acc = {};
2521
- for (let index = 0; index < fields.length; index++) {
2522
- const field = fields[index];
2523
- if (!field)
2524
- throw new Error("Field is undefined.");
2525
- const previousConditionFields = index > 0 ? (_a = acc[fields[index - 1].identifier]) == null ? void 0 : _a.conditionFields : void 0;
2526
- const disabledFields = new Set(previousConditionFields);
2527
- if ((_b = field.condition) == null ? void 0 : _b.identifier) {
2528
- disabledFields.add(field.condition.identifier);
2529
- }
2530
- acc[field.identifier] = {
2531
- disabled: false,
2532
- conditionFields: disabledFields,
2533
- conditionIndex: getConditionIndex(fields, (_c = field.condition) == null ? void 0 : _c.identifier),
2534
- index,
2535
- label: field.label
2536
- };
2537
- }
2538
- return acc;
2539
- };
2540
- const findSection = (fields, sectionId) => {
2541
- for (const [i, section] of Object.entries(fields)) {
2542
- if (section.identifier === sectionId)
2543
- return [section, i];
2544
- }
2545
- };
2546
- const FieldsEditor = React.memo(function FieldsEditor2() {
2547
- const { values, setFieldValue } = formik.useFormikContext();
2548
- const [dropState, dispatch] = React.useReducer(reducer, values.fields, initializer);
2549
- const [isAddSectionDialogOpen, setIsAddSectionDialogOpen] = React.useState(false);
2550
- const { showInfo } = blocks.useToast();
2551
- React.useEffect(() => {
2552
- dispatch({ type: "update", state: initializer(values.fields) });
2553
- }, [dispatch, values.fields]);
2554
- const handleDragStart = React.useCallback((start) => {
2555
- if (start.type === "SECTION") {
2556
- dispatch({ type: "hold", fieldId: start.draggableId });
2557
- }
2558
- }, []);
2559
- const handleDragEnd = React.useCallback(
2560
- (result) => {
2561
- const { source, destination, type, reason, draggableId } = result;
2562
- dispatch({ type: "release" });
2563
- if (!destination || reason === "CANCEL")
2564
- return;
2565
- if (type === "ROOT") {
2566
- const state = dropState[draggableId];
2567
- if (!state)
2568
- throw new Error("Could not find section context.");
2569
- let dest = typeof state.conditionIndex !== "undefined" ? (
2570
- // cannot move a section with a condition before the condition's field
2571
- Math.max(state.conditionIndex + 1, destination.index)
2572
- ) : destination.index;
2573
- for (const section of Object.values(dropState)) {
2574
- if (section.conditionIndex === source.index) {
2575
- dest = Math.min(dest, section.index - 1);
2576
- }
2577
- }
2578
- if (dest != destination.index) {
2579
- showInfo({
2580
- title: "Reordered sections",
2581
- description: "Sections with conditions must be below the fields they reference."
2582
- });
2583
- }
2584
- return setFieldValue("fields", reorder(values.fields, source.index, dest));
2585
- }
2586
- if (type !== "SECTION")
2587
- throw new Error("Unexpected droppable type.");
2588
- const [sourceSection, srcIndex] = findSection(values.fields, source.droppableId) ?? [];
2589
- const [destinationSection, destIndex] = findSection(values.fields, destination.droppableId) ?? [];
2590
- if (!(sourceSection == null ? void 0 : sourceSection.fields) || !destinationSection)
2591
- throw new Error("Could not find section with fields.");
2592
- if (sourceSection.identifier === destinationSection.identifier) {
2593
- setFieldValue(
2594
- `fields.${srcIndex}.fields`,
2595
- reorder(sourceSection.fields, source.index, destination.index)
2596
- ).then();
2597
- } else {
2598
- const removed = sourceSection.fields[source.index];
2599
- if (!removed)
2600
- throw new Error("Could not find field to reorder.");
2601
- setFieldValue(`fields.${srcIndex}.fields`, remove(sourceSection.fields, source.index)).then();
2602
- setFieldValue(
2603
- `fields.${destIndex}.fields`,
2604
- insert(destinationSection.fields, destination.index, removed)
2605
- ).then();
2606
- }
2607
- },
2608
- [values.fields, setFieldValue, dropState, showInfo]
2609
- );
2610
- const makeFieldSectionProps = React.useMemo(
2611
- () => ({
2612
- index: values.fields.length,
2613
- parentPath: "fields",
2614
- initial: emptySection(),
2615
- conditionalSourceFields: makeConditionalSourceFields(values.fields, values.fields.length)
2616
- }),
2617
- [values.fields]
2618
- );
2619
- return /* @__PURE__ */ jsxRuntime.jsx(dnd.DragDropContext, { onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsxRuntime.jsx(dnd.Droppable, { droppableId: "droppable", type: "ROOT", children: (droppableProvided) => /* @__PURE__ */ jsxRuntime.jsxs(
2620
- blocks.Flex,
2621
- {
2622
- ref: droppableProvided.innerRef,
2623
- ...droppableProvided.droppableProps,
2624
- direction: "column",
2625
- gap: "0",
2626
- children: [
2627
- values.fields.map((field, index) => /* @__PURE__ */ jsxRuntime.jsx(
2628
- FieldSectionWithActions,
2629
- {
2630
- field,
2631
- index,
2632
- dropState
2633
- },
2634
- field.label
2635
- )),
2636
- droppableProvided.placeholder,
2637
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Button, { type: "button", variant: "outline", onClick: () => setIsAddSectionDialogOpen(true), children: [
2638
- /* @__PURE__ */ jsxRuntime.jsx(reactIcons.PlusIcon, {}),
2639
- " Add a section"
2640
- ] }),
2641
- /* @__PURE__ */ jsxRuntime.jsx(
2642
- FieldBuilder,
2643
- {
2644
- ...makeFieldSectionProps,
2645
- isOpen: isAddSectionDialogOpen,
2646
- setIsOpen: setIsAddSectionDialogOpen
2647
- }
2648
- )
2649
- ]
2650
- }
2651
- ) }) });
2652
- });
2653
- const initialValues = {
2654
- title: "",
2655
- description: "",
2656
- fields: []
2657
- };
2658
- const title = new StringField({
2659
- label: "Title",
2660
- minLength: 0,
2661
- maxLength: 100,
2662
- required: true,
2663
- identifier: "title"
2664
- });
2665
- const titleProps = { formId, placeholder: "Give your form a title." };
2666
- const description = new TextField({
2667
- label: "Description",
2668
- minLength: 0,
2669
- maxLength: 1e3,
2670
- required: false,
2671
- identifier: "description"
2672
- });
2673
- const descriptionProps = { formId, placeholder: "Explain the purpose of this form." };
2674
- const previewSubmit = () => {
2675
- alert("This is a form preview, your data will not be saved.");
2676
- };
2677
- const FormBuilder = React.memo(
2678
- React.forwardRef((props, ref) => {
2679
- const { onCancel, onSave, revision } = props;
2680
- const { heading = revision ? "Edit form" : "Create a new form" } = props;
2681
- const validate = React.useCallback((form) => {
2682
- const errors = {};
2683
- if (!form.title) {
2684
- errors.title = "Title is required.";
2685
- }
2686
- if (!form.fields || form.fields.length === 0) {
2687
- errors.fields = "At least one field is required.";
2688
- }
2689
- if (hasKeys(errors)) {
2690
- return errors;
2691
- }
2692
- }, []);
2693
- const formik$1 = formik.useFormik({
2694
- initialValues: wrapRootFieldsWithFieldSection(revision) ?? initialValues,
2695
- validate,
2696
- onSubmit: (form) => onSave(form),
2697
- // only validate the entire for on submit
2698
- validateOnChange: false,
2699
- validateOnBlur: false
2700
- });
2701
- const previewSchema = React.useMemo(() => formRevisionToSchema(formik$1.values), [formik$1.values]);
2702
- const titleInput = useFieldInput(title, titleProps);
2703
- const descriptionInput = useFieldInput(description, descriptionProps);
2704
- const FormBuilderHeading = React.useMemo(
2705
- () => typeof heading === "object" ? heading : /* @__PURE__ */ jsxRuntime.jsx(themes.Heading, { children: heading }),
2706
- [heading]
2707
- );
2708
- return /* @__PURE__ */ jsxRuntime.jsx(themes.Tabs.Root, { ref, defaultValue: "edit", children: /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { direction: "column", gap: "2", children: [
2709
- /* @__PURE__ */ jsxRuntime.jsxs(themes.Tabs.List, { children: [
2710
- /* @__PURE__ */ jsxRuntime.jsx(themes.Tabs.Trigger, { value: "edit", children: "Edit" }),
2711
- /* @__PURE__ */ jsxRuntime.jsx(themes.Tabs.Trigger, { value: "preview", children: "Preview" })
2712
- ] }),
2713
- /* @__PURE__ */ jsxRuntime.jsxs(themes.Tabs.Content, { value: "edit", children: [
2714
- FormBuilderHeading,
2715
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Text, { children: [
2716
- "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",
2717
- " ",
2718
- /* @__PURE__ */ jsxRuntime.jsx("em", { children: "Preview" }),
2719
- " tab, but",
2720
- " ",
2721
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "field values entered on this page will not be saved." })
2722
- ] }),
2723
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Flex, { asChild: true, direction: "column", gap: "2", mt: "3", children: /* @__PURE__ */ jsxRuntime.jsxs("form", { id: formId, onSubmit: formik$1.handleSubmit, children: [
2724
- /* @__PURE__ */ jsxRuntime.jsxs(formik.FormikProvider, { value: formik$1, children: [
2725
- titleInput,
2726
- descriptionInput,
2727
- /* @__PURE__ */ jsxRuntime.jsx(FieldsEditor, {}),
2728
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Text, { severity: "danger", size: "1", children: typeof formik$1.errors.fields === "string" && formik$1.errors.fields })
2729
- ] }),
2730
- /* @__PURE__ */ jsxRuntime.jsxs(blocks.Flex, { justify: "end", gap: "2", children: [
2731
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Button, { type: "button", variant: "soft", onClick: onCancel, children: "Cancel" }),
2732
- /* @__PURE__ */ jsxRuntime.jsx(blocks.Button, { type: "submit", disabled: !formik$1.isValid, children: "Save" })
2733
- ] })
2734
- ] }) })
2735
- ] }),
2736
- /* @__PURE__ */ jsxRuntime.jsx(themes.Tabs.Content, { value: "preview", children: /* @__PURE__ */ jsxRuntime.jsx(FormRenderer, { schema: previewSchema, onSubmit: previewSubmit }) })
2737
- ] }) });
2738
- })
2739
- );
2740
- exports2.BaseField = BaseField;
2741
- exports2.BaseFormElement = BaseFormElement;
2742
- exports2.BooleanField = BooleanField;
2743
- exports2.BooleanInput = BooleanInput;
2744
- exports2.DateField = DateField;
2745
- exports2.DateInput = DateInput;
2746
- exports2.FieldSection = FieldSection;
2747
- exports2.FormBrowser = FormBrowser;
2748
- exports2.FormBuilder = FormBuilder;
2749
- exports2.FormRenderer = FormRenderer;
2750
- exports2.FormSubmissionBrowser = FormSubmissionBrowser;
2751
- exports2.FormSubmissionViewer = FormSubmissionViewer;
2752
- exports2.InputWithLabel = InputWithLabel;
2753
- exports2.InputWithLabelAndHelpText = InputWithLabelAndHelpText;
2754
- exports2.MultiSelectField = MultiSelectField;
2755
- exports2.MultiSelectInput = MultiSelectInput;
2756
- exports2.MultiStringField = MultiStringField;
2757
- exports2.MultiStringInput = MultiStringInput;
2758
- exports2.NumberField = NumberField;
2759
- exports2.NumberInput = NumberInput$1;
2760
- exports2.PatchField = PatchField;
2761
- exports2.PatchFormProvider = PatchFormProvider;
2762
- exports2.SelectField = SelectField;
2763
- exports2.SelectInput = SelectInput;
2764
- exports2.StringField = StringField;
2765
- exports2.StringInput = StringInput;
2766
- exports2.TextField = TextField;
2767
- exports2.TextInput = TextInput;
2768
- exports2.deserialize = deserialize;
2769
- exports2.deserializeField = deserializeField;
2770
- exports2.formRevisionToSchema = formRevisionToSchema;
2771
- exports2.isConditionMet = isConditionMet;
2772
- exports2.useFieldInput = useFieldInput;
2773
- exports2.useFieldInputs = useFieldInputs;
2774
- exports2.useFormikInput = useFormikInput;
2775
- exports2.valueIsFile = valueIsFile;
2776
- Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
2777
- });
2778
- //# sourceMappingURL=forms.umd.cjs.map
43
+ If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
44
+
45
+ For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return v.useEffect(()=>{t&&(document.getElementById(t)||console.error(e))},[e,t]),null},Oo="DialogDescriptionWarning",Bo=({contentRef:t,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${hr(Oo).contentName}}.`;return v.useEffect(()=>{var a;const i=(a=t.current)==null?void 0:a.getAttribute("aria-describedby");n&&i&&(document.getElementById(n)||console.warn(r))},[r,t,n]),null},$t=tr,zo=rr,kt=or,jt=ar,Wt=sr,pr=ur,tt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},nt={exports:{}},_o=nt.exports,mr;function Vo(){return mr||(mr=1,function(t,n){(function(e,r){r()})(_o,function(){function e(u,f){return typeof f>"u"?f={autoBom:!1}:typeof f!="object"&&(console.warn("Deprecated: Expected third argument to be a object"),f={autoBom:!f}),f.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(u.type)?new Blob(["\uFEFF",u],{type:u.type}):u}function r(u,f,h){var g=new XMLHttpRequest;g.open("GET",u),g.responseType="blob",g.onload=function(){m(g.response,f,h)},g.onerror=function(){console.error("could not download file")},g.send()}function i(u){var f=new XMLHttpRequest;f.open("HEAD",u,!1);try{f.send()}catch{}return 200<=f.status&&299>=f.status}function a(u){try{u.dispatchEvent(new MouseEvent("click"))}catch{var f=document.createEvent("MouseEvents");f.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),u.dispatchEvent(f)}}var s=typeof window=="object"&&window.window===window?window:typeof self=="object"&&self.self===self?self:typeof tt=="object"&&tt.global===tt?tt:void 0,l=s.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),m=s.saveAs||(typeof window!="object"||window!==s?function(){}:"download"in HTMLAnchorElement.prototype&&!l?function(u,f,h){var g=s.URL||s.webkitURL,C=document.createElement("a");f=f||u.name||"download",C.download=f,C.rel="noopener",typeof u=="string"?(C.href=u,C.origin===location.origin?a(C):i(C.href)?r(u,f,h):a(C,C.target="_blank")):(C.href=g.createObjectURL(u),setTimeout(function(){g.revokeObjectURL(C.href)},4e4),setTimeout(function(){a(C)},0))}:"msSaveOrOpenBlob"in navigator?function(u,f,h){if(f=f||u.name||"download",typeof u!="string")navigator.msSaveOrOpenBlob(e(u,h),f);else if(i(u))r(u,f,h);else{var g=document.createElement("a");g.href=u,g.target="_blank",setTimeout(function(){a(g)})}}:function(u,f,h,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),typeof u=="string")return r(u,f,h);var C=u.type==="application/octet-stream",w=/constructor/i.test(s.HTMLElement)||s.safari,p=/CriOS\/[\d]+/.test(navigator.userAgent);if((p||C&&w||l)&&typeof FileReader<"u"){var b=new FileReader;b.onloadend=function(){var y=b.result;y=p?y:y.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=y:location=y,g=null},b.readAsDataURL(u)}else{var I=s.URL||s.webkitURL,x=I.createObjectURL(u);g?g.location=x:location.href=x,g=null,setTimeout(function(){I.revokeObjectURL(x)},4e4)}});s.saveAs=m.saveAs=m,t.exports=m})}(nt)),nt.exports}var qt=Vo();const Ht=c.memo(t=>{const{file:n,onClose:e}=t,r=c.useRef(null),i=c.useCallback(()=>{var l;if(!r.current)return;const s=document.createElement("canvas");s.width=r.current.width,s.height=r.current.height,(l=s.getContext("2d"))==null||l.drawImage(r.current,0,0,r.current.width,r.current.height),s.toBlob(m=>{m&&navigator.clipboard.write([new ClipboardItem({"image/png":m})])},"image/png")},[]),a=c.useCallback(()=>{qt.saveAs(n,n.name)},[n]);return o.jsx($t,{open:!0,onOpenChange:e,children:o.jsx(kt,{children:o.jsx(jt,{className:"bg-(--color-background) fixed inset-0 data-[state='open']:fade-in-0 data-[state='open']:zoom-in-95 data-[state='closed']:animate-out data-[state='closed']:fade-out-0 data-[state='closed']:zoom-out-95 data-[state='open']:animate-in","data-floating-content":"",children:o.jsxs(Wt,{className:"absolute inset-0 py-12","data-floating-content":"",onOpenAutoFocus:s=>s.preventDefault(),children:[o.jsxs(d.ButtonGroup,{className:"flex gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",variant:"ghost",children:[o.jsxs(d.Tooltip.Root,{children:[o.jsx(d.Tooltip.Trigger,{asChild:!0,children:o.jsx(d.IconButton,{onClick:i,"aria-label":"copy to clipboard",children:o.jsx(d.RiIcon,{icon:"RiFileCopyLine"})})}),o.jsx(d.Tooltip.Content,{size:"sm",children:"Copy"})]}),o.jsxs(d.Tooltip.Root,{children:[o.jsx(d.Tooltip.Trigger,{asChild:!0,children:o.jsx(d.IconButton,{onClick:a,"aria-label":"download",children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})})}),o.jsx(d.Tooltip.Content,{size:"sm",children:"Download"})]}),o.jsx(d.Separator,{orientation:"vertical",size:"sm"}),o.jsx(pr,{asChild:!0,children:o.jsx(d.IconButton,{onClick:e,"aria-label":"close",children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})})]}),o.jsx("figure",{className:"size-full overflow-hidden p-4 flex justify-center items-center",children:o.jsx("img",{ref:r,className:"max-w-full max-h-full",src:URL.createObjectURL(n),alt:n.name})})]})})})})});Ht.displayName="ImageViewer";const gr=c.memo(t=>{const{children:n}=t,[e,r]=c.useState(null),i=c.useCallback(()=>{r(null)},[]),a=c.useCallback(m=>{r(m(i))},[i]),s=c.useCallback(()=>{e&&(e.onClose&&e.onClose(),i())},[i,e]),l=c.useMemo(()=>a,[a]);return o.jsxs(En.Provider,{value:l,children:[n,e&&o.jsx(Ht,{file:e.file,onClose:s})]})});gr.displayName="FileViewerProvider";const Y=t=>{const{className:n,label:e,children:r,severity:i,inputId:a,labelId:s,image:l}=t,[m,u]=c.useState(void 0),f=We(),h=i?ue[i]:"base";c.useEffect(()=>{l instanceof Promise?l.then(u).catch(console.error):u(l)},[l]);const g=m?URL.createObjectURL(m):void 0,C=c.useCallback(()=>{m&&f(()=>({file:m}))},[f,m]);return o.jsxs("div",{className:"flex flex-col gap-1",children:[m&&o.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:g,alt:m.name,onClick:C}),o.jsx("label",{className:ye(n,"flex flex-col gap-1 w-max max-w-full"),htmlFor:a,children:o.jsx(d.Text,{accentColor:h,size:"sm",id:s,weight:"medium",className:"text-wrap",children:e})}),r]})},Gt=t=>{const{helpText:n,children:e,severity:r}=t,i=r?ue[r]:"base";return o.jsxs("div",{className:"flex flex-col gap-1",children:[e,!!n&&o.jsx("div",{className:"flex flex-col w-full",children:o.jsx(d.Text,{accentColor:i,size:"xs",children:n})})]})},J=t=>{const{children:n,...e}=t;return o.jsx(Gt,{...e,children:n})},Xt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onBlur:g,onChange:C,value:w}=u,p=a?null:l,b=a?"":m,I=c.useCallback(y=>{C(!!y),g(!!y)},[g,C]),x=c.useCallback(()=>{g(w)},[g,w]);return o.jsx(J,{helpText:p,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:a?void 0:s.image,className:"items-center flex-row-reverse justify-end gap-2",children:o.jsx(d.Checkbox.Root,{id:n,name:h,checked:w??!1,onCheckedChange:I,onBlur:x,size:"sm",accentColor:"primary",variant:"surface",...f,children:o.jsx(d.Checkbox.Indicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})})})})})});Xt.displayName="BooleanInput";const vr={...X,type:"boolean"},Se=class Se extends j{constructor(e){super({...e,type:"boolean"});N(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new Se(e)}getInput(e){return o.jsx(Xt,{...e,field:this})}};N(Se,"fieldTypeName","Checkbox"),N(Se,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),N(Se,"Icon",H.RiCheckboxCircleLine);let Ee=Se;const Kt=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C}=u,[w,p]=c.useState(!1),b=a?null:l,I=a?"":m,x=u.value?new Date(u.value):void 0,y=c.useCallback(S=>{S&&g(S.toISOString()),p(!1)},[g]),T=c.useCallback(S=>{p(S),S||C(u.value)},[u.value,C]);return o.jsx(J,{helpText:b,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:I,image:a?void 0:s.image,children:o.jsxs(d.Popover.Root,{open:w,onOpenChange:T,children:[o.jsx(d.Popover.Trigger,{asChild:!0,children:o.jsxs(d.Button,{id:n,name:h,type:"button",className:"!justify-between",accentColor:"base",variant:"surface",size:"sm",...f,children:[x?x.toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit"}):"yyyy-mm-dd",o.jsx(d.RiIcon,{icon:"RiArrowDownSLine"})]})}),o.jsx(d.Popover.Content,{align:"start",children:o.jsx(d.DayPicker,{required:!1,mode:"single",variant:"solid",selected:x,onSelect:y})})]})})})});Kt.displayName="DateInput";const yr={...X,type:"date"},Te=class Te extends j{constructor(e){super({...e,type:"date"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new Te(e)}getInput(e){return o.jsx(Kt,{field:this,...e})}};N(Te,"fieldTypeName","Date"),N(Te,"fieldTypeDescription","Allows specifying a date."),N(Te,"Icon",H.RiCalendarLine);let rt=Te;const br=c.memo(t=>{const{field:n,...e}=t,[{value:r}]=k.useField(n.options.clonedFieldIdentifier),i=c.useMemo(()=>{const a=n.options.getFieldToClone(r);return a?pt(a):null},[n.options,r]);return Qt(i,e)});br.displayName="FieldInputCloner";const Uo={...X,type:"custom"};class it extends j{constructor(e,r){super({...e,type:"custom"});N(this,"Component");N(this,"options");this.options=e,this.Component=r}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const r=this.Component;return o.jsx(r,{field:this,...e})}}N(it,"fieldTypeName","Custom"),N(it,"fieldTypeDescription","Allows re-rendering of field already in the form");class $o extends it{constructor(n){super(n,br)}}const Qt=(t,n)=>c.useMemo(()=>!n||!t?null:t.getInput(n),[t,n]),ze=(t,n)=>{const e=c.useMemo(()=>t.map(r=>o.jsx(c.Fragment,{children:r.getInput(n)},r.getId())),[t,n]);return o.jsx("div",{className:"flex flex-col gap-4",children:e})},Yt=[];let ot;const ko=new Uint8Array(16);function jo(){if(!ot&&(ot=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ot))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ot(ko)}const V=[];for(let t=0;t<256;++t)V.push((t+256).toString(16).slice(1));function Wo(t,n=0){return V[t[n+0]]+V[t[n+1]]+V[t[n+2]]+V[t[n+3]]+"-"+V[t[n+4]]+V[t[n+5]]+"-"+V[t[n+6]]+V[t[n+7]]+"-"+V[t[n+8]]+V[t[n+9]]+"-"+V[t[n+10]]+V[t[n+11]]+V[t[n+12]]+V[t[n+13]]+V[t[n+14]]+V[t[n+15]]}const Cr={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function qo(t,n,e){if(Cr.randomUUID&&!t)return Cr.randomUUID();t=t||{};const r=t.random||(t.rng||jo)();return r[6]=r[6]&15|64,r[8]=r[8]&63|128,Wo(r)}const me=t=>t.type==="section",at=(t="",n=[])=>({type:"section",fields:n,identifier:t,label:null,condition:null,conditional:!1}),Ho=t=>{if(!t)return;const n=t.fields;let e=[];const r=[];for(const i of n)i.type==="section"?(e.length>0&&(r.push(at(`AUTO_section-${n.indexOf(i)}`,e)),e=[]),r.push(i)):e.push(i);return e.length>0&&r.push(at("AUTO_section-last",e)),{...t,fields:r,description:t.description??""}};function Jt(t,n,e){const r=Array.from(t),[i]=r.splice(n,1);if(!i)throw new Error("Could not find field to reorder.");return r.splice(e,0,i),r}function wr(t,n,e){const r=Array.from(t??[]);return r.splice(n,0,e),r}function st(t,n){const e=Array.from(t);return e.splice(n,1),e}const Zt=()=>qo(),Ir=(t,n)=>{if(!n)return null;for(const e of t)if(e.type==="section"){const r=Ir(e.fields,n);if(r)return r}else if(e.identifier===n)return e;return null},xr=(t,n)=>t.filter((e,r)=>r<n).flatMap(e=>e.fields),lt=(t,n,e,r,i)=>{const a={...e,identifier:Zt()},s=R(r,t);if(s===void 0)throw new Error("Parent path must point to an existing field.");if(!Array.isArray(s))throw new Error("Parent path must point to an array.");const l=wr(s,n,a);i(t,l).then()},Go=(t,n,e)=>{const r={...at(),label:""};lt("fields",t,r,n,e)},Rt=()=>{const{showError:t}=d.useToast(),n=c.useCallback((r,i,a,s,l,m)=>{const u=r[i];if(!u)throw new Error("Could not find section context.");let f=typeof u.conditionIndex<"u"?Math.max(u.conditionIndex+1,s):s;for(const h of Object.values(r))h.conditionIndex===a&&(f=Math.min(f,h.index-1));if(f!==s){t({title:"Could not reorder sections",description:"Sections with conditions must be below the fields they reference."});return}m("fields",Jt(l.fields,a,f))},[t]),e=c.useCallback((r,i,a,s,l,m,u)=>{var f;if(!(r!=null&&r.fields)||!s)throw new Error("Could not find section with fields.");if(r.identifier===s.identifier)u(`fields.${i}.fields`,Jt(r.fields,a,m)).then();else{const h=r.fields[a];if(!h)throw new Error("Could not find field to reorder.");if(((f=s.condition)==null?void 0:f.identifier)===h.identifier){t({title:"Could not reorder field",description:"Field must be above the section whose condition references it."});return}u(`fields.${i}.fields`,st(r.fields,a)).then(),u(`fields.${l}.fields`,wr(s.fields,m,h)).then()}},[t]);return{reorderSection:n,reorderField:e}},en=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),h=a?null:l,g=a?"":m,{name:C,onChange:w,onBlur:p}=u,b=`${n}-droppable`,{disabled:I}=f,x=u.value??Yt,[y,T]=c.useState(""),[S,L]=c.useState(""),F=S||h,D=c.useCallback(A=>{w(A),p(A)},[w,p]),M=c.useCallback(A=>{x&&x.findIndex(q=>q===A.target.value.trim())>=0?L("All options must be unique"):A.target.value?L(""):L("Option cannot be empty"),T(A.target.value)},[T,x]),O=c.useCallback(()=>{if(S)return;if(!y.trim()){L("Option cannot be empty");return}const A=y.trim();D([...x,A]),T("")},[y,S,D,x]),_=c.useCallback(A=>{A.key==="Enter"&&(A.preventDefault(),O())},[O]),U=c.useCallback(A=>{D(st(x,A))},[x,D]),B=c.useCallback(A=>{if(!A.destination)return;const q=A.source.index,le=A.destination.index;D(Jt(x,q,le))},[D,x]),Z=c.useCallback(()=>{p(x)},[p,x]);return o.jsx(ie.DragDropContext,{onDragEnd:B,children:o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx(J,{helpText:F,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:g,image:a?void 0:s.image,children:(!I||x.length===0)&&o.jsxs("div",{className:"flex gap-2",children:[o.jsx(d.Input.Root,{className:"grow",accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{value:y,onChange:M,onKeyDown:_,id:n,placeholder:s.placeholder,onBlur:Z,name:C,...f})}),o.jsx(d.IconButton,{size:"sm",accentColor:"base",variant:"soft",type:"button","aria-label":"Add option",disabled:!!S||I,onClick:O,children:o.jsx(d.RiIcon,{icon:"RiAddLine"})})]})})}),o.jsx(ie.Droppable,{droppableId:b,children:A=>o.jsxs("div",{className:"flex flex-col",...A.droppableProps,ref:A.innerRef,children:[x.map((q,le)=>o.jsx(ie.Draggable,{draggableId:`${q}-draggable`,index:le,isDragDisabled:I,children:({draggableProps:ne,dragHandleProps:ce,innerRef:Be})=>o.jsxs(d.Badge,{...ce,...ne,ref:Be,className:"mb-1 flex items-center justify-between gap-2",accentColor:"base",size:"sm",variant:"soft",children:[o.jsx("span",{children:typeof q=="object"&&"label"in q?q.label:q}),o.jsx(d.IconButton,{size:"xs",variant:"ghost",type:"button","aria-label":"Delete option",accentColor:"base",disabled:I,onClick:()=>{U(le)},children:o.jsx(d.RiIcon,{icon:"RiCloseLargeLine"})})]})},q)),A.placeholder]})})]})})});en.displayName="MultiStringInput";const Er={...X,type:"multi-string",minimum_length:0,maximum_length:null},Ne=class Ne extends j{constructor(e){const{minimum_length:r,maximum_length:i,placeholder:a,...s}=e;super({...s,type:"multi-string"});N(this,"minLength");N(this,"maxLength");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.minLength=r??0,this.maxLength=i??1/0,this.placeholder=a??"Press enter to add a new option"}getInput(e){return o.jsx(en,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}isBlank(e){return super.isBlank(e)||(e==null?void 0:e.length)===0}isEqual(e,r){return e===void 0&&r===void 0?!0:e===void 0||r===void 0?!1:e.every(i=>r.includes(i))&&r.every(i=>e.includes(i))}getFieldValidators(){const e=super.getFieldValidators();return e.push(r=>{if(Array.isArray(r)&&r.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(r=>{if(Array.isArray(r)&&r.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new Ne(e)}};N(Ne,"fieldTypeName","Multi-string"),N(Ne,"fieldTypeDescription","Allows the user to provide multiple unique strings."),N(Ne,"Icon",H.RiListCheck);let _e=Ne;const tn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useLayoutEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{const D=F.target.valueAsNumber,M=Number.isNaN(D)?void 0:D;T(M),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(M))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{id:n,name:C,onChange:S,onBlur:L,value:y,type:"number",min:s.minimum,max:s.maximum,step:s.integers?1:.1,placeholder:s.placeholder,...g})})})})});tn.displayName="NumberInput";const Sr={...X,type:"number",minimum:Number.MIN_SAFE_INTEGER,maximum:Number.MAX_SAFE_INTEGER,integers:!1},Tr=t=>"fields"in t,te=class te extends j{constructor(e){const{minimum:r=Number.MIN_SAFE_INTEGER,maximum:i=Number.MAX_SAFE_INTEGER,integers:a=!1,placeholder:s="Enter a number",...l}=e;super({...l,type:"number"});N(this,"minimum");N(this,"maximum");N(this,"integers");N(this,"placeholder");this.minimum=r,this.maximum=i,this.integers=a,this.placeholder=s}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new te({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:`${r}minimum`,formValidators:[this._validateMin(e)]}),showDirectly:!1},{field:new te({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:`${r}maximum`,formValidators:[this._validateMax(e)]}),showDirectly:!1},{field:new Ee({label:"Integers",description:"Whole numbers only",required:!1,identifier:`${r}integers`}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.minimum,i=this.maximum;return typeof r=="number"&&e.push(a=>{if(typeof a=="number"&&a<r)return`Must be at least ${this.minimum}.`}),typeof i=="number"&&e.push(a=>{if(typeof a=="number"&&a>i)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(a=>{if(typeof a=="number"&&!Number.isInteger(a))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers,placeholder:this.placeholder}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new te(e)}getInput(e){return o.jsx(tn,{field:this,...e})}};N(te,"fieldTypeName","Number"),N(te,"fieldTypeDescription","Allows specifying a number within a given range."),N(te,"Icon",H.RiHashtag),N(te,"_validateMin",e=>(r,i)=>{const a=Tr(i)?R(i,e):i;return typeof a.maximum=="number"&&typeof r=="number"&&a.maximum<r?"Minimum cannot be greater than minimum.":null}),N(te,"_validateMax",e=>(r,i)=>{const a=Tr(i)?R(i,e):i;return typeof a.minimum=="number"&&typeof r=="number"&&a.minimum>r?"Maximum cannot be less than minimum.":null});let se=te;const nn=c.memo(t=>{const[{inputId:n,labelId:e,label:r,helpText:i,size:a,severity:s,showInputOnly:l,field:m,fieldProps:u},f]=K(t),{name:h,onBlur:g,onChange:C,value:w}=u,[p,b]=c.useState(!1),I=l?null:i,x=l?"":r,y=c.useCallback(L=>{C(L),b(!1)},[C]),T=c.useCallback(()=>{C("")},[C]),S=c.useCallback(L=>{b(L),L||g(w)},[g,w]);return o.jsx(J,{helpText:I,severity:s,children:o.jsxs(Y,{size:a,severity:s,inputId:n,labelId:e,label:x,image:l?void 0:m.image,className:"flex-col items-start justify-start gap-2",children:[o.jsxs("div",{className:"flex w-max items-center gap-1",children:[o.jsxs($t,{open:p,onOpenChange:S,children:[o.jsx(zo,{asChild:!0,children:o.jsxs(d.Button,{id:n,name:h,type:"button",variant:"soft",size:"sm",accentColor:"base",...f,children:[o.jsx(d.RiIcon,{icon:"RiQrCodeLine"}),"Scan"]})}),o.jsxs(kt,{children:[o.jsx(jt,{className:"light:bg-(--black-a6) fixed inset-0 dark:bg-(--black-a8)"}),o.jsx(Wt,{className:"fixed inset-0",children:o.jsx(rn,{onQrScan:y})})]})]}),w&&o.jsx(d.RiIcon,{icon:"RiCheckLine",className:"align-bottom text-(--primary-a11)"})]}),!!w&&o.jsx(d.Card,{className:"max-w-full w-max",size:"sm",children:o.jsxs("div",{className:"max-w-full w-max flex justify-between gap-2",children:[o.jsx("code",{className:"bg-(--base-a3) truncate text-sm",children:w}),o.jsx(d.IconButton,{accentColor:"base",variant:"ghost","aria-label":"delete",size:"sm",onClick:T,children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})]})})]})})});nn.displayName="QrInput";const rn=c.memo(t=>{const{onQrScan:n}=t,e=c.useRef(null),[r,i]=c.useState(!1);return c.useEffect(()=>{if(!e.current)return;const a=new ei(e.current,s=>{const l=s.data;n(l),a.destroy()},{highlightCodeOutline:!0,highlightScanRegion:!0,maxScansPerSecond:1});i(!0),a.start().finally(()=>{i(!1)})},[n]),o.jsxs("div",{className:"relative flex h-full w-full flex-col justify-center gap-2 bg-(--color-background)",children:[o.jsx("div",{className:"absolute top-0 flex w-full p-2",children:o.jsx(pr,{asChild:!0,children:o.jsx(d.IconButton,{"aria-label":"close",variant:"soft",accentColor:"base",children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})})})}),o.jsxs("div",{className:"relative max-h-full max-w-full",children:[o.jsx("video",{className:"size-full",ref:e}),r&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-(--color-background)",children:o.jsx(d.Spinner,{})})]})]})});rn.displayName="QrScanner";const Nr={...X,type:"qr"},Fe=class Fe extends j{constructor(e){super({...e,type:"qr"});N(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="qr")throw new Error("Type mismatch.");return new Fe(e)}getInput(e){return o.jsx(nn,{...e,field:this})}};N(Fe,"fieldTypeName","QR"),N(Fe,"fieldTypeDescription","Used for scanning/reading QR codes."),N(Fe,"Icon",H.RiQrCodeLine);let ct=Fe;class Fr extends j{constructor(e){const{placeholder:r="",...i}=e;super(i);N(this,"options");N(this,"onlyValidateAfterTouched",!1);N(this,"placeholder");this.placeholder=r;const a=new Set;this.options=e.options.map(s=>(typeof s=="string"&&(s={label:s,value:s}),a.add(s.label),s)),a.size!==e.options.length&&console.error(`${e.options.length-a.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options,placeholder:this.placeholder}}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new _e({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:`${r}options`,minimum_length:2}),showDirectly:!0}]}}const on=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C}=u,w=a?null:l,p=a?"":m,b=u.value??Yt,I=c.useCallback(y=>{const T=y.length>0?y:void 0;g(T),C(T)},[C,g]),x=c.useCallback(y=>{y||C(b)},[b,C]);return o.jsx(J,{helpText:w,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:p,image:a?void 0:s.image,children:o.jsxs(d.Menu.Root,{onOpenChange:x,align:"start",children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{id:n,name:h,className:"!justify-between",variant:"surface",type:"button",size:"sm",accentColor:"base",...f,children:[o.jsx("span",{className:"truncate",children:b&&b.length>0?b.join(", "):s.placeholder}),o.jsx(d.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),o.jsx(d.Menu.Content,{children:o.jsx(d.Menu.Scroll,{children:o.jsxs(d.Menu.MultiSelectGroup,{values:b,onValuesChange:I,children:[o.jsxs(d.Menu.SelectAllItem,{children:[o.jsx(d.Menu.CheckboxItemIndicator,{children:y=>y?o.jsx(d.RiIcon,{icon:"RiSubtractLine"}):o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),"Select all"]}),s.options.map(y=>o.jsxs(d.Menu.MultiSelectItem,{value:y.value,children:[o.jsx(d.Menu.SelectedIndicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))]})})})]})})})});on.displayName="MultiSelectInput";const Lr={...X,type:"multi-select",options:[]},Le=class Le extends Fr{constructor(n){const{placeholder:e="Select one or more...",...r}=n;super({...r,placeholder:e,type:"multi-select"})}isBlank(n){return super.isBlank(n)||(n==null?void 0:n.length)===0}isEqual(n,e){return n===void 0&&e===void 0?!0:n===void 0||e===void 0?!1:n.every(r=>e.includes(r))&&e.every(r=>n.includes(r))}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new Le(n)}getInput(n){return o.jsx(on,{field:this,...n})}};N(Le,"fieldTypeName","Multi-select"),N(Le,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),N(Le,"Icon",H.RiCheckboxLine);let Ve=Le;const an=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u},f]=K(t),{name:h,onChange:g,onBlur:C,value:w}=u,p=a?null:l,b=a?"":m,I=c.useCallback(y=>{y&&(g(y),C(y))},[C,g]),x=c.useMemo(()=>s.options.find(y=>y.value===w),[s.options,w]);return o.jsx(J,{helpText:p,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:b,image:a?void 0:s.image,children:o.jsxs(d.Menu.Root,{align:"start",children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{id:n,name:h,className:"!justify-between",accentColor:"base",variant:"surface",type:"button",size:"sm",...f,children:[o.jsx("span",{className:"truncate",children:x?x.label:s.placeholder}),o.jsx(d.RiIcon,{className:"shrink-0",icon:"RiArrowDownSLine"})]})}),o.jsx(d.Menu.Content,{children:o.jsx(d.Menu.Scroll,{children:o.jsx(d.Menu.SelectGroup,{required:!0,value:w,onValueChange:I,children:s.options.map(y=>o.jsxs(d.Menu.SelectItem,{value:y.value,children:[o.jsx(d.Menu.SelectedIndicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})}),y.label]},y.value))})})})]})})})});an.displayName="SelectInput";const Dr={...X,type:"select",options:[]},De=class De extends Fr{constructor(n){const{placeholder:e="Select one...",...r}=n;super({...r,placeholder:e,type:"select"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new De(n)}getInput(n){return o.jsx(an,{field:this,...n})}};N(De,"fieldTypeName","Dropdown"),N(De,"fieldTypeDescription","Allows the user to select a single option from a list of options."),N(De,"Icon",H.RiMenuFoldLine);let Ue=De;const Mr=t=>"fields"in t;class dt extends j{constructor(e){const{minLength:r,maxLength:i,placeholder:a="",...s}=e;super(s);N(this,"minLength");N(this,"maxLength");N(this,"placeholder");this.minLength=r?Math.max(r,0):void 0,this.maxLength=i?Math.max(i,0):be,this.placeholder=a}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:`${r}minimum_length`,minimum:0,maximum:100,formValidators:[this._validateMin(e)],integers:!0}),showDirectly:!1},{field:new se({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:`${r}maximum_length`,minimum:1,maximum:be,formValidators:[this._validateMax(e)],integers:!0}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(r=>{if(this.minLength&&(!r||r.length<this.minLength))return!this.required&&!r?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(r=>{if(typeof r=="string"&&this.maxLength&&r.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength,placeholder:this.placeholder}}}N(dt,"_validateMin",e=>(r,i)=>{const a=Mr(i)?R(i,e):i;return typeof a.maximum_length=="number"&&typeof r=="number"&&a.maximum_length<r?"Minimum cannot be greater than maximum.":null}),N(dt,"_validateMax",e=>(r,i)=>{if(typeof r!="number")return null;const{minimum_length:a}=Mr(i)?R(i,e):i;return typeof a!="number"?null:a>r?"Maximum cannot be less than minimum.":null});const sn=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useLayoutEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{T(F.target.value||void 0),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.Input.Root,{accentColor:"base",variant:"surface",size:"sm",children:o.jsx(d.Input.Field,{id:n,className:"truncate",name:C,value:y??"",type:s.inputType,placeholder:s.placeholder,onChange:S,onBlur:L,...g})})})})});sn.displayName="StringInput";const Pr={...X,type:"string",maximum_length:je,input_type:"text"},Me=class Me extends dt{constructor(e){const{inputType:r="text",...i}=e,a=e.maxLength?Math.min(je,e.maxLength):je,s=e.minLength?Math.min(e.minLength,a):void 0;super({...i,maxLength:a,minLength:s,type:"string"});N(this,"inputType");this.inputType=r}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:r,minimum_length:i,input_type:a,...s}=e;return new Me({...s,maxLength:r,minLength:i,inputType:a,placeholder:"Enter a short description"})}getInput(e){return o.jsx(sn,{field:this,...e})}};N(Me,"fieldTypeName","Short Text"),N(Me,"fieldTypeDescription",`Short text fields can hold up to ${je} characters on a single line.`),N(Me,"Icon",H.RiInputField);let ut=Me;const ln=c.memo(t=>{const[{inputId:n,labelId:e,size:r,severity:i,showInputOnly:a,field:s,helpText:l,label:m,fieldProps:u,touched:f,helpers:h},g]=K(t),{name:C,onBlur:w,onChange:p,value:b}=u,I=a?null:l,x=a?"":m,[y,T]=c.useState(void 0);c.useLayoutEffect(()=>{T(b)},[b]);const S=c.useCallback(F=>{T(F.target.value||void 0),(f||!s.onlyValidateAfterTouched)&&h.setError(s.getError(F.target.value))},[s,h,f]),L=c.useCallback(()=>{p(y),w(y)},[y,w,p]);return o.jsx(J,{helpText:I,severity:i,children:o.jsx(Y,{size:r,severity:i,inputId:n,labelId:e,label:x,image:a?void 0:s.image,children:o.jsx(d.TextArea,{id:n,value:y??"",name:C,onChange:S,onBlur:L,className:"field-sizing-content min-h-12",placeholder:s.placeholder,resize:"vertical",accentColor:"base",variant:"surface",size:"sm",...g})})})});ln.displayName="TextInput";const Ar={...X,type:"text",maximum_length:be},Pe=class Pe extends dt{constructor(n){const e=n.maxLength?Math.min(be,n.maxLength):be,r=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:r,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:r,...i}=n;return new Pe({...i,maxLength:e,minLength:r,placeholder:"Enter a description"})}getInput(n){return o.jsx(ln,{field:this,...n})}};N(Pe,"fieldTypeName","Paragraph"),N(Pe,"fieldTypeDescription",`Paragraph fields can hold up to ${be} characters and can have multiple lines.`),N(Pe,"Icon",H.RiAlignJustify);let ft=Pe;const Or=c.memo(c.forwardRef((t,n)=>{const{file:e,alt:r,error:i,rightSlot:a,className:s,...l}=t;return o.jsxs("div",{className:ye(s,"relative flex h-[200px] w-full flex-col gap-0 overflow-hidden rounded-md border items-center border-(--base-a6)"),ref:n,...l,children:[!e&&!i&&o.jsx("div",{className:"absolute flex h-full w-full flex-col items-center justify-center",children:o.jsx(d.Spinner,{})}),o.jsx("div",{className:"-m-4 flex max-w-full grow items-center justify-center overflow-hidden bg-clip-padding",children:e&&!i&&o.jsx("img",{className:"max-w-full object-cover",src:URL.createObjectURL(e),alt:r??e.name})}),o.jsxs("div",{className:ye("flex h-max w-full items-center gap-1 bg-(--base-2) px-2 py-1",{"bg-transparent":!e}),children:[i?o.jsx(d.RiIcon,{icon:"RiFileWarningLine"}):e&&o.jsx(ke,{fileType:e.type}),o.jsx(d.Text,{className:"truncate",size:"sm",children:i??(e==null?void 0:e.name)}),a]})]})})),Xo=t=>{const n=["byte","kilobyte","megabyte"];let e=t,r=0;for(;e>1e3&&r<n.length-1;)e/=1e3,r++;return new Intl.NumberFormat([],{maximumFractionDigits:Math.max(0,r-1),style:"unit",unit:n[r]}).format(e)},Br=c.memo(t=>{var F;const[{inputId:n,labelId:e,size:r,severity:i,helpText:a,showInputOnly:s,field:l,fieldProps:m},u]=K(t),{name:f,onChange:h,onBlur:g}=m;let[{label:C}]=K(t);C=s?"":C;const w=m.value??Yt,p=c.useRef(null),b=c.useMemo(()=>s?null:a||(l.maxFileSize?`Maximum file size: ${l.maxFileSize}MB`:null),[l.maxFileSize,a,s]),I=c.useCallback(()=>{var D;(D=p.current)==null||D.click()},[]),x=c.useCallback(()=>{if(!p.current)return;const D=p.current.files;if(!D){g([]);return}const M=Array.from(D),O=[...w,...M];h(O),g(O)},[g,h,w]),y=c.useCallback(D=>{const M=[...w];M.splice(D,1),h(M.length>0?M:void 0)},[w,h]);c.useEffect(()=>{if(!p.current)return;const D=new AbortController;return p.current.addEventListener("cancel",()=>{g(void 0)},{signal:D.signal}),()=>{D.abort()}},[g,w]);const T=w?"Select new files":"Select files",S=w?"Select new file":"Select a file",L=l.maxFiles>1?T:S;return o.jsxs("div",{className:"flex flex-col gap-2",children:[o.jsx(J,{helpText:b,severity:i,children:o.jsxs(Y,{size:r,severity:i,inputId:n,labelId:e,label:C,image:s?void 0:l.image,children:[o.jsx("div",{className:"flex gap-2",children:o.jsxs(d.Button,{className:"w-max",size:"sm",variant:"soft",accentColor:"base",onClick:I,id:"upload-input-upload-button",type:"button",...u,children:[o.jsx(d.RiIcon,{icon:"RiUpload2Line"})," ",L]})}),o.jsx("input",{id:n,name:f,type:"file",ref:p,accept:(F=l.extensions)==null?void 0:F.join(","),multiple:l.maxFiles>1,className:"hidden",onChange:x,value:""})]})}),Array.isArray(w)&&w.length>0&&o.jsx("div",{className:"flex h-max flex-col gap-2",children:w.map((D,M)=>o.jsx(zr,{field:l,file:D,onRemove:()=>{y(M)},disabled:u.disabled},M))})]})});Br.displayName="UploadInput";const zr=c.memo(t=>{const{file:n,field:e,onRemove:r,disabled:i}=t,[a,s]=c.useState(null),l=We(),m=c.useMemo(()=>a&&e.getError([a]),[e,a]),{url:u,name:f}=c.useMemo(()=>{let p=null,b,I;return a!=null&&a.type.startsWith("image/")&&(p=URL.createObjectURL(a)),a?(b=a.name,I=Xo(a.size)):(b="Downloading...",I="..."),{url:p,name:b,size:I}},[a]);c.useEffect(()=>{n instanceof Promise?n.then(s).catch(console.error):s(n)},[n]);const h=c.useCallback(p=>{if(p.stopPropagation(),!a)throw new Error("Cannot download a file that is not resolved.");const b=new Blob([a]);qt.saveAs(b,f)},[f,a]),g=c.useCallback(p=>{p.stopPropagation(),r()},[r]),C=c.useCallback(()=>{a&&l(p=>({file:a,onDelete:i?void 0:()=>{r(),p()}}))},[i,r,l,a]),w=c.useMemo(()=>o.jsxs(d.ButtonGroup,{className:"flex grow justify-end",variant:"ghost",accentColor:"base",size:"sm",children:[o.jsx(d.IconButton,{"aria-label":`Download ${f}`,type:"button",onClick:h,disabled:!a,children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})}),!i&&o.jsx(d.IconButton,{type:"button","aria-label":`Remove ${f}`,disabled:i,onClick:g,children:o.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),[i,g,h,f,a]);return u?o.jsx(Or,{className:"cursor-pointer",onClick:C,file:a,error:m??void 0,rightSlot:w}):o.jsx(It,{file:a,error:m??void 0,rightSlot:w})});zr.displayName="DisplayFile";const Ko={...X,type:"upload",extensions:[],maximum_size:void 0,maximum_files:1};function _r(t,n){return t.name===n.name&&t.size===n.size&&t.type===n.type}const Ae=class Ae extends j{constructor(e){const{extensions:r,maximum_files:i,maximum_size:a,...s}=e;super({...s,type:"upload"});N(this,"extensions");N(this,"maxFileSize");N(this,"maxFiles");N(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof a=="number"?a:void 0,this.maxFiles=Math.max(typeof i=="number"?i:1,1),this.extensions=r}isBlank(e){return super.isBlank(e)||(e==null?void 0:e.length)===0}isEqual(e,r){return e===void 0&&r===void 0?!0:!(e===void 0||r===void 0||!e.every(i=>r.some(a=>_r(i,a)))||!r.every(i=>e.some(a=>_r(a,i))))}static getFieldCreationSchema(e=""){const r=e&&`${e}.`;return[{field:new se({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:`${r}maximum_files`,integers:!0}),showDirectly:!1},{field:new se({label:"What is the maximum size of each file?",description:`Maximum file size in megabytes (between 1MB–${ht}MB).`,required:!1,identifier:`${r}maximum_size`,minimum:1,maximum:ht,integers:!0}),showDirectly:!1},{field:new Ve({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:`${r}extensions`,options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]}),showDirectly:!1}]}getFieldValidators(){const e=super.getFieldValidators(),r=this.maxFileSize??ht,i=r*1e3*1e3,a=this.maxFiles||1;return e.push(s=>{if(s&&s.some(l=>l.size>i))return`Files must be at most ${r}MB.`}),e.push(s=>{if(s&&s.length>a)return`You can only upload ${a} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new Ae(e)}getInput(e){return o.jsx(Br,{field:this,...e})}};N(Ae,"fieldTypeName","Upload"),N(Ae,"fieldTypeDescription","Allows a file to be uploaded."),N(Ae,"Icon",H.RiUpload2Line);let cn=Ae;const dn={date:rt,number:se,boolean:Ee,select:Ue,string:ut,text:ft,custom:it,upload:cn,qr:ct,"multi-string":_e,"multi-select":Ve},Qo={date:yr,number:Sr,boolean:vr,select:Dr,string:Pr,text:Ar,custom:Uo,upload:Ko,qr:Nr,"multi-string":Er,"multi-select":Lr},ht=50,Yo=ht*1e3*1e3,un=t=>{const n=t.type;return dn[n].deserialize(t)},pt=t=>t.type==="section"?W.deserialize(t):un(t);function Vr(t,n={}){const{readonly:e=!1}=n;return{title:t.title,description:t.description,fields:t.fields.map(r=>pt(r)),meta:{readonly:e}}}function mt(t){const n=[];for(const e of t.fields)if(e instanceof W)for(const r of e.fields)n.push(r);else{if(!(e instanceof j))throw new Error(`Invalid field type: ${e.type}`);n.push(e)}return n}function Ur(t){const n=mt(t),e={};for(const r of n)e[r.identifier]=r;return e}function Jo(t,n){const e=mt(t),r={};for(const i of e){const a=n[i.identifier]??null;a!==null?r[i.identifier]=i.decodeJsonToValue(a):r[i.identifier]=a}return r}function Zo(t,n){const e=mt(t),r={};for(const i of e){const a=n[i.identifier];r[i.identifier]=i.encodeValueToJson(a)}return r}function gt(t){return Array.isArray(t)&&t.some(n=>n instanceof File||n instanceof Promise)}function fn(t,n){if(!t)return!0;if(gt(n)||gt(t.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(i=>typeof i=="string"?i:i.value):n,r=Array.isArray(t.value)?t.value.map(i=>typeof i=="string"?i:i.value):t.value;if(Array.isArray(r)&&Array.isArray(e)){for(const i of r)if(!e.includes(i))return!1;return!0}return r===n}const $r=c.memo(t=>{const{field:n,...e}=t,{label:r,description:i,fields:a,condition:s}=n,{values:l,setFieldValue:m}=k.useFormikContext(),u=s!=null&&s.identifier?R(l,s.identifier):void 0,f=c.useMemo(()=>u===void 0||fn(s,u),[s,u]);c.useEffect(()=>{if(!f)for(const g of a)m(g.getId(),"").then()},[f,a,m]);const h=ze(a,e);return f?o.jsx(d.Card,{variant:"soft",children:o.jsxs("div",{className:"flex flex-col gap-4",children:[(r||i)&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex flex-col",children:[o.jsx(d.Heading,{size:"md",children:r}),o.jsx(d.Text,{accentColor:"base",children:i})]}),o.jsx(d.Separator,{size:"full"})]}),h]})}):null});$r.displayName="FieldSectionLayout";const Oe=class Oe extends xt{constructor(e){const{label:r=null,fields:i,condition:a=null,conditional:s,...l}=e;super({...l,type:"section"});N(this,"label");N(this,"fields");N(this,"condition");this.fields=i,this.condition=a,this.label=r,s===!1&&(this.condition=null)}static getFieldCreationSchema(e,r=""){if(e.length===0)return[];const i=r&&`${r}.`;return[{field:new Ee({label:"Conditionally render section",identifier:`${i}conditional`,required:!1}),showDirectly:!0},{field:new Oe({label:"Conditional settings",identifier:`${i}conditional-settings`,condition:{identifier:`${i}conditional`,value:!0},fields:[new Ue({label:"Field",description:"The field to use for the condition.",options:e.map(a=>!a.label||a.type==="upload"?null:{label:a.label,value:a.identifier}).filter(a=>!!a),identifier:`${i}condition.identifier`,required:!0}),new $o({label:"Value",identifier:`${i}condition.value`,required:!0,clonedFieldIdentifier:`${i}condition.identifier`,getFieldToClone(a){if(!a)return null;const s=e.find(l=>l.identifier===a);return s?{...s,label:"Value",identifier:`${i}condition.value`,description:"The value to compare against.",required:s.type!=="boolean"}:(console.error("Could not find field with identifier",a),null)}})]}),showDirectly:!1}]}static deserialize(e){if(e.type!=="section")throw new Error("Invalid type");if(!Array.isArray(e.fields))throw new Error(`Invalid fields: ${e.fields} (not an array)`);const r=e.fields.map(un);return new Oe({...e,fields:r})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const r={};for(const i of this.fields){const a=i.getId(),s=i.getError(R(e,a),e);s&&$e(r,i.getId(),s)}return r}getInput(e){return o.jsx($r,{field:this,...e})}};N(Oe,"fieldTypeName","Section"),N(Oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let W=Oe;const ge=t=>Object.keys(t).length>0,vt=(t,n)=>{const e={};for(const r of t.fields)if(r instanceof W){if(r.condition){const{identifier:i}=r.condition;if(!fn(r.condition,R(n,i)))continue}Object.assign(e,r.getErrors(n))}else{if(!(r instanceof j))throw new Error("Invalid field type");const i=r.getId(),a=r.getError(R(n,i),n);a&&$e(e,i,a)}if(ge(e))return e},yt=(t,n)=>t.reduce((e,r)=>{if(r instanceof W)return{...e,...yt(r.fields,n)};const i=r.getId();return $e(e,i,e[i]??void 0),e},ti(n)),kr=(t,n,e)=>t.reduce((r,i)=>{if(i instanceof W)return{...r,...kr(i.fields,n,e)};if(i instanceof j){const a=i.getId(),s=n[a],l=e[a];i.isEqual(s,l)||$e(r,a,l)}return r},{}),jr=c.memo(c.forwardRef((t,n)=>{const{schema:e,values:r={},onValuesChange:i,onSubmit:a,submitText:s="Submit",cancelText:l,onCancel:m,onDirty:u,onDirtyChange:f,hideTitle:h=!e.title,hideDescription:g,className:C,buttonProps:w,enableReinitialize:p=!1,excludeUnchangedFields:b=!1}=t,{readonly:I}=e.meta,x=c.useId(),y=c.useMemo(()=>yt(e.fields,r),[e.fields,r]),T=c.useCallback(_=>{a==null||a(b?kr(e.fields,y,_):_)},[b,y,a,e.fields]),S=k.useFormik({initialValues:y,onSubmit:T,validate:_=>vt(e,_),validateOnBlur:!1,validateOnChange:!1,enableReinitialize:p}),{dirty:L}=S,F=c.useMemo(()=>typeof e.title=="string"?o.jsx(d.Heading,{size:"md",children:e.title}):e.title,[e.title]),D=c.useMemo(()=>typeof e.description=="string"?o.jsx(d.Text,{accentColor:"base",children:e.description}):e.description,[e.description]),M=c.useCallback((_,U)=>{Ur(e)[_].isEqual(y[_],U)||i==null||i({...S.values,[_]:U},{[_]:U})},[S.values,y,i,e]),O=ze(e.fields,{formId:x,disabled:I,onValuesChange:M});return c.useEffect(()=>{L&&u&&u(),f&&f(L)},[L,u,f]),o.jsx(k.FormikProvider,{value:S,children:o.jsxs("form",{id:x,ref:n,className:ye(C,"flex flex-col gap-2"),onSubmit:S.handleSubmit,children:[!h&&o.jsx(d.Card,{variant:"soft",children:o.jsxs("div",{className:"flex flex-col gap-1",children:[F,!g&&D]})}),O,!I&&o.jsxs("div",{className:"flex items-center justify-end gap-2",children:[l&&o.jsxs(d.Button,{accentColor:ue.danger,...w,type:"button",onClick:m,children:[o.jsx(d.RiIcon,{icon:"RiCloseLine"}),l]}),o.jsxs(d.Button,{...w,type:"submit",disabled:!S.isValid,accentColor:"success",children:[o.jsx(d.RiIcon,{icon:"RiCheckLine"}),s]})]})]})})})),ve=c.memo(t=>{const{name:n,render:e}=t,{submitForm:r}=k.useFormikContext(),[i,a,s]=k.useField(n),l=c.useMemo(()=>{const m=u=>{s.setValue(u,!1)};return e({value:i.value,meta:a,setValue:m,patchValue:()=>{r()}})},[e,i.value,a,r,s]);return o.jsx(o.Fragment,{children:l})});ve.displayName="PatchField";const Ro=c.memo(c.forwardRef((t,n)=>{const{children:e,schema:r,values:i,onPatch:a,onError:s,requiresDiff:l=!0,onDirtyChange:m,...u}=t,f=c.useMemo(()=>yt(r.fields,i),[r.fields,i]),h=c.useCallback(x=>{const y={};for(const T in x){const S=x[T];S!==f[T]&&S!==void 0&&(y[T]=S)}return y},[f]),g=c.useCallback(x=>{const y=h(x);l&&!ge(y)||a(y)},[h,a,l]),C=c.useCallback(x=>{const y=vt(r,x);if(y&&s(y),m){const T=h(x);m(ge(T))}return y},[r,m,s,h]),w=k.useFormik({initialValues:f,onSubmit:g,validate:C,validateOnBlur:!1,validateOnChange:!1}),p=c.useCallback(()=>{if(m){const x=h(w.values);ge(x)&&m(!0)}},[w.values,h,m]),{errors:b,resetForm:I}=w;return c.useEffect(()=>{ge(b)&&I({values:f,errors:{}})},[b,f,I]),o.jsx(k.FormikProvider,{value:w,children:o.jsx("form",{...u,ref:n,onSubmit:w.handleSubmit,onChange:p,children:e})})})),bt="form-builder",ea=[["string","text"],["select","multi-select","upload","qr"],["boolean","date","number","multi-string"]],hn={...dn,section:W},Ct=c.createContext({}),ta=(t,n)=>{var r;const e={...t};switch(n.type){case"release":for(const i in e)e[i].disabled=!1;return e;case"hold":for(const i in e)(r=e[i])!=null&&r.conditionFields.has(n.fieldId)&&(e[i].disabled=!0);return e;case"update":return n.state}},na=(t,n)=>{if(n)for(let e=0;e<t.length;e++){const r=t[e];if(r){for(const i of r.fields)if(i.identifier===n)return e}}},Wr=t=>{var e,r,i;const n={};for(let a=0;a<t.length;a++){const s=t[a];if(!s)throw new Error("Field is undefined.");const l=a>0?(e=n[t[a-1].identifier])==null?void 0:e.conditionFields:void 0,m=new Set(l);(r=s.condition)!=null&&r.identifier&&m.add(s.condition.identifier),n[s.identifier]={disabled:!1,conditionFields:m,conditionIndex:na(t,(i=s.condition)==null?void 0:i.identifier),index:a,label:s.label}}return n},pn=c.memo(t=>{const{index:n,type:e,sectionIndex:r,remove:i,duplicate:a,move:s,upload:l}=t;if(e!=="section"&&!l)throw new Error("Upload function prop must be defined for non-section fields.");const{values:m}=k.useFormikContext(),u=c.useRef(null),f=c.useMemo(()=>{const h=[{Icon:H.RiFileCopyLine,key:"duplicate",text:"Duplicate",buttonProps:{onClick:a}}];return h.push({Icon:H.RiDeleteBin7Fill,key:"delete",text:"Delete",buttonProps:{onClick:i}}),e!=="section"&&h.unshift({Icon:H.RiImageLine,key:"upload",text:"Upload image",buttonProps:{onClick:()=>{var g;(g=u.current)==null||g.click()}}}),(r===void 0&&n!==m.fields.length-1||r!==void 0&&(r<m.fields.length-1||n!==m.fields[r].fields.length-1))&&h.unshift({Icon:H.RiArrowDownLine,key:"moveDown",text:"Move down",buttonProps:{onClick:()=>{s("down")}}}),(r===void 0&&n!==0||r!==void 0&&(r!==0||n!==0))&&h.unshift({Icon:H.RiArrowUpLine,key:"moveUp",text:"Move up",buttonProps:{onClick:()=>{s("up")}}}),h},[a,n,s,i,r,e,m.fields]);return o.jsxs(o.Fragment,{children:[o.jsx(d.ButtonGroup,{className:"mx-2 hidden flex-col gap-0.5 sm:flex",variant:"ghost",accentColor:"base",size:"sm",children:f.map(h=>o.jsx(d.IconButton,{type:"button","aria-label":h.text,...h.buttonProps,children:o.jsx(h.Icon,{})},h.key))}),o.jsx("div",{className:"sm:hidden",children:o.jsxs(d.Menu.Root,{children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsx(d.IconButton,{variant:"ghost",accentColor:"base","aria-label":"Actions menu",size:"sm",type:"button",children:o.jsx(d.RiIcon,{icon:"RiMore2Line"})})}),o.jsx(d.Menu.Content,{children:f.map(h=>{var g;return o.jsxs(d.Menu.Item,{onClick:(g=h.buttonProps)==null?void 0:g.onClick,children:[o.jsx(h.Icon,{}),h.text]},h.key)})})]})}),e!=="section"&&o.jsx("input",{style:{display:"none"},ref:u,type:"file",accept:"image/*",onChange:l})]})});pn.displayName="FieldActions";const mn=c.memo(t=>{const{popoverInputs:n,hasError:e,...r}=t;return o.jsxs(d.Popover.Root,{children:[o.jsx(d.Popover.Trigger,{asChild:!0,children:o.jsxs(d.Button,{variant:"soft",type:"button",size:"sm","aria-label":"settings",accentColor:"base",...e&&{color:ue.danger},children:[o.jsx(d.RiIcon,{icon:"RiSettings2Line"}),o.jsx("span",{children:"Settings"})]},"settings")}),o.jsx(d.Popover.Content,{size:"sm",...r,children:o.jsx("div",{className:"flex w-full max-w-[350px] flex-col",children:n})})]})});mn.displayName="FieldSettingsPopover";const qr=(t=()=>null)=>c.useMemo(()=>ea.map(n=>n.map(e=>{const r=dn[e],i=r.Icon;return{children:r.fieldTypeName,icon:o.jsx(i,{}),value:e,onSelect:()=>{t(e)}}})),[t]),Hr=576,gn=c.memo(t=>{var Be,vn,Jr,Zr,Rr;const{parentPath:n,index:e,initial:r,conditionalSourceFields:i}=t,{values:a,setFieldValue:s,errors:l}=k.useFormikContext(),m=qr(),u=We(),{disableRequiredFields:f}=c.use(Ct),h=c.useRef(null),[g,C]=c.useState(h.current&&h.current.getBoundingClientRect().width>=Hr);c.useEffect(()=>{const P=h.current;if(P){const z=new ResizeObserver(G=>{G[0]&&C(G[0].contentRect.width>=Hr)});return z.observe(P),()=>{z.disconnect()}}},[]);const[w,p]=c.useState(void 0);c.useEffect(()=>{me(r)?p(void 0):r.image instanceof Promise?r.image.then(p).catch(console.error):p(r.image)},[r]);const b=w?URL.createObjectURL(w):void 0,I=c.useCallback(P=>{P.stopPropagation();const{image:z,...G}=r;s(`${n}.${e}`,G).then()},[e,r,n,s]);c.useEffect(()=>{me(r)&&!r.conditional&&s(`${n}.${e}.condition`,null).then()},[e,r,n,s]);const x=c.useMemo(()=>{var P,z;return me(r)?(z=Ir(a.fields,(P=r.condition)==null?void 0:P.identifier))==null?void 0:z.label:void 0},[r,a.fields]),y=me(r)?Array.isArray((Be=r.condition)==null?void 0:Be.value)?"contains all of":"equals":void 0;let T;if(me(r)){if(gt((vn=r.condition)==null?void 0:vn.value))throw new Error("File values are not supported for conditions.");T=Array.isArray((Jr=r.condition)==null?void 0:Jr.value)?r.condition.value.map(P=>typeof P=="string"?P:P.label).join(", "):(Rr=(Zr=r.condition)==null?void 0:Zr.value)==null?void 0:Rr.toString()}const S=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),L=c.useCallback(P=>{P.target.parentNode instanceof HTMLElement&&(P.target.parentNode.dataset.replicatedValue=P.target.value)},[]),F=r.type,D=hn[F],[M,O]=c.useMemo(()=>{let P=[],z=[];if(D===W){if(i===void 0)throw new Error("Conditional source fields must be provided when changing sections.");const G=D.getFieldCreationSchema(i,`${n}.${e}`);P=P.concat(G.filter($=>$.showDirectly).map($=>$.field)),z=z.concat(G.filter($=>!$.showDirectly).map($=>$.field))}else{if(!(D.prototype instanceof j))throw new Error(`Field must be an instance of BaseField. Got ${D.toString()}.`);const G=D.getFieldCreationSchema(`${n}.${e}`);g?(P=[...P,...G.filter($=>$.showDirectly).map($=>$.field)],z=[...z,...G.filter($=>!$.showDirectly).map($=>$.field)]):z=[...z,...G.map($=>$.field)]}return[P,z]},[D,i,n,e,g]),_=ze(M,{formId:bt,disabled:!1,...D===W&&{size:"sm"}}),U=ze(O,{formId:bt,disabled:!1});let B=O.length>0;me(r)&&O.length>0&&(B=r.conditional);const Z=O.some(P=>{const z=R(l,D===W?`${n}.${e}.condition`:P.getId());return z&&(typeof z!="object"||ge(z))}),A=Z?ue.danger:void 0,q=c.useMemo(()=>pt(r),[r]),le=Qt(q,{formId:bt,showInputOnly:!1}),ne=c.useMemo(()=>m.flat().find(P=>P.value===F),[m,F]),ce=c.useCallback(()=>{w&&u(()=>({file:w}))},[u,w]);return o.jsx("div",{className:"flex grow items-center w-full",ref:h,children:o.jsxs("div",{className:"flex w-full flex-col gap-2",children:[D===W&&(M.length>0||B)&&o.jsxs("div",{className:"flex flex-col gap-2",children:[_,B&&o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(mn,{popoverInputs:U,hasError:Z,align:"start"}),me(r)&&r.conditional&&o.jsx("span",{className:"text-sm text-(--accent-a11)","data-accent-color":A,children:o.jsxs("em",{children:["Display only if ",o.jsx("strong",{children:x})," ",y," ",o.jsx("strong",{children:T})]})})]})]}),D!==W&&o.jsxs("div",{className:"flex gap-2 w-full justify-between",children:[o.jsxs("div",{className:"flex gap-2 items-center",children:[o.jsxs(d.Badge,{accentColor:"base",variant:"soft",size:"sm",children:[ne==null?void 0:ne.icon,ne==null?void 0:ne.children]}),!f&&o.jsx(ve,{name:`${n}.${e}.required`,render:({setValue:P,value:z})=>o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.Checkbox.Root,{checked:z,onCheckedChange:P,size:"sm",children:o.jsx(d.Checkbox.Indicator,{children:o.jsx(d.RiIcon,{icon:"RiCheckLine"})})}),o.jsx(d.Text,{size:"sm",accentColor:"base",children:"Required"})]})})]}),B&&o.jsx(mn,{popoverInputs:U,hasError:Z,align:"end"})]}),w&&o.jsxs("div",{className:"group relative inline-block w-full min-w-[300px]",children:[o.jsx("img",{className:"h-[100px] w-full min-w-[300px] cursor-pointer rounded-md object-cover",src:b,alt:w.name,onClick:ce}),o.jsx(d.IconButton,{className:"absolute top-2 right-2 hidden group-hover:not-disabled:flex",variant:"solid",accentColor:"base","aria-label":"delete",onClick:I,size:"sm",children:o.jsx(d.RiIcon,{icon:"RiDeleteBin7Fill"})})]}),o.jsx(ve,{name:`${n}.${e}.label`,render:({setValue:P,value:z})=>o.jsx("input",{className:"bg-transparent outline-none text-sm placeholder-(--base-a9)",placeholder:F==="section"?"Enter a section label (optional)":"Enter your question",value:z,onChange:G=>{P(G.target.value)},onInput:S,maxLength:200})}),o.jsx(ve,{name:`${n}.${e}.description`,render:({setValue:P,value:z})=>o.jsx("textarea",{className:"bg-transparent outline-none text-sm field-sizing-content grow placeholder-(--base-a9)",placeholder:`Enter a ${F==="section"?"section":"field"} description (optional)`,value:z,onChange:G=>{P(G.target.value)},onInput:L,maxLength:1e3})}),D!==W&&M.length>0&&o.jsx("div",{className:"w-full",children:_}),D!==W&&o.jsxs(d.Card,{className:"flex gap-4 bg-(--accent-a2) items-center",children:[o.jsxs(d.HoverCard.Root,{children:[o.jsx(d.HoverCard.Trigger,{asChild:!0,children:o.jsx(d.Badge,{icon:!0,size:"sm",variant:"soft",accentColor:"base",children:o.jsx(d.RiIcon,{icon:"RiEyeLine"})})}),o.jsx(d.HoverCard.Content,{className:"w-[225px]",size:"sm",align:"start",children:"This is a preview of the field as it will be rendered in the form."})]}),o.jsx("div",{className:"grow h-max",children:le})]})]})})});gn.displayName="FieldBuilder";const Gr=c.memo(t=>{const{field:n,index:e,sectionIndex:r,remove:i}=t,{setFieldValue:a,values:s}=k.useFormikContext(),{reorderField:l}=Rt(),{showInfo:m,showError:u}=d.useToast(),f=`fields.${r}.fields`,h=c.useMemo(()=>({index:e,parentPath:f,initial:n}),[n,e,f]),g=c.useCallback(()=>{const p=n.label||"Unlabelled field",b={...n,label:p};lt(f,e+1,b,s,a),m({title:"Field duplicated",description:`The field "${p}" has been duplicated`})},[n,f,e,s,a,m]),C=c.useCallback(p=>{const b=r,I=s.fields[b];let x=r,y=p==="up"?e-1:e+1;p==="up"&&e===0?(x=r-1,y=s.fields[x].fields.length):p==="down"&&e===I.fields.length-1&&(x=r+1,y=0);const T=s.fields[x];l(I,b,e,T,x,y,a)},[r,s.fields,e,l,a]),w=c.useCallback(p=>{const{files:b}=p.target;if(!b||b.length!==1)return;const I=b.item(0);if(I){if(I.size>Yo){u({title:"File upload error",description:`The file ${I.name} exceeded the maximum file size`});return}a(`${f}.${e}`,{...n,image:I}).then()}},[n,e,f,a,u]);return o.jsx(ie.Draggable,{draggableId:n.identifier,index:e,children:p=>o.jsx(d.Card,{ref:p.innerRef,...p.draggableProps,...p.dragHandleProps,className:"mb-4",children:o.jsxs("div",{className:"flex items-center justify-between gap-4 w-full",children:[o.jsx(gn,{...h}),o.jsx(pn,{index:e,type:n.type,sectionIndex:r,remove:i,duplicate:g,move:C,upload:w})]})})})});Gr.displayName="FieldWithActions";const Xr=c.memo(t=>{var T;const{field:n,index:e,dropState:r}=t,i=(T=r[n.identifier])==null?void 0:T.disabled,{setFieldValue:a,values:s}=k.useFormikContext(),l=d.useAlertDialog(),{reorderSection:m}=Rt(),{showInfo:u}=d.useToast(),{fieldsOnly:f}=c.use(Ct),h=c.useCallback((S,L)=>{for(const F of S){const D=L.indexOf(F);a(`fields.${D}.condition`,null).then(),a(`fields.${D}.conditional`,!1).then()}},[a]),g=c.useCallback(S=>{var D;const L=n.fields[S];if(!L)throw new Error("Could not find field to remove.");const F=[];for(const M of s.fields)((D=M.condition)==null?void 0:D.identifier)===L.identifier&&F.push(M);return{removing:L,affectedSections:F,action:()=>a(`fields.${e}.fields`,st(n.fields,S))}},[n.fields,s.fields,a,e]),C=c.useCallback(S=>{const{affectedSections:L,action:F,removing:D}=g(S),M=()=>{F().then(),h(L,s.fields)};if(L.length>0){const O=L.map(_=>_.label).join(", ");l({title:"Remove condition?",description:`${D.label} is being used as a condition, deleting it will remove the condition from the ${O} section(s).`,action:"Remove",onAction:M});return}M()},[g,h,s.fields,l]),w=c.useCallback(()=>{const L=n.fields.map((B,Z)=>g(Z)).flatMap(B=>B.affectedSections),F=L.length?"Remove fields and conditions?":"Remove fields?",D=n.fields.length,M=L.map(B=>B.label).join(", "),O=L.length?`Deleting this section will remove the ${D} field(s) it contains and will remove the conditions from following sections: ${M}`:`Deleting this section will remove the ${D} field(s) it contains.`,_=st(s.fields,e),U=()=>a("fields",_);if(L.length>0){l({title:F,description:O,action:"Remove",onAction:()=>{U().then(()=>{h(L,_)})}});return}U().then()},[n.fields,s.fields,e,g,a,l,h]),p=c.useCallback(S=>{const L=S==="up"?e-1:e+1;m(r,n.identifier,e,L,s,a)},[e,m,r,n.identifier,s,a]),b=c.useMemo(()=>({index:e,parentPath:"fields",initial:n,conditionalSourceFields:xr(s.fields,e)}),[n,e,s.fields]),I=c.useCallback(()=>{const S=n.label||"Untitled section",L=n.fields.map(D=>({...D,identifier:Zt()})),F={...n,label:S,fields:L};lt("fields",e+1,F,s,a),u({title:"Section duplicated",description:`The section "${S}" has been duplicated.`})},[n,e,s,a,u]),x=c.useCallback(S=>{lt(`fields.${e}.fields`,n.fields.length,Qo[S],s,a)},[e,n.fields.length,s,a]),y=qr(x);return o.jsx(ie.Draggable,{draggableId:n.identifier,index:e,children:S=>o.jsx(d.Card,{ref:S.innerRef,...S.draggableProps,...S.dragHandleProps,variant:"outline",className:"mb-4 w-full",children:o.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[o.jsxs("div",{className:"flex grow flex-col gap-2 w-full",children:[!f&&o.jsx(gn,{...b}),o.jsx(ie.Droppable,{droppableId:n.identifier,type:"SECTION",isDropDisabled:i,children:L=>o.jsxs("div",{className:"flex flex-col gap-0 w-full",ref:L.innerRef,...L.droppableProps,children:[n.fields.map((F,D)=>o.jsx(Gr,{field:F,index:D,sectionIndex:e,remove:()=>{C(D)}},F.identifier)),L.placeholder,o.jsxs(d.Menu.Root,{children:[o.jsx(d.Menu.ClickTrigger,{children:o.jsxs(d.Button,{type:"button",variant:"soft",size:"sm",children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add field"]})}),o.jsx(d.Menu.Content,{children:y.flat().map(F=>o.jsxs(d.Menu.Item,{onSelect:F.onSelect,children:[F.icon,F.children]},F.value))})]})]})})]}),!f&&o.jsx(pn,{index:e,type:n.type,remove:w,duplicate:I,move:p})]})})})});Xr.displayName="FieldSectionWithActions";const Kr=(t,n)=>{for(const[e,r]of Object.entries(t))if(r.identifier===n)return[r,e]},Qr=c.memo(()=>{const{values:t,setFieldValue:n}=k.useFormikContext(),[e,r]=c.useReducer(ta,t.fields,Wr),{reorderSection:i,reorderField:a}=Rt(),{fieldsOnly:s}=c.use(Ct);c.useEffect(()=>{r({type:"update",state:Wr(t.fields)})},[r,t.fields]);const l=c.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),m=c.useCallback(f=>{const{source:h,destination:g,type:C,reason:w,draggableId:p}=f;if(r({type:"release"}),!g||w==="CANCEL")return;if(C==="ROOT"){i(e,p,h.index,g.index,t,n);return}if(C!=="SECTION")throw new Error("Unexpected droppable type.");const[b,I]=Kr(t.fields,h.droppableId)??[],[x,y]=Kr(t.fields,g.droppableId)??[];a(b,I,h.index,x,y,g.index,n)},[t,a,n,i,e]),u=c.useCallback(f=>{Go(f+1,t,n)},[t,n]);return o.jsx(ie.DragDropContext,{onDragStart:l,onDragEnd:m,children:o.jsx(ie.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>o.jsxs("div",{className:"flex flex-col gap-0",ref:f.innerRef,...f.droppableProps,children:[t.fields.map((h,g)=>o.jsxs(c.Fragment,{children:[o.jsx(Xr,{field:h,index:g,dropState:e,fieldsOnly:s}),!s&&g!==t.fields.length-1&&o.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",size:"sm",accentColor:"base",onClick:()=>{u(g)},children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]})]},h.identifier)),o.jsxs(d.Button,{className:"mb-4",type:"button",variant:"soft",accentColor:"base",size:"sm",onClick:()=>{u(t.fields.length)},children:[o.jsx(d.RiIcon,{icon:"RiAddLine"})," Add section"]}),f.placeholder]})})})});Qr.displayName="FieldsEditor";const ra=c.memo(c.forwardRef((t,n)=>{const{onCancel:e,onSave:r,revision:i,initialTitle:a,showExplainerText:s=!0,showFormTitle:l=!0,fieldsOnly:m=!1,showTabs:u=!0,disableRequiredFields:f=!1,tabsListClassName:h,hydrateRevisionWithImages:g}=t,{showError:C}=d.useToast(),w=c.useCallback(T=>{const S={};T.title||(S.title="Title is required."),(!T.fields||T.fields.length===0)&&(S.fields="At least one field is required.");let L=[];for(const[D,M]of T.fields.entries()){const _=hn.section.getFieldCreationSchema(xr(T.fields,D),`fields.${D}`).map(U=>U.field);L=[...L,..._];for(const[U,B]of M.fields.entries()){const A=hn[B.type].getFieldCreationSchema(`fields.${D}.fields.${U}`).map(q=>q.field);L=[...L,...A]}}const F=vt({fields:L},T);if(F&&(S.fields=F.fields),ge(S))return C({title:"Some form settings are invalid",description:"Please check settings highlighted in red."}),S},[C]),p=c.useMemo(()=>({title:a??"",description:"",fields:[{...at(Zt()),label:""}]}),[a]),b=i?g(i):void 0,I=k.useFormik({initialValues:Ho(b)??p,validate:w,onSubmit:r,validateOnChange:!1,validateOnBlur:!1}),x=c.useMemo(()=>Vr(I.values),[I.values]),y=c.useMemo(()=>({disableRequiredFields:f,fieldsOnly:m}),[f,m]);return o.jsx(Ct,{value:y,children:o.jsx(d.Tabs.Root,{ref:n,defaultValue:"edit",children:o.jsxs("div",{className:"flex flex-col gap-2",children:[u&&o.jsxs(d.Tabs.List,{className:ye("sticky top-0 z-[2000] flex bg-(--color-background)",h),children:[o.jsx(d.Tabs.Trigger,{className:"grow",value:"edit",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.RiIcon,{icon:"RiPencilLine"}),"Edit form"]})}),o.jsx(d.Tabs.Trigger,{className:"grow",value:"preview",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(d.RiIcon,{icon:"RiEyeLine"}),"Preview form"]})})]}),o.jsxs(d.Tabs.Content,{value:"edit",children:[s&&o.jsxs(d.Text,{children:["Create your form using various field types. Sections can be"," ",o.jsx("strong",{children:"conditionally rendered"})," based on"," ",o.jsx("strong",{children:"answers to fields in preceding sections. "})]}),o.jsxs("form",{className:"mt-3 flex flex-col gap-2",id:bt,onSubmit:I.handleSubmit,children:[o.jsxs(k.FormikProvider,{value:I,children:[l&&o.jsxs(o.Fragment,{children:[o.jsx(ve,{name:"title",render:({setValue:T,value:S,meta:L})=>o.jsx(Gt,{severity:"danger",helpText:L.error??null,children:o.jsx(d.Input.Root,{variant:"outline",size:"md",accentColor:L.error?ue.danger:"primary",children:o.jsx(d.Input.Field,{placeholder:"Form title",value:S,onChange:F=>{T(F.target.value)},maxLength:100})})})}),o.jsx(ve,{name:"description",render:({setValue:T,value:S})=>o.jsx(d.TextArea,{className:"field-sizing-content",placeholder:"Explain the purpose of this form",value:S,onChange:L=>{T(L.target.value)},resize:"vertical",maxLength:1e3,size:"md"})})]}),o.jsx(Qr,{}),o.jsx("span",{"data-accent-color":ue.danger,className:"text-xs text-(--accent-a11)",children:typeof I.errors.fields=="string"&&I.errors.fields})]}),o.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e&&o.jsx(d.Button,{type:"button",variant:"solid",accentColor:"base",onClick:e,children:"Cancel"}),o.jsx(d.Button,{type:"submit",children:"Save form"})]})]})]}),o.jsx(d.Tabs.Content,{value:"preview",children:o.jsx(jr,{schema:x,hideTitle:!l})})]})})})})),ia=Object.values(de.Colors),oa=1;async function aa(t,n,e,r){const i=t.getContext("2d",{}),a=new Image(r.width,r.height),s=new Image(r.width,r.height),l=new de.DeferredPromise;return a.onload=function(){i.drawImage(a,0,0,r.width,r.height),s.src=URL.createObjectURL(e),s.onload=async function(){i.drawImage(s,0,0,r.width,r.height);const m=t.toDataURL("image/jpeg",oa),u=await de.fileToBlob(m),f=new File([u],n.name,{type:"image/jpeg"});l.resolve(f)}},a.src=URL.createObjectURL(n),l}const Yr=c.memo(t=>{const{file:n,onClose:e,onSave:r,onDelete:i,dirty:a,onDirty:s}=t;n.objectURL||(n.objectURL=URL.createObjectURL(n));const l=c.useRef(null),m=c.useRef(null),[u,f]=c.useState(de.Colors.red),[h,g]=c.useState(null),[C,w]=c.useState(!1),[p,b]=c.useState(!1),I=c.useRef(null),x=d.useSize(I);c.useEffect(()=>{const B=new Image;B.onload=function(){g({width:B.naturalWidth,height:B.naturalHeight})},B.src=URL.createObjectURL(n)},[n]),c.useEffect(()=>{!p&&(x!=null&&x.width)&&x.height&&b(!0)},[x,p]);const y=c.useCallback(async()=>{a||e();const B=l.current;if(!B)return;if(!h)throw new Error("Original image size not loaded yet");const Z=await B.exportImage("png"),A=new Image(h.width,h.height);A.onload=async function(){const q=await de.fileToBlob(Z),le=new File([q],n.name,{type:n.type}),ne=m.current,ce=await aa(ne,n,le,h);ce.objectURL=URL.createObjectURL(ce);const Be=await de.hashFile(n);await de.hashFile(ce)!==Be&&r(ce),w(!1),e()},w(!0),A.src=Z},[a,n,e,r,h]),T=c.useCallback(()=>{i(n)},[n,i]),S=c.useCallback(()=>{e()},[e]),L=c.useCallback(()=>{s(!0)},[s]),F=c.useCallback(()=>{l.current&&l.current.redo()},[]),D=c.useCallback(()=>{l.current&&l.current.undo()},[]),M=c.useCallback(()=>{l.current&&(s(!1),l.current.clearCanvas())},[s]),O=c.useCallback(B=>{l.current&&l.current.eraseMode(B)},[]),_=c.useCallback(()=>{y()},[y]),U=c.useCallback(()=>{qt.saveAs(n,n.name)},[n]);return o.jsx($t,{open:!0,onOpenChange:e,children:o.jsxs(kt,{children:[o.jsx(jt,{className:"bg-(--color-background) fixed inset-0 data-[state='open']:fade-in-0 data-[state='open']:zoom-in-95 data-[state='closed']:animate-out data-[state='closed']:fade-out-0 data-[state='closed']:zoom-out-95 data-[state='open']:animate-in","data-floating-content":""}),o.jsxs(Wt,{className:"absolute inset-0 py-12","data-floating-content":"",children:[o.jsx(d.ButtonGroup,{className:"flex w-full gap-2 items-center top-0 absolute right-0 p-2",accentColor:"base",size:"md",variant:"soft",children:o.jsxs("div",{className:"grid w-full grid-cols-3",children:[o.jsxs("div",{className:"flex gap-2",children:[o.jsx(d.IconButton,{"aria-label":"close",onClick:S,children:o.jsx(d.RiIcon,{icon:"RiCloseLine"})}),o.jsx(d.IconButton,{"aria-label":`Download ${n.name}`,onClick:U,children:o.jsx(d.RiIcon,{icon:"RiDownload2Line"})})]}),o.jsxs("div",{className:"flex items-center justify-center gap-2",children:[o.jsx(wt,{selectedColor:u,allColors:ia,onFinish:f,trigger:o.jsx(d.IconButton,{"aria-label":"Markup color picker",type:"button",variant:"solid",style:{backgroundColor:u},children:" "})}),o.jsx(d.IconToggleButton,{defaultPressed:!1,"aria-label":"erase",onPressedChange:O,children:o.jsx(d.RiIcon,{icon:"RiEraserFill"})}),o.jsx(d.Separator,{orientation:"vertical",size:"full"}),o.jsx(d.IconButton,{"aria-label":"undo",onClick:D,children:o.jsx(d.RiIcon,{icon:"RiArrowGoBackLine"})}),o.jsx(d.IconButton,{"aria-label":"undo",onClick:F,children:o.jsx(d.RiIcon,{icon:"RiArrowGoForwardLine"})}),o.jsx(d.IconButton,{"aria-label":"undo all",onClick:M,children:o.jsx(d.RiIcon,{icon:"RiLoopLeftLine"})})]}),o.jsxs("div",{className:"flex justify-end gap-2",children:[o.jsx(d.IconButton,{"aria-label":"Save markup",accentColor:"primary",onClick:_,children:o.jsx(d.RiIcon,{icon:"RiSaveLine"})}),o.jsx(d.IconButton,{"aria-label":"Delete attachment",onClick:T,children:o.jsx(d.RiIcon,{icon:"RiDeleteBin2Line"})})]})]})}),h&&o.jsx("canvas",{id:"attachment-markup-canvas",className:"hidden",ref:m,width:h.width,height:h.height}),o.jsxs("div",{className:"relative size-full flex items-center justify-center p-4 overflow-hidden",children:[o.jsx("img",{className:"max-w-full max-h-full invisible absolute",alt:"Photo attachment",ref:I,src:n.objectURL}),C?o.jsx(d.Spinner,{}):o.jsx(ni.ReactSketchCanvas,{className:"max-w-full max-h-full aspect-square",backgroundImage:n.objectURL,ref:l,onStroke:L,strokeColor:u},p?"1":"0")]})]})]})})});Yr.displayName="AttachmentEditor",E.BaseField=j,E.BaseFormElement=xt,E.BooleanField=Ee,E.BooleanInput=Xt,E.ColorPicker=wt,E.DateField=rt,E.DateInput=Kt,E.FieldSection=W,E.FileCard=It,E.FileIcon=ke,E.FormBuilder=ra,E.FormRenderer=jr,E.ImageCard=Or,E.ImageMarkup=Yr,E.ImageViewer=Ht,E.ImageViewerProvider=gr,E.InputWithHelpText=Gt,E.InputWithLabel=Y,E.InputWithLabelAndHelpText=J,E.MultiSelectField=Ve,E.MultiSelectInput=on,E.MultiStringField=_e,E.MultiStringInput=en,E.NumberField=se,E.NumberInput=tn,E.PatchField=ve,E.PatchFormProvider=Ro,E.QrField=ct,E.QrInput=nn,E.QrScanner=rn,E.SUPPORTED_IMAGE_FILE_TYPES=wn,E.SUPPORTED_PDF_FILE_TYPES=xn,E.SUPPORTED_SPREADSHEET_FILE_EXTENSIONS=In,E.SelectField=Ue,E.SelectInput=an,E.StringField=ut,E.StringInput=sn,E.TextField=ft,E.TextInput=ln,E.decodeFormValues=Jo,E.deserialize=pt,E.deserializeField=un,E.emptyBaseField=X,E.emptyBooleanField=vr,E.emptyDateField=yr,E.emptyMultiSelectField=Lr,E.emptyMultiStringField=Er,E.emptyNumberField=Sr,E.emptyQrField=Nr,E.emptySelectField=Dr,E.emptyStringField=Pr,E.emptyTextField=Ar,E.encodeFormValues=Zo,E.fieldIcons=oi,E.flattenFields=mt,E.formRevisionToSchema=Vr,E.getFieldsMapping=Ur,E.initialFormValues=yt,E.isConditionMet=fn,E.useFieldInput=Qt,E.useFieldInputs=ze,E.useFormikInput=K,E.useImageViewer=We,E.validateForm=vt,E.valueIsFile=gt,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});