@strictly/react-form 0.0.10 → 0.0.11
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/.out/core/mobx/field_adapter_builder.js +18 -6
- package/.out/core/mobx/form_presenter.js +224 -121
- package/.out/core/mobx/hooks.js +2 -2
- package/.out/core/mobx/merge_field_adapters_with_validators.js +1 -5
- package/.out/core/mobx/specs/fixtures.js +2 -1
- package/.out/core/mobx/specs/form_presenter.tests.js +6 -3
- package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +2 -1
- package/.out/field_converters/integer_to_string_converter.js +12 -4
- package/.out/field_converters/maybe_identity_converter.js +12 -4
- package/.out/field_converters/nullable_to_boolean_converter.js +24 -7
- package/.out/field_converters/select_value_type_converter.js +36 -12
- package/.out/mantine/create_checkbox.js +8 -4
- package/.out/mantine/create_fields_view.js +7 -4
- package/.out/mantine/create_form.js +1 -1
- package/.out/mantine/create_radio_group.js +8 -4
- package/.out/mantine/create_text_input.js +8 -4
- package/.out/mantine/create_value_input.js +8 -4
- package/.out/mantine/hooks.js +218 -92
- package/.out/mantine/specs/checkbox_hooks.stories.js +13 -1
- package/.out/mantine/specs/checkbox_hooks.tests.js +22 -9
- package/.out/mantine/specs/fields_view_hooks.stories.js +15 -2
- package/.out/mantine/specs/fields_view_hooks.tests.js +12 -3
- package/.out/mantine/specs/radio_group_hooks.stories.js +13 -1
- package/.out/mantine/specs/radio_group_hooks.tests.js +23 -10
- package/.out/mantine/specs/select_hooks.stories.js +13 -1
- package/.out/mantine/specs/text_input_hooks.stories.js +13 -1
- package/.out/mantine/specs/text_input_hooks.tests.js +18 -7
- package/.out/mantine/specs/value_input_hooks.stories.js +14 -2
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/tsup.config.js +2 -9
- package/.out/types/merge_validators.js +1 -4
- package/.out/util/partial.js +5 -5
- package/.out/vitest.workspace.js +2 -10
- package/.turbo/turbo-build.log +7 -7
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/core/mobx/hooks.tsx +1 -0
- package/dist/index.cjs +182 -100
- package/dist/index.js +186 -100
- package/package.json +1 -1
|
@@ -5,13 +5,25 @@ import { TrimmingStringConverter } from 'field_converters/trimming_string_conver
|
|
|
5
5
|
import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_field_value_factory';
|
|
6
6
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
7
7
|
class FieldAdapterBuilder {
|
|
8
|
-
convert;
|
|
9
|
-
create;
|
|
10
|
-
revert;
|
|
11
8
|
constructor(convert, create, revert) {
|
|
12
|
-
this
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
Object.defineProperty(this, "convert", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: convert
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "create", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: create
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "revert", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: revert
|
|
26
|
+
});
|
|
15
27
|
}
|
|
16
28
|
chain(converter, reverter) {
|
|
17
29
|
return new FieldAdapterBuilder(chainAnnotatedFieldConverter(this.convert, converter), this.create, this.revert && reverter && chainUnreliableFieldConverter(reverter, this.revert));
|
|
@@ -1,13 +1,66 @@
|
|
|
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
|
+
};
|
|
1
46
|
import { assertExists, assertExistsAndReturn, assertState, checkValidNumber, map, toArray, UnreachableError, } from '@strictly/base';
|
|
2
47
|
import { flattenAccessorsOfType, flattenTypesOfType, flattenValuesOfType, flattenValueTo, jsonPathPop, mobxCopy, valuePathToTypePath, } from '@strictly/define';
|
|
3
48
|
import { computed, observable, runInAction, } from 'mobx';
|
|
4
49
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
5
50
|
export class FormPresenter {
|
|
6
|
-
type;
|
|
7
|
-
adapters;
|
|
8
51
|
constructor(type, adapters) {
|
|
9
|
-
this
|
|
10
|
-
|
|
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
|
+
});
|
|
11
64
|
}
|
|
12
65
|
maybeGetAdapterForValuePath(valuePath) {
|
|
13
66
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
@@ -34,7 +87,7 @@ export class FormPresenter {
|
|
|
34
87
|
const listValuePath = valuePath;
|
|
35
88
|
const accessor = model.accessors[valuePath];
|
|
36
89
|
const listTypePath = this.typePath(valuePath);
|
|
37
|
-
const definedIndex = index
|
|
90
|
+
const definedIndex = index !== null && index !== void 0 ? index : accessor.value.length;
|
|
38
91
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
39
92
|
const elementTypePath = `${listTypePath}.*`;
|
|
40
93
|
const elementAdapter = assertExistsAndReturn(this.adapters[elementTypePath], 'no adapter specified for list {} ({})', elementTypePath, valuePath);
|
|
@@ -165,7 +218,7 @@ export class FormPresenter {
|
|
|
165
218
|
return false;
|
|
166
219
|
case UnreliableFieldConversionType.Success:
|
|
167
220
|
delete model.errors[valuePath];
|
|
168
|
-
accessor
|
|
221
|
+
accessor === null || accessor === void 0 ? void 0 : accessor.set(conversion.value);
|
|
169
222
|
return true;
|
|
170
223
|
default:
|
|
171
224
|
throw new UnreachableError(conversion);
|
|
@@ -299,124 +352,174 @@ export class FormPresenter {
|
|
|
299
352
|
});
|
|
300
353
|
}
|
|
301
354
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
+
});
|
|
324
421
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
+
});
|
|
329
436
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return field;
|
|
345
|
-
}
|
|
346
|
-
if (typeof prop === 'string') {
|
|
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 {
|
|
347
451
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
348
|
-
|
|
452
|
+
typePath = valuePathToTypePath(this.type,
|
|
453
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
454
|
+
valuePath, true);
|
|
349
455
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
try {
|
|
368
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
369
|
-
typePath = valuePathToTypePath(this.type,
|
|
370
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
371
|
-
valuePath, true);
|
|
372
|
-
}
|
|
373
|
-
catch (e) {
|
|
374
|
-
// TODO make jsonValuePathToTypePath return null in the event of an invalid
|
|
375
|
-
// value path instead of throwing an exception
|
|
376
|
-
// assume that the path was invalid
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
return this.synthesizeFieldByPaths(valuePath, typePath);
|
|
380
|
-
}
|
|
381
|
-
synthesizeFieldByPaths(valuePath, typePath) {
|
|
382
|
-
const adapter = this.adapters[typePath];
|
|
383
|
-
if (adapter == null) {
|
|
384
|
-
// invalid path, which can happen
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
const { convert, create, } = adapter;
|
|
388
|
-
const fieldOverride = this.fieldOverrides[valuePath];
|
|
389
|
-
const accessor = this.getAccessorForValuePath(valuePath);
|
|
390
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
391
|
-
const fieldTypeDef = this.flattenedTypeDefs[typePath];
|
|
392
|
-
const { value, required, readonly, } = convert(accessor != null
|
|
393
|
-
? accessor.value
|
|
394
|
-
: fieldTypeDef != null
|
|
395
|
-
? mobxCopy(fieldTypeDef,
|
|
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);
|
|
396
473
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
397
|
-
|
|
398
|
-
|
|
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),
|
|
399
484
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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 };
|
package/.out/core/mobx/hooks.js
CHANGED
|
@@ -17,7 +17,7 @@ export function useDefaultMobxFormHooks(presenter, value, { onValidFieldSubmit,
|
|
|
17
17
|
]);
|
|
18
18
|
const onFieldSubmit = useCallback(function (valuePath) {
|
|
19
19
|
if (presenter.validateField(model, valuePath)) {
|
|
20
|
-
onValidFieldSubmit
|
|
20
|
+
onValidFieldSubmit === null || onValidFieldSubmit === void 0 ? void 0 : onValidFieldSubmit(model, valuePath);
|
|
21
21
|
}
|
|
22
22
|
return false;
|
|
23
23
|
}, [
|
|
@@ -40,7 +40,7 @@ export function useDefaultMobxFormHooks(presenter, value, { onValidFieldSubmit,
|
|
|
40
40
|
]);
|
|
41
41
|
const onFormSubmit = useCallback(function () {
|
|
42
42
|
if (presenter.validateAll(model)) {
|
|
43
|
-
onValidFormSubmit
|
|
43
|
+
onValidFormSubmit === null || onValidFormSubmit === void 0 ? void 0 : onValidFormSubmit(model, model.value);
|
|
44
44
|
}
|
|
45
45
|
}, [
|
|
46
46
|
presenter,
|
|
@@ -35,11 +35,7 @@ export function mergeAdaptersWithValidators(adapters, validators) {
|
|
|
35
35
|
readonly: readonly1 || readonly2,
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
acc[key] = {
|
|
39
|
-
...adapter,
|
|
40
|
-
convert,
|
|
41
|
-
revert: adapter.revert && revert,
|
|
42
|
-
};
|
|
38
|
+
acc[key] = Object.assign(Object.assign({}, adapter), { convert, revert: adapter.revert && revert });
|
|
43
39
|
return acc;
|
|
44
40
|
}, {});
|
|
45
41
|
}
|
|
@@ -3,9 +3,10 @@ export function createMockedAdapter(_original) {
|
|
|
3
3
|
return mock();
|
|
4
4
|
}
|
|
5
5
|
export function resetMockAdapter({ convert, revert, create, }, mockedAdapter) {
|
|
6
|
+
var _a;
|
|
6
7
|
mockReset(mockedAdapter);
|
|
7
8
|
if (revert) {
|
|
8
|
-
mockedAdapter.revert
|
|
9
|
+
(_a = mockedAdapter.revert) === null || _a === void 0 ? void 0 : _a.mockImplementation(revert);
|
|
9
10
|
}
|
|
10
11
|
mockedAdapter.convert.mockImplementation(convert);
|
|
11
12
|
mockedAdapter.create.mockImplementation(create);
|
|
@@ -335,7 +335,8 @@ describe('all', function () {
|
|
|
335
335
|
const newValue = -1;
|
|
336
336
|
const errorCode = 65;
|
|
337
337
|
beforeEach(function () {
|
|
338
|
-
|
|
338
|
+
var _a;
|
|
339
|
+
(_a = integerToStringAdapter.revert) === null || _a === void 0 ? void 0 : _a.mockReturnValueOnce({
|
|
339
340
|
type: UnreliableFieldConversionType.Failure,
|
|
340
341
|
error: errorCode,
|
|
341
342
|
value: [newValue],
|
|
@@ -548,7 +549,8 @@ describe('all', function () {
|
|
|
548
549
|
'7',
|
|
549
550
|
],
|
|
550
551
|
])('it reports the value of field %s as %s', function (path, fieldValue) {
|
|
551
|
-
|
|
552
|
+
var _a;
|
|
553
|
+
expect((_a = model.fields[path]) === null || _a === void 0 ? void 0 : _a.value).toBe(fieldValue);
|
|
552
554
|
});
|
|
553
555
|
it.each([
|
|
554
556
|
[
|
|
@@ -568,7 +570,8 @@ describe('all', function () {
|
|
|
568
570
|
2,
|
|
569
571
|
],
|
|
570
572
|
])('it reports the error of field %s', function (path, error) {
|
|
571
|
-
|
|
573
|
+
var _a;
|
|
574
|
+
expect((_a = model.fields[path]) === null || _a === void 0 ? void 0 : _a.error).toBe(error);
|
|
572
575
|
});
|
|
573
576
|
});
|
|
574
577
|
describe('add defined value', function () {
|
|
@@ -43,12 +43,13 @@ describe('subFormFieldAdapters', () => {
|
|
|
43
43
|
expect(returnedValue).toEqual(mockedReturnedValue);
|
|
44
44
|
});
|
|
45
45
|
it('calls revert with the correct paths and values', () => {
|
|
46
|
+
var _a, _b;
|
|
46
47
|
const mockedReturnedValue = {
|
|
47
48
|
type: UnreliableFieldConversionType.Success,
|
|
48
49
|
value: 'ok',
|
|
49
50
|
};
|
|
50
51
|
mockedFieldAdapter1.revert.mockReturnValue(mockedReturnedValue);
|
|
51
|
-
const returnedValue = adapters['$.a'].revert
|
|
52
|
+
const returnedValue = (_b = (_a = adapters['$.a']).revert) === null || _b === void 0 ? void 0 : _b.call(_a, true, '$.a', { a: 'y' });
|
|
52
53
|
expect(fieldAdapter1.revert).toHaveBeenCalledWith(true, '$', 'y');
|
|
53
54
|
expect(returnedValue).toEqual(mockedReturnedValue);
|
|
54
55
|
});
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
2
2
|
export class IntegerToStringConverter {
|
|
3
|
-
isNanError;
|
|
4
|
-
base;
|
|
5
3
|
constructor(isNanError, base = 10) {
|
|
6
|
-
this
|
|
7
|
-
|
|
4
|
+
Object.defineProperty(this, "isNanError", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: isNanError
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(this, "base", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: base
|
|
15
|
+
});
|
|
8
16
|
}
|
|
9
17
|
convert(from) {
|
|
10
18
|
const value = Math.floor(from).toString();
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
export class MaybeIdentityConverter {
|
|
2
|
-
converter;
|
|
3
|
-
isFrom;
|
|
4
2
|
constructor(converter, isFrom) {
|
|
5
|
-
this
|
|
6
|
-
|
|
3
|
+
Object.defineProperty(this, "converter", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: converter
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "isFrom", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: isFrom
|
|
14
|
+
});
|
|
7
15
|
}
|
|
8
16
|
convert(from, valuePath, context) {
|
|
9
17
|
return this.converter.convert(from, valuePath, context);
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import { copy, } from '@strictly/define';
|
|
2
2
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
3
3
|
export class NullableToBooleanConverter {
|
|
4
|
-
typeDef;
|
|
5
|
-
prototype;
|
|
6
|
-
nullType;
|
|
7
|
-
defaultValue;
|
|
8
4
|
constructor(typeDef, prototype, nullType, defaultToNull = true) {
|
|
9
|
-
this
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Object.defineProperty(this, "typeDef", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: typeDef
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "prototype", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: prototype
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "nullType", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: nullType
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "defaultValue", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
12
29
|
this.defaultValue = defaultToNull ? this.nullType : prototype;
|
|
13
30
|
}
|
|
14
31
|
convert(from) {
|