mirror of
https://github.com/penpot/penpot.git
synced 2025-03-23 05:01:23 -05:00
Merge pull request #5617 from penpot/alotor-hotfix-plugins
🐛 Fix problem in plugins with `replaceColor` method
This commit is contained in:
commit
1221d60357
5 changed files with 38 additions and 25 deletions
|
@ -5,6 +5,7 @@
|
|||
### :bug: Bugs fixed
|
||||
|
||||
- Fix detach when top copy is dangling and nested copy is not [Taiga #9699](https://tree.taiga.io/project/penpot/issue/9699)
|
||||
- Fix problem in plugins with `replaceColor` method [#174](https://github.com/penpot/penpot-plugins/issues/174)
|
||||
|
||||
## 2.4.1
|
||||
|
||||
|
|
|
@ -166,8 +166,8 @@
|
|||
|
||||
:replaceColor
|
||||
(fn [shapes old-color new-color]
|
||||
(let [old-color (parser/parse-color old-color)
|
||||
new-color (parser/parse-color new-color)]
|
||||
(let [old-color (parser/parse-color-data old-color)
|
||||
new-color (parser/parse-color-data new-color)]
|
||||
(cond
|
||||
(or (not (array? shapes)) (not (every? shape/shape-proxy? shapes)))
|
||||
(u/display-not-valid :replaceColor-shapes shapes)
|
||||
|
@ -190,7 +190,9 @@
|
|||
shapes-by-color
|
||||
(->> (ctc/extract-all-colors shapes file-id shared-libs)
|
||||
(group-by :attrs))]
|
||||
(st/emit! (dwc/change-color-in-selected new-color (get shapes-by-color old-color) old-color))))))
|
||||
|
||||
(when-let [operations (get shapes-by-color old-color)]
|
||||
(st/emit! (dwc/change-color-in-selected operations new-color old-color)))))))
|
||||
|
||||
:getRoot
|
||||
(fn []
|
||||
|
|
|
@ -128,18 +128,19 @@
|
|||
;; image?: ImageData;
|
||||
;; }
|
||||
(defn format-color
|
||||
[{:keys [id name path color opacity ref-id ref-file gradient image] :as color-data}]
|
||||
[{:keys [id file-id name path color opacity ref-id ref-file gradient image] :as color-data}]
|
||||
(when (some? color-data)
|
||||
(obj/without-empty
|
||||
#js {:id (format-id id)
|
||||
:name name
|
||||
:path path
|
||||
:color color
|
||||
:opacity opacity
|
||||
:refId (format-id ref-id)
|
||||
:refFile (format-id ref-file)
|
||||
:gradient (format-gradient gradient)
|
||||
:image (format-image image)})))
|
||||
(let [id (or (format-id id) (format-id ref-id))
|
||||
file-id (or (format-id file-id) (format-id ref-file))]
|
||||
(obj/without-empty
|
||||
#js {:id (or (format-id id) (format-id ref-id))
|
||||
:fileId (or (format-id file-id) (format-id ref-file))
|
||||
:name name
|
||||
:path path
|
||||
:color color
|
||||
:opacity opacity
|
||||
:gradient (format-gradient gradient)
|
||||
:image (format-image image)}))))
|
||||
|
||||
;; Color & ColorShapeInfo
|
||||
(defn format-color-result
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
:$file {:enumerable false :get (constantly file-id)}
|
||||
|
||||
:id {:get (fn [] (dm/str id))}
|
||||
:fileId {:get #(dm/str file-id)}
|
||||
|
||||
:name
|
||||
{:this true
|
||||
|
|
|
@ -111,28 +111,36 @@
|
|||
|
||||
;; export interface Color {
|
||||
;; id?: string;
|
||||
;; fileId?: string;
|
||||
;; refId?: string; // deprecated
|
||||
;; refFile?: string; // deprecated
|
||||
;; name?: string;
|
||||
;; path?: string;
|
||||
;; color?: string;
|
||||
;; opacity?: number;
|
||||
;; refId?: string;
|
||||
;; refFile?: string;
|
||||
;; gradient?: Gradient;
|
||||
;; image?: ImageData;
|
||||
;; }
|
||||
(defn parse-color-data
|
||||
[^js color]
|
||||
(when (some? color)
|
||||
(let [id (or (obj/get color "id") (obj/get color "refId"))
|
||||
file-id (or (obj/get color "fileId") (obj/get color "refFile"))]
|
||||
(d/without-nils
|
||||
{:id (parse-id id)
|
||||
:file-id (parse-id file-id)
|
||||
:color (-> (obj/get color "color") parse-hex)
|
||||
:opacity (obj/get color "opacity")
|
||||
:gradient (-> (obj/get color "gradient") parse-gradient)
|
||||
:image (-> (obj/get color "image") parse-image-data)}))))
|
||||
|
||||
(defn parse-color
|
||||
[^js color]
|
||||
(when (some? color)
|
||||
(d/without-nils
|
||||
{:id (-> (obj/get color "id") parse-id)
|
||||
:name (obj/get color "name")
|
||||
:path (obj/get color "path")
|
||||
:color (-> (obj/get color "color") parse-hex)
|
||||
:opacity (obj/get color "opacity")
|
||||
:ref-id (-> (obj/get color "refId") parse-id)
|
||||
:ref-file (-> (obj/get color "refFile") parse-id)
|
||||
:gradient (-> (obj/get color "gradient") parse-gradient)
|
||||
:image (-> (obj/get color "image") parse-image-data)})))
|
||||
(-> (parse-color-data color)
|
||||
(assoc :name (obj/get color "name")
|
||||
:path (obj/get color "path"))))))
|
||||
|
||||
;; export interface Shadow {
|
||||
;; id?: string;
|
||||
|
|
Loading…
Add table
Reference in a new issue