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.
- package/README.md +12 -1
- package/dist/cli.js +17097 -12238
- package/dist/fonts/OFL.txt +93 -0
- package/dist/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/fonts/inter-greek.woff2 +0 -0
- package/dist/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/fonts/inter-latin.woff2 +0 -0
- package/dist/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/lib/core/boot.js +12 -8
- package/dist/lib/core/eval.js +2 -2
- package/dist/lib/core/func.d.ts +4 -0
- package/dist/lib/core/machine/checks.d.ts +1 -0
- package/dist/lib/core/machine/checks.js +250 -0
- package/dist/lib/core/machine/events.d.ts +1 -0
- package/dist/lib/core/machine/events.js +365 -0
- package/dist/lib/core/machine/running.d.ts +1 -0
- package/dist/lib/core/machine/running.js +180 -0
- package/dist/lib/core/machine/shared.d.ts +1 -0
- package/dist/lib/core/machine/shared.js +123 -0
- package/dist/lib/core/machine/snapshot.d.ts +1 -0
- package/dist/lib/core/machine/snapshot.js +244 -0
- package/dist/lib/core/machine/spec.d.ts +1 -0
- package/dist/lib/core/machine/spec.js +274 -0
- package/dist/lib/core/machine/words.d.ts +1 -0
- package/dist/lib/core/machine/words.js +98 -0
- package/dist/lib/core/machine.d.ts +1 -0
- package/dist/lib/core/machine.js +17 -0
- package/dist/lib/core/mezz.js +31 -0
- package/dist/lib/core/natives/control.js +2 -2
- package/dist/lib/core/natives/data.js +6 -1
- package/dist/lib/core/natives/series.js +59 -9
- package/dist/lib/core/natives/text.js +3 -1
- package/dist/lib/host/browser/calendar.d.ts +34 -0
- package/dist/lib/host/browser/calendar.js +268 -0
- package/dist/lib/host/browser/count.d.ts +15 -0
- package/dist/lib/host/browser/count.js +48 -0
- package/dist/lib/host/browser/dialogs.d.ts +39 -0
- package/dist/lib/host/browser/dialogs.js +443 -0
- package/dist/lib/host/browser/drag.d.ts +70 -0
- package/dist/lib/host/browser/drag.js +268 -0
- package/dist/lib/host/browser/drawings.d.ts +30 -0
- package/dist/lib/host/browser/drawings.js +176 -0
- package/dist/lib/host/browser/events.d.ts +16 -0
- package/dist/lib/host/browser/events.js +125 -0
- package/dist/lib/host/browser/faces.d.ts +35 -0
- package/dist/lib/host/browser/faces.js +131 -0
- package/dist/lib/host/browser/fields.d.ts +16 -0
- package/dist/lib/host/browser/fields.js +322 -0
- package/dist/lib/host/browser/keys.d.ts +29 -0
- package/dist/lib/host/browser/keys.js +151 -0
- package/dist/lib/host/browser/lookup.d.ts +25 -0
- package/dist/lib/host/browser/lookup.js +275 -0
- package/dist/lib/host/browser/menus.d.ts +20 -0
- package/dist/lib/host/browser/menus.js +149 -0
- package/dist/lib/host/browser/mount.d.ts +92 -0
- package/dist/lib/host/browser/mount.js +448 -0
- package/dist/lib/host/browser/orbits.d.ts +90 -0
- package/dist/lib/host/browser/orbits.js +379 -0
- package/dist/lib/host/browser/page.d.ts +13 -0
- package/dist/lib/host/browser/page.js +35 -0
- package/dist/lib/host/browser/richtext.d.ts +19 -0
- package/dist/lib/host/browser/richtext.js +379 -0
- package/dist/lib/host/browser/row-faces.d.ts +5 -0
- package/dist/lib/host/browser/row-faces.js +74 -0
- package/dist/lib/host/browser/screens.d.ts +37 -0
- package/dist/lib/host/browser/screens.js +140 -0
- package/dist/lib/host/browser/swipe.d.ts +31 -0
- package/dist/lib/host/browser/swipe.js +178 -0
- package/dist/lib/host/browser/sync.d.ts +24 -0
- package/dist/lib/host/browser/sync.js +450 -0
- package/dist/lib/host/browser/tables.d.ts +65 -0
- package/dist/lib/host/browser/tables.js +505 -0
- package/dist/lib/host/browser/times.d.ts +14 -0
- package/dist/lib/host/browser/times.js +114 -0
- package/dist/lib/host/browser/toolbars.d.ts +17 -0
- package/dist/lib/host/browser/toolbars.js +129 -0
- package/dist/lib/host/browser/trees.d.ts +20 -0
- package/dist/lib/host/browser/trees.js +235 -0
- package/dist/lib/host/browser/uploads.d.ts +29 -0
- package/dist/lib/host/browser/uploads.js +370 -0
- package/dist/lib/host/browser/widget.d.ts +13 -0
- package/dist/lib/host/browser/widget.js +105 -0
- package/dist/lib/host/browser.d.ts +25 -0
- package/dist/lib/host/browser.js +129 -3964
- package/dist/lib/host/devlog.d.ts +11 -0
- package/dist/lib/host/devlog.js +13 -0
- package/dist/lib/host/devtools/console.d.ts +9 -0
- package/dist/lib/host/devtools/console.js +104 -0
- package/dist/lib/host/devtools/faces.d.ts +25 -0
- package/dist/lib/host/devtools/faces.js +169 -0
- package/dist/lib/host/devtools/log.d.ts +3 -0
- package/dist/lib/host/devtools/log.js +32 -0
- package/dist/lib/host/devtools/machines.d.ts +34 -0
- package/dist/lib/host/devtools/machines.js +212 -0
- package/dist/lib/host/devtools/read.d.ts +13 -0
- package/dist/lib/host/devtools/read.js +52 -0
- package/dist/lib/host/devtools/state.d.ts +90 -0
- package/dist/lib/host/devtools/state.js +123 -0
- package/dist/lib/host/devtools.d.ts +19 -0
- package/dist/lib/host/devtools.js +238 -0
- package/dist/lib/host/fonts/OFL.txt +93 -0
- package/dist/lib/host/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-cyrillic.woff2 +0 -0
- package/dist/lib/host/fonts/inter-greek-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-greek.woff2 +0 -0
- package/dist/lib/host/fonts/inter-latin-ext.woff2 +0 -0
- package/dist/lib/host/fonts/inter-latin.woff2 +0 -0
- package/dist/lib/host/fonts/inter-vietnamese.woff2 +0 -0
- package/dist/lib/host/fonts.d.ts +11 -0
- package/dist/lib/host/fonts.js +30 -0
- package/dist/lib/host/icons.js +4 -0
- package/dist/lib/host/index.d.ts +5 -1
- package/dist/lib/host/index.js +110 -5
- package/dist/lib/host/js.d.ts +5 -0
- package/dist/lib/host/js.js +130 -0
- package/dist/lib/host/locale.d.ts +18 -0
- package/dist/lib/host/locale.js +75 -5
- package/dist/lib/host/markdown.d.ts +6 -0
- package/dist/lib/host/markdown.js +18 -0
- package/dist/lib/host/modules.d.ts +4 -0
- package/dist/lib/host/modules.js +157 -20
- package/dist/lib/host/motion.d.ts +32 -0
- package/dist/lib/host/motion.js +190 -0
- package/dist/lib/host/net.js +14 -3
- package/dist/lib/host/orbit.d.ts +121 -0
- package/dist/lib/host/orbit.js +374 -0
- package/dist/lib/host/palette.d.ts +17 -0
- package/dist/lib/host/palette.js +131 -0
- package/dist/lib/host/rows.d.ts +14 -0
- package/dist/lib/host/rows.js +29 -0
- package/dist/lib/host/scheduler.d.ts +8 -0
- package/dist/lib/host/scheduler.js +64 -36
- package/dist/lib/host/share.d.ts +31 -0
- package/dist/lib/host/share.js +134 -0
- package/dist/lib/host/theme/classic.d.ts +1 -0
- package/dist/lib/host/theme/classic.js +120 -0
- package/dist/lib/host/theme/cupertino.d.ts +1 -0
- package/dist/lib/host/theme/cupertino.js +65 -0
- package/dist/lib/host/theme/data.d.ts +1 -0
- package/dist/lib/host/theme/data.js +109 -0
- package/dist/lib/host/theme/devtools.d.ts +1 -0
- package/dist/lib/host/theme/devtools.js +166 -0
- package/dist/lib/host/theme/dialogs.d.ts +1 -0
- package/dist/lib/host/theme/dialogs.js +63 -0
- package/dist/lib/host/theme/fluent.d.ts +1 -0
- package/dist/lib/host/theme/fluent.js +64 -0
- package/dist/lib/host/theme/forms.d.ts +1 -0
- package/dist/lib/host/theme/forms.js +239 -0
- package/dist/lib/host/theme/fusion.d.ts +1 -0
- package/dist/lib/host/theme/fusion.js +66 -0
- package/dist/lib/host/theme/layout.d.ts +1 -0
- package/dist/lib/host/theme/layout.js +166 -0
- package/dist/lib/host/theme/media.d.ts +1 -0
- package/dist/lib/host/theme/media.js +106 -0
- package/dist/lib/host/theme/navigation.d.ts +1 -0
- package/dist/lib/host/theme/navigation.js +36 -0
- package/dist/lib/host/theme/panes.d.ts +1 -0
- package/dist/lib/host/theme/panes.js +99 -0
- package/dist/lib/host/theme/popups.d.ts +1 -0
- package/dist/lib/host/theme/popups.js +149 -0
- package/dist/lib/host/theme/responsive.d.ts +1 -0
- package/dist/lib/host/theme/responsive.js +103 -0
- package/dist/lib/host/theme/toasts.d.ts +1 -0
- package/dist/lib/host/theme/toasts.js +62 -0
- package/dist/lib/host/theme.js +19 -1179
- package/dist/lib/ui/dialect/events.trb +276 -0
- package/dist/lib/ui/dialect/faces.trb +135 -0
- package/dist/lib/ui/dialect/layout.trb +283 -0
- package/dist/lib/ui/dialect/palette.trb +87 -0
- package/dist/lib/ui/dialect/problems.trb +174 -0
- package/dist/lib/ui/dialect/reactions.trb +198 -0
- package/dist/lib/ui/dialect/rows.trb +208 -0
- package/dist/lib/ui/dialect/screens.trb +293 -0
- package/dist/lib/ui/dialect/steps.trb +203 -0
- package/dist/lib/ui/dialect/validation.trb +137 -0
- package/dist/lib/ui/dialect/view.trb +110 -0
- package/dist/lib/ui/dialect/walking.trb +98 -0
- package/dist/lib/ui/dialect/words.trb +70 -0
- package/dist/lib/ui/i18n.trb +23 -0
- package/dist/lib/ui/test.trb +12 -0
- package/dist/lib/ui/testing/actions.trb +421 -0
- package/dist/lib/ui/testing/faces.trb +148 -0
- package/dist/lib/ui/testing/server.trb +73 -0
- package/dist/lib/ui/ui.trb +25 -1234
- package/dist/trebol.js +4882 -1088
- package/editors/vscode/README.md +15 -0
- package/editors/vscode/language-configuration.json +28 -0
- package/editors/vscode/package.json +42 -0
- package/editors/vscode/syntaxes/trebol.tmLanguage.json +237 -0
- package/package.json +7 -3
- package/src/core/boot.ts +10 -7
- package/src/core/eval.ts +2 -2
- package/src/core/func.ts +4 -0
- package/src/core/machine/checks.ts +251 -0
- package/src/core/machine/events.ts +366 -0
- package/src/core/machine/running.ts +181 -0
- package/src/core/machine/shared.ts +124 -0
- package/src/core/machine/snapshot.ts +245 -0
- package/src/core/machine/spec.ts +275 -0
- package/src/core/machine/words.ts +99 -0
- package/src/core/machine.ts +20 -0
- package/src/core/mezz.ts +31 -0
- package/src/core/natives/control.ts +2 -2
- package/src/core/natives/data.ts +6 -1
- package/src/core/natives/parse.ts +1 -1
- package/src/core/natives/series.ts +55 -11
- package/src/core/natives/text.ts +2 -1
- package/src/host/browser/calendar.ts +264 -0
- package/src/host/browser/count.ts +48 -0
- package/src/host/browser/dialogs.ts +439 -0
- package/src/host/browser/drag.ts +278 -0
- package/src/host/browser/drawings.ts +178 -0
- package/src/host/browser/events.ts +117 -0
- package/src/host/browser/faces.ts +143 -0
- package/src/host/browser/fields.ts +315 -0
- package/src/host/browser/keys.ts +145 -0
- package/src/host/browser/lookup.ts +262 -0
- package/src/host/browser/menus.ts +146 -0
- package/src/host/browser/mount.ts +420 -0
- package/src/host/browser/orbits.ts +418 -0
- package/src/host/browser/page.ts +43 -0
- package/src/host/browser/richtext.ts +346 -0
- package/src/host/browser/row-faces.ts +75 -0
- package/src/host/browser/screens.ts +142 -0
- package/src/host/browser/swipe.ts +168 -0
- package/src/host/browser/sync.ts +354 -0
- package/src/host/browser/tables.ts +461 -0
- package/src/host/browser/times.ts +115 -0
- package/src/host/browser/toolbars.ts +126 -0
- package/src/host/browser/trees.ts +205 -0
- package/src/host/browser/uploads.ts +367 -0
- package/src/host/browser/widget.ts +103 -0
- package/src/host/browser.ts +128 -3747
- package/src/host/devlog.ts +16 -0
- package/src/host/devtools/console.ts +102 -0
- package/src/host/devtools/faces.ts +160 -0
- package/src/host/devtools/log.ts +34 -0
- package/src/host/devtools/machines.ts +208 -0
- package/src/host/devtools/read.ts +58 -0
- package/src/host/devtools/state.ts +148 -0
- package/src/host/devtools.ts +238 -0
- package/src/host/fonts/OFL.txt +93 -0
- package/src/host/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/src/host/fonts/inter-cyrillic.woff2 +0 -0
- package/src/host/fonts/inter-greek-ext.woff2 +0 -0
- package/src/host/fonts/inter-greek.woff2 +0 -0
- package/src/host/fonts/inter-latin-ext.woff2 +0 -0
- package/src/host/fonts/inter-latin.woff2 +0 -0
- package/src/host/fonts/inter-vietnamese.woff2 +0 -0
- package/src/host/fonts.ts +40 -0
- package/src/host/icons.ts +4 -0
- package/src/host/index.ts +110 -5
- package/src/host/js.ts +127 -0
- package/src/host/locale.ts +71 -5
- package/src/host/markdown.ts +18 -0
- package/src/host/modules.ts +150 -22
- package/src/host/motion.ts +204 -0
- package/src/host/net.ts +13 -3
- package/src/host/orbit.ts +432 -0
- package/src/host/palette.ts +139 -0
- package/src/host/rows.ts +30 -0
- package/src/host/scheduler.ts +67 -36
- package/src/host/share.ts +168 -0
- package/src/host/theme/classic.ts +121 -0
- package/src/host/theme/cupertino.ts +66 -0
- package/src/host/theme/data.ts +110 -0
- package/src/host/theme/devtools.ts +167 -0
- package/src/host/theme/dialogs.ts +64 -0
- package/src/host/theme/fluent.ts +65 -0
- package/src/host/theme/forms.ts +240 -0
- package/src/host/theme/fusion.ts +67 -0
- package/src/host/theme/layout.ts +167 -0
- package/src/host/theme/media.ts +107 -0
- package/src/host/theme/navigation.ts +37 -0
- package/src/host/theme/panes.ts +100 -0
- package/src/host/theme/popups.ts +150 -0
- package/src/host/theme/responsive.ts +104 -0
- package/src/host/theme/toasts.ts +63 -0
- package/src/host/theme.ts +19 -1179
- package/src/ui/dialect/events.trb +276 -0
- package/src/ui/dialect/faces.trb +135 -0
- package/src/ui/dialect/layout.trb +283 -0
- package/src/ui/dialect/palette.trb +87 -0
- package/src/ui/dialect/problems.trb +174 -0
- package/src/ui/dialect/reactions.trb +198 -0
- package/src/ui/dialect/rows.trb +208 -0
- package/src/ui/dialect/screens.trb +293 -0
- package/src/ui/dialect/steps.trb +203 -0
- package/src/ui/dialect/validation.trb +137 -0
- package/src/ui/dialect/view.trb +110 -0
- package/src/ui/dialect/walking.trb +98 -0
- package/src/ui/dialect/words.trb +70 -0
- package/src/ui/i18n.trb +23 -0
- package/src/ui/test.trb +12 -0
- package/src/ui/testing/actions.trb +421 -0
- package/src/ui/testing/faces.trb +148 -0
- package/src/ui/testing/server.trb +73 -0
- package/src/ui/ui.trb +25 -1234
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
; A part of the UI dialect: see ui.trb, whose words it shares.
|
|
2
|
+
|
|
3
|
+
; --- steps -----------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
; ["Who" [...] "Company" when [values/kind = "Company"] [...]] -> a step face per pair, then the row
|
|
6
|
+
; of its Back and Next buttons. A step with `when` applies only while its block is true: a reaction
|
|
7
|
+
; hides it, and a hidden step is skipped, its fields neither checked nor in values.
|
|
8
|
+
steps-of: function [f spec [block!] labels [block!] /local p w label b] [
|
|
9
|
+
out: copy []
|
|
10
|
+
parse spec [any [
|
|
11
|
+
set label text-rule (w: none) opt ['when set w block!] set b block! (
|
|
12
|
+
s: make select styles 'step [text: text-of label pane: build-faces b labels state: none]
|
|
13
|
+
if w [add-reaction s 'react compose/only [face/hidden: not do (w)] false]
|
|
14
|
+
append out s
|
|
15
|
+
)
|
|
16
|
+
| p: skip (ui-problem p "steps take a label, when [...] if it applies only sometimes, and a block per step") to end
|
|
17
|
+
]]
|
|
18
|
+
append out steps-nav f
|
|
19
|
+
; Back, Next and the submit buttons follow the step on show: a reaction to the step and to what applies
|
|
20
|
+
add-reaction f 'react [ui-steps-sync face] false
|
|
21
|
+
r: last f/reactions
|
|
22
|
+
r/sources: reduce [f 'value]
|
|
23
|
+
foreach s out [if s/style = 'step [append r/sources reduce [s 'hidden]]]
|
|
24
|
+
r/targets: copy []
|
|
25
|
+
out
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
;-- a machine leads them: steps flow [you "You" [...] company "Company" [...]]. Each step names a state;
|
|
29
|
+
; the one on show is the step of the state the machine is in. Next sends it next with the values of the
|
|
30
|
+
; form, and the machine chooses where to go; Back puts the machine back where it was before that Next.
|
|
31
|
+
|
|
32
|
+
machine?: func [v] [all [object? :v in v 'nodes in v 'queue in v 'state]]
|
|
33
|
+
|
|
34
|
+
steps-nav: function [f] [
|
|
35
|
+
earlier: make select styles 'button [text: select i18n/ui 'back]
|
|
36
|
+
earlier/action: compose [ui-step (f) -1]
|
|
37
|
+
later: make select styles 'button [role: 'primary text: select i18n/ui 'next]
|
|
38
|
+
later/action: compose [ui-step (f) 1]
|
|
39
|
+
make select styles 'row [pane: reduce [earlier later]]
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
steps-flow-of: function [f spec [block!] labels [block!] /local p n label b w] [
|
|
43
|
+
out: copy []
|
|
44
|
+
; check runs nothing: there is no machine to ask
|
|
45
|
+
m: unless ui-checking [get f/flow]
|
|
46
|
+
names: either m [collect [foreach x m/nodes [keep x/name]]] [none]
|
|
47
|
+
parse spec [any [
|
|
48
|
+
p: set n word! set label text-rule
|
|
49
|
+
opt [w: 'when block! (ui-problem w "a machine leads these steps: it chooses where Next goes, with no when")]
|
|
50
|
+
set b block! (
|
|
51
|
+
if all [names not find names n] [ui-problem p rejoin [f/flow " has no state " n ui-suggest n names]]
|
|
52
|
+
s: make select styles 'step [text: text-of label pane: build-faces b labels state: n]
|
|
53
|
+
append out s
|
|
54
|
+
)
|
|
55
|
+
| p: skip (ui-problem p "steps with a machine take the name of a state, a label and a block per step") to end
|
|
56
|
+
]]
|
|
57
|
+
f/trail: copy []
|
|
58
|
+
append out steps-nav f
|
|
59
|
+
unless m [return out]
|
|
60
|
+
; the step on show and the buttons follow the state of the machine
|
|
61
|
+
add-reaction f 'react [ui-steps-follow face ui-steps-sync face] false
|
|
62
|
+
r: last f/reactions
|
|
63
|
+
r/sources: reduce [m [state] f 'value]
|
|
64
|
+
r/targets: copy []
|
|
65
|
+
out
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
; The step of the state the machine is in is on show; the steps before it that it did not go
|
|
69
|
+
; through do not apply, so their fields are neither checked nor in values.
|
|
70
|
+
ui-steps-follow: function [s] [
|
|
71
|
+
m: get s/flow
|
|
72
|
+
at: none
|
|
73
|
+
repeat i length? s/pane [
|
|
74
|
+
g: pick s/pane i
|
|
75
|
+
if all [g/style = 'step in? m g/state] [at: i break]
|
|
76
|
+
]
|
|
77
|
+
unless at [exit]
|
|
78
|
+
done: copy []
|
|
79
|
+
foreach x s/trail [append done first x]
|
|
80
|
+
repeat i length? s/pane [
|
|
81
|
+
g: pick s/pane i
|
|
82
|
+
if g/style = 'step [
|
|
83
|
+
off: all [i < at not find done i]
|
|
84
|
+
unless off = g/hidden [g/hidden: off]
|
|
85
|
+
]
|
|
86
|
+
]
|
|
87
|
+
unless at = s/value [s/value: at]
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
; The submit buttons written in a form with steps go after Next, shown on the last step.
|
|
91
|
+
steps-take-submits: function [f] [
|
|
92
|
+
s: none
|
|
93
|
+
foreach g own-faces f [if g/style = 'steps [s: g break]]
|
|
94
|
+
unless s [exit]
|
|
95
|
+
nav: last s/pane
|
|
96
|
+
foreach g copy f/pane [
|
|
97
|
+
if g/submit [
|
|
98
|
+
append nav/pane g
|
|
99
|
+
remove find-in f/pane g
|
|
100
|
+
]
|
|
101
|
+
]
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
; The position of a face in a block (faces compare by content).
|
|
105
|
+
find-in: function [b [block!] v] [
|
|
106
|
+
forall b [if same? first b v [return b]]
|
|
107
|
+
none
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
; The numbers of the steps that apply.
|
|
111
|
+
steps-live: function [s] [
|
|
112
|
+
out: copy []
|
|
113
|
+
repeat i length? s/pane [
|
|
114
|
+
g: pick s/pane i
|
|
115
|
+
if all [g/style = 'step not g/hidden] [append out i]
|
|
116
|
+
]
|
|
117
|
+
out
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
ui-steps-sync: function [s /local i] [
|
|
121
|
+
live: steps-live s
|
|
122
|
+
if empty? live [exit]
|
|
123
|
+
; the step on show no longer applies: the next one that does, else the last
|
|
124
|
+
unless find live s/value [
|
|
125
|
+
goal: last live
|
|
126
|
+
foreach i live [if i > s/value [goal: i break]]
|
|
127
|
+
s/value: goal
|
|
128
|
+
]
|
|
129
|
+
k: index? find live s/value
|
|
130
|
+
nav: last s/pane
|
|
131
|
+
; with a machine: Back while there is a Next to undo, Next while the machine takes it
|
|
132
|
+
first?: either s/flow [empty? s/trail] [k = 1]
|
|
133
|
+
last?: either s/flow [not can? get s/flow 'next] [k = length? live]
|
|
134
|
+
nav/pane/1/hidden: first?
|
|
135
|
+
nav/pane/2/hidden: last?
|
|
136
|
+
foreach b skip nav/pane 2 [b/hidden: not last?]
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
; True if every field of the step on show is valid; shows the messages of those that are not.
|
|
140
|
+
step-valid?: function [s] [
|
|
141
|
+
faces: own-faces pick s/pane s/value
|
|
142
|
+
foreach g faces [if any [g/rules g/typed] [g/touched: true]]
|
|
143
|
+
foreach g faces [check-async g]
|
|
144
|
+
refresh-form any [s/form s/root]
|
|
145
|
+
foreach g faces [if all [any [g/rules g/typed] validate-face g] [return false]]
|
|
146
|
+
true
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
ui-step: function [
|
|
150
|
+
"Called by Back and Next of a form in steps: by -1 or 1. Next only leaves a step whose fields are valid."
|
|
151
|
+
s by [integer!]
|
|
152
|
+
] [
|
|
153
|
+
if s/flow [
|
|
154
|
+
m: get s/flow
|
|
155
|
+
either by > 0 [
|
|
156
|
+
unless step-valid? s [exit]
|
|
157
|
+
was: m/state
|
|
158
|
+
saved: snapshot m
|
|
159
|
+
send m compose [next values: (form-values any [s/form s/root])]
|
|
160
|
+
; the machine did not move: nothing to undo
|
|
161
|
+
unless strict-equal? was m/state [append/only s/trail reduce [s/value saved]]
|
|
162
|
+
] [
|
|
163
|
+
if empty? s/trail [exit]
|
|
164
|
+
machine-engine/rewind m second take/last s/trail
|
|
165
|
+
]
|
|
166
|
+
ui-steps-follow s
|
|
167
|
+
exit
|
|
168
|
+
]
|
|
169
|
+
live: steps-live s
|
|
170
|
+
unless here: find live s/value [exit]
|
|
171
|
+
if all [by > 0 not step-valid? s] [exit]
|
|
172
|
+
if goal: pick live (index? here) + by [s/value: goal]
|
|
173
|
+
]
|
|
174
|
+
|
|
175
|
+
ui-step-go: function [
|
|
176
|
+
"Called by the host when the user chooses a step or the history moves: back to any step, forward through valid ones."
|
|
177
|
+
s n [integer!]
|
|
178
|
+
] [
|
|
179
|
+
if s/flow [
|
|
180
|
+
; back to a step done, or forward again through valid ones (the browser's Forward)
|
|
181
|
+
either n < s/value [
|
|
182
|
+
done: copy []
|
|
183
|
+
foreach x s/trail [append done first x]
|
|
184
|
+
unless find done n [exit]
|
|
185
|
+
while [s/value <> n] [ui-step s -1]
|
|
186
|
+
] [
|
|
187
|
+
while [s/value <> n] [
|
|
188
|
+
was: s/value
|
|
189
|
+
ui-step s 1
|
|
190
|
+
if s/value = was [exit]
|
|
191
|
+
]
|
|
192
|
+
]
|
|
193
|
+
exit
|
|
194
|
+
]
|
|
195
|
+
live: steps-live s
|
|
196
|
+
unless find live n [exit]
|
|
197
|
+
while [s/value < n] [
|
|
198
|
+
was: s/value
|
|
199
|
+
ui-step s 1
|
|
200
|
+
if s/value = was [exit]
|
|
201
|
+
]
|
|
202
|
+
if n < s/value [s/value: n]
|
|
203
|
+
]
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
; A part of the UI dialect: see ui.trb, whose words it shares.
|
|
2
|
+
|
|
3
|
+
; --- validation ------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
message: function [key args [block!]] [
|
|
6
|
+
out: copy tr select i18n/ui key
|
|
7
|
+
repeat i length? args [replace out rejoin ["#" i] localize pick args i]
|
|
8
|
+
out
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
digit: charset "0123456789"
|
|
12
|
+
word-char: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "._%+-"]
|
|
13
|
+
host-char: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "-"]
|
|
14
|
+
email-rule: [some word-char "@" some host-char some ["." some host-char] end]
|
|
15
|
+
url-rule: [["http://" | "https://"] some host-char any ["." some host-char] opt [":" some digit] opt ["/" to end] end]
|
|
16
|
+
|
|
17
|
+
; check and toggle hold true or false
|
|
18
|
+
logic-face?: func [f] [to logic! find [check toggle] f/style]
|
|
19
|
+
|
|
20
|
+
blank?: func [v] [
|
|
21
|
+
any [none? :v all [string? :v empty? trim copy v]]
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
label-of: func [f] [either f/text [tr f/text] [form f/name]]
|
|
25
|
+
|
|
26
|
+
list-of: function [items [block!]] [
|
|
27
|
+
out: copy ""
|
|
28
|
+
foreach x items [unless empty? out [append out ", "] append out form x]
|
|
29
|
+
out
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
; The message for the first rule a face breaks, or none. Asynchronous checks
|
|
33
|
+
; are skipped here: their last result is kept in async-error.
|
|
34
|
+
validate-face: function [
|
|
35
|
+
"Checks a face's rules; returns a message or none."
|
|
36
|
+
f
|
|
37
|
+
] [
|
|
38
|
+
if f/readonly [return none]
|
|
39
|
+
v: f/value
|
|
40
|
+
rules: any [f/rules []]
|
|
41
|
+
if f/style = 'rows [
|
|
42
|
+
n: either v [length? v] [0]
|
|
43
|
+
return case [
|
|
44
|
+
all [n = 0 find/only rules [required]] [message 'required []]
|
|
45
|
+
n < any [rule-of f 'min 0] [message 'rows-min reduce [rule-of f 'min]]
|
|
46
|
+
n > any [rule-of f 'max n] [message 'rows-max reduce [rule-of f 'max]]
|
|
47
|
+
true [none]
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
if f/typed [
|
|
51
|
+
if f/style = 'upload [return message 'accept reduce [list-of f/accept]]
|
|
52
|
+
if f/style = 'photo [return either f/accept [message 'accept reduce [list-of f/accept]] [message 'images []]]
|
|
53
|
+
return message select [number number money amount date date date-range date-range time time] f/style []
|
|
54
|
+
]
|
|
55
|
+
if blank? :v [
|
|
56
|
+
return either find/only rules [required] [message 'required []] [f/async-error]
|
|
57
|
+
]
|
|
58
|
+
if all [logic-face? f find/only rules [required] not v] [return message 'required []]
|
|
59
|
+
foreach r rules [
|
|
60
|
+
problem: switch/default first r [
|
|
61
|
+
email [unless parse v email-rule [message 'email []]]
|
|
62
|
+
url [unless parse v url-rule [message 'url []]]
|
|
63
|
+
integer [unless parse form v [opt "-" some digit] [message 'integer []]]
|
|
64
|
+
; a range of dates keeps both its ends within them
|
|
65
|
+
min [
|
|
66
|
+
low: either f/style = 'date-range [v/1] [v]
|
|
67
|
+
if all [any [number? low money? low date? low time? low] low < r/2] [message 'min reduce [r/2]]
|
|
68
|
+
]
|
|
69
|
+
max [
|
|
70
|
+
high: either f/style = 'date-range [v/2] [v]
|
|
71
|
+
if all [any [number? high money? high date? high time? high] high > r/2] [message 'max reduce [r/2]]
|
|
72
|
+
]
|
|
73
|
+
length [
|
|
74
|
+
n: length? form v
|
|
75
|
+
if any [n < r/2 n > r/3] [
|
|
76
|
+
either r/2 = r/3 [message 'length-exact reduce [r/2]] [message 'length reduce [r/2 r/3]]
|
|
77
|
+
]
|
|
78
|
+
]
|
|
79
|
+
pattern [unless parse form v r/2 [message 'pattern []]]
|
|
80
|
+
match [
|
|
81
|
+
other: find-named f r/2
|
|
82
|
+
if all [other v <> other/value] [message 'match reduce [label-of other]]
|
|
83
|
+
]
|
|
84
|
+
check [check-result run-handler f r/2]
|
|
85
|
+
] [
|
|
86
|
+
if b: select custom-rules first r [check-result/as run-handler f b first r]
|
|
87
|
+
]
|
|
88
|
+
if problem [return problem]
|
|
89
|
+
]
|
|
90
|
+
f/async-error
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
check-result: func [result /as key "The message of this rule, not check's"] [
|
|
94
|
+
case [
|
|
95
|
+
string? :result [result]
|
|
96
|
+
any [none? :result false = :result] [message any [key 'check] []]
|
|
97
|
+
true [none]
|
|
98
|
+
]
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
; Rules Trebol adds as a program would
|
|
102
|
+
rule 'iban #(en: "Enter a valid IBAN" es: "Introduce un IBAN válido") [iban? form value]
|
|
103
|
+
|
|
104
|
+
find-named: function [f name] [
|
|
105
|
+
scope: any [f/form f/root]
|
|
106
|
+
foreach g named-faces scope [if g/name = name [return g]]
|
|
107
|
+
none
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
; Runs asynchronous checks of a face (they may fetch).
|
|
111
|
+
check-async: function [f] [
|
|
112
|
+
foreach r any [f/rules []] [
|
|
113
|
+
if all [r/1 = 'check-async not blank? f/value] [
|
|
114
|
+
f/pending: true
|
|
115
|
+
f/async-error: check-result run-handler f r/2
|
|
116
|
+
f/pending: false
|
|
117
|
+
]
|
|
118
|
+
]
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
; Updates the errors of touched faces and enables submit buttons only when
|
|
122
|
+
; every field of the form is valid. A view checks only the faces outside its forms.
|
|
123
|
+
refresh-form: function [scope] [
|
|
124
|
+
; the fields of a row count for the form its rows are in
|
|
125
|
+
while [all [scope scope/style = 'entry]] [scope: any [scope/form scope/root]]
|
|
126
|
+
unless all [scope find [form view] scope/style] [exit]
|
|
127
|
+
ok: true
|
|
128
|
+
faces: own-faces scope
|
|
129
|
+
foreach f faces [
|
|
130
|
+
if any [f/rules f/typed f/error] [
|
|
131
|
+
problem: validate-face f
|
|
132
|
+
f/error: either f/touched [problem] [none]
|
|
133
|
+
if problem [ok: false]
|
|
134
|
+
]
|
|
135
|
+
]
|
|
136
|
+
foreach f faces [if f/submit [f/disabled: not ok]]
|
|
137
|
+
]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
; A part of the UI dialect: see ui.trb, whose words it shares.
|
|
2
|
+
|
|
3
|
+
; --- the blocks faces take, and view ---------------------------------------------
|
|
4
|
+
|
|
5
|
+
; [home "Home" [...] client "Client" [id] [...]] -> [name title args body ...]
|
|
6
|
+
screens-of: function [spec [block!] /local n t a b p] [
|
|
7
|
+
out: copy []
|
|
8
|
+
if empty? spec [ui-problem spec "screens take a name, a title, an optional block of arguments and a block per screen"]
|
|
9
|
+
parse spec [any [
|
|
10
|
+
set n word! set t text-rule (a: copy []) opt [ahead [block! block!] set a block!] set b block! (
|
|
11
|
+
forall a [unless word? first a [ui-problem a "the arguments of a screen are words"]]
|
|
12
|
+
append out reduce [n text-of t head a b]
|
|
13
|
+
)
|
|
14
|
+
| p: skip (ui-problem p "screens take a name, a title, an optional block of arguments and a block per screen") to end
|
|
15
|
+
]]
|
|
16
|
+
out
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
menu-item: make object! [
|
|
20
|
+
text: none
|
|
21
|
+
icon: none
|
|
22
|
+
id: none ; the word on-menu gets in event/picked
|
|
23
|
+
items: none ; a submenu
|
|
24
|
+
divider: false
|
|
25
|
+
danger: false ; it removes or cannot be undone: red
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
; As in Red: ["Edit" edit danger #trash "Delete" delete --- "Move to" ["Top" top]] -> menu items
|
|
29
|
+
menu-of: function [spec [block!] /local i d label w b p] [
|
|
30
|
+
out: copy []
|
|
31
|
+
parse spec [any [
|
|
32
|
+
'--- (append out make menu-item [divider: true])
|
|
33
|
+
| (i: none d: false) opt ['danger (d: true)] opt [set i issue!] set label text-rule (label: text-of label) [
|
|
34
|
+
set b block! (append out make menu-item [text: label icon: i items: menu-of b danger: d])
|
|
35
|
+
| set w word! (append out make menu-item [text: label icon: i id: w danger: d])
|
|
36
|
+
]
|
|
37
|
+
| p: skip (ui-problem p "a menu takes a label and a word per item, danger before one that removes, a block for a submenu, or ---") to end
|
|
38
|
+
]]
|
|
39
|
+
out
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
; [focus id nodes [id "Title" [hints] ...] edges [from to "Label" [dashed] ...] trail [id ...]]
|
|
43
|
+
; The host reads the hints (a role or color, many, dashed, count n, steps n at k); this checks the shape.
|
|
44
|
+
orbit-id: [word! | integer! | string! | issue!]
|
|
45
|
+
orbit-of: function [spec [block!] /local b p] [
|
|
46
|
+
parse spec [any [
|
|
47
|
+
'focus orbit-id
|
|
48
|
+
| 'nodes set b block! (parse b [
|
|
49
|
+
any [orbit-id text-rule opt block!]
|
|
50
|
+
[end | p: (ui-problem p "nodes takes an id and a title for each, then a block of hints if it has any")]
|
|
51
|
+
])
|
|
52
|
+
| 'edges set b block! (parse b [
|
|
53
|
+
any [orbit-id orbit-id opt text-rule opt [into ['solid | 'dashed | 'faint]]]
|
|
54
|
+
[end | p: (ui-problem p "edges takes two ids for each, then a label and [solid], [dashed] or [faint] if it has them")]
|
|
55
|
+
])
|
|
56
|
+
| 'trail set b block! (parse b [
|
|
57
|
+
any orbit-id [end | p: (ui-problem p "trail takes the ids of nodes, the most recent last")]
|
|
58
|
+
])
|
|
59
|
+
| p: skip (ui-problem p "an orbit takes focus id, nodes [...], edges [...] and trail [...]") to end
|
|
60
|
+
]]
|
|
61
|
+
copy spec
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
; ["Home" home "Clients" clients "Ada"]: a label and a word per item; the last one may have no word
|
|
65
|
+
crumbs-of: function [spec [block!] /local label w p] [
|
|
66
|
+
parse spec [
|
|
67
|
+
any [set label [string! | map!] set w [word! | path!]] opt [string! | map!]
|
|
68
|
+
[end | p: (ui-problem p "a breadcrumb takes a label and a word per item; only the last may have no word")]
|
|
69
|
+
]
|
|
70
|
+
copy spec
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
; The options of a choice or radio: each reduced, and so are those of a group,
|
|
74
|
+
; a title followed by a block: ["Bikes" ["Road" "City"] "Other"].
|
|
75
|
+
options-of: function [spec [block!]] [
|
|
76
|
+
if ui-checking [return copy spec]
|
|
77
|
+
opts: reduce spec
|
|
78
|
+
forall opts [if block? first opts [change/only opts reduce first opts]]
|
|
79
|
+
opts
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
; Links each face to its view and form, so handlers can find `values`.
|
|
83
|
+
attach: function [f root form] [
|
|
84
|
+
f/root: root
|
|
85
|
+
f/form: form
|
|
86
|
+
if f/pane [
|
|
87
|
+
inner: either find [form entry] f/style [f] [form]
|
|
88
|
+
foreach c f/pane [attach c root inner]
|
|
89
|
+
]
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
view: function [
|
|
93
|
+
"Shows a layout (a block of the dialect, or a face from layout) as the page."
|
|
94
|
+
spec [block! object!]
|
|
95
|
+
] [
|
|
96
|
+
root: either block? spec [layout spec] [spec]
|
|
97
|
+
attach root root none
|
|
98
|
+
set 'page root
|
|
99
|
+
entered: copy []
|
|
100
|
+
foreach f all-faces root [
|
|
101
|
+
if f/style = 'screens [
|
|
102
|
+
set 'router f
|
|
103
|
+
append entered follow-link f route
|
|
104
|
+
]
|
|
105
|
+
]
|
|
106
|
+
foreach f all-faces root [refresh-form f]
|
|
107
|
+
show root
|
|
108
|
+
foreach s entered [run-enter s]
|
|
109
|
+
root
|
|
110
|
+
]
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
; A part of the UI dialect: see ui.trb, whose words it shares.
|
|
2
|
+
|
|
3
|
+
; --- walking faces -------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
all-faces: function [f] [
|
|
6
|
+
out: copy []
|
|
7
|
+
collect-faces f out
|
|
8
|
+
out
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
collect-faces: function [f out] [
|
|
12
|
+
append out f
|
|
13
|
+
if f/pane [foreach c f/pane [collect-faces c out]]
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
; Faces that belong to a scope: nested forms keep their own fields and submits.
|
|
17
|
+
own-faces: function [scope] [
|
|
18
|
+
out: reduce [scope]
|
|
19
|
+
if scope/pane [foreach c scope/pane [collect-own c out]]
|
|
20
|
+
out
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
collect-own: function [f out] [
|
|
24
|
+
append out f
|
|
25
|
+
if all [f/style = 'step f/hidden] [exit]
|
|
26
|
+
if all [f/pane f/style <> 'form] [foreach c f/pane [collect-own c out]]
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
; The fields of a row are not fields of the form: rows holds their values.
|
|
30
|
+
named-faces: function [scope] [
|
|
31
|
+
out: copy []
|
|
32
|
+
collect-named scope out
|
|
33
|
+
out
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
collect-named: function [f out] [
|
|
37
|
+
if f/name [append out f]
|
|
38
|
+
if all [f/style = 'step f/hidden] [exit]
|
|
39
|
+
if all [f/pane f/style <> 'rows] [foreach c f/pane [collect-named c out]]
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
form-values: function [
|
|
43
|
+
"The values of the named fields of a form (or view), as a map."
|
|
44
|
+
scope
|
|
45
|
+
] [
|
|
46
|
+
m: make map! []
|
|
47
|
+
foreach f named-faces scope [poke m f/name f/value]
|
|
48
|
+
m
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
set-values: function [
|
|
52
|
+
"Fills the named fields of a form (or view) from a map or object; none clears them."
|
|
53
|
+
scope data [map! object! none!]
|
|
54
|
+
] [
|
|
55
|
+
foreach f named-faces scope [
|
|
56
|
+
v: either data [select data f/name] [none]
|
|
57
|
+
f/value: either logic-face? f [true = v] [v]
|
|
58
|
+
f/touched: false
|
|
59
|
+
f/typed: none
|
|
60
|
+
f/async-error: none
|
|
61
|
+
if f/style = 'rows [
|
|
62
|
+
f/built: none
|
|
63
|
+
rows-fill f
|
|
64
|
+
]
|
|
65
|
+
]
|
|
66
|
+
refresh-form scope
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
insert-text: function [
|
|
70
|
+
"Puts text where the cursor of a field, area or rich text was last, in place of what was selected, as if the user typed it."
|
|
71
|
+
face [object!]
|
|
72
|
+
text [string!]
|
|
73
|
+
] [
|
|
74
|
+
unless find [field area rich] face/style [
|
|
75
|
+
do make error! rejoin ["insert-text: a " face/style " has no cursor"]
|
|
76
|
+
]
|
|
77
|
+
if any [face/readonly face/disabled empty? text] [exit]
|
|
78
|
+
; the host gives the value with the text in; at its end when the face has had no cursor
|
|
79
|
+
ui-input face insert-at-caret face text
|
|
80
|
+
face
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
field-error: function [
|
|
84
|
+
"Shows a message on a named field until the user changes it: what a server refused. False if there is no such field."
|
|
85
|
+
scope name [word! string!] text [string!]
|
|
86
|
+
] [
|
|
87
|
+
name: to word! name
|
|
88
|
+
foreach f named-faces scope [
|
|
89
|
+
if f/name = name [
|
|
90
|
+
f/async-error: text
|
|
91
|
+
f/error: text
|
|
92
|
+
f/touched: true
|
|
93
|
+
refresh-form scope
|
|
94
|
+
return true
|
|
95
|
+
]
|
|
96
|
+
]
|
|
97
|
+
false
|
|
98
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
; A part of the UI dialect: see ui.trb, whose words it shares.
|
|
2
|
+
|
|
3
|
+
; --- layout --------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
roles: [primary accent danger success warning muted]
|
|
6
|
+
sizes: [small medium large]
|
|
7
|
+
aligns: [left center right spread]
|
|
8
|
+
valigns: [top middle bottom]
|
|
9
|
+
flags: [fill fit hidden disabled readonly inert narrow-only wide-only linked round drag drop reorder multiple sortable stacked count]
|
|
10
|
+
chart-kinds: [bar line area pie]
|
|
11
|
+
simple-rules: [required email url integer]
|
|
12
|
+
letter: charset [#"a" - #"z" #"A" - #"Z"]
|
|
13
|
+
rule-words: [min max length pattern match check check-async calc react is width pad gap menu accept known links sorted key morph poster captions mark by card step]
|
|
14
|
+
media-styles: [video audio]
|
|
15
|
+
media-flags: [loop muted autoplay] ; of a video or a sound
|
|
16
|
+
|
|
17
|
+
; Words that never name a field. email, url and integer are rules too,
|
|
18
|
+
; but also common field names, so the first word after an input style names it.
|
|
19
|
+
field-name?: func [w [word!]] [
|
|
20
|
+
not any [
|
|
21
|
+
find roles w find sizes w find aligns w find flags w
|
|
22
|
+
find rule-words w w = 'required event-word? w
|
|
23
|
+
]
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
; The rules a program or a package adds, by name: name -> the block that checks a value.
|
|
27
|
+
; Their messages are in i18n/ui, under the same name, so an app can change them.
|
|
28
|
+
custom-rules: make map! []
|
|
29
|
+
|
|
30
|
+
rule: function [
|
|
31
|
+
"Adds a rule that a face takes by its name, as it takes required: rule 'even ^"Enter an even number^" [even? value]"
|
|
32
|
+
name [word!]
|
|
33
|
+
message [string! map! block!] "What a face that breaks it says: a text, or a text per language"
|
|
34
|
+
body [block!] "Sees value, face and values; gives true when the value is good, none or false for the message, or a string to say instead"
|
|
35
|
+
] [
|
|
36
|
+
if any [
|
|
37
|
+
all [find ui-dialect-words name not select custom-rules name]
|
|
38
|
+
event-word? name
|
|
39
|
+
] [do make error! rejoin ["rule: " name " is already a word of the dialect"]]
|
|
40
|
+
if all [select i18n/ui name not select custom-rules name] [
|
|
41
|
+
do make error! rejoin ["rule: " name " is already one of Trebol's texts"]
|
|
42
|
+
]
|
|
43
|
+
poke custom-rules name body
|
|
44
|
+
poke i18n/ui name translated message
|
|
45
|
+
name
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
add-rule: func [f rule [block!]] [
|
|
49
|
+
unless f/rules [f/rules: copy []]
|
|
50
|
+
append/only f/rules rule
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
event-word?: func [w [word!]] [
|
|
54
|
+
to logic! find/match form w "on-"
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
; The events a face, a view or a screen answers to.
|
|
58
|
+
ui-events: [
|
|
59
|
+
on-back on-change on-close on-dbl-click on-drop on-end on-enter on-expand on-find on-focus on-key
|
|
60
|
+
on-leave on-menu on-over on-reorder on-search on-select on-sort on-unfocus
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
; An on- word that is no event is a problem of the layout at place: on-chnage, "did you mean on-change?".
|
|
64
|
+
ui-known-event: func [place [block!] ev [word!]] [
|
|
65
|
+
unless find ui-events ev [
|
|
66
|
+
ui-problem place rejoin [ev " is not an event" either ui-nearest ev [on-click] [
|
|
67
|
+
"; the block after a face runs when it is clicked"
|
|
68
|
+
] [ui-suggest ev ui-events]]
|
|
69
|
+
]
|
|
70
|
+
]
|
package/dist/lib/ui/i18n.trb
CHANGED
|
@@ -21,6 +21,8 @@ i18n: make object! [
|
|
|
21
21
|
number #(en: "Enter a number" es: "Introduce un número")
|
|
22
22
|
amount #(en: "Enter an amount" es: "Introduce un importe")
|
|
23
23
|
date #(en: "Enter a valid date" es: "Introduce una fecha válida")
|
|
24
|
+
time #(en: "Enter a valid time" es: "Introduce una hora válida")
|
|
25
|
+
date-range #(en: "Enter a start date and an end date" es: "Introduce una fecha de inicio y otra de fin")
|
|
24
26
|
accept #(en: "Only #1 files" es: "Solo archivos #1")
|
|
25
27
|
images #(en: "Only images" es: "Solo imágenes")
|
|
26
28
|
min #(en: "Must be at least #1" es: "Debe ser como mínimo #1")
|
|
@@ -38,13 +40,31 @@ i18n: make object! [
|
|
|
38
40
|
yes #(en: "Yes" es: "Sí")
|
|
39
41
|
no #(en: "No" es: "No")
|
|
40
42
|
back #(en: "Back" es: "Atrás")
|
|
43
|
+
next #(en: "Next" es: "Siguiente")
|
|
44
|
+
steps #(en: "Steps" es: "Pasos")
|
|
45
|
+
step-of #(en: "Step #1 of #2" es: "Paso #1 de #2")
|
|
46
|
+
palette #(en: "Find" es: "Buscar")
|
|
47
|
+
palette-search #(en: "Find a screen or an action…" es: "Busca una pantalla o una acción…")
|
|
48
|
+
palette-none #(en: "Nothing found" es: "No se encontró nada")
|
|
49
|
+
palette-screen #(en: "Screen" es: "Pantalla")
|
|
41
50
|
close #(en: "Close" es: "Cerrar")
|
|
51
|
+
undo #(en: "Undo" es: "Deshacer")
|
|
42
52
|
move-to #(en: "Move to" es: "Mover a")
|
|
53
|
+
more-actions #(en: "More" es: "Más")
|
|
43
54
|
resize-panes #(en: "Resize panes" es: "Cambiar el tamaño de los paneles")
|
|
44
55
|
breadcrumb #(en: "Breadcrumb" es: "Ruta de navegación")
|
|
45
56
|
more-levels #(en: "Show more levels" es: "Mostrar más niveles")
|
|
57
|
+
orbit-more #(en: "+#1 more" es: "+#1 más")
|
|
58
|
+
orbit-first #(en: "Back to the first" es: "Volver a los primeros")
|
|
59
|
+
orbit-back-to #(en: "Back to #1" es: "Volver a #1")
|
|
46
60
|
choose-date #(en: "Choose date" es: "Elegir fecha")
|
|
47
61
|
choose-date-of #(en: "#1: choose date" es: "#1: elegir fecha")
|
|
62
|
+
choose-time #(en: "Choose time" es: "Elegir hora")
|
|
63
|
+
choose-time-of #(en: "#1: choose time" es: "#1: elegir hora")
|
|
64
|
+
choose-dates #(en: "Choose dates" es: "Elegir fechas")
|
|
65
|
+
choose-dates-of #(en: "#1: choose dates" es: "#1: elegir fechas")
|
|
66
|
+
pick-start #(en: "Pick the first day" es: "Elige el primer día")
|
|
67
|
+
pick-end #(en: "Now pick the last day" es: "Ahora elige el último día")
|
|
48
68
|
previous-month #(en: "Previous month" es: "Mes anterior")
|
|
49
69
|
next-month #(en: "Next month" es: "Mes siguiente")
|
|
50
70
|
no-matches #(en: "Nothing found" es: "No se ha encontrado nada")
|
|
@@ -59,6 +79,9 @@ i18n: make object! [
|
|
|
59
79
|
remove-photo #(en: "Remove" es: "Quitar")
|
|
60
80
|
add-row #(en: "Add row" es: "Añadir fila")
|
|
61
81
|
remove-row #(en: "Remove row" es: "Quitar fila")
|
|
82
|
+
leave-unsaved #(en: "Leave without saving?" es: "¿Salir sin guardar?")
|
|
83
|
+
leave #(en: "Leave" es: "Salir")
|
|
84
|
+
stay #(en: "Stay" es: "Quedarse")
|
|
62
85
|
bold #(en: "Bold" es: "Negrita")
|
|
63
86
|
italic #(en: "Italic" es: "Cursiva")
|
|
64
87
|
heading #(en: "Heading" es: "Título")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Trebol [
|
|
2
|
+
title: "Screen tests: what a user does, without a browser"
|
|
3
|
+
exports: [serve reply click type choose attach pick-menu drag press say see see-mark dismiss test-answer test-route]
|
|
4
|
+
parts: [%testing/server.trb %testing/faces.trb %testing/actions.trb]
|
|
5
|
+
]
|
|
6
|
+
|
|
7
|
+
; `trebol test` runs every block of an app.test.trb on the app started anew,
|
|
8
|
+
; with no browser: the host keeps the view these words act on. Faces are found
|
|
9
|
+
; by what the user sees, a label, the text of a button or a hint, or by their
|
|
10
|
+
; name; only faces on show count, so a closed dialog or another tab is not there.
|
|
11
|
+
|
|
12
|
+
; The words are in its parts: the answers of the server, the faces on show, and what the user does.
|