@hansenexus/hud 0.7.0 → 0.8.0
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 +111 -14
- package/dist/{access-Bc709qpl.d.ts → access-CwPCPsv0.d.ts} +1 -1
- package/dist/auto/runtime.d.ts +9 -9
- package/dist/auto.d.ts +2 -2
- package/dist/auto.js +1 -1
- package/dist/cli.js +34 -1
- package/dist/{define-hud-DTv3njuU.d.ts → define-hud-B0aFXrcK.d.ts} +1 -1
- package/dist/{design-BXG1a4we.js → design-BIXY1-Ex.js} +26 -8
- package/dist/{force-state-panel-mu-txJnA.js → force-state-panel-D5oDydLs.js} +1 -1
- package/dist/{handler-DMzSTqyG.d.ts → handler-BmFhaA2D.d.ts} +1 -1
- package/dist/{index-C3wzZS3o.d.ts → index-5B7foZut.d.ts} +2 -2
- package/dist/{index-D-hI-DRJ.d.ts → index-B2KCKkN0.d.ts} +1 -1
- package/dist/index-B7qaEUgh.d.ts +44 -0
- package/dist/{index-CQXiuMZQ.d.ts → index-BGFyuJyN.d.ts} +1 -1
- package/dist/{index-Caohnz3B.d.ts → index-BeqWehuh.d.ts} +38 -10
- package/dist/{index-BJJoAXJ2.d.ts → index-BqKysxTq.d.ts} +1 -1
- package/dist/{index-DLCSLWW4.d.ts → index-D97Fnoie.d.ts} +2 -2
- package/dist/{index-BR5OB7DO.d.ts → index-DS0yT0c-.d.ts} +1 -1
- package/dist/{index-BNoPbSYD.d.ts → index-DvlCkGB1.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +45 -196
- package/dist/navigation-CX6AXm7H.js +176 -0
- package/dist/next.d.ts +4 -1
- package/dist/next.js +12 -1
- package/dist/obstacles-CCmRFTcZ.js +176 -0
- package/dist/plugins/a11y.d.ts +1 -1
- package/dist/plugins/access/server.d.ts +3 -3
- package/dist/plugins/access.d.ts +2 -2
- package/dist/plugins/agent/server.js +1 -1
- package/dist/plugins/agent.d.ts +2 -2
- package/dist/plugins/capture.d.ts +2 -2
- package/dist/plugins/data/server.d.ts +1 -1
- package/dist/plugins/data/server.js +1 -1
- package/dist/plugins/data.d.ts +1 -1
- package/dist/plugins/design/server.d.ts +55 -15
- package/dist/plugins/design/server.js +187 -122
- package/dist/plugins/design.d.ts +3 -3
- package/dist/plugins/design.js +1 -1
- package/dist/plugins/inspect.d.ts +1 -1
- package/dist/plugins/observe.d.ts +1 -1
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops.d.ts +1 -1
- package/dist/plugins/routes/server.d.ts +1 -1
- package/dist/plugins/routes.d.ts +3 -3
- package/dist/plugins/routes.js +381 -52
- package/dist/plugins/seo.d.ts +1 -1
- package/dist/plugins/vitals.d.ts +1 -1
- package/dist/{plugins-BZT-1LBe.d.ts → plugins-pL2CoWzI.d.ts} +7 -0
- package/dist/same-origin-BHuZO1_H.js +36 -0
- package/dist/server.d.ts +2 -2
- package/dist/store.d.ts +1 -1
- package/dist/store.js +1 -1
- package/dist/{meta-C_G7MB5w.d.ts → types-Dc6JWZR7.d.ts} +6 -6
- package/dist/variant-bar-BzZ0ln-C.js +768 -0
- package/dist/variant-picks-Byc0hC8a.js +144 -0
- package/dist/variants-export-vEtZ-OGC.js +75 -0
- package/dist/{variants-panel-B6zWcknV.js → variants-panel-D23v5KIp.js} +71 -54
- package/dist/variants-types-BOsZ5fDz.js +65 -0
- package/dist/variants-types-VkW7vFZF.d.ts +139 -0
- package/dist/variants.d.ts +1 -1
- package/dist/variants.js +1 -1
- package/dist/vite.d.ts +2 -2
- package/package.json +1 -1
- package/dist/index-B1vHAY9p.d.ts +0 -20
- package/dist/same-origin-BGet22CC.js +0 -21
- package/dist/variants-types-CcRf119M.d.ts +0 -63
package/dist/plugins/routes.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { i as hudIcon } from "../icons-ByDyNq_E.js";
|
|
2
2
|
import { i as definePlugin, n as HudApiError } from "../plugins-CcW_K7c2.js";
|
|
3
3
|
import { n as ROUTES_ID, t as ROUTES_CAPABILITY } from "../meta-Bv0sEao3.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { a as togglePin, c as usePrefs, i as takeFilterFocus, n as requestFilterFocus, o as useFilterFocusTick, r as startNavigationObserver, s as usePathname, t as navigateTo } from "../navigation-CX6AXm7H.js";
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
//#region src/plugins/routes/styles.ts
|
|
7
8
|
/** Panel styles, rendered as a `<style>` inside the panel, so inside the shadow root. */
|
|
8
9
|
const ROUTES_CSS = `
|
|
@@ -31,11 +32,14 @@ const ROUTES_CSS = `
|
|
|
31
32
|
color: var(--hud-fg-muted);
|
|
32
33
|
}
|
|
33
34
|
.routes ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
|
|
34
|
-
.routes li
|
|
35
|
+
.routes li { display: flex; align-items: center; gap: 4px; border-radius: 4px; }
|
|
36
|
+
.routes li a.row, .routes li > span {
|
|
37
|
+
flex: 1;
|
|
35
38
|
display: grid;
|
|
36
39
|
grid-template-columns: minmax(0, 1fr) auto;
|
|
37
40
|
align-items: center;
|
|
38
41
|
gap: 8px;
|
|
42
|
+
min-width: 0;
|
|
39
43
|
padding: 3px 6px;
|
|
40
44
|
border-radius: 4px;
|
|
41
45
|
font-family: var(--hud-mono);
|
|
@@ -45,14 +49,191 @@ const ROUTES_CSS = `
|
|
|
45
49
|
text-overflow: ellipsis;
|
|
46
50
|
white-space: nowrap;
|
|
47
51
|
}
|
|
48
|
-
.routes li
|
|
52
|
+
.routes li:hover, .routes li[data-active] { background: var(--hud-bg-subtle); }
|
|
53
|
+
.routes li[data-active] { box-shadow: inset 2px 0 0 var(--hud-accent); }
|
|
49
54
|
.routes li a[aria-current="page"] { color: var(--hud-accent); font-weight: 600; }
|
|
50
55
|
.routes li > span { color: var(--hud-fg-muted); }
|
|
51
56
|
.routes li small { color: var(--hud-fg-muted); font-family: var(--hud-font); }
|
|
57
|
+
.routes .alts { display: flex; gap: 2px; }
|
|
58
|
+
.routes a.alt {
|
|
59
|
+
padding: 0 5px;
|
|
60
|
+
border: 1px solid var(--hud-border);
|
|
61
|
+
border-radius: 999px;
|
|
62
|
+
font-family: var(--hud-mono);
|
|
63
|
+
font-size: 10px;
|
|
64
|
+
color: var(--hud-fg-muted);
|
|
65
|
+
text-decoration: none;
|
|
66
|
+
}
|
|
67
|
+
.routes a.alt:hover, .routes a.alt[aria-current="page"] { color: var(--hud-accent); border-color: var(--hud-accent); }
|
|
68
|
+
.routes button.pin {
|
|
69
|
+
padding: 0 4px;
|
|
70
|
+
border: 0;
|
|
71
|
+
background: none;
|
|
72
|
+
color: var(--hud-fg-muted);
|
|
73
|
+
font: inherit;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
opacity: 0;
|
|
76
|
+
}
|
|
77
|
+
.routes li:hover button.pin, .routes li[data-active] button.pin, .routes button.pin[aria-pressed="true"],
|
|
78
|
+
.routes button.pin:focus-visible { opacity: 1; }
|
|
79
|
+
.routes button.pin[aria-pressed="true"] { color: var(--hud-accent); }
|
|
80
|
+
.routes button.pin:disabled { cursor: default; }
|
|
52
81
|
.routes .warn { color: var(--hud-warn); margin: 0; }
|
|
53
82
|
.routes .muted { color: var(--hud-fg-muted); margin: 0; }
|
|
54
83
|
`;
|
|
55
84
|
//#endregion
|
|
85
|
+
//#region src/plugins/routes/switcher.ts
|
|
86
|
+
/** 2 for a substring match, 1 when `query` is a subsequence of `text`, 0 otherwise. */
|
|
87
|
+
function fuzzyScore(text, query) {
|
|
88
|
+
if (!query) return 2;
|
|
89
|
+
const hay = text.toLowerCase();
|
|
90
|
+
if (hay.includes(query)) return 2;
|
|
91
|
+
let at = 0;
|
|
92
|
+
for (const char of query) {
|
|
93
|
+
at = hay.indexOf(char, at);
|
|
94
|
+
if (at === -1) return 0;
|
|
95
|
+
at += 1;
|
|
96
|
+
}
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
function tokens(query) {
|
|
100
|
+
return query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
101
|
+
}
|
|
102
|
+
/** The best score of `token` over the route's own fields. */
|
|
103
|
+
function routeScore(route, token) {
|
|
104
|
+
return Math.max(fuzzyScore(route.path, token), fuzzyScore(route.pattern, token), route.group ? fuzzyScore(route.group, token) : 0);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Routes matching every word of the query on path, pattern or group,
|
|
108
|
+
* substring first, then as a subsequence (`dsys` finds `/de/dev/design-system`).
|
|
109
|
+
* A word that only matches some of a route's URLs narrows the route to those.
|
|
110
|
+
*/
|
|
111
|
+
function filterRoutes(routes, query) {
|
|
112
|
+
const words = tokens(query);
|
|
113
|
+
if (words.length === 0) return [...routes];
|
|
114
|
+
return routes.flatMap((route) => {
|
|
115
|
+
const own = words.map((word) => routeScore(route, word));
|
|
116
|
+
if (own.every((score) => score > 0)) return [{
|
|
117
|
+
route,
|
|
118
|
+
score: own.reduce((sum, score) => sum + score, 0)
|
|
119
|
+
}];
|
|
120
|
+
const urls = route.urls.filter(({ url }) => words.every((word, i) => (own[i] ?? 0) > 0 || fuzzyScore(url, word) > 0));
|
|
121
|
+
if (urls.length === 0) return [];
|
|
122
|
+
const score = words.reduce((sum, word, i) => sum + Math.max(own[i] ?? 0, ...urls.map(({ url }) => fuzzyScore(url, word))), 0);
|
|
123
|
+
return [{
|
|
124
|
+
route: {
|
|
125
|
+
...route,
|
|
126
|
+
urls
|
|
127
|
+
},
|
|
128
|
+
score
|
|
129
|
+
}];
|
|
130
|
+
}).map((entry, index) => ({
|
|
131
|
+
...entry,
|
|
132
|
+
index
|
|
133
|
+
})).sort((a, b) => b.score - a.score || a.index - b.index).map(({ route }) => route);
|
|
134
|
+
}
|
|
135
|
+
/** Fixture values of the `locale` segment across the routes, in fixture order. */
|
|
136
|
+
function localesOf(routes) {
|
|
137
|
+
const locales = [];
|
|
138
|
+
for (const route of routes) for (const { params } of route.urls) {
|
|
139
|
+
const locale = params.locale;
|
|
140
|
+
if (locale !== void 0 && !locales.includes(locale)) locales.push(locale);
|
|
141
|
+
}
|
|
142
|
+
return locales;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The locale the page is on: its first segment when that is a locale, else
|
|
146
|
+
* the empty locale when the fixtures have one (an `as-needed` default), else
|
|
147
|
+
* the first fixture value. Undefined without a `locale` segment.
|
|
148
|
+
*/
|
|
149
|
+
function currentLocale(pathname, locales) {
|
|
150
|
+
if (locales.length === 0) return void 0;
|
|
151
|
+
const first = pathname.split("/")[1] ?? "";
|
|
152
|
+
if (first && locales.includes(first)) return first;
|
|
153
|
+
if (locales.includes("")) return "";
|
|
154
|
+
return locales[0];
|
|
155
|
+
}
|
|
156
|
+
function paramsKey(params) {
|
|
157
|
+
return JSON.stringify(Object.entries(params).filter(([name]) => name !== "locale").sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The rows of a route: one per URL, except that with a `locale` fixture the
|
|
161
|
+
* locale variants of a page fold into one row for `locale`, the other
|
|
162
|
+
* locales listed as alternates. Unresolved routes have no rows.
|
|
163
|
+
*/
|
|
164
|
+
function rowsOf(route, locale) {
|
|
165
|
+
if (route.urls.length === 0) return [];
|
|
166
|
+
if (!route.urls.some(({ params }) => params.locale !== void 0) || locale === void 0) return route.urls.map(({ url, params }) => ({
|
|
167
|
+
id: `${route.pattern}${paramsKey(params)}`,
|
|
168
|
+
url,
|
|
169
|
+
route,
|
|
170
|
+
params,
|
|
171
|
+
alternates: []
|
|
172
|
+
}));
|
|
173
|
+
const groups = /* @__PURE__ */ new Map();
|
|
174
|
+
for (const entry of route.urls) {
|
|
175
|
+
const key = paramsKey(entry.params);
|
|
176
|
+
const group = groups.get(key);
|
|
177
|
+
if (group) group.push(entry);
|
|
178
|
+
else groups.set(key, [entry]);
|
|
179
|
+
}
|
|
180
|
+
return [...groups.entries()].flatMap(([key, entries]) => {
|
|
181
|
+
const primary = entries.find(({ params }) => params.locale === locale) ?? entries[0];
|
|
182
|
+
if (!primary) return [];
|
|
183
|
+
return {
|
|
184
|
+
id: `${route.pattern}${key}`,
|
|
185
|
+
url: primary.url,
|
|
186
|
+
route,
|
|
187
|
+
params: primary.params,
|
|
188
|
+
alternates: entries.filter((entry) => entry !== primary).map(({ url, params }) => ({
|
|
189
|
+
locale: params.locale ?? "",
|
|
190
|
+
url
|
|
191
|
+
}))
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/** `*` matches within a segment, `**` across segments; anchored at both ends. */
|
|
196
|
+
function matchesGlob(glob, pathname) {
|
|
197
|
+
const source = glob.split(/(\*\*|\*)/).map((part) => part === "**" ? ".*" : part === "*" ? "[^/]*" : escapeRegExp(part)).join("");
|
|
198
|
+
return new RegExp(`^${source}/?$`).test(pathname);
|
|
199
|
+
}
|
|
200
|
+
function escapeRegExp(text) {
|
|
201
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
202
|
+
}
|
|
203
|
+
function rowUrls(row) {
|
|
204
|
+
return [row.url, ...row.alternates.map((alternate) => alternate.url)];
|
|
205
|
+
}
|
|
206
|
+
/** Whether the row, in any locale, matches a configured glob or a stored pin. */
|
|
207
|
+
function isPinned(row, globs, pins) {
|
|
208
|
+
return rowUrls(row).some((url) => pins.includes(url) || globs.some((glob) => matchesGlob(glob, url)));
|
|
209
|
+
}
|
|
210
|
+
/** Whether a configured glob (not a toggle) pins the row. */
|
|
211
|
+
function isGlobPinned(row, globs) {
|
|
212
|
+
return rowUrls(row).some((url) => globs.some((glob) => matchesGlob(glob, url)));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The rows for the recent pathnames, most recent first: the scanned row that
|
|
216
|
+
* owns the pathname (in any locale), else a bare row, each page once.
|
|
217
|
+
*/
|
|
218
|
+
function recentRows(recent, rows) {
|
|
219
|
+
const seen = /* @__PURE__ */ new Set();
|
|
220
|
+
const out = [];
|
|
221
|
+
for (const pathname of recent) {
|
|
222
|
+
const row = rows.find((candidate) => rowUrls(candidate).includes(pathname));
|
|
223
|
+
const id = row ? row.id : `recent:${pathname}`;
|
|
224
|
+
if (seen.has(id)) continue;
|
|
225
|
+
seen.add(id);
|
|
226
|
+
out.push(row ?? {
|
|
227
|
+
id,
|
|
228
|
+
url: pathname,
|
|
229
|
+
route: null,
|
|
230
|
+
params: {},
|
|
231
|
+
alternates: []
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
56
237
|
//#region src/plugins/routes/routes-panel.tsx
|
|
57
238
|
/** A readable message for a failed request; the route's own 500 bodies carry one. */
|
|
58
239
|
function describeError(error) {
|
|
@@ -95,47 +276,160 @@ function useRoutes(ctx) {
|
|
|
95
276
|
function groupLabel(group) {
|
|
96
277
|
return group ?? "root";
|
|
97
278
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function filterRoutes(routes, query) {
|
|
103
|
-
const q = query.trim().toLowerCase();
|
|
104
|
-
if (!q) return [...routes];
|
|
105
|
-
return routes.flatMap((route) => {
|
|
106
|
-
if (route.path.toLowerCase().includes(q) || route.pattern.toLowerCase().includes(q)) return [route];
|
|
107
|
-
const urls = route.urls.filter(({ url }) => url.toLowerCase().includes(q));
|
|
108
|
-
return urls.length > 0 ? [{
|
|
109
|
-
...route,
|
|
110
|
-
urls
|
|
111
|
-
}] : [];
|
|
112
|
-
});
|
|
279
|
+
const NO_GLOBS = [];
|
|
280
|
+
/** A plain left click: no modifier, so the row navigates in place. */
|
|
281
|
+
function isPlainClick(event) {
|
|
282
|
+
return event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
113
283
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
284
|
+
function RouteRow({ row, here, active, pinned, byGlob, onGo, onPin }) {
|
|
285
|
+
const ref = useRef(null);
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
if (active) ref.current?.scrollIntoView?.({ block: "nearest" });
|
|
288
|
+
}, [active]);
|
|
289
|
+
const route = row.route;
|
|
290
|
+
const values = Object.entries(row.params).filter(([name, value]) => name !== "locale" && value);
|
|
291
|
+
const go = (url) => (event) => {
|
|
292
|
+
if (!isPlainClick(event)) return;
|
|
293
|
+
event.preventDefault();
|
|
294
|
+
onGo(url);
|
|
295
|
+
};
|
|
296
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
297
|
+
ref,
|
|
298
|
+
"data-active": active || void 0,
|
|
299
|
+
children: [
|
|
300
|
+
/* @__PURE__ */ jsxs("a", {
|
|
301
|
+
className: "row",
|
|
302
|
+
href: row.url,
|
|
303
|
+
title: route?.pattern,
|
|
304
|
+
"aria-current": row.url === here ? "page" : void 0,
|
|
305
|
+
onClick: go(row.url),
|
|
306
|
+
children: [row.url, route && values.length > 0 && /* @__PURE__ */ jsx("small", { children: route.path })]
|
|
307
|
+
}),
|
|
308
|
+
row.alternates.length > 0 && /* @__PURE__ */ jsx("span", {
|
|
309
|
+
className: "alts",
|
|
310
|
+
children: row.alternates.map((alternate) => /* @__PURE__ */ jsx("a", {
|
|
311
|
+
className: "alt",
|
|
312
|
+
href: alternate.url,
|
|
313
|
+
title: alternate.url,
|
|
314
|
+
"aria-current": alternate.url === here ? "page" : void 0,
|
|
315
|
+
onClick: go(alternate.url),
|
|
316
|
+
children: alternate.locale || "default"
|
|
317
|
+
}, alternate.url))
|
|
318
|
+
}),
|
|
319
|
+
/* @__PURE__ */ jsx("button", {
|
|
320
|
+
type: "button",
|
|
321
|
+
className: "pin",
|
|
322
|
+
"aria-label": `${pinned ? "Unpin" : "Pin"} ${row.url}`,
|
|
323
|
+
"aria-pressed": pinned,
|
|
324
|
+
disabled: byGlob,
|
|
325
|
+
title: byGlob ? "pinned by routes({ pinned })" : pinned ? "Unpin" : "Pin",
|
|
326
|
+
onClick: () => onPin(row.url),
|
|
327
|
+
children: pinned ? "★" : "☆"
|
|
328
|
+
})
|
|
329
|
+
]
|
|
330
|
+
});
|
|
116
331
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
332
|
+
function UnresolvedRow({ route }) {
|
|
333
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("span", {
|
|
119
334
|
title: `${route.pattern}: no fixture for ${route.unresolved.join(", ")}`,
|
|
120
335
|
children: [route.path, /* @__PURE__ */ jsxs("small", { children: ["no fixture: ", route.unresolved.join(", ")] })]
|
|
121
336
|
}) });
|
|
122
|
-
return /* @__PURE__ */ jsx(Fragment, { children: route.urls.map(({ url, params }) => {
|
|
123
|
-
const values = Object.values(params).filter(Boolean);
|
|
124
|
-
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("a", {
|
|
125
|
-
href: url,
|
|
126
|
-
title: route.pattern,
|
|
127
|
-
"aria-current": url === here ? "page" : void 0,
|
|
128
|
-
children: [url, values.length > 0 && /* @__PURE__ */ jsx("small", { children: route.path })]
|
|
129
|
-
}) }, url);
|
|
130
|
-
}) });
|
|
131
337
|
}
|
|
132
|
-
function RoutesPanel({ ctx }) {
|
|
338
|
+
function RoutesPanel({ ctx, pinned: globs = NO_GLOBS, navigate }) {
|
|
133
339
|
const { data, error, loading, refresh } = useRoutes(ctx);
|
|
134
340
|
const [query, setQuery] = useState("");
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
341
|
+
const [active, setActive] = useState(0);
|
|
342
|
+
const inputRef = useRef(null);
|
|
343
|
+
const here = usePathname();
|
|
344
|
+
const prefs = usePrefs(ctx.app);
|
|
345
|
+
const focusTick = useFilterFocusTick();
|
|
346
|
+
useEffect(() => startNavigationObserver(ctx.app), [ctx.app]);
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
if (focusTick === 0 || !takeFilterFocus()) return;
|
|
349
|
+
const input = inputRef.current;
|
|
350
|
+
if (!input) return;
|
|
351
|
+
input.focus();
|
|
352
|
+
input.select();
|
|
353
|
+
}, [focusTick]);
|
|
354
|
+
const all = data?.routes ?? [];
|
|
355
|
+
const filtered = useMemo(() => filterRoutes(all, query), [all, query]);
|
|
356
|
+
const locale = useMemo(() => currentLocale(here, localesOf(all)), [all, here]);
|
|
357
|
+
const rows = useMemo(() => filtered.flatMap((route) => rowsOf(route, locale)), [filtered, locale]);
|
|
358
|
+
const allRows = useMemo(() => query ? all.flatMap((route) => rowsOf(route, locale)) : rows, [
|
|
359
|
+
all,
|
|
360
|
+
rows,
|
|
361
|
+
query,
|
|
362
|
+
locale
|
|
363
|
+
]);
|
|
364
|
+
const sections = useMemo(() => {
|
|
365
|
+
const out = [];
|
|
366
|
+
if (!query) {
|
|
367
|
+
const pins = rows.filter((row) => isPinned(row, globs, prefs.pins));
|
|
368
|
+
if (pins.length > 0) out.push({
|
|
369
|
+
label: "Pinned",
|
|
370
|
+
rows: pins
|
|
371
|
+
});
|
|
372
|
+
const recent = recentRows(prefs.recent, allRows);
|
|
373
|
+
if (recent.length > 0) out.push({
|
|
374
|
+
label: "Recent",
|
|
375
|
+
rows: recent
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
const groups = [...new Set(filtered.map((route) => groupLabel(route.group)))].sort();
|
|
379
|
+
for (const group of groups) out.push({
|
|
380
|
+
label: group,
|
|
381
|
+
rows: rows.filter((row) => groupLabel(row.route?.group ?? null) === group)
|
|
382
|
+
});
|
|
383
|
+
return out;
|
|
384
|
+
}, [
|
|
385
|
+
query,
|
|
386
|
+
rows,
|
|
387
|
+
allRows,
|
|
388
|
+
filtered,
|
|
389
|
+
globs,
|
|
390
|
+
prefs
|
|
391
|
+
]);
|
|
392
|
+
const items = useMemo(() => sections.flatMap((section) => section.rows), [sections]);
|
|
393
|
+
const count = items.length;
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
setActive((index) => count === 0 ? 0 : Math.min(index, count - 1));
|
|
396
|
+
}, [count]);
|
|
397
|
+
const go = useCallback((url) => {
|
|
398
|
+
if (navigate) navigate(url);
|
|
399
|
+
else navigateTo(url);
|
|
400
|
+
}, [navigate]);
|
|
401
|
+
const onKeyDown = (event) => {
|
|
402
|
+
switch (event.key) {
|
|
403
|
+
case "ArrowDown":
|
|
404
|
+
event.preventDefault();
|
|
405
|
+
setActive((index) => count === 0 ? 0 : (index + 1) % count);
|
|
406
|
+
break;
|
|
407
|
+
case "ArrowUp":
|
|
408
|
+
event.preventDefault();
|
|
409
|
+
setActive((index) => count === 0 ? 0 : (index - 1 + count) % count);
|
|
410
|
+
break;
|
|
411
|
+
case "Enter": {
|
|
412
|
+
const row = items[active] ?? items[0];
|
|
413
|
+
if (!row) return;
|
|
414
|
+
event.preventDefault();
|
|
415
|
+
go(row.url);
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case "Escape":
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
ctx.close();
|
|
421
|
+
break;
|
|
422
|
+
default: return;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
const onChange = (value) => {
|
|
426
|
+
setQuery(value);
|
|
427
|
+
setActive(0);
|
|
428
|
+
};
|
|
429
|
+
const onPin = (url) => togglePin(ctx.app, url);
|
|
138
430
|
const urlCount = data ? data.routes.reduce((n, route) => n + route.urls.length, 0) : 0;
|
|
431
|
+
const unresolved = filtered.filter((route) => route.unresolved.length > 0);
|
|
432
|
+
let offset = 0;
|
|
139
433
|
return /* @__PURE__ */ jsxs("div", {
|
|
140
434
|
className: "routes",
|
|
141
435
|
children: [
|
|
@@ -144,17 +438,21 @@ function RoutesPanel({ ctx }) {
|
|
|
144
438
|
className: "head",
|
|
145
439
|
children: [
|
|
146
440
|
/* @__PURE__ */ jsx("input", {
|
|
441
|
+
ref: inputRef,
|
|
147
442
|
type: "search",
|
|
148
443
|
value: query,
|
|
149
|
-
onChange: (e) =>
|
|
444
|
+
onChange: (e) => onChange(e.target.value),
|
|
445
|
+
onKeyDown,
|
|
150
446
|
placeholder: "Filter routes…",
|
|
151
|
-
"aria-label": "Filter routes"
|
|
447
|
+
"aria-label": "Filter routes",
|
|
448
|
+
autoComplete: "off",
|
|
449
|
+
spellCheck: false
|
|
152
450
|
}),
|
|
153
451
|
data && /* @__PURE__ */ jsxs("span", {
|
|
154
452
|
className: "count",
|
|
155
453
|
title: `${data.routes.length} routes in ${data.dir}`,
|
|
156
454
|
children: [
|
|
157
|
-
|
|
455
|
+
filtered.length,
|
|
158
456
|
"/",
|
|
159
457
|
data.routes.length,
|
|
160
458
|
" · ",
|
|
@@ -187,31 +485,62 @@ function RoutesPanel({ ctx }) {
|
|
|
187
485
|
"."
|
|
188
486
|
]
|
|
189
487
|
}),
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
488
|
+
sections.map((section) => {
|
|
489
|
+
const start = offset;
|
|
490
|
+
offset += section.rows.length;
|
|
491
|
+
return /* @__PURE__ */ jsxs("section", {
|
|
492
|
+
"aria-label": section.label,
|
|
493
|
+
children: [/* @__PURE__ */ jsx("h3", { children: section.label }), /* @__PURE__ */ jsxs("ul", { children: [section.rows.map((row, i) => /* @__PURE__ */ jsx(RouteRow, {
|
|
494
|
+
row,
|
|
495
|
+
here,
|
|
496
|
+
active: start + i === active,
|
|
497
|
+
pinned: isPinned(row, globs, prefs.pins),
|
|
498
|
+
byGlob: isGlobPinned(row, globs),
|
|
499
|
+
onGo: go,
|
|
500
|
+
onPin
|
|
501
|
+
}, row.id)), unresolved.filter((route) => groupLabel(route.group) === section.label).map((route) => /* @__PURE__ */ jsx(UnresolvedRow, { route }, route.pattern))] })]
|
|
502
|
+
}, section.label);
|
|
503
|
+
})
|
|
197
504
|
]
|
|
198
505
|
});
|
|
199
506
|
}
|
|
200
507
|
//#endregion
|
|
201
508
|
//#region src/plugins/routes/index.tsx
|
|
202
509
|
/**
|
|
203
|
-
* Route index: every page of the app's `app/` tree,
|
|
204
|
-
* from the fixtures the server half knows,
|
|
205
|
-
*
|
|
206
|
-
* the `hud sweep`
|
|
510
|
+
* Route index and quick switcher: every page of the app's `app/` tree,
|
|
511
|
+
* dynamic segments filled from the fixtures the server half knows, pinned
|
|
512
|
+
* and recent routes first, one keystroke away. Client half; the scanner lives
|
|
513
|
+
* in `@hansenexus/hud/plugins/routes/server`, which also feeds the `hud sweep`
|
|
514
|
+
* CLI.
|
|
207
515
|
*/
|
|
208
|
-
function routes() {
|
|
516
|
+
function routes({ shortcut = "mod+shift+r", pinned = [], navigate } = {}) {
|
|
517
|
+
function RoutesSwitcher({ ctx }) {
|
|
518
|
+
return /* @__PURE__ */ jsx(RoutesPanel, {
|
|
519
|
+
ctx,
|
|
520
|
+
pinned,
|
|
521
|
+
navigate
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
function useRoutesBadge({ ctx }) {
|
|
525
|
+
useEffect(() => startNavigationObserver(ctx.app), [ctx.app]);
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
209
528
|
return definePlugin({
|
|
210
529
|
id: ROUTES_ID,
|
|
211
530
|
title: "Routes",
|
|
212
531
|
capability: ROUTES_CAPABILITY,
|
|
213
532
|
icon: hudIcon("route"),
|
|
214
|
-
|
|
533
|
+
badge: useRoutesBadge,
|
|
534
|
+
panel: RoutesSwitcher,
|
|
535
|
+
commands: [{
|
|
536
|
+
id: "go",
|
|
537
|
+
title: "Go to route",
|
|
538
|
+
shortcut,
|
|
539
|
+
run: (ctx) => {
|
|
540
|
+
ctx.open();
|
|
541
|
+
requestFilterFocus();
|
|
542
|
+
}
|
|
543
|
+
}]
|
|
215
544
|
});
|
|
216
545
|
}
|
|
217
546
|
//#endregion
|
package/dist/plugins/seo.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as SeoLevel, i as SeoGroup, n as SeoSnapshot, o as runSeoChecks, r as SeoCheck, t as seo } from "../index-
|
|
1
|
+
import { a as SeoLevel, i as SeoGroup, n as SeoSnapshot, o as runSeoChecks, r as SeoCheck, t as seo } from "../index-BGFyuJyN.js";
|
|
2
2
|
export { type SeoCheck, type SeoGroup, type SeoLevel, type SeoSnapshot, runSeoChecks, seo };
|
package/dist/plugins/vitals.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as VitalsSnapshot, i as VitalRating, n as Vital, r as VitalName, t as vitals } from "../index-
|
|
1
|
+
import { a as VitalsSnapshot, i as VitalRating, n as Vital, r as VitalName, t as vitals } from "../index-B2KCKkN0.js";
|
|
2
2
|
export { type Vital, type VitalName, type VitalRating, type VitalsSnapshot, vitals };
|
|
@@ -138,6 +138,13 @@ interface HudPlugin {
|
|
|
138
138
|
* the folded rail's summary dots.
|
|
139
139
|
*/
|
|
140
140
|
badge?: (props: HudPluginProps) => HudBadge | null;
|
|
141
|
+
/**
|
|
142
|
+
* Always-mounted content inside the HUD's shadow root, with no panel frame:
|
|
143
|
+
* it positions itself and opts in with `pointer-events: auto`. Make it a
|
|
144
|
+
* dynamic import like `panel`; while it loads, and when it fails, it is
|
|
145
|
+
* nothing.
|
|
146
|
+
*/
|
|
147
|
+
overlay?: ComponentType<HudPluginProps>;
|
|
141
148
|
/**
|
|
142
149
|
* When the pill runs out of room, items with a higher priority stay visible
|
|
143
150
|
* longest; the rest move into the pill menu. Above 0 the item also survives
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/server/same-origin.ts
|
|
2
|
+
/** The host the browser asked for: a proxy in front of the dev server forwards its own. */
|
|
3
|
+
function requestHosts(request) {
|
|
4
|
+
const named = [request.headers.get("x-forwarded-host"), request.headers.get("host")].flatMap((host) => host ? [host.toLowerCase()] : []);
|
|
5
|
+
return named.length > 0 ? named : [new URL(request.url).host];
|
|
6
|
+
}
|
|
7
|
+
function fromOwnHost(request, origin) {
|
|
8
|
+
try {
|
|
9
|
+
return requestHosts(request).includes(new URL(origin).host);
|
|
10
|
+
} catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Refuses a state-changing request from another origin. A page elsewhere must
|
|
16
|
+
* not be able to write through the developer's browser: a JSON content type
|
|
17
|
+
* forces a CORS preflight that HUD routes never answer, and `Sec-Fetch-Site`
|
|
18
|
+
* rejects cross-site requests outright where the browser sends it. It does
|
|
19
|
+
* not on plain http to another machine (a phone on `http://<lan ip>:3000`);
|
|
20
|
+
* there the `Origin` has to name the host the request went to.
|
|
21
|
+
*/
|
|
22
|
+
function refuseCrossSite(request) {
|
|
23
|
+
const site = request.headers.get("sec-fetch-site");
|
|
24
|
+
const origin = request.headers.get("origin");
|
|
25
|
+
if (site ? site !== "same-origin" && site !== "none" : origin !== null && !fromOwnHost(request, origin)) return Response.json({
|
|
26
|
+
ok: false,
|
|
27
|
+
error: "cross-site request refused"
|
|
28
|
+
}, { status: 403 });
|
|
29
|
+
if (!request.headers.get("content-type")?.toLowerCase().startsWith("application/json")) return Response.json({
|
|
30
|
+
ok: false,
|
|
31
|
+
error: "expected application/json"
|
|
32
|
+
}, { status: 415 });
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { refuseCrossSite as t };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { c as HudPlugin, d as HudRouteContext, f as HudRouteHandler, h as definePlugin, p as HudRoutes, s as HudHttpMethod } from "./plugins-
|
|
2
|
-
import { a as createHudHandler, i as HudRequestHandler, n as HudHandler, o as developmentOnly, r as HudHandlerOptions, t as HudGuard } from "./handler-
|
|
1
|
+
import { c as HudPlugin, d as HudRouteContext, f as HudRouteHandler, h as definePlugin, p as HudRoutes, s as HudHttpMethod } from "./plugins-pL2CoWzI.js";
|
|
2
|
+
import { a as createHudHandler, i as HudRequestHandler, n as HudHandler, o as developmentOnly, r as HudHandlerOptions, t as HudGuard } from "./handler-BmFhaA2D.js";
|
|
3
3
|
export { type HudGuard, type HudHandler, type HudHandlerOptions, type HudHttpMethod, type HudPlugin, type HudRequestHandler, type HudRouteContext, type HudRouteHandler, type HudRoutes, createHudHandler, definePlugin, developmentOnly };
|
package/dist/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as HudCapability, p as HudRoutes } from "./plugins-
|
|
1
|
+
import { a as HudCapability, p as HudRoutes } from "./plugins-pL2CoWzI.js";
|
|
2
2
|
import { a as STORE_COLLECTION, c as assertId, i as HudStoreValue, l as assertValue, n as HudStoreEntry, o as STORE_ID, r as HudStoreError, s as assertCollection, t as HudStore, u as isStoreValue } from "./types-DaJcsEjO.js";
|
|
3
3
|
//#region src/store/file.d.ts
|
|
4
4
|
interface FileStoreOptions {
|
package/dist/store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as definePlugin } from "./plugins-CcW_K7c2.js";
|
|
2
|
-
import { t as refuseCrossSite } from "./same-origin-
|
|
2
|
+
import { t as refuseCrossSite } from "./same-origin-BHuZO1_H.js";
|
|
3
3
|
import { a as assertId, i as assertCollection, n as STORE_COLLECTION, o as assertValue, r as STORE_ID, s as isStoreValue, t as HudStoreError } from "./types-BIkI-qN8.js";
|
|
4
4
|
import { t as file } from "./file-xdSaQ2uR.js";
|
|
5
5
|
//#region src/store/http.ts
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
//#region src/plugins/routes/meta.d.ts
|
|
2
|
+
/** Shared by both halves, so client and server gate on the same capability. */
|
|
3
|
+
declare const ROUTES_ID = "routes";
|
|
4
|
+
declare const ROUTES_CAPABILITY = "routes.read";
|
|
5
|
+
//#endregion
|
|
1
6
|
//#region src/plugins/routes/types.d.ts
|
|
2
7
|
/** One dynamic segment of a route pattern. */
|
|
3
8
|
interface RouteSegment {
|
|
@@ -41,9 +46,4 @@ interface RoutesResponse {
|
|
|
41
46
|
routes: RouteEntry[];
|
|
42
47
|
}
|
|
43
48
|
//#endregion
|
|
44
|
-
|
|
45
|
-
/** Shared by both halves, so client and server gate on the same capability. */
|
|
46
|
-
declare const ROUTES_ID = "routes";
|
|
47
|
-
declare const ROUTES_CAPABILITY = "routes.read";
|
|
48
|
-
//#endregion
|
|
49
|
-
export { RouteUrl as a, RouteSegment as i, ROUTES_ID as n, RoutesResponse as o, RouteEntry as r, ROUTES_CAPABILITY as t };
|
|
49
|
+
export { ROUTES_CAPABILITY as a, RoutesResponse as i, RouteSegment as n, ROUTES_ID as o, RouteUrl as r, RouteEntry as t };
|