nmrium 0.45.0 → 0.45.1-pre.1701344673

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.
@@ -39,12 +39,19 @@ const Select = forwardRef(function Select(props, ref) {
39
39
  onChange(returnValue ? selectedData[itemValueField] : selectedData);
40
40
  }, [itemValueField, onChange, returnValue]);
41
41
  return (_jsxs("select", { ref: ref, css: styles.select(style?.width), name: name, onChange: handleOnChanged, defaultValue: defaultValue, value: value, className: className, style: style, required: true, children: [placeholder && (_jsx("option", { value: "", disabled: true, children: placeholder })), items.map((option) => {
42
- if (typeof option[itemValueField] !== 'string' ||
43
- typeof option[itemTextField] !== 'string') {
44
- // TODO: throw error
42
+ const value = option[itemValueField];
43
+ if (!['number', 'string'].includes(typeof option[itemTextField])) {
44
+ // eslint-disable-next-line no-console
45
+ console.log(`The '${itemTextField}' field should be a string , option : ${JSON.stringify(option)}`);
45
46
  return null;
46
47
  }
47
- return (_jsx("option", { value: option[itemValueField], "data-value": JSON.stringify(option), children: textRender?.(option[itemTextField]) || option[itemTextField] }, JSON.stringify(option)));
48
+ if (!['number', 'string'].includes(typeof value)) {
49
+ // eslint-disable-next-line no-console
50
+ console.log(`The '${itemValueField}' field should be either a string or a number, option : ${JSON.stringify(option)}`);
51
+ return null;
52
+ }
53
+ const label = String(option[itemTextField]);
54
+ return (_jsx("option", { value: value, "data-value": JSON.stringify(option), children: textRender?.(label) || label }, JSON.stringify(option)));
48
55
  })] }));
49
56
  });
50
57
  export default Select;
@@ -6,7 +6,9 @@ export const defaultIntegralsViewState = {
6
6
  export function useActiveSpectrumIntegralsViewState() {
7
7
  const activeSpectrum = useActiveSpectrum();
8
8
  const { view: { integrals }, } = useChartData();
9
- if (activeSpectrum?.id && integrals[activeSpectrum?.id]) {
9
+ if (activeSpectrum?.id &&
10
+ activeSpectrum?.selected &&
11
+ integrals[activeSpectrum?.id]) {
10
12
  return integrals[activeSpectrum?.id];
11
13
  }
12
14
  else {
@@ -9,7 +9,9 @@ export const defaultPeaksViewState = {
9
9
  export function useActiveSpectrumPeaksViewState() {
10
10
  const activeSpectrum = useActiveSpectrum();
11
11
  const { view: { peaks }, } = useChartData();
12
- if (activeSpectrum?.id && peaks[activeSpectrum?.id]) {
12
+ if (activeSpectrum?.id &&
13
+ activeSpectrum?.selected &&
14
+ peaks[activeSpectrum?.id]) {
13
15
  return peaks[activeSpectrum?.id];
14
16
  }
15
17
  else {
@@ -11,7 +11,9 @@ export const defaultRangesViewState = {
11
11
  export function useActiveSpectrumRangesViewState() {
12
12
  const activeSpectrum = useActiveSpectrum();
13
13
  const { view: { ranges }, } = useChartData();
14
- if (activeSpectrum?.id && ranges[activeSpectrum?.id]) {
14
+ if (activeSpectrum?.id &&
15
+ activeSpectrum?.selected &&
16
+ ranges[activeSpectrum?.id]) {
15
17
  return ranges[activeSpectrum?.id];
16
18
  }
17
19
  else {
@@ -6,8 +6,12 @@ export default function useActiveSpectrumStyleOptions(id) {
6
6
  const activeSpectra = useActiveSpectra();
7
7
  const preferences = usePreferences();
8
8
  return useMemo(() => {
9
- const index = activeSpectra?.findIndex((activeSpectrum) => activeSpectrum.id === id);
10
- const isActive = !!(activeSpectra?.length === 0 || index !== -1);
9
+ const index = activeSpectra?.findIndex((activeSpectrum) => activeSpectrum?.selected && activeSpectrum.id === id);
10
+ let isNoneSelected = false;
11
+ isNoneSelected =
12
+ activeSpectra?.every((activeSpectrum) => !activeSpectrum?.selected) ||
13
+ false;
14
+ const isActive = !!(activeSpectra?.length === 0 || index !== -1) || isNoneSelected;
11
15
  const opacity = isActive
12
16
  ? 1
13
17
  : get(preferences.current, 'general.dimmedSpectraOpacity', 0.1);
@@ -8,7 +8,9 @@ export const defaultZonesViewState = {
8
8
  export function useActiveSpectrumZonesViewState() {
9
9
  const activeSpectrum = useActiveSpectrum();
10
10
  const { view: { zones }, } = useChartData();
11
- if (activeSpectrum?.id && zones[activeSpectrum?.id]) {
11
+ if (activeSpectrum?.id &&
12
+ activeSpectrum?.selected &&
13
+ zones[activeSpectrum?.id]) {
12
14
  return zones[activeSpectrum?.id];
13
15
  }
14
16
  else {
@@ -13,7 +13,7 @@ const schema = Yup.object().shape({
13
13
  const WorkspaceAddForm = forwardRef(({ className, message, onSave }, ref) => {
14
14
  return (_jsxs("div", { className: className, children: [_jsx("p", { style: { paddingBottom: '10px' }, children: message }), _jsx(Formik, { initialValues: { workspaceName: '' }, validationSchema: schema, onSubmit: onSave, innerRef: ref, children: _jsx(FormikInput, { name: "workspaceName", placeholder: "Enter workspace Name", style: {
15
15
  input: {
16
- height: '35px',
16
+ padding: '0.5em',
17
17
  width: '90%',
18
18
  fontWeight: 'normal',
19
19
  color: 'black',
@@ -5,7 +5,7 @@ export default function useSpectrum(defaultValue = null) {
5
5
  const { data } = useChartData();
6
6
  const activeSpectrum = useActiveSpectrum();
7
7
  return useMemo(() => {
8
- if (data && activeSpectrum?.id) {
8
+ if (data && activeSpectrum?.id && activeSpectrum?.selected) {
9
9
  const datum = data.find((datum) => datum.id === activeSpectrum.id) || defaultValue;
10
10
  return datum;
11
11
  }
@@ -1,5 +1,4 @@
1
- import { Spectrum } from 'nmr-load-save';
2
- import { ActiveSpectrum } from '../reducer/Reducer';
1
+ import { ActiveSpectrum, Spectrum } from 'nmr-load-save';
3
2
  interface InnerMultipleAnalysisProps {
4
3
  data: Spectrum[];
5
4
  activeSpectrum: ActiveSpectrum | null;
@@ -12,7 +12,7 @@ import FormikInput from '../../elements/formik/FormikInput';
12
12
  import FormikSelect from '../../elements/formik/FormikSelect';
13
13
  import { DEFAULT_MATRIX_FILTERS, GroupPanelStyle, } from './MatrixGenerationPanel';
14
14
  const inputStyle = {
15
- input: { padding: '0.2em 0.1em', width: '100%' },
15
+ input: { padding: '0.4em', width: '100%' },
16
16
  };
17
17
  export function FiltersOptions() {
18
18
  const { values } = useFormikContext();
@@ -96,7 +96,12 @@ function FiltersPanelGroupHeader({ index, name }) {
96
96
  function handleDelete(index) {
97
97
  void setFieldValue('filters', values.filters.filter((_, i) => i !== index));
98
98
  }
99
- return (_jsxs("div", { className: "section-header", style: { display: 'flex', padding: '5px 0px' }, children: [_jsxs("p", { style: { flex: 1, ...GroupPanelStyle.header }, children: [index + 1, "-"] }), _jsx(Select, { value: name, items: DEFAULT_MATRIX_FILTERS, onChange: (value) => handelSelectFilter(value, index), style: { width: '100%' }, returnValue: false, itemTextField: "name", itemValueField: "name", textRender: (text) => normalCase(text) }), _jsxs("div", { style: { display: 'flex' }, children: [_jsx(Button.Danger, { fill: "outline", onClick: () => handleDelete(index), children: _jsx(FaTimes, {}) }), _jsx(Button.Done, { fill: "outline", onClick: () => handleAdd(index + 1), style: { marginLeft: '5px' }, children: _jsx(FaPlus, {}) })] })] }));
99
+ return (_jsxs("div", { className: "section-header", style: { display: 'flex', padding: '5px 0px' }, children: [_jsxs("p", { style: {
100
+ flex: 1,
101
+ margin: 0,
102
+ paddingRight: '5px',
103
+ ...GroupPanelStyle.header,
104
+ }, children: [index + 1, "-"] }), _jsx(Select, { value: name, items: DEFAULT_MATRIX_FILTERS, onChange: (value) => handelSelectFilter(value, index), style: { width: '100%' }, returnValue: false, itemTextField: "name", itemValueField: "name", textRender: (text) => normalCase(text) }), _jsxs("div", { style: { display: 'flex' }, children: [_jsx(Button.Danger, { fill: "outline", onClick: () => handleDelete(index), style: { marginLeft: '5px' }, children: _jsx(FaTimes, {}) }), _jsx(Button.Done, { fill: "outline", onClick: () => handleAdd(index + 1), style: { marginLeft: '5px' }, children: _jsx(FaPlus, {}) })] })] }));
100
105
  }
101
106
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
102
107
  function FieldInfo(props) {
@@ -11,7 +11,7 @@ import { useModal } from '../../elements/popup/Modal';
11
11
  import { useActiveSpectra } from '../../hooks/useActiveSpectra';
12
12
  import useSpectrum from '../../hooks/useSpectrum';
13
13
  import { getSpectraByNucleus } from '../../utility/getSpectraByNucleus';
14
- import DefaultPanelHeader from '../header/DefaultPanelHeader';
14
+ import DefaultPanelHeader, { createFilterLabel, } from '../header/DefaultPanelHeader';
15
15
  import { SpectraAutomaticPickingButton } from '../header/SpectraAutomaticPickingButton';
16
16
  function getMissingProjection(SpectrumsData, activeTab) {
17
17
  let nucleus = activeTab.split(',');
@@ -29,7 +29,6 @@ function SpectraPanelHeaderInner({ data, activeSpectrum, activeSpectra, activeTa
29
29
  const modal = useModal();
30
30
  const alert = useAlert();
31
31
  const dispatch = useDispatch();
32
- const spectra = getSpectraByNucleus(activeTab, data);
33
32
  const handleDelete = useCallback(() => {
34
33
  modal.showConfirmDialog({
35
34
  message: (_jsxs("span", { children: ["You are about to delete", _jsxs("span", { style: { color: 'black' }, children: [" ", activeSpectra?.length, " "] }), "spectra, Are you sure?"] })),
@@ -81,7 +80,8 @@ function SpectraPanelHeaderInner({ data, activeSpectrum, activeSpectra, activeTa
81
80
  });
82
81
  }
83
82
  const hasActiveSpectra = activeSpectra && activeSpectra?.length > 0;
84
- return (_jsxs(DefaultPanelHeader, { onDelete: handleDelete, counter: spectra?.length, deleteToolTip: "Delete selected spectra", disableDelete: !hasActiveSpectra, showSettingButton: true, onSettingClick: onSettingClick, children: [_jsx(Button.BarButton, { toolTip: "Hide selected spectra", onClick: hideAllSpectrumsHandler, tooltipOrientation: "horizontal", disabled: !hasActiveSpectra, children: _jsx(FaEyeSlash, {}) }), _jsx(Button.BarButton, { onClick: showAllSpectrumsHandler, toolTip: "Show selected spectra", tooltipOrientation: "horizontal", disabled: !hasActiveSpectra, children: _jsx(FaEye, {}) }), displayerMode === '2D' && activeSpectrum?.info.isFt && (_jsx(Button.BarButton, { toolTip: "Add missing projection", tooltipOrientation: "horizontal", onClick: addMissingProjectionHandler, children: _jsx(FaCreativeCommonsSamplingPlus, {}) })), displayerMode === '1D' && spectra.length > 1 && (_jsxs(_Fragment, { children: [_jsx(Button.BarButton, { tooltipOrientation: "horizontal", toolTip: "Reset scale", onClick: resetScaleHandler, children: _jsx(SvgNmrResetScale, {}) }), _jsx(Button.BarButton, { tooltipOrientation: "horizontal", toolTip: "Same top", onClick: setSameTopHandler, children: _jsx(SvgNmrSameTop, {}) })] })), _jsx(SpectraAutomaticPickingButton, {}), _jsx(Button.BarButton, { tooltipOrientation: "horizontal", toolTip: "Recolor spectra", onClick: recolorSpectraHandler, children: _jsx(IoColorPaletteOutline, {}) })] }));
83
+ const spectraLengthPerTab = getSpectraByNucleus(activeTab, data)?.length;
84
+ return (_jsxs(DefaultPanelHeader, { onDelete: handleDelete, counter: data?.length, counterLabel: createFilterLabel(data?.length, spectraLengthPerTab), deleteToolTip: "Delete selected spectra", disableDelete: !hasActiveSpectra, showSettingButton: true, onSettingClick: onSettingClick, children: [_jsx(Button.BarButton, { toolTip: "Hide selected spectra", onClick: hideAllSpectrumsHandler, tooltipOrientation: "horizontal", disabled: !hasActiveSpectra, children: _jsx(FaEyeSlash, {}) }), _jsx(Button.BarButton, { onClick: showAllSpectrumsHandler, toolTip: "Show selected spectra", tooltipOrientation: "horizontal", disabled: !hasActiveSpectra, children: _jsx(FaEye, {}) }), displayerMode === '2D' && activeSpectrum?.info.isFt && (_jsx(Button.BarButton, { toolTip: "Add missing projection", tooltipOrientation: "horizontal", onClick: addMissingProjectionHandler, children: _jsx(FaCreativeCommonsSamplingPlus, {}) })), displayerMode === '1D' && spectraLengthPerTab > 1 && (_jsxs(_Fragment, { children: [_jsx(Button.BarButton, { tooltipOrientation: "horizontal", toolTip: "Reset scale", onClick: resetScaleHandler, children: _jsx(SvgNmrResetScale, {}) }), _jsx(Button.BarButton, { tooltipOrientation: "horizontal", toolTip: "Same top", onClick: setSameTopHandler, children: _jsx(SvgNmrSameTop, {}) })] })), _jsx(SpectraAutomaticPickingButton, {}), _jsx(Button.BarButton, { tooltipOrientation: "horizontal", toolTip: "Recolor spectra", onClick: recolorSpectraHandler, children: _jsx(IoColorPaletteOutline, {}) })] }));
85
85
  }
86
86
  const MemoizedSpectraPanelHeader = memo(SpectraPanelHeaderInner);
87
87
  export default function SpectrumsTabs({ onSettingClick, }) {
@@ -1,5 +1,4 @@
1
- import { Spectrum } from 'nmr-load-save';
2
- import { ActiveSpectrum } from '../../reducer/Reducer';
1
+ import { ActiveSpectrum, Spectrum } from 'nmr-load-save';
3
2
  import { OnChangeVisibilityEvent } from './base/ShowHideSpectrumButton';
4
3
  interface SpectraTableProps extends OnChangeVisibilityEvent {
5
4
  data: any;
@@ -24,7 +24,9 @@ function getActiveSpectraAsObject(activeSpectra) {
24
24
  const result = {};
25
25
  if (activeSpectra) {
26
26
  for (const activeSpectrum of activeSpectra) {
27
- result[activeSpectrum.id] = true;
27
+ if (activeSpectrum?.selected) {
28
+ result[activeSpectrum.id] = true;
29
+ }
28
30
  }
29
31
  }
30
32
  return result;
@@ -1,6 +1,6 @@
1
1
  import { Correlation, Link } from 'nmr-correlation';
2
- import { Spectrum2D, Spectrum } from 'nmr-load-save';
3
- import { ActiveSpectrum, DisplayerMode } from '../../../reducer/Reducer';
2
+ import { Spectrum2D, Spectrum, ActiveSpectrum } from 'nmr-load-save';
3
+ import { DisplayerMode } from '../../../reducer/Reducer';
4
4
  declare function getAtomType(nucleus: string): string;
5
5
  declare function getLabelColor(correlationData: any, correlation: any): string | null;
6
6
  declare function findSignalMatch1D(spectrum: Spectrum2D, link: Link, factor: number, xDomain0: number, xDomain1: number): boolean;
@@ -9,10 +9,6 @@ import { UsedColors } from '../../types/UsedColors';
9
9
  import { Action } from '../context/DispatchContext';
10
10
  import { Tool } from '../toolbar/ToolTypes';
11
11
  import { ZoomHistory } from './helper/ZoomHistoryManager';
12
- export interface ActiveSpectrum {
13
- id: string;
14
- index: number;
15
- }
16
12
  export type DisplayerMode = '1D' | '2D';
17
13
  export interface Pivot {
18
14
  value: number;
@@ -1,8 +1,9 @@
1
1
  import { Draft } from 'immer';
2
+ import { ActiveSpectrum } from 'nmr-load-save';
2
3
  import { BaselineCorrectionOptions, ApodizationOptions } from 'nmr-processing';
3
4
  import { ExclusionZone } from '../../../data/types/data1d/ExclusionZone';
4
5
  import { MatrixOptions } from '../../../data/types/data1d/MatrixOptions';
5
- import { ActiveSpectrum, State, TraceDirection } from '../Reducer';
6
+ import { State, TraceDirection } from '../Reducer';
6
7
  import { ActionType } from '../types/ActionType';
7
8
  type ShiftSpectrumAlongXAxisAction = ActionType<'SHIFT_SPECTRUM', {
8
9
  shift: number;
@@ -10,7 +10,7 @@ import { get2DXScale, get2DYScale } from '../../2d/utilities/scale';
10
10
  import { options as Tools } from '../../toolbar/ToolTypes';
11
11
  import { getSpectraByNucleus } from '../../utility/getSpectraByNucleus';
12
12
  import nucleusToString from '../../utility/nucleusToString';
13
- import { getInitialState, } from '../Reducer';
13
+ import { getInitialState } from '../Reducer';
14
14
  import zoomHistoryManager from '../helper/ZoomHistoryManager';
15
15
  import { getActiveSpectrum } from '../helper/getActiveSpectrum';
16
16
  import getRange from '../helper/getRange';
@@ -173,6 +173,7 @@ function handleChangeActiveSpectrum(draft, action) {
173
173
  newActiveSpectra.push({
174
174
  id: spectrumId,
175
175
  index: spectraObj[spectrumId].index,
176
+ selected: true,
176
177
  });
177
178
  }
178
179
  if (newActiveSpectra.length > 0) {
@@ -327,23 +327,25 @@ function setTabActiveSpectrum(draft, dataGroupByTab) {
327
327
  }
328
328
  if (data.length === 1) {
329
329
  const index = draft.data.findIndex((datum) => datum.id === data[0].id);
330
- tabActiveSpectrum[tabKey] = [{ id: data[0].id, index }];
330
+ tabActiveSpectrum[tabKey] = [{ id: data[0].id, index, selected: true }];
331
331
  }
332
332
  else {
333
333
  const tabSpectra = dataGroupByTab[tabKey];
334
334
  const tabSpectraLength = tabSpectra.length;
335
335
  if (tabSpectraLength >= 2) {
336
336
  const FTSpectrums = tabSpectra.filter((d) => !d.info.isFid);
337
- if (FTSpectrums.length > 0 &&
338
- (nucleusLength === 2 ||
339
- (nucleusLength === 1 && tabSpectraLength !== FTSpectrums.length))) {
337
+ if (FTSpectrums.length > 0) {
338
+ const selected = nucleusLength === 2 ||
339
+ (nucleusLength === 1 && tabSpectraLength !== FTSpectrums.length);
340
340
  const index = draft.data.findIndex((datum) => datum.id === FTSpectrums[0].id);
341
- tabActiveSpectrum[tabKey] = [{ id: FTSpectrums[0].id, index }];
341
+ tabActiveSpectrum[tabKey] = [
342
+ { id: FTSpectrums[0].id, index, selected },
343
+ ];
342
344
  }
343
345
  else if (tabSpectraLength - FTSpectrums > 0) {
344
346
  const id = tabSpectra[0].id;
345
347
  const index = draft.data.findIndex((datum) => datum.id === id);
346
- tabActiveSpectrum[tabKey] = [{ id, index }];
348
+ tabActiveSpectrum[tabKey] = [{ id, index, selected: true }];
347
349
  }
348
350
  else {
349
351
  tabActiveSpectrum[tabKey] = null;
@@ -1,4 +1,5 @@
1
1
  export function getActiveSpectra(state) {
2
2
  const { activeSpectra, activeTab } = state.view.spectra;
3
- return activeSpectra?.[activeTab] || null;
3
+ const spectra = activeSpectra?.[activeTab]?.filter((spectrum) => spectrum?.selected);
4
+ return Array.isArray(spectra) && spectra.length > 0 ? spectra : null;
4
5
  }
@@ -1,7 +1,7 @@
1
1
  export function getActiveSpectrum(state) {
2
2
  const { activeSpectra, activeTab } = state.view.spectra;
3
3
  const spectra = activeSpectra[activeTab];
4
- if (spectra?.length === 1) {
4
+ if (spectra?.length === 1 && spectra[0]?.selected) {
5
5
  return spectra[0];
6
6
  }
7
7
  return null;
@@ -18,6 +18,6 @@ function formatNumber(number) {
18
18
  return `${number / 1024}K`;
19
19
  }
20
20
  else {
21
- return number;
21
+ return `${number}`;
22
22
  }
23
23
  }
@@ -1 +1 @@
1
- export default { version: 'v0.45.0' };
1
+ export default { version: 'v0.45.1-pre.1701344673' };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nmrium",
3
3
  "description": "React component to display and process nuclear magnetic resonance (NMR) spectra.",
4
- "version": "0.45.0",
4
+ "version": "0.45.1-pre.1701344673",
5
5
  "license": "MIT",
6
6
  "module": "lib/component/main/index.js",
7
7
  "types": "lib/component/main/index.d.ts",
@@ -85,7 +85,7 @@
85
85
  "ml-stat": "^1.3.3",
86
86
  "multiplet-analysis": "^2.1.2",
87
87
  "nmr-correlation": "^2.3.3",
88
- "nmr-load-save": "^0.23.6",
88
+ "nmr-load-save": "^0.23.8",
89
89
  "nmr-processing": "^11.6.0",
90
90
  "nmredata": "^0.9.7",
91
91
  "numeral": "^2.0.6",