@nexusts/view 0.7.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.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @nexusts/view
2
+
3
+ > **NexusTS** — Bun-native fullstack framework
4
+
5
+ ## Description
6
+
7
+ View engines (Rendu, Edge, Eta) + Inertia.js v2 adapter.
8
+
9
+ 3 engines: Rendu (default, every runtime), Edge (Adonis-style .edge), Eta (EJS-style .eta). Inertia v2 adapter for React + Vue SPAs and SSR.
10
+
11
+ ## Install
12
+
13
+ This module is part of the NexusTS monorepo. Each module is published as its own npm package under the `@nexusts/` scope.
14
+
15
+ Most apps start with just the core:
16
+
17
+ ```bash
18
+ bun add @nexusts/core
19
+ ```
20
+
21
+ Then add this module only if you need it:
22
+
23
+ ```bash
24
+ bun add @nexusts/view
25
+ ```
26
+
27
+ ## Peer dependencies
28
+
29
+ **None.** No external dependencies for Rendu / Edge / Eta. Inertia.js React requires `react` and `@inertiajs/react`; Inertia.js Vue requires `vue` and `@inertiajs/vue3`.
30
+
31
+ ## Usage
32
+
33
+ ```typescript
34
+ import { /* public API */ } from "@nexusts/view";
35
+ ```
36
+
37
+ See the [user guide](../../docs/user-guide/view.md) and the [example app](../../examples/) for a working demo.
38
+
39
+ ## License
40
+
41
+ MIT — see the root [LICENSE](../../LICENSE).
package/dist/edge.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Edge-style template engine adapter (Adonis-style).
3
+ *
4
+ * Edge is the templating engine built for AdonisJS with a mustache-like
5
+ * syntax (`{{ }}`, `@if`, `@each`). It is bundled here as a placeholder
6
+ * for users who prefer that style.
7
+ *
8
+ * The adapter does not bundle Edge directly — it expects the user to
9
+ * provide an `Edge` instance via the constructor so the dependency
10
+ * stays optional.
11
+ */
12
+ import type { ViewAdapter, ViewContext, ViewOptions } from "./types.js";
13
+ export interface EdgeLike {
14
+ renderRaw?: (template: string, data: Record<string, any>) => Promise<string>;
15
+ renderString?: (template: string, data: Record<string, any>) => Promise<string>;
16
+ }
17
+ export declare class EdgeAdapter implements ViewAdapter {
18
+ private edge?;
19
+ readonly name = "edge";
20
+ constructor(edge?: EdgeLike);
21
+ render(template: string, data: Record<string, any>, context?: ViewContext, options?: ViewOptions): Promise<string>;
22
+ }
package/dist/eta.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Eta template engine adapter.
3
+ *
4
+ * Eta is a lightweight, high-performance templating engine with
5
+ * EJS-like syntax (`<%= expr %>`, `<% code %>`). It works on every
6
+ * runtime (Bun, Node, Deno, Cloudflare Workers) because templates
7
+ * are compiled to JavaScript render functions — no eval, no
8
+ * filesystem access at render time.
9
+ *
10
+ * Install (optional peer dep): `bun add eta`
11
+ *
12
+ * import { EtaAdapter } from "nexusjs/view";
13
+ * const eta = new EtaAdapter();
14
+ * const html = await eta.render("<h1><%= it.title %></h1>", { title: "Hi" });
15
+ *
16
+ * Or just use a file with a `.eta` extension — `renderView` picks
17
+ * the Eta adapter automatically:
18
+ *
19
+ * setViewPaths("views");
20
+ * return { view: "about.eta", data: { title: "Hi" } };
21
+ */
22
+ import type { ViewAdapter, ViewContext, ViewOptions } from "./types.js";
23
+ export declare class EtaAdapter implements ViewAdapter {
24
+ readonly name = "eta";
25
+ private cache;
26
+ render(template: string, data: Record<string, any>, _context?: ViewContext, _options?: ViewOptions): Promise<string>;
27
+ compile(template: string, _options?: ViewOptions): (data: Record<string, any>) => Promise<string>;
28
+ private getCompiled;
29
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `nexusjs/view` — view engine adapter + file-based view loader.
3
+ *
4
+ * Public API:
5
+ * - `renderView(template, data, context?)` — render a view.
6
+ * If `template` ends in a known file extension (`.html`, `.edge`,
7
+ * `.rendu`, `.eta`) AND `setViewPaths()` has been called, the
8
+ * file is loaded from the first matching directory and used
9
+ * as the template source. Otherwise the string is treated as
10
+ * inline source.
11
+ * The adapter is selected by file extension (or Rendu for
12
+ * inline / non-extension values).
13
+ * - `setViewPaths(path)` — configure the directory searched for
14
+ * view files. Pass `""` to disable.
15
+ * - `getViewPaths()` — return the current path (empty = disabled).
16
+ * - `loadTemplate(dir, name)` — low-level: load a file from
17
+ * the given directory.
18
+ * - `Application.setViewPaths(path)` — same as the module
19
+ * function, but chainable.
20
+ *
21
+ * Adapters:
22
+ * - RenduAdapter (default for `.html`/`.rendu`/inline)
23
+ * - EdgeAdapter (for `.edge`)
24
+ * - EtaAdapter (for `.eta`)
25
+ *
26
+ * Override with `app.setViewAdapter(new MyAdapter())` to install
27
+ * a different engine globally.
28
+ */
29
+ export type { ViewAdapter, ViewContext, ViewOptions, } from "./types.js";
30
+ export { RenduAdapter } from "./rendu.js";
31
+ export { EdgeAdapter } from "./edge.js";
32
+ export { EtaAdapter } from "./eta.js";
33
+ export { Inertia } from "./inertia/inertia-adapter.js";
34
+ export { defer, always, optional, merge, deepMerge, once, } from "./inertia/helpers.js";
35
+ export { InertiaFormBuilder } from "./inertia/form-helper.js";
36
+ export { inertiaFormMiddleware } from "./inertia/form-middleware.js";
37
+ export { renderDefaultRoot } from "./inertia/default-ssr.js";
38
+ export type { SsrAdapter, SsrRenderResult, InertiaConfig, InertiaPage, InertiaSharedProps, } from "./inertia/types.js";
39
+ export { createReactAdapter } from "./inertia/ssr/react-adapter.js";
40
+ export { createVueAdapter } from "./inertia/ssr/vue-adapter.js";
41
+ export { ComponentRegistry, createRegistry, asRegistry, } from "./inertia/ssr/registry.js";
42
+ export type { ReactSsrOptions } from "./inertia/ssr/react-adapter.js";
43
+ export type { VueSsrOptions } from "./inertia/ssr/vue-adapter.js";
44
+ export { renderView, loadTemplate, setViewPaths, getViewPaths, } from "./view-engine.js";