nmrium 0.58.0 → 0.60.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 (194) hide show
  1. package/lib/component/1d/LinesSeries.js +17 -5
  2. package/lib/component/1d/Viewer1D.js +10 -4
  3. package/lib/component/1d/integral/IntegralResizable.js +2 -2
  4. package/lib/component/1d/matrix/useMatrix.d.ts +1 -1
  5. package/lib/component/1d/multiAnalysis/AnalysisRange.js +1 -1
  6. package/lib/component/1d/ranges/Atoms.js +6 -4
  7. package/lib/component/1d/ranges/Range.js +4 -2
  8. package/lib/component/1d/tool/PivotIndicator.d.ts +1 -0
  9. package/lib/component/1d/tool/{VerticalIndicator.js → PivotIndicator.js} +8 -4
  10. package/lib/component/1d-2d/tools/BrushXY.js +0 -1
  11. package/lib/component/1d-2d/tools/CrossLinePointer.js +0 -1
  12. package/lib/component/2d/Viewer2D.js +7 -3
  13. package/lib/component/2d/tools/PivotIndicator.d.ts +1 -2
  14. package/lib/component/2d/tools/PivotIndicator.js +2 -3
  15. package/lib/component/2d/zones/Zone.js +2 -2
  16. package/lib/component/EventsTrackers/KeysListenerTracker.js +8 -8
  17. package/lib/component/context/ChartContext.js +12 -1
  18. package/lib/component/context/ShareDataContext.d.ts +1 -1
  19. package/lib/component/context/ShareDataContext.js +2 -4
  20. package/lib/component/context/ToasterContext.d.ts +1 -0
  21. package/lib/component/context/ToasterContext.js +12 -3
  22. package/lib/component/elements/ActionsButtonsPopover.js +1 -3
  23. package/lib/component/elements/Alert.d.ts +20 -0
  24. package/lib/component/elements/Alert.js +80 -0
  25. package/lib/component/elements/ContextMenuBluePrint.d.ts +7 -2
  26. package/lib/component/elements/ContextMenuBluePrint.js +9 -3
  27. package/lib/component/elements/DialogManager.d.ts +34 -0
  28. package/lib/component/elements/DialogManager.js +96 -0
  29. package/lib/component/elements/DraggableDialog.d.ts +13 -0
  30. package/lib/component/elements/DraggableDialog.js +156 -0
  31. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +1 -1
  32. package/lib/component/elements/ReactTable/ReactTableFlexLayout.d.ts +0 -3
  33. package/lib/component/elements/ReactTable/ReactTableFlexLayout.js +1 -1
  34. package/lib/component/elements/Select2.d.ts +12 -7
  35. package/lib/component/elements/Select2.js +5 -4
  36. package/lib/component/elements/Select2Controller.d.ts +2 -2
  37. package/lib/component/elements/Select2Controller.js +5 -5
  38. package/lib/component/elements/TabTitle.d.ts +9 -0
  39. package/lib/component/elements/TabTitle.js +18 -0
  40. package/lib/component/elements/ToolbarPopoverItem.d.ts +7 -6
  41. package/lib/component/elements/ToolbarPopoverItem.js +13 -5
  42. package/lib/component/elements/print/PrintContent.d.ts +17 -0
  43. package/lib/component/elements/print/PrintContent.js +281 -0
  44. package/lib/component/elements/print/PrintProvider.d.ts +12 -0
  45. package/lib/component/elements/print/PrintProvider.js +28 -0
  46. package/lib/component/elements/print/index.d.ts +2 -0
  47. package/lib/component/elements/print/index.js +2 -0
  48. package/lib/component/header/ApodizationOptionsPanel.js +2 -2
  49. package/lib/component/header/BaseLineCorrectionPanel.js +3 -0
  50. package/lib/component/hooks/useSaveSettings.d.ts +1 -1
  51. package/lib/component/hooks/useSaveSettings.js +18 -22
  52. package/lib/component/hooks/useToggleSpectraVisibility.d.ts +14 -9
  53. package/lib/component/hooks/useToggleSpectraVisibility.js +45 -16
  54. package/lib/component/loader/DropZone.js +3 -67
  55. package/lib/component/loader/useLoadFiles.d.ts +1 -0
  56. package/lib/component/loader/useLoadFiles.js +78 -0
  57. package/lib/component/main/InnerNMRium.d.ts +4 -3
  58. package/lib/component/main/InnerNMRium.js +5 -10
  59. package/lib/component/main/InnerNMRiumContents.d.ts +3 -2
  60. package/lib/component/main/InnerNMRiumContents.js +38 -29
  61. package/lib/component/main/NMRium.d.ts +2 -5
  62. package/lib/component/main/NMRium.js +1 -1
  63. package/lib/component/main/NMRiumRefAPI.d.ts +7 -0
  64. package/lib/component/main/NMRiumRefAPI.js +12 -0
  65. package/lib/component/main/NMRiumViewer.d.ts +10 -0
  66. package/lib/component/main/NMRiumViewer.js +35 -0
  67. package/lib/component/main/index.d.ts +1 -0
  68. package/lib/component/modal/CopyClipboardModal.d.ts +3 -2
  69. package/lib/component/modal/CopyClipboardModal.js +18 -32
  70. package/lib/component/modal/EditPeakShapeModal.d.ts +4 -6
  71. package/lib/component/modal/EditPeakShapeModal.js +45 -33
  72. package/lib/component/modal/ExportAsJcampModal.d.ts +6 -3
  73. package/lib/component/modal/ExportAsJcampModal.js +69 -35
  74. package/lib/component/modal/ImportPublicationStringModal.js +1 -1
  75. package/lib/component/modal/editRange/EditRangeModal.d.ts +2 -10
  76. package/lib/component/modal/editRange/EditRangeModal.js +26 -54
  77. package/lib/component/modal/editZone/EditZoneModal.d.ts +3 -8
  78. package/lib/component/modal/editZone/EditZoneModal.js +74 -91
  79. package/lib/component/modal/editZone/SignalsForm.d.ts +1 -2
  80. package/lib/component/modal/editZone/SignalsForm.js +33 -50
  81. package/lib/component/modal/editZone/validation/isDefaultPathLength.d.ts +1 -2
  82. package/lib/component/modal/editZone/validation/isDefaultPathLength.js +3 -5
  83. package/lib/component/modal/setting/GeneralSettings.js +4 -2
  84. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.d.ts +1 -0
  85. package/lib/component/modal/setting/settings-tabs/ExternalAPIsTabContent.js +89 -0
  86. package/lib/component/modal/setting/settingsValidation.js +15 -1
  87. package/lib/component/panels/IntegralsPanel/IntegralPanel.js +8 -5
  88. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +5 -1
  89. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +13 -3
  90. package/lib/component/panels/Panels.js +2 -2
  91. package/lib/component/panels/PeaksPanel/PeaksPanel.js +8 -5
  92. package/lib/component/panels/PeaksPanel/PeaksTable.js +7 -13
  93. package/lib/component/panels/RangesPanel/RangesHeader.js +52 -15
  94. package/lib/component/panels/RangesPanel/RangesTable.js +6 -3
  95. package/lib/component/panels/RangesPanel/TableColumns/ActionsColumn.js +21 -3
  96. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.d.ts +6 -5
  97. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +41 -64
  98. package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +13 -6
  99. package/lib/component/panels/SpectraPanel/SpectraTable.js +63 -21
  100. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnField.d.ts +1 -2
  101. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnField.js +33 -41
  102. package/lib/component/panels/SummaryPanel/CorrelationTable/AdditionalColumnHeader.js +68 -53
  103. package/lib/component/panels/SummaryPanel/CorrelationTable/CorrelationTableRow.js +70 -58
  104. package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.d.ts +13 -8
  105. package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.js +17 -81
  106. package/lib/component/panels/SummaryPanel/SummaryPanel.d.ts +3 -0
  107. package/lib/component/panels/SummaryPanel/SummaryPanel.js +8 -1
  108. package/lib/component/panels/SummaryPanel/utilities/Utilities.js +1 -1
  109. package/lib/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +62 -43
  110. package/lib/component/panels/ZonesPanel/ZonesPanel.js +16 -8
  111. package/lib/component/panels/ZonesPanel/ZonesTable.js +4 -1
  112. package/lib/component/panels/ZonesPanel/hooks/useZoneActions.d.ts +5 -0
  113. package/lib/component/panels/ZonesPanel/hooks/useZoneActions.js +40 -0
  114. package/lib/component/panels/databasePanel/DatabasePanel.js +7 -8
  115. package/lib/component/panels/filtersPanel/FilterPanel.js +9 -6
  116. package/lib/component/panels/filtersPanel/FiltersTable.js +12 -10
  117. package/lib/component/panels/header/DefaultPanelHeader.d.ts +1 -0
  118. package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
  119. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +10 -12
  120. package/lib/component/reducer/IgnoreActions.js +1 -0
  121. package/lib/component/reducer/Reducer.js +2 -4
  122. package/lib/component/reducer/actions/DatabaseActions.d.ts +15 -13
  123. package/lib/component/reducer/actions/DatabaseActions.js +52 -34
  124. package/lib/component/reducer/actions/DomainActions.d.ts +2 -2
  125. package/lib/component/reducer/actions/FiltersActions.js +9 -4
  126. package/lib/component/reducer/actions/RangesActions.d.ts +1 -0
  127. package/lib/component/reducer/actions/RangesActions.js +9 -4
  128. package/lib/component/reducer/actions/SpectraActions.d.ts +2 -1
  129. package/lib/component/reducer/actions/SpectraActions.js +53 -43
  130. package/lib/component/reducer/actions/ToolsActions.js +0 -17
  131. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.d.ts +3 -0
  132. package/lib/component/reducer/helper/removeSpectrumRelatedObjectsById.js +16 -0
  133. package/lib/component/reducer/preferences/actions/changePrintPageSettings.d.ts +3 -0
  134. package/lib/component/reducer/preferences/actions/changePrintPageSettings.js +6 -0
  135. package/lib/component/reducer/preferences/actions/matrixGeneration.d.ts +0 -4
  136. package/lib/component/reducer/preferences/actions/matrixGeneration.js +1 -2
  137. package/lib/component/reducer/preferences/preferencesReducer.d.ts +3 -2
  138. package/lib/component/reducer/preferences/preferencesReducer.js +4 -1
  139. package/lib/component/toolbar/ToolBar.js +33 -14
  140. package/lib/component/toolbar/ToolTypes.d.ts +1 -1
  141. package/lib/component/toolbar/ToolTypes.js +0 -14
  142. package/lib/component/workspaces/workspaceDefaultProperties.js +2 -0
  143. package/lib/data/SpectraManager.d.ts +7 -10
  144. package/lib/data/SpectraManager.js +51 -30
  145. package/lib/data/data1d/Spectrum1D/SumManager.d.ts +0 -1
  146. package/lib/data/data1d/Spectrum1D/SumManager.js +2 -10
  147. package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +1 -1
  148. package/lib/data/data1d/Spectrum1D/index.d.ts +1 -1
  149. package/lib/data/data1d/Spectrum1D/index.js +1 -1
  150. package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +10 -16
  151. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.d.ts +1 -7
  152. package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +2 -1
  153. package/lib/data/data1d/Spectrum1D/ranges/initiateRanges.d.ts +10 -16
  154. package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +10 -16
  155. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.d.ts +13 -0
  156. package/lib/data/data1d/Spectrum1D/ranges/resurrectSpectrum.js +65 -0
  157. package/lib/data/molecules/MoleculeManager.d.ts +1 -1
  158. package/lib/data/molecules/MoleculeManager.js +21 -49
  159. package/lib/data/utilities/getCustomColor.d.ts +1 -1
  160. package/lib/data/utilities/removeByPaths.d.ts +3 -0
  161. package/lib/data/utilities/removeByPaths.js +33 -0
  162. package/lib/versionInfo.js +1 -1
  163. package/package.json +34 -34
  164. package/lib/component/1d/tool/VerticalIndicator.d.ts +0 -2
  165. package/lib/component/elements/ContextMenu.d.ts +0 -9
  166. package/lib/component/elements/ContextMenu.js +0 -116
  167. package/lib/component/elements/popup/Modal/ConfirmDialog.d.ts +0 -21
  168. package/lib/component/elements/popup/Modal/ConfirmDialog.js +0 -68
  169. package/lib/component/elements/popup/Modal/Context.d.ts +0 -2
  170. package/lib/component/elements/popup/Modal/Context.js +0 -6
  171. package/lib/component/elements/popup/Modal/Modal.d.ts +0 -9
  172. package/lib/component/elements/popup/Modal/Modal.js +0 -42
  173. package/lib/component/elements/popup/Modal/ModalContent.d.ts +0 -6
  174. package/lib/component/elements/popup/Modal/ModalContent.js +0 -27
  175. package/lib/component/elements/popup/Modal/Provider.d.ts +0 -11
  176. package/lib/component/elements/popup/Modal/Provider.js +0 -172
  177. package/lib/component/elements/popup/Modal/index.d.ts +0 -4
  178. package/lib/component/elements/popup/Modal/index.js +0 -4
  179. package/lib/component/elements/popup/Transition.d.ts +0 -14
  180. package/lib/component/elements/popup/Transition.js +0 -35
  181. package/lib/component/elements/popup/Wrapper.d.ts +0 -8
  182. package/lib/component/elements/popup/Wrapper.js +0 -83
  183. package/lib/component/elements/popup/options.d.ts +0 -28
  184. package/lib/component/elements/popup/options.js +0 -25
  185. package/lib/component/elements/popup/utility.d.ts +0 -2
  186. package/lib/component/elements/popup/utility.js +0 -13
  187. package/lib/component/modal/editZone/EditPathLengthFormik.d.ts +0 -5
  188. package/lib/component/modal/editZone/EditPathLengthFormik.js +0 -67
  189. package/lib/component/modal/editZone/SignalFormTab.d.ts +0 -5
  190. package/lib/component/modal/editZone/SignalFormTab.js +0 -6
  191. package/lib/component/modal/editZone/validation/EditZoneValidation.d.ts +0 -14
  192. package/lib/component/modal/editZone/validation/EditZoneValidation.js +0 -14
  193. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +0 -11
  194. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +0 -29
@@ -1,41 +1,38 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
1
  import { useCallback, useMemo } from 'react';
3
2
  import { useAssignmentData } from '../../../assignment/AssignmentsContext';
4
3
  import { useDispatch } from '../../../context/DispatchContext';
5
- import { useModal } from '../../../elements/popup/Modal';
6
- import { positions, transitions } from '../../../elements/popup/options';
7
- import EditRangeModal from '../../../modal/editRange/EditRangeModal';
8
- export default function useEditRangeModal(range) {
4
+ function getZoomRange(range) {
5
+ const { from, to } = range;
6
+ const margin = Math.abs(from - to);
7
+ return [from - margin, to + margin];
8
+ }
9
+ export default function useEditRangeModal() {
9
10
  const dispatch = useDispatch();
10
- const modal = useModal();
11
11
  const assignmentData = useAssignmentData();
12
- const zoomRange = useCallback((modalRange) => {
13
- const _range = modalRange || range;
14
- if (_range) {
15
- const { from, to } = _range;
16
- const margin = Math.abs(from - to);
17
- dispatch({
18
- type: 'SET_X_DOMAIN',
19
- payload: {
20
- xDomain: [from - margin, to + margin],
21
- },
22
- });
12
+ const zoomRange = useCallback((range) => {
13
+ if (!range) {
14
+ return;
23
15
  }
24
- }, [dispatch, range]);
16
+ const xDomain = getZoomRange(range);
17
+ dispatch({
18
+ type: 'SET_X_DOMAIN',
19
+ payload: {
20
+ xDomain,
21
+ },
22
+ });
23
+ }, [dispatch]);
25
24
  const deleteRange = useCallback((id, resetSelectTool = false) => {
26
- if (range || id) {
27
- dispatch({
28
- type: 'DELETE_RANGE',
29
- payload: {
30
- id: id || range?.id,
31
- assignmentData,
32
- resetSelectTool,
33
- },
34
- });
35
- }
36
- }, [assignmentData, dispatch, range]);
37
- const changeRangeSignalKind = useCallback((kind) => {
38
- if (range) {
25
+ dispatch({
26
+ type: 'DELETE_RANGE',
27
+ payload: {
28
+ id,
29
+ assignmentData,
30
+ resetSelectTool,
31
+ },
32
+ });
33
+ }, [assignmentData, dispatch]);
34
+ const changeRangeSignalKind = useCallback((kind, range) => {
35
+ if (!range) {
39
36
  dispatch({
40
37
  type: 'CHANGE_RANGE_SIGNAL_KIND',
41
38
  payload: {
@@ -44,8 +41,8 @@ export default function useEditRangeModal(range) {
44
41
  },
45
42
  });
46
43
  }
47
- }, [dispatch, range]);
48
- const saveEditRangeHandler = useCallback((editedRange, automaticCloseModal = true) => {
44
+ }, [dispatch]);
45
+ const saveEditRange = useCallback((editedRange) => {
49
46
  dispatch({
50
47
  type: 'SAVE_EDITED_RANGE',
51
48
  payload: {
@@ -53,39 +50,19 @@ export default function useEditRangeModal(range) {
53
50
  assignmentData,
54
51
  },
55
52
  });
56
- if (automaticCloseModal) {
57
- modal.close();
58
- }
59
- }, [assignmentData, dispatch, modal]);
60
- const resetHandler = useCallback((originalRange) => {
61
- saveEditRangeHandler(originalRange, false);
62
- modal.close();
63
- }, [modal, saveEditRangeHandler]);
64
- const editRange = useCallback(() => {
65
- if (!range?.id)
66
- return;
67
- dispatch({
68
- type: 'SET_SELECTED_TOOL',
69
- payload: { selectedTool: 'editRange' },
70
- });
71
- modal.show(_jsx(EditRangeModal, { onRest: resetHandler, onSave: saveEditRangeHandler, onZoom: zoomRange, rangeId: range?.id }), {
72
- position: positions.MIDDLE_RIGHT,
73
- transition: transitions.SCALE,
74
- isBackgroundBlur: false,
75
- });
76
- zoomRange();
77
- }, [
78
- dispatch,
79
- modal,
80
- range?.id,
81
- resetHandler,
82
- saveEditRangeHandler,
83
- zoomRange,
84
- ]);
53
+ // if (automaticCloseModal) {
54
+ // modal.close();
55
+ // }
56
+ }, [assignmentData, dispatch]);
57
+ const reset = useCallback((originalRange) => {
58
+ saveEditRange(originalRange);
59
+ // modal.close();
60
+ }, [saveEditRange]);
85
61
  return useMemo(() => ({
86
- editRange,
87
62
  deleteRange,
88
63
  zoomRange,
89
64
  changeRangeSignalKind,
90
- }), [changeRangeSignalKind, deleteRange, editRange, zoomRange]);
65
+ saveEditRange,
66
+ reset,
67
+ }), [changeRangeSignalKind, deleteRange, reset, saveEditRange, zoomRange]);
91
68
  }
@@ -8,7 +8,7 @@ import { useChartData } from '../../context/ChartContext';
8
8
  import { useDispatch } from '../../context/DispatchContext';
9
9
  import { usePreferences } from '../../context/PreferencesContext';
10
10
  import { useToaster } from '../../context/ToasterContext';
11
- import { useModal } from '../../elements/popup/Modal';
11
+ import { useAlert } from '../../elements/Alert';
12
12
  import { useActiveSpectra } from '../../hooks/useActiveSpectra';
13
13
  import useSpectrum from '../../hooks/useSpectrum';
14
14
  import { useToggleSpectraVisibility } from '../../hooks/useToggleSpectraVisibility';
@@ -28,25 +28,25 @@ function getMissingProjection(spectraData, activeTab) {
28
28
  return missingNucleus;
29
29
  }
30
30
  function SpectraPanelHeaderInner({ data, activeSpectrum, activeSpectra, activeTab, displayerMode, onSettingClick, }) {
31
- const modal = useModal();
31
+ const alert = useAlert();
32
32
  const toaster = useToaster();
33
33
  const dispatch = useDispatch();
34
- const { getToggleVisibilityButtons } = useToggleSpectraVisibility('selected');
35
34
  const { current: { spectraColors }, } = usePreferences();
36
35
  const handleDelete = useCallback(() => {
37
- modal.showConfirmDialog({
36
+ alert.showAlert({
38
37
  message: (_jsxs("span", { children: ["You are about to delete", _jsxs("span", { style: { color: 'black' }, children: [" ", activeSpectra?.length, " "] }), "spectra, Are you sure?"] })),
39
38
  buttons: [
40
39
  {
41
40
  text: 'Yes',
42
- handler: () => {
41
+ onClick: () => {
43
42
  dispatch({ type: 'DELETE_SPECTRA', payload: {} });
44
43
  },
44
+ intent: 'danger',
45
45
  },
46
46
  { text: 'No' },
47
47
  ],
48
48
  });
49
- }, [activeSpectra?.length, dispatch, modal]);
49
+ }, [activeSpectra?.length, alert, dispatch]);
50
50
  function addMissingProjectionHandler() {
51
51
  const missingNucleus = getMissingProjection(data, activeTab);
52
52
  if (missingNucleus.length > 0) {
@@ -79,6 +79,13 @@ function SpectraPanelHeaderInner({ data, activeSpectrum, activeSpectra, activeTa
79
79
  }
80
80
  const hasActiveSpectra = activeSpectra && activeSpectra?.length > 0;
81
81
  const spectraLengthPerTab = getSpectraByNucleus(activeTab, data)?.length;
82
+ const { getToggleVisibilityButtons } = useToggleSpectraVisibility(spectraLengthPerTab < 5
83
+ ? {
84
+ enableHideSelected: false,
85
+ enableShowSelected: false,
86
+ enableShowSelectedOnly: false,
87
+ }
88
+ : {});
82
89
  let leftButtons = getToggleVisibilityButtons(!hasActiveSpectra);
83
90
  if (displayerMode === '2D' && activeSpectrum?.info.isFt) {
84
91
  leftButtons.push({
@@ -4,9 +4,11 @@ import lodashGet from 'lodash/get';
4
4
  import { useMemo, useCallback, useState } from 'react';
5
5
  import { FaCopy, FaRegTrashAlt, FaFileExport } from 'react-icons/fa';
6
6
  import { IoColorPaletteOutline } from 'react-icons/io5';
7
+ import { exportForCT } from '../../../data/SpectraManager';
7
8
  import { isSpectrum1D } from '../../../data/data1d/Spectrum1D';
8
9
  import { ClipboardFallbackModal } from '../../../utils/clipboard/clipboardComponents';
9
10
  import { useClipboard } from '../../../utils/clipboard/clipboardHooks';
11
+ import { useChartData } from '../../context/ChartContext';
10
12
  import { useDispatch } from '../../context/DispatchContext';
11
13
  import { useToaster } from '../../context/ToasterContext';
12
14
  import { ContextMenu, } from '../../elements/ContextMenuBluePrint';
@@ -46,6 +48,7 @@ var SpectraContextMenuOptionsKeys;
46
48
  SpectraContextMenuOptionsKeys["ExportAsJcamp"] = "ExportAsJcamp";
47
49
  SpectraContextMenuOptionsKeys["ExportAsText"] = "ExportAsText";
48
50
  SpectraContextMenuOptionsKeys["CopyAsText"] = "CopyAsText";
51
+ SpectraContextMenuOptionsKeys["ExportForCT"] = "ExportForCT";
49
52
  })(SpectraContextMenuOptionsKeys || (SpectraContextMenuOptionsKeys = {}));
50
53
  const Spectra2DContextMenuOptions = [
51
54
  {
@@ -59,24 +62,48 @@ const Spectra2DContextMenuOptions = [
59
62
  data: { id: SpectraContextMenuOptionsKeys.Delete },
60
63
  },
61
64
  ];
62
- const Spectra1DContextMenuOptions = [
63
- ...Spectra2DContextMenuOptions,
64
- {
65
- text: 'Export as JCAMP-DX',
66
- icon: _jsx(FaFileExport, {}),
67
- data: { id: SpectraContextMenuOptionsKeys.ExportAsJcamp },
68
- },
69
- {
70
- text: 'Export as text',
71
- icon: _jsx(FaFileExport, {}),
72
- data: { id: SpectraContextMenuOptionsKeys.ExportAsText },
73
- },
74
- {
75
- text: 'Copy as text',
76
- icon: _jsx(FaCopy, {}),
77
- data: { id: SpectraContextMenuOptionsKeys.CopyAsText },
78
- },
79
- ];
65
+ function getSpectra1DContextMenuOptions(options) {
66
+ const { molecules = [] } = options;
67
+ return [
68
+ ...Spectra2DContextMenuOptions,
69
+ {
70
+ text: 'Export as JCAMP-DX',
71
+ icon: _jsx(FaFileExport, {}),
72
+ data: { id: SpectraContextMenuOptionsKeys.ExportAsJcamp },
73
+ },
74
+ {
75
+ text: 'Export as text',
76
+ icon: _jsx(FaFileExport, {}),
77
+ data: { id: SpectraContextMenuOptionsKeys.ExportAsText },
78
+ },
79
+ {
80
+ text: 'Copy as text',
81
+ icon: _jsx(FaCopy, {}),
82
+ data: { id: SpectraContextMenuOptionsKeys.CopyAsText },
83
+ },
84
+ {
85
+ text: 'Export for CT',
86
+ icon: _jsx(FaFileExport, {}),
87
+ data: { id: SpectraContextMenuOptionsKeys.ExportForCT },
88
+ tooltip: {
89
+ content: 'A chemical structure and a processed proton spectrum are required to use CT',
90
+ },
91
+ disabled: (spectrum) => !isValidExportForCT(spectrum, molecules),
92
+ },
93
+ ];
94
+ }
95
+ function isValidExportForCT(spectrum, molecules) {
96
+ if (!isSpectrum1D(spectrum)) {
97
+ return false;
98
+ }
99
+ if (!spectrum.info.isFt) {
100
+ return false;
101
+ }
102
+ if (!(Array.isArray(molecules) && molecules.length > 0)) {
103
+ return false;
104
+ }
105
+ return true;
106
+ }
80
107
  export function SpectraTable(props) {
81
108
  const { data, activeSpectra, onChangeVisibility, onOpenSettingModal, onChangeActiveSpectrum, nucleus, } = props;
82
109
  const toaster = useToaster();
@@ -85,6 +112,7 @@ export function SpectraTable(props) {
85
112
  const activeSpectraObj = getActiveSpectraAsObject(activeSpectra);
86
113
  const [exportedSpectrum, setExportedSpectrum] = useState();
87
114
  const { rawWriteWithType, shouldFallback, cleanShouldFallback, text } = useClipboard();
115
+ const { molecules } = useChartData();
88
116
  const COLUMNS = useMemo(() => ({
89
117
  visible: {
90
118
  id: 'hide-show-spectrum',
@@ -114,7 +142,7 @@ export function SpectraTable(props) {
114
142
  },
115
143
  },
116
144
  }), [onChangeVisibility, onOpenSettingModal]);
117
- const selectContextMenuHandler = useCallback((option, spectrum) => {
145
+ const selectContextMenuHandler = useCallback(async (option, spectrum) => {
118
146
  const { id } = option;
119
147
  switch (id) {
120
148
  case SpectraContextMenuOptionsKeys.CopyToClipboard: {
@@ -152,11 +180,23 @@ export function SpectraTable(props) {
152
180
  }));
153
181
  break;
154
182
  }
183
+ case SpectraContextMenuOptionsKeys.ExportForCT: {
184
+ try {
185
+ await exportForCT({ spectrum, molecules });
186
+ }
187
+ catch (error) {
188
+ const message = error?.message;
189
+ if (message) {
190
+ toaster.show({ intent: 'danger', message });
191
+ }
192
+ }
193
+ break;
194
+ }
155
195
  default: {
156
196
  break;
157
197
  }
158
198
  }
159
- }, [dispatch, rawWriteWithType, toaster]);
199
+ }, [dispatch, molecules, rawWriteWithType, toaster]);
160
200
  function handleActiveRow(row) {
161
201
  return activeSpectraObj?.[row?.original.id] || false;
162
202
  }
@@ -219,7 +259,9 @@ export function SpectraTable(props) {
219
259
  };
220
260
  }
221
261
  const contextMenu = nucleus.split(',').length === 1
222
- ? Spectra1DContextMenuOptions
262
+ ? getSpectra1DContextMenuOptions({
263
+ molecules,
264
+ })
223
265
  : Spectra2DContextMenuOptions;
224
266
  return (_jsxs(_Fragment, { children: [_jsx(ReactTable, { rowStyle: handleRowStyle, activeRow: handleActiveRow, data: data, columns: tableColumns, onClick: (e, data) => onChangeActiveSpectrum(e, data.original), enableVirtualScroll: true, approxItemHeight: 24, contextMenu: contextMenu, onContextMenuSelect: selectContextMenuHandler, onSortEnd: handleSortEnd, style: { 'table td': { paddingTop: 0, paddingBottom: 0 } } }), exportedSpectrum && (_jsx(ExportAsJcampModal, { spectrum: exportedSpectrum, closeDialog: () => {
225
267
  setExportedSpectrum(null);
@@ -1,8 +1,7 @@
1
- declare function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks, correlations, spectraData, onEdit, }: {
1
+ declare function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks, spectraData, onEdit, }: {
2
2
  rowCorrelation: any;
3
3
  columnCorrelation: any;
4
4
  commonLinks: any;
5
- correlations: any;
6
5
  spectraData: any;
7
6
  onEdit: any;
8
7
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,18 +1,24 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { v4 } from '@lukeed/uuid';
3
3
  import { buildLink } from 'nmr-correlation';
4
- import { useCallback, useMemo, useRef } from 'react';
4
+ import { useCallback, useMemo } from 'react';
5
5
  import { buildID } from '../../../../data/utilities/Concatenation';
6
6
  import { findRangeOrZoneID } from '../../../../data/utilities/FindUtilities';
7
- import ContextMenu from '../../../elements/ContextMenu';
8
- import { positions, useModal } from '../../../elements/popup/Modal';
7
+ import { ContextMenu } from '../../../elements/ContextMenuBluePrint';
8
+ import { useDialog } from '../../../elements/DialogManager';
9
9
  import { useHighlight } from '../../../highlight';
10
10
  import { cloneCorrelationAndEditLink, getAbbreviation, } from '../utilities/Utilities';
11
11
  import useInView from '../utilities/useInView';
12
- import EditLinkModal from './editLink/EditLinkModal';
13
- function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks, correlations, spectraData, onEdit, }) {
14
- const contextRef = useRef();
15
- const modal = useModal();
12
+ import { EditLinkModal } from './editLink/EditLinkModal';
13
+ function getLinkText(link) {
14
+ const { signal: { x, y }, edited, } = link;
15
+ const deltaX = x?.delta?.toFixed(2) ?? '?';
16
+ const deltaY = y?.delta?.toFixed(2) ?? '?';
17
+ const movedLabel = edited?.moved ? '[MOVED]' : '';
18
+ return `${getAbbreviation(link)} (${deltaX} , ${deltaY}) ${movedLabel}`;
19
+ }
20
+ function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks, spectraData, onEdit, }) {
21
+ const { openDialog } = useDialog();
16
22
  const highlightIDsCommonLinks = useMemo(() => {
17
23
  return commonLinks.flatMap((link) => {
18
24
  const ids = [];
@@ -35,10 +41,10 @@ function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks,
35
41
  event.currentTarget.blur();
36
42
  highlightCommonLinks.hide();
37
43
  }, [highlightCommonLinks]);
38
- const contextMenuHandler = useCallback((e) => {
39
- e.preventDefault();
40
- contextRef.current.handleContextMenu(e);
41
- }, [contextRef]);
44
+ function contextMenuHandler(data) {
45
+ highlightCommonLinks.hide();
46
+ openDialog(EditLinkModal, data);
47
+ }
42
48
  const handleEditPseudoHSQC = useCallback((action, link) => {
43
49
  const pseudoLinkCountHSQC = rowCorrelation.link.filter((_link) => (_link.experimentType === 'hsqc' ||
44
50
  _link.experimentType === 'hmqc') &&
@@ -77,21 +83,20 @@ function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks,
77
83
  const contextMenu = useMemo(() => {
78
84
  // allow the edition of correlations
79
85
  const commonLinksMenu = commonLinks.flatMap((commonLink) => {
80
- const commonLinkContextMenuLabel = `${getAbbreviation(commonLink)} (${commonLink.signal.x?.delta ? commonLink.signal.x.delta.toFixed(2) : '?'}, ${commonLink.signal.y?.delta ? commonLink.signal.y.delta.toFixed(2) : '?'})${commonLink.edited?.moved === true ? '[MOVED]' : ''}`;
81
- return commonLink.pseudo === false
82
- ? [
83
- {
84
- label: `edit ${commonLinkContextMenuLabel}`,
85
- onClick: () => {
86
- highlightCommonLinks.hide();
87
- modal.show(_jsx(EditLinkModal, { onClose: () => modal.close(), onEdit: onEdit, link: commonLink, correlationDim1: columnCorrelation, correlationDim2: rowCorrelation, correlations: correlations }), {
88
- position: positions.MIDDLE_RIGHT,
89
- isBackgroundBlur: false,
90
- });
91
- },
86
+ if (commonLink.pseudo !== false) {
87
+ return [];
88
+ }
89
+ return [
90
+ {
91
+ text: `Edit ${getLinkText(commonLink)}`,
92
+ icon: 'edit',
93
+ data: {
94
+ link: commonLink,
95
+ correlationDim1: columnCorrelation,
96
+ correlationDim2: rowCorrelation,
92
97
  },
93
- ]
94
- : [];
98
+ },
99
+ ];
95
100
  });
96
101
  // allow addition or removal of a pseudo HSQC link between pseudo heavy atom and proton
97
102
  const commonPseudoLinkHSQC = commonLinks.find((commonLink) => commonLink.pseudo === true && commonLink.experimentType === 'hsqc');
@@ -110,16 +115,7 @@ function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks,
110
115
  }
111
116
  }
112
117
  return commonLinksMenu;
113
- }, [
114
- columnCorrelation,
115
- commonLinks,
116
- correlations,
117
- handleEditPseudoHSQC,
118
- highlightCommonLinks,
119
- modal,
120
- onEdit,
121
- rowCorrelation,
122
- ]);
118
+ }, [columnCorrelation, commonLinks, handleEditPseudoHSQC, rowCorrelation]);
123
119
  const contentLabel = useMemo(() => commonLinks.map((commonLink, i) => (_jsxs("label", { children: [_jsx("label", { style: {
124
120
  color: commonLink.pseudo === true || commonLink.edited?.moved === true
125
121
  ? 'blue'
@@ -127,17 +123,13 @@ function AdditionalColumnField({ rowCorrelation, columnCorrelation, commonLinks,
127
123
  }, children: getAbbreviation(commonLink) }), i < commonLinks.length - 1 && _jsx("label", { children: "/" })] }, commonLink.id))), [commonLinks]);
128
124
  const isInViewRow = useInView({ correlation: rowCorrelation });
129
125
  const isInViewColumn = useInView({ correlation: columnCorrelation });
130
- return (_jsxs("td", { onContextMenu: (e) => {
131
- if (contextMenu.length > 0) {
132
- contextMenuHandler(e);
133
- }
134
- }, style: {
126
+ return (_jsx(ContextMenu, { as: "td", options: contextMenu, onSelect: contextMenuHandler, style: {
135
127
  backgroundColor: highlightCommonLinks.isActive
136
128
  ? '#ff6f0057'
137
129
  : isInViewColumn || isInViewRow
138
130
  ? '#f5f5dc'
139
131
  : 'inherit',
140
- }, title: getTitle(commonLinks), onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, children: [contentLabel, _jsx(ContextMenu, { ref: contextRef, context: contextMenu })] }));
132
+ }, title: getTitle(commonLinks), onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, children: contentLabel }));
141
133
  }
142
134
  function getTitle(commonLinks) {
143
135
  if (commonLinks?.length === 0) {
@@ -1,18 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { getCorrelationDelta, getLinkDim } from 'nmr-correlation';
4
- import { useCallback, useMemo, useRef } from 'react';
4
+ import { useCallback, useMemo } from 'react';
5
5
  import { buildID } from '../../../../data/utilities/Concatenation';
6
6
  import { findRangeOrZoneID } from '../../../../data/utilities/FindUtilities';
7
- import ContextMenu from '../../../elements/ContextMenu';
8
- import { positions, useModal } from '../../../elements/popup/Modal';
7
+ import { useAlert } from '../../../elements/Alert';
8
+ import { ContextMenu, } from '../../../elements/ContextMenuBluePrint';
9
+ import { useDialog } from '../../../elements/DialogManager';
9
10
  import { useHighlight } from '../../../highlight';
10
11
  import { getLabelColor } from '../utilities/Utilities';
11
12
  import useInView from '../utilities/useInView';
12
- import EditLinkModal from './editLink/EditLinkModal';
13
+ import { EditLinkModal } from './editLink/EditLinkModal';
13
14
  function AdditionalColumnHeader({ spectraData, correlationsData, correlation, onEdit, }) {
14
- const contextRef = useRef();
15
- const modal = useModal();
15
+ const alert = useAlert();
16
+ const { openDialog } = useDialog();
16
17
  const highlightIDsAdditionalColumn = useMemo(() => {
17
18
  if (correlation.pseudo === true) {
18
19
  return [];
@@ -83,59 +84,73 @@ function AdditionalColumnHeader({ spectraData, correlationsData, correlation, on
83
84
  };
84
85
  }, [correlation]);
85
86
  const contextMenu = useMemo(() => {
86
- return correlation.pseudo === false
87
- ? correlation.link
88
- .filter((link) => getLinkDim(link) === 1 && link.pseudo === false)
89
- .map((link) => {
90
- return {
91
- label: `edit 1D (${link.signal.delta.toFixed(3)}${link.edited?.moved === true ? '[MOVED]' : ''})`,
92
- onClick: () => {
93
- highlightAdditionalColumn.hide();
94
- modal.show(_jsx(EditLinkModal, { onClose: () => modal.close(), onEdit: onEdit, link: link, correlationDim1: correlation, correlationDim2: undefined, correlations: correlationsData.values }), { position: positions.MIDDLE_RIGHT, isBackgroundBlur: false });
87
+ if (correlation.pseudo !== false) {
88
+ return [];
89
+ }
90
+ const contextMenus = [
91
+ {
92
+ text: `Delete all (${correlation.label.origin})`,
93
+ icon: 'trash',
94
+ data: { action: 'removeAll' },
95
+ },
96
+ ];
97
+ for (const link of correlation.link) {
98
+ const isValidLink = getLinkDim(link) === 1 && link.pseudo === false;
99
+ if (isValidLink) {
100
+ const contextMenu = {
101
+ text: `Edit 1D (${link.signal.delta.toFixed(3)}${link.edited?.moved === true ? '[MOVED]' : ''})`,
102
+ icon: 'edit',
103
+ data: {
104
+ action: 'edit',
105
+ data: {
106
+ link,
107
+ correlationDim1: correlation,
108
+ correlationDim2: null,
109
+ },
95
110
  },
96
111
  };
97
- })
98
- .concat([
112
+ contextMenus.push(contextMenu);
113
+ }
114
+ }
115
+ return contextMenus;
116
+ }, [correlation]);
117
+ function removeAllLinks() {
118
+ alert.showAlert({
119
+ message: `All signals of ${correlation.label.origin} (${getCorrelationDelta(correlation).toFixed(2)}) will be deleted. Are you sure?`,
120
+ buttons: [
99
121
  {
100
- label: `delete all (${correlation.label.origin})`,
122
+ text: 'Yes',
101
123
  onClick: () => {
102
- modal.showConfirmDialog({
103
- message: `All signals of ${correlation.label.origin} (${getCorrelationDelta(correlation).toFixed(2)}) will be deleted. Are you sure?`,
104
- buttons: [
105
- {
106
- text: 'Yes',
107
- handler: () => {
108
- onEdit([correlation], 'removeAll');
109
- },
110
- },
111
- { text: 'No' },
112
- ],
113
- });
114
- highlightAdditionalColumn.hide();
124
+ onEdit([correlation], 'removeAll');
115
125
  },
126
+ intent: 'danger',
116
127
  },
117
- ])
118
- : [];
119
- }, [
120
- correlation,
121
- correlationsData.values,
122
- highlightAdditionalColumn,
123
- modal,
124
- onEdit,
125
- ]);
126
- const contextMenuHandler = useCallback((e) => {
127
- e.preventDefault();
128
- contextRef.current.handleContextMenu(e);
129
- }, [contextRef]);
128
+ { text: 'No' },
129
+ ],
130
+ });
131
+ highlightAdditionalColumn.hide();
132
+ }
133
+ function contextMenuHandler(selectedItem) {
134
+ const { action, data } = selectedItem;
135
+ switch (action) {
136
+ case 'removeAll': {
137
+ removeAllLinks();
138
+ break;
139
+ }
140
+ case 'edit': {
141
+ highlightAdditionalColumn.hide();
142
+ openDialog(EditLinkModal, data);
143
+ break;
144
+ }
145
+ default:
146
+ break;
147
+ }
148
+ }
130
149
  const { title, ...thProps } = tableHeaderProps;
131
- return (_jsx("th", { ...thProps, title: title === false ? undefined : title, children: _jsxs("div", { style: { display: 'block' }, onContextMenu: (e) => {
132
- if (contextMenu.length > 0) {
133
- contextMenuHandler(e);
134
- }
135
- }, children: [_jsx("p", { children: correlation.label.origin }), _jsx("p", { children: getCorrelationDelta(correlation)
136
- ? getCorrelationDelta(correlation)?.toFixed(2)
137
- : '' }), _jsx("p", { style: equivalenceTextStyle, children: Number.isInteger(correlation.equivalence)
138
- ? correlation.equivalence
139
- : correlation.equivalence.toFixed(2) }), _jsx(ContextMenu, { ref: contextRef, context: contextMenu })] }) }));
150
+ return (_jsxs(ContextMenu, { onSelect: (selected) => contextMenuHandler(selected), options: contextMenu, as: "th", ...thProps, title: title === false ? undefined : title, children: [_jsx("p", { children: correlation.label.origin }), _jsx("p", { children: getCorrelationDelta(correlation)
151
+ ? getCorrelationDelta(correlation)?.toFixed(2)
152
+ : '' }), _jsx("p", { style: equivalenceTextStyle, children: Number.isInteger(correlation.equivalence)
153
+ ? correlation.equivalence
154
+ : correlation.equivalence.toFixed(2) })] }));
140
155
  }
141
156
  export default AdditionalColumnHeader;