nmrium 0.63.2 → 0.64.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 (160) hide show
  1. package/lib/component/1d/BrushTracker1D.d.ts.map +1 -1
  2. package/lib/component/1d/BrushTracker1D.js +8 -1
  3. package/lib/component/1d/BrushTracker1D.js.map +1 -1
  4. package/lib/component/1d/PredictionErrorsNotations.d.ts +2 -0
  5. package/lib/component/1d/PredictionErrorsNotations.d.ts.map +1 -0
  6. package/lib/component/1d/PredictionErrorsNotations.js +112 -0
  7. package/lib/component/1d/PredictionErrorsNotations.js.map +1 -0
  8. package/lib/component/1d/SVGContent1D.d.ts.map +1 -1
  9. package/lib/component/1d/SVGContent1D.js +2 -1
  10. package/lib/component/1d/SVGContent1D.js.map +1 -1
  11. package/lib/component/2d/ft/Contours.d.ts.map +1 -1
  12. package/lib/component/2d/ft/Contours.js +3 -4
  13. package/lib/component/2d/ft/Contours.js.map +1 -1
  14. package/lib/component/2d/utilities/extractSpectrumSignals.d.ts +5 -3
  15. package/lib/component/2d/utilities/extractSpectrumSignals.d.ts.map +1 -1
  16. package/lib/component/2d/utilities/extractSpectrumSignals.js +3 -3
  17. package/lib/component/2d/utilities/extractSpectrumSignals.js.map +1 -1
  18. package/lib/component/2d/zones/SignalsGuideLines.d.ts.map +1 -1
  19. package/lib/component/2d/zones/SignalsGuideLines.js +74 -6
  20. package/lib/component/2d/zones/SignalsGuideLines.js.map +1 -1
  21. package/lib/component/EventsTrackers/BrushTracker.d.ts.map +1 -1
  22. package/lib/component/EventsTrackers/BrushTracker.js +2 -2
  23. package/lib/component/EventsTrackers/BrushTracker.js.map +1 -1
  24. package/lib/component/assignment/AssignmentProvider.d.ts.map +1 -1
  25. package/lib/component/assignment/AssignmentProvider.js +2 -1
  26. package/lib/component/assignment/AssignmentProvider.js.map +1 -1
  27. package/lib/component/assignment/AssignmentsContext.d.ts +5 -2
  28. package/lib/component/assignment/AssignmentsContext.d.ts.map +1 -1
  29. package/lib/component/assignment/AssignmentsContext.js +2 -1
  30. package/lib/component/assignment/AssignmentsContext.js.map +1 -1
  31. package/lib/component/elements/SVGGroup.js +1 -1
  32. package/lib/component/elements/SVGGroup.js.map +1 -1
  33. package/lib/component/elements/Sections.d.ts +1 -0
  34. package/lib/component/elements/Sections.d.ts.map +1 -1
  35. package/lib/component/elements/Sections.js +42 -7
  36. package/lib/component/elements/Sections.js.map +1 -1
  37. package/lib/component/elements/pdnd.cjs +12 -0
  38. package/lib/component/elements/pdnd.cjs.map +1 -0
  39. package/lib/component/elements/pdnd.d.cts +2 -0
  40. package/lib/component/elements/pdnd.d.cts.map +1 -0
  41. package/lib/component/hooks/useToolsFunctions.js +1 -1
  42. package/lib/component/hooks/useToolsFunctions.js.map +1 -1
  43. package/lib/component/main/InnerNMRiumContents.d.ts.map +1 -1
  44. package/lib/component/main/InnerNMRiumContents.js +3 -1
  45. package/lib/component/main/InnerNMRiumContents.js.map +1 -1
  46. package/lib/component/modal/setting/settings-tabs/DatabasesTabContent.d.ts.map +1 -1
  47. package/lib/component/modal/setting/settings-tabs/DatabasesTabContent.js +7 -4
  48. package/lib/component/modal/setting/settings-tabs/DatabasesTabContent.js.map +1 -1
  49. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +6 -5
  50. package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js.map +1 -1
  51. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts +1 -1
  52. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.d.ts.map +1 -1
  53. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +3 -2
  54. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js.map +1 -1
  55. package/lib/component/panels/MoleculesPanel/useAtomAssignment.d.ts.map +1 -1
  56. package/lib/component/panels/MoleculesPanel/useAtomAssignment.js +17 -9
  57. package/lib/component/panels/MoleculesPanel/useAtomAssignment.js.map +1 -1
  58. package/lib/component/panels/Panels.d.ts +0 -4
  59. package/lib/component/panels/Panels.d.ts.map +1 -1
  60. package/lib/component/panels/Panels.js +8 -14
  61. package/lib/component/panels/Panels.js.map +1 -1
  62. package/lib/component/panels/RangesPanel/RangesHeader.d.ts.map +1 -1
  63. package/lib/component/panels/RangesPanel/RangesHeader.js +5 -8
  64. package/lib/component/panels/RangesPanel/RangesHeader.js.map +1 -1
  65. package/lib/component/panels/SpectraPanel/base/setting/Spectrum2DSetting.d.ts.map +1 -1
  66. package/lib/component/panels/SpectraPanel/base/setting/Spectrum2DSetting.js +4 -1
  67. package/lib/component/panels/SpectraPanel/base/setting/Spectrum2DSetting.js.map +1 -1
  68. package/lib/component/panels/extra/utilities/MultiplicityUtilities.d.ts +1 -1
  69. package/lib/component/panels/extra/utilities/MultiplicityUtilities.d.ts.map +1 -1
  70. package/lib/component/panels/filtersPanel/Filters/FiltersSectionsPanel.d.ts.map +1 -1
  71. package/lib/component/panels/filtersPanel/Filters/FiltersSectionsPanel.js +7 -1
  72. package/lib/component/panels/filtersPanel/Filters/FiltersSectionsPanel.js.map +1 -1
  73. package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.d.ts +1 -1
  74. package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.d.ts.map +1 -1
  75. package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.js +15 -17
  76. package/lib/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.js.map +1 -1
  77. package/lib/component/panels/hooks/useTogglePanel.d.ts.map +1 -1
  78. package/lib/component/panels/hooks/useTogglePanel.js +4 -3
  79. package/lib/component/panels/hooks/useTogglePanel.js.map +1 -1
  80. package/lib/component/reducer/Reducer.d.ts.map +1 -1
  81. package/lib/component/reducer/Reducer.js +2 -0
  82. package/lib/component/reducer/Reducer.js.map +1 -1
  83. package/lib/component/reducer/actions/FiltersActions.d.ts +7 -2
  84. package/lib/component/reducer/actions/FiltersActions.d.ts.map +1 -1
  85. package/lib/component/reducer/actions/FiltersActions.js +56 -26
  86. package/lib/component/reducer/actions/FiltersActions.js.map +1 -1
  87. package/lib/component/reducer/actions/InsetActions.d.ts.map +1 -1
  88. package/lib/component/reducer/actions/InsetActions.js +1 -5
  89. package/lib/component/reducer/actions/InsetActions.js.map +1 -1
  90. package/lib/component/reducer/actions/RangesActions.d.ts +3 -1
  91. package/lib/component/reducer/actions/RangesActions.d.ts.map +1 -1
  92. package/lib/component/reducer/actions/RangesActions.js +7 -14
  93. package/lib/component/reducer/actions/RangesActions.js.map +1 -1
  94. package/lib/component/reducer/actions/ToolsActions.d.ts.map +1 -1
  95. package/lib/component/reducer/actions/ToolsActions.js +2 -2
  96. package/lib/component/reducer/actions/ToolsActions.js.map +1 -1
  97. package/lib/component/reducer/helper/ZoomHistoryManager.d.ts +3 -2
  98. package/lib/component/reducer/helper/ZoomHistoryManager.d.ts.map +1 -1
  99. package/lib/component/reducer/helper/ZoomHistoryManager.js +17 -8
  100. package/lib/component/reducer/helper/ZoomHistoryManager.js.map +1 -1
  101. package/lib/component/reducer/preferences/actions/togglePanel.d.ts.map +1 -1
  102. package/lib/component/reducer/preferences/actions/togglePanel.js +11 -6
  103. package/lib/component/reducer/preferences/actions/togglePanel.js.map +1 -1
  104. package/lib/component/reducer/preferences/preferencesReducer.d.ts +3 -1
  105. package/lib/component/reducer/preferences/preferencesReducer.d.ts.map +1 -1
  106. package/lib/component/reducer/preferences/preferencesReducer.js.map +1 -1
  107. package/lib/component/workspaces/prediction.js +1 -1
  108. package/lib/component/workspaces/prediction.js.map +1 -1
  109. package/lib/data/PredictionManager.d.ts.map +1 -1
  110. package/lib/data/PredictionManager.js +1 -0
  111. package/lib/data/PredictionManager.js.map +1 -1
  112. package/lib/data/data2d/Spectrum2D/contours.d.ts.map +1 -1
  113. package/lib/data/data2d/Spectrum2D/contours.js +6 -4
  114. package/lib/data/data2d/Spectrum2D/contours.js.map +1 -1
  115. package/lib/data/data2d/Spectrum2D/initiateDatum2D.d.ts.map +1 -1
  116. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js +22 -10
  117. package/lib/data/data2d/Spectrum2D/initiateDatum2D.js.map +1 -1
  118. package/lib/data/data2d/Spectrum2D/zones/detectZonesManual.d.ts.map +1 -1
  119. package/lib/data/data2d/Spectrum2D/zones/initiateZones.d.ts.map +1 -1
  120. package/lib/data/types/data1d/index.js +1 -1
  121. package/lib/data/types/data1d/index.js.map +1 -1
  122. package/lib/versionInfo.js +1 -1
  123. package/package.json +20 -19
  124. package/src/component/1d/BrushTracker1D.tsx +8 -1
  125. package/src/component/1d/PredictionErrorsNotations.tsx +209 -0
  126. package/src/component/1d/SVGContent1D.tsx +2 -0
  127. package/src/component/2d/ft/Contours.tsx +3 -11
  128. package/src/component/2d/utilities/extractSpectrumSignals.ts +12 -9
  129. package/src/component/2d/zones/SignalsGuideLines.tsx +107 -11
  130. package/src/component/EventsTrackers/BrushTracker.tsx +2 -3
  131. package/src/component/assignment/AssignmentProvider.tsx +2 -1
  132. package/src/component/assignment/AssignmentsContext.ts +7 -2
  133. package/src/component/elements/SVGGroup.tsx +2 -2
  134. package/src/component/elements/Sections.tsx +103 -19
  135. package/src/component/elements/pdnd.cts +9 -0
  136. package/src/component/hooks/useToolsFunctions.ts +1 -1
  137. package/src/component/main/InnerNMRiumContents.tsx +3 -1
  138. package/src/component/modal/setting/settings-tabs/DatabasesTabContent.tsx +12 -7
  139. package/src/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.tsx +11 -5
  140. package/src/component/panels/MoleculesPanel/MoleculePanelHeader.tsx +32 -32
  141. package/src/component/panels/MoleculesPanel/useAtomAssignment.tsx +29 -8
  142. package/src/component/panels/Panels.tsx +9 -24
  143. package/src/component/panels/RangesPanel/RangesHeader.tsx +14 -21
  144. package/src/component/panels/SpectraPanel/base/setting/Spectrum2DSetting.tsx +11 -1
  145. package/src/component/panels/filtersPanel/Filters/FiltersSectionsPanel.tsx +9 -0
  146. package/src/component/panels/filtersPanel/Filters/hooks/usePhaseCorrectionTwoDimensions.tsx +16 -18
  147. package/src/component/panels/hooks/useTogglePanel.ts +4 -3
  148. package/src/component/reducer/Reducer.ts +2 -0
  149. package/src/component/reducer/actions/FiltersActions.ts +86 -40
  150. package/src/component/reducer/actions/InsetActions.ts +1 -5
  151. package/src/component/reducer/actions/RangesActions.ts +10 -13
  152. package/src/component/reducer/actions/ToolsActions.ts +1 -2
  153. package/src/component/reducer/helper/ZoomHistoryManager.ts +20 -9
  154. package/src/component/reducer/preferences/actions/togglePanel.ts +10 -6
  155. package/src/component/reducer/preferences/preferencesReducer.ts +11 -1
  156. package/src/component/workspaces/prediction.ts +1 -1
  157. package/src/data/PredictionManager.ts +1 -0
  158. package/src/data/data2d/Spectrum2D/contours.ts +8 -4
  159. package/src/data/data2d/Spectrum2D/initiateDatum2D.ts +34 -16
  160. package/src/versionInfo.ts +1 -1
@@ -1,4 +1,5 @@
1
1
  import type { Spectrum1D } from '@zakodium/nmrium-core';
2
+ import type { Range } from 'nmr-processing';
2
3
 
3
4
  import { SIGNAL_INCLUDED_KINDS } from '../../../data/constants/signalsKinds.js';
4
5
 
@@ -6,19 +7,21 @@ export interface BaseSignal {
6
7
  assignment?: string;
7
8
  delta: number;
8
9
  id: string;
9
- rangeId: string;
10
10
  }
11
11
 
12
- interface ExtractSpectrumSignalsOptions {
12
+ export type ExtractedSignal<T> = BaseSignal & T;
13
+
14
+ interface ExtractSpectrumSignalsOptions<T> {
13
15
  from?: number;
14
16
  to?: number;
17
+ include?: (range: Range) => T;
15
18
  }
16
- export function extractSpectrumSignals(
19
+ export function extractSpectrumSignals<T extends object = object>(
17
20
  spectrum: Spectrum1D,
18
- options: ExtractSpectrumSignalsOptions = {},
21
+ options: ExtractSpectrumSignalsOptions<T> = {},
19
22
  ) {
20
- const result: BaseSignal[] = [];
21
- const { from, to } = options;
23
+ const result: Array<ExtractedSignal<T>> = [];
24
+ const { from, to, include } = options;
22
25
 
23
26
  const ranges = spectrum?.ranges?.values;
24
27
  if (!Array.isArray(ranges) || ranges?.length === 0) {
@@ -40,7 +43,7 @@ export function extractSpectrumSignals(
40
43
 
41
44
  if (!isInRange) continue;
42
45
 
43
- const { assignment, signals = [], id: rangeId } = range;
46
+ const { assignment, signals = [] } = range;
44
47
  let index = 0;
45
48
  for (const signal of signals) {
46
49
  const { id, delta, kind } = signal;
@@ -49,8 +52,8 @@ export function extractSpectrumSignals(
49
52
  assignment: index === 0 ? assignment : '',
50
53
  delta,
51
54
  id,
52
- rangeId,
53
- });
55
+ ...include?.(range),
56
+ } as ExtractedSignal<T>);
54
57
  index++;
55
58
  }
56
59
  }
@@ -1,8 +1,16 @@
1
1
  import styled from '@emotion/styled';
2
2
  import type { Spectrum1D } from '@zakodium/nmrium-core';
3
+ import type { Range } from 'nmr-processing';
4
+ import { useRef } from 'react';
5
+ import { LuLink, LuUnlink } from 'react-icons/lu';
3
6
  import { PiTextTBold, PiTextTSlashBold } from 'react-icons/pi';
4
7
 
5
8
  import { FieldEdition } from '../../1d-2d/FieldEdition.js';
9
+ import {
10
+ useAssignment,
11
+ useAssignmentContext,
12
+ } from '../../assignment/AssignmentsContext.js';
13
+ import { filterAssignedIDs } from '../../assignment/utilities/filterAssignedIDs.js';
6
14
  import { useChartData } from '../../context/ChartContext.js';
7
15
  import { useDispatch } from '../../context/DispatchContext.js';
8
16
  import {
@@ -11,16 +19,17 @@ import {
11
19
  } from '../../context/ShareDataContext.js';
12
20
  import { ActionsButtonsPopover } from '../../elements/ActionsButtonsPopover.js';
13
21
  import type { ActionsButtonsPopoverProps } from '../../elements/ActionsButtonsPopover.js';
22
+ import { HighlightEventSource, useHighlight } from '../../highlight/index.js';
14
23
  import { useCanvasContext } from '../../hooks/useCanvasContext.js';
15
24
  import { useTriggerNewAssignmentLabel } from '../../hooks/useTriggerNewAssignmentLabel.js';
16
25
  import { stackOverlappingLabelsArray } from '../../utility/stackOverlappingLabels.js';
17
26
  import { useTracesSpectra } from '../useTracesSpectra.js';
18
27
  import { extractSpectrumSignals } from '../utilities/extractSpectrumSignals.js';
19
- import type { BaseSignal } from '../utilities/extractSpectrumSignals.js';
28
+ import type { ExtractedSignal } from '../utilities/extractSpectrumSignals.js';
20
29
  import { useScale2DX, useScale2DY } from '../utilities/scale.js';
21
30
 
22
- const Rect = styled.rect`
23
- fill: transparent;
31
+ const Rect = styled.rect<{ isActive: boolean }>`
32
+ fill: ${({ isActive }) => (isActive ? '#ff6f0057' : 'transparent')};
24
33
 
25
34
  &:hover {
26
35
  fill: #ff6f0057;
@@ -42,13 +51,18 @@ interface IndicationLinesProps extends SignalsGuideLinesProps {
42
51
  const labelSize = 12;
43
52
  const padding = 2;
44
53
 
45
- interface ProcessedSignal extends BaseSignal {
54
+ interface ExtraExtractProperties {
55
+ range: Range;
56
+ }
57
+ interface ProcessedSignal extends ExtractedSignal<ExtraExtractProperties> {
46
58
  labelWidth: number;
47
59
  deltaInPixel: number;
48
60
  }
49
61
 
50
62
  function useSignalsOverlap(axis: IndicationLinesAxis, spectrum: Spectrum1D) {
51
- const signals = extractSpectrumSignals(spectrum);
63
+ const signals = extractSpectrumSignals<ExtraExtractProperties>(spectrum, {
64
+ include: (range) => ({ range }),
65
+ });
52
66
  const scaleX = useScale2DX();
53
67
  const scaleY = useScale2DY();
54
68
  const context = useCanvasContext(labelSize);
@@ -87,13 +101,14 @@ function IndicationLines(props: IndicationLinesProps) {
87
101
  return (
88
102
  <g>
89
103
  {normalizedSignals.map(
90
- ({ deltaInPixel, stackIndex, assignment, id, rangeId }) => {
104
+ ({ deltaInPixel, stackIndex, assignment, id, range }) => {
91
105
  return (
92
106
  <IndicationLine
93
107
  key={`${axis}[${id}]`}
94
- {...{ deltaInPixel, stackIndex, assignment, id, rangeId }}
108
+ {...{ deltaInPixel, stackIndex, assignment, id }}
95
109
  axis={axis}
96
110
  spectrumId={spectrum.id}
111
+ range={range}
97
112
  />
98
113
  );
99
114
  },
@@ -102,11 +117,10 @@ function IndicationLines(props: IndicationLinesProps) {
102
117
  );
103
118
  }
104
119
 
105
- interface IndicationLineProps {
120
+ interface IndicationLineProps extends ExtraExtractProperties {
106
121
  deltaInPixel: number;
107
122
  stackIndex: number;
108
123
  assignment?: string;
109
- rangeId: string;
110
124
  spectrumId: string;
111
125
  axis: IndicationLinesAxis;
112
126
  }
@@ -121,12 +135,45 @@ function getAxisRangeId(options: GetAxisRangeIdOptions) {
121
135
  return `${axis}[${rangeId}]`;
122
136
  }
123
137
 
138
+ interface UseRangeAssignmentOptions {
139
+ rangeId: string;
140
+ signalsIds: string[];
141
+ spectrumId: string;
142
+ }
143
+
144
+ function useRangeAssignment(options: UseRangeAssignmentOptions) {
145
+ const { rangeId, signalsIds, spectrumId } = options;
146
+
147
+ const assignmentData = useAssignmentContext();
148
+ const assignmentContext = useAssignment(rangeId, spectrumId);
149
+ const highlightId = [rangeId]
150
+ .concat(assignmentContext.assignedDiaIds?.x || [])
151
+ .concat(filterAssignedIDs(assignmentData.data, signalsIds));
152
+
153
+ const highlightContext = useHighlight(highlightId, {
154
+ type: HighlightEventSource.RANGE,
155
+ extra: { id: rangeId, spectrumID: spectrumId },
156
+ });
157
+ return { highlightContext, assignmentContext };
158
+ }
159
+
124
160
  function IndicationLine(props: IndicationLineProps) {
125
- const { deltaInPixel, stackIndex, assignment, rangeId, axis, spectrumId } =
161
+ const isAssignBtnTrigged = useRef(false);
162
+ const { deltaInPixel, stackIndex, assignment, axis, spectrumId, range } =
126
163
  props;
164
+ const { id: rangeId, diaIDs = [], signals } = range;
165
+ const signalsIds = signals.map(({ id }) => id);
127
166
  const { margin, width, height } = useChartData();
128
167
  const { setData: addNewAssignmentLabel } = useShareData();
129
168
  const dispatch = useDispatch();
169
+ const { assignmentContext, highlightContext } = useRangeAssignment({
170
+ rangeId,
171
+ spectrumId,
172
+ signalsIds,
173
+ });
174
+ const hasDiaIDs = diaIDs.length > 0;
175
+ const isAssignmentActive = assignmentContext.isActive;
176
+ const isHighlighted = highlightContext.isActive || isAssignmentActive;
130
177
 
131
178
  const innerWidth = width - margin.left - margin.right;
132
179
  const innerHeight = height - margin.top - margin.bottom;
@@ -157,7 +204,45 @@ function IndicationLine(props: IndicationLineProps) {
157
204
  });
158
205
  }
159
206
 
207
+ function mouseEnterHandler() {
208
+ assignmentContext.highlight('x');
209
+ highlightContext.show();
210
+ }
211
+
212
+ function mouseLeaveHandler() {
213
+ assignmentContext.clearHighlight();
214
+ highlightContext.hide();
215
+ }
216
+
217
+ function assignHandler() {
218
+ isAssignBtnTrigged.current = true;
219
+ assignmentContext.activate('x');
220
+ }
221
+
222
+ function unAssignHandler() {
223
+ dispatch({
224
+ type: 'UNLINK_RANGE',
225
+ payload: {
226
+ rangeKey: rangeId,
227
+ spectrumId,
228
+ },
229
+ });
230
+ }
231
+
160
232
  const actionsButtons: ActionsButtonsPopoverProps['buttons'] = [
233
+ {
234
+ icon: <LuLink />,
235
+ onClick: assignHandler,
236
+ intent: 'success',
237
+ title: 'Assign range',
238
+ },
239
+ {
240
+ icon: <LuUnlink />,
241
+ onClick: () => unAssignHandler(),
242
+ intent: 'danger',
243
+ title: 'Unassign range',
244
+ visible: !!(isAssignmentActive || hasDiaIDs),
245
+ },
161
246
  {
162
247
  icon: <PiTextTBold />,
163
248
  onClick: () => addNewAssignmentLabel(getAxisRangeId({ axis, rangeId })),
@@ -174,14 +259,24 @@ function IndicationLine(props: IndicationLineProps) {
174
259
  },
175
260
  ];
176
261
 
262
+ const isOpen = isAssignBtnTrigged.current ? isAssignmentActive : undefined;
263
+
177
264
  return (
178
265
  <ActionsButtonsPopover
266
+ isOpen={isOpen}
179
267
  targetTagName="g"
180
268
  buttons={actionsButtons}
181
269
  space={2}
182
270
  position={isOverXAxis ? 'right-top' : 'top-left'}
271
+ onClosed={() => {
272
+ isAssignBtnTrigged.current = false;
273
+ }}
183
274
  >
184
- <g transform={`translate(${x},${y})`}>
275
+ <g
276
+ transform={`translate(${x},${y})`}
277
+ onMouseEnter={mouseEnterHandler}
278
+ onMouseLeave={mouseLeaveHandler}
279
+ >
185
280
  <line stroke="lightgrey" x1={0} x2={x2} y1={0} y2={y2} />
186
281
  <Rect
187
282
  x={-rectXOffset}
@@ -189,6 +284,7 @@ function IndicationLine(props: IndicationLineProps) {
189
284
  width={rectWidth}
190
285
  height={rectHeight}
191
286
  data-no-export="true"
287
+ isActive={isHighlighted}
192
288
  />
193
289
  <AssignmentLabel
194
290
  x={labelX}
@@ -498,10 +498,9 @@ export function detectBrushing(
498
498
  const scaleY = (endY - startY) / height;
499
499
  const scaleX = (endX - startX) / width;
500
500
  if (thresholdAxis === 'y') {
501
- if (yDiff >= yThreshold) {
501
+ if (yDiff >= yThreshold && yThreshold > 0) {
502
502
  return { type: 'XY', startX, startY, endX, endY, scaleX, scaleY };
503
503
  }
504
-
505
504
  return {
506
505
  type: 'X',
507
506
  startX,
@@ -513,7 +512,7 @@ export function detectBrushing(
513
512
  };
514
513
  }
515
514
  if (thresholdAxis === 'x') {
516
- if (xDiff >= xThreshold) {
515
+ if (xDiff >= xThreshold && xThreshold > 0) {
517
516
  return { type: 'XY', startX, startY, endX, endY, scaleX, scaleY };
518
517
  }
519
518
 
@@ -24,10 +24,11 @@ export function AssignmentProvider(props: AssignmentProviderProps) {
24
24
 
25
25
  const memoState = useMemo<AssignmentContext>(() => {
26
26
  const activate = (options: ActivateAssignmentOptions) => {
27
+ const { id, axis, spectrumId } = options;
27
28
  setState((prevState) => ({
28
29
  ...prevState,
29
30
  activated: !prevState.activated
30
- ? { id: options.id, axis: options.axis || null }
31
+ ? { id, axis: axis || null, spectrumId }
31
32
  : null,
32
33
  }));
33
34
  };
@@ -32,6 +32,7 @@ export interface HighlightAssignmentOptions {
32
32
  export interface ActivateAssignmentOptions {
33
33
  id: string;
34
34
  axis: Axis;
35
+ spectrumId?: string;
35
36
  }
36
37
 
37
38
  export const assignmentStatus: AssignmentStatus = {
@@ -40,7 +41,7 @@ export const assignmentStatus: AssignmentStatus = {
40
41
  };
41
42
 
42
43
  export interface AssignmentStatus {
43
- activated: AssignmentItem | null;
44
+ activated: (AssignmentItem & { spectrumId?: string }) | null;
44
45
  highlighted: AssignmentItem | null;
45
46
  }
46
47
  export interface AssignmentContext extends AssignmentStatus {
@@ -82,7 +83,10 @@ export function useAssignmentContext() {
82
83
  }
83
84
 
84
85
  // key can be signal id,range id or zone id
85
- export function useAssignment(id: string): AssignmentsData {
86
+ export function useAssignment(
87
+ id: string,
88
+ spectrumId?: string,
89
+ ): AssignmentsData {
86
90
  const { data, activated, highlighted, activate, highlight, clearHighlight } =
87
91
  useAssignmentContext();
88
92
 
@@ -93,6 +97,7 @@ export function useAssignment(id: string): AssignmentsData {
93
97
  function activateAssignment(axis: Axis) {
94
98
  if (id) {
95
99
  activate({
100
+ spectrumId,
96
101
  id,
97
102
  axis,
98
103
  });
@@ -8,7 +8,7 @@ interface SVGGroupProps extends SVGAttributes<SVGElement> {
8
8
  }
9
9
 
10
10
  export function SVGGroup(props: SVGGroupProps) {
11
- const elementsRefs = useRef<SVGElement[]>([]);
11
+ const elementsRefs = useRef<SVGGraphicsElement[]>([]);
12
12
  const { children, direction = 'row', space = 0, ...resProps } = props;
13
13
 
14
14
  useLayoutEffect(() => {
@@ -21,7 +21,7 @@ export function SVGGroup(props: SVGGroupProps) {
21
21
 
22
22
  for (const element of elements) {
23
23
  if (element) {
24
- const boundary = element.getBoundingClientRect();
24
+ const boundary = element.getBBox();
25
25
  if (direction === 'row') {
26
26
  element.setAttribute('transform', `translate(${shift} 0)`);
27
27
  shift += boundary.width + space;
@@ -7,7 +7,16 @@ import type {
7
7
  MouseEvent,
8
8
  ReactNode,
9
9
  } from 'react';
10
- import { createContext, useContext, useMemo } from 'react';
10
+ import {
11
+ createContext,
12
+ useContext,
13
+ useMemo,
14
+ useEffect,
15
+ useRef,
16
+ useState,
17
+ } from 'react';
18
+
19
+ import { draggable, dropTargetForElements } from './pdnd.cjs';
11
20
 
12
21
  interface SelectionsContextState {
13
22
  isOverflow: boolean;
@@ -162,6 +171,10 @@ interface SectionItemProps extends BaseSectionProps {
162
171
  children?: ReactNode | ((options: { isOpen?: boolean }) => ReactNode);
163
172
  isOpen: boolean;
164
173
  sticky?: boolean;
174
+ onReorder?: (
175
+ sourceId: string | undefined,
176
+ targetId: string | undefined,
177
+ ) => void;
165
178
  }
166
179
 
167
180
  interface SectionProps {
@@ -218,29 +231,62 @@ function SectionItem(props: SectionItemProps) {
218
231
  isOpen,
219
232
  sticky = false,
220
233
  arrowProps = { hide: false, style: {} },
234
+ onReorder,
221
235
  } = props;
222
236
 
223
237
  const { isOverflow, matchContentHeight } = useSections();
224
238
 
239
+ const wrapperRef = useRef<HTMLDivElement>(null);
240
+ const handleRef = useRef<HTMLDivElement>(null);
241
+
242
+ useEffect(() => {
243
+ if (!wrapperRef.current || !handleRef.current) return;
244
+
245
+ const cleanDrag = draggable({
246
+ element: wrapperRef.current,
247
+ dragHandle: handleRef.current,
248
+ getInitialData: () => ({ id }),
249
+ });
250
+
251
+ return () => {
252
+ cleanDrag();
253
+ };
254
+ }, [id]);
255
+
225
256
  return (
226
- <SectionWrapper
227
- isOpen={isOpen}
228
- isOverflow={isOverflow}
229
- matchContentHeight={matchContentHeight}
230
- >
231
- <MainSectionHeader
232
- title={title}
233
- isOpen={isOpen}
234
- onClick={(event) => onClick?.(id, event)}
235
- serial={serial}
236
- rightElement={rightElement}
237
- leftElement={leftElement}
238
- headerStyle={headerStyle}
239
- sticky={sticky}
240
- arrowProps={arrowProps}
241
- />
242
- <Wrapper isOpen={isOpen}>{children}</Wrapper>
243
- </SectionWrapper>
257
+ <DroppableSectionWrapper key={id} id={id} onReorder={onReorder}>
258
+ <div ref={wrapperRef}>
259
+ <SectionWrapper
260
+ isOpen={isOpen}
261
+ isOverflow={isOverflow}
262
+ matchContentHeight={matchContentHeight}
263
+ >
264
+ <MainSectionHeader
265
+ title={title}
266
+ isOpen={isOpen}
267
+ onClick={(event) => onClick?.(id, event)}
268
+ serial={serial}
269
+ rightElement={rightElement}
270
+ dragHandleElement={
271
+ typeof onReorder === 'function' && (
272
+ <div
273
+ ref={handleRef}
274
+ onClick={(e) => e.stopPropagation()}
275
+ style={{ cursor: 'grab' }}
276
+ >
277
+ <Icon icon="drag-handle-vertical" />
278
+ </div>
279
+ )
280
+ }
281
+ leftElement={leftElement}
282
+ headerStyle={headerStyle}
283
+ sticky={sticky}
284
+ arrowProps={arrowProps}
285
+ />
286
+ <Wrapper isOpen={isOpen}>{children}</Wrapper>
287
+ </SectionWrapper>
288
+ </div>
289
+ </DroppableSectionWrapper>
244
290
  );
245
291
  }
246
292
 
@@ -270,6 +316,7 @@ interface MainSectionHeaderProps
270
316
  BaseSectionProps {
271
317
  isOpen: boolean;
272
318
  sticky: boolean;
319
+ dragHandleElement?: ReactNode;
273
320
  }
274
321
 
275
322
  function MainSectionHeader(props: MainSectionHeaderProps) {
@@ -279,6 +326,7 @@ function MainSectionHeader(props: MainSectionHeaderProps) {
279
326
  onClick,
280
327
  serial,
281
328
  rightElement,
329
+ dragHandleElement,
282
330
  leftElement,
283
331
  headerStyle = {},
284
332
  sticky,
@@ -314,6 +362,7 @@ function MainSectionHeader(props: MainSectionHeaderProps) {
314
362
  {typeof rightElement === 'function'
315
363
  ? rightElement(isOpen)
316
364
  : rightElement}
365
+ {dragHandleElement}
317
366
  </ElementsContainer>
318
367
  {!arrowProps?.hide && (
319
368
  <OpenIcon
@@ -327,6 +376,41 @@ function MainSectionHeader(props: MainSectionHeaderProps) {
327
376
  );
328
377
  }
329
378
 
379
+ interface DroppableProps extends Pick<SectionItemProps, 'id' | 'onReorder'> {
380
+ children: ReactNode;
381
+ }
382
+
383
+ function DroppableSectionWrapper({ id, onReorder, children }: DroppableProps) {
384
+ const ref = useRef<HTMLDivElement>(null);
385
+ const [isOver, setIsOver] = useState(false);
386
+
387
+ useEffect(() => {
388
+ if (!ref.current) return;
389
+
390
+ return dropTargetForElements({
391
+ element: ref.current,
392
+ canDrop: ({ source }) => source.data?.id !== id,
393
+ onDrop: ({ source }) => {
394
+ const sourceId = source.data?.id as string;
395
+ setIsOver(false);
396
+ onReorder?.(sourceId, id);
397
+ },
398
+ onDragEnter: () => setIsOver(true),
399
+ onDragLeave: () => setIsOver(false),
400
+ });
401
+ }, [id, onReorder]);
402
+
403
+ return (
404
+ <div
405
+ ref={ref}
406
+ data-drop-id={id}
407
+ style={{ ...(isOver && { opacity: 0.1 }) }}
408
+ >
409
+ {children}
410
+ </div>
411
+ );
412
+ }
413
+
330
414
  Sections.Header = SectionHeader;
331
415
  Sections.Body = SectionBody;
332
416
  Sections.Item = SectionItem;
@@ -0,0 +1,9 @@
1
+ // https://github.com/atlassian/pragmatic-drag-and-drop/issues/27
2
+ // Given how `@atlaskit/pragmatic-drag-and-drop` publishes ESM in a non-native way,
3
+ // we have to trick TS into using the CJS build so that our build is compatible
4
+ // with native ESM.
5
+ // We cannot use `verbatimModuleSyntax` ts config option with this pattern.
6
+ export {
7
+ draggable,
8
+ dropTargetForElements,
9
+ } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
@@ -68,7 +68,7 @@ export default function useToolsFunctions() {
68
68
  if (debounceClickEventsRef.current.clicks.length === 0) {
69
69
  dispatch({
70
70
  type: 'FULL_ZOOM_OUT',
71
- payload: { zoomType: 'HORIZONTAL' },
71
+ payload: { zoomType: 'BIDIRECTIONAL' },
72
72
  });
73
73
  }
74
74
  const callback = lodashDebounce(() => {
@@ -50,7 +50,9 @@ const NMRiumContainer = styled.div`
50
50
  cursor: default;
51
51
  }
52
52
 
53
- * {
53
+ span,
54
+ p,
55
+ text {
54
56
  -webkit-user-drag: none;
55
57
  -moz-user-drag: none;
56
58
  -o-user-drag: none;
@@ -1,4 +1,4 @@
1
- import { Checkbox, Classes, Radio } from '@blueprintjs/core';
1
+ import { Checkbox, Classes } from '@blueprintjs/core';
2
2
  import styled from '@emotion/styled';
3
3
  import type { CustomWorkspaces, Database } from '@zakodium/nmrium-core';
4
4
  import { useCallback, useMemo } from 'react';
@@ -128,13 +128,18 @@ function DatabasesTabContent({
128
128
  control={control}
129
129
  name="databases.defaultDatabase"
130
130
  render={({ field }) => {
131
- const { onChange, value } = field;
131
+ const { value, name } = field;
132
+ const databaseKey = row.original.key;
133
+
132
134
  return (
133
- <Radio
134
- value={row.original.key}
135
+ <Checkbox
136
+ name={name}
137
+ value={databaseKey}
135
138
  style={{ margin: 0 }}
136
- checked={value === row.original.key}
137
- onChange={onChange}
139
+ checked={value === databaseKey}
140
+ onChange={() => {
141
+ setValue(name, databaseKey === value ? '' : databaseKey);
142
+ }}
138
143
  />
139
144
  );
140
145
  }}
@@ -191,7 +196,7 @@ function DatabasesTabContent({
191
196
  },
192
197
  },
193
198
  ],
194
- [addHandler, control, deleteHandler, register],
199
+ [addHandler, control, deleteHandler, register, setValue],
195
200
  );
196
201
 
197
202
  function resetHandler() {
@@ -3,7 +3,7 @@ import { yupResolver } from '@hookform/resolvers/yup';
3
3
  import { SvgNmrMultipleAnalysis } from 'cheminfo-font';
4
4
  import type { MatrixOptions } from 'nmr-processing';
5
5
  import { Filters1D } from 'nmr-processing';
6
- import { useCallback } from 'react';
6
+ import { useCallback, useMemo } from 'react';
7
7
  import { FormProvider, useForm } from 'react-hook-form';
8
8
  import { Button, Toolbar } from 'react-science/ui';
9
9
  import * as yup from 'yup';
@@ -171,12 +171,18 @@ function InnerMatrixGenerationPanel() {
171
171
  });
172
172
  const { handleSubmit, reset, control } = methods;
173
173
 
174
+ const memoizedInitialValues = useMemo(
175
+ () =>
176
+ getMatrixOptions(nucleusMatrixOptions.matrixOptions, {
177
+ from: originDomain.xDomain[0],
178
+ to: originDomain.xDomain[1],
179
+ }),
180
+ [nucleusMatrixOptions.matrixOptions, originDomain.xDomain],
181
+ );
182
+
174
183
  useWatchForm({
175
184
  reset,
176
- initialValues: getMatrixOptions(nucleusMatrixOptions.matrixOptions, {
177
- from: originDomain.xDomain[0],
178
- to: originDomain.xDomain[1],
179
- }),
185
+ initialValues: memoizedInitialValues,
180
186
  control,
181
187
  onChange: (values) => {
182
188
  handleOnChange(values);