0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

💄 Change some code styles

This commit is contained in:
Andrés Moya 2022-03-10 15:21:14 +01:00
parent e609670a41
commit 7b81bb3fc2
5 changed files with 57 additions and 47 deletions

View file

@ -40,7 +40,7 @@
(let [file-data (-> (cp/make-file-data (uuid/next) uuid/zero)
(assoc-in [:pages-index uuid/zero :objects] objects))]
(vary-meta changes assoc ::file-data file-data
::applied-changes 0)))
::applied-changes-count 0)))
(defn amend-last-change
"Modify the last redo-changes added with an update function."
@ -68,7 +68,7 @@
(defn- apply-changes-local
[changes]
(if-let [file-data (::file-data (meta changes))]
(let [index (::applied-changes (meta changes))
(let [index (::applied-changes-count (meta changes))
redo-changes (:redo-changes changes)
new-changes (if (< index (count redo-changes))
(->> (subvec (:redo-changes changes) index)
@ -76,7 +76,7 @@
[])
new-file-data (cp/process-changes file-data new-changes)]
(vary-meta changes assoc ::file-data new-file-data
::applied-changes (count redo-changes)))
::applied-changes-count (count redo-changes)))
changes))
;; Page changes
@ -134,6 +134,25 @@
:value old-val})
(apply-changes-local))))
(defn update-page-option
[changes option-key update-fn & args]
(assert-page changes)
(let [page-id (::page-id (meta changes))
page (::page (meta changes))
old-val (get-in page [:options option-key])
new-val (apply update-fn old-val args)]
(-> changes
(update :redo-changes conj {:type :set-option
:page-id page-id
:option option-key
:value new-val})
(update :undo-changes conj {:type :set-option
:page-id page-id
:option option-key
:value old-val})
(apply-changes-local))))
;; Shape tree changes
(defn add-obj
@ -173,7 +192,7 @@
([changes parent-id shapes index]
(assert-page-id changes)
(assert-objects changes)
(let [objects (-> changes meta ::file-data (get-in [:pages-index uuid/zero :objects]))
(let [objects (get-in (meta changes) [::file-data :pages-index uuid/zero :objects])
set-parent-change
(cond-> {:type :mov-objects
@ -208,7 +227,7 @@
([changes ids update-fn {:keys [attrs ignore-geometry?] :or {attrs nil ignore-geometry? false}}]
(assert-page-id changes)
(assert-objects changes)
(let [objects (-> changes meta ::file-data (get-in [:pages-index uuid/zero :objects]))
(let [objects (get-in (meta changes) [::file-data :pages-index uuid/zero :objects])
generate-operation
(fn [operations attr old new ignore-geometry?]
@ -255,7 +274,7 @@
(assert-page-id changes)
(assert-objects changes)
(let [page-id (::page-id (meta changes))
objects (-> changes meta ::file-data (get-in [:pages-index uuid/zero :objects]))
objects (get-in (meta changes) [::file-data :pages-index uuid/zero :objects])
add-redo-change
(fn [change-set id]
@ -303,7 +322,7 @@
(assert-page-id changes)
(assert-objects changes)
(let [page-id (::page-id (meta changes))
objects (-> changes meta ::file-data (get-in [:pages-index uuid/zero :objects]))
objects (get-in (meta changes) [::file-data :pages-index uuid/zero :objects])
xform (comp
(mapcat #(cons % (cph/get-parent-ids objects %)))

View file

@ -288,7 +288,9 @@
cp/default-shape-attrs)
selected-non-frames
(into #{} (filter #(not= (:type (get objects %)) :frame) selected))
(into #{} (comp (map (d/getf objects))
(remove cph/frame-shape?))
selected)
[frame-id parent-id index]
(get-shape-layer-position objects selected-non-frames attrs)]
@ -364,7 +366,6 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
page (wsh/lookup-page state page-id)
flows (-> page :options :flows)
ids (cph/clean-loops objects ids)
@ -397,7 +398,7 @@
;; If any of the deleted is a frame that starts a flow,
;; this must be deleted, too.
(contains? ids (:starting-frame flow)))
flows)
(-> page :options :flows))
all-parents
(reduce (fn [res id]
@ -448,10 +449,10 @@
interactions))))))
(cond->
(seq starting-flows)
(pcb/set-page-option :flows
(reduce #(csp/remove-flow %1 (:id %2))
flows
starting-flows))))]
(pcb/update-page-option :flows (fn [flows]
(reduce #(csp/remove-flow %1 (:id %2))
flows
starting-flows)))))]
(rx/of (dch/commit-changes changes))))))

View file

@ -28,14 +28,11 @@
(ptk/reify ::update-guides
ptk/WatchEvent
(watch [it state _]
(let [page (wsh/lookup-page state)
guides (get-in page [:options :guides] {})
new-guides (assoc guides (:id guide) guide)
(let [page (wsh/lookup-page state)
changes
(-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :guides new-guides))]
(pcb/update-page-option :guides assoc (:id guide) guide))]
(rx/of (dwc/commit-changes changes))))))
(defn remove-guide [guide]
@ -49,14 +46,11 @@
ptk/WatchEvent
(watch [it state _]
(let [page (wsh/lookup-page state)
guides (get-in page [:options :guides] {})
new-guides (dissoc guides (:id guide))
(let [page (wsh/lookup-page state)
changes
(-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :guides new-guides))]
(pcb/update-page-option :guides dissoc (:id guide)))]
(rx/of (dwc/commit-changes changes))))))
(defn remove-guides

View file

@ -29,8 +29,8 @@
ptk/WatchEvent
(watch [it state _]
(let [page (wsh/lookup-page state)
flows (get-in page [:options :flows] [])
flows (get-in page [:options :flows] [])
unames (into #{} (map :name flows))
name (dwc/generate-unique-name unames "Flow-1")
@ -41,8 +41,7 @@
(rx/of (dch/commit-changes
(-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :flows
(csp/add-flow flows new-flow)))))))))
(pcb/update-page-option :flows csp/add-flow new-flow))))))))
(defn add-flow-selected-frame
[]
@ -58,13 +57,11 @@
(ptk/reify ::remove-flow
ptk/WatchEvent
(watch [it state _]
(let [page (wsh/lookup-page state)
flows (get-in page [:options :flows] [])]
(let [page (wsh/lookup-page state)]
(rx/of (dch/commit-changes
(-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :flows
(csp/remove-flow flows flow-id)))))))))
(pcb/update-page-option :flows csp/remove-flow flow-id))))))))
(defn rename-flow
[flow-id name]
@ -73,14 +70,12 @@
(ptk/reify ::rename-flow
ptk/WatchEvent
(watch [it state _]
(let [page (wsh/lookup-page state)
flows (get-in page [:options :flows] [])]
(let [page (wsh/lookup-page state) ]
(rx/of (dch/commit-changes
(-> (pcb/empty-changes it)
(pcb/with-page page)
(pcb/set-page-option :flows
(csp/update-flow flows flow-id
#(csp/rename-flow % name))))))))))
(pcb/update-page-option :flows csp/update-flow flow-id
#(csp/rename-flow % name)))))))))
(defn start-rename-flow
[id]

View file

@ -376,17 +376,18 @@
(filter #(= (:type %) :frame))
(filter #(some? (ctp/get-frame-flow flows (:id %)))))]
(if-not (empty? frames-with-flow)
(let [new-flows (reduce
(fn [flows frame]
(let [name (dwc/generate-unique-name @unames "Flow-1")
_ (vswap! unames conj name)
new-flow {:id (uuid/next)
:name name
:starting-frame (get ids-map (:id frame))}]
(ctp/add-flow flows new-flow)))
flows
frames-with-flow)]
(pcb/set-page-option changes :flows new-flows))
(let [update-flows (fn [flows]
(reduce
(fn [flows frame]
(let [name (dwc/generate-unique-name @unames "Flow-1")
_ (vswap! unames conj name)
new-flow {:id (uuid/next)
:name name
:starting-frame (get ids-map (:id frame))}]
(ctp/add-flow flows new-flow)))
flows
frames-with-flow))]
(pcb/update-page-option changes :flows update-flows))
changes)))
(defn duplicate-changes-update-indices