-
Notifications
You must be signed in to change notification settings - Fork 0
/
plain_text.cljs
39 lines (36 loc) · 1.29 KB
/
plain_text.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(ns editors.plain-text
(:require [rich.core :as rich]
[reagent.core :as r]
[clojure.pprint :as pprint]))
(defonce state (r/atom nil))
(defn plain-text-editor []
[rich/editable
{:state state
:on-key-down (fn [e]
(when (and (= (.-key e) "z") (.-metaKey e))
(.preventDefault e)
(swap! state rich/do-command [:undo])))
:on-paste (fn [e]
(.preventDefault e)
(let [text (-> e .-clipboardData (.getData "Text"))]
(swap! state rich/do-command [:paste text])))}])
(defn plain-text-example []
[:div {:style {:padding "10px"
:min-height "100px"
:display "flex"
:flex-direction "row"}}
[:div {:style {:width "50%"
:border "2px solid black"}}
[plain-text-editor]]
[:div {:style {:width "50%"
:font-family "monospace"
:font-size "1.2em"
:border "2px solid black"
:white-space "pre-wrap"
:overflow-wrap "break-word"}}
(-> @state
:content
rich/minimized-hickory
rich/hickory->hiccup
pprint/pprint
with-out-str)]])