react-cheminfo 0.131.0 → 0.133.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/README.md +29 -0
- package/lib/core.d.ts +1 -0
- package/lib/core.d.ts.map +1 -1
- package/lib/core.js +1 -0
- package/lib/core.js.map +1 -1
- package/lib/drawing/captionEditor/CaptionEditor.d.ts +3 -3
- package/lib/drawing/captionEditor/CaptionEditor.d.ts.map +1 -1
- package/lib/drawing/captionEditor/CaptionEditor.js +8 -4
- package/lib/drawing/captionEditor/CaptionEditor.js.map +1 -1
- package/lib/drawing/captionEditor/CaptionToolbar.d.ts +4 -2
- package/lib/drawing/captionEditor/CaptionToolbar.d.ts.map +1 -1
- package/lib/drawing/captionEditor/CaptionToolbar.js +6 -4
- package/lib/drawing/captionEditor/CaptionToolbar.js.map +1 -1
- package/lib/drawing/captionEditor/index.d.ts +2 -0
- package/lib/drawing/captionEditor/index.d.ts.map +1 -1
- package/lib/drawing/captionEditor/index.js +1 -0
- package/lib/drawing/captionEditor/index.js.map +1 -1
- package/lib/drawing/captionEditor/toolbarInView.d.ts +40 -0
- package/lib/drawing/captionEditor/toolbarInView.d.ts.map +1 -0
- package/lib/drawing/captionEditor/toolbarInView.js +53 -0
- package/lib/drawing/captionEditor/toolbarInView.js.map +1 -0
- package/lib/drawing/core/camera.d.ts +2 -0
- package/lib/drawing/core/camera.d.ts.map +1 -1
- package/lib/drawing/core/camera.js +2 -0
- package/lib/drawing/core/camera.js.map +1 -1
- package/lib/drawing/core/index.d.ts +1 -1
- package/lib/drawing/core/index.d.ts.map +1 -1
- package/lib/drawing/core/index.js +1 -1
- package/lib/drawing/core/index.js.map +1 -1
- package/lib/drawing/render/index.d.ts +1 -1
- package/lib/drawing/render/index.d.ts.map +1 -1
- package/lib/drawing/render/index.js +1 -1
- package/lib/drawing/render/index.js.map +1 -1
- package/lib/drawing/render/pageGrid.d.ts +16 -0
- package/lib/drawing/render/pageGrid.d.ts.map +1 -1
- package/lib/drawing/render/pageGrid.js +28 -10
- package/lib/drawing/render/pageGrid.js.map +1 -1
- package/lib/drawing/ui/PageField.d.ts +29 -0
- package/lib/drawing/ui/PageField.d.ts.map +1 -0
- package/lib/drawing/ui/PageField.js +38 -0
- package/lib/drawing/ui/PageField.js.map +1 -0
- package/lib/drawing/ui/PageGrid.d.ts +20 -0
- package/lib/drawing/ui/PageGrid.d.ts.map +1 -0
- package/lib/drawing/ui/PageGrid.js +26 -0
- package/lib/drawing/ui/PageGrid.js.map +1 -0
- package/lib/drawing/ui/PageSideInput.d.ts +28 -0
- package/lib/drawing/ui/PageSideInput.d.ts.map +1 -0
- package/lib/drawing/ui/PageSideInput.js +47 -0
- package/lib/drawing/ui/PageSideInput.js.map +1 -0
- package/lib/drawing/ui/PageToolbar.d.ts +16 -0
- package/lib/drawing/ui/PageToolbar.d.ts.map +1 -0
- package/lib/drawing/ui/PageToolbar.js +16 -0
- package/lib/drawing/ui/PageToolbar.js.map +1 -0
- package/lib/drawing/ui/PrintSheets.d.ts +32 -0
- package/lib/drawing/ui/PrintSheets.d.ts.map +1 -0
- package/lib/drawing/ui/PrintSheets.js +17 -0
- package/lib/drawing/ui/PrintSheets.js.map +1 -0
- package/lib/drawing/ui/TextToolIcon.d.ts +19 -0
- package/lib/drawing/ui/TextToolIcon.d.ts.map +1 -0
- package/lib/drawing/ui/TextToolIcon.js +21 -0
- package/lib/drawing/ui/TextToolIcon.js.map +1 -0
- package/lib/drawing/ui/ZoomControl.d.ts +25 -0
- package/lib/drawing/ui/ZoomControl.d.ts.map +1 -0
- package/lib/drawing/ui/ZoomControl.js +27 -0
- package/lib/drawing/ui/ZoomControl.js.map +1 -0
- package/lib/drawing/ui/index.d.ts +10 -0
- package/lib/drawing/ui/index.d.ts.map +1 -1
- package/lib/drawing/ui/index.js +7 -0
- package/lib/drawing/ui/index.js.map +1 -1
- package/lib/guide/ui/EmptyGuide.d.ts +5 -2
- package/lib/guide/ui/EmptyGuide.d.ts.map +1 -1
- package/lib/guide/ui/EmptyGuide.js +8 -3
- package/lib/guide/ui/EmptyGuide.js.map +1 -1
- package/lib/guide/ui/GuideFigures.d.ts +6 -0
- package/lib/guide/ui/GuideFigures.d.ts.map +1 -1
- package/lib/guide/ui/GuideFigures.js +5 -5
- package/lib/guide/ui/GuideFigures.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +4 -0
- package/lib/locales/en.json +4 -0
- package/lib/locales/es.json +4 -0
- package/lib/locales/fr.json +4 -0
- package/lib/locales/it.json +4 -0
- package/lib/log/core/index.d.ts +4 -0
- package/lib/log/core/index.d.ts.map +1 -0
- package/lib/log/core/index.js +3 -0
- package/lib/log/core/index.js.map +1 -0
- package/lib/log/core/logGroups.d.ts +87 -0
- package/lib/log/core/logGroups.d.ts.map +1 -0
- package/lib/log/core/logGroups.js +85 -0
- package/lib/log/core/logGroups.js.map +1 -0
- package/lib/log/core/logLines.d.ts +19 -0
- package/lib/log/core/logLines.d.ts.map +1 -0
- package/lib/log/core/logLines.js +36 -0
- package/lib/log/core/logLines.js.map +1 -0
- package/lib/log/ui/LogBadge.d.ts +39 -0
- package/lib/log/ui/LogBadge.d.ts.map +1 -0
- package/lib/log/ui/LogBadge.js +28 -0
- package/lib/log/ui/LogBadge.js.map +1 -0
- package/lib/log/ui/LogCallouts.d.ts +55 -0
- package/lib/log/ui/LogCallouts.d.ts.map +1 -0
- package/lib/log/ui/LogCallouts.js +38 -0
- package/lib/log/ui/LogCallouts.js.map +1 -0
- package/lib/log/ui/index.d.ts +7 -0
- package/lib/log/ui/index.d.ts.map +1 -0
- package/lib/log/ui/index.js +5 -0
- package/lib/log/ui/index.js.map +1 -0
- package/lib/log/ui/logIcon.d.ts +9 -0
- package/lib/log/ui/logIcon.d.ts.map +1 -0
- package/lib/log/ui/logIcon.js +17 -0
- package/lib/log/ui/logIcon.js.map +1 -0
- package/lib/log/ui/useLogEntries.d.ts +15 -0
- package/lib/log/ui/useLogEntries.d.ts.map +1 -0
- package/lib/log/ui/useLogEntries.js +47 -0
- package/lib/log/ui/useLogEntries.js.map +1 -0
- package/lib/mass/core/index.d.ts +1 -0
- package/lib/mass/core/index.d.ts.map +1 -1
- package/lib/mass/core/index.js +1 -0
- package/lib/mass/core/index.js.map +1 -1
- package/lib/mass/core/massDomain.d.ts.map +1 -1
- package/lib/mass/core/massDomain.js +9 -5
- package/lib/mass/core/massDomain.js.map +1 -1
- package/lib/mass/core/massSpectrum.d.ts +9 -0
- package/lib/mass/core/massSpectrum.d.ts.map +1 -1
- package/lib/mass/core/massSpectrum.js.map +1 -1
- package/lib/mass/core/verticalScale.d.ts +30 -0
- package/lib/mass/core/verticalScale.d.ts.map +1 -0
- package/lib/mass/core/verticalScale.js +40 -0
- package/lib/mass/core/verticalScale.js.map +1 -0
- package/lib/mass/ui/MassChart.d.ts.map +1 -1
- package/lib/mass/ui/MassChart.js +4 -38
- package/lib/mass/ui/MassChart.js.map +1 -1
- package/lib/mass/ui/massChartLayers.d.ts +31 -0
- package/lib/mass/ui/massChartLayers.d.ts.map +1 -0
- package/lib/mass/ui/massChartLayers.js +57 -0
- package/lib/mass/ui/massChartLayers.js.map +1 -0
- package/lib/structure/core/conformerMinimise.d.ts +13 -4
- package/lib/structure/core/conformerMinimise.d.ts.map +1 -1
- package/lib/structure/core/conformerMinimise.js +23 -6
- package/lib/structure/core/conformerMinimise.js.map +1 -1
- package/lib/structure/core/conformerRefine.d.ts +2 -2
- package/lib/structure/core/conformerRefine.d.ts.map +1 -1
- package/lib/structure/core/conformerRefine.js +23 -7
- package/lib/structure/core/conformerRefine.js.map +1 -1
- package/lib/structure/core/conformers.d.ts +8 -3
- package/lib/structure/core/conformers.d.ts.map +1 -1
- package/lib/structure/core/conformers.js +10 -7
- package/lib/structure/core/conformers.js.map +1 -1
- package/lib/structure/core/geometryRelaxer.d.ts +10 -3
- package/lib/structure/core/geometryRelaxer.d.ts.map +1 -1
- package/lib/structure/core/index.d.ts +1 -1
- package/lib/structure/core/index.d.ts.map +1 -1
- package/lib/structure/core/index.js.map +1 -1
- package/lib/structure/core/relaxerLogLines.d.ts +16 -0
- package/lib/structure/core/relaxerLogLines.d.ts.map +1 -0
- package/lib/structure/core/relaxerLogLines.js +33 -0
- package/lib/structure/core/relaxerLogLines.js.map +1 -0
- package/lib/structure/core/structurePicture.d.ts +32 -1
- package/lib/structure/core/structurePicture.d.ts.map +1 -1
- package/lib/structure/core/structurePicture.js +29 -2
- package/lib/structure/core/structurePicture.js.map +1 -1
- package/lib/structure/ui/StructureEditor.d.ts +2 -1
- package/lib/structure/ui/StructureEditor.d.ts.map +1 -1
- package/lib/structure/ui/StructureEditor.js +9 -3
- package/lib/structure/ui/StructureEditor.js.map +1 -1
- package/lib/structure/ui/StructureEditorGuide.d.ts +15 -0
- package/lib/structure/ui/StructureEditorGuide.d.ts.map +1 -0
- package/lib/structure/ui/StructureEditorGuide.js +26 -0
- package/lib/structure/ui/StructureEditorGuide.js.map +1 -0
- package/lib/structure/ui/structureEditorProps.d.ts +11 -1
- package/lib/structure/ui/structureEditorProps.d.ts.map +1 -1
- package/lib/structure/ui/useCanvasPress.d.ts +23 -0
- package/lib/structure/ui/useCanvasPress.d.ts.map +1 -0
- package/lib/structure/ui/useCanvasPress.js +53 -0
- package/lib/structure/ui/useCanvasPress.js.map +1 -0
- package/lib/ui.d.ts +1 -0
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +1 -0
- package/lib/ui.js.map +1 -1
- package/lib/xps/core/detectFormat.d.ts +6 -0
- package/lib/xps/core/detectFormat.d.ts.map +1 -1
- package/lib/xps/core/detectFormat.js +8 -0
- package/lib/xps/core/detectFormat.js.map +1 -1
- package/lib/xps/core/xpsEditorApi.d.ts +16 -0
- package/lib/xps/core/xpsEditorApi.d.ts.map +1 -1
- package/lib/xps/ui/XpsCanvas.d.ts +10 -1
- package/lib/xps/ui/XpsCanvas.d.ts.map +1 -1
- package/lib/xps/ui/XpsCanvas.js +14 -3
- package/lib/xps/ui/XpsCanvas.js.map +1 -1
- package/lib/xps/ui/XpsChart.d.ts.map +1 -1
- package/lib/xps/ui/XpsChart.js +12 -43
- package/lib/xps/ui/XpsChart.js.map +1 -1
- package/lib/xps/ui/XpsEditor.d.ts +8 -0
- package/lib/xps/ui/XpsEditor.d.ts.map +1 -1
- package/lib/xps/ui/XpsEditor.js +2 -2
- package/lib/xps/ui/XpsEditor.js.map +1 -1
- package/lib/xps/ui/XpsShell.d.ts +5 -0
- package/lib/xps/ui/XpsShell.d.ts.map +1 -1
- package/lib/xps/ui/XpsShell.js +18 -4
- package/lib/xps/ui/XpsShell.js.map +1 -1
- package/lib/xps/ui/dropEvents.d.ts +8 -1
- package/lib/xps/ui/dropEvents.d.ts.map +1 -1
- package/lib/xps/ui/dropEvents.js +15 -1
- package/lib/xps/ui/dropEvents.js.map +1 -1
- package/lib/xps/ui/useSpectrumDrop.d.ts +6 -0
- package/lib/xps/ui/useSpectrumDrop.d.ts.map +1 -1
- package/lib/xps/ui/useSpectrumDrop.js +1 -1
- package/lib/xps/ui/useSpectrumDrop.js.map +1 -1
- package/lib/xps/ui/useXpsEditorHandle.d.ts +4 -1
- package/lib/xps/ui/useXpsEditorHandle.d.ts.map +1 -1
- package/lib/xps/ui/useXpsEditorHandle.js +6 -2
- package/lib/xps/ui/useXpsEditorHandle.js.map +1 -1
- package/lib/xps/ui/useXpsReadout.d.ts +43 -0
- package/lib/xps/ui/useXpsReadout.d.ts.map +1 -0
- package/lib/xps/ui/useXpsReadout.js +59 -0
- package/lib/xps/ui/useXpsReadout.js.map +1 -0
- package/lib/xps/ui/xpsChartProps.d.ts +9 -0
- package/lib/xps/ui/xpsChartProps.d.ts.map +1 -1
- package/lib/xtb/core/taggedLogger.d.ts +11 -0
- package/lib/xtb/core/taggedLogger.d.ts.map +1 -0
- package/lib/xtb/core/taggedLogger.js +31 -0
- package/lib/xtb/core/taggedLogger.js.map +1 -0
- package/lib/xtb/core/xtbRelaxer.d.ts.map +1 -1
- package/lib/xtb/core/xtbRelaxer.js +13 -5
- package/lib/xtb/core/xtbRelaxer.js.map +1 -1
- package/package.json +4 -3
- package/src/core.ts +1 -0
- package/src/drawing/captionEditor/CaptionEditor.tsx +8 -3
- package/src/drawing/captionEditor/CaptionToolbar.tsx +18 -2
- package/src/drawing/captionEditor/index.ts +2 -0
- package/src/drawing/captionEditor/toolbarInView.ts +73 -0
- package/src/drawing/core/camera.ts +3 -0
- package/src/drawing/core/index.ts +1 -0
- package/src/drawing/render/index.ts +2 -0
- package/src/drawing/render/pageGrid.ts +29 -11
- package/src/drawing/ui/PageField.tsx +104 -0
- package/src/drawing/ui/PageGrid.tsx +48 -0
- package/src/drawing/ui/PageSideInput.tsx +81 -0
- package/src/drawing/ui/PageToolbar.tsx +45 -0
- package/src/drawing/ui/PrintSheets.tsx +57 -0
- package/src/drawing/ui/TextToolIcon.tsx +48 -0
- package/src/drawing/ui/ZoomControl.tsx +112 -0
- package/src/drawing/ui/index.ts +10 -0
- package/src/guide/ui/EmptyGuide.tsx +20 -13
- package/src/guide/ui/GuideFigures.tsx +15 -4
- package/src/locales/de.json +4 -0
- package/src/locales/en.json +4 -0
- package/src/locales/es.json +4 -0
- package/src/locales/fr.json +4 -0
- package/src/locales/it.json +4 -0
- package/src/log/core/index.ts +9 -0
- package/src/log/core/logGroups.ts +159 -0
- package/src/log/core/logLines.ts +44 -0
- package/src/log/ui/LogBadge.tsx +89 -0
- package/src/log/ui/LogCallouts.tsx +103 -0
- package/src/log/ui/index.ts +6 -0
- package/src/log/ui/logIcon.ts +21 -0
- package/src/log/ui/useLogEntries.ts +57 -0
- package/src/mass/core/index.ts +1 -0
- package/src/mass/core/massDomain.ts +9 -3
- package/src/mass/core/massSpectrum.ts +9 -0
- package/src/mass/core/verticalScale.ts +48 -0
- package/src/mass/ui/MassChart.tsx +12 -43
- package/src/mass/ui/massChartLayers.ts +66 -0
- package/src/structure/core/conformerMinimise.ts +34 -8
- package/src/structure/core/conformerRefine.ts +29 -13
- package/src/structure/core/conformers.ts +23 -12
- package/src/structure/core/geometryRelaxer.ts +11 -3
- package/src/structure/core/index.ts +1 -0
- package/src/structure/core/relaxerLogLines.ts +39 -0
- package/src/structure/core/structurePicture.ts +78 -4
- package/src/structure/ui/StructureEditor.tsx +13 -2
- package/src/structure/ui/StructureEditorGuide.tsx +35 -0
- package/src/structure/ui/structureEditorProps.ts +11 -1
- package/src/structure/ui/useCanvasPress.ts +69 -0
- package/src/ui.ts +1 -0
- package/src/xps/core/detectFormat.ts +9 -0
- package/src/xps/core/xpsEditorApi.ts +16 -0
- package/src/xps/ui/XpsCanvas.tsx +26 -3
- package/src/xps/ui/XpsChart.tsx +12 -56
- package/src/xps/ui/XpsEditor.tsx +10 -0
- package/src/xps/ui/XpsShell.tsx +37 -7
- package/src/xps/ui/dropEvents.ts +16 -1
- package/src/xps/ui/useSpectrumDrop.ts +7 -1
- package/src/xps/ui/useXpsEditorHandle.ts +12 -2
- package/src/xps/ui/useXpsReadout.ts +104 -0
- package/src/xps/ui/xpsChartProps.ts +9 -0
- package/src/xtb/core/taggedLogger.ts +35 -0
- package/src/xtb/core/xtbRelaxer.ts +15 -5
- package/styles/caption-editor.css +15 -1
- package/styles/chrome.css +164 -9
- package/styles/drawing.css +100 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CSSProperties, ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { EDITOR_TOOLBAR_WIDTH } from '../core/editorToolbarGeometry.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The box a site's guide is drawn in over an empty canvas: beside the toolbar
|
|
7
|
+
* and under the buttons in the corner, so it never covers either.
|
|
8
|
+
*
|
|
9
|
+
* The box itself lets the pointer through; `<EmptyGuide>` takes it back only on
|
|
10
|
+
* its own buttons, links and figures, so a stroke can start on the words.
|
|
11
|
+
* @param props - What the guide shows.
|
|
12
|
+
* @param props.children - The site's guide.
|
|
13
|
+
* @returns The box and the guide in it.
|
|
14
|
+
*/
|
|
15
|
+
export function StructureEditorGuide(props: {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}): ReactElement {
|
|
18
|
+
return (
|
|
19
|
+
<div data-testid="structure-editor-guide" style={GUIDE_STYLE}>
|
|
20
|
+
{props.children}
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Under the open, export and help buttons in the corner: 4 px from the top, a
|
|
27
|
+
* small button 24 px tall, and 4 px under it.
|
|
28
|
+
*/
|
|
29
|
+
const CORNER_CLEARANCE = 32;
|
|
30
|
+
|
|
31
|
+
const GUIDE_STYLE: CSSProperties = {
|
|
32
|
+
position: 'absolute',
|
|
33
|
+
inset: `${CORNER_CLEARANCE}px 0 0 ${EDITOR_TOOLBAR_WIDTH}px`,
|
|
34
|
+
pointerEvents: 'none',
|
|
35
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CSSProperties } from 'react';
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
import type { CanvasEditorInputFormat } from 'react-ocl';
|
|
3
3
|
|
|
4
4
|
import type { StructureTransfer } from '../core/structureTransfer.ts';
|
|
@@ -74,6 +74,16 @@ export interface StructureEditorProps {
|
|
|
74
74
|
* @default true
|
|
75
75
|
*/
|
|
76
76
|
splash?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* What an empty canvas shows in place of the splash: the site's
|
|
79
|
+
* `<EmptyGuide>`, drawn beside the toolbar and under the buttons in the
|
|
80
|
+
* corner. The pointer goes through it to the canvas except on its own
|
|
81
|
+
* buttons, links and figures; it goes at the press that starts a stroke, and
|
|
82
|
+
* comes back whenever the canvas is empty again. Shown whatever `splash`
|
|
83
|
+
* says. A reaction canvas shows none.
|
|
84
|
+
* @default undefined — the splash, when `splash` is on
|
|
85
|
+
*/
|
|
86
|
+
guide?: ReactNode;
|
|
77
87
|
/**
|
|
78
88
|
* Put a button in the corner that opens every notation of the drawing — its
|
|
79
89
|
* SMILES, its molfiles, its canonical identifiers — and the picture of it,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The press that starts a stroke on the structure editor's canvas, which a
|
|
3
|
+
* site's guide makes way for.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { PointerEvent as ReactPointerEvent } from 'react';
|
|
7
|
+
import { useCallback, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { EDITOR_TOOLBAR_WIDTH } from '../core/editorToolbarGeometry.ts';
|
|
10
|
+
|
|
11
|
+
/** Whether a stroke is being drawn, and how to hear the press that starts one. */
|
|
12
|
+
export interface CanvasPress {
|
|
13
|
+
/** Whether the drawing area is held down, which the guide makes way for. */
|
|
14
|
+
pressed: boolean;
|
|
15
|
+
/** Put on the editor's box, in the capture phase. */
|
|
16
|
+
onPointerDownCapture: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hear a press on the drawing area, so the guide goes at the press that starts
|
|
21
|
+
* a stroke rather than once the stroke is reported.
|
|
22
|
+
*
|
|
23
|
+
* A press on the toolbar, on a corner button or on the guide's own buttons is
|
|
24
|
+
* not a stroke. The guide comes back after the release only when the editor
|
|
25
|
+
* has not reported a drawing by then.
|
|
26
|
+
* @returns See {@link CanvasPress}.
|
|
27
|
+
*/
|
|
28
|
+
export function useCanvasPress(): CanvasPress {
|
|
29
|
+
const [pressed, setPressed] = useState(false);
|
|
30
|
+
const onPointerDownCapture = useCallback(
|
|
31
|
+
(event: ReactPointerEvent<HTMLElement>) => {
|
|
32
|
+
if (!onDrawingArea(event)) return;
|
|
33
|
+
setPressed(true);
|
|
34
|
+
function release(): void {
|
|
35
|
+
globalThis.removeEventListener('pointerup', release, true);
|
|
36
|
+
globalThis.removeEventListener('pointercancel', release, true);
|
|
37
|
+
// Once the editor has handled the release too: a stroke that drew
|
|
38
|
+
// something is reported by then, and the guide does not flash back.
|
|
39
|
+
setTimeout(() => setPressed(false), 0);
|
|
40
|
+
}
|
|
41
|
+
// Heard on the way down, which no handler of the canvas can stop.
|
|
42
|
+
globalThis.addEventListener('pointerup', release, true);
|
|
43
|
+
globalThis.addEventListener('pointercancel', release, true);
|
|
44
|
+
},
|
|
45
|
+
[],
|
|
46
|
+
);
|
|
47
|
+
return { pressed, onPointerDownCapture };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether a press landed on the drawing area: on the editor's canvas, and to
|
|
52
|
+
* the right of its toolbar. Both live in the editor's shadow root, so the event
|
|
53
|
+
* names the element holding it.
|
|
54
|
+
* @param event - The press, heard on the editor's box.
|
|
55
|
+
* @returns Whether it starts a stroke.
|
|
56
|
+
*/
|
|
57
|
+
function onDrawingArea(event: ReactPointerEvent<HTMLElement>): boolean {
|
|
58
|
+
const { target, currentTarget, clientX } = event;
|
|
59
|
+
if (!(target instanceof Element) || target.closest(CANVAS) === null) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return clientX - currentTarget.getBoundingClientRect().left > TOOLBAR_EDGE;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The element the openchemlib editor is drawn in. */
|
|
66
|
+
const CANVAS = '[data-openchemlib-canvas-editor]';
|
|
67
|
+
|
|
68
|
+
/** The toolbar's right edge, inside the editor's one-pixel border. */
|
|
69
|
+
const TOOLBAR_EDGE = EDITOR_TOOLBAR_WIDTH + 1;
|
package/src/ui.ts
CHANGED
|
@@ -22,6 +22,7 @@ export * from './highlight/ui/index.ts';
|
|
|
22
22
|
export * from './hooks/ui/index.ts';
|
|
23
23
|
export * from './i18n/ui/index.ts';
|
|
24
24
|
export * from './language/ui/index.ts';
|
|
25
|
+
export * from './log/ui/index.ts';
|
|
25
26
|
export * from './moleculesSources/ui/index.ts';
|
|
26
27
|
export * from './moleculesToken/ui/index.ts';
|
|
27
28
|
export * from './number/ui/index.ts';
|
|
@@ -69,6 +69,15 @@ const EXTENSIONS = new Map<string, XpsFormat>([
|
|
|
69
69
|
['xy', 'text'],
|
|
70
70
|
]);
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The extensions the readers know, as a file picker's `accept`: what the
|
|
74
|
+
* picker offers first, while a file it does not name is still read by its
|
|
75
|
+
* content.
|
|
76
|
+
*/
|
|
77
|
+
export const XPS_FILE_ACCEPT = [...EXTENSIONS.keys()]
|
|
78
|
+
.map((extension) => `.${extension}`)
|
|
79
|
+
.join(',');
|
|
80
|
+
|
|
72
81
|
/** The one decoder the header is read through, kept rather than rebuilt. */
|
|
73
82
|
const DECODER = new TextDecoder();
|
|
74
83
|
|
|
@@ -59,6 +59,22 @@ export interface XpsEditorHandle {
|
|
|
59
59
|
setSpectra: (spectra: XpsSpectrum[]) => void;
|
|
60
60
|
/** Close every spectrum and start again from an empty chart. */
|
|
61
61
|
clear: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* Open the viewer's file picker; what is chosen is read as a drop is,
|
|
64
|
+
* joining what is open. A browser opens a picker only for a click, so call
|
|
65
|
+
* it from one — an "Import data…" button of a guide.
|
|
66
|
+
*/
|
|
67
|
+
openFiles: () => void;
|
|
68
|
+
/**
|
|
69
|
+
* Read the clipboard's text as a paste into the viewer is read, joining what
|
|
70
|
+
* is open; what cannot be read is said in the status bar, as for a paste.
|
|
71
|
+
* Call it from a click, which is when a browser lets a page read the
|
|
72
|
+
* clipboard.
|
|
73
|
+
* @returns Resolves once the text is handed to the reader, and rejects when
|
|
74
|
+
* the browser refuses to read the clipboard, so the caller can suggest the
|
|
75
|
+
* paste keys instead.
|
|
76
|
+
*/
|
|
77
|
+
paste: () => Promise<void>;
|
|
62
78
|
/**
|
|
63
79
|
* Frame a binding energy on the chart, keeping the counts axis where it was.
|
|
64
80
|
*
|
package/src/xps/ui/XpsCanvas.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
import { useCallback, useMemo } from 'react';
|
|
2
3
|
|
|
4
|
+
import { TOKEN } from '../../tokens/core/familyTokens.ts';
|
|
3
5
|
import { hasBindingAxis } from '../core/energyAxis.ts';
|
|
4
6
|
import { findSpectrum } from '../core/spectrumGroups.ts';
|
|
5
7
|
import { surveyLinesOf } from '../core/surveyElements.ts';
|
|
@@ -32,6 +34,13 @@ export interface XpsCanvasProps {
|
|
|
32
34
|
* @default false
|
|
33
35
|
*/
|
|
34
36
|
isReading?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* What the empty chart shows in place of its own invitation to drop a
|
|
39
|
+
* spectrum: the site's `<EmptyGuide>`, over the whole chart. Gone while a
|
|
40
|
+
* file is dragged over the chart or read, and once anything is open.
|
|
41
|
+
* @default undefined — the chart's own invitation
|
|
42
|
+
*/
|
|
43
|
+
guide?: ReactNode;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
/**
|
|
@@ -46,12 +55,13 @@ export interface XpsCanvasProps {
|
|
|
46
55
|
* The empty chart says what to do with it rather than showing an axis from 0 to
|
|
47
56
|
* 1 and leaving the question open: the two ways in are a file and a paste, and
|
|
48
57
|
* neither is discoverable from a blank plot. The invitation goes as soon as
|
|
49
|
-
* anything is open, since from then on the axes are the answer.
|
|
58
|
+
* anything is open, since from then on the axes are the answer. A site with a
|
|
59
|
+
* guide of its own passes it as `guide`, and it is drawn instead.
|
|
50
60
|
* @param props - Component props.
|
|
51
61
|
* @returns The canvas side of the split.
|
|
52
62
|
*/
|
|
53
63
|
export function XpsCanvas(props: XpsCanvasProps) {
|
|
54
|
-
const { isOver = false, isReading = false, chartId } = props;
|
|
64
|
+
const { isOver = false, isReading = false, chartId, guide } = props;
|
|
55
65
|
const { state } = useXpsEditorState();
|
|
56
66
|
const actions = useXpsActions();
|
|
57
67
|
const highlight = useXpsHighlight();
|
|
@@ -90,6 +100,7 @@ export function XpsCanvas(props: XpsCanvasProps) {
|
|
|
90
100
|
const { selectedId, openPanelIds, domain } = view;
|
|
91
101
|
const { instruments, instrumentId } = settings;
|
|
92
102
|
const quantifying = openPanelIds.includes('quantification');
|
|
103
|
+
const empty = spectra.length === 0 && !isReading;
|
|
93
104
|
const windows = useMemo(
|
|
94
105
|
() =>
|
|
95
106
|
quantifying
|
|
@@ -115,7 +126,10 @@ export function XpsCanvas(props: XpsCanvasProps) {
|
|
|
115
126
|
isOver={isOver}
|
|
116
127
|
isReading={isReading}
|
|
117
128
|
/>
|
|
118
|
-
{
|
|
129
|
+
{empty && guide !== undefined && !isOver ? (
|
|
130
|
+
<div style={guideStyle}>{guide}</div>
|
|
131
|
+
) : null}
|
|
132
|
+
{empty && guide === undefined ? (
|
|
119
133
|
<div style={inviteStyle}>
|
|
120
134
|
<div style={inviteTitleStyle}>Drop a spectrum here</div>
|
|
121
135
|
<div>
|
|
@@ -169,6 +183,15 @@ const inviteStyle = {
|
|
|
169
183
|
|
|
170
184
|
const inviteTitleStyle = { fontSize: 15, fontWeight: 600 } as const;
|
|
171
185
|
|
|
186
|
+
// Instead of the plot: faint figures over an empty frame of axes read as data
|
|
187
|
+
// drawn on it. The pointer goes through to the chart, which takes the drop.
|
|
188
|
+
const guideStyle = {
|
|
189
|
+
position: 'absolute',
|
|
190
|
+
inset: 0,
|
|
191
|
+
background: TOKEN.surface,
|
|
192
|
+
pointerEvents: 'none',
|
|
193
|
+
} as const;
|
|
194
|
+
|
|
172
195
|
/**
|
|
173
196
|
* The windows the selected survey is quantified over, for the chart to shade
|
|
174
197
|
* while the quantification panel is open.
|
package/src/xps/ui/XpsChart.tsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useId, useMemo, useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { MARGIN, plotRect } from '../../chart/core/chartGeometry.ts';
|
|
5
|
-
import { chartScale
|
|
6
|
-
import type { ChartPoint } from '../../chart/core/svgPoint.ts';
|
|
5
|
+
import { chartScale } from '../../chart/core/chartScale.ts';
|
|
7
6
|
import { Axes } from '../../chart/ui/Axes.tsx';
|
|
8
7
|
import { AxisGuide } from '../../chart/ui/AxisGuide.tsx';
|
|
9
8
|
import { SelectionRect } from '../../chart/ui/SelectionRect.tsx';
|
|
10
|
-
import { useChartPointer } from '../../chart/ui/useChartPointer.ts';
|
|
11
9
|
import { useChartSize } from '../../chart/ui/useChartSize.ts';
|
|
12
10
|
import {
|
|
13
11
|
axisEnergy,
|
|
@@ -17,17 +15,15 @@ import {
|
|
|
17
15
|
countsTitle,
|
|
18
16
|
isAxisReversed,
|
|
19
17
|
} from '../core/energyAxis.ts';
|
|
20
|
-
import type { NearestPeak } from '../core/nearestPeak.ts';
|
|
21
|
-
import { nearestPeakEnergy, sameNearestPeak } from '../core/nearestPeak.ts';
|
|
22
18
|
import { fullDomain } from '../core/xpsDomain.ts';
|
|
23
19
|
import { NO_HIGHLIGHT } from '../core/xpsHighlight.ts';
|
|
24
20
|
import type { XpsDomain } from '../core/xpsSpectrum.ts';
|
|
25
21
|
|
|
26
22
|
import { ChartData } from './ChartData.tsx';
|
|
27
23
|
import { DropOverlay } from './DropOverlay.tsx';
|
|
28
|
-
import type { XpsReadout } from './XpsPointerTracker.tsx';
|
|
29
24
|
import { XpsPointerTracker } from './XpsPointerTracker.tsx';
|
|
30
25
|
import { useXpsGestures } from './useXpsGestures.ts';
|
|
26
|
+
import { useXpsReadout } from './useXpsReadout.ts';
|
|
31
27
|
import type { XpsChartProps } from './xpsChartProps.ts';
|
|
32
28
|
|
|
33
29
|
/**
|
|
@@ -72,15 +68,14 @@ export function XpsChart(props: XpsChartProps): ReactNode {
|
|
|
72
68
|
windows,
|
|
73
69
|
isOver = false,
|
|
74
70
|
isReading = false,
|
|
71
|
+
size,
|
|
75
72
|
} = props;
|
|
76
73
|
|
|
77
74
|
const [containerRef, measured] = useChartSize<HTMLDivElement>();
|
|
78
75
|
const svgRef = useRef<SVGSVGElement | null>(null);
|
|
76
|
+
const { width, height } = size ?? measured;
|
|
79
77
|
|
|
80
|
-
const plot = useMemo(
|
|
81
|
-
() => plotRect({ width: measured.width, height: measured.height }),
|
|
82
|
-
[measured.width, measured.height],
|
|
83
|
-
);
|
|
78
|
+
const plot = useMemo(() => plotRect({ width, height }), [width, height]);
|
|
84
79
|
// Read back off the plot rather than off the measurement, so a chart briefly
|
|
85
80
|
// laid out at nothing still draws its axes inside a box that holds them.
|
|
86
81
|
const frameWidth = plot.right + MARGIN.right;
|
|
@@ -125,42 +120,14 @@ export function XpsChart(props: XpsChartProps): ReactNode {
|
|
|
125
120
|
onPickEnergy,
|
|
126
121
|
});
|
|
127
122
|
|
|
128
|
-
const
|
|
129
|
-
(point: ChartPoint): XpsReadout => ({
|
|
130
|
-
energy: chartValue(xScale, point.x),
|
|
131
|
-
counts: chartValue(yScale, point.y),
|
|
132
|
-
peak: nearestPeakEnergy(spectra, axis, xScale, point.x),
|
|
133
|
-
}),
|
|
134
|
-
[xScale, yScale, spectra, axis],
|
|
135
|
-
);
|
|
136
|
-
// Only a change of peak is reported, starting from none: the pointer coming
|
|
137
|
-
// onto the plot over no peak says nothing, so a guide a panel put on the
|
|
138
|
-
// chart stays until the pointer actually reaches a peak.
|
|
139
|
-
const reportedPeak = useRef<NearestPeak | null>(null);
|
|
140
|
-
const onReadout = useCallback(
|
|
141
|
-
(readout: XpsReadout | null) => {
|
|
142
|
-
const found = readout?.peak ?? null;
|
|
143
|
-
if (sameNearestPeak(reportedPeak.current, found)) return;
|
|
144
|
-
reportedPeak.current = found;
|
|
145
|
-
onHighlightChange?.(
|
|
146
|
-
found === null
|
|
147
|
-
? NO_HIGHLIGHT
|
|
148
|
-
: {
|
|
149
|
-
spectrumId: found.spectrumId,
|
|
150
|
-
peakId: found.peak.id,
|
|
151
|
-
componentId: null,
|
|
152
|
-
bindingEnergy: found.peak.bindingEnergy,
|
|
153
|
-
},
|
|
154
|
-
);
|
|
155
|
-
},
|
|
156
|
-
[onHighlightChange],
|
|
157
|
-
);
|
|
158
|
-
const pointer = useChartPointer<XpsReadout>({
|
|
123
|
+
const pointer = useXpsReadout({
|
|
159
124
|
svgRef,
|
|
160
125
|
plot,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
126
|
+
spectra,
|
|
127
|
+
axis,
|
|
128
|
+
xScale,
|
|
129
|
+
yScale,
|
|
130
|
+
onHighlightChange,
|
|
164
131
|
});
|
|
165
132
|
|
|
166
133
|
const guideEnergy =
|
|
@@ -235,17 +202,6 @@ export function XpsChart(props: XpsChartProps): ReactNode {
|
|
|
235
202
|
);
|
|
236
203
|
}
|
|
237
204
|
|
|
238
|
-
/**
|
|
239
|
-
* Whether two readings are about the same peak, which is all the rest of the
|
|
240
|
-
* viewer hears about: the energy under the crosshair changes on every pixel.
|
|
241
|
-
* @param current - The reading last reported.
|
|
242
|
-
* @param next - The reading now.
|
|
243
|
-
* @returns Whether nothing needs reporting.
|
|
244
|
-
*/
|
|
245
|
-
function samePeakReadout(current: XpsReadout, next: XpsReadout): boolean {
|
|
246
|
-
return sameNearestPeak(current.peak, next.peak);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
205
|
/**
|
|
250
206
|
* The room an energy label wants along the bottom, at its widest: `1200` or
|
|
251
207
|
* `284.8` with the space either side of it.
|
package/src/xps/ui/XpsEditor.tsx
CHANGED
|
@@ -81,6 +81,14 @@ export interface XpsEditorProps {
|
|
|
81
81
|
* @default undefined
|
|
82
82
|
*/
|
|
83
83
|
actions?: ReactNode;
|
|
84
|
+
/**
|
|
85
|
+
* What the empty chart shows in place of its own invitation to drop a
|
|
86
|
+
* spectrum: the site's `<EmptyGuide>`, whose "Import data…" and "Paste"
|
|
87
|
+
* buttons call the handle's `openFiles` and `paste`. Gone while a file is
|
|
88
|
+
* dragged over the chart or read, and once anything is open.
|
|
89
|
+
* @default undefined — the chart's own invitation
|
|
90
|
+
*/
|
|
91
|
+
guide?: ReactNode;
|
|
84
92
|
/**
|
|
85
93
|
* The handle a host drives the viewer through: take these spectra, frame this
|
|
86
94
|
* energy, tell me what is open.
|
|
@@ -123,6 +131,7 @@ export function XpsEditor(props: XpsEditorProps) {
|
|
|
123
131
|
defaultPanelIds,
|
|
124
132
|
panels = NO_PANELS,
|
|
125
133
|
actions,
|
|
134
|
+
guide,
|
|
126
135
|
ref,
|
|
127
136
|
storageKey,
|
|
128
137
|
} = props;
|
|
@@ -162,6 +171,7 @@ export function XpsEditor(props: XpsEditorProps) {
|
|
|
162
171
|
handle={ref}
|
|
163
172
|
panels={panels}
|
|
164
173
|
actions={actions}
|
|
174
|
+
guide={guide}
|
|
165
175
|
/>
|
|
166
176
|
</RootLayout>
|
|
167
177
|
</XpsHighlightProvider>
|
package/src/xps/ui/XpsShell.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { ReactNode, Ref } from 'react';
|
|
2
|
-
import { useCallback, useId, useMemo, useState } from 'react';
|
|
1
|
+
import type { ChangeEvent, ReactNode, Ref } from 'react';
|
|
2
|
+
import { useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { sanitizeFileName } from '../../download/core/sanitizeFileName.ts';
|
|
5
5
|
import { useFigureDownload } from '../../download/ui/useFigureDownload.tsx';
|
|
6
6
|
import { FixedPanelRow } from '../../panel/ui/FixedPanelRow.tsx';
|
|
7
7
|
import { PanelRail } from '../../panel/ui/PanelRail.tsx';
|
|
8
|
+
import { XPS_FILE_ACCEPT } from '../core/detectFormat.ts';
|
|
8
9
|
import type { XpsEditorHandle } from '../core/xpsEditorApi.ts';
|
|
9
10
|
import type { XpsSpectrum } from '../core/xpsSpectrum.ts';
|
|
10
11
|
|
|
@@ -16,6 +17,7 @@ import { XpsHeader } from './XpsHeader.tsx';
|
|
|
16
17
|
import { XpsSettingsDialog } from './XpsSettingsDialog.tsx';
|
|
17
18
|
import { XpsSidePanel } from './XpsSidePanel.tsx';
|
|
18
19
|
import { XpsToolbar } from './XpsToolbar.tsx';
|
|
20
|
+
import { readClipboardText } from './dropEvents.ts';
|
|
19
21
|
import { useSpectrumDrop } from './useSpectrumDrop.ts';
|
|
20
22
|
import { useXpsCommandHandlers } from './useXpsCommandHandlers.ts';
|
|
21
23
|
import { useXpsEditorHandle } from './useXpsEditorHandle.ts';
|
|
@@ -40,6 +42,11 @@ export interface XpsShellProps {
|
|
|
40
42
|
* @default undefined
|
|
41
43
|
*/
|
|
42
44
|
actions?: ReactNode;
|
|
45
|
+
/**
|
|
46
|
+
* What the empty chart shows in place of its own invitation.
|
|
47
|
+
* @default undefined — the chart's own invitation
|
|
48
|
+
*/
|
|
49
|
+
guide?: ReactNode;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
@@ -53,15 +60,13 @@ export interface XpsShellProps {
|
|
|
53
60
|
* @returns The screen.
|
|
54
61
|
*/
|
|
55
62
|
export function XpsShell(props: XpsShellProps) {
|
|
56
|
-
const { pasteFromPage, handle, panels, actions: hostActions } = props;
|
|
63
|
+
const { pasteFromPage, handle, panels, actions: hostActions, guide } = props;
|
|
57
64
|
|
|
58
65
|
const { state } = useXpsEditorState();
|
|
59
66
|
const actions = useXpsActions();
|
|
60
67
|
const { spectra } = state.data;
|
|
61
68
|
const side = useXpsSide(panels);
|
|
62
69
|
|
|
63
|
-
useXpsEditorHandle(handle);
|
|
64
|
-
|
|
65
70
|
const [isAboutOpen, setIsAboutOpen] = useState(false);
|
|
66
71
|
const [isDocumentationOpen, setIsDocumentationOpen] = useState(false);
|
|
67
72
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
|
@@ -77,6 +82,15 @@ export function XpsShell(props: XpsShellProps) {
|
|
|
77
82
|
pasteFromPage,
|
|
78
83
|
});
|
|
79
84
|
|
|
85
|
+
// The ways in a guide's buttons reuse: the drop's own reader behind both.
|
|
86
|
+
const fileInput = useRef<HTMLInputElement>(null);
|
|
87
|
+
const openFiles = useCallback(() => fileInput.current?.click(), []);
|
|
88
|
+
const { read, readText, isOver, isReading } = drop;
|
|
89
|
+
const paste = useCallback(async () => {
|
|
90
|
+
readText(await readClipboardText());
|
|
91
|
+
}, [readText]);
|
|
92
|
+
useXpsEditorHandle(handle, { openFiles, paste });
|
|
93
|
+
|
|
80
94
|
// The root is held as state rather than in a ref because the keys are bound
|
|
81
95
|
// to it from an effect: a ref filled in during the commit would leave the
|
|
82
96
|
// effect with nothing to listen on for the first render, and no reason ever
|
|
@@ -130,8 +144,9 @@ export function XpsShell(props: XpsShellProps) {
|
|
|
130
144
|
view={
|
|
131
145
|
<XpsCanvas
|
|
132
146
|
chartId={chartId}
|
|
133
|
-
isOver={
|
|
134
|
-
isReading={
|
|
147
|
+
isOver={isOver}
|
|
148
|
+
isReading={isReading}
|
|
149
|
+
guide={guide}
|
|
135
150
|
/>
|
|
136
151
|
}
|
|
137
152
|
panels={<XpsSidePanel panels={panels} side={side} />}
|
|
@@ -147,6 +162,21 @@ export function XpsShell(props: XpsShellProps) {
|
|
|
147
162
|
/>
|
|
148
163
|
</div>
|
|
149
164
|
</div>
|
|
165
|
+
|
|
166
|
+
<input
|
|
167
|
+
ref={fileInput}
|
|
168
|
+
type="file"
|
|
169
|
+
multiple
|
|
170
|
+
hidden
|
|
171
|
+
accept={XPS_FILE_ACCEPT}
|
|
172
|
+
data-testid="xps-editor-file"
|
|
173
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
174
|
+
const chosen = [...(event.currentTarget.files ?? [])];
|
|
175
|
+
// Emptied so that choosing the same file again is still a change.
|
|
176
|
+
event.currentTarget.value = '';
|
|
177
|
+
read(chosen);
|
|
178
|
+
}}
|
|
179
|
+
/>
|
|
150
180
|
</div>
|
|
151
181
|
|
|
152
182
|
<XpsAboutDialog
|
package/src/xps/ui/dropEvents.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What a drag and a paste actually carry, and whether the viewer should take
|
|
2
|
+
* What a drag and a paste actually carry, and whether the viewer should take
|
|
3
|
+
* it — and, for a Paste button, what the clipboard holds.
|
|
3
4
|
*
|
|
4
5
|
* Kept apart from the hook because these are the decisions rather than the
|
|
5
6
|
* plumbing: a paste into the tolerance box is being typed, a drag of selected
|
|
@@ -50,3 +51,17 @@ export function takePaste(
|
|
|
50
51
|
event.preventDefault();
|
|
51
52
|
readText(text);
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The clipboard's text, for a Paste button: what a paste with the keys would
|
|
57
|
+
* have carried, read without one.
|
|
58
|
+
* @returns The text.
|
|
59
|
+
*/
|
|
60
|
+
export async function readClipboardText(): Promise<string> {
|
|
61
|
+
const clipboard = (globalThis.navigator as Partial<Navigator> | undefined)
|
|
62
|
+
?.clipboard;
|
|
63
|
+
if (clipboard === undefined) {
|
|
64
|
+
throw new Error('This browser lets no page read the clipboard.');
|
|
65
|
+
}
|
|
66
|
+
return clipboard.readText();
|
|
67
|
+
}
|
|
@@ -83,6 +83,12 @@ export interface SpectrumDrop {
|
|
|
83
83
|
* @param files - The files to read.
|
|
84
84
|
*/
|
|
85
85
|
read: (files: FileList | readonly File[]) => void;
|
|
86
|
+
/**
|
|
87
|
+
* Read text as a paste is read — two columns of numbers, a VAMAS or a JCAMP
|
|
88
|
+
* file as text. Stable for the life of the viewer.
|
|
89
|
+
* @param text - The text.
|
|
90
|
+
*/
|
|
91
|
+
readText: (text: string) => void;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
/** The `ref` to put on the viewer's root, and what that root is doing. */
|
|
@@ -238,5 +244,5 @@ export function useSpectrumDrop(
|
|
|
238
244
|
};
|
|
239
245
|
}, [pasteFromPage, read, readText]);
|
|
240
246
|
|
|
241
|
-
return [attach, { isOver, isReading, read }];
|
|
247
|
+
return [attach, { isOver, isReading, read, readText }];
|
|
242
248
|
}
|
|
@@ -23,11 +23,19 @@ import { ENERGY_WINDOW } from '../core/xpsEditorApi.ts';
|
|
|
23
23
|
|
|
24
24
|
import { useXpsActions, useXpsEditorState } from './xpsStateContext.ts';
|
|
25
25
|
|
|
26
|
+
/** The ways in the viewer's screen owns: its file picker and its paste. */
|
|
27
|
+
export type XpsEntryPoints = Pick<XpsEditorHandle, 'openFiles' | 'paste'>;
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* Fill in the handle a host drives the viewer through.
|
|
28
31
|
* @param handle - Where to put it, `undefined` when the host asked for none.
|
|
32
|
+
* @param entry - The file picker and the paste, stable for the viewer's life.
|
|
29
33
|
*/
|
|
30
|
-
export function useXpsEditorHandle(
|
|
34
|
+
export function useXpsEditorHandle(
|
|
35
|
+
handle: Ref<XpsEditorHandle> | undefined,
|
|
36
|
+
entry: XpsEntryPoints,
|
|
37
|
+
) {
|
|
38
|
+
const { openFiles, paste } = entry;
|
|
31
39
|
const { state } = useXpsEditorState();
|
|
32
40
|
const actions = useXpsActions();
|
|
33
41
|
|
|
@@ -48,6 +56,8 @@ export function useXpsEditorHandle(handle: Ref<XpsEditorHandle> | undefined) {
|
|
|
48
56
|
actions.addSpectra(spectra);
|
|
49
57
|
},
|
|
50
58
|
clear: actions.clear,
|
|
59
|
+
openFiles,
|
|
60
|
+
paste,
|
|
51
61
|
zoomToEnergy(bindingEnergy, options) {
|
|
52
62
|
const current = live.current;
|
|
53
63
|
const half = options?.halfWidth ?? ENERGY_WINDOW;
|
|
@@ -70,6 +80,6 @@ export function useXpsEditorHandle(handle: Ref<XpsEditorHandle> | undefined) {
|
|
|
70
80
|
},
|
|
71
81
|
getState: () => live.current,
|
|
72
82
|
}),
|
|
73
|
-
[actions],
|
|
83
|
+
[actions, openFiles, paste],
|
|
74
84
|
);
|
|
75
85
|
}
|