@isoloop/devtools 0.1.0-next.7 → 0.1.0-next.8
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 +6 -4
- package/dist/index.d.ts +11 -0
- package/dist/index.js +19 -1
- package/dist/panel.js +1652 -197
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# @isoloop/devtools
|
|
2
2
|
|
|
3
|
-
A devtools panel for Isoloop, drawn by a visual isolate in its own worker, so a crash or hang in the panel never touches the app. It reads the inspection feed (ADR 0020)
|
|
3
|
+
**Experimental.** A devtools panel for [Isoloop](https://github.com/isoloop/isoloop), drawn by a visual isolate in its own worker, so a crash or hang in the panel never touches the app. It reads the inspection feed ([ADR 0020](https://github.com/isoloop/isoloop/blob/main/docs/adr/0020-inspection-feed.md)).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @isoloop/devtools@next @isoloop/host@next
|
|
7
|
+
```
|
|
4
8
|
|
|
5
9
|
```ts
|
|
6
10
|
import { connectDevtools } from '@isoloop/devtools';
|
|
@@ -8,6 +12,4 @@ import { connectDevtools } from '@isoloop/devtools';
|
|
|
8
12
|
const disconnect = connectDevtools(kernel, { position: 'bottom-right' });
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Alt+Shift+D opens and closes it. Its open state, size and corner are kept in IndexedDB.
|
|
15
|
+
The options, the panel's tabs, the bundler setup and the limits are in the [devtools guide](https://github.com/isoloop/isoloop/blob/main/docs/guide/devtools.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { Kernel } from "@isoloop/host";
|
|
2
2
|
/** The corner the floating button and the docked panel sit in. @experimental */
|
|
3
3
|
export type DevtoolsPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
4
|
+
/**
|
|
5
|
+
* How the closed button shows the kernel's health:
|
|
6
|
+
* - `'ring'`: a ring of twelve arcs, one stretch of isolates each, coloured by
|
|
7
|
+
* their worst state, with a wave of brightness running round it;
|
|
8
|
+
* - `'radar'`: the same ring, with the logo filled by the same twelve colours;
|
|
9
|
+
* - `'off'`: a plain white ring, with no status on the button.
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
export type HealthStatus = "ring" | "radar" | "off";
|
|
4
13
|
/** @experimental */
|
|
5
14
|
export type DevtoolsOptions = {
|
|
6
15
|
/**
|
|
@@ -12,6 +21,8 @@ export type DevtoolsOptions = {
|
|
|
12
21
|
src?: string;
|
|
13
22
|
/** Where the closed button and the opened panel sit. Default `'bottom-right'`. */
|
|
14
23
|
position?: DevtoolsPosition;
|
|
24
|
+
/** How the closed button shows the kernel's health. Default `'ring'`. */
|
|
25
|
+
healthStatus?: HealthStatus;
|
|
15
26
|
/** The panel isolate's id in the kernel. Default `'isoloop-devtools'`. */
|
|
16
27
|
id?: string;
|
|
17
28
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
/** The attribute the panel puts on its open and close buttons. */
|
|
3
3
|
const TOGGLE = "[data-isoloop-devtools-toggle]";
|
|
4
|
+
/** The attribute a panel button puts its text on, for the page to copy. */
|
|
5
|
+
const COPY = "data-isoloop-copy";
|
|
4
6
|
/** Alt+Shift+D (Option+Shift+D on a Mac) opens and closes the panel. */
|
|
5
7
|
const isShortcut = (e) => e.altKey && e.shiftKey && !e.ctrlKey && !e.metaKey && e.code === "KeyD";
|
|
8
|
+
/**
|
|
9
|
+
* A page-side clipboard write for the panel's Copy buttons: the panel runs in a
|
|
10
|
+
* worker, which has none. The button carries its text; the click is the user's
|
|
11
|
+
* own, so the browser allows the write.
|
|
12
|
+
*/
|
|
13
|
+
const onCopy = (e) => {
|
|
14
|
+
const button = e.composedPath().find((n) => n instanceof Element && n.hasAttribute(COPY));
|
|
15
|
+
const text = button instanceof Element ? button.getAttribute(COPY) : null;
|
|
16
|
+
if (text !== null) navigator.clipboard.writeText(text).catch(() => void 0);
|
|
17
|
+
};
|
|
6
18
|
const panelUrl = () => new URL("./panel.js", import.meta.url).href;
|
|
7
19
|
/**
|
|
8
20
|
* A small box in the panel's corner once it has given up, with a Retry. The
|
|
@@ -41,6 +53,7 @@ const fallbackFor = (position) => (slot, info) => {
|
|
|
41
53
|
function connectDevtools(kernel, o = {}) {
|
|
42
54
|
const id = o.id ?? "isoloop-devtools";
|
|
43
55
|
const position = o.position ?? "bottom-right";
|
|
56
|
+
const healthStatus = o.healthStatus ?? "ring";
|
|
44
57
|
const surface = document.createElement("div");
|
|
45
58
|
surface.setAttribute("data-isoloop-devtools", "");
|
|
46
59
|
surface.setAttribute("style", "position:fixed;inset:0;z-index:2147483647;pointer-events:none;display:block;");
|
|
@@ -49,7 +62,10 @@ function connectDevtools(kernel, o = {}) {
|
|
|
49
62
|
id,
|
|
50
63
|
src: o.src ?? panelUrl(),
|
|
51
64
|
surface,
|
|
52
|
-
config: {
|
|
65
|
+
config: {
|
|
66
|
+
position,
|
|
67
|
+
healthStatus
|
|
68
|
+
},
|
|
53
69
|
grants: {
|
|
54
70
|
publish: [],
|
|
55
71
|
subscribe: [],
|
|
@@ -61,6 +77,7 @@ function connectDevtools(kernel, o = {}) {
|
|
|
61
77
|
const button = surface.querySelector("iso-surface")?.shadowRoot?.querySelector(TOGGLE);
|
|
62
78
|
if (button instanceof HTMLElement) button.click();
|
|
63
79
|
};
|
|
80
|
+
surface.addEventListener("click", onCopy);
|
|
64
81
|
const onKey = (e) => {
|
|
65
82
|
if (!isShortcut(e)) return;
|
|
66
83
|
e.preventDefault();
|
|
@@ -71,6 +88,7 @@ function connectDevtools(kernel, o = {}) {
|
|
|
71
88
|
return () => {
|
|
72
89
|
gone ??= (async () => {
|
|
73
90
|
window.removeEventListener("keydown", onKey);
|
|
91
|
+
surface.removeEventListener("click", onCopy);
|
|
74
92
|
await kernel.stop(id);
|
|
75
93
|
surface.remove();
|
|
76
94
|
})();
|