nmrium 0.59.0 → 0.60.0

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.
Files changed (95) hide show
  1. package/lib/component/1d/LinesSeries.js +17 -5
  2. package/lib/component/1d/Viewer1D.js +10 -4
  3. package/lib/component/1d/ranges/Range.js +4 -2
  4. package/lib/component/1d/tool/PivotIndicator.d.ts +1 -0
  5. package/lib/component/1d/tool/{VerticalIndicator.js → PivotIndicator.js} +8 -4
  6. package/lib/component/1d-2d/tools/BrushXY.js +0 -1
  7. package/lib/component/1d-2d/tools/CrossLinePointer.js +0 -1
  8. package/lib/component/2d/Viewer2D.js +1 -1
  9. package/lib/component/2d/tools/PivotIndicator.d.ts +1 -2
  10. package/lib/component/2d/tools/PivotIndicator.js +2 -3
  11. package/lib/component/elements/DialogManager.d.ts +34 -0
  12. package/lib/component/elements/DialogManager.js +96 -0
  13. package/lib/component/elements/DraggableDialog.d.ts +13 -0
  14. package/lib/component/elements/DraggableDialog.js +156 -0
  15. package/lib/component/elements/TabTitle.d.ts +9 -0
  16. package/lib/component/elements/TabTitle.js +18 -0
  17. package/lib/component/header/ApodizationOptionsPanel.js +2 -2
  18. package/lib/component/hooks/useSaveSettings.d.ts +1 -1
  19. package/lib/component/hooks/useSaveSettings.js +18 -22
  20. package/lib/component/main/InnerNMRium.js +2 -2
  21. package/lib/component/main/InnerNMRiumContents.js +5 -0
  22. package/lib/component/modal/EditPeakShapeModal.d.ts +4 -6
  23. package/lib/component/modal/EditPeakShapeModal.js +45 -33
  24. package/lib/component/modal/editRange/EditRangeModal.d.ts +2 -10
  25. package/lib/component/modal/editRange/EditRangeModal.js +26 -54
  26. package/lib/component/modal/editZone/EditZoneModal.d.ts +3 -8
  27. package/lib/component/modal/editZone/EditZoneModal.js +74 -91
  28. package/lib/component/modal/editZone/SignalsForm.d.ts +1 -2
  29. package/lib/component/modal/editZone/SignalsForm.js +33 -50
  30. package/lib/component/modal/editZone/validation/isDefaultPathLength.d.ts +1 -2
  31. package/lib/component/modal/editZone/validation/isDefaultPathLength.js +3 -5
  32. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +13 -3
  33. package/lib/component/panels/PeaksPanel/PeaksTable.js +7 -13
  34. package/lib/component/panels/RangesPanel/RangesHeader.js +0 -3
  35. package/lib/component/panels/RangesPanel/RangesTable.js +6 -3
  36. package/lib/component/panels/RangesPanel/TableColumns/ActionsColumn.js +21 -3
  37. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.d.ts +6 -5
  38. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +41 -64
  39. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnField.d.ts +1 -2
  40. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnField.js +33 -41
  41. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +66 -55
  42. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +68 -60
  43. package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.d.ts +13 -8
  44. package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.js +17 -81
  45. package/lib/component/panels/SummaryPanel/SummaryPanel.d.ts +3 -0
  46. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -1
  47. package/lib/component/panels/SummaryPanel/utilities/Utilities.js +1 -1
  48. package/lib/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +62 -43
  49. package/lib/component/panels/ZonesPanel/ZonesTable.js +4 -1
  50. package/lib/component/panels/ZonesPanel/hooks/useZoneActions.d.ts +5 -0
  51. package/lib/component/panels/ZonesPanel/hooks/useZoneActions.js +40 -0
  52. package/lib/component/reducer/actions/RangesActions.d.ts +1 -0
  53. package/lib/component/reducer/actions/RangesActions.js +9 -4
  54. package/lib/component/reducer/actions/ToolsActions.js +0 -17
  55. package/lib/component/reducer/preferences/actions/matrixGeneration.d.ts +0 -4
  56. package/lib/component/reducer/preferences/actions/matrixGeneration.js +1 -2
  57. package/lib/component/toolbar/ToolTypes.d.ts +1 -1
  58. package/lib/component/toolbar/ToolTypes.js +0 -14
  59. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +1 -7
  60. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.d.ts +1 -7
  61. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +1 -7
  62. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +1 -7
  63. package/lib/data/molecules/MoleculeManager.d.ts +1 -1
  64. package/lib/data/molecules/MoleculeManager.js +5 -11
  65. package/lib/versionInfo.js +1 -1
  66. package/package.json +2 -2
  67. package/lib/component/1d/tool/VerticalIndicator.d.ts +0 -2
  68. package/lib/component/elements/ContextMenu.d.ts +0 -9
  69. package/lib/component/elements/ContextMenu.js +0 -116
  70. package/lib/component/elements/popup/Modal/ConfirmDialog.d.ts +0 -21
  71. package/lib/component/elements/popup/Modal/ConfirmDialog.js +0 -68
  72. package/lib/component/elements/popup/Modal/Context.d.ts +0 -2
  73. package/lib/component/elements/popup/Modal/Context.js +0 -6
  74. package/lib/component/elements/popup/Modal/Modal.d.ts +0 -9
  75. package/lib/component/elements/popup/Modal/Modal.js +0 -42
  76. package/lib/component/elements/popup/Modal/ModalContent.d.ts +0 -6
  77. package/lib/component/elements/popup/Modal/ModalContent.js +0 -27
  78. package/lib/component/elements/popup/Modal/Provider.d.ts +0 -11
  79. package/lib/component/elements/popup/Modal/Provider.js +0 -172
  80. package/lib/component/elements/popup/Modal/index.d.ts +0 -4
  81. package/lib/component/elements/popup/Modal/index.js +0 -4
  82. package/lib/component/elements/popup/Transition.d.ts +0 -14
  83. package/lib/component/elements/popup/Transition.js +0 -35
  84. package/lib/component/elements/popup/Wrapper.d.ts +0 -8
  85. package/lib/component/elements/popup/Wrapper.js +0 -83
  86. package/lib/component/elements/popup/options.d.ts +0 -28
  87. package/lib/component/elements/popup/options.js +0 -25
  88. package/lib/component/elements/popup/utility.d.ts +0 -2
  89. package/lib/component/elements/popup/utility.js +0 -13
  90. package/lib/component/modal/editZone/EditPathLengthFormik.d.ts +0 -5
  91. package/lib/component/modal/editZone/EditPathLengthFormik.js +0 -67
  92. package/lib/component/modal/editZone/SignalFormTab.d.ts +0 -5
  93. package/lib/component/modal/editZone/SignalFormTab.js +0 -6
  94. package/lib/component/modal/editZone/validation/EditZoneValidation.d.ts +0 -14
  95. package/lib/component/modal/editZone/validation/EditZoneValidation.js +0 -14
@@ -1,9 +1,7 @@
1
- import { PeaksNucleusPreferences } from 'nmr-load-save';
2
1
  import { Peak1D } from 'nmr-processing';
3
2
  interface EditPeakShapeModalProps {
4
- onClose?: (element?: string) => void;
5
- peak: Peak1D;
6
- peaksPreferences: PeaksNucleusPreferences;
3
+ onCloseDialog: () => void;
4
+ peak?: Peak1D;
7
5
  }
8
- declare function EditPeakShapeModal({ onClose, peak, peaksPreferences, }: EditPeakShapeModalProps): import("@emotion/react/jsx-runtime").JSX.Element;
9
- export default EditPeakShapeModal;
6
+ export declare function EditPeakShapeModal(props: EditPeakShapeModalProps): import("@emotion/react/jsx-runtime").JSX.Element | undefined;
7
+ export {};
@@ -1,33 +1,27 @@
1
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
+ import { Dialog, DialogBody, DialogFooter } from '@blueprintjs/core';
3
4
  import { css } from '@emotion/react';
4
- import { Formik } from 'formik';
5
- import { useCallback, useRef, useState } from 'react';
5
+ import { yupResolver } from '@hookform/resolvers/yup';
6
+ import { useState } from 'react';
7
+ import { useForm } from 'react-hook-form';
6
8
  import * as Yup from 'yup';
9
+ import { useChartData } from '../context/ChartContext';
7
10
  import { useDispatch } from '../context/DispatchContext';
8
11
  import ActionButtons from '../elements/ActionButtons';
9
- import { CloseButton } from '../elements/CloseButton';
10
12
  import Label from '../elements/Label';
11
- import Select from '../elements/Select';
12
- import FormikInput from '../elements/formik/FormikInput';
13
+ import { NumberInput2Controller } from '../elements/NumberInput2Controller';
14
+ import { Select2 } from '../elements/Select2';
15
+ import { usePanelPreferences } from '../hooks/usePanelPreferences';
13
16
  import { formatNumber } from '../utility/formatNumber';
