nmrium 0.33.0-pre.1677156813 → 0.33.0-pre.1677504537
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/NMRium.d.ts +5 -4
- package/lib/component/NMRium.js +20 -12
- package/lib/component/elements/ReactTable/ReactTable.js +1 -1
- package/lib/component/hooks/useExport.js +7 -2
- package/lib/component/loader/DropZone.js +2 -2
- package/lib/component/panels/SpectrumsPanel/SpectrumsTabs.js +5 -5
- package/lib/component/panels/databasePanel/DatabaseStructureSearchModal.js +1 -1
- package/lib/component/reducer/Reducer.d.ts +2 -2
- package/lib/component/reducer/preferences/preferencesReducer.d.ts +2 -2
- package/lib/data/SpectraManager.d.ts +5 -3
- package/lib/data/SpectraManager.js +22 -13
- package/lib-cjs/component/NMRium.js +22 -12
- package/lib-cjs/component/elements/ReactTable/ReactTable.js +1 -1
- package/lib-cjs/component/hooks/useExport.js +7 -2
- package/lib-cjs/component/loader/DropZone.js +2 -2
- package/lib-cjs/component/panels/SpectrumsPanel/SpectrumsTabs.js +4 -4
- package/lib-cjs/component/panels/databasePanel/DatabaseStructureSearchModal.js +1 -1
- package/lib-cjs/data/SpectraManager.js +22 -13
- package/package.json +2 -2
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
|
2
2
|
import { CorrelationData } from 'nmr-correlation';
|
|
3
|
-
import {
|
|
3
|
+
import { Source, NmriumState } from 'nmr-load-save';
|
|
4
4
|
import { ReactElement, ReactNode } from 'react';
|
|
5
5
|
import { Datum1D } from '../data/types/data1d';
|
|
6
6
|
import { Datum2D } from '../data/types/data2d';
|
|
7
|
-
import { ViewState } from './reducer/Reducer';
|
|
8
7
|
import { BlobObject } from './utility/export';
|
|
9
8
|
import { CustomWorkspaces, WorkspacePreferences as NMRiumPreferences } from './workspaces/Workspace';
|
|
9
|
+
export { serializeNmriumState } from 'nmr-load-save';
|
|
10
|
+
export type { NmriumState } from 'nmr-load-save';
|
|
10
11
|
export type { WorkspacePreferences as NMRiumPreferences } from './workspaces/Workspace';
|
|
11
12
|
export type NMRiumWorkspace = 'exercise' | 'process1D' | 'default' | 'prediction' | 'embedded' | 'assignment' | (string & {});
|
|
13
|
+
export type OnNMRiumChange = (state: NmriumState, source: 'data' | 'view' | 'settings') => void;
|
|
12
14
|
export interface NMRiumProps {
|
|
13
15
|
data?: NMRiumData;
|
|
14
|
-
|
|
15
|
-
onViewChange?: (view: ViewState) => void;
|
|
16
|
+
onChange?: OnNMRiumChange;
|
|
16
17
|
workspace?: NMRiumWorkspace;
|
|
17
18
|
customWorkspaces?: CustomWorkspaces;
|
|
18
19
|
preferences?: NMRiumPreferences;
|
package/lib/component/NMRium.js
CHANGED
|
@@ -74,25 +74,22 @@ const containerStyles = css `
|
|
|
74
74
|
user-select: none;
|
|
75
75
|
}
|
|
76
76
|
`;
|
|
77
|
+
export { serializeNmriumState } from 'nmr-load-save';
|
|
77
78
|
const defaultData = {
|
|
78
79
|
spectra: [],
|
|
79
80
|
};
|
|
80
81
|
const NMRium = forwardRef(function NMRium(props, ref) {
|
|
81
82
|
return (_jsx(RootLayout, { style: { width: '100%' }, children: _jsx(ErrorBoundary, { FallbackComponent: ErrorOverlay, children: _jsx(InnerNMRium, { ...props, innerRef: ref }) }) }));
|
|
82
83
|
});
|
|
83
|
-
function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces, preferences, getSpinner = defaultGetSpinner,
|
|
84
|
+
function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces, preferences, getSpinner = defaultGetSpinner, onChange, emptyText, innerRef, }) {
|
|
84
85
|
const rootRef = useRef(null);
|
|
85
86
|
const elementsWrapperRef = useRef(null);
|
|
86
87
|
const viewerRef = useRef(null);
|
|
87
88
|
const [show, toggle] = useToggle(false);
|
|
88
|
-
const
|
|
89
|
+
const handleChange = useRef(onChange);
|
|
89
90
|
useEffect(() => {
|
|
90
|
-
|
|
91
|
-
}, [
|
|
92
|
-
const handleViewChange = useRef(onViewChange);
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
handleViewChange.current = onViewChange;
|
|
95
|
-
}, [onViewChange]);
|
|
91
|
+
handleChange.current = onChange;
|
|
92
|
+
}, [onChange]);
|
|
96
93
|
const isFullscreen = useFullscreen(rootRef, show, {
|
|
97
94
|
onClose: () => {
|
|
98
95
|
toggle(false);
|
|
@@ -100,15 +97,26 @@ function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces
|
|
|
100
97
|
});
|
|
101
98
|
const [state, dispatch] = useReducer(spectrumReducer, initialState, initState);
|
|
102
99
|
const [preferencesState, dispatchPreferences] = useReducer(preferencesReducer, preferencesInitialState, initPreferencesState);
|
|
103
|
-
const { displayerMode, data: spectraData, actionType, view } = state;
|
|
100
|
+
const { displayerMode, source, data: spectraData, molecules, correlations, actionType, view, } = state;
|
|
101
|
+
const stateRef = useRef();
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
const { workspace, workspaces = {} } = preferencesState;
|
|
104
|
+
stateRef.current = toJSON({ data: spectraData, molecules, correlations, source, view }, { current: workspaces[workspace.current] }, { serialize: false, exportTarget: 'onChange' });
|
|
105
|
+
}, [correlations, molecules, preferencesState, source, spectraData, view]);
|
|
104
106
|
useEffect(() => {
|
|
107
|
+
// trigger onChange callback if data object changed
|
|
105
108
|
if (checkActionType(actionType)) {
|
|
106
|
-
|
|
109
|
+
handleChange.current?.(stateRef.current, 'data');
|
|
107
110
|
}
|
|
108
|
-
}, [actionType,
|
|
111
|
+
}, [actionType, correlations, molecules, source, spectraData]);
|
|
109
112
|
useEffect(() => {
|
|
110
|
-
|
|
113
|
+
// trigger onChange callback if view object changed
|
|
114
|
+
handleChange.current?.(stateRef.current, 'view');
|
|
111
115
|
}, [view]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
// trigger onChange callback if settings changed
|
|
118
|
+
handleChange.current?.(stateRef.current, 'settings');
|
|
119
|
+
}, [preferencesState]);
|
|
112
120
|
const dispatchMiddleWare = useMemo(() => {
|
|
113
121
|
return dispatchMiddleware(dispatch);
|
|
114
122
|
}, []);
|
|
@@ -237,6 +237,6 @@ function ReactTable(props) {
|
|
|
237
237
|
return (_jsx(ReactTableProvider, { value: tableVirtualBoundary, children: _jsx("div", { ref: mRef, style: {
|
|
238
238
|
position: 'relative',
|
|
239
239
|
height: '100%',
|
|
240
|
-
}, css: style, children: _jsx(ReactTableInner, { onScroll: scrollHandler, onSortEnd: onSortEnd, ref: containerRef, ...
|
|
240
|
+
}, css: style, children: _jsx(ReactTableInner, { onScroll: scrollHandler, onSortEnd: onSortEnd, ref: containerRef, ...props }) }) }));
|
|
241
241
|
}
|
|
242
242
|
export default memo(ReactTable);
|
|
@@ -31,7 +31,9 @@ export default function useExport() {
|
|
|
31
31
|
async function handle() {
|
|
32
32
|
//exported file name by default will be the first spectrum name
|
|
33
33
|
const fileName = state.data[0]?.display?.name;
|
|
34
|
-
const exportedData = toJSON(state, preferencesState,
|
|
34
|
+
const exportedData = toJSON(state, preferencesState, {
|
|
35
|
+
exportTarget: 'nmrium',
|
|
36
|
+
});
|
|
35
37
|
await exportAsJSON(exportedData, fileName, spaceIndent, isCompressed);
|
|
36
38
|
hideLoading();
|
|
37
39
|
}
|
|
@@ -66,7 +68,10 @@ export default function useExport() {
|
|
|
66
68
|
const hideLoading = await alert.showLoading(`Exporting as ${name}.nmrium process in progress`);
|
|
67
69
|
setTimeout(() => {
|
|
68
70
|
void (async () => {
|
|
69
|
-
const exportedData = toJSON(state, preferencesState,
|
|
71
|
+
const exportedData = toJSON(state, preferencesState, {
|
|
72
|
+
...include,
|
|
73
|
+
exportTarget: 'nmrium',
|
|
74
|
+
});
|
|
70
75
|
const spaceIndent = pretty ? 2 : 0;
|
|
71
76
|
await exportAsJSON(exportedData, name, spaceIndent, compressed);
|
|
72
77
|
hideLoading();
|
|
@@ -66,8 +66,8 @@ function DropZone(props) {
|
|
|
66
66
|
if (metaFile) {
|
|
67
67
|
parseMetaFileResult = await parseMetaFile(metaFile);
|
|
68
68
|
}
|
|
69
|
-
const { nmrLoaders:
|
|
70
|
-
const { nmriumState, containsNmrium } = await readDropFiles(fileCollection, {
|
|
69
|
+
const { nmrLoaders: sourceSelector } = preferences.current;
|
|
70
|
+
const { nmriumState, containsNmrium } = await readDropFiles(fileCollection, { sourceSelector });
|
|
71
71
|
if (nmriumState?.settings) {
|
|
72
72
|
dispatchPreferences({
|
|
73
73
|
type: 'SET_WORKSPACE',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource @emotion/react */
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
|
-
import { useState, useMemo, memo } from 'react';
|
|
4
|
+
import { useState, useMemo, memo, useCallback } from 'react';
|
|
5
5
|
import { useChartData } from '../../context/ChartContext';
|
|
6
6
|
import { useDispatch } from '../../context/DispatchContext';
|
|
7
7
|
import IsotopesViewer from '../../elements/IsotopesViewer';
|
|
@@ -25,7 +25,7 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
25
25
|
function onTabChangeHandler(tab) {
|
|
26
26
|
dispatch({ type: SET_ACTIVE_TAB, tab: tab.tabid });
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
const openSettingHandler = useCallback((event, selectedSpectrum) => {
|
|
29
29
|
event.stopPropagation();
|
|
30
30
|
setSettingModalPosition({
|
|
31
31
|
x: event.nativeEvent.clientX,
|
|
@@ -33,8 +33,8 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
33
33
|
});
|
|
34
34
|
setSelectedSpectrum(selectedSpectrum);
|
|
35
35
|
setIsSettingModalDisplayed(true);
|
|
36
|
-
}
|
|
37
|
-
|
|
36
|
+
}, []);
|
|
37
|
+
const handleChangeVisibility = useCallback((d, key) => {
|
|
38
38
|
dispatch({
|
|
39
39
|
type: CHANGE_VISIBILITY,
|
|
40
40
|
payload: {
|
|
@@ -42,7 +42,7 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
42
42
|
key,
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
|
-
}
|
|
45
|
+
}, [dispatch]);
|
|
46
46
|
function handleChangeActiveSpectrum(e, spectrum) {
|
|
47
47
|
setTimeout(() => {
|
|
48
48
|
const modifier = `shift[${e.shiftKey ? 'true' : 'false'}]_ctrl[${e.ctrlKey ? 'true' : 'false'}]`;
|
|
@@ -4,5 +4,5 @@ import { StructureEditor } from 'react-ocl/full';
|
|
|
4
4
|
import CloseButton from '../../elements/CloseButton';
|
|
5
5
|
import { ModalStyles } from '../../modal/ModalStyle';
|
|
6
6
|
export function DatabaseStructureSearchModal({ onChange, idCode, onClose, }) {
|
|
7
|
-
return (_jsxs("div", { css: ModalStyles, children: [_jsxs("div", { className: "header handle", children: [_jsx("span", { children: "Search by structure" }), _jsx(CloseButton, { onClick: onClose, className: "close-bt" })] }), _jsx("div", { className: "main-content", children: _jsx(StructureEditor, { initialIDCode: idCode, svgMenu: true, fragment: true, onChange: (
|
|
7
|
+
return (_jsxs("div", { css: ModalStyles, children: [_jsxs("div", { className: "header handle", children: [_jsx("span", { children: "Search by structure" }), _jsx(CloseButton, { onClick: onClose, className: "close-bt" })] }), _jsx("div", { className: "main-content", children: _jsx(StructureEditor, { initialIDCode: idCode, svgMenu: true, fragment: true, onChange: (molFile, molecule, idCode) => onChange(idCode) }) })] }));
|
|
8
8
|
}
|
|
@@ -316,7 +316,7 @@ export declare const spectrumReducer: (base: {
|
|
|
316
316
|
readonly id: string;
|
|
317
317
|
readonly selector?: {
|
|
318
318
|
readonly general?: {
|
|
319
|
-
readonly dataSelection?: "
|
|
319
|
+
readonly dataSelection?: import("nmr-load-save/lib/types/Options/DataSelectionOption").DataSelectionOption | undefined;
|
|
320
320
|
readonly keep1D?: boolean | undefined;
|
|
321
321
|
readonly keep2D?: boolean | undefined;
|
|
322
322
|
readonly onlyReal?: boolean | undefined;
|
|
@@ -816,7 +816,7 @@ export declare const spectrumReducer: (base: {
|
|
|
816
816
|
readonly id: string;
|
|
817
817
|
readonly selector?: {
|
|
818
818
|
readonly general?: {
|
|
819
|
-
readonly dataSelection?: "
|
|
819
|
+
readonly dataSelection?: import("nmr-load-save/lib/types/Options/DataSelectionOption").DataSelectionOption | undefined;
|
|
820
820
|
readonly keep1D?: boolean | undefined;
|
|
821
821
|
readonly keep2D?: boolean | undefined;
|
|
822
822
|
readonly onlyReal?: boolean | undefined;
|
|
@@ -2761,7 +2761,7 @@ declare const preferencesReducer: (base: {
|
|
|
2761
2761
|
};
|
|
2762
2762
|
readonly nmrLoaders: {
|
|
2763
2763
|
readonly general: {
|
|
2764
|
-
readonly dataSelection?: "
|
|
2764
|
+
readonly dataSelection?: import("nmr-load-save/lib/types/Options/DataSelectionOption").DataSelectionOption | undefined;
|
|
2765
2765
|
readonly keep1D?: boolean | undefined;
|
|
2766
2766
|
readonly keep2D?: boolean | undefined;
|
|
2767
2767
|
readonly onlyReal?: boolean | undefined;
|
|
@@ -5839,7 +5839,7 @@ declare const preferencesReducer: (base: {
|
|
|
5839
5839
|
};
|
|
5840
5840
|
readonly nmrLoaders: {
|
|
5841
5841
|
readonly general: {
|
|
5842
|
-
readonly dataSelection?: "
|
|
5842
|
+
readonly dataSelection?: import("nmr-load-save/lib/types/Options/DataSelectionOption").DataSelectionOption | undefined;
|
|
5843
5843
|
readonly keep1D?: boolean | undefined;
|
|
5844
5844
|
readonly keep2D?: boolean | undefined;
|
|
5845
5845
|
readonly onlyReal?: boolean | undefined;
|
|
@@ -6,10 +6,13 @@ export declare enum DataExportOptions {
|
|
|
6
6
|
NO_DATA = "NO_DATA"
|
|
7
7
|
}
|
|
8
8
|
export type DataExportOptionsType = keyof typeof DataExportOptions;
|
|
9
|
+
type ExportTarget = 'nmrium' | 'onChange';
|
|
9
10
|
export interface ExportOptions {
|
|
10
11
|
dataType?: DataExportOptionsType;
|
|
11
12
|
view?: boolean;
|
|
12
13
|
settings?: boolean;
|
|
14
|
+
serialize?: boolean;
|
|
15
|
+
exportTarget?: ExportTarget;
|
|
13
16
|
}
|
|
14
17
|
export declare function addJcampFromURL(spectra: any, jcampURL: any, options: any, usedColors: any): Promise<void>;
|
|
15
18
|
export declare function addJcamp(output: any, jcamp: any, options: any, usedColors: any): void;
|
|
@@ -18,8 +21,7 @@ export declare function addJcamps(files: any, usedColors: any): never[];
|
|
|
18
21
|
*
|
|
19
22
|
* @param {object} state
|
|
20
23
|
*/
|
|
21
|
-
|
|
22
|
-
export declare function toJSON(state: State, preferencesState: Partial<{
|
|
24
|
+
export declare function toJSON(state: Partial<State>, preferencesState: Partial<{
|
|
23
25
|
current: Workspace;
|
|
24
|
-
}>,
|
|
26
|
+
}>, options?: ExportOptions): any;
|
|
25
27
|
export {};
|
|
@@ -60,14 +60,18 @@ export function addJcamps(files, usedColors) {
|
|
|
60
60
|
}
|
|
61
61
|
return spectra;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param {object} state
|
|
66
|
+
*/
|
|
67
|
+
export function toJSON(state, preferencesState, options = {}) {
|
|
64
68
|
const { source, data = [], molecules: mols = [], correlations = {}, actionType = '', } = state;
|
|
65
|
-
const { dataType = 'ROW_DATA', view = false, settings = false } = options;
|
|
69
|
+
const { dataType = 'ROW_DATA', view = false, settings = false, serialize = true, exportTarget = 'nmrium', } = options;
|
|
66
70
|
const molecules = mols.map((mol) => Molecule.toJSON(mol));
|
|
67
71
|
const nmriumState = {
|
|
68
72
|
version: CURRENT_EXPORT_VERSION,
|
|
69
73
|
data: {
|
|
70
|
-
...(
|
|
74
|
+
...(exportTarget === 'onChange' ? { actionType } : {}),
|
|
71
75
|
source,
|
|
72
76
|
spectra: data,
|
|
73
77
|
molecules,
|
|
@@ -76,14 +80,19 @@ export function toJSON(state, preferencesState, target, options = {}) {
|
|
|
76
80
|
view: state.view,
|
|
77
81
|
settings: preferencesState.current,
|
|
78
82
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
if (!serialize) {
|
|
84
|
+
return nmriumState;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const includeData = dataType === 'ROW_DATA'
|
|
88
|
+
? 'rawData'
|
|
89
|
+
: dataType === 'NO_DATA'
|
|
90
|
+
? 'noData'
|
|
91
|
+
: 'dataSource';
|
|
92
|
+
return serializeNmriumState(nmriumState, {
|
|
93
|
+
includeData,
|
|
94
|
+
includeSettings: settings,
|
|
95
|
+
includeView: view,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
89
98
|
}
|
|
@@ -26,6 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.serializeNmriumState = void 0;
|
|
29
30
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
30
31
|
/** @jsxImportSource @emotion/react */
|
|
31
32
|
const react_1 = require("@emotion/react");
|
|
@@ -102,25 +103,23 @@ const containerStyles = (0, react_1.css) `
|
|
|
102
103
|
user-select: none;
|
|
103
104
|
}
|
|
104
105
|
`;
|
|
106
|
+
var nmr_load_save_2 = require("nmr-load-save");
|
|
107
|
+
Object.defineProperty(exports, "serializeNmriumState", { enumerable: true, get: function () { return nmr_load_save_2.serializeNmriumState; } });
|
|
105
108
|
const defaultData = {
|
|
106
109
|
spectra: [],
|
|
107
110
|
};
|
|
108
111
|
const NMRium = (0, react_2.forwardRef)(function NMRium(props, ref) {
|
|
109
112
|
return ((0, jsx_runtime_1.jsx)(ui_1.RootLayout, { style: { width: '100%' }, children: (0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: ErrorOverlay_1.default, children: (0, jsx_runtime_1.jsx)(InnerNMRium, { ...props, innerRef: ref }) }) }));
|
|
110
113
|
});
|
|
111
|
-
function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces, preferences, getSpinner = SpinnerContext_1.defaultGetSpinner,
|
|
114
|
+
function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces, preferences, getSpinner = SpinnerContext_1.defaultGetSpinner, onChange, emptyText, innerRef, }) {
|
|
112
115
|
const rootRef = (0, react_2.useRef)(null);
|
|
113
116
|
const elementsWrapperRef = (0, react_2.useRef)(null);
|
|
114
117
|
const viewerRef = (0, react_2.useRef)(null);
|
|
115
118
|
const [show, toggle] = (0, react_use_1.useToggle)(false);
|
|
116
|
-
const
|
|
119
|
+
const handleChange = (0, react_2.useRef)(onChange);
|
|
117
120
|
(0, react_2.useEffect)(() => {
|
|
118
|
-
|
|
119
|
-
}, [
|
|
120
|
-
const handleViewChange = (0, react_2.useRef)(onViewChange);
|
|
121
|
-
(0, react_2.useEffect)(() => {
|
|
122
|
-
handleViewChange.current = onViewChange;
|
|
123
|
-
}, [onViewChange]);
|
|
121
|
+
handleChange.current = onChange;
|
|
122
|
+
}, [onChange]);
|
|
124
123
|
const isFullscreen = (0, react_use_1.useFullscreen)(rootRef, show, {
|
|
125
124
|
onClose: () => {
|
|
126
125
|
toggle(false);
|
|
@@ -128,15 +127,26 @@ function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces
|
|
|
128
127
|
});
|
|
129
128
|
const [state, dispatch] = (0, react_2.useReducer)(Reducer_1.spectrumReducer, Reducer_1.initialState, Reducer_1.initState);
|
|
130
129
|
const [preferencesState, dispatchPreferences] = (0, react_2.useReducer)(preferencesReducer_1.default, preferencesReducer_1.preferencesInitialState, preferencesReducer_1.initPreferencesState);
|
|
131
|
-
const { displayerMode, data: spectraData, actionType, view } = state;
|
|
130
|
+
const { displayerMode, source, data: spectraData, molecules, correlations, actionType, view, } = state;
|
|
131
|
+
const stateRef = (0, react_2.useRef)();
|
|
132
|
+
(0, react_2.useEffect)(() => {
|
|
133
|
+
const { workspace, workspaces = {} } = preferencesState;
|
|
134
|
+
stateRef.current = (0, SpectraManager_1.toJSON)({ data: spectraData, molecules, correlations, source, view }, { current: workspaces[workspace.current] }, { serialize: false, exportTarget: 'onChange' });
|
|
135
|
+
}, [correlations, molecules, preferencesState, source, spectraData, view]);
|
|
132
136
|
(0, react_2.useEffect)(() => {
|
|
137
|
+
// trigger onChange callback if data object changed
|
|
133
138
|
if ((0, IgnoreActions_1.default)(actionType)) {
|
|
134
|
-
|
|
139
|
+
handleChange.current?.(stateRef.current, 'data');
|
|
135
140
|
}
|
|
136
|
-
}, [actionType,
|
|
141
|
+
}, [actionType, correlations, molecules, source, spectraData]);
|
|
137
142
|
(0, react_2.useEffect)(() => {
|
|
138
|
-
|
|
143
|
+
// trigger onChange callback if view object changed
|
|
144
|
+
handleChange.current?.(stateRef.current, 'view');
|
|
139
145
|
}, [view]);
|
|
146
|
+
(0, react_2.useEffect)(() => {
|
|
147
|
+
// trigger onChange callback if settings changed
|
|
148
|
+
handleChange.current?.(stateRef.current, 'settings');
|
|
149
|
+
}, [preferencesState]);
|
|
140
150
|
const dispatchMiddleWare = (0, react_2.useMemo)(() => {
|
|
141
151
|
return (0, Reducer_1.dispatchMiddleware)(dispatch);
|
|
142
152
|
}, []);
|
|
@@ -265,6 +265,6 @@ function ReactTable(props) {
|
|
|
265
265
|
return ((0, jsx_runtime_1.jsx)(ReactTableContext_1.ReactTableProvider, { value: tableVirtualBoundary, children: (0, jsx_runtime_1.jsx)("div", { ref: mRef, style: {
|
|
266
266
|
position: 'relative',
|
|
267
267
|
height: '100%',
|
|
268
|
-
}, css: style, children: (0, jsx_runtime_1.jsx)(ReactTableInner, { onScroll: scrollHandler, onSortEnd: onSortEnd, ref: containerRef, ...
|
|
268
|
+
}, css: style, children: (0, jsx_runtime_1.jsx)(ReactTableInner, { onScroll: scrollHandler, onSortEnd: onSortEnd, ref: containerRef, ...props }) }) }));
|
|
269
269
|
}
|
|
270
270
|
exports.default = (0, react_1.memo)(ReactTable);
|
|
@@ -36,7 +36,9 @@ function useExport() {
|
|
|
36
36
|
async function handle() {
|
|
37
37
|
//exported file name by default will be the first spectrum name
|
|
38
38
|
const fileName = state.data[0]?.display?.name;
|
|
39
|
-
const exportedData = (0, SpectraManager_1.toJSON)(state, preferencesState,
|
|
39
|
+
const exportedData = (0, SpectraManager_1.toJSON)(state, preferencesState, {
|
|
40
|
+
exportTarget: 'nmrium',
|
|
41
|
+
});
|
|
40
42
|
await (0, export_1.exportAsJSON)(exportedData, fileName, spaceIndent, isCompressed);
|
|
41
43
|
hideLoading();
|
|
42
44
|
}
|
|
@@ -71,7 +73,10 @@ function useExport() {
|
|
|
71
73
|
const hideLoading = await alert.showLoading(`Exporting as ${name}.nmrium process in progress`);
|
|
72
74
|
setTimeout(() => {
|
|
73
75
|
void (async () => {
|
|
74
|
-
const exportedData = (0, SpectraManager_1.toJSON)(state, preferencesState,
|
|
76
|
+
const exportedData = (0, SpectraManager_1.toJSON)(state, preferencesState, {
|
|
77
|
+
...include,
|
|
78
|
+
exportTarget: 'nmrium',
|
|
79
|
+
});
|
|
75
80
|
const spaceIndent = pretty ? 2 : 0;
|
|
76
81
|
await (0, export_1.exportAsJSON)(exportedData, name, spaceIndent, compressed);
|
|
77
82
|
hideLoading();
|
|
@@ -68,8 +68,8 @@ function DropZone(props) {
|
|
|
68
68
|
if (metaFile) {
|
|
69
69
|
parseMetaFileResult = await (0, parseMeta_1.parseMetaFile)(metaFile);
|
|
70
70
|
}
|
|
71
|
-
const { nmrLoaders:
|
|
72
|
-
const { nmriumState, containsNmrium } = await (0, nmr_load_save_1.read)(fileCollection, {
|
|
71
|
+
const { nmrLoaders: sourceSelector } = preferences.current;
|
|
72
|
+
const { nmriumState, containsNmrium } = await (0, nmr_load_save_1.read)(fileCollection, { sourceSelector });
|
|
73
73
|
if (nmriumState?.settings) {
|
|
74
74
|
dispatchPreferences({
|
|
75
75
|
type: 'SET_WORKSPACE',
|
|
@@ -30,7 +30,7 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
30
30
|
function onTabChangeHandler(tab) {
|
|
31
31
|
dispatch({ type: Types_1.SET_ACTIVE_TAB, tab: tab.tabid });
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
const openSettingHandler = (0, react_2.useCallback)((event, selectedSpectrum) => {
|
|
34
34
|
event.stopPropagation();
|
|
35
35
|
setSettingModalPosition({
|
|
36
36
|
x: event.nativeEvent.clientX,
|
|
@@ -38,8 +38,8 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
38
38
|
});
|
|
39
39
|
setSelectedSpectrum(selectedSpectrum);
|
|
40
40
|
setIsSettingModalDisplayed(true);
|
|
41
|
-
}
|
|
42
|
-
|
|
41
|
+
}, []);
|
|
42
|
+
const handleChangeVisibility = (0, react_2.useCallback)((d, key) => {
|
|
43
43
|
dispatch({
|
|
44
44
|
type: Types_1.CHANGE_VISIBILITY,
|
|
45
45
|
payload: {
|
|
@@ -47,7 +47,7 @@ function SpectrumsTabsInner({ data, activeSpectra, activeTab, }) {
|
|
|
47
47
|
key,
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
|
-
}
|
|
50
|
+
}, [dispatch]);
|
|
51
51
|
function handleChangeActiveSpectrum(e, spectrum) {
|
|
52
52
|
setTimeout(() => {
|
|
53
53
|
const modifier = `shift[${e.shiftKey ? 'true' : 'false'}]_ctrl[${e.ctrlKey ? 'true' : 'false'}]`;
|
|
@@ -10,6 +10,6 @@ const full_1 = require("react-ocl/full");
|
|
|
10
10
|
const CloseButton_1 = __importDefault(require("../../elements/CloseButton"));
|
|
11
11
|
const ModalStyle_1 = require("../../modal/ModalStyle");
|
|
12
12
|
function DatabaseStructureSearchModal({ onChange, idCode, onClose, }) {
|
|
13
|
-
return ((0, jsx_runtime_1.jsxs)("div", { css: ModalStyle_1.ModalStyles, children: [(0, jsx_runtime_1.jsxs)("div", { className: "header handle", children: [(0, jsx_runtime_1.jsx)("span", { children: "Search by structure" }), (0, jsx_runtime_1.jsx)(CloseButton_1.default, { onClick: onClose, className: "close-bt" })] }), (0, jsx_runtime_1.jsx)("div", { className: "main-content", children: (0, jsx_runtime_1.jsx)(full_1.StructureEditor, { initialIDCode: idCode, svgMenu: true, fragment: true, onChange: (
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: ModalStyle_1.ModalStyles, children: [(0, jsx_runtime_1.jsxs)("div", { className: "header handle", children: [(0, jsx_runtime_1.jsx)("span", { children: "Search by structure" }), (0, jsx_runtime_1.jsx)(CloseButton_1.default, { onClick: onClose, className: "close-bt" })] }), (0, jsx_runtime_1.jsx)("div", { className: "main-content", children: (0, jsx_runtime_1.jsx)(full_1.StructureEditor, { initialIDCode: idCode, svgMenu: true, fragment: true, onChange: (molFile, molecule, idCode) => onChange(idCode) }) })] }));
|
|
14
14
|
}
|
|
15
15
|
exports.DatabaseStructureSearchModal = DatabaseStructureSearchModal;
|
|
@@ -89,14 +89,18 @@ function addJcamps(files, usedColors) {
|
|
|
89
89
|
return spectra;
|
|
90
90
|
}
|
|
91
91
|
exports.addJcamps = addJcamps;
|
|
92
|
-
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* @param {object} state
|
|
95
|
+
*/
|
|
96
|
+
function toJSON(state, preferencesState, options = {}) {
|
|
93
97
|
const { source, data = [], molecules: mols = [], correlations = {}, actionType = '', } = state;
|
|
94
|
-
const { dataType = 'ROW_DATA', view = false, settings = false } = options;
|
|
98
|
+
const { dataType = 'ROW_DATA', view = false, settings = false, serialize = true, exportTarget = 'nmrium', } = options;
|
|
95
99
|
const molecules = mols.map((mol) => Molecule.toJSON(mol));
|
|
96
100
|
const nmriumState = {
|
|
97
101
|
version: nmr_load_save_1.CURRENT_EXPORT_VERSION,
|
|
98
102
|
data: {
|
|
99
|
-
...(
|
|
103
|
+
...(exportTarget === 'onChange' ? { actionType } : {}),
|
|
100
104
|
source,
|
|
101
105
|
spectra: data,
|
|
102
106
|
molecules,
|
|
@@ -105,15 +109,20 @@ function toJSON(state, preferencesState, target, options = {}) {
|
|
|
105
109
|
view: state.view,
|
|
106
110
|
settings: preferencesState.current,
|
|
107
111
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
if (!serialize) {
|
|
113
|
+
return nmriumState;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const includeData = dataType === 'ROW_DATA'
|
|
117
|
+
? 'rawData'
|
|
118
|
+
: dataType === 'NO_DATA'
|
|
119
|
+
? 'noData'
|
|
120
|
+
: 'dataSource';
|
|
121
|
+
return (0, nmr_load_save_1.serializeNmriumState)(nmriumState, {
|
|
122
|
+
includeData,
|
|
123
|
+
includeSettings: settings,
|
|
124
|
+
includeView: view,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
118
127
|
}
|
|
119
128
|
exports.toJSON = toJSON;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nmrium",
|
|
3
3
|
"description": "React component to display and process nuclear magnetic resonance (NMR) spectra.",
|
|
4
|
-
"version": "0.33.0-pre.
|
|
4
|
+
"version": "0.33.0-pre.1677504537",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib-cjs/component/NMRium.js",
|
|
7
7
|
"module": "lib/component/NMRium.js",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"ml-stat": "^1.3.3",
|
|
82
82
|
"multiplet-analysis": "^2.0.0",
|
|
83
83
|
"nmr-correlation": "^2.3.3",
|
|
84
|
-
"nmr-load-save": "^0.7.
|
|
84
|
+
"nmr-load-save": "^0.7.27",
|
|
85
85
|
"nmr-processing": "^9.3.6",
|
|
86
86
|
"nmredata": "^0.9.2",
|
|
87
87
|
"numeral": "^2.0.6",
|