nmrium 0.38.2 → 0.40.1

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 (104) hide show
  1. package/lib/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
  2. package/lib/component/EventsTrackers/KeysListenerTracker.js +90 -67
  3. package/lib/component/NMRium.d.ts +1 -0
  4. package/lib/component/NMRium.js +4 -2
  5. package/lib/component/context/LoggerContext.js +12 -2
  6. package/lib/component/context/PreferencesContext.d.ts +4 -2
  7. package/lib/component/elements/formik/FormikError.d.ts +8 -0
  8. package/lib/component/elements/formik/FormikError.js +22 -0
  9. package/lib/component/elements/popup/Alert/AlertBlock.d.ts +7 -0
  10. package/lib/component/elements/popup/Alert/AlertBlock.js +24 -0
  11. package/lib/component/elements/popup/Alert/Provider.js +2 -20
  12. package/lib/component/elements/popup/Modal/ConfirmDialog.js +2 -1
  13. package/lib/component/header/Header.js +2 -2
  14. package/lib/component/hooks/useSaveSettings.js +18 -16
  15. package/lib/component/modal/AboutUsModal.js +4 -2
  16. package/lib/component/modal/LoadJCAMPModal.js +41 -28
  17. package/lib/component/modal/LogsHistoryModal.d.ts +6 -0
  18. package/lib/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +6 -4
  19. package/lib/component/modal/PredictSpectraModal.js +12 -2
  20. package/lib/component/modal/editRange/EditRangeModal.d.ts +7 -6
  21. package/lib/component/modal/editRange/EditRangeModal.js +33 -13
  22. package/lib/component/modal/setting/GeneralSettings.js +29 -28
  23. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +18 -16
  24. package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
  25. package/lib/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js +1 -1
  26. package/lib/component/panels/Panels.js +2 -2
  27. package/lib/component/panels/RangesPanel/RangesHeader.js +9 -15
  28. package/lib/component/panels/RangesPanel/RangesPanel.js +7 -10
  29. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.d.ts +1 -1
  30. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +9 -12
  31. package/lib/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
  32. package/lib/component/panels/predictionPanel/PredictionPanel.js +3 -1
  33. package/lib/component/reducer/actions/DatabaseActions.js +6 -4
  34. package/lib/component/reducer/actions/DomainActions.js +3 -0
  35. package/lib/component/reducer/actions/IntegralsActions.js +3 -1
  36. package/lib/component/reducer/actions/SpectrumsActions.js +6 -6
  37. package/lib/component/reducer/actions/ToolsActions.js +3 -32
  38. package/lib/component/reducer/actions/ZonesActions.js +2 -4
  39. package/lib/component/reducer/helper/ZoomHistoryManager.d.ts +8 -0
  40. package/lib/component/reducer/helper/ZoomHistoryManager.js +35 -0
  41. package/lib/component/reducer/preferences/actions/addWorkspace.js +2 -2
  42. package/lib/component/reducer/preferences/preferencesReducer.d.ts +2 -2
  43. package/lib/component/utility/export.d.ts +5 -4
  44. package/lib/component/utility/export.js +24 -52
  45. package/lib/data/PredictionManager.d.ts +3 -1
  46. package/lib/data/PredictionManager.js +27 -1
  47. package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.d.ts +1 -2
  48. package/lib/data/data1d/Spectrum1D/integrals/initiateIntegrals.d.ts +1 -1
  49. package/lib/data/data1d/Spectrum1D/ranges/detectSignal.js +13 -6
  50. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +1 -1
  51. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +23 -18
  52. package/lib/utils/clipboard/clipboard.d.ts +12 -0
  53. package/lib/utils/clipboard/clipboard.js +15 -0
  54. package/lib/utils/clipboard/clipboardComponents.d.ts +45 -0
  55. package/lib/utils/clipboard/clipboardComponents.js +150 -0
  56. package/lib/utils/clipboard/clipboardHooks.d.ts +94 -0
  57. package/lib/utils/clipboard/clipboardHooks.js +142 -0
  58. package/lib/utils/clipboard/types.d.ts +1 -0
  59. package/lib/utils/clipboard/types.js +1 -0
  60. package/lib/versionInfo.js +1 -1
  61. package/lib-cjs/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
  62. package/lib-cjs/component/EventsTrackers/KeysListenerTracker.js +90 -67
  63. package/lib-cjs/component/NMRium.js +4 -2
  64. package/lib-cjs/component/context/LoggerContext.js +11 -1
  65. package/lib-cjs/component/elements/formik/FormikError.js +27 -0
  66. package/lib-cjs/component/elements/popup/Alert/AlertBlock.js +30 -0
  67. package/lib-cjs/component/elements/popup/Alert/Provider.js +2 -20
  68. package/lib-cjs/component/elements/popup/Modal/ConfirmDialog.js +2 -1
  69. package/lib-cjs/component/header/Header.js +2 -2
  70. package/lib-cjs/component/hooks/useSaveSettings.js +17 -15
  71. package/lib-cjs/component/modal/AboutUsModal.js +4 -2
  72. package/lib-cjs/component/modal/LoadJCAMPModal.js +41 -28
  73. package/lib-cjs/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +8 -6
  74. package/lib-cjs/component/modal/PredictSpectraModal.js +12 -2
  75. package/lib-cjs/component/modal/editRange/EditRangeModal.js +32 -12
  76. package/lib-cjs/component/modal/setting/GeneralSettings.js +29 -28
  77. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +17 -15
  78. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
  79. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js +1 -1
  80. package/lib-cjs/component/panels/Panels.js +2 -2
  81. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +9 -15
  82. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +7 -10
  83. package/lib-cjs/component/panels/RangesPanel/hooks/useEditRangeModal.js +9 -12
  84. package/lib-cjs/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
  85. package/lib-cjs/component/panels/predictionPanel/PredictionPanel.js +3 -1
  86. package/lib-cjs/component/reducer/actions/DatabaseActions.js +6 -4
  87. package/lib-cjs/component/reducer/actions/DomainActions.js +3 -0
  88. package/lib-cjs/component/reducer/actions/IntegralsActions.js +3 -1
  89. package/lib-cjs/component/reducer/actions/SpectrumsActions.js +6 -6
  90. package/lib-cjs/component/reducer/actions/ToolsActions.js +26 -32
  91. package/lib-cjs/component/reducer/actions/ZonesActions.js +2 -4
  92. package/lib-cjs/component/reducer/helper/ZoomHistoryManager.js +37 -0
  93. package/lib-cjs/component/reducer/preferences/actions/addWorkspace.js +2 -2
  94. package/lib-cjs/component/utility/export.js +24 -54
  95. package/lib-cjs/data/PredictionManager.js +27 -1
  96. package/lib-cjs/data/data1d/Spectrum1D/ranges/detectSignal.js +13 -6
  97. package/lib-cjs/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +23 -18
  98. package/lib-cjs/utils/clipboard/clipboard.js +23 -0
  99. package/lib-cjs/utils/clipboard/clipboardComponents.js +158 -0
  100. package/lib-cjs/utils/clipboard/clipboardHooks.js +147 -0
  101. package/lib-cjs/utils/clipboard/types.js +2 -0
  102. package/lib-cjs/versionInfo.js +1 -1
  103. package/package.json +17 -17
  104. package/lib/component/header/LogsHistory.d.ts +0 -1
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AnalysisColumnsTypes } from 'nmr-load-save';
2
3
  import { memo } from 'react';
