nmrium 0.24.1 → 0.25.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/IntegralResizable.js +13 -13
- package/lib/component/1d/multiAnalysis/AnalysisRange.js +30 -31
- package/lib/component/1d/ranges/Range.js +18 -28
- package/lib/component/NMRium.js +22 -29
- package/lib/component/context/GlobalContext.d.ts +12 -3
- package/lib/component/context/GlobalContext.js +1 -1
- package/lib/component/elements/ActionButtons.d.ts +10 -0
- package/lib/component/elements/ActionButtons.js +14 -0
- package/lib/component/elements/Button.d.ts +30 -5
- package/lib/component/elements/Button.js +150 -4
- package/lib/component/elements/ContextMenu.js +6 -6
- package/lib/component/elements/ToolTip/ToolTip.js +3 -2
- package/lib/component/elements/resizer/DivResizer.d.ts +2 -0
- package/lib/component/elements/resizer/DivResizer.js +107 -0
- package/lib/component/elements/resizer/Resizer.d.ts +18 -0
- package/lib/component/elements/resizer/Resizer.js +12 -0
- package/lib/component/elements/resizer/SVGResizer.d.ts +2 -0
- package/lib/component/elements/resizer/SVGResizer.js +71 -0
- package/lib/component/elements/resizer/useDraggable.d.ts +19 -0
- package/lib/component/elements/resizer/useDraggable.js +52 -0
- package/lib/component/header/AutoPeakPickingOptionPanel.js +4 -15
- package/lib/component/header/BaseLineCorrectionPanel.js +2 -9
- package/lib/component/header/ManualPhaseCorrectionPanel.js +2 -9
- package/lib/component/header/RangesPickingOptionPanel.js +3 -16
- package/lib/component/header/ZeroFillingOptionsPanel.js +2 -9
- package/lib/component/header/Zones2DOptionPanel.js +3 -14
- package/lib/component/hooks/useExport.js +11 -9
- package/lib/component/loader/DropZone.js +1 -0
- package/lib/component/modal/AlignSpectraModal.js +2 -1
- package/lib/component/modal/ExportAsMatrixModal.js +2 -1
- package/lib/component/modal/ImportPublicationStringModal.js +2 -1
- package/lib/component/modal/LoadJCAMPModal.js +7 -6
- package/lib/component/modal/ModalStyle.js +4 -26
- package/lib/component/modal/MoleculeStructureEditorModal.js +2 -1
- package/lib/component/modal/MultipleSpectraFiltersModal/index.js +2 -1
- package/lib/component/modal/PredictSpectraModal.js +2 -7
- package/lib/component/modal/SaveAsModal.d.ts +1 -1
- package/lib/component/modal/SaveAsModal.js +2 -1
- package/lib/component/modal/setting/GeneralSettings.js +2 -1
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +10 -4
- package/lib/component/panels/predictionPanel/PredictionOptions.js +2 -18
- package/lib/component/utility/Export.d.ts +3 -3
- package/lib/component/utility/Export.js +10 -9
- package/lib/versionInfo.js +1 -1
- package/lib-cjs/component/1d/IntegralResizable.js +12 -12
- package/lib-cjs/component/1d/multiAnalysis/AnalysisRange.js +29 -30
- package/lib-cjs/component/1d/ranges/Range.js +18 -28
- package/lib-cjs/component/NMRium.js +22 -29
- package/lib-cjs/component/context/GlobalContext.js +1 -1
- package/lib-cjs/component/elements/ActionButtons.js +20 -0
- package/lib-cjs/component/elements/Button.js +149 -4
- package/lib-cjs/component/elements/ContextMenu.js +6 -6
- package/lib-cjs/component/elements/ToolTip/ToolTip.js +3 -2
- package/lib-cjs/component/elements/resizer/DivResizer.js +113 -0
- package/lib-cjs/component/elements/resizer/Resizer.js +18 -0
- package/lib-cjs/component/elements/resizer/SVGResizer.js +77 -0
- package/lib-cjs/component/elements/resizer/useDraggable.js +55 -0
- package/lib-cjs/component/header/AutoPeakPickingOptionPanel.js +3 -14
- package/lib-cjs/component/header/BaseLineCorrectionPanel.js +2 -9
- package/lib-cjs/component/header/ManualPhaseCorrectionPanel.js +2 -9
- package/lib-cjs/component/header/RangesPickingOptionPanel.js +2 -15
- package/lib-cjs/component/header/ZeroFillingOptionsPanel.js +2 -9
- package/lib-cjs/component/header/Zones2DOptionPanel.js +2 -13
- package/lib-cjs/component/hooks/useExport.js +11 -9
- package/lib-cjs/component/loader/DropZone.js +1 -0
- package/lib-cjs/component/modal/AlignSpectraModal.js +2 -1
- package/lib-cjs/component/modal/ExportAsMatrixModal.js +2 -1
- package/lib-cjs/component/modal/ImportPublicationStringModal.js +2 -1
- package/lib-cjs/component/modal/LoadJCAMPModal.js +7 -6
- package/lib-cjs/component/modal/ModalStyle.js +4 -26
- package/lib-cjs/component/modal/MoleculeStructureEditorModal.js +5 -1
- package/lib-cjs/component/modal/MultipleSpectraFiltersModal/index.js +2 -1
- package/lib-cjs/component/modal/PredictSpectraModal.js +2 -7
- package/lib-cjs/component/modal/SaveAsModal.js +2 -1
- package/lib-cjs/component/modal/setting/GeneralSettings.js +2 -1
- package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +10 -4
- package/lib-cjs/component/panels/predictionPanel/PredictionOptions.js +2 -18
- package/lib-cjs/component/utility/Export.js +10 -9
- package/lib-cjs/versionInfo.js +1 -1
- package/package.json +16 -17
- package/lib/component/1d/Resizable.d.ts +0 -12
- package/lib/component/1d/Resizable.js +0 -105
- package/lib-cjs/component/1d/Resizable.js +0 -110
|
@@ -32,6 +32,7 @@ const react_1 = require("@emotion/react");
|
|
|
32
32
|
const react_2 = require("react");
|
|
33
33
|
const Yup = __importStar(require("yup"));
|
|
34
34
|
const PredictionManager_1 = require("../../../data/PredictionManager");
|
|
35
|
+
const Button_1 = __importDefault(require("../../elements/Button"));
|
|
35
36
|
const IsotopesViewer_1 = __importDefault(require("../../elements/IsotopesViewer"));
|
|
36
37
|
const Label_1 = __importDefault(require("../../elements/Label"));
|
|
37
38
|
const FormikErrorsSummary_1 = __importDefault(require("../../elements/formik/FormikErrorsSummary"));
|
|
@@ -62,23 +63,6 @@ const styles = (0, react_1.css) `
|
|
|
62
63
|
align-items: flex-end;
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
.btn:not([disabled]):hover {
|
|
66
|
-
background-color: #ffffff;
|
|
67
|
-
}
|
|
68
|
-
.btn:hover {
|
|
69
|
-
background-color: #f2f2f2 !important;
|
|
70
|
-
}
|
|
71
|
-
.btn:disabled {
|
|
72
|
-
opacity: 0.5;
|
|
73
|
-
}
|
|
74
|
-
.btn {
|
|
75
|
-
border: none;
|
|
76
|
-
padding: 0 15px;
|
|
77
|
-
background-color: #ffffff;
|
|
78
|
-
border-radius: 5px;
|
|
79
|
-
height: 25px;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
66
|
.input {
|
|
83
67
|
font-size: 14px;
|
|
84
68
|
border-radius: 5px;
|
|
@@ -113,6 +97,6 @@ function PredictionOptions({ onPredict = () => null }) {
|
|
|
113
97
|
onPredict(values);
|
|
114
98
|
})();
|
|
115
99
|
}, [onPredict]);
|
|
116
|
-
return ((0, jsx_runtime_1.jsxs)("div", { css: styles, children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)(FormikForm_1.default, { ref: refForm, initialValues: PredictionManager_1.defaultPredictionOptions, validationSchema: predictionFormValidation, onSubmit: submitHandler, children: [(0, jsx_runtime_1.jsx)(FormikErrorsSummary_1.default, {}), (0, jsx_runtime_1.jsxs)("div", { className: "row margin-10", children: [(0, jsx_runtime_1.jsx)("span", { className: "custom-label", children: "Frequency : " }), (0, jsx_runtime_1.jsx)(FormikSelect_1.default, { data: PredictionManager_1.FREQUENCIES, style: { width: 290, height: 30, margin: 0 }, name: "frequency" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "row", children: [(0, jsx_runtime_1.jsx)(IsotopesViewer_1.default, { value: "1H", className: "custom-label" }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "From", children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.1H.from", type: "number" }) }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "To", style: { label: { padding: '0 10px' } }, children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.1H.to", type: "number" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "row", children: [(0, jsx_runtime_1.jsx)(IsotopesViewer_1.default, { value: "13C", className: "custom-label" }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "From", children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.13C.from", type: "number" }) }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "To", style: { label: { padding: '0 10px' } }, children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.13C.to", type: "number" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "row margin-10 padding-h-10", children: [(0, jsx_runtime_1.jsx)("span", { className: "custom-label", children: "Line Width : " }), (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.lineWidth", type: "number", style: { input: { margin: 0 } } }), (0, jsx_runtime_1.jsx)("span", { style: { paddingLeft: '0.4rem' }, children: " Hz " })] })] }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(
|
|
100
|
+
return ((0, jsx_runtime_1.jsxs)("div", { css: styles, children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)(FormikForm_1.default, { ref: refForm, initialValues: PredictionManager_1.defaultPredictionOptions, validationSchema: predictionFormValidation, onSubmit: submitHandler, children: [(0, jsx_runtime_1.jsx)(FormikErrorsSummary_1.default, {}), (0, jsx_runtime_1.jsxs)("div", { className: "row margin-10", children: [(0, jsx_runtime_1.jsx)("span", { className: "custom-label", children: "Frequency : " }), (0, jsx_runtime_1.jsx)(FormikSelect_1.default, { data: PredictionManager_1.FREQUENCIES, style: { width: 290, height: 30, margin: 0 }, name: "frequency" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "row", children: [(0, jsx_runtime_1.jsx)(IsotopesViewer_1.default, { value: "1H", className: "custom-label" }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "From", children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.1H.from", type: "number" }) }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "To", style: { label: { padding: '0 10px' } }, children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.1H.to", type: "number" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "row", children: [(0, jsx_runtime_1.jsx)(IsotopesViewer_1.default, { value: "13C", className: "custom-label" }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "From", children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.13C.from", type: "number" }) }), (0, jsx_runtime_1.jsx)(Label_1.default, { title: "To", style: { label: { padding: '0 10px' } }, children: (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.13C.to", type: "number" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "row margin-10 padding-h-10", children: [(0, jsx_runtime_1.jsx)("span", { className: "custom-label", children: "Line Width : " }), (0, jsx_runtime_1.jsx)(FormikInput_1.default, { name: "1d.lineWidth", type: "number", style: { input: { margin: 0 } } }), (0, jsx_runtime_1.jsx)("span", { style: { paddingLeft: '0.4rem' }, children: " Hz " })] })] }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(Button_1.default.Done, { onClick: handleSave, children: "Predict spectrum" }) })] }));
|
|
117
101
|
}
|
|
118
102
|
exports.default = PredictionOptions;
|
|
@@ -121,13 +121,13 @@ exports.exportAsMol = exportAsMol;
|
|
|
121
121
|
/**
|
|
122
122
|
* export the vitalization result as SVG, if you need to remove some content during exportation process enclose the the content with <!-- export-remove --> ${content} <!-- export-remove -->
|
|
123
123
|
*/
|
|
124
|
-
function exportAsSVG(elementID, fileName = 'experiment') {
|
|
125
|
-
const { blob } = getBlob(elementID);
|
|
124
|
+
function exportAsSVG(rootRef, elementID, fileName = 'experiment') {
|
|
125
|
+
const { blob } = getBlob(rootRef, elementID);
|
|
126
126
|
(0, file_saver_1.saveAs)(blob, `${fileName}.svg`);
|
|
127
127
|
}
|
|
128
128
|
exports.exportAsSVG = exportAsSVG;
|
|
129
|
-
function exportAsPng(elementID, fileName = 'experiment') {
|
|
130
|
-
const { blob, width, height } = getBlob(elementID);
|
|
129
|
+
function exportAsPng(rootRef, elementID, fileName = 'experiment') {
|
|
130
|
+
const { blob, width, height } = getBlob(rootRef, elementID);
|
|
131
131
|
try {
|
|
132
132
|
let canvas = document.createElement('canvas');
|
|
133
133
|
canvas.width = width;
|
|
@@ -180,8 +180,8 @@ function copyBlobToCliboard(canvas) {
|
|
|
180
180
|
});
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
|
-
function copyPNGToClipboard(elementID) {
|
|
184
|
-
const { blob, width, height } = getBlob(elementID);
|
|
183
|
+
function copyPNGToClipboard(rootRef, elementID) {
|
|
184
|
+
const { blob, width, height } = getBlob(rootRef, elementID);
|
|
185
185
|
try {
|
|
186
186
|
let canvas = document.createElement('canvas');
|
|
187
187
|
canvas.width = width;
|
|
@@ -217,9 +217,10 @@ function copyPNGToClipboard(elementID) {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
exports.copyPNGToClipboard = copyPNGToClipboard;
|
|
220
|
-
function getBlob(elementID) {
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
function getBlob(rootRef, elementID) {
|
|
221
|
+
let _svg = rootRef.getRootNode()
|
|
222
|
+
.getElementById(elementID)
|
|
223
|
+
?.cloneNode(true);
|
|
223
224
|
const width = _svg?.getAttribute('width').replace('px', '');
|
|
224
225
|
const height = _svg?.getAttribute('height').replace('px', '');
|
|
225
226
|
_svg
|
package/lib-cjs/versionInfo.js
CHANGED
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.
|
|
4
|
+
"version": "0.25.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib-cjs/component/NMRium.js",
|
|
7
7
|
"module": "lib/component/NMRium.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"url": "git+https://github.com/cheminfo/nmrium.git"
|
|
39
39
|
},
|
|
40
40
|
"volta": {
|
|
41
|
-
"node": "16.14.
|
|
41
|
+
"node": "16.14.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"react": ">=16.0.0",
|
|
@@ -46,17 +46,17 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@emotion/react": "^11.8.2",
|
|
49
|
-
"analysis-ui-components": "^0.
|
|
49
|
+
"analysis-ui-components": "^0.11.1",
|
|
50
50
|
"cheminfo-font": "^1.8.1",
|
|
51
51
|
"cheminfo-types": "^1.1.0",
|
|
52
|
-
"d3": "^7.
|
|
52
|
+
"d3": "^7.4.2",
|
|
53
53
|
"eventemitter3": "^4.0.7",
|
|
54
54
|
"file-saver": "^2.0.5",
|
|
55
55
|
"formik": "^2.2.9",
|
|
56
56
|
"immer": "^9.0.12",
|
|
57
|
-
"jszip": "^3.
|
|
57
|
+
"jszip": "^3.8.0",
|
|
58
58
|
"lodash": "^4.17.21",
|
|
59
|
-
"mf-parser": "^1.4.
|
|
59
|
+
"mf-parser": "^1.4.6",
|
|
60
60
|
"ml-airpls": "^1.0.0",
|
|
61
61
|
"ml-array-max": "^1.2.4",
|
|
62
62
|
"ml-array-mean": "^1.1.6",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"ml-baseline-correction-regression": "^1.0.0",
|
|
66
66
|
"ml-conrec": "^3.2.1",
|
|
67
67
|
"ml-gsd": "^10.2.0",
|
|
68
|
-
"ml-spectra-processing": "^11.
|
|
68
|
+
"ml-spectra-processing": "^11.2.0",
|
|
69
69
|
"ml-stat": "^1.3.3",
|
|
70
70
|
"multiplet-analysis": "^2.0.0",
|
|
71
71
|
"nmr-correlation": "^2.2.5",
|
|
72
72
|
"nmr-parser": "^1.7.3",
|
|
73
|
-
"nmr-processing": "^7.4.
|
|
73
|
+
"nmr-processing": "^7.4.2",
|
|
74
74
|
"nmredata": "^0.6.1",
|
|
75
75
|
"numeral": "^2.0.6",
|
|
76
76
|
"openchemlib": "^7.4.3",
|
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
"re-resizable": "^6.9.5",
|
|
79
79
|
"react-color": "2.17.2",
|
|
80
80
|
"react-d3-utils": "^0.5.0",
|
|
81
|
-
"react-draggable": "^4.4.4",
|
|
82
81
|
"react-dropzone": "^12.0.4",
|
|
83
82
|
"react-error-boundary": "^3.1.4",
|
|
84
83
|
"react-icons": "^4.3.1",
|
|
@@ -88,7 +87,7 @@
|
|
|
88
87
|
"react-ocl-nmr": "^1.1.0",
|
|
89
88
|
"react-plot": "^0.16.0",
|
|
90
89
|
"react-rnd": "^10.3.5",
|
|
91
|
-
"react-slider": "^
|
|
90
|
+
"react-slider": "^2.0.0",
|
|
92
91
|
"react-table": "^7.7.0",
|
|
93
92
|
"react-transition-group": "^4.4.2",
|
|
94
93
|
"react-use": "^17.3.2",
|
|
@@ -99,7 +98,7 @@
|
|
|
99
98
|
"@babel/plugin-transform-modules-commonjs": "^7.17.7",
|
|
100
99
|
"@babel/preset-react": "^7.16.7",
|
|
101
100
|
"@babel/preset-typescript": "^7.16.7",
|
|
102
|
-
"@playwright/test": "^1.20.
|
|
101
|
+
"@playwright/test": "^1.20.2",
|
|
103
102
|
"@simbathesailor/use-what-changed": "^2.0.0",
|
|
104
103
|
"@types/d3": "^7.1.0",
|
|
105
104
|
"@types/jest": "^27.4.1",
|
|
@@ -107,14 +106,14 @@
|
|
|
107
106
|
"@types/react": "^17.0.43",
|
|
108
107
|
"@types/react-dom": "^17.0.14",
|
|
109
108
|
"@types/react-router-dom": "^5.3.3",
|
|
110
|
-
"@vitejs/plugin-react": "^1.
|
|
109
|
+
"@vitejs/plugin-react": "^1.3.0",
|
|
111
110
|
"@zakodium/eslint-config": "^5.1.1",
|
|
112
111
|
"cross-env": "^7.0.3",
|
|
113
|
-
"eslint": "^8.
|
|
112
|
+
"eslint": "^8.12.0",
|
|
114
113
|
"jest": "^27.5.1",
|
|
115
114
|
"modern-normalize": "^1.1.0",
|
|
116
|
-
"prettier": "^2.6.
|
|
117
|
-
"rc-menu": "^9.5.
|
|
115
|
+
"prettier": "^2.6.2",
|
|
116
|
+
"rc-menu": "^9.5.3",
|
|
118
117
|
"react": "^17.0.2",
|
|
119
118
|
"react-dom": "^17.0.2",
|
|
120
119
|
"react-router-dom": "^5.3.0",
|
|
@@ -122,6 +121,6 @@
|
|
|
122
121
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
123
122
|
"serve": "^13.0.2",
|
|
124
123
|
"typescript": "~4.6.3",
|
|
125
|
-
"vite": "^2.
|
|
124
|
+
"vite": "^2.9.1"
|
|
126
125
|
}
|
|
127
|
-
}
|
|
126
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
interface ResizedDrop {
|
|
2
|
-
from?: number;
|
|
3
|
-
to?: number;
|
|
4
|
-
}
|
|
5
|
-
interface ResizableProps {
|
|
6
|
-
from: number;
|
|
7
|
-
to: number;
|
|
8
|
-
onDrag?: (element: ResizedDrop) => void;
|
|
9
|
-
onDrop: (element: ResizedDrop) => void;
|
|
10
|
-
}
|
|
11
|
-
declare function Resizable({ from, to, onDrag, onDrop }: ResizableProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
|
-
export default Resizable;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
/** @jsxImportSource @emotion/react */
|
|
3
|
-
import { Fragment, useCallback, useRef, useState } from 'react';
|
|
4
|
-
import Draggable from 'react-draggable';
|
|
5
|
-
import { useChartData } from '../context/ChartContext';
|
|
6
|
-
import { useScaleChecked } from '../context/ScaleContext';
|
|
7
|
-
function Resizable({ from, to, onDrag = () => null, onDrop }) {
|
|
8
|
-
const { height, margin, mode } = useChartData();
|
|
9
|
-
const [rightDragVisibility, setRightDragVisibility] = useState(false);
|
|
10
|
-
const [leftDragVisibility, setLeftDragVisibility] = useState(false);
|
|
11
|
-
const [enable, setEnable] = useState(true);
|
|
12
|
-
const draggableRightRef = useRef(null);
|
|
13
|
-
const draggableLeftRef = useRef(null);
|
|
14
|
-
const { scaleX } = useScaleChecked();
|
|
15
|
-
const handleRightStart = useCallback((e) => {
|
|
16
|
-
e.preventDefault();
|
|
17
|
-
e.stopPropagation();
|
|
18
|
-
setRightDragVisibility(true);
|
|
19
|
-
}, []);
|
|
20
|
-
const handleRightDrag = useCallback((e) => {
|
|
21
|
-
onDrag({ from: scaleX().invert(e.layerX) });
|
|
22
|
-
}, [onDrag, scaleX]);
|
|
23
|
-
const handleRightStop = useCallback((e) => {
|
|
24
|
-
e.preventDefault();
|
|
25
|
-
e.stopPropagation();
|
|
26
|
-
setRightDragVisibility(false);
|
|
27
|
-
const _range = mode === 'RTL'
|
|
28
|
-
? [scaleX().invert(e.layerX), to]
|
|
29
|
-
: [to, scaleX().invert(e.layerX)];
|
|
30
|
-
let resized;
|
|
31
|
-
if (_range[1] > _range[0]) {
|
|
32
|
-
resized = {
|
|
33
|
-
from: _range[0],
|
|
34
|
-
to: _range[1],
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
resized = {
|
|
39
|
-
from,
|
|
40
|
-
to,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
onDrop(resized);
|
|
44
|
-
}, [from, mode, onDrop, scaleX, to]);
|
|
45
|
-
const handleLeftStart = useCallback((e) => {
|
|
46
|
-
e.preventDefault();
|
|
47
|
-
e.stopPropagation();
|
|
48
|
-
setLeftDragVisibility(true);
|
|
49
|
-
}, []);
|
|
50
|
-
const handleLeftDrag = useCallback((e) => {
|
|
51
|
-
onDrag({ to: scaleX().invert(e.layerX) });
|
|
52
|
-
}, [onDrag, scaleX]);
|
|
53
|
-
const handleLeftStop = useCallback((e) => {
|
|
54
|
-
e.preventDefault();
|
|
55
|
-
e.stopPropagation();
|
|
56
|
-
setLeftDragVisibility(false);
|
|
57
|
-
const _range = mode === 'RTL'
|
|
58
|
-
? [from, scaleX().invert(e.layerX)]
|
|
59
|
-
: [scaleX().invert(e.layerX), from];
|
|
60
|
-
let resized;
|
|
61
|
-
if (_range[1] > _range[0]) {
|
|
62
|
-
resized = {
|
|
63
|
-
from: _range[0],
|
|
64
|
-
to: _range[1],
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
resized = {
|
|
69
|
-
from,
|
|
70
|
-
to,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
onDrop(resized);
|
|
74
|
-
}, [from, mode, onDrop, scaleX, to]);
|
|
75
|
-
const mouseDownCaptureHandler = useCallback(({ shiftKey }) => {
|
|
76
|
-
if (shiftKey) {
|
|
77
|
-
setEnable(false);
|
|
78
|
-
}
|
|
79
|
-
}, []);
|
|
80
|
-
const mouseUpCaptureHandler = useCallback(() => {
|
|
81
|
-
setEnable(true);
|
|
82
|
-
}, []);
|
|
83
|
-
const mouseOverHandler = useCallback(({ target, shiftKey }) => {
|
|
84
|
-
if (shiftKey) {
|
|
85
|
-
target.style.cursor = 'crosshair';
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
target.style.cursor = 'ew-resize';
|
|
89
|
-
}
|
|
90
|
-
}, []);
|
|
91
|
-
return (_jsxs(Fragment, { children: [_jsx(Draggable, { axis: "x", defaultPosition: {
|
|
92
|
-
x: scaleX()(from),
|
|
93
|
-
y: 0,
|
|
94
|
-
}, position: {
|
|
95
|
-
x: scaleX()(from),
|
|
96
|
-
y: 0,
|
|
97
|
-
}, scale: 1, handle: ".handle", onStart: handleRightStart, onDrag: handleRightDrag, onStop: handleRightStop, nodeRef: draggableRightRef, children: _jsx("rect", { ref: draggableRightRef, className: enable ? 'handle' : '', width: rightDragVisibility ? 1 : 6, fill: "red", height: height + margin.top, style: { fillOpacity: rightDragVisibility ? 1 : 0 }, onMouseDownCapture: mouseDownCaptureHandler, onMouseUpCapture: mouseUpCaptureHandler, onMouseEnter: mouseOverHandler }) }), _jsx(Draggable, { axis: "x", defaultPosition: {
|
|
98
|
-
x: scaleX()(to),
|
|
99
|
-
y: 0,
|
|
100
|
-
}, position: {
|
|
101
|
-
x: scaleX()(to),
|
|
102
|
-
y: 0,
|
|
103
|
-
}, handle: ".handle", scale: 1, onStart: handleLeftStart, onDrag: handleLeftDrag, onStop: handleLeftStop, nodeRef: draggableLeftRef, children: _jsx("rect", { ref: draggableLeftRef, className: enable ? 'handle' : '', width: leftDragVisibility ? 1 : 6, fill: "red", height: height + margin.top, style: { fillOpacity: leftDragVisibility ? 1 : 0 }, onMouseDownCapture: mouseDownCaptureHandler, onMouseUpCapture: mouseUpCaptureHandler, onMouseEnter: mouseOverHandler }) })] }));
|
|
104
|
-
}
|
|
105
|
-
export default Resizable;
|
|
@@ -1,110 +0,0 @@
|
|
|
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 jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
7
|
-
/** @jsxImportSource @emotion/react */
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
const react_draggable_1 = __importDefault(require("react-draggable"));
|
|
10
|
-
const ChartContext_1 = require("../context/ChartContext");
|
|
11
|
-
const ScaleContext_1 = require("../context/ScaleContext");
|
|
12
|
-
function Resizable({ from, to, onDrag = () => null, onDrop }) {
|
|
13
|
-
const { height, margin, mode } = (0, ChartContext_1.useChartData)();
|
|
14
|
-
const [rightDragVisibility, setRightDragVisibility] = (0, react_1.useState)(false);
|
|
15
|
-
const [leftDragVisibility, setLeftDragVisibility] = (0, react_1.useState)(false);
|
|
16
|
-
const [enable, setEnable] = (0, react_1.useState)(true);
|
|
17
|
-
const draggableRightRef = (0, react_1.useRef)(null);
|
|
18
|
-
const draggableLeftRef = (0, react_1.useRef)(null);
|
|
19
|
-
const { scaleX } = (0, ScaleContext_1.useScaleChecked)();
|
|
20
|
-
const handleRightStart = (0, react_1.useCallback)((e) => {
|
|
21
|
-
e.preventDefault();
|
|
22
|
-
e.stopPropagation();
|
|
23
|
-
setRightDragVisibility(true);
|
|
24
|
-
}, []);
|
|
25
|
-
const handleRightDrag = (0, react_1.useCallback)((e) => {
|
|
26
|
-
onDrag({ from: scaleX().invert(e.layerX) });
|
|
27
|
-
}, [onDrag, scaleX]);
|
|
28
|
-
const handleRightStop = (0, react_1.useCallback)((e) => {
|
|
29
|
-
e.preventDefault();
|
|
30
|
-
e.stopPropagation();
|
|
31
|
-
setRightDragVisibility(false);
|
|
32
|
-
const _range = mode === 'RTL'
|
|
33
|
-
? [scaleX().invert(e.layerX), to]
|
|
34
|
-
: [to, scaleX().invert(e.layerX)];
|
|
35
|
-
let resized;
|
|
36
|
-
if (_range[1] > _range[0]) {
|
|
37
|
-
resized = {
|
|
38
|
-
from: _range[0],
|
|
39
|
-
to: _range[1],
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
resized = {
|
|
44
|
-
from,
|
|
45
|
-
to,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
onDrop(resized);
|
|
49
|
-
}, [from, mode, onDrop, scaleX, to]);
|
|
50
|
-
const handleLeftStart = (0, react_1.useCallback)((e) => {
|
|
51
|
-
e.preventDefault();
|
|
52
|
-
e.stopPropagation();
|
|
53
|
-
setLeftDragVisibility(true);
|
|
54
|
-
}, []);
|
|
55
|
-
const handleLeftDrag = (0, react_1.useCallback)((e) => {
|
|
56
|
-
onDrag({ to: scaleX().invert(e.layerX) });
|
|
57
|
-
}, [onDrag, scaleX]);
|
|
58
|
-
const handleLeftStop = (0, react_1.useCallback)((e) => {
|
|
59
|
-
e.preventDefault();
|
|
60
|
-
e.stopPropagation();
|
|
61
|
-
setLeftDragVisibility(false);
|
|
62
|
-
const _range = mode === 'RTL'
|
|
63
|
-
? [from, scaleX().invert(e.layerX)]
|
|
64
|
-
: [scaleX().invert(e.layerX), from];
|
|
65
|
-
let resized;
|
|
66
|
-
if (_range[1] > _range[0]) {
|
|
67
|
-
resized = {
|
|
68
|
-
from: _range[0],
|
|
69
|
-
to: _range[1],
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
resized = {
|
|
74
|
-
from,
|
|
75
|
-
to,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
onDrop(resized);
|
|
79
|
-
}, [from, mode, onDrop, scaleX, to]);
|
|
80
|
-
const mouseDownCaptureHandler = (0, react_1.useCallback)(({ shiftKey }) => {
|
|
81
|
-
if (shiftKey) {
|
|
82
|
-
setEnable(false);
|
|
83
|
-
}
|
|
84
|
-
}, []);
|
|
85
|
-
const mouseUpCaptureHandler = (0, react_1.useCallback)(() => {
|
|
86
|
-
setEnable(true);
|
|
87
|
-
}, []);
|
|
88
|
-
const mouseOverHandler = (0, react_1.useCallback)(({ target, shiftKey }) => {
|
|
89
|
-
if (shiftKey) {
|
|
90
|
-
target.style.cursor = 'crosshair';
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
target.style.cursor = 'ew-resize';
|
|
94
|
-
}
|
|
95
|
-
}, []);
|
|
96
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_draggable_1.default, { axis: "x", defaultPosition: {
|
|
97
|
-
x: scaleX()(from),
|
|
98
|
-
y: 0,
|
|
99
|
-
}, position: {
|
|
100
|
-
x: scaleX()(from),
|
|
101
|
-
y: 0,
|
|
102
|
-
}, scale: 1, handle: ".handle", onStart: handleRightStart, onDrag: handleRightDrag, onStop: handleRightStop, nodeRef: draggableRightRef, children: (0, jsx_runtime_1.jsx)("rect", { ref: draggableRightRef, className: enable ? 'handle' : '', width: rightDragVisibility ? 1 : 6, fill: "red", height: height + margin.top, style: { fillOpacity: rightDragVisibility ? 1 : 0 }, onMouseDownCapture: mouseDownCaptureHandler, onMouseUpCapture: mouseUpCaptureHandler, onMouseEnter: mouseOverHandler }) }), (0, jsx_runtime_1.jsx)(react_draggable_1.default, { axis: "x", defaultPosition: {
|
|
103
|
-
x: scaleX()(to),
|
|
104
|
-
y: 0,
|
|
105
|
-
}, position: {
|
|
106
|
-
x: scaleX()(to),
|
|
107
|
-
y: 0,
|
|
108
|
-
}, handle: ".handle", scale: 1, onStart: handleLeftStart, onDrag: handleLeftDrag, onStop: handleLeftStop, nodeRef: draggableLeftRef, children: (0, jsx_runtime_1.jsx)("rect", { ref: draggableLeftRef, className: enable ? 'handle' : '', width: leftDragVisibility ? 1 : 6, fill: "red", height: height + margin.top, style: { fillOpacity: leftDragVisibility ? 1 : 0 }, onMouseDownCapture: mouseDownCaptureHandler, onMouseUpCapture: mouseUpCaptureHandler, onMouseEnter: mouseOverHandler }) })] }));
|
|
109
|
-
}
|
|
110
|
-
exports.default = Resizable;
|