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,198 @@
1
+ ; A part of the UI dialect: see ui.trb, whose words it shares.
2
+
3
+ ; --- reactions -------------------------------------------------------------------
4
+ ;
5
+ ; `react [...]` after a face runs the block when the face is shown, and again
6
+ ; whenever a facet it reads changes: `total/text`, `face/value`, `values/qty`.
7
+ ; Which facets it reads is found by reading the block, not by running it. The
8
+ ; host checks them at the end of each round, before it repaints, against what
9
+ ; they were when the block last ran. `is [...]` gives the face's main facet what
10
+ ; the block gives, and `calc [...]` its value, which the user cannot change.
11
+
12
+ reaction: make object! [
13
+ kind: 'react ; react, is or calc
14
+ body: none
15
+ later: false ; runs on a change only, not when the face is shown
16
+ sources: none ; the [face facet ...] it reads, found the first time it is checked
17
+ targets: none ; the [face facet ...] it sets, so that it runs before what reads them
18
+ last: none ; what its sources were when it last ran
19
+ ]
20
+
21
+ add-reaction: function [f k b l] [
22
+ unless f/reactions [f/reactions: copy []]
23
+ append f/reactions make reaction [kind: k body: b later: l]
24
+ ]
25
+
26
+ value-styles: append copy input-styles [progress image video audio]
27
+
28
+ ; The facet `is` sets: data for a table, list, tree or chart, a canvas's draw,
29
+ ; an input's value, and text for the rest.
30
+ main-facet: func [f] [
31
+ case [
32
+ find data-styles f/style ['data]
33
+ f/style = 'orbit ['data]
34
+ f/style = 'canvas ['draw]
35
+ find value-styles f/style ['value]
36
+ true ['text]
37
+ ]
38
+ ]
39
+
40
+ face?: func [v] [all [object? :v in v 'style in v 'pane]]
41
+
42
+ ; Puts in out the face and facet a path names: name/facet (a label), face/facet
43
+ ; (the face itself), values/field (the value of the field of that name). Any
44
+ ; other word that holds an object reads down the path from it, at any depth:
45
+ ; m/state, m/data/qty, settings/dark. Its words are kept as a block, walked on
46
+ ; each check, so an object put in place of another (restart makes new data) is
47
+ ; followed.
48
+ react-path: function [f p out [block!]] [
49
+ w: first p
50
+ unless all [word? :w word? pick p 2] [exit]
51
+ facet: second p
52
+ g: case [
53
+ w = 'face [f]
54
+ w = 'values [facet: 'value attempt [find-named f second p]]
55
+ true [attempt [get w]]
56
+ ]
57
+ case [
58
+ face? :g [if in g facet [append out reduce [g facet]]]
59
+ object? :g [
60
+ ws: copy []
61
+ foreach v next to block! p [either word? :v [append ws v] [break]]
62
+ if in g first ws [append out reduce [g ws]]
63
+ ]
64
+ ]
65
+ ]
66
+
67
+ react-scan: function [f b [block! paren!] sources [block!] targets [block!] /local v] [
68
+ forall b [
69
+ v: first b
70
+ case [
71
+ any [block? :v paren? :v] [react-scan f v sources targets]
72
+ any [path? :v get-path? :v] [react-path f v sources]
73
+ set-path? :v [react-path f v targets]
74
+ ; whether a machine is in a state: what it reads is its state
75
+ all [word? :v v = 'in? word? second b] [react-path f to path! reduce [second b 'state] sources]
76
+ ; an answer kept: of its url if written out, else of any
77
+ all [word? :v v = 'cached] [
78
+ append sources either any [url? second b string? second b] [
79
+ reduce [ui-cache-entry second b 'version]
80
+ ] [
81
+ reduce [ui-cache-news 'version]
82
+ ]
83
+ ]
84
+ ]
85
+ ]
86
+ ]
87
+
88
+ ; What the sources are now. Down a path of an object, each object met is
89
+ ; watched by the host, so that a change to it (a timer of a machine, another
90
+ ; tab) runs the reactions at the end of that round.
91
+ react-now: function [r /local g facet] [
92
+ out: copy []
93
+ foreach [g facet] r/sources [
94
+ either word? facet [append/only out select g facet] [
95
+ foreach w facet [
96
+ either object? :g [ui-watch g g: select g w] [g: none break]
97
+ ]
98
+ append/only out :g
99
+ ]
100
+ ]
101
+ out
102
+ ]
103
+
104
+ ; Faces compare by content, so finding one in a block needs same?.
105
+ find-same: function [b [block!] v] [
106
+ foreach x b [if same? x v [return true]]
107
+ false
108
+ ]
109
+
110
+ react-due?: func [r] [not strict-equal? r/last react-now r]
111
+
112
+ ; True if a reaction sets something b reads.
113
+ feeds?: function [a b /local g m h n] [
114
+ foreach [g m] a/targets [
115
+ foreach [h n] b/sources [if all [same? g h m = n] [return true]]
116
+ ]
117
+ false
118
+ ]
119
+
120
+ react-run: function [f r] [
121
+ if r/kind = 'react [
122
+ run-handler f r/body
123
+ exit
124
+ ]
125
+ m: either r/kind = 'calc ['value] [main-facet f]
126
+ ; a formula that fails, or lacks a value, leaves the field empty
127
+ v: either r/kind = 'calc [attempt [run-handler f r/body]] [run-handler f r/body]
128
+ unless strict-equal? :v select f m [
129
+ poke f m :v
130
+ if m = 'value [store-around f]
131
+ ]
132
+ ]
133
+
134
+ ui-react: function [
135
+ "Called by the host at the end of each round: runs the reactions of the faces whose facets they read changed. Gives the cycles it cut, as texts."
136
+ faces [block! object!] "The faces, or a face to take every face in it"
137
+ /local f r
138
+ ] [
139
+ if object? faces [faces: all-faces faces]
140
+ fs: copy []
141
+ rs: copy []
142
+ foreach f faces [
143
+ foreach r any [select f 'reactions []] [
144
+ unless r/sources [
145
+ r/sources: copy []
146
+ r/targets: copy []
147
+ react-scan f r/body r/sources r/targets
148
+ if r/kind <> 'react [append r/targets reduce [f either r/kind = 'calc ['value] [main-facet f]]]
149
+ ; none is never a list of values: due, so it runs when shown
150
+ r/last: either r/later [react-now r] [none]
151
+ ]
152
+ append fs f
153
+ append rs r
154
+ ]
155
+ ]
156
+ cut: copy []
157
+ failed: none
158
+ ; a second cascade, for what the forms changed after the first (an error, a disabled submit)
159
+ loop 2 [
160
+ ran: copy []
161
+ forever [
162
+ due: copy []
163
+ repeat i length? rs [if all [not find ran i react-due? pick rs i] [append due i]]
164
+ if empty? due [break]
165
+ ; the first that no other one due feeds; if they all feed each other, the first
166
+ i: first due
167
+ foreach j due [
168
+ ok: true
169
+ foreach k due [if all [k <> j feeds? pick rs k pick rs j] [ok: false break]]
170
+ if ok [i: j break]
171
+ ]
172
+ r: pick rs i
173
+ e: try [react-run pick fs i r none]
174
+ if all [error? :e not failed] [failed: :e]
175
+ r/last: react-now r
176
+ append ran i
177
+ ]
178
+ if empty? ran [break]
179
+ ; what reads again what changed after it ran is in a cycle: it waits for the next change
180
+ foreach i ran [
181
+ r: pick rs i
182
+ if react-due? r [
183
+ where: loaded-at r/body
184
+ append cut rejoin [either where [rejoin [where " "]] [""] r/kind ": left out, what it reads changed again after it ran (a cycle)"]
185
+ r/last: react-now r
186
+ ]
187
+ ]
188
+ scopes: copy []
189
+ foreach i ran [
190
+ f: pick fs i
191
+ s: any [f/form f/root]
192
+ if all [s not find-same scopes s] [append scopes s]
193
+ ]
194
+ foreach s scopes [refresh-form s]
195
+ ]
196
+ if failed [do :failed]
197
+ cut
198
+ ]
@@ -0,0 +1,208 @@
1
+ ; A part of the UI dialect: see ui.trb, whose words it shares.
2
+
3
+ ; --- rows ------------------------------------------------------------------------
4
+ ;
5
+ ; A field made of rows the user adds and removes. Its pane is an entry per row
6
+ ; and the add button last; an entry holds the fields of the template and its
7
+ ; remove button. Each entry is a scope of its own, so `values` in a handler or
8
+ ; a formula of a row is that row. The value is a block with a map per row, or
9
+ ; none when there are no rows; code changes the rows by assigning it.
10
+
11
+ last-entry: 0
12
+
13
+ rule-of: function [f name [word!]] [
14
+ foreach r any [f/rules []] [if r/1 = name [return r/2]]
15
+ none
16
+ ]
17
+
18
+ entries-of: function [f] [
19
+ collect [foreach c any [f/pane []] [if c/style = 'entry [keep c]]]
20
+ ]
21
+
22
+ rows-entry: function [f data] [
23
+ spec: copy/deep f/template
24
+ labels: copy []
25
+ set 'last-entry last-entry + 1
26
+ e: make select styles 'entry [owner: f value: last-entry]
27
+ e/pane: ui-build spec labels
28
+ bind-labels spec labels copy []
29
+ foreach g named-faces e [
30
+ if f/readonly [g/readonly: true]
31
+ if f/disabled [g/disabled: true]
32
+ ]
33
+ if data [set-values e data]
34
+ remove-button: make select styles 'button [icon: #trash]
35
+ remove-button/hint: select i18n/ui 'remove-row
36
+ remove-button/action: compose [rows-remove (f) (e/value)]
37
+ append e/pane remove-button
38
+ e
39
+ ]
40
+
41
+ ; Makes the rows again from the value, if it or the flags changed since they were made.
42
+ rows-fill: function [f] [
43
+ state: reduce [f/value f/readonly f/disabled]
44
+ if all [f/pane state = f/built] [exit]
45
+ entries: map-each d any [f/value []] [rows-entry f d]
46
+ ; `min 2` starts with two empty rows
47
+ while [(length? entries) < any [rule-of f 'min 0]] [append entries rows-entry f none]
48
+ add-button: either f/pane [last f/pane] [
49
+ make select styles 'button [icon: #plus]
50
+ ]
51
+ add-button/text: select i18n/ui 'add-row
52
+ add-button/action: compose [rows-add (f)]
53
+ f/pane: append entries add-button
54
+ if f/root [foreach e entries [attach e f/root f/form]]
55
+ rows-store f
56
+ ]
57
+
58
+ ; Takes the value from the rows and shows only the buttons that can be used.
59
+ rows-store: function [f] [
60
+ entries: entries-of f
61
+ n: length? entries
62
+ f/value: either empty? entries [none] [map-each e entries [form-values e]]
63
+ f/built: reduce [f/value f/readonly f/disabled]
64
+ add-button: last f/pane
65
+ add-button/hidden: f/readonly
66
+ add-button/disabled: any [f/disabled n >= any [rule-of f 'max n + 1]]
67
+ foreach e entries [
68
+ remove-button: last e/pane
69
+ remove-button/hidden: f/readonly
70
+ remove-button/disabled: any [f/disabled n <= any [rule-of f 'min 0]]
71
+ ]
72
+ ]
73
+
74
+ ;--- a board: cards in lanes ------------------------------------------------------
75
+ ;
76
+ ; board tasks by status [todo "To do" doing "Doing" done "Done"]: a lane for each word, and in each, as
77
+ ; cards, the rows of its data whose status names it. A lane is a panel that takes drops, holding a list of
78
+ ; its cards that can be dragged; the board makes them, and deals the cards again when its data changes.
79
+
80
+ lanes-of: function [spec [block!] /local w s] [
81
+ out: copy []
82
+ unless parse spec [some [set w word! set s text-rule (append out reduce [w text-of s])]] [
83
+ ui-problem spec "a board takes a word and a label for each lane"
84
+ ]
85
+ out
86
+ ]
87
+
88
+ ; The lane of a row: the word its field holds (a text from JSON too), or the state of its machine.
89
+ board-lane: function [f row] [
90
+ v: attempt [select row f/field]
91
+ if machine? :v [v: v/state if path? :v [v: first v]]
92
+ all [any [word? :v string? :v] attempt [to word! v]]
93
+ ]
94
+
95
+ ; Makes the lanes, and puts each card in the lane its row names, when the data or a lane changed.
96
+ board-fill: function [f /local id label] [
97
+ unless all [f/lanes f/field] [exit]
98
+ data: any [f/data []]
99
+ state: reduce [data map-each row data [board-lane f row]]
100
+ if all [f/pane state = f/built] [exit]
101
+ unless f/pane [
102
+ f/pane: collect [
103
+ foreach [id label] f/lanes [
104
+ cards: make select styles 'list [
105
+ drag: true owner: f text: ""
106
+ columns: any [f/card columns-of [title]]
107
+ events: compose/deep [on-select [board-pick (f) row]]
108
+ ]
109
+ keep make select styles 'panel [lane: id owner: f text: label drop: true pane: reduce [cards]]
110
+ ]
111
+ ]
112
+ ]
113
+ foreach lane f/pane [
114
+ lane/pane/1/data: collect [foreach row data [if lane/lane = board-lane f row [keep/only row]]]
115
+ ]
116
+ f/built: state
117
+ ]
118
+
119
+ board-pick: function [f row] [
120
+ f/selected: row
121
+ if h: handler-for f 'on-select [run-handler f h]
122
+ ]
123
+
124
+ ; The event that takes machine m to the state named lane: of the first way from a state it is in to that state
125
+ ; (or into it, or to one branch of a choose there) whose event it can take now; none if there is none.
126
+ board-way: function [m lane] [
127
+ into?: func [p] [all [p lane = either path? p [first p] [p]]]
128
+ foreach w select graph-of m 'ways [
129
+ if in? m select w 'from [
130
+ if any [
131
+ into? select w 'to
132
+ foreach b any [select w 'branches []] [if into? select b 'to [break/return true]]
133
+ ] [
134
+ foreach e select w 'on [if can? m e [return e]]
135
+ ]
136
+ ]
137
+ ]
138
+ none
139
+ ]
140
+
141
+ ; A card dropped on a lane: its field names that lane, or its machine takes a way to the state of that name, if
142
+ ; it has one. on-drop sees the row moved; false puts it back. (func, so that the to: of the event is no local.)
143
+ board-drop: func [f lane row /local there here v saved r e] [
144
+ there: lane/lane
145
+ here: board-lane f :row
146
+ if any [not here here = there] [exit]
147
+ v: select row f/field
148
+ either machine? :v [
149
+ unless e: board-way v there [exit]
150
+ saved: snapshot v
151
+ send v e
152
+ ] [
153
+ poke row f/field either string? :v [form there] [there]
154
+ ]
155
+ r: fire-event f 'on-drop reduce [quote row: row quote from: to lit-word! here quote to: to lit-word! there]
156
+ if false = :r [either machine? :v [machine-engine/rewind v saved] [poke row f/field :v]]
157
+ board-fill f
158
+ ]
159
+
160
+ ui-board: function [
161
+ "Called by the host when the data of a board may have changed."
162
+ f
163
+ ] [
164
+ board-fill f
165
+ ]
166
+
167
+ ; A field of a row changed: so did the value of its rows, and of the rows those are in.
168
+ store-around: function [f] [
169
+ e: f/form
170
+ if all [e e/style = 'entry] [
171
+ rows-store e/owner
172
+ store-around e/owner
173
+ ]
174
+ ]
175
+
176
+ rows-add: function [f] [
177
+ e: rows-entry f none
178
+ attach e f/root f/form
179
+ faces: copy f/pane
180
+ insert back tail faces e
181
+ f/pane: faces
182
+ rows-store f
183
+ f/touched: true
184
+ changed f
185
+ ]
186
+
187
+ rows-remove: function [f id] [
188
+ faces: copy f/pane
189
+ ; faces compare by content, so a row is found by its number
190
+ forall faces [
191
+ if faces/1/value = id [
192
+ remove faces
193
+ break
194
+ ]
195
+ ]
196
+ f/pane: head faces
197
+ rows-store f
198
+ f/touched: true
199
+ changed f
200
+ ]
201
+
202
+ ui-rows: function [
203
+ "Called by the host when code gave a rows face a new value or changed its flags."
204
+ f
205
+ ] [
206
+ rows-fill f
207
+ refresh-form any [f/form f/root]
208
+ ]
@@ -0,0 +1,293 @@
1
+ ; A part of the UI dialect: see ui.trb, whose words it shares.
2
+
3
+ ; --- screens -------------------------------------------------------------------
4
+ ;
5
+ ; A screens face shows one screen at a time and keeps the page's link in step:
6
+ ; the screen `client [id]` showing id "42" is #/client/42. A route is a block
7
+ ; of the screen name and its arguments as strings, as they come in the link.
8
+
9
+ router: none ; the screens face of the page
10
+ marked: false ; the screen on show has changes not saved (unsaved)
11
+ page: none ; the root face of the view on show
12
+
13
+ ; The [name title args body] of the screen a route names, or none.
14
+ find-screen: function [f route [block!] /local n t a b] [
15
+ if any [empty? route not word? first route] [return none]
16
+ foreach [n t a b] f/data [
17
+ if all [n = first route (length? a) = ((length? route) - 1)] [return reduce [n t a b]]
18
+ ]
19
+ none
20
+ ]
21
+
22
+ ; Builds the screen a route names as the only child of f; returns the screen face.
23
+ enter-screen: function [f route [block!] /local ev b] [
24
+ def: find-screen f route
25
+ ; a screen's arguments and labels are local to it
26
+ spec: copy/deep def/4
27
+ labels: copy []
28
+ ; on-xxx handlers before the first face belong to the screen
29
+ events: copy []
30
+ parse spec [any [p: set ev word! if (event-word? ev) set b block! (ui-known-event p ev append events reduce [ev b])] body:]
31
+ s: make select styles 'screen [text: def/2 pane: ui-build body labels]
32
+ unless empty? events [s/events: events]
33
+ words: copy []
34
+ repeat i length? def/3 [append words reduce [to set-word! pick def/3 i pick route i + 1]]
35
+ bind-labels spec labels words
36
+ morphs reduce [s]
37
+ f/value: copy route
38
+ f/entering: true
39
+ ; what cached kept is asked again as the new screen reads it
40
+ ui-caches-old
41
+ ; what could be undone on the screen left is done now: its back block may need faces of that screen
42
+ ui-toasts-done
43
+ ; a screen starts with nothing to save
44
+ set 'marked false
45
+ set-unsaved false
46
+ f/pane: reduce [s]
47
+ ui-pane f
48
+ s
49
+ ]
50
+
51
+ ; Runs what a screen does on entering, and only then lets the host show it: the
52
+ ; page keeps the screen it had until the new one has its data, so nothing paints
53
+ ; half made; if that takes long, the host shows the new one with gray bars where
54
+ ; its data will be. If on-enter went elsewhere, the screen it went to decides.
55
+ run-enter: function [s] [
56
+ r: none
57
+ if h: handler-for s 'on-enter [r: try [run-handler s h none]]
58
+ if same? s first router/pane [
59
+ router/entering: false
60
+ ; the screen on show changed, and so may whether back and forward can be used
61
+ if h: handler-for router 'on-change [run-handler router h]
62
+ ]
63
+ if error? :r [do :r]
64
+ ]
65
+
66
+ ; Whether the screen on show lets the page leave it: its on-leave says, false or
67
+ ; 'continue (as Red's on-close) to stay; with no on-leave, a screen with unsaved
68
+ ; changes asks the user. Both may wait for a dialog.
69
+ may-leave?: function [/local s h r] [
70
+ unless all [router s: first router/pane] [return true]
71
+ if h: handler-for s 'on-leave [
72
+ r: run-handler s h
73
+ return not any [false = :r 'continue = :r]
74
+ ]
75
+ any [
76
+ not marked
77
+ confirm/with/role select i18n/ui 'leave-unsaved reduce [select i18n/ui 'leave select i18n/ui 'stay] 'danger
78
+ ]
79
+ ]
80
+
81
+ ; Shows the screen of a link given as a block of strings; a link that names no
82
+ ; screen shows the first one and is replaced by its link.
83
+ follow-link: function [f parts [block!]] [
84
+ route: copy parts
85
+ unless empty? route [route/1: attempt [to word! route/1]]
86
+ unless find-screen f route [
87
+ route: reduce [first f/data]
88
+ set-route route true
89
+ ]
90
+ enter-screen f route
91
+ ]
92
+
93
+ go: function [
94
+ "Shows a screen and gives the page its link: go 'clients, go [client row/id] (the name is not evaluated, the arguments are)."
95
+ target [word! block! path!]
96
+ ] [
97
+ unless router [do make error! "go: the view has no screens"]
98
+ route: reduce [either word? target [target] [first target]]
99
+ if block? target [foreach a reduce next target [append route form a]]
100
+ if path? target [foreach a next to block! target [append route form a]]
101
+ unless find-screen router route [do make error! rejoin ["go: no screen for " mold route]]
102
+ unless may-leave? [exit]
103
+ set-route route false
104
+ run-enter enter-screen router route
105
+ ]
106
+
107
+ go-back: function [
108
+ "Returns to the screen the user came from; if they came from outside the page, goes to target."
109
+ target [word! block! path!]
110
+ ] [
111
+ unless route-back [go target]
112
+ ]
113
+
114
+ go-forward: function [
115
+ "Goes to the screen the user came back from, if there is one; true if it went."
116
+ ] [
117
+ route-forward
118
+ ]
119
+
120
+ can-go-back?: function [
121
+ "True if a screen of this page lies behind the current one in the browser's history."
122
+ ] [
123
+ 0 < first route-steps
124
+ ]
125
+
126
+ can-go-forward?: function [
127
+ "True if a screen of this page lies ahead of the current one: the user went back and has not gone elsewhere since."
128
+ ] [
129
+ 0 < second route-steps
130
+ ]
131
+
132
+ unsaved: function [
133
+ "Marks the screen on show as having changes not saved, or not: leaving it asks first, and so does closing the page."
134
+ on [logic!]
135
+ ] [
136
+ set 'marked on
137
+ set-unsaved on
138
+ ]
139
+
140
+ unsaved?: function [
141
+ "True if the screen on show has changes not saved (unsaved)."
142
+ ] [
143
+ marked
144
+ ]
145
+
146
+ ui-route: function [
147
+ "Called by the host when the page's link changes: back, forward or a link."
148
+ f parts [block!]
149
+ ] [
150
+ route: copy parts
151
+ unless empty? route [route/1: attempt [to word! route/1]]
152
+ if route = f/value [exit]
153
+ ; the link has changed already: staying puts the screen's link back
154
+ unless may-leave? [route-undo exit]
155
+ run-enter follow-link f parts
156
+ ]
157
+
158
+ ui-pane: function [
159
+ "Called by the host when code gave a face a new pane: links the new faces to their view and form."
160
+ f
161
+ ] [
162
+ inner: either find [form entry] f/style [f] [f/form]
163
+ foreach c any [f/pane []] [attach c f/root inner]
164
+ unless f/root [exit]
165
+ refresh-form any [inner f/root]
166
+ ; and the forms among the new faces, whose submits start disabled until their fields are valid
167
+ foreach c any [f/pane []] [foreach g all-faces c [if g/style = 'form [refresh-form g]]]
168
+ ]
169
+
170
+ open: func [
171
+ "Shows a dialog."
172
+ dialog [object!]
173
+ ] [
174
+ dialog/hidden: false
175
+ ]
176
+
177
+ close: func [
178
+ "Hides a dialog; closes a stream."
179
+ target [object! handle!]
180
+ ] [
181
+ either object? target [target/hidden: true] [close-stream target]
182
+ ]
183
+
184
+ toast: function [
185
+ "Shows a short notice that goes away by itself."
186
+ message [string! map! word!] "A text, a text per language, or a word of the dictionary"
187
+ /role "primary, success, warning or danger"
188
+ kind [word!]
189
+ /undo "With an Undo button, for what was just done: back runs if the user clicks it"
190
+ back [block!]
191
+ /then "Runs done when the notice goes without Undo: what waits for it, such as the delete on the server"
192
+ done [block!]
193
+ ] [
194
+ text: tr message
195
+ id: none
196
+ if any [undo then] [
197
+ set 'toasts-made id: toasts-made + 1
198
+ append toasts-waiting reduce [id text either undo [back] [none] either then [done] [none]]
199
+ ]
200
+ show-toast text either role [kind] [none] all [undo id]
201
+ ]
202
+
203
+ toasts-made: 0
204
+ ; A notice that can still be undone or whose then has not run: id text back done.
205
+ toasts-waiting: copy []
206
+
207
+ ui-toasts-on: func ["The notices that can still be undone or whose then has not run: id text back done for each."] [
208
+ copy toasts-waiting
209
+ ]
210
+
211
+ ui-toast-undo: function [
212
+ "Called by the host when the user clicks Undo on notice id: runs its back block, never its then."
213
+ v id [integer!]
214
+ ] [
215
+ unless here: find/skip toasts-waiting id 4 [exit]
216
+ back: here/3
217
+ remove/part here 4
218
+ if back [do back]
219
+ ]
220
+
221
+ ui-toast-gone: function [
222
+ "Called by the host when notice id goes without Undo: runs its then block."
223
+ v id [integer!]
224
+ ] [
225
+ unless here: find/skip toasts-waiting id 4 [exit]
226
+ done: here/4
227
+ remove/part here 4
228
+ if done [do done]
229
+ ]
230
+
231
+ ui-toasts-done: function [
232
+ "Ends every notice that can still be undone, as if its time had passed: the screen changes or the page is hidden."
233
+ /local id
234
+ ] [
235
+ while [not empty? toasts-waiting] [
236
+ id: first toasts-waiting
237
+ hide-toast id
238
+ ui-toast-gone none id
239
+ ]
240
+ ]
241
+
242
+ confirm: func [
243
+ "Asks a question in a small dialog and waits: true when the user says yes."
244
+ question [string! map! word!] "A text, a text per language, or a word of the dictionary"
245
+ /with "The answers, yes first"
246
+ choices [block!]
247
+ /role "primary (the default) or danger, for what cannot be undone"
248
+ kind [word!]
249
+ ] [
250
+ show-confirm tr question
251
+ either with [tr first choices] [none]
252
+ either with [tr second choices] [none]
253
+ either role [kind] [none]
254
+ ]
255
+
256
+ print-page: func [
257
+ "Opens the browser's print dialog for the screen."
258
+ /only "Print just this face and what is inside it"
259
+ face [object!]
260
+ ] [
261
+ print-faces either only [face] [none]
262
+ ]
263
+
264
+ set-language: func [
265
+ "Changes the active language and shows every face again in it."
266
+ language [word! string!]
267
+ ] [
268
+ i18n/language: either string? language [to word! language] [language]
269
+ ; the messages under the fields were written in the language before
270
+ if page [foreach f all-faces page [refresh-form f]]
271
+ repaint
272
+ ]
273
+
274
+ ; The looks of src/host/theme.ts, with their names: colors, shapes, fonts, shadows and
275
+ ; how the icons are drawn go together. As they are, they make the items of a menu.
276
+ looks: [
277
+ #(en: "Minimal" es: "Minimalista") minimal
278
+ #(en: "Paper" es: "Papel") paper
279
+ #(en: "Civic" es: "Institucional") civic
280
+ #(en: "Soft" es: "Amable") soft
281
+ #(en: "Ink" es: "Tinta") ink
282
+ #(en: "Classic" es: "Clásico") classic
283
+ #(en: "Cupertino" es: "Cupertino") cupertino
284
+ #(en: "Fusion" es: "Fusion") fusion
285
+ #(en: "Fluent" es: "Fluent") fluent
286
+ ]
287
+
288
+ theme: func [
289
+ "Sets the theme: a look by name (theme 'civic), or parameters (theme [look: civic base: 200 mode: dark])."
290
+ spec [block! word!]
291
+ ] [
292
+ apply-theme construct either word? spec [reduce [to set-word! 'look spec]] [spec]
293
+ ]