impact-nova 2.3.0 → 2.4.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/dist/filter-shell/index.d.ts +12 -0
- package/dist/filter-shell/index.js +9 -0
- package/dist/filter-shell/utils/buildFilterFieldValidationRules.d.ts +1 -0
- package/dist/filter-shell/utils/validateVisibleRequiredFilterFields.d.ts +1 -0
- package/dist/filter-shell/utils/validationNavigation.utils.d.ts +26 -0
- package/dist/filter-shell/utils/validationNavigation.utils.js +38 -0
- package/dist/form-engine/field-dependency-graph.d.ts +17 -0
- package/dist/form-engine/field-dependency-graph.js +90 -0
- package/dist/form-engine/index.d.ts +9 -0
- package/dist/form-engine/index.js +16 -0
- package/dist/form-engine/is-empty-value.d.ts +1 -0
- package/dist/form-engine/is-empty-value.js +8 -0
- package/dist/form-engine/types.d.ts +17 -0
- package/dist/form-react/Fields/ButtonsGroupField.d.ts +3 -0
- package/dist/form-react/Fields/ButtonsGroupField.js +52 -0
- package/dist/form-react/Fields/CheckboxField.d.ts +3 -0
- package/dist/form-react/Fields/CheckboxField.js +46 -0
- package/dist/form-react/Fields/ChipsField.d.ts +3 -0
- package/dist/form-react/Fields/ChipsField.js +146 -0
- package/dist/form-react/Fields/DateInputField.d.ts +8 -0
- package/dist/form-react/Fields/DateInputField.js +134 -0
- package/dist/form-react/Fields/DateRangeField.d.ts +8 -0
- package/dist/form-react/Fields/DateRangeField.js +57 -0
- package/dist/form-react/Fields/DividerField.d.ts +3 -0
- package/dist/form-react/Fields/DividerField.js +9 -0
- package/dist/form-react/Fields/DividerWithLabelField.d.ts +3 -0
- package/dist/form-react/Fields/DividerWithLabelField.js +31 -0
- package/dist/form-react/Fields/FileUploadField.d.ts +3 -0
- package/dist/form-react/Fields/FileUploadField.js +42 -0
- package/dist/form-react/Fields/FillFormByFileUploadField.d.ts +3 -0
- package/dist/form-react/Fields/FillFormByFileUploadField.js +65 -0
- package/dist/form-react/Fields/FillFormByPasteField.d.ts +3 -0
- package/dist/form-react/Fields/FillFormByPasteField.js +106 -0
- package/dist/form-react/Fields/LabelField.d.ts +3 -0
- package/dist/form-react/Fields/LabelField.js +14 -0
- package/dist/form-react/Fields/MonthRangeField.d.ts +8 -0
- package/dist/form-react/Fields/MonthRangeField.js +72 -0
- package/dist/form-react/Fields/MultiMonthPickerField.d.ts +8 -0
- package/dist/form-react/Fields/MultiMonthPickerField.js +46 -0
- package/dist/form-react/Fields/MultiWeekPickerField.d.ts +8 -0
- package/dist/form-react/Fields/MultiWeekPickerField.js +47 -0
- package/dist/form-react/Fields/NumericComboboxField.d.ts +18 -0
- package/dist/form-react/Fields/NumericComboboxField.js +51 -0
- package/dist/form-react/Fields/RadioField.d.ts +3 -0
- package/dist/form-react/Fields/RadioField.js +68 -0
- package/dist/form-react/Fields/SelectField.d.ts +3 -0
- package/dist/form-react/Fields/SelectField.js +76 -0
- package/dist/form-react/Fields/SwitchField.d.ts +3 -0
- package/dist/form-react/Fields/SwitchField.js +47 -0
- package/dist/form-react/Fields/TextAreaField.d.ts +3 -0
- package/dist/form-react/Fields/TextAreaField.js +41 -0
- package/dist/form-react/Fields/TextField.d.ts +3 -0
- package/dist/form-react/Fields/TextField.js +75 -0
- package/dist/form-react/Fields/TextFieldWithBackendValidation.d.ts +3 -0
- package/dist/form-react/Fields/TextFieldWithBackendValidation.js +117 -0
- package/dist/form-react/Fields/WeekRangePicker.d.ts +8 -0
- package/dist/form-react/Fields/WeekRangePicker.js +71 -0
- package/dist/form-react/ReactHooksForm.d.ts +3 -0
- package/dist/form-react/ReactHooksForm.js +132 -0
- package/dist/form-react/components/ArrayFieldRenderer.d.ts +13 -0
- package/dist/form-react/components/ArrayFieldRenderer.js +90 -0
- package/dist/form-react/components/FieldRenderer.d.ts +16 -0
- package/dist/form-react/components/FieldRenderer.js +68 -0
- package/dist/form-react/components/FormFieldRow.d.ts +13 -0
- package/dist/form-react/components/FormFieldRow.js +47 -0
- package/dist/form-react/components/FormFileUploadWrapper.d.ts +22 -0
- package/dist/form-react/components/FormFileUploadWrapper.js +88 -0
- package/dist/form-react/components/ObjectFieldRenderer.d.ts +13 -0
- package/dist/form-react/components/ObjectFieldRenderer.js +46 -0
- package/dist/form-react/components/SetToEmptyWrapper.d.ts +16 -0
- package/dist/form-react/components/SetToEmptyWrapper.js +49 -0
- package/dist/form-react/fields.d.ts +23 -0
- package/dist/form-react/fields.js +40 -0
- package/dist/form-react/hooks/useCascadingForm.d.ts +17 -0
- package/dist/form-react/hooks/useCascadingForm.js +122 -0
- package/dist/form-react/hooks/useFieldVisibility.d.ts +14 -0
- package/dist/form-react/hooks/useFieldVisibility.js +60 -0
- package/dist/form-react/hooks/useFillFormByFileUpload.d.ts +33 -0
- package/dist/form-react/hooks/useFillFormByFileUpload.js +199 -0
- package/dist/form-react/hooks/useFillFormByPaste.d.ts +33 -0
- package/dist/form-react/hooks/useFillFormByPaste.js +104 -0
- package/dist/form-react/hooks/useFormFieldChangeSubscription.d.ts +13 -0
- package/dist/form-react/hooks/useFormFieldChangeSubscription.js +42 -0
- package/dist/form-react/hooks/useReactHookForm.d.ts +3 -0
- package/dist/form-react/hooks/useReactHookForm.js +161 -0
- package/dist/form-react/hooks/useSelectOptions.d.ts +8 -0
- package/dist/form-react/hooks/useSelectOptions.js +116 -0
- package/dist/form-react/index.d.ts +62 -0
- package/dist/form-react/index.js +97 -0
- package/dist/form-react/registry/defaultFieldRegistrations.d.ts +2 -0
- package/dist/form-react/registry/defaultFieldRegistrations.js +30 -0
- package/dist/form-react/registry/fieldRegistry.d.ts +14 -0
- package/dist/form-react/registry/fieldRegistry.js +19 -0
- package/dist/form-react/registry/resolveFieldComponent.d.ts +10 -0
- package/dist/form-react/registry/resolveFieldComponent.js +137 -0
- package/dist/form-react/types/fields.types.d.ts +402 -0
- package/dist/form-react/types/fieldsOutput.types.d.ts +73 -0
- package/dist/form-react/types/reactHookForm.types.d.ts +196 -0
- package/dist/form-react/utils/batchFormFieldUpdates.d.ts +14 -0
- package/dist/form-react/utils/batchFormFieldUpdates.js +13 -0
- package/dist/form-react/utils/buildFieldValidationRules.d.ts +6 -0
- package/dist/form-react/utils/buildFieldValidationRules.js +13 -0
- package/dist/form-react/utils/buildSelectRemountKey.d.ts +14 -0
- package/dist/form-react/utils/buildSelectRemountKey.js +14 -0
- package/dist/form-react/utils/calendar-boundary.d.ts +3 -0
- package/dist/form-react/utils/calendar-boundary.js +33 -0
- package/dist/form-react/utils/date.utils.d.ts +31 -0
- package/dist/form-react/utils/date.utils.js +86 -0
- package/dist/form-react/utils/evaluateFieldValidation.d.ts +19 -0
- package/dist/form-react/utils/evaluateFieldValidation.js +53 -0
- package/dist/form-react/utils/fieldDefaults.utils.d.ts +6 -0
- package/dist/form-react/utils/fieldDefaults.utils.js +25 -0
- package/dist/form-react/utils/fieldPath.utils.d.ts +23 -0
- package/dist/form-react/utils/fieldPath.utils.js +26 -0
- package/dist/form-react/utils/fieldRangeValidation.utils.d.ts +3 -0
- package/dist/form-react/utils/fieldRangeValidation.utils.js +24 -0
- package/dist/form-react/utils/fieldRendererUtils.d.ts +10 -0
- package/dist/form-react/utils/fieldRendererUtils.js +47 -0
- package/dist/form-react/utils/fieldTestIds.d.ts +3 -0
- package/dist/form-react/utils/fieldTestIds.js +13 -0
- package/dist/form-react/utils/formDate.utils.d.ts +13 -0
- package/dist/form-react/utils/formDate.utils.js +9 -0
- package/dist/form-react/utils/formValidationFeedback.utils.d.ts +32 -0
- package/dist/form-react/utils/formValidationFeedback.utils.js +153 -0
- package/dist/form-react/utils/icons.d.ts +5 -0
- package/dist/form-react/utils/icons.js +10 -0
- package/dist/form-react/utils/optionFlag.d.ts +11 -0
- package/dist/form-react/utils/optionFlag.js +17 -0
- package/dist/form-react/utils/pastedValues.d.ts +1 -0
- package/dist/form-react/utils/resolveFormSubmittable.d.ts +18 -0
- package/dist/form-react/utils/resolveFormSubmittable.js +32 -0
- package/dist/form-react/utils/select-option-filter-values.d.ts +5 -0
- package/dist/form-react/utils/select-option-filter-values.js +30 -0
- package/dist/form-react/utils/serializeFormStateForQueryKey.d.ts +1 -0
- package/dist/form-react/utils/serializeFormStateForQueryKey.js +21 -0
- package/dist/form-react/utils/stableSerialize.d.ts +5 -0
- package/dist/form-react/utils/stableSerialize.js +11 -0
- package/dist/form-react/utils/validateVisibleRequiredFormFields.d.ts +21 -0
- package/dist/form-react/utils/validateVisibleRequiredFormFields.js +64 -0
- package/dist/form-react/utils/validationUtils.d.ts +3 -0
- package/dist/form-react/utils/validationUtils.js +77 -0
- package/dist/impact-nova.css +1 -1
- package/dist/lib/primitives/use-field-chrome.js +16 -16
- package/dist/llms/rules/installation.js +1 -1
- package/dist/llms/rules/real-world-patterns.js +1 -1
- package/dist/llms/rules/requirements.js +1 -1
- package/package.json +21 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as a, jsxs as s } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as b } from "react";
|
|
3
|
+
import { Controller as h } from "react-hook-form";
|
|
4
|
+
import { RadioGroup as p, RadioGroupItem as v } from "../../components/forms/radio-group/radio-group.js";
|
|
5
|
+
import { getTestId as d, getFieldTestId as g } from "../utils/fieldTestIds.js";
|
|
6
|
+
const R = ({
|
|
7
|
+
field: e,
|
|
8
|
+
formHelpers: n,
|
|
9
|
+
validationRules: m,
|
|
10
|
+
isDisabled: c
|
|
11
|
+
}) => {
|
|
12
|
+
const l = e.fieldType === "radio" ? e : null, u = b(() => l ? l.options?.map((r) => ({
|
|
13
|
+
label: r.label,
|
|
14
|
+
value: r.value,
|
|
15
|
+
disabled: r.isDisabled ?? !1
|
|
16
|
+
})) || [] : [], [l]);
|
|
17
|
+
return l ? /* @__PURE__ */ a(
|
|
18
|
+
h,
|
|
19
|
+
{
|
|
20
|
+
name: e.id,
|
|
21
|
+
control: n.form.control,
|
|
22
|
+
rules: m,
|
|
23
|
+
render: ({ field: r, fieldState: i }) => {
|
|
24
|
+
const o = !!i.error, x = r.value;
|
|
25
|
+
return /* @__PURE__ */ s("div", { className: "flex flex-col gap-1", "data-testid": g(e.id), children: [
|
|
26
|
+
e.label && /* @__PURE__ */ s("label", { className: "block text-xs font-medium mb-2 text-[#60697d]", "data-testid": d("field-label", e.id), children: [
|
|
27
|
+
e.label,
|
|
28
|
+
e.isRequired && /* @__PURE__ */ a("span", { className: "text-destructive ml-1", children: "*" })
|
|
29
|
+
] }),
|
|
30
|
+
/* @__PURE__ */ a("div", { "data-testid": d("radio-group", e.id), children: /* @__PURE__ */ a(
|
|
31
|
+
p,
|
|
32
|
+
{
|
|
33
|
+
orientation: l?.orientation === "row" ? "horizontal" : "vertical",
|
|
34
|
+
value: x,
|
|
35
|
+
onValueChange: (t) => {
|
|
36
|
+
r.onChange(t), r.onBlur();
|
|
37
|
+
},
|
|
38
|
+
disabled: c,
|
|
39
|
+
children: u.map((t) => /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
|
|
40
|
+
/* @__PURE__ */ a(
|
|
41
|
+
v,
|
|
42
|
+
{
|
|
43
|
+
value: t.value,
|
|
44
|
+
id: `${e.id}-${t.value}`,
|
|
45
|
+
disabled: t.disabled
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
/* @__PURE__ */ a(
|
|
49
|
+
"label",
|
|
50
|
+
{
|
|
51
|
+
htmlFor: `${e.id}-${t.value}`,
|
|
52
|
+
className: `text-sm font-medium leading-[14px] cursor-pointer text-[#60697D] peer-data-[state=checked]:text-[#0D152C] ${t.disabled ? "text-disabled-text cursor-not-allowed peer-disabled:opacity-100" : ""}`,
|
|
53
|
+
children: t.label
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
] }, t.value))
|
|
57
|
+
}
|
|
58
|
+
) }),
|
|
59
|
+
o && /* @__PURE__ */ a("p", { className: "text-destructive text-sm mt-1", children: i?.error?.message }),
|
|
60
|
+
e.helpText && !o && /* @__PURE__ */ a("p", { className: "text-content-secondary text-sm mt-1", children: e.helpText })
|
|
61
|
+
] });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
) : null;
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
R as RadioField
|
|
68
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import { useState as M } from "react";
|
|
3
|
+
import { Controller as f } from "react-hook-form";
|
|
4
|
+
import { Select as x } from "../../components/forms/select/select.js";
|
|
5
|
+
import { useSelectOptions as E } from "../hooks/useSelectOptions.js";
|
|
6
|
+
import { getFieldTestId as R } from "../utils/fieldTestIds.js";
|
|
7
|
+
import { isEmptyValue as T } from "../../form-engine/is-empty-value.js";
|
|
8
|
+
const F = ({
|
|
9
|
+
field: e,
|
|
10
|
+
validationRules: p,
|
|
11
|
+
isDisabled: m,
|
|
12
|
+
formHelpers: l,
|
|
13
|
+
formConfig: u,
|
|
14
|
+
supportedValues: d
|
|
15
|
+
}) => {
|
|
16
|
+
const t = e.fieldType === "select" ? e : null, [S, s] = M(!1), h = l.form.control, b = d?.[e.id], { options: g, isLoading: O, error: y, refetch: C } = E({
|
|
17
|
+
apiConfig: t?.apiConfig,
|
|
18
|
+
formHelpers: l,
|
|
19
|
+
formConfig: u,
|
|
20
|
+
initialOptions: t?.options,
|
|
21
|
+
id: e.id,
|
|
22
|
+
isEnabled: S,
|
|
23
|
+
getSelectOptionsName: t?.getSelectOptionsName,
|
|
24
|
+
fieldSupportedValues: b
|
|
25
|
+
});
|
|
26
|
+
return t ? /* @__PURE__ */ c(
|
|
27
|
+
f,
|
|
28
|
+
{
|
|
29
|
+
name: e.id,
|
|
30
|
+
control: h,
|
|
31
|
+
rules: p,
|
|
32
|
+
render: ({ field: o, fieldState: n }) => {
|
|
33
|
+
const a = !!n.error, i = o.value, A = t?.isMultiSelect ? e.id : `${e.id}-${T(i) ? "empty" : "has-value"}`;
|
|
34
|
+
return /* @__PURE__ */ c(
|
|
35
|
+
x,
|
|
36
|
+
{
|
|
37
|
+
id: e.id,
|
|
38
|
+
label: e.label,
|
|
39
|
+
placeholder: e?.placeholder,
|
|
40
|
+
required: e.isRequired,
|
|
41
|
+
isReadOnly: e.isFieldReadonly,
|
|
42
|
+
disabled: m,
|
|
43
|
+
options: g,
|
|
44
|
+
maxSelectableOptions: t?.maxSelectLimit,
|
|
45
|
+
value: t?.isMultiSelect ? i ?? [] : i?.[0],
|
|
46
|
+
onChange: (r) => {
|
|
47
|
+
t?.isMultiSelect ? o.onChange(
|
|
48
|
+
Array.isArray(r) ? r : []
|
|
49
|
+
) : r == null ? o.onChange([]) : o.onChange(
|
|
50
|
+
Array.isArray(r) ? r : [r]
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
isSearchable: !t?.disableOptionSearch,
|
|
54
|
+
isClearable: !t?.disableClearAll,
|
|
55
|
+
multiple: t?.isMultiSelect,
|
|
56
|
+
isSelectAllEnabled: !t?.disableSelectAll,
|
|
57
|
+
labelOrientation: t?.labelOrientation || "top",
|
|
58
|
+
error: a,
|
|
59
|
+
helperText: a ? n.error?.message : e.helpText,
|
|
60
|
+
ignoreAccents: !0,
|
|
61
|
+
isLoading: O,
|
|
62
|
+
fetchError: y,
|
|
63
|
+
onRefetch: C,
|
|
64
|
+
onMenuOpen: () => s(!0),
|
|
65
|
+
onMenuClose: () => s(!1),
|
|
66
|
+
"data-testid": R(e.id)
|
|
67
|
+
},
|
|
68
|
+
A
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
) : null;
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
F as SelectField
|
|
76
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as l, jsxs as a } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Controller as h } from "react-hook-form";
|
|
4
|
+
import { Switch as d } from "../../components/forms/switch/switch.js";
|
|
5
|
+
const f = ({
|
|
6
|
+
field: e,
|
|
7
|
+
validationRules: r,
|
|
8
|
+
isDisabled: c,
|
|
9
|
+
formHelpers: n
|
|
10
|
+
}) => {
|
|
11
|
+
const t = e.fieldType === "switch" ? e : null;
|
|
12
|
+
return t ? /* @__PURE__ */ l(
|
|
13
|
+
h,
|
|
14
|
+
{
|
|
15
|
+
name: e.id,
|
|
16
|
+
control: n.form.control,
|
|
17
|
+
rules: r,
|
|
18
|
+
render: ({ field: s }) => {
|
|
19
|
+
const i = !!(s.value ?? !1), m = e.label ?? t.rightLabel ?? t.leftLabel ?? e.id;
|
|
20
|
+
return /* @__PURE__ */ a("div", { className: e.className || "", children: [
|
|
21
|
+
e.label ? /* @__PURE__ */ a("label", { className: "block text-xs font-medium mb-2 text-[#60697d]", children: [
|
|
22
|
+
e.label,
|
|
23
|
+
e.isRequired && /* @__PURE__ */ l("span", { className: "text-destructive ml-1", children: "*" })
|
|
24
|
+
] }) : null,
|
|
25
|
+
/* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
|
|
26
|
+
t.leftLabel && /* @__PURE__ */ l("span", { className: "text-sm font-medium text-[#111827]", children: t.leftLabel }),
|
|
27
|
+
/* @__PURE__ */ l(
|
|
28
|
+
d,
|
|
29
|
+
{
|
|
30
|
+
"aria-label": m,
|
|
31
|
+
checked: i,
|
|
32
|
+
onCheckedChange: (o) => {
|
|
33
|
+
s.onChange(o);
|
|
34
|
+
},
|
|
35
|
+
disabled: c
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
t.rightLabel && /* @__PURE__ */ l("span", { className: "text-sm font-medium text-[#111827]", children: t.rightLabel })
|
|
39
|
+
] })
|
|
40
|
+
] });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
) : null;
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
f as SwitchField
|
|
47
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { Controller as h } from "react-hook-form";
|
|
4
|
+
import { Textarea as p } from "../../components/forms/textarea/textarea.js";
|
|
5
|
+
const T = ({
|
|
6
|
+
field: r,
|
|
7
|
+
formHelpers: n,
|
|
8
|
+
validationRules: m,
|
|
9
|
+
isDisabled: o
|
|
10
|
+
}) => {
|
|
11
|
+
const t = r.fieldType === "text_area" ? r : null;
|
|
12
|
+
return t ? /* @__PURE__ */ e(
|
|
13
|
+
h,
|
|
14
|
+
{
|
|
15
|
+
name: r.id,
|
|
16
|
+
control: n.form.control,
|
|
17
|
+
disabled: o,
|
|
18
|
+
rules: m,
|
|
19
|
+
render: ({ field: a, fieldState: l }) => {
|
|
20
|
+
const u = !!l.error, c = a.value;
|
|
21
|
+
return /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
|
|
22
|
+
p,
|
|
23
|
+
{
|
|
24
|
+
label: r.label,
|
|
25
|
+
value: c ?? void 0,
|
|
26
|
+
onChange: (i) => a.onChange(i.target.value),
|
|
27
|
+
placeholder: r.placeholder,
|
|
28
|
+
characterLimit: t.characterLimit,
|
|
29
|
+
disabled: o,
|
|
30
|
+
required: r.isRequired,
|
|
31
|
+
error: u,
|
|
32
|
+
helperText: l.error?.message || r.helpText
|
|
33
|
+
}
|
|
34
|
+
) });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
) : null;
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
T as TextAreaField
|
|
41
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as y, useEffect as b } from "react";
|
|
3
|
+
import { useWatch as V, Controller as w } from "react-hook-form";
|
|
4
|
+
import { SmartInput as x } from "../../components/forms/smart-input/smart-input.js";
|
|
5
|
+
import { readOptionFlag as d } from "../utils/optionFlag.js";
|
|
6
|
+
const T = ({
|
|
7
|
+
field: e,
|
|
8
|
+
validationRules: u,
|
|
9
|
+
isDisabled: i,
|
|
10
|
+
formHelpers: r
|
|
11
|
+
}) => {
|
|
12
|
+
const a = e.fieldType === "text" ? e : null, n = a?.allowNegativeDependency, l = !!n, c = !!a?.nonNegative, p = V({
|
|
13
|
+
control: r.form.control,
|
|
14
|
+
name: n?.fieldId ?? "",
|
|
15
|
+
disabled: !l
|
|
16
|
+
}), f = !c || l && d(
|
|
17
|
+
r.form.getValues(n.fieldId),
|
|
18
|
+
n.optionFlag
|
|
19
|
+
), s = y(!0);
|
|
20
|
+
return b(() => {
|
|
21
|
+
if (!l) return;
|
|
22
|
+
if (s.current) {
|
|
23
|
+
s.current = !1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const t = r.form.getValues(e.id);
|
|
27
|
+
t != null && String(t).trim() !== "" && r.form.trigger(e.id);
|
|
28
|
+
}, [l, p, e.id, r.form]), a ? /* @__PURE__ */ m(
|
|
29
|
+
w,
|
|
30
|
+
{
|
|
31
|
+
name: e.id,
|
|
32
|
+
control: r.form.control,
|
|
33
|
+
rules: {
|
|
34
|
+
...u,
|
|
35
|
+
validate: (t) => {
|
|
36
|
+
if (typeof u.validate == "function") {
|
|
37
|
+
const o = u.validate(
|
|
38
|
+
t,
|
|
39
|
+
r.form.getValues()
|
|
40
|
+
);
|
|
41
|
+
if (o !== !0) return o;
|
|
42
|
+
}
|
|
43
|
+
return c && l && !d(
|
|
44
|
+
r.form.getValues(n.fieldId),
|
|
45
|
+
n.optionFlag
|
|
46
|
+
) && typeof t == "string" && Number(t) < 0 ? `${e.label || "Value"} must be a non-negative number` : !0;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
render: ({ field: t, fieldState: o }) => {
|
|
50
|
+
const g = !!o.error, h = t.value;
|
|
51
|
+
return /* @__PURE__ */ m(
|
|
52
|
+
x,
|
|
53
|
+
{
|
|
54
|
+
name: e.id,
|
|
55
|
+
label: e.label,
|
|
56
|
+
type: a.type,
|
|
57
|
+
value: h ?? void 0,
|
|
58
|
+
onChange: (v) => t.onChange(v),
|
|
59
|
+
onBlur: t.onBlur,
|
|
60
|
+
placeholder: e.placeholder,
|
|
61
|
+
required: e.isRequired && !i,
|
|
62
|
+
disabled: i,
|
|
63
|
+
error: g,
|
|
64
|
+
helperText: g ? o?.error?.message : e?.helpText,
|
|
65
|
+
allowNegative: f,
|
|
66
|
+
allowDecimal: a.allowDecimal ?? !0
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
) : null;
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
T as TextField
|
|
75
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { jsx as m, jsxs as T } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as p, useState as C } from "react";
|
|
3
|
+
import { Controller as k } from "react-hook-form";
|
|
4
|
+
import { SmartInput as I } from "../../components/forms/smart-input/smart-input.js";
|
|
5
|
+
const B = ({
|
|
6
|
+
field: e,
|
|
7
|
+
validationRules: g,
|
|
8
|
+
isDisabled: x,
|
|
9
|
+
formHelpers: t
|
|
10
|
+
}) => {
|
|
11
|
+
const i = e.fieldType === "text_with_backend_validation" ? e : null, o = p(!1), l = p(null), [h, f] = C(!1), v = async (r) => {
|
|
12
|
+
if (i?.validationConfig?.omitValidation?.includes(
|
|
13
|
+
e.id
|
|
14
|
+
)) {
|
|
15
|
+
o.current = !1, l.current = null, await t.form.trigger(e.id);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!(!r || r.trim() === "")) {
|
|
19
|
+
f(!0);
|
|
20
|
+
try {
|
|
21
|
+
const n = e.handlerName ? t.formContext?.functions?.[e.handlerName] : void 0;
|
|
22
|
+
let a;
|
|
23
|
+
if (n) {
|
|
24
|
+
const d = i?.validationConfig?.fieldValuesToIncludeInApiRequest || [], s = d.length > 0 ? d.reduce(
|
|
25
|
+
(u, c) => (u[c] = t.form.getValues(c), u),
|
|
26
|
+
{}
|
|
27
|
+
) : {};
|
|
28
|
+
a = await n({
|
|
29
|
+
formHelpers: t,
|
|
30
|
+
fieldId: e.id,
|
|
31
|
+
newValue: r,
|
|
32
|
+
oldValue: t.getPreviousFieldValue(e.id),
|
|
33
|
+
payload: { includedFieldValues: s }
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
if (!i?.validationConfig)
|
|
37
|
+
throw new Error("Validation config is required");
|
|
38
|
+
const d = i.validationConfig.method || "POST", s = i.validationConfig.fieldValuesToIncludeInApiRequest || [], u = s.length > 0 ? s.reduce(
|
|
39
|
+
(V, w) => (V[w] = t.form.getValues(w), V),
|
|
40
|
+
{}
|
|
41
|
+
) : {}, c = i.validationConfig.apiEndpoint;
|
|
42
|
+
if (!c)
|
|
43
|
+
throw new Error("API endpoint is required");
|
|
44
|
+
if (a = await t.formContext?.transport?.validateTextFieldWithBackend?.(
|
|
45
|
+
{
|
|
46
|
+
formHelpers: t,
|
|
47
|
+
apiEndpoint: c,
|
|
48
|
+
value: r,
|
|
49
|
+
method: d,
|
|
50
|
+
fieldValuesToIncludeInApiRequest: u
|
|
51
|
+
}
|
|
52
|
+
), !a)
|
|
53
|
+
throw new Error(
|
|
54
|
+
"formContext.transport.validateTextFieldWithBackend is required"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
a?.is_valid ? (o.current = !1, l.current = null, await t.form.trigger(e.id)) : (o.current = !0, l.current = a?.message?.trim() || `This ${e.label} is already taken`, await t.form.trigger(e.id));
|
|
58
|
+
} catch (n) {
|
|
59
|
+
o.current = !0, l.current = n instanceof Error ? n.message : `This ${e.label} is already taken`, await t.form.trigger(e.id), t.formContext?.transport?.showFormErrorToast?.({
|
|
60
|
+
title: "Error",
|
|
61
|
+
description: n instanceof Error ? n.message : "Something went wrong"
|
|
62
|
+
});
|
|
63
|
+
} finally {
|
|
64
|
+
f(!1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return i ? /* @__PURE__ */ m(
|
|
69
|
+
k,
|
|
70
|
+
{
|
|
71
|
+
name: e.id,
|
|
72
|
+
control: t.form.control,
|
|
73
|
+
rules: {
|
|
74
|
+
...g,
|
|
75
|
+
validate: {
|
|
76
|
+
...typeof g?.validate == "object" ? g.validate : {},
|
|
77
|
+
backendValidation: () => o.current ? l.current || "Validation pending" : !0
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
render: ({ field: r, fieldState: n }) => {
|
|
81
|
+
const a = !!n.error && n.error.message !== "Validation pending", d = r.value, s = a && !h ? n.error?.message : void 0;
|
|
82
|
+
return /* @__PURE__ */ T("div", { className: "w-full min-w-0", children: [
|
|
83
|
+
/* @__PURE__ */ m(
|
|
84
|
+
I,
|
|
85
|
+
{
|
|
86
|
+
label: e.label,
|
|
87
|
+
type: "text",
|
|
88
|
+
value: d ?? void 0,
|
|
89
|
+
onChange: (u) => {
|
|
90
|
+
u ? (o.current = !0, l.current = null) : (o.current = !1, l.current = null), r.onChange(u);
|
|
91
|
+
},
|
|
92
|
+
onBlur: () => {
|
|
93
|
+
r.onBlur(), v(d ?? "");
|
|
94
|
+
},
|
|
95
|
+
placeholder: e.placeholder,
|
|
96
|
+
required: e.isRequired,
|
|
97
|
+
disabled: x,
|
|
98
|
+
error: a && !h,
|
|
99
|
+
helperText: h ? "Validating…" : a ? void 0 : e.helpText
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
s ? /* @__PURE__ */ m(
|
|
103
|
+
"p",
|
|
104
|
+
{
|
|
105
|
+
className: "mt-2 text-sm leading-snug text-[#DC2626] break-words",
|
|
106
|
+
role: "alert",
|
|
107
|
+
children: s
|
|
108
|
+
}
|
|
109
|
+
) : null
|
|
110
|
+
] });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
) : null;
|
|
114
|
+
};
|
|
115
|
+
export {
|
|
116
|
+
B as TextFieldWithBackendValidation
|
|
117
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { FormFieldProps } from '../types/reactHookForm.types';
|
|
3
|
+
import { UseReactHookFormReturn } from '../hooks/useReactHookForm';
|
|
4
|
+
interface WeekRangeFieldProps extends FormFieldProps {
|
|
5
|
+
formHelpers: UseReactHookFormReturn;
|
|
6
|
+
}
|
|
7
|
+
export declare const WeekRangeField: FC<WeekRangeFieldProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as D } from "react/jsx-runtime";
|
|
2
|
+
import { Controller as F } from "react-hook-form";
|
|
3
|
+
import { WeekRangePicker as O } from "../../components/forms/date-picker/week-range-picker.js";
|
|
4
|
+
import { toLocalDate as M } from "../utils/calendar-boundary.js";
|
|
5
|
+
import { resolveWeekRangeMinMax as x } from "../utils/date.utils.js";
|
|
6
|
+
const p = (e) => {
|
|
7
|
+
const r = e.getFullYear(), n = e.getMonth(), t = new Date(r, n, 1).getDay(), a = e.getDate(), l = Math.ceil((a + t) / 7), s = new Date(e), h = new Date(s);
|
|
8
|
+
return {
|
|
9
|
+
year: r,
|
|
10
|
+
month: n,
|
|
11
|
+
weekOfMonth: l,
|
|
12
|
+
startDate: s,
|
|
13
|
+
endDate: h
|
|
14
|
+
};
|
|
15
|
+
}, b = ({
|
|
16
|
+
field: e,
|
|
17
|
+
validationRules: r,
|
|
18
|
+
isDisabled: n,
|
|
19
|
+
formHelpers: i
|
|
20
|
+
}) => {
|
|
21
|
+
const t = e.fieldType === "week_range" ? e : null;
|
|
22
|
+
if (!t) return null;
|
|
23
|
+
const { minDate: a, maxDate: l, startMonth: s, endMonth: h } = x(t), g = i.form.control;
|
|
24
|
+
return /* @__PURE__ */ D(
|
|
25
|
+
F,
|
|
26
|
+
{
|
|
27
|
+
name: e.id,
|
|
28
|
+
control: g,
|
|
29
|
+
rules: r,
|
|
30
|
+
render: ({ field: S, fieldState: m }) => {
|
|
31
|
+
const d = !!m.error, c = S.value, f = c?.start ? M(c.start) ?? null : null, u = c?.end ? M(c.end) ?? null : null, k = f && u;
|
|
32
|
+
return /* @__PURE__ */ D("div", { children: /* @__PURE__ */ D(
|
|
33
|
+
O,
|
|
34
|
+
{
|
|
35
|
+
label: e.label,
|
|
36
|
+
...k && {
|
|
37
|
+
value: {
|
|
38
|
+
from: p(f),
|
|
39
|
+
to: p(u)
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
onChange: (o) => {
|
|
43
|
+
const w = o?.from?.startDate ? `${o.from.startDate.getFullYear()}-${String(o.from.startDate.getMonth() + 1).padStart(2, "0")}-${String(o.from.startDate.getDate()).padStart(2, "0")}` : null, y = o?.to?.endDate ? `${o.to.endDate.getFullYear()}-${String(o.to.endDate.getMonth() + 1).padStart(2, "0")}-${String(o.to.endDate.getDate()).padStart(2, "0")}` : null;
|
|
44
|
+
i.setValue(e.id, { start: w, end: y });
|
|
45
|
+
},
|
|
46
|
+
placeholder: t.placeholder,
|
|
47
|
+
startMonth: a ?? s,
|
|
48
|
+
endMonth: l ?? h,
|
|
49
|
+
required: e.isRequired,
|
|
50
|
+
disabled: n,
|
|
51
|
+
error: d,
|
|
52
|
+
helperText: d ? m.error?.message : e.helpText,
|
|
53
|
+
calendarType: t.calendarType,
|
|
54
|
+
fiscalMode: t.fiscalMode,
|
|
55
|
+
weekStartsOn: t.weekStartsOn,
|
|
56
|
+
minDate: a,
|
|
57
|
+
maxDate: l,
|
|
58
|
+
selectionMode: t.selectionMode,
|
|
59
|
+
fiscalMonthPattern: t.fiscalMonthPattern,
|
|
60
|
+
fiscalYearStartMonth: t.fiscalYearStartMonth,
|
|
61
|
+
showFooter: t.showFooter,
|
|
62
|
+
format: t.dateFormat
|
|
63
|
+
}
|
|
64
|
+
) });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
b as WeekRangeField
|
|
71
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ReactHooksFormProps, ReactHooksFormRef } from './types/reactHookForm.types';
|
|
2
|
+
export type { ReactHooksFormRef } from './types/reactHookForm.types';
|
|
3
|
+
export declare const ReactHooksForm: import('react').ForwardRefExoticComponent<ReactHooksFormProps & import('react').RefAttributes<ReactHooksFormRef>>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as O, useRef as m, useEffect as n, useCallback as j, useImperativeHandle as x } from "react";
|
|
3
|
+
import { useReactHookForm as G } from "./hooks/useReactHookForm.js";
|
|
4
|
+
import { GRID_COLS_MAP as M, GAP_X_MAP as $, GAP_Y_MAP as N } from "./utils/fieldRendererUtils.js";
|
|
5
|
+
import { FormFieldRow as P } from "./components/FormFieldRow.js";
|
|
6
|
+
import { showFormValidationFailureFeedback as q } from "./utils/formValidationFeedback.utils.js";
|
|
7
|
+
import { resolveFormSubmittable as B, mergeFormValidationFieldErrors as L } from "./utils/resolveFormSubmittable.js";
|
|
8
|
+
import { validateVisibleRequiredFormFields as X } from "./utils/validateVisibleRequiredFormFields.js";
|
|
9
|
+
const C = O(
|
|
10
|
+
({
|
|
11
|
+
formId: R,
|
|
12
|
+
formConfig: i,
|
|
13
|
+
formInitialState: E,
|
|
14
|
+
onSubmit: h,
|
|
15
|
+
onCancel: v,
|
|
16
|
+
onReset: S,
|
|
17
|
+
sendFormStateToParent: t,
|
|
18
|
+
supportedValues: g,
|
|
19
|
+
formContext: o
|
|
20
|
+
}, k) => {
|
|
21
|
+
const r = G(
|
|
22
|
+
i,
|
|
23
|
+
E,
|
|
24
|
+
h,
|
|
25
|
+
v,
|
|
26
|
+
S,
|
|
27
|
+
o
|
|
28
|
+
), { errors: w, isValid: H, isDirty: y, isValidating: D } = r.form.formState, u = m(r), f = m(t), b = m(o), F = m(i.fields);
|
|
29
|
+
n(() => {
|
|
30
|
+
u.current = r, f.current = t, b.current = o, F.current = i.fields;
|
|
31
|
+
});
|
|
32
|
+
const l = j(() => {
|
|
33
|
+
const e = f.current;
|
|
34
|
+
if (!e)
|
|
35
|
+
return;
|
|
36
|
+
const s = u.current;
|
|
37
|
+
e(
|
|
38
|
+
s.form.formState,
|
|
39
|
+
s.form.getValues(),
|
|
40
|
+
{
|
|
41
|
+
isSubmittable: B({
|
|
42
|
+
formConfigFields: F.current,
|
|
43
|
+
formHelpers: s,
|
|
44
|
+
formContext: b.current
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}, []);
|
|
49
|
+
n(() => {
|
|
50
|
+
if (!t)
|
|
51
|
+
return;
|
|
52
|
+
l();
|
|
53
|
+
const e = r.form.watch(() => {
|
|
54
|
+
l();
|
|
55
|
+
});
|
|
56
|
+
return () => e.unsubscribe();
|
|
57
|
+
}, [t, l, r.form]), n(() => {
|
|
58
|
+
t && l();
|
|
59
|
+
}, [
|
|
60
|
+
t,
|
|
61
|
+
l,
|
|
62
|
+
w,
|
|
63
|
+
H,
|
|
64
|
+
y,
|
|
65
|
+
D
|
|
66
|
+
]), x(
|
|
67
|
+
k,
|
|
68
|
+
() => ({
|
|
69
|
+
submitForm: async () => {
|
|
70
|
+
const e = i.fields.filter(
|
|
71
|
+
(a) => r.isFieldVisible(a)
|
|
72
|
+
), s = X(
|
|
73
|
+
r.form,
|
|
74
|
+
e,
|
|
75
|
+
{
|
|
76
|
+
isFieldDisabled: r.isFieldDisabled,
|
|
77
|
+
isFieldDisabledForValidation: r.isFieldDisabledForSubmitValidation,
|
|
78
|
+
formHelpers: r
|
|
79
|
+
}
|
|
80
|
+
), d = o?.validateForm?.({
|
|
81
|
+
formValues: r.form.getValues(),
|
|
82
|
+
visibleFields: e
|
|
83
|
+
}), A = L(
|
|
84
|
+
s.fieldErrors,
|
|
85
|
+
d?.fieldErrors
|
|
86
|
+
);
|
|
87
|
+
return s.isValid && (d?.isValid ?? !0) ? (r.submitValidatedForm(void 0), !0) : (d?.fieldErrors && Object.entries(d.fieldErrors).forEach(
|
|
88
|
+
([a, I]) => {
|
|
89
|
+
r.form.setError(a, {
|
|
90
|
+
type: "validate",
|
|
91
|
+
message: I.message
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
), q({
|
|
95
|
+
fieldErrors: A,
|
|
96
|
+
fieldsInOrder: e,
|
|
97
|
+
showToast: (a) => {
|
|
98
|
+
r.formContext?.transport?.showFormErrorToast?.(
|
|
99
|
+
a
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}), !1);
|
|
103
|
+
},
|
|
104
|
+
hasErrors: Object.keys(r.form.formState?.errors || {}).length > 0,
|
|
105
|
+
errors: r.form.formState?.errors,
|
|
106
|
+
isValid: r.form.formState?.isValid
|
|
107
|
+
}),
|
|
108
|
+
[i.fields, r, o]
|
|
109
|
+
);
|
|
110
|
+
const p = i.gapBetweenFields ?? 6, _ = `grid ${M[i.columns || 1]} ${$[p] ?? "gap-x-6"} ${N[p] ?? "gap-y-6"}`, V = (e) => /* @__PURE__ */ c(
|
|
111
|
+
P,
|
|
112
|
+
{
|
|
113
|
+
field: e,
|
|
114
|
+
formHelpers: r,
|
|
115
|
+
formConfig: i,
|
|
116
|
+
supportedValues: g
|
|
117
|
+
},
|
|
118
|
+
e.id
|
|
119
|
+
);
|
|
120
|
+
return /* @__PURE__ */ c(
|
|
121
|
+
"form",
|
|
122
|
+
{
|
|
123
|
+
id: R || "react-hooks-form",
|
|
124
|
+
onSubmit: r.handleSubmit(void 0),
|
|
125
|
+
children: /* @__PURE__ */ c("div", { className: _, children: i?.enableFieldOrdering ? i?.fields?.sort((e, s) => (e?.order ?? 0) - (s?.order ?? 0)).map(V) : i?.fields?.map(V) })
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
export {
|
|
131
|
+
C as ReactHooksForm
|
|
132
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ArrayFieldConfig } from '../types/fields.types';
|
|
3
|
+
import { IFormConfig } from '../types/reactHookForm.types';
|
|
4
|
+
import { UseReactHookFormReturn } from '../hooks/useReactHookForm';
|
|
5
|
+
interface ArrayFieldRendererProps {
|
|
6
|
+
field: ArrayFieldConfig;
|
|
7
|
+
fieldPathPrefix?: string;
|
|
8
|
+
formHelpers: UseReactHookFormReturn;
|
|
9
|
+
formConfig: IFormConfig;
|
|
10
|
+
supportedValues?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export declare const ArrayFieldRenderer: FC<ArrayFieldRendererProps>;
|
|
13
|
+
export {};
|