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.
- package/lib/component/1d/ApodizationLine.js +2 -2
- package/lib/component/1d/ApodizationLine.js.map +1 -1
- package/lib/component/1d/Line.js +2 -2
- package/lib/component/1d/Line.js.map +1 -1
- package/lib/component/1d/SVGContent1D.d.ts.map +1 -1
- package/lib/component/1d/SVGContent1D.js +4 -1
- package/lib/component/1d/SVGContent1D.js.map +1 -1
- package/lib/component/1d/baseline/BaselinePreview.js +2 -2
- package/lib/component/1d/baseline/BaselinePreview.js.map +1 -1
- package/lib/component/1d/database/DatabaseSpectrum.js +2 -2
- package/lib/component/1d/database/DatabaseSpectrum.js.map +1 -1
- package/lib/component/1d/database/ResurrectedDatabaseRanges.js +2 -2
- package/lib/component/1d/database/ResurrectedDatabaseRanges.js.map +1 -1
- package/lib/component/1d/matrix/Boxplot.js +5 -5
- package/lib/component/1d/matrix/Boxplot.js.map +1 -1
- package/lib/component/1d/matrix/Stocsy.js +2 -2
- package/lib/component/1d/matrix/Stocsy.js.map +1 -1
- package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.d.ts.map +1 -1
- package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.js +12 -3
- package/lib/component/1d/peaks/PeakAnnotationsSpreadMode.js.map +1 -1
- package/lib/component/1d/peaks/usePeakShapesPath.js +2 -2
- package/lib/component/1d/peaks/usePeakShapesPath.js.map +1 -1
- package/lib/component/1d/plugin_svg_chart.d.ts +2 -0
- package/lib/component/1d/plugin_svg_chart.d.ts.map +1 -0
- package/lib/component/1d/plugin_svg_chart.js +43 -0
- package/lib/component/1d/plugin_svg_chart.js.map +1 -0
- package/lib/component/1d-2d/components/RangeIndicator.d.ts.map +1 -1
- package/lib/component/1d-2d/components/RangeIndicator.js +1 -7
- package/lib/component/1d-2d/components/RangeIndicator.js.map +1 -1
- package/lib/component/2d/1d-tracer/HorizontalSliceChart.js +2 -2
- package/lib/component/2d/1d-tracer/HorizontalSliceChart.js.map +1 -1
- package/lib/component/2d/1d-tracer/Left1DChart.js +2 -2
- package/lib/component/2d/1d-tracer/Left1DChart.js.map +1 -1
- package/lib/component/2d/1d-tracer/Top1DChart.js +2 -2
- package/lib/component/2d/1d-tracer/Top1DChart.js.map +1 -1
- package/lib/component/2d/1d-tracer/VerticalSliceChart.js +2 -2
- package/lib/component/2d/1d-tracer/VerticalSliceChart.js.map +1 -1
- package/lib/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.js +3 -3
- package/lib/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.js.map +1 -1
- package/lib/component/2d/ft/Contours.js +2 -2
- package/lib/component/2d/ft/Contours.js.map +1 -1
- package/lib/component/context/ScaleContext.d.ts +1 -1
- package/lib/component/context/ScaleContext.d.ts.map +1 -1
- package/lib/component/elements/D3Axis.d.ts.map +1 -1
- package/lib/component/elements/D3Axis.js +15 -32
- package/lib/component/elements/D3Axis.js.map +1 -1
- package/lib/component/elements/export/ExportContent.d.ts.map +1 -1
- package/lib/component/elements/export/ExportContent.js +2 -2
- package/lib/component/elements/export/ExportContent.js.map +1 -1
- package/lib/component/elements/export/ExportOptionsModal.d.ts.map +1 -1
- package/lib/component/elements/export/ExportOptionsModal.js +9 -3
- package/lib/component/elements/export/ExportOptionsModal.js.map +1 -1
- package/lib/component/elements/export/useExportConfigurer.d.ts +1 -0
- package/lib/component/elements/export/useExportConfigurer.d.ts.map +1 -1
- package/lib/component/elements/export/useExportConfigurer.js +5 -0
- package/lib/component/elements/export/useExportConfigurer.js.map +1 -1
- package/lib/component/elements/print/PrintContent.d.ts.map +1 -1
- package/lib/component/elements/print/PrintContent.js +6 -25
- package/lib/component/elements/print/PrintContent.js.map +1 -1
- package/lib/component/elements/utilities/transferStyles.d.ts +2 -0
- package/lib/component/elements/utilities/transferStyles.d.ts.map +1 -0
- package/lib/component/elements/utilities/transferStyles.js +29 -0
- package/lib/component/elements/utilities/transferStyles.js.map +1 -0
- package/lib/component/hooks/useIntegralPath.js +2 -2
- package/lib/component/hooks/useIntegralPath.js.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/errors/context.d.ts +106 -105
- package/lib/component/modal/setting/tanstack_general_settings/errors/context.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/errors/renderer.d.ts +106 -105
- package/lib/component/modal/setting/tanstack_general_settings/errors/renderer.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_body.d.ts +106 -105
- package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_body.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_footer.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_footer.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_header.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/general_settings_dialog_header.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/hooks/use_safe_workspace.d.ts +15 -15
- package/lib/component/modal/setting/tanstack_general_settings/tabs/auto_processing_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/auto_processing_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/axis_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/axis_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/database_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/database_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.d.ts +12 -10
- package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.js +32 -40
- package/lib/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.js.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/external_api_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/external_api_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/general_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/general_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/import_filters_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/import_filters_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/nuclei_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/nuclei_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/panels_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/panels_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_colors_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_colors_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_label_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/spectra_label_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/title_block_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/title_block_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/tabs/tools_tab.d.ts +91 -90
- package/lib/component/modal/setting/tanstack_general_settings/tabs/tools_tab.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.d.ts +61 -17
- package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.d.ts.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.js +79 -28
- package/lib/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.js.map +1 -1
- package/lib/component/modal/setting/tanstack_general_settings/validation.d.ts +15 -15
- package/lib/component/panels/filtersPanel/processings_sections_panel.js +1 -1
- package/lib/component/panels/filtersPanel/processings_sections_panel.js.map +1 -1
- package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.d.ts +3 -3
- package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.d.ts.map +1 -1
- package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js +69 -56
- package/lib/component/panels/multipleAnalysisPanel/AlignSpectra.js.map +1 -1
- package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js +1 -1
- package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js.map +1 -1
- package/lib/component/toolbar/nmr_toolbar.js +1 -1
- package/lib/component/toolbar/nmr_toolbar.js.map +1 -1
- package/lib/component/utility/core_slots/core_operator_chart_svg.d.ts +8 -0
- package/lib/component/utility/core_slots/core_operator_chart_svg.d.ts.map +1 -0
- package/lib/component/utility/core_slots/core_operator_chart_svg.js +23 -0
- package/lib/component/utility/core_slots/core_operator_chart_svg.js.map +1 -0
- package/lib/component/utility/core_slots/core_operator_panel_tool.d.ts +2 -8
- package/lib/component/utility/core_slots/core_operator_panel_tool.d.ts.map +1 -1
- package/lib/component/utility/core_slots/core_operator_panel_tool.js +8 -6
- package/lib/component/utility/core_slots/core_operator_panel_tool.js.map +1 -1
- package/lib/component/utility/core_slots/core_operator_tool.commons.d.ts +11 -0
- package/lib/component/utility/core_slots/core_operator_tool.commons.d.ts.map +1 -0
- package/lib/component/utility/core_slots/core_operator_tool.commons.js +30 -0
- package/lib/component/utility/core_slots/core_operator_tool.commons.js.map +1 -0
- package/lib/component/utility/core_slots/core_operator_tool.d.ts +2 -8
- package/lib/component/utility/core_slots/core_operator_tool.d.ts.map +1 -1
- package/lib/component/utility/core_slots/core_operator_tool.js +8 -6
- package/lib/component/utility/core_slots/core_operator_tool.js.map +1 -1
- package/lib/component/utility/export.d.ts +5 -0
- package/lib/component/utility/export.d.ts.map +1 -1
- package/lib/component/utility/export.js +22 -0
- package/lib/component/utility/export.js.map +1 -1
- package/lib/data/data2d/Spectrum2D/contours.d.ts.map +1 -1
- package/lib/data/data2d/Spectrum2D/contours.js +23 -10
- package/lib/data/data2d/Spectrum2D/contours.js.map +1 -1
- package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.d.ts +13 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.d.ts.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.js +40 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.js.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.d.ts +27 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.d.ts.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.js +230 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/evaluation.js.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.d.ts +227 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.d.ts.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.js +67 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.js.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/math.d.ts +4 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/math.d.ts.map +1 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/math.js +42 -0
- package/lib/data/data2d/Spectrum2D/findBestMinContour/math.js.map +1 -0
- package/lib/data/utilities/calculateSanPlot.d.ts +3 -1
- package/lib/data/utilities/calculateSanPlot.d.ts.map +1 -1
- package/lib/data/utilities/calculateSanPlot.js +2 -2
- package/lib/data/utilities/calculateSanPlot.js.map +1 -1
- package/lib/versionInfo.js +1 -1
- package/package.json +5 -5
- package/src/component/1d/ApodizationLine.tsx +2 -2
- package/src/component/1d/Line.tsx +2 -2
- package/src/component/1d/SVGContent1D.tsx +6 -0
- package/src/component/1d/baseline/BaselinePreview.tsx +2 -2
- package/src/component/1d/database/DatabaseSpectrum.tsx +2 -2
- package/src/component/1d/database/ResurrectedDatabaseRanges.tsx +2 -2
- package/src/component/1d/matrix/Boxplot.tsx +5 -5
- package/src/component/1d/matrix/Stocsy.tsx +2 -2
- package/src/component/1d/peaks/PeakAnnotationsSpreadMode.tsx +17 -3
- package/src/component/1d/peaks/usePeakShapesPath.ts +2 -2
- package/src/component/1d/plugin_svg_chart.tsx +60 -0
- package/src/component/1d-2d/components/RangeIndicator.tsx +8 -9
- package/src/component/2d/1d-tracer/HorizontalSliceChart.tsx +2 -2
- package/src/component/2d/1d-tracer/Left1DChart.tsx +2 -2
- package/src/component/2d/1d-tracer/Top1DChart.tsx +2 -2
- package/src/component/2d/1d-tracer/VerticalSliceChart.tsx +2 -2
- package/src/component/2d/1d-tracer/phase-correction-traces/SpectrumPhaseTrace.tsx +3 -3
- package/src/component/2d/ft/Contours.tsx +2 -2
- package/src/component/context/ScaleContext.tsx +1 -1
- package/src/component/elements/D3Axis.tsx +49 -67
- package/src/component/elements/export/ExportContent.tsx +3 -2
- package/src/component/elements/export/ExportOptionsModal.tsx +32 -1
- package/src/component/elements/export/useExportConfigurer.tsx +6 -0
- package/src/component/elements/print/PrintContent.tsx +6 -27
- package/src/component/elements/utilities/transferStyles.ts +32 -0
- package/src/component/hooks/useIntegralPath.ts +2 -2
- package/src/component/modal/setting/tanstack_general_settings/tabs/export_tab.fields.tsx +47 -57
- package/src/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.ts +100 -28
- package/src/component/panels/filtersPanel/processings_sections_panel.tsx +1 -1
- package/src/component/panels/multipleAnalysisPanel/AlignSpectra.tsx +128 -98
- package/src/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.tsx +1 -1
- package/src/component/toolbar/nmr_toolbar.tsx +1 -1
- package/src/component/utility/core_slots/core_operator_chart_svg.tsx +61 -0
- package/src/component/utility/core_slots/core_operator_panel_tool.tsx +9 -27
- package/src/component/utility/core_slots/core_operator_tool.commons.ts +63 -0
- package/src/component/utility/core_slots/core_operator_tool.tsx +9 -27
- package/src/component/utility/export.ts +34 -0
- package/src/data/data2d/Spectrum2D/contours.ts +40 -14
- package/src/data/data2d/Spectrum2D/findBestMinContour/estimateNoiseLevel.ts +67 -0
- package/src/data/data2d/Spectrum2D/findBestMinContour/evaluation.ts +432 -0
- package/src/data/data2d/Spectrum2D/findBestMinContour/findAutomaticContourLevels.ts +431 -0
- package/src/data/data2d/Spectrum2D/findBestMinContour/math.ts +59 -0
- package/src/data/utilities/calculateSanPlot.ts +2 -1
- package/src/versionInfo.ts +1 -1
- package/lib/component/elements/export/utilities/transferDocumentStyles.d.ts +0 -2
- package/lib/component/elements/export/utilities/transferDocumentStyles.d.ts.map +0 -1
- package/lib/component/elements/export/utilities/transferDocumentStyles.js +0 -21
- package/lib/component/elements/export/utilities/transferDocumentStyles.js.map +0 -1
- package/lib/component/utility/PathBuilder.d.ts +0 -10
- package/lib/component/utility/PathBuilder.d.ts.map +0 -1
- package/lib/component/utility/PathBuilder.js +0 -38
- package/lib/component/utility/PathBuilder.js.map +0 -1
- package/src/component/elements/export/utilities/transferDocumentStyles.ts +0 -21
- package/src/component/utility/PathBuilder.ts +0 -41
package/src/component/modal/setting/tanstack_general_settings/validation/export_tab_validation.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
31
|
-
*/
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
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 {
|
|
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-
|
|
7
|
-
import
|
|
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:
|
|
19
|
+
nucleus: string;
|
|
31
20
|
onClose: () => void;
|
|
32
21
|
}
|
|
33
22
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 =
|
|
42
|
-
from:
|
|
43
|
-
to:
|
|
44
|
-
nbPeaks:
|
|
45
|
-
targetX:
|
|
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:
|
|
77
|
-
|
|
74
|
+
function getList(nucleus: string) {
|
|
75
|
+
const references = REFERENCES as any;
|
|
76
|
+
|
|
77
|
+
if (!references?.[nucleus]) {
|
|
78
78
|
return [];
|
|
79
79
|
}
|
|
80
|
-
|
|
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
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
const Footer = styled.div`
|
|
110
|
+
display: flex;
|
|
111
|
+
flex-direction: row;
|
|
112
|
+
gap: 5px;
|
|
110
113
|
`;
|
|
111
114
|
|
|
112
|
-
function AlignSpectra(
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
checkSpectra(options, spectra as Spectrum1D[]);
|
|
121
|
+
const optionList = useMemo(() => {
|
|
122
|
+
return getList(nucleus);
|
|
123
|
+
}, [nucleus]);
|
|
128
124
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
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
|
-
|
|
164
|
+
form.setFieldValue('from', String(from));
|
|
165
|
+
form.setFieldValue('to', String(to));
|
|
146
166
|
}
|
|
147
167
|
},
|
|
148
168
|
});
|
|
149
169
|
|
|
150
|
-
function
|
|
170
|
+
function optionChangeHandlerRefactor(key: string) {
|
|
151
171
|
const { delta: targetX = 0, ...otherOptions } =
|
|
152
172
|
(REFERENCES as any)?.[nucleus]?.[key] || {};
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
<
|
|
164
|
-
<
|
|
165
|
-
<div className="
|
|
166
|
-
<
|
|
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
|
-
<
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
</
|
|
175
|
-
|
|
176
|
-
|
|
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;
|
|
@@ -536,7 +536,7 @@ export default function NMRToolbar() {
|
|
|
536
536
|
pluginTools.map((operatorUI) => (
|
|
537
537
|
<CoreOperatorTool
|
|
538
538
|
key={operatorUI.id}
|
|
539
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
|
18
|
-
|
|
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 (!
|
|
13
|
+
if (!toolProps) return null;
|
|
14
|
+
if (!operatorUI.PanelTool) return null;
|
|
28
15
|
|
|
29
|
-
const { PanelTool } =
|
|
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
|
+
}
|