@form-flow/core 1.0.0
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 +281 -0
- package/dist/dependency-graph.d.ts +14 -0
- package/dist/dependency-graph.d.ts.map +1 -0
- package/dist/dependency-graph.js +69 -0
- package/dist/dependency-graph.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/models/field-definition.d.ts +49 -0
- package/dist/models/field-definition.d.ts.map +1 -0
- package/dist/models/field-definition.js +3 -0
- package/dist/models/field-definition.js.map +1 -0
- package/dist/models/form-definition.d.ts +16 -0
- package/dist/models/form-definition.d.ts.map +1 -0
- package/dist/models/form-definition.js +3 -0
- package/dist/models/form-definition.js.map +1 -0
- package/dist/models/group.d.ts +12 -0
- package/dist/models/group.d.ts.map +1 -0
- package/dist/models/group.js +3 -0
- package/dist/models/group.js.map +1 -0
- package/dist/models/operator-registry.d.ts +21 -0
- package/dist/models/operator-registry.d.ts.map +1 -0
- package/dist/models/operator-registry.js +31 -0
- package/dist/models/operator-registry.js.map +1 -0
- package/dist/models/operators.d.ts +43 -0
- package/dist/models/operators.d.ts.map +1 -0
- package/dist/models/operators.js +29 -0
- package/dist/models/operators.js.map +1 -0
- package/dist/models/rule.d.ts +10 -0
- package/dist/models/rule.d.ts.map +1 -0
- package/dist/models/rule.js +3 -0
- package/dist/models/rule.js.map +1 -0
- package/dist/modern-rule-builder-engine.d.ts +46 -0
- package/dist/modern-rule-builder-engine.d.ts.map +1 -0
- package/dist/modern-rule-builder-engine.js +198 -0
- package/dist/modern-rule-builder-engine.js.map +1 -0
- package/dist/rule-builder.d.ts +30 -0
- package/dist/rule-builder.d.ts.map +1 -0
- package/dist/rule-builder.js +75 -0
- package/dist/rule-builder.js.map +1 -0
- package/dist/rule-evaluator.d.ts +11 -0
- package/dist/rule-evaluator.d.ts.map +1 -0
- package/dist/rule-evaluator.js +90 -0
- package/dist/rule-evaluator.js.map +1 -0
- package/dist/utility/field-helper.d.ts +5 -0
- package/dist/utility/field-helper.d.ts.map +1 -0
- package/dist/utility/field-helper.js +11 -0
- package/dist/utility/field-helper.js.map +1 -0
- package/dist/utility/rule-helper.d.ts +10 -0
- package/dist/utility/rule-helper.d.ts.map +1 -0
- package/dist/utility/rule-helper.js +45 -0
- package/dist/utility/rule-helper.js.map +1 -0
- package/dist/utility/rule-mapper.d.ts +11 -0
- package/dist/utility/rule-mapper.d.ts.map +1 -0
- package/dist/utility/rule-mapper.js +88 -0
- package/dist/utility/rule-mapper.js.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# @form-flow/core
|
|
2
|
+
|
|
3
|
+
  
