@gen-epix/ui-core-components 4.0.0 → 4.0.2
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/_chunks/isObject.js +13 -0
- package/dist/_chunks/isObject.js.map +1 -0
- package/dist/_chunks/rolldown-runtime.js +2 -2
- package/dist/components/BackdropSpinner/BackdropSpinner.d.ts +5 -0
- package/dist/components/BackdropSpinner/index.d.ts +1 -0
- package/dist/components/BackdropSpinner/index.js +19 -0
- package/dist/components/BackdropSpinner/index.js.map +1 -0
- package/dist/components/Confirmation/Confirmation.d.ts +2 -0
- package/dist/components/Confirmation/ConfirmationRender.d.ts +11 -0
- package/dist/components/Confirmation/index.d.ts +2 -0
- package/dist/components/Confirmation/index.js +58 -0
- package/dist/components/Confirmation/index.js.map +1 -0
- package/dist/components/CopyToClipboardButton/CopyToClipboardButton.d.ts +13 -0
- package/dist/components/CopyToClipboardButton/index.d.ts +1 -0
- package/dist/components/CopyToClipboardButton/index.js +101 -0
- package/dist/components/CopyToClipboardButton/index.js.map +1 -0
- package/dist/components/Dialog/Dialog.d.ts +27 -0
- package/dist/components/Dialog/index.d.ts +1 -0
- package/dist/components/Dialog/index.js +83 -0
- package/dist/components/Dialog/index.js.map +1 -0
- package/dist/components/LinearProgressWithLabel/LinearProgressWithLabel.d.ts +5 -0
- package/dist/components/LinearProgressWithLabel/index.d.ts +1 -0
- package/dist/components/LinearProgressWithLabel/index.js +31 -0
- package/dist/components/LinearProgressWithLabel/index.js.map +1 -0
- package/dist/components/LoadingIndicator/LoadingIndicator.d.ts +2 -0
- package/dist/components/LoadingIndicator/index.d.ts +1 -0
- package/dist/components/LoadingIndicator/index.js +12 -0
- package/dist/components/LoadingIndicator/index.js.map +1 -0
- package/dist/components/NestedMenu/IconMenuItem.d.ts +18 -0
- package/dist/components/NestedMenu/NestedDropdown.d.ts +17 -0
- package/dist/components/NestedMenu/NestedMenuItem.d.ts +22 -0
- package/dist/components/NestedMenu/index.d.ts +4 -0
- package/dist/components/NestedMenu/index.js +240 -0
- package/dist/components/NestedMenu/index.js.map +1 -0
- package/dist/components/NestedMenu/nestedMenuItemsFromObject.d.ts +11 -0
- package/dist/components/Spinner/Spinner.d.ts +11 -0
- package/dist/components/Spinner/index.d.ts +1 -0
- package/dist/components/Spinner/index.js +63 -0
- package/dist/components/Spinner/index.js.map +1 -0
- package/dist/components/Stepper/Stepper.d.ts +17 -0
- package/dist/components/Stepper/index.d.ts +2 -0
- package/dist/components/Stepper/index.js +1087 -0
- package/dist/components/Stepper/index.js.map +1 -0
- package/dist/components/Stepper/stepperModel.d.ts +4 -0
- package/dist/context/uiCoreComponentsConfigContext/UiCoreComponentsConfigContextProvider.d.ts +6 -0
- package/dist/context/uiCoreComponentsConfigContext/index.d.ts +3 -0
- package/dist/context/uiCoreComponentsConfigContext/index.js +14 -0
- package/dist/context/uiCoreComponentsConfigContext/index.js.map +1 -0
- package/dist/context/uiCoreComponentsConfigContext/uiCoreComponentsConfigContext.d.ts +7 -0
- package/dist/context/uiCoreComponentsConfigContext/useUiCoreComponentsConfigContext.d.ts +2 -0
- package/dist/hoc/withDialog/index.d.ts +1 -0
- package/dist/hoc/withDialog/index.js +69 -0
- package/dist/hoc/withDialog/index.js.map +1 -0
- package/dist/hoc/withDialog/withDialog.d.ts +33 -0
- package/dist/locale/en.json +14 -93
- package/dist/locale/nl.json +14 -93
- package/dist/models/nestedMenu.d.ts +17 -0
- package/dist/models/nestedMenu.js +0 -0
- package/package.json +3 -3
- package/dist/@types/ui-form.d.ts +0 -2
- package/dist/@types/yup.d.ts +0 -30
- package/dist/_chunks/Autocomplete.js +0 -229
- package/dist/_chunks/Autocomplete.js.map +0 -1
- package/dist/_chunks/DatePicker.js +0 -126
- package/dist/_chunks/DatePicker.js.map +0 -1
- package/dist/_chunks/FormUtil.js +0 -1350
- package/dist/_chunks/FormUtil.js.map +0 -1
- package/dist/_chunks/RichTextEditor.js +0 -22721
- package/dist/_chunks/RichTextEditor.js.map +0 -1
- package/dist/_chunks/TransferList.js +0 -453
- package/dist/_chunks/TransferList.js.map +0 -1
- package/dist/_chunks/UploadButton.js +0 -91
- package/dist/_chunks/UploadButton.js.map +0 -1
- package/dist/_chunks/classnames.js +0 -33
- package/dist/_chunks/classnames.js.map +0 -1
- package/dist/_chunks/index.esm.js +0 -348
- package/dist/_chunks/index.esm.js.map +0 -1
- package/dist/_chunks/isEqual.js +0 -348
- package/dist/_chunks/isEqual.js.map +0 -1
- package/dist/_chunks/isObjectLike.js +0 -304
- package/dist/_chunks/isObjectLike.js.map +0 -1
- package/dist/_chunks/isValid.js +0 -28
- package/dist/_chunks/isValid.js.map +0 -1
- package/dist/_chunks/sv.js +0 -434
- package/dist/_chunks/sv.js.map +0 -1
- package/dist/components/fields/Autocomplete/Autocomplete.d.ts +0 -19
- package/dist/components/fields/Autocomplete/AutocompleteSelectAllContext.d.ts +0 -2
- package/dist/components/fields/Autocomplete/AutocompleteSelectAllPaper.d.ts +0 -2
- package/dist/components/fields/Autocomplete/index.d.ts +0 -1
- package/dist/components/fields/Autocomplete/index.js +0 -2
- package/dist/components/fields/CheckboxGroup/CheckboxGroup.d.ts +0 -18
- package/dist/components/fields/CheckboxGroup/index.d.ts +0 -1
- package/dist/components/fields/CheckboxGroup/index.js +0 -114
- package/dist/components/fields/CheckboxGroup/index.js.map +0 -1
- package/dist/components/fields/DatePicker/DatePicker.d.ts +0 -15
- package/dist/components/fields/DatePicker/DatePickerInputAdornment.d.ts +0 -8
- package/dist/components/fields/DatePicker/index.d.ts +0 -1
- package/dist/components/fields/DatePicker/index.js +0 -2
- package/dist/components/fields/DateRangePicker/DateRangePicker.d.ts +0 -17
- package/dist/components/fields/DateRangePicker/index.d.ts +0 -1
- package/dist/components/fields/DateRangePicker/index.js +0 -1648
- package/dist/components/fields/DateRangePicker/index.js.map +0 -1
- package/dist/components/fields/NumberField/NumberField.d.ts +0 -19
- package/dist/components/fields/NumberField/index.d.ts +0 -1
- package/dist/components/fields/NumberField/index.js +0 -180
- package/dist/components/fields/NumberField/index.js.map +0 -1
- package/dist/components/fields/NumberRangeInput/NumberRangeInput.d.ts +0 -15
- package/dist/components/fields/NumberRangeInput/index.d.ts +0 -1
- package/dist/components/fields/NumberRangeInput/index.js +0 -192
- package/dist/components/fields/NumberRangeInput/index.js.map +0 -1
- package/dist/components/fields/RadioGroup/RadioGroup.d.ts +0 -16
- package/dist/components/fields/RadioGroup/index.d.ts +0 -1
- package/dist/components/fields/RadioGroup/index.js +0 -72
- package/dist/components/fields/RadioGroup/index.js.map +0 -1
- package/dist/components/fields/RichTextEditor/RichTextEditor.d.ts +0 -13
- package/dist/components/fields/RichTextEditor/RichTextEditorContent.d.ts +0 -4
- package/dist/components/fields/RichTextEditor/index.d.ts +0 -2
- package/dist/components/fields/RichTextEditor/index.js +0 -2
- package/dist/components/fields/RichTextEditor/useRichTextEditorExtensions.d.ts +0 -10
- package/dist/components/fields/Select/Select.d.ts +0 -16
- package/dist/components/fields/Select/index.d.ts +0 -1
- package/dist/components/fields/Select/index.js +0 -129
- package/dist/components/fields/Select/index.js.map +0 -1
- package/dist/components/fields/Switch/Switch.d.ts +0 -13
- package/dist/components/fields/Switch/index.d.ts +0 -1
- package/dist/components/fields/Switch/index.js +0 -68
- package/dist/components/fields/Switch/index.js.map +0 -1
- package/dist/components/fields/TextField/TextField.d.ts +0 -18
- package/dist/components/fields/TextField/index.d.ts +0 -1
- package/dist/components/fields/TextField/index.js +0 -108
- package/dist/components/fields/TextField/index.js.map +0 -1
- package/dist/components/fields/ToggleButtonGroup/ToggleButtonGroup.d.ts +0 -14
- package/dist/components/fields/ToggleButtonGroup/index.d.ts +0 -1
- package/dist/components/fields/ToggleButtonGroup/index.js +0 -57
- package/dist/components/fields/ToggleButtonGroup/index.js.map +0 -1
- package/dist/components/fields/TransferList/TransferList.d.ts +0 -16
- package/dist/components/fields/TransferList/index.d.ts +0 -1
- package/dist/components/fields/TransferList/index.js +0 -2
- package/dist/components/fields/UploadButton/UploadButton.d.ts +0 -15
- package/dist/components/fields/UploadButton/index.d.ts +0 -1
- package/dist/components/fields/UploadButton/index.js +0 -2
- package/dist/components/helpers/FormFieldHelperText/FormFieldHelperText.d.ts +0 -8
- package/dist/components/helpers/FormFieldHelperText/index.d.ts +0 -1
- package/dist/components/helpers/FormFieldHelperText/index.js +0 -50
- package/dist/components/helpers/FormFieldHelperText/index.js.map +0 -1
- package/dist/components/helpers/FormFieldLoadingIndicator/FormFieldLoadingIndicator.d.ts +0 -4
- package/dist/components/helpers/FormFieldLoadingIndicator/index.d.ts +0 -1
- package/dist/components/helpers/FormFieldLoadingIndicator/index.js +0 -16
- package/dist/components/helpers/FormFieldLoadingIndicator/index.js.map +0 -1
- package/dist/components/helpers/GenericForm/GenericForm.d.ts +0 -18
- package/dist/components/helpers/GenericForm/index.d.ts +0 -1
- package/dist/components/helpers/GenericForm/index.js +0 -156
- package/dist/components/helpers/GenericForm/index.js.map +0 -1
- package/dist/hooks/useIsFormFieldRequiredFromSchema/index.d.ts +0 -1
- package/dist/hooks/useIsFormFieldRequiredFromSchema/index.js +0 -18
- package/dist/hooks/useIsFormFieldRequiredFromSchema/index.js.map +0 -1
- package/dist/hooks/useIsFormFieldRequiredFromSchema/useIsFormFieldRequiredFromSchema.d.ts +0 -4
- package/dist/models/form.d.ts +0 -112
- package/dist/models/form.js +0 -8
- package/dist/models/form.js.map +0 -1
- package/dist/setup/setup.d.ts +0 -1
- package/dist/setup/setup.js +0 -166
- package/dist/setup/setup.js.map +0 -1
- package/dist/utils/FormUtil/FormUtil.d.ts +0 -19
- package/dist/utils/FormUtil/index.d.ts +0 -1
- package/dist/utils/FormUtil/index.js +0 -2
- package/dist/utils/SchemaUtil/SchemaUtil.d.ts +0 -9
- package/dist/utils/SchemaUtil/index.d.ts +0 -1
- package/dist/utils/SchemaUtil/index.js +0 -30
- package/dist/utils/SchemaUtil/index.js.map +0 -1
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { t as e } from "../../../_chunks/FormUtil.js";
|
|
2
|
-
import { FORM_FIELD_DEFINITION_TYPE as t } from "../../../models/form.js";
|
|
3
|
-
import { n } from "../../../_chunks/index.esm.js";
|
|
4
|
-
import { useIsFormFieldRequiredFromSchema as r } from "../../../hooks/useIsFormFieldRequiredFromSchema/index.js";
|
|
5
|
-
import { n as i } from "../../../_chunks/RichTextEditor.js";
|
|
6
|
-
import { t as a } from "../../../_chunks/TransferList.js";
|
|
7
|
-
import { t as o } from "../../../_chunks/Autocomplete.js";
|
|
8
|
-
import { Select as s } from "../../fields/Select/index.js";
|
|
9
|
-
import { TextField as c } from "../../fields/TextField/index.js";
|
|
10
|
-
import { NumberField as l } from "../../fields/NumberField/index.js";
|
|
11
|
-
import { t as u } from "../../../_chunks/DatePicker.js";
|
|
12
|
-
import { t as d } from "../../../_chunks/UploadButton.js";
|
|
13
|
-
import { RadioGroup as f } from "../../fields/RadioGroup/index.js";
|
|
14
|
-
import { Switch as p } from "../../fields/Switch/index.js";
|
|
15
|
-
import { Fragment as m, useCallback as h, useMemo as g } from "react";
|
|
16
|
-
import { useTranslation as _ } from "react-i18next";
|
|
17
|
-
import { Alert as v, AlertTitle as y, Box as b, Button as x, Typography as S } from "@mui/material";
|
|
18
|
-
import { Fragment as C, jsx as w, jsxs as T } from "react/jsx-runtime";
|
|
19
|
-
//#region src/components/helpers/GenericForm/GenericForm.tsx
|
|
20
|
-
var E = ({ disableAll: E, formFieldDefinitions: D, formGroupDefinitions: O, formId: k, formMethods: A, onSubmit: j, renderField: M, renderGroup: N, schema: P, wrapForm: F }) => {
|
|
21
|
-
let { t: I } = _(), L = g(() => e.createBooleanOptions(I), [I]), R = r(P, A.getValues), z = h((e) => {
|
|
22
|
-
switch (e.definition) {
|
|
23
|
-
case t.AUTOCOMPLETE: return /* @__PURE__ */ w(o, {
|
|
24
|
-
...e,
|
|
25
|
-
disabled: e.disabled || E,
|
|
26
|
-
required: R(e.name)
|
|
27
|
-
});
|
|
28
|
-
case t.BOOLEAN: return /* @__PURE__ */ w(s, {
|
|
29
|
-
...e,
|
|
30
|
-
disabled: e.disabled || E,
|
|
31
|
-
options: L,
|
|
32
|
-
required: R(e.name)
|
|
33
|
-
});
|
|
34
|
-
case t.BOOLEAN_SWITCH: return /* @__PURE__ */ w(p, {
|
|
35
|
-
...e,
|
|
36
|
-
disabled: e.disabled || E,
|
|
37
|
-
required: R(e.name)
|
|
38
|
-
});
|
|
39
|
-
case t.DATE: return /* @__PURE__ */ w(u, {
|
|
40
|
-
...e,
|
|
41
|
-
disabled: e.disabled || E,
|
|
42
|
-
required: R(e.name)
|
|
43
|
-
});
|
|
44
|
-
case t.FILE: return /* @__PURE__ */ w(d, {
|
|
45
|
-
...e,
|
|
46
|
-
disabled: e.disabled || E,
|
|
47
|
-
required: R(e.name)
|
|
48
|
-
});
|
|
49
|
-
case t.NUMBER: return /* @__PURE__ */ w(l, {
|
|
50
|
-
...e,
|
|
51
|
-
disabled: e.disabled || E,
|
|
52
|
-
required: R(e.name)
|
|
53
|
-
});
|
|
54
|
-
case t.RADIO_GROUP: return /* @__PURE__ */ w(f, {
|
|
55
|
-
...e,
|
|
56
|
-
disabled: e.disabled || E,
|
|
57
|
-
required: R(e.name)
|
|
58
|
-
});
|
|
59
|
-
case t.RICH_TEXT: return /* @__PURE__ */ w(i, {
|
|
60
|
-
...e,
|
|
61
|
-
disabled: e.disabled || E,
|
|
62
|
-
required: R(e.name)
|
|
63
|
-
});
|
|
64
|
-
case t.SELECT: return /* @__PURE__ */ w(s, {
|
|
65
|
-
...e,
|
|
66
|
-
disabled: e.disabled || E,
|
|
67
|
-
required: R(e.name)
|
|
68
|
-
});
|
|
69
|
-
case t.SWITCH: return /* @__PURE__ */ w(p, {
|
|
70
|
-
...e,
|
|
71
|
-
disabled: e.disabled || E,
|
|
72
|
-
required: R(e.name)
|
|
73
|
-
});
|
|
74
|
-
case t.TEXTFIELD: return /* @__PURE__ */ w(c, {
|
|
75
|
-
...e,
|
|
76
|
-
disabled: e.disabled || E,
|
|
77
|
-
required: R(e.name)
|
|
78
|
-
});
|
|
79
|
-
case t.TRANSFER_LIST: return /* @__PURE__ */ w(a, {
|
|
80
|
-
...e,
|
|
81
|
-
disabled: e.disabled || E,
|
|
82
|
-
required: R(e.name)
|
|
83
|
-
});
|
|
84
|
-
default: throw Error(`Unsupported form field definition: ${e.definition}`);
|
|
85
|
-
}
|
|
86
|
-
}, [
|
|
87
|
-
L,
|
|
88
|
-
E,
|
|
89
|
-
R
|
|
90
|
-
]), B = h((e) => M ? /* @__PURE__ */ w(m, { children: M(e, z(e)) }, e.name) : /* @__PURE__ */ w(b, {
|
|
91
|
-
sx: { marginY: 1 },
|
|
92
|
-
children: z(e)
|
|
93
|
-
}, e.name), [M, z]), V = g(() => {
|
|
94
|
-
if (!O?.length) return /* @__PURE__ */ w(C, { children: D.map(B) });
|
|
95
|
-
let e = /* @__PURE__ */ new Map();
|
|
96
|
-
for (let t of O) e.set(t.groupKey, []);
|
|
97
|
-
let t = [];
|
|
98
|
-
for (let n of D) n.groupKey && e.has(n.groupKey) ? e.get(n.groupKey)?.push(n) : t.push(n);
|
|
99
|
-
return /* @__PURE__ */ T(C, { children: [O.map((t) => {
|
|
100
|
-
let n = e.get(t.groupKey) ?? [];
|
|
101
|
-
if (!n.length) return null;
|
|
102
|
-
let r = /* @__PURE__ */ w(C, { children: n.map(B) });
|
|
103
|
-
return N ? /* @__PURE__ */ w(m, { children: N(t, r) }, t.groupKey) : /* @__PURE__ */ T(b, {
|
|
104
|
-
sx: { marginY: 2 },
|
|
105
|
-
children: [
|
|
106
|
-
/* @__PURE__ */ w(S, {
|
|
107
|
-
variant: "subtitle1",
|
|
108
|
-
children: t.label
|
|
109
|
-
}),
|
|
110
|
-
t.description && /* @__PURE__ */ w(S, {
|
|
111
|
-
color: "text.secondary",
|
|
112
|
-
variant: "body2",
|
|
113
|
-
children: t.description
|
|
114
|
-
}),
|
|
115
|
-
t.messages?.map((e) => /* @__PURE__ */ T(v, {
|
|
116
|
-
severity: e.severity,
|
|
117
|
-
sx: { "& .MuiAlert-message": { width: "100%" } },
|
|
118
|
-
children: [/* @__PURE__ */ w(y, { children: e.message }), e.buttonLabel && e.onButtonClick && /* @__PURE__ */ w(b, {
|
|
119
|
-
sx: {
|
|
120
|
-
display: "flex",
|
|
121
|
-
justifyContent: "flex-end"
|
|
122
|
-
},
|
|
123
|
-
children: /* @__PURE__ */ w(x, {
|
|
124
|
-
color: "inherit",
|
|
125
|
-
onClick: e.onButtonClick,
|
|
126
|
-
size: "small",
|
|
127
|
-
variant: "text",
|
|
128
|
-
children: e.buttonLabel
|
|
129
|
-
})
|
|
130
|
-
})]
|
|
131
|
-
}, e.message)),
|
|
132
|
-
r
|
|
133
|
-
]
|
|
134
|
-
}, t.groupKey);
|
|
135
|
-
}), t.map(B)] });
|
|
136
|
-
}, [
|
|
137
|
-
D,
|
|
138
|
-
O,
|
|
139
|
-
N,
|
|
140
|
-
B
|
|
141
|
-
]);
|
|
142
|
-
return /* @__PURE__ */ w(n, {
|
|
143
|
-
...A,
|
|
144
|
-
children: /* @__PURE__ */ w(b, {
|
|
145
|
-
autoComplete: "off",
|
|
146
|
-
component: "form",
|
|
147
|
-
id: k,
|
|
148
|
-
onSubmit: j,
|
|
149
|
-
children: F ? F(V) : V
|
|
150
|
-
})
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
//#endregion
|
|
154
|
-
export { E as GenericForm };
|
|
155
|
-
|
|
156
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/components/helpers/GenericForm/GenericForm.tsx"],"sourcesContent":["import type {\n ReactElement,\n SubmitEventHandler,\n} from 'react';\nimport {\n Fragment,\n useCallback,\n useMemo,\n} from 'react';\nimport { useTranslation } from 'react-i18next';\nimport type {\n FieldValues,\n Path,\n UseFormReturn,\n} from 'react-hook-form';\nimport { FormProvider } from 'react-hook-form';\nimport {\n Alert,\n AlertTitle,\n Box,\n Button,\n Typography,\n} from '@mui/material';\nimport type { ObjectSchema } from 'yup';\n\nimport type {\n FormFieldDefinition,\n FormGroupDefinition,\n} from '../../../models/form';\nimport { FORM_FIELD_DEFINITION_TYPE } from '../../../models/form';\nimport { FormUtil } from '../../../utils/FormUtil';\nimport { RichTextEditor } from '../../fields/RichTextEditor';\nimport { TransferList } from '../../fields/TransferList';\nimport type { AutocompleteProps } from '../../fields/Autocomplete';\nimport { Autocomplete } from '../../fields/Autocomplete';\nimport type { SelectProps } from '../../fields/Select';\nimport { Select } from '../../fields/Select';\nimport { TextField } from '../../fields/TextField';\nimport { NumberField } from '../../fields/NumberField';\nimport { DatePicker } from '../../fields/DatePicker';\nimport { UploadButton } from '../../fields/UploadButton/UploadButton';\nimport { RadioGroup } from '../../fields/RadioGroup';\nimport { Switch } from '../../fields/Switch';\nimport { useIsFormFieldRequiredFromSchema } from '../../../hooks/useIsFormFieldRequiredFromSchema';\n\nexport type GenericFormProps<TFormFields extends FieldValues> = {\n readonly defaultFormValues?: Partial<TFormFields>;\n readonly disableAll?: boolean;\n readonly formFieldDefinitions: FormFieldDefinition<TFormFields>[];\n readonly formGroupDefinitions?: FormGroupDefinition[];\n readonly formId?: string;\n readonly formMethods: UseFormReturn<TFormFields>;\n readonly onSubmit?: SubmitEventHandler<HTMLFormElement>;\n readonly renderField?: (definition: FormFieldDefinition<TFormFields>, element: ReactElement) => ReactElement;\n readonly renderGroup?: (definition: FormGroupDefinition, children: ReactElement) => ReactElement;\n readonly schema: ObjectSchema<TFormFields, TFormFields>;\n readonly wrapForm?: (children: ReactElement) => ReactElement;\n};\n\nexport const GenericForm = <TFormFields extends FieldValues>({\n disableAll,\n formFieldDefinitions,\n formGroupDefinitions,\n formId,\n formMethods,\n onSubmit,\n renderField,\n renderGroup,\n schema,\n wrapForm,\n}: GenericFormProps<TFormFields>) => {\n const { t } = useTranslation();\n\n const booleanOptions = useMemo(() => FormUtil.createBooleanOptions(t), [t]);\n\n const isFormFieldRequired = useIsFormFieldRequiredFromSchema(schema, formMethods.getValues);\n\n const renderFormFieldDefinition = useCallback((formFieldDefinition: FormFieldDefinition<TFormFields>) => {\n switch (formFieldDefinition.definition) {\n case FORM_FIELD_DEFINITION_TYPE.AUTOCOMPLETE:\n return (\n <Autocomplete\n {...formFieldDefinition as AutocompleteProps<TFormFields, Path<TFormFields>, false>}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.BOOLEAN:\n return (\n <Select\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n options={booleanOptions}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.BOOLEAN_SWITCH:\n return (\n <Switch\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.DATE:\n return (\n <DatePicker\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.FILE:\n return (\n <UploadButton\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.NUMBER:\n return (\n <NumberField\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.RADIO_GROUP:\n return (\n <RadioGroup\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.RICH_TEXT:\n return (\n <RichTextEditor\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.SELECT:\n return (\n <Select\n {...formFieldDefinition as SelectProps<TFormFields, Path<TFormFields>, false>}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.SWITCH:\n return (\n <Switch\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.TEXTFIELD:\n return (\n <TextField\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n case FORM_FIELD_DEFINITION_TYPE.TRANSFER_LIST:\n return (\n <TransferList\n {...formFieldDefinition}\n disabled={formFieldDefinition.disabled || disableAll}\n required={isFormFieldRequired(formFieldDefinition.name)}\n />\n );\n default:\n throw Error(`Unsupported form field definition: ${formFieldDefinition.definition}`);\n }\n }, [booleanOptions, disableAll, isFormFieldRequired]);\n\n\n const renderSingleField = useCallback((formFieldDefinition: FormFieldDefinition<TFormFields>) => {\n if (renderField) {\n return (\n <Fragment key={formFieldDefinition.name}>\n {renderField(formFieldDefinition, renderFormFieldDefinition(formFieldDefinition))}\n </Fragment>\n );\n }\n return (\n <Box\n key={formFieldDefinition.name}\n sx={{\n marginY: 1,\n }}\n >\n {renderFormFieldDefinition(formFieldDefinition)}\n </Box>\n );\n }, [renderField, renderFormFieldDefinition]);\n\n const formFieldsContent = useMemo(() => {\n if (!formGroupDefinitions?.length) {\n return (\n <>\n {formFieldDefinitions.map(renderSingleField)}\n </>\n );\n }\n\n const groupFieldsMap = new Map<string, FormFieldDefinition<TFormFields>[]>();\n for (const group of formGroupDefinitions) {\n groupFieldsMap.set(group.groupKey, []);\n }\n\n const ungroupedFields: FormFieldDefinition<TFormFields>[] = [];\n for (const field of formFieldDefinitions) {\n if (field.groupKey && groupFieldsMap.has(field.groupKey)) {\n groupFieldsMap.get(field.groupKey)?.push(field);\n } else {\n ungroupedFields.push(field);\n }\n }\n\n return (\n <>\n {formGroupDefinitions.map(group => {\n const groupFields = groupFieldsMap.get(group.groupKey) ?? [];\n if (!groupFields.length) {\n return null;\n }\n const groupContent = (\n <>\n {groupFields.map(renderSingleField)}\n </>\n );\n if (renderGroup) {\n return (\n <Fragment key={group.groupKey}>\n {renderGroup(group, groupContent)}\n </Fragment>\n );\n }\n return (\n <Box\n key={group.groupKey}\n sx={{ marginY: 2 }}\n >\n <Typography variant={'subtitle1'}>\n {group.label}\n </Typography>\n {group.description && (\n <Typography\n color={'text.secondary'}\n variant={'body2'}\n >\n {group.description}\n </Typography>\n )}\n {group.messages?.map((msg) => (\n <Alert\n key={msg.message}\n severity={msg.severity}\n sx={{ '& .MuiAlert-message': { width: '100%' } }}\n >\n <AlertTitle>\n {msg.message}\n </AlertTitle>\n {msg.buttonLabel && msg.onButtonClick && (\n <Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>\n <Button\n color={'inherit'}\n onClick={msg.onButtonClick}\n size={'small'}\n variant={'text'}\n >\n {msg.buttonLabel}\n </Button>\n </Box>\n )}\n </Alert>\n ))}\n {groupContent}\n </Box>\n );\n })}\n {ungroupedFields.map(renderSingleField)}\n </>\n );\n }, [formFieldDefinitions, formGroupDefinitions, renderGroup, renderSingleField]);\n\n return (\n <FormProvider {...formMethods}>\n <Box\n autoComplete={'off'}\n component={'form'}\n id={formId}\n onSubmit={onSubmit}\n >\n {wrapForm ? wrapForm(formFieldsContent) : formFieldsContent}\n </Box>\n </FormProvider>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2DA,IAAa,KAAgD,EAC3D,eACA,yBACA,yBACA,WACA,gBACA,aACA,gBACA,gBACA,WACA,kBACmC;CACnC,IAAM,EAAE,SAAM,EAAe,GAEvB,IAAiB,QAAc,EAAS,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,G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K,CAAC;GAC3D,IAAI,CAAC,EAAY,QACf,OAAO;GAET,IAAM,IACJ,kBAAA,GAAA,EAAA,UACG,EAAY,IAAI,CAAiB,EAClC,CAAA;GASJ,OAPI,IAEA,kBAAC,GAAD,EAAA,UACG,EAAY,GAAO,CAAY,EACxB,GAFK,EAAM,QAEX,IAIZ,kBAAC,GAAD;IAEE,IAAI,EAAE,SAAS,EAAE;cAFnB;KAIE,kBAAC,GAAD;MAAY,SAAS;gBAClB,EAAM;KACG,CAAA;KACX,EAAM,eACL,kBAAC,GAAD;MACE,OAAO;MACP,SAAS;gBAER,EAAM;KACG,CAAA;KAEb,EAAM,UAAU,KAAK,MACpB,kBAAC,GAAD;MAEE,UAAU,EAAI;MACd,IAAI,EAAE,uBAAuB,EAAE,OAAO,OAAO,EAAE;gBAHjD,CAKE,kBAAC,GAAD,EAAA,UACG,EAAI,QACK,CAAA,GACX,EAAI,eAAe,EAAI,iBACtB,kBAAC,GAAD;OAAK,IAAI;QAAE,SAAS;QAAQ,gBAAgB;OAAW;iBACrD,kBAAC,GAAD;QACE,OAAO;QACP,SAAS,EAAI;QACb,MAAM;QACN,SAAS;kBAER,EAAI;OACC,CAAA;MACL,CAAA,CAEF;QAnBA,EAAI,OAmBJ,CACR;KACA;IACE;MAtCE,EAAM,QAsCR;EAET,CAAC,GACA,EAAgB,IAAI,CAAiB,CACtC,EAAA,CAAA;CAEN,GAAG;EAAC;EAAsB;EAAsB;EAAa;CAAiB,CAAC;CAE/E,OACE,kBAAC,GAAD;EAAc,GAAI;YAChB,kBAAC,GAAD;GACE,cAAc;GACd,WAAW;GACX,IAAI;GACM;aAET,IAAW,EAAS,CAAiB,IAAI;EACvC,CAAA;CACO,CAAA;AAElB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useIsFormFieldRequiredFromSchema';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { r as e } from "../../_chunks/index.esm.js";
|
|
2
|
-
import { useCallback as t } from "react";
|
|
3
|
-
//#region src/hooks/useIsFormFieldRequiredFromSchema/useIsFormFieldRequiredFromSchema.ts
|
|
4
|
-
var n = (n, r) => t((t) => {
|
|
5
|
-
try {
|
|
6
|
-
let i = structuredClone(r());
|
|
7
|
-
return e(i, t, void 0), n.validateSyncAt(t, i, {
|
|
8
|
-
abortEarly: !0,
|
|
9
|
-
strict: !1
|
|
10
|
-
}), !1;
|
|
11
|
-
} catch (e) {
|
|
12
|
-
return e?.type === "required" || e?.type === "optionality";
|
|
13
|
-
}
|
|
14
|
-
}, [r, n]);
|
|
15
|
-
//#endregion
|
|
16
|
-
export { n as useIsFormFieldRequiredFromSchema };
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/useIsFormFieldRequiredFromSchema/useIsFormFieldRequiredFromSchema.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { set } from 'react-hook-form';\nimport type {\n FieldValues,\n Path,\n UseFormGetValues,\n} from 'react-hook-form';\nimport type {\n ObjectSchema,\n ValidationError,\n} from 'yup';\n\nconst useIsFormFieldRequiredFromSchema = <TFormFields extends FieldValues, TName extends Path<TFormFields>>(schema: ObjectSchema<TFormFields, TFormFields>, getFormValues: UseFormGetValues<TFormFields>): (fieldName: TName) => boolean => {\n return useCallback((fieldName: TName) => {\n try {\n const values = structuredClone(getFormValues());\n set(values, fieldName, undefined);\n\n schema.validateSyncAt(fieldName, values, {\n abortEarly: true,\n strict: false,\n });\n return false;\n } catch (error) {\n return (error as ValidationError)?.type === 'required' || (error as ValidationError)?.type === 'optionality';\n }\n }, [getFormValues, schema]);\n};\n\nexport {\n useIsFormFieldRequiredFromSchema,\n};\n"],"mappings":";;;AAYA,IAAM,KAAsG,GAAgD,MACnJ,GAAa,MAAqB;CACvC,IAAI;EACF,IAAM,IAAS,gBAAgB,EAAc,CAAC;EAO9C,OANA,EAAI,GAAQ,GAAW,KAAA,CAAS,GAEhC,EAAO,eAAe,GAAW,GAAQ;GACvC,YAAY;GACZ,QAAQ;EACV,CAAC,GACM;CACT,SAAS,GAAO;EACd,OAAQ,GAA2B,SAAS,cAAe,GAA2B,SAAS;CACjG;AACF,GAAG,CAAC,GAAe,CAAM,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { FieldValues, Path, UseFormGetValues } from 'react-hook-form';
|
|
2
|
-
import { ObjectSchema } from 'yup';
|
|
3
|
-
declare const useIsFormFieldRequiredFromSchema: <TFormFields extends FieldValues, TName extends Path<TFormFields>>(schema: ObjectSchema<TFormFields, TFormFields>, getFormValues: UseFormGetValues<TFormFields>) => (fieldName: TName) => boolean;
|
|
4
|
-
export { useIsFormFieldRequiredFromSchema, };
|
package/dist/models/form.d.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { FieldValues, Path } from 'react-hook-form';
|
|
2
|
-
import { RichTextEditorProps } from '../components/fields/RichTextEditor';
|
|
3
|
-
import { TransferListProps } from '../components/fields/TransferList';
|
|
4
|
-
import { AutocompleteProps } from '../components/fields/Autocomplete';
|
|
5
|
-
import { TextFieldProps } from '../components/fields/TextField';
|
|
6
|
-
import { SelectProps } from '../components/fields/Select';
|
|
7
|
-
import { DatePickerProps } from '../components/fields/DatePicker';
|
|
8
|
-
import { UploadButtonProps } from '../components/fields/UploadButton/UploadButton';
|
|
9
|
-
import { RadioGroupProps } from '../components/fields/RadioGroup';
|
|
10
|
-
import { NumberFieldProps } from '../components/fields/NumberField';
|
|
11
|
-
import { SwitchProps } from '../components/fields/Switch';
|
|
12
|
-
export declare enum FORM_FIELD_DEFINITION_TYPE {
|
|
13
|
-
AUTOCOMPLETE = "AUTOCOMPLETE",
|
|
14
|
-
BOOLEAN = "BOOLEAN",
|
|
15
|
-
BOOLEAN_SWITCH = "BOOLEAN_SWITCH",
|
|
16
|
-
DATE = "DATE",
|
|
17
|
-
FILE = "FILE",
|
|
18
|
-
HIDDEN = "HIDDEN",
|
|
19
|
-
NUMBER = "NUMBER",
|
|
20
|
-
RADIO_GROUP = "RADIO_GROUP",
|
|
21
|
-
RICH_TEXT = "RICH_TEXT",
|
|
22
|
-
SELECT = "SELECT",
|
|
23
|
-
SWITCH = "SWITCH",
|
|
24
|
-
TEXTFIELD = "TEXTFIELD",
|
|
25
|
-
TRANSFER_LIST = "TRANSFER_LIST"
|
|
26
|
-
}
|
|
27
|
-
export interface AutoCompleteOption<TValue = void> extends OptionBase<TValue extends void ? (number | string) : TValue> {
|
|
28
|
-
groupBySortOrderValue?: number;
|
|
29
|
-
groupByValue?: string;
|
|
30
|
-
}
|
|
31
|
-
export type AutocompleteSelectAllContextData = {
|
|
32
|
-
currentValues: AutocompleteValue[];
|
|
33
|
-
enabledOptionValues: AutocompleteValue[];
|
|
34
|
-
handleSelectAll: (isCurrentlyAll: boolean, currentValues: AutocompleteValue[]) => void;
|
|
35
|
-
selectAllLabel: string;
|
|
36
|
-
};
|
|
37
|
-
export type AutocompleteValue = number | string;
|
|
38
|
-
export type CheckboxOption = OptionBase<number | string>;
|
|
39
|
-
export type FormFieldDefinition<TFormFields extends FieldValues> = FormFieldDefinitionAutocomplete<TFormFields> | FormFieldDefinitionAutocompleteMultiple<TFormFields> | FormFieldDefinitionBoolean<TFormFields> | FormFieldDefinitionBooleanSwitch<TFormFields> | FormFieldDefinitionDate<TFormFields> | FormFieldDefinitionFile<TFormFields> | FormFieldDefinitionHidden<TFormFields> | FormFieldDefinitionNumber<TFormFields> | FormFieldDefinitionRadioGroup<TFormFields> | FormFieldDefinitionRichText<TFormFields> | FormFieldDefinitionSelect<TFormFields> | FormFieldDefinitionSelectMultiple<TFormFields> | FormFieldDefinitionSwitch<TFormFields> | FormFieldDefinitionTextField<TFormFields> | FormFieldDefinitionTransferList<TFormFields>;
|
|
40
|
-
export type FormFieldDefinitionAutocomplete<TFormFields extends FieldValues> = {
|
|
41
|
-
definition: FORM_FIELD_DEFINITION_TYPE.AUTOCOMPLETE;
|
|
42
|
-
multiple?: false;
|
|
43
|
-
} & AutocompleteProps<TFormFields, Path<TFormFields>, false> & FormFieldGrouping;
|
|
44
|
-
export type FormFieldDefinitionAutocompleteMultiple<TFormFields extends FieldValues> = {
|
|
45
|
-
definition: FORM_FIELD_DEFINITION_TYPE.AUTOCOMPLETE;
|
|
46
|
-
multiple?: true;
|
|
47
|
-
} & AutocompleteProps<TFormFields, Path<TFormFields>, true> & FormFieldGrouping;
|
|
48
|
-
export type FormFieldDefinitionBoolean<TFormFields extends FieldValues> = {
|
|
49
|
-
definition: FORM_FIELD_DEFINITION_TYPE.BOOLEAN;
|
|
50
|
-
} & FormFieldGrouping & Omit<SelectProps<TFormFields, Path<TFormFields>, false>, 'options'>;
|
|
51
|
-
export type FormFieldDefinitionBooleanSwitch<TFormFields extends FieldValues> = {
|
|
52
|
-
definition: FORM_FIELD_DEFINITION_TYPE.BOOLEAN_SWITCH;
|
|
53
|
-
} & FormFieldGrouping & Omit<SwitchProps<TFormFields, Path<TFormFields>>, 'options'>;
|
|
54
|
-
export type FormFieldDefinitionDate<TFormFields extends FieldValues> = {
|
|
55
|
-
definition: FORM_FIELD_DEFINITION_TYPE.DATE;
|
|
56
|
-
} & DatePickerProps<TFormFields, Path<TFormFields>> & FormFieldGrouping;
|
|
57
|
-
export type FormFieldDefinitionFile<TFormFields extends FieldValues> = {
|
|
58
|
-
definition: FORM_FIELD_DEFINITION_TYPE.FILE;
|
|
59
|
-
} & FormFieldGrouping & UploadButtonProps<TFormFields, Path<TFormFields>>;
|
|
60
|
-
export type FormFieldDefinitionHidden<TFormFields extends FieldValues> = {
|
|
61
|
-
definition: FORM_FIELD_DEFINITION_TYPE.HIDDEN;
|
|
62
|
-
} & FormFieldGrouping & TextFieldProps<TFormFields, Path<TFormFields>>;
|
|
63
|
-
export type FormFieldDefinitionNumber<TFormFields extends FieldValues> = {
|
|
64
|
-
definition: FORM_FIELD_DEFINITION_TYPE.NUMBER;
|
|
65
|
-
} & FormFieldGrouping & NumberFieldProps<TFormFields, Path<TFormFields>>;
|
|
66
|
-
export type FormFieldDefinitionRadioGroup<TFormFields extends FieldValues> = {
|
|
67
|
-
definition: FORM_FIELD_DEFINITION_TYPE.RADIO_GROUP;
|
|
68
|
-
} & FormFieldGrouping & RadioGroupProps<TFormFields, Path<TFormFields>>;
|
|
69
|
-
export type FormFieldDefinitionRichText<TFormFields extends FieldValues> = {
|
|
70
|
-
definition: FORM_FIELD_DEFINITION_TYPE.RICH_TEXT;
|
|
71
|
-
} & FormFieldGrouping & RichTextEditorProps<TFormFields, Path<TFormFields>>;
|
|
72
|
-
export type FormFieldDefinitionSelect<TFormFields extends FieldValues> = {
|
|
73
|
-
definition: FORM_FIELD_DEFINITION_TYPE.SELECT;
|
|
74
|
-
multiple?: false;
|
|
75
|
-
} & FormFieldGrouping & SelectProps<TFormFields, Path<TFormFields>, false>;
|
|
76
|
-
export type FormFieldDefinitionSelectMultiple<TFormFields extends FieldValues> = {
|
|
77
|
-
definition: FORM_FIELD_DEFINITION_TYPE.SELECT;
|
|
78
|
-
multiple?: true;
|
|
79
|
-
} & FormFieldGrouping & SelectProps<TFormFields, Path<TFormFields>, true>;
|
|
80
|
-
export type FormFieldDefinitionSwitch<TFormFields extends FieldValues> = {
|
|
81
|
-
definition: FORM_FIELD_DEFINITION_TYPE.SWITCH;
|
|
82
|
-
} & FormFieldGrouping & SwitchProps<TFormFields, Path<TFormFields>>;
|
|
83
|
-
export type FormFieldDefinitionTextField<TFormFields extends FieldValues> = {
|
|
84
|
-
definition: FORM_FIELD_DEFINITION_TYPE.TEXTFIELD;
|
|
85
|
-
} & FormFieldGrouping & TextFieldProps<TFormFields, Path<TFormFields>>;
|
|
86
|
-
export type FormFieldDefinitionTransferList<TFormFields extends FieldValues> = {
|
|
87
|
-
definition: FORM_FIELD_DEFINITION_TYPE.TRANSFER_LIST;
|
|
88
|
-
} & FormFieldGrouping & TransferListProps<TFormFields, Path<TFormFields>>;
|
|
89
|
-
export type FormFieldGrouping = {
|
|
90
|
-
groupKey?: string;
|
|
91
|
-
};
|
|
92
|
-
export type FormGroupDefinition = {
|
|
93
|
-
description?: string;
|
|
94
|
-
groupKey: string;
|
|
95
|
-
label: string;
|
|
96
|
-
messages?: FormGroupMessage[];
|
|
97
|
-
};
|
|
98
|
-
export type FormGroupMessage = {
|
|
99
|
-
buttonLabel?: string;
|
|
100
|
-
message: string;
|
|
101
|
-
onButtonClick?: () => void;
|
|
102
|
-
severity: 'error' | 'info' | 'warning';
|
|
103
|
-
};
|
|
104
|
-
export interface OptionBase<TValue> {
|
|
105
|
-
disabled?: boolean;
|
|
106
|
-
label?: string;
|
|
107
|
-
value?: TValue;
|
|
108
|
-
}
|
|
109
|
-
export type RadioButtonOption<TValue = void> = OptionBase<TValue extends void ? (boolean | number | string) : TValue>;
|
|
110
|
-
export type SelectOption<TValue = void> = OptionBase<TValue extends void ? (boolean | number | string) : TValue>;
|
|
111
|
-
export type ToggleButtonOption<TValue = void> = OptionBase<TValue extends void ? (boolean | number | string) : TValue>;
|
|
112
|
-
export type TransferListOption = OptionBase<string>;
|
package/dist/models/form.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region src/models/form.ts
|
|
2
|
-
var e = /* @__PURE__ */ function(e) {
|
|
3
|
-
return e.AUTOCOMPLETE = "AUTOCOMPLETE", e.BOOLEAN = "BOOLEAN", e.BOOLEAN_SWITCH = "BOOLEAN_SWITCH", e.DATE = "DATE", e.FILE = "FILE", e.HIDDEN = "HIDDEN", e.NUMBER = "NUMBER", e.RADIO_GROUP = "RADIO_GROUP", e.RICH_TEXT = "RICH_TEXT", e.SELECT = "SELECT", e.SWITCH = "SWITCH", e.TEXTFIELD = "TEXTFIELD", e.TRANSFER_LIST = "TRANSFER_LIST", e;
|
|
4
|
-
}({});
|
|
5
|
-
//#endregion
|
|
6
|
-
export { e as FORM_FIELD_DEFINITION_TYPE };
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=form.js.map
|
package/dist/models/form.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"form.js","names":[],"sources":["../../src/models/form.ts"],"sourcesContent":["import type {\n FieldValues,\n Path,\n} from 'react-hook-form';\n\nimport type { RichTextEditorProps } from '../components/fields/RichTextEditor';\nimport type { TransferListProps } from '../components/fields/TransferList';\nimport type { AutocompleteProps } from '../components/fields/Autocomplete';\nimport type { TextFieldProps } from '../components/fields/TextField';\nimport type { SelectProps } from '../components/fields/Select';\nimport type { DatePickerProps } from '../components/fields/DatePicker';\nimport type { UploadButtonProps } from '../components/fields/UploadButton/UploadButton';\nimport type { RadioGroupProps } from '../components/fields/RadioGroup';\nimport type { NumberFieldProps } from '../components/fields/NumberField';\nimport type { SwitchProps } from '../components/fields/Switch';\n\nexport enum FORM_FIELD_DEFINITION_TYPE {\n AUTOCOMPLETE = 'AUTOCOMPLETE',\n BOOLEAN = 'BOOLEAN',\n BOOLEAN_SWITCH = 'BOOLEAN_SWITCH',\n DATE = 'DATE',\n FILE = 'FILE',\n HIDDEN = 'HIDDEN',\n NUMBER = 'NUMBER',\n RADIO_GROUP = 'RADIO_GROUP',\n RICH_TEXT = 'RICH_TEXT',\n SELECT = 'SELECT',\n SWITCH = 'SWITCH',\n TEXTFIELD = 'TEXTFIELD',\n TRANSFER_LIST = 'TRANSFER_LIST',\n}\n\nexport interface AutoCompleteOption<TValue = void> extends OptionBase<TValue extends void ? (number | string) : TValue> {\n groupBySortOrderValue?: number;\n groupByValue?: string;\n}\n\nexport type AutocompleteSelectAllContextData = {\n currentValues: AutocompleteValue[];\n enabledOptionValues: AutocompleteValue[];\n handleSelectAll: (isCurrentlyAll: boolean, currentValues: AutocompleteValue[]) => void;\n selectAllLabel: string;\n};\nexport type AutocompleteValue = number | string;\nexport type CheckboxOption = OptionBase<number | string>;\n\nexport type FormFieldDefinition<TFormFields extends FieldValues> =\n FormFieldDefinitionAutocomplete<TFormFields> |\n FormFieldDefinitionAutocompleteMultiple<TFormFields> |\n FormFieldDefinitionBoolean<TFormFields> |\n FormFieldDefinitionBooleanSwitch<TFormFields> |\n FormFieldDefinitionDate<TFormFields> |\n FormFieldDefinitionFile<TFormFields> |\n FormFieldDefinitionHidden<TFormFields> |\n FormFieldDefinitionNumber<TFormFields> |\n FormFieldDefinitionRadioGroup<TFormFields> |\n FormFieldDefinitionRichText<TFormFields> |\n FormFieldDefinitionSelect<TFormFields> |\n FormFieldDefinitionSelectMultiple<TFormFields> |\n FormFieldDefinitionSwitch<TFormFields> |\n FormFieldDefinitionTextField<TFormFields> |\n FormFieldDefinitionTransferList<TFormFields>;\n\nexport type FormFieldDefinitionAutocomplete<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.AUTOCOMPLETE; multiple?: false } & AutocompleteProps<TFormFields, Path<TFormFields>, false> & FormFieldGrouping;\n\nexport type FormFieldDefinitionAutocompleteMultiple<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.AUTOCOMPLETE; multiple?: true } & AutocompleteProps<TFormFields, Path<TFormFields>, true> & FormFieldGrouping;\nexport type FormFieldDefinitionBoolean<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.BOOLEAN } & FormFieldGrouping & Omit<SelectProps<TFormFields, Path<TFormFields>, false>, 'options'>;\nexport type FormFieldDefinitionBooleanSwitch<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.BOOLEAN_SWITCH } & FormFieldGrouping & Omit<SwitchProps<TFormFields, Path<TFormFields>>, 'options'>;\nexport type FormFieldDefinitionDate<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.DATE } & DatePickerProps<TFormFields, Path<TFormFields>> & FormFieldGrouping;\nexport type FormFieldDefinitionFile<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.FILE } & FormFieldGrouping & UploadButtonProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionHidden<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.HIDDEN } & FormFieldGrouping & TextFieldProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionNumber<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.NUMBER } & FormFieldGrouping & NumberFieldProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionRadioGroup<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.RADIO_GROUP } & FormFieldGrouping & RadioGroupProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionRichText<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.RICH_TEXT } & FormFieldGrouping & RichTextEditorProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionSelect<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.SELECT; multiple?: false } & FormFieldGrouping & SelectProps<TFormFields, Path<TFormFields>, false>;\nexport type FormFieldDefinitionSelectMultiple<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.SELECT; multiple?: true } & FormFieldGrouping & SelectProps<TFormFields, Path<TFormFields>, true>;\nexport type FormFieldDefinitionSwitch<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.SWITCH } & FormFieldGrouping & SwitchProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionTextField<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.TEXTFIELD } & FormFieldGrouping & TextFieldProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldDefinitionTransferList<TFormFields extends FieldValues> = { definition: FORM_FIELD_DEFINITION_TYPE.TRANSFER_LIST } & FormFieldGrouping & TransferListProps<TFormFields, Path<TFormFields>>;\nexport type FormFieldGrouping = {\n groupKey?: string;\n};\nexport type FormGroupDefinition = {\n description?: string;\n groupKey: string;\n label: string;\n messages?: FormGroupMessage[];\n};\nexport type FormGroupMessage = {\n buttonLabel?: string;\n message: string;\n onButtonClick?: () => void;\n severity: 'error' | 'info' | 'warning';\n};\nexport interface OptionBase<TValue> {\n disabled?: boolean;\n label?: string;\n value?: TValue;\n}\nexport type RadioButtonOption<TValue = void> = OptionBase<TValue extends void ? (boolean | number | string) : TValue>;\nexport type SelectOption<TValue = void> = OptionBase<TValue extends void ? (boolean | number | string) : TValue>;\nexport type ToggleButtonOption<TValue = void> = OptionBase<TValue extends void ? (boolean | number | string) : TValue>;\n\nexport type TransferListOption = OptionBase<string>;\n"],"mappings":";AAgBA,IAAY,IAAL,yBAAA,GAAA;QACL,EAAA,eAAA,gBACA,EAAA,UAAA,WACA,EAAA,iBAAA,kBACA,EAAA,OAAA,QACA,EAAA,OAAA,QACA,EAAA,SAAA,UACA,EAAA,SAAA,UACA,EAAA,cAAA,eACA,EAAA,YAAA,aACA,EAAA,SAAA,UACA,EAAA,SAAA,UACA,EAAA,YAAA,aACA,EAAA,gBAAA;AACF,EAAA,CAAA,CAAA"}
|
package/dist/setup/setup.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const setupYup: () => void;
|
package/dist/setup/setup.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { addMethod as e, setLocale as t, string as n } from "yup";
|
|
2
|
-
import { t as r } from "i18next";
|
|
3
|
-
import { ValidationUtil as i } from "@gen-epix/ui-core/utils/ValidationUtil";
|
|
4
|
-
//#region src/setup/setup.ts
|
|
5
|
-
var a = () => {
|
|
6
|
-
t({
|
|
7
|
-
array: {
|
|
8
|
-
max: r("Should contain at most ${max} option(s)"),
|
|
9
|
-
min: r("Should contain at least ${min} option(s)")
|
|
10
|
-
},
|
|
11
|
-
boolean: {},
|
|
12
|
-
date: {
|
|
13
|
-
max: r("Should be before ${max}"),
|
|
14
|
-
min: r("Should be later than ${min}")
|
|
15
|
-
},
|
|
16
|
-
mixed: {
|
|
17
|
-
default: r("Value is invalid"),
|
|
18
|
-
notNull: r("Field is mandatory"),
|
|
19
|
-
notOneOf: r("Value is invalid"),
|
|
20
|
-
notType: r("Field is mandatory"),
|
|
21
|
-
oneOf: r("Field is mandatory"),
|
|
22
|
-
required: r("Field is mandatory")
|
|
23
|
-
},
|
|
24
|
-
number: {
|
|
25
|
-
integer: r("Should be an integer"),
|
|
26
|
-
lessThan: r("Should be less than ${less}"),
|
|
27
|
-
max: r("Should be lower or equal to ${max}"),
|
|
28
|
-
min: r("Should be greater or equal to ${min}"),
|
|
29
|
-
moreThan: r("Should be higher than ${more}"),
|
|
30
|
-
negative: r("Should be negative digit"),
|
|
31
|
-
positive: r("Should be a positive digit")
|
|
32
|
-
},
|
|
33
|
-
object: { noUnknown: r("This value is invalid") },
|
|
34
|
-
string: {
|
|
35
|
-
email: r("Should be a valid email address"),
|
|
36
|
-
length: r("Should be precisely ${length} characters long"),
|
|
37
|
-
lowercase: r("Should only contain lowercase characters"),
|
|
38
|
-
matches: r("This value is invalid."),
|
|
39
|
-
max: r("Should contain at most ${max} characters"),
|
|
40
|
-
min: r("Should contain at least ${min} characters"),
|
|
41
|
-
trim: r("Should not contain leading or trailing spaces"),
|
|
42
|
-
uppercase: r("Should only contain uppercase characters"),
|
|
43
|
-
url: r("Should be a valid URL")
|
|
44
|
-
}
|
|
45
|
-
}), [
|
|
46
|
-
{
|
|
47
|
-
assertCallback: (e) => i.validate("STRICT_ALPHA", e),
|
|
48
|
-
message: () => r`Only letters (without diacritics) are allowed.`,
|
|
49
|
-
name: "strictAlpha"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
assertCallback: (e) => i.validate("STRICT_ALPHA_NUMERIC", e),
|
|
53
|
-
message: () => r`Only digits and letters (without diacritics) are allowed.`,
|
|
54
|
-
name: "strictAlphaNumeric"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
assertCallback: (e) => i.validate("ALPHA", e),
|
|
58
|
-
message: () => r`Only letters (including diacritics) are allowed.`,
|
|
59
|
-
name: "alpha"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
assertCallback: (e) => i.validate("ALPHA_NUMERIC", e),
|
|
63
|
-
message: () => r`Only digits and letters (including diacritics) are allowed.`,
|
|
64
|
-
name: "alphaNumeric"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
assertCallback: (e) => i.validate("EXTENDED_ALPHA_NUMERIC", e),
|
|
68
|
-
message: () => r`Only digits, letters (including diacritics) and punctuation marks are allowed.`,
|
|
69
|
-
name: "extendedAlphaNumeric"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
assertCallback: (e) => i.validate("FREE_FORM_TEXT", e),
|
|
73
|
-
message: () => r`Only freeform text characters are allowed.`,
|
|
74
|
-
name: "freeFormText"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
assertCallback: (e) => i.validate("EMAIL", e),
|
|
78
|
-
message: () => r`Only a valid email address is allowed.`,
|
|
79
|
-
name: "email"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
assertCallback: (e) => i.validate("URL", e),
|
|
83
|
-
message: () => r`Only a valid url is allowed.`,
|
|
84
|
-
name: "url"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
assertCallback: (e) => i.validate("REGEX", e),
|
|
88
|
-
message: () => r`Only a valid regex is allowed.`,
|
|
89
|
-
name: "regex"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
assertCallback: (e) => i.validate("UUID4", e),
|
|
93
|
-
message: () => r`Only a valid UUID is allowed.`,
|
|
94
|
-
name: "uuid4"
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
assertCallback: (e) => i.validate("LAT_LONG", e),
|
|
98
|
-
message: () => r`Only valid latitude and longitude coordinates are allowed. For example: 13.7368, 100.5627`,
|
|
99
|
-
name: "latLong"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
assertCallback: (e) => i.validate("TIME_WEEK", e),
|
|
103
|
-
message: () => r`Only a valid time week is allowed. For example: 2021-W01`,
|
|
104
|
-
name: "timeWeek"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
assertCallback: (e) => i.validate("TIME_QUARTER", e),
|
|
108
|
-
message: () => r`Only a valid time quarter notation is allowed. For example: 2021-Q1`,
|
|
109
|
-
name: "timeQuarter"
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
assertCallback: (e) => i.validate("TIME_MONTH", e),
|
|
113
|
-
message: () => r`Only a valid time month notation is allowed. For example: 2021-01`,
|
|
114
|
-
name: "timeMonth"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
assertCallback: (e) => i.validate("TIME_YEAR", e),
|
|
118
|
-
message: () => r`Only a valid time year notation is allowed. For example: 2021`,
|
|
119
|
-
name: "timeYear"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
assertCallback: (e) => i.validate("DECIMAL_0", e),
|
|
123
|
-
message: () => r`Only a valid number is allowed. (signed, 0 decimal places)`,
|
|
124
|
-
name: "decimal0"
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
assertCallback: (e) => i.validate("DECIMAL_1", e),
|
|
128
|
-
message: () => r`Only a valid number is allowed. (signed, maximum 1 decimal place, use '.' as decimal separator)`,
|
|
129
|
-
name: "decimal1"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
assertCallback: (e) => i.validate("DECIMAL_2", e),
|
|
133
|
-
message: () => r`Only a valid number is allowed. (signed, maximum 2 decimal place, use '.' as decimal separator)`,
|
|
134
|
-
name: "decimal2"
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
assertCallback: (e) => i.validate("DECIMAL_3", e),
|
|
138
|
-
message: () => r`Only a valid number is allowed. (signed, maximum 3 decimal place, use '.' as decimal separator)`,
|
|
139
|
-
name: "decimal3"
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
assertCallback: (e) => i.validate("DECIMAL_4", e),
|
|
143
|
-
message: () => r`Only a valid number is allowed. (signed, maximum 4 decimal place, use '.' as decimal separator)`,
|
|
144
|
-
name: "decimal4"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
assertCallback: (e) => i.validate("DECIMAL_5", e),
|
|
148
|
-
message: () => r`Only a valid number is allowed. (signed, maximum 5 decimal place, use '.' as decimal separator)`,
|
|
149
|
-
name: "decimal5"
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
assertCallback: (e) => i.validate("DECIMAL_6", e),
|
|
153
|
-
message: () => r`Only a valid number is allowed. (signed, maximum 6 decimal place, use '.' as decimal separator)`,
|
|
154
|
-
name: "decimal6"
|
|
155
|
-
}
|
|
156
|
-
].forEach((t) => {
|
|
157
|
-
function r(...e) {
|
|
158
|
-
return this.test(t.name, () => typeof t.message == "string" ? t.message : t.message(...e), ((n) => t.assertCallback(n, ...e)));
|
|
159
|
-
}
|
|
160
|
-
e(n, t.name, r);
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
//#endregion
|
|
164
|
-
export { a as setupYup };
|
|
165
|
-
|
|
166
|
-
//# sourceMappingURL=setup.js.map
|
package/dist/setup/setup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","names":[],"sources":["../../src/setup/setup.ts"],"sourcesContent":["import type {\n StringSchema,\n TestFunction,\n} from 'yup';\nimport {\n addMethod,\n setLocale,\n string,\n} from 'yup';\nimport { t } from 'i18next';\nimport { ValidationUtil } from '@gen-epix/ui-core/utils/ValidationUtil';\n\ntype CustomValidation = {\n assertCallback: (value: string, ...args: unknown[]) => boolean;\n message: ((...args: unknown[]) => string) | string;\n name: string;\n};\n\nexport const setupYup = () => {\n setLocale({\n array: {\n max: t('Should contain at most ${max} option(s)'),\n min: t('Should contain at least ${min} option(s)'),\n },\n boolean: {},\n date: {\n max: t('Should be before ${max}'),\n min: t('Should be later than ${min}'),\n },\n mixed: {\n default: t('Value is invalid'),\n notNull: t('Field is mandatory'),\n notOneOf: t('Value is invalid'),\n notType: t('Field is mandatory'),\n oneOf: t('Field is mandatory'),\n required: t('Field is mandatory'),\n },\n number: {\n integer: t('Should be an integer'),\n lessThan: t('Should be less than ${less}'),\n max: t('Should be lower or equal to ${max}'),\n min: t('Should be greater or equal to ${min}'),\n moreThan: t('Should be higher than ${more}'),\n negative: t('Should be negative digit'),\n positive: t('Should be a positive digit'),\n },\n object: {\n noUnknown: t('This value is invalid'),\n },\n string: {\n email: t('Should be a valid email address'),\n length: t('Should be precisely ${length} characters long'),\n lowercase: t('Should only contain lowercase characters'),\n matches: t('This value is invalid.'),\n max: t('Should contain at most ${max} characters'),\n min: t('Should contain at least ${min} characters'),\n trim: t('Should not contain leading or trailing spaces'),\n uppercase: t('Should only contain uppercase characters'),\n url: t('Should be a valid URL'),\n },\n });\n\n const customValidations: CustomValidation[] = [\n {\n assertCallback: (value: string) => ValidationUtil.validate('STRICT_ALPHA', value),\n message: () => t`Only letters (without diacritics) are allowed.`,\n name: 'strictAlpha',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('STRICT_ALPHA_NUMERIC', value),\n message: () => t`Only digits and letters (without diacritics) are allowed.`,\n name: 'strictAlphaNumeric',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('ALPHA', value),\n message: () => t`Only letters (including diacritics) are allowed.`,\n name: 'alpha',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('ALPHA_NUMERIC', value),\n message: () => t`Only digits and letters (including diacritics) are allowed.`,\n name: 'alphaNumeric',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('EXTENDED_ALPHA_NUMERIC', value),\n message: () => t`Only digits, letters (including diacritics) and punctuation marks are allowed.`,\n name: 'extendedAlphaNumeric',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('FREE_FORM_TEXT', value),\n message: () => t`Only freeform text characters are allowed.`,\n name: 'freeFormText',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('EMAIL', value),\n message: () => t`Only a valid email address is allowed.`,\n name: 'email',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('URL', value),\n message: () => t`Only a valid url is allowed.`,\n name: 'url',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('REGEX', value),\n message: () => t`Only a valid regex is allowed.`,\n name: 'regex',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('UUID4', value),\n message: () => t`Only a valid UUID is allowed.`,\n name: 'uuid4',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('LAT_LONG', value),\n message: () => t`Only valid latitude and longitude coordinates are allowed. For example: 13.7368, 100.5627`,\n name: 'latLong',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('TIME_WEEK', value),\n message: () => t`Only a valid time week is allowed. For example: 2021-W01`,\n name: 'timeWeek',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('TIME_QUARTER', value),\n message: () => t`Only a valid time quarter notation is allowed. For example: 2021-Q1`,\n name: 'timeQuarter',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('TIME_MONTH', value),\n message: () => t`Only a valid time month notation is allowed. For example: 2021-01`,\n name: 'timeMonth',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('TIME_YEAR', value),\n message: () => t`Only a valid time year notation is allowed. For example: 2021`,\n name: 'timeYear',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_0', value),\n message: () => t`Only a valid number is allowed. (signed, 0 decimal places)`,\n name: 'decimal0',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_1', value),\n message: () => t`Only a valid number is allowed. (signed, maximum 1 decimal place, use '.' as decimal separator)`,\n name: 'decimal1',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_2', value),\n message: () => t`Only a valid number is allowed. (signed, maximum 2 decimal place, use '.' as decimal separator)`,\n name: 'decimal2',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_3', value),\n message: () => t`Only a valid number is allowed. (signed, maximum 3 decimal place, use '.' as decimal separator)`,\n name: 'decimal3',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_4', value),\n message: () => t`Only a valid number is allowed. (signed, maximum 4 decimal place, use '.' as decimal separator)`,\n name: 'decimal4',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_5', value),\n message: () => t`Only a valid number is allowed. (signed, maximum 5 decimal place, use '.' as decimal separator)`,\n name: 'decimal5',\n },\n {\n assertCallback: (value: string) => ValidationUtil.validate('DECIMAL_6', value),\n message: () => t`Only a valid number is allowed. (signed, maximum 6 decimal place, use '.' as decimal separator)`,\n name: 'decimal6',\n },\n ];\n\n customValidations.forEach((customValidation) => {\n // * Inevitable function inside a forEach\n function method(this: StringSchema, ...args: unknown[]) {\n return this.test(\n customValidation.name,\n () => {\n if (typeof customValidation.message === 'string') {\n return customValidation.message;\n }\n return customValidation.message(...args);\n },\n ((value: string): boolean => customValidation.assertCallback(value, ...args)) as TestFunction,\n );\n }\n addMethod(string, customValidation.name, method);\n });\n};\n"],"mappings":";;;;AAkBA,IAAa,UAAiB;CA6J5B,AA5JA,EAAU;EACR,OAAO;GACL,KAAK,EAAE,yCAAyC;GAChD,KAAK,EAAE,0CAA0C;EACnD;EACA,SAAS,CAAC;EACV,MAAM;GACJ,KAAK,EAAE,yBAAyB;GAChC,KAAK,EAAE,6BAA6B;EACtC;EACA,OAAO;GACL,SAAS,EAAE,kBAAkB;GAC7B,SAAS,EAAE,oBAAoB;GAC/B,UAAU,EAAE,kBAAkB;GAC9B,SAAS,EAAE,oBAAoB;GAC/B,OAAO,EAAE,oBAAoB;GAC7B,UAAU,EAAE,oBAAoB;EAClC;EACA,QAAQ;GACN,SAAS,EAAE,sBAAsB;GACjC,UAAU,EAAE,6BAA6B;GACzC,KAAK,EAAE,oCAAoC;GAC3C,KAAK,EAAE,sCAAsC;GAC7C,UAAU,EAAE,+BAA+B;GAC3C,UAAU,EAAE,0BAA0B;GACtC,UAAU,EAAE,4BAA4B;EAC1C;EACA,QAAQ,EACN,WAAW,EAAE,uBAAuB,EACtC;EACA,QAAQ;GACN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-
import { DeepRequired, FieldErrorsImpl, FieldValues } from 'react-hook-form';
|
|
2
|
-
import { TFunction } from 'i18next';
|
|
3
|
-
import { ObjectSchema } from 'yup';
|
|
4
|
-
import { FormFieldDefinition } from '../../models/form';
|
|
5
|
-
export declare class FormUtil {
|
|
6
|
-
static areFormValuesValid<TFormFields extends FieldValues>(formFieldDefinitions: FormFieldDefinition<TFormFields>[], values: unknown): boolean;
|
|
7
|
-
static createBooleanOptions(t: TFunction<'translation', undefined>): {
|
|
8
|
-
label: string;
|
|
9
|
-
value: boolean;
|
|
10
|
-
}[];
|
|
11
|
-
static createFormValues<TFormFields extends FieldValues, TData = TFormFields>(formFieldDefinitions: FormFieldDefinition<TFormFields>[], item: TData): TFormFields;
|
|
12
|
-
static createStringValuesFromFormValues<TFormFields extends FieldValues>(formFieldDefinitions: FormFieldDefinition<TFormFields>[], formValues: TFormFields): {
|
|
13
|
-
[key: string]: string;
|
|
14
|
-
};
|
|
15
|
-
static createYupSchemaFromFormFieldDefinitions<TFormFields extends FieldValues>(formFieldDefinitions: FormFieldDefinition<TFormFields>[]): ObjectSchema<{
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
}>;
|
|
18
|
-
static getFieldErrorMessage<TFormFields extends FieldValues>(fieldErrors: Partial<FieldErrorsImpl<DeepRequired<TFormFields>>>, fieldName: string): string;
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './FormUtil';
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare class SchemaUtil {
|
|
2
|
-
static get code(): import('yup').StringSchema<string, import('yup').AnyObject, undefined, "">;
|
|
3
|
-
static get description(): import('yup').StringSchema<string, import('yup').AnyObject, undefined, "">;
|
|
4
|
-
static get isoString(): import('yup').StringSchema<string, import('yup').AnyObject, undefined, "">;
|
|
5
|
-
static get label(): import('yup').StringSchema<string, import('yup').AnyObject, undefined, "">;
|
|
6
|
-
static get name(): import('yup').StringSchema<string, import('yup').AnyObject, undefined, "">;
|
|
7
|
-
static get number(): import('yup').NumberSchema<number, import('yup').AnyObject, undefined, "">;
|
|
8
|
-
static get rank(): import('yup').NumberSchema<number, import('yup').AnyObject, undefined, "">;
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './SchemaUtil';
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as e } from "../../_chunks/isValid.js";
|
|
2
|
-
import { number as t, string as n } from "yup";
|
|
3
|
-
//#region src/utils/SchemaUtil/SchemaUtil.ts
|
|
4
|
-
var r = class r {
|
|
5
|
-
static get code() {
|
|
6
|
-
return n().extendedAlphaNumeric().required().max(100);
|
|
7
|
-
}
|
|
8
|
-
static get description() {
|
|
9
|
-
return n().freeFormText().max(1e3);
|
|
10
|
-
}
|
|
11
|
-
static get isoString() {
|
|
12
|
-
return n().transform((t, n) => e(n) ? n.toISOString() : void 0);
|
|
13
|
-
}
|
|
14
|
-
static get label() {
|
|
15
|
-
return n().extendedAlphaNumeric().required().max(100);
|
|
16
|
-
}
|
|
17
|
-
static get name() {
|
|
18
|
-
return n().extendedAlphaNumeric().required().max(100);
|
|
19
|
-
}
|
|
20
|
-
static get number() {
|
|
21
|
-
return t().nullable();
|
|
22
|
-
}
|
|
23
|
-
static get rank() {
|
|
24
|
-
return r.number.required().min(0).integer();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
//#endregion
|
|
28
|
-
export { r as SchemaUtil };
|
|
29
|
-
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/SchemaUtil/SchemaUtil.ts"],"sourcesContent":["import { isValid } from 'date-fns/isValid';\nimport {\n number,\n string,\n} from 'yup';\n\nexport class SchemaUtil {\n public static get code() {\n return string().extendedAlphaNumeric().required().max(100);\n }\n\n public static get description() {\n return string().freeFormText().max(1000);\n }\n\n public static get isoString() {\n return string().transform((_val: unknown, orig: Date) => isValid(orig) ? orig.toISOString() : undefined);\n }\n\n public static get label() {\n return string().extendedAlphaNumeric().required().max(100);\n }\n\n public static get name() {\n return string().extendedAlphaNumeric().required().max(100);\n }\n\n public static get number() {\n return number().nullable();\n }\n\n public static get rank() {\n return SchemaUtil.number.required().min(0).integer();\n }\n}\n"],"mappings":";;;AAMA,IAAa,IAAb,MAAa,EAAW;CACtB,WAAkB,OAAO;EACvB,OAAO,EAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,GAAG;CAC3D;CAEA,WAAkB,cAAc;EAC9B,OAAO,EAAO,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,GAAI;CACzC;CAEA,WAAkB,YAAY;EAC5B,OAAO,EAAO,CAAC,CAAC,WAAW,GAAe,MAAe,EAAQ,CAAI,IAAI,EAAK,YAAY,IAAI,KAAA,CAAS;CACzG;CAEA,WAAkB,QAAQ;EACxB,OAAO,EAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,GAAG;CAC3D;CAEA,WAAkB,OAAO;EACvB,OAAO,EAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,GAAG;CAC3D;CAEA,WAAkB,SAAS;EACzB,OAAO,EAAO,CAAC,CAAC,SAAS;CAC3B;CAEA,WAAkB,OAAO;EACvB,OAAO,EAAW,OAAO,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ;CACrD;AACF"}
|