@niscorp/nova 0.1.2 → 0.1.4
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/ADAPTER.md +6 -0
- package/CHANGELOG.md +20 -0
- package/README.md +29 -1
- package/dist/adapters/dom/index.cjs +98 -4
- package/dist/adapters/dom/index.cjs.map +1 -1
- package/dist/adapters/dom/index.js +7 -7
- package/dist/adapters/dom/server.cjs +12 -1
- package/dist/adapters/dom/server.cjs.map +1 -1
- package/dist/adapters/dom/server.js +7 -7
- package/dist/adapters/react/components/index.cjs +32 -10
- package/dist/adapters/react/components/index.cjs.map +1 -1
- package/dist/adapters/react/components/index.d.cts +2 -2
- package/dist/adapters/react/components/index.d.ts +2 -2
- package/dist/adapters/react/components/index.js +9 -5
- package/dist/adapters/react/index.cjs +268 -97
- package/dist/adapters/react/index.cjs.map +1 -1
- package/dist/adapters/react/index.js +9 -5
- package/dist/adapters/tty/index.cjs +8 -1
- package/dist/adapters/tty/index.cjs.map +1 -1
- package/dist/adapters/tty/index.js +12 -1
- package/dist/adapters/tty/index.js.map +1 -1
- package/dist/adapters/vue/components/index.cjs +32 -1
- package/dist/adapters/vue/components/index.cjs.map +1 -1
- package/dist/adapters/vue/components/index.d.cts +1 -1
- package/dist/adapters/vue/components/index.d.ts +1 -1
- package/dist/adapters/vue/components/index.js +9 -5
- package/dist/adapters/vue/index.cjs +218 -23
- package/dist/adapters/vue/index.cjs.map +1 -1
- package/dist/adapters/vue/index.js +10 -9
- package/dist/adapters/vue/index.js.map +1 -1
- package/dist/{chunk-7S5BNPUS.js → chunk-4ERQYDF6.js} +36 -4
- package/dist/chunk-4ERQYDF6.js.map +1 -0
- package/dist/{chunk-FQAJ24KA.js → chunk-4I2PFMY7.js} +33 -8
- package/dist/chunk-4I2PFMY7.js.map +1 -0
- package/dist/{chunk-IGLCWXQ3.js → chunk-7PKS7UYL.js} +3 -3
- package/dist/{chunk-IGLCWXQ3.js.map → chunk-7PKS7UYL.js.map} +1 -1
- package/dist/{chunk-GVBBL36G.js → chunk-DIFE573X.js} +196 -4
- package/dist/chunk-DIFE573X.js.map +1 -0
- package/dist/chunk-EHHJJLRX.js +16 -0
- package/dist/chunk-EHHJJLRX.js.map +1 -0
- package/dist/{chunk-3HGE3VWK.js → chunk-KYQ4EAQH.js} +33 -11
- package/dist/chunk-KYQ4EAQH.js.map +1 -0
- package/dist/{chunk-V32EVEVM.js → chunk-RXECI7DE.js} +300 -5
- package/dist/chunk-RXECI7DE.js.map +1 -0
- package/dist/{chunk-4ZID7UX5.js → chunk-UUYXVOK2.js} +52 -8
- package/dist/chunk-UUYXVOK2.js.map +1 -0
- package/dist/chunk-UV5YGBHQ.js +62 -0
- package/dist/chunk-UV5YGBHQ.js.map +1 -0
- package/dist/{chunk-6N4WRC5V.js → chunk-WZVQ5PUB.js} +85 -12
- package/dist/chunk-WZVQ5PUB.js.map +1 -0
- package/dist/chunk-X7SSNSQC.js +6 -0
- package/dist/chunk-X7SSNSQC.js.map +1 -0
- package/dist/devtools/index.js +4 -5
- package/dist/devtools/index.js.map +1 -1
- package/dist/document/index.cjs +199 -0
- package/dist/document/index.cjs.map +1 -0
- package/dist/document/index.d.cts +20 -0
- package/dist/document/index.d.ts +20 -0
- package/dist/document/index.js +125 -0
- package/dist/document/index.js.map +1 -0
- package/dist/head-BNj8GwPO.d.cts +20 -0
- package/dist/head-CS6X6ZKr.d.ts +20 -0
- package/dist/index.cjs +77 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +5 -6
- package/dist/migrations/index.js +1 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/reflect/index.js +4 -5
- package/package.json +13 -3
- package/dist/chunk-3HGE3VWK.js.map +0 -1
- package/dist/chunk-4ZID7UX5.js.map +0 -1
- package/dist/chunk-6N4WRC5V.js.map +0 -1
- package/dist/chunk-7S5BNPUS.js.map +0 -1
- package/dist/chunk-FQAJ24KA.js.map +0 -1
- package/dist/chunk-GVBBL36G.js.map +0 -1
- package/dist/chunk-PF4OJTYU.js +0 -199
- package/dist/chunk-PF4OJTYU.js.map +0 -1
- package/dist/chunk-RQB4PRPV.js +0 -285
- package/dist/chunk-RQB4PRPV.js.map +0 -1
- package/dist/chunk-V32EVEVM.js.map +0 -1
- package/dist/chunk-ZITHBBF3.js +0 -85
- package/dist/chunk-ZITHBBF3.js.map +0 -1
- package/dist/{primitive-props-BH_EJWIe.d.ts → primitive-props-Cl5jiC8g.d.cts} +1 -1
- package/dist/{primitive-props-BH_EJWIe.d.cts → primitive-props-Cl5jiC8g.d.ts} +1 -1
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
export { ErrorMarker, Nova, NovaCanvas, NovaErrorBoundary, NovaLayout, NovaRenderProvider, NovaShell, NovaShellProvider, RenderNodeView, RenderTree, useActionData, useActionStatus, useCanvas, useCanvasRenderTree, useNovaDispatch, useNovaPublish, useNovaRegistry, useRenderTree, useShell, useShellRenderTree, useShellState, useSlotWrapper } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
1
|
+
export { ErrorMarker, Nova, NovaCanvas, NovaErrorBoundary, NovaLayout, NovaRenderProvider, NovaShell, NovaShellProvider, RenderNodeView, RenderTree, useActionData, useActionStatus, useCanvas, useCanvasRenderTree, useNovaDispatch, useNovaPublish, useNovaRegistry, useRenderTree, useShell, useShellRenderTree, useShellState, useSlotWrapper } from '../../chunk-KYQ4EAQH.js';
|
|
2
|
+
import '../../chunk-4ERQYDF6.js';
|
|
3
|
+
import '../../chunk-EHHJJLRX.js';
|
|
4
|
+
import '../../chunk-WZVQ5PUB.js';
|
|
5
|
+
import '../../chunk-UV5YGBHQ.js';
|
|
6
|
+
import '../../chunk-RXECI7DE.js';
|
|
7
|
+
import '../../chunk-OGD5CCMZ.js';
|
|
5
8
|
import '../../chunk-7TS3YVQR.js';
|
|
6
|
-
import '../../chunk-
|
|
9
|
+
import '../../chunk-X7SSNSQC.js';
|
|
10
|
+
import '../../chunk-DIFE573X.js';
|
|
7
11
|
import '../../chunk-JI7ZRESP.js';
|
|
8
12
|
import '../../chunk-RBU5PHN4.js';
|
|
9
13
|
import '../../chunk-2MNLEL45.js';
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/layout/head.ts
|
|
4
|
+
var HEAD_NAME = "nova:head";
|
|
5
|
+
|
|
6
|
+
// src/shell/head.ts
|
|
7
|
+
var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
|
|
8
|
+
|
|
3
9
|
// src/adapters/tty/index.ts
|
|
4
10
|
var CANVAS_SLOT = "CanvasSlot";
|
|
5
11
|
var ACTION_SLOT = "ActionSlot";
|
|
@@ -17,6 +23,7 @@ var renderNode = (node, ctx) => {
|
|
|
17
23
|
if (node.type === "text") return { lines: node.value.split("\n") };
|
|
18
24
|
if (node.type === "fragment") return { lines: node.children.flatMap((child) => renderNode(child, ctx).lines) };
|
|
19
25
|
if (node.type === "error") return errorBlock(node.code, node.message);
|
|
26
|
+
if (isHeadNode(node)) return { lines: [] };
|
|
20
27
|
if (node.name === CANVAS_SLOT) {
|
|
21
28
|
const canvasId = typeof node.props["canvasId"] === "string" ? node.props["canvasId"] : "";
|
|
22
29
|
if (canvasId === "") return { lines: [] };
|
|
@@ -31,7 +38,7 @@ var renderNode = (node, ctx) => {
|
|
|
31
38
|
if (build === void 0) return errorBlock("COMPONENT_NOT_FOUND", node.name);
|
|
32
39
|
const instanceId = node.name === ACTION_SLOT ? node.props["instanceId"] : void 0;
|
|
33
40
|
const inner = typeof instanceId === "string" && instanceId !== "" ? { ...ctx, origin: instanceId } : ctx;
|
|
34
|
-
const children = node.children.map((child) => renderNode(child, inner));
|
|
41
|
+
const children = node.children.filter((child) => !isHeadNode(child)).map((child) => renderNode(child, inner));
|
|
35
42
|
const register = (item) => {
|
|
36
43
|
const interactive = { index: ctx.out.length + 1, canvas: ctx.canvas, ...ctx.origin !== void 0 ? { origin: ctx.origin } : {}, ...item };
|
|
37
44
|
ctx.out.push(interactive);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/tty/index.ts"],"names":[],"mappings":";;;AA4EA,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,UAAA,GAAa,EAAA;AAiBnB,IAAM,UAAA,GAAa,CAAC,IAAA,EAAc,OAAA,MAA+B,EAAE,KAAA,EAAO,CAAC,CAAA,GAAA,EAAM,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAE,CAAA,EAAE,CAAA;AAErG,IAAM,OAAA,GAAU,CAAC,KAAA,EAAiB,GAAA,KAAwB;AACxD,EAAA,MAAM,QAAQ,KAAA,CAAM,KAAA,CAAM,CAAC,CAAA,EAAG,MAAK,IAAK,EAAA;AACxC,EAAA,OAAO,UAAU,EAAA,GAAK,GAAA,GAAM,KAAA,CAAM,KAAA,CAAM,GAAG,EAAE,CAAA;AAC/C,CAAA;AAIA,IAAM,UAAA,GAAa,CAAC,EAAA,KAAuB;AACzC,EAAA,MAAM,IAAA,GAAO,gBAAM,EAAE,CAAA,CAAA,CAAA;AACrB,EAAA,OAAO,IAAA,GAAO,SAAI,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA,EAAG,UAAA,GAAa,IAAA,CAAK,MAAM,CAAC,CAAA;AAChE,CAAA;AAEA,IAAM,UAAA,GAAa,CAAC,IAAA,EAAkB,GAAA,KAAuB;AAC3D,EAAA,IAAI,IAAA,CAAK,IAAA,KAAS,MAAA,EAAQ,OAAO,EAAE,OAAO,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA,EAAE;AACjE,EAAA,IAAI,KAAK,IAAA,KAAS,UAAA,EAAY,OAAO,EAAE,OAAO,IAAA,CAAK,QAAA,CAAS,OAAA,CAAQ,CAAC,UAAU,UAAA,CA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AA,CAAI,IAAI,MAAA,GAAS,CAAC,GAAG,IAAA,EAAK,KAAM,EAAA,EAAI,GAAA,CAAI,GAAA,EAAI;AACnD,EAAA,OAAO,GAAA;AACT,CAAA;AAEO,IAAM,gBAAgB,CAC3B,QAAA,EACA,GAAA,EACA,OAAA,GAAuC,EAAC,KAC5B;AACZ,EAAA,MAAM,SAAS,MAAgB;AAC7B,IAAA,MAAM,MAAwB,EAAC;AAG/B,IAAA,MAAM,MAAW,EAAE,QAAA,EAAU,MAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAK,GAAI,OAAA,CAAQ,QAAA,KAAa,SAAY,EAAE,QAAA,EAAU,QAAQ,QAAA,EAAS,GAAI,EAAC,EAAG;AAC7H,IAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,EAAM,CAAE,OAAA,CAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,IAAA,EAAM,GAAG,CAAA,CAAE,KAAK,CAAA;AACvE,IAAA,OAAO,EAAE,MAAM,IAAA,CAAK,KAAK,EAAE,IAAA,CAAK,IAAI,CAAA,EAAG,YAAA,EAAc,GAAA,EAAI;AAAA,EAC3D,CAAA;AACA,EAAA,OAAO,EAAE,MAAA,EAAO;AAClB","file":"index.cjs","sourcesContent":["import type { ComponentRegistry, RenderNode } from '@layout/types';\nimport type { RenderApi } from '@shell';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/tty — a text adapter, the terminal sibling of\n// nova/dom. It turns a served RenderNode tree into lines of plain text plus a\n// numbered table of INTERACTIVES: every `ref`'d node prints with a `[n]`\n// marker and lands in the table, so a REPL host can map \"click 3\" / \"set 5 x\"\n// onto the same event vocabulary the DOM adapter wires by convention —\n// `ui:click` (payload = the node's `value` prop), `ui:model`, `ui:key`.\n// Origin is never stamped here — moss stamps the active instance server-side.\n//\n// No framework, no I/O, no node builtins: render() is a pure snapshot →\n// { text, interactives }. The host (moss's terminal/tty target) owns stdio,\n// prompts, and dispatch; this adapter only says what the screen IS and what\n// on it can be acted on. `CanvasSlot` is resolved here (the frame's markers →\n// per-canvas trees), the one piece of terminal structure the renderer owns.\n// See packages/nova/ADAPTER.md for the shared adapter contract.\n// ═══════════════════════════════════════════════════════════\n\n// A rendered block: lines of text, composed upward (a Stack stacks child\n// blocks, a Row joins single-line children inline, …).\nexport type TtyBlock = { lines: string[] };\n\n// What an interactive marker can be driven with — the REPL host maps these\n// to events: click/row → ui:click, model → ui:model (a typed value),\n// toggle → ui:model (a negated boolean).\nexport type TtyInteractiveKind = 'click' | 'row' | 'model' | 'toggle';\n\nexport type TtyInteractive = {\n // the printed `[n]` — 1-based, in registration order\n index: number;\n kind: TtyInteractiveKind;\n ref: string;\n // the canvas whose dispatch this belongs to; '' = frame chrome (dispatches\n // nothing, same as the DOM adapter's frame)\n canvas: string;\n // the action instance it sits in (the enclosing ActionSlot's instanceId) —\n // a list canvas renders several live instances at once, so the host stamps\n // this as the event's origin, exactly as the DOM adapter does. Absent\n // outside any instance.\n origin?: string;\n // what was printed — for the host's `refs` listing\n label: string;\n // click/row: the dispatch payload; model/toggle: the current value\n value?: unknown;\n // the model path, when model-bound — display only, the server owns meaning\n path?: string;\n};\n\nexport type TtyComponentContext = {\n props: Record<string, unknown>;\n // the node's children, already rendered — the component stacks or joins\n // them where it wants (leaves ignore them).\n children: TtyBlock[];\n // register an interactive and get its printed index — for data-driven\n // components with INTERNAL interactivity (a table's rows, a panel's ✕);\n // simple components let the renderer mark their `ref`/`model` by convention.\n register: (entry: { kind: TtyInteractiveKind; ref: string; label: string; value?: unknown; path?: string }) => number;\n};\n\n// A TTY component: props + rendered children in, one block of lines out.\nexport type TtyComponent = (ctx: TtyComponentContext) => TtyBlock;\n\n// What the terminal hands the view: core's `RenderApi` — the same single\n// definition the dom/react adapters and moss's terminal share.\nexport type TtyRenderApi = RenderApi;\n\n// One rendered frame: the full screen text and everything actionable on it.\nexport type TtyFrame = { text: string; interactives: TtyInteractive[] };\n\nexport type TtyView = {\n // render the current snapshot; call on every wire change\n render: () => TtyFrame;\n};\n\nconst CANVAS_SLOT = 'CanvasSlot';\nconst ACTION_SLOT = 'ActionSlot';\nconst RULE_WIDTH = 60;\n\n// The recursion context: the registry, the canvas in force (frame chrome is\n// ''; a CanvasSlot switches it), the interactive accumulator, the resolver.\ntype Ctx = {\n registry: ComponentRegistry<TtyComponent>;\n canvas: string;\n // the enclosing action instance, when inside one (an ActionSlot switches it)\n origin?: string;\n api: TtyRenderApi;\n out: TtyInteractive[];\n // used when a component name is unregistered — a permissive renderer (the\n // default kit) supplies one so unknown primitives render their children\n // instead of an error; strict consumers omit it.\n fallback?: TtyComponent;\n};\n\nconst errorBlock = (code: string, message: string): TtyBlock => ({ lines: [`!! ${code}: ${message}`] });\n\nconst labelOf = (block: TtyBlock, ref: string): string => {\n const first = block.lines[0]?.trim() ?? '';\n return first === '' ? ref : first.slice(0, 48);\n};\n\n// A canvas heading: `── main ─────…` — the one piece of chrome the renderer\n// prints itself, so a REPL reader can tell canvases apart.\nconst canvasRule = (id: string): string => {\n const head = `── ${id} `;\n return head + '─'.repeat(Math.max(0, RULE_WIDTH - head.length));\n};\n\nconst renderNode = (node: RenderNode, ctx: Ctx): TtyBlock => {\n if (node.type === 'text') return { lines: node.value.split('\\n') };\n if (node.type === 'fragment') return { lines: node.children.flatMap((child) => renderNode(child, ctx).lines) };\n if (node.type === 'error') return errorBlock(node.code, node.message);\n\n // component\n if (node.name === CANVAS_SLOT) {\n const canvasId = typeof node.props['canvasId'] === 'string' ? (node.props['canvasId'] as string) : '';\n if (canvasId === '') return { lines: [] };\n const tree = ctx.api.canvasTree(canvasId);\n // an empty canvas collapses entirely — no heading for nothing\n if (tree.length === 0) return { lines: [] };\n // a canvas starts outside any instance, even one placed by an instance's layout\n const { origin: _outer, ...outside } = ctx;\n const canvasCtx: Ctx = { ...outside, canvas: canvasId };\n return { lines: [canvasRule(canvasId), ...tree.flatMap((child) => renderNode(child, canvasCtx).lines), ''] };\n }\n\n const entry = ctx.registry.get(node.name);\n const build = entry !== undefined ? entry.component : ctx.fallback;\n if (build === undefined) return errorBlock('COMPONENT_NOT_FOUND', node.name);\n\n // An ActionSlot is an instance boundary: what is inside it belongs to it.\n const instanceId = node.name === ACTION_SLOT ? node.props['instanceId'] : undefined;\n const inner: Ctx = typeof instanceId === 'string' && instanceId !== '' ? { ...ctx, origin: instanceId } : ctx;\n const children = node.children.map((child) => renderNode(child, inner));\n const register: TtyComponentContext['register'] = (item) => {\n const interactive: TtyInteractive = { index: ctx.out.length + 1, canvas: ctx.canvas, ...(ctx.origin !== undefined ? { origin: ctx.origin } : {}), ...item };\n ctx.out.push(interactive);\n return interactive.index;\n };\n const block = build({ props: node.props, children, register });\n\n // Convention wiring, the TTY twin of the DOM adapter's listeners: a model'd\n // node is an input (`toggle` when its current value is a boolean), a bare\n // ref'd node is clickable (payload = its `value` prop). The marker lands on\n // the block's first line.\n if (node.model !== undefined) {\n const current = node.props['value'] ?? node.props['checked'];\n const kind: TtyInteractiveKind = typeof current === 'boolean' ? 'toggle' : 'model';\n const index = register({ kind, ref: node.model.ref, label: labelOf(block, node.model.ref), value: current, path: node.model.path });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n if (node.ref !== undefined) {\n const value = node.props['value'];\n const index = register({ kind: 'click', ref: node.ref, label: labelOf(block, node.ref), ...(value !== undefined ? { value } : {}) });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n return block;\n};\n\n// Collapse runs of blank lines so stacked empty canvases don't leave gaps.\nconst tidy = (lines: string[]): string[] => {\n const out: string[] = [];\n for (const line of lines) {\n if (line.trim() === '' && out[out.length - 1]?.trim() === '') continue;\n out.push(line);\n }\n while (out[0]?.trim() === '') out.shift();\n while (out[out.length - 1]?.trim() === '') out.pop();\n return out;\n};\n\nexport const createTtyView = (\n registry: ComponentRegistry<TtyComponent>,\n api: TtyRenderApi,\n options: { fallback?: TtyComponent } = {},\n): TtyView => {\n const render = (): TtyFrame => {\n const out: TtyInteractive[] = [];\n // The frame is chrome — its interactives belong to no canvas and the host\n // dispatches nothing for them, same as the DOM adapter's frame dispatch.\n const ctx: Ctx = { registry, canvas: '', api, out, ...(options.fallback !== undefined ? { fallback: options.fallback } : {}) };\n const lines = api.frame().flatMap((node) => renderNode(node, ctx).lines);\n return { text: tidy(lines).join('\\n'), interactives: out };\n };\n return { render };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/layout/head.ts","../../../src/shell/head.ts","../../../src/adapters/tty/index.ts"],"names":[],"mappings":";;;AAwBO,IAAM,SAAA,GAAY,WAAA;;;AC8BlB,IAAM,aAAa,CAAC,IAAA,KAA8B,KAAK,IAAA,KAAS,WAAA,IAAe,KAAK,IAAA,KAAS,SAAA;;;ACuBpG,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,UAAA,GAAa,EAAA;AAiBnB,IAAM,UAAA,GAAa,CAAC,IAAA,EAAc,OAAA,MAA+B,EAAE,KAAA,EAAO,CAAC,CAAA,GAAA,EAAM,IAAI,CAAA,EAAA,EAAK,OAAO,CAAA,CAAE,CAAA,EAAE,CAAA;AAErG,IAAM,OAAA,GAAU,CAAC,KAAA,EAAiB,GAAA,KAAwB;AACxD,EAAA,MAAM,QAAQ,KAAA,CAAM,KAAA,CAAM,CAAC,CAAA,EAAG,MAAK,IAAK,EAAA;AACxC,EAAA,OAAO,UAAU,EAAA,GAAK,GAAA,GAAM,KAAA,CAAM,KAAA,CAAM,GAAG,EAAE,CAAA;AAC/C,CAAA;AAIA,IAAM,UAAA,GAAa,CAAC,EAAA,KAAuB;AACzC,EAAA,MAAM,IAAA,GAAO,gBAAM,EAAE,CAAA,CAAA,CAAA;AACrB,EAAA,OAAO,IAAA,GAAO,SAAI,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA,EAAG,UAAA,GAAa,IAAA,CAAK,MAAM,CAAC,CAAA;AAChE,CAAA;AA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,KAAA;AACT,CAAA;AAGA,IAAM,IAAA,GAAO,CAAC,KAAA,KAA8B;AAC1C,EAAA,MAAM,MAAgB,EAAC;AACvB,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,IAAA,CAAK,IAAA,EAAK,KAAM,EAAA,IAAM,GAAA,CAAI,GAAA,CAAI,MAAA,GAAS,CAAC,CAAA,EAAG,IAAA,EAAK,KAAM,EAAA,EAAI;AAC9D,IAAA,GAAA,CAAI,KAAK,IAAI,CAAA;AAAA,EACf;AACA,EAAA,OAAO,IAAI,CAAC,CAAA,EAAG,MAAK,KAAM,EAAA,MAAQ,KAAA,EAAM;AACxC,EAAA,OAAO,GAAA,CAAI,IAAI,MAAA,GAAS,CAAC,GAAG,IAAA,EAAK,KAAM,EAAA,EAAI,GAAA,CAAI,GAAA,EAAI;AACnD,EAAA,OAAO,GAAA;AACT,CAAA;AAEO,IAAM,gBAAgB,CAC3B,QAAA,EACA,GAAA,EACA,OAAA,GAAuC,EAAC,KAC5B;AACZ,EAAA,MAAM,SAAS,MAAgB;AAC7B,IAAA,MAAM,MAAwB,EAAC;AAG/B,IAAA,MAAM,MAAW,EAAE,QAAA,EAAU,MAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAK,GAAI,OAAA,CAAQ,QAAA,KAAa,SAAY,EAAE,QAAA,EAAU,QAAQ,QAAA,EAAS,GAAI,EAAC,EAAG;AAC7H,IAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,EAAM,CAAE,OAAA,CAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,IAAA,EAAM,GAAG,CAAA,CAAE,KAAK,CAAA;AACvE,IAAA,OAAO,EAAE,MAAM,IAAA,CAAK,KAAK,EAAE,IAAA,CAAK,IAAI,CAAA,EAAG,YAAA,EAAc,GAAA,EAAI;AAAA,EAC3D,CAAA;AACA,EAAA,OAAO,EAAE,MAAA,EAAO;AAClB","file":"index.cjs","sourcesContent":["// ═══════════════════════════════════════════════════════════\n// THE HEAD — what a screen says it is, as a node in its layout.\n//\n// A document has a part nobody sees on the screen: its title, the sentence\n// that describes it, the picture shown where a link to it is pasted. Those are\n// facts about what the screen shows, so they come from where everything else\n// on the screen comes from — a layout node, its props bound to the action's\n// data — and travel the way everything else does, in the render tree.\n//\n// The node draws nothing. No adapter builds an element for it and no registry\n// has to hold it. Whoever writes the document reads it off the tree (`headOf`)\n// and says it in the surface's own terms: a browser's <head>, a tab's title.\n//\n// The props say what the screen IS, from a closed set of names\n// (./head.schema). How that is spelled in tags is the writer's business, and\n// where the document lives (its address) is not the screen's to say at all — a\n// layout never holds a URL of its own page.\n//\n// This file holds no schema on purpose: a terminal that only reads a head off\n// the wire needs the name and the shape, and nothing to validate with.\n// ═══════════════════════════════════════════════════════════\n\n// Namespaced as a package's own in-layout components are (`loom:field`), so it\n// can never be a name an app's kit already uses for something else.\nexport const HEAD_NAME = 'nova:head';\n\n// What a head node said, once its bindings are resolved and anything it left\n// empty is gone.\nexport type Head = {\n title?: string;\n description?: string;\n image?: string;\n kind?: 'website' | 'article';\n structured?: Record<string, unknown> | Record<string, unknown>[];\n};\n","import { HEAD_NAME } from '../layout/head';\nimport type { Head } from '../layout/head';\nimport type { RenderNode } from '../layout';\nimport type { RenderApi } from './types';\nimport { ACTION_SLOT_NAME, CANVAS_SLOT_NAME } from './slot-names';\n\n// ═══════════════════════════════════════════════════════════\n// The head a screen has, read off its render tree.\n//\n// The frame is walked in the order it is drawn, into each canvas where its\n// slot stands and into each instance on it. A screen can hold more than one\n// head node — a dialog opened over a page — and then THE LAST ONE SPEAKS, whole:\n// two heads are two things, and a title from one beside a description from the\n// other describes neither.\n//\n// A node that says nothing (its bindings are not answered yet) is still the\n// one that speaks: the document keeps what it had rather than borrow from a\n// screen underneath.\n// ═══════════════════════════════════════════════════════════\n\nexport type ScreenHead = {\n head: Head;\n // the action whose instance the node stands in; absent for a node in the\n // frame or in a canvas's own layout\n action?: string;\n};\n\ntype Found = { props: Record<string, unknown>; action: string | undefined };\n\nconst said = (value: unknown): string | undefined => (typeof value === 'string' && value.trim() !== '' ? value : undefined);\n\nconst isObject = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst structuredOf = (value: unknown): Head['structured'] => {\n if (isObject(value)) return value;\n if (Array.isArray(value) && value.length > 0 && value.every(isObject)) return value;\n return undefined;\n};\n\n// A prop that is not one of the names, or holds something other than what its\n// name takes, is left out — the document keeps what it had there.\nconst headFrom = (props: Record<string, unknown>): Head => {\n const [title, description, image] = [said(props['title']), said(props['description']), said(props['image'])];\n const kind = props['kind'] === 'website' || props['kind'] === 'article' ? props['kind'] : undefined;\n const structured = structuredOf(props['structured']);\n return {\n ...(title !== undefined ? { title } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(image !== undefined ? { image } : {}),\n ...(kind !== undefined ? { kind } : {}),\n ...(structured !== undefined ? { structured } : {}),\n };\n};\n\nexport const isHeadNode = (node: RenderNode): boolean => node.type === 'component' && node.name === HEAD_NAME;\n\nexport const headOf = (api: Pick<RenderApi, 'frame' | 'canvasTree'>): ScreenHead | undefined => {\n const found: Found[] = [];\n // a canvas whose own tree names it again would never end\n const open = new Set<string>();\n\n const walk = (nodes: readonly RenderNode[], action: string | undefined): void => {\n for (const node of nodes) {\n if (node.type === 'fragment') {\n walk(node.children, action);\n continue;\n }\n if (node.type !== 'component') continue;\n if (node.name === HEAD_NAME) {\n found.push({ props: node.props, action });\n continue;\n }\n if (node.name === CANVAS_SLOT_NAME) {\n const canvasId = node.props['canvasId'];\n if (typeof canvasId !== 'string' || canvasId === '' || open.has(canvasId)) continue;\n open.add(canvasId);\n walk(api.canvasTree(canvasId), undefined);\n open.delete(canvasId);\n continue;\n }\n const definitionId = node.name === ACTION_SLOT_NAME ? node.props['definitionId'] : undefined;\n walk(node.children, typeof definitionId === 'string' ? definitionId : action);\n }\n };\n\n walk(api.frame(), undefined);\n const last = found[found.length - 1];\n if (last === undefined) return undefined;\n return { head: headFrom(last.props), ...(last.action !== undefined ? { action: last.action } : {}) };\n};\n","import type { ComponentRegistry, RenderNode } from '@layout/types';\nimport { isHeadNode } from '@shell';\nimport type { RenderApi } from '@shell';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/tty — a text adapter, the terminal sibling of\n// nova/dom. It turns a served RenderNode tree into lines of plain text plus a\n// numbered table of INTERACTIVES: every `ref`'d node prints with a `[n]`\n// marker and lands in the table, so a REPL host can map \"click 3\" / \"set 5 x\"\n// onto the same event vocabulary the DOM adapter wires by convention —\n// `ui:click` (payload = the node's `value` prop), `ui:model`, `ui:key`.\n// Origin is never stamped here — moss stamps the active instance server-side.\n//\n// No framework, no I/O, no node builtins: render() is a pure snapshot →\n// { text, interactives }. The host (moss's terminal/tty target) owns stdio,\n// prompts, and dispatch; this adapter only says what the screen IS and what\n// on it can be acted on. `CanvasSlot` is resolved here (the frame's markers →\n// per-canvas trees), the one piece of terminal structure the renderer owns.\n// See packages/nova/ADAPTER.md for the shared adapter contract.\n// ═══════════════════════════════════════════════════════════\n\n// A rendered block: lines of text, composed upward (a Stack stacks child\n// blocks, a Row joins single-line children inline, …).\nexport type TtyBlock = { lines: string[] };\n\n// What an interactive marker can be driven with — the REPL host maps these\n// to events: click/row → ui:click, model → ui:model (a typed value),\n// toggle → ui:model (a negated boolean).\nexport type TtyInteractiveKind = 'click' | 'row' | 'model' | 'toggle';\n\nexport type TtyInteractive = {\n // the printed `[n]` — 1-based, in registration order\n index: number;\n kind: TtyInteractiveKind;\n ref: string;\n // the canvas whose dispatch this belongs to; '' = frame chrome (dispatches\n // nothing, same as the DOM adapter's frame)\n canvas: string;\n // the action instance it sits in (the enclosing ActionSlot's instanceId) —\n // a list canvas renders several live instances at once, so the host stamps\n // this as the event's origin, exactly as the DOM adapter does. Absent\n // outside any instance.\n origin?: string;\n // what was printed — for the host's `refs` listing\n label: string;\n // click/row: the dispatch payload; model/toggle: the current value\n value?: unknown;\n // the model path, when model-bound — display only, the server owns meaning\n path?: string;\n};\n\nexport type TtyComponentContext = {\n props: Record<string, unknown>;\n // the node's children, already rendered — the component stacks or joins\n // them where it wants (leaves ignore them).\n children: TtyBlock[];\n // register an interactive and get its printed index — for data-driven\n // components with INTERNAL interactivity (a table's rows, a panel's ✕);\n // simple components let the renderer mark their `ref`/`model` by convention.\n register: (entry: { kind: TtyInteractiveKind; ref: string; label: string; value?: unknown; path?: string }) => number;\n};\n\n// A TTY component: props + rendered children in, one block of lines out.\nexport type TtyComponent = (ctx: TtyComponentContext) => TtyBlock;\n\n// What the terminal hands the view: core's `RenderApi` — the same single\n// definition the dom/react adapters and moss's terminal share.\nexport type TtyRenderApi = RenderApi;\n\n// One rendered frame: the full screen text and everything actionable on it.\nexport type TtyFrame = { text: string; interactives: TtyInteractive[] };\n\nexport type TtyView = {\n // render the current snapshot; call on every wire change\n render: () => TtyFrame;\n};\n\nconst CANVAS_SLOT = 'CanvasSlot';\nconst ACTION_SLOT = 'ActionSlot';\nconst RULE_WIDTH = 60;\n\n// The recursion context: the registry, the canvas in force (frame chrome is\n// ''; a CanvasSlot switches it), the interactive accumulator, the resolver.\ntype Ctx = {\n registry: ComponentRegistry<TtyComponent>;\n canvas: string;\n // the enclosing action instance, when inside one (an ActionSlot switches it)\n origin?: string;\n api: TtyRenderApi;\n out: TtyInteractive[];\n // used when a component name is unregistered — a permissive renderer (the\n // default kit) supplies one so unknown primitives render their children\n // instead of an error; strict consumers omit it.\n fallback?: TtyComponent;\n};\n\nconst errorBlock = (code: string, message: string): TtyBlock => ({ lines: [`!! ${code}: ${message}`] });\n\nconst labelOf = (block: TtyBlock, ref: string): string => {\n const first = block.lines[0]?.trim() ?? '';\n return first === '' ? ref : first.slice(0, 48);\n};\n\n// A canvas heading: `── main ─────…` — the one piece of chrome the renderer\n// prints itself, so a REPL reader can tell canvases apart.\nconst canvasRule = (id: string): string => {\n const head = `── ${id} `;\n return head + '─'.repeat(Math.max(0, RULE_WIDTH - head.length));\n};\n\nconst renderNode = (node: RenderNode, ctx: Ctx): TtyBlock => {\n if (node.type === 'text') return { lines: node.value.split('\\n') };\n if (node.type === 'fragment') return { lines: node.children.flatMap((child) => renderNode(child, ctx).lines) };\n if (node.type === 'error') return errorBlock(node.code, node.message);\n\n // component\n // a head is something the screen says, not something it shows\n if (isHeadNode(node)) return { lines: [] };\n if (node.name === CANVAS_SLOT) {\n const canvasId = typeof node.props['canvasId'] === 'string' ? (node.props['canvasId'] as string) : '';\n if (canvasId === '') return { lines: [] };\n const tree = ctx.api.canvasTree(canvasId);\n // an empty canvas collapses entirely — no heading for nothing\n if (tree.length === 0) return { lines: [] };\n // a canvas starts outside any instance, even one placed by an instance's layout\n const { origin: _outer, ...outside } = ctx;\n const canvasCtx: Ctx = { ...outside, canvas: canvasId };\n return { lines: [canvasRule(canvasId), ...tree.flatMap((child) => renderNode(child, canvasCtx).lines), ''] };\n }\n\n const entry = ctx.registry.get(node.name);\n const build = entry !== undefined ? entry.component : ctx.fallback;\n if (build === undefined) return errorBlock('COMPONENT_NOT_FOUND', node.name);\n\n // An ActionSlot is an instance boundary: what is inside it belongs to it.\n const instanceId = node.name === ACTION_SLOT ? node.props['instanceId'] : undefined;\n const inner: Ctx = typeof instanceId === 'string' && instanceId !== '' ? { ...ctx, origin: instanceId } : ctx;\n const children = node.children.filter((child) => !isHeadNode(child)).map((child) => renderNode(child, inner));\n const register: TtyComponentContext['register'] = (item) => {\n const interactive: TtyInteractive = { index: ctx.out.length + 1, canvas: ctx.canvas, ...(ctx.origin !== undefined ? { origin: ctx.origin } : {}), ...item };\n ctx.out.push(interactive);\n return interactive.index;\n };\n const block = build({ props: node.props, children, register });\n\n // Convention wiring, the TTY twin of the DOM adapter's listeners: a model'd\n // node is an input (`toggle` when its current value is a boolean), a bare\n // ref'd node is clickable (payload = its `value` prop). The marker lands on\n // the block's first line.\n if (node.model !== undefined) {\n const current = node.props['value'] ?? node.props['checked'];\n const kind: TtyInteractiveKind = typeof current === 'boolean' ? 'toggle' : 'model';\n const index = register({ kind, ref: node.model.ref, label: labelOf(block, node.model.ref), value: current, path: node.model.path });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n if (node.ref !== undefined) {\n const value = node.props['value'];\n const index = register({ kind: 'click', ref: node.ref, label: labelOf(block, node.ref), ...(value !== undefined ? { value } : {}) });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n return block;\n};\n\n// Collapse runs of blank lines so stacked empty canvases don't leave gaps.\nconst tidy = (lines: string[]): string[] => {\n const out: string[] = [];\n for (const line of lines) {\n if (line.trim() === '' && out[out.length - 1]?.trim() === '') continue;\n out.push(line);\n }\n while (out[0]?.trim() === '') out.shift();\n while (out[out.length - 1]?.trim() === '') out.pop();\n return out;\n};\n\nexport const createTtyView = (\n registry: ComponentRegistry<TtyComponent>,\n api: TtyRenderApi,\n options: { fallback?: TtyComponent } = {},\n): TtyView => {\n const render = (): TtyFrame => {\n const out: TtyInteractive[] = [];\n // The frame is chrome — its interactives belong to no canvas and the host\n // dispatches nothing for them, same as the DOM adapter's frame dispatch.\n const ctx: Ctx = { registry, canvas: '', api, out, ...(options.fallback !== undefined ? { fallback: options.fallback } : {}) };\n const lines = api.frame().flatMap((node) => renderNode(node, ctx).lines);\n return { text: tidy(lines).join('\\n'), interactives: out };\n };\n return { render };\n};\n"]}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import '../../chunk-WZVQ5PUB.js';
|
|
2
|
+
import { isHeadNode } from '../../chunk-UV5YGBHQ.js';
|
|
3
|
+
import '../../chunk-RXECI7DE.js';
|
|
4
|
+
import '../../chunk-OGD5CCMZ.js';
|
|
5
|
+
import '../../chunk-7TS3YVQR.js';
|
|
6
|
+
import '../../chunk-X7SSNSQC.js';
|
|
7
|
+
import '../../chunk-DIFE573X.js';
|
|
8
|
+
import '../../chunk-JI7ZRESP.js';
|
|
9
|
+
import '../../chunk-RBU5PHN4.js';
|
|
10
|
+
import '../../chunk-2MNLEL45.js';
|
|
1
11
|
import '../../chunk-PZ5AY32C.js';
|
|
2
12
|
|
|
3
13
|
// src/adapters/tty/index.ts
|
|
@@ -17,6 +27,7 @@ var renderNode = (node, ctx) => {
|
|
|
17
27
|
if (node.type === "text") return { lines: node.value.split("\n") };
|
|
18
28
|
if (node.type === "fragment") return { lines: node.children.flatMap((child) => renderNode(child, ctx).lines) };
|
|
19
29
|
if (node.type === "error") return errorBlock(node.code, node.message);
|
|
30
|
+
if (isHeadNode(node)) return { lines: [] };
|
|
20
31
|
if (node.name === CANVAS_SLOT) {
|
|
21
32
|
const canvasId = typeof node.props["canvasId"] === "string" ? node.props["canvasId"] : "";
|
|
22
33
|
if (canvasId === "") return { lines: [] };
|
|
@@ -31,7 +42,7 @@ var renderNode = (node, ctx) => {
|
|
|
31
42
|
if (build === void 0) return errorBlock("COMPONENT_NOT_FOUND", node.name);
|
|
32
43
|
const instanceId = node.name === ACTION_SLOT ? node.props["instanceId"] : void 0;
|
|
33
44
|
const inner = typeof instanceId === "string" && instanceId !== "" ? { ...ctx, origin: instanceId } : ctx;
|
|
34
|
-
const children = node.children.map((child) => renderNode(child, inner));
|
|
45
|
+
const children = node.children.filter((child) => !isHeadNode(child)).map((child) => renderNode(child, inner));
|
|
35
46
|
const register = (item) => {
|
|
36
47
|
const interactive = { index: ctx.out.length + 1, canvas: ctx.canvas, ...ctx.origin !== void 0 ? { origin: ctx.origin } : {}, ...item };
|
|
37
48
|
ctx.out.push(interactive);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/adapters/tty/index.ts"],"names":[],"mappings":";;;AA4EA,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,UAAA,GAAa,EAAA;AAiBnB,IAAM,UAAA,GAAa,CAAC,IAAA,EAAc,OAAA,MAA+B,EAAE,KAAA,EAAO,CAAC,CAAA,GAAA,EAAM,IAAI,CAAA,EAAA,EAAK,OAA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U,QAAQ,QAAA,EAAS,GAAI,EAAC,EAAG;AAC7H,IAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,EAAM,CAAE,OAAA,CAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,IAAA,EAAM,GAAG,CAAA,CAAE,KAAK,CAAA;AACvE,IAAA,OAAO,EAAE,MAAM,IAAA,CAAK,KAAK,EAAE,IAAA,CAAK,IAAI,CAAA,EAAG,YAAA,EAAc,GAAA,EAAI;AAAA,EAC3D,CAAA;AACA,EAAA,OAAO,EAAE,MAAA,EAAO;AAClB","file":"index.js","sourcesContent":["import type { ComponentRegistry, RenderNode } from '@layout/types';\nimport type { RenderApi } from '@shell';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/tty — a text adapter, the terminal sibling of\n// nova/dom. It turns a served RenderNode tree into lines of plain text plus a\n// numbered table of INTERACTIVES: every `ref`'d node prints with a `[n]`\n// marker and lands in the table, so a REPL host can map \"click 3\" / \"set 5 x\"\n// onto the same event vocabulary the DOM adapter wires by convention —\n// `ui:click` (payload = the node's `value` prop), `ui:model`, `ui:key`.\n// Origin is never stamped here — moss stamps the active instance server-side.\n//\n// No framework, no I/O, no node builtins: render() is a pure snapshot →\n// { text, interactives }. The host (moss's terminal/tty target) owns stdio,\n// prompts, and dispatch; this adapter only says what the screen IS and what\n// on it can be acted on. `CanvasSlot` is resolved here (the frame's markers →\n// per-canvas trees), the one piece of terminal structure the renderer owns.\n// See packages/nova/ADAPTER.md for the shared adapter contract.\n// ═══════════════════════════════════════════════════════════\n\n// A rendered block: lines of text, composed upward (a Stack stacks child\n// blocks, a Row joins single-line children inline, …).\nexport type TtyBlock = { lines: string[] };\n\n// What an interactive marker can be driven with — the REPL host maps these\n// to events: click/row → ui:click, model → ui:model (a typed value),\n// toggle → ui:model (a negated boolean).\nexport type TtyInteractiveKind = 'click' | 'row' | 'model' | 'toggle';\n\nexport type TtyInteractive = {\n // the printed `[n]` — 1-based, in registration order\n index: number;\n kind: TtyInteractiveKind;\n ref: string;\n // the canvas whose dispatch this belongs to; '' = frame chrome (dispatches\n // nothing, same as the DOM adapter's frame)\n canvas: string;\n // the action instance it sits in (the enclosing ActionSlot's instanceId) —\n // a list canvas renders several live instances at once, so the host stamps\n // this as the event's origin, exactly as the DOM adapter does. Absent\n // outside any instance.\n origin?: string;\n // what was printed — for the host's `refs` listing\n label: string;\n // click/row: the dispatch payload; model/toggle: the current value\n value?: unknown;\n // the model path, when model-bound — display only, the server owns meaning\n path?: string;\n};\n\nexport type TtyComponentContext = {\n props: Record<string, unknown>;\n // the node's children, already rendered — the component stacks or joins\n // them where it wants (leaves ignore them).\n children: TtyBlock[];\n // register an interactive and get its printed index — for data-driven\n // components with INTERNAL interactivity (a table's rows, a panel's ✕);\n // simple components let the renderer mark their `ref`/`model` by convention.\n register: (entry: { kind: TtyInteractiveKind; ref: string; label: string; value?: unknown; path?: string }) => number;\n};\n\n// A TTY component: props + rendered children in, one block of lines out.\nexport type TtyComponent = (ctx: TtyComponentContext) => TtyBlock;\n\n// What the terminal hands the view: core's `RenderApi` — the same single\n// definition the dom/react adapters and moss's terminal share.\nexport type TtyRenderApi = RenderApi;\n\n// One rendered frame: the full screen text and everything actionable on it.\nexport type TtyFrame = { text: string; interactives: TtyInteractive[] };\n\nexport type TtyView = {\n // render the current snapshot; call on every wire change\n render: () => TtyFrame;\n};\n\nconst CANVAS_SLOT = 'CanvasSlot';\nconst ACTION_SLOT = 'ActionSlot';\nconst RULE_WIDTH = 60;\n\n// The recursion context: the registry, the canvas in force (frame chrome is\n// ''; a CanvasSlot switches it), the interactive accumulator, the resolver.\ntype Ctx = {\n registry: ComponentRegistry<TtyComponent>;\n canvas: string;\n // the enclosing action instance, when inside one (an ActionSlot switches it)\n origin?: string;\n api: TtyRenderApi;\n out: TtyInteractive[];\n // used when a component name is unregistered — a permissive renderer (the\n // default kit) supplies one so unknown primitives render their children\n // instead of an error; strict consumers omit it.\n fallback?: TtyComponent;\n};\n\nconst errorBlock = (code: string, message: string): TtyBlock => ({ lines: [`!! ${code}: ${message}`] });\n\nconst labelOf = (block: TtyBlock, ref: string): string => {\n const first = block.lines[0]?.trim() ?? '';\n return first === '' ? ref : first.slice(0, 48);\n};\n\n// A canvas heading: `── main ─────…` — the one piece of chrome the renderer\n// prints itself, so a REPL reader can tell canvases apart.\nconst canvasRule = (id: string): string => {\n const head = `── ${id} `;\n return head + '─'.repeat(Math.max(0, RULE_WIDTH - head.length));\n};\n\nconst renderNode = (node: RenderNode, ctx: Ctx): TtyBlock => {\n if (node.type === 'text') return { lines: node.value.split('\\n') };\n if (node.type === 'fragment') return { lines: node.children.flatMap((child) => renderNode(child, ctx).lines) };\n if (node.type === 'error') return errorBlock(node.code, node.message);\n\n // component\n if (node.name === CANVAS_SLOT) {\n const canvasId = typeof node.props['canvasId'] === 'string' ? (node.props['canvasId'] as string) : '';\n if (canvasId === '') return { lines: [] };\n const tree = ctx.api.canvasTree(canvasId);\n // an empty canvas collapses entirely — no heading for nothing\n if (tree.length === 0) return { lines: [] };\n // a canvas starts outside any instance, even one placed by an instance's layout\n const { origin: _outer, ...outside } = ctx;\n const canvasCtx: Ctx = { ...outside, canvas: canvasId };\n return { lines: [canvasRule(canvasId), ...tree.flatMap((child) => renderNode(child, canvasCtx).lines), ''] };\n }\n\n const entry = ctx.registry.get(node.name);\n const build = entry !== undefined ? entry.component : ctx.fallback;\n if (build === undefined) return errorBlock('COMPONENT_NOT_FOUND', node.name);\n\n // An ActionSlot is an instance boundary: what is inside it belongs to it.\n const instanceId = node.name === ACTION_SLOT ? node.props['instanceId'] : undefined;\n const inner: Ctx = typeof instanceId === 'string' && instanceId !== '' ? { ...ctx, origin: instanceId } : ctx;\n const children = node.children.map((child) => renderNode(child, inner));\n const register: TtyComponentContext['register'] = (item) => {\n const interactive: TtyInteractive = { index: ctx.out.length + 1, canvas: ctx.canvas, ...(ctx.origin !== undefined ? { origin: ctx.origin } : {}), ...item };\n ctx.out.push(interactive);\n return interactive.index;\n };\n const block = build({ props: node.props, children, register });\n\n // Convention wiring, the TTY twin of the DOM adapter's listeners: a model'd\n // node is an input (`toggle` when its current value is a boolean), a bare\n // ref'd node is clickable (payload = its `value` prop). The marker lands on\n // the block's first line.\n if (node.model !== undefined) {\n const current = node.props['value'] ?? node.props['checked'];\n const kind: TtyInteractiveKind = typeof current === 'boolean' ? 'toggle' : 'model';\n const index = register({ kind, ref: node.model.ref, label: labelOf(block, node.model.ref), value: current, path: node.model.path });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n if (node.ref !== undefined) {\n const value = node.props['value'];\n const index = register({ kind: 'click', ref: node.ref, label: labelOf(block, node.ref), ...(value !== undefined ? { value } : {}) });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n return block;\n};\n\n// Collapse runs of blank lines so stacked empty canvases don't leave gaps.\nconst tidy = (lines: string[]): string[] => {\n const out: string[] = [];\n for (const line of lines) {\n if (line.trim() === '' && out[out.length - 1]?.trim() === '') continue;\n out.push(line);\n }\n while (out[0]?.trim() === '') out.shift();\n while (out[out.length - 1]?.trim() === '') out.pop();\n return out;\n};\n\nexport const createTtyView = (\n registry: ComponentRegistry<TtyComponent>,\n api: TtyRenderApi,\n options: { fallback?: TtyComponent } = {},\n): TtyView => {\n const render = (): TtyFrame => {\n const out: TtyInteractive[] = [];\n // The frame is chrome — its interactives belong to no canvas and the host\n // dispatches nothing for them, same as the DOM adapter's frame dispatch.\n const ctx: Ctx = { registry, canvas: '', api, out, ...(options.fallback !== undefined ? { fallback: options.fallback } : {}) };\n const lines = api.frame().flatMap((node) => renderNode(node, ctx).lines);\n return { text: tidy(lines).join('\\n'), interactives: out };\n };\n return { render };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/tty/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AA6EA,IAAM,WAAA,GAAc,YAAA;AACpB,IAAM,WAAA,GAAc,YAAA;AACp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A;AAEO,IAAM,gBAAgB,CAC3B,QAAA,EACA,GAAA,EACA,OAAA,GAAuC,EAAC,KAC5B;AACZ,EAAA,MAAM,SAAS,MAAgB;AAC7B,IAAA,MAAM,MAAwB,EAAC;AAG/B,IAAA,MAAM,MAAW,EAAE,QAAA,EAAU,MAAA,EAAQ,EAAA,EAAI,KAAK,GAAA,EAAK,GAAI,OAAA,CAAQ,QAAA,KAAa,SAAY,EAAE,QAAA,EAAU,QAAQ,QAAA,EAAS,GAAI,EAAC,EAAG;AAC7H,IAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,EAAM,CAAE,OAAA,CAAQ,CAAC,IAAA,KAAS,UAAA,CAAW,IAAA,EAAM,GAAG,CAAA,CAAE,KAAK,CAAA;AACvE,IAAA,OAAO,EAAE,MAAM,IAAA,CAAK,KAAK,EAAE,IAAA,CAAK,IAAI,CAAA,EAAG,YAAA,EAAc,GAAA,EAAI;AAAA,EAC3D,CAAA;AACA,EAAA,OAAO,EAAE,MAAA,EAAO;AAClB","file":"index.js","sourcesContent":["import type { ComponentRegistry, RenderNode } from '@layout/types';\nimport { isHeadNode } from '@shell';\nimport type { RenderApi } from '@shell';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/nova/adapters/tty — a text adapter, the terminal sibling of\n// nova/dom. It turns a served RenderNode tree into lines of plain text plus a\n// numbered table of INTERACTIVES: every `ref`'d node prints with a `[n]`\n// marker and lands in the table, so a REPL host can map \"click 3\" / \"set 5 x\"\n// onto the same event vocabulary the DOM adapter wires by convention —\n// `ui:click` (payload = the node's `value` prop), `ui:model`, `ui:key`.\n// Origin is never stamped here — moss stamps the active instance server-side.\n//\n// No framework, no I/O, no node builtins: render() is a pure snapshot →\n// { text, interactives }. The host (moss's terminal/tty target) owns stdio,\n// prompts, and dispatch; this adapter only says what the screen IS and what\n// on it can be acted on. `CanvasSlot` is resolved here (the frame's markers →\n// per-canvas trees), the one piece of terminal structure the renderer owns.\n// See packages/nova/ADAPTER.md for the shared adapter contract.\n// ═══════════════════════════════════════════════════════════\n\n// A rendered block: lines of text, composed upward (a Stack stacks child\n// blocks, a Row joins single-line children inline, …).\nexport type TtyBlock = { lines: string[] };\n\n// What an interactive marker can be driven with — the REPL host maps these\n// to events: click/row → ui:click, model → ui:model (a typed value),\n// toggle → ui:model (a negated boolean).\nexport type TtyInteractiveKind = 'click' | 'row' | 'model' | 'toggle';\n\nexport type TtyInteractive = {\n // the printed `[n]` — 1-based, in registration order\n index: number;\n kind: TtyInteractiveKind;\n ref: string;\n // the canvas whose dispatch this belongs to; '' = frame chrome (dispatches\n // nothing, same as the DOM adapter's frame)\n canvas: string;\n // the action instance it sits in (the enclosing ActionSlot's instanceId) —\n // a list canvas renders several live instances at once, so the host stamps\n // this as the event's origin, exactly as the DOM adapter does. Absent\n // outside any instance.\n origin?: string;\n // what was printed — for the host's `refs` listing\n label: string;\n // click/row: the dispatch payload; model/toggle: the current value\n value?: unknown;\n // the model path, when model-bound — display only, the server owns meaning\n path?: string;\n};\n\nexport type TtyComponentContext = {\n props: Record<string, unknown>;\n // the node's children, already rendered — the component stacks or joins\n // them where it wants (leaves ignore them).\n children: TtyBlock[];\n // register an interactive and get its printed index — for data-driven\n // components with INTERNAL interactivity (a table's rows, a panel's ✕);\n // simple components let the renderer mark their `ref`/`model` by convention.\n register: (entry: { kind: TtyInteractiveKind; ref: string; label: string; value?: unknown; path?: string }) => number;\n};\n\n// A TTY component: props + rendered children in, one block of lines out.\nexport type TtyComponent = (ctx: TtyComponentContext) => TtyBlock;\n\n// What the terminal hands the view: core's `RenderApi` — the same single\n// definition the dom/react adapters and moss's terminal share.\nexport type TtyRenderApi = RenderApi;\n\n// One rendered frame: the full screen text and everything actionable on it.\nexport type TtyFrame = { text: string; interactives: TtyInteractive[] };\n\nexport type TtyView = {\n // render the current snapshot; call on every wire change\n render: () => TtyFrame;\n};\n\nconst CANVAS_SLOT = 'CanvasSlot';\nconst ACTION_SLOT = 'ActionSlot';\nconst RULE_WIDTH = 60;\n\n// The recursion context: the registry, the canvas in force (frame chrome is\n// ''; a CanvasSlot switches it), the interactive accumulator, the resolver.\ntype Ctx = {\n registry: ComponentRegistry<TtyComponent>;\n canvas: string;\n // the enclosing action instance, when inside one (an ActionSlot switches it)\n origin?: string;\n api: TtyRenderApi;\n out: TtyInteractive[];\n // used when a component name is unregistered — a permissive renderer (the\n // default kit) supplies one so unknown primitives render their children\n // instead of an error; strict consumers omit it.\n fallback?: TtyComponent;\n};\n\nconst errorBlock = (code: string, message: string): TtyBlock => ({ lines: [`!! ${code}: ${message}`] });\n\nconst labelOf = (block: TtyBlock, ref: string): string => {\n const first = block.lines[0]?.trim() ?? '';\n return first === '' ? ref : first.slice(0, 48);\n};\n\n// A canvas heading: `── main ─────…` — the one piece of chrome the renderer\n// prints itself, so a REPL reader can tell canvases apart.\nconst canvasRule = (id: string): string => {\n const head = `── ${id} `;\n return head + '─'.repeat(Math.max(0, RULE_WIDTH - head.length));\n};\n\nconst renderNode = (node: RenderNode, ctx: Ctx): TtyBlock => {\n if (node.type === 'text') return { lines: node.value.split('\\n') };\n if (node.type === 'fragment') return { lines: node.children.flatMap((child) => renderNode(child, ctx).lines) };\n if (node.type === 'error') return errorBlock(node.code, node.message);\n\n // component\n // a head is something the screen says, not something it shows\n if (isHeadNode(node)) return { lines: [] };\n if (node.name === CANVAS_SLOT) {\n const canvasId = typeof node.props['canvasId'] === 'string' ? (node.props['canvasId'] as string) : '';\n if (canvasId === '') return { lines: [] };\n const tree = ctx.api.canvasTree(canvasId);\n // an empty canvas collapses entirely — no heading for nothing\n if (tree.length === 0) return { lines: [] };\n // a canvas starts outside any instance, even one placed by an instance's layout\n const { origin: _outer, ...outside } = ctx;\n const canvasCtx: Ctx = { ...outside, canvas: canvasId };\n return { lines: [canvasRule(canvasId), ...tree.flatMap((child) => renderNode(child, canvasCtx).lines), ''] };\n }\n\n const entry = ctx.registry.get(node.name);\n const build = entry !== undefined ? entry.component : ctx.fallback;\n if (build === undefined) return errorBlock('COMPONENT_NOT_FOUND', node.name);\n\n // An ActionSlot is an instance boundary: what is inside it belongs to it.\n const instanceId = node.name === ACTION_SLOT ? node.props['instanceId'] : undefined;\n const inner: Ctx = typeof instanceId === 'string' && instanceId !== '' ? { ...ctx, origin: instanceId } : ctx;\n const children = node.children.filter((child) => !isHeadNode(child)).map((child) => renderNode(child, inner));\n const register: TtyComponentContext['register'] = (item) => {\n const interactive: TtyInteractive = { index: ctx.out.length + 1, canvas: ctx.canvas, ...(ctx.origin !== undefined ? { origin: ctx.origin } : {}), ...item };\n ctx.out.push(interactive);\n return interactive.index;\n };\n const block = build({ props: node.props, children, register });\n\n // Convention wiring, the TTY twin of the DOM adapter's listeners: a model'd\n // node is an input (`toggle` when its current value is a boolean), a bare\n // ref'd node is clickable (payload = its `value` prop). The marker lands on\n // the block's first line.\n if (node.model !== undefined) {\n const current = node.props['value'] ?? node.props['checked'];\n const kind: TtyInteractiveKind = typeof current === 'boolean' ? 'toggle' : 'model';\n const index = register({ kind, ref: node.model.ref, label: labelOf(block, node.model.ref), value: current, path: node.model.path });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n if (node.ref !== undefined) {\n const value = node.props['value'];\n const index = register({ kind: 'click', ref: node.ref, label: labelOf(block, node.ref), ...(value !== undefined ? { value } : {}) });\n return { lines: [`[${index}] ${block.lines[0] ?? ''}`, ...block.lines.slice(1)] };\n }\n return block;\n};\n\n// Collapse runs of blank lines so stacked empty canvases don't leave gaps.\nconst tidy = (lines: string[]): string[] => {\n const out: string[] = [];\n for (const line of lines) {\n if (line.trim() === '' && out[out.length - 1]?.trim() === '') continue;\n out.push(line);\n }\n while (out[0]?.trim() === '') out.shift();\n while (out[out.length - 1]?.trim() === '') out.pop();\n return out;\n};\n\nexport const createTtyView = (\n registry: ComponentRegistry<TtyComponent>,\n api: TtyRenderApi,\n options: { fallback?: TtyComponent } = {},\n): TtyView => {\n const render = (): TtyFrame => {\n const out: TtyInteractive[] = [];\n // The frame is chrome — its interactives belong to no canvas and the host\n // dispatches nothing for them, same as the DOM adapter's frame dispatch.\n const ctx: Ctx = { registry, canvas: '', api, out, ...(options.fallback !== undefined ? { fallback: options.fallback } : {}) };\n const lines = api.frame().flatMap((node) => renderNode(node, ctx).lines);\n return { text: tidy(lines).join('\\n'), interactives: out };\n };\n return { render };\n};\n"]}
|
|
@@ -456,6 +456,9 @@ var useRenderTree = (instanceId) => {
|
|
|
456
456
|
});
|
|
457
457
|
};
|
|
458
458
|
|
|
459
|
+
// src/layout/head.ts
|
|
460
|
+
var HEAD_NAME = "nova:head";
|
|
461
|
+
|
|
459
462
|
// src/layout/adapter.ts
|
|
460
463
|
var NOVA_MODEL_PROP = "novaModel";
|
|
461
464
|
var NOVA_REF_PROP = "novaRef";
|
|
@@ -469,10 +472,32 @@ var renderNodeKey = (node, index) => {
|
|
|
469
472
|
if (node.type === "fragment") return `f:${index}`;
|
|
470
473
|
return `e:${node.code}:${index}`;
|
|
471
474
|
};
|
|
475
|
+
|
|
476
|
+
// src/shell/head.ts
|
|
477
|
+
var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
|
|
472
478
|
var ErrorMarker = vue.defineComponent(
|
|
473
479
|
(props) => () => vue.h("span", { "data-nova-error": props.code, role: "alert" }, `[${props.code}] ${props.message}`),
|
|
474
480
|
{ name: "NovaErrorMarker", props: ["code", "message"] }
|
|
475
481
|
);
|
|
482
|
+
var ShellTitleKey = /* @__PURE__ */ Symbol.for("@niscorp/nova/adapters/vue:title");
|
|
483
|
+
var HeadMark = vue.defineComponent(
|
|
484
|
+
() => {
|
|
485
|
+
const title = vue.inject(ShellTitleKey, void 0);
|
|
486
|
+
vue.onMounted(() => {
|
|
487
|
+
if (title === void 0) return;
|
|
488
|
+
vue.watch(
|
|
489
|
+
title,
|
|
490
|
+
(current, _previous, onCleanup) => {
|
|
491
|
+
current.enter();
|
|
492
|
+
onCleanup(current.leave);
|
|
493
|
+
},
|
|
494
|
+
{ immediate: true }
|
|
495
|
+
);
|
|
496
|
+
});
|
|
497
|
+
return () => null;
|
|
498
|
+
},
|
|
499
|
+
{ name: "NovaHeadMark" }
|
|
500
|
+
);
|
|
476
501
|
|
|
477
502
|
// src/adapters/vue/types.ts
|
|
478
503
|
var isNovaComponent = (value) => typeof value === "function" || typeof value === "object" && value !== null;
|
|
@@ -483,6 +508,7 @@ var renderNode = (ctx, node) => {
|
|
|
483
508
|
if (node.type === "text") return vue.createTextVNode(node.value);
|
|
484
509
|
if (node.type === "fragment") return vue.h(RenderTree, { nodes: node.children });
|
|
485
510
|
if (node.type === "error") return vue.h(ErrorMarker, { code: node.code, message: node.message });
|
|
511
|
+
if (isHeadNode(node)) return vue.h(HeadMark);
|
|
486
512
|
const registered = ctx.registry.get(node.name)?.component;
|
|
487
513
|
const component = isNovaComponent(registered) ? registered : ctx.fallback;
|
|
488
514
|
if (component === void 0) return vue.h(ErrorMarker, { code: "COMPONENT_NOT_FOUND", message: node.name });
|
|
@@ -491,7 +517,12 @@ var renderNode = (ctx, node) => {
|
|
|
491
517
|
if (node.ref !== void 0) props[NOVA_REF_PROP] = node.ref;
|
|
492
518
|
const { children } = node;
|
|
493
519
|
if (children.length === 0) return vue.h(component, props);
|
|
494
|
-
return vue.h(component, props, { default: () => childViews(children) });
|
|
520
|
+
if (!children.some(isHeadNode)) return vue.h(component, props, { default: () => childViews(children) });
|
|
521
|
+
const shown = children.filter((child) => !isHeadNode(child));
|
|
522
|
+
return vue.h(vue.Fragment, [
|
|
523
|
+
shown.length === 0 ? vue.h(component, props) : vue.h(component, props, { default: () => childViews(shown) }),
|
|
524
|
+
...children.filter(isHeadNode).map((_head, i) => vue.h(HeadMark, { key: `head:${i}` }))
|
|
525
|
+
]);
|
|
495
526
|
};
|
|
496
527
|
var RenderNodeView = vue.defineComponent(
|
|
497
528
|
(props) => {
|