Skip to content

Commit 5a293a0

Browse files
authored
Merge pull request #8 from Cirru/migrate-cirru
migrate to stack.cirru storage file
2 parents b6c2736 + f4d89b1 commit 5a293a0

29 files changed

+1916
-3334
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Stack Editor
1919
npm install -g stack-editor
2020
```
2121

22-
Create `ir.edn`:
22+
Create `stack.cirru`:
2323

2424
```clojure
2525
{:package "demo"
@@ -29,7 +29,7 @@ Create `ir.edn`:
2929
Run editor:
3030

3131
```bash
32-
stack-editor ir.edn
32+
stack-editor stack.cirru
3333
```
3434

3535
![Command Line](https://pbs.twimg.com/media/DClMKBMUIAAL5X5.png:large)
@@ -49,7 +49,7 @@ For the UI part of the editor, it's based on the address:
4949
For the [server part](https://github.com/Cirru/stack-server), is an npm command line:
5050

5151
```bash
52-
op=watch port=7010 extension=.cljs out=src/ stack-editor ir.edn
52+
op=watch port=7010 extension=.cljs out=src/ stack-editor stack.cirru
5353
```
5454

5555
* `port`, defaults to `7010`, server port corresponding to the UI part

ir.edn

-2,988
This file was deleted.

src/app/actions.cljs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
(defonce *remote-sepal (atom nil))
1010

11+
(defn display-code! [store]
12+
(let [writer (:writer store)
13+
collection (:collection store)
14+
path-info (get (:stack writer) (:pointer writer))
15+
tree (get-in store (make-path path-info))]
16+
(if (some? tree)
17+
(-> js/window (.open) (.-document) (.write "<pre><code>" (pr-str tree) "</code></pre>")))))
18+
1119
(def options
1220
(merge {"port" "7010", "host" "localhost"} (parse-query (.-search js/location))))
1321

@@ -59,11 +67,3 @@
5967
(dispatch! :notification/add-one "Connection failed!")
6068
(let [response (read-string (:response error))]
6169
(dispatch! :notification/add-one (:status response)))))}))
62-
63-
(defn display-code! [store]
64-
(let [writer (:writer store)
65-
collection (:collection store)
66-
path-info (get (:stack writer) (:pointer writer))
67-
tree (get-in store (make-path path-info))]
68-
(if (some? tree)
69-
(-> js/window (.open) (.-document) (.write "<pre><code>" (pr-str tree) "</code></pre>")))))

src/app/comp/brief_file.cljs

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
[app.style.widget :as widget]
99
[app.util.keycode :as keycode]))
1010

11-
(defn on-input [e d! m!] (m! (:value e)))
11+
(defn on-edit-def [ns-text def-text]
12+
(fn [e dispatch!]
13+
(dispatch! :collection/edit {:kind :defs, :ns ns-text, :extra def-text, :focus [2]})))
14+
15+
(defn on-edit-ns [ns-text]
16+
(fn [e dispatch!]
17+
(dispatch! :collection/edit {:kind :ns, :ns ns-text, :extra nil, :focus []})))
1218

1319
(defn on-edit-procs [ns-text]
1420
(fn [e dispatch!]
1521
(dispatch! :collection/edit {:kind :procs, :ns ns-text, :extra nil, :focus []})))
1622

17-
(def style-link {:cursor :pointer})
18-
19-
(defn on-remove [ns-text] (fn [e d! m!] (d! :collection/remove-file ns-text)))
23+
(defn on-input [e d! m!] (m! (:value e)))
2024

2125
(defn on-keydown [ns-text def-text]
2226
(fn [e d! m!]
@@ -25,16 +29,12 @@
2529
(if (not (string/blank? def-text))
2630
(do (d! :collection/add-definition [ns-text def-text]) (m! ""))))))
2731

28-
(defn on-edit-ns [ns-text]
29-
(fn [e dispatch!]
30-
(dispatch! :collection/edit {:kind :ns, :ns ns-text, :extra nil, :focus []})))
31-
32-
(defn on-edit-def [ns-text def-text]
33-
(fn [e dispatch!]
34-
(dispatch! :collection/edit {:kind :defs, :ns ns-text, :extra def-text, :focus [2]})))
32+
(defn on-remove [ns-text] (fn [e d! m!] (d! :collection/remove-file ns-text)))
3533

