Browse Source

fix: error on reference click

Konstantinos Kaloutas 3 years ago
parent
commit
e919df3d9a
2 changed files with 13 additions and 13 deletions
  1. 12 12
      src/main/frontend/handler/whiteboard.cljs
  2. 1 1
      src/main/frontend/state.cljs

+ 12 - 12
src/main/frontend/handler/whiteboard.cljs

@@ -158,18 +158,18 @@
   "Given the block uuid, add a new shape to the referenced block.
    By default it will be placed next to the given shape id"
   [block-uuid source-shape & {:keys [link? bottom?]}]
-  (let [app (state/active-tldraw-app)
-        ^js api (.-api app)
-        point (-> (.getShapeById app source-shape)
-                  (.-bounds)
-                  ((fn [bounds] (if bottom?
-                                  [(.-minX bounds) (+ 64 (.-maxY bounds))]
-                                  [(+ 64 (.-maxX bounds)) (.-minY bounds)]))))
-        shape (->logseq-portal-shape block-uuid point)]
-    (when (uuid? block-uuid) (editor-handler/set-blocks-id! [block-uuid]))
-    (.createShapes api (clj->js shape))
-    (when link?
-      (.createNewLineBinding api source-shape (:id shape)))))
+  (when-let [app (state/active-tldraw-app)]
+    (let [^js api (.-api app)
+          point (-> (.getShapeById app source-shape)
+                    (.-bounds)
+                    ((fn [bounds] (if bottom?
+                                    [(.-minX bounds) (+ 64 (.-maxY bounds))]
+                                    [(+ 64 (.-maxX bounds)) (.-minY bounds)]))))
+          shape (->logseq-portal-shape block-uuid point)]
+      (when (uuid? block-uuid) (editor-handler/set-blocks-id! [block-uuid]))
+      (.createShapes api (clj->js shape))
+      (when link?
+        (.createNewLineBinding api source-shape (:id shape))))))
 
 (defn page-name->tldr!
   ([page-name]

+ 1 - 1
src/main/frontend/state.cljs

@@ -1562,7 +1562,7 @@ Similar to re-frame subscriptions"
 
 (defn active-tldraw-app
   []
-  (when-let [tldraw-el (.closest js/document.activeElement ".logseq-tldraw[data-tlapp]")]
+  (when-let [tldraw-el (.querySelector js/document.body ".logseq-tldraw[data-tlapp]")]
     (gobj/get js/window.tlapps (.. tldraw-el -dataset -tlapp))))
 
 (defn tldraw-editing-logseq-block?