@zakodium/nmrium-core-plugins-ui 0.1.52 → 0.1.53
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/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.d.ts +15 -0
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.d.ts.map +1 -1
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.js +25 -3
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.js.map +1 -1
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.js +2 -2
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.js.map +1 -1
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction_topbar.js +2 -2
- package/lib/plugins/spectrum_1d_processings_ui/operators/phase_correction_topbar.js.map +1 -1
- package/package.json +2 -2
- package/src/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.ts +30 -3
- package/src/plugins/spectrum_1d_processings_ui/operators/phase_correction_expanded.tsx +2 -2
- package/src/plugins/spectrum_1d_processings_ui/operators/phase_correction_topbar.tsx +2 -2
|
@@ -199,5 +199,20 @@ export declare function usePhaseCorrectionForm(props: ProcessingOperatorUISettin
|
|
|
199
199
|
mode: "automatic-info";
|
|
200
200
|
pivotIndex?: number | undefined;
|
|
201
201
|
}, "mode" | "pivotIndex" | "ph0" | "ph1", number | "absolute" | "manual" | "automatic-compute" | "automatic-info" | undefined>;
|
|
202
|
+
appFieldPh1Listeners: import("@tanstack/react-form").FieldListeners<{
|
|
203
|
+
mode: "absolute";
|
|
204
|
+
pivotIndex?: number | undefined;
|
|
205
|
+
} | {
|
|
206
|
+
mode: "manual";
|
|
207
|
+
ph0: number;
|
|
208
|
+
ph1: number;
|
|
209
|
+
pivotIndex?: number | undefined;
|
|
210
|
+
} | {
|
|
211
|
+
mode: "automatic-compute";
|
|
212
|
+
pivotIndex?: number | undefined;
|
|
213
|
+
} | {
|
|
214
|
+
mode: "automatic-info";
|
|
215
|
+
pivotIndex?: number | undefined;
|
|
216
|
+
}, "mode" | "pivotIndex" | "ph0" | "ph1", number | "absolute" | "manual" | "automatic-compute" | "automatic-info" | undefined>;
|
|
202
217
|
};
|
|
203
218
|
//# 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":"AAKA,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,uBAAuB,CAAC;AA8BnF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,qCAAqC,CAAC,iDAAiD,CAAC
|
|
1
|
+
{"version":3,"file":"phase_correction.hook.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction.hook.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,uBAAuB,CAAC;AA8BnF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,qCAAqC,CAAC,iDAAiD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8HhG"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { revalidateLogic } from '@tanstack/react-form';
|
|
2
2
|
import { castSpectrum1D } from '@zakodium/nmrium-core';
|
|
3
|
-
import { cast } from '@zakodium/utils';
|
|
3
|
+
import { assert, cast } from '@zakodium/utils';
|
|
4
4
|
import { xFindClosestIndex, xMaxAbsoluteValue } from 'ml-spectra-processing';
|
|
5
5
|
import { autoPhaseCorrection } from 'nmr-processing';
|
|
6
|
-
import { useEffect, useMemo } from 'react';
|
|
6
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
7
7
|
import { useForm } from 'react-science/ui';
|
|
8
8
|
const items = [
|
|
9
9
|
{
|
|
@@ -77,6 +77,7 @@ export function usePhaseCorrectionForm(props) {
|
|
|
77
77
|
phases = autoPhaseCorrection(spectrum, { magnitudeMode: true });
|
|
78
78
|
}
|
|
79
79
|
const { ph0, ph1 } = phases;
|
|
80
|
+
prevPh1Ref.current = ph1;
|
|
80
81
|
form.setFieldValue('ph0', ph0, { dontRunListeners: true });
|
|
81
82
|
form.setFieldValue('ph1', ph1, { dontRunListeners: true });
|
|
82
83
|
// reuse previous pivotIndex or compute it if missing
|
|
@@ -92,7 +93,28 @@ export function usePhaseCorrectionForm(props) {
|
|
|
92
93
|
onChange({ ...operation, settings });
|
|
93
94
|
},
|
|
94
95
|
};
|
|
95
|
-
|
|
96
|
+
const prevPh1Ref = useRef(form.state.values.mode === 'manual' ? form.state.values.ph1 : 0);
|
|
97
|
+
const appFieldPh1Listeners = {
|
|
98
|
+
onChange: ({ value, fieldApi }) => {
|
|
99
|
+
// It is not strictly typed to `<AppField name="mode">`,
|
|
100
|
+
// so little safety check if the listener is attached to the right field.
|
|
101
|
+
// NB: `Extract<AppFieldProps, {name: 'mode'}>` returns `never`.
|
|
102
|
+
if (fieldApi.name !== 'ph1')
|
|
103
|
+
return;
|
|
104
|
+
assert(form.state.values.mode === 'manual');
|
|
105
|
+
const ph1 = Number(value);
|
|
106
|
+
if (Number.isNaN(ph1))
|
|
107
|
+
return;
|
|
108
|
+
const diff = ph1 - prevPh1Ref.current;
|
|
109
|
+
const pivotIndex = form.state.values.pivotIndex ?? 0;
|
|
110
|
+
const length = spectrum.data.re.length;
|
|
111
|
+
const factor = length - pivotIndex;
|
|
112
|
+
const ph0 = form.state.values.ph0 - (diff * factor) / length;
|
|
113
|
+
prevPh1Ref.current = ph1;
|
|
114
|
+
form.setFieldValue('ph0', ph0);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
return { form, selectModeProps, appFieldModeListeners, appFieldPh1Listeners };
|
|
96
118
|
}
|
|
97
119
|
function findStrongestPeak(spectrum) {
|
|
98
120
|
const re = spectrum.data.re;
|
|
@@ -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;AAMvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,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;AAMvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACnD,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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AC,KAAK,CAAC,CAAC;YAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;gBAAE,OAAO;YAE9B,MAAM,IAAI,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC;YACtC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;YACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;YACvC,MAAM,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;YAEnC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;YAE7D,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC;YACzB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;AAChF,CAAC;AAED,SAAS,iBAAiB,CAAC,QAAoB;IAC7C,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACnC,OAAO,iBAAiB,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -3,9 +3,9 @@ import { castSpectrum1D } from '@zakodium/nmrium-core';
|
|
|
3
3
|
import { AppForm } from 'react-science/ui';
|
|
4
4
|
import { usePhaseCorrectionForm } from "./phase_correction.hook.js";
|
|
5
5
|
export function PhaseCorrectionExpanded(props) {
|
|
6
|
-
const { form, selectModeProps, appFieldModeListeners } = usePhaseCorrectionForm(props);
|
|
6
|
+
const { form, selectModeProps, appFieldModeListeners, appFieldPh1Listeners } = usePhaseCorrectionForm(props);
|
|
7
7
|
const { spectrum, children } = props;
|
|
8
8
|
castSpectrum1D(spectrum);
|
|
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" })) })] }))] })) })] }));
|
|
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", listeners: appFieldPh1Listeners, children: (field) => (_jsx(field.DraggableNumericInput, { label: "PH1", draggableLabel: "Change PH1 (click and drag)", draggableIntent: "success" })) })] }))] })) })] }));
|
|
10
10
|
}
|
|
11
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,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,
|
|
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,oBAAoB,EAAE,GAC1E,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,EAAC,SAAS,EAAE,oBAAoB,YACtD,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"}
|
|
@@ -5,7 +5,7 @@ import { usePhaseCorrectionForm } from "./phase_correction.hook.js";
|
|
|
5
5
|
export function PhaseCorrectionTopbar(props) {
|
|
6
6
|
const { children, spectrum } = props;
|
|
7
7
|
castSpectrum1D(spectrum);
|
|
8
|
-
const { form, selectModeProps, appFieldModeListeners } = usePhaseCorrectionForm(props);
|
|
9
|
-
return (_jsxs(HorizontalAppForm, { form: form, layout: "inline", children: [_jsx(form.AppField, { name: "mode", listeners: appFieldModeListeners, children: (field) => (_jsxs(_Fragment, { children: [_jsx(field.Select, { layout: "inline", ...selectModeProps }), field.state.value === 'manual' && (_jsxs(_Fragment, { children: [_jsx(form.AppField, { name: "ph0", children: (field) => (_jsx(field.DraggableNumericInput, { hideInput: true, draggableLabel: "Change PH0 (click and drag)", draggableIntent: "success" })) }), _jsx(form.AppField, { name: "ph1", children: (field) => (_jsx(field.DraggableNumericInput, { hideInput: true, draggableLabel: "Change PH1 (click and drag)", draggableIntent: "success" })) })] }))] })) }), children(_jsx(form.SubmitButton, { variant: "outlined", size: "small", intent: "success", children: "Apply" }))] }));
|
|
8
|
+
const { form, selectModeProps, appFieldModeListeners, appFieldPh1Listeners } = usePhaseCorrectionForm(props);
|
|
9
|
+
return (_jsxs(HorizontalAppForm, { form: form, layout: "inline", children: [_jsx(form.AppField, { name: "mode", listeners: appFieldModeListeners, children: (field) => (_jsxs(_Fragment, { children: [_jsx(field.Select, { layout: "inline", ...selectModeProps }), field.state.value === 'manual' && (_jsxs(_Fragment, { children: [_jsx(form.AppField, { name: "ph0", children: (field) => (_jsx(field.DraggableNumericInput, { hideInput: true, draggableLabel: "Change PH0 (click and drag)", draggableIntent: "success" })) }), _jsx(form.AppField, { name: "ph1", listeners: appFieldPh1Listeners, children: (field) => (_jsx(field.DraggableNumericInput, { hideInput: true, draggableLabel: "Change PH1 (click and drag)", draggableIntent: "success" })) })] }))] })) }), children(_jsx(form.SubmitButton, { variant: "outlined", size: "small", intent: "success", children: "Apply" }))] }));
|
|
10
10
|
}
|
|
11
11
|
//# sourceMappingURL=phase_correction_topbar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phase_correction_topbar.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_topbar.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAkC,CAAC;AAErE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,MAAM,UAAU,qBAAqB,CACnC,KAA+F;IAE/F,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACrC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAEzB,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"phase_correction_topbar.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/phase_correction_topbar.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,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AY,IAAC,OAAO,EAAC,UAAU,EAAC,IAAI,EAAC,OAAO,EAAC,MAAM,EAAC,SAAS,sBAE/C,CACrB,IACiB,CACrB,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.
|
|
3
|
+
"version": "0.1.53",
|
|
4
4
|
"license": "CC-BY-NC-SA-4.0",
|
|
5
5
|
"description": "UI related plugins needed for cheminfo/nmrium",
|
|
6
6
|
"keywords": [],
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"volta": {
|
|
53
53
|
"extends": "../../../package.json"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e3f9894f682f35e4745e7629df511b4f099924bb"
|
|
56
56
|
}
|
|
@@ -5,11 +5,11 @@ import type {
|
|
|
5
5
|
} from '@zakodium/nmr-types';
|
|
6
6
|
import type { ProcessingOperatorUISettingsFormProps } from '@zakodium/nmrium-core';
|
|
7
7
|
import { castSpectrum1D } from '@zakodium/nmrium-core';
|
|
8
|
-
import { cast } from '@zakodium/utils';
|
|
8
|
+
import { assert, cast } from '@zakodium/utils';
|
|
9
9
|
import { xFindClosestIndex, xMaxAbsoluteValue } from 'ml-spectra-processing';
|
|
10
10
|
import { autoPhaseCorrection } from 'nmr-processing';
|
|
11
11
|
import type { ComponentProps } from 'react';
|
|
12
|
-
import { useEffect, useMemo } from 'react';
|
|
12
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
13
13
|
import { useForm } from 'react-science/ui';
|
|
14
14
|
|
|
15
15
|
type Mode =
|
|
@@ -112,6 +112,7 @@ export function usePhaseCorrectionForm(
|
|
|
112
112
|
|
|
113
113
|
const { ph0, ph1 } = phases;
|
|
114
114
|
|
|
115
|
+
prevPh1Ref.current = ph1;
|
|
115
116
|
form.setFieldValue('ph0', ph0, { dontRunListeners: true });
|
|
116
117
|
form.setFieldValue('ph1', ph1, { dontRunListeners: true });
|
|
117
118
|
|
|
@@ -132,7 +133,33 @@ export function usePhaseCorrectionForm(
|
|
|
132
133
|
},
|
|
133
134
|
};
|
|
134
135
|
|
|
135
|
-
|
|
136
|
+
const prevPh1Ref = useRef(
|
|
137
|
+
form.state.values.mode === 'manual' ? form.state.values.ph1 : 0,
|
|
138
|
+
);
|
|
139
|
+
const appFieldPh1Listeners: AppFieldProps['listeners'] = {
|
|
140
|
+
onChange: ({ value, fieldApi }) => {
|
|
141
|
+
// It is not strictly typed to `<AppField name="mode">`,
|
|
142
|
+
// so little safety check if the listener is attached to the right field.
|
|
143
|
+
// NB: `Extract<AppFieldProps, {name: 'mode'}>` returns `never`.
|
|
144
|
+
if (fieldApi.name !== 'ph1') return;
|
|
145
|
+
assert(form.state.values.mode === 'manual');
|
|
146
|
+
|
|
147
|
+
const ph1 = Number(value);
|
|
148
|
+
if (Number.isNaN(ph1)) return;
|
|
149
|
+
|
|
150
|
+
const diff = ph1 - prevPh1Ref.current;
|
|
151
|
+
const pivotIndex = form.state.values.pivotIndex ?? 0;
|
|
152
|
+
const length = spectrum.data.re.length;
|
|
153
|
+
const factor = length - pivotIndex;
|
|
154
|
+
|
|
155
|
+
const ph0 = form.state.values.ph0 - (diff * factor) / length;
|
|
156
|
+
|
|
157
|
+
prevPh1Ref.current = ph1;
|
|
158
|
+
form.setFieldValue('ph0', ph0);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return { form, selectModeProps, appFieldModeListeners, appFieldPh1Listeners };
|
|
136
163
|
}
|
|
137
164
|
|
|
138
165
|
function findStrongestPeak(spectrum: Spectrum1D) {
|
|
@@ -7,7 +7,7 @@ import { usePhaseCorrectionForm } from './phase_correction.hook.ts';
|
|
|
7
7
|
export function PhaseCorrectionExpanded(
|
|
8
8
|
props: ProcessingOperatorUISettingsFormProps<'@zakodium/nmrium-core-plugins#phaseCorrection1D'>,
|
|
9
9
|
) {
|
|
10
|
-
const { form, selectModeProps, appFieldModeListeners } =
|
|
10
|
+
const { form, selectModeProps, appFieldModeListeners, appFieldPh1Listeners } =
|
|
11
11
|
usePhaseCorrectionForm(props);
|
|
12
12
|
const { spectrum, children } = props;
|
|
13
13
|
castSpectrum1D(spectrum);
|
|
@@ -37,7 +37,7 @@ export function PhaseCorrectionExpanded(
|
|
|
37
37
|
)}
|
|
38
38
|
</form.AppField>
|
|
39
39
|
|
|
40
|
-
<form.AppField name="ph1">
|
|
40
|
+
<form.AppField name="ph1" listeners={appFieldPh1Listeners}>
|
|
41
41
|
{(field) => (
|
|
42
42
|
<field.DraggableNumericInput
|
|
43
43
|
label="PH1"
|
|
@@ -11,7 +11,7 @@ export function PhaseCorrectionTopbar(
|
|
|
11
11
|
const { children, spectrum } = props;
|
|
12
12
|
castSpectrum1D(spectrum);
|
|
13
13
|
|
|
14
|
-
const { form, selectModeProps, appFieldModeListeners } =
|
|
14
|
+
const { form, selectModeProps, appFieldModeListeners, appFieldPh1Listeners } =
|
|
15
15
|
usePhaseCorrectionForm(props);
|
|
16
16
|
|
|
17
17
|
return (
|
|
@@ -33,7 +33,7 @@ export function PhaseCorrectionTopbar(
|
|
|
33
33
|
)}
|
|
34
34
|
</form.AppField>
|
|
35
35
|
|
|
36
|
-
<form.AppField name="ph1">
|
|
36
|
+
<form.AppField name="ph1" listeners={appFieldPh1Listeners}>
|
|
37
37
|
{(field) => (
|
|
38
38
|
<field.DraggableNumericInput
|
|
39
39
|
hideInput
|