mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 20:36:10 +02:00
Refactor shapes resize related code.
This commit is contained in:
parent
45255ab932
commit
a0726d3a36
3 changed files with 81 additions and 54 deletions
|
@ -25,7 +25,7 @@
|
|||
[uxbox.ui.workspace.base :as uuwb]
|
||||
[uxbox.ui.workspace.drawarea :refer (draw-area)]
|
||||
[uxbox.ui.workspace.movement :as cmov]
|
||||
[uxbox.ui.workspace.canvas.resize]
|
||||
[uxbox.ui.workspace.resize :as cres]
|
||||
[uxbox.ui.workspace.canvas.ruler :refer (ruler)]
|
||||
[uxbox.ui.workspace.canvas.selection :refer (shapes-selection)]
|
||||
[uxbox.ui.workspace.canvas.selrect :refer (selrect)]
|
||||
|
@ -156,27 +156,30 @@
|
|||
(let [key1 (events/listen js/document EventType.MOUSEMOVE on-mousemove)
|
||||
key2 (events/listen js/document EventType.KEYDOWN on-key-down)
|
||||
key3 (events/listen js/document EventType.KEYUP on-key-up)
|
||||
sub1 (cmov/watch-move-actions)]
|
||||
sub1 (cmov/watch-move-actions)
|
||||
sub2 (cres/watch-resize-actions)]
|
||||
(assoc own
|
||||
::sub1 sub1
|
||||
::sub2 sub2
|
||||
::key1 key1
|
||||
::key2 key2
|
||||
::key3 key3))))
|
||||
|
||||
(defn- viewport-transfer-state
|
||||
[old-own own]
|
||||
(->> [::key1 ::key2 ::key3
|
||||
::sub1 ::sub2]
|
||||
(select-keys old-own)
|
||||
(merge own)))
|
||||
|
||||
(defn- viewport-will-unmount
|
||||
[own]
|
||||
(events/unlistenByKey (::key1 own))
|
||||
(events/unlistenByKey (::key2 own))
|
||||
(events/unlistenByKey (::key3 own))
|
||||
(.close (::sub1 own))
|
||||
(dissoc own ::key1 ::key2 ::key3 ::sub1))
|
||||
|
||||
(defn- viewport-transfer-state
|
||||
[old-own own]
|
||||
(->> [::key1 ::key2 ::key3
|
||||
::sub1]
|
||||
(select-keys old-own)
|
||||
(merge own)))
|
||||
(.close (::sub2 own))
|
||||
(dissoc own ::key1 ::key2 ::key3 ::sub1 ::sub2))
|
||||
|
||||
(def viewport
|
||||
(mx/component
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.ui.workspace.canvas.resize
|
||||
(:require-macros [uxbox.util.syntax :refer [define-once]])
|
||||
(:require [sablono.core :as html :refer-macros [html]]
|
||||
[rum.core :as rum]
|
||||
[beicon.core :as rx]
|
||||
[lentes.core :as l]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.shapes :as ush]
|
||||
[uxbox.data.workspace :as udw]
|
||||
[uxbox.data.shapes :as uds]
|
||||
[uxbox.ui.core :as uuc]
|
||||
[uxbox.ui.shapes.core :as uusc]
|
||||
[uxbox.ui.workspace.base :as uuwb]
|
||||
[uxbox.ui.mixins :as mx]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
(define-once :resize-subscriptions
|
||||
(letfn [(init [event]
|
||||
(let [payload (:payload event)
|
||||
stoper (->> uuc/actions-s
|
||||
(rx/map :type)
|
||||
(rx/filter #(empty? %))
|
||||
(rx/take 1))]
|
||||
(as-> uuwb/mouse-delta-s $
|
||||
(rx/take-until stoper $)
|
||||
(rx/with-latest-from vector uuwb/mouse-ctrl-s $)
|
||||
(rx/subscribe $ #(on-value payload %)))))
|
||||
|
||||
(on-value [{:keys [vid shape]} [delta ctrl?]]
|
||||
(let [params {:vid vid :delta (assoc delta :lock ctrl?)}]
|
||||
(rs/emit! (uds/update-vertex-position shape params))))]
|
||||
|
||||
(as-> uuc/actions-s $
|
||||
(rx/dedupe $)
|
||||
(rx/filter #(= (:type %) "ui.shape.resize") $)
|
||||
(rx/on-value $ init))))
|
68
src/uxbox/ui/workspace/resize.cljs
Normal file
68
src/uxbox/ui/workspace/resize.cljs
Normal file
|
@ -0,0 +1,68 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
||||
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||
|
||||
(ns uxbox.ui.workspace.resize
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.shapes :as ush]
|
||||
[uxbox.data.shapes :as uds]
|
||||
[uxbox.ui.core :as uuc]
|
||||
[uxbox.ui.workspace.base :as uuwb]
|
||||
[uxbox.util.geom.point :as gpt]))
|
||||
|
||||
(declare initialize)
|
||||
(declare handle-resize)
|
||||
|
||||
;; --- Public Api
|
||||
|
||||
(defn watch-resize-actions
|
||||
[]
|
||||
(as-> uuc/actions-s $
|
||||
(rx/dedupe $)
|
||||
(rx/filter #(= (:type %) "ui.shape.resize") $)
|
||||
(rx/on-value $ initialize)))
|
||||
|
||||
;; --- Implementation
|
||||
|
||||
(defn- initialize
|
||||
[event]
|
||||
(let [payload (:payload event)
|
||||
stoper (->> uuc/actions-s
|
||||
(rx/map :type)
|
||||
(rx/filter #(empty? %))
|
||||
(rx/take 1))]
|
||||
(as-> uuwb/mouse-delta-s $
|
||||
(rx/take-until stoper $)
|
||||
(rx/with-latest-from vector uuwb/mouse-ctrl-s $)
|
||||
(rx/subscribe $ #(handle-resize payload %)))))
|
||||
|
||||
(defn- handle-resize
|
||||
[{:keys [vid shape]} [delta ctrl?]]
|
||||
(let [params {:vid vid :delta (assoc delta :lock ctrl?)}]
|
||||
(rs/emit! (uds/update-vertex-position shape params))))
|
||||
|
||||
|
||||
;; (define-once :resize-subscriptions
|
||||
;; (letfn [(init [event]
|
||||
;; (let [payload (:payload event)
|
||||
;; stoper (->> uuc/actions-s
|
||||
;; (rx/map :type)
|
||||
;; (rx/filter #(empty? %))
|
||||
;; (rx/take 1))]
|
||||
;; (as-> uuwb/mouse-delta-s $
|
||||
;; (rx/take-until stoper $)
|
||||
;; (rx/with-latest-from vector uuwb/mouse-ctrl-s $)
|
||||
;; (rx/subscribe $ #(on-value payload %)))))
|
||||
|
||||
;; (on-value [{:keys [vid shape]} [delta ctrl?]]
|
||||
;; (let [params {:vid vid :delta (assoc delta :lock ctrl?)}]
|
||||
;; (rs/emit! (uds/update-vertex-position shape params))))]
|
||||
|
||||
;; (as-> uuc/actions-s $
|
||||
;; (rx/dedupe $)
|
||||
;; (rx/filter #(= (:type %) "ui.shape.resize") $)
|
||||
;; (rx/on-value $ init))))
|
Loading…
Add table
Add a link
Reference in a new issue