nmrium 1.7.0 → 1.8.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 (210) hide show
  1. package/lib/component/1d/ranges/Atoms.d.ts.map +1 -1
  2. package/lib/component/1d/ranges/Atoms.js +24 -9
  3. package/lib/component/1d/ranges/Atoms.js.map +1 -1
  4. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.d.ts +2 -1
  5. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.d.ts.map +1 -1
  6. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.js +32 -42
  7. package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.js.map +1 -1
  8. package/lib/component/1d-2d/components/FloatMoleculeStructures/FloatMolecules.d.ts.map +1 -1
  9. package/lib/component/1d-2d/components/FloatMoleculeStructures/FloatMolecules.js.map +1 -1
  10. package/lib/component/2d/zones/SignalsGuideLines.js +1 -1
  11. package/lib/component/2d/zones/SignalsGuideLines.js.map +1 -1
  12. package/lib/component/hooks/useExport.js +1 -1
  13. package/lib/component/hooks/useExport.js.map +1 -1
  14. package/lib/component/loader/useLoadFiles.d.ts.map +1 -1
  15. package/lib/component/loader/useLoadFiles.js +17 -7
  16. package/lib/component/loader/useLoadFiles.js.map +1 -1
  17. package/lib/component/main/NMRiumStateProvider.d.ts.map +1 -1
  18. package/lib/component/main/NMRiumStateProvider.js +2 -3
  19. package/lib/component/main/NMRiumStateProvider.js.map +1 -1
  20. package/lib/component/modal/LoadJCAMPModal.js +7 -2
  21. package/lib/component/modal/LoadJCAMPModal.js.map +1 -1
  22. package/lib/component/modal/MoleculeStructureEditorModal.d.ts.map +1 -1
  23. package/lib/component/modal/MoleculeStructureEditorModal.js +7 -3
  24. package/lib/component/modal/MoleculeStructureEditorModal.js.map +1 -1
  25. package/lib/component/modal/SaveAsModal.d.ts.map +1 -1
  26. package/lib/component/modal/SaveAsModal.js +6 -2
  27. package/lib/component/modal/SaveAsModal.js.map +1 -1
  28. package/lib/component/modal/setting/settings-tabs/ToolsTabContent.d.ts.map +1 -1
  29. package/lib/component/modal/setting/settings-tabs/ToolsTabContent.js +16 -0
  30. package/lib/component/modal/setting/settings-tabs/ToolsTabContent.js.map +1 -1
  31. package/lib/component/panels/MoleculesPanel/MoleculeOptionsPanel.d.ts +6 -0
  32. package/lib/component/panels/MoleculesPanel/MoleculeOptionsPanel.d.ts.map +1 -0
  33. package/lib/component/panels/MoleculesPanel/MoleculeOptionsPanel.js +87 -0
  34. package/lib/component/panels/MoleculesPanel/MoleculeOptionsPanel.js.map +1 -0
  35. package/lib/component/panels/MoleculesPanel/MoleculePanel.d.ts.map +1 -1
  36. package/lib/component/panels/MoleculesPanel/MoleculePanel.js +18 -26
  37. package/lib/component/panels/MoleculesPanel/MoleculePanel.js.map +1 -1
  38. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts.map +1 -1
  39. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +32 -25
  40. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js.map +1 -1
  41. package/lib/component/panels/MoleculesPanel/MoleculeStructure.d.ts +13 -0
  42. package/lib/component/panels/MoleculesPanel/MoleculeStructure.d.ts.map +1 -0
  43. package/lib/component/panels/MoleculesPanel/MoleculeStructure.js +66 -0
  44. package/lib/component/panels/MoleculesPanel/MoleculeStructure.js.map +1 -0
  45. package/lib/component/panels/MoleculesPanel/{useAtomAssignment.d.ts → hooks/useAtomAssignment.d.ts} +1 -1
  46. package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.d.ts.map +1 -0
  47. package/lib/component/panels/MoleculesPanel/{useAtomAssignment.js → hooks/useAtomAssignment.js} +32 -16
  48. package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.js.map +1 -0
  49. package/lib/component/panels/MoleculesPanel/hooks/useExtractAtomAssignmentLabel.d.ts +12 -0
  50. package/lib/component/panels/MoleculesPanel/hooks/useExtractAtomAssignmentLabel.d.ts.map +1 -0
  51. package/lib/component/panels/MoleculesPanel/hooks/useExtractAtomAssignmentLabel.js +58 -0
  52. package/lib/component/panels/MoleculesPanel/hooks/useExtractAtomAssignmentLabel.js.map +1 -0
  53. package/lib/component/panels/MoleculesPanel/utilities/AtomData.d.ts +5 -0
  54. package/lib/component/panels/MoleculesPanel/utilities/AtomData.d.ts.map +1 -0
  55. package/lib/component/panels/MoleculesPanel/utilities/AtomData.js +2 -0
  56. package/lib/component/panels/MoleculesPanel/utilities/AtomData.js.map +1 -0
  57. package/lib/component/panels/MoleculesPanel/utilities/extractFromAtom.d.ts +16 -0
  58. package/lib/component/panels/MoleculesPanel/utilities/extractFromAtom.d.ts.map +1 -0
  59. package/lib/component/panels/MoleculesPanel/utilities/extractFromAtom.js +47 -0
  60. package/lib/component/panels/MoleculesPanel/utilities/extractFromAtom.js.map +1 -0
  61. package/lib/component/panels/MoleculesPanel/utilities/getAssignIds.d.ts +18 -0
  62. package/lib/component/panels/MoleculesPanel/utilities/getAssignIds.d.ts.map +1 -0
  63. package/lib/component/panels/MoleculesPanel/utilities/getAssignIds.js +31 -0
  64. package/lib/component/panels/MoleculesPanel/utilities/getAssignIds.js.map +1 -0
  65. package/lib/component/panels/MoleculesPanel/utilities/getCurrentDiaIDsToHighlight.d.ts +3 -0
  66. package/lib/component/panels/MoleculesPanel/utilities/getCurrentDiaIDsToHighlight.d.ts.map +1 -0
  67. package/lib/component/panels/MoleculesPanel/utilities/getCurrentDiaIDsToHighlight.js +12 -0
  68. package/lib/component/panels/MoleculesPanel/utilities/getCurrentDiaIDsToHighlight.js.map +1 -0
  69. package/lib/component/panels/MoleculesPanel/utilities/getHighlightsOnHover.d.ts +4 -0
  70. package/lib/component/panels/MoleculesPanel/utilities/getHighlightsOnHover.d.ts.map +1 -0
  71. package/lib/component/panels/MoleculesPanel/utilities/getHighlightsOnHover.js +25 -0
  72. package/lib/component/panels/MoleculesPanel/utilities/getHighlightsOnHover.js.map +1 -0
  73. package/lib/component/panels/MoleculesPanel/utilities/getUniqueDiaIDs.d.ts +6 -0
  74. package/lib/component/panels/MoleculesPanel/utilities/getUniqueDiaIDs.d.ts.map +1 -0
  75. package/lib/component/panels/MoleculesPanel/utilities/getUniqueDiaIDs.js +18 -0
  76. package/lib/component/panels/MoleculesPanel/utilities/getUniqueDiaIDs.js.map +1 -0
  77. package/lib/component/panels/hooks/useMoleculeAnnotationCore.d.ts +9 -0
  78. package/lib/component/panels/hooks/useMoleculeAnnotationCore.d.ts.map +1 -0
  79. package/lib/component/panels/hooks/useMoleculeAnnotationCore.js +27 -0
  80. package/lib/component/panels/hooks/useMoleculeAnnotationCore.js.map +1 -0
  81. package/lib/component/reducer/IgnoreActions.d.ts.map +1 -1
  82. package/lib/component/reducer/IgnoreActions.js +2 -1
  83. package/lib/component/reducer/IgnoreActions.js.map +1 -1
  84. package/lib/component/reducer/Reducer.d.ts +11 -5
  85. package/lib/component/reducer/Reducer.d.ts.map +1 -1
  86. package/lib/component/reducer/Reducer.js +8 -3
  87. package/lib/component/reducer/Reducer.js.map +1 -1
  88. package/lib/component/reducer/actions/LoadAction.d.ts +7 -4
  89. package/lib/component/reducer/actions/LoadAction.d.ts.map +1 -1
  90. package/lib/component/reducer/actions/LoadAction.js +35 -26
  91. package/lib/component/reducer/actions/LoadAction.js.map +1 -1
  92. package/lib/component/reducer/actions/MoleculeActions.d.ts +20 -5
  93. package/lib/component/reducer/actions/MoleculeActions.d.ts.map +1 -1
  94. package/lib/component/reducer/actions/MoleculeActions.js +42 -28
  95. package/lib/component/reducer/actions/MoleculeActions.js.map +1 -1
  96. package/lib/component/reducer/actions/RangesActions.d.ts +10 -4
  97. package/lib/component/reducer/actions/RangesActions.d.ts.map +1 -1
  98. package/lib/component/reducer/actions/RangesActions.js +24 -3
  99. package/lib/component/reducer/actions/RangesActions.js.map +1 -1
  100. package/lib/component/reducer/actions/ZonesActions.d.ts +1 -1
  101. package/lib/component/reducer/actions/ZonesActions.d.ts.map +1 -1
  102. package/lib/component/reducer/preferences/actions/changeDefaultMoleculeSettings.d.ts +4 -0
  103. package/lib/component/reducer/preferences/actions/changeDefaultMoleculeSettings.d.ts.map +1 -0
  104. package/lib/component/reducer/preferences/actions/changeDefaultMoleculeSettings.js +7 -0
  105. package/lib/component/reducer/preferences/actions/changeDefaultMoleculeSettings.js.map +1 -0
  106. package/lib/component/reducer/preferences/preferencesReducer.d.ts +3 -2
  107. package/lib/component/reducer/preferences/preferencesReducer.d.ts.map +1 -1
  108. package/lib/component/reducer/preferences/preferencesReducer.js +3 -0
  109. package/lib/component/reducer/preferences/preferencesReducer.js.map +1 -1
  110. package/lib/component/toolbar/ToolTypes.d.ts.map +1 -1
  111. package/lib/component/toolbar/ToolTypes.js +1 -0
  112. package/lib/component/toolbar/ToolTypes.js.map +1 -1
  113. package/lib/component/workspaces/assignment.d.ts.map +1 -1
  114. package/lib/component/workspaces/assignment.js +7 -0
  115. package/lib/component/workspaces/assignment.js.map +1 -1
  116. package/lib/component/workspaces/basic.d.ts.map +1 -1
  117. package/lib/component/workspaces/basic.js +5 -0
  118. package/lib/component/workspaces/basic.js.map +1 -1
  119. package/lib/component/workspaces/embedded.d.ts.map +1 -1
  120. package/lib/component/workspaces/embedded.js +5 -0
  121. package/lib/component/workspaces/embedded.js.map +1 -1
  122. package/lib/component/workspaces/exercise.d.ts.map +1 -1
  123. package/lib/component/workspaces/exercise.js +5 -0
  124. package/lib/component/workspaces/exercise.js.map +1 -1
  125. package/lib/component/workspaces/prediction.d.ts.map +1 -1
  126. package/lib/component/workspaces/prediction.js +5 -0
  127. package/lib/component/workspaces/prediction.js.map +1 -1
  128. package/lib/component/workspaces/process1D.d.ts.map +1 -1
  129. package/lib/component/workspaces/process1D.js +6 -0
  130. package/lib/component/workspaces/process1D.js.map +1 -1
  131. package/lib/component/workspaces/workspaceDefaultProperties.d.ts.map +1 -1
  132. package/lib/component/workspaces/workspaceDefaultProperties.js +18 -0
  133. package/lib/component/workspaces/workspaceDefaultProperties.js.map +1 -1
  134. package/lib/data/SpectraManager.d.ts +1 -1
  135. package/lib/data/SpectraManager.d.ts.map +1 -1
  136. package/lib/data/SpectraManager.js.map +1 -1
  137. package/lib/data/data1d/Spectrum1D/initiateDatum1D.d.ts +0 -1
  138. package/lib/data/data1d/Spectrum1D/initiateDatum1D.d.ts.map +1 -1
  139. package/lib/data/data1d/Spectrum1D/initiateDatum1D.js +17 -16
  140. package/lib/data/data1d/Spectrum1D/initiateDatum1D.js.map +1 -1
  141. package/lib/data/data2d/Spectrum2D/initiateDatum2D.d.ts +0 -1
  142. package/lib/data/data2d/Spectrum2D/initiateDatum2D.d.ts.map +1 -1
  143. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js +7 -6
  144. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js.map +1 -1
  145. package/lib/data/data2d/Spectrum2D/zones/detectZonesManual.d.ts.map +1 -1
  146. package/lib/data/data2d/Spectrum2D/zones/initiateZones.d.ts.map +1 -1
  147. package/lib/data/molecules/Molecule.d.ts +1 -17
  148. package/lib/data/molecules/Molecule.d.ts.map +1 -1
  149. package/lib/data/molecules/Molecule.js +3 -7
  150. package/lib/data/molecules/Molecule.js.map +1 -1
  151. package/lib/data/molecules/MoleculeManager.d.ts +1 -1
  152. package/lib/data/molecules/MoleculeManager.d.ts.map +1 -1
  153. package/lib/data/molecules/MoleculeManager.js +1 -4
  154. package/lib/data/molecules/MoleculeManager.js.map +1 -1
  155. package/lib/versionInfo.js +1 -1
  156. package/package.json +27 -27
  157. package/src/component/1d/ranges/Atoms.tsx +36 -13
  158. package/src/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.tsx +38 -79
  159. package/src/component/1d-2d/components/FloatMoleculeStructures/FloatMolecules.tsx +5 -2
  160. package/src/component/2d/zones/SignalsGuideLines.tsx +1 -1
  161. package/src/component/hooks/useExport.tsx +1 -1
  162. package/src/component/loader/useLoadFiles.ts +19 -7
  163. package/src/component/main/NMRiumStateProvider.tsx +2 -3
  164. package/src/component/modal/LoadJCAMPModal.tsx +10 -4
  165. package/src/component/modal/MoleculeStructureEditorModal.tsx +10 -3
  166. package/src/component/modal/SaveAsModal.tsx +8 -2
  167. package/src/component/modal/setting/settings-tabs/ToolsTabContent.tsx +16 -0
  168. package/src/component/panels/MoleculesPanel/MoleculeOptionsPanel.tsx +160 -0
  169. package/src/component/panels/MoleculesPanel/MoleculePanel.tsx +77 -101
  170. package/src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx +54 -35
  171. package/src/component/panels/MoleculesPanel/MoleculeStructure.tsx +117 -0
  172. package/src/component/panels/MoleculesPanel/{useAtomAssignment.tsx → hooks/useAtomAssignment.tsx} +47 -25
  173. package/src/component/panels/MoleculesPanel/hooks/useExtractAtomAssignmentLabel.ts +74 -0
  174. package/src/component/panels/MoleculesPanel/utilities/AtomData.ts +4 -0
  175. package/src/component/panels/MoleculesPanel/utilities/extractFromAtom.ts +63 -0
  176. package/src/component/panels/MoleculesPanel/utilities/getAssignIds.ts +59 -0
  177. package/src/component/panels/MoleculesPanel/utilities/getCurrentDiaIDsToHighlight.ts +12 -0
  178. package/src/component/panels/MoleculesPanel/utilities/getHighlightsOnHover.ts +36 -0
  179. package/src/component/panels/MoleculesPanel/utilities/getUniqueDiaIDs.ts +20 -0
  180. package/src/component/panels/hooks/useMoleculeAnnotationCore.ts +36 -0
  181. package/src/component/reducer/IgnoreActions.ts +2 -1
  182. package/src/component/reducer/Reducer.ts +21 -8
  183. package/src/component/reducer/actions/LoadAction.ts +51 -38
  184. package/src/component/reducer/actions/MoleculeActions.ts +85 -37
  185. package/src/component/reducer/actions/RangesActions.ts +50 -5
  186. package/src/component/reducer/actions/ZonesActions.ts +1 -1
  187. package/src/component/reducer/preferences/actions/changeDefaultMoleculeSettings.ts +16 -0
  188. package/src/component/reducer/preferences/preferencesReducer.ts +11 -1
  189. package/src/component/toolbar/ToolTypes.ts +1 -0
  190. package/src/component/workspaces/assignment.ts +7 -0
  191. package/src/component/workspaces/basic.ts +5 -0
  192. package/src/component/workspaces/embedded.ts +5 -0
  193. package/src/component/workspaces/exercise.ts +5 -0
  194. package/src/component/workspaces/prediction.ts +5 -0
  195. package/src/component/workspaces/process1D.ts +6 -0
  196. package/src/component/workspaces/workspaceDefaultProperties.ts +18 -0
  197. package/src/data/SpectraManager.ts +1 -7
  198. package/src/data/data1d/Spectrum1D/initiateDatum1D.ts +17 -19
  199. package/src/data/data2d/Spectrum2D/initiateDatum2D.ts +7 -10
  200. package/src/data/molecules/Molecule.ts +5 -25
  201. package/src/data/molecules/MoleculeManager.ts +0 -4
  202. package/src/index.tsx +0 -3
  203. package/src/versionInfo.ts +1 -1
  204. package/lib/component/panels/MoleculesPanel/Utilities.d.ts +0 -43
  205. package/lib/component/panels/MoleculesPanel/Utilities.d.ts.map +0 -1
  206. package/lib/component/panels/MoleculesPanel/Utilities.js +0 -129
  207. package/lib/component/panels/MoleculesPanel/Utilities.js.map +0 -1
  208. package/lib/component/panels/MoleculesPanel/useAtomAssignment.d.ts.map +0 -1
  209. package/lib/component/panels/MoleculesPanel/useAtomAssignment.js.map +0 -1
  210. package/src/component/panels/MoleculesPanel/Utilities.ts +0 -188
