From 9a4c45c8a3023a82e5e772ecbcac71184f1b7b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 10 Jun 2024 16:19:29 +0200 Subject: [PATCH] :bug: Fix export touched attributes --- CHANGES.md | 2 + common/src/app/common/data.cljc | 1 - common/src/app/common/types/component.cljc | 27 ++++++++++-- .../types/types_component_test.cljc | 43 +++++++++++++++++++ frontend/src/app/main/ui/shapes/export.cljs | 7 ++- frontend/src/app/worker/import/parser.cljs | 18 +++++++- 6 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 common/test/common_tests/types/types_component_test.cljc diff --git a/CHANGES.md b/CHANGES.md index 09a21a091..4419c2575 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,8 @@ - Fix problem with flex layout fit to content not positioning correctly children [Taiga #7537](https://tree.taiga.io/project/penpot/issue/7537) - Fix black line is displaying after show main [Taiga #7653](https://tree.taiga.io/project/penpot/issue/7653) - Fix "Share prototypes" modal remains open [Taiga #7442](https://tree.taiga.io/project/penpot/issue/7442) +- Fix "Components visibility and opacity" [#4694](https://github.com/penpot/penpot/issues/4694) +- Fix "Attribute overrides in copies are not exported in zip file" [Taiga #8072](https://tree.taiga.io/project/penpot/issue/8072) ## 2.0.3 diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 736803631..645091fd0 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -224,7 +224,6 @@ [coll] (into [] (remove nil?) coll)) - (defn without-nils "Given a map, return a map removing key-value pairs when value is `nil`." diff --git a/common/src/app/common/types/component.cljc b/common/src/app/common/types/component.cljc index 95bf3016a..bcd6ef3b3 100644 --- a/common/src/app/common/types/component.cljc +++ b/common/src/app/common/types/component.cljc @@ -189,14 +189,20 @@ (when swap-slot (keyword (str "swap-slot-" swap-slot)))) +(defn swap-slot? + [group] + (str/starts-with? (name group) "swap-slot-")) + +(defn group->swap-slot + [group] + (uuid/uuid (subs (name group) 10))) + (defn get-swap-slot "If the shape has a :touched group in the form :swap-slot-, get the id." [shape] - (let [group (->> (:touched shape) - (map name) - (d/seek #(str/starts-with? % "swap-slot-")))] + (let [group (d/seek swap-slot? (:touched shape))] (when group - (uuid/uuid (subs group 10))))) + (group->swap-slot group)))) (defn match-swap-slot? [shape-main shape-inst] @@ -264,3 +270,16 @@ ;; Non instance, non copy. We allow (or (not (instance-head? shape)) (not (in-component-copy? parent)))))) + +(defn all-touched-groups + [] + (into #{} (vals sync-attrs))) + +(defn valid-touched-group? + [group] + (try + (or ((all-touched-groups) group) + (and (swap-slot? group) + (some? (group->swap-slot group)))) + (catch #?(:clj Throwable :cljs :default) _ + false))) \ No newline at end of file diff --git a/common/test/common_tests/types/types_component_test.cljc b/common/test/common_tests/types/types_component_test.cljc new file mode 100644 index 000000000..cff174329 --- /dev/null +++ b/common/test/common_tests/types/types_component_test.cljc @@ -0,0 +1,43 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC + +(ns common-tests.types.types-component-test + (:require + [app.common.test-helpers.ids-map :as thi] + [app.common.test-helpers.shapes :as ths] + [app.common.types.component :as ctk] + [clojure.test :as t])) + +(t/use-fixtures :each thi/test-fixture) + +(t/deftest test-valid-touched-group + (t/is (ctk/valid-touched-group? :name-group)) + (t/is (ctk/valid-touched-group? :geometry-group)) + (t/is (ctk/valid-touched-group? :swap-slot-9cc181fa-5eef-8084-8004-7bb2ab45fd1f)) + (t/is (not (ctk/valid-touched-group? :this-is-not-a-group))) + (t/is (not (ctk/valid-touched-group? :swap-slot-))) + (t/is (not (ctk/valid-touched-group? :swap-slot-xxxxxx))) + (t/is (not (ctk/valid-touched-group? :swap-slot-9cc181fa-5eef-8084-8004))) + (t/is (not (ctk/valid-touched-group? nil)))) + +(t/deftest test-get-swap-slot + (let [s1 (ths/sample-shape :s1) + s2 (ths/sample-shape :s2 :touched #{:visibility-group}) + s3 (ths/sample-shape :s3 :touched #{:swap-slot-9cc181fa-5eef-8084-8004-7bb2ab45fd1f}) + s4 (ths/sample-shape :s4 :touched #{:fill-group + :swap-slot-9cc181fa-5eef-8084-8004-7bb2ab45fd1f}) + s5 (ths/sample-shape :s5 :touched #{:swap-slot-9cc181fa-5eef-8084-8004-7bb2ab45fd1f + :content-group + :geometry-group}) + s6 (ths/sample-shape :s6 :touched #{:swap-slot-9cc181fa})] + (t/is (nil? (ctk/get-swap-slot s1))) + (t/is (nil? (ctk/get-swap-slot s2))) + (t/is (= (ctk/get-swap-slot s3) #uuid "9cc181fa-5eef-8084-8004-7bb2ab45fd1f")) + (t/is (= (ctk/get-swap-slot s4) #uuid "9cc181fa-5eef-8084-8004-7bb2ab45fd1f")) + (t/is (= (ctk/get-swap-slot s5) #uuid "9cc181fa-5eef-8084-8004-7bb2ab45fd1f")) + #?(:clj + (t/is (thrown-with-msg? IllegalArgumentException #"Invalid UUID string" + (ctk/get-swap-slot s6)))))) diff --git a/frontend/src/app/main/ui/shapes/export.cljs b/frontend/src/app/main/ui/shapes/export.cljs index 8ac2387e8..35895b777 100644 --- a/frontend/src/app/main/ui/shapes/export.cljs +++ b/frontend/src/app/main/ui/shapes/export.cljs @@ -50,6 +50,9 @@ (defn bool->str [val] (when (some? val) (str val))) +(defn touched->str [val] + (str/join " " (map str val))) + (defn add-factory [shape] (fn add! ([props attr] @@ -136,7 +139,6 @@ (cond-> bool? (add! :bool-type))))) - (defn add-library-refs [props shape] (let [add! (add-factory shape)] (-> props @@ -150,7 +152,8 @@ (add! :component-id) (add! :component-root) (add! :main-instance) - (add! :shape-ref)))) + (add! :shape-ref) + (add! :touched touched->str)))) (defn prefix-keys [m] (letfn [(prefix-entry [[k v]] diff --git a/frontend/src/app/worker/import/parser.cljs b/frontend/src/app/worker/import/parser.cljs index fab4075ca..5eda72daa 100644 --- a/frontend/src/app/worker/import/parser.cljs +++ b/frontend/src/app/worker/import/parser.cljs @@ -12,6 +12,7 @@ [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.svg.path :as svg.path] + [app.common.types.component :as ctk] [app.common.types.shape.interactions :as ctsi] [app.common.uuid :as uuid] [app.util.json :as json] @@ -129,6 +130,15 @@ (into {})) style-str)) +(defn parse-touched + "Transform a string of :touched-groups into a set" + [touched-str] + (let [touched (->> (str/split touched-str " ") + (map #(keyword (subs % 1))) + (filter ctk/valid-touched-group?) + (into #{}))] + touched)) + (defn add-attrs [m attrs] (reduce-kv @@ -424,7 +434,8 @@ component-file (get-meta node :component-file uuid/uuid) shape-ref (get-meta node :shape-ref uuid/uuid) component-root? (get-meta node :component-root str->bool) - main-instance? (get-meta node :main-instance str->bool)] + main-instance? (get-meta node :main-instance str->bool) + touched (get-meta node :touched parse-touched)] (cond-> props (some? stroke-color-ref-id) @@ -442,7 +453,10 @@ (assoc :main-instance main-instance?) (some? shape-ref) - (assoc :shape-ref shape-ref)))) + (assoc :shape-ref shape-ref) + + (seq touched) + (assoc :touched touched)))) (defn add-fill [props node svg-data]