nmrium 2.6.0 → 2.7.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/ApodizationLine.js +2 -2
  2. package/lib/component/1d/ApodizationLine.js.map +1 -1
  3. package/lib/component/1d/Line.js +2 -2
  4. package/lib/component/1d/Line.js.map +1 -1
  5. package/lib/component/1d/SVGContent1D.d.ts.map +1 -1
  6. package/lib/component/1d/SVGContent1D.js +4 -1
  7. package/lib/component/1d/SVGContent1D.js.map +1 -1
  8. package/lib/component/1d/baseline/BaselinePreview.js +2 -2
  9. package/lib/component/1d/baseline/BaselinePreview.js.map +1 -1
  10. package/lib/component/1d/database/DatabaseSpectrum.js +2 -2
  11. package/lib/component/1d/database/DatabaseSpectrum.js.map +1 -1
  12. package/lib/component/1d/database/ResurrectedDatabaseRanges.js +2 -2
  13. package/lib/component/1d/database/ResurrectedDatabaseRanges.js.map +1 -1
  14. package/lib/component/1d/matrix/Boxplot.js +5 -5
  15. package/lib/component/1d/matrix/Boxplot.js.map +1 -1
  16. package/lib/component/1d/matrix/Stocsy.js +2 -2
  17. package/lib/component/1d/matrix/Stocsy.js.map +1 -1
  18. package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.d.ts.map +1 -1
  19. package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.js +12 -3
  20. package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.js.map +1 -1
  21. package/lib/component/1d/peaks/usePeakShapesPath.js +2 -2
  22. package/lib/component/1d/peaks/usePeakShapesPath.js.map +1 -1
  23. package/lib/component/1d/plugin_svg_chart.d.ts +2 -0
  24. package/lib/component/1d/plugin_svg_chart.d.ts.map +1 -0
  25. package/lib/component/1d/plugin_svg_chart.js +43 -0
  26. package/lib/component/1d/plugin_svg_chart.js.map +1 -0
  27. package/lib/component/1d-2d/components/RangeIndicator.d.ts.map +1 -1
  28. package/lib/component/1d-2d/components/RangeIndicator.js +1 -7
  29. package/lib/component/1d-2d/components/RangeIndicator.js.map +1 -1
  30. package/lib/component/2d/1d-tracer/HorizontalSliceChart.js +2 -2
  31. package/lib/component/2d/1d-tracer/HorizontalSliceChart.js.map +1 -1
  32. package/lib/component/2d/1d-tracer/Left1DChart.js +2 -2
  33. package/lib/component/2d/1d-tracer/Left1DChart.js.map +1 -1
  34. package/lib/component/2d/1d-tracer/Top1DChart.js +2 -2
  35. package/lib/component/2d/1d-tracer/Top1DChart.js.map +1 -1
  36. package/lib/component/2d/1d-tracer/VerticalSliceChart.js +2 -2
  37. package/lib/component/2d/1d-tracer/VerticalSliceChart.js.map +1 -1
  38. package/lib/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.js +3 -3
  39. package/lib/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.js.map +1 -1
  40. package/lib/component/2d/ft/Contours.js +2 -2
  41. package/lib/component/2d/ft/Contours.js.map +1 -1
  42. package/lib/component/context/ScaleContext.d.ts +1 -1
  43. package/lib/component/context/ScaleContext.d.ts.map +1 -1
  44. package/lib/component/elements/D3Axis.d.ts.map +1 -1
  45. package/lib/component/elements/D3Axis.js +15 -32
  46. package/lib/component/elements/D3Axis.js.map +1 -1
  47. package/lib/component/elements/export/ExportContent.d.ts.map +1 -1
  48. package/lib/component/elements/export/ExportContent.js +2 -2
  49. package/lib/component/elements/export/ExportContent.js.map +1 -1
  50. package/lib/component/elements/export/ExportOptionsModal.d.ts.map +1 -1
  51. package/lib/component/elements/export/ExportOptionsModal.js +9 -3
  52. package/lib/component/elements/export/ExportOptionsModal.js.map +1 -1
  53. package/lib/component/elements/export/useExportConfigurer.d.ts +1 -0
  54. package/lib/component/elements/export/useExportConfigurer.d.ts.map +1 -1
  55. package/lib/component/elements/export/useExportConfigurer.js +5 -0
  56. package/lib/component/elements/export/useExportConfigurer.js.map +1 -1
  57. package/lib/component/elements/print/PrintContent.d.ts.map +1 -1
  58. package/lib/component/elements/print/PrintContent.js +6 -25
  59. package/lib/component/elements/print/PrintContent.js.map +1 -1
  60. package/lib/component/elements/utilities/transferStyles.d.ts +2 -0
  61. package/lib/component/elements/utilities/transferStyles.d.ts.map +1 -0
  62. package/lib/component/elements/utilities/transferStyles.js +29 -0
  63. package/lib/component/elements/utilities/transferStyles.js.map +1 -0
  64. package/lib/component/hooks/useIntegralPath.js +2 -2
  65. package/lib/component/hooks/useIntegralPath.js.map +1 -1
  66. package/lib/component/modal/setting/tanstack_general_settings/errors/context.d.ts +106 -105
  67. package/lib/component/modal/setting/tanstack_general_settings/errors/context.d.ts.map +1 -1
  68. package/lib/component/modal/setting/tanstack_general_settings/errors/renderer.d.ts +106 -105
  69. package/lib/component/modal/setting/tanstack_general_settings/errors/renderer.d.ts.map +1 -1
  70. package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_body.d.ts +106 -105
  71. package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_body.d.ts.map +1 -1
  72. package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_footer.d.ts +91 -90
  73. package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_footer.d.ts.map +1 -1
  74. package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_header.d.ts +91 -90
  75. package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_header.d.ts.map +1 -1
  76. package/lib/component/modal/setting/tanstack_general_settings/hooks/use_safe_workspace.d.ts +15 -15
  77. package/lib/component/modal/setting/tanstack_general_settings/tabs/auto_processing_tab.d.ts +91 -90
  78. package/lib/component/modal/setting/tanstack_general_settings/tabs/auto_processing_tab.d.ts.map +1 -1
  79. package/lib/component/modal/setting/tanstack_general_settings/tabs/axis_tab.d.ts +91 -90
  80. package/lib/component/modal/setting/tanstack_general_settings/tabs/axis_tab.d.ts.map +1 -1
  81. package/lib/component/modal/setting/tanstack_general_settings/tabs/database_tab.d.ts +91 -90
  82. package/lib/component/modal/setting/tanstack_general_settings/tabs/database_tab.d.ts.map +1 -1
  83. package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.d.ts +91 -90
  84. package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.d.ts.map +1 -1
  85. package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.d.ts +12 -10
  86. package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.d.ts.map +1 -1
  87. package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.js +32 -40
  88. package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.js.map +1 -1
  89. package/lib/component/modal/setting/tanstack_general_settings/tabs/external_api_tab.d.ts +91 -90
  90. package/lib/component/modal/setting/tanstack_general_settings/tabs/external_api_tab.d.ts.map +1 -1
  91. package/lib/component/modal/setting/tanstack_general_settings/tabs/general_tab.d.ts +91 -90
  92. package/lib/component/modal/setting/tanstack_general_settings/tabs/general_tab.d.ts.map +1 -1
  93. package/lib/component/modal/setting/tanstack_general_settings/tabs/import_filters_tab.d.ts +91 -90
  94. package/lib/component/modal/setting/tanstack_general_settings/tabs/import_filters_tab.d.ts.map +1 -1
  95. package/lib/component/modal/setting/tanstack_general_settings/tabs/nuclei_tab.d.ts +91 -90
  96. package/lib/component/modal/setting/tanstack_general_settings/tabs/nuclei_tab.d.ts.map +1 -1
  97. package/lib/component/modal/setting/tanstack_general_settings/tabs/panels_tab.d.ts +91 -90
  98. package/lib/component/modal/setting/tanstack_general_settings/tabs/panels_tab.d.ts.map +1 -1
  99. package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_colors_tab.d.ts +91 -90
  100. package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_colors_tab.d.ts.map +1 -1
  101. package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_label_tab.d.ts +91 -90
  102. package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_label_tab.d.ts.map +1 -1
  103. package/lib/component/modal/setting/tanstack_general_settings/tabs/title_block_tab.d.ts +91 -90
  104. package/lib/component/modal/setting/tanstack_general_settings/tabs/title_block_tab.d.ts.map +1 -1
  105. package/lib/component/modal/setting/tanstack_general_settings/tabs/tools_tab.d.ts +91 -90
  106. package/lib/component/modal/setting/tanstack_general_settings/tabs/tools_tab.d.ts.map +1 -1
  107. package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.d.ts +61 -17
  108. package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.d.ts.map +1 -1
  109. package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.js +79 -28
  110. package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.js.map +1 -1
  111. package/lib/component/modal/setting/tanstack_general_settings/validation.d.ts +15 -15
  112. package/lib/component/panels/filtersPanel/processings_sections_panel.js +1 -1
  113. package/lib/component/panels/filtersPanel/processings_sections_panel.js.map +1 -1
  114. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.d.ts +3 -3
  115. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.d.ts.map +1 -1
  116. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +69 -56
  117. package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js.map +1 -1
  118. package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
  119. package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js.map +1 -1
  120. package/lib/component/toolbar/nmr_toolbar.js +1 -1
  121. package/lib/component/toolbar/nmr_toolbar.js.map +1 -1
  122. package/lib/component/utility/core_slots/core_operator_chart_svg.d.ts +8 -0
  123. package/lib/component/utility/core_slots/core_operator_chart_svg.d.ts.map +1 -0
  124. package/lib/component/utility/core_slots/core_operator_chart_svg.js +23 -0
  125. package/lib/component/utility/core_slots/core_operator_chart_svg.js.map +1 -0
  126. package/lib/component/utility/core_slots/core_operator_panel_tool.d.ts +2 -8
  127. package/lib/component/utility/core_slots/core_operator_panel_tool.d.ts.map +1 -1
  128. package/lib/component/utility/core_slots/core_operator_panel_tool.js +8 -6
  129. package/lib/component/utility/core_slots/core_operator_panel_tool.js.map +1 -1
  130. package/lib/component/utility/core_slots/core_operator_tool.commons.d.ts +11 -0
  131. package/lib/component/utility/core_slots/core_operator_tool.commons.d.ts.map +1 -0
  132. package/lib/component/utility/core_slots/core_operator_tool.commons.js +30 -0
  133. package/lib/component/utility/core_slots/core_operator_tool.commons.js.map +1 -0
  134. package/lib/component/utility/core_slots/core_operator_tool.d.ts +2 -8
  135. package/lib/component/utility/core_slots/core_operator_tool.d.ts.map +1 -1
  136. package/lib/component/utility/core_slots/core_operator_tool.js +8 -6
  137. package/lib/component/utility/core_slots/core_operator_tool.js.map +1 -1
  138. package/lib/component/utility/export.d.ts +5 -0
  139. package/lib/component/utility/export.d.ts.map +1 -1
  140. package/lib/component/utility/export.js +22 -0
  141. package/lib/component/utility/export.js.map +1 -1
  142. package/lib/data/data2d/Spectrum2D/contours.d.ts.map +1 -1
  143. package/lib/data/data2d/Spectrum2D/contours.js +23 -10
  144. package/lib/data/data2d/Spectrum2D/contours.js.map +1 -1
  145. package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.d.ts +13 -0
  146. package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.d.ts.map +1 -0
  147. package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.js +40 -0
  148. package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.js.map +1 -0
  149. package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.d.ts +27 -0
  150. package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.d.ts.map +1 -0
  151. package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.js +230 -0
  152. package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.js.map +1 -0
  153. package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.d.ts +227 -0
  154. package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.d.ts.map +1 -0
  155. package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.js +67 -0
  156. package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.js.map +1 -0
  157. package/lib/data/data2d/Spectrum2D/findBestMinContour/math.d.ts +4 -0
  158. package/lib/data/data2d/Spectrum2D/findBestMinContour/math.d.ts.map +1 -0
  159. package/lib/data/data2d/Spectrum2D/findBestMinContour/math.js +42 -0
  160. package/lib/data/data2d/Spectrum2D/findBestMinContour/math.js.map +1 -0
  161. package/lib/data/utilities/calculateSanPlot.d.ts +3 -1
  162. package/lib/data/utilities/calculateSanPlot.d.ts.map +1 -1
  163. package/lib/data/utilities/calculateSanPlot.js +2 -2
  164. package/lib/data/utilities/calculateSanPlot.js.map +1 -1
  165. package/lib/versionInfo.js +1 -1
  166. package/package.json +5 -5
  167. package/src/component/1d/ApodizationLine.tsx +2 -2
  168. package/src/component/1d/Line.tsx +2 -2
  169. package/src/component/1d/SVGContent1D.tsx +6 -0
  170. package/src/component/1d/baseline/BaselinePreview.tsx +2 -2
  171. package/src/component/1d/database/DatabaseSpectrum.tsx +2 -2
  172. package/src/component/1d/database/ResurrectedDatabaseRanges.tsx +2 -2
  173. package/src/component/1d/matrix/Boxplot.tsx +5 -5
  174. package/src/component/1d/matrix/Stocsy.tsx +2 -2
  175. package/src/component/1d/peaks/PeakAnnotationsSpreadMode.tsx +17 -3
  176. package/src/component/1d/peaks/usePeakShapesPath.ts +2 -2
  177. package/src/component/1d/plugin_svg_chart.tsx +60 -0
  178. package/src/component/1d-2d/components/RangeIndicator.tsx +8 -9
  179. package/src/component/2d/1d-tracer/HorizontalSliceChart.tsx +2 -2
  180. package/src/component/2d/1d-tracer/Left1DChart.tsx +2 -2
  181. package/src/component/2d/1d-tracer/Top1DChart.tsx +2 -2
  182. package/src/component/2d/1d-tracer/VerticalSliceChart.tsx +2 -2
  183. package/src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx +3 -3
  184. package/src/component/2d/ft/Contours.tsx +2 -2
  185. package/src/component/context/ScaleContext.tsx +1 -1
  186. package/src/component/elements/D3Axis.tsx +49 -67
  187. package/src/component/elements/export/ExportContent.tsx +3 -2
  188. package/src/component/elements/export/ExportOptionsModal.tsx +32 -1
  189. package/src/component/elements/export/useExportConfigurer.tsx +6 -0
  190. package/src/component/elements/print/PrintContent.tsx +6 -27
  191. package/src/component/elements/utilities/transferStyles.ts +32 -0
  192. package/src/component/hooks/useIntegralPath.ts +2 -2
  193. package/src/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.tsx +47 -57
  194. package/src/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.ts +100 -28
  195. package/src/component/panels/filtersPanel/processings_sections_panel.tsx +1 -1
  196. package/src/component/panels/multipleAnalysisPanel/AlignSpectra.tsx +128 -98
  197. package/src/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.tsx +1 -1
  198. package/src/component/toolbar/nmr_toolbar.tsx +1 -1
  199. package/src/component/utility/core_slots/core_operator_chart_svg.tsx +61 -0
  200. package/src/component/utility/core_slots/core_operator_panel_tool.tsx +9 -27
  201. package/src/component/utility/core_slots/core_operator_tool.commons.ts +63 -0
  202. package/src/component/utility/core_slots/core_operator_tool.tsx +9 -27
  203. package/src/component/utility/export.ts +34 -0
  204. package/src/data/data2d/Spectrum2D/contours.ts +40 -14
  205. package/src/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.ts +67 -0
  206. package/src/data/data2d/Spectrum2D/findBestMinContour/evaluation.ts +432 -0
  207. package/src/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.ts +431 -0
  208. package/src/data/data2d/Spectrum2D/findBestMinContour/math.ts +59 -0
  209. package/src/data/utilities/calculateSanPlot.ts +2 -1
  210. package/src/versionInfo.ts +1 -1
  211. package/lib/component/elements/export/utilities/transferDocumentStyles.d.ts +0 -2
  212. package/lib/component/elements/export/utilities/transferDocumentStyles.d.ts.map +0 -1
  213. package/lib/component/elements/export/utilities/transferDocumentStyles.js +0 -21
  214. package/lib/component/elements/export/utilities/transferDocumentStyles.js.map +0 -1
  215. package/lib/component/utility/PathBuilder.d.ts +0 -10
  216. package/lib/component/utility/PathBuilder.d.ts.map +0 -1
  217. package/lib/component/utility/PathBuilder.js +0 -38
  218. package/lib/component/utility/PathBuilder.js.map +0 -1
  219. package/src/component/elements/export/utilities/transferDocumentStyles.ts +0 -21
  220. package/src/component/utility/PathBuilder.ts +0 -41
@@ -3,6 +3,12 @@ import { units } from '@zakodium/nmrium-core';
3
3
  import { coerceNumberInput } from 'react-science/ui';
4
4
  import { z } from 'zod';
5
5
 
6
+ import { convert, convertToPixels } from '../../../../elements/export/units.js';
7
+ import {
8
+ MAX_CANVAS_AREA,
9
+ MAX_CANVAS_SIDE,
10
+ } from '../../../../utility/export.ts';
11
+
6
12
  const exportSizes: PageSizeName[] = [
7
13
  'Letter',
8
14
  'Legal',
@@ -18,40 +24,106 @@ const exportSizes: PageSizeName[] = [
18
24
  ];
19
25
  const exportLayouts: Layout[] = ['portrait', 'landscape'];
20
26
 
21
- /**
22
- * @see {import("@zakodium/nmrium-core").BaseExportSettings}
23
- */
24
- const baseExportSettings = z.object({
25
- useDefaultSettings: z.boolean(),
26
- dpi: coerceNumberInput(),
27
- });
27
+ export const MIN_DPI = 1;
28
+ export const MAX_DPI = 1200;
28
29
 
29
- /**
30
- * @see {import("@zakodium/nmrium-core").BasicExportSettings}
31
- */
32
- const basicExportSettings = z.object({
33
- mode: z.literal('basic'),
34
- ...baseExportSettings.shape,
35
- size: z.enum(exportSizes),
36
- layout: z.enum(exportLayouts),
37
- });
38
- /**
39
- * @see {import("@zakodium/nmrium-core").AdvanceExportSettings}
40
- */
41
- const advancedExportSettings = z.object({
42
- mode: z.literal('advance'),
43
- ...baseExportSettings.shape,
44
- width: coerceNumberInput(),
45
- height: coerceNumberInput(),
46
- unit: z.enum(units.map((u) => u.unit)),
47
- });
30
+ const formatNumber = (value: number) => value.toLocaleString('en-US');
31
+
32
+ /** Sizes are unit-relative (m, in, cm, px...), so the only unit-agnostic invariant is being positive. */
33
+ export const sizeField = coerceNumberInput(z.number().positive());
34
+ export const dpiField = coerceNumberInput(
35
+ z.number().int().min(MIN_DPI).max(MAX_DPI),
36
+ );
37
+
38
+ type NumberField = ReturnType<typeof coerceNumberInput>;
39
+ type Side = 'width' | 'height';
40
+
41
+ const sides: Side[] = ['width', 'height'];
42
+
43
+ /** @see {import("@zakodium/nmrium-core").BasicExportSettings} */
44
+ function basicSettings(dpi: NumberField) {
45
+ return z.object({
46
+ mode: z.literal('basic'),
47
+ useDefaultSettings: z.boolean(),
48
+ dpi,
49
+ size: z.enum(exportSizes),
50
+ layout: z.enum(exportLayouts),
51
+ });
52
+ }
53
+
54
+ /** @see {import("@zakodium/nmrium-core").AdvanceExportSettings} */
55
+ function advancedSettings(size: NumberField, dpi: NumberField) {
56
+ return z.object({
57
+ mode: z.literal('advance'),
58
+ useDefaultSettings: z.boolean(),
59
+ dpi,
60
+ width: size,
61
+ height: size,
62
+ unit: z.enum(units.map((u) => u.unit)),
63
+ });
64
+ }
65
+
66
+ type AdvancedSettings = z.output<ReturnType<typeof advancedSettings>>;
67
+
68
+ /** A canvas the browser cannot allocate makes the export fail, so the real limit is the size in pixels. */
69
+ function getSizeErrors(settings: AdvancedSettings) {
70
+ const { unit, dpi, width, height } = settings;
71
+ const pixels = {
72
+ width: convertToPixels(width, unit, dpi, { precision: 0 }),
73
+ height: convertToPixels(height, unit, dpi, { precision: 0 }),
74
+ };
75
+
76
+ function inCurrentUnit(px: number) {
77
+ if (unit === 'px') return `${formatNumber(px)} px`;
78
+ return `${convert(px, 'px', unit, dpi, { precision: 2 })} ${unit}`;
79
+ }
80
+
81
+ const errors: Partial<Record<Side, string>> = {};
82
+
83
+ for (const side of sides) {
84
+ if (pixels[side] < 1) {
85
+ errors[side] = `Too small to export. Use at least ${inCurrentUnit(1)}.`;
86
+ } else if (pixels[side] > MAX_CANVAS_SIDE) {
87
+ errors[side] =
88
+ `Too large to export. Use at most ${inCurrentUnit(MAX_CANVAS_SIDE)}.`;
89
+ }
90
+ }
91
+
92
+ const hasSideError = sides.some((side) => errors[side]);
93
+ if (!hasSideError && pixels.width * pixels.height > MAX_CANVAS_AREA) {
94
+ const message = `The export would be ${formatNumber(pixels.width)} x ${formatNumber(pixels.height)} pixels, which is too large. Try a smaller size or a lower DPI.`;
95
+ errors.width = message;
96
+ errors.height = message;
97
+ }
98
+
99
+ return errors;
100
+ }
48
101
 
49
102
  /**
50
103
  * @see {import("@zakodium/nmrium-core").ExportSettings}
51
104
  */
52
105
  export const exportSettingsValidation = z.discriminatedUnion('mode', [
53
- basicExportSettings,
54
- advancedExportSettings,
106
+ basicSettings(dpiField),
107
+ advancedSettings(sizeField, dpiField).check(({ value, issues }) => {
108
+ const errors = getSizeErrors(value);
109
+
110
+ for (const side of sides) {
111
+ const message = errors[side];
112
+ if (!message) continue;
113
+
114
+ issues.push({
115
+ code: 'custom',
116
+ input: value[side],
117
+ path: [side],
118
+ message,
119
+ });
120
+ }
121
+ }),
122
+ ]);
123
+
124
+ export const exportSettingsDecoder = z.discriminatedUnion('mode', [
125
+ basicSettings(coerceNumberInput()),
126
+ advancedSettings(coerceNumberInput(), coerceNumberInput()),
55
127
  ]);
56
128
 
57
129
  /**
@@ -103,7 +103,7 @@ export function ProcessingsSectionsPanel() {
103
103
  {operatorsUI.map((operatorUI) => (
104
104
  <CoreOperatorPanelTool
105
105
  key={operatorUI.id}
106
- operator={operatorUI}
106
+ operatorUI={operatorUI}
107
107
  activeOperatorId={selected}
108
108
  spectrum={spectrum}
109
109
  onTriggerOperation={(operation) =>
@@ -1,48 +1,41 @@
1
1
  import styled from '@emotion/styled';
2
- import { yupResolver } from '@hookform/resolvers/yup';
2
+ import { revalidateLogic } from '@tanstack/react-form';
3
3
  import type { Spectrum1D } from '@zakodium/nmrium-core';
4
4
  import { xFindClosestIndex } from 'ml-spectra-processing';
5
5
  import { useMemo } from 'react';
6
- import { useForm } from 'react-hook-form';
7
- import * as Yup from 'yup';
6
+ import { AppForm, Button, coerceNumberInput, useForm } from 'react-science/ui';
7
+ import { z } from 'zod';
8
8
 
9
9
  import { REFERENCES } from '../../../data/constants/References.js';
10
10
  import type { CalibrateOptions } from '../../../data/data1d/Spectrum1D/getReferenceShift.js';
11
11
  import { useDispatch } from '../../context/DispatchContext.js';
12
12
  import { useToaster } from '../../context/ToasterContext.js';
13
- import ActionButtons from '../../elements/ActionButtons.js';
14
- import type { LabelStyle } from '../../elements/Label.js';
15
- import Label from '../../elements/Label.js';
16
- import { NumberInput2Controller } from '../../elements/NumberInput2Controller.js';
17
- import { Select2 } from '../../elements/Select2.js';
18
13
  import useSpectraByActiveNucleus from '../../hooks/useSpectraPerNucleus.js';
19
14
  import { useEvent } from '../../utility/Events.js';
20
15
 
21
- const labelStyle: LabelStyle = {
22
- label: { flex: 4, fontWeight: '500' },
23
- wrapper: { flex: 8, display: 'flex', alignItems: 'center' },
24
- container: { padding: '5px 0' },
25
- };
26
-
27
16
  const baseList = [{ key: 1, value: 'manual', label: 'Manual' }];
28
17
 
29
18
  interface AlignSpectraProps {
30
- nucleus: any;
19
+ nucleus: string;
31
20
  onClose: () => void;
32
21
  }
33
22
 
34
- const DEFAULT_OPTIONS: CalibrateOptions = {
35
- from: -1,
36
- to: 1,
37
- nbPeaks: 1,
38
- targetX: 0,
23
+ type FormInput = z.input<typeof schemaValidation>;
24
+
25
+ const DEFAULT_OPTIONS: FormInput = {
26
+ from: '-1',
27
+ to: '1',
28
+ nbPeaks: '1',
29
+ targetX: '0',
30
+ options: 'manual',
39
31
  };
40
32
 
41
- const schemaValidation = Yup.object({
42
- from: Yup.number().required(),
43
- to: Yup.number().required(),
44
- nbPeaks: Yup.number().required(),
45
- targetX: Yup.number().required(),
33
+ const schemaValidation = z.object({
34
+ from: coerceNumberInput(),
35
+ to: coerceNumberInput(),
36
+ nbPeaks: coerceNumberInput(),
37
+ targetX: coerceNumberInput(),
38
+ options: z.string(),
46
39
  });
47
40
 
48
41
  function checkSpectra(options: CalibrateOptions, spectra: Spectrum1D[]) {
@@ -51,11 +44,14 @@ function checkSpectra(options: CalibrateOptions, spectra: Spectrum1D[]) {
51
44
  const {
52
45
  data: { x },
53
46
  } = spectrum;
47
+
54
48
  const min = x[0];
55
49
  const max = x.at(-1) as number;
50
+
56
51
  if (from < min || to > max) {
57
52
  throw new Error('Some spectra do not have data in the selected range');
58
53
  }
54
+
59
55
  if (Math.abs(xFindClosestIndex(x, from) - xFindClosestIndex(x, to)) < 10) {
60
56
  throw new Error(
61
57
  'The selected range is too small to provide accurate results',
@@ -66,18 +62,23 @@ function checkSpectra(options: CalibrateOptions, spectra: Spectrum1D[]) {
66
62
 
67
63
  function checkOptions(options: CalibrateOptions) {
68
64
  const returnedOptions = { ...options };
65
+
69
66
  if (options.from > options.to) {
70
67
  returnedOptions.to = options.from;
71
68
  returnedOptions.from = options.to;
72
69
  }
70
+
73
71
  return returnedOptions;
74
72
  }
75
73
 
76
- function getList(nucleus: any) {
77
- if (!(REFERENCES as any)?.[nucleus]) {
74
+ function getList(nucleus: string) {
75
+ const references = REFERENCES as any;
76
+
77
+ if (!references?.[nucleus]) {
78
78
  return [];
79
79
  }
80
- const list = Object.entries((REFERENCES as any)[nucleus]).map((item) => ({
80
+
81
+ const list = Object.entries(references[nucleus]).map((item) => ({
81
82
  value: item[0],
82
83
  label: item[0],
83
84
  }));
@@ -93,8 +94,9 @@ const Container = styled.div`
93
94
  padding: 10px 0 5px 20px;
94
95
 
95
96
  .body {
97
+ flex: 1;
96
98
  overflow: auto;
97
- padding: 10px 10px 25px 0;
99
+ padding: 10px 10px 25px 1px;
98
100
  }
99
101
 
100
102
  .header {
@@ -102,38 +104,54 @@ const Container = styled.div`
102
104
  font-weight: bold;
103
105
  padding: 5px 0;
104
106
  }
107
+ `;
105
108
 
106
- .footer {
107
- display: flex;
108
- padding-top: 5px;
109
- }
109
+ const Footer = styled.div`
110
+ display: flex;
111
+ flex-direction: row;
112
+ gap: 5px;
110
113
  `;
111
114
 
112
- function AlignSpectra({ onClose = () => null, nucleus }: AlignSpectraProps) {
115
+ export default function AlignSpectra(props: AlignSpectraProps) {
116
+ const { onClose = () => null, nucleus } = props;
113
117
  const spectra = useSpectraByActiveNucleus();
114
118
  const dispatch = useDispatch();
115
119
  const toaster = useToaster();
116
- const { handleSubmit, reset, control, getValues } = useForm<CalibrateOptions>(
117
- {
118
- defaultValues: DEFAULT_OPTIONS,
119
- resolver: yupResolver(schemaValidation),
120
- },
121
- );
122
120
 
123
- function submitHandler(inputOptions: any) {
124
- const options = checkOptions(inputOptions);
125
- reset(options);
126
- try {
127
- checkSpectra(options, spectra as Spectrum1D[]);
121
+ const optionList = useMemo(() => {
122
+ return getList(nucleus);
123
+ }, [nucleus]);
128
124
 
129
- dispatch({ type: 'ALIGN_SPECTRA', payload: options });
130
- onClose();
131
- } catch (error: unknown) {
132
- const message = (error as Error).message;
125
+ const form = useForm({
126
+ defaultValues: {
127
+ ...DEFAULT_OPTIONS,
128
+ options: optionList[0].value,
129
+ },
130
+ validationLogic: revalidateLogic({ mode: 'change' }),
131
+ onSubmit: ({ value, formApi }) => {
132
+ const parsed = schemaValidation.parse(value);
133
+ const options = checkOptions(parsed);
134
+
135
+ formApi.reset(
136
+ schemaValidation.encode({
137
+ ...options,
138
+ options: optionList[0].value,
139
+ }),
140
+ );
133
141
 
134
- toaster.show({ intent: 'danger', message });
135
- }
136
- }
142
+ try {
143
+ checkSpectra(options, spectra as Spectrum1D[]);
144
+ dispatch({ type: 'ALIGN_SPECTRA', payload: options });
145
+ onClose();
146
+ } catch (error: unknown) {
147
+ const message = (error as Error).message;
148
+ toaster.show({ intent: 'danger', message });
149
+ }
150
+ },
151
+ validators: {
152
+ onDynamic: schemaValidation,
153
+ },
154
+ });
137
155
 
138
156
  useEvent({
139
157
  onBrushEnd: (options) => {
@@ -141,62 +159,74 @@ function AlignSpectra({ onClose = () => null, nucleus }: AlignSpectraProps) {
141
159
  range: [from, to],
142
160
  shiftKey,
143
161
  } = options;
162
+
144
163
  if (shiftKey) {
145
- reset({ ...getValues(), from, to });
164
+ form.setFieldValue('from', String(from));
165
+ form.setFieldValue('to', String(to));
146
166
  }
147
167
  },
148
168
  });
149
169
 
150
- function optionChangeHandler({ value: key }: { value: string }) {
170
+ function optionChangeHandlerRefactor(key: string) {
151
171
  const { delta: targetX = 0, ...otherOptions } =
152
172
  (REFERENCES as any)?.[nucleus]?.[key] || {};
153
- const value = {
154
- ...DEFAULT_OPTIONS,
155
- targetX,
156
- ...otherOptions,
157
- };
158
- reset(value);
173
+
174
+ form.reset(
175
+ schemaValidation.encode({
176
+ from: otherOptions.from ?? Number(DEFAULT_OPTIONS.from),
177
+ to: otherOptions.to ?? Number(DEFAULT_OPTIONS.to),
178
+ nbPeaks: otherOptions.nbPeaks ?? Number(DEFAULT_OPTIONS.nbPeaks),
179
+ options: key,
180
+ targetX,
181
+ }),
182
+ );
159
183
  }
160
- const List = useMemo(() => getList(nucleus), [nucleus]);
161
184
 
162
185
  return (
163
- <Container>
164
- <div className="body" style={{ flex: 1 }}>
165
- <div className="header">
166
- <span>Spectra calibration</span>
186
+ <AppForm form={form} layout="inline">
187
+ <Container>
188
+ <div className="body">
189
+ <form.Section title="Spectra calibration">
190
+ <form.AppField
191
+ name="options"
192
+ listeners={{
193
+ onChange: ({ value }) => {
194
+ optionChangeHandlerRefactor(value);
195
+ },
196
+ }}
197
+ >
198
+ {(field) => <field.Select label="Options" items={optionList} />}
199
+ </form.AppField>
200
+ </form.Section>
201
+
202
+ <form.Section title="Range">
203
+ <form.AppField name="from">
204
+ {(field) => <field.NumericInput label="From" fill />}
205
+ </form.AppField>
206
+
207
+ <form.AppField name="to">
208
+ {(field) => <field.NumericInput label="To" fill />}
209
+ </form.AppField>
210
+ </form.Section>
211
+
212
+ <form.Section title="Configuration">
213
+ <form.AppField name="nbPeaks">
214
+ {(field) => <field.NumericInput label="Number of peaks" />}
215
+ </form.AppField>
216
+
217
+ <form.AppField name="targetX">
218
+ {(field) => <field.NumericInput label="Target PPM" />}
219
+ </form.AppField>
220
+ </form.Section>
167
221
  </div>
168
- <Label title="Options" style={labelStyle}>
169
- <Select2
170
- items={List}
171
- onItemSelect={optionChangeHandler}
172
- defaultSelectedItem={List[0]}
173
- />
174
- </Label>
175
-
176
- <Label title="Range" style={labelStyle}>
177
- <Label title="From">
178
- <NumberInput2Controller control={control} name="from" fill />
179
- </Label>
180
- <Label title="To" style={{ label: { padding: '0 10px' } }}>
181
- <NumberInput2Controller control={control} name="to" fill />
182
- </Label>
183
- </Label>
184
-
185
- <Label title="Number of peaks" style={labelStyle}>
186
- <NumberInput2Controller control={control} name="nbPeaks" fill />
187
- </Label>
188
- <Label title="Target PPM" style={labelStyle}>
189
- <NumberInput2Controller control={control} name="targetX" fill />
190
- </Label>
191
- </div>
192
- <div className="footer">
193
- <ActionButtons
194
- onDone={() => handleSubmit(submitHandler)()}
195
- onCancel={onClose}
196
- />
197
- </div>
198
- </Container>
222
+ <Footer>
223
+ <form.SubmitButton intent="success">Apply</form.SubmitButton>
224
+
225
+ <Button intent="danger" variant="outlined" onClick={onClose}>
226
+ Cancel
227
+ </Button>
228
+ </Footer>
229
+ </Container>
230
+ </AppForm>
199
231
  );
200
232
  }
201
-
202
- export default AlignSpectra;
@@ -148,7 +148,7 @@ function MultipleSpectraAnalysisPanelInner({
148
148
  onClose={settingsPanelHandler}
149
149
  />
150
150
  )}
151
- <div className="inner-container">
151
+ <div>
152
152
  {isFlipped ? (
153
153
  <MultipleSpectraAnalysisPreferences
154
154
  data={spectraAnalysis}
@@ -536,7 +536,7 @@ export default function NMRToolbar() {
536
536
  pluginTools.map((operatorUI) => (
537
537
  <CoreOperatorTool
538
538
  key={operatorUI.id}
539
- operator={operatorUI}
539
+ operatorUI={operatorUI}
540
540
  spectrum={stableSpectrum}
541
541
  activeOperatorId={activeOperatorId}
542
542
  onTriggerOperation={(operation) => {
@@ -0,0 +1,61 @@
1
+ import type { ProcessingOperatorId } from '@zakodium/nmr-types';
2
+ import type {
3
+ ProcessingOperatorUI,
4
+ ProcessingOperatorUIChartSVGProps,
5
+ } from '@zakodium/nmrium-core';
6
+ import { useEffect } from 'react';
7
+ import type { FallbackProps } from 'react-error-boundary';
8
+ import { ErrorBoundary } from 'react-error-boundary';
9
+
10
+ interface CoreOperatorChartSVGProps extends ProcessingOperatorUIChartSVGProps<ProcessingOperatorId> {
11
+ operatorUI: ProcessingOperatorUI<ProcessingOperatorId>;
12
+ }
13
+
14
+ export function CoreOperatorChartSVG(props: CoreOperatorChartSVGProps) {
15
+ const {
16
+ operatorUI,
17
+ core,
18
+ spectrum,
19
+ operation,
20
+ height,
21
+ width,
22
+ margin,
23
+ indicatorLineColor,
24
+ scaleX,
25
+ scaleY,
26
+ } = props;
27
+
28
+ const { ChartSVG } = operatorUI;
29
+ if (!ChartSVG) return null;
30
+
31
+ return (
32
+ <ErrorBoundary FallbackComponent={LogError}>
33
+ <ChartSVG
34
+ core={core}
35
+ spectrum={spectrum}
36
+ operation={operation}
37
+ height={height}
38
+ width={width}
39
+ margin={margin}
40
+ scaleX={scaleX}
41
+ scaleY={scaleY}
42
+ indicatorLineColor={indicatorLineColor}
43
+ />
44
+ </ErrorBoundary>
45
+ );
46
+ }
47
+
48
+ /**
49
+ * SVG context. No friendly error rendering method.
50
+ *
51
+ * @param props
52
+ */
53
+ function LogError(props: FallbackProps) {
54
+ const { error } = props;
55
+
56
+ useEffect(() => {
57
+ reportError(error);
58
+ }, [error]);
59
+
60
+ return null;
61
+ }
@@ -1,41 +1,23 @@
1
- import type { ProcessingOperatorId } from '@zakodium/nmr-types';
2
- import type {
3
- ProcessingOperatorUI,
4
- ProcessingOperatorUIToolProps,
5
- } from '@zakodium/nmrium-core';
6
- import type { PartialPick } from '@zakodium/utils';
7
1
  import { ErrorBoundary } from 'react-error-boundary';
8
2
 
9
- import { useCore } from '../../context/CoreContext.tsx';
10
3
  import { ToolbarItemError } from '../toolbar_item_error.tsx';
11
4
 
12
- interface CoreOperatorPanelToolProps {
13
- operator: ProcessingOperatorUI<ProcessingOperatorId>;
14
- }
5
+ import type { CoreOperatorToolProps } from './core_operator_tool.commons.ts';
6
+ import { useToolProps } from './core_operator_tool.commons.ts';
15
7
 
16
- export function CoreOperatorPanelTool(
17
- props: PartialPick<
18
- Omit<ProcessingOperatorUIToolProps<ProcessingOperatorId>, 'core'>,
19
- 'spectrum'
20
- > &
21
- CoreOperatorPanelToolProps,
22
- ) {
23
- const { spectrum, activeOperatorId, onTriggerOperation, operator } = props;
24
- const core = useCore();
8
+ export function CoreOperatorPanelTool(props: CoreOperatorToolProps) {
9
+ const { spectrum, operatorUI } = props;
10
+ const toolProps = useToolProps(props);
25
11
 
26
12
  if (!spectrum) return null;
27
- if (!operator.PanelTool) return null;
13
+ if (!toolProps) return null;
14
+ if (!operatorUI.PanelTool) return null;
28
15
 
29
- const { PanelTool } = operator;
16
+ const { PanelTool } = operatorUI;
30
17
 
31
18
  return (
32
19
  <ErrorBoundary FallbackComponent={ToolbarItemError}>
33
- <PanelTool
34
- core={core}
35
- spectrum={spectrum}
36
- activeOperatorId={activeOperatorId}
37
- onTriggerOperation={onTriggerOperation}
38
- />
20
+ <PanelTool {...toolProps} />
39
21
  </ErrorBoundary>
40
22
  );
41
23
  }
@@ -0,0 +1,63 @@
1
+ import type {
2
+ ProcessingOperatorId,
3
+ SpectrumProcessingOperation,
4
+ } from '@zakodium/nmr-types';
5
+ import type {
6
+ ProcessingOperatorUI,
7
+ ProcessingOperatorUIToolProps,
8
+ } from '@zakodium/nmrium-core';
9
+ import { generateID } from '@zakodium/nmrium-core';
10
+ import type { PartialPick } from '@zakodium/utils';
11
+ import { assertDefined, assertNotNullish } from '@zakodium/utils';
12
+ import { useEventCallback } from 'usehooks-ts';
13
+
14
+ import { useCore } from '../../context/CoreContext.tsx';
15
+
16
+ interface CoreOperatorToolExtraProps {
17
+ operatorUI: ProcessingOperatorUI<ProcessingOperatorId>;
18
+ onTriggerOperation: (
19
+ operation: SpectrumProcessingOperation<any, any>,
20
+ ) => void;
21
+ }
22
+
23
+ export type CoreOperatorToolProps = PartialPick<
24
+ Omit<ProcessingOperatorUIToolProps, 'core' | 'onTriggerOperation'>,
25
+ 'spectrum'
26
+ > &
27
+ CoreOperatorToolExtraProps;
28
+
29
+ export function useToolProps(
30
+ props: CoreOperatorToolProps,
31
+ ): ProcessingOperatorUIToolProps | null {
32
+ const {
33
+ spectrum,
34
+ activeOperatorId,
35
+ onTriggerOperation: onTriggerOperationProp,
36
+ operatorUI,
37
+ } = props;
38
+ const core = useCore();
39
+
40
+ const onTriggerOperation = useEventCallback(() => {
41
+ const operator = core.getOperator(operatorUI.id);
42
+ assertNotNullish(operator);
43
+ assertDefined(spectrum);
44
+
45
+ onTriggerOperationProp({
46
+ operatorId: operatorUI.id,
47
+ uid: generateID(),
48
+ settings: operator.getDefaultSettings(spectrum),
49
+ options: undefined,
50
+ enabled: true,
51
+ error: undefined,
52
+ });
53
+ });
54
+
55
+ if (!spectrum) return null;
56
+
57
+ return {
58
+ core,
59
+ spectrum,
60
+ activeOperatorId,
61
+ onTriggerOperation,
62
+ };
63
+ }