generated from calcit-lang/respo-calcit-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
246 lines (245 loc) · 10.7 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
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1)
:modules $ [] |respo.calcit/ |lilac/ |memof/ |respo-ui.calcit/ |reel.calcit/
:entries $ {}
:files $ {}
|app.comp.container $ %{} :FileEntry
:defs $ {}
|CodeEntry $ %{} :CodeEntry (:doc |)
:code $ quote
def CodeEntry $ new-record :CodeEntry :doc :code
|Expr $ %{} :CodeEntry (:doc |)
:code $ quote
def Expr $ new-record :Expr :data :by :at
|FileEntry $ %{} :CodeEntry (:doc |)
:code $ quote
def FileEntry $ new-record :FileEntry :ns :defs
|Leaf $ %{} :CodeEntry (:doc |)
:code $ quote
def Leaf $ new-record :Leaf :by :at :text
|comp-container $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-container (reel)
let
store $ :store reel
states $ :states store
cursor $ or (:cursor states) ([])
state $ or (:data states)
{} (:content "\"") (:next-data nil)
display-text $ format-cirru-edn (:next-data state)
div
{} $ :class-name (str-spaced css/fullscreen css/global css/row)
textarea $ {}
:value $ :content state
:placeholder "\"Content"
:class-name $ str-spaced css/expand css/textarea css/font-code!
:style $ {} (:white-space :pre) (:font-size 12)
:on-input $ fn (e d!)
d! cursor $ assoc state :content (:value e)
:on-paste $ fn (e d!)
d! cursor $ assoc state :next-data nil
d! $ :: :interact
=< 2 nil
div
{} $ :class-name (str-spaced css/column css/expand)
div ({})
button $ {} (:class-name css/button) (:inner-text "\"Convert Calcit")
:on-click $ fn (e d!)
d! cursor $ assoc state :next-data
transform-snapshot $ parse-cirru-edn (:content state)
d! $ :: :interact
=< 8 nil
button $ {} (:class-name css/button) (:inner-text "\"Convert Compact")
:on-click $ fn (e d!)
d! cursor $ assoc state :next-data
transform-compact $ parse-cirru-edn (:content state)
d! $ :: :interact
=< 8 nil
button $ {} (:class-name css/button) (:inner-text "\"FileEntry")
:on-click $ fn (e d!)
d! cursor $ assoc state :next-data
transform-file-entry $ parse-cirru-edn (:content state)
d! $ :: :interact
textarea $ {} (:value display-text)
:class-name $ str-spaced css/expand css/textarea css/font-code!
:placeholder "\"data"
:style $ {} (:white-space :pre) (:font-size 12)
:disabled true
if (:interacted? store)
comp-copy $ :next-data state
when dev? $ comp-reel (>> states :reel) reel ({})
|comp-copy $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-copy (data)
[] (effect-copy data)
span $ {}
|effect-copy $ %{} :CodeEntry (:doc |)
:code $ quote
defeffect effect-copy (data) (action el at?)
println "\"Copy Effect:" action $ some? data
if (= action :update)
if (some? data)
let
text $ format-cirru-edn data
copy! text
println "\"Copied!" $ count text
|transform-code $ %{} :CodeEntry (:doc |)
:code $ quote
defn transform-code (expr)
if
= :expr $ :type expr
%{} Expr
:by $ :by expr
:at $ :at expr
:data $ -> (:data expr)
map-kv $ fn (k v)
[] k $ transform-code v
%{} Leaf
:by $ :by expr
:at $ :at expr
:text $ :text expr
|transform-compact $ %{} :CodeEntry (:doc |)
:code $ quote
defn transform-compact (data)
-> data $ update :files
fn (files)
-> files $ map-kv
fn (k file)
[] k $ -> file
update :ns $ fn (c)
%{} CodeEntry (:doc |) (:code c)
update :defs $ fn (defs)
-> defs $ map-kv
fn (def-name code)
[] def-name $ %{} CodeEntry (:doc |) (:code code)
|transform-file-entry $ %{} :CodeEntry (:doc |)
:code $ quote
defn transform-file-entry (snapshot)
update snapshot :files $ fn (files)
map-kv files $ fn (k v)
[] k $ %{} FileEntry
:ns $ :ns v
:defs $ :defs v
|transform-snapshot $ %{} :CodeEntry (:doc |)
:code $ quote
defn transform-snapshot (snapshot)
let
next $ -> snapshot
update-in ([] :ir :files)
fn (files)
-> files $ map-kv
fn (k file)
[] k $ %{} FileEntry
:ns $ %{} CodeEntry (:doc "\"")
:code $ transform-code (:ns file)
:defs $ -> (:defs file)
map-kv $ fn (def-name code)
[] def-name $ %{} CodeEntry (:doc "\"")
:code $ transform-code code
-> next (dissoc :ir)
assoc :package $ get-in next ([] :ir :package)
assoc :files $ get-in next ([] :ir :files)
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.container $ :require (respo-ui.core :as ui)
respo.core :refer $ defcomp defeffect <> >> div button textarea span input
respo.comp.space :refer $ =<
reel.comp.reel :refer $ comp-reel
app.config :refer $ dev?
respo-ui.css :as css
"\"copy-text-to-clipboard" :default copy!
|app.config $ %{} :FileEntry
:defs $ {}
|dev? $ %{} :CodeEntry (:doc |)
:code $ quote
def dev? $ = "\"dev" (get-env "\"mode" "\"release")
|site $ %{} :CodeEntry (:doc |)
:code $ quote
def site $ {} (:storage-key "\"workflow")
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.config)
|app.main $ %{} :FileEntry
:defs $ {}
|*reel $ %{} :CodeEntry (:doc |)
:code $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|dispatch! $ %{} :CodeEntry (:doc |)
:code $ quote
defn dispatch! (op)
when
and config/dev? $ not= (nth op 0) :states
js/console.log "\"Dispatch:" op
reset! *reel $ reel-updater updater @*reel op
|main! $ %{} :CodeEntry (:doc |)
:code $ quote
defn main! ()
println "\"Running mode:" $ if config/dev? "\"dev" "\"release"
if config/dev? $ load-console-formatter!
render-app!
add-watch *reel :changes $ fn (reel prev) (render-app!)
listen-devtools! |k dispatch!
js/window.addEventListener |beforeunload $ fn (event) (persist-storage!)
flipped js/setInterval 60000 persist-storage!
let
raw $ js/localStorage.getItem (:storage-key config/site)
when (some? raw)
dispatch! $ :: :hydrate-storage
assoc (parse-cirru-edn raw) :interacted? false
println "|App started."
|mount-target $ %{} :CodeEntry (:doc |)
:code $ quote
def mount-target $ .!querySelector js/document |.app
|persist-storage! $ %{} :CodeEntry (:doc |)
:code $ quote
defn persist-storage! () (js/console.log "\"persist")
js/localStorage.setItem (:storage-key config/site)
format-cirru-edn $ :store @*reel
|reload! $ %{} :CodeEntry (:doc |)
:code $ quote
defn reload! () $ if (nil? build-errors)
do (remove-watch *reel :changes) (clear-cache!)
add-watch *reel :changes $ fn (reel prev) (render-app!)
reset! *reel $ refresh-reel @*reel schema/store updater
hud! "\"ok~" "\"Ok"
hud! "\"error" build-errors
|render-app! $ %{} :CodeEntry (:doc |)
:code $ quote
defn render-app! () $ render! mount-target (comp-container @*reel) dispatch!
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.main $ :require
respo.core :refer $ render! clear-cache!
app.comp.container :refer $ comp-container
app.updater :refer $ updater
app.schema :as schema
reel.util :refer $ listen-devtools!
reel.core :refer $ reel-updater refresh-reel
reel.schema :as reel-schema
app.config :as config
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
|app.schema $ %{} :FileEntry
:defs $ {}
|store $ %{} :CodeEntry (:doc |)
:code $ quote
def store $ {}
:states $ {}
:cursor $ []
:interacted? false
:ns $ %{} :CodeEntry (:doc |)
:code $ quote (ns app.schema)
|app.updater $ %{} :FileEntry
:defs $ {}
|updater $ %{} :CodeEntry (:doc |)
:code $ quote
defn updater (store op op-id op-time)
tag-match op
:states cursor s
update-states store cursor s
(:hydrate-storage data) data
(:interact) (assoc store :interacted? true)
_ $ do (println "\"unknown op:" op) store
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.updater $ :require
respo.cursor :refer $ update-states