@zakodium/nmrium-core-plugins-ui 0.1.33 → 0.1.34

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,112 +1,150 @@
1
1
  import type { ProcessingOperatorUISettingsFormProps } from '@zakodium/nmrium-core';
2
- export declare function usePhaseCorrectionForm(props: ProcessingOperatorUISettingsFormProps<'@zakodium/nmrium-core-plugins#phaseCorrection1D'>): import("@tanstack/react-form").AppFieldExtendedReactFormApi<{
3
- mode: "absolute";
4
- } | {
5
- mode: "manual";
6
- ph0: number;
7
- ph1: number;
8
- } | {
9
- mode: "automatic";
10
- }, import("@tanstack/react-form").FormValidateOrFn<{
11
- mode: "absolute";
12
- } | {
13
- mode: "manual";
14
- ph0: number;
15
- ph1: number;
16
- } | {
17
- mode: "automatic";
18
- }> | undefined, import("@tanstack/react-form").FormValidateOrFn<{
19
- mode: "absolute";
20
- } | {
21
- mode: "manual";
22
- ph0: number;
23
- ph1: number;
24
- } | {
25
- mode: "automatic";
26
- }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
27
- mode: "absolute";
28
- } | {
29
- mode: "manual";
30
- ph0: number;
31
- ph1: number;
32
- } | {
33
- mode: "automatic";
34
- }> | undefined, import("@tanstack/react-form").FormValidateOrFn<{
35
- mode: "absolute";
36
- } | {
37
- mode: "manual";
38
- ph0: number;
39
- ph1: number;
40
- } | {
41
- mode: "automatic";
42
- }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
43
- mode: "absolute";
44
- } | {
45
- mode: "manual";
46
- ph0: number;
47
- ph1: number;
48
- } | {
49
- mode: "automatic";
50
- }> | undefined, import("@tanstack/react-form").FormValidateOrFn<{
51
- mode: "absolute";
52
- } | {
53
- mode: "manual";
54
- ph0: number;
55
- ph1: number;
56
- } | {
57
- mode: "automatic";
58
- }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
59
- mode: "absolute";
60
- } | {
61
- mode: "manual";
62
- ph0: number;
63
- ph1: number;
64
- } | {
65
- mode: "automatic";
66
- }> | undefined, import("zod").ZodType<{
67
- mode: "absolute";
68
- } | {
69
- mode: "manual";
70
- ph0: number;
71
- ph1: number;
72
- } | {
73
- mode: "automatic";
74
- }, any, import("zod/v4/core").$ZodTypeInternals<{
75
- mode: "absolute";
76
- } | {
77
- mode: "manual";
78
- ph0: number;
79
- ph1: number;
80
- } | {
81
- mode: "automatic";
82
- }, any>>, import("@tanstack/react-form").FormAsyncValidateOrFn<{
83
- mode: "absolute";
84
- } | {
85
- mode: "manual";
86
- ph0: number;
87
- ph1: number;
88
- } | {
89
- mode: "automatic";
90
- }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
91
- mode: "absolute";
92
- } | {
93
- mode: "manual";
94
- ph0: number;
95
- ph1: number;
96
- } | {
97
- mode: "automatic";
98
- }> | undefined, unknown, {
99
- readonly Input: typeof import("react-science/ui")._Input;
100
- readonly NumericInput: typeof import("react-science/ui")._NumericInput;
101
- readonly Checkbox: typeof import("react-science/ui")._Checkbox;
102
- readonly Select: typeof import("react-science/ui")._Select;
103
- readonly Switch: typeof import("react-science/ui")._Switch;
104
- readonly ColorPicker: typeof import("react-science/ui")._ColorPicker;
105
- readonly RadioGroup: typeof import("react-science/ui")._RadioGroup;
106
- readonly DraggableNumericInput: typeof import("react-science/ui")._DraggableNumericInput;
107
- }, {
108
- readonly SubmitButton: typeof import("react-science/ui")._SubmitButton;
109
- readonly ResetButton: typeof import("react-science/ui")._ResetButton;
110
- readonly Section: typeof import("react-science/ui")._Section;
111
- }>;
2
+ export declare function usePhaseCorrectionForm(props: ProcessingOperatorUISettingsFormProps<'@zakodium/nmrium-core-plugins#phaseCorrection1D'>): {
3
+ form: import("@tanstack/react-form").AppFieldExtendedReactFormApi<{
4
+ mode: "absolute";
5
+ } | {
6
+ mode: "manual";
7
+ ph0: number;
8
+ ph1: number;
9
+ } | {
10
+ mode: "automatic-compute";
11
+ } | {
12
+ mode: "automatic-info";
13
+ }, import("@tanstack/react-form").FormValidateOrFn<{
14
+ mode: "absolute";
15
+ } | {
16
+ mode: "manual";
17
+ ph0: number;
18
+ ph1: number;
19
+ } | {
20
+ mode: "automatic-compute";
21
+ } | {
22
+ mode: "automatic-info";
23
+ }> | undefined, import("@tanstack/react-form").FormValidateOrFn<{
24
+ mode: "absolute";
25
+ } | {
26
+ mode: "manual";
27
+ ph0: number;
28
+ ph1: number;
29
+ } | {
30
+ mode: "automatic-compute";
31
+ } | {
32
+ mode: "automatic-info";
33
+ }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
34
+ mode: "absolute";
35
+ } | {
36
+ mode: "manual";
37
+ ph0: number;
38
+ ph1: number;
39
+ } | {
40
+ mode: "automatic-compute";
41
+ } | {
42
+ mode: "automatic-info";
43
+ }> | undefined, import("@tanstack/react-form").FormValidateOrFn<{
44
+ mode: "absolute";
45
+ } | {
46
+ mode: "manual";
47
+ ph0: number;
48
+ ph1: number;
49
+ } | {
50
+ mode: "automatic-compute";
51
+ } | {
52
+ mode: "automatic-info";
53
+ }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
54
+ mode: "absolute";
55
+ } | {
56
+ mode: "manual";
57
+ ph0: number;
58
+ ph1: number;
59
+ } | {
60
+ mode: "automatic-compute";
61
+ } | {
62
+ mode: "automatic-info";
63
+ }> | undefined, import("@tanstack/react-form").FormValidateOrFn<{
64
+ mode: "absolute";
65
+ } | {
66
+ mode: "manual";
67
+ ph0: number;
68
+ ph1: number;
69
+ } | {
70
+ mode: "automatic-compute";
71
+ } | {
72
+ mode: "automatic-info";
73
+ }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
74
+ mode: "absolute";
75
+ } | {
76
+ mode: "manual";
77
+ ph0: number;
78
+ ph1: number;
79
+ } | {
80
+ mode: "automatic-compute";
81
+ } | {
82
+ mode: "automatic-info";
83
+ }> | undefined, import("zod").ZodType<{
84
+ mode: "absolute";
85
+ } | {
86
+ mode: "manual";
87
+ ph0: number;
88
+ ph1: number;
89
+ } | {
90
+ mode: "automatic-compute";
91
+ } | {
92
+ mode: "automatic-info";
93
+ }, any, import("zod/v4/core").$ZodTypeInternals<{
94
+ mode: "absolute";
95
+ } | {
96
+ mode: "manual";
97
+ ph0: number;
98
+ ph1: number;
99
+ } | {
100
+ mode: "automatic-compute";
101
+ } | {
102
+ mode: "automatic-info";
103
+ }, any>>, import("@tanstack/react-form").FormAsyncValidateOrFn<{
104
+ mode: "absolute";
105
+ } | {
106
+ mode: "manual";
107
+ ph0: number;
108
+ ph1: number;
109
+ } | {
110
+ mode: "automatic-compute";
111
+ } | {
112
+ mode: "automatic-info";
113
+ }> | undefined, import("@tanstack/react-form").FormAsyncValidateOrFn<{
114
+ mode: "absolute";
115
+ } | {
116
+ mode: "manual";
117
+ ph0: number;
118
+ ph1: number;
119
+ } | {
120
+ mode: "automatic-compute";
121
+ } | {
122
+ mode: "automatic-info";
123
+ }> | undefined, unknown, {
124
+ readonly Input: typeof import("react-science/ui")._Input;
125
+ readonly NumericInput: typeof import("react-science/ui")._NumericInput;
126
+ readonly Checkbox: typeof import("react-science/ui")._Checkbox;
127
+ readonly Select: typeof import("react-science/ui")._Select;
128
+ readonly Switch: typeof import("react-science/ui")._Switch;
129
+ readonly ColorPicker: typeof import("react-science/ui")._ColorPicker;
130
+ readonly RadioGroup: typeof import("react-science/ui")._RadioGroup;
131
+ readonly DraggableNumericInput: typeof import("react-science/ui")._DraggableNumericInput;
132
+ }, {
133
+ readonly SubmitButton: typeof import("react-science/ui")._SubmitButton;
134
+ readonly ResetButton: typeof import("react-science/ui")._ResetButton;
135
+ readonly Section: typeof import("react-science/ui")._Section;
136
+ }>;
137
+ selectModeProps: Pick<import("react-science/ui").SelectProps, "itemDisabled" | "items">;
138
+ appFieldModeListeners: import("@tanstack/react-form").FieldListeners<{
139
+ mode: "absolute";
140
+ } | {
141
+ mode: "manual";
142
+ ph0: number;
143
+ ph1: number;
144
+ } | {
145
+ mode: "automatic-compute";
146
+ } | {
147
+ mode: "automatic-info";
148
+ }, "mode" | "ph0" | "ph1", number | "absolute" | "manual" | "automatic-compute" | "automatic-info">;
149
+ };
112
150
  //# sourceMappingURL=phase_correction.hook.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phase_correction.hook.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,uBAAuB,CAAC;AAInF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,qCAAqC,CAAC,iDAAiD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyChG"}
1
+ {"version":3,"file":"phase_correction.hook.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qCAAqC,EAEtC,MAAM,uBAAuB,CAAC;AA6B/B,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,qCAAqC,CAAC,iDAAiD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkFhG"}
@@ -1,8 +1,24 @@
1
1
  import { revalidateLogic } from '@tanstack/react-form';
2
- import { useEffect } from 'react';
2
+ import { castSpectrum1D } from '@zakodium/nmrium-core';
3
+ import { cast } from '@zakodium/utils';
4
+ import { autoPhaseCorrection } from 'nmr-processing';
5
+ import { useEffect, useMemo } from 'react';
3
6
  import { useForm } from 'react-science/ui';
7
+ const items = [
8
+ {
9
+ value: 'automatic-compute',
10
+ label: 'Automatic from data computation',
11
+ },
12
+ {
13
+ value: 'automatic-info',
14
+ label: 'Automatic from spectrum informations',
15
+ },
16
+ { value: 'manual', label: 'Manual' },
17
+ { value: 'absolute', label: 'Absolute' },
18
+ ];
4
19
  export function usePhaseCorrectionForm(props) {
5
- const { operation, core, onSubmit, onChange } = props;
20
+ const { spectrum, operation, core, onSubmit, onChange } = props;
21
+ castSpectrum1D(spectrum);
6
22
  const { settings } = operation;
7
23
  const operator = core.getOperationOperator('@zakodium/nmrium-core-plugins#phaseCorrection1D', operation);
8
24
  const { schemaSettings } = operator;
@@ -32,6 +48,37 @@ export function usePhaseCorrectionForm(props) {
32
48
  useEffect(() => {
33
49
  form.reset(settings, { keepDefaultValues: true });
34
50
  }, [form, settings]);
35
- return form;
51
+ const shouldDisableAutoInfoMode = useMemo(() => {
52
+ const { phc0 = 0, phc1 = 0 } = spectrum.info;
53
+ return phc0 === 0 && phc1 === 0;
54
+ }, [spectrum]);
55
+ const selectModeProps = {
56
+ items,
57
+ itemDisabled: (item) => {
58
+ cast(item);
59
+ return item.value === 'automatic-info' && shouldDisableAutoInfoMode;
60
+ },
61
+ };
62
+ const appFieldModeListeners = {
63
+ onChange: ({ value, fieldApi }) => {
64
+ // It is not strictly typed to `<AppField name="mode">`,
65
+ // so little safety check if the listener is attached to the right field.
66
+ // NB: `Extract<AppFieldProps, {name: 'mode'}>` returns `never`.
67
+ if (fieldApi.name !== 'mode')
68
+ return;
69
+ if (value !== 'manual')
70
+ return;
71
+ // When we switch to manual mode, we should set ph0 and ph1 from `autoPhaseCorrection`.
72
+ // cf: `packages/nmr/nmr-processing/src/datum/data1d/filter1d/phaseCorrection.ts`
73
+ // when ph0 and ph1 are not available.
74
+ let phases = autoPhaseCorrection(spectrum);
75
+ if (phases.ph0 === 0 && phases.ph1 === 0) {
76
+ phases = autoPhaseCorrection(spectrum, { magnitudeMode: true });
77
+ }
78
+ form.setFieldValue('ph0', phases.ph0);
79
+ form.setFieldValue('ph1', phases.ph1);
80
+ },
81
+ };
82
+ return { form, selectModeProps, appFieldModeListeners };
36
83
  }
37
84
  //# sourceMappingURL=phase_correction.hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"phase_correction.hook.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM,UAAU,sBAAsB,CACpC,KAA+F;IAE/F,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAEtD,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,oBAAoB,CACxC,iDAAiD,EACjD,SAAS,CACV,CAAC;IAEF,MAAM,EAAE,cAAc,EAAE,GAAG,QAAQ,CAAC;IACpC,MAAM,IAAI,GAAG,OAAO,CAAC;QACnB,aAAa,EAAE,QAAQ;QACvB,UAAU,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE;QACzC,eAAe,EAAE,eAAe,EAAE;QAClC,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;YACtB,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAEtB,MAAM,YAAY,GAAG;gBACnB,GAAG,SAAS;gBACZ,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC;aACtC,CAAC;YAEF,QAAQ,CAAC,YAAY,CAAC,CAAC;QACzB,CAAC;QACD,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;gBACxB,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC9D,IAAI,CAAC,MAAM,CAAC,OAAO;oBAAE,OAAO;gBAE5B,MAAM,aAAa,GAAG,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC9D,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC1B,CAAC;SACF;KACF,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAErB,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"phase_correction.hook.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAKvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAU3C,MAAM,KAAK,GAAW;IACpB;QACE,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,iCAAiC;KACzC;IACD;QACE,KAAK,EAAE,gBAAgB;QACvB,KAAK,EAAE,sCAAsC;KAC9C;IACD,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;IACpC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;CACzC,CAAC;AAEF,MAAM,UAAU,sBAAsB,CACpC,KAA+F;IAE/F,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI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CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"phase_correction_expanded.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,uBAAuB,CAAC;AAOnF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,qCAAqC,CAAC,iDAAiD,CAAC,+BAmEhG"}
1
+ {"version":3,"file":"phase_correction_expanded.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,uBAAuB,CAAC;AAMnF,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,qCAAqC,CAAC,iDAAiD,CAAC,+BAgDhG"}
@@ -1,24 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { castSpectrum1D } from '@zakodium/nmrium-core';
3
- import { autoPhaseCorrection } from 'nmr-processing';
4
3
  import { AppForm } from 'react-science/ui';
5
4
  import { usePhaseCorrectionForm } from "./phase_correction.hook.js";
6
5
  export function PhaseCorrectionExpanded(props) {
7
- const form = usePhaseCorrectionForm(props);
6
+ const { form, selectModeProps, appFieldModeListeners } = usePhaseCorrectionForm(props);
8
7
  const { spectrum, children } = props;
9
8
  castSpectrum1D(spectrum);
10
- return (_jsxs(AppForm, { form: form, layout: "stacked", children: [children?.(_jsx(form.SubmitButton, { variant: "outlined", size: "small", intent: "success", children: "Apply" })), _jsx(form.AppField, { name: "mode", listeners: {
11
- onChange: ({ value, fieldApi }) => {
12
- if (value === 'manual') {
13
- const { ph0, ph1 } = autoPhaseCorrection(spectrum);
14
- fieldApi.form.setFieldValue('ph0', ph0);
15
- fieldApi.form.setFieldValue('ph1', ph1);
16
- }
17
- },
18
- }, children: (field) => (_jsxs(_Fragment, { children: [_jsx(field.Select, { label: "Mode", layout: "inline", items: [
19
- { value: 'automatic', label: 'Automatic' },
20
- { value: 'manual', label: 'Manual' },
21
- { value: 'absolute', label: 'Absolute' },
22
- ] }), field.state.value === 'manual' && (_jsxs(_Fragment, { children: [_jsx(form.AppField, { name: "ph0", children: (field) => (_jsx(field.DraggableNumericInput, { label: "PH0", draggableLabel: "Change PH0 (click and drag)", draggableIntent: "success" })) }), _jsx(form.AppField, { name: "ph1", children: (field) => (_jsx(field.DraggableNumericInput, { label: "PH1", draggableLabel: "Change PH1 (click and drag)", draggableIntent: "success" })) })] }))] })) })] }));
9
+ return (_jsxs(AppForm, { form: form, layout: "stacked", children: [children?.(_jsx(form.SubmitButton, { variant: "outlined", size: "small", intent: "success", children: "Apply" })), _jsx(form.AppField, { name: "mode", listeners: appFieldModeListeners, children: (field) => (_jsxs(_Fragment, { children: [_jsx(field.Select, { label: "Mode", layout: "inline", ...selectModeProps }), field.state.value === 'manual' && (_jsxs(_Fragment, { children: [_jsx(form.AppField, { name: "ph0", children: (field) => (_jsx(field.DraggableNumericInput, { label: "PH0", draggableLabel: "Change PH0 (click and drag)", draggableIntent: "success" })) }), _jsx(form.AppField, { name: "ph1", children: (field) => (_jsx(field.DraggableNumericInput, { label: "PH1", draggableLabel: "Change PH1 (click and drag)", draggableIntent: "success" })) })] }))] })) })] }));
23
10
  }
24
11
  //# sourceMappingURL=phase_correction_expanded.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"phase_correction_expanded.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,MAAM,UAAU,uBAAuB,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ACE,KAAC,IAAI,CAAC,QAAQ,IAAC,IAAI,EAAC,KAAK,YACtB,CAAC,KAAK,EAAE,EAAE,CAAC,CACV,KAAC,KAAK,CAAC,qBAAqB,IAC1B,KAAK,EAAC,KAAK,EACX,cAAc,EAAC,6BAA6B,EAC5C,eAAe,EAAC,SAAS,GACzB,CACH,GACa,EAEhB,KAAC,IAAI,CAAC,QAAQ,IAAC,IAAI,EAAC,KAAK,YACtB,CAAC,KAAK,EAAE,EAAE,CAAC,CACV,KAAC,KAAK,CAAC,qBAAqB,IAC1B,KAAK,EAAC,KAAK,EACX,cAAc,EAAC,6BAA6B,EAC5C,eAAe,EAAC,SAAS,GACzB,CACH,GACa,IACf,CACJ,IACA,CACJ,GACa,IACR,CACX,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"phase_correction_expanded.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,MAAM,UAAU,uBAAuB,CACrC,KAA+F;IAE/F,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,qBAAqB,EAAE,GACpD,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACrC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEzB,OAAO,CACL,MAAC,OAAO,IAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAC,SAAS,aAClC,QAAQ,EAAE,CACT,KAAC,IAAI,CAAC,YAAY,IAAC,OAAO,EAAC,UAAU,EAAC,IAAI,EAAC,OAAO,EAAC,MAAM,EAAC,SAAS,sBAE/C,CACrB,EAED,KAAC,IAAI,CAAC,QAAQ,IAAC,IAAI,EAAC,MAAM,EAAC,SAAS,EAAE,qBAAqB,YACxD,CAAC,KAAK,EAAE,EAAE,CAAC,CACV,8BACE,KAAC,KAAK,CAAC,MAAM,IAAC,KAAK,EAAC,MAAM,EAAC,MAAM,EAAC,QAAQ,KAAK,eAAe,GAAI,EAEjE,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,CACjC,8BACE,KAAC,IAAI,CAAC,QAAQ,IAAC,IAAI,EAAC,KAAK,YACtB,CAAC,KAAK,EAAE,EAAE,CAAC,CACV,KAAC,KAAK,CAAC,qBAAqB,IAC1B,KAAK,EAAC,KAAK,EACX,cAAc,EAAC,6BAA6B,EAC5C,eAAe,EAAC,SAAS,GACzB,CACH,GACa,EAEhB,KAAC,IAAI,CAAC,QAAQ,IAAC,IAAI,EAAC,KAAK,YACtB,CAAC,KAAK,EAAE,EAAE,CAAC,CACV,KAAC,KAAK,CAAC,qBAAqB,IAC1B,KAAK,EAAC,KAAK,EACX,cAAc,EAAC,6BAA6B,EAC5C,eAAe,EAAC,SAAS,GACzB,CACH,GACa,IACf,CACJ,IACA,CACJ,GACa,IACR,CACX,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"phase_correction_tool.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_tool.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,6BAA6B,EAE9B,MAAM,uBAAuB,CAAC;AAmB/B,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,6BAA6B,CAAC,iDAAiD,CAAC,sCAmDxF"}
1
+ {"version":3,"file":"phase_correction_tool.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_tool.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,6BAA6B,EAG9B,MAAM,uBAAuB,CAAC;AAkC/B,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,6BAA6B,CAAC,iDAAiD,CAAC,sCAoDxF"}
@@ -1,14 +1,20 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useHotkeys } from '@blueprintjs/core';
3
- import { generateID, isSpectrum1DFt } from '@zakodium/nmrium-core';
3
+ import { castSpectrum1D, generateID, isSpectrum1DFt, } from '@zakodium/nmrium-core';
4
4
  import { SvgNmrPhaseCorrection } from 'cheminfo-font';
