|
20 | 20 |
|
21 | 21 | (declare comp-value) |
22 | 22 |
|
23 | | -(defcomp comp-nil () (<> span "nil" widget/literal)) |
24 | | - |
25 | | -(defcomp comp-string (x) (<> span (pr-str x) widget/literal)) |
| 23 | +(defcomp comp-bool (x) (<> span (str x) widget/literal)) |
26 | 24 |
|
27 | 25 | (defcomp comp-function () (<> span "fn" widget/literal)) |
28 | 26 |
|
29 | 27 | (defcomp comp-keyword (x) (<> span (str x) widget/literal)) |
30 | 28 |
|
31 | | -(defn toggle-folding [folded?] (fn [e d! m!] (m! (not folded?)))) |
| 29 | +(defcomp comp-nil () (<> span "nil" widget/literal)) |
32 | 30 |
|
33 | 31 | (defcomp comp-number (x) (<> span (str x) widget/literal)) |
34 | 32 |
|
35 | | -(defcomp comp-bool (x) (<> span (str x) widget/literal)) |
| 33 | +(defcomp comp-string (x) (<> span (pr-str x) widget/literal)) |
| 34 | + |
| 35 | +(defn toggle-folding [folded?] (fn [e d! m!] (m! (not folded?)))) |
| 36 | + |
| 37 | +(defn render-fields [states %cursor xs level] |
| 38 | + (list-> |
| 39 | + :div |
| 40 | + {:style (merge widget/style-children layout/column)} |
| 41 | + (->> xs |
| 42 | + (map-indexed |
| 43 | + (fn [index field] |
| 44 | + [index |
| 45 | + (div |
| 46 | + {:style layout/row} |
| 47 | + (comp-value states (first field) 0) |
| 48 | + (cursor-> index comp-value states (last field) (inc level)))]))))) |
| 49 | + |
| 50 | +(defn render-children [states %cursor xs level] |
| 51 | + (list-> |
| 52 | + :div |
| 53 | + {:style (merge widget/style-children layout/column)} |
| 54 | + (->> xs |
| 55 | + (map-indexed |
| 56 | + (fn [index child] [index (cursor-> index comp-value states child (inc level))]))))) |
| 57 | + |
| 58 | +(defcomp |
| 59 | + comp-vector |
| 60 | + (states x level) |
| 61 | + (let [folded? (if (some? (:data states)) (:data states) (> level 1))] |
| 62 | + (if (and folded? (not (empty? x))) |
| 63 | + (div |
| 64 | + {:style (merge widget/structure decoration/folded), |
| 65 | + :on-click (toggle-folding folded?)} |
| 66 | + (<> span (str "[]~" (count x)) widget/only-text)) |
| 67 | + (div |
| 68 | + {:style (merge widget/structure layout/row), :on-click (toggle-folding folded?)} |
| 69 | + (<> span (str "[]") widget/only-text) |
| 70 | + (render-children states %cursor x level))))) |
36 | 71 |
|
37 | 72 | (defcomp |
38 | 73 | comp-value |
|
52 | 87 | :else |
53 | 88 | (div {:style widget/style-unknown, :attrs {:inner-text (str "unknown" (pr-str x))}})))) |
54 | 89 |
|
55 | | -(defcomp |
56 | | - comp-vector |
57 | | - (states x level) |
58 | | - (let [folded? (if (some? (:data states)) (:data states) (> level 1))] |
59 | | - (if (and folded? (not (empty? x))) |
60 | | - (div |
61 | | - {:style (merge widget/structure decoration/folded), |
62 | | - :event {:click (toggle-folding folded?)}} |
63 | | - (<> span (str "[]~" (count x)) widget/only-text)) |
64 | | - (div |
65 | | - {:style (merge widget/structure layout/row), :event {:click (toggle-folding folded?)}} |
66 | | - (<> span (str "[]") widget/only-text) |
67 | | - (render-children states *cursor* x level))))) |
68 | | - |
69 | 90 | (defcomp |
70 | 91 | comp-set |
71 | 92 | (states x level) |
72 | 93 | (let [folded? (if (some? (:data states)) (:data states) (>= level 1))] |
73 | 94 | (if (and folded? (not (empty? x))) |
74 | 95 | (div |
75 | 96 | {:style (merge widget/structure decoration/folded), |
76 | | - :event {:click (toggle-folding folded?)}} |
| 97 | + :on-click (toggle-folding folded?)} |
77 | 98 | (<> span (str "#{}~" (count x)) widget/only-text)) |
78 | 99 | (div |
79 | | - {:style (merge widget/structure layout/row), :event {:click (toggle-folding folded?)}} |
| 100 | + {:style (merge widget/structure layout/row), :on-click (toggle-folding folded?)} |
80 | 101 | (<> span (str "#{}") widget/only-text) |
81 | | - (render-children states *cursor* x level))))) |
| 102 | + (render-children states %cursor x level))))) |
82 | 103 |
|
83 | 104 | (defcomp |
84 | | - comp-list |
| 105 | + comp-map |
85 | 106 | (states x level) |
86 | 107 | (let [folded? (if (some? (:data states)) (:data states) (>= level 1))] |
87 | 108 | (if (and folded? (not (empty? x))) |
88 | 109 | (div |
89 | 110 | {:style (merge widget/structure decoration/folded), |
90 | | - :event {:click (toggle-folding folded?)}} |
91 | | - (<> span (str "'()~" (count x)) widget/only-text)) |
| 111 | + :on-click (toggle-folding folded?)} |
| 112 | + (<> span (str "{}~" (count x)) widget/only-text)) |
92 | 113 | (div |
93 | | - {:style (merge widget/structure layout/row), :event {:click (toggle-folding folded?)}} |
94 | | - (<> span (str "'()") widget/only-text) |
95 | | - (render-children states *cursor* x level))))) |
96 | | - |
97 | | -(defn render-fields [states *cursor* xs level] |
98 | | - (list-> |
99 | | - :div |
100 | | - {:style (merge widget/style-children layout/column)} |
101 | | - (->> xs |
102 | | - (map-indexed |
103 | | - (fn [index field] |
104 | | - [index |
105 | | - (div |
106 | | - {:style layout/row} |
107 | | - (comp-value states (first field) 0) |
108 | | - (cursor-> index comp-value states (last field) (inc level)))]))))) |
109 | | - |
110 | | -(defn render-children [states *cursor* xs level] |
111 | | - (list-> |
112 | | - :div |
113 | | - {:style (merge widget/style-children layout/column)} |
114 | | - (->> xs |
115 | | - (map-indexed |
116 | | - (fn [index child] [index (cursor-> index comp-value states child (inc level))]))))) |
| 114 | + {:style (merge widget/structure layout/row), :on-click (toggle-folding folded?)} |
| 115 | + (<> span "{}" widget/only-text) |
| 116 | + (render-fields states %cursor x level))))) |
117 | 117 |
|
118 | 118 | (defcomp |
119 | | - comp-map |
| 119 | + comp-list |
120 | 120 | (states x level) |
121 | 121 | (let [folded? (if (some? (:data states)) (:data states) (>= level 1))] |
122 | 122 | (if (and folded? (not (empty? x))) |
123 | 123 | (div |
124 | 124 | {:style (merge widget/structure decoration/folded), |
125 | | - :event {:click (toggle-folding folded?)}} |
126 | | - (<> span (str "{}~" (count x)) widget/only-text)) |
| 125 | + :on-click (toggle-folding folded?)} |
| 126 | + (<> span (str "'()~" (count x)) widget/only-text)) |
127 | 127 | (div |
128 | | - {:style (merge widget/structure layout/row), :event {:click (toggle-folding folded?)}} |
129 | | - (<> span "{}" widget/only-text) |
130 | | - (render-fields states *cursor* x level))))) |
| 128 | + {:style (merge widget/structure layout/row), :on-click (toggle-folding folded?)} |
| 129 | + (<> span (str "'()") widget/only-text) |
| 130 | + (render-children states %cursor x level))))) |
0 commit comments