@dynamicforms/vue-forms 0.16.1 → 0.17.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.
package/dist/index.d.ts CHANGED
@@ -7,12 +7,13 @@ import { Ref } from 'vue';
7
7
  /**
8
8
  * Thrown from a handler to end the run it is in. What the trigger answers with is the exception itself rather than
9
9
  * `null`, so a caller can tell a run a handler ended from one that reached no handler at all - and the setters
10
- * that ask a `*Changing*` handler read it as a refusal and write nothing.
10
+ * that ask a `*Changing*` handler read it as a refusal and write nothing. The answer carries it directly where the
11
+ * chain ran synchronously, and as what the answered promise resolves to where a handler in it was asynchronous.
11
12
  */
12
13
  export declare class AbortEventHandlingException extends Error {
13
14
  }
14
15
 
15
- export declare class Action<T extends ActionValue = ActionValue, X extends object = {}> extends Field<T, X> {
16
+ export declare class Action<T extends ActionValue = ActionValue, X extends object = Omit<Extras, keyof ActionValue>> extends Field<T, X> {
16
17
  get [Symbol.toStringTag](): string;
17
18
  protected init(params?: IFieldParams<T, X>): void;
18
19
  /**
@@ -22,9 +23,9 @@ export declare class Action<T extends ActionValue = ActionValue, X extends objec
22
23
  * against a baseline that never carried the key.
23
24
  */
24
25
  private valueWith;
25
- get icon(): string | undefined;
26
- set icon(newValue: string | undefined);
27
- get label(): string | undefined;
26
+ get icon(): T['icon'];
27
+ set icon(newValue: T['icon']);
28
+ get label(): T['label'];
28
29
  /**
29
30
  * The two setters hand the value setter a new object rather than writing into the one the action holds, so each
30
31
  * is an ordinary value change: the handlers fire, isChanged answers over it, and a disabled action refuses it.
@@ -32,7 +33,7 @@ export declare class Action<T extends ActionValue = ActionValue, X extends objec
32
33
  * identity and every copy is a new object, so without the comparison here a write of the value already held
33
34
  * would announce a change and invalidate the value cache of every container above.
34
35
  */
35
- set label(newValue: string | undefined);
36
+ set label(newValue: T['label']);
36
37
  /** the counter behind `busy`, allocated for this action the first time it is asked for */
37
38
  private get busyRuns();
38
39
  /** true from the moment execute() is called until the handler it ran has settled, however it settles */
@@ -45,7 +46,8 @@ export declare class Action<T extends ActionValue = ActionValue, X extends objec
45
46
  *
46
47
  * The answer is a promise whatever the handler returns, so a handler that throws rejects it rather than throwing
47
48
  * out of this call: a caller that does not await the answer and does not attach a catch handler leaves that
48
- * rejection unhandled.
49
+ * rejection unhandled. An `AbortEventHandlingException` is the one exception that does not reject: the answer
50
+ * resolves with it, in a synchronous chain as in an asynchronous one.
49
51
  */
50
52
  execute(params?: any): Promise<any>;
51
53
  }
@@ -103,10 +105,24 @@ export declare class ActionsMap {
103
105
  bindTo(owner: FieldBase): void;
104
106
  /** True where no eager action of `identifier` stands after `index`, which makes `index` the group's entry. */
105
107
  private static outermostEager;
108
+ /**
109
+ * True where `value` is a promise, which is what a walk through an asynchronous handler answers with. The test is
110
+ * the type rather than a `then` member: a handler may answer with a value object that carries one, and calling
111
+ * `then` on such an object replaces the answer with whatever that call returns.
112
+ */
113
+ private static isPromise;
114
+ /**
115
+ * Answers an abort with itself on the asynchronous path as well. Where a handler in the chain is asynchronous, the
116
+ * walk answers with a promise and the abort raised under it arrives as that promise's rejection; this turns it back
117
+ * into the value the caller receives, so a promise the trigger answers with resolves to the exception instead of
118
+ * rejecting with it. Anything else keeps rejecting.
119
+ */
120
+ private static answerAbort;
106
121
  /**
107
122
  * Enters a group at its outermost action. An abort ends the run and is answered with rather than raised: the
108
- * exception is what the caller receives, so a run a handler ended is told apart from one that reached no handler
109
- * and from one whose handler answered null.
123
+ * exception is what the caller receives - directly where the chain ran synchronously, as what the answered promise
124
+ * resolves to where it did not - so a run a handler ended is told apart from one that reached no handler and from
125
+ * one whose handler answered null.
110
126
  */
111
127
  private run;
112
128
  /**
@@ -117,9 +133,19 @@ export declare class ActionsMap {
117
133
  private walk;
118
134
  }
119
135
 
136
+ /**
137
+ * The value an `Action` holds. Both members are `unknown` because `Action` states the concept and a UI library
138
+ * states what it renders: a subclass declares its value type with `label` and `icon` in whatever shape it renders
139
+ * them - `string | MdString`, a per-breakpoint object - and the accessors below answer at that type, because they
140
+ * read it off `T` rather than fixing one of their own.
141
+ *
142
+ * The consequence for an `Action` built without a type argument is that reading either member answers `unknown`
143
+ * and the reader states what it expects. That is the shape the class is for; an application that renders actions
144
+ * uses the subclass its UI library ships.
145
+ */
120
146
  export declare interface ActionValue {
121
- label?: string;
122
- icon?: string;
147
+ label?: unknown;
148
+ icon?: unknown;
123
149
  }
124
150
 
125
151
  /**
@@ -363,7 +389,31 @@ export declare class ExecuteAction extends FieldActionBase {
363
389
  execute(field: FieldBase, supr: FieldActionExecute, params: any): any;
364
390
  }
365
391
 
366
- export declare class Field<T = any, X extends object = {}> extends FieldBase<T, X> {
392
+ /**
393
+ * The extended properties an element carries when nothing states otherwise. It is empty as declared and exists
394
+ * to be augmented: the layer that renders the elements declares what it renders them with, and every element in
395
+ * the application then carries those properties without a type argument at any construction site.
396
+ *
397
+ * ```ts
398
+ * declare module '@dynamicforms/vue-forms' {
399
+ * interface Extras {
400
+ * label?: string;
401
+ * hint?: string;
402
+ * cssClass?: string;
403
+ * }
404
+ * }
405
+ * ```
406
+ *
407
+ * The interface is one per application, so two packages that both declare a property of the same name must give
408
+ * it the same type; declaration merging refuses a second declaration that differs.
409
+ *
410
+ * An element that states an X of its own replaces this rather than adding to it, so an element that carries both
411
+ * is `Field<string, Extras & Local>`.
412
+ */
413
+ export declare interface Extras {
414
+ }
415
+
416
+ export declare class Field<T = any, X extends object = Extras> extends FieldBase<T, X> {
367
417
  get [Symbol.toStringTag](): string;
368
418
  protected get state(): FieldSlots<T>;
369
419
  protected get raw(): FieldSlots<T>;
@@ -431,7 +481,7 @@ export declare abstract class FieldActionBase {
431
481
 
432
482
  export declare type FieldActionExecute<T = any> = (field: FieldBase<T>, ...params: any[]) => any;
433
483
 
434
- export declare abstract class FieldBase<T = any, X extends object = {}> {
484
+ export declare abstract class FieldBase<T = any, X extends object = Extras> {
435
485
  #private;
436
486
  /**
437
487
  * Vue's getTargetType answers INVALID for an object that carries __v_skip, so reactive() hands an element back
@@ -785,6 +835,22 @@ export declare abstract class FieldBase<T = any, X extends object = {}> {
785
835
  set visibility(newValue: DisplayMode);
786
836
  get enabled(): boolean;
787
837
  set enabled(newValue: boolean);
838
+ /**
839
+ * Whether this element and every container above it are enabled. A rendering layer binds one read instead of
840
+ * walking the parent chain: a disabled `Group` states that its section cannot be edited, and the inputs
841
+ * rendered from the members inside it read that here.
842
+ *
843
+ * It is a read and nothing else. `enabled` on each element stays exactly what was written to it, a write to a
844
+ * member of a disabled container is accepted the way it always was, and what a container serializes is decided
845
+ * by the members' own `enabled`. Where a whole subtree is to stop serializing, the members are disabled.
846
+ *
847
+ * `enabled` is the only member with a reading of this kind, and it is not a scheme the other members follow.
848
+ * `visibility` has none because `SUPPRESS` states that an element is absent from the value as well, so folding
849
+ * it down the tree would decide serialization rather than report it; `value` has none because a container
850
+ * composes its own from its members rather than passing one down. A rendering layer that needs a third thing
851
+ * folded down the tree has `provide`/`inject`, which is where the render tree's own context belongs.
852
+ */
853
+ get effectiveEnabled(): boolean;
788
854
  /**
789
855
  * True for an element whose value is composed of its members'. The commit builds such a value only where
790
856
  * something receives it, compares it by content rather than by identity, and runs the element's own validators
@@ -916,6 +982,7 @@ declare namespace Form {
916
982
  NullableField,
917
983
  IFieldConstructorActionsList,
918
984
  IFieldConstructorParams,
985
+ Extras,
919
986
  IFieldParams,
920
987
  IBindParams,
921
988
  AbortEventHandlingException,
@@ -971,7 +1038,7 @@ export declare type GenericFieldsInterface = Record<string, FieldBase>;
971
1038
  /** The current configuration. The object is the module's own record, and reading it again reports later writes. */
972
1039
  export declare function getConfig(): FormsConfig;
973
1040
 
974
- export declare class Group<T extends GenericFieldsInterface = GenericFieldsInterface, X extends object = {}> extends FieldBase<GroupValue<T>, X> {
1041
+ export declare class Group<T extends GenericFieldsInterface = GenericFieldsInterface, X extends object = Extras> extends FieldBase<GroupValue<T>, X> {
975
1042
  get [Symbol.toStringTag](): string;
976
1043
  protected get state(): GroupSlots<GroupValue<T>>;
977
1044
  protected get raw(): GroupSlots<GroupValue<T>>;
@@ -1105,7 +1172,7 @@ export declare type GroupValueInput<T extends GenericFieldsInterface> = Partial<
1105
1172
  * `validators` and `actions` are carried from the declaration rather than supplied, and `touched` and `errors`
1106
1173
  * are what the binding establishes for itself as it validates.
1107
1174
  */
1108
- export declare type IBindParams<T = any, X extends object = {}> = Partial<Pick<IFieldConstructorParams<T>, 'originalValue' | 'enabled' | 'visibility'>> & Partial<NoInfer<X>>;
1175
+ export declare type IBindParams<T = any, X extends object = Extras> = Partial<Pick<IFieldConstructorParams<T>, 'originalValue' | 'enabled' | 'visibility'>> & Partial<NoInfer<X>>;
1109
1176
 
1110
1177
  export declare interface IFieldConstructorActionsList {
1111
1178
  actions?: FieldActionBase[];
@@ -1132,15 +1199,14 @@ export declare type IFieldConstructorParams<T = any> = {
1132
1199
  * What an element's constructor accepts: the parameters the element answers for itself, together with the
1133
1200
  * extended properties its X parameter declares.
1134
1201
  *
1135
- * X is left out of inference, so an element built without a type argument carries no extended properties and a
1136
- * parameter object naming one is rejected as an excess property. A caller that wants them states them:
1137
- * `new Field<string, { label: string }>({ value: 'a', label: 'Name' })`.
1202
+ * X is left out of inference, so an element carries what its X states - `Extras` where no type argument replaces
1203
+ * it - and a parameter object naming anything else is rejected as an excess property.
1138
1204
  *
1139
1205
  * The two halves are made partial separately. `Partial<A & X>` is a mapped type over an intersection, which is
1140
1206
  * what T is inferred through, and inference through it answers with one constituent of a union rather than the
1141
1207
  * union: `new Field({ value: someStringOrNumber })` would be a Field<string>.
1142
1208
  */
1143
- export declare type IFieldParams<T = any, X extends object = {}> = Partial<IFieldConstructorParams<T>> & Partial<NoInfer<X>>;
1209
+ export declare type IFieldParams<T = any, X extends object = Extras> = Partial<IFieldConstructorParams<T>> & Partial<NoInfer<X>>;
1144
1210
 
1145
1211
  declare class InAllowedValues<T = any> extends Validator {
1146
1212
  constructor(allowedValues: AllowedValues<T>, message?: RenderContentRef);
@@ -1159,7 +1225,7 @@ declare class LengthInRange extends Validator {
1159
1225
  constructor(minLength: number, maxLength: number, message?: RenderContentRef);
1160
1226
  }
1161
1227
 
1162
- export declare class List<T extends GenericFieldsInterface = GenericFieldsInterface, X extends object = {}> extends FieldBase<ListValue, X> {
1228
+ export declare class List<T extends GenericFieldsInterface = GenericFieldsInterface, X extends object = Extras> extends FieldBase<ListValue, X> {
1163
1229
  get [Symbol.toStringTag](): string;
1164
1230
  protected get state(): ListSlots<T>;
1165
1231
  protected get raw(): ListSlots<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dynamicforms/vue-forms",
3
3
  "private": false,
4
- "version": "0.16.1",
4
+ "version": "0.17.1",
5
5
  "type": "module",
6
6
  "description": "A lightweight Vue.js library for form state management with built-in validation, conditional logic, nested structures, and a rich event system. UI-agnostic and TypeScript-first.",
7
7
  "author": "Jure Erzno\u017enik",