mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 18:18:24 +02:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
3bb5db6490
24 changed files with 554 additions and 129 deletions
|
@ -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`."
|
||||
|
|
|
@ -269,6 +269,13 @@
|
|||
(keep (mk-check-auto-layout objects))
|
||||
shapes)))
|
||||
|
||||
(defn full-tree?
|
||||
"Checks if we need to calculate the full tree or we can calculate just a partial tree. Partial
|
||||
trees are more efficient but cannot be done when the layout is centered."
|
||||
[objects layout-id]
|
||||
(let [layout-justify-content (get-in objects [layout-id :layout-justify-content])]
|
||||
(contains? #{:center :end :space-around :space-evenly :stretch} layout-justify-content)))
|
||||
|
||||
(defn sizing-auto-modifiers
|
||||
"Recalculates the layouts to adjust the sizing: auto new sizes"
|
||||
[modif-tree sizing-auto-layouts objects bounds ignore-constraints]
|
||||
|
@ -286,7 +293,7 @@
|
|||
(d/seek sizing-auto-layouts))
|
||||
|
||||
shapes
|
||||
(if from-layout
|
||||
(if (and from-layout (not (full-tree? objects from-layout)))
|
||||
(cgst/resolve-subtree from-layout layout-id objects)
|
||||
(cgst/resolve-tree #{layout-id} objects))
|
||||
|
||||
|
|
|
@ -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))))))
|
Loading…
Add table
Add a link
Reference in a new issue