nmrium 1.10.1 → 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 (147) 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/EventsTrackers/KeysListenerTracker.js +3 -3
  17. package/lib/component/EventsTrackers/KeysListenerTracker.js.map +1 -1
  18. package/lib/component/elements/NextPrev.d.ts.map +1 -1
  19. package/lib/component/elements/NextPrev.js +23 -4
  20. package/lib/component/elements/NextPrev.js.map +1 -1
  21. package/lib/component/elements/export/utilities/exportOptionValidationSchema.d.ts +1 -1
  22. package/lib/component/hooks/useExport.d.ts +7 -7
  23. package/lib/component/hooks/useExport.d.ts.map +1 -1
  24. package/lib/component/hooks/useExport.js +22 -42
  25. package/lib/component/hooks/useExport.js.map +1 -1
  26. package/lib/component/hooks/useSetActiveSpectrumAction.d.ts.map +1 -1
  27. package/lib/component/hooks/useSetActiveSpectrumAction.js +3 -1
  28. package/lib/component/hooks/useSetActiveSpectrumAction.js.map +1 -1
  29. package/lib/component/loader/useLoadFiles.d.ts.map +1 -1
  30. package/lib/component/loader/useLoadFiles.js +81 -86
  31. package/lib/component/loader/useLoadFiles.js.map +1 -1
  32. package/lib/component/main/ErrorOverlay.d.ts.map +1 -1
  33. package/lib/component/main/ErrorOverlay.js +6 -1
  34. package/lib/component/main/ErrorOverlay.js.map +1 -1
  35. package/lib/component/main/InnerNMRiumContents.d.ts.map +1 -1
  36. package/lib/component/main/InnerNMRiumContents.js +1 -2
  37. package/lib/component/main/InnerNMRiumContents.js.map +1 -1
  38. package/lib/component/main/NMRiumViewer.js +1 -1
  39. package/lib/component/main/NMRiumViewer.js.map +1 -1
  40. package/lib/component/main/NMRiumViewerWrapper.d.ts.map +1 -1
  41. package/lib/component/main/NMRiumViewerWrapper.js +11 -3
  42. package/lib/component/main/NMRiumViewerWrapper.js.map +1 -1
  43. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.d.ts +6 -0
  44. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.d.ts.map +1 -0
  45. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.js +127 -0
  46. package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.js.map +1 -0
  47. package/lib/component/modal/SaveAsModal.d.ts.map +1 -1
  48. package/lib/component/modal/SaveAsModal.js +4 -8
  49. package/lib/component/modal/SaveAsModal.js.map +1 -1
  50. package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
  51. package/lib/component/modal/changeSum/ChangeSumModal.js.map +1 -1
  52. package/lib/component/modal/changeSum/SelectMolecule.js +4 -1
  53. package/lib/component/modal/changeSum/SelectMolecule.js.map +1 -1
  54. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts.map +1 -1
  55. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +71 -16
  56. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js.map +1 -1
  57. package/lib/component/panels/Panels.d.ts +0 -9
  58. package/lib/component/panels/Panels.d.ts.map +1 -1
  59. package/lib/component/panels/Panels.js +1 -29
  60. package/lib/component/panels/Panels.js.map +1 -1
  61. package/lib/component/panels/hooks/useTogglePanel.d.ts.map +1 -1
  62. package/lib/component/panels/hooks/useTogglePanel.js +4 -3
  63. package/lib/component/panels/hooks/useTogglePanel.js.map +1 -1
  64. package/lib/component/reducer/actions/LoadAction.d.ts.map +1 -1
  65. package/lib/component/reducer/actions/LoadAction.js +6 -0
  66. package/lib/component/reducer/actions/LoadAction.js.map +1 -1
  67. package/lib/component/reducer/actions/MoleculeActions.d.ts +23 -1
  68. package/lib/component/reducer/actions/MoleculeActions.d.ts.map +1 -1
  69. package/lib/component/reducer/actions/MoleculeActions.js +2 -2
  70. package/lib/component/reducer/actions/MoleculeActions.js.map +1 -1
  71. package/lib/component/reducer/actions/RangesActions.js +1 -1
  72. package/lib/component/reducer/actions/RangesActions.js.map +1 -1
  73. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  74. package/lib/component/reducer/actions/SpectraActions.d.ts.map +1 -1
  75. package/lib/component/reducer/actions/SpectraActions.js +2 -2
  76. package/lib/component/reducer/actions/SpectraActions.js.map +1 -1
  77. package/lib/component/reducer/preferences/actions/analyzeSpectra.d.ts +2 -1
  78. package/lib/component/reducer/preferences/actions/analyzeSpectra.d.ts.map +1 -1
  79. package/lib/component/reducer/preferences/actions/analyzeSpectra.js +10 -0
  80. package/lib/component/reducer/preferences/actions/analyzeSpectra.js.map +1 -1
  81. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.d.ts +4 -0
  82. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.d.ts.map +1 -0
  83. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.js +9 -0
  84. package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.js.map +1 -0
  85. package/lib/component/reducer/preferences/preferencesReducer.d.ts +8 -1
  86. package/lib/component/reducer/preferences/preferencesReducer.d.ts.map +1 -1
  87. package/lib/component/reducer/preferences/preferencesReducer.js +6 -1
  88. package/lib/component/reducer/preferences/preferencesReducer.js.map +1 -1
  89. package/lib/component/toolbar/ToolBar.d.ts.map +1 -1
  90. package/lib/component/toolbar/ToolBar.js +6 -7
  91. package/lib/component/toolbar/ToolBar.js.map +1 -1
  92. package/lib/component/toolbar/toolbarMenu.d.ts +5 -1
  93. package/lib/component/toolbar/toolbarMenu.d.ts.map +1 -1
  94. package/lib/component/toolbar/toolbarMenu.js +1 -1
  95. package/lib/component/toolbar/toolbarMenu.js.map +1 -1
  96. package/lib/component/utility/export.d.ts +2 -1
  97. package/lib/component/utility/export.d.ts.map +1 -1
  98. package/lib/component/utility/export.js +5 -1
  99. package/lib/component/utility/export.js.map +1 -1
  100. package/lib/data/data1d/multipleSpectraAnalysis.d.ts +1 -0
  101. package/lib/data/data1d/multipleSpectraAnalysis.d.ts.map +1 -1
  102. package/lib/data/data1d/multipleSpectraAnalysis.js +14 -0
  103. package/lib/data/data1d/multipleSpectraAnalysis.js.map +1 -1
  104. package/lib/data/data2d/Spectrum2D/contours.d.ts.map +1 -1
  105. package/lib/data/data2d/Spectrum2D/contours.js +13 -6
  106. package/lib/data/data2d/Spectrum2D/contours.js.map +1 -1
  107. package/lib/data/molecules/MoleculeManager.d.ts +6 -1
  108. package/lib/data/molecules/MoleculeManager.d.ts.map +1 -1
  109. package/lib/data/molecules/MoleculeManager.js +3 -2
  110. package/lib/data/molecules/MoleculeManager.js.map +1 -1
  111. package/lib/versionInfo.js +1 -1
  112. package/package.json +36 -36
  113. package/src/component/1d/BrushTracker1D.tsx +8 -0
  114. package/src/component/1d/FloatPublicationString.tsx +0 -1
  115. package/src/component/1d/FloatingRanges.tsx +0 -1
  116. package/src/component/1d/inset/DraggableInset.tsx +0 -1
  117. package/src/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.tsx +11 -2
  118. package/src/component/EventsTrackers/KeysListenerTracker.tsx +3 -3
  119. package/src/component/elements/NextPrev.tsx +28 -4
  120. package/src/component/hooks/useExport.tsx +34 -64
  121. package/src/component/hooks/useSetActiveSpectrumAction.ts +3 -2
  122. package/src/component/loader/useLoadFiles.ts +134 -111
  123. package/src/component/main/ErrorOverlay.tsx +11 -2
  124. package/src/component/main/InnerNMRiumContents.tsx +6 -9
  125. package/src/component/main/NMRiumViewer.tsx +2 -2
  126. package/src/component/main/NMRiumViewerWrapper.tsx +14 -6
  127. package/src/component/modal/MoleculeAutoLabelsDatabaseModal.tsx +219 -0
  128. package/src/component/modal/SaveAsModal.tsx +14 -41
  129. package/src/component/modal/changeSum/ChangeSumModal.tsx +1 -1
  130. package/src/component/modal/changeSum/SelectMolecule.tsx +23 -23
  131. package/src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx +94 -15
  132. package/src/component/panels/Panels.tsx +1 -53
  133. package/src/component/panels/hooks/useTogglePanel.ts +4 -3
  134. package/src/component/reducer/actions/LoadAction.ts +15 -1
  135. package/src/component/reducer/actions/MoleculeActions.ts +4 -2
  136. package/src/component/reducer/actions/RangesActions.ts +1 -1
  137. package/src/component/reducer/actions/SpectraActions.ts +6 -2
  138. package/src/component/reducer/preferences/actions/analyzeSpectra.ts +16 -0
  139. package/src/component/reducer/preferences/actions/toggleOpenSplitPanel.ts +18 -0
  140. package/src/component/reducer/preferences/preferencesReducer.ts +22 -1
  141. package/src/component/toolbar/ToolBar.tsx +9 -9
  142. package/src/component/toolbar/toolbarMenu.tsx +13 -2
  143. package/src/component/utility/export.ts +6 -0
  144. package/src/data/data1d/multipleSpectraAnalysis.ts +20 -0
  145. package/src/data/data2d/Spectrum2D/contours.ts +16 -6
  146. package/src/data/molecules/MoleculeManager.ts +7 -2
  147. package/src/versionInfo.ts +1 -1
@@ -451,6 +451,14 @@ export function BrushTracker1D({ children }: Required<PropsWithChildren>) {
451
451
  }
452
452
  break;
453
453
  }
454
+ case 'multipleSpectraAnalysis': {
455
+ dispatchPreferences({
456
+ type: 'CUT_SPECTRA_ANALYSIS',
457
+ payload: { x: xPPM, nucleus: activeTab },
458
+ });
459
+
460
+ break;
461
+ }
454
462
  case 'phaseCorrection':
455
463
  dispatch({
456
464
  type: 'SET_ONE_DIMENSION_PIVOT_POINT',
@@ -269,7 +269,6 @@ function DraggablePublicationString(props: DraggablePublicationStringProps) {
269
269
  dragHandleClassName="handle"
270
270
  enableUserSelectHack={false}
271
271
  bounds={`#${viewerRef.id}`}
272
- style={{ zIndex: 1 }}
273
272
  onDragStart={() => setIsMoveActive(true)}
274
273
  onResize={(e, dir, eRef, size, position) =>
275
274
  handleResize({ ...size, ...position })
@@ -301,7 +301,6 @@ function DraggableRanges(props: DraggablePublicationStringProps) {
301
301
  dragHandleClassName="handle"
302
302
  enableUserSelectHack={false}
303
303
  bounds={`#${viewerRef.id}`}
304
- style={{ zIndex: 1 }}
305
304
  onDragStart={() => setIsMoveActive(true)}
306
305
  onResize={(e, dir, eRef, size, position) =>
307
306
  handleResize({ ...size, ...position })
@@ -189,7 +189,6 @@ export function DraggableInset(props: Inset) {
189
189
  dragHandleClassName="handle"
190
190
  enableUserSelectHack={false}
191
191
  bounds={`#${viewerRef.id}`}
192
- style={{ zIndex: 1 }}
193
192
  onDragStart={() => setIsMoveActive(true)}
194
193
  onResize={(e, dir, eRef, size, position) =>
195
194
  handleResize({ ...size, ...position })
@@ -40,6 +40,10 @@ const ReactRnd = styled(Rnd)`
40
40
  background-color: white;
41
41
  border: 1px solid #ebecf1;
42
42
  }
43
+
44
+ form {
45
+ z-index: 1;
46
+ }
43
47
  `;
44
48
 
45
49
  export function DraggableStructure(props: DraggableStructureProps) {
@@ -165,7 +169,6 @@ export function DraggableStructure(props: DraggableStructureProps) {
165
169
  dragHandleClassName="handle"
166
170
  enableUserSelectHack={false}
167
171
  bounds={`#${viewerRef.id}`}
168
- style={{ zIndex: 1 }}
169
172
  className="draggable-molecule"
170
173
  onDragStart={() => setIsMoveActive(true)}
171
174
  onResizeStop={(e, dir, eRef, { width, height }) =>
@@ -194,7 +197,13 @@ export function DraggableStructure(props: DraggableStructureProps) {
194
197
  >
195
198
  <div
196
199
  className="content"
197
- onDoubleClick={() => openMoleculeEditor(molecule)}
200
+ onDoubleClick={(e) => {
201
+ if ((e.target as HTMLElement).closest('form')) {
202
+ return;
203
+ }
204
+
205
+ openMoleculeEditor(molecule);
206
+ }}
198
207
  >
199
208
  <ResponsiveChart>
200
209
  {({ width, height }) => {
@@ -51,7 +51,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
51
51
  changeDisplayViewModeHandler,
52
52
  } = useToolsFunctions();
53
53
 
54
- const { saveAsJSONHandler } = useExport();
54
+ const { defaultSaveAsHandler } = useExport();
55
55
  const isToolVisible = useCheckToolsVisibility();
56
56
 
57
57
  const { highlight, remove } = useHighlightData();
@@ -428,7 +428,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
428
428
  break;
429
429
  case 's':
430
430
  if (isToolVisible('exportAs')) {
431
- saveAsJSONHandler();
431
+ defaultSaveAsHandler();
432
432
  e.preventDefault();
433
433
  }
434
434
  break;
@@ -488,7 +488,7 @@ function KeysListenerTracker(props: KeysListenerTrackerProps) {
488
488
  nuclei,
489
489
  openLoader,
490
490
  openSaveAsDialog,
491
- saveAsJSONHandler,
491
+ defaultSaveAsHandler,
492
492
  toaster,
493
493
  ],
494
494
  );
@@ -1,7 +1,6 @@
1
1
  import styled from '@emotion/styled';
2
2
  import type { CSSProperties, ReactElement } from 'react';
3
- import { Children } from 'react';
4
- import { useResizeObserver } from 'react-d3-utils';
3
+ import { Children, useLayoutEffect, useRef, useState } from 'react';
5
4
  import { FaAngleLeft } from 'react-icons/fa';
6
5
 
7
6
  type Direction = 'right' | 'left';
@@ -90,10 +89,35 @@ interface NextPrevProps {
90
89
 
91
90
  export function NextPrev(props: NextPrevProps) {
92
91
  const { children, index = 0, onChange = () => null, style = {} } = props;
93
- const [ref, { width } = { width: 0 }] = useResizeObserver();
94
92
  const slidersCount = Children.count(children);
95
93
  const lastIndex = slidersCount > 0 ? slidersCount - 1 : 0;
96
94
  const activeIndex = Math.min(index, lastIndex);
95
+ const containerRef = useRef<HTMLDivElement>(null);
96
+
97
+ const [width, setWidth] = useState(0);
98
+
99
+ useLayoutEffect(() => {
100
+ const container = containerRef.current;
101
+ if (!container) return;
102
+
103
+ const observer = new ResizeObserver((entries) => {
104
+ for (const entry of entries) {
105
+ const newWidth = entry.contentRect.width;
106
+ if (newWidth > 0) {
107
+ setWidth(newWidth);
108
+ }
109
+ }
110
+ });
111
+
112
+ observer.observe(container);
113
+
114
+ const rect = container.getBoundingClientRect();
115
+ if (rect.width > 0) {
116
+ setWidth(rect.width);
117
+ }
118
+
119
+ return () => observer.disconnect();
120
+ }, []);
97
121
 
98
122
  function nextHandler() {
99
123
  if (index < lastIndex) {
@@ -113,7 +137,7 @@ export function NextPrev(props: NextPrevProps) {
113
137
  const slidersWidth = width * slidersCount;
114
138
 
115
139
  return (
116
- <Container ref={ref}>
140
+ <Container ref={containerRef}>
117
141
  <TransformController
118
142
  translation={translation}
119
143
  slidersWidth={slidersWidth}
@@ -1,6 +1,6 @@
1
+ import type { NmriumState } from '@zakodium/nmrium-core';
1
2
  import { useCallback } from 'react';
2
3
 
3
- import type { ExportOptions } from '../../data/SpectraManager.js';
4
4
  import { toJSON } from '../../data/SpectraManager.js';
5
5
  import { useChartData } from '../context/ChartContext.js';
6
6
  import { useCore } from '../context/CoreContext.js';
@@ -9,17 +9,21 @@ import { useToaster } from '../context/ToasterContext.js';
9
9
  import {
10
10
  browserNotSupportedErrorToast,
11
11
  copyPNGToClipboard,
12
- exportAsJsonBlob,
13
12
  exportAsPng,
14
13
  exportAsSVG,
15
14
  } from '../utility/export.js';
16
15
  import { saveAs } from '../utility/save_as.ts';
17
16
 
18
- interface SaveOptions {
19
- include: ExportOptions;
17
+ export interface SaveOptions {
18
+ include: {
19
+ settings: boolean;
20
+ view: boolean;
21
+ dataType:
22
+ | 'NO_DATA'
23
+ | 'SELF_CONTAINED'
24
+ | 'SELF_CONTAINED_EXTERNAL_DATASOURCE';
25
+ };
20
26
  name: string;
21
- compressed: boolean;
22
- pretty: boolean;
23
27
  }
24
28
 
25
29
  export function useExport() {
@@ -28,75 +32,29 @@ export function useExport() {
28
32
  const preferencesState = usePreferences();
29
33
  const core = useCore();
30
34
 
31
- const saveAsJSONHandler = useCallback(
32
- (spaceIndent = 0, isCompressed = true) => {
33
- const hideLoading = toaster.showLoading({
34
- message: 'Exporting as NMRium process in progress',
35
- });
36
- setTimeout(async () => {
37
- try {
38
- const name = state.data[0]?.info?.name || 'experiment';
39
- const exportedData = toJSON(core, state, preferencesState, {
40
- exportTarget: 'nmrium',
41
- view: true,
42
- });
43
-
44
- const blob = await exportAsJsonBlob(
45
- exportedData,
46
- name,
47
- spaceIndent,
48
- isCompressed,
49
- );
50
- saveAs({ blob, name, extension: '.nmrium' });
51
- } catch (error) {
52
- toaster.show({
53
- intent: 'danger',
54
- message: `Export failed due to an unexpected error: ${(error as Error)?.message || 'Unknown error'}`,
55
- });
56
- reportError(error);
57
- } finally {
58
- hideLoading();
59
- }
60
- }, 0);
61
- },
62
- [core, preferencesState, state, toaster],
63
- );
64
-
65
35
  const saveHandler = useCallback(
66
36
  (options: SaveOptions) => {
67
37
  async function handler() {
68
- const { pretty, compressed, include } = options;
69
38
  const name = options.name || 'experiment';
70
- const exportArchive =
71
- include.dataType?.startsWith('SELF_CONTAINED') ?? false;
39
+ const include = options.include;
72
40
 
73
41
  const hideLoading = toaster.showLoading({
74
- message: `Exporting as ${name}.nmrium process in progress`,
42
+ message: `Exporting as ${name}.nmrium.zip process in progress`,
75
43
  });
76
44
  setTimeout(async () => {
77
45
  try {
78
- const exportedData = toJSON(core, state, preferencesState, {
79
- ...include,
46
+ const nmriumState = toJSON(core, state, preferencesState, {
47
+ serialize: false,
80
48
  exportTarget: 'nmrium',
81
- });
82
- const spaceIndent = pretty || exportArchive ? 2 : 0;
83
- const blob = await exportAsJsonBlob(
84
- exportedData,
85
- name,
86
- spaceIndent,
87
- compressed && !exportArchive,
88
- );
89
-
90
- if (!exportArchive) {
91
- return saveAs({ blob, name, extension: '.nmrium' });
92
- }
93
-
49
+ }) as NmriumState;
94
50
  const archive = await core.serializeNmriumArchive({
95
- molecules: state.molecules,
96
- spectra: state.data,
51
+ state: nmriumState,
97
52
  aggregator: state.aggregator,
98
- includeData: options.include.dataType === 'SELF_CONTAINED',
99
- serializedState: blob,
53
+ includeData: include.dataType !== 'NO_DATA',
54
+ externalData:
55
+ include.dataType === 'SELF_CONTAINED' ? 'embedded' : 'linked',
56
+ includeSettings: include.settings,
57
+ includeView: include.view,
100
58
  });
101
59
  const zipBlob = new Blob([archive], {
102
60
  type: 'chemical/x-nmrium+zip',
@@ -119,8 +77,20 @@ export function useExport() {
119
77
  [core, preferencesState, state, toaster],
120
78
  );
121
79
 
80
+ const defaultName = state.data[0]?.info?.name || 'experiment';
81
+ const defaultSaveAsHandler = useCallback(() => {
82
+ saveHandler({
83
+ name: defaultName,
84
+ include: {
85
+ dataType: 'SELF_CONTAINED',
86
+ view: true,
87
+ settings: false,
88
+ },
89
+ });
90
+ }, [saveHandler, defaultName]);
91
+
122
92
  return {
123
- saveAsJSONHandler,
93
+ defaultSaveAsHandler,
124
94
  saveHandler,
125
95
  };
126
96
  }
@@ -1,10 +1,11 @@
1
+ import { useChartData } from '../context/ChartContext.tsx';
1
2
  import { useDispatch } from '../context/DispatchContext.js';
2
3
  import type { EventModifierKeys } from '../context/KeyModifierContext.js';
3
4
  import { getModifiers } from '../context/KeyModifierContext.js';
4
5
 
5
6
  export function useSetActiveSpectrumAction() {
6
7
  const dispatch = useDispatch();
7
-
8
+ const { data: spectra } = useChartData();
8
9
  function setActiveSpectrum(event: EventModifierKeys, id: string) {
9
10
  setTimeout(() => {
10
11
  const { ctrlKey, shiftKey } = getModifiers(event);
@@ -13,7 +14,7 @@ export function useSetActiveSpectrumAction() {
13
14
  }]`;
14
15
  dispatch({
15
16
  type: 'CHANGE_ACTIVE_SPECTRUM',
16
- payload: { modifier, id },
17
+ payload: { modifier, id, sortedSpectra: spectra },
17
18
  });
18
19
  }, 0);
19
20
  }
@@ -1,16 +1,19 @@
1
- import type { NmriumState, ParsingOptions } from '@zakodium/nmrium-core';
1
+ import type { ParsingOptions } from '@zakodium/nmrium-core';
2
+ import type { FileItem } from 'file-collection';
2
3
  import { FileCollection } from 'file-collection';
3
- import type { ParseResult } from 'papaparse';
4
4
  import { useCallback } from 'react';
5
5
 
6
6
  import { isMetaFile, parseMetaFile } from '../../data/parseMeta/index.js';
7
7
  import { useCore } from '../context/CoreContext.js';
8
+ import type { Action } from '../context/DispatchContext.js';
8
9
  import { useDispatch } from '../context/DispatchContext.js';
9
10
  import { useLogger } from '../context/LoggerContext.js';
10
11
  import { usePreferences } from '../context/PreferencesContext.js';
11
12
  import { useToaster } from '../context/ToasterContext.js';
12
13
  import useCheckExperimentalFeature from '../hooks/useCheckExperimentalFeature.js';
13
14
 
15
+ type Payload = Extract<Action, { type: 'LOAD_DROP_FILES' }>['payload'];
16
+
14
17
  export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
15
18
  const dispatch = useDispatch();
16
19
  const preferences = usePreferences();
@@ -21,110 +24,116 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
21
24
  const experimentalFeatures = useCheckExperimentalFeature();
22
25
  const core = useCore();
23
26
 
24
- return useCallback(
25
- (files: File[]) => {
26
- dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: true } });
27
+ const dispatchPayload = useCallback(
28
+ (payload: Omit<Payload, 'spectraColors' | 'defaultMoleculeSettings'>) => {
29
+ const { nmriumState } = payload;
30
+ const { spectraColors, defaultMoleculeSettings } = workspacePreferences;
27
31
 
28
- async function loadFiles(files: File[]) {
29
- if (
30
- onOpenMetaInformation &&
31
- files.length === 1 &&
32
- isMetaFile(files[0])
33
- ) {
34
- onOpenMetaInformation(files[0]);
35
- return;
36
- }
37
-
38
- const nmriumArchiveFiles: File[] = [];
39
- const otherFiles: File[] = [];
40
- let nmriumState: Partial<NmriumState>;
41
- let containsNmrium: boolean;
42
- let parseMetaFileResult: ParseResult<any> | null = null;
43
- const { onLoadProcessing, spectraColors, defaultMoleculeSettings } =
44
- workspacePreferences;
45
- const { nmrLoaders: selector } = preferences.current;
46
-
47
- const parsingOptions: Partial<ParsingOptions> = {
48
- selector,
49
- logger: logger.child({ context: 'nmr-processing' }),
50
- onLoadProcessing,
51
- experimentalFeatures,
52
- };
53
-
54
- let aggregator: FileCollection | undefined;
55
- let fileCollection: FileCollection | undefined;
56
- let selectorRoot: string | undefined;
57
- let resetSourceObject = false;
58
-
59
- if (files.length === 1 && files[0].name.endsWith('.nmrium.zip')) {
60
- const [state, ium] = await core.readNMRiumArchive(
61
- files[0].stream(),
62
- parsingOptions,
63
- );
64
- nmriumState = state;
65
- containsNmrium = true;
66
- aggregator = ium;
67
- } else {
68
- for (const file of files) {
69
- if (file.name.endsWith('.nmrium.zip')) {
70
- nmriumArchiveFiles.push(file);
71
- } else {
72
- otherFiles.push(file);
73
- }
74
- }
75
-
76
- if (nmriumArchiveFiles.length > 0) {
77
- await Promise.all(
78
- nmriumArchiveFiles.map((file) => loadFiles([file])),
79
- );
80
- }
81
-
82
- fileCollection = await new FileCollection().appendFileList(
83
- otherFiles,
84
- );
85
-
86
- const metaFile = Object.values(fileCollection.files).find((file) =>
87
- isMetaFile(file),
88
- );
89
-
90
- if (metaFile) {
91
- parseMetaFileResult = await parseMetaFile(metaFile);
92
- }
93
- ({ nmriumState, containsNmrium, selectorRoot } = await core.read(
94
- fileCollection,
95
- parsingOptions,
96
- ));
97
- if (containsNmrium) {
98
- resetSourceObject = true;
99
- }
100
- }
101
-
102
- if (nmriumState.settings) {
103
- dispatchPreferences({
104
- type: 'SET_WORKSPACE',
105
- payload: {
106
- data: nmriumState.settings,
107
- workspaceSource: 'nmriumFile',
108
- },
109
- });
110
- }
111
- dispatch({
112
- type: 'LOAD_DROP_FILES',
32
+ if (nmriumState.settings) {
33
+ dispatchPreferences({
34
+ type: 'SET_WORKSPACE',
113
35
  payload: {
114
- nmriumState,
115
- containsNmrium,
116
- parseMetaFileResult,
117
- spectraColors,
118
- aggregator,
119
- fileCollection,
120
- selectorRoot,
121
- resetSourceObject,
122
- defaultMoleculeSettings,
36
+ data: nmriumState.settings,
37
+ workspaceSource: 'nmriumFile',
123
38
  },
124
39
  });
125
40
  }
41
+ dispatch({
42
+ type: 'LOAD_DROP_FILES',
43
+ payload: { ...payload, spectraColors, defaultMoleculeSettings },
44
+ });
45
+ },
46
+ [dispatch, dispatchPreferences, workspacePreferences],
47
+ );
48
+
49
+ const loadNmriumArchives = useCallback(
50
+ async (file: File, parsingOptions: Partial<ParsingOptions>) => {
51
+ const [nmriumState, aggregator] = await core.readNMRiumArchive(
52
+ file.stream(),
53
+ parsingOptions,
54
+ );
55
+
56
+ dispatchPayload({ nmriumState, aggregator, containsNmrium: true });
57
+ },
58
+ [core, dispatchPayload],
59
+ );
60
+
61
+ const loadFileCollection = useCallback(
62
+ async (
63
+ fileCollection: FileCollection,
64
+ metaFile: FileItem | undefined,
65
+ parsingOptions: Partial<ParsingOptions>,
66
+ ) => {
67
+ const parseMetaFileResult = metaFile
68
+ ? await parseMetaFile(metaFile)
69
+ : null;
70
+ const {
71
+ nmriumState,
72
+ containsNmrium,
73
+ selectorRoot,
74
+ fileCollection: sanitizedCollection,
75
+ } = await core.read(fileCollection, parsingOptions);
76
+ const resetSourceObject = containsNmrium;
77
+
78
+ dispatchPayload({
79
+ nmriumState,
80
+ containsNmrium,
81
+ parseMetaFileResult,
82
+ fileCollection: sanitizedCollection,
83
+ selectorRoot,
84
+ resetSourceObject,
85
+ });
86
+ },
87
+ [core, dispatchPayload],
88
+ );
89
+
90
+ const currentPreferences = preferences.current;
91
+ const loadUserFiles = useCallback(
92
+ async (files: File[]) => {
93
+ if (onOpenMetaInformation && files.length === 1 && isMetaFile(files[0])) {
94
+ onOpenMetaInformation(files[0]);
95
+ return;
96
+ }
97
+
98
+ const { onLoadProcessing } = workspacePreferences;
99
+ const { nmrLoaders: selector } = currentPreferences;
100
+
101
+ const parsingOptions: Partial<ParsingOptions> = {
102
+ selector,
103
+ logger: logger.child({ context: 'nmr-processing' }),
104
+ onLoadProcessing,
105
+ experimentalFeatures,
106
+ };
107
+
108
+ const groupedFiles = await groupFiles(files);
109
+ const { nmriumArchiveFiles, fileCollection, metaFile } = groupedFiles;
110
+
111
+ if (nmriumArchiveFiles.length > 0) {
112
+ await Promise.all(
113
+ nmriumArchiveFiles.map((file) =>
114
+ loadNmriumArchives(file, parsingOptions),
115
+ ),
116
+ );
117
+ }
118
+
119
+ await loadFileCollection(fileCollection, metaFile, parsingOptions);
120
+ },
121
+ [
122
+ experimentalFeatures,
123
+ loadFileCollection,
124
+ loadNmriumArchives,
125
+ logger,
126
+ onOpenMetaInformation,
127
+ currentPreferences,
128
+ workspacePreferences,
129
+ ],
130
+ );
126
131
 
127
- loadFiles(files)
132
+ return useCallback(
133
+ (files: File[]) => {
134
+ dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: true } });
135
+
136
+ loadUserFiles(files)
128
137
  .catch((error: unknown) => {
129
138
  toaster.show({ message: (error as Error).message, intent: 'danger' });
130
139
  logger.error(error as Error);
@@ -133,16 +142,30 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
133
142
  dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: false } });
134
143
  });
135
144
  },
136
- [
137
- core,
138
- dispatch,
139
- dispatchPreferences,
140
- experimentalFeatures,
141
- logger,
142
- onOpenMetaInformation,
143
- preferences,
144
- toaster,
145
- workspacePreferences,
146
- ],
145
+ [dispatch, loadUserFiles, logger, toaster],
146
+ );
147
+ }
148
+
149
+ async function groupFiles(files: File[]) {
150
+ const nmriumArchiveFiles: File[] = [];
151
+ const otherFiles: File[] = [];
152
+
153
+ for (const file of files) {
154
+ // eslint-disable-next-line no-await-in-loop
155
+ const header = await file.slice(0, 128).arrayBuffer();
156
+
157
+ if (FileCollection.isIum(header, 'chemical/x-nmrium+zip')) {
158
+ nmriumArchiveFiles.push(file);
159
+ continue;
160
+ }
161
+
162
+ otherFiles.push(file);
163
+ }
164
+
165
+ const fileCollection = await new FileCollection().appendFileList(otherFiles);
166
+ const metaFile = Object.values(fileCollection.files).find((file) =>
167
+ isMetaFile(file),
147
168
  );
169
+
170
+ return { nmriumArchiveFiles, fileCollection, metaFile };
148
171
  }
@@ -1,4 +1,5 @@
1
1
  import styled from '@emotion/styled';
2
+ import type { ReactNode } from 'react';
2
3
  import type { FallbackProps } from 'react-error-boundary';
3
4
 
4
5
  const WrongP = styled.p`
@@ -19,12 +20,20 @@ const Details = styled.details`
19
20
  `;
20
21
 
21
22
  export default function ErrorOverlay(props: FallbackProps) {
23
+ const error = props.error;
24
+ const message =
25
+ error && typeof error === 'object' && 'message' in error
26
+ ? error.message
27
+ : null;
28
+ const stack =
29
+ error && typeof error === 'object' && 'stack' in error ? error.stack : null;
30
+
22
31
  return (
23
32
  <div style={{ margin: 25 }}>
24
33
  <WrongP>Something went wrong.</WrongP>
25
34
  <Details>
26
- <p style={{ textDecoration: 'underline' }}>{props.error.message}</p>
27
- {props.error.stack}
35
+ <p style={{ textDecoration: 'underline' }}>{message as ReactNode}</p>
36
+ {stack as ReactNode}
28
37
  </Details>
29
38
  </div>
30
39
  );
@@ -13,7 +13,6 @@ import { ExportManagerController } from '../elements/export/ExportManager.js';
13
13
  import { PrintContent } from '../elements/print/PrintContent.js';
14
14
  import { Header } from '../header/Header.js';
15
15
  import DropZone from '../loader/DropZone.js';
16
- import { PanelOpenProviderProvider } from '../panels/Panels.js';
17
16
  import { PanelsBar } from '../panels/PanelsBar.js';
18
17
  import ToolBar from '../toolbar/ToolBar.js';
19
18
 
@@ -145,14 +144,12 @@ export function InnerNMRiumContents(props: InnerNMRiumContentsProps) {
145
144
  >
146
145
  <KeysListenerTracker mainDivRef={mainDivRef} />
147
146
 
148
- <PanelOpenProviderProvider>
149
- <ToolBar />
150
- <NMRiumViewerWrapper
151
- viewerRef={viewerRef}
152
- emptyText={emptyText}
153
- />
154
- <PanelsBar />
155
- </PanelOpenProviderProvider>
147
+ <ToolBar />
148
+ <NMRiumViewerWrapper
149
+ viewerRef={viewerRef}
150
+ emptyText={emptyText}
151
+ />
152
+ <PanelsBar />
156
153
  <div
157
154
  ref={elementsWrapperRef}
158
155
  key={String(isFullScreen)}
@@ -91,11 +91,11 @@ export function NMRiumViewer(props: NMRiumViewerProps) {
91
91
  ...style,
92
92
  }}
93
93
  >
94
+ <Viewer emptyText={emptyText} />
94
95
  <FloatingRanges />
95
96
  <FloatPublicationString />
96
- <FloatMolecules />
97
97
  <SpectraInsets />
98
- <Viewer emptyText={emptyText} />
98
+ <FloatMolecules />
99
99
  </div>
100
100
  );
101
101
  }