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,190 @@
|
|
|
1
|
+
// How the page moves when it changes: a screen that gives way to another, rows
|
|
2
|
+
// that come, go or change places, a face shown or hidden. Nothing here is asked
|
|
3
|
+
// for by the app; the theme's --tb-move and --tb-ease say how long and how, and a
|
|
4
|
+
// user who asks the system for less motion gets none.
|
|
5
|
+
/** The theme's time for a change of place, in ms, read from the page once. */
|
|
6
|
+
let moveMs = -1;
|
|
7
|
+
function duration() {
|
|
8
|
+
if (moveMs < 0) {
|
|
9
|
+
const v = getComputedStyle(document.documentElement).getPropertyValue('--tb-move').trim();
|
|
10
|
+
moveMs = v.endsWith('ms') ? parseFloat(v) : v.endsWith('s') ? parseFloat(v) * 1000 : 220;
|
|
11
|
+
if (!Number.isFinite(moveMs))
|
|
12
|
+
moveMs = 220;
|
|
13
|
+
}
|
|
14
|
+
return moveMs;
|
|
15
|
+
}
|
|
16
|
+
/** The theme changed: read its time again. */
|
|
17
|
+
export function themeMoved() {
|
|
18
|
+
moveMs = -1;
|
|
19
|
+
}
|
|
20
|
+
const EASE = 'cubic-bezier(0.2, 0, 0, 1)';
|
|
21
|
+
/** Whether the page may move now: the browser can, the user has not asked for less, the page is on show. */
|
|
22
|
+
export function mayMove() {
|
|
23
|
+
if (typeof matchMedia !== 'function' || typeof Element.prototype.animate !== 'function')
|
|
24
|
+
return false;
|
|
25
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches)
|
|
26
|
+
return false;
|
|
27
|
+
return document.visibilityState !== 'hidden' && duration() > 0;
|
|
28
|
+
}
|
|
29
|
+
// --- screens ---------------------------------------------------------------------
|
|
30
|
+
/** Which way the user went to the screen coming: on, or back to one seen before. */
|
|
31
|
+
let travel = 'on';
|
|
32
|
+
export function travelled(way) {
|
|
33
|
+
travel = way;
|
|
34
|
+
}
|
|
35
|
+
let swapping = false;
|
|
36
|
+
/**
|
|
37
|
+
* Puts the screen coming in place of the one on show: the browser takes a picture of
|
|
38
|
+
* the page, swap changes it, and the old screen slides out as the new one slides in,
|
|
39
|
+
* the way the user went. Faces given the same `morph` in both become one another.
|
|
40
|
+
* swap is called once, now or at the browser's next frame; it may decide not to.
|
|
41
|
+
*/
|
|
42
|
+
export function changeScreen(box, coming, swap) {
|
|
43
|
+
const doc = document;
|
|
44
|
+
// the first screen, or a page that cannot or may not move
|
|
45
|
+
const way = travel;
|
|
46
|
+
travel = 'on';
|
|
47
|
+
if (swapping)
|
|
48
|
+
return;
|
|
49
|
+
if (box.childElementCount === 0 || typeof doc.startViewTransition !== 'function' || !mayMove())
|
|
50
|
+
return swap();
|
|
51
|
+
swapping = true;
|
|
52
|
+
const root = document.documentElement;
|
|
53
|
+
root.dataset['tbTravel'] = way;
|
|
54
|
+
box.style.setProperty('view-transition-name', 'tb-screen');
|
|
55
|
+
// only the names in both screens: a face with no partner goes with its screen
|
|
56
|
+
const both = morphsIn(coming);
|
|
57
|
+
const was = nameMorphs(both);
|
|
58
|
+
const t = doc.startViewTransition(() => {
|
|
59
|
+
swapping = false;
|
|
60
|
+
clearMorphs();
|
|
61
|
+
swap();
|
|
62
|
+
nameMorphs(was);
|
|
63
|
+
});
|
|
64
|
+
void t.finished.catch(() => { }).then(() => {
|
|
65
|
+
box.style.removeProperty('view-transition-name');
|
|
66
|
+
delete root.dataset['tbTravel'];
|
|
67
|
+
clearMorphs();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** The faces given a morph name for the change of screen going on. */
|
|
71
|
+
let named = [];
|
|
72
|
+
/**
|
|
73
|
+
* Gives the browser the morph name of each face on show that has one among those
|
|
74
|
+
* given, so a face of the old screen and one of the new with the same name become
|
|
75
|
+
* one another; when two on show share a name, the first keeps it. Gives the names given.
|
|
76
|
+
*/
|
|
77
|
+
function nameMorphs(among) {
|
|
78
|
+
const seen = new Set();
|
|
79
|
+
for (const e of Array.from(document.querySelectorAll('[data-tb-morph]'))) {
|
|
80
|
+
const name = morphIdent(e.dataset['tbMorph']);
|
|
81
|
+
if (!among.has(name) || seen.has(name) || e.getClientRects().length === 0)
|
|
82
|
+
continue;
|
|
83
|
+
seen.add(name);
|
|
84
|
+
e.style.setProperty('view-transition-name', name);
|
|
85
|
+
named.push(e);
|
|
86
|
+
}
|
|
87
|
+
return seen;
|
|
88
|
+
}
|
|
89
|
+
/** The morph names of a screen not yet on the page. */
|
|
90
|
+
function morphsIn(screen) {
|
|
91
|
+
return new Set(Array.from(screen.querySelectorAll('[data-tb-morph]'), e => morphIdent(e.dataset['tbMorph'])));
|
|
92
|
+
}
|
|
93
|
+
function clearMorphs() {
|
|
94
|
+
for (const e of named)
|
|
95
|
+
e.style.removeProperty('view-transition-name');
|
|
96
|
+
named = [];
|
|
97
|
+
}
|
|
98
|
+
/** A name as the browser takes it: letters, digits, - and _, anything else spelled by its code. */
|
|
99
|
+
export function morphIdent(name) {
|
|
100
|
+
let out = 'tb-m-';
|
|
101
|
+
for (const ch of name)
|
|
102
|
+
out += /[A-Za-z0-9_-]/.test(ch) ? ch : `_${ch.codePointAt(0).toString(16)}_`;
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
// --- rows --------------------------------------------------------------------------
|
|
106
|
+
/** Where each row stood before the rows changed. */
|
|
107
|
+
export function rowPlaces(rows) {
|
|
108
|
+
const at = new Map();
|
|
109
|
+
for (const r of rows)
|
|
110
|
+
at.set(r, r.getBoundingClientRect());
|
|
111
|
+
return at;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* After the rows changed: those that stayed glide from where they were to where
|
|
115
|
+
* they are, the new ones fade in.
|
|
116
|
+
*/
|
|
117
|
+
export function moveRows(rows, was) {
|
|
118
|
+
const ms = duration();
|
|
119
|
+
for (const r of rows) {
|
|
120
|
+
const from = was.get(r);
|
|
121
|
+
if (from === undefined) {
|
|
122
|
+
r.animate([{ opacity: 0 }, { opacity: 1 }], { duration: ms, easing: EASE });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const to = r.getBoundingClientRect();
|
|
126
|
+
const dx = from.left - to.left;
|
|
127
|
+
const dy = from.top - to.top;
|
|
128
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5)
|
|
129
|
+
continue;
|
|
130
|
+
r.animate([{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }], { duration: ms, easing: EASE });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A row that went fades where it stood, out of the flow so the others close the gap:
|
|
135
|
+
* its cells keep their widths, as it no longer lies in its table.
|
|
136
|
+
*/
|
|
137
|
+
export function leaveRow(r, at) {
|
|
138
|
+
const widths = Array.from(r.children, c => c.getBoundingClientRect().width);
|
|
139
|
+
Array.from(r.children).forEach((c, i) => {
|
|
140
|
+
c.style.width = `${widths[i]}px`;
|
|
141
|
+
c.style.boxSizing = 'border-box';
|
|
142
|
+
});
|
|
143
|
+
r.classList.add('tb-leaving');
|
|
144
|
+
r.setAttribute('aria-hidden', 'true');
|
|
145
|
+
r.removeAttribute('tabindex');
|
|
146
|
+
Object.assign(r.style, { position: 'fixed', top: `${at.top}px`, left: `${at.left}px`, width: `${at.width}px`, height: `${at.height}px`, margin: '0' });
|
|
147
|
+
const a = r.animate([{ opacity: 1 }, { opacity: 0 }], { duration: duration() * 0.7, easing: EASE });
|
|
148
|
+
a.onfinish = () => r.remove();
|
|
149
|
+
a.oncancel = () => r.remove();
|
|
150
|
+
}
|
|
151
|
+
// --- shown and hidden --------------------------------------------------------------
|
|
152
|
+
/** The faces folding away now, so a face shown again stops folding. */
|
|
153
|
+
const folding = new WeakMap();
|
|
154
|
+
/** Whether a face is folding away now. */
|
|
155
|
+
export function isFolding(e) {
|
|
156
|
+
return folding.has(e);
|
|
157
|
+
}
|
|
158
|
+
/** A face shown again unfolds: from no height, if it lies among others one above another, and from clear. */
|
|
159
|
+
export function unfold(e) {
|
|
160
|
+
folding.get(e)?.cancel();
|
|
161
|
+
const h = e.getBoundingClientRect().height;
|
|
162
|
+
const stacked = stackedIn(e);
|
|
163
|
+
const frames = stacked && h > 0
|
|
164
|
+
? [{ height: '0px', opacity: 0, overflow: 'hidden' }, { height: `${h}px`, opacity: 1, overflow: 'hidden' }]
|
|
165
|
+
: [{ opacity: 0 }, { opacity: 1 }];
|
|
166
|
+
e.animate(frames, { duration: duration(), easing: EASE });
|
|
167
|
+
}
|
|
168
|
+
/** A face hidden folds away, and then done hides it. */
|
|
169
|
+
export function fold(e, done) {
|
|
170
|
+
const h = e.getBoundingClientRect().height;
|
|
171
|
+
const stacked = stackedIn(e);
|
|
172
|
+
const frames = stacked && h > 0
|
|
173
|
+
? [{ height: `${h}px`, opacity: 1, overflow: 'hidden' }, { height: '0px', opacity: 0, overflow: 'hidden', marginTop: '0px', marginBottom: '0px', paddingTop: '0px', paddingBottom: '0px' }]
|
|
174
|
+
: [{ opacity: 1 }, { opacity: 0 }];
|
|
175
|
+
const a = e.animate(frames, { duration: duration() * 0.8, easing: EASE });
|
|
176
|
+
folding.set(e, a);
|
|
177
|
+
a.onfinish = () => {
|
|
178
|
+
folding.delete(e);
|
|
179
|
+
done();
|
|
180
|
+
};
|
|
181
|
+
a.oncancel = () => folding.delete(e);
|
|
182
|
+
}
|
|
183
|
+
/** Whether a face lies among others one above another, so its height can open. */
|
|
184
|
+
function stackedIn(e) {
|
|
185
|
+
const p = e.parentElement;
|
|
186
|
+
if (p === null)
|
|
187
|
+
return false;
|
|
188
|
+
const s = getComputedStyle(p);
|
|
189
|
+
return !s.display.includes('flex') || s.flexDirection.startsWith('column');
|
|
190
|
+
}
|
package/dist/lib/host/net.js
CHANGED
|
@@ -250,8 +250,8 @@ function progressOf(t, target) {
|
|
|
250
250
|
return;
|
|
251
251
|
}
|
|
252
252
|
// a host mezzanine: in user, where the host's Trebol code is loaded
|
|
253
|
-
const i = ctxFind(t.rt.
|
|
254
|
-
const fn = i < 0 ? undefined : t.rt.
|
|
253
|
+
const i = ctxFind(t.rt.lib, intern('show-progress'));
|
|
254
|
+
const fn = i < 0 ? undefined : t.rt.lib.vals[i];
|
|
255
255
|
if (fn !== undefined)
|
|
256
256
|
spawn(sch, { data: [fn, target, done, total] }, 0);
|
|
257
257
|
};
|
|
@@ -349,6 +349,9 @@ native('http-request', '["Sends an HTTP request; used by fetch." url [url! strin
|
|
|
349
349
|
let problem = null;
|
|
350
350
|
try {
|
|
351
351
|
const init = { method: verb, headers, body, credentials, signal: ctl.signal };
|
|
352
|
+
// a page being hidden may close: a small request still goes (an Undo notice ending sends its delete)
|
|
353
|
+
if (typeof document !== 'undefined' && document.visibilityState === 'hidden' && (body === undefined || (typeof body === 'string' && body.length < 60000)))
|
|
354
|
+
init.keepalive = true;
|
|
352
355
|
const res = shown !== null && typeof XMLHttpRequest !== 'undefined'
|
|
353
356
|
? await sendXhr(url, init, shown.tell)
|
|
354
357
|
: await sendFetch(url, init, shown === null ? null : shown.tell);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PaletteEntry {
|
|
2
|
+
label: string;
|
|
3
|
+
/** What shows at the right: a kind, or the keys of a shortcut; '' for none. */
|
|
4
|
+
hint: string;
|
|
5
|
+
/** What the host needs to do it; the box never looks inside. */
|
|
6
|
+
target: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface PaletteHost {
|
|
9
|
+
/** What matches the text typed; the latest asked wins. */
|
|
10
|
+
search(text: string): Promise<PaletteEntry[]>;
|
|
11
|
+
pick(entry: PaletteEntry): void;
|
|
12
|
+
label: string;
|
|
13
|
+
placeholder: string;
|
|
14
|
+
nothing: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function paletteOpen(): boolean;
|
|
17
|
+
export declare function openPalette(h: PaletteHost): void;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// The palette: Ctrl+K (⌘K on a Mac) opens a box that finds what the page can do.
|
|
2
|
+
// What it finds comes from the dialect (ui-palette): the screens, the buttons and
|
|
3
|
+
// links on show, the items of their menus, and what the app's on-find gives. Here
|
|
4
|
+
// is only the box: typing, and choosing with the keys or the pointer.
|
|
5
|
+
let box = null;
|
|
6
|
+
let ids = 0;
|
|
7
|
+
export function paletteOpen() {
|
|
8
|
+
return box !== null && box.isConnected;
|
|
9
|
+
}
|
|
10
|
+
export function openPalette(h) {
|
|
11
|
+
if (paletteOpen())
|
|
12
|
+
return;
|
|
13
|
+
const before = document.activeElement;
|
|
14
|
+
const d = document.createElement('dialog');
|
|
15
|
+
d.className = 'tb-dialog tb-palette';
|
|
16
|
+
d.setAttribute('aria-label', h.label);
|
|
17
|
+
const listId = `tb-palette-${++ids}`;
|
|
18
|
+
const input = document.createElement('input');
|
|
19
|
+
input.className = 'tb-input tb-palette-input';
|
|
20
|
+
input.type = 'text';
|
|
21
|
+
input.placeholder = h.placeholder;
|
|
22
|
+
input.setAttribute('aria-label', h.label);
|
|
23
|
+
input.setAttribute('role', 'combobox');
|
|
24
|
+
input.setAttribute('aria-expanded', 'true');
|
|
25
|
+
input.setAttribute('aria-controls', listId);
|
|
26
|
+
input.setAttribute('aria-autocomplete', 'list');
|
|
27
|
+
input.autocomplete = 'off';
|
|
28
|
+
input.spellcheck = false;
|
|
29
|
+
const list = document.createElement('ul');
|
|
30
|
+
list.className = 'tb-palette-list';
|
|
31
|
+
list.id = listId;
|
|
32
|
+
list.setAttribute('role', 'listbox');
|
|
33
|
+
list.setAttribute('aria-label', h.label);
|
|
34
|
+
const none = document.createElement('p');
|
|
35
|
+
none.className = 'tb-palette-none';
|
|
36
|
+
none.textContent = h.nothing;
|
|
37
|
+
none.hidden = true;
|
|
38
|
+
d.append(input, list, none);
|
|
39
|
+
let entries = [];
|
|
40
|
+
let at = 0;
|
|
41
|
+
let asked = 0;
|
|
42
|
+
const mark = () => {
|
|
43
|
+
list.querySelectorAll('[role="option"]').forEach((o, i) => o.setAttribute('aria-selected', String(i === at)));
|
|
44
|
+
const chosen = list.children[at];
|
|
45
|
+
if (chosen !== undefined) {
|
|
46
|
+
input.setAttribute('aria-activedescendant', chosen.id);
|
|
47
|
+
chosen.scrollIntoView({ block: 'nearest' });
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
input.removeAttribute('aria-activedescendant');
|
|
51
|
+
};
|
|
52
|
+
const draw = () => {
|
|
53
|
+
list.replaceChildren(...entries.map((e, i) => {
|
|
54
|
+
const o = document.createElement('li');
|
|
55
|
+
o.className = 'tb-palette-option';
|
|
56
|
+
o.id = `${listId}-${i}`;
|
|
57
|
+
o.setAttribute('role', 'option');
|
|
58
|
+
const label = document.createElement('span');
|
|
59
|
+
label.textContent = e.label;
|
|
60
|
+
o.append(label);
|
|
61
|
+
if (e.hint !== '') {
|
|
62
|
+
const hint = document.createElement('span');
|
|
63
|
+
hint.className = 'tb-palette-hint';
|
|
64
|
+
hint.textContent = e.hint;
|
|
65
|
+
o.append(hint);
|
|
66
|
+
}
|
|
67
|
+
return o;
|
|
68
|
+
}));
|
|
69
|
+
none.hidden = entries.length > 0 || input.value === '';
|
|
70
|
+
mark();
|
|
71
|
+
};
|
|
72
|
+
const ask = async () => {
|
|
73
|
+
const n = ++asked;
|
|
74
|
+
const got = await h.search(input.value);
|
|
75
|
+
if (n !== asked || !d.isConnected)
|
|
76
|
+
return;
|
|
77
|
+
entries = got;
|
|
78
|
+
at = 0;
|
|
79
|
+
draw();
|
|
80
|
+
};
|
|
81
|
+
const close = () => {
|
|
82
|
+
d.close();
|
|
83
|
+
d.remove();
|
|
84
|
+
box = null;
|
|
85
|
+
if (before?.isConnected === true)
|
|
86
|
+
before.focus({ preventScroll: true });
|
|
87
|
+
};
|
|
88
|
+
const choose = (i) => {
|
|
89
|
+
const e = entries[i];
|
|
90
|
+
if (e === undefined)
|
|
91
|
+
return;
|
|
92
|
+
close();
|
|
93
|
+
h.pick(e);
|
|
94
|
+
};
|
|
95
|
+
input.addEventListener('input', () => void ask());
|
|
96
|
+
input.addEventListener('keydown', ev => {
|
|
97
|
+
const n = entries.length;
|
|
98
|
+
if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') {
|
|
99
|
+
ev.preventDefault();
|
|
100
|
+
if (n > 0)
|
|
101
|
+
at = (at + (ev.key === 'ArrowDown' ? 1 : n - 1)) % n;
|
|
102
|
+
mark();
|
|
103
|
+
}
|
|
104
|
+
else if (ev.key === 'Enter') {
|
|
105
|
+
ev.preventDefault();
|
|
106
|
+
choose(at);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
list.addEventListener('pointermove', ev => {
|
|
110
|
+
const o = ev.target.closest('[role="option"]');
|
|
111
|
+
const i = o === null ? -1 : Array.prototype.indexOf.call(list.children, o);
|
|
112
|
+
if (i >= 0 && i !== at) {
|
|
113
|
+
at = i;
|
|
114
|
+
mark();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
list.addEventListener('click', ev => {
|
|
118
|
+
const o = ev.target.closest('[role="option"]');
|
|
119
|
+
if (o !== null)
|
|
120
|
+
choose(Array.prototype.indexOf.call(list.children, o));
|
|
121
|
+
});
|
|
122
|
+
// Escape, or a click on the shade around it
|
|
123
|
+
d.addEventListener('cancel', ev => { ev.preventDefault(); close(); });
|
|
124
|
+
d.addEventListener('click', ev => { if (ev.target === d)
|
|
125
|
+
close(); });
|
|
126
|
+
box = d;
|
|
127
|
+
document.body.append(d);
|
|
128
|
+
d.showModal();
|
|
129
|
+
input.focus();
|
|
130
|
+
void ask();
|
|
131
|
+
}
|
|
@@ -28,6 +28,8 @@ export declare function makeHandle(kind: string, obj: unknown): Cell;
|
|
|
28
28
|
export declare function handleOf<T>(c: Cell, kind: string): T | null;
|
|
29
29
|
export declare function dropHandle(c: Cell): void;
|
|
30
30
|
export declare function makeScheduler(rt: Runtime, onError: Scheduler['onError']): Scheduler;
|
|
31
|
+
/** Whether a scheduler runs this runtime: a runtime of the core alone has none. */
|
|
32
|
+
export declare function hasScheduler(rt: Runtime): boolean;
|
|
31
33
|
/** The scheduler running a task's runtime. */
|
|
32
34
|
export declare function schedulerOf(t: Task): Scheduler;
|
|
33
35
|
/** Starts a task for `code` (a block bound to the user context or deeper). */
|
|
@@ -35,6 +35,10 @@ export function makeScheduler(rt, onError) {
|
|
|
35
35
|
schedulers.set(rt, sch);
|
|
36
36
|
return sch;
|
|
37
37
|
}
|
|
38
|
+
/** Whether a scheduler runs this runtime: a runtime of the core alone has none. */
|
|
39
|
+
export function hasScheduler(rt) {
|
|
40
|
+
return schedulers.has(rt);
|
|
41
|
+
}
|
|
38
42
|
/** The scheduler running a task's runtime. */
|
|
39
43
|
export function schedulerOf(t) {
|
|
40
44
|
const sch = schedulers.get(t.rt);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Runtime } from '../core/index.ts';
|
|
2
|
+
/** What travels on the channel: text is a value molded with mold/all. */
|
|
3
|
+
export interface Envelope {
|
|
4
|
+
from: string;
|
|
5
|
+
text: string;
|
|
6
|
+
/** The id of an ask: the one who sent it waits for an envelope that acks it. */
|
|
7
|
+
ask?: string;
|
|
8
|
+
acks?: string[];
|
|
9
|
+
/** A new owner: every tab sends again what it is still waiting for. */
|
|
10
|
+
fresh?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ChannelLike {
|
|
13
|
+
postMessage(e: Envelope): void;
|
|
14
|
+
onmessage: ((e: {
|
|
15
|
+
data: Envelope;
|
|
16
|
+
}) => void) | null;
|
|
17
|
+
close(): void;
|
|
18
|
+
}
|
|
19
|
+
export interface LocksLike {
|
|
20
|
+
request(name: string, options: {
|
|
21
|
+
ifAvailable: true;
|
|
22
|
+
}, fn: (lock: unknown) => Promise<void> | void): Promise<unknown>;
|
|
23
|
+
request(name: string, fn: (lock: unknown) => Promise<void> | void): Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
/** Where a runtime finds channels and locks: the browser's, or a test's. */
|
|
26
|
+
export interface ShareEnv {
|
|
27
|
+
channel(name: string): ChannelLike | null;
|
|
28
|
+
locks(): LocksLike | null;
|
|
29
|
+
}
|
|
30
|
+
/** Gives a runtime its own channels and locks (tests play several tabs in one process). */
|
|
31
|
+
export declare function setShareEnv(rt: Runtime, env: ShareEnv): void;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Host natives for shared machines: one machine for every tab or window of the
|
|
2
|
+
// same app. One tab owns it (it holds a Web Lock named after it) and runs it;
|
|
3
|
+
// the others keep a copy, which a BroadcastChannel keeps up to date and which
|
|
4
|
+
// sends its events to the owner. The machine engine (src/core/machine.ts)
|
|
5
|
+
// uses these natives only when the host has them.
|
|
6
|
+
import { K, NONE, TRUE, FALSE, string, block, text, throwError } from "../core/index.js";
|
|
7
|
+
import { native, value } from "../core/natives/define.js";
|
|
8
|
+
import { schedulerOf, hasScheduler, spawnHandler, taskResult, makeHandle, handleOf } from "./scheduler.js";
|
|
9
|
+
const browserEnv = {
|
|
10
|
+
channel: name => {
|
|
11
|
+
const B = globalThis.BroadcastChannel;
|
|
12
|
+
if (B === undefined)
|
|
13
|
+
return null;
|
|
14
|
+
const ch = new B(name);
|
|
15
|
+
// in Node a channel would keep the process alive
|
|
16
|
+
ch.unref?.();
|
|
17
|
+
return ch;
|
|
18
|
+
},
|
|
19
|
+
locks: () => globalThis.navigator?.locks ?? null,
|
|
20
|
+
};
|
|
21
|
+
const envs = new WeakMap();
|
|
22
|
+
/** Gives a runtime its own channels and locks (tests play several tabs in one process). */
|
|
23
|
+
export function setShareEnv(rt, env) {
|
|
24
|
+
envs.set(rt, env);
|
|
25
|
+
}
|
|
26
|
+
const envOf = (rt) => envs.get(rt) ?? browserEnv;
|
|
27
|
+
/** A lock held until the page goes. */
|
|
28
|
+
const forever = () => new Promise(() => { });
|
|
29
|
+
const str = (c) => text(c);
|
|
30
|
+
native('share-open', '["Opens the channel of a shared machine; none when the host has none." name [string!] heard [block!]]', (t, f) => {
|
|
31
|
+
// with no locks there is no telling who owns the machine, and with no scheduler (the core
|
|
32
|
+
// alone, as in Node with no host) nothing could hear the other tabs: it stays in this tab
|
|
33
|
+
const env = envOf(t.rt);
|
|
34
|
+
const ch = env.locks() === null || !hasScheduler(t.rt) ? null : env.channel(str(f.args[0]));
|
|
35
|
+
if (ch === null)
|
|
36
|
+
return value(NONE);
|
|
37
|
+
const sch = schedulerOf(t);
|
|
38
|
+
const heard = f.args[1];
|
|
39
|
+
const sh = { me: Math.random().toString(36).slice(2), ch, serial: 0, waiting: new Map() };
|
|
40
|
+
ch.onmessage = async ({ data: env }) => {
|
|
41
|
+
if (env.from === sh.me)
|
|
42
|
+
return;
|
|
43
|
+
try {
|
|
44
|
+
await taskResult(spawnHandler(sch, heard, { message: string(env.text), asked: env.ask === undefined ? NONE : string(env.ask) }));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// the scheduler has reported it
|
|
48
|
+
}
|
|
49
|
+
settle(sh, env.acks);
|
|
50
|
+
if (env.fresh)
|
|
51
|
+
for (const [id, w] of sh.waiting)
|
|
52
|
+
ch.postMessage({ from: sh.me, text: w.text, ask: id });
|
|
53
|
+
};
|
|
54
|
+
return value(makeHandle('share', sh));
|
|
55
|
+
});
|
|
56
|
+
function settle(sh, acks) {
|
|
57
|
+
for (const id of acks ?? []) {
|
|
58
|
+
const w = sh.waiting.get(id);
|
|
59
|
+
if (w === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
sh.waiting.delete(id);
|
|
62
|
+
w.done();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const notShared = () => throwError('script', 'bad-share', 'not the channel of a shared machine');
|
|
66
|
+
native('share-post', '["Sends a value to every other tab; acks are asks it answers, also this tab\'s own." channel [handle!] message [string!] acks [block!] fresh [logic!]]', (_t, f) => {
|
|
67
|
+
const sh = handleOf(f.args[0], 'share');
|
|
68
|
+
if (sh === null)
|
|
69
|
+
return notShared();
|
|
70
|
+
const acks = f.args[2].s.data.slice(f.args[2].i).map(str);
|
|
71
|
+
const env = { from: sh.me, text: str(f.args[1]) };
|
|
72
|
+
if (acks.length > 0)
|
|
73
|
+
env.acks = acks;
|
|
74
|
+
if (f.args[3].t === K.Logic && f.args[3].v)
|
|
75
|
+
env.fresh = true;
|
|
76
|
+
sh.ch.postMessage(env);
|
|
77
|
+
settle(sh, acks);
|
|
78
|
+
return value(NONE);
|
|
79
|
+
});
|
|
80
|
+
native('share-ask', '["Sends a value to the owner and waits until an answer acks it." channel [handle!] message [string!]]', (_t, f, v) => {
|
|
81
|
+
// called again with what the wait gave
|
|
82
|
+
if (f.phase === 1)
|
|
83
|
+
return value(v);
|
|
84
|
+
f.phase = 1;
|
|
85
|
+
const sh = handleOf(f.args[0], 'share');
|
|
86
|
+
if (sh === null)
|
|
87
|
+
return notShared();
|
|
88
|
+
const msg = str(f.args[1]);
|
|
89
|
+
const id = `${sh.me}-${++sh.serial}`;
|
|
90
|
+
return {
|
|
91
|
+
k: 'await',
|
|
92
|
+
p: new Promise(resolve => {
|
|
93
|
+
sh.waiting.set(id, { text: msg, done: () => resolve(NONE) });
|
|
94
|
+
sh.ch.postMessage({ from: sh.me, text: msg, ask: id });
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
native('share-asks', '["What this tab asked and is still waiting for, as a block of id and message." channel [handle!]]', (_t, f) => {
|
|
99
|
+
const sh = handleOf(f.args[0], 'share');
|
|
100
|
+
if (sh === null)
|
|
101
|
+
return notShared();
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const [id, w] of sh.waiting)
|
|
104
|
+
out.push(string(id), string(w.text));
|
|
105
|
+
return value(block(out));
|
|
106
|
+
});
|
|
107
|
+
native('share-lock', '["Takes the lock of a shared machine if it is free (true); else gives false and evaluates took when it comes free." name [string!] took [block!]]', (t, f, v) => {
|
|
108
|
+
if (f.phase === 1)
|
|
109
|
+
return value(v);
|
|
110
|
+
f.phase = 1;
|
|
111
|
+
const locks = envOf(t.rt).locks();
|
|
112
|
+
if (locks === null || !hasScheduler(t.rt))
|
|
113
|
+
return value(TRUE);
|
|
114
|
+
const sch = schedulerOf(t);
|
|
115
|
+
const name = str(f.args[0]);
|
|
116
|
+
const took = f.args[1];
|
|
117
|
+
return {
|
|
118
|
+
k: 'await',
|
|
119
|
+
p: new Promise(resolve => {
|
|
120
|
+
void locks.request(name, { ifAvailable: true }, lock => {
|
|
121
|
+
if (lock !== null) {
|
|
122
|
+
resolve(TRUE);
|
|
123
|
+
return forever();
|
|
124
|
+
}
|
|
125
|
+
resolve(FALSE);
|
|
126
|
+
void locks.request(name, () => {
|
|
127
|
+
spawnHandler(sch, took, {});
|
|
128
|
+
return forever();
|
|
129
|
+
});
|
|
130
|
+
return undefined;
|
|
131
|
+
});
|
|
132
|
+
}),
|
|
133
|
+
};
|
|
134
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CLASSIC: string;
|