trebol 0.1.1 → 0.2.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/README.md +12 -1
- package/dist/cli.js +17097 -12238
- package/dist/fonts/OFL.txt +93 -0
- package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/fonts/inter-greek.woff2 +0 -0
- package/dist/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/fonts/inter-latin.woff2 +0 -0
- package/dist/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/lib/core/boot.js +12 -8
- package/dist/lib/core/eval.js +2 -2
- package/dist/lib/core/func.d.ts +4 -0
- package/dist/lib/core/machine/checks.d.ts +1 -0
- package/dist/lib/core/machine/checks.js +250 -0
- package/dist/lib/core/machine/events.d.ts +1 -0
- package/dist/lib/core/machine/events.js +365 -0
- package/dist/lib/core/machine/running.d.ts +1 -0
- package/dist/lib/core/machine/running.js +180 -0
- package/dist/lib/core/machine/shared.d.ts +1 -0
- package/dist/lib/core/machine/shared.js +123 -0
- package/dist/lib/core/machine/snapshot.d.ts +1 -0
- package/dist/lib/core/machine/snapshot.js +244 -0
- package/dist/lib/core/machine/spec.d.ts +1 -0
- package/dist/lib/core/machine/spec.js +274 -0
- package/dist/lib/core/machine/words.d.ts +1 -0
- package/dist/lib/core/machine/words.js +98 -0
- package/dist/lib/core/machine.d.ts +1 -0
- package/dist/lib/core/machine.js +17 -0
- package/dist/lib/core/mezz.js +31 -0
- package/dist/lib/core/natives/control.js +2 -2
- package/dist/lib/core/natives/data.js +6 -1
- package/dist/lib/core/natives/series.js +59 -9
- package/dist/lib/core/natives/text.js +3 -1
- package/dist/lib/host/browser/calendar.d.ts +34 -0
- package/dist/lib/host/browser/calendar.js +268 -0
- package/dist/lib/host/browser/count.d.ts +15 -0
- package/dist/lib/host/browser/count.js +48 -0
- package/dist/lib/host/browser/dialogs.d.ts +39 -0
- package/dist/lib/host/browser/dialogs.js +443 -0
- package/dist/lib/host/browser/drag.d.ts +70 -0
- package/dist/lib/host/browser/drag.js +268 -0
- package/dist/lib/host/browser/drawings.d.ts +30 -0
- package/dist/lib/host/browser/drawings.js +176 -0
- package/dist/lib/host/browser/events.d.ts +16 -0
- package/dist/lib/host/browser/events.js +125 -0
- package/dist/lib/host/browser/faces.d.ts +35 -0
- package/dist/lib/host/browser/faces.js +131 -0
- package/dist/lib/host/browser/fields.d.ts +16 -0
- package/dist/lib/host/browser/fields.js +322 -0
- package/dist/lib/host/browser/keys.d.ts +29 -0
- package/dist/lib/host/browser/keys.js +151 -0
- package/dist/lib/host/browser/lookup.d.ts +25 -0
- package/dist/lib/host/browser/lookup.js +275 -0
- package/dist/lib/host/browser/menus.d.ts +20 -0
- package/dist/lib/host/browser/menus.js +149 -0
- package/dist/lib/host/browser/mount.d.ts +92 -0
- package/dist/lib/host/browser/mount.js +448 -0
- package/dist/lib/host/browser/orbits.d.ts +90 -0
- package/dist/lib/host/browser/orbits.js +379 -0
- package/dist/lib/host/browser/page.d.ts +13 -0
- package/dist/lib/host/browser/page.js +35 -0
- package/dist/lib/host/browser/richtext.d.ts +19 -0
- package/dist/lib/host/browser/richtext.js +379 -0
- package/dist/lib/host/browser/row-faces.d.ts +5 -0
- package/dist/lib/host/browser/row-faces.js +74 -0
- package/dist/lib/host/browser/screens.d.ts +37 -0
- package/dist/lib/host/browser/screens.js +140 -0
- package/dist/lib/host/browser/swipe.d.ts +31 -0
- package/dist/lib/host/browser/swipe.js +178 -0
- package/dist/lib/host/browser/sync.d.ts +24 -0
- package/dist/lib/host/browser/sync.js +450 -0
- package/dist/lib/host/browser/tables.d.ts +65 -0
- package/dist/lib/host/browser/tables.js +505 -0
- package/dist/lib/host/browser/times.d.ts +14 -0
- package/dist/lib/host/browser/times.js +114 -0
- package/dist/lib/host/browser/toolbars.d.ts +17 -0
- package/dist/lib/host/browser/toolbars.js +129 -0
- package/dist/lib/host/browser/trees.d.ts +20 -0
- package/dist/lib/host/browser/trees.js +235 -0
- package/dist/lib/host/browser/uploads.d.ts +29 -0
- package/dist/lib/host/browser/uploads.js +370 -0
- package/dist/lib/host/browser/widget.d.ts +13 -0
- package/dist/lib/host/browser/widget.js +105 -0
- package/dist/lib/host/browser.d.ts +25 -0
- package/dist/lib/host/browser.js +129 -3964
- package/dist/lib/host/devlog.d.ts +11 -0
- package/dist/lib/host/devlog.js +13 -0
- package/dist/lib/host/devtools/console.d.ts +9 -0
- package/dist/lib/host/devtools/console.js +104 -0
- package/dist/lib/host/devtools/faces.d.ts +25 -0
- package/dist/lib/host/devtools/faces.js +169 -0
- package/dist/lib/host/devtools/log.d.ts +3 -0
- package/dist/lib/host/devtools/log.js +32 -0
- package/dist/lib/host/devtools/machines.d.ts +34 -0
- package/dist/lib/host/devtools/machines.js +212 -0
- package/dist/lib/host/devtools/read.d.ts +13 -0
- package/dist/lib/host/devtools/read.js +52 -0
- package/dist/lib/host/devtools/state.d.ts +90 -0
- package/dist/lib/host/devtools/state.js +123 -0
- package/dist/lib/host/devtools.d.ts +19 -0
- package/dist/lib/host/devtools.js +238 -0
- package/dist/lib/host/fonts/OFL.txt +93 -0
- package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
- package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
- package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/lib/host/fonts.d.ts +11 -0
- package/dist/lib/host/fonts.js +30 -0
- package/dist/lib/host/icons.js +4 -0
- package/dist/lib/host/index.d.ts +5 -1
- package/dist/lib/host/index.js +110 -5
- package/dist/lib/host/js.d.ts +5 -0
- package/dist/lib/host/js.js +130 -0
- package/dist/lib/host/locale.d.ts +18 -0
- package/dist/lib/host/locale.js +75 -5
- package/dist/lib/host/markdown.d.ts +6 -0
- package/dist/lib/host/markdown.js +18 -0
- package/dist/lib/host/modules.d.ts +4 -0
- package/dist/lib/host/modules.js +157 -20
- package/dist/lib/host/motion.d.ts +32 -0
- package/dist/lib/host/motion.js +190 -0
- package/dist/lib/host/net.js +14 -3
- package/dist/lib/host/orbit.d.ts +121 -0
- package/dist/lib/host/orbit.js +374 -0
- package/dist/lib/host/palette.d.ts +17 -0
- package/dist/lib/host/palette.js +131 -0
- package/dist/lib/host/rows.d.ts +14 -0
- package/dist/lib/host/rows.js +29 -0
- package/dist/lib/host/scheduler.d.ts +8 -0
- package/dist/lib/host/scheduler.js +64 -36
- package/dist/lib/host/share.d.ts +31 -0
- package/dist/lib/host/share.js +134 -0
- package/dist/lib/host/theme/classic.d.ts +1 -0
- package/dist/lib/host/theme/classic.js +120 -0
- package/dist/lib/host/theme/cupertino.d.ts +1 -0
- package/dist/lib/host/theme/cupertino.js +65 -0
- package/dist/lib/host/theme/data.d.ts +1 -0
- package/dist/lib/host/theme/data.js +109 -0
- package/dist/lib/host/theme/devtools.d.ts +1 -0
- package/dist/lib/host/theme/devtools.js +166 -0
- package/dist/lib/host/theme/dialogs.d.ts +1 -0
- package/dist/lib/host/theme/dialogs.js +63 -0
- package/dist/lib/host/theme/fluent.d.ts +1 -0
- package/dist/lib/host/theme/fluent.js +64 -0
- package/dist/lib/host/theme/forms.d.ts +1 -0
- package/dist/lib/host/theme/forms.js +239 -0
- package/dist/lib/host/theme/fusion.d.ts +1 -0
- package/dist/lib/host/theme/fusion.js +66 -0
- package/dist/lib/host/theme/layout.d.ts +1 -0
- package/dist/lib/host/theme/layout.js +166 -0
- package/dist/lib/host/theme/media.d.ts +1 -0
- package/dist/lib/host/theme/media.js +106 -0
- package/dist/lib/host/theme/navigation.d.ts +1 -0
- package/dist/lib/host/theme/navigation.js +36 -0
- package/dist/lib/host/theme/panes.d.ts +1 -0
- package/dist/lib/host/theme/panes.js +99 -0
- package/dist/lib/host/theme/popups.d.ts +1 -0
- package/dist/lib/host/theme/popups.js +149 -0
- package/dist/lib/host/theme/responsive.d.ts +1 -0
- package/dist/lib/host/theme/responsive.js +103 -0
- package/dist/lib/host/theme/toasts.d.ts +1 -0
- package/dist/lib/host/theme/toasts.js +62 -0
- package/dist/lib/host/theme.js +19 -1179
- package/dist/lib/ui/dialect/events.trb +276 -0
- package/dist/lib/ui/dialect/faces.trb +135 -0
- package/dist/lib/ui/dialect/layout.trb +283 -0
- package/dist/lib/ui/dialect/palette.trb +87 -0
- package/dist/lib/ui/dialect/problems.trb +174 -0
- package/dist/lib/ui/dialect/reactions.trb +198 -0
- package/dist/lib/ui/dialect/rows.trb +208 -0
- package/dist/lib/ui/dialect/screens.trb +293 -0
- package/dist/lib/ui/dialect/steps.trb +203 -0
- package/dist/lib/ui/dialect/validation.trb +137 -0
- package/dist/lib/ui/dialect/view.trb +110 -0
- package/dist/lib/ui/dialect/walking.trb +98 -0
- package/dist/lib/ui/dialect/words.trb +70 -0
- package/dist/lib/ui/i18n.trb +23 -0
- package/dist/lib/ui/test.trb +12 -0
- package/dist/lib/ui/testing/actions.trb +421 -0
- package/dist/lib/ui/testing/faces.trb +148 -0
- package/dist/lib/ui/testing/server.trb +73 -0
- package/dist/lib/ui/ui.trb +25 -1234
- package/dist/trebol.js +4882 -1088
- package/editors/vscode/README.md +15 -0
- package/editors/vscode/language-configuration.json +28 -0
- package/editors/vscode/package.json +42 -0
- package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
- package/package.json +7 -3
- package/src/core/boot.ts +10 -7
- package/src/core/eval.ts +2 -2
- package/src/core/func.ts +4 -0
- package/src/core/machine/checks.ts +251 -0
- package/src/core/machine/events.ts +366 -0
- package/src/core/machine/running.ts +181 -0
- package/src/core/machine/shared.ts +124 -0
- package/src/core/machine/snapshot.ts +245 -0
- package/src/core/machine/spec.ts +275 -0
- package/src/core/machine/words.ts +99 -0
- package/src/core/machine.ts +20 -0
- package/src/core/mezz.ts +31 -0
- package/src/core/natives/control.ts +2 -2
- package/src/core/natives/data.ts +6 -1
- package/src/core/natives/parse.ts +1 -1
- package/src/core/natives/series.ts +55 -11
- package/src/core/natives/text.ts +2 -1
- package/src/host/browser/calendar.ts +264 -0
- package/src/host/browser/count.ts +48 -0
- package/src/host/browser/dialogs.ts +439 -0
- package/src/host/browser/drag.ts +278 -0
- package/src/host/browser/drawings.ts +178 -0
- package/src/host/browser/events.ts +117 -0
- package/src/host/browser/faces.ts +143 -0
- package/src/host/browser/fields.ts +315 -0
- package/src/host/browser/keys.ts +145 -0
- package/src/host/browser/lookup.ts +262 -0
- package/src/host/browser/menus.ts +146 -0
- package/src/host/browser/mount.ts +420 -0
- package/src/host/browser/orbits.ts +418 -0
- package/src/host/browser/page.ts +43 -0
- package/src/host/browser/richtext.ts +346 -0
- package/src/host/browser/row-faces.ts +75 -0
- package/src/host/browser/screens.ts +142 -0
- package/src/host/browser/swipe.ts +168 -0
- package/src/host/browser/sync.ts +354 -0
- package/src/host/browser/tables.ts +461 -0
- package/src/host/browser/times.ts +115 -0
- package/src/host/browser/toolbars.ts +126 -0
- package/src/host/browser/trees.ts +205 -0
- package/src/host/browser/uploads.ts +367 -0
- package/src/host/browser/widget.ts +103 -0
- package/src/host/browser.ts +128 -3747
- package/src/host/devlog.ts +16 -0
- package/src/host/devtools/console.ts +102 -0
- package/src/host/devtools/faces.ts +160 -0
- package/src/host/devtools/log.ts +34 -0
- package/src/host/devtools/machines.ts +208 -0
- package/src/host/devtools/read.ts +58 -0
- package/src/host/devtools/state.ts +148 -0
- package/src/host/devtools.ts +238 -0
- package/src/host/fonts/OFL.txt +93 -0
- package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/src/host/fonts/inter-cyrillic.woff2 +0 -0
- package/src/host/fonts/inter-greek-ext.woff2 +0 -0
- package/src/host/fonts/inter-greek.woff2 +0 -0
- package/src/host/fonts/inter-latin-ext.woff2 +0 -0
- package/src/host/fonts/inter-latin.woff2 +0 -0
- package/src/host/fonts/inter-vietnamese.woff2 +0 -0
- package/src/host/fonts.ts +40 -0
- package/src/host/icons.ts +4 -0
- package/src/host/index.ts +110 -5
- package/src/host/js.ts +127 -0
- package/src/host/locale.ts +71 -5
- package/src/host/markdown.ts +18 -0
- package/src/host/modules.ts +150 -22
- package/src/host/motion.ts +204 -0
- package/src/host/net.ts +13 -3
- package/src/host/orbit.ts +432 -0
- package/src/host/palette.ts +139 -0
- package/src/host/rows.ts +30 -0
- package/src/host/scheduler.ts +67 -36
- package/src/host/share.ts +168 -0
- package/src/host/theme/classic.ts +121 -0
- package/src/host/theme/cupertino.ts +66 -0
- package/src/host/theme/data.ts +110 -0
- package/src/host/theme/devtools.ts +167 -0
- package/src/host/theme/dialogs.ts +64 -0
- package/src/host/theme/fluent.ts +65 -0
- package/src/host/theme/forms.ts +240 -0
- package/src/host/theme/fusion.ts +67 -0
- package/src/host/theme/layout.ts +167 -0
- package/src/host/theme/media.ts +107 -0
- package/src/host/theme/navigation.ts +37 -0
- package/src/host/theme/panes.ts +100 -0
- package/src/host/theme/popups.ts +150 -0
- package/src/host/theme/responsive.ts +104 -0
- package/src/host/theme/toasts.ts +63 -0
- package/src/host/theme.ts +19 -1179
- package/src/ui/dialect/events.trb +276 -0
- package/src/ui/dialect/faces.trb +135 -0
- package/src/ui/dialect/layout.trb +283 -0
- package/src/ui/dialect/palette.trb +87 -0
- package/src/ui/dialect/problems.trb +174 -0
- package/src/ui/dialect/reactions.trb +198 -0
- package/src/ui/dialect/rows.trb +208 -0
- package/src/ui/dialect/screens.trb +293 -0
- package/src/ui/dialect/steps.trb +203 -0
- package/src/ui/dialect/validation.trb +137 -0
- package/src/ui/dialect/view.trb +110 -0
- package/src/ui/dialect/walking.trb +98 -0
- package/src/ui/dialect/words.trb +70 -0
- package/src/ui/i18n.trb +23 -0
- package/src/ui/test.trb +12 -0
- package/src/ui/testing/actions.trb +421 -0
- package/src/ui/testing/faces.trb +148 -0
- package/src/ui/testing/server.trb +73 -0
- package/src/ui/ui.trb +25 -1234
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Cell, ObjectCell } from '../core/index.ts';
|
|
2
|
+
export declare const devLog: {
|
|
3
|
+
/** The host ran a UI event function (ui-click, ui-input...) on a face. */
|
|
4
|
+
event: (_fn: string, _face: ObjectCell, _args: Cell[]) => void;
|
|
5
|
+
/** A request ended: its status, or null and why it failed. */
|
|
6
|
+
request: (_verb: string, _url: string, _status: number | null, _ms: number, _problem: string | null) => void;
|
|
7
|
+
/** A toast, an error nobody caught or a warning (a cycle of reactions). */
|
|
8
|
+
note: (_kind: "toast" | "error" | "warning", _text: string) => void;
|
|
9
|
+
/** The faces on the page were repainted. */
|
|
10
|
+
repainted: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// What the app does, told to the dev tools of trebol dev (devtools.ts). Each
|
|
2
|
+
// hook does nothing until the dev tools start and set it, so the host calls
|
|
3
|
+
// them freely: in a built page, in tests and in Node they are never set.
|
|
4
|
+
export const devLog = {
|
|
5
|
+
/** The host ran a UI event function (ui-click, ui-input...) on a face. */
|
|
6
|
+
event: (_fn, _face, _args) => { },
|
|
7
|
+
/** A request ended: its status, or null and why it failed. */
|
|
8
|
+
request: (_verb, _url, _status, _ms, _problem) => { },
|
|
9
|
+
/** A toast, an error nobody caught or a warning (a cycle of reactions). */
|
|
10
|
+
note: (_kind, _text) => { },
|
|
11
|
+
/** The faces on the page were repainted. */
|
|
12
|
+
repainted: () => { },
|
|
13
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const UNFINISHED: RegExp;
|
|
2
|
+
export declare function buildConsole(pane: HTMLElement): void;
|
|
3
|
+
export declare function fitInput(): void;
|
|
4
|
+
export declare function setInput(src: string): void;
|
|
5
|
+
export declare function consoleKey(ev: KeyboardEvent): void;
|
|
6
|
+
export declare function unfinished(src: string): boolean;
|
|
7
|
+
export declare function say(kind: 'in' | 'out' | 'value' | 'error', text: string): void;
|
|
8
|
+
/** Runs code typed in the console in the app's user context, `face` being the face picked. */
|
|
9
|
+
export declare function run(src: string): Promise<void>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// --- console -------------------------------------------------------------------------
|
|
2
|
+
import { K, load, LoadError, bindSeries, scriptStart, form, intern } from "../../core/index.js";
|
|
3
|
+
import { spawn, taskResult } from "../scheduler.js";
|
|
4
|
+
import { report } from "../index.js";
|
|
5
|
+
import { HISTORY_KEY, MAX_HISTORY, MAX_LOG, side, consoleOut, setConsoleOut, consoleIn, setConsoleIn, consoleFace, setConsoleFace, picked, history, setHistory, back, setBack, running, setRunning, el, write } from "./state.js";
|
|
6
|
+
import { moldShort } from "./read.js";
|
|
7
|
+
// Load errors that mean "the input is not finished yet" (as in the trebol console).
|
|
8
|
+
export const UNFINISHED = /: missing ([\])]|} to close (string|binary))$/;
|
|
9
|
+
export function buildConsole(pane) {
|
|
10
|
+
setConsoleOut(el('div', 'tb-dev-out'));
|
|
11
|
+
consoleOut.setAttribute('role', 'log');
|
|
12
|
+
consoleOut.setAttribute('aria-label', 'Console output');
|
|
13
|
+
setConsoleFace(el('div', 'tb-dev-face'));
|
|
14
|
+
const row = el('div', 'tb-dev-prompt');
|
|
15
|
+
setConsoleIn(el('textarea', 'tb-dev-in'));
|
|
16
|
+
consoleIn.rows = 1;
|
|
17
|
+
consoleIn.spellcheck = false;
|
|
18
|
+
consoleIn.setAttribute('aria-label', 'Trebol code to run');
|
|
19
|
+
consoleIn.placeholder = 'face/text: "Hello"';
|
|
20
|
+
consoleIn.addEventListener('keydown', consoleKey);
|
|
21
|
+
consoleIn.addEventListener('input', fitInput);
|
|
22
|
+
row.append(el('span', 'tb-dev-sign', '>>'), consoleIn);
|
|
23
|
+
row.addEventListener('click', () => consoleIn.focus());
|
|
24
|
+
pane.append(consoleOut, consoleFace, row);
|
|
25
|
+
}
|
|
26
|
+
export function fitInput() {
|
|
27
|
+
consoleIn.style.height = 'auto';
|
|
28
|
+
consoleIn.style.height = `${Math.min(consoleIn.scrollHeight, 160)}px`;
|
|
29
|
+
}
|
|
30
|
+
export function setInput(src) {
|
|
31
|
+
consoleIn.value = src;
|
|
32
|
+
fitInput();
|
|
33
|
+
consoleIn.setSelectionRange(src.length, src.length);
|
|
34
|
+
}
|
|
35
|
+
export function consoleKey(ev) {
|
|
36
|
+
const src = consoleIn.value;
|
|
37
|
+
if (ev.key === 'Enter' && !ev.shiftKey) {
|
|
38
|
+
if (src.trim() === '' || unfinished(src))
|
|
39
|
+
return;
|
|
40
|
+
ev.preventDefault();
|
|
41
|
+
setInput('');
|
|
42
|
+
setRunning(running.then(() => run(src)));
|
|
43
|
+
}
|
|
44
|
+
else if (ev.key === 'ArrowUp' && !src.slice(0, consoleIn.selectionStart).includes('\n') && back < history.length) {
|
|
45
|
+
ev.preventDefault();
|
|
46
|
+
setBack(back + 1);
|
|
47
|
+
setInput(history[history.length - back]);
|
|
48
|
+
}
|
|
49
|
+
else if (ev.key === 'ArrowDown' && !src.slice(consoleIn.selectionEnd).includes('\n') && back > 0) {
|
|
50
|
+
ev.preventDefault();
|
|
51
|
+
setBack(back - 1);
|
|
52
|
+
setInput(back === 0 ? '' : history[history.length - back]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function unfinished(src) {
|
|
56
|
+
try {
|
|
57
|
+
load(src);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
return e instanceof LoadError && UNFINISHED.test(e.message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function say(kind, text) {
|
|
65
|
+
const line = el('pre', `tb-dev-said-${kind}`, text);
|
|
66
|
+
const end = consoleOut.scrollTop + consoleOut.clientHeight >= consoleOut.scrollHeight - 4;
|
|
67
|
+
consoleOut.append(line);
|
|
68
|
+
while (consoleOut.childElementCount > MAX_LOG)
|
|
69
|
+
consoleOut.firstElementChild.remove();
|
|
70
|
+
if (end)
|
|
71
|
+
consoleOut.scrollTop = consoleOut.scrollHeight;
|
|
72
|
+
}
|
|
73
|
+
/** Runs code typed in the console in the app's user context, `face` being the face picked. */
|
|
74
|
+
export async function run(src) {
|
|
75
|
+
setBack(0);
|
|
76
|
+
if (history[history.length - 1] !== src)
|
|
77
|
+
history.push(src);
|
|
78
|
+
setHistory(history.slice(-MAX_HISTORY));
|
|
79
|
+
write(() => localStorage, HISTORY_KEY, { lines: history });
|
|
80
|
+
say('in', src.split('\n').map((l, i) => (i === 0 ? '>> ' : ' ') + l).join('\n'));
|
|
81
|
+
consoleOut.scrollTop = consoleOut.scrollHeight;
|
|
82
|
+
let code;
|
|
83
|
+
try {
|
|
84
|
+
code = load(src);
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
say('error', `** Syntax error: ${e.message}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const rt = side.host.rt;
|
|
91
|
+
bindSeries(code.s, rt.user, true);
|
|
92
|
+
if (picked !== null)
|
|
93
|
+
bindSeries(code.s, { keys: [intern('face')], vals: [picked], parent: null });
|
|
94
|
+
try {
|
|
95
|
+
const v = await taskResult(spawn(side.host.sch, code.s, scriptStart(code).start));
|
|
96
|
+
if (v.t === K.Error)
|
|
97
|
+
say('error', form(v));
|
|
98
|
+
else if (v.t !== K.Unset)
|
|
99
|
+
say('value', `== ${moldShort(v)}`);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
say('error', report(e));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ObjectCell, type Ctx } from '../../core/index.ts';
|
|
2
|
+
export declare const faceKeys: WeakMap<Ctx, number>;
|
|
3
|
+
export declare let nextKey: number;
|
|
4
|
+
export declare function faceKey(face: ObjectCell): number;
|
|
5
|
+
export declare function buildFaces(pane: HTMLElement): void;
|
|
6
|
+
/** The faces on the page, in the order of their nodes, with how deep each is. */
|
|
7
|
+
export declare function facesOnPage(): {
|
|
8
|
+
face: ObjectCell;
|
|
9
|
+
el: Element;
|
|
10
|
+
depth: number;
|
|
11
|
+
}[];
|
|
12
|
+
export declare function drawTree(): void;
|
|
13
|
+
export declare function drawDetail(): void;
|
|
14
|
+
export declare function pick(face: ObjectCell | null): void;
|
|
15
|
+
/** Draws the outline around a face, or hides it. */
|
|
16
|
+
export declare function point(face: ObjectCell | null): void;
|
|
17
|
+
export declare function placeOutline(): void;
|
|
18
|
+
export declare function setPicking(on: boolean): void;
|
|
19
|
+
export declare function pickTarget(ev: Event): {
|
|
20
|
+
face: ObjectCell;
|
|
21
|
+
el: HTMLElement;
|
|
22
|
+
} | null;
|
|
23
|
+
export declare function pickMove(ev: PointerEvent): void;
|
|
24
|
+
export declare function pickDown(ev: PointerEvent): void;
|
|
25
|
+
export declare function pickClick(ev: MouseEvent): void;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// --- faces ---------------------------------------------------------------------------
|
|
2
|
+
import { K, form } from "../../core/index.js";
|
|
3
|
+
import { side, state, panel, opener, outline, pickButton, tree, setTree, detail, setDetail, picked, setPicked, pointed, setPointed, picking, storePicking, el, button } from "./state.js";
|
|
4
|
+
import { get, faceRef, on, moldShort, placeOf } from "./read.js";
|
|
5
|
+
import { inDevtools, openTab, refresh } from "../devtools.js";
|
|
6
|
+
export const faceKeys = new WeakMap();
|
|
7
|
+
export let nextKey = 1;
|
|
8
|
+
export function faceKey(face) {
|
|
9
|
+
let k = faceKeys.get(face.ctx);
|
|
10
|
+
if (k === undefined)
|
|
11
|
+
faceKeys.set(face.ctx, k = nextKey++);
|
|
12
|
+
return k;
|
|
13
|
+
}
|
|
14
|
+
export function buildFaces(pane) {
|
|
15
|
+
setTree(el('div', 'tb-dev-tree'));
|
|
16
|
+
tree.setAttribute('aria-label', 'Faces on the page');
|
|
17
|
+
tree.addEventListener('pointerleave', () => point(null));
|
|
18
|
+
setDetail(el('div', 'tb-dev-detail'));
|
|
19
|
+
pane.append(tree, detail);
|
|
20
|
+
}
|
|
21
|
+
/** The faces on the page, in the order of their nodes, with how deep each is. */
|
|
22
|
+
export function facesOnPage() {
|
|
23
|
+
const out = [];
|
|
24
|
+
const walk = (e, depth) => {
|
|
25
|
+
for (const c of Array.from(e.children)) {
|
|
26
|
+
if (c === panel || c === opener || c === outline)
|
|
27
|
+
continue;
|
|
28
|
+
const f = side.faceOf(c);
|
|
29
|
+
if (f !== null)
|
|
30
|
+
out.push({ face: f, el: c, depth });
|
|
31
|
+
walk(c, f !== null ? depth + 1 : depth);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
walk(document.body, 0);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
export function drawTree() {
|
|
38
|
+
const top = tree.scrollTop;
|
|
39
|
+
tree.replaceChildren();
|
|
40
|
+
for (const { face, el: node, depth } of facesOnPage()) {
|
|
41
|
+
const row = button('tb-dev-node', faceRef(face, side.host.rt), () => pick(face));
|
|
42
|
+
row.style.paddingLeft = `${8 + depth * 14}px`;
|
|
43
|
+
if (face.ctx === picked?.ctx)
|
|
44
|
+
row.setAttribute('aria-current', 'true');
|
|
45
|
+
if (node.offsetParent === null && getComputedStyle(node).position !== 'fixed')
|
|
46
|
+
row.classList.add('tb-dev-unseen');
|
|
47
|
+
row.addEventListener('pointerenter', () => point(face));
|
|
48
|
+
tree.append(row);
|
|
49
|
+
}
|
|
50
|
+
tree.scrollTop = top;
|
|
51
|
+
}
|
|
52
|
+
export function drawDetail() {
|
|
53
|
+
detail.replaceChildren();
|
|
54
|
+
if (picked === null) {
|
|
55
|
+
detail.append(el('p', 'tb-dev-hint', 'Pick a face on the page, or choose one in the tree.'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const f = picked;
|
|
59
|
+
const title = el('h3', undefined, faceRef(f, side.host.rt));
|
|
60
|
+
detail.append(title);
|
|
61
|
+
const where = placeOf(f);
|
|
62
|
+
if (where !== null) {
|
|
63
|
+
const p = el('p', 'tb-dev-place');
|
|
64
|
+
if (where.href !== null) {
|
|
65
|
+
const a = el('a', undefined, where.text);
|
|
66
|
+
a.href = where.href;
|
|
67
|
+
a.title = 'Open in VS Code';
|
|
68
|
+
p.append(a);
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
p.textContent = where.text;
|
|
72
|
+
detail.append(p);
|
|
73
|
+
}
|
|
74
|
+
if (side.nodeOf(f) === null)
|
|
75
|
+
detail.append(el('p', 'tb-dev-hint', 'Not on the page any more.'));
|
|
76
|
+
const dl = el('dl');
|
|
77
|
+
const row = (k, v) => {
|
|
78
|
+
dl.append(el('dt', undefined, k), el('dd', undefined, v));
|
|
79
|
+
};
|
|
80
|
+
for (const n of ['style', 'name', 'text', 'value', 'error', 'rules', 'hint', 'role']) {
|
|
81
|
+
const v = get(f, n);
|
|
82
|
+
if (v.t !== K.None)
|
|
83
|
+
row(n, moldShort(v, 400));
|
|
84
|
+
}
|
|
85
|
+
const events = [];
|
|
86
|
+
if (get(f, 'action').t === K.Block)
|
|
87
|
+
events.push('action');
|
|
88
|
+
const ev = get(f, 'events');
|
|
89
|
+
if (ev.t === K.Block) {
|
|
90
|
+
for (const c of ev.s.data.slice(ev.i))
|
|
91
|
+
if (c.t !== K.Block)
|
|
92
|
+
events.push(form(c));
|
|
93
|
+
}
|
|
94
|
+
if (events.length > 0)
|
|
95
|
+
row('events', events.join(' '));
|
|
96
|
+
const flags = ['required', 'disabled', 'hidden', 'readonly'].filter(n => on(f, n));
|
|
97
|
+
if (flags.length > 0)
|
|
98
|
+
row('flags', flags.join(' '));
|
|
99
|
+
const data = get(f, 'data');
|
|
100
|
+
if (data.t === K.Block)
|
|
101
|
+
row('rows', String(data.s.data.length - data.i));
|
|
102
|
+
detail.append(dl);
|
|
103
|
+
}
|
|
104
|
+
export function pick(face) {
|
|
105
|
+
setPicked(face);
|
|
106
|
+
point(null);
|
|
107
|
+
refresh();
|
|
108
|
+
}
|
|
109
|
+
/** Draws the outline around a face, or hides it. */
|
|
110
|
+
export function point(face) {
|
|
111
|
+
setPointed(face);
|
|
112
|
+
placeOutline();
|
|
113
|
+
}
|
|
114
|
+
export function placeOutline() {
|
|
115
|
+
const face = pointed ?? (state.open && state.tab === 'faces' ? picked : null);
|
|
116
|
+
const node = face !== null ? side.nodeOf(face) : null;
|
|
117
|
+
const r = node?.getBoundingClientRect();
|
|
118
|
+
if (r === undefined || (r.width === 0 && r.height === 0)) {
|
|
119
|
+
if (outline.matches(':popover-open'))
|
|
120
|
+
outline.hidePopover();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
Object.assign(outline.style, { left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` });
|
|
124
|
+
outline.classList.toggle('tb-dev-pointed', pointed !== null);
|
|
125
|
+
// shown again so it stays above a dialog opened since
|
|
126
|
+
if (outline.matches(':popover-open'))
|
|
127
|
+
outline.hidePopover();
|
|
128
|
+
outline.showPopover();
|
|
129
|
+
}
|
|
130
|
+
export function setPicking(on) {
|
|
131
|
+
storePicking(on);
|
|
132
|
+
pickButton.setAttribute('aria-pressed', String(on));
|
|
133
|
+
document.documentElement.classList.toggle('tb-dev-picking', on);
|
|
134
|
+
if (on)
|
|
135
|
+
openTab('faces');
|
|
136
|
+
else
|
|
137
|
+
point(null);
|
|
138
|
+
}
|
|
139
|
+
export function pickTarget(ev) {
|
|
140
|
+
const t = ev.target;
|
|
141
|
+
if (!(t instanceof Element) || inDevtools(t) || t === opener)
|
|
142
|
+
return null;
|
|
143
|
+
return side.faceAt(t);
|
|
144
|
+
}
|
|
145
|
+
export function pickMove(ev) {
|
|
146
|
+
if (!picking)
|
|
147
|
+
return;
|
|
148
|
+
const at = pickTarget(ev);
|
|
149
|
+
if (at !== null)
|
|
150
|
+
point(at.face);
|
|
151
|
+
}
|
|
152
|
+
export function pickDown(ev) {
|
|
153
|
+
if (!picking || pickTarget(ev) === null)
|
|
154
|
+
return;
|
|
155
|
+
// the face does not get the press: no focus, no drag
|
|
156
|
+
ev.preventDefault();
|
|
157
|
+
ev.stopImmediatePropagation();
|
|
158
|
+
}
|
|
159
|
+
export function pickClick(ev) {
|
|
160
|
+
if (!picking)
|
|
161
|
+
return;
|
|
162
|
+
const at = pickTarget(ev);
|
|
163
|
+
if (at === null)
|
|
164
|
+
return;
|
|
165
|
+
ev.preventDefault();
|
|
166
|
+
ev.stopImmediatePropagation();
|
|
167
|
+
setPicking(false);
|
|
168
|
+
pick(at.face);
|
|
169
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// --- log -----------------------------------------------------------------------------
|
|
2
|
+
import { MAX_LOG, logList, setLogList, lastLog, setLastLog, el, button } from "./state.js";
|
|
3
|
+
export function buildLog(pane) {
|
|
4
|
+
const bar = el('div', 'tb-dev-bar');
|
|
5
|
+
bar.append(button('tb-dev-button', 'Clear', () => {
|
|
6
|
+
logList.replaceChildren();
|
|
7
|
+
setLastLog(null);
|
|
8
|
+
}));
|
|
9
|
+
setLogList(el('ol', 'tb-dev-entries'));
|
|
10
|
+
logList.setAttribute('aria-label', 'What the app did');
|
|
11
|
+
pane.append(bar, logList);
|
|
12
|
+
}
|
|
13
|
+
/** Adds a line to the log; the same one again (typing in a field) counts instead of adding. */
|
|
14
|
+
export function log(kind, text, key) {
|
|
15
|
+
if (key !== undefined && lastLog?.key === key && lastLog.li.isConnected) {
|
|
16
|
+
lastLog.count++;
|
|
17
|
+
lastLog.text.textContent = `${text} (×${lastLog.count})`;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const li = el('li', `tb-dev-${kind}`);
|
|
21
|
+
const now = new Date();
|
|
22
|
+
const time = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
|
|
23
|
+
const t = el('span', 'tb-dev-text', text);
|
|
24
|
+
li.append(el('time', undefined, time), el('span', 'tb-dev-kind', kind), t);
|
|
25
|
+
const end = logList.scrollTop + logList.clientHeight >= logList.scrollHeight - 4;
|
|
26
|
+
logList.append(li);
|
|
27
|
+
while (logList.childElementCount > MAX_LOG)
|
|
28
|
+
logList.firstElementChild.remove();
|
|
29
|
+
if (end)
|
|
30
|
+
logList.scrollTop = logList.scrollHeight;
|
|
31
|
+
setLastLog(key !== undefined ? { key, li, text: t, count: 1 } : null);
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Cell, type ObjectCell, type Ctx } from '../../core/index.ts';
|
|
2
|
+
/** A machine the program holds: the word (or object/field) it is in. */
|
|
3
|
+
export interface Found {
|
|
4
|
+
name: string;
|
|
5
|
+
m: ObjectCell;
|
|
6
|
+
}
|
|
7
|
+
export declare let machineList: HTMLElement;
|
|
8
|
+
export declare let machineDetail: HTMLElement;
|
|
9
|
+
/** The machine chosen, by its context, and the state chosen in it (its key as mold gives it). */
|
|
10
|
+
export declare let chosen: {
|
|
11
|
+
ctx: Ctx;
|
|
12
|
+
state: string | null;
|
|
13
|
+
} | null;
|
|
14
|
+
/** What each machine's state was at the last repaint, for the log. */
|
|
15
|
+
export declare const seenState: WeakMap<Ctx, string>;
|
|
16
|
+
export declare let drawing: number;
|
|
17
|
+
export declare function buildMachines(pane: HTMLElement): void;
|
|
18
|
+
export declare function field(o: ObjectCell, name: string): Cell | null;
|
|
19
|
+
export declare function isMachine(v: Cell): v is ObjectCell;
|
|
20
|
+
/** The machines in the words of the program, and in the fields of the objects in them; no others. */
|
|
21
|
+
export declare function findMachines(): Found[];
|
|
22
|
+
/** A line in the log for each machine whose state changed since the last repaint. */
|
|
23
|
+
export declare function noteMachines(): void;
|
|
24
|
+
/** The value after a word in a block of plain data, as graph-of gives it. */
|
|
25
|
+
export declare function pickKey(b: Cell | null, key: string): Cell | null;
|
|
26
|
+
export declare function pairs(b: Cell | null): [Cell, Cell][];
|
|
27
|
+
/** The values of a block or a path. */
|
|
28
|
+
export declare function items(b: Cell | null): Cell[];
|
|
29
|
+
export declare function truthy(v: Cell | null): boolean;
|
|
30
|
+
export declare function graphOf(m: ObjectCell): Promise<Cell>;
|
|
31
|
+
/** A way as one line: `on start → work`, with where and set when it has them. */
|
|
32
|
+
export declare function wayText(w: Cell): string;
|
|
33
|
+
export declare function drawMachines(): Promise<void>;
|
|
34
|
+
export declare function drawMachine(f: Found, g: Cell): void;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// --- machines ------------------------------------------------------------------------
|
|
2
|
+
import { K, NONE, mold, form, ctxFind, intern, spell } from "../../core/index.js";
|
|
3
|
+
import { spawn, taskResult } from "../scheduler.js";
|
|
4
|
+
import { side, el, button } from "./state.js";
|
|
5
|
+
import { wordText, short, moldShort } from "./read.js";
|
|
6
|
+
import { log } from "./log.js";
|
|
7
|
+
export let machineList;
|
|
8
|
+
export let machineDetail;
|
|
9
|
+
/** The machine chosen, by its context, and the state chosen in it (its key as mold gives it). */
|
|
10
|
+
export let chosen = null;
|
|
11
|
+
/** What each machine's state was at the last repaint, for the log. */
|
|
12
|
+
export const seenState = new WeakMap();
|
|
13
|
+
export let drawing = 0;
|
|
14
|
+
export function buildMachines(pane) {
|
|
15
|
+
machineList = el('div', 'tb-dev-tree');
|
|
16
|
+
machineList.setAttribute('aria-label', 'Machines and their states');
|
|
17
|
+
machineDetail = el('div', 'tb-dev-detail');
|
|
18
|
+
pane.append(machineList, machineDetail);
|
|
19
|
+
}
|
|
20
|
+
export function field(o, name) {
|
|
21
|
+
const i = ctxFind(o.ctx, intern(name));
|
|
22
|
+
return i < 0 ? null : o.ctx.vals[i];
|
|
23
|
+
}
|
|
24
|
+
export function isMachine(v) {
|
|
25
|
+
return v.t === K.Object && field(v, 'nodes') !== null && field(v, 'queue') !== null
|
|
26
|
+
&& field(v, 'scope') !== null && field(v, 'state') !== null;
|
|
27
|
+
}
|
|
28
|
+
/** The machines in the words of the program, and in the fields of the objects in them; no others. */
|
|
29
|
+
export function findMachines() {
|
|
30
|
+
const out = [];
|
|
31
|
+
const seen = new Set();
|
|
32
|
+
const user = side.host.rt.user;
|
|
33
|
+
const add = (name, v) => {
|
|
34
|
+
if (!isMachine(v) || seen.has(v.ctx))
|
|
35
|
+
return;
|
|
36
|
+
seen.add(v.ctx);
|
|
37
|
+
out.push({ name, m: v });
|
|
38
|
+
};
|
|
39
|
+
user.keys.forEach((k, i) => {
|
|
40
|
+
const v = user.vals[i];
|
|
41
|
+
add(spell(k), v);
|
|
42
|
+
if (v.t === K.Object && !isMachine(v) && field(v, 'style') === null) {
|
|
43
|
+
const o = v;
|
|
44
|
+
o.ctx.keys.forEach((f, j) => add(`${spell(k)}/${spell(f)}`, o.ctx.vals[j]));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/** A line in the log for each machine whose state changed since the last repaint. */
|
|
50
|
+
export function noteMachines() {
|
|
51
|
+
for (const { name, m } of findMachines()) {
|
|
52
|
+
const now = mold(field(m, 'state') ?? NONE);
|
|
53
|
+
const was = seenState.get(m.ctx);
|
|
54
|
+
seenState.set(m.ctx, now);
|
|
55
|
+
if (was !== undefined && was !== now)
|
|
56
|
+
log('machine', `${name}: ${was} → ${now}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** The value after a word in a block of plain data, as graph-of gives it. */
|
|
60
|
+
export function pickKey(b, key) {
|
|
61
|
+
if (b === null || b.t !== K.Block)
|
|
62
|
+
return null;
|
|
63
|
+
const d = b.s.data.slice(b.i);
|
|
64
|
+
for (let i = 0; i + 1 < d.length; i += 2)
|
|
65
|
+
if (wordText(d[i]) === key)
|
|
66
|
+
return d[i + 1];
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
export function pairs(b) {
|
|
70
|
+
if (b === null || b.t !== K.Block)
|
|
71
|
+
return [];
|
|
72
|
+
const d = b.s.data.slice(b.i);
|
|
73
|
+
const out = [];
|
|
74
|
+
for (let i = 0; i + 1 < d.length; i += 2)
|
|
75
|
+
out.push([d[i], d[i + 1]]);
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** The values of a block or a path. */
|
|
79
|
+
export function items(b) {
|
|
80
|
+
return b === null || (b.t !== K.Block && b.t !== K.Path) ? [] : b.s.data.slice(b.i);
|
|
81
|
+
}
|
|
82
|
+
export function truthy(v) {
|
|
83
|
+
return v !== null && !(v.t === K.None || (v.t === K.Logic && !v.v));
|
|
84
|
+
}
|
|
85
|
+
export async function graphOf(m) {
|
|
86
|
+
const fn = { t: K.Word, sym: intern('graph-of'), bind: side.host.rt.lib };
|
|
87
|
+
return taskResult(spawn(side.host.sch, { data: [fn, m] }, 0));
|
|
88
|
+
}
|
|
89
|
+
/** A way as one line: `on start → work`, with where and set when it has them. */
|
|
90
|
+
export function wayText(w) {
|
|
91
|
+
const on = pickKey(w, 'on');
|
|
92
|
+
const ev = on !== null && on.t === K.Block ? items(on).map(form).join(' ') : null;
|
|
93
|
+
const to = pickKey(w, 'to');
|
|
94
|
+
const parts = [];
|
|
95
|
+
if (ev !== null)
|
|
96
|
+
parts.push(`on ${ev}`);
|
|
97
|
+
if (to !== null)
|
|
98
|
+
parts.push(`→ ${mold(to)}`);
|
|
99
|
+
else {
|
|
100
|
+
const branches = items(pickKey(w, 'branches')).map(b => `${wordText(items(b)[0]) === 'else' ? 'else ' : ''}${mold(pickKey(b, 'to') ?? NONE)}`);
|
|
101
|
+
parts.push(`→ ${wordText(items(w)[2]) ?? 'choose'} [${branches.join(' | ')}]`);
|
|
102
|
+
}
|
|
103
|
+
const where = pickKey(w, 'where');
|
|
104
|
+
if (truthy(where))
|
|
105
|
+
parts.push(`where ${short(mold(where), 40)}`);
|
|
106
|
+
const set = pickKey(w, 'set');
|
|
107
|
+
if (truthy(set))
|
|
108
|
+
parts.push(`set ${short(mold(set), 40)}`);
|
|
109
|
+
if (ev === null)
|
|
110
|
+
parts.unshift('at once');
|
|
111
|
+
return parts.join(' ');
|
|
112
|
+
}
|
|
113
|
+
export async function drawMachines() {
|
|
114
|
+
const ticket = ++drawing;
|
|
115
|
+
const found = findMachines();
|
|
116
|
+
const graphs = [];
|
|
117
|
+
for (const f of found) {
|
|
118
|
+
try {
|
|
119
|
+
graphs.push(await graphOf(f.m));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
graphs.push(NONE);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (ticket !== drawing)
|
|
126
|
+
return;
|
|
127
|
+
const top = machineList.scrollTop;
|
|
128
|
+
machineList.replaceChildren();
|
|
129
|
+
machineDetail.replaceChildren();
|
|
130
|
+
if (found.length === 0) {
|
|
131
|
+
machineList.append(el('p', 'tb-dev-hint', 'No machine in the words of the program.'));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (chosen === null || !found.some(f => f.m.ctx === chosen.ctx))
|
|
135
|
+
chosen = { ctx: found[0].m.ctx, state: null };
|
|
136
|
+
found.forEach((f, i) => {
|
|
137
|
+
const g = graphs[i];
|
|
138
|
+
const head = button('tb-dev-node tb-dev-machine-head', `${f.name} ${mold(field(f.m, 'state') ?? NONE)}`, () => {
|
|
139
|
+
chosen = { ctx: f.m.ctx, state: null };
|
|
140
|
+
void drawMachines();
|
|
141
|
+
});
|
|
142
|
+
if (chosen.ctx === f.m.ctx && chosen.state === null)
|
|
143
|
+
head.setAttribute('aria-current', 'true');
|
|
144
|
+
machineList.append(head);
|
|
145
|
+
for (const [key, info] of pairs(pickKey(g, 'states'))) {
|
|
146
|
+
const k = mold(key);
|
|
147
|
+
const depth = key.t === K.Path ? items(key).length : 1;
|
|
148
|
+
const name = key.t === K.Path ? form(items(key).at(-1)) : form(key);
|
|
149
|
+
const kind = wordText(pickKey(info, 'kind') ?? NONE);
|
|
150
|
+
const marks = [
|
|
151
|
+
truthy(pickKey(info, 'initial')) ? '›' : ' ',
|
|
152
|
+
kind === 'final' ? '(final)' : kind === 'parallel' ? '(parallel)' : '',
|
|
153
|
+
];
|
|
154
|
+
const row = button('tb-dev-node', `${marks[0]} ${name} ${marks[1]}`.trimEnd(), () => {
|
|
155
|
+
chosen = { ctx: f.m.ctx, state: k };
|
|
156
|
+
void drawMachines();
|
|
157
|
+
});
|
|
158
|
+
row.style.paddingLeft = `${8 + depth * 14}px`;
|
|
159
|
+
if (truthy(pickKey(info, 'on')))
|
|
160
|
+
row.classList.add('tb-dev-on');
|
|
161
|
+
if (chosen.ctx === f.m.ctx && chosen.state === k)
|
|
162
|
+
row.setAttribute('aria-current', 'true');
|
|
163
|
+
machineList.append(row);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
machineList.scrollTop = top;
|
|
167
|
+
const at = found.findIndex(f => f.m.ctx === chosen.ctx);
|
|
168
|
+
drawMachine(found[at], graphs[at]);
|
|
169
|
+
}
|
|
170
|
+
export function drawMachine(f, g) {
|
|
171
|
+
const d = machineDetail;
|
|
172
|
+
d.append(el('h3', undefined, chosen.state === null ? f.name : `${f.name} · ${chosen.state}`));
|
|
173
|
+
const dl = el('dl');
|
|
174
|
+
const row = (k, v) => {
|
|
175
|
+
dl.append(el('dt', undefined, k), el('dd', undefined, v));
|
|
176
|
+
};
|
|
177
|
+
const states = pairs(pickKey(g, 'states'));
|
|
178
|
+
const on = new Set(states.filter(([, info]) => truthy(pickKey(info, 'on'))).map(([k]) => mold(k)));
|
|
179
|
+
const ways = items(pickKey(g, 'ways'));
|
|
180
|
+
row('state', mold(field(f.m, 'state') ?? NONE));
|
|
181
|
+
const data = field(f.m, 'data');
|
|
182
|
+
if (data !== null && data.t === K.Object) {
|
|
183
|
+
const o = data;
|
|
184
|
+
row('data', o.ctx.keys.map((k, i) => `${spell(k)}: ${moldShort(o.ctx.vals[i], 200)}`).join('\n') || '(none)');
|
|
185
|
+
}
|
|
186
|
+
// what can? says yes to: the events of the ways out of the states it is in
|
|
187
|
+
const now = new Set();
|
|
188
|
+
for (const w of ways) {
|
|
189
|
+
const from = pickKey(w, 'from');
|
|
190
|
+
if (from !== null && on.has(mold(from)))
|
|
191
|
+
for (const e of items(pickKey(w, 'on')))
|
|
192
|
+
now.add(form(e));
|
|
193
|
+
}
|
|
194
|
+
row('takes now', now.size > 0 ? [...now].join(' ') : '(nothing)');
|
|
195
|
+
if (truthy(field(f.m, 'done')))
|
|
196
|
+
row('done', mold(field(f.m, 'outcome') ?? NONE));
|
|
197
|
+
if (chosen.state !== null) {
|
|
198
|
+
const info = states.find(([k]) => mold(k) === chosen.state)?.[1] ?? null;
|
|
199
|
+
for (const n of ['kind', 'timeout', 'outcome', 'invoke', 'for', 'defer']) {
|
|
200
|
+
const v = pickKey(info, n);
|
|
201
|
+
if (v !== null && truthy(v) && !(v.t === K.Block && items(v).length === 0))
|
|
202
|
+
row(n, n === 'invoke' && v.t === K.Block ? 'a machine of its own' : moldShort(v, 200));
|
|
203
|
+
}
|
|
204
|
+
if (truthy(pickKey(info, 'run')))
|
|
205
|
+
row('run', moldShort(pickKey(info, 'run'), 200));
|
|
206
|
+
}
|
|
207
|
+
const mine = ways.filter(w => chosen.state === null || mold(pickKey(w, 'from') ?? NONE) === chosen.state);
|
|
208
|
+
if (mine.length > 0) {
|
|
209
|
+
row('ways', mine.map(w => (chosen.state === null ? `${mold(pickKey(w, 'from') ?? NONE)} ` : '') + wayText(w)).join('\n'));
|
|
210
|
+
}
|
|
211
|
+
d.append(dl);
|
|
212
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Cell, type ObjectCell, type Runtime } from '../../core/index.ts';
|
|
2
|
+
export declare function get(face: ObjectCell, name: string): Cell;
|
|
3
|
+
export declare function wordText(v: Cell): string | null;
|
|
4
|
+
export declare function short(s: string, most?: number): string;
|
|
5
|
+
/** How a face is named in the tree, the log and errors: its style, name and text (`field email "Email"`). */
|
|
6
|
+
export declare function faceRef(face: ObjectCell, rt: Runtime): string;
|
|
7
|
+
export declare function on(face: ObjectCell, name: string): boolean;
|
|
8
|
+
export declare function moldShort(v: Cell, most?: number): string;
|
|
9
|
+
/** A face's file:line:col and a vscode:// link to it, when the file is in the folder trebol dev serves. */
|
|
10
|
+
export declare function placeOf(face: ObjectCell): {
|
|
11
|
+
text: string;
|
|
12
|
+
href: string | null;
|
|
13
|
+
} | null;
|