3634
(def style-file {:padding "16px", :font-size 16, :line-height 1.6})
3735

36+
(def style-link {:cursor :pointer})
37+
3838
(defcomp
3939
comp-brief-file
4040
(states ns-text file)

src/app/comp/command.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
[respo.core :refer [defcomp div <> span input]]
55
[hsl.core :refer [hsl]]))
66

7+
(defn on-click [on-select] (fn [e dispatch!] (on-select dispatch!)))
8+
79
(def style-command
810
{:backgroud-color (hsl 0 0 0),
911
:padding "0 8px",
1012
:line-height 2.4,
1113
:font-family "Source Code Pro, Menlo,monospace",
1214
:cursor "pointer"})
1315

14-
(defn on-click [on-select] (fn [e dispatch!] (on-select dispatch!)))
15-
1616
(defcomp
1717
comp-command
1818
(command selected? on-select)

src/app/comp/def.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
(def style-circular {:text-decoration :underline})
1919

20+
(def style-count {:font-size 12, :color (hsl 0 0 100 0.4)})
21+
2022
(def style-def
2123
{:color (hsl 0 0 70 0.7), :font-size 14, :cursor :pointer, :white-space :nowrap})
2224

2325
(def style-external {:color (hsl 260 16 44), :font-size 12, :cursor :default})
2426

2527
(def style-highlight {:color (hsl 0 0 100 0.86)})
2628

27-
(def style-count {:font-size 12, :color (hsl 0 0 100 0.4)})
28-
2929
(defcomp
3030
comp-def
3131
(child-node path selected?)

src/app/comp/file_tree.cljs

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,9 @@
1010
[app.style.widget :as widget]
1111
[app.util.keycode :as keycode]))
1212

13-
(def style-body {:flex 1, :overflow :auto})
14-
15-
(def style-highlight {:color (hsl 0 0 100 0.9)})
16-
17-
(def style-toolbar {:padding "16px 16px"})
18-
19-
(def style-column {:padding "16px 16px", :min-width 80, :line-height 1.6, :overflow :auto})
20-
21-
(defn on-view [path ns-piece]
22-
(fn [e dispatch!] (dispatch! :graph/view-ns (conj path ns-piece))))
23-
2413
(defn on-change [cursor] (fn [e dispatch!] (dispatch! :states [cursor (:value e)])))
2514

26-
(def style-file-tree {:background-color (hsl 0 0 0)})
15+
(defn on-graph [e dispatch!] (dispatch! :router/route {:name :graph, :data nil}))
2716

2817
(defn on-keydown [state cursor]
2918
(fn [e dispatch!]
@@ -34,10 +23,13 @@
3423
(dispatch! :collection/add-namespace state))
3524
(dispatch! :states [cursor ""])))))
3625

37-
(defn on-graph [e dispatch!] (dispatch! :router/route {:name :graph, :data nil}))
38-
3926
(defn on-stack [e d! m!] (d! :router/route {:name :workspace, :data nil}))
4027

28+
(defn on-view [path ns-piece]
29+
(fn [e dispatch!] (dispatch! :graph/view-ns (conj path ns-piece))))
30+
31+
(def style-toolbar {:padding "16px 16px"})
32+
4133
(defn render-toolbar [state cursor]
4234
(div
4335
{:style style-toolbar}
@@ -52,9 +44,17 @@
5244
:on-input (on-change cursor),
5345
:on-keydown (on-keydown state cursor)})))
5446

47+
(def style-body {:flex 1, :overflow :auto})
48+
49+
(def style-column {:padding "16px 16px", :min-width 80, :line-height 1.6, :overflow :auto})
50+
5551
(def style-file
5652
{:cursor :pointer, :color (hsl 0 0 100 0.5), :white-space :nowrap, :font-size 16})
5753

54+
(def style-file-tree {:background-color (hsl 0 0 0)})
55+
56+
(def style-highlight {:color (hsl 0 0 100 0.9)})
57+
5858
(defcomp
5959
comp-file-tree
6060
(states store)

src/app/comp/graph.cljs

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@
99
[app.style.widget :as widget]
1010
[clojure.set :as set]))
1111

