-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompact.cirru
228 lines (227 loc) · 9.52 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
{} (:package |app)
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!)
:modules $ [] |respo.calcit/ |lilac/ |memof/ |respo-ui.calcit/ |respo-markdown.calcit/ |reel.calcit/ |respo-feather.calcit/
:version |0.0.1
:files $ {}
|app.comp.container $ {}
:ns $ quote
ns app.comp.container $ :require
[] respo-ui.core :refer $ [] hsl
[] respo-ui.core :as ui
[] respo.core :refer $ [] defcomp defeffect >> <> div button input list-> textarea span
[] respo.comp.space :refer $ [] =<
[] reel.comp.reel :refer $ [] comp-reel
[] respo-md.comp.md :refer $ [] comp-md
[] app.config :refer $ [] dev?
[] feather.core :refer $ [] comp-icon
[] app.util :refer $ [] measure-text
:defs $ {}
|comp-container $ quote
defcomp comp-container (reel)
let
store $ :store reel
states $ :states store
div ({})
list->
{}
:style $ merge ui/global ui/fullscreen ui/row
{} $ :background-color (hsl 0 0 50 0.2)
:on-click $ fn (e d!)
let
event $ :event e
x $ .-clientX event
y $ .-clientY event
d! :add-note $ {}
:x $ - x 12
:y $ - y 12
:text "\""
.!preventDefault event
:on-drop $ fn (e d!)
let
info $ parse-cirru-edn
-> (:event e) .-dataTransfer $ .!getData "\"text"
d! :move-note $ {}
:id $ :id info
:dx $ -
.-clientX $ :event e
:sx info
:dy $ -
.-clientY $ :event e
:sy info
:on-dragover $ fn (e d!)
.!preventDefault $ :event e
-> (:notes store) (.to-list)
map $ fn (pair)
let[] (k note) pair $ [] k (comp-note note)
when dev? $ comp-reel (>> states :reel) reel ({})
|comp-note $ quote
defcomp comp-note (note)
[] (effect-focus)
div
{}
:style $ merge ui/row-center
{} (:position :absolute)
:top $ :y note
:left $ :x note
:on-click $ fn (e d!)
:draggable true
:on-dragstart $ fn (e d!)
-> (:event e) .-dataTransfer $ .!setData "\"text"
format-cirru-edn $ {}
:id $ :id note
:sx $ .-clientX (:event e)
:sy $ .-clientY (:event e)
input $ {}
:value $ :text note
:on-input $ fn (e d!)
d! :update-note $ {}
:id $ :id note
:text $ :value e
:style $ merge ui/input
{}
:background-color $ hsl 0 0 100
:border :none
:line-height "\"24px"
:min-width 16
:padding "\"0 12px"
:height "\"24px"
:width $ + 26
measure-text (:text note) 14 ui/font-normal
:font-size 14
:font-family ui/font-normal
:autofocus true
comp-icon :x
{} (:font-size 12)
:color $ hsl 0 50 50
:margin-left 4
:cursor :pointer
fn (e d!)
d! :rm-note $ :id note
|effect-focus $ quote
defeffect effect-focus () (action el at?) (js/console.log "\"focus" action el)
when (= action :mount)
-> el (.!querySelector "\"input") (.!focus)
|app.schema $ {}
:ns $ quote (ns app.schema)
:defs $ {}
|note $ quote
def note $ {} (:id nil) (:text "\"") (:time 0) (:x 0) (:y 0)
|store $ quote
def store $ {}
:states $ {}
:notes $ {}
|app.updater $ {}
:ns $ quote
ns app.updater $ :require
[] respo.cursor :refer $ [] update-states
[] app.schema :as schema
:defs $ {}
|updater $ quote
defn updater (store op op-data op-id op-time)
case-default op
do (println "\"Unknown op:" op) store
:states $ update-states store op-data
:hydrate-storage op-data
:add-note $ assoc-in store ([] :notes op-id)
merge schema/note op-data $ {} (:id op-id) (:time op-time)
:rm-note $ update store :notes
fn (notes)
dissoc notes $ str op-data
:update-note $ assoc-in store
[] :notes (:id op-data) :text
:text op-data
:move-note $ update-in store
[] :notes $ :id op-data
fn (x) (println "\"update" x op-data)
-> x
update :x $ fn (x)
+ x $ :dx op-data
update :y $ fn (y)
+ y $ :dy op-data
|app.main $ {}
:ns $ quote
ns app.main $ :require
[] respo.core :refer $ [] render! clear-cache! realize-ssr!
[] 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
[] cljs.reader :refer $ [] read-string
[] app.config :as config
"\"./calcit.build-errors" :default build-errors
"\"bottom-tip" :default hud!
:defs $ {}
|render-app! $ quote
defn render-app! () $ render! mount-target (comp-container @*reel) dispatch!
|persist-storage! $ quote
defn persist-storage! (? e)
.setItem js/localStorage (:storage config/site)
format-cirru-edn $ :store @*reel
|mount-target $ quote
def mount-target $ .querySelector js/document |.app
|*reel $ quote
defatom *reel $ -> reel-schema/reel (assoc :base schema/store) (assoc :store schema/store)
|main! $ quote
defn main! ()
if config/dev? $ load-console-formatter!
render-app!
add-watch *reel :changes $ fn (r p) (render-app!)
listen-devtools! |a dispatch!
js/window.addEventListener |beforeunload persist-storage!
js/window.addEventListener "\"keydown" $ \ on-key! %
; js/setInterval persist-storage! $ * 1000 60
; let
raw $ .getItem js/localStorage (:storage config/site)
when (some? raw)
dispatch! :hydrate-storage $ parse-cirru-edn raw
println "|App started."
|on-key! $ quote
defn on-key! (event)
cond
and (.-ctrlKey event)
= "\"b" $ .-key event
dispatch! :toggle-color nil
(and (.-ctrlKey event) (= "\"=" (.-key event)))
dispatch! :inc-line nil
(and (.-ctrlKey event) (= "\"-" (.-key event)))
dispatch! :dec-line nil
|dispatch! $ quote
defn dispatch! (op op-data) (; println "\"Dispatch:" op op-data)
reset! *reel $ reel-updater updater @*reel op op-data
|reload! $ 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
|app.util $ {}
:ns $ quote (ns app.util)
:defs $ {}
|*canvas-el $ quote
defatom *canvas-el $ if (exists? js/document) (js/document.createElement "\"canvas") nil
|measure-text $ quote
defn measure-text (text size font)
if (some? @*canvas-el)
let
ctx $ .!getContext @*canvas-el "\"2d"
set! (.-font ctx) (str size "\"px " font)
; println $ pr-str (str size "\"px " font)
.-width $ .!measureText ctx text
, 0
|get-env! $ quote
defn get-env! (property)
aget (.-env js/process) property
|app.config $ {}
:ns $ quote
ns app.config $ :require
[] app.util :refer $ [] get-env!
:defs $ {}
|dev? $ quote
def dev? $ = "\"dev" (get-env "\"mode")
|site $ quote
def site $ {} (:storage "\"screen-notes") (:dev-ui "\"http://localhost:8100/main.css") (:release-ui "\"http://cdn.tiye.me/favored-fonts/main.css") (:cdn-url "\"http://cdn.tiye.me/screen-notes/") (:cdn-folder "\"tiye.me:cdn/screen-notes") (:title "\"Screen notes") (:icon "\"http://cdn.tiye.me/logo/mvc-works.png") (:upload-folder "\"tiye.me:repo/mvc-works/screen-notes/")
|bundle-builds $ quote
def bundle-builds $ #{} "\"release" "\"local-bundle"