mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 14:39:45 -05:00
✨ Create paths, booleans and ellipses through plugins api
This commit is contained in:
parent
e4e537b960
commit
55c27f140a
3 changed files with 73 additions and 26 deletions
|
@ -79,6 +79,12 @@
|
|||
(def text-align-types
|
||||
#{"left" "right" "center" "justify"})
|
||||
|
||||
(def bool-types
|
||||
#{:union
|
||||
:difference
|
||||
:exclude
|
||||
:intersection})
|
||||
|
||||
(sm/define! ::points
|
||||
[:vector {:gen/max 4 :gen/min 4} ::gpt/point])
|
||||
|
||||
|
@ -200,8 +206,10 @@
|
|||
[:type [:= :bool]]
|
||||
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
|
||||
|
||||
;; FIXME: improve this schema
|
||||
[:bool-type :keyword]
|
||||
;; FIXME: This should be the spec but we need to create a migration
|
||||
;; to make this transition safely
|
||||
;; [:bool-type [::sm/one-of bool-types]]
|
||||
|
||||
[:bool-content
|
||||
[:vector {:gen/max 2}
|
||||
|
|
|
@ -83,31 +83,38 @@
|
|||
(gsh/update-group-selrect children))))
|
||||
|
||||
(defn create-bool
|
||||
[bool-type]
|
||||
(ptk/reify ::create-bool-union
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state)
|
||||
name (-> bool-type d/name str/capital)
|
||||
ids (selected-shapes-idx state)
|
||||
ordered-indexes (cph/order-by-indexed-shapes objects ids)
|
||||
shapes (->> ordered-indexes
|
||||
(map (d/getf objects))
|
||||
(remove cph/frame-shape?)
|
||||
(remove #(ctn/has-any-copy-parent? objects %)))]
|
||||
([bool-type]
|
||||
(create-bool bool-type nil nil))
|
||||
([bool-type ids {:keys [id-ret]}]
|
||||
(assert (or (nil? ids) (set? ids)))
|
||||
(ptk/reify ::create-bool-union
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state)
|
||||
name (-> bool-type d/name str/capital)
|
||||
ids (->> (d/nilv ids (wsh/lookup-selected state))
|
||||
(cph/clean-loops objects))
|
||||
ordered-indexes (cph/order-by-indexed-shapes objects ids)
|
||||
shapes (->> ordered-indexes
|
||||
(map (d/getf objects))
|
||||
(remove cph/frame-shape?)
|
||||
(remove #(ctn/has-any-copy-parent? objects %)))]
|
||||
|
||||
(when-not (empty? shapes)
|
||||
(let [[boolean-data index] (create-bool-data bool-type name (reverse shapes) objects)
|
||||
index (inc index)
|
||||
shape-id (:id boolean-data)
|
||||
changes (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/add-object boolean-data {:index index})
|
||||
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
|
||||
(pcb/change-parent shape-id shapes))]
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(dws/select-shapes (d/ordered-set shape-id)))))))))
|
||||
(when-not (empty? shapes)
|
||||
(let [[boolean-data index] (create-bool-data bool-type name (reverse shapes) objects)
|
||||
index (inc index)
|
||||
shape-id (:id boolean-data)
|
||||
changes (-> (pcb/empty-changes it page-id)
|
||||
(pcb/with-objects objects)
|
||||
(pcb/add-object boolean-data {:index index})
|
||||
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
|
||||
(pcb/change-parent shape-id shapes))]
|
||||
(when id-ret
|
||||
(reset! id-ret shape-id))
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(dws/select-shapes (d/ordered-set shape-id))))))))))
|
||||
|
||||
(defn group-to-bool
|
||||
[shape-id bool-type]
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.changes :as ch]
|
||||
[app.main.data.workspace.bool :as dwb]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.media :as dwm]
|
||||
[app.main.store :as st]
|
||||
|
@ -124,6 +125,26 @@
|
|||
[_]
|
||||
(create-shape :rect))
|
||||
|
||||
(createEllipse
|
||||
[_]
|
||||
(create-shape :circle))
|
||||
|
||||
(createPath
|
||||
[_]
|
||||
(let [page-id (:current-page-id @st/state)
|
||||
page (dm/get-in @st/state [:workspace-data :pages-index page-id])
|
||||
shape (cts/setup-shape
|
||||
{:type :path
|
||||
:content [{:command :move-to :params {:x 0 :y 0}}
|
||||
{:command :line-to :params {:x 100 :y 100}}]})
|
||||
changes
|
||||
(-> (cb/empty-changes)
|
||||
(cb/with-page page)
|
||||
(cb/with-objects (:objects page))
|
||||
(cb/add-object shape))]
|
||||
(st/emit! (ch/commit-changes changes))
|
||||
(shape/shape-proxy (:id shape))))
|
||||
|
||||
(createText
|
||||
[_ text]
|
||||
(let [file-id (:current-file-id @st/state)
|
||||
|
@ -147,7 +168,18 @@
|
|||
file-id (:current-file-id @st/state)
|
||||
page-id (:current-page-id @st/state)]
|
||||
(st/emit! (dwm/create-svg-shape id "svg" svg-string (gpt/point 0 0)))
|
||||
(shape/shape-proxy file-id page-id id)))))
|
||||
(shape/shape-proxy file-id page-id id))))
|
||||
|
||||
(createBoolean [_ bool-type shapes]
|
||||
(let [ids (into #{} (map #(obj/get % "$id")) shapes)
|
||||
bool-type (keyword bool-type)]
|
||||
|
||||
(if (contains? cts/bool-types bool-type)
|
||||
(let [id-ret (atom nil)]
|
||||
(st/emit! (dwb/create-bool bool-type ids {:id-ret id-ret}))
|
||||
(shape/shape-proxy @id-ret))
|
||||
|
||||
(utils/display-not-valid :bool-shape bool-type)))))
|
||||
|
||||
(defn create-context
|
||||
[]
|
||||
|
|
Loading…
Add table
Reference in a new issue