extended-dynamic-forms 0.3.7 → 0.3.9

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # Extended Dynamic Forms
2
2
 
3
- ## BREAKING CHANGE: v0.2.0
3
+ ## Declarative Configuration (JSON-only)
4
4
 
5
- All conditional logic now uses **JsonLogic rules only** for conditions. Function-based conditions have been removed for security and portability. Note that validation effects may still use functions. See migration examples below.
5
+ Conditional logic is configured with pure JSON via `x-edf:rules` in your `schema` and `uiSchema`. Function-based conditions and external hooks are not required and should not be used in app code.
6
6
 
7
7
  ## Project Status
8
8
 
@@ -18,7 +18,7 @@ All conditional logic now uses **JsonLogic rules only** for conditions. Function
18
18
 
19
19
  Extended Dynamic Forms is an extension library for React JSON Schema Form (RJSF) v6 that adds:
20
20
 
21
- - **Three Pillars Architecture** for conditional logic with O(N) performance (where N is the number of conditional rules/array items)
21
+ - **Declarative conditionals** with O(N) performance (rules + dynamic arrays)
22
22
  - **Multi-step wizard forms** with automatic step detection
23
23
  - **Central event orchestration** with webhook support
24
24
  - **25+ Ant Design components** for professional UI
@@ -51,71 +51,62 @@ npm run dev
51
51
 
52
52
  ## Core Architecture
53
53
 
54
- ### Three Pillars Conditional System
54
+ ### Declarative Conditionals (JSON-only)
55
55
 
56
- The conditional logic system is divided into three independent pillars:
56
+ Embed rules directly inside your configs. EDF evaluates JsonLogic `condition` and applies JSON Patch `effect` internally. No hooks, functions, or classes in user code.
57
57
 
58
- #### 1. UI Logic Pillar
59
- Controls form appearance using JsonLogic conditions and JSON Patch operations:
58
+ - UI rules → `uiSchema['x-edf:rules']`
59
+ - Schema rules → `schema['x-edf:rules']`
60
60
 
61
- ```typescript
62
- import { useConditionalUi, UiRule } from 'extended-dynamic-forms/conditionals/v2';
63
-
64
- const uiRules: UiRule[] = [{
65
- name: 'Show license number when has license',
66
- condition: { "==": [{ "var": "hasDriversLicense" }, true] },
67
- effect: [{ op: 'remove', path: '/licenseNumber/ui:widget' }]
68
- }];
69
-
70
- const conditionalUiSchema = useConditionalUi(uiRules, baseUiSchema, formData);
71
- ```
72
-
73
- #### 2. Schema Logic Pillar
74
- Modifies JSON Schema structure dynamically (use sparingly):
75
-
76
- ```typescript
77
- const schemaRules: SchemaRule[] = [{
78
- name: 'Add premium fields',
79
- condition: { "==": [{ "var": "accountType" }, "premium"] },
80
- effect: [{ op: 'add', path: '/properties/premiumFeatures', value: {...} }]
81
- }];
61
+ Example (UI rules):
62
+ ```json
63
+ {
64
+ "x-edf:rules": [
65
+ {
66
+ "name": "Show license number when has license",
67
+ "condition": { "==": [{ "var": "hasDriversLicense" }, true] },
68
+ "effect": [{ "op": "remove", "path": "/licenseNumber/ui:widget" }]
69
+ }
70
+ ]
71
+ }
82
72
  ```
83
73
 
84
- #### 3. Validation Logic Pillar
85
- Adds conditional validation rules:
86
-
87
- ```typescript
88
- const validationRules: ValidationRule[] = [{
89
- name: 'Require consent for minors',
90
- condition: { "<": [{ "var": "age" }, 18] },
91
- effect: {
92
- name: 'Parent consent validation',
93
- isActive: { "<": [{ "var": "age" }, 18] },
94
- validate: (errors, formData) => {
95
- if (!formData.parentConsent) {
96
- errors.parentConsent.__errors = ['Parent consent required'];
97
- }
74
+ Example (Schema rules):
75
+ ```json
76
+ {
77
+ "x-edf:rules": [
78
+ {
79
+ "name": "Add premium fields",
80
+ "condition": { "==": [{ "var": "accountType" }, "premium"] },
81
+ "effect": [
82
+ { "op": "add", "path": "/properties/premiumFeatures", "value": { "type": "object" } }
83
+ ]
98
84
  }
99
- }
100
- }];
85
+ ]
86
+ }
101
87
  ```
102
88
 
103
89
  ### Dynamic Arrays with O(N) Performance
104
90
 
105
- Provides efficient handling of conditional logic within arrays, where N is the number of array items:
91
+ Use declarative `ui:dynamicItems` with per-item JsonLogic. No functions:
106
92
 
107
- ```typescript
108
- import { createDynamicArrayItemsUiSchema } from 'extended-dynamic-forms/conditionals/v2';
109
-
110
- const uiSchema = {
111
- directors: {
112
- items: createDynamicArrayItemsUiSchema((director, index) => ({
113
- shareholdingPercentage: {
114
- 'ui:widget': director.hasShareholding ? 'percentage' : 'hidden'
93
+ ```json
94
+ {
95
+ "directors": {
96
+ "items": {
97
+ "ui:dynamicItems": {
98
+ "base": { "shareholdingPercentage": { "ui:widget": "hidden" } },
99
+ "rules": [
100
+ {
101
+ "condition": { "===": [{ "var": "hasShareholding" }, true] },
102
+ "ui": { "shareholdingPercentage": { "ui:widget": "updown" } },
103
+ "otherwise": { "shareholdingPercentage": { "ui:widget": "hidden" } }
104
+ }
105
+ ]
115
106
  }
116
- }))
107
+ }
117
108
  }
118
- };
109
+ }
119
110
  ```
120
111
 
121
112
  ## Multi-Step Wizard Forms
@@ -127,7 +118,7 @@ import { WizardForm } from 'extended-dynamic-forms';
127
118
 
128
119
  <WizardForm
129
120
  schema={wizardSchema}
130
- uiSchema={conditionalUiSchema}
121
+ uiSchema={uiSchema}
131
122
  formData={formData}
132
123
  onStepChange={(fromStep, toStep) => {
133
124
  console.log(`Step ${fromStep} → ${toStep}`);
@@ -149,8 +140,8 @@ const schema = {
149
140
  }
150
141
  };
151
142
 
152
- // Conditions use flat paths (no STEP_ prefix)
153
- condition: { "==": [{ "var": "hasDriversLicense" }, true] }
143
+ // Conditions refer to flattened form data (no STEP_ prefix)
144
+ // Example rule (in uiSchema.x-edf:rules): { "==": [{ "var": "hasDriversLicense" }, true] }
154
145
  ```
