nmrium 0.39.0 → 0.40.1
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/context/LoggerContext.js +11 -6
- package/lib/component/elements/popup/Alert/AlertBlock.d.ts +7 -0
- package/lib/component/elements/popup/Alert/AlertBlock.js +24 -0
- package/lib/component/elements/popup/Alert/Provider.js +2 -20
- package/lib/component/elements/popup/Modal/ConfirmDialog.js +2 -1
- package/lib/component/header/Header.js +2 -2
- package/lib/component/modal/AboutUsModal.js +4 -2
- package/lib/component/modal/LogsHistoryModal.d.ts +6 -0
- package/lib/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +6 -4
- package/lib/component/modal/setting/GeneralSettings.js +28 -27
- package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +18 -16
- package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
- package/lib/component/panels/RangesPanel/RangesHeader.js +9 -15
- package/lib/component/panels/RangesPanel/RangesPanel.js +7 -10
- package/lib/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
- package/lib/component/utility/export.d.ts +5 -4
- package/lib/component/utility/export.js +24 -52
- package/lib/utils/clipboard/clipboard.d.ts +12 -0
- package/lib/utils/clipboard/clipboard.js +15 -0
- package/lib/utils/clipboard/clipboardComponents.d.ts +45 -0
- package/lib/utils/clipboard/clipboardComponents.js +150 -0
- package/lib/utils/clipboard/clipboardHooks.d.ts +94 -0
- package/lib/utils/clipboard/clipboardHooks.js +142 -0
- package/lib/utils/clipboard/types.d.ts +1 -0
- package/lib/utils/clipboard/types.js +1 -0
- package/lib/versionInfo.js +1 -1
- package/lib-cjs/component/context/LoggerContext.js +10 -5
- package/lib-cjs/component/elements/popup/Alert/AlertBlock.js +30 -0
- package/lib-cjs/component/elements/popup/Alert/Provider.js +2 -20
- package/lib-cjs/component/elements/popup/Modal/ConfirmDialog.js +2 -1
- package/lib-cjs/component/header/Header.js +2 -2
- package/lib-cjs/component/modal/AboutUsModal.js +4 -2
- package/lib-cjs/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +8 -6
- package/lib-cjs/component/modal/setting/GeneralSettings.js +28 -27
- package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +17 -15
- package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
- package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +9 -15
- package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +7 -10
- package/lib-cjs/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
- package/lib-cjs/component/utility/export.js +24 -54
- package/lib-cjs/utils/clipboard/clipboard.js +23 -0
- package/lib-cjs/utils/clipboard/clipboardComponents.js +158 -0
- package/lib-cjs/utils/clipboard/clipboardHooks.js +147 -0
- package/lib-cjs/utils/clipboard/types.js +2 -0
- package/lib-cjs/versionInfo.js +1 -1
- package/package.json +13 -13
- package/lib/component/header/LogsHistory.d.ts +0 -1
|
@@ -10,12 +10,13 @@ const react_1 = require("react");
|
|
|
10
10
|
const fa_1 = require("react-icons/fa");
|
|
11
11
|
const io5_1 = require("react-icons/io5");
|
|
12
12
|
const ui_1 = require("react-science/ui");
|
|
13
|
+
const clipboardComponents_1 = require("../../../utils/clipboard/clipboardComponents");
|
|
14
|
+
const clipboardHooks_1 = require("../../../utils/clipboard/clipboardHooks");
|
|
13
15
|
const DispatchContext_1 = require("../../context/DispatchContext");
|
|
14
16
|
const ReactTable_1 = __importDefault(require("../../elements/ReactTable/ReactTable"));
|
|
15
17
|
const Alert_1 = require("../../elements/popup/Alert");
|
|
16
18
|
const usePanelPreferences_1 = require("../../hooks/usePanelPreferences");
|
|
17
19
|
const ExportAsJcampModal_1 = __importDefault(require("../../modal/ExportAsJcampModal"));
|
|
18
|
-
const export_1 = require("../../utility/export");
|
|
19
20
|
const ColorIndicator_1 = __importDefault(require("./base/ColorIndicator"));
|
|
20
21
|
const ShowHideSpectrumButton_1 = __importDefault(require("./base/ShowHideSpectrumButton"));
|
|
21
22
|
const SpectrumName_1 = require("./base/SpectrumName");
|
|
@@ -136,19 +137,15 @@ function SpectraTable(props) {
|
|
|
136
137
|
},
|
|
137
138
|
},
|
|
138
139
|
}), [onChangeVisibility, onOpenSettingModal]);
|
|
140
|
+
const { rawWriteWithType, cleanShouldFallback, shouldFallback, text } = (0, clipboardHooks_1.useClipboard)();
|
|
139
141
|
const selectContextMenuHandler = (0, react_1.useCallback)((option, spectrum) => {
|
|
140
142
|
const { id } = option.data;
|
|
141
143
|
switch (id) {
|
|
142
144
|
case SpectraContextMenuOptionsKeys.CopyToClipboard: {
|
|
143
145
|
void (async () => {
|
|
144
146
|
const { data, info } = spectrum;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
alert.success('Data copied to clipboard');
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
alert.error('Copy to clipboard failed');
|
|
151
|
-
}
|
|
147
|
+
await rawWriteWithType(JSON.stringify({ data, info }, (_, value) => ArrayBuffer.isView(value) ? Array.from(value) : value, 2));
|
|
148
|
+
alert.success('Data copied to clipboard');
|
|
152
149
|
})();
|
|
153
150
|
break;
|
|
154
151
|
}
|
|
@@ -166,7 +163,7 @@ function SpectraTable(props) {
|
|
|
166
163
|
break;
|
|
167
164
|
}
|
|
168
165
|
}
|
|
169
|
-
}, [alert, dispatch]);
|
|
166
|
+
}, [alert, dispatch, rawWriteWithType]);
|
|
170
167
|
function handleActiveRow(row) {
|
|
171
168
|
return activeSpectraObj?.[row?.original.id] || false;
|
|
172
169
|
}
|
|
@@ -220,7 +217,7 @@ function SpectraTable(props) {
|
|
|
220
217
|
? Spectra1DContextMenuOptions
|
|
221
218
|
: Spectra2DContextMenuOptions, onContextMenuSelect: selectContextMenuHandler, onSortEnd: handleSortEnd, style: { 'table td': { paddingTop: 0, paddingBottom: 0 } } }), exportedSpectrum && ((0, jsx_runtime_1.jsx)(ExportAsJcampModal_1.default, { spectrum: exportedSpectrum, closeDialog: () => {
|
|
222
219
|
setExportedSpectrum(null);
|
|
223
|
-
} }))] }));
|
|
220
|
+
} })), (0, jsx_runtime_1.jsx)(clipboardComponents_1.ClipboardFallbackModal, { mode: shouldFallback, onDismiss: cleanShouldFallback, text: text, label: "Spectra" })] }));
|
|
224
221
|
}
|
|
225
222
|
exports.SpectraTable = SpectraTable;
|
|
226
223
|
const ColumnHeader = ({ label, col, }) => {
|
|
@@ -3,46 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getBlob = exports.exportAsMatrix = exports.exportAsMol = exports.
|
|
6
|
+
exports.getBlob = exports.exportAsMatrix = exports.exportAsMol = exports.copyPNGToClipboard = exports.exportAsPng = exports.exportAsNMRE = exports.exportAsJSON = exports.exportAsSVG = void 0;
|
|
7
7
|
const file_saver_1 = require("file-saver");
|
|
8
8
|
const jszip_1 = __importDefault(require("jszip"));
|
|
9
|
-
|
|
10
|
-
return copyToClipboard(data, 'text/html');
|
|
11
|
-
}
|
|
12
|
-
exports.copyHTMLToClipboard = copyHTMLToClipboard;
|
|
13
|
-
async function copyTextToClipboard(data) {
|
|
14
|
-
return copyToClipboard(data, 'text/plain');
|
|
15
|
-
}
|
|
16
|
-
exports.copyTextToClipboard = copyTextToClipboard;
|
|
17
|
-
async function copyToClipboard(data, type) {
|
|
18
|
-
try {
|
|
19
|
-
if (typeof ClipboardItem !== 'undefined') {
|
|
20
|
-
void navigator.clipboard.write([
|
|
21
|
-
new ClipboardItem({
|
|
22
|
-
[type]: new Promise((resolve) => {
|
|
23
|
-
resolve(new Blob([data], { type }));
|
|
24
|
-
}),
|
|
25
|
-
}),
|
|
26
|
-
]);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
const clipboard = await import('clipboard-polyfill');
|
|
30
|
-
//TODO when Firefox team implement ClipboardItem this code should be removed
|
|
31
|
-
// this library is used mainly to solve the problem of copy HTML to a clipboard in Firefox but we use it for both HTML and plain text
|
|
32
|
-
const item = new clipboard.ClipboardItem({
|
|
33
|
-
[type]: new Blob([data], { type }),
|
|
34
|
-
});
|
|
35
|
-
await clipboard.write([item]);
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
9
|
+
const clipboard_1 = require("../../utils/clipboard/clipboard");
|
|
43
10
|
/**
|
|
44
11
|
* export the experiments result in JSON format
|
|
45
|
-
* @param
|
|
12
|
+
* @param data
|
|
13
|
+
* @param fileName
|
|
14
|
+
* @param spaceIndent
|
|
15
|
+
* @param isCompressed
|
|
46
16
|
*/
|
|
47
17
|
async function exportAsJSON(data, fileName = 'experiment', spaceIndent = 0, isCompressed = false) {
|
|
48
18
|
const fileData = JSON.stringify(data, (key, value) => ArrayBuffer.isView(value) ? Array.from(value) : value, spaceIndent);
|
|
@@ -151,16 +121,24 @@ function copyDataURLClipboardFireFox(image) {
|
|
|
151
121
|
}
|
|
152
122
|
function copyBlobToClipboard(canvas) {
|
|
153
123
|
canvas.toBlob((b) => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
124
|
+
if (!b)
|
|
125
|
+
return;
|
|
126
|
+
(async () => {
|
|
127
|
+
const clip = await (0, clipboard_1.newClipboardItem)({
|
|
128
|
+
[b.type]: b,
|
|
129
|
+
});
|
|
130
|
+
await (0, clipboard_1.write)([clip]);
|
|
131
|
+
})()
|
|
132
|
+
.catch(() => {
|
|
133
|
+
const png = canvas.toDataURL('image/png', 1);
|
|
134
|
+
copyDataURLClipboardFireFox(png);
|
|
135
|
+
URL.revokeObjectURL(png);
|
|
136
|
+
})
|
|
137
|
+
.then(() => {
|
|
158
138
|
// eslint-disable-next-line no-console
|
|
159
139
|
console.log('experiment copied.');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
reportError(error);
|
|
163
|
-
});
|
|
140
|
+
})
|
|
141
|
+
.catch(reportError);
|
|
164
142
|
});
|
|
165
143
|
}
|
|
166
144
|
function copyPNGToClipboard(rootRef, elementID) {
|
|
@@ -176,17 +154,9 @@ function copyPNGToClipboard(rootRef, elementID) {
|
|
|
176
154
|
}
|
|
177
155
|
let img = new Image();
|
|
178
156
|
const url = URL.createObjectURL(blob);
|
|
179
|
-
img.addEventListener('load',
|
|
157
|
+
img.addEventListener('load', () => {
|
|
180
158
|
context?.drawImage(img, 0, 0);
|
|
181
|
-
|
|
182
|
-
// @ts-expect-error write exists in some browsers
|
|
183
|
-
if (navigator.clipboard.write) {
|
|
184
|
-
copyBlobToClipboard(canvas);
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
copyDataURLClipboardFireFox(png);
|
|
188
|
-
}
|
|
189
|
-
URL.revokeObjectURL(png);
|
|
159
|
+
copyBlobToClipboard(canvas);
|
|
190
160
|
});
|
|
191
161
|
img.src = url;
|
|
192
162
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newClipboardItem = exports.write = exports.writeText = exports.read = exports.readText = void 0;
|
|
4
|
+
function readText() {
|
|
5
|
+
return import('clipboard-polyfill').then((c) => c.readText());
|
|
6
|
+
}
|
|
7
|
+
exports.readText = readText;
|
|
8
|
+
function read() {
|
|
9
|
+
return import('clipboard-polyfill').then((c) => c.read());
|
|
10
|
+
}
|
|
11
|
+
exports.read = read;
|
|
12
|
+
function writeText(data) {
|
|
13
|
+
return import('clipboard-polyfill').then((c) => c.writeText(data));
|
|
14
|
+
}
|
|
15
|
+
exports.writeText = writeText;
|
|
16
|
+
function write(data) {
|
|
17
|
+
return import('clipboard-polyfill').then((c) => c.write(data));
|
|
18
|
+
}
|
|
19
|
+
exports.write = write;
|
|
20
|
+
function newClipboardItem(items, options) {
|
|
21
|
+
return import('clipboard-polyfill').then((c) => new c.ClipboardItem(items, options));
|
|
22
|
+
}
|
|
23
|
+
exports.newClipboardItem = newClipboardItem;
|
|
@@ -0,0 +1,158 @@
|
|
|
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
|
+
exports.ClipboardFallbackModal = exports.ClipboardFallback = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const ui_1 = require("react-science/ui");
|
|
11
|
+
const Button_1 = __importDefault(require("../../component/elements/Button"));
|
|
12
|
+
const ClipboardForm = styled_1.default.form `
|
|
13
|
+
padding: 0.5rem;
|
|
14
|
+
|
|
15
|
+
& > label {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: 0.5rem;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
textarea {
|
|
22
|
+
padding: 0.5rem;
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
const Actions = styled_1.default.div `
|
|
26
|
+
display: flex;
|
|
27
|
+
gap: 0.5rem;
|
|
28
|
+
justify-content: flex-end;
|
|
29
|
+
`;
|
|
30
|
+
function throwError(props, prop) {
|
|
31
|
+
throw new Error(`props.${prop} is mandatory with ${String(props.mode)} mode`);
|
|
32
|
+
}
|
|
33
|
+
function assertReadProps(props) {
|
|
34
|
+
if (typeof props.onRead !== 'function')
|
|
35
|
+
throwError(props, 'onRead');
|
|
36
|
+
}
|
|
37
|
+
function assertReadTextProps(props) {
|
|
38
|
+
if (typeof props.onReadText !== 'function')
|
|
39
|
+
throwError(props, 'onReadText');
|
|
40
|
+
}
|
|
41
|
+
function assertWriteProps(props) {
|
|
42
|
+
if (!props.file)
|
|
43
|
+
throwError(props, 'file');
|
|
44
|
+
if (typeof props.onDismiss !== 'function')
|
|
45
|
+
throwError(props, 'onDismiss');
|
|
46
|
+
}
|
|
47
|
+
function assertWriteTextProps(props) {
|
|
48
|
+
if (typeof props.text !== 'string')
|
|
49
|
+
throwError(props, 'text');
|
|
50
|
+
if (typeof props.onDismiss !== 'function')
|
|
51
|
+
throwError(props, 'onDismiss');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* switch between ClipboardFallback variant over mode props
|
|
55
|
+
* mode === read => ClipboardFallbackReadProps
|
|
56
|
+
* mode === readText => ClipboardFallbackReadTextProps
|
|
57
|
+
* mode === write => ClipboardFallbackWriteProps
|
|
58
|
+
* mode === writeText => ClipboardFallbackWriteTextProps
|
|
59
|
+
*
|
|
60
|
+
* implement what you need in function what part of the clipboard api from useClipboard you use
|
|
61
|
+
* props will be checked at runtime
|
|
62
|
+
*
|
|
63
|
+
* @param props
|
|
64
|
+
*/
|
|
65
|
+
function ClipboardFallback(props) {
|
|
66
|
+
switch (props.mode) {
|
|
67
|
+
case 'read':
|
|
68
|
+
assertReadProps(props);
|
|
69
|
+
return (0, jsx_runtime_1.jsx)(ClipboardFallbackRead, { ...props });
|
|
70
|
+
case 'readText':
|
|
71
|
+
assertReadTextProps(props);
|
|
72
|
+
return (0, jsx_runtime_1.jsx)(ClipboardFallbackReadText, { ...props });
|
|
73
|
+
case 'write': {
|
|
74
|
+
assertWriteProps(props);
|
|
75
|
+
return (0, jsx_runtime_1.jsx)(ClipboardFallbackWrite, { ...props });
|
|
76
|
+
}
|
|
77
|
+
case 'writeText':
|
|
78
|
+
assertWriteTextProps(props);
|
|
79
|
+
return (0, jsx_runtime_1.jsx)(ClipboardFallbackWriteText, { ...props });
|
|
80
|
+
default:
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.ClipboardFallback = ClipboardFallback;
|
|
85
|
+
/**
|
|
86
|
+
* return null if !props.mode
|
|
87
|
+
*
|
|
88
|
+
* @param props
|
|
89
|
+
* @see ClipboardFallback
|
|
90
|
+
*/
|
|
91
|
+
function ClipboardFallbackModal(props) {
|
|
92
|
+
if (!props.mode)
|
|
93
|
+
return null;
|
|
94
|
+
const titles = {
|
|
95
|
+
read: `Import data from file`,
|
|
96
|
+
readText: `Paste text from clipboard`,
|
|
97
|
+
write: `Export data to file`,
|
|
98
|
+
writeText: `Copy text from text area`,
|
|
99
|
+
};
|
|
100
|
+
return ((0, jsx_runtime_1.jsxs)(ui_1.Modal, { hasCloseButton: true, isOpen: true, onRequestClose: props.onDismiss, children: [(0, jsx_runtime_1.jsx)(ui_1.Modal.Header, { children: (0, jsx_runtime_1.jsx)("h2", { children: titles[props.mode] }) }), (0, jsx_runtime_1.jsx)(ui_1.Modal.Body, { children: (0, jsx_runtime_1.jsx)(ClipboardFallback, { ...props }) })] }));
|
|
101
|
+
}
|
|
102
|
+
exports.ClipboardFallbackModal = ClipboardFallbackModal;
|
|
103
|
+
function ClipboardFallbackRead(props) {
|
|
104
|
+
const onFileRef = (0, react_1.useRef)(props.onRead);
|
|
105
|
+
onFileRef.current = props.onRead;
|
|
106
|
+
const onSubmit = (0, react_1.useCallback)((event) => {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
const data = new FormData(event.currentTarget);
|
|
109
|
+
const file = data.get('file');
|
|
110
|
+
if (!(file instanceof File))
|
|
111
|
+
return;
|
|
112
|
+
onFileRef.current(file);
|
|
113
|
+
}, []);
|
|
114
|
+
if (props.mode !== 'read')
|
|
115
|
+
return null;
|
|
116
|
+
return ((0, jsx_runtime_1.jsxs)(ClipboardForm, { onSubmit: onSubmit, children: [(0, jsx_runtime_1.jsxs)("label", { children: [(0, jsx_runtime_1.jsx)("span", { children: props.label ?? 'File' }), (0, jsx_runtime_1.jsx)("input", { name: "file", type: "file" })] }), (0, jsx_runtime_1.jsx)("p", { children: "We were not able to read from your clipboard. Please input your data in the file field" }), (0, jsx_runtime_1.jsxs)(Actions, { children: [(0, jsx_runtime_1.jsx)(Button_1.default.Done, { type: "submit", children: "Submit" }), (0, jsx_runtime_1.jsx)(Button_1.default.Secondary, { type: "reset", onClick: props.onDismiss, children: "Cancel" })] })] }));
|
|
117
|
+
}
|
|
118
|
+
function ClipboardFallbackReadText(props) {
|
|
119
|
+
const onTextRef = (0, react_1.useRef)(props.onReadText);
|
|
120
|
+
onTextRef.current = props.onReadText;
|
|
121
|
+
const onSubmit = (0, react_1.useCallback)((event) => {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
const data = new FormData(event.currentTarget);
|
|
124
|
+
const text = data.get('text');
|
|
125
|
+
if (typeof text !== 'string')
|
|
126
|
+
return;
|
|
127
|
+
onTextRef.current(text);
|
|
128
|
+
}, []);
|
|
129
|
+
if (props.mode !== 'readText')
|
|
130
|
+
return null;
|
|
131
|
+
return ((0, jsx_runtime_1.jsxs)(ClipboardForm, { onSubmit: onSubmit, children: [(0, jsx_runtime_1.jsxs)("label", { children: [(0, jsx_runtime_1.jsx)("span", { children: props.label ?? 'Text' }), (0, jsx_runtime_1.jsx)("textarea", { name: "text", cols: 50, rows: 10 })] }), (0, jsx_runtime_1.jsx)("p", { children: "We were not able to read text from your clipboard. Please paste your data in the text area." }), (0, jsx_runtime_1.jsxs)(Actions, { children: [(0, jsx_runtime_1.jsx)(Button_1.default.Done, { type: "submit", children: "Submit" }), (0, jsx_runtime_1.jsx)(Button_1.default.Secondary, { type: "reset", onClick: props.onDismiss, children: "Cancel" })] })] }));
|
|
132
|
+
}
|
|
133
|
+
function ClipboardFallbackWrite(props) {
|
|
134
|
+
const onDismissRef = (0, react_1.useRef)(props.onDismiss);
|
|
135
|
+
onDismissRef.current = props.onDismiss;
|
|
136
|
+
const onSubmit = (0, react_1.useCallback)((event) => {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
onDismissRef.current();
|
|
139
|
+
}, []);
|
|
140
|
+
const downloadLink = (0, react_1.useMemo)(() => URL.createObjectURL(props.file), [props.file]);
|
|
141
|
+
(0, react_1.useEffect)(() => {
|
|
142
|
+
return () => URL.revokeObjectURL(downloadLink);
|
|
143
|
+
}, [downloadLink]);
|
|
144
|
+
if (props.mode !== 'write')
|
|
145
|
+
return null;
|
|
146
|
+
return ((0, jsx_runtime_1.jsxs)(ClipboardForm, { onSubmit: onSubmit, children: [(0, jsx_runtime_1.jsx)("p", { children: props.label ?? 'Download' }), (0, jsx_runtime_1.jsx)("a", { href: downloadLink, download: props.file.name, children: "We were not able to write data to your clipboard. Please download your data with this link." }), (0, jsx_runtime_1.jsx)(Actions, { children: (0, jsx_runtime_1.jsx)(Button_1.default.Secondary, { type: "submit", children: "Dismiss" }) })] }));
|
|
147
|
+
}
|
|
148
|
+
function ClipboardFallbackWriteText(props) {
|
|
149
|
+
const onDismissRef = (0, react_1.useRef)(props.onDismiss);
|
|
150
|
+
onDismissRef.current = props.onDismiss;
|
|
151
|
+
const onSubmit = (0, react_1.useCallback)((event) => {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
onDismissRef.current();
|
|
154
|
+
}, []);
|
|
155
|
+
if (props.mode !== 'writeText')
|
|
156
|
+
return null;
|
|
157
|
+
return ((0, jsx_runtime_1.jsxs)(ClipboardForm, { onSubmit: onSubmit, children: [(0, jsx_runtime_1.jsx)("span", { children: props.label ?? 'Text' }), (0, jsx_runtime_1.jsx)("textarea", { name: "text", cols: 30, rows: 10, ref: (node) => node?.select(), children: props.text }), (0, jsx_runtime_1.jsx)("p", { children: "We were not able to write text to your clipboard. Please copy your data in the text area." }), (0, jsx_runtime_1.jsx)(Actions, { children: (0, jsx_runtime_1.jsx)(Button_1.default.Secondary, { type: "submit", children: "Dismiss" }) })] }));
|
|
158
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useClipboard = exports.useNavigatorPermission = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const clipboard_1 = require("./clipboard");
|
|
6
|
+
function useNavigatorPermission(now, permissionName, onGranted, onError = reportError) {
|
|
7
|
+
const [state, setState] = (0, react_1.useState)();
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
if (!now)
|
|
10
|
+
return;
|
|
11
|
+
let canceled = false;
|
|
12
|
+
let status;
|
|
13
|
+
function onPermissionChange() {
|
|
14
|
+
if (canceled)
|
|
15
|
+
return;
|
|
16
|
+
setState(status.state);
|
|
17
|
+
if (status.state === 'granted') {
|
|
18
|
+
onGranted?.();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
void navigator.permissions
|
|
22
|
+
.query({ name: permissionName })
|
|
23
|
+
.then((pStatus) => {
|
|
24
|
+
if (canceled)
|
|
25
|
+
return;
|
|
26
|
+
status = pStatus;
|
|
27
|
+
setState(status.state);
|
|
28
|
+
status.addEventListener('change', onPermissionChange);
|
|
29
|
+
})
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
if (canceled)
|
|
32
|
+
return;
|
|
33
|
+
onError(error);
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
canceled = true;
|
|
37
|
+
if (status) {
|
|
38
|
+
status.removeEventListener('change', onPermissionChange);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, [now, permissionName, onGranted, onError]);
|
|
42
|
+
return { state, isGranted: state === 'granted' };
|
|
43
|
+
}
|
|
44
|
+
exports.useNavigatorPermission = useNavigatorPermission;
|
|
45
|
+
/**
|
|
46
|
+
* Give you a wrapped clipboard api and a shouldFallback state.
|
|
47
|
+
* ignore if read and readText return promise filled with undefined, and rely on shouldFallback to display an alternative interaction.
|
|
48
|
+
* You should use ClipboardFallback component
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```tsx
|
|
52
|
+
* const { readText, shouldFallback, setShouldFallback } = useClipboard();
|
|
53
|
+
*
|
|
54
|
+
* function handlePasteAction() {
|
|
55
|
+
* // yes you can safely ignore error here,
|
|
56
|
+
* // readText() will never throw, error is caught and set shouldFallback to corresponding mode
|
|
57
|
+
* void readText().then(handlePaste);
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* function handlePaste(text: string | undefined) {
|
|
61
|
+
* if (!text) return;
|
|
62
|
+
*
|
|
63
|
+
* setState(text);
|
|
64
|
+
* setShouldFallback(null);
|
|
65
|
+
* }
|
|
66
|
+
*
|
|
67
|
+
* return (
|
|
68
|
+
* <>
|
|
69
|
+
* <button onClick={handlePasteAction}>Paste</button>
|
|
70
|
+
* <ClipboardFallbackModal
|
|
71
|
+
* mode={shouldFallback}
|
|
72
|
+
* onDismiss={() => setShouldFallback(null)}
|
|
73
|
+
* onReadText={handlePaste}
|
|
74
|
+
* />
|
|
75
|
+
* </>
|
|
76
|
+
* )
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function useClipboard() {
|
|
80
|
+
const [shouldFallback, setShouldFallback] = (0, react_1.useState)();
|
|
81
|
+
const [text, setText] = (0, react_1.useState)();
|
|
82
|
+
const [blobs, setBlobs] = (0, react_1.useState)();
|
|
83
|
+
const cleanShouldFallback = (0, react_1.useCallback)(() => {
|
|
84
|
+
setShouldFallback(undefined);
|
|
85
|
+
setText(undefined);
|
|
86
|
+
setBlobs(undefined);
|
|
87
|
+
}, []);
|
|
88
|
+
const clipboardAPI = (0, react_1.useMemo)(() => ({
|
|
89
|
+
async read() {
|
|
90
|
+
try {
|
|
91
|
+
return await (0, clipboard_1.read)();
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
setShouldFallback('read');
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
async readText() {
|
|
98
|
+
try {
|
|
99
|
+
return await (0, clipboard_1.readText)();
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
setShouldFallback('readText');
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
async write(data) {
|
|
106
|
+
try {
|
|
107
|
+
return await (0, clipboard_1.write)(data);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
const blobs = await Promise.all(data.map((ci) => ci.getType(ci.types[0])));
|
|
111
|
+
setBlobs(blobs);
|
|
112
|
+
setShouldFallback('write');
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
async rawWriteWithType(data, type = 'text/plain') {
|
|
116
|
+
try {
|
|
117
|
+
const item = await (0, clipboard_1.newClipboardItem)({
|
|
118
|
+
[type]: new Promise((resolve) => {
|
|
119
|
+
resolve(new Blob([data], { type }));
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
return await (0, clipboard_1.write)([item]);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
setText(data);
|
|
126
|
+
setShouldFallback('writeText');
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
async writeText(data) {
|
|
130
|
+
try {
|
|
131
|
+
return await (0, clipboard_1.writeText)(data);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
setText(data);
|
|
135
|
+
setShouldFallback('writeText');
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
}), []);
|
|
139
|
+
return {
|
|
140
|
+
...clipboardAPI,
|
|
141
|
+
shouldFallback,
|
|
142
|
+
text,
|
|
143
|
+
blobs,
|
|
144
|
+
cleanShouldFallback,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
exports.useClipboard = useClipboard;
|
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.40.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib-cjs/component/NMRium.js",
|
|
7
7
|
"module": "lib/component/NMRium.js",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
|
|
28
28
|
"prepack": "npm run clean-lib && npm run compile",
|
|
29
29
|
"prepublishOnly": "npm run set-version-npm",
|
|
30
|
-
"prettier": "prettier --check src",
|
|
31
|
-
"prettier-write": "prettier --write src",
|
|
30
|
+
"prettier": "prettier --check src test-e2e",
|
|
31
|
+
"prettier-write": "prettier --write src test-e2e",
|
|
32
32
|
"set-version-npm": "VERSION=$(jq .version package.json | tr -d '\"') && echo \"export default { version: 'v$VERSION' };\" > src/versionInfo.ts",
|
|
33
33
|
"set-version-sha": "SHA=$(git rev-parse HEAD) && echo \"export default { version: 'git-$SHA' };\" > src/versionInfo.ts",
|
|
34
34
|
"start": "npm run dev",
|
|
35
35
|
"stylelint": "stylelint \"**/*.{css,tsx}\"",
|
|
36
36
|
"stylelint-fix": "npm run stylelint -- --fix",
|
|
37
|
-
"test": "npm run test-only && npm run
|
|
37
|
+
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types && npm run stylelint && npm run build-no-minify && npm run test-e2e",
|
|
38
38
|
"test-only": "vitest run --coverage",
|
|
39
39
|
"test-e2e": "playwright test --project chromium",
|
|
40
40
|
"test-e2e-server": "serve -l tcp://localhost:3000 build"
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"multiplet-analysis": "^2.1.1",
|
|
87
87
|
"nmr-correlation": "^2.3.3",
|
|
88
88
|
"nmr-load-save": "^0.13.2",
|
|
89
|
-
"nmr-processing": "^9.7.
|
|
89
|
+
"nmr-processing": "^9.7.4",
|
|
90
90
|
"nmredata": "^0.9.2",
|
|
91
91
|
"numeral": "^2.0.6",
|
|
92
92
|
"openchemlib": "^8.3.0",
|
|
@@ -118,32 +118,32 @@
|
|
|
118
118
|
"@playwright/test": "^1.35.1",
|
|
119
119
|
"@simbathesailor/use-what-changed": "^2.0.0",
|
|
120
120
|
"@types/d3": "^7.4.0",
|
|
121
|
-
"@types/node": "^20.
|
|
121
|
+
"@types/node": "^20.4.0",
|
|
122
122
|
"@types/papaparse": "^5.3.7",
|
|
123
123
|
"@types/react": "^18.2.14",
|
|
124
124
|
"@types/react-dom": "^18.2.6",
|
|
125
125
|
"@types/react-table": "^7.7.14",
|
|
126
126
|
"@vitejs/plugin-react-swc": "^3.3.2",
|
|
127
|
-
"@vitest/coverage-v8": "^0.32.
|
|
127
|
+
"@vitest/coverage-v8": "^0.32.4",
|
|
128
128
|
"cross-env": "^7.0.3",
|
|
129
129
|
"cspell": "^6.31.1",
|
|
130
|
-
"eslint": "^8.
|
|
130
|
+
"eslint": "^8.44.0",
|
|
131
131
|
"eslint-config-cheminfo-react": "^9.1.1",
|
|
132
132
|
"eslint-config-cheminfo-typescript": "^11.3.1",
|
|
133
133
|
"modern-normalize": "^2.0.0",
|
|
134
134
|
"postcss-styled-syntax": "^0.4.0",
|
|
135
135
|
"prettier": "^2.8.8",
|
|
136
|
-
"rc-menu": "^9.
|
|
136
|
+
"rc-menu": "^9.11.0",
|
|
137
137
|
"react": "^18.2.0",
|
|
138
138
|
"react-dom": "^18.2.0",
|
|
139
|
-
"react-router-dom": "^6.14.
|
|
139
|
+
"react-router-dom": "^6.14.1",
|
|
140
140
|
"rimraf": "^5.0.1",
|
|
141
141
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
142
142
|
"serve": "^14.2.0",
|
|
143
|
-
"stylelint": "^15.
|
|
144
|
-
"stylelint-config-standard": "^
|
|
143
|
+
"stylelint": "^15.10.1",
|
|
144
|
+
"stylelint-config-standard": "^34.0.0",
|
|
145
145
|
"typescript": "~5.1.6",
|
|
146
146
|
"vite": "^4.3.9",
|
|
147
|
-
"vitest": "^0.32.
|
|
147
|
+
"vitest": "^0.32.4"
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function LogsHistory(): import("react/jsx-runtime").JSX.Element;
|