@syncfusion/ej2-react-form-renderer 0.1.0-beta → 0.1.2-beta
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/README.md +3 -10
- package/package.json +1 -1
- package/src/CheckboxGroup.js +3 -2
- package/src/ConditionalRuleEngine.d.ts +295 -0
- package/src/ConditionalRuleEngine.js +566 -0
- package/src/DataGridComponent.d.ts +0 -1
- package/src/DataGridComponent.js +9 -22
- package/src/FormRenderer.d.ts +28 -7
- package/src/FormRenderer.js +342 -202
- package/src/MinMaxRuleEngine.d.ts +95 -0
- package/src/MinMaxRuleEngine.js +361 -0
- package/src/expressions/DependencyTracker.d.ts +30 -0
- package/src/expressions/DependencyTracker.js +128 -0
- package/src/expressions/ExpressionEngine.d.ts +81 -0
- package/src/expressions/ExpressionEngine.js +503 -0
- package/src/expressions/ExpressionParser.d.ts +39 -0
- package/src/expressions/ExpressionParser.js +270 -0
- package/src/json-converter.d.ts +32 -31
- package/src/json-converter.js +313 -284
- package/src/parser.js +22 -18
- package/src/renderFormField.d.ts +3 -1
- package/src/renderFormField.js +70 -46
- package/src/types/FormSchema.d.ts +36 -2
- package/src/utils.js +348 -0
- package/styles/form-renderer.base.css +49 -23
package/src/parser.js
CHANGED
|
@@ -91,7 +91,7 @@ export class UniversalJsonParser {
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
const schema = {
|
|
94
|
-
version: input.version || "1.0
|
|
94
|
+
version: input.version || "0.1.0",
|
|
95
95
|
components
|
|
96
96
|
};
|
|
97
97
|
const schemaValidation = validateFormSchema(schema);
|
|
@@ -253,7 +253,7 @@ export class UniversalJsonParser {
|
|
|
253
253
|
return { type: 'textbox', textboxType: 'url' };
|
|
254
254
|
}
|
|
255
255
|
if (/^\d{4}-\d{2}-\d{2}/.test(value)) {
|
|
256
|
-
return { type: '
|
|
256
|
+
return { type: 'date' };
|
|
257
257
|
}
|
|
258
258
|
// For generic strings, check field name patterns
|
|
259
259
|
const fieldNameMatch = this.matchFieldNamePattern(fieldName);
|
|
@@ -284,7 +284,7 @@ export class UniversalJsonParser {
|
|
|
284
284
|
if (/email|mail|e-?mail/.test(normalized))
|
|
285
285
|
return { type: 'textbox', textboxType: 'email' };
|
|
286
286
|
if (/date|birth|birthday|dob|created|updated/.test(normalized))
|
|
287
|
-
return { type: '
|
|
287
|
+
return { type: 'date' };
|
|
288
288
|
if (/phone|tel|mobile|cell|cellphone|msisdn/.test(normalized))
|
|
289
289
|
return { type: 'textbox', textboxType: 'number' };
|
|
290
290
|
if (/url|link|uri|website/.test(normalized))
|
|
@@ -394,9 +394,10 @@ export class UniversalJsonParser {
|
|
|
394
394
|
type: type,
|
|
395
395
|
label: element.title || element.label || this.humanizeFieldName(element.name),
|
|
396
396
|
defaultValue: element.defaultValue,
|
|
397
|
+
expressionValue: element.expressionValue,
|
|
397
398
|
...Object.keys(validation).length > 0 ? validation : undefined
|
|
398
399
|
};
|
|
399
|
-
if (type === 'dropdown' || type === 'multiselect' || type === 'radio' || type === '
|
|
400
|
+
if (type === 'dropdown' || type === 'multiselect' || type === 'radio' || type === 'splitButton') {
|
|
400
401
|
if (element.choices && Array.isArray(element.choices)) {
|
|
401
402
|
component.options = element.choices;
|
|
402
403
|
}
|
|
@@ -437,7 +438,8 @@ export class UniversalJsonParser {
|
|
|
437
438
|
id: this.generateComponentId(typeInference.type),
|
|
438
439
|
type: typeInference.type,
|
|
439
440
|
label: this.humanizeFieldName(key),
|
|
440
|
-
defaultValue: value
|
|
441
|
+
defaultValue: value,
|
|
442
|
+
expressionValue: undefined
|
|
441
443
|
};
|
|
442
444
|
if (typeInference.textboxType) {
|
|
443
445
|
component.textboxType = typeInference.textboxType;
|
|
@@ -449,7 +451,7 @@ export class UniversalJsonParser {
|
|
|
449
451
|
component.regex = VALIDATION_REGEX['URL'];
|
|
450
452
|
}
|
|
451
453
|
}
|
|
452
|
-
if (typeInference.type === '
|
|
454
|
+
if (typeInference.type === 'date' && component.defaultValue !== undefined && component.defaultValue !== null) {
|
|
453
455
|
const formatted = this.formatDateTimeValue(component.defaultValue);
|
|
454
456
|
if (formatted)
|
|
455
457
|
component.defaultValue = formatted;
|
|
@@ -487,9 +489,11 @@ export class UniversalJsonParser {
|
|
|
487
489
|
}
|
|
488
490
|
const component = {
|
|
489
491
|
id: propDef.id || this.generateComponentId(typeInfo.type),
|
|
492
|
+
name: propDef.name,
|
|
490
493
|
type: typeInfo.type,
|
|
491
494
|
label: propDef.title || propDef.label || this.humanizeFieldName(fieldName),
|
|
492
495
|
defaultValue: propDef.default || propDef.defaultValue || undefined,
|
|
496
|
+
expressionValue: propDef.expressionValue || undefined,
|
|
493
497
|
content: propDef.content,
|
|
494
498
|
buttonType: propDef.buttonType,
|
|
495
499
|
textboxType: propDef.textboxType,
|
|
@@ -511,12 +515,12 @@ export class UniversalJsonParser {
|
|
|
511
515
|
}
|
|
512
516
|
}
|
|
513
517
|
}
|
|
514
|
-
if (typeInfo.type === '
|
|
518
|
+
if (typeInfo.type === 'date' && component.defaultValue !== undefined && component.defaultValue !== null) {
|
|
515
519
|
const formatted = this.formatDateTimeValue(component.defaultValue);
|
|
516
520
|
if (formatted)
|
|
517
521
|
component.defaultValue = formatted;
|
|
518
522
|
}
|
|
519
|
-
if ((typeInfo.type === '
|
|
523
|
+
if ((typeInfo.type === 'splitButton' || typeInfo.type === 'dropdown' || typeInfo.type === 'multiselect' || typeInfo.type === 'radio') && (propDef.enum || propDef.options)) {
|
|
520
524
|
component.options = propDef.enum || propDef.options;
|
|
521
525
|
}
|
|
522
526
|
return component;
|
|
@@ -586,7 +590,7 @@ export class UniversalJsonParser {
|
|
|
586
590
|
if (/password|pwd|pass|security|secret|key/.test(fmt) || /password|pwd|pass|security|secret|key/.test(text))
|
|
587
591
|
return { type: 'textbox', textboxType: 'password' };
|
|
588
592
|
if (fmt === 'date' || fmt === 'date-time' || /date|birthday|dob/.test(text))
|
|
589
|
-
return { type: '
|
|
593
|
+
return { type: 'date' };
|
|
590
594
|
if (propDef.enum)
|
|
591
595
|
return { type: 'dropdown' };
|
|
592
596
|
if (propDef.options)
|
|
@@ -606,14 +610,14 @@ export class UniversalJsonParser {
|
|
|
606
610
|
return { type: 'button' };
|
|
607
611
|
if (schemaType === 'signature' || schemaType === 'sign')
|
|
608
612
|
return { type: 'signature' };
|
|
609
|
-
if (schemaType === 'image' || schemaType === '
|
|
610
|
-
return { type: '
|
|
611
|
-
if (schemaType === 'file' || schemaType === '
|
|
612
|
-
return { type: '
|
|
613
|
-
if (schemaType === 'color' || schemaType === '
|
|
614
|
-
return { type: '
|
|
615
|
-
if (schemaType === '
|
|
616
|
-
return { type: '
|
|
613
|
+
if (schemaType === 'image' || schemaType === 'imageEditor')
|
|
614
|
+
return { type: 'imageEditor' };
|
|
615
|
+
if (schemaType === 'file' || schemaType === 'fileUpload')
|
|
616
|
+
return { type: 'fileUpload' };
|
|
617
|
+
if (schemaType === 'color' || schemaType === 'colorPicker')
|
|
618
|
+
return { type: 'colorPicker' };
|
|
619
|
+
if (schemaType === 'splitButton')
|
|
620
|
+
return { type: 'splitButton' };
|
|
617
621
|
return { type: this.config.defaultTextType };
|
|
618
622
|
}
|
|
619
623
|
generateComponentId(type) {
|
|
@@ -716,7 +720,7 @@ export const validateFormSchema = (schema) => {
|
|
|
716
720
|
*/
|
|
717
721
|
export const sanitizeFormSchema = (schema) => {
|
|
718
722
|
const sanitized = {
|
|
719
|
-
version: schema.version || "1.0
|
|
723
|
+
version: schema.version || "0.1.0",
|
|
720
724
|
components: schema.components || []
|
|
721
725
|
};
|
|
722
726
|
const sanitizeComponent = (comp) => {
|
package/src/renderFormField.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ export interface RenderFormFieldProps {
|
|
|
8
8
|
component: FormComponent;
|
|
9
9
|
value?: any;
|
|
10
10
|
onChange: (value: any) => void;
|
|
11
|
+
formState?: any;
|
|
11
12
|
onBlur?: () => void;
|
|
12
13
|
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
13
14
|
ref?: any;
|
|
14
15
|
hasError?: boolean;
|
|
16
|
+
locale: string;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Renders a single form field component
|
|
18
20
|
*/
|
|
19
|
-
export declare const
|
|
21
|
+
export declare const RenderFormField: ({ component, value, onChange, onBlur, ref, hasError, onClick, locale, formState }: RenderFormFieldProps) => React.ReactNode;
|
package/src/renderFormField.js
CHANGED
|
@@ -12,8 +12,9 @@ import { MessageComponent } from '@syncfusion/ej2-react-notifications';
|
|
|
12
12
|
import { ImageEditorComponent } from '@syncfusion/ej2-react-image-editor';
|
|
13
13
|
import { DataGridComponent } from './DataGridComponent';
|
|
14
14
|
import { RichTextEditorComponent, Toolbar, HtmlEditor, Inject as RTEInject, Link, QuickToolbar } from '@syncfusion/ej2-react-richtexteditor';
|
|
15
|
-
import { mapButtonStyleToClass, mapPositionToJustifyContent, resolveButtonType } from './utils';
|
|
15
|
+
import { mapButtonStyleToClass, mapPositionToJustifyContent, resolveButtonType, resolveConditionalData, resolveOptions, useFetchOptions } from './utils';
|
|
16
16
|
import CheckboxGroup from './CheckboxGroup';
|
|
17
|
+
import { ConditionalRuleEngine } from './ConditionalRuleEngine';
|
|
17
18
|
/**
|
|
18
19
|
* Converts htmlAttributes from array format to object format
|
|
19
20
|
*/
|
|
@@ -33,14 +34,14 @@ const normalizeAttributes = (attributes) => {
|
|
|
33
34
|
/**
|
|
34
35
|
* Renders a single form field component
|
|
35
36
|
*/
|
|
36
|
-
export const
|
|
37
|
+
export const RenderFormField = ({ component, value, onChange, onBlur, ref, hasError = false, onClick, locale, formState }) => {
|
|
37
38
|
const commonProps = {
|
|
38
39
|
floatLabelType: (component.floatLabelType || 'Never'),
|
|
39
40
|
placeholder: component.placeholder || '',
|
|
40
41
|
enabled: !component.disabled,
|
|
41
42
|
};
|
|
42
43
|
const createValidationHandlers = (getValue) => {
|
|
43
|
-
const validateOn = component.validateOn || '
|
|
44
|
+
const validateOn = component.validateOn || 'Change';
|
|
44
45
|
const handlers = {};
|
|
45
46
|
// If validateOn is 'Change' or undefined, add change and blur handlers
|
|
46
47
|
if (!validateOn || validateOn === 'Change') {
|
|
@@ -56,45 +57,61 @@ export const renderFormField = ({ component, value, onChange, onBlur, ref, hasEr
|
|
|
56
57
|
};
|
|
57
58
|
const htmlAttrs = normalizeAttributes(component.htmlAttributes);
|
|
58
59
|
const errorClass = hasError ? 'e-error' : '';
|
|
59
|
-
const cssClass = `${component.cssClass || ''} ${errorClass}`.trim();
|
|
60
|
+
const cssClass = `${component.cssClass || ''} ${errorClass} ${component.size === 'Small' ? ' e-small' : component.size === 'Bigger' ? ' e-bigger' : ''}`.trim();
|
|
60
61
|
switch (component.type) {
|
|
61
62
|
case 'textbox':
|
|
62
|
-
return (_jsx(TextBoxComponent, { id: component.id, type: component.multiline ? 'hidden' : component.textboxType ? component.textboxType : 'text', name: component.id, ...commonProps, value: value !== undefined ? value : (component.defaultValue || ''), multiline: component.multiline, showClearButton: component.showClearButton, autocomplete: component.autocomplete === false ? 'off' : 'on', readonly: component.readOnly || false, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
63
|
+
return (_jsx(TextBoxComponent, { id: component.id, type: component.multiline ? 'hidden' : component.textboxType ? component.textboxType : 'text', name: component.id, locale: locale, ...commonProps, value: value !== undefined ? value : (component.defaultValue || ''), multiline: component.multiline, showClearButton: component.showClearButton, autocomplete: component.autocomplete === false ? 'off' : 'on', readonly: component.readOnly || false, cssClass: cssClass, htmlAttributes: htmlAttrs, appendTemplate: component.suffix, prependTemplate: component.prefix, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
63
64
|
case 'textarea':
|
|
64
|
-
return (_jsx(TextAreaComponent, { id: component.id, name: component.id, ...commonProps, value: value !== undefined ? value : (component.defaultValue || ''), cols: component.cols || 200, rows: component.textareaRows || 4, showClearButton: component.showClearButton || false, readonly: component.readOnly || false, maxLength: component?.maxLength || 255, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
65
|
+
return (_jsx(TextAreaComponent, { id: component.id, name: component.id, locale: locale, ...commonProps, value: value !== undefined ? value : (component.defaultValue || ''), cols: component.cols || 200, rows: component.textareaRows || 4, showClearButton: component.showClearButton || false, readonly: component.readOnly || false, maxLength: component?.maxLength || 255, cssClass: cssClass, htmlAttributes: htmlAttrs, appendTemplate: component.suffix, prependTemplate: component.prefix, resizeMode: 'Vertical', ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
65
66
|
case 'number':
|
|
66
|
-
|
|
67
|
+
value = value === "" ? undefined : value;
|
|
68
|
+
return (_jsx(NumericTextBoxComponent, { id: component.id, name: component.id, locale: locale, ...commonProps, value: value !== undefined || value !== "" ? value : (component.defaultValue || 0), decimals: component.decimals || 2, currency: component.currency, format: component.numberFormat || 'n2', step: component.step || 1, min: component.minValue || undefined, max: component.maxValue || undefined, readonly: component.readOnly || false, showClearButton: component.showClearButton || false, cssClass: cssClass, htmlAttributes: htmlAttrs, appendTemplate: component.suffix, prependTemplate: component.prefix, ...createValidationHandlers((args) => args.value || ''), ref: ref }, `${component.id}-${component.minValue}-${component.maxValue}`));
|
|
67
69
|
case 'checkbox':
|
|
68
70
|
const checkboxLabel = component.label && component.required
|
|
69
71
|
? `${component.label} *`
|
|
70
72
|
: component.label;
|
|
71
|
-
return (_jsx(CheckBoxComponent, { id: component.id, name: component.id, label: checkboxLabel, labelPosition: component.checkboxLabelPosition, checked: component.
|
|
72
|
-
case '
|
|
73
|
-
|
|
73
|
+
return (_jsx(CheckBoxComponent, { id: component.id, locale: locale, name: component.id, label: checkboxLabel, labelPosition: component.checkboxLabelPosition, checked: (component.checked ?? false) || (value ?? false), indeterminate: component.indeterminate || false, disabled: component.disabled, cssClass: cssClass, htmlAttributes: htmlAttrs, change: (args) => onChange(args.checked), ref: ref }, component.id));
|
|
74
|
+
case 'checkboxGroup':
|
|
75
|
+
const fetchedCheckboxOptions = useFetchOptions(component.options);
|
|
76
|
+
const resolvedCheckboxOptions = resolveOptions(component.options, fetchedCheckboxOptions);
|
|
77
|
+
const finalCheckboxOptions = resolvedCheckboxOptions.length > 0 ? resolvedCheckboxOptions : component.options || ['Option 1'];
|
|
78
|
+
return (_jsx(CheckboxGroup, { component: { ...component, options: finalCheckboxOptions }, value: value, onChange: (v) => onChange(v), optionRef: ref }, component.id));
|
|
74
79
|
case 'radio':
|
|
75
|
-
return (_jsx("div", { id: `${component.id}-group`, className: `e-radio-group ${errorClass}`, children: (component.options
|
|
80
|
+
return (_jsx("div", { id: `${component.id}-group`, className: `e-radio-group ${errorClass}`, children: (Array.isArray(component.options) ? component.options : ['Option 1']).map((option, idx) => {
|
|
76
81
|
const optionValue = option;
|
|
77
82
|
const optionText = option;
|
|
78
|
-
return (_jsx("div", { style: { marginBottom: '8px' }, children: _jsx(RadioButtonComponent, { id: `${component.id}_${idx}_${optionValue}`, name: component.id, label: optionText, disabled: component.disabled, value: optionValue, htmlAttributes: htmlAttrs, labelPosition: component.fieldLabelPosition, checked: component.defaultValue === optionValue, cssClass:
|
|
83
|
+
return (_jsx("div", { style: { marginBottom: '8px' }, children: _jsx(RadioButtonComponent, { id: `${component.id}_${idx}_${optionValue}`, name: component.id, label: optionText, locale: locale, disabled: component.disabled, value: optionValue, htmlAttributes: htmlAttrs, labelPosition: component.fieldLabelPosition, checked: component.defaultValue === optionValue || value === optionValue, cssClass: cssClass, change: (args) => {
|
|
79
84
|
if (args.value === optionValue) {
|
|
80
85
|
onChange(optionValue);
|
|
81
86
|
}
|
|
82
87
|
}, ref: ref ? (el) => ref(el, idx) : undefined }, component.id) }, idx));
|
|
83
88
|
}) }));
|
|
84
89
|
case 'dropdown':
|
|
85
|
-
|
|
90
|
+
const fetchedDropdownOptions = useFetchOptions(component.options);
|
|
91
|
+
const resolvedDropdownOptions = resolveOptions(component.options, fetchedDropdownOptions);
|
|
92
|
+
let finalDropdownOptions = resolvedDropdownOptions.length > 0 ? resolvedDropdownOptions : component.options || ['Option 1'];
|
|
93
|
+
if (component.conditions?.choiceBasedField) {
|
|
94
|
+
finalDropdownOptions = ConditionalRuleEngine.getChoiceBasedOptions(component.conditions.choiceBasedField, finalDropdownOptions, formState?.values, component.conditions.choiceBasedField.primaryFieldId);
|
|
95
|
+
if (finalDropdownOptions.length > 0 && value != null && !finalDropdownOptions.includes(value)) {
|
|
96
|
+
formState.onChange(component.id, { value: null });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return (_jsx(DropDownListComponent, { id: component.id, name: component.id, ...commonProps, locale: locale, cssClass: cssClass, dataSource: finalDropdownOptions, value: value !== undefined ? value : (component.defaultValue ?? null), showClearButton: component.showClearButton || false, readonly: component.readOnly || false, enableVirtualization: component.enableVirtualization || false, popupHeight: component.popupHeight || '300px', popupWidth: component.popupWidth || '100%', htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
86
100
|
case 'multiselect':
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
101
|
+
const fetchedMultiSelectOptions = useFetchOptions(component.options);
|
|
102
|
+
const resolvedMultiSelectOptions = resolveOptions(component.options, fetchedMultiSelectOptions);
|
|
103
|
+
const finalMultiSelectOptions = resolvedMultiSelectOptions.length > 0 ? resolvedMultiSelectOptions : component.options || ['Option 1'];
|
|
104
|
+
return (_jsx(MultiSelectComponent, { id: component.id, name: component.id, locale: locale, ...commonProps, value: value !== undefined ? value : (component.defaultValue ?? null), placeholder: component.placeholder, dataSource: finalMultiSelectOptions, fields: { text: 'text', value: 'value' }, showClearButton: component.showClearButton || false, readonly: component.readOnly || false, allowCustomValue: component.allowCustomValue || false, addTagOnBlur: component.addTagOnBlur || false, delimiterChar: component.delimiterChar || ',', showSelectAll: component.showSelectAll || false, mode: component.showSelectAll ? 'CheckBox' : undefined, selectAllText: component.selectAllText, unSelectAllText: component.unSelectAllText, showDropDownIcon: component.showDropDownIcon !== false, enableVirtualization: component.enableVirtualization || false, popupHeight: component.popupHeight || '300px', popupWidth: component.popupWidth || '100%', cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref, children: _jsx(Inject, { services: [CheckBoxSelection] }) }, component.id));
|
|
105
|
+
case 'date':
|
|
106
|
+
return (_jsx(DatePickerComponent, { ...commonProps, id: component.id, name: component.id, locale: locale, value: value !== undefined ? value : (component.defaultValue ?? null), floatLabelType: component.floatLabelType || 'Never', format: component.format || 'MM/dd/yyyy', placeholder: component.placeholder || '', readOnly: component.readOnly || false, showClearButton: component.showClearButton !== false ? true : false, showTodayButton: component.showTodayButton !== false ? true : false, calendarMode: component.calendarMode || 'Gregorian', dayHeaderFormat: component.dayHeaderFormat || 'Short', depth: component.depth || 'Month', start: component.start || 'Month', firstDayOfWeek: component.firstDayOfWeek || 0, min: component?.minDate ? new Date(component.minDate) : undefined, max: component?.maxDate ? new Date(component.maxDate) : undefined, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref, children: _jsx(Inject, { services: [Islamic] }) }, `${component.id}-${component.minDate}-${component.maxDate}`));
|
|
107
|
+
case 'dateTime':
|
|
108
|
+
return (_jsx(DateTimePickerComponent, { id: `${component.id}-${component.minTime}-${component.maxTime}-${component.minDate}-${component.maxDate}`, ...commonProps, locale: locale, name: component.id, floatLabelType: component.floatLabelType || 'Never', dayHeaderFormat: component.dayHeaderFormat || 'Short', value: value !== undefined ? value : (component.defaultValue ?? null), format: component.format || 'MM/dd/yyyy hh:mm a', showClearButton: component.showClearButton !== false, showTodayButton: component.showTodayButton !== false ? true : false, depth: component.depth || 'Month', start: component.start || 'Month', step: component.step || 1, readonly: component.readOnly || false, min: component?.minDate ? new Date(component.minDate) : undefined, max: component?.maxDate ? new Date(component.maxDate) : undefined, minTime: component?.minTime ? new Date(`2000-01-01 ${component.minTime}`) : undefined, maxTime: component?.maxTime ? new Date(`2000-01-01 ${component.maxTime}`) : undefined, enableMask: false, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref, children: _jsx(Inject, { services: [Islamic] }) }));
|
|
109
|
+
case 'time':
|
|
110
|
+
return (_jsx(TimePickerComponent, { id: `${component.id}-${component.minTime}-${component.maxTime}`, locale: locale, name: component.id, floatLabelType: component.floatLabelType || 'Never', placeholder: component.placeholder || '', enabled: !component.disabled, value: value !== undefined ? value : (component.defaultValue ?? null), format: component.format || 'hh:mm a', showClearButton: component.showClearButton !== false, step: component.step || 30, readonly: component.readOnly || false, min: component?.minTime ? new Date(`2000-01-01 ${component.minTime}`) : undefined, max: component?.maxTime ? new Date(`2000-01-01 ${component.maxTime}`) : undefined, enableMask: false, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
111
|
+
case 'dateRange':
|
|
112
|
+
return (_jsx(DateRangePickerComponent, { id: component.id, locale: locale, name: component.id, floatLabelType: component.floatLabelType || 'Never', dayHeaderFormat: component.dayHeaderFormat || 'Short', placeholder: component.placeholder || '', enabled: !component.disabled, value: value !== undefined ? value : (component.defaultValue ?? null), depth: component.depth || 'Month', start: component.start || 'Month', min: component?.minDate ? new Date(component.minDate) : undefined, max: component?.maxDate ? new Date(component.maxDate) : undefined, format: component.format || 'MM/dd/yyyy', separator: component.separator || ' - ', showClearButton: component.showClearButton !== false, readonly: component.readOnly || false, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
96
113
|
case 'switch':
|
|
97
|
-
return (_jsx(SwitchComponent, { id: component.id, value: component.defaultValue, name: component.id, checked: component.checked, disabled: component.disabled, onLabel: component.onLabel || '', offLabel: component.offLabel || '', cssClass: cssClass, htmlAttributes: htmlAttrs, change: (args) => onChange(args.checked), ref: ref }, component.id));
|
|
114
|
+
return (_jsx(SwitchComponent, { id: component.id, locale: locale, value: component.defaultValue, name: component.id, checked: (component.checked ?? false) || (value ?? false), disabled: component.disabled, onLabel: component.onLabel || '', offLabel: component.offLabel || '', cssClass: cssClass, htmlAttributes: htmlAttrs, change: (args) => onChange(args.checked), ref: ref }, component.id));
|
|
98
115
|
case 'button':
|
|
99
116
|
// If buttonsGroups is provided, render a button group in-place of a single button
|
|
100
117
|
const groupButtons = (component.buttonsGroups || component.buttons || []);
|
|
@@ -107,12 +124,12 @@ export const renderFormField = ({ component, value, onChange, onBlur, ref, hasEr
|
|
|
107
124
|
justifyContent: mapPositionToJustifyContent(component.position),
|
|
108
125
|
width: component.width || undefined,
|
|
109
126
|
};
|
|
110
|
-
return (_jsx("div", { id: component.id, role: "group", "aria-label": component.label || 'Button Group', className:
|
|
127
|
+
return (_jsx("div", { id: component.id, role: "group", "aria-label": component.label || 'Button Group', className: cssClass, style: groupStyleObj, children: groupButtons.map((btn, idx) => {
|
|
111
128
|
const btnId = `${component.id}_${idx}`;
|
|
112
129
|
const btnCssClass = [
|
|
113
130
|
mapButtonStyleToClass(btn.style)
|
|
114
131
|
].filter(Boolean).join(' ');
|
|
115
|
-
return (_jsx(ButtonComponent, { id: String(btnId), name: String(btnId), type: resolveButtonType(btn.type), cssClass: btnCssClass, disabled: btn.disabled || false, content: btn.label || `Button ${idx + 1}`, iconCss: btn.iconCss, iconPosition: btn.iconPosition, onClick: (event) => {
|
|
132
|
+
return (_jsx(ButtonComponent, { id: String(btnId), name: String(btnId), locale: locale, type: resolveButtonType(btn.type), cssClass: btnCssClass, disabled: btn.disabled || false, content: btn.label || `Button ${idx + 1}`, iconCss: btn.iconCss, iconPosition: btn.iconPosition, onClick: (event) => {
|
|
116
133
|
if (onClick) {
|
|
117
134
|
onClick(event);
|
|
118
135
|
}
|
|
@@ -129,19 +146,20 @@ export const renderFormField = ({ component, value, onChange, onBlur, ref, hasEr
|
|
|
129
146
|
mapButtonStyleToClass(component.style),
|
|
130
147
|
resolvedButtonType === 'submit' ? 'submit-btn form-submit-type' : '',
|
|
131
148
|
resolvedButtonType === 'reset' ? 'form-reset-type' : '',
|
|
132
|
-
component.cssClass || 'e-primary'
|
|
149
|
+
component.cssClass || 'e-primary',
|
|
150
|
+
component.size === 'Small' ? ' e-small' : component.size === 'Bigger' ? ' e-bigger' : ''
|
|
133
151
|
].filter(Boolean).join(' ') || 'e-primary';
|
|
134
152
|
const buttonContainerStyle = {
|
|
135
153
|
display: 'flex',
|
|
136
154
|
justifyContent: mapPositionToJustifyContent(component.position),
|
|
137
155
|
width: component.width || '100%',
|
|
138
156
|
};
|
|
139
|
-
return (_jsx("div", { id: `${component.id}-container`, style: buttonContainerStyle, children: _jsx(ButtonComponent, { id: component.id, type: resolvedButtonType, cssClass: buttonCssClassList, disabled: component.disabled, iconCss: component.iconCss, iconPosition: component.iconPosition, onClick: (event) => {
|
|
157
|
+
return (_jsx("div", { id: `${component.id}-container`, style: buttonContainerStyle, children: _jsx(ButtonComponent, { id: component.id, type: resolvedButtonType, locale: locale, cssClass: buttonCssClassList, disabled: component.disabled, iconCss: component.iconCss, iconPosition: component.iconPosition, onClick: (event) => {
|
|
140
158
|
if (onClick) {
|
|
141
159
|
onClick(event);
|
|
142
160
|
}
|
|
143
161
|
}, ref: ref, children: component.label }, component.id) }, `form-${component.type}-${component.id}`));
|
|
144
|
-
case '
|
|
162
|
+
case 'splitButton':
|
|
145
163
|
const splitButtonCssClassList = [
|
|
146
164
|
component.style === 'primary' ? 'e-primary' : '',
|
|
147
165
|
component.style === 'flat' ? '' : '',
|
|
@@ -155,7 +173,7 @@ export const renderFormField = ({ component, value, onChange, onBlur, ref, hasEr
|
|
|
155
173
|
display: 'flex',
|
|
156
174
|
justifyContent: mapPositionToJustifyContent(component.position)
|
|
157
175
|
};
|
|
158
|
-
return (_jsx("div", { id: `${component.id}-container`, "aria-label": 'Splitbutton', style: splitButtonContainerStyle, children: _jsx(SplitButtonComponent, { id: component.id, content: component.label || 'Split Button', items: component.options?.map((option, index) => ({
|
|
176
|
+
return (_jsx("div", { id: `${component.id}-container`, "aria-label": 'Splitbutton', style: splitButtonContainerStyle, children: _jsx(SplitButtonComponent, { id: component.id, locale: locale, content: component.label || 'Split Button', items: component.options?.map((option, index) => ({
|
|
159
177
|
text: option,
|
|
160
178
|
id: `${component.id}_option_${index}`
|
|
161
179
|
})) || [{ text: 'Option 1', id: `${component.id}_option_0` }], cssClass: splitButtonCssClassList, disabled: component.disabled, iconCss: component.iconCss, iconPosition: component.iconPosition || 'Left', onClick: (event) => {
|
|
@@ -168,34 +186,40 @@ export const renderFormField = ({ component, value, onChange, onBlur, ref, hasEr
|
|
|
168
186
|
}
|
|
169
187
|
}, ref: ref }, component.id) }, `form-${component.type}-${component.id}`));
|
|
170
188
|
case 'signature':
|
|
171
|
-
return (_jsx(SignatureComponent, { id: component.id, backgroundColor: component.backgroundColor || '', strokeColor: component.strokeColor || '', maxStrokeWidth: component.maxValue, minStrokeWidth: component.minValue, velocity: component.velocity, disabled: component.disabled, change: (args) => onChange(args.value), ref: ref }, component.id));
|
|
189
|
+
return (_jsx(SignatureComponent, { id: component.id, className: cssClass, locale: locale, backgroundColor: component.backgroundColor || '', strokeColor: component.strokeColor || '', maxStrokeWidth: component.maxValue, minStrokeWidth: component.minValue, velocity: component.velocity, disabled: component.disabled, change: (args) => onChange(args.value), ref: ref }, component.id));
|
|
172
190
|
case 'rating':
|
|
173
|
-
return (_jsx(RatingComponent, { id: component.id, name: component.id, value: value !== undefined ? value : (component.defaultValue || 0), disabled: component.disabled, cssClass:
|
|
174
|
-
case '
|
|
175
|
-
return (_jsx(ColorPickerComponent, { id: component.id, value: value !== undefined ? value : (component.defaultValue || ''), disabled: component.disabled, enableOpacity: component.enableOpacity, showButtons: component.showButtons, showRecentColors: component.showRecentColors, noColor: component.showNoColor, cssClass: cssClass, change: (args) => onChange(args.value), ref: ref }, component.id));
|
|
176
|
-
case '
|
|
177
|
-
return (_jsx(MaskedTextBoxComponent, { id: component.id, name: component.id, ...commonProps, value: value !== undefined ? value : (component.defaultValue || ''), floatLabelType: component.floatLabelType || 'Never', placeholder: component.placeholder || '', enabled: !component.disabled, mask: component.mask || '000-000-0000', promptChar: component.promptChar || '_', customCharacters: component.customCharacters, readOnly: component.readOnly || false, showClearButton: component.showClearButton !== false, cssClass: cssClass, htmlAttributes: htmlAttrs, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
178
|
-
case '
|
|
179
|
-
return (_jsx(SliderComponent, { id: component.id, value: value !== undefined ? value : (component.defaultValue ?? 0), min: component.minValue || 0, max: component.maxValue || 100, step: component.step || 1, disabled: component.disabled, cssClass: cssClass, enabled: !component.disabled, showButtons: component.showButtons, change: (args) => onChange(args.value), ref: ref }, component.id));
|
|
180
|
-
case '
|
|
181
|
-
return (_jsx(UploaderComponent, { id: component.id, name: component.id, type: 'file', enabled: !component.disabled, allowedExtensions: component.allowExtensions, asyncSettings: { saveUrl: component.saveUrl, removeUrl: component.removeUrl }, buttons: component.buttons || {
|
|
191
|
+
return (_jsx(RatingComponent, { id: component.id, name: component.id, locale: locale, value: value !== undefined ? value : (component.defaultValue || 0), disabled: component.disabled, cssClass: cssClass, allowReset: component.allowReset, itemsCount: component.itemsCount, min: component?.minValue, precision: component.precision, readOnly: component.readOnly, showTooltip: component.showRatingTooltip || false, showLabel: component.showRatingLabel, labelPosition: component.showRatingLabel ? component.ratingLabelPosition : undefined, valueChanged: (args) => onChange(args.value), ref: ref }, component.id));
|
|
192
|
+
case 'colorPicker':
|
|
193
|
+
return (_jsx(ColorPickerComponent, { id: component.id, locale: locale, value: value !== undefined ? value : (component.defaultValue || ''), disabled: component.disabled, enableOpacity: component.enableOpacity, showButtons: component.showButtons, showRecentColors: component.showRecentColors, noColor: component.showNoColor, cssClass: cssClass, change: (args) => onChange(args.value), ref: ref }, component.id));
|
|
194
|
+
case 'inputMask':
|
|
195
|
+
return (_jsx(MaskedTextBoxComponent, { id: component.id, name: component.id, ...commonProps, locale: locale, value: value !== undefined ? value : (component.defaultValue || ''), floatLabelType: component.floatLabelType || 'Never', placeholder: component.placeholder || '', enabled: !component.disabled, mask: component.mask || '000-000-0000', promptChar: component.promptChar || '_', customCharacters: component.customCharacters, readOnly: component.readOnly || false, showClearButton: component.showClearButton !== false, cssClass: cssClass, htmlAttributes: htmlAttrs, appendTemplate: component.suffix, prependTemplate: component.prefix, ...createValidationHandlers((args) => args.value || ''), ref: ref }, component.id));
|
|
196
|
+
case 'rangeSlider':
|
|
197
|
+
return (_jsx(SliderComponent, { id: component.id, locale: locale, value: value !== undefined ? value : (component.defaultValue ?? 0), min: component.minValue || 0, max: component.maxValue || 100, step: component.step || 1, disabled: component.disabled, cssClass: cssClass, enabled: !component.disabled, showButtons: component.showButtons, change: (args) => onChange(args.value), ref: ref }, component.id));
|
|
198
|
+
case 'fileUpload':
|
|
199
|
+
return (_jsx(UploaderComponent, { id: component.id, name: component.id, locale: locale, type: 'file', enabled: !component.disabled, allowedExtensions: component.allowExtensions, asyncSettings: { saveUrl: component.saveUrl, removeUrl: component.removeUrl }, buttons: component.buttons || {
|
|
182
200
|
"browse": "Choose File",
|
|
183
201
|
"clear": "Clear All",
|
|
184
202
|
"upload": "Upload All"
|
|
185
203
|
}, maxFileSize: component?.maxValue, minFileSize: component?.minValue, multiple: component.allowMultiple, showFileList: component.showFileList, htmlAttributes: htmlAttrs, cssClass: cssClass, change: (args) => onChange(args.filesData), ref: ref }, component.id));
|
|
186
|
-
case '
|
|
187
|
-
return (_jsx(ImageEditorComponent, { id: component.id, disabled: component.disabled, cssClass:
|
|
204
|
+
case 'imageEditor':
|
|
205
|
+
return (_jsx(ImageEditorComponent, { id: component.id, locale: locale, disabled: component.disabled, cssClass: cssClass, height: (component.height || '350px').toString(), width: (component.width || '100%').toString(), ref: ref }, component.id));
|
|
188
206
|
case 'message':
|
|
189
|
-
return (_jsx(MessageComponent, { id: component.id, severity: component.severity || component.messageType || 'info', variant: component.variant, content: component.content || 'Message', showCloseIcon: component.showCloseIcon
|
|
190
|
-
case '
|
|
207
|
+
return (_jsx(MessageComponent, { id: component.id, locale: locale, severity: component.severity || component.messageType || 'info', variant: component.variant, content: component.content || 'Message', showCloseIcon: component.showCloseIcon, showIcon: (component.showIcon === undefined ? false : component.showIcon) || false, disabled: component.disabled, cssClass: cssClass, ref: ref }, component.id));
|
|
208
|
+
case 'dataGrid':
|
|
191
209
|
const dg = component;
|
|
192
|
-
|
|
193
|
-
|
|
210
|
+
const conditionalData = resolveConditionalData(dg.conditions, formState?.values || {})?.dataSource;
|
|
211
|
+
const conditionalColumns = resolveConditionalData(dg.conditions, formState?.values || {})?.columns;
|
|
212
|
+
const fetchedDataSource = conditionalData ? useFetchOptions(conditionalData) : useFetchOptions(dg.dataSource);
|
|
213
|
+
const resolvedDataSource = conditionalData ? resolveOptions(conditionalData, fetchedDataSource) : resolveOptions(dg.dataSource, fetchedDataSource);
|
|
214
|
+
const finalDataSource = resolvedDataSource.length > 0 ? resolvedDataSource : (dg.dataSource ?? []);
|
|
215
|
+
const finalColumns = conditionalColumns && conditionalColumns.length > 0 ? conditionalColumns : (dg.columns ?? []);
|
|
216
|
+
return (_jsx("div", { id: dg.id, className: dg.cssClass, children: _jsx(DataGridComponent, { id: dg.id, type: 'dataGrid', locale: locale, label: dg.label || '', name: dg.name || '', columns: finalColumns, dataSource: value !== undefined ? value : finalDataSource, height: dg.height || '200px', width: dg.width || '100%', pageSize: dg.pageSize || 6, allowPaging: dg.allowPaging !== false, allowFiltering: dg.allowFiltering, allowAdding: dg.allowAdding !== false, allowEditing: dg.allowEditing !== false, allowDeleting: dg.allowDeleting !== false, onDataChange: (data) => onChange(data), cssClass: cssClass, ref: ref }) }, dg.id));
|
|
217
|
+
case 'richTextEditor':
|
|
194
218
|
const toolbarSettings = {
|
|
195
219
|
items: ['Undo', 'Redo', '|', 'Bold', 'Italic', 'Underline', 'StrikeThrough', 'InlineCode', '|', 'CreateLink', 'Blockquote', '|', 'BulletFormatList', 'NumberFormatList', '|', 'Formats', 'Alignments', '|', 'Outdent', 'Indent', '|',
|
|
196
220
|
'FontColor', 'BackgroundColor', 'FontName', 'FontSize', '|', 'LowerCase', 'UpperCase', '|', 'SourceCode']
|
|
197
221
|
};
|
|
198
|
-
return (_jsx(RichTextEditorComponent, { id: component.id, name: component.id, toolbarSettings: toolbarSettings, value: value !== undefined ? value : (component.defaultValue || ''), placeholder: component.placeholder || '', enabled: !component.disabled, readonly: component.readOnly || false, maxLength: component.maxLength || 1000, cssClass: cssClass || undefined, height: component.height || '300px', width: component.width || '100%', htmlAttributes: htmlAttrs, ref: ref, children: _jsx(RTEInject, { services: [Toolbar, Link, HtmlEditor, QuickToolbar] }) }, `${component.id}`));
|
|
222
|
+
return (_jsx(RichTextEditorComponent, { id: component.id, locale: locale, name: component.id, toolbarSettings: toolbarSettings, value: value !== undefined ? value : (component.defaultValue || ''), placeholder: component.placeholder || '', enabled: !component.disabled, readonly: component.readOnly || false, maxLength: component.maxLength || 1000, cssClass: cssClass || undefined, height: component.height || '300px', width: component.width || '100%', htmlAttributes: htmlAttrs, ref: ref, children: _jsx(RTEInject, { services: [Toolbar, Link, HtmlEditor, QuickToolbar] }) }, `${component.id}`));
|
|
199
223
|
default:
|
|
200
224
|
return (_jsxs("div", { className: "unsupported-component", children: ["Unsupported component type: ", component.type] }));
|
|
201
225
|
}
|
|
@@ -8,17 +8,47 @@ export interface ButtonClickEventArgs {
|
|
|
8
8
|
buttonLabel: string;
|
|
9
9
|
event: React.MouseEvent<HTMLButtonElement>;
|
|
10
10
|
}
|
|
11
|
+
export type ConditionalOperator = 'equal' | 'notEqual' | 'greaterThan' | 'lessThan' | 'greaterThanOrEqual' | 'lessThanOrEqual' | 'in' | 'notIn' | 'contains' | 'notContains';
|
|
12
|
+
export interface ConditionalRule {
|
|
13
|
+
field: string;
|
|
14
|
+
operator: ConditionalOperator;
|
|
15
|
+
value: any;
|
|
16
|
+
}
|
|
17
|
+
export interface CompositeConditionalRule {
|
|
18
|
+
condition: 'and' | 'or';
|
|
19
|
+
rules: (ConditionalRule | CompositeConditionalRule)[];
|
|
20
|
+
}
|
|
21
|
+
export type ConditionType = ConditionalRule | CompositeConditionalRule;
|
|
22
|
+
export interface ChoiceBasedFieldRule {
|
|
23
|
+
primaryFieldId: string;
|
|
24
|
+
choiceMapping: Record<string, string[]>;
|
|
25
|
+
showAllWhenNotMapped?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface FormComponentConditions {
|
|
28
|
+
visibleWhen?: ConditionType;
|
|
29
|
+
hideWhen?: ConditionType;
|
|
30
|
+
readOnlyWhen?: ConditionType;
|
|
31
|
+
disabledWhen?: ConditionType;
|
|
32
|
+
requiredWhen?: ConditionType;
|
|
33
|
+
setValueWhen?: {
|
|
34
|
+
condition: ConditionType;
|
|
35
|
+
value: any;
|
|
36
|
+
};
|
|
37
|
+
choiceBasedField?: ChoiceBasedFieldRule;
|
|
38
|
+
}
|
|
11
39
|
export interface FormSchema {
|
|
12
40
|
version: string;
|
|
13
|
-
theme: string;
|
|
14
41
|
components: FormComponent[];
|
|
15
42
|
}
|
|
16
43
|
export interface FormComponent {
|
|
17
44
|
id: string;
|
|
18
|
-
type: 'textbox' | 'textarea' | 'number' | 'email' | 'url' | 'phone' | 'password' | 'checkbox' | '
|
|
45
|
+
type: 'textbox' | 'textarea' | 'number' | 'email' | 'url' | 'phone' | 'password' | 'checkbox' | 'checkboxGroup' | 'radio' | 'dropdown' | 'multiselect' | 'button' | 'date' | 'dateTime' | 'time' | 'dateRange' | 'switch' | 'signature' | 'rating' | 'imageEditor' | 'fileUpload' | 'rangeSlider' | 'colorPicker' | 'inputMask' | 'message' | 'panel' | 'table' | 'tabs' | 'dataGrid' | 'card' | 'splitButton' | 'richTextEditor' | 'staticHtml';
|
|
19
46
|
textboxType?: string;
|
|
20
47
|
label: string;
|
|
21
48
|
name: string;
|
|
49
|
+
description?: string | undefined;
|
|
50
|
+
prefix?: string | undefined;
|
|
51
|
+
suffix?: string | undefined;
|
|
22
52
|
placeholder?: string;
|
|
23
53
|
defaultValue?: any;
|
|
24
54
|
disabled?: boolean;
|
|
@@ -59,6 +89,7 @@ export interface FormComponent {
|
|
|
59
89
|
decimals?: number;
|
|
60
90
|
currency?: string;
|
|
61
91
|
format?: string;
|
|
92
|
+
numberFormat?: string;
|
|
62
93
|
allowReset?: boolean;
|
|
63
94
|
itemsCount?: number;
|
|
64
95
|
precision?: number | string;
|
|
@@ -108,6 +139,7 @@ export interface FormComponent {
|
|
|
108
139
|
showDropDownIcon?: boolean;
|
|
109
140
|
validateOn?: 'Change' | 'Blur';
|
|
110
141
|
pageSize?: number;
|
|
142
|
+
size?: string;
|
|
111
143
|
allowPaging?: boolean;
|
|
112
144
|
allowAdding?: boolean;
|
|
113
145
|
allowEditing?: boolean;
|
|
@@ -153,6 +185,8 @@ export interface FormComponent {
|
|
|
153
185
|
tableCells?: FormComponent[][][];
|
|
154
186
|
parentPath?: string;
|
|
155
187
|
properties?: Record<string, any>;
|
|
188
|
+
expressionValue?: string;
|
|
189
|
+
conditions?: FormComponentConditions;
|
|
156
190
|
_configured?: boolean;
|
|
157
191
|
}
|
|
158
192
|
export interface ValidationRules {
|