trebol 0.1.2 → 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 +2 -0
- package/dist/cli.js +10040 -7519
- package/dist/lib/core/boot.js +10 -7
- package/dist/lib/core/eval.js +2 -2
- 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 +1 -1
- package/dist/lib/core/natives/data.js +6 -1
- package/dist/lib/core/natives/series.js +49 -9
- package/dist/lib/core/natives/text.js +0 -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 +84 -4812
- 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 +15 -19
- package/dist/lib/host/devtools.js +39 -427
- package/dist/lib/host/fonts.js +4 -3
- package/dist/lib/host/icons.js +4 -0
- package/dist/lib/host/index.d.ts +3 -1
- package/dist/lib/host/index.js +107 -4
- package/dist/lib/host/locale.d.ts +18 -0
- package/dist/lib/host/locale.js +75 -5
- package/dist/lib/host/markdown.d.ts +4 -0
- package/dist/lib/host/markdown.js +8 -0
- package/dist/lib/host/modules.js +118 -19
- package/dist/lib/host/motion.d.ts +32 -0
- package/dist/lib/host/motion.js +190 -0
- package/dist/lib/host/net.js +5 -2
- package/dist/lib/host/palette.d.ts +17 -0
- package/dist/lib/host/palette.js +131 -0
- package/dist/lib/host/scheduler.d.ts +2 -0
- package/dist/lib/host/scheduler.js +4 -0
- 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 -1384
- 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 +17 -0
- package/dist/lib/ui/test.trb +3 -556
- 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 -1675
- package/dist/trebol.js +4463 -1891
- package/package.json +1 -1
- package/src/core/boot.ts +9 -6
- package/src/core/eval.ts +2 -2
- 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 +1 -1
- package/src/core/natives/data.ts +6 -1
- package/src/core/natives/parse.ts +1 -1
- package/src/core/natives/series.ts +47 -11
- package/src/core/natives/text.ts +0 -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 +82 -4612
- 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 +39 -442
- package/src/host/fonts.ts +4 -3
- package/src/host/icons.ts +4 -0
- package/src/host/index.ts +107 -4
- package/src/host/locale.ts +71 -5
- package/src/host/markdown.ts +9 -0
- package/src/host/modules.ts +117 -21
- package/src/host/motion.ts +204 -0
- package/src/host/net.ts +4 -2
- package/src/host/palette.ts +139 -0
- package/src/host/scheduler.ts +5 -0
- 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 -1384
- 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 +17 -0
- package/src/ui/test.trb +3 -556
- 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 -1675
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
// --- dialogs, tabs and toasts --------------------------------------------------------
|
|
2
|
+
import { K, NONE, TRUE, FALSE, native, value, intern, spell, text, UNSET, throwError } from "../../core/index.js";
|
|
3
|
+
import { spawn } from "../scheduler.js";
|
|
4
|
+
import { iconNode } from "../icons.js";
|
|
5
|
+
import { devLog } from "../devlog.js";
|
|
6
|
+
import { get, str, own, keepOwn, flag, word, children } from "./faces.js";
|
|
7
|
+
import { host, byCtx, newId, fire, el, build } from "./mount.js";
|
|
8
|
+
import { int } from "./drag.js";
|
|
9
|
+
import { here, setHere } from "./screens.js";
|
|
10
|
+
import { rootFace } from "./page.js";
|
|
11
|
+
export function buildDialog(face, m) {
|
|
12
|
+
const d = el('dialog', 'tb-dialog');
|
|
13
|
+
const head = el('header', 'tb-dialog-head');
|
|
14
|
+
const title = el('h2', 'tb-dialog-title');
|
|
15
|
+
title.id = `tb-${newId()}`;
|
|
16
|
+
d.setAttribute('aria-labelledby', title.id);
|
|
17
|
+
const x = el('button', 'tb-dialog-close');
|
|
18
|
+
x.type = 'button';
|
|
19
|
+
keepOwn(x, 'close', 'aria-label');
|
|
20
|
+
x.textContent = '×';
|
|
21
|
+
x.addEventListener('click', () => void fire('ui-close', face));
|
|
22
|
+
head.append(title, x);
|
|
23
|
+
const body = el('div', 'tb-dialog-body');
|
|
24
|
+
d.append(head, body);
|
|
25
|
+
// Esc: let the face decide, so code that keeps it open still wins
|
|
26
|
+
d.addEventListener('cancel', ev => {
|
|
27
|
+
ev.preventDefault();
|
|
28
|
+
void fire('ui-close', face);
|
|
29
|
+
});
|
|
30
|
+
m.label = title;
|
|
31
|
+
m.box = body;
|
|
32
|
+
return d;
|
|
33
|
+
}
|
|
34
|
+
export function syncDialog(m) {
|
|
35
|
+
const d = m.el;
|
|
36
|
+
m.label.textContent = str(m.face, 'text') ?? '';
|
|
37
|
+
const open = !flag(m.face, 'hidden');
|
|
38
|
+
if (open === d.open)
|
|
39
|
+
return;
|
|
40
|
+
if (!d.isConnected) {
|
|
41
|
+
queueMicrotask(() => { if (d.isConnected)
|
|
42
|
+
syncDialog(m); });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!open)
|
|
46
|
+
return d.close();
|
|
47
|
+
d.showModal();
|
|
48
|
+
// after this repaint, which never writes into a focused input
|
|
49
|
+
queueMicrotask(() => d.querySelector('input, textarea, select')?.focus());
|
|
50
|
+
}
|
|
51
|
+
export function buildTabs(face, m) {
|
|
52
|
+
const node = el('div', 'tb-tabs');
|
|
53
|
+
const list = el('div', 'tb-tablist');
|
|
54
|
+
list.setAttribute('role', 'tablist');
|
|
55
|
+
node.append(list);
|
|
56
|
+
const tabs = children(face);
|
|
57
|
+
const pick = (i) => {
|
|
58
|
+
void fire('ui-input', face, { t: K.Integer, v: i + 1 });
|
|
59
|
+
list.children[i]?.focus();
|
|
60
|
+
};
|
|
61
|
+
tabs.forEach((t, i) => {
|
|
62
|
+
const panel = build(t);
|
|
63
|
+
const b = el('button', 'tb-tab');
|
|
64
|
+
b.type = 'button';
|
|
65
|
+
b.id = `tb-${newId()}`;
|
|
66
|
+
panel.id = `${b.id}-panel`;
|
|
67
|
+
b.setAttribute('role', 'tab');
|
|
68
|
+
b.setAttribute('aria-controls', panel.id);
|
|
69
|
+
panel.setAttribute('aria-labelledby', b.id);
|
|
70
|
+
b.textContent = str(t, 'text') ?? '';
|
|
71
|
+
b.addEventListener('click', () => pick(i));
|
|
72
|
+
const tm = byCtx.get(t.ctx);
|
|
73
|
+
tm.button = b;
|
|
74
|
+
list.append(b);
|
|
75
|
+
node.append(panel);
|
|
76
|
+
});
|
|
77
|
+
list.addEventListener('keydown', ev => {
|
|
78
|
+
const at = Array.prototype.indexOf.call(list.children, document.activeElement);
|
|
79
|
+
const n = tabs.length;
|
|
80
|
+
const to = ev.key === 'ArrowRight' ? (at + 1) % n : ev.key === 'ArrowLeft' ? (at - 1 + n) % n
|
|
81
|
+
: ev.key === 'Home' ? 0 : ev.key === 'End' ? n - 1 : -1;
|
|
82
|
+
if (to < 0 || at < 0)
|
|
83
|
+
return;
|
|
84
|
+
ev.preventDefault();
|
|
85
|
+
pick(to);
|
|
86
|
+
});
|
|
87
|
+
m.box = list;
|
|
88
|
+
return node;
|
|
89
|
+
}
|
|
90
|
+
export function syncTabs(m) {
|
|
91
|
+
const v = get(m.face, 'value');
|
|
92
|
+
const tabs = children(m.face);
|
|
93
|
+
const at = v.t === K.Integer ? Math.min(Math.max(Number(v.v), 1), tabs.length) - 1 : 0;
|
|
94
|
+
tabs.forEach((t, i) => {
|
|
95
|
+
const tm = byCtx.get(t.ctx);
|
|
96
|
+
if (tm === undefined || tm.button === null)
|
|
97
|
+
return;
|
|
98
|
+
const on = i === at;
|
|
99
|
+
tm.button.setAttribute('aria-selected', on ? 'true' : 'false');
|
|
100
|
+
tm.button.tabIndex = on ? 0 : -1;
|
|
101
|
+
tm.el.hidden = !on;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export const stepsState = new WeakMap();
|
|
105
|
+
export const mountedSteps = new Set();
|
|
106
|
+
export function buildSteps(face, m) {
|
|
107
|
+
const node = el('div', 'tb-steps');
|
|
108
|
+
const bar = el('ol', 'tb-steps-bar');
|
|
109
|
+
keepOwn(bar, 'steps', 'aria-label');
|
|
110
|
+
const count = el('p', 'tb-steps-count');
|
|
111
|
+
node.append(bar, count);
|
|
112
|
+
const v = get(face, 'value');
|
|
113
|
+
const st = { steps: [], count, trail: [{ depth: here.depth, step: v.t === K.Integer ? Number(v.v) : 1 }], shown: 0 };
|
|
114
|
+
let nav = null;
|
|
115
|
+
children(face).forEach((c, i) => {
|
|
116
|
+
if (word(c, 'style') !== 'step') {
|
|
117
|
+
nav = c;
|
|
118
|
+
const n = build(c);
|
|
119
|
+
n.classList.add('tb-steps-nav');
|
|
120
|
+
node.append(n);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const li = el('li');
|
|
124
|
+
const b = el('button', 'tb-steps-item');
|
|
125
|
+
b.type = 'button';
|
|
126
|
+
const num = el('span', 'tb-steps-num');
|
|
127
|
+
const title = el('span', 'tb-steps-title');
|
|
128
|
+
b.append(num, title);
|
|
129
|
+
b.addEventListener('click', () => void fire('ui-step-go', face, int(i + 1)));
|
|
130
|
+
li.append(b);
|
|
131
|
+
bar.append(li);
|
|
132
|
+
node.append(build(c));
|
|
133
|
+
st.steps.push({ face: c, li, button: b, num, title });
|
|
134
|
+
});
|
|
135
|
+
// Enter in a field goes to the next step; on the last one it sends the form
|
|
136
|
+
node.addEventListener('keydown', ev => {
|
|
137
|
+
if (ev.key !== 'Enter' || ev.defaultPrevented || !(ev.target instanceof HTMLInputElement) || !inTextBox(ev.target))
|
|
138
|
+
return;
|
|
139
|
+
const next = nav === null ? undefined : children(nav)[1];
|
|
140
|
+
if (next === undefined || flag(next, 'hidden'))
|
|
141
|
+
return;
|
|
142
|
+
ev.preventDefault();
|
|
143
|
+
byCtx.get(next.ctx)?.el.click();
|
|
144
|
+
});
|
|
145
|
+
stepsState.set(m, st);
|
|
146
|
+
mountedSteps.add(m);
|
|
147
|
+
return node;
|
|
148
|
+
}
|
|
149
|
+
export function syncSteps(m) {
|
|
150
|
+
const st = stepsState.get(m);
|
|
151
|
+
if (st === undefined)
|
|
152
|
+
return;
|
|
153
|
+
const v = get(m.face, 'value');
|
|
154
|
+
const at = v.t === K.Integer ? Number(v.v) : 1;
|
|
155
|
+
const live = st.steps.filter(s => !flag(s.face, 'hidden'));
|
|
156
|
+
const k = live.findIndex(s => s === st.steps[at - 1]);
|
|
157
|
+
st.steps.forEach((s, i) => {
|
|
158
|
+
const j = live.indexOf(s);
|
|
159
|
+
const title = str(s.face, 'text') ?? '';
|
|
160
|
+
s.li.hidden = j < 0;
|
|
161
|
+
s.li.classList.toggle('tb-done', j >= 0 && j < k);
|
|
162
|
+
s.li.classList.toggle('tb-current', j === k);
|
|
163
|
+
s.num.textContent = String(j + 1);
|
|
164
|
+
s.title.textContent = title;
|
|
165
|
+
s.button.disabled = j < 0 || j >= k;
|
|
166
|
+
if (j === k)
|
|
167
|
+
s.button.setAttribute('aria-current', 'step');
|
|
168
|
+
else
|
|
169
|
+
s.button.removeAttribute('aria-current');
|
|
170
|
+
const panel = byCtx.get(s.face.ctx)?.el;
|
|
171
|
+
if (panel === undefined)
|
|
172
|
+
return;
|
|
173
|
+
panel.hidden = i !== at - 1;
|
|
174
|
+
panel.setAttribute('aria-label', title);
|
|
175
|
+
});
|
|
176
|
+
st.count.textContent = k < 0 ? '' : `${own('step-of', String(k + 1), String(live.length))} · ${str(live[k].face, 'text') ?? ''}`;
|
|
177
|
+
if (st.shown !== 0 && st.shown !== at) {
|
|
178
|
+
stepHistory(st, at, st.shown);
|
|
179
|
+
const panel = byCtx.get(st.steps[at - 1].face.ctx)?.el;
|
|
180
|
+
if (m.el.getBoundingClientRect().top < 0)
|
|
181
|
+
m.el.scrollIntoView({ block: 'start' });
|
|
182
|
+
panel?.focus({ preventScroll: true });
|
|
183
|
+
}
|
|
184
|
+
st.shown = at;
|
|
185
|
+
}
|
|
186
|
+
/** A new step on show: forward is a new history entry; back returns to the entry that showed it. */
|
|
187
|
+
export function stepHistory(st, to, from) {
|
|
188
|
+
const cur = st.trail.find(x => x.depth === here.depth);
|
|
189
|
+
// Back or Forward brought it: the history is already there
|
|
190
|
+
if (cur?.step === to)
|
|
191
|
+
return;
|
|
192
|
+
if (to > from) {
|
|
193
|
+
setHere({ depth: here.depth + 1, top: here.depth + 1 });
|
|
194
|
+
st.trail = st.trail.filter(x => x.depth < here.depth);
|
|
195
|
+
st.trail.push({ depth: here.depth, step: to });
|
|
196
|
+
history.pushState({ ...here }, '');
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const back = st.trail.filter(x => x.depth < here.depth && x.step === to).pop();
|
|
200
|
+
if (back !== undefined)
|
|
201
|
+
history.go(back.depth - here.depth);
|
|
202
|
+
else if (cur !== undefined)
|
|
203
|
+
cur.step = to;
|
|
204
|
+
}
|
|
205
|
+
/** Back or Forward landed on an entry a form in steps made: it shows that step again. */
|
|
206
|
+
export function stepsLanded() {
|
|
207
|
+
const d = history.state?.depth;
|
|
208
|
+
if (typeof d !== 'number')
|
|
209
|
+
return;
|
|
210
|
+
for (const m of mountedSteps) {
|
|
211
|
+
if (!m.el.isConnected) {
|
|
212
|
+
mountedSteps.delete(m);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const hit = stepsState.get(m).trail.find(x => x.depth === d);
|
|
216
|
+
if (hit === undefined)
|
|
217
|
+
continue;
|
|
218
|
+
setHere({ depth: d, top: here.top });
|
|
219
|
+
void fire('ui-step-go', m.face, int(hit.step));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// A split shows two panes side by side with a handle between them; on narrow
|
|
223
|
+
// screens it shows one pane, the one its value names, and the second pane
|
|
224
|
+
// gets a back button.
|
|
225
|
+
export function buildSplit(face, m) {
|
|
226
|
+
const node = el('div', 'tb-split');
|
|
227
|
+
const [a, b] = children(face);
|
|
228
|
+
const first = el('div', 'tb-split-pane');
|
|
229
|
+
const second = el('div', 'tb-split-pane');
|
|
230
|
+
first.tabIndex = second.tabIndex = -1;
|
|
231
|
+
const handle = el('div', 'tb-split-handle');
|
|
232
|
+
handle.tabIndex = 0;
|
|
233
|
+
handle.setAttribute('role', 'separator');
|
|
234
|
+
handle.setAttribute('aria-orientation', 'vertical');
|
|
235
|
+
keepOwn(handle, 'resize-panes', 'aria-label');
|
|
236
|
+
handle.setAttribute('aria-valuemin', '20');
|
|
237
|
+
handle.setAttribute('aria-valuemax', '80');
|
|
238
|
+
const resize = (pct) => {
|
|
239
|
+
const p = Math.round(Math.min(80, Math.max(20, pct)));
|
|
240
|
+
node.style.setProperty('--tb-split', `${p}%`);
|
|
241
|
+
handle.setAttribute('aria-valuenow', String(p));
|
|
242
|
+
};
|
|
243
|
+
resize(40);
|
|
244
|
+
handle.addEventListener('pointerdown', ev => {
|
|
245
|
+
handle.setPointerCapture(ev.pointerId);
|
|
246
|
+
ev.preventDefault();
|
|
247
|
+
});
|
|
248
|
+
handle.addEventListener('pointermove', ev => {
|
|
249
|
+
if (!handle.hasPointerCapture(ev.pointerId))
|
|
250
|
+
return;
|
|
251
|
+
const r = node.getBoundingClientRect();
|
|
252
|
+
resize(((ev.clientX - r.left) / r.width) * 100);
|
|
253
|
+
});
|
|
254
|
+
handle.addEventListener('keydown', ev => {
|
|
255
|
+
const now = Number(handle.getAttribute('aria-valuenow'));
|
|
256
|
+
const to = ev.key === 'ArrowLeft' ? now - 5 : ev.key === 'ArrowRight' ? now + 5
|
|
257
|
+
: ev.key === 'Home' ? 20 : ev.key === 'End' ? 80 : null;
|
|
258
|
+
if (to === null)
|
|
259
|
+
return;
|
|
260
|
+
ev.preventDefault();
|
|
261
|
+
resize(to);
|
|
262
|
+
});
|
|
263
|
+
const back = el('button', 'tb-button tb-split-back');
|
|
264
|
+
back.type = 'button';
|
|
265
|
+
const arrow = iconNode('arrow-left');
|
|
266
|
+
const caption = el('span');
|
|
267
|
+
keepOwn(caption, 'back');
|
|
268
|
+
back.append(...(arrow !== null ? [arrow] : []), caption);
|
|
269
|
+
back.addEventListener('click', () => void fire('ui-input', face, { t: K.Integer, v: 1 }));
|
|
270
|
+
if (a !== undefined)
|
|
271
|
+
first.append(build(a));
|
|
272
|
+
second.append(back);
|
|
273
|
+
if (b !== undefined)
|
|
274
|
+
second.append(build(b));
|
|
275
|
+
node.append(first, handle, second);
|
|
276
|
+
return node;
|
|
277
|
+
}
|
|
278
|
+
export function syncSplit(m) {
|
|
279
|
+
const v = get(m.face, 'value');
|
|
280
|
+
const pane = v.t === K.Integer && Number(v.v) === 2 ? '2' : '1';
|
|
281
|
+
const was = m.el.dataset['pane'];
|
|
282
|
+
if (was === pane)
|
|
283
|
+
return;
|
|
284
|
+
m.el.dataset['pane'] = pane;
|
|
285
|
+
// on narrow screens the other pane just appeared: take the focus there
|
|
286
|
+
if (was !== undefined && matchMedia('(max-width: 640px)').matches) {
|
|
287
|
+
const shown = m.el.children[pane === '2' ? 2 : 0];
|
|
288
|
+
(shown.querySelector('.tb-selected') ?? shown).focus();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
export let toasts = null;
|
|
292
|
+
/** The notices with an Undo button on show, by the id ui.trb gave them. */
|
|
293
|
+
export const undoToasts = new Map();
|
|
294
|
+
native('show-toast', '["Shows a short message at the edge of the screen." message [string!] kind [word! none!] undo [integer! none!] "With an Undo button: the id of what it undoes"]', (_t, f) => {
|
|
295
|
+
if (toasts === null) {
|
|
296
|
+
// a manual popover sits in the top layer, so toasts show above open dialogs
|
|
297
|
+
toasts = el('div', 'tb-toasts');
|
|
298
|
+
toasts.popover = 'manual';
|
|
299
|
+
toasts.setAttribute('aria-live', 'polite');
|
|
300
|
+
document.body.append(toasts);
|
|
301
|
+
}
|
|
302
|
+
const kind = f.args[1].t === K.Word ? spell(f.args[1].sym).toLowerCase() : null;
|
|
303
|
+
const id = f.args[2].t === K.Integer ? Number(f.args[2].v) : null;
|
|
304
|
+
const t = el('div', kind !== null ? `tb-toast tb-${kind}` : 'tb-toast');
|
|
305
|
+
if (kind === 'danger')
|
|
306
|
+
t.setAttribute('role', 'alert');
|
|
307
|
+
const message = text(f.args[0]);
|
|
308
|
+
devLog.note('toast', kind !== null ? `${kind}: ${message}` : message);
|
|
309
|
+
const said = el('span', 'tb-toast-text');
|
|
310
|
+
t.append(said);
|
|
311
|
+
const box = toasts;
|
|
312
|
+
let timer;
|
|
313
|
+
const dismiss = () => {
|
|
314
|
+
clearTimeout(timer);
|
|
315
|
+
t.remove();
|
|
316
|
+
if (box.childElementCount === 0 && box.matches(':popover-open'))
|
|
317
|
+
box.hidePopover();
|
|
318
|
+
};
|
|
319
|
+
// gone without Undo: ui.trb runs what waited for it
|
|
320
|
+
const gone = () => {
|
|
321
|
+
dismiss();
|
|
322
|
+
if (id !== null && undoToasts.delete(id))
|
|
323
|
+
fireRoot('ui-toast-gone', id);
|
|
324
|
+
};
|
|
325
|
+
t.addEventListener('click', gone);
|
|
326
|
+
const wait = id !== null ? 8000 : kind === 'danger' ? 6000 : 4000;
|
|
327
|
+
if (id !== null) {
|
|
328
|
+
const undo = el('button', 'tb-toast-undo');
|
|
329
|
+
undo.type = 'button';
|
|
330
|
+
keepOwn(undo, 'undo');
|
|
331
|
+
undo.addEventListener('click', ev => {
|
|
332
|
+
ev.stopPropagation();
|
|
333
|
+
dismiss();
|
|
334
|
+
if (undoToasts.delete(id))
|
|
335
|
+
fireRoot('ui-toast-undo', id);
|
|
336
|
+
});
|
|
337
|
+
t.append(undo);
|
|
338
|
+
t.dataset.tbUndo = String(id);
|
|
339
|
+
undoToasts.set(id, t);
|
|
340
|
+
// while the pointer or the keyboard is on it, it waits: the user has time to read and choose
|
|
341
|
+
const hold = () => clearTimeout(timer);
|
|
342
|
+
const resume = () => {
|
|
343
|
+
if (!t.matches(':hover') && !t.contains(document.activeElement))
|
|
344
|
+
timer = setTimeout(gone, wait);
|
|
345
|
+
};
|
|
346
|
+
t.addEventListener('pointerenter', hold);
|
|
347
|
+
t.addEventListener('focusin', hold);
|
|
348
|
+
t.addEventListener('pointerleave', resume);
|
|
349
|
+
t.addEventListener('focusout', () => setTimeout(resume));
|
|
350
|
+
}
|
|
351
|
+
timer = setTimeout(gone, wait);
|
|
352
|
+
if (box.matches(':popover-open'))
|
|
353
|
+
box.hidePopover();
|
|
354
|
+
box.append(t);
|
|
355
|
+
box.showPopover();
|
|
356
|
+
// screen readers announce text that changes inside a live region already shown
|
|
357
|
+
setTimeout(() => { said.textContent = message; }, 50);
|
|
358
|
+
return value(f.args[0]);
|
|
359
|
+
});
|
|
360
|
+
native('hide-toast', '["Takes away a notice with an Undo button, by its id." id [integer!]]', (_t, f) => {
|
|
361
|
+
const id = Number(f.args[0].v);
|
|
362
|
+
const t = undoToasts.get(id);
|
|
363
|
+
if (t !== undefined) {
|
|
364
|
+
undoToasts.delete(id);
|
|
365
|
+
const box = t.parentElement;
|
|
366
|
+
t.remove();
|
|
367
|
+
if (box !== null && box.childElementCount === 0 && box.matches(':popover-open'))
|
|
368
|
+
box.hidePopover();
|
|
369
|
+
}
|
|
370
|
+
return value(UNSET);
|
|
371
|
+
});
|
|
372
|
+
/** A box where Ctrl+Z undoes typing: a text input, a text area or rich text. */
|
|
373
|
+
export function inTextBox(target) {
|
|
374
|
+
if (!(target instanceof HTMLElement))
|
|
375
|
+
return false;
|
|
376
|
+
if (target.isContentEditable || target instanceof HTMLTextAreaElement)
|
|
377
|
+
return true;
|
|
378
|
+
return target instanceof HTMLInputElement && !['button', 'checkbox', 'radio', 'range', 'color', 'file', 'submit', 'reset'].includes(target.type);
|
|
379
|
+
}
|
|
380
|
+
/** Runs a function of ui.trb for the page, not for one face: the view on show is its face. */
|
|
381
|
+
export function fireRoot(fn, id) {
|
|
382
|
+
const n = int(id);
|
|
383
|
+
if (rootFace !== null)
|
|
384
|
+
void fire(fn, rootFace, n);
|
|
385
|
+
else
|
|
386
|
+
spawn(host.sch, { data: [{ t: K.Word, sym: intern(fn), bind: host.rt.lib }, NONE, n] }, 0);
|
|
387
|
+
}
|
|
388
|
+
native('show-confirm', '["Asks a question in a small dialog; true when the user says yes." question [string!] yes [string! none!] no [string! none!] kind [word! none!]]', (_t, f, v) => {
|
|
389
|
+
if (f.phase === 1)
|
|
390
|
+
return value(v);
|
|
391
|
+
f.phase = 1;
|
|
392
|
+
const answer = (at, key) => f.args[at].t === K.String ? text(f.args[at]) : own(key);
|
|
393
|
+
const danger = f.args[3].t === K.Word && spell(f.args[3].sym).toLowerCase() === 'danger';
|
|
394
|
+
const d = el('dialog', 'tb-dialog tb-confirm');
|
|
395
|
+
d.setAttribute('role', 'alertdialog');
|
|
396
|
+
const body = el('div', 'tb-dialog-body');
|
|
397
|
+
const q = el('p', 'tb-confirm-question');
|
|
398
|
+
q.id = `tb-${newId()}`;
|
|
399
|
+
q.textContent = text(f.args[0]);
|
|
400
|
+
d.setAttribute('aria-labelledby', q.id);
|
|
401
|
+
const row = el('div', 'tb-row tb-right');
|
|
402
|
+
const no = el('button', 'tb-button');
|
|
403
|
+
const yes = el('button', danger ? 'tb-button tb-danger' : 'tb-button tb-primary');
|
|
404
|
+
no.type = yes.type = 'button';
|
|
405
|
+
no.textContent = answer(2, 'no');
|
|
406
|
+
yes.textContent = answer(1, 'yes');
|
|
407
|
+
row.append(no, yes);
|
|
408
|
+
body.append(q, row);
|
|
409
|
+
d.append(body);
|
|
410
|
+
const p = new Promise(resolve => {
|
|
411
|
+
const done = (ok) => {
|
|
412
|
+
d.close();
|
|
413
|
+
d.remove();
|
|
414
|
+
resolve(ok ? TRUE : FALSE);
|
|
415
|
+
};
|
|
416
|
+
yes.addEventListener('click', () => done(true));
|
|
417
|
+
no.addEventListener('click', () => done(false));
|
|
418
|
+
// Esc is no
|
|
419
|
+
d.addEventListener('cancel', ev => { ev.preventDefault(); done(false); });
|
|
420
|
+
});
|
|
421
|
+
document.body.append(d);
|
|
422
|
+
// over an open dialog too: the top layer stacks dialogs in the order they open
|
|
423
|
+
d.showModal();
|
|
424
|
+
// what cannot be undone starts on no, so Enter does not do it by mistake
|
|
425
|
+
(danger ? no : yes).focus();
|
|
426
|
+
return { k: 'await', p };
|
|
427
|
+
});
|
|
428
|
+
native('print-faces', '["Opens the print dialog for the page, or for one face only." face [object! none!]]', (_t, f) => {
|
|
429
|
+
const target = f.args[0].t === K.Object ? byCtx.get(f.args[0].ctx)?.el : undefined;
|
|
430
|
+
if (f.args[0].t === K.Object && (target === undefined || !target.isConnected)) {
|
|
431
|
+
return throwError('script', 'not-shown', 'print-page/only needs a face on the screen');
|
|
432
|
+
}
|
|
433
|
+
if (target !== undefined) {
|
|
434
|
+
target.classList.add('tb-print-target');
|
|
435
|
+
document.documentElement.classList.add('tb-print-only');
|
|
436
|
+
addEventListener('afterprint', () => {
|
|
437
|
+
target.classList.remove('tb-print-target');
|
|
438
|
+
document.documentElement.classList.remove('tb-print-only');
|
|
439
|
+
}, { once: true });
|
|
440
|
+
}
|
|
441
|
+
print();
|
|
442
|
+
return value(UNSET);
|
|
443
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type Cell, type ObjectCell } from '../../core/index.ts';
|
|
2
|
+
import { type Mounted } from './mount.ts';
|
|
3
|
+
import type { MenuEntry } from './menus.ts';
|
|
4
|
+
/** Mounted faces that accept drops. */
|
|
5
|
+
export declare const dropZones: Set<Mounted>;
|
|
6
|
+
/** What is being dragged: a face, or a row of a table, list or tree. */
|
|
7
|
+
export interface Source {
|
|
8
|
+
face: ObjectCell;
|
|
9
|
+
el: HTMLElement;
|
|
10
|
+
payload: Cell;
|
|
11
|
+
/** The container it can be reordered in, and its position there (0-based). */
|
|
12
|
+
within: Mounted | null;
|
|
13
|
+
index: number;
|
|
14
|
+
/** The element holding a row and its siblings (a tree has one per level). */
|
|
15
|
+
group: HTMLElement | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Where a drag would land. In a tree, `group` holds the siblings it goes
|
|
19
|
+
* between, `parent` is their node (none at the root) and `into` the row of a
|
|
20
|
+
* folder it goes into, at the end.
|
|
21
|
+
*/
|
|
22
|
+
export interface Target {
|
|
23
|
+
m: Mounted;
|
|
24
|
+
index: number;
|
|
25
|
+
reorder: boolean;
|
|
26
|
+
group?: HTMLElement;
|
|
27
|
+
parent?: Cell;
|
|
28
|
+
into?: HTMLElement;
|
|
29
|
+
}
|
|
30
|
+
export declare const isData: (m: Mounted) => boolean;
|
|
31
|
+
/** The elements a drop target places things between: rows, or child faces. */
|
|
32
|
+
export declare function slots(m: Mounted): HTMLElement[];
|
|
33
|
+
export declare function mountedAbove(e: Element | null): Mounted | undefined;
|
|
34
|
+
/** The drag source at an element: a draggable face, a row, or a child of a reorderable container. */
|
|
35
|
+
export declare function sourceAt(start: Element): Source | null;
|
|
36
|
+
/** The drop target under a point, and the insertion index there. */
|
|
37
|
+
export declare function targetAt(src: Source, x: number, y: number): Target | null;
|
|
38
|
+
export declare const horizontal: (m: Mounted) => boolean;
|
|
39
|
+
export declare function insertionAt(m: Mounted, x: number, y: number): number;
|
|
40
|
+
/** How many things a container places: all the rows of a table or list, drawn or not. */
|
|
41
|
+
export declare function slotCount(m: Mounted): number;
|
|
42
|
+
export declare let line: HTMLElement | null;
|
|
43
|
+
/** Shows where a drop would land: a line between slots, and the target outlined. */
|
|
44
|
+
export declare function indicate(t: Target | null): void;
|
|
45
|
+
/** Ends a drag on a target: a move inside its container, or a drop. */
|
|
46
|
+
export declare function land(src: Source, t: Target): void;
|
|
47
|
+
export declare const int: (n: number) => Cell;
|
|
48
|
+
/** Moves a child or row and keeps the focus on it once the page is repainted. */
|
|
49
|
+
export declare function reorder(m: Mounted, from: number, to: number, group?: HTMLElement, parent?: Cell): Promise<void>;
|
|
50
|
+
/** "Move to" entries: the visible drop zones other than the face itself. */
|
|
51
|
+
export declare function moveTargets(face: ObjectCell, payload: Cell): MenuEntry[];
|
|
52
|
+
export interface Dragging {
|
|
53
|
+
src: Source;
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
id: number;
|
|
57
|
+
on: boolean;
|
|
58
|
+
ghost: HTMLElement | null;
|
|
59
|
+
target: Target | null;
|
|
60
|
+
timer: number;
|
|
61
|
+
}
|
|
62
|
+
export declare let dragging: Dragging | null;
|
|
63
|
+
export declare function startDrag(d: Dragging): void;
|
|
64
|
+
export declare function moveDrag(d: Dragging, x: number, y: number): void;
|
|
65
|
+
export declare function endDrag(drop: boolean): void;
|
|
66
|
+
export declare function swallowClick(ev: Event): void;
|
|
67
|
+
export declare function onPointerDown(ev: PointerEvent): void;
|
|
68
|
+
export declare function onPointerMove(ev: PointerEvent): void;
|
|
69
|
+
/** Alt+Up and Alt+Down move the focused row or child inside a reorderable container. */
|
|
70
|
+
export declare function onReorderKey(ev: KeyboardEvent): void;
|