diff --git a/src/main/frontend/components/sidebar.cljs b/src/main/frontend/components/sidebar.cljs index bd8160fe3..7c459fda1 100644 --- a/src/main/frontend/components/sidebar.cljs +++ b/src/main/frontend/components/sidebar.cljs @@ -31,7 +31,8 @@ [frontend.context.i18n :as i18n] [reitit.frontend.easy :as rfe] [goog.dom :as gdom] - [frontend.handler.web.nfs :as nfs-handler])) + [frontend.handler.web.nfs :as nfs-handler] + [cljs-drag-n-drop.core :as dnd])) (defn nav-item [title href svg-d active? close-modal-fn] @@ -105,7 +106,17 @@ [:div.flex-1.h-0.overflow-y-auto (sidebar-nav route-match close-fn)]]]) -(rum/defc main +(rum/defc main < + {:did-mount (fn [state] + (when-let [element (gdom/getElement "main-content")] + (dnd/subscribe! + element + :upload-files + {:drop (fn [e files] + (when-let [id (state/get-edit-input-id)] + (let [format (:block/format (state/get-edit-block))] + (editor-handler/upload-asset id files format editor-handler/*asset-uploading? true))))})) + state)} [{:keys [route-match global-graph-pages? logged? home? route-name indexeddb-support? white? db-restoring? main-content]}] (ui/catch-error [:div#main-content-container.w-full.flex.justify-center diff --git a/src/main/frontend/handler/editor/lifecycle.cljs b/src/main/frontend/handler/editor/lifecycle.cljs index a9db134f0..dfb8ffa07 100644 --- a/src/main/frontend/handler/editor/lifecycle.cljs +++ b/src/main/frontend/handler/editor/lifecycle.cljs @@ -3,7 +3,6 @@ [goog.dom :as gdom] [goog.object :as gobj] [clojure.string :as string] - [cljs-drag-n-drop.core :as dnd] [frontend.handler.editor.keyboards :as keyboards-handler] [frontend.handler.page :as page-handler] [frontend.handler.editor :as editor-handler :refer [get-state]] @@ -15,20 +14,11 @@ (defn did-mount! [state] (let [[{:keys [format block-parent-id]} id] (:rum/args state) - content (get-in @state/state [:editor/content id]) - input (gdom/getElement id) - element (gdom/getElement "main-content")] + content (get-in @state/state [:editor/content id])] (when block-parent-id (state/set-editing-block-dom-id! block-parent-id)) (editor-handler/restore-cursor-pos! id content) - (when (and input element) - (dnd/subscribe! - element - :upload-files - {:drop (fn [e files] - (editor-handler/upload-asset id files format editor-handler/*asset-uploading? true))})) - ;; Here we delay this listener, otherwise the click to edit event will trigger a outside click event, ;; which will hide the editor so no way for editing. (js/setTimeout #(keyboards-handler/esc-save! state) 100) @@ -46,15 +36,6 @@ [state] (let [{:keys [id value format block repo config]} (get-state) file? (:file? config)] - (when-let [input (gdom/getElement id)] - ;; (.removeEventListener input "paste" (fn [event] - ;; (append-paste-doc! format event))) - (let [s (str "cljs-drag-n-drop." :upload-images) - element (gdom/getElement "main-content") - a (gobj/get element s) - timer (:timer a)] - (when (and element timer) - (dnd/unsubscribe! element :upload-files)))) (editor-handler/clear-when-saved!) ;; TODO: ugly (when-not (contains? #{:insert :indent-outdent :auto-save :undo :redo :delete} (state/get-editor-op))