mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 14:12:36 -05:00
✨ Get rid of IUpdateGroup and IBatchedChange usage.
This commit is contained in:
parent
2b461d5b08
commit
36f4948ad1
8 changed files with 181 additions and 181 deletions
|
@ -798,13 +798,13 @@
|
||||||
([frame shape]
|
([frame shape]
|
||||||
(let [new-shape
|
(let [new-shape
|
||||||
(if (:modifiers shape)
|
(if (:modifiers shape)
|
||||||
(as-> (case (:type shape)
|
(-> (case (:type shape)
|
||||||
(:curve :path) (transform-path-shape shape)
|
(:curve :path) (transform-path-shape shape)
|
||||||
(transform-rect-shape shape)) $
|
(transform-rect-shape shape))
|
||||||
(dissoc $ :modifiers))
|
(dissoc :modifiers))
|
||||||
shape)]
|
shape)]
|
||||||
(-> new-shape
|
(cond-> new-shape
|
||||||
(translate-to-frame frame)))))
|
frame (translate-to-frame frame)))))
|
||||||
|
|
||||||
|
|
||||||
(defn transform-matrix
|
(defn transform-matrix
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
[uxbox.common.pages-helpers :as cph]
|
[uxbox.common.pages-helpers :as cph]
|
||||||
[uxbox.common.exceptions :as ex]
|
[uxbox.common.exceptions :as ex]
|
||||||
[uxbox.common.geom.shapes :as geom]
|
[uxbox.common.geom.shapes :as geom]
|
||||||
|
[uxbox.common.geom.matrix :as gmt]
|
||||||
|
[uxbox.common.geom.point :as gpt]
|
||||||
[uxbox.common.spec :as us]
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.common.uuid :as uuid]))
|
[uxbox.common.uuid :as uuid]))
|
||||||
|
|
||||||
|
@ -382,33 +384,53 @@
|
||||||
(seq shapes) ; Recursive delete all dependend objects
|
(seq shapes) ; Recursive delete all dependend objects
|
||||||
(as-> $ (reduce #(or (process-change %1 {:type :del-obj :id %2}) %1) $ shapes))))))
|
(as-> $ (reduce #(or (process-change %1 {:type :del-obj :id %2}) %1) $ shapes))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn rotation-modifiers
|
||||||
|
[center shape angle]
|
||||||
|
(let [displacement (let [shape-center (geom/center shape)]
|
||||||
|
(-> (gmt/matrix)
|
||||||
|
(gmt/rotate angle center)
|
||||||
|
(gmt/rotate (- angle) shape-center)))]
|
||||||
|
{:rotation angle
|
||||||
|
:displacement displacement}))
|
||||||
|
|
||||||
(defmethod process-change :reg-objects
|
(defmethod process-change :reg-objects
|
||||||
[data {:keys [shapes]}]
|
[data {:keys [shapes]}]
|
||||||
(let [objects (:objects data)]
|
(let [objects (:objects data)
|
||||||
(loop [shapes shapes data data]
|
xfm (comp
|
||||||
(if (seq shapes)
|
(mapcat #(cons % (cph/get-parents % objects)))
|
||||||
(let [item (get objects (first shapes))]
|
(map #(get objects %))
|
||||||
(if (= :group (:type item))
|
(filter #(= (:type %) :group))
|
||||||
(recur
|
(map :id)
|
||||||
(rest shapes)
|
(distinct))
|
||||||
(update-in data [:objects (:id item)]
|
|
||||||
(fn [{:keys [shapes] :as obj}]
|
ids (into [] xfm shapes)
|
||||||
(let [shapes (->> shapes
|
|
||||||
(map (partial get objects))
|
update-group
|
||||||
(filter identity))]
|
(fn [group data]
|
||||||
(if (seq shapes)
|
(let [objects (:objects data)
|
||||||
(let [selrect (geom/selection-rect shapes)]
|
gcenter (geom/center group)
|
||||||
(as-> obj $
|
|
||||||
(assoc $
|
gxfm (comp
|
||||||
:x (:x selrect)
|
(map #(get objects %))
|
||||||
:y (:y selrect)
|
(map #(-> %
|
||||||
:width (:width selrect)
|
(assoc :modifiers
|
||||||
:height (:height selrect))
|
(rotation-modifiers gcenter % (- (:rotation group 0))))
|
||||||
(assoc $ :points (geom/shape->points $))
|
(geom/transform-shape))))
|
||||||
(assoc $ :selrect (geom/points->selrect (:points $)))))
|
|
||||||
obj)))))
|
selrect (-> (into [] gxfm (:shapes group))
|
||||||
(recur (rest shapes) data)))
|
(geom/selection-rect))]
|
||||||
data))))
|
|
||||||
|
;; Rotate the group shape change the data and rotate back again
|
||||||
|
(-> group
|
||||||
|
(assoc-in [:modifiers :rotation] (- (:rotation group)))
|
||||||
|
(geom/transform-shape)
|
||||||
|
(merge (select-keys selrect [:x :y :width :height]))
|
||||||
|
(assoc-in [:modifiers :rotation] (:rotation group))
|
||||||
|
(geom/transform-shape))))]
|
||||||
|
|
||||||
|
(reduce #(update-in %1 [:objects %2] update-group %1) data ids)))
|
||||||
|
|
||||||
|
|
||||||
(defmethod process-change :mov-objects
|
(defmethod process-change :mov-objects
|
||||||
[data {:keys [parent-id shapes index] :as change}]
|
[data {:keys [parent-id shapes index] :as change}]
|
||||||
|
|
|
@ -39,15 +39,6 @@
|
||||||
(when parent-id
|
(when parent-id
|
||||||
(lazy-seq (cons parent-id (get-parents parent-id objects))))))
|
(lazy-seq (cons parent-id (get-parents parent-id objects))))))
|
||||||
|
|
||||||
(defn get-common-parents
|
|
||||||
[ids objects]
|
|
||||||
(loop [res (d/ordered-set)
|
|
||||||
ids (seq ids)]
|
|
||||||
(if ids
|
|
||||||
(recur (into res (get-parents (first ids) objects))
|
|
||||||
(next ids))
|
|
||||||
res)))
|
|
||||||
|
|
||||||
(defn generate-child-parent-index
|
(defn generate-child-parent-index
|
||||||
[objects]
|
[objects]
|
||||||
(reduce-kv
|
(reduce-kv
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(declare initialized)
|
(declare initialized)
|
||||||
(declare initialize-group-check)
|
|
||||||
|
|
||||||
;; --- Initialize Workspace
|
;; --- Initialize Workspace
|
||||||
|
|
||||||
|
@ -158,8 +157,7 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(rx/of (dwp/initialize-page-persistence page-id)
|
(rx/of (dwp/initialize-page-persistence page-id)))))
|
||||||
initialize-group-check))))
|
|
||||||
|
|
||||||
(defn finalize-page
|
(defn finalize-page
|
||||||
[page-id]
|
[page-id]
|
||||||
|
@ -176,19 +174,6 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(rx/of ::dwp/finalize))))
|
(rx/of ::dwp/finalize))))
|
||||||
|
|
||||||
(declare adjust-group-shapes)
|
|
||||||
|
|
||||||
(def initialize-group-check
|
|
||||||
(ptk/reify ::initialize-group-check
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ state stream]
|
|
||||||
(let [stoper (rx/filter (ptk/type? ::finalize-page) stream)]
|
|
||||||
(->> stream
|
|
||||||
(rx/filter #(satisfies? dwc/IUpdateGroup %))
|
|
||||||
(rx/map #(adjust-group-shapes (dwc/get-ids %)))
|
|
||||||
(rx/take-until stoper))))))
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Workspace State Manipulation
|
;; Workspace State Manipulation
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -277,52 +262,6 @@
|
||||||
(assoc :left-offset left-offset)))))))))))
|
(assoc :left-offset left-offset)))))))))))
|
||||||
|
|
||||||
|
|
||||||
;; TODO: this event is mainly replaced by `:reg-objects` change, but many events
|
|
||||||
;; are still implemented in function of this so we need to maintain it until
|
|
||||||
;; all is ported to use `:reg-objects`.
|
|
||||||
|
|
||||||
;; TODO: Additioanlly: many stuff related to rotation is not ported so
|
|
||||||
;; we need to port it before completelly remove this.
|
|
||||||
|
|
||||||
(defn adjust-group-shapes
|
|
||||||
[ids]
|
|
||||||
(ptk/reify ::adjust-group-shapes
|
|
||||||
dwc/IBatchedChange
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(let [page-id (:current-page-id state)
|
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
|
||||||
groups-to-adjust (->> ids
|
|
||||||
(mapcat #(cph/get-parents % objects))
|
|
||||||
(map #(get objects %))
|
|
||||||
(filter #(= (:type %) :group))
|
|
||||||
(map #(:id %))
|
|
||||||
distinct)
|
|
||||||
update-group
|
|
||||||
(fn [state group]
|
|
||||||
(let [objects (get-in state [:workspace-data page-id :objects])
|
|
||||||
group-center (geom/center group)
|
|
||||||
group-objects (->> (:shapes group)
|
|
||||||
(map #(get objects %))
|
|
||||||
(map #(-> %
|
|
||||||
(assoc :modifiers
|
|
||||||
(dwt/rotation-modifiers group-center % (- (:rotation group 0))))
|
|
||||||
(geom/transform-shape))))
|
|
||||||
selrect (geom/selection-rect group-objects)]
|
|
||||||
|
|
||||||
;; Rotate the group shape change the data and rotate back again
|
|
||||||
(-> group
|
|
||||||
(assoc-in [:modifiers :rotation] (- (:rotation group)))
|
|
||||||
(geom/transform-shape)
|
|
||||||
(merge (select-keys selrect [:x :y :width :height]))
|
|
||||||
(assoc-in [:modifiers :rotation] (:rotation group))
|
|
||||||
(geom/transform-shape))))
|
|
||||||
|
|
||||||
reduce-fn
|
|
||||||
#(update-in %1 [:workspace-data page-id :objects %2] (partial update-group %1))]
|
|
||||||
|
|
||||||
(reduce reduce-fn state groups-to-adjust)))))
|
|
||||||
|
|
||||||
(defn start-pan [state]
|
(defn start-pan [state]
|
||||||
(-> state
|
(-> state
|
||||||
(assoc-in [:workspace-local :panning] true)))
|
(assoc-in [:workspace-local :panning] true)))
|
||||||
|
@ -762,14 +701,21 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
parents (cph/get-common-parents ids objects)
|
|
||||||
|
parents (loop [res #{parent-id}
|
||||||
|
ids (seq ids)]
|
||||||
|
(if (nil? ids)
|
||||||
|
(vec res)
|
||||||
|
(recur
|
||||||
|
(conj res (cph/get-parent (first ids) objects))
|
||||||
|
(next ids))))
|
||||||
|
|
||||||
rchanges [{:type :mov-objects
|
rchanges [{:type :mov-objects
|
||||||
:parent-id parent-id
|
:parent-id parent-id
|
||||||
:index to-index
|
:index to-index
|
||||||
:shapes (vec (reverse ids))}
|
:shapes (vec (reverse ids))}
|
||||||
{:type :reg-objects
|
{:type :reg-objects
|
||||||
:shapes (vec (conj parents parent-id))}]
|
:shapes parents}]
|
||||||
|
|
||||||
uchanges
|
uchanges
|
||||||
(reduce (fn [res id]
|
(reduce (fn [res id]
|
||||||
|
@ -782,8 +728,12 @@
|
||||||
[] (reverse ids))
|
[] (reverse ids))
|
||||||
uchanges (conj uchanges
|
uchanges (conj uchanges
|
||||||
{:type :reg-objects
|
{:type :reg-objects
|
||||||
:shapes (vec parents)})]
|
:shapes parents})]
|
||||||
|
|
||||||
|
;; (println "================ rchanges")
|
||||||
|
;; (cljs.pprint/pprint rchanges)
|
||||||
|
;; (println "================ uchanges")
|
||||||
|
;; (cljs.pprint/pprint uchanges)
|
||||||
(rx/of (dwc/commit-changes rchanges uchanges
|
(rx/of (dwc/commit-changes rchanges uchanges
|
||||||
{:commit-local? true}))))))
|
{:commit-local? true}))))))
|
||||||
|
|
||||||
|
@ -828,17 +778,35 @@
|
||||||
[axis]
|
[axis]
|
||||||
(us/verify ::geom/align-axis axis)
|
(us/verify ::geom/align-axis axis)
|
||||||
(ptk/reify :align-objects
|
(ptk/reify :align-objects
|
||||||
dwc/IBatchedChange
|
ptk/WatchEvent
|
||||||
ptk/UpdateEvent
|
(watch [_ state stream]
|
||||||
(update [_ state]
|
(let [page-id (:current-page-id state)
|
||||||
(let [page-id (:current-page-id state)
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
moved-objs (if (= 1 (count selected))
|
moved (if (= 1 (count selected))
|
||||||
(align-object-to-frame objects (first selected) axis)
|
(align-object-to-frame objects (first selected) axis)
|
||||||
(align-objects-list objects selected axis))
|
(align-objects-list objects selected axis))]
|
||||||
updated-objs (merge objects (d/index-by :id moved-objs))]
|
(loop [moved (seq moved)
|
||||||
(assoc-in state [:workspace-data page-id :objects] updated-objs)))))
|
rchanges []
|
||||||
|
uchanges []]
|
||||||
|
(if (nil? moved)
|
||||||
|
(do
|
||||||
|
;; (println "================ rchanges")
|
||||||
|
;; (cljs.pprint/pprint rchanges)
|
||||||
|
;; (println "================ uchanges")
|
||||||
|
;; (cljs.pprint/pprint uchanges)
|
||||||
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})))
|
||||||
|
(let [curr (first moved)
|
||||||
|
prev (get objects (:id curr))
|
||||||
|
ops1 (dwc/generate-operations prev curr)
|
||||||
|
ops2 (dwc/generate-operations curr prev)]
|
||||||
|
(recur (next moved)
|
||||||
|
(conj rchanges {:type :mod-obj
|
||||||
|
:operations ops1
|
||||||
|
:id (:id curr)})
|
||||||
|
(conj uchanges {:type :mod-obj
|
||||||
|
:operations ops2
|
||||||
|
:id (:id curr)})))))))))
|
||||||
|
|
||||||
(defn align-object-to-frame
|
(defn align-object-to-frame
|
||||||
[objects object-id axis]
|
[objects object-id axis]
|
||||||
|
@ -856,16 +824,35 @@
|
||||||
[axis]
|
[axis]
|
||||||
(us/verify ::geom/dist-axis axis)
|
(us/verify ::geom/dist-axis axis)
|
||||||
(ptk/reify :align-objects
|
(ptk/reify :align-objects
|
||||||
dwc/IBatchedChange
|
ptk/WatchEvent
|
||||||
ptk/UpdateEvent
|
(watch [_ state stream]
|
||||||
(update [_ state]
|
(let [page-id (:current-page-id state)
|
||||||
(let [page-id (:current-page-id state)
|
objects (get-in state [:workspace-data page-id :objects])
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
|
||||||
selected (get-in state [:workspace-local :selected])
|
selected (get-in state [:workspace-local :selected])
|
||||||
selected-objs (map #(get objects %) selected)
|
|
||||||
moved-objs (geom/distribute-space selected-objs axis objects)
|
moved (-> (map #(get objects %) selected)
|
||||||
updated-objs (merge objects (d/index-by :id moved-objs))]
|
(geom/distribute-space axis objects))]
|
||||||
(assoc-in state [:workspace-data page-id :objects] updated-objs)))))
|
(loop [moved (seq moved)
|
||||||
|
rchanges []
|
||||||
|
uchanges []]
|
||||||
|
(if (nil? moved)
|
||||||
|
(do
|
||||||
|
;; (println "================ rchanges")
|
||||||
|
;; (cljs.pprint/pprint rchanges)
|
||||||
|
;; (println "================ uchanges")
|
||||||
|
;; (cljs.pprint/pprint uchanges)
|
||||||
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})))
|
||||||
|
(let [curr (first moved)
|
||||||
|
prev (get objects (:id curr))
|
||||||
|
ops1 (dwc/generate-operations prev curr)
|
||||||
|
ops2 (dwc/generate-operations curr prev)]
|
||||||
|
(recur (next moved)
|
||||||
|
(conj rchanges {:type :mod-obj
|
||||||
|
:operations ops1
|
||||||
|
:id (:id curr)})
|
||||||
|
(conj uchanges {:type :mod-obj
|
||||||
|
:operations ops2
|
||||||
|
:id (:id curr)})))))))))
|
||||||
|
|
||||||
;; --- Start shape "edition mode"
|
;; --- Start shape "edition mode"
|
||||||
|
|
||||||
|
@ -923,6 +910,8 @@
|
||||||
;; Event mainly used for handling user modification of the size of the
|
;; Event mainly used for handling user modification of the size of the
|
||||||
;; object from workspace sidebar options inputs.
|
;; object from workspace sidebar options inputs.
|
||||||
|
|
||||||
|
;; TODO: maybe replace directly with dwc/update-shapes?
|
||||||
|
|
||||||
(defn update-dimensions
|
(defn update-dimensions
|
||||||
[ids attr value]
|
[ids attr value]
|
||||||
(us/verify (s/coll-of ::us/uuid) ids)
|
(us/verify (s/coll-of ::us/uuid) ids)
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
;; --- Protocols
|
;; --- Protocols
|
||||||
|
|
||||||
(defprotocol IBatchedChange)
|
(defprotocol IBatchedChange)
|
||||||
(defprotocol IUpdateGroup
|
|
||||||
(get-ids [this]))
|
|
||||||
|
|
||||||
(declare setup-selection-index)
|
(declare setup-selection-index)
|
||||||
(declare update-page-indices)
|
(declare update-page-indices)
|
||||||
|
@ -96,7 +94,7 @@
|
||||||
:val vmb}))))
|
:val vmb}))))
|
||||||
result)))))
|
result)))))
|
||||||
|
|
||||||
(defn- generate-changes
|
(defn generate-changes
|
||||||
[prev curr]
|
[prev curr]
|
||||||
(letfn [(impl-diff [res id]
|
(letfn [(impl-diff [res id]
|
||||||
(let [prev-obj (get-in prev [:objects id])
|
(let [prev-obj (get-in prev [:objects id])
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[uxbox.common.data :as d]
|
[uxbox.common.data :as d]
|
||||||
|
[uxbox.common.spec :as us]
|
||||||
[uxbox.main.data.workspace.common :as dwc]))
|
[uxbox.main.data.workspace.common :as dwc]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -37,42 +38,39 @@
|
||||||
:column default-layout-params
|
:column default-layout-params
|
||||||
:row default-layout-params})
|
:row default-layout-params})
|
||||||
|
|
||||||
(defn add-frame-grid [frame-id]
|
(defn add-frame-grid
|
||||||
(ptk/reify ::set-frame-grid
|
[frame-id]
|
||||||
dwc/IBatchedChange
|
(us/assert ::us/uuid frame-id)
|
||||||
ptk/UpdateEvent
|
(ptk/reify ::add-frame-grid
|
||||||
(update [_ state]
|
ptk/WatchEvent
|
||||||
(let [pid (:current-page-id state)
|
(watch [_ state stream]
|
||||||
default-params (or
|
(let [page-id (:current-page-id state)
|
||||||
(get-in state [:workspace-data pid :options :saved-grids :square])
|
data (get-in state [:workspace-data page-id])
|
||||||
(:square default-grid-params))
|
params (or (get-in data [:options :saved-grids :square])
|
||||||
prop-path [:workspace-data pid :objects frame-id :grids]
|
(:square default-grid-params))
|
||||||
grid {:type :square
|
grid {:type :square
|
||||||
:params default-params
|
:params params
|
||||||
:display true}]
|
:display true}]
|
||||||
(-> state
|
(rx/of (dwc/update-shapes [frame-id]
|
||||||
(update-in prop-path #(if (nil? %) [grid] (conj % grid))))))))
|
(fn [obj] (update obj :grids (fnil #(conj % grid) [])))))))))
|
||||||
|
|
||||||
(defn remove-frame-grid [frame-id index]
|
|
||||||
(ptk/reify ::set-frame-grid
|
|
||||||
dwc/IBatchedChange
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(let [pid (:current-page-id state)]
|
|
||||||
(-> state
|
|
||||||
(update-in [:workspace-data pid :objects frame-id :grids] #(d/remove-at-index % index)))))))
|
|
||||||
|
|
||||||
(defn set-frame-grid [frame-id index data]
|
(defn remove-frame-grid
|
||||||
|
[frame-id index]
|
||||||
(ptk/reify ::set-frame-grid
|
(ptk/reify ::set-frame-grid
|
||||||
dwc/IBatchedChange
|
ptk/WatchEvent
|
||||||
ptk/UpdateEvent
|
(watch [_ state stream]
|
||||||
(update [_ state]
|
(rx/of (dwc/update-shapes [frame-id] (fn [o] (update o :grids (fnil #(d/remove-at-index % index) []))))))))
|
||||||
(let [pid (:current-page-id state)]
|
|
||||||
(->
|
|
||||||
state
|
|
||||||
(assoc-in [:workspace-data pid :objects frame-id :grids index] data))))))
|
|
||||||
|
|
||||||
(defn set-default-grid [type params]
|
(defn set-frame-grid
|
||||||
|
[frame-id index data]
|
||||||
|
(ptk/reify ::set-frame-grid
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state stream]
|
||||||
|
(rx/of (dwc/update-shapes [frame-id] #(assoc-in % [:grids index] data))))))
|
||||||
|
|
||||||
|
(defn set-default-grid
|
||||||
|
[type params]
|
||||||
(ptk/reify ::set-default-grid
|
(ptk/reify ::set-default-grid
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
|
|
@ -400,27 +400,30 @@
|
||||||
[ids]
|
[ids]
|
||||||
(us/verify (s/coll-of uuid?) ids)
|
(us/verify (s/coll-of uuid?) ids)
|
||||||
(ptk/reify ::apply-modifiers
|
(ptk/reify ::apply-modifiers
|
||||||
dwc/IUpdateGroup
|
|
||||||
(get-ids [_] ids)
|
|
||||||
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(let [page-id (:current-page-id state)
|
|
||||||
objects (get-in state [:workspace-data page-id :objects])
|
|
||||||
|
|
||||||
;; ID's + Children
|
|
||||||
ids-with-children (concat ids (mapcat #(cph/get-children % objects) ids))
|
|
||||||
|
|
||||||
;; For each shape applies the modifiers by transforming the objects
|
|
||||||
update-shape
|
|
||||||
(fn [state shape-id]
|
|
||||||
(update-in state [:workspace-data page-id :objects shape-id] gsh/transform-shape))]
|
|
||||||
|
|
||||||
(reduce update-shape state ids-with-children)))
|
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [page-id (:current-page-id state)]
|
(let [page-id (:current-page-id state)
|
||||||
(rx/of (dwc/diff-and-commit-changes page-id)
|
objects0 (get-in state [:workspace-pages page-id :data :objects])
|
||||||
(dwc/rehash-shape-frame-relationship ids))))))
|
objects1 (get-in state [:workspace-data page-id :objects])
|
||||||
|
|
||||||
|
;; ID's + Children ID's
|
||||||
|
ids-with-children (d/concat [] (mapcat #(cph/get-children % objects1) ids) ids)
|
||||||
|
|
||||||
|
;; For each shape applies the modifiers by transforming the objects
|
||||||
|
update-shape #(update %1 %2 gsh/transform-shape)
|
||||||
|
objects2 (reduce update-shape objects1 ids-with-children)
|
||||||
|
|
||||||
|
regchg {:type :reg-objects :shapes (vec ids)}
|
||||||
|
|
||||||
|
;; we need to generate redo chages from current
|
||||||
|
;; state (with current temporal values) to new state but
|
||||||
|
;; the undo should be calculated from clear current
|
||||||
|
;; state (without temporal values in it, for this reason
|
||||||
|
;; we have 3 different objects references).
|
||||||
|
|
||||||
|
rchanges (conj (dwc/generate-changes {:objects objects1} {:objects objects2}) regchg)
|
||||||
|
uchanges (conj (dwc/generate-changes {:objects objects2} {:objects objects0}) regchg)
|
||||||
|
]
|
||||||
|
|
||||||
|
(rx/of (dwc/commit-changes rchanges uchanges {:commit-local? true})
|
||||||
|
(dwc/rehash-shape-frame-relationship ids))))))
|
||||||
|
|
|
@ -137,7 +137,6 @@
|
||||||
|
|
||||||
:render-object
|
:render-object
|
||||||
(do
|
(do
|
||||||
(prn route)
|
|
||||||
(let [page-id (uuid (get-in route [:params :path :page-id]))
|
(let [page-id (uuid (get-in route [:params :path :page-id]))
|
||||||
object-id (uuid (get-in route [:params :path :object-id]))]
|
object-id (uuid (get-in route [:params :path :object-id]))]
|
||||||
[:& render/render-object {:page-id page-id
|
[:& render/render-object {:page-id page-id
|
||||||
|
|
Loading…
Add table
Reference in a new issue