editor.cljs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. (ns frontend.components.editor
  2. (:require [clojure.string :as string]
  3. [frontend.commands :as commands
  4. :refer [*first-command-group *matched-block-commands *matched-commands]]
  5. [frontend.components.block :as block]
  6. [frontend.components.datetime :as datetime-comp]
  7. [frontend.components.search :as search]
  8. [frontend.components.svg :as svg]
  9. [frontend.context.i18n :refer [t]]
  10. [frontend.db :as db]
  11. [frontend.db.model :as db-model]
  12. [frontend.extensions.zotero :as zotero]
  13. [frontend.handler.editor :as editor-handler :refer [get-state]]
  14. [frontend.handler.editor.lifecycle :as lifecycle]
  15. [frontend.handler.page :as page-handler]
  16. [frontend.handler.paste :as paste-handler]
  17. [frontend.mixins :as mixins]
  18. [frontend.modules.shortcut.core :as shortcut]
  19. [frontend.state :as state]
  20. [frontend.ui :as ui]
  21. [frontend.util :as util]
  22. [frontend.util.cursor :as cursor]
  23. [frontend.util.keycode :as keycode]
  24. [goog.dom :as gdom]
  25. [goog.string :as gstring]
  26. [logseq.graph-parser.property :as gp-property]
  27. [logseq.graph-parser.util :as gp-util]
  28. [promesa.core :as p]
  29. [react-draggable]
  30. [rum.core :as rum]))
  31. (rum/defc commands < rum/reactive
  32. [id format]
  33. (when (= :commands (state/sub :editor/action))
  34. (let [matched (util/react *matched-commands)]
  35. (ui/auto-complete
  36. matched
  37. {:get-group-name
  38. (fn [item]
  39. (get *first-command-group (first item)))
  40. :item-render
  41. (fn [item]
  42. (let [command-name (first item)
  43. command-doc (get item 2)
  44. doc (when (state/show-command-doc?) command-doc)]
  45. (cond
  46. (string? doc)
  47. [:div {:title doc}
  48. command-name]
  49. (vector? doc)
  50. [:div.has-help
  51. command-name
  52. (ui/tippy
  53. {:html doc
  54. :interactive true
  55. :fixed-position? true
  56. :position "right"}
  57. [:small (svg/help-circle)])]
  58. :else
  59. [:div command-name])))
  60. :on-chosen
  61. (fn [chosen-item]
  62. (let [command (first chosen-item)]
  63. (reset! commands/*current-command command)
  64. (let [command-steps (get (into {} matched) command)
  65. restore-slash? (or
  66. (contains? #{"Today" "Yesterday" "Tomorrow" "Current time"} command)
  67. (and
  68. (not (fn? command-steps))
  69. (not (contains? (set (map first command-steps)) :editor/input))
  70. (not (contains? #{"Date picker" "Template" "Deadline" "Scheduled" "Upload an image"} command))))]
  71. (editor-handler/insert-command! id command-steps
  72. format
  73. {:restore? restore-slash?})
  74. (state/pub-event! [:instrument {:type :editor/command-triggered
  75. :payload {:command command}}]))))
  76. :class
  77. "black"}))))
  78. (rum/defc block-commands < rum/reactive
  79. [id format]
  80. (when (= :block-commands (state/get-editor-action))
  81. (let [matched (util/react *matched-block-commands)]
  82. (ui/auto-complete
  83. (map first matched)
  84. {:on-chosen (fn [chosen]
  85. (editor-handler/insert-command! id (get (into {} matched) chosen)
  86. format
  87. {:last-pattern commands/angle-bracket}))
  88. :class "black"}))))
  89. (defn- in-sidebar? [el]
  90. (not (.contains (.getElementById js/document "left-container") el)))
  91. (rum/defc page-search < rum/reactive
  92. {:will-unmount (fn [state] (reset! editor-handler/*selected-text nil) state)}
  93. "Embedded page searching popup"
  94. [id format]
  95. (let [action (state/sub :editor/action)]
  96. (when (contains? #{:page-search :page-search-hashtag} action)
  97. (let [pos (state/get-editor-last-pos)
  98. input (gdom/getElement id)]
  99. (when input
  100. (let [current-pos (cursor/pos input)
  101. edit-content (or (state/sub [:editor/content id]) "")
  102. sidebar? (in-sidebar? input)
  103. q (or
  104. @editor-handler/*selected-text
  105. (when (= action :page-search-hashtag)
  106. (gp-util/safe-subs edit-content pos current-pos))
  107. (when (> (count edit-content) current-pos)
  108. (gp-util/safe-subs edit-content pos current-pos))
  109. "")
  110. matched-pages (when-not (string/blank? q)
  111. (editor-handler/get-matched-pages q))
  112. matched-pages (cond
  113. (contains? (set (map util/page-name-sanity-lc matched-pages))
  114. (util/page-name-sanity-lc (string/trim q))) ;; if there's a page name fully matched
  115. (sort-by (fn [m]
  116. [(count m) m])
  117. matched-pages)
  118. (string/blank? q)
  119. nil
  120. (empty? matched-pages)
  121. (cons (str (t :new-page) ": " q) matched-pages)
  122. ;; reorder, shortest and starts-with first.
  123. :else
  124. (let [matched-pages (remove nil? matched-pages)
  125. matched-pages (sort-by
  126. (fn [m]
  127. [(not (gstring/caseInsensitiveStartsWith m q)) (count m) m])
  128. matched-pages)]
  129. (if (gstring/caseInsensitiveStartsWith (first matched-pages) q)
  130. (cons (first matched-pages)
  131. (cons (str (t :new-page) ": " q) (rest matched-pages)))
  132. (cons (str (t :new-page) ": " q) matched-pages))))]
  133. (ui/auto-complete
  134. matched-pages
  135. {:on-chosen (page-handler/on-chosen-handler input id q pos format)
  136. :on-enter #(page-handler/page-not-exists-handler input id q current-pos)
  137. :item-render (fn [page-name chosen?]
  138. [:div.preview-trigger-wrapper
  139. (block/page-preview-trigger
  140. {:children
  141. [:div.flex
  142. (when (db-model/whiteboard-page? page-name) [:span.mr-1 (ui/icon "whiteboard")])
  143. (search/highlight-exact-query page-name q)]
  144. :open? chosen?
  145. :manual? true
  146. :fixed-position? true
  147. :tippy-distance 24
  148. :tippy-position (if sidebar? "left" "right")}
  149. page-name)])
  150. :empty-placeholder [:div.text-gray-500.text-sm.px-4.py-2 "Search for a page"]
  151. :class "black"})))))))
  152. (rum/defcs block-search-auto-complete < rum/reactive
  153. {:init (fn [state]
  154. (assoc state ::result (atom nil)))
  155. :did-update (fn [state]
  156. (let [result (::result state)
  157. [edit-block _ _ q] (:rum/args state)]
  158. (p/let [matched-blocks (when-not (string/blank? q)
  159. (editor-handler/get-matched-blocks q (:block/uuid edit-block)))]
  160. (reset! result matched-blocks)))
  161. state)}
  162. [state _edit-block input id q format]
  163. (let [result (->> (rum/react (get state ::result))
  164. (remove (fn [b] (string/blank? (:block/content (db-model/query-block-by-uuid (:block/uuid b)))))))
  165. chosen-handler (editor-handler/block-on-chosen-handler input id q format)
  166. non-exist-block-handler (editor-handler/block-non-exist-handler input)]
  167. (ui/auto-complete
  168. result
  169. {:on-chosen chosen-handler
  170. :on-enter non-exist-block-handler
  171. :empty-placeholder [:div.text-gray-500.pl-4.pr-4 (t :editor/block-search)]
  172. :item-render (fn [{:block/keys [page uuid]}] ;; content returned from search engine is normalized
  173. (let [page (or (:block/original-name page)
  174. (:block/name page))
  175. repo (state/sub :git/current-repo)
  176. format (db/get-page-format page)
  177. block (db-model/query-block-by-uuid uuid)
  178. content (:block/content block)]
  179. (when-not (string/blank? content)
  180. [:.py-2 (search/block-search-result-item repo uuid format content q :block)])))
  181. :class "black"})))
  182. (rum/defcs block-search < rum/reactive
  183. {:will-unmount (fn [state]
  184. (reset! editor-handler/*selected-text nil)
  185. (state/clear-search-result!)
  186. state)}
  187. [state id _format]
  188. (when (= :block-search (state/sub :editor/action))
  189. (let [pos (state/get-editor-last-pos)
  190. input (gdom/getElement id)
  191. [id format] (:rum/args state)
  192. current-pos (cursor/pos input)
  193. edit-content (state/sub [:editor/content id])
  194. edit-block (state/get-edit-block)
  195. q (or
  196. @editor-handler/*selected-text
  197. (when (> (count edit-content) current-pos)
  198. (subs edit-content pos current-pos)))]
  199. (when input
  200. (block-search-auto-complete edit-block input id q format)))))
  201. (rum/defc template-search < rum/reactive
  202. {:will-unmount (fn [state] (reset! editor-handler/*selected-text nil) state)}
  203. [id _format]
  204. (let [pos (state/get-editor-last-pos)
  205. input (gdom/getElement id)]
  206. (when input
  207. (let [current-pos (cursor/pos input)
  208. edit-content (state/sub [:editor/content id])
  209. q (or
  210. (when (>= (count edit-content) current-pos)
  211. (subs edit-content pos current-pos))
  212. "")
  213. matched-templates (editor-handler/get-matched-templates q)
  214. non-exist-handler (fn [_state]
  215. (state/clear-editor-action!))]
  216. (ui/auto-complete
  217. matched-templates
  218. {:on-chosen (editor-handler/template-on-chosen-handler id)
  219. :on-enter non-exist-handler
  220. :empty-placeholder [:div.text-gray-500.px-4.py-2.text-sm "Search for a template"]
  221. :item-render (fn [[template _block-db-id]]
  222. template)
  223. :class "black"})))))
  224. (rum/defc property-search < rum/reactive
  225. {:will-unmount (fn [state] (reset! editor-handler/*selected-text nil) state)}
  226. [id]
  227. (let [input (gdom/getElement id)]
  228. (when input
  229. (let [q (or (:searching-property (editor-handler/get-searching-property input))
  230. "")
  231. matched-properties (editor-handler/get-matched-properties q)
  232. q-property (string/replace (string/lower-case q) #"\s+" "-")
  233. non-exist-handler (fn [_state]
  234. ((editor-handler/property-on-chosen-handler id q-property) nil))]
  235. (ui/auto-complete
  236. matched-properties
  237. {:on-chosen (editor-handler/property-on-chosen-handler id q-property)
  238. :on-enter non-exist-handler
  239. :empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property: " q-property)]
  240. :header [:div.px-4.py-2.text-sm.font-medium "Matched properties: "]
  241. :item-render (fn [property] property)
  242. :class "black"})))))
  243. (rum/defc property-value-search < rum/reactive
  244. {:will-unmount (fn [state] (reset! editor-handler/*selected-text nil) state)}
  245. [id]
  246. (let [property (:property (state/get-editor-action-data))
  247. input (gdom/getElement id)]
  248. (when (and input
  249. (not (string/blank? property)))
  250. (let [current-pos (cursor/pos input)
  251. edit-content (state/sub [:editor/content id])
  252. start-idx (string/last-index-of (subs edit-content 0 current-pos)
  253. gp-property/colons)
  254. q (or
  255. (when (>= current-pos (+ start-idx 2))
  256. (subs edit-content (+ start-idx 2) current-pos))
  257. "")
  258. q (string/triml q)
  259. matched-values (editor-handler/get-matched-property-values property q)
  260. non-exist-handler (fn [_state]
  261. ((editor-handler/property-value-on-chosen-handler id q) nil))]
  262. (ui/auto-complete
  263. matched-values
  264. {:on-chosen (editor-handler/property-value-on-chosen-handler id q)
  265. :on-enter non-exist-handler
  266. :empty-placeholder [:div.px-4.py-2.text-sm (str "Create a new property value: " q)]
  267. :header [:div.px-4.py-2.text-sm.font-medium "Matched property values: "]
  268. :item-render (fn [property-value] property-value)
  269. :class "black"})))))
  270. (rum/defcs input < rum/reactive
  271. (rum/local {} ::input-value)
  272. (mixins/event-mixin
  273. (fn [state]
  274. (mixins/on-key-down
  275. state
  276. {;; enter
  277. 13 (fn [state e]
  278. (let [input-value (get state ::input-value)
  279. input-option (:options (state/get-editor-show-input))]
  280. (when (seq @input-value)
  281. ;; no new line input
  282. (util/stop e)
  283. (let [[_id on-submit] (:rum/args state)
  284. command (:command (first input-option))]
  285. (on-submit command @input-value))
  286. (reset! input-value nil))))
  287. ;; escape
  288. 27 (fn [_state _e]
  289. (let [[id _on-submit on-cancel] (:rum/args state)]
  290. (on-cancel id)))})))
  291. [state _id on-submit _on-cancel]
  292. (when (= :input (state/sub :editor/action))
  293. (when-let [action-data (state/sub :editor/action-data)]
  294. (let [{:keys [pos options]} action-data
  295. input-value (get state ::input-value)]
  296. (when (seq options)
  297. (let [command (:command (first options))]
  298. [:div.p-2.rounded-md.shadow-lg
  299. (for [{:keys [id placeholder type autoFocus] :as input-item} options]
  300. [:div.my-3 {:key id}
  301. [:input.form-input.block.w-full.pl-2.sm:text-sm.sm:leading-5
  302. (merge
  303. (cond->
  304. {:key (str "modal-input-" (name id))
  305. :id (str "modal-input-" (name id))
  306. :type (or type "text")
  307. :on-change (fn [e]
  308. (swap! input-value assoc id (util/evalue e)))
  309. :auto-complete (if (util/chrome?) "chrome-off" "off")}
  310. placeholder
  311. (assoc :placeholder placeholder)
  312. autoFocus
  313. (assoc :auto-focus true))
  314. (dissoc input-item :id))]])
  315. (ui/button
  316. "Submit"
  317. :on-click
  318. (fn [e]
  319. (util/stop e)
  320. (on-submit command @input-value pos)))]))))))
  321. (rum/defc absolute-modal < rum/static
  322. [cp modal-name set-default-width? {:keys [top left rect]}]
  323. (let [max-height 370
  324. max-width 300
  325. offset-top 24
  326. vw-height js/window.innerHeight
  327. to-max-height (if (and (seq rect) (> vw-height max-height))
  328. (let [delta-height (- vw-height (+ (:top rect) top offset-top))]
  329. (if (< delta-height max-height)
  330. (- (max (* 2 offset-top) delta-height) 16)
  331. max-height))
  332. max-height)
  333. right-sidebar? (:ui/sidebar-open? @state/state)
  334. editing-key (first (keys (:editor/editing? @state/state)))
  335. *el (rum/use-ref nil)
  336. _ (rum/use-effect! (fn []
  337. (when-let [^js/HTMLElement cnt
  338. (and right-sidebar? editing-key
  339. (js/document.querySelector "#main-content-container"))]
  340. (when (.contains cnt (js/document.querySelector (str "#" editing-key)))
  341. (let [el (rum/deref *el)
  342. ofx (- (.-scrollWidth cnt) (.-clientWidth cnt))]
  343. (when (> ofx 0)
  344. (set! (.-transform (.-style el)) (str "translateX(-" (+ ofx 20) "px)")))))))
  345. [right-sidebar? editing-key])
  346. y-overflow-vh? (< to-max-height 130)
  347. to-max-height (if y-overflow-vh? max-height to-max-height)
  348. pos-rect (when (and (seq rect) editing-key)
  349. (:rect (cursor/get-caret-pos (state/get-input))))
  350. y-diff (when pos-rect (- (:height pos-rect) (:height rect)))
  351. style (merge
  352. {:top (+ top offset-top (if (int? y-diff) y-diff 0))
  353. :max-height to-max-height
  354. :max-width 700
  355. ;; TODO: auto responsive fixed size
  356. :width "fit-content"
  357. :z-index 11}
  358. (when set-default-width?
  359. {:width max-width})
  360. (let [^js/HTMLElement editor
  361. (js/document.querySelector ".editor-wrapper")]
  362. (if (<= (.-clientWidth editor) (+ left (if set-default-width? max-width 500)))
  363. {:right 0}
  364. {:left (if (or (nil? y-diff) (and y-diff (= y-diff 0))) left 0)})))]
  365. [:div.absolute.rounded-md.shadow-lg.absolute-modal
  366. {:ref *el
  367. :data-modal-name modal-name
  368. :class (if y-overflow-vh? "is-overflow-vh-y" "")
  369. :on-mouse-down (fn [e]
  370. (.stopPropagation e))
  371. :style style}
  372. cp]))
  373. (rum/defc transition-cp < rum/reactive
  374. [cp modal-name set-default-width?]
  375. (when-let [pos (:pos (state/sub :editor/action-data))]
  376. (ui/css-transition
  377. {:class-names "fade"
  378. :timeout {:enter 500
  379. :exit 300}}
  380. (absolute-modal cp modal-name set-default-width? pos))))
  381. (rum/defc image-uploader < rum/reactive
  382. [id format]
  383. [:div.image-uploader
  384. [:input
  385. {:id "upload-file"
  386. :type "file"
  387. :on-change (fn [e]
  388. (let [files (.-files (.-target e))]
  389. (editor-handler/upload-asset id files format editor-handler/*asset-uploading? false)))
  390. :hidden true}]
  391. #_:clj-kondo/ignore
  392. (when-let [uploading? (util/react editor-handler/*asset-uploading?)]
  393. (let [processing (util/react editor-handler/*asset-uploading-process)]
  394. (transition-cp
  395. [:div.flex.flex-row.align-center.rounded-md.shadow-sm.bg-base-2.px-1.py-1
  396. (ui/loading
  397. (util/format "Uploading %s%" (util/format "%2d" processing)))]
  398. "upload-file"
  399. false)))])
  400. (defn- set-up-key-down!
  401. [state format]
  402. (mixins/on-key-down
  403. state
  404. {}
  405. {:not-matched-handler (editor-handler/keydown-not-matched-handler format)}))
  406. (defn- set-up-key-up!
  407. [state input input-id]
  408. (mixins/on-key-up
  409. state
  410. {}
  411. (editor-handler/keyup-handler state input input-id)))
  412. (def search-timeout (atom nil))
  413. (defn- setup-key-listener!
  414. [state]
  415. (let [{:keys [id format]} (get-state)
  416. input-id id
  417. input (gdom/getElement input-id)]
  418. (set-up-key-down! state format)
  419. (set-up-key-up! state input input-id)))
  420. (def starts-with? clojure.string/starts-with?)
  421. (defn get-editor-style-class
  422. "Get textarea css class according to it's content"
  423. [content format]
  424. (let [content (if content (str content) "")]
  425. ;; as the function is binding to the editor content, optimization is welcome
  426. (str
  427. (if (or (> (.-length content) 1000)
  428. (string/includes? content "\n"))
  429. "multiline-block"
  430. "uniline-block")
  431. " "
  432. (case format
  433. :markdown
  434. (cond
  435. (starts-with? content "# ") "h1"
  436. (starts-with? content "## ") "h2"
  437. (starts-with? content "### ") "h3"
  438. (starts-with? content "#### ") "h4"
  439. (starts-with? content "##### ") "h5"
  440. (starts-with? content "###### ") "h6"
  441. (and (starts-with? content "---\n") (.endsWith content "\n---")) "page-properties"
  442. :else "normal-block")
  443. ;; other formats
  444. (cond
  445. (and (starts-with? content "---\n") (.endsWith content "\n---")) "page-properties"
  446. :else "normal-block")))))
  447. (defn editor-row-height-unchanged?
  448. "Check if the row height of editor textarea is changed, which happens when font-size changed"
  449. []
  450. ;; FIXME: assuming enter key is the only trigger of the height changing (under markdown editing of headlines)
  451. ;; FIXME: looking for an elegant & robust way to track the change of font-size, or wait for our own WYSIWYG text area
  452. (let [last-key (state/get-last-key-code)]
  453. (and (not= keycode/enter (:key-code last-key))
  454. (not= keycode/enter-code (:code last-key)))))
  455. (rum/defc mock-textarea <
  456. rum/static
  457. {:did-update
  458. (fn [state]
  459. (when-not (:editor/on-paste? @state/state)
  460. (try (editor-handler/handle-last-input)
  461. (catch js/Error _e
  462. nil)))
  463. (state/set-state! :editor/on-paste? false)
  464. state)}
  465. [content]
  466. [:div#mock-text
  467. {:style {:width "100%"
  468. :height "100%"
  469. :position "absolute"
  470. :visibility "hidden"
  471. :top 0
  472. :left 0}}
  473. (let [content (str content "0")]
  474. (for [[idx c] (map-indexed
  475. vector
  476. (string/split content ""))]
  477. (if (= c "\n")
  478. [:span {:id (str "mock-text_" idx)
  479. :key idx} "0" [:br]]
  480. [:span {:id (str "mock-text_" idx)
  481. :key idx} c])))])
  482. (rum/defc mock-textarea-wrapper < rum/reactive
  483. []
  484. (let [content (state/sub-edit-content)]
  485. (mock-textarea content)))
  486. (rum/defc animated-modal < rum/reactive
  487. [modal-name component set-default-width?]
  488. (when-let [pos (:pos (state/get-editor-action-data))]
  489. (ui/css-transition
  490. {:key modal-name
  491. :class-names {:enter "origin-top-left opacity-0 transform scale-95"
  492. :enter-done "origin-top-left transition opacity-100 transform scale-100"
  493. :exit "origin-top-left transition opacity-0 transform scale-95"}
  494. :timeout {:enter 0
  495. :exit 150}}
  496. (fn [_]
  497. (absolute-modal
  498. component
  499. modal-name
  500. set-default-width?
  501. pos)))))
  502. (rum/defc modals < rum/reactive
  503. "React to atom changes, find and render the correct modal"
  504. [id format]
  505. (let [action (state/sub :editor/action)]
  506. (cond
  507. (= action :commands)
  508. (animated-modal "commands" (commands id format) true)
  509. (= action :block-commands)
  510. (animated-modal "block-commands" (block-commands id format) true)
  511. (contains? #{:page-search :page-search-hashtag} action)
  512. (animated-modal "page-search" (page-search id format) true)
  513. (= :block-search action)
  514. (animated-modal "block-search" (block-search id format) true)
  515. (= :template-search action)
  516. (animated-modal "template-search" (template-search id format) true)
  517. (= :property-search action)
  518. (animated-modal "property-search" (property-search id) true)
  519. (= :property-value-search action)
  520. (animated-modal "property-value-search" (property-value-search id) true)
  521. (= :datepicker action)
  522. (animated-modal "date-picker" (datetime-comp/date-picker id format nil) false)
  523. (= :input action)
  524. (animated-modal "input" (input id
  525. (fn [command m]
  526. (editor-handler/handle-command-input command id format m))
  527. (fn []
  528. (editor-handler/handle-command-input-close id)))
  529. true)
  530. (= :zotero action)
  531. (animated-modal "zotero-search" (zotero/zotero-search id) false)
  532. :else
  533. nil)))
  534. (rum/defcs box < rum/reactive
  535. {:init (fn [state]
  536. (assoc state ::heading-level (:heading-level (first (:rum/args state)))
  537. ::id (str (random-uuid))))
  538. :did-mount (fn [state]
  539. (state/set-editor-args! (:rum/args state))
  540. state)}
  541. (mixins/event-mixin setup-key-listener!)
  542. (shortcut/mixin :shortcut.handler/block-editing-only)
  543. lifecycle/lifecycle
  544. [state {:keys [format block]} id _config]
  545. (let [content (state/sub-edit-content)
  546. heading-class (get-editor-style-class content format)]
  547. [:div.editor-inner {:class (if block "block-editor" "non-block-editor")}
  548. (ui/ls-textarea
  549. {:id id
  550. :cacheMeasurements (editor-row-height-unchanged?) ;; check when content updated (as the content variable is binded)
  551. :default-value (or content "")
  552. :minRows (if (state/enable-grammarly?) 2 1)
  553. :on-click (editor-handler/editor-on-click! id)
  554. :on-change (editor-handler/editor-on-change! block id search-timeout)
  555. :on-paste (paste-handler/editor-on-paste! id)
  556. :auto-focus false
  557. :class heading-class})
  558. (mock-textarea-wrapper)
  559. (modals id format)
  560. (when format
  561. (image-uploader id format))]))