generated from Cirru/calcit-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compact.cirru
6272 lines (6271 loc) · 291 KB
/
compact.cirru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{} (:package |app)
:configs $ {} (:init-fn |app.server/main!) (:reload-fn |app.server/reload!) (:version |0.9.3)
:modules $ [] |lilac/ |memof/ |recollect/ |cumulo-util.calcit/ |ws-edn.calcit/ |bisection-key/ |respo-markdown.calcit/
:entries $ {}
:client $ {} (:init-fn |app.client/main!) (:reload-fn |app.client/reload!)
:modules $ [] |lilac/ |memof/ |recollect/ |respo.calcit/ |respo-ui.calcit/ |respo-message.calcit/ |cumulo-util.calcit/ |ws-edn.calcit/ |respo-feather.calcit/ |alerts.calcit/ |respo-markdown.calcit/ |bisection-key/
:files $ {}
|app.bookmark $ %{} :FileEntry
:defs $ {}
|%bookmark $ %{} :CodeEntry (:doc |)
:code $ quote
defrecord! %bookmark
:get-focus $ fn (self)
tag-match self
:def ns' def' f
, f
(:ns ns' f) f
:get-ns $ fn (self) (nth self 1)
:is-ns? $ fn (self)
= (nth self 0) :ns
:is-def? $ fn (self)
= (nth self 0) :def
:update-focus $ fn (self updater)
tag-match self
:def ns' def' f
%:: %bookmark :def ns' def' $ updater f
(:ns ns' f)
%:: %bookmark :ns ns' $ updater f
:to-path $ fn (self)
tag-match self
:def ns' def' f
concat ([] :files ns' :defs def' :code)
mapcat
or f $ []
fn (x) ([] :data x)
(:ns ns' f)
concat ([] :files ns' :ns :code)
mapcat
or f $ []
fn (x) ([] :data x)
:preview $ fn (self)
tag-match self
:def ns' def' f
str ns' "\"/" def'
(:ns ns' f) (str ns' "\"/")
|Bookmark $ %{} :CodeEntry (:doc "|constructor for definition bookmarks, write `Bookmark $ :: :def ns' def' f` to initialize")
:code $ quote
defn Bookmark (b)
tag-match b
:def ns' def' f
%:: %bookmark :def ns' def' f
(:ns ns' f) (%:: %bookmark :ns ns' f)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.bookmark)
|app.client $ %{} :FileEntry
:defs $ {}
|*connecting? $ %{} :CodeEntry (:doc |)
:code $ quote (defatom *connecting? false)
|*states $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *states $ {}
:states $ {}
:cursor $ []
|*store $ %{} :CodeEntry (:doc |)
:code $ quote (defatom *store nil)
|connect! $ %{} :CodeEntry (:doc |)
:code $ quote
defn connect! () (js/console.info "\"Connecting...") (reset! *connecting? true)
ws-connect! ws-host $ {}
:on-open $ fn (event) (simulate-login!) (detect-watching!) (heartbeat!)
:on-close $ fn (event) (reset! *store nil) (reset! *connecting? false) (js/console.error "\"Lost connection!")
dispatch! $ :: :states/clear
:on-data $ fn (data)
tag-match data
:patch changes
do
when config/dev? $ js/console.log "\"Changes" changes
reset! *store $ patch-twig @*store changes
_ $ eprintln "\"Unknown op:" data
:class-mapper $ {} (:Expr schema/CirruExpr) (:Leaf schema/CirruLeaf)
|detect-watching! $ %{} :CodeEntry (:doc |)
:code $ quote
defn detect-watching! () $ let
query $ parse-query!
when
some? $ get query "\"watching"
dispatch! $ :: :router/change
:: :watching $ get query "\"watching"
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when
and config/dev? $ not= (nth op 0) :states
js/console.info |Dispatch op
tag-match op
:states cursor new-state
reset! *states $ assoc-in @*states (conj cursor :data) new-state
(:states/clear)
reset! *states $ {}
:states $ {}
:cursor $ []
(:manual-state/abstract)
reset! *states $ updater/abstract @*states
(:manual-state/draft-box)
reset! *states $ updater/draft-box @*states
(:effect/save-files)
do
reset! *states $ updater/clear-editor @*states
send-op! op
(:ir/indent)
do
reset! *states $ updater/clear-editor @*states
send-op! op
(:ir/unindent)
do
reset! *states $ updater/clear-editor @*states
send-op! op
(:ir/reset-files)
do
reset! *states $ updater/clear-editor @*states
send-op! op
_ $ send-op! op
|heartbeat! $ %{} :CodeEntry (:doc |)
:code $ quote
defn heartbeat! () $ flipped js/setTimeout 3000
fn () $ if (ws-connected?)
do
ws-send! $ :: :ping
heartbeat!
println "\"Disabled heartbeat since connection lost."
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! ()
if config/dev? (load-console-formatter!) (disable-list-structure-check!)
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
; reset! *changes-logger $ fn (global-element element changes) (println "\"Changes:" changes)
render-app!
connect!
add-watch *store :changes $ fn (store prev) (render-app!)
if
= :editor $ get-in @*store ([] :router 0)
focus!
add-watch *states :changes $ fn (states prev) (render-app!)
js/window.addEventListener "\"keydown" $ fn (event)
on-window-keydown event dispatch! $ :router @*store
js/window.addEventListener "\"focus" $ fn (event) (retry-connect!)
js/window.addEventListener "\"visibilitychange" $ fn (event)
when (= "\"visible" js/document.visibilityState) (retry-connect!)
println "\"App started!"
|mount-target $ %{} :CodeEntry (:doc |)
:code $ quote
def mount-target $ js/document.querySelector |.app
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (nil? build-errors)
do (clear-cache!) (render-app!) (remove-watch *states :changes) (remove-watch *store :changes)
add-watch *states :changes $ fn (states prev) (render-app!)
add-watch *store :changes $ fn (store prev) (render-app!)
if
= :editor $ get-in @*store ([] :router 0)
focus!
println "|Code updated."
tip! "\"ok~" nil
tip! "\"error" build-errors
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! () $ render! mount-target (comp-container @*states @*store) dispatch!
|retry-connect! $ %{} :CodeEntry (:doc |)
:code $ quote
defn retry-connect! () $ if
and (nil? @*store) (not @*connecting?)
connect!
|send-op! $ %{} :CodeEntry (:doc |)
:code $ quote
defn send-op! (op) (ws-send! op)
|simulate-login! $ %{} :CodeEntry (:doc |)
:code $ quote
defn simulate-login! () $ let
raw $ js/window.localStorage.getItem (:storage-key config/site)
if (some? raw)
do $ dispatch!
:: :user/log-in $ parse-cirru-edn raw
do $ println "|Found no storage."
:ns $ %{} :CodeEntry (:doc "|browser side main file")
:code $ quote
ns app.client $ :require
respo.core :refer $ render! clear-cache! *changes-logger
app.comp.container :refer $ comp-container
app.client-util :refer $ ws-host parse-query!
app.util.dom :refer $ focus!
app.util.shortcuts :refer $ on-window-keydown
app.client-updater :as updater
ws-edn.client :refer $ ws-connect! ws-send! ws-connected?
recollect.patch :refer $ patch-twig
app.config :as config
"\"bottom-tip" :default tip!
"\"./calcit.build-errors" :default build-errors
app.schema :as schema
"\"@calcit/procs" :refer $ disable-list-structure-check!
|app.client-updater $ %{} :FileEntry
:defs $ {}
|abstract $ %{} :CodeEntry (:doc |)
:code $ quote
defn abstract (states)
assoc-in states ([] :editor :data :abstract?) true
|clear-editor $ %{} :CodeEntry (:doc |)
:code $ quote
defn clear-editor (states)
update states :editor $ fn (scope)
-> scope .to-list
filter $ fn (pair)
let[] (k v) pair $ tag? k
pairs-map
|draft-box $ %{} :CodeEntry (:doc |)
:code $ quote
defn draft-box (states)
assoc-in states ([] :editor :data :draft-box?) true
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.client-updater)
|app.client-util $ %{} :FileEntry
:defs $ {}
|coord-contains? $ %{} :CodeEntry (:doc |)
:code $ quote
defn coord-contains? (xs ys)
if (empty? ys) true $ if (empty? xs) false
if
= (first xs) (first ys)
recur (rest xs) (rest ys)
, false
|expr-many-items? $ %{} :CodeEntry (:doc |)
:code $ quote
defn expr-many-items? (x size)
if (expr? x)
let
d $ :data x
or
> (count d) size
any? (vals d) expr?
, false
|expr? $ %{} :CodeEntry (:doc "|a function to detect expression,\nan expression is represented with a record with `CirruExpr`\n")
:code $ quote
defn expr? (x) (&record:matches? schema/CirruExpr x)
|leaf? $ %{} :CodeEntry (:doc |)
:code $ quote
defn leaf? (x) (&record:matches? schema/CirruLeaf x)
|parse-query! $ %{} :CodeEntry (:doc |)
:code $ quote
defn parse-query! () $ let
url-obj $ url-parse js/location.href true
to-calcit-data $ .-query url-obj
|ws-host $ %{} :CodeEntry (:doc |)
:code $ quote
def ws-host $ if
and (exists? js/location)
not $ blank? (.-search js/location)
let
query $ parse-query!
println "|Loading from url" query
str |ws://
or (get query "\"host") |localhost
, |: $ or (get query "\"port") (:port schema/configs)
, |ws://localhost:6001
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.client-util $ :require ([] app.config :as config) ([] "\"url-parse" :default url-parse) (app.schema :as schema)
|app.comp.about $ %{} :FileEntry
:defs $ {}
|comp-about $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-about () $ div
{} $ :class-name (str-spaced css/global css/fullscreen css/column)
div
{} $ :class-name (str-spaced css/flex css/center)
img $ {} (:src "\"//cdn.tiye.me/logo/cirru.png")
:style $ {} (:width 64) (:height 64) (:border-radius "\"8px")
=< nil 16
<> "\"No connection to server..." $ {} (:font-family "|Josefin Sans") (:font-weight 300) (:font-size 24)
:color $ hsl 0 80 60
div
{} $ :style
{} $ :color (hsl 0 0 80)
<> "\"Get editor server running with:"
pre $ {} (:innerHTML install-commands) (:class-name "\"copy-commands")
:style $ {} (:cursor :pointer) (:padding "\"0 8px")
:title "\"Click to copy."
:on-click $ fn (e d!)
copy-silently! $ .replace install-commands "\"$ " "\""
div
{} (:class-name css/center)
:style $ {} (:padding "\"8px 8px")
:color $ hsl 0 0 50
comp-md-block "\"Calcit Editor is a syntax tree editor of [Cirru Project](http://cirru.org). Read more at [Calcit Editor](https://github.com/calcit-lang/editor).\n" $ {}
|install-commands $ %{} :CodeEntry (:doc "|copy the commands to use")
:code $ quote (def install-commands "\"$ npm install -g @calcit/editor\n$ ct\n")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.about $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp <> span div pre input button img a br
respo.css :refer $ defstyle
respo.comp.inspect :refer $ comp-inspect
respo.comp.space :refer $ =<
app.style :as style
respo-md.comp.md :refer $ comp-md-block
app.util.dom :refer $ copy-silently!
|app.comp.abstract $ %{} :FileEntry
:defs $ {}
|comp-abstract $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-abstract (states close-modal!)
comp-modal close-modal! $ let
cursor $ :cursor states
state $ or (:data states) |style-
div ({})
input $ {}
:class-name $ str-spaced style/input |el-abstract
:value state
:on-input $ fn (e d!)
d! cursor $ :value e
:on-keydown $ fn (e d!)
cond
= keycode/enter $ :key-code e
if
not $ blank? state
do (d! :analyze/abstract-def state) (d! cursor nil) (close-modal! d!)
(= (:keycode e) keycode/escape)
close-modal! d!
=< nil 8
button $ {} (:class-name style/button) (:inner-text |Submit)
:on-click $ fn (e d!)
if
not $ blank? state
do (d! :analyze/abstract-def state) (d! cursor nil) (close-modal! d!)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.abstract $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo.core :refer $ defcomp <> span div pre input button a
respo.comp.inspect :refer $ comp-inspect
respo.comp.space :refer $ =<
app.style :as style
app.comp.modal :refer $ comp-modal
app.keycode :as keycode
|app.comp.bookmark $ %{} :FileEntry
:defs $ {}
|comp-bookmark $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-bookmark (bookmark idx selected?)
div
{}
:class-name $ str |stack-bookmark (if selected? "\" selected-bookmark" "\"")
:draggable true
:on-click $ on-pick bookmark idx
:on-dragstart $ fn (e d!)
-> e :event .-dataTransfer $ .!setData "\"id" idx
:on-drop $ fn (e d!)
let
target-idx $ js/parseInt
-> e :event .-dataTransfer $ .!getData "\"id"
when (not= target-idx idx)
d! :writer/move-order $ {} (:from target-idx) (:to idx)
:on-dragover $ fn (e d!) (-> e :event .!preventDefault)
tag-match bookmark
:ns the-ns focus
div
{} (:class-name css-bookmark)
:style $ {} (:padding "\"8px")
<> "\"ns" style-kind
span $ {} (:inner-text the-ns)
:class-name $ str-spaced css/font-normal
:style $ if selected? style-highlight
(:def the-ns the-def focus)
div
{} $ :class-name css-bookmark
div ({})
span $ {} (:inner-text the-def)
:class-name $ str-spaced css/font-normal
:style $ if selected? style-highlight
div
{} $ :class-name css/row-middle
=< 4 nil
<> the-ns style-minor
|css-bookmark $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-bookmark $ {}
"\"$0" $ {} (:line-height |1.2em) (:padding "|4px 8px") (:cursor :pointer) (:position :relative)
:color $ hsl 0 0 70
:white-space :nowrap
|on-pick $ %{} :CodeEntry (:doc |)
:code $ quote
defn on-pick (bookmark idx)
fn (e d!)
let
event $ :original-event e
shift? $ .-shiftKey event
alt? $ .-altKey event
meta? $ .-metaKey event
cond
meta? $ d! :writer/collapse idx
alt? $ d! :writer/remove-idx idx
true $ d! :writer/point-to idx
|style-highlight $ %{} :CodeEntry (:doc |)
:code $ quote
def style-highlight $ {}
:color $ hsl 0 0 100
|style-kind $ %{} :CodeEntry (:doc |)
:code $ quote
def style-kind $ {}
:color $ hsl 340 80 60
:font-family ui/font-normal
:font-size 12
:margin-right 4
:vertical-align :middle
|style-main $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-main $ {}
"\"&" $ {} (:vertical-align :middle)
:color $ hsl 0 0 70
|style-minor $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-minor $ {}
"\"&" $ {}
:color $ hsl 0 0 40
:font-size 12
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.bookmark $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.css :refer $ defstyle
respo.core :refer $ defcomp <> span div a
respo.comp.space :refer $ =<
|app.comp.changed-files $ %{} :FileEntry
:defs $ {}
|comp-changed-files $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-changed-files (states changed-files)
div
{} $ :style style-column
<> |Changes style/title
list-> ({})
-> changed-files (.to-list)
map $ fn (pair)
let[] (k info) pair $ [] k (comp-changed-info info k)
if (empty? changed-files)
div
{} $ :style style-nothing
<> "|No changes"
div ({})
a $ {} (:inner-text |Save) (:class-name style/button)
:on-click $ fn (e d!) (d! :effect/save-files nil)
a $ {} (:inner-text |Reset) (:class-name style/button)
:on-click $ fn (e d!) (d! :ir/reset-files nil)
d! $ :: :states/clear
|style-column $ %{} :CodeEntry (:doc |)
:code $ quote
def style-column $ {} (:overflow :auto) (:padding-top 24) (:padding-bottom 120)
|style-nothing $ %{} :CodeEntry (:doc |)
:code $ quote
def style-nothing $ {} (:font-family "|Josefin Sans")
:color $ hsl 0 0 100 0.5
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.changed-files $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo.core :refer $ defcomp list-> <> span div pre input button a
respo.comp.space :refer $ =<
app.client-util :as util
app.style :as style
app.comp.changed-info :refer $ comp-changed-info
|app.comp.changed-info $ %{} :FileEntry
:defs $ {}
|comp-changed-info $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-changed-info (info ns-text)
div
{} $ :style style-info
div ({}) (<> ns-text) (=< 8 nil)
span
{} $ :class-name "\"is-minor"
comp-icon :corner-up-left style-reset $ fn (e d!) (d! :ir/reset-ns ns-text)
d! $ :: :states/clear
=< 24 nil
if
not= :same $ :ns info
render-status ns-text :ns $ :ns info
div
{} (:class-name css/row-parted)
:style $ {} (:align-items :flex-end)
list->
{} $ :style style-defs
-> (:defs info) (.to-list)
map $ fn (entry)
let-sugar
[] def-text status
, entry
[] def-text $ div ({}) (render-status ns-text def-text status)
div ({})
comp-icon :save style-reset $ fn (e d!) (d! :effect/save-ns ns-text)
|on-preview $ %{} :CodeEntry (:doc |)
:code $ quote
defn on-preview (ns-text kind status)
fn (e d!) (; println |peek ns-text kind status)
d! :writer/select $ case-default kind (:: :def ns-text kind)
:ns $ :: :ns ns-text
|on-reset-def $ %{} :CodeEntry (:doc |)
:code $ quote
defn on-reset-def (ns-text kind)
fn (e d!)
d! :ir/reset-at $ case-default kind (:: :def ns-text kind)
:ns $ :: :ns ns-text
d! $ :: :states/clear
|render-status $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-status (ns-text kind status)
span
{} (:style style-status-card)
:title $ str "|Browse " kind
:on-click $ on-preview ns-text kind status
<> kind
=< 8 nil
<> (turn-string status) style-status
=< 4 nil
span
{} $ :class-name "\"is-minor"
comp-icon :corner-up-left style-reset $ on-reset-def ns-text kind
|style-defs $ %{} :CodeEntry (:doc |)
:code $ quote
def style-defs $ {} (:padding-left 16)
|style-info $ %{} :CodeEntry (:doc |)
:code $ quote
def style-info $ {}
:background-color $ hsl 0 0 100 0.1
:padding 8
:margin-bottom 8
|style-reset $ %{} :CodeEntry (:doc |)
:code $ quote
def style-reset $ {} (:text-decoration :underline) (:font-size 12)
:color $ hsl 220 60 80 0.6
:cursor :pointer
|style-status $ %{} :CodeEntry (:doc |)
:code $ quote
def style-status $ {} (:font-size 12) (:font-family "|Josefin Sans")
:color $ hsl 160 70 40
|style-status-card $ %{} :CodeEntry (:doc |)
:code $ quote
def style-status-card $ {} (:cursor :pointer)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.changed-info $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp list-> >> <> span div pre input button a
respo.comp.space :refer $ =<
app.style :as style
feather.core :refer $ comp-icon
|app.comp.configs $ %{} :FileEntry
:defs $ {}
|comp-configs $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-configs (states configs entries)
let
version-plugin $ use-prompt (>> states :version)
{} (:text "\"Set a version:")
:initial $ :version configs
:placeholder "\"a version number..."
:input-class css/font-code
modules-plugin $ use-prompt (>> states :modules)
{} (:text "\"Add modules:")
:initial $ .join-str (:modules configs) "\" "
:placeholder "\"module/compact.cirru etc."
:input-class css/font-code
:multiline? true
init-fn-plugin $ use-prompt (>> states :init-fn)
{} (:text "\"Set a init-fn:")
:initial $ :init-fn configs
:placeholder "\"a path..."
:input-class css/font-code
reload-fn-plugin $ use-prompt (>> states :reload-fn)
{} (:text "\"Set a reload-fn:")
:initial $ :reload-fn configs
:placeholder "\"a path..."
:input-class css/font-code
div
{}
:class-name $ str-spaced css/expand css/column
:style $ {} (:padding "\"40px 16px 0 16px")
=< nil 8
div ({}) (render-label "\"Version:") (=< 8 nil)
span
{} $ :on-click
fn (e d!)
.show version-plugin d! $ fn (text)
d! :configs/update $ {} (:version text)
render-field $ :version configs
div
{} $ :class-name css/row
render-label "\"Modules:"
=< 8 nil
span
{} $ :on-click
fn (e d!)
.show modules-plugin d! $ fn (text)
d! :configs/update $ {}
:modules $ filter-not
split (trim text) "\" "
, blank?
render-field $ -> (:modules configs) (or "\"") (join-str "\" ")
div ({}) (render-label "\"init-fn:") (=< 8 nil)
span
{} $ :on-click
fn (e d!)
.show init-fn-plugin d! $ fn (text)
d! :configs/update $ {} (:init-fn text)
render-field $ :init-fn configs
div ({}) (render-label "\"reload-fn:") (=< 8 nil)
span
{} $ :on-click
fn (e d!)
.show reload-fn-plugin d! $ fn (text)
d! :configs/update $ {} (:reload-fn text)
render-field $ :reload-fn configs
pre
{} $ :style
merge $ {} (:max-width "\"100%") (:overflow :auto)
:color $ hsl 0 0 60
code $ {}
:innerHTML $ trim (format-cirru-edn configs)
comp-entries states entries
.render version-plugin
.render modules-plugin
.render init-fn-plugin
.render reload-fn-plugin
|comp-entries $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-entries (states entries)
let
code-plugin $ use-prompt (>> states :entries-code)
{} (:text "\"Update entries:")
:initial $ format-cirru-edn entries
:placeholder "\"{} ..."
:input-style $ {} (:font-family ui/font-code)
:multiline? true
div ({})
pre $ {}
:style $ merge
{} (:max-width "\"100%") (:overflow :auto)
:color $ hsl 0 0 60
:inner-text $ format-cirru-edn entries
button $ {} (:class-name style/button) (:inner-text "\"Edit")
:on-click $ fn (e d!)
.show code-plugin d! $ fn (text)
d! :configs/update-entries $ [] :reset (parse-cirru-edn text)
.render code-plugin
|render-field $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-field (v)
<>
if (blank? v) "\"-" v
str-spaced css/font-code style-value
|render-label $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-label (title) (<> title css/font-fancy)
|style-value $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-value $ {}
"\"&" $ {} (:cursor :pointer)
:color $ hsl 200 90 80
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.configs $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp >> <> span div a pre code button
respo.comp.space :refer $ =<
cirru-edn.core :as cirru-edn
respo-alerts.core :refer $ use-prompt
app.style :as style
respo.css :refer $ defstyle
|app.comp.container $ %{} :FileEntry
:defs $ {}
|comp-container $ %{} :CodeEntry (:doc "|respo UI main entry")
:code $ quote
defcomp comp-container (states store)
let
state $ :data states
session $ :session store
writer $ :writer session
router $ :router store
theme $ get-in store ([] :user :theme)
picker-mode? $ some? (:picker-mode writer)
if (nil? store) (comp-about)
div
{} $ :class-name (str-spaced css/global css/fullscreen css/column style-container)
if (not picker-mode?)
comp-header (>> states :header)
if (tuple? router) (nth router 0)
:logged-in? store
:stats store
div
{} $ :class-name (str-spaced css/row css/expand)
if (:logged-in? store)
tag-match router
:profile d
comp-profile (>> states :profile) (:user store) (:id session) d
(:files d)
comp-page-files (>> states :files) (:selected-ns writer) d
(:graph d)
comp-deps-graph (>> states :graph) (:package d) (:configs d) (:entries d) (:deps-dict d) (:writer d)
(:editor d)
comp-page-editor (>> states :editor) (:stack writer) d (:pointer writer) picker-mode? theme
(:search d)
comp-search (>> states :search) d
(:watching d)
comp-watching (>> states :watching) d $ :theme session
(:configs d)
comp-configs (>> states :configs) (:configs d) (:entries d)
_ $ div ({})
<> $ str "\"404 page: " (to-lispy-string router)
if (some? router)
tag-match router
:watcher d
comp-watching (>> states :watching) d $ :theme session
_ $ comp-login (>> states :login)
comp-login $ >> states :login
when dev? $ comp-inspect |Session store style-inspector
; when dev? $ comp-inspect "|Router data" states
merge style-inspector $ {} (:left 100)
comp-messages $ get-in store ([] :session :notifications)
|style-container $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-container $ {}
"\"&" $ {} (:background-color :black) (:color :white)
|style-inspector $ %{} :CodeEntry (:doc |)
:code $ quote
def style-inspector $ {} (:bottom 40) (:left 0) (:max-width |100%)
:background-color $ hsl 0 0 50
:color :black
:opacity 1
:z-index 100
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp >> <> div span
respo.css :refer $ defstyle
respo.comp.inspect :refer $ comp-inspect
respo.comp.space :refer $ =<
app.comp.header :refer $ comp-header
app.comp.profile :refer $ comp-profile
app.comp.login :refer $ comp-login
app.comp.page-files :refer $ comp-page-files
app.comp.page-editor :refer $ comp-page-editor
app.comp.page-members :refer $ comp-page-members
app.comp.search :refer $ comp-search
app.comp.messages :refer $ comp-messages
app.comp.watching :refer $ comp-watching
app.comp.about :refer $ comp-about
app.comp.configs :refer $ comp-configs
app.config :refer $ dev?
app.comp.about :as about
app.comp.graph :refer $ comp-deps-graph
|app.comp.draft-box $ %{} :FileEntry
:defs $ {}
|comp-draft-box $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-draft-box (states expr focus close-modal!)
let
cursor $ :cursor states
comp-modal
fn (d!) (d! cursor nil) (close-modal! d!)
let
path $ -> focus
mapcat $ fn (x) ([] :data x)
node $ get-in expr path
missing? $ nil? node
an-expr? $ expr? node
if missing?
span $ {} (:class-name css-wrong) (:inner-text "|Does not edit expression!")
:on-click $ fn (e d!) (close-modal! d!)
let
state $ or (:data states)
if an-expr?
format-cirru $ [] (tree->cirru node)
:text node
div
{} $ :class-name css/column
div
{} $ :style style-original
if an-expr? (<> "|Cirru Mode" style-mode)
textarea $ {} (:spellcheck false) (:class-name css-text)
:value $ if an-expr?
format-cirru $ tree->cirru node
:text node
=< nil 8
textarea $ {}
:class-name $ str-spaced |el-draft-box css-draft-area
:value state
:on-input $ fn (e d!)
d! cursor $ :value e
:on-keydown $ fn (e d!)
cond
= keycode/escape $ :keycode e
close-modal! d!
(and (= keycode/s (:keycode e)) (.-metaKey (:event e)))
do
.!preventDefault $ :event e
if expr?
d! :ir/draft-expr $ parse-cirru-edn state
d! :ir/update-leaf $ {} (:text state)
:at $ now!
d! cursor nil
close-modal! d!
=< nil 8
div
{} $ :class-name (str-spaced css/row style-toolbar)
button $ {} (:class-name style/button) (:inner-text |Apply)
:on-click $ on-submit an-expr? state cursor close-modal! false
button $ {} (:class-name style/button) (:inner-text |Submit)
:on-click $ on-submit an-expr? state cursor close-modal! true
|css-draft-area $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-draft-area $ {}
"\"$0" $ {}
:background-color $ hsl 0 0 100 0.2
:min-height 320
:line-height |1.6em
:min-width 960
:color :white
:font-family ui/font-code
:font-size 14
:outline :none
:border :none
:padding 8
:min-width 800
:vertical-align :top
|css-text $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-text $ {}
"\"$0" $ {} (:font-family ui/font-code) (:color :white) (:padding "|8px 8px") (:height 60) (:display :block) (:width |100%)
:background-color $ hsl 0 0 100 0.2
:outline :none
:border :none
:font-size 14
:padding 8
:min-width 800
:vetical-align :top
|css-wrong $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle css-wrong $ {}
"\"$0" $ {} (:color :red) (:font-size 24) (:font-weight 100) (:font-family "|Josefin Sans") (:cursor :pointer)
|on-submit $ %{} :CodeEntry (:doc |)
:code $ quote
defn on-submit (expr? text cursor close-modal! close?)
fn (e d!)
if expr?
d! :ir/draft-expr $ first (parse-cirru-list text)
d! :ir/update-leaf $ {} (:text text)
:at $ now!
if close? $ do (d! cursor nil) (close-modal! d!)
|style-mode $ %{} :CodeEntry (:doc |)
:code $ quote
def style-mode $ {}
:color $ hsl 0 0 100 0.6
:background-color $ hsl 300 50 50 0.6
:padding "|0 8px"
:font-size 12
:border-radius |4px
|style-original $ %{} :CodeEntry (:doc |)
:code $ quote
def style-original $ {} (:max-height 240) (:overflow :auto)
|style-toolbar $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-toolbar $ {}
"\"&" $ {} (:justify-content :flex-end)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.draft-box $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp <> span div textarea pre button a
respo.css :refer $ defstyle
respo.comp.space :refer $ =<
app.comp.modal :refer $ comp-modal
app.style :as style
app.util :refer $ tree->cirru now! expr?
app.keycode :as keycode
|app.comp.expr $ %{} :FileEntry
:defs $ {}
|comp-expr $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-expr (states expr focus coord others tail? layout-mode readonly? picker-mode? theme depth)
let
focused? $ = focus coord
focus-in? $ coord-contains? focus coord
first-id $ get-min-key (:data expr)
last-id $ get-max-key (:data expr)
sorted-children $ -> (:data expr) (.to-list) (.sort-by first)
list->
{} (:tab-index 0)
:class-name $ str-spaced "\"comp-expr" style-expr (base-style-expr theme) (if focused? |cirru-focused |)
:style $ decide-expr-theme expr (includes? others coord) focused? focus-in? tail? layout-mode (count coord) depth theme
:on $ if readonly?
{} $ :click
fn (e d!)
if picker-mode? $ do
.!preventDefault $ :event e
d! :writer/pick-node $ tree->cirru expr
{}
:keydown $ on-keydown coord expr picker-mode?
:click $ fn (e d!)
if picker-mode?
do
.!preventDefault $ :event e
d! :writer/pick-node $ tree->cirru expr
d! :writer/focus coord
loop
result $ []
children sorted-children
prev-mode :inline
if (empty? children) result $ let-sugar
[] k child
first children
child-coord $ conj coord k
partial-others $ -> others
filter $ fn (x) (coord-contains? x child-coord)
cursor-key k
mode $ if (leaf? child) :inline
if (expr-many-items? child 6) :block $ case-default prev-mode :block (:inline :inline-block)
:inline-block $ if (expr-many-items? child 2) :block :inline-block
if (nil? cursor-key) (js/console.warn "|[Editor] missing cursor key" k child)
recur
conj result $ [] k
if (&record:matches? child CirruLeaf)
comp-leaf (>> states cursor-key) child focus child-coord (includes? partial-others child-coord) (= first-id k) readonly? picker-mode? theme
comp-expr (>> states cursor-key) child focus child-coord partial-others (= last-id k) mode readonly? picker-mode? theme $ inc depth
rest children
, mode
|on-keydown $ %{} :CodeEntry (:doc |)
:code $ quote
defn on-keydown (coord expr picker-mode?)
fn (e d!)
let
event $ :original-event e
shift? $ .-shiftKey event
meta? $ or (.-metaKey event) (.-ctrlKey event)
code $ :key-code e
cond
and meta? $ = code keycode/enter
d! (if shift? :ir/append-leaf :ir/prepend-leaf) nil
(and meta? (= code keycode/enter))
d! :ir/prepend-leaf nil
(= code keycode/enter)
if (empty? coord) (d! :ir/prepend-leaf nil)
d! (if shift? :ir/expr-before :ir/expr-after) nil
(= code keycode/backspace) (d! :ir/delete-node nil)
(= code keycode/space)
do
d! (if shift? :ir/leaf-before :ir/leaf-after) nil
.!preventDefault event
(= code keycode/tab)
do
d! $ :: (if shift? :ir/unindent :ir/indent)
.!preventDefault event
(= code keycode/up)
do
if
not $ empty? coord
d! :writer/go-up nil
.!preventDefault event
(= code keycode/down)
do
d! :writer/go-down $ {} (:tail? shift?)
.!preventDefault event
(= code keycode/left)
do (d! :writer/go-left nil) (.!preventDefault event)
(= code keycode/right)
do (d! :writer/go-right nil) (.!preventDefault event)
(and meta? (= code keycode/c))
do-copy-logics! d!
format-cirru $ [] (tree->cirru expr)
, "\"Copied!"
(and meta? (= code keycode/x))
do
do-copy-logics! d!
format-cirru $ [] (tree->cirru expr)
, "\"Copied!"
d! :ir/delete-node nil
(and meta? (= code keycode/v))