mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 15:21:18 -05:00
🐛 Fix export touched attributes
This commit is contained in:
parent
257dab4775
commit
9a4c45c8a3
6 changed files with 89 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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`."
|
||||
|
|
|
@ -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-<uuid>, 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)))
|
43
common/test/common_tests/types/types_component_test.cljc
Normal file
43
common/test/common_tests/types/types_component_test.cljc
Normal file
|
@ -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))))))
|
|
@ -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]]
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue