nmrium 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/component/1d/BrushTracker1D.d.ts.map +1 -1
- package/lib/component/1d/BrushTracker1D.js +7 -0
- package/lib/component/1d/BrushTracker1D.js.map +1 -1
- package/lib/component/1d/FloatPublicationString.d.ts.map +1 -1
- package/lib/component/1d/FloatPublicationString.js +1 -1
- package/lib/component/1d/FloatPublicationString.js.map +1 -1
- package/lib/component/1d/FloatingRanges.d.ts.map +1 -1
- package/lib/component/1d/FloatingRanges.js +1 -1
- package/lib/component/1d/FloatingRanges.js.map +1 -1
- package/lib/component/1d/inset/DraggableInset.d.ts.map +1 -1
- package/lib/component/1d/inset/DraggableInset.js +1 -1
- package/lib/component/1d/inset/DraggableInset.js.map +1 -1
- package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.d.ts.map +1 -1
- package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.js +11 -2
- package/lib/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.js.map +1 -1
- package/lib/component/2d/useTracesSpectra.d.ts.map +1 -1
- package/lib/component/2d/useTracesSpectra.js +3 -2
- package/lib/component/2d/useTracesSpectra.js.map +1 -1
- package/lib/component/EventsTrackers/KeysListenerTracker.js +3 -3
- package/lib/component/EventsTrackers/KeysListenerTracker.js.map +1 -1
- package/lib/component/elements/NextPrev.d.ts.map +1 -1
- package/lib/component/elements/NextPrev.js +23 -4
- package/lib/component/elements/NextPrev.js.map +1 -1
- package/lib/component/elements/export/utilities/exportOptionValidationSchema.d.ts +1 -1
- package/lib/component/hooks/useExport.d.ts +7 -7
- package/lib/component/hooks/useExport.d.ts.map +1 -1
- package/lib/component/hooks/useExport.js +22 -42
- package/lib/component/hooks/useExport.js.map +1 -1
- package/lib/component/hooks/useSetActiveSpectrumAction.d.ts.map +1 -1
- package/lib/component/hooks/useSetActiveSpectrumAction.js +3 -1
- package/lib/component/hooks/useSetActiveSpectrumAction.js.map +1 -1
- package/lib/component/loader/useLoadFiles.d.ts.map +1 -1
- package/lib/component/loader/useLoadFiles.js +81 -86
- package/lib/component/loader/useLoadFiles.js.map +1 -1
- package/lib/component/main/ErrorOverlay.d.ts.map +1 -1
- package/lib/component/main/ErrorOverlay.js +6 -1
- package/lib/component/main/ErrorOverlay.js.map +1 -1
- package/lib/component/main/InnerNMRiumContents.d.ts.map +1 -1
- package/lib/component/main/InnerNMRiumContents.js +1 -2
- package/lib/component/main/InnerNMRiumContents.js.map +1 -1
- package/lib/component/main/NMRiumViewer.js +1 -1
- package/lib/component/main/NMRiumViewer.js.map +1 -1
- package/lib/component/main/NMRiumViewerWrapper.d.ts.map +1 -1
- package/lib/component/main/NMRiumViewerWrapper.js +11 -3
- package/lib/component/main/NMRiumViewerWrapper.js.map +1 -1
- package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.d.ts +6 -0
- package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.d.ts.map +1 -0
- package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.js +127 -0
- package/lib/component/modal/MoleculeAutoLabelsDatabaseModal.js.map +1 -0
- package/lib/component/modal/SaveAsModal.d.ts.map +1 -1
- package/lib/component/modal/SaveAsModal.js +4 -8
- package/lib/component/modal/SaveAsModal.js.map +1 -1
- package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
- package/lib/component/modal/changeSum/ChangeSumModal.js.map +1 -1
- package/lib/component/modal/changeSum/SelectMolecule.js +4 -1
- package/lib/component/modal/changeSum/SelectMolecule.js.map +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts.map +1 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +71 -16
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js.map +1 -1
- package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.d.ts.map +1 -1
- package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.js +3 -12
- package/lib/component/panels/MoleculesPanel/hooks/useAtomAssignment.js.map +1 -1
- package/lib/component/panels/Panels.d.ts +0 -9
- package/lib/component/panels/Panels.d.ts.map +1 -1
- package/lib/component/panels/Panels.js +1 -29
- package/lib/component/panels/Panels.js.map +1 -1
- package/lib/component/panels/hooks/useTogglePanel.d.ts.map +1 -1
- package/lib/component/panels/hooks/useTogglePanel.js +4 -3
- package/lib/component/panels/hooks/useTogglePanel.js.map +1 -1
- package/lib/component/reducer/actions/LoadAction.d.ts.map +1 -1
- package/lib/component/reducer/actions/LoadAction.js +6 -0
- package/lib/component/reducer/actions/LoadAction.js.map +1 -1
- package/lib/component/reducer/actions/MoleculeActions.d.ts +23 -1
- package/lib/component/reducer/actions/MoleculeActions.d.ts.map +1 -1
- package/lib/component/reducer/actions/MoleculeActions.js +2 -2
- package/lib/component/reducer/actions/MoleculeActions.js.map +1 -1
- package/lib/component/reducer/actions/RangesActions.js +1 -1
- package/lib/component/reducer/actions/RangesActions.js.map +1 -1
- package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
- package/lib/component/reducer/actions/SpectraActions.d.ts.map +1 -1
- package/lib/component/reducer/actions/SpectraActions.js +2 -2
- package/lib/component/reducer/actions/SpectraActions.js.map +1 -1
- package/lib/component/reducer/preferences/actions/analyzeSpectra.d.ts +2 -1
- package/lib/component/reducer/preferences/actions/analyzeSpectra.d.ts.map +1 -1
- package/lib/component/reducer/preferences/actions/analyzeSpectra.js +10 -0
- package/lib/component/reducer/preferences/actions/analyzeSpectra.js.map +1 -1
- package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.d.ts +4 -0
- package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.d.ts.map +1 -0
- package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.js +9 -0
- package/lib/component/reducer/preferences/actions/toggleOpenSplitPanel.js.map +1 -0
- package/lib/component/reducer/preferences/preferencesReducer.d.ts +8 -1
- package/lib/component/reducer/preferences/preferencesReducer.d.ts.map +1 -1
- package/lib/component/reducer/preferences/preferencesReducer.js +6 -1
- package/lib/component/reducer/preferences/preferencesReducer.js.map +1 -1
- package/lib/component/toolbar/ToolBar.d.ts.map +1 -1
- package/lib/component/toolbar/ToolBar.js +6 -7
- package/lib/component/toolbar/ToolBar.js.map +1 -1
- package/lib/component/toolbar/toolbarMenu.d.ts +5 -1
- package/lib/component/toolbar/toolbarMenu.d.ts.map +1 -1
- package/lib/component/toolbar/toolbarMenu.js +1 -1
- package/lib/component/toolbar/toolbarMenu.js.map +1 -1
- package/lib/component/utility/export.d.ts +2 -1
- package/lib/component/utility/export.d.ts.map +1 -1
- package/lib/component/utility/export.js +5 -1
- package/lib/component/utility/export.js.map +1 -1
- package/lib/data/data1d/multipleSpectraAnalysis.d.ts +1 -0
- package/lib/data/data1d/multipleSpectraAnalysis.d.ts.map +1 -1
- package/lib/data/data1d/multipleSpectraAnalysis.js +14 -0
- package/lib/data/data1d/multipleSpectraAnalysis.js.map +1 -1
- package/lib/data/data2d/Spectrum2D/contours.d.ts.map +1 -1
- package/lib/data/data2d/Spectrum2D/contours.js +13 -6
- package/lib/data/data2d/Spectrum2D/contours.js.map +1 -1
- package/lib/data/molecules/MoleculeManager.d.ts +6 -1
- package/lib/data/molecules/MoleculeManager.d.ts.map +1 -1
- package/lib/data/molecules/MoleculeManager.js +3 -2
- package/lib/data/molecules/MoleculeManager.js.map +1 -1
- package/lib/versionInfo.js +1 -1
- package/package.json +39 -39
- package/src/component/1d/BrushTracker1D.tsx +8 -0
- package/src/component/1d/FloatPublicationString.tsx +0 -1
- package/src/component/1d/FloatingRanges.tsx +0 -1
- package/src/component/1d/inset/DraggableInset.tsx +0 -1
- package/src/component/1d-2d/components/FloatMoleculeStructures/DraggableStructure.tsx +11 -2
- package/src/component/2d/useTracesSpectra.ts +4 -3
- package/src/component/EventsTrackers/KeysListenerTracker.tsx +3 -3
- package/src/component/elements/NextPrev.tsx +28 -4
- package/src/component/hooks/useExport.tsx +34 -64
- package/src/component/hooks/useSetActiveSpectrumAction.ts +3 -2
- package/src/component/loader/useLoadFiles.ts +134 -111
- package/src/component/main/ErrorOverlay.tsx +11 -2
- package/src/component/main/InnerNMRiumContents.tsx +6 -9
- package/src/component/main/NMRiumViewer.tsx +2 -2
- package/src/component/main/NMRiumViewerWrapper.tsx +14 -6
- package/src/component/modal/MoleculeAutoLabelsDatabaseModal.tsx +219 -0
- package/src/component/modal/SaveAsModal.tsx +14 -41
- package/src/component/modal/changeSum/ChangeSumModal.tsx +1 -1
- package/src/component/modal/changeSum/SelectMolecule.tsx +23 -23
- package/src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx +94 -15
- package/src/component/panels/MoleculesPanel/hooks/useAtomAssignment.tsx +3 -17
- package/src/component/panels/Panels.tsx +1 -53
- package/src/component/panels/hooks/useTogglePanel.ts +4 -3
- package/src/component/reducer/actions/LoadAction.ts +15 -1
- package/src/component/reducer/actions/MoleculeActions.ts +4 -2
- package/src/component/reducer/actions/RangesActions.ts +1 -1
- package/src/component/reducer/actions/SpectraActions.ts +6 -2
- package/src/component/reducer/preferences/actions/analyzeSpectra.ts +16 -0
- package/src/component/reducer/preferences/actions/toggleOpenSplitPanel.ts +18 -0
- package/src/component/reducer/preferences/preferencesReducer.ts +22 -1
- package/src/component/toolbar/ToolBar.tsx +9 -9
- package/src/component/toolbar/toolbarMenu.tsx +13 -2
- package/src/component/utility/export.ts +6 -0
- package/src/data/data1d/multipleSpectraAnalysis.ts +20 -0
- package/src/data/data2d/Spectrum2D/contours.ts +16 -6
- package/src/data/molecules/MoleculeManager.ts +7 -2
- package/src/versionInfo.ts +1 -1
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import type {
|
|
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
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
+
const dispatchPayload = useCallback(
|
|
28
|
+
(payload: Omit<Payload, 'spectraColors' | 'defaultMoleculeSettings'>) => {
|
|
29
|
+
const { nmriumState } = payload;
|
|
30
|
+
const { spectraColors, defaultMoleculeSettings } = workspacePreferences;
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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' }}>{
|
|
27
|
-
{
|
|
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
|
-
<
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
<
|
|
98
|
+
<FloatMolecules />
|
|
99
99
|
</div>
|
|
100
100
|
);
|
|
101
101
|
}
|
|
@@ -3,7 +3,7 @@ import type { SplitPaneSize } from 'react-science/ui';
|
|
|
3
3
|
import { SplitPane } from 'react-science/ui';
|
|
4
4
|
|
|
5
5
|
import { usePreferences } from '../context/PreferencesContext.js';
|
|
6
|
-
import { Panels
|
|
6
|
+
import { Panels } from '../panels/Panels.js';
|
|
7
7
|
import { useAccordionItems } from '../panels/hooks/useAccordionItems.js';
|
|
8
8
|
import { useGetPanelOptions } from '../panels/hooks/useGetPanelOptions.js';
|
|
9
9
|
|
|
@@ -19,8 +19,6 @@ export function NMRiumViewerWrapper(props: NMRiumViewerWrapperProps) {
|
|
|
19
19
|
const { emptyText, viewerRef } = props;
|
|
20
20
|
const { current, dispatch } = usePreferences();
|
|
21
21
|
const getPanelPreferences = useGetPanelOptions();
|
|
22
|
-
const { closeSplitPane, openSplitPane, isSplitPaneOpen } =
|
|
23
|
-
usePanelOpenState();
|
|
24
22
|
|
|
25
23
|
const {
|
|
26
24
|
general: { verticalSplitterPosition, verticalSplitterCloseThreshold },
|
|
@@ -36,6 +34,14 @@ export function NMRiumViewerWrapper(props: NMRiumViewerWrapperProps) {
|
|
|
36
34
|
},
|
|
37
35
|
});
|
|
38
36
|
}
|
|
37
|
+
function handleToggleSplitPanel(isOpen: boolean) {
|
|
38
|
+
dispatch({
|
|
39
|
+
type: 'TOGGLE_SPLIT_PANEL',
|
|
40
|
+
payload: {
|
|
41
|
+
isOpen,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
39
45
|
|
|
40
46
|
const displayedPanels = items.filter((item) => {
|
|
41
47
|
const panelOptions = getPanelPreferences(item);
|
|
@@ -47,16 +53,18 @@ export function NMRiumViewerWrapper(props: NMRiumViewerWrapperProps) {
|
|
|
47
53
|
return <NMRiumViewer emptyText={emptyText} viewerRef={viewerRef} />;
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
const isOpen = !general?.hidePanelOnLoad;
|
|
57
|
+
|
|
50
58
|
return (
|
|
51
59
|
<SplitPane
|
|
52
60
|
size={verticalSplitterPosition}
|
|
53
61
|
direction="horizontal"
|
|
54
62
|
controlledSide="end"
|
|
55
|
-
open={
|
|
56
|
-
defaultOpen={
|
|
63
|
+
open={isOpen}
|
|
64
|
+
defaultOpen={isOpen}
|
|
57
65
|
closeThreshold={verticalSplitterCloseThreshold}
|
|
58
66
|
onSizeChange={resizeHandler}
|
|
59
|
-
onOpenChange={(isOpen) => (isOpen
|
|
67
|
+
onOpenChange={(isOpen) => handleToggleSplitPanel(isOpen)}
|
|
60
68
|
>
|
|
61
69
|
<NMRiumViewer emptyText={emptyText} viewerRef={viewerRef} />
|
|
62
70
|
<Panels />
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Dialog, InputGroup } from '@blueprintjs/core';
|
|
2
|
+
import styled from '@emotion/styled';
|
|
3
|
+
import { Molecule } from 'openchemlib';
|
|
4
|
+
import { autoLabelDatabase } from 'openchemlib-utils';
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { MF } from 'react-mf';
|
|
7
|
+
import { IdcodeSvgRenderer } from 'react-ocl';
|
|
8
|
+
import { Button } from 'react-science/ui';
|
|
9
|
+
import { filter } from 'smart-array-filter';
|
|
10
|
+
|
|
11
|
+
import { useDispatch } from '../context/DispatchContext.tsx';
|
|
12
|
+
import { StyledDialogBody } from '../elements/StyledDialogBody.js';
|
|
13
|
+
|
|
14
|
+
interface LabelDatabaseItem {
|
|
15
|
+
idCode: string;
|
|
16
|
+
coordinates: string;
|
|
17
|
+
mf: string;
|
|
18
|
+
mw: number;
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ChemicalGrid = styled.div`
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-wrap: wrap;
|
|
25
|
+
gap: 1.25rem;
|
|
26
|
+
justify-content: flex-start;
|
|
27
|
+
padding: 0.5rem 1rem;
|
|
28
|
+
flex: 1;
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const AddButton = styled(Button)`
|
|
32
|
+
position: absolute;
|
|
33
|
+
top: 0;
|
|
34
|
+
left: 0;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const ChemicalCard = styled.div`
|
|
38
|
+
position: relative;
|
|
39
|
+
flex: 0 0 calc((100% - 2.5rem) / 3);
|
|
40
|
+
min-width: 200px;
|
|
41
|
+
border-radius: 8px;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
background: #fff;
|
|
44
|
+
box-shadow: 0 2px 8px rgb(0 0 0 / 8%);
|
|
45
|
+
transition: all 0.25s ease;
|
|
46
|
+
/* stylelint-disable nesting-selector-no-missing-scoping-root */
|
|
47
|
+
&:hover {
|
|
48
|
+
box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
|
|
49
|
+
transform: translateY(-2px);
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const CardLabel = styled.div`
|
|
54
|
+
padding: 0.75rem 1rem;
|
|
55
|
+
background: linear-gradient(180deg, #fff 0%, #f0f2f5 40%, #e2e6eb 100%);
|
|
56
|
+
border-bottom: 1px solid #d1d5db;
|
|
57
|
+
box-shadow: inset 0 1px 0 rgb(255 255 255 / 80%);
|
|
58
|
+
|
|
59
|
+
h3 {
|
|
60
|
+
margin: 0;
|
|
61
|
+
font-size: 0.95rem;
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
color: #374151;
|
|
64
|
+
text-align: center;
|
|
65
|
+
text-transform: capitalize;
|
|
66
|
+
letter-spacing: 0.02em;
|
|
67
|
+
text-shadow: 0 1px 0 rgb(255 255 255 / 50%);
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const StructureContainer = styled.div`
|
|
72
|
+
display: flex;
|
|
73
|
+
align-items: center;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
padding: 0.5rem;
|
|
76
|
+
background: #fafafa;
|
|
77
|
+
border-bottom: 1px solid #eee;
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
const CardInfo = styled.div`
|
|
81
|
+
padding: 0.75rem 1rem;
|
|
82
|
+
display: flex;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
align-items: center;
|
|
85
|
+
background: #fff;
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const MolecularFormula = styled.div<{ color?: string }>`
|
|
89
|
+
font-size: 0.9rem;
|
|
90
|
+
font-weight: 500;
|
|
91
|
+
color: ${({ color }) => color ?? '#374151'};
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
const SearchContainer = styled.div`
|
|
95
|
+
padding: 1.2rem;
|
|
96
|
+
margin-bottom: 1.5rem;
|
|
97
|
+
background-color: white;
|
|
98
|
+
border-bottom: 1px solid #e0e0e0;
|
|
99
|
+
position: sticky;
|
|
100
|
+
top: 0;
|
|
101
|
+
z-index: 1;
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
const SearchInput = styled(InputGroup)`
|
|
105
|
+
input {
|
|
106
|
+
background: #eceff7;
|
|
107
|
+
|
|
108
|
+
&:focus {
|
|
109
|
+
background: #fff;
|
|
110
|
+
box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
const NoResults = styled.p`
|
|
116
|
+
text-align: center;
|
|
117
|
+
color: #6b7280;
|
|
118
|
+
font-size: 1rem;
|
|
119
|
+
padding: 3rem;
|
|
120
|
+
`;
|
|
121
|
+
interface MoleculeAutoLabelsDatabaseModalProps {
|
|
122
|
+
onClose?: (element?: string) => void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function MoleculeAutoLabelsDatabaseModal({
|
|
126
|
+
onClose = () => null,
|
|
127
|
+
}: MoleculeAutoLabelsDatabaseModalProps) {
|
|
128
|
+
const dispatch = useDispatch();
|
|
129
|
+
const [keywords, setSearch] = useState('');
|
|
130
|
+
|
|
131
|
+
function handleAddMolecule(options: LabelDatabaseItem) {
|
|
132
|
+
const { idCode, coordinates, label } = options;
|
|
133
|
+
const molecule = Molecule.fromIDCode(idCode, coordinates);
|
|
134
|
+
|
|
135
|
+
if (molecule.getAllAtoms() <= 0) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
dispatch({
|
|
140
|
+
type: 'ADD_MOLECULE',
|
|
141
|
+
payload: { molfile: molecule.toMolfileV3(), label },
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
onClose();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const filteredLabelDatabase = filter(autoLabelDatabase, { keywords });
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<Dialog
|
|
151
|
+
isOpen
|
|
152
|
+
onClose={() => onClose()}
|
|
153
|
+
style={{ width: '90vw', maxWidth: 1000, height: '80vh' }}
|
|
154
|
+
title="Template database"
|
|
155
|
+
>
|
|
156
|
+
<StyledDialogBody style={{ padding: 0 }}>
|
|
157
|
+
<SearchContainer>
|
|
158
|
+
<SearchInput
|
|
159
|
+
size="large"
|
|
160
|
+
placeholder="Search ..."
|
|
161
|
+
value={keywords}
|
|
162
|
+
onChange={({ target }) => {
|
|
163
|
+
if (target.value !== undefined) {
|
|
164
|
+
setSearch(target.value);
|
|
165
|
+
}
|
|
166
|
+
}}
|
|
167
|
+
leftIcon="search"
|
|
168
|
+
type="search"
|
|
169
|
+
/>
|
|
170
|
+
</SearchContainer>
|
|
171
|
+
{filteredLabelDatabase.length === 0 ? (
|
|
172
|
+
<NoResults>No results found for "{keywords}"</NoResults>
|
|
173
|
+
) : (
|
|
174
|
+
<ChemicalGrid>
|
|
175
|
+
{filteredLabelDatabase.map((compound) => (
|
|
176
|
+
<ChemicalCard key={compound.label}>
|
|
177
|
+
<AddButton
|
|
178
|
+
size="large"
|
|
179
|
+
icon="plus"
|
|
180
|
+
minimal
|
|
181
|
+
tooltipProps={{
|
|
182
|
+
content: (
|
|
183
|
+
<MolecularFormula color="white">
|
|
184
|
+
<span>Add </span>
|
|
185
|
+
<MF mf={compound.mf} /> -
|
|
186
|
+
<span> {compound.mw.toFixed(2)}</span>
|
|
187
|
+
<span> molecule </span>
|
|
188
|
+
</MolecularFormula>
|
|
189
|
+
),
|
|
190
|
+
}}
|
|
191
|
+
onClick={() => handleAddMolecule(compound)}
|
|
192
|
+
/>
|
|
193
|
+
<CardLabel>
|
|
194
|
+
<h3>{compound.label}</h3>
|
|
195
|
+
</CardLabel>
|
|
196
|
+
|
|
197
|
+
<StructureContainer>
|
|
198
|
+
<IdcodeSvgRenderer
|
|
199
|
+
idcode={compound.idCode}
|
|
200
|
+
coordinates={compound.coordinates}
|
|
201
|
+
width={300}
|
|
202
|
+
height={200}
|
|
203
|
+
/>
|
|
204
|
+
</StructureContainer>
|
|
205
|
+
|
|
206
|
+
<CardInfo>
|
|
207
|
+
<MolecularFormula>
|
|
208
|
+
<MF mf={compound.mf} /> -
|
|
209
|
+
<span> {compound.mw.toFixed(2)}</span>
|
|
210
|
+
</MolecularFormula>
|
|
211
|
+
</CardInfo>
|
|
212
|
+
</ChemicalCard>
|
|
213
|
+
))}
|
|
214
|
+
</ChemicalGrid>
|
|
215
|
+
)}
|
|
216
|
+
</StyledDialogBody>
|
|
217
|
+
</Dialog>
|
|
218
|
+
);
|
|
219
|
+
}
|