nmrium 0.54.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.
Files changed (106) hide show
  1. package/lib/component/1d/XAxis.js +1 -1
  2. package/lib/component/1d/integral/IntegralsSeries.js +2 -2
  3. package/lib/component/1d/integral/Integration.d.ts +3 -1
  4. package/lib/component/1d/integral/Integration.js +3 -2
  5. package/lib/component/1d/peaks/PeakEditionManager.js +5 -3
  6. package/lib/component/1d/ranges/AssignmentActionsButtons.d.ts +1 -0
  7. package/lib/component/1d/ranges/AssignmentActionsButtons.js +3 -3
  8. package/lib/component/1d/ranges/AssignmentLabel.d.ts +1 -1
  9. package/lib/component/1d/ranges/AssignmentLabel.js +31 -4
  10. package/lib/component/1d/ranges/Atoms.js +4 -5
  11. package/lib/component/1d/ranges/Range.js +48 -6
  12. package/lib/component/1d/ranges/Ranges.js +2 -1
  13. package/lib/component/1d/ranges/RangesIntegrals.js +11 -4
  14. package/lib/component/1d-2d/FieldEdition.d.ts +13 -0
  15. package/lib/component/1d-2d/FieldEdition.js +42 -0
  16. package/lib/component/2d/Chart2D.js +5 -3
  17. package/lib/component/2d/zones/Zone.js +18 -2
  18. package/lib/component/2d/zones/ZonesAssignmentsLabels.d.ts +7 -0
  19. package/lib/component/2d/zones/ZonesAssignmentsLabels.js +286 -0
  20. package/lib/component/EventsTrackers/KeysListenerTracker.js +14 -1
  21. package/lib/component/context/ShareDataContext.d.ts +10 -0
  22. package/lib/component/context/ShareDataContext.js +22 -0
  23. package/lib/component/elements/ActionsButtonsPopover.d.ts +10 -0
  24. package/lib/component/elements/ActionsButtonsPopover.js +22 -0
  25. package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +7 -5
  26. package/lib/component/elements/ReactTable/ReactTable.d.ts +2 -2
  27. package/lib/component/elements/SVGButton.d.ts +14 -0
  28. package/lib/component/elements/SVGButton.js +6 -0
  29. package/lib/component/elements/SVGGroup.js +15 -13
  30. package/lib/component/elements/SVGText.d.ts +8 -0
  31. package/lib/component/elements/SVGText.js +24 -0
  32. package/lib/component/elements/draggable/SVGDraggable.d.ts +2 -2
  33. package/lib/component/elements/formik/FormikInput.d.ts +2 -1
  34. package/lib/component/elements/formik/FormikInput.js +4 -3
  35. package/lib/component/header/Header.js +7 -10
  36. package/lib/component/hooks/useActiveSpectrumZonesViewState.js +1 -0
  37. package/lib/component/hooks/useCheckPointsNumberInWindowArea.d.ts +1 -1
  38. package/lib/component/hooks/useFormatNumberByNucleus.d.ts +1 -1
  39. package/lib/component/hooks/useFormatNumberByNucleus.js +8 -7
  40. package/lib/component/hooks/useIntegralPath.d.ts +2 -0
  41. package/lib/component/hooks/useIntegralPath.js +3 -1
  42. package/lib/component/hooks/usePanelPreferences.js +1 -2
  43. package/lib/component/hooks/useSaveSettings.js +7 -14
  44. package/lib/component/hooks/useTriggerNewAssignmentLabel.d.ts +4 -0
  45. package/lib/component/hooks/useTriggerNewAssignmentLabel.js +8 -0
  46. package/lib/component/hooks/useWorkspaceAction.d.ts +7 -0
  47. package/lib/component/hooks/useWorkspaceAction.js +89 -0
  48. package/lib/component/loader/DropZone.js +0 -3
  49. package/lib/component/main/InnerNMRium.js +3 -1
  50. package/lib/component/main/InnerNMRiumContents.js +14 -2
  51. package/lib/component/main/NMRiumStateProvider.js +4 -2
  52. package/lib/component/modal/editRange/forms/components/DeltaInput.js +3 -3
  53. package/lib/component/modal/editRange/forms/components/NewSignalTab.js +17 -12
  54. package/lib/component/modal/editRange/forms/components/signal-tabs/SignalJCouplingsTable.js +30 -13
  55. package/lib/component/modal/editRange/forms/components/signal-tabs/SignalPeaksTable.js +26 -16
  56. package/lib/component/modal/setting/GeneralSettings.js +7 -21
  57. package/lib/component/modal/setting/WorkspaceItem.js +1 -1
  58. package/lib/component/modal/setting/settings-tabs/NucleiTabContent.d.ts +2 -0
  59. package/lib/component/modal/setting/settings-tabs/NucleiTabContent.js +99 -0
  60. package/lib/component/modal/setting/settingsValidation.js +36 -40
  61. package/lib/component/panels/SpectraPanel/SpectraPreferences.js +13 -1
  62. package/lib/component/panels/SpectraPanel/base/setting/PlotChart.js +1 -1
  63. package/lib/component/panels/SpectraPanel/base/setting/Spectrum2DHistogram.js +1 -1
  64. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentLabelColumn.d.ts +6 -0
  65. package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentLabelColumn.js +16 -0
  66. package/lib/component/panels/ZonesPanel/ZonesPanel.js +18 -2
  67. package/lib/component/panels/ZonesPanel/ZonesPreferences.js +15 -9
  68. package/lib/component/panels/ZonesPanel/ZonesTable.js +2 -2
  69. package/lib/component/panels/ZonesPanel/ZonesTableRow.js +3 -2
  70. package/lib/component/panels/multipleAnalysisPanel/preferences/index.js +1 -1
  71. package/lib/component/reducer/IgnoreActions.js +1 -0
  72. package/lib/component/reducer/Reducer.js +6 -0
  73. package/lib/component/reducer/actions/DomainActions.d.ts +7 -2
  74. package/lib/component/reducer/actions/DomainActions.js +29 -1
  75. package/lib/component/reducer/actions/RangesActions.js +12 -6
  76. package/lib/component/reducer/actions/ZonesActions.d.ts +15 -2
  77. package/lib/component/reducer/actions/ZonesActions.js +47 -13
  78. package/lib/component/reducer/helper/setRangesViewProperty.d.ts +1 -0
  79. package/lib/component/reducer/helper/setRangesViewProperty.js +11 -11
  80. package/lib/component/reducer/preferences/actions/addWorkspace.js +4 -23
  81. package/lib/component/reducer/preferences/actions/analyzeSpectra.js +4 -4
  82. package/lib/component/reducer/preferences/actions/initPreferences.js +2 -4
  83. package/lib/component/reducer/preferences/actions/matrixGeneration.js +3 -3
  84. package/lib/component/reducer/preferences/actions/removeWorkspace.js +0 -5
  85. package/lib/component/reducer/preferences/actions/setActiveWorkspace.js +0 -4
  86. package/lib/component/reducer/preferences/actions/setPanelsPreferences.js +1 -1
  87. package/lib/component/reducer/preferences/actions/setPreferences.js +2 -16
  88. package/lib/component/reducer/preferences/preferencesReducer.d.ts +7 -0
  89. package/lib/component/reducer/preferences/preferencesReducer.js +21 -18
  90. package/lib/component/toolbar/ToolBar.js +18 -14
  91. package/lib/component/utility/PreferencesHelper.js +5 -4
  92. package/lib/component/utility/export.js +4 -0
  93. package/lib/component/workspaces/assignment.js +0 -1
  94. package/lib/component/workspaces/basic.js +0 -1
  95. package/lib/component/workspaces/embedded.js +0 -1
  96. package/lib/component/workspaces/exercise.js +26 -29
  97. package/lib/component/workspaces/prediction.js +171 -174
  98. package/lib/component/workspaces/process1D.js +0 -1
  99. package/lib/component/workspaces/simulation.js +35 -38
  100. package/lib/component/workspaces/workspaceDefaultProperties.js +9 -11
  101. package/lib/versionInfo.js +1 -1
  102. package/package.json +31 -31
  103. package/lib/component/modal/setting/settings-tabs/FormattingTabContent.d.ts +0 -2
  104. package/lib/component/modal/setting/settings-tabs/FormattingTabContent.js +0 -80
  105. package/lib/component/reducer/preferences/utilities/mapNucleiFormatting.d.ts +0 -2
  106. package/lib/component/reducer/preferences/utilities/mapNucleiFormatting.js +0 -10
@@ -190,6 +190,34 @@ function handleSetYDomain(draft, action) {
190
190
  draft.yDomain = yDomain;
191
191
  addToBrushHistory(draft, { xDomain: draft.xDomain, yDomain });
192
192
  }
193
+ //action
194
+ function handleSetAxisDomain(draft, action) {
195
+ const { nucleiPreferences } = action.payload;
196
+ const { originDomain: { xDomain, yDomain }, displayerMode, view: { spectra: { activeTab }, }, } = draft;
197
+ const axisDomain = {};
198
+ const [xNucleus, yNucleus] = activeTab?.split(',') || [];
199
+ for (const nuclei of nucleiPreferences) {
200
+ const { nucleus, axisFrom, axisTo } = nuclei;
201
+ if (nucleus?.toLowerCase() === xNucleus?.toLowerCase()) {
202
+ axisDomain.x = { from: axisFrom, to: axisTo };
203
+ }
204
+ if (nucleus?.toLowerCase() === yNucleus?.toLowerCase()) {
205
+ axisDomain.y = { from: axisFrom, to: axisTo };
206
+ }
207
+ }
208
+ const { x, y } = axisDomain;
209
+ const x1 = x?.from ?? xDomain[0];
210
+ const x2 = x?.to ?? xDomain[1];
211
+ const y1 = y?.from ?? yDomain[0];
212
+ const y2 = y?.to ?? yDomain[1];
213
+ if (displayerMode === '1D') {
214
+ draft.xDomain = [x1, x2];
215
+ }
216
+ else {
217
+ draft.xDomain = [x1, x2];
218
+ draft.yDomain = [y1, y2];
219
+ }
220
+ }
193
221
  function handleMoveOverXAxis(draft, action) {
194
222
  const { shiftX, shiftY } = action.payload;
195
223
  const [x1, x2] = draft.xDomain;
@@ -219,4 +247,4 @@ function handleMoveOverXAxis(draft, action) {
219
247
  draft.xDomain = [x1Domain, x2Domain];
220
248
  draft.yDomain = [y1Domain, y2Domain];
221
249
  }
222
- export { getDomain, setDomain, setMode, handleSetXDomain, handleSetYDomain, handleMoveOverXAxis, };
250
+ export { getDomain, setDomain, setMode, handleSetXDomain, handleSetYDomain, handleMoveOverXAxis, handleSetAxisDomain, };
@@ -9,7 +9,7 @@ import { initSumOptions, setSumOptions, } from '../../../data/data1d/Spectrum1D/
9
9
  import { unlink, unlinkInAssignmentData, } from '../../../data/utilities/RangeUtilities';
10
10
  import { getActiveSpectrum } from '../helper/getActiveSpectrum';
11
11
  import { getSpectrum } from '../helper/getSpectrum';
12
- import { setRangesViewProperty } from '../helper/setRangesViewProperty';
12
+ import { initializeRangeViewObject, setRangesViewProperty, } from '../helper/setRangesViewProperty';
13
13
  import { handleUpdateCorrelations } from './CorrelationsActions';
14
14
  import { setDomain } from './DomainActions';
15
15
  import { toggleDisplayingPeaks } from './PeaksActions';
@@ -368,11 +368,17 @@ function handleChangeRangeAssignmentLabel(draft, action) {
368
368
  if (activeSpectrum?.id) {
369
369
  const { index } = activeSpectrum;
370
370
  const spectrum = draft.data[index];
371
- if (isSpectrum1D(spectrum)) {
372
- const range = spectrum.ranges.values.find((range) => range.id === rangeID);
373
- if (range) {
374
- range.assignment = value;
375
- }
371
+ if (!isSpectrum1D(spectrum)) {
372
+ return;
373
+ }
374
+ initializeRangeViewObject(draft, activeSpectrum.id);
375
+ const rangesView = draft.view.ranges[spectrum.id];
376
+ if (!rangesView.showAssignmentsLabels) {
377
+ rangesView.showAssignmentsLabels = true;
378
+ }
379
+ const range = spectrum.ranges.values.find((range) => range.id === rangeID);
380
+ if (range) {
381
+ range.assignment = value;
376
382
  }
377
383
  }
378
384
  }
@@ -65,7 +65,18 @@ type UnlinkZoneAction = ActionType<'UNLINK_ZONE', UnlinkZoneProps>;
65
65
  type ToggleZonesViewAction = ActionType<'TOGGLE_ZONES_VIEW_PROPERTY', {
66
66
  key: keyof FilterType<ZonesViewState, boolean>;
67
67
  }>;
68
- export type ZonesActions = AutoZonesDetectionAction | ChangeZonesFactorAction | Add2dZoneAction | ChangeZoneSignalDeltaAction | ChangeZoneSignalKindAction | DeleteZoneAction | DeleteSignal2DAction | SetSignalPathLengthAction | SetZoneDiaIDAction | SaveEditedZoneAction | UnlinkZoneAction | ToggleZonesViewAction | ActionType<'AUTO_ZONES_SPECTRA_PICKING'>;
68
+ type ChangeZoneAssignmentLabelAction = ActionType<'CHANGE_ZONE_ASSIGNMENT_LABEL', {
69
+ zoneID: string;
70
+ value: string;
71
+ }>;
72
+ type SetZoneAssignmentLabelCoordinationAction = ActionType<'SET_ZONE_ASSIGNMENT_LABEL_COORDINATION', {
73
+ zoneID: string;
74
+ coordination: {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ }>;
79
+ export type ZonesActions = AutoZonesDetectionAction | ChangeZonesFactorAction | Add2dZoneAction | ChangeZoneSignalDeltaAction | ChangeZoneSignalKindAction | DeleteZoneAction | DeleteSignal2DAction | SetSignalPathLengthAction | SetZoneDiaIDAction | SaveEditedZoneAction | UnlinkZoneAction | ToggleZonesViewAction | ChangeZoneAssignmentLabelAction | SetZoneAssignmentLabelCoordinationAction | ActionType<'AUTO_ZONES_SPECTRA_PICKING'>;
69
80
  declare function handleChangeZonesFactor(draft: Draft<State>, action: ChangeZonesFactorAction): void;
70
81
  declare function handleAdd2dZone(draft: Draft<State>, action: Add2dZoneAction): void;
71
82
  declare function handleAutoZonesDetection(draft: Draft<State>, action: AutoZonesDetectionAction): void;
@@ -81,4 +92,6 @@ declare function handleUnlinkZone(draft: Draft<State>, action: UnlinkZoneAction)
81
92
  declare function handleSetDiaIDZone(draft: Draft<State>, action: SetZoneDiaIDAction): void;
82
93
  declare function handleSaveEditedZone(draft: Draft<State>, action: SaveEditedZoneAction): void;
83
94
  declare function handleToggleZonesViewProperty(draft: Draft<State>, action: ToggleZonesViewAction): void;
84
- export { handleAdd2dZone, handleAutoZonesDetection, handleDeleteSignal, deleteSignal2D, handleDeleteZone, handleChangeZoneSignalDelta, handleChangeZoneSignalKind, handleUnlinkZone, unlinkZone, handleSaveEditedZone, handleSetDiaIDZone, handleSetSignalPathLength, handleChangeZonesFactor, handleAutoSpectraZonesDetection, handleToggleZonesViewProperty, };
95
+ declare function handleChangeZoneAssignmentLabel(draft: Draft<State>, action: ChangeZoneAssignmentLabelAction): void;
96
+ declare function handleSetZoneAssignmentLabelCoordination(draft: Draft<State>, action: SetZoneAssignmentLabelCoordinationAction): void;
97
+ export { handleAdd2dZone, handleAutoZonesDetection, handleDeleteSignal, deleteSignal2D, handleDeleteZone, handleChangeZoneSignalDelta, handleChangeZoneSignalKind, handleUnlinkZone, unlinkZone, handleSaveEditedZone, handleSetDiaIDZone, handleSetSignalPathLength, handleChangeZonesFactor, handleAutoSpectraZonesDetection, handleToggleZonesViewProperty, handleChangeZoneAssignmentLabel, handleSetZoneAssignmentLabelCoordination, };
@@ -3,7 +3,7 @@ import lodashCloneDeep from 'lodash/cloneDeep';
3
3
  import { setPathLength } from 'nmr-correlation';
4
4
  import { Filters, FiltersManager } from 'nmr-processing';
5
5
  import { DATUM_KIND, SIGNAL_INLCUDED_KINDS, } from '../../../data/constants/signalsKinds';
6
- import { changeZoneSignal, detectZones, detectZonesManual, } from '../../../data/data2d/Spectrum2D';
6
+ import { changeZoneSignal, detectZones, detectZonesManual, isSpectrum2D, } from '../../../data/data2d/Spectrum2D';
7
7
  import { unlink, unlinkInAssignmentData, } from '../../../data/utilities/ZoneUtilities';
8
8
  import { isNumber } from '../../../data/utilities/isNumber';
9
9
  import { defaultZonesViewState } from '../../hooks/useActiveSpectrumZonesViewState';
@@ -233,23 +233,57 @@ function handleSaveEditedZone(draft, action) {
233
233
  handleUpdateCorrelations(draft);
234
234
  }
235
235
  }
236
+ function initializeZoneViewObject(draft, spectrumID) {
237
+ const zonesView = draft.view.zones;
238
+ if (spectrumID in zonesView)
239
+ return;
240
+ const defaultZonesView = { ...defaultZonesViewState };
241
+ zonesView[spectrumID] = defaultZonesView;
242
+ }
236
243
  function togglePeaksViewProperty(draft, key) {
237
244
  const activeSpectrum = getActiveSpectrum(draft);
238
- if (activeSpectrum?.id) {
239
- const zonesView = draft.view.zones;
240
- if (zonesView[activeSpectrum.id]) {
241
- zonesView[activeSpectrum.id][key] = !zonesView[activeSpectrum.id][key];
242
- }
243
- else {
244
- const defaultZonesView = { ...defaultZonesViewState };
245
- defaultZonesView[key] = !defaultZonesView[key];
246
- zonesView[activeSpectrum.id] = defaultZonesView;
247
- }
248
- }
245
+ if (!activeSpectrum?.id)
246
+ return;
247
+ initializeZoneViewObject(draft, activeSpectrum.id);
248
+ const zonesView = draft.view.zones;
249
+ zonesView[activeSpectrum.id][key] = !zonesView[activeSpectrum.id][key];
249
250
  }
250
251
  //action
251
252
  function handleToggleZonesViewProperty(draft, action) {
252
253
  const { key } = action.payload;
253
254
  togglePeaksViewProperty(draft, key);
254
255
  }
255
- export { handleAdd2dZone, handleAutoZonesDetection, handleDeleteSignal, deleteSignal2D, handleDeleteZone, handleChangeZoneSignalDelta, handleChangeZoneSignalKind, handleUnlinkZone, unlinkZone, handleSaveEditedZone, handleSetDiaIDZone, handleSetSignalPathLength, handleChangeZonesFactor, handleAutoSpectraZonesDetection, handleToggleZonesViewProperty, };
256
+ function handleChangeZoneAssignmentLabel(draft, action) {
257
+ const { zoneID, value } = action.payload;
258
+ const activeSpectrum = getActiveSpectrum(draft);
259
+ if (!activeSpectrum?.id)
260
+ return;
261
+ const { index } = activeSpectrum;
262
+ const spectrum = draft.data[index];
263
+ if (!isSpectrum2D(spectrum))
264
+ return;
265
+ initializeZoneViewObject(draft, activeSpectrum.id);
266
+ const zoneView = draft.view.zones[spectrum.id];
267
+ if (!zoneView.showAssignmentsLabels) {
268
+ zoneView.showAssignmentsLabels = true;
269
+ }
270
+ const zone = spectrum.zones.values.find((zone) => zone.id === zoneID);
271
+ if (zone) {
272
+ zone.assignment = value;
273
+ if (!value) {
274
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
275
+ delete zoneView.assignmentsLabelsCoordinates[zoneID];
276
+ }
277
+ }
278
+ }
279
+ function handleSetZoneAssignmentLabelCoordination(draft, action) {
280
+ const { zoneID, coordination } = action.payload;
281
+ const activeSpectrum = getActiveSpectrum(draft);
282
+ if (!activeSpectrum)
283
+ return;
284
+ initializeZoneViewObject(draft, activeSpectrum.id);
285
+ const zonesView = draft.view.zones;
286
+ zonesView[activeSpectrum.id].assignmentsLabelsCoordinates[zoneID] =
287
+ coordination;
288
+ }
289
+ export { handleAdd2dZone, handleAutoZonesDetection, handleDeleteSignal, deleteSignal2D, handleDeleteZone, handleChangeZoneSignalDelta, handleChangeZoneSignalKind, handleUnlinkZone, unlinkZone, handleSaveEditedZone, handleSetDiaIDZone, handleSetSignalPathLength, handleChangeZonesFactor, handleAutoSpectraZonesDetection, handleToggleZonesViewProperty, handleChangeZoneAssignmentLabel, handleSetZoneAssignmentLabelCoordination, };
@@ -3,3 +3,4 @@ import { RangesViewState } from 'nmr-load-save';
3
3
  import { State } from '../Reducer';
4
4
  export declare function setRangesViewProperty<T extends keyof RangesViewState>(draft: Draft<State>, key: T, value: (value: RangesViewState[T]) => RangesViewState[T]): void;
5
5
  export declare function setRangesViewProperty<T extends keyof RangesViewState>(draft: Draft<State>, key: T, value: RangesViewState[T]): void;
6
+ export declare function initializeRangeViewObject(draft: Draft<State>, spectrumID: string): void;
@@ -1,19 +1,19 @@
1
1
  import { defaultRangesViewState } from '../../hooks/useActiveSpectrumRangesViewState';
2
2
  import { getActiveSpectrum } from './getActiveSpectrum';
3
3
  export function setRangesViewProperty(draft, key, value) {
4
- const viewData = draft.view.ranges;
4
+ const rangesView = draft.view.ranges;
5
5
  const activeSpectrum = getActiveSpectrum(draft);
6
6
  if (!activeSpectrum?.id)
7
7
  return;
8
8
  const id = activeSpectrum.id;
9
- if (viewData[id]) {
10
- viewData[id][key] =
11
- typeof value === 'function' ? value(viewData[id][key]) : value;
12
- }
13
- else {
14
- const defaultView = { ...defaultRangesViewState };
15
- defaultView[key] =
16
- typeof value === 'function' ? value(defaultView[key]) : value;
17
- viewData[id] = defaultView;
18
- }
9
+ initializeRangeViewObject(draft, id);
10
+ rangesView[id][key] =
11
+ typeof value === 'function' ? value(rangesView[id][key]) : value;
12
+ }
13
+ export function initializeRangeViewObject(draft, spectrumID) {
14
+ const rangesView = draft.view.ranges;
15
+ if (spectrumID in rangesView)
16
+ return;
17
+ const defaultRangesView = { ...defaultRangesViewState };
18
+ rangesView[spectrumID] = defaultRangesView;
19
19
  }
@@ -1,27 +1,8 @@
1
- import { v4 } from '@lukeed/uuid';
2
- import lodashMerge from 'lodash/merge';
3
- import { getLocalStorage, storeData } from '../../../utility/LocalStorage';
4
- import { workspaceDefaultProperties } from '../../../workspaces/workspaceDefaultProperties';
5
1
  export function addWorkspace(draft, action) {
6
2
  const { workspaceKey, data } = action.payload;
7
- // eslint-disable-next-line unicorn/prefer-logical-operator-over-ternary
8
- const workSpaceData = data
9
- ? data
10
- : draft.workspaces?.[draft.workspace.current];
11
- if (workSpaceData) {
12
- const newWorkSpace = lodashMerge({}, workspaceDefaultProperties, workSpaceData, {
13
- version: 1,
14
- label: workspaceKey,
15
- source: 'user',
16
- });
17
- const newWorkspaceKey = v4();
18
- const localData = getLocalStorage('nmr-general-settings');
19
- localData.currentWorkspace = newWorkspaceKey;
20
- localData.workspaces[newWorkspaceKey] = newWorkSpace;
21
- storeData('nmr-general-settings', JSON.stringify(localData));
22
- draft.workspaces[newWorkspaceKey] = newWorkSpace;
23
- draft.originalWorkspaces[newWorkspaceKey] =
24
- newWorkSpace;
25
- draft.workspace.current = newWorkspaceKey;
3
+ if (data) {
4
+ draft.workspaces[workspaceKey] = data;
5
+ draft.originalWorkspaces[workspaceKey] = data;
6
+ draft.workspace.current = workspaceKey;
26
7
  }
27
8
  }
@@ -4,7 +4,7 @@ import { getMultipleSpectraAnalysisDefaultValues } from '../panelsPreferencesDef
4
4
  import { getActiveWorkspace } from '../utilities/getActiveWorkspace';
5
5
  export function analyzeSpectra(draft, action) {
6
6
  const currentWorkspacePreferences = getActiveWorkspace(draft);
7
- const panels = currentWorkspacePreferences.formatting.panels;
7
+ const panels = currentWorkspacePreferences.panels;
8
8
  const { start, end, nucleus, columnKey } = action.payload;
9
9
  if (!panels.multipleSpectraAnalysis) {
10
10
  panels.multipleSpectraAnalysis =
@@ -21,20 +21,20 @@ export function analyzeSpectra(draft, action) {
21
21
  export function changeAnalysisColumnValueKey(draft, action) {
22
22
  const { columnKey, valueKey, nucleus } = action.payload;
23
23
  const currentWorkspacePreferences = getActiveWorkspace(draft);
24
- const panels = currentWorkspacePreferences.formatting.panels;
24
+ const panels = currentWorkspacePreferences.panels;
25
25
  MultipleAnalysis.changeColumnValueKey(panels.multipleSpectraAnalysis, nucleus, columnKey, valueKey);
26
26
  }
27
27
  export function deleteAnalysisColumn(draft, action) {
28
28
  const { columnKey, nucleus } = action.payload;
29
29
  const currentWorkspacePreferences = getActiveWorkspace(draft);
30
- const panels = currentWorkspacePreferences.formatting.panels;
30
+ const panels = currentWorkspacePreferences.panels;
31
31
  MultipleAnalysis.deleteSpectraAnalysis(panels.multipleSpectraAnalysis, columnKey, nucleus);
32
32
  }
33
33
  export function setSpectraAnalysisPanelsPreferences(draft, action) {
34
34
  if (action.payload) {
35
35
  const currentWorkspacePreferences = getActiveWorkspace(draft);
36
36
  const { nucleus, data } = action.payload;
37
- const panels = currentWorkspacePreferences.formatting.panels;
37
+ const panels = currentWorkspacePreferences.panels;
38
38
  if (!panels?.multipleSpectraAnalysis) {
39
39
  panels.multipleSpectraAnalysis =
40
40
  getMultipleSpectraAnalysisDefaultValues(nucleus);
@@ -1,4 +1,3 @@
1
- import { getLocalStorage } from '../../../utility/LocalStorage';
2
1
  import { WORKSPACES_KEYS } from '../preferencesReducer';
3
2
  import { initWorkspace } from '../utilities/initWorkspace';
4
3
  import { mapWorkspaces } from '../utilities/mapWorkspaces';
@@ -7,8 +6,7 @@ function getWorkspace(draft, workspace) {
7
6
  }
8
7
  export function initPreferences(draft, action) {
9
8
  if (action.payload) {
10
- const localData = getLocalStorage('nmr-general-settings');
11
- const { dispatch, workspace, customWorkspaces: cw, preferences, } = action.payload;
9
+ const { dispatch, workspace, customWorkspaces: cw, preferences, currentWorkspace, } = action.payload;
12
10
  const customWorkspaces = mapWorkspaces(cw, { source: 'custom' });
13
11
  draft.workspaces = {
14
12
  ...draft.workspaces,
@@ -39,7 +37,7 @@ export function initPreferences(draft, action) {
39
37
  };
40
38
  }
41
39
  else {
42
- const _workspace = getWorkspace(draft, localData.currentWorkspace);
40
+ const _workspace = getWorkspace(draft, currentWorkspace);
43
41
  draft.workspace = { current: _workspace, base: null };
44
42
  }
45
43
  if (preferences) {
@@ -3,7 +3,7 @@ import { getActiveWorkspace } from '../utilities/getActiveWorkspace';
3
3
  function addExclusionZone(draft, action) {
4
4
  const { zone, range, nucleus } = action.payload;
5
5
  const currentWorkspacePreferences = getActiveWorkspace(draft);
6
- const panels = currentWorkspacePreferences.formatting.panels;
6
+ const panels = currentWorkspacePreferences.panels;
7
7
  const exclusionZone = {
8
8
  id: v4(),
9
9
  ...zone,
@@ -27,7 +27,7 @@ function addExclusionZone(draft, action) {
27
27
  function deleteExclusionZone(draft, action) {
28
28
  const { zone, nucleus } = action.payload;
29
29
  const currentWorkspacePreferences = getActiveWorkspace(draft);
30
- const panels = currentWorkspacePreferences.formatting.panels;
30
+ const panels = currentWorkspacePreferences.panels;
31
31
  if (panels.matrixGeneration?.[nucleus]) {
32
32
  const options = panels.matrixGeneration[nucleus];
33
33
  options.exclusionsZones = options.exclusionsZones.filter((_zone) => _zone.id !== zone.id);
@@ -36,7 +36,7 @@ function deleteExclusionZone(draft, action) {
36
36
  function setMatrixGenerationOptions(draft, action) {
37
37
  const { options, nucleus } = action.payload;
38
38
  const currentWorkspacePreferences = getActiveWorkspace(draft);
39
- const panels = currentWorkspacePreferences.formatting.panels;
39
+ const panels = currentWorkspacePreferences.panels;
40
40
  panels.matrixGeneration = { ...panels.matrixGeneration, [nucleus]: options };
41
41
  }
42
42
  export { addExclusionZone, deleteExclusionZone, setMatrixGenerationOptions };
@@ -1,13 +1,8 @@
1
- import { getLocalStorage, storeData } from '../../../utility/LocalStorage';
2
1
  export function removeWorkspace(draft, action) {
3
2
  const { workspace } = action.payload;
4
3
  if (workspace === draft.workspace.current) {
5
4
  draft.workspace.current = 'default';
6
5
  }
7
- const localData = getLocalStorage('nmr-general-settings');
8
6
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
9
7
  delete draft.workspaces[workspace];
10
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
11
- delete localData.workspaces[workspace];
12
- storeData('nmr-general-settings', JSON.stringify(localData));
13
8
  }
@@ -1,10 +1,6 @@
1
- import { getLocalStorage, storeData } from '../../../utility/LocalStorage';
2
1
  export function setActiveWorkspace(draft, action) {
3
2
  if (action.payload) {
4
3
  const { workspace } = action.payload;
5
- const localData = getLocalStorage('nmr-general-settings');
6
4
  draft.workspace.current = workspace;
7
- localData.currentWorkspace = workspace;
8
- storeData('nmr-general-settings', JSON.stringify(localData));
9
5
  }
10
6
  }
@@ -3,7 +3,7 @@ export function setPanelsPreferences(draft, action) {
3
3
  if (action.payload) {
4
4
  const currentWorkspacePreferences = getActiveWorkspace(draft);
5
5
  const { key, value } = action.payload;
6
- const panels = currentWorkspacePreferences.formatting.panels;
6
+ const panels = currentWorkspacePreferences.panels;
7
7
  if (value?.nuclei) {
8
8
  const { nuclei, ...commonPreferences } = value;
9
9
  panels[key] = {
@@ -1,27 +1,13 @@
1
1
  import cloneDeep from 'lodash/cloneDeep';
2
- import { getLocalStorage, storeData } from '../../../utility/LocalStorage';
3
2
  import { getActiveWorkspace } from '../utilities/getActiveWorkspace';
4
- import { mapNucleiFormatting } from '../utilities/mapNucleiFormatting';
5
3
  export function setPreferences(draft, action) {
6
- const localData = getLocalStorage('nmr-general-settings');
7
4
  const currentWorkspacePreferences = getActiveWorkspace(draft);
8
5
  if (action.payload) {
9
- const { formatting, ...restPreferences } = action.payload;
6
+ const preferences = action.payload;
10
7
  draft.workspaces[draft.workspace.current] = {
11
8
  ...currentWorkspacePreferences,
12
- ...restPreferences,
13
- formatting: mapNucleiFormatting(formatting),
9
+ ...preferences,
14
10
  };
15
11
  }
16
- if (draft.workspaces[draft.workspace.current].source === 'user') {
17
- draft.workspaces[draft.workspace.current].version++;
18
- storeData('nmr-general-settings', JSON.stringify({
19
- ...localData,
20
- workspaces: {
21
- ...localData.workspaces,
22
- [draft.workspace.current]: draft.workspaces[draft.workspace.current],
23
- },
24
- }));
25
- }
26
12
  draft.originalWorkspaces[draft.workspace.current] = cloneDeep(draft.workspaces[draft.workspace.current]);
27
13
  }
@@ -8,6 +8,11 @@ export declare const WORKSPACES_KEYS: {
8
8
  componentKey: string;
9
9
  nmriumKey: string;
10
10
  };
11
+ export interface Settings {
12
+ version: number;
13
+ workspaces: Record<string, WorkspaceWithSource>;
14
+ currentWorkspace: any;
15
+ }
11
16
  type InitPreferencesAction = ActionType<'INIT_PREFERENCES', {
12
17
  display: NMRiumPreferences;
13
18
  workspace: NMRiumWorkspace;
@@ -101,6 +106,8 @@ export interface PreferencesState {
101
106
  };
102
107
  }
103
108
  export declare const preferencesInitialState: PreferencesState;
109
+ export declare function readSettings(): Settings;
110
+ export declare function updateSettings(settings: Settings): void;
104
111
  export declare function initPreferencesState(state: PreferencesState): PreferencesState;
105
112
  declare const preferencesReducer: Reducer<PreferencesState, any>;
106
113
  export default preferencesReducer;
@@ -1,5 +1,6 @@
1
1
  import { produce } from 'immer';
2
- import { getLocalStorage, removeData, storeData, } from '../../utility/LocalStorage';
2
+ import { CURRENT_EXPORT_VERSION, migrateSettings, } from 'nmr-load-save';
3
+ import { getLocalStorage, storeData } from '../../utility/LocalStorage';
3
4
  import Workspaces from '../../workspaces';
4
5
  import { addWorkspace } from './actions/addWorkspace';
5
6
  import { analyzeSpectra, changeAnalysisColumnValueKey, deleteAnalysisColumn, setSpectraAnalysisPanelsPreferences, } from './actions/analyzeSpectra';
@@ -13,7 +14,7 @@ import { setPreferences } from './actions/setPreferences';
13
14
  import { setVerticalSplitterPosition } from './actions/setVerticalSplitterPosition';
14
15
  import { setWorkspace } from './actions/setWorkspace';
15
16
  import { mapWorkspaces } from './utilities/mapWorkspaces';
16
- const LOCAL_STORAGE_VERSION = 17;
17
+ const LOCAL_STORAGE_SETTINGS_KEY = 'nmr-general-settings';
17
18
  export const WORKSPACES_KEYS = {
18
19
  componentKey: `nmrium-component-workspace`,
19
20
  nmriumKey: `nmrium-file-workspace`,
@@ -49,7 +50,7 @@ export const WORKSPACES = [
49
50
  },
50
51
  ];
51
52
  export const preferencesInitialState = {
52
- version: LOCAL_STORAGE_VERSION,
53
+ version: CURRENT_EXPORT_VERSION,
53
54
  workspaces: {},
54
55
  originalWorkspaces: {},
55
56
  dispatch: () => null,
@@ -58,26 +59,28 @@ export const preferencesInitialState = {
58
59
  base: null,
59
60
  },
60
61
  };
62
+ export function readSettings() {
63
+ const localData = getLocalStorage(LOCAL_STORAGE_SETTINGS_KEY) || {
64
+ version: CURRENT_EXPORT_VERSION,
65
+ currentWorkspace: null,
66
+ workspaces: {},
67
+ };
68
+ return migrateSettings(localData);
69
+ }
70
+ export function updateSettings(settings) {
71
+ storeData(LOCAL_STORAGE_SETTINGS_KEY, JSON.stringify(settings));
72
+ }
61
73
  export function initPreferencesState(state) {
62
- const nmrLocalStorageVersion = getLocalStorage('nmr-local-storage-version', false);
63
- const localData = getLocalStorage('nmr-general-settings');
64
- // remove old nmr-local-storage-version key
65
- if (nmrLocalStorageVersion && localData?.version) {
66
- removeData('nmr-local-storage-version');
67
- }
74
+ const localData = getLocalStorage(LOCAL_STORAGE_SETTINGS_KEY);
75
+ const settings = readSettings();
68
76
  // if the local setting version != current settings version number
69
- if (!localData?.version || localData?.version !== LOCAL_STORAGE_VERSION) {
70
- removeData('nmr-general-settings');
71
- const data = {
72
- version: LOCAL_STORAGE_VERSION,
73
- workspaces: {},
74
- };
75
- storeData('nmr-general-settings', JSON.stringify(data));
77
+ if (localData?.version !== CURRENT_EXPORT_VERSION) {
78
+ updateSettings(settings);
76
79
  }
77
80
  const predefinedWorkspaces = mapWorkspaces(Workspaces, {
78
81
  source: 'predefined',
79
82
  });
80
- const localWorkspaces = mapWorkspaces(localData?.workspaces || {}, {
83
+ const localWorkspaces = mapWorkspaces(settings?.workspaces || {}, {
81
84
  source: 'user',
82
85
  });
83
86
  return {
@@ -85,7 +88,7 @@ export function initPreferencesState(state) {
85
88
  originalWorkspaces: { ...predefinedWorkspaces, ...localWorkspaces },
86
89
  workspaces: { ...predefinedWorkspaces, ...localWorkspaces },
87
90
  workspace: {
88
- current: localData?.currentWorkspace || 'default',
91
+ current: settings?.currentWorkspace || 'default',
89
92
  base: null,
90
93
  },
91
94
  };