nmrium 0.57.1 → 0.59.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 (139) hide show
  1. package/lib/component/1d/integral/IntegralResizable.js +2 -2
  2. package/lib/component/1d/matrix/useMatrix.d.ts +1 -1
  3. package/lib/component/1d/multiAnalysis/AnalysisRange.js +1 -1
  4. package/lib/component/1d/ranges/Atoms.js +6 -4
  5. package/lib/component/1d-2d/components/SpectrumInfoBlock.d.ts +1 -1
  6. package/lib/component/1d-2d/components/SpectrumInfoBlock.js +114 -7
  7. package/lib/component/2d/Viewer2D.js +6 -2
  8. package/lib/component/2d/zones/Zone.js +2 -2
  9. package/lib/component/EventsTrackers/KeysListenerTracker.js +8 -8
  10. package/lib/component/context/ChartContext.js +12 -1
  11. package/lib/component/context/ShareDataContext.d.ts +1 -1
  12. package/lib/component/context/ShareDataContext.js +2 -4
  13. package/lib/component/context/ToasterContext.d.ts +1 -0
  14. package/lib/component/context/ToasterContext.js +12 -3
  15. package/lib/component/elements/ActionsButtonsPopover.d.ts +7 -1
  16. package/lib/component/elements/ActionsButtonsPopover.js +7 -6
  17. package/lib/component/elements/Alert.d.ts +20 -0
  18. package/lib/component/elements/Alert.js +80 -0
  19. package/lib/component/elements/ContextMenuBluePrint.d.ts +7 -2
  20. package/lib/component/elements/ContextMenuBluePrint.js +9 -3
  21. package/lib/component/elements/Input2.js +2 -2
  22. package/lib/component/elements/Input2Controller.d.ts +4 -2
  23. package/lib/component/elements/Input2Controller.js +22 -6
  24. package/lib/component/elements/MoleculeSelection.js +2 -2
  25. package/lib/component/elements/NextPrev.d.ts +4 -5
  26. package/lib/component/elements/NextPrev.js +76 -79
  27. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +1 -1
  28. package/lib/component/elements/ReactTable/ReactTableFlexLayout.d.ts +0 -3
  29. package/lib/component/elements/ReactTable/ReactTableFlexLayout.js +1 -1
  30. package/lib/component/elements/Select2.d.ts +12 -7
  31. package/lib/component/elements/Select2.js +5 -4
  32. package/lib/component/elements/Select2Controller.d.ts +2 -2
  33. package/lib/component/elements/Select2Controller.js +5 -5
  34. package/lib/component/elements/ToolbarPopoverItem.d.ts +7 -6
  35. package/lib/component/elements/ToolbarPopoverItem.js +13 -5
  36. package/lib/component/elements/print/PrintContent.d.ts +17 -0
  37. package/lib/component/elements/print/PrintContent.js +281 -0
  38. package/lib/component/elements/print/PrintProvider.d.ts +12 -0
  39. package/lib/component/elements/print/PrintProvider.js +28 -0
  40. package/lib/component/elements/print/index.d.ts +2 -0
  41. package/lib/component/elements/print/index.js +2 -0
  42. package/lib/component/header/ApodizationOptionsPanel.js +14 -7
  43. package/lib/component/header/BaseLineCorrectionPanel.js +20 -10
  44. package/lib/component/header/ZeroFillingOptionsPanel.js +17 -10
  45. package/lib/component/hooks/useSaveSettings.js +43 -26
  46. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +14 -9
  47. package/lib/component/hooks/useToggleSpectraVisibility.js +45 -16
  48. package/lib/component/hooks/useWorkspaceAction.js +12 -14
  49. package/lib/component/loader/DropZone.js +3 -67
  50. package/lib/component/loader/useLoadFiles.d.ts +1 -0
  51. package/lib/component/loader/useLoadFiles.js +78 -0
  52. package/lib/component/main/InnerNMRium.d.ts +4 -3
  53. package/lib/component/main/InnerNMRium.js +4 -9
  54. package/lib/component/main/InnerNMRiumContents.d.ts +3 -2
  55. package/lib/component/main/InnerNMRiumContents.js +33 -29
  56. package/lib/component/main/NMRium.d.ts +2 -5
  57. package/lib/component/main/NMRium.js +1 -1
  58. package/lib/component/main/NMRiumRefAPI.d.ts +7 -0
  59. package/lib/component/main/NMRiumRefAPI.js +12 -0
  60. package/lib/component/main/NMRiumViewer.d.ts +10 -0
  61. package/lib/component/main/NMRiumViewer.js +35 -0
  62. package/lib/component/main/index.d.ts +1 -0
  63. package/lib/component/modal/CopyClipboardModal.d.ts +3 -2
  64. package/lib/component/modal/CopyClipboardModal.js +18 -32
  65. package/lib/component/modal/ExportAsJcampModal.d.ts +6 -3
  66. package/lib/component/modal/ExportAsJcampModal.js +69 -35
  67. package/lib/component/modal/ImportPublicationStringModal.js +1 -1
  68. package/lib/component/modal/LoadJCAMPModal.d.ts +3 -1
  69. package/lib/component/modal/LoadJCAMPModal.js +17 -18
  70. package/lib/component/modal/SaveAsModal.d.ts +3 -1
  71. package/lib/component/modal/SaveAsModal.js +20 -30
  72. package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
  73. package/lib/component/modal/changeSum/ChangeSumModalContents.js +35 -47
  74. package/lib/component/modal/changeSum/SelectMolecule.d.ts +2 -5
  75. package/lib/component/modal/changeSum/SelectMolecule.js +9 -8
  76. package/lib/component/modal/setting/GeneralSettings.js +4 -2
  77. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.d.ts +1 -0
  78. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.js +89 -0
  79. package/lib/component/modal/setting/settingsValidation.js +15 -1
  80. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +8 -5
  81. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +5 -1
  82. package/lib/component/panels/MoleculesPanel/MoleculePanel.js +5 -3
  83. package/lib/component/panels/Panels.js +15 -15
  84. package/lib/component/panels/PeaksPanel/PeaksPanel.js +8 -5
  85. package/lib/component/panels/RangesPanel/RangesHeader.js +52 -12
  86. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +13 -6
  87. package/lib/component/panels/SpectraPanel/SpectraTable.js +63 -21
  88. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +6 -2
  89. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +6 -2
  90. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -0
  91. package/lib/component/panels/ZonesPanel/ZonesPanel.js +16 -8
  92. package/lib/component/panels/databasePanel/DatabasePanel.js +7 -8
  93. package/lib/component/panels/filtersPanel/FilterPanel.js +9 -6
  94. package/lib/component/panels/filtersPanel/FiltersTable.js +12 -10
  95. package/lib/component/panels/header/DefaultPanelHeader.d.ts +1 -0
  96. package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
  97. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +10 -12
  98. package/lib/component/panels/predictionPanel/PredictionPanel.js +2 -2
  99. package/lib/component/reducer/IgnoreActions.js +1 -0
  100. package/lib/component/reducer/Reducer.js +2 -4
  101. package/lib/component/reducer/actions/DatabaseActions.d.ts +15 -13
  102. package/lib/component/reducer/actions/DatabaseActions.js +52 -34
  103. package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
  104. package/lib/component/reducer/actions/FiltersActions.js +9 -4
  105. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  106. package/lib/component/reducer/actions/SpectraActions.js +53 -43
  107. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.d.ts +3 -0
  108. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.js +16 -0
  109. package/lib/component/reducer/preferences/actions/changeInformationBlockPosition.d.ts +3 -0
  110. package/lib/component/reducer/preferences/actions/changeInformationBlockPosition.js +5 -0
  111. package/lib/component/reducer/preferences/actions/changePrintPageSettings.d.ts +3 -0
  112. package/lib/component/reducer/preferences/actions/changePrintPageSettings.js +6 -0
  113. package/lib/component/reducer/preferences/actions/toggleInformationBlock.d.ts +3 -0
  114. package/lib/component/reducer/preferences/actions/toggleInformationBlock.js +7 -0
  115. package/lib/component/reducer/preferences/preferencesReducer.d.ts +12 -2
  116. package/lib/component/reducer/preferences/preferencesReducer.js +9 -0
  117. package/lib/component/toolbar/ToolBar.js +33 -14
  118. package/lib/component/workspaces/workspaceDefaultProperties.js +2 -0
  119. package/lib/data/SpectraManager.d.ts +7 -10
  120. package/lib/data/SpectraManager.js +51 -30
  121. package/lib/data/data1d/Spectrum1D/SumManager.d.ts +0 -1
  122. package/lib/data/data1d/Spectrum1D/SumManager.js +2 -10
  123. package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +1 -1
  124. package/lib/data/data1d/Spectrum1D/index.d.ts +1 -1
  125. package/lib/data/data1d/Spectrum1D/index.js +1 -1
  126. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +10 -10
  127. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +2 -1
  128. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +10 -10
  129. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +10 -10
  130. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.d.ts +13 -0
  131. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.js +65 -0
  132. package/lib/data/molecules/MoleculeManager.js +16 -38
  133. package/lib/data/utilities/getCustomColor.d.ts +1 -1
  134. package/lib/data/utilities/removeByPaths.d.ts +3 -0
  135. package/lib/data/utilities/removeByPaths.js +33 -0
  136. package/lib/versionInfo.js +1 -1
  137. package/package.json +36 -36
  138. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +0 -11
  139. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +0 -29
@@ -1,37 +1,66 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { FaEye, FaEyeSlash } from 'react-icons/fa';
2
+ import { FaEye, FaEyeSlash, FaMinus, FaPlus } from 'react-icons/fa';
3
+ import { GrRadialSelected } from 'react-icons/gr';
4
+ import { TooltipHelpContent } from 'react-science/ui';
3
5
  import { useChartData } from '../context/ChartContext';
4
6
  import { useDispatch } from '../context/DispatchContext';
5
- export function useToggleSpectraVisibility(mode = 'all') {
7
+ export function useToggleSpectraVisibility(props = {}) {
8
+ const { enableHideAll = true, enableHideSelected = true, enableShowAll = true, enableShowSelectedOnly = true, enableShowSelected = true, } = props;
6
9
  const dispatch = useDispatch();
7
10
  const { view: { spectra: { activeTab }, }, } = useChartData();
8
- function showSpectraHandler() {
11
+ function showSpectraHandler(mode) {
9
12
  dispatch({
10
13
  type: 'CHANGE_SPECTRA_VISIBILITY_BY_NUCLEUS',
11
14
  payload: { nucleus: activeTab, flag: true, mode },
12
15
  });
13
16
  }
14
- function hideSpectraHandler() {
17
+ function hideSpectraHandler(mode) {
15
18
  dispatch({
16
19
  type: 'CHANGE_SPECTRA_VISIBILITY_BY_NUCLEUS',
17
20
  payload: { nucleus: activeTab, flag: false, mode },
18
21
  });
19
22
  }
20
23
  function getToggleVisibilityButtons(disabled = false) {
21
- return [
22
- {
24
+ const output = [];
25
+ if (enableShowAll) {
26
+ output.push({
27
+ icon: _jsx(FaEye, {}),
28
+ tooltip: _jsx(TooltipHelpContent, { title: "Show all spectra" }),
29
+ onClick: () => showSpectraHandler('all'),
30
+ });
31
+ }
32
+ if (enableShowSelected) {
33
+ output.push({
23
34
  disabled,
24
- icon: _jsx(FaEyeSlash, {}),
25
- tooltip: `Hide ${mode} spectra`,
26
- onClick: hideSpectraHandler,
27
- },
28
- {
35
+ icon: _jsx(FaPlus, {}),
36
+ tooltip: _jsx(TooltipHelpContent, { title: "Show selected spectra" }),
37
+ onClick: () => showSpectraHandler('selected'),
38
+ });
39
+ }
40
+ if (enableShowSelectedOnly) {
41
+ output.push({
29
42
  disabled,
30
- icon: _jsx(FaEye, {}),
31
- tooltip: `Show ${mode} spectra`,
32
- onClick: showSpectraHandler,
33
- },
34
- ];
43
+ icon: _jsx(GrRadialSelected, {}),
44
+ tooltip: _jsx(TooltipHelpContent, { title: "Focus on selected spectra" }),
45
+ onClick: () => showSpectraHandler('selectedOnly'),
46
+ });
47
+ }
48
+ if (enableHideSelected) {
49
+ output.push({
50
+ disabled,
51
+ icon: _jsx(FaMinus, {}),
52
+ tooltip: _jsx(TooltipHelpContent, { title: "Hide selected spectra" }),
53
+ onClick: () => hideSpectraHandler('selected'),
54
+ });
55
+ }
56
+ if (enableHideAll) {
57
+ output.push({
58
+ icon: _jsx(FaEyeSlash, {}),
59
+ tooltip: _jsx(TooltipHelpContent, { title: "Hide all spectra" }),
60
+ onClick: () => hideSpectraHandler('all'),
61
+ });
62
+ }
63
+ return output;
35
64
  }
36
65
  return {
37
66
  showSpectraHandler,
@@ -61,20 +61,18 @@ export function useWorkspaceAction() {
61
61
  });
62
62
  }
63
63
  function saveWorkspace(data) {
64
- if (data) {
65
- const settings = readSettings() || {
66
- version: 0,
67
- currentWorkspace: null,
68
- workspaces: {},
69
- };
70
- updateSettings({
71
- ...settings,
72
- workspaces: {
73
- ...settings.workspaces,
74
- [workspace.current]: data,
75
- },
76
- });
77
- }
64
+ const settings = readSettings() || {
65
+ version: 0,
66
+ currentWorkspace: null,
67
+ workspaces: {},
68
+ };
69
+ updateSettings({
70
+ ...settings,
71
+ workspaces: {
72
+ ...settings.workspaces,
73
+ [workspace.current]: data ?? current,
74
+ },
75
+ });
78
76
  dispatch({
79
77
  type: 'SET_PREFERENCES',
80
78
  ...(data && { payload: data }),
@@ -1,21 +1,14 @@
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 { fileCollectionFromFileList } from 'filelist-utils';
5
- import { read as readDropFiles } from 'nmr-load-save';
6
4
  import { useCallback, useState } from 'react';
7
5
  import { useDropzone } from 'react-dropzone';
8
6
  import { FaUpload } from 'react-icons/fa';
9
- import { isMetaFile, parseMetaFile } from '../../data/parseMeta';
10
7
  import { useChartData } from '../context/ChartContext';
11
- import { useDispatch } from '../context/DispatchContext';
12
8
  import { LoaderProvider } from '../context/LoaderContext';
13
- import { useLogger } from '../context/LoggerContext';
14
- import { usePreferences } from '../context/PreferencesContext';
15
- import { useToaster } from '../context/ToasterContext';
16
- import useCheckExperimentalFeature from '../hooks/useCheckExperimentalFeature';
17
9
  import { useCheckToolsVisibility } from '../hooks/useCheckToolsVisibility';
18
10
  import { MetaImportationModal } from '../modal/metaImportation/MetaImportationModal';
11
+ import { useLoadFiles } from './useLoadFiles';
19
12
  const style = css `
20
13
  height: 100%;
21
14
  background-color: #b5b5b599;
@@ -46,69 +39,12 @@ const containerStyle = css `
46
39
  `;
47
40
  function DropZone(props) {
48
41
  const { width, height } = useChartData();
49
- const dispatch = useDispatch();
50
- const { dispatch: dispatchPreferences, current: workspacePreferences } = usePreferences();
51
- const preferences = usePreferences();
52
42
  const isToolEnabled = useCheckToolsVisibility();
53
- const toaster = useToaster();
54
- const { logger } = useLogger();
55
- const experimentalFeatures = useCheckExperimentalFeature();
56
43
  const [metaInformationFile, openMetaInformationDialog] = useState();
57
- async function loadFilesHandler(files) {
58
- try {
59
- if (files.length === 1 && isMetaFile(files[0])) {
60
- openMetaInformationDialog(files[0]);
61
- }
62
- else {
63
- const fileCollection = await fileCollectionFromFileList(files);
64
- const metaFile = Object.values(fileCollection.files).find((file) => isMetaFile(file));
65
- let parseMetaFileResult = null;
66
- if (metaFile) {
67
- parseMetaFileResult = await parseMetaFile(metaFile);
68
- }
69
- const { nmrLoaders: sourceSelector } = preferences.current;
70
- const { onLoadProcessing, spectraColors } = workspacePreferences;
71
- const { nmriumState, containsNmrium } = await readDropFiles(fileCollection, {
72
- sourceSelector,
73
- logger: logger.child({ context: 'nmr-processing' }),
74
- onLoadProcessing,
75
- experimentalFeatures,
76
- });
77
- if (nmriumState?.settings) {
78
- dispatchPreferences({
79
- type: 'SET_WORKSPACE',
80
- payload: {
81
- data: nmriumState.settings,
82
- workspaceSource: 'nmriumFile',
83
- },
84
- });
85
- }
86
- dispatch({
87
- type: 'LOAD_DROP_FILES',
88
- payload: {
89
- nmriumState,
90
- containsNmrium,
91
- parseMetaFileResult,
92
- spectraColors,
93
- },
94
- });
95
- }
96
- }
97
- catch (error) {
98
- toaster.show({ message: error.message, intent: 'danger' });
99
- logger.error(error);
100
- }
101
- finally {
102
- dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: false } });
103
- }
104
- }
105
- function onDrop(droppedFiles) {
106
- dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: true } });
107
- void loadFilesHandler(droppedFiles);
108
- }
44
+ const loadFiles = useLoadFiles(openMetaInformationDialog);
109
45
  const isImportEnabled = isToolEnabled('import');
110
46
  const { getRootProps, getInputProps, isDragActive, open: openImportDialog, } = useDropzone({
111
- onDrop,
47
+ onDrop: loadFiles,
112
48
  noClick: true,
113
49
  noKeyboard: true,
114
50
  noDrag: !isImportEnabled,
@@ -0,0 +1 @@
1
+ export declare function useLoadFiles(onOpenMetaInformation?: (file: File) => void): (files: File[]) => void;
@@ -0,0 +1,78 @@
1
+ import { fileCollectionFromFileList } from 'filelist-utils';
2
+ import { read as readDropFiles } from 'nmr-load-save';
3
+ import { useCallback } from 'react';
4
+ import { isMetaFile, parseMetaFile } from '../../data/parseMeta';
5
+ import { useDispatch } from '../context/DispatchContext';
6
+ import { useLogger } from '../context/LoggerContext';
7
+ import { usePreferences } from '../context/PreferencesContext';
8
+ import { useToaster } from '../context/ToasterContext';
9
+ import useCheckExperimentalFeature from '../hooks/useCheckExperimentalFeature';
10
+ export function useLoadFiles(onOpenMetaInformation) {
11
+ const dispatch = useDispatch();
12
+ const { dispatch: dispatchPreferences, current: workspacePreferences } = usePreferences();
13
+ const preferences = usePreferences();
14
+ const toaster = useToaster();
15
+ const { logger } = useLogger();
16
+ const experimentalFeatures = useCheckExperimentalFeature();
17
+ return useCallback((files) => {
18
+ dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: true } });
19
+ async function loadFiles(files) {
20
+ if (onOpenMetaInformation &&
21
+ files.length === 1 &&
22
+ isMetaFile(files[0])) {
23
+ onOpenMetaInformation(files[0]);
24
+ }
25
+ else {
26
+ const fileCollection = await fileCollectionFromFileList(files);
27
+ const metaFile = Object.values(fileCollection.files).find((file) => isMetaFile(file));
28
+ let parseMetaFileResult = null;
29
+ if (metaFile) {
30
+ parseMetaFileResult = await parseMetaFile(metaFile);
31
+ }
32
+ const { nmrLoaders: sourceSelector } = preferences.current;
33
+ const { onLoadProcessing, spectraColors } = workspacePreferences;
34
+ const { nmriumState, containsNmrium } = await readDropFiles(fileCollection, {
35
+ sourceSelector,
36
+ logger: logger.child({ context: 'nmr-processing' }),
37
+ onLoadProcessing,
38
+ experimentalFeatures,
39
+ });
40
+ if (nmriumState?.settings) {
41
+ dispatchPreferences({
42
+ type: 'SET_WORKSPACE',
43
+ payload: {
44
+ data: nmriumState.settings,
45
+ workspaceSource: 'nmriumFile',
46
+ },
47
+ });
48
+ }
49
+ dispatch({
50
+ type: 'LOAD_DROP_FILES',
51
+ payload: {
52
+ nmriumState,
53
+ containsNmrium,
54
+ parseMetaFileResult,
55
+ spectraColors,
56
+ },
57
+ });
58
+ }
59
+ }
60
+ loadFiles(files)
61
+ .catch((error) => {
62
+ toaster.show({ message: error.message, intent: 'danger' });
63
+ logger.error(error);
64
+ })
65
+ .finally(() => {
66
+ dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: false } });
67
+ });
68
+ }, [
69
+ dispatch,
70
+ dispatchPreferences,
71
+ experimentalFeatures,
72
+ logger,
73
+ onOpenMetaInformation,
74
+ preferences,
75
+ toaster,
76
+ workspacePreferences,
77
+ ]);
78
+ }
@@ -1,7 +1,8 @@
1
1
  import { ForwardedRef } from 'react';
2
- import type { NMRiumProps, NMRiumRef } from './NMRium';
2
+ import type { NMRiumProps } from './NMRium';
3
+ import { NMRiumRefAPI } from './NMRiumRefAPI';
3
4
  type InnerNMRiumProps = Omit<NMRiumProps, 'onError'> & {
4
- innerRef: ForwardedRef<NMRiumRef>;
5
+ apiRef: ForwardedRef<NMRiumRefAPI>;
5
6
  };
6
- export declare function InnerNMRium({ data: nmriumData, workspace, customWorkspaces, preferences, getSpinner, onChange, emptyText, innerRef, }: InnerNMRiumProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function InnerNMRium({ data: nmriumData, workspace, customWorkspaces, preferences, getSpinner, onChange, emptyText, apiRef, }: InnerNMRiumProps): import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useReducer, useRef, useImperativeHandle, } from 'react';
2
+ import { useEffect, useReducer, useRef } from 'react';
3
3
  import { useFullscreen } from 'react-science/ui';
4
4
  import { AssignmentProvider } from '../assignment';
5
5
  import { GlobalProvider } from '../context/GlobalContext';
@@ -8,14 +8,14 @@ import { LoggerProvider } from '../context/LoggerContext';
8
8
  import { PreferencesProvider } from '../context/PreferencesContext';
9
9
  import { ToasterProvider } from '../context/ToasterContext';
10
10
  import { TopicMoleculeProvider } from '../context/TopicMoleculeContext';
11
+ import { AlertProvider } from '../elements/Alert';
11
12
  import { ModalProvider } from '../elements/popup/Modal';
12
13
  import { HighlightProvider } from '../highlight';
13
14
  import { defaultGetSpinner, SpinnerProvider } from '../loader/SpinnerContext';
14
15
  import preferencesReducer, { preferencesInitialState, initPreferencesState, readSettings, } from '../reducer/preferences/preferencesReducer';
15
- import { getBlob } from '../utility/export';
16
16
  import { InnerNMRiumContents } from './InnerNMRiumContents';
17
17
  import NMRiumStateProvider from './NMRiumStateProvider';
18
- export function InnerNMRium({ data: nmriumData, workspace, customWorkspaces, preferences, getSpinner = defaultGetSpinner, onChange, emptyText, innerRef, }) {
18
+ export function InnerNMRium({ data: nmriumData, workspace, customWorkspaces, preferences, getSpinner = defaultGetSpinner, onChange, emptyText, apiRef, }) {
19
19
  const rootRef = useRef(null);
20
20
  const elementsWrapperRef = useRef(null);
21
21
  const viewerRef = useRef(null);
@@ -38,14 +38,9 @@ export function InnerNMRium({ data: nmriumData, workspace, customWorkspaces, pre
38
38
  },
39
39
  });
40
40
  }, [customWorkspaces, preferences, workspace]);
41
- useImperativeHandle(innerRef, () => ({
42
- getSpectraViewerAsBlob: () => {
43
- return rootRef?.current ? getBlob(rootRef.current, 'nmrSVG') : null;
44
- },
45
- }), []);
46
41
  return (_jsx("div", { ref: mainDivRef, style: { height: '100%', position: 'relative' }, translate: "no", children: _jsx(GlobalProvider, { value: {
47
42
  rootRef: rootRef.current,
48
43
  elementsWrapperRef: elementsWrapperRef.current,
49
44
  viewerRef: viewerRef.current,
50
- }, children: _jsx(PreferencesProvider, { value: preferencesState, children: _jsx(LoggerProvider, { children: _jsx(KeyModifiersProvider, { children: _jsx(ToasterProvider, { children: _jsx(NMRiumStateProvider, { onChange: onChange, nmriumData: nmriumData, children: _jsx(TopicMoleculeProvider, { children: _jsx(ModalProvider, { wrapperRef: elementsWrapperRef.current, children: _jsx(HighlightProvider, { children: _jsx(AssignmentProvider, { children: _jsx(SpinnerProvider, { value: getSpinner, children: _jsx(InnerNMRiumContents, { emptyText: emptyText, mainDivRef: mainDivRef, elementsWrapperRef: elementsWrapperRef, rootRef: rootRef, viewerRef: viewerRef }) }) }) }) }) }) }) }) }) }) }) }) }));
45
+ }, children: _jsx(PreferencesProvider, { value: preferencesState, children: _jsx(LoggerProvider, { children: _jsx(KeyModifiersProvider, { children: _jsx(ToasterProvider, { children: _jsx(NMRiumStateProvider, { onChange: onChange, nmriumData: nmriumData, children: _jsx(TopicMoleculeProvider, { children: _jsx(ModalProvider, { wrapperRef: elementsWrapperRef.current, children: _jsx(AlertProvider, { children: _jsx(HighlightProvider, { children: _jsx(AssignmentProvider, { children: _jsx(SpinnerProvider, { value: getSpinner, children: _jsx(InnerNMRiumContents, { emptyText: emptyText, mainDivRef: mainDivRef, elementsWrapperRef: elementsWrapperRef, rootRef: rootRef, viewerRef: viewerRef, apiRef: apiRef }) }) }) }) }) }) }) }) }) }) }) }) }) }));
51
46
  }
@@ -1,12 +1,13 @@
1
1
  /** @jsxImportSource @emotion/react */
2
- import { RefObject } from 'react';
3
- import { NMRiumProps } from '.';
2
+ import { ForwardedRef, RefObject } from 'react';
3
+ import { NMRiumProps, NMRiumRefAPI } from '.';
4
4
  interface InnerNMRiumContentsProps {
5
5
  emptyText: NMRiumProps['emptyText'];
6
6
  mainDivRef: RefObject<HTMLDivElement>;
7
7
  elementsWrapperRef: RefObject<HTMLDivElement>;
8
8
  rootRef: RefObject<HTMLDivElement>;
9
9
  viewerRef: RefObject<HTMLDivElement>;
10
+ apiRef: ForwardedRef<NMRiumRefAPI>;
10
11
  }
11
12
  export declare function InnerNMRiumContents(props: InnerNMRiumContentsProps): import("@emotion/react/jsx-runtime").JSX.Element;
12
13
  export {};
@@ -1,18 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { Global, css } from '@emotion/react';
4
- import { useCallback } from 'react';
4
+ import { useCallback, } from 'react';
5
5
  import { useFullscreen } from 'react-science/ui';
6
6
  import checkModifierKeyActivated from '../../data/utilities/checkModifierKeyActivated';
7
- import Viewer1D from '../1d/Viewer1D';
8
- import FloatMoleculeStructures from '../1d-2d/components/FloatMoleculeStructures';
9
- import Viewer2D from '../2d/Viewer2D';
10
7
  import KeysListenerTracker from '../EventsTrackers/KeysListenerTracker';
11
- import { useChartData } from '../context/ChartContext';
8
+ import { usePreferences } from '../context/PreferencesContext';
9
+ import { PrintContent } from '../elements/print/PrintContent';
12
10
  import Header from '../header/Header';
13
11
  import DropZone from '../loader/DropZone';
14
12
  import Panels from '../panels/Panels';
15
13
  import ToolBar from '../toolbar/ToolBar';
14
+ import { useNMRiumRefAPI } from './NMRiumRefAPI';
15
+ import { NMRiumViewer } from './NMRiumViewer';
16
16
  import { SplitPaneWrapper } from './SplitPaneWrapper';
17
17
  import { StateError } from './StateError';
18
18
  const viewerContainerStyle = css `
@@ -63,40 +63,44 @@ const containerStyles = css `
63
63
  }
64
64
  `;
65
65
  export function InnerNMRiumContents(props) {
66
- const { emptyText, mainDivRef, elementsWrapperRef, rootRef, viewerRef } = props;
67
- const { displayerMode } = useChartData();
66
+ const { emptyText, mainDivRef, elementsWrapperRef, rootRef, viewerRef, apiRef, } = props;
68
67
  const { isFullScreen } = useFullscreen();
69
68
  const preventContextMenuHandler = useCallback((e) => {
70
69
  if (!checkModifierKeyActivated(e)) {
71
70
  e.preventDefault();
72
71
  }
73
72
  }, []);
73
+ useNMRiumRefAPI(apiRef, rootRef);
74
74
  return (_jsxs(_Fragment, { children: [_jsx(StateError, {}), _jsx(Global, { styles: css `
75
75
  .actions-buttons-popover {
76
76
  border-radius: 10px;
77
77
  padding: 5px;
78
78
  background-color: white;
79
79
  }
80
- ` }), _jsx("div", { className: "nmrium-container", ref: rootRef, css: containerStyles, onContextMenu: preventContextMenuHandler, style: { height: '100%', width: '100%' }, children: _jsx(DropZone, { children: _jsxs("div", { style: {
81
- display: 'flex',
82
- flexDirection: 'column',
83
- backgroundColor: 'white',
84
- width: '100%',
85
- }, children: [_jsx(Header, {}), _jsxs("div", { style: {
86
- display: 'flex',
87
- flexDirection: 'row',
88
- height: '100%',
89
- }, children: [_jsx(ToolBar, {}), _jsxs(SplitPaneWrapper, { children: [_jsxs("div", { css: viewerContainerStyle, children: [_jsx(KeysListenerTracker, { mainDivRef: mainDivRef }), _jsxs("div", { id: "nmrium-viewer", "data-testid": "viewer", ref: viewerRef, style: {
90
- width: '100%',
91
- height: '100%',
92
- position: 'relative',
93
- }, children: [_jsx(FloatMoleculeStructures, {}), displayerMode === '1D' ? (_jsx(Viewer1D, { emptyText: emptyText })) : (_jsx(Viewer2D, { emptyText: emptyText }))] })] }), _jsx(Panels, {})] }), _jsx("div", { ref: elementsWrapperRef, id: "main-wrapper", style: {
94
- position: 'absolute',
95
- pointerEvents: 'none',
96
- zIndex: 10,
97
- left: 0,
98
- right: 0,
99
- top: 0,
100
- bottom: 0,
101
- } }, String(isFullScreen))] })] }) }) })] }));
80
+ ` }), _jsxs("div", { className: "nmrium-container", ref: rootRef, css: containerStyles, onContextMenu: preventContextMenuHandler, style: { height: '100%', width: '100%' }, children: [_jsx(DropZone, { children: _jsxs("div", { style: {
81
+ display: 'flex',
82
+ flexDirection: 'column',
83
+ backgroundColor: 'white',
84
+ width: '100%',
85
+ }, children: [_jsx(Header, {}), _jsxs("div", { style: {
86
+ display: 'flex',
87
+ flexDirection: 'row',
88
+ height: '100%',
89
+ }, children: [_jsx(ToolBar, {}), _jsxs(SplitPaneWrapper, { children: [_jsxs("div", { css: viewerContainerStyle, children: [_jsx(KeysListenerTracker, { mainDivRef: mainDivRef }), _jsx(NMRiumViewer, { emptyText: emptyText, viewerRef: viewerRef })] }), _jsx(Panels, {})] }), _jsx("div", { ref: elementsWrapperRef, id: "main-wrapper", style: {
90
+ position: 'absolute',
91
+ pointerEvents: 'none',
92
+ zIndex: 10,
93
+ left: 0,
94
+ right: 0,
95
+ top: 0,
96
+ bottom: 0,
97
+ } }, String(isFullScreen))] })] }) }), _jsx("div", {}), _jsx(PrintWrapper, { children: _jsx(NMRiumViewer, { emptyText: emptyText, viewerRef: viewerRef }) })] })] }));
98
+ }
99
+ function PrintWrapper(props) {
100
+ const { children } = props;
101
+ const { current: { printPageOptions }, dispatch, } = usePreferences();
102
+ function handleSavePrintOptions(options) {
103
+ dispatch({ type: 'CHANGE_PRINT_PAGE_SETTINGS', payload: options });
104
+ }
105
+ return (_jsx(PrintContent, { defaultPrintPageOptions: printPageOptions, onPrint: handleSavePrintOptions, children: children }));
102
106
  }
@@ -1,7 +1,7 @@
1
1
  import type { CustomWorkspaces, WorkspacePreferences as NMRiumPreferences } from 'nmr-load-save';
2
2
  import { ReactElement, ReactNode } from 'react';
3
3
  import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
4
- import { BlobObject } from '../utility/export';
4
+ import { NMRiumRefAPI } from './NMRiumRefAPI';
5
5
  import { NMRiumChangeCb, NMRiumData, NMRiumWorkspace } from './types';
6
6
  export interface NMRiumProps {
7
7
  data?: NMRiumData;
@@ -17,7 +17,4 @@ export interface NMRiumProps {
17
17
  */
18
18
  getSpinner?: () => ReactElement;
19
19
  }
20
- export interface NMRiumRef {
21
- getSpectraViewerAsBlob: () => BlobObject | null;
22
- }
23
- export declare const NMRium: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<NMRiumProps & import("react").RefAttributes<NMRiumRef>>>;
20
+ export declare const NMRium: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<NMRiumProps & import("react").RefAttributes<NMRiumRefAPI>>>;
@@ -6,7 +6,7 @@ import ErrorOverlay from './ErrorOverlay';
6
6
  import { InnerNMRium } from './InnerNMRium';
7
7
  const NMRiumBase = forwardRef(function NMRium(props, ref) {
8
8
  const { noErrorBoundary = false, onError, ...otherProps } = props;
9
- const innerNmrium = _jsx(InnerNMRium, { ...otherProps, innerRef: ref });
9
+ const innerNmrium = _jsx(InnerNMRium, { ...otherProps, apiRef: ref });
10
10
  const children = noErrorBoundary ? (innerNmrium) : (_jsx(ErrorBoundary, { FallbackComponent: ErrorOverlay, onError: onError, children: innerNmrium }));
11
11
  return (_jsx(FullScreenProvider, { children: _jsx(RootLayout, { style: { width: '100%' }, children: children }) }));
12
12
  });
@@ -0,0 +1,7 @@
1
+ import { ForwardedRef, RefObject } from 'react';
2
+ import { BlobObject } from '../utility/export';
3
+ export interface NMRiumRefAPI {
4
+ getSpectraViewerAsBlob: () => BlobObject | null;
5
+ loadFiles: (files: File[]) => void;
6
+ }
7
+ export declare function useNMRiumRefAPI(ref: ForwardedRef<NMRiumRefAPI>, rootRef: RefObject<HTMLDivElement>): void;
@@ -0,0 +1,12 @@
1
+ import { useImperativeHandle } from 'react';
2
+ import { useLoadFiles } from '../loader/useLoadFiles';
3
+ import { getBlob } from '../utility/export';
4
+ export function useNMRiumRefAPI(ref, rootRef) {
5
+ const loadFiles = useLoadFiles();
6
+ useImperativeHandle(ref, () => ({
7
+ getSpectraViewerAsBlob: () => {
8
+ return rootRef.current ? getBlob(rootRef.current, 'nmrSVG') : null;
9
+ },
10
+ loadFiles,
11
+ }), [rootRef, loadFiles]);
12
+ }
@@ -0,0 +1,10 @@
1
+ import { CSSProperties, RefObject } from 'react';
2
+ import { NMRiumProps } from './NMRium';
3
+ interface NMRiumViewerProps {
4
+ emptyText: NMRiumProps['emptyText'];
5
+ viewerRef: RefObject<HTMLDivElement>;
6
+ style?: CSSProperties;
7
+ onRender?: () => void;
8
+ }
9
+ export declare function NMRiumViewer(props: NMRiumViewerProps): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useDeferredValue, useEffect } from 'react';
3
+ import Viewer1D from '../1d/Viewer1D';
4
+ import FloatMoleculeStructures from '../1d-2d/components/FloatMoleculeStructures';
5
+ import Viewer2D from '../2d/Viewer2D';
6
+ import { useChartData } from '../context/ChartContext';
7
+ export function NMRiumViewer(props) {
8
+ const { emptyText, viewerRef, onRender, style = {} } = props;
9
+ const { displayerMode, width, height } = useChartData();
10
+ const renderDimension = useDeferredValue({ width, height });
11
+ useEffect(() => {
12
+ function handleRenderComplete() {
13
+ if (typeof onRender !== 'function') {
14
+ return;
15
+ }
16
+ setTimeout(() => {
17
+ if (renderDimension.width !== width ||
18
+ renderDimension.height !== height) {
19
+ onRender();
20
+ }
21
+ }, 0);
22
+ }
23
+ const animationFrameId = requestAnimationFrame(handleRenderComplete);
24
+ return () => {
25
+ cancelAnimationFrame(animationFrameId);
26
+ };
27
+ }, [onRender, width, height, renderDimension.width, renderDimension.height]);
28
+ return (_jsxs("div", { id: "nmrium-viewer", "data-testid": "viewer", ref: viewerRef, style: {
29
+ width: '100%',
30
+ height: '100%',
31
+ position: 'relative',
32
+ backgroundColor: 'white',
33
+ ...style,
34
+ }, children: [_jsx(FloatMoleculeStructures, {}), displayerMode === '1D' ? (_jsx(Viewer1D, { emptyText: emptyText })) : (_jsx(Viewer2D, { emptyText: emptyText }))] }));
35
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export { serializeNmriumState as serializeNMRiumState } from 'nmr-load-save';
3
3
  export * from './NMRium';
4
+ export type { NMRiumRefAPI } from './NMRiumRefAPI';
@@ -1,7 +1,8 @@
1
1
  interface CopyClipboardModalProps {
2
- text: string;
2
+ text?: string;
3
+ title: string;
3
4
  onClose: () => void;
4
5
  onCopyClick: (text: string) => void;
5
6
  }
6
- declare function CopyClipboardModal({ text, onClose, onCopyClick, }: CopyClipboardModalProps): import("@emotion/react/jsx-runtime").JSX.Element;
7
+ declare function CopyClipboardModal(props: CopyClipboardModalProps): import("@emotion/react/jsx-runtime").JSX.Element | undefined;
7
8
  export default CopyClipboardModal;
@@ -1,39 +1,25 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
+ import { Button, Dialog, DialogBody, DialogFooter } from '@blueprintjs/core';
3
4
  import { css } from '@emotion/react';
5
+ import styled from '@emotion/styled';
4
6
  import { FaCopy } from 'react-icons/fa';
5
- import { CloseButton } from '../elements/CloseButton';
6
- const styles = css `
7
- overflow: auto;
8
- width: 400px;
9
-
10
- .inner-container {
11
- padding: 5px;
12
- width: 100%;
13
- height: 180px;
14
- border: none;
15
- }
16
-
17
- .main-buttons-container {
18
- padding: 5px 0;
19
- border-bottom: 0.55px solid #ebebeb;
20
- display: flex;
21
- justify-content: space-between;
22
- }
23
-
24
- button {
25
- background-color: transparent;
26
- border: none;
27
- padding: 0 5px;
28
- }
29
-
30
- button:disabled {
31
- opacity: 0.6;
32
- }
7
+ const Body = styled.div `
8
+ padding: 5px;
9
+ width: 100%;
10
+ height: 180px;
11
+ border: none;
33
12
  `;
34
- function CopyClipboardModal({ text, onClose, onCopyClick, }) {
35
- return (_jsxs("div", { css: styles, children: [_jsxs("div", { className: "main-buttons-container handle", children: [_jsx("button", { type: "button", onClick: () => onCopyClick(text), children: _jsx(FaCopy, {}) }), _jsx(CloseButton, { tooltip: "Close", onClick: onClose })] }), _jsx("div", { className: "inner-container",
36
- // eslint-disable-next-line react/no-danger
37
- dangerouslySetInnerHTML: { __html: text } })] }));
13
+ function CopyClipboardModal(props) {
14
+ const { text, ...otherProps } = props;
15
+ if (!text)
16
+ return;
17
+ return _jsx(InnerCopyClipboardModal, { text: text, ...otherProps });
18
+ }
19
+ function InnerCopyClipboardModal(props) {
20
+ const { text, title, onClose, onCopyClick } = props;
21
+ return (_jsxs(Dialog, { isOpen: true, title: title, onClose: onClose, children: [_jsx(DialogBody, { css: css `
22
+ background-color: white;
23
+ `, children: _jsx(Body, { dangerouslySetInnerHTML: { __html: text } }) }), _jsx(DialogFooter, { children: _jsx(Button, { onClick: () => onCopyClick(text), intent: "success", icon: _jsx(FaCopy, {}) }) })] }));
38
24
  }
39
25
  export default CopyClipboardModal;