@astroapps/forms-core 1.0.0 → 1.0.2

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.
@@ -8,6 +8,7 @@ export interface ExpressionEvalContext {
8
8
  dataNode: SchemaDataNode;
9
9
  schemaInterface: SchemaInterface;
10
10
  variables?: Value<Record<string, any> | undefined>;
11
+ runAsync(effect: () => void): void;
11
12
  }
12
13
  export type ExpressionEval<T extends EntityExpression> = (expr: T, context: ExpressionEvalContext) => void;
13
14
  export declare const jsonataEval: ExpressionEval<JsonataExpression>;
@@ -36,7 +36,7 @@ export interface FormContextData {
36
36
  optionSelected?: boolean;
37
37
  }
38
38
  export interface FormState {
39
- getControlState(parent: SchemaDataNode, formNode: FormNode, context: FormContextOptions): ControlState;
39
+ getControlState(parent: SchemaDataNode, formNode: FormNode, context: FormContextOptions, runAsync: (af: () => void) => void): ControlState;
40
40
  cleanup(): void;
41
41
  evalExpression(expr: EntityExpression, context: ExpressionEvalContext): void;
42
42
  }
package/lib/index.cjs CHANGED
@@ -1313,7 +1313,8 @@ var jsonataEval = function jsonataEval(expr, _ref4) {
1313
1313
  var scope = _ref4.scope,
1314
1314
  returnResult = _ref4.returnResult,
1315
1315
  dataNode = _ref4.dataNode,
1316
- variables = _ref4.variables;
1316
+ variables = _ref4.variables,
1317
+ runAsync = _ref4.runAsync;
1317
1318
  var path = getJsonPath(dataNode);
1318
1319
  var pathString = jsonPathString(path, function (x) {
1319
1320
  return "#$i[" + x + "]";
@@ -1335,7 +1336,10 @@ var jsonataEval = function jsonataEval(expr, _ref4) {
1335
1336
  };
1336
1337
  }
1337
1338
  });
1338
- controls.createAsyncEffect(runJsonata, scope);
1339
+ var asyncEffect = controls.createAsyncEffect(runJsonata, scope);
1340
+ runAsync(function () {
1341
+ return asyncEffect.start();
1342
+ });
1339
1343
  };
1340
1344
  var uuidEval = function uuidEval(_, ctx) {
1341
1345
  ctx.returnResult(uuid.v4());
@@ -1355,11 +1359,12 @@ var jsonataValidator = function jsonataValidator(validation, context) {
1355
1359
  dataNode: context.parentData,
1356
1360
  returnResult: function returnResult(v) {
1357
1361
  controls.trackControlChange(context.data.control, controls.ControlChange.Validate);
1358
- console.log("Setting jsonata error", v);
1362
+ // console.log("Setting jsonata error", v);
1359
1363
  context.data.control.setError("jsonata", v == null ? void 0 : v.toString());
1360
1364
  },
1361
1365
  schemaInterface: context.schemaInterface,
1362
- variables: context.formContext.fields.variables
1366
+ variables: context.formContext.fields.variables,
1367
+ runAsync: context.runAsync
1363
1368
  });
1364
1369
  };
1365
1370
  var lengthValidator = function lengthValidator(lv, context) {
@@ -1427,7 +1432,7 @@ function createValidators(def, context) {
1427
1432
  });
1428
1433
  }
1429
1434
  }
1430
- function setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode) {
1435
+ function setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode, runAsync) {
1431
1436
  var validationEnabled = createScopedComputed(controlImpl, function () {
1432
1437
  return !definition.hidden;
1433
1438
  });
@@ -1448,7 +1453,8 @@ function setupValidation(controlImpl, definition, dataNode, schemaInterface, par
1448
1453
  addCleanup: function addCleanup(cleanup) {
1449
1454
  validatorsScope.addCleanup(cleanup);
1450
1455
  },
1451
- formContext: controlImpl
1456
+ formContext: controlImpl,
1457
+ runAsync: runAsync
1452
1458
  });
1453
1459
  controls.createEffect(function () {
1454
1460
  if (!validationEnabled.value) return undefined;
@@ -1484,7 +1490,7 @@ function createFormState(schemaInterface, evaluators) {
1484
1490
  // console.log("Cleanup form state");
1485
1491
  controlStates.cleanup();
1486
1492
  },
1487
- getControlState: function getControlState(parent, formNode, context) {
1493
+ getControlState: function getControlState(parent, formNode, context, runAsync) {
1488
1494
  var _context$stateKey;
1489
1495
  var stateId = parent.id + "$" + formNode.id + ((_context$stateKey = context.stateKey) != null ? _context$stateKey : "");
1490
1496
  var controlImpl = controlStates.fields[stateId];
@@ -1499,7 +1505,8 @@ function createFormState(schemaInterface, evaluators) {
1499
1505
  scope: scope,
1500
1506
  dataNode: parent,
1501
1507
  variables: controlImpl.fields.variables,
1502
- schemaInterface: schemaInterface
1508
+ schemaInterface: schemaInterface,
1509
+ runAsync: runAsync
1503
1510
  });
1504
1511
  return true;
1505
1512
  }
@@ -1607,7 +1614,7 @@ function createFormState(schemaInterface, evaluators) {
1607
1614
  dn.control.disabled = disabled.value;
1608
1615
  }
1609
1616
  }, scope);
1610
- setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode);
1617
+ setupValidation(controlImpl, definition, dataNode, schemaInterface, parent, formNode, runAsync);
1611
1618
  controls.createSyncEffect(function () {
1612
1619
  var _dataNode$value;
1613
1620
  var dn = (_dataNode$value = dataNode.value) == null ? void 0 : _dataNode$value.control;