@astroapps/forms-core 1.0.2 → 1.1.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/lib/formNode.d.ts +7 -0
- package/lib/formState.d.ts +3 -0
- package/lib/index.cjs +46 -3
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +46 -5
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/formNode.ts +45 -0
- package/src/formState.ts +30 -3
package/lib/formNode.d.ts
CHANGED
|
@@ -43,3 +43,10 @@ export declare function visitControlData<A>(definition: ControlDefinition, ctx:
|
|
|
43
43
|
export type ControlDataVisitor<A> = (dataNode: SchemaDataNode, definition: DataControlDefinition) => A | undefined;
|
|
44
44
|
export declare function visitFormData<A>(node: FormNode, dataNode: SchemaDataNode, cb: ControlDataVisitor<A>, notSelf?: boolean): A | undefined;
|
|
45
45
|
export declare function visitFormDataInContext<A>(parentContext: SchemaDataNode, node: FormNode, cb: ControlDataVisitor<A>): A | undefined;
|
|
46
|
+
export interface FormDataNode {
|
|
47
|
+
parent?: FormDataNode;
|
|
48
|
+
formNode: FormNode;
|
|
49
|
+
parentData: SchemaDataNode;
|
|
50
|
+
childIndex?: number;
|
|
51
|
+
}
|
|
52
|
+
export declare function visitFormDataNode<A>(node: FormDataNode, visitFn: (node: FormDataNode, data?: SchemaDataNode) => A | undefined): A | undefined;
|
package/lib/formState.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface ControlState {
|
|
|
19
19
|
disabled: boolean;
|
|
20
20
|
clearHidden: boolean;
|
|
21
21
|
variables: Record<string, any>;
|
|
22
|
+
meta: Control<Record<string, any>>;
|
|
22
23
|
}
|
|
23
24
|
export interface FormContextOptions {
|
|
24
25
|
readonly?: boolean | null;
|
|
@@ -39,6 +40,8 @@ export interface FormState {
|
|
|
39
40
|
getControlState(parent: SchemaDataNode, formNode: FormNode, context: FormContextOptions, runAsync: (af: () => void) => void): ControlState;
|
|
40
41
|
cleanup(): void;
|
|
41
42
|
evalExpression(expr: EntityExpression, context: ExpressionEvalContext): void;
|
|
43
|
+
getExistingControlState(parent: SchemaDataNode, formNode: FormNode, stateKey?: string): ControlState | undefined;
|
|
42
44
|
}
|
|
45
|
+
export declare function getControlStateId(parent: SchemaDataNode, formNode: FormNode, stateKey?: string): string;
|
|
43
46
|
export declare function createFormState(schemaInterface: SchemaInterface, evaluators?: Record<string, ExpressionEval<any>>): FormState;
|
|
44
47
|
export declare function createOverrideProxy<A extends object, B extends Record<string, any>>(proxyFor: A, handlers: Control<B>): A;
|
package/lib/index.cjs
CHANGED
|
@@ -1227,6 +1227,35 @@ function visitFormDataInContext(parentContext, node, cb) {
|
|
|
1227
1227
|
var dataNode = lookupDataNode(node.definition, parentContext);
|
|
1228
1228
|
return visitFormData(node, dataNode != null ? dataNode : parentContext, cb, !dataNode);
|
|
1229
1229
|
}
|
|
1230
|
+
function visitFormDataNode(node, visitFn) {
|
|
1231
|
+
var dataNode = lookupDataNode(node.formNode.definition, node.parentData);
|
|
1232
|
+
var v = visitFn(node, dataNode);
|
|
1233
|
+
if (v !== undefined) return v;
|
|
1234
|
+
var parentData = dataNode != null ? dataNode : node.parentData;
|
|
1235
|
+
if (parentData.schema.field.collection && parentData.elementIndex == null) {
|
|
1236
|
+
var elemCount = parentData.control.elements.length;
|
|
1237
|
+
for (var i = 0; i < elemCount; i++) {
|
|
1238
|
+
var _v = visitChildren(parentData.getChildElement(i));
|
|
1239
|
+
if (_v !== undefined) return _v;
|
|
1240
|
+
}
|
|
1241
|
+
return undefined;
|
|
1242
|
+
} else {
|
|
1243
|
+
return visitChildren(parentData);
|
|
1244
|
+
}
|
|
1245
|
+
function visitChildren(parentData) {
|
|
1246
|
+
var children = node.formNode.getChildNodes();
|
|
1247
|
+
for (var _i2 = 0; _i2 < children.length; _i2++) {
|
|
1248
|
+
var child = children[_i2];
|
|
1249
|
+
var res = visitFormDataNode({
|
|
1250
|
+
formNode: child,
|
|
1251
|
+
parent: node,
|
|
1252
|
+
parentData: parentData,
|
|
1253
|
+
childIndex: _i2
|
|
1254
|
+
}, visitFn);
|
|
1255
|
+
if (res !== undefined) return res;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1230
1259
|
|
|
1231
1260
|
/**
|
|
1232
1261
|
* Converts a JSON path array to a string.
|
|
@@ -1474,6 +1503,9 @@ function setupValidation(controlImpl, definition, dataNode, schemaInterface, par
|
|
|
1474
1503
|
}, function (c) {}, controlImpl);
|
|
1475
1504
|
}
|
|
1476
1505
|
|
|
1506
|
+
function getControlStateId(parent, formNode, stateKey) {
|
|
1507
|
+
return parent.id + "$" + formNode.id + (stateKey != null ? stateKey : "");
|
|
1508
|
+
}
|
|
1477
1509
|
function createFormState(schemaInterface, evaluators) {
|
|
1478
1510
|
if (evaluators === void 0) {
|
|
1479
1511
|
evaluators = defaultEvaluators;
|
|
@@ -1490,9 +1522,17 @@ function createFormState(schemaInterface, evaluators) {
|
|
|
1490
1522
|
// console.log("Cleanup form state");
|
|
1491
1523
|
controlStates.cleanup();
|
|
1492
1524
|
},
|
|
1525
|
+
getExistingControlState: function getExistingControlState(parent, formNode, stateKey) {
|
|
1526
|
+
var stateId = getControlStateId(parent, formNode, stateKey);
|
|
1527
|
+
var control = controls.getCurrentFields(controlStates)[stateId];
|
|
1528
|
+
if (control) {
|
|
1529
|
+
var _getMetaValue;
|
|
1530
|
+
return (_getMetaValue = controls.getMetaValue(control, "impl")) == null ? void 0 : _getMetaValue.value;
|
|
1531
|
+
}
|
|
1532
|
+
return undefined;
|
|
1533
|
+
},
|
|
1493
1534
|
getControlState: function getControlState(parent, formNode, context, runAsync) {
|
|
1494
|
-
var
|
|
1495
|
-
var stateId = parent.id + "$" + formNode.id + ((_context$stateKey = context.stateKey) != null ? _context$stateKey : "");
|
|
1535
|
+
var stateId = getControlStateId(parent, formNode, context.stateKey);
|
|
1496
1536
|
var controlImpl = controlStates.fields[stateId];
|
|
1497
1537
|
controlImpl.value = context;
|
|
1498
1538
|
function evalExpr(scope, init, nk, e, coerce) {
|
|
@@ -1570,7 +1610,8 @@ function createFormState(schemaInterface, evaluators) {
|
|
|
1570
1610
|
clearHidden: false,
|
|
1571
1611
|
hidden: false,
|
|
1572
1612
|
variables: (_controlImpl$fields$v = controlImpl.fields.variables.current.value) != null ? _controlImpl$fields$v : {},
|
|
1573
|
-
stateId: stateId
|
|
1613
|
+
stateId: stateId,
|
|
1614
|
+
meta: controls.newControl({})
|
|
1574
1615
|
});
|
|
1575
1616
|
var _control$fields = control.fields,
|
|
1576
1617
|
dataNode = _control$fields.dataNode,
|
|
@@ -1747,6 +1788,7 @@ exports.doubleField = doubleField;
|
|
|
1747
1788
|
exports.fieldPathForDefinition = fieldPathForDefinition;
|
|
1748
1789
|
exports.findField = findField;
|
|
1749
1790
|
exports.fontAwesomeIcon = fontAwesomeIcon;
|
|
1791
|
+
exports.getControlStateId = getControlStateId;
|
|
1750
1792
|
exports.getDisplayOnlyOptions = getDisplayOnlyOptions;
|
|
1751
1793
|
exports.getGroupRendererOptions = getGroupRendererOptions;
|
|
1752
1794
|
exports.getJsonPath = getJsonPath;
|
|
@@ -1816,5 +1858,6 @@ exports.visitControlDataArray = visitControlDataArray;
|
|
|
1816
1858
|
exports.visitControlDefinition = visitControlDefinition;
|
|
1817
1859
|
exports.visitFormData = visitFormData;
|
|
1818
1860
|
exports.visitFormDataInContext = visitFormDataInContext;
|
|
1861
|
+
exports.visitFormDataNode = visitFormDataNode;
|
|
1819
1862
|
exports.withScalarOptions = withScalarOptions;
|
|
1820
1863
|
//# sourceMappingURL=index.cjs.map
|