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