mirror of
https://github.com/penpot/penpot.git
synced 2025-06-21 23:56:58 +02:00
♻️ Move update-bool from common geom to types path
This commit is contained in:
parent
d8913ab18b
commit
03e4ca12be
8 changed files with 46 additions and 35 deletions
|
@ -19,6 +19,7 @@
|
||||||
[app.common.types.color :as types.color]
|
[app.common.types.color :as types.color]
|
||||||
[app.common.types.file :as types.file]
|
[app.common.types.file :as types.file]
|
||||||
[app.common.types.page :as types.page]
|
[app.common.types.page :as types.page]
|
||||||
|
[app.common.types.path :as types.path]
|
||||||
[app.common.types.shape :as types.shape]
|
[app.common.types.shape :as types.shape]
|
||||||
[app.common.types.typography :as types.typography]
|
[app.common.types.typography :as types.typography]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
@ -346,7 +347,7 @@
|
||||||
(let [objects (get-current-objects state)
|
(let [objects (get-current-objects state)
|
||||||
bool (-> group
|
bool (-> group
|
||||||
(assoc :type :bool)
|
(assoc :type :bool)
|
||||||
(gsh/update-bool objects))
|
(types.path/update-bool-shape objects))
|
||||||
change {:type :mod-obj
|
change {:type :mod-obj
|
||||||
:id (:id bool)
|
:id (:id bool)
|
||||||
:operations
|
:operations
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
[app.common.types.grid :as ctg]
|
[app.common.types.grid :as ctg]
|
||||||
[app.common.types.page :as ctp]
|
[app.common.types.page :as ctp]
|
||||||
[app.common.types.pages-list :as ctpl]
|
[app.common.types.pages-list :as ctpl]
|
||||||
|
[app.common.types.path :as path]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.types.tokens-lib :as ctob]
|
[app.common.types.tokens-lib :as ctob]
|
||||||
|
@ -744,7 +745,7 @@
|
||||||
group
|
group
|
||||||
|
|
||||||
(= :bool (:type group))
|
(= :bool (:type group))
|
||||||
(gsh/update-bool group objects)
|
(path/update-bool-shape group objects)
|
||||||
|
|
||||||
(:masked-group group)
|
(:masked-group group)
|
||||||
(->> (map lookup children)
|
(->> (map lookup children)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.file :as ctf]
|
[app.common.types.file :as ctf]
|
||||||
|
[app.common.types.path :as path]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.common.types.tokens-lib :as ctob]
|
[app.common.types.tokens-lib :as ctob]
|
||||||
[app.common.uuid :as uuid]))
|
[app.common.uuid :as uuid]))
|
||||||
|
@ -685,10 +686,10 @@
|
||||||
(empty? children) ;; a parent with no children will be deleted,
|
(empty? children) ;; a parent with no children will be deleted,
|
||||||
nil ;; so it does not need resize
|
nil ;; so it does not need resize
|
||||||
|
|
||||||
(= (:type parent) :bool)
|
(cfh/bool-shape? parent)
|
||||||
(gsh/update-bool parent objects)
|
(path/update-bool-shape parent objects)
|
||||||
|
|
||||||
(= (:type parent) :group)
|
(cfh/group-shape? parent)
|
||||||
;; FIXME: this functions should be
|
;; FIXME: this functions should be
|
||||||
;; normalized in the same way as
|
;; normalized in the same way as
|
||||||
;; update-bool in order to make all
|
;; update-bool in order to make all
|
||||||
|
@ -1174,4 +1175,4 @@
|
||||||
|
|
||||||
(update :undo-changes conj {:type :set-base-font-size
|
(update :undo-changes conj {:type :set-base-font-size
|
||||||
:base-font-size previous-font-size})
|
:base-font-size previous-font-size})
|
||||||
(apply-changes-local))))
|
(apply-changes-local))))
|
||||||
|
|
|
@ -164,7 +164,6 @@
|
||||||
(dm/export gtr/calculate-geometry)
|
(dm/export gtr/calculate-geometry)
|
||||||
(dm/export gtr/update-group-selrect)
|
(dm/export gtr/update-group-selrect)
|
||||||
(dm/export gtr/update-mask-selrect)
|
(dm/export gtr/update-mask-selrect)
|
||||||
(dm/export gtr/update-bool)
|
|
||||||
(dm/export gtr/apply-transform)
|
(dm/export gtr/apply-transform)
|
||||||
(dm/export gtr/transform-shape)
|
(dm/export gtr/transform-shape)
|
||||||
(dm/export gtr/transform-selrect)
|
(dm/export gtr/transform-selrect)
|
||||||
|
|
|
@ -456,13 +456,6 @@
|
||||||
(assoc :flip-x (-> mask :flip-x))
|
(assoc :flip-x (-> mask :flip-x))
|
||||||
(assoc :flip-y (-> mask :flip-y)))))
|
(assoc :flip-y (-> mask :flip-y)))))
|
||||||
|
|
||||||
(defn update-bool
|
|
||||||
"Calculates the selrect+points for the boolean shape"
|
|
||||||
[shape objects]
|
|
||||||
(let [content (path/calc-bool-content shape objects)
|
|
||||||
shape (assoc shape :content content)]
|
|
||||||
(path/update-geometry shape)))
|
|
||||||
|
|
||||||
;; FIXME: revisit
|
;; FIXME: revisit
|
||||||
(defn update-shapes-geometry
|
(defn update-shapes-geometry
|
||||||
[objects ids]
|
[objects ids]
|
||||||
|
@ -477,7 +470,7 @@
|
||||||
(update-mask-selrect shape children)
|
(update-mask-selrect shape children)
|
||||||
|
|
||||||
(cfh/bool-shape? shape)
|
(cfh/bool-shape? shape)
|
||||||
(update-bool shape objects)
|
(path/update-bool-shape shape objects)
|
||||||
|
|
||||||
(cfh/group-shape? shape)
|
(cfh/group-shape? shape)
|
||||||
(update-group-selrect shape children)
|
(update-group-selrect shape children)
|
||||||
|
|
|
@ -22,6 +22,14 @@
|
||||||
|
|
||||||
#?(:clj (set! *warn-on-reflection* true))
|
#?(:clj (set! *warn-on-reflection* true))
|
||||||
|
|
||||||
|
(def ^:cosnt bool-group-style-properties bool/group-style-properties)
|
||||||
|
(def ^:const bool-style-properties bool/style-properties)
|
||||||
|
(def ^:const default-bool-fills bool/default-fills)
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; TRANSFORMATIONS
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defn content?
|
(defn content?
|
||||||
[o]
|
[o]
|
||||||
(impl/path-data? o))
|
(impl/path-data? o))
|
||||||
|
@ -197,6 +205,13 @@
|
||||||
(-> (calc-bool-content* shape objects)
|
(-> (calc-bool-content* shape objects)
|
||||||
(impl/path-data)))
|
(impl/path-data)))
|
||||||
|
|
||||||
|
(defn update-bool-shape
|
||||||
|
"Calculates the selrect+points for the boolean shape"
|
||||||
|
[shape objects]
|
||||||
|
(let [content (calc-bool-content shape objects)
|
||||||
|
shape (assoc shape :content content)]
|
||||||
|
(update-geometry shape)))
|
||||||
|
|
||||||
(defn shape-with-open-path?
|
(defn shape-with-open-path?
|
||||||
[shape]
|
[shape]
|
||||||
(let [svg? (contains? shape :svg-attrs)
|
(let [svg? (contains? shape :svg-attrs)
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
(def default-fills
|
(def default-fills
|
||||||
[{:fill-color clr/black}])
|
[{:fill-color clr/black}])
|
||||||
|
|
||||||
(def style-group-properties
|
(def group-style-properties
|
||||||
[:shadow :blur])
|
[:shadow :blur])
|
||||||
|
|
||||||
(def style-properties
|
(def style-properties
|
||||||
(into style-group-properties
|
(into group-style-properties
|
||||||
[:fill-color
|
[:fill-color
|
||||||
:fill-opacity
|
:fill-opacity
|
||||||
:fill-color-gradient
|
:fill-color-gradient
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.types.component :as ctc]
|
[app.common.types.component :as ctc]
|
||||||
[app.common.types.container :as ctn]
|
[app.common.types.container :as ctn]
|
||||||
|
[app.common.types.path :as path]
|
||||||
[app.common.types.path.bool :as bool]
|
[app.common.types.path.bool :as bool]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
|
@ -35,7 +36,7 @@
|
||||||
head
|
head
|
||||||
(cond-> head
|
(cond-> head
|
||||||
(and (contains? head :svg-attrs) (empty? (:fills head)))
|
(and (contains? head :svg-attrs) (empty? (:fills head)))
|
||||||
(assoc :fills bool/default-fills))
|
(assoc :fills path/default-bool-fills))
|
||||||
|
|
||||||
shape
|
shape
|
||||||
{:id shape-id
|
{:id shape-id
|
||||||
|
@ -48,12 +49,26 @@
|
||||||
|
|
||||||
shape
|
shape
|
||||||
(-> shape
|
(-> shape
|
||||||
(merge (select-keys head bool/style-properties))
|
(merge (select-keys head path/bool-style-properties))
|
||||||
(cts/setup-shape)
|
(cts/setup-shape)
|
||||||
(gsh/update-bool objects))]
|
(path/update-bool-shape objects))]
|
||||||
|
|
||||||
[shape (cph/get-position-on-parent objects (:id head))]))
|
[shape (cph/get-position-on-parent objects (:id head))]))
|
||||||
|
|
||||||
|
(defn group->bool
|
||||||
|
[type group objects]
|
||||||
|
(let [shapes (->> (:shapes group)
|
||||||
|
(map (d/getf objects)))
|
||||||
|
head (if (= type :difference) (first shapes) (last shapes))
|
||||||
|
head (cond-> head
|
||||||
|
(and (contains? head :svg-attrs) (empty? (:fills head)))
|
||||||
|
(assoc :fills path/default-bool-fills))]
|
||||||
|
(-> group
|
||||||
|
(assoc :type :bool)
|
||||||
|
(assoc :bool-type type)
|
||||||
|
(merge (select-keys head bool/style-properties))
|
||||||
|
(path/update-bool-shape objects))))
|
||||||
|
|
||||||
(defn create-bool
|
(defn create-bool
|
||||||
[type & {:keys [ids force-shape-id]}]
|
[type & {:keys [ids force-shape-id]}]
|
||||||
|
|
||||||
|
@ -101,20 +116,6 @@
|
||||||
(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->bool
|
|
||||||
[type group objects]
|
|
||||||
(let [shapes (->> (:shapes group)
|
|
||||||
(map (d/getf objects)))
|
|
||||||
head (if (= type :difference) (first shapes) (last shapes))
|
|
||||||
head (cond-> head
|
|
||||||
(and (contains? head :svg-attrs) (empty? (:fills head)))
|
|
||||||
(assoc :fills bool/default-fills))]
|
|
||||||
(-> group
|
|
||||||
(assoc :type :bool)
|
|
||||||
(assoc :bool-type type)
|
|
||||||
(merge (select-keys head bool/style-properties))
|
|
||||||
(gsh/update-bool objects))))
|
|
||||||
|
|
||||||
(defn group-to-bool
|
(defn group-to-bool
|
||||||
[shape-id type]
|
[shape-id type]
|
||||||
(ptk/reify ::group-to-bool
|
(ptk/reify ::group-to-bool
|
||||||
|
@ -130,7 +131,7 @@
|
||||||
(-> shape
|
(-> shape
|
||||||
(assoc :type :group)
|
(assoc :type :group)
|
||||||
(dissoc :bool-type)
|
(dissoc :bool-type)
|
||||||
(d/without-keys bool/style-group-properties)
|
(d/without-keys path/bool-group-style-properties)
|
||||||
(gsh/update-group-selrect
|
(gsh/update-group-selrect
|
||||||
(mapv (d/getf objects)
|
(mapv (d/getf objects)
|
||||||
(:shapes shape)))))
|
(:shapes shape)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue