Skip to content

Commit

Permalink
fix: update component on main node resize
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc authored and andelf committed Oct 4, 2022
1 parent 306ec17 commit 107af5d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/frontend/extensions/excalidraw.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[frontend.ui :as ui]
[frontend.util :as util]
[goog.object :as gobj]
[goog.functions :refer [debounce]]
[rum.core :as rum]
[frontend.mobile.util :as mobile-util]))

Expand Down Expand Up @@ -63,8 +64,14 @@
(rum/local false ::view-mode?)
(rum/local false ::grid-mode?)
(rum/local nil ::elements)
{:did-mount update-draw-content-width
:did-update update-draw-content-width}
(rum/local nil ::resize-observer)
(rum/local (random-uuid) ::uuid)
{:did-mount (fn [state]
(reset! (::resize-observer state) (js/ResizeObserver. (debounce #(reset! (::uuid state) (random-uuid)) 500)))
(.observe @(::resize-observer state) (ui/main-node))
(update-draw-content-width state))
:did-update update-draw-content-width
:will-unmount (fn [state] (.disconnect @(::resize-observer state)))}
[state data option]
(let [*draw-width (get state ::draw-width)
*zen-mode? (get state ::zen-mode?)
Expand All @@ -88,12 +95,14 @@
(editor-handler/edit-block! block :max block-uuid))}
"Edit Block"]]
[:div.draw-wrap
{:on-mouse-down (fn [e]
{:key @(::uuid state)
:on-mouse-down (fn [e]
(util/stop e)
(state/set-block-component-editing-mode! true))
:on-blur #(state/set-block-component-editing-mode! false)
:style {:width @*draw-width
:height (if wide-mode? 650 500)}}

(excalidraw
(merge
{:on-change (fn [elements app-state]
Expand All @@ -109,7 +118,7 @@
(draw/save-excalidraw!
file
(serializeAsJSON elements app-state))))))

:zen-mode-enabled @*zen-mode?
:view-mode-enabled @*view-mode?
:grid-mode-enabled @*grid-mode?
Expand Down

0 comments on commit 107af5d

Please sign in to comment.