@astroapps/forms-core 1.0.1 → 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/evalExpression.d.ts +1 -0
- package/lib/formNode.d.ts +7 -0
- package/lib/formState.d.ts +4 -1
- package/lib/index.cjs +62 -12
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +60 -14
- package/lib/index.js.map +1 -1
- package/lib/validators.d.ts +2 -1
- package/package.json +1 -1
- package/src/evalExpression.ts +4 -2
- package/src/formNode.ts +45 -0
- package/src/formState.ts +34 -3
- package/src/validators.ts +5 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ensureMetaValue, newControl, updateComputedValue, addDependent, createSyncEffect, createAsyncEffect, collectChanges, trackedValue, createCleanupScope, createEffect, trackControlChange, ControlChange, createScopedEffect, getControlPath, unsafeRestoreControl
|
|
1
|
+
import { ensureMetaValue, newControl, updateComputedValue, addDependent, createSyncEffect, createAsyncEffect, collectChanges, trackedValue, createCleanupScope, createEffect, trackControlChange, ControlChange, getCurrentFields, getMetaValue, createScopedEffect, getControlPath, unsafeRestoreControl } from '@astroapps/controls';
|
|
2
2
|
import jsonata from 'jsonata';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
|
|
@@ -1074,6 +1074,35 @@ function visitFormDataInContext(parentContext, node, cb) {
|
|
|
1074
1074
|
const dataNode = lookupDataNode(node.definition, parentContext);
|
|
1075
1075
|
return visitFormData(node, dataNode != null ? dataNode : parentContext, cb, !dataNode);
|
|
1076
1076
|
}
|
|
1077
|
+
function visitFormDataNode(node, visitFn) {
|
|
1078
|
+
const dataNode = lookupDataNode(node.formNode.definition, node.parentData);
|
|
1079
|
+
const v = visitFn(node, dataNode);
|
|
1080
|
+
if (v !== undefined) return v;
|
|
1081
|
+
const parentData = dataNode != null ? dataNode : node.parentData;
|
|
1082
|
+
if (parentData.schema.field.collection && parentData.elementIndex == null) {
|
|
1083
|
+
const elemCount = parentData.control.elements.length;
|
|
1084
|
+
for (let i = 0; i < elemCount; i++) {
|
|
1085
|
+
const _v = visitChildren(parentData.getChildElement(i));
|
|
1086
|
+
if (_v !== undefined) return _v;
|
|
1087
|
+
}
|
|
1088
|
+
return undefined;
|
|
1089
|
+
} else {
|
|
1090
|
+
return visitChildren(parentData);
|
|
1091
|
+
}
|
|
1092
|
+
function visitChildren(parentData) {
|
|
1093
|
+
const children = node.formNode.getChildNodes();
|
|
1094
|
+
for (let i = 0; i < children.length; i++) {
|
|
1095
|
+
const child = children[i];
|
|
1096
|
+
const res = visitFormDataNode({
|
|
1097
|
+
formNode: child,
|
|
1098
|
+
parent: node,
|
|
1099
|
+
parentData,
|
|
1100
|
+
childIndex: i
|
|
1101
|
+
}, visitFn);
|
|
1102
|
+
if (res !== undefined) return res;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1077
1106
|
|
|
1078
1107
|
/**
|
|
1079
1108
|
* Converts a JSON path array to a string.
|
|
@@ -1147,7 +1176,8 @@ const jsonataEval = (expr, {
|
|
|
1147
1176
|
scope,
|
|
1148
1177
|
returnResult,
|
|
1149
1178
|
dataNode,
|
|
1150
|
-
variables
|
|
1179
|
+
variables,
|
|
1180
|
+
runAsync
|
|
1151
1181
|
}) => {
|
|
1152
1182
|
const path = getJsonPath(dataNode);
|
|
1153
1183
|
const pathString = jsonPathString(path, x => `#$i[${x}]`);
|
|
@@ -1174,7 +1204,8 @@ const jsonataEval = (expr, {
|
|
|
1174
1204
|
// console.log(parsedJsonata.fields.fullExpr.value, evalResult, bindings);
|
|
1175
1205
|
collectChanges(effect.collectUsage, () => returnResult(evalResult));
|
|
1176
1206
|
}
|
|
1177
|
-
createAsyncEffect(runJsonata, scope);
|
|
1207
|
+
const asyncEffect = createAsyncEffect(runJsonata, scope);
|
|
1208
|
+
runAsync(() => asyncEffect.start());
|
|
1178
1209
|
};
|
|
1179
1210
|
const uuidEval = (_, ctx) => {
|
|
1180
1211
|
ctx.returnResult(v4());
|
|
@@ -1197,11 +1228,12 @@ const jsonataValidator = (validation, context) => {
|
|
|
1197
1228
|
dataNode: context.parentData,
|
|
1198
1229
|
returnResult: v => {
|
|
1199
1230
|
trackControlChange(context.data.control, ControlChange.Validate);
|
|
1200
|
-
console.log("Setting jsonata error", v);
|
|
1231
|
+
// console.log("Setting jsonata error", v);
|
|
1201
1232
|
context.data.control.setError("jsonata", v == null ? void 0 : v.toString());
|
|
1202
1233
|
},
|
|
1203
1234
|
schemaInterface: context.schemaInterface,
|
|
1204
|
-
variables: context.formContext.fields.variables
|
|
1235
|
+
variables: context.formContext.fields.variables,
|
|
1236
|
+
runAsync: context.runAsync
|
|
1205
1237
|
});
|
|
1206
1238
|
};
|
|
1207
1239
|
const lengthValidator = (lv, context) => {
|
|
@@ -1277,7 +1309,7 @@ function createValidators(def, context) {
|
|
|
1277
1309
|
});
|
|
1278
1310
|
}
|
|
1279
1311
|
}
|
|
1280
|
-
function setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode) {
|
|
1312
|
+
function setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode, runAsync) {
|
|
1281
1313
|
const validationEnabled = createScopedComputed(controlImpl, () => !definition.hidden);
|
|
1282
1314
|
const validatorsScope = createCleanupScope();
|
|
1283
1315
|
createEffect(() => {
|
|
@@ -1296,7 +1328,8 @@ function setupValidation(controlImpl, definition, dataNode, schemaInterface, par
|
|
|
1296
1328
|
addCleanup(cleanup) {
|
|
1297
1329
|
validatorsScope.addCleanup(cleanup);
|
|
1298
1330
|
},
|
|
1299
|
-
formContext: controlImpl
|
|
1331
|
+
formContext: controlImpl,
|
|
1332
|
+
runAsync
|
|
1300
1333
|
});
|
|
1301
1334
|
createEffect(() => {
|
|
1302
1335
|
if (!validationEnabled.value) return undefined;
|
|
@@ -1315,6 +1348,9 @@ function setupValidation(controlImpl, definition, dataNode, schemaInterface, par
|
|
|
1315
1348
|
}, c => {}, controlImpl);
|
|
1316
1349
|
}
|
|
1317
1350
|
|
|
1351
|
+
function getControlStateId(parent, formNode, stateKey) {
|
|
1352
|
+
return parent.id + "$" + formNode.id + (stateKey != null ? stateKey : "");
|
|
1353
|
+
}
|
|
1318
1354
|
function createFormState(schemaInterface, evaluators = defaultEvaluators) {
|
|
1319
1355
|
// console.log("createFormState");
|
|
1320
1356
|
const controlStates = newControl({});
|
|
@@ -1328,9 +1364,17 @@ function createFormState(schemaInterface, evaluators = defaultEvaluators) {
|
|
|
1328
1364
|
// console.log("Cleanup form state");
|
|
1329
1365
|
controlStates.cleanup();
|
|
1330
1366
|
},
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1367
|
+
getExistingControlState(parent, formNode, stateKey) {
|
|
1368
|
+
const stateId = getControlStateId(parent, formNode, stateKey);
|
|
1369
|
+
const control = getCurrentFields(controlStates)[stateId];
|
|
1370
|
+
if (control) {
|
|
1371
|
+
var _getMetaValue;
|
|
1372
|
+
return (_getMetaValue = getMetaValue(control, "impl")) == null ? void 0 : _getMetaValue.value;
|
|
1373
|
+
}
|
|
1374
|
+
return undefined;
|
|
1375
|
+
},
|
|
1376
|
+
getControlState(parent, formNode, context, runAsync) {
|
|
1377
|
+
const stateId = getControlStateId(parent, formNode, context.stateKey);
|
|
1334
1378
|
const controlImpl = controlStates.fields[stateId];
|
|
1335
1379
|
controlImpl.value = context;
|
|
1336
1380
|
function evalExpr(scope, init, nk, e, coerce) {
|
|
@@ -1343,7 +1387,8 @@ function createFormState(schemaInterface, evaluators = defaultEvaluators) {
|
|
|
1343
1387
|
scope,
|
|
1344
1388
|
dataNode: parent,
|
|
1345
1389
|
variables: controlImpl.fields.variables,
|
|
1346
|
-
schemaInterface
|
|
1390
|
+
schemaInterface,
|
|
1391
|
+
runAsync
|
|
1347
1392
|
});
|
|
1348
1393
|
return true;
|
|
1349
1394
|
}
|
|
@@ -1395,7 +1440,8 @@ function createFormState(schemaInterface, evaluators = defaultEvaluators) {
|
|
|
1395
1440
|
clearHidden: false,
|
|
1396
1441
|
hidden: false,
|
|
1397
1442
|
variables: (_controlImpl$fields$v = controlImpl.fields.variables.current.value) != null ? _controlImpl$fields$v : {},
|
|
1398
|
-
stateId
|
|
1443
|
+
stateId,
|
|
1444
|
+
meta: newControl({})
|
|
1399
1445
|
});
|
|
1400
1446
|
const {
|
|
1401
1447
|
dataNode,
|
|
@@ -1424,7 +1470,7 @@ function createFormState(schemaInterface, evaluators = defaultEvaluators) {
|
|
|
1424
1470
|
dn.control.disabled = disabled.value;
|
|
1425
1471
|
}
|
|
1426
1472
|
}, scope);
|
|
1427
|
-
setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode);
|
|
1473
|
+
setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode, runAsync);
|
|
1428
1474
|
createSyncEffect(() => {
|
|
1429
1475
|
var _dataNode$value;
|
|
1430
1476
|
const dn = (_dataNode$value = dataNode.value) == null ? void 0 : _dataNode$value.control;
|
|
@@ -1517,5 +1563,5 @@ function createOverrideProxy(proxyFor, handlers) {
|
|
|
1517
1563
|
});
|
|
1518
1564
|
}
|
|
1519
1565
|
|
|
1520
|
-
export { ActionStyle, AdornmentPlacement, ControlAdornmentType, ControlDefinitionType, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType, FormNode, FormTree, GroupRenderType, IconLibrary, IconPlacement, SchemaDataNode, SchemaDataTree, SchemaDataTreeImpl, SchemaNode, SchemaTags, SchemaTree, SyncTextType, ValidationMessageType, ValidatorType, addFieldOption, boolField, buildSchema, compoundField, createControlMap, createFormLookup, createFormState, createFormTree, createOverrideProxy, createSchemaDataNode, createSchemaLookup, createSchemaNode, createSchemaTree, createScoped, createScopedComputed, dateField, dateTimeField, defaultCompoundField, defaultScalarField, defaultSchemaInterface, doubleField, fieldPathForDefinition, findField, fontAwesomeIcon, getDisplayOnlyOptions, getGroupRendererOptions, getJsonPath, getMetaFields, getRootDataNode, getSchemaFieldList, getSchemaNodePath, getSchemaNodePathString, getSchemaPath, getTagParam, hideDisplayOnly, intField, isActionControl, isArrayRenderer, isAutoCompleteClasses, isAutocompleteRenderer, isCheckEntryClasses, isCompoundField, isCompoundNode, isControlDisabled, isControlDisplayOnly, isControlReadonly, isDataControl, isDataGroupRenderer, isDateTimeRenderer, isDialogRenderer, isDisplayControl, isDisplayOnlyRenderer, isFlexRenderer, isGridRenderer, isGroupControl, isHtmlDisplay, isInlineRenderer, isScalarField, isSelectChildRenderer, isTabsRenderer, isTextDisplay, isTextfieldRenderer, isWizardRenderer, jsonPathString, legacyFormNode, lookupDataNode, makeCompoundField, makeParamTag, makeScalarField, makeSchemaDataNode, mergeField, mergeFields, missingField, relativePath, relativeSegmentPath, resolveSchemaNode, resolveSchemas, schemaDataForFieldPath, schemaDataForFieldRef, schemaForFieldPath, schemaForFieldRef, stringField, stringOptionsField, timeField, traverseData, traverseParents, traverseSchemaPath, validDataNode, visitControlData, visitControlDataArray, visitControlDefinition, visitFormData, visitFormDataInContext, withScalarOptions };
|
|
1566
|
+
export { ActionStyle, AdornmentPlacement, ControlAdornmentType, ControlDefinitionType, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType, FormNode, FormTree, GroupRenderType, IconLibrary, IconPlacement, SchemaDataNode, SchemaDataTree, SchemaDataTreeImpl, SchemaNode, SchemaTags, SchemaTree, SyncTextType, ValidationMessageType, ValidatorType, addFieldOption, boolField, buildSchema, compoundField, createControlMap, createFormLookup, createFormState, createFormTree, createOverrideProxy, createSchemaDataNode, createSchemaLookup, createSchemaNode, createSchemaTree, createScoped, createScopedComputed, dateField, dateTimeField, defaultCompoundField, defaultScalarField, defaultSchemaInterface, doubleField, fieldPathForDefinition, findField, fontAwesomeIcon, getControlStateId, getDisplayOnlyOptions, getGroupRendererOptions, getJsonPath, getMetaFields, getRootDataNode, getSchemaFieldList, getSchemaNodePath, getSchemaNodePathString, getSchemaPath, getTagParam, hideDisplayOnly, intField, isActionControl, isArrayRenderer, isAutoCompleteClasses, isAutocompleteRenderer, isCheckEntryClasses, isCompoundField, isCompoundNode, isControlDisabled, isControlDisplayOnly, isControlReadonly, isDataControl, isDataGroupRenderer, isDateTimeRenderer, isDialogRenderer, isDisplayControl, isDisplayOnlyRenderer, isFlexRenderer, isGridRenderer, isGroupControl, isHtmlDisplay, isInlineRenderer, isScalarField, isSelectChildRenderer, isTabsRenderer, isTextDisplay, isTextfieldRenderer, isWizardRenderer, jsonPathString, legacyFormNode, lookupDataNode, makeCompoundField, makeParamTag, makeScalarField, makeSchemaDataNode, mergeField, mergeFields, missingField, relativePath, relativeSegmentPath, resolveSchemaNode, resolveSchemas, schemaDataForFieldPath, schemaDataForFieldRef, schemaForFieldPath, schemaForFieldRef, stringField, stringOptionsField, timeField, traverseData, traverseParents, traverseSchemaPath, validDataNode, visitControlData, visitControlDataArray, visitControlDefinition, visitFormData, visitFormDataInContext, visitFormDataNode, withScalarOptions };
|
|
1521
1567
|
//# sourceMappingURL=index.js.map
|