mirror of
https://github.com/logseq/logseq.git
synced 2026-05-01 01:16:27 +00:00
enhance(capacitor): WIP blocks content and editor
This commit is contained in:
44
src/main/capacitor/components/editor.cljs
Normal file
44
src/main/capacitor/components/editor.cljs
Normal file
@@ -0,0 +1,44 @@
|
||||
(ns capacitor.components.editor
|
||||
(:require [rum.core :as rum]
|
||||
[capacitor.ionic :as ionic]
|
||||
[frontend.handler.notification :as notification]))
|
||||
|
||||
(rum/defc editor-aux
|
||||
[content {:keys [on-outside!]}]
|
||||
|
||||
(let [*input (rum/use-ref nil)]
|
||||
|
||||
(rum/use-effect!
|
||||
(fn []
|
||||
(let [timer (js/requestAnimationFrame
|
||||
(fn []
|
||||
(when-let [^js input (some-> (rum/deref *input)
|
||||
(.querySelector "textarea"))]
|
||||
(.focus input)
|
||||
(let [len (.-length (.-value input))]
|
||||
(.setSelectionRange input len len))
|
||||
;(.scrollIntoView input #js {:behavior "smooth", :block "start"})
|
||||
)))]
|
||||
#(js/clearTimeout timer)))
|
||||
[])
|
||||
|
||||
(rum/use-effect!
|
||||
(fn []
|
||||
(let [handle-outside! (fn [^js e]
|
||||
(when-not (some-> e (.-target) (.closest ".editor-aux-input"))
|
||||
(on-outside! e)))]
|
||||
(js/window.addEventListener "mousedown" handle-outside!)
|
||||
#(js/window.removeEventListener "mousedown" handle-outside!)))
|
||||
[])
|
||||
|
||||
(ionic/ion-textarea
|
||||
{:class "editor-aux-input bg-gray-100 border"
|
||||
:ref *input
|
||||
:auto-grow true
|
||||
:autofocus true
|
||||
:value content})))
|
||||
|
||||
(rum/defc content-aux
|
||||
[content & opts]
|
||||
|
||||
[:p content])
|
||||
Reference in New Issue
Block a user