12-
(def style-body {:flex 1, :overflow :auto})
13-
14-
(def style-graph {:background-color (hsl 0 0 0), :overflow :auto})
15-
16-
(defn on-load [e dispatch!] (dispatch! :graph/load-graph nil))
17-
18-
(def style-toolbar {:padding 16})
12+
(defn on-edit [e dispatch!] (dispatch! :graph/edit-current nil))
1913

2014
(defn on-files [e dispatch!] (dispatch! :router/route {:name :file-tree, :data nil}))
2115

22-
(def style-column {:min-width 80, :overflow :auto, :padding "16px 16px", :flex-shrink 0})
16+
(defn on-load [e dispatch!] (dispatch! :graph/load-graph nil))
2317

2418
(defn on-orphans [e dispatch!] (dispatch! :graph/show-orphans nil))
2519

26-
(defn on-edit [e dispatch!] (dispatch! :graph/edit-current nil))
20+
(def style-toolbar {:padding 16})
2721

2822
(defn render-toolbar []
2923
(div
@@ -38,6 +32,12 @@
3832
(=< 8 nil)
3933
(button {:inner-text "Find orphans", :style widget/button, :on-click on-orphans}))))
4034

35+
(def style-body {:flex 1, :overflow :auto})
36+
37+
(def style-column {:min-width 80, :overflow :auto, :padding "16px 16px", :flex-shrink 0})
38+
39+
(def style-graph {:background-color (hsl 0 0 0), :overflow :auto})
40+
4141
(defcomp
4242
comp-graph
4343
(store)

src/app/comp/hydrate.cljs

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
[cljs.reader :refer [read-string]]
99
[app.util.detect :refer [cirru-vec?]]))
1010

11+
(defn on-change [cursor] (fn [e dispatch!] (dispatch! :states [cursor (:value e)])))
12+
13+
(defn on-hydrate [text]
14+
(fn [e dispatch!]
15+
(let [piece (read-string text)]
16+
(if (cirru-vec? piece)
17+
(do (dispatch! :collection/hydrate piece) (dispatch! :modal/recycle nil))
18+
(dispatch! :notification/add-one (str "Checking failed: " (pr-str text)))))))
19+
20+
(def style-hint {:font-family "Hind"})
21+
1122
(def style-textarea
1223
{:background-color (hsl 0 0 100 0.2),
1324
:font-family "Source Code Pro, Menlo",
@@ -17,19 +28,8 @@
1728
:height 200,
1829
:line-height "24px"})
1930

20-
(def style-hint {:font-family "Hind"})
21-
2231
(def style-toolbar {:justify-content :flex-end})
2332

24-
(defn on-change [cursor] (fn [e dispatch!] (dispatch! :states [cursor (:value e)])))
25-
26-
(defn on-hydrate [text]
27-
(fn [e dispatch!]
28-
(let [piece (read-string text)]
29-
(if (cirru-vec? piece)
30-
(do (dispatch! :collection/hydrate piece) (dispatch! :modal/recycle nil))
31-
(dispatch! :notification/add-one (str "Checking failed: " (pr-str text)))))))
32-
3333
(defcomp
3434
comp-hydrate
3535
(states)

src/app/comp/modal_stack.cljs

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@
88
[app.comp.hydrate :refer [comp-hydrate]]
99
[app.comp.orphans :refer [comp-orphans]]))
1010

11+
(defn on-recycle [e dispatch!] (dispatch! :modal/recycle nil))
12+
1113
(defn on-tip [e dispatch!] )
1214

15+
(defn renderer [states kind title data]
16+
(div
17+
{}
18+
(case title
19+
:rename-path (comp-rename-path (>> states :rename-path) data)
20+
:hydrate (comp-hydrate (>> states :hydrate))
21+
:orphans (comp-orphans data)
22+
(<> span title nil))))
23+
1324
(def style-modal
1425
(merge
1526
ui/center
@@ -21,17 +32,6 @@
2132
:width "100%",
2233
:height "100%"}))
2334

