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.
Files changed (300) hide show
  1. package/README.md +12 -1
  2. package/dist/cli.js +17097 -12238
  3. package/dist/fonts/OFL.txt +93 -0
  4. package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
  5. package/dist/fonts/inter-cyrillic.woff2 +0 -0
  6. package/dist/fonts/inter-greek-ext.woff2 +0 -0
  7. package/dist/fonts/inter-greek.woff2 +0 -0
  8. package/dist/fonts/inter-latin-ext.woff2 +0 -0
  9. package/dist/fonts/inter-latin.woff2 +0 -0
  10. package/dist/fonts/inter-vietnamese.woff2 +0 -0
  11. package/dist/lib/core/boot.js +12 -8
  12. package/dist/lib/core/eval.js +2 -2
  13. package/dist/lib/core/func.d.ts +4 -0
  14. package/dist/lib/core/machine/checks.d.ts +1 -0
  15. package/dist/lib/core/machine/checks.js +250 -0
  16. package/dist/lib/core/machine/events.d.ts +1 -0
  17. package/dist/lib/core/machine/events.js +365 -0
  18. package/dist/lib/core/machine/running.d.ts +1 -0
  19. package/dist/lib/core/machine/running.js +180 -0
  20. package/dist/lib/core/machine/shared.d.ts +1 -0
  21. package/dist/lib/core/machine/shared.js +123 -0
  22. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  23. package/dist/lib/core/machine/snapshot.js +244 -0
  24. package/dist/lib/core/machine/spec.d.ts +1 -0
  25. package/dist/lib/core/machine/spec.js +274 -0
  26. package/dist/lib/core/machine/words.d.ts +1 -0
  27. package/dist/lib/core/machine/words.js +98 -0
  28. package/dist/lib/core/machine.d.ts +1 -0
  29. package/dist/lib/core/machine.js +17 -0
  30. package/dist/lib/core/mezz.js +31 -0
  31. package/dist/lib/core/natives/control.js +2 -2
  32. package/dist/lib/core/natives/data.js +6 -1
  33. package/dist/lib/core/natives/series.js +59 -9
  34. package/dist/lib/core/natives/text.js +3 -1
  35. package/dist/lib/host/browser/calendar.d.ts +34 -0
  36. package/dist/lib/host/browser/calendar.js +268 -0
  37. package/dist/lib/host/browser/count.d.ts +15 -0
  38. package/dist/lib/host/browser/count.js +48 -0
  39. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  40. package/dist/lib/host/browser/dialogs.js +443 -0
  41. package/dist/lib/host/browser/drag.d.ts +70 -0
  42. package/dist/lib/host/browser/drag.js +268 -0
  43. package/dist/lib/host/browser/drawings.d.ts +30 -0
  44. package/dist/lib/host/browser/drawings.js +176 -0
  45. package/dist/lib/host/browser/events.d.ts +16 -0
  46. package/dist/lib/host/browser/events.js +125 -0
  47. package/dist/lib/host/browser/faces.d.ts +35 -0
  48. package/dist/lib/host/browser/faces.js +131 -0
  49. package/dist/lib/host/browser/fields.d.ts +16 -0
  50. package/dist/lib/host/browser/fields.js +322 -0
  51. package/dist/lib/host/browser/keys.d.ts +29 -0
  52. package/dist/lib/host/browser/keys.js +151 -0
  53. package/dist/lib/host/browser/lookup.d.ts +25 -0
  54. package/dist/lib/host/browser/lookup.js +275 -0
  55. package/dist/lib/host/browser/menus.d.ts +20 -0
  56. package/dist/lib/host/browser/menus.js +149 -0
  57. package/dist/lib/host/browser/mount.d.ts +92 -0
  58. package/dist/lib/host/browser/mount.js +448 -0
  59. package/dist/lib/host/browser/orbits.d.ts +90 -0
  60. package/dist/lib/host/browser/orbits.js +379 -0
  61. package/dist/lib/host/browser/page.d.ts +13 -0
  62. package/dist/lib/host/browser/page.js +35 -0
  63. package/dist/lib/host/browser/richtext.d.ts +19 -0
  64. package/dist/lib/host/browser/richtext.js +379 -0
  65. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  66. package/dist/lib/host/browser/row-faces.js +74 -0
  67. package/dist/lib/host/browser/screens.d.ts +37 -0
  68. package/dist/lib/host/browser/screens.js +140 -0
  69. package/dist/lib/host/browser/swipe.d.ts +31 -0
  70. package/dist/lib/host/browser/swipe.js +178 -0
  71. package/dist/lib/host/browser/sync.d.ts +24 -0
  72. package/dist/lib/host/browser/sync.js +450 -0
  73. package/dist/lib/host/browser/tables.d.ts +65 -0
  74. package/dist/lib/host/browser/tables.js +505 -0
  75. package/dist/lib/host/browser/times.d.ts +14 -0
  76. package/dist/lib/host/browser/times.js +114 -0
  77. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  78. package/dist/lib/host/browser/toolbars.js +129 -0
  79. package/dist/lib/host/browser/trees.d.ts +20 -0
  80. package/dist/lib/host/browser/trees.js +235 -0
  81. package/dist/lib/host/browser/uploads.d.ts +29 -0
  82. package/dist/lib/host/browser/uploads.js +370 -0
  83. package/dist/lib/host/browser/widget.d.ts +13 -0
  84. package/dist/lib/host/browser/widget.js +105 -0
  85. package/dist/lib/host/browser.d.ts +25 -0
  86. package/dist/lib/host/browser.js +129 -3964
  87. package/dist/lib/host/devlog.d.ts +11 -0
  88. package/dist/lib/host/devlog.js +13 -0
  89. package/dist/lib/host/devtools/console.d.ts +9 -0
  90. package/dist/lib/host/devtools/console.js +104 -0
  91. package/dist/lib/host/devtools/faces.d.ts +25 -0
  92. package/dist/lib/host/devtools/faces.js +169 -0
  93. package/dist/lib/host/devtools/log.d.ts +3 -0
  94. package/dist/lib/host/devtools/log.js +32 -0
  95. package/dist/lib/host/devtools/machines.d.ts +34 -0
  96. package/dist/lib/host/devtools/machines.js +212 -0
  97. package/dist/lib/host/devtools/read.d.ts +13 -0
  98. package/dist/lib/host/devtools/read.js +52 -0
  99. package/dist/lib/host/devtools/state.d.ts +90 -0
  100. package/dist/lib/host/devtools/state.js +123 -0
  101. package/dist/lib/host/devtools.d.ts +19 -0
  102. package/dist/lib/host/devtools.js +238 -0
  103. package/dist/lib/host/fonts/OFL.txt +93 -0
  104. package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  105. package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
  106. package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
  107. package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
  108. package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
  109. package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
  110. package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
  111. package/dist/lib/host/fonts.d.ts +11 -0
  112. package/dist/lib/host/fonts.js +30 -0
  113. package/dist/lib/host/icons.js +4 -0
  114. package/dist/lib/host/index.d.ts +5 -1
  115. package/dist/lib/host/index.js +110 -5
  116. package/dist/lib/host/js.d.ts +5 -0
  117. package/dist/lib/host/js.js +130 -0
  118. package/dist/lib/host/locale.d.ts +18 -0
  119. package/dist/lib/host/locale.js +75 -5
  120. package/dist/lib/host/markdown.d.ts +6 -0
  121. package/dist/lib/host/markdown.js +18 -0
  122. package/dist/lib/host/modules.d.ts +4 -0
  123. package/dist/lib/host/modules.js +157 -20
  124. package/dist/lib/host/motion.d.ts +32 -0
  125. package/dist/lib/host/motion.js +190 -0
  126. package/dist/lib/host/net.js +14 -3
  127. package/dist/lib/host/orbit.d.ts +121 -0
  128. package/dist/lib/host/orbit.js +374 -0
  129. package/dist/lib/host/palette.d.ts +17 -0
  130. package/dist/lib/host/palette.js +131 -0
  131. package/dist/lib/host/rows.d.ts +14 -0
  132. package/dist/lib/host/rows.js +29 -0
  133. package/dist/lib/host/scheduler.d.ts +8 -0
  134. package/dist/lib/host/scheduler.js +64 -36
  135. package/dist/lib/host/share.d.ts +31 -0
  136. package/dist/lib/host/share.js +134 -0
  137. package/dist/lib/host/theme/classic.d.ts +1 -0
  138. package/dist/lib/host/theme/classic.js +120 -0
  139. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  140. package/dist/lib/host/theme/cupertino.js +65 -0
  141. package/dist/lib/host/theme/data.d.ts +1 -0
  142. package/dist/lib/host/theme/data.js +109 -0
  143. package/dist/lib/host/theme/devtools.d.ts +1 -0
  144. package/dist/lib/host/theme/devtools.js +166 -0
  145. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  146. package/dist/lib/host/theme/dialogs.js +63 -0
  147. package/dist/lib/host/theme/fluent.d.ts +1 -0
  148. package/dist/lib/host/theme/fluent.js +64 -0
  149. package/dist/lib/host/theme/forms.d.ts +1 -0
  150. package/dist/lib/host/theme/forms.js +239 -0
  151. package/dist/lib/host/theme/fusion.d.ts +1 -0
  152. package/dist/lib/host/theme/fusion.js +66 -0
  153. package/dist/lib/host/theme/layout.d.ts +1 -0
  154. package/dist/lib/host/theme/layout.js +166 -0
  155. package/dist/lib/host/theme/media.d.ts +1 -0
  156. package/dist/lib/host/theme/media.js +106 -0
  157. package/dist/lib/host/theme/navigation.d.ts +1 -0
  158. package/dist/lib/host/theme/navigation.js +36 -0
  159. package/dist/lib/host/theme/panes.d.ts +1 -0
  160. package/dist/lib/host/theme/panes.js +99 -0
  161. package/dist/lib/host/theme/popups.d.ts +1 -0
  162. package/dist/lib/host/theme/popups.js +149 -0
  163. package/dist/lib/host/theme/responsive.d.ts +1 -0
  164. package/dist/lib/host/theme/responsive.js +103 -0
  165. package/dist/lib/host/theme/toasts.d.ts +1 -0
  166. package/dist/lib/host/theme/toasts.js +62 -0
  167. package/dist/lib/host/theme.js +19 -1179
  168. package/dist/lib/ui/dialect/events.trb +276 -0
  169. package/dist/lib/ui/dialect/faces.trb +135 -0
  170. package/dist/lib/ui/dialect/layout.trb +283 -0
  171. package/dist/lib/ui/dialect/palette.trb +87 -0
  172. package/dist/lib/ui/dialect/problems.trb +174 -0
  173. package/dist/lib/ui/dialect/reactions.trb +198 -0
  174. package/dist/lib/ui/dialect/rows.trb +208 -0
  175. package/dist/lib/ui/dialect/screens.trb +293 -0
  176. package/dist/lib/ui/dialect/steps.trb +203 -0
  177. package/dist/lib/ui/dialect/validation.trb +137 -0
  178. package/dist/lib/ui/dialect/view.trb +110 -0
  179. package/dist/lib/ui/dialect/walking.trb +98 -0
  180. package/dist/lib/ui/dialect/words.trb +70 -0
  181. package/dist/lib/ui/i18n.trb +23 -0
  182. package/dist/lib/ui/test.trb +12 -0
  183. package/dist/lib/ui/testing/actions.trb +421 -0
  184. package/dist/lib/ui/testing/faces.trb +148 -0
  185. package/dist/lib/ui/testing/server.trb +73 -0
  186. package/dist/lib/ui/ui.trb +25 -1234
  187. package/dist/trebol.js +4882 -1088
  188. package/editors/vscode/README.md +15 -0
  189. package/editors/vscode/language-configuration.json +28 -0
  190. package/editors/vscode/package.json +42 -0
  191. package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
  192. package/package.json +7 -3
  193. package/src/core/boot.ts +10 -7
  194. package/src/core/eval.ts +2 -2
  195. package/src/core/func.ts +4 -0
  196. package/src/core/machine/checks.ts +251 -0
  197. package/src/core/machine/events.ts +366 -0
  198. package/src/core/machine/running.ts +181 -0
  199. package/src/core/machine/shared.ts +124 -0
  200. package/src/core/machine/snapshot.ts +245 -0
  201. package/src/core/machine/spec.ts +275 -0
  202. package/src/core/machine/words.ts +99 -0
  203. package/src/core/machine.ts +20 -0
  204. package/src/core/mezz.ts +31 -0
  205. package/src/core/natives/control.ts +2 -2
  206. package/src/core/natives/data.ts +6 -1
  207. package/src/core/natives/parse.ts +1 -1
  208. package/src/core/natives/series.ts +55 -11
  209. package/src/core/natives/text.ts +2 -1
  210. package/src/host/browser/calendar.ts +264 -0
  211. package/src/host/browser/count.ts +48 -0
  212. package/src/host/browser/dialogs.ts +439 -0
  213. package/src/host/browser/drag.ts +278 -0
  214. package/src/host/browser/drawings.ts +178 -0
  215. package/src/host/browser/events.ts +117 -0
  216. package/src/host/browser/faces.ts +143 -0
  217. package/src/host/browser/fields.ts +315 -0
  218. package/src/host/browser/keys.ts +145 -0
  219. package/src/host/browser/lookup.ts +262 -0
  220. package/src/host/browser/menus.ts +146 -0
  221. package/src/host/browser/mount.ts +420 -0
  222. package/src/host/browser/orbits.ts +418 -0
  223. package/src/host/browser/page.ts +43 -0
  224. package/src/host/browser/richtext.ts +346 -0
  225. package/src/host/browser/row-faces.ts +75 -0
  226. package/src/host/browser/screens.ts +142 -0
  227. package/src/host/browser/swipe.ts +168 -0
  228. package/src/host/browser/sync.ts +354 -0
  229. package/src/host/browser/tables.ts +461 -0
  230. package/src/host/browser/times.ts +115 -0
  231. package/src/host/browser/toolbars.ts +126 -0
  232. package/src/host/browser/trees.ts +205 -0
  233. package/src/host/browser/uploads.ts +367 -0
  234. package/src/host/browser/widget.ts +103 -0
  235. package/src/host/browser.ts +128 -3747
  236. package/src/host/devlog.ts +16 -0
  237. package/src/host/devtools/console.ts +102 -0
  238. package/src/host/devtools/faces.ts +160 -0
  239. package/src/host/devtools/log.ts +34 -0
  240. package/src/host/devtools/machines.ts +208 -0
  241. package/src/host/devtools/read.ts +58 -0
  242. package/src/host/devtools/state.ts +148 -0
  243. package/src/host/devtools.ts +238 -0
  244. package/src/host/fonts/OFL.txt +93 -0
  245. package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
  246. package/src/host/fonts/inter-cyrillic.woff2 +0 -0
  247. package/src/host/fonts/inter-greek-ext.woff2 +0 -0
  248. package/src/host/fonts/inter-greek.woff2 +0 -0
  249. package/src/host/fonts/inter-latin-ext.woff2 +0 -0
  250. package/src/host/fonts/inter-latin.woff2 +0 -0
  251. package/src/host/fonts/inter-vietnamese.woff2 +0 -0
  252. package/src/host/fonts.ts +40 -0
  253. package/src/host/icons.ts +4 -0
  254. package/src/host/index.ts +110 -5
  255. package/src/host/js.ts +127 -0
  256. package/src/host/locale.ts +71 -5
  257. package/src/host/markdown.ts +18 -0
  258. package/src/host/modules.ts +150 -22
  259. package/src/host/motion.ts +204 -0
  260. package/src/host/net.ts +13 -3
  261. package/src/host/orbit.ts +432 -0
  262. package/src/host/palette.ts +139 -0
  263. package/src/host/rows.ts +30 -0
  264. package/src/host/scheduler.ts +67 -36
  265. package/src/host/share.ts +168 -0
  266. package/src/host/theme/classic.ts +121 -0
  267. package/src/host/theme/cupertino.ts +66 -0
  268. package/src/host/theme/data.ts +110 -0
  269. package/src/host/theme/devtools.ts +167 -0
  270. package/src/host/theme/dialogs.ts +64 -0
  271. package/src/host/theme/fluent.ts +65 -0
  272. package/src/host/theme/forms.ts +240 -0
  273. package/src/host/theme/fusion.ts +67 -0
  274. package/src/host/theme/layout.ts +167 -0
  275. package/src/host/theme/media.ts +107 -0
  276. package/src/host/theme/navigation.ts +37 -0
  277. package/src/host/theme/panes.ts +100 -0
  278. package/src/host/theme/popups.ts +150 -0
  279. package/src/host/theme/responsive.ts +104 -0
  280. package/src/host/theme/toasts.ts +63 -0
  281. package/src/host/theme.ts +19 -1179
  282. package/src/ui/dialect/events.trb +276 -0
  283. package/src/ui/dialect/faces.trb +135 -0
  284. package/src/ui/dialect/layout.trb +283 -0
  285. package/src/ui/dialect/palette.trb +87 -0
  286. package/src/ui/dialect/problems.trb +174 -0
  287. package/src/ui/dialect/reactions.trb +198 -0
  288. package/src/ui/dialect/rows.trb +208 -0
  289. package/src/ui/dialect/screens.trb +293 -0
  290. package/src/ui/dialect/steps.trb +203 -0
  291. package/src/ui/dialect/validation.trb +137 -0
  292. package/src/ui/dialect/view.trb +110 -0
  293. package/src/ui/dialect/walking.trb +98 -0
  294. package/src/ui/dialect/words.trb +70 -0
  295. package/src/ui/i18n.trb +23 -0
  296. package/src/ui/test.trb +12 -0
  297. package/src/ui/testing/actions.trb +421 -0
  298. package/src/ui/testing/faces.trb +148 -0
  299. package/src/ui/testing/server.trb +73 -0
  300. package/src/ui/ui.trb +25 -1234
@@ -0,0 +1,178 @@
1
+ // --- swipe ---------------------------------------------------------------------------
2
+ //
3
+ // On a phone, swiping a row of a table or list that has a menu to the left
4
+ // shows its first actions behind it, as mail apps do, the danger ones red, and
5
+ // More for the whole menu. A move more down than across still scrolls.
6
+ import {} from "../../core/index.js";
7
+ import { own, icon } from "./faces.js";
8
+ import { rowOf, el } from "./mount.js";
9
+ import { contextEntries } from "./events.js";
10
+ import { mountedAbove, dragging, swallowClick } from "./drag.js";
11
+ import { openMenu } from "./menus.js";
12
+ /** The row under the finger, and the one left open. */
13
+ export let swipe = null;
14
+ export let swiped = null;
15
+ export const SWIPE_BUTTON = 76;
16
+ export function swipeRows(node, f) {
17
+ node.classList.add('tb-swipe');
18
+ node.addEventListener('pointerdown', ev => {
19
+ if (ev.pointerType !== 'touch' || swipe !== null || !matchMedia('(max-width: 640px)').matches)
20
+ return;
21
+ const row = ev.target.closest('tr, li');
22
+ // a row of this face, not of one inside it
23
+ if (row === null || !rowOf.has(row) || mountedAbove(row)?.el !== node)
24
+ return;
25
+ if (swiped !== null && swiped.row !== row)
26
+ closeSwipe();
27
+ const open = swiped?.row === row ? swiped : null;
28
+ const box = open?.box ?? swipeBox(f, row);
29
+ if (box === null)
30
+ return;
31
+ swipe = {
32
+ face: f, row, x: ev.clientX, y: ev.clientY, id: ev.pointerId,
33
+ from: open?.at ?? 0, at: open?.at ?? 0, on: false, box, width: box.childElementCount * SWIPE_BUTTON,
34
+ };
35
+ });
36
+ }
37
+ /** The buttons behind a row: its first two plain actions, and More if the menu has others. */
38
+ export function swipeBox(f, row) {
39
+ const all = contextEntries(f, row);
40
+ const shown = all.filter(e => !e.divider && e.sub === undefined).slice(0, 2);
41
+ if (shown.length === 0)
42
+ return null;
43
+ const box = el('div', 'tb-swipe-actions');
44
+ // its corners are those of the row, or of the list a first or last row is the edge of
45
+ const rs = getComputedStyle(row);
46
+ const list = getComputedStyle(row.parentElement);
47
+ const first = row.previousElementSibling === null;
48
+ const last = row.nextElementSibling === null;
49
+ box.style.borderTopRightRadius = first && rs.borderTopRightRadius === '0px' ? list.borderTopRightRadius : rs.borderTopRightRadius;
50
+ box.style.borderBottomRightRadius = last && rs.borderBottomRightRadius === '0px' ? list.borderBottomRightRadius : rs.borderBottomRightRadius;
51
+ box.style.borderTopLeftRadius = rs.borderTopLeftRadius;
52
+ box.style.borderBottomLeftRadius = rs.borderBottomLeftRadius;
53
+ const button = (e, cls, run) => {
54
+ const b = el('button', cls);
55
+ b.type = 'button';
56
+ const svg = e.icon ? icon(e.icon) : null;
57
+ const text = el('span');
58
+ text.textContent = e.text;
59
+ b.append(...(svg !== null ? [svg] : []), text);
60
+ b.addEventListener('click', () => run(b));
61
+ box.append(b);
62
+ };
63
+ if (all.filter(e => !e.divider).length > shown.length) {
64
+ button({ text: own('more-actions'), icon: 'menu' }, 'tb-swipe-action tb-swipe-more', b => {
65
+ const r = b.getBoundingClientRect();
66
+ closeSwipe();
67
+ openMenu(all, r.left, r.bottom, row);
68
+ });
69
+ }
70
+ for (const e of shown.reverse()) {
71
+ button(e, e.danger ? 'tb-swipe-action tb-danger' : 'tb-swipe-action', () => {
72
+ closeSwipe();
73
+ e.run?.();
74
+ });
75
+ }
76
+ return box;
77
+ }
78
+ /** Shows the row moved to at (0 or less) and the buttons in the room it leaves. */
79
+ export function placeSwipe(s) {
80
+ s.row.style.transform = s.at === 0 ? '' : `translateX(${s.at}px)`;
81
+ // where the row ends without the move, so it holds while the row settles
82
+ const r = s.row.getBoundingClientRect();
83
+ const right = r.right - (new DOMMatrix(getComputedStyle(s.row).transform).m41);
84
+ Object.assign(s.box.style, {
85
+ top: `${r.top}px`, height: `${r.height}px`, left: `${right + s.at}px`, width: `${-s.at}px`,
86
+ });
87
+ }
88
+ export function settleSwipe(s, at) {
89
+ s.at = at;
90
+ s.row.classList.add('tb-swipe-settle');
91
+ s.box.classList.add('tb-swipe-settle');
92
+ placeSwipe(s);
93
+ if (at === 0) {
94
+ // the buttons go once the row is back
95
+ const done = () => { if (swiped !== s && swipe?.row !== s.row) {
96
+ s.box.remove();
97
+ s.row.classList.remove('tb-swipe-settle');
98
+ } };
99
+ s.row.addEventListener('transitionend', done, { once: true });
100
+ setTimeout(done, 300);
101
+ }
102
+ }
103
+ export function closeSwipe() {
104
+ const s = swiped;
105
+ if (s === null)
106
+ return;
107
+ swiped = null;
108
+ if (s.row.isConnected)
109
+ settleSwipe(s, 0);
110
+ else
111
+ s.box.remove();
112
+ }
113
+ export function onSwipeMove(ev) {
114
+ const s = swipe;
115
+ if (s === null || ev.pointerId !== s.id)
116
+ return;
117
+ const dx = ev.clientX - s.x;
118
+ const dy = ev.clientY - s.y;
119
+ if (!s.on) {
120
+ if (Math.abs(dy) > 10 && Math.abs(dy) >= Math.abs(dx)) {
121
+ swipe = null;
122
+ return;
123
+ }
124
+ if (Math.abs(dx) <= 10)
125
+ return;
126
+ // a row held long enough is being dragged, not swiped
127
+ if (dragging?.on) {
128
+ swipe = null;
129
+ return;
130
+ }
131
+ s.on = true;
132
+ s.row.classList.remove('tb-swipe-settle');
133
+ s.box.classList.remove('tb-swipe-settle');
134
+ if (!s.box.isConnected)
135
+ document.body.append(s.box);
136
+ }
137
+ ev.preventDefault();
138
+ // past the buttons it moves at a third of the finger, as if held back
139
+ const at = Math.min(0, s.from + dx);
140
+ s.at = at < -s.width ? -s.width + (at + s.width) / 3 : at;
141
+ placeSwipe(s);
142
+ }
143
+ export function onSwipeEnd(ev) {
144
+ const s = swipe;
145
+ if (s === null || ev.pointerId !== s.id)
146
+ return;
147
+ swipe = null;
148
+ if (!s.on) {
149
+ // a tap on the open row closes it, and does not select it
150
+ if (swiped?.row === s.row && ev.type === 'pointerup') {
151
+ closeSwipe();
152
+ swallowNextClick();
153
+ }
154
+ return;
155
+ }
156
+ swallowNextClick();
157
+ const open = ev.type === 'pointerup' && s.at < -s.width / 2;
158
+ if (open)
159
+ swiped = s;
160
+ else if (swiped?.row === s.row)
161
+ swiped = null;
162
+ settleSwipe(s, open ? -s.width : 0);
163
+ }
164
+ /** The click that ends a move is not a click. */
165
+ export function swallowNextClick() {
166
+ addEventListener('click', swallowClick, true);
167
+ setTimeout(() => removeEventListener('click', swallowClick, true), 0);
168
+ }
169
+ /** A touch outside the open row and its buttons, or a scroll, closes it. */
170
+ export function outsideSwipe(ev) {
171
+ const s = swiped;
172
+ if (s === null)
173
+ return;
174
+ const t = ev.target;
175
+ if (ev.type === 'pointerdown' && t !== null && (s.box.contains(t) || s.row.contains(t)))
176
+ return;
177
+ closeSwipe();
178
+ }
@@ -0,0 +1,24 @@
1
+ import { type Cell, type ObjectCell } from '../../core/index.ts';
2
+ import { type Mounted } from './mount.ts';
3
+ export declare function sync(m: Mounted): void;
4
+ /**
5
+ * A screen is made away from the page; the page keeps the one it has until `entering`
6
+ * ends, or shows the new one empty, as gray bars, if its on-enter takes long.
7
+ */
8
+ export declare function placeScreen(m: Mounted, box: HTMLElement): void;
9
+ export declare function settleScreen(box: HTMLElement, f: ObjectCell): void;
10
+ /** Puts the screen made last on the page, when the browser has its picture of it; one entering since waits for its own. */
11
+ export declare function showComing(box: HTMLElement, f: ObjectCell, loading: boolean): void;
12
+ /** How long, in ms, a screen's on-enter may take before the screen comes without its data. */
13
+ export declare const LOADING_AFTER = 300;
14
+ export declare let loadingTimer: ReturnType<typeof setTimeout> | null;
15
+ /** Sets a spacing property to a step of the theme's scale, or back to the stylesheet's. */
16
+ export declare function space(e: HTMLElement, prop: string, v: Cell): void;
17
+ /** Sets the face-driven classes, keeping the base classes from build. */
18
+ export declare function setExtra(e: HTMLElement, cls: string[]): void;
19
+ /**
20
+ * Runs the reactions whose facets changed in this round, at once, so the repaint
21
+ * that follows shows them: ui-react, given the faces on the page that have any.
22
+ */
23
+ export declare function react(): void;
24
+ export declare function syncDirty(): void;
@@ -0,0 +1,450 @@
1
+ // --- syncing -----------------------------------------------------------------------
2
+ import { K, form, intern, text, blockOf } from "../../core/index.js";
3
+ import { translate } from "../index.js";
4
+ import { runNow } from "../scheduler.js";
5
+ import { devLog } from "../devlog.js";
6
+ import { changeScreen, mayMove, unfold, fold, isFolding } from "../motion.js";
7
+ import { get, str, optionText, entriesOf, isGroup, optionsOf, optionsKey, fillSelect, own, display, flag, word } from "./faces.js";
8
+ import { host, byNode, byCtx, dirty, reactors, newReactor, reacting, fire, el, INPUTS, syncMark, iconLabel, appendChildren, setNewReactor, setReacting } from "./mount.js";
9
+ import { isData } from "./drag.js";
10
+ import { rangeText } from "./calendar.js";
11
+ import { shortcutAria, shortcutLabel } from "./keys.js";
12
+ import { countRun } from "./count.js";
13
+ import { syncSlider, syncProgress, syncIcon, required, syncRadio } from "./fields.js";
14
+ import { syncMedia, syncPhoto, syncUpload } from "./uploads.js";
15
+ import { syncWidget } from "./widget.js";
16
+ import { syncLookup } from "./lookup.js";
17
+ import { syncCanvas, syncChart } from "./drawings.js";
18
+ import { syncOrbit } from "./orbits.js";
19
+ import { syncRowsField, placeEntries } from "./row-faces.js";
20
+ import { syncRich } from "./richtext.js";
21
+ import { syncRows, morphName } from "./tables.js";
22
+ import { syncTree } from "./trees.js";
23
+ import { syncToolbar, syncBreadcrumb } from "./toolbars.js";
24
+ import { syncDialog, syncTabs, syncSteps, syncSplit } from "./dialogs.js";
25
+ import { comingScreen, enteredScreen, setComingScreen } from "./screens.js";
26
+ export function sync(m) {
27
+ const f = m.face;
28
+ const style = word(f, 'style') ?? '';
29
+ const role = word(f, 'role');
30
+ const t = str(f, 'text');
31
+ const hidden = flag(f, 'hidden');
32
+ const err = str(f, 'error');
33
+ const cls = [];
34
+ // a face shown or hidden after it was first on the page unfolds or folds away
35
+ const wasHidden = m.el.classList.contains('tb-hidden');
36
+ const turned = style !== 'dialog' && hidden !== wasHidden && m.el.dataset['tb'] !== undefined && m.el.isConnected && mayMove();
37
+ if (hidden && style !== 'dialog' && !(turned || isFolding(m.el)))
38
+ cls.push('tb-hidden');
39
+ if (flag(f, 'fill'))
40
+ cls.push('tb-fill');
41
+ if (flag(f, 'narrow-only'))
42
+ cls.push('tb-narrow-only');
43
+ if (flag(f, 'wide-only'))
44
+ cls.push('tb-wide-only');
45
+ if (flag(f, 'fit'))
46
+ cls.push('tb-fit');
47
+ if (flag(f, 'drop'))
48
+ cls.push('tb-drop-zone');
49
+ if (role !== null && !INPUTS.has(style))
50
+ cls.push(`tb-${role}`);
51
+ const size = word(f, 'size');
52
+ if (size !== null)
53
+ cls.push(`tb-${size}`);
54
+ const align = word(f, 'align');
55
+ if (align !== null && style === 'row')
56
+ cls.push(`tb-${align}`);
57
+ const valign = word(f, 'valign');
58
+ if (valign !== null && style === 'row')
59
+ cls.push(`tb-${valign}`);
60
+ if (err !== null)
61
+ cls.push('tb-invalid');
62
+ if (flag(f, 'pending'))
63
+ cls.push('tb-pending');
64
+ setExtra(m.el, cls);
65
+ // the rows of a table or list carry its morph name, each with its key
66
+ const morph = style === 'table' || style === 'list' ? null : morphName(get(f, 'morph'));
67
+ if (morph !== null)
68
+ m.el.dataset['tbMorph'] = morph;
69
+ else
70
+ delete m.el.dataset['tbMorph'];
71
+ if (turned && hidden && !isFolding(m.el))
72
+ fold(m.el, () => { if (flag(m.face, 'hidden'))
73
+ setExtra(m.el, [...(m.el.dataset['tb'] ?? '').split(' ').filter(Boolean), 'tb-hidden']); });
74
+ else if (!hidden && (turned || isFolding(m.el)))
75
+ unfold(m.el);
76
+ // shown as it is, but it and its children cannot be used
77
+ m.el.inert = flag(f, 'inert');
78
+ // a face you can drag takes the focus, so the keyboard reaches its menu and moves it
79
+ if (flag(f, 'drag') && !isData(m) && m.el.tabIndex < 0)
80
+ m.el.tabIndex = 0;
81
+ space(m.el, 'padding', get(f, 'pad'));
82
+ space(m.el, 'gap', get(f, 'gap'));
83
+ if (style === 'radio')
84
+ return syncRadio(m, err);
85
+ if (style === 'slider')
86
+ return syncSlider(m, err);
87
+ if (style === 'upload')
88
+ return syncUpload(m, err);
89
+ if (style === 'photo')
90
+ return syncPhoto(m, err);
91
+ if (style === 'widget')
92
+ return syncWidget(m, err);
93
+ if (style === 'lookup')
94
+ return syncLookup(m, err);
95
+ if (style === 'rich')
96
+ return syncRich(m, err);
97
+ if (m.input !== null) {
98
+ if (m.label !== null) {
99
+ m.label.textContent = t ?? '';
100
+ m.label.classList.toggle('tb-required', required(f) && style !== 'check');
101
+ }
102
+ const v = get(f, 'value');
103
+ if (m.input instanceof HTMLInputElement && m.input.type === 'checkbox') {
104
+ m.input.checked = v.t === K.Logic && v.v;
105
+ }
106
+ else {
107
+ // options given by code after the face was made
108
+ if (m.input instanceof HTMLSelectElement) {
109
+ if (m.input.dataset.options !== optionsKey(f))
110
+ fillSelect(m.input, f);
111
+ }
112
+ const want = v.t === K.None ? str(f, 'typed') ?? '' : style === 'date-range' ? rangeText(v)
113
+ : style === 'money' || style === 'date' || style === 'time' ? display(v) : form(v);
114
+ // never fight the user's typing: with the focus, only a value code set is drawn (set-values
115
+ // after Enter sent the form); a read-only field has no typing to fight
116
+ const theirs = document.activeElement === m.input && !flag(f, 'readonly') && (m.typing > 0 || v === m.typed);
117
+ if (!theirs && m.input.value !== want)
118
+ m.input.value = want;
119
+ const hint = str(f, 'hint');
120
+ if (m.input instanceof HTMLSelectElement) {
121
+ const select = m.input;
122
+ // a required choice shows its hint until one is picked, and cannot be put back to none;
123
+ // one not required keeps the empty option to clear it
124
+ const empty = select.options[0];
125
+ empty.textContent = hint ?? own('choose');
126
+ empty.disabled = empty.hidden = required(f);
127
+ optionsOf(f).forEach((o, i) => {
128
+ const opt = select.options[i + 1];
129
+ if (opt)
130
+ opt.textContent = optionText(o);
131
+ });
132
+ const groups = select.querySelectorAll('optgroup');
133
+ entriesOf(f).filter(isGroup).forEach((g, i) => {
134
+ if (groups[i])
135
+ groups[i].label = translate(g.title, host.rt);
136
+ });
137
+ }
138
+ else if (hint !== null)
139
+ m.input.placeholder = hint;
140
+ }
141
+ const readonly = flag(f, 'readonly');
142
+ // text can be read-only; a choice or a checkbox can only be disabled
143
+ const typing = m.input instanceof HTMLTextAreaElement || (m.input instanceof HTMLInputElement && m.input.type !== 'checkbox');
144
+ if (typing)
145
+ m.input.readOnly = readonly;
146
+ m.input.disabled = flag(f, 'disabled') || (readonly && !typing);
147
+ if (style === 'date' || style === 'date-range' || style === 'time') {
148
+ const pick = m.input.nextElementSibling;
149
+ pick.disabled = m.input.disabled || readonly;
150
+ const what = style === 'date' ? 'choose-date' : style === 'time' ? 'choose-time' : 'choose-dates';
151
+ pick.setAttribute('aria-label', t !== null ? own(`${what}-of`, t) : own(what));
152
+ }
153
+ m.input.setAttribute('aria-required', required(f) ? 'true' : 'false');
154
+ m.input.setAttribute('aria-invalid', err !== null ? 'true' : 'false');
155
+ if (m.error !== null)
156
+ m.error.textContent = err ?? '';
157
+ return;
158
+ }
159
+ switch (style) {
160
+ case 'title':
161
+ case 'heading':
162
+ case 'text': {
163
+ const tv = get(f, 'text');
164
+ if (flag(f, 'count') && countRun(m, tv))
165
+ break;
166
+ m.el.textContent = tv.t === K.None ? '' : tv.t === K.Map || tv.t === K.Word ? translate(tv, host.rt) : display(tv);
167
+ break;
168
+ }
169
+ case 'tile': {
170
+ (m.label ?? m.el).textContent = t ?? '';
171
+ syncMark(m);
172
+ break;
173
+ }
174
+ case 'button':
175
+ case 'link': {
176
+ (m.label ?? m.el).textContent = t ?? '';
177
+ const named = iconLabel(f);
178
+ if (named !== null)
179
+ m.el.setAttribute('aria-label', named);
180
+ else
181
+ m.el.removeAttribute('aria-label');
182
+ const keys = str(f, 'shortcut');
183
+ if (keys !== null)
184
+ m.el.setAttribute('aria-keyshortcuts', shortcutAria(keys));
185
+ else
186
+ m.el.removeAttribute('aria-keyshortcuts');
187
+ // in a toolbar, narrow screens show only the icon, so the text goes in the tooltip too
188
+ const bar = m.label !== null && m.el.parentElement?.classList.contains('tb-toolbar') === true;
189
+ const tip = named ?? (keys !== null || bar ? t : null);
190
+ m.el.title = tip === null ? '' : keys === null ? tip : `${tip} (${shortcutLabel(keys)})`;
191
+ break;
192
+ }
193
+ // its data may have changed: the dialect deals the cards to their lanes again, if they moved
194
+ case 'board':
195
+ void fire('ui-board', f);
196
+ break;
197
+ case 'progress':
198
+ syncProgress(m);
199
+ return;
200
+ case 'canvas':
201
+ syncCanvas(m);
202
+ return;
203
+ case 'chart':
204
+ syncChart(m);
205
+ return;
206
+ case 'orbit':
207
+ syncOrbit(m);
208
+ return;
209
+ case 'icon':
210
+ syncIcon(m);
211
+ return;
212
+ case 'video':
213
+ case 'audio':
214
+ syncMedia(m);
215
+ return;
216
+ case 'image': {
217
+ const img = m.el;
218
+ const src = str(f, 'value') ?? '';
219
+ if (img.getAttribute('src') !== src)
220
+ img.src = src;
221
+ img.alt = t ?? '';
222
+ img.classList.toggle('tb-round', flag(f, 'round'));
223
+ // a size, as in Red: the image fills it, cut to fit
224
+ const ext = get(f, 'extent');
225
+ img.style.width = ext.t === K.Pair ? `${ext.x}px` : '';
226
+ img.style.height = ext.t === K.Pair ? `${ext.y}px` : '';
227
+ return;
228
+ }
229
+ case 'table':
230
+ case 'list':
231
+ syncRows(m);
232
+ return;
233
+ case 'rows':
234
+ syncRowsField(m, err);
235
+ break;
236
+ case 'tree':
237
+ syncTree(m);
238
+ return;
239
+ case 'breadcrumb':
240
+ syncBreadcrumb(m);
241
+ return;
242
+ case 'toolbar': {
243
+ if (t !== null)
244
+ m.el.setAttribute('aria-label', t);
245
+ else
246
+ m.el.removeAttribute('aria-label');
247
+ break;
248
+ }
249
+ case 'desktop':
250
+ case 'backdrop': {
251
+ const src = str(f, 'value');
252
+ m.el.style.backgroundImage = src !== null ? `url(${JSON.stringify(src)})` : '';
253
+ break;
254
+ }
255
+ case 'dialog':
256
+ syncDialog(m);
257
+ break;
258
+ case 'tabs':
259
+ syncTabs(m);
260
+ return;
261
+ case 'steps':
262
+ syncSteps(m);
263
+ return;
264
+ // a step that comes to apply or not changes the bar of its steps
265
+ case 'step': {
266
+ const up = m.el.parentElement === null ? undefined : byNode.get(m.el.parentElement);
267
+ if (up !== undefined)
268
+ syncSteps(up);
269
+ break;
270
+ }
271
+ case 'split':
272
+ syncSplit(m);
273
+ return;
274
+ case 'tab':
275
+ if (m.button !== null)
276
+ m.button.textContent = t ?? '';
277
+ break;
278
+ case 'panel': {
279
+ let h = m.el.querySelector(':scope > .tb-panel-title');
280
+ if (t === null)
281
+ h?.remove();
282
+ else {
283
+ if (h === null) {
284
+ h = el('h2', 'tb-panel-title');
285
+ m.el.prepend(h);
286
+ }
287
+ h.textContent = t;
288
+ }
289
+ break;
290
+ }
291
+ case 'scroll': {
292
+ if (t !== null)
293
+ m.el.setAttribute('aria-label', t);
294
+ else
295
+ m.el.removeAttribute('aria-label');
296
+ break;
297
+ }
298
+ case 'grid': {
299
+ const cols = get(f, 'cols');
300
+ m.el.style.setProperty('--tb-cols', cols.t === K.Integer ? String(cols.v) : '2');
301
+ // [1 4 1]: a column per weight, never narrower than what it holds
302
+ const weights = cols.t === K.Block ? cols.s.data.slice(cols.i).filter(c => c.t === K.Integer) : [];
303
+ if (weights.length > 0)
304
+ m.el.style.setProperty('--tb-tracks', weights.map(w => `minmax(min-content, ${form(w)}fr)`).join(' '));
305
+ else
306
+ m.el.style.removeProperty('--tb-tracks');
307
+ break;
308
+ }
309
+ }
310
+ if (style === 'toolbar')
311
+ syncToolbar(m.el);
312
+ if (m.el instanceof HTMLButtonElement) {
313
+ // a submit stays focusable while the form has errors; clicking it shows them
314
+ if (flag(f, 'submit'))
315
+ m.el.setAttribute('aria-disabled', flag(f, 'disabled') ? 'true' : 'false');
316
+ else
317
+ m.el.disabled = flag(f, 'disabled');
318
+ }
319
+ // children replaced by code: rebuild this container
320
+ const kids = get(f, 'pane');
321
+ if (kids.t === K.Block && m.kids?.s !== kids.s) {
322
+ m.kids = kids;
323
+ if (style === 'rows') {
324
+ placeEntries(m);
325
+ void fire('ui-pane', f);
326
+ return;
327
+ }
328
+ const box = m.box ?? m.el;
329
+ if (style === 'screens')
330
+ placeScreen(m, box);
331
+ else {
332
+ const keep = box.querySelector(':scope > .tb-panel-title');
333
+ box.replaceChildren(...(keep ? [keep] : []));
334
+ appendChildren(box, f, style);
335
+ }
336
+ // let the dialect link the new faces to their view and form
337
+ void fire('ui-pane', f);
338
+ }
339
+ if (style === 'screens')
340
+ settleScreen(m.box ?? m.el, f);
341
+ }
342
+ /**
343
+ * A screen is made away from the page; the page keeps the one it has until `entering`
344
+ * ends, or shows the new one empty, as gray bars, if its on-enter takes long.
345
+ */
346
+ export function placeScreen(m, box) {
347
+ const coming = el('div');
348
+ setComingScreen(coming);
349
+ appendChildren(coming, m.face, 'screens');
350
+ settleScreen(box, m.face);
351
+ }
352
+ export function settleScreen(box, f) {
353
+ const entering = flag(f, 'entering');
354
+ box.toggleAttribute('aria-busy', entering);
355
+ if (entering) {
356
+ // an on-enter that keeps the user waiting: the new screen comes now, gray where its data will be
357
+ if (comingScreen !== null && loadingTimer === null) {
358
+ loadingTimer = setTimeout(() => {
359
+ loadingTimer = null;
360
+ if (comingScreen === null || !flag(f, 'entering'))
361
+ return;
362
+ showComing(box, f, true);
363
+ }, LOADING_AFTER);
364
+ }
365
+ return;
366
+ }
367
+ if (loadingTimer !== null)
368
+ clearTimeout(loadingTimer);
369
+ loadingTimer = null;
370
+ if (comingScreen === null)
371
+ delete box.dataset['tbLoading'];
372
+ else
373
+ showComing(box, f, false);
374
+ }
375
+ /** Puts the screen made last on the page, when the browser has its picture of it; one entering since waits for its own. */
376
+ export function showComing(box, f, loading) {
377
+ if (comingScreen === null)
378
+ return;
379
+ changeScreen(box, comingScreen, () => {
380
+ const entering = flag(f, 'entering');
381
+ if (comingScreen === null || (entering && !loading))
382
+ return;
383
+ box.replaceChildren(...comingScreen.childNodes);
384
+ setComingScreen(null);
385
+ box.toggleAttribute('data-tb-loading', entering);
386
+ enteredScreen(box);
387
+ });
388
+ }
389
+ /** How long, in ms, a screen's on-enter may take before the screen comes without its data. */
390
+ export const LOADING_AFTER = 300;
391
+ export let loadingTimer = null;
392
+ /** Sets a spacing property to a step of the theme's scale, or back to the stylesheet's. */
393
+ export function space(e, prop, v) {
394
+ if (v.t === K.Integer)
395
+ e.style.setProperty(prop, `var(--tb-space-${v.v})`);
396
+ else
397
+ e.style.removeProperty(prop);
398
+ }
399
+ /** Sets the face-driven classes, keeping the base classes from build. */
400
+ export function setExtra(e, cls) {
401
+ const prev = (e.dataset['tb'] ?? '').split(' ').filter(Boolean);
402
+ for (const c of prev)
403
+ if (!cls.includes(c))
404
+ e.classList.remove(c);
405
+ for (const c of cls)
406
+ e.classList.add(c);
407
+ e.dataset['tb'] = cls.join(' ');
408
+ }
409
+ /**
410
+ * Runs the reactions whose facets changed in this round, at once, so the repaint
411
+ * that follows shows them: ui-react, given the faces on the page that have any.
412
+ */
413
+ export function react() {
414
+ for (const m of reactors)
415
+ if (!m.el.isConnected && comingScreen?.contains(m.el) !== true)
416
+ reactors.delete(m);
417
+ if (reacting !== null || reactors.size === 0 || (dirty.length === 0 && !newReactor))
418
+ return;
419
+ setNewReactor(false);
420
+ const faces = blockOf(K.Block, [...reactors].map(m => m.face));
421
+ const ht = runNow(host.sch, { data: [{ t: K.Word, sym: intern('ui-react'), bind: host.rt.lib }, faces] }, 0);
422
+ const warn = (t) => {
423
+ if (t.state !== 'done' || t.result.t !== K.Block)
424
+ return;
425
+ for (const c of t.result.s.data) {
426
+ console.warn(`Trebol: ${text(c)}`);
427
+ devLog.note('warning', text(c));
428
+ }
429
+ };
430
+ if (ht.state === 'done')
431
+ warn(ht);
432
+ else if (ht.state !== 'failed') {
433
+ setReacting(ht);
434
+ ht.watchers.push(t => {
435
+ setReacting(null);
436
+ // what changed while it waited is checked at the end of this round
437
+ setNewReactor(true);
438
+ warn(t);
439
+ });
440
+ }
441
+ }
442
+ export function syncDirty() {
443
+ for (const ctx of dirty) {
444
+ ctx.dirty = false;
445
+ const m = byCtx.get(ctx);
446
+ if (m !== undefined && (m.el.isConnected || comingScreen?.contains(m.el)))
447
+ sync(m);
448
+ }
449
+ dirty.length = 0;
450
+ }