@form-flow/core 1.0.0 → 2.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 +59 -8
- package/dist/dependency-graph.d.ts +4 -2
- package/dist/dependency-graph.d.ts.map +1 -1
- package/dist/dependency-graph.js +12 -1
- package/dist/dependency-graph.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/models/field-definition.d.ts +24 -10
- package/dist/models/field-definition.d.ts.map +1 -1
- package/dist/models/form-definition.d.ts +6 -5
- package/dist/models/form-definition.d.ts.map +1 -1
- package/dist/models/operator-registry.d.ts +3 -3
- package/dist/models/operator-registry.d.ts.map +1 -1
- package/dist/models/operator-registry.js.map +1 -1
- package/dist/models/operators.d.ts +4 -3
- package/dist/models/operators.d.ts.map +1 -1
- package/dist/models/operators.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# @form-flow/core
|
|
2
|
+

|
|
3
|
+

|
|
2
4
|
|
|
3
|
-
  
|
|
4
5
|
|
|
5
6
|
> **Framework-agnostic TypeScript engine for conditional form field behavior**
|
|
6
7
|
> Define when fields should be visible, required, disabled, or readonly based on other field values—no framework lock-in.
|
|
8
|
+
> Form-flow rules are based on [json-logic-js](https://github.com/jwadhams/json-logic-js)
|
|
7
9
|
|
|
8
10
|
---
|
|
9
11
|
|
|
@@ -159,6 +161,43 @@ const state: FormControlState = RuleEvaluator.evaluateFields(
|
|
|
159
161
|
}
|
|
160
162
|
```
|
|
161
163
|
|
|
164
|
+
### Rule context fields
|
|
165
|
+
|
|
166
|
+
Use `definition.ruleContextFields` to expose source-only paths that can be referenced in rules without promoting them to target form fields.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const definition = {
|
|
170
|
+
formId: "deal-form",
|
|
171
|
+
fields: [
|
|
172
|
+
{
|
|
173
|
+
id: "deal.goal",
|
|
174
|
+
type: "number",
|
|
175
|
+
label: "Deal Goal",
|
|
176
|
+
visibleIf: {
|
|
177
|
+
groupId: "goal-visible",
|
|
178
|
+
operator: "and",
|
|
179
|
+
ruleType: "visibleIf",
|
|
180
|
+
rules: [
|
|
181
|
+
{
|
|
182
|
+
ruleId: "1",
|
|
183
|
+
conditionFieldId: "customer.yearlyEarnings",
|
|
184
|
+
operator: "gte",
|
|
185
|
+
value: 1000
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
ruleContextFields: [
|
|
192
|
+
{
|
|
193
|
+
id: "customer.yearlyEarnings",
|
|
194
|
+
type: "number",
|
|
195
|
+
label: "Customer Yearly Earnings"
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
162
201
|
### `FieldHelper.getAvailableRuleTypes()`
|
|
163
202
|
|
|
164
203
|
Get which rule types can still be added to a field.
|
|
@@ -192,17 +231,28 @@ console.log(availableRules); // ["disabledIf", "readonlyIf"]
|
|
|
192
231
|
### Type Definitions
|
|
193
232
|
|
|
194
233
|
```ts
|
|
195
|
-
|
|
196
|
-
type FieldDefinition<T = any> = {
|
|
234
|
+
type BaseFieldDefinition<T = any> = {
|
|
197
235
|
id: string;
|
|
198
236
|
type: string;
|
|
199
237
|
label: string;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
// Field with conditional rules
|
|
241
|
+
type FieldDefinition<T = any> = BaseFieldDefinition<T> & {
|
|
200
242
|
visibleIf?: FieldRuleGroupDefinition;
|
|
201
243
|
requiredIf?: FieldRuleGroupDefinition;
|
|
202
244
|
disabledIf?: FieldRuleGroupDefinition;
|
|
203
245
|
readonlyIf?: FieldRuleGroupDefinition;
|
|
204
246
|
};
|
|
205
247
|
|
|
248
|
+
type RuleContextFieldDefinition<T = any> = BaseFieldDefinition<T>;
|
|
249
|
+
|
|
250
|
+
type FormFlowDefinition<T = any> = {
|
|
251
|
+
formId: string;
|
|
252
|
+
fields: FieldDefinition<T>[];
|
|
253
|
+
ruleContextFields?: RuleContextFieldDefinition<T>[];
|
|
254
|
+
};
|
|
255
|
+
|
|
206
256
|
// Atomic rule
|
|
207
257
|
type FieldRuleDefinition = {
|
|
208
258
|
ruleId: string;
|
|
@@ -244,7 +294,7 @@ Tests are written with **Jest** and cover both `RuleEvaluator` and `FieldHelper`
|
|
|
244
294
|
|
|
245
295
|
---
|
|
246
296
|
|
|
247
|
-
|
|
297
|
+
<!--## 🤝 Contributing
|
|
248
298
|
|
|
249
299
|
Contributions are welcome! Please check out the [Contributing Guide](CONTRIBUTING.md).
|
|
250
300
|
|
|
@@ -255,6 +305,7 @@ Contributions are welcome! Please check out the [Contributing Guide](CONTRIBUTIN
|
|
|
255
305
|
5. Open a Pull Request
|
|
256
306
|
|
|
257
307
|
---
|
|
308
|
+
-->
|
|
258
309
|
|
|
259
310
|
## 📄 License
|
|
260
311
|
|
|
@@ -264,17 +315,17 @@ MIT © [Andrea Moretti]
|
|
|
264
315
|
|
|
265
316
|
## ☕ Support
|
|
266
317
|
|
|
267
|
-
If this library saves you time,
|
|
318
|
+
If this library saves you time, or you just like my work you can just
|
|
268
319
|
|
|
269
|
-
[](https://buymeacoffee.com/andrea.moretti)
|
|
270
321
|
|
|
271
322
|
---
|
|
272
323
|
|
|
273
324
|
## 🔗 Links
|
|
274
325
|
|
|
275
326
|
- [📦 npm Package](https://www.npmjs.com/package/@form-flow/core)
|
|
276
|
-
- [🐛 Report Issues](https://github.com/
|
|
277
|
-
- [💬 Discussions](https://github.com/
|
|
327
|
+
- [🐛 Report Issues](https://github.com/amoretti-dev/form-flow-core/issues)
|
|
328
|
+
- [💬 Discussions](https://github.com/amoretti-dev/form-flow-core/discussions)
|
|
278
329
|
|
|
279
330
|
---
|
|
280
331
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { FieldDefinition } from './models/field-definition';
|
|
1
|
+
import { FieldDefinition, RuleContextFieldDefinition } from './models/field-definition';
|
|
2
|
+
import { FormFlowDefinition } from './models/form-definition';
|
|
2
3
|
export declare class DependencyGraph {
|
|
3
4
|
private dependentsMap;
|
|
4
|
-
constructor(
|
|
5
|
+
constructor(definition: FormFlowDefinition);
|
|
6
|
+
constructor(fields: FieldDefinition[], ruleContextFields?: RuleContextFieldDefinition[]);
|
|
5
7
|
/**
|
|
6
8
|
* Estrae le dipendenze ricorsivamente da una regola, che può essere un FieldRuleDefinition o un FieldRuleGroupDefinition.
|
|
7
9
|
*/
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"dependency-graph.d.ts","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D,qBAAa,eAAe;IACxB,OAAO,CAAC,aAAa,CAAuC;gBAEhD,UAAU,EAAE,kBAAkB;gBAC9B,MAAM,EAAE,eAAe,EAAE,EAAE,iBAAiB,CAAC,EAAE,0BAA0B,EAAE;IAyCvF;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAuB3B;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;CAiBnD"}
|
package/dist/dependency-graph.js
CHANGED
|
@@ -3,8 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DependencyGraph = void 0;
|
|
4
4
|
const rule_helper_1 = require("./utility/rule-helper");
|
|
5
5
|
class DependencyGraph {
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(definitionOrFields, ruleContextFields = []) {
|
|
7
7
|
this.dependentsMap = new Map();
|
|
8
|
+
const fields = Array.isArray(definitionOrFields)
|
|
9
|
+
? definitionOrFields
|
|
10
|
+
: definitionOrFields.fields;
|
|
11
|
+
const contextFields = Array.isArray(definitionOrFields)
|
|
12
|
+
? ruleContextFields
|
|
13
|
+
: definitionOrFields.ruleContextFields ?? [];
|
|
14
|
+
contextFields.forEach((field) => {
|
|
15
|
+
if (!this.dependentsMap.has(field.id)) {
|
|
16
|
+
this.dependentsMap.set(field.id, new Set());
|
|
17
|
+
}
|
|
18
|
+
});
|
|
8
19
|
fields.forEach(field => {
|
|
9
20
|
const dependencies = new Set();
|
|
10
21
|
// Estrazione delle dipendenze dalle regole
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-graph.js","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"dependency-graph.js","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":";;;AAGA,uDAAmD;AAEnD,MAAa,eAAe;IAKxB,YACI,kBAA0D,EAC1D,oBAAkD,EAAE;QANhD,kBAAa,GAA6B,IAAI,GAAG,EAAE,CAAC;QAQxD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;YAC5C,CAAC,CAAC,kBAAkB;YACpB,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC;QAChC,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACnD,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,kBAAkB,CAAC,iBAAiB,IAAI,EAAE,CAAC;QAEjD,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,aAAa,CAAC,GAAG,CA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I,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;AA3FD,0CA2FC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { type FieldControlType, type FieldDefinition, type ConditionalFieldProperty, type FieldListOption, type FieldControlState, type CustomFieldControlType, type FormControlState, } from './models/field-definition';
|
|
1
|
+
export { type BaseFieldDefinition, type FieldControlType, type FieldDefinition, type ConditionalFieldProperty, type FieldListOption, type FieldControlState, type CustomFieldControlType, type FormControlState, type RuleContextFieldDefinition, } from './models/field-definition';
|
|
2
2
|
export { type FormFlowDefinition, type FormFlowSchema, type FormFlowValues, } from './models/form-definition';
|
|
3
3
|
export { type FieldRuleGroupDefinition, type FieldRuleNode, type LogicalOperator, } from './models/group';
|
|
4
4
|
export { type FieldRuleDefinition } from './models/rule';
|
|
5
5
|
export { RuleEvaluator as FormFlowRuleEvaluator } from './rule-evaluator';
|
|
6
|
-
export {
|
|
6
|
+
export { type RuleOperatorKey, type RuleOperatorMeta, type RuleOperatorValueType, } from './models/operators';
|
|
7
7
|
export { OperatorRegistry as FormFlowOperatorRegistry } from './models/operator-registry';
|
|
8
8
|
export { DependencyGraph as FormFlowDependencyGraph } from './dependency-graph';
|
|
9
9
|
export { RuleBuilder as FormFlowRuleBuilder } from './rule-builder';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,0BAA0B,GAClC,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,EAEH,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
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// packages/core/src/index.ts
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.FormFlowFieldHelper = exports.FormFlowRuleHelper = exports.FormFlowRuleMapper = exports.FormFlowRuleBuilder = exports.FormFlowDependencyGraph = exports.FormFlowOperatorRegistry = exports.
|
|
4
|
+
exports.FormFlowFieldHelper = exports.FormFlowRuleHelper = exports.FormFlowRuleMapper = exports.FormFlowRuleBuilder = exports.FormFlowDependencyGraph = exports.FormFlowOperatorRegistry = exports.FormFlowRuleEvaluator = void 0;
|
|
5
5
|
// 3. Valutatore ufficiale del sistema
|
|
6
6
|
var rule_evaluator_1 = require("./rule-evaluator");
|
|
7
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
8
|
var operator_registry_1 = require("./models/operator-registry");
|
|
12
9
|
Object.defineProperty(exports, "FormFlowOperatorRegistry", { enumerable: true, get: function () { return operator_registry_1.OperatorRegistry; } });
|
|
13
10
|
var dependency_graph_1 = require("./dependency-graph");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6BAA6B;;;AA2B7B,sCAAsC;AACtC,mDAA0E;AAAjE,uHAAA,aAAa,OAAyB;AAU/C,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"}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { FieldRuleGroupDefinition } from './group';
|
|
2
|
-
export type
|
|
2
|
+
export type BuiltInFieldControlType = "text" | "number" | "date" | "singleSelect" | "multipleSelect" | "checkbox";
|
|
3
|
+
export type FieldControlType<TCustom extends string = never> = BuiltInFieldControlType | Exclude<TCustom, BuiltInFieldControlType>;
|
|
4
|
+
/** @deprecated Use FieldControlType<TCustom> */
|
|
3
5
|
export type CustomFieldControlType<T extends string = never> = FieldControlType | Exclude<T, FieldControlType>;
|
|
4
6
|
export type ConditionalFieldProperty = "visibleIf" | "requiredIf" | "disabledIf" | "readonlyIf";
|
|
5
7
|
export type FieldListOption = {
|
|
6
8
|
label: string;
|
|
7
9
|
value: any;
|
|
8
10
|
} & Record<string, any>;
|
|
9
|
-
export interface
|
|
11
|
+
export interface BaseFieldDefinition<TCustom extends string = never> {
|
|
10
12
|
id: string;
|
|
11
13
|
label: string;
|
|
12
|
-
type:
|
|
13
|
-
|
|
14
|
-
visibleIf?: FieldRuleGroupDefinition;
|
|
15
|
-
requiredIf?: FieldRuleGroupDefinition;
|
|
16
|
-
disabledIf?: FieldRuleGroupDefinition;
|
|
17
|
-
readonlyIf?: FieldRuleGroupDefinition;
|
|
14
|
+
type: FieldControlType<TCustom>;
|
|
15
|
+
metadata?: Record<string, any>;
|
|
18
16
|
/**
|
|
19
17
|
* List of available options for fields like select, checkbox, or radio buttons.
|
|
20
18
|
*
|
|
@@ -26,18 +24,34 @@ export interface FieldDefinition<TControl extends FieldControlType = FieldContro
|
|
|
26
24
|
* to its shape using `satisfies` to ensure compatibility while extending it
|
|
27
25
|
* with additional UI-related metadata (e.g. icons, images, tooltips).
|
|
28
26
|
*
|
|
29
|
-
*
|
|
27
|
+
* @example
|
|
30
28
|
*
|
|
29
|
+
* ```tsx
|
|
31
30
|
* const options = [
|
|
32
31
|
* { label: "Startup", value: "startup", icon: "🚀" },
|
|
33
32
|
* { label: "Agency", value: "agency", icon: "🏢" },
|
|
34
33
|
* { label: "Freelancer", value: "freelancer", icon: "🧑💻" }
|
|
35
34
|
* ] satisfies FieldOption[];
|
|
35
|
+
* ```
|
|
36
36
|
*/
|
|
37
37
|
options?: FieldListOption[];
|
|
38
38
|
}
|
|
39
|
+
export interface FieldDefinition<TCustom extends string = never> extends BaseFieldDefinition<TCustom> {
|
|
40
|
+
defaultValue?: any;
|
|
41
|
+
visibleIf?: FieldRuleGroupDefinition;
|
|
42
|
+
requiredIf?: FieldRuleGroupDefinition;
|
|
43
|
+
disabledIf?: FieldRuleGroupDefinition;
|
|
44
|
+
readonlyIf?: FieldRuleGroupDefinition;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Source-only field made available to rule builders and dependency tracking.
|
|
48
|
+
* It can be referenced inside conditions, but it is never evaluated as a target
|
|
49
|
+
* control state by the core runtime.
|
|
50
|
+
*/
|
|
51
|
+
export interface RuleContextFieldDefinition<TCustom extends string = never> extends BaseFieldDefinition<TCustom> {
|
|
52
|
+
}
|
|
39
53
|
/**
|
|
40
|
-
*
|
|
54
|
+
* Represent target field after conditional rules evaluation
|
|
41
55
|
*/
|
|
42
56
|
export interface FieldControlState {
|
|
43
57
|
visible: boolean;
|
|
@@ -1 +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,
|
|
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,uBAAuB,GAC/B,MAAM,GACN,QAAQ,GACR,MAAM,GACN,cAAc,GACd,gBAAgB,GAChB,UAAU,CAAC;AAEf,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,MAAM,GAAG,KAAK,IACzD,uBAAuB,GAAG,OAAO,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;AAEtE,gDAAgD;AAChD,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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ition";
|
|
2
2
|
export type FormFlowValues = Record<string, any>;
|
|
3
|
-
export interface FormFlowDefinition<
|
|
3
|
+
export interface FormFlowDefinition<TCustom extends string = never> {
|
|
4
4
|
formId: string;
|
|
5
|
-
fields: FieldDefinition<
|
|
5
|
+
fields: FieldDefinition<TCustom>[];
|
|
6
|
+
ruleContextFields?: RuleContextFieldDefinition<TCustom>[];
|
|
6
7
|
metadata?: Record<string, any>;
|
|
7
8
|
}
|
|
8
|
-
export interface FormFlowSchema<
|
|
9
|
-
definition: FormFlowDefinition<
|
|
9
|
+
export interface FormFlowSchema<TCustom extends string = never> {
|
|
10
|
+
definition: FormFlowDefinition<TCustom>;
|
|
10
11
|
getValues: () => FormFlowValues;
|
|
11
12
|
getFieldValue: (fieldId: keyof FormFlowValues) => any;
|
|
12
13
|
setValues: (values: FormFlowValues, emit?: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-definition.d.ts","sourceRoot":"","sources":["../../src/models/form-definition.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"form-definition.d.ts","sourceRoot":"","sources":["../../src/models/form-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,eAAe,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEzG,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEjD,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,MAAM,GAAG,KAAK;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;IACnC,iBAAiB,CAAC,EAAE,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,MAAM,GAAG,KAAK;IAC1D,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACvC,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuleOperatorKey, RuleOperatorMeta } from "./operators";
|
|
1
|
+
import { RuleOperatorKey, RuleOperatorMeta, RuleOperatorsMap } from "./operators";
|
|
2
2
|
export declare const OperatorRegistry: {
|
|
3
3
|
/**
|
|
4
4
|
* Get the definition of a specific operator by key.
|
|
@@ -7,12 +7,12 @@ export declare const OperatorRegistry: {
|
|
|
7
7
|
/**
|
|
8
8
|
* Get all operator definitions (e.g., for building UI pickers).
|
|
9
9
|
*/
|
|
10
|
-
getAll: () =>
|
|
10
|
+
getAll: () => RuleOperatorsMap;
|
|
11
11
|
/**
|
|
12
12
|
* Register one or more operator overrides or additions.
|
|
13
13
|
* Existing operators with the same key will be replaced.
|
|
14
14
|
*/
|
|
15
|
-
register: (overrides:
|
|
15
|
+
register: (overrides: RuleOperatorsMap) => void;
|
|
16
16
|
/**
|
|
17
17
|
* Reset the registry to the original default operator map.
|
|
18
18
|
*/
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"operator-registry.d.ts","sourceRoot":"","sources":["../../src/models/operator-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK3G,eAAO,MAAM,gBAAgB;IACzB;;OAEG;eACQ,eAAe,KAAG,gBAAgB,GAAG,SAAS;IAEzD;;OAEG;kBACS,gBAAgB;IAE5B;;;OAGG;0BACmB,gBAAgB;IAItC;;OAEG;;CAIN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operator-registry.js","sourceRoot":"","sources":["../../src/models/operator-registry.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"operator-registry.js","sourceRoot":"","sources":["../../src/models/operator-registry.ts"],"names":[],"mappings":";;;AAAA,uBAAuB;AACvB,2CAA2G;AAE3G,4CAA4C;AAC5C,IAAI,QAAQ,GAAqB,EAAE,GAAG,mCAAuB,EAAE,CAAC;AAEnD,QAAA,gBAAgB,GAAG;IAC5B;;OAEG;IACH,GAAG,EAAE,CAAC,GAAoB,EAAgC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;IAE1E;;OAEG;IACH,MAAM,EAAE,GAAqB,EAAE,CAAC,QAAQ;IAExC;;;OAGG;IACH,QAAQ,EAAE,CAAC,SAA2B,EAAE,EAAE;QACtC,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"}
|
|
@@ -24,20 +24,21 @@ export type RuleOperatorValueType = "list" | "single" | "none" | "field" | undef
|
|
|
24
24
|
/**
|
|
25
25
|
* Metadata for describing how an operator behaves.
|
|
26
26
|
*/
|
|
27
|
-
export interface RuleOperatorMeta {
|
|
27
|
+
export interface RuleOperatorMeta<TCustom extends string = never> {
|
|
28
28
|
/** Label to display in the UI (can be customized by consumers). */
|
|
29
29
|
label: string;
|
|
30
30
|
/** Which field types this operator is allowed for. */
|
|
31
|
-
allowedTypes?: FieldControlType[] | "all";
|
|
31
|
+
allowedTypes?: FieldControlType<TCustom>[] | "all";
|
|
32
32
|
/** The type of value this operator requires. */
|
|
33
33
|
valueType?: RuleOperatorValueType;
|
|
34
34
|
/** If true, the operator will be hidden from the UI picker. */
|
|
35
35
|
hideFromPicker?: boolean;
|
|
36
36
|
}
|
|
37
|
+
export type RuleOperatorsMap<TCustom extends string = never> = Partial<Record<RuleOperatorKey, RuleOperatorMeta<TCustom>>>;
|
|
37
38
|
/**
|
|
38
39
|
* Default operator map shipped with `@form-flow/core`.
|
|
39
40
|
* Consumers may override or extend this map at runtime.
|
|
40
41
|
*/
|
|
41
|
-
export declare const FORM_FLOW_OPERATORS_MAP:
|
|
42
|
+
export declare const FORM_FLOW_OPERATORS_MAP: RuleOperatorsMap;
|
|
42
43
|
export {};
|
|
43
44
|
//# sourceMappingURL=operators.d.ts.map
|
|
@@ -1 +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;
|
|
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,CAAC,OAAO,SAAS,MAAM,GAAG,KAAK;IAC9D,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IAEd,sDAAsD;IACtD,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK,CAAC;IAEnD,gDAAgD;IAChD,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAElC,+DAA+D;IAC/D,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,MAAM,GAAG,KAAK,IACzD,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,gBAoBrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/models/operators.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/models/operators.ts"],"names":[],"mappings":";;;AAoDA;;;GAGG;AACU,QAAA,uBAAuB,GAAqB;IACvD,EAAE,EAAE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