Repository navigation
Expand file tree
/
Copy pathcalcit.cirru
More file actions
512 lines (511 loc) · 24.7 KB
/
Copy pathcalcit.cirru
File metadata and controls
512 lines (511 loc) · 24.7 KB
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
{}
:about "|Machine-generated snapshot. Do not edit directly — changes will be overwritten. Use `calcit query` to inspect and `calcit edit`/`calcit tree` to modify. Run `calcit docs agents --contract` before mutations; use `--full` for first orientation or changed contract digest. Manual edits must follow format and schema conventions, then run `calcit edit format`."
:package |app
:entries $ {} $ :default
{} (:description |) (:init-fn 'app.main/main!) (:mode :js) (:reload-fn 'app.main/reload!) (:target :browser)
:feature-policy $ {}
:modules $ [] |respo.calcit/ |respo-ui.calcit/ |respo-markdown.calcit/ |reel.calcit/ |js-ffi/
:type-slots $ {} $ :dispatch-op 'app.schema/Action
:files $ {}
'app.comp.container $ %{} 'FileEntry
:defs $ {}
'comp-container $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-container (reel on-control)
let
store $ :store reel
states $ :states store
div
{} $ :style $ .merge ui/global
{} (:background-color |white) (:font-size |16px)
div
{} $ :style $ {} (:background-image "|linear-gradient(to right, #0f2242, #2452a1)")
comp-header
div
{} $ :style $ {} (:color |white) (:font-weight |300) (:font-family ui/font-fancy) (:font-size |20px) (:margin |auto) (:text-align |center) (:max-width |800px) (:padding "|0 16px")
comp-md-block (inline |clojure-is.md)
{} $ :class-name "|content on-dark"
comp-showcase $ :case-idx store
respo.comp.space/space-y 32
comp-tools
comp-resources
respo.comp.space/space-y 16
comp-footer
if dev?
Some $ comp-typed-reel (>> states :reel) reel ({}) on-control
, None
:examples $ []
:schema $ quote $ Fn (reel.typed/State app.schema/Action app.schema/Store)
Fn reel.typed/Control (-> Unit) (:features :io :state)
-> respo.schema/Component
:features :state
'comp-footer $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-footer ()
div
{} $ :style $ {} (:background-color |#292d2e) (:height |200px) (:padding |16px)
div
{} $ :style $ {} (:max-width |800px) (:margin |auto)
a
{}
:style $ {}
:color $ hsl 240 80 80
:text-decoration |none
:href |https://github.com/clojure-china/clojure-script.org
:target |_blank
<> "|Site built with Calcit & Respo."
:examples $ []
:schema $ quote $ Fn (-> respo.schema/Component)
'comp-header $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-header ()
div
{} $ :style $ {} (:padding |16px)
div
{} $ :style $ .merge ui/row-parted
{} (:max-width |800px) (:margin |auto)
div
{}
:style $ .merge ui/row-center $ {} (:cursor |pointer)
:on-click $ fn (e d!)
hint-fn $ Fn respo.schema/RespoEvent
Fn app.schema/Action $ -> Unit
-> Unit
d! $ app.schema/Action :pick-case $ decode-map-as (rand-int 10) Number
div $ {} $ :style
{}
:background-image $ str "|url(https://cdn.tiye.me/logo/cljs.png)"
:width |40px
:height |40px
:background-position "|center center"
:background-size |cover
respo.comp.space/space-x 8
a $ {} (:href |https://clojurescript.org/) (:inner-text "|(Unofficial)")
:style $ {}
:color $ hsl 240 80 80
:font-family ui/font-fancy
:text-decoration |none
div $ {}
:examples $ []
:schema $ quote $ Fn (-> respo.schema/Component)
'comp-resources $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-resources ()
div
{} $ :style $ {} (:max-width |800px) (:margin |auto) (:padding |16px)
comp-md-block (inline |resource.md)
{} $ :class-name |content
:examples $ []
:schema $ quote $ Fn (-> respo.schema/Component) (:features :state)
'comp-tool-card $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-tool-card (info)
div
{} $ :style $ .merge ui/row-parted
{}
:border $ str "|1px solid " $ hsl 0 0 90
:padding "|8px 16px"
:border-radius |8px
:margin-top |16px
div ({})
div ({})
a
{}
:href $ :url info
:target |_blank
:style $ {} (:text-decoration |none) (:font-size |16px)
:color $ hsl 240 90 70
:line-height |1.4em
:font-family ui/font-fancy
<> $ :name info
div ({})
<> $ :description info
match (:logo info)
(:some logo)
Some $ div $ {}
:style $ {}
:background-image $ str "|url(" logo "|)"
:background-size |cover
:background-position |center
:width |40px
:height |40px
(:none) None
:examples $ []
:schema $ quote $ Fn ToolInfo (-> respo.schema/Component)
'comp-tools $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-tools ()
div
{} $ :style $ {} (:max-width |800px) (:margin |auto) (:padding |16px)
comp-md-block (inline |quote.md)
{} $ :class-name |content
div
{} $ :style $ {} (:margin-top |48px)
<> |Learning $ {} (:font-size |24px) (:font-weight |100) (:font-family ui/font-normal) (:vertical-align |middle)
respo.comp.space/space-x 16
a
{}
:style $ .merge ui/button $ {} (:vertical-align |middle) (:border-radius |16px) (:padding "|0 16px") (:font-family ui/font-fancy) (:font-size |20px) (:text-decoration |none) (:line-height |32px) (:display |inline-block)
:href |http://clojurescript.io/
:target |_blank
<> "|Get an online REPL"
comp-md-block (inline |learning.md)
{} $ :class-name |content
div
{} $ :style $ {} (:width |auto)
comp-tool-card $ ToolInfo :name |shadow-cljs :logo (Some |http://cdn.tiye.me/logo/shadow-cljs.png) :url |http://shadow-cljs.org :description "|ClojureScript compilation made easy."
comp-tool-card $ ToolInfo :name |figwheel-main :logo None :url |https://figwheel.org :description "|Figwheel Main builds your ClojureScript code and hot loads it as you are coding!"
:examples $ []
:schema $ quote $ Fn (-> respo.schema/Component) (:features :state)
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.comp.container
:require
respo-ui.core :refer $ hsl
respo-ui.core :as ui
respo.core :refer $ defcomp >> <> div button textarea span a
reel.comp.reel :refer $ comp-typed-reel
respo-md.comp.md :refer $ comp-md comp-md-block
app.config :refer $ dev?
app.util :refer $ highlighter inline
app.comp.showcase :refer $ comp-showcase
|@calcit/std :refer $ rand-int
app.schema :refer $ ToolInfo
'app.comp.showcase $ %{} 'FileEntry
:defs $ {}
'comp-showcase $ %{} 'CodeEntry (:doc |)
:code $ quote $ defcomp comp-showcase (case-idx)
let
showcase $ match (showcases .get case-idx)
(:some item) item
(:none) (raise "|Unknown showcase index")
div
{} (:class-name |showcase)
:style $ .merge ui/center $ {} (:padding |16px) (:min-height |320px) (:overflow |auto) (:padding |16px)
div ({})
<> (:text showcase)
{} (:color |white) (:font-size |16px)
respo.comp.space/space-x 16
a $ {}
:href $ :url showcase
:target |_blank
:style $ {}
:color $ hsl 240 80 80
:text-decoration |none
:font-family ui/font-fancy
:inner-text |Link
comp-md-block
str "|```clojure" &newline (:code showcase) &newline "|```"
{}
:style $ {} (:background-color |transparent) (:font-family ui/font-code) (:color |white) (:padding |8px) (:margin |auto)
:highlight highlighter
:examples $ []
:schema $ quote $ Fn Number (-> respo.schema/Component) (:features :state)
'showcases $ %{} 'CodeEntry (:doc |)
:code $ quote $ def showcases
{}
0 $ Showcase :code (inline |thread-macro.cljs) :text "|Thread macros" :url |https://clojure.org/guides/threading_macros
1 $ Showcase :code (inline |destructuring.cljs) :text |Destructuring :url |https://gist.github.com/john2x/e1dca953548bfdfb9844
2 $ Showcase :code (inline |inter-op.cljs) :text |InterOp :url |http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/
3 $ Showcase :code (inline |transducer.cljs) :text |Transducers :url |https://stackoverflow.com/a/26322910/883571
4 $ Showcase :code (inline |reagent.cljs) :text |Reagent :url |http://reagent-project.github.io/
5 $ Showcase :code (inline |js-deps.cljs) :text "|JS Dependencies" :url |https://code.thheller.com/blog/shadow-cljs/2017/11/10/js-dependencies-in-practice.html
6 $ Showcase :code (inline |nodejs.cljs) :text "|Node.js Server" :url |https://gist.github.com/semperos/83696c0ac168eb03ab1d
7 $ Showcase :code (inline |data.cljs) :text "|Data manipulation" :url |https://stackoverflow.com/a/38754874/883571
8 $ Showcase :code (inline |atom.cljs) :text |Atom :url |https://clojuredocs.org/clojure.core/atom
9 $ Showcase :code (inline |edn.cljs) :text |EDN :url |https://learnxinyminutes.com/docs/edn/
:examples $ []
:schema $ quote $ Map Number Showcase
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.comp.showcase
:require
respo-ui.core :refer $ hsl
respo-ui.core :as ui
respo.core :refer $ defcomp cursor-> action-> mutation-> <> div button textarea span a
respo-md.comp.md :refer $ comp-md comp-md-block
app.config :refer $ dev?
app.util :refer $ highlighter inline
app.schema :refer $ Showcase
'app.config $ %{} 'FileEntry
:defs $ {}
'Site $ %{} 'CodeEntry (:doc |)
:code $ quote $ defstruct Site (:dev-ui String) (:release-ui String) (:cdn-url String) (:title String) (:icon String) (:storage-key String)
:examples $ []
:schema $ quote StructDef
'dev? $ %{} 'CodeEntry (:doc |)
:code $ quote $ def dev?
= |dev $ .unwrap-or (get-env |mode) |release
:examples $ []
:schema $ quote Bool
'site $ %{} 'CodeEntry (:doc |)
:code $ quote $ def site
Site :dev-ui |http://localhost:8100/main.css :release-ui |http://cdn.tiye.me/favored-fonts/main.css :cdn-url |http://cdn.tiye.me/clojure-script-org/ :title "|ClojureScript, beginners' home page" :icon |http://cdn.tiye.me/logo/cljs.png :storage-key |clojure-script.org
:examples $ []
:schema $ quote Site
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.config
'app.main $ %{} 'FileEntry
:defs $ {}
'*reel $ %{} 'CodeEntry (:doc |)
:code $ quote $ defref *reel (typed-reel/new-reel schema/store)
:examples $ []
:schema $ quote $ Ref (reel.typed/State schema/Action schema/Store)
'dispatch! $ %{} 'CodeEntry (:doc "|Dispatches a typed application action.")
:code $ quote $ defn dispatch! (op) (dispatch-resolved! op)
:examples $ []
:schema $ quote $ Fn schema/Action (-> Unit) (:features :js-ffi :state)
'dispatch-resolved! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn dispatch-resolved! (op)
reset! *reel $ match op
(reel.typed/Control control) (typed-reel/apply-control updater @*reel control)
(app.schema/Action action)
typed-reel/record-op updater @*reel action (generate-id!) (host/now-ms)
, &unit
:examples $ []
:schema $ quote $ Fn schema/ResolvedAction (-> Unit) (:features :js-ffi :state)
'main! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn main! ()
println "|Running mode:" $ if config/dev? |dev |release
if config/dev? $ load-console-formatter!
register-clojure!
match
browser/storage-get $ :storage-key config/site
(:some raw)
dispatch! $ restore-action raw
(:none) &unit
render-app!
add-watch! *reel :changes $ fn (r p)
hint-fn $ Fn (reel.typed/State schema/Action schema/Store) (reel.typed/State schema/Action schema/Store) (-> Unit)
render-app!
listen-devtools! |a on-control!
browser/add-event-listener! |beforeunload $ fn (event)
hint-fn $ Fn browser/EventHost $ -> Unit
save-store!
dispatch! $ schema/Action :pick-case $ decode-map-as (rand-int 10) Number
println "|App started."
:examples $ []
:schema $ quote $ Fn (-> Unit) (:features :io :js-ffi :state)
'mount-target $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn mount-target ()
let
document-host $ js-cast js/document 'respo.dom/DomDocument
document-host .query-selector |.app
:examples $ []
:schema $ quote $ Fn
-> $ JsNullish respo.dom/DomElement
:features :js-ffi
'on-control! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn on-control! (control) (dispatch-resolved! control)
:examples $ []
:schema $ quote $ Fn reel.typed/Control (-> Unit) (:features :js-ffi :state)
'register-clojure! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn register-clojure! ()
let
language clojure-lang
if (fn? language)
register-language! |clojure $ fn (api)
hint-fn $ Fn app.util/HighlightHost (-> app.util/LanguageDefinition) (:features :js-ffi)
js-cast (language api) (quote app.util/LanguageDefinition)
raise "|Expected Highlight.js LanguageFn"
, &unit
:examples $ []
:schema $ quote $ Fn (-> Unit) (:features :js-ffi) (:open :decode)
'reload! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn reload! ()
if (js-nullish? build-errors)
do (remove-watch! *reel :changes) (clear-cache!)
add-watch! *reel :changes $ fn (reel prev)
hint-fn $ Fn (reel.typed/State schema/Action schema/Store) (reel.typed/State schema/Action schema/Store) (-> Unit)
render-app!
reset! *reel $ typed-reel/refresh updater @*reel schema/store
hud! |ok~ |Ok
hud! |error build-errors
, &unit
:examples $ []
:schema $ quote $ Fn (-> Unit) (:features :io :js-ffi :state)
'render-app! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn render-app! ()
render-with! (mount-target)
fn () $ comp-container @*reel on-control!
, dispatch!
:examples $ []
:schema $ quote $ Fn (-> Unit) (:features :io :js-ffi :state)
'save-store! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn save-store! ()
let
store $ :store @*reel
browser/storage-set! (:storage-key config/site)
format-cirru-edn $ {}
:states $ :states store
:content $ :content store
:case-idx $ :case-idx store
:examples $ []
:schema $ quote $ Fn (-> Unit) (:features :state)
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.main
:require
respo.core :refer $ render-with! clear-cache! realize-ssr!
app.comp.container :refer $ comp-container
app.updater :refer $ updater restore-action
app.schema :as schema
app.config :as config
reel.util :refer $ listen-devtools!
|highlight.js/lib/languages/clojure :default clojure-lang
|./calcit.build-errors :default build-errors
|bottom-tip :default hud!
|@calcit/std :refer $ rand-int
reel.typed :as typed-reel
js-ffi.shared :as host
app.util :refer $ register-language!
js-ffi.browser :as browser
'app.schema $ %{} 'FileEntry
:defs $ {}
'Action $ %{} 'CodeEntry (:doc |)
:code $ quote $ defenum Action
:states (List respo.schema/CoordKey) StateValue
:content String
:pick-case Number
:hydrate-storage app.schema/Store
:examples $ []
:schema $ quote EnumDef
'ResolvedAction $ %{} 'CodeEntry (:doc |)
:code $ quote $ defunion ResolvedAction Action reel.typed/Control
:examples $ []
:schema $ quote UnionDef
'Showcase $ %{} 'CodeEntry (:doc |)
:code $ quote $ defstruct Showcase (:code String) (:text String) (:url String)
:examples $ []
:schema $ quote StructDef
'StateValue $ %{} 'CodeEntry (:doc |)
:code $ quote $ defunion StateValue Bool Number String Tag (List StateValue) (Map respo.schema/CoordKey StateValue)
:examples $ []
:schema $ quote UnionDef
'Store $ %{} 'CodeEntry
:doc "|Application fields and the recursive Respo state tree are checked at hydration and update boundaries."
:code $ quote $ defstruct Store
:states $ Map respo.schema/CoordKey StateValue
:content String
:case-idx Number
:examples $ []
:schema $ quote StructDef
'ToolInfo $ %{} 'CodeEntry (:doc |)
:code $ quote $ defstruct ToolInfo (:name String) (:url String) (:description String)
:logo $ Option String
:examples $ []
:schema $ quote StructDef
'store $ %{} 'CodeEntry (:doc |)
:code $ quote $ def store
Store :states ({}) :content | :case-idx 0
:examples $ []
:schema $ quote Store
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.schema
'app.updater $ %{} 'FileEntry
:defs $ {}
'restore-action $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn restore-action (raw)
Action :hydrate-storage $ decode-map-as (parse-cirru-edn raw) 'app.schema/Store
:examples $ []
:schema $ quote $ Fn String (-> Action)
:tests $ [] $ %{} 'TestEntry (:name |restores-legacy-store-map)
:code $ quote $ let
action $ restore-action $ format-cirru-edn
{}
:states $ {} $ :reel
{} $ :data false
:content |saved
:case-idx 3
match action
(:hydrate-storage restored)
do
assert= |saved $ :content restored
assert= 3 $ :case-idx restored
assert= (:states restored)
{} $ :reel $ {} (:data false)
_ $ raise "|Expected hydration action"
:tags $ #{} :regression :unit
'updater $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn updater (store op op-id op-time)
match op
(:states cursor s)
assoc store :states $ decode-map-as
update-state-tree (:states store) cursor s
Map respo.schema/CoordKey app.schema/StateValue
(:content c) (assoc store :content c)
(:pick-case c) (assoc store :case-idx c)
(:hydrate-storage d) d
:examples $ []
:schema $ quote $ Fn Store Action String Number (-> Store)
:tests $ [] $ %{} 'TestEntry (:name |updates-concrete-store)
:code $ quote $ let
original $ Store :states ({}) :content | :case-idx 0
edited $ updater original (Action :content |hello) |op-1 1
picked $ updater edited (Action :pick-case 4) |op-2 2
assert= | $ :content original
assert= |hello $ :content picked
assert= 4 $ :case-idx picked
assert= 0 $ :case-idx original
:tags $ #{} :regression :unit
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.updater
:require
respo.cursor :refer $ update-state-tree
app.schema :refer $ Store Action
'app.util $ %{} 'FileEntry
:defs $ {}
'HighlightHost $ %{} 'CodeEntry (:doc |)
:code $ quote $ deftrait HighlightHost
.highlight $ Fn app.util/HighlightHost String JsObject $ -> JsObject
.register-language! $ Fn app.util/HighlightHost String
Fn app.util/HighlightHost $ -> app.util/LanguageDefinition
-> Unit
:examples $ []
:ffi $ {} (:backend :js) (:kind :external-object)
:schema $ quote Trait
'HighlightResult $ %{} 'CodeEntry (:doc |)
:code $ quote $ deftrait HighlightResult (:value 'String)
:examples $ []
:ffi $ {} (:backend :js) (:kind :external-object)
:schema $ quote Trait
'LanguageDefinition $ %{} 'CodeEntry (:doc |)
:code $ quote $ deftrait LanguageDefinition (:name 'String)
:examples $ []
:ffi $ {} (:backend :js) (:kind :external-object) (:target :browser)
:schema $ quote Trait
'checked-highlighter-html $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn checked-highlighter-html (html)
if (string? html) html $ raise "|Markdown highlighter expected HTML String"
:examples $ []
:schema $ quote $ Fn Input (-> String) (:generics Input) (:open :decode)
'highlighter $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn highlighter (code lang)
let
html $ if (contains? supported-langs lang)
let
host $ js-cast hljs 'app.util/HighlightHost
result $ js-cast
host .highlight code $ to-js-data $ {} (:language lang)
, 'app.util/HighlightResult
.-value result
escape-html code
checked-highlighter-html html
:examples $ []
:schema $ quote $ Fn String String (-> String) (:features :js-ffi)
'inline $ %{} 'CodeEntry (:doc |)
:code $ quote $ defmacro inline (path)
read-file $ str |content/ path
:examples $ []
:schema $ quote $ Macro Syntax
-> $ Expr String
:capabilities :fs-read
'register-language! $ %{} 'CodeEntry (:doc |)
:code $ quote $ defn register-language! (name language)
let
registry $ js-cast hljs 'app.util/HighlightHost
registry .register-language! name language
, &unit
:examples $ []
:schema $ quote $ Fn String
Fn HighlightHost $ -> LanguageDefinition
-> Unit
:features :js-ffi
'supported-langs $ %{} 'CodeEntry (:doc |)
:code $ quote $ def supported-langs (&{} |clojure |clojure)
:examples $ []
:schema $ quote $ Map String String
:ns $ %{} 'NsEntry (:doc |)
:code $ quote $ ns app.util
:require (|escape-html :default escape-html) (|highlight.js :default hljs)