trebol 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cli.js +10040 -7519
- package/dist/lib/core/boot.js +10 -7
- package/dist/lib/core/eval.js +2 -2
- package/dist/lib/core/machine/checks.d.ts +1 -0
- package/dist/lib/core/machine/checks.js +250 -0
- package/dist/lib/core/machine/events.d.ts +1 -0
- package/dist/lib/core/machine/events.js +365 -0
- package/dist/lib/core/machine/running.d.ts +1 -0
- package/dist/lib/core/machine/running.js +180 -0
- package/dist/lib/core/machine/shared.d.ts +1 -0
- package/dist/lib/core/machine/shared.js +123 -0
- package/dist/lib/core/machine/snapshot.d.ts +1 -0
- package/dist/lib/core/machine/snapshot.js +244 -0
- package/dist/lib/core/machine/spec.d.ts +1 -0
- package/dist/lib/core/machine/spec.js +274 -0
- package/dist/lib/core/machine/words.d.ts +1 -0
- package/dist/lib/core/machine/words.js +98 -0
- package/dist/lib/core/machine.d.ts +1 -0
- package/dist/lib/core/machine.js +17 -0
- package/dist/lib/core/mezz.js +31 -0
- package/dist/lib/core/natives/control.js +1 -1
- package/dist/lib/core/natives/data.js +6 -1
- package/dist/lib/core/natives/series.js +49 -9
- package/dist/lib/core/natives/text.js +0 -1
- package/dist/lib/host/browser/calendar.d.ts +34 -0
- package/dist/lib/host/browser/calendar.js +268 -0
- package/dist/lib/host/browser/count.d.ts +15 -0
- package/dist/lib/host/browser/count.js +48 -0
- package/dist/lib/host/browser/dialogs.d.ts +39 -0
- package/dist/lib/host/browser/dialogs.js +443 -0
- package/dist/lib/host/browser/drag.d.ts +70 -0
- package/dist/lib/host/browser/drag.js +268 -0
- package/dist/lib/host/browser/drawings.d.ts +30 -0
- package/dist/lib/host/browser/drawings.js +176 -0
- package/dist/lib/host/browser/events.d.ts +16 -0
- package/dist/lib/host/browser/events.js +125 -0
- package/dist/lib/host/browser/faces.d.ts +35 -0
- package/dist/lib/host/browser/faces.js +131 -0
- package/dist/lib/host/browser/fields.d.ts +16 -0
- package/dist/lib/host/browser/fields.js +322 -0
- package/dist/lib/host/browser/keys.d.ts +29 -0
- package/dist/lib/host/browser/keys.js +151 -0
- package/dist/lib/host/browser/lookup.d.ts +25 -0
- package/dist/lib/host/browser/lookup.js +275 -0
- package/dist/lib/host/browser/menus.d.ts +20 -0
- package/dist/lib/host/browser/menus.js +149 -0
- package/dist/lib/host/browser/mount.d.ts +92 -0
- package/dist/lib/host/browser/mount.js +448 -0
- package/dist/lib/host/browser/orbits.d.ts +90 -0
- package/dist/lib/host/browser/orbits.js +379 -0
- package/dist/lib/host/browser/page.d.ts +13 -0
- package/dist/lib/host/browser/page.js +35 -0
- package/dist/lib/host/browser/richtext.d.ts +19 -0
- package/dist/lib/host/browser/richtext.js +379 -0
- package/dist/lib/host/browser/row-faces.d.ts +5 -0
- package/dist/lib/host/browser/row-faces.js +74 -0
- package/dist/lib/host/browser/screens.d.ts +37 -0
- package/dist/lib/host/browser/screens.js +140 -0
- package/dist/lib/host/browser/swipe.d.ts +31 -0
- package/dist/lib/host/browser/swipe.js +178 -0
- package/dist/lib/host/browser/sync.d.ts +24 -0
- package/dist/lib/host/browser/sync.js +450 -0
- package/dist/lib/host/browser/tables.d.ts +65 -0
- package/dist/lib/host/browser/tables.js +505 -0
- package/dist/lib/host/browser/times.d.ts +14 -0
- package/dist/lib/host/browser/times.js +114 -0
- package/dist/lib/host/browser/toolbars.d.ts +17 -0
- package/dist/lib/host/browser/toolbars.js +129 -0
- package/dist/lib/host/browser/trees.d.ts +20 -0
- package/dist/lib/host/browser/trees.js +235 -0
- package/dist/lib/host/browser/uploads.d.ts +29 -0
- package/dist/lib/host/browser/uploads.js +370 -0
- package/dist/lib/host/browser/widget.d.ts +13 -0
- package/dist/lib/host/browser/widget.js +105 -0
- package/dist/lib/host/browser.d.ts +25 -0
- package/dist/lib/host/browser.js +84 -4812
- package/dist/lib/host/devtools/console.d.ts +9 -0
- package/dist/lib/host/devtools/console.js +104 -0
- package/dist/lib/host/devtools/faces.d.ts +25 -0
- package/dist/lib/host/devtools/faces.js +169 -0
- package/dist/lib/host/devtools/log.d.ts +3 -0
- package/dist/lib/host/devtools/log.js +32 -0
- package/dist/lib/host/devtools/machines.d.ts +34 -0
- package/dist/lib/host/devtools/machines.js +212 -0
- package/dist/lib/host/devtools/read.d.ts +13 -0
- package/dist/lib/host/devtools/read.js +52 -0
- package/dist/lib/host/devtools/state.d.ts +90 -0
- package/dist/lib/host/devtools/state.js +123 -0
- package/dist/lib/host/devtools.d.ts +15 -19
- package/dist/lib/host/devtools.js +39 -427
- package/dist/lib/host/fonts.js +4 -3
- package/dist/lib/host/icons.js +4 -0
- package/dist/lib/host/index.d.ts +3 -1
- package/dist/lib/host/index.js +107 -4
- package/dist/lib/host/locale.d.ts +18 -0
- package/dist/lib/host/locale.js +75 -5
- package/dist/lib/host/markdown.d.ts +4 -0
- package/dist/lib/host/markdown.js +8 -0
- package/dist/lib/host/modules.js +118 -19
- package/dist/lib/host/motion.d.ts +32 -0
- package/dist/lib/host/motion.js +190 -0
- package/dist/lib/host/net.js +5 -2
- package/dist/lib/host/palette.d.ts +17 -0
- package/dist/lib/host/palette.js +131 -0
- package/dist/lib/host/scheduler.d.ts +2 -0
- package/dist/lib/host/scheduler.js +4 -0
- package/dist/lib/host/share.d.ts +31 -0
- package/dist/lib/host/share.js +134 -0
- package/dist/lib/host/theme/classic.d.ts +1 -0
- package/dist/lib/host/theme/classic.js +120 -0
- package/dist/lib/host/theme/cupertino.d.ts +1 -0
- package/dist/lib/host/theme/cupertino.js +65 -0
- package/dist/lib/host/theme/data.d.ts +1 -0
- package/dist/lib/host/theme/data.js +109 -0
- package/dist/lib/host/theme/devtools.d.ts +1 -0
- package/dist/lib/host/theme/devtools.js +166 -0
- package/dist/lib/host/theme/dialogs.d.ts +1 -0
- package/dist/lib/host/theme/dialogs.js +63 -0
- package/dist/lib/host/theme/fluent.d.ts +1 -0
- package/dist/lib/host/theme/fluent.js +64 -0
- package/dist/lib/host/theme/forms.d.ts +1 -0
- package/dist/lib/host/theme/forms.js +239 -0
- package/dist/lib/host/theme/fusion.d.ts +1 -0
- package/dist/lib/host/theme/fusion.js +66 -0
- package/dist/lib/host/theme/layout.d.ts +1 -0
- package/dist/lib/host/theme/layout.js +166 -0
- package/dist/lib/host/theme/media.d.ts +1 -0
- package/dist/lib/host/theme/media.js +106 -0
- package/dist/lib/host/theme/navigation.d.ts +1 -0
- package/dist/lib/host/theme/navigation.js +36 -0
- package/dist/lib/host/theme/panes.d.ts +1 -0
- package/dist/lib/host/theme/panes.js +99 -0
- package/dist/lib/host/theme/popups.d.ts +1 -0
- package/dist/lib/host/theme/popups.js +149 -0
- package/dist/lib/host/theme/responsive.d.ts +1 -0
- package/dist/lib/host/theme/responsive.js +103 -0
- package/dist/lib/host/theme/toasts.d.ts +1 -0
- package/dist/lib/host/theme/toasts.js +62 -0
- package/dist/lib/host/theme.js +19 -1384
- package/dist/lib/ui/dialect/events.trb +276 -0
- package/dist/lib/ui/dialect/faces.trb +135 -0
- package/dist/lib/ui/dialect/layout.trb +283 -0
- package/dist/lib/ui/dialect/palette.trb +87 -0
- package/dist/lib/ui/dialect/problems.trb +174 -0
- package/dist/lib/ui/dialect/reactions.trb +198 -0
- package/dist/lib/ui/dialect/rows.trb +208 -0
- package/dist/lib/ui/dialect/screens.trb +293 -0
- package/dist/lib/ui/dialect/steps.trb +203 -0
- package/dist/lib/ui/dialect/validation.trb +137 -0
- package/dist/lib/ui/dialect/view.trb +110 -0
- package/dist/lib/ui/dialect/walking.trb +98 -0
- package/dist/lib/ui/dialect/words.trb +70 -0
- package/dist/lib/ui/i18n.trb +17 -0
- package/dist/lib/ui/test.trb +3 -556
- package/dist/lib/ui/testing/actions.trb +421 -0
- package/dist/lib/ui/testing/faces.trb +148 -0
- package/dist/lib/ui/testing/server.trb +73 -0
- package/dist/lib/ui/ui.trb +25 -1675
- package/dist/trebol.js +4463 -1891
- package/package.json +1 -1
- package/src/core/boot.ts +9 -6
- package/src/core/eval.ts +2 -2
- package/src/core/machine/checks.ts +251 -0
- package/src/core/machine/events.ts +366 -0
- package/src/core/machine/running.ts +181 -0
- package/src/core/machine/shared.ts +124 -0
- package/src/core/machine/snapshot.ts +245 -0
- package/src/core/machine/spec.ts +275 -0
- package/src/core/machine/words.ts +99 -0
- package/src/core/machine.ts +20 -0
- package/src/core/mezz.ts +31 -0
- package/src/core/natives/control.ts +1 -1
- package/src/core/natives/data.ts +6 -1
- package/src/core/natives/parse.ts +1 -1
- package/src/core/natives/series.ts +47 -11
- package/src/core/natives/text.ts +0 -1
- package/src/host/browser/calendar.ts +264 -0
- package/src/host/browser/count.ts +48 -0
- package/src/host/browser/dialogs.ts +439 -0
- package/src/host/browser/drag.ts +278 -0
- package/src/host/browser/drawings.ts +178 -0
- package/src/host/browser/events.ts +117 -0
- package/src/host/browser/faces.ts +143 -0
- package/src/host/browser/fields.ts +315 -0
- package/src/host/browser/keys.ts +145 -0
- package/src/host/browser/lookup.ts +262 -0
- package/src/host/browser/menus.ts +146 -0
- package/src/host/browser/mount.ts +420 -0
- package/src/host/browser/orbits.ts +418 -0
- package/src/host/browser/page.ts +43 -0
- package/src/host/browser/richtext.ts +346 -0
- package/src/host/browser/row-faces.ts +75 -0
- package/src/host/browser/screens.ts +142 -0
- package/src/host/browser/swipe.ts +168 -0
- package/src/host/browser/sync.ts +354 -0
- package/src/host/browser/tables.ts +461 -0
- package/src/host/browser/times.ts +115 -0
- package/src/host/browser/toolbars.ts +126 -0
- package/src/host/browser/trees.ts +205 -0
- package/src/host/browser/uploads.ts +367 -0
- package/src/host/browser/widget.ts +103 -0
- package/src/host/browser.ts +82 -4612
- package/src/host/devtools/console.ts +102 -0
- package/src/host/devtools/faces.ts +160 -0
- package/src/host/devtools/log.ts +34 -0
- package/src/host/devtools/machines.ts +208 -0
- package/src/host/devtools/read.ts +58 -0
- package/src/host/devtools/state.ts +148 -0
- package/src/host/devtools.ts +39 -442
- package/src/host/fonts.ts +4 -3
- package/src/host/icons.ts +4 -0
- package/src/host/index.ts +107 -4
- package/src/host/locale.ts +71 -5
- package/src/host/markdown.ts +9 -0
- package/src/host/modules.ts +117 -21
- package/src/host/motion.ts +204 -0
- package/src/host/net.ts +4 -2
- package/src/host/palette.ts +139 -0
- package/src/host/scheduler.ts +5 -0
- package/src/host/share.ts +168 -0
- package/src/host/theme/classic.ts +121 -0
- package/src/host/theme/cupertino.ts +66 -0
- package/src/host/theme/data.ts +110 -0
- package/src/host/theme/devtools.ts +167 -0
- package/src/host/theme/dialogs.ts +64 -0
- package/src/host/theme/fluent.ts +65 -0
- package/src/host/theme/forms.ts +240 -0
- package/src/host/theme/fusion.ts +67 -0
- package/src/host/theme/layout.ts +167 -0
- package/src/host/theme/media.ts +107 -0
- package/src/host/theme/navigation.ts +37 -0
- package/src/host/theme/panes.ts +100 -0
- package/src/host/theme/popups.ts +150 -0
- package/src/host/theme/responsive.ts +104 -0
- package/src/host/theme/toasts.ts +63 -0
- package/src/host/theme.ts +19 -1384
- package/src/ui/dialect/events.trb +276 -0
- package/src/ui/dialect/faces.trb +135 -0
- package/src/ui/dialect/layout.trb +283 -0
- package/src/ui/dialect/palette.trb +87 -0
- package/src/ui/dialect/problems.trb +174 -0
- package/src/ui/dialect/reactions.trb +198 -0
- package/src/ui/dialect/rows.trb +208 -0
- package/src/ui/dialect/screens.trb +293 -0
- package/src/ui/dialect/steps.trb +203 -0
- package/src/ui/dialect/validation.trb +137 -0
- package/src/ui/dialect/view.trb +110 -0
- package/src/ui/dialect/walking.trb +98 -0
- package/src/ui/dialect/words.trb +70 -0
- package/src/ui/i18n.trb +17 -0
- package/src/ui/test.trb +3 -556
- package/src/ui/testing/actions.trb +421 -0
- package/src/ui/testing/faces.trb +148 -0
- package/src/ui/testing/server.trb +73 -0
- package/src/ui/ui.trb +25 -1675
package/src/ui/test.trb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Trebol [
|
|
2
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 test-answer test-route]
|
|
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]
|
|
4
5
|
]
|
|
5
6
|
|
|
6
7
|
; `trebol test` runs every block of an app.test.trb on the app started anew,
|
|
@@ -8,558 +9,4 @@ Trebol [
|
|
|
8
9
|
; by what the user sees, a label, the text of a button or a hint, or by their
|
|
9
10
|
; name; only faces on show count, so a closed dialog or another tab is not there.
|
|
10
11
|
|
|
11
|
-
;
|
|
12
|
-
|
|
13
|
-
; [method path handler ...] of every serve
|
|
14
|
-
test-routes: copy []
|
|
15
|
-
|
|
16
|
-
serve: function [
|
|
17
|
-
"Answers the requests of the app: a method, a path and a block that gives the answer, for each; a later serve comes first."
|
|
18
|
-
routes [block!] {GET "/api/clients/:id" [...]: the block sees body, query and the :words of the path}
|
|
19
|
-
/local m p b pos
|
|
20
|
-
] [
|
|
21
|
-
new: copy []
|
|
22
|
-
parse routes [any [
|
|
23
|
-
set m ['GET | 'POST | 'PUT | 'PATCH | 'DELETE] set p string! set b block! (append new reduce [m p b])
|
|
24
|
-
| pos: skip (do make error! rejoin ["serve takes a method, a path and a block, not " mold/flat first pos])
|
|
25
|
-
]]
|
|
26
|
-
; a later serve, as one in a test, answers before those it follows
|
|
27
|
-
insert test-routes new
|
|
28
|
-
true
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
reply: func [
|
|
32
|
-
"An answer of serve with its status: reply 422 #(errors: ...)."
|
|
33
|
-
status [integer!]
|
|
34
|
-
data [any-type!]
|
|
35
|
-
] [
|
|
36
|
-
make object! [reply-status: status reply-data: :data]
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
; The words a path gives: "/api/clients/:id" and "/api/clients/42" -> [id: "42"]; none if they do not match.
|
|
40
|
-
test-match: function [pattern [string!] path [string!]] [
|
|
41
|
-
want: split pattern #"/"
|
|
42
|
-
got: split path #"/"
|
|
43
|
-
if (length? want) <> length? got [return none]
|
|
44
|
-
words: copy []
|
|
45
|
-
repeat i length? want [
|
|
46
|
-
w: pick want i g: pick got i
|
|
47
|
-
case [
|
|
48
|
-
#":" = first w [append words reduce [to set-word! next w dehex g]]
|
|
49
|
-
w <> g [return none]
|
|
50
|
-
]
|
|
51
|
-
]
|
|
52
|
-
words
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
test-answer: function [
|
|
56
|
-
"Called by the host for each request of the app: its status and its body as JSON, or none when serve has no answer for it."
|
|
57
|
-
method [word!] url [string!] body [string! none!]
|
|
58
|
-
] [
|
|
59
|
-
path: url
|
|
60
|
-
query: make map! []
|
|
61
|
-
if q: find url #"?" [
|
|
62
|
-
path: copy/part url q
|
|
63
|
-
foreach part split next q #"&" [
|
|
64
|
-
kv: split part #"="
|
|
65
|
-
poke query to word! dehex first kv either second kv [dehex second kv] [""]
|
|
66
|
-
]
|
|
67
|
-
]
|
|
68
|
-
foreach [m pattern b] test-routes [
|
|
69
|
-
if all [m = method words: test-match pattern path] [
|
|
70
|
-
data: all [body any [attempt [load-json body] body]]
|
|
71
|
-
append words compose/only [body: (data) query: (query)]
|
|
72
|
-
r: do bind copy/deep b make object! words
|
|
73
|
-
return either all [object? :r in r 'reply-status] [
|
|
74
|
-
reduce [r/reply-status to-json :r/reply-data]
|
|
75
|
-
] [
|
|
76
|
-
reduce [200 to-json :r]
|
|
77
|
-
]
|
|
78
|
-
]
|
|
79
|
-
]
|
|
80
|
-
none
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
; --- the faces on show ----------------------------------------------------------
|
|
84
|
-
|
|
85
|
-
; [face parent ...] of the faces the user sees, in their order on the page; first
|
|
86
|
-
; the reactions run, as the browser runs them at the end of each round
|
|
87
|
-
test-shown: function [] [
|
|
88
|
-
out: copy []
|
|
89
|
-
if v: shown-view [
|
|
90
|
-
foreach cycle ui-react v [print cycle]
|
|
91
|
-
test-walk v none out
|
|
92
|
-
]
|
|
93
|
-
out
|
|
94
|
-
]
|
|
95
|
-
|
|
96
|
-
test-walk: function [f parent out] [
|
|
97
|
-
; on a wide screen, as the tests see it
|
|
98
|
-
if any [f/hidden f/narrow-only] [exit]
|
|
99
|
-
append out reduce [f parent]
|
|
100
|
-
unless block? f/pane [exit]
|
|
101
|
-
either f/style = 'tabs [
|
|
102
|
-
; the label of every tab, the faces of the one chosen
|
|
103
|
-
repeat i length? f/pane [
|
|
104
|
-
t: pick f/pane i
|
|
105
|
-
append out reduce [t f]
|
|
106
|
-
if all [i = f/value block? t/pane] [foreach c t/pane [test-walk c t out]]
|
|
107
|
-
]
|
|
108
|
-
] [
|
|
109
|
-
foreach c f/pane [test-walk c f out]
|
|
110
|
-
]
|
|
111
|
-
]
|
|
112
|
-
|
|
113
|
-
test-route: function [
|
|
114
|
-
"Called by the host when the page goes back or forward: the screens on show follow the link."
|
|
115
|
-
parts [block!]
|
|
116
|
-
/local f p
|
|
117
|
-
] [
|
|
118
|
-
foreach [f p] test-shown [if f/style = 'screens [return ui-route f parts]]
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
; What a text of the interface shows: a string, a text per language or a word of the dictionary.
|
|
122
|
-
test-text: func [t] [either any [none? :t logic? :t] [none] [tr t]]
|
|
123
|
-
|
|
124
|
-
; The cells of a row of a table or list, as shown.
|
|
125
|
-
test-cells: function [f row /local w label] [
|
|
126
|
-
collect [
|
|
127
|
-
foreach [w label] any [f/columns []] [
|
|
128
|
-
v: select row w
|
|
129
|
-
unless none? :v [keep either string? :v [v] [localize :v]]
|
|
130
|
-
]
|
|
131
|
-
]
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
; Every text on show: of faces, values, errors and rows, and the notices shown.
|
|
135
|
-
test-texts: function [/local f p t] [
|
|
136
|
-
out: copy []
|
|
137
|
-
foreach [f p] test-shown [
|
|
138
|
-
foreach t reduce [test-text f/text test-text f/hint f/error] [if string? t [append out t]]
|
|
139
|
-
v: f/value
|
|
140
|
-
case [
|
|
141
|
-
string? :v [append out v]
|
|
142
|
-
find [number money date] f/style [if v [append out localize v]]
|
|
143
|
-
]
|
|
144
|
-
if all [f/style = 'lookup v] [
|
|
145
|
-
foreach one either block? v [v] [reduce [v]] [
|
|
146
|
-
append out either t: all [f/known select f/known one] [test-text t] [form one]
|
|
147
|
-
]
|
|
148
|
-
]
|
|
149
|
-
; the names of the files an upload or photo has
|
|
150
|
-
if all [find [upload photo] f/style v] [
|
|
151
|
-
foreach one either block? v [v] [reduce [v]] [if object? one [append out one/name]]
|
|
152
|
-
]
|
|
153
|
-
if all [find [choice radio] f/style v] [
|
|
154
|
-
foreach o any [f/options []] [
|
|
155
|
-
if all [map? o (form v) = form o/value] [append out test-text o/text]
|
|
156
|
-
]
|
|
157
|
-
]
|
|
158
|
-
if all [find [table list] f/style block? f/data] [
|
|
159
|
-
foreach row f/data [append out test-cells f row]
|
|
160
|
-
]
|
|
161
|
-
; the title of every node of an orbit, its focus too
|
|
162
|
-
if all [f/style = 'orbit block? f/data] [
|
|
163
|
-
parse any [select f/data 'nodes []] [any [skip set t skip (append out test-text t) opt block!]]
|
|
164
|
-
]
|
|
165
|
-
]
|
|
166
|
-
append out shown-toasts
|
|
167
|
-
append out shown-questions
|
|
168
|
-
out
|
|
169
|
-
]
|
|
170
|
-
|
|
171
|
-
; The nodes of an orbit as [id title back ...]: its neighbours, and its trail with back true.
|
|
172
|
-
test-orbit-nodes: function [f /local id t] [
|
|
173
|
-
out: copy []
|
|
174
|
-
unless block? f/data [return out]
|
|
175
|
-
focus: select f/data 'focus
|
|
176
|
-
trail: any [select f/data 'trail []]
|
|
177
|
-
parse any [select f/data 'nodes []] [any [
|
|
178
|
-
set id skip set t skip opt block! (
|
|
179
|
-
unless id = focus [append out reduce [id test-text t to logic! find trail id]]
|
|
180
|
-
)
|
|
181
|
-
]]
|
|
182
|
-
out
|
|
183
|
-
]
|
|
184
|
-
|
|
185
|
-
; What a face is called: its label, hint or the text it shows.
|
|
186
|
-
test-called?: function [f what] [
|
|
187
|
-
either word? what [f/name = what] [
|
|
188
|
-
any [what = test-text f/text what = test-text f/hint]
|
|
189
|
-
]
|
|
190
|
-
]
|
|
191
|
-
|
|
192
|
-
; The one face on show of some styles called what; an error naming the action if there is none or more than one.
|
|
193
|
-
test-face: function [action [word!] styles [block!] what /local f p] [
|
|
194
|
-
found: copy []
|
|
195
|
-
foreach [f p] test-shown [
|
|
196
|
-
if all [find styles f/style test-called? f what] [append found reduce [f p]]
|
|
197
|
-
]
|
|
198
|
-
if empty? found [do make error! rejoin [action ": nothing on the screen is " mold what]]
|
|
199
|
-
if 2 < length? found [do make error! rejoin [action ": " (length? found) / 2 " faces on the screen are " mold what]]
|
|
200
|
-
f: first found
|
|
201
|
-
if any [f/disabled f/inert f/readonly] [do make error! rejoin [action ": " mold what " cannot be used now"]]
|
|
202
|
-
found
|
|
203
|
-
]
|
|
204
|
-
|
|
205
|
-
; --- what the user does ---------------------------------------------------------
|
|
206
|
-
|
|
207
|
-
text-styles: [field password number money date area rich]
|
|
208
|
-
|
|
209
|
-
click: function [
|
|
210
|
-
"Clicks a button, link, tile, check, toggle or tab, the row of a table or list that shows a text, or a node of an orbit."
|
|
211
|
-
what [string! word!] "What it shows, or a field's name"
|
|
212
|
-
/local f p row id t back
|
|
213
|
-
] [
|
|
214
|
-
if string? what [
|
|
215
|
-
; a neighbour of an orbit, or a node of its trail
|
|
216
|
-
foreach [f p] test-shown [
|
|
217
|
-
if f/style = 'orbit [
|
|
218
|
-
foreach [id t back] test-orbit-nodes f [
|
|
219
|
-
if t = what [
|
|
220
|
-
if any [f/disabled f/inert] [do make error! rejoin ["click: " mold what " cannot be used now"]]
|
|
221
|
-
ui-orbit f id back
|
|
222
|
-
return true
|
|
223
|
-
]
|
|
224
|
-
]
|
|
225
|
-
]
|
|
226
|
-
]
|
|
227
|
-
; a row of a table or list
|
|
228
|
-
foreach [f p] test-shown [
|
|
229
|
-
if all [find [table list] f/style block? f/data] [
|
|
230
|
-
foreach row f/data [
|
|
231
|
-
if find test-cells f row what [
|
|
232
|
-
if any [f/disabled f/inert] [do make error! rejoin ["click: " mold what " cannot be used now"]]
|
|
233
|
-
ui-select f row
|
|
234
|
-
return true
|
|
235
|
-
]
|
|
236
|
-
]
|
|
237
|
-
]
|
|
238
|
-
]
|
|
239
|
-
]
|
|
240
|
-
found: test-face 'click [button link tile check toggle tab] what
|
|
241
|
-
test-activate first found second found
|
|
242
|
-
]
|
|
243
|
-
|
|
244
|
-
; Does what a click on a face does; parent is the face it is in.
|
|
245
|
-
test-activate: function [f parent] [
|
|
246
|
-
switch/default f/style [
|
|
247
|
-
check toggle [ui-input f not f/value ui-blur f]
|
|
248
|
-
tab [ui-input parent index? find parent/pane f]
|
|
249
|
-
link [
|
|
250
|
-
case [
|
|
251
|
-
f/action [ui-click f]
|
|
252
|
-
any [word? f/value path? f/value] [go f/value]
|
|
253
|
-
]
|
|
254
|
-
]
|
|
255
|
-
] [ui-click f]
|
|
256
|
-
true
|
|
257
|
-
]
|
|
258
|
-
|
|
259
|
-
type: function [
|
|
260
|
-
"Types a text in a field, then leaves it; an empty text clears it."
|
|
261
|
-
what [string! word!] "Its label or hint, or its name"
|
|
262
|
-
text [any-type!] "What to type; a number or date is typed as written"
|
|
263
|
-
] [
|
|
264
|
-
f: first test-face 'type text-styles what
|
|
265
|
-
text: either string? :text [text] [form :text]
|
|
266
|
-
ui-input f either empty? text [none] [text]
|
|
267
|
-
ui-blur f
|
|
268
|
-
true
|
|
269
|
-
]
|
|
270
|
-
|
|
271
|
-
choose: function [
|
|
272
|
-
"Chooses an option of a choice, radio or lookup by the text it shows."
|
|
273
|
-
what [string! word!] "Its label, or its name"
|
|
274
|
-
option [string!]
|
|
275
|
-
/local o
|
|
276
|
-
] [
|
|
277
|
-
f: first test-face 'choose [choice radio lookup] what
|
|
278
|
-
if f/style = 'lookup [
|
|
279
|
-
ui-lookup-search f option
|
|
280
|
-
foreach o any [f/options []] [
|
|
281
|
-
if option = test-text o/text [
|
|
282
|
-
ui-lookup-pick f o
|
|
283
|
-
ui-blur f
|
|
284
|
-
return true
|
|
285
|
-
]
|
|
286
|
-
]
|
|
287
|
-
do make error! rejoin ["choose: " mold what " finds no " mold option]
|
|
288
|
-
]
|
|
289
|
-
; a group of options is a title then a block of them
|
|
290
|
-
options: collect [
|
|
291
|
-
opts: any [f/options []]
|
|
292
|
-
forall opts [
|
|
293
|
-
case [
|
|
294
|
-
block? first opts [keep first opts]
|
|
295
|
-
not block? pick opts 2 [keep/only first opts]
|
|
296
|
-
]
|
|
297
|
-
]
|
|
298
|
-
]
|
|
299
|
-
foreach o options [
|
|
300
|
-
if option = either map? o [test-text o/text] [form o] [
|
|
301
|
-
ui-input f form either map? o [o/value] [o]
|
|
302
|
-
ui-blur f
|
|
303
|
-
return true
|
|
304
|
-
]
|
|
305
|
-
]
|
|
306
|
-
do make error! rejoin ["choose: " mold what " has no option " mold option]
|
|
307
|
-
]
|
|
308
|
-
|
|
309
|
-
pick-menu: function [
|
|
310
|
-
"Chooses an item of the menu a button opens, of the context menu of a face, or of the row of a table or list that shows a text."
|
|
311
|
-
what [string! word!] "What the face or row shows, or a face's name"
|
|
312
|
-
item [string! block!] {The item's text; ["Move to" "Top"] for one in a submenu}
|
|
313
|
-
/local f p row i
|
|
314
|
-
] [
|
|
315
|
-
on: none row: none
|
|
316
|
-
if string? what [
|
|
317
|
-
; foreach keeps its words to itself
|
|
318
|
-
foreach [f p] test-shown [
|
|
319
|
-
if all [find [table list] f/style block? f/data f/menu] [
|
|
320
|
-
foreach r f/data [if find test-cells f r what [on: f row: r break]]
|
|
321
|
-
if row [break]
|
|
322
|
-
]
|
|
323
|
-
]
|
|
324
|
-
]
|
|
325
|
-
either on [f: on] [
|
|
326
|
-
f: first test-face 'pick-menu collect [foreach [f p] test-shown [keep f/style]] what
|
|
327
|
-
unless block? f/menu [do make error! rejoin ["pick-menu: " mold what " has no menu"]]
|
|
328
|
-
]
|
|
329
|
-
if any [f/disabled f/inert] [do make error! rejoin ["pick-menu: " mold what " cannot be used now"]]
|
|
330
|
-
items: f/menu
|
|
331
|
-
texts: either block? item [item] [reduce [item]]
|
|
332
|
-
forall texts [
|
|
333
|
-
found: none
|
|
334
|
-
foreach i items [if all [not i/divider (first texts) = test-text i/text] [found: i break]]
|
|
335
|
-
unless found [do make error! rejoin ["pick-menu: the menu of " mold what " has no " mold first texts]]
|
|
336
|
-
either tail? next texts [
|
|
337
|
-
if found/items [do make error! rejoin ["pick-menu: " mold first texts " opens a submenu"]]
|
|
338
|
-
] [
|
|
339
|
-
unless found/items [do make error! rejoin ["pick-menu: " mold first texts " has no submenu"]]
|
|
340
|
-
items: found/items
|
|
341
|
-
]
|
|
342
|
-
]
|
|
343
|
-
ui-menu f found row
|
|
344
|
-
true
|
|
345
|
-
]
|
|
346
|
-
|
|
347
|
-
; [face row index ...] of the rows of the tables and lists on show that show a text.
|
|
348
|
-
test-rows: function [what /local f p] [
|
|
349
|
-
out: copy []
|
|
350
|
-
if string? what [
|
|
351
|
-
foreach [f p] test-shown [
|
|
352
|
-
if all [find [table list] f/style block? f/data] [
|
|
353
|
-
repeat i length? f/data [
|
|
354
|
-
if find test-cells f pick f/data i what [append out reduce [f pick f/data i i]]
|
|
355
|
-
]
|
|
356
|
-
]
|
|
357
|
-
]
|
|
358
|
-
]
|
|
359
|
-
out
|
|
360
|
-
]
|
|
361
|
-
|
|
362
|
-
drag: function [
|
|
363
|
-
"Drags a face, or the row of a table or list that shows a text, onto another: in a list that can be reordered it takes that place, else it is dropped on it."
|
|
364
|
-
what [string! word!] "What the face or row shows, or a face's name"
|
|
365
|
-
onto [string! word!] "The place it goes: a face, or the row it goes before"
|
|
366
|
-
/local f p row i
|
|
367
|
-
] [
|
|
368
|
-
shown: test-shown
|
|
369
|
-
styles: collect [foreach [f p] shown [keep f/style]]
|
|
370
|
-
; what is dragged: its face, what it carries, where it is, and the face it moves in
|
|
371
|
-
either not empty? rows: test-rows what [
|
|
372
|
-
set [from payload index] rows
|
|
373
|
-
; rows the user sorted by a header are not in the order of their data
|
|
374
|
-
sorted: all [from/sortable from/sorted not all [from/events select from/events 'on-sort]]
|
|
375
|
-
within: all [from/reorder not sorted from]
|
|
376
|
-
unless any [from/drag within] [do make error! rejoin ["drag: the rows of " mold what " cannot be dragged"]]
|
|
377
|
-
] [
|
|
378
|
-
set [from p] test-face 'drag styles what
|
|
379
|
-
payload: from/value
|
|
380
|
-
within: all [p p/reorder not find [table list tree] p/style p]
|
|
381
|
-
index: all [within index? find/same within/pane from]
|
|
382
|
-
unless any [from/drag within] [do make error! rejoin ["drag: " mold what " cannot be dragged"]]
|
|
383
|
-
]
|
|
384
|
-
; moved to another place among its own
|
|
385
|
-
if within [
|
|
386
|
-
place: none
|
|
387
|
-
either find [table list] within/style [
|
|
388
|
-
foreach [f row i] test-rows onto [if same? f within [place: i break]]
|
|
389
|
-
] [
|
|
390
|
-
foreach c within/pane [if all [not c/hidden test-called? c onto] [place: index? find/same within/pane c break]]
|
|
391
|
-
]
|
|
392
|
-
if place [
|
|
393
|
-
ui-reorder within index place none
|
|
394
|
-
return true
|
|
395
|
-
]
|
|
396
|
-
]
|
|
397
|
-
; dropped on a face, or before a row of one
|
|
398
|
-
zone: none
|
|
399
|
-
; foreach keeps its words to itself
|
|
400
|
-
foreach [f row i] test-rows onto [if f/drop [zone: f at: i break]]
|
|
401
|
-
either zone [
|
|
402
|
-
if same? zone from [do make error! rejoin ["drag: " mold what " is already in " mold onto]]
|
|
403
|
-
] [
|
|
404
|
-
zone: first test-face 'drag styles onto
|
|
405
|
-
unless zone/drop [do make error! rejoin ["drag: " mold onto " takes nothing dropped"]]
|
|
406
|
-
if test-inside? zone from shown [do make error! rejoin ["drag: " mold what " cannot go into itself"]]
|
|
407
|
-
at: 1 + length? either find [table list tree] zone/style [any [zone/data []]] [any [zone/pane []]]
|
|
408
|
-
]
|
|
409
|
-
ui-drop zone :payload from at none
|
|
410
|
-
true
|
|
411
|
-
]
|
|
412
|
-
|
|
413
|
-
; Does an upload or photo whose accept is list take a file? As the browser's picker: "pdf" and ".pdf"
|
|
414
|
-
; by its name, "image/png" and "image/*" by its type.
|
|
415
|
-
test-accepts?: function [list [block!] name [string!] type [string!]] [
|
|
416
|
-
if empty? list [return true]
|
|
417
|
-
name: lowercase copy name
|
|
418
|
-
type: lowercase copy type
|
|
419
|
-
foreach x list [
|
|
420
|
-
x: lowercase trim form x
|
|
421
|
-
if either find x #"/" [
|
|
422
|
-
either #"*" = last x [find/match type copy/part x (length? x) - 1] [type = x]
|
|
423
|
-
] [
|
|
424
|
-
unless #"." = first x [x: join "." x]
|
|
425
|
-
all [(length? name) >= length? x x = skip tail name negate length? x]
|
|
426
|
-
] [return true]
|
|
427
|
-
]
|
|
428
|
-
false
|
|
429
|
-
]
|
|
430
|
-
|
|
431
|
-
attach: function [
|
|
432
|
-
"Chooses files for an upload or photo, as the user picks them or drops them on it; the ones its accept refuses are refused, as the browser does."
|
|
433
|
-
what [string! word!] "Its label, or its name"
|
|
434
|
-
files [file! block!] "A file next to the test, or a block of them"
|
|
435
|
-
] [
|
|
436
|
-
f: first test-face 'attach [upload photo] what
|
|
437
|
-
list: either block? f/accept [f/accept] [either f/style = 'photo [["image/*"]] [[]]]
|
|
438
|
-
taken: copy []
|
|
439
|
-
refused: copy []
|
|
440
|
-
foreach file either block? files [files] [reduce [files]] [
|
|
441
|
-
one: test-file file
|
|
442
|
-
either test-accepts? list one/1 one/3 [append taken one] [append refused one/1]
|
|
443
|
-
]
|
|
444
|
-
; one file unless it takes more
|
|
445
|
-
unless f/multiple [taken: copy/part taken 4]
|
|
446
|
-
ui-files f taken refused
|
|
447
|
-
true
|
|
448
|
-
]
|
|
449
|
-
|
|
450
|
-
; The face a face is in, among the faces on show.
|
|
451
|
-
test-parent: function [f shown /local g p] [
|
|
452
|
-
foreach [g p] shown [if same? g f [return p]]
|
|
453
|
-
none
|
|
454
|
-
]
|
|
455
|
-
|
|
456
|
-
; Is f inside the face outer (or outer itself)?
|
|
457
|
-
test-inside?: function [f outer shown] [
|
|
458
|
-
while [f] [
|
|
459
|
-
if same? f outer [return true]
|
|
460
|
-
f: test-parent f shown
|
|
461
|
-
]
|
|
462
|
-
false
|
|
463
|
-
]
|
|
464
|
-
|
|
465
|
-
; "Ctrl+Shift+K" -> [ctrl shift alt key] as the browser compares them: Ctrl and Cmd are one, names as
|
|
466
|
-
; the browser gives them, a letter in lower case
|
|
467
|
-
test-keys: function [spec [string!] /local k] [
|
|
468
|
-
parts: split lowercase copy spec #"+"
|
|
469
|
-
foreach k parts [trim k]
|
|
470
|
-
k: take/last parts
|
|
471
|
-
if empty? k [k: "+"]
|
|
472
|
-
k: any [select ["esc" "escape" "del" "delete" "up" "arrowup" "down" "arrowdown" "left" "arrowleft" "right" "arrowright" "space" " "] k k]
|
|
473
|
-
any-of: func [names] [not empty? intersect parts names]
|
|
474
|
-
reduce [any-of ["ctrl" "control" "cmd" "meta"] any-of ["shift"] any-of ["alt" "option"] k]
|
|
475
|
-
]
|
|
476
|
-
|
|
477
|
-
; The key of "Ctrl+S" as on-key gets it in event/key: a char (#"s", #"^M" for Enter) or a word ('left, 'F2).
|
|
478
|
-
test-key: function [spec [string!]] [
|
|
479
|
-
k: last split spec #"+"
|
|
480
|
-
if empty? k [k: "+"]
|
|
481
|
-
shift: find spec "shift+"
|
|
482
|
-
case [
|
|
483
|
-
c: select ["enter" #"^M" "escape" #"^[" "esc" #"^[" "tab" #"^-" "backspace" #"^H" "space" #" "] k [c]
|
|
484
|
-
1 = length? k [either shift [uppercase first k] [lowercase first k]]
|
|
485
|
-
w: select [
|
|
486
|
-
"left" left "arrowleft" left "right" right "arrowright" right "up" up "arrowup" up "down" down "arrowdown" down
|
|
487
|
-
"home" home "end" end "pageup" page-up "pagedown" page-down "insert" insert "delete" delete "del" delete
|
|
488
|
-
] k [w]
|
|
489
|
-
parse k [#"F" some digit] [to word! uppercase copy k]
|
|
490
|
-
true [do make error! rejoin ["press: " mold spec " is not a key"]]
|
|
491
|
-
]
|
|
492
|
-
]
|
|
493
|
-
|
|
494
|
-
digit: charset "0123456789"
|
|
495
|
-
|
|
496
|
-
press: function [
|
|
497
|
-
"Presses a key, as Enter or Ctrl+S: the button or link with it as its shortcut, or else the on-key of the face with the cursor, or of the view."
|
|
498
|
-
key [string!] {"Enter", "Escape", "Ctrl+S", "Shift+Tab", "a"}
|
|
499
|
-
/on "With the cursor in a face"
|
|
500
|
-
what [string! word!] "Its label, hint or text, or its name"
|
|
501
|
-
/local f p
|
|
502
|
-
] [
|
|
503
|
-
shown: test-shown
|
|
504
|
-
want: test-keys key
|
|
505
|
-
; a dialog on show keeps the rest of the page out of reach
|
|
506
|
-
dialog: none
|
|
507
|
-
foreach [f p] shown [if f/style = 'dialog [dialog: f]]
|
|
508
|
-
foreach [f p] shown [
|
|
509
|
-
if all [
|
|
510
|
-
f/shortcut
|
|
511
|
-
find [button link] f/style
|
|
512
|
-
want = test-keys f/shortcut
|
|
513
|
-
any [none? dialog test-inside? f dialog shown]
|
|
514
|
-
] [
|
|
515
|
-
if any [f/disabled f/inert] [do make error! rejoin ["press: " mold key " cannot be used now"]]
|
|
516
|
-
return test-activate f p
|
|
517
|
-
]
|
|
518
|
-
]
|
|
519
|
-
at: none
|
|
520
|
-
if on [at: first test-face 'press collect [foreach [f p] shown [keep f/style]] what]
|
|
521
|
-
k: test-key key
|
|
522
|
-
fields: reduce [
|
|
523
|
-
quote key: either word? k [to lit-word! k] [k]
|
|
524
|
-
quote ctrl?: to logic! find key "ctrl+" quote shift?: to logic! find key "shift+" quote alt?: to logic! find key "alt+"
|
|
525
|
-
quote meta?: to logic! any [find key "cmd+" find key "meta+"]
|
|
526
|
-
]
|
|
527
|
-
; the face with the cursor or the nearest around it that has an on-key, or the view
|
|
528
|
-
f: any [at shown-view]
|
|
529
|
-
while [all [f not all [f/events select f/events 'on-key]]] [f: either at [test-parent f shown] [none]]
|
|
530
|
-
if f [ui-event f 'on-key fields]
|
|
531
|
-
case [
|
|
532
|
-
; Enter in a one-line field of a form clicks its submit, if it can be clicked
|
|
533
|
-
all [at k = #"^M" find [field password number money date] at/style at/form at/form/style = 'form] [
|
|
534
|
-
foreach [f p] test-shown [
|
|
535
|
-
if all [f/submit same? f/form at/form] [
|
|
536
|
-
unless any [f/disabled f/inert] [ui-click f]
|
|
537
|
-
break
|
|
538
|
-
]
|
|
539
|
-
]
|
|
540
|
-
]
|
|
541
|
-
; Escape closes the dialog on show
|
|
542
|
-
all [k = #"^[" dialog] [ui-close dialog]
|
|
543
|
-
]
|
|
544
|
-
true
|
|
545
|
-
]
|
|
546
|
-
|
|
547
|
-
say: func [
|
|
548
|
-
"Says how the user answers the next question of confirm, which is yes when nothing is said; a test that leaves one unasked fails."
|
|
549
|
-
yes [logic!] "yes or no"
|
|
550
|
-
] [
|
|
551
|
-
test-say yes
|
|
552
|
-
]
|
|
553
|
-
|
|
554
|
-
see: function [
|
|
555
|
-
"True if a text is on the screen, in a face, a field, a row or a notice; an error otherwise."
|
|
556
|
-
text [string!]
|
|
557
|
-
/not "True if it is not on the screen"
|
|
558
|
-
] [
|
|
559
|
-
there: false
|
|
560
|
-
foreach t test-texts [if find t text [there: true break]]
|
|
561
|
-
if there = to logic! not [
|
|
562
|
-
do make error! rejoin ["see: " mold text either not [" is on the screen"] [" is not on the screen"]]
|
|
563
|
-
]
|
|
564
|
-
true
|
|
565
|
-
]
|
|
12
|
+
; The words are in its parts: the answers of the server, the faces on show, and what the user does.
|