nmrium 0.57.1 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/lib/component/1d/integral/IntegralResizable.js +2 -2
  2. package/lib/component/1d/matrix/useMatrix.d.ts +1 -1
  3. package/lib/component/1d/multiAnalysis/AnalysisRange.js +1 -1
  4. package/lib/component/1d/ranges/Atoms.js +6 -4
  5. package/lib/component/1d-2d/components/SpectrumInfoBlock.d.ts +1 -1
  6. package/lib/component/1d-2d/components/SpectrumInfoBlock.js +114 -7
  7. package/lib/component/2d/Viewer2D.js +6 -2
  8. package/lib/component/2d/zones/Zone.js +2 -2
  9. package/lib/component/EventsTrackers/KeysListenerTracker.js +8 -8
  10. package/lib/component/context/ChartContext.js +12 -1
  11. package/lib/component/context/ShareDataContext.d.ts +1 -1
  12. package/lib/component/context/ShareDataContext.js +2 -4
  13. package/lib/component/context/ToasterContext.d.ts +1 -0
  14. package/lib/component/context/ToasterContext.js +12 -3
  15. package/lib/component/elements/ActionsButtonsPopover.d.ts +7 -1
  16. package/lib/component/elements/ActionsButtonsPopover.js +7 -6
  17. package/lib/component/elements/Alert.d.ts +20 -0
  18. package/lib/component/elements/Alert.js +80 -0
  19. package/lib/component/elements/ContextMenuBluePrint.d.ts +7 -2
  20. package/lib/component/elements/ContextMenuBluePrint.js +9 -3
  21. package/lib/component/elements/Input2.js +2 -2
  22. package/lib/component/elements/Input2Controller.d.ts +4 -2
  23. package/lib/component/elements/Input2Controller.js +22 -6
  24. package/lib/component/elements/MoleculeSelection.js +2 -2
  25. package/lib/component/elements/NextPrev.d.ts +4 -5
  26. package/lib/component/elements/NextPrev.js +76 -79
  27. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +1 -1
  28. package/lib/component/elements/ReactTable/ReactTableFlexLayout.d.ts +0 -3
  29. package/lib/component/elements/ReactTable/ReactTableFlexLayout.js +1 -1
  30. package/lib/component/elements/Select2.d.ts +12 -7
  31. package/lib/component/elements/Select2.js +5 -4
  32. package/lib/component/elements/Select2Controller.d.ts +2 -2
  33. package/lib/component/elements/Select2Controller.js +5 -5
  34. package/lib/component/elements/ToolbarPopoverItem.d.ts +7 -6
  35. package/lib/component/elements/ToolbarPopoverItem.js +13 -5
  36. package/lib/component/elements/print/PrintContent.d.ts +17 -0
  37. package/lib/component/elements/print/PrintContent.js +281 -0
  38. package/lib/component/elements/print/PrintProvider.d.ts +12 -0
  39. package/lib/component/elements/print/PrintProvider.js +28 -0
  40. package/lib/component/elements/print/index.d.ts +2 -0
  41. package/lib/component/elements/print/index.js +2 -0
  42. package/lib/component/header/ApodizationOptionsPanel.js +14 -7
  43. package/lib/component/header/BaseLineCorrectionPanel.js +20 -10
  44. package/lib/component/header/ZeroFillingOptionsPanel.js +17 -10
  45. package/lib/component/hooks/useSaveSettings.js +43 -26
  46. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +14 -9
  47. package/lib/component/hooks/useToggleSpectraVisibility.js +45 -16
  48. package/lib/component/hooks/useWorkspaceAction.js +12 -14
  49. package/lib/component/loader/DropZone.js +3 -67
  50. package/lib/component/loader/useLoadFiles.d.ts +1 -0
  51. package/lib/component/loader/useLoadFiles.js +78 -0
  52. package/lib/component/main/InnerNMRium.d.ts +4 -3
  53. package/lib/component/main/InnerNMRium.js +4 -9
  54. package/lib/component/main/InnerNMRiumContents.d.ts +3 -2
  55. package/lib/component/main/InnerNMRiumContents.js +33 -29
  56. package/lib/component/main/NMRium.d.ts +2 -5
  57. package/lib/component/main/NMRium.js +1 -1
  58. package/lib/component/main/NMRiumRefAPI.d.ts +7 -0
  59. package/lib/component/main/NMRiumRefAPI.js +12 -0
  60. package/lib/component/main/NMRiumViewer.d.ts +10 -0
  61. package/lib/component/main/NMRiumViewer.js +35 -0
  62. package/lib/component/main/index.d.ts +1 -0
  63. package/lib/component/modal/CopyClipboardModal.d.ts +3 -2
  64. package/lib/component/modal/CopyClipboardModal.js +18 -32
  65. package/lib/component/modal/ExportAsJcampModal.d.ts +6 -3
  66. package/lib/component/modal/ExportAsJcampModal.js +69 -35
  67. package/lib/component/modal/ImportPublicationStringModal.js +1 -1
  68. package/lib/component/modal/LoadJCAMPModal.d.ts +3 -1
  69. package/lib/component/modal/LoadJCAMPModal.js +17 -18
  70. package/lib/component/modal/SaveAsModal.d.ts +3 -1
  71. package/lib/component/modal/SaveAsModal.js +20 -30
  72. package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
  73. package/lib/component/modal/changeSum/ChangeSumModalContents.js +35 -47
  74. package/lib/component/modal/changeSum/SelectMolecule.d.ts +2 -5
  75. package/lib/component/modal/changeSum/SelectMolecule.js +9 -8
  76. package/lib/component/modal/setting/GeneralSettings.js +4 -2
  77. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.d.ts +1 -0
  78. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.js +89 -0
  79. package/lib/component/modal/setting/settingsValidation.js +15 -1
  80. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +8 -5
  81. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +5 -1
  82. package/lib/component/panels/MoleculesPanel/MoleculePanel.js +5 -3
  83. package/lib/component/panels/Panels.js +15 -15
  84. package/lib/component/panels/PeaksPanel/PeaksPanel.js +8 -5
  85. package/lib/component/panels/RangesPanel/RangesHeader.js +52 -12
  86. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +13 -6
  87. package/lib/component/panels/SpectraPanel/SpectraTable.js +63 -21
  88. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +6 -2
  89. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +6 -2
  90. package/lib/component/panels/SummaryPanel/SummaryPanel.js +4 -0
  91. package/lib/component/panels/ZonesPanel/ZonesPanel.js +16 -8
  92. package/lib/component/panels/databasePanel/DatabasePanel.js +7 -8
  93. package/lib/component/panels/filtersPanel/FilterPanel.js +9 -6
  94. package/lib/component/panels/filtersPanel/FiltersTable.js +12 -10
  95. package/lib/component/panels/header/DefaultPanelHeader.d.ts +1 -0
  96. package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
  97. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +10 -12
  98. package/lib/component/panels/predictionPanel/PredictionPanel.js +2 -2
  99. package/lib/component/reducer/IgnoreActions.js +1 -0
  100. package/lib/component/reducer/Reducer.js +2 -4
  101. package/lib/component/reducer/actions/DatabaseActions.d.ts +15 -13
  102. package/lib/component/reducer/actions/DatabaseActions.js +52 -34
  103. package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
  104. package/lib/component/reducer/actions/FiltersActions.js +9 -4
  105. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  106. package/lib/component/reducer/actions/SpectraActions.js +53 -43
  107. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.d.ts +3 -0
  108. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.js +16 -0
  109. package/lib/component/reducer/preferences/actions/changeInformationBlockPosition.d.ts +3 -0
  110. package/lib/component/reducer/preferences/actions/changeInformationBlockPosition.js +5 -0
  111. package/lib/component/reducer/preferences/actions/changePrintPageSettings.d.ts +3 -0
  112. package/lib/component/reducer/preferences/actions/changePrintPageSettings.js +6 -0
  113. package/lib/component/reducer/preferences/actions/toggleInformationBlock.d.ts +3 -0
  114. package/lib/component/reducer/preferences/actions/toggleInformationBlock.js +7 -0
  115. package/lib/component/reducer/preferences/preferencesReducer.d.ts +12 -2
  116. package/lib/component/reducer/preferences/preferencesReducer.js +9 -0
  117. package/lib/component/toolbar/ToolBar.js +33 -14
  118. package/lib/component/workspaces/workspaceDefaultProperties.js +2 -0
  119. package/lib/data/SpectraManager.d.ts +7 -10
  120. package/lib/data/SpectraManager.js +51 -30
  121. package/lib/data/data1d/Spectrum1D/SumManager.d.ts +0 -1
  122. package/lib/data/data1d/Spectrum1D/SumManager.js +2 -10
  123. package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +1 -1
  124. package/lib/data/data1d/Spectrum1D/index.d.ts +1 -1
  125. package/lib/data/data1d/Spectrum1D/index.js +1 -1
  126. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +10 -10
  127. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +2 -1
  128. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +10 -10
  129. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +10 -10
  130. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.d.ts +13 -0
  131. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.js +65 -0
  132. package/lib/data/molecules/MoleculeManager.js +16 -38
  133. package/lib/data/utilities/getCustomColor.d.ts +1 -1
  134. package/lib/data/utilities/removeByPaths.d.ts +3 -0
  135. package/lib/data/utilities/removeByPaths.js +33 -0
  136. package/lib/versionInfo.js +1 -1
  137. package/package.json +36 -36
  138. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +0 -11
  139. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +0 -29
