mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
Fix mouse mixin.
This commit is contained in:
parent
3748d3c7b4
commit
3e336112ca
3 changed files with 34 additions and 32 deletions
|
@ -18,7 +18,7 @@
|
||||||
;; Workspace
|
;; Workspace
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn workspace-render
|
(defn- workspace-render
|
||||||
[own projectid]
|
[own projectid]
|
||||||
(let [workspace (rum/react wb/workspace-state )]
|
(let [workspace (rum/react wb/workspace-state )]
|
||||||
(html
|
(html
|
||||||
|
@ -43,13 +43,13 @@
|
||||||
(when-not (empty? (:toolboxes workspace))
|
(when-not (empty? (:toolboxes workspace))
|
||||||
(aside))]])))
|
(aside))]])))
|
||||||
|
|
||||||
(defn workspace-will-mount
|
(defn- workspace-will-mount
|
||||||
[own]
|
[own]
|
||||||
(let [[projectid pageid] (:rum/props own)]
|
(let [[projectid pageid] (:rum/props own)]
|
||||||
(rs/emit! (dw/initialize projectid pageid))
|
(rs/emit! (dw/initialize projectid pageid))
|
||||||
own))
|
own))
|
||||||
|
|
||||||
(defn workspace-transfer-state
|
(defn- workspace-transfer-state
|
||||||
[old-state state]
|
[old-state state]
|
||||||
(let [[projectid pageid] (:rum/props state)]
|
(let [[projectid pageid] (:rum/props state)]
|
||||||
(rs/emit! (dw/initialize projectid pageid))
|
(rs/emit! (dw/initialize projectid pageid))
|
||||||
|
|
|
@ -74,26 +74,33 @@
|
||||||
(defonce mouse-s (rx/dedupe mouse-bus))
|
(defonce mouse-s (rx/dedupe mouse-bus))
|
||||||
(defonce mouse-position (rx/to-atom (rx/throttle 50 mouse-s)))
|
(defonce mouse-position (rx/to-atom (rx/throttle 50 mouse-s)))
|
||||||
|
|
||||||
(def mouse-mixin
|
(defn- mouse-mixin-did-mount
|
||||||
{:did-mount
|
[own]
|
||||||
(fn [own]
|
(println "mouse-mixin-did-mount")
|
||||||
(let [canvas (util/get-ref-dom own "canvas")
|
(let [canvas (util/get-ref-dom own "canvas")
|
||||||
key (events/listen js/document EventType.MOUSEMOVE
|
on-mousemove (fn [event]
|
||||||
(fn [event]
|
(let [brect (.getBoundingClientRect canvas)
|
||||||
(let [brect (.getBoundingClientRect canvas)
|
offset-x (.-left brect)
|
||||||
offset-x (.-left brect)
|
offset-y (.-top brect)
|
||||||
offset-y (.-top brect)
|
x (.-clientX event)
|
||||||
x (.-clientX event)
|
y (.-clientY event)]
|
||||||
y (.-clientY event)]
|
(rx/push! mouse-bus [(- x offset-x)
|
||||||
(rx/push! mouse-bus [(- x offset-x)
|
(- y offset-y)])))
|
||||||
(- y offset-y)]))))]
|
key (events/listen js/document
|
||||||
(assoc own ::eventkey key)))
|
EventType.MOUSEMOVE
|
||||||
|
on-mousemove)]
|
||||||
|
(assoc own ::eventkey key)))
|
||||||
|
|
||||||
:did-unmount
|
(defn- mouse-mixin-will-unmount
|
||||||
(fn [own]
|
[own]
|
||||||
(let [key (::eventkey own)]
|
(println "mouse-mixin-will-unmount")
|
||||||
(events/unlistenByKey key)
|
(let [key (::eventkey own)]
|
||||||
(dissoc own ::eventkey)))})
|
(events/unlistenByKey key)
|
||||||
|
(dissoc own ::eventkey)))
|
||||||
|
|
||||||
|
(def ^:static mouse-mixin
|
||||||
|
{:did-mount mouse-mixin-did-mount
|
||||||
|
:will-unmount mouse-mixin-will-unmount})
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Constants
|
;; Constants
|
||||||
|
|
|
@ -15,20 +15,15 @@
|
||||||
;; Coordinates Debug
|
;; Coordinates Debug
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn coordenates-render
|
(defn- coordenates-render
|
||||||
[]
|
[own]
|
||||||
(let [[x y] (rum/react wb/mouse-position)]
|
(let [[x y] (rum/react wb/mouse-position)]
|
||||||
(html
|
(html
|
||||||
[:div
|
[:div {:style {:position "absolute" :left "80px" :top "20px"}}
|
||||||
{:style {:position "absolute" :left "80px" :top "20px"}}
|
|
||||||
[:table
|
[:table
|
||||||
[:tbody
|
[:tbody
|
||||||
[:tr
|
[:tr [:td "X:"] [:td x]]
|
||||||
[:td "X:"]
|
[:tr [:td "Y:"] [:td y]]]]])))
|
||||||
[:td x]]
|
|
||||||
[:tr
|
|
||||||
[:td "Y:"]
|
|
||||||
[:td y]]]]])))
|
|
||||||
|
|
||||||
(def coordinates
|
(def coordinates
|
||||||
(util/component
|
(util/component
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue