nmrium 0.38.2 → 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.
Files changed (104) hide show
  1. package/lib/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
  2. package/lib/component/EventsTrackers/KeysListenerTracker.js +90 -67
  3. package/lib/component/NMRium.d.ts +1 -0
  4. package/lib/component/NMRium.js +4 -2
  5. package/lib/component/context/LoggerContext.js +12 -2
  6. package/lib/component/context/PreferencesContext.d.ts +4 -2
  7. package/lib/component/elements/formik/FormikError.d.ts +8 -0
  8. package/lib/component/elements/formik/FormikError.js +22 -0
  9. package/lib/component/elements/popup/Alert/AlertBlock.d.ts +7 -0
  10. package/lib/component/elements/popup/Alert/AlertBlock.js +24 -0
  11. package/lib/component/elements/popup/Alert/Provider.js +2 -20
  12. package/lib/component/elements/popup/Modal/ConfirmDialog.js +2 -1
  13. package/lib/component/header/Header.js +2 -2
  14. package/lib/component/hooks/useSaveSettings.js +18 -16
  15. package/lib/component/modal/AboutUsModal.js +4 -2
  16. package/lib/component/modal/LoadJCAMPModal.js +41 -28
  17. package/lib/component/modal/LogsHistoryModal.d.ts +6 -0
  18. package/lib/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +6 -4
  19. package/lib/component/modal/PredictSpectraModal.js +12 -2
  20. package/lib/component/modal/editRange/EditRangeModal.d.ts +7 -6
  21. package/lib/component/modal/editRange/EditRangeModal.js +33 -13
  22. package/lib/component/modal/setting/GeneralSettings.js +29 -28
  23. package/lib/component/panels/MoleculesPanel/MoleculePanelHeader.js +18 -16
  24. package/lib/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
  25. package/lib/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js +1 -1
  26. package/lib/component/panels/Panels.js +2 -2
  27. package/lib/component/panels/RangesPanel/RangesHeader.js +9 -15
  28. package/lib/component/panels/RangesPanel/RangesPanel.js +7 -10
  29. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.d.ts +1 -1
  30. package/lib/component/panels/RangesPanel/hooks/useEditRangeModal.js +9 -12
  31. package/lib/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
  32. package/lib/component/panels/predictionPanel/PredictionPanel.js +3 -1
  33. package/lib/component/reducer/actions/DatabaseActions.js +6 -4
  34. package/lib/component/reducer/actions/DomainActions.js +3 -0
  35. package/lib/component/reducer/actions/IntegralsActions.js +3 -1
  36. package/lib/component/reducer/actions/SpectrumsActions.js +6 -6
  37. package/lib/component/reducer/actions/ToolsActions.js +3 -32
  38. package/lib/component/reducer/actions/ZonesActions.js +2 -4
  39. package/lib/component/reducer/helper/ZoomHistoryManager.d.ts +8 -0
  40. package/lib/component/reducer/helper/ZoomHistoryManager.js +35 -0
  41. package/lib/component/reducer/preferences/actions/addWorkspace.js +2 -2
  42. package/lib/component/reducer/preferences/preferencesReducer.d.ts +2 -2
  43. package/lib/component/utility/export.d.ts +5 -4
  44. package/lib/component/utility/export.js +24 -52
  45. package/lib/data/PredictionManager.d.ts +3 -1
  46. package/lib/data/PredictionManager.js +27 -1
  47. package/lib/data/data1d/Spectrum1D/generateSpectrumFromPublicationString.d.ts +1 -2
  48. package/lib/data/data1d/Spectrum1D/integrals/initiateIntegrals.d.ts +1 -1
  49. package/lib/data/data1d/Spectrum1D/ranges/detectSignal.js +13 -6
  50. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.d.ts +1 -1
  51. package/lib/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +23 -18
  52. package/lib/utils/clipboard/clipboard.d.ts +12 -0
  53. package/lib/utils/clipboard/clipboard.js +15 -0
  54. package/lib/utils/clipboard/clipboardComponents.d.ts +45 -0
  55. package/lib/utils/clipboard/clipboardComponents.js +150 -0
  56. package/lib/utils/clipboard/clipboardHooks.d.ts +94 -0
  57. package/lib/utils/clipboard/clipboardHooks.js +142 -0
  58. package/lib/utils/clipboard/types.d.ts +1 -0
  59. package/lib/utils/clipboard/types.js +1 -0
  60. package/lib/versionInfo.js +1 -1
  61. package/lib-cjs/component/1d/multiAnalysis/MultiAnalysisRanges.js +1 -1
  62. package/lib-cjs/component/EventsTrackers/KeysListenerTracker.js +90 -67
  63. package/lib-cjs/component/NMRium.js +4 -2
  64. package/lib-cjs/component/context/LoggerContext.js +11 -1
  65. package/lib-cjs/component/elements/formik/FormikError.js +27 -0
  66. package/lib-cjs/component/elements/popup/Alert/AlertBlock.js +30 -0
  67. package/lib-cjs/component/elements/popup/Alert/Provider.js +2 -20
  68. package/lib-cjs/component/elements/popup/Modal/ConfirmDialog.js +2 -1
  69. package/lib-cjs/component/header/Header.js +2 -2
  70. package/lib-cjs/component/hooks/useSaveSettings.js +17 -15
  71. package/lib-cjs/component/modal/AboutUsModal.js +4 -2
  72. package/lib-cjs/component/modal/LoadJCAMPModal.js +41 -28
  73. package/lib-cjs/component/{header/LogsHistory.js → modal/LogsHistoryModal.js} +8 -6
  74. package/lib-cjs/component/modal/PredictSpectraModal.js +12 -2
  75. package/lib-cjs/component/modal/editRange/EditRangeModal.js +32 -12
  76. package/lib-cjs/component/modal/setting/GeneralSettings.js +29 -28
  77. package/lib-cjs/component/panels/MoleculesPanel/MoleculePanelHeader.js +17 -15
  78. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/MultipleSpectraAnalysisPanel.js +9 -13
  79. package/lib-cjs/component/panels/MultipleSpectraAnalysisPanel/preferences/AnalysisTablePreferences.js +1 -1
  80. package/lib-cjs/component/panels/Panels.js +2 -2
  81. package/lib-cjs/component/panels/RangesPanel/RangesHeader.js +9 -15
  82. package/lib-cjs/component/panels/RangesPanel/RangesPanel.js +7 -10
  83. package/lib-cjs/component/panels/RangesPanel/hooks/useEditRangeModal.js +9 -12
  84. package/lib-cjs/component/panels/SpectrumsPanel/SpectraTable.js +7 -10
  85. package/lib-cjs/component/panels/predictionPanel/PredictionPanel.js +3 -1
  86. package/lib-cjs/component/reducer/actions/DatabaseActions.js +6 -4
  87. package/lib-cjs/component/reducer/actions/DomainActions.js +3 -0
  88. package/lib-cjs/component/reducer/actions/IntegralsActions.js +3 -1
  89. package/lib-cjs/component/reducer/actions/SpectrumsActions.js +6 -6
  90. package/lib-cjs/component/reducer/actions/ToolsActions.js +26 -32
  91. package/lib-cjs/component/reducer/actions/ZonesActions.js +2 -4
  92. package/lib-cjs/component/reducer/helper/ZoomHistoryManager.js +37 -0
  93. package/lib-cjs/component/reducer/preferences/actions/addWorkspace.js +2 -2
  94. package/lib-cjs/component/utility/export.js +24 -54
  95. package/lib-cjs/data/PredictionManager.js +27 -1
  96. package/lib-cjs/data/data1d/Spectrum1D/ranges/detectSignal.js +13 -6
  97. package/lib-cjs/data/data1d/Spectrum1D/ranges/generateSpectrumFromRanges.js +23 -18
  98. package/lib-cjs/utils/clipboard/clipboard.js +23 -0
  99. package/lib-cjs/utils/clipboard/clipboardComponents.js +158 -0
  100. package/lib-cjs/utils/clipboard/clipboardHooks.js +147 -0
  101. package/lib-cjs/utils/clipboard/types.js +2 -0
  102. package/lib-cjs/versionInfo.js +1 -1
  103. package/package.json +17 -17
  104. package/lib/component/header/LogsHistory.d.ts +0 -1
@@ -2,23 +2,28 @@ import { rangesToXY } from 'nmr-processing';
2
2
  import { initiateDatum1D } from '../initiateDatum1D';
3
3
  export function generateSpectrumFromRanges(ranges, info, usedColors) {
4
4
  const { nucleus, solvent, name = null, frequency = 400 } = info;
5
- const { x, y } = rangesToXY(ranges, {
6
- nucleus,
7
- frequency,
8
- nbPoints: 2 ** 17,
9
- });
10
- const datum = initiateDatum1D({
11
- data: { x, im: null, re: y },
12
- info: {
5
+ try {
6
+ const { x, y } = rangesToXY(ranges, {
13
7
  nucleus,
14
- originFrequency: frequency,
15
- baseFrequency: frequency,
16
- pulseSequence: '',
17
- solvent,
18
- isFt: true,
19
- name,
20
- },
21
- ranges: { values: ranges, options: { sum: 100 } },
22
- }, { usedColors });
23
- return datum;
8
+ frequency,
9
+ nbPoints: 2 ** 17,
10
+ });
11
+ const datum = initiateDatum1D({
12
+ data: { x, im: null, re: y },
13
+ info: {
14
+ nucleus,
15
+ originFrequency: frequency,
16
+ baseFrequency: frequency,
17
+ pulseSequence: '',
18
+ solvent,
19
+ isFt: true,
20
+ name,
21
+ },
22
+ ranges: { values: ranges, options: { sum: 100 } },
23
+ }, { usedColors });
24
+ return datum;
25
+ }
26
+ catch (error) {
27
+ reportError(error);
28
+ }
24
29
  }
@@ -0,0 +1,12 @@
1
+ export declare function readText(): Promise<string>;
2
+ export declare function read(): Promise<ClipboardItems>;
3
+ export declare function writeText(data: string): Promise<void>;
4
+ export interface ClipboardItemInterface {
5
+ readonly presentationStyle?: PresentationStyle;
6
+ readonly lastModified?: number;
7
+ readonly delayed?: boolean;
8
+ readonly types: ReadonlyArray<string>;
9
+ getType(type: string): Promise<Blob>;
10
+ }
11
+ export declare function write(data: ClipboardItemInterface[]): Promise<void>;
12
+ export declare function newClipboardItem(items: Record<string, string | Blob | PromiseLike<string | Blob>>, options?: ClipboardItemOptions): Promise<ClipboardItem>;
@@ -0,0 +1,15 @@
1
+ export function readText() {
2
+ return import('clipboard-polyfill').then((c) => c.readText());
3
+ }
4
+ export function read() {
5
+ return import('clipboard-polyfill').then((c) => c.read());
6
+ }
7
+ export function writeText(data) {
8
+ return import('clipboard-polyfill').then((c) => c.writeText(data));
9
+ }
10
+ export function write(data) {
11
+ return import('clipboard-polyfill').then((c) => c.write(data));
12
+ }
13
+ export function newClipboardItem(items, options) {
14
+ return import('clipboard-polyfill').then((c) => new c.ClipboardItem(items, options));
15
+ }
@@ -0,0 +1,45 @@
1
+ import { ClipboardMode } from './types';
2
+ export interface CFBP {
3
+ mode: ClipboardMode | undefined;
4
+ label?: string;
5
+ onDismiss: () => void;
6
+ }
7
+ export interface ClipboardFallbackProps extends CFBP, Partial<Omit<ClipboardFallbackReadProps, 'mode' | 'label' | 'onDismiss'>>, Partial<Omit<ClipboardFallbackReadTextProps, 'mode' | 'label' | 'onDismiss'>>, Partial<Omit<ClipboardFallbackWriteProps, 'mode' | 'label' | 'onDismiss'>>, Partial<Omit<ClipboardFallbackWriteTextProps, 'mode' | 'label' | 'onDismiss'>> {
8
+ }
9
+ /**
10
+ * switch between ClipboardFallback variant over mode props
11
+ * mode === read => ClipboardFallbackReadProps
12
+ * mode === readText => ClipboardFallbackReadTextProps
13
+ * mode === write => ClipboardFallbackWriteProps
14
+ * mode === writeText => ClipboardFallbackWriteTextProps
15
+ *
16
+ * implement what you need in function what part of the clipboard api from useClipboard you use
17
+ * props will be checked at runtime
18
+ *
19
+ * @param props
20
+ */
21
+ export declare function ClipboardFallback(props: ClipboardFallbackProps): import("react/jsx-runtime").JSX.Element | null;
22
+ /**
23
+ * return null if !props.mode
24
+ *
25
+ * @param props
26
+ * @see ClipboardFallback
27
+ */
28
+ export declare function ClipboardFallbackModal(props: ClipboardFallbackProps): import("react/jsx-runtime").JSX.Element | null;
29
+ interface ClipboardFallbackReadProps extends CFBP {
30
+ onRead: (file: File) => void;
31
+ mode: 'read';
32
+ }
33
+ interface ClipboardFallbackReadTextProps extends CFBP {
34
+ onReadText: (text: string) => void;
35
+ mode: 'readText';
36
+ }
37
+ interface ClipboardFallbackWriteProps extends CFBP {
38
+ file: File;
39
+ mode: 'write';
40
+ }
41
+ interface ClipboardFallbackWriteTextProps extends CFBP {
42
+ text: string;
43
+ mode: 'writeText';
44
+ }
45
+ export {};
@@ -0,0 +1,150 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styled from '@emotion/styled';
3
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
4
+ import { Modal } from 'react-science/ui';
5
+ import Button from '../../component/elements/Button';
6
+ const ClipboardForm = styled.form `
7
+ padding: 0.5rem;
8
+
9
+ & > label {
10
+ display: flex;
11
+ flex-direction: column;
12
+ gap: 0.5rem;
13
+ }
14
+
15
+ textarea {
16
+ padding: 0.5rem;
17
+ }
18
+ `;
19
+ const Actions = styled.div `
20
+ display: flex;
21
+ gap: 0.5rem;
22
+ justify-content: flex-end;
23
+ `;
24
+ function throwError(props, prop) {
25
+ throw new Error(`props.${prop} is mandatory with ${String(props.mode)} mode`);
26
+ }
27
+ function assertReadProps(props) {
28
+ if (typeof props.onRead !== 'function')
29
+ throwError(props, 'onRead');
30
+ }
31
+ function assertReadTextProps(props) {
32
+ if (typeof props.onReadText !== 'function')
33
+ throwError(props, 'onReadText');
34
+ }
35
+ function assertWriteProps(props) {
36
+ if (!props.file)
37
+ throwError(props, 'file');
38
+ if (typeof props.onDismiss !== 'function')
39
+ throwError(props, 'onDismiss');
40
+ }
41
+ function assertWriteTextProps(props) {
42
+ if (typeof props.text !== 'string')
43
+ throwError(props, 'text');
44
+ if (typeof props.onDismiss !== 'function')
45
+ throwError(props, 'onDismiss');
46
+ }
47
+ /**
48
+ * switch between ClipboardFallback variant over mode props
49
+ * mode === read => ClipboardFallbackReadProps
50
+ * mode === readText => ClipboardFallbackReadTextProps
51
+ * mode === write => ClipboardFallbackWriteProps
52
+ * mode === writeText => ClipboardFallbackWriteTextProps
53
+ *
54
+ * implement what you need in function what part of the clipboard api from useClipboard you use
55
+ * props will be checked at runtime
56
+ *
57
+ * @param props
58
+ */
59
+ export function ClipboardFallback(props) {
60
+ switch (props.mode) {
61
+ case 'read':
62
+ assertReadProps(props);
63
+ return _jsx(ClipboardFallbackRead, { ...props });
64
+ case 'readText':
65
+ assertReadTextProps(props);
66
+ return _jsx(ClipboardFallbackReadText, { ...props });
67
+ case 'write': {
68
+ assertWriteProps(props);
69
+ return _jsx(ClipboardFallbackWrite, { ...props });
70
+ }
71
+ case 'writeText':
72
+ assertWriteTextProps(props);
73
+ return _jsx(ClipboardFallbackWriteText, { ...props });
74
+ default:
75
+ return null;
76
+ }
77
+ }
78
+ /**
79
+ * return null if !props.mode
80
+ *
81
+ * @param props
82
+ * @see ClipboardFallback
83
+ */
84
+ export function ClipboardFallbackModal(props) {
85
+ if (!props.mode)
86
+ return null;
87
+ const titles = {
88
+ read: `Import data from file`,
89
+ readText: `Paste text from clipboard`,
90
+ write: `Export data to file`,
91
+ writeText: `Copy text from text area`,
92
+ };
93
+ return (_jsxs(Modal, { hasCloseButton: true, isOpen: true, onRequestClose: props.onDismiss, children: [_jsx(Modal.Header, { children: _jsx("h2", { children: titles[props.mode] }) }), _jsx(Modal.Body, { children: _jsx(ClipboardFallback, { ...props }) })] }));
94
+ }
95
+ function ClipboardFallbackRead(props) {
96
+ const onFileRef = useRef(props.onRead);
97
+ onFileRef.current = props.onRead;
98
+ const onSubmit = useCallback((event) => {
99
+ event.preventDefault();
100
+ const data = new FormData(event.currentTarget);
101
+ const file = data.get('file');
102
+ if (!(file instanceof File))
103
+ return;
104
+ onFileRef.current(file);
105
+ }, []);
106
+ if (props.mode !== 'read')
107
+ return null;
108
+ return (_jsxs(ClipboardForm, { onSubmit: onSubmit, children: [_jsxs("label", { children: [_jsx("span", { children: props.label ?? 'File' }), _jsx("input", { name: "file", type: "file" })] }), _jsx("p", { children: "We were not able to read from your clipboard. Please input your data in the file field" }), _jsxs(Actions, { children: [_jsx(Button.Done, { type: "submit", children: "Submit" }), _jsx(Button.Secondary, { type: "reset", onClick: props.onDismiss, children: "Cancel" })] })] }));
109
+ }
110
+ function ClipboardFallbackReadText(props) {
111
+ const onTextRef = useRef(props.onReadText);
112
+ onTextRef.current = props.onReadText;
113
+ const onSubmit = useCallback((event) => {
114
+ event.preventDefault();
115
+ const data = new FormData(event.currentTarget);
116
+ const text = data.get('text');
117
+ if (typeof text !== 'string')
118
+ return;
119
+ onTextRef.current(text);
120
+ }, []);
121
+ if (props.mode !== 'readText')
122
+ return null;
123
+ return (_jsxs(ClipboardForm, { onSubmit: onSubmit, children: [_jsxs("label", { children: [_jsx("span", { children: props.label ?? 'Text' }), _jsx("textarea", { name: "text", cols: 50, rows: 10 })] }), _jsx("p", { children: "We were not able to read text from your clipboard. Please paste your data in the text area." }), _jsxs(Actions, { children: [_jsx(Button.Done, { type: "submit", children: "Submit" }), _jsx(Button.Secondary, { type: "reset", onClick: props.onDismiss, children: "Cancel" })] })] }));
124
+ }
125
+ function ClipboardFallbackWrite(props) {
126
+ const onDismissRef = useRef(props.onDismiss);
127
+ onDismissRef.current = props.onDismiss;
128
+ const onSubmit = useCallback((event) => {
129
+ event.preventDefault();
130
+ onDismissRef.current();
131
+ }, []);
132
+ const downloadLink = useMemo(() => URL.createObjectURL(props.file), [props.file]);
133
+ useEffect(() => {
134
+ return () => URL.revokeObjectURL(downloadLink);
135
+ }, [downloadLink]);
136
+ if (props.mode !== 'write')
137
+ return null;
138
+ return (_jsxs(ClipboardForm, { onSubmit: onSubmit, children: [_jsx("p", { children: props.label ?? 'Download' }), _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." }), _jsx(Actions, { children: _jsx(Button.Secondary, { type: "submit", children: "Dismiss" }) })] }));
139
+ }
140
+ function ClipboardFallbackWriteText(props) {
141
+ const onDismissRef = useRef(props.onDismiss);
142
+ onDismissRef.current = props.onDismiss;
143
+ const onSubmit = useCallback((event) => {
144
+ event.preventDefault();
145
+ onDismissRef.current();
146
+ }, []);
147
+ if (props.mode !== 'writeText')
148
+ return null;
149
+ return (_jsxs(ClipboardForm, { onSubmit: onSubmit, children: [_jsx("span", { children: props.label ?? 'Text' }), _jsx("textarea", { name: "text", cols: 30, rows: 10, ref: (node) => node?.select(), children: props.text }), _jsx("p", { children: "We were not able to write text to your clipboard. Please copy your data in the text area." }), _jsx(Actions, { children: _jsx(Button.Secondary, { type: "submit", children: "Dismiss" }) })] }));
150
+ }
@@ -0,0 +1,94 @@
1
+ import { ClipboardMode } from './types';
2
+ type PN = PermissionName | 'clipboard-read' | 'clipboard-write';
3
+ export interface UsePermissionReturn {
4
+ state: PermissionState | undefined;
5
+ isGranted: boolean;
6
+ }
7
+ export declare function useNavigatorPermission(now: boolean, permissionName: PN, onGranted?: () => void, onError?: typeof reportError): UsePermissionReturn;
8
+ export interface UseClipboardReturn {
9
+ /**
10
+ * polyfill native api (stable)
11
+ */
12
+ /**
13
+ * Fallback on 'read' mode
14
+ */
15
+ read: () => Promise<ClipboardItems | undefined>;
16
+ /**
17
+ * Fallback on 'readText' mode
18
+ */
19
+ readText: () => Promise<string | undefined>;
20
+ /**
21
+ * Fallback on 'write' mode with blobs (get blob for each first type for each item) state
22
+ */
23
+ write: (data: ClipboardItems) => Promise<void>;
24
+ /**
25
+ * Fallback on 'writeText' mode with text state
26
+ */
27
+ writeText: (data: string) => Promise<void>;
28
+ /**
29
+ * custom helper (stable)
30
+ */
31
+ /**
32
+ * use write but no need do to manually ClipboardItems transform
33
+ * Fallback on 'writeText' mode with text state
34
+ * @param data
35
+ * @param type a mime type default to 'text/plain'
36
+ */
37
+ rawWriteWithType: (data: string, type?: 'text/html' | 'text/plain' | string) => Promise<void>;
38
+ /**
39
+ * state for alternative
40
+ */
41
+ /**
42
+ * state to know if you need to display an alternative interface
43
+ */
44
+ shouldFallback: ClipboardMode | undefined;
45
+ /**
46
+ * state for 'writeText' / 'rawWriteWithType' mode fallback
47
+ */
48
+ text: string | undefined;
49
+ /**
50
+ * state for 'write' mode fallback
51
+ */
52
+ blobs: Blob[] | undefined;
53
+ /**
54
+ * method to clean up state for alternative interface (set shouldFallback to undefined, text to undefined and blobs to undefined)
55
+ * stable
56
+ */
57
+ cleanShouldFallback: () => void;
58
+ }
59
+ /**
60
+ * Give you a wrapped clipboard api and a shouldFallback state.
61
+ * ignore if read and readText return promise filled with undefined, and rely on shouldFallback to display an alternative interaction.
62
+ * You should use ClipboardFallback component
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * const { readText, shouldFallback, setShouldFallback } = useClipboard();
67
+ *
68
+ * function handlePasteAction() {
69
+ * // yes you can safely ignore error here,
70
+ * // readText() will never throw, error is caught and set shouldFallback to corresponding mode
71
+ * void readText().then(handlePaste);
72
+ * }
73
+ *
74
+ * function handlePaste(text: string | undefined) {
75
+ * if (!text) return;
76
+ *
77
+ * setState(text);
78
+ * setShouldFallback(null);
79
+ * }
80
+ *
81
+ * return (
82
+ * <>
83
+ * <button onClick={handlePasteAction}>Paste</button>
84
+ * <ClipboardFallbackModal
85
+ * mode={shouldFallback}
86
+ * onDismiss={() => setShouldFallback(null)}
87
+ * onReadText={handlePaste}
88
+ * />
89
+ * </>
90
+ * )
91
+ * ```
92
+ */
93
+ export declare function useClipboard(): UseClipboardReturn;
94
+ export {};
@@ -0,0 +1,142 @@
1
+ import { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { newClipboardItem, read, readText, write, writeText, } from './clipboard';
3
+ export function useNavigatorPermission(now, permissionName, onGranted, onError = reportError) {
4
+ const [state, setState] = useState();
5
+ useEffect(() => {
6
+ if (!now)
7
+ return;
8
+ let canceled = false;
9
+ let status;
10
+ function onPermissionChange() {
11
+ if (canceled)
12
+ return;
13
+ setState(status.state);
14
+ if (status.state === 'granted') {
15
+ onGranted?.();
16
+ }
17
+ }
18
+ void navigator.permissions
19
+ .query({ name: permissionName })
20
+ .then((pStatus) => {
21
+ if (canceled)
22
+ return;
23
+ status = pStatus;
24
+ setState(status.state);
25
+ status.addEventListener('change', onPermissionChange);
26
+ })
27
+ .catch((error) => {
28
+ if (canceled)
29
+ return;
30
+ onError(error);
31
+ });
32
+ return () => {
33
+ canceled = true;
34
+ if (status) {
35
+ status.removeEventListener('change', onPermissionChange);
36
+ }
37
+ };
38
+ }, [now, permissionName, onGranted, onError]);
39
+ return { state, isGranted: state === 'granted' };
40
+ }
41
+ /**
42
+ * Give you a wrapped clipboard api and a shouldFallback state.
43
+ * ignore if read and readText return promise filled with undefined, and rely on shouldFallback to display an alternative interaction.
44
+ * You should use ClipboardFallback component
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * const { readText, shouldFallback, setShouldFallback } = useClipboard();
49
+ *
50
+ * function handlePasteAction() {
51
+ * // yes you can safely ignore error here,
52
+ * // readText() will never throw, error is caught and set shouldFallback to corresponding mode
53
+ * void readText().then(handlePaste);
54
+ * }
55
+ *
56
+ * function handlePaste(text: string | undefined) {
57
+ * if (!text) return;
58
+ *
59
+ * setState(text);
60
+ * setShouldFallback(null);
61
+ * }
62
+ *
63
+ * return (
64
+ * <>
65
+ * <button onClick={handlePasteAction}>Paste</button>
66
+ * <ClipboardFallbackModal
67
+ * mode={shouldFallback}
68
+ * onDismiss={() => setShouldFallback(null)}
69
+ * onReadText={handlePaste}
70
+ * />
71
+ * </>
72
+ * )
73
+ * ```
74
+ */
75
+ export function useClipboard() {
76
+ const [shouldFallback, setShouldFallback] = useState();
77
+ const [text, setText] = useState();
78
+ const [blobs, setBlobs] = useState();
79
+ const cleanShouldFallback = useCallback(() => {
80
+ setShouldFallback(undefined);
81
+ setText(undefined);
82
+ setBlobs(undefined);
83
+ }, []);
84
+ const clipboardAPI = useMemo(() => ({
85
+ async read() {
86
+ try {
87
+ return await read();
88
+ }
89
+ catch {
90
+ setShouldFallback('read');
91
+ }
92
+ },
93
+ async readText() {
94
+ try {
95
+ return await readText();
96
+ }
97
+ catch {
98
+ setShouldFallback('readText');
99
+ }
100
+ },
101
+ async write(data) {
102
+ try {
103
+ return await write(data);
104
+ }
105
+ catch {
106
+ const blobs = await Promise.all(data.map((ci) => ci.getType(ci.types[0])));
107
+ setBlobs(blobs);
108
+ setShouldFallback('write');
109
+ }
110
+ },
111
+ async rawWriteWithType(data, type = 'text/plain') {
112
+ try {
113
+ const item = await newClipboardItem({
114
+ [type]: new Promise((resolve) => {
115
+ resolve(new Blob([data], { type }));
116
+ }),
117
+ });
118
+ return await write([item]);
119
+ }
120
+ catch {
121
+ setText(data);
122
+ setShouldFallback('writeText');
123
+ }
124
+ },
125
+ async writeText(data) {
126
+ try {
127
+ return await writeText(data);
128
+ }
129
+ catch {
130
+ setText(data);
131
+ setShouldFallback('writeText');
132
+ }
133
+ },
134
+ }), []);
135
+ return {
136
+ ...clipboardAPI,
137
+ shouldFallback,
138
+ text,
139
+ blobs,
140
+ cleanShouldFallback,
141
+ };
142
+ }
@@ -0,0 +1 @@
1
+ export type ClipboardMode = 'read' | 'readText' | 'write' | 'writeText';
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export default { version: 'v0.38.2' };
1
+ export default { version: 'v0.40.1' };
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const nmr_load_save_1 = require("nmr-load-save");
7
8
  const react_1 = require("react");
8
9
  const ChartContext_1 = require("../../context/ChartContext");
9
10
  const usePanelPreferences_1 = require("../../hooks/usePanelPreferences");
10
11
  const AnalysisRange_1 = __importDefault(require("./AnalysisRange"));
11
- const nmr_load_save_1 = require("nmr-load-save");
12
12
  function MultiAnalysisRangesInner({ columns, displayerKey, activeTab, }) {
13
13
  const ranges = Object.keys(columns).filter((key) => columns[key].type !== nmr_load_save_1.AnalysisColumnsTypes.FORMULA);
14
14
  if (!ranges || ranges.length === 0) {