@kairotic/app 0.0.0-stage → 0.2.1
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.
- package/README.md +9 -2
- package/index.html +1101 -0
- package/kairotic/api.cljs +362 -0
- package/kairotic/assistant.cljs +505 -0
- package/kairotic/backends/gun-backend.js +371 -0
- package/kairotic/canvas.cljs +751 -0
- package/kairotic/code.cljs +108 -0
- package/kairotic/components.cljs +838 -0
- package/kairotic/core.cljs +96 -0
- package/kairotic/corefns.cljs +473 -0
- package/kairotic/docs.mjs +2 -0
- package/kairotic/engine.cljs +482 -0
- package/kairotic/examples.mjs +96 -0
- package/kairotic/faust.cljs +225 -0
- package/kairotic/help.cljs +1036 -0
- package/kairotic/hiccup.cljs +566 -0
- package/kairotic/input.cljs +271 -0
- package/kairotic/kfile.mjs +138 -0
- package/kairotic/library.cljs +214 -0
- package/kairotic/links.cljs +41 -0
- package/kairotic/mt.cljs +1604 -0
- package/kairotic/mtboxes.cljs +276 -0
- package/kairotic/packages/analysis.mjs +64 -0
- package/kairotic/packages/controls.mjs +28 -0
- package/kairotic/packages/data.mjs +22 -0
- package/kairotic/packages/faust-units/cmaes.mjs +82 -0
- package/kairotic/packages/faust-units/graph.mjs +212 -0
- package/kairotic/packages/faust-units/listen.mjs +125 -0
- package/kairotic/packages/faust-units/notation.mjs +139 -0
- package/kairotic/packages/faust-units/parse.mjs +439 -0
- package/kairotic/packages/faust-units/recipe.mjs +195 -0
- package/kairotic/packages/faust-units/render.mjs +69 -0
- package/kairotic/packages/faust-units/units.mjs +130 -0
- package/kairotic/packages/faust-units/view.mjs +353 -0
- package/kairotic/packages/faust-units.mjs +9 -0
- package/kairotic/packages/io.mjs +58 -0
- package/kairotic/packages/net.mjs +28 -0
- package/kairotic/packages/patterns.mjs +34 -0
- package/kairotic/packages/spatial.mjs +22 -0
- package/kairotic/packages/spectral/shift.mjs +169 -0
- package/kairotic/packages/spectral.mjs +16 -0
- package/kairotic/packages/synth.mjs +28 -0
- package/kairotic/packages/theory/counterpoint.mjs +798 -0
- package/kairotic/packages/theory/mirror.mjs +221 -0
- package/kairotic/packages/theory.mjs +46 -0
- package/kairotic/patterns.cljs +538 -0
- package/kairotic/presets.cljs +227 -0
- package/kairotic/quantize.cljs +782 -0
- package/kairotic/record.cljs +169 -0
- package/kairotic/release.cljs +90 -0
- package/kairotic/ring.cljs +129 -0
- package/kairotic/ringaudio.cljs +232 -0
- package/kairotic/ringcore.mjs +270 -0
- package/kairotic/score.cljs +176 -0
- package/kairotic/shapes.cljs +283 -0
- package/kairotic/signal.cljs +327 -0
- package/kairotic/sounds.cljs +565 -0
- package/kairotic/sounds.mjs +108 -0
- package/kairotic/span.cljs +129 -0
- package/kairotic/spell.cljs +281 -0
- package/kairotic/structure.cljs +145 -0
- package/kairotic/talk.cljs +115 -0
- package/kairotic/tempo.cljs +226 -0
- package/kairotic/treecanvas.cljs +299 -0
- package/kairotic/tutorials.mjs +1283 -0
- package/kairotic/vendor/codemirror.mjs +23 -0
- package/package.json +23 -4
- package/page/00-work.cljs +862 -0
- package/page/01-commands.cljs +1219 -0
- package/page/02-patch-view.cljs +1051 -0
- package/page/03-history-view.cljs +481 -0
- package/page/04-panels.cljs +448 -0
- package/page/05-gestures.cljs +1247 -0
- package/page/06-connection.cljs +219 -0
- package/page/07-claude.cljs +430 -0
- package/page/08-sessions.cljs +423 -0
- package/page/09-learn.cljs +602 -0
- package/page/10-embed.cljs +469 -0
- package/page/11-startup.cljs +61 -0
- package/page/12-feedback.cljs +172 -0
- package/page/13-perform.cljs +325 -0
- package/page/14-editor.cljs +656 -0
- package/page/15-presets.cljs +230 -0
- package/page/16-release.cljs +242 -0
- package/page/17-sounds.cljs +147 -0
- package/page/18-lines.cljs +594 -0
- package/page/19-files.cljs +247 -0
- package/page/19-html.cljs +152 -0
- package/page/20-talk.cljs +527 -0
- package/page/21-net.cljs +110 -0
- package/page/22-learn.cljs +303 -0
- package/page/23-ids.cljs +233 -0
- package/page/24-clipboard.cljs +136 -0
- package/page/25-tidy.cljs +74 -0
- package/page/26-probes.cljs +111 -0
- package/sources.mjs +2 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
;; SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
;; Kairotic · the page, part 9 of 12: sessions
|
|
3
|
+
;; The page's ClojureScript, in the order it is evaluated (app/index.html lists the files).
|
|
4
|
+
|
|
5
|
+
(in-ns 'user)
|
|
6
|
+
|
|
7
|
+
;; ───────────────────────── session manager ─────────────────────────
|
|
8
|
+
|
|
9
|
+
(defonce rooms (atom {}))
|
|
10
|
+
(defonce solo-works (atom {}))
|
|
11
|
+
(defonce lobby-peers (atom []))
|
|
12
|
+
(defonce snapshot-subs (atom [])) ; not `subs`: the page shares one namespace with components, and clojure.core/subs must stay a function there
|
|
13
|
+
(defonce mgr (atom {:open true :confirm nil :busy nil :invite nil :relays false}))
|
|
14
|
+
|
|
15
|
+
(defn room-name [id] (str "room-" (str/lower-case id)))
|
|
16
|
+
|
|
17
|
+
(defn meta-of [d]
|
|
18
|
+
(let [m (js->clj (.data d))]
|
|
19
|
+
{:id (.-id d)
|
|
20
|
+
:name (let [n (get m "name")] (if (and (string? n) (seq n)) n "Untitled"))
|
|
21
|
+
:created (let [t (get m "created")] (if (number? t) t 0))
|
|
22
|
+
:origin (let [o (get m "origin")] (when (string? o) o))}))
|
|
23
|
+
|
|
24
|
+
(defn lobby-presence! []
|
|
25
|
+
(when-let [r @roomref]
|
|
26
|
+
(.catch (.presence r (clj->js {:room (when (= :room (:kind @work)) (:id @work))})) (fn [_] nil))))
|
|
27
|
+
|
|
28
|
+
(defn people-in [id] (count (filter (fn [p] (= (:room p) id)) @lobby-peers)))
|
|
29
|
+
|
|
30
|
+
(defn unsub-all! []
|
|
31
|
+
(doseq [u @snapshot-subs] (u))
|
|
32
|
+
(reset! snapshot-subs []))
|
|
33
|
+
|
|
34
|
+
(defn leave-room! []
|
|
35
|
+
(when-let [r @named-room]
|
|
36
|
+
(.catch (.leave r) (fn [_] nil))
|
|
37
|
+
(reset! named-room nil))
|
|
38
|
+
(reset! peers []))
|
|
39
|
+
|
|
40
|
+
(defn set-hash! [h]
|
|
41
|
+
(try (if (seq h)
|
|
42
|
+
(set! (.-hash js/location) h)
|
|
43
|
+
(.replaceState js/history nil "" (str (.-pathname js/location) (.-search js/location))))
|
|
44
|
+
(catch :default _ nil)))
|
|
45
|
+
|
|
46
|
+
(defn show-manager! [] (swap! mgr assoc :open true :confirm nil))
|
|
47
|
+
(defn hide-manager!
|
|
48
|
+
"Closes the session manager: back to the open work, or — when none is open yet — into a local one."
|
|
49
|
+
[]
|
|
50
|
+
(if (:kind @work)
|
|
51
|
+
(swap! mgr assoc :open false :confirm nil)
|
|
52
|
+
(open-work! :local "local" "Local")))
|
|
53
|
+
|
|
54
|
+
(defn on-meta [d]
|
|
55
|
+
(when (.-exists d)
|
|
56
|
+
(let [m (js->clj (.data d)) v (get m "simultaneity_ms") n (get m "name")]
|
|
57
|
+
(when (string? n) (swap! work assoc :name n))
|
|
58
|
+
(when (and (number? v) (<= 0 v 10000) (not= v (:simul-ms @settings)))
|
|
59
|
+
(swap! settings assoc :simul-ms v)))))
|
|
60
|
+
|
|
61
|
+
(defn reset-patch-state!
|
|
62
|
+
"What the boxes of the patch on screen showed and held is forgotten (a new box with the same id starts
|
|
63
|
+
empty): when another work opens, or another line of this one (#117)."
|
|
64
|
+
[]
|
|
65
|
+
(swap! eng/rt assoc :shows {} :states {} :loops #{})
|
|
66
|
+
(reset! score-cache {})
|
|
67
|
+
(reset! live-trees {})
|
|
68
|
+
(reset! dismissed-trees {})
|
|
69
|
+
(reset! sent-trees {})
|
|
70
|
+
(reset! sent-data {})
|
|
71
|
+
(reset! sent-shape nil)
|
|
72
|
+
(reset! msg-edits {}))
|
|
73
|
+
|
|
74
|
+
(defn reset-work-state! [mode]
|
|
75
|
+
(reset-patch-state!)
|
|
76
|
+
(unsub-all!)
|
|
77
|
+
(leave-room!)
|
|
78
|
+
(reset! queues {})
|
|
79
|
+
(reset! cache {})
|
|
80
|
+
(reset! settings {:simul-ms 1500})
|
|
81
|
+
(swap! ui assoc :follow nil :merge-pick false :sel nil :drag nil :wire nil)
|
|
82
|
+
(.remove (.-classList ($ "hist-wrap")) "picking")
|
|
83
|
+
(reset! world {:pos nil :auto true :prev-pos nil :jumped-at 0})
|
|
84
|
+
(reset! line-state {:active main-line :index {} :pos {}})
|
|
85
|
+
(swap! hist assoc :nodes {} :other {} :loaded false :mode mode))
|
|
86
|
+
|
|
87
|
+
(defonce lesson (atom nil)) ; the open lesson (a tutorial or a help patch), Study 18
|
|
88
|
+
|
|
89
|
+
(defn open-work!
|
|
90
|
+
"Opens a work: :room (shared), :solo (private) or :local (not saved)."
|
|
91
|
+
[kind id nm]
|
|
92
|
+
(eng/stop!)
|
|
93
|
+
(reset! lesson nil)
|
|
94
|
+
(reset! cbox/trust (not= kind :room))
|
|
95
|
+
(cbox/forget-language! "clojurescript")
|
|
96
|
+
(reset! work {:kind kind :id id :name nm})
|
|
97
|
+
(reset-work-state! (case kind
|
|
98
|
+
:room (if (:writable @hist) :shared :readonly)
|
|
99
|
+
:solo :solo
|
|
100
|
+
:local))
|
|
101
|
+
(swap! mgr assoc :open false :confirm nil :invite nil)
|
|
102
|
+
(set-hash! (if (= kind :room) (str "room-" id) ""))
|
|
103
|
+
(lobby-presence!)
|
|
104
|
+
(if (= kind :local)
|
|
105
|
+
(start-local!)
|
|
106
|
+
(let [db @dbref]
|
|
107
|
+
(swap! snapshot-subs conj (.onSnapshot (.collection db (hist-path)) on-history db-failed!))
|
|
108
|
+
(swap! snapshot-subs conj (.onSnapshot (.doc db (work-base)) on-meta (fn [_] nil)))
|
|
109
|
+
;; the names of its lines (#117)
|
|
110
|
+
(swap! snapshot-subs conj (.onSnapshot (.collection db (str (work-base) "/lines")) on-lines (fn [_] nil)))
|
|
111
|
+
(when (and (= kind :room) @roomref)
|
|
112
|
+
(-> (.join @roomref (room-name id))
|
|
113
|
+
(.then (fn [r]
|
|
114
|
+
(if (and (= :room (:kind @work)) (= id (:id @work)))
|
|
115
|
+
(do (reset! named-room r) (setup-room! r))
|
|
116
|
+
(.catch (.leave r) (fn [_] nil)))))
|
|
117
|
+
(.catch (fn [_] nil))))))
|
|
118
|
+
(repl-print! "out" (esc (str "; " (case kind :room "Shared room" :solo "Solo work" "Local work") ": «" nm "»"))))
|
|
119
|
+
|
|
120
|
+
(defn close-work! []
|
|
121
|
+
(reset! lesson nil)
|
|
122
|
+
(reset! work {:kind nil :id nil :name nil})
|
|
123
|
+
(reset-work-state! :none)
|
|
124
|
+
(set-hash! "")
|
|
125
|
+
(lobby-presence!)
|
|
126
|
+
(show-manager!))
|
|
127
|
+
|
|
128
|
+
(defn coll-for [kind] (case kind :room "rooms" :solo (str "data/users/" (uid))))
|
|
129
|
+
|
|
130
|
+
(defn busy! [msg] (swap! mgr assoc :busy msg))
|
|
131
|
+
|
|
132
|
+
(defn mgr-fail! [e]
|
|
133
|
+
(busy! nil)
|
|
134
|
+
(db-failed! e))
|
|
135
|
+
|
|
136
|
+
(defn create-work! [kind nm example?]
|
|
137
|
+
(let [db @dbref
|
|
138
|
+
ref (.doc (.collection db (coll-for kind)))
|
|
139
|
+
id (.-id ref)]
|
|
140
|
+
(busy! "Creating…")
|
|
141
|
+
(-> (.set ref (clj->js {:name nm :created (js/Date.now) :author (uid) :simultaneity_ms 1500}))
|
|
142
|
+
(.then (fn [_]
|
|
143
|
+
(busy! nil)
|
|
144
|
+
(open-work! kind id nm)
|
|
145
|
+
(when example? (gesture! "(load-example)"))))
|
|
146
|
+
(.catch mgr-fail!))))
|
|
147
|
+
|
|
148
|
+
(defn plain [o] (js/JSON.parse (js/JSON.stringify o)))
|
|
149
|
+
|
|
150
|
+
(defn copy-work!
|
|
151
|
+
"Copies a work with all its history into a new work (from room to solo or the other way round)."
|
|
152
|
+
[from-kind from-id to-kind nm]
|
|
153
|
+
(let [db @dbref
|
|
154
|
+
src (str (base-of from-kind from-id) "/history")
|
|
155
|
+
ref (.doc (.collection db (coll-for to-kind)))
|
|
156
|
+
id (.-id ref)
|
|
157
|
+
dst (str (coll-for to-kind) "/" id "/history")]
|
|
158
|
+
(busy! "Copying the history…")
|
|
159
|
+
(-> (.set ref (clj->js {:name nm :created (js/Date.now) :author (uid) :simultaneity_ms 1500
|
|
160
|
+
:origin (str (name from-kind) ":" from-id)}))
|
|
161
|
+
(.then (fn [_] (.get (.collection db src))))
|
|
162
|
+
(.then (fn [snap]
|
|
163
|
+
(reduce (fn [p d] (.then p (fn [_] (.set (.doc db (str dst "/" (.-id d))) (plain (.data d))))))
|
|
164
|
+
(js/Promise.resolve nil)
|
|
165
|
+
(array-seq (.-docs snap)))))
|
|
166
|
+
;; and the names of its lines (their segments came with the history)
|
|
167
|
+
(.then (fn [_] (.get (.collection db (str (base-of from-kind from-id) "/lines")))))
|
|
168
|
+
(.then (fn [snap]
|
|
169
|
+
(reduce (fn [p d] (.then p (fn [_] (.set (.doc db (str (coll-for to-kind) "/" id "/lines/" (.-id d))) (plain (.data d))))))
|
|
170
|
+
(js/Promise.resolve nil)
|
|
171
|
+
(filter (fn [d] (.-exists d)) (array-seq (.-docs snap))))))
|
|
172
|
+
(.then (fn [_] (busy! nil) (open-work! to-kind id nm)))
|
|
173
|
+
(.catch mgr-fail!))))
|
|
174
|
+
|
|
175
|
+
(defn delete-work!
|
|
176
|
+
"Deletes a work and all its history."
|
|
177
|
+
[kind id]
|
|
178
|
+
(let [db @dbref base (base-of kind id)]
|
|
179
|
+
(when (and (= kind (:kind @work)) (= id (:id @work))) (close-work!))
|
|
180
|
+
(busy! "Deleting…")
|
|
181
|
+
(-> (.get (.collection db (str base "/history")))
|
|
182
|
+
(.then (fn [snap]
|
|
183
|
+
(reduce (fn [p d] (.then p (fn [_] (.delete (.doc db (str base "/history/" (.-id d)))))))
|
|
184
|
+
(js/Promise.resolve nil)
|
|
185
|
+
(array-seq (.-docs snap)))))
|
|
186
|
+
;; the names of its lines (their segments went with the history)
|
|
187
|
+
(.then (fn [_] (.get (.collection db (str base "/lines")))))
|
|
188
|
+
(.then (fn [snap]
|
|
189
|
+
(reduce (fn [p d] (.then p (fn [_] (.delete (.doc db (str base "/lines/" (.-id d)))))))
|
|
190
|
+
(js/Promise.resolve nil)
|
|
191
|
+
(array-seq (.-docs snap)))))
|
|
192
|
+
(.then (fn [_] (.delete (.doc db base))))
|
|
193
|
+
(.then (fn [_] (busy! nil) (swap! mgr assoc :confirm nil)))
|
|
194
|
+
(.catch mgr-fail!))))
|
|
195
|
+
|
|
196
|
+
(defn fmt-date [t]
|
|
197
|
+
(if (pos? t)
|
|
198
|
+
(let [d (js/Date. t)]
|
|
199
|
+
(str (.toLocaleDateString d "en-GB" #js {:day "numeric" :month "short"}) " · "
|
|
200
|
+
(.toLocaleTimeString d "en-GB" #js {:hour "2-digit" :minute "2-digit"})))
|
|
201
|
+
""))
|
|
202
|
+
|
|
203
|
+
(defn room-link
|
|
204
|
+
"A link to room id on this site, with this page's relays when they are not the site's."
|
|
205
|
+
[id]
|
|
206
|
+
(with-relay (str (.-origin js/location) (.-pathname js/location) "#room-" id)))
|
|
207
|
+
|
|
208
|
+
(defn item-html [kind {:keys [id created origin] nm :name}]
|
|
209
|
+
(let [k (name kind)
|
|
210
|
+
current? (and (= kind (:kind @work)) (= id (:id @work)))
|
|
211
|
+
confirm? (= (:confirm @mgr) [k id])
|
|
212
|
+
n (when (= kind :room) (people-in id))
|
|
213
|
+
can-write (:writable @hist)]
|
|
214
|
+
(str "<li class=\"item" (when current? " current") (when (= id (:invite @mgr)) " invited") "\">"
|
|
215
|
+
"<div class=\"item-main\"><span class=\"item-name\">" (esc nm) "</span>"
|
|
216
|
+
"<span class=\"item-meta\">" (fmt-date created)
|
|
217
|
+
(when origin (str " · copy"))
|
|
218
|
+
(when (and n (pos? n)) (str " · <b>" n (if (= 1 n) " person inside" " people inside") "</b>"))
|
|
219
|
+
(when current? " · open now")
|
|
220
|
+
"</span></div>"
|
|
221
|
+
"<div class=\"item-acts\">"
|
|
222
|
+
"<button class=\"act primary\" data-act=\"open\" data-kind=\"" k "\" data-id=\"" (esc id) "\">" (if current? "Back" "Open") "</button>"
|
|
223
|
+
(when (and (= kind :room) (pages?))
|
|
224
|
+
(str "<button class=\"act\" data-act=\"link\" data-kind=\"room\" data-id=\"" (esc id) "\" title=\"Copies a link to this room"
|
|
225
|
+
(when (relay-param) ", with the relay it is on") "\">Copy link</button>"))
|
|
226
|
+
(when can-write
|
|
227
|
+
(str (if (= kind :solo)
|
|
228
|
+
(str "<button class=\"act\" data-act=\"copy\" data-kind=\"" k "\" data-to=\"room\" data-id=\"" (esc id) "\" title=\"Creates a shared room with a copy of this work and its history\">Share a copy</button>")
|
|
229
|
+
(str "<button class=\"act\" data-act=\"copy\" data-kind=\"" k "\" data-to=\"solo\" data-id=\"" (esc id) "\" title=\"Creates a solo work with a copy of this room and its history\">Copy for me</button>"))
|
|
230
|
+
"<button class=\"act danger" (when confirm? " armed") "\" data-act=\"delete\" data-kind=\"" k "\" data-id=\"" (esc id) "\">"
|
|
231
|
+
(if confirm? "Sure? Delete" "Delete") "</button>"))
|
|
232
|
+
"</div></li>")))
|
|
233
|
+
|
|
234
|
+
(defn welcome
|
|
235
|
+
"What the session manager says before any work is open: what Kairotic is, how to start, and that it is an alpha."
|
|
236
|
+
[]
|
|
237
|
+
(if (es?)
|
|
238
|
+
(str "<div class=\"mgr-welcome\">"
|
|
239
|
+
"<p class=\"wt\">Te damos la bienvenida a <b>Kairotic</b> <span class=\"alpha\">0.2.0-alpha</span></p>"
|
|
240
|
+
"<p>Un espacio para componer, improvisar e interpretar música donde <b>el patch y su código son la misma obra</b>: cajas unidas por líneas, como en Max o Pure Data, cada gesto guardado en una historia que puedes recorrer, ramificar y compartir.</p>"
|
|
241
|
+
"<ul>"
|
|
242
|
+
"<li><b>Empieza</b> abajo: una obra <b>solo</b> (se guarda para ti), una <b>sala compartida</b> (con otras personas en la misma historia) o <b>en local</b>, sin guardar.</li>"
|
|
243
|
+
"<li><b>Doble clic</b> en un sitio vacío crea una caja (<code>osc~ 440</code>); arrastra de una salida a una entrada para conectar; <b>▶</b> pone en marcha el sonido.</li>"
|
|
244
|
+
"<li>La pestaña <b>Help</b> tiene la guía, los conceptos, los tutoriales y una página para cada caja; <b>Claude</b> hace patches a partir de lo que describes.</li>"
|
|
245
|
+
"</ul>"
|
|
246
|
+
"<p class=\"alpha-note\">Es una <b>versión alfa</b>: puede fallar, y cambiará. Lo que nos cuentes decide lo que viene después; la pestaña <b>Feedback</b> lo convierte en un aviso en GitHub. ¡Gracias por probarla!</p>"
|
|
247
|
+
"<p class=\"wb\"><button class=\"act primary\" data-act=\"guide\">Leer la guía</button> <button class=\"act\" data-act=\"local\">Empezar en local</button> <button class=\"act\" data-act=\"feedback\">Feedback</button></p>"
|
|
248
|
+
"</div>")
|
|
249
|
+
(str "<div class=\"mgr-welcome\">"
|
|
250
|
+
"<p class=\"wt\">Welcome to <b>Kairotic</b> <span class=\"alpha\">0.2.0-alpha</span></p>"
|
|
251
|
+
"<p>A space to compose, improvise and perform music where <b>the patch and its code are the same work</b>: boxes joined by lines, as in Max or Pure Data, every gesture kept in a history you can travel, branch and share.</p>"
|
|
252
|
+
"<ul>"
|
|
253
|
+
"<li><b>Start</b> below: a <b>solo</b> work (saved for you), a <b>shared room</b> (with others, in the same history) or <b>locally</b>, without saving.</li>"
|
|
254
|
+
"<li><b>Double-click</b> an empty place to create a box (<code>osc~ 440</code>); drag from an outlet to an inlet to connect; <b>▶</b> starts the sound.</li>"
|
|
255
|
+
"<li>The <b>Help</b> tab has the guide, the concepts, the tutorials and a page for every box; <b>Claude</b> makes patches from what you describe.</li>"
|
|
256
|
+
"</ul>"
|
|
257
|
+
"<p class=\"alpha-note\">This is an <b>alpha</b>: it may fail, and it will change. What you tell us decides what comes next; the <b>Feedback</b> tab turns it into a GitHub issue. Thank you for trying it!</p>"
|
|
258
|
+
"<p class=\"wb\"><button class=\"act primary\" data-act=\"guide\">Read the guide</button> <button class=\"act\" data-act=\"local\">Start locally</button> <button class=\"act\" data-act=\"feedback\">Feedback</button></p>"
|
|
259
|
+
"</div>")))
|
|
260
|
+
|
|
261
|
+
(defn render-manager! []
|
|
262
|
+
(let [{:keys [open busy invite]} @mgr
|
|
263
|
+
el ($ "manager")
|
|
264
|
+
db? (some? @dbref)
|
|
265
|
+
can-write (:writable @hist)
|
|
266
|
+
connecting? (= :connecting (:mode @hist))
|
|
267
|
+
solo-list (sort-by :created > (vals @solo-works))
|
|
268
|
+
room-list (sort-by (fn [s] [(if (= (:id s) invite) 0 1) (- (people-in (:id s))) (- (:created s))]) (vals @rooms))
|
|
269
|
+
inv (when invite (get @rooms invite))]
|
|
270
|
+
(set! (.-hidden el) (not open))
|
|
271
|
+
(set! (.-innerHTML ($ "work-name"))
|
|
272
|
+
(if (:kind @work)
|
|
273
|
+
(str (case (:kind @work) :room "Room" :solo "Solo" "Local") " · <b>" (esc (or (:name @work) "")) "</b>")
|
|
274
|
+
"No work open"))
|
|
275
|
+
(when open
|
|
276
|
+
;; the lists update live: whatever you are typing in the forms is kept
|
|
277
|
+
(let [keep (into {} (for [k ["new-solo" "new-room" "relay-url"] :let [i ($ k)] :when i] [k (.-value i)]))
|
|
278
|
+
keep-ex (into {} (for [k ["new-solo-ex" "new-room-ex"] :let [i ($ k)] :when i] [k (.-checked i)]))
|
|
279
|
+
focus (.. js/document -activeElement -id)]
|
|
280
|
+
(js/setTimeout
|
|
281
|
+
(fn []
|
|
282
|
+
(doseq [[k v] keep] (when-let [i ($ k)] (set! (.-value i) v)))
|
|
283
|
+
(doseq [[k v] keep-ex] (when-let [i ($ k)] (set! (.-checked i) v)))
|
|
284
|
+
(when (and (seq focus) ($ focus) (contains? keep focus)) (.focus ($ focus))))
|
|
285
|
+
0))
|
|
286
|
+
(set! (.-innerHTML ($ "mgr-body"))
|
|
287
|
+
(str
|
|
288
|
+
(when (nil? (:kind @work)) (welcome))
|
|
289
|
+
(when busy (str "<p class=\"mgr-busy\">" (esc busy) "</p>"))
|
|
290
|
+
(cond
|
|
291
|
+
connecting? "<p class=\"mgr-note\">Connecting…</p>"
|
|
292
|
+
(not db?)
|
|
293
|
+
(str "<p class=\"mgr-note\">This view has no database (outside claude.ai or not signed in): you can only work locally, without saving.</p>"
|
|
294
|
+
"<button class=\"act primary\" data-act=\"local\">Start locally</button> "
|
|
295
|
+
"<button class=\"act\" data-act=\"open-file\" title=\"A work saved as a .kairotic file: it opens as a local work\">Open a file…</button>")
|
|
296
|
+
:else
|
|
297
|
+
(str
|
|
298
|
+
(when inv
|
|
299
|
+
(str "<div class=\"invite\">You have been invited to the room <b>" (esc (:name inv)) "</b>."
|
|
300
|
+
" <button class=\"act primary\" data-act=\"open\" data-kind=\"room\" data-id=\"" (esc (:id inv)) "\">Enter</button></div>"))
|
|
301
|
+
(when-not can-write
|
|
302
|
+
"<p class=\"mgr-note\">You can enter the rooms and walk through their history, but not create or change works: your access to this artifact is read only.</p>")
|
|
303
|
+
(relay-section (:relays @mgr))
|
|
304
|
+
"<div class=\"mgr-cols\">"
|
|
305
|
+
(if (pages?)
|
|
306
|
+
"<section class=\"mgr-col\"><h3>Solo</h3><p class=\"mgr-hint\">Only you see these works: they are encrypted with a key that stays in this browser.</p>"
|
|
307
|
+
"<section class=\"mgr-col\"><h3>Solo</h3><p class=\"mgr-hint\">Only you see these works, not even whoever shares the artifact.</p>")
|
|
308
|
+
(if (seq solo-list)
|
|
309
|
+
(str "<ul class=\"items\">" (apply str (map (fn [o] (item-html :solo o)) solo-list)) "</ul>")
|
|
310
|
+
"<p class=\"mgr-empty\">You have no solo works yet.</p>")
|
|
311
|
+
(when (and can-write (uid))
|
|
312
|
+
"<form class=\"new\" data-kind=\"solo\"><input id=\"new-solo\" placeholder=\"Name of the work\" maxlength=\"60\" required><label class=\"opt\"><input type=\"checkbox\" id=\"new-solo-ex\"> with the example work</label><button class=\"act primary\">Create</button></form>")
|
|
313
|
+
"</section>"
|
|
314
|
+
(if (pages?)
|
|
315
|
+
"<section class=\"mgr-col\"><h3>Shared rooms</h3><p class=\"mgr-hint\">Anyone using this site with the same relay sees them and can enter.</p>"
|
|
316
|
+
"<section class=\"mgr-col\"><h3>Shared rooms</h3><p class=\"mgr-hint\">Anyone with access to this artifact sees them and can enter.</p>")
|
|
317
|
+
(if (seq room-list)
|
|
318
|
+
(str "<ul class=\"items\">" (apply str (map (fn [s] (item-html :room s)) room-list)) "</ul>")
|
|
319
|
+
"<p class=\"mgr-empty\">No rooms yet.</p>")
|
|
320
|
+
(when can-write
|
|
321
|
+
"<form class=\"new\" data-kind=\"room\"><input id=\"new-room\" placeholder=\"Name of the room\" maxlength=\"60\" required><label class=\"opt\"><input type=\"checkbox\" id=\"new-room-ex\"> with the example work</label><button class=\"act primary\">Create</button></form>")
|
|
322
|
+
"</section></div>"
|
|
323
|
+
"<p class=\"mgr-foot\"><button class=\"act\" data-act=\"local\">Try locally, without saving</button> <button class=\"act\" data-act=\"learn\" title=\"Tutorials and the help of every component\">Learn: tutorials and help</button>"
|
|
324
|
+
;; a work as a file (#149): open one as a new solo work, or keep the one open
|
|
325
|
+
" <button class=\"act\" data-act=\"open-file\" title=\"A work saved as a .kairotic file: it opens as a new solo work, with its whole history\">Open a file…</button>"
|
|
326
|
+
(when (:kind @work) " <button class=\"act\" data-act=\"export-file\" title=\"The open work as a .kairotic file: every line, its whole history and the sounds recorded\">Download this work</button>")
|
|
327
|
+
"</p>")))))))
|
|
328
|
+
|
|
329
|
+
(add-watch mgr ::render (fn [_ _ _ _] (render-manager!)))
|
|
330
|
+
(add-watch rooms ::render (fn [_ _ _ _] (render-manager!)))
|
|
331
|
+
(add-watch solo-works ::render (fn [_ _ _ _] (render-manager!)))
|
|
332
|
+
(add-watch lobby-peers ::render (fn [_ _ _ _] (when (:open @mgr) (render-manager!))))
|
|
333
|
+
(add-watch work ::render (fn [_ _ _ _] (render-manager!)))
|
|
334
|
+
|
|
335
|
+
(.addEventListener ($ "mgr-body") "click"
|
|
336
|
+
(fn [e]
|
|
337
|
+
(when-let [b (.closest (.-target e) "[data-act]")]
|
|
338
|
+
(let [act (.. b -dataset -act)
|
|
339
|
+
kind (keyword (.. b -dataset -kind))
|
|
340
|
+
id (.. b -dataset -id)
|
|
341
|
+
item (get (if (= kind :room) @rooms @solo-works) id)]
|
|
342
|
+
(case act
|
|
343
|
+
"open" (if (and (= kind (:kind @work)) (= id (:id @work)))
|
|
344
|
+
(hide-manager!)
|
|
345
|
+
(open-work! kind id (:name item)))
|
|
346
|
+
"copy" (let [to (keyword (.. b -dataset -to))]
|
|
347
|
+
(copy-work! kind id to (str (:name item) (if (= to :room) " (shared)" " (my copy)"))))
|
|
348
|
+
"delete" (if (= (:confirm @mgr) [(name kind) id])
|
|
349
|
+
(delete-work! kind id)
|
|
350
|
+
(do (swap! mgr assoc :confirm [(name kind) id])
|
|
351
|
+
(js/setTimeout (fn [] (when (= (:confirm @mgr) [(name kind) id]) (swap! mgr assoc :confirm nil))) 4000)))
|
|
352
|
+
"local" (open-work! :local "local" "Local")
|
|
353
|
+
"link" (let [u (room-link id)]
|
|
354
|
+
(-> (js/Promise.resolve)
|
|
355
|
+
(.then (fn [_] (.writeText (.-clipboard js/navigator) u)))
|
|
356
|
+
(.then (fn [_] (set! (.-textContent b) "Copied")))
|
|
357
|
+
(.catch (fn [_] (repl-print! "out" (esc (str "; " u)))
|
|
358
|
+
(set! (.-textContent b) "In the REPL")))
|
|
359
|
+
(.then (fn [_] (js/setTimeout (fn [] (render-manager!)) 1500)))))
|
|
360
|
+
"relay-test" (let [u (normalize-relay (.-value ($ "relay-url")))]
|
|
361
|
+
(if-let [why (relay-problem u)]
|
|
362
|
+
(reset! relay-test {:url (str/trim (.-value ($ "relay-url"))) :state :fail :msg why})
|
|
363
|
+
(test-relay! u)))
|
|
364
|
+
"relay-site" (choose-relays! "none")
|
|
365
|
+
"relay-off" (choose-relays! "off")
|
|
366
|
+
"relay-drop" (let [u (.. b -dataset -url)]
|
|
367
|
+
(choose-relays! (let [left (remove #{u} (current-relays))] (if (seq left) (str/join "," left) "off"))))
|
|
368
|
+
"learn" (do (open-work! :local "local" "Local") (show-help! nil))
|
|
369
|
+
"guide" (do (open-work! :local "local" "Local") (docs "guide"))
|
|
370
|
+
"feedback" (do (when-not (:kind @work) (open-work! :local "local" "Local")) (swap! mgr assoc :open false) (.click ($ "tab-feedback")))
|
|
371
|
+
"open-file" (open-work-file!)
|
|
372
|
+
"export-file" (gesture! "(export-work)")
|
|
373
|
+
nil)))))
|
|
374
|
+
|
|
375
|
+
(.addEventListener ($ "mgr-body") "submit"
|
|
376
|
+
(fn [e]
|
|
377
|
+
(.preventDefault e)
|
|
378
|
+
(let [f (.-target e)
|
|
379
|
+
kind (keyword (.. f -dataset -kind))]
|
|
380
|
+
(if (= kind :relay)
|
|
381
|
+
;; use this relay (only it): the page reloads syncing through it
|
|
382
|
+
(let [typed (str/trim (.-value ($ "relay-url"))) u (normalize-relay typed)]
|
|
383
|
+
(if-let [why (relay-problem u)]
|
|
384
|
+
(reset! relay-test {:url typed :state :fail :msg why})
|
|
385
|
+
(choose-relays! u)))
|
|
386
|
+
(let [nm (str/trim (.-value ($ (str "new-" (name kind)))))
|
|
387
|
+
ex (.-checked ($ (str "new-" (name kind) "-ex")))]
|
|
388
|
+
(when (seq nm) (create-work! kind nm ex)))))))
|
|
389
|
+
|
|
390
|
+
;; the relay section: open or closed stays as it was when the manager is drawn again, and while it is
|
|
391
|
+
;; open its relays' state is looked at every two seconds
|
|
392
|
+
(.addEventListener ($ "mgr-body") "toggle"
|
|
393
|
+
(fn [e] (let [t (.-target e)]
|
|
394
|
+
(when (and (= "relays" (.-id t)) (not= (boolean (.-open t)) (:relays @mgr)))
|
|
395
|
+
(swap! mgr assoc :relays (boolean (.-open t))))))
|
|
396
|
+
true)
|
|
397
|
+
(add-watch relay-status ::render (fn [_ _ _ _] (when (:open @mgr) (render-manager!))))
|
|
398
|
+
(add-watch relay-test ::render (fn [_ _ _ _] (when (:open @mgr) (render-manager!))))
|
|
399
|
+
(defonce relay-timer
|
|
400
|
+
(js/setInterval (fn [] (when (and (:open @mgr) (pages?)) (refresh-relay-status!))) 2000))
|
|
401
|
+
|
|
402
|
+
(.addEventListener ($ "open-manager") "click" (fn [_] (show-manager!)))
|
|
403
|
+
(.addEventListener ($ "mgr-close") "click" (fn [_] (hide-manager!)))
|
|
404
|
+
(.addEventListener js/document "keydown"
|
|
405
|
+
(fn [e] (when (and (= (.-key e) "Escape") (:open @mgr) (not (:merge-pick @ui))) (hide-manager!))))
|
|
406
|
+
|
|
407
|
+
;; when a compilation finishes, the status, ports and parameters of code boxes change
|
|
408
|
+
(swap! cbox/listeners assoc :page (fn [] (render-all!)))
|
|
409
|
+
|
|
410
|
+
;; ───────────────────────── transport ─────────────────────────
|
|
411
|
+
|
|
412
|
+
(.addEventListener ($ "play") "click" (fn [_] (gesture! "(play)")))
|
|
413
|
+
(.addEventListener ($ "stop") "click" (fn [_] (gesture! "(stop)")))
|
|
414
|
+
|
|
415
|
+
(-> (.-kairoticVerovio js/window)
|
|
416
|
+
(.then (fn [tk]
|
|
417
|
+
(reset! vrv tk)
|
|
418
|
+
(reset! vrv-status :ok)
|
|
419
|
+
(reset! score-cache {})
|
|
420
|
+
(render-scene (current))))
|
|
421
|
+
(.catch (fn [_]
|
|
422
|
+
(reset! vrv-status :error)
|
|
423
|
+
(render-scene (current)))))
|