@strictly/react-form 0.0.5 → 0.0.6
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/hooks.d.ts +10 -0
- package/.out/core/mobx/hooks.js +47 -0
- package/.out/core/props.d.ts +2 -2
- package/.out/index.d.ts +1 -0
- package/.out/index.js +1 -0
- package/.out/mantine/create_fields_view.d.ts +7 -0
- package/.out/mantine/{create_sub_form.js → create_fields_view.js} +4 -5
- package/.out/mantine/create_form.d.ts +7 -0
- package/.out/mantine/create_form.js +13 -0
- package/.out/mantine/hooks.d.ts +6 -4
- package/.out/mantine/hooks.js +17 -7
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/checkbox_hooks.stories.js +2 -2
- package/.out/mantine/specs/{sub_form_hooks.stories.d.ts → fields_view_hooks.stories.d.ts} +2 -2
- package/.out/mantine/specs/{sub_form_hooks.stories.js → fields_view_hooks.stories.js} +9 -8
- package/.out/mantine/specs/fields_view_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/fields_view_hooks.tests.js +12 -0
- package/.out/mantine/specs/form_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/form_hooks.stories.js +60 -0
- package/.out/mantine/specs/form_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/form_hooks.tests.js +12 -0
- package/.out/mantine/specs/list_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/list_hooks.stories.js +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.js +2 -2
- package/.out/mantine/specs/select_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/select_hooks.stories.js +2 -2
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/text_input_hooks.stories.js +2 -2
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/value_input_hooks.stories.js +2 -2
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/core/mobx/hooks.ts +94 -0
- package/core/props.ts +2 -2
- package/dist/index.cjs +167 -77
- package/dist/index.d.cts +42 -34
- package/dist/index.d.ts +42 -34
- package/dist/index.js +162 -68
- package/index.ts +1 -0
- package/mantine/{create_sub_form.tsx → create_fields_view.tsx} +27 -16
- package/mantine/create_form.tsx +43 -0
- package/mantine/hooks.tsx +48 -14
- package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +460 -0
- package/mantine/specs/__snapshots__/form_hooks.tests.tsx.snap +273 -0
- package/mantine/specs/checkbox_hooks.stories.tsx +4 -4
- package/mantine/specs/{sub_form_hooks.stories.tsx → fields_view_hooks.stories.tsx} +23 -11
- package/mantine/specs/fields_view_hooks.tests.tsx +15 -0
- package/mantine/specs/form_hooks.stories.tsx +107 -0
- package/mantine/specs/form_hooks.tests.tsx +15 -0
- package/mantine/specs/list_hooks.stories.tsx +4 -4
- package/mantine/specs/radio_group_hooks.stories.tsx +4 -4
- package/mantine/specs/select_hooks.stories.tsx +4 -4
- package/mantine/specs/text_input_hooks.stories.tsx +4 -4
- package/mantine/specs/value_input_hooks.stories.tsx +4 -4
- package/package.json +1 -1
- package/.out/mantine/create_sub_form.d.ts +0 -6
package/dist/index.d.cts
CHANGED
|
@@ -149,29 +149,17 @@ declare class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record
|
|
|
149
149
|
get accessors(): Readonly<Record<string, Accessor>>;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
type
|
|
153
|
-
|
|
152
|
+
type FieldsViewProps<F extends Fields> = {
|
|
153
|
+
fields: F;
|
|
154
|
+
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
155
|
+
onFieldFocus?(this: void, key: keyof F): void;
|
|
156
|
+
onFieldBlur?(this: void, key: keyof F): void;
|
|
157
|
+
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
154
158
|
};
|
|
155
|
-
type
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
type TosOfFieldAdapters<FieldAdapters extends Readonly<Record<string, FieldAdapter>>> = {
|
|
159
|
-
[K in keyof FieldAdapters]: ToOfFieldAdapter<FieldAdapters[K]>;
|
|
160
|
-
}[keyof FieldAdapters];
|
|
161
|
-
declare function mergeFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context>(fieldAdapters: FieldAdapters, converter: TwoWayFieldConverter<TosOfFieldAdapters<FieldAdapters>, TosOfFieldAdapters<FieldAdapters>, E, ValuePathsOfFieldAdapters<FieldAdapters>, Context>): MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters, E, Context>;
|
|
162
|
-
|
|
163
|
-
type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Partial<Readonly<Record<string, Validator>>>, Key extends keyof Validators = keyof Validators> = Simplify<{
|
|
164
|
-
readonly [K in Key]: MergedOfFieldAdapterWithValidator<FieldAdapters[K], Validators[K]>;
|
|
165
|
-
} & {
|
|
166
|
-
readonly [K in Exclude<keyof FieldAdapters, Key>]: FieldAdapters[K];
|
|
167
|
-
}>;
|
|
168
|
-
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;
|
|
169
|
-
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>;
|
|
170
|
-
|
|
171
|
-
type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
|
|
172
|
-
[K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
|
|
159
|
+
type FormProps<O> = {
|
|
160
|
+
value: O;
|
|
161
|
+
onValueChange: (value: O) => void;
|
|
173
162
|
};
|
|
174
|
-
declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
|
|
175
163
|
|
|
176
164
|
/**
|
|
177
165
|
* Used to extract the supported value paths from a presenter
|
|
@@ -191,17 +179,35 @@ type ToValueOfPresenterValuePath<Presenter extends FormPresenter<any, any, any,
|
|
|
191
179
|
*/
|
|
192
180
|
type FormFieldsOfPresenter<Presenter extends FormPresenter<any, any, any, any>> = Presenter extends FormPresenter<infer _1, infer _2, infer _3, infer ValuePathsToAdapters> ? FlattenedConvertedFieldsOf<ValuePathsToAdapters> : never;
|
|
193
181
|
|
|
194
|
-
type
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
182
|
+
type ValueOfPresenter<P extends FormPresenter<any, any, any, any>> = P extends FormPresenter<infer T, any, any, any> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
|
|
183
|
+
type ModelOfPresenter<P extends FormPresenter<any, any, any, any>> = ReturnType<P['createModel']>;
|
|
184
|
+
declare function useDefaultMobxFormHooks<P extends FormPresenter<any, any, any, any>>(presenter: P, value: ValueOfPresenter<P>, onValidSubmit?: <Path extends ValuePathsOfPresenter<P>>(model: ModelOfPresenter<P>, valuePath: Path) => void): {
|
|
185
|
+
model: ModelOfPresenter<P>;
|
|
186
|
+
} & Omit<FieldsViewProps<ModelOfPresenter<P>['fields']>, 'fields'>;
|
|
187
|
+
|
|
188
|
+
type MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context> = {
|
|
189
|
+
[K in keyof FieldAdapters]: FieldAdapter<FromOfFieldAdapter<FieldAdapters[K]>, ToOfFieldAdapter<FieldAdapters[K]>, ErrorOfFieldAdapter<FieldAdapters[K]> | E, ValuePathOfFieldAdapter<FieldAdapters[K]>, Context>;
|
|
200
190
|
};
|
|
201
|
-
type
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
type ValuePathsOfFieldAdapters<FieldAdapters extends Readonly<Record<string, FieldAdapter>>> = {
|
|
192
|
+
[K in keyof FieldAdapters]: ValuePathOfFieldAdapter<FieldAdapters[K]>;
|
|
193
|
+
}[keyof FieldAdapters];
|
|
194
|
+
type TosOfFieldAdapters<FieldAdapters extends Readonly<Record<string, FieldAdapter>>> = {
|
|
195
|
+
[K in keyof FieldAdapters]: ToOfFieldAdapter<FieldAdapters[K]>;
|
|
196
|
+
}[keyof FieldAdapters];
|
|
197
|
+
declare function mergeFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context>(fieldAdapters: FieldAdapters, converter: TwoWayFieldConverter<TosOfFieldAdapters<FieldAdapters>, TosOfFieldAdapters<FieldAdapters>, E, ValuePathsOfFieldAdapters<FieldAdapters>, Context>): MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters, E, Context>;
|
|
198
|
+
|
|
199
|
+
type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Partial<Readonly<Record<string, Validator>>>, Key extends keyof Validators = keyof Validators> = Simplify<{
|
|
200
|
+
readonly [K in Key]: MergedOfFieldAdapterWithValidator<FieldAdapters[K], Validators[K]>;
|
|
201
|
+
} & {
|
|
202
|
+
readonly [K in Exclude<keyof FieldAdapters, Key>]: FieldAdapters[K];
|
|
203
|
+
}>;
|
|
204
|
+
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;
|
|
205
|
+
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>;
|
|
206
|
+
|
|
207
|
+
type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
|
|
208
|
+
[K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
|
|
204
209
|
};
|
|
210
|
+
declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
|
|
205
211
|
|
|
206
212
|
declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
|
|
207
213
|
private readonly isNanError;
|
|
@@ -360,7 +366,7 @@ type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
|
360
366
|
declare function SimpleSelect(props: SelectProps & {
|
|
361
367
|
onChange?: (value: string | null) => void;
|
|
362
368
|
}): react_jsx_runtime.JSX.Element;
|
|
363
|
-
declare function
|
|
369
|
+
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): MantineFormImpl<F>;
|
|
364
370
|
declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
365
371
|
private readonly textInputCache;
|
|
366
372
|
private readonly valueInputCache;
|
|
@@ -369,7 +375,8 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
369
375
|
private readonly radioCache;
|
|
370
376
|
private readonly pillCache;
|
|
371
377
|
private readonly listCache;
|
|
372
|
-
private readonly
|
|
378
|
+
private readonly fieldsViewCache;
|
|
379
|
+
private readonly formCache;
|
|
373
380
|
accessor fields: F;
|
|
374
381
|
onFieldValueChange: <K extends keyof F>(this: void, key: K, value: F[K]['value']) => void;
|
|
375
382
|
onFieldFocus: ((this: void, key: keyof F) => void) | undefined;
|
|
@@ -389,7 +396,8 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
389
396
|
pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
|
|
390
397
|
pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P>;
|
|
391
398
|
list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>>;
|
|
392
|
-
|
|
399
|
+
fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P>;
|
|
400
|
+
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>;
|
|
393
401
|
}
|
|
394
402
|
|
|
395
403
|
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<{
|
|
@@ -398,4 +406,4 @@ type MergedOfValidators<Validators1 extends Partial<Readonly<Record<Keys, Valida
|
|
|
398
406
|
type MergedOfValidator<Validator1 extends Validator, Validator2 extends Validator> = Validator1 extends Validator<infer V, infer E1, infer P, infer C> ? Validator2 extends Validator<V, infer E2, P, C> ? Validator<V, E1 | E2, P, C> : never : never;
|
|
399
407
|
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>;
|
|
400
408
|
|
|
401
|
-
export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, DefaultErrorRenderer, type
|
|
409
|
+
export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, DefaultErrorRenderer, 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 FormFieldsOfPresenter, FormModel, FormPresenter, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, type ToValueOfPresenterValuePath, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, type ValuePathOfFieldAdapter, type ValuePathsOfPresenter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
|
package/dist/index.d.ts
CHANGED
|
@@ -149,29 +149,17 @@ declare class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record
|
|
|
149
149
|
get accessors(): Readonly<Record<string, Accessor>>;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
type
|
|
153
|
-
|
|
152
|
+
type FieldsViewProps<F extends Fields> = {
|
|
153
|
+
fields: F;
|
|
154
|
+
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
155
|
+
onFieldFocus?(this: void, key: keyof F): void;
|
|
156
|
+
onFieldBlur?(this: void, key: keyof F): void;
|
|
157
|
+
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
154
158
|
};
|
|
155
|
-
type
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
type TosOfFieldAdapters<FieldAdapters extends Readonly<Record<string, FieldAdapter>>> = {
|
|
159
|
-
[K in keyof FieldAdapters]: ToOfFieldAdapter<FieldAdapters[K]>;
|
|
160
|
-
}[keyof FieldAdapters];
|
|
161
|
-
declare function mergeFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context>(fieldAdapters: FieldAdapters, converter: TwoWayFieldConverter<TosOfFieldAdapters<FieldAdapters>, TosOfFieldAdapters<FieldAdapters>, E, ValuePathsOfFieldAdapters<FieldAdapters>, Context>): MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters, E, Context>;
|
|
162
|
-
|
|
163
|
-
type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Partial<Readonly<Record<string, Validator>>>, Key extends keyof Validators = keyof Validators> = Simplify<{
|
|
164
|
-
readonly [K in Key]: MergedOfFieldAdapterWithValidator<FieldAdapters[K], Validators[K]>;
|
|
165
|
-
} & {
|
|
166
|
-
readonly [K in Exclude<keyof FieldAdapters, Key>]: FieldAdapters[K];
|
|
167
|
-
}>;
|
|
168
|
-
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;
|
|
169
|
-
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>;
|
|
170
|
-
|
|
171
|
-
type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
|
|
172
|
-
[K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
|
|
159
|
+
type FormProps<O> = {
|
|
160
|
+
value: O;
|
|
161
|
+
onValueChange: (value: O) => void;
|
|
173
162
|
};
|
|
174
|
-
declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
|
|
175
163
|
|
|
176
164
|
/**
|
|
177
165
|
* Used to extract the supported value paths from a presenter
|
|
@@ -191,17 +179,35 @@ type ToValueOfPresenterValuePath<Presenter extends FormPresenter<any, any, any,
|
|
|
191
179
|
*/
|
|
192
180
|
type FormFieldsOfPresenter<Presenter extends FormPresenter<any, any, any, any>> = Presenter extends FormPresenter<infer _1, infer _2, infer _3, infer ValuePathsToAdapters> ? FlattenedConvertedFieldsOf<ValuePathsToAdapters> : never;
|
|
193
181
|
|
|
194
|
-
type
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
182
|
+
type ValueOfPresenter<P extends FormPresenter<any, any, any, any>> = P extends FormPresenter<infer T, any, any, any> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
|
|
183
|
+
type ModelOfPresenter<P extends FormPresenter<any, any, any, any>> = ReturnType<P['createModel']>;
|
|
184
|
+
declare function useDefaultMobxFormHooks<P extends FormPresenter<any, any, any, any>>(presenter: P, value: ValueOfPresenter<P>, onValidSubmit?: <Path extends ValuePathsOfPresenter<P>>(model: ModelOfPresenter<P>, valuePath: Path) => void): {
|
|
185
|
+
model: ModelOfPresenter<P>;
|
|
186
|
+
} & Omit<FieldsViewProps<ModelOfPresenter<P>['fields']>, 'fields'>;
|
|
187
|
+
|
|
188
|
+
type MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context> = {
|
|
189
|
+
[K in keyof FieldAdapters]: FieldAdapter<FromOfFieldAdapter<FieldAdapters[K]>, ToOfFieldAdapter<FieldAdapters[K]>, ErrorOfFieldAdapter<FieldAdapters[K]> | E, ValuePathOfFieldAdapter<FieldAdapters[K]>, Context>;
|
|
200
190
|
};
|
|
201
|
-
type
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
type ValuePathsOfFieldAdapters<FieldAdapters extends Readonly<Record<string, FieldAdapter>>> = {
|
|
192
|
+
[K in keyof FieldAdapters]: ValuePathOfFieldAdapter<FieldAdapters[K]>;
|
|
193
|
+
}[keyof FieldAdapters];
|
|
194
|
+
type TosOfFieldAdapters<FieldAdapters extends Readonly<Record<string, FieldAdapter>>> = {
|
|
195
|
+
[K in keyof FieldAdapters]: ToOfFieldAdapter<FieldAdapters[K]>;
|
|
196
|
+
}[keyof FieldAdapters];
|
|
197
|
+
declare function mergeFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context>(fieldAdapters: FieldAdapters, converter: TwoWayFieldConverter<TosOfFieldAdapters<FieldAdapters>, TosOfFieldAdapters<FieldAdapters>, E, ValuePathsOfFieldAdapters<FieldAdapters>, Context>): MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters, E, Context>;
|
|
198
|
+
|
|
199
|
+
type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Partial<Readonly<Record<string, Validator>>>, Key extends keyof Validators = keyof Validators> = Simplify<{
|
|
200
|
+
readonly [K in Key]: MergedOfFieldAdapterWithValidator<FieldAdapters[K], Validators[K]>;
|
|
201
|
+
} & {
|
|
202
|
+
readonly [K in Exclude<keyof FieldAdapters, Key>]: FieldAdapters[K];
|
|
203
|
+
}>;
|
|
204
|
+
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;
|
|
205
|
+
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>;
|
|
206
|
+
|
|
207
|
+
type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
|
|
208
|
+
[K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
|
|
204
209
|
};
|
|
210
|
+
declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
|
|
205
211
|
|
|
206
212
|
declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
|
|
207
213
|
private readonly isNanError;
|
|
@@ -360,7 +366,7 @@ type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
|
360
366
|
declare function SimpleSelect(props: SelectProps & {
|
|
361
367
|
onChange?: (value: string | null) => void;
|
|
362
368
|
}): react_jsx_runtime.JSX.Element;
|
|
363
|
-
declare function
|
|
369
|
+
declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): MantineFormImpl<F>;
|
|
364
370
|
declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
365
371
|
private readonly textInputCache;
|
|
366
372
|
private readonly valueInputCache;
|
|
@@ -369,7 +375,8 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
369
375
|
private readonly radioCache;
|
|
370
376
|
private readonly pillCache;
|
|
371
377
|
private readonly listCache;
|
|
372
|
-
private readonly
|
|
378
|
+
private readonly fieldsViewCache;
|
|
379
|
+
private readonly formCache;
|
|
373
380
|
accessor fields: F;
|
|
374
381
|
onFieldValueChange: <K extends keyof F>(this: void, key: K, value: F[K]['value']) => void;
|
|
375
382
|
onFieldFocus: ((this: void, key: keyof F) => void) | undefined;
|
|
@@ -389,7 +396,8 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
389
396
|
pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
|
|
390
397
|
pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P>;
|
|
391
398
|
list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>>;
|
|
392
|
-
|
|
399
|
+
fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P>;
|
|
400
|
+
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>;
|
|
393
401
|
}
|
|
394
402
|
|
|
395
403
|
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<{
|
|
@@ -398,4 +406,4 @@ type MergedOfValidators<Validators1 extends Partial<Readonly<Record<Keys, Valida
|
|
|
398
406
|
type MergedOfValidator<Validator1 extends Validator, Validator2 extends Validator> = Validator1 extends Validator<infer V, infer E1, infer P, infer C> ? Validator2 extends Validator<V, infer E2, P, C> ? Validator<V, E1 | E2, P, C> : never : never;
|
|
399
407
|
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>;
|
|
400
408
|
|
|
401
|
-
export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, DefaultErrorRenderer, type
|
|
409
|
+
export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, DefaultErrorRenderer, 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 FormFieldsOfPresenter, FormModel, FormPresenter, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, type ToValueOfPresenterValuePath, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, type ValuePathOfFieldAdapter, type ValuePathsOfPresenter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
|
package/dist/index.js
CHANGED
|
@@ -655,6 +655,62 @@ var FormModel = class {
|
|
|
655
655
|
}
|
|
656
656
|
};
|
|
657
657
|
|
|
658
|
+
// core/mobx/hooks.ts
|
|
659
|
+
import {
|
|
660
|
+
useCallback,
|
|
661
|
+
useMemo
|
|
662
|
+
} from "react";
|
|
663
|
+
function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
|
|
664
|
+
const model = useMemo(function() {
|
|
665
|
+
return presenter.createModel(value);
|
|
666
|
+
}, [
|
|
667
|
+
presenter,
|
|
668
|
+
value
|
|
669
|
+
]);
|
|
670
|
+
const onFieldValueChange = useCallback(
|
|
671
|
+
function(path, value2) {
|
|
672
|
+
presenter.clearFieldError(model, path);
|
|
673
|
+
presenter.setFieldValue(model, path, value2);
|
|
674
|
+
},
|
|
675
|
+
[
|
|
676
|
+
presenter,
|
|
677
|
+
model
|
|
678
|
+
]
|
|
679
|
+
);
|
|
680
|
+
const onFieldSubmit = useCallback(
|
|
681
|
+
function(valuePath) {
|
|
682
|
+
if (presenter.validateField(model, valuePath)) {
|
|
683
|
+
onValidSubmit?.(model, valuePath);
|
|
684
|
+
}
|
|
685
|
+
return false;
|
|
686
|
+
},
|
|
687
|
+
[
|
|
688
|
+
presenter,
|
|
689
|
+
model,
|
|
690
|
+
onValidSubmit
|
|
691
|
+
]
|
|
692
|
+
);
|
|
693
|
+
const onFieldBlur = useCallback(
|
|
694
|
+
function(path) {
|
|
695
|
+
setTimeout(function() {
|
|
696
|
+
if (presenter.isValuePathActive(model, path)) {
|
|
697
|
+
presenter.validateField(model, path);
|
|
698
|
+
}
|
|
699
|
+
}, 100);
|
|
700
|
+
},
|
|
701
|
+
[
|
|
702
|
+
presenter,
|
|
703
|
+
model
|
|
704
|
+
]
|
|
705
|
+
);
|
|
706
|
+
return {
|
|
707
|
+
model,
|
|
708
|
+
onFieldValueChange,
|
|
709
|
+
onFieldSubmit,
|
|
710
|
+
onFieldBlur
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
|
|
658
714
|
// core/mobx/merge_field_adapters_with_two_way_converter.ts
|
|
659
715
|
import { map as map2 } from "@strictly/base";
|
|
660
716
|
function mergeFieldAdaptersWithTwoWayConverter(fieldAdapters, converter) {
|
|
@@ -982,14 +1038,14 @@ import {
|
|
|
982
1038
|
} from "mobx";
|
|
983
1039
|
import {
|
|
984
1040
|
useEffect,
|
|
985
|
-
useMemo as
|
|
1041
|
+
useMemo as useMemo3
|
|
986
1042
|
} from "react";
|
|
987
1043
|
|
|
988
1044
|
// util/partial.tsx
|
|
989
1045
|
import { observer } from "mobx-react";
|
|
990
1046
|
import {
|
|
991
1047
|
forwardRef,
|
|
992
|
-
useMemo
|
|
1048
|
+
useMemo as useMemo2
|
|
993
1049
|
} from "react";
|
|
994
1050
|
import { jsx } from "react/jsx-runtime";
|
|
995
1051
|
function createSimplePartialComponent(Component, curriedProps) {
|
|
@@ -1050,7 +1106,7 @@ function createPartialComponent(Component, curriedPropsSource, additionalPropKey
|
|
|
1050
1106
|
);
|
|
1051
1107
|
}
|
|
1052
1108
|
function usePartialComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1053
|
-
return
|
|
1109
|
+
return useMemo2(
|
|
1054
1110
|
function() {
|
|
1055
1111
|
return createPartialComponent(
|
|
1056
1112
|
Component,
|
|
@@ -1120,7 +1176,7 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
|
|
|
1120
1176
|
);
|
|
1121
1177
|
}
|
|
1122
1178
|
function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1123
|
-
return
|
|
1179
|
+
return useMemo2(
|
|
1124
1180
|
function() {
|
|
1125
1181
|
return createPartialObserverComponent(
|
|
1126
1182
|
Component,
|
|
@@ -1187,8 +1243,81 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1187
1243
|
);
|
|
1188
1244
|
}
|
|
1189
1245
|
|
|
1246
|
+
// mantine/create_fields_view.tsx
|
|
1247
|
+
import { observer as observer2 } from "mobx-react";
|
|
1248
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
1249
|
+
function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
1250
|
+
function toKey(subKey) {
|
|
1251
|
+
return subKey.replace("$", valuePath);
|
|
1252
|
+
}
|
|
1253
|
+
function toSubKey(key) {
|
|
1254
|
+
return key.replace(valuePath, "$");
|
|
1255
|
+
}
|
|
1256
|
+
function onFieldValueChange(subKey, value) {
|
|
1257
|
+
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
1258
|
+
}
|
|
1259
|
+
function onFieldBlur(subKey) {
|
|
1260
|
+
observableProps.onFieldBlur?.(toKey(subKey));
|
|
1261
|
+
}
|
|
1262
|
+
function onFieldFocus(subKey) {
|
|
1263
|
+
observableProps.onFieldFocus?.(toKey(subKey));
|
|
1264
|
+
}
|
|
1265
|
+
function onFieldSubmit(subKey) {
|
|
1266
|
+
observableProps.onFieldSubmit?.(toKey(subKey));
|
|
1267
|
+
}
|
|
1268
|
+
return observer2(function(props) {
|
|
1269
|
+
const subFields = Object.entries(observableProps.fields).reduce((acc, [
|
|
1270
|
+
fieldKey,
|
|
1271
|
+
fieldValue
|
|
1272
|
+
]) => {
|
|
1273
|
+
if (fieldKey.startsWith(valuePath)) {
|
|
1274
|
+
acc[toSubKey(fieldKey)] = fieldValue;
|
|
1275
|
+
}
|
|
1276
|
+
return acc;
|
|
1277
|
+
}, {});
|
|
1278
|
+
return /* @__PURE__ */ jsx3(
|
|
1279
|
+
FieldsView,
|
|
1280
|
+
{
|
|
1281
|
+
// maybe we can do this in a more type safe way
|
|
1282
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1283
|
+
...props,
|
|
1284
|
+
fields: subFields,
|
|
1285
|
+
onFieldBlur,
|
|
1286
|
+
onFieldFocus,
|
|
1287
|
+
onFieldSubmit,
|
|
1288
|
+
onFieldValueChange
|
|
1289
|
+
}
|
|
1290
|
+
);
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
// mantine/create_form.tsx
|
|
1295
|
+
import { observer as observer3 } from "mobx-react";
|
|
1296
|
+
import {
|
|
1297
|
+
useCallback as useCallback2
|
|
1298
|
+
} from "react";
|
|
1299
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1300
|
+
function createForm(valuePath, Form, observableProps) {
|
|
1301
|
+
return observer3((props) => {
|
|
1302
|
+
const { value } = observableProps.fields[valuePath];
|
|
1303
|
+
const onValueChange = useCallback2((value2) => {
|
|
1304
|
+
observableProps.onFieldValueChange(valuePath, value2);
|
|
1305
|
+
}, []);
|
|
1306
|
+
return /* @__PURE__ */ jsx4(
|
|
1307
|
+
Form,
|
|
1308
|
+
{
|
|
1309
|
+
// maybe we can do this in a more type safe way
|
|
1310
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1311
|
+
...props,
|
|
1312
|
+
onValueChange,
|
|
1313
|
+
value
|
|
1314
|
+
}
|
|
1315
|
+
);
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1190
1319
|
// mantine/create_list.tsx
|
|
1191
|
-
import { Fragment, jsx as
|
|
1320
|
+
import { Fragment, jsx as jsx5 } from "react/jsx-runtime";
|
|
1192
1321
|
function createList(valuePath, List) {
|
|
1193
1322
|
const propSource = () => {
|
|
1194
1323
|
const values = [...this.fields[valuePath].value];
|
|
@@ -1204,7 +1333,7 @@ function DefaultList({
|
|
|
1204
1333
|
listPath,
|
|
1205
1334
|
children
|
|
1206
1335
|
}) {
|
|
1207
|
-
return /* @__PURE__ */
|
|
1336
|
+
return /* @__PURE__ */ jsx5(Fragment, { children: values.map(function(value, index) {
|
|
1208
1337
|
const valuePath = `${listPath}.${index}`;
|
|
1209
1338
|
return children(valuePath, value, index);
|
|
1210
1339
|
}) });
|
|
@@ -1243,7 +1372,7 @@ function createRadio(valuePath, value, Radio) {
|
|
|
1243
1372
|
}
|
|
1244
1373
|
|
|
1245
1374
|
// mantine/create_radio_group.tsx
|
|
1246
|
-
import { jsx as
|
|
1375
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
1247
1376
|
function createRadioGroup(valuePath, RadioGroup) {
|
|
1248
1377
|
const onChange = (value) => {
|
|
1249
1378
|
this.onFieldValueChange?.(valuePath, value);
|
|
@@ -1271,7 +1400,7 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1271
1400
|
name: valuePath,
|
|
1272
1401
|
value,
|
|
1273
1402
|
required,
|
|
1274
|
-
error: error && /* @__PURE__ */
|
|
1403
|
+
error: error && /* @__PURE__ */ jsx6(ErrorRenderer, { error }),
|
|
1275
1404
|
onChange,
|
|
1276
1405
|
onFocus,
|
|
1277
1406
|
onBlur,
|
|
@@ -1281,53 +1410,8 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1281
1410
|
return createUnsafePartialObserverComponent(RadioGroup, propSource, ["ErrorRenderer"]);
|
|
1282
1411
|
}
|
|
1283
1412
|
|
|
1284
|
-
// mantine/create_sub_form.tsx
|
|
1285
|
-
import { observer as observer2 } from "mobx-react";
|
|
1286
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1287
|
-
function createSubForm(valuePath, SubForm, observableProps) {
|
|
1288
|
-
function toKey(subKey) {
|
|
1289
|
-
return subKey.replace("$", valuePath);
|
|
1290
|
-
}
|
|
1291
|
-
function toSubKey(key) {
|
|
1292
|
-
return key.replace(valuePath, "$");
|
|
1293
|
-
}
|
|
1294
|
-
function onFieldValueChange(subKey, value) {
|
|
1295
|
-
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
1296
|
-
}
|
|
1297
|
-
function onFieldBlur(subKey) {
|
|
1298
|
-
observableProps.onFieldBlur?.(toKey(subKey));
|
|
1299
|
-
}
|
|
1300
|
-
function onFieldFocus(subKey) {
|
|
1301
|
-
observableProps.onFieldFocus?.(toKey(subKey));
|
|
1302
|
-
}
|
|
1303
|
-
function onFieldSubmit(subKey) {
|
|
1304
|
-
observableProps.onFieldSubmit?.(toKey(subKey));
|
|
1305
|
-
}
|
|
1306
|
-
return observer2(function() {
|
|
1307
|
-
const subFields = Object.entries(observableProps.fields).reduce((acc, [
|
|
1308
|
-
fieldKey,
|
|
1309
|
-
fieldValue
|
|
1310
|
-
]) => {
|
|
1311
|
-
if (fieldKey.startsWith(valuePath)) {
|
|
1312
|
-
acc[toSubKey(fieldKey)] = fieldValue;
|
|
1313
|
-
}
|
|
1314
|
-
return acc;
|
|
1315
|
-
}, {});
|
|
1316
|
-
return /* @__PURE__ */ jsx5(
|
|
1317
|
-
SubForm,
|
|
1318
|
-
{
|
|
1319
|
-
fields: subFields,
|
|
1320
|
-
onFieldBlur,
|
|
1321
|
-
onFieldFocus,
|
|
1322
|
-
onFieldSubmit,
|
|
1323
|
-
onFieldValueChange
|
|
1324
|
-
}
|
|
1325
|
-
);
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
1413
|
// mantine/create_text_input.tsx
|
|
1330
|
-
import { jsx as
|
|
1414
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1331
1415
|
function createTextInput(valuePath, TextInput) {
|
|
1332
1416
|
const onChange = (e) => {
|
|
1333
1417
|
this.onFieldValueChange?.(valuePath, e.target.value);
|
|
@@ -1361,7 +1445,7 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1361
1445
|
value,
|
|
1362
1446
|
disabled: readonly,
|
|
1363
1447
|
required,
|
|
1364
|
-
error: error && /* @__PURE__ */
|
|
1448
|
+
error: error && /* @__PURE__ */ jsx7(ErrorRenderer, { error }),
|
|
1365
1449
|
onChange,
|
|
1366
1450
|
onFocus,
|
|
1367
1451
|
onBlur,
|
|
@@ -1376,7 +1460,7 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1376
1460
|
}
|
|
1377
1461
|
|
|
1378
1462
|
// mantine/create_value_input.tsx
|
|
1379
|
-
import { jsx as
|
|
1463
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1380
1464
|
function createValueInput(valuePath, ValueInput) {
|
|
1381
1465
|
const onChange = (value) => {
|
|
1382
1466
|
this.onFieldValueChange?.(valuePath, value);
|
|
@@ -1410,7 +1494,7 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1410
1494
|
value,
|
|
1411
1495
|
disabled: readonly,
|
|
1412
1496
|
required,
|
|
1413
|
-
error: error && /* @__PURE__ */
|
|
1497
|
+
error: error && /* @__PURE__ */ jsx8(ErrorRenderer, { error }),
|
|
1414
1498
|
onChange,
|
|
1415
1499
|
onFocus,
|
|
1416
1500
|
onBlur,
|
|
@@ -1425,18 +1509,18 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1425
1509
|
}
|
|
1426
1510
|
|
|
1427
1511
|
// mantine/hooks.tsx
|
|
1428
|
-
import { jsx as
|
|
1512
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1429
1513
|
function SimpleSelect(props) {
|
|
1430
|
-
return /* @__PURE__ */
|
|
1514
|
+
return /* @__PURE__ */ jsx9(Select, { ...props });
|
|
1431
1515
|
}
|
|
1432
|
-
function
|
|
1516
|
+
function useMantineFormFields({
|
|
1433
1517
|
onFieldValueChange,
|
|
1434
1518
|
onFieldBlur,
|
|
1435
1519
|
onFieldFocus,
|
|
1436
1520
|
onFieldSubmit,
|
|
1437
1521
|
fields
|
|
1438
1522
|
}) {
|
|
1439
|
-
const form =
|
|
1523
|
+
const form = useMemo3(
|
|
1440
1524
|
function() {
|
|
1441
1525
|
return new MantineFormImpl(fields);
|
|
1442
1526
|
},
|
|
@@ -1500,9 +1584,10 @@ var MantineFormImpl = class {
|
|
|
1500
1584
|
listCache = new Cache(
|
|
1501
1585
|
createList.bind(this)
|
|
1502
1586
|
);
|
|
1503
|
-
|
|
1504
|
-
|
|
1587
|
+
fieldsViewCache = new Cache(
|
|
1588
|
+
createFieldsView.bind(this)
|
|
1505
1589
|
);
|
|
1590
|
+
formCache = new Cache(createForm.bind(this));
|
|
1506
1591
|
@observable2.ref
|
|
1507
1592
|
accessor fields;
|
|
1508
1593
|
onFieldValueChange;
|
|
@@ -1568,13 +1653,21 @@ var MantineFormImpl = class {
|
|
|
1568
1653
|
DefaultList
|
|
1569
1654
|
);
|
|
1570
1655
|
}
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1656
|
+
fieldsView(valuePath, FieldsView) {
|
|
1657
|
+
return this.fieldsViewCache.retrieveOrCreate(
|
|
1658
|
+
valuePath,
|
|
1659
|
+
// strip props from component since we lose information in the cache
|
|
1660
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1661
|
+
FieldsView,
|
|
1662
|
+
this
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
form(valuePath, Form) {
|
|
1666
|
+
return this.formCache.retrieveOrCreate(
|
|
1574
1667
|
valuePath,
|
|
1575
1668
|
// strip props from component since we lose information in the cache
|
|
1576
1669
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1577
|
-
|
|
1670
|
+
Form,
|
|
1578
1671
|
this
|
|
1579
1672
|
);
|
|
1580
1673
|
}
|
|
@@ -1647,7 +1740,8 @@ export {
|
|
|
1647
1740
|
mergeValidators,
|
|
1648
1741
|
prototypingFieldValueFactory,
|
|
1649
1742
|
subFormFieldAdapters,
|
|
1650
|
-
|
|
1743
|
+
useDefaultMobxFormHooks,
|
|
1744
|
+
useMantineFormFields,
|
|
1651
1745
|
usePartialComponent,
|
|
1652
1746
|
usePartialObserverComponent,
|
|
1653
1747
|
validatingConverter
|
package/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './core/mobx/field_adapters_of_values'
|
|
|
4
4
|
export * from './core/mobx/flattened_adapters_of_fields'
|
|
5
5
|
export * from './core/mobx/form_fields_of_field_adapters'
|
|
6
6
|
export * from './core/mobx/form_presenter'
|
|
7
|
+
export * from './core/mobx/hooks'
|
|
7
8
|
export * from './core/mobx/merge_field_adapters_with_two_way_converter'
|
|
8
9
|
export * from './core/mobx/merge_field_adapters_with_validators'
|
|
9
10
|
export * from './core/mobx/sub_form_field_adapters'
|