|
101 | 101 | n))"]]
|
102 | 102 | [editor source {:eval? true}])))
|
103 | 103 |
|
104 |
| -(defn tag [tag & s] |
105 |
| - (let [[opts s] (if (map? (first s)) [(first s) (rest s)] [nil s])] |
106 |
| - (str "<" (name tag) (reduce-kv #(str %1 " " (name %2) "=" "'" %3 "'") "" opts) ">" (apply str s) "</" (name tag) ">"))) |
107 |
| - |
108 | 104 | (defn linux? []
|
109 | 105 | (some? (re-find #"(Linux)|(X11)" js/navigator.userAgent)))
|
110 | 106 |
|
|
127 | 123 |
|
128 | 124 | (defn render-key [key]
|
129 | 125 | (let [keys (into [] (map #(get ((memoize key-mapping)) % %) (str/split key #"-")))]
|
130 |
| - (tag :span |
131 |
| - (str/join (tag :span " + ") (map (partial tag :kdb {:class "kbd"}) keys))))) |
| 126 | + (into [:span] |
| 127 | + (map-indexed (fn [i k] |
| 128 | + [:<> |
| 129 | + (when-not (zero? i) [:span " + "]) |
| 130 | + [:kbd.kbd k]]) keys)))) |
| 131 | + |
| 132 | +(defn key-bindings-table [] |
| 133 | + [:table.w-full.text-sm |
| 134 | + [:thead |
| 135 | + [:tr.border-t |
| 136 | + [:th.px-3.py-1.align-top.text-left.text-xs.uppercase.font-normal.black-50 "Command"] |
| 137 | + [:th.px-3.py-1.align-top.text-left.text-xs.uppercase.font-normal.black-50 "Keybinding"] |
| 138 | + [:th.px-3.py-1.align-top.text-left.text-xs.uppercase.font-normal.black-50 "Alternate Binding"] |
| 139 | + [:th.px-3.py-1.align-top.text-left.text-xs.uppercase.font-normal.black-50 {:style {:min-width 290}} "Description"]]] |
| 140 | + (into [:tbody] |
| 141 | + (->> keymap/paredit-keymap* |
| 142 | + (merge (sci/keymap* "Alt")) |
| 143 | + (sort-by first) |
| 144 | + (map (fn [[command [{:keys [key shift doc]} & [{alternate-key :key}]]]] |
| 145 | + [:<> |
| 146 | + [:tr.border-t.hover:bg-gray-100 |
| 147 | + [:td.px-3.py-1.align-top.monospace.whitespace-no-wrap [:b (name command)]] |
| 148 | + [:td.px-3.py-1.align-top.text-right.text-sm.whitespace-no-wrap (render-key key)] |
| 149 | + [:td.px-3.py-1.align-top.text-right.text-sm.whitespace-no-wrap (some-> alternate-key render-key)] |
| 150 | + [:td.px-3.py-1.align-top doc]] |
| 151 | + (when shift |
| 152 | + [:tr.border-t.hover:bg-gray-100 |
| 153 | + [:td.px-3.py-1.align-top [:b (name shift)]] |
| 154 | + [:td.px-3.py-1.align-top.text-sm.whitespace-no-wrap.text-right |
| 155 | + (render-key (str "Shift-" key))] |
| 156 | + [:td.px-3.py-1.align-top.text-sm] |
| 157 | + [:td.px-3.py-1.align-top]])]))))]) |
132 | 158 |
|
133 | 159 | (defn ^:dev/after-load render []
|
134 | 160 | (rdom/render [samples] (js/document.getElementById "editor"))
|
| 161 | + |
135 | 162 | (.. (js/document.querySelectorAll "[clojure-mode]")
|
136 | 163 | (forEach #(when-not (.-firstElementChild %)
|
137 | 164 | (rdom/render [editor (str/trim (.-innerHTML %))] %))))
|
|
141 | 168 | (forEach #(when-let [k (get mapping (.-innerHTML %))]
|
142 | 169 | (set! (.-innerHTML %) k)))))
|
143 | 170 |
|
144 |
| - (j/assoc! (js/document.getElementById "docs") |
145 |
| - :innerHTML |
146 |
| - (tag :div |
147 |
| - (tag :h2 {:class "text-center text-3xl font-bold mt-0 mb-12"} |
148 |
| - (tag :a {:class "near-black" :href "#keybindings"} "🎹 Keybindings")) |
149 |
| - (tag :table {:cellpadding 0 :class "w-full text-sm"} |
150 |
| - (tag :tr |
151 |
| - {:class "border-t even:bg-gray-100"} |
152 |
| - (tag :th {:class "px-3 py-1 align-top text-left text-xs uppercase font-normal black-50"} "Command") |
153 |
| - (tag :th {:class "px-3 py-1 align-top text-left text-xs uppercase font-normal black-50"} "Keybinding") |
154 |
| - (tag :th {:class "px-3 py-1 align-top text-left text-xs uppercase font-normal black-50"} "Alternate Binding") |
155 |
| - (tag :th {:class "px-3 py-1 align-top text-left text-xs uppercase font-normal black-50" :style "min-width: 290px;"} "Description")) |
156 |
| - (->> keymap/paredit-keymap* |
157 |
| - (merge (sci/keymap* "Alt")) |
158 |
| - (sort-by first) |
159 |
| - (reduce (fn [out [command [{:keys [key shift doc]} & [{alternate-key :key}]]]] |
160 |
| - (str out |
161 |
| - (tag :tr |
162 |
| - {:class "border-t hover:bg-gray-100"} |
163 |
| - (tag :td {:class "px-3 py-1 align-top monospace whitespace-no-wrap"} (tag :b (name command))) |
164 |
| - (tag :td {:class "px-3 py-1 align-top text-right text-sm whitespace-no-wrap"} (render-key key)) |
165 |
| - (tag :td {:class "px-3 py-1 align-top text-right text-sm whitespace-no-wrap"} (some-> alternate-key render-key)) |
166 |
| - (tag :td {:class "px-3 py-1 align-top"} doc)) |
167 |
| - (when shift |
168 |
| - (tag :tr |
169 |
| - {:class "border-t hover:bg-gray-100"} |
170 |
| - (tag :td {:class "px-3 py-1 align-top"} (tag :b (name shift))) |
171 |
| - (tag :td {:class "px-3 py-1 align-top text-sm whitespace-no-wrap text-right"} |
172 |
| - (render-key (str "Shift-" key))) |
173 |
| - (tag :td {:class "px-3 py-1 align-top text-sm"}) |
174 |
| - (tag :td {:class "px-3 py-1 align-top"} ""))))) ""))))) |
| 171 | + (rdom/render [key-bindings-table] (js/document.getElementById "docs")) |
175 | 172 |
|
176 | 173 | (when (linux?)
|
177 | 174 | (js/twemoji.parse (.-body js/document))))
|
0 commit comments