@riebeckite/honox 0.0.30 → 0.0.31
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/dist/index.js
CHANGED
|
@@ -2069,27 +2069,35 @@ function isNotFoundError2(error) {
|
|
|
2069
2069
|
}
|
|
2070
2070
|
|
|
2071
2071
|
// src/client_module.ts
|
|
2072
|
-
import {
|
|
2073
|
-
serializePublicClientConfig
|
|
2074
|
-
} from "@riebeckite/core";
|
|
2072
|
+
import { serializePublicClientConfig } from "@riebeckite/core";
|
|
2075
2073
|
var clientModuleId = "virtual:riebeckite/client";
|
|
2076
2074
|
var resolvedClientModuleId = `\0${clientModuleId}`;
|
|
2077
2075
|
function riebeckiteClientModule(getConfig) {
|
|
2076
|
+
let development = false;
|
|
2078
2077
|
return {
|
|
2079
2078
|
name: "riebeckite-client-module",
|
|
2079
|
+
config(_config, environment) {
|
|
2080
|
+
development = environment.command === "serve";
|
|
2081
|
+
},
|
|
2080
2082
|
resolveId(id) {
|
|
2081
2083
|
if (id === clientModuleId) return resolvedClientModuleId;
|
|
2082
2084
|
return null;
|
|
2083
2085
|
},
|
|
2084
2086
|
load(id) {
|
|
2085
2087
|
if (id !== resolvedClientModuleId) return null;
|
|
2086
|
-
return createClientModule(getConfig());
|
|
2088
|
+
return createClientModule(getConfig(), development);
|
|
2087
2089
|
}
|
|
2088
2090
|
};
|
|
2089
2091
|
}
|
|
2090
|
-
function createClientModule(config) {
|
|
2092
|
+
function createClientModule(config, development) {
|
|
2091
2093
|
const imports = [];
|
|
2092
2094
|
const initializers = [];
|
|
2095
|
+
if (development) {
|
|
2096
|
+
imports.push(
|
|
2097
|
+
'import { initDevelopmentInspector } from "virtual:riebeckite/development-inspector";'
|
|
2098
|
+
);
|
|
2099
|
+
initializers.push("initDevelopmentInspector()");
|
|
2100
|
+
}
|
|
2093
2101
|
for (const [index, entry] of config.plugins.flatMap((plugin) => plugin.clientEntries ?? []).entries()) {
|
|
2094
2102
|
const localName = `pluginClientInitializer${index}`;
|
|
2095
2103
|
const importTarget = entry.exportName ? `{ ${entry.exportName} as ${localName} }` : localName;
|
|
@@ -2125,6 +2133,204 @@ ${initializers.map((initializer) => ` ${initializer};`).join("\n")}
|
|
|
2125
2133
|
`;
|
|
2126
2134
|
}
|
|
2127
2135
|
|
|
2136
|
+
// src/development_inspector.ts
|
|
2137
|
+
import { collectDevelopmentDiagnostics } from "@riebeckite/diagnostics";
|
|
2138
|
+
var clientModuleId2 = "virtual:riebeckite/development-inspector";
|
|
2139
|
+
var resolvedClientModuleId2 = `\0${clientModuleId2}`;
|
|
2140
|
+
var endpointPath = "/__riebeckite/inspector/report";
|
|
2141
|
+
function riebeckiteDevelopmentInspector(getApplication) {
|
|
2142
|
+
let revision = 0;
|
|
2143
|
+
return {
|
|
2144
|
+
name: "riebeckite-development-inspector",
|
|
2145
|
+
apply: "serve",
|
|
2146
|
+
enforce: "pre",
|
|
2147
|
+
resolveId(id) {
|
|
2148
|
+
return id === clientModuleId2 ? resolvedClientModuleId2 : null;
|
|
2149
|
+
},
|
|
2150
|
+
load(id) {
|
|
2151
|
+
return id === resolvedClientModuleId2 ? inspectorClientModule() : null;
|
|
2152
|
+
},
|
|
2153
|
+
configureServer(server) {
|
|
2154
|
+
const middleware = async (request, response) => {
|
|
2155
|
+
if (!isLocalRequest(request.headers.host, server)) {
|
|
2156
|
+
response.statusCode = 403;
|
|
2157
|
+
response.end();
|
|
2158
|
+
return;
|
|
2159
|
+
}
|
|
2160
|
+
try {
|
|
2161
|
+
const application = getApplication();
|
|
2162
|
+
const report = await collectDevelopmentDiagnostics({
|
|
2163
|
+
config: application.config,
|
|
2164
|
+
revision
|
|
2165
|
+
});
|
|
2166
|
+
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
2167
|
+
response.setHeader("cache-control", "no-store");
|
|
2168
|
+
const currentPage = currentPageFromRequest(request.url);
|
|
2169
|
+
response.end(
|
|
2170
|
+
JSON.stringify({
|
|
2171
|
+
...report,
|
|
2172
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2173
|
+
currentPage,
|
|
2174
|
+
theme: application.config.theme.name,
|
|
2175
|
+
plugins: application.config.plugins.map((plugin) => plugin.name),
|
|
2176
|
+
capabilities: {
|
|
2177
|
+
dependencies: "unavailable",
|
|
2178
|
+
output: "unavailable",
|
|
2179
|
+
pageMetadata: "unavailable"
|
|
2180
|
+
}
|
|
2181
|
+
})
|
|
2182
|
+
);
|
|
2183
|
+
} catch {
|
|
2184
|
+
response.statusCode = 500;
|
|
2185
|
+
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
2186
|
+
response.end(JSON.stringify({ code: "INSPECTOR_REPORT_FAILED" }));
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
server.middlewares.use(endpointPath, middleware);
|
|
2190
|
+
return () => prioritizeMiddleware(server, middleware);
|
|
2191
|
+
},
|
|
2192
|
+
handleHotUpdate({ server }) {
|
|
2193
|
+
revision += 1;
|
|
2194
|
+
server.hot.send({ type: "custom", event: "riebeckite:inspector" });
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
function currentPageFromRequest(url) {
|
|
2199
|
+
const value = new URL(url ?? endpointPath, "http://localhost").searchParams.get(
|
|
2200
|
+
"path"
|
|
2201
|
+
);
|
|
2202
|
+
return value && value.startsWith("/") && !value.startsWith("//") ? value : "/";
|
|
2203
|
+
}
|
|
2204
|
+
function prioritizeMiddleware(server, middleware) {
|
|
2205
|
+
const stack = server.middlewares.stack;
|
|
2206
|
+
const index = stack?.findIndex(
|
|
2207
|
+
(layer) => layer.handle === middleware || layer.route === endpointPath
|
|
2208
|
+
) ?? -1;
|
|
2209
|
+
if (index > 0 && stack) stack.unshift(...stack.splice(index, 1));
|
|
2210
|
+
}
|
|
2211
|
+
function isLocalRequest(host, server) {
|
|
2212
|
+
if (!host) return false;
|
|
2213
|
+
const hostname = host.replace(/:\d+$/, "").toLowerCase();
|
|
2214
|
+
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]")
|
|
2215
|
+
return true;
|
|
2216
|
+
const address = server.httpServer?.address();
|
|
2217
|
+
return typeof address === "object" && address?.address === hostname;
|
|
2218
|
+
}
|
|
2219
|
+
function inspectorClientModule() {
|
|
2220
|
+
return `
|
|
2221
|
+
const endpoint = ${JSON.stringify(endpointPath)};
|
|
2222
|
+
const panelId = "riebeckite-development-inspector";
|
|
2223
|
+
|
|
2224
|
+
export function initDevelopmentInspector() {
|
|
2225
|
+
let panel;
|
|
2226
|
+
let launcher;
|
|
2227
|
+
let controller;
|
|
2228
|
+
let generation = 0;
|
|
2229
|
+
let report;
|
|
2230
|
+
let activeTab = 0;
|
|
2231
|
+
const tabs = ["Overview", "Diagnostics", "Dependencies", "Plugins", "Output"];
|
|
2232
|
+
const refresh = async () => {
|
|
2233
|
+
if (!panel?.isConnected) return;
|
|
2234
|
+
controller?.abort();
|
|
2235
|
+
controller = new AbortController();
|
|
2236
|
+
const current = ++generation;
|
|
2237
|
+
try {
|
|
2238
|
+
const response = await fetch(endpoint + "?path=" + encodeURIComponent(location.pathname), { cache: "no-store", signal: controller.signal });
|
|
2239
|
+
if (!response.ok) throw new Error("Inspector report is unavailable.");
|
|
2240
|
+
const next = await response.json();
|
|
2241
|
+
if (current !== generation || !panel?.isConnected) return;
|
|
2242
|
+
report = next;
|
|
2243
|
+
render();
|
|
2244
|
+
} catch (error) {
|
|
2245
|
+
if (error.name === "AbortError" || current !== generation) return;
|
|
2246
|
+
renderFailure(panel.shadowRoot, error instanceof Error ? error.message : String(error));
|
|
2247
|
+
panel.shadowRoot.querySelector("[data-close]").addEventListener("click", close);
|
|
2248
|
+
}
|
|
2249
|
+
};
|
|
2250
|
+
const open = () => {
|
|
2251
|
+
if (!panel) {
|
|
2252
|
+
panel = document.createElement("div");
|
|
2253
|
+
panel.id = panelId;
|
|
2254
|
+
panel.attachShadow({ mode: "open" });
|
|
2255
|
+
document.body.append(panel);
|
|
2256
|
+
}
|
|
2257
|
+
refresh();
|
|
2258
|
+
};
|
|
2259
|
+
const close = () => {
|
|
2260
|
+
generation += 1;
|
|
2261
|
+
controller?.abort();
|
|
2262
|
+
panel?.remove();
|
|
2263
|
+
launcher?.focus();
|
|
2264
|
+
};
|
|
2265
|
+
launcher = document.createElement("button");
|
|
2266
|
+
launcher.type = "button";
|
|
2267
|
+
launcher.textContent = "Inspector";
|
|
2268
|
+
launcher.setAttribute("aria-label", "Open Riebeckite Development Inspector");
|
|
2269
|
+
launcher.style.cssText = "position:fixed;right:16px;bottom:16px;z-index:2147483647;border:1px solid #434343;border-radius:4px;background:#171717;color:#fff;padding:8px 12px;font:600 12px system-ui;cursor:pointer";
|
|
2270
|
+
launcher.addEventListener("click", open);
|
|
2271
|
+
document.body.append(launcher);
|
|
2272
|
+
window.addEventListener("keydown", (event) => {
|
|
2273
|
+
const editable = event.target instanceof HTMLElement && (event.target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(event.target.tagName));
|
|
2274
|
+
if (event.key === "Escape" && panel?.isConnected) {
|
|
2275
|
+
event.preventDefault();
|
|
2276
|
+
close();
|
|
2277
|
+
} else if (event.key.toLowerCase() === "r" && event.ctrlKey && event.altKey && !editable) {
|
|
2278
|
+
event.preventDefault();
|
|
2279
|
+
panel?.isConnected ? close() : open();
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
import.meta.hot?.on("riebeckite:inspector", refresh);
|
|
2283
|
+
|
|
2284
|
+
function render() {
|
|
2285
|
+
const root = panel.shadowRoot;
|
|
2286
|
+
root.innerHTML = '<style>' + styles + '</style><section role="dialog" aria-modal="false" aria-labelledby="rb-title" tabindex="-1"><header><div><strong id="rb-title">Riebeckite Inspector</strong><p>Ctrl+Alt+R</p></div><button type="button" data-close aria-label="Close inspector">Close</button></header><div class="summary"><b>' + report.summary.errors + '</b> errors <b>' + report.summary.warnings + '</b> warnings <b>' + report.summary.info + '</b> info</div><div role="tablist" aria-label="Inspector sections">' + tabs.map((tab, index) => '<button id="rb-tab-' + index + '" role="tab" aria-controls="rb-panel-' + index + '" aria-selected="' + (index === activeTab) + '" tabindex="' + (index === activeTab ? 0 : -1) + '" data-tab="' + index + '">' + tab + '</button>').join("") + '</div><div id="rb-panel-' + activeTab + '" role="tabpanel" aria-labelledby="rb-tab-' + activeTab + '" tabindex="0">' + panelContent() + '</div><p class="status" aria-live="polite">Inspector report updated</p></section>';
|
|
2287
|
+
root.querySelector("[data-close]").addEventListener("click", close);
|
|
2288
|
+
root.querySelectorAll("[data-tab]").forEach((button) => button.addEventListener("click", () => { activeTab = Number(button.dataset.tab); render(); }));
|
|
2289
|
+
root.querySelector("[role=tablist]").addEventListener("keydown", (event) => {
|
|
2290
|
+
if (event.key === "Home") activeTab = 0;
|
|
2291
|
+
else if (event.key === "End") activeTab = tabs.length - 1;
|
|
2292
|
+
else if (event.key === "ArrowRight" || event.key === "ArrowDown") activeTab = (activeTab + 1) % tabs.length;
|
|
2293
|
+
else if (event.key === "ArrowLeft" || event.key === "ArrowUp") activeTab = (activeTab + tabs.length - 1) % tabs.length;
|
|
2294
|
+
else return;
|
|
2295
|
+
event.preventDefault(); render(); root.querySelector('[data-tab="' + activeTab + '"]').focus();
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function panelContent() {
|
|
2299
|
+
if (activeTab === 0) return '<dl><dt>Page</dt><dd>' + escapeHtml(report.currentPage) + '</dd><dt>Theme</dt><dd>' + escapeHtml(report.theme) + '</dd><dt>Revision</dt><dd>' + escapeHtml(report.revision) + '</dd></dl>';
|
|
2300
|
+
if (activeTab === 1) return diagnosticList(report.diagnostics);
|
|
2301
|
+
if (activeTab === 2) return unavailable("Dependencies", report.capabilities.dependencies);
|
|
2302
|
+
if (activeTab === 3) return '<ul>' + (report.plugins.map((plugin) => '<li>' + escapeHtml(plugin) + '</li>').join("") || "<li>No plugins configured.</li>") + '</ul>';
|
|
2303
|
+
return unavailable("Output", report.capabilities.output);
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
function diagnosticList(diagnostics) {
|
|
2308
|
+
return '<ul>' + (diagnostics.map((diagnostic) =>
|
|
2309
|
+
'<li data-severity="' + escapeHtml(diagnostic.severity) + '"><b>' + escapeHtml(diagnostic.code) + '</b> ' + escapeHtml(diagnostic.message) + location(diagnostic) + '</li>'
|
|
2310
|
+
).join("") || "<li>No diagnostic findings.</li>") + '</ul>';
|
|
2311
|
+
}
|
|
2312
|
+
|
|
2313
|
+
function unavailable(subject, capability) {
|
|
2314
|
+
return '<p class="partial">' + escapeHtml(subject) + ': ' + escapeHtml(capability) + ' in the development inspector.</p>';
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
function renderFailure(root, message) {
|
|
2318
|
+
root.innerHTML = '<style>' + styles + '</style><section role="dialog" aria-modal="false" aria-labelledby="rb-failure-title"><header><strong id="rb-failure-title">Riebeckite Inspector</strong><button type="button" data-close aria-label="Close inspector">Close</button></header><p class="failure" aria-live="polite">' + escapeHtml(message) + '</p></section>';
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
function location(diagnostic) {
|
|
2322
|
+
const location = diagnostic.location;
|
|
2323
|
+
return location?.file ? ' <small>(' + escapeHtml(location.file) + (location.line ? ':' + location.line : '') + ')</small>' : '';
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
function escapeHtml(value) {
|
|
2327
|
+
return String(value).replace(/[&<>"]/g, (character) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[character]);
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
const styles = ':host{all:initial}section{position:fixed;right:16px;bottom:56px;z-index:2147483647;width:min(540px,calc(100vw - 32px));max-height:70vh;overflow:auto;background:#171717;color:#f4f4f4;border:1px solid #555;padding:16px;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;box-shadow:0 8px 24px #0006}header{display:flex;justify-content:space-between;gap:16px;border-bottom:1px solid #555;padding-bottom:8px}header p,.status,small{color:#b8b8b8;margin:2px 0}.summary{margin:12px 0}button{border:1px solid #666;background:#242424;color:#fff;padding:6px 8px;cursor:pointer}button[aria-selected="true"]{border-color:#e2c57b;color:#ffe08a}.partial{color:#e2c57b}ul{margin:12px 0;padding-left:20px}li{margin:8px 0}li[data-severity="error"]{color:#ff9797}li[data-severity="warning"]{color:#ffe08a}dl{display:grid;grid-template-columns:max-content 1fr;gap:8px 16px}dt{color:#b8b8b8}.failure{color:#ff9797}@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important}}@media(max-width:560px){section{right:8px;bottom:52px;width:calc(100vw - 32px);max-height:75vh}}';
|
|
2331
|
+
`;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2128
2334
|
// src/vite_runner.ts
|
|
2129
2335
|
import fs7 from "node:fs/promises";
|
|
2130
2336
|
import path9 from "node:path";
|
|
@@ -2356,7 +2562,8 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
2356
2562
|
appRoot: () => requireApplication(application).appRoot,
|
|
2357
2563
|
contentRoot: () => requireApplication(application).contentRoot,
|
|
2358
2564
|
exclude: () => getConfig().content.exclude ?? []
|
|
2359
|
-
})
|
|
2565
|
+
}),
|
|
2566
|
+
riebeckiteDevelopmentInspector(() => requireApplication(application))
|
|
2360
2567
|
];
|
|
2361
2568
|
}
|
|
2362
2569
|
function requireApplication(application) {
|
package/dist/server.js
CHANGED
|
@@ -130,7 +130,7 @@ function mountRiebeckiteEndpoints(app, options) {
|
|
|
130
130
|
for (const endpoint of endpoints) {
|
|
131
131
|
const method = endpoint.method ?? "GET";
|
|
132
132
|
const handler = async (context) => {
|
|
133
|
-
const manifest = await options.content.getManifest();
|
|
133
|
+
const manifest = endpoint.requiresManifest === false ? void 0 : await options.content.getManifest();
|
|
134
134
|
const request = await toPluginEndpointRequest(context, method);
|
|
135
135
|
const response = await endpoint.handler({
|
|
136
136
|
config: options.config,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
|
|
2
2
|
import type { Plugin } from "vite";
|
|
3
|
-
export declare function riebeckiteClientModule(getConfig: () => ResolvedRiebeckiteConfig): Plugin;
|
|
3
|
+
export declare function riebeckiteClientModule(getConfig: () => Pick<ResolvedRiebeckiteConfig, "plugins">): Plugin;
|
|
@@ -10,7 +10,6 @@ export type PrimitiveClassProps = {
|
|
|
10
10
|
className?: string;
|
|
11
11
|
};
|
|
12
12
|
export type ArticleProps = PrimitiveProps & {
|
|
13
|
-
"data-slot"?: string;
|
|
14
13
|
post?: PostContent;
|
|
15
14
|
entry?: PublicContentEntry;
|
|
16
15
|
};
|
|
@@ -26,7 +25,6 @@ export type ArticleHeaderProps = (PrimitiveClassProps & {
|
|
|
26
25
|
});
|
|
27
26
|
export type ArticleContentProps = PrimitiveClassProps & {
|
|
28
27
|
children?: PrimitiveChildren;
|
|
29
|
-
"data-slot"?: string;
|
|
30
28
|
};
|
|
31
29
|
export type ArticleMetaProps = PrimitiveProps & {
|
|
32
30
|
label?: string;
|
|
@@ -15,14 +15,7 @@ import {
|
|
|
15
15
|
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
|
|
16
16
|
import { createElement } from "hono/jsx";
|
|
17
17
|
function Article(props) {
|
|
18
|
-
const article = /* @__PURE__ */ jsx(
|
|
19
|
-
"article",
|
|
20
|
-
{
|
|
21
|
-
class: joinClassNames("rb-article", props.class, props.className),
|
|
22
|
-
"data-slot": props["data-slot"] ?? "article",
|
|
23
|
-
children: props.children
|
|
24
|
-
}
|
|
25
|
-
);
|
|
18
|
+
const article = /* @__PURE__ */ jsx("article", { class: joinClassNames("rb-article", props.class, props.className), children: props.children });
|
|
26
19
|
if (!props.post) return article;
|
|
27
20
|
return /* @__PURE__ */ jsx(ArticleProvider, { entry: props.entry, post: props.post, children: article });
|
|
28
21
|
}
|
|
@@ -68,8 +61,7 @@ function ArticleContent(props) {
|
|
|
68
61
|
props.class,
|
|
69
62
|
props.className
|
|
70
63
|
);
|
|
71
|
-
|
|
72
|
-
return /* @__PURE__ */ jsx("div", { class: className, "data-slot": dataSlot, children: props.children });
|
|
64
|
+
return /* @__PURE__ */ jsx("div", { class: className, children: props.children });
|
|
73
65
|
}
|
|
74
66
|
function HtmlFragment(props) {
|
|
75
67
|
return raw(props.html);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/honox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,13 +44,14 @@
|
|
|
44
44
|
"hono": "^4.12.25",
|
|
45
45
|
"honox": "0.1.56",
|
|
46
46
|
"vite": "^8.0.9",
|
|
47
|
-
"@riebeckite/core": "0.0.
|
|
48
|
-
"@riebeckite/
|
|
49
|
-
"@riebeckite/plugin-color-mode": "0.0.
|
|
47
|
+
"@riebeckite/core": "0.0.31",
|
|
48
|
+
"@riebeckite/diagnostics": "0.0.31",
|
|
49
|
+
"@riebeckite/plugin-color-mode": "0.0.31",
|
|
50
|
+
"@riebeckite/ui": "0.0.31"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"tsx": "^4.22.4",
|
|
53
|
-
"@riebeckite/test": "0.0.
|
|
54
|
+
"@riebeckite/test": "0.0.31"
|
|
54
55
|
},
|
|
55
56
|
"publishConfig": {
|
|
56
57
|
"access": "public"
|