@isoloop/devtools 0.0.0 → 0.1.0-next.4

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 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,13 @@
1
+ # @isoloop/devtools
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) through the `inspect` grant. `@experimental`.
4
+
5
+ ```ts
6
+ import { connectDevtools } from '@isoloop/devtools';
7
+ // With @isoloop/vite, emit the panel like your own isolates:
8
+ import panel from '@isoloop/devtools/panel?isolate';
9
+
10
+ const disconnect = connectDevtools(kernel, { src: panel, position: 'bottom-right' });
11
+ ```
12
+
13
+ Alt+Shift+D opens and closes it. Its open state, size and corner are kept in IndexedDB.
@@ -0,0 +1,35 @@
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
+ /** @experimental */
5
+ export type DevtoolsOptions = {
6
+ /**
7
+ * The panel isolate's module URL. Defaults to the `panel.js` next to this
8
+ * module in the published package. With `@isoloop/vite`, pass
9
+ * `import panel from '@isoloop/devtools/panel?isolate'` instead, so the
10
+ * build emits it like the app's own isolates.
11
+ */
12
+ src?: string;
13
+ /** Where the closed button and the opened panel sit. Default `'bottom-right'`. */
14
+ position?: DevtoolsPosition;
15
+ /** The panel isolate's id in the kernel. Default `'isoloop-devtools'`. */
16
+ id?: string;
17
+ };
18
+ /**
19
+ * Connects the devtools panel: a surface covering the viewport that takes no
20
+ * pointer events itself (the panel's boxes are `position: fixed`), and the
21
+ * panel isolate in its own worker with the `inspect` grant (never pooled).
22
+ * Alt+Shift+D toggles it. Guide: `docs/guide/devtools.md`.
23
+ *
24
+ * ```ts
25
+ * import { connectDevtools } from '@isoloop/devtools';
26
+ * const disconnect = connectDevtools(kernel, { position: 'bottom-left' });
27
+ * ```
28
+ *
29
+ * The floating button and Alt+Shift+D open and close it.
30
+ *
31
+ * @returns A function that disconnects: it stops the panel isolate and
32
+ * removes its surface, resolving once the worker is gone.
33
+ * @experimental
34
+ */
35
+ export declare function connectDevtools(kernel: Kernel, o?: DevtoolsOptions): () => Promise<void>;
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ // src/index.ts
2
+ /** The attribute the panel puts on its open and close buttons. */
3
+ const TOGGLE = "[data-isoloop-devtools-toggle]";
4
+ /** Alt+Shift+D (Option+Shift+D on a Mac) opens and closes the panel. */
5
+ const isShortcut = (e) => e.altKey && e.shiftKey && !e.ctrlKey && !e.metaKey && e.code === "KeyD";
6
+ const panelUrl = () => new URL("./panel.js", import.meta.url).href;
7
+ /**
8
+ * A small box in the panel's corner once it has given up, with a Retry. The
9
+ * surface covers the viewport without taking pointer events, so the default
10
+ * fallback would sit unclickable at the top left.
11
+ */
12
+ const fallbackFor = (position) => (slot, info) => {
13
+ const [v, h] = position.split("-");
14
+ const box = document.createElement("div");
15
+ 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;`);
16
+ box.textContent = "Devtools stopped. ";
17
+ const retry = document.createElement("button");
18
+ retry.type = "button";
19
+ retry.textContent = "Retry";
20
+ retry.addEventListener("click", info.respawn);
21
+ box.append(retry);
22
+ slot.append(box);
23
+ };
24
+ /**
25
+ * Connects the devtools panel: a surface covering the viewport that takes no
26
+ * pointer events itself (the panel's boxes are `position: fixed`), and the
27
+ * panel isolate in its own worker with the `inspect` grant (never pooled).
28
+ * Alt+Shift+D toggles it. Guide: `docs/guide/devtools.md`.
29
+ *
30
+ * ```ts
31
+ * import { connectDevtools } from '@isoloop/devtools';
32
+ * const disconnect = connectDevtools(kernel, { position: 'bottom-left' });
33
+ * ```
34
+ *
35
+ * The floating button and Alt+Shift+D open and close it.
36
+ *
37
+ * @returns A function that disconnects: it stops the panel isolate and
38
+ * removes its surface, resolving once the worker is gone.
39
+ * @experimental
40
+ */
41
+ function connectDevtools(kernel, o = {}) {
42
+ const id = o.id ?? "isoloop-devtools";
43
+ const position = o.position ?? "bottom-right";
44
+ const surface = document.createElement("div");
45
+ surface.setAttribute("data-isoloop-devtools", "");
46
+ surface.setAttribute("style", "position:fixed;inset:0;z-index:2147483647;pointer-events:none;display:block;");
47
+ document.body.append(surface);
48
+ kernel.spawn({
49
+ id,
50
+ src: o.src ?? panelUrl(),
51
+ surface,
52
+ config: { position },
53
+ grants: {
54
+ publish: [],
55
+ subscribe: [],
56
+ inspect: true
57
+ },
58
+ fallback: fallbackFor(position)
59
+ });
60
+ const toggle = () => {
61
+ const button = surface.querySelector("iso-surface")?.shadowRoot?.querySelector(TOGGLE);
62
+ if (button instanceof HTMLElement) button.click();
63
+ };
64
+ const onKey = (e) => {
65
+ if (!isShortcut(e)) return;
66
+ e.preventDefault();
67
+ toggle();
68
+ };
69
+ window.addEventListener("keydown", onKey);
70
+ let gone;
71
+ return () => {
72
+ gone ??= (async () => {
73
+ window.removeEventListener("keydown", onKey);
74
+ await kernel.stop(id);
75
+ surface.remove();
76
+ })();
77
+ return gone;
78
+ };
79
+ }
80
+ export { connectDevtools };