@astroapps/forms-core 1.1.1 → 1.2.1

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.
@@ -61,6 +61,7 @@ export declare function defaultCompoundField(field: string, displayName: string,
61
61
  type: FieldType.Compound;
62
62
  };
63
63
  export declare function mergeField(field: SchemaField, mergeInto: SchemaField[]): SchemaField[];
64
+ export declare function mergeOption(fields: SchemaField[], name: string, value: any, fieldName: string): SchemaField[];
64
65
  export declare function mergeFields(fields: SchemaField[], name: string, value: any, newFields: SchemaField[]): SchemaField[];
65
66
  export declare function addFieldOption(typeField: SchemaField, name: string, value: any): SchemaField;
66
67
  export declare function resolveSchemas<A extends SchemaMap>(schemaMap: A): A;
@@ -21,4 +21,4 @@ export declare const lengthValidator: ValidatorEval<LengthValidator>;
21
21
  export declare const dateValidator: ValidatorEval<DateValidator>;
22
22
  export declare const defaultValidators: Record<string, ValidatorEval<any>>;
23
23
  export declare function createValidators(def: ControlDefinition, context: ValidationEvalContext): void;
24
- export declare function setupValidation(controlImpl: Control<FormContextOptions>, definition: ControlDefinition, dataNode: Control<SchemaDataNode | undefined>, schemaInterface: SchemaInterface, parent: SchemaDataNode, formNode: FormNode, runAsync: (af: () => void) => void): void;
24
+ export declare function setupValidation(controlImpl: Control<FormContextOptions>, definition: ControlDefinition, dataNode: Control<SchemaDataNode | undefined>, schemaInterface: SchemaInterface, parent: SchemaDataNode, formNode: FormNode, hidden: Control<boolean>, runAsync: (af: () => void) => void): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astroapps/forms-core",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
package/src/formState.ts CHANGED
@@ -195,7 +195,7 @@ export function createFormState(
195
195
  Control<any>
196
196
  >;
197
197
 
198
- const df = displayOverrides.fields as Record<
198
+ const { text, html } = displayOverrides.fields as Record<
199
199
  KeysOfUnion<TextDisplay | HtmlDisplay>,
200
200
  Control<any>
201
201
  >;
@@ -376,9 +376,17 @@ export function createFormState(
376
376
 
377
377
  createSyncEffect(() => {
378
378
  if (isDisplayControl(def)) {
379
- if (isTextDisplay(def.displayData)) df.text.value = display.value;
380
- else if (isHtmlDisplay(def.displayData))
381
- df.html.value = display.value;
379
+ if (display.value !== undefined) {
380
+ text.value = isTextDisplay(def.displayData)
381
+ ? display.value
382
+ : NoOverride;
383
+ html.value = isHtmlDisplay(def.displayData)
384
+ ? display.value
385
+ : NoOverride;
386
+ } else {
387
+ text.value = NoOverride;
388
+ html.value = NoOverride;
389
+ }
382
390
  }
383
391
  }, displayOverrides);
384
392
 
@@ -389,6 +397,7 @@ export function createFormState(
389
397
  schemaInterface,
390
398
  parent,
391
399
  formNode,
400
+ hidden,
392
401
  runAsync,
393
402
  );
394
403
 
@@ -492,7 +501,8 @@ export function createOverrideProxy<
492
501
  return new Proxy(proxyFor, {
493
502
  get(target: A, p: string | symbol, receiver: any): any {
494
503
  if (Object.hasOwn(overrides, p)) {
495
- return overrides[p as keyof B]!.value;
504
+ const nv = overrides[p as keyof B]!.value;
505
+ if (nv !== NoOverride) return nv;
496
506
  }
497
507
  return Reflect.get(target, p, receiver);
498
508
  },
@@ -513,4 +523,7 @@ export function createOverrideProxy<
513
523
  });
514
524
  }
515
525
 
526
+ class NoValue {}
527
+ const NoOverride = new NoValue();
528
+
516
529
  type KeysOfUnion<T> = T extends T ? keyof T : never;
@@ -266,6 +266,17 @@ export function mergeField(
266
266
  }
267
267
  }
268
268
 
269
+ export function mergeOption(
270
+ fields: SchemaField[],
271
+ name: string,
272
+ value: any,
273
+ fieldName: string,
274
+ ): SchemaField[] {
275
+ return fields.map((x) =>
276
+ x.field === fieldName ? addFieldOption(x, name, value) : x,
277
+ );
278
+ }
279
+
269
280
  export function mergeFields(
270
281
  fields: SchemaField[],
271
282
  name: string,
package/src/validators.ts CHANGED
@@ -6,7 +6,11 @@ import {
6
6
  SchemaValidator,
7
7
  ValidatorType,
8
8
  } from "./schemaValidator";
9
- import { ControlDefinition, isDataControl } from "./controlDefinition";
9
+ import {
10
+ ControlDefinition,
11
+ DataControlDefinition,
12
+ isDataControl,
13
+ } from "./controlDefinition";
10
14
  import { SchemaDataNode } from "./schemaDataNode";
11
15
  import {
12
16
  Control,
@@ -171,11 +175,12 @@ export function setupValidation(
171
175
  schemaInterface: SchemaInterface,
172
176
  parent: SchemaDataNode,
173
177
  formNode: FormNode,
178
+ hidden: Control<boolean>,
174
179
  runAsync: (af: () => void) => void,
175
180
  ) {
176
181
  const validationEnabled = createScopedComputed(
177
182
  controlImpl,
178
- () => !definition.hidden,
183
+ () => !hidden.value,
179
184
  );
180
185
  const validatorsScope = createCleanupScope();
181
186
  createEffect(