155
146
 
156
147
  Note on wizard detection:
@@ -213,6 +204,7 @@ Notes:
213
204
  - EDF includes `LayoutGridField` out of the box. Just set `ui:field: 'LayoutGridField'` on the step object.
214
205
  - EDF variant uses `'ui:layoutGrid'` with AntD gutter and 24-grid spans. The RJSF canonical layout (`'ui:layout'` with 12-grid widths) is also parsed.
215
206
  - You can still override or extend via the `fields` prop if needed.
207
+ - LayoutGridField now writes nested updates immutably using path metadata. This is enabled by default; set `ui:options.pathAware: false` on a step to fall back to the previous shallow merge behaviour.
216
208
 
217
209
  ## Event System & Webhooks
218
210
 
@@ -684,7 +676,7 @@ npm run format # Prettier
684
676
  ```
685
677
  src/
686
678
  ├── components/ # Core form components
687
- ├── conditionals/ # Three Pillars system
679
+ ├── conditionals/ # Declarative conditional engines (internal)
688
680
  │ └── v2/ # Current implementation
689
681
  ├── events/ # Event orchestration
690
682
  ├── layouts/ # Layout systems
@@ -718,16 +710,8 @@ Run `npm run dev` to explore examples.
718
710
  Full TypeScript support with exported types:
719
711
 
720
712
  ```typescript
721
- import {
722
- ExtendedForm,
723
- WizardForm,
724
- UiRule,
725
- SchemaRule,
726
- ValidationRule,
727
- JsonLogicRule,
728
- FormEvent,
729
- WebhookConfig
730
- } from 'extended-dynamic-forms';
713
+ import { ExtendedForm, WizardForm } from 'extended-dynamic-forms';
714
+ // Config is JSON-only; rules are embedded via x-edf:rules
731
715
  ```
732
716
 
733
717
  ## Contributing
@@ -17,6 +17,7 @@ export declare const customFields: {
17
17
  };
18
18
  export declare const customTemplates: {
19
19
  FieldTemplate: React.FC<import('@rjsf/utils').FieldTemplateProps>;
20
+ ObjectFieldTemplate: React.FC<import('@rjsf/utils').ObjectFieldTemplateProps>;
20
21
  ArrayFieldTemplate: (props: import('@rjsf/utils').ArrayFieldTemplateProps) => import("react/jsx-runtime").JSX.Element;
21
22
  ArrayFieldItemTemplate: (props: import('@rjsf/utils').ArrayFieldItemTemplateType) => import("react/jsx-runtime").JSX.Element;
22
23
  WizardObjectFieldTemplate: React.FC<import('@rjsf/utils').ObjectFieldTemplateProps>;
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+ import { ObjectFieldTemplateProps } from '@rjsf/utils';
3
+
4
+ export declare const ObjectFieldTemplate: React.FC<ObjectFieldTemplateProps>;
5
+ export default ObjectFieldTemplate;