react-cheminfo 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/about/core/about.d.ts +9 -0
- package/lib/about/core/about.d.ts.map +1 -1
- package/lib/about/core/about.js +1 -0
- package/lib/about/core/about.js.map +1 -1
- package/lib/about/core/index.d.ts +1 -0
- package/lib/about/core/index.d.ts.map +1 -1
- package/lib/about/core/index.js +1 -0
- package/lib/about/core/index.js.map +1 -1
- package/lib/about/core/repository.d.ts +14 -0
- package/lib/about/core/repository.d.ts.map +1 -0
- package/lib/about/core/repository.js +21 -0
- package/lib/about/core/repository.js.map +1 -0
- package/lib/about/ui/AboutBuild.d.ts +5 -4
- package/lib/about/ui/AboutBuild.d.ts.map +1 -1
- package/lib/about/ui/AboutBuild.js +10 -10
- package/lib/about/ui/AboutBuild.js.map +1 -1
- package/lib/about/ui/AboutPage.d.ts.map +1 -1
- package/lib/about/ui/AboutPage.js +7 -8
- package/lib/about/ui/AboutPage.js.map +1 -1
- package/lib/about/ui/AboutVersion.d.ts +25 -0
- package/lib/about/ui/AboutVersion.d.ts.map +1 -0
- package/lib/about/ui/AboutVersion.js +31 -0
- package/lib/about/ui/AboutVersion.js.map +1 -0
- package/lib/about/ui/index.d.ts +2 -0
- package/lib/about/ui/index.d.ts.map +1 -1
- package/lib/about/ui/index.js +1 -0
- package/lib/about/ui/index.js.map +1 -1
- package/lib/build/core/buildInfo.d.ts +16 -0
- package/lib/build/core/buildInfo.d.ts.map +1 -1
- package/lib/build/core/buildInfo.js +21 -0
- package/lib/build/core/buildInfo.js.map +1 -1
- package/lib/build/core/index.d.ts +1 -1
- package/lib/build/core/index.d.ts.map +1 -1
- package/lib/build/core/index.js +1 -1
- package/lib/build/core/index.js.map +1 -1
- package/lib/build/vite/buildInfo.d.ts.map +1 -1
- package/lib/build/vite/buildInfo.js +2 -2
- package/lib/build/vite/buildInfo.js.map +1 -1
- package/lib/ecosystem/core/sites.d.ts.map +1 -1
- package/lib/ecosystem/core/sites.js +12 -0
- package/lib/ecosystem/core/sites.js.map +1 -1
- package/lib/ecosystem/core/types.d.ts +8 -0
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/molecule3d/core/camera.d.ts +89 -0
- package/lib/molecule3d/core/camera.d.ts.map +1 -0
- package/lib/molecule3d/core/camera.js +172 -0
- package/lib/molecule3d/core/camera.js.map +1 -0
- package/lib/molecule3d/core/index.d.ts +2 -0
- package/lib/molecule3d/core/index.d.ts.map +1 -1
- package/lib/molecule3d/core/index.js +1 -0
- package/lib/molecule3d/core/index.js.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
- package/lib/molecule3d/ui/MoleculeCanvas3D.js +14 -37
- package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
- package/lib/molecule3d/ui/camera.d.ts +35 -2
- package/lib/molecule3d/ui/camera.d.ts.map +1 -1
- package/lib/molecule3d/ui/camera.js +113 -4
- package/lib/molecule3d/ui/camera.js.map +1 -1
- package/lib/molecule3d/ui/captureScene.d.ts +14 -0
- package/lib/molecule3d/ui/captureScene.d.ts.map +1 -0
- package/lib/molecule3d/ui/captureScene.js +24 -0
- package/lib/molecule3d/ui/captureScene.js.map +1 -0
- package/lib/molecule3d/ui/createViewer.d.ts +18 -0
- package/lib/molecule3d/ui/createViewer.d.ts.map +1 -0
- package/lib/molecule3d/ui/createViewer.js +19 -0
- package/lib/molecule3d/ui/createViewer.js.map +1 -0
- package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts +21 -0
- package/lib/molecule3d/ui/moleculeViewer3DProps.d.ts.map +1 -1
- package/lib/molecule3d/ui/useMoleculeScene.d.ts +47 -0
- package/lib/molecule3d/ui/useMoleculeScene.d.ts.map +1 -0
- package/lib/molecule3d/ui/useMoleculeScene.js +82 -0
- package/lib/molecule3d/ui/useMoleculeScene.js.map +1 -0
- package/lib/molecule3d/ui/useSharedCamera.d.ts +52 -0
- package/lib/molecule3d/ui/useSharedCamera.d.ts.map +1 -0
- package/lib/molecule3d/ui/useSharedCamera.js +82 -0
- package/lib/molecule3d/ui/useSharedCamera.js.map +1 -0
- package/lib/molecule3d/ui/viewer.d.ts +21 -15
- package/lib/molecule3d/ui/viewer.d.ts.map +1 -1
- package/lib/molecule3d/ui/viewer.js +41 -47
- package/lib/molecule3d/ui/viewer.js.map +1 -1
- package/lib/molecule3d/ui/viewerSpec.d.ts +17 -0
- package/lib/molecule3d/ui/viewerSpec.d.ts.map +1 -0
- package/lib/molecule3d/ui/viewerSpec.js +34 -0
- package/lib/molecule3d/ui/viewerSpec.js.map +1 -0
- package/lib/structure/core/editorGuide.d.ts +69 -0
- package/lib/structure/core/editorGuide.d.ts.map +1 -0
- package/lib/structure/core/editorGuide.js +162 -0
- package/lib/structure/core/editorGuide.js.map +1 -0
- package/lib/structure/core/editorToolbar.d.ts +45 -0
- package/lib/structure/core/editorToolbar.d.ts.map +1 -0
- package/lib/structure/core/editorToolbar.js +132 -0
- package/lib/structure/core/editorToolbar.js.map +1 -0
- package/lib/structure/core/editorToolbarGeometry.d.ts +36 -0
- package/lib/structure/core/editorToolbarGeometry.d.ts.map +1 -0
- package/lib/structure/core/editorToolbarGeometry.js +61 -0
- package/lib/structure/core/editorToolbarGeometry.js.map +1 -0
- package/lib/structure/core/index.d.ts +6 -0
- package/lib/structure/core/index.d.ts.map +1 -1
- package/lib/structure/core/index.js +3 -0
- package/lib/structure/core/index.js.map +1 -1
- package/lib/structure/core/pendingCall.d.ts +21 -0
- package/lib/structure/core/pendingCall.d.ts.map +1 -0
- package/lib/structure/core/pendingCall.js +37 -0
- package/lib/structure/core/pendingCall.js.map +1 -0
- package/lib/structure/ui/EditorCanvas.d.ts +1 -16
- package/lib/structure/ui/EditorCanvas.d.ts.map +1 -1
- package/lib/structure/ui/EditorCanvas.js +5 -18
- package/lib/structure/ui/EditorCanvas.js.map +1 -1
- package/lib/structure/ui/EditorHelpButton.d.ts +22 -0
- package/lib/structure/ui/EditorHelpButton.d.ts.map +1 -0
- package/lib/structure/ui/EditorHelpButton.js +38 -0
- package/lib/structure/ui/EditorHelpButton.js.map +1 -0
- package/lib/structure/ui/KeyCaps.d.ts +12 -0
- package/lib/structure/ui/KeyCaps.d.ts.map +1 -0
- package/lib/structure/ui/KeyCaps.js +29 -0
- package/lib/structure/ui/KeyCaps.js.map +1 -0
- package/lib/structure/ui/StructureEditor.d.ts +9 -2
- package/lib/structure/ui/StructureEditor.d.ts.map +1 -1
- package/lib/structure/ui/StructureEditor.js +17 -24
- package/lib/structure/ui/StructureEditor.js.map +1 -1
- package/lib/structure/ui/StructureEditorHelp.d.ts +18 -0
- package/lib/structure/ui/StructureEditorHelp.d.ts.map +1 -0
- package/lib/structure/ui/StructureEditorHelp.js +68 -0
- package/lib/structure/ui/StructureEditorHelp.js.map +1 -0
- package/lib/structure/ui/ToolbarTooltip.d.ts +20 -0
- package/lib/structure/ui/ToolbarTooltip.d.ts.map +1 -0
- package/lib/structure/ui/ToolbarTooltip.js +49 -0
- package/lib/structure/ui/ToolbarTooltip.js.map +1 -0
- package/lib/structure/ui/editorChange.d.ts +52 -0
- package/lib/structure/ui/editorChange.d.ts.map +1 -0
- package/lib/structure/ui/editorChange.js +34 -0
- package/lib/structure/ui/editorChange.js.map +1 -0
- package/lib/structure/ui/index.d.ts +3 -1
- package/lib/structure/ui/index.d.ts.map +1 -1
- package/lib/structure/ui/index.js +1 -0
- package/lib/structure/ui/index.js.map +1 -1
- package/lib/structure/ui/useToolbarFloor.d.ts.map +1 -1
- package/lib/structure/ui/useToolbarFloor.js +6 -45
- package/lib/structure/ui/useToolbarFloor.js.map +1 -1
- package/lib/structure/ui/useToolbarHover.d.ts +28 -0
- package/lib/structure/ui/useToolbarHover.d.ts.map +1 -0
- package/lib/structure/ui/useToolbarHover.js +96 -0
- package/lib/structure/ui/useToolbarHover.js.map +1 -0
- package/lib/structure/ui/watchToolbar.d.ts +17 -0
- package/lib/structure/ui/watchToolbar.d.ts.map +1 -0
- package/lib/structure/ui/watchToolbar.js +56 -0
- package/lib/structure/ui/watchToolbar.js.map +1 -0
- package/package.json +1 -1
- package/src/about/core/about.ts +11 -0
- package/src/about/core/index.ts +1 -0
- package/src/about/core/repository.ts +22 -0
- package/src/about/ui/AboutBuild.tsx +13 -20
- package/src/about/ui/AboutPage.tsx +30 -22
- package/src/about/ui/AboutVersion.tsx +67 -0
- package/src/about/ui/index.ts +2 -0
- package/src/build/core/buildInfo.ts +24 -0
- package/src/build/core/index.ts +6 -1
- package/src/build/vite/buildInfo.ts +2 -2
- package/src/ecosystem/core/sites.ts +12 -0
- package/src/ecosystem/core/types.ts +8 -0
- package/src/molecule3d/core/camera.ts +212 -0
- package/src/molecule3d/core/index.ts +14 -0
- package/src/molecule3d/ui/MoleculeCanvas3D.tsx +14 -43
- package/src/molecule3d/ui/camera.ts +128 -7
- package/src/molecule3d/ui/captureScene.ts +31 -0
- package/src/molecule3d/ui/createViewer.ts +24 -0
- package/src/molecule3d/ui/moleculeViewer3DProps.ts +21 -0
- package/src/molecule3d/ui/useMoleculeScene.ts +141 -0
- package/src/molecule3d/ui/useSharedCamera.ts +121 -0
- package/src/molecule3d/ui/viewer.ts +45 -50
- package/src/molecule3d/ui/viewerSpec.ts +38 -0
- package/src/structure/core/editorGuide.ts +221 -0
- package/src/structure/core/editorToolbar.ts +175 -0
- package/src/structure/core/editorToolbarGeometry.ts +80 -0
- package/src/structure/core/index.ts +29 -0
- package/src/structure/core/pendingCall.ts +59 -0
- package/src/structure/ui/EditorCanvas.tsx +9 -35
- package/src/structure/ui/EditorHelpButton.tsx +70 -0
- package/src/structure/ui/KeyCaps.tsx +40 -0
- package/src/structure/ui/StructureEditor.tsx +39 -21
- package/src/structure/ui/StructureEditorHelp.tsx +136 -0
- package/src/structure/ui/ToolbarTooltip.tsx +95 -0
- package/src/structure/ui/editorChange.ts +81 -0
- package/src/structure/ui/index.ts +5 -1
- package/src/structure/ui/useToolbarFloor.ts +7 -46
- package/src/structure/ui/useToolbarHover.ts +134 -0
- package/src/structure/ui/watchToolbar.ts +59 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* What the keyboard and the mouse do in the structure editor, shown in the
|
|
4
|
+
* editor's help popover, and usable by a site on a page of its own.
|
|
5
|
+
*/
|
|
6
|
+
import { Classes } from '@blueprintjs/core';
|
|
7
|
+
import { TOKEN } from "../../tokens/core/familyTokens.js";
|
|
8
|
+
import { STRUCTURE_EDITOR_DOCS, editorGuideSections, } from "../core/editorGuide.js";
|
|
9
|
+
import { KeyCaps } from "./KeyCaps.js";
|
|
10
|
+
/**
|
|
11
|
+
* The guide to the structure editor: the keys that change the atom or bond
|
|
12
|
+
* under the pointer, the selection gestures, the stereo conventions, and links
|
|
13
|
+
* to the full documentation. Gestures that do nothing in the given editor are
|
|
14
|
+
* left out.
|
|
15
|
+
* @param props - See {@link StructureEditorHelpProps}.
|
|
16
|
+
* @returns The guide.
|
|
17
|
+
*/
|
|
18
|
+
export function StructureEditorHelp(props) {
|
|
19
|
+
const sections = editorGuideSections(props);
|
|
20
|
+
return (_jsxs("div", { style: PANEL_STYLE, "data-testid": "structure-editor-help", children: [_jsx("p", { className: Classes.TEXT_MUTED, style: PARAGRAPH_STYLE, children: "Hover a toolbar button to see what it does and its key." }), _jsx("div", { style: GRID_STYLE, children: sections.map((section) => (_jsxs("section", { style: ROW_STYLE, children: [_jsx("h4", { style: HEADING_STYLE, children: section.title }), section.gestures.map((gesture) => (_jsxs("div", { style: ROW_STYLE, children: [_jsx(GestureInput, { input: gesture.input }), _jsx("span", { children: gesture.action })] }, gestureKey(gesture)))), section.note === undefined ? null : (_jsx("p", { className: Classes.TEXT_MUTED, style: NOTE_STYLE, children: section.note }))] }, section.title))) }), _jsxs("p", { style: PARAGRAPH_STYLE, children: ["Learn more:", ' ', STRUCTURE_EDITOR_DOCS.map((link, index) => (_jsxs("span", { children: [index === 0 ? null : ' · ', _jsx("a", { href: link.url, target: "_blank", rel: "noopener noreferrer", children: link.title })] }, link.url)))] })] }));
|
|
21
|
+
}
|
|
22
|
+
function GestureInput(props) {
|
|
23
|
+
return (_jsx("span", { style: INPUT_STYLE, children: props.input.map((part) => typeof part === 'string' ? (_jsx("span", { children: part }, part)) : (_jsx(KeyCaps, { keys: [part.key] }, part.key))) }));
|
|
24
|
+
}
|
|
25
|
+
function gestureKey(gesture) {
|
|
26
|
+
const input = gesture.input
|
|
27
|
+
.map((part) => (typeof part === 'string' ? part : part.key))
|
|
28
|
+
.join(' ');
|
|
29
|
+
return `${input} ${gesture.action}`;
|
|
30
|
+
}
|
|
31
|
+
const PANEL_STYLE = {
|
|
32
|
+
display: 'flex',
|
|
33
|
+
flexDirection: 'column',
|
|
34
|
+
gap: 10,
|
|
35
|
+
width: 400,
|
|
36
|
+
maxHeight: 'min(70vh, 36rem)',
|
|
37
|
+
overflowY: 'auto',
|
|
38
|
+
padding: 12,
|
|
39
|
+
fontSize: 12,
|
|
40
|
+
};
|
|
41
|
+
const GRID_STYLE = {
|
|
42
|
+
display: 'grid',
|
|
43
|
+
gridTemplateColumns: 'max-content minmax(0, 1fr)',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
columnGap: 12,
|
|
46
|
+
rowGap: 6,
|
|
47
|
+
};
|
|
48
|
+
const ROW_STYLE = { display: 'contents' };
|
|
49
|
+
const HEADING_STYLE = {
|
|
50
|
+
gridColumn: '1 / -1',
|
|
51
|
+
margin: '8px 0 0',
|
|
52
|
+
paddingBottom: 3,
|
|
53
|
+
borderBottom: `1px solid ${TOKEN.border}`,
|
|
54
|
+
color: TOKEN.textMuted,
|
|
55
|
+
fontSize: 11,
|
|
56
|
+
fontWeight: 700,
|
|
57
|
+
letterSpacing: '0.04em',
|
|
58
|
+
textTransform: 'uppercase',
|
|
59
|
+
};
|
|
60
|
+
const INPUT_STYLE = {
|
|
61
|
+
display: 'flex',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
gap: 4,
|
|
64
|
+
whiteSpace: 'nowrap',
|
|
65
|
+
};
|
|
66
|
+
const PARAGRAPH_STYLE = { margin: 0, lineHeight: 1.45 };
|
|
67
|
+
const NOTE_STYLE = { ...PARAGRAPH_STYLE, gridColumn: '1 / -1' };
|
|
68
|
+
//# sourceMappingURL=StructureEditorHelp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StructureEditorHelp.js","sourceRoot":"","sources":["../../../src/structure/ui/StructureEditorHelp.tsx"],"names":[],"mappings":";AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,OAAO,EACL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAC;AAKxC;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAA+B;IAE/B,MAAM,QAAQ,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAE5C,OAAO,CACL,eAAK,KAAK,EAAE,WAAW,iBAAc,uBAAuB,aAC1D,YAAG,SAAS,EAAE,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,eAAe,wEAEpD,EAEJ,cAAK,KAAK,EAAE,UAAU,YACnB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACzB,mBAA6B,KAAK,EAAE,SAAS,aAC3C,aAAI,KAAK,EAAE,aAAa,YAAG,OAAO,CAAC,KAAK,GAAM,EAC7C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CACjC,eAA+B,KAAK,EAAE,SAAS,aAC7C,KAAC,YAAY,IAAC,KAAK,EAAE,OAAO,CAAC,KAAK,GAAI,EACtC,yBAAO,OAAO,CA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 +1,20 @@
|
|
|
1
|
+
import type { ReactElement, RefObject } from 'react';
|
|
2
|
+
import type { StructureEditorMode } from './editorChange.ts';
|
|
3
|
+
/** What {@link ToolbarTooltip} needs. */
|
|
4
|
+
export interface ToolbarTooltipProps {
|
|
5
|
+
/** The positioned element wrapping the editor. */
|
|
6
|
+
containerRef: RefObject<HTMLElement | null>;
|
|
7
|
+
/** Which editor the toolbar belongs to, since some buttons are greyed. */
|
|
8
|
+
mode: StructureEditorMode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The name, key and purpose of the toolbar button under the pointer.
|
|
12
|
+
*
|
|
13
|
+
* The toolbar is a canvas, so the tooltip is anchored to an invisible box laid
|
|
14
|
+
* over the button rather than to the button itself; the box lets the pointer
|
|
15
|
+
* through, so the editor still sees every hover and click.
|
|
16
|
+
* @param props - See {@link ToolbarTooltipProps}.
|
|
17
|
+
* @returns The tooltip, or nothing before a button has been hovered.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ToolbarTooltip(props: ToolbarTooltipProps): ReactElement | null;
|
|
20
|
+
//# sourceMappingURL=ToolbarTooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarTooltip.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/ToolbarTooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAG7D,yCAAyC;AACzC,MAAM,WAAW,mBAAmB;IAClC,kDAAkD;IAClD,YAAY,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC5C,0EAA0E;IAC1E,IAAI,EAAE,mBAAmB,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,mBAAmB,GACzB,YAAY,GAAG,IAAI,CAiBrB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Classes, Tooltip } from '@blueprintjs/core';
|
|
3
|
+
import { EDITOR_TOOLBAR_BUTTONS, isEditorToolbarButtonAvailable, } from "../core/editorToolbar.js";
|
|
4
|
+
import { KeyCaps } from "./KeyCaps.js";
|
|
5
|
+
import { useToolbarHover } from "./useToolbarHover.js";
|
|
6
|
+
/**
|
|
7
|
+
* The name, key and purpose of the toolbar button under the pointer.
|
|
8
|
+
*
|
|
9
|
+
* The toolbar is a canvas, so the tooltip is anchored to an invisible box laid
|
|
10
|
+
* over the button rather than to the button itself; the box lets the pointer
|
|
11
|
+
* through, so the editor still sees every hover and click.
|
|
12
|
+
* @param props - See {@link ToolbarTooltipProps}.
|
|
13
|
+
* @returns The tooltip, or nothing before a button has been hovered.
|
|
14
|
+
*/
|
|
15
|
+
export function ToolbarTooltip(props) {
|
|
16
|
+
const { containerRef, mode } = props;
|
|
17
|
+
const hover = useToolbarHover(containerRef);
|
|
18
|
+
if (hover === null)
|
|
19
|
+
return null;
|
|
20
|
+
const button = EDITOR_TOOLBAR_BUTTONS[hover.button];
|
|
21
|
+
if (button === undefined)
|
|
22
|
+
return null;
|
|
23
|
+
return (_jsx(Tooltip, { isOpen: hover.open, placement: "right", content: _jsx(ButtonTip, { button: button, mode: mode }), renderTarget: ({ ref }) => (_jsx("span", { ref: ref, "aria-hidden": true, style: { ...TARGET_STYLE, ...hover.box } })) }));
|
|
24
|
+
}
|
|
25
|
+
function ButtonTip(props) {
|
|
26
|
+
const { button, mode } = props;
|
|
27
|
+
const available = isEditorToolbarButtonAvailable(button, mode);
|
|
28
|
+
return (_jsxs("div", { style: TIP_STYLE, "data-testid": "structure-editor-tooltip", children: [_jsxs("div", { style: HEAD_STYLE, children: [_jsx("strong", { children: button.name }), button.keys === undefined ? null : _jsx(KeyCaps, { keys: button.keys })] }), _jsx("div", { children: button.description }), available ? null : (_jsx("div", { className: Classes.TEXT_MUTED, children: button.availability === 'reaction'
|
|
29
|
+
? 'Only when drawing a reaction.'
|
|
30
|
+
: 'Not available in this editor.' }))] }));
|
|
31
|
+
}
|
|
32
|
+
const TARGET_STYLE = {
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
pointerEvents: 'none',
|
|
35
|
+
};
|
|
36
|
+
const TIP_STYLE = {
|
|
37
|
+
display: 'flex',
|
|
38
|
+
flexDirection: 'column',
|
|
39
|
+
gap: 4,
|
|
40
|
+
maxWidth: 260,
|
|
41
|
+
lineHeight: 1.4,
|
|
42
|
+
};
|
|
43
|
+
const HEAD_STYLE = {
|
|
44
|
+
display: 'flex',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
justifyContent: 'space-between',
|
|
47
|
+
gap: 12,
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=ToolbarTooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarTooltip.js","sourceRoot":"","sources":["../../../src/structure/ui/ToolbarTooltip.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIrD,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAUvD;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,KAA0B;IAE1B,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACrC,MAAM,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,MAAM,GAAG,sBAAsB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,MAAM,KAAK,SAA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ACf,aAAa,EAAE,QAAQ;IACvB,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,GAAG;IACb,UAAU,EAAE,GAAG;CAChB,CAAC;AAEF,MAAM,UAAU,GAAkB;IAChC,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,eAAe;IAC/B,GAAG,EAAE,EAAE;CACR,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the structure editor reports after an edit.
|
|
3
|
+
*
|
|
4
|
+
* Only types are imported from react-ocl and openchemlib, so this module can be
|
|
5
|
+
* reached from the `react-cheminfo/structure` barrel without pulling either in.
|
|
6
|
+
*/
|
|
7
|
+
import type { Molecule } from 'openchemlib';
|
|
8
|
+
import type { CanvasEditorOnChangeMolecule, CanvasEditorOnChangeReaction } from 'react-ocl';
|
|
9
|
+
/** What the editor draws: one structure, or a reaction with its arrow. */
|
|
10
|
+
export type StructureEditorMode = 'molecule' | 'reaction';
|
|
11
|
+
/** The notations every change carries, whichever the editor. */
|
|
12
|
+
interface StructureEditorNotations {
|
|
13
|
+
/**
|
|
14
|
+
* The idCode, with the coordinates the editor laid out written after a
|
|
15
|
+
* space. `splitIdCode` takes the two apart.
|
|
16
|
+
*/
|
|
17
|
+
idCode: string;
|
|
18
|
+
/** The V2000 molfile of a molecule, or the RXN file of a reaction. */
|
|
19
|
+
molfile: string;
|
|
20
|
+
/** The SMILES of a molecule, or the reaction SMILES. */
|
|
21
|
+
smiles: string;
|
|
22
|
+
}
|
|
23
|
+
/** What a molecule editor holds at the moment it changed. */
|
|
24
|
+
export interface StructureEditorMoleculeChange extends StructureEditorNotations {
|
|
25
|
+
mode: 'molecule';
|
|
26
|
+
/**
|
|
27
|
+
* A copy of the drawn molecule, with its coordinates. It is taken when the
|
|
28
|
+
* edit happens, so it still describes that edit when it arrives after the
|
|
29
|
+
* debounce, and the caller may modify it without touching the canvas.
|
|
30
|
+
*/
|
|
31
|
+
molecule: Molecule;
|
|
32
|
+
}
|
|
33
|
+
/** What a reaction editor holds at the moment it changed. */
|
|
34
|
+
export interface StructureEditorReactionChange extends StructureEditorNotations {
|
|
35
|
+
mode: 'reaction';
|
|
36
|
+
}
|
|
37
|
+
/** Everything the editor holds at the moment it changed. */
|
|
38
|
+
export type StructureEditorChange = StructureEditorMoleculeChange | StructureEditorReactionChange;
|
|
39
|
+
/**
|
|
40
|
+
* Read a molecule editor's event out, while it still describes the edit.
|
|
41
|
+
* @param event - The event react-ocl passes to its callback.
|
|
42
|
+
* @returns The change, independent of the editor from then on.
|
|
43
|
+
*/
|
|
44
|
+
export declare function moleculeChange(event: CanvasEditorOnChangeMolecule): StructureEditorMoleculeChange;
|
|
45
|
+
/**
|
|
46
|
+
* Read a reaction editor's event out, while it still describes the edit.
|
|
47
|
+
* @param event - The event react-ocl passes to its callback.
|
|
48
|
+
* @returns The change, independent of the editor from then on.
|
|
49
|
+
*/
|
|
50
|
+
export declare function reactionChange(event: CanvasEditorOnChangeReaction): StructureEditorReactionChange;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=editorChange.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorChange.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/editorChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EACV,4BAA4B,EAC5B,4BAA4B,EAC7B,MAAM,WAAW,CAAC;AAEnB,0EAA0E;AAC1E,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,UAAU,CAAC;AAE1D,gEAAgE;AAChE,UAAU,wBAAwB;IAChC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,6DAA6D;AAC7D,MAAM,WAAW,6BAA8B,SAAQ,wBAAwB;IAC7E,IAAI,EAAE,UAAU,CAAC;IACjB;;;;OAIG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,6DAA6D;AAC7D,MAAM,WAAW,6BAA8B,SAAQ,wBAAwB;IAC7E,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,4DAA4D;AAC5D,MAAM,MAAM,qBAAqB,GAC/B,6BAA6B,GAAG,6BAA6B,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,4BAA4B,GAClC,6BAA6B,CAQ/B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,4BAA4B,GAClC,6BAA6B,CAO/B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the structure editor reports after an edit.
|
|
3
|
+
*
|
|
4
|
+
* Only types are imported from react-ocl and openchemlib, so this module can be
|
|
5
|
+
* reached from the `react-cheminfo/structure` barrel without pulling either in.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Read a molecule editor's event out, while it still describes the edit.
|
|
9
|
+
* @param event - The event react-ocl passes to its callback.
|
|
10
|
+
* @returns The change, independent of the editor from then on.
|
|
11
|
+
*/
|
|
12
|
+
export function moleculeChange(event) {
|
|
13
|
+
return {
|
|
14
|
+
mode: 'molecule',
|
|
15
|
+
idCode: event.getIdcode(),
|
|
16
|
+
molfile: event.getMolfile(),
|
|
17
|
+
smiles: event.getSmiles(),
|
|
18
|
+
molecule: event.getMolecule(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Read a reaction editor's event out, while it still describes the edit.
|
|
23
|
+
* @param event - The event react-ocl passes to its callback.
|
|
24
|
+
* @returns The change, independent of the editor from then on.
|
|
25
|
+
*/
|
|
26
|
+
export function reactionChange(event) {
|
|
27
|
+
return {
|
|
28
|
+
mode: 'reaction',
|
|
29
|
+
idCode: event.getIdcode(),
|
|
30
|
+
molfile: event.getRxn(),
|
|
31
|
+
smiles: event.getSmiles(),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=editorChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorChange.js","sourceRoot":"","sources":["../../../src/structure/ui/editorChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4CH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAmC;IAEnC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE;QACzB,OAAO,EAAE,KAAK,CAAC,UAAU,EAAE;QAC3B,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE;QACzB,QAAQ,EAAE,KAAK,CAAC,WAAW,EAAE;KAC9B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAmC;IAEnC,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE;QACzB,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE;QACvB,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE;KAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
* optional peers are not installed — which is what a site wanting only the
|
|
10
10
|
* Tools menu does. Type-only re-exports are erased and so are safe.
|
|
11
11
|
*/
|
|
12
|
-
export type { StructureEditorChange, StructureEditorMode, } from './
|
|
12
|
+
export type { StructureEditorChange, StructureEditorMode, StructureEditorMoleculeChange, StructureEditorReactionChange, } from './editorChange.ts';
|
|
13
13
|
export type { StructureLabels, StructureProps } from './Structure.tsx';
|
|
14
14
|
export { Structure } from './Structure.tsx';
|
|
15
15
|
export type { StructureEditorProps } from './StructureEditor.tsx';
|
|
16
16
|
export { StructureEditor } from './StructureEditor.tsx';
|
|
17
|
+
export type { StructureEditorHelpProps } from './StructureEditorHelp.tsx';
|
|
18
|
+
export { StructureEditorHelp } from './StructureEditorHelp.tsx';
|
|
17
19
|
export type { ToolbarFloorOptions } from './useToolbarFloor.ts';
|
|
18
20
|
export { useToolbarFloor } from './useToolbarFloor.ts';
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EACV,qBAAqB,EACrB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -11,5 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export { Structure } from "./Structure.js";
|
|
13
13
|
export { StructureEditor } from "./StructureEditor.js";
|
|
14
|
+
export { StructureEditorHelp } from "./StructureEditorHelp.js";
|
|
14
15
|
export { useToolbarFloor } from "./useToolbarFloor.js";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structure/ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/structure/ui/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AASH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAiB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAuB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA2B,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToolbarFloor.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/useToolbarFloor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useToolbarFloor.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/useToolbarFloor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC,0CAA0C;AAC1C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,OAAO,GAAE,mBAAwB,GAChC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAyBlC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useLayoutEffect, useRef } from 'react';
|
|
2
2
|
import { toolbarFloorHeight } from "../core/toolbarFloor.js";
|
|
3
|
+
import { watchToolbar } from "./watchToolbar.js";
|
|
3
4
|
/**
|
|
4
5
|
* Give an editor's container a minimum height that shows the whole toolbar.
|
|
5
6
|
*
|
|
@@ -16,18 +17,11 @@ export function useToolbarFloor(options = {}) {
|
|
|
16
17
|
const container = containerRef.current;
|
|
17
18
|
if (container === null)
|
|
18
19
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const attach = () => {
|
|
22
|
-
const found = findToolbar(container);
|
|
23
|
-
if (found === null)
|
|
24
|
-
return;
|
|
25
|
-
size?.disconnect();
|
|
26
|
-
toolbar = found;
|
|
27
|
-
size = new ResizeObserver(() => {
|
|
20
|
+
return watchToolbar(container, (toolbar) => {
|
|
21
|
+
const size = new ResizeObserver(() => {
|
|
28
22
|
// offsetHeight, because a dialog opens under a scaling transform and a
|
|
29
23
|
// measured rectangle would be that of the half drawn toolbar.
|
|
30
|
-
const height =
|
|
24
|
+
const height = toolbar.offsetHeight;
|
|
31
25
|
// Zero is a toolbar being torn down or not yet laid out, never a
|
|
32
26
|
// toolbar that needs no room: writing the fallback for it would undo a
|
|
33
27
|
// correct floor and leave the palette cut off.
|
|
@@ -35,43 +29,10 @@ export function useToolbarFloor(options = {}) {
|
|
|
35
29
|
return;
|
|
36
30
|
container.style.minHeight = `${toolbarFloorHeight(height, minHeight)}px`;
|
|
37
31
|
});
|
|
38
|
-
size.observe(
|
|
39
|
-
|
|
40
|
-
// The editor is imported lazily and builds itself asynchronously, so it is
|
|
41
|
-
// almost never there on the first look, and how long it takes is a cold
|
|
42
|
-
// module graph and a network away from anything this code can predict. So
|
|
43
|
-
// the arrival is watched for rather than waited out: a deadline that
|
|
44
|
-
// expires leaves the toolbar cut off for the life of the page, with
|
|
45
|
-
// nothing on screen to say why.
|
|
46
|
-
const arrivals = new MutationObserver(() => {
|
|
47
|
-
if (toolbar?.isConnected === true)
|
|
48
|
-
return;
|
|
49
|
-
attach();
|
|
32
|
+
size.observe(toolbar);
|
|
33
|
+
return () => size.disconnect();
|
|
50
34
|
});
|
|
51
|
-
arrivals.observe(container, { childList: true, subtree: true });
|
|
52
|
-
attach();
|
|
53
|
-
return () => {
|
|
54
|
-
arrivals.disconnect();
|
|
55
|
-
size?.disconnect();
|
|
56
|
-
};
|
|
57
35
|
}, [minHeight, revision]);
|
|
58
36
|
return containerRef;
|
|
59
37
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Find the toolbar canvas of the editor.
|
|
62
|
-
*
|
|
63
|
-
* The editor builds itself inside a shadow root and puts the toolbar there as
|
|
64
|
-
* a direct child, the drawing canvas being nested deeper.
|
|
65
|
-
* @param container - The element wrapping the editor.
|
|
66
|
-
* @returns The toolbar canvas, or null while the editor has not drawn one.
|
|
67
|
-
*/
|
|
68
|
-
function findToolbar(container) {
|
|
69
|
-
for (const element of container.querySelectorAll('*')) {
|
|
70
|
-
for (const child of element.shadowRoot?.children ?? []) {
|
|
71
|
-
if (child instanceof HTMLCanvasElement)
|
|
72
|
-
return child;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
38
|
//# sourceMappingURL=useToolbarFloor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToolbarFloor.js","sourceRoot":"","sources":["../../../src/structure/ui/useToolbarFloor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"useToolbarFloor.js","sourceRoot":"","sources":["../../../src/structure/ui/useToolbarFloor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAkBjD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,UAA+B,EAAE;IAEjC,MAAM,EAAE,SAAS,GAAG,GAAG,EAAE,QAAQ,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAElD,eAAe,CAAC,GAAG,EAAE;QACnB,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO;QAE/B,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;YACzC,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,GAAG,EAAE;gBACnC,uEAAuE;gBACvE,8DAA8D;gBAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;gBACpC,iEAAiE;gBACjE,uEAAuE;gBACvE,+CAA+C;gBAC/C,IAAI,MAAM,KAAK,CAAC;oBAAE,OAAO;gBACzB,SAAS,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC;YAC3E,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE1B,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { EditorToolbarButtonBox } from '../core/editorToolbarGeometry.ts';
|
|
3
|
+
/** The toolbar button the pointer rests on, or last rested on. */
|
|
4
|
+
export interface ToolbarHover {
|
|
5
|
+
/** The button's index in `EDITOR_TOOLBAR_BUTTONS`. */
|
|
6
|
+
button: number;
|
|
7
|
+
/** Where the button is drawn, relative to the container's padding box. */
|
|
8
|
+
box: EditorToolbarButtonBox;
|
|
9
|
+
/**
|
|
10
|
+
* Whether its tooltip is showing. The last button is kept after the pointer
|
|
11
|
+
* leaves, so a closing tooltip fades out with its text rather than empty.
|
|
12
|
+
*/
|
|
13
|
+
open: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Follow the pointer over the editor's toolbar.
|
|
17
|
+
*
|
|
18
|
+
* The first button waits for the pointer to rest, so crossing the toolbar on
|
|
19
|
+
* the way to the drawing opens nothing; once one is showing, the next follows
|
|
20
|
+
* at once. Pressing a button hides its tooltip until the pointer moves on,
|
|
21
|
+
* since whoever pressed it no longer needs telling. Touch is ignored: a finger
|
|
22
|
+
* has no hover, and a tooltip opened by a tap would cover the canvas.
|
|
23
|
+
* @param containerRef - The element wrapping the editor, positioned so the
|
|
24
|
+
* returned box can be laid over the button.
|
|
25
|
+
* @returns The button under the pointer, or null before any has been hovered.
|
|
26
|
+
*/
|
|
27
|
+
export declare function useToolbarHover(containerRef: RefObject<HTMLElement | null>): ToolbarHover | null;
|
|
28
|
+
//# sourceMappingURL=useToolbarHover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolbarHover.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/useToolbarHover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAQ/E,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,GAAG,EAAE,sBAAsB,CAAC;IAC5B;;;OAGG;IACH,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GAC1C,YAAY,GAAG,IAAI,CA4ErB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { editorToolbarButtonAt, editorToolbarButtonBox, } from "../core/editorToolbarGeometry.js";
|
|
3
|
+
import { watchToolbar } from "./watchToolbar.js";
|
|
4
|
+
/**
|
|
5
|
+
* Follow the pointer over the editor's toolbar.
|
|
6
|
+
*
|
|
7
|
+
* The first button waits for the pointer to rest, so crossing the toolbar on
|
|
8
|
+
* the way to the drawing opens nothing; once one is showing, the next follows
|
|
9
|
+
* at once. Pressing a button hides its tooltip until the pointer moves on,
|
|
10
|
+
* since whoever pressed it no longer needs telling. Touch is ignored: a finger
|
|
11
|
+
* has no hover, and a tooltip opened by a tap would cover the canvas.
|
|
12
|
+
* @param containerRef - The element wrapping the editor, positioned so the
|
|
13
|
+
* returned box can be laid over the button.
|
|
14
|
+
* @returns The button under the pointer, or null before any has been hovered.
|
|
15
|
+
*/
|
|
16
|
+
export function useToolbarHover(containerRef) {
|
|
17
|
+
const [hover, setHover] = useState(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const container = containerRef.current;
|
|
20
|
+
if (container === null)
|
|
21
|
+
return;
|
|
22
|
+
let timer;
|
|
23
|
+
let current = -1;
|
|
24
|
+
let pressed = -1;
|
|
25
|
+
let open = false;
|
|
26
|
+
const show = (toolbar, button) => {
|
|
27
|
+
open = true;
|
|
28
|
+
setHover({ button, box: boxIn(container, toolbar, button), open });
|
|
29
|
+
};
|
|
30
|
+
const hide = () => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
if (!open)
|
|
33
|
+
return;
|
|
34
|
+
open = false;
|
|
35
|
+
setHover((previous) => previous === null ? null : { ...previous, open: false });
|
|
36
|
+
};
|
|
37
|
+
const onLeave = () => {
|
|
38
|
+
current = -1;
|
|
39
|
+
pressed = -1;
|
|
40
|
+
hide();
|
|
41
|
+
};
|
|
42
|
+
const onDown = () => {
|
|
43
|
+
pressed = current;
|
|
44
|
+
hide();
|
|
45
|
+
};
|
|
46
|
+
const stop = watchToolbar(container, (toolbar) => {
|
|
47
|
+
const onMove = (event) => {
|
|
48
|
+
if (event.pointerType === 'touch')
|
|
49
|
+
return;
|
|
50
|
+
const button = editorToolbarButtonAt(event.offsetX, event.offsetY, toolbar.offsetHeight);
|
|
51
|
+
if (button === current)
|
|
52
|
+
return;
|
|
53
|
+
current = button;
|
|
54
|
+
if (button !== pressed)
|
|
55
|
+
pressed = -1;
|
|
56
|
+
if (button === -1 || button === pressed) {
|
|
57
|
+
hide();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
if (open) {
|
|
62
|
+
show(toolbar, button);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
timer = setTimeout(() => show(toolbar, button), OPEN_DELAY);
|
|
66
|
+
};
|
|
67
|
+
toolbar.addEventListener('pointermove', onMove);
|
|
68
|
+
toolbar.addEventListener('pointerleave', onLeave);
|
|
69
|
+
toolbar.addEventListener('pointerdown', onDown);
|
|
70
|
+
return () => {
|
|
71
|
+
toolbar.removeEventListener('pointermove', onMove);
|
|
72
|
+
toolbar.removeEventListener('pointerleave', onLeave);
|
|
73
|
+
toolbar.removeEventListener('pointerdown', onDown);
|
|
74
|
+
onLeave();
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
return () => {
|
|
78
|
+
stop();
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
};
|
|
81
|
+
}, [containerRef]);
|
|
82
|
+
return hover;
|
|
83
|
+
}
|
|
84
|
+
// Long enough that sweeping the pointer across the toolbar opens nothing.
|
|
85
|
+
const OPEN_DELAY = 250;
|
|
86
|
+
function boxIn(container, toolbar, button) {
|
|
87
|
+
const box = editorToolbarButtonBox(button, toolbar.offsetHeight);
|
|
88
|
+
const toolbarRect = toolbar.getBoundingClientRect();
|
|
89
|
+
const containerRect = container.getBoundingClientRect();
|
|
90
|
+
return {
|
|
91
|
+
...box,
|
|
92
|
+
left: toolbarRect.left - containerRect.left - container.clientLeft + box.left,
|
|
93
|
+
top: toolbarRect.top - containerRect.top - container.clientTop + box.top,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=useToolbarHover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolbarHover.js","sourceRoot":"","sources":["../../../src/structure/ui/useToolbarHover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAejD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,YAA2C;IAE3C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAsB,IAAI,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC;QACvC,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO;QAE/B,IAAI,KAAgD,CAAC;QACrD,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC;QACjB,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC;QACjB,IAAI,IAAI,GAAG,KAAK,CAAC;QAEjB,MAAM,IAAI,GAAG,CAAC,OAA0B,EAAE,MAAc,EAAQ,EAAE;YAChE,IAAI,GAAG,IAAI,CAAC;YACZ,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QACrE,CAAC,CAAC;QACF,MAAM,IAAI,GAAG,GAAS,EAAE;YACtB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,IAAI,CAAC,IAAI;gBAAE,OAAO;YAClB,IAAI,GAAG,KAAK,CAAC;YACb,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,CACpB,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC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2
|
+
* Run something against the editor's toolbar canvas as soon as it exists, and
|
|
3
|
+
* again against each new one the editor builds.
|
|
4
|
+
*
|
|
5
|
+
* The editor is imported lazily and builds itself asynchronously, so the
|
|
6
|
+
* toolbar is almost never there on the first look, and how long it takes is a
|
|
7
|
+
* cold module graph and a network away from anything this code can predict.
|
|
8
|
+
* So its arrival is watched for rather than waited out: a deadline that
|
|
9
|
+
* expires leaves whatever depends on the toolbar missing for the life of the
|
|
10
|
+
* page, with nothing on screen to say why.
|
|
11
|
+
* @param container - The element wrapping the editor.
|
|
12
|
+
* @param onToolbar - Called with each toolbar found; what it returns is called
|
|
13
|
+
* when that toolbar is replaced or the watch ends.
|
|
14
|
+
* @returns A function ending the watch.
|
|
15
|
+
*/
|
|
16
|
+
export declare function watchToolbar(container: HTMLElement, onToolbar: (toolbar: HTMLCanvasElement) => () => void): () => void;
|
|
17
|
+
//# sourceMappingURL=watchToolbar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchToolbar.d.ts","sourceRoot":"","sources":["../../../src/structure/ui/watchToolbar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,MAAM,IAAI,GACpD,MAAM,IAAI,CAuBZ"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run something against the editor's toolbar canvas as soon as it exists, and
|
|
3
|
+
* again against each new one the editor builds.
|
|
4
|
+
*
|
|
5
|
+
* The editor is imported lazily and builds itself asynchronously, so the
|
|
6
|
+
* toolbar is almost never there on the first look, and how long it takes is a
|
|
7
|
+
* cold module graph and a network away from anything this code can predict.
|
|
8
|
+
* So its arrival is watched for rather than waited out: a deadline that
|
|
9
|
+
* expires leaves whatever depends on the toolbar missing for the life of the
|
|
10
|
+
* page, with nothing on screen to say why.
|
|
11
|
+
* @param container - The element wrapping the editor.
|
|
12
|
+
* @param onToolbar - Called with each toolbar found; what it returns is called
|
|
13
|
+
* when that toolbar is replaced or the watch ends.
|
|
14
|
+
* @returns A function ending the watch.
|
|
15
|
+
*/
|
|
16
|
+
export function watchToolbar(container, onToolbar) {
|
|
17
|
+
let toolbar = null;
|
|
18
|
+
let release = null;
|
|
19
|
+
const attach = () => {
|
|
20
|
+
const found = findToolbar(container);
|
|
21
|
+
if (found === null)
|
|
22
|
+
return;
|
|
23
|
+
release?.();
|
|
24
|
+
toolbar = found;
|
|
25
|
+
release = onToolbar(found);
|
|
26
|
+
};
|
|
27
|
+
const arrivals = new MutationObserver(() => {
|
|
28
|
+
if (toolbar?.isConnected === true)
|
|
29
|
+
return;
|
|
30
|
+
attach();
|
|
31
|
+
});
|
|
32
|
+
arrivals.observe(container, { childList: true, subtree: true });
|
|
33
|
+
attach();
|
|
34
|
+
return () => {
|
|
35
|
+
arrivals.disconnect();
|
|
36
|
+
release?.();
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Find the toolbar canvas of the editor.
|
|
41
|
+
*
|
|
42
|
+
* The editor builds itself inside a shadow root and puts the toolbar there as
|
|
43
|
+
* a direct child, the drawing canvas being nested deeper.
|
|
44
|
+
* @param container - The element wrapping the editor.
|
|
45
|
+
* @returns The toolbar canvas, or null while the editor has not drawn one.
|
|
46
|
+
*/
|
|
47
|
+
function findToolbar(container) {
|
|
48
|
+
for (const element of container.querySelectorAll('*')) {
|
|
49
|
+
for (const child of element.shadowRoot?.children ?? []) {
|
|
50
|
+
if (child instanceof HTMLCanvasElement)
|
|
51
|
+
return child;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=watchToolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchToolbar.js","sourceRoot":"","sources":["../../../src/structure/ui/watchToolbar.ts"],"names":[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"name": "react-cheminfo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
|
|
6
6
|
"author": "Luc Patiny",
|