Skip to content

Commit 7dab066

Browse files
committed
Add with-view
1 parent ad979de commit 7dab066

File tree

9 files changed

+61
-10
lines changed

9 files changed

+61
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.2.5
2+
3+
* Add `with-view`, to open up a run-time html view
4+
15
# 0.2.4
26

37
* Update to react 18

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "interactive-syntax",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/LeifAndersen/interactive-syntax-clojure.git"

src/injectable/core.inject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
(def println private/println)
66
(def css private/css)
77
(def render-visr private/render-visr)
8+
(def with-view private/with-view)
89
(defmacro defvisr [name & props]
910
(let [{:keys [render
1011
elaborate

src/interactive_syntax/core.cljs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,8 @@
10471047
runner
10481048
running?
10491049
insert-visr!
1050-
fs]
1050+
fs
1051+
app-pane]
10511052
:as db}]
10521053
(let [new-file (if @file-changed
10531054
#(swap! menu conj [:confirm-save :new])
@@ -1077,7 +1078,12 @@
10771078
print-buffer #(swap! menu conj :print)
10781079
run+pause (fn []
10791080
(reset! output #queue [])
1080-
(env/eval-buffer db))]
1081+
(env/eval-buffer db))
1082+
stop (fn []
1083+
(reset! app-pane false))
1084+
fullscreen (fn []
1085+
(-> js/document (.getElementById "internalAppContainer")
1086+
(.requestFullscreen)))]
10811087
[:div
10821088
[:div {:class-name "d-block d-md-none"}
10831089
[:> Row {:class-name "align-items-center flex-nowrap"
@@ -1118,12 +1124,16 @@
11181124
:style {:padding-right 0}}
11191125
[:> Dropdown {:as ButtonGroup
11201126
:size "sm"}
1127+
(when @app-pane
1128+
[:> Button {:on-click fullscreen
1129+
:variant "warning"}
1130+
strings/FULLSCREEN])
11211131
[:> Button {:variant (if @running? "warning" "success")
11221132
:on-click run+pause}
11231133
(if @running? strings/PAUSE strings/RUN)]
11241134
[:> (oget Dropdown :Toggle) {:split true}]
11251135
[:> (oget Dropdown :Menu)
1126-
[:> (oget Dropdown :Item) strings/STOP]
1136+
[:> (oget Dropdown :Item) {:on-click stop} strings/STOP]
11271137
[:> (oget Dropdown :Item) {:on-click do-insert-visr}
11281138
strings/INSERT-VISR]]]]]]
11291139
[:div {:className "d-none d-md-block"}
@@ -1160,13 +1170,18 @@
11601170
[:> Col {:xs "auto"
11611171
:style {:paddingRight 0}}
11621172
[:> ButtonGroup
1173+
(when @app-pane
1174+
[:> Button {:on-click fullscreen
1175+
:variant "warning"}
1176+
strings/FULLSCREEN])
11631177
[:> Button {:on-click do-insert-visr
11641178
:variant "info"}
11651179
strings/INSERT-VISR]
11661180
[:> Button {:on-click run+pause
11671181
:variant (if @running? "warning" "success")}
11681182
(if @running? strings/PAUSE strings/RUN)]
1169-
[:> Button {:variant "danger"} strings/STOP]]]]]]))
1183+
[:> Button {:on-click stop
1184+
:variant "danger"} strings/STOP]]]]]]))
11701185

11711186
(def exclude-autocomplete-keys
11721187
{8 "backspace", 9 "tab", 13 "enter", 16 "shift", 17 "ctrl",
@@ -1443,7 +1458,7 @@
14431458
;; Views
14441459

14451460
(defn home-page [{{:keys [orientation]} :options
1446-
:keys [fs buffers output version menu split]
1461+
:keys [fs buffers output version menu split app-pane]
14471462
:as db}
14481463
& [{editor-ref :editor
14491464
editor-reset-ref :editor-reset
@@ -1516,11 +1531,21 @@
15161531
[:> SplitPane {:split @orientation
15171532
:on-change #(reset! split (aget % 0))}
15181533
[:> Pane {:initialSize @split
1519-
:style [:height "100%"]}
1534+
:style {:height "100%"}}
15201535
[editor-view db {:editor-reset editor-reset-ref
15211536
:editor editor-ref
15221537
:visr-run visr-run-ref}]]
1523-
[result-view db repl-ref]]]
1538+
(if @app-pane
1539+
[:> SplitPane {:split (utils/swap-orientation @orientation)}
1540+
[:> Pane {:initialSize 1}
1541+
[result-view db repl-ref]]
1542+
[:div {:id "internalAppContainer"
1543+
:style {:height "100%"
1544+
:width "100%"
1545+
:background-color "white"}}
1546+
[:div {:id "internalApp"}
1547+
"Open Your Heart!"]]]
1548+
[result-view db repl-ref])]]
15241549
[:div {:style {:flex "1 1 auto"
15251550
:overflow "auto"
15261551
:height "100%"

src/interactive_syntax/db.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@
179179
::split
180180
::ns
181181
::mode
182-
::repl]))
182+
::repl
183+
::app-pane]))
183184

184185
(s/def ::buffers (s/+ ::buffer))
185186
(s/def ::current nat-int?)
@@ -258,6 +259,7 @@
258259
:persist-test ""
259260
:temp "")
260261
:output ""
262+
:app-pane false
261263
:mode false
262264
:split "50%"
263265
:cursor nil
@@ -325,6 +327,7 @@
325327
:auth (->DBAtom backed-db [:auth])
326328
:input (->DBAtom backed-db [:current :input])
327329
:output (atom "") ;;(->DBAtom backed-db [:current :output])
330+
:app-pane (atom false) ;; (->DBAtom backed-db [:current :app-pane])
328331
:buffer-mode (->DBAtom backed-db [:current :mode])
329332
:ns (->DBAtom backed-db [:current :ns])
330333
:repl (atom [])

src/interactive_syntax/env.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@
756756
(def make-reset-editors-cache editor/make-reset-editors-cache)
757757
(defn reset-editors! [source set-text editor instances cache
758758
codemirror-options
759-
{{:keys [show-editors visr-default sandbox]} :options
759+
{{:keys [show-editors sandbox]} :options
760760
:keys [fs deps] :as db}
761761
cb & [{visr-run-ref :visr-run
762762
:as editor-options}]]

src/interactive_syntax/stdlib.cljs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@
9090
(reset! main @buff))
9191
(or timeout-limit 1000))))))
9292

93+
(defn with-view [{:keys [app-pane]
94+
:as db}
95+
cb & extras]
96+
(reset! app-pane true)
97+
(js/setTimeout (fn []
98+
(when (some (partial = :fullscreen) extras)
99+
(-> js/document
100+
(.getElementById "internalAppContainer")
101+
(.requestFullscreen)))
102+
(cb (.getElementById js/document "internalApp"))) 0)
103+
nil)
104+
93105
(defn parse-defvisr [name stx]
94106
(let [this (gensym 'this)]
95107
(loop [props {}
@@ -250,6 +262,7 @@
250262
:buffer_writes buffer-writes
251263
:parse_defvisr parse-defvisr
252264
:render_visr (partial render-visr db)
265+
:with_view (partial with-view db)
253266
:css css}}
254267
:reagent {:core reagent.core
255268
:dom reagent.dom}
@@ -290,6 +303,7 @@
290303
'css 'visr.private/css
291304
'render-visr 'visr.private/render-visr
292305
'parse-defvisr 'visr.private/parse-defvisr
306+
'with-view 'visr.private/with-view
293307
'buffer-writes 'visr.private/buffer-writes})
294308
(state-injection 'cljs.analyzer (ns-publics 'cljs.analyzer))
295309
(state-injection 'cljs.analyzer.api (ns-publics 'cljs.analyzer.api))

src/interactive_syntax/strings.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
(def RUN "Run")
4040
(def PAUSE "Pause")
4141
(def STOP "Stop")
42+
(def FULLSCREEN "Fullscreen")
4243

4344
(def OPTIONS-MENU "Options Menu")
4445
(def SPLIT "Split")

src/interactive_syntax/utils.cljs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@
3333
(let [node (createRoot node)]
3434
(.render node (r/as-element element)))
3535
(d/render element node)))
36+
37+
(defn swap-orientation [orientation]
38+
(if (= orientation "horizontal") "vertical" "horizontal"))

0 commit comments

Comments
 (0)