mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 16:18:11 -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
|
(def text-align-types
|
||||||
#{"left" "right" "center" "justify"})
|
#{"left" "right" "center" "justify"})
|
||||||
|
|
||||||
|
(def bool-types
|
||||||
|
#{:union
|
||||||
|
:difference
|
||||||
|
:exclude
|
||||||
|
:intersection})
|
||||||
|
|
||||||
(sm/define! ::points
|
(sm/define! ::points
|
||||||
[:vector {:gen/max 4 :gen/min 4} ::gpt/point])
|
[:vector {:gen/max 4 :gen/min 4} ::gpt/point])
|
||||||
|
|
||||||
|
@ -200,8 +206,10 @@
|
||||||
[:type [:= :bool]]
|
[:type [:= :bool]]
|
||||||
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
|
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
|
||||||
|
|
||||||
;; FIXME: improve this schema
|
|
||||||
[:bool-type :keyword]
|
[: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
|
[:bool-content
|
||||||
[:vector {:gen/max 2}
|
[:vector {:gen/max 2}
|
||||||
|
|
|
@ -83,14 +83,18 @@
|
||||||
(gsh/update-group-selrect children))))
|
(gsh/update-group-selrect children))))
|
||||||
|
|
||||||
(defn create-bool
|
(defn create-bool
|
||||||
[bool-type]
|
([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/reify ::create-bool-union
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it state _]
|
(watch [it state _]
|
||||||
(let [page-id (:current-page-id state)
|
(let [page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state)
|
objects (wsh/lookup-page-objects state)
|
||||||
name (-> bool-type d/name str/capital)
|
name (-> bool-type d/name str/capital)
|
||||||
ids (selected-shapes-idx state)
|
ids (->> (d/nilv ids (wsh/lookup-selected state))
|
||||||
|
(cph/clean-loops objects))
|
||||||
ordered-indexes (cph/order-by-indexed-shapes objects ids)
|
ordered-indexes (cph/order-by-indexed-shapes objects ids)
|
||||||
shapes (->> ordered-indexes
|
shapes (->> ordered-indexes
|
||||||
(map (d/getf objects))
|
(map (d/getf objects))
|
||||||
|
@ -106,8 +110,11 @@
|
||||||
(pcb/add-object boolean-data {:index index})
|
(pcb/add-object boolean-data {:index index})
|
||||||
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
|
(pcb/update-shapes (map :id shapes) ctl/remove-layout-item-data)
|
||||||
(pcb/change-parent shape-id shapes))]
|
(pcb/change-parent shape-id shapes))]
|
||||||
|
(when id-ret
|
||||||
|
(reset! id-ret shape-id))
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes)
|
(rx/of (dch/commit-changes changes)
|
||||||
(dws/select-shapes (d/ordered-set shape-id)))))))))
|
(dws/select-shapes (d/ordered-set shape-id))))))))))
|
||||||
|
|
||||||
(defn group-to-bool
|
(defn group-to-bool
|
||||||
[shape-id bool-type]
|
[shape-id bool-type]
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.changes :as ch]
|
[app.main.data.changes :as ch]
|
||||||
|
[app.main.data.workspace.bool :as dwb]
|
||||||
[app.main.data.workspace.groups :as dwg]
|
[app.main.data.workspace.groups :as dwg]
|
||||||
[app.main.data.workspace.media :as dwm]
|
[app.main.data.workspace.media :as dwm]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -124,6 +125,26 @@
|
||||||
[_]
|
[_]
|
||||||
(create-shape :rect))
|
(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
|
(createText
|
||||||
[_ text]
|
[_ text]
|
||||||
(let [file-id (:current-file-id @st/state)
|
(let [file-id (:current-file-id @st/state)
|
||||||
|
@ -147,7 +168,18 @@
|
||||||
file-id (:current-file-id @st/state)
|
file-id (:current-file-id @st/state)
|
||||||
page-id (:current-page-id @st/state)]
|
page-id (:current-page-id @st/state)]
|
||||||
(st/emit! (dwm/create-svg-shape id "svg" svg-string (gpt/point 0 0)))
|
(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
|
(defn create-context
|
||||||
[]
|
[]
|
||||||
|
|
Loading…
Add table
Reference in a new issue