@syncfusion/ej2-react-form-renderer 0.1.0-beta → 0.1.1-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/package.json +2 -2
- package/src/CheckboxGroup.js +1 -1
- package/src/ConditionalRuleEngine.d.ts +253 -0
- package/src/ConditionalRuleEngine.js +489 -0
- package/src/DataGridComponent.d.ts +0 -1
- package/src/DataGridComponent.js +3 -19
- package/src/FormRenderer.d.ts +29 -2
- package/src/FormRenderer.js +122 -40
- package/src/json-converter.d.ts +10 -0
- package/src/json-converter.js +181 -32
- package/src/parser.js +18 -17
- package/src/renderFormField.d.ts +2 -1
- package/src/renderFormField.js +44 -43
- package/src/types/FormSchema.d.ts +29 -1
- package/src/utils.js +86 -0
- package/styles/form-renderer.base.css +39 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncfusion/ej2-react-form-renderer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-beta",
|
|
4
4
|
"description": "Form renderer component for rendering dynamic JSON-driven forms with Syncfusion EJ2 React components",
|
|
5
5
|
"author": "Syncfusion Inc.",
|
|
6
6
|
"license": "SEE LICENSE IN license",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@syncfusion/ej2-react-navigations": "*",
|
|
43
43
|
"@syncfusion/ej2-react-notifications": "*",
|
|
44
44
|
"@syncfusion/ej2-react-popups": "*",
|
|
45
|
-
"@syncfusion/ej2-react-richtexteditor": "
|
|
45
|
+
"@syncfusion/ej2-react-richtexteditor": "^32.1.1",
|
|
46
46
|
"@syncfusion/ej2-react-splitbuttons": "*"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {}
|
package/src/CheckboxGroup.js
CHANGED
|
@@ -42,7 +42,7 @@ const CheckboxGroup = ({ component, formState, value, onChange, optionRef }) =>
|
|
|
42
42
|
return (_jsx("div", { className: `checkbox-group ${component.cssClass || ''}`, style: containerStyle, ...htmlAttrs, role: "group", "aria-label": groupLabel, title: component.tooltip, children: _jsx("div", { className: "checkbox-group-items", style: itemsStyle, children: (component.options || ['Option 1']).map((option, idx) => {
|
|
43
43
|
const optionValue = typeof option === 'string' ? option : (option.value ?? option.label ?? option.key);
|
|
44
44
|
const optionLabel = typeof option === 'string' ? option : (option.label ?? option.value ?? String(optionValue));
|
|
45
|
-
return (_jsx(CheckBoxComponent, { id: `${component.id}_${idx}`, label: optionLabel, checked: selectedItems.includes(optionValue), disabled: component.disabled, labelPosition: component.checkboxLabelPosition || 'After', change: (e) => handleCheckboxChange(optionValue, e.checked), cssClass: component.cssClass
|
|
45
|
+
return (_jsx(CheckBoxComponent, { id: `${component.id}_${idx}`, label: optionLabel, checked: selectedItems.includes(optionValue), disabled: component.disabled, labelPosition: component.checkboxLabelPosition || 'After', change: (e) => handleCheckboxChange(optionValue, e.checked), cssClass: `${component.cssClass}${component.size === 'Small' ? ' e-small' : component.size === 'Bigger' ? ' e-bigger' : ''}`, htmlAttributes: htmlAttrs, ref: optionRef ? (el) => optionRef(el, idx) : undefined }, `${component.id}-${idx}`));
|
|
46
46
|
}) }) }, `form-checkboxgroup-${component.id}`));
|
|
47
47
|
};
|
|
48
48
|
export default CheckboxGroup;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConditionalRuleEngine - Core rule evaluation engine for conditional behaviors
|
|
3
|
+
*
|
|
4
|
+
* Evaluates declarative condition rules (from QueryBuilder or manual JSON) against
|
|
5
|
+
* form state to determine field visibility, read-only state, disabled state, and
|
|
6
|
+
* which validators should apply.
|
|
7
|
+
*
|
|
8
|
+
* @spec CONDITIONAL-VALIDATION.md
|
|
9
|
+
* @requirement Tasks 3.1-3.12: ConditionalRuleEngine implementation
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Simple rule evaluation (field operator value)
|
|
13
|
+
* - Composite rules (AND/OR combinations with nesting)
|
|
14
|
+
* - Conditional validators (apply validator only when condition met)
|
|
15
|
+
* - Relationship validators (cross-field validation with safe expression eval)
|
|
16
|
+
* - Behavioral flags (visibility, readOnly, disabled)
|
|
17
|
+
* - Error handling with safe defaults
|
|
18
|
+
*
|
|
19
|
+
* Security:
|
|
20
|
+
* - Uses expr-eval for safe expression evaluation (no eval())
|
|
21
|
+
* - Defaults to safe behavior on errors (visible, not disabled, not read-only)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const isVisible = ConditionalRuleEngine.isFieldVisible(
|
|
26
|
+
* component.conditions,
|
|
27
|
+
* { country: 'US', age: 25 }
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* const behaviors = ConditionalRuleEngine.applyConditionalBehaviors(
|
|
31
|
+
* component.conditions,
|
|
32
|
+
* formValues
|
|
33
|
+
* );
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import React from 'react';
|
|
37
|
+
import type { ConditionType, FormComponentConditions } from '../FormBuilder/types/FormSchema';
|
|
38
|
+
/**
|
|
39
|
+
* Form field value type (aligned with FormValidator)
|
|
40
|
+
*/
|
|
41
|
+
export type FormValueType = string | number | boolean | Date | bigint | symbol | File | FileList | string[] | number[] | React.ReactNode | null | undefined | any;
|
|
42
|
+
/**
|
|
43
|
+
* ConditionalRuleEngine class
|
|
44
|
+
*
|
|
45
|
+
* @spec CONDITIONAL-VALIDATION.md - Core rule evaluation engine
|
|
46
|
+
* @requirement Phase 1: Conditional visibility, readOnly, disabled behaviors
|
|
47
|
+
*/
|
|
48
|
+
export declare class ConditionalRuleEngine {
|
|
49
|
+
/**
|
|
50
|
+
* Evaluate a conditional rule against form values
|
|
51
|
+
*
|
|
52
|
+
* Handles both simple rules (field operator value) and composite rules (AND/OR).
|
|
53
|
+
* Returns false for malformed rules.
|
|
54
|
+
*
|
|
55
|
+
* @spec CONDITIONAL-VALIDATION.md - evaluateCondition method
|
|
56
|
+
* @requirement Task 3.2: Implement evaluateCondition with simple and composite handling
|
|
57
|
+
*
|
|
58
|
+
* @param rule - ConditionalRule or CompositeConditionalRule
|
|
59
|
+
* @param formValues - Current form field values (key = field name, value = field value)
|
|
60
|
+
* @returns true if condition met, false otherwise
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const rule = { field: 'age', operator: 'greaterThan', value: 18 };
|
|
65
|
+
* const isAdult = ConditionalRuleEngine.evaluateCondition(rule, { age: 25 });
|
|
66
|
+
* // isAdult = true
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
static evaluateCondition(rule: ConditionType, formValues: Record<string, FormValueType>): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Evaluate simple field comparison rule
|
|
72
|
+
*
|
|
73
|
+
* Supports operators: equal, notEqual, greaterThan, lessThan, greaterThanOrEqual,
|
|
74
|
+
* lessThanOrEqual, in, notIn, contains, notContains.
|
|
75
|
+
*
|
|
76
|
+
* Handles both camelCase (greaterThan) and lowercase (greaterthan) operator formats
|
|
77
|
+
* for compatibility with QueryBuilder output.
|
|
78
|
+
*
|
|
79
|
+
* @spec CONDITIONAL-VALIDATION.md - evaluateSimpleRule method
|
|
80
|
+
* @requirement Task 3.3: Implement evaluateSimpleRule supporting all operators
|
|
81
|
+
*
|
|
82
|
+
* @param rule - Simple conditional rule with field, operator, value
|
|
83
|
+
* @param formValues - Current form field values
|
|
84
|
+
* @returns true if comparison is true, false otherwise
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const rule = { field: 'email', operator: 'contains', value: '@' };
|
|
89
|
+
* const hasAt = evaluateSimpleRule(rule, { email: 'test@example.com' });
|
|
90
|
+
* // hasAt = true
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
private static evaluateSimpleRule;
|
|
94
|
+
/**
|
|
95
|
+
* Evaluate composite rule with AND/OR logic
|
|
96
|
+
*
|
|
97
|
+
* Recursively evaluates nested rules with AND (all must be true) or OR
|
|
98
|
+
* (at least one must be true) logic.
|
|
99
|
+
*
|
|
100
|
+
* @spec CONDITIONAL-VALIDATION.md - evaluateCompositeRule method
|
|
101
|
+
* @requirement Task 3.4: Implement evaluateCompositeRule for AND/OR logic
|
|
102
|
+
*
|
|
103
|
+
* @param rule - Composite rule with condition ('and'|'or') and rules array
|
|
104
|
+
* @param formValues - Current form field values
|
|
105
|
+
* @returns true if composite condition met, false otherwise
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const rule = {
|
|
110
|
+
* condition: 'and',
|
|
111
|
+
* rules: [
|
|
112
|
+
* { field: 'age', operator: 'greaterThan', value: 18 },
|
|
113
|
+
* { field: 'country', operator: 'equal', value: 'US' }
|
|
114
|
+
* ]
|
|
115
|
+
* };
|
|
116
|
+
* const isEligible = evaluateCompositeRule(rule, { age: 25, country: 'US' });
|
|
117
|
+
* // isEligible = true
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
private static evaluateCompositeRule;
|
|
121
|
+
/**
|
|
122
|
+
* Check if field should be visible
|
|
123
|
+
*
|
|
124
|
+
* Evaluates visibleWhen condition. Defaults to true (visible) if no condition
|
|
125
|
+
* is defined or on error.
|
|
126
|
+
*
|
|
127
|
+
* @spec CONDITIONAL-VALIDATION.md - isFieldVisible method
|
|
128
|
+
* @requirement Task 3.8: Implement isFieldVisible (defaults to true if no condition)
|
|
129
|
+
*
|
|
130
|
+
* @param conditions - FormComponentConditions containing visibleWhen rule
|
|
131
|
+
* @param formValues - Current form field values
|
|
132
|
+
* @returns true if field should be visible, false if hidden
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const conditions = {
|
|
137
|
+
* visibleWhen: { field: 'showEmail', operator: 'equal', value: true }
|
|
138
|
+
* };
|
|
139
|
+
* const visible = isFieldVisible(conditions, { showEmail: true });
|
|
140
|
+
* // visible = true
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
static isFieldVisible(conditions: FormComponentConditions | undefined, formValues: Record<string, FormValueType>): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Check if field should be read-only
|
|
146
|
+
*
|
|
147
|
+
* Evaluates readOnlyWhen condition. Defaults to false (editable) if no
|
|
148
|
+
* condition is defined or on error.
|
|
149
|
+
*
|
|
150
|
+
* @spec CONDITIONAL-VALIDATION.md - isFieldReadOnly method
|
|
151
|
+
* @requirement Task 3.9: Implement isFieldReadOnly (defaults to false if no condition)
|
|
152
|
+
*
|
|
153
|
+
* @param conditions - FormComponentConditions containing readOnlyWhen rule
|
|
154
|
+
* @param formValues - Current form field values
|
|
155
|
+
* @returns true if field should be read-only, false if editable
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const conditions = {
|
|
160
|
+
* readOnlyWhen: { field: 'isVerified', operator: 'equal', value: true }
|
|
161
|
+
* };
|
|
162
|
+
* const readOnly = isFieldReadOnly(conditions, { isVerified: true });
|
|
163
|
+
* // readOnly = true
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
static isFieldReadOnly(conditions: FormComponentConditions | undefined, formValues: Record<string, FormValueType>): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Check if field should be disabled
|
|
169
|
+
*
|
|
170
|
+
* Evaluates disabledWhen condition. Defaults to false (enabled) if no
|
|
171
|
+
* condition is defined or on error.
|
|
172
|
+
*
|
|
173
|
+
* @spec CONDITIONAL-VALIDATION.md - isFieldDisabled method
|
|
174
|
+
* @requirement Task 3.10: Implement isFieldDisabled (defaults to false if no condition)
|
|
175
|
+
*
|
|
176
|
+
* @param conditions - FormComponentConditions containing disabledWhen rule
|
|
177
|
+
* @param formValues - Current form field values
|
|
178
|
+
* @returns true if field should be disabled, false if enabled
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const conditions = {
|
|
183
|
+
* disabledWhen: { field: 'orderStatus', operator: 'equal', value: 'completed' }
|
|
184
|
+
* };
|
|
185
|
+
* const disabled = isFieldDisabled(conditions, { orderStatus: 'completed' });
|
|
186
|
+
* // disabled = true
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
static isFieldDisabled(conditions: FormComponentConditions | undefined, formValues: Record<string, FormValueType>): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Check if field should be hidden
|
|
192
|
+
*
|
|
193
|
+
* Evaluates hideWhen condition. Defaults to false (visible) if no condition
|
|
194
|
+
* is defined or on error.
|
|
195
|
+
*
|
|
196
|
+
* @param conditions - FormComponentConditions containing hideWhen rule
|
|
197
|
+
* @param formValues - Current form field values
|
|
198
|
+
* @returns true if field should be hidden, false if visible
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const conditions = {
|
|
203
|
+
* hideWhen: { field: 'hideEmail', operator: 'equal', value: true }
|
|
204
|
+
* };
|
|
205
|
+
* const hidden = isFieldHidden(conditions, { hideEmail: true });
|
|
206
|
+
* // hidden = true
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
static isFieldHidden(conditions: FormComponentConditions | undefined, formValues: Record<string, FormValueType>): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Check if field should be required
|
|
212
|
+
*
|
|
213
|
+
* Evaluates requiredWhen condition. Defaults to false (not required) if no condition
|
|
214
|
+
* is defined or on error.
|
|
215
|
+
*
|
|
216
|
+
* @param conditions - FormComponentConditions containing requiredWhen rule
|
|
217
|
+
* @param formValues - Current form field values
|
|
218
|
+
* @returns true if field should be required, false if optional
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const conditions = {
|
|
223
|
+
* requiredWhen: { field: 'requireDetails', operator: 'equal', value: true }
|
|
224
|
+
* };
|
|
225
|
+
* const required = isFieldRequired(conditions, { requireDetails: true });
|
|
226
|
+
* // required = true
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
static isFieldRequired(conditions: FormComponentConditions | undefined, formValues: Record<string, FormValueType>): boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Get value to set for field if condition is met
|
|
232
|
+
*
|
|
233
|
+
* Evaluates setValueWhen condition and returns the value to assign if true.
|
|
234
|
+
* Returns undefined if no condition is defined, condition not met, or on error.
|
|
235
|
+
*
|
|
236
|
+
* @param conditions - FormComponentConditions containing setValueWhen rule
|
|
237
|
+
* @param formValues - Current form field values
|
|
238
|
+
* @returns The value to set if condition met, undefined otherwise
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const conditions = {
|
|
243
|
+
* setValueWhen: {
|
|
244
|
+
* condition: { field: 'country', operator: 'equal', value: 'US' },
|
|
245
|
+
* value: 'United States'
|
|
246
|
+
* }
|
|
247
|
+
* };
|
|
248
|
+
* const value = getConditionalValue(conditions, { country: 'US' });
|
|
249
|
+
* // value = 'United States'
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
static getConditionalValue(conditions: FormComponentConditions | undefined, formValues: Record<string, FormValueType>): any;
|
|
253
|
+
}
|