Browse Source

enhance(draw): allow edit block

cherry-pick #3983
Andelf 3 years ago
parent
commit
1bb06deeb4

+ 5 - 4
src/main/frontend/components/block.cljs

@@ -526,22 +526,23 @@
            (p/let [_ (loader/load :excalidraw)]
              (reset! excalidraw-loaded? true))
            state)}
-  [file]
+  [file block-uuid]
   (let [loaded? (rum/react excalidraw-loaded?)
         draw-component (when loaded?
                          (resolve 'frontend.extensions.excalidraw/draw))]
     (when draw-component
-      (draw-component {:file file}))))
+      (draw-component {:file file :block-uuid block-uuid}))))
 
 (rum/defc page-reference < rum/reactive
   [html-export? s config label]
   (let [show-brackets? (state/show-brackets?)
         nested-link? (:nested-link? config)
-        contents-page? (= "contents" (string/lower-case (str (:id config))))]
+        contents-page? (= "contents" (string/lower-case (str (:id config))))
+        block-uuid (:block/uuid config)]
     (if (string/ends-with? s ".excalidraw")
       [:div.draw {:on-click (fn [e]
                               (.stopPropagation e))}
-       (excalidraw s)]
+       (excalidraw s block-uuid)]
       [:span.page-reference
        {:data-ref s}
        (when (and (or show-brackets? nested-link?)

+ 12 - 7
src/main/frontend/extensions/excalidraw.cljs

@@ -3,6 +3,8 @@
             [cljs-bean.core :as bean]
             [clojure.string :as string]
             [frontend.config :as config]
+            [frontend.db :as db]
+            [frontend.handler.editor :as editor-handler]
             [frontend.handler.draw :as draw]
             [frontend.handler.notification :as notification]
             [frontend.handler.ui :as ui-handler]
@@ -59,7 +61,7 @@
         *grid-mode? (get state ::grid-mode?)
         wide-mode? (state/sub :ui/wide-mode?)
         *elements (get state ::elements)
-        file (:file option)]
+        {:keys [file block-uuid]} option]
     (when data
       [:div.overflow-hidden {:on-mouse-down (fn [e] (util/stop e))}
        [:div.my-1 {:style {:font-size 10}}
@@ -70,7 +72,10 @@
         [:a.mr-2 {:on-click #(swap! *view-mode? not)}
          (util/format "View Mode (%s)" (if @*view-mode? "ON" "OFF"))]
         [:a.mr-2 {:on-click #(swap! *grid-mode? not)}
-         (util/format "Grid Mode (%s)" (if @*view-mode? "ON" "OFF"))]]
+         (util/format "Grid Mode (%s)" (if @*view-mode? "ON" "OFF"))]
+        [:a.mr-2 {:on-click #(when-let [block (db/pull [:block/uuid block-uuid])]
+                               (editor-handler/edit-block! block :max block-uuid))}
+         "Edit Block"]]
        [:div.draw-wrap
         {:on-mouse-down (fn [e]
                           (util/stop e)
@@ -81,11 +86,11 @@
         (excalidraw
          (merge
           {:on-change (fn [elements app-state]
-                        (when-not (or (= "down" (.-cursorButton app-state))
-                                      (.-draggingElement app-state)
-                                      (.-editingElement app-state)
-                                      (.-editingGroupId app-state)
-                                      (.-editingLinearElement app-state))
+                        (when-not (or (= "down" (gobj/get app-state "cursorButton"))
+                                      (gobj/get app-state "draggingElement")
+                                      (gobj/get app-state "editingElement")
+                                      (gobj/get app-state "editingGroupId")
+                                      (gobj/get app-state "editingLinearElement"))
                           (let [elements->clj (bean/->clj elements)]
                             (when (and (seq elements->clj)
                                        (not= elements->clj @*elements)) ;; not= requires clj collections