react-cheminfo 0.121.0 → 0.123.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/drawing/core/index.d.ts +2 -0
- package/lib/drawing/core/index.d.ts.map +1 -1
- package/lib/drawing/core/index.js +1 -0
- package/lib/drawing/core/index.js.map +1 -1
- package/lib/drawing/core/undoHistory.d.ts +59 -0
- package/lib/drawing/core/undoHistory.d.ts.map +1 -0
- package/lib/drawing/core/undoHistory.js +68 -0
- package/lib/drawing/core/undoHistory.js.map +1 -0
- package/lib/ecosystem/core/index.d.ts +2 -2
- package/lib/ecosystem/core/index.d.ts.map +1 -1
- package/lib/ecosystem/core/index.js +1 -1
- package/lib/ecosystem/core/index.js.map +1 -1
- package/lib/ecosystem/core/lookup.d.ts +6 -0
- package/lib/ecosystem/core/lookup.d.ts.map +1 -1
- package/lib/ecosystem/core/lookup.js +8 -0
- package/lib/ecosystem/core/lookup.js.map +1 -1
- package/lib/ecosystem/core/sites.d.ts +1 -1
- package/lib/ecosystem/core/sites.d.ts.map +1 -1
- package/lib/ecosystem/core/sites.js.map +1 -1
- package/lib/ecosystem/core/types.d.ts +23 -1
- package/lib/ecosystem/core/types.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.d.ts.map +1 -1
- package/lib/ecosystem/core/unlistedSites.js +77 -0
- package/lib/ecosystem/core/unlistedSites.js.map +1 -1
- package/lib/ecosystem/ui/glyphs.d.ts.map +1 -1
- package/lib/ecosystem/ui/glyphs.js +16 -0
- package/lib/ecosystem/ui/glyphs.js.map +1 -1
- package/lib/host/core/answerGet.js +1 -1
- package/lib/host/core/answerGet.js.map +1 -1
- package/lib/host/core/datasetKinds.d.ts +246 -0
- package/lib/host/core/datasetKinds.d.ts.map +1 -0
- package/lib/host/core/datasetKinds.js +97 -0
- package/lib/host/core/datasetKinds.js.map +1 -0
- package/lib/host/core/hostOutputs.js +1 -1
- package/lib/host/core/hostOutputs.js.map +1 -1
- package/lib/host/core/index.d.ts +6 -1
- package/lib/host/core/index.d.ts.map +1 -1
- package/lib/host/core/index.js +4 -1
- package/lib/host/core/index.js.map +1 -1
- package/lib/host/core/kindAccepts.d.ts +15 -0
- package/lib/host/core/kindAccepts.d.ts.map +1 -0
- package/lib/host/core/kindAccepts.js +22 -0
- package/lib/host/core/kindAccepts.js.map +1 -0
- package/lib/host/core/kinds.d.ts +7 -10
- package/lib/host/core/kinds.d.ts.map +1 -1
- package/lib/host/core/kinds.js +7 -17
- package/lib/host/core/kinds.js.map +1 -1
- package/lib/host/core/selectInputs.d.ts.map +1 -1
- package/lib/host/core/selectInputs.js +2 -1
- package/lib/host/core/selectInputs.js.map +1 -1
- package/lib/host/core/sendTargets.d.ts +32 -0
- package/lib/host/core/sendTargets.d.ts.map +1 -0
- package/lib/host/core/sendTargets.js +40 -0
- package/lib/host/core/sendTargets.js.map +1 -0
- package/lib/host/ui/SendToButton.d.ts +38 -0
- package/lib/host/ui/SendToButton.d.ts.map +1 -0
- package/lib/host/ui/SendToButton.js +61 -0
- package/lib/host/ui/SendToButton.js.map +1 -0
- package/lib/host/ui/index.d.ts +2 -0
- package/lib/host/ui/index.d.ts.map +1 -1
- package/lib/host/ui/index.js +1 -0
- package/lib/host/ui/index.js.map +1 -1
- package/lib/host/ui/openTool.d.ts +16 -8
- package/lib/host/ui/openTool.d.ts.map +1 -1
- package/lib/host/ui/openTool.js +36 -11
- package/lib/host/ui/openTool.js.map +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts +1 -1
- package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
- package/lib/locales/de.json +10 -1
- package/lib/locales/en.json +10 -1
- package/lib/locales/es.json +10 -1
- package/lib/locales/fr.json +10 -1
- package/lib/locales/it.json +10 -1
- package/lib/panel/core/createPanelState.d.ts +58 -0
- package/lib/panel/core/createPanelState.d.ts.map +1 -0
- package/lib/panel/core/createPanelState.js +74 -0
- package/lib/panel/core/createPanelState.js.map +1 -0
- package/lib/panel/core/index.d.ts +2 -0
- package/lib/panel/core/index.d.ts.map +1 -1
- package/lib/panel/core/index.js +1 -0
- package/lib/panel/core/index.js.map +1 -1
- package/lib/panel/ui/PanelFrame.d.ts +27 -0
- package/lib/panel/ui/PanelFrame.d.ts.map +1 -0
- package/lib/panel/ui/PanelFrame.js +12 -0
- package/lib/panel/ui/PanelFrame.js.map +1 -0
- package/lib/panel/ui/index.d.ts +2 -0
- package/lib/panel/ui/index.d.ts.map +1 -1
- package/lib/panel/ui/index.js +1 -0
- package/lib/panel/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/src/drawing/core/index.ts +2 -0
- package/src/drawing/core/undoHistory.ts +118 -0
- package/src/ecosystem/core/index.ts +2 -0
- package/src/ecosystem/core/lookup.ts +9 -0
- package/src/ecosystem/core/sites.ts +1 -0
- package/src/ecosystem/core/types.ts +28 -0
- package/src/ecosystem/core/unlistedSites.ts +81 -0
- package/src/ecosystem/ui/glyphs.tsx +97 -0
- package/src/host/core/answerGet.ts +1 -1
- package/src/host/core/datasetKinds.ts +202 -0
- package/src/host/core/hostOutputs.ts +1 -1
- package/src/host/core/index.ts +12 -1
- package/src/host/core/kindAccepts.ts +21 -0
- package/src/host/core/kinds.ts +14 -18
- package/src/host/core/selectInputs.ts +2 -1
- package/src/host/core/sendTargets.ts +67 -0
- package/src/host/ui/SendToButton.tsx +147 -0
- package/src/host/ui/index.ts +2 -0
- package/src/host/ui/openTool.ts +57 -16
- package/src/locales/de.json +10 -1
- package/src/locales/en.json +10 -1
- package/src/locales/es.json +10 -1
- package/src/locales/fr.json +10 -1
- package/src/locales/it.json +10 -1
- package/src/panel/core/createPanelState.ts +126 -0
- package/src/panel/core/index.ts +6 -0
- package/src/panel/ui/PanelFrame.tsx +47 -0
- package/src/panel/ui/index.ts +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How one kind name falls under another, apart from the schemas of
|
|
3
|
+
* `./kinds.ts`, so a page that only matches kinds — a Send menu — never loads
|
|
4
|
+
* ajv.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Whether a kind falls under another: the same name, or a name under it on a
|
|
9
|
+
* segment boundary. A list (`…[]`) never stands for one value, nor one value
|
|
10
|
+
* for a list.
|
|
11
|
+
* @param accepted - The kind a tool declares, e.g. `'chem.molfile'`.
|
|
12
|
+
* @param offered - The kind an item carries, e.g. `'chem.molfile.2d'`.
|
|
13
|
+
* @returns `true` when an item of `offered` can be read as `accepted`.
|
|
14
|
+
*/
|
|
15
|
+
export function kindAccepts(accepted: string, offered: string): boolean {
|
|
16
|
+
const list = accepted.endsWith('[]');
|
|
17
|
+
if (offered.endsWith('[]') !== list) return false;
|
|
18
|
+
const base = list ? accepted.slice(0, -2) : accepted;
|
|
19
|
+
const name = list ? offered.slice(0, -2) : offered;
|
|
20
|
+
return name === base || name.startsWith(`${base}.`);
|
|
21
|
+
}
|
package/src/host/core/kinds.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* kinds of `./irKinds.ts`, the Raman ones of `./ramanKinds.ts`, the UV-vis
|
|
9
9
|
* ones of `./uvKinds.ts` and the mass
|
|
10
10
|
* spectrometry ones of `./msKinds.ts`, the reaction of `./reactionKinds.ts`,
|
|
11
|
-
* the peptide of `./peptideKinds.ts`,
|
|
11
|
+
* the peptide of `./peptideKinds.ts`, the set of spectra of
|
|
12
|
+
* `./datasetKinds.ts`, and
|
|
12
13
|
* the kinds a tool hands back, of `./resultKinds.ts`. A name with children is a category whose
|
|
13
14
|
* schema every child satisfies, so `chem.molfile` reads `chem.molfile.2d` and
|
|
14
15
|
* `chem.molfile.3d.h.energy` alike; the fields a tool does not read are
|
|
@@ -19,8 +20,14 @@
|
|
|
19
20
|
import type { JSONSchemaType, ValidateFunction } from 'ajv';
|
|
20
21
|
import { Ajv } from 'ajv';
|
|
21
22
|
|
|
23
|
+
import type { SpectraDatasetValue } from './datasetKinds.ts';
|
|
24
|
+
import {
|
|
25
|
+
NUMBER_ARRAY_KEYWORD,
|
|
26
|
+
SPECTRA_DATASET_SCHEMA,
|
|
27
|
+
} from './datasetKinds.ts';
|
|
22
28
|
import type { IrJdxValue, IrPeaksValue } from './irKinds.ts';
|
|
23
29
|
import { IR_JDX_SCHEMA, IR_PEAKS_SCHEMA } from './irKinds.ts';
|
|
30
|
+
import { kindAccepts } from './kindAccepts.ts';
|
|
24
31
|
import type { MsAssignmentsValue, MsIonsValue, MsJdxValue } from './msKinds.ts';
|
|
25
32
|
import {
|
|
26
33
|
MS_ASSIGNMENTS_SCHEMA,
|
|
@@ -73,7 +80,10 @@ export type CheckedValue =
|
|
|
73
80
|
| { kind: 'spectra.ms.assignments'; value: MsAssignmentsValue }
|
|
74
81
|
| { kind: 'image.svg'; value: SvgImageValue }
|
|
75
82
|
| { kind: 'chem.name'; value: NameValue }
|
|
76
|
-
| { kind: 'data.table'; value: TableValue }
|
|
83
|
+
| { kind: 'data.table'; value: TableValue }
|
|
84
|
+
| { kind: 'data.spectra'; value: SpectraDatasetValue };
|
|
85
|
+
|
|
86
|
+
export { kindAccepts } from './kindAccepts.ts';
|
|
77
87
|
|
|
78
88
|
/** The name of a kind there is a schema for: one a tool reads, or one it hands back. */
|
|
79
89
|
export type KnownKind = CheckedValue['kind'];
|
|
@@ -88,22 +98,6 @@ type ValueOf<K extends KnownKind> = CheckedOf<K>['value'];
|
|
|
88
98
|
export type CheckOutcome =
|
|
89
99
|
{ valid: true; checked: CheckedValue } | { valid: false; errors: string[] };
|
|
90
100
|
|
|
91
|
-
/**
|
|
92
|
-
* Whether a kind falls under another: the same name, or a name under it on a
|
|
93
|
-
* segment boundary. A list (`…[]`) never stands for one value, nor one value
|
|
94
|
-
* for a list.
|
|
95
|
-
* @param accepted - The kind a tool declares, e.g. `'chem.molfile'`.
|
|
96
|
-
* @param offered - The kind an item carries, e.g. `'chem.molfile.2d'`.
|
|
97
|
-
* @returns `true` when an item of `offered` can be read as `accepted`.
|
|
98
|
-
*/
|
|
99
|
-
export function kindAccepts(accepted: string, offered: string): boolean {
|
|
100
|
-
const list = accepted.endsWith('[]');
|
|
101
|
-
if (offered.endsWith('[]') !== list) return false;
|
|
102
|
-
const base = list ? accepted.slice(0, -2) : accepted;
|
|
103
|
-
const name = list ? offered.slice(0, -2) : offered;
|
|
104
|
-
return name === base || name.startsWith(`${base}.`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
101
|
/**
|
|
108
102
|
* Whether there is a schema for a kind.
|
|
109
103
|
* @param kind - A kind name.
|
|
@@ -194,6 +188,7 @@ const SMILES_SCHEMA: JSONSchemaType<SmilesValue> = {
|
|
|
194
188
|
// `removeAdditional` strips what `additionalProperties: false` would refuse;
|
|
195
189
|
// a table's cell is a string, a number or null, which is a union of types.
|
|
196
190
|
const ajv = new Ajv({ removeAdditional: true, allowUnionTypes: true });
|
|
191
|
+
ajv.addKeyword(NUMBER_ARRAY_KEYWORD);
|
|
197
192
|
|
|
198
193
|
const VALIDATORS: { [K in KnownKind]: ValidateFunction<ValueOf<K>> } = {
|
|
199
194
|
'chem.molfile': ajv.compile(MOLFILE_SCHEMA),
|
|
@@ -217,4 +212,5 @@ const VALIDATORS: { [K in KnownKind]: ValidateFunction<ValueOf<K>> } = {
|
|
|
217
212
|
'image.svg': ajv.compile<SvgImageValue>(SVG_IMAGE_SCHEMA),
|
|
218
213
|
'chem.name': ajv.compile<NameValue>(NAME_SCHEMA),
|
|
219
214
|
'data.table': ajv.compile<TableValue>(TABLE_SCHEMA),
|
|
215
|
+
'data.spectra': ajv.compile<SpectraDatasetValue>(SPECTRA_DATASET_SCHEMA),
|
|
220
216
|
};
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* host is answered with when the request loads nothing.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { kindAccepts } from './kindAccepts.ts';
|
|
6
7
|
import type { CheckedValue, KnownKind } from './kinds.ts';
|
|
7
|
-
import { checkValue, isKnownKind
|
|
8
|
+
import { checkValue, isKnownKind } from './kinds.ts';
|
|
8
9
|
import type {
|
|
9
10
|
HostError,
|
|
10
11
|
HostItem,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which sites of the family can take what a page could send them: matched on
|
|
3
|
+
* the kinds alone, from what the registry says each site receives, before
|
|
4
|
+
* anything is built or any site is opened.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { knownSites } from '../../ecosystem/core/lookup.ts';
|
|
8
|
+
import type {
|
|
9
|
+
EcosystemSite,
|
|
10
|
+
SiteReceiver,
|
|
11
|
+
} from '../../ecosystem/core/types.ts';
|
|
12
|
+
|
|
13
|
+
import { kindAccepts } from './kindAccepts.ts';
|
|
14
|
+
|
|
15
|
+
/** Something a page could send, named before it is built. */
|
|
16
|
+
export interface SendOffer {
|
|
17
|
+
/** The kind it would be sent as, e.g. `'data.spectra'`. */
|
|
18
|
+
kind: string;
|
|
19
|
+
/** What it is, as the menu names it, e.g. `'3 IR spectra'`. */
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A site that can take one of the offers, and how. */
|
|
24
|
+
export interface SendTarget<Offer extends SendOffer = SendOffer> {
|
|
25
|
+
/** The site. */
|
|
26
|
+
site: EcosystemSite;
|
|
27
|
+
/** The way it takes data that matched. */
|
|
28
|
+
receiver: SiteReceiver;
|
|
29
|
+
/** The offer it takes: the first of its kinds that any offer carries. */
|
|
30
|
+
offer: Offer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The sites that can take one of the offers, in the order the family declares
|
|
35
|
+
* them. A site whose receiver accepts several offers takes the one its own
|
|
36
|
+
* order of kinds prefers.
|
|
37
|
+
* @param offers - What the page could send, in its own order of preference.
|
|
38
|
+
* @param from - The site sending, which is never offered to itself.
|
|
39
|
+
* @returns One target per site receiver that accepts an offer.
|
|
40
|
+
*/
|
|
41
|
+
export function sendTargets<Offer extends SendOffer>(
|
|
42
|
+
offers: readonly Offer[],
|
|
43
|
+
from?: string,
|
|
44
|
+
): Array<SendTarget<Offer>> {
|
|
45
|
+
const targets: Array<SendTarget<Offer>> = [];
|
|
46
|
+
if (offers.length === 0) return targets;
|
|
47
|
+
for (const site of knownSites()) {
|
|
48
|
+
if (site.id === from) continue;
|
|
49
|
+
for (const receiver of site.receives ?? []) {
|
|
50
|
+
const offer = preferredOffer(receiver, offers);
|
|
51
|
+
if (offer !== undefined) targets.push({ site, receiver, offer });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return targets;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function preferredOffer<Offer extends SendOffer>(
|
|
58
|
+
receiver: SiteReceiver,
|
|
59
|
+
offers: readonly Offer[],
|
|
60
|
+
): Offer | undefined {
|
|
61
|
+
for (const accepted of receiver.kinds) {
|
|
62
|
+
for (const offer of offers) {
|
|
63
|
+
if (kindAccepts(accepted, offer.kind)) return offer;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Menu, MenuDivider, MenuItem } from '@blueprintjs/core';
|
|
2
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
import { siteDisplayName } from '../../ecosystem/core/lookup.ts';
|
|
5
|
+
import { siteUrl } from '../../ecosystem/core/sites.ts';
|
|
6
|
+
import { SiteMark } from '../../ecosystem/ui/marks.tsx';
|
|
7
|
+
import { useChromeT } from '../../i18n/ui/useT.ts';
|
|
8
|
+
import type { HeaderButtonProps } from '../../shared/ui/MenuButton.tsx';
|
|
9
|
+
import { MenuButton } from '../../shared/ui/MenuButton.tsx';
|
|
10
|
+
import type { HostItem } from '../core/protocol.ts';
|
|
11
|
+
import type { SendOffer, SendTarget } from '../core/sendTargets.ts';
|
|
12
|
+
import { sendTargets } from '../core/sendTargets.ts';
|
|
13
|
+
|
|
14
|
+
import { openTool } from './openTool.ts';
|
|
15
|
+
|
|
16
|
+
/** Something the page could send, and how it is built once a site is picked. */
|
|
17
|
+
export interface SendItemOffer extends SendOffer {
|
|
18
|
+
/** Build the item; the site's tab is already open and loading meanwhile. */
|
|
19
|
+
make: () => HostItem | Promise<HostItem>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What {@link SendToButton} needs. */
|
|
23
|
+
export interface SendToButtonProps extends HeaderButtonProps {
|
|
24
|
+
/** What the page could send now, in its own order of preference. */
|
|
25
|
+
offers: readonly SendItemOffer[];
|
|
26
|
+
/** The site sending: how it introduces itself, and never a target. */
|
|
27
|
+
siteId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Where a site is opened instead of its own host, by site id — a checkout
|
|
30
|
+
* running locally, e.g. `{ ml: 'http://localhost:11112' }`.
|
|
31
|
+
* @default {}
|
|
32
|
+
*/
|
|
33
|
+
addresses?: Readonly<Record<string, string>>;
|
|
34
|
+
/**
|
|
35
|
+
* Told, in one sentence, why something could not be sent.
|
|
36
|
+
* @default undefined — nobody is told
|
|
37
|
+
*/
|
|
38
|
+
onError?: (message: string) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const DOES_STYLE: CSSProperties = { fontSize: '0.85em', opacity: 0.75 };
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The Send entry of a site header: the sites of the family that can take what
|
|
45
|
+
* the page shows, each opened in a new tab and handed it through the host
|
|
46
|
+
* protocol. Which sites are listed is worked out from the kinds alone, before
|
|
47
|
+
* anything is built; the data is built once a site is picked, while its tab
|
|
48
|
+
* loads.
|
|
49
|
+
* @param props - See {@link SendToButtonProps}.
|
|
50
|
+
* @returns The button and its menu.
|
|
51
|
+
*/
|
|
52
|
+
export function SendToButton(props: SendToButtonProps): ReactElement {
|
|
53
|
+
const { offers, siteId, addresses = {}, onError, ...rest } = props;
|
|
54
|
+
const t = useChromeT();
|
|
55
|
+
const targets = sendTargets(offers, siteId);
|
|
56
|
+
|
|
57
|
+
function send(target: SendTarget<SendItemOffer>): void {
|
|
58
|
+
const base = addresses[target.site.id] ?? siteUrl(target.site);
|
|
59
|
+
const url = new URL(target.receiver.page ?? '/', base).href;
|
|
60
|
+
const document = `${siteId}:send:${crypto.randomUUID()}`;
|
|
61
|
+
const opened = openTool({
|
|
62
|
+
url,
|
|
63
|
+
host: siteId,
|
|
64
|
+
document: async () => ({
|
|
65
|
+
document,
|
|
66
|
+
items: [await target.offer.make()],
|
|
67
|
+
}),
|
|
68
|
+
...(onError === undefined ? {} : { onError }),
|
|
69
|
+
});
|
|
70
|
+
if (!opened) onError?.(t('send.blocked'));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<MenuButton
|
|
75
|
+
{...rest}
|
|
76
|
+
className="send-to-button"
|
|
77
|
+
icon="send-to"
|
|
78
|
+
label={t('send.label')}
|
|
79
|
+
menu={<SendMenu targets={targets} onSend={send} none={t('send.none')} />}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface SendMenuProps {
|
|
85
|
+
targets: ReadonlyArray<SendTarget<SendItemOffer>>;
|
|
86
|
+
onSend: (target: SendTarget<SendItemOffer>) => void;
|
|
87
|
+
none: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function SendMenu(props: SendMenuProps): ReactElement {
|
|
91
|
+
const { targets, onSend, none } = props;
|
|
92
|
+
const t = useChromeT();
|
|
93
|
+
if (targets.length === 0) {
|
|
94
|
+
return (
|
|
95
|
+
<Menu>
|
|
96
|
+
<MenuItem disabled text={none} />
|
|
97
|
+
</Menu>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const offers: SendItemOffer[] = [];
|
|
101
|
+
for (const target of targets) {
|
|
102
|
+
if (!offers.includes(target.offer)) offers.push(target.offer);
|
|
103
|
+
}
|
|
104
|
+
return (
|
|
105
|
+
<Menu>
|
|
106
|
+
{offers.map((offer) => (
|
|
107
|
+
<SendGroup
|
|
108
|
+
key={offer.kind}
|
|
109
|
+
title={t('send.heading', { what: offer.label })}
|
|
110
|
+
targets={targets.filter((target) => target.offer === offer)}
|
|
111
|
+
onSend={onSend}
|
|
112
|
+
/>
|
|
113
|
+
))}
|
|
114
|
+
</Menu>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface SendGroupProps {
|
|
119
|
+
title: string;
|
|
120
|
+
targets: ReadonlyArray<SendTarget<SendItemOffer>>;
|
|
121
|
+
onSend: (target: SendTarget<SendItemOffer>) => void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function SendGroup(props: SendGroupProps): ReactElement {
|
|
125
|
+
const { title, targets, onSend } = props;
|
|
126
|
+
return (
|
|
127
|
+
<>
|
|
128
|
+
<MenuDivider title={title} />
|
|
129
|
+
{targets.map((target) => (
|
|
130
|
+
<MenuItem
|
|
131
|
+
key={`${target.site.id}:${target.receiver.page ?? '/'}`}
|
|
132
|
+
icon={<SiteMark site={target.site} size={24} />}
|
|
133
|
+
multiline
|
|
134
|
+
text={
|
|
135
|
+
<>
|
|
136
|
+
<div>{siteDisplayName(target.site)}</div>
|
|
137
|
+
<div style={DOES_STYLE}>{target.receiver.does}</div>
|
|
138
|
+
</>
|
|
139
|
+
}
|
|
140
|
+
onClick={() => {
|
|
141
|
+
onSend(target);
|
|
142
|
+
}}
|
|
143
|
+
/>
|
|
144
|
+
))}
|
|
145
|
+
</>
|
|
146
|
+
);
|
|
147
|
+
}
|
package/src/host/ui/index.ts
CHANGED
|
@@ -17,6 +17,8 @@ export type { SaveFigureAs, SaveFigureAsOptions } from './useSaveFigureAs.tsx';
|
|
|
17
17
|
export { useSaveFigureAs } from './useSaveFigureAs.tsx';
|
|
18
18
|
export { useSaveShortcut } from './useSaveShortcut.ts';
|
|
19
19
|
export { openTool } from './openTool.ts';
|
|
20
|
+
export type { SendItemOffer, SendToButtonProps } from './SendToButton.tsx';
|
|
21
|
+
export { SendToButton } from './SendToButton.tsx';
|
|
20
22
|
export type {
|
|
21
23
|
FramedTool,
|
|
22
24
|
FramedToolOptions,
|
package/src/host/ui/openTool.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Open a
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Open a tool on its own site, in a new tab, carrying data: a framed tool's
|
|
3
|
+
* structure for a visitor who wants the whole site, or what a Send menu sends
|
|
4
|
+
* another site of the family.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { errorMessage } from '../../error/core/toError.ts';
|
|
8
|
+
import type {
|
|
9
|
+
LoadOutcome,
|
|
10
|
+
ToolConnection,
|
|
11
|
+
ToolDocument,
|
|
12
|
+
} from '../core/connectTool.ts';
|
|
8
13
|
import { REQUEST_TIMEOUT, connectTool } from '../core/connectTool.ts';
|
|
9
14
|
import { toolPageUrl } from '../core/toolPage.ts';
|
|
10
15
|
|
|
@@ -12,29 +17,40 @@ import { HELLO_TIMEOUT } from './useFramedTool.ts';
|
|
|
12
17
|
|
|
13
18
|
/** What {@link openTool} opens, and what it hands over. */
|
|
14
19
|
export interface OpenToolOptions {
|
|
15
|
-
/** The
|
|
20
|
+
/** The address; the tab opens the same page without the framing. */
|
|
16
21
|
url: string;
|
|
17
22
|
/** How the host introduces itself to the tool. */
|
|
18
23
|
host: string;
|
|
19
24
|
/**
|
|
20
|
-
* What the tab is handed once the tool greets it
|
|
21
|
-
*
|
|
25
|
+
* What the tab is handed once the tool greets it: the document, a function
|
|
26
|
+
* building it once the tab is open — a large one takes the time the tool
|
|
27
|
+
* takes to load — or `null` to open the page as it is.
|
|
22
28
|
*/
|
|
23
|
-
document: ToolDocument | null;
|
|
29
|
+
document: ToolDocument | (() => Promise<ToolDocument>) | null;
|
|
30
|
+
/**
|
|
31
|
+
* Told, in one sentence, when the document could not be built, or the tool
|
|
32
|
+
* refused it or never answered.
|
|
33
|
+
* @default undefined — nobody is told
|
|
34
|
+
*/
|
|
35
|
+
onError?: (message: string) => void;
|
|
24
36
|
}
|
|
25
37
|
|
|
38
|
+
/** What a tool that greeted nobody, or never answered, is reported as. */
|
|
39
|
+
const NOT_ANSWERED = 'The tool did not answer in time.';
|
|
40
|
+
|
|
26
41
|
/**
|
|
27
42
|
* Open the tool's own page in a new tab and, when there is a document, hand
|
|
28
43
|
* it over through the host protocol: the tool greets the window that opened
|
|
29
44
|
* it as it greets a parent frame. The connection is closed once the tool has
|
|
30
45
|
* answered, or has had its time to.
|
|
31
46
|
*
|
|
32
|
-
* Call it from a click: a browser opens a tab only then
|
|
47
|
+
* Call it from a click: a browser opens a tab only then, which is why a
|
|
48
|
+
* document that takes time to build is passed as a function.
|
|
33
49
|
* @param options - See {@link OpenToolOptions}.
|
|
34
50
|
* @returns `false` when the browser would not open the tab.
|
|
35
51
|
*/
|
|
36
52
|
export function openTool(options: OpenToolOptions): boolean {
|
|
37
|
-
const { url, host, document } = options;
|
|
53
|
+
const { url, host, document, onError } = options;
|
|
38
54
|
const page = toolPageUrl(url);
|
|
39
55
|
if (document === null) {
|
|
40
56
|
// `noopener` makes `open` return null whether or not the tab opened.
|
|
@@ -54,14 +70,39 @@ export function openTool(options: OpenToolOptions): boolean {
|
|
|
54
70
|
};
|
|
55
71
|
},
|
|
56
72
|
});
|
|
73
|
+
void handOver(connection, document)
|
|
74
|
+
.then(
|
|
75
|
+
(outcome) => {
|
|
76
|
+
if (outcome.status === 'refused') onError?.(outcome.error.message);
|
|
77
|
+
if (outcome.status === 'dropped') onError?.(NOT_ANSWERED);
|
|
78
|
+
},
|
|
79
|
+
(error: unknown) => {
|
|
80
|
+
onError?.(errorMessage(error));
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
.finally(() => {
|
|
84
|
+
connection.close();
|
|
85
|
+
});
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function handOver(
|
|
90
|
+
connection: ToolConnection,
|
|
91
|
+
document: ToolDocument | (() => Promise<ToolDocument>),
|
|
92
|
+
): Promise<LoadOutcome> {
|
|
93
|
+
const ready = typeof document === 'function' ? await document() : document;
|
|
94
|
+
// The tool's time to greet and to answer runs from when there is something
|
|
95
|
+
// to hand it.
|
|
57
96
|
const timer = setTimeout(() => {
|
|
58
97
|
connection.close();
|
|
59
98
|
}, HELLO_TIMEOUT + REQUEST_TIMEOUT);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
99
|
+
try {
|
|
100
|
+
// Only the data: nothing the opener takes back is asked of the tab.
|
|
101
|
+
return await connection.load({
|
|
102
|
+
document: ready.document,
|
|
103
|
+
items: ready.items,
|
|
104
|
+
});
|
|
105
|
+
} finally {
|
|
63
106
|
clearTimeout(timer);
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
return true;
|
|
107
|
+
}
|
|
67
108
|
}
|
package/src/locales/de.json
CHANGED
|
@@ -126,11 +126,16 @@
|
|
|
126
126
|
"site.chembio.tagline": "Naturstoffe, und die Organismen, in denen sie gefunden wurden.",
|
|
127
127
|
"site.wikidata.tagline": "Die Chemie der Wikipedia-Infoboxen, nach Struktur durchsuchbar.",
|
|
128
128
|
"site.mz.tagline": "Massenspektren, danach geordnet, wie sie gemessen wurden.",
|
|
129
|
+
"site.plot.tagline": "Tabellen und Spektren als Diagramme zeichnen, in Größe und Stil einer Zeitschrift.",
|
|
130
|
+
"site.ml.tagline": "Maschinelles Lernen auf Spektren, im Browser.",
|
|
129
131
|
"site.uv-vis.tagline": "UV-Vis-Spektren überlagern und jedes λmax ablesen.",
|
|
130
132
|
"site.xps.tagline": "Röntgenphotoelektronenspektren lesen, anpassen und vorhersagen.",
|
|
131
133
|
"site.biodraw.tagline": "Zellen und Membranen zeichnen und Proteine darin verankern.",
|
|
132
134
|
"site.diagram.tagline": "Flussdiagramme und Blockschaltbilder zeichnen, mit Pfeilen, die den Blöcken folgen.",
|
|
133
135
|
"site.peptide.tagline": "Peptidsynthese lernen, von Schutzgruppen bis zur Festphase.",
|
|
136
|
+
"site.optics.tagline": "Linsen und Spiegel auf eine Bank stellen und dem Licht bis zum Bild folgen.",
|
|
137
|
+
"site.circuits.tagline": "Batterien, Lampen und Widerstände verdrahten und ablesen, was die Messgeräte zeigen.",
|
|
138
|
+
"site.mechanics.tagline": "Einen Block auf eine schiefe Ebene oder an eine Rolle setzen und sehen, wie sich die Kräfte addieren.",
|
|
134
139
|
"share.button": "Teilen",
|
|
135
140
|
"share.buttonTitle": "Einen Link zu dieser Seite teilen oder sie in Ihre eigene Website einbetten",
|
|
136
141
|
"share.dialogTitleFor": "{title} teilen oder einbetten",
|
|
@@ -1054,5 +1059,9 @@
|
|
|
1054
1059
|
"folder.create": "Erstellen",
|
|
1055
1060
|
"folder.folderTaken": "Hier heißt bereits ein Ordner {name}: Wählen Sie einen anderen Namen.",
|
|
1056
1061
|
"folder.openFolder": "Den Ordner {folder} öffnen",
|
|
1057
|
-
"folder.found": "In {path}"
|
|
1062
|
+
"folder.found": "In {path}",
|
|
1063
|
+
"send.label": "Senden an",
|
|
1064
|
+
"send.heading": "{what} senden an",
|
|
1065
|
+
"send.none": "Von dieser Seite lässt sich noch nichts an ein anderes Werkzeug senden.",
|
|
1066
|
+
"send.blocked": "Der Browser hat den neuen Tab blockiert: Pop-ups für diese Seite erlauben, dann erneut senden."
|
|
1058
1067
|
}
|
package/src/locales/en.json
CHANGED
|
@@ -126,11 +126,16 @@
|
|
|
126
126
|
"site.chembio.tagline": "Natural products, and the organisms they were found in.",
|
|
127
127
|
"site.wikidata.tagline": "The chemistry of Wikipedia’s infoboxes, searchable by structure.",
|
|
128
128
|
"site.mz.tagline": "Mass spectra, classified by how they were measured.",
|
|
129
|
+
"site.plot.tagline": "Plot tables and spectra as charts sized and styled for a journal.",
|
|
130
|
+
"site.ml.tagline": "Machine learning on spectra, in the browser.",
|
|
129
131
|
"site.uv-vis.tagline": "Overlay UV-vis spectra and read off every λmax.",
|
|
130
132
|
"site.xps.tagline": "Read, fit and predict X-ray photoelectron spectra.",
|
|
131
133
|
"site.biodraw.tagline": "Draw cells and membranes, and snap proteins into them.",
|
|
132
134
|
"site.diagram.tagline": "Draw flowcharts and block diagrams, with arrows that follow the blocks.",
|
|
133
135
|
"site.peptide.tagline": "Learn peptide synthesis, from protecting groups to the solid phase.",
|
|
136
|
+
"site.optics.tagline": "Set lenses and mirrors on a bench, and follow the light to its image.",
|
|
137
|
+
"site.circuits.tagline": "Wire batteries, bulbs and resistors, and read what the meters show.",
|
|
138
|
+
"site.mechanics.tagline": "Put a block on a slope or over a pulley, and see the forces add up.",
|
|
134
139
|
"share.button": "Share",
|
|
135
140
|
"share.buttonTitle": "Share a link to this page, or embed it in your own site",
|
|
136
141
|
"share.dialogTitleFor": "Share or embed — {title}",
|
|
@@ -1054,5 +1059,9 @@
|
|
|
1054
1059
|
"folder.create": "Create",
|
|
1055
1060
|
"folder.folderTaken": "A folder is already named {name} here: choose another name.",
|
|
1056
1061
|
"folder.openFolder": "Open the folder {folder}",
|
|
1057
|
-
"folder.found": "In {path}"
|
|
1062
|
+
"folder.found": "In {path}",
|
|
1063
|
+
"send.label": "Send to",
|
|
1064
|
+
"send.heading": "Send {what} to",
|
|
1065
|
+
"send.none": "Nothing on this page can be sent to another tool yet.",
|
|
1066
|
+
"send.blocked": "The browser blocked the new tab: allow pop-ups for this site, then send again."
|
|
1058
1067
|
}
|
package/src/locales/es.json
CHANGED
|
@@ -126,11 +126,16 @@
|
|
|
126
126
|
"site.chembio.tagline": "Productos naturales, y los organismos en los que se encontraron.",
|
|
127
127
|
"site.wikidata.tagline": "La química de las fichas de Wikipedia, con búsqueda por estructura.",
|
|
128
128
|
"site.mz.tagline": "Espectros de masas, clasificados según cómo se midieron.",
|
|
129
|
+
"site.plot.tagline": "Trazar tablas y espectros como gráficos con el tamaño y el estilo de una revista.",
|
|
130
|
+
"site.ml.tagline": "Aprendizaje automático sobre espectros, en el navegador.",
|
|
129
131
|
"site.uv-vis.tagline": "Superponer espectros UV-vis y leer cada λmax.",
|
|
130
132
|
"site.xps.tagline": "Leer, ajustar y predecir espectros de fotoelectrones de rayos X.",
|
|
131
133
|
"site.biodraw.tagline": "Dibujar células y membranas, y anclar proteínas en ellas.",
|
|
132
134
|
"site.diagram.tagline": "Dibujar diagramas de flujo y de bloques, con flechas que siguen a los bloques.",
|
|
133
135
|
"site.peptide.tagline": "Aprender la síntesis de péptidos, de los grupos protectores a la fase sólida.",
|
|
136
|
+
"site.optics.tagline": "Colocar lentes y espejos en un banco, y seguir la luz hasta la imagen.",
|
|
137
|
+
"site.circuits.tagline": "Conectar pilas, bombillas y resistencias, y leer lo que marcan los medidores.",
|
|
138
|
+
"site.mechanics.tagline": "Poner un bloque en un plano inclinado o en una polea, y ver cómo se suman las fuerzas.",
|
|
134
139
|
"share.button": "Compartir",
|
|
135
140
|
"share.buttonTitle": "Compartir un enlace a esta página, o incrustarla en su propio sitio",
|
|
136
141
|
"share.dialogTitleFor": "Compartir o incrustar — {title}",
|
|
@@ -1054,5 +1059,9 @@
|
|
|
1054
1059
|
"folder.create": "Crear",
|
|
1055
1060
|
"folder.folderTaken": "Aquí ya hay una carpeta llamada {name}: elija otro nombre.",
|
|
1056
1061
|
"folder.openFolder": "Abrir la carpeta {folder}",
|
|
1057
|
-
"folder.found": "En {path}"
|
|
1062
|
+
"folder.found": "En {path}",
|
|
1063
|
+
"send.label": "Enviar a",
|
|
1064
|
+
"send.heading": "Enviar {what} a",
|
|
1065
|
+
"send.none": "Nada de esta página puede enviarse todavía a otra herramienta.",
|
|
1066
|
+
"send.blocked": "El navegador bloqueó la nueva pestaña: permita las ventanas emergentes para este sitio y vuelva a enviar."
|
|
1058
1067
|
}
|
package/src/locales/fr.json
CHANGED
|
@@ -126,11 +126,16 @@
|
|
|
126
126
|
"site.chembio.tagline": "Les produits naturels, et les organismes où ils ont été trouvés.",
|
|
127
127
|
"site.wikidata.tagline": "La chimie des infobox de Wikipédia, interrogeable par structure.",
|
|
128
128
|
"site.mz.tagline": "Des spectres de masse, classés selon la façon dont ils ont été mesurés.",
|
|
129
|
+
"site.plot.tagline": "Tracer des tableaux et des spectres en graphiques aux dimensions et au style d’une revue.",
|
|
130
|
+
"site.ml.tagline": "Apprentissage automatique sur des spectres, dans le navigateur.",
|
|
129
131
|
"site.uv-vis.tagline": "Superposer des spectres UV-visible et relever chaque λmax.",
|
|
130
132
|
"site.xps.tagline": "Lire, ajuster et prédire des spectres de photoélectrons X.",
|
|
131
133
|
"site.biodraw.tagline": "Dessiner cellules et membranes, et y ancrer des protéines.",
|
|
132
134
|
"site.diagram.tagline": "Dessiner des logigrammes et des schémas-blocs, avec des flèches qui suivent les blocs.",
|
|
133
135
|
"site.peptide.tagline": "Apprendre la synthèse peptidique, des groupes protecteurs à la phase solide.",
|
|
136
|
+
"site.optics.tagline": "Placer lentilles et miroirs sur un banc, et suivre la lumière jusqu'à l'image.",
|
|
137
|
+
"site.circuits.tagline": "Câbler piles, ampoules et résistances, et lire ce qu'indiquent les appareils.",
|
|
138
|
+
"site.mechanics.tagline": "Poser un bloc sur un plan incliné ou à une poulie, et voir les forces s'additionner.",
|
|
134
139
|
"share.button": "Partager",
|
|
135
140
|
"share.buttonTitle": "Partager un lien vers cette page, ou l'intégrer à votre propre site",
|
|
136
141
|
"share.dialogTitleFor": "Partager ou intégrer — {title}",
|
|
@@ -1054,5 +1059,9 @@
|
|
|
1054
1059
|
"folder.create": "Créer",
|
|
1055
1060
|
"folder.folderTaken": "Un dossier s’appelle déjà {name} ici : choisissez un autre nom.",
|
|
1056
1061
|
"folder.openFolder": "Ouvrir le dossier {folder}",
|
|
1057
|
-
"folder.found": "Dans {path}"
|
|
1062
|
+
"folder.found": "Dans {path}",
|
|
1063
|
+
"send.label": "Envoyer vers",
|
|
1064
|
+
"send.heading": "Envoyer {what} vers",
|
|
1065
|
+
"send.none": "Rien sur cette page ne peut encore être envoyé à un autre outil.",
|
|
1066
|
+
"send.blocked": "Le navigateur a bloqué le nouvel onglet : autorisez les fenêtres pour ce site, puis envoyez à nouveau."
|
|
1058
1067
|
}
|
package/src/locales/it.json
CHANGED
|
@@ -126,11 +126,16 @@
|
|
|
126
126
|
"site.chembio.tagline": "Prodotti naturali, e gli organismi in cui sono stati trovati.",
|
|
127
127
|
"site.wikidata.tagline": "La chimica delle infobox di Wikipedia, ricercabile per struttura.",
|
|
128
128
|
"site.mz.tagline": "Spettri di massa, classificati in base a come sono stati misurati.",
|
|
129
|
+
"site.plot.tagline": "Tracciare tabelle e spettri come grafici con le dimensioni e lo stile di una rivista.",
|
|
130
|
+
"site.ml.tagline": "Apprendimento automatico sugli spettri, nel browser.",
|
|
129
131
|
"site.uv-vis.tagline": "Sovrapporre spettri UV-vis e leggere ogni λmax.",
|
|
130
132
|
"site.xps.tagline": "Leggere, adattare e prevedere spettri fotoelettronici a raggi X.",
|
|
131
133
|
"site.biodraw.tagline": "Disegnare cellule e membrane, e ancorarvi delle proteine.",
|
|
132
134
|
"site.diagram.tagline": "Disegnare diagrammi di flusso e a blocchi, con frecce che seguono i blocchi.",
|
|
133
135
|
"site.peptide.tagline": "Imparare la sintesi dei peptidi, dai gruppi protettivi alla fase solida.",
|
|
136
|
+
"site.optics.tagline": "Disporre lenti e specchi su un banco, e seguire la luce fino all'immagine.",
|
|
137
|
+
"site.circuits.tagline": "Collegare pile, lampadine e resistenze, e leggere ciò che segnano gli strumenti.",
|
|
138
|
+
"site.mechanics.tagline": "Mettere un blocco su un piano inclinato o a una carrucola, e vedere le forze sommarsi.",
|
|
134
139
|
"share.button": "Condividi",
|
|
135
140
|
"share.buttonTitle": "Condividere un link a questa pagina, o incorporarla nel proprio sito",
|
|
136
141
|
"share.dialogTitleFor": "Condividere o incorporare — {title}",
|
|
@@ -1054,5 +1059,9 @@
|
|
|
1054
1059
|
"folder.create": "Crea",
|
|
1055
1060
|
"folder.folderTaken": "Qui c’è già una cartella chiamata {name}: scegli un altro nome.",
|
|
1056
1061
|
"folder.openFolder": "Apri la cartella {folder}",
|
|
1057
|
-
"folder.found": "In {path}"
|
|
1062
|
+
"folder.found": "In {path}",
|
|
1063
|
+
"send.label": "Invia a",
|
|
1064
|
+
"send.heading": "Invia {what} a",
|
|
1065
|
+
"send.none": "Nulla di questa pagina può ancora essere inviato a un altro strumento.",
|
|
1066
|
+
"send.blocked": "Il browser ha bloccato la nuova scheda: consenti i pop-up per questo sito, poi invia di nuovo."
|
|
1058
1067
|
}
|