@hamur/devtools 0.0.0-stage → 0.0.2

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.
Files changed (134) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +24 -2
  3. package/dist/src/client.js +780 -0
  4. package/dist/src/index.js +1711 -0
  5. package/dist/types/src/apps/locator.d.ts +3 -0
  6. package/dist/types/src/bridge.d.ts +8 -0
  7. package/dist/types/src/client.d.ts +3 -0
  8. package/dist/types/src/dev/analyze.d.ts +31 -0
  9. package/dist/types/src/dev/assets.d.ts +33 -0
  10. package/dist/types/src/dev/authz.d.ts +49 -0
  11. package/dist/types/src/dev/bundle.d.ts +22 -0
  12. package/dist/types/src/dev/config.d.ts +24 -0
  13. package/dist/types/src/dev/handler.d.ts +20 -0
  14. package/dist/types/src/dev/modules.d.ts +28 -0
  15. package/dist/types/src/dev/overview.d.ts +20 -0
  16. package/dist/types/src/dev/processes.d.ts +4 -0
  17. package/dist/types/src/dev/server-routes.d.ts +7 -0
  18. package/dist/types/src/dev/tasks.d.ts +26 -0
  19. package/dist/types/src/dev/timeline.d.ts +20 -0
  20. package/dist/types/src/dev/virtual.d.ts +9 -0
  21. package/dist/types/src/icons.d.ts +24 -0
  22. package/dist/types/src/index.d.ts +8 -0
  23. package/dist/types/src/locator.d.ts +17 -0
  24. package/dist/types/src/mask.d.ts +8 -0
  25. package/dist/types/src/module.d.ts +27 -0
  26. package/dist/types/src/open-in-editor.d.ts +4 -0
  27. package/dist/types/src/options.d.ts +14 -0
  28. package/dist/types/src/panel/document.d.ts +16 -0
  29. package/dist/types/src/panel/groups.d.ts +14 -0
  30. package/dist/types/src/panel/index.d.ts +1 -0
  31. package/dist/types/src/panel/settings.d.ts +69 -0
  32. package/dist/types/src/panel/style.d.ts +1 -0
  33. package/dist/types/src/panel/ui.d.ts +34 -0
  34. package/dist/types/src/server/authz.d.ts +30 -0
  35. package/dist/types/src/server/index.d.ts +3 -0
  36. package/dist/types/src/server/routes.d.ts +6 -0
  37. package/dist/types/src/server/storage.d.ts +56 -0
  38. package/dist/types/src/source-link.d.ts +2 -0
  39. package/dist/types/src/tabs/analyze-model.d.ts +31 -0
  40. package/dist/types/src/tabs/analyze.d.ts +2 -0
  41. package/dist/types/src/tabs/assets.d.ts +11 -0
  42. package/dist/types/src/tabs/audit-model.d.ts +42 -0
  43. package/dist/types/src/tabs/audit.d.ts +2 -0
  44. package/dist/types/src/tabs/authz-model.d.ts +11 -0
  45. package/dist/types/src/tabs/authz.d.ts +2 -0
  46. package/dist/types/src/tabs/config.d.ts +8 -0
  47. package/dist/types/src/tabs/inspect.d.ts +7 -0
  48. package/dist/types/src/tabs/modules.d.ts +4 -0
  49. package/dist/types/src/tabs/overview.d.ts +2 -0
  50. package/dist/types/src/tabs/pages.d.ts +2 -0
  51. package/dist/types/src/tabs/payload.d.ts +6 -0
  52. package/dist/types/src/tabs/plugins-model.d.ts +15 -0
  53. package/dist/types/src/tabs/plugins.d.ts +2 -0
  54. package/dist/types/src/tabs/seo-model.d.ts +36 -0
  55. package/dist/types/src/tabs/seo.d.ts +2 -0
  56. package/dist/types/src/tabs/server-routes.d.ts +2 -0
  57. package/dist/types/src/tabs/storage.d.ts +13 -0
  58. package/dist/types/src/tabs/tasks-model.d.ts +16 -0
  59. package/dist/types/src/tabs/tasks.d.ts +2 -0
  60. package/dist/types/src/tabs/terminals-model.d.ts +53 -0
  61. package/dist/types/src/tabs/terminals.d.ts +2 -0
  62. package/dist/types/src/tabs/timeline-model.d.ts +58 -0
  63. package/dist/types/src/tabs/timeline.d.ts +2 -0
  64. package/dist/types/src/tester.d.ts +43 -0
  65. package/dist/types/src/toolbar/element.d.ts +28 -0
  66. package/dist/types/src/toolbar/shortcut.d.ts +14 -0
  67. package/dist/types/src/toolbar/style.d.ts +3 -0
  68. package/dist/types/src/view-context.d.ts +13 -0
  69. package/package.json +34 -4
  70. package/src/apps/locator.ts +131 -0
  71. package/src/bridge.ts +172 -0
  72. package/src/client.ts +10 -0
  73. package/src/dev/analyze.ts +128 -0
  74. package/src/dev/assets.ts +208 -0
  75. package/src/dev/authz.ts +162 -0
  76. package/src/dev/bundle.ts +91 -0
  77. package/src/dev/config.ts +132 -0
  78. package/src/dev/handler.ts +161 -0
  79. package/src/dev/modules.ts +60 -0
  80. package/src/dev/overview.ts +57 -0
  81. package/src/dev/processes.ts +34 -0
  82. package/src/dev/server-routes.ts +14 -0
  83. package/src/dev/tasks.ts +93 -0
  84. package/src/dev/timeline.ts +43 -0
  85. package/src/dev/virtual.ts +40 -0
  86. package/src/env.d.ts +21 -0
  87. package/src/icons.ts +48 -0
  88. package/src/index.ts +12 -0
  89. package/src/locator.ts +31 -0
  90. package/src/mask.ts +16 -0
  91. package/src/module.ts +352 -0
  92. package/src/open-in-editor.ts +18 -0
  93. package/src/options.ts +36 -0
  94. package/src/panel/document.ts +60 -0
  95. package/src/panel/groups.ts +41 -0
  96. package/src/panel/index.ts +429 -0
  97. package/src/panel/settings.ts +224 -0
  98. package/src/panel/style.ts +321 -0
  99. package/src/panel/ui.ts +52 -0
  100. package/src/server/authz.ts +110 -0
  101. package/src/server/index.ts +25 -0
  102. package/src/server/routes.ts +51 -0
  103. package/src/server/storage.ts +251 -0
  104. package/src/source-link.ts +29 -0
  105. package/src/tabs/analyze-model.ts +97 -0
  106. package/src/tabs/analyze.ts +217 -0
  107. package/src/tabs/assets.ts +375 -0
  108. package/src/tabs/audit-model.ts +216 -0
  109. package/src/tabs/audit.ts +223 -0
  110. package/src/tabs/authz-model.ts +28 -0
  111. package/src/tabs/authz.ts +337 -0
  112. package/src/tabs/config.ts +250 -0
  113. package/src/tabs/inspect.ts +101 -0
  114. package/src/tabs/modules.ts +58 -0
  115. package/src/tabs/overview.ts +104 -0
  116. package/src/tabs/pages.ts +188 -0
  117. package/src/tabs/payload.ts +224 -0
  118. package/src/tabs/plugins-model.ts +44 -0
  119. package/src/tabs/plugins.ts +95 -0
  120. package/src/tabs/seo-model.ts +140 -0
  121. package/src/tabs/seo.ts +162 -0
  122. package/src/tabs/server-routes.ts +469 -0
  123. package/src/tabs/storage.ts +313 -0
  124. package/src/tabs/tasks-model.ts +59 -0
  125. package/src/tabs/tasks.ts +287 -0
  126. package/src/tabs/terminals-model.ts +127 -0
  127. package/src/tabs/terminals.ts +294 -0
  128. package/src/tabs/timeline-model.ts +200 -0
  129. package/src/tabs/timeline.ts +260 -0
  130. package/src/tester.ts +158 -0
  131. package/src/toolbar/element.ts +428 -0
  132. package/src/toolbar/shortcut.ts +56 -0
  133. package/src/toolbar/style.ts +94 -0
  134. package/src/view-context.ts +93 -0
@@ -0,0 +1,250 @@
1
+ import { defineDevtoolsApp, type DevtoolsAppContext } from "hamur/app"
2
+ import type { ConfigAnswer } from "../dev/config.ts"
3
+ import { holdsPlaceholder, MASKED } from "../mask.ts"
4
+ import { element, tone, UI } from "../panel/ui.ts"
5
+
6
+ const isBranch = (value: unknown): value is Record<string, unknown> =>
7
+ typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length > 0
8
+
9
+ const text = (value: unknown): string => (typeof value === "string" ? value : (JSON.stringify(value) ?? String(value)))
10
+
11
+ /** Every value under the object `value` that is not a non-empty object, with its dot path below `prefix`. */
12
+ export function leaves(value: unknown, prefix: string): Array<[string, unknown]> {
13
+ if (!isBranch(value)) return []
14
+ return Object.entries(value).flatMap(([key, item]): Array<[string, unknown]> => {
15
+ const path = prefix ? `${prefix}.${key}` : key
16
+ return isBranch(item) ? leaves(item, path) : [[path, item]]
17
+ })
18
+ }
19
+
20
+ /** The text typed for a public value, read as JSON; a parse error names the path. */
21
+ export function parseConfigValue(path: string, typed: string): unknown {
22
+ try {
23
+ return JSON.parse(typed)
24
+ } catch (error) {
25
+ throw new Error(
26
+ `The value of ${JSON.stringify(path)} must be JSON: ${error instanceof Error ? error.message : String(error)}`,
27
+ )
28
+ }
29
+ }
30
+
31
+ function section(name: string, title: string, note: string, ...children: Node[]): HTMLElement {
32
+ const box = element(
33
+ "section",
34
+ {},
35
+ element(
36
+ "h2",
37
+ { className: `m-0 ${UI.groupHead}` },
38
+ element("span", { className: "font-medium text-fg-2" }, title),
39
+ element("span", { className: "flex-1" }),
40
+ element("span", { className: "text-fg-4" }, note),
41
+ ),
42
+ ...children,
43
+ )
44
+ box.dataset.section = name
45
+ return box
46
+ }
47
+
48
+ function table(heads: string[], rows: HTMLTableRowElement[]): HTMLTableElement | HTMLParagraphElement {
49
+ if (!rows.length) return element("p", { className: UI.notice }, "None")
50
+ return element(
51
+ "table",
52
+ { className: "w-full border-collapse" },
53
+ element("thead", {}, element("tr", {}, ...heads.map((head) => element("th", { className: UI.th }, head)))),
54
+ element("tbody", {}, ...rows),
55
+ )
56
+ }
57
+
58
+ function cell(key: string, look: string, ...children: (Node | string)[]): HTMLTableCellElement {
59
+ const td = element("td", { className: `${UI.td} ${look}` }, ...children)
60
+ td.dataset.col = key
61
+ return td
62
+ }
63
+
64
+ const PATH = "w-64 font-mono text-sm font-medium text-fg break-all"
65
+ const VALUE = "font-mono text-xs text-fg-2 break-all"
66
+
67
+ function statusLine(): HTMLOutputElement {
68
+ const status = element("output")
69
+ tone(status, false)
70
+ return status
71
+ }
72
+
73
+ function publicRow(ctx: DevtoolsAppContext, path: string, value: unknown): HTMLTableRowElement {
74
+ if (holdsPlaceholder(value)) {
75
+ const row = element("tr", { className: UI.tr }, cell("path", PATH, path), cell("value", VALUE, text(value)))
76
+ row.dataset.path = path
77
+ row.dataset.readonly = ""
78
+ return row
79
+ }
80
+ const input = element("input", {
81
+ type: "text",
82
+ name: "value",
83
+ value: JSON.stringify(value) ?? "null",
84
+ className: `${UI.field} flex-1 font-mono`,
85
+ })
86
+ input.setAttribute("aria-label", `Value of ${path}`)
87
+ const status = statusLine()
88
+ const button = element("button", { type: "submit", className: UI.button }, "Set")
89
+ const form = element("form", { className: "flex items-center gap-1.5" }, input, button, status)
90
+ const row = element("tr", { className: UI.tr }, cell("path", PATH, path), cell("value", "", form))
91
+ row.dataset.path = path
92
+ form.addEventListener("submit", async (event) => {
93
+ event.preventDefault()
94
+ tone(status, false)
95
+ let next: unknown
96
+ try {
97
+ next = parseConfigValue(path, input.value)
98
+ } catch (error) {
99
+ tone(status, true)
100
+ status.textContent = error instanceof Error ? error.message : String(error)
101
+ return
102
+ }
103
+ button.disabled = true
104
+ status.textContent = "Restarting the server process…"
105
+ try {
106
+ await ctx.rpc("devtools:config-runtime", { path, value: next })
107
+ status.textContent = "Set until hamur dev restarts; the next page load reads it"
108
+ row.dataset.saved = ""
109
+ } catch (error) {
110
+ tone(status, true)
111
+ status.textContent = error instanceof Error ? error.message : String(error)
112
+ } finally {
113
+ button.disabled = false
114
+ }
115
+ })
116
+ return row
117
+ }
118
+
119
+ function resetButton(ctx: DevtoolsAppContext): HTMLElement {
120
+ const status = statusLine()
121
+ const button = element("button", { type: "button", className: UI.button }, "Reset edits")
122
+ button.dataset.reset = ""
123
+ button.addEventListener("click", async () => {
124
+ button.disabled = true
125
+ tone(status, false)
126
+ status.textContent = "Restarting the server process…"
127
+ try {
128
+ await ctx.rpc("devtools:config-reset", {})
129
+ status.textContent = "Edits dropped; the next page load reads the config file's values"
130
+ } catch (error) {
131
+ tone(status, true)
132
+ status.textContent = error instanceof Error ? error.message : String(error)
133
+ } finally {
134
+ button.disabled = false
135
+ }
136
+ })
137
+ return element("div", { className: "flex items-center gap-2 px-4 py-2" }, button, status)
138
+ }
139
+
140
+ function privateRow(ctx: DevtoolsAppContext, path: string, value: unknown): HTMLTableRowElement {
141
+ const shown = cell("value", VALUE, text(value))
142
+ const row = element("tr", { className: UI.tr }, cell("path", PATH, path), shown)
143
+ row.dataset.path = path
144
+ if (value !== MASKED) return row
145
+ const button = element("button", { type: "button", className: `${UI.button} ml-2` }, "Reveal")
146
+ button.dataset.reveal = ""
147
+ button.addEventListener("click", async () => {
148
+ button.disabled = true
149
+ try {
150
+ const { value: revealed } = await ctx.rpc<{ value: unknown }>("devtools:config-reveal", { path })
151
+ shown.textContent = text(revealed)
152
+ row.dataset.revealed = ""
153
+ } catch (error) {
154
+ shown.replaceChildren(
155
+ element("span", { className: UI.fail }, error instanceof Error ? error.message : String(error)),
156
+ )
157
+ }
158
+ })
159
+ shown.append(" ", button)
160
+ return row
161
+ }
162
+
163
+ function treeList(value: Record<string, unknown>, prefix: string): HTMLUListElement {
164
+ const list = element("ul", { className: `m-0 ${prefix ? "pl-4" : "px-4 py-1"} list-none font-mono text-xs` })
165
+ for (const [key, item] of Object.entries(value)) {
166
+ const path = prefix ? `${prefix}.${key}` : key
167
+ const li = element("li", { className: "py-0.5" })
168
+ li.dataset.path = path
169
+ if (isBranch(item))
170
+ li.append(
171
+ element(
172
+ "details",
173
+ {},
174
+ element("summary", { className: "cursor-pointer text-fg-2" }, key),
175
+ treeList(item, path),
176
+ ),
177
+ )
178
+ else {
179
+ li.dataset.leaf = `${path} ${text(item)}`.toLowerCase()
180
+ li.append(
181
+ element("span", { className: "text-fg-3" }, key),
182
+ ": ",
183
+ element("code", { className: "text-fg-2" }, text(item)),
184
+ )
185
+ }
186
+ list.append(li)
187
+ }
188
+ return list
189
+ }
190
+
191
+ /** Shows a leaf when its path or value holds `query`, and a branch when one of its leaves shows; a search opens the branches it keeps. */
192
+ export function filterTree(root: HTMLElement, query: string): void {
193
+ const needle = query.trim().toLowerCase()
194
+ for (const li of [...root.querySelectorAll<HTMLLIElement>("li")].reverse()) {
195
+ const leaf = li.dataset.leaf
196
+ if (leaf !== undefined) li.hidden = !leaf.includes(needle)
197
+ else {
198
+ li.hidden = !li.querySelector(":scope > details > ul > li:not([hidden])")
199
+ if (needle) li.querySelector(":scope > details")!.setAttribute("open", "")
200
+ }
201
+ }
202
+ }
203
+
204
+ function tree(name: string, title: string, value: unknown, searchable: boolean): HTMLElement {
205
+ const root = isBranch(value) ? treeList(value, "") : element("p", { className: UI.notice }, "None")
206
+ if (!searchable) return section(name, title, "", root)
207
+ const search = element("input", {
208
+ type: "search",
209
+ placeholder: `Search ${title.toLowerCase()}`,
210
+ className: `${UI.field} w-56 mx-4 my-1.5`,
211
+ })
212
+ search.setAttribute("aria-label", `Search ${title.toLowerCase()}`)
213
+ search.addEventListener("input", () => filterTree(root, search.value))
214
+ return section(name, title, "", search, root)
215
+ }
216
+
217
+ export default defineDevtoolsApp({
218
+ async init(canvas, ctx) {
219
+ let answer: ConfigAnswer
220
+ try {
221
+ answer = await ctx.rpc<ConfigAnswer>("devtools:config", {})
222
+ } catch (error) {
223
+ canvas.append(element("p", { className: UI.error }, error instanceof Error ? error.message : String(error)))
224
+ return
225
+ }
226
+ canvas.className = "flex-1 min-h-0 overflow-auto pb-2"
227
+ canvas.append(
228
+ section(
229
+ "public",
230
+ "runtimeConfig.public",
231
+ "editable until the next restart",
232
+ resetButton(ctx),
233
+ table(
234
+ ["Key", "Value"],
235
+ leaves(answer.runtimeConfig.public, "public").map(([path, value]) => publicRow(ctx, path, value)),
236
+ ),
237
+ ),
238
+ section(
239
+ "private",
240
+ "Private runtime config",
241
+ "server only, masked",
242
+ table(
243
+ ["Key", "Value"],
244
+ leaves(answer.runtimeConfig.private, "").map(([path, value]) => privateRow(ctx, path, value)),
245
+ ),
246
+ ),
247
+ tree("options", "Resolved options", answer.options, true),
248
+ )
249
+ },
250
+ })
@@ -0,0 +1,101 @@
1
+ import { defineDevtoolsApp } from "hamur/app"
2
+ import type { VirtualRow } from "../dev/virtual.ts"
3
+ import { element, pill, UI } from "../panel/ui.ts"
4
+ import { PANEL_CONFIG_ID, type PanelConfig } from "../panel/document.ts"
5
+
6
+ /** The rows whose id holds `text`, ignoring case and surrounding spaces. */
7
+ export const filterVirtual = (rows: readonly VirtualRow[], text: string): VirtualRow[] => {
8
+ const needle = text.trim().toLowerCase()
9
+ return rows.filter((row) => row.id.toLowerCase().includes(needle))
10
+ }
11
+
12
+ /** The inspect page's address below `app.baseURL`; `theme` follows the panel. */
13
+ export const inspectURL = (baseURL: string, theme: string | undefined): string =>
14
+ `${baseURL.replace(/\/+$/, "")}/_hamur/inspect${theme === "light" || theme === "dark" ? `?theme=${theme}` : ""}`
15
+
16
+ const baseURL = (): string => {
17
+ const config = JSON.parse(document.getElementById(PANEL_CONFIG_ID)?.textContent ?? "{}") as Partial<PanelConfig>
18
+ return config.baseURL ?? "/"
19
+ }
20
+
21
+ function virtualElement(row: VirtualRow): HTMLElement {
22
+ const summary = element(
23
+ "summary",
24
+ { className: "flex items-center gap-2 h-9 px-4 cursor-pointer hover:bg-hover" },
25
+ element("strong", { className: "font-mono text-sm font-medium text-fg" }, row.id),
26
+ ...(row.file ? [element("span", { className: "ml-auto font-mono text-xs text-fg-3" }, row.file)] : []),
27
+ )
28
+ const details = element(
29
+ "details",
30
+ { className: "border-b border-line" },
31
+ summary,
32
+ element(
33
+ "pre",
34
+ { className: "m-0 mx-4 mb-2 px-3 py-2.5 rounded-lg bg-field font-mono text-xs text-fg-2 overflow-auto" },
35
+ row.source,
36
+ ),
37
+ )
38
+ details.dataset.id = row.id
39
+ return details
40
+ }
41
+
42
+ export default defineDevtoolsApp({
43
+ init(canvas) {
44
+ const frame = element("iframe", {
45
+ src: inspectURL(baseURL(), document.documentElement.dataset.theme),
46
+ title: "Transform inspector",
47
+ })
48
+ frame.className = "block flex-1 min-h-0 w-full border-0"
49
+ canvas.className = "flex flex-col flex-1 min-h-0"
50
+ const note = element("p", { className: `m-0 px-4 py-1 ${UI.fail} empty:hidden` })
51
+ note.dataset.error = ""
52
+ const list = element("div")
53
+ const filter = element("input", {
54
+ type: "search",
55
+ placeholder: "Filter virtual files",
56
+ className: `${UI.field} w-56 mx-4 my-2`,
57
+ })
58
+ filter.setAttribute("aria-label", "Filter virtual files")
59
+ const files = element("div", { className: "flex-1 min-h-0 overflow-auto" }, note, filter, list)
60
+ const show = (name: "transforms" | "files"): void => {
61
+ frame.hidden = name !== "transforms"
62
+ files.hidden = name !== "files"
63
+ for (const node of tabs.querySelectorAll("button")) {
64
+ node.setAttribute("aria-pressed", String(node.dataset.view === name))
65
+ node.className = pill(node.dataset.view === name)
66
+ }
67
+ }
68
+ const button = (name: "transforms" | "files", label: string) => {
69
+ const node = element("button", { type: "button" }, label)
70
+ node.dataset.view = name
71
+ node.addEventListener("click", () => show(name))
72
+ return node
73
+ }
74
+ const tabs = element(
75
+ "div",
76
+ { className: UI.strip },
77
+ button("transforms", "Transforms"),
78
+ button("files", "Virtual files"),
79
+ )
80
+ canvas.append(tabs, frame, files)
81
+ show("transforms")
82
+ let rows: VirtualRow[] = []
83
+ const paint = (): void => {
84
+ const shown = filterVirtual(rows, filter.value)
85
+ list.replaceChildren(
86
+ ...(shown.length ? shown.map(virtualElement) : [element("p", { className: UI.notice }, "No virtual files")]),
87
+ )
88
+ }
89
+ filter.addEventListener("input", paint)
90
+ void fetch("api/virtual")
91
+ .then(async (response) => {
92
+ const found = (await response.json()) as VirtualRow[] & { error?: string }
93
+ if (!response.ok) throw new Error(found.error ?? `api/virtual answered ${response.status}`)
94
+ rows = found
95
+ paint()
96
+ })
97
+ .catch((error: unknown) => {
98
+ note.textContent = error instanceof Error ? error.message : String(error)
99
+ })
100
+ },
101
+ })
@@ -0,0 +1,58 @@
1
+ import { defineDevtoolsApp } from "hamur/app"
2
+ import { element, UI } from "../panel/ui.ts"
3
+ import type { ModuleRow } from "../dev/modules.ts"
4
+
5
+ /** The options of a module as the text its expandable row shows. */
6
+ export const optionsText = (options: unknown): string => JSON.stringify(options, null, 2) ?? "undefined"
7
+
8
+ function moduleElement(row: ModuleRow): HTMLElement {
9
+ const chips = element(
10
+ "span",
11
+ { className: "flex items-center gap-2 ml-auto font-mono text-xs text-fg-3" },
12
+ element("span", {}, row.version ?? "–"),
13
+ )
14
+ if (row.configKey !== null) {
15
+ const chip = element("code", { className: UI.chip }, row.configKey)
16
+ chip.dataset.configKey = row.configKey
17
+ chips.append(chip)
18
+ }
19
+ const empty = row.options !== null && typeof row.options === "object" && Object.keys(row.options).length === 0
20
+ const summary = element(
21
+ "summary",
22
+ { className: "flex items-center gap-2 h-9 px-4 cursor-pointer hover:bg-hover" },
23
+ element("strong", { className: "font-mono text-sm font-medium text-fg" }, row.name),
24
+ chips,
25
+ )
26
+ const details = element(
27
+ "details",
28
+ { className: "border-b border-line" },
29
+ summary,
30
+ element(
31
+ "pre",
32
+ { className: "m-0 mx-4 mb-2 px-3 py-2.5 rounded-lg bg-field font-mono text-xs text-fg-2 overflow-auto" },
33
+ empty ? "No options" : optionsText(row.options),
34
+ ),
35
+ )
36
+ details.dataset.name = row.name
37
+ return details
38
+ }
39
+
40
+ export default defineDevtoolsApp({
41
+ async init(canvas) {
42
+ canvas.className = "flex-1 min-h-0 overflow-auto"
43
+ const note = element("p", { className: `m-0 px-4 py-1 ${UI.fail} empty:hidden` })
44
+ note.dataset.error = ""
45
+ const list = element("div")
46
+ canvas.append(note, list)
47
+ try {
48
+ const response = await fetch("api/modules")
49
+ const rows = (await response.json()) as ModuleRow[] & { error?: string }
50
+ if (!response.ok) throw new Error(rows.error ?? `api/modules answered ${response.status}`)
51
+ list.replaceChildren(
52
+ ...(rows.length ? rows.map(moduleElement) : [element("p", { className: UI.notice }, "No modules")]),
53
+ )
54
+ } catch (error) {
55
+ note.textContent = error instanceof Error ? error.message : String(error)
56
+ }
57
+ },
58
+ })
@@ -0,0 +1,104 @@
1
+ import { defineDevtoolsApp } from "hamur/app"
2
+ import type { OverviewAnswer } from "../dev/overview.ts"
3
+ import { element, UI } from "../panel/ui.ts"
4
+
5
+ const VERSIONS: Array<[keyof OverviewAnswer["versions"], string]> = [
6
+ ["hamur", "hamur"],
7
+ ["adapter", "Adapter"],
8
+ ["library", "Library"],
9
+ ["bun", "Bun"],
10
+ ]
11
+
12
+ const COUNTS: Array<[keyof OverviewAnswer["counts"], string]> = [
13
+ ["pages", "Pages"],
14
+ ["serverRoutes", "Server routes"],
15
+ ["modules", "Modules"],
16
+ ["appPlugins", "App plugins"],
17
+ ["serverPlugins", "Server plugins"],
18
+ ]
19
+
20
+ const TIMINGS = ["responseStart", "domContentLoadedEventEnd"] as const
21
+
22
+ const NONE = "–"
23
+
24
+ type Timing = Record<(typeof TIMINGS)[number], number>
25
+
26
+ /** Navigation Timing of the app page, read from the parent of the panel's frame; `undefined` when the panel is opened alone. */
27
+ function pageTiming(): Timing | undefined {
28
+ if (window.parent === window) return undefined
29
+ const entry = window.parent.performance.getEntriesByType("navigation")[0] as PerformanceNavigationTiming | undefined
30
+ if (!entry) return undefined
31
+ return Object.fromEntries(TIMINGS.map((key) => [key, Math.round(entry[key])])) as Timing
32
+ }
33
+
34
+ function tile(key: string, label: string, value: string): HTMLElement {
35
+ const number = element("span", { className: "text-xl font-semibold tracking-tight tabular-nums" }, value)
36
+ number.dataset.count = key
37
+ return element(
38
+ "div",
39
+ { className: "flex flex-col gap-0.5 px-3.5 py-3" },
40
+ number,
41
+ element("span", { className: "text-xs text-fg-3" }, label),
42
+ )
43
+ }
44
+
45
+ function loadBar(timing: Timing | undefined): HTMLElement {
46
+ const bar = element("div", { className: "flex gap-0.5" })
47
+ if (!timing || timing.domContentLoadedEventEnd <= 0) return bar
48
+ const first = Math.min(100, (timing.responseStart / timing.domContentLoadedEventEnd) * 100)
49
+ const response = element("span", { className: "h-1.5 rounded-full bg-blue" })
50
+ response.style.width = `${first}%`
51
+ const rest = element("span", { className: "h-1.5 rounded-full bg-accent" })
52
+ rest.style.width = `${100 - first}%`
53
+ bar.append(response, rest)
54
+ return bar
55
+ }
56
+
57
+ export default defineDevtoolsApp({
58
+ async init(canvas) {
59
+ canvas.className = "flex flex-1 min-h-0 overflow-auto"
60
+ const response = await fetch("api/overview")
61
+ const answer = (await response.json()) as OverviewAnswer & { error?: string }
62
+ if (!response.ok) throw new Error(answer.error ?? `api/overview answered ${response.status}`)
63
+ const timing = pageTiming()
64
+ const timings = TIMINGS.map((key) => {
65
+ const value = element("span", { className: "text-fg tabular-nums" }, timing ? `${timing[key]} ms` : NONE)
66
+ value.dataset.timing = key
67
+ return element("span", {}, `${key} `, value)
68
+ })
69
+ const versions = VERSIONS.map(([key, label]) => {
70
+ const value = element("span", { className: "font-mono text-xs text-fg-2" }, answer.versions[key] ?? NONE)
71
+ value.dataset.version = key
72
+ return element(
73
+ "div",
74
+ { className: UI.row },
75
+ element("span", { className: UI.rowKey }, label),
76
+ element("span", { className: UI.rowValue }, value),
77
+ )
78
+ })
79
+ canvas.append(
80
+ element(
81
+ "div",
82
+ { className: "flex-1 min-w-0 flex flex-col gap-3.5 px-4 py-3.5" },
83
+ element(
84
+ "div",
85
+ { className: "grid grid-cols-4 rounded-lg bg-field" },
86
+ ...COUNTS.map(([key, label]) => tile(key, label, String(answer.counts[key] ?? NONE))),
87
+ ),
88
+ element(
89
+ "section",
90
+ { className: "flex flex-col gap-2.5" },
91
+ element("h2", { className: "m-0 text-xs font-medium text-fg-2" }, "Last document load"),
92
+ loadBar(timing),
93
+ element("div", { className: "flex flex-wrap gap-4 text-xs text-fg-3" }, ...timings),
94
+ ),
95
+ ),
96
+ element(
97
+ "aside",
98
+ { className: "w-72 flex-none flex flex-col gap-1 px-4 py-3.5 border-l border-line" },
99
+ element("h2", { className: `m-0 ${UI.label}` }, "Versions"),
100
+ ...versions,
101
+ ),
102
+ )
103
+ },
104
+ })