trebol-dev 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -4
- package/app/app.trb +569 -0
- package/app/demo.trb +36 -0
- package/app/history.trb +43 -0
- package/app/model.trb +611 -0
- package/app/move-sample.trb +21 -0
- package/app/move.trb +129 -0
- package/app/options.trb +404 -0
- package/app/palette.trb +145 -0
- package/app/props.trb +304 -0
- package/app/sample.trb +16 -0
- package/app/samples.trb +46 -0
- package/app/trebol-code.js +13 -0
- package/bin/trebol-dev.js +55 -0
- package/package.json +44 -6
- package/server/files.js +111 -0
package/README.md
CHANGED
|
@@ -1,7 +1,61 @@
|
|
|
1
1
|
# trebol-dev
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
The visual designer for [Trebol](https://trebol-lang.com/). It opens the screens of a Trebol project, lets you
|
|
4
|
+
change them by hand or with the mouse, and writes the code back: only what you changed, with your comments,
|
|
5
|
+
spacing and order kept as you wrote them.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npx trebol-dev # the project in this folder
|
|
9
|
+
npx trebol-dev my-app # or in another one
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
It opens on <http://localhost:5180/> (`--port` picks another). Only this machine reaches it.
|
|
13
|
+
|
|
14
|
+
New to it? [Design with the mouse](https://trebol-lang.com/docs/designer/01-the-window.html), the third tutorial of
|
|
15
|
+
Trebol's documentation, builds the screens of a small shop with it, page by page. Its pages are written here, in
|
|
16
|
+
`docs/designer/`, and Trebol's documentation takes them from here when it is built.
|
|
17
|
+
|
|
18
|
+
## What it does
|
|
19
|
+
|
|
20
|
+
The window holds it all, with no page scroll: the structure on the left, the properties on the right, and in
|
|
21
|
+
the middle the preview, the code, or both side by side (*Design*, *Split*, *Code*). Each part scrolls by itself.
|
|
22
|
+
|
|
23
|
+
- **Files**: every `.trb` file of the project, outside `node_modules` and hidden folders.
|
|
24
|
+
- **Structure**: the faces of each `view` and `layout` in the file, nested as written, with its screens, tabs,
|
|
25
|
+
steps and the template of its rows. Drag a face anywhere to move it, into another box too; *Up* and *Down*
|
|
26
|
+
move it past the face beside it, into the box beside it and out of its own. *Add* has every style of Trebol, in groups
|
|
27
|
+
(layout, text, input, choice, data, action, media): what it adds goes inside the chosen face when that face
|
|
28
|
+
holds others (a panel, a row, a grid...), and after it otherwise; the face added is the one chosen next.
|
|
29
|
+
- **Preview**: the screen as it looks, laid out without running any of the program's code. Click a face to
|
|
30
|
+
choose it.
|
|
31
|
+
- **Code**: the file itself, coloured as Trebol, with the chosen face marked. Put the cursor in a face to
|
|
32
|
+
choose it. Change the code and the structure and preview follow; change the design and the code follows.
|
|
33
|
+
Code that does not load says why, and is not saved.
|
|
34
|
+
- **Properties**: the text a face shows, the name of a field, whether it is required, the columns of a grid
|
|
35
|
+
(`3`, a weight for each as `1 2 1`, or `small 1` for a fixed side column); *Delete* takes it out.
|
|
36
|
+
|
|
37
|
+
A face chosen in one of them is chosen in all three. Drag the space between two columns to make one wider.
|
|
38
|
+
|
|
39
|
+
*Undo* and *Redo* take back any change and bring it back, made with the mouse, in the properties or in the
|
|
40
|
+
code (Ctrl+Z, Ctrl+Shift+Z, Ctrl+Y). *Save* writes the file. Leaving a file with changes asks first.
|
|
41
|
+
|
|
42
|
+
## How it keeps your code
|
|
43
|
+
|
|
44
|
+
The text of the file is the truth: the designer keeps the design nowhere else. It reads the values of the file
|
|
45
|
+
and where each one sits in the text (`load-spans`), and lays out each screen as `trebol check` does
|
|
46
|
+
(`ui-sketch`), so every face knows the text it was written with. A change rewrites only that text: a new label
|
|
47
|
+
replaces the old string, a face that moves takes its comment with it, a face that goes takes its line.
|
|
48
|
+
|
|
49
|
+
## On a web page
|
|
50
|
+
|
|
51
|
+
With no project behind it, as on trebol-lang.com, it shows a sample project; *Save* downloads the file.
|
|
52
|
+
|
|
53
|
+
## Building the code editor
|
|
54
|
+
|
|
55
|
+
The code view is CodeMirror 6, built into one file, `app/trebol-code.js`, from `editor/trebol-code.js`:
|
|
56
|
+
`npm install` and `npm run build:editor`. The built file is kept in the repository, so the designer needs
|
|
57
|
+
nothing else to run.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
Apache-2.0.
|
package/app/app.trb
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
Trebol [
|
|
2
|
+
title: "Trebol designer"
|
|
3
|
+
description: "Lays out the screens of a Trebol project and writes the code back, as you wrote it."
|
|
4
|
+
]
|
|
5
|
+
|
|
6
|
+
; The designer of a project's screens. The file's text is the truth: every change, made on the
|
|
7
|
+
; structure, the properties or the code itself, gives new text, and the design is read from it
|
|
8
|
+
; again. Saving writes the text back through the file API of server/files.js.
|
|
9
|
+
|
|
10
|
+
import %model.trb
|
|
11
|
+
import %demo.trb
|
|
12
|
+
import %palette.trb
|
|
13
|
+
import %options.trb
|
|
14
|
+
import %props.trb
|
|
15
|
+
import %samples.trb
|
|
16
|
+
import %history.trb
|
|
17
|
+
import %move.trb
|
|
18
|
+
import %trebol-code.js
|
|
19
|
+
|
|
20
|
+
files: copy []
|
|
21
|
+
path: none ; the file being designed, from the project's folder
|
|
22
|
+
text: "" ; its text now
|
|
23
|
+
saved: "" ; its text as last read or saved
|
|
24
|
+
d: none ; the design read from text
|
|
25
|
+
chosen: none ; the index of the chosen face in shown-faces d
|
|
26
|
+
problem: none ; why the text does not load, when it does not
|
|
27
|
+
demo: none ; with no server: the files of the demo project, kept in the page
|
|
28
|
+
demo-saved: none ; and each as last downloaded
|
|
29
|
+
prop-entries: [] ; the options the properties show, by the index their controls name
|
|
30
|
+
props-query: "" ; what the properties are narrowed to
|
|
31
|
+
keep-props: false ; a property being typed in: the panel stays, so the typing goes on
|
|
32
|
+
histories: make map! [] ; each file's undo and redo, by its path: kept when another file is opened
|
|
33
|
+
hist: none ; the history of the file being designed
|
|
34
|
+
|
|
35
|
+
; the file API answers only the designer's own pages, which say so with this header
|
|
36
|
+
api-get: func [url] [fetch/with url [headers: [X-Trebol-Dev "1"]]]
|
|
37
|
+
api-put: func [url content] [fetch/with url [method: 'PUT body: content headers: [X-Trebol-Dev "1"]]]
|
|
38
|
+
|
|
39
|
+
read-files: function [] [
|
|
40
|
+
; no file API answers on a web page: the demo project, saved by downloading
|
|
41
|
+
either error? r: try [api-get "/api/files"] [
|
|
42
|
+
set 'demo copy demo-files
|
|
43
|
+
set 'demo-saved copy demo-files
|
|
44
|
+
project-name/text: "demo: Save downloads the file"
|
|
45
|
+
set 'files sort keys-of demo
|
|
46
|
+
] [
|
|
47
|
+
project-name/text: r/name
|
|
48
|
+
set 'files r/files
|
|
49
|
+
]
|
|
50
|
+
file-choice/options: files
|
|
51
|
+
either empty? files [nothing/hidden: false] [open-file first files]
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
open-file: function [name [string!]] [
|
|
55
|
+
if all [path text <> saved] [
|
|
56
|
+
; the demo keeps the changes of a file left; a project's file is left only if the user says so
|
|
57
|
+
either demo [put demo path text] [
|
|
58
|
+
unless confirm/role rejoin [path " has changes that are not saved. Leave them?"] 'danger [
|
|
59
|
+
file-choice/value: path
|
|
60
|
+
exit
|
|
61
|
+
]
|
|
62
|
+
; its changes are left: so is what undoes them
|
|
63
|
+
put histories path new-history
|
|
64
|
+
]
|
|
65
|
+
]
|
|
66
|
+
set 'path name
|
|
67
|
+
file-choice/value: name
|
|
68
|
+
unless select histories name [put histories name new-history]
|
|
69
|
+
set 'hist select histories name
|
|
70
|
+
t: either demo [select demo name] [api-get rejoin ["/api/file?path=" enhex name]]
|
|
71
|
+
set 'saved either demo [select demo-saved name] [t]
|
|
72
|
+
set 'chosen none
|
|
73
|
+
; another file: nothing of the last one's design stays, even when this one does not load
|
|
74
|
+
set 'd none
|
|
75
|
+
change-text t
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
save-file: function [] [
|
|
79
|
+
either demo [
|
|
80
|
+
put demo path text
|
|
81
|
+
put demo-saved path text
|
|
82
|
+
download last split path #"/" text
|
|
83
|
+
] [
|
|
84
|
+
api-put rejoin ["/api/file?path=" enhex path] text
|
|
85
|
+
]
|
|
86
|
+
set 'saved text
|
|
87
|
+
toast "Saved"
|
|
88
|
+
redraw
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
; New text, from any change: read it again; text that does not load keeps the last design.
|
|
92
|
+
change-text: function [t [string!]] [
|
|
93
|
+
set 'text t
|
|
94
|
+
either error? e: try [design-of t] [
|
|
95
|
+
set 'problem form e/message
|
|
96
|
+
] [
|
|
97
|
+
set 'problem none
|
|
98
|
+
set 'd e
|
|
99
|
+
; the Add menu has the styles the file defines too
|
|
100
|
+
add-button/menu: get in first layout/only compose/only [button menu (palette-menu/own d/own)] 'menu
|
|
101
|
+
; and the code colours them as styles: only when they change, as that lays the editor out anew
|
|
102
|
+
unless own-words = d/own [
|
|
103
|
+
set 'own-words copy d/own
|
|
104
|
+
w: copy code-words
|
|
105
|
+
foreach s d/own [put w s 'style]
|
|
106
|
+
code-view/props: make code-view/props [words: w]
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
redraw
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
; A change the person made: it can be undone. Opening a file, undo and redo change the text without one.
|
|
113
|
+
write-text: function [t [string!]] [
|
|
114
|
+
if hist [remember hist text t]
|
|
115
|
+
change-text t
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
edit: function [t [string! none!]] [if t [write-text t]]
|
|
119
|
+
|
|
120
|
+
undo-change: function [] [if all [hist t: undo-text hist text] [change-text t]]
|
|
121
|
+
redo-change: function [] [if all [hist t: redo-text hist text] [change-text t]]
|
|
122
|
+
|
|
123
|
+
; Ctrl+Z in the code: what was typed there and not yet read is a change first
|
|
124
|
+
code-undo: function [typed what [word!]] [
|
|
125
|
+
if all [string? typed typed <> text] [write-text typed]
|
|
126
|
+
either what = 'undo [undo-change] [redo-change]
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
; Ctrl+Z and Ctrl+Shift+Z or Ctrl+Y (Cmd on a Mac), unless pressed where the person types: a box undoes its own
|
|
130
|
+
undo-key: function [e] [
|
|
131
|
+
if any [e/typing? e/alt? not any [e/ctrl? e/meta?]] [exit]
|
|
132
|
+
case [
|
|
133
|
+
any [e/key = #"y" all [e/key = #"z" e/shift?]] [redo-change]
|
|
134
|
+
e/key = #"z" [undo-change]
|
|
135
|
+
]
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
the-face: does [all [d chosen pick shown-faces d chosen]]
|
|
139
|
+
|
|
140
|
+
face-name: function [f] [
|
|
141
|
+
; a screen: its name and title, home "Home"
|
|
142
|
+
if all [f/style = 'screen r: written-range d f] [return rejoin ["screen " pick r/1 r/2 " " mold f/text]]
|
|
143
|
+
if piece? f [return rejoin [f/style " " mold f/text]]
|
|
144
|
+
s: form style-word d f
|
|
145
|
+
if l: face-label d f [s: rejoin [l ": " s]]
|
|
146
|
+
; a grid says how it splits: grid 3, grid [1 2 1]
|
|
147
|
+
if all [f/style = 'grid f/cols] [s: rejoin [s " " mold f/cols]]
|
|
148
|
+
if f/name [s: rejoin [s " " f/name]]
|
|
149
|
+
if string? f/text [
|
|
150
|
+
t: f/text
|
|
151
|
+
; long texts are cut, so the structure stays narrow
|
|
152
|
+
if 20 < length? t [t: rejoin [copy/part t 19 "…"]]
|
|
153
|
+
s: rejoin [s " " mold t]
|
|
154
|
+
]
|
|
155
|
+
s
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
; the structure: every face written in the file, nested as written
|
|
159
|
+
nodes-of: function [fs [block!] all-faces [block!]] [
|
|
160
|
+
collect [
|
|
161
|
+
foreach f fs [
|
|
162
|
+
either n: find/same all-faces f [
|
|
163
|
+
node: make map! reduce ['id index? n 'name face-name f]
|
|
164
|
+
if kids: pane-of d f [
|
|
165
|
+
node/children: nodes-of kids all-faces
|
|
166
|
+
node/expanded: true
|
|
167
|
+
]
|
|
168
|
+
keep node
|
|
169
|
+
] [
|
|
170
|
+
if kids: pane-of d f [keep nodes-of kids all-faces]
|
|
171
|
+
]
|
|
172
|
+
]
|
|
173
|
+
]
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
node-of: function [id list [block!]] [
|
|
177
|
+
unless id [return none]
|
|
178
|
+
foreach n list [
|
|
179
|
+
if n/id = id [return n]
|
|
180
|
+
if n/children [if found: node-of id n/children [return found]]
|
|
181
|
+
]
|
|
182
|
+
none
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
redraw: function [] [
|
|
186
|
+
file-state/text: case [
|
|
187
|
+
problem ["Not saved: the code does not load"]
|
|
188
|
+
text = saved ["Saved"]
|
|
189
|
+
true ["Changed"]
|
|
190
|
+
]
|
|
191
|
+
save-button/disabled: any [problem text = saved not path]
|
|
192
|
+
undo-button/disabled: not can-undo? hist
|
|
193
|
+
redo-button/disabled: not can-redo? hist
|
|
194
|
+
code-view/value: text
|
|
195
|
+
problem-text/hidden: not problem
|
|
196
|
+
problem-text/text: any [problem ""]
|
|
197
|
+
unless d [
|
|
198
|
+
; a file opened that does not load: no structure, preview nor properties until it does
|
|
199
|
+
structure/data: copy []
|
|
200
|
+
preview/pane: copy []
|
|
201
|
+
problems/hidden: true
|
|
202
|
+
props/hidden: true
|
|
203
|
+
nothing-chosen/hidden: false
|
|
204
|
+
exit
|
|
205
|
+
]
|
|
206
|
+
fs: shown-faces d
|
|
207
|
+
structure/data: collect [foreach l d/layouts [if l/view [keep nodes-of reduce [l/view] fs]]]
|
|
208
|
+
if all [chosen chosen > length? fs] [set 'chosen none]
|
|
209
|
+
structure/selected: node-of chosen structure/data
|
|
210
|
+
show-screens
|
|
211
|
+
preview/pane: collect [foreach l d/layouts [if l/view [keep l/view/pane]]]
|
|
212
|
+
fill-samples preview/pane
|
|
213
|
+
; every screen, not only the one on show: choosing a face on another shows it with its rows
|
|
214
|
+
foreach [f them] d/screens [fill-samples them]
|
|
215
|
+
mark-chosen
|
|
216
|
+
problems/data: collect [
|
|
217
|
+
foreach l d/layouts [foreach [p m] l/problems [keep make map! reduce ['at any [loaded-at p ""] 'message m]]]
|
|
218
|
+
]
|
|
219
|
+
problems/hidden: empty? problems/data
|
|
220
|
+
problem-count/text: either empty? problems/data ["No problems"] [
|
|
221
|
+
rejoin [length? problems/data either 1 = length? problems/data [" problem"] [" problems"]]
|
|
222
|
+
]
|
|
223
|
+
show-props
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
show-props: function [] [
|
|
227
|
+
f: the-face
|
|
228
|
+
props/hidden: not f
|
|
229
|
+
nothing-chosen/hidden: to logic! f
|
|
230
|
+
unless f [exit]
|
|
231
|
+
face-kind/text: face-name f
|
|
232
|
+
; a view holds the rest: it is neither moved nor deleted
|
|
233
|
+
face-moves/hidden: to logic! layout-of d f
|
|
234
|
+
; a screen is deleted, never moved: the first is the one an app starts on
|
|
235
|
+
move-up/hidden: move-down/hidden: to logic! find [screen tab step] f/style
|
|
236
|
+
; a tab or a step has a label only: no options to find, no events
|
|
237
|
+
props-tab/hidden: props-find/hidden: to logic! piece? f
|
|
238
|
+
def: style-def-of d f
|
|
239
|
+
chain: copy []
|
|
240
|
+
while [def] [append chain form def/name def: def/parent]
|
|
241
|
+
face-chain/text: form chain
|
|
242
|
+
either keep-props [set 'keep-props false] [fill-props]
|
|
243
|
+
]
|
|
244
|
+
|
|
245
|
+
; the controls of the chosen face's options or handlers, laid out anew from what its style takes
|
|
246
|
+
fill-props: function [] [
|
|
247
|
+
unless f: the-face [exit]
|
|
248
|
+
either all [props-tab/value = "Events" not piece? f] [
|
|
249
|
+
props-list/pane: layout/only events-code d f props-query 'prop-act
|
|
250
|
+
] [
|
|
251
|
+
p: props-code d f props-query 'prop-act
|
|
252
|
+
set 'prop-entries p/2
|
|
253
|
+
props-list/pane: layout/only p/1
|
|
254
|
+
]
|
|
255
|
+
]
|
|
256
|
+
|
|
257
|
+
; what a control of the properties did: the k-th option (a group of entries), or 0 for the
|
|
258
|
+
; texts, what it follows and handlers
|
|
259
|
+
prop-act: function [k [integer!] what [word!] value] [
|
|
260
|
+
g: either k > 0 [pick prop-entries k] [none]
|
|
261
|
+
if what = 'check [return either g [prop-check g value] [true]]
|
|
262
|
+
unless f: the-face [exit]
|
|
263
|
+
e: all [g first g]
|
|
264
|
+
; typing goes on in the control: the panel is laid out again only for a choice or a removal
|
|
265
|
+
if find [values code text hint is calc react event action label screen-name screen-title screen-args piece-label] what [set 'keep-props true]
|
|
266
|
+
; a picked icon shows in the panel: laid out again
|
|
267
|
+
t: switch what [
|
|
268
|
+
flag [either value [set-option d f e none] [remove-option d f e]]
|
|
269
|
+
choice [set-option d f e reduce [to word! value]]
|
|
270
|
+
icon [prop-values f g mold to issue! form value]
|
|
271
|
+
custom [either value/2 [set-option/rule d f e none value/1] [remove-option/rule d f e value/1]]
|
|
272
|
+
values [prop-values f g value]
|
|
273
|
+
code [
|
|
274
|
+
either empty? trim copy value [remove-option d f e] [
|
|
275
|
+
b: attempt [load value]
|
|
276
|
+
either block? b [set-option d f e reduce [b]] [none]
|
|
277
|
+
]
|
|
278
|
+
]
|
|
279
|
+
remove [
|
|
280
|
+
either e/how = 'custom [
|
|
281
|
+
; every rule of a program the face has goes
|
|
282
|
+
foreach w custom-rule-words [
|
|
283
|
+
if option-of/rule face-parts d f e w [write-text remove-option/rule d f e w f: the-face]
|
|
284
|
+
]
|
|
285
|
+
none
|
|
286
|
+
] [
|
|
287
|
+
q: group-part face-parts d f g
|
|
288
|
+
either q [remove-option d f q/2] [none]
|
|
289
|
+
]
|
|
290
|
+
]
|
|
291
|
+
text [set-face-text d f value]
|
|
292
|
+
hint [set-hint d f value]
|
|
293
|
+
is calc react [
|
|
294
|
+
b: attempt [load value]
|
|
295
|
+
set-reaction d f what either all [block? b not empty? b] [b] [none]
|
|
296
|
+
]
|
|
297
|
+
label [
|
|
298
|
+
w: all [string? value not empty? trim copy value attempt [load value]]
|
|
299
|
+
case [
|
|
300
|
+
none? w [set-face-label d f none]
|
|
301
|
+
word? w [set-face-label d f w]
|
|
302
|
+
true [none]
|
|
303
|
+
]
|
|
304
|
+
]
|
|
305
|
+
global [set-face-global d f value]
|
|
306
|
+
screen-name [w: attempt [load value] either word? w [set-screen d f 'name w] [none]]
|
|
307
|
+
screen-title [set-screen d f 'title value]
|
|
308
|
+
screen-args [
|
|
309
|
+
w: attempt [load/all value]
|
|
310
|
+
either all [block? w parse w [any word!]] [set-screen d f 'args w] [none]
|
|
311
|
+
]
|
|
312
|
+
add-screen [add-screen d f]
|
|
313
|
+
piece-label [set-piece-label d f value]
|
|
314
|
+
add-piece [add-piece d f value]
|
|
315
|
+
action [
|
|
316
|
+
b: all [string? value not empty? trim copy value attempt [load value]]
|
|
317
|
+
set-action d f either all [block? b not empty? b] [b] [none]
|
|
318
|
+
]
|
|
319
|
+
event [
|
|
320
|
+
b: all [string? value/2 not empty? trim copy value/2 attempt [load value/2]]
|
|
321
|
+
either block? b [set-event d f value/1 b] [remove-event d f value/1]
|
|
322
|
+
]
|
|
323
|
+
]
|
|
324
|
+
either t [edit t] [set 'keep-props false]
|
|
325
|
+
]
|
|
326
|
+
|
|
327
|
+
; what is typed for an option, as the values of the entry of its group that takes them, or none
|
|
328
|
+
typed-as: function [g [block!] value [string!]] [
|
|
329
|
+
vals: attempt [load/all value]
|
|
330
|
+
unless block? vals [return none]
|
|
331
|
+
foreach e g [
|
|
332
|
+
case [
|
|
333
|
+
find [name label] e/how [if all [1 = length? vals word? first vals] [return reduce [e vals]]]
|
|
334
|
+
; a block is typed as it is shown: [1 2 1]
|
|
335
|
+
e/how = 'block [if all [1 = length? vals block? first vals] [return reduce [e vals]]]
|
|
336
|
+
true [
|
|
337
|
+
vs: vals
|
|
338
|
+
; a text is typed as it is shown, with or without its quotes
|
|
339
|
+
if all [find e/args 'text not string? first vals] [vs: reduce [value]]
|
|
340
|
+
if all [(length? vs) = length? e/args args-take? e/args vs] [return reduce [e vs]]
|
|
341
|
+
]
|
|
342
|
+
]
|
|
343
|
+
]
|
|
344
|
+
none
|
|
345
|
+
]
|
|
346
|
+
|
|
347
|
+
args-take?: function [args [block!] vals [block!]] [
|
|
348
|
+
repeat i length? args [
|
|
349
|
+
a: pick args i v: pick vals i
|
|
350
|
+
ok: case [
|
|
351
|
+
a = 'text [any [string? :v map? :v lit-word? :v]]
|
|
352
|
+
'one-of = first a [all [word? :v to logic! find either word? a/2 [get a/2] [a/2] v]]
|
|
353
|
+
true [
|
|
354
|
+
rule: copy []
|
|
355
|
+
foreach t a [unless empty? rule [append rule '|] append rule t]
|
|
356
|
+
parse reduce [:v] rule
|
|
357
|
+
]
|
|
358
|
+
]
|
|
359
|
+
unless ok [return false]
|
|
360
|
+
]
|
|
361
|
+
true
|
|
362
|
+
]
|
|
363
|
+
|
|
364
|
+
prop-check: function [g [block!] value] [
|
|
365
|
+
if any [not string? value empty? trim copy value typed-as g value] [return true]
|
|
366
|
+
m: copy ""
|
|
367
|
+
foreach e g [unless empty? m [append m " or "] append m type-of-args e]
|
|
368
|
+
rejoin ["it takes " m]
|
|
369
|
+
]
|
|
370
|
+
|
|
371
|
+
; values typed for an option: written when they are what it takes, taken out when emptied
|
|
372
|
+
prop-values: function [f g [block!] value [string!]] [
|
|
373
|
+
q: group-part face-parts d f g
|
|
374
|
+
if empty? trim copy value [return either q [remove-option d f q/2] [none]]
|
|
375
|
+
unless t: typed-as g value [return none]
|
|
376
|
+
e: t/1 vals: t/2
|
|
377
|
+
if e/how = 'name [return set-face-name d f first vals]
|
|
378
|
+
; written in another of its ways: in place of it
|
|
379
|
+
either all [q not same? q/2 e] [set-option/over d f e vals q/1] [set-option d f e vals]
|
|
380
|
+
]
|
|
381
|
+
|
|
382
|
+
; the loaded block that holds a box's faces
|
|
383
|
+
; a screens face shows one screen: the one the chosen face is on, or its first; tabs and steps
|
|
384
|
+
; show the tab or step the chosen face is on
|
|
385
|
+
show-screens: function [] [
|
|
386
|
+
c: the-face
|
|
387
|
+
foreach [f them] d/screens [
|
|
388
|
+
on: first them
|
|
389
|
+
foreach s them [if all [c any [same? s c inside? d c s]] [on: s]]
|
|
390
|
+
unless all [block? f/pane 1 = length? f/pane same? on first f/pane] [f/pane: either on [reduce [on]] [copy []]]
|
|
391
|
+
]
|
|
392
|
+
unless c [exit]
|
|
393
|
+
foreach f faces-of d [
|
|
394
|
+
if all [find [tabs steps] f/style block? f/pane] [
|
|
395
|
+
repeat i length? f/pane [
|
|
396
|
+
p: pick f/pane i
|
|
397
|
+
if all [any [same? p c inside? d c p] f/value <> i] [f/value: i]
|
|
398
|
+
]
|
|
399
|
+
]
|
|
400
|
+
]
|
|
401
|
+
]
|
|
402
|
+
|
|
403
|
+
choose-face: function [id] [
|
|
404
|
+
set 'chosen id
|
|
405
|
+
show-screens
|
|
406
|
+
structure/selected: node-of chosen structure/data
|
|
407
|
+
mark-chosen
|
|
408
|
+
show-props
|
|
409
|
+
]
|
|
410
|
+
|
|
411
|
+
; the chosen face, marked in the preview and in the code
|
|
412
|
+
mark-chosen: function [] [
|
|
413
|
+
f: the-face
|
|
414
|
+
preview/selected: f
|
|
415
|
+
s: all [f face-span d f]
|
|
416
|
+
code-view/props: make code-view/props [mark: either s [reduce [s/x s/y]] [none]]
|
|
417
|
+
]
|
|
418
|
+
|
|
419
|
+
; a face clicked in the preview
|
|
420
|
+
pick-face: function [f [object!]] [
|
|
421
|
+
if n: find/same shown-faces d f [choose-face index? n]
|
|
422
|
+
]
|
|
423
|
+
|
|
424
|
+
; the cursor put in the code: the innermost face written around it
|
|
425
|
+
caret-at: function [at [integer!]] [
|
|
426
|
+
unless d [exit]
|
|
427
|
+
best: none
|
|
428
|
+
n: 0
|
|
429
|
+
foreach f shown-faces d [
|
|
430
|
+
n: n + 1
|
|
431
|
+
if all [s: face-span d f at >= s/x at <= (s/x + s/y)] [
|
|
432
|
+
if any [not best s/y <= best/2] [best: reduce [n s/y]]
|
|
433
|
+
]
|
|
434
|
+
]
|
|
435
|
+
if all [best best/1 <> chosen] [choose-face best/1]
|
|
436
|
+
]
|
|
437
|
+
|
|
438
|
+
; Design, Split or Code: what the middle shows
|
|
439
|
+
show-mode: function [m] [
|
|
440
|
+
preview-pane/hidden: m = "Code"
|
|
441
|
+
code-pane/hidden: m = "Design"
|
|
442
|
+
centre/cols: either m = "Split" [[1 1]] [[1]]
|
|
443
|
+
]
|
|
444
|
+
|
|
445
|
+
; the code view colours the dialect's words: styles, and the words that change them
|
|
446
|
+
code-words: make map! []
|
|
447
|
+
own-words: []
|
|
448
|
+
foreach w ui-dialect-words [put code-words w either select styles w ['style] ['flag]]
|
|
449
|
+
|
|
450
|
+
; up or down: past the face beside it, into a box beside it, or out of its box
|
|
451
|
+
step-face: function [by [integer!]] [
|
|
452
|
+
unless all [f: the-face m: move-step d f by] [exit]
|
|
453
|
+
edit m/1
|
|
454
|
+
set 'chosen m/2
|
|
455
|
+
redraw
|
|
456
|
+
]
|
|
457
|
+
|
|
458
|
+
; a row dragged in the structure: its face goes where it was dropped among its siblings
|
|
459
|
+
reorder: function [parent from [integer!] to [integer!]] [
|
|
460
|
+
list: either parent [parent/children] [structure/data]
|
|
461
|
+
; the tree has moved the row already: it is at to, and the one it went beside next to it
|
|
462
|
+
a: pick list to
|
|
463
|
+
b: pick list either to > from [to - 1] [to + 1]
|
|
464
|
+
fs: shown-faces d
|
|
465
|
+
place-face (pick fs a/id) reduce [either to > from ['after] ['before] pick fs b/id]
|
|
466
|
+
]
|
|
467
|
+
|
|
468
|
+
; a row dragged to another level of the structure: before the row it was dropped above, or the last of its box
|
|
469
|
+
drop-face: function [node parent index [integer!]] [
|
|
470
|
+
unless parent [redraw exit]
|
|
471
|
+
fs: shown-faces d
|
|
472
|
+
kids: any [parent/children []]
|
|
473
|
+
place-face (pick fs node/id) either index <= length? kids [
|
|
474
|
+
reduce ['before pick fs kids/:index/id]
|
|
475
|
+
] [
|
|
476
|
+
reduce ['into pick fs parent/id]
|
|
477
|
+
]
|
|
478
|
+
]
|
|
479
|
+
|
|
480
|
+
place-face: function [f where [block!]] [
|
|
481
|
+
either m: move-to d f where [edit m/1 set 'chosen m/2] [none]
|
|
482
|
+
; a move that cannot be made puts the row back
|
|
483
|
+
redraw
|
|
484
|
+
]
|
|
485
|
+
|
|
486
|
+
; an item of the Add menu: inside the chosen face if it holds faces, else after it
|
|
487
|
+
add-face: function [item [word!]] [
|
|
488
|
+
unless code: palette-code item [exit]
|
|
489
|
+
f: the-face
|
|
490
|
+
; what is added is chosen: it comes right after the faces of the one it goes in or after
|
|
491
|
+
at: none
|
|
492
|
+
t: case [
|
|
493
|
+
all [f b: pane-block d f] [at: chosen + 1 + count-inside d f insert-into d b code]
|
|
494
|
+
f [at: chosen + 1 + count-inside d f insert-after d f code]
|
|
495
|
+
all [not empty? d/layouts v: d/layouts/1/view] [
|
|
496
|
+
at: 1 + count-inside d v
|
|
497
|
+
insert-into d d/layouts/1/block code
|
|
498
|
+
]
|
|
499
|
+
]
|
|
500
|
+
unless t [exit]
|
|
501
|
+
edit t
|
|
502
|
+
if all [at not problem pick shown-faces d at] [choose-face at]
|
|
503
|
+
]
|
|
504
|
+
|
|
505
|
+
; the Add menu comes from the palette
|
|
506
|
+
view compose/deep/only [
|
|
507
|
+
width fill
|
|
508
|
+
on-key [undo-key event]
|
|
509
|
+
row spread middle [
|
|
510
|
+
row middle [
|
|
511
|
+
title "Trebol designer"
|
|
512
|
+
global project-name: text muted ""
|
|
513
|
+
global file-choice: choice "File" [] on-change [if value [open-file value]]
|
|
514
|
+
]
|
|
515
|
+
global mode-f: radio mode "View" ["Design" "Split" "Code"] segmented on-change [show-mode value]
|
|
516
|
+
row middle [
|
|
517
|
+
global file-state: text muted ""
|
|
518
|
+
global undo-button: button #undo "Undo" disabled [undo-change]
|
|
519
|
+
global redo-button: button #redo "Redo" disabled [redo-change]
|
|
520
|
+
global save-button: button #check "Save" primary [save-file]
|
|
521
|
+
]
|
|
522
|
+
]
|
|
523
|
+
global nothing: text muted hidden "This project has no .trb files yet."
|
|
524
|
+
grid fit [small 1 medium] resize [
|
|
525
|
+
panel "Structure" pad 2 [
|
|
526
|
+
global add-button: button #plus "Add" small menu (palette-menu) on-menu [add-face event/picked]
|
|
527
|
+
global structure: tree [name] reorder drop on-select [choose-face row/id]
|
|
528
|
+
on-reorder [reorder event/parent event/from event/to]
|
|
529
|
+
on-drop [drop-face event/dropped event/parent event/index]
|
|
530
|
+
]
|
|
531
|
+
global centre: grid fit [1 1] [
|
|
532
|
+
global preview-pane: panel "Preview" [
|
|
533
|
+
global device-f: radio "Screen" ["Desktop" "Tablet" "Phone"] segmented on-change [
|
|
534
|
+
frame/screen: select ["Desktop" 1280x800 "Tablet" 834x1112 "Phone" 390x844] value
|
|
535
|
+
]
|
|
536
|
+
global frame: device desktop fit [
|
|
537
|
+
global preview: column inert on-select [pick-face event/face] []
|
|
538
|
+
]
|
|
539
|
+
global problems: table [at "Where" message "Problem"] hidden
|
|
540
|
+
]
|
|
541
|
+
global code-pane: panel "Code" pad 2 [
|
|
542
|
+
global problem-text: text danger hidden ""
|
|
543
|
+
global code-view: widget <trebol-code> fit [words: code-words mark: none] on-change [write-text value]
|
|
544
|
+
on-caret [caret-at event/detail] on-undo [code-undo event/detail 'undo] on-redo [code-undo event/detail 'redo]
|
|
545
|
+
]
|
|
546
|
+
]
|
|
547
|
+
panel "Properties" pad 4 [
|
|
548
|
+
global nothing-chosen: text muted "Choose a face in the structure, the preview or the code."
|
|
549
|
+
global props: column hidden [
|
|
550
|
+
global face-kind: code ""
|
|
551
|
+
global face-chain: text small muted ""
|
|
552
|
+
global props-tab: radio "Show" ["Options" "Events"] segmented on-change [fill-props]
|
|
553
|
+
global props-find: field "Find an option" on-change [set 'props-query any [value ""] fill-props]
|
|
554
|
+
global props-list: column []
|
|
555
|
+
global face-moves: row [
|
|
556
|
+
global move-up: button #arrow-up "Up" [step-face -1]
|
|
557
|
+
global move-down: button #arrow-down "Down" [step-face 1]
|
|
558
|
+
button #trash "Delete" danger [edit remove-face d the-face set 'chosen none redraw]
|
|
559
|
+
]
|
|
560
|
+
]
|
|
561
|
+
]
|
|
562
|
+
]
|
|
563
|
+
global problem-count: text muted small "No problems"
|
|
564
|
+
]
|
|
565
|
+
|
|
566
|
+
mode-f/value: "Split"
|
|
567
|
+
props-tab/value: "Options"
|
|
568
|
+
device-f/value: "Desktop"
|
|
569
|
+
read-files
|
package/app/demo.trb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Trebol [
|
|
2
|
+
title: "The project the designer shows with no server: on a web page, as a demo"
|
|
3
|
+
exports: [demo-files]
|
|
4
|
+
]
|
|
5
|
+
|
|
6
|
+
; Each file's name and text. Changes stay in the page; saving gives the file to download.
|
|
7
|
+
demo-files: make map! reduce [
|
|
8
|
+
"app.trb" {Trebol [title: "Workshop"]
|
|
9
|
+
|
|
10
|
+
; the board of the workshop: book a repair, see what is in
|
|
11
|
+
view [
|
|
12
|
+
title "Bike workshop"
|
|
13
|
+
text muted "Book a repair and we call you when it is ready."
|
|
14
|
+
booking: panel "Book a repair" [
|
|
15
|
+
form [
|
|
16
|
+
field name "Your name" required
|
|
17
|
+
field phone "Phone" required ; we call when it is ready
|
|
18
|
+
choice bike "Bike" ["Road" "City" "Mountain" "Folding"]
|
|
19
|
+
date due "Due back"
|
|
20
|
+
area notes "What is wrong"
|
|
21
|
+
check rush "Rush job, 20% more"
|
|
22
|
+
submit "Book in" [toast "Booked in."]
|
|
23
|
+
]
|
|
24
|
+
]
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
"contact.trb" {Trebol [title: "Contact"]
|
|
28
|
+
|
|
29
|
+
view [
|
|
30
|
+
heading "Write to us"
|
|
31
|
+
field email "Email" required email
|
|
32
|
+
area message "Message" required
|
|
33
|
+
button "Send" primary [toast "Sent."]
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
]
|