14
- import { ModalStyles } from './ModalStyle';
15
- const styles = css `
16
- width: 400px;
17
- min-height: 250px;
18
-
19
- .inner-content {
20
- flex: 1;
21
- }
22
- `;
23
- const getKindDefaultValues = (kind) => {
17
+ function getKindDefaultValues(kind) {
24
18
  return {
25
19
  kind,
26
20
  fwhm: 500,
27
21
  ...(kind === 'pseudoVoigt' && { mu: 0.5 }),
28
22
  };
29
- };
30
- const getValues = (peak, kind) => {
23
+ }
24
+ function getValues(peak, kind) {
31
25
  const { shape } = peak;
32
26
  const shapeData = (shape?.kind || '').toLocaleLowerCase() !== kind
33
27
  ? {
@@ -36,11 +30,13 @@ const getValues = (peak, kind) => {
36
30
  }
37
31
  : shape;
38
32
  return shapeData;
39
- };
40
- const validation = (kind) => Yup.object().shape({
41
- fwhm: Yup.number().required(),
42
- ...(kind === 'pseudoVoigt' && { mu: Yup.number().required() }),
43
- });
33
+ }
34
+ function validation(kind) {
35
+ return Yup.object().shape({
36
+ fwhm: Yup.number().required(),
37
+ ...(kind === 'pseudoVoigt' && { mu: Yup.number().required() }),
38
+ });
39
+ }
44
40
  const KINDS = [
45
41
  {
46
42
  value: 'gaussian',
@@ -60,12 +56,23 @@ const labelStyle = {
60
56
  label: { flex: 3, fontSize: '14px', fontWeight: 'normal' },
61
57
  wrapper: { flex: 7, display: 'flex' },
62
58
  };
63
- const inputStyle = { input: { width: '200px', textAlign: 'left' } };
64
- function EditPeakShapeModal({ onClose = () => null, peak, peaksPreferences, }) {
59
+ export function EditPeakShapeModal(props) {
60
+ const { peak, ...otherProps } = props;
61
+ if (!peak)
62
+ return;
63
+ return _jsx(InnerEditPeakShapeModal, { peak: peak, ...otherProps });
64
+ }
65
+ function InnerEditPeakShapeModal(props) {
66
+ const { peak, onCloseDialog } = props;
65
67
  const dispatch = useDispatch();
66
- const refForm = useRef();
67
- const [kind, setKind] = useState(peak.shape?.kind);
68
- const changePeakShapeHandler = useCallback((values) => {
68
+ const { view: { spectra: { activeTab }, }, } = useChartData();
69
+ const peaksPreferences = usePanelPreferences('peaks', activeTab);
70
+ const [kind, setKind] = useState(peak.shape?.kind || 'gaussian');
71
+ const { handleSubmit, control, reset } = useForm({
72
+ defaultValues: getValues(peak, kind),
73
+ resolver: yupResolver(validation(kind)),
74
+ });
75
+ function changePeakShapeHandler(values) {
69
76
  dispatch({
70
77
  type: 'CHANGE_PEAK_SHAPE',
71
78
  payload: {
@@ -75,10 +82,15 @@ function EditPeakShapeModal({ onClose = () => null, peak, peaksPreferences, }) {
75
82
  },
76
83
  },
77
84
  });
78
- onClose();
79
- }, [dispatch, onClose, peak.id]);
80
- const values = getValues(peak, kind);
85
+ onCloseDialog();
86
+ }
87
+ function handleChangeKind({ value }) {
88
+ reset(getValues(peak, value));
89
+ setKind(value);
90
+ }
81
91
  const valuePPM = formatNumber(peak.x, peaksPreferences.deltaPPM.format);
82
- return (_jsxs("div", { css: [ModalStyles, styles], children: [_jsxs("div", { className: "header handle", children: [_jsxs("span", { children: [`Peak Shape Edition ( ${valuePPM} PPM)`, " "] }), _jsx(CloseButton, { tooltip: "Close", onClick: () => onClose?.(), className: "close-bt" })] }), _jsx("div", { className: "inner-content", children: _jsx(Formik, { enableReinitialize: true, innerRef: refForm, initialValues: values, validationSchema: validation(kind), onSubmit: changePeakShapeHandler, children: _jsxs(_Fragment, { children: [_jsx(Label, { title: "Kind:", style: labelStyle, children: _jsx(Select, { items: KINDS, style: { margin: 0, height: 30 }, value: kind, onChange: (kind) => setKind(kind) }) }), _jsx(Label, { title: "FWHM:", style: labelStyle, children: _jsx(FormikInput, { name: "fwhm", style: inputStyle }) }), kind === 'pseudoVoigt' && (_jsx(Label, { title: "Mu:", style: labelStyle, children: _jsx(FormikInput, { name: "mu", style: inputStyle }) }))] }) }) }), _jsx("div", { className: "footer-container", children: _jsx(ActionButtons, { style: { flexDirection: 'row-reverse', margin: 0 }, onDone: () => refForm.current.submitForm(), doneLabel: "Save", onCancel: () => onClose?.() }) })] }));
92
+ return (_jsxs(Dialog, { isOpen: true, style: { width: 400 }, onClose: onCloseDialog, title: `Peak Shape Edition ( ${valuePPM} PPM )`, children: [_jsx(DialogBody, { css: css `
93
+ background-color: white;
94
+ padding: 1.5em 3em;
95
+ `, children: _jsxs(_Fragment, { children: [_jsx(Label, { title: "Kind:", style: labelStyle, children: _jsx(Select2, { items: KINDS, selectedItemValue: kind, onItemSelect: handleChangeKind }) }), _jsx(Label, { title: "FWHM:", style: labelStyle, children: _jsx(NumberInput2Controller, { min: 0, control: control, name: "fwhm" }) }), kind === 'pseudoVoigt' && (_jsx(Label, { title: "Mu:", style: labelStyle, children: _jsx(NumberInput2Controller, { min: 0, control: control, name: "mu" }) }))] }) }), _jsx(DialogFooter, { children: _jsx(ActionButtons, { style: { flexDirection: 'row-reverse', margin: 0 }, onDone: () => handleSubmit(changePeakShapeHandler)(), doneLabel: "Save", onCancel: () => onCloseDialog?.() }) })] }));
83
96
  }
84
- export default EditPeakShapeModal;
@@ -1,10 +1,2 @@
1
- import { Range } from 'nmr-processing';
2
- interface EditRangeModalProps {
3
- onSave: (value: any) => Promise<void> | null | void;
4
- onClose?: () => void;
5
- onRest: (originalRange: Range) => void;
6
- onZoom: (value: any) => void;
7
- rangeId: string;
8
- }
9
- declare function EditRangeModal({ onSave, onClose, onZoom, onRest, rangeId, }: EditRangeModalProps): import("@emotion/react/jsx-runtime").JSX.Element | undefined;
10
- export default EditRangeModal;
1
+ import { DialogProps } from '../../elements/DialogManager';
2
+ export declare function EditRangeModal(props: DialogProps<string>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,81 +1,53 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
+ import { Button, DialogBody, DialogFooter } from '@blueprintjs/core';
3
4
  import { css } from '@emotion/react';
4
5
  import { v4 } from '@lukeed/uuid';
5
6
  import { Formik } from 'formik';
6
7
  import { splitPatterns, translateMultiplet } from 'nmr-processing';
7
- import { useMemo, useCallback, useRef, useEffect } from 'react';
8
+ import { useMemo, useCallback, useRef } from 'react';
8
9
  import { FaSearchPlus } from 'react-icons/fa';
9
10
  import { useChartData } from '../../context/ChartContext';
10
11
  import { useDispatch } from '../../context/DispatchContext';
11
- import Button from '../../elements/Button';
12
- import { CloseButton } from '../../elements/CloseButton';
13
- import { SaveButton } from '../../elements/SaveButton';
12
+ import { DraggableDialog } from '../../elements/DraggableDialog';
14
13
  import FormikOnChange from '../../elements/formik/FormikOnChange';
15
14
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
16
15
  import useSpectrum from '../../hooks/useSpectrum';
16
+ import useEditRangeModal from '../../panels/RangesPanel/hooks/useEditRangeModal';
17
17
  import { hasCouplingConstant } from '../../panels/extra/utilities/MultiplicityUtilities';
18
18
  import { formatNumber } from '../../utility/formatNumber';
19
19
  import SignalsContent from './forms/components/SignalsContent';
20
20
  import editRangeFormValidation from './forms/validation/EditRangeValidation';
21
21
  const styles = css `
22
- min-height: 500px;
23
- padding: 5px;
24
-
25
- button:focus {
26
- outline: none;
27
- }
28
-
29
- .header {
30
- border-bottom: 1px solid #f0f0f0;
31
- display: flex;
32
- align-items: center;
33
-
34
- .title {
35
- color: #464646;
36
- font-size: 15px;
37
- flex: 1;
38
- border-left: 1px solid #ececec;
39
- padding-left: 6px;
40
- }
41
-
42
- button {
43
- background-color: transparent;
44
- border: none;
45
- padding: 5px;
46
-
47
- svg {
48
- height: 16px;
49
- }
50
- }
51
- }
22
+ background-color: white;
52
23
 
53
24
  .tabs .tab-list {
54
25
  overflow-x: auto;
55
26
  }
56
27
  `;
57
- function EditRangeModal({ onSave, onClose, onZoom, onRest, rangeId, }) {
28
+ export function EditRangeModal(props) {
29
+ const { reset, saveEditRange, zoomRange } = useEditRangeModal();
30
+ const { dialogData: rangeID, onCloseDialog } = props;
31
+ return (_jsx(InnerEditRangeModal, { onRest: (range) => {
32
+ onCloseDialog();
33
+ reset(range);
34
+ }, onSave: (range) => {
35
+ onCloseDialog();
36
+ saveEditRange(range);
37
+ }, onZoom: zoomRange, rangeID: rangeID }));
38
+ }
39
+ function InnerEditRangeModal(props) {
40
+ const { onSave, onZoom, onRest, rangeID } = props;
58
41
  const formRef = useRef(null);
59
42
  const { view: { spectra: { activeTab }, }, } = useChartData();
60
43
  const dispatch = useDispatch();
61
- const range = useRange(rangeId);
44
+ const range = useRange(rangeID);
62
45
  const originalRangeRef = useRef(range);
63
46
  const rangesPreferences = usePanelPreferences('ranges', activeTab);
64
- const handleOnZoom = useCallback(() => {
47
+ function handleOnZoom() {
65
48
  onZoom(range);
66
- }, [onZoom, range]);
67
- useEffect(() => {
68
- dispatch({
69
- type: 'SET_SELECTED_TOOL',
70
- payload: {
71
- selectedTool: 'zoom',
72
- },
73
- });
74
- if (!range) {
75
- onClose?.();
76
- }
77
- }, [activeTab, dispatch, onClose, range]);
78
- const handleOnClose = useCallback(() => {
49
+ }
50
+ function handleOnClose() {
79
51
  dispatch({
80
52
  type: 'SET_SELECTED_TOOL',
81
53
  payload: {
@@ -83,7 +55,7 @@ function EditRangeModal({ onSave, onClose, onZoom, onRest, rangeId, }) {
83
55
  },
84
56
  });
85
57
  onRest(originalRangeRef.current);
86
- }, [dispatch, onRest]);
58
+ }
87
59
  const getCouplings = useCallback((couplings) => couplings
88
60
  .filter((coupling) => coupling.coupling !== '')
89
61
  .map((coupling) => {
@@ -154,7 +126,8 @@ function EditRangeModal({ onSave, onClose, onZoom, onRest, rangeId, }) {
154
126
  if (!rangesPreferences || !range) {
155
127
  return;
156
128
  }
157
- return (_jsxs("div", { css: styles, children: [_jsxs("div", { className: "header handle", children: [_jsx(Button.Action, { onClick: handleOnZoom, fill: "outline", style: { fontSize: '14' }, color: { base: '#5f5f5f', hover: 'white' }, children: _jsx(FaSearchPlus, { title: "Set to default view on range in spectrum" }) }), _jsx("span", { className: "title", children: ` Range and Signal edition: ${formatNumber(range?.from, rangesPreferences.from.format)} ppm to ${formatNumber(range?.to, rangesPreferences.to.format)} ppm` }), _jsx(SaveButton, { onClick: () => formRef.current.submitForm(), tooltip: "Save and Exit" }), _jsx(CloseButton, { tooltip: "Close", onClick: handleOnClose })] }), _jsx(Formik, { innerRef: formRef, initialValues: data, validationSchema: editRangeFormValidation, onSubmit: handleOnSave, children: _jsxs(_Fragment, { children: [_jsx(SignalsContent, { range: range }), _jsx(FormikOnChange, { onChange: changeHandler })] }) })] }));
129
+ const title = ` Range and Signal edition: ${formatNumber(range?.from, rangesPreferences.from.format)} ppm to ${formatNumber(range?.to, rangesPreferences.to.format)} ppm`;
130
+ return (_jsxs(DraggableDialog, { hasBackdrop: false, canOutsideClickClose: false, style: { width: 700 }, title: title, isOpen: true, headerLeftElement: _jsx(Button, { intent: "success", style: { marginRight: '5px', borderRadius: '5px' }, icon: _jsx(FaSearchPlus, { title: "Set to default view on range in spectrum" }), minimal: true, onClick: handleOnZoom }), onClose: handleOnClose, placement: "top-right", children: [_jsx(DialogBody, { css: styles, children: _jsx(Formik, { innerRef: formRef, initialValues: data, validationSchema: editRangeFormValidation, onSubmit: handleOnSave, children: _jsxs(_Fragment, { children: [_jsx(SignalsContent, { range: range }), _jsx(FormikOnChange, { onChange: changeHandler })] }) }) }), _jsx(DialogFooter, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button, { intent: "success", onClick: () => formRef.current.submitForm(), children: "Save and Exit" }) }) })] }));
158
131
  }
159
132
  function useRange(rangeId) {
160
133
  const { ranges } = useSpectrum({
@@ -163,4 +136,3 @@ function useRange(rangeId) {
163
136
  const index = ranges.values.findIndex((rangeRecord) => rangeRecord.id === rangeId);
164
137
  return ranges.values[index];
165
138
  }
166
- export default EditRangeModal;
@@ -1,8 +1,3 @@
1
- interface EditZoneModalProps {
2
- onSaveEditZoneModal: (value: any) => Promise<void> | null | void;
3
- onCloseEditZoneModal: () => void;
4
- onZoomEditZoneModal: (value: any) => void;
5
- rowData: any;
6
- }
7
- declare function EditZoneModal({ onSaveEditZoneModal, onCloseEditZoneModal, onZoomEditZoneModal, rowData, }: EditZoneModalProps): import("@emotion/react/jsx-runtime").JSX.Element;
8
- export default EditZoneModal;
1
+ import { DialogProps } from '../../elements/DialogManager';
2
+ import { ZoneData } from '../../panels/ZonesPanel/hooks/useMapZones';
3
+ export declare function EditZoneModal(props: DialogProps<ZoneData>): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,101 +1,84 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
+ import { Button, DialogBody, DialogFooter } from '@blueprintjs/core';
3
4
  import { css } from '@emotion/react';
4
- import { Formik } from 'formik';
5
- import { useCallback, useEffect, useMemo, useRef } from 'react';
5
+ import { yupResolver } from '@hookform/resolvers/yup';
6
+ import { FormProvider, useForm } from 'react-hook-form';
6
7
  import { FaSearchPlus } from 'react-icons/fa';
8
+ import * as Yup from 'yup';
7
9
  import DefaultPathLengths from '../../../data/constants/DefaultPathLengths';
8
- import Button from '../../elements/Button';
9
- import { CloseButton } from '../../elements/CloseButton';
10
- import { SaveButton } from '../../elements/SaveButton';
11
- import SignalsForm from './SignalsForm';
12
- import zoneFormValidation from './validation/EditZoneValidation';
13
- import isDefaultPathLength from './validation/isDefaultPathLength';
14
- const styles = css `
15
- width: 500px;
16
- height: 250px;
17
- padding: 5px;
18
-
19
- button:focus {
20
- outline: none;
21
- }
22
-
23
- .header {
24
- height: 24px;
25
- border-bottom: 1px solid #f0f0f0;
26
- display: flex;
27
- align-items: center;
28
-
29
- span {
30
- color: #464646;
31
- font-size: 15px;
32
- flex: 1;
33
- border-left: 1px solid #ececec;
34
- padding-left: 6px;
35
- }
36
-
37
- button {
38
- background-color: transparent;
39
- border: none;
40
- padding: 5px;
41
-
42
- svg {
43
- height: 16px;
44
- }
45
- }
46
- }
47
-
48
- .container {
49
- display: flex;
50
- margin: 30px 5px;
51
- }
52
- `;
53
- function EditZoneModal({ onSaveEditZoneModal = () => null, onCloseEditZoneModal = () => null, onZoomEditZoneModal = () => null, rowData, }) {
54
- const formRef = useRef(null);
55
- const handleOnZoom = useCallback(() => {
56
- onZoomEditZoneModal(rowData);
57
- }, [onZoomEditZoneModal, rowData]);
58
- useEffect(() => {
59
- handleOnZoom();
60
- }, [handleOnZoom]);
61
- const handleOnClose = useCallback(() => {
62
- onCloseEditZoneModal();
63
- }, [onCloseEditZoneModal]);
64
- const handleOnSave = useCallback((formValues) => {
10
+ import { DraggableDialog } from '../../elements/DraggableDialog';
11
+ import { useZoneActions } from '../../panels/ZonesPanel/hooks/useZoneActions';
12
+ import { SignalsForm } from './SignalsForm';
13
+ import { isDefaultPathLength } from './validation/isDefaultPathLength';
14
+ const signalSchema = Yup.object().shape({
15
+ j: Yup.object().shape({
16
+ pathLength: Yup.object().shape({
17
+ from: Yup.number().required().positive().integer(),
18
+ to: Yup.number().required().positive().integer(),
19
+ }),
20
+ }),
21
+ });
22
+ const zoneFormValidation = Yup.object().shape({
23
+ activeTab: Yup.string(),
24
+ signals: Yup.array()
25
+ .of(signalSchema)
26
+ .min(1, 'There must be at least one signal in a zone!'),
27
+ });
28
+ export function EditZoneModal(props) {
29
+ const { dialogData: zone, onCloseDialog } = props;
30
+ const { saveZone, zoomToZone } = useZoneActions();
31
+ function handleSave(values) {
65
32
  void (async () => {
66
- const _rowData = {
67
- ...rowData,
68
- signals: formValues.signals.map((signal) => {
69
- if (isDefaultPathLength(signal.j?.pathLength, rowData.tableMetaInfo.experiment)) {
70
- delete signal.j?.pathLength;
71
- if (signal.j && Object.keys(signal.j).length === 0) {
72
- delete signal.j;
73
- }
74
- }
75
- return signal;
76
- }),
33
+ const zoneData = {
34
+ ...zone,
35
+ signals: mapSignalsBeforeSave(values?.signals, zone.tableMetaInfo.experiment),
77
36
  };
78
- await onSaveEditZoneModal(_rowData);
79
- handleOnClose();
37
+ saveZone(zoneData);
38
+ onCloseDialog();
80
39
  })();
81
- }, [handleOnClose, onSaveEditZoneModal, rowData]);
82
- const data = useMemo(() => {
83
- return {
40
+ }
41
+ const methods = useForm({
42
+ defaultValues: {
84
43
  activeTab: '0',
85
- signals: rowData.signals.map((signal) => {
86
- return {
87
- ...signal,
88
- j: {
89
- pathLength: {
90
- from: DefaultPathLengths[rowData.tableMetaInfo.experiment]?.from || 1,
91
- to: DefaultPathLengths[rowData.tableMetaInfo.experiment]?.to || 1,
92
- },
93
- ...signal.j,
94
- },
95
- };
96
- }),
44
+ signals: mapSignals(zone),
45
+ },
46
+ resolver: yupResolver(zoneFormValidation),
47
+ });
48
+ const { handleSubmit } = methods;
49
+ return (_jsxs(DraggableDialog, { hasBackdrop: false, canOutsideClickClose: false, style: { width: 700 }, title: "Zone and Signal edition", isOpen: true, headerLeftElement: _jsx(Button, { intent: "success", style: { marginRight: '5px', borderRadius: '5px' }, icon: _jsx(FaSearchPlus, { title: "Set to default view on range in spectrum" }), minimal: true, onClick: () => zoomToZone(zone) }), onClose: onCloseDialog, placement: "top-right", children: [_jsx(DialogBody, { css: css `
50
+ background-color: white;
51
+ `, children: _jsx(FormProvider, { ...methods, children: _jsx(SignalsForm, {}) }) }), _jsx(DialogFooter, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button, { intent: "success", onClick: () => handleSubmit(handleSave)(), children: "Save and Exit" }) }) })] }));
52
+ }
53
+ function mapSignalsBeforeSave(signals, experiment) {
54
+ const outputSignals = [];
55
+ for (const signal of signals) {
56
+ if (isDefaultPathLength(signal.j?.pathLength, experiment)) {
57
+ delete signal.j?.pathLength;
58
+ if (signal.j && Object.keys(signal.j).length === 0) {
59
+ delete signal.j;
60
+ }
61
+ }
62
+ outputSignals.push(signal);
63
+ }
64
+ return outputSignals;
65
+ }
66
+ function mapSignals(zone) {
67
+ const outputSignals = [];
68
+ const { signals, tableMetaInfo: { experiment }, } = zone;
69
+ const { from = 1, to = 1 } = DefaultPathLengths?.[experiment] || {};
70
+ for (const signal of signals) {
71
+ const mappedSignal = {
72
+ ...signal,
73
+ j: {
74
+ pathLength: {
75
+ from,
76
+ to,
77
+ },
78
+ ...signal.j,
79
+ },
97
80
  };
98
- }, [rowData.signals, rowData.tableMetaInfo.experiment]);
99
- return (_jsx("div", { css: styles, children: _jsx(Formik, { innerRef: formRef, initialValues: data, validationSchema: zoneFormValidation, onSubmit: handleOnSave, children: _jsxs(_Fragment, { children: [_jsxs("div", { className: "header handle", children: [_jsx(Button, { onClick: handleOnZoom, className: "zoom-button", children: _jsx(FaSearchPlus, { title: "Set to default view on range in spectrum" }) }), _jsx("span", { children: `Zone and Signal edition` }), _jsx(SaveButton, { onClick: () => formRef.current.submitForm(), tooltip: "Save and exit" }), _jsx(CloseButton, { tooltip: "Close", onClick: handleOnClose })] }), _jsx(SignalsForm, {})] }) }) }));
81
+ outputSignals.push(mappedSignal);
82
+ }
83
+ return outputSignals;
100
84
  }
101
- export default EditZoneModal;
@@ -1,2 +1 @@
1
- declare function SignalsForm(): import("@emotion/react/jsx-runtime").JSX.Element;
2
- export default SignalsForm;
1
+ export declare function SignalsForm(): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,52 +1,35 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
- import { css } from '@emotion/react';
4
- import { useFormikContext } from 'formik';
5
- import { useCallback, useMemo } from 'react';
6
- import Tab from '../../elements/Tab/Tab';
7
- import Tabs from '../../elements/Tab/Tabs';
8
- import SignalFormTab from './SignalFormTab';
9
- const textStyles = css `
10
- text-align: center;
11
- width: 100%;
12
-
13
- .error-text {
14
- color: red;
15
- }
16
- `;
17
- const tabStylesAddition = css `
18
- color: red;
19
- `;
20
- const tabStyles = css `
21
- display: inline-grid;
22
- list-style: none;
23
- padding: 0.5rem 1.5rem;
24
- `;
25
- function SignalsForm() {
26
- const { values, setFieldValue, errors, } = useFormikContext();
27
- const tabContainsErrors = useCallback((i) => {
28
- return !!errors?.signals?.[i];
29
- }, [errors]);
30
- const signalFormTabs = useMemo(() => {
31
- const signalTabs = values.signals.length > 0
32
- ? values.signals.map((signal, i) => (_jsx(Tab
33
- // eslint-disable-next-line react/no-array-index-key
34
- , { tabid: `${i}`, tabstyles: tabContainsErrors(i) ? tabStylesAddition : tabStyles, render: () => (_jsxs("div", { style: {
35
- display: 'flex',
36
- flexDirection: 'column',
37
- alignItems: 'center',
38
- fontSize: '11px',
39
- }, children: [_jsxs("span", { children: ["\uD835\uDEC5", _jsx("sub", { children: signal.x.nucleus }), ": ", signal.x.delta.toFixed(2)] }), _jsxs("span", { children: ["\uD835\uDEC5", _jsx("sub", { children: signal.y.nucleus }), ": ", signal.y.delta.toFixed(2)] })] })), children: _jsx(SignalFormTab, { signalIndex: i }) }, `signalForm_zone${i}`)))
40
- : [];
41
- return signalTabs;
42
- }, [tabContainsErrors, values.signals]);
43
- const tapClickHandler = useCallback(({ tabid }) => {
44
- setFieldValue('activeTab', tabid);
45
- }, [setFieldValue]);
46
- const handleDeleteSignal = useCallback(({ tabid }) => {
47
- const _signals = values.signals.filter((_signal, i) => i !== Number(tabid));
48
- setFieldValue('signals', _signals);
49
- }, [setFieldValue, values.signals]);
50
- return (_jsxs("div", { children: [_jsx("div", { css: textStyles }), _jsx(Tabs, { activeTab: values.activeTab, onClick: tapClickHandler, onDelete: handleDeleteSignal, children: signalFormTabs })] }));
3
+ import { Tab, Tabs } from '@blueprintjs/core';
4
+ import { useFormContext, useWatch } from 'react-hook-form';
5
+ import DefaultPathLengths from '../../../data/constants/DefaultPathLengths';
6
+ import IsotopesViewer from '../../elements/IsotopesViewer';
7
+ import Label from '../../elements/Label';
8
+ import { NumberInput2Controller } from '../../elements/NumberInput2Controller';
9
+ import { TabTitle } from '../../elements/TabTitle';
10
+ export function SignalsForm() {
11
+ const { setValue, formState: { errors }, } = useFormContext();
12
+ const { signals = [], activeTab, experimentType } = useWatch();
13
+ function handleTapChange(tabID) {
14
+ setValue('activeTab', tabID);
15
+ }
16
+ function handleDeleteSignal(index) {
17
+ const filteredSignals = signals.filter((_signal, i) => i !== index);
18
+ setValue('signals', filteredSignals);
19
+ }
20
+ return (_jsx("div", { children: _jsx(Tabs, { selectedTabId: activeTab, onChange: handleTapChange, children: signals.map((signal, index) => {
21
+ return (_jsx(Tab
22
+ // eslint-disable-next-line react/no-array-index-key
23
+ , { id: `${index}`, style: { ...(errors?.signals?.[index] && { color: 'red' }) }, panel: _jsx(SignalTab, { index: index, experimentType: experimentType }), children: _jsx(TabTitle, { onDelete: () => handleDeleteSignal(index), children: _jsx(Title, { signal: signal }) }) }, `zone-signal-${index}`));
24
+ }) }) }));
25
+ }
26
+ function SignalTab(props) {
27
+ const { index, experimentType } = props;
28
+ const { control } = useFormContext();
29
+ const { from = 1, to = 1 } = DefaultPathLengths?.[experimentType] || {};
30
+ return (_jsxs("div", { children: [_jsx("p", { children: "Setting of the minimum and maximum path length (J coupling)." }), _jsxs("div", { style: { display: 'flex', flexDirection: 'row' }, children: [_jsx(Label, { title: "Min:", children: _jsx(NumberInput2Controller, { name: `signals[${index}].j.pathLength.from`, control: control, defaultValue: from, min: 1, max: to, step: 1, majorStepSize: 1, minorStepSize: 1 }) }), _jsx(Label, { title: "Max:", style: { container: { paddingLeft: '5px' } }, children: _jsx(NumberInput2Controller, { name: `signals[${index}].j.pathLength.to`, control: control, defaultValue: to, min: from, step: 1, majorStepSize: 1, minorStepSize: 1 }) })] })] }));
31
+ }
32
+ function Title({ signal }) {
33
+ const { x, y } = signal;
34
+ return (_jsxs(_Fragment, { children: ["\uD835\uDEC5", _jsx(IsotopesViewer, { value: x.nucleus, style: { display: 'inline-block' } }), ":", x.delta.toFixed(2), " , \uD835\uDEC5", _jsx(IsotopesViewer, { value: y.nucleus, style: { display: 'inline-block' } }), ":", y.delta.toFixed(2)] }));
51
35
  }
52
- export default SignalsForm;
@@ -1,3 +1,2 @@
1
1
  import { FromTo } from 'cheminfo-types';
2
- declare function isDefaultPathLength(pathLength: FromTo, experimentType: string): boolean;
3
- export default isDefaultPathLength;
2
+ export declare function isDefaultPathLength(pathLength: FromTo, experimentType: string): boolean;
@@ -1,7 +1,5 @@
1
1
  import DefaultPathLengths from '../../../../data/constants/DefaultPathLengths';
2
- function isDefaultPathLength(pathLength, experimentType) {
3
- return (DefaultPathLengths[experimentType] &&
4
- pathLength.from === DefaultPathLengths[experimentType].from &&
5
- pathLength.to === DefaultPathLengths[experimentType].to);
2
+ export function isDefaultPathLength(pathLength, experimentType) {
3
+ const { from, to } = DefaultPathLengths?.[experimentType] || {};
4
+ return pathLength.from === from && pathLength.to === to;
6
5
  }
7
- export default isDefaultPathLength;
@@ -128,9 +128,19 @@ export default function MoleculePanelHeader({ currentIndex, molecules, molecules
128
128
  async function handlePasteMolfile(molfile) {
129
129
  if (!molfile)
130
130
  return;
131
- const molecules = await getMolecules(molfile);
132
- dispatch({ type: 'ADD_MOLECULES', payload: { molecules } });
133
- cleanShouldFallback();
131
+ try {
132
+ const molecules = getMolecules(molfile);
133
+ dispatch({ type: 'ADD_MOLECULES', payload: { molecules } });
134
+ }
135
+ catch {
136
+ toaster.show({
137
+ intent: 'danger',
138
+ message: 'Failed to parse SMILES or molfile. Please paste a valid format',
139
+ });
140
+ }
141
+ finally {
142
+ cleanShouldFallback();
143
+ }
134
144
  }
135
145
  const handleDelete = useCallback(() => {
136
146
  if (molecules[currentIndex]?.id) {