@isoloop/devtools 0.0.0 → 0.1.0-next.10
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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +105 -0
- package/dist/panel.js +3120 -0
- package/package.json +38 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sabin Pandelovitch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @isoloop/devtools
|
|
2
|
+
|
|
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](https://github.com/isoloop/isoloop/blob/main/docs/guide/inspection.md).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @isoloop/devtools@next @isoloop/host@next
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { connectDevtools } from '@isoloop/devtools';
|
|
11
|
+
|
|
12
|
+
const disconnect = connectDevtools(kernel, { position: 'bottom-right' });
|
|
13
|
+
```
|
|
14
|
+
|
|
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
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Kernel } from "@isoloop/host";
|
|
2
|
+
/** The corner the floating button and the docked panel sit in. @experimental */
|
|
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";
|
|
13
|
+
/** The options of `connectDevtools`: where the panel sits, how its button shows health, and the panel's module and id. @experimental */
|
|
14
|
+
export type DevtoolsOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* The panel isolate's module URL. Defaults to the `panel.js` next to this
|
|
17
|
+
* module in the published package, which `@isoloop/vite` serves in dev and
|
|
18
|
+
* Vite emits in a build. With another bundler, pass the URL it serves
|
|
19
|
+
* `@isoloop/devtools/panel` at.
|
|
20
|
+
*/
|
|
21
|
+
src?: string;
|
|
22
|
+
/** Where the closed button and the opened panel sit. Default `'bottom-right'`. */
|
|
23
|
+
position?: DevtoolsPosition;
|
|
24
|
+
/** How the closed button shows the kernel's health. Default `'ring'`. */
|
|
25
|
+
healthStatus?: HealthStatus;
|
|
26
|
+
/** The panel isolate's id in the kernel. Default `'isoloop-devtools'`. */
|
|
27
|
+
id?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Connects the devtools panel: a surface covering the viewport that takes no
|
|
31
|
+
* pointer events itself (the panel's boxes are `position: fixed`), and the
|
|
32
|
+
* panel isolate in its own worker with the `inspect` grant (never pooled).
|
|
33
|
+
* The floating button and Alt+Shift+D (Option+Shift+D on a Mac) open and
|
|
34
|
+
* close it. Nothing keeps it out of a production build: leave the call out of
|
|
35
|
+
* production code yourself.
|
|
36
|
+
*
|
|
37
|
+
* @param kernel The kernel to inspect.
|
|
38
|
+
* @param o Where the panel sits, how its button shows health, and the
|
|
39
|
+
* panel's module and id. Default: all defaults.
|
|
40
|
+
* @returns A function that disconnects: it stops the panel isolate and
|
|
41
|
+
* removes its surface, resolving once the worker is gone.
|
|
42
|
+
* @throws {Error} When an isolate with the panel's `id` already exists, for
|
|
43
|
+
* example a second `connectDevtools` before the first disconnects.
|
|
44
|
+
* @throws {KernelError} `bus_failed` when the bus failed to load its contracts.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { connectDevtools } from '@isoloop/devtools';
|
|
48
|
+
*
|
|
49
|
+
* const disconnect = connectDevtools(kernel, { position: 'bottom-left' });
|
|
50
|
+
* ```
|
|
51
|
+
* @experimental
|
|
52
|
+
*/
|
|
53
|
+
export declare function connectDevtools(kernel: Kernel, o?: DevtoolsOptions): () => Promise<void>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
/** The attribute the panel puts on its open and close buttons. */
|
|
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";
|
|
6
|
+
/** Alt+Shift+D (Option+Shift+D on a Mac) opens and closes the panel. */
|
|
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
|
+
};
|
|
18
|
+
const panelUrl = () => new URL("./panel.js", import.meta.url).href;
|
|
19
|
+
/**
|
|
20
|
+
* A small box in the panel's corner once it has given up, with a Retry. The
|
|
21
|
+
* surface covers the viewport without taking pointer events, so the default
|
|
22
|
+
* fallback would sit unclickable at the top left.
|
|
23
|
+
*/
|
|
24
|
+
const fallbackFor = (position) => (slot, info) => {
|
|
25
|
+
const [v, h] = position.split("-");
|
|
26
|
+
const box = document.createElement("div");
|
|
27
|
+
box.setAttribute("style", `position:fixed;${v}:12px;${h}:12px;pointer-events:auto;padding:8px 10px;border-radius:8px;font:12px/1.4 system-ui,sans-serif;color:#fff;background:#7f1d1d;`);
|
|
28
|
+
box.textContent = "Devtools stopped. ";
|
|
29
|
+
const retry = document.createElement("button");
|
|
30
|
+
retry.type = "button";
|
|
31
|
+
retry.textContent = "Retry";
|
|
32
|
+
retry.addEventListener("click", info.respawn);
|
|
33
|
+
box.append(retry);
|
|
34
|
+
slot.append(box);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Connects the devtools panel: a surface covering the viewport that takes no
|
|
38
|
+
* pointer events itself (the panel's boxes are `position: fixed`), and the
|
|
39
|
+
* panel isolate in its own worker with the `inspect` grant (never pooled).
|
|
40
|
+
* The floating button and Alt+Shift+D (Option+Shift+D on a Mac) open and
|
|
41
|
+
* close it. Nothing keeps it out of a production build: leave the call out of
|
|
42
|
+
* production code yourself.
|
|
43
|
+
*
|
|
44
|
+
* @param kernel The kernel to inspect.
|
|
45
|
+
* @param o Where the panel sits, how its button shows health, and the
|
|
46
|
+
* panel's module and id. Default: all defaults.
|
|
47
|
+
* @returns A function that disconnects: it stops the panel isolate and
|
|
48
|
+
* removes its surface, resolving once the worker is gone.
|
|
49
|
+
* @throws {Error} When an isolate with the panel's `id` already exists, for
|
|
50
|
+
* example a second `connectDevtools` before the first disconnects.
|
|
51
|
+
* @throws {KernelError} `bus_failed` when the bus failed to load its contracts.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { connectDevtools } from '@isoloop/devtools';
|
|
55
|
+
*
|
|
56
|
+
* const disconnect = connectDevtools(kernel, { position: 'bottom-left' });
|
|
57
|
+
* ```
|
|
58
|
+
* @experimental
|
|
59
|
+
*/
|
|
60
|
+
function connectDevtools(kernel, o = {}) {
|
|
61
|
+
const id = o.id ?? "isoloop-devtools";
|
|
62
|
+
const position = o.position ?? "bottom-right";
|
|
63
|
+
const healthStatus = o.healthStatus ?? "ring";
|
|
64
|
+
const surface = document.createElement("div");
|
|
65
|
+
surface.setAttribute("data-isoloop-devtools", "");
|
|
66
|
+
surface.setAttribute("style", "position:fixed;inset:0;z-index:2147483647;pointer-events:none;display:block;");
|
|
67
|
+
document.body.append(surface);
|
|
68
|
+
kernel.spawn({
|
|
69
|
+
id,
|
|
70
|
+
src: o.src ?? panelUrl(),
|
|
71
|
+
surface,
|
|
72
|
+
config: {
|
|
73
|
+
position,
|
|
74
|
+
healthStatus
|
|
75
|
+
},
|
|
76
|
+
grants: {
|
|
77
|
+
publish: [],
|
|
78
|
+
subscribe: [],
|
|
79
|
+
inspect: true
|
|
80
|
+
},
|
|
81
|
+
fallback: fallbackFor(position)
|
|
82
|
+
});
|
|
83
|
+
const toggle = () => {
|
|
84
|
+
const button = surface.querySelector("iso-surface")?.shadowRoot?.querySelector(TOGGLE);
|
|
85
|
+
if (button instanceof HTMLElement) button.click();
|
|
86
|
+
};
|
|
87
|
+
surface.addEventListener("click", onCopy);
|
|
88
|
+
const onKey = (e) => {
|
|
89
|
+
if (!isShortcut(e)) return;
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
toggle();
|
|
92
|
+
};
|
|
93
|
+
window.addEventListener("keydown", onKey);
|
|
94
|
+
let gone;
|
|
95
|
+
return () => {
|
|
96
|
+
gone ??= (async () => {
|
|
97
|
+
window.removeEventListener("keydown", onKey);
|
|
98
|
+
surface.removeEventListener("click", onCopy);
|
|
99
|
+
await kernel.stop(id);
|
|
100
|
+
surface.remove();
|
|
101
|
+
})();
|
|
102
|
+
return gone;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export { connectDevtools };
|