mirror of
https://github.com/penpot/penpot.git
synced 2025-01-26 00:19:07 -05:00
✨ Move guides together with frames
This commit is contained in:
parent
f0fd1bb40c
commit
3f89baa1fe
5 changed files with 63 additions and 8 deletions
|
@ -6,9 +6,11 @@
|
||||||
|
|
||||||
(ns app.main.data.workspace.guides
|
(ns app.main.data.workspace.guides
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.spec :as us]
|
||||||
[app.main.data.workspace.changes :as dwc]
|
[app.main.data.workspace.changes :as dwc]
|
||||||
[app.main.data.workspace.state-helpers :as wsh]
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
[cljs.spec.alpha :as s]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
(defn make-update-guide [guide]
|
(defn make-update-guide [guide]
|
||||||
|
@ -18,6 +20,7 @@
|
||||||
(merge guide))))
|
(merge guide))))
|
||||||
|
|
||||||
(defn update-guides [guide]
|
(defn update-guides [guide]
|
||||||
|
;; TODO CHECK SPEC
|
||||||
(ptk/reify ::update-guides
|
(ptk/reify ::update-guides
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
|
@ -41,6 +44,7 @@
|
||||||
:origin it}))))))
|
:origin it}))))))
|
||||||
|
|
||||||
(defn remove-guide [guide]
|
(defn remove-guide [guide]
|
||||||
|
;; TODO CHECK SPEC
|
||||||
(ptk/reify ::remove-guide
|
(ptk/reify ::remove-guide
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
|
@ -61,3 +65,36 @@
|
||||||
{:redo-changes rch
|
{:redo-changes rch
|
||||||
:undo-changes uch
|
:undo-changes uch
|
||||||
:origin it}))))))
|
:origin it}))))))
|
||||||
|
|
||||||
|
(defn move-frame-guides
|
||||||
|
[ids]
|
||||||
|
(us/verify (s/coll-of uuid?) ids)
|
||||||
|
|
||||||
|
(ptk/reify ::move-frame-guides
|
||||||
|
ptk/WatchEvent
|
||||||
|
|
||||||
|
(watch [_ state _]
|
||||||
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
|
frame-ids (->> ids (filter #(= :frame (get-in objects [% :type]))) (into #{}))
|
||||||
|
object-modifiers (get state :workspace-modifiers)
|
||||||
|
|
||||||
|
moved-guide?
|
||||||
|
(fn [guide]
|
||||||
|
(let [frame-id (:frame-id guide)]
|
||||||
|
(and (contains? frame-ids frame-id)
|
||||||
|
(some? (get-in object-modifiers [frame-id :modifiers :displacement])))))
|
||||||
|
|
||||||
|
build-move-event
|
||||||
|
(fn [guide]
|
||||||
|
(let [disp (get-in object-modifiers [(:frame-id guide) :modifiers :displacement])
|
||||||
|
guide (if (= :x (:axis guide))
|
||||||
|
(update guide :position + (:e disp))
|
||||||
|
(update guide :position + (:f disp)))]
|
||||||
|
(update-guides guide)))]
|
||||||
|
|
||||||
|
(->> (wsh/lookup-page-options state)
|
||||||
|
:guides
|
||||||
|
(vals)
|
||||||
|
(filter moved-guide?)
|
||||||
|
(map build-move-event)
|
||||||
|
(rx/from))))))
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.main.data.workspace.changes :as dch]
|
[app.main.data.workspace.changes :as dch]
|
||||||
[app.main.data.workspace.common :as dwc]
|
[app.main.data.workspace.common :as dwc]
|
||||||
|
[app.main.data.workspace.guides :as dwg]
|
||||||
[app.main.data.workspace.selection :as dws]
|
[app.main.data.workspace.selection :as dws]
|
||||||
[app.main.data.workspace.state-helpers :as wsh]
|
[app.main.data.workspace.state-helpers :as wsh]
|
||||||
[app.main.data.workspace.undo :as dwu]
|
[app.main.data.workspace.undo :as dwu]
|
||||||
|
@ -155,6 +156,8 @@
|
||||||
|
|
||||||
(update state :workspace-modifiers #(reduce update-shape % shapes)))))))
|
(update state :workspace-modifiers #(reduce update-shape % shapes)))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn- apply-modifiers
|
(defn- apply-modifiers
|
||||||
[ids]
|
[ids]
|
||||||
(us/verify (s/coll-of uuid?) ids)
|
(us/verify (s/coll-of uuid?) ids)
|
||||||
|
@ -186,6 +189,7 @@
|
||||||
:rotation
|
:rotation
|
||||||
:flip-x
|
:flip-x
|
||||||
:flip-y]})
|
:flip-y]})
|
||||||
|
(dwg/move-frame-guides ids-with-children)
|
||||||
(clear-local-transform)
|
(clear-local-transform)
|
||||||
(dwu/commit-undo-transaction))))))
|
(dwu/commit-undo-transaction))))))
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,7 @@
|
||||||
guide-width (/ guide-width zoom)
|
guide-width (/ guide-width zoom)
|
||||||
guide-pill-corner-radius (/ guide-pill-corner-radius zoom)]
|
guide-pill-corner-radius (/ guide-pill-corner-radius zoom)]
|
||||||
|
|
||||||
[:g.guide-area
|
[:g.guide-area {:data-guide-frame-id (when (some? frame) (str (:id frame)))}
|
||||||
(when-not disabled-guides?
|
(when-not disabled-guides?
|
||||||
(let [{:keys [x y width height]} (guide-area-axis pos vbox zoom frame axis)]
|
(let [{:keys [x y width height]} (guide-area-axis pos vbox zoom frame axis)]
|
||||||
[:rect {:x x
|
[:rect {:x x
|
||||||
|
|
|
@ -85,13 +85,16 @@
|
||||||
mask? (and group? masked-group?)
|
mask? (and group? masked-group?)
|
||||||
|
|
||||||
;; When the shape is a frame we maybe need to move its thumbnail
|
;; When the shape is a frame we maybe need to move its thumbnail
|
||||||
thumb-node (when frame? (dom/get-element (str "thumbnail-" id)))]
|
thumb-node (when frame? (dom/get-element (str "thumbnail-" id)))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
frame?
|
frame?
|
||||||
[thumb-node
|
(into [thumb-node
|
||||||
(dom/query shape-node ".frame-background")
|
(dom/query shape-node ".frame-background")
|
||||||
(dom/query shape-node ".frame-clip")]
|
(dom/query shape-node ".frame-clip")]
|
||||||
|
(dom/query-all (str "[data-guide-frame-id='" id "']")))
|
||||||
|
|
||||||
;; For groups we don't want to transform the whole group but only
|
;; For groups we don't want to transform the whole group but only
|
||||||
;; its filters/masks
|
;; its filters/masks
|
||||||
|
|
|
@ -213,9 +213,20 @@
|
||||||
(.-innerText el)))
|
(.-innerText el)))
|
||||||
|
|
||||||
(defn query
|
(defn query
|
||||||
[^js el ^string query]
|
([^string query]
|
||||||
(when (some? el)
|
(query globals/document query))
|
||||||
(.querySelector el query)))
|
|
||||||
|
([^js el ^string query]
|
||||||
|
(when (some? el)
|
||||||
|
(.querySelector el query))))
|
||||||
|
|
||||||
|
(defn query-all
|
||||||
|
([^string query]
|
||||||
|
(query-all globals/document query))
|
||||||
|
|
||||||
|
([^js el ^string query]
|
||||||
|
(when (some? el)
|
||||||
|
(.querySelectorAll el query))))
|
||||||
|
|
||||||
(defn get-client-position
|
(defn get-client-position
|
||||||
[^js event]
|
[^js event]
|
||||||
|
|
Loading…
Add table
Reference in a new issue