@strictly/react-form 0.0.15 → 0.0.17
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 +9 -6
- package/.out/core/mobx/form_model.js +77 -42
- package/.out/core/mobx/specs/form_model.tests.js +80 -20
- package/.out/core/mobx/types.d.ts +4 -4
- package/.out/core/props.d.ts +2 -0
- 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 +14 -2
- 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/.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 +89 -47
- package/core/mobx/specs/form_model.tests.ts +131 -11
- package/core/mobx/types.ts +4 -4
- package/core/props.ts +4 -0
- package/dist/index.cjs +165 -89
- package/dist/index.d.cts +45 -40
- package/dist/index.d.ts +45 -40
- package/dist/index.js +162 -81
- package/index.ts +0 -1
- package/mantine/create_field_view.tsx +94 -0
- package/mantine/create_list.tsx +9 -2
- package/mantine/hooks.tsx +19 -2
- 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/.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.cts
CHANGED
|
@@ -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>;
|
|
@@ -97,6 +97,20 @@ type FormFieldsOfFieldAdapters<ValuePathsToTypePaths extends Readonly<Record<str
|
|
|
97
97
|
};
|
|
98
98
|
type FormFieldOfFieldAdapter<F extends FieldAdapter | undefined> = F extends FieldAdapter<infer _From, infer To, infer E> ? Field<To, E> : never;
|
|
99
99
|
|
|
100
|
+
type FieldsViewProps<F extends Fields> = {
|
|
101
|
+
fields: F;
|
|
102
|
+
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
103
|
+
onFieldFocus?(this: void, key: keyof F): void;
|
|
104
|
+
onFieldBlur?(this: void, key: keyof F): void;
|
|
105
|
+
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
106
|
+
};
|
|
107
|
+
type FormMode = 'edit' | 'create';
|
|
108
|
+
type FormProps<O> = {
|
|
109
|
+
value: O;
|
|
110
|
+
onValueChange: (value: O) => void;
|
|
111
|
+
mode: FormMode;
|
|
112
|
+
};
|
|
113
|
+
|
|
100
114
|
type FlattenedListTypesOfType<T extends Type> = FlattenedListTypesOfTypes<SimplifyDeep<FlattenedTypesOfType<T, null>>>;
|
|
101
115
|
type FlattenedListTypesOfTypes<T extends Readonly<Record<string, Type>>> = {
|
|
102
116
|
[K in keyof T as T[K]['definition'] extends ListTypeDef ? K : never]: T[K];
|
|
@@ -119,18 +133,20 @@ type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<
|
|
|
119
133
|
readonly [K in keyof ValuePathsToTypePaths as unknown extends TypePathsToAdapters[ValuePathsToTypePaths[K]] ? never : K]: NonNullable<TypePathsToAdapters[ValuePathsToTypePaths[K]]>;
|
|
120
134
|
} : never;
|
|
121
135
|
type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>> = UnionToIntersection<{
|
|
122
|
-
readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
|
|
123
|
-
}[keyof TypePathsToAdapters]>;
|
|
136
|
+
readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
|
|
137
|
+
}[keyof TypePathsToAdapters] | {}>;
|
|
124
138
|
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>> {
|
|
125
139
|
readonly type: T;
|
|
140
|
+
private readonly originalValue;
|
|
126
141
|
protected readonly adapters: TypePathsToAdapters;
|
|
142
|
+
protected readonly mode: FormMode;
|
|
127
143
|
accessor value: MobxValueOfType<T>;
|
|
128
144
|
accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
|
|
129
145
|
accessor errors: FlattenedErrors<ValuePathsToAdapters>;
|
|
130
146
|
private readonly flattenedTypeDefs;
|
|
131
|
-
constructor(type: T,
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
|
|
148
|
+
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
|
|
149
|
+
get forceMutableFields(): boolean;
|
|
134
150
|
get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
|
|
135
151
|
private get knownFields();
|
|
136
152
|
private maybeSynthesizeFieldByValuePath;
|
|
@@ -150,22 +166,22 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
150
166
|
clearAll(value: ValueOfType<T>): void;
|
|
151
167
|
isValuePathActive<K extends keyof ValuePathsToAdapters>(valuePath: K): boolean;
|
|
152
168
|
validateField<K extends keyof ValuePathsToAdapters>(valuePath: K, ignoreDefaultValue?: boolean): boolean;
|
|
153
|
-
validateAll(): boolean;
|
|
169
|
+
validateAll(force?: boolean): boolean;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
/**
|
|
157
|
-
* Used to extract the supported value paths from a
|
|
173
|
+
* Used to extract the supported value paths from a model
|
|
158
174
|
*/
|
|
159
175
|
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;
|
|
160
176
|
/**
|
|
161
177
|
* Used to extract the render type (so the value that is passed to the view) of a given value path
|
|
162
|
-
* from a
|
|
178
|
+
* from a model
|
|
163
179
|
*/
|
|
164
180
|
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;
|
|
165
181
|
/**
|
|
166
|
-
* Extracts the form fields from
|
|
182
|
+
* Extracts the form fields from a form model. The recommended way is to
|
|
167
183
|
* define the form fields explicitly and use that type to enforce the types
|
|
168
|
-
* of your converters, but generating the FormFields from your
|
|
184
|
+
* of your converters, but generating the FormFields from your model
|
|
169
185
|
* is less typing, albeit at the cost of potentially getting type errors
|
|
170
186
|
* reported a long way away from the source
|
|
171
187
|
*/
|
|
@@ -208,18 +224,6 @@ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, Type
|
|
|
208
224
|
};
|
|
209
225
|
declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, TypePathsToValuePaths extends Record<TypePath, string>>(subAdapters: SubAdapters, parentTypePath: TypePath): SubFormFieldAdapters<SubAdapters, TypePath, TypePathsToValuePaths[TypePath]>;
|
|
210
226
|
|
|
211
|
-
type FieldsViewProps<F extends Fields> = {
|
|
212
|
-
fields: F;
|
|
213
|
-
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
214
|
-
onFieldFocus?(this: void, key: keyof F): void;
|
|
215
|
-
onFieldBlur?(this: void, key: keyof F): void;
|
|
216
|
-
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
217
|
-
};
|
|
218
|
-
type FormProps<O> = {
|
|
219
|
-
value: O;
|
|
220
|
-
onValueChange: (value: O) => void;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
227
|
declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
|
|
224
228
|
private readonly isNanError;
|
|
225
229
|
private readonly base;
|
|
@@ -286,21 +290,6 @@ declare function DefaultErrorRenderer({ error, }: InternalErrorRendererProps<any
|
|
|
286
290
|
|
|
287
291
|
type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
|
|
288
292
|
|
|
289
|
-
/**
|
|
290
|
-
* Displays current value and error of a field
|
|
291
|
-
*/
|
|
292
|
-
declare function FieldView<F extends Fields, K extends keyof F>({ fields, valuePath, children, }: {
|
|
293
|
-
fields: F;
|
|
294
|
-
valuePath: K;
|
|
295
|
-
children: (props: {
|
|
296
|
-
value: ValueTypeOfField<F[K]>;
|
|
297
|
-
error: ErrorOfField<F[K]> | undefined;
|
|
298
|
-
ErrorSink: ComponentType<{
|
|
299
|
-
error: ErrorOfField<F[K]>;
|
|
300
|
-
}>;
|
|
301
|
-
}) => JSX.Element;
|
|
302
|
-
}): react_jsx_runtime.JSX.Element;
|
|
303
|
-
|
|
304
293
|
type AllFieldsOfFields<F extends Fields> = {
|
|
305
294
|
[K in keyof F as ValueTypeOfField<F[K]> extends any ? K : never]: F[K];
|
|
306
295
|
};
|
|
@@ -353,6 +342,20 @@ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<Component
|
|
|
353
342
|
|
|
354
343
|
type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
|
|
355
344
|
|
|
345
|
+
type FieldViewProps<F extends Fields, K extends keyof F> = {
|
|
346
|
+
children: (props: {
|
|
347
|
+
value: ValueTypeOfField<F[K]>;
|
|
348
|
+
error: ErrorOfField<F[K]> | undefined;
|
|
349
|
+
ErrorSink: ComponentType<{
|
|
350
|
+
error: ErrorOfField<F[K]>;
|
|
351
|
+
}>;
|
|
352
|
+
onFocus: () => void;
|
|
353
|
+
onBlur: () => void;
|
|
354
|
+
onValueChange: (v: ValueTypeOfField<F[K]>) => void;
|
|
355
|
+
onSubmit: () => void;
|
|
356
|
+
}) => JSX.Element;
|
|
357
|
+
};
|
|
358
|
+
|
|
356
359
|
type CallbackMapper<ValuePath extends string> = {
|
|
357
360
|
<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;
|
|
358
361
|
};
|
|
@@ -403,7 +406,7 @@ type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
|
403
406
|
declare function SimpleSelect(props: SelectProps & {
|
|
404
407
|
onChange?: (value: string | null) => void;
|
|
405
408
|
}): react_jsx_runtime.JSX.Element;
|
|
406
|
-
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): MantineFormImpl<F>;
|
|
409
|
+
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): Omit<MantineFormImpl<F>, 'fields'>;
|
|
407
410
|
declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
408
411
|
private readonly textInputCache;
|
|
409
412
|
private readonly valueInputCache;
|
|
@@ -412,6 +415,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
412
415
|
private readonly radioCache;
|
|
413
416
|
private readonly pillCache;
|
|
414
417
|
private readonly listCache;
|
|
418
|
+
private readonly fieldViewCache;
|
|
415
419
|
private readonly fieldsViewCache;
|
|
416
420
|
private readonly formCache;
|
|
417
421
|
accessor fields: F;
|
|
@@ -433,6 +437,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
433
437
|
pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
|
|
434
438
|
pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>;
|
|
435
439
|
list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>, never>;
|
|
440
|
+
fieldView<K extends keyof AllFieldsOfFields<F>>(valuePath: K): ComponentType<FieldViewProps<F, K>>;
|
|
436
441
|
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>>;
|
|
437
442
|
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>;
|
|
438
443
|
}
|
|
@@ -445,4 +450,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
|
|
|
445
450
|
|
|
446
451
|
declare function Empty(): null;
|
|
447
452
|
|
|
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,
|
|
453
|
+
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, type FormMode, 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.d.ts
CHANGED
|
@@ -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>;
|
|
@@ -97,6 +97,20 @@ type FormFieldsOfFieldAdapters<ValuePathsToTypePaths extends Readonly<Record<str
|
|
|
97
97
|
};
|
|
98
98
|
type FormFieldOfFieldAdapter<F extends FieldAdapter | undefined> = F extends FieldAdapter<infer _From, infer To, infer E> ? Field<To, E> : never;
|
|
99
99
|
|
|
100
|
+
type FieldsViewProps<F extends Fields> = {
|
|
101
|
+
fields: F;
|
|
102
|
+
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
103
|
+
onFieldFocus?(this: void, key: keyof F): void;
|
|
104
|
+
onFieldBlur?(this: void, key: keyof F): void;
|
|
105
|
+
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
106
|
+
};
|
|
107
|
+
type FormMode = 'edit' | 'create';
|
|
108
|
+
type FormProps<O> = {
|
|
109
|
+
value: O;
|
|
110
|
+
onValueChange: (value: O) => void;
|
|
111
|
+
mode: FormMode;
|
|
112
|
+
};
|
|
113
|
+
|
|
100
114
|
type FlattenedListTypesOfType<T extends Type> = FlattenedListTypesOfTypes<SimplifyDeep<FlattenedTypesOfType<T, null>>>;
|
|
101
115
|
type FlattenedListTypesOfTypes<T extends Readonly<Record<string, Type>>> = {
|
|
102
116
|
[K in keyof T as T[K]['definition'] extends ListTypeDef ? K : never]: T[K];
|
|
@@ -119,18 +133,20 @@ type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<
|
|
|
119
133
|
readonly [K in keyof ValuePathsToTypePaths as unknown extends TypePathsToAdapters[ValuePathsToTypePaths[K]] ? never : K]: NonNullable<TypePathsToAdapters[ValuePathsToTypePaths[K]]>;
|
|
120
134
|
} : never;
|
|
121
135
|
type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>> = UnionToIntersection<{
|
|
122
|
-
readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
|
|
123
|
-
}[keyof TypePathsToAdapters]>;
|
|
136
|
+
readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
|
|
137
|
+
}[keyof TypePathsToAdapters] | {}>;
|
|
124
138
|
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>> {
|
|
125
139
|
readonly type: T;
|
|
140
|
+
private readonly originalValue;
|
|
126
141
|
protected readonly adapters: TypePathsToAdapters;
|
|
142
|
+
protected readonly mode: FormMode;
|
|
127
143
|
accessor value: MobxValueOfType<T>;
|
|
128
144
|
accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
|
|
129
145
|
accessor errors: FlattenedErrors<ValuePathsToAdapters>;
|
|
130
146
|
private readonly flattenedTypeDefs;
|
|
131
|
-
constructor(type: T,
|
|
132
|
-
|
|
133
|
-
|
|
147
|
+
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
|
|
148
|
+
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
|
|
149
|
+
get forceMutableFields(): boolean;
|
|
134
150
|
get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
|
|
135
151
|
private get knownFields();
|
|
136
152
|
private maybeSynthesizeFieldByValuePath;
|
|
@@ -150,22 +166,22 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
150
166
|
clearAll(value: ValueOfType<T>): void;
|
|
151
167
|
isValuePathActive<K extends keyof ValuePathsToAdapters>(valuePath: K): boolean;
|
|
152
168
|
validateField<K extends keyof ValuePathsToAdapters>(valuePath: K, ignoreDefaultValue?: boolean): boolean;
|
|
153
|
-
validateAll(): boolean;
|
|
169
|
+
validateAll(force?: boolean): boolean;
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
/**
|
|
157
|
-
* Used to extract the supported value paths from a
|
|
173
|
+
* Used to extract the supported value paths from a model
|
|
158
174
|
*/
|
|
159
175
|
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;
|
|
160
176
|
/**
|
|
161
177
|
* Used to extract the render type (so the value that is passed to the view) of a given value path
|
|
162
|
-
* from a
|
|
178
|
+
* from a model
|
|
163
179
|
*/
|
|
164
180
|
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;
|
|
165
181
|
/**
|
|
166
|
-
* Extracts the form fields from
|
|
182
|
+
* Extracts the form fields from a form model. The recommended way is to
|
|
167
183
|
* define the form fields explicitly and use that type to enforce the types
|
|
168
|
-
* of your converters, but generating the FormFields from your
|
|
184
|
+
* of your converters, but generating the FormFields from your model
|
|
169
185
|
* is less typing, albeit at the cost of potentially getting type errors
|
|
170
186
|
* reported a long way away from the source
|
|
171
187
|
*/
|
|
@@ -208,18 +224,6 @@ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, Type
|
|
|
208
224
|
};
|
|
209
225
|
declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, TypePathsToValuePaths extends Record<TypePath, string>>(subAdapters: SubAdapters, parentTypePath: TypePath): SubFormFieldAdapters<SubAdapters, TypePath, TypePathsToValuePaths[TypePath]>;
|
|
210
226
|
|
|
211
|
-
type FieldsViewProps<F extends Fields> = {
|
|
212
|
-
fields: F;
|
|
213
|
-
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
214
|
-
onFieldFocus?(this: void, key: keyof F): void;
|
|
215
|
-
onFieldBlur?(this: void, key: keyof F): void;
|
|
216
|
-
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
217
|
-
};
|
|
218
|
-
type FormProps<O> = {
|
|
219
|
-
value: O;
|
|
220
|
-
onValueChange: (value: O) => void;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
227
|
declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
|
|
224
228
|
private readonly isNanError;
|
|
225
229
|
private readonly base;
|
|
@@ -286,21 +290,6 @@ declare function DefaultErrorRenderer({ error, }: InternalErrorRendererProps<any
|
|
|
286
290
|
|
|
287
291
|
type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
|
|
288
292
|
|
|
289
|
-
/**
|
|
290
|
-
* Displays current value and error of a field
|
|
291
|
-
*/
|
|
292
|
-
declare function FieldView<F extends Fields, K extends keyof F>({ fields, valuePath, children, }: {
|
|
293
|
-
fields: F;
|
|
294
|
-
valuePath: K;
|
|
295
|
-
children: (props: {
|
|
296
|
-
value: ValueTypeOfField<F[K]>;
|
|
297
|
-
error: ErrorOfField<F[K]> | undefined;
|
|
298
|
-
ErrorSink: ComponentType<{
|
|
299
|
-
error: ErrorOfField<F[K]>;
|
|
300
|
-
}>;
|
|
301
|
-
}) => JSX.Element;
|
|
302
|
-
}): react_jsx_runtime.JSX.Element;
|
|
303
|
-
|
|
304
293
|
type AllFieldsOfFields<F extends Fields> = {
|
|
305
294
|
[K in keyof F as ValueTypeOfField<F[K]> extends any ? K : never]: F[K];
|
|
306
295
|
};
|
|
@@ -353,6 +342,20 @@ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<Component
|
|
|
353
342
|
|
|
354
343
|
type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
|
|
355
344
|
|
|
345
|
+
type FieldViewProps<F extends Fields, K extends keyof F> = {
|
|
346
|
+
children: (props: {
|
|
347
|
+
value: ValueTypeOfField<F[K]>;
|
|
348
|
+
error: ErrorOfField<F[K]> | undefined;
|
|
349
|
+
ErrorSink: ComponentType<{
|
|
350
|
+
error: ErrorOfField<F[K]>;
|
|
351
|
+
}>;
|
|
352
|
+
onFocus: () => void;
|
|
353
|
+
onBlur: () => void;
|
|
354
|
+
onValueChange: (v: ValueTypeOfField<F[K]>) => void;
|
|
355
|
+
onSubmit: () => void;
|
|
356
|
+
}) => JSX.Element;
|
|
357
|
+
};
|
|
358
|
+
|
|
356
359
|
type CallbackMapper<ValuePath extends string> = {
|
|
357
360
|
<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;
|
|
358
361
|
};
|
|
@@ -403,7 +406,7 @@ type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
|
403
406
|
declare function SimpleSelect(props: SelectProps & {
|
|
404
407
|
onChange?: (value: string | null) => void;
|
|
405
408
|
}): react_jsx_runtime.JSX.Element;
|
|
406
|
-
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): MantineFormImpl<F>;
|
|
409
|
+
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): Omit<MantineFormImpl<F>, 'fields'>;
|
|
407
410
|
declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
408
411
|
private readonly textInputCache;
|
|
409
412
|
private readonly valueInputCache;
|
|
@@ -412,6 +415,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
412
415
|
private readonly radioCache;
|
|
413
416
|
private readonly pillCache;
|
|
414
417
|
private readonly listCache;
|
|
418
|
+
private readonly fieldViewCache;
|
|
415
419
|
private readonly fieldsViewCache;
|
|
416
420
|
private readonly formCache;
|
|
417
421
|
accessor fields: F;
|
|
@@ -433,6 +437,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
433
437
|
pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
|
|
434
438
|
pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>;
|
|
435
439
|
list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>, never>;
|
|
440
|
+
fieldView<K extends keyof AllFieldsOfFields<F>>(valuePath: K): ComponentType<FieldViewProps<F, K>>;
|
|
436
441
|
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>>;
|
|
437
442
|
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>;
|
|
438
443
|
}
|
|
@@ -445,4 +450,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
|
|
|
445
450
|
|
|
446
451
|
declare function Empty(): null;
|
|
447
452
|
|
|
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,
|
|
453
|
+
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, type FormMode, 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 };
|