3
4
  import { useChartData } from '../../context/ChartContext';
4
5
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
5
6
  import AnalysisRange from './AnalysisRange';
6
- import { AnalysisColumnsTypes } from 'nmr-load-save';
7
7
  function MultiAnalysisRangesInner({ columns, displayerKey, activeTab, }) {
8
8
  const ranges = Object.keys(columns).filter((key) => columns[key].type !== AnalysisColumnsTypes.FORMULA);
9
9
  if (!ranges || ranges.length === 0) {
@@ -29,81 +29,98 @@ function KeysListenerTracker() {
29
29
  return displayerMode === DISPLAYER_MODE.DM_1D && data && data.length > 0;
30
30
  }, [data, displayerMode]);
31
31
  const deleteHandler = useCallback(async (sourceData) => {
32
- const { type, extra: { id, zone, spectrumID, colKey }, } = sourceData;
32
+ const { type, extra } = sourceData;
33
33
  switch (type) {
34
34
  case HighlightEventSource.INTEGRAL: {
35
- dispatch({
36
- type: 'DELETE_INTEGRAL',
37
- payload: {
38
- id,
39
- },
40
- });
41
- // remove keys from the highlighted list after delete
42
- remove();
35
+ const { id } = extra || {};
36
+ if (id) {
37
+ dispatch({
38
+ type: 'DELETE_INTEGRAL',
39
+ payload: {
40
+ id,
41
+ },
42
+ });
43
+ // remove keys from the highlighted list after delete
44
+ remove();
45
+ }
43
46
  break;
44
47
  }
45
48
  case HighlightEventSource.PEAK: {
46
- dispatch({
47
- type: 'DELETE_PEAK',
48
- payload: {
49
- id,
50
- },
51
- });
52
- // remove keys from the highlighted list after delete
53
- remove();
49
+ const { id } = extra || {};
50
+ if (id) {
51
+ dispatch({
52
+ type: 'DELETE_PEAK',
53
+ payload: {
54
+ id,
55
+ },
56
+ });
57
+ // remove keys from the highlighted list after delete
58
+ remove();
59
+ }
54
60
  break;
55
61
  }
56
62
  case HighlightEventSource.RANGE: {
57
- dispatch({
58
- type: 'DELETE_RANGE',
59
- payload: {
60
- id,
61
- assignmentData,
62
- },
63
- });
64
- // remove keys from the highlighted list after delete
65
- remove();
63
+ const { id } = extra || {};
64
+ if (id) {
65
+ dispatch({
66
+ type: 'DELETE_RANGE',
67
+ payload: {
68
+ id,
69
+ assignmentData,
70
+ },
71
+ });
72
+ // remove keys from the highlighted list after delete
73
+ remove();
74
+ }
66
75
  break;
67
76
  }
68
77
  case HighlightEventSource.ZONE: {
69
- dispatch({
70
- type: 'DELETE_2D_ZONE',
71
- payload: {
72
- id,
73
- assignmentData,
74
- },
75
- });
76
- // remove keys from the highlighted list after delete
77
- remove();
78
+ const { id } = extra || {};
79
+ if (id) {
80
+ dispatch({
81
+ type: 'DELETE_2D_ZONE',
82
+ payload: {
83
+ id,
84
+ assignmentData,
85
+ },
86
+ });
87
+ // remove keys from the highlighted list after delete
88
+ remove();
89
+ }
78
90
  break;
79
91
  }
80
92
  case HighlightEventSource.EXCLUSION_ZONE: {
93
+ const { zone, spectrumID } = extra || {};
81
94
  const buttons = [
82
95
  {
83
96
  text: 'Yes, for all spectra',
84
97
  handler: async () => {
85
- const hideLoading = await alert.showLoading('Delete all spectra exclusion zones in progress');
86
- dispatch({
87
- type: 'DELETE_EXCLUSION_ZONE',
88
- payload: {
89
- zone,
90
- },
91
- });
92
- hideLoading();
98
+ if (zone) {
99
+ const hideLoading = await alert.showLoading('Delete all spectra exclusion zones in progress');
100
+ dispatch({
101
+ type: 'DELETE_EXCLUSION_ZONE',
102
+ payload: {
103
+ zone,
104
+ },
105
+ });
106
+ hideLoading();
107
+ }
93
108
  },
94
109
  },
95
110
  {
96
111
  text: 'Yes',
97
112
  handler: async () => {
98
- const hideLoading = await alert.showLoading('Delete exclusion zones in progress');
99
- dispatch({
100
- type: 'DELETE_EXCLUSION_ZONE',
101
- payload: {
102
- zone,
103
- spectrumId: spectrumID,
104
- },
105
- });
106
- hideLoading();
113
+ if (spectrumID) {
114
+ const hideLoading = await alert.showLoading('Delete exclusion zones in progress');
115
+ dispatch({
116
+ type: 'DELETE_EXCLUSION_ZONE',
117
+ payload: {
118
+ zone,
119
+ spectrumId: spectrumID,
120
+ },
121
+ });
122
+ hideLoading();
123
+ }
107
124
  },
108
125
  },
109
126
  { text: 'No' },
@@ -115,19 +132,22 @@ function KeysListenerTracker() {
115
132
  break;
116
133
  }
117
134
  case HighlightEventSource.MATRIX_GENERATION_EXCLUSION_ZONE: {
135
+ const { zone } = extra || {};
118
136
  const buttons = [
119
137
  {
120
138
  text: 'Yes',
121
139
  handler: async () => {
122
- const hideLoading = await alert.showLoading('Delete all spectra exclusion zones in progress');
123
- dispatchPreferences({
124
- type: 'DELETE_MATRIX_GENERATION_EXCLUSION_ZONE',
125
- payload: {
126
- zone,
127
- nucleus: activeTab,
128
- },
129
- });
130
- hideLoading();
140
+ if (zone) {
141
+ const hideLoading = await alert.showLoading('Delete all spectra exclusion zones in progress');
142
+ dispatchPreferences({
143
+ type: 'DELETE_MATRIX_GENERATION_EXCLUSION_ZONE',
144
+ payload: {
145
+ zone,
146
+ nucleus: activeTab,
147
+ },
148
+ });
149
+ hideLoading();
150
+ }
131
151
  },
132
152
  },
133
153
  { text: 'No' },
@@ -139,12 +159,15 @@ function KeysListenerTracker() {
139
159
  break;
140
160
  }
141
161
  case HighlightEventSource.MULTIPLE_ANALYSIS_ZONE: {
142
- dispatchPreferences({
143
- type: 'DELETE_ANALYSIS_COLUMN',
144
- payload: { columnKey: colKey, nucleus: activeTab },
145
- });
146
- // remove keys from the highlighted list after delete
147
- remove();
162
+ const { colKey } = extra || {};
163
+ if (colKey) {
164
+ dispatchPreferences({
165
+ type: 'DELETE_ANALYSIS_COLUMN',
166
+ payload: { columnKey: colKey, nucleus: activeTab },
167
+ });
168
+ // remove keys from the highlighted list after delete
169
+ remove();
170
+ }
148
171
  break;
149
172
  }
150
173
  default:
@@ -12,6 +12,7 @@ export type OnNMRiumChange = (state: NmriumState, source: 'data' | 'view' | 'set
12
12
  export interface NMRiumProps {
13
13
  data?: NMRiumData;
14
14
  onChange?: OnNMRiumChange;
15
+ noErrorBoundary?: boolean;
15
16
  onError?: ErrorBoundaryPropsWithComponent['onError'];
16
17
  workspace?: NMRiumWorkspace;
17
18
  customWorkspaces?: CustomWorkspaces;
@@ -79,8 +79,10 @@ const defaultData = {
79
79
  spectra: [],
80
80
  };
81
81
  const NMRium = forwardRef(function NMRium(props, ref) {
82
- const { onError, ...otherProps } = props;
83
- return (_jsx(RootLayout, { style: { width: '100%' }, children: _jsx(ErrorBoundary, { FallbackComponent: ErrorOverlay, onError: onError, children: _jsx(InnerNMRium, { ...otherProps, innerRef: ref }) }) }));
82
+ const { noErrorBoundary = false, onError, ...otherProps } = props;
83
+ const innerNmrium = _jsx(InnerNMRium, { ...otherProps, innerRef: ref });
84
+ const children = noErrorBoundary ? (innerNmrium) : (_jsx(ErrorBoundary, { FallbackComponent: ErrorOverlay, onError: onError, children: innerNmrium }));
85
+ return _jsx(RootLayout, { style: { width: '100%' }, children: children });
84
86
  });
85
87
  function InnerNMRium({ data: dataProp = defaultData, workspace, customWorkspaces, preferences, getSpinner = defaultGetSpinner, onChange, emptyText, innerRef, }) {
86
88
  const rootRef = useRef(null);
@@ -1,6 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { FifoLogger } from 'fifo-logger';
3
3
  import { createContext, useContext, useRef, useMemo, useState, useCallback, useEffect, } from 'react';
4
+ import { LogsHistoryModal } from '../modal/LogsHistoryModal';
4
5
  import { usePreferences } from './PreferencesContext';
5
6
  export const LoggerContext = createContext(null);
6
7
  export function useLogger() {
@@ -14,8 +15,17 @@ export function LoggerProvider({ children }) {
14
15
  const { current: { general: { loggingLevel }, }, } = usePreferences();
15
16
  const [lastReadLogId, setLastLogId] = useState(0);
16
17
  const [logsHistory, setLogsHistory] = useState([]);
18
+ const [isLogHistoryOpened, openLogHistory] = useState(false);
17
19
  const loggerRef = useRef(new FifoLogger({
18
20
  onChange: (log, logs) => {
21
+ if (log && ['warn', 'error', 'fatal'].includes(log.levelLabel)) {
22
+ //open the log history automatically if we have warn,error, or fatal
23
+ openLogHistory(true);
24
+ if (log?.error) {
25
+ // eslint-disable-next-line no-console
26
+ console.error(log.error);
27
+ }
28
+ }
19
29
  setLogsHistory(logs.slice());
20
30
  },
21
31
  }));
@@ -38,5 +48,5 @@ export function LoggerProvider({ children }) {
38
48
  lastReadLogId,
39
49
  };
40
50
  }, [lastReadLogId, logsHistory, markAsRead]);
41
- return (_jsx(LoggerContext.Provider, { value: loggerState, children: children }));
51
+ return (_jsxs(LoggerContext.Provider, { value: loggerState, children: [isLogHistoryOpened && (_jsx(LogsHistoryModal, { autoOpen: true, onClose: () => openLogHistory(false) })), children] }));
42
52
  }
@@ -15,7 +15,7 @@ export declare function usePreferences(): {
15
15
  dispatch: (action?: ({
16
16
  type: "ADD_WORKSPACE";
17
17
  payload: {
18
- workspace: string;
18
+ workspaceKey: string;
19
19
  data?: Omit<import("nmr-load-save").Workspace, "label" | "version"> | undefined;
20
20
  };
21
21
  } | {
@@ -81,10 +81,12 @@ export declare function usePreferences(): {
81
81
  customWorkspaces: Record<string, import("nmr-load-save").Workspace>;
82
82
  dispatch: any;
83
83
  };
84
- } | {
84
+ } | ({
85
85
  type: "SET_PREFERENCES";
86
86
  payload: Partial<import("nmr-load-save").Workspace>;
87
87
  } | {
88
+ type: "SET_PREFERENCES";
89
+ }) | {
88
90
  type: "SET_PANELS_PREFERENCES";
89
91
  payload: {
90
92
  key: string;
@@ -0,0 +1,8 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ export interface FormikErrorProps {
3
+ style?: Partial<Record<'container' | 'text', CSSProperties>>;
4
+ name: string;
5
+ children: ReactNode;
6
+ }
7
+ declare function FormikError({ style, name, children }: FormikErrorProps): import("react/jsx-runtime").JSX.Element;
8
+ export default FormikError;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useFormikContext } from 'formik';
3
+ import lodashGet from 'lodash/get';
4
+ const styles = {
5
+ container: {
6
+ padding: '0.4rem',
7
+ display: 'flex',
8
+ flexDirection: 'column',
9
+ },
10
+ text: {
11
+ color: '#fd000c',
12
+ margin: '0.5px',
13
+ fontSize: '0.9em',
14
+ },
15
+ };
16
+ function FormikError({ style, name, children }) {
17
+ const { errors, isValid, dirty, touched } = useFormikContext();
18
+ const errorText = lodashGet(errors, name);
19
+ const isTouched = lodashGet(touched, name);
20
+ return (_jsxs("div", { style: { ...styles.container, ...style?.container }, children: [children, !isValid && dirty && isTouched && (_jsx("span", { style: { ...styles.text, ...style?.text }, children: errorText }))] }));
21
+ }
22
+ export default FormikError;
@@ -0,0 +1,7 @@
1
+ interface AlertBlockProps {
2
+ offset: string;
3
+ alert: any;
4
+ onClose: () => void;
5
+ }
6
+ export default function AlertBlock(props: AlertBlockProps): import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { FaTimes } from 'react-icons/fa';
3
+ import { types } from '../options';
4
+ import ProgressIndicator from './ProgressIndicator';
5
+ export default function AlertBlock(props) {
6
+ const { offset, alert, onClose } = props;
7
+ return (_jsxs("div", { style: {
8
+ margin: offset,
9
+ padding: '25px',
10
+ borderRadius: '10px',
11
+ pointerEvents: 'all',
12
+ backgroundColor: alert.options.backgroundColor,
13
+ color: alert.options.color,
14
+ minHeight: '60px',
15
+ position: 'relative',
16
+ }, children: [_jsx("button", { style: {
17
+ position: 'absolute',
18
+ right: '5px',
19
+ top: '5px',
20
+ border: 'none',
21
+ backgroundColor: 'transparent',
22
+ color: 'white',
23
+ }, type: "button", onClick: onClose, children: _jsx(FaTimes, {}) }), _jsx("span", { children: alert.message }), alert.options.type === types.PROGRESS_INDICATOR && _jsx(ProgressIndicator, {})] }, alert.id));
24
+ }
@@ -2,13 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import groupBy from 'lodash/groupBy';
3
3
  import { Fragment, useState, useRef, useEffect, useCallback, useMemo, memo, } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
- import { FaTimes } from 'react-icons/fa';
6
5
  import { TransitionGroup } from 'react-transition-group';
7
6
  import Transition from '../Transition';
8
7
  import Wrapper from '../Wrapper';
9
8
  import { positions, transitions, types } from '../options';
9
+ import AlertBlock from './AlertBlock';
10
10
  import { AlertProvider } from './Context';
11
- import ProgressIndicator from './ProgressIndicator';
12
11
  function Provider({ children, wrapperRef = null, offset = '5px', position = positions.BOTTOM_CENTER, timeout = 3000, type, transition = transitions.FADE, ...props }) {
13
12
  const root = useRef(null);
14
13
  const timersId = useRef([]);
@@ -121,24 +120,7 @@ function Provider({ children, wrapperRef = null, offset = '5px', position = posi
121
120
  createPortal(_jsx(Fragment, { children: Object.keys(positions).map((key) => {
122
121
  const position = positions[key];
123
122
  return (_jsx(TransitionGroup, { appear: true, options: { position, zIndex: 999999 }, component: Wrapper, containerStyle: parentStyle, ...props, children: alertsByPosition[position]
124
- ? alertsByPosition[position].map((alert) => (_jsx(Transition, { type: transition, children: _jsxs("div", { style: {
125
- margin: offset,
126
- padding: '25px',
127
- borderRadius: '10px',
128
- pointerEvents: 'all',
129
- backgroundColor: alert.options.backgroundColor,
130
- color: alert.options.color,
131
- minHeight: '60px',
132
- position: 'relative',
133
- }, children: [_jsx("button", { style: {
134
- position: 'absolute',
135
- right: '5px',
136
- top: '5px',
137
- border: 'none',
138
- backgroundColor: 'transparent',
139
- color: 'white',
140
- }, type: "button", onClick: () => closeHandler(alert), children: _jsx(FaTimes, {}) }), _jsx("span", { children: alert.message }), alert.options.type ===
141
- types.PROGRESS_INDICATOR && _jsx(ProgressIndicator, {})] }, alert.id) }, alert.id)))
123
+ ? alertsByPosition[position].map((alert) => (_jsx(Transition, { type: transition, children: _jsx(AlertBlock, { offset: offset, alert: alert, onClose: () => closeHandler(alert) }) }, alert.id)))
142
124
  : null }, position));
143
125
  }) }), root.current)] }));
144
126
  }
@@ -6,7 +6,8 @@ const styles = css `
6
6
  display: block;
7
7
  border-radius: 5px;
8
8
  overflow: hidden;
9
- width: 350px;
9
+ width: 30vw;
10
+ min-width: 350px;
10
11
  border-top: 10px solid #ed0000;
11
12
 
12
13
  .message {
@@ -12,6 +12,7 @@ import { Header } from '../elements/Header';
12
12
  import DropDownButton from '../elements/dropDownButton/DropDownButton';
13
13
  import { useSaveSettings } from '../hooks/useSaveSettings';
14
14
  import AboutUsModal from '../modal/AboutUsModal';
15
+ import { LogsHistoryModal } from '../modal/LogsHistoryModal';
15
16
  import GeneralSettingsModal from '../modal/setting/GeneralSettings';
16
17
  import WorkspaceItem from '../modal/setting/WorkspaceItem';
17
18
  import { options } from '../toolbar/ToolTypes';
@@ -19,7 +20,6 @@ import ApodizationOptionsPanel from './ApodizationOptionsPanel';
19
20
  import AutoPeakPickingOptionPanel from './AutoPeakPickingOptionPanel';
20
21
  import BaseLineCorrectionPanel from './BaseLineCorrectionPanel';
21
22
  import { HeaderContainer } from './HeaderContainer';
22
- import { LogsHistory } from './LogsHistory';
23
23
  import PhaseCorrectionPanel from './PhaseCorrectionPanel';
24
24
  import RangesPickingOptionPanel from './RangesPickingOptionPanel';
25
25
  import ZeroFillingOptionsPanel from './ZeroFillingOptionsPanel';
@@ -100,7 +100,7 @@ function HeaderInner(props) {
100
100
  alignItems: 'center',
101
101
  }, children: [_jsx("div", { children: _jsx(Toolbar, { orientation: "horizontal", children: _jsx(AboutUsModal, {}) }) }), _jsx("div", { className: "toolOptionsPanel", style: { flex: 1 }, children: selectedPanel })] }), _jsxs(HeaderContainer, { style: {
102
102
  alignItems: 'center',
103
- }, children: [!hideGeneralSettings && (_jsxs(_Fragment, { children: [_jsx(DropDownButton, { data: workspacesList, selectedKey: workspace.current, onSelect: changeWorkspaceHandler, renderItem: renderItem }), _jsx(SaveButton, {})] })), !general?.hideLogs && _jsx(LogsHistory, {}), _jsx("div", { children: _jsxs(Toolbar, { orientation: "horizontal", children: [_jsx(Toolbar.Item, { id: "user-manual", title: "User manual", onClick: () => window.open(docsBaseUrl, '_blank'), children: _jsx(FaQuestionCircle, {}) }), !hideGeneralSettings && (_jsx(GeneralSettingsModal, { height: height / 2 })), !isFullscreen && (_jsx(Toolbar.Item, { id: "full-screen", onClick: onMaximize, title: "Full Screen", className: "windowButton", children: _jsx(FaRegWindowMaximize, {}) }))] }) })] })] }) }));
103
+ }, children: [!hideGeneralSettings && (_jsxs(_Fragment, { children: [_jsx(DropDownButton, { data: workspacesList, selectedKey: workspace.current, onSelect: changeWorkspaceHandler, renderItem: renderItem }), _jsx(SaveButton, {})] })), !general?.hideLogs && _jsx(LogsHistoryModal, {}), _jsx("div", { children: _jsxs(Toolbar, { orientation: "horizontal", children: [_jsx(Toolbar.Item, { id: "user-manual", title: "User manual", onClick: () => window.open(docsBaseUrl, '_blank'), children: _jsx(FaQuestionCircle, {}) }), !hideGeneralSettings && (_jsx(GeneralSettingsModal, { height: height / 2 })), !isFullscreen && (_jsx(Toolbar.Item, { id: "full-screen", onClick: onMaximize, title: "Full Screen", className: "windowButton", children: _jsx(FaRegWindowMaximize, {}) }))] }) })] })] }) }));
104
104
  }
105
105
  function SaveButton() {
106
106
  const { workspace, workspaces, originalWorkspaces } = usePreferences();
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Formik } from 'formik';
3
- import { useRef, forwardRef, useState } from 'react';
3
+ import { useRef, forwardRef } from 'react';
4
4
  import { Modal, useOnOff } from 'react-science/ui';
5
5
  import * as Yup from 'yup';
6
6
  import { usePreferences } from '../context/PreferencesContext';
@@ -23,30 +23,32 @@ const WorkspaceAddForm = forwardRef(({ className, message, onSave }, ref) => {
23
23
  export function useSaveSettings() {
24
24
  const alert = useAlert();
25
25
  const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
26
- const [values, setValues] = useState(undefined);
26
+ const settingsRef = useRef();
27
27
  const { dispatch, current } = usePreferences();
28
28
  const formRef = useRef(null);
29
- function addNewWorkspace(workspaceName, values) {
30
- dispatch({
31
- type: 'ADD_WORKSPACE',
32
- payload: {
33
- workspace: workspaceName,
34
- data: values,
35
- },
36
- });
37
- closeDialog();
38
- alert.success('Preferences saved successfully');
29
+ function addNewWorkspace({ workspaceName }) {
30
+ if (settingsRef.current) {
31
+ dispatch({
32
+ type: 'ADD_WORKSPACE',
33
+ payload: {
34
+ workspaceKey: workspaceName,
35
+ data: settingsRef.current,
36
+ },
37
+ });
38
+ closeDialog();
39
+ alert.success('Preferences saved successfully');
40
+ }
39
41
  }
40
42
  return {
41
- saveSettings: (values = {}) => {
42
- setValues(values);
43
+ saveSettings: (values) => {
44
+ settingsRef.current = values;
43
45
  if (current.source !== 'user') {
44
46
  openDialog();
45
47
  }
46
48
  else {
47
49
  dispatch({
48
50
  type: 'SET_PREFERENCES',
49
- payload: values,
51
+ ...(values && { payload: values }),
50
52
  });
51
53
  closeDialog();
52
54
  }
@@ -54,7 +56,7 @@ export function useSaveSettings() {
54
56
  SaveSettingsModal: () => {
55
57
  const alertConfig = {
56
58
  message: 'Please enter a new user workspace name in order to save your changes locally',
57
- render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave: ({ workspaceName }) => addNewWorkspace(workspaceName, values), ref: formRef })),
59
+ render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave: addNewWorkspace, ref: formRef })),
58
60
  buttons: [
59
61
  {
60
62
  text: 'Save',
@@ -6,6 +6,9 @@ import { Modal, Toolbar, useOnOff } from 'react-science/ui';
6
6
  import versionInfo from '../../versionInfo';
7
7
  import Logo from '../elements/Logo';
8
8
  const styles = css `
9
+ width: 40vw;
10
+ min-width: 500px;
11
+
9
12
  button:focus {
10
13
  outline: none;
11
14
  }
@@ -82,7 +85,6 @@ const styles = css `
82
85
  display: flex;
83
86
  flex-direction: column;
84
87
  user-select: none;
85
- width: 500px;
86
88
  `;
87
89
  function AboutUsModal() {
88
90
  const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
@@ -90,7 +92,7 @@ function AboutUsModal() {
90
92
  display: 'flex',
91
93
  alignItems: 'center',
92
94
  justifyContent: 'center',
93
- }, children: _jsx(SvgLogoNmrium, {}) }) }), _jsx(Modal, { hasCloseButton: true, isOpen: isOpenDialog, onRequestClose: closeDialog, children: _jsxs("div", { css: styles, children: [_jsx(Modal.Header, { children: _jsx("div", { className: "header", children: _jsx("span", { children: "About NMRium" }) }) }), _jsxs("div", { className: "container", children: [_jsxs("div", { className: "center-container", children: [_jsx(Logo, { width: 160, height: 50 }), "Version ", _jsx(VersionInfo, {}), _jsx("span", { className: "separator" }), _jsx("a", { href: "https://git.nmrium.org", target: "_blank", rel: "noreferrer", children: "GitHub ( https://git.nmrium.org )" })] }), _jsx("div", { className: "center-container", children: _jsx("span", { className: "separator" }) }), _jsx("span", { className: "content", children: "This project is developed by Zakodium S\u00E0rl (Switzerland), the University of Cologne (Germany), Johannes Gutenberg University Mainz (Germany) and Universidad del Valle (Colombia)." }), _jsxs("div", { className: "center-container", children: [_jsx("span", { className: "separator" }), _jsx("span", { className: "title", children: "Funding is provided by" }), _jsx("span", { className: "separator" })] }), _jsx("div", { className: "content", children: _jsxs("ul", { children: [_jsx("li", { children: "IDNMR grant, which part of the Scientific Library Services and Information Systems (LIS) initiative of the DFG." }), _jsx("li", { children: "Zakodium S\u00E0rl (Switzerland)." }), _jsx("li", { children: "Universidad del Valle (Cali, Colombia)." })] }) })] })] }) })] }));
95
+ }, children: _jsx(SvgLogoNmrium, {}) }) }), _jsx(Modal, { hasCloseButton: true, isOpen: isOpenDialog, onRequestClose: closeDialog, maxWidth: 1000, children: _jsxs("div", { css: styles, children: [_jsx(Modal.Header, { children: _jsx("div", { className: "header", children: _jsx("span", { children: "About NMRium" }) }) }), _jsxs("div", { className: "container", children: [_jsxs("div", { className: "center-container", children: [_jsx(Logo, { width: 160, height: 50 }), "Version ", _jsx(VersionInfo, {}), _jsx("span", { className: "separator" }), _jsx("a", { href: "https://git.nmrium.org", target: "_blank", rel: "noreferrer", children: "GitHub ( https://git.nmrium.org )" })] }), _jsx("div", { className: "center-container", children: _jsx("span", { className: "separator" }) }), _jsx("span", { className: "content", children: "This project is developed by Zakodium S\u00E0rl (Switzerland), the University of Cologne (Germany), Johannes Gutenberg University Mainz (Germany) and Universidad del Valle (Colombia)." }), _jsxs("div", { className: "center-container", children: [_jsx("span", { className: "separator" }), _jsx("span", { className: "title", children: "Funding is provided by" }), _jsx("span", { className: "separator" })] }), _jsx("div", { className: "content", children: _jsxs("ul", { children: [_jsx("li", { children: "IDNMR grant, which part of the Scientific Library Services and Information Systems (LIS) initiative of the DFG." }), _jsx("li", { children: "Zakodium S\u00E0rl (Switzerland)." }), _jsx("li", { children: "Universidad del Valle (Cali, Colombia)." })] }) })] })] }) })] }));
94
96
  }
