mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 23:26:39 +02:00
🚧 Initial work on granular shape edition.
This commit is contained in:
parent
3eff27b5c5
commit
b03d10a824
5 changed files with 70 additions and 23 deletions
|
@ -82,8 +82,8 @@
|
||||||
"A marker protocol for mark events that alters the
|
"A marker protocol for mark events that alters the
|
||||||
page and is subject to perform a backend synchronization.")
|
page and is subject to perform a backend synchronization.")
|
||||||
|
|
||||||
(defprotocol IPageOps
|
(defprotocol IPagePersistentOps
|
||||||
(-ops [_] "Get a list of ops for the event."))
|
(-persistent-ops [o] "Get a list of ops for the event."))
|
||||||
|
|
||||||
(defn page-update?
|
(defn page-update?
|
||||||
[o]
|
[o]
|
||||||
|
|
|
@ -450,16 +450,21 @@
|
||||||
(update-in $ [:workspace-data :shapes] conj id))
|
(update-in $ [:workspace-data :shapes] conj id))
|
||||||
(assoc-in $ [:workspace-data :shapes-by-id id] shape))))
|
(assoc-in $ [:workspace-data :shapes-by-id id] shape))))
|
||||||
|
|
||||||
|
(declare shape-added)
|
||||||
|
|
||||||
(defn add-shape
|
(defn add-shape
|
||||||
[data]
|
[data]
|
||||||
(ptk/reify ::add-shape
|
(let [shape (assoc (geom/setup-proportions data)
|
||||||
udp/IPageDataUpdate
|
:id (uuid/random))]
|
||||||
ptk/UpdateEvent
|
(ptk/reify ::add-shape
|
||||||
(update [_ state]
|
udp/IPageDataUpdate
|
||||||
;; TODO: revisit the `setup-proportions` seems unnecesary
|
|
||||||
(let [page-id (get-in state [:workspace-local :id])
|
udp/IPagePersistentOps
|
||||||
shape (assoc (geom/setup-proportions data)
|
(-persistent-ops [_]
|
||||||
:id (uuid/random))]
|
[[:add-shape (:id shape) shape]])
|
||||||
|
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
(impl-assoc-shape state shape)))))
|
(impl-assoc-shape state shape)))))
|
||||||
|
|
||||||
;; --- Duplicate Selected
|
;; --- Duplicate Selected
|
||||||
|
@ -593,12 +598,30 @@
|
||||||
(defn update-shape-attrs
|
(defn update-shape-attrs
|
||||||
[id attrs]
|
[id attrs]
|
||||||
(s/assert ::us/uuid id)
|
(s/assert ::us/uuid id)
|
||||||
(s/assert ::attributes attrs)
|
|
||||||
(let [atts (s/conform ::attributes attrs)]
|
(let [atts (s/conform ::attributes attrs)]
|
||||||
(ptk/reify ::update-shape-attrs
|
(ptk/reify ::update-shape-attrs
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:workspace-data :shapes-by-id id] merge attrs)))))
|
(if (map? attrs)
|
||||||
|
(update-in state [:workspace-data :shapes-by-id id] merge attrs)
|
||||||
|
state)))))
|
||||||
|
|
||||||
|
(defn update-shape
|
||||||
|
[id & attrs]
|
||||||
|
(let [attrs' (->> (apply hash-map attrs)
|
||||||
|
(s/conform ::attributes))]
|
||||||
|
(ptk/reify ::update-shape
|
||||||
|
udp/IPagePersistentOps
|
||||||
|
(-persistent-ops [_]
|
||||||
|
(->> (partition-all 2 attrs)
|
||||||
|
(mapv (fn [[key val]] [:mod-shape id key val]))))
|
||||||
|
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(cond-> state
|
||||||
|
(not= attrs' ::s/invalid)
|
||||||
|
(update-in [:workspace-data :shapes-by-id id] merge attrs'))))))
|
||||||
|
|
||||||
|
|
||||||
;; --- Update Selected Shapes attrs
|
;; --- Update Selected Shapes attrs
|
||||||
|
|
||||||
|
@ -640,8 +663,8 @@
|
||||||
(if align? (* 3 gy) 10))}))
|
(if align? (* 3 gy) 10))}))
|
||||||
|
|
||||||
(declare initial-selection-align)
|
(declare initial-selection-align)
|
||||||
(declare materialize-current-modifier-in-bulk)
|
|
||||||
(declare apply-temporal-displacement-in-bulk)
|
(declare apply-temporal-displacement-in-bulk)
|
||||||
|
(declare materialize-temporal-modifier-in-bulk)
|
||||||
|
|
||||||
(s/def ::direction #{:up :down :right :left})
|
(s/def ::direction #{:up :down :right :left})
|
||||||
(s/def ::speed #{:std :fast})
|
(s/def ::speed #{:std :fast})
|
||||||
|
@ -653,6 +676,7 @@
|
||||||
(ptk/reify ::move-selected
|
(ptk/reify ::move-selected
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
(prn "move-selected" direction speed)
|
||||||
(let [{:keys [selected flags id]} (:workspace-local state)
|
(let [{:keys [selected flags id]} (:workspace-local state)
|
||||||
align? (refs/alignment-activated? flags)
|
align? (refs/alignment-activated? flags)
|
||||||
metadata (merge c/page-metadata
|
metadata (merge c/page-metadata
|
||||||
|
@ -662,7 +686,7 @@
|
||||||
(rx/concat
|
(rx/concat
|
||||||
(when align? (rx/of (initial-selection-align selected)))
|
(when align? (rx/of (initial-selection-align selected)))
|
||||||
(rx/of (apply-temporal-displacement-in-bulk selected displacement))
|
(rx/of (apply-temporal-displacement-in-bulk selected displacement))
|
||||||
(rx/of (materialize-current-modifier-in-bulk selected)))))))
|
(rx/of (materialize-temporal-modifier-in-bulk selected)))))))
|
||||||
|
|
||||||
;; --- Update Shape Position
|
;; --- Update Shape Position
|
||||||
|
|
||||||
|
@ -776,6 +800,7 @@
|
||||||
|
|
||||||
;; --- Temportal displacement for Shape / Selection
|
;; --- Temportal displacement for Shape / Selection
|
||||||
|
|
||||||
|
;; DEPRECATED
|
||||||
(defn apply-temporal-displacement-in-bulk
|
(defn apply-temporal-displacement-in-bulk
|
||||||
"Apply the same displacement delta to all shapes identified by the
|
"Apply the same displacement delta to all shapes identified by the
|
||||||
set if ids."
|
set if ids."
|
||||||
|
@ -787,16 +812,39 @@
|
||||||
xfmt (gmt/translate prev delta)]
|
xfmt (gmt/translate prev delta)]
|
||||||
(assoc-in state [:workspace-data :shapes-by-id id :modifier-mtx] xfmt)))]
|
(assoc-in state [:workspace-data :shapes-by-id id :modifier-mtx] xfmt)))]
|
||||||
(ptk/reify ::apply-temporal-displacement-in-bulk
|
(ptk/reify ::apply-temporal-displacement-in-bulk
|
||||||
;; udp/IPageOps
|
|
||||||
;; (-ops [_]
|
|
||||||
;; (mapv #(vec :udp/shape id :move delta) ids))
|
|
||||||
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(reduce process-shape state ids)))))
|
(reduce process-shape state ids)))))
|
||||||
|
|
||||||
|
|
||||||
|
;; ;; NOTE: replaces the `apply-temporal-displacement-in-bulk`
|
||||||
|
;; (defn apply-displacement-in-bulk
|
||||||
|
;; [ids delta]
|
||||||
|
;; (ptk/reify ::apply-displacement-in-bulk
|
||||||
|
;; ptk/UpdateEvent
|
||||||
|
;; (update [_ state]
|
||||||
|
;; (let [xfmt (gmt/translate (gmt/matrix) delta)]
|
||||||
|
;; (reduce (fn [state id]
|
||||||
|
;; (update-in state [:workspace-data :shapes-by-id id] geom/transform xfmt))
|
||||||
|
;; state
|
||||||
|
;; ids)))))
|
||||||
|
|
||||||
|
|
||||||
|
;; (defn materialize-transformation-in-bulk
|
||||||
|
;; [ids xfmt]
|
||||||
|
;; (s/assert ::set-of-uuid ids)
|
||||||
|
;; (s/assert gmt/matrix? xfmt)
|
||||||
|
;; (ptk/reify ::materialize-transformation-in-bulk
|
||||||
|
;; ptk/UpdateEvent
|
||||||
|
;; (update [_ state]
|
||||||
|
;; (reduce (fn [state id]
|
||||||
|
;; (update-in state [:workspace-data :shapes-by-id id] geom/transform xfmt))
|
||||||
|
;; state
|
||||||
|
;; ids))))
|
||||||
|
|
||||||
;; --- Modifiers
|
;; --- Modifiers
|
||||||
|
|
||||||
|
;; DEPRECATED
|
||||||
(defn assoc-temporal-modifier-in-bulk
|
(defn assoc-temporal-modifier-in-bulk
|
||||||
[ids xfmt]
|
[ids xfmt]
|
||||||
(s/assert ::set-of-uuid ids)
|
(s/assert ::set-of-uuid ids)
|
||||||
|
@ -806,7 +854,7 @@
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(reduce #(assoc-in %1 [:workspace-data :shapes-by-id %2 :modifier-mtx] xfmt) state ids))))
|
(reduce #(assoc-in %1 [:workspace-data :shapes-by-id %2 :modifier-mtx] xfmt) state ids))))
|
||||||
|
|
||||||
(defn materialize-current-modifier-in-bulk
|
(defn materialize-temporal-modifier-in-bulk
|
||||||
[ids]
|
[ids]
|
||||||
(s/assert ::us/set ids)
|
(s/assert ::us/set ids)
|
||||||
(letfn [(process-shape [state id]
|
(letfn [(process-shape [state id]
|
||||||
|
@ -816,7 +864,7 @@
|
||||||
(update-in [:workspace-data :shapes-by-id id] geom/transform xfmt)
|
(update-in [:workspace-data :shapes-by-id id] geom/transform xfmt)
|
||||||
(update-in [:workspace-data :shapes-by-id id] dissoc :modifier-mtx))
|
(update-in [:workspace-data :shapes-by-id id] dissoc :modifier-mtx))
|
||||||
state)))]
|
state)))]
|
||||||
(ptk/reify ::materialize-current-modifier-in-bulk
|
(ptk/reify ::materialize-temporal-modifier-in-bulk
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(reduce process-shape state ids)))))
|
(reduce process-shape state ids)))))
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
(->> (uws/mouse-position-deltas position)
|
(->> (uws/mouse-position-deltas position)
|
||||||
(rx/map #(dw/apply-temporal-displacement-in-bulk selected %))
|
(rx/map #(dw/apply-temporal-displacement-in-bulk selected %))
|
||||||
(rx/take-until stoper))
|
(rx/take-until stoper))
|
||||||
(rx/of (dw/materialize-current-modifier-in-bulk selected)
|
(rx/of (dw/materialize-temporal-modifier-in-bulk selected)
|
||||||
::dw/page-data-update))))))
|
::dw/page-data-update))))))
|
||||||
|
|
||||||
(defn on-mouse-down
|
(defn on-mouse-down
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
(rx/map normalize-proportion-lock)
|
(rx/map normalize-proportion-lock)
|
||||||
(rx/mapcat (partial resize shape))
|
(rx/mapcat (partial resize shape))
|
||||||
(rx/take-until stoper))
|
(rx/take-until stoper))
|
||||||
(rx/of (dw/materialize-current-modifier-in-bulk ids)
|
(rx/of (dw/materialize-temporal-modifier-in-bulk ids)
|
||||||
::dw/page-data-update)))))))
|
::dw/page-data-update)))))))
|
||||||
|
|
||||||
;; --- Controls (Component)
|
;; --- Controls (Component)
|
||||||
|
|
|
@ -94,7 +94,6 @@
|
||||||
(rx/subscribe-with ob sub)
|
(rx/subscribe-with ob sub)
|
||||||
sub))
|
sub))
|
||||||
|
|
||||||
|
|
||||||
(defn mouse-position-deltas
|
(defn mouse-position-deltas
|
||||||
[current]
|
[current]
|
||||||
(->> (rx/concat (rx/of current)
|
(->> (rx/concat (rx/of current)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue