Refresh UI components and showcase; release updated framework packages
This commit is contained in:
1 parent
d800228585
commit
c77f5e1cec
293 files changed
+22544
-35778
No files matched your search
@@ -120,6 +120,9 @@ export function createContext<Params extends Record<string, string> = Record<str
|
||||
req: Request,
|
||||
url: URL,
|
||||
): Context<Params> {
|
||||
// The caller supplies the validated public URL (including trusted proxies).
|
||||
// Request-based handlers must see the same origin as ctx.url.
|
||||
if (req.url !== url.href) req = new Request(url, req);
|
||||
const cookies = createCookieStore(req);
|
||||
return {
|
||||
req,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { getRequestContext } from "./request-context.ts";
|
||||
import { Buffer } from "node:buffer";
|
||||
|
||||
type Registry = { id: string; definitions: unknown[] };
|
||||
const registries = new WeakMap<object, Registry>();
|
||||
|
||||
/** Hoist nested templates out of each other for linear-size hydration data. */
|
||||
export function encodeControlTemplate(value: unknown): string {
|
||||
const ctx = getRequestContext();
|
||||
if (!ctx) return Buffer.from(JSON.stringify(value), "utf8").toString("base64");
|
||||
let registry = registries.get(ctx);
|
||||
if (!registry) {
|
||||
registry = { id: `wrn-controls-${crypto.randomUUID()}`, definitions: [] };
|
||||
registries.set(ctx, registry);
|
||||
}
|
||||
const index = registry.definitions.push(value) - 1;
|
||||
return `@${registry.id}:${index}`;
|
||||
}
|
||||
|
||||
export function renderControlTemplates(): string {
|
||||
const ctx = getRequestContext();
|
||||
const registry = ctx && registries.get(ctx);
|
||||
if (!registry) return "";
|
||||
const json = JSON.stringify(registry.definitions).replace(/</g, "\\u003c");
|
||||
return `<script type="application/json" data-wrn-controls id="${registry.id}">${json}</script>`;
|
||||
}
|
||||
@@ -237,3 +237,4 @@ export type {
|
||||
IdempotencyRecord,
|
||||
IdempotencyStore,
|
||||
} from "./platform.ts";
|
||||
export { encodeControlTemplate, renderControlTemplates } from "./control-templates.ts";
|
||||
Reference in new issue
Block a user