@@ -1,23 +1,21 @@
1
1
  /** @jsxImportSource @emotion/react */
2
2
  import type { SerializedStyles } from '@emotion/react';
3
3
  import { css } from '@emotion/react';
4
- import { memo, useEffect, useState } from 'react';
4
+ import { memo, useCallback, useEffect, useState } from 'react';
5
5
  import { ResponsiveChart } from 'react-d3-utils';
6
- import OCLnmr from 'react-ocl-nmr';
7
6
 
8
7
  import type {
9
8
  MoleculesView,
10
9
  StateMoleculeExtended,
11
10
  } from '../../../data/molecules/Molecule.js';
12
11
  import { useChartData } from '../../context/ChartContext.js';
13
- import { useDispatch } from '../../context/DispatchContext.js';
14
12
  import { NextPrev } from '../../elements/NextPrev.js';
15
- import { useHighlightColor } from '../../hooks/useHighlightColor.js';
16
13
  import { useMoleculeEditor } from '../../modal/MoleculeStructureEditorModal.js';
17
14
 
18
15
  import MoleculeHeader from './MoleculeHeader.js';
16
+ import { MoleculeOptionsPanel } from './MoleculeOptionsPanel.tsx';
19
17
  import MoleculePanelHeader from './MoleculePanelHeader.js';
