@vaadin/hilla-lit-form 24.7.0-alpha9 → 24.7.0-beta3

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/Binder.d.ts CHANGED
@@ -1,28 +1,7 @@
1
1
  import { type BinderConfiguration, BinderRoot } from './BinderRoot.js';
2
2
  import type { AbstractModel, DetachedModelConstructor, Value } from './Models.js';
3
- /**
4
- * A Binder controls all aspects of a single form.
5
- * Typically, it is used to get and set the form value,
6
- * access the form model, validate, reset, and submit the form.
7
- *
8
- * @typeParam T - Type of the value that binds to a form
9
- * @typeParam M - Type of the model that describes the structure of the value
10
- */
11
3
  export declare class Binder<M extends AbstractModel> extends BinderRoot<M> {
12
4
  readonly ['constructor']: Omit<typeof Binder<M>, 'constructor'>;
13
5
  context: Element;
14
- /**
15
- *
16
- * @param context - The form view component instance to update.
17
- * @param Model - The constructor (the class reference) of the form model. The Binder instantiates the top-level model
18
- * @param config - The options object, which can be used to config the onChange and onSubmit callbacks.
19
- *
20
- * ```
21
- * binder = new Binder(orderView, OrderModel);
22
- * or
23
- * binder = new Binder(orderView, OrderModel, {onSubmit: async (order) => {endpoint.save(order)}});
24
- * ```
25
- */
26
6
  constructor(context: Element, Model: DetachedModelConstructor<M>, config?: BinderConfiguration<Value<M>>);
27
7
  }
28
- //# sourceMappingURL=Binder.d.ts.map
package/Binder.js CHANGED
@@ -1,29 +1,22 @@
1
- import { BinderRoot } from "./BinderRoot.js";
2
- class Binder extends BinderRoot {
3
- context;
4
- /**
5
- *
6
- * @param context - The form view component instance to update.
7
- * @param Model - The constructor (the class reference) of the form model. The Binder instantiates the top-level model
8
- * @param config - The options object, which can be used to config the onChange and onSubmit callbacks.
9
- *
10
- * ```
11
- * binder = new Binder(orderView, OrderModel);
12
- * or
13
- * binder = new Binder(orderView, OrderModel, {onSubmit: async (order) => {endpoint.save(order)}});
14
- * ```
15
- */
16
- constructor(context, Model, config) {
17
- const changeCallback = config?.onChange ?? (typeof context.requestUpdate === "function" ? () => context.requestUpdate() : void 0);
18
- super(Model, {
19
- ...config ?? {},
20
- onChange: changeCallback,
21
- context
22
- });
23
- this.context = context;
24
- }
1
+ import { BinderRoot } from './BinderRoot.js';
2
+ export class Binder extends BinderRoot {
3
+ constructor(context, Model, config) {
4
+ const changeCallback = config?.onChange ??
5
+ (typeof context.requestUpdate === 'function'
6
+ ? () => context.requestUpdate()
7
+ : undefined);
8
+ super(Model, {
9
+ ...(config ?? {}),
10
+ onChange: changeCallback,
11
+ context,
12
+ });
13
+ Object.defineProperty(this, "context", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ this.context = context;
20
+ }
25
21
  }
26
- export {
27
- Binder
28
- };
29
- //# sourceMappingURL=Binder.js.map
22
+ //# sourceMappingURL=Binder.js.map
package/Binder.js.map CHANGED
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/Binder.ts"],
4
- "sourcesContent": ["import type { LitElement } from 'lit';\nimport { type BinderConfiguration, BinderRoot } from './BinderRoot.js';\nimport type { AbstractModel, DetachedModelConstructor, Value } from './Models.js';\n\n/**\n * A Binder controls all aspects of a single form.\n * Typically, it is used to get and set the form value,\n * access the form model, validate, reset, and submit the form.\n *\n * @typeParam T - Type of the value that binds to a form\n * @typeParam M - Type of the model that describes the structure of the value\n */\nexport class Binder<M extends AbstractModel> extends BinderRoot<M> {\n declare readonly ['constructor']: Omit<typeof Binder<M>, 'constructor'>;\n\n context: Element;\n\n /**\n *\n * @param context - The form view component instance to update.\n * @param Model - The constructor (the class reference) of the form model. The Binder instantiates the top-level model\n * @param config - The options object, which can be used to config the onChange and onSubmit callbacks.\n *\n * ```\n * binder = new Binder(orderView, OrderModel);\n * or\n * binder = new Binder(orderView, OrderModel, {onSubmit: async (order) => {endpoint.save(order)}});\n * ```\n */\n constructor(context: Element, Model: DetachedModelConstructor<M>, config?: BinderConfiguration<Value<M>>) {\n const changeCallback =\n config?.onChange ??\n (typeof (context as LitElement).requestUpdate === 'function'\n ? () => (context as LitElement).requestUpdate()\n : undefined);\n\n super(Model, {\n ...(config ?? {}),\n onChange: changeCallback,\n context,\n });\n this.context = context;\n }\n}\n"],
5
- "mappings": "AACA,SAAmC,kBAAkB;AAW9C,MAAM,eAAwC,WAAc;AAAA,EAGjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,YAAY,SAAkB,OAAoC,QAAwC;AACxG,UAAM,iBACJ,QAAQ,aACP,OAAQ,QAAuB,kBAAkB,aAC9C,MAAO,QAAuB,cAAc,IAC5C;AAEN,UAAM,OAAO;AAAA,MACX,GAAI,UAAU,CAAC;AAAA,MACf,UAAU;AAAA,MACV;AAAA,IACF,CAAC;AACD,SAAK,UAAU;AAAA,EACjB;AACF;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"Binder.js","sourceRoot":"","sources":["src/Binder.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAWvE,MAAM,OAAO,MAAgC,SAAQ,UAAa;IAiBhE,YAAY,OAAgB,EAAE,KAAkC,EAAE,MAAsC;QACtG,MAAM,cAAc,GAClB,MAAM,EAAE,QAAQ;YAChB,CAAC,OAAQ,OAAsB,CAAC,aAAa,KAAK,UAAU;gBAC1D,CAAC,CAAC,GAAG,EAAE,CAAE,OAAsB,CAAC,aAAa,EAAE;gBAC/C,CAAC,CAAC,SAAS,CAAC,CAAC;QAEjB,KAAK,CAAC,KAAK,EAAE;YACX,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;YACjB,QAAQ,EAAE,cAAc;YACxB,OAAO;SACR,CAAC,CAAC;QAzBL;;;;;WAAiB;QA0Bf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { LitElement } from 'lit';\nimport { type BinderConfiguration, BinderRoot } from './BinderRoot.js';\nimport type { AbstractModel, DetachedModelConstructor, Value } from './Models.js';\n\n/**\n * A Binder controls all aspects of a single form.\n * Typically, it is used to get and set the form value,\n * access the form model, validate, reset, and submit the form.\n *\n * @typeParam T - Type of the value that binds to a form\n * @typeParam M - Type of the model that describes the structure of the value\n */\nexport class Binder<M extends AbstractModel> extends BinderRoot<M> {\n declare readonly ['constructor']: Omit<typeof Binder<M>, 'constructor'>;\n\n context: Element;\n\n /**\n *\n * @param context - The form view component instance to update.\n * @param Model - The constructor (the class reference) of the form model. The Binder instantiates the top-level model\n * @param config - The options object, which can be used to config the onChange and onSubmit callbacks.\n *\n * ```\n * binder = new Binder(orderView, OrderModel);\n * or\n * binder = new Binder(orderView, OrderModel, {onSubmit: async (order) => {endpoint.save(order)}});\n * ```\n */\n constructor(context: Element, Model: DetachedModelConstructor<M>, config?: BinderConfiguration<Value<M>>) {\n const changeCallback =\n config?.onChange ??\n (typeof (context as LitElement).requestUpdate === 'function'\n ? () => (context as LitElement).requestUpdate()\n : undefined);\n\n super(Model, {\n ...(config ?? {}),\n onChange: changeCallback,\n context,\n });\n this.context = context;\n }\n}\n"]}
package/BinderNode.d.ts CHANGED
@@ -9,110 +9,32 @@ export declare const _setErrorsWithDescendants: unique symbol;
9
9
  export declare const _clearValidation: unique symbol;
10
10
  export declare function getBinderNode<M extends AbstractModel>(model: M): BinderNode<M>;
11
11
  export declare const CHANGED: Event;
12
- /**
13
- * The BinderNode\<M\> class provides the form binding related APIs
14
- * with respect to a particular model instance.
15
- *
16
- * Structurally, model instances form a tree, in which the object
17
- * and array models have child nodes of field and array item model
18
- * instances.
19
- */
20
12
  export declare class BinderNode<M extends AbstractModel = AbstractModel> extends EventTarget {
21
13
  #private;
22
14
  readonly ['constructor']: ClassStaticProperties<typeof BinderNode<M>>;
23
15
  readonly model: M;
24
- /**
25
- * The validity state read from the bound element, if any. Represents the
26
- * HTML element internal validation.
27
- *
28
- * For elements with `validity.valid === false`, the value in the
29
- * bound element is considered as invalid.
30
- */
31
16
  [_validity]?: ValidityState;
32
17
  constructor(model: M);
33
- /**
34
- * The binder for the top-level model.
35
- */
36
18
  get binder(): BinderRoot;
37
- /**
38
- * The default value related to the model
39
- */
40
19
  get defaultValue(): Value<M> | undefined;
41
- /**
42
- * True if the current value is different from the defaultValue.
43
- */
44
20
  get dirty(): boolean;
45
- /**
46
- * The combined array of all errors for this node’s model and all its nested
47
- * models
48
- */
49
21
  get errors(): readonly ValueError[];
50
- /**
51
- * Indicates if there is any error for the node's model.
52
- */
53
22
  get invalid(): boolean;
54
- /**
55
- * The name generated from the model structure, used to set the name
56
- * attribute on the field components.
57
- */
58
23
  get name(): string;
59
- /**
60
- * The array of validation errors directly related with the model.
61
- */
62
24
  get ownErrors(): ReadonlyArray<ValueError<Value<M>>>;
63
- /**
64
- * The parent node, if this binder node corresponds to a nested model,
65
- * otherwise undefined for the top-level binder.
66
- */
67
25
  get parent(): BinderNode | undefined;
68
- /**
69
- * True if the value is required to be non-empty.
70
- */
71
26
  get required(): boolean;
72
- /**
73
- * The array of validators for the model. The default value is defined in the
74
- * model.
75
- */
76
27
  get validators(): ReadonlyArray<Validator<Value<M>>>;
77
28
  set validators(validators: ReadonlyArray<Validator<Value<M>>>);
78
- /**
79
- * The current value related to the model
80
- */
81
29
  get value(): Value<M> | undefined;
82
30
  set value(value: Value<M> | undefined);
83
- /**
84
- * True if the bound field was ever focused and blurred by the user.
85
- */
86
31
  get visited(): boolean;
87
32
  set visited(v: boolean);
88
- /**
89
- * A helper method to add a validator
90
- *
91
- * @param validator - a validator
92
- */
93
33
  addValidator(validator: Validator<Value<M>>): void;
94
- /**
95
- * Append an item to the array value.
96
- *
97
- * Requires the context model to be an array reference.
98
- *
99
- * @param item - optional new item value, an empty item is
100
- * appended if the argument is omitted
101
- */
102
34
  appendItem(item?: Value<ArrayItemModel<M>>): void;
103
- /**
104
- * Returns a binder node for the nested model instance.
105
- *
106
- * @param model - The nested model instance
107
- */
108
35
  for<N extends AbstractModel>(model: N): BinderNode<N>;
109
36
  prependItem(item?: Value<ArrayItemModel<M>>): void;
110
37
  removeSelf(): void;
111
- /**
112
- * Runs all validation callbacks potentially affecting this
113
- * or any nested model. Returns the combined array of all
114
- * errors as in the errors property.
115
- */
116
38
  validate(): Promise<readonly ValueError[]>;
117
39
  protected [_clearValidation](): boolean;
118
40
  protected [_setErrorsWithDescendants](errors?: readonly ValueError[]): void;
@@ -120,4 +42,3 @@ export declare class BinderNode<M extends AbstractModel = AbstractModel> extends
120
42
  protected [_updateValidation](): Promise<void>;
121
43
  initializeValue(forceInitialize?: boolean): void;
122
44
  }
123
- //# sourceMappingURL=BinderNode.d.ts.map