mirror of
https://github.com/penpot/penpot.git
synced 2025-05-30 19:16:10 +02:00
💄 Change some code styles
This commit is contained in:
parent
e609670a41
commit
7b81bb3fc2
5 changed files with 57 additions and 47 deletions
|
@ -40,7 +40,7 @@
|
||||||
(let [file-data (-> (cp/make-file-data (uuid/next) uuid/zero)
|
(let [file-data (-> (cp/make-file-data (uuid/next) uuid/zero)
|
||||||
(assoc-in [:pages-index uuid/zero :objects] objects))]
|
(assoc-in [:pages-index uuid/zero :objects] objects))]
|
||||||
(vary-meta changes assoc ::file-data file-data
|
(vary-meta changes assoc ::file-data file-data
|
||||||
::applied-changes 0)))
|
::applied-changes-count 0)))
|
||||||
|
|
||||||
(defn amend-last-change
|
(defn amend-last-change
|
||||||
"Modify the last redo-changes added with an update function."
|
"Modify the last redo-changes added with an update function."
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
(defn- apply-changes-local
|
(defn- apply-changes-local
|
||||||
[changes]
|
[changes]
|
||||||
(if-let [file-data (::file-data (meta 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)
|
redo-changes (:redo-changes changes)
|
||||||
new-changes (if (< index (count redo-changes))
|
new-changes (if (< index (count redo-changes))
|
||||||
(->> (subvec (:redo-changes changes) index)
|
(->> (subvec (:redo-changes changes) index)
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
[])
|
[])
|
||||||
new-file-data (cp/process-changes file-data new-changes)]
|
new-file-data (cp/process-changes file-data new-changes)]
|
||||||
(vary-meta changes assoc ::file-data new-file-data
|
(vary-meta changes assoc ::file-data new-file-data
|
||||||
::applied-changes (count redo-changes)))
|
::applied-changes-count (count redo-changes)))
|
||||||
changes))
|
changes))
|
||||||
|
|
||||||
;; Page changes
|
;; Page changes
|
||||||
|
@ -134,6 +134,25 @@
|
||||||
:value old-val})
|
:value old-val})
|
||||||
(apply-changes-local))))
|
(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
|
;; Shape tree changes
|
||||||
|
|
||||||
(defn add-obj
|
(defn add-obj
|
||||||
|
@ -173,7 +192,7 @@
|
||||||
([changes parent-id shapes index]
|
([changes parent-id shapes index]
|
||||||
(assert-page-id changes)
|
(assert-page-id changes)
|
||||||
(assert-objects 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
|
set-parent-change
|
||||||
(cond-> {:type :mov-objects
|
(cond-> {:type :mov-objects
|
||||||
|
@ -208,7 +227,7 @@
|
||||||
([changes ids update-fn {:keys [attrs ignore-geometry?] :or {attrs nil ignore-geometry? false}}]
|
([changes ids update-fn {:keys [attrs ignore-geometry?] :or {attrs nil ignore-geometry? false}}]
|
||||||
(assert-page-id changes)
|
(assert-page-id changes)
|
||||||
(assert-objects 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
|
generate-operation
|
||||||
(fn [operations attr old new ignore-geometry?]
|
(fn [operations attr old new ignore-geometry?]
|
||||||
|
@ -255,7 +274,7 @@
|
||||||
(assert-page-id changes)
|
(assert-page-id changes)
|
||||||
(assert-objects changes)
|
(assert-objects changes)
|
||||||
(let [page-id (::page-id (meta 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
|
add-redo-change
|
||||||
(fn [change-set id]
|
(fn [change-set id]
|
||||||
|
@ -303,7 +322,7 @@
|
||||||
(assert-page-id changes)
|
(assert-page-id changes)
|
||||||
(assert-objects changes)
|
(assert-objects changes)
|
||||||
(let [page-id (::page-id (meta 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
|
xform (comp
|
||||||
(mapcat #(cons % (cph/get-parent-ids objects %)))
|
(mapcat #(cons % (cph/get-parent-ids objects %)))
|
||||||
|
|
|
@ -288,7 +288,9 @@
|
||||||
cp/default-shape-attrs)
|
cp/default-shape-attrs)
|
||||||
|
|
||||||
selected-non-frames
|
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]
|
[frame-id parent-id index]
|
||||||
(get-shape-layer-position objects selected-non-frames attrs)]
|
(get-shape-layer-position objects selected-non-frames attrs)]
|
||||||
|
@ -364,7 +366,6 @@
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
page (wsh/lookup-page state page-id)
|
page (wsh/lookup-page state page-id)
|
||||||
flows (-> page :options :flows)
|
|
||||||
|
|
||||||
ids (cph/clean-loops objects ids)
|
ids (cph/clean-loops objects ids)
|
||||||
|
|
||||||
|
@ -397,7 +398,7 @@
|
||||||
;; If any of the deleted is a frame that starts a flow,
|
;; If any of the deleted is a frame that starts a flow,
|
||||||
;; this must be deleted, too.
|
;; this must be deleted, too.
|
||||||
(contains? ids (:starting-frame flow)))
|
(contains? ids (:starting-frame flow)))
|
||||||
flows)
|
(-> page :options :flows))
|
||||||
|
|
||||||
all-parents
|
all-parents
|
||||||
(reduce (fn [res id]
|
(reduce (fn [res id]
|
||||||
|
@ -448,10 +449,10 @@
|
||||||
interactions))))))
|
interactions))))))
|
||||||
(cond->
|
(cond->
|
||||||
(seq starting-flows)
|
(seq starting-flows)
|
||||||
(pcb/set-page-option :flows
|
(pcb/update-page-option :flows (fn [flows]
|
||||||
(reduce #(csp/remove-flow %1 (:id %2))
|
(reduce #(csp/remove-flow %1 (:id %2))
|
||||||
flows
|
flows
|
||||||
starting-flows))))]
|
starting-flows)))))]
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes))))))
|
(rx/of (dch/commit-changes changes))))))
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,11 @@
|
||||||
(ptk/reify ::update-guides
|
(ptk/reify ::update-guides
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page (wsh/lookup-page state)
|
(let [page (wsh/lookup-page state)
|
||||||
guides (get-in page [:options :guides] {})
|
|
||||||
new-guides (assoc guides (:id guide) guide)
|
|
||||||
|
|
||||||
changes
|
changes
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/with-page page)
|
(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))))))
|
(rx/of (dwc/commit-changes changes))))))
|
||||||
|
|
||||||
(defn remove-guide [guide]
|
(defn remove-guide [guide]
|
||||||
|
@ -49,14 +46,11 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page (wsh/lookup-page state)
|
(let [page (wsh/lookup-page state)
|
||||||
guides (get-in page [:options :guides] {})
|
|
||||||
new-guides (dissoc guides (:id guide))
|
|
||||||
|
|
||||||
changes
|
changes
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/with-page page)
|
(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))))))
|
(rx/of (dwc/commit-changes changes))))))
|
||||||
|
|
||||||
(defn remove-guides
|
(defn remove-guides
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page (wsh/lookup-page state)
|
(let [page (wsh/lookup-page state)
|
||||||
flows (get-in page [:options :flows] [])
|
|
||||||
|
|
||||||
|
flows (get-in page [:options :flows] [])
|
||||||
unames (into #{} (map :name flows))
|
unames (into #{} (map :name flows))
|
||||||
name (dwc/generate-unique-name unames "Flow-1")
|
name (dwc/generate-unique-name unames "Flow-1")
|
||||||
|
|
||||||
|
@ -41,8 +41,7 @@
|
||||||
(rx/of (dch/commit-changes
|
(rx/of (dch/commit-changes
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/with-page page)
|
(pcb/with-page page)
|
||||||
(pcb/set-page-option :flows
|
(pcb/update-page-option :flows csp/add-flow new-flow))))))))
|
||||||
(csp/add-flow flows new-flow)))))))))
|
|
||||||
|
|
||||||
(defn add-flow-selected-frame
|
(defn add-flow-selected-frame
|
||||||
[]
|
[]
|
||||||
|
@ -58,13 +57,11 @@
|
||||||
(ptk/reify ::remove-flow
|
(ptk/reify ::remove-flow
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page (wsh/lookup-page state)
|
(let [page (wsh/lookup-page state)]
|
||||||
flows (get-in page [:options :flows] [])]
|
|
||||||
(rx/of (dch/commit-changes
|
(rx/of (dch/commit-changes
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/with-page page)
|
(pcb/with-page page)
|
||||||
(pcb/set-page-option :flows
|
(pcb/update-page-option :flows csp/remove-flow flow-id))))))))
|
||||||
(csp/remove-flow flows flow-id)))))))))
|
|
||||||
|
|
||||||
(defn rename-flow
|
(defn rename-flow
|
||||||
[flow-id name]
|
[flow-id name]
|
||||||
|
@ -73,14 +70,12 @@
|
||||||
(ptk/reify ::rename-flow
|
(ptk/reify ::rename-flow
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page (wsh/lookup-page state)
|
(let [page (wsh/lookup-page state) ]
|
||||||
flows (get-in page [:options :flows] [])]
|
|
||||||
(rx/of (dch/commit-changes
|
(rx/of (dch/commit-changes
|
||||||
(-> (pcb/empty-changes it)
|
(-> (pcb/empty-changes it)
|
||||||
(pcb/with-page page)
|
(pcb/with-page page)
|
||||||
(pcb/set-page-option :flows
|
(pcb/update-page-option :flows csp/update-flow flow-id
|
||||||
(csp/update-flow flows flow-id
|
#(csp/rename-flow % name)))))))))
|
||||||
#(csp/rename-flow % name))))))))))
|
|
||||||
|
|
||||||
(defn start-rename-flow
|
(defn start-rename-flow
|
||||||
[id]
|
[id]
|
||||||
|
|
|
@ -376,17 +376,18 @@
|
||||||
(filter #(= (:type %) :frame))
|
(filter #(= (:type %) :frame))
|
||||||
(filter #(some? (ctp/get-frame-flow flows (:id %)))))]
|
(filter #(some? (ctp/get-frame-flow flows (:id %)))))]
|
||||||
(if-not (empty? frames-with-flow)
|
(if-not (empty? frames-with-flow)
|
||||||
(let [new-flows (reduce
|
(let [update-flows (fn [flows]
|
||||||
(fn [flows frame]
|
(reduce
|
||||||
(let [name (dwc/generate-unique-name @unames "Flow-1")
|
(fn [flows frame]
|
||||||
_ (vswap! unames conj name)
|
(let [name (dwc/generate-unique-name @unames "Flow-1")
|
||||||
new-flow {:id (uuid/next)
|
_ (vswap! unames conj name)
|
||||||
:name name
|
new-flow {:id (uuid/next)
|
||||||
:starting-frame (get ids-map (:id frame))}]
|
:name name
|
||||||
(ctp/add-flow flows new-flow)))
|
:starting-frame (get ids-map (:id frame))}]
|
||||||
flows
|
(ctp/add-flow flows new-flow)))
|
||||||
frames-with-flow)]
|
flows
|
||||||
(pcb/set-page-option changes :flows new-flows))
|
frames-with-flow))]
|
||||||
|
(pcb/update-page-option changes :flows update-flows))
|
||||||
changes)))
|
changes)))
|
||||||
|
|
||||||
(defn duplicate-changes-update-indices
|
(defn duplicate-changes-update-indices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue