nmrium 0.25.0 → 0.26.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/multiplicityTree/MultiplicityTree.js +5 -5
- package/lib/component/1d/ranges/Range.js +6 -5
- package/lib/component/2d/zones/Signal.js +8 -8
- package/lib/component/2d/zones/Zone.js +3 -3
- package/lib/component/EventsTrackers/KeysListenerTracker.js +1 -1
- package/lib/component/assignment/AssignmentsContext.d.ts +35 -0
- package/lib/component/assignment/AssignmentsContext.js +83 -0
- package/lib/component/assignment/AssignmentsReducer.d.ts +32 -0
- package/lib/component/assignment/AssignmentsReducer.js +39 -0
- package/lib/component/assignment/actions/initAssignment.d.ts +5 -0
- package/lib/component/assignment/actions/initAssignment.js +62 -0
- package/lib/component/assignment/actions/removeAssignment.d.ts +16 -0
- package/lib/component/assignment/actions/removeAssignment.js +24 -0
- package/lib/component/assignment/actions/setActiveAssignment.d.ts +10 -0
- package/lib/component/assignment/actions/setActiveAssignment.js +8 -0
- package/lib/component/assignment/actions/toggleAssignment.d.ts +7 -0
- package/lib/component/assignment/actions/toggleAssignment.js +44 -0
- package/lib/component/assignment/index.d.ts +0 -18
- package/lib/component/assignment/index.js +12 -266
- package/lib/component/assignment/utilities/filterForIDsWithAssignment.d.ts +2 -0
- package/lib/component/assignment/utilities/filterForIDsWithAssignment.js +3 -0
- package/lib/component/elements/Button.js +2 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.d.ts +5 -1
- package/lib/component/elements/ReactTable/Elements/ReactTableRow.js +38 -10
- package/lib/component/elements/ReactTable/ReactTable.d.ts +3 -1
- package/lib/component/elements/ReactTable/ReactTable.js +7 -2
- package/lib/component/elements/ReactTable/Style.d.ts +1 -3
- package/lib/component/elements/ReactTable/Style.js +1 -7
- package/lib/component/header/BaseLineCorrectionPanel.js +1 -1
- package/lib/component/modal/setting/FormattingTabContent.js +17 -11
- package/lib/component/modal/setting/GeneralSettings.js +2 -1
- package/lib/component/modal/setting/settingsValidation.d.ts +8 -0
- package/lib/component/modal/setting/settingsValidation.js +40 -0
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignment.js +6 -4
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignmentTable.d.ts +4 -3
- package/lib/component/panels/AutomaticAssignment/AutomaticAssignmentTable.js +13 -6
- package/lib/component/panels/AutomaticAssignment/useAutoAssignments.d.ts +10 -0
- package/lib/component/panels/AutomaticAssignment/useAutoAssignments.js +60 -0
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +1 -1
- package/lib/component/panels/MoleculesPanel/Utilities.d.ts +20 -11
- package/lib/component/panels/MoleculesPanel/Utilities.js +50 -68
- package/lib/component/panels/MoleculesPanel/useAtomAssignment.d.ts +2 -2
- package/lib/component/panels/MoleculesPanel/useAtomAssignment.js +55 -60
- package/lib/component/panels/RangesPanel/RangesHeader.js +2 -2
- package/lib/component/panels/RangesPanel/RangesPanel.js +1 -1
- package/lib/component/panels/RangesPanel/RangesTableRow.js +12 -11
- package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.d.ts +16 -9
- package/lib/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.js +2 -2
- package/lib/component/panels/RangesPanel/TableColumns/SignalAssignmentsColumn.d.ts +2 -3
- package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +1 -1
- package/lib/component/panels/SpectrumsPanel/SpectraPanelHeader.js +5 -18
- package/lib/component/panels/SummaryPanel/SummaryPanel.js +1 -1
- package/lib/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +1 -1
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.d.ts +5 -7
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.js +2 -2
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.d.ts +4 -8
- package/lib/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.js +1 -1
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.d.ts +5 -9
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.js +4 -4
- package/lib/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumns.d.ts +4 -8
- package/lib/component/panels/ZonesPanel/ZonesPanel.js +1 -1
- package/lib/component/panels/ZonesPanel/ZonesTableRow.d.ts +2 -1
- package/lib/component/panels/ZonesPanel/ZonesTableRow.js +20 -20
- package/lib/component/panels/header/SpectraAutomaticPickingButton.d.ts +2 -0
- package/lib/component/panels/header/SpectraAutomaticPickingButton.js +30 -0
- package/lib/component/reducer/Reducer.d.ts +2 -0
- package/lib/component/reducer/Reducer.js +4 -1
- package/lib/component/reducer/actions/AssignmentsActions.d.ts +9 -0
- package/lib/component/reducer/actions/AssignmentsActions.js +18 -0
- package/lib/component/reducer/actions/LoadActions.d.ts +1 -1
- package/lib/component/reducer/actions/LoadActions.js +10 -5
- package/lib/component/reducer/preferencesReducer.d.ts +1 -8
- package/lib/component/reducer/preferencesReducer.js +10 -13
- package/lib/component/reducer/types/Types.d.ts +1 -0
- package/lib/component/reducer/types/Types.js +1 -0
- package/lib/component/utility/FormatNumber.js +1 -1
- package/lib/component/workspaces/Workspace.d.ts +2 -4
- package/lib/component/workspaces/basic.js +8 -9
- package/lib/data/SpectraManager.js +23 -15
- package/lib/data/data1d/Data1DManager.d.ts +1 -1
- package/lib/data/data1d/Data1DManager.js +2 -1
- package/lib/data/data1d/Spectrum1D/toJSON.d.ts +2 -0
- package/lib/data/data1d/Spectrum1D/toJSON.js +1 -0
- package/lib/data/data1d/database.d.ts +1 -2
- package/lib/data/data1d/database.js +1 -1
- package/lib/data/data1d/filter1d/exclusionZones.d.ts +1 -4
- package/lib/data/data2d/Data2DManager.d.ts +1 -1
- package/lib/data/data2d/Data2DManager.js +2 -1
- package/lib/data/data2d/Spectrum2D/toJSON.d.ts +2 -0
- package/lib/data/data2d/Spectrum2D/toJSON.js +1 -0
- package/lib/data/types/common/Source.d.ts +1 -0
- package/lib/data/types/data2d/Signal2DAxisData.d.ts +1 -1
- package/lib/versionInfo.js +1 -1
- package/lib-cjs/component/1d/multiplicityTree/MultiplicityTree.js +6 -6
- package/lib-cjs/component/1d/ranges/Range.js +8 -7
- package/lib-cjs/component/2d/zones/Signal.js +9 -9
- package/lib-cjs/component/2d/zones/Zone.js +4 -4
- package/lib-cjs/component/EventsTrackers/KeysListenerTracker.js +2 -2
- package/lib-cjs/component/assignment/AssignmentsContext.js +88 -0
- package/lib-cjs/component/assignment/AssignmentsReducer.js +45 -0
- package/lib-cjs/component/assignment/actions/initAssignment.js +65 -0
- package/lib-cjs/component/assignment/actions/removeAssignment.js +29 -0
- package/lib-cjs/component/assignment/actions/setActiveAssignment.js +11 -0
- package/lib-cjs/component/assignment/actions/toggleAssignment.js +47 -0
- package/lib-cjs/component/assignment/index.js +15 -269
- package/lib-cjs/component/assignment/utilities/filterForIDsWithAssignment.js +7 -0
- package/lib-cjs/component/elements/Button.js +2 -1
- package/lib-cjs/component/elements/ReactTable/Elements/ReactTableRow.js +42 -14
- package/lib-cjs/component/elements/ReactTable/ReactTable.js +7 -2
- package/lib-cjs/component/elements/ReactTable/Style.js +1 -9
- package/lib-cjs/component/header/BaseLineCorrectionPanel.js +1 -1
- package/lib-cjs/component/modal/setting/FormattingTabContent.js +17 -11
- package/lib-cjs/component/modal/setting/GeneralSettings.js +2 -1
- package/lib-cjs/component/modal/setting/settingsValidation.js +66 -0
- package/lib-cjs/component/panels/AutomaticAssignment/AutomaticAssignment.js +6 -4
- package/lib-cjs/component/panels/AutomaticAssignment/AutomaticAssignmentTable.js +13 -6
- package/lib-cjs/component/panels/AutomaticAssignment/useAutoAssignments.js +67 -0
- package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +2 -2
- package/lib-cjs/component/panels/MoleculesPanel/Utilities.js +50 -68
- package/lib-cjs/component/panels/MoleculesPanel/useAtomAssignment.js +55 -60
- package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +3 -3
- package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +2 -2
- package/lib-cjs/component/panels/RangesPanel/RangesTableRow.js +15 -14
- package/lib-cjs/component/panels/RangesPanel/TableColumns/RangeAssignmentsColumn.js +2 -2
- package/lib-cjs/component/panels/RangesPanel/hooks/useEditRangeModal.js +2 -2
- package/lib-cjs/component/panels/SpectrumsPanel/SpectraPanelHeader.js +3 -16
- package/lib-cjs/component/panels/SummaryPanel/SummaryPanel.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/ActionsColumn.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumn.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/SignalAssignmentsColumns.js +1 -1
- package/lib-cjs/component/panels/ZonesPanel/TableColumns/ZoneAssignmentsColumn.js +4 -4
- package/lib-cjs/component/panels/ZonesPanel/ZonesPanel.js +2 -2
- package/lib-cjs/component/panels/ZonesPanel/ZonesTableRow.js +21 -21
- package/lib-cjs/component/panels/header/SpectraAutomaticPickingButton.js +37 -0
- package/lib-cjs/component/reducer/Reducer.js +4 -1
- package/lib-cjs/component/reducer/actions/AssignmentsActions.js +21 -0
- package/lib-cjs/component/reducer/actions/LoadActions.js +9 -4
- package/lib-cjs/component/reducer/preferencesReducer.js +10 -13
- package/lib-cjs/component/reducer/types/Types.js +2 -1
- package/lib-cjs/component/utility/FormatNumber.js +1 -1
- package/lib-cjs/component/workspaces/basic.js +8 -9
- package/lib-cjs/data/SpectraManager.js +23 -15
- package/lib-cjs/data/data1d/Data1DManager.js +2 -1
- package/lib-cjs/data/data1d/Spectrum1D/toJSON.js +1 -0
- package/lib-cjs/data/data2d/Data2DManager.js +2 -1
- package/lib-cjs/data/data2d/Spectrum2D/toJSON.js +1 -0
- package/lib-cjs/versionInfo.js +1 -1
- package/package.json +19 -19
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAssignment = exports.useAssignmentData = exports.AssignmentProvider = exports.assignmentContext = exports.assignmentState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
exports.assignmentState = {
|
|
6
|
+
assignments: {},
|
|
7
|
+
activated: null,
|
|
8
|
+
highlighted: null,
|
|
9
|
+
};
|
|
10
|
+
exports.assignmentContext = (0, react_1.createContext)({
|
|
11
|
+
data: exports.assignmentState,
|
|
12
|
+
dispatch: () => null,
|
|
13
|
+
});
|
|
14
|
+
exports.AssignmentProvider = exports.assignmentContext.Provider;
|
|
15
|
+
function useAssignmentData() {
|
|
16
|
+
const context = (0, react_1.useContext)(exports.assignmentContext);
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error('Assignment context was not found');
|
|
19
|
+
}
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
exports.useAssignmentData = useAssignmentData;
|
|
23
|
+
// key can be signal id,range id or zone id
|
|
24
|
+
function useAssignment(key) {
|
|
25
|
+
const { data: { activated, highlighted, assignments }, dispatch, } = useAssignmentData();
|
|
26
|
+
if ((typeof key !== 'string' && typeof key !== 'number') || key === '') {
|
|
27
|
+
throw new Error(`assignment key must be a non-empty string or number`);
|
|
28
|
+
}
|
|
29
|
+
const id = String(key);
|
|
30
|
+
const isActive = (0, react_1.useMemo)(() => {
|
|
31
|
+
return activated?.id === id;
|
|
32
|
+
}, [activated?.id, id]);
|
|
33
|
+
const isOver = (0, react_1.useMemo)(() => {
|
|
34
|
+
return highlighted?.id === id;
|
|
35
|
+
}, [highlighted?.id, id]);
|
|
36
|
+
const assigned = (0, react_1.useMemo)(() => {
|
|
37
|
+
return assignments[id] || null;
|
|
38
|
+
}, [assignments, id]);
|
|
39
|
+
const removeAll = (0, react_1.useCallback)((axis) => {
|
|
40
|
+
dispatch({
|
|
41
|
+
type: 'REMOVE',
|
|
42
|
+
payload: { ids: [id], axis },
|
|
43
|
+
});
|
|
44
|
+
}, [dispatch, id]);
|
|
45
|
+
const toggle = (0, react_1.useCallback)((atomIDs, dimension) => {
|
|
46
|
+
dispatch({
|
|
47
|
+
type: 'TOGGLE',
|
|
48
|
+
payload: { atomIDs, id, dimension },
|
|
49
|
+
});
|
|
50
|
+
}, [dispatch, id]);
|
|
51
|
+
const setActive = (0, react_1.useCallback)((axis) => {
|
|
52
|
+
dispatch({
|
|
53
|
+
type: 'SET_ACTIVE',
|
|
54
|
+
payload: {
|
|
55
|
+
id,
|
|
56
|
+
axis,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}, [dispatch, id]);
|
|
60
|
+
const show = (0, react_1.useCallback)((axis) => {
|
|
61
|
+
dispatch({
|
|
62
|
+
type: 'SHOW',
|
|
63
|
+
payload: {
|
|
64
|
+
id,
|
|
65
|
+
axis,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}, [dispatch, id]);
|
|
69
|
+
const hide = (0, react_1.useCallback)(() => {
|
|
70
|
+
dispatch({
|
|
71
|
+
type: 'HIDE',
|
|
72
|
+
});
|
|
73
|
+
}, [dispatch]);
|
|
74
|
+
return {
|
|
75
|
+
id,
|
|
76
|
+
activated,
|
|
77
|
+
isActive,
|
|
78
|
+
isOver,
|
|
79
|
+
highlighted,
|
|
80
|
+
assigned,
|
|
81
|
+
removeAll,
|
|
82
|
+
toggle,
|
|
83
|
+
setActive,
|
|
84
|
+
show,
|
|
85
|
+
hide,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
exports.useAssignment = useAssignment;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const initAssignment_1 = __importDefault(require("./actions/initAssignment"));
|
|
7
|
+
const removeAssignment_1 = __importDefault(require("./actions/removeAssignment"));
|
|
8
|
+
const setActiveAssignment_1 = __importDefault(require("./actions/setActiveAssignment"));
|
|
9
|
+
const toggleAssignment_1 = __importDefault(require("./actions/toggleAssignment"));
|
|
10
|
+
function assignmentReducer(state, action) {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case 'INITIATE_ASSIGNMENTS': {
|
|
13
|
+
return (0, initAssignment_1.default)(action);
|
|
14
|
+
}
|
|
15
|
+
case 'REMOVE': {
|
|
16
|
+
const { axis, ids, atomID } = action.payload;
|
|
17
|
+
return (0, removeAssignment_1.default)(state, { axis, ids, atomID });
|
|
18
|
+
}
|
|
19
|
+
case 'TOGGLE': {
|
|
20
|
+
return (0, toggleAssignment_1.default)(state, action);
|
|
21
|
+
}
|
|
22
|
+
case 'SET_ACTIVE': {
|
|
23
|
+
return (0, setActiveAssignment_1.default)(state, action);
|
|
24
|
+
}
|
|
25
|
+
case 'SHOW': {
|
|
26
|
+
const { id, axis } = action.payload;
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
highlighted: {
|
|
30
|
+
id,
|
|
31
|
+
axis: axis || null,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
case 'HIDE': {
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
highlighted: null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
default:
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = assignmentReducer;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Spectrum1D_1 = require("../../../data/data1d/Spectrum1D");
|
|
4
|
+
const AssignmentsContext_1 = require("../AssignmentsContext");
|
|
5
|
+
function initAssignment(action) {
|
|
6
|
+
const newState = {
|
|
7
|
+
...AssignmentsContext_1.assignmentState,
|
|
8
|
+
};
|
|
9
|
+
const spectra = (action.payload.spectra || []);
|
|
10
|
+
for (const spectrum of spectra) {
|
|
11
|
+
if ((0, Spectrum1D_1.isSpectrum1D)(spectrum)) {
|
|
12
|
+
setRangesAssignments(newState, spectrum.ranges);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
setZonesAssignments(newState, spectrum.zones);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return newState;
|
|
19
|
+
}
|
|
20
|
+
exports.default = initAssignment;
|
|
21
|
+
function setRangesAssignments(state, ranges) {
|
|
22
|
+
const diaIDRecords = ranges.values.reduce((acc, { id, diaIDs, signals }) => {
|
|
23
|
+
acc.push({ id, diaIDs: diaIDs || [] });
|
|
24
|
+
for (const signal of signals) {
|
|
25
|
+
acc.push({ id: signal.id, diaIDs: signal.diaIDs || [] });
|
|
26
|
+
}
|
|
27
|
+
return acc;
|
|
28
|
+
}, []);
|
|
29
|
+
for (const { id, diaIDs } of diaIDRecords) {
|
|
30
|
+
for (const diaID of diaIDs) {
|
|
31
|
+
setAssignment(state, id, 'x', diaID);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function setZonesAssignments(state, zones) {
|
|
36
|
+
const diaIDRecords = zones.values.reduce((acc, { id, x, y, signals }) => {
|
|
37
|
+
acc.push({ id, diaIDs: { x: x.diaIDs || [], y: y.diaIDs || [] } });
|
|
38
|
+
for (const signal of signals) {
|
|
39
|
+
acc.push({
|
|
40
|
+
id: signal.id,
|
|
41
|
+
diaIDs: { x: signal.x.diaIDs || [], y: signal.y.diaIDs || [] },
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
}, []);
|
|
46
|
+
for (const { id, diaIDs } of diaIDRecords) {
|
|
47
|
+
['x', 'y'].forEach((axis) => {
|
|
48
|
+
for (const diaID of diaIDs[axis]) {
|
|
49
|
+
setAssignment(state, id, axis, diaID);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function setAssignment(state, id, axis, diaID) {
|
|
55
|
+
if (Array.isArray(state.assignments?.[id]?.[axis]) &&
|
|
56
|
+
!state.assignments[id][axis].includes(diaID)) {
|
|
57
|
+
state.assignments[id][axis].push(diaID);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
state.assignments = {
|
|
61
|
+
...state.assignments,
|
|
62
|
+
[id]: { ...state.assignments[id], [axis]: [diaID] },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeAssignment = void 0;
|
|
4
|
+
function removeAssignment(state, options) {
|
|
5
|
+
const { id, atomID = '', axis } = options;
|
|
6
|
+
const atomIDs = state.assignments?.[id]?.[axis] || null;
|
|
7
|
+
if (atomIDs) {
|
|
8
|
+
if (atomID) {
|
|
9
|
+
atomIDs.filter((id) => id !== atomID);
|
|
10
|
+
state.assignments[id][axis] = atomIDs;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
state.assignments[id][axis] = [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.removeAssignment = removeAssignment;
|
|
18
|
+
function removeAssignments(state, action) {
|
|
19
|
+
const newState = {
|
|
20
|
+
...state,
|
|
21
|
+
};
|
|
22
|
+
// signal id
|
|
23
|
+
const { ids, atomID = '', axis } = action;
|
|
24
|
+
for (const id of ids) {
|
|
25
|
+
removeAssignment(newState, { id, atomID, axis });
|
|
26
|
+
}
|
|
27
|
+
return newState;
|
|
28
|
+
}
|
|
29
|
+
exports.default = removeAssignments;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function setActiveAssignment(state, action) {
|
|
4
|
+
let { id, axis } = action.payload;
|
|
5
|
+
const isActive = state.activated?.id === id;
|
|
6
|
+
return {
|
|
7
|
+
...state,
|
|
8
|
+
activated: !isActive ? { id, axis: axis || null } : null,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.default = setActiveAssignment;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const removeAssignment_1 = require("./removeAssignment");
|
|
4
|
+
function addAssignment(state, action) {
|
|
5
|
+
const { id, atomID, axis, dimension } = action;
|
|
6
|
+
const assignment = state.assignments?.[id] || null;
|
|
7
|
+
const axisAssignments = assignment?.[axis] || null;
|
|
8
|
+
// avoid duplicates
|
|
9
|
+
if (axisAssignments) {
|
|
10
|
+
if (!axisAssignments.includes(id)) {
|
|
11
|
+
axisAssignments.push(atomID);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const otherAxis = axis === 'x' ? 'y' : 'x';
|
|
16
|
+
state.assignments = {
|
|
17
|
+
...state.assignments,
|
|
18
|
+
[id]: {
|
|
19
|
+
...state.assignments[id],
|
|
20
|
+
[axis]: [atomID],
|
|
21
|
+
...(dimension === '2D' && {
|
|
22
|
+
[otherAxis]: assignment?.[otherAxis] ? assignment[otherAxis] : [],
|
|
23
|
+
}),
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function ToggleAssignments(state, action) {
|
|
29
|
+
const newState = {
|
|
30
|
+
...state,
|
|
31
|
+
};
|
|
32
|
+
const { id, atomIDs: atomsKeys, dimension } = action.payload;
|
|
33
|
+
const axis = state.activated?.axis;
|
|
34
|
+
if (axis) {
|
|
35
|
+
const atomIDs = state.assignments?.[id]?.[axis] || [];
|
|
36
|
+
for (const atomID of atomsKeys) {
|
|
37
|
+
if (!atomIDs.includes(id)) {
|
|
38
|
+
addAssignment(newState, { axis, id, atomID, dimension });
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
(0, removeAssignment_1.removeAssignment)(newState, { atomID, axis, id });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return newState;
|
|
46
|
+
}
|
|
47
|
+
exports.default = ToggleAssignments;
|
|
@@ -1,279 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.AssignmentProvider = void 0;
|
|
4
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-dynamic-delete */
|
|
6
8
|
const react_1 = require("react");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
switch (action.type) {
|
|
10
|
-
case 'ADD': {
|
|
11
|
-
const newState = {
|
|
12
|
-
...state,
|
|
13
|
-
assignment: { ...state.assignment },
|
|
14
|
-
};
|
|
15
|
-
if (newState.assignment[action.payload.id[0]] === undefined) {
|
|
16
|
-
newState.assignment[action.payload.id[0]] = {};
|
|
17
|
-
}
|
|
18
|
-
if (newState.assignment[action.payload.id[0]][action.payload.axis] ===
|
|
19
|
-
undefined) {
|
|
20
|
-
newState.assignment[action.payload.id[0]][action.payload.axis] = [];
|
|
21
|
-
}
|
|
22
|
-
// avoid duplicates
|
|
23
|
-
if (!newState.assignment[action.payload.id[0]][action.payload.axis].includes(action.payload.id[1])) {
|
|
24
|
-
newState.assignment[action.payload.id[0]][action.payload.axis].push(action.payload.id[1]);
|
|
25
|
-
}
|
|
26
|
-
return newState;
|
|
27
|
-
}
|
|
28
|
-
case 'REMOVE': {
|
|
29
|
-
const newState = {
|
|
30
|
-
...state,
|
|
31
|
-
assignment: { ...state.assignment },
|
|
32
|
-
};
|
|
33
|
-
if (newState.assignment[action.payload.id[0]]?.[action.payload.axis] !==
|
|
34
|
-
undefined) {
|
|
35
|
-
newState.assignment[action.payload.id[0]][action.payload.axis] =
|
|
36
|
-
newState.assignment[action.payload.id[0]][action.payload.axis].filter((_id) => _id !== action.payload.id[1]);
|
|
37
|
-
if (newState.assignment[action.payload.id[0]][action.payload.axis]
|
|
38
|
-
.length === 0) {
|
|
39
|
-
delete newState.assignment[action.payload.id[0]][action.payload.axis];
|
|
40
|
-
}
|
|
41
|
-
if (Object.keys(newState.assignment[action.payload.id[0]]).length === 0) {
|
|
42
|
-
delete newState.assignment[action.payload.id[0]];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return newState;
|
|
46
|
-
}
|
|
47
|
-
case 'REMOVE_ALL': {
|
|
48
|
-
const newState = {
|
|
49
|
-
...state,
|
|
50
|
-
assignment: { ...state.assignment },
|
|
51
|
-
};
|
|
52
|
-
// takes an array now to delete multiple identifiers
|
|
53
|
-
action.payload.id.forEach((_id) => {
|
|
54
|
-
if (newState.assignment[_id]?.[action.payload.axis] !== undefined) {
|
|
55
|
-
delete newState.assignment[_id][action.payload.axis];
|
|
56
|
-
if (Object.keys(newState.assignment[_id]).length === 0) {
|
|
57
|
-
delete newState.assignment[_id];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return newState;
|
|
62
|
-
}
|
|
63
|
-
case 'SET_IS_ACTIVE': {
|
|
64
|
-
return {
|
|
65
|
-
...state,
|
|
66
|
-
isActive: action.payload.id !== undefined && action.payload.axis !== undefined,
|
|
67
|
-
activeID: action.payload.id,
|
|
68
|
-
activeAxis: action.payload.axis,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
case 'SET_IS_ON_HOVER': {
|
|
72
|
-
return {
|
|
73
|
-
...state,
|
|
74
|
-
isOnHover: action.payload.id !== undefined,
|
|
75
|
-
onHoverID: action.payload.id,
|
|
76
|
-
onHoverAxis: action.payload.axis,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
case 'DELETE_RECORD': {
|
|
80
|
-
const newState = {
|
|
81
|
-
...state,
|
|
82
|
-
assignment: { ...state.assignment },
|
|
83
|
-
};
|
|
84
|
-
delete newState.assignment[action.payload.id];
|
|
85
|
-
if (newState.isActive && newState.activeID === action.payload.id) {
|
|
86
|
-
newState.isActive = false;
|
|
87
|
-
newState.activeID = undefined;
|
|
88
|
-
newState.activeAxis = undefined;
|
|
89
|
-
}
|
|
90
|
-
if (newState.isOnHover && newState.onHoverID === action.payload.id) {
|
|
91
|
-
newState.isOnHover = false;
|
|
92
|
-
newState.onHoverID = undefined;
|
|
93
|
-
newState.onHoverAxis = undefined;
|
|
94
|
-
}
|
|
95
|
-
return newState;
|
|
96
|
-
}
|
|
97
|
-
default: {
|
|
98
|
-
throw new Error(`unknown action type: ${action.type}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const emptyState = {
|
|
103
|
-
assignment: {},
|
|
104
|
-
isActive: false,
|
|
105
|
-
activeID: undefined,
|
|
106
|
-
activeAxis: undefined,
|
|
107
|
-
isOnHover: false,
|
|
108
|
-
onHoverID: undefined,
|
|
109
|
-
onHoverAxis: undefined,
|
|
110
|
-
};
|
|
9
|
+
const AssignmentsContext_1 = require("./AssignmentsContext");
|
|
10
|
+
const AssignmentsReducer_1 = __importDefault(require("./AssignmentsReducer"));
|
|
111
11
|
function AssignmentProvider(props) {
|
|
112
|
-
const { spectraData } = props;
|
|
113
|
-
const [
|
|
114
|
-
const
|
|
115
|
-
function initAssignmentDataRanges(range, _contextValue) {
|
|
116
|
-
_contextValue.dispatch({
|
|
117
|
-
type: 'DELETE_RECORD',
|
|
118
|
-
payload: { id: range.id },
|
|
119
|
-
});
|
|
120
|
-
(range.diaIDs || []).forEach((_diaID) => _contextValue.dispatch({
|
|
121
|
-
type: 'ADD',
|
|
122
|
-
payload: { id: [range.id, _diaID], axis: 'x' },
|
|
123
|
-
}));
|
|
124
|
-
range.signals.forEach((signal) => (signal.diaIDs || []).forEach((_diaID) => _contextValue.dispatch({
|
|
125
|
-
type: 'ADD',
|
|
126
|
-
payload: { id: [signal.id, _diaID], axis: 'x' },
|
|
127
|
-
})));
|
|
128
|
-
}
|
|
129
|
-
function initAssignmentDataZones(zone, _contextValue) {
|
|
130
|
-
_contextValue.dispatch({
|
|
131
|
-
type: 'DELETE_RECORD',
|
|
132
|
-
payload: { id: zone.id },
|
|
133
|
-
});
|
|
134
|
-
(zone.y.diaIDs || []).forEach((_diaID) => _contextValue.dispatch({
|
|
135
|
-
type: 'ADD',
|
|
136
|
-
payload: { id: [zone.id, _diaID], axis: 'y' },
|
|
137
|
-
}));
|
|
138
|
-
(zone.x.diaIDs || []).forEach((_diaID) => _contextValue.dispatch({
|
|
139
|
-
type: 'ADD',
|
|
140
|
-
payload: { id: [zone.id, _diaID], axis: 'x' },
|
|
141
|
-
}));
|
|
142
|
-
zone.signals.forEach((signal) => {
|
|
143
|
-
(signal.x.diaIDs || []).forEach((_diaID) => _contextValue.dispatch({
|
|
144
|
-
type: 'ADD',
|
|
145
|
-
payload: { id: [signal.id, _diaID], axis: 'x' },
|
|
146
|
-
}));
|
|
147
|
-
(signal.y.diaIDs || []).forEach((_diaID) => _contextValue.dispatch({
|
|
148
|
-
type: 'ADD',
|
|
149
|
-
payload: { id: [signal.id, _diaID], axis: 'y' },
|
|
150
|
-
}));
|
|
151
|
-
});
|
|
152
|
-
}
|
|
12
|
+
const { spectraData: spectra } = props;
|
|
13
|
+
const [data, dispatch] = (0, react_1.useReducer)(AssignmentsReducer_1.default, AssignmentsContext_1.assignmentState);
|
|
14
|
+
const state = (0, react_1.useMemo)(() => ({ data, dispatch }), [data]);
|
|
153
15
|
(0, react_1.useEffect)(() => {
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
else if (spectrum.info.dimension === 2) {
|
|
160
|
-
spectrum.zones.values.forEach((zone) => initAssignmentDataZones(zone, contextValue));
|
|
161
|
-
}
|
|
16
|
+
if (spectra) {
|
|
17
|
+
dispatch({
|
|
18
|
+
type: 'INITIATE_ASSIGNMENTS',
|
|
19
|
+
payload: { spectra },
|
|
162
20
|
});
|
|
163
21
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return ((0, jsx_runtime_1.jsx)(assignmentContext.Provider, { value: contextValue, children: props.children }));
|
|
22
|
+
}, [spectra]);
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(AssignmentsContext_1.assignmentContext.Provider, { value: state, children: props.children }));
|
|
167
24
|
}
|
|
168
25
|
exports.AssignmentProvider = AssignmentProvider;
|
|
169
|
-
function useAssignmentData() {
|
|
170
|
-
return (0, react_1.useContext)(assignmentContext);
|
|
171
|
-
}
|
|
172
|
-
exports.useAssignmentData = useAssignmentData;
|
|
173
|
-
function useAssignment(key) {
|
|
174
|
-
const context = useAssignmentData();
|
|
175
|
-
if ((typeof key !== 'string' && typeof key !== 'number') || key === '') {
|
|
176
|
-
throw new Error(`assignment key must be a non-empty string or number`);
|
|
177
|
-
}
|
|
178
|
-
const id = String(key);
|
|
179
|
-
const isActive = (0, react_1.useMemo)(() => {
|
|
180
|
-
return context.assignment.isActive && context.assignment.activeID === id;
|
|
181
|
-
}, [context.assignment.activeID, context.assignment.isActive, id]);
|
|
182
|
-
const activeAxis = (0, react_1.useMemo)(() => {
|
|
183
|
-
return isActive ? context.assignment.activeAxis : undefined;
|
|
184
|
-
}, [context.assignment.activeAxis, isActive]);
|
|
185
|
-
const assigned = (0, react_1.useMemo)(() => {
|
|
186
|
-
return context.assignment.assignment[id]
|
|
187
|
-
? context.assignment.assignment[id]
|
|
188
|
-
: [];
|
|
189
|
-
}, [context.assignment.assignment, id]);
|
|
190
|
-
const isOnHover = (0, react_1.useMemo)(() => {
|
|
191
|
-
return context.assignment.isOnHover && context.assignment.onHoverID === id;
|
|
192
|
-
}, [context.assignment.isOnHover, context.assignment.onHoverID, id]);
|
|
193
|
-
const onHoverAxis = (0, react_1.useMemo)(() => {
|
|
194
|
-
return isOnHover ? context.assignment.onHoverAxis : undefined;
|
|
195
|
-
}, [context.assignment.onHoverAxis, isOnHover]);
|
|
196
|
-
const add = (0, react_1.useCallback)((_id) => {
|
|
197
|
-
context.dispatch({
|
|
198
|
-
type: 'ADD',
|
|
199
|
-
payload: { id: [id, _id], axis: activeAxis },
|
|
200
|
-
});
|
|
201
|
-
}, [activeAxis, context, id]);
|
|
202
|
-
const remove = (0, react_1.useCallback)((_id) => {
|
|
203
|
-
context.dispatch({
|
|
204
|
-
type: 'REMOVE',
|
|
205
|
-
payload: { id: [id, _id], axis: activeAxis },
|
|
206
|
-
});
|
|
207
|
-
}, [activeAxis, context, id]);
|
|
208
|
-
const removeAll = (0, react_1.useCallback)((axis) => {
|
|
209
|
-
context.dispatch({
|
|
210
|
-
type: 'REMOVE_ALL',
|
|
211
|
-
payload: { id: [id], axis },
|
|
212
|
-
});
|
|
213
|
-
}, [context, id]);
|
|
214
|
-
const toggle = (0, react_1.useCallback)((_id) => {
|
|
215
|
-
if (assigned[activeAxis] === undefined ||
|
|
216
|
-
!assigned[activeAxis].includes(_id)) {
|
|
217
|
-
add(_id);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
remove(_id);
|
|
221
|
-
}
|
|
222
|
-
}, [activeAxis, add, assigned, remove]);
|
|
223
|
-
// totally deletion of a record from assignment storage
|
|
224
|
-
const deleteRecord = (0, react_1.useCallback)(() => {
|
|
225
|
-
context.dispatch({
|
|
226
|
-
type: 'DELETE_RECORD',
|
|
227
|
-
payload: { id },
|
|
228
|
-
});
|
|
229
|
-
}, [context, id]);
|
|
230
|
-
const onClick = (0, react_1.useCallback)((axis) => {
|
|
231
|
-
context.dispatch({
|
|
232
|
-
type: 'SET_IS_ACTIVE',
|
|
233
|
-
payload: {
|
|
234
|
-
id: !isActive ? id : undefined,
|
|
235
|
-
axis: !isActive && id !== undefined ? axis : undefined,
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
}, [context, id, isActive]);
|
|
239
|
-
const setIsOnHover = (0, react_1.useCallback)((action, axis) => {
|
|
240
|
-
if (action === 'enter') {
|
|
241
|
-
context.dispatch({
|
|
242
|
-
type: 'SET_IS_ON_HOVER',
|
|
243
|
-
payload: {
|
|
244
|
-
id: id,
|
|
245
|
-
axis: id !== undefined ? axis : undefined,
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
else if (action === 'leave') {
|
|
250
|
-
context.dispatch({
|
|
251
|
-
type: 'SET_IS_ON_HOVER',
|
|
252
|
-
payload: {},
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}, [context, id]);
|
|
256
|
-
const onMouseEnter = (0, react_1.useCallback)((axis) => setIsOnHover('enter', axis), [setIsOnHover]);
|
|
257
|
-
const onMouseLeave = (0, react_1.useCallback)((axis) => setIsOnHover('leave', axis), [setIsOnHover]);
|
|
258
|
-
return {
|
|
259
|
-
id,
|
|
260
|
-
isActive,
|
|
261
|
-
activeAxis,
|
|
262
|
-
assigned,
|
|
263
|
-
add,
|
|
264
|
-
remove,
|
|
265
|
-
removeAll,
|
|
266
|
-
toggle,
|
|
267
|
-
deleteRecord,
|
|
268
|
-
onClick,
|
|
269
|
-
isOnHover,
|
|
270
|
-
onHoverAxis,
|
|
271
|
-
onMouseEnter,
|
|
272
|
-
onMouseLeave,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
exports.useAssignment = useAssignment;
|
|
276
|
-
function filterForIDsWithAssignment(assignmentData, ids) {
|
|
277
|
-
return ids.filter((id) => Object.keys(assignmentData.assignment).filter((_id) => _id === id));
|
|
278
|
-
}
|
|
279
|
-
exports.filterForIDsWithAssignment = filterForIDsWithAssignment;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterForIDsWithAssignment = void 0;
|
|
4
|
+
function filterForIDsWithAssignment(assignmentData, ids) {
|
|
5
|
+
return ids.filter((id) => Object.keys(assignmentData.data).filter((_id) => _id === id));
|
|
6
|
+
}
|
|
7
|
+
exports.filterForIDsWithAssignment = filterForIDsWithAssignment;
|
|
@@ -133,12 +133,13 @@ const Button = (props) => {
|
|
|
133
133
|
], ...restProps, children: (0, jsx_runtime_1.jsxs)("span", { style: { flex: 1 }, children: [" ", props.children] }) }));
|
|
134
134
|
};
|
|
135
135
|
function ThemeButton(props) {
|
|
136
|
+
const { colorTheme, ...buttonProps } = props;
|
|
136
137
|
const { base, shade, tint } = colorPalettes[props.colorTheme];
|
|
137
138
|
const { color = { base: shade, hover: 'white' }, backgroundColor = {
|
|
138
139
|
base: base,
|
|
139
140
|
hover: shade,
|
|
140
141
|
active: tint,
|
|
141
|
-
}, fill = 'solid', ...restProps } =
|
|
142
|
+
}, fill = 'solid', ...restProps } = buttonProps;
|
|
142
143
|
return (0, jsx_runtime_1.jsx)(Button, { ...{ fill, ...restProps, backgroundColor, color } });
|
|
143
144
|
}
|
|
144
145
|
Button.Done = (props) => {
|