20
- import useAtomAssignment from './useAtomAssignment.js';
18
+ import { MoleculeStructure } from './MoleculeStructure.tsx';
21
19
 
22
20
  const styles: Record<
23
21
  'panel' | 'innerPanel' | 'molecule' | 'slider' | 'items',
@@ -61,20 +59,13 @@ function MoleculePanelInner(props: MoleculePanelInnerProps) {
61
59
  const { molecules: moleculesProp, moleculesView } = props;
62
60
  const [currentIndex, setCurrentIndex] = useState(0);
63
61
  const [molecules, setMolecules] = useState<StateMoleculeExtended[]>([]);
62
+ const [isFlipped, setFlipStatus] = useState(false);
64
63
 
65
- const dispatch = useDispatch();
66
64
  const { modal, openMoleculeEditor } = useMoleculeEditor();
67
- const highlightColor = useHighlightColor();
68
-
69
- const {
70
- currentDiaIDsToHighlight,
71
- handleOnAtomHover,
72
- handleOnClickAtom,
73
- assignedDiaIDsMerged,
74
- } = useAtomAssignment();
75
65
 
76
66
  useEffect(() => {
77
67
  if (moleculesProp) {
68
+ // eslint-disable-next-line react-you-might-not-need-an-effect/no-derived-state
78
69
  setMolecules((prevMolecules) => {
79
70
  if (moleculesProp.length > prevMolecules.length) {
80
71
  setCurrentIndex(molecules.length);
@@ -84,14 +75,6 @@ function MoleculePanelInner(props: MoleculePanelInnerProps) {
84
75
  }
85
76
  }, [molecules.length, moleculesProp]);
86
77
 
87
- function handleReplaceMolecule(molecule: any, molfile: any) {
88
- const { id, label } = molecule;
89
- dispatch({
90
- type: 'SET_MOLECULE',
91
- payload: { molfile, id, label },
92
- });
93
- }
94
-
95
78
  function moleculeIndexHandler(index: any) {
96
79
  setCurrentIndex(index);
97
80
  }
@@ -99,89 +82,82 @@ function MoleculePanelInner(props: MoleculePanelInnerProps) {
99
82
  const lastIndex = molecules?.length > 0 ? molecules.length - 1 : 0;
100
83
  const activeIndex = Math.min(currentIndex, lastIndex);
101
84
 
85
+ const settingsPanelHandler = useCallback(() => {
86
+ setFlipStatus(!isFlipped);
87
+ }, [isFlipped]);
88
+
89
+ const onClose = useCallback(() => {
90
+ setFlipStatus(false);
91
+ }, []);
92
+
102
93
  return (
103
94
  <div css={styles.panel}>
104
- <MoleculePanelHeader
105
- currentIndex={activeIndex}
106
- moleculesView={moleculesView}
107
- molecules={molecules}
108
- onOpenMoleculeEditor={() => openMoleculeEditor()}
109
- onMoleculeIndexChange={moleculeIndexHandler}
110
- />
111
-
112
- <div css={styles.innerPanel}>
113
- <div css={styles.molecule}>
114
- <ResponsiveChart>
115
- {({ height, width }) => {
116
- return (
117
- <NextPrev
118
- onChange={(slideIndex) => setCurrentIndex(slideIndex)}
119
- index={currentIndex}
120
- >
121
- {molecules && molecules.length > 0 ? (
122
- molecules.map((mol: StateMoleculeExtended, index) => (
123
- <div key={mol.id} css={styles.items}>
124
- <MoleculeHeader
125
- currentMolecule={mol}
126
- molecules={molecules}
127
- />
128
-
129
- <div
130
- css={styles.slider}
131
- className="mol-svg-container"
132
- onDoubleClick={() => openMoleculeEditor(mol)}
133
- style={{
134
- backgroundColor:
135
- (index + 1) % 2 !== 0 ? '#fafafa' : 'white',
136
- }}
137
- >
138
- <OCLnmr
139
- id={`molSVG${index}`}
140
- width={width}
141
- height={height - 60}
142
- molfile={mol.molfile || ''}
143
- setMolfile={(molfile) =>
144
- handleReplaceMolecule(mol, molfile)
145
- }
146
- setSelectedAtom={handleOnClickAtom}
147
- atomHighlightColor={
148
- currentDiaIDsToHighlight &&
149
- currentDiaIDsToHighlight.length > 0
150
- ? '#ff000080'
151
- : highlightColor
152
- }
153
- atomHighlightOpacity={1}
154
- highlights={
155
- currentDiaIDsToHighlight &&
156
- currentDiaIDsToHighlight.length > 0
157
- ? currentDiaIDsToHighlight
158
- : assignedDiaIDsMerged
159
- }
160
- atomHighlightStrategy="prefer-editor-props"
161
- setHoverAtom={handleOnAtomHover}
162
- showAtomNumber={
163
- moleculesView?.[mol.id]?.showAtomNumber || false
164
- }
165
- noCarbonLabelWithCustomLabel
166
- />
167
- </div>
95
+ {!isFlipped && (
96
+ <MoleculePanelHeader
97
+ currentIndex={activeIndex}
98
+ moleculesView={moleculesView}
99
+ molecules={molecules}
100
+ onOpenMoleculeEditor={() => openMoleculeEditor()}
101
+ onMoleculeIndexChange={moleculeIndexHandler}
102
+ onClickPreferences={settingsPanelHandler}
103
+ />
104
+ )}
105
+ {isFlipped && <MoleculeOptionsPanel onClose={onClose} />}
106
+ {!isFlipped && (
107
+ <div css={styles.innerPanel}>
108
+ <div css={styles.molecule}>
109
+ <ResponsiveChart>
110
+ {({ height, width }) => {
111
+ return (
112
+ <NextPrev
113
+ onChange={(slideIndex) => setCurrentIndex(slideIndex)}
114
+ index={currentIndex}
115
+ >
116
+ {molecules && molecules.length > 0 ? (
117
+ molecules.map((mol: StateMoleculeExtended, index) => {
118
+ return (
119
+ <div key={mol.id} css={styles.items}>
120
+ <MoleculeHeader
121
+ currentMolecule={mol}
122
+ molecules={molecules}
123
+ />
124
+
125
+ <div
126
+ css={styles.slider}
127
+ className="mol-svg-container"
128
+ onDoubleClick={() => openMoleculeEditor(mol)}
129
+ style={{
130
+ backgroundColor:
131
+ (index + 1) % 2 !== 0 ? '#fafafa' : 'white',
132
+ }}
133
+ >
134
+ <MoleculeStructure
135
+ index={index}
136
+ width={width}
137
+ height={height - 60}
138
+ molecule={mol}
139
+ moleculeView={moleculesView?.[mol.id] || {}}
140
+ />
141
+ </div>
142
+ </div>
143
+ );
144
+ })
145
+ ) : (
146
+ <div
147
+ css={styles.slider}
148
+ style={{ height: '100%' }}
149
+ onClick={() => openMoleculeEditor()}
150
+ >
151
+ <span>Click to draw molecule</span>
168
152
  </div>
169
- ))
170
- ) : (
171
- <div
172
- css={styles.slider}
173
- style={{ height: '100%' }}
174
- onClick={() => openMoleculeEditor()}
175
- >
176
- <span>Click to draw molecule</span>
177
- </div>
178
- )}
179
- </NextPrev>
180
- );
181
- }}
182
- </ResponsiveChart>
153
+ )}
154
+ </NextPrev>
155
+ );
156
+ }}
157
+ </ResponsiveChart>
158
+ </div>
183
159
  </div>
184
- </div>
160
+ )}
185
161
  {modal}
186
162
  </div>
187
163
  );
@@ -1,5 +1,5 @@
1
1
  import { Molecule } from 'openchemlib';
2
- import type { CSSProperties, ReactNode } from 'react';
2
+ import type { ReactNode } from 'react';
3
3
  import { useCallback } from 'react';
4
4
  import {
5
5
  FaCopy,
@@ -8,10 +8,12 @@ import {
8
8
  FaFileImage,
9
9
  FaPaste,
10
10
  FaPlus,
11
+ FaRegBookmark,
11
12
  FaRegTrashAlt,
12
13
  } from 'react-icons/fa';
13
14
  import { FaMaximize, FaMinimize } from 'react-icons/fa6';
14
15
  import { IoOpenOutline } from 'react-icons/io5';
16
+ import { MdNumbers, MdOutlineLabelOff } from 'react-icons/md';
15
17
  import { PanelHeader, Toolbar } from 'react-science/ui';
16
18
 
17
19
  import type {
@@ -23,28 +25,20 @@ import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardCompon
23
25
  import { useClipboard } from '../../../utils/clipboard/clipboardHooks.js';
24
26
  import { useDispatch } from '../../context/DispatchContext.js';
25
27
  import { useGlobal } from '../../context/GlobalContext.js';
28
+ import { usePreferences } from '../../context/PreferencesContext.tsx';
26
29
  import { useToaster } from '../../context/ToasterContext.js';
27
30
  import { useTopicMolecule } from '../../context/TopicMoleculeContext.js';
28
31
  import type { ToolbarPopoverMenuItem } from '../../elements/ToolbarPopoverItem.js';
29
32
  import { ToolbarPopoverItem } from '../../elements/ToolbarPopoverItem.js';
30
33
  import AboutPredictionModal from '../../modal/AboutPredictionModal.js';
31
34
  import PredictSpectraModal from '../../modal/PredictSpectraModal.js';
35
+ import { booleanToString } from '../../utility/booleanToString.ts';
32
36
  import {
33
37
  browserNotSupportedErrorToast,
34
38
  copyPNGToClipboard,
35
39
  exportAsSVG,
36
40
  } from '../../utility/export.js';
37
-
38
- const styles: Record<'atomLabel', CSSProperties> = {
39
- atomLabel: {
40
- width: '14px',
41
- height: '14px',
42
- padding: 0,
43
- margin: 0,
44
- textAlign: 'center',
45
- lineHeight: 1,
46
- },
47
- };
41
+ import { useMoleculeAnnotationCore } from '../hooks/useMoleculeAnnotationCore.ts';
48
42
 
49
43
  const MOL_EXPORT_MENU: ToolbarPopoverMenuItem[] = [
50
44
  {
@@ -110,7 +104,9 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
110
104
  const { rootRef } = useGlobal();
111
105
  const toaster = useToaster();
112
106
  const dispatch = useDispatch();
113
-
107
+ const {
108
+ current: { defaultMoleculeSettings },
109
+ } = usePreferences();
114
110
  const moleculeKey = molecules?.[currentIndex]?.id;
115
111
  const saveAsSVGHandler = useCallback(() => {
116
112
  if (!rootRef) return;
@@ -208,7 +204,10 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
208
204
  if (!text) return;
209
205
  try {
210
206
  const molecules = getMolecules(text);
211
- dispatch({ type: 'ADD_MOLECULES', payload: { molecules } });
207
+ dispatch({
208
+ type: 'ADD_MOLECULES',
209
+ payload: { molecules, defaultMoleculeSettings },
210
+ });
212
211
  } catch {
213
212
  toaster.show({
214
213
  intent: 'danger',
@@ -237,13 +236,6 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
237
236
  });
238
237
  }
239
238
 
240
- function showAtomNumbersHandler() {
241
- dispatch({
242
- type: 'TOGGLE_MOLECULE_ATOM_NUMBER',
243
- payload: { id: moleculeKey },
244
- });
245
- }
246
-
247
239
  const topicMolecule = useTopicMolecule();
248
240
 
249
241
  function expandMoleculeHydrogens(expand?: boolean) {
@@ -258,30 +250,49 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
258
250
  dispatch({ type: 'SET_MOLECULE', payload: { id, label, molfile } });
259
251
  }
260
252
 
253
+ function clearCustomAtomLabels() {
254
+ const currentMolecule = molecules[currentIndex];
255
+
256
+ if (!currentMolecule) return;
257
+ const { id, label, molfile } = currentMolecule;
258
+
259
+ const molecule = Molecule.fromMolfile(molfile);
260
+
261
+ for (let atom = 0; atom < molecule.getAllAtoms(); atom++) {
262
+ molecule.setAtomCustomLabel(atom, null);
263
+ }
264
+
265
+ dispatch({
266
+ type: 'SET_MOLECULE',
267
+ payload: { id, label, molfile: molecule.toMolfileV3() },
268
+ });
269
+ }
270
+
261
271
  const hasMolecules = molecules && molecules.length > 0;
262
272
  const showCounter = hasMolecules && renderSource !== 'predictionPanel';
263
-
264
273
  const moreMenu: ToolbarPopoverMenuItem[] = [
265
274
  {
266
275
  icon: <FaMaximize />,
267
276
  text: 'Expand all hydrogens',
268
- data: {
269
- id: 'expandAllHydrogens',
270
- },
271
277
  disabled: !hasMolecules,
272
278
  onClick: () => expandMoleculeHydrogens(true),
273
279
  },
274
280
  {
275
281
  icon: <FaMinimize />,
276
282
  text: 'Collapse all hydrogens',
277
- data: {
278
- id: 'collapseAllHydrogens',
279
- },
280
283
  disabled: !hasMolecules,
281
284
  onClick: () => expandMoleculeHydrogens(false),
282
285
  },
286
+ {
287
+ icon: <MdOutlineLabelOff />,
288
+ text: 'Clear custom atom labels',
289
+ disabled: !hasMolecules,
290
+ onClick: () => clearCustomAtomLabels(),
291
+ },
283
292
  ];
284
293
 
294
+ const { handleChangeAtomAnnotation, isAnnotation } =
295
+ useMoleculeAnnotationCore(moleculeKey, moleculesView[moleculeKey]);
285
296
  return (
286
297
  <PanelHeader
287
298
  onClickSettings={onClickPreferences}
@@ -324,6 +335,21 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
324
335
  {hasMolecules && (
325
336
  <PredictSpectraModal molecule={molecules[currentIndex]} />
326
337
  )}
338
+
339
+ <Toolbar.Item
340
+ tooltip={`${booleanToString(!isAnnotation('atom-numbers'))} atom number`}
341
+ icon={<MdNumbers />}
342
+ onClick={() => handleChangeAtomAnnotation('atom-numbers')}
343
+ active={isAnnotation('atom-numbers')}
344
+ disabled={!hasMolecules}
345
+ />
346
+ <Toolbar.Item
347
+ tooltip={`${booleanToString(!isAnnotation('custom-labels'))} custom labels`}
348
+ icon={<FaRegBookmark />}
349
+ onClick={() => handleChangeAtomAnnotation('custom-labels')}
350
+ active={isAnnotation('custom-labels')}
351
+ disabled={!hasMolecules}
352
+ />
327
353
  </>
328
354
  )}
329
355
 
@@ -334,13 +360,6 @@ export default function MoleculePanelHeader(props: MoleculePanelHeaderProps) {
334
360
  active={moleculesView?.[moleculeKey]?.floating.visible || false}
335
361
  disabled={!hasMolecules}
336
362
  />
337
- <Toolbar.Item
338
- tooltip="Show atom number"
339
- icon={<p style={styles.atomLabel}>#</p>}
340
- onClick={showAtomNumbersHandler}
341
- active={moleculesView?.[moleculeKey]?.showAtomNumber || false}
342
- disabled={!hasMolecules}
343
- />
344
363
 
345
364
  <ToolbarPopoverItem
346
365
  options={moreMenu}
@@ -0,0 +1,117 @@
1
+ import type { MoleculeView } from '@zakodium/nmrium-core';
2
+ import { useRef } from 'react';
3
+ import type { MolfileSvgRendererProps } from 'react-ocl';
4
+ import { MolfileSvgRenderer } from 'react-ocl';
5
+ import type { OCLnmrProps } from 'react-ocl-nmr';
6
+ import OCLnmr from 'react-ocl-nmr';
7
+
8
+ import type { StateMoleculeExtended } from '../../../data/molecules/Molecule.ts';
9
+ import { useDispatch } from '../../context/DispatchContext.tsx';
10
+ import { useHighlightColor } from '../../hooks/useHighlightColor.ts';
11
+
12
+ import useAtomAssignment from './hooks/useAtomAssignment.tsx';
13
+ import { useExtractAtomAssignmentLabel } from './hooks/useExtractAtomAssignmentLabel.ts';
14
+
15
+ interface MoleculeStructureProps extends Pick<OCLnmrProps, 'width' | 'height'> {
16
+ moleculeView: MoleculeView;
17
+ renderAsSVG?: boolean;
18
+ molecule: StateMoleculeExtended;
19
+ showMoleculeLabel?: boolean;
20
+ index?: number;
21
+ }
22
+
23
+ export function MoleculeStructure(props: MoleculeStructureProps) {
24
+ const {
25
+ molecule,
26
+ moleculeView,
27
+ width,
28
+ height,
29
+ renderAsSVG = false,
30
+ showMoleculeLabel,
31
+ index = 0,
32
+ } = props;
33
+ const {
34
+ currentDiaIDsToHighlight,
35
+ handleOnAtomHover,
36
+ handleOnClickAtom,
37
+ assignedDiaIDsMerged,
38
+ } = useAtomAssignment();
39
+ const highlightColor = useHighlightColor();
40
+ const dispatch = useDispatch();
41
+ const { onAtomHover, getAssignmentLabelByHover, getLastHoverAtom } =
42
+ useExtractAtomAssignmentLabel();
43
+ //TODO Temporary workaround to prevent other focused elements from being triggered by the space key
44
+ const containerRef = useRef<HTMLDivElement>(null);
45
+
46
+ const atomHighlightColor =
47
+ currentDiaIDsToHighlight?.length > 0 ? '#ff000080' : highlightColor;
48
+ const baseProps: MolfileSvgRendererProps = {
49
+ height,
50
+ width,
51
+ label: (showMoleculeLabel ?? moleculeView.showLabel) ? molecule.label : '',
52
+ labelFontSize: 15,
53
+ labelColor: 'rgba(138, 59, 59, 1)',
54
+ molfile: molecule.molfile,
55
+ atomHighlightColor,
56
+ atomHighlightOpacity: 1,
57
+ showAtomNumber: moleculeView.atomAnnotation === 'atom-numbers',
58
+ noAtomCustomLabels: moleculeView.atomAnnotation !== 'custom-labels',
59
+ noCarbonLabelWithCustomLabel: true,
60
+ };
61
+
62
+ if (renderAsSVG) {
63
+ return <MolfileSvgRenderer {...baseProps} />;
64
+ }
65
+
66
+ return (
67
+ <div tabIndex={0} ref={containerRef}>
68
+ <OCLnmr
69
+ id={`molSVG${index}`}
70
+ {...baseProps}
71
+ setSelectedAtom={(atom, event) =>
72
+ handleOnClickAtom(atom, event, molecule.id)
73
+ }
74
+ highlights={
75
+ currentDiaIDsToHighlight?.length > 0
76
+ ? currentDiaIDsToHighlight
77
+ : assignedDiaIDsMerged
78
+ }
79
+ atomHighlightStrategy="prefer-editor-props"
80
+ setHoverAtom={(atom) => {
81
+ //TODO Temporary workaround to prevent other focused elements from being triggered by the space key
82
+ containerRef.current?.focus();
83
+ handleOnAtomHover(atom);
84
+ if (atom) {
85
+ onAtomHover(atom);
86
+ }
87
+ }}
88
+ setMolfile={(molfile) => {
89
+ const diaObject = getLastHoverAtom();
90
+ const assignmentObj = getAssignmentLabelByHover(molecule.id, molfile);
91
+
92
+ if (assignmentObj && diaObject) {
93
+ dispatch({
94
+ type: 'CHANGE_ASSIGNMENT_LABEL_BY_DIAIDS',
95
+ payload: {
96
+ diaIDs: [diaObject.idCode].concat(
97
+ diaObject.attachedHydrogensIDCodes,
98
+ ),
99
+ assignment: assignmentObj.assignment,
100
+ previousAssignment: assignmentObj.previousAssignment,
101
+ },
102
+ });
103
+ }
104
+
105
+ dispatch({
106
+ type: 'SET_MOLECULE',
107
+ payload: {
108
+ molfile,
109
+ id: molecule.id,
110
+ label: molecule.label,
111
+ },
112
+ });
113
+ }}
114
+ />
115
+ </div>
116
+ );
117
+ }
@@ -3,28 +3,30 @@ import type { DiaIDAndInfo } from 'openchemlib-utils';
3
3
  import type { MouseEvent } from 'react';
4
4
  import { useMemo, useRef } from 'react';
5
5
 
6
- import { isSpectrum1D } from '../../../data/data1d/Spectrum1D/isSpectrum1D.js';
7
- import { isSpectrum2D } from '../../../data/data2d/Spectrum2D/isSpectrum2D.ts';
8
- import { ConcatenationString } from '../../../data/utilities/Concatenation.js';
9
- import checkModifierKeyActivated from '../../../data/utilities/checkModifierKeyActivated.js';
10
- import { useTracesSpectra } from '../../2d/useTracesSpectra.ts';
11
- import type { Assignments, Axis } from '../../assignment/AssignmentsContext.js';
12
- import { useAssignmentContext } from '../../assignment/AssignmentsContext.js';
13
- import { useChartData } from '../../context/ChartContext.js';
14
- import { useDispatch } from '../../context/DispatchContext.js';
15
- import { useToaster } from '../../context/ToasterContext.js';
16
- import type { HighlightEventSource } from '../../highlight/index.js';
17
- import { useHighlightData } from '../../highlight/index.js';
18
- import useSpectrum from '../../hooks/useSpectrum.js';
19
-
20
- import type { AtomData } from './Utilities.js';
21
- import {
22
- extractFromAtom,
23
- getAssignIds,
24
- getCurrentDiaIDsToHighlight,
25
- getHighlightsOnHover,
26
- getUniqueDiaIDs,
27
- } from './Utilities.js';
6
+ import { isSpectrum1D } from '../../../../data/data1d/Spectrum1D/isSpectrum1D.ts';
7
+ import { isSpectrum2D } from '../../../../data/data2d/Spectrum2D/isSpectrum2D.ts';
8
+ import { ConcatenationString } from '../../../../data/utilities/Concatenation.ts';
9
+ import checkModifierKeyActivated from '../../../../data/utilities/checkModifierKeyActivated.ts';
10
+ import { useTracesSpectra } from '../../../2d/useTracesSpectra.ts';
11
+ import type {
12
+ Assignments,
13
+ Axis,
14
+ } from '../../../assignment/AssignmentsContext.ts';
15
+ import { useAssignmentContext } from '../../../assignment/AssignmentsContext.ts';
16
+ import { useChartData } from '../../../context/ChartContext.tsx';
17
+ import { useDispatch } from '../../../context/DispatchContext.tsx';
18
+ import { useToaster } from '../../../context/ToasterContext.tsx';
19
+ import type { HighlightEventSource } from '../../../highlight/index.tsx';
20
+ import { useHighlightData } from '../../../highlight/index.tsx';
21
+ import useSpectrum from '../../../hooks/useSpectrum.ts';
22
+ import type { AtomData } from '../utilities/AtomData.ts';
23
+ import { extractFromAtom } from '../utilities/extractFromAtom.ts';
24
+ import { getAssignIds } from '../utilities/getAssignIds.ts';
25
+ import { getCurrentDiaIDsToHighlight } from '../utilities/getCurrentDiaIDsToHighlight.ts';
26
+ import { getHighlightsOnHover } from '../utilities/getHighlightsOnHover.ts';
27
+ import { getUniqueDiaIDs } from '../utilities/getUniqueDiaIDs.ts';
28
+
29
+ import { useExtractAtomAssignmentLabel } from './useExtractAtomAssignmentLabel.ts';
28
30
 
29
31
  function flattenAssignedDiaIDs(assignments: Assignments) {
30
32
  const assignedDiaIDs: string[] = [];
@@ -84,6 +86,7 @@ export default function useAtomAssignment() {
84
86
  const highlightData = useHighlightData();
85
87
  const highlightedIdDsRef = useRef<string[]>([]);
86
88
  const assignments = useAssignmentContext();
89
+ const { getAssignmentLabelById } = useExtractAtomAssignmentLabel();
87
90
  const { activated: activatedAssignment } = assignments;
88
91
 
89
92
  const activatedKey = activatedAssignment
@@ -126,8 +129,16 @@ export default function useAtomAssignment() {
126
129
  return getCurrentDiaIDsToHighlight(assignments).concat(highlights);
127
130
  }, [assignments, highlightData.highlight, spectrum, tracesSpectra]);
128
131
 
129
- function assign1DAtom(spectrum: Spectrum1D, key: string, atom: AtomData) {
130
- const assignKeys = getAssignIds(spectrum, key);
132
+ interface Assign1DOptions {
133
+ spectrum: Spectrum1D;
134
+ assignId: string;
135
+ atom: AtomData;
136
+ assignmentLabel?: string;
137
+ }
138
+
139
+ function assign1DAtom(options: Assign1DOptions) {
140
+ const { spectrum, assignId, atom, assignmentLabel } = options;
141
+ const assignKeys = getAssignIds(spectrum, assignId);
131
142
 
132
143
  if (!assignKeys) return;
133
144
  const [{ index: rangeIndex }] = assignKeys;
@@ -154,6 +165,7 @@ export default function useAtomAssignment() {
154
165
  diaIDs: uniqueDiaIDs.diaIDs,
155
166
  keys: assignKeys,
156
167
  spectrumId,
168
+ assignment: assignmentLabel || '',
157
169
  },
158
170
  });
159
171
  }
@@ -193,6 +205,7 @@ export default function useAtomAssignment() {
193
205
  function handleOnClickAtom(
194
206
  diaIDAndInfo: DiaIDAndInfo | undefined,
195
207
  event: MouseEvent,
208
+ moleculeId: string,
196
209
  ) {
197
210
  if (checkModifierKeyActivated(event) || !activatedAssignment) return;
198
211
 
@@ -202,6 +215,10 @@ export default function useAtomAssignment() {
202
215
  if (!id || !axis) {
203
216
  return;
204
217
  }
218
+
219
+ const assignmentLabel = diaIDAndInfo?.idCode
220
+ ? getAssignmentLabelById(moleculeId, diaIDAndInfo.idCode)
221
+ : '';
205
222
  const atomInformation = extractFromAtom(diaIDAndInfo, nucleus, axis);
206
223
 
207
224
  if (atomInformation.nbAtoms === 0) {
@@ -226,7 +243,12 @@ export default function useAtomAssignment() {
226
243
  if (!currentSpectrum) return;
227
244
 
228
245
  if (isSpectrum1D(currentSpectrum)) {
229
- assign1DAtom(currentSpectrum, activatedAssignment.id, atomInformation);
246
+ assign1DAtom({
247
+ spectrum: currentSpectrum,
248
+ assignId: activatedAssignment.id,
249
+ atom: atomInformation,
250
+ assignmentLabel,
251
+ });
230
252
  } else {
231
253
  assign2DAtom(
232
254
  currentSpectrum,