5
5
  import { useMemo } from 'react';
6
6
  import { Toolbar, TooltipHelpContent } from 'react-science/ui';
7
7
  import { useEventCallback } from 'usehooks-ts';
8
- function defaultPhaseCorrectionOperation() {
8
+ function getPhaseCorrection1DSettings(spectrum) {
9
+ const { phc0 = 0, phc1 = 0 } = spectrum.info;
10
+ if (phc0 === 0 && phc1 === 0)
11
+ return { mode: 'automatic-compute' };
12
+ return { mode: 'automatic-info' };
13
+ }
14
+ function defaultPhaseCorrectionOperation(spectrum) {
9
15
  return {
10
16
  operatorId: '@zakodium/nmrium-core-plugins#phaseCorrection1D',
11
- settings: { mode: 'automatic' },
17
+ settings: getPhaseCorrection1DSettings(spectrum),
12
18
  options: undefined,
13
19
  error: undefined,
14
20
  uid: generateID(),
@@ -17,6 +23,7 @@ function defaultPhaseCorrectionOperation() {
17
23
  }
18
24
  export function PhaseCorrectionTool(props) {
19
25
  const { spectrum, activeOperatorId, onTriggerOperation } = props;
26
+ castSpectrum1D(spectrum);
20
27
  const isActive = activeOperatorId === '@zakodium/nmrium-core-plugins#phaseCorrection1D';
21
28
  const isVisible = isSpectrum1DFt(spectrum) && spectrum.info.isComplex;
22
29
  const triggerOperation = useEventCallback((event) => {
@@ -25,7 +32,7 @@ export function PhaseCorrectionTool(props) {
25
32
  // nmrium keyboard listener is also on document
26
33
  event.stopImmediatePropagation();
27
34
  }
28
- onTriggerOperation(defaultPhaseCorrectionOperation());
35
+ onTriggerOperation(defaultPhaseCorrectionOperation(spectrum));
29
36
  });
30
37
  const hotkeys = useMemo(() => {
31
38
  return [
@@ -1 +1 @@
1
- {"version":3,"file":"phase_correction_tool.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_tool.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,SAAS,+BAA+B;IACtC,OAAO;QACL,UAAU,EAAE,iDAAiD;QAC7D,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;QAC/B,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,UAAU,EAAE;QACjB,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,KAAuF;IAEvF,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC;IAEjE,MAAM,QAAQ,GACZ,gBAAgB,KAAK,iDAAiD,CAAC;IAEzE,MAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;IAEtE,MAAM,gBAAgB,GAAG,gBAAgB,CACvC,CAAC,KAAiC,EAAE,EAAE;QACpC,IAAI,0BAA0B,IAAI,KAAK,EAAE,CAAC;YACxC,wCAAwC;YACxC,+CAA+C;YAC/C,KAAK,CAAC,wBAAwB,EAAE,CAAC;QACnC,CAAC;QAED,kBAAkB,CAAC,+BAA+B,EAAE,CAAC,CAAC;IACxD,CAAC,CACF,CAAC;IAEF,MAAM,OAAO,GAAG,OAAO,CAAiB,GAAG,EAAE;QAC3C,OAAO;YACL;gBACE,KAAK,EAAE,GAAG;gBACV,KAAK,EAAE,kBAAkB;gBACzB,MAAM,EAAE,IAAI;gBACZ,SAAS,EAAE,gBAAgB;aAC5B;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAE5B,OAAO,CACL,KAAC,OAAO,CAAC,IAAI,IACX,EAAE,EAAC,iDAAiD,EACpD,IAAI,EAAE,KAAC,qBAAqB,KAAG,EAC/B,OAAO,EACL,KAAC,kBAAkB,IACjB,KAAK,EAAC,kBAAkB,EACxB,SAAS,EAAE,CAAC,GAAG,CAAC,EAChB,WAAW,EAAC,gLAAgL,EAC5L,IAAI,EAAC,qCAAqC,GAC1C,EAEJ,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,gBAAgB,GACzB,CACH,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"phase_correction_tool.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_tool.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAM/C,OAAO,EACL,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,SAAS,4BAA4B,CACnC,QAAoB;IAEpB,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,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AC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAE5B,OAAO,CACL,KAAC,OAAO,CAAC,IAAI,IACX,EAAE,EAAC,iDAAiD,EACpD,IAAI,EAAE,KAAC,qBAAqB,KAAG,EAC/B,OAAO,EACL,KAAC,kBAAkB,IACjB,KAAK,EAAC,kBAAkB,EACxB,SAAS,EAAE,CAAC,GAAG,CAAC,EAChB,WAAW,EAAC,gLAAgL,EAC5L,IAAI,EAAC,qCAAqC,GAC1C,EAEJ,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,gBAAgB,GACzB,CACH,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakodium/nmrium-core-plugins-ui",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "license": "CC-BY-NC-SA-4.0",
5
5
  "description": "UI related plugins needed for cheminfo/nmrium",
6
6
  "keywords": [],
@@ -28,12 +28,13 @@
28
28
  "@blueprintjs/select": "^6.3.3",
29
29
  "@emotion/styled": "^11.14.1",
30
30
  "@tanstack/react-form": "^1.33.2",
31
- "@zakodium/nmrium-core": "^0.7.52",
32
- "@zakodium/nmrium-core-plugins": "^0.7.70",
31
+ "@zakodium/nmrium-core": "^0.7.53",
32
+ "@zakodium/nmrium-core-plugins": "^0.7.71",
33
+ "@zakodium/utils": "^0.5.0",
33
34
  "fifo-logger": "^2.0.1",
34
35
  "react": "^18.3.1",
35
36
  "react-dom": "^18.3.1",
36
- "react-science": "^20.6.1",
37
+ "react-science": "^20.7.0",
37
38
  "usehooks-ts": "^3.1.1",
38
39
  "zod": "^4.4.3"
39
40
  },
@@ -44,5 +45,5 @@
44
45
  "typescript": "~6.0.3",
45
46
  "vitest": "^4.1.10"
46
47
  },
47
- "gitHead": "9923521b72b11cd934452efc4a84cffeaf1c5e2c"
48
+ "gitHead": "699ffe8485c79fa4cc9a6e1f8c54282fa14f8506"
48
49
  }
@@ -1,12 +1,41 @@
1
1
  import { revalidateLogic } from '@tanstack/react-form';
2
- import type { ProcessingOperatorUISettingsFormProps } from '@zakodium/nmrium-core';
3
- import { useEffect } from 'react';
2
+ import type {
3
+ ProcessingOperatorUISettingsFormProps,
4
+ Spectrum1DProcessingTypeRegistry,
5
+ } from '@zakodium/nmrium-core';
6
+ import { castSpectrum1D } from '@zakodium/nmrium-core';
7
+ import { cast } from '@zakodium/utils';
8
+ import { autoPhaseCorrection } from 'nmr-processing';
9
+ import type { ComponentProps } from 'react';
10
+ import { useEffect, useMemo } from 'react';
4
11
  import { useForm } from 'react-science/ui';
5
12
 
13
+ type Mode =
14
+ Spectrum1DProcessingTypeRegistry['@zakodium/nmrium-core-plugins#phaseCorrection1D']['settings']['mode'];
15
+
16
+ interface Item {
17
+ value: Mode;
18
+ label: string;
19
+ }
20
+
21
+ const items: Item[] = [
22
+ {
23
+ value: 'automatic-compute',
24
+ label: 'Automatic from data computation',
25
+ },
26
+ {
27
+ value: 'automatic-info',
28
+ label: 'Automatic from spectrum informations',
29
+ },
30
+ { value: 'manual', label: 'Manual' },
31
+ { value: 'absolute', label: 'Absolute' },
32
+ ];
33
+
6
34
  export function usePhaseCorrectionForm(
7
35
  props: ProcessingOperatorUISettingsFormProps<'@zakodium/nmrium-core-plugins#phaseCorrection1D'>,
8
36
  ) {
9
- const { operation, core, onSubmit, onChange } = props;
37
+ const { spectrum, operation, core, onSubmit, onChange } = props;
38
+ castSpectrum1D(spectrum);
10
39
 
11
40
  const { settings } = operation;
12
41
  const operator = core.getOperationOperator(
@@ -44,5 +73,45 @@ export function usePhaseCorrectionForm(
44
73
  form.reset(settings, { keepDefaultValues: true });
45
74
  }, [form, settings]);
46
75
 
47
- return form;
76
+ const shouldDisableAutoInfoMode = useMemo(() => {
77
+ const { phc0 = 0, phc1 = 0 } = spectrum.info;
78
+
79
+ return phc0 === 0 && phc1 === 0;
80
+ }, [spectrum]);
81
+
82
+ type AppFieldProps = ComponentProps<typeof form.AppField>;
83
+ type AppFieldApi = Parameters<AppFieldProps['children']>[0];
84
+ type SelectProps = ComponentProps<AppFieldApi['Select']>;
85
+
86
+ const selectModeProps: Pick<SelectProps, 'items' | 'itemDisabled'> = {
87
+ items,
88
+ itemDisabled: (item) => {
89
+ cast<Item>(item);
90
+
91
+ return item.value === 'automatic-info' && shouldDisableAutoInfoMode;
92
+ },
93
+ };
94
+
95
+ const appFieldModeListeners: AppFieldProps['listeners'] = {
96
+ onChange: ({ value, fieldApi }) => {
97
+ // It is not strictly typed to `<AppField name="mode">`,
98
+ // so little safety check if the listener is attached to the right field.
99
+ // NB: `Extract<AppFieldProps, {name: 'mode'}>` returns `never`.
100
+ if (fieldApi.name !== 'mode') return;
101
+ if (value !== 'manual') return;
102
+
103
+ // When we switch to manual mode, we should set ph0 and ph1 from `autoPhaseCorrection`.
104
+ // cf: `packages/nmr/nmr-processing/src/datum/data1d/filter1d/phaseCorrection.ts`
105
+ // when ph0 and ph1 are not available.
106
+ let phases = autoPhaseCorrection(spectrum);
107
+ if (phases.ph0 === 0 && phases.ph1 === 0) {
108
+ phases = autoPhaseCorrection(spectrum, { magnitudeMode: true });
109
+ }
110
+
111
+ form.setFieldValue('ph0', phases.ph0);
112
+ form.setFieldValue('ph1', phases.ph1);
113
+ },
114
+ };
115
+
116
+ return { form, selectModeProps, appFieldModeListeners };
48
117
  }
@@ -1,6 +1,5 @@
1
1
  import type { ProcessingOperatorUISettingsFormProps } from '@zakodium/nmrium-core';
2
2
  import { castSpectrum1D } from '@zakodium/nmrium-core';
3
- import { autoPhaseCorrection } from 'nmr-processing';
4
3
  import { AppForm } from 'react-science/ui';
5
4
 
6
5
  import { usePhaseCorrectionForm } from './phase_correction.hook.ts';
@@ -8,7 +7,8 @@ import { usePhaseCorrectionForm } from './phase_correction.hook.ts';
8
7
  export function PhaseCorrectionExpanded(
9
8
  props: ProcessingOperatorUISettingsFormProps<'@zakodium/nmrium-core-plugins#phaseCorrection1D'>,
10
9
  ) {
11
- const form = usePhaseCorrectionForm(props);
10
+ const { form, selectModeProps, appFieldModeListeners } =
11
+ usePhaseCorrectionForm(props);
12
12
  const { spectrum, children } = props;
13
13
  castSpectrum1D(spectrum);
14
14
 
@@ -20,30 +20,10 @@ export function PhaseCorrectionExpanded(
20
20
  </form.SubmitButton>,
21
21
  )}
22
22
 
23
- <form.AppField
24
- name="mode"
25
- listeners={{
26
- onChange: ({ value, fieldApi }) => {
27
- if (value === 'manual') {
28
- const { ph0, ph1 } = autoPhaseCorrection(spectrum);
29
-
30
- fieldApi.form.setFieldValue('ph0', ph0);
31
- fieldApi.form.setFieldValue('ph1', ph1);
32
- }
33
- },
34
- }}
35
- >
23
+ <form.AppField name="mode" listeners={appFieldModeListeners}>
36
24
  {(field) => (
37
25
  <>
38
- <field.Select
39
- label="Mode"
40
- layout="inline"
41
- items={[
42
- { value: 'automatic', label: 'Automatic' },
43
- { value: 'manual', label: 'Manual' },
44
- { value: 'absolute', label: 'Absolute' },
45
- ]}
46
- />
26
+ <field.Select label="Mode" layout="inline" {...selectModeProps} />
47
27
 
48
28
  {field.state.value === 'manual' && (
49
29
  <>
@@ -2,19 +2,35 @@ import type { HotkeyConfig } from '@blueprintjs/core';
2
2
  import { useHotkeys } from '@blueprintjs/core';
3
3
  import type {
4
4
  ProcessingOperatorUIToolProps,
5
+ Spectrum1D,
5
6
  Spectrum1DProcessingTypeRegistry,
6
7
  } from '@zakodium/nmrium-core';
7
- import { generateID, isSpectrum1DFt } from '@zakodium/nmrium-core';
8
+ import {
9
+ castSpectrum1D,
10
+ generateID,
11
+ isSpectrum1DFt,
12
+ } from '@zakodium/nmrium-core';
8
13
  import { SvgNmrPhaseCorrection } from 'cheminfo-font';
9
14
  import type { MouseEvent } from 'react';
10
15
  import { useMemo } from 'react';
11
16
  import { Toolbar, TooltipHelpContent } from 'react-science/ui';
12
17
  import { useEventCallback } from 'usehooks-ts';
13
18
 
14
- function defaultPhaseCorrectionOperation(): Spectrum1DProcessingTypeRegistry['@zakodium/nmrium-core-plugins#phaseCorrection1D'] {
19
+ function getPhaseCorrection1DSettings(
20
+ spectrum: Spectrum1D,
21
+ ): Spectrum1DProcessingTypeRegistry['@zakodium/nmrium-core-plugins#phaseCorrection1D']['settings'] {
22
+ const { phc0 = 0, phc1 = 0 } = spectrum.info;
23
+
24
+ if (phc0 === 0 && phc1 === 0) return { mode: 'automatic-compute' };
25
+ return { mode: 'automatic-info' };
26
+ }
27
+
28
+ function defaultPhaseCorrectionOperation(
29
+ spectrum: Spectrum1D,
30
+ ): Spectrum1DProcessingTypeRegistry['@zakodium/nmrium-core-plugins#phaseCorrection1D'] {
15
31
  return {
16
32
  operatorId: '@zakodium/nmrium-core-plugins#phaseCorrection1D',
17
- settings: { mode: 'automatic' },
33
+ settings: getPhaseCorrection1DSettings(spectrum),
18
34
  options: undefined,
19
35
  error: undefined,
20
36
  uid: generateID(),
@@ -26,6 +42,7 @@ export function PhaseCorrectionTool(
26
42
  props: ProcessingOperatorUIToolProps<'@zakodium/nmrium-core-plugins#phaseCorrection1D'>,
27
43
  ) {
28
44
  const { spectrum, activeOperatorId, onTriggerOperation } = props;
45
+ castSpectrum1D(spectrum);
29
46
 
30
47
  const isActive =
31
48
  activeOperatorId === '@zakodium/nmrium-core-plugins#phaseCorrection1D';
@@ -40,7 +57,7 @@ export function PhaseCorrectionTool(
40
57
  event.stopImmediatePropagation();
41
58
  }
42
59
 
43
- onTriggerOperation(defaultPhaseCorrectionOperation());
60
+ onTriggerOperation(defaultPhaseCorrectionOperation(spectrum));
44
61
  },
45
62
  );
46
63