trebol-dev 0.1.1 → 0.3.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.
@@ -0,0 +1 @@
1
+ {"demo": true}
package/app/app.trb CHANGED
@@ -16,7 +16,13 @@ import %props.trb
16
16
  import %samples.trb
17
17
  import %history.trb
18
18
  import %move.trb
19
+ import %machines.trb
20
+ import %machine-edits.trb
21
+ import %machine-moves.trb
22
+ import %machine-places.trb
23
+ import %fragments.trb
19
24
  import %trebol-code.js
25
+ import %machine-graph.js
20
26
 
21
27
  files: copy []
22
28
  path: none ; the file being designed, from the project's folder
@@ -35,11 +41,17 @@ hist: none ; the history of the file being designed
35
41
 
36
42
  ; the file API answers only the designer's own pages, which say so with this header
37
43
  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"]]]
44
+ ; the answer comes whole (status and body), so a save the server refuses is not an error
45
+ api-put: func [url content] [fetch/with url [method: 'PUT body: content headers: [X-Trebol-Dev "1"] full: true]]
46
+ ; the version of a file's text the server knows it by: the SHA-256 of its bytes
47
+ text-version: func [t [string!]] [lowercase enbase/base checksum t 'sha256 16]
39
48
 
40
49
  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"] [
50
+ ; the listing is asked for next to the page: under trebol-dev the server answers it with the
51
+ ; project; on a web page (the demo trebol build made) it is the file api/files.json, which says
52
+ ; demo, so the page asks for nothing that is not there. With neither: the demo project too,
53
+ ; saved by downloading
54
+ either any [error? r: try [api-get "api/files.json"] r/demo] [
43
55
  set 'demo copy demo-files
44
56
  set 'demo-saved copy demo-files
45
57
  project-name/text: "demo: Save downloads the file"
@@ -82,7 +94,24 @@ save-file: function [] [
82
94
  put demo-saved path text
83
95
  download last split path #"/" text
84
96
  ] [
85
- api-put rejoin ["/api/file?path=" enhex path] text
97
+ url: rejoin ["/api/file?path=" enhex path]
98
+ ; base: the text as last read or saved here; the server refuses it if the file changed since
99
+ r: api-put rejoin [url "&base=" text-version saved] text
100
+ if r/status = 412 [
101
+ either confirm/role rejoin [
102
+ path " was changed outside the designer since it was opened. Save over that change?"
103
+ " No reads the file again, and undo brings back what is here."
104
+ ] 'danger [
105
+ r: api-put url text
106
+ ] [
107
+ t: api-get url
108
+ set 'saved t
109
+ write-text t
110
+ toast rejoin [path " is read again"]
111
+ exit
112
+ ]
113
+ ]
114
+ unless r/status = 200 [do make error! rejoin ["Not saved: " r/status " " r/body]]
86
115
  ]
87
116
  set 'saved text
88
117
  toast "Saved"
@@ -116,7 +145,8 @@ write-text: function [t [string!]] [
116
145
  change-text t
117
146
  ]
118
147
 
119
- edit: function [t [string! none!]] [if t [write-text t]]
148
+ ; the places of the machines' states stay last in the file, whatever an edit wrote after them
149
+ edit: function [t [string! none!]] [if t [write-text places-last t]]
120
150
 
121
151
  undo-change: function [] [if all [hist t: undo-text hist text] [change-text t]]
122
152
  redo-change: function [] [if all [hist t: redo-text hist text] [change-text t]]
@@ -202,6 +232,7 @@ redraw: function [] [
202
232
  problems/hidden: true
203
233
  props/hidden: true
204
234
  nothing-chosen/hidden: false
235
+ redraw-machines
205
236
  exit
206
237
  ]
207
238
  fs: shown-faces d
@@ -222,9 +253,11 @@ redraw: function [] [
222
253
  rejoin [length? problems/data either 1 = length? problems/data [" problem"] [" problems"]]
223
254
  ]
224
255
  show-props
256
+ redraw-machines
225
257
  ]
226
258
 
227
259
  show-props: function [] [
260
+ if editing = "Machines" [props/hidden: true exit]
228
261
  f: the-face
229
262
  props/hidden: not f
230
263
  nothing-chosen/hidden: to logic! f
@@ -255,130 +288,8 @@ fill-props: function [] [
255
288
  ]
256
289
  ]
257
290
 
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
- ]
291
+ ; what the controls of the properties do (shares these words)
292
+ do %props-act.trb
382
293
 
383
294
  ; the loaded block that holds a box's faces
384
295
  ; a screens face shows one screen: the one the chosen face is on, or its first; tabs and steps
@@ -425,6 +336,7 @@ pick-face: function [f [object!]] [
425
336
  ; the cursor put in the code: the innermost face written around it
426
337
  caret-at: function [at [integer!]] [
427
338
  unless d [exit]
339
+ if editing = "Machines" [machine-caret at exit]
428
340
  best: none
429
341
  n: 0
430
342
  foreach f shown-faces d [
@@ -438,7 +350,8 @@ caret-at: function [at [integer!]] [
438
350
 
439
351
  ; Design, Split or Code: what the middle shows
440
352
  show-mode: function [m] [
441
- preview-pane/hidden: m = "Code"
353
+ preview-pane/hidden: any [m = "Code" editing = "Machines"]
354
+ machine-pane/hidden: any [m = "Code" editing <> "Machines"]
442
355
  code-pane/hidden: m = "Design"
443
356
  centre/cols: either m = "Split" [[1 1]] [[1]]
444
357
  ]
@@ -503,6 +416,12 @@ add-face: function [item [word!]] [
503
416
  if all [at not problem pick shown-faces d at] [choose-face at]
504
417
  ]
505
418
 
419
+ ; the machines of the file: their structure, properties and code (shares these words)
420
+ do %machines-view.trb
421
+ do %fragments-view.trb
422
+ do %machine-try.trb
423
+ do %machine-canvas.trb
424
+
506
425
  ; the Add menu comes from the palette
507
426
  view compose/deep/only [
508
427
  width fill
@@ -512,6 +431,7 @@ view compose/deep/only [
512
431
  title "Trebol designer"
513
432
  global project-name: text muted ""
514
433
  global file-choice: choice "File" [] on-change [if value [open-file value]]
434
+ global editing-f: radio "Edit" ["Screens" "Machines"] segmented on-change [show-editing value]
515
435
  ]
516
436
  global mode-f: radio mode "View" ["Design" "Split" "Code"] segmented on-change [show-mode value]
517
437
  row middle [
@@ -528,6 +448,14 @@ view compose/deep/only [
528
448
  global structure: tree [name] reorder drop on-select [choose-face row/id]
529
449
  on-reorder [reorder event/parent event/from event/to]
530
450
  on-drop [drop-face event/dropped event/parent event/index]
451
+ global machine-side: column hidden [
452
+ row [
453
+ button #plus "New machine" small [machine-add 'machine]
454
+ button #plus "New fragment" small [machine-add 'fragment]
455
+ ]
456
+ global machine-none: text muted "This file makes no machines yet. Its states and ways are made on the drawing."
457
+ global machine-tree: tree [name] on-select [pick-machine row/id]
458
+ ]
531
459
  ]
532
460
  global centre: grid fit [1 1] [
533
461
  global preview-pane: panel "Preview" [
@@ -539,6 +467,15 @@ view compose/deep/only [
539
467
  ]
540
468
  global problems: table [at "Where" message "Problem"] hidden
541
469
  ]
470
+ global machine-pane: panel "Drawing" hidden [
471
+ global machine-drawing: widget <tb-machine-graph> fit [graph: none selected: none editing: none trying: false]
472
+ on-pick [pick-machine event/detail] on-add [canvas-add event/detail] on-connect [canvas-connect event/detail]
473
+ on-grow [canvas-grow event/detail] on-rename [canvas-rename event/detail] on-remove [canvas-remove event/detail]
474
+ on-initial [canvas-initial event/detail] on-move [canvas-move event/detail] on-place [canvas-placed event/detail]
475
+ on-undo [undo-change] on-redo [redo-change] on-try [try-machine] on-restart [try-machine] on-stop [stop-try none]
476
+ on-open [toggle-open event/detail] on-fragment [open-fragment event/detail]
477
+ global machine-problems: table [at "Where" message "Problem"] hidden
478
+ ]
542
479
  global code-pane: panel "Code" pad 2 [
543
480
  global problem-text: text danger hidden ""
544
481
  global code-view: widget <trebol-code> fit [words: code-words mark: none] on-change [write-text value]
@@ -547,6 +484,15 @@ view compose/deep/only [
547
484
  ]
548
485
  panel "Properties" pad 4 [
549
486
  global nothing-chosen: text muted "Choose a face in the structure, the preview or the code."
487
+ global machine-props: column hidden []
488
+ global try-panel: column hidden [
489
+ text small muted "Send it an event: the buttons of those no way out takes now cannot be used."
490
+ global try-buttons: row []
491
+ global try-fields: field "Event fields" "the fields the next event carries: count: 3"
492
+ text small muted "Data"
493
+ global try-data: code ""
494
+ global try-history: column []
495
+ ]
550
496
  global props: column hidden [
551
497
  global face-kind: code ""
552
498
  global face-chain: text small muted ""
@@ -566,5 +512,6 @@ view compose/deep/only [
566
512
 
567
513
  mode-f/value: "Split"
568
514
  props-tab/value: "Options"
515
+ editing-f/value: "Screens"
569
516
  device-f/value: "Desktop"
570
517
  read-files