24-
(defn on-recycle [e dispatch!] (dispatch! :modal/recycle nil))
25-
26-
(defn renderer [states kind title data]
27-
(div
28-
{}
29-
(case title
30-
:rename-path (comp-rename-path (>> states :rename-path) data)
31-
:hydrate (comp-hydrate (>> states :hydrate))
32-
:orphans (comp-orphans data)
33-
(<> span title nil))))
34-
3535
(defcomp
3636
comp-modal-stack
3737
(states modal-stack)

src/app/comp/orphans.cljs

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
[respo.core :refer [defcomp div list-> <> span input]]
55
[respo-ui.core :as ui]))
66

7-
(def style-container
8-
{:width 800, :height 400, :overflow :auto, :padding 16, :background (hsl 0 0 0 0.9)})
9-
10-
(def style-def {:min-width 200, :display :inline-block, :cursor :pointer})
11-
12-
(def style-title {:font-size 24, :font-weight 100, :font-family "Josefin Sans"})
13-
147
(defn on-edit [def-info]
158
(fn [e dispatch!]
169
(dispatch!
1710
:collection/edit
1811
{:kind :defs, :ns (:ns def-info), :extra (:def def-info), :focus [1]})
1912
(dispatch! :modal/recycle nil)))
2013

14+
(def style-container
15+
{:width 800, :height 400, :overflow :auto, :padding 16, :background (hsl 0 0 0 0.9)})
16+
17+
(def style-def {:min-width 200, :display :inline-block, :cursor :pointer})
18+
19+
(def style-title {:font-size 24, :font-weight 100, :font-family "Josefin Sans"})
20+
2121
(defcomp
2222
comp-orphans
2323
(orphans)

src/app/comp/palette.cljs

+10-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
[app.style.widget :as widget]
1111
[app.util.detect :refer [fuzzy-search]]))
1212

13-
(defn on-input [cursor state]
14-
(fn [e dispatch!] (dispatch! :states [cursor (merge state {:text (:value e), :cursor 0})])))
13+
(def basic-commands [[:save] [:load] [:hydrate] [:dehydrate] [:graph]])
1514

1615
(defn handle-command [cursor commands files dispatch!]
1716
(let [command (get (into [] commands) cursor)]
@@ -37,18 +36,12 @@
3736
(do
3837
(dispatch!
3938
:collection/edit
40-
{:ns (get command 1), :kind :procs, :extra nil, :focus [0]}))
41-
nil)))
42-
43-
(def style-container
44-
{:position "fixed", :background-color (hsl 200 40 10 0.8), :justify-content "center"})
45-
46-
(defn on-select [cursor commands files]
47-
(fn [dispatch!] (handle-command cursor commands files dispatch!)))
39+
{:ns (get command 1), :kind :procs, :extra nil, :focus [0]})))))
4840

4941
(def initial-state {:text "", :cursor 0})
5042

51-
(def basic-commands [[:save] [:load] [:hydrate] [:dehydrate] [:graph]])
43+
(defn on-input [cursor state]
44+
(fn [e dispatch!] (dispatch! :states [cursor (merge state {:text (:value e), :cursor 0})])))
5245

5346
(defn on-keydown [respo-cursor state commands cursor collection]
5447
(fn [e dispatch!]
@@ -71,6 +64,12 @@
7164
(handle-command cursor commands collection dispatch!))
7265
:else nil))))
7366

67+
(defn on-select [cursor commands files]
68+
(fn [dispatch!] (handle-command cursor commands files dispatch!)))
69+
70+
(def style-container
71+
{:position "fixed", :background-color (hsl 200 40 10 0.8), :justify-content "center"})
72+
7473
(defcomp
7574
comp-palette
7675
(states files)

src/app/comp/rename_path.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
(defn on-input [e dispatch! m!] (m! (:value e)))
1414

15-
(defn on-rename [code-path text]
16-
(fn [e d! m!] (d! :collection/rename [code-path text]) (d! :modal/recycle nil) (m! nil)))
17-
1815
(defn on-keydown [code-path text]
1916
(fn [e d! m!]
2017
(println keycode/key-esc)
@@ -24,6 +21,9 @@
2421
(= (:key-code e) keycode/key-esc) (d! :modal/recycle nil)
2522
:else nil)))
2623

24+
(defn on-rename [code-path text]
25+
(fn [e d! m!] (d! :collection/rename [code-path text]) (d! :modal/recycle nil) (m! nil)))
26+
2727
(defcomp
2828
comp-rename-path
2929
(states code-path)

0 commit comments

Comments
 (0)