nmrium 0.58.0 → 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 (112) 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/2d/Viewer2D.js +6 -2
  6. package/lib/component/2d/zones/Zone.js +2 -2
  7. package/lib/component/EventsTrackers/KeysListenerTracker.js +8 -8
  8. package/lib/component/context/ChartContext.js +12 -1
  9. package/lib/component/context/ShareDataContext.d.ts +1 -1
  10. package/lib/component/context/ShareDataContext.js +2 -4
  11. package/lib/component/context/ToasterContext.d.ts +1 -0
  12. package/lib/component/context/ToasterContext.js +12 -3
  13. package/lib/component/elements/ActionsButtonsPopover.js +1 -3
  14. package/lib/component/elements/Alert.d.ts +20 -0
  15. package/lib/component/elements/Alert.js +80 -0
  16. package/lib/component/elements/ContextMenuBluePrint.d.ts +7 -2
  17. package/lib/component/elements/ContextMenuBluePrint.js +9 -3
  18. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +1 -1
  19. package/lib/component/elements/ReactTable/ReactTableFlexLayout.d.ts +0 -3
  20. package/lib/component/elements/ReactTable/ReactTableFlexLayout.js +1 -1
  21. package/lib/component/elements/Select2.d.ts +12 -7
  22. package/lib/component/elements/Select2.js +5 -4
  23. package/lib/component/elements/Select2Controller.d.ts +2 -2
  24. package/lib/component/elements/Select2Controller.js +5 -5
  25. package/lib/component/elements/ToolbarPopoverItem.d.ts +7 -6
  26. package/lib/component/elements/ToolbarPopoverItem.js +13 -5
  27. package/lib/component/elements/print/PrintContent.d.ts +17 -0
  28. package/lib/component/elements/print/PrintContent.js +281 -0
  29. package/lib/component/elements/print/PrintProvider.d.ts +12 -0
  30. package/lib/component/elements/print/PrintProvider.js +28 -0
  31. package/lib/component/elements/print/index.d.ts +2 -0
  32. package/lib/component/elements/print/index.js +2 -0
  33. package/lib/component/header/BaseLineCorrectionPanel.js +3 -0
  34. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +14 -9
  35. package/lib/component/hooks/useToggleSpectraVisibility.js +45 -16
  36. package/lib/component/loader/DropZone.js +3 -67
  37. package/lib/component/loader/useLoadFiles.d.ts +1 -0
  38. package/lib/component/loader/useLoadFiles.js +78 -0
  39. package/lib/component/main/InnerNMRium.d.ts +4 -3
  40. package/lib/component/main/InnerNMRium.js +4 -9
  41. package/lib/component/main/InnerNMRiumContents.d.ts +3 -2
  42. package/lib/component/main/InnerNMRiumContents.js +33 -29
  43. package/lib/component/main/NMRium.d.ts +2 -5
  44. package/lib/component/main/NMRium.js +1 -1
  45. package/lib/component/main/NMRiumRefAPI.d.ts +7 -0
  46. package/lib/component/main/NMRiumRefAPI.js +12 -0
  47. package/lib/component/main/NMRiumViewer.d.ts +10 -0
  48. package/lib/component/main/NMRiumViewer.js +35 -0
  49. package/lib/component/main/index.d.ts +1 -0
  50. package/lib/component/modal/CopyClipboardModal.d.ts +3 -2
  51. package/lib/component/modal/CopyClipboardModal.js +18 -32
  52. package/lib/component/modal/ExportAsJcampModal.d.ts +6 -3
  53. package/lib/component/modal/ExportAsJcampModal.js +69 -35
  54. package/lib/component/modal/ImportPublicationStringModal.js +1 -1
  55. package/lib/component/modal/setting/GeneralSettings.js +4 -2
  56. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.d.ts +1 -0
  57. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.js +89 -0
  58. package/lib/component/modal/setting/settingsValidation.js +15 -1
  59. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +8 -5
  60. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +5 -1
  61. package/lib/component/panels/Panels.js +2 -2
  62. package/lib/component/panels/PeaksPanel/PeaksPanel.js +8 -5
  63. package/lib/component/panels/RangesPanel/RangesHeader.js +52 -12
  64. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +13 -6
  65. package/lib/component/panels/SpectraPanel/SpectraTable.js +63 -21
  66. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +6 -2
  67. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +6 -2
  68. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -0
  69. package/lib/component/panels/ZonesPanel/ZonesPanel.js +16 -8
  70. package/lib/component/panels/databasePanel/DatabasePanel.js +7 -8
  71. package/lib/component/panels/filtersPanel/FilterPanel.js +9 -6
  72. package/lib/component/panels/filtersPanel/FiltersTable.js +12 -10
  73. package/lib/component/panels/header/DefaultPanelHeader.d.ts +1 -0
  74. package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
  75. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +10 -12
  76. package/lib/component/reducer/IgnoreActions.js +1 -0
  77. package/lib/component/reducer/Reducer.js +2 -4
  78. package/lib/component/reducer/actions/DatabaseActions.d.ts +15 -13
  79. package/lib/component/reducer/actions/DatabaseActions.js +52 -34
  80. package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
  81. package/lib/component/reducer/actions/FiltersActions.js +9 -4
  82. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  83. package/lib/component/reducer/actions/SpectraActions.js +53 -43
  84. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.d.ts +3 -0
  85. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.js +16 -0
  86. package/lib/component/reducer/preferences/actions/changePrintPageSettings.d.ts +3 -0
  87. package/lib/component/reducer/preferences/actions/changePrintPageSettings.js +6 -0
  88. package/lib/component/reducer/preferences/preferencesReducer.d.ts +3 -2
  89. package/lib/component/reducer/preferences/preferencesReducer.js +4 -1
  90. package/lib/component/toolbar/ToolBar.js +33 -14
  91. package/lib/component/workspaces/workspaceDefaultProperties.js +2 -0
  92. package/lib/data/SpectraManager.d.ts +7 -10
  93. package/lib/data/SpectraManager.js +51 -30
  94. package/lib/data/data1d/Spectrum1D/SumManager.d.ts +0 -1
  95. package/lib/data/data1d/Spectrum1D/SumManager.js +2 -10
  96. package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +1 -1
  97. package/lib/data/data1d/Spectrum1D/index.d.ts +1 -1
  98. package/lib/data/data1d/Spectrum1D/index.js +1 -1
  99. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +10 -10
  100. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +2 -1
  101. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +10 -10
  102. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +10 -10
  103. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.d.ts +13 -0
  104. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.js +65 -0
  105. package/lib/data/molecules/MoleculeManager.js +16 -38
  106. package/lib/data/utilities/getCustomColor.d.ts +1 -1
  107. package/lib/data/utilities/removeByPaths.d.ts +3 -0
  108. package/lib/data/utilities/removeByPaths.js +33 -0
  109. package/lib/versionInfo.js +1 -1
  110. package/package.json +34 -34
  111. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +0 -11
  112. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +0 -29
