trebol 0.1.0 → 0.1.2
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 +18 -3
- package/dist/cli.js +13790 -11417
- 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/access.d.ts +10 -0
- package/dist/lib/core/access.js +210 -0
- package/dist/lib/core/base.d.ts +4 -0
- package/dist/lib/core/base.js +50 -0
- package/dist/lib/core/bitset.d.ts +9 -0
- package/dist/lib/core/bitset.js +75 -0
- package/dist/lib/core/boot.d.ts +18 -0
- package/dist/lib/core/boot.js +73 -0
- package/dist/lib/core/compare.d.ts +9 -0
- package/dist/lib/core/compare.js +156 -0
- package/dist/lib/core/ctx.d.ts +36 -0
- package/dist/lib/core/ctx.js +251 -0
- package/dist/lib/core/dec.d.ts +28 -0
- package/dist/lib/core/dec.js +158 -0
- package/dist/lib/core/errors.d.ts +15 -0
- package/dist/lib/core/errors.js +44 -0
- package/dist/lib/core/escapes.d.ts +14 -0
- package/dist/lib/core/escapes.js +80 -0
- package/dist/lib/core/eval.d.ts +220 -0
- package/dist/lib/core/eval.js +666 -0
- package/dist/lib/core/func.d.ts +68 -0
- package/dist/lib/core/func.js +129 -0
- package/dist/lib/core/hash.d.ts +5 -0
- package/dist/lib/core/hash.js +155 -0
- package/dist/lib/core/index.d.ts +18 -0
- package/dist/lib/core/index.js +20 -0
- package/dist/lib/core/int64.d.ts +22 -0
- package/dist/lib/core/int64.js +113 -0
- package/dist/lib/core/kinds.d.ts +67 -0
- package/dist/lib/core/kinds.js +134 -0
- package/dist/lib/core/lexer.d.ts +13 -0
- package/dist/lib/core/lexer.js +702 -0
- package/dist/lib/core/mezz.d.ts +1 -0
- package/dist/lib/core/mezz.js +360 -0
- package/dist/lib/core/mold.d.ts +20 -0
- package/dist/lib/core/mold.js +434 -0
- package/dist/lib/core/natives/control.d.ts +1 -0
- package/dist/lib/core/natives/control.js +374 -0
- package/dist/lib/core/natives/csv.d.ts +15 -0
- package/dist/lib/core/natives/csv.js +315 -0
- package/dist/lib/core/natives/data.d.ts +11 -0
- package/dist/lib/core/natives/data.js +367 -0
- package/dist/lib/core/natives/define.d.ts +17 -0
- package/dist/lib/core/natives/define.js +47 -0
- package/dist/lib/core/natives/encode.d.ts +3 -0
- package/dist/lib/core/natives/encode.js +187 -0
- package/dist/lib/core/natives/json.d.ts +5 -0
- package/dist/lib/core/natives/json.js +273 -0
- package/dist/lib/core/natives/math.d.ts +3 -0
- package/dist/lib/core/natives/math.js +500 -0
- package/dist/lib/core/natives/parse.d.ts +1 -0
- package/dist/lib/core/natives/parse.js +600 -0
- package/dist/lib/core/natives/series.d.ts +4 -0
- package/dist/lib/core/natives/series.js +519 -0
- package/dist/lib/core/natives/text.d.ts +1 -0
- package/dist/lib/core/natives/text.js +487 -0
- package/dist/lib/core/natives/xml.d.ts +9 -0
- package/dist/lib/core/natives/xml.js +242 -0
- package/dist/lib/core/series.d.ts +26 -0
- package/dist/lib/core/series.js +73 -0
- package/dist/lib/core/symbols.d.ts +9 -0
- package/dist/lib/core/symbols.js +44 -0
- package/dist/lib/core/values.d.ts +206 -0
- package/dist/lib/core/values.js +223 -0
- package/dist/lib/host/browser.d.ts +4 -0
- package/dist/lib/host/browser.js +4974 -0
- package/dist/lib/host/chart.d.ts +26 -0
- package/dist/lib/host/chart.js +158 -0
- package/dist/lib/host/compress.d.ts +1 -0
- package/dist/lib/host/compress.js +37 -0
- package/dist/lib/host/devlog.d.ts +11 -0
- package/dist/lib/host/devlog.js +13 -0
- package/dist/lib/host/devtools.d.ts +23 -0
- package/dist/lib/host/devtools.js +626 -0
- package/dist/lib/host/draw.d.ts +31 -0
- package/dist/lib/host/draw.js +348 -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 +29 -0
- package/dist/lib/host/icons.d.ts +3 -0
- package/dist/lib/host/icons.js +97 -0
- package/dist/lib/host/index.d.ts +40 -0
- package/dist/lib/host/index.js +192 -0
- package/dist/lib/host/js.d.ts +5 -0
- package/dist/lib/host/js.js +130 -0
- package/dist/lib/host/locale.d.ts +40 -0
- package/dist/lib/host/locale.js +241 -0
- package/dist/lib/host/markdown.d.ts +30 -0
- package/dist/lib/host/markdown.js +161 -0
- package/dist/lib/host/modules.d.ts +14 -0
- package/dist/lib/host/modules.js +300 -0
- package/dist/lib/host/natives.d.ts +6 -0
- package/dist/lib/host/natives.js +98 -0
- package/dist/lib/host/net.d.ts +12 -0
- package/dist/lib/host/net.js +549 -0
- package/dist/lib/host/orbit.d.ts +121 -0
- package/dist/lib/host/orbit.js +374 -0
- package/dist/lib/host/page.d.ts +9 -0
- package/dist/lib/host/page.js +55 -0
- package/dist/lib/host/rows.d.ts +29 -0
- package/dist/lib/host/rows.js +109 -0
- package/dist/lib/host/scheduler.d.ts +51 -0
- package/dist/lib/host/scheduler.js +197 -0
- package/dist/lib/host/theme.d.ts +58 -0
- package/dist/lib/host/theme.js +1667 -0
- package/dist/lib/ui/i18n.trb +117 -0
- package/dist/lib/ui/test.trb +565 -0
- package/dist/lib/ui/ui.trb +1678 -0
- package/dist/trebol.js +1427 -138
- 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 +23 -7
- package/src/core/boot.ts +1 -1
- package/src/core/func.ts +4 -0
- package/src/core/natives/control.ts +1 -1
- package/src/core/natives/series.ts +9 -1
- package/src/core/natives/text.ts +2 -0
- package/src/host/browser.ts +1235 -83
- package/src/host/devlog.ts +16 -0
- package/src/host/devtools.ts +641 -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 +39 -0
- package/src/host/index.ts +5 -3
- package/src/host/js.ts +127 -0
- package/src/host/markdown.ts +9 -0
- package/src/host/modules.ts +41 -2
- package/src/host/net.ts +9 -1
- package/src/host/orbit.ts +432 -0
- package/src/host/rows.ts +30 -0
- package/src/host/scheduler.ts +62 -36
- package/src/host/theme.ts +270 -6
- package/src/ui/i18n.trb +10 -0
- package/src/ui/test.trb +565 -0
- package/src/ui/ui.trb +564 -90
package/src/ui/ui.trb
CHANGED
|
@@ -2,8 +2,8 @@ Trebol [
|
|
|
2
2
|
title: "UI dialect: faces, styles, layout and validation"
|
|
3
3
|
exports: [
|
|
4
4
|
face styles stylize layout view theme looks open close toast confirm print-page
|
|
5
|
-
validate-face field-error form-values set-values ui-pane ui-input ui-files ui-remove-file ui-lookup-search ui-lookup-pick ui-lookup-remove ui-blur ui-click ui-select ui-sort ui-close ui-event ui-menu ui-drop ui-reorder ui-crumb ui-expand
|
|
6
|
-
go go-back go-forward can-go-back? can-go-forward? ui-route set-language ui-rows
|
|
5
|
+
validate-face field-error form-values set-values insert-text ui-pane ui-input ui-files ui-remove-file ui-lookup-search ui-lookup-pick ui-lookup-remove ui-blur ui-click ui-select ui-sort ui-close ui-event ui-menu ui-drop ui-reorder ui-crumb ui-expand ui-orbit
|
|
6
|
+
go go-back go-forward can-go-back? can-go-forward? unsaved unsaved? ui-route set-language ui-rows ui-check ui-react
|
|
7
7
|
]
|
|
8
8
|
]
|
|
9
9
|
|
|
@@ -36,6 +36,14 @@ face: make object! [
|
|
|
36
36
|
readonly: false ; shown and sent, but the user cannot change it, and no rule applies
|
|
37
37
|
inert: false ; shown as it is, but neither it nor its children can be used
|
|
38
38
|
linked: false ; a tile that stands for something kept elsewhere: marked with an arrow
|
|
39
|
+
round: false ; an image: cut to a circle, as for a person's photo
|
|
40
|
+
tag: none ; a widget: the name of the element it is, as the page's JavaScript defines it
|
|
41
|
+
props: none ; a widget: the element's properties, an object
|
|
42
|
+
poster: none ; a video: the image shown before it plays
|
|
43
|
+
captions: none ; a video: its captions, a .vtt file, or a block of one per language [en %a.vtt es %b.vtt]
|
|
44
|
+
looping: false ; a video or a sound starts again when it ends (loop in the dialect)
|
|
45
|
+
silent: false ; a video or a sound plays without its sound (muted in the dialect)
|
|
46
|
+
autoplay: false ; a video or a sound plays on its own, always silent, as browsers allow
|
|
39
47
|
drag: false ; can be dragged: carries its value, or the row in a table, list or tree
|
|
40
48
|
drop: false ; accepts drops (on-drop)
|
|
41
49
|
reorder: false ; its children or rows can be moved around (on-reorder)
|
|
@@ -43,7 +51,7 @@ face: make object! [
|
|
|
43
51
|
error: none ; current message, shown once the face is touched
|
|
44
52
|
touched: false
|
|
45
53
|
pending: false ; an asynchronous check is running
|
|
46
|
-
sent: none ; an upload: how far its files went up, 0-1; none hides the bar
|
|
54
|
+
sent: none ; an upload or photo: how far its files went up, 0-1; none hides the bar
|
|
47
55
|
async-error: none ; result of the last asynchronous check
|
|
48
56
|
action: none ; the block after the face: click, change
|
|
49
57
|
events: none ; [on-change [...] on-select [...]]
|
|
@@ -54,18 +62,18 @@ face: make object! [
|
|
|
54
62
|
links: none ; a lookup: the screen each value links to when readonly, a map
|
|
55
63
|
query: none ; a lookup: the text last searched for
|
|
56
64
|
currency: none ; a money field's currency code: EUR
|
|
57
|
-
|
|
65
|
+
reactions: none ; react, is and calc: a block of reaction objects
|
|
58
66
|
template: none ; rows: the block of the fields of one row
|
|
59
67
|
built: none ; rows: what its rows were last made from
|
|
60
68
|
owner: none ; a row of rows: the rows face it belongs to
|
|
61
69
|
typed: none ; what the user typed in a number, money or date field when it is not one;
|
|
62
|
-
; in an upload, the names of the files it refused
|
|
70
|
+
; in an upload or photo, the names of the files it refused
|
|
63
71
|
multiple: false ; an upload or a lookup takes more than one
|
|
64
|
-
accept: none ; the files an upload takes: ["pdf" "image/*"]
|
|
72
|
+
accept: none ; the files an upload takes: ["pdf" "image/*"]; a photo, images unless told
|
|
65
73
|
pane: none
|
|
66
|
-
columns: none ; table, list and tree: [field "Label" ...]
|
|
74
|
+
columns: none ; table, list and tree: [field "Label" ...]; a column of images, [field ["Label" image round]]
|
|
67
75
|
data: none ; table, list and tree: a block of map! or object! rows (a tree's
|
|
68
|
-
; have their own in `children`); breadcrumb: its items
|
|
76
|
+
; have their own in `children`); breadcrumb: its items; orbit: its focus, nodes, edges and trail
|
|
69
77
|
key: 'id ; the row field that identifies a row
|
|
70
78
|
selected: none ; the row last chosen
|
|
71
79
|
sortable: false ; a table the host sorts, from the rows it has, when a header is chosen
|
|
@@ -77,6 +85,7 @@ face: make object! [
|
|
|
77
85
|
extent: none ; a canvas: the size of its drawing space, a pair
|
|
78
86
|
form: none ; the enclosing form, if any
|
|
79
87
|
root: none ; the view this face belongs to
|
|
88
|
+
place: none ; where the face was written, file:line:col; none if made at run time
|
|
80
89
|
submit: false
|
|
81
90
|
]
|
|
82
91
|
|
|
@@ -84,17 +93,18 @@ face: make object! [
|
|
|
84
93
|
styles: make map! []
|
|
85
94
|
|
|
86
95
|
container-styles: [view column row form panel grid dialog scroll split toolbar desktop]
|
|
87
|
-
input-styles: [field password number money date area rich check toggle choice radio upload lookup rows]
|
|
96
|
+
input-styles: [field password number money date area rich check toggle choice radio upload photo lookup rows widget]
|
|
88
97
|
data-styles: [table list tree chart]
|
|
89
98
|
|
|
90
99
|
foreach [name base] [
|
|
91
100
|
view column column column row row form form panel panel grid grid scroll scroll desktop desktop
|
|
92
101
|
title title heading heading text text divider divider
|
|
93
102
|
field field password password number number money money date date area area rich rich check check choice choice
|
|
94
|
-
toggle toggle radio radio upload upload lookup lookup progress progress image image icon icon
|
|
103
|
+
toggle toggle radio radio upload upload photo photo lookup lookup progress progress image image backdrop backdrop icon icon
|
|
104
|
+
video video audio audio widget widget
|
|
95
105
|
button button link link tile tile table table list list tabs tabs tab tab
|
|
96
106
|
toolbar toolbar breadcrumb breadcrumb tree tree screens screens screen screen rows rows entry entry
|
|
97
|
-
canvas canvas chart chart
|
|
107
|
+
canvas canvas chart chart orbit orbit
|
|
98
108
|
] [
|
|
99
109
|
poke styles name make face [style: base]
|
|
100
110
|
]
|
|
@@ -114,7 +124,7 @@ stylize: function [
|
|
|
114
124
|
parse spec [some [
|
|
115
125
|
set name set-word! set base word! set defaults block! (
|
|
116
126
|
proto: select styles base
|
|
117
|
-
unless proto [do make error! rejoin ["stylize: unknown style " base]]
|
|
127
|
+
unless proto [do make error! rejoin ["stylize: unknown style " base ui-suggest base words-of styles]]
|
|
118
128
|
poke styles to word! name make proto defaults
|
|
119
129
|
)
|
|
120
130
|
]]
|
|
@@ -126,11 +136,13 @@ roles: [primary accent danger success warning muted]
|
|
|
126
136
|
sizes: [small medium large]
|
|
127
137
|
aligns: [left center right spread]
|
|
128
138
|
valigns: [top middle bottom]
|
|
129
|
-
flags: [fill fit hidden disabled readonly inert narrow-only wide-only linked drag drop reorder multiple sortable stacked]
|
|
139
|
+
flags: [fill fit hidden disabled readonly inert narrow-only wide-only linked round drag drop reorder multiple sortable stacked]
|
|
130
140
|
chart-kinds: [bar line area pie]
|
|
131
141
|
simple-rules: [required email url integer]
|
|
132
142
|
letter: charset [#"a" - #"z" #"A" - #"Z"]
|
|
133
|
-
rule-words: [min max length pattern match check check-async calc width pad gap menu accept known links sorted]
|
|
143
|
+
rule-words: [min max length pattern match check check-async calc react is width pad gap menu accept known links sorted poster captions]
|
|
144
|
+
media-styles: [video audio]
|
|
145
|
+
media-flags: [loop muted autoplay] ; of a video or a sound
|
|
134
146
|
|
|
135
147
|
; Words that never name a field. email, url and integer are rules too,
|
|
136
148
|
; but also common field names, so the first word after an input style names it.
|
|
@@ -150,6 +162,189 @@ event-word?: func [w [word!]] [
|
|
|
150
162
|
to logic! find/match form w "on-"
|
|
151
163
|
]
|
|
152
164
|
|
|
165
|
+
; --- problems in a layout -------------------------------------------------------
|
|
166
|
+
;
|
|
167
|
+
; layout reads the whole block and makes one error of every problem it finds,
|
|
168
|
+
; each with the place it was loaded from (loaded-at) and a word it may mean.
|
|
169
|
+
|
|
170
|
+
; [place message ...] while a block is laid out; none otherwise, and then a problem is an error at once.
|
|
171
|
+
ui-problems: none
|
|
172
|
+
|
|
173
|
+
ui-problem: func [place [block!] message [string!]] [
|
|
174
|
+
either ui-problems [append ui-problems reduce [place message]] [ui-fail reduce [place message]]
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
; The faces of a block, as build-faces gives them, or an error with every problem in it.
|
|
178
|
+
ui-build: function [spec [block!] labels [block!]] [
|
|
179
|
+
outer: ui-problems
|
|
180
|
+
set 'ui-problems copy []
|
|
181
|
+
out: try [build-faces spec labels]
|
|
182
|
+
found: ui-problems
|
|
183
|
+
set 'ui-problems outer
|
|
184
|
+
if error? out [do out]
|
|
185
|
+
unless empty? found [either ui-checking [append ui-checking found] [ui-fail found]]
|
|
186
|
+
out
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
; While ui-check runs: the problems of every block, and no code of the program is run.
|
|
190
|
+
ui-checking: none
|
|
191
|
+
|
|
192
|
+
; It lays out each block after view or layout (styles of stylize first), and the
|
|
193
|
+
; faces of each screen and row of rows, which a running app lays out only when shown.
|
|
194
|
+
ui-check: function [
|
|
195
|
+
"Every problem in the layouts of a program, without running it: [place message ...]"
|
|
196
|
+
code [block!]
|
|
197
|
+
/local b p
|
|
198
|
+
] [
|
|
199
|
+
set 'ui-checking copy []
|
|
200
|
+
blocks: copy []
|
|
201
|
+
; the blocks after view, layout and stylize, in code and in the blocks inside it
|
|
202
|
+
walk: function [code] [
|
|
203
|
+
parse code [any [
|
|
204
|
+
p: ['view | 'layout | 'stylize | path! if (find [view layout] first first p)]
|
|
205
|
+
; view compose [...]: its parens stand for values check cannot know
|
|
206
|
+
opt ['compose | path! if ('compose = first first next p)]
|
|
207
|
+
set b block! (
|
|
208
|
+
append/only blocks reduce [first p b]
|
|
209
|
+
walk b
|
|
210
|
+
)
|
|
211
|
+
| set b [block! | paren!] (walk b)
|
|
212
|
+
| skip
|
|
213
|
+
]]
|
|
214
|
+
]
|
|
215
|
+
walk code
|
|
216
|
+
attempt-at: func [place body] [
|
|
217
|
+
if error? r: try body [append ui-checking reduce [place form r/message]]
|
|
218
|
+
]
|
|
219
|
+
foreach p blocks [if 'stylize = first p [attempt-at next p [stylize copy/deep second p]]]
|
|
220
|
+
foreach p blocks [
|
|
221
|
+
unless 'stylize = first p [
|
|
222
|
+
attempt-at next p [
|
|
223
|
+
faces: all-faces layout second p
|
|
224
|
+
; screens and rows lay these out when shown
|
|
225
|
+
while [not empty? faces] [
|
|
226
|
+
f: take faces
|
|
227
|
+
later: copy []
|
|
228
|
+
if f/style = 'screens [foreach [n t a b] f/data [append/only later b]]
|
|
229
|
+
if all [f/style = 'rows f/template] [append/only later f/template]
|
|
230
|
+
foreach b later [
|
|
231
|
+
spec: copy/deep b
|
|
232
|
+
parse spec [any [set w word! if (event-word? w) block!] body:]
|
|
233
|
+
foreach g ui-build body copy [] [append faces all-faces g]
|
|
234
|
+
]
|
|
235
|
+
]
|
|
236
|
+
]
|
|
237
|
+
]
|
|
238
|
+
]
|
|
239
|
+
; a screen or rows laid out twice (rows with min) gives its problems twice
|
|
240
|
+
found: copy []
|
|
241
|
+
seen: copy []
|
|
242
|
+
foreach [p m] ui-checking [
|
|
243
|
+
k: rejoin [any [loaded-at p ""] " " m]
|
|
244
|
+
unless find seen k [append seen k append found reduce [p m]]
|
|
245
|
+
]
|
|
246
|
+
set 'ui-checking none
|
|
247
|
+
found
|
|
248
|
+
]
|
|
249
|
+
|
|
250
|
+
ui-fail: function [found [block!] /local place m] [
|
|
251
|
+
either 2 = length? found [
|
|
252
|
+
message: rejoin ["layout: " second found]
|
|
253
|
+
] [
|
|
254
|
+
places: collect [foreach [place m] found [keep any [loaded-at place ""]]]
|
|
255
|
+
wide: 0
|
|
256
|
+
foreach p places [wide: max wide length? p]
|
|
257
|
+
message: rejoin ["layout: " (length? found) / 2 " problems"]
|
|
258
|
+
i: 0
|
|
259
|
+
foreach [place m] found [
|
|
260
|
+
p: pick places i: i + 1
|
|
261
|
+
append message rejoin ["^/ " p append/dup copy "" #" " wide + 1 - length? p m]
|
|
262
|
+
]
|
|
263
|
+
]
|
|
264
|
+
e: make error! message
|
|
265
|
+
; the first values from the place, one after another as near shows them
|
|
266
|
+
e/near: copy []
|
|
267
|
+
foreach v copy/part first found 3 [append/only e/near :v]
|
|
268
|
+
e/at: loaded-at first found
|
|
269
|
+
do e
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
; What a rule word takes, for a problem when what follows it is something else.
|
|
273
|
+
ui-takes: [
|
|
274
|
+
min "a number, an amount or a date" max "a number, an amount or a date" length "two integers"
|
|
275
|
+
pattern "a block" check "a block" check-async "a block" calc "a block" react "a block, after later or not" is "a block" accept "a block"
|
|
276
|
+
menu "a block" sorted "a block" known "a map" links "a map" match "the name of a field"
|
|
277
|
+
poster "a file or a url" captions "a file, a url or a block" width "small, medium, large or fill"
|
|
278
|
+
pad "a step from 0 to 7, none or wide" gap "a step from 0 to 7, none or wide" key "a text or a word"
|
|
279
|
+
]
|
|
280
|
+
|
|
281
|
+
; Every word the dialect knows, for ui-suggest.
|
|
282
|
+
ui-dialect-words: does [
|
|
283
|
+
unique compose [
|
|
284
|
+
(words-of styles) (roles) (sizes) (aligns) (valigns) (flags) (chart-kinds) (simple-rules)
|
|
285
|
+
(rule-words) (media-flags) required global key
|
|
286
|
+
]
|
|
287
|
+
]
|
|
288
|
+
|
|
289
|
+
; The word near enough to w to be what it meant (buton: button), or none.
|
|
290
|
+
ui-nearest: function [w [word!] words [block!]] [
|
|
291
|
+
t: form w
|
|
292
|
+
most: either 4 < length? t [2] [1]
|
|
293
|
+
best: none
|
|
294
|
+
foreach c words [
|
|
295
|
+
d: ui-distance t form c
|
|
296
|
+
if all [d > 0 d <= most] [best: c most: d - 1]
|
|
297
|
+
]
|
|
298
|
+
best
|
|
299
|
+
]
|
|
300
|
+
|
|
301
|
+
; "; did you mean button?" for buton, when one of the words is near enough; "" otherwise.
|
|
302
|
+
ui-suggest: function [w [word!] words [block!]] [
|
|
303
|
+
either best: ui-nearest w words [rejoin ["; did you mean " best "?"]] [""]
|
|
304
|
+
]
|
|
305
|
+
|
|
306
|
+
; Optimal string alignment distance: letters put in, taken out, changed, or two neighbours swapped.
|
|
307
|
+
ui-distance: function [a [string!] b [string!]] [
|
|
308
|
+
n: length? b
|
|
309
|
+
before: none
|
|
310
|
+
prev: copy []
|
|
311
|
+
repeat j n + 1 [append prev j - 1]
|
|
312
|
+
repeat i length? a [
|
|
313
|
+
row: reduce [i]
|
|
314
|
+
repeat j n [
|
|
315
|
+
d: min min (pick prev j + 1) + 1 (last row) + 1 (pick prev j) + either (pick a i) = (pick b j) [0] [1]
|
|
316
|
+
if all [i > 1 j > 1 (pick a i) = (pick b j - 1) (pick a i - 1) = (pick b j)] [
|
|
317
|
+
d: min d (pick before j - 1) + 1
|
|
318
|
+
]
|
|
319
|
+
append row d
|
|
320
|
+
]
|
|
321
|
+
before: prev
|
|
322
|
+
prev: row
|
|
323
|
+
]
|
|
324
|
+
last prev
|
|
325
|
+
]
|
|
326
|
+
|
|
327
|
+
; A value as a problem shows it: its mold, cut when long.
|
|
328
|
+
ui-shown: function [v] [
|
|
329
|
+
t: mold :v
|
|
330
|
+
either 30 < length? t [append copy/part t 27 "..."] [t]
|
|
331
|
+
]
|
|
332
|
+
|
|
333
|
+
; The style a word after a face means when it is a mistyped one (feild: field), or none.
|
|
334
|
+
ui-meant-style: function [v] [
|
|
335
|
+
all [word? :v s: ui-nearest v ui-dialect-words select styles s s]
|
|
336
|
+
]
|
|
337
|
+
|
|
338
|
+
; The problem with a value that follows a face and means nothing to it.
|
|
339
|
+
ui-stray: function [f v] [
|
|
340
|
+
case [
|
|
341
|
+
all [word? :v t: select ui-takes v] [rejoin [v " takes " t]]
|
|
342
|
+
s: ui-meant-style :v [rejoin [v " is not a style; did you mean " s "?"]]
|
|
343
|
+
word? :v [rejoin [v " is not a word of " f/style ui-suggest v ui-dialect-words]]
|
|
344
|
+
true [rejoin [f/style " does not take " ui-shown :v]]
|
|
345
|
+
]
|
|
346
|
+
]
|
|
347
|
+
|
|
153
348
|
; Labels (`search: field`, `table clients`) are local to the layout, as R3
|
|
154
349
|
; planned for its VID: each layout gets an object holding them, and the
|
|
155
350
|
; layout's blocks (its handlers too) are bound to it. `global search: field`
|
|
@@ -165,7 +360,7 @@ layout: function [
|
|
|
165
360
|
spec: copy/deep spec
|
|
166
361
|
labels: copy []
|
|
167
362
|
either only [
|
|
168
|
-
out: build
|
|
363
|
+
out: ui-build spec labels
|
|
169
364
|
] [
|
|
170
365
|
; on-xxx handlers and its width before the first face belong to the view itself
|
|
171
366
|
events: copy []
|
|
@@ -174,7 +369,7 @@ layout: function [
|
|
|
174
369
|
set ev word! if (event-word? ev) set b block! (append events reduce [ev b])
|
|
175
370
|
| 'width set w ['small | 'medium | 'large | 'fill] (width: w)
|
|
176
371
|
] body:]
|
|
177
|
-
out: make select styles 'view [pane: build
|
|
372
|
+
out: make select styles 'view [pane: ui-build body labels]
|
|
178
373
|
unless empty? events [out/events: events]
|
|
179
374
|
out/size: width
|
|
180
375
|
]
|
|
@@ -205,18 +400,22 @@ text-of: func [t] [either lit-word? :t [to word! t] [t]]
|
|
|
205
400
|
; The faces of a block of the dialect; labels collects [word face ...].
|
|
206
401
|
build-faces: function [
|
|
207
402
|
spec [block!] labels [block!]
|
|
208
|
-
/local label global? style-word f proto n s b w a i v ev p
|
|
403
|
+
/local label global? style-word f proto n s b w a i v ev p pos later
|
|
209
404
|
] [
|
|
210
405
|
out: copy []
|
|
406
|
+
; what starts the next face
|
|
407
|
+
face-start: [set-word! | 'global | set w word! if (select styles w)]
|
|
211
408
|
modifier: [
|
|
212
|
-
|
|
409
|
+
; ui-check reads view compose [...] with its parens in it: menu (looks)
|
|
410
|
+
if (ui-checking) opt [set w word! if (select ui-takes w)] some paren!
|
|
411
|
+
| set s [string! | map!] (either f/text [f/hint: s] [f/text: s])
|
|
213
412
|
; a word of the dictionary: button 'save (in a link, a lit-word is the screen)
|
|
214
413
|
| if (f/style <> 'link) set v lit-word! (v: to word! v either f/text [f/hint: v] [f/text: v])
|
|
215
414
|
| set ev word! if (event-word? ev) set b block! (
|
|
216
415
|
unless f/events [f/events: copy []]
|
|
217
416
|
append f/events reduce [ev b]
|
|
218
417
|
)
|
|
219
|
-
| set b block! (
|
|
418
|
+
| pos: set b block! (
|
|
220
419
|
case [
|
|
221
420
|
; grid [1 4 1] [...]: the weight of each column, then the children
|
|
222
421
|
all [f/style = 'grid none? f/pane not empty? b parse b [some integer!]] [f/cols: b]
|
|
@@ -226,16 +425,20 @@ build-faces: function [
|
|
|
226
425
|
; --- in a toolbar is a separator
|
|
227
426
|
f/pane: build-faces either f/style = 'toolbar [replace/all copy b '--- 'divider] [b] labels
|
|
228
427
|
if all [f/style = 'split 2 <> length? f/pane] [
|
|
229
|
-
|
|
428
|
+
ui-problem pos "split takes two faces, one per pane"
|
|
230
429
|
]
|
|
231
430
|
]
|
|
232
431
|
find data-styles f/style [f/columns: columns-of b]
|
|
233
432
|
; the first block holds the items, the second is the action
|
|
234
433
|
all [f/style = 'breadcrumb none? f/data] [f/data: crumbs-of b]
|
|
434
|
+
; orbit [focus ... nodes [...]]: what it shows; a second block is the action
|
|
435
|
+
all [f/style = 'orbit none? f/data] [f/data: orbit-of b]
|
|
436
|
+
; widget <geo-map> [zoom: 12]: its properties; a second block is the action
|
|
437
|
+
all [f/style = 'widget none? f/props] [f/props: either ui-checking [make object! []] [make object! b]]
|
|
235
438
|
f/style = 'canvas [f/draw: b]
|
|
236
439
|
f/style = 'tabs [f/pane: tabs-of b labels]
|
|
237
440
|
f/style = 'screens [f/data: screens-of b]
|
|
238
|
-
find [choice radio] f/style [f/options: options-of b]
|
|
441
|
+
all [find [choice radio] f/style none? f/options] [f/options: options-of b]
|
|
239
442
|
true [f/action: b]
|
|
240
443
|
]
|
|
241
444
|
)
|
|
@@ -252,14 +455,22 @@ build-faces: function [
|
|
|
252
455
|
| 'length set a integer! set n integer! (add-rule f reduce ['length a n])
|
|
253
456
|
| 'pattern set b block! (add-rule f reduce ['pattern b])
|
|
254
457
|
| 'accept set b block! (f/accept: b)
|
|
458
|
+
| 'poster set v [file! | url!] (f/poster: v)
|
|
459
|
+
| 'captions set v [file! | url! | block!] (f/captions: v)
|
|
460
|
+
; muted names a role elsewhere, and loop a function, so a video keeps them in fields of its own
|
|
461
|
+
| set w word! if (all [find media-flags w find media-styles f/style]) (
|
|
462
|
+
poke f select [muted silent loop looping autoplay autoplay] w true
|
|
463
|
+
)
|
|
255
464
|
| 'known set v map! (f/known: v)
|
|
256
465
|
| 'links set v map! (f/links: v)
|
|
257
466
|
| 'match set w word! (add-rule f reduce ['match w])
|
|
258
467
|
| 'check set b block! (add-rule f reduce ['check b])
|
|
259
468
|
| 'check-async set b block! (add-rule f reduce ['check-async b])
|
|
260
|
-
| 'calc set b block! (f
|
|
469
|
+
| 'calc set b block! (add-reaction f 'calc b false f/readonly: true)
|
|
470
|
+
| 'is set b block! (add-reaction f 'is b false)
|
|
471
|
+
| 'react (later: false) opt ['later (later: true)] set b block! (add-reaction f 'react b later)
|
|
261
472
|
| 'width set w word! (f/size: w)
|
|
262
|
-
| set w ['pad | 'gap] [set n integer! | 'none (n: 0) | 'wide (n: 6)] (poke f w spacing n)
|
|
473
|
+
| pos: set w ['pad | 'gap] [set n integer! | 'none (n: 0) | 'wide (n: 6)] (poke f w spacing n pos)
|
|
263
474
|
| 'menu set b block! (f/menu: menu-of b)
|
|
264
475
|
| 'key set s string! (f/shortcut: s)
|
|
265
476
|
| 'key set w word! (f/key: w)
|
|
@@ -273,77 +484,101 @@ build-faces: function [
|
|
|
273
484
|
; money price "Price" EUR
|
|
274
485
|
| set w word! if (all [f/style = 'money parse form w [3 letter]]) (f/currency: to word! uppercase form w)
|
|
275
486
|
]
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
487
|
+
parse spec [any [
|
|
488
|
+
(label: none global?: false)
|
|
489
|
+
opt ['global (global?: true)]
|
|
490
|
+
opt [set label set-word!]
|
|
491
|
+
[
|
|
492
|
+
; a face that compose puts in: check takes what follows as words of a face it cannot know
|
|
493
|
+
if (ui-checking) paren! (f: make face []) any modifier
|
|
494
|
+
| pos: set style-word word! if (proto: select styles style-word) (
|
|
284
495
|
f: make proto []
|
|
496
|
+
f/place: loaded-at pos
|
|
285
497
|
append out f
|
|
286
498
|
if label [label-face label labels global? f]
|
|
287
499
|
)
|
|
500
|
+
; widget <geo-map> place "Place": the element comes before the name
|
|
501
|
+
opt [if (f/style = 'widget) set v tag! (f/tag: to string! v)]
|
|
288
502
|
opt [if (find input-styles f/style) set n word! if (field-name? n) (f/name: n)]
|
|
289
503
|
; chart bar income [...]: the kind comes before the label
|
|
290
504
|
opt [if (f/style = 'chart) set n word! if (find chart-kinds n) (f/kind: n)]
|
|
291
505
|
; table clients [...] is the same as clients: table [...]
|
|
292
|
-
opt [if (find data-styles f/style) set n word! if (all [field-name? n n <> 'key]) (label-face n labels global? f)]
|
|
293
|
-
any
|
|
506
|
+
opt [if (any [find data-styles f/style f/style = 'orbit]) set n word! if (all [field-name? n n <> 'key]) (label-face n labels global? f)]
|
|
507
|
+
any [
|
|
508
|
+
modifier
|
|
509
|
+
; a mistyped style starts a face of its own: what follows it is that face's
|
|
510
|
+
| pos: not face-start skip (ui-problem pos ui-stray f first pos) opt [
|
|
511
|
+
if (ui-meant-style first pos) any [not face-start skip]
|
|
512
|
+
]
|
|
513
|
+
]
|
|
294
514
|
(if f/style = 'rows [rows-fill f])
|
|
515
|
+
; not a style: a problem, then on to the next face
|
|
516
|
+
| pos: skip (
|
|
517
|
+
w: first pos
|
|
518
|
+
ui-problem pos case [
|
|
519
|
+
not word? :w [rejoin ["a face starts with a style, not " ui-shown :w]]
|
|
520
|
+
find ui-dialect-words w [rejoin [w " is not a style; it goes after one"]]
|
|
521
|
+
true [rejoin [w " is not a style" ui-suggest w words-of styles]]
|
|
522
|
+
]
|
|
523
|
+
) any [not face-start skip]
|
|
295
524
|
]
|
|
296
|
-
]
|
|
297
|
-
do make error! "layout: cannot read the layout"
|
|
298
|
-
]
|
|
525
|
+
]]
|
|
299
526
|
out
|
|
300
527
|
]
|
|
301
528
|
|
|
302
|
-
spacing: func [n [integer!]] [
|
|
303
|
-
|
|
304
|
-
|
|
529
|
+
spacing: func [n [integer!] place [block!]] [
|
|
530
|
+
if all [n >= 0 n <= 7] [return n]
|
|
531
|
+
ui-problem place rejoin [first place " takes a step from 0 to 7"]
|
|
532
|
+
0
|
|
305
533
|
]
|
|
306
534
|
|
|
307
535
|
; [name "Name" email] -> [name "Name" email "email"]
|
|
308
|
-
|
|
536
|
+
; A column of images keeps what it is with its label: [photo "" image round] -> [photo ["" image round]]
|
|
537
|
+
columns-of: function [spec [block!] /local w label kind p] [
|
|
309
538
|
out: copy []
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
539
|
+
parse spec [any [
|
|
540
|
+
set w word! (label: form w kind: none) opt [set label text-rule]
|
|
541
|
+
opt ['image (kind: copy [image]) opt ['round (append kind 'round)]]
|
|
542
|
+
(
|
|
543
|
+
label: text-of label
|
|
544
|
+
append out w
|
|
545
|
+
append/only out either kind [head insert/only kind label] [label]
|
|
546
|
+
)
|
|
547
|
+
| p: skip (ui-problem p "table columns are words, each with an optional label, then image or image round") to end
|
|
548
|
+
]]
|
|
313
549
|
out
|
|
314
550
|
]
|
|
315
551
|
|
|
316
552
|
; [name desc] -> [name desc], checked
|
|
317
553
|
sort-order: function [b [block!]] [
|
|
318
|
-
unless parse b [word! ['asc | 'desc]] [
|
|
319
|
-
do make error! "layout: sorted takes a column and asc or desc"
|
|
320
|
-
]
|
|
554
|
+
unless parse b [word! ['asc | 'desc]] [ui-problem b "sorted takes a column and asc or desc"]
|
|
321
555
|
copy b
|
|
322
556
|
]
|
|
323
557
|
|
|
324
558
|
; ["General" [...] "Advanced" [...]] -> a tab face per pair
|
|
325
|
-
tabs-of: function [spec [block!] labels [block!]] [
|
|
559
|
+
tabs-of: function [spec [block!] labels [block!] /local p] [
|
|
326
560
|
out: copy []
|
|
327
|
-
|
|
328
|
-
label
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
561
|
+
parse spec [any [
|
|
562
|
+
set label text-rule set b block! (
|
|
563
|
+
label: text-of label
|
|
564
|
+
append out make select styles 'tab [text: label pane: build-faces b labels]
|
|
565
|
+
)
|
|
566
|
+
| p: skip (ui-problem p "tabs take a label and a block per tab") to end
|
|
567
|
+
]]
|
|
333
568
|
out
|
|
334
569
|
]
|
|
335
570
|
|
|
336
571
|
; [home "Home" [...] client "Client" [id] [...]] -> [name title args body ...]
|
|
337
|
-
screens-of: function [spec [block!] /local n t a b] [
|
|
572
|
+
screens-of: function [spec [block!] /local n t a b p] [
|
|
338
573
|
out: copy []
|
|
339
|
-
|
|
574
|
+
if empty? spec [ui-problem spec "screens take a name, a title, an optional block of arguments and a block per screen"]
|
|
575
|
+
parse spec [any [
|
|
340
576
|
set n word! set t text-rule (a: copy []) opt [ahead [block! block!] set a block!] set b block! (
|
|
341
|
-
|
|
342
|
-
append out reduce [n text-of t a b]
|
|
577
|
+
forall a [unless word? first a [ui-problem a "the arguments of a screen are words"]]
|
|
578
|
+
append out reduce [n text-of t head a b]
|
|
343
579
|
)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
]
|
|
580
|
+
| p: skip (ui-problem p "screens take a name, a title, an optional block of arguments and a block per screen") to end
|
|
581
|
+
]]
|
|
347
582
|
out
|
|
348
583
|
]
|
|
349
584
|
|
|
@@ -356,24 +591,46 @@ menu-item: make object! [
|
|
|
356
591
|
]
|
|
357
592
|
|
|
358
593
|
; As in Red: ["Edit" edit #trash "Delete" delete --- "Move to" ["Top" top]] -> menu items
|
|
359
|
-
menu-of: function [spec [block!] /local i label w b] [
|
|
594
|
+
menu-of: function [spec [block!] /local i label w b p] [
|
|
360
595
|
out: copy []
|
|
361
|
-
|
|
596
|
+
parse spec [any [
|
|
362
597
|
'--- (append out make menu-item [divider: true])
|
|
363
598
|
| (i: none) opt [set i issue!] set label text-rule (label: text-of label) [
|
|
364
599
|
set b block! (append out make menu-item [text: label icon: i items: menu-of b])
|
|
365
600
|
| set w word! (append out make menu-item [text: label icon: i id: w])
|
|
366
601
|
]
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
]
|
|
602
|
+
| p: skip (ui-problem p "a menu takes a label and a word per item, a block for a submenu, or ---") to end
|
|
603
|
+
]]
|
|
370
604
|
out
|
|
371
605
|
]
|
|
372
606
|
|
|
607
|
+
; [focus id nodes [id "Title" [hints] ...] edges [from to "Label" [dashed] ...] trail [id ...]]
|
|
608
|
+
; The host reads the hints (a role or color, many, dashed, count n, steps n at k); this checks the shape.
|
|
609
|
+
orbit-id: [word! | integer! | string! | issue!]
|
|
610
|
+
orbit-of: function [spec [block!] /local b p] [
|
|
611
|
+
parse spec [any [
|
|
612
|
+
'focus orbit-id
|
|
613
|
+
| 'nodes set b block! (parse b [
|
|
614
|
+
any [orbit-id text-rule opt block!]
|
|
615
|
+
[end | p: (ui-problem p "nodes takes an id and a title for each, then a block of hints if it has any")]
|
|
616
|
+
])
|
|
617
|
+
| 'edges set b block! (parse b [
|
|
618
|
+
any [orbit-id orbit-id opt text-rule opt [into ['solid | 'dashed | 'faint]]]
|
|
619
|
+
[end | p: (ui-problem p "edges takes two ids for each, then a label and [solid], [dashed] or [faint] if it has them")]
|
|
620
|
+
])
|
|
621
|
+
| 'trail set b block! (parse b [
|
|
622
|
+
any orbit-id [end | p: (ui-problem p "trail takes the ids of nodes, the most recent last")]
|
|
623
|
+
])
|
|
624
|
+
| p: skip (ui-problem p "an orbit takes focus id, nodes [...], edges [...] and trail [...]") to end
|
|
625
|
+
]]
|
|
626
|
+
copy spec
|
|
627
|
+
]
|
|
628
|
+
|
|
373
629
|
; ["Home" home "Clients" clients "Ada"]: a label and a word per item; the last one may have no word
|
|
374
|
-
crumbs-of: function [spec [block!] /local label w] [
|
|
375
|
-
|
|
376
|
-
|
|
630
|
+
crumbs-of: function [spec [block!] /local label w p] [
|
|
631
|
+
parse spec [
|
|
632
|
+
any [set label [string! | map!] set w [word! | path!]] opt [string! | map!]
|
|
633
|
+
[end | p: (ui-problem p "a breadcrumb takes a label and a word per item; only the last may have no word")]
|
|
377
634
|
]
|
|
378
635
|
copy spec
|
|
379
636
|
]
|
|
@@ -381,6 +638,7 @@ crumbs-of: function [spec [block!] /local label w] [
|
|
|
381
638
|
; The options of a choice or radio: each reduced, and so are those of a group,
|
|
382
639
|
; a title followed by a block: ["Bikes" ["Road" "City"] "Other"].
|
|
383
640
|
options-of: function [spec [block!]] [
|
|
641
|
+
if ui-checking [return copy spec]
|
|
384
642
|
opts: reduce spec
|
|
385
643
|
forall opts [if block? first opts [change/only opts reduce first opts]]
|
|
386
644
|
opts
|
|
@@ -423,6 +681,7 @@ view: function [
|
|
|
423
681
|
; of the screen name and its arguments as strings, as they come in the link.
|
|
424
682
|
|
|
425
683
|
router: none ; the screens face of the page
|
|
684
|
+
marked: false ; the screen on show has changes not saved (unsaved)
|
|
426
685
|
page: none ; the root face of the view on show
|
|
427
686
|
|
|
428
687
|
; The [name title args body] of the screen a route names, or none.
|
|
@@ -443,13 +702,16 @@ enter-screen: function [f route [block!] /local ev b] [
|
|
|
443
702
|
; on-xxx handlers before the first face belong to the screen
|
|
444
703
|
events: copy []
|
|
445
704
|
parse spec [any [set ev word! if (event-word? ev) set b block! (append events reduce [ev b])] body:]
|
|
446
|
-
s: make select styles 'screen [text: def/2 pane: build
|
|
705
|
+
s: make select styles 'screen [text: def/2 pane: ui-build body labels]
|
|
447
706
|
unless empty? events [s/events: events]
|
|
448
707
|
words: copy []
|
|
449
708
|
repeat i length? def/3 [append words reduce [to set-word! pick def/3 i pick route i + 1]]
|
|
450
709
|
bind-labels spec labels words
|
|
451
710
|
f/value: copy route
|
|
452
711
|
f/entering: true
|
|
712
|
+
; a screen starts with nothing to save
|
|
713
|
+
set 'marked false
|
|
714
|
+
set-unsaved false
|
|
453
715
|
f/pane: reduce [s]
|
|
454
716
|
ui-pane f
|
|
455
717
|
s
|
|
@@ -469,6 +731,21 @@ run-enter: function [s] [
|
|
|
469
731
|
if error? :r [do :r]
|
|
470
732
|
]
|
|
471
733
|
|
|
734
|
+
; Whether the screen on show lets the page leave it: its on-leave says, false or
|
|
735
|
+
; 'continue (as Red's on-close) to stay; with no on-leave, a screen with unsaved
|
|
736
|
+
; changes asks the user. Both may wait for a dialog.
|
|
737
|
+
may-leave?: function [/local s h r] [
|
|
738
|
+
unless all [router s: first router/pane] [return true]
|
|
739
|
+
if h: handler-for s 'on-leave [
|
|
740
|
+
r: run-handler s h
|
|
741
|
+
return not any [false = :r 'continue = :r]
|
|
742
|
+
]
|
|
743
|
+
any [
|
|
744
|
+
not marked
|
|
745
|
+
confirm/with/role select i18n/ui 'leave-unsaved reduce [select i18n/ui 'leave select i18n/ui 'stay] 'danger
|
|
746
|
+
]
|
|
747
|
+
]
|
|
748
|
+
|
|
472
749
|
; Shows the screen of a link given as a block of strings; a link that names no
|
|
473
750
|
; screen shows the first one and is replaced by its link.
|
|
474
751
|
follow-link: function [f parts [block!]] [
|
|
@@ -490,6 +767,7 @@ go: function [
|
|
|
490
767
|
if block? target [foreach a reduce next target [append route form a]]
|
|
491
768
|
if path? target [foreach a next to block! target [append route form a]]
|
|
492
769
|
unless find-screen router route [do make error! rejoin ["go: no screen for " mold route]]
|
|
770
|
+
unless may-leave? [exit]
|
|
493
771
|
set-route route false
|
|
494
772
|
run-enter enter-screen router route
|
|
495
773
|
]
|
|
@@ -519,6 +797,20 @@ can-go-forward?: function [
|
|
|
519
797
|
0 < second route-steps
|
|
520
798
|
]
|
|
521
799
|
|
|
800
|
+
unsaved: function [
|
|
801
|
+
"Marks the screen on show as having changes not saved, or not: leaving it asks first, and so does closing the page."
|
|
802
|
+
on [logic!]
|
|
803
|
+
] [
|
|
804
|
+
set 'marked on
|
|
805
|
+
set-unsaved on
|
|
806
|
+
]
|
|
807
|
+
|
|
808
|
+
unsaved?: function [
|
|
809
|
+
"True if the screen on show has changes not saved (unsaved)."
|
|
810
|
+
] [
|
|
811
|
+
marked
|
|
812
|
+
]
|
|
813
|
+
|
|
522
814
|
ui-route: function [
|
|
523
815
|
"Called by the host when the page's link changes: back, forward or a link."
|
|
524
816
|
f parts [block!]
|
|
@@ -526,6 +818,8 @@ ui-route: function [
|
|
|
526
818
|
route: copy parts
|
|
527
819
|
unless empty? route [route/1: attempt [to word! route/1]]
|
|
528
820
|
if route = f/value [exit]
|
|
821
|
+
; the link has changed already: staying puts the screen's link back
|
|
822
|
+
unless may-leave? [route-undo exit]
|
|
529
823
|
run-enter follow-link f parts
|
|
530
824
|
]
|
|
531
825
|
|
|
@@ -535,7 +829,10 @@ ui-pane: function [
|
|
|
535
829
|
] [
|
|
536
830
|
inner: either find [form entry] f/style [f] [f/form]
|
|
537
831
|
foreach c any [f/pane []] [attach c f/root inner]
|
|
538
|
-
|
|
832
|
+
unless f/root [exit]
|
|
833
|
+
refresh-form any [inner f/root]
|
|
834
|
+
; and the forms among the new faces, whose submits start disabled until their fields are valid
|
|
835
|
+
foreach c any [f/pane []] [foreach g all-faces c [if g/style = 'form [refresh-form g]]]
|
|
539
836
|
]
|
|
540
837
|
|
|
541
838
|
open: func [
|
|
@@ -678,6 +975,20 @@ set-values: function [
|
|
|
678
975
|
refresh-form scope
|
|
679
976
|
]
|
|
680
977
|
|
|
978
|
+
insert-text: function [
|
|
979
|
+
"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."
|
|
980
|
+
face [object!]
|
|
981
|
+
text [string!]
|
|
982
|
+
] [
|
|
983
|
+
unless find [field area rich] face/style [
|
|
984
|
+
do make error! rejoin ["insert-text: a " face/style " has no cursor"]
|
|
985
|
+
]
|
|
986
|
+
if any [face/readonly face/disabled empty? text] [exit]
|
|
987
|
+
; the host gives the value with the text in; at its end when the face has had no cursor
|
|
988
|
+
ui-input face insert-at-caret face text
|
|
989
|
+
face
|
|
990
|
+
]
|
|
991
|
+
|
|
681
992
|
field-error: function [
|
|
682
993
|
"Shows a message on a named field until the user changes it: what a server refused. False if there is no such field."
|
|
683
994
|
scope name [word! string!] text [string!]
|
|
@@ -719,7 +1030,7 @@ rows-entry: function [f data] [
|
|
|
719
1030
|
labels: copy []
|
|
720
1031
|
set 'last-entry last-entry + 1
|
|
721
1032
|
e: make select styles 'entry [owner: f value: last-entry]
|
|
722
|
-
e/pane: build
|
|
1033
|
+
e/pane: ui-build spec labels
|
|
723
1034
|
bind-labels spec labels copy []
|
|
724
1035
|
foreach g named-faces e [
|
|
725
1036
|
if f/readonly [g/readonly: true]
|
|
@@ -809,23 +1120,169 @@ ui-rows: function [
|
|
|
809
1120
|
refresh-form any [f/form f/root]
|
|
810
1121
|
]
|
|
811
1122
|
|
|
812
|
-
;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1123
|
+
; --- reactions -------------------------------------------------------------------
|
|
1124
|
+
;
|
|
1125
|
+
; `react [...]` after a face runs the block when the face is shown, and again
|
|
1126
|
+
; whenever a facet it reads changes: `total/text`, `face/value`, `values/qty`.
|
|
1127
|
+
; Which facets it reads is found by reading the block, not by running it. The
|
|
1128
|
+
; host checks them at the end of each round, before it repaints, against what
|
|
1129
|
+
; they were when the block last ran. `is [...]` gives the face's main facet what
|
|
1130
|
+
; the block gives, and `calc [...]` its value, which the user cannot change.
|
|
1131
|
+
|
|
1132
|
+
reaction: make object! [
|
|
1133
|
+
kind: 'react ; react, is or calc
|
|
1134
|
+
body: none
|
|
1135
|
+
later: false ; runs on a change only, not when the face is shown
|
|
1136
|
+
sources: none ; the [face facet ...] it reads, found the first time it is checked
|
|
1137
|
+
targets: none ; the [face facet ...] it sets, so that it runs before what reads them
|
|
1138
|
+
last: none ; what its sources were when it last ran
|
|
1139
|
+
]
|
|
1140
|
+
|
|
1141
|
+
add-reaction: function [f k b l] [
|
|
1142
|
+
unless f/reactions [f/reactions: copy []]
|
|
1143
|
+
append f/reactions make reaction [kind: k body: b later: l]
|
|
1144
|
+
]
|
|
1145
|
+
|
|
1146
|
+
value-styles: append copy input-styles [progress image video audio]
|
|
1147
|
+
|
|
1148
|
+
; The facet `is` sets: data for a table, list, tree or chart, a canvas's draw,
|
|
1149
|
+
; an input's value, and text for the rest.
|
|
1150
|
+
main-facet: func [f] [
|
|
1151
|
+
case [
|
|
1152
|
+
find data-styles f/style ['data]
|
|
1153
|
+
f/style = 'orbit ['data]
|
|
1154
|
+
f/style = 'canvas ['draw]
|
|
1155
|
+
find value-styles f/style ['value]
|
|
1156
|
+
true ['text]
|
|
1157
|
+
]
|
|
1158
|
+
]
|
|
1159
|
+
|
|
1160
|
+
face?: func [v] [all [object? :v in v 'style in v 'pane]]
|
|
1161
|
+
|
|
1162
|
+
; Puts in out the face and facet a path names: name/facet (a label), face/facet
|
|
1163
|
+
; (the face itself), values/field (the value of the field of that name).
|
|
1164
|
+
react-path: function [f p out [block!]] [
|
|
1165
|
+
w: first p
|
|
1166
|
+
unless all [word? :w word? pick p 2] [exit]
|
|
1167
|
+
facet: second p
|
|
1168
|
+
g: case [
|
|
1169
|
+
w = 'face [f]
|
|
1170
|
+
w = 'values [facet: 'value attempt [find-named f second p]]
|
|
1171
|
+
true [attempt [get w]]
|
|
1172
|
+
]
|
|
1173
|
+
if all [face? :g in g facet] [append out reduce [g facet]]
|
|
1174
|
+
]
|
|
1175
|
+
|
|
1176
|
+
react-scan: function [f b [block! paren!] sources [block!] targets [block!] /local v] [
|
|
1177
|
+
foreach v b [
|
|
1178
|
+
case [
|
|
1179
|
+
any [block? :v paren? :v] [react-scan f v sources targets]
|
|
1180
|
+
any [path? :v get-path? :v] [react-path f v sources]
|
|
1181
|
+
set-path? :v [react-path f v targets]
|
|
1182
|
+
]
|
|
1183
|
+
]
|
|
1184
|
+
]
|
|
1185
|
+
|
|
1186
|
+
react-now: function [r /local g facet] [
|
|
1187
|
+
out: copy []
|
|
1188
|
+
foreach [g facet] r/sources [append/only out select g facet]
|
|
1189
|
+
out
|
|
1190
|
+
]
|
|
1191
|
+
|
|
1192
|
+
; Faces compare by content, so finding one in a block needs same?.
|
|
1193
|
+
find-same: function [b [block!] v] [
|
|
1194
|
+
foreach x b [if same? x v [return true]]
|
|
1195
|
+
false
|
|
1196
|
+
]
|
|
1197
|
+
|
|
1198
|
+
react-due?: func [r] [not strict-equal? r/last react-now r]
|
|
1199
|
+
|
|
1200
|
+
; True if a reaction sets something b reads.
|
|
1201
|
+
feeds?: function [a b /local g m h n] [
|
|
1202
|
+
foreach [g m] a/targets [
|
|
1203
|
+
foreach [h n] b/sources [if all [same? g h m = n] [return true]]
|
|
1204
|
+
]
|
|
1205
|
+
false
|
|
1206
|
+
]
|
|
1207
|
+
|
|
1208
|
+
react-run: function [f r] [
|
|
1209
|
+
if r/kind = 'react [
|
|
1210
|
+
run-handler f r/body
|
|
1211
|
+
exit
|
|
1212
|
+
]
|
|
1213
|
+
m: either r/kind = 'calc ['value] [main-facet f]
|
|
1214
|
+
; a formula that fails, or lacks a value, leaves the field empty
|
|
1215
|
+
v: either r/kind = 'calc [attempt [run-handler f r/body]] [run-handler f r/body]
|
|
1216
|
+
unless strict-equal? :v select f m [
|
|
1217
|
+
poke f m :v
|
|
1218
|
+
if m = 'value [store-around f]
|
|
1219
|
+
]
|
|
1220
|
+
]
|
|
1221
|
+
|
|
1222
|
+
ui-react: function [
|
|
1223
|
+
"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."
|
|
1224
|
+
faces [block! object!] "The faces, or a face to take every face in it"
|
|
1225
|
+
/local f r
|
|
1226
|
+
] [
|
|
1227
|
+
if object? faces [faces: all-faces faces]
|
|
1228
|
+
fs: copy []
|
|
1229
|
+
rs: copy []
|
|
1230
|
+
foreach f faces [
|
|
1231
|
+
foreach r any [select f 'reactions []] [
|
|
1232
|
+
unless r/sources [
|
|
1233
|
+
r/sources: copy []
|
|
1234
|
+
r/targets: copy []
|
|
1235
|
+
react-scan f r/body r/sources r/targets
|
|
1236
|
+
if r/kind <> 'react [append r/targets reduce [f either r/kind = 'calc ['value] [main-facet f]]]
|
|
1237
|
+
; none is never a list of values: due, so it runs when shown
|
|
1238
|
+
r/last: either r/later [react-now r] [none]
|
|
1239
|
+
]
|
|
1240
|
+
append fs f
|
|
1241
|
+
append rs r
|
|
1242
|
+
]
|
|
1243
|
+
]
|
|
1244
|
+
cut: copy []
|
|
1245
|
+
failed: none
|
|
1246
|
+
; a second cascade, for what the forms changed after the first (an error, a disabled submit)
|
|
1247
|
+
loop 2 [
|
|
1248
|
+
ran: copy []
|
|
1249
|
+
forever [
|
|
1250
|
+
due: copy []
|
|
1251
|
+
repeat i length? rs [if all [not find ran i react-due? pick rs i] [append due i]]
|
|
1252
|
+
if empty? due [break]
|
|
1253
|
+
; the first that no other one due feeds; if they all feed each other, the first
|
|
1254
|
+
i: first due
|
|
1255
|
+
foreach j due [
|
|
1256
|
+
ok: true
|
|
1257
|
+
foreach k due [if all [k <> j feeds? pick rs k pick rs j] [ok: false break]]
|
|
1258
|
+
if ok [i: j break]
|
|
1259
|
+
]
|
|
1260
|
+
r: pick rs i
|
|
1261
|
+
e: try [react-run pick fs i r none]
|
|
1262
|
+
if all [error? :e not failed] [failed: :e]
|
|
1263
|
+
r/last: react-now r
|
|
1264
|
+
append ran i
|
|
1265
|
+
]
|
|
1266
|
+
if empty? ran [break]
|
|
1267
|
+
; what reads again what changed after it ran is in a cycle: it waits for the next change
|
|
1268
|
+
foreach i ran [
|
|
1269
|
+
r: pick rs i
|
|
1270
|
+
if react-due? r [
|
|
1271
|
+
where: loaded-at r/body
|
|
1272
|
+
append cut rejoin [either where [rejoin [where " "]] [""] r/kind ": left out, what it reads changed again after it ran (a cycle)"]
|
|
1273
|
+
r/last: react-now r
|
|
825
1274
|
]
|
|
826
1275
|
]
|
|
827
|
-
|
|
1276
|
+
scopes: copy []
|
|
1277
|
+
foreach i ran [
|
|
1278
|
+
f: pick fs i
|
|
1279
|
+
s: any [f/form f/root]
|
|
1280
|
+
if all [s not find-same scopes s] [append scopes s]
|
|
1281
|
+
]
|
|
1282
|
+
foreach s scopes [refresh-form s]
|
|
828
1283
|
]
|
|
1284
|
+
if failed [do :failed]
|
|
1285
|
+
cut
|
|
829
1286
|
]
|
|
830
1287
|
|
|
831
1288
|
; --- validation ------------------------------------------------------------------
|
|
@@ -877,6 +1334,7 @@ validate-face: function [
|
|
|
877
1334
|
]
|
|
878
1335
|
if f/typed [
|
|
879
1336
|
if f/style = 'upload [return message 'accept reduce [list-of f/accept]]
|
|
1337
|
+
if f/style = 'photo [return either f/accept [message 'accept reduce [list-of f/accept]] [message 'images []]]
|
|
880
1338
|
return message select [number number money amount date date] f/style []
|
|
881
1339
|
]
|
|
882
1340
|
if blank? :v [
|
|
@@ -939,7 +1397,6 @@ refresh-form: function [scope] [
|
|
|
939
1397
|
; the fields of a row count for the form its rows are in
|
|
940
1398
|
while [all [scope scope/style = 'entry]] [scope: any [scope/form scope/root]]
|
|
941
1399
|
unless all [scope find [form view] scope/style] [exit]
|
|
942
|
-
recalc scope
|
|
943
1400
|
ok: true
|
|
944
1401
|
faces: own-faces scope
|
|
945
1402
|
foreach f faces [
|
|
@@ -1018,6 +1475,7 @@ changed: function [f] [
|
|
|
1018
1475
|
|
|
1019
1476
|
; An upload's value is none or a block of objects [name size type file];
|
|
1020
1477
|
; file is a handle the host keeps, read with read-file or sent with multipart.
|
|
1478
|
+
; A photo's is none, the object of the image chosen, or the address of one kept elsewhere.
|
|
1021
1479
|
ui-files: function [
|
|
1022
1480
|
"Called by the host when the user chooses or drops files: name size type file for each, and the names it refused."
|
|
1023
1481
|
f files [block!] refused [block!]
|
|
@@ -1026,7 +1484,11 @@ ui-files: function [
|
|
|
1026
1484
|
foreach [n s t h] files [keep make object! [name: n size: s type: t file: h]]
|
|
1027
1485
|
]
|
|
1028
1486
|
unless empty? chosen [
|
|
1029
|
-
f/value:
|
|
1487
|
+
f/value: case [
|
|
1488
|
+
f/style = 'photo [first chosen]
|
|
1489
|
+
f/multiple [append copy any [f/value []] chosen]
|
|
1490
|
+
true [copy/part chosen 1]
|
|
1491
|
+
]
|
|
1030
1492
|
]
|
|
1031
1493
|
f/typed: either empty? refused [none] [refused]
|
|
1032
1494
|
f/touched: true
|
|
@@ -1034,12 +1496,15 @@ ui-files: function [
|
|
|
1034
1496
|
]
|
|
1035
1497
|
|
|
1036
1498
|
ui-remove-file: function [
|
|
1037
|
-
"Called by the host when the user removes the file at a position of an upload."
|
|
1499
|
+
"Called by the host when the user removes the file at a position of an upload, or a photo's."
|
|
1038
1500
|
f index [integer!]
|
|
1039
1501
|
] [
|
|
1040
|
-
|
|
1041
|
-
|
|
1502
|
+
f/value: either f/style = 'photo [none] [
|
|
1503
|
+
files: remove at copy f/value index
|
|
1504
|
+
either empty? head files [none] [head files]
|
|
1505
|
+
]
|
|
1042
1506
|
f/typed: none
|
|
1507
|
+
f/touched: true
|
|
1043
1508
|
changed f
|
|
1044
1509
|
]
|
|
1045
1510
|
|
|
@@ -1186,6 +1651,15 @@ ui-reorder: function [
|
|
|
1186
1651
|
fire-event f 'on-reorder fields
|
|
1187
1652
|
]
|
|
1188
1653
|
|
|
1654
|
+
ui-orbit: function [
|
|
1655
|
+
"Called by the host when the user picks a node of an orbit: a neighbour, or one of the trail when back is true."
|
|
1656
|
+
f id back [logic!]
|
|
1657
|
+
] [
|
|
1658
|
+
f/value: id
|
|
1659
|
+
; with no on-back, stepping back is one more pick
|
|
1660
|
+
either all [back handler-for f 'on-back] [fire-event f 'on-back []] [if f/action [run-handler f f/action]]
|
|
1661
|
+
]
|
|
1662
|
+
|
|
1189
1663
|
ui-expand: function [
|
|
1190
1664
|
"Called by the host when the user opens a node of a tree."
|
|
1191
1665
|
f node
|