@axdspub/axiom-ui-forms 0.2.4 → 0.2.6
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/library/axiom-ui-forms.d.ts +17 -29
- package/library/esm/_virtual/index2.js +2 -2
- package/library/esm/_virtual/index3.js +2 -2
- package/library/esm/_virtual/index8.js +2 -2
- package/library/esm/_virtual/index9.js +2 -2
- package/library/esm/node_modules/ajv/dist/compile/codegen/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/compile/validate/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/library/esm/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/library/esm/src/Form/Components/FieldCreator.js +16 -21
- package/library/esm/src/Form/Components/FieldCreator.js.map +1 -1
- package/library/esm/src/Form/Components/FieldLabel.js +6 -6
- package/library/esm/src/Form/Components/FieldLabel.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Date.js +8 -12
- package/library/esm/src/Form/Components/Inputs/Date.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/GeoJSON.js +49 -48
- package/library/esm/src/Form/Components/Inputs/GeoJSON.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Geometry.js +81 -59
- package/library/esm/src/Form/Components/Inputs/Geometry.js.map +1 -1
- package/library/esm/src/Form/Components/Inputs/Object.js +3 -3
- package/library/esm/src/Form/Components/Inputs/Object.js.map +1 -1
- package/library/esm/src/Form/Creator/FormContextProvider.js +17 -0
- package/library/esm/src/Form/Creator/FormContextProvider.js.map +1 -0
- package/library/esm/src/Form/Creator/FormCreator.js +39 -22
- package/library/esm/src/Form/Creator/FormCreator.js.map +1 -1
- package/library/esm/src/Form/Creator/FormFields.js +2 -2
- package/library/esm/src/Form/Creator/FormFields.js.map +1 -1
- package/library/esm/src/Form/Creator/FormSection.js +4 -4
- package/library/esm/src/Form/Creator/FormSection.js.map +1 -1
- package/library/esm/src/Form/Creator/FormSectionContextProvider.js +23 -0
- package/library/esm/src/Form/Creator/FormSectionContextProvider.js.map +1 -0
- package/library/esm/src/Form/Creator/Page.js +23 -34
- package/library/esm/src/Form/Creator/Page.js.map +1 -1
- package/library/esm/src/Form/Creator/Wizard.js +38 -48
- package/library/esm/src/Form/Creator/Wizard.js.map +1 -1
- package/library/esm/src/Form/helpers.js +25 -8
- package/library/esm/src/Form/helpers.js.map +1 -1
- package/library/esm/src/Form/resolveRefs.js.map +1 -1
- package/library/esm/src/Form/schemaToFormHelpers.js +45 -25
- package/library/esm/src/Form/schemaToFormHelpers.js.map +1 -1
- package/library/esm/src/library.js +1 -1
- package/package.json +14 -7
@@ -1,5 +1,5 @@
|
|
1
1
|
import { GeoJSON } from 'geojson';
|
2
|
-
import {
|
2
|
+
import { JSONSchema6, JSONSchema6Type, JSONSchema6Definition } from 'json-schema';
|
3
3
|
import React$1, { ReactElement } from 'react';
|
4
4
|
|
5
5
|
interface IValueTypes {
|
@@ -35,12 +35,11 @@ interface IFormFieldRoot {
|
|
35
35
|
path?: IFormField[];
|
36
36
|
fullPath?: string[];
|
37
37
|
level?: number;
|
38
|
-
|
38
|
+
defaultValue?: IValueType | IValueType[];
|
39
39
|
conditions?: IFieldConditions;
|
40
40
|
settings?: Record<string, unknown>;
|
41
41
|
}
|
42
42
|
interface INumberValueInput extends IFormFieldRoot {
|
43
|
-
value?: 'number';
|
44
43
|
constraints?: {
|
45
44
|
min?: number;
|
46
45
|
max?: number;
|
@@ -50,7 +49,6 @@ interface INumberField extends INumberValueInput {
|
|
50
49
|
type: 'number';
|
51
50
|
}
|
52
51
|
interface IStringValueInput extends IFormFieldRoot {
|
53
|
-
value?: 'text';
|
54
52
|
placeholder?: string;
|
55
53
|
}
|
56
54
|
interface ITextField extends IStringValueInput {
|
@@ -82,10 +80,9 @@ interface ISelectableInput extends IFormFieldRoot {
|
|
82
80
|
};
|
83
81
|
}
|
84
82
|
interface ISingleSelectableInput extends ISelectableInput {
|
85
|
-
value?: 'text' | 'number';
|
86
83
|
}
|
87
84
|
interface IMultiSelectableInput extends ISelectableInput {
|
88
|
-
|
85
|
+
defaultValues?: Array<string | number>;
|
89
86
|
}
|
90
87
|
interface ISelectField extends ISingleSelectableInput {
|
91
88
|
type: 'select';
|
@@ -99,7 +96,6 @@ interface ICheckboxField extends IMultiSelectableInput {
|
|
99
96
|
}
|
100
97
|
interface IBooleanField extends IFormFieldRoot {
|
101
98
|
type: 'boolean';
|
102
|
-
value?: 'boolean';
|
103
99
|
}
|
104
100
|
interface IDateFieldConstraints {
|
105
101
|
minDate?: string;
|
@@ -107,7 +103,6 @@ interface IDateFieldConstraints {
|
|
107
103
|
}
|
108
104
|
interface IDateField extends IFormFieldRoot {
|
109
105
|
type: 'date';
|
110
|
-
value?: 'date';
|
111
106
|
constraints?: IDateFieldConstraints;
|
112
107
|
}
|
113
108
|
interface ITimeFieldConstraints {
|
@@ -116,7 +111,6 @@ interface ITimeFieldConstraints {
|
|
116
111
|
}
|
117
112
|
interface ITimeField extends IFormFieldRoot {
|
118
113
|
type: 'time';
|
119
|
-
value?: 'time';
|
120
114
|
constraints?: ITimeFieldConstraints;
|
121
115
|
}
|
122
116
|
interface IDateTimeConstraints {
|
@@ -125,7 +119,6 @@ interface IDateTimeConstraints {
|
|
125
119
|
}
|
126
120
|
interface IDateTimeField extends IFormFieldRoot {
|
127
121
|
type: 'datetime';
|
128
|
-
value?: 'datetime';
|
129
122
|
constraints?: IDateTimeConstraints;
|
130
123
|
}
|
131
124
|
interface IContainerField extends IFormFieldRoot {
|
@@ -144,13 +137,11 @@ interface IFormFieldPage extends IFormFieldSection {
|
|
144
137
|
}
|
145
138
|
interface IGeoJSONField extends IFormFieldRoot {
|
146
139
|
type: 'geojson';
|
147
|
-
value?: 'geojson';
|
148
140
|
exclude_types?: string[];
|
149
141
|
include_types?: string[];
|
150
142
|
}
|
151
143
|
interface IGeometryField extends IFormFieldRoot {
|
152
144
|
type: 'geometry';
|
153
|
-
value?: 'geometry';
|
154
145
|
exclude_types?: string[];
|
155
146
|
include_types?: string[];
|
156
147
|
}
|
@@ -200,18 +191,15 @@ type IFormValueState = [IFormValues, (v: IFormValues) => void];
|
|
200
191
|
type IFormInputComponent = React.FC<IFormFieldProps>;
|
201
192
|
type IValueChangeFn = (v: IValueType | IValueType[] | undefined) => void;
|
202
193
|
interface IFieldInputProps {
|
203
|
-
form: IForm;
|
204
194
|
field: IFormField;
|
205
195
|
onChange: IValueChangeFn;
|
206
|
-
formValueState: IFormValueState;
|
207
196
|
value?: IValueType;
|
208
|
-
inputOverrides?: Record<string, React.FC<IFieldInputProps>>;
|
209
197
|
className?: string;
|
210
198
|
}
|
211
199
|
|
212
200
|
interface IFormCreatorProps {
|
213
201
|
form: IForm;
|
214
|
-
schema?:
|
202
|
+
schema?: JSONSchema6;
|
215
203
|
formValueState: [IFormValues, (v: IFormValues) => void];
|
216
204
|
note?: string;
|
217
205
|
error?: string;
|
@@ -220,7 +208,7 @@ interface IFormCreatorProps {
|
|
220
208
|
urlNavigable?: boolean;
|
221
209
|
inputOverrides?: Record<string, React$1.FC<IFieldInputProps>>;
|
222
210
|
}
|
223
|
-
declare const FormCreator: ({ form, formValueState, note, error, onChange, className, urlNavigable, inputOverrides }: IFormCreatorProps) => ReactElement;
|
211
|
+
declare const FormCreator: ({ form, formValueState, note, error, onChange, className, urlNavigable, inputOverrides, schema }: IFormCreatorProps) => ReactElement;
|
224
212
|
type IFormSectionStatus = Record<string, {
|
225
213
|
completed: number;
|
226
214
|
total: number;
|
@@ -245,20 +233,19 @@ declare function getPathFromField(field: IFormField): string;
|
|
245
233
|
declare const checkCondition: (field: IFormField, formValues: IFormValues) => boolean;
|
246
234
|
declare function getFieldsFromFormSection(formSection: IFormSection): IFormField[];
|
247
235
|
declare function cleanUnusedDependenciesFromFormValues(form: IForm, formValues: IFormValues): IFormValues;
|
236
|
+
declare function updateFormValuesWithFieldValueInPlace(field: IFormField, newValue: IValueType | IValueType[], formValues: IFormValues): void;
|
237
|
+
declare function updateFormValuesWithFieldValue(field: IFormField, newValue: IValueType | IValueType[], formValues: IFormValues): IFormValues;
|
248
238
|
declare const makeJsonPath: (field: IFormField, index?: number) => string;
|
249
239
|
declare const calculateSectionStatus: (sections: IFormSection[], formValueState: IFormValueState) => IFormSectionStatus;
|
250
240
|
|
251
241
|
interface IFieldCreator {
|
252
242
|
field: IFormField;
|
253
|
-
form: IForm;
|
254
243
|
onChange?: IValueChangeFn;
|
255
244
|
className?: string;
|
256
245
|
defaultClassName?: string;
|
257
246
|
value?: IValueType | IValueType[];
|
258
|
-
formValueState: IFormValueState;
|
259
|
-
inputOverrides?: Record<string, React$1.FC<IFieldInputProps>>;
|
260
247
|
}
|
261
|
-
declare const FieldCreator: ({ field,
|
248
|
+
declare const FieldCreator: ({ field, value, onChange, className, defaultClassName }: IFieldCreator) => ReactElement | null;
|
262
249
|
|
263
250
|
declare const BooleanInput: ({ field, onChange, value }: IFieldInputProps) => ReactElement;
|
264
251
|
|
@@ -280,14 +267,15 @@ declare const DateInput: ({ field, onChange, value }: IFieldInputProps) => React
|
|
280
267
|
|
281
268
|
declare const TimeInput: ({ field, onChange, value }: IFieldInputProps) => ReactElement;
|
282
269
|
|
283
|
-
declare const validateSchema: (schemaOb: unknown, version?: number) =>
|
284
|
-
schema?:
|
270
|
+
declare const validateSchema: (schemaOb: unknown, version?: number) => {
|
271
|
+
schema?: JSONSchema6;
|
285
272
|
error?: string;
|
286
|
-
|
287
|
-
|
288
|
-
declare const
|
289
|
-
declare const
|
290
|
-
declare const
|
273
|
+
unrefed?: JSONSchema6;
|
274
|
+
};
|
275
|
+
declare const validateAgainstSchema: (schema: JSONSchema6, formValues: IFormValues) => string[] | undefined;
|
276
|
+
declare const getValueFromSchema: (schema: JSONSchema6Type | JSONSchema6Definition | undefined) => string | number | boolean | undefined;
|
277
|
+
declare const getLabelFromSchema: (schema: JSONSchema6Type | JSONSchema6Definition | undefined) => string | undefined;
|
278
|
+
declare const schemaToFormObject: (schema: JSONSchema6) => IForm;
|
291
279
|
|
292
280
|
declare const schemaToFormHelpers_getLabelFromSchema: typeof getLabelFromSchema;
|
293
281
|
declare const schemaToFormHelpers_getValueFromSchema: typeof getValueFromSchema;
|
@@ -298,4 +286,4 @@ declare namespace schemaToFormHelpers {
|
|
298
286
|
export { schemaToFormHelpers_getLabelFromSchema as getLabelFromSchema, schemaToFormHelpers_getValueFromSchema as getValueFromSchema, schemaToFormHelpers_schemaToFormObject as schemaToFormObject, schemaToFormHelpers_validateAgainstSchema as validateAgainstSchema, schemaToFormHelpers_validateSchema as validateSchema };
|
299
287
|
}
|
300
288
|
|
301
|
-
export { BooleanInput, DateInput, DateTimeInput, FieldCreator, FormCreator, GeoJSONInputLoader as GeoJSONInput, type IBooleanField, type ICheckboxField, type ICompositeValueType, type IFieldInputProps, type IForm, type IFormField, type IFormFieldPage, type IFormFieldProps, type IFormFieldSection, type IFormFieldType, type IFormInputComponent, type IFormSection, type IFormValueState, type IFormValues, type IFormWithPages, type INumberField, type IObjectField, type IPage, type IRadioField, type ISectionFormFieldType, type ISelectField, type IValueChangeFn, type IValueType, type IWizardStep, JSONStringInput, LongStringInput as LongTextInput, NumberInput, SingleSelectInput as SelectInput, StringInput as TextInput, TimeInput, addFieldPath, calculateSectionStatus, checkCondition, cleanUnusedDependenciesFromFormValues, copyAndAddPathToFields, getChildFields, getFieldValue, getFields, getFieldsFromFormSection, getPathFromField, getUniqueFormFields, makeJsonPath, schemaToFormHelpers as schemToFormHelpers };
|
289
|
+
export { BooleanInput, DateInput, DateTimeInput, FieldCreator, FormCreator, GeoJSONInputLoader as GeoJSONInput, type IBooleanField, type ICheckboxField, type ICompositeValueType, type IFieldInputProps, type IForm, type IFormField, type IFormFieldPage, type IFormFieldProps, type IFormFieldSection, type IFormFieldType, type IFormInputComponent, type IFormSection, type IFormValueState, type IFormValues, type IFormWithPages, type INumberField, type IObjectField, type IPage, type IRadioField, type ISectionFormFieldType, type ISelectField, type IValueChangeFn, type IValueType, type IWizardStep, JSONStringInput, LongStringInput as LongTextInput, NumberInput, SingleSelectInput as SelectInput, StringInput as TextInput, TimeInput, addFieldPath, calculateSectionStatus, checkCondition, cleanUnusedDependenciesFromFormValues, copyAndAddPathToFields, getChildFields, getFieldValue, getFields, getFieldsFromFormSection, getPathFromField, getUniqueFormFields, makeJsonPath, schemaToFormHelpers as schemToFormHelpers, updateFormValuesWithFieldValue, updateFormValuesWithFieldValueInPlace };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { __exports as validate } from '../../../../../_virtual/
|
1
|
+
import { __exports as validate } from '../../../../../_virtual/index2.js';
|
2
2
|
import { __require as requireBoolSchema } from './boolSchema.js';
|
3
3
|
import { __require as requireDataType } from './dataType.js';
|
4
4
|
import { __require as requireApplicability } from './applicability.js';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { __exports as applicator } from '../../../../../_virtual/
|
1
|
+
import { __exports as applicator } from '../../../../../_virtual/index8.js';
|
2
2
|
import { __require as requireAdditionalItems } from './additionalItems.js';
|
3
3
|
import { __require as requirePrefixItems } from './prefixItems.js';
|
4
4
|
import { __require as requireItems } from './items.js';
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { __assign, __spreadArray } from '../../../node_modules/tslib/tslib.es6.js';
|
2
2
|
import inputMap from './Inputs/inputMap.js';
|
3
|
-
import {
|
3
|
+
import { useFormContext } from '../Creator/FormContextProvider.js';
|
4
|
+
import { checkCondition, getFieldValue, updateFormValuesWithFieldValue, cleanUnusedDependenciesFromFormValues } from '../helpers.js';
|
4
5
|
import { utils as index$1, Button } from '../../../node_modules/@axdspub/axiom-ui-utilities/library/index.js';
|
5
6
|
import { ExclamationTriangleIcon, PlusIcon, CopyIcon, CheckIcon, Cross1Icon, TrashIcon } from '../../../node_modules/@radix-ui/react-icons/dist/react-icons.esm.js';
|
6
|
-
import { set } from 'lodash';
|
7
7
|
import React__default, { useState } from 'react';
|
8
8
|
|
9
9
|
var toolButtonClass = 'border-white hover:border-single hover:border-1 hover:border-slate-400';
|
@@ -30,14 +30,14 @@ var DeleteMultiple = function (_a) {
|
|
30
30
|
React__default.createElement(TrashIcon, { className: 'inline ml-2 fill-white' }))));
|
31
31
|
};
|
32
32
|
var OneOfMultiple = function (_a) {
|
33
|
-
var InputComponent = _a.InputComponent, field = _a.field,
|
33
|
+
var InputComponent = _a.InputComponent, field = _a.field, value = _a.value, index = _a.index, onChange = _a.onChange, values = _a.values;
|
34
34
|
var addValue = function (v) {
|
35
35
|
var newValues = __spreadArray([], values, true);
|
36
36
|
newValues.splice(index + 1, 0, v);
|
37
37
|
onChange(newValues);
|
38
38
|
};
|
39
39
|
return (React__default.createElement("div", { className: 'flex flex-col gap-2' },
|
40
|
-
React__default.createElement(InputComponent, {
|
40
|
+
React__default.createElement(InputComponent, { field: __assign(__assign({}, field), { required: false, label: index > 0 ? null : field.label, id: "".concat(field.id, "-").concat(index) }), value: value, onChange: function (v) {
|
41
41
|
var newValues = __spreadArray([], values, true);
|
42
42
|
newValues[index] = v;
|
43
43
|
onChange(newValues);
|
@@ -61,46 +61,41 @@ var OneOfMultiple = function (_a) {
|
|
61
61
|
React__default.createElement(CopyIcon, { className: 'inline ml-2' }))))));
|
62
62
|
};
|
63
63
|
var MultipleFieldCreator = function (_a) {
|
64
|
-
var
|
65
|
-
var formValues =
|
64
|
+
var field = _a.field, onChange = _a.onChange, value = _a.value;
|
65
|
+
var _b = useFormContext(), formValues = _b.formValues, setFormValues = _b.setFormValues, inputOverrides = _b.inputOverrides;
|
66
66
|
var defaultOnChange = function (v) {
|
67
|
-
var formValuesCopy =
|
68
|
-
var fieldPath = getPathFromField(field);
|
69
|
-
set(formValuesCopy, fieldPath, v);
|
67
|
+
var formValuesCopy = updateFormValuesWithFieldValue(field, v, formValues);
|
70
68
|
setFormValues(formValuesCopy);
|
71
69
|
};
|
72
70
|
var initialVal = value !== undefined ? value : getFieldValue(field, formValues);
|
73
71
|
var initialValues = (initialVal !== undefined ? (Array.isArray(initialVal) ? initialVal : [initialVal]) : [null]);
|
74
72
|
var InputComponent = __assign(__assign({}, inputMap), (inputOverrides !== null && inputOverrides !== void 0 ? inputOverrides : {}))[field.type];
|
75
73
|
return React__default.createElement("div", null, initialValues === null || initialValues === void 0 ? void 0 : initialValues.map(function (value, index) {
|
76
|
-
return React__default.createElement(OneOfMultiple, {
|
74
|
+
return React__default.createElement(OneOfMultiple, { key: "".concat(field.id, "-").concat(index), InputComponent: InputComponent, field: field, value: value, index: index, onChange: onChange !== null && onChange !== void 0 ? onChange : defaultOnChange, values: initialValues });
|
77
75
|
}));
|
78
76
|
};
|
79
77
|
var FieldCreator = function (_a) {
|
80
78
|
var _b;
|
81
|
-
var field = _a.field,
|
82
|
-
var
|
79
|
+
var field = _a.field, value = _a.value, onChange = _a.onChange, className = _a.className, _c = _a.defaultClassName, defaultClassName = _c === void 0 ? 'py-2 flex flex-col gap-8' : _c;
|
80
|
+
var _d = useFormContext(), form = _d.form, inputOverrides = _d.inputOverrides, setFormValues = _d.setFormValues, formValues = _d.formValues;
|
83
81
|
var InputComponent = __assign(__assign({}, inputMap), (inputOverrides !== null && inputOverrides !== void 0 ? inputOverrides : {}))[field.type];
|
84
|
-
var updateFormValues = function (v) {
|
85
|
-
setFormValues(cleanUnusedDependenciesFromFormValues(form, v));
|
86
|
-
};
|
87
82
|
if (!checkCondition(field, formValues)) {
|
88
83
|
return null;
|
89
84
|
}
|
90
85
|
var defaultOnChange = function (v) {
|
91
|
-
var formValuesCopy =
|
92
|
-
|
93
|
-
set(formValuesCopy, fieldPath, v);
|
94
|
-
updateFormValues(formValuesCopy);
|
86
|
+
var formValuesCopy = updateFormValuesWithFieldValue(field, v, formValues);
|
87
|
+
setFormValues(cleanUnusedDependenciesFromFormValues(form, formValuesCopy));
|
95
88
|
};
|
89
|
+
var onChangeFn = onChange !== null && onChange !== void 0 ? onChange : defaultOnChange;
|
96
90
|
var initialValue = value !== undefined ? value : getFieldValue(field, formValues);
|
91
|
+
console.log("initialValue: ".concat(field.id), initialValue);
|
97
92
|
return InputComponent !== undefined
|
98
93
|
? React__default.createElement("div", { className: index$1.makeClassName({
|
99
94
|
className: className,
|
100
95
|
defaultClassName: defaultClassName
|
101
96
|
}) }, field.multiple === true
|
102
|
-
? React__default.createElement(MultipleFieldCreator, { field: field,
|
103
|
-
: React__default.createElement(InputComponent, { field: field,
|
97
|
+
? React__default.createElement(MultipleFieldCreator, { field: field, onChange: onChange, value: initialValue })
|
98
|
+
: React__default.createElement(InputComponent, { field: field, onChange: onChangeFn, value: Array.isArray(initialValue) ? initialValue[0] : initialValue }))
|
104
99
|
: React__default.createElement("div", null,
|
105
100
|
React__default.createElement("p", { className: 'font-bold mb-2' },
|
106
101
|
React__default.createElement(ExclamationTriangleIcon, { className: 'inline' }),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FieldCreator.js","sources":["../../../../../src/Form/Components/FieldCreator.tsx"],"sourcesContent":["import inputMap from '@/Form/Components/Inputs/inputMap'\nimport { type IFormValues, type IFieldInputProps, type IFormField, type IValueChangeFn, type IValueType, type IForm, type IFormValueState } from '@/Form/Creator/FormCreatorTypes'\nimport { checkCondition, cleanUnusedDependenciesFromFormValues, getFieldValue, getPathFromField } from '@/Form/helpers'\nimport { Button, utils } from '@axdspub/axiom-ui-utilities'\nimport { CheckIcon, CopyIcon, Cross1Icon, ExclamationTriangleIcon, PlusIcon, TrashIcon } from '@radix-ui/react-icons'\nimport { set } from 'lodash'\nimport React, { useState, type ReactElement } from 'react'\n\ninterface IFieldCreator {\n field: IFormField\n form: IForm\n onChange?: IValueChangeFn\n className?: string\n defaultClassName?: string\n value?: IValueType | IValueType[]\n formValueState: IFormValueState\n inputOverrides?: Record<string, React.FC<IFieldInputProps>>\n}\n\nconst toolButtonClass = 'border-white hover:border-single hover:border-1 hover:border-slate-400'\n\nconst DeleteMultiple = ({\n doDelete\n}: {\n doDelete: () => void\n}): ReactElement => {\n const [confirm, setConfirm] = useState(false)\n\n return (\n <>\n {\n confirm\n ? <p className='flex flex-row gap-2 text-sm'><span className='text-slate-600'>Deleting: </span> Are you sure?\n <Button size='xs' type='submit'\n onClick={() => {\n doDelete()\n setConfirm(false)\n }}>Yes <CheckIcon className='inline ml-2' />\n </Button>\n <Button size='xs' type='alert'\n onClick={() => {\n setConfirm(false)\n }}>Cancel <Cross1Icon className='inline ml-2' />\n </Button>\n </p>\n : <Button size='xs' className={toolButtonClass} onClick={() => { setConfirm(true) }}>\n Delete <TrashIcon className='inline ml-2 fill-white' />\n </Button>\n }\n </>\n )\n}\n\nconst OneOfMultiple = ({\n InputComponent,\n field,\n form,\n value,\n index,\n onChange,\n values,\n formValueState\n\n}: {\n InputComponent: React.FC<IFieldInputProps>\n field: IFormField\n form: IForm\n value: IValueType\n index: number\n onChange: (v: IValueType[] | undefined) => void\n values: IValueType[]\n formValueState: [IFormValues, (v: IFormValues) => void]\n\n}): ReactElement => {\n const addValue = (v: IValueType | null): void => {\n const newValues = [...values]\n newValues.splice(index + 1, 0, v)\n onChange(newValues)\n }\n\n return (\n <div className='flex flex-col gap-2'>\n <InputComponent\n formValueState={formValueState}\n form={form}\n field={{\n ...field,\n required: false,\n label: index > 0 ? null : field.label,\n id: `${field.id}-${index}`\n }}\n value={value}\n onChange={(v) => {\n const newValues = [...values]\n newValues[index] = v as IValueType\n onChange(newValues)\n }}\n />\n\n <div className='flex flex-row justify-between w-full p-2'>\n {index > 0 && (\n <DeleteMultiple doDelete={() => {\n const newValues = [...values]\n newValues.splice(index, 1)\n onChange(newValues)\n }} />\n )}\n <div className='ml-auto flex gap-2'>\n <Button\n size='xs'\n className={toolButtonClass}\n onClick={() => {\n addValue(null)\n }}>Add <PlusIcon className='inline ml-2' /></Button>\n <Button\n size='xs'\n className={toolButtonClass}\n onClick={() => {\n addValue(structuredClone(value))\n }}>Duplicate <CopyIcon className='inline ml-2' />\n </Button>\n </div>\n </div>\n </div>\n )\n}\n\nconst MultipleFieldCreator = ({\n form,\n field,\n onChange,\n value,\n formValueState,\n inputOverrides\n}: IFieldCreator): ReactElement => {\n const [formValues, setFormValues] = formValueState\n const defaultOnChange = (v: IValueType[] | undefined): void => {\n const formValuesCopy = structuredClone(formValues)\n const fieldPath = getPathFromField(field)\n set(formValuesCopy, fieldPath, v)\n setFormValues(formValuesCopy)\n }\n\n const initialVal = value !== undefined ? value : getFieldValue(field, formValues)\n const initialValues = (initialVal !== undefined ? (Array.isArray(initialVal) ? initialVal : [initialVal]) : [null])\n\n const InputComponent = {\n ...inputMap,\n ...(inputOverrides ?? {})\n }[field.type]\n\n return <div>\n {\n initialValues?.map((value, index) => {\n return <OneOfMultiple\n formValueState={formValueState}\n key={`${field.id}-${index}`}\n InputComponent={InputComponent}\n form={form}\n field={field}\n value={value}\n index={index}\n onChange={onChange ?? defaultOnChange}\n values={initialValues}\n />\n })\n }\n </div>\n}\n\nconst FieldCreator = ({\n field,\n form,\n value,\n onChange,\n className,\n defaultClassName = 'py-2 flex flex-col gap-8',\n formValueState,\n inputOverrides\n}: IFieldCreator): ReactElement | null => {\n const [formValues, setFormValues] = formValueState\n const InputComponent = {\n ...inputMap,\n ...(inputOverrides ?? {})\n }[field.type]\n\n const updateFormValues = (v: IFormValues): void => {\n setFormValues(cleanUnusedDependenciesFromFormValues(form, v))\n }\n\n if (!checkCondition(field, formValues)) {\n return null\n }\n\n const defaultOnChange = (v: IValueType | IValueType[] | undefined): void => {\n const formValuesCopy = structuredClone(formValues)\n const fieldPath = getPathFromField(field)\n set(formValuesCopy, fieldPath, v)\n updateFormValues(formValuesCopy)\n }\n const initialValue = value !== undefined ? value : getFieldValue(field, formValues)\n return InputComponent !== undefined\n ? <div className={utils.makeClassName({\n className,\n defaultClassName\n })}>{\n field.multiple === true\n ? <MultipleFieldCreator\n field={field}\n form={form}\n onChange={onChange}\n value={initialValue}\n formValueState={formValueState}\n inputOverrides={inputOverrides}\n />\n : <InputComponent\n field={field}\n form={form}\n onChange={onChange ?? defaultOnChange}\n value={Array.isArray(initialValue) ? initialValue[0] : initialValue}\n formValueState={formValueState}\n inputOverrides={inputOverrides}\n />\n\n }</div>\n : <div>\n <p className='font-bold mb-2'><ExclamationTriangleIcon className='inline' /> {field.label ?? ''}</p>\n <p className='p-4 text-sm bg-slate-100'>No component definition for <span className='text-rose-800 font-mono text-xs bg-slate-300 p-2'>type</span><span className='p-2 bg-slate-700 text-white font-mono text-xs'>{field.type}</span> at <span className='text-rose-800 font-mono text-xs bg-slate-300 p-2'>id</span><span className='p-2 bg-slate-700 text-white font-mono text-xs'>{field.id}</span></p>\n </div>\n}\n\nexport default FieldCreator\n"],"names":["React","utils"],"mappings":";;;;;;;;AAmBA,IAAM,eAAe,GAAG,wEAAwE;AAEhG,IAAM,cAAc,GAAG,UAAC,EAIvB,EAAA;AAHC,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA;IAIF,IAAA,EAAA,GAAwB,QAAQ,CAAC,KAAK,CAAC,EAAtC,OAAO,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,UAAU,GAAA,EAAA,CAAA,CAAA,CAAmB;IAE7C,QACEA,4DAEI;AACE,UAAEA,cAAA,CAAA,aAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAC,6BAA6B,EAAA;YAACA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,gBAAgB,EAAkB,EAAA,YAAA,CAAA;;YAC3FA,cAAC,CAAA,aAAA,CAAA,MAAM,EAAC,EAAA,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,EAC7B,OAAO,EAAE,YAAA;AACP,oBAAA,QAAQ,EAAE;oBACV,UAAU,CAAC,KAAK,CAAC;iBAClB,EAAA;;AAAM,gBAAAA,cAAA,CAAA,aAAA,CAAC,SAAS,EAAC,EAAA,SAAS,EAAC,aAAa,GAAG,CACrC;YACTA,cAAC,CAAA,aAAA,CAAA,MAAM,EAAC,EAAA,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAC5B,OAAO,EAAE,YAAA;oBACP,UAAU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ACnE,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAAA,CAC9B;AAGR,UAAEA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,IAAA;YACEA,cAAG,CAAA,aAAA,CAAA,GAAA,EAAA,EAAA,SAAS,EAAC,gBAAgB,EAAA;AAAC,gBAAAA,cAAA,CAAA,aAAA,CAAC,uBAAuB,EAAA,EAAC,SAAS,EAAC,QAAQ,EAAG,CAAA;AAAE,gBAAA,GAAA,EAAA,CAAA,EAAA,GAAA,KAAK,CAAC,KAAK,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,EAAE,CAAK;YACpGA,cAAG,CAAA,aAAA,CAAA,GAAA,EAAA,EAAA,SAAS,EAAC,0BAA0B,EAAA;;gBAA6BA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,kDAAkD,EAAY,EAAA,MAAA,CAAA;AAAA,gBAAAA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,+CAA+C,IAAE,KAAK,CAAC,IAAI,CAAQ;;gBAAIA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,kDAAkD,EAAU,EAAA,IAAA,CAAA;gBAAAA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,+CAA+C,EAAE,EAAA,KAAK,CAAC,EAAE,CAAQ,CAAI,CACtY;AACZ;;;;"}
|
1
|
+
{"version":3,"file":"FieldCreator.js","sources":["../../../../../src/Form/Components/FieldCreator.tsx"],"sourcesContent":["import inputMap from '@/Form/Components/Inputs/inputMap'\nimport { useFormContext } from '@/Form/Creator/FormContextProvider'\nimport { type IFieldInputProps, type IFormField, type IValueChangeFn, type IValueType } from '@/Form/Creator/FormCreatorTypes'\nimport { checkCondition, cleanUnusedDependenciesFromFormValues, getFieldValue, updateFormValuesWithFieldValue } from '@/Form/helpers'\nimport { Button, utils } from '@axdspub/axiom-ui-utilities'\nimport { CheckIcon, CopyIcon, Cross1Icon, ExclamationTriangleIcon, PlusIcon, TrashIcon } from '@radix-ui/react-icons'\nimport React, { useState, type ReactElement } from 'react'\n\ninterface IFieldCreator {\n field: IFormField\n onChange?: IValueChangeFn\n className?: string\n defaultClassName?: string\n value?: IValueType | IValueType[]\n}\n\nconst toolButtonClass = 'border-white hover:border-single hover:border-1 hover:border-slate-400'\n\nconst DeleteMultiple = ({\n doDelete\n}: {\n doDelete: () => void\n}): ReactElement => {\n const [confirm, setConfirm] = useState(false)\n\n return (\n <>\n {\n confirm\n ? <p className='flex flex-row gap-2 text-sm'><span className='text-slate-600'>Deleting: </span> Are you sure?\n <Button size='xs' type='submit'\n onClick={() => {\n doDelete()\n setConfirm(false)\n }}>Yes <CheckIcon className='inline ml-2' />\n </Button>\n <Button size='xs' type='alert'\n onClick={() => {\n setConfirm(false)\n }}>Cancel <Cross1Icon className='inline ml-2' />\n </Button>\n </p>\n : <Button size='xs' className={toolButtonClass} onClick={() => { setConfirm(true) }}>\n Delete <TrashIcon className='inline ml-2 fill-white' />\n </Button>\n }\n </>\n )\n}\n\nconst OneOfMultiple = ({\n InputComponent,\n field,\n value,\n index,\n onChange,\n values\n\n}: {\n InputComponent: React.FC<IFieldInputProps>\n field: IFormField\n value: IValueType\n index: number\n onChange: (v: IValueType[] | undefined) => void\n values: IValueType[]\n}): ReactElement => {\n const addValue = (v: IValueType | null): void => {\n const newValues = [...values]\n newValues.splice(index + 1, 0, v)\n onChange(newValues)\n }\n\n return (\n <div className='flex flex-col gap-2'>\n <InputComponent\n field={{\n ...field,\n required: false,\n label: index > 0 ? null : field.label,\n id: `${field.id}-${index}`\n }}\n value={value}\n onChange={(v) => {\n const newValues = [...values]\n newValues[index] = v as IValueType\n onChange(newValues)\n }}\n />\n\n <div className='flex flex-row justify-between w-full p-2'>\n {index > 0 && (\n <DeleteMultiple doDelete={() => {\n const newValues = [...values]\n newValues.splice(index, 1)\n onChange(newValues)\n }} />\n )}\n <div className='ml-auto flex gap-2'>\n <Button\n size='xs'\n className={toolButtonClass}\n onClick={() => {\n addValue(null)\n }}>Add <PlusIcon className='inline ml-2' /></Button>\n <Button\n size='xs'\n className={toolButtonClass}\n onClick={() => {\n addValue(structuredClone(value))\n }}>Duplicate <CopyIcon className='inline ml-2' />\n </Button>\n </div>\n </div>\n </div>\n )\n}\n\nconst MultipleFieldCreator = ({\n field,\n onChange,\n value\n}: IFieldCreator): ReactElement => {\n const { formValues, setFormValues, inputOverrides } = useFormContext()\n const defaultOnChange = (v: IValueType[] | undefined): void => {\n const formValuesCopy = updateFormValuesWithFieldValue(field, v, formValues)\n setFormValues(formValuesCopy)\n }\n\n const initialVal = value !== undefined ? value : getFieldValue(field, formValues)\n const initialValues = (initialVal !== undefined ? (Array.isArray(initialVal) ? initialVal : [initialVal]) : [null])\n\n const InputComponent = {\n ...inputMap,\n ...(inputOverrides ?? {})\n }[field.type]\n\n return <div>\n {\n initialValues?.map((value, index) => {\n return <OneOfMultiple\n key={`${field.id}-${index}`}\n InputComponent={InputComponent}\n field={field}\n value={value}\n index={index}\n onChange={onChange ?? defaultOnChange}\n values={initialValues}\n />\n })\n }\n </div>\n}\n\nconst FieldCreator = ({\n field,\n value,\n onChange,\n className,\n defaultClassName = 'py-2 flex flex-col gap-8'\n}: IFieldCreator): ReactElement | null => {\n const { form, inputOverrides, setFormValues, formValues } = useFormContext()\n const InputComponent = {\n ...inputMap,\n ...(inputOverrides ?? {})\n }[field.type]\n\n if (!checkCondition(field, formValues)) {\n return null\n }\n\n const defaultOnChange = (v: IValueType | IValueType[] | undefined): void => {\n const formValuesCopy = updateFormValuesWithFieldValue(field, v as IValueType, formValues)\n setFormValues(cleanUnusedDependenciesFromFormValues(form, formValuesCopy))\n }\n const onChangeFn = onChange ?? defaultOnChange\n\n const initialValue = value !== undefined ? value : getFieldValue(field, formValues)\n console.log(`initialValue: ${field.id}`, initialValue)\n return InputComponent !== undefined\n ? <div className={utils.makeClassName({\n className,\n defaultClassName\n })}>{\n field.multiple === true\n ? <MultipleFieldCreator\n field={field}\n onChange={onChange}\n value={initialValue}\n />\n : <InputComponent\n field={field}\n onChange={onChangeFn}\n value={Array.isArray(initialValue) ? initialValue[0] : initialValue}\n />\n\n }</div>\n : <div>\n <p className='font-bold mb-2'><ExclamationTriangleIcon className='inline' /> {field.label ?? ''}</p>\n <p className='p-4 text-sm bg-slate-100'>No component definition for <span className='text-rose-800 font-mono text-xs bg-slate-300 p-2'>type</span><span className='p-2 bg-slate-700 text-white font-mono text-xs'>{field.type}</span> at <span className='text-rose-800 font-mono text-xs bg-slate-300 p-2'>id</span><span className='p-2 bg-slate-700 text-white font-mono text-xs'>{field.id}</span></p>\n </div>\n}\n\nexport default FieldCreator\n"],"names":["React","utils"],"mappings":";;;;;;;;AAgBA,IAAM,eAAe,GAAG,wEAAwE;AAEhG,IAAM,cAAc,GAAG,UAAC,EAIvB,EAAA;AAHC,IAAA,IAAA,QAAQ,GAAA,EAAA,CAAA,QAAA;IAIF,IAAA,EAAA,GAAwB,QAAQ,CAAC,KAAK,CAAC,EAAtC,OAAO,GAAA,EAAA,CAAA,CAAA,CAAA,EAAE,UAAU,GAAA,EAAA,CAAA,CAAA,CAAmB;IAE7C,QACEA,4DAEI;AACE,UAAEA,cAAA,CAAA,aAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAC,6BAA6B,EAAA;YAACA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,gBAAgB,EAAkB,EAAA,YAAA,CAAA;;YAC3FA,cAAC,CAAA,aAAA,CAAA,MAAM,EAAC,EAAA,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,EAC7B,OAAO,EAAE,YAAA;AACP,oBAAA,QAAQ,EAAE;oBACV,UAAU,CAAC,KAAK,CAAC;iBAClB,EAAA;;AAAM,gBAAAA,cAAA,CAAA,aAAA,CAAC,SAAS,EAAC,EAAA,SAAS,EAAC,aAAa,GAAG,C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pGA,cAAG,CAAA,aAAA,CAAA,GAAA,EAAA,EAAA,SAAS,EAAC,0BAA0B,EAAA;;gBAA6BA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,kDAAkD,EAAY,EAAA,MAAA,CAAA;AAAA,gBAAAA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAC,+CAA+C,IAAE,KAAK,CAAC,IAAI,CAAQ;;gBAAIA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,kDAAkD,EAAU,EAAA,IAAA,CAAA;gBAAAA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,+CAA+C,EAAE,EAAA,KAAK,CAAC,EAAE,CAAQ,CAAI,CACtY;AACZ;;;;"}
|
@@ -2,11 +2,10 @@ import { __assign } from '../../../node_modules/tslib/tslib.es6.js';
|
|
2
2
|
import React__default from 'react';
|
3
3
|
|
4
4
|
var FieldLabelText = function (field) {
|
5
|
-
return (React__default.createElement("
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
field.required === true ? React__default.createElement("span", { className: 'text-red-500' }, "*") : '')));
|
5
|
+
return (React__default.createElement("strong", null,
|
6
|
+
field.label,
|
7
|
+
" ",
|
8
|
+
field.required === true ? React__default.createElement("span", { className: 'text-red-500' }, "*") : ''));
|
10
9
|
};
|
11
10
|
var FieldDescriptionText = function (field) {
|
12
11
|
return (React__default.createElement(React__default.Fragment, null, field.description !== undefined
|
@@ -15,7 +14,8 @@ var FieldDescriptionText = function (field) {
|
|
15
14
|
};
|
16
15
|
var FieldLabel = function (field) {
|
17
16
|
return React__default.createElement(React__default.Fragment, null,
|
18
|
-
React__default.createElement(
|
17
|
+
React__default.createElement("p", null,
|
18
|
+
React__default.createElement(FieldLabelText, __assign({}, field))),
|
19
19
|
React__default.createElement(FieldDescriptionText, __assign({}, field)));
|
20
20
|
};
|
21
21
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FieldLabel.js","sources":["../../../../../src/Form/Components/FieldLabel.tsx"],"sourcesContent":["import { type IFormField } from '@/Form/Creator/FormCreatorTypes'\nimport React, { type ReactElement } from 'react'\n\nexport const FieldLabelText = (field: IFormField): ReactElement => {\n return (\n <
|
1
|
+
{"version":3,"file":"FieldLabel.js","sources":["../../../../../src/Form/Components/FieldLabel.tsx"],"sourcesContent":["import { type IFormField } from '@/Form/Creator/FormCreatorTypes'\nimport React, { type ReactElement } from 'react'\n\nexport const FieldLabelText = (field: IFormField): ReactElement => {\n return (\n <strong>{field.label} { field.required === true ? <span className='text-red-500'>*</span> : ''}</strong>\n )\n}\n\nexport const FieldDescriptionText = (field: IFormField): ReactElement => {\n return (\n <>{\n field.description !== undefined\n ? <p className='text-xs py-2'>{field.description}</p>\n : ''\n }</>\n )\n}\n\nconst FieldLabel = (field: IFormField): ReactElement => {\n return <>\n <p><FieldLabelText {...field} /></p>\n <FieldDescriptionText {...field} />\n\n </>\n}\n\nexport default FieldLabel\n"],"names":["React"],"mappings":";;;AAGO,IAAM,cAAc,GAAG,UAAC,KAAiB,EAAA;AAC9C,IAAA,QACEA,cAAA,CAAA,aAAA,CAAA,QAAA,EAAA,IAAA;AAAS,QAAA,KAAK,CAAC,KAAK;;AAAI,QAAA,KAAK,CAAC,QAAQ,KAAK,IAAI,GAAGA,cAAM,CAAA,aAAA,CAAA,MAAA,EAAA,EAAA,SAAS,EAAC,cAAc,QAAS,GAAG,EAAE,CAAU;AAE5G;AAEO,IAAM,oBAAoB,GAAG,UAAC,KAAiB,EAAA;AACpD,IAAA,QACEA,cACE,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA,EAAA,KAAK,CAAC,WAAW,KAAK;UAClBA,oCAAG,SAAS,EAAC,cAAc,EAAE,EAAA,KAAK,CAAC,WAAW;AAChD,UAAE,EAAE,CACJ;AAER;AAEM,IAAA,UAAU,GAAG,UAAC,KAAiB,EAAA;IACnC,OAAOA,cAAA,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA;AACL,QAAAA,cAAA,CAAA,aAAA,CAAA,GAAA,EAAA,IAAA;AAAG,YAAAA,cAAA,CAAA,aAAA,CAAC,cAAc,EAAA,QAAA,CAAA,EAAA,EAAK,KAAK,CAAA,CAAI,CAAI;AACpC,QAAAA,cAAA,CAAA,aAAA,CAAC,oBAAoB,EAAA,QAAA,CAAA,EAAA,EAAK,KAAK,CAAA,CAAI,CAElC;AACL;;;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { __assign } from '../../../../node_modules/tslib/tslib.es6.js';
|
2
2
|
import FieldLabel from '../FieldLabel.js';
|
3
|
-
import React__default, { useState
|
3
|
+
import React__default, { useState } from 'react';
|
4
4
|
|
5
5
|
var DateInput = function (_a) {
|
6
6
|
var _b;
|
@@ -11,12 +11,8 @@ var DateInput = function (_a) {
|
|
11
11
|
field.id,
|
12
12
|
" is missing 'options'");
|
13
13
|
}
|
14
|
-
var _c = useState(
|
15
|
-
var _d =
|
16
|
-
var _e = (_b = field.constraints) !== null && _b !== void 0 ? _b : {}, minDate = _e.minDate, maxDate = _e.maxDate;
|
17
|
-
useEffect(function () {
|
18
|
-
setInputValue(formatValue(value));
|
19
|
-
}, [value]);
|
14
|
+
var _c = useState(null), error = _c[0], setError = _c[1];
|
15
|
+
var _d = (_b = field.constraints) !== null && _b !== void 0 ? _b : {}, minDate = _d.minDate, maxDate = _d.maxDate;
|
20
16
|
// Convert the value to the format expected by date input (YYYY-MM-DD)
|
21
17
|
var formatValue = function (val) {
|
22
18
|
if (!val)
|
@@ -36,6 +32,7 @@ var DateInput = function (_a) {
|
|
36
32
|
return '';
|
37
33
|
}
|
38
34
|
};
|
35
|
+
var inputValue = formatValue(value);
|
39
36
|
var validateDate = function (dateStr) {
|
40
37
|
if (!minDate && !maxDate)
|
41
38
|
return null;
|
@@ -51,15 +48,14 @@ var DateInput = function (_a) {
|
|
51
48
|
return null;
|
52
49
|
};
|
53
50
|
var handleChange = function (e) {
|
54
|
-
var
|
55
|
-
setInputValue(newInputValue);
|
51
|
+
var newValue = e.target.value;
|
56
52
|
// Only notify parent of change if we have a complete valid date
|
57
|
-
if (
|
53
|
+
if (newValue) {
|
58
54
|
// Create date in UTC by appending T00:00:00Z to the input value
|
59
|
-
var date = new Date(
|
55
|
+
var date = new Date(newValue + 'T00:00:00Z');
|
60
56
|
// Check if it's a valid date and the year is reasonable (4 digits)
|
61
57
|
if (!isNaN(date.getTime()) && date.getUTCFullYear() > 999) {
|
62
|
-
var validationError = validateDate(
|
58
|
+
var validationError = validateDate(newValue);
|
63
59
|
setError(validationError);
|
64
60
|
if (!validationError) {
|
65
61
|
onChange(date.toISOString());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Date.js","sources":["../../../../../../src/Form/Components/Inputs/Date.tsx"],"sourcesContent":["import FieldLabel from '@/Form/Components/FieldLabel'\nimport { type IFieldInputProps } from '@/Form/Creator/FormCreatorTypes'\nimport React, { type ReactElement, useState
|
1
|
+
{"version":3,"file":"Date.js","sources":["../../../../../../src/Form/Components/Inputs/Date.tsx"],"sourcesContent":["import FieldLabel from '@/Form/Components/FieldLabel'\nimport { type IFieldInputProps } from '@/Form/Creator/FormCreatorTypes'\nimport React, { type ReactElement, useState } from 'react'\n\nconst DateInput = ({ field, onChange, value }: IFieldInputProps): ReactElement => {\n if (field.type !== 'date') {\n return <p>Field config for {field.id} is missing 'options'</p>\n }\n\n const [error, setError] = useState<string | null>(null)\n const { minDate, maxDate } = field.constraints ?? {}\n\n // Convert the value to the format expected by date input (YYYY-MM-DD)\n const formatValue = (val: string | undefined | null): string => {\n if (!val) return ''\n try {\n // Ensure the value is in the correct format\n const date = new Date(val)\n if (isNaN(date.getTime())) return ''\n\n // Format to YYYY-MM-DD using UTC to avoid timezone issues\n const year = date.getUTCFullYear()\n const month = String(date.getUTCMonth() + 1).padStart(2, '0')\n const day = String(date.getUTCDate()).padStart(2, '0')\n\n return `${year}-${month}-${day}`\n } catch {\n return ''\n }\n }\n\n const inputValue = formatValue(value as string)\n\n const validateDate = (dateStr: string): string | null => {\n if (!minDate && !maxDate) return null\n\n const inputDate = new Date(dateStr + 'T00:00:00Z')\n const minDateObj = minDate ? new Date(minDate) : null\n const maxDateObj = maxDate ? new Date(maxDate) : null\n\n if (minDateObj && inputDate < minDateObj) {\n return `Date must be after ${formatValue(minDate)}`\n }\n if (maxDateObj && inputDate > maxDateObj) {\n return `Date must be before ${formatValue(maxDate)}`\n }\n return null\n }\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {\n const newValue = e.target.value\n // Only notify parent of change if we have a complete valid date\n if (newValue) {\n // Create date in UTC by appending T00:00:00Z to the input value\n const date = new Date(newValue + 'T00:00:00Z')\n // Check if it's a valid date and the year is reasonable (4 digits)\n if (!isNaN(date.getTime()) && date.getUTCFullYear() > 999) {\n const validationError = validateDate(newValue)\n setError(validationError)\n if (!validationError) {\n onChange(date.toISOString())\n }\n }\n } else {\n setError(null)\n onChange(undefined)\n }\n }\n\n const getConstraintMessage = (): string | null => {\n if (!minDate && !maxDate) return null\n const parts = []\n if (minDate) parts.push(`after ${formatValue(minDate)}`)\n if (maxDate) parts.push(`before ${formatValue(maxDate)}`)\n return `Must be ${parts.join(' and ')}`\n }\n\n const constraintMessage = getConstraintMessage()\n\n return (\n <div>\n <div className=\"flex flex-wrap items-baseline gap-2\">\n <label htmlFor={field.id} className=\"flex-1 min-w-[200px]\">\n <FieldLabel {...field} />\n </label>\n {constraintMessage && (\n <span className=\"text-sm text-slate-500 italic\">\n {constraintMessage}\n </span>\n )}\n </div>\n <input\n id={field.id}\n className={`border ${error ? 'border-red-500' : 'border-slate-300'} p-2 w-full`}\n data-testid={field.id}\n type=\"date\"\n value={inputValue}\n onChange={handleChange}\n min={minDate ? formatValue(minDate) : undefined}\n max={maxDate ? formatValue(maxDate) : undefined}\n />\n {error && <p className=\"text-red-500 text-sm mt-1\">{error}</p>}\n </div>\n )\n}\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