react-science 20.2.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.
@@ -4,5 +4,12 @@ export interface FormProps extends FormHTMLAttributes<HTMLFormElement> {
4
4
  children: ReactNode;
5
5
  layout?: Layout;
6
6
  }
7
+ /**
8
+ * @param props
9
+ * @deprecated Use `AppForm` instead.
10
+ * This component will be merged into `AppForm` and removed in a next major release.
11
+ * During migration, consider removing the `onSubmit` props.
12
+ * If you did not bound `noValidate` props, you will have to bound `domValidate` to `AppForm`.
13
+ */
7
14
  export declare function Form(props: FormProps): import("react").JSX.Element;
8
15
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/input_groups/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD,MAAM,WAAW,SAAU,SAAQ,kBAAkB,CAAC,eAAe,CAAC;IACpE,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,+BAYpC"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/input_groups/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD,MAAM,WAAW,SAAU,SAAQ,kBAAkB,CAAC,eAAe,CAAC;IACpE,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,+BAYpC"}
@@ -1,6 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useMemo } from 'react';
3
3
  import { formContext } from './form_context.js';
4
+ /**
5
+ * @param props
6
+ * @deprecated Use `AppForm` instead.
7
+ * This component will be merged into `AppForm` and removed in a next major release.
8
+ * During migration, consider removing the `onSubmit` props.
9
+ * If you did not bound `noValidate` props, you will have to bound `domValidate` to `AppForm`.
10
+ */
4
11
  export function Form(props) {
5
12
  const { children, layout = 'stacked', ...otherProps } = props;
6
13
  const contextValue = useMemo(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"form.js","sourceRoot":"","sources":["../../../../../src/components/form/components/input_groups/form.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,MAAM,UAAU,IAAI,CAAC,KAAgB;IACnC,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC;IAE9D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE;QAChC,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,CACL,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YACvC,kBAAU,UAAU,YAAG,QAAQ,GAAQ,GAClB,CACxB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"form.js","sourceRoot":"","sources":["../../../../../src/components/form/components/input_groups/form.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD;;;;;;GAMG;AACH,MAAM,UAAU,IAAI,CAAC,KAAgB;IACnC,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAC;IAE9D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE;QAChC,OAAO,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO,CACL,KAAC,WAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YACvC,kBAAU,UAAU,YAAG,QAAQ,GAAQ,GAClB,CACxB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { ReactNode, SyntheticEvent } from 'react';
2
+ import type { FormProps as DomFormProps } from '../input_groups/form.js';
3
+ export interface AppFormProps extends Omit<DomFormProps, 'noValidate'> {
4
+ domValidate?: boolean;
5
+ /**
6
+ * should return meta to pass to `form.handleSubmit`
7
+ */
8
+ onSubmitMeta?: (event: SyntheticEvent<HTMLFormElement, SubmitEvent>) => any;
9
+ }
10
+ /**
11
+ * Mount `form.AppForm` and `Form` with default onSubmit.
12
+ * It reduces the boilerplate code.
13
+ */
14
+ export declare const AppForm: MinimalFunctionComponent<MinimalProps<import("react").PropsWithChildren<NoInfer<AppFormProps> & {
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
+ readonly Input: typeof import("../input/input.tsx").Input;
17
+ readonly NumericInput: typeof import("../input/numeric_input.tsx").NumericInput;
18
+ readonly Checkbox: typeof import("../input/checkbox.tsx").Checkbox;
19
+ readonly Select: typeof import("../input/select.tsx").Select;
20
+ readonly Switch: typeof import("../input/switch.tsx").Switch;
21
+ readonly ColorPicker: typeof import("../input/color_picker.tsx").ColorPicker;
22
+ readonly RadioGroup: typeof import("../input/radio_group.tsx").RadioGroup;
23
+ }, {
24
+ readonly SubmitButton: typeof import("../input/submit_button.tsx").SubmitButton;
25
+ readonly ResetButton: typeof import("../input/reset_button.tsx").ResetButton;
26
+ readonly Section: typeof import("./Section.tsx").Section;
27
+ }>;
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 {};
39
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { withForm } from '../../context/use_ts_form.js';
3
+ import { Form as DomForm } from '../input_groups/form.js';
4
+ const props = { children: null };
5
+ // AppForm is a generic component for all forms
6
+ // it will not touch to values inside the form,
7
+ // and unknown is not possible.
8
+ // <AppForm form={form}> would throw an error like "unknown is not compatible with <inferred values type>"
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const defaultValues = undefined;
11
+ /**
12
+ * Mount `form.AppForm` and `Form` with default onSubmit.
13
+ * It reduces the boilerplate code.
14
+ */
15
+ export const AppForm = minimalForm(withForm({
16
+ defaultValues,
17
+ props,
18
+ render: function FormRender(props) {
19
+ const { form, children, domValidate, onSubmitMeta, ...domProps } = props;
20
+ const { AppForm } = form;
21
+ return (_jsx(AppForm, { children: _jsx(DomForm, { onSubmit: (event) => {
22
+ event.preventDefault();
23
+ const meta = onSubmitMeta?.(
24
+ // onSubmit event is not typed properly.
25
+ // It uses Event instead of SubmitEvent.
26
+ event);
27
+ void form.handleSubmit(meta);
28
+ }, ...domProps, noValidate: !domValidate, children: children }) }));
29
+ },
30
+ }));
31
+ function minimalForm(component) {
32
+ return component;
33
+ }
34
+ //# sourceMappingURL=form.js.map
@@ -0,0 +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,WAAW,CAChC,QAAQ,CAAC;IACP,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,IAAI,CAAC;QAEzB,OAAO,CACL,KAAC,OAAO,cAEN,KAAC,OAAO,IACN,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClB,KAAK,CAAC,cAAc,EAAE,CAAC;oBAEvB,MAAM,IAAI,GAAG,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"}
@@ -1,2 +1,3 @@
1
1
  export { type Section as _Section } from './Section.js';
2
+ export { AppForm, type AppFormProps } from './form.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC"}
@@ -1,2 +1,2 @@
1
- export {};
1
+ export { AppForm } from './form.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/form/components/layout/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAqB,MAAM,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-science",
3
- "version": "20.2.0",
3
+ "version": "20.3.1",
4
4
  "description": "React components to build scientific applications UI",
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,6 +9,13 @@ export interface FormProps extends FormHTMLAttributes<HTMLFormElement> {
9
9
  layout?: Layout;
10
10
  }
11
11
 
12
+ /**
13
+ * @param props
14
+ * @deprecated Use `AppForm` instead.
15
+ * This component will be merged into `AppForm` and removed in a next major release.
16
+ * During migration, consider removing the `onSubmit` props.
17
+ * If you did not bound `noValidate` props, you will have to bound `domValidate` to `AppForm`.
18
+ */
12
19
  export function Form(props: FormProps) {
13
20
  const { children, layout = 'stacked', ...otherProps } = props;
14
21
 
@@ -0,0 +1,83 @@
1
+ import type { ReactNode, SyntheticEvent } from 'react';
2
+
3
+ import { withForm } from '../../context/use_ts_form.js';
4
+ import type { FormProps as DomFormProps } from '../input_groups/form.js';
5
+ import { Form as DomForm } from '../input_groups/form.js';
6
+
7
+ export interface AppFormProps extends Omit<DomFormProps, 'noValidate'> {
8
+ domValidate?: boolean;
9
+ /**
10
+ * should return meta to pass to `form.handleSubmit`
11
+ */
12
+ // Generic meta-result is not possible with higher order component pattern
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ onSubmitMeta?: (event: SyntheticEvent<HTMLFormElement, SubmitEvent>) => any;
15
+ }
16
+
17
+ const props: AppFormProps = { children: null };
18
+
19
+ // AppForm is a generic component for all forms
20
+ // it will not touch to values inside the form,
21
+ // and unknown is not possible.
22
+ // <AppForm form={form}> would throw an error like "unknown is not compatible with <inferred values type>"
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ const defaultValues: any = undefined;
25
+
26
+ /**
27
+ * Mount `form.AppForm` and `Form` with default onSubmit.
28
+ * It reduces the boilerplate code.
29
+ */
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
+ }
@@ -1 +1,2 @@
1
1
  export { type Section as _Section } from './Section.js';
2
+ export { AppForm, type AppFormProps } from './form.js';