@strictly/react-form 0.0.11 → 0.0.13

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/index.ts CHANGED
@@ -3,7 +3,7 @@ export * from './core/mobx/field_adapter_builder'
3
3
  export * from './core/mobx/field_adapters_of_values'
4
4
  export * from './core/mobx/flattened_adapters_of_fields'
5
5
  export * from './core/mobx/form_fields_of_field_adapters'
6
- export * from './core/mobx/form_presenter'
6
+ export * from './core/mobx/form_model'
7
7
  export * from './core/mobx/hooks'
8
8
  export * from './core/mobx/merge_field_adapters_with_two_way_converter'
9
9
  export * from './core/mobx/merge_field_adapters_with_validators'
@@ -1,4 +1,8 @@
1
1
  import { type StringConcatOf } from '@strictly/base'
2
+ import {
3
+ jsonPathPrefix,
4
+ jsonPathUnprefix,
5
+ } from '@strictly/define'
2
6
  import type { FieldsViewProps } from 'core/props'
3
7
  import { observer } from 'mobx-react'
4
8
  import type {
@@ -42,12 +46,12 @@ export function createFieldsView<
42
46
  ): FieldsView<K, MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>> {
43
47
  function toKey(subKey: string | number | symbol): string {
44
48
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
45
- return (subKey as string).replace('$', valuePath as string)
49
+ return jsonPathPrefix(valuePath, subKey as string)
46
50
  }
47
51
 
48
52
  function toSubKey(key: string | number | symbol): string {
49
53
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
50
- return (key as string).replace(valuePath as string, '$')
54
+ return jsonPathUnprefix(valuePath, key as string)
51
55
  }
52
56
 
53
57
  function onFieldValueChange<SubK extends keyof P['fields']>(
package/mantine/hooks.tsx CHANGED
@@ -431,4 +431,6 @@ class MantineFormImpl<
431
431
  this,
432
432
  ) as unknown as MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>
433
433
  }
434
+
435
+ // TODO have an option to bind to a Text/(value: T) => JSX.Element for viewing form fields
434
436
  }
package/package.json CHANGED
@@ -70,7 +70,7 @@
70
70
  "test:watch": "vitest"
71
71
  },
72
72
  "type": "module",
73
- "version": "0.0.11",
73
+ "version": "0.0.13",
74
74
  "exports": {
75
75
  ".": {
76
76
  "import": {
@@ -1,525 +0,0 @@
1
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
2
- var useValue = arguments.length > 2;
3
- for (var i = 0; i < initializers.length; i++) {
4
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
5
- }
6
- return useValue ? value : void 0;
7
- };
8
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
9
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
10
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
11
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
12
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
13
- var _, done = false;
14
- for (var i = decorators.length - 1; i >= 0; i--) {
15
- var context = {};
16
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
17
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
18
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
19
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
20
- if (kind === "accessor") {
21
- if (result === void 0) continue;
22
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
23
- if (_ = accept(result.get)) descriptor.get = _;
24
- if (_ = accept(result.set)) descriptor.set = _;
25
- if (_ = accept(result.init)) initializers.unshift(_);
26
- }
27
- else if (_ = accept(result)) {
28
- if (kind === "field") initializers.unshift(_);
29
- else descriptor[key] = _;
30
- }
31
- }
32
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
33
- done = true;
34
- };
35
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
36
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
37
- 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");
38
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
39
- };
40
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
41
- if (kind === "m") throw new TypeError("Private method is not writable");
42
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
43
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
44
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
45
- };
46
- import { assertExists, assertExistsAndReturn, assertState, checkValidNumber, map, toArray, UnreachableError, } from '@strictly/base';
47
- import { flattenAccessorsOfType, flattenTypesOfType, flattenValuesOfType, flattenValueTo, jsonPathPop, mobxCopy, valuePathToTypePath, } from '@strictly/define';
48
- import { computed, observable, runInAction, } from 'mobx';
49
- import { UnreliableFieldConversionType, } from 'types/field_converters';
50
- export class FormPresenter {
51
- constructor(type, adapters) {
52
- Object.defineProperty(this, "type", {
53
- enumerable: true,
54
- configurable: true,
55
- writable: true,
56
- value: type
57
- });
58
- Object.defineProperty(this, "adapters", {
59
- enumerable: true,
60
- configurable: true,
61
- writable: true,
62
- value: adapters
63
- });
64
- }
65
- maybeGetAdapterForValuePath(valuePath) {
66
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
67
- const typePath = valuePathToTypePath(this.type, valuePath, true);
68
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
69
- return this.adapters[typePath];
70
- }
71
- getAdapterForValuePath(valuePath) {
72
- return assertExistsAndReturn(this.maybeGetAdapterForValuePath(valuePath), 'expected adapter to be defined {}', valuePath);
73
- }
74
- typePath(valuePath) {
75
- return valuePathToTypePath(this.type, valuePath, true);
76
- }
77
- setFieldValueAndValidate(model, valuePath, value) {
78
- return this.internalSetFieldValue(model, valuePath, value, true);
79
- }
80
- setFieldValue(model, valuePath, value) {
81
- return this.internalSetFieldValue(model, valuePath, value, false);
82
- }
83
- addListItem(model, valuePath,
84
- // TODO can this type be simplified?
85
- elementValue = null, index) {
86
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
87
- const listValuePath = valuePath;
88
- const accessor = model.accessors[valuePath];
89
- const listTypePath = this.typePath(valuePath);
90
- const definedIndex = index !== null && index !== void 0 ? index : accessor.value.length;
91
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
92
- const elementTypePath = `${listTypePath}.*`;
93
- const elementAdapter = assertExistsAndReturn(this.adapters[elementTypePath], 'no adapter specified for list {} ({})', elementTypePath, valuePath);
94
- // TODO validation on new elements
95
- const element = elementValue != null
96
- ? elementValue[0]
97
- : elementAdapter.create(
98
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
99
- elementTypePath, model.value);
100
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
- const originalList = accessor.value;
102
- const newList = [
103
- ...originalList.slice(0, definedIndex),
104
- element,
105
- ...originalList.slice(definedIndex),
106
- ];
107
- // shuffle the overrides around to account for new indices
108
- // to so this we need to sort the array indices in descending order
109
- const targetPaths = Object.keys(model.fieldOverrides).filter(function (v) {
110
- return v.startsWith(`${listValuePath}.`);
111
- }).map(function (v) {
112
- const parts = v.substring(listValuePath.length + 1).split('.');
113
- const index = parseInt(parts[0]);
114
- return [
115
- index,
116
- parts.slice(1),
117
- ];
118
- }).filter(function ([index]) {
119
- return index >= definedIndex;
120
- }).sort(function ([a], [b]) {
121
- // descending
122
- return b - a;
123
- });
124
- runInAction(function () {
125
- targetPaths.forEach(function ([index, postfix,]) {
126
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
127
- const fromJsonPath = [
128
- listValuePath,
129
- `${index}`,
130
- ...postfix,
131
- ].join('.');
132
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
133
- const toJsonPath = [
134
- listValuePath,
135
- `${index + 1}`,
136
- ...postfix,
137
- ].join('.');
138
- const fieldOverride = model.fieldOverrides[fromJsonPath];
139
- delete model.fieldOverrides[fromJsonPath];
140
- model.fieldOverrides[toJsonPath] = fieldOverride;
141
- const error = model.errors[fromJsonPath];
142
- delete model.errors[fromJsonPath];
143
- model.errors[toJsonPath] = error;
144
- });
145
- accessor.set(newList);
146
- // delete any value overrides so the new list isn't shadowed
147
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
148
- delete model.fieldOverrides[listValuePath];
149
- });
150
- }
151
- removeListItem(model, elementValuePath) {
152
- const [listValuePath, elementIndexString,] = assertExistsAndReturn(jsonPathPop(elementValuePath), 'expected a path with two or more segments {}', elementValuePath);
153
- const accessor = model.accessors[listValuePath];
154
- const elementIndex = checkValidNumber(parseInt(elementIndexString), 'unexpected index {} ({})', elementIndexString, elementValuePath);
155
- const newList = [...accessor.value];
156
- assertState(elementIndex >= 0 && elementIndex < newList.length, 'invalid index from path {} ({})', elementIndex, elementValuePath);
157
- newList.splice(elementIndex, 1);
158
- // shuffle the overrides around to account for new indices
159
- // to so this we need to sort the array indices in descending order
160
- const targetPaths = Object.keys(model.fieldOverrides).filter(function (v) {
161
- return v.startsWith(`${listValuePath}.`);
162
- }).map(function (v) {
163
- const parts = v.substring(listValuePath.length + 1).split('.');
164
- const index = parseInt(parts[0]);
165
- return [
166
- index,
167
- parts.slice(1),
168
- ];
169
- }).filter(function ([index]) {
170
- return index > elementIndex;
171
- }).sort(function ([a], [b]) {
172
- // ascending
173
- return a - b;
174
- });
175
- runInAction(function () {
176
- targetPaths.forEach(function ([index, postfix,]) {
177
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
178
- const fromJsonPath = [
179
- listValuePath,
180
- `${index}`,
181
- ...postfix,
182
- ].join('.');
183
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
184
- const toJsonPath = [
185
- listValuePath,
186
- `${index - 1}`,
187
- ...postfix,
188
- ].join('.');
189
- const fieldOverride = model.fieldOverrides[fromJsonPath];
190
- delete model.fieldOverrides[fromJsonPath];
191
- model.fieldOverrides[toJsonPath] = fieldOverride;
192
- const error = model.errors[fromJsonPath];
193
- delete model.errors[fromJsonPath];
194
- model.errors[toJsonPath] = error;
195
- });
196
- accessor.set(newList);
197
- // delete any value overrides so the new list isn't shadowed
198
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
199
- delete model.fieldOverrides[listValuePath];
200
- });
201
- }
202
- internalSetFieldValue(model, valuePath, value, displayValidation) {
203
- const { revert } = this.getAdapterForValuePath(valuePath);
204
- assertExists(revert, 'setting value not supported {}', valuePath);
205
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
206
- const conversion = revert(value, valuePath, model.value);
207
- const accessor = model.getAccessorForValuePath(valuePath);
208
- return runInAction(() => {
209
- model.fieldOverrides[valuePath] = [value];
210
- switch (conversion.type) {
211
- case UnreliableFieldConversionType.Failure:
212
- if (displayValidation) {
213
- model.errors[valuePath] = conversion.error;
214
- }
215
- if (conversion.value != null && accessor != null) {
216
- accessor.set(conversion.value[0]);
217
- }
218
- return false;
219
- case UnreliableFieldConversionType.Success:
220
- delete model.errors[valuePath];
221
- accessor === null || accessor === void 0 ? void 0 : accessor.set(conversion.value);
222
- return true;
223
- default:
224
- throw new UnreachableError(conversion);
225
- }
226
- });
227
- }
228
- clearFieldError(model, valuePath) {
229
- const fieldOverride = model.fieldOverrides[valuePath];
230
- if (fieldOverride != null) {
231
- runInAction(function () {
232
- delete model.errors[valuePath];
233
- });
234
- }
235
- }
236
- clearFieldValue(model, valuePath) {
237
- const typePath = this.typePath(valuePath);
238
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
239
- const adapter = this.adapters[typePath];
240
- if (adapter == null) {
241
- return;
242
- }
243
- const { convert, create, } = adapter;
244
- const value = create(valuePath, model.value);
245
- const { value: displayValue, } = convert(value, valuePath, model.value);
246
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
247
- const key = valuePath;
248
- runInAction(function () {
249
- model.fieldOverrides[key] = [displayValue];
250
- });
251
- }
252
- clearAll(model, value) {
253
- runInAction(() => {
254
- model.errors = {};
255
- // TODO this isn't correct, should reload from value
256
- model.fieldOverrides = {};
257
- model.value = mobxCopy(this.type, value);
258
- });
259
- }
260
- isValuePathActive(model, valuePath) {
261
- const values = flattenValuesOfType(this.type, model.value);
262
- const keys = new Set(Object.keys(values));
263
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
264
- return keys.has(valuePath);
265
- }
266
- validateField(model, valuePath, ignoreDefaultValue = false) {
267
- const { convert, revert, create, } = this.getAdapterForValuePath(valuePath);
268
- const fieldOverride = model.fieldOverrides[valuePath];
269
- const accessor = model.getAccessorForValuePath(valuePath);
270
- const { value: storedValue, } = convert(accessor != null
271
- ? accessor.value
272
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
273
- : create(valuePath, model.value),
274
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
275
- valuePath, model.value);
276
- const value = fieldOverride != null
277
- ? fieldOverride[0]
278
- : storedValue;
279
- const dirty = storedValue !== value;
280
- assertExists(revert, 'changing field directly not supported {}', valuePath);
281
- if (ignoreDefaultValue) {
282
- const { value: defaultDisplayValue, } = convert(create(valuePath, model.value), valuePath, model.value);
283
- if (defaultDisplayValue === value) {
284
- return true;
285
- }
286
- }
287
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
288
- const conversion = revert(value, valuePath, model.value);
289
- return runInAction(function () {
290
- switch (conversion.type) {
291
- case UnreliableFieldConversionType.Failure:
292
- model.errors[valuePath] = conversion.error;
293
- if (conversion.value != null && accessor != null && dirty) {
294
- accessor.set(conversion.value[0]);
295
- }
296
- return false;
297
- case UnreliableFieldConversionType.Success:
298
- delete model.errors[valuePath];
299
- if (accessor != null && dirty) {
300
- accessor.set(conversion.value);
301
- }
302
- return true;
303
- default:
304
- throw new UnreachableError(conversion);
305
- }
306
- });
307
- }
308
- validateAll(model) {
309
- // sort keys shortest to longest so parent changes don't overwrite child changes
310
- const accessors = toArray(model.accessors).toSorted(function ([a], [b]) {
311
- return a.length - b.length;
312
- });
313
- return runInAction(() => {
314
- return accessors.reduce((success, [valuePath, accessor,]) => {
315
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
316
- const adapterPath = valuePath;
317
- const adapter = this.maybeGetAdapterForValuePath(adapterPath);
318
- if (adapter == null) {
319
- // no adapter == there should be nothing specified for this field
320
- return success;
321
- }
322
- const { convert, revert, } = adapter;
323
- if (revert == null) {
324
- // no convert method means this field is immutable
325
- return success;
326
- }
327
- const fieldOverride = model.fieldOverrides[adapterPath];
328
- const { value: storedValue, } = convert(accessor.value, valuePath, model.value);
329
- const value = fieldOverride != null
330
- ? fieldOverride[0]
331
- : storedValue;
332
- // TODO more nuanced comparison
333
- const dirty = fieldOverride != null && fieldOverride[0] !== storedValue;
334
- const conversion = revert(value, valuePath, model.value);
335
- switch (conversion.type) {
336
- case UnreliableFieldConversionType.Failure:
337
- model.errors[adapterPath] = conversion.error;
338
- if (conversion.value != null && dirty) {
339
- accessor.set(conversion.value[0]);
340
- }
341
- return false;
342
- case UnreliableFieldConversionType.Success:
343
- if (dirty) {
344
- accessor.set(conversion.value);
345
- }
346
- delete model.errors[adapterPath];
347
- return success;
348
- default:
349
- throw new UnreachableError(conversion);
350
- }
351
- }, true);
352
- });
353
- }
354
- }
355
- let FormModel = (() => {
356
- var _a, _FormModel_value_accessor_storage, _FormModel_fieldOverrides_accessor_storage, _FormModel_errors_accessor_storage;
357
- var _b, _c, _d;
358
- let _instanceExtraInitializers = [];
359
- let _value_decorators;
360
- let _value_initializers = [];
361
- let _value_extraInitializers = [];
362
- let _fieldOverrides_decorators;
363
- let _fieldOverrides_initializers = [];
364
- let _fieldOverrides_extraInitializers = [];
365
- let _errors_decorators;
366
- let _errors_initializers = [];
367
- let _errors_extraInitializers = [];
368
- let _get_fields_decorators;
369
- let _get_knownFields_decorators;
370
- let _get_accessors_decorators;
371
- return _a = class FormModel {
372
- get value() { return __classPrivateFieldGet(this, _FormModel_value_accessor_storage, "f"); }
373
- set value(value) { __classPrivateFieldSet(this, _FormModel_value_accessor_storage, value, "f"); }
374
- get fieldOverrides() { return __classPrivateFieldGet(this, _FormModel_fieldOverrides_accessor_storage, "f"); }
375
- set fieldOverrides(value) { __classPrivateFieldSet(this, _FormModel_fieldOverrides_accessor_storage, value, "f"); }
376
- get errors() { return __classPrivateFieldGet(this, _FormModel_errors_accessor_storage, "f"); }
377
- set errors(value) { __classPrivateFieldSet(this, _FormModel_errors_accessor_storage, value, "f"); }
378
- constructor(type, value, adapters) {
379
- Object.defineProperty(this, "type", {
380
- enumerable: true,
381
- configurable: true,
382
- writable: true,
383
- value: (__runInitializers(this, _instanceExtraInitializers), type)
384
- });
385
- Object.defineProperty(this, "adapters", {
386
- enumerable: true,
387
- configurable: true,
388
- writable: true,
389
- value: adapters
390
- });
391
- _FormModel_value_accessor_storage.set(this, __runInitializers(this, _value_initializers, void 0));
392
- _FormModel_fieldOverrides_accessor_storage.set(this, (__runInitializers(this, _value_extraInitializers), __runInitializers(this, _fieldOverrides_initializers, void 0)));
393
- _FormModel_errors_accessor_storage.set(this, (__runInitializers(this, _fieldOverrides_extraInitializers), __runInitializers(this, _errors_initializers, {})));
394
- Object.defineProperty(this, "flattenedTypeDefs", {
395
- enumerable: true,
396
- configurable: true,
397
- writable: true,
398
- value: __runInitializers(this, _errors_extraInitializers)
399
- });
400
- this.value = mobxCopy(type, value);
401
- this.flattenedTypeDefs = flattenTypesOfType(type);
402
- // pre-populate field overrides for consistent behavior when default information is overwritten
403
- // then returned to
404
- const conversions = flattenValueTo(type, this.value, () => { }, (_t, value, _setter, typePath, valuePath) => {
405
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
406
- const adapter = this.adapters[typePath];
407
- if (adapter == null) {
408
- return;
409
- }
410
- const { convert, revert, } = adapter;
411
- if (revert == null) {
412
- // no need to store a temporary value if the value cannot be written back
413
- return;
414
- }
415
- return convert(value, valuePath, this.value);
416
- });
417
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
418
- this.fieldOverrides = map(conversions, function (_k, v) {
419
- return v && [v.value];
420
- });
421
- }
422
- get fields() {
423
- return new Proxy(this.knownFields, {
424
- get: (target, prop) => {
425
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
426
- const field = target[prop];
427
- if (field != null) {
428
- return field;
429
- }
430
- if (typeof prop === 'string') {
431
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
432
- return this.maybeSynthesizeFieldByValuePath(prop);
433
- }
434
- },
435
- });
436
- }
437
- get knownFields() {
438
- return flattenValueTo(this.type, this.value, () => { },
439
- // TODO swap these to valuePath, typePath in flatten
440
- (_t, _v, _setter, typePath, valuePath) => {
441
- return this.synthesizeFieldByPaths(
442
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
443
- valuePath,
444
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
445
- typePath);
446
- });
447
- }
448
- maybeSynthesizeFieldByValuePath(valuePath) {
449
- let typePath;
450
- try {
451
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
452
- typePath = valuePathToTypePath(this.type,
453
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
454
- valuePath, true);
455
- }
456
- catch (e) {
457
- // TODO make jsonValuePathToTypePath return null in the event of an invalid
458
- // value path instead of throwing an exception
459
- // assume that the path was invalid
460
- return;
461
- }
462
- return this.synthesizeFieldByPaths(valuePath, typePath);
463
- }
464
- synthesizeFieldByPaths(valuePath, typePath) {
465
- const adapter = this.adapters[typePath];
466
- if (adapter == null) {
467
- // invalid path, which can happen
468
- return;
469
- }
470
- const { convert, create, } = adapter;
471
- const fieldOverride = this.fieldOverrides[valuePath];
472
- const accessor = this.getAccessorForValuePath(valuePath);
473
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
474
- const fieldTypeDef = this.flattenedTypeDefs[typePath];
475
- const { value, required, readonly, } = convert(accessor != null
476
- ? accessor.value
477
- : fieldTypeDef != null
478
- ? mobxCopy(fieldTypeDef,
479
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
480
- create(valuePath, this.value))
481
- // fake values can't be copied
482
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
483
- : create(valuePath, this.value),
484
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
485
- valuePath, this.value);
486
- const error = this.errors[valuePath];
487
- return {
488
- value: fieldOverride != null ? fieldOverride[0] : value,
489
- error,
490
- readonly,
491
- required,
492
- };
493
- }
494
- getAccessorForValuePath(valuePath) {
495
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
496
- return this.accessors[valuePath];
497
- }
498
- get accessors() {
499
- return flattenAccessorsOfType(this.type, this.value, (value) => {
500
- this.value = mobxCopy(this.type, value);
501
- });
502
- }
503
- },
504
- _FormModel_value_accessor_storage = new WeakMap(),
505
- _FormModel_fieldOverrides_accessor_storage = new WeakMap(),
506
- _FormModel_errors_accessor_storage = new WeakMap(),
507
- (() => {
508
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
509
- _value_decorators = [(_b = observable).ref.bind(_b)];
510
- _fieldOverrides_decorators = [(_c = observable).shallow.bind(_c)];
511
- _errors_decorators = [(_d = observable).shallow.bind(_d)];
512
- _get_fields_decorators = [computed];
513
- _get_knownFields_decorators = [computed];
514
- _get_accessors_decorators = [computed];
515
- __esDecorate(_a, null, _value_decorators, { kind: "accessor", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value, set: (obj, value) => { obj.value = value; } }, metadata: _metadata }, _value_initializers, _value_extraInitializers);
516
- __esDecorate(_a, null, _fieldOverrides_decorators, { kind: "accessor", name: "fieldOverrides", static: false, private: false, access: { has: obj => "fieldOverrides" in obj, get: obj => obj.fieldOverrides, set: (obj, value) => { obj.fieldOverrides = value; } }, metadata: _metadata }, _fieldOverrides_initializers, _fieldOverrides_extraInitializers);
517
- __esDecorate(_a, null, _errors_decorators, { kind: "accessor", name: "errors", static: false, private: false, access: { has: obj => "errors" in obj, get: obj => obj.errors, set: (obj, value) => { obj.errors = value; } }, metadata: _metadata }, _errors_initializers, _errors_extraInitializers);
518
- __esDecorate(_a, null, _get_fields_decorators, { kind: "getter", name: "fields", static: false, private: false, access: { has: obj => "fields" in obj, get: obj => obj.fields }, metadata: _metadata }, null, _instanceExtraInitializers);
519
- __esDecorate(_a, null, _get_knownFields_decorators, { kind: "getter", name: "knownFields", static: false, private: false, access: { has: obj => "knownFields" in obj, get: obj => obj.knownFields }, metadata: _metadata }, null, _instanceExtraInitializers);
520
- __esDecorate(_a, null, _get_accessors_decorators, { kind: "getter", name: "accessors", static: false, private: false, access: { has: obj => "accessors" in obj, get: obj => obj.accessors }, metadata: _metadata }, null, _instanceExtraInitializers);
521
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
522
- })(),
523
- _a;
524
- })();
525
- export { FormModel };