react-cheminfo 0.16.0 → 0.18.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/parallel/core/index.d.ts +7 -5
- package/lib/parallel/core/index.d.ts.map +1 -1
- package/lib/parallel/core/index.js +5 -3
- package/lib/parallel/core/index.js.map +1 -1
- package/lib/parallel/core/parallelBrush.d.ts +22 -1
- package/lib/parallel/core/parallelBrush.d.ts.map +1 -1
- package/lib/parallel/core/parallelBrush.js +53 -3
- package/lib/parallel/core/parallelBrush.js.map +1 -1
- package/lib/parallel/core/parallelFilter.d.ts +14 -1
- package/lib/parallel/core/parallelFilter.d.ts.map +1 -1
- package/lib/parallel/core/parallelFilter.js +44 -11
- package/lib/parallel/core/parallelFilter.js.map +1 -1
- package/lib/parallel/core/parallelOrder.d.ts +36 -0
- package/lib/parallel/core/parallelOrder.d.ts.map +1 -0
- package/lib/parallel/core/parallelOrder.js +65 -0
- package/lib/parallel/core/parallelOrder.js.map +1 -0
- package/lib/parallel/core/parallelPaint.d.ts +4 -0
- package/lib/parallel/core/parallelPaint.d.ts.map +1 -1
- package/lib/parallel/core/parallelPaint.js +15 -6
- package/lib/parallel/core/parallelPaint.js.map +1 -1
- package/lib/parallel/core/parallelPalette.d.ts +10 -1
- package/lib/parallel/core/parallelPalette.d.ts.map +1 -1
- package/lib/parallel/core/parallelPalette.js +14 -1
- package/lib/parallel/core/parallelPalette.js.map +1 -1
- package/lib/parallel/core/parallelSelection.d.ts +43 -0
- package/lib/parallel/core/parallelSelection.d.ts.map +1 -0
- package/lib/parallel/core/parallelSelection.js +87 -0
- package/lib/parallel/core/parallelSelection.js.map +1 -0
- package/lib/parallel/core/parallelTicks.d.ts.map +1 -1
- package/lib/parallel/core/parallelTicks.js +7 -4
- package/lib/parallel/core/parallelTicks.js.map +1 -1
- package/lib/parallel/core/parallelTypes.d.ts +12 -1
- package/lib/parallel/core/parallelTypes.d.ts.map +1 -1
- package/lib/parallel/core/parallelTypes.js.map +1 -1
- package/lib/parallel/ui/ParallelAxesLayer.d.ts +2 -2
- package/lib/parallel/ui/ParallelAxesLayer.d.ts.map +1 -1
- package/lib/parallel/ui/ParallelAxesLayer.js +2 -2
- package/lib/parallel/ui/ParallelAxesLayer.js.map +1 -1
- package/lib/parallel/ui/ParallelCoordinates.d.ts.map +1 -1
- package/lib/parallel/ui/ParallelCoordinates.js +10 -5
- package/lib/parallel/ui/ParallelCoordinates.js.map +1 -1
- package/lib/parallel/ui/ParallelLabels.d.ts +6 -0
- package/lib/parallel/ui/ParallelLabels.d.ts.map +1 -1
- package/lib/parallel/ui/ParallelLabels.js +14 -2
- package/lib/parallel/ui/ParallelLabels.js.map +1 -1
- package/lib/parallel/ui/index.d.ts +4 -0
- package/lib/parallel/ui/index.d.ts.map +1 -1
- package/lib/parallel/ui/index.js +2 -0
- package/lib/parallel/ui/index.js.map +1 -1
- package/lib/parallel/ui/parallelCoordinatesProps.d.ts +26 -8
- package/lib/parallel/ui/parallelCoordinatesProps.d.ts.map +1 -1
- package/lib/parallel/ui/parallelGestureModel.d.ts +37 -6
- package/lib/parallel/ui/parallelGestureModel.d.ts.map +1 -1
- package/lib/parallel/ui/parallelGestureModel.js +42 -12
- package/lib/parallel/ui/parallelGestureModel.js.map +1 -1
- package/lib/parallel/ui/parallelPlotModel.d.ts +1 -1
- package/lib/parallel/ui/parallelPlotModel.d.ts.map +1 -1
- package/lib/parallel/ui/parallelPlotModel.js +3 -3
- package/lib/parallel/ui/parallelPlotModel.js.map +1 -1
- package/lib/parallel/ui/parallelStyles.d.ts +26 -3
- package/lib/parallel/ui/parallelStyles.d.ts.map +1 -1
- package/lib/parallel/ui/parallelStyles.js +26 -4
- package/lib/parallel/ui/parallelStyles.js.map +1 -1
- package/lib/parallel/ui/useParallelAxisDrag.d.ts +60 -0
- package/lib/parallel/ui/useParallelAxisDrag.d.ts.map +1 -0
- package/lib/parallel/ui/useParallelAxisDrag.js +96 -0
- package/lib/parallel/ui/useParallelAxisDrag.js.map +1 -0
- package/lib/parallel/ui/useParallelGesture.d.ts +10 -5
- package/lib/parallel/ui/useParallelGesture.d.ts.map +1 -1
- package/lib/parallel/ui/useParallelGesture.js +46 -21
- package/lib/parallel/ui/useParallelGesture.js.map +1 -1
- 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/parallel/core/index.ts +16 -0
- package/src/parallel/core/parallelBrush.ts +69 -3
- package/src/parallel/core/parallelFilter.ts +52 -15
- package/src/parallel/core/parallelOrder.ts +73 -0
- package/src/parallel/core/parallelPaint.ts +16 -5
- package/src/parallel/core/parallelPalette.ts +14 -1
- package/src/parallel/core/parallelSelection.ts +99 -0
- package/src/parallel/core/parallelTicks.ts +7 -3
- package/src/parallel/core/parallelTypes.ts +13 -1
- package/src/parallel/ui/ParallelAxesLayer.tsx +10 -4
- package/src/parallel/ui/ParallelCoordinates.tsx +22 -3
- package/src/parallel/ui/ParallelLabels.tsx +23 -2
- package/src/parallel/ui/index.ts +15 -0
- package/src/parallel/ui/parallelCoordinatesProps.ts +26 -8
- package/src/parallel/ui/parallelGestureModel.ts +63 -13
- package/src/parallel/ui/parallelPlotModel.ts +3 -3
- package/src/parallel/ui/parallelStyles.ts +46 -4
- package/src/parallel/ui/useParallelAxisDrag.ts +147 -0
- package/src/parallel/ui/useParallelGesture.ts +61 -28
- 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,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the keyboard and the mouse do in the openchemlib canvas editor, beyond
|
|
3
|
+
* what its toolbar shows: the keys that change the atom or the bond under the
|
|
4
|
+
* pointer, the selection gestures and the stereo conventions.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** A key, drawn as a key cap. `Mod` is ⌘ on a Mac and Ctrl elsewhere. */
|
|
8
|
+
export interface EditorGuideKey {
|
|
9
|
+
key: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Which editors a gesture applies to. */
|
|
13
|
+
export type EditorGuideScope = 'fragment' | 'molecule' | 'reaction';
|
|
14
|
+
|
|
15
|
+
/** One gesture and what it does. */
|
|
16
|
+
export interface EditorGesture {
|
|
17
|
+
/** Keys, and plain text for the mouse part; unique within one gesture. */
|
|
18
|
+
input: ReadonlyArray<string | EditorGuideKey>;
|
|
19
|
+
action: string;
|
|
20
|
+
/**
|
|
21
|
+
* The only editor the gesture works in.
|
|
22
|
+
* @default undefined — every editor
|
|
23
|
+
*/
|
|
24
|
+
only?: EditorGuideScope;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Gestures that share a context, such as the pointer resting on an atom. */
|
|
28
|
+
export interface EditorGuideSection {
|
|
29
|
+
title: string;
|
|
30
|
+
gestures: readonly EditorGesture[];
|
|
31
|
+
/**
|
|
32
|
+
* A sentence read after the gestures.
|
|
33
|
+
* @default undefined
|
|
34
|
+
*/
|
|
35
|
+
note?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A page of the full documentation. */
|
|
39
|
+
export interface EditorGuideLink {
|
|
40
|
+
title: string;
|
|
41
|
+
url: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The sections, in the order the guide lists them. */
|
|
45
|
+
export const STRUCTURE_EDITOR_GUIDE: readonly EditorGuideSection[] = [
|
|
46
|
+
{
|
|
47
|
+
title: 'Pointer on an atom',
|
|
48
|
+
gestures: [
|
|
49
|
+
{ input: ['Type', { key: 'n' }, { key: 'a' }], action: 'Make it Na' },
|
|
50
|
+
{
|
|
51
|
+
input: ['Type', { key: 'p' }, { key: 'h' }],
|
|
52
|
+
action: 'Attach a phenyl; Me, Et, Boc, TMS… work too',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
input: [{ key: 'Enter' }, 'or', { key: 'Esc' }],
|
|
56
|
+
action: 'Apply or forget what was typed',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
input: [{ key: '1' }, '…', { key: '9' }],
|
|
60
|
+
action: 'Attach a chain of that many carbons',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
input: [{ key: '+' }, 'or', { key: '-' }],
|
|
64
|
+
action: 'Raise or lower the charge',
|
|
65
|
+
},
|
|
66
|
+
{ input: [{ key: '.' }], action: 'Add or remove a radical' },
|
|
67
|
+
{ input: [{ key: ':' }], action: 'Make it a triplet, then a singlet' },
|
|
68
|
+
{ input: [{ key: '?' }], action: 'Make it a connection point' },
|
|
69
|
+
{
|
|
70
|
+
input: [{ key: 'q' }],
|
|
71
|
+
action: 'Edit its query features',
|
|
72
|
+
only: 'fragment',
|
|
73
|
+
},
|
|
74
|
+
{ input: [{ key: 'x' }], action: 'Accept any halogen', only: 'fragment' },
|
|
75
|
+
{ input: [{ key: 'Delete' }], action: 'Delete it' },
|
|
76
|
+
],
|
|
77
|
+
note: 'What is typed shows black for an element, blue for a group, grey while incomplete and red when unknown.',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
title: 'Pointer on a bond',
|
|
81
|
+
gestures: [
|
|
82
|
+
{
|
|
83
|
+
input: [{ key: '1' }, { key: '2' }, { key: '3' }],
|
|
84
|
+
action: 'Single, double or triple',
|
|
85
|
+
},
|
|
86
|
+
{ input: [{ key: '0' }], action: 'Zero-order (metal–ligand) bond' },
|
|
87
|
+
{
|
|
88
|
+
input: [{ key: 'u' }, 'or', { key: 'd' }],
|
|
89
|
+
action: 'Up or down stereo bond',
|
|
90
|
+
},
|
|
91
|
+
{ input: [{ key: 'c' }], action: 'Double bond of unknown geometry' },
|
|
92
|
+
{ input: [{ key: 'v' }], action: 'Fuse a 3-membered ring' },
|
|
93
|
+
{
|
|
94
|
+
input: [{ key: '4' }, '…', { key: '7' }],
|
|
95
|
+
action: 'Fuse a ring of that size',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
input: [{ key: 'a' }, 'or', { key: 'b' }],
|
|
99
|
+
action: 'Fuse a benzene ring',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
input: [{ key: 'q' }],
|
|
103
|
+
action: 'Edit its query features',
|
|
104
|
+
only: 'fragment',
|
|
105
|
+
},
|
|
106
|
+
{ input: [{ key: 'Delete' }], action: 'Delete it' },
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
title: 'Anywhere',
|
|
111
|
+
gestures: [
|
|
112
|
+
{ input: [{ key: 'Mod' }, { key: 'Z' }], action: 'Undo' },
|
|
113
|
+
{ input: [{ key: 'Mod' }, { key: 'C' }], action: 'Copy the structure' },
|
|
114
|
+
{
|
|
115
|
+
input: [{ key: 'Mod' }, { key: 'V' }],
|
|
116
|
+
action: 'Paste a molfile, a SMILES or an idCode',
|
|
117
|
+
},
|
|
118
|
+
{ input: [{ key: 'Delete' }], action: 'Delete the selection' },
|
|
119
|
+
{
|
|
120
|
+
input: [{ key: 'h' }, 'or', { key: 'v' }],
|
|
121
|
+
action: 'Flip horizontally or vertically',
|
|
122
|
+
only: 'molecule',
|
|
123
|
+
},
|
|
124
|
+
{ input: [{ key: 'F1' }], action: 'Open this guide' },
|
|
125
|
+
],
|
|
126
|
+
note: 'Keys act once the drawing has been clicked. On empty canvas, a key picks the tool whose tooltip shows it.',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
title: 'Selecting',
|
|
130
|
+
gestures: [
|
|
131
|
+
{ input: ['Drag'], action: 'Select what the lasso encloses' },
|
|
132
|
+
{ input: [{ key: 'Alt' }, '+ drag'], action: 'Select a rectangle' },
|
|
133
|
+
{ input: [{ key: 'Shift' }, '+ drag'], action: 'Add to the selection' },
|
|
134
|
+
{ input: ['Drag the selection'], action: 'Move it' },
|
|
135
|
+
{
|
|
136
|
+
input: [{ key: 'Shift' }, '+ drag the selection'],
|
|
137
|
+
action: 'Copy it',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
input: ['Double-click'],
|
|
141
|
+
action: 'Edit the query features of an atom, a bond or the selection',
|
|
142
|
+
only: 'fragment',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
note: 'These need the Select tool, which Space picks.',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
title: 'Stereochemistry',
|
|
149
|
+
gestures: [],
|
|
150
|
+
note: 'Pink bonds flag a stereocentre with too little or too much information. Draw an up or down bond with its narrow end on the centre, then use the enhanced stereo tool to say whether the drawing is this enantiomer (abs), both of them (&) or one of the two (or).',
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
/** The documentation this guide summarises. */
|
|
155
|
+
export const STRUCTURE_EDITOR_DOCS: readonly EditorGuideLink[] = [
|
|
156
|
+
{ title: 'Tools and keys', url: 'https://docs.nmrium.org/help/ocl/' },
|
|
157
|
+
{
|
|
158
|
+
title: 'Atom properties',
|
|
159
|
+
url: 'https://docs.nmrium.org/chemical_structure/ocl/atom-properties/',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
title: 'Stereochemistry',
|
|
163
|
+
url: 'https://docs.nmrium.org/ocl/stereochemistry/',
|
|
164
|
+
},
|
|
165
|
+
];
|
|
166
|
+
|
|
167
|
+
/** The editor a guide is written for. */
|
|
168
|
+
export interface EditorGuideOptions {
|
|
169
|
+
/**
|
|
170
|
+
* Whether the editor draws one structure or a reaction.
|
|
171
|
+
* @default 'molecule'
|
|
172
|
+
*/
|
|
173
|
+
mode?: 'molecule' | 'reaction';
|
|
174
|
+
/**
|
|
175
|
+
* Whether the editor draws a query fragment.
|
|
176
|
+
* @default false
|
|
177
|
+
*/
|
|
178
|
+
fragment?: boolean;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The guide for one editor: gestures that do nothing there are left out, and so
|
|
183
|
+
* is a section left with nothing to say.
|
|
184
|
+
* @param options - The editor the guide is for.
|
|
185
|
+
* @returns The sections to show.
|
|
186
|
+
*/
|
|
187
|
+
export function editorGuideSections(
|
|
188
|
+
options: EditorGuideOptions = {},
|
|
189
|
+
): EditorGuideSection[] {
|
|
190
|
+
const { mode = 'molecule', fragment = false } = options;
|
|
191
|
+
const sections: EditorGuideSection[] = [];
|
|
192
|
+
for (const section of STRUCTURE_EDITOR_GUIDE) {
|
|
193
|
+
const gestures = section.gestures.filter(({ only }) =>
|
|
194
|
+
appliesTo(only, mode, fragment),
|
|
195
|
+
);
|
|
196
|
+
if (gestures.length === 0 && section.note === undefined) continue;
|
|
197
|
+
sections.push({ ...section, gestures });
|
|
198
|
+
}
|
|
199
|
+
return sections;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function appliesTo(
|
|
203
|
+
only: EditorGuideScope | undefined,
|
|
204
|
+
mode: 'molecule' | 'reaction',
|
|
205
|
+
fragment: boolean,
|
|
206
|
+
): boolean {
|
|
207
|
+
if (only === undefined) return true;
|
|
208
|
+
if (only === 'fragment') return fragment;
|
|
209
|
+
return only === mode;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* The text of a key cap.
|
|
214
|
+
* @param key - The key, `Mod` standing for the platform's shortcut modifier.
|
|
215
|
+
* @param isMac - Whether the page runs on a Mac.
|
|
216
|
+
* @returns What the cap shows.
|
|
217
|
+
*/
|
|
218
|
+
export function editorKeyLabel(key: string, isMac: boolean): string {
|
|
219
|
+
if (key !== 'Mod') return key;
|
|
220
|
+
return isMac ? '⌘' : 'Ctrl';
|
|
221
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each button of the openchemlib canvas editor's toolbar does.
|
|
3
|
+
*
|
|
4
|
+
* The toolbar is one canvas painted from a sprite, so there is no element per
|
|
5
|
+
* button to carry a title: the button under the pointer is found from where
|
|
6
|
+
* the pointer is (see `editorToolbarGeometry.ts`) and its entry here is what
|
|
7
|
+
* the tooltip says.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Which editor a button works in. The reaction-only button is drawn greyed in
|
|
12
|
+
* a molecule editor, and the text tool is greyed in every editor react-ocl
|
|
13
|
+
* builds, since neither enables drawing objects.
|
|
14
|
+
*/
|
|
15
|
+
export type EditorToolbarAvailability = 'always' | 'reaction' | 'never';
|
|
16
|
+
|
|
17
|
+
/** One button of the toolbar. */
|
|
18
|
+
export interface EditorToolbarButton {
|
|
19
|
+
/** What the button is called. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** What it does, in a sentence or two. */
|
|
22
|
+
description: string;
|
|
23
|
+
/**
|
|
24
|
+
* Keys that pick the tool, pressed while the pointer is over empty canvas.
|
|
25
|
+
* `Mod` stands for ⌘ on a Mac and Ctrl elsewhere.
|
|
26
|
+
* @default undefined — no key
|
|
27
|
+
*/
|
|
28
|
+
keys?: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Which editor the button works in.
|
|
31
|
+
* @default 'always'
|
|
32
|
+
*/
|
|
33
|
+
availability?: EditorToolbarAvailability;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The buttons, in the order the toolbar numbers them: down the first column,
|
|
38
|
+
* then down the second.
|
|
39
|
+
*/
|
|
40
|
+
export const EDITOR_TOOLBAR_BUTTONS: readonly EditorToolbarButton[] = [
|
|
41
|
+
{ name: 'Clear', description: 'Erase the whole drawing.' },
|
|
42
|
+
{
|
|
43
|
+
name: 'Clean up',
|
|
44
|
+
description:
|
|
45
|
+
'Redraw the structure with fresh 2D coordinates. With part of it selected, the rest keeps its layout.',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'Select',
|
|
49
|
+
description:
|
|
50
|
+
'Drag around atoms to select them: hold Alt for a rectangle, Shift to add to the selection. Drag a selection to move it, Shift-drag to copy it.',
|
|
51
|
+
keys: ['Space'],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'Unknown configuration',
|
|
55
|
+
description:
|
|
56
|
+
'Click a stereocentre to mark its configuration as unknown; click again to undo it.',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Delete',
|
|
60
|
+
description: 'Click an atom or a bond to delete it.',
|
|
61
|
+
keys: ['0'],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'Single bond',
|
|
65
|
+
description:
|
|
66
|
+
'Click empty space for a new bond, or drag from an atom. Clicking a bond again makes it double, then triple.',
|
|
67
|
+
keys: ['1'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'Up bond',
|
|
71
|
+
description:
|
|
72
|
+
'Wedged stereo bond, pointing toward the viewer. Its narrow end goes on the stereocentre.',
|
|
73
|
+
keys: ['u'],
|
|
74
|
+
},
|
|
75
|
+
ring('3-membered ring', '3'),
|
|
76
|
+
ring('5-membered ring', '5'),
|
|
77
|
+
ring('7-membered ring', '7'),
|
|
78
|
+
{
|
|
79
|
+
name: 'Positive charge',
|
|
80
|
+
description: 'Click an atom to raise its charge by one.',
|
|
81
|
+
keys: ['+'],
|
|
82
|
+
},
|
|
83
|
+
atom('Carbon', 'C', 'c'),
|
|
84
|
+
atom('Nitrogen', 'N', 'n'),
|
|
85
|
+
atom('Oxygen', 'O', 'o'),
|
|
86
|
+
atom('Fluorine', 'F', 'f'),
|
|
87
|
+
atom('Bromine', 'Br', 'b'),
|
|
88
|
+
atom('Hydrogen', 'H'),
|
|
89
|
+
{ name: 'Undo', description: 'Revert the last change.', keys: ['Mod', 'Z'] },
|
|
90
|
+
{
|
|
91
|
+
name: 'Zoom and rotate',
|
|
92
|
+
description:
|
|
93
|
+
'Press where the centre should be, then drag up or down to zoom and sideways to rotate. With a selection, only that part moves.',
|
|
94
|
+
keys: ['z'],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Atom mapping',
|
|
98
|
+
description:
|
|
99
|
+
'Drag from a reactant atom to the same atom in a product: both get the same number. Click a mapped atom to unmap it.',
|
|
100
|
+
keys: ['m'],
|
|
101
|
+
availability: 'reaction',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'Enhanced stereo',
|
|
105
|
+
description:
|
|
106
|
+
'Click a stereo bond to say what its centre means: abs, this enantiomer; &, both (racemic); or, one of the two. Press the button again to switch between the three.',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'Text',
|
|
110
|
+
description: 'Place a text label in the drawing.',
|
|
111
|
+
availability: 'never',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'Chain',
|
|
115
|
+
description:
|
|
116
|
+
'Drag from empty space or from an atom to draw a zigzag carbon chain.',
|
|
117
|
+
keys: ['2'],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'Down bond',
|
|
121
|
+
description:
|
|
122
|
+
'Hashed stereo bond, pointing away from the viewer. Its narrow end goes on the stereocentre.',
|
|
123
|
+
keys: ['d'],
|
|
124
|
+
},
|
|
125
|
+
ring('4-membered ring', '4'),
|
|
126
|
+
ring('6-membered ring', '6'),
|
|
127
|
+
ring('Benzene ring', 'a'),
|
|
128
|
+
{
|
|
129
|
+
name: 'Negative charge',
|
|
130
|
+
description: 'Click an atom to lower its charge by one.',
|
|
131
|
+
keys: ['-'],
|
|
132
|
+
},
|
|
133
|
+
atom('Silicon', 'Si'),
|
|
134
|
+
atom('Phosphorus', 'P', 'p'),
|
|
135
|
+
atom('Sulfur', 'S', 's'),
|
|
136
|
+
atom('Chlorine', 'Cl', 'l'),
|
|
137
|
+
atom('Iodine', 'I', 'i'),
|
|
138
|
+
{
|
|
139
|
+
name: 'Any atom',
|
|
140
|
+
description:
|
|
141
|
+
'Pick any element, isotope, valence or radical in a dialog, then click to place it or to change an atom. Alt-click an atom to edit its own properties.',
|
|
142
|
+
keys: ['.'],
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Whether a button can be used in an editor of the given kind.
|
|
148
|
+
* @param button - The button.
|
|
149
|
+
* @param mode - The kind of editor.
|
|
150
|
+
* @returns True when pressing the button selects its tool.
|
|
151
|
+
*/
|
|
152
|
+
export function isEditorToolbarButtonAvailable(
|
|
153
|
+
button: EditorToolbarButton,
|
|
154
|
+
mode: 'molecule' | 'reaction',
|
|
155
|
+
): boolean {
|
|
156
|
+
const { availability = 'always' } = button;
|
|
157
|
+
if (availability === 'always') return true;
|
|
158
|
+
return availability === 'reaction' && mode === 'reaction';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function ring(name: string, key: string): EditorToolbarButton {
|
|
162
|
+
return {
|
|
163
|
+
name,
|
|
164
|
+
description:
|
|
165
|
+
'Click empty space for a new ring, a bond to fuse one onto it, or an atom for a spiro ring.',
|
|
166
|
+
keys: [key],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function atom(name: string, symbol: string, key?: string): EditorToolbarButton {
|
|
171
|
+
const description = `Click empty space for a new ${symbol} atom, or an atom to turn it into ${symbol}.`;
|
|
172
|
+
return key === undefined
|
|
173
|
+
? { name, description }
|
|
174
|
+
: { name, description, keys: [key] };
|
|
175
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the openchemlib editor draws each toolbar button.
|
|
3
|
+
*
|
|
4
|
+
* The toolbar is two columns of seventeen square buttons inside a thin border,
|
|
5
|
+
* numbered down the first column and then down the second, as
|
|
6
|
+
* `EDITOR_TOOLBAR_BUTTONS` lists them. Every length here is in CSS pixels at
|
|
7
|
+
* the size openchemlib draws the toolbar, and is scaled by the height the
|
|
8
|
+
* toolbar is measured at, so a toolbar drawn larger still maps correctly.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Buttons in one column of the toolbar. */
|
|
12
|
+
export const EDITOR_TOOLBAR_ROWS = 17;
|
|
13
|
+
|
|
14
|
+
/** Columns of the toolbar. */
|
|
15
|
+
export const EDITOR_TOOLBAR_COLUMNS = 2;
|
|
16
|
+
|
|
17
|
+
/** Side of one button, in CSS pixels. */
|
|
18
|
+
const BUTTON_SIZE = 21;
|
|
19
|
+
|
|
20
|
+
/** Border around the buttons, in CSS pixels. */
|
|
21
|
+
const BORDER = 2;
|
|
22
|
+
|
|
23
|
+
/** Height of the toolbar as openchemlib draws it, in CSS pixels. */
|
|
24
|
+
const DRAWN_HEIGHT = EDITOR_TOOLBAR_ROWS * BUTTON_SIZE + 2 * BORDER;
|
|
25
|
+
|
|
26
|
+
/** Where a button is drawn, in CSS pixels from the toolbar's top left corner. */
|
|
27
|
+
export interface EditorToolbarButtonBox {
|
|
28
|
+
left: number;
|
|
29
|
+
top: number;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The button under a point of the toolbar.
|
|
36
|
+
* @param x - Distance from the toolbar's left edge, in CSS pixels.
|
|
37
|
+
* @param y - Distance from the toolbar's top edge, in CSS pixels.
|
|
38
|
+
* @param toolbarHeight - Height the toolbar is measured at, in CSS pixels.
|
|
39
|
+
* @returns The button's index, or -1 when the point is on no button.
|
|
40
|
+
*/
|
|
41
|
+
export function editorToolbarButtonAt(
|
|
42
|
+
x: number,
|
|
43
|
+
y: number,
|
|
44
|
+
toolbarHeight: number,
|
|
45
|
+
): number {
|
|
46
|
+
const scale = scaleOf(toolbarHeight);
|
|
47
|
+
if (scale === 0) return -1;
|
|
48
|
+
const column = Math.floor((x / scale - BORDER) / BUTTON_SIZE);
|
|
49
|
+
const row = Math.floor((y / scale - BORDER) / BUTTON_SIZE);
|
|
50
|
+
if (column < 0 || column >= EDITOR_TOOLBAR_COLUMNS) return -1;
|
|
51
|
+
if (row < 0 || row >= EDITOR_TOOLBAR_ROWS) return -1;
|
|
52
|
+
return column * EDITOR_TOOLBAR_ROWS + row;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Where a button is drawn.
|
|
57
|
+
* @param button - The button's index.
|
|
58
|
+
* @param toolbarHeight - Height the toolbar is measured at, in CSS pixels.
|
|
59
|
+
* @returns The button's box, relative to the toolbar.
|
|
60
|
+
*/
|
|
61
|
+
export function editorToolbarButtonBox(
|
|
62
|
+
button: number,
|
|
63
|
+
toolbarHeight: number,
|
|
64
|
+
): EditorToolbarButtonBox {
|
|
65
|
+
const scale = scaleOf(toolbarHeight);
|
|
66
|
+
const column = Math.floor(button / EDITOR_TOOLBAR_ROWS);
|
|
67
|
+
const row = button % EDITOR_TOOLBAR_ROWS;
|
|
68
|
+
return {
|
|
69
|
+
left: (BORDER + column * BUTTON_SIZE) * scale,
|
|
70
|
+
top: (BORDER + row * BUTTON_SIZE) * scale,
|
|
71
|
+
width: BUTTON_SIZE * scale,
|
|
72
|
+
height: BUTTON_SIZE * scale,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function scaleOf(toolbarHeight: number): number {
|
|
77
|
+
return Number.isFinite(toolbarHeight) && toolbarHeight > 0
|
|
78
|
+
? toolbarHeight / DRAWN_HEIGHT
|
|
79
|
+
: 0;
|
|
80
|
+
}
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
export type { AtomLabelPlacement, LabelledMolecule } from './atomLabels.ts';
|
|
2
2
|
export { applyAtomLabels, customAtomLabel } from './atomLabels.ts';
|
|
3
|
+
export type {
|
|
4
|
+
EditorGesture,
|
|
5
|
+
EditorGuideKey,
|
|
6
|
+
EditorGuideLink,
|
|
7
|
+
EditorGuideOptions,
|
|
8
|
+
EditorGuideScope,
|
|
9
|
+
EditorGuideSection,
|
|
10
|
+
} from './editorGuide.ts';
|
|
11
|
+
export {
|
|
12
|
+
STRUCTURE_EDITOR_DOCS,
|
|
13
|
+
STRUCTURE_EDITOR_GUIDE,
|
|
14
|
+
editorGuideSections,
|
|
15
|
+
editorKeyLabel,
|
|
16
|
+
} from './editorGuide.ts';
|
|
17
|
+
export type {
|
|
18
|
+
EditorToolbarAvailability,
|
|
19
|
+
EditorToolbarButton,
|
|
20
|
+
} from './editorToolbar.ts';
|
|
21
|
+
export {
|
|
22
|
+
EDITOR_TOOLBAR_BUTTONS,
|
|
23
|
+
isEditorToolbarButtonAvailable,
|
|
24
|
+
} from './editorToolbar.ts';
|
|
25
|
+
export type { EditorToolbarButtonBox } from './editorToolbarGeometry.ts';
|
|
26
|
+
export {
|
|
27
|
+
EDITOR_TOOLBAR_COLUMNS,
|
|
28
|
+
EDITOR_TOOLBAR_ROWS,
|
|
29
|
+
editorToolbarButtonAt,
|
|
30
|
+
editorToolbarButtonBox,
|
|
31
|
+
} from './editorToolbarGeometry.ts';
|
|
3
32
|
export type { EditorLine, EditorValue } from './editorValue.ts';
|
|
4
33
|
export type { IdCodeValue } from './editorValue.ts';
|
|
5
34
|
export { isEmptyIdCode, splitEditorValue, splitIdCode } from './editorValue.ts';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** A call held back until its value has been still, which can be cut short. */
|
|
2
|
+
export interface PendingCall<TValue> {
|
|
3
|
+
/**
|
|
4
|
+
* Hold a value back, replacing whichever one was waiting.
|
|
5
|
+
* @param value - The value to deliver.
|
|
6
|
+
* @param delay - How long to wait, in milliseconds; `0` or less delivers now.
|
|
7
|
+
* @param deliver - What the value is handed to.
|
|
8
|
+
*/
|
|
9
|
+
push: (
|
|
10
|
+
value: TValue,
|
|
11
|
+
delay: number,
|
|
12
|
+
deliver: (value: TValue) => void,
|
|
13
|
+
) => void;
|
|
14
|
+
/** Forget the value waiting, which is then never delivered. */
|
|
15
|
+
drop: () => void;
|
|
16
|
+
/** Deliver the value waiting now rather than when its delay runs out. */
|
|
17
|
+
flush: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A trailing debounce for one value at a time, whose waiting value can be
|
|
22
|
+
* delivered early or thrown away.
|
|
23
|
+
* @returns The pending call, holding nothing.
|
|
24
|
+
*/
|
|
25
|
+
export function createPendingCall<TValue>(): PendingCall<TValue> {
|
|
26
|
+
let pending: {
|
|
27
|
+
value: TValue;
|
|
28
|
+
deliver: (value: TValue) => void;
|
|
29
|
+
timer: ReturnType<typeof setTimeout>;
|
|
30
|
+
} | null = null;
|
|
31
|
+
|
|
32
|
+
function drop(): void {
|
|
33
|
+
if (pending === null) return;
|
|
34
|
+
clearTimeout(pending.timer);
|
|
35
|
+
pending = null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
push(value, delay, deliver) {
|
|
40
|
+
drop();
|
|
41
|
+
if (delay <= 0) {
|
|
42
|
+
deliver(value);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
pending = null;
|
|
47
|
+
deliver(value);
|
|
48
|
+
}, delay);
|
|
49
|
+
pending = { value, deliver, timer };
|
|
50
|
+
},
|
|
51
|
+
drop,
|
|
52
|
+
flush() {
|
|
53
|
+
if (pending === null) return;
|
|
54
|
+
const { value, deliver } = pending;
|
|
55
|
+
drop();
|
|
56
|
+
deliver(value);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -7,23 +7,11 @@ import type {
|
|
|
7
7
|
} from 'react-ocl';
|
|
8
8
|
import { CanvasMoleculeEditor, CanvasReactionEditor } from 'react-ocl';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** Which kind of editor produced it. */
|
|
16
|
-
mode: StructureEditorMode;
|
|
17
|
-
/**
|
|
18
|
-
* The idCode, with the coordinates the editor laid out written after a
|
|
19
|
-
* space. `splitIdCode` takes the two apart.
|
|
20
|
-
*/
|
|
21
|
-
idCode: string;
|
|
22
|
-
/** The V2000 molfile of a molecule, or the RXN file of a reaction. */
|
|
23
|
-
molfile: string;
|
|
24
|
-
/** The SMILES of a molecule, or the reaction SMILES. */
|
|
25
|
-
smiles: string;
|
|
26
|
-
}
|
|
10
|
+
import type {
|
|
11
|
+
StructureEditorChange,
|
|
12
|
+
StructureEditorMode,
|
|
13
|
+
} from './editorChange.ts';
|
|
14
|
+
import { moleculeChange, reactionChange } from './editorChange.ts';
|
|
27
15
|
|
|
28
16
|
interface EditorCanvasProps {
|
|
29
17
|
/** Called on every stroke, with the editor read out synchronously. */
|
|
@@ -71,29 +59,15 @@ export function EditorCanvas(props: EditorCanvasProps): ReactElement {
|
|
|
71
59
|
} = props;
|
|
72
60
|
const [initialValue] = useState(value);
|
|
73
61
|
|
|
62
|
+
// The event describes the editor only while the callback runs, so it is read
|
|
63
|
+
// out now and whatever waiting there is happens afterwards.
|
|
74
64
|
const handleMolecule = useCallback(
|
|
75
|
-
(event: CanvasEditorOnChangeMolecule) =>
|
|
76
|
-
// The event describes the editor only while the callback runs, so every
|
|
77
|
-
// notation is read now and whatever waiting there is happens afterwards.
|
|
78
|
-
onChange({
|
|
79
|
-
mode: 'molecule',
|
|
80
|
-
idCode: event.getIdcode(),
|
|
81
|
-
molfile: event.getMolfile(),
|
|
82
|
-
smiles: event.getSmiles(),
|
|
83
|
-
});
|
|
84
|
-
},
|
|
65
|
+
(event: CanvasEditorOnChangeMolecule) => onChange(moleculeChange(event)),
|
|
85
66
|
[onChange],
|
|
86
67
|
);
|
|
87
68
|
|
|
88
69
|
const handleReaction = useCallback(
|
|
89
|
-
(event: CanvasEditorOnChangeReaction) =>
|
|
90
|
-
onChange({
|
|
91
|
-
mode: 'reaction',
|
|
92
|
-
idCode: event.getIdcode(),
|
|
93
|
-
molfile: event.getRxn(),
|
|
94
|
-
smiles: event.getSmiles(),
|
|
95
|
-
});
|
|
96
|
-
},
|
|
70
|
+
(event: CanvasEditorOnChangeReaction) => onChange(reactionChange(event)),
|
|
97
71
|
[onChange],
|
|
98
72
|
);
|
|
99
73
|
|