@strictly/react-form 0.0.14 → 0.0.16
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.d.ts +1 -1
- package/.out/core/mobx/form_model.d.ts +7 -5
- package/.out/core/mobx/form_model.js +27 -23
- package/.out/core/mobx/merge_field_adapters_with_validators.d.ts +1 -1
- package/.out/core/mobx/specs/form_model.tests.js +18 -8
- package/.out/core/mobx/types.d.ts +4 -4
- package/.out/index.d.ts +0 -1
- package/.out/index.js +0 -1
- package/.out/mantine/create_field_view.d.ts +20 -0
- package/.out/mantine/create_field_view.js +54 -0
- package/.out/mantine/create_list.js +3 -2
- package/.out/mantine/hooks.d.ts +4 -1
- package/.out/mantine/hooks.js +13 -1
- package/.out/mantine/specs/field_view_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/field_view_hooks.stories.js +61 -0
- package/.out/mantine/specs/field_view_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/field_view_hooks.tests.js +12 -0
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/merge_validators.d.ts +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/field_adapter_builder.ts +2 -2
- package/core/mobx/form_model.ts +48 -23
- package/core/mobx/merge_field_adapters_with_validators.ts +1 -1
- package/core/mobx/specs/form_model.tests.ts +28 -11
- package/core/mobx/types.ts +4 -4
- package/dist/index.cjs +124 -70
- package/dist/index.d.cts +31 -28
- package/dist/index.d.ts +31 -28
- package/dist/index.js +121 -62
- package/index.ts +0 -1
- package/mantine/create_field_view.tsx +94 -0
- package/mantine/create_list.tsx +9 -2
- package/mantine/hooks.tsx +18 -1
- package/mantine/specs/__snapshots__/field_view_hooks.tests.tsx.snap +153 -0
- package/mantine/specs/field_view_hooks.stories.tsx +112 -0
- package/mantine/specs/field_view_hooks.tests.tsx +15 -0
- package/package.json +1 -1
- package/types/merge_validators.ts +2 -2
- package/.out/mantine/field_view.d.ts +0 -18
- package/.out/mantine/field_view.js +0 -16
- package/mantine/field_view.tsx +0 -39
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Maybe, ElementOfArray, StringConcatOf, StringKeyOf as StringKeyOf$1, ExhaustiveArrayOfUnion, FriendlyExhaustiveArrayOfUnion } from '@strictly/base';
|
|
2
2
|
import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, MobxValueOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
|
|
3
|
-
import { ValueOf, SimplifyDeep, ReadonlyDeep, StringKeyOf, Simplify } from 'type-fest';
|
|
3
|
+
import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf, Simplify } from 'type-fest';
|
|
4
4
|
import { ComponentType, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, DependencyList } from 'react';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
|
|
@@ -73,7 +73,7 @@ declare function adapterFromPrototype<From, To, ValuePath extends string, Contex
|
|
|
73
73
|
declare function adapterFromPrototype<From, To, E, ValuePath extends string, Context>(converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>, prototype: From): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
|
|
74
74
|
declare function identityAdapter<V, ValuePath extends string, Context>(prototype: V, required?: boolean): FieldAdapterBuilder<V, V, never, ValuePath, Context>;
|
|
75
75
|
declare function trimmingStringAdapter<ValuePath extends string, Context>(): FieldAdapterBuilder<string, string, never, ValuePath, Context>;
|
|
76
|
-
declare function listAdapter<E, ValuePath extends string, Context>(): FieldAdapterBuilder<readonly E[], readonly E[], never, ValuePath, Context>;
|
|
76
|
+
declare function listAdapter<E, ValuePath extends string = string, Context = unknown>(): FieldAdapterBuilder<readonly E[], readonly E[], never, ValuePath, Context>;
|
|
77
77
|
|
|
78
78
|
type FieldAdaptersOfValues<FlattenedValues extends Readonly<Record<string, any>>, TypePathsToValuePaths extends Readonly<Record<keyof FlattenedValues, string>> = Readonly<Record<keyof FlattenedValues, any>>, Context = any> = {
|
|
79
79
|
readonly [K in keyof FlattenedValues]: FieldAdapter<FlattenedValues[K], any, any, TypePathsToValuePaths[K], Context>;
|
|
@@ -118,7 +118,10 @@ type FlattenedErrors<ValuePathsToAdapters extends Readonly<Record<string, FieldA
|
|
|
118
118
|
type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>, ValuePathsToTypePaths extends Readonly<Record<string, string>>> = keyof TypePathsToAdapters extends ValueOf<ValuePathsToTypePaths> ? {
|
|
119
119
|
readonly [K in keyof ValuePathsToTypePaths as unknown extends TypePathsToAdapters[ValuePathsToTypePaths[K]] ? never : K]: NonNullable<TypePathsToAdapters[ValuePathsToTypePaths[K]]>;
|
|
120
120
|
} : never;
|
|
121
|
-
|
|
121
|
+
type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>> = UnionToIntersection<{
|
|
122
|
+
readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
|
|
123
|
+
}[keyof TypePathsToAdapters] | {}>;
|
|
124
|
+
declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValuesOfType<T, '*'>, ContextType>, ContextType = ContextOf<TypePathsToAdapters>, ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>> {
|
|
122
125
|
readonly type: T;
|
|
123
126
|
protected readonly adapters: TypePathsToAdapters;
|
|
124
127
|
accessor value: MobxValueOfType<T>;
|
|
@@ -126,8 +129,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
126
129
|
accessor errors: FlattenedErrors<ValuePathsToAdapters>;
|
|
127
130
|
private readonly flattenedTypeDefs;
|
|
128
131
|
constructor(type: T, value: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters);
|
|
129
|
-
|
|
130
|
-
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>): ContextType;
|
|
132
|
+
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
|
|
131
133
|
get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
|
|
132
134
|
private get knownFields();
|
|
133
135
|
private maybeSynthesizeFieldByValuePath;
|
|
@@ -151,18 +153,18 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
/**
|
|
154
|
-
* Used to extract the supported value paths from a
|
|
156
|
+
* Used to extract the supported value paths from a model
|
|
155
157
|
*/
|
|
156
158
|
type ValuePathsOfModel<Model extends FormModel<any, any, any, any, any>> = Model extends FormModel<infer _1, infer _2, infer _3, infer _4, infer ValuePathsToAdapters> ? keyof ValuePathsToAdapters : never;
|
|
157
159
|
/**
|
|
158
160
|
* Used to extract the render type (so the value that is passed to the view) of a given value path
|
|
159
|
-
* from a
|
|
161
|
+
* from a model
|
|
160
162
|
*/
|
|
161
163
|
type ToValueOfModelValuePath<Model extends FormModel<any, any, any, any, any>, K extends ValuePathsOfModel<Model>> = Model extends FormModel<infer _1, infer _2, infer _3, infer _4, infer ValuePathsToAdapters> ? ToOfFieldAdapter<ValuePathsToAdapters[K]> : never;
|
|
162
164
|
/**
|
|
163
|
-
* Extracts the form fields from
|
|
165
|
+
* Extracts the form fields from a form model. The recommended way is to
|
|
164
166
|
* define the form fields explicitly and use that type to enforce the types
|
|
165
|
-
* of your converters, but generating the FormFields from your
|
|
167
|
+
* of your converters, but generating the FormFields from your model
|
|
166
168
|
* is less typing, albeit at the cost of potentially getting type errors
|
|
167
169
|
* reported a long way away from the source
|
|
168
170
|
*/
|
|
@@ -196,7 +198,7 @@ type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<K
|
|
|
196
198
|
} & {
|
|
197
199
|
readonly [K in Exclude<keyof FieldAdapters, Key>]: FieldAdapters[K];
|
|
198
200
|
}>;
|
|
199
|
-
type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1
|
|
201
|
+
type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1 & C2> : never : never;
|
|
200
202
|
declare function mergeAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Readonly<Record<string, Validator>>, Key extends keyof Validators = keyof Validators>(adapters: FieldAdapters, validators: Validators): MergedOfFieldAdaptersWithValidators<FieldAdapters, Validators, Key>;
|
|
201
203
|
|
|
202
204
|
type SubFormFieldAdapter<F extends FieldAdapter, ValuePath extends string> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, ValuePathOfFieldAdapter<F> extends StringConcatOf<'$', infer ValuePathSuffix> ? `${ValuePath}${ValuePathSuffix}` : string, ContextOfFieldAdapter<F>>;
|
|
@@ -283,21 +285,6 @@ declare function DefaultErrorRenderer({ error, }: InternalErrorRendererProps<any
|
|
|
283
285
|
|
|
284
286
|
type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
|
|
285
287
|
|
|
286
|
-
/**
|
|
287
|
-
* Displays current value and error of a field
|
|
288
|
-
*/
|
|
289
|
-
declare function FieldView<F extends Fields, K extends keyof F>({ fields, valuePath, children, }: {
|
|
290
|
-
fields: F;
|
|
291
|
-
valuePath: K;
|
|
292
|
-
children: (props: {
|
|
293
|
-
value: ValueTypeOfField<F[K]>;
|
|
294
|
-
error: ErrorOfField<F[K]> | undefined;
|
|
295
|
-
ErrorSink: ComponentType<{
|
|
296
|
-
error: ErrorOfField<F[K]>;
|
|
297
|
-
}>;
|
|
298
|
-
}) => JSX.Element;
|
|
299
|
-
}): react_jsx_runtime.JSX.Element;
|
|
300
|
-
|
|
301
288
|
type AllFieldsOfFields<F extends Fields> = {
|
|
302
289
|
[K in keyof F as ValueTypeOfField<F[K]> extends any ? K : never]: F[K];
|
|
303
290
|
};
|
|
@@ -350,6 +337,20 @@ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<Component
|
|
|
350
337
|
|
|
351
338
|
type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
|
|
352
339
|
|
|
340
|
+
type FieldViewProps<F extends Fields, K extends keyof F> = {
|
|
341
|
+
children: (props: {
|
|
342
|
+
value: ValueTypeOfField<F[K]>;
|
|
343
|
+
error: ErrorOfField<F[K]> | undefined;
|
|
344
|
+
ErrorSink: ComponentType<{
|
|
345
|
+
error: ErrorOfField<F[K]>;
|
|
346
|
+
}>;
|
|
347
|
+
onFocus: () => void;
|
|
348
|
+
onBlur: () => void;
|
|
349
|
+
onValueChange: (v: ValueTypeOfField<F[K]>) => void;
|
|
350
|
+
onSubmit: () => void;
|
|
351
|
+
}) => JSX.Element;
|
|
352
|
+
};
|
|
353
|
+
|
|
353
354
|
type CallbackMapper<ValuePath extends string> = {
|
|
354
355
|
<Cb extends (...args: any[]) => any>(cb: Cb): Parameters<Cb> extends [infer SubFormValuePath extends string, ...(infer Rest)] ? SubFormValuePath extends StringConcatOf<ValuePath, infer Postfix> ? (valuePath: `$${Postfix}`, ...rest: Rest) => ReturnType<Cb> : never : never;
|
|
355
356
|
};
|
|
@@ -400,7 +401,7 @@ type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
|
400
401
|
declare function SimpleSelect(props: SelectProps & {
|
|
401
402
|
onChange?: (value: string | null) => void;
|
|
402
403
|
}): react_jsx_runtime.JSX.Element;
|
|
403
|
-
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): MantineFormImpl<F>;
|
|
404
|
+
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): Omit<MantineFormImpl<F>, 'fields'>;
|
|
404
405
|
declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
405
406
|
private readonly textInputCache;
|
|
406
407
|
private readonly valueInputCache;
|
|
@@ -409,6 +410,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
409
410
|
private readonly radioCache;
|
|
410
411
|
private readonly pillCache;
|
|
411
412
|
private readonly listCache;
|
|
413
|
+
private readonly fieldViewCache;
|
|
412
414
|
private readonly fieldsViewCache;
|
|
413
415
|
private readonly formCache;
|
|
414
416
|
accessor fields: F;
|
|
@@ -430,6 +432,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
430
432
|
pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
|
|
431
433
|
pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>;
|
|
432
434
|
list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>, never>;
|
|
435
|
+
fieldView<K extends keyof AllFieldsOfFields<F>>(valuePath: K): ComponentType<FieldViewProps<F, K>>;
|
|
433
436
|
fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): FieldsView<K, MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>>;
|
|
434
437
|
form<K extends keyof AllFieldsOfFields<F>, P extends FormProps<ValueTypeOfField<F[K]>> = FormProps<ValueTypeOfField<F[K]>>>(valuePath: K, Form: ComponentType<P>): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>;
|
|
435
438
|
}
|
|
@@ -437,9 +440,9 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
437
440
|
type MergedOfValidators<Validators1 extends Partial<Readonly<Record<Keys, Validator>>>, Validators2 extends Partial<Readonly<Record<Keys, Validator>>>, Keys extends string = Extract<keyof Validators1 | keyof Validators2, string>> = Simplify<{
|
|
438
441
|
readonly [K in Keys]: undefined extends Validators1[K] ? undefined extends Validators2[K] ? never : Validators2[K] : undefined extends Validators2[K] ? Validators1[K] : MergedOfValidator<NonNullable<Validators1[K]>, NonNullable<Validators2[K]>>;
|
|
439
442
|
}>;
|
|
440
|
-
type MergedOfValidator<Validator1 extends Validator, Validator2 extends Validator> = Validator1 extends Validator<infer V, infer E1, infer P, infer
|
|
443
|
+
type MergedOfValidator<Validator1 extends Validator, Validator2 extends Validator> = Validator1 extends Validator<infer V, infer E1, infer P, infer C1> ? Validator2 extends Validator<V, infer E2, P, infer C2> ? Validator<V, E1 | E2, P, C1 & C2> : never : never;
|
|
441
444
|
declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Keys, Validator>>>, Validators2 extends Partial<Readonly<Record<Keys, Validator>>>, Keys extends string = Extract<keyof Validators1 | keyof Validators2, string>>(validators1: Validators1, validators2: Validators2): MergedOfValidators<Validators1, Validators2, Keys>;
|
|
442
445
|
|
|
443
446
|
declare function Empty(): null;
|
|
444
447
|
|
|
445
|
-
export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory,
|
|
448
|
+
export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormFieldsOfModel, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, type ToValueOfModelValuePath, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, type ValuePathOfFieldAdapter, type ValuePathsOfModel, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
|
package/dist/index.js
CHANGED
|
@@ -326,8 +326,8 @@ import {
|
|
|
326
326
|
observable,
|
|
327
327
|
runInAction
|
|
328
328
|
} from "mobx";
|
|
329
|
-
var _accessors_dec, _knownFields_dec, _fields_dec,
|
|
330
|
-
_value_dec = [observable.ref], _fieldOverrides_dec = [observable.shallow], _errors_dec = [observable.shallow],
|
|
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
331
|
var FormModel = class {
|
|
332
332
|
constructor(type, value, adapters) {
|
|
333
333
|
this.type = type;
|
|
@@ -339,13 +339,13 @@ var FormModel = class {
|
|
|
339
339
|
__publicField(this, "flattenedTypeDefs");
|
|
340
340
|
this.value = mobxCopy(type, value);
|
|
341
341
|
this.flattenedTypeDefs = flattenTypesOfType(type);
|
|
342
|
-
const contextValue = this.toContext(value);
|
|
343
342
|
const conversions = flattenValueTo(
|
|
344
343
|
type,
|
|
345
344
|
this.value,
|
|
346
345
|
() => {
|
|
347
346
|
},
|
|
348
|
-
(_t,
|
|
347
|
+
(_t, fieldValue, _setter, typePath, valuePath) => {
|
|
348
|
+
const contextValue = this.toContext(value, valuePath);
|
|
349
349
|
const adapter2 = this.adapters[typePath];
|
|
350
350
|
if (adapter2 == null) {
|
|
351
351
|
return;
|
|
@@ -357,16 +357,13 @@ var FormModel = class {
|
|
|
357
357
|
if (revert == null) {
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
360
|
-
return convert(
|
|
360
|
+
return convert(fieldValue, valuePath, contextValue);
|
|
361
361
|
}
|
|
362
362
|
);
|
|
363
363
|
this.fieldOverrides = map(conversions, function(_k, v) {
|
|
364
364
|
return v && [v.value];
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
|
-
get context() {
|
|
368
|
-
return this.toContext(this.value);
|
|
369
|
-
}
|
|
370
367
|
get fields() {
|
|
371
368
|
return new Proxy(
|
|
372
369
|
this.knownFields,
|
|
@@ -426,6 +423,7 @@ var FormModel = class {
|
|
|
426
423
|
const fieldOverride = this.fieldOverrides[valuePath];
|
|
427
424
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
428
425
|
const fieldTypeDef = this.flattenedTypeDefs[typePath];
|
|
426
|
+
const context = this.toContext(this.value, valuePath);
|
|
429
427
|
const {
|
|
430
428
|
value,
|
|
431
429
|
required,
|
|
@@ -434,11 +432,11 @@ var FormModel = class {
|
|
|
434
432
|
accessor != null ? accessor.value : fieldTypeDef != null ? mobxCopy(
|
|
435
433
|
fieldTypeDef,
|
|
436
434
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
437
|
-
create(valuePath,
|
|
438
|
-
) : create(valuePath,
|
|
435
|
+
create(valuePath, context)
|
|
436
|
+
) : create(valuePath, context),
|
|
439
437
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
440
438
|
valuePath,
|
|
441
|
-
|
|
439
|
+
context
|
|
442
440
|
);
|
|
443
441
|
const error = this.errors[valuePath];
|
|
444
442
|
return {
|
|
@@ -496,7 +494,9 @@ var FormModel = class {
|
|
|
496
494
|
const element = elementValue != null ? elementValue[0] : elementAdapter.create(
|
|
497
495
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
498
496
|
elementTypePath,
|
|
499
|
-
|
|
497
|
+
// TODO what can we use for the value path here?
|
|
498
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
499
|
+
this.toContext(this.value, valuePath)
|
|
500
500
|
);
|
|
501
501
|
const originalList = accessor.value;
|
|
502
502
|
const newList = [
|
|
@@ -614,7 +614,7 @@ var FormModel = class {
|
|
|
614
614
|
internalSetFieldValue(valuePath, value, displayValidation) {
|
|
615
615
|
const { revert } = this.getAdapterForValuePath(valuePath);
|
|
616
616
|
assertExists(revert, "setting value not supported {}", valuePath);
|
|
617
|
-
const conversion = revert(value, valuePath, this.
|
|
617
|
+
const conversion = revert(value, valuePath, this.toContext(this.value, valuePath));
|
|
618
618
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
619
619
|
return runInAction(() => {
|
|
620
620
|
this.fieldOverrides[valuePath] = [value];
|
|
@@ -654,10 +654,11 @@ var FormModel = class {
|
|
|
654
654
|
convert,
|
|
655
655
|
create
|
|
656
656
|
} = adapter2;
|
|
657
|
-
const
|
|
657
|
+
const context = this.toContext(this.value, valuePath);
|
|
658
|
+
const value = create(valuePath, context);
|
|
658
659
|
const {
|
|
659
660
|
value: displayValue
|
|
660
|
-
} = convert(value, valuePath,
|
|
661
|
+
} = convert(value, valuePath, context);
|
|
661
662
|
const key = valuePath;
|
|
662
663
|
runInAction(() => {
|
|
663
664
|
this.fieldOverrides[key] = [displayValue];
|
|
@@ -683,13 +684,14 @@ var FormModel = class {
|
|
|
683
684
|
} = this.getAdapterForValuePath(valuePath);
|
|
684
685
|
const fieldOverride = this.fieldOverrides[valuePath];
|
|
685
686
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
687
|
+
const context = this.toContext(this.value, valuePath);
|
|
686
688
|
const {
|
|
687
689
|
value: storedValue
|
|
688
690
|
} = convert(
|
|
689
|
-
accessor != null ? accessor.value : create(valuePath,
|
|
691
|
+
accessor != null ? accessor.value : create(valuePath, context),
|
|
690
692
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
691
693
|
valuePath,
|
|
692
|
-
|
|
694
|
+
context
|
|
693
695
|
);
|
|
694
696
|
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
695
697
|
const dirty = storedValue !== value;
|
|
@@ -697,12 +699,12 @@ var FormModel = class {
|
|
|
697
699
|
if (ignoreDefaultValue) {
|
|
698
700
|
const {
|
|
699
701
|
value: defaultDisplayValue
|
|
700
|
-
} = convert(create(valuePath,
|
|
702
|
+
} = convert(create(valuePath, context), valuePath, context);
|
|
701
703
|
if (defaultDisplayValue === value) {
|
|
702
704
|
return true;
|
|
703
705
|
}
|
|
704
706
|
}
|
|
705
|
-
const conversion = revert(value, valuePath,
|
|
707
|
+
const conversion = revert(value, valuePath, context);
|
|
706
708
|
return runInAction(() => {
|
|
707
709
|
switch (conversion.type) {
|
|
708
710
|
case 1 /* Failure */:
|
|
@@ -745,12 +747,13 @@ var FormModel = class {
|
|
|
745
747
|
return success;
|
|
746
748
|
}
|
|
747
749
|
const fieldOverride = this.fieldOverrides[adapterPath];
|
|
750
|
+
const context = this.toContext(this.value, valuePath);
|
|
748
751
|
const {
|
|
749
752
|
value: storedValue
|
|
750
|
-
} = convert(accessor.value, valuePath,
|
|
753
|
+
} = convert(accessor.value, valuePath, context);
|
|
751
754
|
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
752
755
|
const dirty = fieldOverride != null && fieldOverride[0] !== storedValue;
|
|
753
|
-
const conversion = revert(value, valuePath,
|
|
756
|
+
const conversion = revert(value, valuePath, context);
|
|
754
757
|
switch (conversion.type) {
|
|
755
758
|
case 1 /* Failure */:
|
|
756
759
|
this.errors[adapterPath] = conversion.error;
|
|
@@ -780,7 +783,6 @@ _errors = new WeakMap();
|
|
|
780
783
|
__decorateElement(_init, 4, "value", _value_dec, FormModel, _value);
|
|
781
784
|
__decorateElement(_init, 4, "fieldOverrides", _fieldOverrides_dec, FormModel, _fieldOverrides);
|
|
782
785
|
__decorateElement(_init, 4, "errors", _errors_dec, FormModel, _errors);
|
|
783
|
-
__decorateElement(_init, 2, "context", _context_dec, FormModel);
|
|
784
786
|
__decorateElement(_init, 2, "fields", _fields_dec, FormModel);
|
|
785
787
|
__decorateElement(_init, 2, "knownFields", _knownFields_dec, FormModel);
|
|
786
788
|
__decorateElement(_init, 2, "accessors", _accessors_dec, FormModel);
|
|
@@ -1149,34 +1151,6 @@ function DefaultErrorRenderer({
|
|
|
1149
1151
|
return JSON.stringify(error);
|
|
1150
1152
|
}
|
|
1151
1153
|
|
|
1152
|
-
// mantine/field_view.tsx
|
|
1153
|
-
import { Observer } from "mobx-react";
|
|
1154
|
-
|
|
1155
|
-
// util/empty.tsx
|
|
1156
|
-
function Empty() {
|
|
1157
|
-
return null;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
// mantine/field_view.tsx
|
|
1161
|
-
import { jsx } from "react/jsx-runtime";
|
|
1162
|
-
function FieldView({
|
|
1163
|
-
fields,
|
|
1164
|
-
valuePath,
|
|
1165
|
-
children
|
|
1166
|
-
}) {
|
|
1167
|
-
return /* @__PURE__ */ jsx(Observer, { children: () => {
|
|
1168
|
-
const {
|
|
1169
|
-
value,
|
|
1170
|
-
error
|
|
1171
|
-
} = fields[valuePath];
|
|
1172
|
-
return children({
|
|
1173
|
-
value,
|
|
1174
|
-
error,
|
|
1175
|
-
ErrorSink: Empty
|
|
1176
|
-
});
|
|
1177
|
-
} });
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
1154
|
// mantine/hooks.tsx
|
|
1181
1155
|
import {
|
|
1182
1156
|
Checkbox as CheckboxImpl,
|
|
@@ -1203,12 +1177,12 @@ import {
|
|
|
1203
1177
|
forwardRef,
|
|
1204
1178
|
useMemo
|
|
1205
1179
|
} from "react";
|
|
1206
|
-
import { jsx
|
|
1180
|
+
import { jsx } from "react/jsx-runtime";
|
|
1207
1181
|
function createSimplePartialComponent(Component, curriedProps) {
|
|
1208
1182
|
return forwardRef(
|
|
1209
1183
|
function(exposedProps, ref) {
|
|
1210
1184
|
const C = Component;
|
|
1211
|
-
return /* @__PURE__ */
|
|
1185
|
+
return /* @__PURE__ */ jsx(
|
|
1212
1186
|
C,
|
|
1213
1187
|
__spreadValues(__spreadValues({
|
|
1214
1188
|
ref
|
|
@@ -1248,7 +1222,7 @@ function createPartialComponent(Component, curriedPropsSource, additionalPropKey
|
|
|
1248
1222
|
]
|
|
1249
1223
|
);
|
|
1250
1224
|
const curriedProps = curriedPropsSource(additionalProps);
|
|
1251
|
-
return /* @__PURE__ */
|
|
1225
|
+
return /* @__PURE__ */ jsx(
|
|
1252
1226
|
C,
|
|
1253
1227
|
__spreadValues(__spreadValues({
|
|
1254
1228
|
ref
|
|
@@ -1315,7 +1289,7 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
|
|
|
1315
1289
|
]
|
|
1316
1290
|
);
|
|
1317
1291
|
const curriedProps = curriedPropsSource(additionalProps);
|
|
1318
|
-
return /* @__PURE__ */
|
|
1292
|
+
return /* @__PURE__ */ jsx(
|
|
1319
1293
|
C,
|
|
1320
1294
|
__spreadValues(__spreadValues({
|
|
1321
1295
|
ref
|
|
@@ -1346,7 +1320,7 @@ function usePartialObserverComponent(curriedPropsSource, deps, Component, additi
|
|
|
1346
1320
|
}
|
|
1347
1321
|
|
|
1348
1322
|
// mantine/create_checkbox.tsx
|
|
1349
|
-
import { jsx as
|
|
1323
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
1350
1324
|
function createCheckbox(valuePath, Checkbox) {
|
|
1351
1325
|
const onChange = (e) => {
|
|
1352
1326
|
var _a;
|
|
@@ -1383,7 +1357,7 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1383
1357
|
checked: value,
|
|
1384
1358
|
disabled: readonly,
|
|
1385
1359
|
required,
|
|
1386
|
-
error: error && /* @__PURE__ */
|
|
1360
|
+
error: error && /* @__PURE__ */ jsx2(ErrorRenderer, { error }),
|
|
1387
1361
|
onChange,
|
|
1388
1362
|
onFocus,
|
|
1389
1363
|
onBlur,
|
|
@@ -1397,6 +1371,80 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1397
1371
|
);
|
|
1398
1372
|
}
|
|
1399
1373
|
|
|
1374
|
+
// mantine/create_field_view.tsx
|
|
1375
|
+
import { Observer } from "mobx-react";
|
|
1376
|
+
import {
|
|
1377
|
+
useCallback as useCallback2
|
|
1378
|
+
} from "react";
|
|
1379
|
+
|
|
1380
|
+
// util/empty.tsx
|
|
1381
|
+
function Empty() {
|
|
1382
|
+
return null;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// mantine/create_field_view.tsx
|
|
1386
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1387
|
+
function FieldView({
|
|
1388
|
+
valuePath,
|
|
1389
|
+
form,
|
|
1390
|
+
children
|
|
1391
|
+
}) {
|
|
1392
|
+
const onFocus = useCallback2(() => {
|
|
1393
|
+
var _a;
|
|
1394
|
+
(_a = form.onFieldFocus) == null ? void 0 : _a.call(form, valuePath);
|
|
1395
|
+
}, [
|
|
1396
|
+
form,
|
|
1397
|
+
valuePath
|
|
1398
|
+
]);
|
|
1399
|
+
const onBlur = useCallback2(() => {
|
|
1400
|
+
var _a;
|
|
1401
|
+
(_a = form.onFieldBlur) == null ? void 0 : _a.call(form, valuePath);
|
|
1402
|
+
}, [
|
|
1403
|
+
form,
|
|
1404
|
+
valuePath
|
|
1405
|
+
]);
|
|
1406
|
+
const onValueChange = useCallback2((value) => {
|
|
1407
|
+
var _a;
|
|
1408
|
+
(_a = form.onFieldValueChange) == null ? void 0 : _a.call(form, valuePath, value);
|
|
1409
|
+
}, [
|
|
1410
|
+
form,
|
|
1411
|
+
valuePath
|
|
1412
|
+
]);
|
|
1413
|
+
const onSubmit = useCallback2(() => {
|
|
1414
|
+
var _a;
|
|
1415
|
+
(_a = form.onFieldSubmit) == null ? void 0 : _a.call(form, valuePath);
|
|
1416
|
+
}, [
|
|
1417
|
+
form,
|
|
1418
|
+
valuePath
|
|
1419
|
+
]);
|
|
1420
|
+
return /* @__PURE__ */ jsx3(Observer, { children: () => {
|
|
1421
|
+
const {
|
|
1422
|
+
value,
|
|
1423
|
+
error
|
|
1424
|
+
} = form.fields[valuePath];
|
|
1425
|
+
return children({
|
|
1426
|
+
value,
|
|
1427
|
+
error,
|
|
1428
|
+
ErrorSink: Empty,
|
|
1429
|
+
onFocus,
|
|
1430
|
+
onBlur,
|
|
1431
|
+
onValueChange,
|
|
1432
|
+
onSubmit
|
|
1433
|
+
});
|
|
1434
|
+
} });
|
|
1435
|
+
}
|
|
1436
|
+
function createFieldView(valuePath) {
|
|
1437
|
+
return (props) => {
|
|
1438
|
+
return /* @__PURE__ */ jsx3(
|
|
1439
|
+
FieldView,
|
|
1440
|
+
__spreadValues({
|
|
1441
|
+
form: this,
|
|
1442
|
+
valuePath
|
|
1443
|
+
}, props)
|
|
1444
|
+
);
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1400
1448
|
// mantine/create_fields_view.tsx
|
|
1401
1449
|
import {
|
|
1402
1450
|
jsonPathPrefix,
|
|
@@ -1468,13 +1516,13 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
1468
1516
|
// mantine/create_form.tsx
|
|
1469
1517
|
import { observer as observer3 } from "mobx-react";
|
|
1470
1518
|
import {
|
|
1471
|
-
useCallback as
|
|
1519
|
+
useCallback as useCallback3
|
|
1472
1520
|
} from "react";
|
|
1473
1521
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1474
1522
|
function createForm(valuePath, Form, observableProps) {
|
|
1475
1523
|
return observer3((props) => {
|
|
1476
1524
|
const { value } = observableProps.fields[valuePath];
|
|
1477
|
-
const onValueChange =
|
|
1525
|
+
const onValueChange = useCallback3((value2) => {
|
|
1478
1526
|
observableProps.onFieldValueChange(valuePath, value2);
|
|
1479
1527
|
}, []);
|
|
1480
1528
|
return /* @__PURE__ */ jsx5(
|
|
@@ -1488,7 +1536,10 @@ function createForm(valuePath, Form, observableProps) {
|
|
|
1488
1536
|
}
|
|
1489
1537
|
|
|
1490
1538
|
// mantine/create_list.tsx
|
|
1491
|
-
import {
|
|
1539
|
+
import {
|
|
1540
|
+
Fragment
|
|
1541
|
+
} from "react";
|
|
1542
|
+
import { Fragment as Fragment2, jsx as jsx6 } from "react/jsx-runtime";
|
|
1492
1543
|
function createList(valuePath, List) {
|
|
1493
1544
|
const propSource = () => {
|
|
1494
1545
|
const values = [...this.fields[valuePath].value];
|
|
@@ -1504,9 +1555,9 @@ function DefaultList({
|
|
|
1504
1555
|
listPath,
|
|
1505
1556
|
children
|
|
1506
1557
|
}) {
|
|
1507
|
-
return /* @__PURE__ */ jsx6(
|
|
1558
|
+
return /* @__PURE__ */ jsx6(Fragment2, { children: values.map(function(value, index) {
|
|
1508
1559
|
const valuePath = `${listPath}.${index}`;
|
|
1509
|
-
return children(valuePath, value, index);
|
|
1560
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: children(valuePath, value, index) }, valuePath);
|
|
1510
1561
|
}) });
|
|
1511
1562
|
}
|
|
1512
1563
|
|
|
@@ -1705,6 +1756,7 @@ function useMantineFormFields({
|
|
|
1705
1756
|
onFieldFocus,
|
|
1706
1757
|
onFieldSubmit,
|
|
1707
1758
|
fields
|
|
1759
|
+
// should use FieldView rather than observing fields directly from here
|
|
1708
1760
|
}) {
|
|
1709
1761
|
const form = useMemo2(
|
|
1710
1762
|
function() {
|
|
@@ -1773,6 +1825,9 @@ var MantineFormImpl = class {
|
|
|
1773
1825
|
__publicField(this, "listCache", new Cache(
|
|
1774
1826
|
createList.bind(this)
|
|
1775
1827
|
));
|
|
1828
|
+
__publicField(this, "fieldViewCache", new Cache(
|
|
1829
|
+
createFieldView.bind(this)
|
|
1830
|
+
));
|
|
1776
1831
|
__publicField(this, "fieldsViewCache", new Cache(
|
|
1777
1832
|
createFieldsView.bind(this)
|
|
1778
1833
|
));
|
|
@@ -1840,6 +1895,11 @@ var MantineFormImpl = class {
|
|
|
1840
1895
|
DefaultList
|
|
1841
1896
|
);
|
|
1842
1897
|
}
|
|
1898
|
+
fieldView(valuePath) {
|
|
1899
|
+
return this.fieldViewCache.retrieveOrCreate(
|
|
1900
|
+
valuePath
|
|
1901
|
+
);
|
|
1902
|
+
}
|
|
1843
1903
|
fieldsView(valuePath, FieldsView) {
|
|
1844
1904
|
return this.fieldsViewCache.retrieveOrCreate(
|
|
1845
1905
|
valuePath,
|
|
@@ -1907,7 +1967,6 @@ export {
|
|
|
1907
1967
|
AbstractSelectValueTypeConverter,
|
|
1908
1968
|
DefaultErrorRenderer,
|
|
1909
1969
|
Empty,
|
|
1910
|
-
FieldView,
|
|
1911
1970
|
FormModel,
|
|
1912
1971
|
IntegerToStringConverter,
|
|
1913
1972
|
NullableToBooleanConverter,
|
package/index.ts
CHANGED
|
@@ -17,7 +17,6 @@ export * from './field_converters/trimming_string_converter'
|
|
|
17
17
|
export * from './field_converters/validating_converter'
|
|
18
18
|
export * from './field_value_factories/prototyping_field_value_factory'
|
|
19
19
|
export * from './mantine/error_renderer'
|
|
20
|
-
export * from './mantine/field_view'
|
|
21
20
|
export * from './mantine/hooks'
|
|
22
21
|
export * from './types/error_of_field'
|
|
23
22
|
export * from './types/field'
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Observer } from 'mobx-react'
|
|
2
|
+
import {
|
|
3
|
+
type ComponentType,
|
|
4
|
+
useCallback,
|
|
5
|
+
} from 'react'
|
|
6
|
+
import { type AllFieldsOfFields } from 'types/all_fields_of_fields'
|
|
7
|
+
import { type ErrorOfField } from 'types/error_of_field'
|
|
8
|
+
import { type Fields } from 'types/field'
|
|
9
|
+
import { type ValueTypeOfField } from 'types/value_type_of_field'
|
|
10
|
+
import { Empty } from 'util/empty'
|
|
11
|
+
import { type MantineForm } from './types'
|
|
12
|
+
|
|
13
|
+
export type FieldViewProps<F extends Fields, K extends keyof F> = {
|
|
14
|
+
children: (props: {
|
|
15
|
+
value: ValueTypeOfField<F[K]>,
|
|
16
|
+
error: ErrorOfField<F[K]> | undefined,
|
|
17
|
+
ErrorSink: ComponentType<{ error: ErrorOfField<F[K]> }>,
|
|
18
|
+
onFocus: () => void,
|
|
19
|
+
onBlur: () => void,
|
|
20
|
+
onValueChange: (v: ValueTypeOfField<F[K]>) => void,
|
|
21
|
+
onSubmit: () => void,
|
|
22
|
+
}) => JSX.Element,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Displays current value and error of a field
|
|
27
|
+
*/
|
|
28
|
+
function FieldView<F extends Fields, K extends keyof F>({
|
|
29
|
+
valuePath,
|
|
30
|
+
form,
|
|
31
|
+
children,
|
|
32
|
+
}: FieldViewProps<F, K> & {
|
|
33
|
+
valuePath: K,
|
|
34
|
+
form: MantineForm<F>,
|
|
35
|
+
}) {
|
|
36
|
+
const onFocus = useCallback(() => {
|
|
37
|
+
form.onFieldFocus?.(valuePath)
|
|
38
|
+
}, [
|
|
39
|
+
form,
|
|
40
|
+
valuePath,
|
|
41
|
+
])
|
|
42
|
+
const onBlur = useCallback(() => {
|
|
43
|
+
form.onFieldBlur?.(valuePath)
|
|
44
|
+
}, [
|
|
45
|
+
form,
|
|
46
|
+
valuePath,
|
|
47
|
+
])
|
|
48
|
+
const onValueChange = useCallback((value: ValueTypeOfField<F[K]>) => {
|
|
49
|
+
form.onFieldValueChange?.(valuePath, value)
|
|
50
|
+
}, [
|
|
51
|
+
form,
|
|
52
|
+
valuePath,
|
|
53
|
+
])
|
|
54
|
+
const onSubmit = useCallback(() => {
|
|
55
|
+
form.onFieldSubmit?.(valuePath)
|
|
56
|
+
}, [
|
|
57
|
+
form,
|
|
58
|
+
valuePath,
|
|
59
|
+
])
|
|
60
|
+
return (
|
|
61
|
+
<Observer>
|
|
62
|
+
{() => {
|
|
63
|
+
const {
|
|
64
|
+
value,
|
|
65
|
+
error,
|
|
66
|
+
} = form.fields[valuePath]
|
|
67
|
+
return children({
|
|
68
|
+
value,
|
|
69
|
+
error,
|
|
70
|
+
ErrorSink: Empty,
|
|
71
|
+
onFocus,
|
|
72
|
+
onBlur,
|
|
73
|
+
onValueChange,
|
|
74
|
+
onSubmit,
|
|
75
|
+
})
|
|
76
|
+
}}
|
|
77
|
+
</Observer>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function createFieldView<
|
|
82
|
+
F extends Fields,
|
|
83
|
+
K extends keyof AllFieldsOfFields<F>,
|
|
84
|
+
>(this: MantineForm<F>, valuePath: K): ComponentType<FieldViewProps<F, K>> {
|
|
85
|
+
return (props: FieldViewProps<F, K>) => {
|
|
86
|
+
return (
|
|
87
|
+
<FieldView
|
|
88
|
+
form={this}
|
|
89
|
+
valuePath={valuePath}
|
|
90
|
+
{...props}
|
|
91
|
+
/>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
}
|
package/mantine/create_list.tsx
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type ElementOfArray } from '@strictly/base'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type ComponentType,
|
|
4
|
+
Fragment,
|
|
5
|
+
} from 'react'
|
|
3
6
|
import { type Fields } from 'types/field'
|
|
4
7
|
import { type ListFieldsOfFields } from 'types/list_fields_of_fields'
|
|
5
8
|
import { type ValueTypeOfField } from 'types/value_type_of_field'
|
|
@@ -54,7 +57,11 @@ export function DefaultList<
|
|
|
54
57
|
<>
|
|
55
58
|
{values.map(function (value, index) {
|
|
56
59
|
const valuePath: `${ListPath}.${number}` = `${listPath}.${index}`
|
|
57
|
-
return
|
|
60
|
+
return (
|
|
61
|
+
<Fragment key={valuePath}>
|
|
62
|
+
{children(valuePath, value, index)}
|
|
63
|
+
</Fragment>
|
|
64
|
+
)
|
|
58
65
|
})}
|
|
59
66
|
</>
|
|
60
67
|
)
|