@strictly/react-form 0.0.10 → 0.0.12
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.d.ts → form_model.d.ts} +15 -21
- package/.out/core/mobx/form_model.js +513 -0
- package/.out/core/mobx/hooks.d.ts +6 -25
- package/.out/core/mobx/hooks.js +14 -50
- 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 → form_model.tests.js} +52 -43
- package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +2 -1
- package/.out/core/mobx/types.d.ts +4 -4
- 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/index.d.ts +1 -1
- package/.out/index.js +1 -1
- 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 +9 -9
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/core/mobx/{form_presenter.ts → form_model.ts} +287 -329
- package/core/mobx/hooks.tsx +26 -123
- package/core/mobx/specs/{form_presenter.tests.ts → form_model.tests.ts} +101 -94
- package/core/mobx/types.ts +12 -12
- package/dist/index.cjs +639 -600
- package/dist/index.d.cts +51 -73
- package/dist/index.d.ts +51 -73
- package/dist/index.js +644 -601
- package/index.ts +1 -1
- package/mantine/hooks.tsx +2 -0
- package/package.json +1 -1
- package/.out/core/mobx/form_presenter.js +0 -422
- /package/.out/core/mobx/specs/{form_presenter.tests.d.ts → form_model.tests.d.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
3
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
12
|
+
var __typeError = (msg) => {
|
|
13
|
+
throw TypeError(msg);
|
|
14
|
+
};
|
|
15
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __spreadValues = (a, b) => {
|
|
17
|
+
for (var prop in b || (b = {}))
|
|
18
|
+
if (__hasOwnProp.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop))
|
|
23
|
+
__defNormalProp(a, prop, b[prop]);
|
|
24
|
+
}
|
|
25
|
+
return a;
|
|
26
|
+
};
|
|
27
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
28
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
29
|
var __export = (target, all) => {
|
|
7
30
|
for (var name in all)
|
|
8
31
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +39,49 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
39
|
return to;
|
|
17
40
|
};
|
|
18
41
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
+
var __decoratorStart = (base) => {
|
|
43
|
+
var _a;
|
|
44
|
+
return [, , , __create((_a = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a : null)];
|
|
45
|
+
};
|
|
46
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
47
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
48
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
49
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
50
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
51
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
52
|
+
return value;
|
|
53
|
+
};
|
|
54
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
55
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
56
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
57
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
58
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
59
|
+
return __privateGet(this, extra);
|
|
60
|
+
}, set [name](x) {
|
|
61
|
+
return __privateSet(this, extra, x);
|
|
62
|
+
} }, name));
|
|
63
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
64
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
65
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
66
|
+
if (k) {
|
|
67
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
68
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
69
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
70
|
+
}
|
|
71
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
72
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
73
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
74
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
75
|
+
}
|
|
76
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
77
|
+
};
|
|
78
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
79
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
80
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
81
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
82
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
83
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
84
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
19
85
|
|
|
20
86
|
// index.ts
|
|
21
87
|
var index_exports = {};
|
|
@@ -23,7 +89,6 @@ __export(index_exports, {
|
|
|
23
89
|
AbstractSelectValueTypeConverter: () => AbstractSelectValueTypeConverter,
|
|
24
90
|
DefaultErrorRenderer: () => DefaultErrorRenderer,
|
|
25
91
|
FormModel: () => FormModel,
|
|
26
|
-
FormPresenter: () => FormPresenter,
|
|
27
92
|
IntegerToStringConverter: () => IntegerToStringConverter,
|
|
28
93
|
NullableToBooleanConverter: () => NullableToBooleanConverter,
|
|
29
94
|
SelectDiscriminatedUnionConverter: () => SelectDiscriminatedUnionConverter,
|
|
@@ -286,328 +351,21 @@ function listAdapter() {
|
|
|
286
351
|
);
|
|
287
352
|
}
|
|
288
353
|
|
|
289
|
-
// core/mobx/
|
|
354
|
+
// core/mobx/form_model.ts
|
|
290
355
|
var import_base2 = require("@strictly/base");
|
|
291
356
|
var import_define = require("@strictly/define");
|
|
292
357
|
var import_mobx = require("mobx");
|
|
293
|
-
var
|
|
294
|
-
|
|
295
|
-
this.type = type;
|
|
296
|
-
this.adapters = adapters;
|
|
297
|
-
}
|
|
298
|
-
maybeGetAdapterForValuePath(valuePath) {
|
|
299
|
-
const typePath = (0, import_define.valuePathToTypePath)(this.type, valuePath, true);
|
|
300
|
-
return this.adapters[typePath];
|
|
301
|
-
}
|
|
302
|
-
getAdapterForValuePath(valuePath) {
|
|
303
|
-
return (0, import_base2.assertExistsAndReturn)(
|
|
304
|
-
this.maybeGetAdapterForValuePath(valuePath),
|
|
305
|
-
"expected adapter to be defined {}",
|
|
306
|
-
valuePath
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
typePath(valuePath) {
|
|
310
|
-
return (0, import_define.valuePathToTypePath)(this.type, valuePath, true);
|
|
311
|
-
}
|
|
312
|
-
setFieldValueAndValidate(model, valuePath, value) {
|
|
313
|
-
return this.internalSetFieldValue(model, valuePath, value, true);
|
|
314
|
-
}
|
|
315
|
-
setFieldValue(model, valuePath, value) {
|
|
316
|
-
return this.internalSetFieldValue(model, valuePath, value, false);
|
|
317
|
-
}
|
|
318
|
-
addListItem(model, valuePath, elementValue = null, index) {
|
|
319
|
-
const listValuePath = valuePath;
|
|
320
|
-
const accessor = model.accessors[valuePath];
|
|
321
|
-
const listTypePath = this.typePath(valuePath);
|
|
322
|
-
const definedIndex = index ?? accessor.value.length;
|
|
323
|
-
const elementTypePath = `${listTypePath}.*`;
|
|
324
|
-
const elementAdapter = (0, import_base2.assertExistsAndReturn)(
|
|
325
|
-
this.adapters[elementTypePath],
|
|
326
|
-
"no adapter specified for list {} ({})",
|
|
327
|
-
elementTypePath,
|
|
328
|
-
valuePath
|
|
329
|
-
);
|
|
330
|
-
const element = elementValue != null ? elementValue[0] : elementAdapter.create(
|
|
331
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
332
|
-
elementTypePath,
|
|
333
|
-
model.value
|
|
334
|
-
);
|
|
335
|
-
const originalList = accessor.value;
|
|
336
|
-
const newList = [
|
|
337
|
-
...originalList.slice(0, definedIndex),
|
|
338
|
-
element,
|
|
339
|
-
...originalList.slice(definedIndex)
|
|
340
|
-
];
|
|
341
|
-
const targetPaths = Object.keys(model.fieldOverrides).filter(function(v) {
|
|
342
|
-
return v.startsWith(`${listValuePath}.`);
|
|
343
|
-
}).map(function(v) {
|
|
344
|
-
const parts = v.substring(listValuePath.length + 1).split(".");
|
|
345
|
-
const index2 = parseInt(parts[0]);
|
|
346
|
-
return [
|
|
347
|
-
index2,
|
|
348
|
-
parts.slice(1)
|
|
349
|
-
];
|
|
350
|
-
}).filter(function([index2]) {
|
|
351
|
-
return index2 >= definedIndex;
|
|
352
|
-
}).sort(function([a], [b]) {
|
|
353
|
-
return b - a;
|
|
354
|
-
});
|
|
355
|
-
(0, import_mobx.runInAction)(function() {
|
|
356
|
-
targetPaths.forEach(function([
|
|
357
|
-
index2,
|
|
358
|
-
postfix
|
|
359
|
-
]) {
|
|
360
|
-
const fromJsonPath = [
|
|
361
|
-
listValuePath,
|
|
362
|
-
`${index2}`,
|
|
363
|
-
...postfix
|
|
364
|
-
].join(".");
|
|
365
|
-
const toJsonPath = [
|
|
366
|
-
listValuePath,
|
|
367
|
-
`${index2 + 1}`,
|
|
368
|
-
...postfix
|
|
369
|
-
].join(".");
|
|
370
|
-
const fieldOverride = model.fieldOverrides[fromJsonPath];
|
|
371
|
-
delete model.fieldOverrides[fromJsonPath];
|
|
372
|
-
model.fieldOverrides[toJsonPath] = fieldOverride;
|
|
373
|
-
const error = model.errors[fromJsonPath];
|
|
374
|
-
delete model.errors[fromJsonPath];
|
|
375
|
-
model.errors[toJsonPath] = error;
|
|
376
|
-
});
|
|
377
|
-
accessor.set(newList);
|
|
378
|
-
delete model.fieldOverrides[listValuePath];
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
removeListItem(model, elementValuePath) {
|
|
382
|
-
const [
|
|
383
|
-
listValuePath,
|
|
384
|
-
elementIndexString
|
|
385
|
-
] = (0, import_base2.assertExistsAndReturn)(
|
|
386
|
-
(0, import_define.jsonPathPop)(elementValuePath),
|
|
387
|
-
"expected a path with two or more segments {}",
|
|
388
|
-
elementValuePath
|
|
389
|
-
);
|
|
390
|
-
const accessor = model.accessors[listValuePath];
|
|
391
|
-
const elementIndex = (0, import_base2.checkValidNumber)(
|
|
392
|
-
parseInt(elementIndexString),
|
|
393
|
-
"unexpected index {} ({})",
|
|
394
|
-
elementIndexString,
|
|
395
|
-
elementValuePath
|
|
396
|
-
);
|
|
397
|
-
const newList = [...accessor.value];
|
|
398
|
-
(0, import_base2.assertState)(
|
|
399
|
-
elementIndex >= 0 && elementIndex < newList.length,
|
|
400
|
-
"invalid index from path {} ({})",
|
|
401
|
-
elementIndex,
|
|
402
|
-
elementValuePath
|
|
403
|
-
);
|
|
404
|
-
newList.splice(elementIndex, 1);
|
|
405
|
-
const targetPaths = Object.keys(model.fieldOverrides).filter(function(v) {
|
|
406
|
-
return v.startsWith(`${listValuePath}.`);
|
|
407
|
-
}).map(function(v) {
|
|
408
|
-
const parts = v.substring(listValuePath.length + 1).split(".");
|
|
409
|
-
const index = parseInt(parts[0]);
|
|
410
|
-
return [
|
|
411
|
-
index,
|
|
412
|
-
parts.slice(1)
|
|
413
|
-
];
|
|
414
|
-
}).filter(function([index]) {
|
|
415
|
-
return index > elementIndex;
|
|
416
|
-
}).sort(function([a], [b]) {
|
|
417
|
-
return a - b;
|
|
418
|
-
});
|
|
419
|
-
(0, import_mobx.runInAction)(function() {
|
|
420
|
-
targetPaths.forEach(function([
|
|
421
|
-
index,
|
|
422
|
-
postfix
|
|
423
|
-
]) {
|
|
424
|
-
const fromJsonPath = [
|
|
425
|
-
listValuePath,
|
|
426
|
-
`${index}`,
|
|
427
|
-
...postfix
|
|
428
|
-
].join(".");
|
|
429
|
-
const toJsonPath = [
|
|
430
|
-
listValuePath,
|
|
431
|
-
`${index - 1}`,
|
|
432
|
-
...postfix
|
|
433
|
-
].join(".");
|
|
434
|
-
const fieldOverride = model.fieldOverrides[fromJsonPath];
|
|
435
|
-
delete model.fieldOverrides[fromJsonPath];
|
|
436
|
-
model.fieldOverrides[toJsonPath] = fieldOverride;
|
|
437
|
-
const error = model.errors[fromJsonPath];
|
|
438
|
-
delete model.errors[fromJsonPath];
|
|
439
|
-
model.errors[toJsonPath] = error;
|
|
440
|
-
});
|
|
441
|
-
accessor.set(newList);
|
|
442
|
-
delete model.fieldOverrides[listValuePath];
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
internalSetFieldValue(model, valuePath, value, displayValidation) {
|
|
446
|
-
const { revert } = this.getAdapterForValuePath(valuePath);
|
|
447
|
-
(0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
|
|
448
|
-
const conversion = revert(value, valuePath, model.value);
|
|
449
|
-
const accessor = model.getAccessorForValuePath(valuePath);
|
|
450
|
-
return (0, import_mobx.runInAction)(() => {
|
|
451
|
-
model.fieldOverrides[valuePath] = [value];
|
|
452
|
-
switch (conversion.type) {
|
|
453
|
-
case 1 /* Failure */:
|
|
454
|
-
if (displayValidation) {
|
|
455
|
-
model.errors[valuePath] = conversion.error;
|
|
456
|
-
}
|
|
457
|
-
if (conversion.value != null && accessor != null) {
|
|
458
|
-
accessor.set(conversion.value[0]);
|
|
459
|
-
}
|
|
460
|
-
return false;
|
|
461
|
-
case 0 /* Success */:
|
|
462
|
-
delete model.errors[valuePath];
|
|
463
|
-
accessor?.set(conversion.value);
|
|
464
|
-
return true;
|
|
465
|
-
default:
|
|
466
|
-
throw new import_base2.UnreachableError(conversion);
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
clearFieldError(model, valuePath) {
|
|
471
|
-
const fieldOverride = model.fieldOverrides[valuePath];
|
|
472
|
-
if (fieldOverride != null) {
|
|
473
|
-
(0, import_mobx.runInAction)(function() {
|
|
474
|
-
delete model.errors[valuePath];
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
clearFieldValue(model, valuePath) {
|
|
479
|
-
const typePath = this.typePath(valuePath);
|
|
480
|
-
const adapter2 = this.adapters[typePath];
|
|
481
|
-
if (adapter2 == null) {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
const {
|
|
485
|
-
convert,
|
|
486
|
-
create
|
|
487
|
-
} = adapter2;
|
|
488
|
-
const value = create(valuePath, model.value);
|
|
489
|
-
const {
|
|
490
|
-
value: displayValue
|
|
491
|
-
} = convert(value, valuePath, model.value);
|
|
492
|
-
const key = valuePath;
|
|
493
|
-
(0, import_mobx.runInAction)(function() {
|
|
494
|
-
model.fieldOverrides[key] = [displayValue];
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
clearAll(model, value) {
|
|
498
|
-
(0, import_mobx.runInAction)(() => {
|
|
499
|
-
model.errors = {};
|
|
500
|
-
model.fieldOverrides = {};
|
|
501
|
-
model.value = (0, import_define.mobxCopy)(this.type, value);
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
isValuePathActive(model, valuePath) {
|
|
505
|
-
const values = (0, import_define.flattenValuesOfType)(this.type, model.value);
|
|
506
|
-
const keys = new Set(Object.keys(values));
|
|
507
|
-
return keys.has(valuePath);
|
|
508
|
-
}
|
|
509
|
-
validateField(model, valuePath, ignoreDefaultValue = false) {
|
|
510
|
-
const {
|
|
511
|
-
convert,
|
|
512
|
-
revert,
|
|
513
|
-
create
|
|
514
|
-
} = this.getAdapterForValuePath(valuePath);
|
|
515
|
-
const fieldOverride = model.fieldOverrides[valuePath];
|
|
516
|
-
const accessor = model.getAccessorForValuePath(valuePath);
|
|
517
|
-
const {
|
|
518
|
-
value: storedValue
|
|
519
|
-
} = convert(
|
|
520
|
-
accessor != null ? accessor.value : create(valuePath, model.value),
|
|
521
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
522
|
-
valuePath,
|
|
523
|
-
model.value
|
|
524
|
-
);
|
|
525
|
-
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
526
|
-
const dirty = storedValue !== value;
|
|
527
|
-
(0, import_base2.assertExists)(revert, "changing field directly not supported {}", valuePath);
|
|
528
|
-
if (ignoreDefaultValue) {
|
|
529
|
-
const {
|
|
530
|
-
value: defaultDisplayValue
|
|
531
|
-
} = convert(create(valuePath, model.value), valuePath, model.value);
|
|
532
|
-
if (defaultDisplayValue === value) {
|
|
533
|
-
return true;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
const conversion = revert(value, valuePath, model.value);
|
|
537
|
-
return (0, import_mobx.runInAction)(function() {
|
|
538
|
-
switch (conversion.type) {
|
|
539
|
-
case 1 /* Failure */:
|
|
540
|
-
model.errors[valuePath] = conversion.error;
|
|
541
|
-
if (conversion.value != null && accessor != null && dirty) {
|
|
542
|
-
accessor.set(conversion.value[0]);
|
|
543
|
-
}
|
|
544
|
-
return false;
|
|
545
|
-
case 0 /* Success */:
|
|
546
|
-
delete model.errors[valuePath];
|
|
547
|
-
if (accessor != null && dirty) {
|
|
548
|
-
accessor.set(conversion.value);
|
|
549
|
-
}
|
|
550
|
-
return true;
|
|
551
|
-
default:
|
|
552
|
-
throw new import_base2.UnreachableError(conversion);
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
validateAll(model) {
|
|
557
|
-
const accessors = (0, import_base2.toArray)(model.accessors).toSorted(function([a], [b]) {
|
|
558
|
-
return a.length - b.length;
|
|
559
|
-
});
|
|
560
|
-
return (0, import_mobx.runInAction)(() => {
|
|
561
|
-
return accessors.reduce(
|
|
562
|
-
(success, [
|
|
563
|
-
valuePath,
|
|
564
|
-
accessor
|
|
565
|
-
]) => {
|
|
566
|
-
const adapterPath = valuePath;
|
|
567
|
-
const adapter2 = this.maybeGetAdapterForValuePath(adapterPath);
|
|
568
|
-
if (adapter2 == null) {
|
|
569
|
-
return success;
|
|
570
|
-
}
|
|
571
|
-
const {
|
|
572
|
-
convert,
|
|
573
|
-
revert
|
|
574
|
-
} = adapter2;
|
|
575
|
-
if (revert == null) {
|
|
576
|
-
return success;
|
|
577
|
-
}
|
|
578
|
-
const fieldOverride = model.fieldOverrides[adapterPath];
|
|
579
|
-
const {
|
|
580
|
-
value: storedValue
|
|
581
|
-
} = convert(accessor.value, valuePath, model.value);
|
|
582
|
-
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
583
|
-
const dirty = fieldOverride != null && fieldOverride[0] !== storedValue;
|
|
584
|
-
const conversion = revert(value, valuePath, model.value);
|
|
585
|
-
switch (conversion.type) {
|
|
586
|
-
case 1 /* Failure */:
|
|
587
|
-
model.errors[adapterPath] = conversion.error;
|
|
588
|
-
if (conversion.value != null && dirty) {
|
|
589
|
-
accessor.set(conversion.value[0]);
|
|
590
|
-
}
|
|
591
|
-
return false;
|
|
592
|
-
case 0 /* Success */:
|
|
593
|
-
if (dirty) {
|
|
594
|
-
accessor.set(conversion.value);
|
|
595
|
-
}
|
|
596
|
-
delete model.errors[adapterPath];
|
|
597
|
-
return success;
|
|
598
|
-
default:
|
|
599
|
-
throw new import_base2.UnreachableError(conversion);
|
|
600
|
-
}
|
|
601
|
-
},
|
|
602
|
-
true
|
|
603
|
-
);
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
};
|
|
358
|
+
var _accessors_dec, _knownFields_dec, _fields_dec, _errors_dec, _fieldOverrides_dec, _value_dec, _init, _value, _fieldOverrides, _errors;
|
|
359
|
+
_value_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errors_dec = [import_mobx.observable.shallow], _fields_dec = [import_mobx.computed], _knownFields_dec = [import_mobx.computed], _accessors_dec = [import_mobx.computed];
|
|
607
360
|
var FormModel = class {
|
|
608
361
|
constructor(type, value, adapters) {
|
|
609
362
|
this.type = type;
|
|
610
363
|
this.adapters = adapters;
|
|
364
|
+
__runInitializers(_init, 5, this);
|
|
365
|
+
__privateAdd(this, _value, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
366
|
+
__privateAdd(this, _fieldOverrides, __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
367
|
+
__privateAdd(this, _errors, __runInitializers(_init, 16, this, {})), __runInitializers(_init, 19, this);
|
|
368
|
+
__publicField(this, "flattenedTypeDefs");
|
|
611
369
|
this.value = (0, import_define.mobxCopy)(type, value);
|
|
612
370
|
this.flattenedTypeDefs = (0, import_define.flattenTypesOfType)(type);
|
|
613
371
|
const conversions = (0, import_define.flattenValueTo)(
|
|
@@ -634,14 +392,6 @@ var FormModel = class {
|
|
|
634
392
|
return v && [v.value];
|
|
635
393
|
});
|
|
636
394
|
}
|
|
637
|
-
@import_mobx.observable.ref
|
|
638
|
-
accessor value;
|
|
639
|
-
@import_mobx.observable.shallow
|
|
640
|
-
accessor fieldOverrides;
|
|
641
|
-
@import_mobx.observable.shallow
|
|
642
|
-
accessor errors = {};
|
|
643
|
-
flattenedTypeDefs;
|
|
644
|
-
@import_mobx.computed
|
|
645
395
|
get fields() {
|
|
646
396
|
return new Proxy(
|
|
647
397
|
this.knownFields,
|
|
@@ -658,7 +408,6 @@ var FormModel = class {
|
|
|
658
408
|
}
|
|
659
409
|
);
|
|
660
410
|
}
|
|
661
|
-
@import_mobx.computed
|
|
662
411
|
get knownFields() {
|
|
663
412
|
return (0, import_define.flattenValueTo)(
|
|
664
413
|
this.type,
|
|
@@ -727,7 +476,6 @@ var FormModel = class {
|
|
|
727
476
|
getAccessorForValuePath(valuePath) {
|
|
728
477
|
return this.accessors[valuePath];
|
|
729
478
|
}
|
|
730
|
-
@import_mobx.computed
|
|
731
479
|
// should only be referenced internally, so loosely typed
|
|
732
480
|
get accessors() {
|
|
733
481
|
return (0, import_define.flattenAccessorsOfType)(
|
|
@@ -738,249 +486,381 @@ var FormModel = class {
|
|
|
738
486
|
}
|
|
739
487
|
);
|
|
740
488
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
489
|
+
maybeGetAdapterForValuePath(valuePath) {
|
|
490
|
+
const typePath = (0, import_define.valuePathToTypePath)(this.type, valuePath, true);
|
|
491
|
+
return this.adapters[typePath];
|
|
492
|
+
}
|
|
493
|
+
getAdapterForValuePath(valuePath) {
|
|
494
|
+
return (0, import_base2.assertExistsAndReturn)(
|
|
495
|
+
this.maybeGetAdapterForValuePath(valuePath),
|
|
496
|
+
"expected adapter to be defined {}",
|
|
497
|
+
valuePath
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
typePath(valuePath) {
|
|
501
|
+
return (0, import_define.valuePathToTypePath)(this.type, valuePath, true);
|
|
502
|
+
}
|
|
503
|
+
setFieldValueAndValidate(valuePath, value) {
|
|
504
|
+
return this.internalSetFieldValue(valuePath, value, true);
|
|
505
|
+
}
|
|
506
|
+
setFieldValue(valuePath, value) {
|
|
507
|
+
return this.internalSetFieldValue(valuePath, value, false);
|
|
508
|
+
}
|
|
509
|
+
addListItem(valuePath, elementValue = null, index) {
|
|
510
|
+
const listValuePath = valuePath;
|
|
511
|
+
const accessor = this.accessors[valuePath];
|
|
512
|
+
const listTypePath = this.typePath(valuePath);
|
|
513
|
+
const definedIndex = index != null ? index : accessor.value.length;
|
|
514
|
+
const elementTypePath = `${listTypePath}.*`;
|
|
515
|
+
const elementAdapter = (0, import_base2.assertExistsAndReturn)(
|
|
516
|
+
this.adapters[elementTypePath],
|
|
517
|
+
"no adapter specified for list {} ({})",
|
|
518
|
+
elementTypePath,
|
|
519
|
+
valuePath
|
|
520
|
+
);
|
|
521
|
+
const element = elementValue != null ? elementValue[0] : elementAdapter.create(
|
|
522
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
523
|
+
elementTypePath,
|
|
524
|
+
this.value
|
|
525
|
+
);
|
|
526
|
+
const originalList = accessor.value;
|
|
527
|
+
const newList = [
|
|
528
|
+
...originalList.slice(0, definedIndex),
|
|
529
|
+
element,
|
|
530
|
+
...originalList.slice(definedIndex)
|
|
531
|
+
];
|
|
532
|
+
const targetPaths = Object.keys(this.fieldOverrides).filter(function(v) {
|
|
533
|
+
return v.startsWith(`${listValuePath}.`);
|
|
534
|
+
}).map(function(v) {
|
|
535
|
+
const parts = v.substring(listValuePath.length + 1).split(".");
|
|
536
|
+
const index2 = parseInt(parts[0]);
|
|
537
|
+
return [
|
|
538
|
+
index2,
|
|
539
|
+
parts.slice(1)
|
|
540
|
+
];
|
|
541
|
+
}).filter(function([index2]) {
|
|
542
|
+
return index2 >= definedIndex;
|
|
543
|
+
}).sort(function([a], [b]) {
|
|
544
|
+
return b - a;
|
|
545
|
+
});
|
|
546
|
+
(0, import_mobx.runInAction)(() => {
|
|
547
|
+
targetPaths.forEach(([
|
|
548
|
+
index2,
|
|
549
|
+
postfix
|
|
550
|
+
]) => {
|
|
551
|
+
const fromJsonPath = [
|
|
552
|
+
listValuePath,
|
|
553
|
+
`${index2}`,
|
|
554
|
+
...postfix
|
|
555
|
+
].join(".");
|
|
556
|
+
const toJsonPath = [
|
|
557
|
+
listValuePath,
|
|
558
|
+
`${index2 + 1}`,
|
|
559
|
+
...postfix
|
|
560
|
+
].join(".");
|
|
561
|
+
const fieldOverride = this.fieldOverrides[fromJsonPath];
|
|
562
|
+
delete this.fieldOverrides[fromJsonPath];
|
|
563
|
+
this.fieldOverrides[toJsonPath] = fieldOverride;
|
|
564
|
+
const error = this.errors[fromJsonPath];
|
|
565
|
+
delete this.errors[fromJsonPath];
|
|
566
|
+
this.errors[toJsonPath] = error;
|
|
567
|
+
});
|
|
568
|
+
accessor.set(newList);
|
|
569
|
+
delete this.fieldOverrides[listValuePath];
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
removeListItem(...elementValuePaths) {
|
|
573
|
+
const orderedElementValuePaths = elementValuePaths.toSorted().reverse();
|
|
574
|
+
(0, import_mobx.runInAction)(() => {
|
|
575
|
+
orderedElementValuePaths.forEach((elementValuePath) => {
|
|
576
|
+
const [
|
|
577
|
+
listValuePath,
|
|
578
|
+
elementIndexString
|
|
579
|
+
] = (0, import_base2.assertExistsAndReturn)(
|
|
580
|
+
(0, import_define.jsonPathPop)(elementValuePath),
|
|
581
|
+
"expected a path with two or more segments {}",
|
|
582
|
+
elementValuePath
|
|
583
|
+
);
|
|
584
|
+
const accessor = this.accessors[listValuePath];
|
|
585
|
+
const elementIndex = (0, import_base2.checkValidNumber)(
|
|
586
|
+
parseInt(elementIndexString),
|
|
587
|
+
"unexpected index {} ({})",
|
|
588
|
+
elementIndexString,
|
|
589
|
+
elementValuePath
|
|
590
|
+
);
|
|
591
|
+
const newList = [...accessor.value];
|
|
592
|
+
(0, import_base2.assertState)(
|
|
593
|
+
elementIndex >= 0 && elementIndex < newList.length,
|
|
594
|
+
"invalid index from path {} ({})",
|
|
595
|
+
elementIndex,
|
|
596
|
+
elementValuePath
|
|
597
|
+
);
|
|
598
|
+
newList.splice(elementIndex, 1);
|
|
599
|
+
const targetPaths = Object.keys(this.fieldOverrides).filter(function(v) {
|
|
600
|
+
return v.startsWith(`${listValuePath}.`);
|
|
601
|
+
}).map(function(v) {
|
|
602
|
+
const parts = v.substring(listValuePath.length + 1).split(".");
|
|
603
|
+
const index = parseInt(parts[0]);
|
|
783
604
|
return [
|
|
784
|
-
|
|
785
|
-
|
|
605
|
+
index,
|
|
606
|
+
parts.slice(1)
|
|
786
607
|
];
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
608
|
+
}).filter(function([index]) {
|
|
609
|
+
return index > elementIndex;
|
|
610
|
+
}).sort(function([a], [b]) {
|
|
611
|
+
return a - b;
|
|
612
|
+
});
|
|
613
|
+
targetPaths.forEach(([
|
|
614
|
+
index,
|
|
615
|
+
postfix
|
|
616
|
+
]) => {
|
|
617
|
+
const fromJsonPath = [
|
|
618
|
+
listValuePath,
|
|
619
|
+
`${index}`,
|
|
620
|
+
...postfix
|
|
621
|
+
].join(".");
|
|
622
|
+
const toJsonPath = [
|
|
623
|
+
listValuePath,
|
|
624
|
+
`${index - 1}`,
|
|
625
|
+
...postfix
|
|
626
|
+
].join(".");
|
|
627
|
+
const fieldOverride = this.fieldOverrides[fromJsonPath];
|
|
628
|
+
delete this.fieldOverrides[fromJsonPath];
|
|
629
|
+
this.fieldOverrides[toJsonPath] = fieldOverride;
|
|
630
|
+
const error = this.errors[fromJsonPath];
|
|
631
|
+
delete this.errors[fromJsonPath];
|
|
632
|
+
this.errors[toJsonPath] = error;
|
|
633
|
+
});
|
|
634
|
+
accessor.set(newList);
|
|
635
|
+
delete this.fieldOverrides[listValuePath];
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
internalSetFieldValue(valuePath, value, displayValidation) {
|
|
640
|
+
const { revert } = this.getAdapterForValuePath(valuePath);
|
|
641
|
+
(0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
|
|
642
|
+
const conversion = revert(value, valuePath, this.value);
|
|
643
|
+
const accessor = this.getAccessorForValuePath(valuePath);
|
|
644
|
+
return (0, import_mobx.runInAction)(() => {
|
|
645
|
+
this.fieldOverrides[valuePath] = [value];
|
|
646
|
+
switch (conversion.type) {
|
|
647
|
+
case 1 /* Failure */:
|
|
648
|
+
if (displayValidation) {
|
|
649
|
+
this.errors[valuePath] = conversion.error;
|
|
650
|
+
}
|
|
651
|
+
if (conversion.value != null && accessor != null) {
|
|
652
|
+
accessor.set(conversion.value[0]);
|
|
653
|
+
}
|
|
654
|
+
return false;
|
|
655
|
+
case 0 /* Success */:
|
|
656
|
+
delete this.errors[valuePath];
|
|
657
|
+
accessor == null ? void 0 : accessor.set(conversion.value);
|
|
658
|
+
return true;
|
|
659
|
+
default:
|
|
660
|
+
throw new import_base2.UnreachableError(conversion);
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
clearFieldError(valuePath) {
|
|
665
|
+
const fieldOverride = this.fieldOverrides[valuePath];
|
|
666
|
+
if (fieldOverride != null) {
|
|
667
|
+
(0, import_mobx.runInAction)(() => {
|
|
668
|
+
delete this.errors[valuePath];
|
|
669
|
+
});
|
|
804
670
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
return
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
671
|
+
}
|
|
672
|
+
clearFieldValue(valuePath) {
|
|
673
|
+
const typePath = this.typePath(valuePath);
|
|
674
|
+
const adapter2 = this.adapters[typePath];
|
|
675
|
+
if (adapter2 == null) {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const {
|
|
679
|
+
convert,
|
|
680
|
+
create
|
|
681
|
+
} = adapter2;
|
|
682
|
+
const value = create(valuePath, this.value);
|
|
683
|
+
const {
|
|
684
|
+
value: displayValue
|
|
685
|
+
} = convert(value, valuePath, this.value);
|
|
686
|
+
const key = valuePath;
|
|
687
|
+
(0, import_mobx.runInAction)(() => {
|
|
688
|
+
this.fieldOverrides[key] = [displayValue];
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
clearAll(value) {
|
|
692
|
+
(0, import_mobx.runInAction)(() => {
|
|
693
|
+
this.errors = {};
|
|
694
|
+
this.fieldOverrides = {};
|
|
695
|
+
this.value = (0, import_define.mobxCopy)(this.type, value);
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
isValuePathActive(valuePath) {
|
|
699
|
+
const values = (0, import_define.flattenValuesOfType)(this.type, this.value);
|
|
700
|
+
const keys = new Set(Object.keys(values));
|
|
701
|
+
return keys.has(valuePath);
|
|
702
|
+
}
|
|
703
|
+
validateField(valuePath, ignoreDefaultValue = false) {
|
|
704
|
+
const {
|
|
705
|
+
convert,
|
|
706
|
+
revert,
|
|
707
|
+
create
|
|
708
|
+
} = this.getAdapterForValuePath(valuePath);
|
|
709
|
+
const fieldOverride = this.fieldOverrides[valuePath];
|
|
710
|
+
const accessor = this.getAccessorForValuePath(valuePath);
|
|
711
|
+
const {
|
|
712
|
+
value: storedValue
|
|
713
|
+
} = convert(
|
|
714
|
+
accessor != null ? accessor.value : create(valuePath, this.value),
|
|
715
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
716
|
+
valuePath,
|
|
717
|
+
this.value
|
|
718
|
+
);
|
|
719
|
+
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
720
|
+
const dirty = storedValue !== value;
|
|
721
|
+
(0, import_base2.assertExists)(revert, "changing field directly not supported {}", valuePath);
|
|
722
|
+
if (ignoreDefaultValue) {
|
|
723
|
+
const {
|
|
724
|
+
value: defaultDisplayValue
|
|
725
|
+
} = convert(create(valuePath, this.value), valuePath, this.value);
|
|
726
|
+
if (defaultDisplayValue === value) {
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const conversion = revert(value, valuePath, this.value);
|
|
731
|
+
return (0, import_mobx.runInAction)(() => {
|
|
732
|
+
switch (conversion.type) {
|
|
733
|
+
case 1 /* Failure */:
|
|
734
|
+
this.errors[valuePath] = conversion.error;
|
|
735
|
+
if (conversion.value != null && accessor != null && dirty) {
|
|
736
|
+
accessor.set(conversion.value[0]);
|
|
871
737
|
}
|
|
872
|
-
|
|
738
|
+
return false;
|
|
739
|
+
case 0 /* Success */:
|
|
740
|
+
delete this.errors[valuePath];
|
|
741
|
+
if (accessor != null && dirty) {
|
|
742
|
+
accessor.set(conversion.value);
|
|
743
|
+
}
|
|
744
|
+
return true;
|
|
745
|
+
default:
|
|
746
|
+
throw new import_base2.UnreachableError(conversion);
|
|
873
747
|
}
|
|
874
|
-
)
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
validateAll() {
|
|
751
|
+
const accessors = (0, import_base2.toArray)(this.accessors).toSorted(function([a], [b]) {
|
|
752
|
+
return a.length - b.length;
|
|
753
|
+
});
|
|
754
|
+
return (0, import_mobx.runInAction)(() => {
|
|
755
|
+
return accessors.reduce(
|
|
756
|
+
(success, [
|
|
757
|
+
valuePath,
|
|
758
|
+
accessor
|
|
759
|
+
]) => {
|
|
760
|
+
const adapterPath = valuePath;
|
|
761
|
+
const adapter2 = this.maybeGetAdapterForValuePath(adapterPath);
|
|
762
|
+
if (adapter2 == null) {
|
|
763
|
+
return success;
|
|
764
|
+
}
|
|
765
|
+
const {
|
|
766
|
+
convert,
|
|
767
|
+
revert
|
|
768
|
+
} = adapter2;
|
|
769
|
+
if (revert == null) {
|
|
770
|
+
return success;
|
|
771
|
+
}
|
|
772
|
+
const fieldOverride = this.fieldOverrides[adapterPath];
|
|
773
|
+
const {
|
|
774
|
+
value: storedValue
|
|
775
|
+
} = convert(accessor.value, valuePath, this.value);
|
|
776
|
+
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
777
|
+
const dirty = fieldOverride != null && fieldOverride[0] !== storedValue;
|
|
778
|
+
const conversion = revert(value, valuePath, this.value);
|
|
779
|
+
switch (conversion.type) {
|
|
780
|
+
case 1 /* Failure */:
|
|
781
|
+
this.errors[adapterPath] = conversion.error;
|
|
782
|
+
if (conversion.value != null && dirty) {
|
|
783
|
+
accessor.set(conversion.value[0]);
|
|
784
|
+
}
|
|
785
|
+
return false;
|
|
786
|
+
case 0 /* Success */:
|
|
787
|
+
if (dirty) {
|
|
788
|
+
accessor.set(conversion.value);
|
|
789
|
+
}
|
|
790
|
+
delete this.errors[adapterPath];
|
|
791
|
+
return success;
|
|
792
|
+
default:
|
|
793
|
+
throw new import_base2.UnreachableError(conversion);
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
true
|
|
884
797
|
);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
_init = __decoratorStart(null);
|
|
802
|
+
_value = new WeakMap();
|
|
803
|
+
_fieldOverrides = new WeakMap();
|
|
804
|
+
_errors = new WeakMap();
|
|
805
|
+
__decorateElement(_init, 4, "value", _value_dec, FormModel, _value);
|
|
806
|
+
__decorateElement(_init, 4, "fieldOverrides", _fieldOverrides_dec, FormModel, _fieldOverrides);
|
|
807
|
+
__decorateElement(_init, 4, "errors", _errors_dec, FormModel, _errors);
|
|
808
|
+
__decorateElement(_init, 2, "fields", _fields_dec, FormModel);
|
|
809
|
+
__decorateElement(_init, 2, "knownFields", _knownFields_dec, FormModel);
|
|
810
|
+
__decorateElement(_init, 2, "accessors", _accessors_dec, FormModel);
|
|
811
|
+
__decoratorMetadata(_init, FormModel);
|
|
896
812
|
|
|
897
813
|
// core/mobx/hooks.tsx
|
|
898
|
-
|
|
814
|
+
var import_react = require("react");
|
|
815
|
+
function useDefaultMobxFormHooks(model, {
|
|
899
816
|
onValidFieldSubmit,
|
|
900
|
-
onValidFormSubmit
|
|
901
|
-
FormFieldsView
|
|
817
|
+
onValidFormSubmit
|
|
902
818
|
} = {}) {
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
value
|
|
908
|
-
]);
|
|
909
|
-
const onFieldValueChange = (0, import_react2.useCallback)(
|
|
910
|
-
function(path, value2) {
|
|
911
|
-
presenter.clearFieldError(model, path);
|
|
912
|
-
presenter.setFieldValue(model, path, value2);
|
|
819
|
+
const onFieldValueChange = (0, import_react.useCallback)(
|
|
820
|
+
function(path, value) {
|
|
821
|
+
model.clearFieldError(path);
|
|
822
|
+
model.setFieldValue(path, value);
|
|
913
823
|
},
|
|
914
|
-
[
|
|
915
|
-
presenter,
|
|
916
|
-
model
|
|
917
|
-
]
|
|
824
|
+
[model]
|
|
918
825
|
);
|
|
919
|
-
const onFieldSubmit = (0,
|
|
826
|
+
const onFieldSubmit = (0, import_react.useCallback)(
|
|
920
827
|
function(valuePath) {
|
|
921
|
-
if (
|
|
922
|
-
onValidFieldSubmit
|
|
828
|
+
if (model.validateField(valuePath)) {
|
|
829
|
+
onValidFieldSubmit == null ? void 0 : onValidFieldSubmit(valuePath);
|
|
923
830
|
}
|
|
924
831
|
return false;
|
|
925
832
|
},
|
|
926
833
|
[
|
|
927
|
-
presenter,
|
|
928
834
|
model,
|
|
929
835
|
onValidFieldSubmit
|
|
930
836
|
]
|
|
931
837
|
);
|
|
932
|
-
const onFieldBlur = (0,
|
|
838
|
+
const onFieldBlur = (0, import_react.useCallback)(
|
|
933
839
|
function(path) {
|
|
934
840
|
setTimeout(function() {
|
|
935
|
-
if (
|
|
936
|
-
|
|
841
|
+
if (model.isValuePathActive(path)) {
|
|
842
|
+
model.validateField(path, true);
|
|
937
843
|
}
|
|
938
844
|
}, 100);
|
|
939
845
|
},
|
|
940
|
-
[
|
|
941
|
-
presenter,
|
|
942
|
-
model
|
|
943
|
-
]
|
|
846
|
+
[model]
|
|
944
847
|
);
|
|
945
|
-
const onFormSubmit = (0,
|
|
848
|
+
const onFormSubmit = (0, import_react.useCallback)(
|
|
946
849
|
function() {
|
|
947
|
-
if (
|
|
948
|
-
onValidFormSubmit
|
|
850
|
+
if (model.validateAll()) {
|
|
851
|
+
onValidFormSubmit == null ? void 0 : onValidFormSubmit(model.value);
|
|
949
852
|
}
|
|
950
853
|
},
|
|
951
854
|
[
|
|
952
|
-
presenter,
|
|
953
855
|
model,
|
|
954
856
|
onValidFormSubmit
|
|
955
857
|
]
|
|
956
858
|
);
|
|
957
|
-
const FormFields = (0, import_react2.useMemo)(() => {
|
|
958
|
-
if (FormFieldsView == null) {
|
|
959
|
-
return void 0;
|
|
960
|
-
}
|
|
961
|
-
return createUnsafePartialObserverComponent(FormFieldsView, () => {
|
|
962
|
-
return {
|
|
963
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
964
|
-
fields: model.fields,
|
|
965
|
-
onFieldBlur,
|
|
966
|
-
onFieldSubmit,
|
|
967
|
-
onFieldValueChange
|
|
968
|
-
};
|
|
969
|
-
});
|
|
970
|
-
}, [
|
|
971
|
-
model,
|
|
972
|
-
FormFieldsView,
|
|
973
|
-
onFieldBlur,
|
|
974
|
-
onFieldSubmit,
|
|
975
|
-
onFieldValueChange
|
|
976
|
-
]);
|
|
977
859
|
return {
|
|
978
|
-
model,
|
|
979
860
|
onFieldValueChange,
|
|
980
861
|
onFieldSubmit,
|
|
981
862
|
onFieldBlur,
|
|
982
|
-
onFormSubmit
|
|
983
|
-
FormFields
|
|
863
|
+
onFormSubmit
|
|
984
864
|
};
|
|
985
865
|
}
|
|
986
866
|
|
|
@@ -1048,11 +928,10 @@ function mergeAdaptersWithValidators(adapters, validators) {
|
|
|
1048
928
|
readonly: readonly1 || readonly2
|
|
1049
929
|
};
|
|
1050
930
|
}
|
|
1051
|
-
acc[key] = {
|
|
1052
|
-
...adapter2,
|
|
931
|
+
acc[key] = __spreadProps(__spreadValues({}, adapter2), {
|
|
1053
932
|
convert,
|
|
1054
933
|
revert: adapter2.revert && revert
|
|
1055
|
-
};
|
|
934
|
+
});
|
|
1056
935
|
return acc;
|
|
1057
936
|
},
|
|
1058
937
|
{}
|
|
@@ -1131,9 +1010,9 @@ var NullableToBooleanConverter = class {
|
|
|
1131
1010
|
this.typeDef = typeDef;
|
|
1132
1011
|
this.prototype = prototype;
|
|
1133
1012
|
this.nullType = nullType;
|
|
1013
|
+
__publicField(this, "defaultValue");
|
|
1134
1014
|
this.defaultValue = defaultToNull ? this.nullType : prototype;
|
|
1135
1015
|
}
|
|
1136
|
-
defaultValue;
|
|
1137
1016
|
convert(from) {
|
|
1138
1017
|
return {
|
|
1139
1018
|
value: from !== this.nullType,
|
|
@@ -1292,21 +1171,170 @@ var import_base6 = require("@strictly/base");
|
|
|
1292
1171
|
var import_mobx2 = require("mobx");
|
|
1293
1172
|
var import_react4 = require("react");
|
|
1294
1173
|
|
|
1174
|
+
// util/partial.tsx
|
|
1175
|
+
var import_mobx_react = require("mobx-react");
|
|
1176
|
+
var import_react2 = require("react");
|
|
1177
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1178
|
+
function createSimplePartialComponent(Component, curriedProps) {
|
|
1179
|
+
return (0, import_react2.forwardRef)(
|
|
1180
|
+
function(exposedProps, ref) {
|
|
1181
|
+
const C = Component;
|
|
1182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1183
|
+
C,
|
|
1184
|
+
__spreadValues(__spreadValues({
|
|
1185
|
+
ref
|
|
1186
|
+
}, curriedProps), exposedProps)
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
function createPartialComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1192
|
+
return (0, import_react2.forwardRef)(
|
|
1193
|
+
function(props, ref) {
|
|
1194
|
+
const C = Component;
|
|
1195
|
+
const [
|
|
1196
|
+
additionalProps,
|
|
1197
|
+
exposedProps
|
|
1198
|
+
] = additionalPropKeys.reduce(
|
|
1199
|
+
function([
|
|
1200
|
+
additionalProps2,
|
|
1201
|
+
exposedProps2
|
|
1202
|
+
], key) {
|
|
1203
|
+
const value = props[
|
|
1204
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1205
|
+
key
|
|
1206
|
+
];
|
|
1207
|
+
delete exposedProps2[key];
|
|
1208
|
+
additionalProps2[key] = value;
|
|
1209
|
+
return [
|
|
1210
|
+
additionalProps2,
|
|
1211
|
+
exposedProps2
|
|
1212
|
+
];
|
|
1213
|
+
},
|
|
1214
|
+
[
|
|
1215
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1216
|
+
{},
|
|
1217
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1218
|
+
__spreadValues({}, props)
|
|
1219
|
+
]
|
|
1220
|
+
);
|
|
1221
|
+
const curriedProps = curriedPropsSource(additionalProps);
|
|
1222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1223
|
+
C,
|
|
1224
|
+
__spreadValues(__spreadValues({
|
|
1225
|
+
ref
|
|
1226
|
+
}, curriedProps), exposedProps)
|
|
1227
|
+
);
|
|
1228
|
+
}
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
function usePartialComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1232
|
+
return (0, import_react2.useMemo)(
|
|
1233
|
+
function() {
|
|
1234
|
+
return createPartialComponent(
|
|
1235
|
+
Component,
|
|
1236
|
+
curriedPropsSource,
|
|
1237
|
+
additionalPropKeys
|
|
1238
|
+
);
|
|
1239
|
+
},
|
|
1240
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1241
|
+
[
|
|
1242
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1243
|
+
...deps,
|
|
1244
|
+
Component,
|
|
1245
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1246
|
+
...additionalPropKeys
|
|
1247
|
+
]
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
function createPartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1251
|
+
return createUnsafePartialObserverComponent(
|
|
1252
|
+
Component,
|
|
1253
|
+
curriedPropsSource,
|
|
1254
|
+
additionalPropKeys
|
|
1255
|
+
);
|
|
1256
|
+
}
|
|
1257
|
+
function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1258
|
+
return (0, import_mobx_react.observer)(
|
|
1259
|
+
(0, import_react2.forwardRef)(
|
|
1260
|
+
function(props, ref) {
|
|
1261
|
+
const C = Component;
|
|
1262
|
+
const [
|
|
1263
|
+
additionalProps,
|
|
1264
|
+
exposedProps
|
|
1265
|
+
] = additionalPropKeys.reduce(
|
|
1266
|
+
function([
|
|
1267
|
+
additionalProps2,
|
|
1268
|
+
exposedProps2
|
|
1269
|
+
], key) {
|
|
1270
|
+
const value = props[
|
|
1271
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1272
|
+
key
|
|
1273
|
+
];
|
|
1274
|
+
delete exposedProps2[key];
|
|
1275
|
+
additionalProps2[key] = value;
|
|
1276
|
+
return [
|
|
1277
|
+
additionalProps2,
|
|
1278
|
+
exposedProps2
|
|
1279
|
+
];
|
|
1280
|
+
},
|
|
1281
|
+
[
|
|
1282
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1283
|
+
{},
|
|
1284
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1285
|
+
__spreadValues({}, props)
|
|
1286
|
+
]
|
|
1287
|
+
);
|
|
1288
|
+
const curriedProps = curriedPropsSource(additionalProps);
|
|
1289
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1290
|
+
C,
|
|
1291
|
+
__spreadValues(__spreadValues({
|
|
1292
|
+
ref
|
|
1293
|
+
}, curriedProps), exposedProps)
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
)
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1300
|
+
return (0, import_react2.useMemo)(
|
|
1301
|
+
function() {
|
|
1302
|
+
return createPartialObserverComponent(
|
|
1303
|
+
Component,
|
|
1304
|
+
curriedPropsSource,
|
|
1305
|
+
additionalPropKeys
|
|
1306
|
+
);
|
|
1307
|
+
},
|
|
1308
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1309
|
+
[
|
|
1310
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1311
|
+
...deps,
|
|
1312
|
+
Component,
|
|
1313
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1314
|
+
...additionalPropKeys
|
|
1315
|
+
]
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1295
1319
|
// mantine/create_checkbox.tsx
|
|
1296
1320
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1297
1321
|
function createCheckbox(valuePath, Checkbox) {
|
|
1298
1322
|
const onChange = (e) => {
|
|
1299
|
-
|
|
1323
|
+
var _a;
|
|
1324
|
+
(_a = this.onFieldValueChange) == null ? void 0 : _a.call(this, valuePath, e.target.checked);
|
|
1300
1325
|
};
|
|
1301
1326
|
const onFocus = () => {
|
|
1302
|
-
|
|
1327
|
+
var _a;
|
|
1328
|
+
(_a = this.onFieldFocus) == null ? void 0 : _a.call(this, valuePath);
|
|
1303
1329
|
};
|
|
1304
1330
|
const onBlur = () => {
|
|
1305
|
-
|
|
1331
|
+
var _a;
|
|
1332
|
+
(_a = this.onFieldBlur) == null ? void 0 : _a.call(this, valuePath);
|
|
1306
1333
|
};
|
|
1307
1334
|
const onKeyUp = (e) => {
|
|
1335
|
+
var _a;
|
|
1308
1336
|
if (e.key === "Enter") {
|
|
1309
|
-
if (this.onFieldSubmit
|
|
1337
|
+
if ((_a = this.onFieldSubmit) == null ? void 0 : _a.call(this, valuePath)) {
|
|
1310
1338
|
e.preventDefault();
|
|
1311
1339
|
}
|
|
1312
1340
|
}
|
|
@@ -1354,13 +1382,16 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
1354
1382
|
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
1355
1383
|
}
|
|
1356
1384
|
function onFieldBlur(subKey) {
|
|
1357
|
-
|
|
1385
|
+
var _a;
|
|
1386
|
+
(_a = observableProps.onFieldBlur) == null ? void 0 : _a.call(observableProps, toKey(subKey));
|
|
1358
1387
|
}
|
|
1359
1388
|
function onFieldFocus(subKey) {
|
|
1360
|
-
|
|
1389
|
+
var _a;
|
|
1390
|
+
(_a = observableProps.onFieldFocus) == null ? void 0 : _a.call(observableProps, toKey(subKey));
|
|
1361
1391
|
}
|
|
1362
1392
|
function onFieldSubmit(subKey) {
|
|
1363
|
-
|
|
1393
|
+
var _a;
|
|
1394
|
+
(_a = observableProps.onFieldSubmit) == null ? void 0 : _a.call(observableProps, toKey(subKey));
|
|
1364
1395
|
}
|
|
1365
1396
|
const Component = (0, import_mobx_react2.observer)(
|
|
1366
1397
|
function(props) {
|
|
@@ -1379,16 +1410,13 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
1379
1410
|
);
|
|
1380
1411
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1381
1412
|
FieldsView,
|
|
1382
|
-
{
|
|
1383
|
-
// maybe we can do this in a more type safe way
|
|
1384
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1385
|
-
...props,
|
|
1413
|
+
__spreadProps(__spreadValues({}, props), {
|
|
1386
1414
|
fields: subFields,
|
|
1387
1415
|
onFieldBlur,
|
|
1388
1416
|
onFieldFocus,
|
|
1389
1417
|
onFieldSubmit,
|
|
1390
1418
|
onFieldValueChange
|
|
1391
|
-
}
|
|
1419
|
+
})
|
|
1392
1420
|
);
|
|
1393
1421
|
}
|
|
1394
1422
|
);
|
|
@@ -1416,13 +1444,10 @@ function createForm(valuePath, Form, observableProps) {
|
|
|
1416
1444
|
}, []);
|
|
1417
1445
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1418
1446
|
Form,
|
|
1419
|
-
{
|
|
1420
|
-
// maybe we can do this in a more type safe way
|
|
1421
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1422
|
-
...props,
|
|
1447
|
+
__spreadProps(__spreadValues({}, props), {
|
|
1423
1448
|
onValueChange,
|
|
1424
1449
|
value
|
|
1425
|
-
}
|
|
1450
|
+
})
|
|
1426
1451
|
);
|
|
1427
1452
|
});
|
|
1428
1453
|
}
|
|
@@ -1486,17 +1511,21 @@ function createRadio(valuePath, value, Radio) {
|
|
|
1486
1511
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1487
1512
|
function createRadioGroup(valuePath, RadioGroup) {
|
|
1488
1513
|
const onChange = (value) => {
|
|
1489
|
-
|
|
1514
|
+
var _a;
|
|
1515
|
+
(_a = this.onFieldValueChange) == null ? void 0 : _a.call(this, valuePath, value);
|
|
1490
1516
|
};
|
|
1491
1517
|
const onFocus = () => {
|
|
1492
|
-
|
|
1518
|
+
var _a;
|
|
1519
|
+
(_a = this.onFieldFocus) == null ? void 0 : _a.call(this, valuePath);
|
|
1493
1520
|
};
|
|
1494
1521
|
const onBlur = () => {
|
|
1495
|
-
|
|
1522
|
+
var _a;
|
|
1523
|
+
(_a = this.onFieldBlur) == null ? void 0 : _a.call(this, valuePath);
|
|
1496
1524
|
};
|
|
1497
1525
|
const onKeyUp = (e) => {
|
|
1526
|
+
var _a;
|
|
1498
1527
|
if (e.key === "Enter") {
|
|
1499
|
-
if (this.onFieldSubmit
|
|
1528
|
+
if ((_a = this.onFieldSubmit) == null ? void 0 : _a.call(this, valuePath)) {
|
|
1500
1529
|
e.preventDefault();
|
|
1501
1530
|
}
|
|
1502
1531
|
}
|
|
@@ -1525,17 +1554,21 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1525
1554
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1526
1555
|
function createTextInput(valuePath, TextInput) {
|
|
1527
1556
|
const onChange = (e) => {
|
|
1528
|
-
|
|
1557
|
+
var _a;
|
|
1558
|
+
(_a = this.onFieldValueChange) == null ? void 0 : _a.call(this, valuePath, e.target.value);
|
|
1529
1559
|
};
|
|
1530
1560
|
const onFocus = () => {
|
|
1531
|
-
|
|
1561
|
+
var _a;
|
|
1562
|
+
(_a = this.onFieldFocus) == null ? void 0 : _a.call(this, valuePath);
|
|
1532
1563
|
};
|
|
1533
1564
|
const onBlur = () => {
|
|
1534
|
-
|
|
1565
|
+
var _a;
|
|
1566
|
+
(_a = this.onFieldBlur) == null ? void 0 : _a.call(this, valuePath);
|
|
1535
1567
|
};
|
|
1536
1568
|
const onKeyUp = (e) => {
|
|
1569
|
+
var _a;
|
|
1537
1570
|
if (e.key === "Enter") {
|
|
1538
|
-
if (this.onFieldSubmit
|
|
1571
|
+
if ((_a = this.onFieldSubmit) == null ? void 0 : _a.call(this, valuePath)) {
|
|
1539
1572
|
e.preventDefault();
|
|
1540
1573
|
}
|
|
1541
1574
|
}
|
|
@@ -1577,17 +1610,21 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1577
1610
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1578
1611
|
function createValueInput(valuePath, ValueInput) {
|
|
1579
1612
|
const onChange = (value) => {
|
|
1580
|
-
|
|
1613
|
+
var _a;
|
|
1614
|
+
(_a = this.onFieldValueChange) == null ? void 0 : _a.call(this, valuePath, value);
|
|
1581
1615
|
};
|
|
1582
1616
|
const onFocus = () => {
|
|
1583
|
-
|
|
1617
|
+
var _a;
|
|
1618
|
+
(_a = this.onFieldFocus) == null ? void 0 : _a.call(this, valuePath);
|
|
1584
1619
|
};
|
|
1585
1620
|
const onBlur = () => {
|
|
1586
|
-
|
|
1621
|
+
var _a;
|
|
1622
|
+
(_a = this.onFieldBlur) == null ? void 0 : _a.call(this, valuePath);
|
|
1587
1623
|
};
|
|
1588
1624
|
const onKeyUp = (e) => {
|
|
1625
|
+
var _a;
|
|
1589
1626
|
if (e.key === "Enter") {
|
|
1590
|
-
if (this.onFieldSubmit
|
|
1627
|
+
if ((_a = this.onFieldSubmit) == null ? void 0 : _a.call(this, valuePath)) {
|
|
1591
1628
|
e.preventDefault();
|
|
1592
1629
|
}
|
|
1593
1630
|
}
|
|
@@ -1625,7 +1662,7 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1625
1662
|
// mantine/hooks.tsx
|
|
1626
1663
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1627
1664
|
function SimpleSelect(props) {
|
|
1628
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core.Select, {
|
|
1665
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core.Select, __spreadValues({}, props));
|
|
1629
1666
|
}
|
|
1630
1667
|
function useMantineFormFields({
|
|
1631
1668
|
onFieldValueChange,
|
|
@@ -1676,39 +1713,40 @@ function useMantineFormFields({
|
|
|
1676
1713
|
]);
|
|
1677
1714
|
return form;
|
|
1678
1715
|
}
|
|
1716
|
+
var _fields_dec2, _init2, _fields;
|
|
1717
|
+
_fields_dec2 = [import_mobx2.observable.ref];
|
|
1679
1718
|
var MantineFormImpl = class {
|
|
1680
|
-
textInputCache = new import_base6.Cache(
|
|
1681
|
-
createTextInput.bind(this)
|
|
1682
|
-
);
|
|
1683
|
-
valueInputCache = new import_base6.Cache(
|
|
1684
|
-
createValueInput.bind(this)
|
|
1685
|
-
);
|
|
1686
|
-
checkboxCache = new import_base6.Cache(
|
|
1687
|
-
createCheckbox.bind(this)
|
|
1688
|
-
);
|
|
1689
|
-
radioGroupCache = new import_base6.Cache(
|
|
1690
|
-
createRadioGroup.bind(this)
|
|
1691
|
-
);
|
|
1692
|
-
radioCache = new import_base6.Cache(
|
|
1693
|
-
createRadio.bind(this)
|
|
1694
|
-
);
|
|
1695
|
-
pillCache = new import_base6.Cache(
|
|
1696
|
-
createPill.bind(this)
|
|
1697
|
-
);
|
|
1698
|
-
listCache = new import_base6.Cache(
|
|
1699
|
-
createList.bind(this)
|
|
1700
|
-
);
|
|
1701
|
-
fieldsViewCache = new import_base6.Cache(
|
|
1702
|
-
createFieldsView.bind(this)
|
|
1703
|
-
);
|
|
1704
|
-
formCache = new import_base6.Cache(createForm.bind(this));
|
|
1705
|
-
@import_mobx2.observable.ref
|
|
1706
|
-
accessor fields;
|
|
1707
|
-
onFieldValueChange;
|
|
1708
|
-
onFieldFocus;
|
|
1709
|
-
onFieldBlur;
|
|
1710
|
-
onFieldSubmit;
|
|
1711
1719
|
constructor(fields) {
|
|
1720
|
+
__publicField(this, "textInputCache", new import_base6.Cache(
|
|
1721
|
+
createTextInput.bind(this)
|
|
1722
|
+
));
|
|
1723
|
+
__publicField(this, "valueInputCache", new import_base6.Cache(
|
|
1724
|
+
createValueInput.bind(this)
|
|
1725
|
+
));
|
|
1726
|
+
__publicField(this, "checkboxCache", new import_base6.Cache(
|
|
1727
|
+
createCheckbox.bind(this)
|
|
1728
|
+
));
|
|
1729
|
+
__publicField(this, "radioGroupCache", new import_base6.Cache(
|
|
1730
|
+
createRadioGroup.bind(this)
|
|
1731
|
+
));
|
|
1732
|
+
__publicField(this, "radioCache", new import_base6.Cache(
|
|
1733
|
+
createRadio.bind(this)
|
|
1734
|
+
));
|
|
1735
|
+
__publicField(this, "pillCache", new import_base6.Cache(
|
|
1736
|
+
createPill.bind(this)
|
|
1737
|
+
));
|
|
1738
|
+
__publicField(this, "listCache", new import_base6.Cache(
|
|
1739
|
+
createList.bind(this)
|
|
1740
|
+
));
|
|
1741
|
+
__publicField(this, "fieldsViewCache", new import_base6.Cache(
|
|
1742
|
+
createFieldsView.bind(this)
|
|
1743
|
+
));
|
|
1744
|
+
__publicField(this, "formCache", new import_base6.Cache(createForm.bind(this)));
|
|
1745
|
+
__privateAdd(this, _fields, __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
|
|
1746
|
+
__publicField(this, "onFieldValueChange");
|
|
1747
|
+
__publicField(this, "onFieldFocus");
|
|
1748
|
+
__publicField(this, "onFieldBlur");
|
|
1749
|
+
__publicField(this, "onFieldSubmit");
|
|
1712
1750
|
this.fields = fields;
|
|
1713
1751
|
}
|
|
1714
1752
|
textInput(valuePath, TextInput = import_core.TextInput) {
|
|
@@ -1785,15 +1823,17 @@ var MantineFormImpl = class {
|
|
|
1785
1823
|
this
|
|
1786
1824
|
);
|
|
1787
1825
|
}
|
|
1826
|
+
// TODO have an option to bind to a Text/(value: T) => JSX.Element for viewing form fields
|
|
1788
1827
|
};
|
|
1828
|
+
_init2 = __decoratorStart(null);
|
|
1829
|
+
_fields = new WeakMap();
|
|
1830
|
+
__decorateElement(_init2, 4, "fields", _fields_dec2, MantineFormImpl, _fields);
|
|
1831
|
+
__decoratorMetadata(_init2, MantineFormImpl);
|
|
1789
1832
|
|
|
1790
1833
|
// types/merge_validators.ts
|
|
1791
1834
|
var import_define7 = require("@strictly/define");
|
|
1792
1835
|
function mergeValidators(validators1, validators2) {
|
|
1793
|
-
const validators = {
|
|
1794
|
-
...validators1,
|
|
1795
|
-
...validators2
|
|
1796
|
-
};
|
|
1836
|
+
const validators = __spreadValues(__spreadValues({}, validators1), validators2);
|
|
1797
1837
|
const keys1 = new Set(Object.keys(validators1));
|
|
1798
1838
|
const keys2 = new Set(Object.keys(validators2));
|
|
1799
1839
|
return Array.from(keys1.intersection(keys2)).reduce(
|
|
@@ -1830,7 +1870,6 @@ function mergeValidators(validators1, validators2) {
|
|
|
1830
1870
|
AbstractSelectValueTypeConverter,
|
|
1831
1871
|
DefaultErrorRenderer,
|
|
1832
1872
|
FormModel,
|
|
1833
|
-
FormPresenter,
|
|
1834
1873
|
IntegerToStringConverter,
|
|
1835
1874
|
NullableToBooleanConverter,
|
|
1836
1875
|
SelectDiscriminatedUnionConverter,
|