@@ -0,0 +1,281 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
+ /** @jsxImportSource @emotion/react */
3
+ import { Dialog, DialogBody, DialogFooter, Radio, RadioGroup, Tag, } from '@blueprintjs/core';
4
+ import { css } from '@emotion/react';
5
+ import { useCallback, useEffect, useRef, useState, } from 'react';
6
+ import { createPortal } from 'react-dom';
7
+ import { Controller, useForm } from 'react-hook-form';
8
+ import ActionButtons from '../ActionButtons';
9
+ import Label from '../Label';
10
+ import { NumberInput2Controller } from '../NumberInput2Controller';
11
+ import { Select2Controller } from '../Select2Controller';
12
+ import { PrintProvider } from './PrintProvider';
13
+ const isFirefox = navigator.userAgent.toLowerCase().includes('firefox');
14
+ const pageSizes = [
15
+ {
16
+ name: 'Letter',
17
+ portrait: { width: 21.59, height: 27.94 },
18
+ landscape: { width: 27.94, height: 21.59 },
19
+ },
20
+ {
21
+ name: 'Legal',
22
+ portrait: { width: 21.59, height: 35.56 },
23
+ landscape: { width: 35.56, height: 21.59 },
24
+ },
25
+ {
26
+ name: 'Tabloid',
27
+ portrait: { width: 27.94, height: 43.18 },
28
+ landscape: { width: 43.18, height: 27.94 },
29
+ },
30
+ {
31
+ name: 'Executive',
32
+ portrait: { width: 26.67, height: 18.42 },
33
+ landscape: { width: 18.42, height: 26.67 },
34
+ },
35
+ {
36
+ name: 'Statement',
37
+ portrait: { width: 21.59, height: 13.97 },
38
+ landscape: { width: 13.97, height: 21.59 },
39
+ },
40
+ {
41
+ name: 'Folio',
42
+ portrait: { width: 33.02, height: 21.59 },
43
+ landscape: { width: 21.59, height: 33.02 },
44
+ },
45
+ {
46
+ name: 'A3',
47
+ portrait: { width: 29.7, height: 42 },
48
+ landscape: { width: 42, height: 29.7 },
49
+ },
50
+ {
51
+ name: 'A4',
52
+ portrait: { width: 21, height: 29.7 },
53
+ landscape: { width: 29.7, height: 21 },
54
+ },
55
+ {
56
+ name: 'A5',
57
+ portrait: { width: 14.8, height: 21 },
58
+ landscape: { width: 21, height: 14.8 },
59
+ },
60
+ {
61
+ name: 'B4',
62
+ portrait: { width: 25.7, height: 36.4 },
63
+ landscape: { width: 36.4, height: 25.7 },
64
+ },
65
+ {
66
+ name: 'B5',
67
+ portrait: { width: 18.2, height: 25.7 },
68
+ landscape: { width: 25.7, height: 18.2 },
69
+ },
70
+ ];
71
+ function getSizesList(layout) {
72
+ const output = [];
73
+ for (const item of pageSizes) {
74
+ const { name, ...otherKeys } = item;
75
+ const { width, height } = otherKeys[layout];
76
+ output.push({ label: `${name} (${width} cm x ${height} cm)`, value: name });
77
+ }
78
+ return output;
79
+ }
80
+ export function PrintContent(props) {
81
+ const [isPageOptionModalOpened, togglePageOptionDialog] = useState(false);
82
+ const [pageOptions, setPageOptions] = useState();
83
+ const { onBeforePrint, onAfterPrint, children, printPageOptions, defaultPrintPageOptions, onPrint, } = props;
84
+ useEffect(() => {
85
+ function handleKeyDow(event) {
86
+ if ((event.ctrlKey || event.metaKey) && event.key === 'p') {
87
+ event.preventDefault();
88
+ if (!printPageOptions) {
89
+ togglePageOptionDialog(true);
90
+ }
91
+ else {
92
+ setPageOptions(printPageOptions);
93
+ }
94
+ }
95
+ }
96
+ window.addEventListener('keydown', handleKeyDow);
97
+ return () => {
98
+ window.removeEventListener('keydown', handleKeyDow);
99
+ };
100
+ }, [printPageOptions]);
101
+ if (!pageOptions) {
102
+ return (_jsx(PrintPageOptionsModal, { isOpen: isPageOptionModalOpened, onCloseDialog: () => {
103
+ togglePageOptionDialog(false);
104
+ }, onPrint: (options) => {
105
+ togglePageOptionDialog(false);
106
+ onPrint?.(options);
107
+ setPageOptions(options);
108
+ }, defaultPrintPageOptions: defaultPrintPageOptions || {} }));
109
+ }
110
+ return (_jsxs(_Fragment, { children: [_jsx("div", { style: {
111
+ backgroundColor: 'white',
112
+ opacity: 0.5,
113
+ left: 0,
114
+ top: 0,
115
+ position: 'fixed',
116
+ width: '100%',
117
+ height: '100%',
118
+ zIndex: 10,
119
+ } }), _jsx(InnerPrintFrame, { printPageOptions: pageOptions, onAfterPrint: () => {
120
+ setPageOptions(null);
121
+ onAfterPrint?.();
122
+ }, onBeforePrint: () => {
123
+ onBeforePrint?.();
124
+ }, children: children })] }));
125
+ }
126
+ export function InnerPrintFrame(props) {
127
+ const { children, onAfterPrint, onBeforePrint, printPageOptions = {}, } = props;
128
+ const { size = 'A4', margin = 0, layout = 'landscape', } = printPageOptions || {};
129
+ const frameRef = useRef(null);
130
+ const [content, setContent] = useState();
131
+ const { width = 0, height = 0 } = pageSizes.find((pageItem) => pageItem.name === size)?.[layout] || {};
132
+ const handleAfterPrint = useCallback(() => {
133
+ onAfterPrint?.();
134
+ }, [onAfterPrint]);
135
+ const handleBeforePrint = useCallback(() => {
136
+ onBeforePrint?.();
137
+ }, [onBeforePrint]);
138
+ const load = useCallback(() => {
139
+ const contentWindow = frameRef.current?.contentWindow;
140
+ if (!contentWindow)
141
+ return;
142
+ const document = contentWindow.document;
143
+ setContent(document.body);
144
+ transferStyles(document);
145
+ appendPrintPageStyle(document, { size, layout, margin });
146
+ contentWindow.addEventListener('afterprint', handleAfterPrint);
147
+ contentWindow.addEventListener('beforeprint', handleBeforePrint);
148
+ return contentWindow;
149
+ }, [handleAfterPrint, handleBeforePrint, layout, margin, size]);
150
+ useEffect(() => {
151
+ const contentWindow = frameRef.current?.contentWindow;
152
+ if (!isFirefox) {
153
+ load();
154
+ }
155
+ return () => {
156
+ if (!contentWindow)
157
+ return;
158
+ contentWindow.removeEventListener('afterprint', handleAfterPrint);
159
+ contentWindow.removeEventListener('beforeprint', handleBeforePrint);
160
+ };
161
+ }, [
162
+ onBeforePrint,
163
+ onAfterPrint,
164
+ handleBeforePrint,
165
+ handleAfterPrint,
166
+ size,
167
+ layout,
168
+ margin,
169
+ load,
170
+ ]);
171
+ return (_jsx(PrintProvider, { width: width, height: height, margin: margin, children: _jsx("iframe", { ref: frameRef, style: {
172
+ width: 0,
173
+ height: 0,
174
+ border: 'none',
175
+ }, onLoad: () => {
176
+ if (isFirefox) {
177
+ load();
178
+ }
179
+ }, children: content &&
180
+ createPortal(_jsx(RenderContainer, { onRenderComplete: () => {
181
+ frameRef.current?.contentWindow?.focus();
182
+ frameRef.current?.contentWindow?.print();
183
+ }, style: {
184
+ width: `${width - margin}cm`,
185
+ height: `${height - margin}cm`,
186
+ margin: `${margin}cm`,
187
+ }, children: children }), content) }) }));
188
+ }
189
+ function RenderContainer(props) {
190
+ const { onRenderComplete, style, children } = props;
191
+ useEffect(() => {
192
+ const handleRenderComplete = () => {
193
+ setTimeout(() => {
194
+ onRenderComplete();
195
+ }, 250);
196
+ };
197
+ const animationFrameId = requestAnimationFrame(handleRenderComplete);
198
+ return () => {
199
+ cancelAnimationFrame(animationFrameId);
200
+ };
201
+ }, [onRenderComplete]);
202
+ return _jsx("div", { style: style, children: children });
203
+ }
204
+ function appendPrintPageStyle(document, style = {}) {
205
+ const { layout = 'landscape', size = 'A4' } = style;
206
+ const styleElement = document.createElement('style');
207
+ styleElement.textContent = `
208
+ @media print {
209
+
210
+ @page {
211
+ size: ${size} ${layout};
212
+ padding:0;
213
+ margin:0;
214
+ }
215
+ }
216
+ `;
217
+ document.head.append(styleElement);
218
+ }
219
+ function transferStyles(targetDocument) {
220
+ // Copy the style from the main page and inject it inside the iframe
221
+ const styleSheets = Array.from(document.styleSheets);
222
+ const targetHead = targetDocument.head;
223
+ for (const styleSheet of styleSheets) {
224
+ try {
225
+ if (styleSheet.cssRules) {
226
+ const newStyleEl = document.createElement('style');
227
+ const cssRules = Array.from(styleSheet.cssRules);
228
+ const cssText = cssRules.map((rule) => rule.cssText).join('\n');
229
+ newStyleEl.append(document.createTextNode(cssText));
230
+ targetHead.append(newStyleEl);
231
+ }
232
+ }
233
+ catch (error) {
234
+ // eslint-disable-next-line no-console
235
+ console.error('Error transferring styles:', error);
236
+ }
237
+ }
238
+ }
239
+ function PrintPageOptionsModal(props) {
240
+ const { isOpen, ...otherProps } = props;
241
+ if (!isOpen)
242
+ return;
243
+ return _jsx(InnerPrintOptionsModal, { ...otherProps });
244
+ }
245
+ const labelStyle = {
246
+ label: {
247
+ flex: 4,
248
+ color: '#232323',
249
+ },
250
+ wrapper: {
251
+ flex: 8,
252
+ display: 'flex',
253
+ justifyContent: 'flex-start',
254
+ },
255
+ container: { margin: '5px 0' },
256
+ };
257
+ const INITIAL_VALUE = {
258
+ size: 'A4',
259
+ layout: 'landscape',
260
+ margin: 0,
261
+ };
262
+ function InnerPrintOptionsModal(props) {
263
+ const { onCloseDialog, onPrint, defaultPrintPageOptions } = props;
264
+ function submitHandler(values) {
265
+ onPrint(values);
266
+ onCloseDialog?.();
267
+ }
268
+ const { handleSubmit, control, watch } = useForm({
269
+ defaultValues: { ...INITIAL_VALUE, ...defaultPrintPageOptions },
270
+ });
271
+ const layout = watch('layout');
272
+ const sizesList = getSizesList(layout);
273
+ return (_jsxs(Dialog, { isOpen: true, title: "Print options", onClose: onCloseDialog, style: { width: 600 }, children: [_jsxs(DialogBody, { css: css `
274
+ background-color: white;
275
+ `, children: [_jsx(Label, { style: labelStyle, title: "Size", children: _jsx(Select2Controller, { control: control, name: "size", items: sizesList }) }), _jsx(Label, { style: labelStyle, title: "Layout", children: _jsx(Controller, { name: "layout", control: control, render: ({ field }) => {
276
+ const { value, onChange, ...otherFieldProps } = field;
277
+ return (_jsxs(RadioGroup, { inline: true, onChange: onChange, selectedValue: value, ...otherFieldProps, children: [_jsx(Radio, { label: "Portrait", value: "portrait" }), _jsx(Radio, { label: "Landscape", value: "landscape" })] }));
278
+ } }) }), _jsx(Label, { style: labelStyle, title: "Margin", children: _jsx(NumberInput2Controller, { name: "margin", control: control, min: 0, rightElement: _jsx(Tag, { children: "cm" }) }) })] }), _jsx(DialogFooter, { children: _jsx(ActionButtons, { style: { flexDirection: 'row-reverse', margin: 0 }, onDone: () => {
279
+ void handleSubmit(submitHandler)();
280
+ }, doneLabel: "Print", onCancel: () => onCloseDialog?.() }) })] }));
281
+ }
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ interface PrintPagContextProps {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ export declare function usePrintPage(): PrintPagContextProps | null;
7
+ interface PrintProviderProps extends PrintPagContextProps {
8
+ children: ReactNode;
9
+ margin: number;
10
+ }
11
+ export declare function PrintProvider(props: PrintProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from 'react';
3
+ const PrintContext = createContext(null);
4
+ export function usePrintPage() {
5
+ return useContext(PrintContext);
6
+ }
7
+ /**
8
+ * Converts centimetre to pixels.
9
+ * @param cm - The value in centimetre.
10
+ * @param ppi - Pixels per inch (default is 96).
11
+ * @returns The value in pixels.
12
+ */
13
+ function cmToPx(cm, margin, ppi = 96) {
14
+ const inches = (cm - margin * 2) / 2.54;
15
+ return Math.round(inches * ppi);
16
+ }
17
+ export function PrintProvider(props) {
18
+ const { children, width, height, margin } = props;
19
+ const state = useMemo(() => {
20
+ const w = cmToPx(width, margin);
21
+ const h = cmToPx(height, margin);
22
+ return {
23
+ width: w,
24
+ height: h,
25
+ };
26
+ }, [height, margin, width]);
27
+ return (_jsx(PrintContext.Provider, { value: state, children: children }));
28
+ }
@@ -0,0 +1,2 @@
1
+ export * from './PrintContent';
2
+ export * from './PrintProvider';
@@ -0,0 +1,2 @@
1
+ export * from './PrintContent';
2
+ export * from './PrintProvider';
@@ -127,6 +127,9 @@ function BaseLineCorrectionInnerPanel(props) {
127
127
  onItemSelect(item);
128
128
  const { values } = getData(item.value, props?.filter?.value || {});
129
129
  reset(values);
130
+ setTimeout(() => {
131
+ submitHandler();
132
+ }, 0);
130
133
  }, ...defaultSelectProps, children: _jsx(Button, { text: algorithm?.label, rightIcon: "double-caret-vertical" }) }) }), algorithm && algorithm?.value === 'airpls' && (_jsxs("div", { style: { display: 'flex' }, children: [_jsx(Label, { title: "Max iterations:", style: headerLabelStyle, children: _jsx(NumberInput2Controller, { control: control, name: "maxIterations", min: 0, stepSize: 1, style: { width: '60px' }, debounceTime: 250, onValueChange: () => {
131
134
  submitHandler();
132
135
  } }) }), _jsx(Label, { title: "Tolerance:", style: headerLabelStyle, children: _jsx(NumberInput2Controller, { control: control, name: "tolerance", min: 0, stepSize: 0.001, majorStepSize: 0.001, minorStepSize: 0.001, style: { width: '60px' }, debounceTime: 250, onValueChange: () => {
@@ -1,10 +1,15 @@
1
- export declare function useToggleSpectraVisibility(mode?: 'selected' | 'all'): {
2
- showSpectraHandler: () => void;
3
- hideSpectraHandler: () => void;
4
- getToggleVisibilityButtons: (disabled?: boolean) => {
5
- disabled: boolean;
6
- icon: import("react/jsx-runtime").JSX.Element;
7
- tooltip: string;
8
- onClick: () => void;
9
- }[];
1
+ import { ToolbarItemProps } from '../panels/header/DefaultPanelHeader';
2
+ import { SpectraSelectedMode } from '../reducer/actions/SpectraActions';
3
+ interface ToggleSpectraVisibility {
4
+ enableShowAll: boolean;
5
+ enableShowSelected: boolean;
6
+ enableShowSelectedOnly: boolean;
7
+ enableHideSelected: boolean;
8
+ enableHideAll: boolean;
9
+ }
10
+ export declare function useToggleSpectraVisibility(props?: Partial<ToggleSpectraVisibility>): {
11
+ showSpectraHandler: (mode: SpectraSelectedMode) => void;
12
+ hideSpectraHandler: (mode: SpectraSelectedMode) => void;
13
+ getToggleVisibilityButtons: (disabled?: boolean) => ToolbarItemProps[];
10
14
  };
15
+ export {};
@@ -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,
@@ -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 {};