trebol-dev 0.0.1 → 0.1.1

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