@niscorp/moss 0.4.0 → 0.6.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/CHANGELOG.md +492 -0
- package/DESIGN.md +265 -49
- package/DOCS.md +1527 -344
- package/README.md +37 -20
- package/dist/app-CUnDcXQu.d.ts +143 -0
- package/dist/app-CdANzi2q.d.cts +143 -0
- package/dist/chunk-3RIWTXGI.cjs +174 -0
- package/dist/chunk-3RIWTXGI.cjs.map +1 -0
- package/dist/chunk-4ZGAFZGS.js +152 -0
- package/dist/chunk-4ZGAFZGS.js.map +1 -0
- package/dist/chunk-6QPTMKRE.cjs +53 -0
- package/dist/chunk-6QPTMKRE.cjs.map +1 -0
- package/dist/chunk-D3YZIAYV.cjs +137 -0
- package/dist/chunk-D3YZIAYV.cjs.map +1 -0
- package/dist/chunk-IUJ2TRNB.cjs +57 -0
- package/dist/chunk-IUJ2TRNB.cjs.map +1 -0
- package/dist/chunk-IW3A2YIC.js +49 -0
- package/dist/chunk-IW3A2YIC.js.map +1 -0
- package/dist/chunk-NRZ3Z2FF.js +61 -0
- package/dist/chunk-NRZ3Z2FF.js.map +1 -0
- package/dist/chunk-NSK7QSSG.js +26 -0
- package/dist/chunk-NSK7QSSG.js.map +1 -0
- package/dist/chunk-PWUO4RET.js +374 -0
- package/dist/chunk-PWUO4RET.js.map +1 -0
- package/dist/chunk-R2YPQHQH.cjs +383 -0
- package/dist/chunk-R2YPQHQH.cjs.map +1 -0
- package/dist/chunk-R66WUKGC.cjs +2716 -0
- package/dist/chunk-R66WUKGC.cjs.map +1 -0
- package/dist/chunk-T5BRTFKP.js +53 -0
- package/dist/chunk-T5BRTFKP.js.map +1 -0
- package/dist/chunk-TGKDS2T7.cjs +330 -0
- package/dist/chunk-TGKDS2T7.cjs.map +1 -0
- package/dist/chunk-TLNRFAQ6.js +326 -0
- package/dist/chunk-TLNRFAQ6.js.map +1 -0
- package/dist/chunk-V5YMJL7Z.js +2704 -0
- package/dist/chunk-V5YMJL7Z.js.map +1 -0
- package/dist/chunk-VBWNHF4H.cjs +30 -0
- package/dist/chunk-VBWNHF4H.cjs.map +1 -0
- package/dist/chunk-VKQPOZDJ.cjs +72 -0
- package/dist/chunk-VKQPOZDJ.cjs.map +1 -0
- package/dist/{chunk-U3UR5AOQ.js → chunk-WKBH3UMB.js} +43 -16
- package/dist/chunk-WKBH3UMB.js.map +1 -0
- package/dist/client/node.cjs.map +1 -1
- package/dist/client/node.d.cts +3 -1
- package/dist/client/node.d.ts +3 -1
- package/dist/client/node.js.map +1 -1
- package/dist/client.cjs +14 -302
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +9 -33
- package/dist/client.d.ts +9 -33
- package/dist/client.js +2 -2
- package/dist/document-D7nroBww.d.cts +169 -0
- package/dist/document-DeTPGBil.d.ts +169 -0
- package/dist/env-CY8EGWnD.d.cts +24 -0
- package/dist/env-DEPqqHEb.d.ts +24 -0
- package/dist/index-B411sK9M.d.cts +130 -0
- package/dist/index-B411sK9M.d.ts +130 -0
- package/dist/index.cjs +45 -3916
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -100
- package/dist/index.d.ts +46 -100
- package/dist/index.js +4 -94
- package/dist/index.js.map +1 -1
- package/dist/integrations.cjs +975 -0
- package/dist/integrations.cjs.map +1 -0
- package/dist/integrations.d.cts +63 -0
- package/dist/integrations.d.ts +63 -0
- package/dist/integrations.js +972 -0
- package/dist/integrations.js.map +1 -0
- package/dist/messages-CSwCJgH3.d.cts +51 -0
- package/dist/messages-CSwCJgH3.d.ts +51 -0
- package/dist/node.cjs +17 -3455
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +13 -10
- package/dist/node.d.ts +13 -10
- package/dist/node.js +5 -3
- package/dist/protocol.cjs +24 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +11 -0
- package/dist/protocol.d.ts +11 -0
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +1 -0
- package/dist/slots-96gNc9uH.d.cts +12 -0
- package/dist/slots-BX5N0Juv.d.ts +14 -0
- package/dist/slots-CU-AbnJg.d.cts +14 -0
- package/dist/slots-sLXDrlbG.d.ts +12 -0
- package/dist/socket-D90h1xSV.d.cts +24 -0
- package/dist/socket-D90h1xSV.d.ts +24 -0
- package/dist/targets-DInbLzff.d.cts +9 -0
- package/dist/targets-DInbLzff.d.ts +9 -0
- package/dist/terminal/dom/index.cjs +8 -3
- package/dist/terminal/dom/index.cjs.map +1 -1
- package/dist/terminal/dom/index.d.cts +3 -0
- package/dist/terminal/dom/index.d.ts +3 -0
- package/dist/terminal/dom/index.js +8 -3
- package/dist/terminal/dom/index.js.map +1 -1
- package/dist/terminal/dom/server.cjs +2 -7
- package/dist/terminal/dom/server.cjs.map +1 -1
- package/dist/terminal/dom/server.d.cts +3 -5
- package/dist/terminal/dom/server.d.ts +3 -5
- package/dist/terminal/dom/server.js +2 -7
- package/dist/terminal/dom/server.js.map +1 -1
- package/dist/terminal/index.cjs +22 -300
- package/dist/terminal/index.cjs.map +1 -1
- package/dist/terminal/index.d.cts +7 -2
- package/dist/terminal/index.d.ts +7 -2
- package/dist/terminal/index.js +21 -22
- package/dist/terminal/index.js.map +1 -1
- package/dist/terminal/ink/index.d.ts +3 -2
- package/dist/terminal/ink/index.js +149 -106
- package/dist/terminal/ink/index.js.map +1 -1
- package/dist/terminal/react/index.cjs +21 -71
- package/dist/terminal/react/index.cjs.map +1 -1
- package/dist/terminal/react/index.d.cts +5 -2
- package/dist/terminal/react/index.d.ts +5 -2
- package/dist/terminal/react/index.js +17 -20
- package/dist/terminal/react/index.js.map +1 -1
- package/dist/terminal/react/server.cjs +4 -68
- package/dist/terminal/react/server.cjs.map +1 -1
- package/dist/terminal/react/server.d.cts +9 -6
- package/dist/terminal/react/server.d.ts +9 -6
- package/dist/terminal/react/server.js +3 -18
- package/dist/terminal/react/server.js.map +1 -1
- package/dist/terminal/tty/index.cjs +147 -130
- package/dist/terminal/tty/index.cjs.map +1 -1
- package/dist/terminal/tty/index.d.cts +4 -2
- package/dist/terminal/tty/index.d.ts +4 -2
- package/dist/terminal/tty/index.js +147 -130
- package/dist/terminal/tty/index.js.map +1 -1
- package/dist/terminal/vue/index.cjs +20 -72
- package/dist/terminal/vue/index.cjs.map +1 -1
- package/dist/terminal/vue/index.d.cts +8 -12
- package/dist/terminal/vue/index.d.ts +8 -12
- package/dist/terminal/vue/index.js +45 -1
- package/dist/terminal/vue/index.js.map +1 -1
- package/dist/terminal/vue/server.cjs +4 -76
- package/dist/terminal/vue/server.cjs.map +1 -1
- package/dist/terminal/vue/server.d.cts +7 -6
- package/dist/terminal/vue/server.d.ts +7 -6
- package/dist/terminal/vue/server.js +3 -10
- package/dist/terminal/vue/server.js.map +1 -1
- package/dist/tide.cjs +41 -0
- package/dist/tide.cjs.map +1 -0
- package/dist/tide.d.cts +25 -0
- package/dist/tide.d.ts +25 -0
- package/dist/tide.js +39 -0
- package/dist/tide.js.map +1 -0
- package/dist/unverified.cjs +12 -0
- package/dist/unverified.cjs.map +1 -0
- package/dist/unverified.d.cts +7 -0
- package/dist/unverified.d.ts +7 -0
- package/dist/unverified.js +10 -0
- package/dist/unverified.js.map +1 -0
- package/dist/vite.cjs +96 -232
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +6 -8
- package/dist/vite.d.ts +6 -8
- package/dist/vite.js +97 -71
- package/dist/vite.js.map +1 -1
- package/package.json +52 -9
- package/dist/chunk-4T6KAXBP.js +0 -256
- package/dist/chunk-4T6KAXBP.js.map +0 -1
- package/dist/chunk-EMRDIZLY.js +0 -99
- package/dist/chunk-EMRDIZLY.js.map +0 -1
- package/dist/chunk-HOZID4EM.js +0 -366
- package/dist/chunk-HOZID4EM.js.map +0 -1
- package/dist/chunk-R3QMJ3JF.js +0 -3404
- package/dist/chunk-R3QMJ3JF.js.map +0 -1
- package/dist/chunk-SK4PDGEE.js +0 -55
- package/dist/chunk-SK4PDGEE.js.map +0 -1
- package/dist/chunk-U3UR5AOQ.js.map +0 -1
- package/dist/document-DhWxieUc.d.cts +0 -1024
- package/dist/document-DhWxieUc.d.ts +0 -1024
- package/dist/slots-Do9ScG7v.d.cts +0 -37
- package/dist/slots-Do9ScG7v.d.ts +0 -37
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { RenderApi } from '@niscorp/nova';
|
|
2
|
-
import { Wire } from '../client.cjs';
|
|
2
|
+
import { WireStatus, Wire } from '../client.cjs';
|
|
3
|
+
import '../messages-CSwCJgH3.cjs';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '../env-CY8EGWnD.cjs';
|
|
3
6
|
|
|
4
|
-
type TerminalApi = RenderApi
|
|
7
|
+
type TerminalApi = RenderApi & {
|
|
8
|
+
status: () => WireStatus;
|
|
9
|
+
};
|
|
5
10
|
type TerminalMount = {
|
|
6
11
|
update: () => void;
|
|
7
12
|
destroy: () => void;
|
package/dist/terminal/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { RenderApi } from '@niscorp/nova';
|
|
2
|
-
import { Wire } from '../client.js';
|
|
2
|
+
import { WireStatus, Wire } from '../client.js';
|
|
3
|
+
import '../messages-CSwCJgH3.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
import '../env-DEPqqHEb.js';
|
|
3
6
|
|
|
4
|
-
type TerminalApi = RenderApi
|
|
7
|
+
type TerminalApi = RenderApi & {
|
|
8
|
+
status: () => WireStatus;
|
|
9
|
+
};
|
|
5
10
|
type TerminalMount = {
|
|
6
11
|
update: () => void;
|
|
7
12
|
destroy: () => void;
|
package/dist/terminal/index.js
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import { createWire } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { createWire } from '../chunk-TLNRFAQ6.js';
|
|
2
|
+
import '../chunk-4ZGAFZGS.js';
|
|
3
3
|
import { createHeadKeeper, headOf } from '@niscorp/nova/document';
|
|
4
4
|
|
|
5
|
-
// src/terminal/hotkey.ts
|
|
6
|
-
var onHotkey = (spec, handler) => {
|
|
7
|
-
const parts = spec.toLowerCase().split("+");
|
|
8
|
-
const key = parts[parts.length - 1] ?? "";
|
|
9
|
-
const mods = new Set(parts.slice(0, -1));
|
|
10
|
-
const listener = (event) => {
|
|
11
|
-
if (event.key.toLowerCase() === key && event.ctrlKey === mods.has("ctrl") && event.shiftKey === mods.has("shift") && event.altKey === mods.has("alt") && event.metaKey === (mods.has("meta") || mods.has("cmd"))) {
|
|
12
|
-
event.preventDefault();
|
|
13
|
-
handler();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
window.addEventListener("keydown", listener);
|
|
17
|
-
return () => window.removeEventListener("keydown", listener);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
5
|
// src/terminal/history.ts
|
|
21
|
-
var
|
|
6
|
+
var BACK_ENTRY_STATE = { nisc: "terminal-back" };
|
|
22
7
|
var trapBack = (handler) => {
|
|
23
8
|
if (typeof window === "undefined") return () => void 0;
|
|
24
9
|
const history = window.history;
|
|
25
10
|
if (history === void 0 || typeof history.pushState !== "function") return () => void 0;
|
|
26
11
|
const spare = () => {
|
|
27
12
|
try {
|
|
28
|
-
history.pushState(
|
|
13
|
+
history.pushState(BACK_ENTRY_STATE, "");
|
|
29
14
|
} catch {
|
|
30
15
|
}
|
|
31
16
|
};
|
|
@@ -39,6 +24,21 @@ var trapBack = (handler) => {
|
|
|
39
24
|
window.removeEventListener("popstate", onPopState);
|
|
40
25
|
};
|
|
41
26
|
};
|
|
27
|
+
|
|
28
|
+
// src/terminal/index.ts
|
|
29
|
+
var onHotkey = (spec, handler) => {
|
|
30
|
+
const parts = spec.toLowerCase().split("+");
|
|
31
|
+
const key = parts[parts.length - 1] ?? "";
|
|
32
|
+
const mods = new Set(parts.slice(0, -1));
|
|
33
|
+
const listener = (event) => {
|
|
34
|
+
if (event.key.toLowerCase() === key && event.ctrlKey === mods.has("ctrl") && event.shiftKey === mods.has("shift") && event.altKey === mods.has("alt") && event.metaKey === (mods.has("meta") || mods.has("cmd"))) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
handler();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
window.addEventListener("keydown", listener);
|
|
40
|
+
return () => window.removeEventListener("keydown", listener);
|
|
41
|
+
};
|
|
42
42
|
var followHead = (api, subscribe) => {
|
|
43
43
|
if (typeof document === "undefined") return () => void 0;
|
|
44
44
|
const keep = createHeadKeeper(document);
|
|
@@ -46,15 +46,14 @@ var followHead = (api, subscribe) => {
|
|
|
46
46
|
read();
|
|
47
47
|
return subscribe(read);
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
// src/terminal/index.ts
|
|
51
49
|
var createTerminal = (config) => {
|
|
52
50
|
const { target, wire } = config;
|
|
53
51
|
const api = {
|
|
54
52
|
frame: () => wire.snapshot().frame,
|
|
55
53
|
canvasTree: (id) => wire.snapshot().trees.get(id) ?? [],
|
|
56
54
|
dispatch: (id, event) => wire.dispatch(id, event),
|
|
57
|
-
publish: (channel, payload) => wire.publish(channel, payload)
|
|
55
|
+
publish: (channel, payload) => wire.publish(channel, payload),
|
|
56
|
+
status: () => wire.status()
|
|
58
57
|
};
|
|
59
58
|
const mount = target(api);
|
|
60
59
|
const unsubscribe = wire.subscribe(mount.update);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/terminal/hotkey.ts","../../src/terminal/history.ts","../../src/terminal/head.ts","../../src/terminal/index.ts"],"names":[],"mappings":";;;;;AAeO,IAAM,QAAA,GAAW,CAAC,IAAA,EAAc,OAAA,KAAwC;AAC7E,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,WAAA,EAAY,CAAE,MAAM,GAAG,CAAA;AAC1C,EAAA,MAAM,GAAA,GAAM,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,IAAK,EAAA;AACvC,EAAA,MAAM,OAAO,IAAI,GAAA,CAAI,MAAM,KAAA,CAAM,CA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A,MAAA,CAAO,OAAA,EAAQ;AACf,IAAA,KAAA,GAAA,CAAS,KAAA,GAAQ,KAAK,IAAA,CAAK,MAAA;AAC3B,IAAA,MAAA,GAAS,eAAe,EAAE,MAAA,EAAQ,SAAS,KAAK,CAAA,EAAG,MAAM,CAAA;AAAA,EAC3D,CAAA;AAEA,EAAA,MAAM,KAAA,GAAQ,MAAY,IAAA,CAAK,KAAA,EAAM;AACrC,EAAA,MAAM,IAAA,GAAO,MAAY,IAAA,CAAK,IAAA,EAAK;AAEnC,EAAA,MAAM,cAAA,GAAiB,OAAO,OAAA,KAAY,MAAA,GAAY,SAAY,QAAA,CAAS,MAAA,CAAO,SAAS,IAAI,CAAA;AAC/F,EAAA,MAAM,eAAA,GAAkB,OAAO,QAAA,KAAa,MAAA,GAAY,SAAY,QAAA,CAAS,MAAA,CAAO,UAAU,KAAK,CAAA;AACnG,EAAA,MAAM,kBAAkB,MAAA,CAAO,QAAA,KAAa,KAAA,GAAQ,MAAA,GAAY,SAAS,IAAI,CAAA;AAI7E,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,SAAS,MAAM;AACb,MAAA,cAAA,IAAiB;AACjB,MAAA,eAAA,IAAkB;AAClB,MAAA,eAAA,IAAkB;AAClB,MAAA,MAAA,CAAO,OAAA,EAAQ;AACf,MAAA,IAAI,QAAA,OAAe,OAAA,EAAQ;AAAA,IAC7B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["// ═══════════════════════════════════════════════════════════════\n// The live-swap hotkey — isolated here because it is the one imperative,\n// gimmicky corner of the terminal (a render target is not app state, so it\n// can't be a nova action; it's client chrome). Keyed on `event.key`, the\n// CHARACTER the key produces, so a combo matches the key the user actually\n// presses on any layout — `event.code` would bind a physical QWERTY position\n// (the key labelled Y sits elsewhere on QWERTZ/AZERTY). Use letter keys, not\n// punctuation, so Shift never remaps the character.\n// ═══════════════════════════════════════════════════════════════\n\nexport type HotkeyDisposer = () => void;\n\n// Attach `handler` to a keydown matching `spec` (e.g. \"ctrl+shift+y\"); returns\n// a disposer. Matches modifiers exactly, so \"ctrl+shift+y\" never fires on\n// \"ctrl+shift+alt+y\".\nexport const onHotkey = (spec: string, handler: () => void): HotkeyDisposer => {\n const parts = spec.toLowerCase().split('+');\n const key = parts[parts.length - 1] ?? '';\n const mods = new Set(parts.slice(0, -1));\n const listener = (event: KeyboardEvent): void => {\n if (\n event.key.toLowerCase() === key &&\n event.ctrlKey === mods.has('ctrl') &&\n event.shiftKey === mods.has('shift') &&\n event.altKey === mods.has('alt') &&\n event.metaKey === (mods.has('meta') || mods.has('cmd'))\n ) {\n event.preventDefault();\n handler();\n }\n };\n window.addEventListener('keydown', listener);\n return () => window.removeEventListener('keydown', listener);\n};\n","// ═══════════════════════════════════════════════════════════════\n// The browser's back button, caught.\n//\n// ⟲ IT USED TO UNLOAD THE APPLICATION. A moss terminal never touched the URL,\n// so a tab held exactly one history entry and back meant \"leave the page\" —\n// the socket dropped, the shell went unattended, and somebody who wanted to\n// close a screen got a blank tab instead. Nothing was lost (the shell is\n// durable, keyed by principal, and a reload reattaches to it) but nobody\n// pressing back is thinking about that.\n//\n// What it does instead: keep ONE spare history entry ahead of the page and\n// spend it on every press. Back consumes the spare, this puts another one\n// straight back, and the gesture is handed to the terminal — which sends it up\n// the wire, where the shell that owns the navigation decides what back means.\n//\n// The URL never changes. That is the honest position while location lives on\n// the SERVER: the shell is keyed by principal, not by tab, so an address bar\n// would be a per-tab claim on state two tabs share. When deep links arrive they\n// arrive as a projection of the shell's own location, and this file is where\n// the gesture will already be.\n// ═══════════════════════════════════════════════════════════════\n\nexport type BackTrapDisposer = () => void;\n\n// Marks the entry as ours, so a host that keeps its own history state can tell\n// this one apart. Nothing reads it yet; a debugger looking at `history.state`\n// deserves to find a name rather than an empty object.\nconst SENTINEL = { nisc: 'terminal-back' } as const;\n\n// Catch the host's back gesture and call `handler` instead of letting the page\n// unload. A no-op (and a disposer that does nothing) wherever there is no\n// history to trap — a TTY, a TUI, a plain process — so the conductor can ask\n// for it unconditionally.\nexport const trapBack = (handler: () => void): BackTrapDisposer => {\n if (typeof window === 'undefined') return () => undefined;\n const history = window.history as History | undefined;\n if (history === undefined || typeof history.pushState !== 'function') return () => undefined;\n\n // The spare. `pushState` with no url keeps the current address, so this adds\n // an entry without changing what the address bar says or asking the server\n // for anything.\n const spare = (): void => {\n try {\n history.pushState(SENTINEL, '');\n } catch {\n // A sandboxed document can refuse this. Back then behaves as it always\n // did rather than throwing on the way out of a keypress.\n }\n };\n\n const onPopState = (): void => {\n // One entry was just spent — replace it, then act. In that order: the\n // handler sends a message up the wire and the answer arrives on another\n // tick, and the history has to be whole before the next press, not after.\n spare();\n handler();\n };\n\n spare();\n window.addEventListener('popstate', onPopState);\n return () => {\n window.removeEventListener('popstate', onPopState);\n // The spare entry stays. It cannot be removed without navigating, and one\n // dead entry is a far smaller surprise than a navigation nobody asked for.\n };\n};\n","import { createHeadKeeper, headOf } from '@niscorp/nova/document';\nimport type { TerminalApi } from './index';\n\n// ═══════════════════════════════════════════════════════════════\n// The page's <head>, kept on the screen.\n//\n// A drawn page arrives with its head written (../document). From then on the\n// screen moves over the wire and the page is never fetched again, so the head\n// is read off the trees the wire holds, whenever they change: the elements the\n// screen's head holds go into the page's, and the page's own tags give way to\n// them and come back (nova's head keeper).\n//\n// Terminal chrome, like the back trap beside it: the head is the terminal's\n// relationship to the surface it is painted on, the same for every render\n// target, and the app authors nothing to keep it. Where there is no document\n// (a TTY, a TUI) there is no head, and this does nothing.\n// ═══════════════════════════════════════════════════════════════\n\nexport const followHead = (api: TerminalApi, subscribe: (listener: () => void) => () => void): (() => void) => {\n if (typeof document === 'undefined') return () => undefined;\n const keep = createHeadKeeper(document);\n const read = (): void => keep(headOf(api)?.elements);\n read();\n return subscribe(read);\n};\n","import type { RenderApi } from '@niscorp/nova';\nimport { createWire } from '../client';\nimport type { Wire } from '../client';\nimport { onHotkey } from './hotkey';\nimport { trapBack } from './history';\nimport { followHead } from './head';\n\n// ═══════════════════════════════════════════════════════════════\n// @niscorp/moss/terminal — the terminal, owned by the protocol that defines\n// it. A terminal is the wire (../client) plus a RENDER TARGET (react, dom,\n// console, …) painting the wire's snapshot and sending events back. This\n// module is framework-blind: the conductor drives one target against the\n// wire; the switcher cycles targets on a hotkey, sharing one wire so the\n// session survives the swap. Targets live in the subpaths (./react, ./dom);\n// the framework-shaped code stays there, never here.\n// ═══════════════════════════════════════════════════════════════\n\n// What a target renders against — nova core's `RenderApi`: the wire's snapshot\n// as pull functions (frame + per-canvas trees) plus the event sinks (dispatch\n// tagged by canvas, publish). Aliased, not redeclared — the dom adapter, the\n// react adapter, and this conductor share ONE contract, so a target written\n// for nova's dom view drops straight onto the wire. A target never touches the\n// wire directly.\nexport type TerminalApi = RenderApi;\n\n// A mounted target: re-render on demand, tear down on swap.\nexport type TerminalMount = { update: () => void; destroy: () => void };\n\n// A render target: paint the api onto the target's own surface, return the\n// mount handle. The surface — a DOM root, a stdio pair — is construction\n// config on the concrete target (`reactTarget({ root, … })`, `domTarget({\n// root })`), never part of this contract: the conductor stays surface-blind\n// and runs anywhere the wire does. A target renders once on mount; the\n// conductor calls `update` on every wire change.\nexport type Target = (api: TerminalApi) => TerminalMount;\n\n// The conductor: one target, one wire. Subscribes the target's `update` to\n// the wire and routes events back. Nothing framework-shaped.\nexport const createTerminal = (config: { target: Target; wire: Wire }): { destroy: () => void } => {\n const { target, wire } = config;\n const api: TerminalApi = {\n frame: () => wire.snapshot().frame,\n canvasTree: (id) => wire.snapshot().trees.get(id) ?? [],\n dispatch: (id, event) => wire.dispatch(id, event),\n publish: (channel, payload) => wire.publish(channel, payload),\n };\n const mount = target(api);\n const unsubscribe = wire.subscribe(mount.update);\n const stopHead = followHead(api, wire.subscribe);\n return {\n destroy: () => {\n unsubscribe();\n stopHead();\n mount.destroy();\n },\n };\n};\n\nexport type MountTerminalConfig = {\n // render targets by name; the hotkey cycles them in insertion order\n targets: Record<string, Target>;\n // e.g. \"ctrl+shift+t\" — the live render-target swap. Omit for no swapping.\n swapKey?: string;\n // e.g. \"ctrl+shift+r\" — ask the server for a fresh shell. Omit for no key.\n //\n // The one control that must work when nothing else does. It sits on a\n // keystroke for the same reason the swap does — it acts on the terminal's\n // relationship to the server, not on anything the app models — but the\n // reason it exists at all is stronger: a shell lives on the SERVER, keyed by\n // principal, so a broken one survives every gesture a client can make alone.\n // Reloading reattaches to it. Clearing the token and signing back in\n // reattaches to it. Without a key that says \"throw it away\", somebody\n // watching a dead screen has no move left.\n resetKey?: string;\n // Catch the host's BACK gesture — the browser's back button — and send it up\n // the wire instead of letting it unload the page. Default: on, wherever a\n // history exists to catch (see ./history); nothing at all in a TTY or a TUI.\n //\n // Terminal chrome for the same reason the swap and reset keys are: back is\n // the terminal's relationship to the surface it is painted on, and the app\n // authors nothing to receive it. What back MEANS is decided a layer up, by\n // the shell that owns the navigation.\n trapBack?: boolean;\n // which target to mount first (default: the first key)\n initial?: string;\n // inject an existing wire (shared across swaps), or let the terminal make\n // one — `url` seeds a self-made wire (default: /socket on the host).\n wire?: Wire;\n url?: string;\n};\n\n// The switcher: mount a terminal that can hot-swap its render target on a\n// keystroke, over ONE wire (created here unless injected) so the socket,\n// session, and current trees survive the swap. The hotkey is the one legit\n// piece of imperative client chrome — a render target is not app state, so\n// it is not a nova action; it lives here, in the terminal.\nexport const mountTerminal = (config: MountTerminalConfig): { swap: () => void; reset: () => void; back: () => void; destroy: () => void } => {\n const keys = Object.keys(config.targets);\n if (keys.length === 0) throw new Error('mountTerminal: at least one target is required');\n\n const ownsWire = config.wire === undefined;\n const wire = config.wire ?? createWire(config.url !== undefined ? { url: config.url } : {});\n\n const targetAt = (i: number): Target => {\n const key = keys[i];\n const target = key === undefined ? undefined : config.targets[key];\n if (target === undefined) throw new Error(`mountTerminal: no target at index ${i}`);\n return target;\n };\n\n const start = config.initial === undefined ? 0 : keys.indexOf(config.initial);\n let index = start < 0 ? 0 : start;\n let active = createTerminal({ target: targetAt(index), wire });\n\n const swap = (): void => {\n active.destroy();\n index = (index + 1) % keys.length;\n active = createTerminal({ target: targetAt(index), wire });\n };\n\n const reset = (): void => wire.reset();\n const back = (): void => wire.back();\n\n const disposeSwapKey = config.swapKey === undefined ? undefined : onHotkey(config.swapKey, swap);\n const disposeResetKey = config.resetKey === undefined ? undefined : onHotkey(config.resetKey, reset);\n const disposeBackTrap = config.trapBack === false ? undefined : trapBack(back);\n\n // All three are returned so a host can bind its own control (a button, a\n // console call) — the keys and the trap are a convenience, not the only way in.\n return {\n swap,\n reset,\n back,\n destroy: () => {\n disposeSwapKey?.();\n disposeResetKey?.();\n disposeBackTrap?.();\n active.destroy();\n if (ownsWire) wire.dispose();\n },\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/terminal/history.ts","../../src/terminal/index.ts"],"names":[],"mappings":";;;;;AAEA,IAAM,gBAAA,GAAmB,EAAE,IAAA,EAAM,eAAA,EAAgB;AAE1C,IAAM,QAAA,GAAW,CAAC,OAAA,KAA0C;AACjE,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,MAAM,MAAA;AAEhD,EAAA,MAAM,UAA+B,MAAA,CAAO,OAAA;AAC5C,EAAA,IAAI,YAAY,MAAA,IAAa,OAAO,QAAQ,SAAA,KAAc,UAAA,SAAmB,MAAM,MAAA;AAEnF,EAAA,MAAM,QAAQ,MAAY;AACxB,IAAA,IAAI;AACF,MAAA,OAAA,CAAQ,SAAA,CAAU,kBAAkB,EAAE,CAAA;AAAA,IACxC,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF,CAAA;AAEA,EAAA,MAAM,aAAa,MAAY;AAE7B,IAAA,KAAA,EAAM;AACN,IAAA,OAAA,EAAQ;AAAA,EACV,CAAA;AAEA,EAAA,KAAA,EAAM;AACN,EAAA,MAAA,CAAO,gBAAA,CAAiB,YAAY,UAAU,CAAA;AAC9C,EAAA,OAAO,MAAM;AACX,IAAA,MAAA,CAAO,mBA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,GAAiB,OAAO,OAAA,KAAY,MAAA,GAAY,SAAY,QAAA,CAAS,MAAA,CAAO,SAAS,IAAI,CAAA;AAC/F,EAAA,MAAM,eAAA,GAAkB,OAAO,QAAA,KAAa,MAAA,GAAY,SAAY,QAAA,CAAS,MAAA,CAAO,UAAU,KAAK,CAAA;AACnG,EAAA,MAAM,kBAAkB,MAAA,CAAO,QAAA,KAAa,KAAA,GAAQ,MAAA,GAAY,SAAS,IAAI,CAAA;AAE7E,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,SAAS,MAAM;AACb,MAAA,cAAA,IAAiB;AACjB,MAAA,eAAA,IAAkB;AAClB,MAAA,eAAA,IAAkB;AAClB,MAAA,MAAA,CAAO,OAAA,EAAQ;AACf,MAAA,IAAI,QAAA,OAAe,OAAA,EAAQ;AAAA,IAC7B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["export type BackTrapDisposer = () => void;\n\nconst BACK_ENTRY_STATE = { nisc: 'terminal-back' } as const;\n\nexport const trapBack = (handler: () => void): BackTrapDisposer => {\n if (typeof window === 'undefined') return () => undefined;\n // A window stood up outside a browser may have no history, whatever its type says.\n const history: History | undefined = window.history;\n if (history === undefined || typeof history.pushState !== 'function') return () => undefined;\n\n const spare = (): void => {\n try {\n history.pushState(BACK_ENTRY_STATE, '');\n } catch {\n // A sandboxed document can refuse: back then keeps the browser's default.\n }\n };\n\n const onPopState = (): void => {\n // Before the handler: its answer comes on a later tick, and the next press needs the spare.\n spare();\n handler();\n };\n\n spare();\n window.addEventListener('popstate', onPopState);\n return () => {\n window.removeEventListener('popstate', onPopState);\n // The spare entry stays: it cannot be removed without navigating.\n };\n};\n","import { createHeadKeeper, headOf } from '@niscorp/nova/document';\nimport type { RenderApi } from '@niscorp/nova';\nimport { createWire } from '../client';\nimport type { Wire, WireStatus } from '../client';\nimport { trapBack } from './history';\n\ntype HotkeyDisposer = () => void;\n\nconst onHotkey = (spec: string, handler: () => void): HotkeyDisposer => {\n const parts = spec.toLowerCase().split('+');\n const key = parts[parts.length - 1] ?? '';\n const mods = new Set(parts.slice(0, -1));\n // event.key, not event.code: the character the key produces, wherever the layout puts it.\n const listener = (event: KeyboardEvent): void => {\n if (\n event.key.toLowerCase() === key &&\n event.ctrlKey === mods.has('ctrl') &&\n event.shiftKey === mods.has('shift') &&\n event.altKey === mods.has('alt') &&\n event.metaKey === (mods.has('meta') || mods.has('cmd'))\n ) {\n event.preventDefault();\n handler();\n }\n };\n window.addEventListener('keydown', listener);\n return () => window.removeEventListener('keydown', listener);\n};\n\nconst followHead = (api: TerminalApi, subscribe: (listener: () => void) => () => void): (() => void) => {\n if (typeof document === 'undefined') return () => undefined;\n const keep = createHeadKeeper(document);\n const read = (): void => keep(headOf(api)?.elements);\n read();\n return subscribe(read);\n};\n\nexport type TerminalApi = RenderApi & { status: () => WireStatus };\n\nexport type TerminalMount = { update: () => void; destroy: () => void };\n\nexport type Target = (api: TerminalApi) => TerminalMount;\n\nexport const createTerminal = (config: { target: Target; wire: Wire }): { destroy: () => void } => {\n const { target, wire } = config;\n const api: TerminalApi = {\n frame: () => wire.snapshot().frame,\n canvasTree: (id) => wire.snapshot().trees.get(id) ?? [],\n dispatch: (id, event) => wire.dispatch(id, event),\n publish: (channel, payload) => wire.publish(channel, payload),\n status: () => wire.status(),\n };\n const mount = target(api);\n const unsubscribe = wire.subscribe(mount.update);\n const stopHead = followHead(api, wire.subscribe);\n return {\n destroy: () => {\n unsubscribe();\n stopHead();\n mount.destroy();\n },\n };\n};\n\nexport type MountTerminalConfig = {\n targets: Record<string, Target>;\n swapKey?: string;\n resetKey?: string;\n trapBack?: boolean;\n initial?: string;\n wire?: Wire;\n url?: string;\n};\n\nexport const mountTerminal = (config: MountTerminalConfig): { swap: () => void; reset: () => void; back: () => void; destroy: () => void } => {\n const keys = Object.keys(config.targets);\n if (keys.length === 0) throw new Error('mountTerminal: at least one target is required');\n\n const ownsWire = config.wire === undefined;\n const wire = config.wire ?? createWire(config.url !== undefined ? { url: config.url } : {});\n\n const targetAt = (i: number): Target => {\n const key = keys[i];\n const target = key === undefined ? undefined : config.targets[key];\n if (target === undefined) throw new Error(`mountTerminal: no target at index ${i}`);\n return target;\n };\n\n const start = config.initial === undefined ? 0 : keys.indexOf(config.initial);\n let index = start < 0 ? 0 : start;\n let active = createTerminal({ target: targetAt(index), wire });\n\n const swap = (): void => {\n active.destroy();\n index = (index + 1) % keys.length;\n active = createTerminal({ target: targetAt(index), wire });\n };\n\n const reset = (): void => wire.reset();\n const back = (): void => wire.back();\n\n const disposeSwapKey = config.swapKey === undefined ? undefined : onHotkey(config.swapKey, swap);\n const disposeResetKey = config.resetKey === undefined ? undefined : onHotkey(config.resetKey, reset);\n const disposeBackTrap = config.trapBack === false ? undefined : trapBack(back);\n\n return {\n swap,\n reset,\n back,\n destroy: () => {\n disposeSwapKey?.();\n disposeResetKey?.();\n disposeBackTrap?.();\n active.destroy();\n if (ownsWire) wire.dispose();\n },\n };\n};\n"]}
|
|
@@ -4,7 +4,9 @@ import { FC, ReactNode } from 'react';
|
|
|
4
4
|
|
|
5
5
|
type WireStatus = 'connecting' | 'open' | 'closed' | 'incompatible' | 'static';
|
|
6
6
|
|
|
7
|
-
type TerminalApi = RenderApi
|
|
7
|
+
type TerminalApi = RenderApi & {
|
|
8
|
+
status: () => WireStatus;
|
|
9
|
+
};
|
|
8
10
|
type TerminalMount = {
|
|
9
11
|
update: () => void;
|
|
10
12
|
destroy: () => void;
|
|
@@ -24,7 +26,6 @@ type InkTargetConfig = {
|
|
|
24
26
|
slotWrapper?: TerminalSlotWrapper;
|
|
25
27
|
stdin?: NodeJS.ReadStream;
|
|
26
28
|
stdout?: NodeJS.WriteStream;
|
|
27
|
-
status?: () => WireStatus;
|
|
28
29
|
onQuit?: () => void;
|
|
29
30
|
patchConsole?: boolean;
|
|
30
31
|
};
|
|
@@ -1,100 +1,138 @@
|
|
|
1
1
|
import { createContext, createElement, useRef, useContext, Fragment } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { NovaRenderProvider, RenderTree } from '@niscorp/nova/adapters/react';
|
|
4
|
-
import { defaultRegistry, FrameControlsContext, ErrorMarker, TextWrap, fallback as fallback$1, markerFocusId, CanvasMarkersContext } from '@niscorp/nova/adapters/ink';
|
|
2
|
+
import { defaultRegistry, FrameControlsContext, markerFocusId, fallback as fallback$1, TextWrap, ErrorMarker, CanvasMarkersContext } from '@niscorp/nova/adapters/ink';
|
|
5
3
|
import { createTtyView } from '@niscorp/nova/adapters/tty';
|
|
6
4
|
import { defaultRegistry as defaultRegistry$1, fallback } from '@niscorp/nova/adapters/tty/components';
|
|
5
|
+
import { render, Text, useFocusManager, useInput } from 'ink';
|
|
6
|
+
import { CANVAS_SLOT_NAME, ACTION_SLOT_NAME, scopeDispatch } from '@niscorp/nova';
|
|
7
|
+
import { NovaRenderProvider, RenderTree } from '@niscorp/nova/adapters/react';
|
|
7
8
|
|
|
8
9
|
// src/terminal/ink/index.ts
|
|
10
|
+
var STATUS_WORDS = {
|
|
11
|
+
connecting: "\u2026 connecting",
|
|
12
|
+
lost: "\xD7 connection lost \u2014 retrying",
|
|
13
|
+
incompatible: "\xD7 this terminal and the server speak different protocol versions \u2014 update one of them"
|
|
14
|
+
};
|
|
15
|
+
var tapEventOf = (interactive) => {
|
|
16
|
+
if (interactive.kind === "model") return void 0;
|
|
17
|
+
if (interactive.kind === "toggle") return { type: "ui:model", ref: interactive.ref, payload: interactive.value !== true };
|
|
18
|
+
return interactive.value === void 0 ? { type: "ui:click", ref: interactive.ref } : { type: "ui:click", ref: interactive.ref, payload: interactive.value };
|
|
19
|
+
};
|
|
20
|
+
var sendFrom = (api, interactive, event) => {
|
|
21
|
+
if (interactive.canvas === "") return false;
|
|
22
|
+
const dispatch = (stamped) => api.dispatch(interactive.canvas, stamped);
|
|
23
|
+
(interactive.origin === void 0 ? dispatch : scopeDispatch(dispatch, interactive.origin))(event);
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
var canvasSlotOf = (api, canvasId) => {
|
|
27
|
+
if (api === void 0 || canvasId === void 0 || canvasId === "") return void 0;
|
|
28
|
+
const tree = api.canvasTree(canvasId);
|
|
29
|
+
if (tree.length === 0) return void 0;
|
|
30
|
+
return {
|
|
31
|
+
canvasId,
|
|
32
|
+
tree,
|
|
33
|
+
dispatch: (event) => api.dispatch(canvasId, event),
|
|
34
|
+
publish: (channel, payload) => api.publish(channel, payload)
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var actionSlotOf = (api, canvasId, instanceId) => {
|
|
38
|
+
if (api === void 0 || instanceId === void 0 || canvasId === void 0) return void 0;
|
|
39
|
+
return {
|
|
40
|
+
canvasId,
|
|
41
|
+
instanceId,
|
|
42
|
+
dispatch: scopeDispatch((event) => api.dispatch(canvasId, event), instanceId),
|
|
43
|
+
publish: (channel, payload) => api.publish(channel, payload)
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
var registerSlots = (registry, slots) => {
|
|
47
|
+
registry.register(CANVAS_SLOT_NAME, slots.canvas, { description: "A canvas, live from the server." });
|
|
48
|
+
registry.register(ACTION_SLOT_NAME, slots.action, { description: "An action instance boundary from the server; the app slotWrapper wraps it." });
|
|
49
|
+
};
|
|
9
50
|
var TerminalApiContext = createContext(void 0);
|
|
10
51
|
var registerWireSlots = (registry, options = {}) => {
|
|
11
52
|
const { slotWrapper, fallback, textWrapper, errorMarker, canvasProvider, instanceProvider } = options;
|
|
12
53
|
const CanvasSlot = ({ canvasId }) => {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
const
|
|
16
|
-
if (tree.length === 0) return null;
|
|
17
|
-
const body = createElement(RenderTree, { nodes: tree });
|
|
54
|
+
const slot = canvasSlotOf(useContext(TerminalApiContext), canvasId);
|
|
55
|
+
if (slot === void 0) return null;
|
|
56
|
+
const body = createElement(RenderTree, { nodes: slot.tree });
|
|
18
57
|
return createElement(
|
|
19
58
|
NovaRenderProvider,
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
dispatch: (event) => api.dispatch(canvasId, event),
|
|
23
|
-
publish: (channel, payload) => api.publish(channel, payload),
|
|
24
|
-
fallback,
|
|
25
|
-
textWrapper,
|
|
26
|
-
errorMarker
|
|
27
|
-
},
|
|
28
|
-
canvasProvider === void 0 ? body : createElement(canvasProvider, { canvasId }, body)
|
|
59
|
+
{ registry, dispatch: slot.dispatch, publish: slot.publish, fallback, textWrapper, errorMarker },
|
|
60
|
+
canvasProvider === void 0 ? body : createElement(canvasProvider, { canvasId: slot.canvasId }, body)
|
|
29
61
|
);
|
|
30
62
|
};
|
|
31
|
-
registry.register("CanvasSlot", CanvasSlot, { description: "A canvas, live from the server." });
|
|
32
63
|
const ActionSlot = ({
|
|
33
64
|
instanceId,
|
|
34
65
|
canvasId,
|
|
35
66
|
definitionId,
|
|
36
67
|
children
|
|
37
68
|
}) => {
|
|
38
|
-
const
|
|
69
|
+
const slot = actionSlotOf(useContext(TerminalApiContext), canvasId, instanceId);
|
|
39
70
|
const wrapped = slotWrapper === void 0 ? createElement(Fragment, { key: instanceId }, children) : createElement(slotWrapper, { key: instanceId, instanceId, canvasId, definitionId }, children);
|
|
40
|
-
if (
|
|
71
|
+
if (slot === void 0) return wrapped;
|
|
41
72
|
return createElement(
|
|
42
73
|
NovaRenderProvider,
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
dispatch: (event) => api.dispatch(canvasId, event.origin === void 0 ? { ...event, origin: instanceId } : event),
|
|
46
|
-
publish: (channel, payload) => api.publish(channel, payload),
|
|
47
|
-
fallback,
|
|
48
|
-
textWrapper,
|
|
49
|
-
errorMarker
|
|
50
|
-
},
|
|
51
|
-
instanceProvider === void 0 ? wrapped : createElement(instanceProvider, { canvasId, instanceId }, wrapped)
|
|
74
|
+
{ registry, dispatch: slot.dispatch, publish: slot.publish, fallback, textWrapper, errorMarker },
|
|
75
|
+
instanceProvider === void 0 ? wrapped : createElement(instanceProvider, { canvasId: slot.canvasId, instanceId: slot.instanceId }, wrapped)
|
|
52
76
|
);
|
|
53
77
|
};
|
|
54
|
-
registry
|
|
78
|
+
registerSlots(registry, { canvas: CanvasSlot, action: ActionSlot });
|
|
55
79
|
};
|
|
80
|
+
var terminalFrame = (api, registry, leaves = {}) => createElement(
|
|
81
|
+
TerminalApiContext.Provider,
|
|
82
|
+
{ value: api },
|
|
83
|
+
createElement(
|
|
84
|
+
NovaRenderProvider,
|
|
85
|
+
{
|
|
86
|
+
registry,
|
|
87
|
+
// The frame is chrome: events come only from inside a canvas.
|
|
88
|
+
dispatch: () => void 0,
|
|
89
|
+
publish: (channel, payload) => api.publish(channel, payload),
|
|
90
|
+
...leaves
|
|
91
|
+
},
|
|
92
|
+
createElement(RenderTree, { nodes: api.frame() })
|
|
93
|
+
)
|
|
94
|
+
);
|
|
56
95
|
|
|
57
96
|
// src/terminal/ink/index.ts
|
|
58
|
-
var
|
|
59
|
-
var inkTarget = (config = {}) => (api) => {
|
|
60
|
-
const registry = config.registry ?? defaultRegistry();
|
|
97
|
+
var createMarks = (api) => {
|
|
61
98
|
const indexView = createTtyView(defaultRegistry$1(), api, { fallback: fallback });
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
99
|
+
let list = [];
|
|
100
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
101
|
+
return {
|
|
102
|
+
reindex: () => {
|
|
103
|
+
list = indexView.render().interactives;
|
|
104
|
+
byKey.clear();
|
|
105
|
+
const seen = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const item of list) {
|
|
107
|
+
const base = `${item.canvas}:${item.origin ?? ""}:${item.ref}`;
|
|
108
|
+
const occurrence = seen.get(base) ?? 0;
|
|
109
|
+
seen.set(base, occurrence + 1);
|
|
110
|
+
byKey.set(`${base}#${occurrence}`, item);
|
|
111
|
+
if ((item.kind === "click" || item.kind === "row") && item.value !== void 0) {
|
|
112
|
+
byKey.set(`${base}@${JSON.stringify(item.value)}`, item);
|
|
113
|
+
}
|
|
74
114
|
}
|
|
115
|
+
},
|
|
116
|
+
count: () => list.length,
|
|
117
|
+
at: (index) => list.find((entry) => entry.index === index),
|
|
118
|
+
resolverFor: (canvasId, instanceId) => (ref, identity = {}) => {
|
|
119
|
+
const base = `${canvasId}:${instanceId}:${ref}`;
|
|
120
|
+
if (identity.value !== void 0) {
|
|
121
|
+
const byValue = byKey.get(`${base}@${JSON.stringify(identity.value)}`);
|
|
122
|
+
if (byValue !== void 0) return byValue.index;
|
|
123
|
+
}
|
|
124
|
+
return byKey.get(`${base}#${identity.occurrence ?? 0}`)?.index;
|
|
75
125
|
}
|
|
76
126
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const InstanceMarkers = ({ canvasId, instanceId, children }) => createElement(CanvasMarkersContext.Provider, { value: resolverFor(canvasId, instanceId) }, children);
|
|
87
|
-
registerWireSlots(registry, {
|
|
88
|
-
slotWrapper: config.slotWrapper,
|
|
89
|
-
fallback: fallback$1,
|
|
90
|
-
textWrapper: TextWrap,
|
|
91
|
-
errorMarker: ErrorMarker,
|
|
92
|
-
canvasProvider: CanvasMarkers,
|
|
93
|
-
instanceProvider: InstanceMarkers
|
|
94
|
-
});
|
|
95
|
-
const typingRef = { current: false };
|
|
96
|
-
const frameControls = { setTyping: (typing) => void (typingRef.current = typing) };
|
|
97
|
-
const Nav = () => {
|
|
127
|
+
};
|
|
128
|
+
var markerProviders = (marks) => ({
|
|
129
|
+
canvasProvider: ({ canvasId, children }) => createElement(CanvasMarkersContext.Provider, { value: marks.resolverFor(canvasId, "") }, children),
|
|
130
|
+
instanceProvider: ({ canvasId, instanceId, children }) => createElement(CanvasMarkersContext.Provider, { value: marks.resolverFor(canvasId, instanceId) }, children)
|
|
131
|
+
});
|
|
132
|
+
var DIGIT_COMMIT_MS = 600;
|
|
133
|
+
var navOf = (deps) => {
|
|
134
|
+
const { api, marks, typing } = deps;
|
|
135
|
+
return () => {
|
|
98
136
|
const { focus, focusNext, focusPrevious } = useFocusManager();
|
|
99
137
|
const buffer = useRef("");
|
|
100
138
|
const timer = useRef(void 0);
|
|
@@ -108,28 +146,26 @@ var inkTarget = (config = {}) => (api) => {
|
|
|
108
146
|
const commit = () => {
|
|
109
147
|
const index = Number(buffer.current);
|
|
110
148
|
clearBuffer();
|
|
111
|
-
const item = marks.
|
|
149
|
+
const item = marks.at(index);
|
|
112
150
|
if (item === void 0 || item.canvas === "") return;
|
|
113
151
|
focus(markerFocusId(index));
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
else if (item.kind !== "model")
|
|
117
|
-
api.dispatch(item.canvas, item.value === void 0 ? { type: "ui:click", ref: item.ref, ...origin } : { type: "ui:click", ref: item.ref, payload: item.value, ...origin });
|
|
152
|
+
const event = tapEventOf(item);
|
|
153
|
+
if (event !== void 0) sendFrom(api, item, event);
|
|
118
154
|
};
|
|
119
155
|
useInput((input, key) => {
|
|
120
156
|
if (key.downArrow) {
|
|
121
|
-
if (!
|
|
157
|
+
if (!typing()) focusNext();
|
|
122
158
|
return;
|
|
123
159
|
}
|
|
124
160
|
if (key.upArrow) {
|
|
125
|
-
if (!
|
|
161
|
+
if (!typing()) focusPrevious();
|
|
126
162
|
return;
|
|
127
163
|
}
|
|
128
|
-
if (
|
|
129
|
-
if (/^[0-9]
|
|
164
|
+
if (typing()) return;
|
|
165
|
+
if (/^[0-9]+$/.test(input) && !key.ctrl && !key.meta) {
|
|
130
166
|
buffer.current += input;
|
|
131
167
|
if (timer.current !== void 0) clearTimeout(timer.current);
|
|
132
|
-
if (Number(buffer.current) * 10 > marks.
|
|
168
|
+
if (Number(buffer.current) * 10 > marks.count()) commit();
|
|
133
169
|
else timer.current = setTimeout(commit, DIGIT_COMMIT_MS);
|
|
134
170
|
return;
|
|
135
171
|
}
|
|
@@ -137,38 +173,35 @@ var inkTarget = (config = {}) => (api) => {
|
|
|
137
173
|
});
|
|
138
174
|
return null;
|
|
139
175
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
176
|
+
};
|
|
177
|
+
var statusLineOf = (status) => () => {
|
|
178
|
+
const now = status();
|
|
179
|
+
if (now === "open") return null;
|
|
180
|
+
if (now === "incompatible") return createElement(Text, { color: "red" }, STATUS_WORDS.incompatible);
|
|
181
|
+
return now === "connecting" ? createElement(Text, { color: "yellow" }, STATUS_WORDS.connecting) : createElement(Text, { color: "red" }, STATUS_WORDS.lost);
|
|
182
|
+
};
|
|
183
|
+
var inkTarget = (config = {}) => (api) => {
|
|
184
|
+
const registry = config.registry ?? defaultRegistry();
|
|
185
|
+
const marks = createMarks(api);
|
|
186
|
+
registerWireSlots(registry, {
|
|
187
|
+
slotWrapper: config.slotWrapper,
|
|
188
|
+
fallback: fallback$1,
|
|
189
|
+
textWrapper: TextWrap,
|
|
190
|
+
errorMarker: ErrorMarker,
|
|
191
|
+
...markerProviders(marks)
|
|
192
|
+
});
|
|
193
|
+
const typingRef = { current: false };
|
|
194
|
+
const frameControls = { setTyping: (typing) => void (typingRef.current = typing) };
|
|
195
|
+
const Nav = navOf({ api, marks, typing: () => typingRef.current });
|
|
196
|
+
const StatusLine = statusLineOf(api.status);
|
|
148
197
|
const Frame = () => {
|
|
149
|
-
reindex();
|
|
198
|
+
marks.reindex();
|
|
150
199
|
return createElement(
|
|
151
200
|
FrameControlsContext.Provider,
|
|
152
201
|
{ value: frameControls },
|
|
153
|
-
createElement(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
createElement(
|
|
157
|
-
NovaRenderProvider,
|
|
158
|
-
{
|
|
159
|
-
registry,
|
|
160
|
-
// the frame is chrome — app events flow only from inside a canvas
|
|
161
|
-
dispatch: () => void 0,
|
|
162
|
-
publish: (channel, payload) => api.publish(channel, payload),
|
|
163
|
-
fallback: fallback$1,
|
|
164
|
-
textWrapper: TextWrap,
|
|
165
|
-
errorMarker: ErrorMarker
|
|
166
|
-
},
|
|
167
|
-
createElement(Nav),
|
|
168
|
-
createElement(StatusLine),
|
|
169
|
-
createElement(RenderTree, { nodes: api.frame() })
|
|
170
|
-
)
|
|
171
|
-
)
|
|
202
|
+
createElement(Nav),
|
|
203
|
+
createElement(StatusLine),
|
|
204
|
+
terminalFrame(api, registry, { fallback: fallback$1, textWrapper: TextWrap, errorMarker: ErrorMarker })
|
|
172
205
|
);
|
|
173
206
|
};
|
|
174
207
|
const instance = render(createElement(Frame), {
|
|
@@ -177,10 +210,20 @@ var inkTarget = (config = {}) => (api) => {
|
|
|
177
210
|
exitOnCtrlC: true,
|
|
178
211
|
patchConsole: config.patchConsole ?? true
|
|
179
212
|
});
|
|
180
|
-
|
|
213
|
+
let destroyed = false;
|
|
214
|
+
const ended = () => {
|
|
215
|
+
if (!destroyed) config.onQuit?.();
|
|
216
|
+
};
|
|
217
|
+
void instance.waitUntilExit().then(ended, (error) => {
|
|
218
|
+
console.error("[moss/ink] the terminal ended on an error:", error);
|
|
219
|
+
ended();
|
|
220
|
+
});
|
|
181
221
|
return {
|
|
182
222
|
update: () => instance.rerender(createElement(Frame)),
|
|
183
|
-
destroy: () =>
|
|
223
|
+
destroy: () => {
|
|
224
|
+
destroyed = true;
|
|
225
|
+
instance.unmount();
|
|
226
|
+
}
|
|
184
227
|
};
|
|
185
228
|
};
|
|
186
229
|
|