nmrium 1.10.0 → 1.11.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 (155) hide show
  1. package/lib/component/1d/BrushTracker1D.d.ts.map +1 -1
  2. package/lib/component/1d/BrushTracker1D.js +7 -0
  3. package/lib/component/1d/BrushTracker1D.js.map +1 -1
  4. package/lib/component/1d/FloatPublicationString.d.ts.map +1 -1
  5. package/lib/component/1d/FloatPublicationString.js +1 -1
  6. package/lib/component/1d/FloatPublicationString.js.map +1 -1
  7. package/lib/component/1d/FloatingRanges.d.ts.map +1 -1
  8. package/lib/component/1d/FloatingRanges.js +1 -1
  9. package/lib/component/1d/FloatingRanges.js.map +1 -1
  10. package/lib/component/1d/inset/DraggableInset.d.ts.map +1 -1
  11. package/lib/component/1d/inset/DraggableInset.js +1 -1
  12. package/lib/component/1d/inset/DraggableInset.js.map +1 -1
  13. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.d.ts.map +1 -1
  14. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.js +11 -2
  15. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.js.map +1 -1
  16. package/lib/component/2d/useTracesSpectra.d.ts.map +1 -1
  17. package/lib/component/2d/useTracesSpectra.js +3 -2
  18. package/lib/component/2d/useTracesSpectra.js.map +1 -1
  19. package/lib/component/EventsTrackers/KeysListenerTracker.js +3 -3
  20. package/lib/component/EventsTrackers/KeysListenerTracker.js.map +1 -1
  21. package/lib/component/elements/NextPrev.d.ts.map +1 -1
  22. package/lib/component/elements/NextPrev.js +23 -4
  23. package/lib/component/elements/NextPrev.js.map +1 -1
  24. package/lib/component/elements/export/utilities/exportOptionValidationSchema.d.ts +1 -1
  25. package/lib/component/hooks/useExport.d.ts +7 -7
  26. package/lib/component/hooks/useExport.d.ts.map +1 -1
  27. package/lib/component/hooks/useExport.js +22 -42
  28. package/lib/component/hooks/useExport.js.map +1 -1
  29. package/lib/component/hooks/useSetActiveSpectrumAction.d.ts.map +1 -1
  30. package/lib/component/hooks/useSetActiveSpectrumAction.js +3 -1
  31. package/lib/component/hooks/useSetActiveSpectrumAction.js.map +1 -1
  32. package/lib/component/loader/useLoadFiles.d.ts.map +1 -1
  33. package/lib/component/loader/useLoadFiles.js +81 -86
  34. package/lib/component/loader/useLoadFiles.js.map +1 -1
  35. package/lib/component/main/ErrorOverlay.d.ts.map +1 -1
  36. package/lib/component/main/ErrorOverlay.js +6 -1
  37. package/lib/component/main/ErrorOverlay.js.map +1 -1
  38. package/lib/component/main/InnerNMRiumContents.d.ts.map +1 -1
  39. package/lib/component/main/InnerNMRiumContents.js +1 -2
  40. package/lib/component/main/InnerNMRiumContents.js.map +1 -1
  41. package/lib/component/main/NMRiumViewer.js +1 -1
  42. package/lib/component/main/NMRiumViewer.js.map +1 -1
  43. package/lib/component/main/NMRiumViewerWrapper.d.ts.map +1 -1
  44. package/lib/component/main/NMRiumViewerWrapper.js +11 -3
  45. package/lib/component/main/NMRiumViewerWrapper.js.map +1 -1
  46. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.d.ts +6 -0
  47. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.d.ts.map +1 -0
  48. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.js +127 -0
  49. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.js.map +1 -0
  50. package/lib/component/modal/SaveAsModal.d.ts.map +1 -1
  51. package/lib/component/modal/SaveAsModal.js +4 -8
  52. package/lib/component/modal/SaveAsModal.js.map +1 -1
  53. package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
  54. package/lib/component/modal/changeSum/ChangeSumModal.js.map +1 -1
  55. package/lib/component/modal/changeSum/SelectMolecule.js +4 -1
  56. package/lib/component/modal/changeSum/SelectMolecule.js.map +1 -1
  57. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts.map +1 -1
  58. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +71 -16
  59. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js.map +1 -1
  60. package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.d.ts.map +1 -1
  61. package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.js +3 -12
  62. package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.js.map +1 -1
  63. package/lib/component/panels/Panels.d.ts +0 -9
  64. package/lib/component/panels/Panels.d.ts.map +1 -1
  65. package/lib/component/panels/Panels.js +1 -29
  66. package/lib/component/panels/Panels.js.map +1 -1
  67. package/lib/component/panels/hooks/useTogglePanel.d.ts.map +1 -1
  68. package/lib/component/panels/hooks/useTogglePanel.js +4 -3
  69. package/lib/component/panels/hooks/useTogglePanel.js.map +1 -1
  70. package/lib/component/reducer/actions/LoadAction.d.ts.map +1 -1
  71. package/lib/component/reducer/actions/LoadAction.js +6 -0
  72. package/lib/component/reducer/actions/LoadAction.js.map +1 -1
  73. package/lib/component/reducer/actions/MoleculeActions.d.ts +23 -1
  74. package/lib/component/reducer/actions/MoleculeActions.d.ts.map +1 -1
  75. package/lib/component/reducer/actions/MoleculeActions.js +2 -2
  76. package/lib/component/reducer/actions/MoleculeActions.js.map +1 -1
  77. package/lib/component/reducer/actions/RangesActions.js +1 -1
  78. package/lib/component/reducer/actions/RangesActions.js.map +1 -1
  79. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  80. package/lib/component/reducer/actions/SpectraActions.d.ts.map +1 -1
  81. package/lib/component/reducer/actions/SpectraActions.js +2 -2
  82. package/lib/component/reducer/actions/SpectraActions.js.map +1 -1
  83. package/lib/component/reducer/preferences/actions/analyzeSpectra.d.ts +2 -1
  84. package/lib/component/reducer/preferences/actions/analyzeSpectra.d.ts.map +1 -1
  85. package/lib/component/reducer/preferences/actions/analyzeSpectra.js +10 -0
  86. package/lib/component/reducer/preferences/actions/analyzeSpectra.js.map +1 -1
  87. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.d.ts +4 -0
  88. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.d.ts.map +1 -0
  89. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.js +9 -0
  90. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.js.map +1 -0
  91. package/lib/component/reducer/preferences/preferencesReducer.d.ts +8 -1
  92. package/lib/component/reducer/preferences/preferencesReducer.d.ts.map +1 -1
  93. package/lib/component/reducer/preferences/preferencesReducer.js +6 -1
  94. package/lib/component/reducer/preferences/preferencesReducer.js.map +1 -1
  95. package/lib/component/toolbar/ToolBar.d.ts.map +1 -1
  96. package/lib/component/toolbar/ToolBar.js +6 -7
  97. package/lib/component/toolbar/ToolBar.js.map +1 -1
  98. package/lib/component/toolbar/toolbarMenu.d.ts +5 -1
  99. package/lib/component/toolbar/toolbarMenu.d.ts.map +1 -1
  100. package/lib/component/toolbar/toolbarMenu.js +1 -1
  101. package/lib/component/toolbar/toolbarMenu.js.map +1 -1
  102. package/lib/component/utility/export.d.ts +2 -1
  103. package/lib/component/utility/export.d.ts.map +1 -1
  104. package/lib/component/utility/export.js +5 -1
  105. package/lib/component/utility/export.js.map +1 -1
  106. package/lib/data/data1d/multipleSpectraAnalysis.d.ts +1 -0
  107. package/lib/data/data1d/multipleSpectraAnalysis.d.ts.map +1 -1
  108. package/lib/data/data1d/multipleSpectraAnalysis.js +14 -0
  109. package/lib/data/data1d/multipleSpectraAnalysis.js.map +1 -1
  110. package/lib/data/data2d/Spectrum2D/contours.d.ts.map +1 -1
  111. package/lib/data/data2d/Spectrum2D/contours.js +13 -6
  112. package/lib/data/data2d/Spectrum2D/contours.js.map +1 -1
  113. package/lib/data/molecules/MoleculeManager.d.ts +6 -1
  114. package/lib/data/molecules/MoleculeManager.d.ts.map +1 -1
  115. package/lib/data/molecules/MoleculeManager.js +3 -2
  116. package/lib/data/molecules/MoleculeManager.js.map +1 -1
  117. package/lib/versionInfo.js +1 -1
  118. package/package.json +39 -39
  119. package/src/component/1d/BrushTracker1D.tsx +8 -0
  120. package/src/component/1d/FloatPublicationString.tsx +0 -1
  121. package/src/component/1d/FloatingRanges.tsx +0 -1
  122. package/src/component/1d/inset/DraggableInset.tsx +0 -1
  123. package/src/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.tsx +11 -2
  124. package/src/component/2d/useTracesSpectra.ts +4 -3
  125. package/src/component/EventsTrackers/KeysListenerTracker.tsx +3 -3
  126. package/src/component/elements/NextPrev.tsx +28 -4
  127. package/src/component/hooks/useExport.tsx +34 -64
  128. package/src/component/hooks/useSetActiveSpectrumAction.ts +3 -2
  129. package/src/component/loader/useLoadFiles.ts +134 -111
  130. package/src/component/main/ErrorOverlay.tsx +11 -2
  131. package/src/component/main/InnerNMRiumContents.tsx +6 -9
  132. package/src/component/main/NMRiumViewer.tsx +2 -2
  133. package/src/component/main/NMRiumViewerWrapper.tsx +14 -6
  134. package/src/component/modal/MoleculeAutoLabelsDatabaseModal.tsx +219 -0
  135. package/src/component/modal/SaveAsModal.tsx +14 -41
  136. package/src/component/modal/changeSum/ChangeSumModal.tsx +1 -1
  137. package/src/component/modal/changeSum/SelectMolecule.tsx +23 -23
  138. package/src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx +94 -15
  139. package/src/component/panels/MoleculesPanel/hooks/useAtomAssignment.tsx +3 -17
  140. package/src/component/panels/Panels.tsx +1 -53
  141. package/src/component/panels/hooks/useTogglePanel.ts +4 -3
  142. package/src/component/reducer/actions/LoadAction.ts +15 -1
  143. package/src/component/reducer/actions/MoleculeActions.ts +4 -2
  144. package/src/component/reducer/actions/RangesActions.ts +1 -1
  145. package/src/component/reducer/actions/SpectraActions.ts +6 -2
  146. package/src/component/reducer/preferences/actions/analyzeSpectra.ts +16 -0
  147. package/src/component/reducer/preferences/actions/toggleOpenSplitPanel.ts +18 -0
  148. package/src/component/reducer/preferences/preferencesReducer.ts +22 -1
  149. package/src/component/toolbar/ToolBar.tsx +9 -9
  150. package/src/component/toolbar/toolbarMenu.tsx +13 -2
  151. package/src/component/utility/export.ts +6 -0
  152. package/src/data/data1d/multipleSpectraAnalysis.ts +20 -0
  153. package/src/data/data2d/Spectrum2D/contours.ts +16 -6
  154. package/src/data/molecules/MoleculeManager.ts +7 -2
  155. package/src/versionInfo.ts +1 -1
