@samveys/view
Kontrak ViewEngine, registry engine dan ctx.view
Daftar ini dibaca dari versi 1.0.2; jalankan pnpm sync untuk memperbaruinya.
import { createViewContext, createViewRegistry, view } from '@samveys/view'
Fungsi (3)
createViewContext
Fungsi
The per-request `ctx.view`. Shared data is merged under the data given to `render` (render wins).
function createViewContext(registry: ViewRegistry, http: HttpContext): ViewContext;
Diekspor dari packages/view/src/registry.ts
createViewRegistry
Fungsi
Creates an engine registry. The first engine registered becomes the active one unless `use()` picks another.
function createViewRegistry(initial?: string): ViewRegistry;
Diekspor dari packages/view/src/registry.ts
view
Fungsi
The `@samveys/view` plugin. Binds `'view.registry'` and adds the lazy `ctx.view`. Engine plugins (`template()`, `vue()`) list it in `requires.plugins` and register themselves with `container.make('view.registry').register(name, engine)`.
function view(options?: ViewOptions): import("@samveys/core").Plugin<ViewOptions>;
Diekspor dari packages/view/src/plugin.ts
Interface (7)
InertiaRoot
Interface
What the `@inertia` directive of a template reads from the `$inertia` variable. `@samveys/inertia` passes it when it renders the root view.
interface InertiaRoot {
/** The page object, serialized into `data-page`. */
readonly page: unknown;
/** Id of the root element. Default `app`. */
readonly id?: string;
/** Server-rendered markup placed inside the root element. */
readonly body?: string;
/** Server-rendered `<head>` markup, printed by `@inertiaHead`. */
readonly head?: string;
}
Diekspor dari packages/view/src/contracts.ts
ViewContext
Interface
Per-request view API exposed as `ctx.view`.
interface ViewContext {
render(name: string, data?: Record<string, unknown>, init?: ResponseInit): Promise<Response>;
share(key: string, value: unknown): void;
readonly shared: Readonly<Record<string, unknown>>;
}
Diekspor dari packages/view/src/contracts.ts
ViewEngine
Interface
A pluggable view engine.
interface ViewEngine {
render(name: string, data: Record<string, unknown>, ctx?: ViewRenderContext): Promise<string>;
}
Diekspor dari packages/view/src/contracts.ts
ViewHelpers
Interface
Services other packages contribute and engines consume, so that `@samveys/template` does not depend on `@samveys/vite` or `@samveys/security`. Each plugin sets its own entry when it boots.
interface ViewHelpers {
/** Tags for Vite entries (`@vite(...)`): set by `@samveys/vite`. */
vite?: (entries: readonly string[]) => string | Promise<string>;
Diekspor dari packages/view/src/contracts.ts
ViewOptions
Interface
Tidak ada komentar dokumentasi.
interface ViewOptions {
/** Name of the engine to use; default is the first engine registered. */
readonly engine?: string;
}
Diekspor dari packages/view/src/plugin.ts
ViewRegistry
Interface
Registry holding the available engines and which one is active.
interface ViewRegistry {
register(name: string, engine: ViewEngine): void;
use(name: string): void;
has(name: string): boolean;
/** The named engine, or the active one. Throws `SVS_E109` when none is registered. */
get(name?: string): ViewEngine;
readonly active: string | undefined;
readonly helpers: ViewHelpers;
}
Diekspor dari packages/view/src/contracts.ts
ViewRenderContext
Interface
Per-request context handed to an engine so it can read request state (CSRF token, cookies).
interface ViewRenderContext {
readonly http?: HttpContext;
}
Diekspor dari packages/view/src/contracts.ts