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,448 @@
|
|
|
1
|
+
// --- mounting ----------------------------------------------------------------------
|
|
2
|
+
import { K, NONE, string, ctxFind, intern, spell } from "../../core/index.js";
|
|
3
|
+
import { report } from "../index.js";
|
|
4
|
+
import { spawn, taskResult } from "../scheduler.js";
|
|
5
|
+
import { linkHref } from "../markdown.js";
|
|
6
|
+
import { devLog } from "../devlog.js";
|
|
7
|
+
import { faceRef } from "../devtools.js";
|
|
8
|
+
import { get, str, flag, word, children, iconName, icon } from "./faces.js";
|
|
9
|
+
import { listen } from "./events.js";
|
|
10
|
+
import { buildInput, buildCheck, buildSlider, buildRadio, buildProgress } from "./fields.js";
|
|
11
|
+
import { buildUpload, buildPhoto } from "./uploads.js";
|
|
12
|
+
import { buildWidget } from "./widget.js";
|
|
13
|
+
import { buildLookup } from "./lookup.js";
|
|
14
|
+
import { buildCanvas, buildChart } from "./drawings.js";
|
|
15
|
+
import { buildOrbit } from "./orbits.js";
|
|
16
|
+
import { buildRowsField } from "./row-faces.js";
|
|
17
|
+
import { buildRich } from "./richtext.js";
|
|
18
|
+
import { buildRows } from "./tables.js";
|
|
19
|
+
import { buildTree } from "./trees.js";
|
|
20
|
+
import { buildToolbar, buildBreadcrumb } from "./toolbars.js";
|
|
21
|
+
import { buildDialog, buildTabs, buildSteps, buildSplit } from "./dialogs.js";
|
|
22
|
+
import { sync, placeScreen } from "./sync.js";
|
|
23
|
+
import { screenHref, setScreensFace } from "./screens.js";
|
|
24
|
+
import { setTitleFace } from "./page.js";
|
|
25
|
+
export let host;
|
|
26
|
+
export function setHost(v) {
|
|
27
|
+
host = v;
|
|
28
|
+
}
|
|
29
|
+
/** Mounted faces by their node and by their input. */
|
|
30
|
+
export const byNode = new WeakMap();
|
|
31
|
+
/** The row cell each table row or list item shows. */
|
|
32
|
+
export const rowOf = new WeakMap();
|
|
33
|
+
/** Mounted faces by context; a face rebuilt in a new container replaces its entry. */
|
|
34
|
+
export const byCtx = new WeakMap();
|
|
35
|
+
/** Contexts of mounted faces written since the last repaint (filled by the core). */
|
|
36
|
+
export const dirty = [];
|
|
37
|
+
/** Mounted faces with react, is or calc; and whether one came since reactions last ran. */
|
|
38
|
+
export const reactors = new Set();
|
|
39
|
+
export let newReactor = false;
|
|
40
|
+
export function setNewReactor(v) {
|
|
41
|
+
newReactor = v;
|
|
42
|
+
}
|
|
43
|
+
/** The ui-react still running because a reaction waits (a fetch); the next one waits for it. */
|
|
44
|
+
export let reacting = null;
|
|
45
|
+
export function setReacting(v) {
|
|
46
|
+
reacting = v;
|
|
47
|
+
}
|
|
48
|
+
export let nextId = 1;
|
|
49
|
+
/** A new number for the id of an element. */
|
|
50
|
+
export function newId() {
|
|
51
|
+
return nextId++;
|
|
52
|
+
}
|
|
53
|
+
export const ACTIVE = new Set([K.Word, K.SetWord, K.GetWord, K.Paren, K.Path, K.SetPath, K.GetPath, K.Function, K.Native]);
|
|
54
|
+
/** The handler each UI event function runs, to name it in an error; the others go by their own name. */
|
|
55
|
+
export const HANDLERS = {
|
|
56
|
+
'ui-click': 'action', 'ui-input': 'on-change', 'ui-files': 'on-change', 'ui-remove-file': 'on-change',
|
|
57
|
+
'ui-lookup-pick': 'on-change', 'ui-lookup-remove': 'on-change', 'ui-lookup-search': 'on-search',
|
|
58
|
+
'ui-select': 'on-select', 'ui-sort': 'on-sort', 'ui-drop': 'on-drop', 'ui-menu': 'on-menu',
|
|
59
|
+
'ui-reorder': 'on-reorder', 'ui-expand': 'on-expand', 'ui-close': 'on-close',
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* An error of a UI event function says where in the app it happened: `action of button "Save"`, not the
|
|
63
|
+
* name of Trebol's own function (ui-click) that ran it.
|
|
64
|
+
*/
|
|
65
|
+
export function whereInApp(e, fn, face, args) {
|
|
66
|
+
const i = ctxFind(e.ctx, intern('where'));
|
|
67
|
+
const w = i < 0 ? null : e.ctx.vals[i];
|
|
68
|
+
if (w === null || w.t !== K.Word || spell(w.sym) !== fn)
|
|
69
|
+
return;
|
|
70
|
+
const ev = fn === 'ui-event' && args[0] !== undefined && args[0].t === K.LitWord ? spell(args[0].sym) : null;
|
|
71
|
+
e.ctx.vals[i] = string(`${ev ?? HANDLERS[fn] ?? fn.replace(/^ui-/, '')} of ${faceRef(face, host.rt)}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Runs a UI event function (ui-input, ui-blur, ui-click) as a new task. An error is shown and gives none, so
|
|
75
|
+
* what the caller does next (focus the first problem, blur) still runs and nothing is left unhandled.
|
|
76
|
+
*/
|
|
77
|
+
export function fire(fn, face, ...args) {
|
|
78
|
+
// a word, path or paren given as data (a dropped `date`) is quoted, so it is passed, not evaluated
|
|
79
|
+
const quote = { t: K.Word, sym: intern('quote'), bind: host.rt.lib };
|
|
80
|
+
const call = [{ t: K.Word, sym: intern(fn), bind: host.rt.lib }, face, ...args.flatMap(a => ACTIVE.has(a.t) ? [quote, a] : [a])];
|
|
81
|
+
devLog.event(fn, face, args);
|
|
82
|
+
return taskResult(spawn(host.sch, { data: call }, 0)).catch((e) => {
|
|
83
|
+
if (e.t === K.Error)
|
|
84
|
+
whereInApp(e, fn, face, args);
|
|
85
|
+
showError(report(e));
|
|
86
|
+
return NONE;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** The panel of errors trebol dev shows on the page; null until the first one. */
|
|
90
|
+
export let devErrors = null;
|
|
91
|
+
/**
|
|
92
|
+
* An error nobody caught: in the console and, when trebol dev serves the page (it adds
|
|
93
|
+
* `<meta name="trebol-dev">`), also on the page, so a broken app is not a blank page.
|
|
94
|
+
*/
|
|
95
|
+
export function showError(message) {
|
|
96
|
+
console.error(message);
|
|
97
|
+
devLog.note('error', message);
|
|
98
|
+
if (document.querySelector('meta[name="trebol-dev"]') === null)
|
|
99
|
+
return;
|
|
100
|
+
if (devErrors === null || !devErrors.isConnected) {
|
|
101
|
+
// a manual popover sits in the top layer, above open dialogs
|
|
102
|
+
const panel = el('section', 'tb-dev-errors');
|
|
103
|
+
panel.popover = 'manual';
|
|
104
|
+
panel.setAttribute('role', 'alert');
|
|
105
|
+
panel.setAttribute('aria-label', 'Trebol error');
|
|
106
|
+
const head = el('header');
|
|
107
|
+
const title = el('span');
|
|
108
|
+
title.textContent = 'Trebol error';
|
|
109
|
+
const close = el('button', 'tb-button');
|
|
110
|
+
close.type = 'button';
|
|
111
|
+
close.textContent = 'Close';
|
|
112
|
+
close.addEventListener('click', () => panel.remove());
|
|
113
|
+
panel.addEventListener('keydown', ev => { if (ev.key === 'Escape')
|
|
114
|
+
panel.remove(); });
|
|
115
|
+
head.append(title, close);
|
|
116
|
+
panel.append(head);
|
|
117
|
+
document.body.append(panel);
|
|
118
|
+
panel.showPopover();
|
|
119
|
+
devErrors = panel;
|
|
120
|
+
}
|
|
121
|
+
const pre = el('pre');
|
|
122
|
+
pre.textContent = message;
|
|
123
|
+
devErrors.append(pre);
|
|
124
|
+
}
|
|
125
|
+
export function el(tag, cls) {
|
|
126
|
+
const e = document.createElement(tag);
|
|
127
|
+
if (cls)
|
|
128
|
+
e.className = cls;
|
|
129
|
+
return e;
|
|
130
|
+
}
|
|
131
|
+
export const INPUTS = new Set(['field', 'password', 'number', 'money', 'date', 'date-range', 'time', 'area', 'choice']);
|
|
132
|
+
export function build(face) {
|
|
133
|
+
const style = word(face, 'style') ?? 'face';
|
|
134
|
+
const m = {
|
|
135
|
+
face, el: null, input: null, label: null, error: null, kids: get(face, 'pane'),
|
|
136
|
+
box: null, rows: null, empty: null, button: null, radios: null, open: null, shown: undefined,
|
|
137
|
+
typing: 0, typed: null, items: [], first: 0, end: 0, rowHeight: 0,
|
|
138
|
+
};
|
|
139
|
+
let node;
|
|
140
|
+
if (INPUTS.has(style)) {
|
|
141
|
+
node = buildInput(face, style, m);
|
|
142
|
+
}
|
|
143
|
+
else if (style === 'check' || style === 'toggle') {
|
|
144
|
+
node = buildCheck(face, m, style === 'toggle');
|
|
145
|
+
}
|
|
146
|
+
else if (style === 'radio') {
|
|
147
|
+
node = buildRadio(face, m);
|
|
148
|
+
}
|
|
149
|
+
else if (style === 'slider') {
|
|
150
|
+
node = buildSlider(face, m);
|
|
151
|
+
}
|
|
152
|
+
else if (style === 'upload') {
|
|
153
|
+
node = buildUpload(face, m);
|
|
154
|
+
}
|
|
155
|
+
else if (style === 'photo') {
|
|
156
|
+
node = buildPhoto(face, m);
|
|
157
|
+
}
|
|
158
|
+
else if (style === 'widget') {
|
|
159
|
+
node = buildWidget(face, m);
|
|
160
|
+
}
|
|
161
|
+
else if (style === 'lookup') {
|
|
162
|
+
node = buildLookup(face, m);
|
|
163
|
+
}
|
|
164
|
+
else if (style === 'rich') {
|
|
165
|
+
node = buildRich(face, m);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
switch (style) {
|
|
169
|
+
case 'view':
|
|
170
|
+
node = el('main', 'tb-view');
|
|
171
|
+
break;
|
|
172
|
+
case 'column':
|
|
173
|
+
node = el('div', 'tb-column');
|
|
174
|
+
break;
|
|
175
|
+
case 'row':
|
|
176
|
+
node = el('div', 'tb-row');
|
|
177
|
+
break;
|
|
178
|
+
case 'toolbar':
|
|
179
|
+
node = buildToolbar();
|
|
180
|
+
break;
|
|
181
|
+
case 'breadcrumb':
|
|
182
|
+
node = buildBreadcrumb(m);
|
|
183
|
+
break;
|
|
184
|
+
case 'rows':
|
|
185
|
+
node = buildRowsField(m);
|
|
186
|
+
break;
|
|
187
|
+
case 'entry': {
|
|
188
|
+
node = el('div', 'tb-entry');
|
|
189
|
+
node.setAttribute('role', 'group');
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case 'grid':
|
|
193
|
+
node = el('div', 'tb-grid');
|
|
194
|
+
break;
|
|
195
|
+
case 'board':
|
|
196
|
+
node = el('div', 'tb-board');
|
|
197
|
+
break;
|
|
198
|
+
case 'desktop':
|
|
199
|
+
node = el('div', 'tb-desktop');
|
|
200
|
+
break;
|
|
201
|
+
case 'scroll': {
|
|
202
|
+
// focusable, so keyboard users can scroll it too
|
|
203
|
+
node = el('div', 'tb-scroll');
|
|
204
|
+
node.tabIndex = 0;
|
|
205
|
+
node.setAttribute('role', 'region');
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case 'panel':
|
|
209
|
+
node = el('section', 'tb-panel');
|
|
210
|
+
break;
|
|
211
|
+
case 'form': {
|
|
212
|
+
const f = el('form', 'tb-form');
|
|
213
|
+
f.noValidate = true;
|
|
214
|
+
// Enter in a field clicks the submit button, which handles it
|
|
215
|
+
f.addEventListener('submit', ev => ev.preventDefault());
|
|
216
|
+
node = f;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case 'title':
|
|
220
|
+
node = el('h1', 'tb-title');
|
|
221
|
+
break;
|
|
222
|
+
case 'heading':
|
|
223
|
+
node = el('h2', 'tb-heading');
|
|
224
|
+
break;
|
|
225
|
+
case 'text':
|
|
226
|
+
node = el('p', 'tb-text');
|
|
227
|
+
break;
|
|
228
|
+
case 'divider':
|
|
229
|
+
node = el('hr', 'tb-divider');
|
|
230
|
+
break;
|
|
231
|
+
case 'link': {
|
|
232
|
+
const a = el('a', 'tb-link');
|
|
233
|
+
a.href = screenHref(get(face, 'value')) ?? linkHref(str(face, 'value') ?? '#') ?? '#';
|
|
234
|
+
withIcon(a, face, m);
|
|
235
|
+
a.addEventListener('click', ev => {
|
|
236
|
+
if (get(face, 'action').t === K.Block) {
|
|
237
|
+
ev.preventDefault();
|
|
238
|
+
void fire('ui-click', face);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
node = a;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case 'button': {
|
|
245
|
+
const b = el('button', 'tb-button');
|
|
246
|
+
const submit = flag(face, 'submit');
|
|
247
|
+
b.type = submit ? 'submit' : 'button';
|
|
248
|
+
b.addEventListener('click', ev => {
|
|
249
|
+
if (!submit) {
|
|
250
|
+
const done = fire('ui-click', face);
|
|
251
|
+
// Next of a form in steps that stays: take the user to the first problem of the step
|
|
252
|
+
const steps = b.closest('.tb-steps-nav')?.parentElement;
|
|
253
|
+
if (steps)
|
|
254
|
+
void done.then(() => focusProblem(steps.querySelector(':scope > .tb-step-panel:not([hidden])')));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
ev.preventDefault();
|
|
258
|
+
clickSubmit(face, b.closest('form, .tb-view') ?? document.body);
|
|
259
|
+
});
|
|
260
|
+
withIcon(b, face, m);
|
|
261
|
+
node = b;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case 'tile': {
|
|
265
|
+
const b = el('button', flag(face, 'linked') ? 'tb-tile tb-tile-linked' : 'tb-tile');
|
|
266
|
+
b.type = 'button';
|
|
267
|
+
b.addEventListener('click', () => void fire('ui-click', face));
|
|
268
|
+
withIcon(b, face, m);
|
|
269
|
+
node = b;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'progress':
|
|
273
|
+
node = buildProgress(m);
|
|
274
|
+
break;
|
|
275
|
+
case 'image':
|
|
276
|
+
node = el('img', 'tb-image');
|
|
277
|
+
break;
|
|
278
|
+
case 'video':
|
|
279
|
+
case 'audio': {
|
|
280
|
+
const media = el(style, `tb-${style}`);
|
|
281
|
+
media.controls = true;
|
|
282
|
+
media.preload = 'metadata';
|
|
283
|
+
if (media instanceof HTMLVideoElement)
|
|
284
|
+
media.playsInline = true;
|
|
285
|
+
node = media;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case 'backdrop': {
|
|
289
|
+
// decoration behind its container: screen readers skip it
|
|
290
|
+
node = el('div', 'tb-backdrop');
|
|
291
|
+
node.setAttribute('aria-hidden', 'true');
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case 'canvas':
|
|
295
|
+
node = buildCanvas(m);
|
|
296
|
+
break;
|
|
297
|
+
case 'chart':
|
|
298
|
+
node = buildChart(m);
|
|
299
|
+
break;
|
|
300
|
+
case 'orbit':
|
|
301
|
+
node = buildOrbit(m);
|
|
302
|
+
break;
|
|
303
|
+
case 'icon':
|
|
304
|
+
node = el('span', 'tb-icon-face');
|
|
305
|
+
break;
|
|
306
|
+
case 'table':
|
|
307
|
+
case 'list':
|
|
308
|
+
node = buildRows(face, style, m);
|
|
309
|
+
break;
|
|
310
|
+
case 'tree':
|
|
311
|
+
node = buildTree(face, m);
|
|
312
|
+
break;
|
|
313
|
+
case 'dialog':
|
|
314
|
+
node = buildDialog(face, m);
|
|
315
|
+
break;
|
|
316
|
+
case 'tabs':
|
|
317
|
+
node = buildTabs(face, m);
|
|
318
|
+
break;
|
|
319
|
+
case 'steps':
|
|
320
|
+
node = buildSteps(face, m);
|
|
321
|
+
break;
|
|
322
|
+
case 'split':
|
|
323
|
+
node = buildSplit(face, m);
|
|
324
|
+
break;
|
|
325
|
+
case 'screens': {
|
|
326
|
+
node = el('div', 'tb-screens');
|
|
327
|
+
setScreensFace(face);
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case 'screen': {
|
|
331
|
+
node = el('section', 'tb-screen');
|
|
332
|
+
const t = str(face, 'text');
|
|
333
|
+
if (t !== null) {
|
|
334
|
+
node.setAttribute('aria-label', t);
|
|
335
|
+
document.title = t;
|
|
336
|
+
setTitleFace(face);
|
|
337
|
+
}
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
case 'tab': {
|
|
341
|
+
node = el('div', 'tb-tab-panel');
|
|
342
|
+
node.setAttribute('role', 'tabpanel');
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case 'step': {
|
|
346
|
+
node = el('div', 'tb-step-panel');
|
|
347
|
+
node.setAttribute('role', 'group');
|
|
348
|
+
node.tabIndex = -1;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
default: node = el('div');
|
|
352
|
+
}
|
|
353
|
+
if (style === 'screens')
|
|
354
|
+
placeScreen(m, node);
|
|
355
|
+
else if (children(face).length > 0 && style !== 'tabs' && style !== 'steps' && style !== 'split')
|
|
356
|
+
appendChildren(m.box ?? node, face, style);
|
|
357
|
+
}
|
|
358
|
+
m.el = node;
|
|
359
|
+
byNode.set(node, m);
|
|
360
|
+
if (m.input !== null)
|
|
361
|
+
byNode.set(m.input, m);
|
|
362
|
+
byCtx.set(face.ctx, m);
|
|
363
|
+
face.ctx.watch = dirty;
|
|
364
|
+
if (get(face, 'reactions').t === K.Block) {
|
|
365
|
+
reactors.add(m);
|
|
366
|
+
newReactor = true;
|
|
367
|
+
}
|
|
368
|
+
listen(m, style);
|
|
369
|
+
sync(m);
|
|
370
|
+
return node;
|
|
371
|
+
}
|
|
372
|
+
/** Puts the face's icon before its caption, which then goes in `m.label`. */
|
|
373
|
+
export function withIcon(node, face, m) {
|
|
374
|
+
const name = iconName(face);
|
|
375
|
+
const svg = name !== null ? icon(name) : null;
|
|
376
|
+
if (svg === null)
|
|
377
|
+
return;
|
|
378
|
+
m.label = el('span');
|
|
379
|
+
node.append(svg, m.label);
|
|
380
|
+
node.classList.add('tb-has-icon');
|
|
381
|
+
}
|
|
382
|
+
/** The small second icon of a tile (mark #list "List"), in a corner of its icon, and the name it adds. */
|
|
383
|
+
export function syncMark(m) {
|
|
384
|
+
const f = m.face;
|
|
385
|
+
const v = get(f, 'mark');
|
|
386
|
+
const name = v.t === K.Issue ? spell(v.sym).toLowerCase() : null;
|
|
387
|
+
let mark = m.el.querySelector(':scope > .tb-tile-mark');
|
|
388
|
+
if (mark?.dataset.icon !== (name ?? undefined)) {
|
|
389
|
+
mark?.remove();
|
|
390
|
+
mark = null;
|
|
391
|
+
const svg = name !== null ? icon(name) : null;
|
|
392
|
+
if (svg !== null) {
|
|
393
|
+
mark = el('span', 'tb-tile-mark');
|
|
394
|
+
mark.dataset.icon = name;
|
|
395
|
+
mark.setAttribute('aria-hidden', 'true');
|
|
396
|
+
mark.append(svg);
|
|
397
|
+
m.el.append(mark);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const said = mark !== null ? str(f, 'mark-text') : null;
|
|
401
|
+
if (said !== null && said !== '')
|
|
402
|
+
m.el.setAttribute('aria-label', `${str(f, 'text') ?? ''}, ${said}`);
|
|
403
|
+
else
|
|
404
|
+
m.el.removeAttribute('aria-label');
|
|
405
|
+
}
|
|
406
|
+
/** A face with an icon and no text is named after its icon: #arrow-left -> "Arrow left". */
|
|
407
|
+
export function iconLabel(face) {
|
|
408
|
+
const name = iconName(face);
|
|
409
|
+
if (name === null || (str(face, 'text') ?? '') !== '')
|
|
410
|
+
return null;
|
|
411
|
+
const hint = str(face, 'hint');
|
|
412
|
+
if (hint !== null)
|
|
413
|
+
return hint;
|
|
414
|
+
const words = name.replace(/-/g, ' ');
|
|
415
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
416
|
+
}
|
|
417
|
+
/** Children of a container; consecutive buttons in a form, or in a step of one, share an action row. */
|
|
418
|
+
export function appendChildren(node, face, style) {
|
|
419
|
+
let actions = null;
|
|
420
|
+
for (const c of children(face)) {
|
|
421
|
+
const isButton = word(c, 'style') === 'button';
|
|
422
|
+
if ((style === 'form' || style === 'step') && isButton) {
|
|
423
|
+
if (actions === null) {
|
|
424
|
+
actions = el('div', 'tb-actions');
|
|
425
|
+
node.append(actions);
|
|
426
|
+
}
|
|
427
|
+
actions.append(build(c));
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
actions = null;
|
|
431
|
+
const n = build(c);
|
|
432
|
+
if (style === 'toolbar' && n.tagName === 'HR')
|
|
433
|
+
n.setAttribute('aria-orientation', 'vertical');
|
|
434
|
+
node.append(n);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
export function clickSubmit(face, formEl) {
|
|
439
|
+
// after a failed submit, take the user to the first problem
|
|
440
|
+
void fire('ui-click', face).then(() => focusProblem(formEl));
|
|
441
|
+
}
|
|
442
|
+
export function focusProblem(scope) {
|
|
443
|
+
for (const i of Array.from(scope?.querySelectorAll('input, textarea, select') ?? [])) {
|
|
444
|
+
const m = byNode.get(i);
|
|
445
|
+
if (m !== undefined && get(m.face, 'error').t === K.String)
|
|
446
|
+
return i.focus();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type OrbitSpec, type Role, type Place, type Placed, type Box } from '../orbit.ts';
|
|
2
|
+
import { type Mounted } from './mount.ts';
|
|
3
|
+
export interface OrbitVis {
|
|
4
|
+
key: string;
|
|
5
|
+
/** Moved and faded; `inner`, inside it, is scaled by the radius. Chrome draws a faded group of tiny units blurred, so the two stay apart. */
|
|
6
|
+
g: SVGGElement;
|
|
7
|
+
inner: SVGGElement;
|
|
8
|
+
role: Role;
|
|
9
|
+
cur: Place;
|
|
10
|
+
from: Place;
|
|
11
|
+
to: Place;
|
|
12
|
+
dying: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface OrbitLine {
|
|
15
|
+
a: string;
|
|
16
|
+
b: string;
|
|
17
|
+
path: SVGPathElement;
|
|
18
|
+
text: SVGTextElement | null;
|
|
19
|
+
curve: number;
|
|
20
|
+
}
|
|
21
|
+
export interface OrbitState {
|
|
22
|
+
svg: SVGSVGElement;
|
|
23
|
+
defs: SVGDefsElement;
|
|
24
|
+
world: SVGGElement;
|
|
25
|
+
lines: SVGGElement;
|
|
26
|
+
bubbles: SVGGElement;
|
|
27
|
+
vis: Map<string, OrbitVis>;
|
|
28
|
+
edges: OrbitLine[];
|
|
29
|
+
/** What it shows: the spec as read, and a signature of it that tells when it changed. */
|
|
30
|
+
spec: OrbitSpec;
|
|
31
|
+
signature: string;
|
|
32
|
+
/** The page of neighbours on show, and the focus it is a page of. */
|
|
33
|
+
page: number;
|
|
34
|
+
pageOf: string | null;
|
|
35
|
+
box: Box;
|
|
36
|
+
/** The bubbles of the last layout, and how many neighbours were left off its page. */
|
|
37
|
+
placed: Placed[];
|
|
38
|
+
left: number;
|
|
39
|
+
cam: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
s: number;
|
|
43
|
+
};
|
|
44
|
+
camFrom: {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
s: number;
|
|
48
|
+
} | null;
|
|
49
|
+
camTo: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
s: number;
|
|
53
|
+
} | null;
|
|
54
|
+
anim: number;
|
|
55
|
+
/** The node the person picked last: new neighbours grow from it. */
|
|
56
|
+
picked: string | null;
|
|
57
|
+
/** The pick came from the keyboard: once redrawn, the focus goes back to the orbit. */
|
|
58
|
+
byKey: boolean;
|
|
59
|
+
dragged: boolean;
|
|
60
|
+
gradients: Map<string, [string, string]>;
|
|
61
|
+
width: number;
|
|
62
|
+
height: number;
|
|
63
|
+
}
|
|
64
|
+
export declare let orbitCount: number;
|
|
65
|
+
/** An orbit: an SVG the size of the face, a world the camera moves, edges under the bubbles. */
|
|
66
|
+
export declare function buildOrbit(m: Mounted): HTMLElement;
|
|
67
|
+
/** Drag to pan, Ctrl and the wheel (or a pinch) to zoom about the pointer, double click to fit again. */
|
|
68
|
+
export declare function orbitCamera(m: Mounted, st: OrbitState): void;
|
|
69
|
+
/** Tab goes through the neighbours, Enter or Space picks one, Escape or Backspace steps back. */
|
|
70
|
+
export declare function orbitKeys(m: Mounted, st: OrbitState): void;
|
|
71
|
+
/** The person picked a bubble: a neighbour enters, the trail steps back, "+N more" turns the page. */
|
|
72
|
+
export declare function orbitPick(m: Mounted, st: OrbitState, key: string, byKey: boolean): void;
|
|
73
|
+
export declare function syncOrbit(m: Mounted): void;
|
|
74
|
+
export declare function orbitSignature(spec: OrbitSpec): string;
|
|
75
|
+
/** The ids of the gradients of a color, made the first time it is used. */
|
|
76
|
+
export declare function orbitGradients(st: OrbitState, color: string): [string, string];
|
|
77
|
+
/** Moves from what is on screen to what the spec says: bubbles that stay move, new ones grow from the one picked, the rest fade. */
|
|
78
|
+
export declare function orbitRender(m: Mounted, st: OrbitState): void;
|
|
79
|
+
/** Every bubble on show drawn anew (its title, hints and size may have changed), and the edges, for the camera's zoom. */
|
|
80
|
+
export declare function orbitDressAll(m: Mounted, st: OrbitState, scale: number): void;
|
|
81
|
+
export declare function orbitBubble(m: Mounted, st: OrbitState, p: Placed, start: Place): OrbitVis;
|
|
82
|
+
/** What a bubble shows and how it reads: a link to a neighbour, back to the trail, or the next page. */
|
|
83
|
+
export declare function orbitDress(m: Mounted, st: OrbitState, v: OrbitVis, p: Placed, left: number, scale: number): void;
|
|
84
|
+
export declare function orbitEdgeText(spec: OrbitSpec, key: string): string;
|
|
85
|
+
export declare function orbitEdges(st: OrbitState, placed: Placed[], scale: number): void;
|
|
86
|
+
export declare function orbitHover(st: OrbitState, key: string, on: boolean): void;
|
|
87
|
+
export declare function orbitApplyCam(st: OrbitState): void;
|
|
88
|
+
/** Tweens every bubble and the camera from where they are to where they go; 0 ms puts them there at once. */
|
|
89
|
+
export declare function orbitAnimate(st: OrbitState, ms: number): void;
|
|
90
|
+
export declare function orbitDrawEdges(st: OrbitState): void;
|