nmrium 0.39.0 → 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 (47) hide show
  1. package/lib/component/context/LoggerContext.js +11 -6
  2. package/lib/component/elements/popup/Alert/AlertBlock.d.ts +7 -0
  3. package/lib/component/elements/popup/Alert/AlertBlock.js +24 -0
  4. package/lib/component/elements/popup/Alert/Provider.js +2 -20
  5. package/lib/component/elements/popup/Modal/ConfirmDialog.js +2 -1
  6. package/lib/component/header/Header.js +2 -2
  7. package/lib/component/modal/AboutUsModal.js +4 -2
  8. package/lib/component/modal/LogsHistoryModal.d.ts +6 -0
  9. package/lib/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +6 -4
  10. package/lib/component/modal/setting/GeneralSettings.js +28 -27
  11. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +18 -16
  12. package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
  13. package/lib/component/panels/RangesPanel/RangesHeader.js +9 -15
  14. package/lib/component/panels/RangesPanel/RangesPanel.js +7 -10
  15. package/lib/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
  16. package/lib/component/utility/export.d.ts +5 -4
  17. package/lib/component/utility/export.js +24 -52
  18. package/lib/utils/clipboard/clipboard.d.ts +12 -0
  19. package/lib/utils/clipboard/clipboard.js +15 -0
  20. package/lib/utils/clipboard/clipboardComponents.d.ts +45 -0
  21. package/lib/utils/clipboard/clipboardComponents.js +150 -0
  22. package/lib/utils/clipboard/clipboardHooks.d.ts +94 -0
  23. package/lib/utils/clipboard/clipboardHooks.js +142 -0
  24. package/lib/utils/clipboard/types.d.ts +1 -0
  25. package/lib/utils/clipboard/types.js +1 -0
  26. package/lib/versionInfo.js +1 -1
  27. package/lib-cjs/component/context/LoggerContext.js +10 -5
  28. package/lib-cjs/component/elements/popup/Alert/AlertBlock.js +30 -0
  29. package/lib-cjs/component/elements/popup/Alert/Provider.js +2 -20
  30. package/lib-cjs/component/elements/popup/Modal/ConfirmDialog.js +2 -1
  31. package/lib-cjs/component/header/Header.js +2 -2
  32. package/lib-cjs/component/modal/AboutUsModal.js +4 -2
  33. package/lib-cjs/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +8 -6
  34. package/lib-cjs/component/modal/setting/GeneralSettings.js +28 -27
  35. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +17 -15
  36. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
  37. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +9 -15
  38. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +7 -10
  39. package/lib-cjs/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
  40. package/lib-cjs/component/utility/export.js +24 -54
  41. package/lib-cjs/utils/clipboard/clipboard.js +23 -0
  42. package/lib-cjs/utils/clipboard/clipboardComponents.js +158 -0
  43. package/lib-cjs/utils/clipboard/clipboardHooks.js +147 -0
  44. package/lib-cjs/utils/clipboard/types.js +2 -0
  45. package/lib-cjs/versionInfo.js +1 -1
  46. package/package.json +13 -13
  47. package/lib/component/header/LogsHistory.d.ts +0 -1
@@ -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,12 +15,16 @@ 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) => {
19
- if (log?.error &&
20
- (log?.levelLabel === 'error' || log?.levelLabel === 'fatal')) {
21
- // eslint-disable-next-line no-console
22
- console.error(log.error);
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
+ }
23
28
  }
24
29
  setLogsHistory(logs.slice());
25
30
  },
@@ -43,5 +48,5 @@ export function LoggerProvider({ children }) {
43
48
  lastReadLogId,
44
49
  };
45
50
  }, [lastReadLogId, logsHistory, markAsRead]);
46
- 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] }));
47
52
  }
@@ -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();
@@ -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() {
@@ -0,0 +1,6 @@
1
+ interface LogsHistoryModalProps {
2
+ autoOpen?: boolean;
3
+ onClose?: () => void;
4
+ }
5
+ export declare function LogsHistoryModal(props: LogsHistoryModalProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -47,9 +47,10 @@ function getMaxLevelLogs(logs, lastReadLogId) {
47
47
  }
48
48
  return { backgroundColor, count: logsCounts[maxLevel] };
49
49
  }
50
- export function LogsHistory() {
50
+ export function LogsHistoryModal(props) {
51
+ const { autoOpen = false, onClose } = props;
51
52
  const { logsHistory, logger, markAsRead, lastReadLogId } = useLogger();
52
- const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
53
+ const [isOpenDialog, openDialog, closeDialog] = useOnOff(autoOpen);
53
54
  const { count, backgroundColor } = getMaxLevelLogs(logsHistory, lastReadLogId);
54
55
  const COLUMNS = useMemo(() => [
55
56
  {
@@ -88,7 +89,7 @@ export function LogsHistory() {
88
89
  },
89
90
  ], [lastReadLogId]);
90
91
  const sortedLogs = logsHistory.slice().sort((a, b) => b.time - a.time);
91
- return (_jsxs(_Fragment, { children: [_jsx(Button.BarButton, { onClick: () => {
92
+ return (_jsxs(_Fragment, { children: [!autoOpen && (_jsx(Button.BarButton, { onClick: () => {
92
93
  openDialog();
93
94
  }, children: _jsxs("div", { style: { position: 'relative' }, children: [_jsx(IoBugOutline, { fontSize: "1.4em" }), count && (_jsx("span", { style: {
94
95
  position: 'absolute',
@@ -99,8 +100,9 @@ export function LogsHistory() {
99
100
  minWidth: '14px',
100
101
  fontSize: '0.75em',
101
102
  color: 'white',
102
- }, children: count }))] }) }), _jsxs(Modal, { hasCloseButton: true, isOpen: isOpenDialog, onRequestClose: () => {
103
+ }, children: count }))] }) })), _jsxs(Modal, { hasCloseButton: true, isOpen: isOpenDialog, onRequestClose: () => {
103
104
  markAsRead();
104
105
  closeDialog();
106
+ onClose?.();
105
107
  }, children: [_jsx(Modal.Header, { children: "Logs History " }), _jsx(Modal.Body, { children: _jsx("div", { style: { width: '50vw', height: '50vh', padding: '0.5em' }, children: _jsx(ReactTable, { columns: COLUMNS, data: sortedLogs, emptyDataRowText: "No Logs", rowStyle: handleRowStyle }) }) }), _jsx(Modal.Footer, { children: _jsx(Button.Danger, { onClick: () => logger.clear(), fill: "outline", children: _jsxs("div", { style: { display: 'flex', alignItems: 'center' }, children: [_jsx(FaRegTrashAlt, {}), _jsx("span", { style: { paddingLeft: '5px' }, children: "Clear Logs" })] }) }) })] })] }));
106
108
  }
@@ -5,6 +5,8 @@ import { Formik } from 'formik';
5
5
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
6
  import { FaBolt, FaPaste, FaRegCopy, FaWrench } from 'react-icons/fa';
7
7
  import { Modal, Toolbar, useOnOff } from 'react-science/ui';
8
+ import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
9
+ import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
8
10
  import { usePreferences, useWorkspacesList, } from '../../context/PreferencesContext';
9
11
  import ActionButtons from '../../elements/ActionButtons';
10
12
  import Button from '../../elements/Button';
@@ -15,7 +17,6 @@ import DropDownButton from '../../elements/dropDownButton/DropDownButton';
15
17
  import { useAlert } from '../../elements/popup/Alert';
16
18
  import { useSaveSettings } from '../../hooks/useSaveSettings';
17
19
  import { getPreferencesByWorkspace } from '../../reducer/preferences/utilities/getPreferencesByWorkspace';
18
- import { copyTextToClipboard } from '../../utility/export';
19
20
  import PredefinedWorkspaces from '../../workspaces';
20
21
  import WorkspaceItem from './WorkspaceItem';
21
22
  import DatabasesTabContent from './settings-tabs/DatabasesTabContent';
@@ -28,7 +29,8 @@ import OnLoadProcessingTabContent from './settings-tabs/OnLoadProcessingTabConte
28
29
  import ToolsTabContent from './settings-tabs/ToolsTabContent';
29
30
  import { validation } from './settingsValidation';
30
31
  const styles = css `
31
- width: 800px;
32
+ width: 50vw;
33
+ min-width: 800px;
32
34
 
33
35
  .main-content {
34
36
  width: 100%;
@@ -175,20 +177,16 @@ function GeneralSettingsModal({ height }) {
175
177
  function handleDisabledRestButton(values) {
176
178
  setRestDisabled(isRestButtonDisable(values, workspaceName, originalWorkspaces));
177
179
  }
180
+ const { readText, rawWriteWithType, shouldFallback, cleanShouldFallback, text, } = useClipboard();
178
181
  function handleCopyWorkspace() {
179
182
  const data = { [workspaceName]: refForm.current?.values };
180
- void copyTextToClipboard(JSON.stringify(data)).then((flag) => {
181
- if (flag) {
182
- alert.success('Workspace copied to clipboard');
183
- }
184
- else {
185
- alert.error('copied not completed');
186
- }
183
+ void rawWriteWithType(JSON.stringify(data)).then(() => {
184
+ alert.success('Workspace copied to clipboard');
187
185
  });
188
186
  }
189
187
  const setWorkspaceSetting = useCallback((inputWorkspace) => {
190
188
  const parseWorkspaceName = Object.keys(inputWorkspace)[0];
191
- if (preferences?.workspace.current === parseWorkspaceName) {
189
+ if (preferences.workspace.current === parseWorkspaceName) {
192
190
  refForm.current?.setValues(inputWorkspace[parseWorkspaceName]);
193
191
  }
194
192
  else if (preferences.workspaces[parseWorkspaceName]) {
@@ -201,41 +199,44 @@ function GeneralSettingsModal({ height }) {
201
199
  },
202
200
  });
203
201
  }
204
- }, [dispatch, preferences?.workspace, preferences.workspaces]);
205
- function handlePastWorkspace() {
206
- void navigator.clipboard.readText().then((text) => {
207
- try {
208
- const parseWorkspaces = JSON.parse(text);
209
- setWorkspaceSetting(parseWorkspaces);
210
- }
211
- catch {
212
- alert.error('object parse error');
213
- }
214
- });
215
- }
202
+ }, [dispatch, preferences.workspace, preferences.workspaces]);
216
203
  useEffect(() => {
217
204
  if (pastRef.current) {
218
205
  setWorkspaceSetting(pastRef.current);
219
206
  pastRef.current = null;
220
207
  }
221
208
  }, [setWorkspaceSetting]);
222
- return (_jsxs(_Fragment, { children: [_jsx(Toolbar.Item, { id: "general-settings", onClick: openDialog, title: "General settings", children: _jsx(FaWrench, {}) }), _jsxs(Modal, { hasCloseButton: true, isOpen: isOpenDialog, onRequestClose: closeDialog, children: [_jsx(Modal.Header, { children: _jsxs("div", { style: {
209
+ function handlePastWorkspace(text) {
210
+ if (!text)
211
+ return;
212
+ try {
213
+ const parseWorkspaces = JSON.parse(text);
214
+ setWorkspaceSetting(parseWorkspaces);
215
+ }
216
+ catch {
217
+ alert.error('object parse error');
218
+ }
219
+ cleanShouldFallback();
220
+ }
221
+ function handlePastWorkspaceAction() {
222
+ void readText().then(handlePastWorkspace);
223
+ }
224
+ return (_jsxs(_Fragment, { children: [_jsx(Toolbar.Item, { id: "general-settings", onClick: openDialog, title: "General settings", children: _jsx(FaWrench, {}) }), _jsxs(Modal, { hasCloseButton: true, isOpen: isOpenDialog, onRequestClose: closeDialog, maxWidth: 1000, children: [_jsx(Modal.Header, { children: _jsxs("div", { style: {
223
225
  display: 'flex',
224
226
  flexDirection: 'column',
225
- width: '100%',
226
227
  }, children: [_jsx("span", { children: "General Settings" }), _jsxs("div", { style: {
227
228
  display: 'flex',
228
229
  alignItems: 'center',
229
230
  cursor: 'default',
230
231
  paddingTop: '10px',
231
- }, children: [_jsx(Label, { title: "Workspace", children: _jsx(DropDownButton, { data: workspacesList, renderItem: renderItem, selectedKey: preferences?.workspace.current, onSelect: ChangeWorkspaceHandler }) }), _jsx(Button.Action, { size: "xSmall", onClick: handleReset, toolTip: "Reset workspace preferences", tooltipOrientation: "horizontal", style: {
232
+ }, children: [_jsx(Label, { title: "Workspace", children: _jsx(DropDownButton, { data: workspacesList, renderItem: renderItem, selectedKey: preferences.workspace.current, onSelect: ChangeWorkspaceHandler }) }), _jsx(Button.Action, { size: "xSmall", onClick: handleReset, toolTip: "Reset workspace preferences", tooltipOrientation: "horizontal", style: {
232
233
  marginLeft: '10px',
233
234
  }, disabled: isRestDisabled, children: _jsx(FaBolt, {}) }), _jsx(Button.Done, { size: "xSmall", fill: "outline", onClick: handleCopyWorkspace, toolTip: "Copy workspace preferences", tooltipOrientation: "horizontal", style: {
234
235
  marginLeft: '10px',
235
- }, children: _jsx(FaRegCopy, {}) }), _jsx(Button.Action, { size: "xSmall", fill: "outline", onClick: handlePastWorkspace, toolTip: "Past workspace preferences", tooltipOrientation: "horizontal", style: {
236
+ }, children: _jsx(FaRegCopy, {}) }), _jsx(Button.Action, { size: "xSmall", fill: "outline", onClick: handlePastWorkspaceAction, toolTip: "Past workspace preferences", tooltipOrientation: "horizontal", style: {
236
237
  marginLeft: '10px',
237
238
  }, children: _jsx(FaPaste, {}) })] })] }) }), _jsx(Modal.Body, { children: _jsx("div", { css: styles, style: { height }, children: _jsx(Formik, { enableReinitialize: true, innerRef: refForm, initialValues: currentWorkspace, validationSchema: validation, onSubmit: submitHandler, validate: handleDisabledRestButton, children: _jsxs(Tabs, { position: PositionsEnum.LEFT, activeTab: activeTab, onClick: tabChangeHandler, children: [_jsx(Tab, { title: "General", tabid: "general", children: _jsx("div", { className: "inner-content", children: _jsx(GeneralTabContent, {}) }) }), _jsx(Tab, { title: "Formatting", tabid: "formatting", children: _jsx("div", { className: "inner-content", children: _jsx(FormattingTabContent, {}) }) }), _jsx(Tab, { title: "Panels", tabid: "display", children: _jsx("div", { className: "inner-content", children: _jsx(DisplayTabContent, {}) }) }), _jsx(Tab, { title: "Tools", tabid: "tools", children: _jsx("div", { className: "inner-content", children: _jsx(ToolsTabContent, {}) }) }), _jsx(Tab, { title: "Databases", tabid: "databases", children: _jsx("div", { className: "inner-content", children: _jsx(DatabasesTabContent, { currentWorkspace: workspaceName, originalWorkspaces: originalWorkspaces }) }) }), _jsx(Tab, { title: "Import filters", tabid: "importation-filters", children: _jsx("div", { className: "inner-content", children: _jsx(ImportationFiltersTabContent, {}) }) }), _jsx(Tab, { title: "Title Block", tabid: "title-block", children: _jsx("div", { className: "inner-content", children: _jsx(InfoBlockTabContent, {}) }) }), _jsx(Tab, { title: "On Load Processing", tabid: "on-load-processing", children: _jsx("div", { className: "inner-content", children: _jsx(OnLoadProcessingTabContent, {}) }) })] }) }) }) }), _jsx(Modal.Footer, { children: _jsxs("div", { style: { display: 'flex', justifyContent: 'flex-end' }, children: [_jsx(ActionButtons, { style: { flexDirection: 'row-reverse', margin: 0 }, onDone: () => refForm.current?.submitForm(), doneLabel: "Apply and Save", onCancel: () => {
238
239
  closeDialog?.();
239
- } }), _jsx(Button.Secondary, { style: { margin: '0 10px' }, onClick: applyPreferencesHandler, children: "Apply" })] }) })] }), _jsx(SaveSettingsModal, {})] }));
240
+ } }), _jsx(Button.Secondary, { style: { margin: '0 10px' }, onClick: applyPreferencesHandler, children: "Apply" })] }) })] }), _jsx(SaveSettingsModal, {}), _jsx(ClipboardFallbackModal, { mode: shouldFallback, onDismiss: cleanShouldFallback, onReadText: handlePastWorkspace, text: text, label: "Workspace" })] }));
240
241
  }
241
242
  export default GeneralSettingsModal;
@@ -5,6 +5,8 @@ import { useCallback } from 'react';
5
5
  import { FaCog, FaCopy, FaDownload, FaFileExport, FaFileImage, FaPaste, FaPlus, FaRegTrashAlt, } from 'react-icons/fa';
6
6
  import { IoOpenOutline } from 'react-icons/io5';
7
7
  import { DropdownMenu } from 'react-science/ui';
8
+ import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
9
+ import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
8
10
  import { useAssignmentData } from '../../assignment/AssignmentsContext';
9
11
  import { useDispatch } from '../../context/DispatchContext';
10
12
  import { useGlobal } from '../../context/GlobalContext';
@@ -13,7 +15,7 @@ import Button from '../../elements/Button';
13
15
  import { useAlert } from '../../elements/popup/Alert';
14
16
  import AboutPredictionModal from '../../modal/AboutPredictionModal';
15
17
  import { usePredictSpectraModal } from '../../modal/PredictSpectraModal';
16
- import { copyPNGToClipboard, copyTextToClipboard, exportAsSVG, } from '../../utility/export';
18
+ import { copyPNGToClipboard, exportAsSVG } from '../../utility/export';
17
19
  import PanelHeader from '../header/PanelHeader';
18
20
  const styles = {
19
21
  counter: {
@@ -87,16 +89,12 @@ export default function MoleculePanelHeader({ currentIndex, molecules, molecules
87
89
  copyPNGToClipboard(rootRef, `molSVG${currentIndex} `);
88
90
  alert.success('MOL copied as PNG to clipboard');
89
91
  }, [rootRef, alert, currentIndex]);
92
+ const { rawWriteWithType, readText, shouldFallback, cleanShouldFallback, text, } = useClipboard();
90
93
  const saveAsMolHandler = useCallback((molfile) => {
91
- void copyTextToClipboard(molfile).then((flag) => {
92
- if (flag) {
93
- alert.success('MOLFile copied to clipboard');
94
- }
95
- else {
96
- alert.error('copied not completed');
97
- }
94
+ void rawWriteWithType(molfile).then(() => {
95
+ alert.success('MOLFile copied to clipboard');
98
96
  });
99
- }, [alert]);
97
+ }, [alert, rawWriteWithType]);
100
98
  const exportHandler = useCallback((selected) => {
101
99
  const molecule = molecules?.[currentIndex];
102
100
  if (molecule) {
@@ -125,11 +123,15 @@ export default function MoleculePanelHeader({ currentIndex, molecules, molecules
125
123
  saveAsPNGHandler,
126
124
  saveAsSVGHandler,
127
125
  ]);
128
- const handlePaste = useCallback(() => {
129
- void navigator.clipboard.readText().then((molfile) => {
130
- dispatch({ type: 'ADD_MOLECULE', payload: { molfile } });
131
- });
132
- }, [dispatch]);
126
+ function handlePasteMolfileAction() {
127
+ void readText().then(handlePasteMolfile);
128
+ }
129
+ function handlePasteMolfile(molfile) {
130
+ if (!molfile)
131
+ return;
132
+ dispatch({ type: 'ADD_MOLECULE', payload: { molfile } });
133
+ cleanShouldFallback();
134
+ }
133
135
  const handleDelete = useCallback(() => {
134
136
  if (molecules[currentIndex]?.id) {
135
137
  onMoleculeIndexChange?.(0);
@@ -158,7 +160,7 @@ export default function MoleculePanelHeader({ currentIndex, molecules, molecules
158
160
  });
159
161
  }
160
162
  const hasMolecules = molecules && molecules.length > 0;
161
- return (_jsxs(PanelHeader, { children: [renderSource === 'predictionPanel' && _jsx(AboutPredictionModal, {}), renderSource === 'moleculePanel' && (_jsx(DropdownMenu, { trigger: "click", options: MOL_EXPORT_MENU, onSelect: exportHandler, children: _jsx(Button.BarButton, { as: "div", disabled: !hasMolecules, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Export As", tooltipOrientation: "horizontal", children: _jsx(FaFileExport, {}) }) })), _jsx(Button.BarButton, { onClick: handlePaste, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Paste molfile", tooltipOrientation: "horizontal", children: _jsx(FaPaste, {}) }), _jsx(Button.BarButton, { onClick: onOpenMoleculeEditor, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Add molecule", tooltipOrientation: "horizontal", children: _jsx(FaPlus, {}) }), renderSource === 'moleculePanel' && (_jsxs(_Fragment, { children: [_jsx(Button.BarButton, { onClick: handleDelete, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Delete molecule", tooltipOrientation: "horizontal", disabled: !hasMolecules, children: _jsx(FaRegTrashAlt, {}) }), hasMolecules && (_jsx(Button.BarButton, { color: { base: '#4e4e4e', hover: '#4e4e4e' }, onClick: () => openPredictSpectraModal(molecules[currentIndex]), toolTip: "Predict spectra", tooltipOrientation: "horizontal", children: _jsx(SvgNmrFt, {}) }))] })), _jsx(ActiveButton, { value: moleculesView?.[moleculeKey]?.floating.visible || false, popupTitle: "Float molecule", popupPlacement: "left", onClick: floatMoleculeHandler, disabled: !hasMolecules, children: _jsx(IoOpenOutline, {}) }), _jsx(ActiveButton, { style: { marginLeft: '2px' }, value: moleculesView?.[moleculeKey]?.showAtomNumber || false, popupTitle: "Show atom number", popupPlacement: "left", onClick: showAtomNumbersHandler, disabled: !hasMolecules, children: _jsx("p", { style: styles.atomLabel, children: "#" }) }), _jsx("div", { style: { flex: 1 }, children: children }), _jsxs("p", { style: styles.counter, children: [molecules &&
163
+ return (_jsxs(PanelHeader, { children: [renderSource === 'predictionPanel' && _jsx(AboutPredictionModal, {}), renderSource === 'moleculePanel' && (_jsx(DropdownMenu, { trigger: "click", options: MOL_EXPORT_MENU, onSelect: exportHandler, children: _jsx(Button.BarButton, { as: "div", disabled: !hasMolecules, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Export As", tooltipOrientation: "horizontal", children: _jsx(FaFileExport, {}) }) })), _jsx(Button.BarButton, { onClick: handlePasteMolfileAction, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Paste molfile", tooltipOrientation: "horizontal", children: _jsx(FaPaste, {}) }), _jsx(Button.BarButton, { onClick: onOpenMoleculeEditor, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Add molecule", tooltipOrientation: "horizontal", children: _jsx(FaPlus, {}) }), renderSource === 'moleculePanel' && (_jsxs(_Fragment, { children: [_jsx(Button.BarButton, { onClick: handleDelete, color: { base: '#4e4e4e', hover: '#4e4e4e' }, toolTip: "Delete molecule", tooltipOrientation: "horizontal", disabled: !hasMolecules, children: _jsx(FaRegTrashAlt, {}) }), hasMolecules && (_jsx(Button.BarButton, { color: { base: '#4e4e4e', hover: '#4e4e4e' }, onClick: () => openPredictSpectraModal(molecules[currentIndex]), toolTip: "Predict spectra", tooltipOrientation: "horizontal", children: _jsx(SvgNmrFt, {}) }))] })), _jsx(ActiveButton, { value: moleculesView?.[moleculeKey]?.floating.visible || false, popupTitle: "Float molecule", popupPlacement: "left", onClick: floatMoleculeHandler, disabled: !hasMolecules, children: _jsx(IoOpenOutline, {}) }), _jsx(ActiveButton, { style: { marginLeft: '2px' }, value: moleculesView?.[moleculeKey]?.showAtomNumber || false, popupTitle: "Show atom number", popupPlacement: "left", onClick: showAtomNumbersHandler, disabled: !hasMolecules, children: _jsx("p", { style: styles.atomLabel, children: "#" }) }), _jsx("div", { style: { flex: 1 }, children: children }), _jsxs("p", { style: styles.counter, children: [molecules &&
162
164
  molecules.length > 0 &&
163
- `${+(currentIndex + 1)} / ${molecules.length}`, ' '] }), onClickPreferences && (_jsx(Button.BarButton, { color: { base: 'black', hover: 'black' }, onClick: onClickPreferences, toolTip: "Preferences", tooltipOrientation: "vertical", children: _jsx(FaCog, {}) }))] }));
165
+ `${+(currentIndex + 1)} / ${molecules.length}`, ' '] }), onClickPreferences && (_jsx(Button.BarButton, { color: { base: 'black', hover: 'black' }, onClick: onClickPreferences, toolTip: "Preferences", tooltipOrientation: "vertical", children: _jsx(FaCog, {}) })), _jsx(ClipboardFallbackModal, { mode: shouldFallback, onDismiss: cleanShouldFallback, onReadText: handlePasteMolfile, text: text, label: "Molfile" })] }));
164
166
  }
@@ -6,6 +6,8 @@ import { useCallback, useState, useRef, memo } from 'react';
6
6
  import { FaFileExport } from 'react-icons/fa';
7
7
  import { IoPulseOutline } from 'react-icons/io5';
8
8
  import { getDataAsString, generateAnalyzeSpectra, } from '../../../data/data1d/multipleSpectraAnalysis';
9
+ import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
10
+ import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
9
11
  import { useChartData } from '../../context/ChartContext';
10
12
  import { useDispatch } from '../../context/DispatchContext';
11
13
  import Button from '../../elements/ButtonToolTip';
@@ -14,7 +16,6 @@ import { positions, useAlert } from '../../elements/popup/Alert';
14
16
  import { useModal } from '../../elements/popup/Modal';
15
17
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
16
18
  import AlignSpectraModal from '../../modal/AlignSpectraModal';
17
- import { copyTextToClipboard } from '../../utility/export';
18
19
  import { getSpectraByNucleus } from '../../utility/getSpectraByNucleus';
19
20
  import { tablePanelStyle } from '../extra/BasicPanelStyle';
20
21
  import DefaultPanelHeader from '../header/DefaultPanelHeader';
@@ -50,18 +51,13 @@ function MultipleSpectraAnalysisPanelInner({ activeTab, spectra, showLegend, })
50
51
  width: 500,
51
52
  });
52
53
  }, [activeTab, modal, dispatch]);
54
+ const { rawWriteWithType, cleanShouldFallback, shouldFallback, text } = useClipboard();
53
55
  const copyToClipboardHandler = useCallback(() => {
54
- void (async () => {
55
- const data = getDataAsString(spectraAnalysis, spectra, spectraPreferences);
56
- const success = await copyTextToClipboard(data);
57
- if (success) {
58
- alert.success('Data copied to clipboard');
59
- }
60
- else {
61
- alert.error('copy to clipboard failed');
62
- }
63
- })();
64
- }, [alert, spectra, spectraAnalysis, spectraPreferences]);
56
+ const data = getDataAsString(spectraAnalysis, spectra, spectraPreferences);
57
+ if (!data)
58
+ return;
59
+ void rawWriteWithType(data).then(() => alert.success('Data copied to clipboard'));
60
+ }, [alert, rawWriteWithType, spectra, spectraAnalysis, spectraPreferences]);
65
61
  return (_jsxs("div", { css: [
66
62
  tablePanelStyle,
67
63
  isFlipped &&
@@ -70,7 +66,7 @@ function MultipleSpectraAnalysisPanelInner({ activeTab, spectra, showLegend, })
70
66
  position: relative;
71
67
  }
72
68
  `,
73
- ], children: [!isFlipped && (_jsxs(DefaultPanelHeader, { deleteToolTip: "Delete All Peaks", showSettingButton: true, canDelete: false, onSettingClick: settingsPanelHandler, children: [_jsx(Button, { popupTitle: "Copy To Clipboard", onClick: copyToClipboardHandler, children: _jsx(FaFileExport, {}) }), _jsx(Button, { popupTitle: "Spectra calibration", onClick: openAlignSpectra, children: _jsx(SvgNmrOverlay, { style: { fontSize: '18px' } }) }), _jsx(ToggleButton, { popupTitle: "Y spectra tracker", popupPlacement: "right", onClick: showTrackerHandler, defaultValue: showLegend, children: _jsx(IoPulseOutline, {}) }, `${showLegend}`)] })), isFlipped && (_jsx(PreferencesHeader, { onSave: saveSettingHandler, onClose: settingsPanelHandler })), _jsx("div", { className: "inner-container", children: !isFlipped ? (_jsx(MultipleSpectraAnalysisTable, { data: spectraAnalysis, resortSpectra: preferences.analysisOptions.resortSpectra, activeTab: activeTab })) : (_jsx(MultipleSpectraAnalysisPreferences, { data: spectraAnalysis, activeTab: activeTab, onAfterSave: afterSaveHandler, ref: settingRef })) })] }));
69
+ ], children: [!isFlipped && (_jsxs(DefaultPanelHeader, { deleteToolTip: "Delete All Peaks", showSettingButton: true, canDelete: false, onSettingClick: settingsPanelHandler, children: [_jsx(Button, { popupTitle: "Copy To Clipboard", onClick: copyToClipboardHandler, children: _jsx(FaFileExport, {}) }), _jsx(Button, { popupTitle: "Spectra calibration", onClick: openAlignSpectra, children: _jsx(SvgNmrOverlay, { style: { fontSize: '18px' } }) }), _jsx(ToggleButton, { popupTitle: "Y spectra tracker", popupPlacement: "right", onClick: showTrackerHandler, defaultValue: showLegend, children: _jsx(IoPulseOutline, {}) }, `${showLegend}`)] })), isFlipped && (_jsx(PreferencesHeader, { onSave: saveSettingHandler, onClose: settingsPanelHandler })), _jsx("div", { className: "inner-container", children: !isFlipped ? (_jsx(MultipleSpectraAnalysisTable, { data: spectraAnalysis, resortSpectra: preferences.analysisOptions.resortSpectra, activeTab: activeTab })) : (_jsx(MultipleSpectraAnalysisPreferences, { data: spectraAnalysis, activeTab: activeTab, onAfterSave: afterSaveHandler, ref: settingRef })) }), _jsx(ClipboardFallbackModal, { mode: shouldFallback, onDismiss: cleanShouldFallback, text: text, label: "Spectra Analysis" })] }));
74
70
  }
75
71
  const MemoizedMultipleSpectraAnalysisPanel = memo(MultipleSpectraAnalysisPanelInner);
76
72
  export default function MultipleSpectraAnalysisPanel() {
@@ -6,6 +6,8 @@ import lodashGet from 'lodash/get';
6
6
  import { rangesToACS } from 'nmr-processing';
7
7
  import { FaFileExport, FaUnlink, FaSitemap, FaChartBar } from 'react-icons/fa';
8
8
  import { ImLink } from 'react-icons/im';
9
+ import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
10
+ import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
9
11
  import { useAssignmentData } from '../../assignment/AssignmentsContext';
10
12
  import { useDispatch } from '../../context/DispatchContext';
11
13
  import ActiveButton from '../../elements/ActiveButton';
@@ -15,7 +17,6 @@ import { useModal } from '../../elements/popup/Modal';
15
17
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
16
18
  import CopyClipboardModal from '../../modal/CopyClipboardModal';
17
19
  import ChangeSumModal from '../../modal/changeSum/ChangeSumModal';
18
- import { copyHTMLToClipboard } from '../../utility/export';
19
20
  import { getNumberOfDecimals } from '../../utility/formatNumber';
20
21
  import DefaultPanelHeader from '../header/DefaultPanelHeader';
21
22
  const style = css `
@@ -87,16 +88,9 @@ function RangesHeader({ id, ranges, info, onUnlink, onFilterActivated, onSetting
87
88
  function handleShowJGraph() {
88
89
  dispatch({ type: 'SHOW_J_GRAPH', payload: { id } });
89
90
  }
91
+ const { rawWriteWithType, shouldFallback, cleanShouldFallback, text } = useClipboard();
90
92
  function saveToClipboardHandler(value) {
91
- void (async () => {
92
- const success = await copyHTMLToClipboard(value);
93
- if (success) {
94
- alert.success('Data copied to clipboard');
95
- }
96
- else {
97
- alert.error('copy to clipboard failed');
98
- }
99
- })();
93
+ void rawWriteWithType(value, 'text/html').then(() => alert.success('Data copied to clipboard'));
100
94
  }
101
95
  function saveAsHTMLHandler() {
102
96
  if (Array.isArray(ranges?.values) && ranges.values.length > 0) {
@@ -118,10 +112,10 @@ function RangesHeader({ id, ranges, info, onUnlink, onFilterActivated, onSetting
118
112
  });
119
113
  }
120
114
  const hasRanges = Array.isArray(ranges?.values) && ranges.values.length > 0;
121
- return (_jsx("div", { css: style, children: _jsxs(DefaultPanelHeader, { counter: ranges?.values?.length || 0, onDelete: handleDeleteAll, deleteToolTip: "Delete All Ranges", onFilter: onFilterActivated, filterToolTip: isFilterActive ? 'Show all ranges' : 'Hide ranges out of view', filterIsActive: isFilterActive, counterFiltered: filterCounter, showSettingButton: true, onSettingClick: onSettingClick, children: [_jsx(Button, { popupTitle: "Preview publication string", popupPlacement: "right", onClick: saveAsHTMLHandler, className: "btn preview-publication-icon", disabled: !hasRanges, children: _jsx(FaFileExport, {}) }), _jsx(Button, { popupTitle: currentSum
122
- ? `Change ranges sum (${Number(currentSum).toFixed(2)})`
123
- : 'Change ranges sum', popupPlacement: "right", onClick: showChangeRangesSumModal, className: "btn icon", children: _jsx(SvgNmrSum, {}) }), _jsx(Button, { popupTitle: "Remove all assignments", popupPlacement: "right", onClick: handleOnRemoveAssignments, disabled: !hasRanges, className: "btn icon", children: _jsx(FaUnlink, {}) }), _jsx(ActiveButton, { popupTitle: showMultiplicityTrees
124
- ? 'Hide multiplicity trees in spectrum'
125
- : 'Show multiplicity trees in spectrum', popupPlacement: "right", onClick: handleSetShowMultiplicityTrees, value: showMultiplicityTrees, disabled: !hasRanges, children: _jsx(FaSitemap, { style: { pointerEvents: 'none', fontSize: '12px' } }) }), _jsx(ActiveButton, { popupTitle: showJGraph ? 'Hide J Graph' : 'Show J Graph', popupPlacement: "right", onClick: handleShowJGraph, value: showJGraph, disabled: !hasRanges, children: _jsx(FaChartBar, { style: { pointerEvents: 'none', fontSize: '12px' } }) }), _jsx(ActiveButton, { popupTitle: showRangesIntegrals ? 'Hide integrals' : 'Show integrals', popupPlacement: "right", onClick: handleShowIntegrals, value: showRangesIntegrals, disabled: !hasRanges, children: _jsx(SvgNmrIntegrate, { style: { pointerEvents: 'none', fontSize: '12px' } }) }), _jsx(ActiveButton, { className: "icon", popupTitle: "Fix integral values", popupPlacement: "right", onClick: changeSumConstantFlagHandler, value: ranges?.options?.isSumConstant, children: _jsx(ImLink, {}) })] }) }));
115
+ return (_jsxs("div", { css: style, children: [_jsxs(DefaultPanelHeader, { counter: ranges?.values?.length || 0, onDelete: handleDeleteAll, deleteToolTip: "Delete All Ranges", onFilter: onFilterActivated, filterToolTip: isFilterActive ? 'Show all ranges' : 'Hide ranges out of view', filterIsActive: isFilterActive, counterFiltered: filterCounter, showSettingButton: true, onSettingClick: onSettingClick, children: [_jsx(Button, { popupTitle: "Preview publication string", popupPlacement: "right", onClick: saveAsHTMLHandler, className: "btn preview-publication-icon", disabled: !hasRanges, children: _jsx(FaFileExport, {}) }), _jsx(Button, { popupTitle: currentSum
116
+ ? `Change ranges sum (${Number(currentSum).toFixed(2)})`
117
+ : 'Change ranges sum', popupPlacement: "right", onClick: showChangeRangesSumModal, className: "btn icon", children: _jsx(SvgNmrSum, {}) }), _jsx(Button, { popupTitle: "Remove all assignments", popupPlacement: "right", onClick: handleOnRemoveAssignments, disabled: !hasRanges, className: "btn icon", children: _jsx(FaUnlink, {}) }), _jsx(ActiveButton, { popupTitle: showMultiplicityTrees
118
+ ? 'Hide multiplicity trees in spectrum'
119
+ : 'Show multiplicity trees in spectrum', popupPlacement: "right", onClick: handleSetShowMultiplicityTrees, value: showMultiplicityTrees, disabled: !hasRanges, children: _jsx(FaSitemap, { style: { pointerEvents: 'none', fontSize: '12px' } }) }), _jsx(ActiveButton, { popupTitle: showJGraph ? 'Hide J Graph' : 'Show J Graph', popupPlacement: "right", onClick: handleShowJGraph, value: showJGraph, disabled: !hasRanges, children: _jsx(FaChartBar, { style: { pointerEvents: 'none', fontSize: '12px' } }) }), _jsx(ActiveButton, { popupTitle: showRangesIntegrals ? 'Hide integrals' : 'Show integrals', popupPlacement: "right", onClick: handleShowIntegrals, value: showRangesIntegrals, disabled: !hasRanges, children: _jsx(SvgNmrIntegrate, { style: { pointerEvents: 'none', fontSize: '12px' } }) }), _jsx(ActiveButton, { className: "icon", popupTitle: "Fix integral values", popupPlacement: "right", onClick: changeSumConstantFlagHandler, value: ranges?.options?.isSumConstant, children: _jsx(ImLink, {}) })] }), _jsx(ClipboardFallbackModal, { mode: shouldFallback, onDismiss: cleanShouldFallback, text: text, label: "Preview publication string" })] }));
126
120
  }
127
121
  export default RangesHeader;
@@ -4,6 +4,8 @@ import { css } from '@emotion/react';
4
4
  import { xGetFromToIndex } from 'ml-spectra-processing';
5
5
  import { useCallback, useMemo, memo, useState, useRef } from 'react';
6
6
  import { FaCopy } from 'react-icons/fa';
7
+ import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
8
+ import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
7
9
  import { useAssignmentData } from '../../assignment/AssignmentsContext';
8
10
  import { useChartData } from '../../context/ChartContext';
9
11
  import { useDispatch } from '../../context/DispatchContext';
@@ -11,7 +13,6 @@ import { useAlert } from '../../elements/popup/Alert';
11
13
  import { usePanelPreferences } from '../../hooks/usePanelPreferences';
12
14
  import useSpectrum from '../../hooks/useSpectrum';
13
15
  import { rangeStateInit } from '../../reducer/Reducer';
14
- import { copyTextToClipboard } from '../../utility/export';
15
16
  import { tablePanelStyle } from '../extra/BasicPanelStyle';
16
17
  import NoTableData from '../extra/placeholder/NoTableData';
17
18
  import PreferencesHeader from '../header/PreferencesHeader';
@@ -68,6 +69,7 @@ function RangesTablePanelInner({ id, ranges, data, info, xDomain, preferences, a
68
69
  },
69
70
  });
70
71
  }, [assignmentData, dispatch]);
72
+ const { rawWriteWithType, shouldFallback, cleanShouldFallback, text } = useClipboard();
71
73
  const saveJSONToClipboardHandler = useCallback(async (value) => {
72
74
  if (data.x && data.re) {
73
75
  const { x, re } = data;
@@ -81,15 +83,10 @@ function RangesTablePanelInner({ id, ranges, data, info, xDomain, preferences, a
81
83
  y: Array.from(re.slice(fromIndex, toIndex)),
82
84
  ...value,
83
85
  };
84
- const success = await copyTextToClipboard(JSON.stringify(dataToClipboard, undefined, 2));
85
- if (success) {
86
- alert.show('Data copied to clipboard');
87
- }
88
- else {
89
- alert.error('copy to clipboard failed');
90
- }
86
+ await rawWriteWithType(JSON.stringify(dataToClipboard, undefined, 2));
87
+ alert.show('Data copied to clipboard');
91
88
  }
92
- }, [data, alert]);
89
+ }, [data, rawWriteWithType, alert]);
93
90
  const contextMenuSelectHandler = useCallback((option, data) => {
94
91
  void saveJSONToClipboardHandler(data);
95
92
  }, [saveJSONToClipboardHandler]);
@@ -119,7 +116,7 @@ function RangesTablePanelInner({ id, ranges, data, info, xDomain, preferences, a
119
116
  showRangesIntegrals,
120
117
  showMultiplicityTrees,
121
118
  showJGraph,
122
- isFilterActive, onUnlink: unlinkRangeHandler, onFilterActivated: filterHandler, onSettingClick: settingsPanelHandler, filterCounter: rangesData.length })), isFlipped && (_jsx(PreferencesHeader, { onSave: saveSettingHandler, onClose: settingsPanelHandler })), _jsx("div", { className: "inner-container", children: !isFlipped ? (_jsx("div", { className: "table-container", children: rangesData && rangesData.length > 0 ? (_jsx(RangesTable, { activeTab: activeTab, tableData: rangesData, onUnlink: unlinkRangeHandler, contextMenu: rangesContextMenuOptions, onContextMenuSelect: contextMenuSelectHandler, preferences: preferences, info: info })) : (_jsx(NoTableData, {})) })) : (_jsx(RangesPreferences, { ref: settingRef })) })] }));
119
+ isFilterActive, onUnlink: unlinkRangeHandler, onFilterActivated: filterHandler, onSettingClick: settingsPanelHandler, filterCounter: rangesData.length })), isFlipped && (_jsx(PreferencesHeader, { onSave: saveSettingHandler, onClose: settingsPanelHandler })), _jsx("div", { className: "inner-container", children: !isFlipped ? (_jsx("div", { className: "table-container", children: rangesData && rangesData.length > 0 ? (_jsx(RangesTable, { activeTab: activeTab, tableData: rangesData, onUnlink: unlinkRangeHandler, contextMenu: rangesContextMenuOptions, onContextMenuSelect: contextMenuSelectHandler, preferences: preferences, info: info })) : (_jsx(NoTableData, {})) })) : (_jsx(RangesPreferences, { ref: settingRef })) }), _jsx(ClipboardFallbackModal, { mode: shouldFallback, onDismiss: cleanShouldFallback, text: text, label: "Range" })] }));
123
120
  }
124
121
  const MemoizedRangesTablePanel = memo(RangesTablePanelInner);
125
122
  const emptyData = { ranges: {}, data: {}, info: {} };