@@ -8,7 +8,6 @@ import {
8
8
  import { useMemo } from 'react';
9
9
  import { Controller, useForm } from 'react-hook-form';
10
10
 
11
- import type { ExportOptions } from '../../data/SpectraManager.js';
12
11
  import { DataExportOptions } from '../../data/SpectraManager.js';
13
12
  import { useChartData } from '../context/ChartContext.js';
14
13
  import ActionButtons from '../elements/ActionButtons.js';
@@ -16,18 +15,16 @@ import { Input2Controller } from '../elements/Input2Controller.js';
16
15
  import type { LabelStyle } from '../elements/Label.js';
17
16
  import Label from '../elements/Label.js';
18
17
  import { StyledDialogBody } from '../elements/StyledDialogBody.js';
19
- import useCheckExperimentalFeature from '../hooks/useCheckExperimentalFeature.js';
18
+ import type { SaveOptions } from '../hooks/useExport.js';
20
19
  import { useExport } from '../hooks/useExport.js';
21
20
 
22
- const INITIAL_VALUE = {
21
+ const INITIAL_VALUE: SaveOptions = {
23
22
  name: '',
24
- compressed: false,
25
- pretty: false,
26
23
  include: {
27
- dataType: DataExportOptions.RAW_DATA,
24
+ dataType: DataExportOptions.SELF_CONTAINED,
28
25
  view: false,
29
26
  settings: false,
30
- } satisfies ExportOptions,
27
+ },
31
28
  };
32
29
 
33
30
  export const labelStyle: LabelStyle = {
@@ -57,15 +54,14 @@ function SaveAsModal(props: SaveAsModalProps) {
57
54
 
58
55
  return <InnerSaveAsModal onCloseDialog={onCloseDialog} />;
59
56
  }
57
+
60
58
  function InnerSaveAsModal(props: InnerSaveAsModalProps) {
61
59
  const { onCloseDialog } = props;
62
- const { sources, data, aggregator } = useChartData();
60
+ const { data, aggregator } = useChartData();
63
61
  const { saveHandler } = useExport();
64
- const experimentalFlagEnabled = useCheckExperimentalFeature();
65
-
66
62
  const fileName = data[0]?.info?.name;
67
63
 
68
- function submitHandler(values: any) {
64
+ function submitHandler(values: SaveOptions) {
69
65
  saveHandler(values);
70
66
  onCloseDialog?.();
71
67
  }
@@ -94,12 +90,6 @@ function InnerSaveAsModal(props: InnerSaveAsModalProps) {
94
90
  controllerProps={{ rules: { required: true } }}
95
91
  />
96
92
  </Label>
97
- <Label style={labelStyle} title="Compressed">
98
- <Checkbox style={{ margin: 0 }} {...register(`compressed`)} />
99
- </Label>
100
- <Label style={labelStyle} title="Pretty format">
101
- <Checkbox style={{ margin: 0 }} {...register(`pretty`)} />
102
- </Label>
103
93
  <Label style={labelStyle} title="Include view">
104
94
  <Checkbox style={{ margin: 0 }} {...register(`include.view`)} />
105
95
  </Label>
@@ -114,33 +104,16 @@ function InnerSaveAsModal(props: InnerSaveAsModalProps) {
114
104
  const { value, ref, ...otherFieldProps } = field;
115
105
  return (
116
106
  <RadioGroup inline selectedValue={value} {...otherFieldProps}>
117
- <Radio label="Raw data" value={DataExportOptions.RAW_DATA} />
118
107
  <Radio
119
- label="Data source"
120
- value={DataExportOptions.DATA_SOURCE}
121
- disabled={Object.keys(sources).length === 0}
108
+ label="External data embed"
109
+ value={DataExportOptions.SELF_CONTAINED}
110
+ />
111
+ <Radio
112
+ label="External data linked"
113
+ disabled={!containsLinkedFiles}
114
+ value={DataExportOptions.SELF_CONTAINED_EXTERNAL_DATASOURCE}
122
115
  />
123
116
  <Radio label="No data" value={DataExportOptions.NO_DATA} />
124
-
125
- {/*
126
- * Radio group works with Children.map.
127
- * So Radio must be direct children of RadioGroup.
128
- */}
129
- {experimentalFlagEnabled && (
130
- <Radio
131
- label="Full data (external data embed, experimental)"
132
- value={DataExportOptions.SELF_CONTAINED}
133
- />
134
- )}
135
- {experimentalFlagEnabled && (
136
- <Radio
137
- label="Full data (external data linked, experimental)"
138
- disabled={!containsLinkedFiles}
139
- value={
140
- DataExportOptions.SELF_CONTAINED_EXTERNAL_DATASOURCE
141
- }
142
- />
143
- )}
144
117
  </RadioGroup>
145
118
  );
146
119
  }}
@@ -35,7 +35,7 @@ export default function ChangeSumModal(props: ChangeSumModalProps) {
35
35
  <Dialog
36
36
  isOpen
37
37
  onClose={closeDialog}
38
- style={{ width: 500 }}
38
+ style={{ width: 500, minHeight: 450 }}
39
39
  title={
40
40
  currentSum
41
41
  ? `Set new ${sumType} sum (Current: ${currentSum.toFixed(2)})`
@@ -87,29 +87,29 @@ export default function SelectMolecule<
87
87
  [setValue],
88
88
  );
89
89
 
90
- return (
91
- <div>
92
- {element && molecules && molecules.length > 0 ? (
93
- <Container>
94
- <Title>Select a molecule as reference!</Title>
90
+ if (element && molecules && molecules.length > 0) {
91
+ return (
92
+ <Container>
93
+ <Title>Select a molecule as reference!</Title>
94
+
95
+ <SelectionContainer>
96
+ <MoleculeSelection
97
+ index={currentIndex}
98
+ molecules={molecules}
99
+ onChange={onChangeMoleculeSelectionHandler}
100
+ />
101
+ <SumValue>
102
+ New sum for {element} will be {newSum}!
103
+ </SumValue>
104
+ </SelectionContainer>
105
+ </Container>
106
+ );
107
+ }
95
108
 
96
- <SelectionContainer>
97
- <MoleculeSelection
98
- index={currentIndex}
99
- molecules={molecules}
100
- onChange={onChangeMoleculeSelectionHandler}
101
- />
102
- <SumValue>
103
- New sum for {element} will be {newSum}!
104
- </SumValue>
105
- </SelectionContainer>
106
- </Container>
107
- ) : (
108
- <EmptyText color={invalid ? 'red' : 'black'}>
109
- You have to Select a spectrum and Add a molecule from the Structure
110
- panel to select as a reference!
111
- </EmptyText>
112
- )}
113
- </div>
109
+ return (
110
+ <EmptyText color={invalid ? 'red' : 'black'}>
111
+ You have to Select a spectrum and Add a molecule from the Structure panel
112
+ to select as a reference!
113
+ </EmptyText>
114
114
  );
115
115
  }
@@ -1,8 +1,10 @@
1
1
  import { Molecule } from 'openchemlib';
2
+ import { autoLabel } from 'openchemlib-utils';
2
3
  import type { ReactNode } from 'react';
3
4
  import { useCallback } from 'react';
4
5
  import {
5
6
  FaCopy,
7
+ FaDatabase,
6
8
  FaDownload,
7
9
  FaFileExport,
8
10
  FaFileImage,
@@ -13,7 +15,7 @@ import {
13
15
  } from 'react-icons/fa';
14
16
  import { FaMaximize, FaMinimize } from 'react-icons/fa6';
15
17
  import { IoOpenOutline } from 'react-icons/io5';
16
- import { MdNumbers, MdOutlineLabelOff } from 'react-icons/md';
18
+ import { MdFlashAuto, MdNumbers, MdOutlineLabelOff } from 'react-icons/md';
17
19
  import { PanelHeader, Toolbar } from 'react-science/ui';
18
20
 
19
21
  import type {
@@ -33,50 +35,80 @@ import { useToaster } from '../../context/ToasterContext.js';
33
35
  import { useTopicMolecule } from '../../context/TopicMoleculeContext.js';
34
36
  import type { ToolbarPopoverMenuItem } from '../../elements/ToolbarPopoverItem.js';
35
37
  import { ToolbarPopoverItem } from '../../elements/ToolbarPopoverItem.js';
38
+ import { useDialogToggle } from '../../hooks/useDialogToggle.ts';
36
39
  import AboutPredictionModal from '../../modal/AboutPredictionModal.js';
40
+ import { MoleculeAutoLabelsDatabaseModal } from '../../modal/MoleculeAutoLabelsDatabaseModal.tsx';
37
41
  import PredictSpectraModal from '../../modal/PredictSpectraModal.js';
38
42
  import { booleanToString } from '../../utility/booleanToString.ts';
39
43
  import {
40
44
  browserNotSupportedErrorToast,
41
45
  copyPNGToClipboard,
46
+ exportAsMolfile,
42
47
  exportAsSVG,
43
48
  } from '../../utility/export.js';
44
49
  import { useMoleculeAnnotationCore } from '../hooks/useMoleculeAnnotationCore.ts';
45
50
 
46
- const MOL_EXPORT_MENU: ToolbarPopoverMenuItem[] = [
51
+ type ExportOperation =
52
+ | 'CopyAsSmiles'
53
+ | 'CopyAsMolfileV3'
54
+ | 'SaveAsMolfileV3'
55
+ | 'CopyAsMolfileV2'
56
+ | 'SaveAsMolfileV2'
57
+ | 'CopyAsPng'
58
+ | 'SaveAsSvg';
59
+
60
+ interface ExportDataItem {
61
+ id: ExportOperation;
62
+ }
63
+
64
+ const MOL_EXPORT_MENU: Array<ToolbarPopoverMenuItem<ExportDataItem>> = [
47
65
  {
48
66
  icon: <FaCopy />,
49
67
  text: 'Copy as SMILES',
50
68
  data: {
51
- id: 'smiles',
69
+ id: 'CopyAsSmiles',
52
70
  },
53
71
  },
54
72
  {
55
73
  icon: <FaCopy />,
56
- text: 'Copy as molfile V3',
74
+ text: 'Copy as molfile V2',
57
75
  data: {
58
- id: 'molfileV3',
76
+ id: 'CopyAsMolfileV2',
59
77
  },
60
78
  },
61
79
  {
62
80
  icon: <FaCopy />,
63
- text: 'Copy as molfile V2',
81
+ text: 'Copy as molfile V3',
64
82
  data: {
65
- id: 'molfileV2',
83
+ id: 'CopyAsMolfileV3',
84
+ },
85
+ },
86
+ {
87
+ icon: <FaDownload />,
88
+ text: 'Save as molfile V2',
89
+ data: {
90
+ id: 'SaveAsMolfileV2',
91
+ },
92
+ },
93
+ {
94
+ icon: <FaDownload />,
95
+ text: 'Save as molfile V3',
96
+ data: {
97
+ id: 'SaveAsMolfileV3',
66
98
  },
67
99
  },
68
100
  {
69
101
  icon: <FaFileImage />,
70
102
  text: 'Copy as PNG',
71
103
  data: {
72
- id: 'png',
104
+ id: 'CopyAsPng',
73
105
  },
74
106
  },
75
107
  {
76
108
  icon: <FaDownload />,
77
109
  text: 'Export as SVG',
78
110
  data: {
79
- id: 'svg',
111
+ id: 'SaveAsSvg',
80
112
  },
81
113
  },
82
114
  ];
@@ -111,6 +143,9 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
111
143
  current: { defaultMoleculeSettings },
112
144
  } = usePreferences();
113
145
  const moleculeKey = molecules?.[currentIndex]?.id;
146
+ const { dialog, openDialog, closeDialog } = useDialogToggle({
147
+ autoLabelDatabaseDialog: false,
148
+ });
114
149
  const saveAsSVGHandler = useCallback(() => {
115
150
  if (!rootRef) return;
116
151
  exportAsSVG(`molSVG${currentIndex}`, {
@@ -161,29 +196,39 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
161
196
  );
162
197
 
163
198
  const exportHandler = useCallback(
164
- (selected: any) => {
199
+ (selected?: ExportDataItem) => {
165
200
  const m = molecules?.[currentIndex];
166
201
  const molecule = Molecule.fromMolfile(m.molfile);
167
202
  if (molecule) {
168
203
  switch (selected?.id) {
169
- case 'smiles':
204
+ case 'CopyAsSmiles':
170
205
  copyHandler(molecule.toIsomericSmiles(), 'SMILES');
171
206
 
172
207
  break;
173
- case 'molfileV3':
208
+ case 'CopyAsMolfileV3':
174
209
  copyHandler(m.molfile, 'MOLFile');
175
210
  break;
176
- case 'molfileV2': {
211
+ case 'SaveAsMolfileV3':
212
+ exportAsMolfile(m.molfile, m.label);
213
+ break;
214
+ case 'CopyAsMolfileV2': {
177
215
  copyHandler(
178
216
  molecule.toMolfile({ customLabelPosition: 'normal' }),
179
217
  'MOLFile',
180
218
  );
181
219
  break;
182
220
  }
183
- case 'png':
221
+ case 'SaveAsMolfileV2': {
222
+ exportAsMolfile(
223
+ molecule.toMolfile({ customLabelPosition: 'normal' }),
224
+ m.label,
225
+ );
226
+ break;
227
+ }
228
+ case 'CopyAsPng':
184
229
  void saveAsPNGHandler();
185
230
  break;
186
- case 'svg':
231
+ case 'SaveAsSvg':
187
232
  saveAsSVGHandler();
188
233
  break;
189
234
  default:
@@ -274,6 +319,20 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
274
319
  });
275
320
  }
276
321
 
322
+ function autoLabels() {
323
+ const currentMolecule = molecules[currentIndex];
324
+
325
+ if (!currentMolecule) return;
326
+ const { id, label, molfile } = currentMolecule;
327
+
328
+ const molecule = Molecule.fromMolfile(molfile);
329
+ autoLabel(molecule);
330
+ dispatch({
331
+ type: 'SET_MOLECULE',
332
+ payload: { id, label, molfile: molecule.toMolfileV3() },
333
+ });
334
+ }
335
+
277
336
  const hasMolecules = molecules && molecules.length > 0;
278
337
  const showCounter = hasMolecules && renderSource !== 'predictionPanel';
279
338
  const moreMenu: ToolbarPopoverMenuItem[] = [
@@ -295,6 +354,23 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
295
354
  disabled: !hasMolecules,
296
355
  onClick: () => clearCustomAtomLabels(),
297
356
  },
357
+ {
358
+ icon: <MdFlashAuto />,
359
+ text: 'Auto label atoms',
360
+ disabled: !hasMolecules,
361
+ tooltip: {
362
+ title: 'Auto label atoms',
363
+ description:
364
+ 'Atoms are automatically labeled according to a predefined template database',
365
+ link: 'https://docs.nmrium.org/help/structure-labelling',
366
+ },
367
+ onClick: () => autoLabels(),
368
+ },
369
+ {
370
+ icon: <FaDatabase />,
371
+ text: 'Template database',
372
+ onClick: () => openDialog('autoLabelDatabaseDialog'),
373
+ },
298
374
  ];
299
375
 
300
376
  const { handleChangeAtomAnnotation, isAnnotation } =
@@ -305,6 +381,9 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
305
381
  current={showCounter ? currentIndex + 1 : undefined}
306
382
  total={showCounter ? molecules.length : undefined}
307
383
  >
384
+ {dialog.autoLabelDatabaseDialog && (
385
+ <MoleculeAutoLabelsDatabaseModal onClose={closeDialog} />
386
+ )}
308
387
  <Toolbar>
309
388
  {renderSource === 'predictionPanel' && <AboutPredictionModal />}
310
389
  {renderSource === 'moleculePanel' && (
@@ -7,7 +7,7 @@ import { isSpectrum1D } from '../../../../data/data1d/Spectrum1D/isSpectrum1D.ts
7
7
  import { isSpectrum2D } from '../../../../data/data2d/Spectrum2D/isSpectrum2D.ts';
8
8
  import { ConcatenationString } from '../../../../data/utilities/Concatenation.ts';
9
9
  import checkModifierKeyActivated from '../../../../data/utilities/checkModifierKeyActivated.ts';
10
- import { getTracesSpectra } from '../../../2d/useTracesSpectra.ts';
10
+ import { useTracesSpectra } from '../../../2d/useTracesSpectra.ts';
11
11
  import type {
12
12
  Assignments,
13
13
  Axis,
@@ -72,22 +72,8 @@ function getSignalsDiaIDs(
72
72
  }
73
73
 
74
74
  function use1DSpectraTraces() {
75
- const {
76
- data,
77
- view: {
78
- spectra: { activeSpectra, activeTab },
79
- },
80
- } = useChartData();
81
-
82
- return useMemo(() => {
83
- const nuclei = activeTab.split(',');
84
- try {
85
- const traces = getTracesSpectra({ nuclei, spectra: data, activeSpectra });
86
- return Object.values(traces).filter((spectrum) => spectrum !== null);
87
- } catch {
88
- return [];
89
- }
90
- }, [activeTab, data, activeSpectra]);
75
+ const traces = useTracesSpectra();
76
+ return Object.values(traces).filter((spectrum) => spectrum !== null);
91
77
  }
92
78
 
93
79
  export default function useAtomAssignment() {
@@ -1,7 +1,6 @@
1
1
  import styled from '@emotion/styled';
2
2
  import type { NMRiumPanelPreferences } from '@zakodium/nmrium-core';
3
- import type { PropsWithChildren } from 'react';
4
- import { createContext, memo, useContext, useMemo, useState } from 'react';
3
+ import { memo } from 'react';
5
4
  import { FaRegEdit } from 'react-icons/fa';
6
5
  import type { ToolbarItemProps } from 'react-science/ui';
7
6
  import { Accordion, Toolbar } from 'react-science/ui';
@@ -21,57 +20,6 @@ const Container = styled.div`
21
20
  height: 100%;
22
21
  width: 100%;
23
22
  `;
24
- interface PanelStateContext {
25
- openSplitPane: () => void;
26
- closeSplitPane: () => void;
27
- isSplitPaneOpen: boolean;
28
- }
29
-
30
- const AccordionContext = createContext<PanelStateContext | null>(null);
31
-
32
- export function usePanelOpenState() {
33
- const context = useContext(AccordionContext);
34
-
35
- if (!context) {
36
- throw new Error('Panel open context must be used within PanelOpenProvider');
37
- }
38
-
39
- return context;
40
- }
41
-
42
- export function PanelOpenProviderProvider({
43
- children,
44
- }: Required<PropsWithChildren>) {
45
- const { current } = usePreferences();
46
-
47
- const {
48
- display: { general = {} },
49
- } = current;
50
- // TODO: make sure to move this state to the workspace once the refactoring of nmrium-core is finished.
51
- const [isSplitPaneOpen, setIsSplitPaneOpen] = useState(
52
- !general?.hidePanelOnLoad,
53
- );
54
-
55
- const state = useMemo(() => {
56
- function openSplitPane() {
57
- setIsSplitPaneOpen(true);
58
- }
59
- function closeSplitPane() {
60
- setIsSplitPaneOpen(false);
61
- }
62
- return {
63
- openSplitPane,
64
- closeSplitPane,
65
- isSplitPaneOpen,
66
- };
67
- }, [isSplitPaneOpen]);
68
-
69
- return (
70
- <AccordionContext.Provider value={state}>
71
- {children}
72
- </AccordionContext.Provider>
73
- );
74
- }
75
23
 
76
24
  function PanelsInner() {
77
25
  const getPanelPreferences = useGetPanelOptions();
@@ -1,17 +1,18 @@
1
1
  import type { NMRiumPanelPreferences } from '@zakodium/nmrium-core';
2
2
 
3
3
  import { usePreferences } from '../../context/PreferencesContext.js';
4
- import { usePanelOpenState } from '../Panels.js';
5
4
 
6
5
  export function useTogglePanel() {
7
6
  const { dispatch, current } = usePreferences();
8
- const { isSplitPaneOpen, openSplitPane } = usePanelOpenState();
9
7
 
10
8
  function togglePanel(id: keyof NMRiumPanelPreferences) {
11
9
  // TODO: make sure current is not a lie and remove the optional chaining.
12
10
  const flag = current?.display?.panels?.[id]?.display;
11
+ const isSplitPaneOpen = !current.display.general?.hidePanelOnLoad;
13
12
 
14
- openSplitPane();
13
+ if (!isSplitPaneOpen) {
14
+ dispatch({ type: 'TOGGLE_SPLIT_PANEL', payload: { isOpen: true } });
15
+ }
15
16
 
16
17
  if ((!isSplitPaneOpen && !flag) || isSplitPaneOpen) {
17
18
  dispatch({
@@ -129,7 +129,10 @@ function setData(draft: Draft<State>, input: InputProps | InitiateProps) {
129
129
 
130
130
  if (view) {
131
131
  const defaultViewState = getDefaultViewState();
132
-
132
+ // TODO: Refactor to find the spectrum index in each call rather than saving it in state.
133
+ // For now, we will clear the activeSpectra and selectReferences
134
+ view.spectra.activeSpectra = {};
135
+ view.spectra.selectReferences = {};
133
136
  draft.view = lodashMerge(defaultViewState, view);
134
137
  }
135
138
 
@@ -289,6 +292,11 @@ function initData(
289
292
  if (view) {
290
293
  const defaultViewState = getDefaultViewState();
291
294
  draft.view = lodashMerge(defaultViewState, view);
295
+ draft.view.molecules = Object.fromEntries(
296
+ Object.entries(draft.view.molecules).filter(([id]) =>
297
+ draft.molecules.some((molecule) => molecule.id === id),
298
+ ),
299
+ );
292
300
  }
293
301
  draft.actionType = action.type;
294
302
  draft.isLoading = false;
@@ -332,6 +340,12 @@ function handleLoadDropFiles(draft: Draft<State>, action: LoadDropFilesAction) {
332
340
  draft.sources = {};
333
341
  }
334
342
 
343
+ draft.view.molecules = Object.fromEntries(
344
+ Object.entries(draft.view.molecules).filter(([id]) =>
345
+ draft.molecules.some((molecule) => molecule.id === id),
346
+ ),
347
+ );
348
+
335
349
  draft.actionType = type;
336
350
  draft.isLoading = false;
337
351
  return undefined;
@@ -33,6 +33,7 @@ interface AddMoleculeProps {
33
33
  id?: string;
34
34
  floatMoleculeOnSave?: boolean;
35
35
  defaultMoleculeSettings?: MoleculeView;
36
+ label?: string;
36
37
  }
37
38
  type AddMoleculeAction = ActionType<'ADD_MOLECULE', AddMoleculeProps>;
38
39
  type AddMoleculesAction = ActionType<
@@ -105,9 +106,10 @@ export type MoleculeActions =
105
106
  | ToggleMoleculeLabelAction;
106
107
 
107
108
  function addMolecule(draft: Draft<State>, props: AddMoleculeProps) {
108
- const { molfile, id, floatMoleculeOnSave, defaultMoleculeSettings } = props;
109
+ const { molfile, id, label, floatMoleculeOnSave, defaultMoleculeSettings } =
110
+ props;
109
111
  const isEmpty = draft.molecules.length === 0;
110
- MoleculeManager.addMolfile(draft.molecules, molfile, id);
112
+ MoleculeManager.addMolfile(draft.molecules, molfile, { id, label });
111
113
 
112
114
  /**
113
115
  * if it's the first creation of a molecule after the molecules list was empty,
@@ -465,7 +465,7 @@ function handleChangeRangesAssignmentLabelsByDiaIds(
465
465
  for (const signal of signals) {
466
466
  if (
467
467
  previousAssignment === signal.assignment &&
468
- uniqueDiaIds.has(signal.id)
468
+ signal.diaIDs?.some((id) => uniqueDiaIds.has(id))
469
469
  ) {
470
470
  signal.assignment = assignment;
471
471
  }
@@ -82,6 +82,7 @@ type ChangeActiveSpectrumAction = ActionType<
82
82
  | (string & {});
83
83
 
84
84
  id?: string; // spectrum id
85
+ sortedSpectra?: Spectrum[];
85
86
  }
86
87
  >;
87
88
  type ChangeSpectrumSettingAction = ActionType<
@@ -292,11 +293,14 @@ function handleChangeActiveSpectrum(
292
293
  data,
293
294
  toolOptions,
294
295
  } = draft;
295
- const { modifier, id } = action.payload;
296
+ const { modifier, id, sortedSpectra } = action.payload;
296
297
  const spectra = getActiveSpectra(draft);
297
298
 
298
299
  //get the spectra that its nucleus match the active tab
299
- const spectraPerNucleus = getSpectraByNucleus(activeTab, data);
300
+ const spectraPerNucleus = getSpectraByNucleus(
301
+ activeTab,
302
+ sortedSpectra ?? data,
303
+ );
300
304
 
301
305
  //set of the current active spectra
302
306
  let spectraIds = spectra?.map((s) => s.id) || [];
@@ -6,6 +6,7 @@ import { getMultipleSpectraAnalysisDefaultValues } from '../panelsPreferencesDef
6
6
  import type {
7
7
  AnalyzeSpectraAction,
8
8
  ChangeAnalysisColumnValueKeyAction,
9
+ CutSpectraAnalysisAction,
9
10
  DeleteAnalysisColumn,
10
11
  PreferencesState,
11
12
  SetSpectraAnalysisPanelPreferencesAction,
@@ -34,6 +35,21 @@ export function analyzeSpectra(
34
35
  columnKey,
35
36
  });
36
37
  }
38
+ export function cutSpectraAnalysis(
39
+ draft: Draft<PreferencesState>,
40
+ action: CutSpectraAnalysisAction,
41
+ ) {
42
+ const currentWorkspacePreferences = getActiveWorkspace(draft);
43
+ const panels = currentWorkspacePreferences.panels;
44
+ const { x, nucleus } = action.payload;
45
+
46
+ if (!panels.multipleSpectraAnalysis) {
47
+ panels.multipleSpectraAnalysis =
48
+ getMultipleSpectraAnalysisDefaultValues(nucleus);
49
+ }
50
+
51
+ MultipleAnalysis.cutAnalysis(panels.multipleSpectraAnalysis, nucleus, x);
52
+ }
37
53
 
38
54
  export function changeAnalysisColumnValueKey(
39
55
  draft: Draft<PreferencesState>,
@@ -0,0 +1,18 @@
1
+ import type { Draft } from 'immer';
2
+
3
+ import type {
4
+ PreferencesState,
5
+ ToggleSplitPanelAction,
6
+ } from '../preferencesReducer.ts';
7
+ import { getActiveWorkspace } from '../utilities/getActiveWorkspace.ts';
8
+
9
+ export function toggleOpenSplitPanel(
10
+ draft: Draft<PreferencesState>,
11
+ action: ToggleSplitPanelAction,
12
+ ) {
13
+ const currentWorkspacePreferences = getActiveWorkspace(draft);
14
+ const { isOpen } = action.payload || {};
15
+ const generalPreferences = currentWorkspacePreferences.display.general || {};
16
+ generalPreferences.hidePanelOnLoad =
17
+ isOpen ?? !generalPreferences.hidePanelOnLoad;
18
+ }