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