@niscorp/moss 0.1.0
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/DESIGN.md +592 -0
- package/DOCS.md +943 -0
- package/LICENSE +202 -0
- package/README.md +155 -0
- package/dist/chunk-2AHJ6VDR.js +3314 -0
- package/dist/chunk-2AHJ6VDR.js.map +1 -0
- package/dist/chunk-EMRDIZLY.js +99 -0
- package/dist/chunk-EMRDIZLY.js.map +1 -0
- package/dist/chunk-HF6IGQ74.js +3342 -0
- package/dist/chunk-HF6IGQ74.js.map +1 -0
- package/dist/chunk-J72N3EMJ.js +238 -0
- package/dist/chunk-J72N3EMJ.js.map +1 -0
- package/dist/chunk-SK4PDGEE.js +55 -0
- package/dist/chunk-SK4PDGEE.js.map +1 -0
- package/dist/chunk-ZOEUEMDX.js +251 -0
- package/dist/chunk-ZOEUEMDX.js.map +1 -0
- package/dist/client/node.cjs +42 -0
- package/dist/client/node.cjs.map +1 -0
- package/dist/client/node.d.cts +9 -0
- package/dist/client/node.d.ts +9 -0
- package/dist/client/node.js +40 -0
- package/dist/client/node.js.map +1 -0
- package/dist/client.cjs +275 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +52 -0
- package/dist/client.d.ts +52 -0
- package/dist/client.js +4 -0
- package/dist/client.js.map +1 -0
- package/dist/document-BEn2zXah.d.cts +993 -0
- package/dist/document-BEn2zXah.d.ts +993 -0
- package/dist/index.cjs +3716 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/node.cjs +3309 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +28 -0
- package/dist/node.d.ts +28 -0
- package/dist/node.js +64 -0
- package/dist/node.js.map +1 -0
- package/dist/slots-Do9ScG7v.d.cts +37 -0
- package/dist/slots-Do9ScG7v.d.ts +37 -0
- package/dist/terminal/dom/index.cjs +34 -0
- package/dist/terminal/dom/index.cjs.map +1 -0
- package/dist/terminal/dom/index.d.cts +11 -0
- package/dist/terminal/dom/index.d.ts +11 -0
- package/dist/terminal/dom/index.js +32 -0
- package/dist/terminal/dom/index.js.map +1 -0
- package/dist/terminal/dom/server.cjs +16 -0
- package/dist/terminal/dom/server.cjs.map +1 -0
- package/dist/terminal/dom/server.d.cts +14 -0
- package/dist/terminal/dom/server.d.ts +14 -0
- package/dist/terminal/dom/server.js +14 -0
- package/dist/terminal/dom/server.js.map +1 -0
- package/dist/terminal/index.cjs +346 -0
- package/dist/terminal/index.cjs.map +1 -0
- package/dist/terminal/index.d.cts +32 -0
- package/dist/terminal/index.d.ts +32 -0
- package/dist/terminal/index.js +100 -0
- package/dist/terminal/index.js.map +1 -0
- package/dist/terminal/ink/index.d.ts +33 -0
- package/dist/terminal/ink/index.js +189 -0
- package/dist/terminal/ink/index.js.map +1 -0
- package/dist/terminal/react/index.cjs +87 -0
- package/dist/terminal/react/index.cjs.map +1 -0
- package/dist/terminal/react/index.d.cts +15 -0
- package/dist/terminal/react/index.d.ts +15 -0
- package/dist/terminal/react/index.js +35 -0
- package/dist/terminal/react/index.js.map +1 -0
- package/dist/terminal/react/server.cjs +79 -0
- package/dist/terminal/react/server.cjs.map +1 -0
- package/dist/terminal/react/server.d.cts +16 -0
- package/dist/terminal/react/server.d.ts +16 -0
- package/dist/terminal/react/server.js +28 -0
- package/dist/terminal/react/server.js.map +1 -0
- package/dist/terminal/tty/index.cjs +201 -0
- package/dist/terminal/tty/index.cjs.map +1 -0
- package/dist/terminal/tty/index.d.cts +18 -0
- package/dist/terminal/tty/index.d.ts +18 -0
- package/dist/terminal/tty/index.js +199 -0
- package/dist/terminal/tty/index.js.map +1 -0
- package/dist/terminal/vue/index.cjs +104 -0
- package/dist/terminal/vue/index.cjs.map +1 -0
- package/dist/terminal/vue/index.d.cts +23 -0
- package/dist/terminal/vue/index.d.ts +23 -0
- package/dist/terminal/vue/index.js +3 -0
- package/dist/terminal/vue/index.js.map +1 -0
- package/dist/terminal/vue/server.cjs +88 -0
- package/dist/terminal/vue/server.cjs.map +1 -0
- package/dist/terminal/vue/server.d.cts +18 -0
- package/dist/terminal/vue/server.d.ts +18 -0
- package/dist/terminal/vue/server.js +21 -0
- package/dist/terminal/vue/server.js.map +1 -0
- package/package.json +213 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var server = require('react-dom/server');
|
|
5
|
+
var react$1 = require('@niscorp/nova/adapters/react');
|
|
6
|
+
|
|
7
|
+
// src/terminal/react/server.ts
|
|
8
|
+
var TerminalApiContext = react.createContext(void 0);
|
|
9
|
+
var registerWireSlots = (registry, options = {}) => {
|
|
10
|
+
const { slotWrapper, fallback, textWrapper, errorMarker, canvasProvider, instanceProvider } = options;
|
|
11
|
+
const CanvasSlot = ({ canvasId }) => {
|
|
12
|
+
const api = react.useContext(TerminalApiContext);
|
|
13
|
+
if (api === void 0 || canvasId === void 0 || canvasId === "") return null;
|
|
14
|
+
const tree = api.canvasTree(canvasId);
|
|
15
|
+
if (tree.length === 0) return null;
|
|
16
|
+
const body = react.createElement(react$1.RenderTree, { nodes: tree });
|
|
17
|
+
return react.createElement(
|
|
18
|
+
react$1.NovaRenderProvider,
|
|
19
|
+
{
|
|
20
|
+
registry,
|
|
21
|
+
dispatch: (event) => api.dispatch(canvasId, event),
|
|
22
|
+
publish: (channel, payload) => api.publish(channel, payload),
|
|
23
|
+
fallback,
|
|
24
|
+
textWrapper,
|
|
25
|
+
errorMarker
|
|
26
|
+
},
|
|
27
|
+
canvasProvider === void 0 ? body : react.createElement(canvasProvider, { canvasId }, body)
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
registry.register("CanvasSlot", CanvasSlot, { description: "A canvas, live from the server." });
|
|
31
|
+
const ActionSlot = ({
|
|
32
|
+
instanceId,
|
|
33
|
+
canvasId,
|
|
34
|
+
definitionId,
|
|
35
|
+
children
|
|
36
|
+
}) => {
|
|
37
|
+
const api = react.useContext(TerminalApiContext);
|
|
38
|
+
const wrapped = slotWrapper === void 0 ? react.createElement(react.Fragment, { key: instanceId }, children) : react.createElement(slotWrapper, { key: instanceId, instanceId, canvasId, definitionId }, children);
|
|
39
|
+
if (api === void 0 || instanceId === void 0 || canvasId === void 0) return wrapped;
|
|
40
|
+
return react.createElement(
|
|
41
|
+
react$1.NovaRenderProvider,
|
|
42
|
+
{
|
|
43
|
+
registry,
|
|
44
|
+
dispatch: (event) => api.dispatch(canvasId, event.origin === void 0 ? { ...event, origin: instanceId } : event),
|
|
45
|
+
publish: (channel, payload) => api.publish(channel, payload),
|
|
46
|
+
fallback,
|
|
47
|
+
textWrapper,
|
|
48
|
+
errorMarker
|
|
49
|
+
},
|
|
50
|
+
instanceProvider === void 0 ? wrapped : react.createElement(instanceProvider, { canvasId, instanceId }, wrapped)
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
registry.register("ActionSlot", ActionSlot, { description: "An action instance boundary from the server; the app slotWrapper wraps it." });
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/terminal/react/server.ts
|
|
57
|
+
var nothing = () => void 0;
|
|
58
|
+
var renderSnapshot = (config) => {
|
|
59
|
+
const { snapshot, registry, slotWrapper } = config;
|
|
60
|
+
registerWireSlots(registry, { slotWrapper });
|
|
61
|
+
const api = {
|
|
62
|
+
frame: () => snapshot.frame,
|
|
63
|
+
canvasTree: (id) => snapshot.trees[id] ?? [],
|
|
64
|
+
// a string has nobody to press it
|
|
65
|
+
dispatch: nothing,
|
|
66
|
+
publish: nothing
|
|
67
|
+
};
|
|
68
|
+
return server.renderToString(
|
|
69
|
+
react.createElement(
|
|
70
|
+
TerminalApiContext.Provider,
|
|
71
|
+
{ value: api },
|
|
72
|
+
react.createElement(react$1.NovaRenderProvider, { registry, dispatch: nothing, publish: nothing }, react.createElement(react$1.RenderTree, { nodes: api.frame() }))
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.renderSnapshot = renderSnapshot;
|
|
78
|
+
//# sourceMappingURL=server.cjs.map
|
|
79
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terminal/react/slots.ts","../../../src/terminal/react/server.ts"],"names":["createContext","useContext","createElement","RenderTree","NovaRenderProvider","Fragment","renderToString"],"mappings":";;;;;;;AAaO,IAAM,kBAAA,GAAqBA,oBAAuC,MAAS,CAAA;AAwC3E,IAAM,iBAAA,GAAoB,CAAC,QAAA,EAA4C,OAAA,GAA2B,EAAC,KAAY;AACpH,EAAA,MAAM,EAAE,WAAA,EAAa,QAAA,EAAU,aAAa,WAAA,EAAa,cAAA,EAAgB,kBAAiB,GAAI,OAAA;AAE9F,EAAA,MAAM,UAAA,GAAmD,CAAC,EAAE,QAAA,EAAS,KAA6B;AAChG,IAAA,MAAM,GAAA,GAAMC,iBAAW,kBAAkB,CAAA;AACzC,IAAA,IAAI,QAAQ,MAAA,IAAa,QAAA,KAAa,MAAA,IAAa,QAAA,KAAa,IAAI,OAAO,IAAA;AAC3E,IAAA,MAAM,IAAA,GAAO,GAAA,CAAI,UAAA,CAAW,QAAQ,CAAA;AACpC,IAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,OAAO,IAAA;AAC9B,IAAA,MAAM,OAAOC,mBAAA,CAAcC,kBAAA,EAAY,EAAE,KAAA,EAAO,MAAM,CAAA;AACtD,IAAA,OAAOD,mBAAA;AAAA,MACLE,0BAAA;AAAA,MACA;AAAA,QACE,QAAA;AAAA,QACA,UAAU,CAAC,KAAA,KAAqB,GAAA,CAAI,QAAA,CAAS,UAAU,KAAK,CAAA;AAAA,QAC5D,SAAS,CAAC,OAAA,EAAiB,YAAsB,GAAA,CAAI,OAAA,CAAQ,SAAS,OAAO,CAAA;AAAA,QAC7E,QAAA;AAAA,QACA,WAAA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AACA,EAAA,QAAA,CAAS,SAAS,YAAA,EAAc,UAAA,EAAY,EAAE,WAAA,EAAa,8EAA8E,CAAA;AAC3I,CAAA;;;AChFA,IAAM,UAAU,MAAY,MAAA;AAErB,IAAM,cAAA,GAAiB,CAAC,MAAA,KAAyC;AACtE,EAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAU,WAAA,EAAY,GAAI,MAAA;AAC5C,EAAA,iBAAA,CAAkB,QAAA,EAAU,EAAE,WAAA,EAAa,CAAA;AAC3C,EAAA,MAAM,GAAA,GAAM;AAAA,IACV,KAAA,EAAO,MAAM,QAAA,CAAS,KAAA;AAAA,IACtB,YAAY,CAAC,EAAA,KAAe,SAAS,KAAA,CAAM,EAAE,KAAK,EAAC;AAAA;AAAA,IAEnD,QAAA,EAAU,OAAA;AAAA,IACV,OAAA,EAAS;AAAA,GACX;AACA,EAAA,OAAOI,qBAAA;AAAA,IACLJ,mBAAAA;AAAA,MACE,kBAAA,CAAmB,QAAA;AAAA,MACnB,EAAE,OAAO,GAAA,EAAI;AAAA,MACbA,oBAAcE,0BAAAA,EAAoB,EAAE,QAAA,EAAU,QAAA,EAAU,SAAS,OAAA,EAAS,OAAA,EAAQ,EAAGF,mBAAAA,CAAcC,oBAAY,EAAE,KAAA,EAAO,IAAI,KAAA,EAAM,EAAG,CAAC;AAAA;AACxI,GACF;AACF","file":"server.cjs","sourcesContent":["import { createContext, createElement, Fragment, useContext, type ComponentType, type FC, type ReactNode } from 'react';\nimport { NovaRenderProvider, RenderTree } from '@niscorp/nova/adapters/react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport type { ComponentRegistry, NovaEvent } from '@niscorp/nova';\nimport type { TerminalApi } from '../index';\n\n// ═══════════════════════════════════════════════════════════\n// The wire-backed structural slots, shared by every react-shaped render\n// target (terminal/react in the browser, terminal/ink in a TTY) — same seam,\n// different renderer. Split from the react target so the ink bundle never\n// drags react-dom.\n// ═══════════════════════════════════════════════════════════\n\nexport const TerminalApiContext = createContext<TerminalApi | undefined>(undefined);\n\n// An app-supplied component wrapping each action instance at the ActionSlot\n// boundary — the terminal twin of nova's client-shell SlotWrapper (same seam,\n// same job: animation, gating, logging, chips). Served trees carry IDENTITY\n// only (ids, not the definition — wire weight), so the props diverge from the\n// client-shell wrapper in exactly that one way: `definitionId`, not `action`.\nexport type TerminalSlotWrapperProps = {\n canvasId?: string;\n instanceId?: string;\n definitionId?: string;\n children?: ReactNode;\n};\nexport type TerminalSlotWrapper = FC<TerminalSlotWrapperProps>;\n\n// The host-specific leaf renderers a react-shaped target may thread through\n// to nova's provider (ink needs all three; the browser needs none).\nexport type WireSlotOptions = {\n slotWrapper?: TerminalSlotWrapper;\n fallback?: NovaComponent;\n textWrapper?: ComponentType<{ children?: ReactNode }>;\n errorMarker?: ComponentType<{ code: string; message: string }>;\n // wraps each canvas's rendered tree with a host context (ink provides the\n // per-canvas marker resolver here); the browser omits it\n canvasProvider?: ComponentType<{ canvasId: string; children?: ReactNode }>;\n // the same, per action instance — inside a list canvas several instances\n // share refs, so ink resolves markers per instance here\n instanceProvider?: ComponentType<{ canvasId: string; instanceId: string; children?: ReactNode }>;\n};\n\n// Register the wire-backed structural slots on a registry:\n//\n// - CanvasSlot: a served CanvasSlot marker in the frame resolves to that\n// canvas's live tree, dispatching events tagged with the canvas (the\n// server stamps origin). It overrides nova's shell-backed CanvasSlot,\n// which the terminal has no shell for.\n// - ActionSlot: the per-instance boundary a served tree carries (identity in\n// props, rendered content as children). With no wrapper it's transparent;\n// with one, the wrapper decides everything. Keyed by instanceId so an\n// instance swap REMOUNTS: no stale view state crossing instances.\nexport const registerWireSlots = (registry: ComponentRegistry<NovaComponent>, options: WireSlotOptions = {}): void => {\n const { slotWrapper, fallback, textWrapper, errorMarker, canvasProvider, instanceProvider } = options;\n\n const CanvasSlot: NovaComponent<{ canvasId?: string }> = ({ canvasId }: { canvasId?: string }) => {\n const api = useContext(TerminalApiContext);\n if (api === undefined || canvasId === undefined || canvasId === '') return null;\n const tree = api.canvasTree(canvasId);\n if (tree.length === 0) return null;\n const body = createElement(RenderTree, { nodes: tree });\n return createElement(\n NovaRenderProvider,\n {\n registry,\n dispatch: (event: NovaEvent) => api.dispatch(canvasId, event),\n publish: (channel: string, payload?: unknown) => api.publish(channel, payload),\n fallback,\n textWrapper,\n errorMarker,\n },\n canvasProvider === undefined ? body : createElement(canvasProvider, { canvasId }, body),\n );\n };\n registry.register('CanvasSlot', CanvasSlot, { description: 'A canvas, live from the server.' });\n\n const ActionSlot: NovaComponent<{ instanceId?: string; canvasId?: string; definitionId?: string }> = ({\n instanceId,\n canvasId,\n definitionId,\n children,\n }: TerminalSlotWrapperProps) => {\n const api = useContext(TerminalApiContext);\n const wrapped = slotWrapper === undefined ? createElement(Fragment, { key: instanceId }, children) : createElement(slotWrapper, { key: instanceId, instanceId, canvasId, definitionId }, children);\n // Origin is decided HERE, where instance identity lives: a list canvas\n // renders several live cards at once, and a click inside THIS boundary\n // must reach THIS instance's triggers — the server's active-instance\n // fallback only holds for card-deck canvases. Events that already carry\n // an origin keep it.\n if (api === undefined || instanceId === undefined || canvasId === undefined) return wrapped;\n return createElement(\n NovaRenderProvider,\n {\n registry,\n dispatch: (event: NovaEvent) => api.dispatch(canvasId, event.origin === undefined ? { ...event, origin: instanceId } : event),\n publish: (channel: string, payload?: unknown) => api.publish(channel, payload),\n fallback,\n textWrapper,\n errorMarker,\n },\n instanceProvider === undefined ? wrapped : createElement(instanceProvider, { canvasId, instanceId }, wrapped),\n );\n };\n registry.register('ActionSlot', ActionSlot, { description: 'An action instance boundary from the server; the app slotWrapper wraps it.' });\n};\n","import { createElement } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport { NovaRenderProvider, RenderTree } from '@niscorp/nova/adapters/react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport type { ComponentRegistry, RenderNode } from '@niscorp/nova';\nimport { TerminalApiContext, registerWireSlots } from './slots';\nimport type { TerminalSlotWrapper } from './slots';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/moss/terminal/react/server — the React target, drawing to a string.\n// The same registry, the same wire slots and the same tree as the browser's\n// target (./index), so what a server writes into a document is what the\n// browser's target then adopts element for element. A terminal host, like any\n// other: it is handed a screen and draws it. Split from ./index so a browser\n// bundle never carries react-dom/server, and this never carries react-dom/client.\n// ═══════════════════════════════════════════════════════════\n\nexport type RenderSnapshotConfig = {\n // the frame and every canvas's tree — moss's `shells.snapshot`\n snapshot: { frame: RenderNode[]; trees: Record<string, RenderNode[]> };\n // the app's kit, exactly as the browser's `reactTarget` is given it\n registry: ComponentRegistry<NovaComponent>;\n slotWrapper?: TerminalSlotWrapper;\n};\n\nconst nothing = (): void => undefined;\n\nexport const renderSnapshot = (config: RenderSnapshotConfig): string => {\n const { snapshot, registry, slotWrapper } = config;\n registerWireSlots(registry, { slotWrapper });\n const api = {\n frame: () => snapshot.frame,\n canvasTree: (id: string) => snapshot.trees[id] ?? [],\n // a string has nobody to press it\n dispatch: nothing,\n publish: nothing,\n };\n return renderToString(\n createElement(\n TerminalApiContext.Provider,\n { value: api },\n createElement(NovaRenderProvider, { registry, dispatch: nothing, publish: nothing }, createElement(RenderTree, { nodes: api.frame() })),\n ),\n );\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
2
|
+
import { RenderNode, ComponentRegistry } from '@niscorp/nova';
|
|
3
|
+
import { T as TerminalSlotWrapper } from '../../slots-Do9ScG7v.cjs';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type RenderSnapshotConfig = {
|
|
7
|
+
snapshot: {
|
|
8
|
+
frame: RenderNode[];
|
|
9
|
+
trees: Record<string, RenderNode[]>;
|
|
10
|
+
};
|
|
11
|
+
registry: ComponentRegistry<NovaComponent>;
|
|
12
|
+
slotWrapper?: TerminalSlotWrapper;
|
|
13
|
+
};
|
|
14
|
+
declare const renderSnapshot: (config: RenderSnapshotConfig) => string;
|
|
15
|
+
|
|
16
|
+
export { type RenderSnapshotConfig, renderSnapshot };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
2
|
+
import { RenderNode, ComponentRegistry } from '@niscorp/nova';
|
|
3
|
+
import { T as TerminalSlotWrapper } from '../../slots-Do9ScG7v.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type RenderSnapshotConfig = {
|
|
7
|
+
snapshot: {
|
|
8
|
+
frame: RenderNode[];
|
|
9
|
+
trees: Record<string, RenderNode[]>;
|
|
10
|
+
};
|
|
11
|
+
registry: ComponentRegistry<NovaComponent>;
|
|
12
|
+
slotWrapper?: TerminalSlotWrapper;
|
|
13
|
+
};
|
|
14
|
+
declare const renderSnapshot: (config: RenderSnapshotConfig) => string;
|
|
15
|
+
|
|
16
|
+
export { type RenderSnapshotConfig, renderSnapshot };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { registerWireSlots, TerminalApiContext } from '../../chunk-SK4PDGEE.js';
|
|
2
|
+
import { createElement } from 'react';
|
|
3
|
+
import { renderToString } from 'react-dom/server';
|
|
4
|
+
import { NovaRenderProvider, RenderTree } from '@niscorp/nova/adapters/react';
|
|
5
|
+
|
|
6
|
+
var nothing = () => void 0;
|
|
7
|
+
var renderSnapshot = (config) => {
|
|
8
|
+
const { snapshot, registry, slotWrapper } = config;
|
|
9
|
+
registerWireSlots(registry, { slotWrapper });
|
|
10
|
+
const api = {
|
|
11
|
+
frame: () => snapshot.frame,
|
|
12
|
+
canvasTree: (id) => snapshot.trees[id] ?? [],
|
|
13
|
+
// a string has nobody to press it
|
|
14
|
+
dispatch: nothing,
|
|
15
|
+
publish: nothing
|
|
16
|
+
};
|
|
17
|
+
return renderToString(
|
|
18
|
+
createElement(
|
|
19
|
+
TerminalApiContext.Provider,
|
|
20
|
+
{ value: api },
|
|
21
|
+
createElement(NovaRenderProvider, { registry, dispatch: nothing, publish: nothing }, createElement(RenderTree, { nodes: api.frame() }))
|
|
22
|
+
)
|
|
23
|
+
);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { renderSnapshot };
|
|
27
|
+
//# sourceMappingURL=server.js.map
|
|
28
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terminal/react/server.ts"],"names":[],"mappings":";;;;;AAyBA,IAAM,UAAU,MAAY,MAAA;AAErB,IAAM,cAAA,GAAiB,CAAC,MAAA,KAAyC;AACtE,EAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAU,WAAA,EAAY,GAAI,MAAA;AAC5C,EAAA,iBAAA,CAAkB,QAAA,EAAU,EAAE,WAAA,EAAa,CAAA;AAC3C,EAAA,MAAM,GAAA,GAAM;AAAA,IACV,KAAA,EAAO,MAAM,QAAA,CAAS,KAAA;AAAA,IACtB,YAAY,CAAC,EAAA,KAAe,SAAS,KAAA,CAAM,EAAE,KAAK,EAAC;AAAA;AAAA,IAEnD,QAAA,EAAU,OAAA;AAAA,IACV,OAAA,EAAS;AAAA,GACX;AACA,EAAA,OAAO,cAAA;AAAA,IACL,aAAA;AAAA,MACE,kBAAA,CAAmB,QAAA;AAAA,MACnB,EAAE,OAAO,GAAA,EAAI;AAAA,MACb,cAAc,kBAAA,EAAoB,EAAE,QAAA,EAAU,QAAA,EAAU,SAAS,OAAA,EAAS,OAAA,EAAQ,EAAG,aAAA,CAAc,YAAY,EAAE,KAAA,EAAO,IAAI,KAAA,EAAM,EAAG,CAAC;AAAA;AACxI,GACF;AACF","file":"server.js","sourcesContent":["import { createElement } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport { NovaRenderProvider, RenderTree } from '@niscorp/nova/adapters/react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport type { ComponentRegistry, RenderNode } from '@niscorp/nova';\nimport { TerminalApiContext, registerWireSlots } from './slots';\nimport type { TerminalSlotWrapper } from './slots';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/moss/terminal/react/server — the React target, drawing to a string.\n// The same registry, the same wire slots and the same tree as the browser's\n// target (./index), so what a server writes into a document is what the\n// browser's target then adopts element for element. A terminal host, like any\n// other: it is handed a screen and draws it. Split from ./index so a browser\n// bundle never carries react-dom/server, and this never carries react-dom/client.\n// ═══════════════════════════════════════════════════════════\n\nexport type RenderSnapshotConfig = {\n // the frame and every canvas's tree — moss's `shells.snapshot`\n snapshot: { frame: RenderNode[]; trees: Record<string, RenderNode[]> };\n // the app's kit, exactly as the browser's `reactTarget` is given it\n registry: ComponentRegistry<NovaComponent>;\n slotWrapper?: TerminalSlotWrapper;\n};\n\nconst nothing = (): void => undefined;\n\nexport const renderSnapshot = (config: RenderSnapshotConfig): string => {\n const { snapshot, registry, slotWrapper } = config;\n registerWireSlots(registry, { slotWrapper });\n const api = {\n frame: () => snapshot.frame,\n canvasTree: (id: string) => snapshot.trees[id] ?? [],\n // a string has nobody to press it\n dispatch: nothing,\n publish: nothing,\n };\n return renderToString(\n createElement(\n TerminalApiContext.Provider,\n { value: api },\n createElement(NovaRenderProvider, { registry, dispatch: nothing, publish: nothing }, createElement(RenderTree, { nodes: api.frame() })),\n ),\n );\n};\n"]}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var readline = require('readline');
|
|
4
|
+
var tty = require('@niscorp/nova/adapters/tty');
|
|
5
|
+
var components = require('@niscorp/nova/adapters/tty/components');
|
|
6
|
+
|
|
7
|
+
// src/terminal/tty/index.ts
|
|
8
|
+
var HELP = [
|
|
9
|
+
"type to act:",
|
|
10
|
+
" <n> tap [n] \u2014 click a button or row, flip a toggle, focus an input",
|
|
11
|
+
" <words> with one input on screen, typed words go straight into it",
|
|
12
|
+
" \u2026while an input is focused, the next line is its value; empty line cancels",
|
|
13
|
+
"commands:",
|
|
14
|
+
" click/set/toggle/key <n> \u2026 the explicit forms of the above",
|
|
15
|
+
" refs list everything actionable",
|
|
16
|
+
" show reprint the current screen",
|
|
17
|
+
" publish <ch> [json] publish on a channel",
|
|
18
|
+
" quit leave"
|
|
19
|
+
].join("\n");
|
|
20
|
+
var ttyTarget = (config) => (api) => {
|
|
21
|
+
const { input, output } = config;
|
|
22
|
+
const view = tty.createTtyView(config.registry ?? components.defaultRegistry(), api, { fallback: config.fallback ?? components.fallback });
|
|
23
|
+
const debounceMs = config.debounceMs ?? 80;
|
|
24
|
+
const basePrompt = config.prompt ?? "\u203A ";
|
|
25
|
+
let last = { text: "", interactives: [] };
|
|
26
|
+
let timer;
|
|
27
|
+
let focus = null;
|
|
28
|
+
const rl = readline.createInterface({ input, output, prompt: basePrompt });
|
|
29
|
+
const say = (text) => void output.write(`${text}
|
|
30
|
+
`);
|
|
31
|
+
const valueText = (item) => typeof item.value === "string" || typeof item.value === "number" ? String(item.value) : "";
|
|
32
|
+
const focusPrompt = (item) => `${item.path ?? item.ref} \u27E8${valueText(item)}\u27E9 \u203A `;
|
|
33
|
+
const findFocused = () => focus === null ? void 0 : last.interactives.find((item) => item.kind === "model" && item.canvas === focus?.canvas && item.ref === focus?.ref);
|
|
34
|
+
const enterFocus = (item) => {
|
|
35
|
+
focus = { canvas: item.canvas, ref: item.ref, name: item.path ?? item.ref };
|
|
36
|
+
rl.setPrompt(focusPrompt(item));
|
|
37
|
+
rl.prompt(true);
|
|
38
|
+
};
|
|
39
|
+
const exitFocus = () => {
|
|
40
|
+
focus = null;
|
|
41
|
+
rl.setPrompt(basePrompt);
|
|
42
|
+
};
|
|
43
|
+
let link = "unknown";
|
|
44
|
+
const checkStatus = () => {
|
|
45
|
+
if (config.status === void 0) return;
|
|
46
|
+
const now = config.status();
|
|
47
|
+
if (now === "incompatible") {
|
|
48
|
+
if (link !== "incompatible") say("\xD7 this terminal and the server speak different protocol versions \u2014 update one of them");
|
|
49
|
+
link = "incompatible";
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (now === "open" && link !== "up") {
|
|
53
|
+
link = "up";
|
|
54
|
+
say("\u2713 connected");
|
|
55
|
+
rl.prompt(true);
|
|
56
|
+
} else if (now !== "open" && link === "up") {
|
|
57
|
+
link = "down";
|
|
58
|
+
say("\xD7 connection lost \u2014 retrying");
|
|
59
|
+
rl.prompt(true);
|
|
60
|
+
} else if (link === "unknown") {
|
|
61
|
+
link = "down";
|
|
62
|
+
say("\u2026 connecting");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const paint = (force = false) => {
|
|
66
|
+
const frame = view.render();
|
|
67
|
+
const changed = frame.text !== last.text;
|
|
68
|
+
last = frame;
|
|
69
|
+
if (focus !== null) {
|
|
70
|
+
const still = findFocused();
|
|
71
|
+
if (still === void 0) {
|
|
72
|
+
say(`input ${focus.name} left the screen`);
|
|
73
|
+
exitFocus();
|
|
74
|
+
} else rl.setPrompt(focusPrompt(still));
|
|
75
|
+
}
|
|
76
|
+
if (!changed && !force) return;
|
|
77
|
+
if (frame.text !== "") say(`
|
|
78
|
+
${frame.text}`);
|
|
79
|
+
rl.prompt(true);
|
|
80
|
+
};
|
|
81
|
+
const update = () => {
|
|
82
|
+
checkStatus();
|
|
83
|
+
if (debounceMs === 0) {
|
|
84
|
+
paint();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
timer = setTimeout(paint, debounceMs);
|
|
89
|
+
};
|
|
90
|
+
const act = (interactive, event) => {
|
|
91
|
+
if (interactive.canvas === "") {
|
|
92
|
+
say(`[${interactive.index}] is frame chrome \u2014 it dispatches nothing`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
api.dispatch(interactive.canvas, interactive.origin === void 0 ? event : { ...event, origin: interactive.origin });
|
|
96
|
+
};
|
|
97
|
+
const fill = (interactive, value) => act(interactive, { type: "ui:model", ref: interactive.ref, payload: value });
|
|
98
|
+
const flip = (interactive) => act(interactive, { type: "ui:model", ref: interactive.ref, payload: interactive.value !== true });
|
|
99
|
+
const tap = (interactive) => {
|
|
100
|
+
if (interactive.kind === "model") {
|
|
101
|
+
enterFocus(interactive);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (interactive.kind === "toggle") {
|
|
105
|
+
flip(interactive);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
act(interactive, interactive.value === void 0 ? { type: "ui:click", ref: interactive.ref } : { type: "ui:click", ref: interactive.ref, payload: interactive.value });
|
|
109
|
+
};
|
|
110
|
+
const find = (token) => {
|
|
111
|
+
const index = Number(token);
|
|
112
|
+
if (!Number.isInteger(index)) return void 0;
|
|
113
|
+
return last.interactives.find((item) => item.index === index);
|
|
114
|
+
};
|
|
115
|
+
const onLine = (raw) => {
|
|
116
|
+
if (focus !== null) {
|
|
117
|
+
const target = findFocused();
|
|
118
|
+
if (raw !== "" && target !== void 0) fill(target, raw);
|
|
119
|
+
exitFocus();
|
|
120
|
+
rl.prompt();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const line = raw.trim();
|
|
124
|
+
if (line === "") {
|
|
125
|
+
rl.prompt();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const [head = "", second, ...restTokens] = line.split(/\s+/);
|
|
129
|
+
const rest = restTokens.join(" ");
|
|
130
|
+
if (head === "help") say(HELP);
|
|
131
|
+
else if (head === "show") paint(true);
|
|
132
|
+
else if (head === "quit" || head === "exit") {
|
|
133
|
+
if (config.onQuit !== void 0) config.onQuit();
|
|
134
|
+
else say("no quit handler \u2014 Ctrl+C to leave");
|
|
135
|
+
return;
|
|
136
|
+
} else if (head === "refs") {
|
|
137
|
+
if (last.interactives.length === 0) say("nothing actionable on screen");
|
|
138
|
+
for (const item of last.interactives) {
|
|
139
|
+
const where = item.canvas === "" ? "frame" : item.canvas;
|
|
140
|
+
say(`[${item.index}] ${item.kind} ${item.ref} @${where} ${item.label}${item.path !== void 0 ? ` (${item.path})` : ""}`);
|
|
141
|
+
}
|
|
142
|
+
} else if (head === "publish") {
|
|
143
|
+
if (second === void 0) say("usage: publish <channel> [json]");
|
|
144
|
+
else if (rest === "") api.publish(second);
|
|
145
|
+
else {
|
|
146
|
+
try {
|
|
147
|
+
api.publish(second, JSON.parse(rest));
|
|
148
|
+
} catch {
|
|
149
|
+
api.publish(second, rest);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} else if (head === "set") {
|
|
153
|
+
const target = find(second);
|
|
154
|
+
if (target === void 0) say(`no [${second ?? "?"}] on screen \u2014 try refs`);
|
|
155
|
+
else if (target.kind === "model") {
|
|
156
|
+
if (rest === "") enterFocus(target);
|
|
157
|
+
else fill(target, rest);
|
|
158
|
+
} else if (target.kind === "toggle") {
|
|
159
|
+
if (rest === "true" || rest === "false") act(target, { type: "ui:model", ref: target.ref, payload: rest === "true" });
|
|
160
|
+
else say(`[${target.index}] is a toggle \u2014 use: toggle ${target.index}`);
|
|
161
|
+
} else say(`[${target.index}] is not an input`);
|
|
162
|
+
} else if (head === "toggle") {
|
|
163
|
+
const target = find(second);
|
|
164
|
+
if (target === void 0) say(`no [${second ?? "?"}] on screen \u2014 try refs`);
|
|
165
|
+
else if (target.kind === "toggle") flip(target);
|
|
166
|
+
else say(`[${target.index}] is not a toggle`);
|
|
167
|
+
} else if (head === "key") {
|
|
168
|
+
const target = find(second);
|
|
169
|
+
if (target === void 0) say(`no [${second ?? "?"}] on screen \u2014 try refs`);
|
|
170
|
+
else if (target.kind === "model" && rest !== "") act(target, { type: "ui:key", ref: target.ref, key: rest });
|
|
171
|
+
else say("usage: key <n> <key> \u2014 on an input");
|
|
172
|
+
} else if (head === "click" || /^\d+$/.test(head)) {
|
|
173
|
+
const target = find(head === "click" ? second : head);
|
|
174
|
+
if (target === void 0) say(`no [${head === "click" ? second ?? "?" : head}] on screen \u2014 try refs`);
|
|
175
|
+
else tap(target);
|
|
176
|
+
} else {
|
|
177
|
+
const inputs = last.interactives.filter((item) => item.kind === "model");
|
|
178
|
+
if (inputs.length === 1 && inputs[0] !== void 0) fill(inputs[0], line);
|
|
179
|
+
else if (inputs.length === 0) say(`unknown command: ${head} \u2014 try help`);
|
|
180
|
+
else say(`several inputs on screen \u2014 pick one: ${inputs.map((item) => `[${item.index}]`).join(" ")}`);
|
|
181
|
+
}
|
|
182
|
+
rl.prompt();
|
|
183
|
+
};
|
|
184
|
+
rl.on("line", onLine);
|
|
185
|
+
rl.on("close", () => config.onQuit?.());
|
|
186
|
+
say('[moss/tty] terminal attached \u2014 type what you see: a number taps [n], words fill the input. "help" for more.');
|
|
187
|
+
checkStatus();
|
|
188
|
+
paint(true);
|
|
189
|
+
return {
|
|
190
|
+
update,
|
|
191
|
+
destroy: () => {
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
rl.removeAllListeners();
|
|
194
|
+
rl.close();
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
exports.ttyTarget = ttyTarget;
|
|
200
|
+
//# sourceMappingURL=index.cjs.map
|
|
201
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/terminal/tty/index.ts"],"names":["createTtyView","defaultRegistry","defaultFallback","createInterface"],"mappings":";;;;;;;AA6CA,IAAM,IAAA,GAAO;AAAA,EACX,cAAA;AAAA,EACA,iFAAA;AAAA,EACA,uEAAA;AAAA,EACA,mFAAA;AAAA,EACA,WAAA;AAAA,EACA,qEAAA;AAAA,EACA,2DAAA;AAAA,EACA,2DAAA;AAAA,EACA,qDAAA;AAAA,EACA;AACF,CAAA,CAAE,KAAK,IAAI,CAAA;AAEJ,IAAM,SAAA,GAAY,CAAC,MAAA,KAAoC,CAAC,GAAA,KAAQ;AACrE,EAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAO,GAAI,MAAA;AAC1B,EAAA,MAAM,IAAA,GAAOA,iBAAA,CAAc,MAAA,CAAO,QAAA,IAAYC,0BAAA,EAAgB,EAAG,GAAA,EAAK,EAAE,QAAA,EAAU,MA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IACX;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import { createInterface } from 'node:readline';\nimport { createTtyView } from '@niscorp/nova/adapters/tty';\nimport type { TtyComponent, TtyFrame, TtyInteractive } from '@niscorp/nova/adapters/tty';\nimport { defaultRegistry, fallback as defaultFallback } from '@niscorp/nova/adapters/tty/components';\nimport type { ComponentRegistry, NovaEvent } from '@niscorp/nova';\nimport type { WireStatus } from '../../client';\nimport type { Target } from '../index';\n\n// ═══════════════════════════════════════════════════════════\n// @niscorp/moss/terminal/tty — the line-terminal render target: a REPL over\n// the wire. nova's TTY adapter says what the screen IS ({ text, interactives });\n// this target owns the stdio half — print each served frame, read lines, map\n// them onto the adapter's numbered interactives with the same event\n// vocabulary every other target dispatches (`ui:click`, `ui:model`, `ui:key`).\n//\n// The input scheme is \"numbers act, words fill\": a bare number taps [n] —\n// click a button or row, flip a toggle, FOCUS an input (the next line typed\n// is its value, verbatim; an empty line cancels) — and bare words go straight\n// into the only input on screen. Command words (refs, help, quit, …) are the\n// escape hatch, not the default. All of this is target policy: the wire, the\n// server, and the apps never see anything but ordinary events.\n//\n// Runs on anything with a Readable/Writable pair: a real TTY, a test's\n// PassThrough, a pipe. Node-shaped code lives here, never in the adapter.\n// ═══════════════════════════════════════════════════════════\n\nexport type TtyTargetConfig = {\n input: NodeJS.ReadableStream;\n output: NodeJS.WritableStream;\n // the app's TTY kit; omit for nova's default (floor kit + fallback)\n registry?: ComponentRegistry<TtyComponent>;\n fallback?: TtyComponent;\n // called on `quit` / EOF — the host owns the wire and the process, so the\n // target only reports the intent\n onQuit?: () => void;\n // the wire's connection state, when the host can supply it (wire.status) —\n // the REPL says '… connecting' / '✓ connected' / '× connection lost',\n // because a silent screen on a dead socket is indistinguishable from a\n // working terminal rendering an empty app\n status?: () => WireStatus;\n // coalesce a burst of wire updates into one repaint; 0 paints immediately\n debounceMs?: number;\n prompt?: string;\n};\n\nconst HELP = [\n 'type to act:',\n ' <n> tap [n] — click a button or row, flip a toggle, focus an input',\n ' <words> with one input on screen, typed words go straight into it',\n ' …while an input is focused, the next line is its value; empty line cancels',\n 'commands:',\n ' click/set/toggle/key <n> … the explicit forms of the above',\n ' refs list everything actionable',\n ' show reprint the current screen',\n ' publish <ch> [json] publish on a channel',\n ' quit leave',\n].join('\\n');\n\nexport const ttyTarget = (config: TtyTargetConfig): Target => (api) => {\n const { input, output } = config;\n const view = createTtyView(config.registry ?? defaultRegistry(), api, { fallback: config.fallback ?? defaultFallback });\n const debounceMs = config.debounceMs ?? 80;\n const basePrompt = config.prompt ?? '› ';\n\n let last: TtyFrame = { text: '', interactives: [] };\n let timer: ReturnType<typeof setTimeout> | undefined;\n // The focused input, tracked by identity (canvas + ref), never by index —\n // a repaint renumbers, identity survives the server echo.\n let focus: { canvas: string; ref: string; name: string } | null = null;\n\n const rl = createInterface({ input, output, prompt: basePrompt });\n const say = (text: string): void => void output.write(`${text}\\n`);\n\n const valueText = (item: TtyInteractive): string =>\n typeof item.value === 'string' || typeof item.value === 'number' ? String(item.value) : '';\n const focusPrompt = (item: TtyInteractive): string => `${item.path ?? item.ref} ⟨${valueText(item)}⟩ › `;\n\n const findFocused = (): TtyInteractive | undefined =>\n focus === null\n ? undefined\n : last.interactives.find((item) => item.kind === 'model' && item.canvas === focus?.canvas && item.ref === focus?.ref);\n\n const enterFocus = (item: TtyInteractive): void => {\n focus = { canvas: item.canvas, ref: item.ref, name: item.path ?? item.ref };\n rl.setPrompt(focusPrompt(item));\n rl.prompt(true);\n };\n\n const exitFocus = (): void => {\n focus = null;\n rl.setPrompt(basePrompt);\n };\n\n // Report real transitions only: up once, down once — never the\n // closed↔connecting flap of every backoff retry.\n let link: 'unknown' | 'up' | 'down' | 'incompatible' = 'unknown';\n const checkStatus = (): void => {\n if (config.status === undefined) return;\n const now = config.status();\n if (now === 'incompatible') {\n if (link !== 'incompatible') say('× this terminal and the server speak different protocol versions — update one of them');\n link = 'incompatible';\n return;\n }\n if (now === 'open' && link !== 'up') {\n link = 'up';\n say('✓ connected');\n rl.prompt(true);\n } else if (now !== 'open' && link === 'up') {\n link = 'down';\n say('× connection lost — retrying');\n rl.prompt(true);\n } else if (link === 'unknown') {\n link = 'down';\n say('… connecting');\n }\n };\n\n const paint = (force = false): void => {\n const frame = view.render();\n const changed = frame.text !== last.text;\n last = frame;\n // Focus follows identity across repaints; if the input left the screen\n // (navigation, sign-out), focus drops with a note instead of swallowing\n // the next line silently.\n if (focus !== null) {\n const still = findFocused();\n if (still === undefined) {\n say(`input ${focus.name} left the screen`);\n exitFocus();\n } else rl.setPrompt(focusPrompt(still));\n }\n if (!changed && !force) return;\n if (frame.text !== '') say(`\\n${frame.text}`);\n rl.prompt(true);\n };\n\n const update = (): void => {\n // Status transitions print immediately — never debounced with the trees.\n checkStatus();\n if (debounceMs === 0) {\n paint();\n return;\n }\n clearTimeout(timer);\n timer = setTimeout(paint, debounceMs);\n };\n\n // Dispatch for a numbered interactive — the canvas and the instance were\n // recorded at render time (the instance is the origin: a list canvas has\n // several live at once); frame chrome ('') dispatches nothing, same as\n // every other target.\n const act = (interactive: TtyInteractive, event: NovaEvent): void => {\n if (interactive.canvas === '') {\n say(`[${interactive.index}] is frame chrome — it dispatches nothing`);\n return;\n }\n api.dispatch(interactive.canvas, interactive.origin === undefined ? event : { ...event, origin: interactive.origin });\n };\n\n const fill = (interactive: TtyInteractive, value: string): void =>\n act(interactive, { type: 'ui:model', ref: interactive.ref, payload: value });\n\n const flip = (interactive: TtyInteractive): void =>\n act(interactive, { type: 'ui:model', ref: interactive.ref, payload: interactive.value !== true });\n\n // A bare number: act by kind — the tap of this terminal.\n const tap = (interactive: TtyInteractive): void => {\n if (interactive.kind === 'model') {\n enterFocus(interactive);\n return;\n }\n if (interactive.kind === 'toggle') {\n flip(interactive);\n return;\n }\n act(interactive, interactive.value === undefined\n ? { type: 'ui:click', ref: interactive.ref }\n : { type: 'ui:click', ref: interactive.ref, payload: interactive.value });\n };\n\n const find = (token: string | undefined): TtyInteractive | undefined => {\n const index = Number(token);\n if (!Number.isInteger(index)) return undefined;\n return last.interactives.find((item) => item.index === index);\n };\n\n const onLine = (raw: string): void => {\n // Focused input: the whole line is the value, verbatim — even words that\n // look like commands. An empty line cancels.\n if (focus !== null) {\n const target = findFocused();\n if (raw !== '' && target !== undefined) fill(target, raw);\n exitFocus();\n rl.prompt();\n return;\n }\n\n const line = raw.trim();\n if (line === '') {\n rl.prompt();\n return;\n }\n const [head = '', second, ...restTokens] = line.split(/\\s+/);\n const rest = restTokens.join(' ');\n\n if (head === 'help') say(HELP);\n else if (head === 'show') paint(true);\n else if (head === 'quit' || head === 'exit') {\n if (config.onQuit !== undefined) config.onQuit();\n else say('no quit handler — Ctrl+C to leave');\n return;\n } else if (head === 'refs') {\n if (last.interactives.length === 0) say('nothing actionable on screen');\n for (const item of last.interactives) {\n const where = item.canvas === '' ? 'frame' : item.canvas;\n say(`[${item.index}] ${item.kind} ${item.ref} @${where} ${item.label}${item.path !== undefined ? ` (${item.path})` : ''}`);\n }\n } else if (head === 'publish') {\n if (second === undefined) say('usage: publish <channel> [json]');\n else if (rest === '') api.publish(second);\n else {\n try {\n api.publish(second, JSON.parse(rest));\n } catch {\n api.publish(second, rest);\n }\n }\n } else if (head === 'set') {\n const target = find(second);\n if (target === undefined) say(`no [${second ?? '?'}] on screen — try refs`);\n else if (target.kind === 'model') {\n // `set 1 alex` fills; a bare `set 1` focuses instead of sending ''\n if (rest === '') enterFocus(target);\n else fill(target, rest);\n } else if (target.kind === 'toggle') {\n if (rest === 'true' || rest === 'false') act(target, { type: 'ui:model', ref: target.ref, payload: rest === 'true' });\n else say(`[${target.index}] is a toggle — use: toggle ${target.index}`);\n } else say(`[${target.index}] is not an input`);\n } else if (head === 'toggle') {\n const target = find(second);\n if (target === undefined) say(`no [${second ?? '?'}] on screen — try refs`);\n else if (target.kind === 'toggle') flip(target);\n else say(`[${target.index}] is not a toggle`);\n } else if (head === 'key') {\n const target = find(second);\n if (target === undefined) say(`no [${second ?? '?'}] on screen — try refs`);\n else if (target.kind === 'model' && rest !== '') act(target, { type: 'ui:key', ref: target.ref, key: rest });\n else say('usage: key <n> <key> — on an input');\n } else if (head === 'click' || /^\\d+$/.test(head)) {\n const target = find(head === 'click' ? second : head);\n if (target === undefined) say(`no [${head === 'click' ? second ?? '?' : head}] on screen — try refs`);\n else tap(target);\n } else {\n // Not a command and not a number: words fill the only input on screen.\n const inputs = last.interactives.filter((item) => item.kind === 'model');\n if (inputs.length === 1 && inputs[0] !== undefined) fill(inputs[0], line);\n else if (inputs.length === 0) say(`unknown command: ${head} — try help`);\n else say(`several inputs on screen — pick one: ${inputs.map((item) => `[${item.index}]`).join(' ')}`);\n }\n rl.prompt();\n };\n\n rl.on('line', onLine);\n // EOF (Ctrl+D / a closed pipe) means the same as `quit`.\n rl.on('close', () => config.onQuit?.());\n\n say('[moss/tty] terminal attached — type what you see: a number taps [n], words fill the input. \"help\" for more.');\n checkStatus();\n paint(true);\n\n return {\n update,\n destroy: () => {\n clearTimeout(timer);\n rl.removeAllListeners();\n rl.close();\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TtyComponent } from '@niscorp/nova/adapters/tty';
|
|
2
|
+
import { ComponentRegistry } from '@niscorp/nova';
|
|
3
|
+
import { WireStatus } from '../../client.cjs';
|
|
4
|
+
import { Target } from '../index.cjs';
|
|
5
|
+
|
|
6
|
+
type TtyTargetConfig = {
|
|
7
|
+
input: NodeJS.ReadableStream;
|
|
8
|
+
output: NodeJS.WritableStream;
|
|
9
|
+
registry?: ComponentRegistry<TtyComponent>;
|
|
10
|
+
fallback?: TtyComponent;
|
|
11
|
+
onQuit?: () => void;
|
|
12
|
+
status?: () => WireStatus;
|
|
13
|
+
debounceMs?: number;
|
|
14
|
+
prompt?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const ttyTarget: (config: TtyTargetConfig) => Target;
|
|
17
|
+
|
|
18
|
+
export { type TtyTargetConfig, ttyTarget };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TtyComponent } from '@niscorp/nova/adapters/tty';
|
|
2
|
+
import { ComponentRegistry } from '@niscorp/nova';
|
|
3
|
+
import { WireStatus } from '../../client.js';
|
|
4
|
+
import { Target } from '../index.js';
|
|
5
|
+
|
|
6
|
+
type TtyTargetConfig = {
|
|
7
|
+
input: NodeJS.ReadableStream;
|
|
8
|
+
output: NodeJS.WritableStream;
|
|
9
|
+
registry?: ComponentRegistry<TtyComponent>;
|
|
10
|
+
fallback?: TtyComponent;
|
|
11
|
+
onQuit?: () => void;
|
|
12
|
+
status?: () => WireStatus;
|
|
13
|
+
debounceMs?: number;
|
|
14
|
+
prompt?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const ttyTarget: (config: TtyTargetConfig) => Target;
|
|
17
|
+
|
|
18
|
+
export { type TtyTargetConfig, ttyTarget };
|