react-cheminfo 0.31.0 → 0.33.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 +1 -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/i18n/core/chromeCatalog.d.ts +2 -2
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/i18n/core/chromeCatalog.js +10 -4
- package/lib/i18n/core/chromeCatalog.js.map +1 -1
- package/lib/i18n/core/index.d.ts +2 -0
- package/lib/i18n/core/index.d.ts.map +1 -1
- package/lib/i18n/core/index.js +1 -0
- package/lib/i18n/core/index.js.map +1 -1
- package/lib/i18n/core/languages.d.ts +4 -4
- package/lib/i18n/core/languages.d.ts.map +1 -1
- package/lib/i18n/core/languages.js +5 -4
- package/lib/i18n/core/languages.js.map +1 -1
- package/lib/i18n/core/prose.d.ts +32 -0
- package/lib/i18n/core/prose.d.ts.map +1 -0
- package/lib/i18n/core/prose.js +45 -0
- package/lib/i18n/core/prose.js.map +1 -0
- package/lib/i18n/ui/Prose.d.ts +28 -0
- package/lib/i18n/ui/Prose.d.ts.map +1 -0
- package/lib/i18n/ui/Prose.js +14 -0
- package/lib/i18n/ui/Prose.js.map +1 -0
- package/lib/i18n/ui/index.d.ts +2 -0
- package/lib/i18n/ui/index.d.ts.map +1 -1
- package/lib/i18n/ui/index.js +1 -0
- package/lib/i18n/ui/index.js.map +1 -1
- package/lib/locales/de.json +7 -1
- package/lib/locales/en.json +7 -1
- package/lib/locales/es.json +7 -1
- package/lib/locales/fr.json +7 -1
- package/lib/locales/it.json +459 -0
- package/lib/number/core/index.d.ts +2 -0
- package/lib/number/core/index.d.ts.map +1 -0
- package/lib/number/core/index.js +2 -0
- package/lib/number/core/index.js.map +1 -0
- package/lib/number/core/numberText.d.ts +46 -0
- package/lib/number/core/numberText.d.ts.map +1 -0
- package/lib/number/core/numberText.js +88 -0
- package/lib/number/core/numberText.js.map +1 -0
- package/lib/number/ui/NumberInput.d.ts +113 -0
- package/lib/number/ui/NumberInput.d.ts.map +1 -0
- package/lib/number/ui/NumberInput.js +100 -0
- package/lib/number/ui/NumberInput.js.map +1 -0
- package/lib/number/ui/index.d.ts +3 -0
- package/lib/number/ui/index.d.ts.map +1 -0
- package/lib/number/ui/index.js +2 -0
- package/lib/number/ui/index.js.map +1 -0
- package/lib/orbital/ui/AtomicOrbitalCanvas.d.ts +12 -2
- package/lib/orbital/ui/AtomicOrbitalCanvas.d.ts.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalCanvas.js +17 -3
- package/lib/orbital/ui/AtomicOrbitalCanvas.js.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalControls.d.ts +10 -5
- package/lib/orbital/ui/AtomicOrbitalControls.d.ts.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalControls.js +12 -7
- package/lib/orbital/ui/AtomicOrbitalControls.js.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalViewer.d.ts +8 -1
- package/lib/orbital/ui/AtomicOrbitalViewer.d.ts.map +1 -1
- package/lib/orbital/ui/AtomicOrbitalViewer.js.map +1 -1
- package/lib/periodic/ui/ElementCell.d.ts +10 -0
- package/lib/periodic/ui/ElementCell.d.ts.map +1 -1
- package/lib/periodic/ui/ElementCell.js +124 -14
- package/lib/periodic/ui/ElementCell.js.map +1 -1
- package/lib/periodic/ui/PeriodicTable.d.ts.map +1 -1
- package/lib/periodic/ui/PeriodicTable.js +46 -19
- package/lib/periodic/ui/PeriodicTable.js.map +1 -1
- package/lib/periodic/ui/PeriodicTableChrome.js +2 -2
- package/lib/periodic/ui/PeriodicTableChrome.js.map +1 -1
- package/lib/spectra/ui/NumberField.d.ts +2 -5
- package/lib/spectra/ui/NumberField.d.ts.map +1 -1
- package/lib/spectra/ui/NumberField.js +4 -54
- package/lib/spectra/ui/NumberField.js.map +1 -1
- 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/package.json +1 -1
- package/src/core.ts +1 -0
- package/src/i18n/core/chromeCatalog.ts +10 -4
- package/src/i18n/core/index.ts +2 -0
- package/src/i18n/core/languages.ts +5 -4
- package/src/i18n/core/prose.ts +53 -0
- package/src/i18n/ui/Prose.tsx +47 -0
- package/src/i18n/ui/index.ts +2 -0
- package/src/locales/de.json +7 -1
- package/src/locales/en.json +7 -1
- package/src/locales/es.json +7 -1
- package/src/locales/fr.json +7 -1
- package/src/locales/it.json +459 -0
- package/src/number/core/index.ts +6 -0
- package/src/number/core/numberText.ts +91 -0
- package/src/number/ui/NumberInput.tsx +300 -0
- package/src/number/ui/index.ts +7 -0
- package/src/orbital/ui/AtomicOrbitalCanvas.tsx +32 -5
- package/src/orbital/ui/AtomicOrbitalControls.tsx +26 -6
- package/src/orbital/ui/AtomicOrbitalViewer.tsx +8 -1
- package/src/periodic/ui/ElementCell.tsx +153 -14
- package/src/periodic/ui/PeriodicTable.tsx +51 -22
- package/src/periodic/ui/PeriodicTableChrome.tsx +2 -2
- package/src/spectra/ui/NumberField.tsx +11 -58
- package/src/ui.ts +1 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Button,
|
|
3
|
+
ButtonGroup,
|
|
4
|
+
Classes,
|
|
5
|
+
ControlGroup,
|
|
6
|
+
InputGroup,
|
|
7
|
+
} from '@blueprintjs/core';
|
|
8
|
+
import type { CSSProperties, KeyboardEvent, ReactElement } from 'react';
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
|
|
11
|
+
import { clamp } from '../../format/core/clamp.ts';
|
|
12
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
13
|
+
import {
|
|
14
|
+
isPartialNumber,
|
|
15
|
+
numberText,
|
|
16
|
+
readNumber,
|
|
17
|
+
stepNumber,
|
|
18
|
+
} from '../core/numberText.ts';
|
|
19
|
+
|
|
20
|
+
/** What every number box takes, whether or not it can be left empty. */
|
|
21
|
+
export interface NumberInputBaseProps {
|
|
22
|
+
/**
|
|
23
|
+
* Smallest accepted value, applied when the box is left rather than while it
|
|
24
|
+
* is typed in.
|
|
25
|
+
* @default undefined — unbounded below
|
|
26
|
+
*/
|
|
27
|
+
min?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Largest accepted value, applied when the box is left.
|
|
30
|
+
* @default undefined — unbounded above
|
|
31
|
+
*/
|
|
32
|
+
max?: number;
|
|
33
|
+
/**
|
|
34
|
+
* What one press of an arrow key or a stepper button adds; Shift multiplies
|
|
35
|
+
* it by ten and Alt divides it by ten.
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
step?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Whether only whole numbers are wanted. A typed decimal is rounded when the
|
|
41
|
+
* box is left.
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
integer?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the up and down buttons are drawn beside the box.
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
buttons?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Grey text shown while the box is empty.
|
|
52
|
+
* @default undefined — the box carries no placeholder
|
|
53
|
+
*/
|
|
54
|
+
placeholder?: string;
|
|
55
|
+
/** @default false */
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the control takes the whole width it is given.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
fill?: boolean;
|
|
62
|
+
/** @default 'medium' */
|
|
63
|
+
size?: 'small' | 'medium' | 'large';
|
|
64
|
+
/**
|
|
65
|
+
* Accessible name, for a box no `<label>` points at.
|
|
66
|
+
* @default undefined — the box is named by its label
|
|
67
|
+
*/
|
|
68
|
+
ariaLabel?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The box's id, for a `<label htmlFor>` elsewhere in the form.
|
|
71
|
+
* @default undefined
|
|
72
|
+
*/
|
|
73
|
+
id?: string;
|
|
74
|
+
/**
|
|
75
|
+
* A name a test finds the box by, written as `data-testid`.
|
|
76
|
+
* @default undefined
|
|
77
|
+
*/
|
|
78
|
+
testId?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Drawn inside the box at its left — a unit, a prefix such as `10⁻`.
|
|
81
|
+
* @default undefined
|
|
82
|
+
*/
|
|
83
|
+
leftElement?: ReactElement;
|
|
84
|
+
/**
|
|
85
|
+
* Drawn inside the box at its right — a unit, a small button.
|
|
86
|
+
* @default undefined
|
|
87
|
+
*/
|
|
88
|
+
rightElement?: ReactElement;
|
|
89
|
+
/** @default undefined */
|
|
90
|
+
className?: string;
|
|
91
|
+
/** @default undefined */
|
|
92
|
+
style?: CSSProperties;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** A box that always holds a number. */
|
|
96
|
+
export interface RequiredNumberInputProps extends NumberInputBaseProps {
|
|
97
|
+
/** The number the box shows. */
|
|
98
|
+
value: number;
|
|
99
|
+
/**
|
|
100
|
+
* Whether an emptied box hands up nothing. A required box keeps the number
|
|
101
|
+
* it had and shows it again when the box is left.
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
allowEmpty?: false;
|
|
105
|
+
/** Called with the new number, never while the text is half-typed. */
|
|
106
|
+
onChange: (value: number) => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A box that may be left empty, which hands up `undefined`. */
|
|
110
|
+
export interface OptionalNumberInputProps extends NumberInputBaseProps {
|
|
111
|
+
/** The number the box shows, or nothing when it is empty. */
|
|
112
|
+
value: number | undefined;
|
|
113
|
+
allowEmpty: true;
|
|
114
|
+
/** Called with the new number, or with `undefined` when the box is emptied. */
|
|
115
|
+
onChange: (value: number | undefined) => void;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** See {@link NumberInput}. */
|
|
119
|
+
export type NumberInputProps =
|
|
120
|
+
RequiredNumberInputProps | OptionalNumberInputProps;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A number typed into a box.
|
|
124
|
+
*
|
|
125
|
+
* The box keeps what was typed rather than what parsed. A reader halfway
|
|
126
|
+
* through `0.2` has typed `0.`, which reads as zero, and a box rendered from
|
|
127
|
+
* that number would write `0` back over the dot before the `2` arrives —
|
|
128
|
+
* which is why Blueprint's `NumericInput` cannot be given a number to show and
|
|
129
|
+
* is never used directly on our sites. Nothing is handed up until the text
|
|
130
|
+
* reads as a number, so a calculation never sees a half-typed value, and the
|
|
131
|
+
* bounds are applied when the box is left rather than under the caret.
|
|
132
|
+
* @param props - See {@link NumberInputProps}.
|
|
133
|
+
* @returns The box, with its stepper buttons unless they are turned off.
|
|
134
|
+
*/
|
|
135
|
+
export function NumberInput(props: NumberInputProps): ReactElement {
|
|
136
|
+
const {
|
|
137
|
+
value,
|
|
138
|
+
min,
|
|
139
|
+
max,
|
|
140
|
+
step = 1,
|
|
141
|
+
integer = false,
|
|
142
|
+
allowEmpty = false,
|
|
143
|
+
buttons = true,
|
|
144
|
+
placeholder,
|
|
145
|
+
disabled = false,
|
|
146
|
+
fill = false,
|
|
147
|
+
size = 'medium',
|
|
148
|
+
ariaLabel,
|
|
149
|
+
id,
|
|
150
|
+
testId,
|
|
151
|
+
leftElement,
|
|
152
|
+
rightElement,
|
|
153
|
+
className,
|
|
154
|
+
style,
|
|
155
|
+
} = props;
|
|
156
|
+
const t = useChromeT();
|
|
157
|
+
const onChange = props.onChange as (next: number | undefined) => void;
|
|
158
|
+
const [draft, setDraft] = useState(() => ({
|
|
159
|
+
text: numberText(value),
|
|
160
|
+
held: value,
|
|
161
|
+
}));
|
|
162
|
+
|
|
163
|
+
// The number changed elsewhere — a preset, a reset, a link — so the box has
|
|
164
|
+
// to follow. `held` is what this box last handed up, not the prop it was
|
|
165
|
+
// rendered with: comparing against the prop would make the box's own edit
|
|
166
|
+
// look external and rewrite `-0.` as `0` under the caret.
|
|
167
|
+
if (draft.held !== value) setDraft({ text: numberText(value), held: value });
|
|
168
|
+
|
|
169
|
+
function hold(text: string, held: number | undefined) {
|
|
170
|
+
setDraft({ text, held });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function commit(next: number) {
|
|
174
|
+
hold(numberText(next), next);
|
|
175
|
+
onChange(next);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function type(text: string) {
|
|
179
|
+
const emptied = text.trim() === '';
|
|
180
|
+
const parsed = readNumber(text, integer);
|
|
181
|
+
hold(text, emptied && allowEmpty ? undefined : (parsed ?? value));
|
|
182
|
+
if (emptied) {
|
|
183
|
+
if (allowEmpty) onChange(undefined);
|
|
184
|
+
} else if (parsed !== undefined) {
|
|
185
|
+
onChange(parsed);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function leave() {
|
|
190
|
+
if (draft.text.trim() === '') {
|
|
191
|
+
if (!allowEmpty) hold(numberText(value), value);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const parsed = readNumber(draft.text);
|
|
195
|
+
if (parsed === undefined) {
|
|
196
|
+
hold(numberText(value), value);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const settled = settle(parsed, integer, min, max);
|
|
200
|
+
if (settled !== parsed || !Object.is(settled, value)) commit(settled);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function press(event: KeyboardEvent<HTMLInputElement>) {
|
|
204
|
+
const direction =
|
|
205
|
+
event.key === 'ArrowUp' ? 1 : event.key === 'ArrowDown' ? -1 : 0;
|
|
206
|
+
if (direction === 0 || disabled) return;
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
const scale = event.shiftKey ? 10 : event.altKey ? 0.1 : 1;
|
|
209
|
+
move(direction * scale);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function move(scale: number) {
|
|
213
|
+
const from = readNumber(draft.text) ?? value ?? 0;
|
|
214
|
+
commit(settle(stepNumber(from, step * scale), integer, min, max));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const box = (
|
|
218
|
+
<InputGroup
|
|
219
|
+
id={id}
|
|
220
|
+
size={size}
|
|
221
|
+
fill={fill}
|
|
222
|
+
disabled={disabled}
|
|
223
|
+
placeholder={placeholder}
|
|
224
|
+
value={draft.text}
|
|
225
|
+
intent={isPartialNumber(draft.text) ? 'none' : 'danger'}
|
|
226
|
+
inputMode={integer ? 'numeric' : 'decimal'}
|
|
227
|
+
spellCheck={false}
|
|
228
|
+
autoComplete="off"
|
|
229
|
+
autoCorrect="off"
|
|
230
|
+
autoCapitalize="off"
|
|
231
|
+
aria-label={ariaLabel}
|
|
232
|
+
data-testid={testId}
|
|
233
|
+
leftElement={leftElement}
|
|
234
|
+
rightElement={rightElement}
|
|
235
|
+
className={buttons ? undefined : className}
|
|
236
|
+
style={buttons ? undefined : style}
|
|
237
|
+
onValueChange={type}
|
|
238
|
+
onKeyDown={press}
|
|
239
|
+
onBlur={leave}
|
|
240
|
+
/>
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
if (!buttons) return box;
|
|
244
|
+
|
|
245
|
+
const shown = readNumber(draft.text) ?? value;
|
|
246
|
+
return (
|
|
247
|
+
<ControlGroup
|
|
248
|
+
fill={fill}
|
|
249
|
+
style={style}
|
|
250
|
+
className={[Classes.NUMERIC_INPUT, className].filter(Boolean).join(' ')}
|
|
251
|
+
>
|
|
252
|
+
{box}
|
|
253
|
+
<ButtonGroup className={Classes.FIXED} vertical>
|
|
254
|
+
<Button
|
|
255
|
+
icon="chevron-up"
|
|
256
|
+
size={size}
|
|
257
|
+
aria-label={t('number.increment')}
|
|
258
|
+
disabled={
|
|
259
|
+
disabled ||
|
|
260
|
+
(max !== undefined && shown !== undefined && shown >= max)
|
|
261
|
+
}
|
|
262
|
+
onClick={() => move(1)}
|
|
263
|
+
/>
|
|
264
|
+
<Button
|
|
265
|
+
icon="chevron-down"
|
|
266
|
+
size={size}
|
|
267
|
+
aria-label={t('number.decrement')}
|
|
268
|
+
disabled={
|
|
269
|
+
disabled ||
|
|
270
|
+
(min !== undefined && shown !== undefined && shown <= min)
|
|
271
|
+
}
|
|
272
|
+
onClick={() => move(-1)}
|
|
273
|
+
/>
|
|
274
|
+
</ButtonGroup>
|
|
275
|
+
</ControlGroup>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* The number a box settles on once it is left or stepped.
|
|
281
|
+
* @param value - What the text read as.
|
|
282
|
+
* @param integer - Whether only whole numbers are wanted.
|
|
283
|
+
* @param min - Smallest accepted value, when there is one.
|
|
284
|
+
* @param max - Largest accepted value, when there is one.
|
|
285
|
+
* @returns The rounded, bounded number.
|
|
286
|
+
*/
|
|
287
|
+
function settle(
|
|
288
|
+
value: number,
|
|
289
|
+
integer: boolean,
|
|
290
|
+
min: number | undefined,
|
|
291
|
+
max: number | undefined,
|
|
292
|
+
): number {
|
|
293
|
+
const rounded = integer ? Math.round(value) : value;
|
|
294
|
+
return clamp(
|
|
295
|
+
rounded,
|
|
296
|
+
min ?? Number.NEGATIVE_INFINITY,
|
|
297
|
+
max ?? Number.POSITIVE_INFINITY,
|
|
298
|
+
rounded,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
@@ -64,11 +64,21 @@ interface AtomicOrbitalCanvasProps {
|
|
|
64
64
|
*/
|
|
65
65
|
onAxesChange?: (axes: boolean) => void;
|
|
66
66
|
/**
|
|
67
|
-
* Whether the scene turns on its own, which is what
|
|
68
|
-
* of a 3D shape readable.
|
|
67
|
+
* Whether the scene turns on its own when the canvas opens, which is what
|
|
68
|
+
* makes a still screenshot of a 3D shape readable.
|
|
69
|
+
*
|
|
70
|
+
* The canvas owns the state from then on: the button in its corner flips it,
|
|
71
|
+
* and {@link AtomicOrbitalCanvasProps.onSpinningChange} reports the new value
|
|
72
|
+
* to a site that wants to remember it for the next mount.
|
|
69
73
|
* @default false
|
|
70
74
|
*/
|
|
71
75
|
spinning?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Called when the student flips the spin, with its new state — so a site can
|
|
78
|
+
* persist the choice and pass it back as `spinning`.
|
|
79
|
+
* @default undefined
|
|
80
|
+
*/
|
|
81
|
+
onSpinningChange?: (spinning: boolean) => void;
|
|
72
82
|
/**
|
|
73
83
|
* How fast it turns, in molstar's own spin unit. Lower is slower.
|
|
74
84
|
* @default 0.3
|
|
@@ -108,10 +118,11 @@ export function AtomicOrbitalCanvas(
|
|
|
108
118
|
palette = PHASE_PALETTES.textbook,
|
|
109
119
|
resolution = DEFAULT_RESOLUTION,
|
|
110
120
|
axes: initialAxes = true,
|
|
111
|
-
spinning = false,
|
|
121
|
+
spinning: initialSpinning = false,
|
|
112
122
|
spinSpeed = DEFAULT_SPIN_SPEED,
|
|
113
123
|
sample = sampleInProcess,
|
|
114
124
|
onAxesChange,
|
|
125
|
+
onSpinningChange,
|
|
115
126
|
onNodeRadii,
|
|
116
127
|
onFailureChange,
|
|
117
128
|
} = props;
|
|
@@ -129,6 +140,7 @@ export function AtomicOrbitalCanvas(
|
|
|
129
140
|
const axesRef = useRef(initialAxes);
|
|
130
141
|
|
|
131
142
|
const [axes, setAxes] = useState(initialAxes);
|
|
143
|
+
const [spinning, setSpinning] = useState(initialSpinning);
|
|
132
144
|
|
|
133
145
|
// What the canvas is being asked to show. Comparing it with what it *is*
|
|
134
146
|
// showing gives the progress note without a state write on every prop change.
|
|
@@ -137,9 +149,19 @@ export function AtomicOrbitalCanvas(
|
|
|
137
149
|
|
|
138
150
|
// Callbacks are read through refs so a caller passing an inline arrow does
|
|
139
151
|
// not re-sample the orbital on every render of its parent.
|
|
140
|
-
const callbacks = useRef({
|
|
152
|
+
const callbacks = useRef({
|
|
153
|
+
onAxesChange,
|
|
154
|
+
onSpinningChange,
|
|
155
|
+
onNodeRadii,
|
|
156
|
+
onFailureChange,
|
|
157
|
+
});
|
|
141
158
|
useEffect(() => {
|
|
142
|
-
callbacks.current = {
|
|
159
|
+
callbacks.current = {
|
|
160
|
+
onAxesChange,
|
|
161
|
+
onSpinningChange,
|
|
162
|
+
onNodeRadii,
|
|
163
|
+
onFailureChange,
|
|
164
|
+
};
|
|
143
165
|
});
|
|
144
166
|
|
|
145
167
|
// Created and disposed once per mount. React 19 runs this twice in
|
|
@@ -210,6 +232,11 @@ export function AtomicOrbitalCanvas(
|
|
|
210
232
|
setAxes(!axes);
|
|
211
233
|
callbacks.current.onAxesChange?.(!axes);
|
|
212
234
|
}}
|
|
235
|
+
spinning={spinning}
|
|
236
|
+
onToggleSpin={() => {
|
|
237
|
+
setSpinning(!spinning);
|
|
238
|
+
callbacks.current.onSpinningChange?.(!spinning);
|
|
239
|
+
}}
|
|
213
240
|
onResetView={() => {
|
|
214
241
|
void viewerRef.current?.resetView();
|
|
215
242
|
}}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The three controls an orbital canvas owns: the cartesian frame, the slow
|
|
3
|
+
* spin that makes a 3D shape readable on a flat screen, and the way back to the
|
|
4
|
+
* framing the orbital opened on — a change of orbital keeps whatever angle and
|
|
5
|
+
* zoom the student is on.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { Button } from '@blueprintjs/core';
|
|
@@ -17,25 +18,33 @@ interface AtomicOrbitalControlsProps {
|
|
|
17
18
|
axes: boolean;
|
|
18
19
|
/** Called when the frame button is pressed. */
|
|
19
20
|
onToggleAxes: () => void;
|
|
21
|
+
/** Whether the scene is turning. */
|
|
22
|
+
spinning: boolean;
|
|
23
|
+
/** Called when the spin button is pressed. */
|
|
24
|
+
onToggleSpin: () => void;
|
|
20
25
|
/** Called when the reset button is pressed. */
|
|
21
26
|
onResetView: () => void;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
|
-
* The frame and reset buttons, in the canvas's top-right corner.
|
|
30
|
+
* The frame, spin and reset buttons, in the canvas's top-right corner.
|
|
26
31
|
* @param props - See {@link AtomicOrbitalControlsProps}.
|
|
27
|
-
* @returns The
|
|
32
|
+
* @returns The three buttons.
|
|
28
33
|
*/
|
|
29
34
|
export function AtomicOrbitalControls(
|
|
30
35
|
props: AtomicOrbitalControlsProps,
|
|
31
36
|
): ReactElement {
|
|
32
|
-
const { axes, onToggleAxes, onResetView } = props;
|
|
37
|
+
const { axes, onToggleAxes, spinning, onToggleSpin, onResetView } = props;
|
|
33
38
|
const t = useChromeT();
|
|
34
39
|
const axesHelp: HelpContent = {
|
|
35
40
|
title: t('orbital.axesTitle'),
|
|
36
41
|
body: t('orbital.axesBody'),
|
|
37
42
|
example: { code: '3d_yz', note: t('orbital.axesExample') },
|
|
38
43
|
};
|
|
44
|
+
const spinHelp: HelpContent = {
|
|
45
|
+
title: t('orbital.spinTitle'),
|
|
46
|
+
body: t('orbital.spinBody'),
|
|
47
|
+
};
|
|
39
48
|
const resetHelp: HelpContent = {
|
|
40
49
|
title: t('orbital.resetTitle'),
|
|
41
50
|
body: t('orbital.resetBody'),
|
|
@@ -53,6 +62,17 @@ export function AtomicOrbitalControls(
|
|
|
53
62
|
onClick={onToggleAxes}
|
|
54
63
|
/>
|
|
55
64
|
</HelpTooltip>
|
|
65
|
+
<HelpTooltip content={spinHelp} placement="bottom">
|
|
66
|
+
<Button
|
|
67
|
+
variant="minimal"
|
|
68
|
+
size="small"
|
|
69
|
+
icon="refresh"
|
|
70
|
+
active={spinning}
|
|
71
|
+
aria-label={t('orbital.spin')}
|
|
72
|
+
aria-pressed={spinning}
|
|
73
|
+
onClick={onToggleSpin}
|
|
74
|
+
/>
|
|
75
|
+
</HelpTooltip>
|
|
56
76
|
<HelpTooltip content={resetHelp} placement="bottom">
|
|
57
77
|
<Button
|
|
58
78
|
variant="minimal"
|
|
@@ -68,10 +68,17 @@ export interface AtomicOrbitalViewerProps {
|
|
|
68
68
|
*/
|
|
69
69
|
onAxesChange?: (axes: boolean) => void;
|
|
70
70
|
/**
|
|
71
|
-
* Whether the scene turns on its own.
|
|
71
|
+
* Whether the scene turns on its own when the canvas opens. The button in the
|
|
72
|
+
* canvas's corner flips it from there.
|
|
72
73
|
* @default false
|
|
73
74
|
*/
|
|
74
75
|
spinning?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Called when the student flips the spin, with its new state — so a site can
|
|
78
|
+
* persist the choice and pass it back as `spinning`.
|
|
79
|
+
* @default undefined
|
|
80
|
+
*/
|
|
81
|
+
onSpinningChange?: (spinning: boolean) => void;
|
|
75
82
|
/**
|
|
76
83
|
* How fast it turns, in molstar's own spin unit. Lower is slower.
|
|
77
84
|
* @default 0.3
|