@formhaus/react 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +68 -6
- package/dist/index.js +1 -5
- package/package.json +19 -15
- package/dist/FormActions.d.ts +0 -3
- package/dist/FormActions.d.ts.map +0 -1
- package/dist/FormActions.js +0 -28
- package/dist/FormActions.js.map +0 -1
- package/dist/FormField.d.ts +0 -16
- package/dist/FormField.d.ts.map +0 -1
- package/dist/FormField.js +0 -33
- package/dist/FormField.js.map +0 -1
- package/dist/FormRenderer.d.ts +0 -3
- package/dist/FormRenderer.d.ts.map +0 -1
- package/dist/FormRenderer.js +0 -94
- package/dist/FormRenderer.js.map +0 -1
- package/dist/FormStepProgress.d.ts +0 -3
- package/dist/FormStepProgress.d.ts.map +0 -1
- package/dist/FormStepProgress.js +0 -6
- package/dist/FormStepProgress.js.map +0 -1
- package/dist/fields/CheckboxField.d.ts +0 -3
- package/dist/fields/CheckboxField.d.ts.map +0 -1
- package/dist/fields/CheckboxField.js +0 -9
- package/dist/fields/CheckboxField.js.map +0 -1
- package/dist/fields/DateField.d.ts +0 -3
- package/dist/fields/DateField.d.ts.map +0 -1
- package/dist/fields/DateField.js +0 -9
- package/dist/fields/DateField.js.map +0 -1
- package/dist/fields/FileField.d.ts +0 -3
- package/dist/fields/FileField.d.ts.map +0 -1
- package/dist/fields/FileField.js +0 -12
- package/dist/fields/FileField.js.map +0 -1
- package/dist/fields/MultiselectField.d.ts +0 -3
- package/dist/fields/MultiselectField.d.ts.map +0 -1
- package/dist/fields/MultiselectField.js +0 -20
- package/dist/fields/MultiselectField.js.map +0 -1
- package/dist/fields/RadioField.d.ts +0 -3
- package/dist/fields/RadioField.d.ts.map +0 -1
- package/dist/fields/RadioField.js +0 -13
- package/dist/fields/RadioField.js.map +0 -1
- package/dist/fields/SelectField.d.ts +0 -3
- package/dist/fields/SelectField.d.ts.map +0 -1
- package/dist/fields/SelectField.js +0 -10
- package/dist/fields/SelectField.js.map +0 -1
- package/dist/fields/SwitchField.d.ts +0 -3
- package/dist/fields/SwitchField.d.ts.map +0 -1
- package/dist/fields/SwitchField.js +0 -9
- package/dist/fields/SwitchField.js.map +0 -1
- package/dist/fields/TextField.d.ts +0 -3
- package/dist/fields/TextField.d.ts.map +0 -1
- package/dist/fields/TextField.js +0 -22
- package/dist/fields/TextField.js.map +0 -1
- package/dist/fields/TextareaField.d.ts +0 -3
- package/dist/fields/TextareaField.d.ts.map +0 -1
- package/dist/fields/TextareaField.js +0 -10
- package/dist/fields/TextareaField.js.map +0 -1
- package/dist/hooks/useFieldOptions.d.ts +0 -4
- package/dist/hooks/useFieldOptions.d.ts.map +0 -1
- package/dist/hooks/useFieldOptions.js +0 -39
- package/dist/hooks/useFieldOptions.js.map +0 -1
- package/dist/hooks/useFormEngine.d.ts +0 -3
- package/dist/hooks/useFormEngine.d.ts.map +0 -1
- package/dist/hooks/useFormEngine.js +0 -14
- package/dist/hooks/useFormEngine.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -55
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 formhaus contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _formhaus_core from '@formhaus/core';
|
|
3
|
+
import { FieldType, FormAction, FormDefinition, ValidatorFn, StepValidateFn, FieldOption, FormAnalyticsEvent, FormEngineOptions, FormEngine } from '@formhaus/core';
|
|
4
|
+
import { ComponentType } from 'react';
|
|
5
|
+
|
|
6
|
+
type OptionsProvider = (values: Record<string, unknown>) => FieldOption[] | Promise<FieldOption[]>;
|
|
7
|
+
interface FieldComponentProps {
|
|
8
|
+
field: _formhaus_core.FormField;
|
|
9
|
+
value: unknown;
|
|
10
|
+
error?: string;
|
|
11
|
+
loading?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
onChange: (value: unknown) => void;
|
|
14
|
+
onBlur: () => void;
|
|
15
|
+
onFocus?: () => void;
|
|
16
|
+
}
|
|
17
|
+
type FieldComponentMap = Partial<Record<FieldType, ComponentType<FieldComponentProps>>>;
|
|
18
|
+
interface FormActionsProps {
|
|
19
|
+
submitAction?: FormAction;
|
|
20
|
+
backAction?: FormAction | false;
|
|
21
|
+
cancelAction?: FormAction;
|
|
22
|
+
isFirstStep: boolean;
|
|
23
|
+
isLastStep: boolean;
|
|
24
|
+
isMultiStep: boolean;
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
values?: Record<string, unknown>;
|
|
27
|
+
primaryLabel?: string;
|
|
28
|
+
showBack?: boolean;
|
|
29
|
+
backLabel?: string;
|
|
30
|
+
onSubmit: () => void;
|
|
31
|
+
onNext: () => void;
|
|
32
|
+
onPrev: () => void;
|
|
33
|
+
onCancel: () => void;
|
|
34
|
+
onPrimary?: () => void;
|
|
35
|
+
}
|
|
36
|
+
interface FormStepProgressProps {
|
|
37
|
+
current: number;
|
|
38
|
+
total: number;
|
|
39
|
+
stepTitle?: string;
|
|
40
|
+
stepDescription?: string;
|
|
41
|
+
}
|
|
42
|
+
interface FormRendererProps {
|
|
43
|
+
definition: FormDefinition;
|
|
44
|
+
initialValues?: Record<string, unknown>;
|
|
45
|
+
onSubmit: (values: Record<string, unknown>) => Promise<void> | void;
|
|
46
|
+
onCancel?: () => void;
|
|
47
|
+
onStepChange?: (stepId: string, direction: 'next' | 'back') => void;
|
|
48
|
+
onFieldChange?: (key: string, value: unknown, allValues: Record<string, unknown>) => void;
|
|
49
|
+
validators?: Record<string, ValidatorFn>;
|
|
50
|
+
onStepValidate?: StepValidateFn;
|
|
51
|
+
errors?: Record<string, string>;
|
|
52
|
+
loading?: boolean;
|
|
53
|
+
components?: FieldComponentMap;
|
|
54
|
+
optionsProviders?: Record<string, OptionsProvider>;
|
|
55
|
+
ActionsComponent?: ComponentType<FormActionsProps>;
|
|
56
|
+
ProgressComponent?: ComponentType<FormStepProgressProps>;
|
|
57
|
+
onAnalyticsEvent?: (event: FormAnalyticsEvent) => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare function FormRenderer({ definition, initialValues, onSubmit, onCancel, onStepChange, onFieldChange, validators, onStepValidate, errors: externalErrors, loading, components, optionsProviders, ActionsComponent, ProgressComponent, onAnalyticsEvent, }: FormRendererProps): react_jsx_runtime.JSX.Element;
|
|
61
|
+
|
|
62
|
+
declare function FormActions({ submitAction, backAction, cancelAction, isFirstStep, isLastStep, isMultiStep, loading, values, onSubmit, onNext, onPrev, onCancel, primaryLabel: primaryLabelProp, showBack: showBackProp, backLabel: backLabelProp, onPrimary: onPrimaryProp, }: FormActionsProps): react_jsx_runtime.JSX.Element;
|
|
63
|
+
|
|
64
|
+
declare function FormStepProgress({ current, total, stepTitle, stepDescription, }: FormStepProgressProps): react_jsx_runtime.JSX.Element;
|
|
65
|
+
|
|
66
|
+
declare function useFormEngine(definition: FormDefinition, initialValues?: Record<string, unknown>, options?: FormEngineOptions): FormEngine;
|
|
67
|
+
|
|
68
|
+
export { type FieldComponentMap, type FieldComponentProps, FormActions, type FormActionsProps, FormRenderer, type FormRendererProps, FormStepProgress, type FormStepProgressProps, useFormEngine };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export { FormRenderer } from './FormRenderer';
|
|
2
|
-
export { FormActions } from './FormActions';
|
|
3
|
-
export { FormStepProgress } from './FormStepProgress';
|
|
4
|
-
export { useFormEngine } from './hooks/useFormEngine';
|
|
5
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import {useRef,useSyncExternalStore,useEffect,useState}from'react';import {FormEngine,evaluateCondition}from'@formhaus/core';import {jsxs,jsx}from'react/jsx-runtime';function ke(e,r,t){return t?true:!e?.disabled||e.disabled.length===0?false:e.disabled.every(i=>evaluateCondition(i,r))}function A({submitAction:e,backAction:r,cancelAction:t,isFirstStep:i,isLastStep:a,isMultiStep:s,loading:c,values:p={},onSubmit:l,onNext:n,onPrev:d,onCancel:u,primaryLabel:f,showBack:h,backLabel:y,onPrimary:b}){let o=h??(s&&!i&&r!==false),F=y??(typeof r=="object"?r?.label??"Back":"Back"),$=f??(s&&!a?"Continue":e?.label??"Submit"),O=ke(s&&!a?void 0:e,p,c);function E(){b?b():s&&!a?n():l();}return jsxs("div",{className:"fh-form-actions",children:[jsxs("div",{className:"fh-form-actions__secondary",children:[o&&jsx("button",{type:"button",className:"fh-form-actions__button fh-form-actions__button--text",disabled:c,onClick:d,children:F}),t&&jsx("button",{type:"button",className:"fh-form-actions__button fh-form-actions__button--text",disabled:c,onClick:u,children:t.label})]}),jsx("button",{type:"button",className:"fh-form-actions__button fh-form-actions__button--primary",disabled:O,"aria-busy":c,onClick:E,children:$})]})}function z({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0;return jsxs("div",{className:"fh-field fh-field--checkbox",children:[jsxs("div",{className:"fh-field__checkbox-wrapper",children:[jsx("input",{id:l,type:"checkbox",className:"fh-field__checkbox",checked:!!r,disabled:a||i,"aria-invalid":!!t,"aria-describedby":u,onChange:f=>s(f.target.checked),onBlur:c,onFocus:p}),e.label&&jsx("label",{className:"fh-field__label",htmlFor:l,children:e.label})]}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function J({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0;return jsxs("div",{className:"fh-field",children:[e.label&&jsxs("label",{className:"fh-field__label",htmlFor:l,children:[e.label,e.validation?.required&&jsx("span",{className:"fh-field__required","aria-hidden":"true",children:" *"})]}),jsx("input",{id:l,type:"date",className:"fh-field__input fh-field__input--date",value:String(r??""),disabled:a||i,"aria-invalid":!!t,"aria-describedby":u,onChange:f=>s(f.target.value),onBlur:c,onFocus:p}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function X({field:e,error:r,loading:t,disabled:i,onChange:a,onBlur:s,onFocus:c}){let p=e.key,l=`${e.key}-helper`,n=`${e.key}-error`,d=r?n:e.helperText?l:void 0;return jsxs("div",{className:"fh-field",children:[e.label&&jsxs("label",{className:"fh-field__label",htmlFor:p,children:[e.label,e.validation?.required&&jsx("span",{className:"fh-field__required","aria-hidden":"true",children:" *"})]}),jsx("input",{id:p,type:"file",className:"fh-field__input fh-field__input--file",accept:e.accept,disabled:i||t,"aria-invalid":!!r,"aria-describedby":d,onChange:u=>{let f=u.target.files;a(f&&f.length>0?f[0]:null);},onBlur:s,onFocus:c}),r&&jsx("p",{id:n,className:"fh-field__error",role:"alert",children:r}),!r&&e.helperText&&jsx("p",{id:l,className:"fh-field__helper",children:e.helperText})]})}function Z({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0,f=e.options??[],h=Array.isArray(r)?r:[];function y(b){let o=h.includes(b)?h.filter(F=>F!==b):[...h,b];s(o);}return jsxs("fieldset",{className:"fh-field fh-field--multiselect","aria-invalid":!!t||void 0,"aria-describedby":u,children:[e.label&&jsx("legend",{className:"fh-field__label",children:e.label}),jsx("div",{className:"fh-field__multiselect-group",children:f.map(b=>{let o=`${l}-${b.value}`;return jsxs("div",{className:"fh-field__multiselect-option",children:[jsx("input",{id:o,type:"checkbox",className:"fh-field__checkbox",checked:h.includes(b.value),disabled:a||i,onChange:()=>y(b.value),onBlur:c,onFocus:p}),jsx("label",{className:"fh-field__multiselect-label",htmlFor:o,children:b.label})]},b.value)})}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function ee({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0,f=e.options??[];return jsxs("fieldset",{className:"fh-field fh-field--radio","aria-invalid":!!t||void 0,"aria-describedby":u,children:[e.label&&jsx("legend",{className:"fh-field__label",children:e.label}),jsx("div",{className:"fh-field__radio-group",children:f.map(h=>{let y=`${l}-${h.value}`;return jsxs("div",{className:"fh-field__radio-option",children:[jsx("input",{id:y,type:"radio",className:"fh-field__radio",name:l,value:h.value,checked:String(r)===String(h.value),disabled:a||i,onChange:()=>s(h.value),onBlur:c,onFocus:p}),jsx("label",{className:"fh-field__radio-label",htmlFor:y,children:h.label})]},h.value)})}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function te({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0,f=e.options??[];return jsxs("div",{className:"fh-field",children:[e.label&&jsxs("label",{className:"fh-field__label",htmlFor:l,children:[e.label,e.validation?.required&&jsx("span",{className:"fh-field__required","aria-hidden":"true",children:" *"})]}),jsxs("select",{id:l,className:"fh-field__input fh-field__input--select",value:r??"",disabled:a||i,"aria-invalid":!!t,"aria-describedby":u,onChange:h=>s(h.target.value),onBlur:c,onFocus:p,children:[e.placeholder&&jsx("option",{value:"",disabled:true,children:e.placeholder}),f.map(h=>jsx("option",{value:h.value,children:h.label},h.value))]}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function re({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0;return jsxs("div",{className:"fh-field fh-field--switch",children:[jsxs("div",{className:"fh-field__switch-wrapper",children:[jsx("input",{id:l,type:"checkbox",role:"switch",className:"fh-field__switch",checked:!!r,disabled:a||i,"aria-invalid":!!t,"aria-describedby":u,onChange:f=>s(f.target.checked),onBlur:c,onFocus:p}),e.label&&jsx("label",{className:"fh-field__label",htmlFor:l,children:e.label})]}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function k({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0,f=y=>{let b=y.target.value;s(e.type==="number"?Number(b):b);},h=e.type==="email"?"email":e.type==="phone"?"tel":e.type==="number"?"number":e.type==="password"?"password":"text";return jsxs("div",{className:"fh-field",children:[e.label&&jsxs("label",{className:"fh-field__label",htmlFor:l,children:[e.label,e.validation?.required&&jsx("span",{className:"fh-field__required","aria-hidden":"true",children:" *"})]}),jsx("input",{id:l,type:h,className:"fh-field__input",value:r!=null?String(r):"",placeholder:e.placeholder??e.mask,disabled:a||i,"aria-invalid":!!t,"aria-describedby":u,onChange:f,onBlur:c,onFocus:p}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}function le({field:e,value:r,error:t,loading:i,disabled:a,onChange:s,onBlur:c,onFocus:p}){let l=e.key,n=`${e.key}-helper`,d=`${e.key}-error`,u=t?d:e.helperText?n:void 0;return jsxs("div",{className:"fh-field",children:[e.label&&jsxs("label",{className:"fh-field__label",htmlFor:l,children:[e.label,e.validation?.required&&jsx("span",{className:"fh-field__required","aria-hidden":"true",children:" *"})]}),jsx("textarea",{id:l,className:"fh-field__input fh-field__input--textarea",value:r??"",placeholder:e.placeholder,rows:e.rows??3,disabled:a||i,"aria-invalid":!!t,"aria-describedby":u,onChange:f=>s(f.target.value),onBlur:c,onFocus:p}),t&&jsx("p",{id:d,className:"fh-field__error",role:"alert",children:t}),!t&&e.helperText&&jsx("p",{id:n,className:"fh-field__helper",children:e.helperText})]})}var Ne={text:k,email:k,phone:k,number:k,password:k,select:te,multiselect:Z,checkbox:z,radio:ee,switch:re,file:X,date:J,textarea:le};function ie({field:e,value:r,error:t,loading:i,disabled:a,components:s,onChange:c,onBlur:p,onFocus:l}){let n=s?.[e.type]??Ne[e.type];return n?jsx(n,{field:e,value:r,error:t,loading:i,disabled:a,onChange:c,onBlur:p,onFocus:l}):jsxs("div",{children:["Unsupported field type: ",e.type]})}function K({current:e,total:r,stepTitle:t,stepDescription:i}){let a=e/r*100;return jsxs("div",{className:"fh-step-progress",children:[jsx("div",{className:"fh-step-progress__bar",children:jsx("div",{className:"fh-step-progress__fill",style:{width:`${a}%`}})}),jsx("div",{className:"fh-step-progress__info",children:jsxs("span",{className:"fh-step-progress__counter",children:["Step ",e," of ",r]})}),t&&jsx("h3",{className:"fh-step-progress__title",children:t}),i&&jsx("p",{className:"fh-step-progress__description",children:i})]})}function pe(e,r,t){let[i,a]=useState({}),s=useRef(new Map);return useEffect(()=>{if(!t)return;let c=false;for(let p of e){if(!p.optionsFrom)continue;let l=t[p.optionsFrom];if(!l)continue;let n=(p.optionsDependsOn??[]).map(u=>r[u]).join("|");if(s.current.get(p.key)===n)continue;s.current.set(p.key,n);let d=l(r);Array.isArray(d)?c||a(u=>({...u,[p.key]:d})):d.then(u=>{c||a(f=>({...f,[p.key]:u}));}).catch(()=>{s.current.delete(p.key);});}return ()=>{c=true;}},[e,r,t]),i}function U(e,r,t){let i=useRef(null),a=useRef(e.id);(i.current===null||a.current!==e.id)&&(i.current=new FormEngine(e,r,t),a.current=e.id);let s=i.current;return useSyncExternalStore(s.subscribe.bind(s),s.getSnapshot.bind(s)),s}function Re({definition:e,initialValues:r,onSubmit:t,onCancel:i,onStepChange:a,onFieldChange:s,validators:c,onStepValidate:p,errors:l,loading:n=false,components:d,optionsProviders:u,ActionsComponent:f,ProgressComponent:h,onAnalyticsEvent:y}){let o=U(e,r,{validators:c,onStepValidate:p}),F=pe(o.visibleFields,o.values,u);useEffect(()=>{l&&o.setErrors(l);},[l,o]);function $(m,_){o.setValue(m,_),s?.(m,_,o.values);}function O(m){y?.({type:"field_focused",fieldKey:m});}function E(m){y?.({type:"field_blurred",fieldKey:m,hasValue:o.values[m]!==void 0&&o.values[m]!==""});}function D(m){m.preventDefault();let _=o.validate();for(let[Fe,ve]of Object.entries(_))y?.({type:"field_error",fieldKey:Fe,error:ve});if(Object.keys(_).length>0)return;let S=o.getSubmitValues();y?.({type:"form_submitted",fieldCount:Object.keys(S).length}),t(S);}async function V(){let m=o.currentStep;await o.nextStepAsync()&&(m&&y?.({type:"step_completed",stepId:m.id}),o.currentStep&&(a?.(o.currentStep.id,"next"),y?.({type:"step_viewed",stepId:o.currentStep.id,stepIndex:o.currentStepIndex})));}function ce(){o.prevStep(),o.currentStep&&a?.(o.currentStep.id,"back");}function me(){i?.();}let ue=h??K,fe=f??A,L=o.isLastStep||!o.isMultiStep,he=o.isMultiStep&&!L?o.currentStep?.next?.label??"Continue":e.submit?.label??"Submit",be=o.isMultiStep&&!o.isFirstStep&&o.currentStep?.back!==false,ye=typeof o.currentStep?.back=="object"?o.currentStep.back.label??"Back":"Back";async function _e(){o.isMultiStep&&!L?await V():D({preventDefault:()=>{}});}return jsxs("form",{className:"fh-form",onSubmit:D,children:[o.isMultiStep&&jsx(ue,{current:o.progress.current,total:o.progress.total,stepTitle:o.currentStep?.title,stepDescription:o.currentStep?.description}),jsx("div",{className:"fh-form__fields",children:o.visibleFields.map(m=>{let _=F[m.key]?{...m,options:F[m.key]}:m;return jsx(ie,{field:_,value:o.values[m.key],error:o.errors[m.key],loading:o.fieldLoading[m.key],disabled:n,components:d,onChange:S=>$(m.key,S),onBlur:()=>E(m.key),onFocus:()=>O(m.key)},m.key)})}),o.topLevelErrors.length>0&&jsx("div",{className:"fh-form__top-errors",children:o.topLevelErrors.map(m=>jsx("p",{className:"fh-form__top-error",children:m},m))}),jsx(fe,{submitAction:e.submit,backAction:o.currentStep?.back,cancelAction:e.cancel,isFirstStep:o.isFirstStep,isLastStep:L,isMultiStep:o.isMultiStep,loading:n||o.stepValidating,values:o.values,onSubmit:()=>D({preventDefault:()=>{}}),onNext:V,onPrev:ce,onCancel:me,primaryLabel:he,showBack:be,backLabel:ye,onPrimary:_e})]})}export{A as FormActions,Re as FormRenderer,K as FormStepProgress,U as useFormEngine};
|
package/package.json
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formhaus/react",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "React components for
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "React components for Formhaus forms. Define a form once in JSON, render with native HTML or your own components.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18"
|
|
9
|
+
},
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
13
14
|
}
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist"
|
|
17
18
|
],
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
20
|
-
"test": "vitest run",
|
|
21
|
-
"clean": "rm -rf dist"
|
|
22
|
-
},
|
|
23
19
|
"dependencies": {
|
|
24
|
-
"@formhaus/core": "
|
|
20
|
+
"@formhaus/core": "0.3.1"
|
|
25
21
|
},
|
|
26
22
|
"peerDependencies": {
|
|
27
23
|
"react": ">=18.0.0"
|
|
@@ -33,13 +29,21 @@
|
|
|
33
29
|
"jsdom": "^29.0.2",
|
|
34
30
|
"react": "^19.2.4",
|
|
35
31
|
"react-dom": "^19.2.4",
|
|
32
|
+
"tsup": "^8.5.1",
|
|
36
33
|
"typescript": "^5.7.3",
|
|
37
34
|
"vitest": "^4.1.3"
|
|
38
35
|
},
|
|
39
36
|
"license": "MIT",
|
|
40
37
|
"repository": {
|
|
41
38
|
"type": "git",
|
|
42
|
-
"url": "https://github.com/ignsm/formhaus.git",
|
|
39
|
+
"url": "git+https://github.com/ignsm/formhaus.git",
|
|
43
40
|
"directory": "packages/react"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"test:resolve": "node --input-type=module -e \"import('./dist/index.js').then(m => { if (!m.FormRenderer) process.exit(1); console.log('ESM resolve OK'); })\"",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
44
48
|
}
|
|
45
|
-
}
|
|
49
|
+
}
|
package/dist/FormActions.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { FormActionsProps } from './types';
|
|
2
|
-
export declare function FormActions({ submitAction, backAction, cancelAction, isFirstStep, isLastStep, isMultiStep, loading, values, onSubmit, onNext, onPrev, onCancel, primaryLabel: primaryLabelProp, showBack: showBackProp, backLabel: backLabelProp, onPrimary: onPrimaryProp, }: FormActionsProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
//# sourceMappingURL=FormActions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormActions.d.ts","sourceRoot":"","sources":["../src/FormActions.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAYhD,wBAAgB,WAAW,CAAC,EAC1B,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,MAAW,EACX,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,YAAY,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,GACzB,EAAE,gBAAgB,2CAwDlB"}
|
package/dist/FormActions.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { evaluateCondition } from '@formhaus/core';
|
|
3
|
-
function isActionDisabled(action, values, loading) {
|
|
4
|
-
if (loading)
|
|
5
|
-
return true;
|
|
6
|
-
if (!action?.disabled || action.disabled.length === 0)
|
|
7
|
-
return false;
|
|
8
|
-
return action.disabled.every((c) => evaluateCondition(c, values));
|
|
9
|
-
}
|
|
10
|
-
export function FormActions({ submitAction, backAction, cancelAction, isFirstStep, isLastStep, isMultiStep, loading, values = {}, onSubmit, onNext, onPrev, onCancel, primaryLabel: primaryLabelProp, showBack: showBackProp, backLabel: backLabelProp, onPrimary: onPrimaryProp, }) {
|
|
11
|
-
const showBack = showBackProp ?? (isMultiStep && !isFirstStep && backAction !== false);
|
|
12
|
-
const backLabel = backLabelProp ?? (typeof backAction === 'object' ? (backAction?.label ?? 'Back') : 'Back');
|
|
13
|
-
const primaryLabel = primaryLabelProp ?? (isMultiStep && !isLastStep ? 'Continue' : (submitAction?.label ?? 'Submit'));
|
|
14
|
-
const primaryDisabled = isActionDisabled(isMultiStep && !isLastStep ? undefined : submitAction, values, loading);
|
|
15
|
-
function handlePrimary() {
|
|
16
|
-
if (onPrimaryProp) {
|
|
17
|
-
onPrimaryProp();
|
|
18
|
-
}
|
|
19
|
-
else if (isMultiStep && !isLastStep) {
|
|
20
|
-
onNext();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
onSubmit();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return (_jsxs("div", { className: "fh-form-actions", children: [_jsxs("div", { className: "fh-form-actions__secondary", children: [showBack && (_jsx("button", { type: "button", className: "fh-form-actions__button fh-form-actions__button--text", disabled: loading, onClick: onPrev, children: backLabel })), cancelAction && (_jsx("button", { type: "button", className: "fh-form-actions__button fh-form-actions__button--text", disabled: loading, onClick: onCancel, children: cancelAction.label }))] }), _jsx("button", { type: "button", className: "fh-form-actions__button fh-form-actions__button--primary", disabled: primaryDisabled, "aria-busy": loading, onClick: handlePrimary, children: primaryLabel })] }));
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=FormActions.js.map
|
package/dist/FormActions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormActions.js","sourceRoot":"","sources":["../src/FormActions.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAInD,SAAS,gBAAgB,CACvB,MAA8B,EAC9B,MAA+B,EAC/B,OAAiB;IAEjB,IAAI,OAAO;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACpE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,EAC1B,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,MAAM,GAAG,EAAE,EACX,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,YAAY,EAAE,gBAAgB,EAC9B,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,aAAa,GACP;IACjB,MAAM,QAAQ,GAAG,YAAY,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,IAAI,UAAU,KAAK,KAAK,CAAC,CAAC;IACvF,MAAM,SAAS,GAAG,aAAa,IAAI,CAAC,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7G,MAAM,YAAY,GAAG,gBAAgB,IAAI,CAAC,WAAW,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC;IAEvH,MAAM,eAAe,GAAG,gBAAgB,CACtC,WAAW,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,EACrD,MAAM,EACN,OAAO,CACR,CAAC;IAEF,SAAS,aAAa;QACpB,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,EAAE,CAAC;QAClB,CAAC;aAAM,IAAI,WAAW,IAAI,CAAC,UAAU,EAAE,CAAC;YACtC,MAAM,EAAE,CAAC;QACX,CAAC;aAAM,CAAC;YACN,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAED,OAAO,CACL,eAAK,SAAS,EAAC,iBAAiB,aAC9B,eAAK,SAAS,EAAC,4BAA4B,aACxC,QAAQ,IAAI,CACX,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,uDAAuD,EACjE,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,MAAM,YAEd,SAAS,GACH,CACV,EACA,YAAY,IAAI,CACf,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,uDAAuD,EACjE,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,QAAQ,YAEhB,YAAY,CAAC,KAAK,GACZ,CACV,IACG,EACN,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,0DAA0D,EACpE,QAAQ,EAAE,eAAe,eACd,OAAO,EAClB,OAAO,EAAE,aAAa,YAErB,YAAY,GACN,IACL,CACP,CAAC;AACJ,CAAC"}
|
package/dist/FormField.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { FormField as FormFieldType } from '@formhaus/core';
|
|
2
|
-
import type { FieldComponentMap } from './types';
|
|
3
|
-
interface FormFieldProps {
|
|
4
|
-
field: FormFieldType;
|
|
5
|
-
value: unknown;
|
|
6
|
-
error?: string;
|
|
7
|
-
loading?: boolean;
|
|
8
|
-
disabled?: boolean;
|
|
9
|
-
components?: FieldComponentMap;
|
|
10
|
-
onChange: (value: unknown) => void;
|
|
11
|
-
onBlur: () => void;
|
|
12
|
-
onFocus?: () => void;
|
|
13
|
-
}
|
|
14
|
-
export declare function FormField({ field, value, error, loading, disabled, components, onChange, onBlur, onFocus, }: FormFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=FormField.d.ts.map
|
package/dist/FormField.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.d.ts","sourceRoot":"","sources":["../src/FormField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,SAAS,IAAI,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAWnF,OAAO,KAAK,EAAE,iBAAiB,EAAuB,MAAM,SAAS,CAAC;AAkBtE,UAAU,cAAc;IACtB,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,cAAc,2CAmBhB"}
|
package/dist/FormField.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { CheckboxField } from './fields/CheckboxField';
|
|
3
|
-
import { DateField } from './fields/DateField';
|
|
4
|
-
import { FileField } from './fields/FileField';
|
|
5
|
-
import { MultiselectField } from './fields/MultiselectField';
|
|
6
|
-
import { RadioField } from './fields/RadioField';
|
|
7
|
-
import { SelectField } from './fields/SelectField';
|
|
8
|
-
import { SwitchField } from './fields/SwitchField';
|
|
9
|
-
import { TextField } from './fields/TextField';
|
|
10
|
-
import { TextareaField } from './fields/TextareaField';
|
|
11
|
-
const defaultComponents = {
|
|
12
|
-
text: TextField,
|
|
13
|
-
email: TextField,
|
|
14
|
-
phone: TextField,
|
|
15
|
-
number: TextField,
|
|
16
|
-
password: TextField,
|
|
17
|
-
select: SelectField,
|
|
18
|
-
multiselect: MultiselectField,
|
|
19
|
-
checkbox: CheckboxField,
|
|
20
|
-
radio: RadioField,
|
|
21
|
-
switch: SwitchField,
|
|
22
|
-
file: FileField,
|
|
23
|
-
date: DateField,
|
|
24
|
-
textarea: TextareaField,
|
|
25
|
-
};
|
|
26
|
-
export function FormField({ field, value, error, loading, disabled, components, onChange, onBlur, onFocus, }) {
|
|
27
|
-
const Component = components?.[field.type] ?? defaultComponents[field.type];
|
|
28
|
-
if (!Component) {
|
|
29
|
-
return _jsxs("div", { children: ["Unsupported field type: ", field.type] });
|
|
30
|
-
}
|
|
31
|
-
return (_jsx(Component, { field: field, value: value, error: error, loading: loading, disabled: disabled, onChange: onChange, onBlur: onBlur, onFocus: onFocus }));
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=FormField.js.map
|
package/dist/FormField.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.js","sourceRoot":"","sources":["../src/FormField.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EA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AE,MAAM,EACd,OAAO,EAAE,OAAO,GAChB,CACH,CAAC;AACJ,CAAC"}
|
package/dist/FormRenderer.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { FormRendererProps } from './types';
|
|
2
|
-
export declare function FormRenderer({ schema, initialValues, onSubmit, onCancel, onStepChange, onFieldChange, validators, errors: externalErrors, loading, components, optionsProviders, ActionsComponent, ProgressComponent, onAnalyticsEvent, }: FormRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
//# sourceMappingURL=FormRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../src/FormRenderer.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,UAAU,EACV,MAAM,EAAE,cAAc,EACtB,OAAe,EACf,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,EAAE,iBAAiB,2CAwJnB"}
|
package/dist/FormRenderer.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import { FormActions } from './FormActions';
|
|
4
|
-
import { FormField } from './FormField';
|
|
5
|
-
import { FormStepProgress } from './FormStepProgress';
|
|
6
|
-
import { useFieldOptions } from './hooks/useFieldOptions';
|
|
7
|
-
import { useFormEngine } from './hooks/useFormEngine';
|
|
8
|
-
export function FormRenderer({ schema, initialValues, onSubmit, onCancel, onStepChange, onFieldChange, validators, errors: externalErrors, loading = false, components, optionsProviders, ActionsComponent, ProgressComponent, onAnalyticsEvent, }) {
|
|
9
|
-
const engineOptions = { validators };
|
|
10
|
-
const engine = useFormEngine(schema, initialValues, engineOptions);
|
|
11
|
-
const resolvedOptions = useFieldOptions(engine.visibleFields, engine.values, optionsProviders);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
if (externalErrors) {
|
|
14
|
-
engine.setErrors(externalErrors);
|
|
15
|
-
}
|
|
16
|
-
}, [externalErrors, engine]);
|
|
17
|
-
function handleFieldUpdate(key, value) {
|
|
18
|
-
engine.setValue(key, value);
|
|
19
|
-
onFieldChange?.(key, value, engine.values);
|
|
20
|
-
}
|
|
21
|
-
function handleFieldFocus(key) {
|
|
22
|
-
onAnalyticsEvent?.({ type: 'field_focused', fieldKey: key });
|
|
23
|
-
}
|
|
24
|
-
function handleFieldBlur(key) {
|
|
25
|
-
onAnalyticsEvent?.({
|
|
26
|
-
type: 'field_blurred',
|
|
27
|
-
fieldKey: key,
|
|
28
|
-
hasValue: engine.values[key] !== undefined && engine.values[key] !== '',
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function handleSubmit(e) {
|
|
32
|
-
e.preventDefault();
|
|
33
|
-
const allErrors = engine.validate();
|
|
34
|
-
for (const [key, msg] of Object.entries(allErrors)) {
|
|
35
|
-
onAnalyticsEvent?.({ type: 'field_error', fieldKey: key, error: msg });
|
|
36
|
-
}
|
|
37
|
-
if (Object.keys(allErrors).length > 0)
|
|
38
|
-
return;
|
|
39
|
-
const submitValues = engine.getSubmitValues();
|
|
40
|
-
onAnalyticsEvent?.({ type: 'form_submitted', fieldCount: Object.keys(submitValues).length });
|
|
41
|
-
onSubmit(submitValues);
|
|
42
|
-
}
|
|
43
|
-
function handleNext() {
|
|
44
|
-
const prevStep = engine.currentStep;
|
|
45
|
-
const success = engine.nextStep();
|
|
46
|
-
if (success) {
|
|
47
|
-
if (prevStep) {
|
|
48
|
-
onAnalyticsEvent?.({ type: 'step_completed', stepId: prevStep.id });
|
|
49
|
-
}
|
|
50
|
-
if (engine.currentStep) {
|
|
51
|
-
onStepChange?.(engine.currentStep.id, 'next');
|
|
52
|
-
onAnalyticsEvent?.({
|
|
53
|
-
type: 'step_viewed',
|
|
54
|
-
stepId: engine.currentStep.id,
|
|
55
|
-
stepIndex: engine.currentStepIndex,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function handlePrev() {
|
|
61
|
-
engine.prevStep();
|
|
62
|
-
if (engine.currentStep) {
|
|
63
|
-
onStepChange?.(engine.currentStep.id, 'back');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function handleCancel() {
|
|
67
|
-
onCancel?.();
|
|
68
|
-
}
|
|
69
|
-
const ProgressComp = ProgressComponent ?? FormStepProgress;
|
|
70
|
-
const ActionsComp = ActionsComponent ?? FormActions;
|
|
71
|
-
const effectiveIsLastStep = engine.isLastStep || !engine.isMultiStep;
|
|
72
|
-
const computedPrimaryLabel = engine.isMultiStep && !effectiveIsLastStep
|
|
73
|
-
? (engine.currentStep?.next?.label ?? 'Continue')
|
|
74
|
-
: (schema.submit?.label ?? 'Submit');
|
|
75
|
-
const computedShowBack = engine.isMultiStep && !engine.isFirstStep && engine.currentStep?.back !== false;
|
|
76
|
-
const computedBackLabel = typeof engine.currentStep?.back === 'object'
|
|
77
|
-
? (engine.currentStep.back.label ?? 'Back')
|
|
78
|
-
: 'Back';
|
|
79
|
-
function handlePrimary() {
|
|
80
|
-
if (engine.isMultiStep && !effectiveIsLastStep) {
|
|
81
|
-
handleNext();
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
handleSubmit({ preventDefault: () => { } });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return (_jsxs("form", { className: "fh-form", onSubmit: handleSubmit, children: [engine.isMultiStep && (_jsx(ProgressComp, { current: engine.progress.current, total: engine.progress.total, stepTitle: engine.currentStep?.title, stepDescription: engine.currentStep?.description })), _jsx("div", { className: "fh-form__fields", children: engine.visibleFields.map((field) => {
|
|
88
|
-
const fieldWithOptions = resolvedOptions[field.key]
|
|
89
|
-
? { ...field, options: resolvedOptions[field.key] }
|
|
90
|
-
: field;
|
|
91
|
-
return (_jsx(FormField, { field: fieldWithOptions, value: engine.values[field.key], error: engine.errors[field.key], loading: engine.fieldLoading[field.key], disabled: loading, components: components, onChange: (v) => handleFieldUpdate(field.key, v), onBlur: () => handleFieldBlur(field.key), onFocus: () => handleFieldFocus(field.key) }, field.key));
|
|
92
|
-
}) }), engine.topLevelErrors.length > 0 && (_jsx("div", { className: "fh-form__top-errors", children: engine.topLevelErrors.map((error) => (_jsx("p", { className: "fh-form__top-error", children: error }, error))) })), _jsx(ActionsComp, { submitAction: schema.submit, backAction: engine.currentStep?.back, cancelAction: schema.cancel, isFirstStep: engine.isFirstStep, isLastStep: effectiveIsLastStep, isMultiStep: engine.isMultiStep, loading: loading, values: engine.values, onSubmit: () => handleSubmit({ preventDefault: () => { } }), onNext: handleNext, onPrev: handlePrev, onCancel: handleCancel, primaryLabel: computedPrimaryLabel, showBack: computedShowBack, backLabel: computedBackLabel, onPrimary: handlePrimary })] }));
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=FormRenderer.js.map
|
package/dist/FormRenderer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormRenderer.js","sourceRoot":"","sources":["../src/FormRenderer.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGtD,MAAM,UAAU,YAAY,CAAC,EAC3B,MAAM,EACN,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,aAAa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AAC,IAAI,CACnC,cAAK,SAAS,EAAC,qBAAqB,YACjC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CACpC,YAAe,SAAS,EAAC,oBAAoB,YAC1C,KAAK,IADA,KAAK,CAET,CACL,CAAC,GACE,CACP,EAED,KAAC,WAAW,IACV,YAAY,EAAE,MAAM,CAAC,MAAM,EAC3B,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE,IAAI,EACpC,YAAY,EAAE,MAAM,CAAC,MAAM,EAC3B,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,UAAU,EAAE,mBAAmB,EAC/B,WAAW,EAAE,MAAM,CAAC,WAAW,EAC/B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,QAAQ,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC,EAAqB,CAAC,EAC7E,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,oBAAoB,EAClC,QAAQ,EAAE,gBAAgB,EAC1B,SAAS,EAAE,iBAAiB,EAC5B,SAAS,EAAE,aAAa,GACxB,IACG,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormStepProgress.d.ts","sourceRoot":"","sources":["../src/FormStepProgress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,wBAAgB,gBAAgB,CAAC,EAC/B,OAAO,EACP,KAAK,EACL,SAAS,EACT,eAAe,GAChB,EAAE,qBAAqB,2CAiBvB"}
|
package/dist/FormStepProgress.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function FormStepProgress({ current, total, stepTitle, stepDescription, }) {
|
|
3
|
-
const percent = (current / total) * 100;
|
|
4
|
-
return (_jsxs("div", { className: "fh-step-progress", children: [_jsx("div", { className: "fh-step-progress__bar", children: _jsx("div", { className: "fh-step-progress__fill", style: { width: `${percent}%` } }) }), _jsx("div", { className: "fh-step-progress__info", children: _jsxs("span", { className: "fh-step-progress__counter", children: ["Step ", current, " of ", total] }) }), stepTitle && _jsx("h3", { className: "fh-step-progress__title", children: stepTitle }), stepDescription && _jsx("p", { className: "fh-step-progress__description", children: stepDescription })] }));
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=FormStepProgress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormStepProgress.js","sourceRoot":"","sources":["../src/FormStepProgress.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,gBAAgB,CAAC,EAC/B,OAAO,EACP,KAAK,EACL,SAAS,EACT,eAAe,GACO;IACtB,MAAM,OAAO,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;IAExC,OAAO,CACL,eAAK,SAAS,EAAC,kBAAkB,aAC/B,cAAK,SAAS,EAAC,uBAAuB,YACpC,cAAK,SAAS,EAAC,wBAAwB,EAAC,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,GAAG,EAAE,GAAI,GACvE,EACN,cAAK,SAAS,EAAC,wBAAwB,YACrC,gBAAM,SAAS,EAAC,2BAA2B,sBACnC,OAAO,UAAM,KAAK,IACnB,GACH,EACL,SAAS,IAAI,aAAI,SAAS,EAAC,yBAAyB,YAAE,SAAS,GAAM,EACrE,eAAe,IAAI,YAAG,SAAS,EAAC,+BAA+B,YAAE,eAAe,GAAK,IAClF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxField.d.ts","sourceRoot":"","sources":["../../src/fields/CheckboxField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAuCrB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function CheckboxField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const inputId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
return (_jsxs("div", { className: "fh-field fh-field--checkbox", children: [_jsxs("div", { className: "fh-field__checkbox-wrapper", children: [_jsx("input", { id: inputId, type: "checkbox", className: "fh-field__checkbox", checked: !!value, disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: (e) => onChange(e.target.checked), onBlur: onBlur, onFocus: onFocus }), field.label && (_jsx("label", { className: "fh-field__label", htmlFor: inputId, children: field.label }))] }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=CheckboxField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxField.js","sourceRoot":"","sources":["../../src/fields/CheckboxField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,aAAa,CAAC,EAC5B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAA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AAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAsCrB"}
|
package/dist/fields/DateField.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function DateField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const inputId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
return (_jsxs("div", { className: "fh-field", children: [field.label && (_jsxs("label", { className: "fh-field__label", htmlFor: inputId, children: [field.label, field.validation?.required && _jsx("span", { className: "fh-field__required", "aria-hidden": "true", children: " *" })] })), _jsx("input", { id: inputId, type: "date", className: "fh-field__input fh-field__input--date", value: String(value ?? ''), disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: (e) => onChange(e.target.value), onBlur: onBlur, onFocus: onFocus }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=DateField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../src/fields/DateField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,OAAO,GA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AE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAyCrB"}
|
package/dist/fields/FileField.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function FileField({ field, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const inputId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
return (_jsxs("div", { className: "fh-field", children: [field.label && (_jsxs("label", { className: "fh-field__label", htmlFor: inputId, children: [field.label, field.validation?.required && _jsx("span", { className: "fh-field__required", "aria-hidden": "true", children: " *" })] })), _jsx("input", { id: inputId, type: "file", className: "fh-field__input fh-field__input--file", accept: field.accept, disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: (e) => {
|
|
8
|
-
const files = e.target.files;
|
|
9
|
-
onChange(files && files.length > 0 ? files[0] : null);
|
|
10
|
-
}, onBlur: onBlur, onFocus: onFocus }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=FileField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FileField.js","sourceRoot":"","sources":["../../src/fields/FileField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC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AC,kBAAkB,YAC1C,KAAK,CAAC,UAAU,GACf,CACL,IACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { FieldComponentProps } from '../types';
|
|
2
|
-
export declare function MultiselectField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }: FieldComponentProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
//# sourceMappingURL=MultiselectField.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultiselectField.d.ts","sourceRoot":"","sources":["../../src/fields/MultiselectField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAwDrB"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function MultiselectField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const groupId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
const options = field.options ?? [];
|
|
8
|
-
const selected = Array.isArray(value) ? value : [];
|
|
9
|
-
function handleToggle(optValue) {
|
|
10
|
-
const next = selected.includes(optValue)
|
|
11
|
-
? selected.filter((v) => v !== optValue)
|
|
12
|
-
: [...selected, optValue];
|
|
13
|
-
onChange(next);
|
|
14
|
-
}
|
|
15
|
-
return (_jsxs("fieldset", { className: "fh-field fh-field--multiselect", "aria-invalid": !!error || undefined, "aria-describedby": describedBy, children: [field.label && _jsx("legend", { className: "fh-field__label", children: field.label }), _jsx("div", { className: "fh-field__multiselect-group", children: options.map((opt) => {
|
|
16
|
-
const optionId = `${groupId}-${opt.value}`;
|
|
17
|
-
return (_jsxs("div", { className: "fh-field__multiselect-option", children: [_jsx("input", { id: optionId, type: "checkbox", className: "fh-field__checkbox", checked: selected.includes(opt.value), disabled: disabled || loading, onChange: () => handleToggle(opt.value), onBlur: onBlur, onFocus: onFocus }), _jsx("label", { className: "fh-field__multiselect-label", htmlFor: optionId, children: opt.label })] }, opt.value));
|
|
18
|
-
}) }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=MultiselectField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultiselectField.js","sourceRoot":"","sources":["../../src/fields/MultiselectField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,gBAAgB,CAAC,EAC/B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC;IACrC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAA6B,CAAC,CAAC,CAAC,EAAE,CAAC;IAE5E,SAAS,YAAY,CAAC,QAAgB;QACpC,M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rD,KAAK,GACJ,CACL,EACA,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,IAAI,CAC7B,YAAG,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAC,kBAAkB,YAC1C,KAAK,CAAC,UAAU,GACf,CACL,IACQ,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RadioField.d.ts","sourceRoot":"","sources":["../../src/fields/RadioField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAkDrB"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function RadioField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const groupId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
const options = field.options ?? [];
|
|
8
|
-
return (_jsxs("fieldset", { className: "fh-field fh-field--radio", "aria-invalid": !!error || undefined, "aria-describedby": describedBy, children: [field.label && _jsx("legend", { className: "fh-field__label", children: field.label }), _jsx("div", { className: "fh-field__radio-group", children: options.map((opt) => {
|
|
9
|
-
const optionId = `${groupId}-${opt.value}`;
|
|
10
|
-
return (_jsxs("div", { className: "fh-field__radio-option", children: [_jsx("input", { id: optionId, type: "radio", className: "fh-field__radio", name: groupId, value: opt.value, checked: String(value) === String(opt.value), disabled: disabled || loading, onChange: () => onChange(opt.value), onBlur: onBlur, onFocus: onFocus }), _jsx("label", { className: "fh-field__radio-label", htmlFor: optionId, children: opt.label })] }, opt.value));
|
|
11
|
-
}) }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=RadioField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RadioField.js","sourceRoot":"","sources":["../../src/fields/RadioField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC;IACrC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;IAEpC,OAAO,CACL,oBACE,SAAS,EAAC,0BAA0B,kBACtB,CAAC,CAAC,KAAK,IAAI,SAAS,sBAChB,WAAW,aAE5B,KAAK,CAAC,KAAK,IAAI,iBAAQ,SAAS,EAAC,iBAAiB,YAAE,KAAK,CAAC,KAAK,GAAU,EAC1E,cAAK,SAAS,EAAC,uBAAuB,YACnC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;oBACnB,MAAM,QAAQ,GAAG,GAAG,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;oBAC3C,OAAO,CACL,eAAqB,SAAS,EAAC,wBAAwB,aACrD,gBACE,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,iBAAiB,EAC3B,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,GAAG,CAAC,KAAK,EAChB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAC5C,QAAQ,EAAE,QAAQ,IAAI,OAAO,EAC7B,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,GAChB,EACF,gBAAO,SAAS,EAAC,uBAAuB,EAAC,OAAO,EAAE,QAAQ,YACvD,GAAG,CAAC,KAAK,GACJ,KAfA,GAAG,CAAC,KAAK,CAgBb,CACP,CAAC;gBACJ,CAAC,CAAC,GACE,EACL,KAAK,IAAI,CACR,YAAG,EAAE,EAAE,OAAO,EAAE,SAAS,EAAC,iBAAiB,EAAC,IAAI,EAAC,OAAO,YACrD,KAAK,GACJ,CACL,EACA,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,IAAI,CAC7B,YAAG,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAC,kBAAkB,YAC1C,KAAK,CAAC,UAAU,GACf,CACL,IACQ,CACZ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SelectField.d.ts","sourceRoot":"","sources":["../../src/fields/SelectField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAiDrB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function SelectField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const inputId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
const options = field.options ?? [];
|
|
8
|
-
return (_jsxs("div", { className: "fh-field", children: [field.label && (_jsxs("label", { className: "fh-field__label", htmlFor: inputId, children: [field.label, field.validation?.required && _jsx("span", { className: "fh-field__required", "aria-hidden": "true", children: " *" })] })), _jsxs("select", { id: inputId, className: "fh-field__input fh-field__input--select", value: value ?? '', disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: (e) => onChange(e.target.value), onBlur: onBlur, onFocus: onFocus, children: [field.placeholder && (_jsx("option", { value: "", disabled: true, children: field.placeholder })), options.map((opt) => (_jsx("option", { value: opt.value, children: opt.label }, opt.value)))] }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=SelectField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SelectField.js","sourceRoot":"","sources":["../../src/fields/SelectField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC;IACrC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,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@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchField.d.ts","sourceRoot":"","sources":["../../src/fields/SwitchField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAwCrB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function SwitchField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const inputId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
return (_jsxs("div", { className: "fh-field fh-field--switch", children: [_jsxs("div", { className: "fh-field__switch-wrapper", children: [_jsx("input", { id: inputId, type: "checkbox", role: "switch", className: "fh-field__switch", checked: !!value, disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: (e) => onChange(e.target.checked), onBlur: onBlur, onFocus: onFocus }), field.label && (_jsx("label", { className: "fh-field__label", htmlFor: inputId, children: field.label }))] }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=SwitchField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchField.js","sourceRoot":"","sources":["../../src/fields/SwitchField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,E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
|
-
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../src/fields/TextField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAuDrB"}
|
package/dist/fields/TextField.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function TextField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
3
|
-
const inputId = field.key;
|
|
4
|
-
const helperId = `${field.key}-helper`;
|
|
5
|
-
const errorId = `${field.key}-error`;
|
|
6
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
7
|
-
const handleChange = (e) => {
|
|
8
|
-
const v = e.target.value;
|
|
9
|
-
onChange(field.type === 'number' ? Number(v) : v);
|
|
10
|
-
};
|
|
11
|
-
const inputType = field.type === 'email'
|
|
12
|
-
? 'email'
|
|
13
|
-
: field.type === 'phone'
|
|
14
|
-
? 'tel'
|
|
15
|
-
: field.type === 'number'
|
|
16
|
-
? 'number'
|
|
17
|
-
: field.type === 'password'
|
|
18
|
-
? 'password'
|
|
19
|
-
: 'text';
|
|
20
|
-
return (_jsxs("div", { className: "fh-field", children: [field.label && (_jsxs("label", { className: "fh-field__label", htmlFor: inputId, children: [field.label, field.validation?.required && _jsx("span", { className: "fh-field__required", "aria-hidden": "true", children: " *" })] })), _jsx("input", { id: inputId, type: inputType, className: "fh-field__input", value: value != null ? String(value) : '', placeholder: field.placeholder ?? field.mask, disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: handleChange, onBlur: onBlur, onFocus: onFocus }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=TextField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","sourceRoot":"","sources":["../../src/fields/TextField.tsx"],"names":[],"mappings":";AAEA,MAAM,UAAU,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC;IACrC,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAE9E,MAAM,YAAY,GAAG,CAAC,CAAsC,EAAE,EAAE;QAC9D,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;QACzB,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC;IAEF,MAAM,SAAS,GACb,KAAK,CAAC,IAAI,KAAK,OAAO;QACpB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO;YACtB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ;gBACvB,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU;oBACzB,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,MAAM,CAA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R,EAAE,mBAAmB,2CAuCrB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
const DEFAULT_ROWS = 3;
|
|
3
|
-
export function TextareaField({ field, value, error, loading, disabled, onChange, onBlur, onFocus, }) {
|
|
4
|
-
const inputId = field.key;
|
|
5
|
-
const helperId = `${field.key}-helper`;
|
|
6
|
-
const errorId = `${field.key}-error`;
|
|
7
|
-
const describedBy = error ? errorId : field.helperText ? helperId : undefined;
|
|
8
|
-
return (_jsxs("div", { className: "fh-field", children: [field.label && (_jsxs("label", { className: "fh-field__label", htmlFor: inputId, children: [field.label, field.validation?.required && _jsx("span", { className: "fh-field__required", "aria-hidden": "true", children: " *" })] })), _jsx("textarea", { id: inputId, className: "fh-field__input fh-field__input--textarea", value: value ?? '', placeholder: field.placeholder, rows: field.rows ?? DEFAULT_ROWS, disabled: disabled || loading, "aria-invalid": !!error, "aria-describedby": describedBy, onChange: (e) => onChange(e.target.value), onBlur: onBlur, onFocus: onFocus }), error && (_jsx("p", { id: errorId, className: "fh-field__error", role: "alert", children: error })), !error && field.helperText && (_jsx("p", { id: helperId, className: "fh-field__helper", children: field.helperText }))] }));
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=TextareaField.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextareaField.js","sourceRoot":"","sources":["../../src/fields/TextareaField.tsx"],"names":[],"mappings":";AAEA,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAM,UAAU,aAAa,CAAC,EAC5B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,GACa;IACpB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC;IAC1B,MAAM,QAAQ,GAAG,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvC,MAAM,OAAO,GAAG,GAAG,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
|
-
export declare function useFieldOptions(fields: FormField[], values: Record<string, unknown>, providers?: Record<string, OptionsProvider>): Record<string, FieldOption[]>;
|
|
4
|
-
//# sourceMappingURL=useFieldOptions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldOptions.d.ts","sourceRoot":"","sources":["../../src/hooks/useFieldOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,EAAE,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAC1C,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAuC/B"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
export function useFieldOptions(fields, values, providers) {
|
|
3
|
-
const [resolved, setResolved] = useState({});
|
|
4
|
-
const lastDepsRef = useRef(new Map());
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (!providers)
|
|
7
|
-
return;
|
|
8
|
-
let isStale = false;
|
|
9
|
-
for (const field of fields) {
|
|
10
|
-
if (!field.optionsFrom)
|
|
11
|
-
continue;
|
|
12
|
-
const provider = providers[field.optionsFrom];
|
|
13
|
-
if (!provider)
|
|
14
|
-
continue;
|
|
15
|
-
const depsKey = (field.optionsDependsOn ?? []).map((k) => values[k]).join('|');
|
|
16
|
-
if (lastDepsRef.current.get(field.key) === depsKey)
|
|
17
|
-
continue;
|
|
18
|
-
lastDepsRef.current.set(field.key, depsKey);
|
|
19
|
-
const result = provider(values);
|
|
20
|
-
if (Array.isArray(result)) {
|
|
21
|
-
if (!isStale)
|
|
22
|
-
setResolved((prev) => ({ ...prev, [field.key]: result }));
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
result
|
|
26
|
-
.then((options) => {
|
|
27
|
-
if (!isStale)
|
|
28
|
-
setResolved((prev) => ({ ...prev, [field.key]: options }));
|
|
29
|
-
})
|
|
30
|
-
.catch(() => {
|
|
31
|
-
lastDepsRef.current.delete(field.key);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return () => { isStale = true; };
|
|
36
|
-
}, [fields, values, providers]);
|
|
37
|
-
return resolved;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=useFieldOptions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldOptions.js","sourceRoot":"","sources":["../../src/hooks/useFieldOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGpD,MAAM,UAAU,eAAe,CAC7B,MAAmB,EACnB,MAA+B,EAC/B,SAA2C;IAE3C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAgC,EAAE,CAAC,CAAC;IAC5E,MAAM,WAAW,GAAG,MAAM,CAAsB,IAAI,GAAG,EAAE,CAAC,CAAC;IAE3D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS;YAAE,OAAO;QAEvB,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,WAAW;gBAAE,SAAS;YAEjC,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YAC9C,IAAI,CAAC,QAAQ;gBAAE,SAAS;YAExB,MAAM,OAAO,GAAG,CAAC,KAAK,CAAC,gBAAgB,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,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ngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGrF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,EAClB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,UAAU,CAcZ"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FormEngine } from '@formhaus/core';
|
|
2
|
-
import { useRef, useSyncExternalStore } from 'react';
|
|
3
|
-
export function useFormEngine(schema, initialValues, options) {
|
|
4
|
-
const engineRef = useRef(null);
|
|
5
|
-
const schemaIdRef = useRef(schema.id);
|
|
6
|
-
if (engineRef.current === null || schemaIdRef.current !== schema.id) {
|
|
7
|
-
engineRef.current = new FormEngine(schema, initialValues, options);
|
|
8
|
-
schemaIdRef.current = schema.id;
|
|
9
|
-
}
|
|
10
|
-
const engine = engineRef.current;
|
|
11
|
-
useSyncExternalStore(engine.subscribe.bind(engine), engine.getSnapshot.bind(engine));
|
|
12
|
-
return engine;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=useFormEngine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormEngine.js","sourceRoot":"","sources":["../../src/hooks/useFormEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA2C,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAErD,MAAM,UAAU,aAAa,CAC3B,MAAkB,EAClB,aAAuC,EACvC,OAA2B;IAE3B,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,MAAM,CAAS,MAAM,CAAC,EAAE,CAAC,CAAC;IAE9C,IAAI,SAAS,CAAC,OAAO,KAAK,IAAI,IAAI,WAAW,CAAC,OAAO,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;QACpE,SAAS,CAAC,OAAO,GAAG,IAAI,UAAU,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QACnE,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC;IAClC,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;IAEjC,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAErF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EACV,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { FieldOption, FieldType, FormAction, FormAnalyticsEvent, FormSchema, ValidatorFn } from '@formhaus/core';
|
|
2
|
-
import type { ComponentType } from 'react';
|
|
3
|
-
export type OptionsProvider = (values: Record<string, unknown>) => FieldOption[] | Promise<FieldOption[]>;
|
|
4
|
-
export interface FieldComponentProps {
|
|
5
|
-
field: import('@formhaus/core').FormField;
|
|
6
|
-
value: unknown;
|
|
7
|
-
error?: string;
|
|
8
|
-
loading?: boolean;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
onChange: (value: unknown) => void;
|
|
11
|
-
onBlur: () => void;
|
|
12
|
-
onFocus?: () => void;
|
|
13
|
-
}
|
|
14
|
-
export type FieldComponentMap = Partial<Record<FieldType, ComponentType<FieldComponentProps>>>;
|
|
15
|
-
export interface FormActionsProps {
|
|
16
|
-
submitAction?: FormAction;
|
|
17
|
-
backAction?: FormAction | false;
|
|
18
|
-
cancelAction?: FormAction;
|
|
19
|
-
isFirstStep: boolean;
|
|
20
|
-
isLastStep: boolean;
|
|
21
|
-
isMultiStep: boolean;
|
|
22
|
-
loading?: boolean;
|
|
23
|
-
values?: Record<string, unknown>;
|
|
24
|
-
primaryLabel?: string;
|
|
25
|
-
showBack?: boolean;
|
|
26
|
-
backLabel?: string;
|
|
27
|
-
onSubmit: () => void;
|
|
28
|
-
onNext: () => void;
|
|
29
|
-
onPrev: () => void;
|
|
30
|
-
onCancel: () => void;
|
|
31
|
-
onPrimary?: () => void;
|
|
32
|
-
}
|
|
33
|
-
export interface FormStepProgressProps {
|
|
34
|
-
current: number;
|
|
35
|
-
total: number;
|
|
36
|
-
stepTitle?: string;
|
|
37
|
-
stepDescription?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface FormRendererProps {
|
|
40
|
-
schema: FormSchema;
|
|
41
|
-
initialValues?: Record<string, unknown>;
|
|
42
|
-
onSubmit: (values: Record<string, unknown>) => Promise<void> | void;
|
|
43
|
-
onCancel?: () => void;
|
|
44
|
-
onStepChange?: (stepId: string, direction: 'next' | 'back') => void;
|
|
45
|
-
onFieldChange?: (key: string, value: unknown, allValues: Record<string, unknown>) => void;
|
|
46
|
-
validators?: Record<string, ValidatorFn>;
|
|
47
|
-
errors?: Record<string, string>;
|
|
48
|
-
loading?: boolean;
|
|
49
|
-
components?: FieldComponentMap;
|
|
50
|
-
optionsProviders?: Record<string, OptionsProvider>;
|
|
51
|
-
ActionsComponent?: ComponentType<FormActionsProps>;
|
|
52
|
-
ProgressComponent?: ComponentType<FormStepProgressProps>;
|
|
53
|
-
onAnalyticsEvent?: (event: FormAnalyticsEvent) => void;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACtH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;AAE5C,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,OAAO,gBAAgB,EAAE,SAAS,CAAC;IAC1C,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,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