nmrium 0.53.0 → 0.55.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/Viewer1D.js +48 -17
- package/lib/component/1d/XAxis.js +1 -1
- package/lib/component/1d/integral/IntegralsSeries.js +2 -2
- package/lib/component/1d/integral/Integration.d.ts +3 -1
- package/lib/component/1d/integral/Integration.js +3 -2
- package/lib/component/1d/peaks/PeakEditionManager.js +5 -3
- package/lib/component/1d/ranges/AssignmentActionsButtons.d.ts +1 -0
- package/lib/component/1d/ranges/AssignmentActionsButtons.js +3 -3
- package/lib/component/1d/ranges/AssignmentLabel.d.ts +1 -1
- package/lib/component/1d/ranges/AssignmentLabel.js +31 -4
- package/lib/component/1d/ranges/Atoms.js +4 -5
- package/lib/component/1d/ranges/Range.js +62 -12
- package/lib/component/1d/ranges/Ranges.js +2 -1
- package/lib/component/1d/ranges/RangesIntegrals.js +11 -4
- package/lib/component/1d/tool/XLabelPointer.js +4 -12
- package/lib/component/1d-2d/FieldEdition.d.ts +13 -0
- package/lib/component/1d-2d/FieldEdition.js +42 -0
- package/lib/component/2d/Chart2D.js +5 -3
- package/lib/component/2d/tools/XYLabelPointer.js +3 -9
- package/lib/component/2d/zones/Zone.js +18 -2
- package/lib/component/2d/zones/ZonesAssignmentsLabels.d.ts +7 -0
- package/lib/component/2d/zones/ZonesAssignmentsLabels.js +286 -0
- package/lib/component/EventsTrackers/KeysListenerTracker.js +14 -1
- package/lib/component/context/LoggerContext.js +11 -4
- package/lib/component/context/ShareDataContext.d.ts +10 -0
- package/lib/component/context/ShareDataContext.js +22 -0
- package/lib/component/elements/ActionsButtonsPopover.d.ts +10 -0
- package/lib/component/elements/ActionsButtonsPopover.js +22 -0
- package/lib/component/elements/CloseButton.d.ts +1 -1
- package/lib/component/elements/CustomToolTip.d.ts +8 -0
- package/lib/component/elements/CustomToolTip.js +107 -0
- package/lib/component/elements/EditableColumn.js +3 -2
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +7 -5
- package/lib/component/elements/ReactTable/ReactTable.d.ts +2 -2
- package/lib/component/elements/SVGButton.d.ts +14 -0
- package/lib/component/elements/SVGButton.js +6 -0
- package/lib/component/elements/SVGGroup.js +15 -13
- package/lib/component/elements/SVGText.d.ts +8 -0
- package/lib/component/elements/SVGText.js +24 -0
- package/lib/component/elements/SaveButton.d.ts +1 -1
- package/lib/component/elements/draggable/SVGDraggable.d.ts +2 -2
- package/lib/component/elements/formik/FormikError.js +2 -4
- package/lib/component/elements/formik/FormikInput.d.ts +2 -1
- package/lib/component/elements/formik/FormikInput.js +5 -4
- package/lib/component/header/Header.js +8 -11
- package/lib/component/header/PhaseCorrectionTwoDimensionsPanel.js +41 -10
- package/lib/component/hooks/useActiveSpectrumZonesViewState.js +1 -0
- package/lib/component/hooks/useCheckPointsNumberInWindowArea.d.ts +1 -1
- package/lib/component/hooks/useFormatNumberByNucleus.d.ts +1 -1
- package/lib/component/hooks/useFormatNumberByNucleus.js +8 -7
- package/lib/component/hooks/useIntegralPath.d.ts +2 -0
- package/lib/component/hooks/useIntegralPath.js +3 -1
- package/lib/component/hooks/usePanelPreferences.js +1 -2
- package/lib/component/hooks/useSaveSettings.js +7 -14
- package/lib/component/hooks/useTriggerNewAssignmentLabel.d.ts +4 -0
- package/lib/component/hooks/useTriggerNewAssignmentLabel.js +8 -0
- package/lib/component/hooks/useWorkspaceAction.d.ts +7 -0
- package/lib/component/hooks/useWorkspaceAction.js +89 -0
- package/lib/component/loader/DropZone.js +0 -3
- package/lib/component/main/InnerNMRium.js +3 -1
- package/lib/component/main/InnerNMRiumContents.js +14 -2
- package/lib/component/main/NMRiumStateProvider.js +15 -3
- package/lib/component/modal/AboutPredictionModal.js +1 -1
- package/lib/component/modal/AboutSpectrumSimulationModal.js +1 -1
- package/lib/component/modal/CopyClipboardModal.js +1 -1
- package/lib/component/modal/EditPeakShapeModal.js +1 -1
- package/lib/component/modal/ImportPublicationStringModal.js +11 -5
- package/lib/component/modal/PredictSpectraModal.js +1 -1
- package/lib/component/modal/aboutUs/AboutUsModal.js +1 -1
- package/lib/component/modal/changeSum/ChangeSumModal.js +1 -1
- package/lib/component/modal/editRange/EditRangeModal.js +1 -1
- package/lib/component/modal/editRange/forms/components/DeltaInput.js +3 -3
- package/lib/component/modal/editRange/forms/components/NewSignalTab.js +17 -12
- package/lib/component/modal/editRange/forms/components/signal-tabs/SignalJCouplingsTable.js +30 -13
- package/lib/component/modal/editRange/forms/components/signal-tabs/SignalPeaksTable.js +26 -16
- package/lib/component/modal/editZone/EditZoneModal.js +1 -1
- package/lib/component/modal/setting/GeneralSettings.js +18 -39
- package/lib/component/modal/setting/WorkspaceItem.js +1 -1
- package/lib/component/modal/setting/settings-tabs/NucleiTabContent.d.ts +2 -0
- package/lib/component/modal/setting/settings-tabs/NucleiTabContent.js +99 -0
- package/lib/component/modal/setting/settingsValidation.js +36 -40
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignment.js +2 -2
- package/lib/component/panels/IntegralsPanel/IntegralPanel.js +2 -2
- package/lib/component/panels/MatrixGenerationPanel/MatrixGenerationPanel.js +2 -2
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +1 -1
- package/lib/component/panels/PeaksPanel/PeaksPanel.js +5 -5
- package/lib/component/panels/RangesPanel/RangesHeader.js +11 -11
- package/lib/component/panels/RangesPanel/RangesPreferences.js +16 -16
- package/lib/component/panels/RangesPanel/RangesTable.js +1 -1
- package/lib/component/panels/RangesPanel/RangesTableRow.js +2 -2
- package/lib/component/panels/SpectraPanel/SpectraPanelHeader.js +22 -8
- package/lib/component/panels/SpectraPanel/SpectraPreferences.js +13 -1
- package/lib/component/panels/SpectraPanel/base/setting/PlotChart.js +1 -1
- package/lib/component/panels/SpectraPanel/base/setting/Spectrum2DHistogram.js +1 -1
- package/lib/component/panels/SummaryPanel/CorrelationTable/editLink/EditLinkModal.js +1 -1
- package/lib/component/panels/SummaryPanel/SetMolecularFormulaModal.d.ts +5 -5
- package/lib/component/panels/SummaryPanel/SetMolecularFormulaModal.js +79 -89
- package/lib/component/panels/SummaryPanel/SetShiftTolerancesModal.d.ts +5 -4
- package/lib/component/panels/SummaryPanel/SetShiftTolerancesModal.js +66 -98
- package/lib/component/panels/SummaryPanel/SummaryPanel.js +13 -32
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentLabelColumn.d.ts +6 -0
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentLabelColumn.js +16 -0
- package/lib/component/panels/ZonesPanel/ZonesPanel.js +22 -6
- package/lib/component/panels/ZonesPanel/ZonesPreferences.js +15 -9
- package/lib/component/panels/ZonesPanel/ZonesTable.js +2 -2
- package/lib/component/panels/ZonesPanel/ZonesTableRow.js +3 -2
- package/lib/component/panels/databasePanel/DatabaseSearchOptions.js +2 -2
- package/lib/component/panels/header/DefaultPanelHeader.js +2 -2
- package/lib/component/panels/header/PreferencesHeader.js +1 -1
- package/lib/component/panels/header/SpectraAutomaticPickingButton.js +1 -1
- package/lib/component/panels/multipleAnalysisPanel/MultipleSpectraAnalysisPanel.js +4 -4
- package/lib/component/panels/multipleAnalysisPanel/preferences/index.js +1 -1
- package/lib/component/reducer/IgnoreActions.js +1 -0
- package/lib/component/reducer/Reducer.js +8 -0
- package/lib/component/reducer/actions/DomainActions.d.ts +7 -2
- package/lib/component/reducer/actions/DomainActions.js +29 -1
- package/lib/component/reducer/actions/FiltersActions.d.ts +3 -2
- package/lib/component/reducer/actions/FiltersActions.js +27 -1
- package/lib/component/reducer/actions/MoleculeActions.js +1 -1
- package/lib/component/reducer/actions/RangesActions.d.ts +2 -3
- package/lib/component/reducer/actions/RangesActions.js +28 -26
- package/lib/component/reducer/actions/SpectraActions.d.ts +5 -4
- package/lib/component/reducer/actions/SpectraActions.js +5 -1
- package/lib/component/reducer/actions/ZonesActions.d.ts +15 -2
- package/lib/component/reducer/actions/ZonesActions.js +47 -13
- package/lib/component/reducer/helper/setRangesViewProperty.d.ts +1 -0
- package/lib/component/reducer/helper/setRangesViewProperty.js +11 -11
- package/lib/component/reducer/preferences/actions/addWorkspace.js +4 -23
- package/lib/component/reducer/preferences/actions/analyzeSpectra.js +4 -4
- package/lib/component/reducer/preferences/actions/initPreferences.js +2 -4
- package/lib/component/reducer/preferences/actions/matrixGeneration.js +3 -3
- package/lib/component/reducer/preferences/actions/removeWorkspace.js +0 -5
- package/lib/component/reducer/preferences/actions/setActiveWorkspace.js +0 -4
- package/lib/component/reducer/preferences/actions/setPanelsPreferences.js +1 -1
- package/lib/component/reducer/preferences/actions/setPreferences.js +2 -16
- package/lib/component/reducer/preferences/actions/setWorkspace.js +4 -3
- package/lib/component/reducer/preferences/preferencesReducer.d.ts +7 -0
- package/lib/component/reducer/preferences/preferencesReducer.js +21 -18
- package/lib/component/toolbar/ToolBar.js +115 -25
- package/lib/component/utility/PreferencesHelper.js +5 -4
- package/lib/component/utility/export.js +4 -0
- package/lib/component/workspaces/assignment.js +0 -1
- package/lib/component/workspaces/basic.js +0 -1
- package/lib/component/workspaces/embedded.js +0 -1
- package/lib/component/workspaces/exercise.js +26 -29
- package/lib/component/workspaces/prediction.js +171 -174
- package/lib/component/workspaces/process1D.js +0 -1
- package/lib/component/workspaces/simulation.js +35 -38
- package/lib/component/workspaces/workspaceDefaultProperties.js +16 -23
- package/lib/data/data1d/Spectrum1D/get1DColor.d.ts +10 -3
- package/lib/data/data1d/Spectrum1D/get1DColor.js +28 -2
- package/lib/data/data1d/Spectrum1D/index.d.ts +2 -2
- package/lib/data/data1d/Spectrum1D/index.js +2 -2
- package/lib/data/data1d/Spectrum1D/ranges/createRange.d.ts +50 -0
- package/lib/data/data1d/Spectrum1D/ranges/createRange.js +51 -0
- package/lib/data/data1d/Spectrum1D/ranges/detectSignals.d.ts +2 -1
- package/lib/data/data1d/Spectrum1D/ranges/detectSignals.js +4 -2
- package/lib/data/data1d/Spectrum1D/ranges/resizeRange.d.ts +52 -0
- package/lib/data/data1d/Spectrum1D/ranges/resizeRange.js +28 -0
- package/lib/data/data2d/Spectrum2D/get2DColor.d.ts +11 -3
- package/lib/data/data2d/Spectrum2D/get2DColor.js +20 -4
- package/lib/data/data2d/Spectrum2D/getSlice.js +1 -1
- package/lib/data/data2d/Spectrum2D/zones/detectZonesManual.d.ts +1 -0
- package/lib/data/data2d/Spectrum2D/zones/initiateZones.d.ts +1 -0
- package/lib/data/utilities/generateColor.d.ts +7 -3
- package/lib/data/utilities/generateColor.js +5 -17
- package/lib/versionInfo.js +1 -1
- package/package.json +35 -35
- package/lib/component/elements/MolecularFormulaInput.d.ts +0 -6
- package/lib/component/elements/MolecularFormulaInput.js +0 -63
- package/lib/component/modal/setting/settings-tabs/FormattingTabContent.d.ts +0 -2
- package/lib/component/modal/setting/settings-tabs/FormattingTabContent.js +0 -80
- package/lib/component/reducer/preferences/utilities/mapNucleiFormatting.d.ts +0 -2
- package/lib/component/reducer/preferences/utilities/mapNucleiFormatting.js +0 -10
- package/lib/data/data1d/Spectrum1D/ranges/addRange.d.ts +0 -7
- package/lib/data/data1d/Spectrum1D/ranges/addRange.js +0 -31
- package/lib/data/data1d/Spectrum1D/ranges/changeRange.d.ts +0 -3
- package/lib/data/data1d/Spectrum1D/ranges/changeRange.js +0 -32
|
@@ -51,17 +51,19 @@ function ReactTableRow(props) {
|
|
|
51
51
|
const clickHandler = useCallback((event) => {
|
|
52
52
|
onClick?.(event, row);
|
|
53
53
|
}, [onClick, row]);
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const { key: rowKey, ...otherKeyProps } = row.getRowProps();
|
|
55
|
+
return (_jsx(ContextMenu, { options: contextMenu, onSelect: (selected) => onContextMenuSelect?.(selected, row.original), as: "tr", style: { position: 'static' }, css: getRowStyle(highlight.isActive || isRowActive, rowStyle, disableDefaultRowStyle), ...otherKeyProps, ...highlight.onHover, children: row.cells.map((cell) => {
|
|
56
|
+
const { style, padding } = cell;
|
|
56
57
|
if (cell.isRowSpanned) {
|
|
57
58
|
return null;
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
60
|
-
|
|
61
|
+
const { key: columnKey, ...otherColumnProps } = cell.getCellProps();
|
|
62
|
+
return (_jsx("td", { rowSpan: cell.rowSpan, ...otherColumnProps, onContextMenu: (e) => {
|
|
61
63
|
e.preventDefault();
|
|
62
64
|
return false;
|
|
63
|
-
}, style: { padding, ...style }, onClick: clickHandler, children: cell.render('Cell') },
|
|
65
|
+
}, style: { padding, ...style }, onClick: clickHandler, children: cell.render('Cell') }, columnKey));
|
|
64
66
|
}
|
|
65
|
-
}) },
|
|
67
|
+
}) }, rowKey));
|
|
66
68
|
}
|
|
67
69
|
export default ReactTableRow;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @jsxImportSource @emotion/react */
|
|
2
2
|
import { CSSObject, SerializedStyles } from '@emotion/react';
|
|
3
|
-
import { CSSProperties } from 'react';
|
|
3
|
+
import { CSSProperties, ReactElement } from 'react';
|
|
4
4
|
import { CellProps, Column as ReactColumn, UseSortByColumnOptions } from 'react-table';
|
|
5
5
|
import { HighlightEventSource } from '../../highlight';
|
|
6
6
|
import { BaseContextMenuProps } from '../ContextMenuBluePrint';
|
|
@@ -8,7 +8,7 @@ import { ClickEvent } from './Elements/ReactTableRow';
|
|
|
8
8
|
interface ExtraColumn<T extends object> {
|
|
9
9
|
enableRowSpan?: boolean;
|
|
10
10
|
style?: CSSProperties;
|
|
11
|
-
Cell?: (cell: CellProps<T>) =>
|
|
11
|
+
Cell?: (cell: CellProps<T>) => ReactElement | string;
|
|
12
12
|
}
|
|
13
13
|
export type Column<T extends object> = ReactColumn<T> & ExtraColumn<T> & UseSortByColumnOptions<T>;
|
|
14
14
|
interface SortEvent {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IconName, TooltipProps } from '@blueprintjs/core';
|
|
2
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
3
|
+
interface IconButtonProps extends React.SVGAttributes<SVGElement> {
|
|
4
|
+
size?: number;
|
|
5
|
+
padding?: number;
|
|
6
|
+
icon?: IconName;
|
|
7
|
+
backgroundColor?: CSSProperties['backgroundColor'];
|
|
8
|
+
color?: CSSProperties['color'];
|
|
9
|
+
title?: string;
|
|
10
|
+
tooltipProps?: TooltipProps;
|
|
11
|
+
renderIcon?: (props: Pick<IconButtonProps, 'color' | 'size'>) => ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function SVGButton(props: IconButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon, Tooltip } from '@blueprintjs/core';
|
|
3
|
+
export function SVGButton(props) {
|
|
4
|
+
const { size = 16, padding = 5, className, icon, renderIcon, backgroundColor = 'gray', color = 'white', title, tooltipProps, ...otherProps } = props;
|
|
5
|
+
return (_jsx(Tooltip, { content: title, compact: true, targetTagName: "g", placement: "auto-end", ...tooltipProps, children: _jsxs("svg", { width: size, height: size, viewBox: `0 0 ${size} ${size}`, ...otherProps, children: [_jsx("circle", { cx: size / 2, cy: size / 2, r: size / 2, fill: backgroundColor }), _jsx("g", { transform: `translate(${padding / 2} ${padding / 2})`, children: typeof renderIcon === 'function' ? (renderIcon({ size: size - padding, color })) : (_jsx(Icon, { tagName: "g", icon: icon, size: size - padding, color: color })) })] }) }));
|
|
6
|
+
}
|
|
@@ -5,18 +5,20 @@ export function SVGGroup(props) {
|
|
|
5
5
|
const { children, direction = 'row', space = 0, ...resProps } = props;
|
|
6
6
|
useLayoutEffect(() => {
|
|
7
7
|
let shift = 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
const elements = elementsRefs.current;
|
|
9
|
+
if (!elements) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const element of elements) {
|
|
13
|
+
if (element) {
|
|
14
|
+
const boundary = element.getBoundingClientRect();
|
|
15
|
+
if (direction === 'row') {
|
|
16
|
+
element.setAttribute('transform', `translate(${shift} 0)`);
|
|
17
|
+
shift += boundary.width + space;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
element.setAttribute('transform', `translate(0 ${shift})`);
|
|
21
|
+
shift += boundary.height + space;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -27,6 +29,6 @@ export function SVGGroup(props) {
|
|
|
27
29
|
if (ref) {
|
|
28
30
|
elementsRefs.current[index] = ref;
|
|
29
31
|
}
|
|
30
|
-
}, children: child },
|
|
32
|
+
}, children: child }, `${index}`));
|
|
31
33
|
}) }));
|
|
32
34
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SVGAttributes } from 'react';
|
|
2
|
+
interface SVGTextProps extends SVGAttributes<SVGTextElement> {
|
|
3
|
+
rectProps?: SVGAttributes<SVGRectElement>;
|
|
4
|
+
padding?: number;
|
|
5
|
+
borderRadius?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function SVGText(props: SVGTextProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
const defaultTextBBox = {
|
|
4
|
+
width: 0,
|
|
5
|
+
height: 0,
|
|
6
|
+
x: 0,
|
|
7
|
+
y: 0,
|
|
8
|
+
};
|
|
9
|
+
export function SVGText(props) {
|
|
10
|
+
const textRef = useRef(null);
|
|
11
|
+
const [boxSize, setBoxSize] = useState(defaultTextBBox);
|
|
12
|
+
const { rectProps = {}, padding = 0, borderRadius = 0, children, ...otherProps } = props;
|
|
13
|
+
const { ...otherRectProps } = rectProps;
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
const boundary = textRef?.current?.getBBox();
|
|
16
|
+
if (boundary) {
|
|
17
|
+
setBoxSize(boundary);
|
|
18
|
+
}
|
|
19
|
+
}, []);
|
|
20
|
+
const { width: textWidth, height: textHeight, x, y } = boxSize;
|
|
21
|
+
const width = textWidth + padding * 2;
|
|
22
|
+
const height = textHeight + padding * 2;
|
|
23
|
+
return (_jsxs("g", { children: [_jsx("rect", { width: width, height: height, x: x - padding, y: y - padding, fill: "transparent", ...(borderRadius && { rx: borderRadius, ry: borderRadius }), ...otherRectProps }), _jsx("text", { ref: textRef, fill: "black", textAnchor: "middle", ...otherProps, children: children })] }));
|
|
24
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ToolbarItemProps } from 'react-science/ui';
|
|
2
|
-
export declare function SaveButton(props: Pick<ToolbarItemProps, 'onClick' | '
|
|
2
|
+
export declare function SaveButton(props: Pick<ToolbarItemProps, 'onClick' | 'tooltip'>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
2
|
import { Position } from './useDraggable';
|
|
3
|
-
type ChildType =
|
|
3
|
+
type ChildType = ReactElement[] | ReactElement | boolean | null;
|
|
4
4
|
type PositionChangeHandler = (data: Position) => void;
|
|
5
5
|
export interface DraggableProps {
|
|
6
6
|
children?: ChildType | ((x1: number, x2: number) => ChildType);
|
|
@@ -3,7 +3,6 @@ import { useFormikContext } from 'formik';
|
|
|
3
3
|
import lodashGet from 'lodash/get';
|
|
4
4
|
const styles = {
|
|
5
5
|
container: {
|
|
6
|
-
padding: '0.4rem',
|
|
7
6
|
display: 'flex',
|
|
8
7
|
flexDirection: 'column',
|
|
9
8
|
},
|
|
@@ -14,9 +13,8 @@ const styles = {
|
|
|
14
13
|
},
|
|
15
14
|
};
|
|
16
15
|
function FormikError({ style, name, children }) {
|
|
17
|
-
const { errors, isValid, dirty
|
|
16
|
+
const { errors, isValid, dirty } = useFormikContext();
|
|
18
17
|
const errorText = lodashGet(errors, name);
|
|
19
|
-
|
|
20
|
-
return (_jsxs("div", { style: { ...styles.container, ...style?.container }, children: [children, !isValid && dirty && isTouched && (_jsx("span", { style: { ...styles.text, ...style?.text }, children: errorText }))] }));
|
|
18
|
+
return (_jsxs("div", { style: { ...styles.container, ...style?.container }, children: [children, !isValid && dirty && (_jsx("span", { style: { ...styles.text, ...style?.text }, children: errorText }))] }));
|
|
21
19
|
}
|
|
22
20
|
export default FormikError;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { InputProps } from '../Input';
|
|
2
3
|
export interface InputMapValueFunctions {
|
|
3
4
|
mapOnChangeValue?: (value: string | number) => any;
|
|
@@ -7,5 +8,5 @@ interface FormikInputProps extends InputMapValueFunctions {
|
|
|
7
8
|
name: string;
|
|
8
9
|
checkErrorAfterInputTouched?: boolean;
|
|
9
10
|
}
|
|
10
|
-
declare
|
|
11
|
+
declare const FormikInput: import("react").ForwardRefExoticComponent<FormikInputProps & InputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
11
12
|
export default FormikInput;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useFormikContext } from 'formik';
|
|
3
3
|
import lodashGet from 'lodash/get';
|
|
4
|
+
import { forwardRef } from 'react';
|
|
4
5
|
import Input from '../Input';
|
|
5
|
-
function FormikInput(props) {
|
|
6
|
+
const FormikInput = forwardRef(function FormikInput(props, ref) {
|
|
6
7
|
const { name, style = { label: {}, input: {}, inputWrapper: {} }, onChange, type = 'text', className = '', value = null, checkErrorAfterInputTouched = true, mapOnChangeValue, mapValue, ...resProps } = props;
|
|
7
|
-
const { values, handleChange, errors, touched, setFieldValue } = useFormikContext();
|
|
8
|
+
const { values, handleChange, errors, touched, setFieldValue, handleBlur } = useFormikContext();
|
|
8
9
|
function changeHandler(e) {
|
|
9
10
|
onChange?.(e);
|
|
10
11
|
if (mapOnChangeValue) {
|
|
@@ -20,7 +21,7 @@ function FormikInput(props) {
|
|
|
20
21
|
}
|
|
21
22
|
let val = value || lodashGet(values, name);
|
|
22
23
|
val = mapValue ? mapValue(val) : val;
|
|
23
|
-
return (_jsx(Input, { name: name, value: val, onChange: changeHandler, type: type, style: {
|
|
24
|
+
return (_jsx(Input, { ref: ref, name: name, value: val, onChange: changeHandler, onBlur: handleBlur, type: type, style: {
|
|
24
25
|
...style,
|
|
25
26
|
inputWrapper: {
|
|
26
27
|
...style.inputWrapper,
|
|
@@ -34,5 +35,5 @@ function FormikInput(props) {
|
|
|
34
35
|
: {}),
|
|
35
36
|
},
|
|
36
37
|
}, className: className, ...resProps }));
|
|
37
|
-
}
|
|
38
|
+
});
|
|
38
39
|
export default FormikInput;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource @emotion/react */
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
|
-
import { useMemo,
|
|
4
|
+
import { useMemo, memo } from 'react';
|
|
5
5
|
import { FaRegWindowMaximize, FaQuestionCircle, FaRegSave, FaFilm, } from 'react-icons/fa';
|
|
6
6
|
import { Toolbar, useFullscreen } from 'react-science/ui';
|
|
7
7
|
import { docsBaseUrl } from '../../constants';
|
|
@@ -11,6 +11,7 @@ import Button from '../elements/Button';
|
|
|
11
11
|
import { Header } from '../elements/Header';
|
|
12
12
|
import DropDownButton from '../elements/dropDownButton/DropDownButton';
|
|
13
13
|
import { useSaveSettings } from '../hooks/useSaveSettings';
|
|
14
|
+
import { useWorkspaceAction } from '../hooks/useWorkspaceAction';
|
|
14
15
|
import { LogsHistoryModal } from '../modal/LogsHistoryModal';
|
|
15
16
|
import AboutUsModal from '../modal/aboutUs/AboutUsModal';
|
|
16
17
|
import GeneralSettingsModal from '../modal/setting/GeneralSettings';
|
|
@@ -63,7 +64,8 @@ const styles = css `
|
|
|
63
64
|
`;
|
|
64
65
|
function HeaderInner(props) {
|
|
65
66
|
const { selectedOptionPanel, height } = props;
|
|
66
|
-
const { current: { display: { general }, }, workspace,
|
|
67
|
+
const { current: { display: { general }, }, workspace, } = usePreferences();
|
|
68
|
+
const { setActiveWorkspace } = useWorkspaceAction();
|
|
67
69
|
const fullscreen = useFullscreen();
|
|
68
70
|
const workspacesList = useWorkspacesList();
|
|
69
71
|
const hideGeneralSettings = !!(general?.hideGeneralSettings && workspace.base);
|
|
@@ -90,14 +92,9 @@ function HeaderInner(props) {
|
|
|
90
92
|
return null;
|
|
91
93
|
}
|
|
92
94
|
}, [selectedOptionPanel]);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
payload: {
|
|
97
|
-
workspace: option.key,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}, [dispatch]);
|
|
95
|
+
function changeWorkspaceHandler(option) {
|
|
96
|
+
setActiveWorkspace(option.key);
|
|
97
|
+
}
|
|
101
98
|
function renderItem(item) {
|
|
102
99
|
return _jsx(WorkspaceItem, { item: item });
|
|
103
100
|
}
|
|
@@ -105,7 +102,7 @@ function HeaderInner(props) {
|
|
|
105
102
|
alignItems: 'center',
|
|
106
103
|
}, children: [_jsx("div", { children: _jsx(Toolbar, { children: _jsx(AboutUsModal, {}) }) }), _jsx("div", { className: "toolOptionsPanel", style: { flex: 1 }, children: selectedPanel })] }), _jsxs(HeaderContainer, { style: {
|
|
107
104
|
alignItems: 'center',
|
|
108
|
-
}, children: [!hideWorkspaces && (_jsx(DropDownButton, { data: workspacesList, selectedKey: workspace.current, onSelect: changeWorkspaceHandler, renderItem: renderItem })), !hideGeneralSettings && _jsx(SaveButton, {}), !general?.hideLogs && _jsx(LogsHistoryModal, {}), _jsx("div", { children: _jsxs(Toolbar, { children: [!general?.hideHelp && (_jsx(Toolbar.Item, { id: "user-manual",
|
|
105
|
+
}, children: [!hideWorkspaces && (_jsx(DropDownButton, { data: workspacesList, selectedKey: workspace.current, onSelect: changeWorkspaceHandler, renderItem: renderItem })), !hideGeneralSettings && _jsx(SaveButton, {}), !general?.hideLogs && _jsx(LogsHistoryModal, {}), _jsx("div", { children: _jsxs(Toolbar, { children: [!general?.hideHelp && (_jsx(Toolbar.Item, { id: "user-manual", tooltip: "User manual", onClick: () => window.open(docsBaseUrl, '_blank'), icon: _jsx(FaQuestionCircle, {}) })), _jsx(Toolbar.Item, { id: "user-manual", tooltip: "NMRium channel", onClick: () => window.open('https://www.youtube.com/@nmrium', '_blank'), icon: _jsx(FaFilm, {}) }), !hideGeneralSettings && (_jsx(GeneralSettingsModal, { height: height / 2 })), !fullscreen.isFullScreen && !general?.hideMaximize && (_jsx(Toolbar.Item, { id: "full-screen", onClick: fullscreen.toggle, tooltip: "Full screen", className: "windowButton", icon: _jsx(FaRegWindowMaximize, {}) }))] }) })] })] }) }));
|
|
109
106
|
}
|
|
110
107
|
function SaveButton() {
|
|
111
108
|
const { workspace, workspaces, originalWorkspaces } = usePreferences();
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource @emotion/react */
|
|
3
|
+
import { Select } from '@blueprintjs/select';
|
|
3
4
|
import { css } from '@emotion/react';
|
|
4
5
|
import debounce from 'lodash/debounce';
|
|
5
6
|
import { Filters } from 'nmr-processing';
|
|
6
7
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
8
|
import { FaRulerHorizontal, FaRulerVertical } from 'react-icons/fa';
|
|
8
9
|
import { MdLooksTwo } from 'react-icons/md';
|
|
9
|
-
import { Toolbar } from 'react-science/ui';
|
|
10
|
+
import { Button, Toolbar, useSelect } from 'react-science/ui';
|
|
10
11
|
import { useActivePhaseTraces } from '../2d/1d-tracer/phase-correction-traces/useActivePhaseTraces';
|
|
11
12
|
import { useDispatch } from '../context/DispatchContext';
|
|
12
13
|
import ActionButtons from '../elements/ActionButtons';
|
|
@@ -17,6 +18,17 @@ import { useFilter } from '../hooks/useFilter';
|
|
|
17
18
|
import useSpectrum from '../hooks/useSpectrum';
|
|
18
19
|
import { headerLabelStyle } from './Header';
|
|
19
20
|
import { HeaderContainer } from './HeaderContainer';
|
|
21
|
+
const defaultPhasingTypeItem = {
|
|
22
|
+
label: 'Manual',
|
|
23
|
+
value: 'manual',
|
|
24
|
+
};
|
|
25
|
+
const algorithms = [
|
|
26
|
+
defaultPhasingTypeItem,
|
|
27
|
+
{
|
|
28
|
+
label: 'Automatic',
|
|
29
|
+
value: 'automatic',
|
|
30
|
+
},
|
|
31
|
+
];
|
|
20
32
|
const inputStyle = {
|
|
21
33
|
input: {
|
|
22
34
|
width: '70px',
|
|
@@ -46,8 +58,12 @@ export default function PhaseCorrectionTwoDimensionsPanel() {
|
|
|
46
58
|
const valueRef = useRef(defaultPhaseOptions);
|
|
47
59
|
const ph0Ref = useRef();
|
|
48
60
|
const ph1Ref = useRef();
|
|
61
|
+
const { value: phaseCorrectionTypeItem, ...defaultSelectProps } = useSelect({
|
|
62
|
+
defaultSelectedItem: defaultPhasingTypeItem,
|
|
63
|
+
itemTextKey: 'label',
|
|
64
|
+
});
|
|
49
65
|
useEffect(() => {
|
|
50
|
-
if (filter) {
|
|
66
|
+
if (filter && phaseCorrectionTypeItem?.value === 'manual') {
|
|
51
67
|
const { value } = filter;
|
|
52
68
|
const phaseOptions = defaultPhaseOptions;
|
|
53
69
|
for (const direction of Object.keys(value)) {
|
|
@@ -57,7 +73,7 @@ export default function PhaseCorrectionTwoDimensionsPanel() {
|
|
|
57
73
|
setValue(phaseOptions);
|
|
58
74
|
valueRef.current = phaseOptions;
|
|
59
75
|
}
|
|
60
|
-
}, [filter]);
|
|
76
|
+
}, [filter, phaseCorrectionTypeItem?.value]);
|
|
61
77
|
useEffect(() => {
|
|
62
78
|
if (ph0Ref.current && ph1Ref.current) {
|
|
63
79
|
const { ph0, ph1 } = valueRef.current[activeTraceDirection];
|
|
@@ -142,14 +158,29 @@ export default function PhaseCorrectionTwoDimensionsPanel() {
|
|
|
142
158
|
});
|
|
143
159
|
}
|
|
144
160
|
function handleApplyFilter() {
|
|
145
|
-
|
|
161
|
+
switch (phaseCorrectionTypeItem?.value) {
|
|
162
|
+
case 'automatic': {
|
|
163
|
+
dispatch({
|
|
164
|
+
type: 'APPLY_AUTO_PHASE_CORRECTION_TOW_DIMENSION_FILTER',
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case 'manual': {
|
|
169
|
+
dispatch({
|
|
170
|
+
type: 'APPLY_MANUAL_PHASE_CORRECTION_TOW_DIMENSION_FILTER',
|
|
171
|
+
});
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
146
177
|
}
|
|
147
178
|
function handleToggleAddTraceToBothDirections() {
|
|
148
179
|
dispatch({ type: 'TOGGLE_ADD_PHASE_CORRECTION_TRACE_TO_BOTH_DIRECTIONS' });
|
|
149
180
|
}
|
|
150
|
-
return (_jsxs(HeaderContainer, { style: { padding: '0 5px' }, children: [_jsx(Label, { title: "Direction:", style: headerLabelStyle, children: _jsxs(Toolbar, { children: [_jsx(Toolbar.Item, { css: css `
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
181
|
+
return (_jsxs(HeaderContainer, { style: { padding: '0 5px' }, children: [_jsx("div", { style: { padding: '0 5px' }, children: _jsx(Select, { items: algorithms, filterable: false, itemsEqual: "value", ...defaultSelectProps, children: _jsx(Button, { text: phaseCorrectionTypeItem?.label, rightIcon: "double-caret-vertical" }) }) }), phaseCorrectionTypeItem?.value === 'manual' && (_jsxs(_Fragment, { children: [_jsx(Label, { title: "Direction:", style: headerLabelStyle, children: _jsxs(Toolbar, { children: [_jsx(Toolbar.Item, { css: css `
|
|
182
|
+
border: 1px solid #f7f7f7;
|
|
183
|
+
`, tooltip: "Horizontal", icon: _jsx(FaRulerHorizontal, {}), active: activeTraceDirection === 'horizontal', onClick: () => onChangeHandler('horizontal') }), _jsx(Toolbar.Item, { css: css `
|
|
184
|
+
border: 1px solid #f7f7f7;
|
|
185
|
+
`, tooltip: "Vertical", icon: _jsx(FaRulerVertical, {}), active: activeTraceDirection === 'vertical', onClick: () => onChangeHandler('vertical') })] }) }), _jsx("div", { style: { paddingRight: '5px' }, children: _jsx(Toolbar, { children: _jsx(Toolbar.Item, { tooltip: "Add the trace in both directions", icon: _jsx(MdLooksTwo, {}), active: addTracesToBothDirections, onClick: handleToggleAddTraceToBothDirections }) }) }), _jsx(Label, { title: "PH0:", style: headerLabelStyle, children: _jsx(Input, { name: "ph0", style: inputStyle, onChange: handleInput, value: value[activeTraceDirection].ph0, type: "number", debounceTime: 250 }) }), _jsx(Label, { title: "PH1:", style: headerLabelStyle, children: _jsx(Input, { name: "ph1", style: inputStyle, onChange: handleInput, value: value[activeTraceDirection].ph1, type: "number", debounceTime: 250 }) }), _jsx(InputRange, { ref: ph0Ref, name: "ph0", label: "Change PH0 (click and drag)", shortLabel: "Ph0", style: { width: '20%' }, onChange: handleRangeChange }), _jsx(InputRange, { ref: ph1Ref, name: "ph1", label: "Change PH1 (click and drag)", shortLabel: "Ph1", style: { width: '20%' }, onChange: handleRangeChange })] })), _jsx(ActionButtons, { onDone: handleApplyFilter, onCancel: handleCancelFilter })] }));
|
|
155
186
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MIN_AREA_POINTS
|
|
1
|
+
export declare const MIN_AREA_POINTS = 5;
|
|
2
2
|
export declare function useCheckPointsNumberInWindowArea(): number;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type ReturnFunction = (value?: number | string, formatKey?: string, prefix?: string, suffix?: string) => string;
|
|
1
|
+
export type ReturnFunction = (value?: number | string, formatKey?: 'ppmFormat' | 'hzFormat' | (string & {}), prefix?: string, suffix?: string) => string;
|
|
2
2
|
export declare function useFormatNumberByNucleus(nucleus?: string[]): ReturnFunction[];
|
|
3
3
|
export declare function useFormatNumberByNucleus(nucleus?: string): ReturnFunction;
|
|
@@ -4,14 +4,15 @@ import { usePreferences } from '../context/PreferencesContext';
|
|
|
4
4
|
import { formatNumber } from '../utility/formatNumber';
|
|
5
5
|
export function useFormatNumberByNucleus(nucleus) {
|
|
6
6
|
const preferences = usePreferences();
|
|
7
|
-
const
|
|
8
|
-
ppm: '0.0',
|
|
9
|
-
hz: '0.0',
|
|
10
|
-
});
|
|
7
|
+
const nucleiPreferences = lodashGet(preferences.current, `nuclei`, []);
|
|
11
8
|
return useMemo(() => {
|
|
12
9
|
function formatFun(n) {
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const preferences = nucleiPreferences?.find(({ nucleus }) => nucleus.toLowerCase() === n.toLowerCase()) || {
|
|
11
|
+
ppmFormat: '0.0',
|
|
12
|
+
hzFormat: '0.0',
|
|
13
|
+
};
|
|
14
|
+
return (value, formatKey = 'ppmFormat', prefix = '', suffix = '') => {
|
|
15
|
+
return formatNumber(value, preferences[formatKey], {
|
|
15
16
|
prefix,
|
|
16
17
|
suffix,
|
|
17
18
|
});
|
|
@@ -29,5 +30,5 @@ export function useFormatNumberByNucleus(nucleus) {
|
|
|
29
30
|
else {
|
|
30
31
|
throw new Error('nuclus must be string or array of string');
|
|
31
32
|
}
|
|
32
|
-
}, [
|
|
33
|
+
}, [nucleiPreferences, nucleus]);
|
|
33
34
|
}
|
|
@@ -13,12 +13,14 @@ function useIntegralYDomain(max, scaleRatio = 1) {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
export default function useIntegralPath(options) {
|
|
16
|
-
const { x, y, max, scaleRatio } = options;
|
|
16
|
+
const { x, y, max, scaleRatio, from, to } = options;
|
|
17
17
|
const scaleX = useXScale();
|
|
18
18
|
const scaleY = useIntegralYDomain(max, scaleRatio);
|
|
19
19
|
const xySeries = xyReduce({ x, y }, {
|
|
20
20
|
nbPoints: 200,
|
|
21
21
|
optimize: true,
|
|
22
|
+
from,
|
|
23
|
+
to,
|
|
22
24
|
});
|
|
23
25
|
const pathBuilder = new PathBuilder();
|
|
24
26
|
pathBuilder.moveTo(scaleX(xySeries.x[0]), scaleY(xySeries.y[0]));
|
|
@@ -4,7 +4,6 @@ import { getDefaultPredictionOptions } from '../../data/PredictionManager';
|
|
|
4
4
|
import { usePreferences } from '../context/PreferencesContext';
|
|
5
5
|
import { getIntegralDefaultValues, getPeaksDefaultValues, getZoneDefaultValues, getRangeDefaultValues, databaseDefaultValues, getMultipleSpectraAnalysisDefaultValues, getSpectraDefaultValues, } from '../reducer/preferences/panelsPreferencesDefaultValues';
|
|
6
6
|
import { getValue } from '../utility/LocalStorage';
|
|
7
|
-
const basePath = 'formatting.panels';
|
|
8
7
|
function getDefaultPreferences(panelKey, nucleus) {
|
|
9
8
|
switch (panelKey) {
|
|
10
9
|
case 'spectra':
|
|
@@ -35,7 +34,7 @@ function joinWithNucleusPreferences(data, nucleus, returnOnlyNucleusPreferences
|
|
|
35
34
|
return { ...nuclei[nucleus], ...rest };
|
|
36
35
|
}
|
|
37
36
|
function getPanelPreferences(preferences, panelKey, nucleus, returnOnlyNucleusPreferences = false) {
|
|
38
|
-
const panelPath =
|
|
37
|
+
const panelPath = `panels.${panelKey}`;
|
|
39
38
|
let path = panelPath;
|
|
40
39
|
if (nucleus) {
|
|
41
40
|
switch (panelKey) {
|
|
@@ -8,6 +8,7 @@ import { usePreferences } from '../context/PreferencesContext';
|
|
|
8
8
|
import { useToaster } from '../context/ToasterContext';
|
|
9
9
|
import FormikInput from '../elements/formik/FormikInput';
|
|
10
10
|
import ConfirmationDialog from '../elements/popup/Modal/ConfirmDialog';
|
|
11
|
+
import { useWorkspaceAction } from './useWorkspaceAction';
|
|
11
12
|
const schema = Yup.object().shape({
|
|
12
13
|
workspaceName: Yup.string().required(),
|
|
13
14
|
});
|
|
@@ -25,16 +26,11 @@ export function useSaveSettings() {
|
|
|
25
26
|
const toaster = useToaster();
|
|
26
27
|
const [isOpenDialog, openDialog, closeDialog] = useOnOff(false);
|
|
27
28
|
const settingsRef = useRef();
|
|
28
|
-
const {
|
|
29
|
+
const { current } = usePreferences();
|
|
29
30
|
const formRef = useRef(null);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
payload: {
|
|
34
|
-
workspaceKey: workspaceName,
|
|
35
|
-
data: settingsRef.current,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
31
|
+
const { saveWorkspace, addNewWorkspace } = useWorkspaceAction();
|
|
32
|
+
function handleAddNewWorkspace({ workspaceName }) {
|
|
33
|
+
addNewWorkspace(workspaceName, settingsRef.current);
|
|
38
34
|
closeDialog();
|
|
39
35
|
toaster.show({
|
|
40
36
|
message: 'Preferences saved successfully',
|
|
@@ -48,17 +44,14 @@ export function useSaveSettings() {
|
|
|
48
44
|
openDialog();
|
|
49
45
|
}
|
|
50
46
|
else {
|
|
51
|
-
|
|
52
|
-
type: 'SET_PREFERENCES',
|
|
53
|
-
...(values && { payload: values }),
|
|
54
|
-
});
|
|
47
|
+
saveWorkspace(values);
|
|
55
48
|
closeDialog();
|
|
56
49
|
}
|
|
57
50
|
},
|
|
58
51
|
SaveSettingsModal: () => {
|
|
59
52
|
const alertConfig = {
|
|
60
53
|
message: 'Please enter a new user workspace name in order to save your changes locally',
|
|
61
|
-
render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave:
|
|
54
|
+
render: (props) => (_jsx(WorkspaceAddForm, { ...props, onSave: handleAddNewWorkspace, ref: formRef })),
|
|
62
55
|
buttons: [
|
|
63
56
|
{
|
|
64
57
|
text: 'Save',
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useShareData } from '../context/ShareDataContext';
|
|
2
|
+
export function useTriggerNewAssignmentLabel(id) {
|
|
3
|
+
const { data: rangeKey, setData } = useShareData();
|
|
4
|
+
function dismissNewLabel() {
|
|
5
|
+
setData(null);
|
|
6
|
+
}
|
|
7
|
+
return { isNewAssignment: rangeKey === id, dismissNewLabel };
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Workspace } from 'nmr-load-save';
|
|
2
|
+
export declare function useWorkspaceAction(): {
|
|
3
|
+
addNewWorkspace: (workspaceName: string, data?: Omit<Workspace, 'version' | 'label'>) => void;
|
|
4
|
+
removeWorkspace: (key: string) => void;
|
|
5
|
+
saveWorkspace: (data?: Partial<Workspace>) => void;
|
|
6
|
+
setActiveWorkspace: (workspace: string) => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { v4 } from '@lukeed/uuid';
|
|
2
|
+
import lodashMerge from 'lodash/merge';
|
|
3
|
+
import { usePreferences } from '../context/PreferencesContext';
|
|
4
|
+
import { readSettings, updateSettings, } from '../reducer/preferences/preferencesReducer';
|
|
5
|
+
import { workspaceDefaultProperties } from '../workspaces/workspaceDefaultProperties';
|
|
6
|
+
export function useWorkspaceAction() {
|
|
7
|
+
const { dispatch, current, workspace } = usePreferences();
|
|
8
|
+
function setActiveWorkspace(workspace) {
|
|
9
|
+
const settings = readSettings() || {
|
|
10
|
+
currentWorkspace: null,
|
|
11
|
+
version: 0,
|
|
12
|
+
workspaces: {},
|
|
13
|
+
};
|
|
14
|
+
settings.currentWorkspace = workspace;
|
|
15
|
+
updateSettings(settings);
|
|
16
|
+
dispatch({
|
|
17
|
+
type: 'SET_ACTIVE_WORKSPACE',
|
|
18
|
+
payload: {
|
|
19
|
+
workspace,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function addNewWorkspace(workspaceName, data) {
|
|
24
|
+
const workSpaceData = data ?? current;
|
|
25
|
+
const newWorkSpace = lodashMerge({}, workspaceDefaultProperties, workSpaceData, {
|
|
26
|
+
version: 1,
|
|
27
|
+
label: workspaceName,
|
|
28
|
+
source: 'user',
|
|
29
|
+
});
|
|
30
|
+
const workspaceKey = v4();
|
|
31
|
+
const localData = readSettings() || { workspaces: {} };
|
|
32
|
+
const settings = {
|
|
33
|
+
...localData,
|
|
34
|
+
currentWorkspace: workspaceKey,
|
|
35
|
+
workspaces: { ...localData?.workspaces, [workspaceKey]: newWorkSpace },
|
|
36
|
+
};
|
|
37
|
+
updateSettings(settings);
|
|
38
|
+
dispatch({
|
|
39
|
+
type: 'ADD_WORKSPACE',
|
|
40
|
+
payload: {
|
|
41
|
+
workspaceKey,
|
|
42
|
+
data: newWorkSpace,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function removeWorkspace(key) {
|
|
47
|
+
const settings = readSettings();
|
|
48
|
+
if (settings) {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
50
|
+
delete settings.workspaces[key];
|
|
51
|
+
if (key === settings.currentWorkspace) {
|
|
52
|
+
settings.currentWorkspace = 'default';
|
|
53
|
+
}
|
|
54
|
+
updateSettings(settings);
|
|
55
|
+
}
|
|
56
|
+
dispatch({
|
|
57
|
+
type: 'REMOVE_WORKSPACE',
|
|
58
|
+
payload: {
|
|
59
|
+
workspace: key,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function saveWorkspace(data) {
|
|
64
|
+
if (data) {
|
|
65
|
+
const settings = readSettings() || {
|
|
66
|
+
version: 0,
|
|
67
|
+
currentWorkspace: null,
|
|
68
|
+
workspaces: {},
|
|
69
|
+
};
|
|
70
|
+
updateSettings({
|
|
71
|
+
...settings,
|
|
72
|
+
workspaces: {
|
|
73
|
+
...settings.workspaces,
|
|
74
|
+
[workspace.current]: data,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
dispatch({
|
|
79
|
+
type: 'SET_PREFERENCES',
|
|
80
|
+
...(data && { payload: data }),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
addNewWorkspace,
|
|
85
|
+
removeWorkspace,
|
|
86
|
+
saveWorkspace,
|
|
87
|
+
setActiveWorkspace,
|
|
88
|
+
};
|
|
89
|
+
}
|