@@ -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';
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Checkbox } from '@blueprintjs/core';
3
3
  import { yupResolver } from '@hookform/resolvers/yup';
4
4
  import { Filters, } from 'nmr-processing';
5
- import { useRef, memo } from 'react';
5
+ import { useRef, memo, useCallback, useEffect } from 'react';
6
6
  import { useForm } from 'react-hook-form';
7
7
  import * as Yup from 'yup';
8
8
  import { defaultApodizationOptions } from '../../data/constants/DefaultApodizationOptions';
@@ -26,16 +26,20 @@ const initialValues = {
26
26
  function ApodizationOptionsInnerPanel(props) {
27
27
  const dispatch = useDispatch();
28
28
  const previousPreviewRef = useRef(initialValues.livePreview);
29
+ const onChange = useCallback((values) => {
30
+ const { livePreview, ...options } = values;
31
+ if (livePreview || previousPreviewRef.current !== livePreview) {
32
+ dispatch({
33
+ type: 'CALCULATE_APODIZATION_FILTER',
34
+ payload: { livePreview, options },
35
+ });
36
+ }
37
+ }, [dispatch]);
29
38
  function handleApplyFilter(values, triggerSource = 'apply') {
30
39
  const { livePreview, ...options } = values;
31
40
  switch (triggerSource) {
32
41
  case 'onChange': {
33
- if (livePreview || previousPreviewRef.current !== livePreview) {
34
- dispatch({
35
- type: 'CALCULATE_APODIZATION_FILTER',
36
- payload: { livePreview, options },
37
- });
38
- }
42
+ onChange(values);
39
43
  break;
40
44
  }
41
45
  case 'apply': {
@@ -68,6 +72,9 @@ function ApodizationOptionsInnerPanel(props) {
68
72
  void handleSubmit((values) => handleApplyFilter(values, 'onChange'))();
69
73
  }
70
74
  const { onChange: onLivePreviewChange, ...otherLivePreviewOptions } = register('livePreview');
75
+ useEffect(() => {
76
+ void handleSubmit((values) => onChange(values))();
77
+ }, [handleSubmit, onChange]);
71
78
  return (_jsxs(HeaderContainer, { children: [_jsx(Label, { title: "Line broadening:", shortTitle: "LB:", style: headerLabelStyle, children: _jsx(NumberInput2Controller, { control: control, name: "lineBroadening", debounceTime: 250, min: 0, max: 1, stepSize: 0.1, style: { width: '60px' }, onValueChange: () => {
72
79
  submitHandler();
73
80
  } }) }), _jsx(Label, { title: "Gauss broadening:", shortTitle: "GB:", style: headerLabelStyle, children: _jsx(NumberInput2Controller, { control: control, name: "gaussBroadening", debounceTime: 250, min: 0, max: 1, stepSize: 0.1, style: { width: '60px' }, onValueChange: () => {
@@ -3,7 +3,7 @@ import { Checkbox } from '@blueprintjs/core';
3
3
  import { Select } from '@blueprintjs/select';
4
4
  import { yupResolver } from '@hookform/resolvers/yup';
5
5
  import { Filters } from 'nmr-processing';
6
- import { memo, useRef } from 'react';
6
+ import { memo, useCallback, useEffect, useRef } from 'react';
7
7
  import { useForm } from 'react-hook-form';
8
8
  import { Button, useSelect } from 'react-science/ui';
9
9
  import * as Yup from 'yup';
@@ -73,19 +73,23 @@ function BaseLineCorrectionInnerPanel(props) {
73
73
  defaultSelectedItem: algorithmsList.find((item) => item.value === baseAlgorithm),
74
74
  itemTextKey: 'label',
75
75
  });
76
+ const onChange = useCallback((values) => {
77
+ const { livePreview, ...options } = values;
78
+ if (livePreview || previousPreviewRef !== livePreview) {
79
+ dispatch({
80
+ type: 'CALCULATE_BASE_LINE_CORRECTION_FILTER',
81
+ payload: {
82
+ options,
83
+ livePreview,
84
+ },
85
+ });
86
+ }
87
+ }, [dispatch]);
76
88
  const handleApplyFilter = (values, triggerSource = 'apply') => {
77
89
  const { livePreview, ...options } = values;
78
90
  switch (triggerSource) {
79
91
  case 'onChange': {
80
- if (livePreview || previousPreviewRef !== livePreview) {
81
- dispatch({
82
- type: 'CALCULATE_BASE_LINE_CORRECTION_FILTER',
83
- payload: {
84
- options,
85
- livePreview,
86
- },
87
- });
88
- }
92
+ onChange(values);
89
93
  break;
90
94
  }
91
95
  case 'apply': {
@@ -116,10 +120,16 @@ function BaseLineCorrectionInnerPanel(props) {
116
120
  void handleSubmit((values) => handleApplyFilter(values, 'onChange'))();
117
121
  }
118
122
  const { onChange: onLivePreviewChange, ...otherLivePreviewRegisterOptions } = register(`livePreview`);
123
+ useEffect(() => {
124
+ void handleSubmit((values) => onChange(values))();
125
+ }, [handleSubmit, onChange]);
119
126
  return (_jsxs(HeaderContainer, { children: [_jsx(Label, { title: "Algorithm: ", style: headerLabelStyle, children: _jsx(Select, { items: algorithmsList, filterable: false, itemsEqual: "value", onItemSelect: (item) => {
120
127
  onItemSelect(item);
121
128
  const { values } = getData(item.value, props?.filter?.value || {});
122
129
  reset(values);
130
+ setTimeout(() => {
131
+ submitHandler();
132
+ }, 0);
123
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: () => {
124
134
  submitHandler();
125
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,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Checkbox } from '@blueprintjs/core';
3
3
  import { Filters } from 'nmr-processing';
4
- import { memo, useRef } from 'react';
4
+ import { memo, useCallback, useEffect, useRef } from 'react';
5
5
  import { useForm } from 'react-hook-form';
6
6
  import generateNumbersPowerOfX from '../../data/utilities/generateNumbersPowerOfX';
7
7
  import { useDispatch } from '../context/DispatchContext';
@@ -31,19 +31,23 @@ function ZeroFillingOptionsInnerPanel(props) {
31
31
  const { handleSubmit, register, control } = useForm({
32
32
  defaultValues: { nbPoints: size, livePreview: true },
33
33
  });
34
+ const onChange = useCallback((values) => {
35
+ const { livePreview, ...options } = values;
36
+ if (livePreview || previousPreviewRef !== livePreview) {
37
+ dispatch({
38
+ type: 'CALCULATE_ZERO_FILLING_FILTER',
39
+ payload: {
40
+ options,
41
+ livePreview,
42
+ },
43
+ });
44
+ }
45
+ }, [dispatch]);
34
46
  function handleApplyFilter(values, triggerSource = 'apply') {
35
47
  const { livePreview, ...options } = values;
36
48
  switch (triggerSource) {
37
49
  case 'onChange': {
38
- if (livePreview || previousPreviewRef !== livePreview) {
39
- dispatch({
40
- type: 'CALCULATE_ZERO_FILLING_FILTER',
41
- payload: {
42
- options,
43
- livePreview,
44
- },
45
- });
46
- }
50
+ onChange(values);
47
51
  break;
48
52
  }
49
53
  case 'apply': {
@@ -69,6 +73,9 @@ function ZeroFillingOptionsInnerPanel(props) {
69
73
  function submitHandler(triggerSource = 'apply') {
70
74
  void handleSubmit((values) => handleApplyFilter(values, triggerSource))();
71
75
  }
76
+ useEffect(() => {
77
+ void handleSubmit((values) => onChange(values))();
78
+ }, [handleSubmit, onChange]);
72
79
  return (_jsxs(HeaderContainer, { children: [_jsx(Label, { title: "Size:", style: headerLabelStyle, children: _jsx(Select2Controller, { control: control, name: "nbPoints", items: sizes, onItemSelect: () => {
73
80
  submitHandler('onChange');
74
81
  } }) }), _jsx(Label, { title: "Live preview", style: { label: { padding: '0 5px' } }, children: _jsx(Checkbox, { style: { margin: 0 }, ...otherLivePreviewRegisterOptions, onChange: (event) => {
@@ -1,33 +1,46 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Dialog } from '@blueprintjs/core';
3
- import { Formik } from 'formik';
4
- import { useRef, forwardRef } from 'react';
3
+ import { yupResolver } from '@hookform/resolvers/yup';
4
+ import { useRef } from 'react';
5
+ import { useForm } from 'react-hook-form';
5
6
  import { useOnOff } from 'react-science/ui';
6
7
  import * as Yup from 'yup';
7
8
  import { usePreferences } from '../context/PreferencesContext';
8
9
  import { useToaster } from '../context/ToasterContext';
9
- import FormikInput from '../elements/formik/FormikInput';
10
+ import { Input2Controller } from '../elements/Input2Controller';
10
11
  import ConfirmationDialog from '../elements/popup/Modal/ConfirmDialog';
11
12
  import { useWorkspaceAction } from './useWorkspaceAction';
12
13
  const schema = Yup.object().shape({
13
14
  workspaceName: Yup.string().required(),
14
15
  });
15
- const WorkspaceAddForm = forwardRef(({ className, message, onSave }, ref) => {
16
- return (_jsxs("div", { className: className, children: [_jsx("p", { style: { paddingBottom: '10px' }, children: message }), _jsx(Formik, { initialValues: { workspaceName: '' }, validationSchema: schema, onSubmit: onSave, innerRef: ref, children: _jsx(FormikInput, { name: "workspaceName", placeholder: "Enter workspace Name", style: {
17
- input: {
18
- padding: '0.5em',
19
- width: '90%',
20
- fontWeight: 'normal',
21
- color: 'black',
22
- },
23
- }, autoFocus: true }) })] }));
24
- });
16
+ function keyDownCheck(event) {
17
+ if (event.key === 'Enter') {
18
+ return true;
19
+ }
20
+ else if (event.key === 'Escape') {
21
+ return false;
22
+ }
23
+ }
24
+ function WorkspaceAddForm(props) {
25
+ const { className, message, control, onEnter } = props;
26
+ return (_jsxs("div", { className: className, children: [_jsx("p", { style: { paddingBottom: '10px' }, children: message }), _jsx(Input2Controller, { control: control, name: "workspaceName", placeholder: "Enter workspace Name", style: {
27
+ width: '90%',
28
+ borderRadius: '5px',
29
+ }, autoFocus: true, large: true, onKeyDown: (event) => {
30
+ if (keyDownCheck(event)) {
31
+ onEnter();
32
+ }
33
+ } })] }));
34
+ }
25
35
  export function useSaveSettings() {
26
36
  const toaster = useToaster();
27
37
  const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
28
38
  const settingsRef = useRef();
29
39
  const { current } = usePreferences();
30
- const formRef = useRef(null);
40
+ const { handleSubmit, control, reset } = useForm({
41
+ defaultValues: { workspaceName: '' },
42
+ resolver: yupResolver(schema),
43
+ });
31
44
  const { saveWorkspace, addNewWorkspace } = useWorkspaceAction();
32
45
  function handleAddNewWorkspace({ workspaceName }) {
33
46
  addNewWorkspace(workspaceName, settingsRef.current);
@@ -37,26 +50,30 @@ export function useSaveSettings() {
37
50
  intent: 'success',
38
51
  });
39
52
  }
53
+ function saveSettings(values) {
54
+ settingsRef.current = values;
55
+ if (current.source !== 'user') {
56
+ reset({ workspaceName: '' });
57
+ openDialog();
58
+ }
59
+ else {
60
+ saveWorkspace(values);
61
+ closeDialog();
62
+ }
63
+ }
40
64
  return {
41
- saveSettings: (values) => {
42
- settingsRef.current = values;
43
- if (current.source !== 'user') {
44
- openDialog();
45
- }
46
- else {
47
- saveWorkspace(values);
48
- closeDialog();
49
- }
50
- },
65
+ saveSettings,
51
66
  SaveSettingsModal: () => {
52
67
  const alertConfig = {
53
68
  message: 'Please enter a new user workspace name in order to save your changes locally',
54
- render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave: handleAddNewWorkspace, ref: formRef })),
69
+ render: (props) => (_jsx(WorkspaceAddForm, { ...props, onEnter: () => {
70
+ void handleSubmit(handleAddNewWorkspace)();
71
+ }, control: control })),
55
72
  buttons: [
56
73
  {
57
74
  text: 'Save',
58
75
  handler: () => {
59
- void formRef.current?.submitForm();
76
+ void handleSubmit(handleAddNewWorkspace)();
60
77
  },
61
78
  preventClose: true,
62
79
  },
@@ -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 {};