@vaadin/hilla-lit-form 25.1.0-alpha2 → 25.1.0-alpha5
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 +4 -3
- package/Binder.js +2 -2
- package/Binder.js.map +1 -1
- package/BinderNode.d.ts +5 -4
- package/BinderNode.js +95 -32
- package/BinderNode.js.map +1 -1
- package/BinderRoot.d.ts +6 -5
- package/BinderRoot.js +10 -4
- package/BinderRoot.js.map +1 -1
- package/Field.d.ts +9 -9
- package/Field.js +28 -7
- package/Field.js.map +1 -1
- package/Models.d.ts +16 -14
- package/Models.js +14 -13
- package/Models.js.map +1 -1
- package/ProvisionalModel.d.ts +4 -0
- package/StringConverter.d.ts +4 -0
- package/Validation.d.ts +6 -5
- package/Validation.js +1 -2
- package/Validation.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +3 -2
- package/stringConverters.d.ts +3 -0
- package/stringConverters.js +52 -0
- package/stringConverters.js.map +1 -0
package/Binder.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type BinderConfiguration, BinderRoot } from './BinderRoot.js';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { Value } from './Models.js';
|
|
3
|
+
import type { ProvisionalModel, ProvisionalModelConstructor } from './ProvisionalModel.js';
|
|
4
|
+
export declare class Binder<M extends ProvisionalModel> extends BinderRoot<M> {
|
|
4
5
|
readonly ['constructor']: Omit<typeof Binder<M>, 'constructor'>;
|
|
5
6
|
context: Element;
|
|
6
|
-
constructor(context: Element,
|
|
7
|
+
constructor(context: Element, modelClass: ProvisionalModelConstructor<M>, config?: BinderConfiguration<Value<M>>);
|
|
7
8
|
}
|
package/Binder.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BinderRoot } from './BinderRoot.js';
|
|
2
2
|
export class Binder extends BinderRoot {
|
|
3
|
-
constructor(context,
|
|
3
|
+
constructor(context, modelClass, config) {
|
|
4
4
|
const changeCallback = config?.onChange ??
|
|
5
5
|
(typeof context.requestUpdate === 'function'
|
|
6
6
|
? () => context.requestUpdate()
|
|
7
7
|
: undefined);
|
|
8
|
-
super(
|
|
8
|
+
super(modelClass, {
|
|
9
9
|
...(config ?? {}),
|
|
10
10
|
onChange: changeCallback,
|
|
11
11
|
context,
|
package/Binder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Binder.js","sourceRoot":"","sources":["src/Binder.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"Binder.js","sourceRoot":"","sources":["src/Binder.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAYvE,MAAM,OAAO,MAAmC,SAAQ,UAAa;IAiBnE,YAAY,OAAgB,EAAE,UAA0C,EAAE,MAAsC;QAC9G,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,UAAU,EAAE;YAChB,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 { Value } from './Models.js';\nimport type { ProvisionalModel, ProvisionalModelConstructor } from './ProvisionalModel.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 ProvisionalModel> 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 modelClass - 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, modelClass: ProvisionalModelConstructor<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(modelClass, {\n ...(config ?? {}),\n onChange: changeCallback,\n context,\n });\n this.context = context;\n }\n}\n"]}
|
package/BinderNode.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BinderRoot } from './BinderRoot.js';
|
|
2
|
-
import {
|
|
2
|
+
import { type ArrayItemModel, type Value } from './Models.js';
|
|
3
|
+
import type { ProvisionalModel } from './ProvisionalModel.js';
|
|
3
4
|
import type { ClassStaticProperties } from './types.js';
|
|
4
5
|
import type { Validator, ValueError } from './Validation.js';
|
|
5
6
|
import { _validity } from './Validity.js';
|
|
@@ -7,9 +8,9 @@ export declare const _updateValidation: unique symbol;
|
|
|
7
8
|
export declare const _update: unique symbol;
|
|
8
9
|
export declare const _setErrorsWithDescendants: unique symbol;
|
|
9
10
|
export declare const _clearValidation: unique symbol;
|
|
10
|
-
export declare function getBinderNode<M extends
|
|
11
|
+
export declare function getBinderNode<M extends ProvisionalModel>(model: M): BinderNode<M>;
|
|
11
12
|
export declare const CHANGED: Event;
|
|
12
|
-
export declare class BinderNode<M extends
|
|
13
|
+
export declare class BinderNode<M extends ProvisionalModel = ProvisionalModel> extends EventTarget {
|
|
13
14
|
#private;
|
|
14
15
|
readonly ['constructor']: ClassStaticProperties<typeof BinderNode<M>>;
|
|
15
16
|
readonly model: M;
|
|
@@ -32,7 +33,7 @@ export declare class BinderNode<M extends AbstractModel = AbstractModel> extends
|
|
|
32
33
|
set visited(v: boolean);
|
|
33
34
|
addValidator(validator: Validator<Value<M>>): void;
|
|
34
35
|
appendItem(item?: Value<ArrayItemModel<M>>): void;
|
|
35
|
-
for<N extends
|
|
36
|
+
for<N extends ProvisionalModel>(model: N): BinderNode<N>;
|
|
36
37
|
prependItem(item?: Value<ArrayItemModel<M>>): void;
|
|
37
38
|
removeSelf(): void;
|
|
38
39
|
validate(): Promise<readonly ValueError[]>;
|
package/BinderNode.js
CHANGED
|
@@ -9,9 +9,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _BinderNode_instances, _BinderNode_ownErrors, _BinderNode_validators, _BinderNode_validityStateValidator, _BinderNode_visited, _BinderNode_getChildBinderNodes, _BinderNode_isArray, _BinderNode_isArrayItem,
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
12
|
+
var _BinderNode_instances, _BinderNode_ownErrors, _BinderNode_validators, _BinderNode_validityStateValidator, _BinderNode_visited, _BinderNode_getChildBinderNodes, _BinderNode_isArray, _BinderNode_isArrayItem, _BinderNode_requestValidationOfDescendants, _BinderNode_requestValidationWithAncestors, _BinderNode_runOwnValidators, _BinderNode_setValueState, _a;
|
|
13
|
+
import m, { $defaultValue, $key, $optional, $owner, NumberModel, $constraints, Null, NotNull, AssertTrue, AssertFalse, Min, Max, DecimalMin, Negative, NegativeOrZero, Positive, PositiveOrZero, Size, Digits, Past, Future, Pattern, NotEmpty, NotBlank, Email, Model, ArrayModel, ObjectModel, $itemModel, } from '@vaadin/hilla-models';
|
|
14
|
+
import { _createEmptyItemValue, _validators, AbstractModel, ArrayModel as BinderArrayModel, getObjectModelOwnAndParentGetters, ObjectModel as BinderObjectModel, } from './Models.js';
|
|
15
|
+
import * as Validators from './Validators.js';
|
|
15
16
|
import { _validity } from './Validity.js';
|
|
16
17
|
export const _updateValidation = Symbol('updateValidation');
|
|
17
18
|
export const _update = Symbol('update');
|
|
@@ -26,11 +27,61 @@ export function getBinderNode(model) {
|
|
|
26
27
|
}
|
|
27
28
|
return node;
|
|
28
29
|
}
|
|
30
|
+
function getConstraintValidator(constraint) {
|
|
31
|
+
const constraintTypes = [
|
|
32
|
+
Null,
|
|
33
|
+
NotNull,
|
|
34
|
+
AssertTrue,
|
|
35
|
+
AssertFalse,
|
|
36
|
+
Min,
|
|
37
|
+
Max,
|
|
38
|
+
DecimalMin,
|
|
39
|
+
Negative,
|
|
40
|
+
NegativeOrZero,
|
|
41
|
+
Positive,
|
|
42
|
+
PositiveOrZero,
|
|
43
|
+
Size,
|
|
44
|
+
Digits,
|
|
45
|
+
Past,
|
|
46
|
+
Future,
|
|
47
|
+
Pattern,
|
|
48
|
+
NotEmpty,
|
|
49
|
+
NotBlank,
|
|
50
|
+
Email,
|
|
51
|
+
];
|
|
52
|
+
for (const constraintType of constraintTypes) {
|
|
53
|
+
if (m.isConstraint(constraint, constraintType)) {
|
|
54
|
+
const Validator = Validators[constraintType.name];
|
|
55
|
+
return new Validator(constraint.attributes);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Unsupported constraint: ${constraint.name}`);
|
|
59
|
+
}
|
|
60
|
+
function getModelValidators(model) {
|
|
61
|
+
if (model instanceof AbstractModel) {
|
|
62
|
+
return model[_validators];
|
|
63
|
+
}
|
|
64
|
+
const validators = model instanceof NumberModel ? [new Validators.IsNumber(model[$optional])] : [];
|
|
65
|
+
for (const constraint of model[$constraints]) {
|
|
66
|
+
const validator = getConstraintValidator(constraint);
|
|
67
|
+
validators.push(validator);
|
|
68
|
+
}
|
|
69
|
+
return validators;
|
|
70
|
+
}
|
|
71
|
+
function createEmptyValue(model) {
|
|
72
|
+
if (model instanceof AbstractModel) {
|
|
73
|
+
return model.constructor.createEmptyValue();
|
|
74
|
+
}
|
|
75
|
+
return model[$defaultValue];
|
|
76
|
+
}
|
|
77
|
+
function createEmptyArrayItemValue(model) {
|
|
78
|
+
return (model instanceof BinderArrayModel ? model[_createEmptyItemValue]() : model[$itemModel][$defaultValue]);
|
|
79
|
+
}
|
|
29
80
|
function getErrorPropertyName(valueError) {
|
|
30
81
|
return typeof valueError.property === 'string' ? valueError.property : getBinderNode(valueError.property).name;
|
|
31
82
|
}
|
|
32
83
|
function updateObjectOrArrayKey(model, value, key, keyValue) {
|
|
33
|
-
if (model instanceof ObjectModel) {
|
|
84
|
+
if (model instanceof BinderObjectModel || model instanceof ObjectModel) {
|
|
34
85
|
return {
|
|
35
86
|
...value,
|
|
36
87
|
[key]: keyValue,
|
|
@@ -39,7 +90,7 @@ function updateObjectOrArrayKey(model, value, key, keyValue) {
|
|
|
39
90
|
if (keyValue === undefined) {
|
|
40
91
|
throw new TypeError('Unexpected undefined value');
|
|
41
92
|
}
|
|
42
|
-
if (model instanceof ArrayModel) {
|
|
93
|
+
if (model instanceof BinderArrayModel || model instanceof ArrayModel) {
|
|
43
94
|
const array = value.slice();
|
|
44
95
|
array[key] = keyValue;
|
|
45
96
|
return array;
|
|
@@ -80,8 +131,8 @@ export class BinderNode extends EventTarget {
|
|
|
80
131
|
_BinderNode_visited.set(this, false);
|
|
81
132
|
this.model = model;
|
|
82
133
|
nodes.set(model, this);
|
|
83
|
-
__classPrivateFieldSet(this, _BinderNode_validityStateValidator, new ValidityStateValidator(), "f");
|
|
84
|
-
__classPrivateFieldSet(this, _BinderNode_validators, model
|
|
134
|
+
__classPrivateFieldSet(this, _BinderNode_validityStateValidator, new Validators.ValidityStateValidator(), "f");
|
|
135
|
+
__classPrivateFieldSet(this, _BinderNode_validators, getModelValidators(model), "f");
|
|
85
136
|
if (this.constructor === BinderNode) {
|
|
86
137
|
this.initializeValue();
|
|
87
138
|
}
|
|
@@ -94,13 +145,13 @@ export class BinderNode extends EventTarget {
|
|
|
94
145
|
return binder;
|
|
95
146
|
}
|
|
96
147
|
get defaultValue() {
|
|
97
|
-
const key = this.model[
|
|
148
|
+
const key = this.model[$key];
|
|
98
149
|
const parentDefaultValue = this.parent.defaultValue;
|
|
99
150
|
if (__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_isArrayItem).call(this) && !(key in parentDefaultValue)) {
|
|
100
151
|
if (defaultArrayItemCache.has(this.parent)) {
|
|
101
152
|
return defaultArrayItemCache.get(this.parent);
|
|
102
153
|
}
|
|
103
|
-
const value = this.model
|
|
154
|
+
const value = createEmptyValue(this.model);
|
|
104
155
|
defaultArrayItemCache.set(this.parent, value);
|
|
105
156
|
return value;
|
|
106
157
|
}
|
|
@@ -118,9 +169,9 @@ export class BinderNode extends EventTarget {
|
|
|
118
169
|
get name() {
|
|
119
170
|
let { model } = this;
|
|
120
171
|
let name = '';
|
|
121
|
-
while (model[
|
|
122
|
-
name = `${String(model[
|
|
123
|
-
model = model[
|
|
172
|
+
while (model[$owner] instanceof AbstractModel || model[$owner] instanceof Model) {
|
|
173
|
+
name = `${String(model[$key])}${name ? `.${name}` : ''}`;
|
|
174
|
+
model = model[$owner];
|
|
124
175
|
}
|
|
125
176
|
return name;
|
|
126
177
|
}
|
|
@@ -128,8 +179,10 @@ export class BinderNode extends EventTarget {
|
|
|
128
179
|
return __classPrivateFieldGet(this, _BinderNode_ownErrors, "f") ? __classPrivateFieldGet(this, _BinderNode_ownErrors, "f") : [];
|
|
129
180
|
}
|
|
130
181
|
get parent() {
|
|
131
|
-
const modelParent = this.model[
|
|
132
|
-
return modelParent instanceof AbstractModel
|
|
182
|
+
const modelParent = this.model[$owner];
|
|
183
|
+
return modelParent instanceof AbstractModel || modelParent instanceof Model
|
|
184
|
+
? getBinderNode(modelParent)
|
|
185
|
+
: undefined;
|
|
133
186
|
}
|
|
134
187
|
get required() {
|
|
135
188
|
return __classPrivateFieldGet(this, _BinderNode_validators, "f").some((validator) => validator.impliesRequired);
|
|
@@ -146,7 +199,7 @@ export class BinderNode extends EventTarget {
|
|
|
146
199
|
return undefined;
|
|
147
200
|
}
|
|
148
201
|
this.initializeValue();
|
|
149
|
-
const key = this.model[
|
|
202
|
+
const key = this.model[$key];
|
|
150
203
|
return this.parent.value[key];
|
|
151
204
|
}
|
|
152
205
|
set value(value) {
|
|
@@ -172,7 +225,7 @@ export class BinderNode extends EventTarget {
|
|
|
172
225
|
}
|
|
173
226
|
appendItem(item) {
|
|
174
227
|
if (__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_isArray).call(this)) {
|
|
175
|
-
const itemValueOrEmptyValue = item ?? this.model
|
|
228
|
+
const itemValueOrEmptyValue = item ?? createEmptyArrayItemValue(this.model);
|
|
176
229
|
const newValue = [...(this.value ?? []), itemValueOrEmptyValue];
|
|
177
230
|
const newDefaultValue = [...(this.defaultValue ?? []), itemValueOrEmptyValue];
|
|
178
231
|
__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_setValueState).call(this, newValue, newDefaultValue);
|
|
@@ -190,7 +243,7 @@ export class BinderNode extends EventTarget {
|
|
|
190
243
|
}
|
|
191
244
|
prependItem(item) {
|
|
192
245
|
if (__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_isArray).call(this)) {
|
|
193
|
-
const itemValueOrEmptyValue = item ?? this.model
|
|
246
|
+
const itemValueOrEmptyValue = item ?? createEmptyArrayItemValue(this.model);
|
|
194
247
|
const newValue = [itemValueOrEmptyValue, ...(this.value ?? [])];
|
|
195
248
|
const newDefaultValue = [itemValueOrEmptyValue, ...(this.defaultValue ?? [])];
|
|
196
249
|
__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_setValueState).call(this, newValue, newDefaultValue);
|
|
@@ -202,8 +255,8 @@ export class BinderNode extends EventTarget {
|
|
|
202
255
|
removeSelf() {
|
|
203
256
|
var _b;
|
|
204
257
|
if (__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_isArrayItem).call(this)) {
|
|
205
|
-
const newValue = (this.parent.value ?? []).filter((_, i) => i !== this.model[
|
|
206
|
-
const newDefaultValue = (this.parent.defaultValue ?? []).filter((_, i) => i !== this.model[
|
|
258
|
+
const newValue = (this.parent.value ?? []).filter((_, i) => i !== this.model[$key]);
|
|
259
|
+
const newDefaultValue = (this.parent.defaultValue ?? []).filter((_, i) => i !== this.model[$key]);
|
|
207
260
|
__classPrivateFieldGet((_b = this.parent), _BinderNode_instances, "m", _BinderNode_setValueState).call(_b, newValue, newDefaultValue);
|
|
208
261
|
}
|
|
209
262
|
else {
|
|
@@ -264,19 +317,19 @@ export class BinderNode extends EventTarget {
|
|
|
264
317
|
(this.parent.value === undefined || this.parent.defaultValue === undefined)) {
|
|
265
318
|
this.parent.initializeValue(true);
|
|
266
319
|
}
|
|
267
|
-
const key = this.model[
|
|
320
|
+
const key = this.model[$key];
|
|
268
321
|
let value = this.parent
|
|
269
|
-
? this.parent.value[this.model[
|
|
322
|
+
? this.parent.value[this.model[$key]]
|
|
270
323
|
: undefined;
|
|
271
324
|
const defaultValue = this.parent
|
|
272
|
-
? this.parent.defaultValue[this.model[
|
|
325
|
+
? this.parent.defaultValue[this.model[$key]]
|
|
273
326
|
: undefined;
|
|
274
327
|
if (value === undefined) {
|
|
275
328
|
if (forceInitialize || !this.parent) {
|
|
276
|
-
value = this.model
|
|
329
|
+
value = createEmptyValue(this.model);
|
|
277
330
|
__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_setValueState).call(this, value, defaultValue === undefined ? value : defaultValue);
|
|
278
331
|
}
|
|
279
|
-
else if (this.parent.model instanceof
|
|
332
|
+
else if (this.parent.model instanceof BinderObjectModel &&
|
|
280
333
|
!(key in (this.parent.value || {}))) {
|
|
281
334
|
__classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_setValueState).call(this, undefined, defaultValue === undefined ? value : defaultValue);
|
|
282
335
|
}
|
|
@@ -287,25 +340,35 @@ _BinderNode_getChildBinderNodes = function* _BinderNode_getChildBinderNodes() {
|
|
|
287
340
|
if (this.value === undefined || this.defaultValue === undefined) {
|
|
288
341
|
return;
|
|
289
342
|
}
|
|
290
|
-
if (
|
|
343
|
+
if (this.model instanceof BinderObjectModel) {
|
|
291
344
|
for (const [, getter] of getObjectModelOwnAndParentGetters(this.model)) {
|
|
292
345
|
const childModel = getter.call(this.model);
|
|
293
|
-
if (childModel[
|
|
346
|
+
if (childModel[$key] in this.defaultValue) {
|
|
294
347
|
yield getBinderNode(childModel);
|
|
295
348
|
}
|
|
296
349
|
}
|
|
297
350
|
}
|
|
298
|
-
else if (
|
|
351
|
+
else if (this.model instanceof BinderArrayModel) {
|
|
299
352
|
for (const childBinderNode of this.model) {
|
|
300
353
|
yield childBinderNode;
|
|
301
354
|
}
|
|
302
355
|
}
|
|
356
|
+
else if (this.model instanceof ObjectModel) {
|
|
357
|
+
for (const propName in this.model) {
|
|
358
|
+
if (propName in this.defaultValue) {
|
|
359
|
+
yield getBinderNode(this.model[propName]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if (this.model instanceof ArrayModel) {
|
|
364
|
+
for (const childModel of m.items(this.model)) {
|
|
365
|
+
yield getBinderNode(childModel);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
303
368
|
}, _BinderNode_isArray = function _BinderNode_isArray() {
|
|
304
|
-
return this.model instanceof ArrayModel;
|
|
369
|
+
return this.model instanceof ArrayModel || this.model instanceof BinderArrayModel;
|
|
305
370
|
}, _BinderNode_isArrayItem = function _BinderNode_isArrayItem() {
|
|
306
|
-
return this.model[
|
|
307
|
-
}, _BinderNode_isObject = function _BinderNode_isObject() {
|
|
308
|
-
return this.model instanceof ObjectModel;
|
|
371
|
+
return this.model[$owner] instanceof BinderArrayModel || this.model[$owner] instanceof ArrayModel;
|
|
309
372
|
}, _BinderNode_requestValidationOfDescendants = function* _BinderNode_requestValidationOfDescendants() {
|
|
310
373
|
for (const node of __classPrivateFieldGet(this, _BinderNode_instances, "m", _BinderNode_getChildBinderNodes).call(this)) {
|
|
311
374
|
yield* __classPrivateFieldGet(node, _BinderNode_instances, "m", _BinderNode_runOwnValidators).call(node);
|
|
@@ -331,7 +394,7 @@ _BinderNode_getChildBinderNodes = function* _BinderNode_getChildBinderNodes() {
|
|
|
331
394
|
}, _BinderNode_setValueState = function _BinderNode_setValueState(value, defaultValue) {
|
|
332
395
|
const { parent } = this;
|
|
333
396
|
if (parent) {
|
|
334
|
-
const key = this.model[
|
|
397
|
+
const key = this.model[$key];
|
|
335
398
|
const parentValue = updateObjectOrArrayKey(parent.model, parent.value, key, value);
|
|
336
399
|
const keepPristine = value === defaultValue && parent.value === parent.defaultValue;
|
|
337
400
|
if (keepPristine) {
|
package/BinderNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BinderNode.js","sourceRoot":"","sources":["src/BinderNode.ts"],"names":[],"mappings":";;;;;;;;;;;;AAmBA,OAAO,EACL,qBAAqB,EACrB,IAAI,EACJ,OAAO,EACP,WAAW,EACX,aAAa,EAEb,UAAU,EACV,iCAAiC,EACjC,WAAW,GAEZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAA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AAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAEtC,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,YAAY,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;YACxG,uBAAA,MAAM,wDAAe,MAArB,MAAM,EAAgB,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,uBAAA,MAAM,wDAAe,MAArB,MAAM,EAAgB,WAAW,EAAE,SAAS,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;SAAM,CAAC;QAEN,MAAM,MAAM,GAAG,IAAgC,CAAC;QAChD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QACrC,CAAC;QACD,MAAM,CAAC,KAAK,GAAG,KAAM,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */\n/*\n * Copyright 2000-2020 Vaadin Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n// TODO: Fix dependency cycle\n\nimport type { BinderRoot } from './BinderRoot.js';\nimport {\n _createEmptyItemValue,\n _key,\n _parent,\n _validators,\n AbstractModel,\n type ArrayItemModel,\n ArrayModel,\n getObjectModelOwnAndParentGetters,\n ObjectModel,\n type Value,\n} from './Models.js';\nimport type { ClassStaticProperties } from './types.js';\nimport type { Validator, ValueError } from './Validation.js';\nimport { ValidityStateValidator } from './Validators.js';\nimport { _validity } from './Validity.js';\n\nexport const _updateValidation = Symbol('updateValidation');\nexport const _update = Symbol('update');\nexport const _setErrorsWithDescendants = Symbol('setErrorsWithDescendants');\nexport const _clearValidation = Symbol('clearValidation');\n\nconst nodes = new WeakMap<AbstractModel, BinderNode>();\n\nexport function getBinderNode<M extends AbstractModel>(model: M): BinderNode<M> {\n let node = nodes.get(model);\n\n if (!node) {\n node = new BinderNode(model);\n nodes.set(model, node);\n }\n\n return node as BinderNode<M>;\n}\n\nfunction getErrorPropertyName(valueError: ValueError): string {\n return typeof valueError.property === 'string' ? valueError.property : getBinderNode(valueError.property).name;\n}\n\nfunction updateObjectOrArrayKey<M extends AbstractModel>(\n model: M,\n value: Value<M>,\n key: keyof any,\n keyValue: unknown,\n): Value<M> {\n if (model instanceof ObjectModel) {\n // Value contained in object - replace object in parent\n return {\n ...(value as Record<never, never> & Value<M>),\n [key]: keyValue,\n };\n }\n\n if (keyValue === undefined) {\n throw new TypeError('Unexpected undefined value');\n }\n\n if (model instanceof ArrayModel) {\n // Value contained in array - replace array in parent\n const array = (value as unknown[]).slice();\n array[key as number] = keyValue;\n return array as Value<M>;\n }\n\n throw new TypeError(`Unknown model type ${(model as AbstractModel).constructor.name}`);\n}\n\nexport const CHANGED = new Event('binder-node-changed');\n\nclass NotArrayModelError extends Error {\n constructor() {\n super('The model does not represent array');\n }\n}\n\nclass NotArrayItemModelError extends Error {\n constructor() {\n super('The model does not represent array item');\n }\n}\n\ndeclare class ArrayItemBinderNode<M extends AbstractModel> extends BinderNode<M> {\n // @ts-expect-error: re-defining the parent getter.\n declare readonly parent: BinderNode<ArrayModel<M>>;\n}\n\nconst defaultArrayItemCache = new WeakMap<BinderNode, unknown>();\n\n/**\n * The BinderNode\\<M\\> class provides the form binding related APIs\n * with respect to a particular model instance.\n *\n * Structurally, model instances form a tree, in which the object\n * and array models have child nodes of field and array item model\n * instances.\n */\nexport class BinderNode<M extends AbstractModel = AbstractModel> extends EventTarget {\n declare readonly ['constructor']: ClassStaticProperties<typeof BinderNode<M>>;\n readonly model: M;\n /**\n * The validity state read from the bound element, if any. Represents the\n * HTML element internal validation.\n *\n * For elements with `validity.valid === false`, the value in the\n * bound element is considered as invalid.\n */\n [_validity]?: ValidityState;\n #ownErrors?: ReadonlyArray<ValueError<Value<M>>>;\n #validators: ReadonlyArray<Validator<Value<M>>>;\n readonly #validityStateValidator: ValidityStateValidator<Value<M>>;\n #visited = false;\n\n constructor(model: M) {\n super();\n this.model = model;\n nodes.set(model, this);\n this.#validityStateValidator = new ValidityStateValidator<Value<M>>();\n this.#validators = model[_validators];\n\n // Workaround for children initialization with private props\n if (this.constructor === BinderNode) {\n this.initializeValue();\n }\n }\n\n /**\n * The binder for the top-level model.\n */\n get binder(): BinderRoot {\n const binder = this.parent?.binder;\n\n if (!binder) {\n throw new TypeError('BinderNode is detached');\n }\n\n return binder;\n }\n\n /**\n * The default value related to the model\n */\n get defaultValue(): Value<M> | undefined {\n const key = this.model[_key];\n const parentDefaultValue = this.parent!.defaultValue as Readonly<Partial<Record<typeof key, Value<M>>>>;\n\n if (this.#isArrayItem() && !(key in parentDefaultValue)) {\n if (defaultArrayItemCache.has(this.parent)) {\n return defaultArrayItemCache.get(this.parent) as Value<M>;\n }\n\n const value = this.model.constructor.createEmptyValue();\n defaultArrayItemCache.set(this.parent, value);\n return value as Value<M>;\n }\n\n return parentDefaultValue[key];\n }\n\n /**\n * True if the current value is different from the defaultValue.\n */\n get dirty(): boolean {\n return this.value !== this.defaultValue;\n }\n\n /**\n * The combined array of all errors for this node’s model and all its nested\n * models\n */\n get errors(): readonly ValueError[] {\n return [...Array.from(this.#getChildBinderNodes(), (node) => node.errors).flat(), ...this.ownErrors];\n }\n\n /**\n * Indicates if there is any error for the node's model.\n */\n get invalid(): boolean {\n return this.errors.length > 0;\n }\n\n /**\n * The name generated from the model structure, used to set the name\n * attribute on the field components.\n */\n get name(): string {\n let { model }: { model: AbstractModel } = this;\n let name = '';\n\n while (model[_parent] instanceof AbstractModel) {\n name = `${String(model[_key])}${name ? `.${name}` : ''}`;\n model = model[_parent];\n }\n\n return name;\n }\n\n /**\n * The array of validation errors directly related with the model.\n */\n get ownErrors(): ReadonlyArray<ValueError<Value<M>>> {\n return this.#ownErrors ? this.#ownErrors : [];\n }\n\n /**\n * The parent node, if this binder node corresponds to a nested model,\n * otherwise undefined for the top-level binder.\n */\n get parent(): BinderNode | undefined {\n const modelParent = this.model[_parent];\n return modelParent instanceof AbstractModel ? getBinderNode(modelParent) : undefined;\n }\n\n /**\n * True if the value is required to be non-empty.\n */\n get required(): boolean {\n return this.#validators.some((validator) => validator.impliesRequired);\n }\n\n /**\n * The array of validators for the model. The default value is defined in the\n * model.\n */\n get validators(): ReadonlyArray<Validator<Value<M>>> {\n return this.#validators;\n }\n\n set validators(validators: ReadonlyArray<Validator<Value<M>>>) {\n this.#validators = validators;\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * The current value related to the model\n */\n get value(): Value<M> | undefined {\n if (!this.parent) {\n return undefined;\n }\n\n this.initializeValue();\n\n const key = this.model[_key];\n\n // The value of parent in unknown, so we need to cast it.\n type ParentValue = Readonly<Record<typeof key, Value<M>>>;\n return (this.parent.value as ParentValue)[key];\n }\n\n set value(value: Value<M> | undefined) {\n this.initializeValue(true);\n const oldValue = this.value;\n if (value !== oldValue) {\n this.#setValueState(value, undefined);\n this[_updateValidation]().catch(() => {});\n }\n }\n\n /**\n * True if the bound field was ever focused and blurred by the user.\n */\n get visited(): boolean {\n return this.#visited;\n }\n\n set visited(v: boolean) {\n if (this.#visited !== v) {\n this.#visited = v;\n this.dispatchEvent(CHANGED);\n }\n }\n\n /**\n * A helper method to add a validator\n *\n * @param validator - a validator\n */\n addValidator(validator: Validator<Value<M>>): void {\n this.validators = [...this.#validators, validator];\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * Append an item to the array value.\n *\n * Requires the context model to be an array reference.\n *\n * @param item - optional new item value, an empty item is\n * appended if the argument is omitted\n */\n appendItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? this.model[_createEmptyItemValue]();\n const newValue = [...(this.value ?? []), itemValueOrEmptyValue];\n const newDefaultValue = [...(this.defaultValue ?? []), itemValueOrEmptyValue];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n /**\n * Returns a binder node for the nested model instance.\n *\n * @param model - The nested model instance\n */\n for<N extends AbstractModel>(model: N): BinderNode<N> {\n const binderNode = getBinderNode(model);\n if (binderNode.binder !== this.binder) {\n throw new Error('Unknown binder');\n }\n\n return binderNode;\n }\n\n prependItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? this.model[_createEmptyItemValue]();\n const newValue = [itemValueOrEmptyValue, ...(this.value ?? [])];\n const newDefaultValue = [itemValueOrEmptyValue, ...(this.defaultValue ?? [])];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n removeSelf(): void {\n if (this.#isArrayItem()) {\n const newValue = (this.parent.value ?? []).filter((_, i) => i !== this.model[_key]);\n const newDefaultValue = (this.parent.defaultValue ?? []).filter((_, i) => i !== this.model[_key]);\n this.parent.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayItemModelError();\n }\n }\n\n /**\n * Runs all validation callbacks potentially affecting this\n * or any nested model. Returns the combined array of all\n * errors as in the errors property.\n */\n async validate(): Promise<readonly ValueError[]> {\n const errors = await Promise.all([\n ...this.#requestValidationOfDescendants(),\n ...this.#requestValidationWithAncestors(),\n ]).then((arr) => arr.flat());\n this[_setErrorsWithDescendants](errors.length ? errors : undefined);\n this[_update]();\n return errors;\n }\n\n protected [_clearValidation](): boolean {\n if (this.#visited) {\n this.#visited = false;\n this.dispatchEvent(CHANGED);\n }\n let needsUpdate = false;\n if (this.#ownErrors) {\n this.#ownErrors = undefined;\n needsUpdate = true;\n this.dispatchEvent(CHANGED);\n }\n if ([...this.#getChildBinderNodes()].filter((childBinderNode) => childBinderNode[_clearValidation]()).length > 0) {\n needsUpdate = true;\n }\n return needsUpdate;\n }\n\n protected [_setErrorsWithDescendants](errors?: readonly ValueError[]): void {\n const { name } = this;\n const ownErrors = errors\n ? (errors.filter((valueError) => getErrorPropertyName(valueError) === name) as ReadonlyArray<\n ValueError<Value<M>>\n >)\n : undefined;\n const relatedErrors = errors\n ? errors.filter((valueError) => getErrorPropertyName(valueError).startsWith(name))\n : undefined;\n this.#ownErrors = ownErrors;\n for (const childBinderNode of this.#getChildBinderNodes()) {\n childBinderNode[_setErrorsWithDescendants](relatedErrors);\n }\n this.dispatchEvent(CHANGED);\n }\n\n protected [_update](_?: Value<M>): void {\n if (this.parent) {\n this.parent[_update]();\n }\n }\n\n protected async [_updateValidation](): Promise<void> {\n if (this.invalid) {\n await this.validate();\n }\n }\n\n *#getChildBinderNodes(): Generator<BinderNode, void, void> {\n if (this.value === undefined || this.defaultValue === undefined) {\n // Undefined value cannot have child properties and items.\n return;\n }\n\n if (this.#isObject()) {\n for (const [, getter] of getObjectModelOwnAndParentGetters(this.model)) {\n const childModel = getter.call(this.model);\n // We need to skip all non-initialised optional fields here in order\n // to prevent infinite recursion for circular references in the model.\n // Here we rely on presence of keys in `defaultValue` to detect all\n // initialised fields. The keys in `defaultValue` are defined for all\n // non-optional fields plus those optional fields whose values were\n // set from initial `binder.read()` or `binder.clear()` or by using a\n // binder node (e.g., form binding) for a nested field.\n if (childModel[_key] in (this.defaultValue as Record<never, never>)) {\n yield getBinderNode(childModel);\n }\n }\n } else if (this.#isArray()) {\n for (const childBinderNode of this.model) {\n yield childBinderNode;\n }\n }\n }\n\n #isArray(): this is BinderNode<ArrayModel> {\n return this.model instanceof ArrayModel;\n }\n\n #isArrayItem(): this is ArrayItemBinderNode<M> {\n return this.model[_parent] instanceof ArrayModel;\n }\n\n #isObject(): this is BinderNode<ObjectModel> {\n return this.model instanceof ObjectModel;\n }\n\n *#requestValidationOfDescendants(): Generator<Promise<readonly ValueError[]>, void, void> {\n for (const node of this.#getChildBinderNodes()) {\n yield* node.#runOwnValidators();\n yield* node.#requestValidationOfDescendants();\n }\n }\n\n *#requestValidationWithAncestors(): Generator<Promise<readonly ValueError[]>, void, void> {\n yield* this.#runOwnValidators();\n\n if (this.parent) {\n yield* this.parent.#requestValidationWithAncestors();\n }\n }\n\n *#runOwnValidators(): Generator<Promise<readonly ValueError[]>, void, void> {\n const hasInvalidState = this[_validity] && !this[_validity].valid;\n const hasBadInput = !!this[_validity]?.badInput;\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n if ((hasInvalidState && !hasBadInput) || !hasInvalidState) {\n for (const validator of this.#validators) {\n yield this.binder.requestValidation(this.model, validator);\n }\n }\n\n if (hasInvalidState) {\n yield this.binder.requestValidation(this.model, this.#validityStateValidator);\n }\n }\n\n initializeValue(forceInitialize = false): void {\n // First, make sure parents have value initialized\n if (\n this.parent &&\n (this.parent.value === undefined || (this.parent.defaultValue as Value<M> | undefined) === undefined)\n ) {\n this.parent.initializeValue(true);\n }\n\n const key = this.model[_key];\n let value: Value<M> | undefined = this.parent\n ? (this.parent.value as Record<typeof key, Value<M>>)[this.model[_key]]\n : undefined;\n\n const defaultValue: Value<M> | undefined = this.parent\n ? (this.parent.defaultValue as Readonly<Record<typeof key, Value<M>>>)[this.model[_key]]\n : undefined;\n\n if (value === undefined) {\n // Initialize value if this is the root level node, or it is enforced\n if (forceInitialize || !this.parent) {\n value = this.model.constructor.createEmptyValue() as Value<M>;\n this.#setValueState(value, defaultValue === undefined ? value : defaultValue);\n } else if (\n this.parent.model instanceof ObjectModel &&\n !(key in ((this.parent.value || {}) as Partial<Record<typeof key, Value<M>>>))\n ) {\n this.#setValueState(undefined, defaultValue === undefined ? value : defaultValue);\n }\n }\n }\n\n #setValueState(value: Value<M> | undefined, defaultValue: Value<M> | undefined): void {\n const { parent } = this;\n if (parent) {\n const key = this.model[_key];\n const parentValue = updateObjectOrArrayKey(parent.model, parent.value, key, value);\n const keepPristine = value === defaultValue && parent.value === parent.defaultValue;\n if (keepPristine) {\n // Keep value and defaultValue equal, so that `dirty` stays false\n parent.#setValueState(parentValue, parentValue);\n } else if (defaultValue !== undefined) {\n // Update value and defaultValue at the same time with different content\n const parentDefaultValue = updateObjectOrArrayKey(parent.model, parent.defaultValue, key, defaultValue);\n parent.#setValueState(parentValue, parentDefaultValue);\n } else {\n parent.#setValueState(parentValue, undefined);\n }\n } else {\n // Root level model - update the binder root\n const binder = this as unknown as BinderRoot<M>;\n if (defaultValue !== undefined) {\n binder.defaultValue = defaultValue;\n }\n binder.value = value!;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BinderNode.js","sourceRoot":"","sources":["src/BinderNode.ts"],"names":[],"mappings":";;;;;;;;;;;;AAiBA,OAAO,CAAC,EAAE,EACR,aAAa,EACb,IAAI,EACJ,SAAS,EACT,MAAM,EACN,WAAW,EACX,YAAY,EAEZ,IAAI,EACJ,OAAO,EACP,UAAU,EACV,WAAW,EACX,GAAG,EACH,GAAG,EACH,UAAU,EACV,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,MAAM,EACN,IAAI,EAEJ,MAAM,EAEN,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,KAAK,EAEL,KAAK,EACL,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,aAAa,EAEb,UAAU,IAAI,gBAAgB,EAC9B,iCAAiC,EACjC,WAAW,IAAI,iBAAiB,GAEjC,MAAM,aAAa,CAAC;AAIrB,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,yBAAyB,GAAG,MA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W,EAAE,kBAAkB,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,uBAAA,MAAM,wDAAe,MAArB,MAAM,EAAgB,WAAW,EAAE,SAAS,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;SAAM,CAAC;QAEN,MAAM,MAAM,GAAG,IAAgC,CAAC;QAChD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QACrC,CAAC;QACD,MAAM,CAAC,KAAK,GAAG,KAAM,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */\n/*\n * Copyright 2000-2020 Vaadin Ltd.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n// TODO: Fix dependency cycle\nimport m, {\n $defaultValue,\n $key,\n $optional,\n $owner,\n NumberModel,\n $constraints,\n type Constraint,\n Null,\n NotNull,\n AssertTrue,\n AssertFalse,\n Min,\n Max,\n DecimalMin,\n Negative,\n NegativeOrZero,\n Positive,\n PositiveOrZero,\n Size,\n Digits,\n Past,\n // PastOrPresent, // not supported\n Future,\n // FutureOrPresent, // not supported\n Pattern,\n NotEmpty,\n NotBlank,\n Email,\n type NonAttributedConstraint,\n Model,\n ArrayModel,\n ObjectModel,\n $itemModel,\n} from '@vaadin/hilla-models';\nimport type { Constructor, EmptyObject } from 'type-fest';\nimport type { BinderRoot } from './BinderRoot.js';\nimport {\n _createEmptyItemValue,\n _validators,\n AbstractModel,\n type ArrayItemModel,\n ArrayModel as BinderArrayModel,\n getObjectModelOwnAndParentGetters,\n ObjectModel as BinderObjectModel,\n type Value,\n} from './Models.js';\nimport type { ProvisionalModel } from './ProvisionalModel.js';\nimport type { ClassStaticProperties } from './types.js';\nimport type { Validator, ValueError } from './Validation.js';\nimport * as Validators from './Validators.js';\nimport { _validity } from './Validity.js';\n\nexport const _updateValidation = Symbol('updateValidation');\nexport const _update = Symbol('update');\nexport const _setErrorsWithDescendants = Symbol('setErrorsWithDescendants');\nexport const _clearValidation = Symbol('clearValidation');\n\nconst nodes = new WeakMap<ProvisionalModel, BinderNode>();\n\n/**\n * Given the model instance attached to the BinderNode, returns the corresponding BinderNode.\n *\n * @param model - The model instance\n * @returns The corresponding BinderNode\n */\nexport function getBinderNode<M extends ProvisionalModel>(model: M): BinderNode<M> {\n let node = nodes.get(model);\n\n if (!node) {\n node = new BinderNode(model);\n nodes.set(model, node);\n }\n\n return node as BinderNode<M>;\n}\n\n/**\n * Returns the corresponding validator for the given constraint.\n *\n * @param constraint - The constraint to get the validator for\n * @returns The corresponding validator\n */\nfunction getConstraintValidator<T>(constraint: Constraint<T>): Validator<T> {\n const constraintTypes = [\n Null,\n NotNull,\n AssertTrue,\n AssertFalse,\n Min,\n Max,\n DecimalMin,\n Negative,\n NegativeOrZero,\n Positive,\n PositiveOrZero,\n Size,\n Digits,\n Past,\n // PastOrPresent, // not supported\n Future,\n // FutureOrPresent, // not supported\n Pattern,\n NotEmpty,\n NotBlank,\n Email,\n ];\n for (const constraintType of constraintTypes) {\n if (m.isConstraint(constraint, constraintType as NonAttributedConstraint)) {\n // eslint-disable-next-line import/namespace\n const Validator = Validators[constraintType.name] as Constructor<\n Validator<T>,\n EmptyObject extends typeof constraint.attributes\n ? [typeof constraint.attributes | undefined]\n : [typeof constraint.attributes]\n >;\n return new Validator(constraint.attributes);\n }\n }\n throw new Error(`Unsupported constraint: ${constraint.name}`);\n}\n\n/**\n * Returns the array of validators for the given model.\n *\n * @param model - The model to get the validators for\n * @returns The array of validators\n */\nfunction getModelValidators<M extends ProvisionalModel>(model: M): ReadonlyArray<Validator<Value<M>>> {\n if (model instanceof AbstractModel) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return model[_validators];\n }\n\n const validators: Array<Validator<Value<M>>> =\n model instanceof NumberModel ? [new Validators.IsNumber(model[$optional]) as Validator<Value<M>>] : [];\n\n for (const constraint of model[$constraints]) {\n const validator = getConstraintValidator<Value<M>>(constraint);\n validators.push(validator);\n }\n\n return validators;\n}\n\nfunction createEmptyValue<M extends ProvisionalModel>(model: M) {\n if (model instanceof AbstractModel) {\n return model.constructor.createEmptyValue();\n }\n\n return model[$defaultValue];\n}\n\nfunction createEmptyArrayItemValue<M extends ArrayModel | BinderArrayModel>(model: M): ArrayItemModel<M> {\n return (\n model instanceof BinderArrayModel ? model[_createEmptyItemValue]() : model[$itemModel][$defaultValue]\n ) as ArrayItemModel<M>;\n}\n\nfunction getErrorPropertyName(valueError: ValueError): string {\n return typeof valueError.property === 'string' ? valueError.property : getBinderNode(valueError.property).name;\n}\n\nfunction updateObjectOrArrayKey<M extends ProvisionalModel>(\n model: M,\n value: Value<M>,\n key: keyof any,\n keyValue: unknown,\n): Value<M> {\n if (model instanceof BinderObjectModel || model instanceof ObjectModel) {\n // Value contained in object - replace object in parent\n return {\n ...(value as Record<never, never> & Value<M>),\n [key]: keyValue,\n };\n }\n\n if (keyValue === undefined) {\n throw new TypeError('Unexpected undefined value');\n }\n\n if (model instanceof BinderArrayModel || model instanceof ArrayModel) {\n // Value contained in array - replace array in parent\n const array = (value as unknown[]).slice();\n array[key as number] = keyValue;\n return array as Value<M>;\n }\n\n throw new TypeError(`Unknown model type ${model.constructor.name}`);\n}\n\nexport const CHANGED = new Event('binder-node-changed');\n\nclass NotArrayModelError extends Error {\n constructor() {\n super('The model does not represent array');\n }\n}\n\nclass NotArrayItemModelError extends Error {\n constructor() {\n super('The model does not represent array item');\n }\n}\n\ndeclare class ArrayItemBinderNode<M extends ProvisionalModel> extends BinderNode<M> {\n // @ts-expect-error: re-defining the parent getter.\n declare readonly parent: BinderNode<BinderArrayModel<M>>;\n}\n\nconst defaultArrayItemCache = new WeakMap<BinderNode, unknown>();\n\n/**\n * The BinderNode\\<M\\> class provides the form binding related APIs\n * with respect to a particular model instance.\n *\n * Structurally, model instances form a tree, in which the object\n * and array models have child nodes of field and array item model\n * instances.\n */\nexport class BinderNode<M extends ProvisionalModel = ProvisionalModel> extends EventTarget {\n declare readonly ['constructor']: ClassStaticProperties<typeof BinderNode<M>>;\n readonly model: M;\n /**\n * The validity state read from the bound element, if any. Represents the\n * HTML element internal validation.\n *\n * For elements with `validity.valid === false`, the value in the\n * bound element is considered as invalid.\n */\n [_validity]?: ValidityState;\n #ownErrors?: ReadonlyArray<ValueError<Value<M>>>;\n #validators: ReadonlyArray<Validator<Value<M>>>;\n readonly #validityStateValidator: Validators.ValidityStateValidator<Value<M>>;\n #visited = false;\n\n constructor(model: M) {\n super();\n this.model = model;\n nodes.set(model, this);\n this.#validityStateValidator = new Validators.ValidityStateValidator<Value<M>>();\n this.#validators = getModelValidators(model);\n\n // Workaround for children initialization with private props\n if (this.constructor === BinderNode) {\n this.initializeValue();\n }\n }\n\n /**\n * The binder for the top-level model.\n */\n get binder(): BinderRoot {\n const binder = this.parent?.binder;\n\n if (!binder) {\n throw new TypeError('BinderNode is detached');\n }\n\n return binder;\n }\n\n /**\n * The default value related to the model\n */\n get defaultValue(): Value<M> | undefined {\n const key = this.model[$key];\n const parentDefaultValue = this.parent!.defaultValue as Readonly<Partial<Record<typeof key, Value<M>>>>;\n\n if (this.#isArrayItem() && !(key in parentDefaultValue)) {\n if (defaultArrayItemCache.has(this.parent)) {\n return defaultArrayItemCache.get(this.parent) as Value<M>;\n }\n\n const value = createEmptyValue(this.model);\n defaultArrayItemCache.set(this.parent, value);\n return value as Value<M>;\n }\n\n return parentDefaultValue[key];\n }\n\n /**\n * True if the current value is different from the defaultValue.\n */\n get dirty(): boolean {\n return this.value !== this.defaultValue;\n }\n\n /**\n * The combined array of all errors for this node’s model and all its nested\n * models\n */\n get errors(): readonly ValueError[] {\n return [...Array.from(this.#getChildBinderNodes(), (node) => node.errors).flat(), ...this.ownErrors];\n }\n\n /**\n * Indicates if there is any error for the node's model.\n */\n get invalid(): boolean {\n return this.errors.length > 0;\n }\n\n /**\n * The name generated from the model structure, used to set the name\n * attribute on the field components.\n */\n get name(): string {\n let { model }: { model: ProvisionalModel } = this;\n let name = '';\n\n while (model[$owner] instanceof AbstractModel || model[$owner] instanceof Model) {\n name = `${String(model[$key])}${name ? `.${name}` : ''}`;\n model = model[$owner];\n }\n\n return name;\n }\n\n /**\n * The array of validation errors directly related with the model.\n */\n get ownErrors(): ReadonlyArray<ValueError<Value<M>>> {\n return this.#ownErrors ? this.#ownErrors : [];\n }\n\n /**\n * The parent node, if this binder node corresponds to a nested model,\n * otherwise undefined for the top-level binder.\n */\n get parent(): BinderNode | undefined {\n const modelParent = this.model[$owner];\n return modelParent instanceof AbstractModel || modelParent instanceof Model\n ? getBinderNode(modelParent)\n : undefined;\n }\n\n /**\n * True if the value is required to be non-empty.\n */\n get required(): boolean {\n return this.#validators.some((validator) => validator.impliesRequired);\n }\n\n /**\n * The array of validators for the model. The default value is defined in the\n * model.\n */\n get validators(): ReadonlyArray<Validator<Value<M>>> {\n return this.#validators;\n }\n\n set validators(validators: ReadonlyArray<Validator<Value<M>>>) {\n this.#validators = validators;\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * The current value related to the model\n */\n get value(): Value<M> | undefined {\n if (!this.parent) {\n return undefined;\n }\n\n this.initializeValue();\n\n // Retrieve the value from the parent's value using the key from the model.\n const key = this.model[$key];\n\n // The value of parent in unknown, so we need to cast it.\n type ParentValue = Readonly<Record<typeof key, Value<M>>>;\n return (this.parent.value as ParentValue)[key];\n }\n\n set value(value: Value<M> | undefined) {\n this.initializeValue(true);\n const oldValue = this.value;\n if (value !== oldValue) {\n this.#setValueState(value, undefined);\n this[_updateValidation]().catch(() => {});\n }\n }\n\n /**\n * True if the bound field was ever focused and blurred by the user.\n */\n get visited(): boolean {\n return this.#visited;\n }\n\n set visited(v: boolean) {\n if (this.#visited !== v) {\n this.#visited = v;\n this.dispatchEvent(CHANGED);\n }\n }\n\n /**\n * A helper method to add a validator\n *\n * @param validator - a validator\n */\n addValidator(validator: Validator<Value<M>>): void {\n this.validators = [...this.#validators, validator];\n this.dispatchEvent(CHANGED);\n }\n\n /**\n * Append an item to the array value.\n *\n * Requires the context model to be an array reference.\n *\n * @param item - optional new item value, an empty item is\n * appended if the argument is omitted\n */\n appendItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? createEmptyArrayItemValue(this.model);\n const newValue = [...(this.value ?? []), itemValueOrEmptyValue];\n const newDefaultValue = [...(this.defaultValue ?? []), itemValueOrEmptyValue];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n /**\n * Returns a binder node for the nested model instance.\n *\n * @param model - The nested model instance\n */\n for<N extends ProvisionalModel>(model: N): BinderNode<N> {\n const binderNode = getBinderNode(model);\n if (binderNode.binder !== this.binder) {\n throw new Error('Unknown binder');\n }\n\n return binderNode;\n }\n\n prependItem(item?: Value<ArrayItemModel<M>>): void {\n if (this.#isArray()) {\n const itemValueOrEmptyValue = item ?? createEmptyArrayItemValue(this.model);\n const newValue = [itemValueOrEmptyValue, ...(this.value ?? [])];\n const newDefaultValue = [itemValueOrEmptyValue, ...(this.defaultValue ?? [])];\n this.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayModelError();\n }\n }\n\n removeSelf(): void {\n if (this.#isArrayItem()) {\n // Removing item in a read-only array involves computing a new array with\n // the current item filtered out by numeric index obtained from `$key`.\n const newValue = (this.parent.value ?? []).filter((_, i) => i !== this.model[$key]);\n const newDefaultValue = (this.parent.defaultValue ?? []).filter((_, i) => i !== this.model[$key]);\n this.parent.#setValueState(newValue, newDefaultValue);\n } else {\n throw new NotArrayItemModelError();\n }\n }\n\n /**\n * Runs all validation callbacks potentially affecting this\n * or any nested model. Returns the combined array of all\n * errors as in the errors property.\n */\n async validate(): Promise<readonly ValueError[]> {\n const errors = await Promise.all([\n ...this.#requestValidationOfDescendants(),\n ...this.#requestValidationWithAncestors(),\n ]).then((arr) => arr.flat());\n this[_setErrorsWithDescendants](errors.length ? errors : undefined);\n this[_update]();\n return errors;\n }\n\n protected [_clearValidation](): boolean {\n if (this.#visited) {\n this.#visited = false;\n this.dispatchEvent(CHANGED);\n }\n let needsUpdate = false;\n if (this.#ownErrors) {\n this.#ownErrors = undefined;\n needsUpdate = true;\n this.dispatchEvent(CHANGED);\n }\n if ([...this.#getChildBinderNodes()].filter((childBinderNode) => childBinderNode[_clearValidation]()).length > 0) {\n needsUpdate = true;\n }\n return needsUpdate;\n }\n\n protected [_setErrorsWithDescendants](errors?: readonly ValueError[]): void {\n const { name } = this;\n const ownErrors = errors\n ? (errors.filter((valueError) => getErrorPropertyName(valueError) === name) as ReadonlyArray<\n ValueError<Value<M>>\n >)\n : undefined;\n const relatedErrors = errors\n ? errors.filter((valueError) => getErrorPropertyName(valueError).startsWith(name))\n : undefined;\n this.#ownErrors = ownErrors;\n for (const childBinderNode of this.#getChildBinderNodes()) {\n childBinderNode[_setErrorsWithDescendants](relatedErrors);\n }\n this.dispatchEvent(CHANGED);\n }\n\n protected [_update](_?: Value<M>): void {\n if (this.parent) {\n this.parent[_update]();\n }\n }\n\n protected async [_updateValidation](): Promise<void> {\n if (this.invalid) {\n await this.validate();\n }\n }\n\n *#getChildBinderNodes(): Generator<BinderNode, void, void> {\n if (this.value === undefined || this.defaultValue === undefined) {\n // Undefined value cannot have child properties and items.\n return;\n }\n\n if (this.model instanceof BinderObjectModel) {\n for (const [, getter] of getObjectModelOwnAndParentGetters(this.model)) {\n const childModel = getter.call(this.model);\n // We need to skip all non-initialised optional fields here in order\n // to prevent infinite recursion for circular references in the model.\n // Here we rely on presence of keys in `defaultValue` to detect all\n // initialised fields. The keys in `defaultValue` are defined for all\n // non-optional fields plus those optional fields whose values were\n // set from initial `binder.read()` or `binder.clear()` or by using a\n // binder node (e.g., form binding) for a nested field.\n if (childModel[$key] in (this.defaultValue as Record<never, never>)) {\n yield getBinderNode(childModel);\n }\n }\n } else if (this.model instanceof BinderArrayModel) {\n for (const childBinderNode of this.model) {\n yield childBinderNode;\n }\n } else if (this.model instanceof ObjectModel) {\n // eslint-disable-next-line @typescript-eslint/no-for-in-array,no-restricted-syntax\n for (const propName in this.model) {\n // We need to skip all non-initialised optional fields here in order\n // to prevent infinite recursion for circular references in the model.\n // Here we rely on presence of keys in `defaultValue` to detect all\n // initialised fields. The keys in `defaultValue` are defined for all\n // non-optional fields plus those optional fields whose values were\n // set from initial `binder.read()` or `binder.clear()` or by using a\n // binder node (e.g., form binding) for a nested field.\n if (propName in (this.defaultValue as Record<never, never>)) {\n yield getBinderNode((this.model as unknown as Record<string, Model>)[propName]);\n }\n }\n } else if (this.model instanceof ArrayModel) {\n for (const childModel of m.items(this.model)) {\n yield getBinderNode(childModel);\n }\n }\n }\n\n #isArray(): this is BinderNode<ArrayModel | BinderArrayModel> {\n return this.model instanceof ArrayModel || this.model instanceof BinderArrayModel;\n }\n\n #isArrayItem(): this is ArrayItemBinderNode<M> {\n return this.model[$owner] instanceof BinderArrayModel || this.model[$owner] instanceof ArrayModel;\n }\n\n *#requestValidationOfDescendants(): Generator<Promise<readonly ValueError[]>, void, void> {\n for (const node of this.#getChildBinderNodes()) {\n yield* node.#runOwnValidators();\n yield* node.#requestValidationOfDescendants();\n }\n }\n\n *#requestValidationWithAncestors(): Generator<Promise<readonly ValueError[]>, void, void> {\n yield* this.#runOwnValidators();\n\n if (this.parent) {\n yield* this.parent.#requestValidationWithAncestors();\n }\n }\n\n *#runOwnValidators(): Generator<Promise<readonly ValueError[]>, void, void> {\n const hasInvalidState = this[_validity] && !this[_validity].valid;\n const hasBadInput = !!this[_validity]?.badInput;\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n if ((hasInvalidState && !hasBadInput) || !hasInvalidState) {\n for (const validator of this.#validators) {\n yield this.binder.requestValidation(this.model, validator);\n }\n }\n\n if (hasInvalidState) {\n yield this.binder.requestValidation(this.model, this.#validityStateValidator);\n }\n }\n\n initializeValue(forceInitialize = false): void {\n // First, make sure parents have value initialized\n if (\n this.parent &&\n (this.parent.value === undefined || (this.parent.defaultValue as Value<M> | undefined) === undefined)\n ) {\n this.parent.initializeValue(true);\n }\n\n const key = this.model[$key];\n let value: Value<M> | undefined = this.parent\n ? (this.parent.value as Record<typeof key, Value<M>>)[this.model[$key]]\n : undefined;\n\n const defaultValue: Value<M> | undefined = this.parent\n ? (this.parent.defaultValue as Readonly<Record<typeof key, Value<M>>>)[this.model[$key]]\n : undefined;\n\n if (value === undefined) {\n // Initialize value if this is the root level node, or it is enforced\n if (forceInitialize || !this.parent) {\n value = createEmptyValue(this.model) as Value<M>;\n this.#setValueState(value, defaultValue === undefined ? value : defaultValue);\n } else if (\n this.parent.model instanceof BinderObjectModel &&\n !(key in ((this.parent.value || {}) as Partial<Record<typeof key, Value<M>>>))\n ) {\n this.#setValueState(undefined, defaultValue === undefined ? value : defaultValue);\n }\n }\n }\n\n #setValueState(value: Value<M> | undefined, defaultValue: Value<M> | undefined): void {\n const { parent } = this;\n if (parent) {\n const key = this.model[$key];\n const parentValue = updateObjectOrArrayKey(parent.model, parent.value, key, value);\n const keepPristine = value === defaultValue && parent.value === parent.defaultValue;\n if (keepPristine) {\n // Keep value and defaultValue equal, so that `dirty` stays false\n parent.#setValueState(parentValue, parentValue);\n } else if (defaultValue !== undefined) {\n // Update value and defaultValue at the same time with different content\n const parentDefaultValue = updateObjectOrArrayKey(parent.model, parent.defaultValue, key, defaultValue);\n parent.#setValueState(parentValue, parentDefaultValue);\n } else {\n parent.#setValueState(parentValue, undefined);\n }\n } else {\n // Root level model - update the binder root\n const binder = this as unknown as BinderRoot<M>;\n if (defaultValue !== undefined) {\n binder.defaultValue = defaultValue;\n }\n binder.value = value!;\n }\n }\n}\n"]}
|
package/BinderRoot.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _update, BinderNode } from './BinderNode.js';
|
|
2
2
|
import { type FieldStrategy } from './Field.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type Value } from './Models.js';
|
|
4
|
+
import type { ProvisionalModel, ProvisionalModelConstructor } from './ProvisionalModel.js';
|
|
4
5
|
import type { ClassStaticProperties } from './types.js';
|
|
5
6
|
import { type InterpolateMessageCallback, type Validator, type ValueError } from './Validation.js';
|
|
6
7
|
export type BinderConfiguration<T> = Readonly<{
|
|
@@ -10,11 +11,11 @@ export type BinderConfiguration<T> = Readonly<{
|
|
|
10
11
|
export type BinderRootConfiguration<T> = BinderConfiguration<T> & Readonly<{
|
|
11
12
|
context?: unknown;
|
|
12
13
|
}>;
|
|
13
|
-
export declare class BinderRoot<M extends
|
|
14
|
+
export declare class BinderRoot<M extends ProvisionalModel = ProvisionalModel> extends BinderNode<M> {
|
|
14
15
|
#private;
|
|
15
16
|
static interpolateMessageCallback?: InterpolateMessageCallback<any>;
|
|
16
17
|
readonly ['constructor']: ClassStaticProperties<typeof BinderRoot<M>>;
|
|
17
|
-
constructor(
|
|
18
|
+
constructor(modelClass: ProvisionalModelConstructor<M>, config?: BinderRootConfiguration<Value<M>>);
|
|
18
19
|
get defaultValue(): Value<M>;
|
|
19
20
|
set defaultValue(newValue: Value<M>);
|
|
20
21
|
get binder(): BinderRoot;
|
|
@@ -27,8 +28,8 @@ export declare class BinderRoot<M extends AbstractModel = AbstractModel> extends
|
|
|
27
28
|
clear(): void;
|
|
28
29
|
submit(): Promise<Value<M> | void>;
|
|
29
30
|
submitTo<V>(endpointMethod: (value: Value<M>) => Promise<V>): Promise<V>;
|
|
30
|
-
requestValidation<NM extends
|
|
31
|
-
getFieldStrategy<TField>(elm: HTMLElement, model?:
|
|
31
|
+
requestValidation<NM extends ProvisionalModel>(model: NM, validator: Validator<Value<NM>>): Promise<ReadonlyArray<ValueError<Value<NM>>>>;
|
|
32
|
+
getFieldStrategy<TField>(elm: HTMLElement, model?: ProvisionalModel<TField>): FieldStrategy;
|
|
32
33
|
protected performValidation(): Promise<void> | void;
|
|
33
34
|
protected completeValidation(): void;
|
|
34
35
|
protected [_update](oldValue: Value<M>): void;
|
package/BinderRoot.js
CHANGED
|
@@ -11,13 +11,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _BinderRoot_defaultValue, _BinderRoot_value, _BinderRoot_emptyValue, _BinderRoot_submitting, _BinderRoot_validating, _BinderRoot_validationRequest, _BinderRoot_config, _BinderRoot_validations, _BinderRoot_context;
|
|
13
13
|
import { EndpointValidationError } from '@vaadin/hilla-frontend/EndpointErrors.js';
|
|
14
|
+
import { $owner, Model } from '@vaadin/hilla-models';
|
|
15
|
+
import m from '@vaadin/hilla-models';
|
|
14
16
|
import { _clearValidation, _setErrorsWithDescendants, _update, BinderNode, CHANGED } from './BinderNode.js';
|
|
15
17
|
import { getDefaultFieldStrategy } from './Field.js';
|
|
16
|
-
import {
|
|
18
|
+
import { createDetachedModel } from './Models.js';
|
|
17
19
|
import { runValidator, ServerValidator, ValidationError, } from './Validation.js';
|
|
18
20
|
export class BinderRoot extends BinderNode {
|
|
19
|
-
constructor(
|
|
20
|
-
super(
|
|
21
|
+
constructor(modelClass, config) {
|
|
22
|
+
super((modelClass instanceof Model
|
|
23
|
+
? m.attach(modelClass, () => this)
|
|
24
|
+
: createDetachedModel(modelClass)));
|
|
21
25
|
_BinderRoot_defaultValue.set(this, void 0);
|
|
22
26
|
_BinderRoot_value.set(this, void 0);
|
|
23
27
|
_BinderRoot_emptyValue.set(this, void 0);
|
|
@@ -27,7 +31,9 @@ export class BinderRoot extends BinderNode {
|
|
|
27
31
|
_BinderRoot_config.set(this, void 0);
|
|
28
32
|
_BinderRoot_validations.set(this, new Map());
|
|
29
33
|
_BinderRoot_context.set(this, this);
|
|
30
|
-
|
|
34
|
+
if (!(modelClass instanceof Model)) {
|
|
35
|
+
this.model[$owner] = this;
|
|
36
|
+
}
|
|
31
37
|
__classPrivateFieldSet(this, _BinderRoot_context, config?.context ?? this, "f");
|
|
32
38
|
__classPrivateFieldSet(this, _BinderRoot_config, config, "f");
|
|
33
39
|
this.initializeValue(true);
|