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