|
|
4
|
+
|
|
5
|
+
> **Framework-agnostic TypeScript engine for conditional form field behavior**
|
|
6
|
+
> Define when fields should be visible, required, disabled, or readonly based on other field valuesβno framework lock-in.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## β¨ Features
|
|
11
|
+
|
|
12
|
+
- π― **Conditional rendering logic** β Show/hide fields based on form state
|
|
13
|
+
- β
**Dynamic validation** β Make fields required/optional conditionally
|
|
14
|
+
- π **Smart field states** β Disable or set readonly based on rules
|
|
15
|
+
- π§© **Framework agnostic** β Works with React, Vue, Angular, Svelte, or vanilla JS
|
|
16
|
+
- ποΈ **Easy w/r configuration** - Save and load field definitions from database or datasets
|
|
17
|
+
- πͺΆ **Zero dependencies** β Lightweight and tree-shakeable
|
|
18
|
+
- π **Full TypeScript support** β Type-safe rule definitions
|
|
19
|
+
- π§ͺ **Battle-tested** β Comprehensive test coverage with Jest
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## π Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @form-flow/core
|
|
27
|
+
# or
|
|
28
|
+
yarn add @form-flow/core
|
|
29
|
+
# or
|
|
30
|
+
pnpm add @form-flow/core
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## π Quick Start
|
|
36
|
+
|
|
37
|
+
### Basic Example
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { FieldDefinition, RuleEvaluator } from "@form-flow/core";
|
|
41
|
+
|
|
42
|
+
// Define your fields
|
|
43
|
+
const ageField: FieldDefinition = {
|
|
44
|
+
id: "age",
|
|
45
|
+
type: "number",
|
|
46
|
+
label: "Your Age"
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const consentField: FieldDefinition = {
|
|
50
|
+
id: "parentalConsent",
|
|
51
|
+
type: "checkbox",
|
|
52
|
+
label: "Parental Consent Required",
|
|
53
|
+
|
|
54
|
+
// Show this field only when age < 18
|
|
55
|
+
visibleIf: {
|
|
56
|
+
groupId: "visibility-group",
|
|
57
|
+
operator: "and",
|
|
58
|
+
ruleType: "visibleIf",
|
|
59
|
+
rules: [
|
|
60
|
+
{ ruleId: "1", conditionFieldId: "age", operator: "lt", value: 18 }
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// Make it required when visible
|
|
65
|
+
requiredIf: {
|
|
66
|
+
groupId: "required-group",
|
|
67
|
+
operator: "and",
|
|
68
|
+
ruleType: "requiredIf",
|
|
69
|
+
rules: [
|
|
70
|
+
{ ruleId: "2", conditionFieldId: "age", operator: "lt", value: 18 }
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// Evaluate rules against current form data
|
|
76
|
+
const formData = { age: 16 };
|
|
77
|
+
const fieldStates = RuleEvaluator.evaluateFields(
|
|
78
|
+
[ageField, consentField],
|
|
79
|
+
formData
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
console.log(fieldStates.parentalConsent.visible); // true
|
|
83
|
+
console.log(fieldStates.parentalConsent.required); // true
|
|
84
|
+
|
|
85
|
+
const formData2 = { age: 21 };
|
|
86
|
+
const fieldStates2 = RuleEvaluator.evaluateFields(
|
|
87
|
+
[ageField, consentField],
|
|
88
|
+
formData2
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
console.log(fieldStates2.parentalConsent.visible); // false
|
|
92
|
+
console.log(fieldStates2.parentalConsent.required); // false
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Advanced: Complex Rules
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const emailField: FieldDefinition = {
|
|
99
|
+
id: "workEmail",
|
|
100
|
+
type: "email",
|
|
101
|
+
label: "Work Email",
|
|
102
|
+
|
|
103
|
+
// Show if (employed AND age >= 18) OR freelancer
|
|
104
|
+
visibleIf: {
|
|
105
|
+
groupId: "email-visibility",
|
|
106
|
+
operator: "or",
|
|
107
|
+
ruleType: "visibleIf",
|
|
108
|
+
rules: [
|
|
109
|
+
{
|
|
110
|
+
groupId: "employed-adult",
|
|
111
|
+
operator: "and",
|
|
112
|
+
ruleType: "visibleIf",
|
|
113
|
+
rules: [
|
|
114
|
+
{ ruleId: "1", conditionFieldId: "employmentStatus", operator: "eq", value: "employed" },
|
|
115
|
+
{ ruleId: "2", conditionFieldId: "age", operator: "gte", value: 18 }
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
{ ruleId: "3", conditionFieldId: "employmentStatus", operator: "eq", value: "freelancer" }
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
|
|
122
|
+
// Readonly if verified
|
|
123
|
+
readonlyIf: {
|
|
124
|
+
groupId: "verified-check",
|
|
125
|
+
operator: "and",
|
|
126
|
+
ruleType: "readonlyIf",
|
|
127
|
+
rules: [
|
|
128
|
+
{ ruleId: "4", conditionFieldId: "emailVerified", operator: "eq", value: true }
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## π οΈ API Reference
|
|
137
|
+
|
|
138
|
+
### `RuleEvaluator.evaluateFields()`
|
|
139
|
+
|
|
140
|
+
Evaluates all conditional rules for your form fields.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const state: FormControlState = RuleEvaluator.evaluateFields(
|
|
144
|
+
fields: FieldDefinition[],
|
|
145
|
+
formData: Record<string, any>
|
|
146
|
+
);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Returns:** `FormControlState` β Map of field IDs to their computed states
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
{
|
|
153
|
+
[fieldId: string]: {
|
|
154
|
+
visible: boolean;
|
|
155
|
+
required: boolean;
|
|
156
|
+
disabled: boolean;
|
|
157
|
+
readonly: boolean;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### `FieldHelper.getAvailableRuleTypes()`
|
|
163
|
+
|
|
164
|
+
Get which rule types can still be added to a field.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { FieldHelper } from "@form-flow/core";
|
|
168
|
+
|
|
169
|
+
const availableRules = FieldHelper.getAvailableRuleTypes(consentField);
|
|
170
|
+
console.log(availableRules); // ["disabledIf", "readonlyIf"]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## π Core Concepts
|
|
176
|
+
|
|
177
|
+
### Rule Types
|
|
178
|
+
|
|
179
|
+
| Rule Type | Purpose | Example |
|
|
180
|
+
|-----------|---------|---------|
|
|
181
|
+
| `visibleIf` | Control field visibility | Show "Company Name" if employment is "employed" |
|
|
182
|
+
| `requiredIf` | Make field conditionally required | Require "Tax ID" if revenue > 50000 |
|
|
183
|
+
| `disabledIf` | Disable field interaction | Disable "Submit" until terms are accepted |
|
|
184
|
+
| `readonlyIf` | Make field read-only | Lock "Email" after verification |
|
|
185
|
+
|
|
186
|
+
### Operators
|
|
187
|
+
|
|
188
|
+
- **Comparison:** `eq`, `neq`, `lt`, `lte`, `gt`, `gte`
|
|
189
|
+
- **String:** `contains`, `startsWith`, `endsWith`
|
|
190
|
+
- **Logical:** `and`, `or` (for grouping rules)
|
|
191
|
+
|
|
192
|
+
### Type Definitions
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
// Field with conditional rules
|
|
196
|
+
type FieldDefinition<T = any> = {
|
|
197
|
+
id: string;
|
|
198
|
+
type: string;
|
|
199
|
+
label: string;
|
|
200
|
+
visibleIf?: FieldRuleGroupDefinition;
|
|
201
|
+
requiredIf?: FieldRuleGroupDefinition;
|
|
202
|
+
disabledIf?: FieldRuleGroupDefinition;
|
|
203
|
+
readonlyIf?: FieldRuleGroupDefinition;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Atomic rule
|
|
207
|
+
type FieldRuleDefinition = {
|
|
208
|
+
ruleId: string;
|
|
209
|
+
conditionFieldId: string;
|
|
210
|
+
operator: "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "contains" | "startsWith" | "endsWith";
|
|
211
|
+
value: any;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// Rule group (supports nesting)
|
|
215
|
+
type FieldRuleGroupDefinition = {
|
|
216
|
+
groupId: string;
|
|
217
|
+
operator: "and" | "or";
|
|
218
|
+
ruleType: ConditionalFieldProperty;
|
|
219
|
+
rules: Array<FieldRuleDefinition | FieldRuleGroupDefinition>;
|
|
220
|
+
};
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## π§ͺ Testing
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
npm run test
|
|
229
|
+
# or
|
|
230
|
+
yarn test
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Tests are written with **Jest** and cover both `RuleEvaluator` and `FieldHelper` with comprehensive test coverage.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## πΊοΈπ‘ Roadmap & Ideas
|
|
238
|
+
|
|
239
|
+
- [ ] **Visual Rule Builder** β Drag-and-drop UI for creating rules (React version in development)
|
|
240
|
+
- [ ] **Rule Templates** β Pre-built common patterns (age verification, address forms, etc.)
|
|
241
|
+
- [ ] **Async Rules** β Support for API-based conditions
|
|
242
|
+
- [ ] **Rule Debugging** β Dev tools for visualizing rule evaluation
|
|
243
|
+
- [ ] **Performance Optimizations** β Memoization and selective re-evaluation
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## π€ Contributing
|
|
248
|
+
|
|
249
|
+
Contributions are welcome! Please check out the [Contributing Guide](CONTRIBUTING.md).
|
|
250
|
+
|
|
251
|
+
1. Fork the repository
|
|
252
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
253
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
254
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
255
|
+
5. Open a Pull Request
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## π License
|
|
260
|
+
|
|
261
|
+
MIT Β© [Andrea Moretti]
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## β Support
|
|
266
|
+
|
|
267
|
+
If this library saves you time, consider supporting its development:
|
|
268
|
+
|
|
269
|
+
[](https://buymeacoffee.com/YOUR_USERNAME)
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## π Links
|
|
274
|
+
|
|
275
|
+
- [π¦ npm Package](https://www.npmjs.com/package/@form-flow/core)
|
|
276
|
+
- [π Report Issues](https://github.com/YOUR_USERNAME/form-flow-core/issues)
|
|
277
|
+
- [π¬ Discussions](https://github.com/YOUR_USERNAME/form-flow-core/discussions)
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
**Made with β€οΈ by the open-source community**
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FieldDefinition } from './models/field-definition';
|
|
2
|
+
export declare class DependencyGraph {
|
|
3
|
+
private dependentsMap;
|
|
4
|
+
constructor(fields: FieldDefinition[]);
|
|
5
|
+
/**
|
|
6
|
+
* Estrae le dipendenze ricorsivamente da una regola, che puΓ² essere un FieldRuleDefinition o un FieldRuleGroupDefinition.
|
|
7
|
+
*/
|
|
8
|
+
private extractDependencies;
|
|
9
|
+
/**
|
|
10
|
+
* Restituisce tutti i campi che dipendono da un campo specifico.
|
|
11
|
+
*/
|
|
12
|
+
getDependentFields(fieldId: string): Set<string>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=dependency-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-graph.d.ts","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAI5D,qBAAa,eAAe;IACxB,OAAO,CAAC,aAAa,CAAuC;gBAEhD,MAAM,EAAE,eAAe,EAAE;IAwBrC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAuB3B;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;CAiBnD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DependencyGraph = void 0;
|
|
4
|
+
const rule_helper_1 = require("./utility/rule-helper");
|
|
5
|
+
class DependencyGraph {
|
|
6
|
+
constructor(fields) {
|
|
7
|
+
this.dependentsMap = new Map();
|
|
8
|
+
fields.forEach(field => {
|
|
9
|
+
const dependencies = new Set();
|
|
10
|
+
// Estrazione delle dipendenze dalle regole
|
|
11
|
+
const fieldRules = ['visibleIf', 'requiredIf', 'disabledIf', 'readonlyIf'];
|
|
12
|
+
fieldRules.forEach(ruleName => {
|
|
13
|
+
const rule = field[ruleName];
|
|
14
|
+
if (rule) {
|
|
15
|
+
this.extractDependencies(rule, dependencies);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
// Registriamo le dipendenze
|
|
19
|
+
dependencies.forEach(dep => {
|
|
20
|
+
if (!this.dependentsMap.has(dep)) {
|
|
21
|
+
this.dependentsMap.set(dep, new Set());
|
|
22
|
+
}
|
|
23
|
+
this.dependentsMap.get(dep).add(field.id);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Estrae le dipendenze ricorsivamente da una regola, che puΓ² essere un FieldRuleDefinition o un FieldRuleGroupDefinition.
|
|
29
|
+
*/
|
|
30
|
+
extractDependencies(rule, dependencies) {
|
|
31
|
+
if ('conditionFieldId' in rule) {
|
|
32
|
+
// Se Γ¨ una FieldRuleDefinition, aggiungi il conditionFieldId
|
|
33
|
+
dependencies.add(rule.conditionFieldId);
|
|
34
|
+
}
|
|
35
|
+
if ('rules' in rule) {
|
|
36
|
+
// Se Γ¨ un FieldRuleGroupDefinition, esploriamo ricorsivamente le regole
|
|
37
|
+
const groups = rule_helper_1.RuleHelper.getGroups(rule);
|
|
38
|
+
const rules = rule_helper_1.RuleHelper.getRules(rule);
|
|
39
|
+
// Esplora i gruppi
|
|
40
|
+
groups.forEach(group => {
|
|
41
|
+
this.extractDependencies(group, dependencies);
|
|
42
|
+
});
|
|
43
|
+
// Esplora le regole singole
|
|
44
|
+
rules.forEach(r => {
|
|
45
|
+
this.extractDependencies(r, dependencies);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Restituisce tutti i campi che dipendono da un campo specifico.
|
|
51
|
+
*/
|
|
52
|
+
getDependentFields(fieldId) {
|
|
53
|
+
const visited = new Set();
|
|
54
|
+
const stack = [fieldId];
|
|
55
|
+
while (stack.length > 0) {
|
|
56
|
+
const current = stack.pop();
|
|
57
|
+
const dependents = this.dependentsMap.get(current) ?? new Set();
|
|
58
|
+
for (const dep of dependents) {
|
|
59
|
+
if (!visited.has(dep)) {
|
|
60
|
+
visited.add(dep);
|
|
61
|
+
stack.push(dep);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return visited;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.DependencyGraph = DependencyGraph;
|
|
69
|
+
//# sourceMappingURL=dependency-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-graph.js","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":";;;AAEA,uDAAmD;AAEnD,MAAa,eAAe;IAGxB,YAAY,MAAyB;QAF7B,kBAAa,GAA6B,IAAI,GAAG,EAAE,CAAC;QAGxD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACnB,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;YAEvC,2CAA2C;YAC3C,MAAM,UAAU,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;YAC3E,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAC1B,MAAM,IAAI,GAAG,KAAK,CAAC,QAAiC,CAAC,CAAC;gBAEtD,IAAI,IAAI,EAAE,CAAC;oBACP,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;gBACjD,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,4BAA4B;YAC5B,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACvB,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;gBAC3C,CAAC;gBACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACK,mBAAmB,CAAC,IAAmB,EAAE,YAAyB;QACtE,IAAI,kBAAkB,IAAI,IAAI,EAAE,CAAC;YAC7B,6DAA6D;YAC7D,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YAClB,wEAAwE;YACxE,MAAM,MAAM,GAAG,wBAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,KAAK,GAAG,wBAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YAExC,mBAAmB;YACnB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACnB,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAClD,CAAC,CAAC,CAAC;YAEH,4BAA4B;YAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;gBACd,IAAI,CAAC,mBAAmB,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,OAAe;QAC9B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAClC,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC;QAExB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;YAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;YAChE,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;gBAC3B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBACpB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBACjB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACpB,CAAC;YACL,CAAC;QACL,CAAC;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAzED,0CAyEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { type FieldControlType, type FieldDefinition, type ConditionalFieldProperty, type FieldListOption, type FieldControlState, type CustomFieldControlType, type FormControlState, } from './models/field-definition';
|
|
2
|
+
export { type FormFlowDefinition, type FormFlowSchema, type FormFlowValues, } from './models/form-definition';
|
|
3
|
+
export { type FieldRuleGroupDefinition, type FieldRuleNode, type LogicalOperator, } from './models/group';
|
|
4
|
+
export { type FieldRuleDefinition } from './models/rule';
|
|
5
|
+
export { RuleEvaluator as FormFlowRuleEvaluator } from './rule-evaluator';
|
|
6
|
+
export { FORM_FLOW_OPERATORS_MAP, type RuleOperatorKey, type RuleOperatorMeta, type RuleOperatorValueType, } from './models/operators';
|
|
7
|
+
export { OperatorRegistry as FormFlowOperatorRegistry } from './models/operator-registry';
|
|
8
|
+
export { DependencyGraph as FormFlowDependencyGraph } from './dependency-graph';
|
|
9
|
+
export { RuleBuilder as FormFlowRuleBuilder } from './rule-builder';
|
|
10
|
+
export { RuleMapper as FormFlowRuleMapper } from './utility/rule-mapper';
|
|
11
|
+
export { RuleHelper as FormFlowRuleHelper } from './utility/rule-helper';
|
|
12
|
+
export { FieldHelper as FormFlowFieldHelper } from './utility/field-helper';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,cAAc,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,KAAK,wBAAwB,EAC7B,KAAK,aAAa,EAClB,KAAK,eAAe,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIzD,OAAO,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG1E,OAAO,EACH,uBAAuB,EACvB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,GAC7B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACH,gBAAgB,IAAI,wBAAwB,EAC/C,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,eAAe,IAAI,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAE,WAAW,IAAI,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,WAAW,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// packages/core/src/index.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FormFlowFieldHelper = exports.FormFlowRuleHelper = exports.FormFlowRuleMapper = exports.FormFlowRuleBuilder = exports.FormFlowDependencyGraph = exports.FormFlowOperatorRegistry = exports.FORM_FLOW_OPERATORS_MAP = exports.FormFlowRuleEvaluator = void 0;
|
|
5
|
+
// 3. Valutatore ufficiale del sistema
|
|
6
|
+
var rule_evaluator_1 = require("./rule-evaluator");
|
|
7
|
+
Object.defineProperty(exports, "FormFlowRuleEvaluator", { enumerable: true, get: function () { return rule_evaluator_1.RuleEvaluator; } });
|
|
8
|
+
// 4. (Opzionale) operatori configurabili, se vuoi supportare override dal consumer
|
|
9
|
+
var operators_1 = require("./models/operators");
|
|
10
|
+
Object.defineProperty(exports, "FORM_FLOW_OPERATORS_MAP", { enumerable: true, get: function () { return operators_1.FORM_FLOW_OPERATORS_MAP; } });
|
|
11
|
+
var operator_registry_1 = require("./models/operator-registry");
|
|
12
|
+
Object.defineProperty(exports, "FormFlowOperatorRegistry", { enumerable: true, get: function () { return operator_registry_1.OperatorRegistry; } });
|
|
13
|
+
var dependency_graph_1 = require("./dependency-graph");
|
|
14
|
+
Object.defineProperty(exports, "FormFlowDependencyGraph", { enumerable: true, get: function () { return dependency_graph_1.DependencyGraph; } });
|
|
15
|
+
var rule_builder_1 = require("./rule-builder");
|
|
16
|
+
Object.defineProperty(exports, "FormFlowRuleBuilder", { enumerable: true, get: function () { return rule_builder_1.RuleBuilder; } });
|
|
17
|
+
var rule_mapper_1 = require("./utility/rule-mapper");
|
|
18
|
+
Object.defineProperty(exports, "FormFlowRuleMapper", { enumerable: true, get: function () { return rule_mapper_1.RuleMapper; } });
|
|
19
|
+
var rule_helper_1 = require("./utility/rule-helper");
|
|
20
|
+
Object.defineProperty(exports, "FormFlowRuleHelper", { enumerable: true, get: function () { return rule_helper_1.RuleHelper; } });
|
|
21
|
+
var field_helper_1 = require("./utility/field-helper");
|
|
22
|
+
Object.defineProperty(exports, "FormFlowFieldHelper", { enumerable: true, get: function () { return field_helper_1.FieldHelper; } });
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;AAyB7B,sCAAsC;AACtC,mDAA0E;AAAjE,uHAAA,aAAa,OAAyB;AAE/C,mFAAmF;AACnF,gDAK4B;AAJxB,oHAAA,uBAAuB,OAAA;AAM3B,gEAEmC;AAD/B,6HAAA,gBAAgB,OAA4B;AAGhD,uDAAgF;AAAvE,2HAAA,eAAe,OAA2B;AAEnD,+CAAoE;AAA3D,mHAAA,WAAW,OAAuB;AAC3C,qDAAyE;AAAhE,iHAAA,UAAU,OAAsB;AACzC,qDAAyE;AAAhE,iHAAA,UAAU,OAAsB;AACzC,uDAA4E;AAAnE,mHAAA,WAAW,OAAuB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { FieldRuleGroupDefinition } from './group';
|
|
2
|
+
export type FieldControlType = 'text' | 'number' | 'date' | 'singleSelect' | 'multipleSelect' | 'checkbox';
|
|
3
|
+
export type CustomFieldControlType<T extends string = never> = FieldControlType | Exclude<T, FieldControlType>;
|
|
4
|
+
export type ConditionalFieldProperty = "visibleIf" | "requiredIf" | "disabledIf" | "readonlyIf";
|
|
5
|
+
export type FieldListOption = {
|
|
6
|
+
label: string;
|
|
7
|
+
value: any;
|
|
8
|
+
} & Record<string, any>;
|
|
9
|
+
export interface FieldDefinition<TControl extends FieldControlType = FieldControlType> {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
type: TControl;
|
|
13
|
+
defaultValue?: any;
|
|
14
|
+
visibleIf?: FieldRuleGroupDefinition;
|
|
15
|
+
requiredIf?: FieldRuleGroupDefinition;
|
|
16
|
+
disabledIf?: FieldRuleGroupDefinition;
|
|
17
|
+
readonlyIf?: FieldRuleGroupDefinition;
|
|
18
|
+
/**
|
|
19
|
+
* List of available options for fields like select, checkbox, or radio buttons.
|
|
20
|
+
*
|
|
21
|
+
* The base shape is defined by `FieldOption`, which requires:
|
|
22
|
+
* - `label`: the text displayed to the user
|
|
23
|
+
* - `value`: the actual value stored/submitted
|
|
24
|
+
*
|
|
25
|
+
* The `FieldOption` type is **not exported**, but consumers can still conform
|
|
26
|
+
* to its shape using `satisfies` to ensure compatibility while extending it
|
|
27
|
+
* with additional UI-related metadata (e.g. icons, images, tooltips).
|
|
28
|
+
*
|
|
29
|
+
* Example:
|
|
30
|
+
*
|
|
31
|
+
* const options = [
|
|
32
|
+
* { label: "Startup", value: "startup", icon: "π" },
|
|
33
|
+
* { label: "Agency", value: "agency", icon: "π’" },
|
|
34
|
+
* { label: "Freelancer", value: "freelancer", icon: "π§βπ»" }
|
|
35
|
+
* ] satisfies FieldOption[];
|
|
36
|
+
*/
|
|
37
|
+
options?: FieldListOption[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Rappresenta il campo target dopo la valutazione delle regole condizionali
|
|
41
|
+
*/
|
|
42
|
+
export interface FieldControlState {
|
|
43
|
+
visible: boolean;
|
|
44
|
+
required: boolean;
|
|
45
|
+
disabled: boolean;
|
|
46
|
+
readonly: boolean;
|
|
47
|
+
}
|
|
48
|
+
export type FormControlState = Record<string, FieldControlState>;
|
|
49
|
+
//# sourceMappingURL=field-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-definition.d.ts","sourceRoot":"","sources":["../../src/models/field-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,cAAc,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAC3G,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,KAAK,IACzD,gBAAgB,GAAG,OAAO,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;AAClD,MAAM,MAAM,wBAAwB,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;AAQhG,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;CACZ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAExB,MAAM,WAAW,eAAe,CAAC,QAAQ,SAAS,gBAAgB,GAAG,gBAAgB;IACnF,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;IACf,YAAY,CAAC,EAAE,GAAG,CAAC;IAGnB,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,UAAU,CAAC,EAAE,wBAAwB,CAAC;IACtC,UAAU,CAAC,EAAE,wBAAwB,CAAC;IACtC,UAAU,CAAC,EAAE,wBAAwB,CAAC;IAEtC;;;;;;;;;;;;;;;;;;KAkBC;IACD,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;CAC7B;AAGD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB;AACD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-definition.js","sourceRoot":"","sources":["../../src/models/field-definition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CustomFieldControlType, FieldDefinition } from "./field-definition";
|
|
2
|
+
export type FormFlowValues = Record<string, any>;
|
|
3
|
+
export interface FormFlowDefinition<TControl extends CustomFieldControlType = CustomFieldControlType> {
|
|
4
|
+
formId: string;
|
|
5
|
+
fields: FieldDefinition<TControl>[];
|
|
6
|
+
metadata?: Record<string, any>;
|
|
7
|
+
}
|
|
8
|
+
export interface FormFlowSchema<TControl extends CustomFieldControlType = CustomFieldControlType> {
|
|
9
|
+
definition: FormFlowDefinition<TControl>;
|
|
10
|
+
getValues: () => FormFlowValues;
|
|
11
|
+
getFieldValue: (fieldId: keyof FormFlowValues) => any;
|
|
12
|
+
setValues: (values: FormFlowValues, emit?: boolean) => void;
|
|
13
|
+
setFieldValue: (fieldId: keyof FormFlowValues, value: any, emit?: boolean) => void;
|
|
14
|
+
readonly values: FormFlowValues;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=form-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-definition.d.ts","sourceRoot":"","sources":["../../src/models/form-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE7E,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEjD,MAAM,WAAW,kBAAkB,CAC9B,QAAQ,SAAS,sBAAsB,GAAG,sBAAsB;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,cAAc,CAAC,QAAQ,SAAS,sBAAsB,GAAG,sBAAsB;IAC5F,UAAU,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IACxC,SAAS,EAAE,MAAM,cAAc,CAAC;IAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,cAAc,KAAK,GAAG,CAAC;IACtD,SAAS,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5D,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACnF,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-definition.js","sourceRoot":"","sources":["../../src/models/form-definition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConditionalFieldProperty } from "./field-definition";
|
|
2
|
+
import { FieldRuleDefinition } from "./rule";
|
|
3
|
+
export type LogicalOperator = "and" | "or";
|
|
4
|
+
export type FieldRuleNode = FieldRuleDefinition | FieldRuleGroupDefinition;
|
|
5
|
+
export interface FieldRuleGroupDefinition {
|
|
6
|
+
groupId: string;
|
|
7
|
+
ruleType: ConditionalFieldProperty;
|
|
8
|
+
operator: LogicalOperator;
|
|
9
|
+
not?: boolean;
|
|
10
|
+
rules: FieldRuleNode[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/models/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,IAAI,CAAC;AAC3C,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,wBAAwB,CAAC;AAC3E,MAAM,WAAW,wBAAwB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,wBAAwB,CAAC;IACnC,QAAQ,EAAE,eAAe,CAAC;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,aAAa,EAAE,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/models/group.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { RuleOperatorKey, RuleOperatorMeta } from "./operators";
|
|
2
|
+
export declare const OperatorRegistry: {
|
|
3
|
+
/**
|
|
4
|
+
* Get the definition of a specific operator by key.
|
|
5
|
+
*/
|
|
6
|
+
get: (key: RuleOperatorKey) => RuleOperatorMeta | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Get all operator definitions (e.g., for building UI pickers).
|
|
9
|
+
*/
|
|
10
|
+
getAll: () => Partial<Record<RuleOperatorKey, RuleOperatorMeta>>;
|
|
11
|
+
/**
|
|
12
|
+
* Register one or more operator overrides or additions.
|
|
13
|
+
* Existing operators with the same key will be replaced.
|
|
14
|
+
*/
|
|
15
|
+
register: (overrides: Partial<Record<RuleOperatorKey, RuleOperatorMeta>>) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Reset the registry to the original default operator map.
|
|
18
|
+
*/
|
|
19
|
+
reset: () => void;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=operator-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator-registry.d.ts","sourceRoot":"","sources":["../../src/models/operator-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKzF,eAAO,MAAM,gBAAgB;IACzB;;OAEG;eACQ,eAAe,KAAG,gBAAgB,GAAG,SAAS;IAEzD;;OAEG;kBACS,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IAE9D;;;OAGG;0BACmB,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IAIxE;;OAEG;;CAIN,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OperatorRegistry = void 0;
|
|
4
|
+
// operator-registry.ts
|
|
5
|
+
const operators_1 = require("./operators");
|
|
6
|
+
// Mutable copy of the original operator map
|
|
7
|
+
let registry = { ...operators_1.FORM_FLOW_OPERATORS_MAP };
|
|
8
|
+
exports.OperatorRegistry = {
|
|
9
|
+
/**
|
|
10
|
+
* Get the definition of a specific operator by key.
|
|
11
|
+
*/
|
|
12
|
+
get: (key) => registry[key],
|
|
13
|
+
/**
|
|
14
|
+
* Get all operator definitions (e.g., for building UI pickers).
|
|
15
|
+
*/
|
|
16
|
+
getAll: () => registry,
|
|
17
|
+
/**
|
|
18
|
+
* Register one or more operator overrides or additions.
|
|
19
|
+
* Existing operators with the same key will be replaced.
|
|
20
|
+
*/
|
|
21
|
+
register: (overrides) => {
|
|
22
|
+
registry = { ...registry, ...overrides };
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Reset the registry to the original default operator map.
|
|
26
|
+
*/
|
|
27
|
+
reset: () => {
|
|
28
|
+
registry = { ...operators_1.FORM_FLOW_OPERATORS_MAP };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=operator-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator-registry.js","sourceRoot":"","sources":["../../src/models/operator-registry.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,2CAAyF;AAEzF,4CAA4C;AAC5C,IAAI,QAAQ,GAAuD,EAAE,GAAG,mCAAuB,EAAE,CAAC;AAErF,QAAA,gBAAgB,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,CAAC,GAAoB,EAAgC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;IAE1E;;OAEG;IACH,MAAM,EAAE,GAAuD,EAAE,CAAC,QAAQ;IAE1E;;;OAGG;IACH,QAAQ,EAAE,CAAC,SAA6D,EAAE,EAAE;QACxE,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,KAAK,EAAE,GAAG,EAAE;QACR,QAAQ,GAAG,EAAE,GAAG,mCAAuB,EAAE,CAAC;IAC9C,CAAC;CACJ,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { RuleBuilder } from "../rule-builder";
|
|
2
|
+
import { FieldControlType } from "./field-definition";
|
|
3
|
+
/**
|
|
4
|
+
* Base operators defined inside RuleBuilder.
|
|
5
|
+
*/
|
|
6
|
+
type RuleOperatorBase = keyof typeof RuleBuilder.value;
|
|
7
|
+
/**
|
|
8
|
+
* Special operator that represents a field reference.
|
|
9
|
+
*/
|
|
10
|
+
type RuleOperatorSpecial = "var";
|
|
11
|
+
/**
|
|
12
|
+
* Union of all operator keys supported by the system.
|
|
13
|
+
*/
|
|
14
|
+
export type RuleOperatorKey = RuleOperatorBase | RuleOperatorSpecial;
|
|
15
|
+
/**
|
|
16
|
+
* Defines the kind of value an operator expects:
|
|
17
|
+
* - "list": expects an array of values
|
|
18
|
+
* - "single": expects a single value
|
|
19
|
+
* - "none": no value required (boolean-like)
|
|
20
|
+
* - "field": expects a reference to another field
|
|
21
|
+
* - undefined: not specified
|
|
22
|
+
*/
|
|
23
|
+
export type RuleOperatorValueType = "list" | "single" | "none" | "field" | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Metadata for describing how an operator behaves.
|
|
26
|
+
*/
|
|
27
|
+
export interface RuleOperatorMeta {
|
|
28
|
+
/** Label to display in the UI (can be customized by consumers). */
|
|
29
|
+
label: string;
|
|
30
|
+
/** Which field types this operator is allowed for. */
|
|
31
|
+
allowedTypes?: FieldControlType[] | "all";
|
|
32
|
+
/** The type of value this operator requires. */
|
|
33
|
+
valueType?: RuleOperatorValueType;
|
|
34
|
+
/** If true, the operator will be hidden from the UI picker. */
|
|
35
|
+
hideFromPicker?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Default operator map shipped with `@form-flow/core`.
|
|
39
|
+
* Consumers may override or extend this map at runtime.
|
|
40
|
+
*/
|
|
41
|
+
export declare const FORM_FLOW_OPERATORS_MAP: Partial<Record<RuleOperatorKey, RuleOperatorMeta>>;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=operators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.d.ts","sourceRoot":"","sources":["../../src/models/operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD;;GAEG;AACH,KAAK,gBAAgB,GAAG,MAAM,OAAO,WAAW,CAAC,KAAK,CAAC;AAEvD;;GAEG;AACH,KAAK,mBAAmB,GAAG,KAAK,CAAC;AAEjC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAC7B,MAAM,GACN,QAAQ,GACR,MAAM,GACN,OAAO,GACP,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IAEd,sDAAsD;IACtD,YAAY,CAAC,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IAE1C,gDAAgD;IAChD,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAElC,+DAA+D;IAC/D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAClC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAoBlD,CAAC"}
|