react-cheminfo 0.39.0 → 0.39.1
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/share/ui/SharePreview.d.ts.map +1 -1
- package/lib/share/ui/SharePreview.js +25 -0
- package/lib/share/ui/SharePreview.js.map +1 -1
- package/lib/share/ui/useShareRegionReports.d.ts.map +1 -1
- package/lib/share/ui/useShareRegionReports.js +41 -12
- package/lib/share/ui/useShareRegionReports.js.map +1 -1
- package/package.json +1 -1
- package/src/share/ui/SharePreview.tsx +31 -0
- package/src/share/ui/useShareRegionReports.ts +39 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharePreview.d.ts","sourceRoot":"","sources":["../../../src/share/ui/SharePreview.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SharePreview.d.ts","sourceRoot":"","sources":["../../../src/share/ui/SharePreview.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAC;AA6BzD,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACpD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAyInE"}
|
|
@@ -10,6 +10,10 @@ import { SHARE_REGIONS_REQUEST, readShareRegions, sharePreviewAddress, sharePrev
|
|
|
10
10
|
import { SharePreviewDevices } from "./SharePreviewDevices.js";
|
|
11
11
|
/** Room the window's own bar takes, which the page is not scaled into. */
|
|
12
12
|
const CHROME_HEIGHT = 26;
|
|
13
|
+
/** How often the framed page is asked again while it has answered nothing. */
|
|
14
|
+
const ASK_INTERVAL = 300;
|
|
15
|
+
/** How many times, so a page with nothing to report is left alone. */
|
|
16
|
+
const ASK_LIMIT = 10;
|
|
13
17
|
/**
|
|
14
18
|
* The page as the link hands it out, live, beside the options that write it.
|
|
15
19
|
*
|
|
@@ -65,6 +69,27 @@ export function SharePreview(props) {
|
|
|
65
69
|
useEffect(() => {
|
|
66
70
|
mark.current?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
67
71
|
}, [highlight?.part]);
|
|
72
|
+
// The frame's own load says the document is there, never that the page it
|
|
73
|
+
// builds is listening: a React tree mounts in a task of its own, after it.
|
|
74
|
+
// So the question is repeated until it is answered — there is no event on
|
|
75
|
+
// this side to wait for, and a page that answers nothing is a page with no
|
|
76
|
+
// parts to point at, which costs ten messages and stops.
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (regions.length > 0)
|
|
79
|
+
return undefined;
|
|
80
|
+
let asked = 0;
|
|
81
|
+
const timer = setInterval(() => {
|
|
82
|
+
asked += 1;
|
|
83
|
+
if (asked > ASK_LIMIT) {
|
|
84
|
+
clearInterval(timer);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
frame.current?.contentWindow?.postMessage({ type: SHARE_REGIONS_REQUEST }, '*');
|
|
88
|
+
}, ASK_INTERVAL);
|
|
89
|
+
return () => {
|
|
90
|
+
clearInterval(timer);
|
|
91
|
+
};
|
|
92
|
+
}, [regions, src]);
|
|
68
93
|
return (_jsxs("section", { className: "share-preview", "aria-label": t('share.preview'), children: [_jsxs("header", { className: "share-preview__header", children: [_jsxs(H6, { className: "share-preview__label", children: [_jsx(Icon, { icon: "eye-open", size: 13 }), t('share.preview'), _jsx(HelpIcon, { content: help })] }), _jsx(SharePreviewDevices, { value: device, onChange: setDevice, windowSize: windowSize })] }), _jsx("div", { className: "share-preview__stage", ref: stage, children: _jsxs("div", { className: "share-preview__device", style: { width: page.width * scale }, children: [_jsxs("div", { className: "share-preview__chrome", children: [_jsx(Icon, { icon: "eye-open", size: 11 }), _jsx("span", { className: "share-preview__address", children: sharePreviewAddress(url) }), _jsx("span", { className: "share-preview__size", children: sizeNote(page.width, page.height, scale) })] }), _jsxs("div", { className: "share-preview__page", style: { height: page.height * scale }, children: [_jsx("iframe", { ref: frame, className: "share-preview__frame", src: src, title: title, style: frameStyle(page.width, page.height, scale), onLoad: () => {
|
|
69
94
|
// What the page before it reported is where its own parts
|
|
70
95
|
// were, so it is dropped rather than drawn over this one.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharePreview.js","sourceRoot":"","sources":["../../../src/share/ui/SharePreview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA2B,CAAC;AAEhE,0EAA0E;AAC1E,MAAM,aAAa,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"SharePreview.js","sourceRoot":"","sources":["../../../src/share/ui/SharePreview.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,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ts","sourceRoot":"","sources":["../../../src/share/ui/useShareRegionReports.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"useShareRegionReports.d.ts","sourceRoot":"","sources":["../../../src/share/ui/useShareRegionReports.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAiE1E"}
|
|
@@ -29,19 +29,46 @@ export function useShareRegionReports(hidden) {
|
|
|
29
29
|
if (!marking)
|
|
30
30
|
return undefined;
|
|
31
31
|
const host = globalThis.parent;
|
|
32
|
+
let scheduled = 0;
|
|
33
|
+
let reported = '';
|
|
32
34
|
function report() {
|
|
33
|
-
|
|
35
|
+
scheduled = 0;
|
|
36
|
+
const regions = measureRegions();
|
|
37
|
+
// A page that is drawing — a structure, a result, a chart — mutates many
|
|
38
|
+
// times a second while its boxes stay where they are, and every message
|
|
39
|
+
// sent re-renders the dialog on the other side. Only a move is news.
|
|
40
|
+
const signature = JSON.stringify(regions);
|
|
41
|
+
if (signature === reported)
|
|
42
|
+
return;
|
|
43
|
+
reported = signature;
|
|
44
|
+
host.postMessage({ type: SHARE_REGIONS_MESSAGE, regions }, '*');
|
|
45
|
+
}
|
|
46
|
+
// A search that returns, a structure that draws and a font that lands all
|
|
47
|
+
// move the boxes within a frame of each other, so the page is measured
|
|
48
|
+
// once after them rather than once per notification.
|
|
49
|
+
function schedule() {
|
|
50
|
+
if (scheduled === 0)
|
|
51
|
+
scheduled = requestAnimationFrame(report);
|
|
34
52
|
}
|
|
35
53
|
// A chart, a web font or a structure drawn after mount all move the boxes,
|
|
36
|
-
// so the page is measured again whenever anything in it
|
|
37
|
-
// than once, on a deadline it would lose.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
// so the page is measured again whenever anything in it changes rather
|
|
55
|
+
// than once, on a deadline it would lose. Watching its size is not enough:
|
|
56
|
+
// a page laid out to the height of the viewport keeps that height while a
|
|
57
|
+
// result appears inside a column of it, and the part nobody measured is
|
|
58
|
+
// the one the reader is pointing at.
|
|
59
|
+
const resizes = new ResizeObserver(schedule);
|
|
60
|
+
resizes.observe(document.documentElement);
|
|
61
|
+
resizes.observe(document.body);
|
|
62
|
+
const mutations = new MutationObserver(schedule);
|
|
63
|
+
mutations.observe(document.body, { childList: true, subtree: true });
|
|
64
|
+
globalThis.addEventListener('resize', schedule);
|
|
41
65
|
report();
|
|
42
66
|
return () => {
|
|
43
|
-
|
|
44
|
-
|
|
67
|
+
if (scheduled !== 0)
|
|
68
|
+
cancelAnimationFrame(scheduled);
|
|
69
|
+
resizes.disconnect();
|
|
70
|
+
mutations.disconnect();
|
|
71
|
+
globalThis.removeEventListener('resize', schedule);
|
|
45
72
|
};
|
|
46
73
|
}, [marking, hidden]);
|
|
47
74
|
return marking;
|
|
@@ -60,12 +87,14 @@ function measureRegions() {
|
|
|
60
87
|
const box = range.getBoundingClientRect();
|
|
61
88
|
if (box.width === 0 || box.height === 0)
|
|
62
89
|
continue;
|
|
90
|
+
// Rounded, so a layout that settles half a pixel to the left is not
|
|
91
|
+
// reported as a part that moved.
|
|
63
92
|
regions.push({
|
|
64
93
|
part,
|
|
65
|
-
x: box.x + globalThis.scrollX,
|
|
66
|
-
y: box.y + globalThis.scrollY,
|
|
67
|
-
width: box.width,
|
|
68
|
-
height: box.height,
|
|
94
|
+
x: Math.round(box.x + globalThis.scrollX),
|
|
95
|
+
y: Math.round(box.y + globalThis.scrollY),
|
|
96
|
+
width: Math.round(box.width),
|
|
97
|
+
height: Math.round(box.height),
|
|
69
98
|
});
|
|
70
99
|
}
|
|
71
100
|
return regions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useShareRegionReports.js","sourceRoot":"","sources":["../../../src/share/ui/useShareRegionReports.ts"],"names":[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,SAAS;YAAE,SAAS;QACjC,2EAA2E;QAC3E,8DAA8D;QAC9D,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,qBAAqB,EAAE,CAAC;QAC1C,IAAI,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAClD,oEAAoE;QACpE,iCAAiC;QACjC,OAAO,CAAC,IAAI,CAAC;YACX,IAAI;YACJ,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC;YACzC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC;YACzC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;YAC5B,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cheminfo",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React components, hooks and framework-free helpers shared by the cheminfo sites: site chrome, citations, sharing, routing, pedagogy, charts, and the structure, orbital and 3D molecule viewers",
|
|
6
6
|
"author": "Luc Patiny",
|
|
@@ -22,6 +22,12 @@ import { SharePreviewDevices } from './SharePreviewDevices.tsx';
|
|
|
22
22
|
/** Room the window's own bar takes, which the page is not scaled into. */
|
|
23
23
|
const CHROME_HEIGHT = 26;
|
|
24
24
|
|
|
25
|
+
/** How often the framed page is asked again while it has answered nothing. */
|
|
26
|
+
const ASK_INTERVAL = 300;
|
|
27
|
+
|
|
28
|
+
/** How many times, so a page with nothing to report is left alone. */
|
|
29
|
+
const ASK_LIMIT = 10;
|
|
30
|
+
|
|
25
31
|
export interface SharePreviewProps {
|
|
26
32
|
/** The address the frame loads — the link as it stands. */
|
|
27
33
|
url: string;
|
|
@@ -97,6 +103,31 @@ export function SharePreview(props: SharePreviewProps): ReactElement {
|
|
|
97
103
|
mark.current?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
98
104
|
}, [highlight?.part]);
|
|
99
105
|
|
|
106
|
+
// The frame's own load says the document is there, never that the page it
|
|
107
|
+
// builds is listening: a React tree mounts in a task of its own, after it.
|
|
108
|
+
// So the question is repeated until it is answered — there is no event on
|
|
109
|
+
// this side to wait for, and a page that answers nothing is a page with no
|
|
110
|
+
// parts to point at, which costs ten messages and stops.
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (regions.length > 0) return undefined;
|
|
113
|
+
let asked = 0;
|
|
114
|
+
const timer = setInterval(() => {
|
|
115
|
+
asked += 1;
|
|
116
|
+
if (asked > ASK_LIMIT) {
|
|
117
|
+
clearInterval(timer);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
frame.current?.contentWindow?.postMessage(
|
|
121
|
+
{ type: SHARE_REGIONS_REQUEST },
|
|
122
|
+
'*',
|
|
123
|
+
);
|
|
124
|
+
}, ASK_INTERVAL);
|
|
125
|
+
|
|
126
|
+
return () => {
|
|
127
|
+
clearInterval(timer);
|
|
128
|
+
};
|
|
129
|
+
}, [regions, src]);
|
|
130
|
+
|
|
100
131
|
return (
|
|
101
132
|
<section className="share-preview" aria-label={t('share.preview')}>
|
|
102
133
|
<header className="share-preview__header">
|
|
@@ -33,25 +33,47 @@ export function useShareRegionReports(hidden: ReadonlySet<string>): boolean {
|
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
if (!marking) return undefined;
|
|
35
35
|
const host = globalThis.parent;
|
|
36
|
+
let scheduled = 0;
|
|
37
|
+
let reported = '';
|
|
36
38
|
|
|
37
39
|
function report(): void {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
scheduled = 0;
|
|
41
|
+
const regions = measureRegions();
|
|
42
|
+
// A page that is drawing — a structure, a result, a chart — mutates many
|
|
43
|
+
// times a second while its boxes stay where they are, and every message
|
|
44
|
+
// sent re-renders the dialog on the other side. Only a move is news.
|
|
45
|
+
const signature = JSON.stringify(regions);
|
|
46
|
+
if (signature === reported) return;
|
|
47
|
+
reported = signature;
|
|
48
|
+
host.postMessage({ type: SHARE_REGIONS_MESSAGE, regions }, '*');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// A search that returns, a structure that draws and a font that lands all
|
|
52
|
+
// move the boxes within a frame of each other, so the page is measured
|
|
53
|
+
// once after them rather than once per notification.
|
|
54
|
+
function schedule(): void {
|
|
55
|
+
if (scheduled === 0) scheduled = requestAnimationFrame(report);
|
|
42
56
|
}
|
|
43
57
|
|
|
44
58
|
// A chart, a web font or a structure drawn after mount all move the boxes,
|
|
45
|
-
// so the page is measured again whenever anything in it
|
|
46
|
-
// than once, on a deadline it would lose.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
// so the page is measured again whenever anything in it changes rather
|
|
60
|
+
// than once, on a deadline it would lose. Watching its size is not enough:
|
|
61
|
+
// a page laid out to the height of the viewport keeps that height while a
|
|
62
|
+
// result appears inside a column of it, and the part nobody measured is
|
|
63
|
+
// the one the reader is pointing at.
|
|
64
|
+
const resizes = new ResizeObserver(schedule);
|
|
65
|
+
resizes.observe(document.documentElement);
|
|
66
|
+
resizes.observe(document.body);
|
|
67
|
+
const mutations = new MutationObserver(schedule);
|
|
68
|
+
mutations.observe(document.body, { childList: true, subtree: true });
|
|
69
|
+
globalThis.addEventListener('resize', schedule);
|
|
50
70
|
report();
|
|
51
71
|
|
|
52
72
|
return () => {
|
|
53
|
-
|
|
54
|
-
|
|
73
|
+
if (scheduled !== 0) cancelAnimationFrame(scheduled);
|
|
74
|
+
resizes.disconnect();
|
|
75
|
+
mutations.disconnect();
|
|
76
|
+
globalThis.removeEventListener('resize', schedule);
|
|
55
77
|
};
|
|
56
78
|
}, [marking, hidden]);
|
|
57
79
|
|
|
@@ -71,12 +93,14 @@ function measureRegions(): ShareRegion[] {
|
|
|
71
93
|
range.selectNodeContents(marker);
|
|
72
94
|
const box = range.getBoundingClientRect();
|
|
73
95
|
if (box.width === 0 || box.height === 0) continue;
|
|
96
|
+
// Rounded, so a layout that settles half a pixel to the left is not
|
|
97
|
+
// reported as a part that moved.
|
|
74
98
|
regions.push({
|
|
75
99
|
part,
|
|
76
|
-
x: box.x + globalThis.scrollX,
|
|
77
|
-
y: box.y + globalThis.scrollY,
|
|
78
|
-
width: box.width,
|
|
79
|
-
height: box.height,
|
|
100
|
+
x: Math.round(box.x + globalThis.scrollX),
|
|
101
|
+
y: Math.round(box.y + globalThis.scrollY),
|
|
102
|
+
width: Math.round(box.width),
|
|
103
|
+
height: Math.round(box.height),
|
|
80
104
|
});
|
|
81
105
|
}
|
|
82
106
|
|