mirror of
https://github.com/penpot/penpot.git
synced 2025-07-21 05:57:12 +02:00
🐛 Stop drag events when the user focus out the application
This commit is contained in:
parent
054ffbe396
commit
895f649ef1
11 changed files with 53 additions and 80 deletions
|
@ -4,11 +4,14 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.util.mouse)
|
||||
(ns app.util.mouse
|
||||
(:require
|
||||
[beicon.v2.core :as rx]))
|
||||
|
||||
(defrecord MouseEvent [type ctrl shift alt meta])
|
||||
(defrecord PointerEvent [source pt ctrl shift alt meta])
|
||||
(defrecord ScrollEvent [point])
|
||||
(defrecord BlurEvent [])
|
||||
|
||||
(defn mouse-event?
|
||||
[v]
|
||||
|
@ -22,6 +25,10 @@
|
|||
[v]
|
||||
(instance? ScrollEvent v))
|
||||
|
||||
(defn blur-event?
|
||||
[v]
|
||||
(instance? BlurEvent v))
|
||||
|
||||
(defn mouse-down-event?
|
||||
[^MouseEvent v]
|
||||
(= :down (.-type v)))
|
||||
|
@ -61,3 +68,16 @@
|
|||
(defn get-pointer-shift-mod
|
||||
[^PointerEvent ev]
|
||||
(.-shift ev))
|
||||
|
||||
(defn drag-stopper
|
||||
"Creates a stream to stop drag events. Takes into account the mouse and also
|
||||
if the window loses focus or the esc key is pressed."
|
||||
[stream]
|
||||
(rx/merge
|
||||
(->> stream
|
||||
(rx/filter blur-event?))
|
||||
(->> stream
|
||||
(rx/filter mouse-event?)
|
||||
(rx/filter mouse-up-event?))
|
||||
(->> stream
|
||||
(rx/filter #(= % :interrupt)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue