diff --git a/src/NMRiumWrapper.tsx b/src/NMRiumWrapper.tsx index e857788..bac4988 100644 --- a/src/NMRiumWrapper.tsx +++ b/src/NMRiumWrapper.tsx @@ -37,7 +37,8 @@ export default function NMRiumWrapper() { const nmriumRef = useRef(null); const [data, setDate] = useState(); - const { workspace, preferences, defaultEmptyMessage } = usePreferences(); + const { workspace, preferences, defaultEmptyMessage, customWorkspaces } = + usePreferences(); const dataChangeHandler = useCallback((state, source) => { events.trigger('data-change', { state, @@ -125,6 +126,7 @@ export default function NMRiumWrapper() { onError={(error) => { events.trigger('error', error); }} + customWorkspaces={customWorkspaces} /> diff --git a/src/hooks/usePreferences.ts b/src/hooks/usePreferences.ts index f60f62d..dffd655 100644 --- a/src/hooks/usePreferences.ts +++ b/src/hooks/usePreferences.ts @@ -1,17 +1,21 @@ -import { WorkspacePreferences } from 'nmr-load-save'; +import { CustomWorkspaces, WorkspacePreferences } from 'nmr-load-save'; import { NMRiumWorkspace } from 'nmrium'; import { useLayoutEffect, useState } from 'react'; +import { getNmrXivWorkspace } from '../workspaces/nmrxiv'; + interface Preferences { preferences: WorkspacePreferences | undefined; workspace: NMRiumWorkspace | undefined; defaultEmptyMessage: string | undefined; + customWorkspaces: CustomWorkspaces; } const DEFAULT_PREFERENCES = { preferences: undefined, workspace: undefined, defaultEmptyMessage: undefined, + customWorkspaces: {}, }; export function usePreferences() { @@ -25,10 +29,12 @@ export function usePreferences() { let preferences: WorkspacePreferences | undefined; let workspace: NMRiumWorkspace | undefined; let defaultEmptyMessage: string | undefined; + let hidePanelOnLoad = false; if (parameters.has('workspace')) { workspace = parameters.get('workspace') as NMRiumWorkspace; } + if (parameters.has('preferences')) { preferences = JSON.parse(parameters.get('preferences') || ''); } @@ -36,8 +42,33 @@ export function usePreferences() { if (parameters.has('defaultEmptyMessage')) { defaultEmptyMessage = parameters.get('defaultEmptyMessage') as string; } - setConfiguration({ preferences, workspace, defaultEmptyMessage }); + if (parameters.has('hidePanelOnLoad')) { + hidePanelOnLoad = + parameters.get('hidePanelOnLoad')?.toLowerCase() === 'true'; + } + + const customWorkspaces = createCustomWorkspaces({ hidePanelOnLoad }); + setConfiguration({ + preferences, + workspace, + defaultEmptyMessage, + customWorkspaces, + }); }, []); return configuration; } + +interface CreateCustomWorkspacesOptions { + hidePanelOnLoad?: boolean; +} + +function createCustomWorkspaces( + options: CreateCustomWorkspacesOptions, +): CustomWorkspaces { + const { hidePanelOnLoad = false } = options; + + return { + nmrXiv: getNmrXivWorkspace(hidePanelOnLoad), + }; +} diff --git a/src/workspaces/nmrxiv.ts b/src/workspaces/nmrxiv.ts new file mode 100644 index 0000000..a1fabb5 --- /dev/null +++ b/src/workspaces/nmrxiv.ts @@ -0,0 +1,63 @@ +import { InnerWorkspace } from 'nmr-load-save'; + +export function getNmrXivWorkspace(hidePanelOnLoad = false): InnerWorkspace { + return { + version: 1, + label: 'nmrXiv', + general: { + dimmedSpectraOpacity: 0.1, + verticalSplitterPosition: '160px', + verticalSplitterCloseThreshold: 600, + spectraRendering: 'auto', + loggingLevel: 'info', + invert: false, + }, + display: { + general: { + experimentalFeatures: { display: true }, + hidePanelOnLoad, + hideHelp: true, + hideLogs: true, + hideMaximize: true, + hideWorkspaces: true, + hideGeneralSettings: true, + }, + + panels: { + spectraPanel: { display: true, open: true }, + informationPanel: { display: true, open: false }, + peaksPanel: { display: true, open: false }, + integralsPanel: { display: true, open: false }, + rangesPanel: { display: true, open: false }, + structuresPanel: { display: true, open: false }, + processingsPanel: { display: true, open: false }, + zonesPanel: { display: true, open: false }, + summaryPanel: { display: true, open: false }, + }, + toolBarButtons: { + peakPicking: true, + baselineCorrection: true, + exclusionZones: true, + exportAs: true, + fft: true, + import: true, + integral: true, + multipleSpectraAnalysis: true, + phaseCorrection: true, + rangePicking: true, + realImaginary: true, + slicing: true, + spectraCenterAlignments: true, + spectraStackAlignments: true, + apodization: true, + zeroFilling: true, + zonePicking: true, + zoomOut: true, + zoom: true, + autoRangeAndZonePicking: true, + fftDimension1: true, + fftDimension2: true, + }, + }, + }; +}