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.
Files changed (256) hide show
  1. package/README.md +2 -0
  2. package/dist/cli.js +10040 -7519
  3. package/dist/lib/core/boot.js +10 -7
  4. package/dist/lib/core/eval.js +2 -2
  5. package/dist/lib/core/machine/checks.d.ts +1 -0
  6. package/dist/lib/core/machine/checks.js +250 -0
  7. package/dist/lib/core/machine/events.d.ts +1 -0
  8. package/dist/lib/core/machine/events.js +365 -0
  9. package/dist/lib/core/machine/running.d.ts +1 -0
  10. package/dist/lib/core/machine/running.js +180 -0
  11. package/dist/lib/core/machine/shared.d.ts +1 -0
  12. package/dist/lib/core/machine/shared.js +123 -0
  13. package/dist/lib/core/machine/snapshot.d.ts +1 -0
  14. package/dist/lib/core/machine/snapshot.js +244 -0
  15. package/dist/lib/core/machine/spec.d.ts +1 -0
  16. package/dist/lib/core/machine/spec.js +274 -0
  17. package/dist/lib/core/machine/words.d.ts +1 -0
  18. package/dist/lib/core/machine/words.js +98 -0
  19. package/dist/lib/core/machine.d.ts +1 -0
  20. package/dist/lib/core/machine.js +17 -0
  21. package/dist/lib/core/mezz.js +31 -0
  22. package/dist/lib/core/natives/control.js +1 -1
  23. package/dist/lib/core/natives/data.js +6 -1
  24. package/dist/lib/core/natives/series.js +49 -9
  25. package/dist/lib/core/natives/text.js +0 -1
  26. package/dist/lib/host/browser/calendar.d.ts +34 -0
  27. package/dist/lib/host/browser/calendar.js +268 -0
  28. package/dist/lib/host/browser/count.d.ts +15 -0
  29. package/dist/lib/host/browser/count.js +48 -0
  30. package/dist/lib/host/browser/dialogs.d.ts +39 -0
  31. package/dist/lib/host/browser/dialogs.js +443 -0
  32. package/dist/lib/host/browser/drag.d.ts +70 -0
  33. package/dist/lib/host/browser/drag.js +268 -0
  34. package/dist/lib/host/browser/drawings.d.ts +30 -0
  35. package/dist/lib/host/browser/drawings.js +176 -0
  36. package/dist/lib/host/browser/events.d.ts +16 -0
  37. package/dist/lib/host/browser/events.js +125 -0
  38. package/dist/lib/host/browser/faces.d.ts +35 -0
  39. package/dist/lib/host/browser/faces.js +131 -0
  40. package/dist/lib/host/browser/fields.d.ts +16 -0
  41. package/dist/lib/host/browser/fields.js +322 -0
  42. package/dist/lib/host/browser/keys.d.ts +29 -0
  43. package/dist/lib/host/browser/keys.js +151 -0
  44. package/dist/lib/host/browser/lookup.d.ts +25 -0
  45. package/dist/lib/host/browser/lookup.js +275 -0
  46. package/dist/lib/host/browser/menus.d.ts +20 -0
  47. package/dist/lib/host/browser/menus.js +149 -0
  48. package/dist/lib/host/browser/mount.d.ts +92 -0
  49. package/dist/lib/host/browser/mount.js +448 -0
  50. package/dist/lib/host/browser/orbits.d.ts +90 -0
  51. package/dist/lib/host/browser/orbits.js +379 -0
  52. package/dist/lib/host/browser/page.d.ts +13 -0
  53. package/dist/lib/host/browser/page.js +35 -0
  54. package/dist/lib/host/browser/richtext.d.ts +19 -0
  55. package/dist/lib/host/browser/richtext.js +379 -0
  56. package/dist/lib/host/browser/row-faces.d.ts +5 -0
  57. package/dist/lib/host/browser/row-faces.js +74 -0
  58. package/dist/lib/host/browser/screens.d.ts +37 -0
  59. package/dist/lib/host/browser/screens.js +140 -0
  60. package/dist/lib/host/browser/swipe.d.ts +31 -0
  61. package/dist/lib/host/browser/swipe.js +178 -0
  62. package/dist/lib/host/browser/sync.d.ts +24 -0
  63. package/dist/lib/host/browser/sync.js +450 -0
  64. package/dist/lib/host/browser/tables.d.ts +65 -0
  65. package/dist/lib/host/browser/tables.js +505 -0
  66. package/dist/lib/host/browser/times.d.ts +14 -0
  67. package/dist/lib/host/browser/times.js +114 -0
  68. package/dist/lib/host/browser/toolbars.d.ts +17 -0
  69. package/dist/lib/host/browser/toolbars.js +129 -0
  70. package/dist/lib/host/browser/trees.d.ts +20 -0
  71. package/dist/lib/host/browser/trees.js +235 -0
  72. package/dist/lib/host/browser/uploads.d.ts +29 -0
  73. package/dist/lib/host/browser/uploads.js +370 -0
  74. package/dist/lib/host/browser/widget.d.ts +13 -0
  75. package/dist/lib/host/browser/widget.js +105 -0
  76. package/dist/lib/host/browser.d.ts +25 -0
  77. package/dist/lib/host/browser.js +84 -4812
  78. package/dist/lib/host/devtools/console.d.ts +9 -0
  79. package/dist/lib/host/devtools/console.js +104 -0
  80. package/dist/lib/host/devtools/faces.d.ts +25 -0
  81. package/dist/lib/host/devtools/faces.js +169 -0
  82. package/dist/lib/host/devtools/log.d.ts +3 -0
  83. package/dist/lib/host/devtools/log.js +32 -0
  84. package/dist/lib/host/devtools/machines.d.ts +34 -0
  85. package/dist/lib/host/devtools/machines.js +212 -0
  86. package/dist/lib/host/devtools/read.d.ts +13 -0
  87. package/dist/lib/host/devtools/read.js +52 -0
  88. package/dist/lib/host/devtools/state.d.ts +90 -0
  89. package/dist/lib/host/devtools/state.js +123 -0
  90. package/dist/lib/host/devtools.d.ts +15 -19
  91. package/dist/lib/host/devtools.js +39 -427
  92. package/dist/lib/host/fonts.js +4 -3
  93. package/dist/lib/host/icons.js +4 -0
  94. package/dist/lib/host/index.d.ts +3 -1
  95. package/dist/lib/host/index.js +107 -4
  96. package/dist/lib/host/locale.d.ts +18 -0
  97. package/dist/lib/host/locale.js +75 -5
  98. package/dist/lib/host/markdown.d.ts +4 -0
  99. package/dist/lib/host/markdown.js +8 -0
  100. package/dist/lib/host/modules.js +118 -19
  101. package/dist/lib/host/motion.d.ts +32 -0
  102. package/dist/lib/host/motion.js +190 -0
  103. package/dist/lib/host/net.js +5 -2
  104. package/dist/lib/host/palette.d.ts +17 -0
  105. package/dist/lib/host/palette.js +131 -0
  106. package/dist/lib/host/scheduler.d.ts +2 -0
  107. package/dist/lib/host/scheduler.js +4 -0
  108. package/dist/lib/host/share.d.ts +31 -0
  109. package/dist/lib/host/share.js +134 -0
  110. package/dist/lib/host/theme/classic.d.ts +1 -0
  111. package/dist/lib/host/theme/classic.js +120 -0
  112. package/dist/lib/host/theme/cupertino.d.ts +1 -0
  113. package/dist/lib/host/theme/cupertino.js +65 -0
  114. package/dist/lib/host/theme/data.d.ts +1 -0
  115. package/dist/lib/host/theme/data.js +109 -0
  116. package/dist/lib/host/theme/devtools.d.ts +1 -0
  117. package/dist/lib/host/theme/devtools.js +166 -0
  118. package/dist/lib/host/theme/dialogs.d.ts +1 -0
  119. package/dist/lib/host/theme/dialogs.js +63 -0
  120. package/dist/lib/host/theme/fluent.d.ts +1 -0
  121. package/dist/lib/host/theme/fluent.js +64 -0
  122. package/dist/lib/host/theme/forms.d.ts +1 -0
  123. package/dist/lib/host/theme/forms.js +239 -0
  124. package/dist/lib/host/theme/fusion.d.ts +1 -0
  125. package/dist/lib/host/theme/fusion.js +66 -0
  126. package/dist/lib/host/theme/layout.d.ts +1 -0
  127. package/dist/lib/host/theme/layout.js +166 -0
  128. package/dist/lib/host/theme/media.d.ts +1 -0
  129. package/dist/lib/host/theme/media.js +106 -0
  130. package/dist/lib/host/theme/navigation.d.ts +1 -0
  131. package/dist/lib/host/theme/navigation.js +36 -0
  132. package/dist/lib/host/theme/panes.d.ts +1 -0
  133. package/dist/lib/host/theme/panes.js +99 -0
  134. package/dist/lib/host/theme/popups.d.ts +1 -0
  135. package/dist/lib/host/theme/popups.js +149 -0
  136. package/dist/lib/host/theme/responsive.d.ts +1 -0
  137. package/dist/lib/host/theme/responsive.js +103 -0
  138. package/dist/lib/host/theme/toasts.d.ts +1 -0
  139. package/dist/lib/host/theme/toasts.js +62 -0
  140. package/dist/lib/host/theme.js +19 -1384
  141. package/dist/lib/ui/dialect/events.trb +276 -0
  142. package/dist/lib/ui/dialect/faces.trb +135 -0
  143. package/dist/lib/ui/dialect/layout.trb +283 -0
  144. package/dist/lib/ui/dialect/palette.trb +87 -0
  145. package/dist/lib/ui/dialect/problems.trb +174 -0
  146. package/dist/lib/ui/dialect/reactions.trb +198 -0
  147. package/dist/lib/ui/dialect/rows.trb +208 -0
  148. package/dist/lib/ui/dialect/screens.trb +293 -0
  149. package/dist/lib/ui/dialect/steps.trb +203 -0
  150. package/dist/lib/ui/dialect/validation.trb +137 -0
  151. package/dist/lib/ui/dialect/view.trb +110 -0
  152. package/dist/lib/ui/dialect/walking.trb +98 -0
  153. package/dist/lib/ui/dialect/words.trb +70 -0
  154. package/dist/lib/ui/i18n.trb +17 -0
  155. package/dist/lib/ui/test.trb +3 -556
  156. package/dist/lib/ui/testing/actions.trb +421 -0
  157. package/dist/lib/ui/testing/faces.trb +148 -0
  158. package/dist/lib/ui/testing/server.trb +73 -0
  159. package/dist/lib/ui/ui.trb +25 -1675
  160. package/dist/trebol.js +4463 -1891
  161. package/package.json +1 -1
  162. package/src/core/boot.ts +9 -6
  163. package/src/core/eval.ts +2 -2
  164. package/src/core/machine/checks.ts +251 -0
  165. package/src/core/machine/events.ts +366 -0
  166. package/src/core/machine/running.ts +181 -0
  167. package/src/core/machine/shared.ts +124 -0
  168. package/src/core/machine/snapshot.ts +245 -0
  169. package/src/core/machine/spec.ts +275 -0
  170. package/src/core/machine/words.ts +99 -0
  171. package/src/core/machine.ts +20 -0
  172. package/src/core/mezz.ts +31 -0
  173. package/src/core/natives/control.ts +1 -1
  174. package/src/core/natives/data.ts +6 -1
  175. package/src/core/natives/parse.ts +1 -1
  176. package/src/core/natives/series.ts +47 -11
  177. package/src/core/natives/text.ts +0 -1
  178. package/src/host/browser/calendar.ts +264 -0
  179. package/src/host/browser/count.ts +48 -0
  180. package/src/host/browser/dialogs.ts +439 -0
  181. package/src/host/browser/drag.ts +278 -0
  182. package/src/host/browser/drawings.ts +178 -0
  183. package/src/host/browser/events.ts +117 -0
  184. package/src/host/browser/faces.ts +143 -0
  185. package/src/host/browser/fields.ts +315 -0
  186. package/src/host/browser/keys.ts +145 -0
  187. package/src/host/browser/lookup.ts +262 -0
  188. package/src/host/browser/menus.ts +146 -0
  189. package/src/host/browser/mount.ts +420 -0
  190. package/src/host/browser/orbits.ts +418 -0
  191. package/src/host/browser/page.ts +43 -0
  192. package/src/host/browser/richtext.ts +346 -0
  193. package/src/host/browser/row-faces.ts +75 -0
  194. package/src/host/browser/screens.ts +142 -0
  195. package/src/host/browser/swipe.ts +168 -0
  196. package/src/host/browser/sync.ts +354 -0
  197. package/src/host/browser/tables.ts +461 -0
  198. package/src/host/browser/times.ts +115 -0
  199. package/src/host/browser/toolbars.ts +126 -0
  200. package/src/host/browser/trees.ts +205 -0
  201. package/src/host/browser/uploads.ts +367 -0
  202. package/src/host/browser/widget.ts +103 -0
  203. package/src/host/browser.ts +82 -4612
  204. package/src/host/devtools/console.ts +102 -0
  205. package/src/host/devtools/faces.ts +160 -0
  206. package/src/host/devtools/log.ts +34 -0
  207. package/src/host/devtools/machines.ts +208 -0
  208. package/src/host/devtools/read.ts +58 -0
  209. package/src/host/devtools/state.ts +148 -0
  210. package/src/host/devtools.ts +39 -442
  211. package/src/host/fonts.ts +4 -3
  212. package/src/host/icons.ts +4 -0
  213. package/src/host/index.ts +107 -4
  214. package/src/host/locale.ts +71 -5
  215. package/src/host/markdown.ts +9 -0
  216. package/src/host/modules.ts +117 -21
  217. package/src/host/motion.ts +204 -0
  218. package/src/host/net.ts +4 -2
  219. package/src/host/palette.ts +139 -0
  220. package/src/host/scheduler.ts +5 -0
  221. package/src/host/share.ts +168 -0
  222. package/src/host/theme/classic.ts +121 -0
  223. package/src/host/theme/cupertino.ts +66 -0
  224. package/src/host/theme/data.ts +110 -0
  225. package/src/host/theme/devtools.ts +167 -0
  226. package/src/host/theme/dialogs.ts +64 -0
  227. package/src/host/theme/fluent.ts +65 -0
  228. package/src/host/theme/forms.ts +240 -0
  229. package/src/host/theme/fusion.ts +67 -0
  230. package/src/host/theme/layout.ts +167 -0
  231. package/src/host/theme/media.ts +107 -0
  232. package/src/host/theme/navigation.ts +37 -0
  233. package/src/host/theme/panes.ts +100 -0
  234. package/src/host/theme/popups.ts +150 -0
  235. package/src/host/theme/responsive.ts +104 -0
  236. package/src/host/theme/toasts.ts +63 -0
  237. package/src/host/theme.ts +19 -1384
  238. package/src/ui/dialect/events.trb +276 -0
  239. package/src/ui/dialect/faces.trb +135 -0
  240. package/src/ui/dialect/layout.trb +283 -0
  241. package/src/ui/dialect/palette.trb +87 -0
  242. package/src/ui/dialect/problems.trb +174 -0
  243. package/src/ui/dialect/reactions.trb +198 -0
  244. package/src/ui/dialect/rows.trb +208 -0
  245. package/src/ui/dialect/screens.trb +293 -0
  246. package/src/ui/dialect/steps.trb +203 -0
  247. package/src/ui/dialect/validation.trb +137 -0
  248. package/src/ui/dialect/view.trb +110 -0
  249. package/src/ui/dialect/walking.trb +98 -0
  250. package/src/ui/dialect/words.trb +70 -0
  251. package/src/ui/i18n.trb +17 -0
  252. package/src/ui/test.trb +3 -556
  253. package/src/ui/testing/actions.trb +421 -0
  254. package/src/ui/testing/faces.trb +148 -0
  255. package/src/ui/testing/server.trb +73 -0
  256. package/src/ui/ui.trb +25 -1675
@@ -0,0 +1,283 @@
1
+ ; A part of the UI dialect: see ui.trb, whose words it shares.
2
+
3
+ ; --- laying out -----------------------------------------------------------------
4
+
5
+ ; Labels (`search: field`, `table clients`) are local to the layout, as R3
6
+ ; planned for its VID: each layout gets an object holding them, and the
7
+ ; layout's blocks (its handlers too) are bound to it. `global search: field`
8
+ ; sets a global word instead.
9
+
10
+ layout: function [
11
+ "Turns a block of the UI dialect into a view face; /only gives the block of faces."
12
+ spec [block!]
13
+ /only "Return the faces, not a view holding them"
14
+ /local ev b w
15
+ ] [
16
+ ; a copy, so laying out the same block twice never shares bindings
17
+ spec: copy/deep spec
18
+ labels: copy []
19
+ either only [
20
+ out: ui-build spec labels
21
+ ] [
22
+ ; on-xxx handlers and its width before the first face belong to the view itself
23
+ events: copy []
24
+ width: none
25
+ parse spec [any [
26
+ p: set ev word! if (event-word? ev) set b block! (ui-known-event p ev append events reduce [ev b])
27
+ | 'width set w ['small | 'medium | 'large | 'fill] (width: w)
28
+ ] body:]
29
+ out: make select styles 'view [pane: ui-build body labels]
30
+ unless empty? events [out/events: events]
31
+ out/size: width
32
+ ]
33
+ bind-labels spec labels copy []
34
+ morphs either only [out] [reduce [out]]
35
+ out
36
+ ]
37
+
38
+ ; Binds a laid-out block to an object of its labels and the given [word: value ...].
39
+ bind-labels: function [spec [block!] labels [block!] words [block!] /local w f] [
40
+ foreach [w f] labels [append words reduce [to set-word! w f]]
41
+ unless empty? words [bind spec make object! words]
42
+ ]
43
+
44
+ ; Works out the morph names given as blocks once the layout's words are bound: in
45
+ ; [client id] the first word is the name as written, and what follows is evaluated.
46
+ morphs: function [faces [block!]] [
47
+ if ui-checking [exit]
48
+ foreach f faces [foreach g all-faces f [
49
+ if all [block? m: g/morph not empty? m word? first m] [g/morph: append reduce [first m] reduce next m]
50
+ ]]
51
+ ]
52
+
53
+ ; Keeps a label for a face: in the layout's labels, or as a global word.
54
+ label-face: function [label labels [block!] global? [logic!] f] [
55
+ either global? [set label f] [
56
+ w: to word! label
57
+ either p: find/skip labels w 2 [p/2: f] [append labels reduce [w f]]
58
+ ]
59
+ ]
60
+
61
+ ; A text of the interface: a string, a text per language (a map), or a word of
62
+ ; the dictionary written as a lit-word ('save). Faces keep it as given and the
63
+ ; host shows it in the active language, so set-language translates them.
64
+ text-rule: [string! | map! | lit-word!]
65
+ text-of: func [t] [either lit-word? :t [to word! t] [t]]
66
+
67
+ ; The faces of a block of the dialect; labels collects [word face ...].
68
+ build-faces: function [
69
+ spec [block!] labels [block!]
70
+ /local label global? style-word f proto n s b w a i v ev p pos later
71
+ ] [
72
+ out: copy []
73
+ ; what starts the next face
74
+ face-start: [set-word! | 'global | set w word! if (select styles w)]
75
+ modifier: [
76
+ ; ui-check reads view compose [...] with its parens in it: menu (looks)
77
+ if (ui-checking) opt [set w word! if (select ui-takes w)] some paren!
78
+ | set s [string! | map!] (either f/text [f/hint: s] [f/text: s])
79
+ ; a word of the dictionary: button 'save (in a link, a lit-word is the screen)
80
+ | if (f/style <> 'link) set v lit-word! (v: to word! v either f/text [f/hint: v] [f/text: v])
81
+ | p: set ev word! if (event-word? ev) set b block! (
82
+ ; a widget's element fires events of its own: on-moved
83
+ unless any [f/tag f/style = 'widget] [ui-known-event p ev]
84
+ unless f/events [f/events: copy []]
85
+ append f/events reduce [ev b]
86
+ )
87
+ | pos: set b block! (
88
+ case [
89
+ ; grid [1 4 1] [...]: the weight of each column, then the children
90
+ all [f/style = 'grid none? f/pane not empty? b parse b [some integer!]] [f/cols: b]
91
+ ; rows items [...]: the fields of a row; a second block is the action
92
+ all [f/style = 'rows none? f/template] [f/template: b]
93
+ find container-styles f/style [
94
+ ; --- in a toolbar is a separator
95
+ f/pane: build-faces either f/style = 'toolbar [replace/all copy b '--- 'divider] [b] labels
96
+ if f/style = 'form [steps-take-submits f]
97
+ if all [f/style = 'split 2 <> length? f/pane] [
98
+ ui-problem pos "split takes two faces, one per pane"
99
+ ]
100
+ ]
101
+ ; board tasks by status [todo "To do" ...]: its lanes; a second block is the action
102
+ all [f/style = 'board none? f/lanes] [f/lanes: lanes-of b]
103
+ find data-styles f/style [f/columns: columns-of b]
104
+ ; the first block holds the items, the second is the action
105
+ all [f/style = 'breadcrumb none? f/data] [f/data: crumbs-of b]
106
+ ; orbit [focus ... nodes [...]]: what it shows; a second block is the action
107
+ all [f/style = 'orbit none? f/data] [f/data: orbit-of b]
108
+ ; widget <geo-map> [zoom: 12]: its properties; a second block is the action
109
+ all [f/style = 'widget none? f/props] [f/props: either ui-checking [make object! []] [make object! b]]
110
+ f/style = 'canvas [f/draw: b]
111
+ f/style = 'tabs [f/pane: tabs-of b labels]
112
+ f/style = 'steps [f/pane: either f/flow [steps-flow-of f b labels] [steps-of f b labels]]
113
+ f/style = 'screens [f/data: screens-of b]
114
+ all [find [choice radio] f/style none? f/options] [f/options: options-of b]
115
+ true [f/action: b]
116
+ ]
117
+ )
118
+ | set i issue! (f/icon: i)
119
+ | set v [file! | url! | percent!] (f/value: v)
120
+ ; a link to a screen: link "Clients" 'clients, link "Ada" 'client/42
121
+ | set v lit-word! (f/value: to word! v)
122
+ | set v lit-path! (f/value: to path! v)
123
+ ; slider volume "Volume" 0 100: the least and the most it takes
124
+ | if (f/style = 'slider) set a number! set n number! (add-rule f reduce ['min a] add-rule f reduce ['max n])
125
+ | 'step set n number! if (find [slider time] f/style) (f/step: n)
126
+ | set n integer! (f/cols: n)
127
+ | set p pair! (f/extent: p)
128
+ | set w word! if (all [f/style = 'chart find chart-kinds w]) (f/kind: w)
129
+ | 'min set n [number! | money! | date! | time!] (add-rule f reduce ['min n])
130
+ | 'max set n [number! | money! | date! | time!] (add-rule f reduce ['max n])
131
+ | 'length set a integer! set n integer! (add-rule f reduce ['length a n])
132
+ | 'pattern set b block! (add-rule f reduce ['pattern b])
133
+ | 'accept set b block! (f/accept: b)
134
+ | 'poster set v [file! | url!] (f/poster: v)
135
+ | 'captions set v [file! | url! | block!] (f/captions: v)
136
+ ; muted names a role elsewhere, and loop a function, so a video keeps them in fields of its own
137
+ | set w word! if (all [find media-flags w find media-styles f/style]) (
138
+ poke f select [muted silent loop looping autoplay autoplay] w true
139
+ )
140
+ | 'known set v map! (f/known: v)
141
+ | 'links set v map! (f/links: v)
142
+ | 'match set w word! (add-rule f reduce ['match w])
143
+ | 'check set b block! (add-rule f reduce ['check b])
144
+ | 'check-async set b block! (add-rule f reduce ['check-async b])
145
+ | 'calc set b block! (add-reaction f 'calc b false f/readonly: true)
146
+ | 'is set b block! (add-reaction f 'is b false)
147
+ | 'react (later: false) opt ['later (later: true)] set b block! (add-reaction f 'react b later)
148
+ | 'width set w word! (f/size: w)
149
+ | pos: set w ['pad | 'gap] [set n integer! | 'none (n: 0) | 'wide (n: 6)] (poke f w spacing n pos)
150
+ | 'menu set b block! (f/menu: menu-of b)
151
+ | 'morph set v [lit-word! | block!] (f/morph: either block? v [v] [to word! v])
152
+ ; tile #folder "Records" mark #list "List": the label goes right after the mark's icon
153
+ | 'mark set v issue! set s text-rule (f/mark: v f/mark-text: text-of s)
154
+ | 'by set w word! if (f/style = 'board) (f/field: w)
155
+ | 'card set b block! if (f/style = 'board) (f/card: columns-of b)
156
+ | 'key set s string! (f/shortcut: s)
157
+ | 'key set w word! (f/key: w)
158
+ | 'sorted set b block! (f/sorted: sort-order b)
159
+ | set w word! if (find roles w) (f/role: w)
160
+ | set w word! if (find sizes w) (f/size: w)
161
+ | set w word! if (find aligns w) (f/align: w)
162
+ | set w word! if (all [f/style = 'row find valigns w]) (f/valign: w)
163
+ | set w word! if (find flags w) (poke f w true)
164
+ | set w word! if (find simple-rules w) (add-rule f reduce [w])
165
+ | set w word! if (select custom-rules w) (add-rule f reduce [w])
166
+ ; money price "Price" EUR
167
+ | set w word! if (all [f/style = 'money parse form w [3 letter]]) (f/currency: to word! uppercase form w)
168
+ ; steps flow [...]: a machine leads the steps (check, which runs nothing, takes the word as one)
169
+ | set w word! ahead block! if (all [f/style = 'steps not f/flow any [ui-checking machine? attempt [get w]]]) (f/flow: w)
170
+ ]
171
+ parse spec [any [
172
+ (label: none global?: false)
173
+ opt ['global (global?: true)]
174
+ opt [set label set-word!]
175
+ [
176
+ ; a face that compose puts in: check takes what follows as words of a face it cannot know
177
+ if (ui-checking) paren! (f: make face []) any modifier
178
+ | pos: set style-word word! if (proto: select styles style-word) (
179
+ f: make proto []
180
+ f/place: loaded-at pos
181
+ append out f
182
+ if label [label-face label labels global? f]
183
+ )
184
+ ; widget <geo-map> place "Place": the element comes before the name
185
+ opt [if (f/style = 'widget) set v tag! (f/tag: to string! v)]
186
+ opt [if (find input-styles f/style) set n word! if (field-name? n) (f/name: n)]
187
+ ; chart bar income [...]: the kind comes before the label
188
+ opt [if (f/style = 'chart) set n word! if (find chart-kinds n) (f/kind: n)]
189
+ ; table clients [...] is the same as clients: table [...]
190
+ opt [if (any [find data-styles f/style f/style = 'orbit]) set n word! if (field-name? n) (label-face n labels global? f)]
191
+ any [
192
+ modifier
193
+ ; a mistyped style starts a face of its own: what follows it is that face's
194
+ | pos: not face-start skip (ui-problem pos ui-stray f first pos) opt [
195
+ if (ui-meant-style first pos) any [not face-start skip]
196
+ ]
197
+ ]
198
+ (if f/style = 'rows [rows-fill f])
199
+ (if f/style = 'slider [slider-fill f pos])
200
+ (if all [f/style = 'time f/step any [not integer? f/step f/step < 1 f/step > 720]] [
201
+ ui-problem pos "a time's step is a whole number of minutes from 1 to 720"
202
+ ])
203
+ (if f/style = 'board [
204
+ unless f/lanes [ui-problem pos "a board takes a block with a word and a label for each lane"]
205
+ unless f/field [ui-problem pos "a board takes by and the field that names the lane of a card: by status"]
206
+ board-fill f
207
+ ])
208
+ ; not a style: a problem, then on to the next face
209
+ | pos: skip (
210
+ w: first pos
211
+ ui-problem pos case [
212
+ not word? :w [rejoin ["a face starts with a style, not " ui-shown :w]]
213
+ find ui-dialect-words w [rejoin [w " is not a style; it goes after one"]]
214
+ true [rejoin [w " is not a style" ui-suggest w words-of styles]]
215
+ ]
216
+ ) any [not face-start skip]
217
+ ]
218
+ ]]
219
+ out
220
+ ]
221
+
222
+ ; A slider goes from 0 to 100 unless told, one at a time, and starts at its least.
223
+ slider-fill: function [f place [block!]] [
224
+ unless rule-of f 'min [add-rule f copy [min 0]]
225
+ unless rule-of f 'max [add-rule f copy [max 100]]
226
+ low: rule-of f 'min high: rule-of f 'max
227
+ unless all [number? low number? high low < high] [
228
+ ui-problem place "a slider takes its least and its most as two numbers, the least first: 0 100"
229
+ exit
230
+ ]
231
+ if all [f/step any [f/step <= 0 f/step > (high - low)]] [
232
+ ui-problem place "a slider's step is a number above 0 and no more than its most less its least"
233
+ ]
234
+ if none? f/value [f/value: low]
235
+ ]
236
+
237
+ ; Where a slider stands for a number given to it: within its least and most.
238
+ slider-at: function [f v] [
239
+ unless number? :v [return f/value]
240
+ max rule-of f 'min min rule-of f 'max v
241
+ ]
242
+
243
+ spacing: func [n [integer!] place [block!]] [
244
+ if all [n >= 0 n <= 7] [return n]
245
+ ui-problem place rejoin [first place " takes a step from 0 to 7"]
246
+ 0
247
+ ]
248
+
249
+ ; [name "Name" email] -> [name "Name" email "email"]
250
+ ; A column of images keeps what it is with its label: [photo "" image round] -> [photo ["" image round]]
251
+ columns-of: function [spec [block!] /local w label kind p] [
252
+ out: copy []
253
+ parse spec [any [
254
+ set w word! (label: form w kind: none) opt [set label text-rule]
255
+ opt ['image (kind: copy [image]) opt ['round (append kind 'round)]]
256
+ (
257
+ label: text-of label
258
+ append out w
259
+ append/only out either kind [head insert/only kind label] [label]
260
+ )
261
+ | p: skip (ui-problem p "table columns are words, each with an optional label, then image or image round") to end
262
+ ]]
263
+ out
264
+ ]
265
+
266
+ ; [name desc] -> [name desc], checked
267
+ sort-order: function [b [block!]] [
268
+ unless parse b [word! ['asc | 'desc]] [ui-problem b "sorted takes a column and asc or desc"]
269
+ copy b
270
+ ]
271
+
272
+ ; ["General" [...] "Advanced" [...]] -> a tab face per pair
273
+ tabs-of: function [spec [block!] labels [block!] /local p] [
274
+ out: copy []
275
+ parse spec [any [
276
+ set label text-rule set b block! (
277
+ label: text-of label
278
+ append out make select styles 'tab [text: label pane: build-faces b labels]
279
+ )
280
+ | p: skip (ui-problem p "tabs take a label and a block per tab") to end
281
+ ]]
282
+ out
283
+ ]
@@ -0,0 +1,87 @@
1
+ ; A part of the UI dialect: see ui.trb, whose words it shares.
2
+
3
+ ; --- the palette -----------------------------------------------------------------
4
+ ;
5
+ ; Ctrl+K opens a box that finds what the page can do: its screens without
6
+ ; arguments, the buttons and links on show and the items of their menus, and
7
+ ; what the view's on-find gives for the text typed (its value), as pairs of a
8
+ ; label and a link, as a breadcrumb's.
9
+
10
+ ; The faces on show in f, as the user sees them on a wide screen.
11
+ palette-walk: function [f out [block!]] [
12
+ if any [f/hidden f/narrow-only] [exit]
13
+ append out f
14
+ unless block? f/pane [exit]
15
+ case [
16
+ f/style = 'tabs [
17
+ repeat i length? f/pane [
18
+ t: pick f/pane i
19
+ if all [i = f/value block? t/pane] [foreach c t/pane [palette-walk c out]]
20
+ ]
21
+ ]
22
+ ; the step on show and the buttons
23
+ f/style = 'steps [
24
+ repeat i length? f/pane [
25
+ t: pick f/pane i
26
+ if any [i = f/value t/style <> 'step] [palette-walk t out]
27
+ ]
28
+ ]
29
+ true [foreach c f/pane [palette-walk c out]]
30
+ ]
31
+ ]
32
+
33
+ ; The items of a menu that match, with the labels of the menus they are in.
34
+ palette-menu: function [f items [block!] path [string!] match [function!] out [block!] /local i] [
35
+ foreach i items [
36
+ unless i/divider [
37
+ label: rejoin [path " › " tr i/text]
38
+ either i/items [palette-menu f i/items label :match out] [
39
+ if match label [append out reduce [label 'menu none reduce [f i]]]
40
+ ]
41
+ ]
42
+ ]
43
+ ]
44
+
45
+ ui-palette: function [
46
+ "Called by the host as the user types in the palette (Ctrl+K) of view v: label, kind, keys and target of each thing that matches the text."
47
+ v [object!] text [string!]
48
+ /local n t a b f
49
+ ] [
50
+ out: copy []
51
+ match: func [label] [any [empty? text find label text]]
52
+ if router [
53
+ foreach [n t a b] router/data [
54
+ if empty? a [
55
+ label: tr t
56
+ if match label [append out reduce [label 'screen none n]]
57
+ ]
58
+ ]
59
+ ]
60
+ faces: copy []
61
+ palette-walk v faces
62
+ foreach f faces [
63
+ if all [find [button link] f/style not f/disabled] [
64
+ label: any [all [f/text tr f/text] f/hint]
65
+ if all [string? label not empty? label] [
66
+ either f/menu [palette-menu f f/menu label :match out] [
67
+ if match label [append out reduce [label 'action f/shortcut f]]
68
+ ]
69
+ ]
70
+ ]
71
+ ]
72
+ if all [not empty? text h: handler-for v 'on-find] [
73
+ found: run-handler/given v h text
74
+ if block? :found [foreach [label link] found [append out reduce [tr label 'found none :link]]]
75
+ ]
76
+ out
77
+ ]
78
+
79
+ ui-palette-pick: function [
80
+ "Called by the host when the user chooses in the palette of view v: goes to a screen or link, or chooses a menu item."
81
+ v [object!] kind [word!] target
82
+ ] [
83
+ switch kind [
84
+ screen found [go :target]
85
+ menu [ui-menu target/1 target/2 none]
86
+ ]
87
+ ]
@@ -0,0 +1,174 @@
1
+ ; A part of the UI dialect: see ui.trb, whose words it shares.
2
+
3
+ ; --- problems in a layout -------------------------------------------------------
4
+ ;
5
+ ; layout reads the whole block and makes one error of every problem it finds,
6
+ ; each with the place it was loaded from (loaded-at) and a word it may mean.
7
+
8
+ ; [place message ...] while a block is laid out; none otherwise, and then a problem is an error at once.
9
+ ui-problems: none
10
+
11
+ ui-problem: func [place [block!] message [string!]] [
12
+ either ui-problems [append ui-problems reduce [place message]] [ui-fail reduce [place message]]
13
+ ]
14
+
15
+ ; The faces of a block, as build-faces gives them, or an error with every problem in it.
16
+ ui-build: function [spec [block!] labels [block!]] [
17
+ outer: ui-problems
18
+ set 'ui-problems copy []
19
+ out: try [build-faces spec labels]
20
+ found: ui-problems
21
+ set 'ui-problems outer
22
+ if error? out [do out]
23
+ unless empty? found [either ui-checking [append ui-checking found] [ui-fail found]]
24
+ out
25
+ ]
26
+
27
+ ; While ui-check runs: the problems of every block, and no code of the program is run.
28
+ ui-checking: none
29
+
30
+ ; It lays out each block after view or layout (styles of stylize first), and the
31
+ ; faces of each screen and row of rows, which a running app lays out only when shown.
32
+ ui-check: function [
33
+ "Every problem in the layouts of a program, without running it: [place message ...]"
34
+ code [block!]
35
+ /local b p n m rest
36
+ ] [
37
+ set 'ui-checking copy []
38
+ blocks: copy []
39
+ ; the blocks after view, layout and stylize, in code and in the blocks inside it
40
+ walk: function [code] [
41
+ parse code [any [
42
+ p: ['view | 'layout | 'stylize | path! if (find [view layout] first first p)]
43
+ ; view compose [...]: its parens stand for values check cannot know
44
+ opt ['compose | path! if ('compose = first first next p)]
45
+ set b block! (
46
+ append/only blocks reduce [first p b]
47
+ walk b
48
+ )
49
+ | 'machine set b block! (append/only blocks reduce ['machine b])
50
+ ; a rule of the program: its words may follow a style
51
+ | 'rule set n lit-word! set m [string! | map! | block!] set b block! (append/only blocks reduce ['rule p reduce [to word! n m b]])
52
+ | set b [block! | paren!] (walk b)
53
+ | skip
54
+ ]]
55
+ ]
56
+ walk code
57
+ attempt-at: func [place body] [
58
+ if error? r: try body [append ui-checking reduce [place form r/message]]
59
+ ]
60
+ ; the imports at the top of the program run first: a module only defines things, as the rules of a package do
61
+ ; (a JavaScript module may need a browser)
62
+ parse code [any [
63
+ p: 'import [lit-word! | set n [file! | url!] if (not find [%.js %.mjs] suffix? n)] (attempt-at p [do/next p 'rest])
64
+ | skip
65
+ ]]
66
+ foreach p blocks [if 'rule = first p [attempt-at second p [apply/only :rule third p]]]
67
+ foreach p blocks [if 'stylize = first p [attempt-at next p [stylize copy/deep second p]]]
68
+ ; a machine is made without running anything: its data stays unevaluated
69
+ foreach p blocks [
70
+ if 'machine = first p [
71
+ if error? r: try [machine-engine/make-machine second p] [
72
+ append ui-checking reduce [any [machine-engine/failed next p] form r/message]
73
+ ]
74
+ ]
75
+ ]
76
+ foreach p blocks [
77
+ unless find [stylize machine rule] first p [
78
+ attempt-at next p [
79
+ faces: all-faces layout second p
80
+ ; screens and rows lay these out when shown
81
+ while [not empty? faces] [
82
+ f: take faces
83
+ later: copy []
84
+ if f/style = 'screens [foreach [n t a b] f/data [append/only later b]]
85
+ if all [f/style = 'rows f/template] [append/only later f/template]
86
+ foreach b later [
87
+ spec: copy/deep b
88
+ parse spec [any [set w word! if (event-word? w) block!] body:]
89
+ foreach g ui-build body copy [] [append faces all-faces g]
90
+ ]
91
+ ]
92
+ ]
93
+ ]
94
+ ]
95
+ ; a screen or rows laid out twice (rows with min) gives its problems twice
96
+ found: copy []
97
+ seen: copy []
98
+ foreach [p m] ui-checking [
99
+ k: rejoin [any [loaded-at p ""] " " m]
100
+ unless find seen k [append seen k append found reduce [p m]]
101
+ ]
102
+ set 'ui-checking none
103
+ found
104
+ ]
105
+
106
+ ui-fail: function [found [block!] /local place m] [
107
+ either 2 = length? found [
108
+ message: rejoin ["layout: " second found]
109
+ ] [
110
+ places: collect [foreach [place m] found [keep any [loaded-at place ""]]]
111
+ wide: 0
112
+ foreach p places [wide: max wide length? p]
113
+ message: rejoin ["layout: " (length? found) / 2 " problems"]
114
+ i: 0
115
+ foreach [place m] found [
116
+ p: pick places i: i + 1
117
+ append message rejoin ["^/ " p append/dup copy "" #" " wide + 1 - length? p m]
118
+ ]
119
+ ]
120
+ e: make error! message
121
+ ; the first values from the place, one after another as near shows them
122
+ e/near: copy []
123
+ foreach v copy/part first found 3 [append/only e/near :v]
124
+ e/at: loaded-at first found
125
+ do e
126
+ ]
127
+
128
+ ; What a rule word takes, for a problem when what follows it is something else.
129
+ ui-takes: [
130
+ min "a number, an amount, a date or a time" max "a number, an amount, a date or a time" length "two integers"
131
+ pattern "a block" check "a block" check-async "a block" calc "a block" react "a block, after later or not" is "a block" accept "a block"
132
+ menu "a block" sorted "a block" known "a map" links "a map" match "the name of a field"
133
+ poster "a file or a url" captions "a file, a url or a block" width "small, medium, large or fill"
134
+ pad "a step from 0 to 7, none or wide" gap "a step from 0 to 7, none or wide" key "a text or a word"
135
+ morph "a name, 'logo, or a block, [client id]" mark "an icon and its label, #list ^"List^""
136
+ by "the field that names the lane of a card, by status" card "a block of the fields a card shows"
137
+ step "a number above 0; for a time, minutes"
138
+ ]
139
+
140
+ ; Every word the dialect knows, for ui-suggest.
141
+ ui-dialect-words: does [
142
+ unique compose [
143
+ (words-of styles) (roles) (sizes) (aligns) (valigns) (flags) (chart-kinds) (simple-rules)
144
+ (rule-words) (media-flags) required global (words-of custom-rules)
145
+ ]
146
+ ]
147
+
148
+ ; The word near enough to w to be what it meant (buton: button), or none; the
149
+ ; machines' errors use the same.
150
+ ui-nearest: function [w [word!] words [block!]] [machine-engine/nearest w words]
151
+
152
+ ; "; did you mean button?" for buton, when one of the words is near enough; "" otherwise.
153
+ ui-suggest: function [w [word!] words [block!]] [machine-engine/suggest w words]
154
+
155
+ ; A value as a problem shows it: its mold, cut when long.
156
+ ui-shown: function [v] [
157
+ t: mold :v
158
+ either 30 < length? t [append copy/part t 27 "..."] [t]
159
+ ]
160
+
161
+ ; The style a word after a face means when it is a mistyped one (feild: field), or none.
162
+ ui-meant-style: function [v] [
163
+ all [word? :v s: ui-nearest v ui-dialect-words select styles s s]
164
+ ]
165
+
166
+ ; The problem with a value that follows a face and means nothing to it.
167
+ ui-stray: function [f v] [
168
+ case [
169
+ all [word? :v t: select ui-takes v] [rejoin [v " takes " t]]
170
+ s: ui-meant-style :v [rejoin [v " is not a style; did you mean " s "?"]]
171
+ word? :v [rejoin [v " is not a word of " f/style ui-suggest v ui-dialect-words]]
172
+ true [rejoin [f/style " does not take " ui-shown :v]]
173
+ ]
174
+ ]