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
|
@@ -0,0 +1,1678 @@
|
|
|
1
|
+
Trebol [
|
|
2
|
+
title: "UI dialect: faces, styles, layout and validation"
|
|
3
|
+
exports: [
|
|
4
|
+
face styles stylize layout view theme looks open close toast confirm print-page
|
|
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
|
+
]
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
; --- faces ---------------------------------------------------------------------
|
|
11
|
+
;
|
|
12
|
+
; A face is an object. The host keeps one DOM node per face and copies these
|
|
13
|
+
; fields to it after every scheduler slice, so code changes a face by
|
|
14
|
+
; setting a field: `total/text: "42"`.
|
|
15
|
+
|
|
16
|
+
face: make object! [
|
|
17
|
+
style: 'face ; what the host renders
|
|
18
|
+
name: none ; field name: the key in `values`, and a word in handlers
|
|
19
|
+
text: none ; label, caption or content
|
|
20
|
+
value: none ; a field's value; also a progress (0-1 or percent) or an image (file or url)
|
|
21
|
+
hint: none ; placeholder
|
|
22
|
+
role: none ; primary accent danger success warning muted
|
|
23
|
+
size: none ; small medium large
|
|
24
|
+
align: none ; left center right spread
|
|
25
|
+
valign: none ; a row's children, top middle bottom; none lines them up on the controls
|
|
26
|
+
cols: none ; columns of a grid: a number, or the weight of each [1 4 1]
|
|
27
|
+
icon: none
|
|
28
|
+
fill: false
|
|
29
|
+
fit: false ; takes the height the window has left, and its children scroll inside
|
|
30
|
+
pad: none ; inner and between-children spacing, a step of the spacing scale (0-7)
|
|
31
|
+
gap: none
|
|
32
|
+
narrow-only: false ; shown only on narrow screens
|
|
33
|
+
wide-only: false ; hidden on narrow screens
|
|
34
|
+
hidden: false
|
|
35
|
+
disabled: false
|
|
36
|
+
readonly: false ; shown and sent, but the user cannot change it, and no rule applies
|
|
37
|
+
inert: false ; shown as it is, but neither it nor its children can be used
|
|
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
|
|
47
|
+
drag: false ; can be dragged: carries its value, or the row in a table, list or tree
|
|
48
|
+
drop: false ; accepts drops (on-drop)
|
|
49
|
+
reorder: false ; its children or rows can be moved around (on-reorder)
|
|
50
|
+
rules: none ; validation: a block of [rule args...] blocks
|
|
51
|
+
error: none ; current message, shown once the face is touched
|
|
52
|
+
touched: false
|
|
53
|
+
pending: false ; an asynchronous check is running
|
|
54
|
+
sent: none ; an upload or photo: how far its files went up, 0-1; none hides the bar
|
|
55
|
+
async-error: none ; result of the last asynchronous check
|
|
56
|
+
action: none ; the block after the face: click, change
|
|
57
|
+
events: none ; [on-change [...] on-select [...]]
|
|
58
|
+
shortcut: none ; a key that activates a button or link: "Ctrl+S"
|
|
59
|
+
menu: none ; context menu (or the menu a button opens): a block of menu items; on-menu runs
|
|
60
|
+
options: none ; choices of a choice or radio; what a lookup's search found
|
|
61
|
+
known: none ; a lookup: what each value shows as, a map; a value not in it shows as itself
|
|
62
|
+
links: none ; a lookup: the screen each value links to when readonly, a map
|
|
63
|
+
query: none ; a lookup: the text last searched for
|
|
64
|
+
currency: none ; a money field's currency code: EUR
|
|
65
|
+
reactions: none ; react, is and calc: a block of reaction objects
|
|
66
|
+
template: none ; rows: the block of the fields of one row
|
|
67
|
+
built: none ; rows: what its rows were last made from
|
|
68
|
+
owner: none ; a row of rows: the rows face it belongs to
|
|
69
|
+
typed: none ; what the user typed in a number, money or date field when it is not one;
|
|
70
|
+
; in an upload or photo, the names of the files it refused
|
|
71
|
+
multiple: false ; an upload or a lookup takes more than one
|
|
72
|
+
accept: none ; the files an upload takes: ["pdf" "image/*"]; a photo, images unless told
|
|
73
|
+
pane: none
|
|
74
|
+
columns: none ; table, list and tree: [field "Label" ...]; a column of images, [field ["Label" image round]]
|
|
75
|
+
data: none ; table, list and tree: a block of map! or object! rows (a tree's
|
|
76
|
+
; have their own in `children`); breadcrumb: its items; orbit: its focus, nodes, edges and trail
|
|
77
|
+
key: 'id ; the row field that identifies a row
|
|
78
|
+
selected: none ; the row last chosen
|
|
79
|
+
sortable: false ; a table the host sorts, from the rows it has, when a header is chosen
|
|
80
|
+
sorted: none ; a table: the order shown, [column asc] or [column desc]
|
|
81
|
+
totals: none ; a table: a row shown at the foot, never chosen nor sorted
|
|
82
|
+
kind: none ; a chart: bar line area pie
|
|
83
|
+
stacked: false ; a chart: its series one on top of another
|
|
84
|
+
draw: none ; a canvas: the block of the draw dialect it shows
|
|
85
|
+
extent: none ; a canvas: the size of its drawing space, a pair
|
|
86
|
+
form: none ; the enclosing form, if any
|
|
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
|
|
89
|
+
submit: false
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
; style name -> prototype face
|
|
93
|
+
styles: make map! []
|
|
94
|
+
|
|
95
|
+
container-styles: [view column row form panel grid dialog scroll split toolbar desktop]
|
|
96
|
+
input-styles: [field password number money date area rich check toggle choice radio upload photo lookup rows widget]
|
|
97
|
+
data-styles: [table list tree chart]
|
|
98
|
+
|
|
99
|
+
foreach [name base] [
|
|
100
|
+
view column column column row row form form panel panel grid grid scroll scroll desktop desktop
|
|
101
|
+
title title heading heading text text divider divider
|
|
102
|
+
field field password password number number money money date date area area rich rich check check choice choice
|
|
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
|
|
105
|
+
button button link link tile tile table table list list tabs tabs tab tab
|
|
106
|
+
toolbar toolbar breadcrumb breadcrumb tree tree screens screens screen screen rows rows entry entry
|
|
107
|
+
canvas canvas chart chart orbit orbit
|
|
108
|
+
] [
|
|
109
|
+
poke styles name make face [style: base]
|
|
110
|
+
]
|
|
111
|
+
poke styles 'view make face [style: 'view]
|
|
112
|
+
poke styles 'submit make face [style: 'button role: 'primary submit: true]
|
|
113
|
+
poke styles 'dialog make face [style: 'dialog hidden: true]
|
|
114
|
+
poke styles 'tabs make face [style: 'tabs value: 1]
|
|
115
|
+
poke styles 'screens make face [style: 'screens entering: false] ; entering: the screen on show is still the old one
|
|
116
|
+
poke styles 'split make face [style: 'split value: 1] ; value: the pane shown on narrow screens
|
|
117
|
+
poke styles 'canvas make face [style: 'canvas extent: 300x150]
|
|
118
|
+
poke styles 'chart make face [style: 'chart kind: 'bar]
|
|
119
|
+
|
|
120
|
+
stylize: function [
|
|
121
|
+
"Defines styles from existing ones: name: base [field: value ...]"
|
|
122
|
+
spec [block!]
|
|
123
|
+
] [
|
|
124
|
+
parse spec [some [
|
|
125
|
+
set name set-word! set base word! set defaults block! (
|
|
126
|
+
proto: select styles base
|
|
127
|
+
unless proto [do make error! rejoin ["stylize: unknown style " base ui-suggest base words-of styles]]
|
|
128
|
+
poke styles to word! name make proto defaults
|
|
129
|
+
)
|
|
130
|
+
]]
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
; --- layout --------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
roles: [primary accent danger success warning muted]
|
|
136
|
+
sizes: [small medium large]
|
|
137
|
+
aligns: [left center right spread]
|
|
138
|
+
valigns: [top middle bottom]
|
|
139
|
+
flags: [fill fit hidden disabled readonly inert narrow-only wide-only linked round drag drop reorder multiple sortable stacked]
|
|
140
|
+
chart-kinds: [bar line area pie]
|
|
141
|
+
simple-rules: [required email url integer]
|
|
142
|
+
letter: charset [#"a" - #"z" #"A" - #"Z"]
|
|
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
|
|
146
|
+
|
|
147
|
+
; Words that never name a field. email, url and integer are rules too,
|
|
148
|
+
; but also common field names, so the first word after an input style names it.
|
|
149
|
+
field-name?: func [w [word!]] [
|
|
150
|
+
not any [
|
|
151
|
+
find roles w find sizes w find aligns w find flags w
|
|
152
|
+
find rule-words w w = 'required event-word? w
|
|
153
|
+
]
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
add-rule: func [f rule [block!]] [
|
|
157
|
+
unless f/rules [f/rules: copy []]
|
|
158
|
+
append/only f/rules rule
|
|
159
|
+
]
|
|
160
|
+
|
|
161
|
+
event-word?: func [w [word!]] [
|
|
162
|
+
to logic! find/match form w "on-"
|
|
163
|
+
]
|
|
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
|
+
|
|
348
|
+
; Labels (`search: field`, `table clients`) are local to the layout, as R3
|
|
349
|
+
; planned for its VID: each layout gets an object holding them, and the
|
|
350
|
+
; layout's blocks (its handlers too) are bound to it. `global search: field`
|
|
351
|
+
; sets a global word instead.
|
|
352
|
+
|
|
353
|
+
layout: function [
|
|
354
|
+
"Turns a block of the UI dialect into a view face; /only gives the block of faces."
|
|
355
|
+
spec [block!]
|
|
356
|
+
/only "Return the faces, not a view holding them"
|
|
357
|
+
/local ev b w
|
|
358
|
+
] [
|
|
359
|
+
; a copy, so laying out the same block twice never shares bindings
|
|
360
|
+
spec: copy/deep spec
|
|
361
|
+
labels: copy []
|
|
362
|
+
either only [
|
|
363
|
+
out: ui-build spec labels
|
|
364
|
+
] [
|
|
365
|
+
; on-xxx handlers and its width before the first face belong to the view itself
|
|
366
|
+
events: copy []
|
|
367
|
+
width: none
|
|
368
|
+
parse spec [any [
|
|
369
|
+
set ev word! if (event-word? ev) set b block! (append events reduce [ev b])
|
|
370
|
+
| 'width set w ['small | 'medium | 'large | 'fill] (width: w)
|
|
371
|
+
] body:]
|
|
372
|
+
out: make select styles 'view [pane: ui-build body labels]
|
|
373
|
+
unless empty? events [out/events: events]
|
|
374
|
+
out/size: width
|
|
375
|
+
]
|
|
376
|
+
bind-labels spec labels copy []
|
|
377
|
+
out
|
|
378
|
+
]
|
|
379
|
+
|
|
380
|
+
; Binds a laid-out block to an object of its labels and the given [word: value ...].
|
|
381
|
+
bind-labels: function [spec [block!] labels [block!] words [block!] /local w f] [
|
|
382
|
+
foreach [w f] labels [append words reduce [to set-word! w f]]
|
|
383
|
+
unless empty? words [bind spec make object! words]
|
|
384
|
+
]
|
|
385
|
+
|
|
386
|
+
; Keeps a label for a face: in the layout's labels, or as a global word.
|
|
387
|
+
label-face: function [label labels [block!] global? [logic!] f] [
|
|
388
|
+
either global? [set label f] [
|
|
389
|
+
w: to word! label
|
|
390
|
+
either p: find/skip labels w 2 [p/2: f] [append labels reduce [w f]]
|
|
391
|
+
]
|
|
392
|
+
]
|
|
393
|
+
|
|
394
|
+
; A text of the interface: a string, a text per language (a map), or a word of
|
|
395
|
+
; the dictionary written as a lit-word ('save). Faces keep it as given and the
|
|
396
|
+
; host shows it in the active language, so set-language translates them.
|
|
397
|
+
text-rule: [string! | map! | lit-word!]
|
|
398
|
+
text-of: func [t] [either lit-word? :t [to word! t] [t]]
|
|
399
|
+
|
|
400
|
+
; The faces of a block of the dialect; labels collects [word face ...].
|
|
401
|
+
build-faces: function [
|
|
402
|
+
spec [block!] labels [block!]
|
|
403
|
+
/local label global? style-word f proto n s b w a i v ev p pos later
|
|
404
|
+
] [
|
|
405
|
+
out: copy []
|
|
406
|
+
; what starts the next face
|
|
407
|
+
face-start: [set-word! | 'global | set w word! if (select styles w)]
|
|
408
|
+
modifier: [
|
|
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])
|
|
412
|
+
; a word of the dictionary: button 'save (in a link, a lit-word is the screen)
|
|
413
|
+
| if (f/style <> 'link) set v lit-word! (v: to word! v either f/text [f/hint: v] [f/text: v])
|
|
414
|
+
| set ev word! if (event-word? ev) set b block! (
|
|
415
|
+
unless f/events [f/events: copy []]
|
|
416
|
+
append f/events reduce [ev b]
|
|
417
|
+
)
|
|
418
|
+
| pos: set b block! (
|
|
419
|
+
case [
|
|
420
|
+
; grid [1 4 1] [...]: the weight of each column, then the children
|
|
421
|
+
all [f/style = 'grid none? f/pane not empty? b parse b [some integer!]] [f/cols: b]
|
|
422
|
+
; rows items [...]: the fields of a row; a second block is the action
|
|
423
|
+
all [f/style = 'rows none? f/template] [f/template: b]
|
|
424
|
+
find container-styles f/style [
|
|
425
|
+
; --- in a toolbar is a separator
|
|
426
|
+
f/pane: build-faces either f/style = 'toolbar [replace/all copy b '--- 'divider] [b] labels
|
|
427
|
+
if all [f/style = 'split 2 <> length? f/pane] [
|
|
428
|
+
ui-problem pos "split takes two faces, one per pane"
|
|
429
|
+
]
|
|
430
|
+
]
|
|
431
|
+
find data-styles f/style [f/columns: columns-of b]
|
|
432
|
+
; the first block holds the items, the second is the action
|
|
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]]
|
|
438
|
+
f/style = 'canvas [f/draw: b]
|
|
439
|
+
f/style = 'tabs [f/pane: tabs-of b labels]
|
|
440
|
+
f/style = 'screens [f/data: screens-of b]
|
|
441
|
+
all [find [choice radio] f/style none? f/options] [f/options: options-of b]
|
|
442
|
+
true [f/action: b]
|
|
443
|
+
]
|
|
444
|
+
)
|
|
445
|
+
| set i issue! (f/icon: i)
|
|
446
|
+
| set v [file! | url! | percent!] (f/value: v)
|
|
447
|
+
; a link to a screen: link "Clients" 'clients, link "Ada" 'client/42
|
|
448
|
+
| set v lit-word! (f/value: to word! v)
|
|
449
|
+
| set v lit-path! (f/value: to path! v)
|
|
450
|
+
| set n integer! (f/cols: n)
|
|
451
|
+
| set p pair! (f/extent: p)
|
|
452
|
+
| set w word! if (all [f/style = 'chart find chart-kinds w]) (f/kind: w)
|
|
453
|
+
| 'min set n [number! | money! | date!] (add-rule f reduce ['min n])
|
|
454
|
+
| 'max set n [number! | money! | date!] (add-rule f reduce ['max n])
|
|
455
|
+
| 'length set a integer! set n integer! (add-rule f reduce ['length a n])
|
|
456
|
+
| 'pattern set b block! (add-rule f reduce ['pattern b])
|
|
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
|
+
)
|
|
464
|
+
| 'known set v map! (f/known: v)
|
|
465
|
+
| 'links set v map! (f/links: v)
|
|
466
|
+
| 'match set w word! (add-rule f reduce ['match w])
|
|
467
|
+
| 'check set b block! (add-rule f reduce ['check b])
|
|
468
|
+
| 'check-async set b block! (add-rule f reduce ['check-async b])
|
|
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)
|
|
472
|
+
| 'width set w word! (f/size: w)
|
|
473
|
+
| pos: set w ['pad | 'gap] [set n integer! | 'none (n: 0) | 'wide (n: 6)] (poke f w spacing n pos)
|
|
474
|
+
| 'menu set b block! (f/menu: menu-of b)
|
|
475
|
+
| 'key set s string! (f/shortcut: s)
|
|
476
|
+
| 'key set w word! (f/key: w)
|
|
477
|
+
| 'sorted set b block! (f/sorted: sort-order b)
|
|
478
|
+
| set w word! if (find roles w) (f/role: w)
|
|
479
|
+
| set w word! if (find sizes w) (f/size: w)
|
|
480
|
+
| set w word! if (find aligns w) (f/align: w)
|
|
481
|
+
| set w word! if (all [f/style = 'row find valigns w]) (f/valign: w)
|
|
482
|
+
| set w word! if (find flags w) (poke f w true)
|
|
483
|
+
| set w word! if (find simple-rules w) (add-rule f reduce [w])
|
|
484
|
+
; money price "Price" EUR
|
|
485
|
+
| set w word! if (all [f/style = 'money parse form w [3 letter]]) (f/currency: to word! uppercase form w)
|
|
486
|
+
]
|
|
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) (
|
|
495
|
+
f: make proto []
|
|
496
|
+
f/place: loaded-at pos
|
|
497
|
+
append out f
|
|
498
|
+
if label [label-face label labels global? f]
|
|
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)]
|
|
502
|
+
opt [if (find input-styles f/style) set n word! if (field-name? n) (f/name: n)]
|
|
503
|
+
; chart bar income [...]: the kind comes before the label
|
|
504
|
+
opt [if (f/style = 'chart) set n word! if (find chart-kinds n) (f/kind: n)]
|
|
505
|
+
; table clients [...] is the same as clients: table [...]
|
|
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
|
+
]
|
|
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]
|
|
524
|
+
]
|
|
525
|
+
]]
|
|
526
|
+
out
|
|
527
|
+
]
|
|
528
|
+
|
|
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
|
|
533
|
+
]
|
|
534
|
+
|
|
535
|
+
; [name "Name" email] -> [name "Name" email "email"]
|
|
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] [
|
|
538
|
+
out: copy []
|
|
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
|
+
]]
|
|
549
|
+
out
|
|
550
|
+
]
|
|
551
|
+
|
|
552
|
+
; [name desc] -> [name desc], checked
|
|
553
|
+
sort-order: function [b [block!]] [
|
|
554
|
+
unless parse b [word! ['asc | 'desc]] [ui-problem b "sorted takes a column and asc or desc"]
|
|
555
|
+
copy b
|
|
556
|
+
]
|
|
557
|
+
|
|
558
|
+
; ["General" [...] "Advanced" [...]] -> a tab face per pair
|
|
559
|
+
tabs-of: function [spec [block!] labels [block!] /local p] [
|
|
560
|
+
out: copy []
|
|
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
|
+
]]
|
|
568
|
+
out
|
|
569
|
+
]
|
|
570
|
+
|
|
571
|
+
; [home "Home" [...] client "Client" [id] [...]] -> [name title args body ...]
|
|
572
|
+
screens-of: function [spec [block!] /local n t a b p] [
|
|
573
|
+
out: copy []
|
|
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 [
|
|
576
|
+
set n word! set t text-rule (a: copy []) opt [ahead [block! block!] set a block!] set b block! (
|
|
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]
|
|
579
|
+
)
|
|
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
|
+
]]
|
|
582
|
+
out
|
|
583
|
+
]
|
|
584
|
+
|
|
585
|
+
menu-item: make object! [
|
|
586
|
+
text: none
|
|
587
|
+
icon: none
|
|
588
|
+
id: none ; the word on-menu gets in event/picked
|
|
589
|
+
items: none ; a submenu
|
|
590
|
+
divider: false
|
|
591
|
+
]
|
|
592
|
+
|
|
593
|
+
; As in Red: ["Edit" edit #trash "Delete" delete --- "Move to" ["Top" top]] -> menu items
|
|
594
|
+
menu-of: function [spec [block!] /local i label w b p] [
|
|
595
|
+
out: copy []
|
|
596
|
+
parse spec [any [
|
|
597
|
+
'--- (append out make menu-item [divider: true])
|
|
598
|
+
| (i: none) opt [set i issue!] set label text-rule (label: text-of label) [
|
|
599
|
+
set b block! (append out make menu-item [text: label icon: i items: menu-of b])
|
|
600
|
+
| set w word! (append out make menu-item [text: label icon: i id: w])
|
|
601
|
+
]
|
|
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
|
+
]]
|
|
604
|
+
out
|
|
605
|
+
]
|
|
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
|
+
|
|
629
|
+
; ["Home" home "Clients" clients "Ada"]: a label and a word per item; the last one may have no word
|
|
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")]
|
|
634
|
+
]
|
|
635
|
+
copy spec
|
|
636
|
+
]
|
|
637
|
+
|
|
638
|
+
; The options of a choice or radio: each reduced, and so are those of a group,
|
|
639
|
+
; a title followed by a block: ["Bikes" ["Road" "City"] "Other"].
|
|
640
|
+
options-of: function [spec [block!]] [
|
|
641
|
+
if ui-checking [return copy spec]
|
|
642
|
+
opts: reduce spec
|
|
643
|
+
forall opts [if block? first opts [change/only opts reduce first opts]]
|
|
644
|
+
opts
|
|
645
|
+
]
|
|
646
|
+
|
|
647
|
+
; Links each face to its view and form, so handlers can find `values`.
|
|
648
|
+
attach: function [f root form] [
|
|
649
|
+
f/root: root
|
|
650
|
+
f/form: form
|
|
651
|
+
if f/pane [
|
|
652
|
+
inner: either find [form entry] f/style [f] [form]
|
|
653
|
+
foreach c f/pane [attach c root inner]
|
|
654
|
+
]
|
|
655
|
+
]
|
|
656
|
+
|
|
657
|
+
view: function [
|
|
658
|
+
"Shows a layout (a block of the dialect, or a face from layout) as the page."
|
|
659
|
+
spec [block! object!]
|
|
660
|
+
] [
|
|
661
|
+
root: either block? spec [layout spec] [spec]
|
|
662
|
+
attach root root none
|
|
663
|
+
set 'page root
|
|
664
|
+
entered: copy []
|
|
665
|
+
foreach f all-faces root [
|
|
666
|
+
if f/style = 'screens [
|
|
667
|
+
set 'router f
|
|
668
|
+
append entered follow-link f route
|
|
669
|
+
]
|
|
670
|
+
]
|
|
671
|
+
foreach f all-faces root [refresh-form f]
|
|
672
|
+
show root
|
|
673
|
+
foreach s entered [run-enter s]
|
|
674
|
+
root
|
|
675
|
+
]
|
|
676
|
+
|
|
677
|
+
; --- screens -------------------------------------------------------------------
|
|
678
|
+
;
|
|
679
|
+
; A screens face shows one screen at a time and keeps the page's link in step:
|
|
680
|
+
; the screen `client [id]` showing id "42" is #/client/42. A route is a block
|
|
681
|
+
; of the screen name and its arguments as strings, as they come in the link.
|
|
682
|
+
|
|
683
|
+
router: none ; the screens face of the page
|
|
684
|
+
marked: false ; the screen on show has changes not saved (unsaved)
|
|
685
|
+
page: none ; the root face of the view on show
|
|
686
|
+
|
|
687
|
+
; The [name title args body] of the screen a route names, or none.
|
|
688
|
+
find-screen: function [f route [block!] /local n t a b] [
|
|
689
|
+
if any [empty? route not word? first route] [return none]
|
|
690
|
+
foreach [n t a b] f/data [
|
|
691
|
+
if all [n = first route (length? a) = ((length? route) - 1)] [return reduce [n t a b]]
|
|
692
|
+
]
|
|
693
|
+
none
|
|
694
|
+
]
|
|
695
|
+
|
|
696
|
+
; Builds the screen a route names as the only child of f; returns the screen face.
|
|
697
|
+
enter-screen: function [f route [block!] /local ev b] [
|
|
698
|
+
def: find-screen f route
|
|
699
|
+
; a screen's arguments and labels are local to it
|
|
700
|
+
spec: copy/deep def/4
|
|
701
|
+
labels: copy []
|
|
702
|
+
; on-xxx handlers before the first face belong to the screen
|
|
703
|
+
events: copy []
|
|
704
|
+
parse spec [any [set ev word! if (event-word? ev) set b block! (append events reduce [ev b])] body:]
|
|
705
|
+
s: make select styles 'screen [text: def/2 pane: ui-build body labels]
|
|
706
|
+
unless empty? events [s/events: events]
|
|
707
|
+
words: copy []
|
|
708
|
+
repeat i length? def/3 [append words reduce [to set-word! pick def/3 i pick route i + 1]]
|
|
709
|
+
bind-labels spec labels words
|
|
710
|
+
f/value: copy route
|
|
711
|
+
f/entering: true
|
|
712
|
+
; a screen starts with nothing to save
|
|
713
|
+
set 'marked false
|
|
714
|
+
set-unsaved false
|
|
715
|
+
f/pane: reduce [s]
|
|
716
|
+
ui-pane f
|
|
717
|
+
s
|
|
718
|
+
]
|
|
719
|
+
|
|
720
|
+
; Runs what a screen does on entering, and only then lets the host show it: the
|
|
721
|
+
; page keeps the screen it had until the new one has its data, so nothing paints
|
|
722
|
+
; half made. If on-enter went elsewhere, the screen it went to decides.
|
|
723
|
+
run-enter: function [s] [
|
|
724
|
+
r: none
|
|
725
|
+
if h: handler-for s 'on-enter [r: try [run-handler s h none]]
|
|
726
|
+
if same? s first router/pane [
|
|
727
|
+
router/entering: false
|
|
728
|
+
; the screen on show changed, and so may whether back and forward can be used
|
|
729
|
+
if h: handler-for router 'on-change [run-handler router h]
|
|
730
|
+
]
|
|
731
|
+
if error? :r [do :r]
|
|
732
|
+
]
|
|
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
|
+
|
|
749
|
+
; Shows the screen of a link given as a block of strings; a link that names no
|
|
750
|
+
; screen shows the first one and is replaced by its link.
|
|
751
|
+
follow-link: function [f parts [block!]] [
|
|
752
|
+
route: copy parts
|
|
753
|
+
unless empty? route [route/1: attempt [to word! route/1]]
|
|
754
|
+
unless find-screen f route [
|
|
755
|
+
route: reduce [first f/data]
|
|
756
|
+
set-route route true
|
|
757
|
+
]
|
|
758
|
+
enter-screen f route
|
|
759
|
+
]
|
|
760
|
+
|
|
761
|
+
go: function [
|
|
762
|
+
"Shows a screen and gives the page its link: go 'clients, go [client row/id] (the name is not evaluated, the arguments are)."
|
|
763
|
+
target [word! block! path!]
|
|
764
|
+
] [
|
|
765
|
+
unless router [do make error! "go: the view has no screens"]
|
|
766
|
+
route: reduce [either word? target [target] [first target]]
|
|
767
|
+
if block? target [foreach a reduce next target [append route form a]]
|
|
768
|
+
if path? target [foreach a next to block! target [append route form a]]
|
|
769
|
+
unless find-screen router route [do make error! rejoin ["go: no screen for " mold route]]
|
|
770
|
+
unless may-leave? [exit]
|
|
771
|
+
set-route route false
|
|
772
|
+
run-enter enter-screen router route
|
|
773
|
+
]
|
|
774
|
+
|
|
775
|
+
go-back: function [
|
|
776
|
+
"Returns to the screen the user came from; if they came from outside the page, goes to target."
|
|
777
|
+
target [word! block! path!]
|
|
778
|
+
] [
|
|
779
|
+
unless route-back [go target]
|
|
780
|
+
]
|
|
781
|
+
|
|
782
|
+
go-forward: function [
|
|
783
|
+
"Goes to the screen the user came back from, if there is one; true if it went."
|
|
784
|
+
] [
|
|
785
|
+
route-forward
|
|
786
|
+
]
|
|
787
|
+
|
|
788
|
+
can-go-back?: function [
|
|
789
|
+
"True if a screen of this page lies behind the current one in the browser's history."
|
|
790
|
+
] [
|
|
791
|
+
0 < first route-steps
|
|
792
|
+
]
|
|
793
|
+
|
|
794
|
+
can-go-forward?: function [
|
|
795
|
+
"True if a screen of this page lies ahead of the current one: the user went back and has not gone elsewhere since."
|
|
796
|
+
] [
|
|
797
|
+
0 < second route-steps
|
|
798
|
+
]
|
|
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
|
+
|
|
814
|
+
ui-route: function [
|
|
815
|
+
"Called by the host when the page's link changes: back, forward or a link."
|
|
816
|
+
f parts [block!]
|
|
817
|
+
] [
|
|
818
|
+
route: copy parts
|
|
819
|
+
unless empty? route [route/1: attempt [to word! route/1]]
|
|
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]
|
|
823
|
+
run-enter follow-link f parts
|
|
824
|
+
]
|
|
825
|
+
|
|
826
|
+
ui-pane: function [
|
|
827
|
+
"Called by the host when code gave a face a new pane: links the new faces to their view and form."
|
|
828
|
+
f
|
|
829
|
+
] [
|
|
830
|
+
inner: either find [form entry] f/style [f] [f/form]
|
|
831
|
+
foreach c any [f/pane []] [attach c f/root inner]
|
|
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]]]
|
|
836
|
+
]
|
|
837
|
+
|
|
838
|
+
open: func [
|
|
839
|
+
"Shows a dialog."
|
|
840
|
+
dialog [object!]
|
|
841
|
+
] [
|
|
842
|
+
dialog/hidden: false
|
|
843
|
+
]
|
|
844
|
+
|
|
845
|
+
close: func [
|
|
846
|
+
"Hides a dialog; closes a stream."
|
|
847
|
+
target [object! handle!]
|
|
848
|
+
] [
|
|
849
|
+
either object? target [target/hidden: true] [close-stream target]
|
|
850
|
+
]
|
|
851
|
+
|
|
852
|
+
toast: func [
|
|
853
|
+
"Shows a short notice that goes away by itself."
|
|
854
|
+
message [string! map! word!] "A text, a text per language, or a word of the dictionary"
|
|
855
|
+
/role "primary, success, warning or danger"
|
|
856
|
+
kind [word!]
|
|
857
|
+
] [
|
|
858
|
+
show-toast tr message either role [kind] [none]
|
|
859
|
+
]
|
|
860
|
+
|
|
861
|
+
confirm: func [
|
|
862
|
+
"Asks a question in a small dialog and waits: true when the user says yes."
|
|
863
|
+
question [string! map! word!] "A text, a text per language, or a word of the dictionary"
|
|
864
|
+
/with "The answers, yes first"
|
|
865
|
+
choices [block!]
|
|
866
|
+
/role "primary (the default) or danger, for what cannot be undone"
|
|
867
|
+
kind [word!]
|
|
868
|
+
] [
|
|
869
|
+
show-confirm tr question
|
|
870
|
+
either with [tr first choices] [none]
|
|
871
|
+
either with [tr second choices] [none]
|
|
872
|
+
either role [kind] [none]
|
|
873
|
+
]
|
|
874
|
+
|
|
875
|
+
print-page: func [
|
|
876
|
+
"Opens the browser's print dialog for the screen."
|
|
877
|
+
/only "Print just this face and what is inside it"
|
|
878
|
+
face [object!]
|
|
879
|
+
] [
|
|
880
|
+
print-faces either only [face] [none]
|
|
881
|
+
]
|
|
882
|
+
|
|
883
|
+
set-language: func [
|
|
884
|
+
"Changes the active language and shows every face again in it."
|
|
885
|
+
language [word! string!]
|
|
886
|
+
] [
|
|
887
|
+
i18n/language: either string? language [to word! language] [language]
|
|
888
|
+
; the messages under the fields were written in the language before
|
|
889
|
+
if page [foreach f all-faces page [refresh-form f]]
|
|
890
|
+
repaint
|
|
891
|
+
]
|
|
892
|
+
|
|
893
|
+
; The looks of src/host/theme.ts, with their names: colors, shapes, fonts, shadows and
|
|
894
|
+
; how the icons are drawn go together. As they are, they make the items of a menu.
|
|
895
|
+
looks: [
|
|
896
|
+
#(en: "Minimal" es: "Minimalista") minimal
|
|
897
|
+
#(en: "Paper" es: "Papel") paper
|
|
898
|
+
#(en: "Civic" es: "Institucional") civic
|
|
899
|
+
#(en: "Soft" es: "Amable") soft
|
|
900
|
+
#(en: "Ink" es: "Tinta") ink
|
|
901
|
+
#(en: "Classic" es: "Clásico") classic
|
|
902
|
+
#(en: "Cupertino" es: "Cupertino") cupertino
|
|
903
|
+
#(en: "Fusion" es: "Fusion") fusion
|
|
904
|
+
#(en: "Fluent" es: "Fluent") fluent
|
|
905
|
+
]
|
|
906
|
+
|
|
907
|
+
theme: func [
|
|
908
|
+
"Sets the theme: a look by name (theme 'civic), or parameters (theme [look: civic base: 200 mode: dark])."
|
|
909
|
+
spec [block! word!]
|
|
910
|
+
] [
|
|
911
|
+
apply-theme construct either word? spec [reduce [to set-word! 'look spec]] [spec]
|
|
912
|
+
]
|
|
913
|
+
|
|
914
|
+
; --- walking faces -------------------------------------------------------------
|
|
915
|
+
|
|
916
|
+
all-faces: function [f] [
|
|
917
|
+
out: copy []
|
|
918
|
+
collect-faces f out
|
|
919
|
+
out
|
|
920
|
+
]
|
|
921
|
+
|
|
922
|
+
collect-faces: function [f out] [
|
|
923
|
+
append out f
|
|
924
|
+
if f/pane [foreach c f/pane [collect-faces c out]]
|
|
925
|
+
]
|
|
926
|
+
|
|
927
|
+
; Faces that belong to a scope: nested forms keep their own fields and submits.
|
|
928
|
+
own-faces: function [scope] [
|
|
929
|
+
out: reduce [scope]
|
|
930
|
+
if scope/pane [foreach c scope/pane [collect-own c out]]
|
|
931
|
+
out
|
|
932
|
+
]
|
|
933
|
+
|
|
934
|
+
collect-own: function [f out] [
|
|
935
|
+
append out f
|
|
936
|
+
if all [f/pane f/style <> 'form] [foreach c f/pane [collect-own c out]]
|
|
937
|
+
]
|
|
938
|
+
|
|
939
|
+
; The fields of a row are not fields of the form: rows holds their values.
|
|
940
|
+
named-faces: function [scope] [
|
|
941
|
+
out: copy []
|
|
942
|
+
collect-named scope out
|
|
943
|
+
out
|
|
944
|
+
]
|
|
945
|
+
|
|
946
|
+
collect-named: function [f out] [
|
|
947
|
+
if f/name [append out f]
|
|
948
|
+
if all [f/pane f/style <> 'rows] [foreach c f/pane [collect-named c out]]
|
|
949
|
+
]
|
|
950
|
+
|
|
951
|
+
form-values: function [
|
|
952
|
+
"The values of the named fields of a form (or view), as a map."
|
|
953
|
+
scope
|
|
954
|
+
] [
|
|
955
|
+
m: make map! []
|
|
956
|
+
foreach f named-faces scope [poke m f/name f/value]
|
|
957
|
+
m
|
|
958
|
+
]
|
|
959
|
+
|
|
960
|
+
set-values: function [
|
|
961
|
+
"Fills the named fields of a form (or view) from a map or object; none clears them."
|
|
962
|
+
scope data [map! object! none!]
|
|
963
|
+
] [
|
|
964
|
+
foreach f named-faces scope [
|
|
965
|
+
v: either data [select data f/name] [none]
|
|
966
|
+
f/value: either logic-face? f [true = v] [v]
|
|
967
|
+
f/touched: false
|
|
968
|
+
f/typed: none
|
|
969
|
+
f/async-error: none
|
|
970
|
+
if f/style = 'rows [
|
|
971
|
+
f/built: none
|
|
972
|
+
rows-fill f
|
|
973
|
+
]
|
|
974
|
+
]
|
|
975
|
+
refresh-form scope
|
|
976
|
+
]
|
|
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
|
+
|
|
992
|
+
field-error: function [
|
|
993
|
+
"Shows a message on a named field until the user changes it: what a server refused. False if there is no such field."
|
|
994
|
+
scope name [word! string!] text [string!]
|
|
995
|
+
] [
|
|
996
|
+
name: to word! name
|
|
997
|
+
foreach f named-faces scope [
|
|
998
|
+
if f/name = name [
|
|
999
|
+
f/async-error: text
|
|
1000
|
+
f/error: text
|
|
1001
|
+
f/touched: true
|
|
1002
|
+
refresh-form scope
|
|
1003
|
+
return true
|
|
1004
|
+
]
|
|
1005
|
+
]
|
|
1006
|
+
false
|
|
1007
|
+
]
|
|
1008
|
+
|
|
1009
|
+
; --- rows ------------------------------------------------------------------------
|
|
1010
|
+
;
|
|
1011
|
+
; A field made of rows the user adds and removes. Its pane is an entry per row
|
|
1012
|
+
; and the add button last; an entry holds the fields of the template and its
|
|
1013
|
+
; remove button. Each entry is a scope of its own, so `values` in a handler or
|
|
1014
|
+
; a formula of a row is that row. The value is a block with a map per row, or
|
|
1015
|
+
; none when there are no rows; code changes the rows by assigning it.
|
|
1016
|
+
|
|
1017
|
+
last-entry: 0
|
|
1018
|
+
|
|
1019
|
+
rule-of: function [f name [word!]] [
|
|
1020
|
+
foreach r any [f/rules []] [if r/1 = name [return r/2]]
|
|
1021
|
+
none
|
|
1022
|
+
]
|
|
1023
|
+
|
|
1024
|
+
entries-of: function [f] [
|
|
1025
|
+
collect [foreach c any [f/pane []] [if c/style = 'entry [keep c]]]
|
|
1026
|
+
]
|
|
1027
|
+
|
|
1028
|
+
rows-entry: function [f data] [
|
|
1029
|
+
spec: copy/deep f/template
|
|
1030
|
+
labels: copy []
|
|
1031
|
+
set 'last-entry last-entry + 1
|
|
1032
|
+
e: make select styles 'entry [owner: f value: last-entry]
|
|
1033
|
+
e/pane: ui-build spec labels
|
|
1034
|
+
bind-labels spec labels copy []
|
|
1035
|
+
foreach g named-faces e [
|
|
1036
|
+
if f/readonly [g/readonly: true]
|
|
1037
|
+
if f/disabled [g/disabled: true]
|
|
1038
|
+
]
|
|
1039
|
+
if data [set-values e data]
|
|
1040
|
+
remove-button: make select styles 'button [icon: #trash]
|
|
1041
|
+
remove-button/hint: select i18n/ui 'remove-row
|
|
1042
|
+
remove-button/action: compose [rows-remove (f) (e/value)]
|
|
1043
|
+
append e/pane remove-button
|
|
1044
|
+
e
|
|
1045
|
+
]
|
|
1046
|
+
|
|
1047
|
+
; Makes the rows again from the value, if it or the flags changed since they were made.
|
|
1048
|
+
rows-fill: function [f] [
|
|
1049
|
+
state: reduce [f/value f/readonly f/disabled]
|
|
1050
|
+
if all [f/pane state = f/built] [exit]
|
|
1051
|
+
entries: map-each d any [f/value []] [rows-entry f d]
|
|
1052
|
+
; `min 2` starts with two empty rows
|
|
1053
|
+
while [(length? entries) < any [rule-of f 'min 0]] [append entries rows-entry f none]
|
|
1054
|
+
add-button: either f/pane [last f/pane] [
|
|
1055
|
+
make select styles 'button [icon: #plus]
|
|
1056
|
+
]
|
|
1057
|
+
add-button/text: select i18n/ui 'add-row
|
|
1058
|
+
add-button/action: compose [rows-add (f)]
|
|
1059
|
+
f/pane: append entries add-button
|
|
1060
|
+
if f/root [foreach e entries [attach e f/root f/form]]
|
|
1061
|
+
rows-store f
|
|
1062
|
+
]
|
|
1063
|
+
|
|
1064
|
+
; Takes the value from the rows and shows only the buttons that can be used.
|
|
1065
|
+
rows-store: function [f] [
|
|
1066
|
+
entries: entries-of f
|
|
1067
|
+
n: length? entries
|
|
1068
|
+
f/value: either empty? entries [none] [map-each e entries [form-values e]]
|
|
1069
|
+
f/built: reduce [f/value f/readonly f/disabled]
|
|
1070
|
+
add-button: last f/pane
|
|
1071
|
+
add-button/hidden: f/readonly
|
|
1072
|
+
add-button/disabled: any [f/disabled n >= any [rule-of f 'max n + 1]]
|
|
1073
|
+
foreach e entries [
|
|
1074
|
+
remove-button: last e/pane
|
|
1075
|
+
remove-button/hidden: f/readonly
|
|
1076
|
+
remove-button/disabled: any [f/disabled n <= any [rule-of f 'min 0]]
|
|
1077
|
+
]
|
|
1078
|
+
]
|
|
1079
|
+
|
|
1080
|
+
; A field of a row changed: so did the value of its rows, and of the rows those are in.
|
|
1081
|
+
store-around: function [f] [
|
|
1082
|
+
e: f/form
|
|
1083
|
+
if all [e e/style = 'entry] [
|
|
1084
|
+
rows-store e/owner
|
|
1085
|
+
store-around e/owner
|
|
1086
|
+
]
|
|
1087
|
+
]
|
|
1088
|
+
|
|
1089
|
+
rows-add: function [f] [
|
|
1090
|
+
e: rows-entry f none
|
|
1091
|
+
attach e f/root f/form
|
|
1092
|
+
faces: copy f/pane
|
|
1093
|
+
insert back tail faces e
|
|
1094
|
+
f/pane: faces
|
|
1095
|
+
rows-store f
|
|
1096
|
+
f/touched: true
|
|
1097
|
+
changed f
|
|
1098
|
+
]
|
|
1099
|
+
|
|
1100
|
+
rows-remove: function [f id] [
|
|
1101
|
+
faces: copy f/pane
|
|
1102
|
+
; faces compare by content, so a row is found by its number
|
|
1103
|
+
forall faces [
|
|
1104
|
+
if faces/1/value = id [
|
|
1105
|
+
remove faces
|
|
1106
|
+
break
|
|
1107
|
+
]
|
|
1108
|
+
]
|
|
1109
|
+
f/pane: head faces
|
|
1110
|
+
rows-store f
|
|
1111
|
+
f/touched: true
|
|
1112
|
+
changed f
|
|
1113
|
+
]
|
|
1114
|
+
|
|
1115
|
+
ui-rows: function [
|
|
1116
|
+
"Called by the host when code gave a rows face a new value or changed its flags."
|
|
1117
|
+
f
|
|
1118
|
+
] [
|
|
1119
|
+
rows-fill f
|
|
1120
|
+
refresh-form any [f/form f/root]
|
|
1121
|
+
]
|
|
1122
|
+
|
|
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
|
|
1274
|
+
]
|
|
1275
|
+
]
|
|
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]
|
|
1283
|
+
]
|
|
1284
|
+
if failed [do :failed]
|
|
1285
|
+
cut
|
|
1286
|
+
]
|
|
1287
|
+
|
|
1288
|
+
; --- validation ------------------------------------------------------------------
|
|
1289
|
+
|
|
1290
|
+
message: function [key args [block!]] [
|
|
1291
|
+
out: copy tr select i18n/ui key
|
|
1292
|
+
repeat i length? args [replace out rejoin ["#" i] localize pick args i]
|
|
1293
|
+
out
|
|
1294
|
+
]
|
|
1295
|
+
|
|
1296
|
+
digit: charset "0123456789"
|
|
1297
|
+
word-char: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "._%+-"]
|
|
1298
|
+
host-char: charset [#"a" - #"z" #"A" - #"Z" #"0" - #"9" "-"]
|
|
1299
|
+
email-rule: [some word-char "@" some host-char some ["." some host-char] end]
|
|
1300
|
+
url-rule: [["http://" | "https://"] some host-char any ["." some host-char] opt [":" some digit] opt ["/" to end] end]
|
|
1301
|
+
|
|
1302
|
+
; check and toggle hold true or false
|
|
1303
|
+
logic-face?: func [f] [to logic! find [check toggle] f/style]
|
|
1304
|
+
|
|
1305
|
+
blank?: func [v] [
|
|
1306
|
+
any [none? :v all [string? :v empty? trim copy v]]
|
|
1307
|
+
]
|
|
1308
|
+
|
|
1309
|
+
label-of: func [f] [either f/text [tr f/text] [form f/name]]
|
|
1310
|
+
|
|
1311
|
+
list-of: function [items [block!]] [
|
|
1312
|
+
out: copy ""
|
|
1313
|
+
foreach x items [unless empty? out [append out ", "] append out form x]
|
|
1314
|
+
out
|
|
1315
|
+
]
|
|
1316
|
+
|
|
1317
|
+
; The message for the first rule a face breaks, or none. Asynchronous checks
|
|
1318
|
+
; are skipped here: their last result is kept in async-error.
|
|
1319
|
+
validate-face: function [
|
|
1320
|
+
"Checks a face's rules; returns a message or none."
|
|
1321
|
+
f
|
|
1322
|
+
] [
|
|
1323
|
+
if f/readonly [return none]
|
|
1324
|
+
v: f/value
|
|
1325
|
+
rules: any [f/rules []]
|
|
1326
|
+
if f/style = 'rows [
|
|
1327
|
+
n: either v [length? v] [0]
|
|
1328
|
+
return case [
|
|
1329
|
+
all [n = 0 find/only rules [required]] [message 'required []]
|
|
1330
|
+
n < any [rule-of f 'min 0] [message 'rows-min reduce [rule-of f 'min]]
|
|
1331
|
+
n > any [rule-of f 'max n] [message 'rows-max reduce [rule-of f 'max]]
|
|
1332
|
+
true [none]
|
|
1333
|
+
]
|
|
1334
|
+
]
|
|
1335
|
+
if f/typed [
|
|
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 []]]
|
|
1338
|
+
return message select [number number money amount date date] f/style []
|
|
1339
|
+
]
|
|
1340
|
+
if blank? :v [
|
|
1341
|
+
return either find/only rules [required] [message 'required []] [f/async-error]
|
|
1342
|
+
]
|
|
1343
|
+
if all [logic-face? f find/only rules [required] not v] [return message 'required []]
|
|
1344
|
+
foreach r rules [
|
|
1345
|
+
problem: switch first r [
|
|
1346
|
+
email [unless parse v email-rule [message 'email []]]
|
|
1347
|
+
url [unless parse v url-rule [message 'url []]]
|
|
1348
|
+
integer [unless parse form v [opt "-" some digit] [message 'integer []]]
|
|
1349
|
+
min [if all [any [number? v money? v date? v] v < r/2] [message 'min reduce [r/2]]]
|
|
1350
|
+
max [if all [any [number? v money? v date? v] v > r/2] [message 'max reduce [r/2]]]
|
|
1351
|
+
length [
|
|
1352
|
+
n: length? form v
|
|
1353
|
+
if any [n < r/2 n > r/3] [
|
|
1354
|
+
either r/2 = r/3 [message 'length-exact reduce [r/2]] [message 'length reduce [r/2 r/3]]
|
|
1355
|
+
]
|
|
1356
|
+
]
|
|
1357
|
+
pattern [unless parse form v r/2 [message 'pattern []]]
|
|
1358
|
+
match [
|
|
1359
|
+
other: find-named f r/2
|
|
1360
|
+
if all [other v <> other/value] [message 'match reduce [label-of other]]
|
|
1361
|
+
]
|
|
1362
|
+
check [check-result run-handler f r/2]
|
|
1363
|
+
]
|
|
1364
|
+
if problem [return problem]
|
|
1365
|
+
]
|
|
1366
|
+
f/async-error
|
|
1367
|
+
]
|
|
1368
|
+
|
|
1369
|
+
check-result: func [result] [
|
|
1370
|
+
case [
|
|
1371
|
+
string? :result [result]
|
|
1372
|
+
any [none? :result false = :result] [message 'check []]
|
|
1373
|
+
true [none]
|
|
1374
|
+
]
|
|
1375
|
+
]
|
|
1376
|
+
|
|
1377
|
+
find-named: function [f name] [
|
|
1378
|
+
scope: any [f/form f/root]
|
|
1379
|
+
foreach g named-faces scope [if g/name = name [return g]]
|
|
1380
|
+
none
|
|
1381
|
+
]
|
|
1382
|
+
|
|
1383
|
+
; Runs asynchronous checks of a face (they may fetch).
|
|
1384
|
+
check-async: function [f] [
|
|
1385
|
+
foreach r any [f/rules []] [
|
|
1386
|
+
if all [r/1 = 'check-async not blank? f/value] [
|
|
1387
|
+
f/pending: true
|
|
1388
|
+
f/async-error: check-result run-handler f r/2
|
|
1389
|
+
f/pending: false
|
|
1390
|
+
]
|
|
1391
|
+
]
|
|
1392
|
+
]
|
|
1393
|
+
|
|
1394
|
+
; Updates the errors of touched faces and enables submit buttons only when
|
|
1395
|
+
; every field of the form is valid. A view checks only the faces outside its forms.
|
|
1396
|
+
refresh-form: function [scope] [
|
|
1397
|
+
; the fields of a row count for the form its rows are in
|
|
1398
|
+
while [all [scope scope/style = 'entry]] [scope: any [scope/form scope/root]]
|
|
1399
|
+
unless all [scope find [form view] scope/style] [exit]
|
|
1400
|
+
ok: true
|
|
1401
|
+
faces: own-faces scope
|
|
1402
|
+
foreach f faces [
|
|
1403
|
+
if any [f/rules f/typed f/error] [
|
|
1404
|
+
problem: validate-face f
|
|
1405
|
+
f/error: either f/touched [problem] [none]
|
|
1406
|
+
if problem [ok: false]
|
|
1407
|
+
]
|
|
1408
|
+
]
|
|
1409
|
+
foreach f faces [if f/submit [f/disabled: not ok]]
|
|
1410
|
+
]
|
|
1411
|
+
|
|
1412
|
+
; --- events --------------------------------------------------------------------
|
|
1413
|
+
;
|
|
1414
|
+
; The host calls these from DOM events, each in its own task.
|
|
1415
|
+
|
|
1416
|
+
; A handler block runs with face, value, values and, as in Red, event bound;
|
|
1417
|
+
; event is an object (event/key, event/away? ...) or none. Named fields are
|
|
1418
|
+
; not bound: their values are in values, their faces reached through labels.
|
|
1419
|
+
run-handler: function [f body [block!] /with ev [object!] /on node "row is this node, not the selected one"] [
|
|
1420
|
+
scope: any [f/form f/root]
|
|
1421
|
+
; /only: a value that is a block stays one block
|
|
1422
|
+
words: compose/only [
|
|
1423
|
+
face: (f)
|
|
1424
|
+
value: (quoted f/value)
|
|
1425
|
+
values: (form-values any [scope f])
|
|
1426
|
+
]
|
|
1427
|
+
if find data-styles f/style [append words compose [row: (either on [node] [f/selected])]]
|
|
1428
|
+
append words compose [event: (either with [ev] [none])]
|
|
1429
|
+
ctx: make object! words
|
|
1430
|
+
do bind copy/deep body ctx
|
|
1431
|
+
]
|
|
1432
|
+
|
|
1433
|
+
; A value as it must appear in a block given to make object!
|
|
1434
|
+
quoted: func [v] [
|
|
1435
|
+
case [
|
|
1436
|
+
word? :v [to lit-word! :v]
|
|
1437
|
+
path? :v [to lit-path! :v]
|
|
1438
|
+
true [:v]
|
|
1439
|
+
]
|
|
1440
|
+
]
|
|
1441
|
+
|
|
1442
|
+
handler-for: function [f name] [
|
|
1443
|
+
all [f/events select f/events name]
|
|
1444
|
+
]
|
|
1445
|
+
|
|
1446
|
+
ui-input: function [
|
|
1447
|
+
"Called by the host when the user changes a field."
|
|
1448
|
+
f new
|
|
1449
|
+
] [
|
|
1450
|
+
f/value: switch/default f/style [
|
|
1451
|
+
number [any [attempt [to decimal! new] none]]
|
|
1452
|
+
; the host gives the amount as 1234.5, whatever the language
|
|
1453
|
+
money [all [new attempt [to money! rejoin [any [f/currency ""] "$" new]]]]
|
|
1454
|
+
; and a date as 2026-11-03
|
|
1455
|
+
date [all [new attempt [to date! new]]]
|
|
1456
|
+
check [to logic! new]
|
|
1457
|
+
toggle [to logic! new]
|
|
1458
|
+
] [new]
|
|
1459
|
+
if f/style = 'number [
|
|
1460
|
+
if all [decimal? f/value f/value = to integer! f/value] [f/value: to integer! f/value]
|
|
1461
|
+
]
|
|
1462
|
+
; text that is not a number, amount or date stays on screen, with its message
|
|
1463
|
+
f/typed: all [find [number money date] f/style new none? f/value new]
|
|
1464
|
+
changed f
|
|
1465
|
+
]
|
|
1466
|
+
|
|
1467
|
+
changed: function [f] [
|
|
1468
|
+
f/async-error: none
|
|
1469
|
+
store-around f
|
|
1470
|
+
refresh-form any [f/form f/root]
|
|
1471
|
+
if f/action [run-handler f f/action]
|
|
1472
|
+
if h: handler-for f 'on-change [run-handler f h]
|
|
1473
|
+
if all [f/form f/form/style = 'entry] [changed f/form/owner]
|
|
1474
|
+
]
|
|
1475
|
+
|
|
1476
|
+
; An upload's value is none or a block of objects [name size type file];
|
|
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.
|
|
1479
|
+
ui-files: function [
|
|
1480
|
+
"Called by the host when the user chooses or drops files: name size type file for each, and the names it refused."
|
|
1481
|
+
f files [block!] refused [block!]
|
|
1482
|
+
] [
|
|
1483
|
+
chosen: collect [
|
|
1484
|
+
foreach [n s t h] files [keep make object! [name: n size: s type: t file: h]]
|
|
1485
|
+
]
|
|
1486
|
+
unless empty? chosen [
|
|
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
|
+
]
|
|
1492
|
+
]
|
|
1493
|
+
f/typed: either empty? refused [none] [refused]
|
|
1494
|
+
f/touched: true
|
|
1495
|
+
changed f
|
|
1496
|
+
]
|
|
1497
|
+
|
|
1498
|
+
ui-remove-file: function [
|
|
1499
|
+
"Called by the host when the user removes the file at a position of an upload, or a photo's."
|
|
1500
|
+
f index [integer!]
|
|
1501
|
+
] [
|
|
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
|
+
]
|
|
1506
|
+
f/typed: none
|
|
1507
|
+
f/touched: true
|
|
1508
|
+
changed f
|
|
1509
|
+
]
|
|
1510
|
+
|
|
1511
|
+
; A lookup's value is none, one value, or with `multiple` a block of them. Its on-search
|
|
1512
|
+
; answers the options for event/query: maps with value and text, as a choice takes them.
|
|
1513
|
+
ui-lookup-search: function [
|
|
1514
|
+
"Called by the host when the user opens a lookup or types in it."
|
|
1515
|
+
f text [string!]
|
|
1516
|
+
] [
|
|
1517
|
+
f/query: text
|
|
1518
|
+
found: fire-event f 'on-search compose [query: (text)]
|
|
1519
|
+
; the user may have typed on while this was answering
|
|
1520
|
+
if f/query = text [f/options: either block? :found [found] [copy []]]
|
|
1521
|
+
]
|
|
1522
|
+
|
|
1523
|
+
ui-lookup-pick: function [
|
|
1524
|
+
"Called by the host when the user chooses an option of a lookup."
|
|
1525
|
+
f option [map!]
|
|
1526
|
+
] [
|
|
1527
|
+
unless f/known [f/known: make map! []]
|
|
1528
|
+
poke f/known option/value option/text
|
|
1529
|
+
f/value: either f/multiple [
|
|
1530
|
+
any [
|
|
1531
|
+
all [f/value find f/value option/value f/value]
|
|
1532
|
+
append copy any [f/value []] option/value
|
|
1533
|
+
]
|
|
1534
|
+
] [option/value]
|
|
1535
|
+
changed f
|
|
1536
|
+
]
|
|
1537
|
+
|
|
1538
|
+
ui-lookup-remove: function [
|
|
1539
|
+
"Called by the host when the user removes the value at a position of a multiple lookup."
|
|
1540
|
+
f index [integer!]
|
|
1541
|
+
] [
|
|
1542
|
+
chosen: head remove at copy f/value index
|
|
1543
|
+
f/value: either empty? chosen [none] [chosen]
|
|
1544
|
+
changed f
|
|
1545
|
+
]
|
|
1546
|
+
|
|
1547
|
+
ui-blur: function [
|
|
1548
|
+
"Called by the host when the user leaves a field."
|
|
1549
|
+
f
|
|
1550
|
+
] [
|
|
1551
|
+
f/touched: true
|
|
1552
|
+
check-async f
|
|
1553
|
+
refresh-form any [f/form f/root]
|
|
1554
|
+
]
|
|
1555
|
+
|
|
1556
|
+
ui-click: function [
|
|
1557
|
+
"Called by the host when the user activates a button."
|
|
1558
|
+
f
|
|
1559
|
+
] [
|
|
1560
|
+
if f/submit [
|
|
1561
|
+
scope: any [f/form f/root]
|
|
1562
|
+
faces: own-faces scope
|
|
1563
|
+
foreach g faces [if g/rules [g/touched: true]]
|
|
1564
|
+
foreach g faces [check-async g]
|
|
1565
|
+
refresh-form scope
|
|
1566
|
+
if f/disabled [exit]
|
|
1567
|
+
]
|
|
1568
|
+
if f/action [run-handler f f/action]
|
|
1569
|
+
]
|
|
1570
|
+
|
|
1571
|
+
ui-select: function [
|
|
1572
|
+
"Called by the host when the user chooses a row of a table or list."
|
|
1573
|
+
f row
|
|
1574
|
+
] [
|
|
1575
|
+
f/selected: row
|
|
1576
|
+
if h: handler-for f 'on-select [run-handler f h]
|
|
1577
|
+
]
|
|
1578
|
+
|
|
1579
|
+
ui-sort: function [
|
|
1580
|
+
"Called by the host when the user chooses the header of a column of a table."
|
|
1581
|
+
f column [word!]
|
|
1582
|
+
] [
|
|
1583
|
+
order: either all [block? f/sorted f/sorted/1 = column f/sorted/2 = 'asc] ['desc] ['asc]
|
|
1584
|
+
f/sorted: reduce [column order]
|
|
1585
|
+
fire-event f 'on-sort reduce [quote column: to lit-word! column quote order: to lit-word! order]
|
|
1586
|
+
]
|
|
1587
|
+
|
|
1588
|
+
ui-close: function [
|
|
1589
|
+
"Called by the host when the user dismisses a dialog."
|
|
1590
|
+
f
|
|
1591
|
+
] [
|
|
1592
|
+
f/hidden: true
|
|
1593
|
+
if h: handler-for f 'on-close [run-handler f h]
|
|
1594
|
+
]
|
|
1595
|
+
|
|
1596
|
+
; Runs the on-xxx handler of an event with event bound to an object made of
|
|
1597
|
+
; type (the event name without on-) and the given [word: value ...] fields.
|
|
1598
|
+
fire-event: function [f name [word!] fields [block!]] [
|
|
1599
|
+
if h: handler-for f name [
|
|
1600
|
+
type: to word! skip form name 3
|
|
1601
|
+
run-handler/with f h make object! append reduce [quote type: to lit-word! type] fields
|
|
1602
|
+
]
|
|
1603
|
+
]
|
|
1604
|
+
|
|
1605
|
+
ui-event: function [
|
|
1606
|
+
"Called by the host for on-focus, on-unfocus, on-over, on-dbl-click and on-key."
|
|
1607
|
+
f name [word!] fields [block!]
|
|
1608
|
+
] [
|
|
1609
|
+
fire-event f name fields
|
|
1610
|
+
]
|
|
1611
|
+
|
|
1612
|
+
ui-crumb: function [
|
|
1613
|
+
"Called by the host when the user chooses an item of a breadcrumb."
|
|
1614
|
+
f item [word! path!]
|
|
1615
|
+
] [
|
|
1616
|
+
f/value: item
|
|
1617
|
+
if f/action [run-handler f f/action]
|
|
1618
|
+
]
|
|
1619
|
+
|
|
1620
|
+
ui-menu: function [
|
|
1621
|
+
"Called by the host when the user chooses a menu item; row is the row it was opened on."
|
|
1622
|
+
f item row
|
|
1623
|
+
] [
|
|
1624
|
+
if row [f/selected: row]
|
|
1625
|
+
fire-event f 'on-menu reduce [quote picked: quoted item/id]
|
|
1626
|
+
]
|
|
1627
|
+
|
|
1628
|
+
ui-drop: function [
|
|
1629
|
+
"Called by the host when something is dropped on a face; index is where it goes (1-based), parent the tree node."
|
|
1630
|
+
f dropped source index [integer!] parent
|
|
1631
|
+
] [
|
|
1632
|
+
fields: reduce [quote dropped: quoted :dropped quote source: source quote index: index]
|
|
1633
|
+
if f/style = 'tree [append fields reduce [quote parent: parent]]
|
|
1634
|
+
fire-event f 'on-drop fields
|
|
1635
|
+
]
|
|
1636
|
+
|
|
1637
|
+
ui-reorder: function [
|
|
1638
|
+
"Called by the host when the user moves a child or row of a face; in a tree, among the children of parent."
|
|
1639
|
+
f from [integer!] to [integer!] parent
|
|
1640
|
+
] [
|
|
1641
|
+
fields: reduce [quote from: from quote to: to]
|
|
1642
|
+
case [
|
|
1643
|
+
f/style = 'tree [
|
|
1644
|
+
either parent [parent/children: move-item parent/children from to] [f/data: move-item f/data from to]
|
|
1645
|
+
f/data: f/data ; repaint the tree
|
|
1646
|
+
append fields reduce [quote parent: parent]
|
|
1647
|
+
]
|
|
1648
|
+
find data-styles f/style [f/data: move-item f/data from to]
|
|
1649
|
+
true [f/pane: move-item f/pane from to]
|
|
1650
|
+
]
|
|
1651
|
+
fire-event f 'on-reorder fields
|
|
1652
|
+
]
|
|
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
|
+
|
|
1663
|
+
ui-expand: function [
|
|
1664
|
+
"Called by the host when the user opens a node of a tree."
|
|
1665
|
+
f node
|
|
1666
|
+
] [
|
|
1667
|
+
if h: handler-for f 'on-expand [
|
|
1668
|
+
run-handler/with/on f h make object! [type: 'expand] node
|
|
1669
|
+
]
|
|
1670
|
+
]
|
|
1671
|
+
|
|
1672
|
+
move-item: function [items [block!] from [integer!] to [integer!]] [
|
|
1673
|
+
items: copy items
|
|
1674
|
+
x: pick items from
|
|
1675
|
+
remove at items from
|
|
1676
|
+
insert/only at items to :x
|
|
1677
|
+
items
|
|
1678
|
+
]
|