mirror of
https://github.com/penpot/penpot.git
synced 2025-05-22 01:46:10 +02:00
🐛 Fix problem when assigning color from palette or assets
This commit is contained in:
parent
2fef90e7eb
commit
09d0a9e3f8
4 changed files with 35 additions and 34 deletions
|
@ -39,6 +39,7 @@
|
||||||
- Fix manipulate duplicated project (delete, duplicate, rename, pin/unpin...) [Taiga #5027](https://tree.taiga.io/project/penpot/issue/5027)
|
- Fix manipulate duplicated project (delete, duplicate, rename, pin/unpin...) [Taiga #5027](https://tree.taiga.io/project/penpot/issue/5027)
|
||||||
- Fix deleted files appear in search results [Taiga #5002](https://tree.taiga.io/project/penpot/issue/5002)
|
- Fix deleted files appear in search results [Taiga #5002](https://tree.taiga.io/project/penpot/issue/5002)
|
||||||
- Fix problem with selected colors and texts [Taiga #5051](https://tree.taiga.io/project/penpot/issue/5051)
|
- Fix problem with selected colors and texts [Taiga #5051](https://tree.taiga.io/project/penpot/issue/5051)
|
||||||
|
- Fix problem when assigning color from palette or assets [Taiga #5050](https://tree.taiga.io/project/penpot/issue/5050)
|
||||||
|
|
||||||
### :heart: Community contributions by (Thank you!)
|
### :heart: Community contributions by (Thank you!)
|
||||||
- To @ondrejkonec: for contributing to the code with:
|
- To @ondrejkonec: for contributing to the code with:
|
||||||
|
|
|
@ -37,8 +37,10 @@
|
||||||
(= type :frame)))
|
(= type :frame)))
|
||||||
|
|
||||||
(defn group-shape?
|
(defn group-shape?
|
||||||
[{:keys [type]}]
|
([objects id]
|
||||||
(= type :group))
|
(group-shape? (get objects id)))
|
||||||
|
([{:keys [type]}]
|
||||||
|
(= type :group)))
|
||||||
|
|
||||||
(defn mask-shape?
|
(defn mask-shape?
|
||||||
[{:keys [type masked-group?]}]
|
[{:keys [type masked-group?]}]
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.colors :as colors]
|
[app.common.colors :as colors]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.main.broadcast :as mbc]
|
[app.main.broadcast :as mbc]
|
||||||
[app.main.data.modal :as md]
|
[app.main.data.modal :as md]
|
||||||
|
@ -81,6 +82,8 @@
|
||||||
text-ids (filter is-text? ids)
|
text-ids (filter is-text? ids)
|
||||||
shape-ids (remove is-text? ids)
|
shape-ids (remove is-text? ids)
|
||||||
|
|
||||||
|
undo-id (js/Symbol)
|
||||||
|
|
||||||
attrs
|
attrs
|
||||||
(cond-> {}
|
(cond-> {}
|
||||||
(contains? color :color)
|
(contains? color :color)
|
||||||
|
@ -104,8 +107,10 @@
|
||||||
transform-attrs #(transform % attrs)]
|
transform-attrs #(transform % attrs)]
|
||||||
|
|
||||||
(rx/concat
|
(rx/concat
|
||||||
|
(rx/of (dwu/start-undo-transaction undo-id))
|
||||||
(rx/from (map #(dwt/update-text-with-function % transform-attrs) text-ids))
|
(rx/from (map #(dwt/update-text-with-function % transform-attrs) text-ids))
|
||||||
(rx/of (dch/update-shapes shape-ids transform-attrs)))))
|
(rx/of (dch/update-shapes shape-ids transform-attrs))
|
||||||
|
(rx/of (dwu/commit-undo-transaction undo-id)))))
|
||||||
|
|
||||||
(defn swap-attrs [shape attr index new-index]
|
(defn swap-attrs [shape attr index new-index]
|
||||||
(let [first (get-in shape [attr index])
|
(let [first (get-in shape [attr index])
|
||||||
|
@ -366,23 +371,33 @@
|
||||||
(rx/of (dwu/commit-undo-transaction undo-id)))))))
|
(rx/of (dwu/commit-undo-transaction undo-id)))))))
|
||||||
|
|
||||||
(defn apply-color-from-palette
|
(defn apply-color-from-palette
|
||||||
[color is-alt?]
|
[color stroke?]
|
||||||
(ptk/reify ::apply-color-from-palette
|
(ptk/reify ::apply-color-from-palette
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [objects (wsh/lookup-page-objects state)
|
(let [objects (wsh/lookup-page-objects state)
|
||||||
selected (->> (wsh/lookup-selected state)
|
selected (->> (wsh/lookup-selected state)
|
||||||
(cph/clean-loops objects))
|
(cph/clean-loops objects))
|
||||||
selected-obj (keep (d/getf objects) selected)
|
|
||||||
select-shapes-for-color (fn [shape objects]
|
ids
|
||||||
(let [shapes (case (:type shape)
|
(loop [pending (seq selected)
|
||||||
:group (cph/get-children objects (:id shape))
|
result []]
|
||||||
[shape])]
|
(if (empty? pending)
|
||||||
(->> shapes
|
result
|
||||||
(remove cph/group-shape?)
|
(let [cur (first pending)
|
||||||
(map :id))))
|
;; We treat frames with no fill the same as groups
|
||||||
ids (mapcat #(select-shapes-for-color % objects) selected-obj)]
|
group? (or (cph/group-shape? objects cur)
|
||||||
(if is-alt?
|
(and (cph/frame-shape? objects cur)
|
||||||
|
(empty? (dm/get-in objects [cur :fills]))))
|
||||||
|
|
||||||
|
pending
|
||||||
|
(if group?
|
||||||
|
(concat pending (dm/get-in objects [cur :shapes]))
|
||||||
|
pending)
|
||||||
|
|
||||||
|
result (cond-> result (not group?) (conj cur))]
|
||||||
|
(recur (rest pending) result))))]
|
||||||
|
(if stroke?
|
||||||
(rx/of (change-stroke ids (merge uc/empty-color color) 0))
|
(rx/of (change-stroke ids (merge uc/empty-color color) 0))
|
||||||
(rx/of (change-fill ids (merge uc/empty-color color) 0)))))))
|
(rx/of (change-fill ids (merge uc/empty-color color) 0)))))))
|
||||||
|
|
||||||
|
|
|
@ -1150,25 +1150,9 @@
|
||||||
(:color color) (:color color)
|
(:color color) (:color color)
|
||||||
:else (:value color))
|
:else (:value color))
|
||||||
|
|
||||||
;; TODO: looks like the first argument is not necessary
|
|
||||||
;; TODO: this code should be out of this UI component
|
|
||||||
apply-color
|
apply-color
|
||||||
(fn [_ event]
|
(fn [event]
|
||||||
(let [objects (wsh/lookup-page-objects @st/state)
|
(st/emit! (dc/apply-color-from-palette (merge uc/empty-color color) (kbd/alt? event))))
|
||||||
selected (->> (wsh/lookup-selected @st/state)
|
|
||||||
(cph/clean-loops objects))
|
|
||||||
selected-obj (keep (d/getf objects) selected)
|
|
||||||
select-shapes-for-color (fn [shape objects]
|
|
||||||
(let [shapes (case (:type shape)
|
|
||||||
:group (cph/get-children objects (:id shape))
|
|
||||||
[shape])]
|
|
||||||
(->> shapes
|
|
||||||
(remove cph/group-shape?)
|
|
||||||
(map :id))))
|
|
||||||
ids (mapcat #(select-shapes-for-color % objects) selected-obj)]
|
|
||||||
(if (kbd/alt? event)
|
|
||||||
(st/emit! (dc/change-stroke ids (merge uc/empty-color color) 0))
|
|
||||||
(st/emit! (dc/change-fill ids (merge uc/empty-color color) 0)))))
|
|
||||||
|
|
||||||
rename-color
|
rename-color
|
||||||
(fn [name]
|
(fn [name]
|
||||||
|
@ -1277,8 +1261,7 @@
|
||||||
:selected (contains? selected-colors (:id color)))
|
:selected (contains? selected-colors (:id color)))
|
||||||
:on-context-menu on-context-menu
|
:on-context-menu on-context-menu
|
||||||
:on-click (when-not (:editing @state)
|
:on-click (when-not (:editing @state)
|
||||||
#(on-asset-click % (:id color)
|
#(on-asset-click % (:id color) apply-color))
|
||||||
(partial apply-color (:id color))))
|
|
||||||
:ref item-ref
|
:ref item-ref
|
||||||
:draggable (and (not workspace-read-only?) (not (:editing @state)))
|
:draggable (and (not workspace-read-only?) (not (:editing @state)))
|
||||||
:on-drag-start on-color-drag-start
|
:on-drag-start on-color-drag-start
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue