nmrium 0.24.0 → 0.26.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 (220) hide show
  1. package/lib/component/1d/IntegralResizable.js +13 -13
  2. package/lib/component/1d/multiAnalysis/AnalysisRange.js +30 -31
  3. package/lib/component/1d/multiplicityTree/MultiplicityTree.js +5 -5
  4. package/lib/component/1d/ranges/Range.js +24 -33
  5. package/lib/component/2d/zones/Signal.js +8 -8
  6. package/lib/component/2d/zones/Zone.js +3 -3
  7. package/lib/component/EventsTrackers/KeysListenerTracker.js +1 -1
  8. package/lib/component/NMRium.js +22 -29
  9. package/lib/component/assignment/AssignmentsContext.d.ts +35 -0
  10. package/lib/component/assignment/AssignmentsContext.js +83 -0
  11. package/lib/component/assignment/AssignmentsReducer.d.ts +32 -0
  12. package/lib/component/assignment/AssignmentsReducer.js +39 -0
  13. package/lib/component/assignment/actions/initAssignment.d.ts +5 -0
  14. package/lib/component/assignment/actions/initAssignment.js +62 -0
  15. package/lib/component/assignment/actions/removeAssignment.d.ts +16 -0
  16. package/lib/component/assignment/actions/removeAssignment.js +24 -0
  17. package/lib/component/assignment/actions/setActiveAssignment.d.ts +10 -0
  18. package/lib/component/assignment/actions/setActiveAssignment.js +8 -0
  19. package/lib/component/assignment/actions/toggleAssignment.d.ts +7 -0
  20. package/lib/component/assignment/actions/toggleAssignment.js +44 -0
  21. package/lib/component/assignment/index.d.ts +0 -18
  22. package/lib/component/assignment/index.js +12 -266
  23. package/lib/component/assignment/utilities/filterForIDsWithAssignment.d.ts +2 -0
  24. package/lib/component/assignment/utilities/filterForIDsWithAssignment.js +3 -0
  25. package/lib/component/context/GlobalContext.d.ts +12 -3
  26. package/lib/component/context/GlobalContext.js +1 -1
  27. package/lib/component/elements/ActionButtons.d.ts +10 -0
  28. package/lib/component/elements/ActionButtons.js +14 -0
  29. package/lib/component/elements/Button.d.ts +30 -5
  30. package/lib/component/elements/Button.js +151 -4
  31. package/lib/component/elements/ContextMenu.js +6 -6
  32. package/lib/component/elements/ReactTable/Elements/ReactTableRow.d.ts +5 -1
  33. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +38 -10
  34. package/lib/component/elements/ReactTable/ReactTable.d.ts +3 -1
  35. package/lib/component/elements/ReactTable/ReactTable.js +7 -2
  36. package/lib/component/elements/ReactTable/Style.d.ts +1 -3
  37. package/lib/component/elements/ReactTable/Style.js +1 -7
  38. package/lib/component/elements/ToolTip/ToolTip.js +3 -2
  39. package/lib/component/elements/resizer/DivResizer.d.ts +2 -0
  40. package/lib/component/elements/resizer/DivResizer.js +107 -0
  41. package/lib/component/elements/resizer/Resizer.d.ts +18 -0
  42. package/lib/component/elements/resizer/Resizer.js +12 -0
  43. package/lib/component/elements/resizer/SVGResizer.d.ts +2 -0
  44. package/lib/component/elements/resizer/SVGResizer.js +71 -0
  45. package/lib/component/elements/resizer/useDraggable.d.ts +19 -0
  46. package/lib/component/elements/resizer/useDraggable.js +52 -0
  47. package/lib/component/header/AutoPeakPickingOptionPanel.js +4 -15
  48. package/lib/component/header/BaseLineCorrectionPanel.js +2 -9
  49. package/lib/component/header/ManualPhaseCorrectionPanel.js +2 -9
  50. package/lib/component/header/RangesPickingOptionPanel.js +3 -16
  51. package/lib/component/header/ZeroFillingOptionsPanel.js +2 -9
  52. package/lib/component/header/Zones2DOptionPanel.js +3 -14
  53. package/lib/component/hooks/useExport.js +11 -9
  54. package/lib/component/loader/DropZone.js +1 -0
  55. package/lib/component/modal/AlignSpectraModal.js +2 -1
  56. package/lib/component/modal/ExportAsMatrixModal.js +2 -1
  57. package/lib/component/modal/ImportPublicationStringModal.js +2 -1
  58. package/lib/component/modal/LoadJCAMPModal.js +7 -6
  59. package/lib/component/modal/ModalStyle.js +4 -26
  60. package/lib/component/modal/MoleculeStructureEditorModal.js +2 -1
  61. package/lib/component/modal/MultipleSpectraFiltersModal/index.js +2 -1
  62. package/lib/component/modal/PredictSpectraModal.js +2 -7
  63. package/lib/component/modal/SaveAsModal.d.ts +1 -1
  64. package/lib/component/modal/SaveAsModal.js +2 -1
  65. package/lib/component/modal/setting/FormattingTabContent.js +17 -11
  66. package/lib/component/modal/setting/GeneralSettings.js +3 -1
  67. package/lib/component/modal/setting/settingsValidation.d.ts +8 -0
  68. package/lib/component/modal/setting/settingsValidation.js +40 -0
  69. package/lib/component/panels/AutomaticAssignment/AutomaticAssignment.js +6 -4
  70. package/lib/component/panels/AutomaticAssignment/AutomaticAssignmentTable.d.ts +4 -3
  71. package/lib/component/panels/AutomaticAssignment/AutomaticAssignmentTable.js +13 -6
  72. package/lib/component/panels/AutomaticAssignment/useAutoAssignments.d.ts +10 -0
  73. package/lib/component/panels/AutomaticAssignment/useAutoAssignments.js +60 -0
  74. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +11 -5
  75. package/lib/component/panels/MoleculesPanel/Utilities.d.ts +20 -11
  76. package/lib/component/panels/MoleculesPanel/Utilities.js +50 -68
  77. package/lib/component/panels/MoleculesPanel/useAtomAssignment.d.ts +2 -2
  78. package/lib/component/panels/MoleculesPanel/useAtomAssignment.js +55 -60
  79. package/lib/component/panels/RangesPanel/RangesHeader.js +2 -2
  80. package/lib/component/panels/RangesPanel/RangesPanel.js +1 -1
  81. package/lib/component/panels/RangesPanel/RangesTableRow.js +12 -11
  82. package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.d.ts +16 -9
  83. package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.js +2 -2
  84. package/lib/component/panels/RangesPanel/TableColumns/SignalAssignmentsColumn.d.ts +2 -3
  85. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +1 -1
  86. package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +5 -18
  87. package/lib/component/panels/SummaryPanel/SummaryPanel.js +1 -1
  88. package/lib/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +1 -1
  89. package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.d.ts +5 -7
  90. package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.js +2 -2
  91. package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.d.ts +4 -8
  92. package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.js +1 -1
  93. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.d.ts +5 -9
  94. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.js +4 -4
  95. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumns.d.ts +4 -8
  96. package/lib/component/panels/ZonesPanel/ZonesPanel.js +1 -1
  97. package/lib/component/panels/ZonesPanel/ZonesTableRow.d.ts +2 -1
  98. package/lib/component/panels/ZonesPanel/ZonesTableRow.js +20 -20
  99. package/lib/component/panels/header/SpectraAutomaticPickingButton.d.ts +2 -0
  100. package/lib/component/panels/header/SpectraAutomaticPickingButton.js +30 -0
  101. package/lib/component/panels/predictionPanel/PredictionOptions.js +2 -18
  102. package/lib/component/reducer/Reducer.d.ts +2 -0
  103. package/lib/component/reducer/Reducer.js +4 -1
  104. package/lib/component/reducer/actions/AssignmentsActions.d.ts +9 -0
  105. package/lib/component/reducer/actions/AssignmentsActions.js +18 -0
  106. package/lib/component/reducer/actions/LoadActions.d.ts +1 -1
  107. package/lib/component/reducer/actions/LoadActions.js +10 -5
  108. package/lib/component/reducer/preferencesReducer.d.ts +1 -8
  109. package/lib/component/reducer/preferencesReducer.js +16 -16
  110. package/lib/component/reducer/types/Types.d.ts +1 -0
  111. package/lib/component/reducer/types/Types.js +1 -0
  112. package/lib/component/utility/Export.d.ts +3 -3
  113. package/lib/component/utility/Export.js +10 -9
  114. package/lib/component/utility/FormatNumber.js +1 -1
  115. package/lib/component/workspaces/Workspace.d.ts +2 -4
  116. package/lib/component/workspaces/basic.js +8 -9
  117. package/lib/data/SpectraManager.js +23 -15
  118. package/lib/data/data1d/Data1DManager.d.ts +1 -1
  119. package/lib/data/data1d/Data1DManager.js +2 -1
  120. package/lib/data/data1d/Spectrum1D/toJSON.d.ts +2 -0
  121. package/lib/data/data1d/Spectrum1D/toJSON.js +1 -0
  122. package/lib/data/data1d/database.d.ts +1 -2
  123. package/lib/data/data1d/database.js +1 -1
  124. package/lib/data/data1d/filter1d/exclusionZones.d.ts +1 -4
  125. package/lib/data/data2d/Data2DManager.d.ts +1 -1
  126. package/lib/data/data2d/Data2DManager.js +2 -1
  127. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js +1 -1
  128. package/lib/data/data2d/Spectrum2D/toJSON.d.ts +2 -0
  129. package/lib/data/data2d/Spectrum2D/toJSON.js +1 -0
  130. package/lib/data/types/common/Source.d.ts +1 -0
  131. package/lib/data/types/data2d/Signal2DAxisData.d.ts +1 -1
  132. package/lib/versionInfo.js +1 -1
  133. package/lib-cjs/component/1d/IntegralResizable.js +12 -12
  134. package/lib-cjs/component/1d/multiAnalysis/AnalysisRange.js +29 -30
  135. package/lib-cjs/component/1d/multiplicityTree/MultiplicityTree.js +6 -6
  136. package/lib-cjs/component/1d/ranges/Range.js +26 -35
  137. package/lib-cjs/component/2d/zones/Signal.js +9 -9
  138. package/lib-cjs/component/2d/zones/Zone.js +4 -4
  139. package/lib-cjs/component/EventsTrackers/KeysListenerTracker.js +2 -2
  140. package/lib-cjs/component/NMRium.js +22 -29
  141. package/lib-cjs/component/assignment/AssignmentsContext.js +88 -0
  142. package/lib-cjs/component/assignment/AssignmentsReducer.js +45 -0
  143. package/lib-cjs/component/assignment/actions/initAssignment.js +65 -0
  144. package/lib-cjs/component/assignment/actions/removeAssignment.js +29 -0
  145. package/lib-cjs/component/assignment/actions/setActiveAssignment.js +11 -0
  146. package/lib-cjs/component/assignment/actions/toggleAssignment.js +47 -0
  147. package/lib-cjs/component/assignment/index.js +15 -269
  148. package/lib-cjs/component/assignment/utilities/filterForIDsWithAssignment.js +7 -0
  149. package/lib-cjs/component/context/GlobalContext.js +1 -1
  150. package/lib-cjs/component/elements/ActionButtons.js +20 -0
  151. package/lib-cjs/component/elements/Button.js +150 -4
  152. package/lib-cjs/component/elements/ContextMenu.js +6 -6
  153. package/lib-cjs/component/elements/ReactTable/Elements/ReactTableRow.js +42 -14
  154. package/lib-cjs/component/elements/ReactTable/ReactTable.js +7 -2
  155. package/lib-cjs/component/elements/ReactTable/Style.js +1 -9
  156. package/lib-cjs/component/elements/ToolTip/ToolTip.js +3 -2
  157. package/lib-cjs/component/elements/resizer/DivResizer.js +113 -0
  158. package/lib-cjs/component/elements/resizer/Resizer.js +18 -0
  159. package/lib-cjs/component/elements/resizer/SVGResizer.js +77 -0
  160. package/lib-cjs/component/elements/resizer/useDraggable.js +55 -0
  161. package/lib-cjs/component/header/AutoPeakPickingOptionPanel.js +3 -14
  162. package/lib-cjs/component/header/BaseLineCorrectionPanel.js +2 -9
  163. package/lib-cjs/component/header/ManualPhaseCorrectionPanel.js +2 -9
  164. package/lib-cjs/component/header/RangesPickingOptionPanel.js +2 -15
  165. package/lib-cjs/component/header/ZeroFillingOptionsPanel.js +2 -9
  166. package/lib-cjs/component/header/Zones2DOptionPanel.js +2 -13
  167. package/lib-cjs/component/hooks/useExport.js +11 -9
  168. package/lib-cjs/component/loader/DropZone.js +1 -0
  169. package/lib-cjs/component/modal/AlignSpectraModal.js +2 -1
  170. package/lib-cjs/component/modal/ExportAsMatrixModal.js +2 -1
  171. package/lib-cjs/component/modal/ImportPublicationStringModal.js +2 -1
  172. package/lib-cjs/component/modal/LoadJCAMPModal.js +7 -6
  173. package/lib-cjs/component/modal/ModalStyle.js +4 -26
  174. package/lib-cjs/component/modal/MoleculeStructureEditorModal.js +5 -1
  175. package/lib-cjs/component/modal/MultipleSpectraFiltersModal/index.js +2 -1
  176. package/lib-cjs/component/modal/PredictSpectraModal.js +2 -7
  177. package/lib-cjs/component/modal/SaveAsModal.js +2 -1
  178. package/lib-cjs/component/modal/setting/FormattingTabContent.js +17 -11
  179. package/lib-cjs/component/modal/setting/GeneralSettings.js +3 -1
  180. package/lib-cjs/component/modal/setting/settingsValidation.js +66 -0
  181. package/lib-cjs/component/panels/AutomaticAssignment/AutomaticAssignment.js +6 -4
  182. package/lib-cjs/component/panels/AutomaticAssignment/AutomaticAssignmentTable.js +13 -6
  183. package/lib-cjs/component/panels/AutomaticAssignment/useAutoAssignments.js +67 -0
  184. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +12 -6
  185. package/lib-cjs/component/panels/MoleculesPanel/Utilities.js +50 -68
  186. package/lib-cjs/component/panels/MoleculesPanel/useAtomAssignment.js +55 -60
  187. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +3 -3
  188. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +2 -2
  189. package/lib-cjs/component/panels/RangesPanel/RangesTableRow.js +15 -14
  190. package/lib-cjs/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.js +2 -2
  191. package/lib-cjs/component/panels/RangesPanel/hooks/useEditRangeModal.js +2 -2
  192. package/lib-cjs/component/panels/SpectrumsPanel/SpectraPanelHeader.js +3 -16
  193. package/lib-cjs/component/panels/SummaryPanel/SummaryPanel.js +2 -2
  194. package/lib-cjs/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +2 -2
  195. package/lib-cjs/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.js +2 -2
  196. package/lib-cjs/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.js +1 -1
  197. package/lib-cjs/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.js +4 -4
  198. package/lib-cjs/component/panels/ZonesPanel/ZonesPanel.js +2 -2
  199. package/lib-cjs/component/panels/ZonesPanel/ZonesTableRow.js +21 -21
  200. package/lib-cjs/component/panels/header/SpectraAutomaticPickingButton.js +37 -0
  201. package/lib-cjs/component/panels/predictionPanel/PredictionOptions.js +2 -18
  202. package/lib-cjs/component/reducer/Reducer.js +4 -1
  203. package/lib-cjs/component/reducer/actions/AssignmentsActions.js +21 -0
  204. package/lib-cjs/component/reducer/actions/LoadActions.js +9 -4
  205. package/lib-cjs/component/reducer/preferencesReducer.js +16 -16
  206. package/lib-cjs/component/reducer/types/Types.js +2 -1
  207. package/lib-cjs/component/utility/Export.js +10 -9
  208. package/lib-cjs/component/utility/FormatNumber.js +1 -1
  209. package/lib-cjs/component/workspaces/basic.js +8 -9
  210. package/lib-cjs/data/SpectraManager.js +23 -15
  211. package/lib-cjs/data/data1d/Data1DManager.js +2 -1
  212. package/lib-cjs/data/data1d/Spectrum1D/toJSON.js +1 -0
  213. package/lib-cjs/data/data2d/Data2DManager.js +2 -1
  214. package/lib-cjs/data/data2d/Spectrum2D/initiateDatum2D.js +1 -1
  215. package/lib-cjs/data/data2d/Spectrum2D/toJSON.js +1 -0
  216. package/lib-cjs/versionInfo.js +1 -1
  217. package/package.json +25 -26
  218. package/lib/component/1d/Resizable.d.ts +0 -12
  219. package/lib/component/1d/Resizable.js +0 -105
  220. package/lib-cjs/component/1d/Resizable.js +0 -110
@@ -1,13 +1,13 @@
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 { useCallback, useState, useEffect } from 'react';
4
+ import { useCallback } from 'react';
5
5
  import { useChartData } from '../context/ChartContext';
6
6
  import { useDispatch } from '../context/DispatchContext';
7
7
  import { useScaleChecked } from '../context/ScaleContext';
8
+ import Resizer from '../elements/resizer/Resizer';
8
9
  import { HighlightedSource, useHighlight } from '../highlight/index';
9
10
  import { RESIZE_INTEGRAL } from '../reducer/types/Types';
10
- import Resizable from './Resizable';
11
11
  const stylesOnHover = css `
12
12
  pointer-events: bounding-box;
13
13
  @-moz-document url-prefix() {
@@ -36,31 +36,31 @@ function IntegralResizable({ integralData }) {
36
36
  const { height, margin } = useChartData();
37
37
  const { scaleX } = useScaleChecked();
38
38
  const dispatch = useDispatch();
39
- const [{ id, integral, from, to }, setIntegral] = useState(integralData);
39
+ const { id, from, to, integral } = integralData;
40
40
  const highlight = useHighlight([id], {
41
41
  type: HighlightedSource.INTEGRAL,
42
42
  extra: { id },
43
43
  });
44
- useEffect(() => {
45
- setIntegral(integralData);
46
- }, [integralData]);
47
- const handleOnStopResizing = useCallback((resized) => {
44
+ const handleOnStopResizing = useCallback((position) => {
48
45
  dispatch({
49
46
  type: RESIZE_INTEGRAL,
50
- payload: { data: { ...integralData, ...resized } },
47
+ payload: {
48
+ data: {
49
+ ...integralData,
50
+ from: scaleX().invert(position.x2),
51
+ to: scaleX().invert(position.x1),
52
+ },
53
+ },
51
54
  });
52
- }, [dispatch, integralData]);
55
+ }, [dispatch, integralData, scaleX]);
53
56
  const handleOnEnterNotation = useCallback(() => {
54
57
  highlight.show();
55
58
  }, [highlight]);
56
59
  const handleOnMouseLeaveNotation = useCallback(() => {
57
60
  highlight.hide();
58
61
  }, [highlight]);
59
- const dragHandler = useCallback((boundary) => {
60
- setIntegral((integral) => ({ ...integral, ...boundary }));
61
- }, []);
62
62
  const x0 = from ? scaleX()(from) : 0;
63
63
  const x1 = to ? scaleX()(to) : 0;
64
- return (_jsxs("g", { css: highlight.isActive ? stylesHighlighted : stylesOnHover, onMouseEnter: handleOnEnterNotation, onMouseLeave: handleOnMouseLeaveNotation, children: [_jsx("rect", { "data-no-export": "true", x: `${x1}`, y: "0", width: `${x0 - x1}`, height: height - margin.bottom, className: "highlight" }), _jsx("text", { x: x1, y: height - margin.bottom + 30, fill: "black", style: { fontSize: '12px', fontWeight: 'bold' }, children: integral !== undefined ? integral.toFixed(2) : '' }), _jsx(Resizable, { from: integralData.from, to: integralData.to, onDrag: dragHandler, onDrop: handleOnStopResizing, "data-no-export": "true" })] }));
64
+ return (_jsx("g", { css: highlight.isActive ? stylesHighlighted : stylesOnHover, onMouseEnter: handleOnEnterNotation, onMouseLeave: handleOnMouseLeaveNotation, children: _jsx(Resizer, { tag: "svg", initialPosition: { x1: x1, x2: x0 }, onEnd: handleOnStopResizing, children: (x1, x2) => (_jsxs("g", { children: [_jsx("rect", { x: "0", y: "0", width: x2 - x1, height: height - margin.bottom, className: "highlight", "data-no-export": "true" }), _jsx("text", { x: 0, y: height - margin.bottom + 30, fill: "black", style: { fontSize: '12px', fontWeight: 'bold' }, children: integral !== undefined ? integral.toFixed(2) : '' })] })) }) }));
65
65
  }
66
66
  export default IntegralResizable;
@@ -1,41 +1,37 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { css } from '@emotion/react';
4
4
  import { useCallback } from 'react';
5
5
  import { useDispatch } from '../../context/DispatchContext';
6
6
  import { useScaleChecked } from '../../context/ScaleContext';
7
7
  import DeleteButton from '../../elements/DeleteButton';
8
+ import Resizer from '../../elements/resizer/Resizer';
8
9
  import { useHighlight } from '../../highlight';
9
10
  import { DELETE_ANALYZE_SPECTRA_RANGE, RESIZE_ANALYZE_SPECTRA_RANGE, } from '../../reducer/types/Types';
10
- import Resizable from '../Resizable';
11
- const stylesOnHover = css `
12
- pointer-events: bounding-box;
13
- @-moz-document url-prefix() {
14
- pointer-events: fill;
15
- }
16
- user-select: 'none';
17
- -webkit-user-select: none; /* Chrome all / Safari all */
18
- -moz-user-select: none; /* Firefox all */
11
+ const styles = {
12
+ common: css `
13
+ pointer-events: bounding-box;
19
14
 
20
- .delete-button {
21
- visibility: hidden;
22
- }
23
- `;
24
- const stylesHighlighted = css `
25
- pointer-events: bounding-box;
26
-
27
- @-moz-document url-prefix() {
28
- pointer-events: fill;
29
- }
30
- .range-area {
31
- height: 100%;
32
- fill: #ff6f0057;
33
- }
34
- .delete-button {
35
- visibility: visible;
36
- cursor: pointer;
37
- }
38
- `;
15
+ @-moz-document url-prefix() {
16
+ pointer-events: fill;
17
+ }
18
+ `,
19
+ hover: css `
20
+ .delete-button {
21
+ visibility: hidden;
22
+ }
23
+ `,
24
+ Highlighted: css `
25
+ .range-area {
26
+ height: 100%;
27
+ fill: #ff6f0057;
28
+ }
29
+ .delete-button {
30
+ visibility: visible;
31
+ cursor: pointer;
32
+ }
33
+ `,
34
+ };
39
35
  function AnalysisRange({ rangeData, columnKey }) {
40
36
  const { from, to } = rangeData;
41
37
  const highlight = useHighlight([columnKey]);
@@ -44,12 +40,15 @@ function AnalysisRange({ rangeData, columnKey }) {
44
40
  const deleteHandler = useCallback(() => {
45
41
  dispatch({ type: DELETE_ANALYZE_SPECTRA_RANGE, colKey: columnKey });
46
42
  }, [columnKey, dispatch]);
47
- const handleOnStopResizing = useCallback((resized) => {
43
+ const resizeEndHandler = useCallback((resized) => {
48
44
  dispatch({
49
45
  type: RESIZE_ANALYZE_SPECTRA_RANGE,
50
46
  payload: { ...rangeData, ...resized, columnKey },
51
47
  });
52
48
  }, [columnKey, dispatch, rangeData]);
53
- return (_jsxs("g", { ...highlight.onHover, css: highlight.isActive ? stylesHighlighted : stylesOnHover, children: [_jsxs("g", { transform: `translate(${scaleX()(to)},25)`, children: [_jsx("rect", { x: "0", width: scaleX()(from) - scaleX()(to), height: "6", className: "range-area", fill: "green" }), _jsx("text", { textAnchor: "middle", x: (scaleX()(from) - scaleX()(to)) / 2, y: "-5", fontSize: "12", fill: "red", fontWeight: "bolder", fillOpacity: highlight.isActive ? 1 : 0.6, children: columnKey })] }), _jsx(Resizable, { from: rangeData.from, to: rangeData.to, onDrop: handleOnStopResizing }), _jsx(DeleteButton, { x: scaleX()(to) - 20, y: 10, onDelete: deleteHandler })] }));
49
+ return (_jsx("g", { ...highlight.onHover, css: [
50
+ styles.common,
51
+ highlight.isActive ? styles.Highlighted : styles.hover,
52
+ ], children: _jsx(Resizer, { tag: "svg", onEnd: resizeEndHandler, initialPosition: { x2: scaleX()(from), x1: scaleX()(to) }, children: (x1, x2) => (_jsxs(_Fragment, { children: [_jsxs("g", { transform: `translate(0,25)`, children: [_jsx("rect", { x: "0", width: x2 - x1, height: "6", className: "range-area", fill: "green" }), _jsx("text", { textAnchor: "middle", x: (x2 - x1) / 2, y: "-5", fontSize: "12", fill: "red", fontWeight: "bolder", fillOpacity: highlight.isActive ? 1 : 0.6, children: columnKey })] }), _jsx(DeleteButton, { x: -20, y: 10, onDelete: deleteHandler })] })) }) }));
54
53
  }
55
54
  export default AnalysisRange;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import lodashGet from 'lodash/get';
4
4
  import { useMemo, useState, useEffect } from 'react';
5
- import { useAssignment } from '../../assignment';
5
+ import { useAssignment } from '../../assignment/AssignmentsContext';
6
6
  import { useChartData } from '../../context/ChartContext';
7
7
  import { useScaleChecked } from '../../context/ScaleContext';
8
8
  import { HighlightedSource, useHighlight } from '../../highlight';
@@ -18,7 +18,7 @@ const styles = {
18
18
  strokeWidth: 1,
19
19
  };
20
20
  function extractID(assignment) {
21
- return [assignment.id].concat(assignment.assigned.x || []);
21
+ return [assignment.id].concat(assignment.assigned?.x || []);
22
22
  }
23
23
  function MultiplicityTree({ rangeFrom, rangeTo, signal, labelOptions = {
24
24
  distance: 10,
@@ -169,11 +169,11 @@ function MultiplicityTree({ rangeFrom, rangeTo, signal, labelOptions = {
169
169
  ? { ...styles, opacity: 1, strokeWidth: 1.5 }
170
170
  : styles, ...{
171
171
  onMouseEnter: () => {
172
- assignment.onMouseEnter('x');
172
+ assignment.show('x');
173
173
  highlight.show();
174
174
  },
175
175
  onMouseLeave: () => {
176
- assignment.onMouseLeave('x');
176
+ assignment.hide();
177
177
  highlight.hide();
178
178
  },
179
179
  }, ...{
@@ -184,7 +184,7 @@ function MultiplicityTree({ rangeFrom, rangeTo, signal, labelOptions = {
184
184
  : (e) => {
185
185
  if (e.shiftKey) {
186
186
  e.stopPropagation();
187
- assignment.onClick('x');
187
+ assignment.setActive('x');
188
188
  }
189
189
  },
190
190
  }, children: multiplicityTree }));
@@ -3,13 +3,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
3
3
  import { css } from '@emotion/react';
4
4
  import { useCallback, useState, useEffect } from 'react';
5
5
  import { checkRangeKind } from '../../../data/utilities/RangeUtilities';
6
- import { filterForIDsWithAssignment, useAssignment, useAssignmentData, } from '../../assignment';
6
+ import { useAssignment, useAssignmentData, } from '../../assignment/AssignmentsContext';
7
+ import { filterForIDsWithAssignment } from '../../assignment/utilities/filterForIDsWithAssignment';
7
8
  import { useDispatch } from '../../context/DispatchContext';
8
9
  import { useScaleChecked } from '../../context/ScaleContext';
10
+ import Resizer from '../../elements/resizer/Resizer';
9
11
  import { HighlightedSource, useHighlight } from '../../highlight';
10
12
  import { RESIZE_RANGE } from '../../reducer/types/Types';
11
13
  import { options } from '../../toolbar/ToolTypes';
12
- import Resizable from '../Resizable';
13
14
  import MultiplicityTree from '../multiplicityTree/MultiplicityTree';
14
15
  import TempMultiplicityTree from '../multiplicityTree/TempMultiplicityTree';
15
16
  const stylesOnHover = css `
@@ -41,24 +42,14 @@ const stylesHighlighted = css `
41
42
  }
42
43
  `;
43
44
  function Range({ rangeData, showMultiplicityTrees, selectedTool, startEditMode, }) {
44
- const { id, from: rangeFrom, to: rangeTo, integration, signals } = rangeData;
45
+ const { id, from, to, integration, signals } = rangeData;
45
46
  const assignmentData = useAssignmentData();
46
47
  const assignmentRange = useAssignment(id);
47
- const highlightRange = useHighlight([assignmentRange.id].concat(assignmentRange.assigned.x || []).concat(filterForIDsWithAssignment(assignmentData, signals.map((_signal) => _signal.id))), { type: HighlightedSource.RANGE, extra: { id } });
48
- const [rangeBoundary, setRangeBoundary] = useState({
49
- from: rangeFrom,
50
- to: rangeTo,
51
- });
48
+ const highlightRange = useHighlight([assignmentRange.id].concat(assignmentRange.assigned?.x || []).concat(filterForIDsWithAssignment(assignmentData, signals.map((_signal) => _signal.id))), { type: HighlightedSource.RANGE, extra: { id } });
52
49
  const { scaleX } = useScaleChecked();
53
50
  const dispatch = useDispatch();
54
51
  const [reduceOpacity, setReduceOpacity] = useState(false);
55
52
  const [isBlockedByEditing, setIsBlockedByEditing] = useState(false);
56
- useEffect(() => {
57
- setRangeBoundary({
58
- from: rangeFrom,
59
- to: rangeTo,
60
- });
61
- }, [rangeFrom, rangeTo]);
62
53
  useEffect(() => {
63
54
  if (selectedTool && selectedTool === options.editRange.id) {
64
55
  setIsBlockedByEditing(true);
@@ -70,44 +61,44 @@ function Range({ rangeData, showMultiplicityTrees, selectedTool, startEditMode,
70
61
  useEffect(() => {
71
62
  setReduceOpacity(!checkRangeKind(rangeData));
72
63
  }, [rangeData]);
73
- const handleOnStopResizing = useCallback((resized) => {
64
+ const handleOnStopResizing = useCallback((position) => {
74
65
  dispatch({
75
66
  type: RESIZE_RANGE,
76
- data: { ...rangeData, ...resized },
67
+ data: {
68
+ ...rangeData,
69
+ from: scaleX().invert(position.x2),
70
+ to: scaleX().invert(position.x1),
71
+ },
77
72
  });
78
- }, [dispatch, rangeData]);
73
+ }, [dispatch, rangeData, scaleX]);
79
74
  const mouseEnterHandler = useCallback(() => {
80
- assignmentRange.onMouseEnter('x');
75
+ assignmentRange.show('x');
81
76
  highlightRange.show();
82
77
  }, [assignmentRange, highlightRange]);
83
78
  const mouseLeaveHandler = useCallback(() => {
84
- assignmentRange.onMouseLeave('x');
79
+ assignmentRange.hide();
85
80
  highlightRange.hide();
86
81
  }, [assignmentRange, highlightRange]);
87
82
  const assignHandler = useCallback((e) => {
88
83
  if (selectedTool === options.rangesPicking.id &&
89
84
  e.shiftKey &&
90
85
  !isBlockedByEditing) {
91
- assignmentRange.onClick('x');
86
+ assignmentRange.setActive('x');
92
87
  }
93
88
  }, [assignmentRange, isBlockedByEditing, selectedTool]);
94
- const dragHandler = useCallback((boundary) => {
95
- setRangeBoundary((range) => ({ ...range, ...boundary }));
96
- }, []);
97
- const { from, to } = rangeBoundary;
98
89
  return (_jsxs("g", { "data-test-id": "range", style: { outline: 'none' }, css: isBlockedByEditing ||
99
90
  highlightRange.isActive ||
100
91
  assignmentRange.isActive
101
92
  ? stylesHighlighted
102
- : stylesOnHover, onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, onClick: assignHandler, children: [_jsxs("g", { transform: `translate(${scaleX()(to)},10)`, children: [_jsx("rect", { x: "0", width: Math.abs(scaleX()(from) - scaleX()(to)), height: "6", className: "range-area", fill: "green", fillOpacity: !reduceOpacity ||
103
- highlightRange.isActive ||
104
- assignmentRange.isActive
105
- ? 1
106
- : 0.4 }), _jsx("text", { textAnchor: "middle", x: Math.abs(scaleX()(from) - scaleX()(to)) / 2, y: "20", fontSize: "10", fill: "red", fillOpacity: !reduceOpacity ||
107
- highlightRange.isActive ||
108
- assignmentRange.isActive
109
- ? 1
110
- : 0.6, children: integration !== undefined ? integration.toFixed(2) : '' })] }), _jsx(Resizable, { from: rangeData.from, to: rangeData.to, onDrop: handleOnStopResizing, onDrag: dragHandler }), startEditMode ? (_jsx(TempMultiplicityTree, {})) : (showMultiplicityTrees &&
93
+ : stylesOnHover, onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, onClick: assignHandler, children: [_jsx(Resizer, { tag: "svg", initialPosition: { x1: scaleX()(to), x2: scaleX()(from) }, onEnd: handleOnStopResizing, children: (x1, x2) => (_jsxs("g", { transform: `translate(0,10)`, children: [_jsx("rect", { "data-no-export": "true", x: "0", width: x2 - x1, height: "6", className: "range-area", fill: "green", fillOpacity: !reduceOpacity ||
94
+ highlightRange.isActive ||
95
+ assignmentRange.isActive
96
+ ? 1
97
+ : 0.4 }), _jsx("text", { textAnchor: "middle", x: (x2 - x1) / 2, y: "20", fontSize: "10", fill: "red", fillOpacity: !reduceOpacity ||
98
+ highlightRange.isActive ||
99
+ assignmentRange.isActive
100
+ ? 1
101
+ : 0.6, children: integration !== undefined ? integration.toFixed(2) : '' })] })) }), startEditMode ? (_jsx(TempMultiplicityTree, {})) : (showMultiplicityTrees &&
111
102
  signals &&
112
103
  signals.length > 0 &&
113
104
  signals.map((_signal) => (_jsx(MultiplicityTree, { rangeFrom: from, rangeTo: to, signal: _signal }, _signal.id))))] }, id));
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { memo, useState, useEffect, useCallback } from 'react';
4
4
  import { buildID } from '../../../data/utilities/Concatenation';
5
- import { useAssignment } from '../../assignment';
5
+ import { useAssignment } from '../../assignment/AssignmentsContext';
6
6
  import { useChartData } from '../../context/ChartContext';
7
7
  import { useHighlightData, useHighlight } from '../../highlight';
8
8
  import { get2DXScale, get2DYScale } from '../utilities/scale';
@@ -34,13 +34,13 @@ const Signal = memo(({ signal, isVisible }) => {
34
34
  ]);
35
35
  if (!signal)
36
36
  return null;
37
- return (_jsxs("g", { className: "zone-signal", onMouseEnter: () => {
38
- assignment.onMouseEnter(undefined);
39
- highlight.show();
40
- }, onMouseLeave: () => {
41
- assignment.onMouseLeave(undefined);
42
- highlight.hide();
43
- }, children: [isVisible.signals && (_jsxs("g", { children: [_jsx("circle", { cx: scaleX(signal.x.delta || 0), cy: scaleY(signal.y.delta || 0), r: isHighlighted ? 6 : 4, fill: isHighlighted ? 'green' : 'darkgreen' }, signal.id), _jsx(SignalCrosshair, { signal: signal })] })), _jsx("g", { className: "zone-signal-peak", children: isVisible.peaks &&
37
+ return (_jsxs("g", { className: "zone-signal", children: [isVisible.signals && (_jsxs("g", { children: [_jsx(SignalCrosshair, { signal: signal }), _jsx("circle", { onMouseEnter: () => {
38
+ assignment.show();
39
+ highlight.show();
40
+ }, onMouseLeave: () => {
41
+ assignment.hide();
42
+ highlight.hide();
43
+ }, cx: scaleX(signal.x.delta || 0), cy: scaleY(signal.y.delta || 0), r: isHighlighted ? 6 : 4, fill: isHighlighted ? 'green' : 'darkgreen' }, signal.id)] })), _jsx("g", { className: "zone-signal-peak", style: { pointerEvents: 'none' }, children: isVisible.peaks &&
44
44
  signal.peaks &&
45
45
  signal.peaks.map((peak, i) => (_jsx("circle", { cx: scaleX(peak.x), cy: scaleY(peak.y), r: 2, fill: "black" }, `${signal.id + i}`))) })] }));
46
46
  });
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
3
3
  import { css } from '@emotion/react';
4
4
  import { useState, useEffect } from 'react';
5
5
  import { checkZoneKind } from '../../../data/utilities/ZoneUtilities';
6
- import { useAssignment } from '../../assignment';
6
+ import { useAssignment } from '../../assignment/AssignmentsContext';
7
7
  import { useChartData } from '../../context/ChartContext';
8
8
  import { HighlightedSource, useHighlight } from '../../highlight';
9
9
  import { get2DXScale, get2DYScale } from '../utilities/scale';
@@ -54,10 +54,10 @@ const Zone = ({ zoneData, isVisible }) => {
54
54
  return (_jsxs("g", { css: highlightZone.isActive || assignmentZone.isActive
55
55
  ? stylesHighlighted
56
56
  : stylesOnHover, onMouseEnter: () => {
57
- assignmentZone.onMouseEnter(undefined);
57
+ assignmentZone.show();
58
58
  highlightZone.show();
59
59
  }, onMouseLeave: () => {
60
- assignmentZone.onMouseLeave(undefined);
60
+ assignmentZone.hide();
61
61
  highlightZone.hide();
62
62
  }, children: [isVisible.zones && (_jsx("g", { transform: `translate(${scaleX(x2)},${scaleY(y1)})`, children: _jsx("rect", { x: "0", width: scaleX(x1) - scaleX(x2), height: scaleY(y2) - scaleY(y1), className: "Integral-area", fill: "#0000000f", stroke: reduceOpacity ? '#343a40' : 'darkgreen', strokeWidth: reduceOpacity ? '0' : '1' }) })), signals.map((_signal, i) => (_jsx(Signal, { signal: _signal, isVisible: isVisible }, `${id + i}`)))] }, id));
63
63
  };
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect, useMemo } from 'react';
2
2
  import checkModifierKeyActivated from '../../data/utilities/checkModifierKeyActivated';
3
- import { useAssignmentData } from '../assignment';
3
+ import { useAssignmentData } from '../assignment/AssignmentsContext';
4
4
  import { useChartData } from '../context/ChartContext';
5
5
  import { useDispatch } from '../context/DispatchContext';
6
6
  import { useLoader } from '../context/LoaderContext';
@@ -49,7 +49,6 @@ const containerStyles = css `
49
49
 
50
50
  button {
51
51
  cursor: pointer;
52
- color: black;
53
52
  &:disabled {
54
53
  cursor: default;
55
54
  }
@@ -76,25 +75,6 @@ const containerStyles = css `
76
75
  .SplitPane {
77
76
  height: 100%;
78
77
  }
79
-
80
- .Resizer.vertical:after {
81
- content: '\\22EE';
82
- top: 50%;
83
- color: black;
84
- position: absolute;
85
- font-size: 14px;
86
- }
87
-
88
- .Resizer.vertical {
89
- padding: 2px;
90
- }
91
-
92
- .Resizer.vertical:hover {
93
- background-color: #dfdfdf !important;
94
- border-left: 0.55px #bbbbbb;
95
- solid;
96
- border-right: 0.55px #bbbbbb solid;
97
- }
98
78
  `;
99
79
  const defaultPreferences = {};
100
80
  const defaultData = {
@@ -105,7 +85,7 @@ function NMRium(props) {
105
85
  }
106
86
  function InnerNMRium({ data: dataProp = defaultData, workspace, preferences = defaultPreferences, getSpinner = defaultGetSpinner, onDataChange, emptyText, }) {
107
87
  const rootRef = useRef(null);
108
- const elementsWraperRef = useRef(null);
88
+ const elementsWrapperRef = useRef(null);
109
89
  const [show, toggle] = useToggle(false);
110
90
  const isFullscreen = useFullscreen(rootRef, show, {
111
91
  onClose: () => {
@@ -147,16 +127,29 @@ function InnerNMRium({ data: dataProp = defaultData, workspace, preferences = de
147
127
  e.preventDefault();
148
128
  }
149
129
  }, []);
150
- const mouseEnterHandler = useCallback(() => {
151
- dispatchMiddleWare({ type: SET_MOUSE_OVER_DISPLAYER, payload: true });
152
- }, [dispatchMiddleWare]);
153
- const mouseLeaveHandler = useCallback(() => {
154
- dispatchMiddleWare({ type: SET_MOUSE_OVER_DISPLAYER, payload: false });
130
+ const mainDivRef = useRef(null);
131
+ useEffect(() => {
132
+ const div = mainDivRef.current;
133
+ if (!div) {
134
+ return;
135
+ }
136
+ function mouseEnterHandler() {
137
+ dispatchMiddleWare({ type: SET_MOUSE_OVER_DISPLAYER, payload: true });
138
+ }
139
+ function mouseLeaveHandler() {
140
+ dispatchMiddleWare({ type: SET_MOUSE_OVER_DISPLAYER, payload: false });
141
+ }
142
+ div.addEventListener('mouseenter', mouseEnterHandler);
143
+ div.addEventListener('mouseleave', mouseLeaveHandler);
144
+ return () => {
145
+ div.removeEventListener('mouseenter', mouseEnterHandler);
146
+ div.removeEventListener('mouseleave', mouseLeaveHandler);
147
+ };
155
148
  }, [dispatchMiddleWare]);
156
149
  return (_jsx(GlobalProvider, { value: {
157
150
  rootRef: rootRef.current,
158
- elementsWraperRef: elementsWraperRef.current,
159
- }, children: _jsx(PreferencesProvider, { value: preferencesState, children: _jsx("div", { onMouseEnter: mouseEnterHandler, onMouseLeave: mouseLeaveHandler, style: { height: '100%', position: 'relative' }, children: _jsx(AlertProvider, { wrapperRef: elementsWraperRef.current, children: _jsx(DispatchProvider, { value: dispatchMiddleWare, children: _jsx(ChartDataProvider, { value: state, children: _jsx(ModalProvider, { wrapperRef: elementsWraperRef.current, children: _jsx(HighlightProvider, { children: _jsx(AssignmentProvider, { spectraData: spectraData, children: _jsx(SpinnerProvider, { value: getSpinner, children: _jsx("div", { className: "nmrium-container", ref: rootRef, css: containerStyles, onContextMenu: preventContextMenuHandler, style: { height: '100%', width: '100%' }, children: _jsx(DropZone, { children: _jsxs("div", { style: {
151
+ elementsWrapperRef: elementsWrapperRef.current,
152
+ }, children: _jsx(PreferencesProvider, { value: preferencesState, children: _jsx("div", { ref: mainDivRef, style: { height: '100%', position: 'relative' }, children: _jsx(AlertProvider, { wrapperRef: elementsWrapperRef.current, children: _jsx(DispatchProvider, { value: dispatchMiddleWare, children: _jsx(ChartDataProvider, { value: state, children: _jsx(ModalProvider, { wrapperRef: elementsWrapperRef.current, children: _jsx(HighlightProvider, { children: _jsx(AssignmentProvider, { spectraData: spectraData, children: _jsx(SpinnerProvider, { value: getSpinner, children: _jsx("div", { className: "nmrium-container", ref: rootRef, css: containerStyles, onContextMenu: preventContextMenuHandler, style: { height: '100%', width: '100%' }, children: _jsx(DropZone, { children: _jsxs("div", { style: {
160
153
  display: 'flex',
161
154
  flexDirection: 'column',
162
155
  backgroundColor: 'white',
@@ -169,7 +162,7 @@ function InnerNMRium({ data: dataProp = defaultData, workspace, preferences = de
169
162
  width: '100%',
170
163
  height: '100%',
171
164
  }, children: displayerMode ===
172
- DISPLAYER_MODE.DM_1D ? (_jsx(Viewer1D, { emptyText: emptyText })) : (_jsx(Viewer2D, { emptyText: emptyText })) })] }), _jsx(Panels, {})] }), _jsx("div", { ref: elementsWraperRef, id: "main-wrapper", style: {
165
+ DISPLAYER_MODE.DM_1D ? (_jsx(Viewer1D, { emptyText: emptyText })) : (_jsx(Viewer2D, { emptyText: emptyText })) })] }), _jsx(Panels, {})] }), _jsx("div", { ref: elementsWrapperRef, id: "main-wrapper", style: {
173
166
  position: 'absolute',
174
167
  pointerEvents: 'none',
175
168
  zIndex: 0,
@@ -0,0 +1,35 @@
1
+ /// <reference types="react" />
2
+ import { AssignmentsActions } from './AssignmentsReducer';
3
+ export declare type Axis = 'x' | 'y';
4
+ export declare type Assignment = Record<Axis, string[]>;
5
+ export declare type Assignments = Record<string, Assignment>;
6
+ export declare type AssignmentDimension = '1D' | '2D';
7
+ export interface AssignmentAction {
8
+ id: string;
9
+ axis: Axis | null;
10
+ }
11
+ export interface AssignmentState {
12
+ assignments: Assignments;
13
+ activated: AssignmentAction | null;
14
+ highlighted: AssignmentAction | null;
15
+ }
16
+ export interface AssignmentContext {
17
+ data: AssignmentState;
18
+ dispatch: (action: AssignmentsActions) => void;
19
+ }
20
+ export interface AssignmentsData extends Pick<AssignmentState, 'activated' | 'highlighted'> {
21
+ id: string;
22
+ isActive: boolean;
23
+ isOver: boolean;
24
+ assigned: Record<Axis, string[]>;
25
+ removeAll: (axis: Axis) => void;
26
+ toggle: (atomIDs: string[], dimension: AssignmentDimension) => void;
27
+ setActive: (axis: Axis) => void;
28
+ show: (axis?: Axis) => void;
29
+ hide: () => void;
30
+ }
31
+ export declare const assignmentState: AssignmentState;
32
+ export declare const assignmentContext: import("react").Context<AssignmentContext>;
33
+ export declare const AssignmentProvider: import("react").Provider<AssignmentContext>;
34
+ export declare function useAssignmentData(): AssignmentContext;
35
+ export declare function useAssignment(key: any): AssignmentsData;
@@ -0,0 +1,83 @@
1
+ import { createContext, useCallback, useContext, useMemo } from 'react';
2
+ export const assignmentState = {
3
+ assignments: {},
4
+ activated: null,
5
+ highlighted: null,
6
+ };
7
+ export const assignmentContext = createContext({
8
+ data: assignmentState,
9
+ dispatch: () => null,
10
+ });
11
+ export const AssignmentProvider = assignmentContext.Provider;
12
+ export function useAssignmentData() {
13
+ const context = useContext(assignmentContext);
14
+ if (!context) {
15
+ throw new Error('Assignment context was not found');
16
+ }
17
+ return context;
18
+ }
19
+ // key can be signal id,range id or zone id
20
+ export function useAssignment(key) {
21
+ const { data: { activated, highlighted, assignments }, dispatch, } = useAssignmentData();
22
+ if ((typeof key !== 'string' && typeof key !== 'number') || key === '') {
23
+ throw new Error(`assignment key must be a non-empty string or number`);
24
+ }
25
+ const id = String(key);
26
+ const isActive = useMemo(() => {
27
+ return activated?.id === id;
28
+ }, [activated?.id, id]);
29
+ const isOver = useMemo(() => {
30
+ return highlighted?.id === id;
31
+ }, [highlighted?.id, id]);
32
+ const assigned = useMemo(() => {
33
+ return assignments[id] || null;
34
+ }, [assignments, id]);
35
+ const removeAll = useCallback((axis) => {
36
+ dispatch({
37
+ type: 'REMOVE',
38
+ payload: { ids: [id], axis },
39
+ });
40
+ }, [dispatch, id]);
41
+ const toggle = useCallback((atomIDs, dimension) => {
42
+ dispatch({
43
+ type: 'TOGGLE',
44
+ payload: { atomIDs, id, dimension },
45
+ });
46
+ }, [dispatch, id]);
47
+ const setActive = useCallback((axis) => {
48
+ dispatch({
49
+ type: 'SET_ACTIVE',
50
+ payload: {
51
+ id,
52
+ axis,
53
+ },
54
+ });
55
+ }, [dispatch, id]);
56
+ const show = useCallback((axis) => {
57
+ dispatch({
58
+ type: 'SHOW',
59
+ payload: {
60
+ id,
61
+ axis,
62
+ },
63
+ });
64
+ }, [dispatch, id]);
65
+ const hide = useCallback(() => {
66
+ dispatch({
67
+ type: 'HIDE',
68
+ });
69
+ }, [dispatch]);
70
+ return {
71
+ id,
72
+ activated,
73
+ isActive,
74
+ isOver,
75
+ highlighted,
76
+ assigned,
77
+ removeAll,
78
+ toggle,
79
+ setActive,
80
+ show,
81
+ hide,
82
+ };
83
+ }
@@ -0,0 +1,32 @@
1
+ import { Data1D } from '../../data/types/data1d';
2
+ import { Data2D } from '../../data/types/data2d';
3
+ import { ActionType } from '../reducer/types/Types';
4
+ import { AssignmentDimension, AssignmentState, Axis } from './AssignmentsContext';
5
+ export declare type InitiateAction = ActionType<'INITIATE_ASSIGNMENTS', {
6
+ spectra: (Data1D | Data2D)[];
7
+ }>;
8
+ export declare type ToggleAction = ActionType<'TOGGLE', {
9
+ atomIDs: string[];
10
+ id: string;
11
+ dimension: AssignmentDimension;
12
+ }>;
13
+ export declare type AddAction = ActionType<'ADD', {
14
+ id: string;
15
+ atomID: string;
16
+ axis: Axis;
17
+ }>;
18
+ export declare type RemoveAction = ActionType<'REMOVE', {
19
+ ids: string[];
20
+ atomID?: string;
21
+ axis: Axis;
22
+ }>;
23
+ export declare type SetActiveAction = ActionType<'SET_ACTIVE', {
24
+ id: string;
25
+ axis: Axis;
26
+ }>;
27
+ export declare type ShowAction = ActionType<'SHOW', {
28
+ id: string;
29
+ axis?: Axis;
30
+ }>;
31
+ export declare type AssignmentsActions = InitiateAction | ToggleAction | AddAction | RemoveAction | SetActiveAction | ShowAction | ActionType<'HIDE'>;
32
+ export default function assignmentReducer(state: AssignmentState, action: AssignmentsActions): AssignmentState;
@@ -0,0 +1,39 @@
1
+ import initAssignment from './actions/initAssignment';
2
+ import removeAssignments from './actions/removeAssignment';
3
+ import setActiveAssignment from './actions/setActiveAssignment';
4
+ import toggleAssignment from './actions/toggleAssignment';
5
+ export default function assignmentReducer(state, action) {
6
+ switch (action.type) {
7
+ case 'INITIATE_ASSIGNMENTS': {
8
+ return initAssignment(action);
9
+ }
10
+ case 'REMOVE': {
11
+ const { axis, ids, atomID } = action.payload;
12
+ return removeAssignments(state, { axis, ids, atomID });
13
+ }
14
+ case 'TOGGLE': {
15
+ return toggleAssignment(state, action);
16
+ }
17
+ case 'SET_ACTIVE': {
18
+ return setActiveAssignment(state, action);
19
+ }
20
+ case 'SHOW': {
21
+ const { id, axis } = action.payload;
22
+ return {
23
+ ...state,
24
+ highlighted: {
25
+ id,
26
+ axis: axis || null,
27
+ },
28
+ };
29
+ }
30
+ case 'HIDE': {
31
+ return {
32
+ ...state,
33
+ highlighted: null,
34
+ };
35
+ }
36
+ default:
37
+ return state;
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ export default function initAssignment(action: any): {
2
+ assignments: import("../AssignmentsContext").Assignments;
3
+ activated: import("../AssignmentsContext").AssignmentAction | null;
4
+ highlighted: import("../AssignmentsContext").AssignmentAction | null;
5
+ };