mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 12:59:12 -05:00
🔧 Refactor calculation of multi selection attributes
This commit is contained in:
parent
809d7ab7f4
commit
b9e3426532
4 changed files with 327 additions and 11 deletions
|
@ -36,7 +36,6 @@
|
|||
;; :rx nil
|
||||
;; :ry nil}
|
||||
;;
|
||||
|
||||
(defn get-attrs-multi
|
||||
([objs attrs]
|
||||
(get-attrs-multi objs attrs = identity))
|
||||
|
|
|
@ -65,3 +65,320 @@
|
|||
:constraints-v :constraints-group
|
||||
:fixed-scroll :constraints-group})
|
||||
|
||||
;; Attributes that may directly be edited by the user with forms
|
||||
(def editable-attrs
|
||||
{:frame #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:selrect
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fills
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
:hide-fill-on-export}
|
||||
|
||||
:group #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}
|
||||
|
||||
:rect #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fills
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
|
||||
:stroke-style
|
||||
:stroke-alignment
|
||||
:stroke-width
|
||||
:stroke-color
|
||||
:stroke-color-ref-id
|
||||
:stroke-color-ref-file
|
||||
:stroke-opacity
|
||||
:stroke-color-gradient
|
||||
:stroke-cap-start
|
||||
:stroke-cap-end
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}
|
||||
|
||||
:circle #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fills
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
|
||||
:stroke-style
|
||||
:stroke-alignment
|
||||
:stroke-width
|
||||
:stroke-color
|
||||
:stroke-color-ref-id
|
||||
:stroke-color-ref-file
|
||||
:stroke-opacity
|
||||
:stroke-color-gradient
|
||||
:stroke-cap-start
|
||||
:stroke-cap-end
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}
|
||||
|
||||
:path #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fills
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
|
||||
:stroke-style
|
||||
:stroke-alignment
|
||||
:stroke-width
|
||||
:stroke-color
|
||||
:stroke-color-ref-id
|
||||
:stroke-color-ref-file
|
||||
:stroke-opacity
|
||||
:stroke-color-gradient
|
||||
:stroke-cap-start
|
||||
:stroke-cap-end
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}
|
||||
|
||||
:text #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
|
||||
:shadow
|
||||
|
||||
:blur
|
||||
|
||||
:typography-ref-id
|
||||
:typography-ref-file
|
||||
|
||||
:font-id
|
||||
:font-family
|
||||
:font-variant-id
|
||||
:font-size
|
||||
:font-weight
|
||||
:font-style
|
||||
|
||||
:text-align
|
||||
|
||||
:text-direction
|
||||
|
||||
:line-height
|
||||
:letter-spacing
|
||||
|
||||
:vertical-align
|
||||
|
||||
:text-decoration
|
||||
|
||||
:text-transform
|
||||
|
||||
:grow-type}
|
||||
|
||||
:image #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}
|
||||
|
||||
:svg-raw #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fills
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
|
||||
:stroke-style
|
||||
:stroke-alignment
|
||||
:stroke-width
|
||||
:stroke-color
|
||||
:stroke-color-ref-id
|
||||
:stroke-color-ref-file
|
||||
:stroke-opacity
|
||||
:stroke-color-gradient
|
||||
:stroke-cap-start
|
||||
:stroke-cap-end
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}
|
||||
|
||||
:bool #{:proportion-lock
|
||||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
:constraints-v
|
||||
:fixed-scroll
|
||||
:parent-id
|
||||
:frame-id
|
||||
|
||||
:opacity
|
||||
:blend-mode
|
||||
:blocked
|
||||
:hidden
|
||||
|
||||
:fill-color
|
||||
:fill-opacity
|
||||
:fill-color-ref-id
|
||||
:fill-color-ref-file
|
||||
:fill-color-gradient
|
||||
|
||||
:stroke-style
|
||||
:stroke-alignment
|
||||
:stroke-width
|
||||
:stroke-color
|
||||
:stroke-color-ref-id
|
||||
:stroke-color-ref-file
|
||||
:stroke-opacity
|
||||
:stroke-color-gradient
|
||||
:stroke-cap-start
|
||||
:stroke-cap-end
|
||||
|
||||
:shadow
|
||||
|
||||
:blur}})
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
:file-id (:fill-color-ref-file values)
|
||||
:gradient (:fill-color-gradient values)}
|
||||
|
||||
hide-fill-on-export? (:hide-fill-on-export values false)
|
||||
hide-fill-on-export? (:hide-fill-on-export values)
|
||||
|
||||
checkbox-ref (mf/use-ref)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
(:require
|
||||
[app.common.attrs :as attrs]
|
||||
[app.common.data :as d]
|
||||
[app.common.pages.common :as cpc]
|
||||
[app.common.text :as txt]
|
||||
[app.main.ui.hooks :as hooks]
|
||||
[app.main.ui.workspace.sidebar.options.menus.blur :refer [blur-attrs blur-menu]]
|
||||
|
@ -20,8 +21,11 @@
|
|||
[app.main.ui.workspace.sidebar.options.menus.text :as ot]
|
||||
[rumext.alpha :as mf]))
|
||||
|
||||
;; We define a map that goes from type to
|
||||
;; attribute and how to handle them
|
||||
;; Define how to read each kind of attribute depending on the shape type:
|
||||
;; - shape: read the attribute directly from the shape.
|
||||
;; - children: read it from all the children, and then merging it.
|
||||
;; - ignore: do not read this attribute from this shape.
|
||||
;; - text: read it from all the content nodes, and then merging it.
|
||||
(def type->props
|
||||
{:frame
|
||||
{:measure :shape
|
||||
|
@ -151,9 +155,6 @@
|
|||
[v]
|
||||
(when v (select-keys v blur-keys)))
|
||||
|
||||
(defn empty-map [keys]
|
||||
(into {} (map #(hash-map % nil)) keys))
|
||||
|
||||
(defn get-attrs*
|
||||
"Given a `type` of options that we want to extract and the shapes to extract them from
|
||||
returns a list of tuples [id, values] with the extracted properties for the shapes that
|
||||
|
@ -172,10 +173,9 @@
|
|||
(let [props (get-in type->props [type attr-type])]
|
||||
(case props
|
||||
:ignore [ids values]
|
||||
:shape [(conj ids id)
|
||||
(merge-attrs values (merge
|
||||
(empty-map attrs)
|
||||
(select-keys shape attrs)))]
|
||||
:shape (let [editable-attrs (filter (get cpc/editable-attrs (:type shape)) attrs)]
|
||||
[(conj ids id)
|
||||
(merge-attrs values (select-keys shape editable-attrs))])
|
||||
:text [(conj ids id)
|
||||
(-> values
|
||||
(merge-attrs (select-keys shape attrs))
|
||||
|
|
Loading…
Add table
Reference in a new issue