mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 14:41:37 +02:00
✨ Add api methods to align, distribute and flatten shapes
This commit is contained in:
parent
fb39dd5440
commit
8c1fba5160
3 changed files with 117 additions and 70 deletions
|
@ -371,30 +371,70 @@
|
|||
(st/emit! (dw/go-to-page id))))
|
||||
|
||||
(alignHorizontal
|
||||
[_ _shapes _direction]
|
||||
;; TODO
|
||||
)
|
||||
[_ shapes direction]
|
||||
(let [dir (case direction
|
||||
"left" :hleft
|
||||
"center" :hcenter
|
||||
"right" :hright
|
||||
nil)]
|
||||
(cond
|
||||
(nil? dir)
|
||||
(u/display-not-valid :alignHorizontal-direction "Direction not valid")
|
||||
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :alignHorizontal-shapes "Not valid shapes")
|
||||
|
||||
:else
|
||||
(let [ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dw/align-objects dir ids))))))
|
||||
|
||||
(alignVertical
|
||||
[_ _shapes _direction]
|
||||
;; TODO
|
||||
)
|
||||
[_ shapes direction]
|
||||
(let [dir (case direction
|
||||
"top" :vtop
|
||||
"center" :vcenter
|
||||
"bottom" :vbottom
|
||||
nil)]
|
||||
(cond
|
||||
(nil? dir)
|
||||
(u/display-not-valid :alignVertical-direction "Direction not valid")
|
||||
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :alignVertical-shapes "Not valid shapes")
|
||||
|
||||
:else
|
||||
(let [ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dw/align-objects dir ids))))))
|
||||
|
||||
(distributeHorizontal
|
||||
[_ _shapes]
|
||||
;; TODO
|
||||
)
|
||||
[_ shapes]
|
||||
(cond
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :distributeHorizontal-shapes "Not valid shapes")
|
||||
|
||||
:else
|
||||
(let [ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dw/distribute-objects :horizontal ids)))))
|
||||
|
||||
(distributeVertical
|
||||
[_ _shapes]
|
||||
;; TODO
|
||||
)
|
||||
[_ shapes]
|
||||
(cond
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :distributeVertical-shapes "Not valid shapes")
|
||||
|
||||
:else
|
||||
(let [ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dw/distribute-objects :vertical ids)))))
|
||||
|
||||
(flatten
|
||||
[_ _shapes]
|
||||
;; TODO
|
||||
)
|
||||
)
|
||||
[_ shapes]
|
||||
(cond
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :flatten-shapes "Not valid shapes")
|
||||
|
||||
:else
|
||||
(let [ids (into #{} (map #(obj/get % "$id")) shapes)]
|
||||
(st/emit! (dw/convert-selected-to-path ids))))))
|
||||
|
||||
(defn create-context
|
||||
[plugin-id]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue