mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 05:36:36 +02:00
Improved actions locking for better user experience.
This commit is contained in:
parent
94e22902f0
commit
2a0918a567
4 changed files with 24 additions and 13 deletions
|
@ -5,9 +5,17 @@
|
||||||
;; Actions
|
;; Actions
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defonce actions-lock (atom :nothing))
|
||||||
(defonce actions-s (rx/bus))
|
(defonce actions-s (rx/bus))
|
||||||
|
|
||||||
(defn emit-action!
|
(defn acquire-action!
|
||||||
[type]
|
[type]
|
||||||
(rx/push! actions-s type))
|
(when-let [result (compare-and-set! actions-lock :nothing type)]
|
||||||
|
;; (println "acquire-action!" type)
|
||||||
|
(rx/push! actions-s type)))
|
||||||
|
|
||||||
|
(defn release-action!
|
||||||
|
[type]
|
||||||
|
(when-let [result (compare-and-set! actions-lock type :nothing)]
|
||||||
|
;; (println "release-action!" type)
|
||||||
|
(rx/push! actions-s :nothing)))
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
(and (not selected?) (empty? selected))
|
(and (not selected?) (empty? selected))
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :shape/movement)
|
(uuc/acquire-action! :shape/movement)
|
||||||
(rs/emit! (dw/select-shape id)))
|
(rs/emit! (dw/select-shape id)))
|
||||||
|
|
||||||
(and (not selected?) (not (empty? selected)))
|
(and (not selected?) (not (empty? selected)))
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :shape/movement))))))
|
(uuc/acquire-action! :shape/movement))))))
|
||||||
|
|
||||||
(defn on-mouse-up
|
(defn on-mouse-up
|
||||||
[event {:keys [id group] :as shape}]
|
[event {:keys [id group] :as shape}]
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :nothing))))
|
(uuc/release-action! :shape/movement))))
|
||||||
|
|
||||||
(declare handlers)
|
(declare handlers)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
(and (not selected?) (empty? selected))
|
(and (not selected?) (empty? selected))
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :shape/movement)
|
(uuc/acquire-action! :shape/movement)
|
||||||
(rs/emit! (dw/select-shape id)))
|
(rs/emit! (dw/select-shape id)))
|
||||||
|
|
||||||
(and (not selected?) (not (empty? selected)))
|
(and (not selected?) (not (empty? selected)))
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :shape/movement))))))
|
(uuc/acquire-action! :shape/movement))))))
|
||||||
|
|
||||||
(defn on-mouse-up
|
(defn on-mouse-up
|
||||||
[event {:keys [id group] :as shape}]
|
[event {:keys [id group] :as shape}]
|
||||||
|
@ -56,7 +56,7 @@
|
||||||
:else
|
:else
|
||||||
(do
|
(do
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :nothing))))
|
(uuc/release-action! :shape/movement))))
|
||||||
|
|
||||||
(defn- text-component-did-mount
|
(defn- text-component-did-mount
|
||||||
[own]
|
[own]
|
||||||
|
@ -64,12 +64,14 @@
|
||||||
(let [container (mx/get-ref-dom own "container")
|
(let [container (mx/get-ref-dom own "container")
|
||||||
local (:rum/local own)]
|
local (:rum/local own)]
|
||||||
(swap! local assoc :edition true)
|
(swap! local assoc :edition true)
|
||||||
|
(uuc/acquire-action! ::edition)
|
||||||
(set! (.-contentEditable container) true)
|
(set! (.-contentEditable container) true)
|
||||||
(.setAttribute container "contenteditable" "true")
|
(.setAttribute container "contenteditable" "true")
|
||||||
(.focus container)))
|
(.focus container)))
|
||||||
(on-blur [ev]
|
(on-blur [ev]
|
||||||
(let [container (mx/get-ref-dom own "container")
|
(let [container (mx/get-ref-dom own "container")
|
||||||
local (:rum/local own)]
|
local (:rum/local own)]
|
||||||
|
(uuc/release-action! ::edition)
|
||||||
(swap! local assoc :edition false)
|
(swap! local assoc :edition false)
|
||||||
(set! (.-contentEditable container) false)
|
(set! (.-contentEditable container) false)
|
||||||
(.removeAttribute container "contenteditable")))]
|
(.removeAttribute container "contenteditable")))]
|
||||||
|
|
|
@ -84,11 +84,12 @@
|
||||||
(when-not (empty? (:selected workspace))
|
(when-not (empty? (:selected workspace))
|
||||||
(rs/emit! (dw/deselect-all)))
|
(rs/emit! (dw/deselect-all)))
|
||||||
(if-let [shape (:drawing workspace)]
|
(if-let [shape (:drawing workspace)]
|
||||||
(uuc/emit-action! :draw/shape)
|
(uuc/acquire-action! :draw/shape)
|
||||||
(uuc/emit-action! :draw/selrect)))
|
(uuc/acquire-action! :draw/selrect)))
|
||||||
(on-mouse-up [event]
|
(on-mouse-up [event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(uuc/emit-action! :nothing))]
|
(uuc/release-action! :draw/shape)
|
||||||
|
(uuc/release-action! :draw/selrect))]
|
||||||
(html
|
(html
|
||||||
[:svg.viewport {:width uuwb/viewport-width
|
[:svg.viewport {:width uuwb/viewport-width
|
||||||
:height uuwb/viewport-height
|
:height uuwb/viewport-height
|
||||||
|
@ -124,11 +125,11 @@
|
||||||
|
|
||||||
(on-key-down [event]
|
(on-key-down [event]
|
||||||
(when (kbd/space? event)
|
(when (kbd/space? event)
|
||||||
(uuc/emit-action! :scroll/viewport)))
|
(uuc/acquire-action! :scroll/viewport)))
|
||||||
|
|
||||||
(on-key-up [event]
|
(on-key-up [event]
|
||||||
(when (kbd/space? event)
|
(when (kbd/space? event)
|
||||||
(uuc/emit-action! :nothing)))
|
(uuc/release-action! :scroll/viewport)))
|
||||||
|
|
||||||
(on-mousemove [event]
|
(on-mousemove [event]
|
||||||
(let [wpt (gpt/point (.-clientX event)
|
(let [wpt (gpt/point (.-clientX event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue