mirror of
https://github.com/penpot/penpot.git
synced 2025-03-26 06:31:26 -05:00
🐛 Fix multiple edition
This commit is contained in:
parent
43cbe2dd39
commit
a13fb1f94f
5 changed files with 54 additions and 29 deletions
|
@ -247,8 +247,6 @@
|
|||
:width :height
|
||||
:x :y
|
||||
:rotation
|
||||
:rx :ry
|
||||
:r1 :r2 :r3 :r4
|
||||
:selrect
|
||||
|
||||
:constraints-h
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
|
||||
(ns app.common.spec.radius
|
||||
(:require
|
||||
[app.common.spec :as us]
|
||||
[clojure.spec.alpha :as s]))
|
||||
[app.common.pages.common :refer [editable-attrs]]
|
||||
[app.common.spec :as us]
|
||||
[clojure.spec.alpha :as s]))
|
||||
|
||||
(s/def ::rx ::us/safe-number)
|
||||
(s/def ::ry ::us/safe-number)
|
||||
|
@ -30,6 +31,10 @@
|
|||
;; shapes that has border radius, and so it hasn't :rx nor :r1.
|
||||
;; In this case operations must leave shape untouched.
|
||||
|
||||
(defn has-radius?
|
||||
[shape]
|
||||
((get editable-attrs (:type shape)) :rx))
|
||||
|
||||
(defn radius-mode
|
||||
[shape]
|
||||
(if (:r1 shape)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages.common :as cpc]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
|
@ -145,7 +146,8 @@
|
|||
shapes (->> shapes
|
||||
(remove #(get % :blocked false))
|
||||
(mapcat #(cph/get-children objects (:id %)))
|
||||
(concat shapes))
|
||||
(concat shapes)
|
||||
(filter #((cpc/editable-attrs (:type %)) :rotation)))
|
||||
|
||||
update-shape
|
||||
(fn [modifiers shape]
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
(def ^:private type->options
|
||||
{:bool #{:size :position :rotation}
|
||||
:circle #{:size :position :rotation}
|
||||
:frame #{:size :position :rotation :radius :presets}
|
||||
:frame #{:presets :size :position :radius}
|
||||
:group #{:size :position :rotation}
|
||||
:image #{:size :position :rotation :radius}
|
||||
:path #{:size :position :rotation}
|
||||
|
@ -141,26 +141,36 @@
|
|||
(fn [value]
|
||||
(st/emit! (udw/increase-rotation ids value))))
|
||||
|
||||
change-radius
|
||||
(mf/use-callback
|
||||
(mf/deps ids-with-children)
|
||||
(fn [update-fn]
|
||||
(dch/update-shapes ids-with-children
|
||||
(fn [shape]
|
||||
(if (ctr/has-radius? shape)
|
||||
(update-fn shape)
|
||||
shape)))))
|
||||
|
||||
on-switch-to-radius-1
|
||||
(mf/use-callback
|
||||
(mf/deps ids)
|
||||
(fn [_value]
|
||||
(if all-equal?
|
||||
(st/emit! (dch/update-shapes ids-with-children ctr/switch-to-radius-1))
|
||||
(st/emit! (change-radius ctr/switch-to-radius-1))
|
||||
(reset! radius-multi? true))))
|
||||
|
||||
on-switch-to-radius-4
|
||||
(mf/use-callback
|
||||
(mf/deps ids)
|
||||
(fn [_value]
|
||||
(st/emit! (dch/update-shapes ids-with-children ctr/switch-to-radius-4))
|
||||
(st/emit! (change-radius ctr/switch-to-radius-4))
|
||||
(reset! radius-multi? false)))
|
||||
|
||||
on-radius-1-change
|
||||
(mf/use-callback
|
||||
(mf/deps ids)
|
||||
(fn [value]
|
||||
(st/emit! (dch/update-shapes ids-with-children #(ctr/set-radius-1 % value)))))
|
||||
(st/emit! (change-radius #(ctr/set-radius-1 % value)))))
|
||||
|
||||
on-radius-multi-change
|
||||
(mf/use-callback
|
||||
|
@ -168,16 +178,15 @@
|
|||
(fn [event]
|
||||
(let [value (-> event dom/get-target dom/get-value d/parse-integer)]
|
||||
(when (some? value)
|
||||
(st/emit! (dch/update-shapes ids-with-children ctr/switch-to-radius-1)
|
||||
(dch/update-shapes ids-with-children #(ctr/set-radius-1 % value)))
|
||||
(st/emit! (change-radius ctr/switch-to-radius-1)
|
||||
(change-radius #(ctr/set-radius-1 % value)))
|
||||
(reset! radius-multi? false)))))
|
||||
|
||||
on-radius-4-change
|
||||
(mf/use-callback
|
||||
(mf/deps ids)
|
||||
(fn [value attr]
|
||||
(st/emit! (dch/update-shapes ids-with-children #(ctr/set-radius-4 % attr value)))))
|
||||
|
||||
(st/emit! (change-radius #(ctr/set-radius-4 % attr value)))))
|
||||
|
||||
on-width-change #(on-size-change % :width)
|
||||
on-height-change #(on-size-change % :height)
|
||||
|
@ -273,7 +282,7 @@
|
|||
:precision 2}]]])
|
||||
|
||||
;; ROTATION
|
||||
(when (and (not= type :frame) (options :rotation))
|
||||
(when (options :rotation)
|
||||
[:div.row-flex
|
||||
[:span.element-set-subtitle (tr "workspace.options.rotation")]
|
||||
[:div.input-element.degrees {:title (tr "workspace.options.rotation")}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
;; - 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
|
||||
(def type->read-mode
|
||||
{:frame
|
||||
{:measure :shape
|
||||
:layer :shape
|
||||
|
@ -118,7 +118,7 @@
|
|||
:stroke :shape
|
||||
:text :ignore}})
|
||||
|
||||
(def props->attrs
|
||||
(def group->attrs
|
||||
{:measure measure-attrs
|
||||
:layer layer-attrs
|
||||
:constraint constraint-attrs
|
||||
|
@ -157,36 +157,47 @@
|
|||
(when v (select-keys v blur-keys)))
|
||||
|
||||
(defn get-attrs*
|
||||
"Given a `type` of options that we want to extract and the shapes to extract them from
|
||||
"Given a group of attributes 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
|
||||
applies (some of them ignore some attributes)"
|
||||
[shapes objects attr-type]
|
||||
(let [attrs (props->attrs attr-type)
|
||||
[shapes objects attr-group]
|
||||
(let [attrs (group->attrs attr-group)
|
||||
|
||||
merge-attrs
|
||||
(fn [v1 v2]
|
||||
(cond
|
||||
(= attr-type :shadow) (attrs/get-attrs-multi [v1 v2] attrs shadow-eq shadow-sel)
|
||||
(= attr-type :blur) (attrs/get-attrs-multi [v1 v2] attrs blur-eq blur-sel)
|
||||
:else (attrs/get-attrs-multi [v1 v2] attrs)))
|
||||
(= attr-group :shadow) (attrs/get-attrs-multi [v1 v2] attrs shadow-eq shadow-sel)
|
||||
(= attr-group :blur) (attrs/get-attrs-multi [v1 v2] attrs blur-eq blur-sel)
|
||||
:else (attrs/get-attrs-multi [v1 v2] attrs)))
|
||||
|
||||
extract-attrs
|
||||
(fn [[ids values] {:keys [id type content] :as shape}]
|
||||
(let [props (get-in type->props [type attr-type])]
|
||||
(case props
|
||||
(let [read-mode (get-in type->read-mode [type attr-group])
|
||||
editable-attrs (filter (get cpc/editable-attrs (:type shape)) attrs)]
|
||||
(case read-mode
|
||||
:ignore [ids values]
|
||||
:shape (let [editable-attrs (filter (get cpc/editable-attrs (:type shape)) attrs)]
|
||||
|
||||
:shape (let [;; Get the editable attrs from the shape, ensuring that all attributes
|
||||
;; are present, with value nil if they are not present in the shape.
|
||||
shape-values (merge
|
||||
(into {} (map #(hash-map % nil) editable-attrs))
|
||||
(select-keys shape editable-attrs))]
|
||||
[(conj ids id)
|
||||
(merge-attrs values (select-keys shape editable-attrs))])
|
||||
(merge-attrs values shape-values)])
|
||||
|
||||
:text [(conj ids id)
|
||||
(-> values
|
||||
(merge-attrs (select-keys shape attrs))
|
||||
(merge-attrs (merge
|
||||
(select-keys txt/default-text-attrs attrs)
|
||||
(attrs/get-attrs-multi (txt/node-seq content) attrs))))]
|
||||
(select-keys txt/default-text-attrs attrs)
|
||||
(attrs/get-attrs-multi (txt/node-seq content) attrs))))]
|
||||
|
||||
:children (let [children (->> (:shapes shape []) (map #(get objects %)))
|
||||
[new-ids new-values] (get-attrs* children objects attr-type)]
|
||||
[new-ids new-values] (get-attrs* children objects attr-group)]
|
||||
[(d/concat-vec ids new-ids) (merge-attrs values new-values)])
|
||||
|
||||
[])))]
|
||||
|
||||
(reduce extract-attrs [[] []] shapes)))
|
||||
|
||||
(def get-attrs (memoize get-attrs*))
|
||||
|
|
Loading…
Add table
Reference in a new issue