0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-14 07:51:35 -05:00

🐛 Fixes problems with multiple values in fill and stroke

This commit is contained in:
alonso.torres 2021-02-03 12:10:43 +01:00 committed by Hirunatan
parent e7d6a54907
commit 8fd8bc4537
5 changed files with 57 additions and 24 deletions

View file

@ -116,11 +116,21 @@
text-ids (filter is-text? ids)
shape-ids (filter (comp not is-text?) ids)
attrs {:fill-color (:color color)
:fill-color-ref-id (:id color)
:fill-color-ref-file (:file-id color)
:fill-color-gradient (:gradient color)
:fill-opacity (:opacity color)}
attrs (cond-> {}
(contains? color :color)
(assoc :fill-color (:color color))
(contains? color :id)
(assoc :fill-color-ref-id (:id color))
(contains? color :file-id)
(assoc :fill-color-ref-file (:file-id color))
(contains? color :gradient)
(assoc :fill-color-gradient (:gradient color))
(contains? color :opacity)
(assoc :fill-opacity (:opacity color)))
update-fn (fn [shape] (merge shape attrs))
editors (get-in state [:workspace-local :editors])
@ -138,19 +148,30 @@
(let [pid (:current-page-id state)
objects (get-in state [:workspace-data :pages-index pid :objects])
not-frame (fn [shape-id] (not= (get-in objects [shape-id :type]) :frame))
update-fn (fn [s]
(cond-> s
true
(assoc :stroke-color (:color color)
:stroke-opacity (:opacity color)
:stroke-color-gradient (:gradient color)
:stroke-color-ref-id (:id color)
:stroke-color-ref-file (:file-id color))
(= (:stroke-style s) :none)
(assoc :stroke-style :solid
:stroke-width 1
:stroke-opacity 1)))]
color-attrs (cond-> {}
(contains? color :color)
(assoc :stroke-color (:color color))
(contains? color :id)
(assoc :stroke-color-ref-id (:id color))
(contains? color :file-id)
(assoc :stroke-color-ref-file (:file-id color))
(contains? color :gradient)
(assoc :stroke-color-gradient (:gradient color))
(contains? color :opacity)
(assoc :stroke-opacity (:opacity color)))
update-fn (fn [shape]
(-> shape
(merge color-attrs)
(cond-> (= (:stroke-style s) :none)
(assoc :stroke-style :solid
:stroke-width 1
:stroke-opacity 1))))]
(rx/of (dwc/update-shapes ids update-fn))))))
(defn picker-for-selected-shape []

View file

@ -63,13 +63,18 @@
(mf/use-callback
(mf/deps ids)
(fn [color]
(st/emit! (dc/change-fill ids color))))
(let [remove-multiple (fn [[key value]] (not= value :multiple))
color (into {} (filter remove-multiple) color)]
(st/emit! (dc/change-fill ids color)))))
on-detach
(mf/use-callback
(mf/deps ids)
(fn []
(st/emit! (dc/change-fill ids (dissoc color :id :file-id)))))
(let [remove-multiple (fn [[key value]] (not= value :multiple))
color (-> (into {} (filter remove-multiple) color)
(assoc :id nil :file-id nil))]
(st/emit! (dc/change-fill ids color)))))
on-open-picker
(mf/use-callback

View file

@ -82,10 +82,13 @@
(dissoc :gradient)))))
change-opacity (fn [new-opacity]
(when on-change (on-change (assoc color :opacity new-opacity))))
(when on-change (on-change (assoc color
:opacity new-opacity
:id nil
:file-id nil))))
handle-pick-color (fn [color]
(when on-change (on-change color)))
(when on-change (on-change (merge {:id nil :file-id nil} color))))
handle-open (fn [] (when on-open (on-open)))
@ -133,7 +136,7 @@
(cond
;; Rendering a color with ID
(:id color)
(and (:id color) (not (uc/multiple? color)))
[:*
[:div.color-info
[:div.color-name (str (get-color-name color))]]

View file

@ -66,7 +66,9 @@
(mf/use-callback
(mf/deps ids)
(fn [color]
(st/emit! (dc/change-stroke ids color))))
(let [remove-multiple (fn [[key value]] (not= value :multiple))
color (into {} (filter remove-multiple) color)]
(st/emit! (dc/change-stroke ids color)))))
handle-detach
(mf/use-callback

View file

@ -109,10 +109,12 @@
:else "transparent")))
(defn multiple? [{:keys [value color gradient]}]
(defn multiple? [{:keys [id file-id value color gradient]}]
(or (= value :multiple)
(= color :multiple)
(= gradient :multiple)
(= id :multiple)
(= file-id :multiple)
(and gradient color)))
(defn parse-color [^string color-str]