mirror of
https://github.com/penpot/penpot.git
synced 2025-05-20 16:56:11 +02:00
✨ Review changes
This commit is contained in:
parent
8833e19c7f
commit
6e0433a34b
6 changed files with 91 additions and 70 deletions
|
@ -13,12 +13,21 @@
|
||||||
;; Auxiliary functions to help create a set of changes (undo + redo)
|
;; Auxiliary functions to help create a set of changes (undo + redo)
|
||||||
|
|
||||||
(defn empty-changes
|
(defn empty-changes
|
||||||
[origin page-id]
|
([origin page-id]
|
||||||
(let [changes {:redo-changes []
|
(let [changes (empty-changes origin)]
|
||||||
:undo-changes []
|
(with-meta changes
|
||||||
:origin origin}]
|
{::page-id page-id})))
|
||||||
(with-meta changes
|
|
||||||
{::page-id page-id})))
|
([origin]
|
||||||
|
{:redo-changes []
|
||||||
|
:undo-changes []
|
||||||
|
:origin origin}))
|
||||||
|
|
||||||
|
(defn with-page [changes page]
|
||||||
|
(vary-meta changes assoc
|
||||||
|
::page page
|
||||||
|
::page-id (:id page)
|
||||||
|
::objects (:objects page)))
|
||||||
|
|
||||||
(defn with-objects [changes objects]
|
(defn with-objects [changes objects]
|
||||||
(vary-meta changes assoc ::objects objects))
|
(vary-meta changes assoc ::objects objects))
|
||||||
|
@ -167,10 +176,25 @@
|
||||||
(reduce add-undo-change-parent $ ids)
|
(reduce add-undo-change-parent $ ids)
|
||||||
(reduce add-undo-change-shape $ ids))))))
|
(reduce add-undo-change-shape $ ids))))))
|
||||||
|
|
||||||
|
|
||||||
(defn move-page
|
(defn move-page
|
||||||
[chdata index prev-index]
|
[chdata index prev-index]
|
||||||
(let [page-id (::page-id (meta chdata))]
|
(let [page-id (::page-id (meta chdata))]
|
||||||
(-> chdata
|
(-> chdata
|
||||||
(update :redo-changes conj {:type :mov-page :id page-id :index index})
|
(update :redo-changes conj {:type :mov-page :id page-id :index index})
|
||||||
(update :undo-changes conj {:type :mov-page :id page-id :index prev-index}))))
|
(update :undo-changes conj {:type :mov-page :id page-id :index prev-index}))))
|
||||||
|
|
||||||
|
(defn set-page-option
|
||||||
|
[chdata option-key option-val]
|
||||||
|
(let [page-id (::page-id (meta chdata))
|
||||||
|
page (::page (meta chdata))
|
||||||
|
old-val (get-in page [:options option-key])]
|
||||||
|
|
||||||
|
(-> chdata
|
||||||
|
(update :redo-changes conj {:type :set-option
|
||||||
|
:page-id page-id
|
||||||
|
:option option-key
|
||||||
|
:value option-val})
|
||||||
|
(update :undo-changes conj {:type :set-option
|
||||||
|
:page-id page-id
|
||||||
|
:option option-key
|
||||||
|
:value old-val}))))
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.pages.changes-builder :as pcb]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.types.page-options :as tpo]
|
[app.common.types.page-options :as tpo]
|
||||||
[app.main.data.workspace.changes :as dwc]
|
[app.main.data.workspace.changes :as dwc]
|
||||||
|
@ -27,47 +28,30 @@
|
||||||
(ptk/reify ::update-guides
|
(ptk/reify ::update-guides
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page (wsh/lookup-page state)
|
||||||
guides (-> state wsh/lookup-page-options (:guides {}))
|
guides (get-in page [:options :guides] {})
|
||||||
|
|
||||||
new-guides (assoc guides (:id guide) guide)
|
new-guides (assoc guides (:id guide) guide)
|
||||||
|
|
||||||
rch [{:type :set-option
|
changes
|
||||||
:page-id page-id
|
(-> (pcb/empty-changes it)
|
||||||
:option :guides
|
(pcb/with-page page)
|
||||||
:value new-guides}]
|
(pcb/set-page-option :guides new-guides))]
|
||||||
uch [{:type :set-option
|
(rx/of (dwc/commit-changes changes))))))
|
||||||
:page-id page-id
|
|
||||||
:option :guides
|
|
||||||
:value guides}]]
|
|
||||||
(rx/of
|
|
||||||
(dwc/commit-changes
|
|
||||||
{:redo-changes rch
|
|
||||||
:undo-changes uch
|
|
||||||
:origin it}))))))
|
|
||||||
|
|
||||||
(defn remove-guide [guide]
|
(defn remove-guide [guide]
|
||||||
(us/verify ::tpo/guide guide)
|
(us/verify ::tpo/guide guide)
|
||||||
(ptk/reify ::remove-guide
|
(ptk/reify ::remove-guide
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page (wsh/lookup-page state)
|
||||||
guides (-> state wsh/lookup-page-options (:guides {}))
|
guides (get-in page [:options :guides] {})
|
||||||
new-guides (dissoc guides (:id guide))
|
new-guides (dissoc guides (:id guide))
|
||||||
|
|
||||||
rch [{:type :set-option
|
changes
|
||||||
:page-id page-id
|
(-> (pcb/empty-changes it)
|
||||||
:option :guides
|
(pcb/with-page page)
|
||||||
:value new-guides}]
|
(pcb/set-page-option :guides new-guides))]
|
||||||
uch [{:type :set-option
|
(rx/of (dwc/commit-changes changes))))))
|
||||||
:page-id page-id
|
|
||||||
:option :guides
|
|
||||||
:value guides}]]
|
|
||||||
(rx/of
|
|
||||||
(dwc/commit-changes
|
|
||||||
{:redo-changes rch
|
|
||||||
:undo-changes uch
|
|
||||||
:origin it}))))))
|
|
||||||
|
|
||||||
(defn move-frame-guides
|
(defn move-frame-guides
|
||||||
"Move guides that are inside a frame when that frame is moved"
|
"Move guides that are inside a frame when that frame is moved"
|
||||||
|
@ -78,7 +62,10 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
frame-ids? (->> ids (filter #(= :frame (get-in objects [% :type]))) (into #{}))
|
|
||||||
|
is-frame? (fn [id] (= :frame (get-in objects [id :type])))
|
||||||
|
frame-ids? (into #{} (filter is-frame?) ids)
|
||||||
|
|
||||||
object-modifiers (get state :workspace-modifiers)
|
object-modifiers (get state :workspace-modifiers)
|
||||||
|
|
||||||
build-move-event
|
build-move-event
|
||||||
|
|
|
@ -9,6 +9,12 @@
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.pages :as cp]))
|
[app.common.pages :as cp]))
|
||||||
|
|
||||||
|
(defn lookup-page
|
||||||
|
([state]
|
||||||
|
(lookup-page state (:current-page-id state)))
|
||||||
|
([state page-id]
|
||||||
|
(get-in state [:workspace-data :pages-index page-id])))
|
||||||
|
|
||||||
(defn lookup-page-objects
|
(defn lookup-page-objects
|
||||||
([state]
|
([state]
|
||||||
(lookup-page-objects state (:current-page-id state)))
|
(lookup-page-objects state (:current-page-id state)))
|
||||||
|
|
|
@ -152,10 +152,7 @@
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [layout zoom objects selected page-id drawing transform modifiers] :as props}]
|
[{:keys [layout zoom objects selected page-id drawing transform modifiers] :as props}]
|
||||||
|
|
||||||
(let [shapes
|
(let [shapes (into [] (keep (d/getf objects)) selected)
|
||||||
(->> selected
|
|
||||||
(map #(get objects %))
|
|
||||||
(filterv (comp not nil?)))
|
|
||||||
|
|
||||||
filter-shapes
|
filter-shapes
|
||||||
(into #{}
|
(into #{}
|
||||||
|
|
|
@ -22,22 +22,28 @@
|
||||||
;; PRIVATE FUNCTIONS
|
;; PRIVATE FUNCTIONS
|
||||||
|
|
||||||
(defn- make-insert-tree-data
|
(defn- make-insert-tree-data
|
||||||
|
"Inserts all data in it's corresponding axis bucket"
|
||||||
[shape-data axis]
|
[shape-data axis]
|
||||||
(fn [tree]
|
(fn [tree]
|
||||||
(let [tree (or tree (rt/make-tree))]
|
(let [tree (or tree (rt/make-tree))
|
||||||
(as-> tree $
|
|
||||||
(reduce (fn [tree data]
|
insert-data
|
||||||
(rt/insert tree (get-in data [:pt axis]) data))
|
(fn [tree data]
|
||||||
$ shape-data)))))
|
(rt/insert tree (get-in data [:pt axis]) data))]
|
||||||
|
|
||||||
|
(reduce insert-data tree shape-data))))
|
||||||
|
|
||||||
(defn- make-delete-tree-data
|
(defn- make-delete-tree-data
|
||||||
|
"Removes all data in it's corresponding axis bucket"
|
||||||
[shape-data axis]
|
[shape-data axis]
|
||||||
(fn [tree]
|
(fn [tree]
|
||||||
(let [tree (or tree (rt/make-tree))]
|
(let [tree (or tree (rt/make-tree))
|
||||||
(as-> tree $
|
|
||||||
(reduce (fn [tree data]
|
remove-data
|
||||||
(rt/remove tree (get-in data [:pt axis]) data))
|
(fn [tree data]
|
||||||
$ shape-data)))))
|
(rt/remove tree (get-in data [:pt axis]) data))]
|
||||||
|
|
||||||
|
(reduce remove-data tree shape-data))))
|
||||||
|
|
||||||
(defn- add-root-frame
|
(defn- add-root-frame
|
||||||
[page-data]
|
[page-data]
|
||||||
|
@ -52,19 +58,19 @@
|
||||||
(let [frame-id (:id frame)
|
(let [frame-id (:id frame)
|
||||||
parent-id (:parent-id frame)
|
parent-id (:parent-id frame)
|
||||||
frame-data (->> (snap/shape-snap-points frame)
|
frame-data (->> (snap/shape-snap-points frame)
|
||||||
(map #(hash-map :type :shape
|
(mapv #(array-map :type :shape
|
||||||
:id frame-id
|
:id frame-id
|
||||||
:pt %)))
|
:pt %)))
|
||||||
|
|
||||||
grid-x-data (->> (gg/grid-snap-points frame :x)
|
grid-x-data (->> (gg/grid-snap-points frame :x)
|
||||||
(map #(hash-map :type :grid-x
|
(mapv #(array-map :type :grid-x
|
||||||
:id frame-id
|
:id frame-id
|
||||||
:pt %)))
|
:pt %)))
|
||||||
|
|
||||||
grid-y-data (->> (gg/grid-snap-points frame :y)
|
grid-y-data (->> (gg/grid-snap-points frame :y)
|
||||||
(map #(hash-map :type :grid-y
|
(mapv #(array-map :type :grid-y
|
||||||
:id frame-id
|
:id frame-id
|
||||||
:pt %)))]
|
:pt %)))]
|
||||||
|
|
||||||
(-> page-data
|
(-> page-data
|
||||||
;; Update root frame information
|
;; Update root frame information
|
||||||
|
@ -84,7 +90,7 @@
|
||||||
(let [frame-id (:frame-id shape)
|
(let [frame-id (:frame-id shape)
|
||||||
snap-points (snap/shape-snap-points shape)
|
snap-points (snap/shape-snap-points shape)
|
||||||
shape-data (->> snap-points
|
shape-data (->> snap-points
|
||||||
(mapv #(hash-map
|
(mapv #(array-map
|
||||||
:type :shape
|
:type :shape
|
||||||
:id (:id shape)
|
:id (:id shape)
|
||||||
:pt %)))]
|
:pt %)))]
|
||||||
|
@ -98,7 +104,7 @@
|
||||||
[page-data guide]
|
[page-data guide]
|
||||||
|
|
||||||
(let [guide-data (->> (snap/guide-snap-points guide)
|
(let [guide-data (->> (snap/guide-snap-points guide)
|
||||||
(mapv #(hash-map
|
(mapv #(array-map
|
||||||
:type :guide
|
:type :guide
|
||||||
:id (:id guide)
|
:id (:id guide)
|
||||||
:pt %)))]
|
:pt %)))]
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
(defmethod impl/handler :snaps/range-query
|
(defmethod impl/handler :snaps/range-query
|
||||||
[{:keys [page-id frame-id axis ranges] :as message}]
|
[{:keys [page-id frame-id axis ranges] :as message}]
|
||||||
(->> ranges
|
|
||||||
(mapcat #(sd/query @state page-id frame-id axis %))
|
(into []
|
||||||
(set) ;; unique
|
(comp (mapcat #(sd/query @state page-id frame-id axis %))
|
||||||
(into [])))
|
(distinct))
|
||||||
|
ranges))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue