react-science 20.3.0 → 20.3.1

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.
@@ -1,4 +1,4 @@
1
- import type { SyntheticEvent } from 'react';
1
+ import type { ReactNode, SyntheticEvent } from 'react';
2
2
  import type { FormProps as DomFormProps } from '../input_groups/form.js';
3
3
  export interface AppFormProps extends Omit<DomFormProps, 'noValidate'> {
4
4
  domValidate?: boolean;
@@ -11,7 +11,7 @@ export interface AppFormProps extends Omit<DomFormProps, 'noValidate'> {
11
11
  * Mount `form.AppForm` and `Form` with default onSubmit.
12
12
  * It reduces the boilerplate code.
13
13
  */
14
- export declare const AppForm: import("react").FunctionComponent<import("react").PropsWithChildren<NoInfer<AppFormProps> & {
14
+ export declare const AppForm: MinimalFunctionComponent<MinimalProps<import("react").PropsWithChildren<NoInfer<AppFormProps> & {
15
15
  form: import("@tanstack/react-form").AppFieldExtendedReactFormApi<any, any, any, import("@tanstack/form-core").FormAsyncValidateOrFn<any> | undefined, any, import("@tanstack/form-core").FormAsyncValidateOrFn<any> | undefined, any, import("@tanstack/form-core").FormAsyncValidateOrFn<any> | undefined, any, import("@tanstack/form-core").FormAsyncValidateOrFn<any> | undefined, import("@tanstack/form-core").FormAsyncValidateOrFn<any> | undefined, any, {
16
16
  readonly Input: typeof import("../input/input.tsx").Input;
17
17
  readonly NumericInput: typeof import("../input/numeric_input.tsx").NumericInput;
@@ -25,5 +25,15 @@ export declare const AppForm: import("react").FunctionComponent<import("react").
25
25
  readonly ResetButton: typeof import("../input/reset_button.tsx").ResetButton;
26
26
  readonly Section: typeof import("./Section.tsx").Section;
27
27
  }>;
28
- }>>;
28
+ }>>>;
29
+ type MinimalProps<Props extends {
30
+ form: unknown;
31
+ }> = Omit<Props, 'form'> & {
32
+ /**
33
+ * Some properties of form are ignored because it is known to produce type errors on usage.
34
+ */
35
+ form: Omit<Props['form'], 'pushFieldValue' | 'insertFieldValue' | 'replaceFieldValue'>;
36
+ };
37
+ type MinimalFunctionComponent<Props> = (props: Props) => ReactNode;
38
+ export {};
29
39
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,KAAK,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGzE,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC;IACpE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IAGH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,eAAe,EAAE,WAAW,CAAC,KAAK,GAAG,CAAC;CAC7E;AAWD;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;GA8BlB,CAAC"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAGvD,OAAO,KAAK,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGzE,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC;IACpE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IAGH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,eAAe,EAAE,WAAW,CAAC,KAAK,GAAG,CAAC;CAC7E;AAWD;;;GAGG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;IAgCnB,CAAC;AAEF,KAAK,YAAY,CAAC,KAAK,SAAS;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG;IACzE;;OAEG;IACH,IAAI,EAAE,IAAI,CACR,KAAK,CAAC,MAAM,CAAC,EAKb,gBAAgB,GAAG,kBAAkB,GAAG,mBAAmB,CAC5D,CAAC;CACH,CAAC;AACF,KAAK,wBAAwB,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC"}
@@ -12,7 +12,7 @@ const defaultValues = undefined;
12
12
  * Mount `form.AppForm` and `Form` with default onSubmit.
13
13
  * It reduces the boilerplate code.
14
14
  */
15
- export const AppForm = withForm({
15
+ export const AppForm = minimalForm(withForm({
16
16
  defaultValues,
17
17
  props,
18
18
  render: function FormRender(props) {
@@ -27,5 +27,8 @@ export const AppForm = withForm({
27
27
  void form.handleSubmit(meta);
28
28
  }, ...domProps, noValidate: !domValidate, children: children }) }));
29
29
  },
30
- });
30
+ }));
31
+ function minimalForm(component) {
32
+ return component;
33
+ }
31
34
  //# sourceMappingURL=form.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.js","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/form.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAY1D,MAAM,KAAK,GAAiB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAE/C,+CAA+C;AAC/C,+CAA+C;AAC/C,+BAA+B;AAC/B,0GAA0G;AAC1G,8DAA8D;AAC9D,MAAM,aAAa,GAAQ,SAAS,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;IAC9B,aAAa;IACb,KAAK;IACL,MAAM,EAAE,SAAS,UAAU,CAAC,KAAK;QAC/B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC;QACzE,MAAM,EAAE,OAAO,EAAE,GAAG,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YAAY,EAAE;oBACzB,wCAAwC;oBACxC,wCAAwC;oBACxC,KAAqD,CACtD,CAAC;oBAEF,KAAK,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC,KACG,QAAQ,EACZ,UAAU,EAAE,CAAC,WAAW,YAEvB,QAAQ,GACD,GACF,CACX,CAAC;IACJ,CAAC;CACF,CAAC,CACH,CAAC;AAiBF,SAAS,WAAW,CAClB,SAA0C;IAE1C,OAAO,SAA0D,CAAC;AACpE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-science",
3
- "version": "20.3.0",
3
+ "version": "20.3.1",
4
4
  "description": "React components to build scientific applications UI",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,4 +1,4 @@
1
- import type { SyntheticEvent } from 'react';
1
+ import type { ReactNode, SyntheticEvent } from 'react';
2
2
 
3
3
  import { withForm } from '../../context/use_ts_form.js';
4
4
  import type { FormProps as DomFormProps } from '../input_groups/form.js';
@@ -27,34 +27,57 @@ const defaultValues: any = undefined;
27
27
  * Mount `form.AppForm` and `Form` with default onSubmit.
28
28
  * It reduces the boilerplate code.
29
29
  */
30
- export const AppForm = withForm({
31
- defaultValues,
32
- props,
33
- render: function FormRender(props) {
34
- const { form, children, domValidate, onSubmitMeta, ...domProps } = props;
35
- const { AppForm } = form;
36
-
37
- return (
38
- <AppForm>
39
- {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
40
- <DomForm
41
- onSubmit={(event) => {
42
- event.preventDefault();
43
-
44
- const meta = onSubmitMeta?.(
45
- // onSubmit event is not typed properly.
46
- // It uses Event instead of SubmitEvent.
47
- event as SyntheticEvent<HTMLFormElement, SubmitEvent>,
48
- );
49
-
50
- void form.handleSubmit(meta);
51
- }}
52
- {...domProps}
53
- noValidate={!domValidate}
54
- >
55
- {children}
56
- </DomForm>
57
- </AppForm>
58
- );
59
- },
60
- });
30
+ export const AppForm = minimalForm(
31
+ withForm({
32
+ defaultValues,
33
+ props,
34
+ render: function FormRender(props) {
35
+ const { form, children, domValidate, onSubmitMeta, ...domProps } = props;
36
+ const { AppForm } = form;
37
+
38
+ return (
39
+ <AppForm>
40
+ {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
41
+ <DomForm
42
+ onSubmit={(event) => {
43
+ event.preventDefault();
44
+
45
+ const meta = onSubmitMeta?.(
46
+ // onSubmit event is not typed properly.
47
+ // It uses Event instead of SubmitEvent.
48
+ event as SyntheticEvent<HTMLFormElement, SubmitEvent>,
49
+ );
50
+
51
+ void form.handleSubmit(meta);
52
+ }}
53
+ {...domProps}
54
+ noValidate={!domValidate}
55
+ >
56
+ {children}
57
+ </DomForm>
58
+ </AppForm>
59
+ );
60
+ },
61
+ }),
62
+ );
63
+
64
+ type MinimalProps<Props extends { form: unknown }> = Omit<Props, 'form'> & {
65
+ /**
66
+ * Some properties of form are ignored because it is known to produce type errors on usage.
67
+ */
68
+ form: Omit<
69
+ Props['form'],
70
+ // field array API cause this kind of errors:
71
+ // Types of property 'pushFieldValue' are incompatible.
72
+ // ...
73
+ // Type 'any' is not assignable to type 'never'.
74
+ 'pushFieldValue' | 'insertFieldValue' | 'replaceFieldValue'
75
+ >;
76
+ };
77
+ type MinimalFunctionComponent<Props> = (props: Props) => ReactNode;
78
+
79
+ function minimalForm<Props extends { form: unknown }>(
80
+ component: MinimalFunctionComponent<Props>,
81
+ ): MinimalFunctionComponent<MinimalProps<Props>> {
82
+ return component as MinimalFunctionComponent<MinimalProps<Props>>;
83
+ }