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
@@ -0,0 +1,74 @@
1
+ import { Molecule } from 'openchemlib';
2
+ import type { DiaIDAndInfo } from 'openchemlib-utils';
3
+ import { useRef } from 'react';
4
+
5
+ import { useTopicMolecule } from '../../../context/TopicMoleculeContext.tsx';
6
+
7
+ export function useExtractAtomAssignmentLabel() {
8
+ const topicMolecule = useTopicMolecule();
9
+ const lastHoverAtomIdRef = useRef<DiaIDAndInfo>();
10
+
11
+ function getLastHoverAtom() {
12
+ return lastHoverAtomIdRef.current;
13
+ }
14
+
15
+ function getTopicAtom(moleculeId: string, oclId: string, molfile?: string) {
16
+ const baseMolecule = topicMolecule?.[moleculeId];
17
+
18
+ if (!baseMolecule) return;
19
+
20
+ const molecule = molfile
21
+ ? baseMolecule.fromMolecule(Molecule.fromMolfile(molfile))
22
+ : baseMolecule;
23
+
24
+ const groupedDiaIdsMapping = molecule.getGroupedDiastereotopicAtomIDs();
25
+ if (!Array.isArray(groupedDiaIdsMapping)) return;
26
+
27
+ return groupedDiaIdsMapping.find((obj: any) => obj.oclID === oclId);
28
+ }
29
+
30
+ function getTopicAtomByHover(moleculeId: string, molfile?: string) {
31
+ if (!lastHoverAtomIdRef.current) return;
32
+
33
+ return getTopicAtom(moleculeId, lastHoverAtomIdRef.current.idCode, molfile);
34
+ }
35
+
36
+ function onAtomHover(atom: DiaIDAndInfo | undefined) {
37
+ lastHoverAtomIdRef.current = atom;
38
+ }
39
+
40
+ function getAssignmentLabelById(
41
+ moleculeId: string,
42
+ oclID: string,
43
+ molfile?: string,
44
+ ) {
45
+ const atomData = getTopicAtom(moleculeId, oclID, molfile);
46
+ if (!atomData) return;
47
+
48
+ const { customLabels = [], heavyAtomsCustomLabels = [] } = atomData;
49
+ const labels =
50
+ customLabels.length > 0 ? customLabels : heavyAtomsCustomLabels;
51
+
52
+ const uniqueLabels = [
53
+ ...new Set(labels.map((l: string) => l.trim()).filter(Boolean)),
54
+ ];
55
+ return uniqueLabels.join(',');
56
+ }
57
+
58
+ function getAssignmentLabelByHover(moleculeId: string, molfile?: string) {
59
+ const diaId = lastHoverAtomIdRef.current?.idCode;
60
+ if (!diaId) return;
61
+ return {
62
+ assignment: getAssignmentLabelById(moleculeId, diaId, molfile),
63
+ previousAssignment: getAssignmentLabelById(moleculeId, diaId),
64
+ };
65
+ }
66
+
67
+ return {
68
+ getAssignmentLabelByHover,
69
+ getAssignmentLabelById,
70
+ onAtomHover,
71
+ getLastHoverAtom,
72
+ getTopicAtomByHover,
73
+ };
74
+ }
@@ -0,0 +1,4 @@
1
+ export interface AtomData {
2
+ oclIDs: string[];
3
+ nbAtoms: number;
4
+ }
@@ -0,0 +1,63 @@
1
+ import type { DiaIDAndInfo } from 'openchemlib-utils';
2
+
3
+ import type { Axis } from '../../../assignment/AssignmentsContext.js';
4
+
5
+ import type { AtomData } from './AtomData.ts';
6
+
7
+ /**
8
+ * Returns the OCL id(s) and number of atoms of an atom when hovering over
9
+ * or clicking on it. This is depending on an optional given axis.
10
+ * In case of an heavy atom with bonded hydrogens the OCL id(s)
11
+ * and number of these hydrogens are added as well.
12
+ *
13
+ * @param {DiaIDAndInfo} diaIDAndInfo - atom returned by OCLnmr component
14
+ * @param {string} activeTab - active tab
15
+ * @param {Axis} axis - current axis
16
+ *
17
+ */
18
+ export function extractFromAtom(
19
+ diaIDAndInfo: DiaIDAndInfo | undefined,
20
+ activeTab: string,
21
+ axis?: Axis | null,
22
+ ): AtomData {
23
+ const elements = getElements(activeTab);
24
+
25
+ if (elements && elements.length > 0 && diaIDAndInfo) {
26
+ const dim = axis === 'x' ? 0 : axis === 'y' ? 1 : null;
27
+ switch (dim !== null && elements[dim]) {
28
+ case diaIDAndInfo.atomLabel: {
29
+ // take always oclID if atom type is same as element of activeTab)
30
+ return {
31
+ oclIDs: [diaIDAndInfo.idCode],
32
+ nbAtoms: diaIDAndInfo.nbEquivalentAtoms,
33
+ };
34
+ }
35
+ case 'H': {
36
+ // if we are in proton spectrum and use then the IDs of attached hydrogens of an atom
37
+ return {
38
+ oclIDs: diaIDAndInfo.attachedHydrogensIDCodes,
39
+ nbAtoms:
40
+ diaIDAndInfo.nbEquivalentAtoms * diaIDAndInfo.nbAttachedHydrogens,
41
+ };
42
+ }
43
+ default:
44
+ return {
45
+ oclIDs: [diaIDAndInfo.idCode].concat(
46
+ diaIDAndInfo.attachedHydrogensIDCodes,
47
+ ),
48
+ nbAtoms:
49
+ diaIDAndInfo.nbEquivalentAtoms +
50
+ diaIDAndInfo.nbEquivalentAtoms * diaIDAndInfo.nbAttachedHydrogens,
51
+ };
52
+ }
53
+ }
54
+
55
+ return { oclIDs: [], nbAtoms: 0 };
56
+ }
57
+
58
+ function getElements(activeTab: string) {
59
+ if (!activeTab) return;
60
+
61
+ const nuclei = activeTab.split(',');
62
+ return nuclei.map((nucleus) => nucleus.replaceAll(/\d/g, ''));
63
+ }
@@ -0,0 +1,59 @@
1
+ import type { Range, Zone } from '@zakodium/nmr-types';
2
+ import type { Spectrum } from '@zakodium/nmrium-core';
3
+
4
+ import { isSpectrum1D } from '../../../../data/data1d/Spectrum1D/isSpectrum1D.ts';
5
+
6
+ interface TargetAssignment {
7
+ key: string;
8
+ index: number;
9
+ }
10
+
11
+ interface RangeTargetAssignKey extends TargetAssignment {
12
+ target: 'range';
13
+ }
14
+ interface ZoneTargetAssignKey extends TargetAssignment {
15
+ target: 'zone';
16
+ }
17
+ interface SignalTargetAssignKey extends TargetAssignment {
18
+ target: 'signal';
19
+ }
20
+ export type TargetAssignKeys =
21
+ | [RangeTargetAssignKey | ZoneTargetAssignKey]
22
+ | [RangeTargetAssignKey | ZoneTargetAssignKey, SignalTargetAssignKey];
23
+
24
+ export function getAssignIds(
25
+ spectrum: Spectrum,
26
+ id: string,
27
+ ): TargetAssignKeys | null {
28
+ if (!spectrum) return null;
29
+
30
+ const data = getRangesOrZones(spectrum);
31
+ const target = isSpectrum1D(spectrum) ? 'range' : 'zone';
32
+
33
+ for (let i = 0; i < data.length; i++) {
34
+ const datum = data[i];
35
+
36
+ if (datum.id === id) {
37
+ return [{ target, index: i, key: datum.id }];
38
+ }
39
+
40
+ const signalIndex = datum.signals.findIndex((signal) => signal.id === id);
41
+ if (signalIndex !== -1) {
42
+ const { id } = datum.signals[signalIndex];
43
+ return [
44
+ { target, index: i, key: datum.id },
45
+ { target: 'signal', index: signalIndex, key: id },
46
+ ];
47
+ }
48
+ }
49
+
50
+ return null;
51
+ }
52
+
53
+ function getRangesOrZones(spectrum: Spectrum): Array<Range | Zone> {
54
+ if (isSpectrum1D(spectrum)) {
55
+ return spectrum.ranges.values;
56
+ } else {
57
+ return spectrum.zones.values;
58
+ }
59
+ }
@@ -0,0 +1,12 @@
1
+ import type { AssignmentContext } from '../../../assignment/AssignmentsContext.ts';
2
+
3
+ export function getCurrentDiaIDsToHighlight(assignmentData: AssignmentContext) {
4
+ const { highlighted, data } = assignmentData;
5
+ const assignment = highlighted ? data[highlighted.id] : null;
6
+ const axisHover = highlighted ? highlighted.axis : null;
7
+ if (axisHover && assignment?.[axisHover]) {
8
+ return assignment[axisHover];
9
+ } else {
10
+ return (assignment?.x || []).concat(assignment?.y || []);
11
+ }
12
+ }
@@ -0,0 +1,36 @@
1
+ import type { Spectrum } from '@zakodium/nmrium-core';
2
+
3
+ import { assignmentAxes } from '../../../assignment/AssignmentsContext.js';
4
+ import type { AssignmentContext } from '../../../assignment/AssignmentsContext.ts';
5
+
6
+ import { getAssignIds } from './getAssignIds.ts';
7
+
8
+ export function getHighlightsOnHover(
9
+ assignments: AssignmentContext,
10
+ oclIDs: string[],
11
+ spectra: Spectrum[],
12
+ ) {
13
+ // set all IDs to highlight when hovering over an atom from AssignKey data
14
+ let highlights: string[] = [];
15
+ const assignmentsByKey = assignments.data;
16
+
17
+ for (const key in assignmentsByKey) {
18
+ const assignments = assignmentsByKey[key];
19
+ for (const axis of assignmentAxes) {
20
+ if (assignments[axis]?.some((oclKey: any) => oclIDs.includes(oclKey))) {
21
+ highlights = highlights.concat(assignments[axis]);
22
+ for (const spectrum of spectra) {
23
+ const assignIds = getAssignIds(spectrum, key);
24
+ if (!assignIds) {
25
+ continue;
26
+ }
27
+
28
+ const ids = assignIds.map<string>((item) => item.key);
29
+ highlights.push(...ids);
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ return highlights;
36
+ }
@@ -0,0 +1,20 @@
1
+ import type { AtomData } from './AtomData.ts';
2
+
3
+ export function getUniqueDiaIDs(diaIDs: string[], atomInformation: AtomData) {
4
+ // a previous version of the code prevented to assign many time the same atom
5
+ // see revision cc13abc18f77b6787b923e3c4edaef51750d9e90
6
+ const { nbAtoms, oclIDs } = atomInformation;
7
+
8
+ const diaIDSet = new Set(diaIDs);
9
+ let tempNbAtoms: number = nbAtoms;
10
+
11
+ for (const oclID of oclIDs) {
12
+ if (diaIDSet.has(oclID)) {
13
+ tempNbAtoms *= -1;
14
+ diaIDSet.delete(oclID);
15
+ } else {
16
+ diaIDSet.add(oclID);
17
+ }
18
+ }
19
+ return { diaIDs: Array.from(diaIDSet), nbAtoms: tempNbAtoms };
20
+ }
@@ -0,0 +1,36 @@
1
+ import type { MoleculeView } from '@zakodium/nmrium-core';
2
+
3
+ import { useDispatch } from '../../context/DispatchContext.tsx';
4
+
5
+ type Annotation = MoleculeView['atomAnnotation'];
6
+
7
+ export function useMoleculeAnnotationCore(
8
+ id: string,
9
+ moleculeView: MoleculeView,
10
+ ) {
11
+ const dispatch = useDispatch();
12
+ const { atomAnnotation: baseAtomAnnotation } = moleculeView || {};
13
+ function isAnnotation(annotation: Annotation) {
14
+ return baseAtomAnnotation === annotation;
15
+ }
16
+
17
+ function handleChangeAtomAnnotation(annotation: Annotation) {
18
+ const atomAnnotation =
19
+ baseAtomAnnotation === annotation ? 'none' : annotation;
20
+ dispatch({
21
+ type: 'CHANGE_MOLECULE_ANNOTATION',
22
+ payload: { id, atomAnnotation },
23
+ });
24
+ }
25
+ function handleToggleMoleculeLabel() {
26
+ dispatch({
27
+ type: 'TOGGLE_MOLECULE_LABEL',
28
+ payload: { id },
29
+ });
30
+ }
31
+ return {
32
+ handleToggleMoleculeLabel,
33
+ isAnnotation,
34
+ handleChangeAtomAnnotation,
35
+ };
36
+ }
@@ -29,8 +29,9 @@ const ignoreActions = new Set<Partial<Action['type']>>([
29
29
  'TOGGLE_REAL_IMAGINARY_VISIBILITY',
30
30
  'FLOAT_MOLECULE_OVER_SPECTRUM',
31
31
  'TOGGLE_SPECTRA_LEGEND',
32
- 'TOGGLE_MOLECULE_ATOM_NUMBER',
32
+ 'CHANGE_MOLECULE_ANNOTATION',
33
33
  'SET_2D_LEVEL',
34
+ 'TOGGLE_MOLECULE_LABEL',
34
35
  ]);
35
36
 
36
37
  function checkActionType(type: Action['type']): boolean {
@@ -1,6 +1,7 @@
1
1
  import type { BaselineCorrectionZone } from '@zakodium/nmr-types';
2
2
  import type { Spectrum, ViewState } from '@zakodium/nmrium-core';
3
- import type { FileCollection, Source } from 'file-collection';
3
+ import type { Source } from 'file-collection';
4
+ import { FileCollection } from 'file-collection';
4
5
  import type { Draft } from 'immer';
5
6
  import { original, produce } from 'immer';
6
7
  import type { CorrelationData } from 'nmr-correlation';
@@ -114,7 +115,7 @@ export function getDefaultViewState(): ViewState {
114
115
  export const getInitialState = (): State => ({
115
116
  actionType: 'INITIALIZE_NMRIUM',
116
117
  sources: {},
117
- fileCollections: {},
118
+ aggregator: new FileCollection(),
118
119
  data: [],
119
120
  tempData: null,
120
121
  xDomain: [],
@@ -192,15 +193,20 @@ export interface State {
192
193
 
193
194
  /**
194
195
  * web source of data
195
- * Record key is identifier of the source (stored in spectra)
196
+ * Record key is an identifier of the source (stored in spectra)
197
+ *
198
+ * Is needed until we remove the support of the old nmrium format
196
199
  */
197
200
  sources: Record<string, Source>;
198
201
 
199
202
  /**
200
- * File collections of the loaded files
201
- * Record key is identifier of the fileCollection (stored in spectra)
203
+ * Aggregation of file collections used to load the data
204
+ * - external data sources (web-source, import jdx from url, ...)
205
+ * - multiples files open / drag and drop
206
+ *
207
+ * Each of them is separated in an uuid folder
202
208
  */
203
- fileCollections: Record<string, FileCollection>;
209
+ aggregator: FileCollection;
204
210
 
205
211
  /**
206
212
  * spectra list (1d and 2d)
@@ -669,10 +675,12 @@ function innerSpectrumReducer(draft: Draft<State>, action: Action) {
669
675
  return MoleculeActions.handlePredictSpectraFromMolecule(draft, action);
670
676
  case 'FLOAT_MOLECULE_OVER_SPECTRUM':
671
677
  return MoleculeActions.handleFloatMoleculeOverSpectrum(draft, action);
672
- case 'TOGGLE_MOLECULE_ATOM_NUMBER':
673
- return MoleculeActions.handleToggleMoleculeAtomsNumbers(draft, action);
678
+ case 'CHANGE_MOLECULE_ANNOTATION':
679
+ return MoleculeActions.handleChangeMoleculeAnnotation(draft, action);
674
680
  case 'CHANGE_FLOAT_MOLECULE_POSITION':
675
681
  return MoleculeActions.handleChangeFloatMoleculePosition(draft, action);
682
+ case 'TOGGLE_MOLECULE_LABEL':
683
+ return MoleculeActions.handleToggleMoleculeLabel(draft, action);
676
684
 
677
685
  case 'SET_CORRELATIONS_MF':
678
686
  return CorrelationsActions.handleSetMF(draft, action);
@@ -730,6 +738,11 @@ function innerSpectrumReducer(draft: Draft<State>, action: Action) {
730
738
  draft,
731
739
  action,
732
740
  );
741
+ case 'CHANGE_ASSIGNMENT_LABEL_BY_DIAIDS':
742
+ return RangesActions.handleChangeRangesAssignmentLabelsByDiaIds(
743
+ draft,
744
+ action,
745
+ );
733
746
 
734
747
  case 'SET_KEY_PREFERENCES':
735
748
  return PreferencesActions.handleSetKeyPreferences(draft, action);
@@ -1,10 +1,11 @@
1
1
  import type {
2
+ MoleculeView,
2
3
  NmriumState,
3
4
  SpectraColors,
4
5
  Spectrum,
5
6
  ViewState,
6
7
  } from '@zakodium/nmrium-core';
7
- import type { FileCollection } from 'file-collection';
8
+ import { FileCollection } from 'file-collection';
8
9
  import type { Draft } from 'immer';
9
10
  import { produce } from 'immer';
10
11
  import lodashMerge from 'lodash/merge.js';
@@ -24,6 +25,7 @@ import type { State } from '../Reducer.js';
24
25
  import { getDefaultViewState, getInitialState } from '../Reducer.js';
25
26
  import type { ActionType } from '../types/ActionType.js';
26
27
 
28
+ import { initMoleculeViewProperties } from './MoleculeActions.ts';
27
29
  import { changeSpectrumVerticalAlignment } from './PreferencesActions.js';
28
30
  import { setSpectraMetaInfo } from './SpectraActions.js';
29
31
  import { setActiveTab } from './ToolsActions.js';
@@ -31,15 +33,18 @@ import { setActiveTab } from './ToolsActions.js';
31
33
  //TODO use viewState type instead of any { view?: ViewState }
32
34
  interface InitiateProps {
33
35
  nmriumState: Partial<NmriumState>;
34
- fileCollections?: Map<string, FileCollection>;
36
+ aggregator: FileCollection;
35
37
  }
36
- interface InputProps extends InitiateProps {
38
+ interface InputProps extends Omit<InitiateProps, 'aggregator'> {
37
39
  containsNmrium?: boolean;
38
40
  usedColors?: UsedColors;
39
41
  parseMetaFileResult?: ParseResult<any> | null;
40
42
  resetSourceObject?: boolean;
41
43
  spectraColors?: SpectraColors;
42
44
  fileCollection?: FileCollection;
45
+ selectorRoot?: string;
46
+ aggregator?: FileCollection;
47
+ defaultMoleculeSettings?: MoleculeView;
43
48
  }
44
49
 
45
50
  type SetIsLoadingAction = ActionType<
@@ -92,6 +97,12 @@ function setCorrelation(draft: Draft<State>, correlations: CorrelationData) {
92
97
  }
93
98
  }
94
99
 
100
+ function isDataSourceDropFiles(
101
+ input: InputProps | InitiateProps,
102
+ ): input is InputProps {
103
+ return 'containsNmrium' in input;
104
+ }
105
+
95
106
  function setData(draft: Draft<State>, input: InputProps | InitiateProps) {
96
107
  const { data, view } = input.nmriumState || {
97
108
  data: { spectra: [], molecules: [], correlations: {} },
@@ -118,6 +129,7 @@ function setData(draft: Draft<State>, input: InputProps | InitiateProps) {
118
129
 
119
130
  if (view) {
120
131
  const defaultViewState = getDefaultViewState();
132
+
121
133
  draft.view = lodashMerge(defaultViewState, view);
122
134
  }
123
135
 
@@ -140,31 +152,46 @@ function setData(draft: Draft<State>, input: InputProps | InitiateProps) {
140
152
  }
141
153
  }
142
154
 
143
- updateFileCollections(draft, input);
155
+ if (input.aggregator) {
156
+ if ('forceInitialize' in input && input.forceInitialize) {
157
+ draft.aggregator = input.aggregator;
158
+ } else {
159
+ draft.aggregator = FileCollection.fromCollection(draft.aggregator);
160
+ draft.aggregator.appendFileCollection(input.aggregator, '');
161
+ }
162
+ }
163
+
164
+ if (
165
+ 'fileCollection' in input &&
166
+ input.fileCollection &&
167
+ 'selectorRoot' in input &&
168
+ input.selectorRoot
169
+ ) {
170
+ draft.aggregator = FileCollection.fromCollection(draft.aggregator);
171
+ draft.aggregator.appendFileCollection(
172
+ input.fileCollection,
173
+ input.selectorRoot,
174
+ );
175
+ }
144
176
 
145
- const fileCollectionId =
146
- 'fileCollection' in input
147
- ? sources?.at(-1)?.id || crypto.randomUUID()
148
- : undefined;
149
- const fileCollection =
150
- 'fileCollection' in input ? input.fileCollection : undefined;
177
+ const newMolecules = MoleculeManager.fromJSON(molecules, draft.molecules);
151
178
 
152
- draft.molecules = draft.molecules.concat(
153
- MoleculeManager.fromJSON(molecules, fileCollectionId, draft.molecules),
154
- );
179
+ draft.molecules = draft.molecules.concat(newMolecules);
180
+
181
+ if (isDataSourceDropFiles(input) && !input?.containsNmrium) {
182
+ const { defaultMoleculeSettings } = input;
183
+ for (const { id } of newMolecules) {
184
+ initMoleculeViewProperties(draft, { id, defaultMoleculeSettings });
185
+ }
186
+ }
155
187
 
156
188
  draft.data = draft.data.concat(
157
189
  initSpectra(spectra, {
158
190
  usedColors: draft.usedColors,
159
191
  molecules: draft.molecules,
160
192
  spectraColors,
161
- fileCollectionId,
162
193
  }),
163
194
  );
164
- if (fileCollection && fileCollectionId) {
165
- draft.fileCollections ??= {};
166
- draft.fileCollections[fileCollectionId] = fileCollection;
167
- }
168
195
  setCorrelation(draft, correlations);
169
196
 
170
197
  if (parseMetaFileResult) {
@@ -183,11 +210,10 @@ function initSpectra(
183
210
  usedColors: UsedColors;
184
211
  molecules: StateMoleculeExtended[];
185
212
  spectraColors: SpectraColors;
186
- fileCollectionId: string | undefined;
187
213
  },
188
214
  ) {
189
215
  const spectra: any = [];
190
- const { usedColors, molecules, spectraColors, fileCollectionId } = options;
216
+ const { usedColors, molecules, spectraColors } = options;
191
217
  for (const spectrum of inputSpectra) {
192
218
  const { info } = spectrum;
193
219
  if (info.dimension === 1) {
@@ -196,14 +222,13 @@ function initSpectra(
196
222
  usedColors,
197
223
  molecules,
198
224
  colors: spectraColors.oneDimension,
199
- fileCollectionId,
200
225
  }),
201
226
  );
202
227
  } else if (info.dimension === 2) {
203
228
  spectra.push(
204
229
  initiateDatum2D(
205
230
  { ...spectrum },
206
- { usedColors, colors: spectraColors.twoDimensions, fileCollectionId },
231
+ { usedColors, colors: spectraColors.twoDimensions },
207
232
  ),
208
233
  );
209
234
  }
@@ -228,21 +253,6 @@ function setPreferences(draft: Draft<State>, data: ViewState) {
228
253
  }
229
254
  }
230
255
 
231
- function updateFileCollections(
232
- draft: Draft<State>,
233
- payload: Pick<InitiateProps, 'fileCollections'>,
234
- ) {
235
- const fileCollections = payload.fileCollections;
236
- if (!fileCollections) return;
237
-
238
- if (fileCollections.size > 0) {
239
- draft.fileCollections ??= {};
240
- }
241
- for (const [id, fc] of fileCollections) {
242
- draft.fileCollections[id] = fc;
243
- }
244
- }
245
-
246
256
  function initData(
247
257
  draft: Draft<State>,
248
258
  action: LoadDropFilesAction | InitiateAction,
@@ -272,7 +282,10 @@ function initData(
272
282
  initialDraft.actionType = action.type;
273
283
  });
274
284
  } else {
275
- updateFileCollections(draft, action.payload);
285
+ if (action.payload.aggregator) {
286
+ draft.aggregator = FileCollection.fromCollection(draft.aggregator);
287
+ draft.aggregator.appendFileCollection(action.payload.aggregator, '');
288
+ }
276
289
  if (view) {
277
290
  const defaultViewState = getDefaultViewState();
278
291
  draft.view = lodashMerge(defaultViewState, view);