95
97
  export default AboutUsModal;
96
98
  function VersionInfo() {
@@ -8,12 +8,27 @@ import * as Yup from 'yup';
8
8
  import { useDispatch } from '../context/DispatchContext';
9
9
  import Button from '../elements/Button';
10
10
  import Label from '../elements/Label';
11
+ import FormikError from '../elements/formik/FormikError';
11
12
  import FormikInput from '../elements/formik/FormikInput';
12
13
  import { useAlert } from '../elements/popup/Alert/Context';
13
- import { extractFileMetaFromPath } from '../utility/FileUtility';
14
14
  const allowedExtensions = new Set(['dx', 'jdx', 'jcamp']);
15
15
  const loadFormValidation = Yup.object({
16
- url: Yup.string().url().required(),
16
+ url: Yup.string()
17
+ .url()
18
+ .required()
19
+ .test('file type', 'Imported file must be one of those extensions [ .jdx, .dx, .jcamp ]', (url) => {
20
+ try {
21
+ const fileURL = new URL(url);
22
+ const extension = fileURL.pathname.split('.')?.[1] || '';
23
+ if (allowedExtensions.has(extension)) {
24
+ return true;
25
+ }
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ return false;
31
+ }),
17
32
  });
18
33
  const labelStyle = {
19
34
  wrapper: { display: 'flex', height: '100%', flex: 1 },
@@ -25,33 +40,31 @@ export function LoadJCAMPModal({ onCloseDialog, isOpen }) {
25
40
  if (!isOpen)
26
41
  return;
27
42
  async function loadJCAMPHandler({ url }) {
28
- const { extension } = extractFileMetaFromPath(url);
29
- if (allowedExtensions.has(extension)) {
30
- const hidLoading = await alert.showLoading('Load JCAMP from external URL in progress ...');
31
- const { pathname, origin } = new URL(url);
32
- try {
33
- const nmriumState = await readFromWebSource({
34
- entries: [{ relativePath: pathname, baseURL: origin }],
35
- });
36
- dispatch({
37
- type: 'LOAD_DROP_FILES',
38
- payload: { nmriumState, resetSourceObject: false },
39
- });
40
- }
41
- catch {
42
- alert.error(`Failed to load ${url}`);
43
- }
44
- finally {
45
- hidLoading();
46
- onCloseDialog?.();
47
- }
43
+ const hidLoading = await alert.showLoading('Load JCAMP from external URL in progress ...');
44
+ const { pathname, origin } = new URL(url);
45
+ try {
46
+ const nmriumState = await readFromWebSource({
47
+ entries: [{ relativePath: pathname, baseURL: origin }],
48
+ });
49
+ dispatch({
50
+ type: 'LOAD_DROP_FILES',
51
+ payload: { nmriumState, resetSourceObject: false },
52
+ });
53
+ }
54
+ catch {
55
+ alert.error(`Failed to load ${url}`);
48
56
  }
49
- else {
50
- alert.error('Imported file must be one of those extensions [ .jdx, .dx, .jcamp ] ');
57
+ finally {
58
+ hidLoading();
59
+ onCloseDialog?.();
51
60
  }
52
61
  }
53
- return (_jsxs(Modal, { hasCloseButton: true, isOpen: true, onRequestClose: onCloseDialog, children: [_jsx(Modal.Header, { children: "Load JCAMP Dialog" }), _jsx(Modal.Body, { children: _jsx("div", { style: { minWidth: '400px', padding: '1.5em' }, children: _jsx(Formik, { initialValues: { url: '' }, validationSchema: loadFormValidation, onSubmit: loadJCAMPHandler, innerRef: ref, children: _jsx(Label, { title: "URL", style: labelStyle, children: _jsx(FormikInput, { name: "url", type: "string", style: {
54
- input: { padding: '0.8em', textAlign: 'left', width: '100%' },
55
- inputWrapper: { width: '100%' },
56
- }, placeholder: "Enter URL to JCAMP-DX file" }) }) }) }) }), _jsx(Modal.Footer, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button.Done, { onClick: () => ref.current?.submitForm(), children: "Load" }) }) })] }));
62
+ return (_jsxs(Modal, { hasCloseButton: true, isOpen: true, onRequestClose: onCloseDialog, children: [_jsx(Modal.Header, { children: "Load JCAMP Dialog" }), _jsx(Modal.Body, { children: _jsx("div", { style: { minWidth: '400px', padding: '1.5em' }, children: _jsx(Formik, { initialValues: { url: '' }, validationSchema: loadFormValidation, onSubmit: loadJCAMPHandler, innerRef: ref, children: _jsx(Label, { title: "URL", style: labelStyle, children: _jsx(FormikError, { name: "url", style: { container: { flex: 1 } }, children: _jsx(FormikInput, { name: "url", type: "string", style: {
63
+ input: {
64
+ padding: '0.8em',
65
+ textAlign: 'left',
66
+ width: '100%',
67
+ },
68
+ inputWrapper: { width: '100%' },
69
+ }, placeholder: "Enter URL to JCAMP-DX file" }) }) }) }) }) }), _jsx(Modal.Footer, { children: _jsx("div", { style: { display: 'flex', flexDirection: 'row-reverse' }, children: _jsx(Button.Done, { onClick: () => ref.current?.submitForm(), children: "Load" }) }) })] }));
57
70
  }