mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 01:08:28 +02:00
Merge pull request #5605 from penpot/niwinz-enhancements-2
⚡ Add performance enhacements
This commit is contained in:
commit
013a8c95df
37 changed files with 547 additions and 485 deletions
|
@ -79,7 +79,6 @@
|
|||
[component new-component-id library-data]
|
||||
(let [components-v2 (dm/get-in library-data [:options :components-v2])]
|
||||
(if components-v2
|
||||
|
||||
(let [main-instance-page (ctf/get-component-page library-data component)
|
||||
main-instance-shape (ctf/get-component-root library-data component)
|
||||
delta (gpt/point (+ (:width main-instance-shape) 50) 0)
|
||||
|
@ -205,21 +204,23 @@
|
|||
(cond-> {}
|
||||
force-frame? (assoc :force-frame-id frame-id)))
|
||||
|
||||
first-shape (cond-> (first new-shapes)
|
||||
(not (nil? parent-id))
|
||||
(assoc :parent-id parent-id)
|
||||
(and (not (nil? parent)) (= :frame (:type parent)))
|
||||
(assoc :frame-id (:id parent))
|
||||
(and (not (nil? parent)) (not= :frame (:type parent)))
|
||||
(assoc :frame-id (:frame-id parent))
|
||||
(and (not (nil? parent)) (ctn/in-any-component? objects parent))
|
||||
(dissoc :component-root)
|
||||
(and (nil? parent) (not (nil? frame-id)))
|
||||
(assoc :frame-id frame-id))
|
||||
first-shape
|
||||
(cond-> (first new-shapes)
|
||||
(not (nil? parent-id))
|
||||
(assoc :parent-id parent-id)
|
||||
(and (not (nil? parent)) (= :frame (:type parent)))
|
||||
(assoc :frame-id (:id parent))
|
||||
(and (not (nil? parent)) (not= :frame (:type parent)))
|
||||
(assoc :frame-id (:frame-id parent))
|
||||
(and (not (nil? parent)) (ctn/in-any-component? objects parent))
|
||||
(dissoc :component-root)
|
||||
(and (nil? parent) (not (nil? frame-id)))
|
||||
(assoc :frame-id frame-id))
|
||||
|
||||
;; on copy/paste old id is used later to reorder the paster layers
|
||||
changes (cond-> (pcb/add-object changes first-shape {:ignore-touched true})
|
||||
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id)))
|
||||
changes
|
||||
(cond-> (pcb/add-object changes first-shape {:ignore-touched true})
|
||||
(some? old-id) (pcb/amend-last-change #(assoc % :old-id old-id)))
|
||||
|
||||
changes
|
||||
(if (ctl/grid-layout? objects (:parent-id first-shape))
|
||||
|
@ -240,9 +241,10 @@
|
|||
(pcb/reorder-grid-children [(:parent-id first-shape)])))
|
||||
changes)
|
||||
|
||||
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||
changes
|
||||
(rest new-shapes))]
|
||||
changes
|
||||
(reduce #(pcb/add-object %1 %2 {:ignore-touched true})
|
||||
changes
|
||||
(rest new-shapes))]
|
||||
|
||||
[new-shape changes])))
|
||||
|
||||
|
@ -1488,7 +1490,7 @@
|
|||
(defn- update-tokens
|
||||
"Token synchronization algorithm. Copy the applied tokens that have changed
|
||||
in the origin shape to the dest shape (applying or removing as necessary).
|
||||
|
||||
|
||||
Only the given token attributes are synced."
|
||||
[changes container dest-shape orig-shape token-attrs]
|
||||
(let [orig-tokens (get orig-shape :applied-tokens {})
|
||||
|
|
|
@ -115,6 +115,9 @@
|
|||
(sm/register! ::recent-color schema:recent-color)
|
||||
(sm/register! ::color-attrs schema:color-attrs)
|
||||
|
||||
(def valid-color?
|
||||
(sm/lazy-validator schema:color))
|
||||
|
||||
(def check-color!
|
||||
(sm/check-fn schema:color :hint "expected valid color struct"))
|
||||
|
||||
|
@ -143,7 +146,6 @@
|
|||
|
||||
;; --- fill
|
||||
|
||||
;; FIXME: revisit, this generates invalid colors
|
||||
(defn fill->shape-color
|
||||
[fill]
|
||||
(d/without-nils
|
||||
|
@ -154,16 +156,6 @@
|
|||
:ref-id (:fill-color-ref-id fill)
|
||||
:ref-file (:fill-color-ref-file fill)}))
|
||||
|
||||
(defn fill->color
|
||||
[fill]
|
||||
(d/without-nils
|
||||
{:color (:fill-color fill)
|
||||
:opacity (:fill-opacity fill)
|
||||
:gradient (:fill-color-gradient fill)
|
||||
:image (:fill-image fill)
|
||||
:id (:fill-color-ref-id fill)
|
||||
:file-id (:fill-color-ref-file fill)}))
|
||||
|
||||
(defn set-fill-color
|
||||
[shape position color opacity gradient image]
|
||||
(update-in shape [:fills position]
|
||||
|
|
|
@ -464,8 +464,8 @@
|
|||
Returns a list ((asset ((container shapes) (container shapes)...))...)"
|
||||
[file-data library-data asset-type]
|
||||
(let [assets-seq (case asset-type
|
||||
:component (ctkl/components-seq library-data)
|
||||
:color (ctcl/colors-seq library-data)
|
||||
:component (ctkl/components-seq library-data)
|
||||
:color (ctcl/colors-seq library-data)
|
||||
:typography (ctyl/typographies-seq library-data))
|
||||
|
||||
find-usages-in-container
|
||||
|
|
65
common/test/common_tests/helpers_test.cljc
Normal file
65
common/test/common_tests/helpers_test.cljc
Normal file
|
@ -0,0 +1,65 @@
|
|||
;; 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.helpers-test
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
[app.common.test-helpers.compositions :as tho]
|
||||
[app.common.test-helpers.files :as thf]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
(t/deftest create-file
|
||||
(let [f1 (thf/sample-file :file1)
|
||||
f2 (thf/sample-file :file2 :page-label :page1)
|
||||
f3 (thf/sample-file :file3 :name "testing file")
|
||||
f4 (-> (thf/sample-file :file4 :page-label :page2)
|
||||
(thf/add-sample-page :page3 :name "testing page")
|
||||
(ths/add-sample-shape :shape1))
|
||||
f5 (-> f4
|
||||
(ths/add-sample-shape :shape2)
|
||||
(thf/switch-to-page :page2)
|
||||
(ths/add-sample-shape :shape3 :name "testing shape" :width 100))
|
||||
s1 (ths/get-shape f4 :shape1)
|
||||
s2 (ths/get-shape f5 :shape2 :page-label :page3)
|
||||
s3 (ths/get-shape f5 :shape3)]
|
||||
|
||||
;; (thf/pprint-file f4)
|
||||
|
||||
(t/is (= (:name f1) "Test file"))
|
||||
(t/is (= (:name f3) "testing file"))
|
||||
(t/is (= (:id f2) (thi/id :file2)))
|
||||
(t/is (= (:id f4) (thi/id :file4)))
|
||||
(t/is (= (-> f4 :data :pages-index vals first :id) (thi/id :page2)))
|
||||
(t/is (= (-> f4 :data :pages-index vals first :name) "Page 1"))
|
||||
(t/is (= (-> f4 :data :pages-index vals second :id) (thi/id :page3)))
|
||||
(t/is (= (-> f4 :data :pages-index vals second :name) "testing page"))
|
||||
|
||||
(t/is (= (:id (thf/current-page f2)) (thi/id :page1)))
|
||||
(t/is (= (:id (thf/current-page f4)) (thi/id :page3)))
|
||||
(t/is (= (:id (thf/current-page f5)) (thi/id :page2)))
|
||||
|
||||
(t/is (= (:id s1) (thi/id :shape1)))
|
||||
(t/is (= (:name s1) "Rectangle"))
|
||||
(t/is (= (:id s2) (thi/id :shape2)))
|
||||
(t/is (= (:name s2) "Rectangle"))
|
||||
(t/is (= (:id s3) (thi/id :shape3)))
|
||||
(t/is (= (:name s3) "testing shape"))
|
||||
(t/is (= (:width s3) 100))
|
||||
(t/is (= (:width (:selrect s3)) 100))))
|
||||
|
||||
(t/deftest create-components
|
||||
(let [f1 (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root))]
|
||||
|
||||
#_(thf/dump-file f1)
|
||||
#_(thf/pprint-file f4)
|
||||
|
||||
(t/is (= (:name f1) "Test file"))))
|
|
@ -35,12 +35,12 @@
|
|||
[common-tests.svg-test]
|
||||
[common-tests.text-test]
|
||||
[common-tests.time-test]
|
||||
[common-tests.types-modifiers-test]
|
||||
[common-tests.types-shape-interactions-test]
|
||||
[common-tests.types.absorb-assets-test]
|
||||
[common-tests.types.components-test]
|
||||
[common-tests.types.modifiers-test]
|
||||
[common-tests.types.shape-decode-encode-test]
|
||||
[common-tests.types.shape-interactions-test]
|
||||
[common-tests.types.tokens-lib-test]
|
||||
[common-tests.types.types-component-test]
|
||||
[common-tests.types.types-libraries-test]
|
||||
[common-tests.uuid-test]))
|
||||
|
||||
#?(:cljs (enable-console-print!))
|
||||
|
@ -82,10 +82,10 @@
|
|||
'common-tests.svg-test
|
||||
'common-tests.text-test
|
||||
'common-tests.time-test
|
||||
'common-tests.types-modifiers-test
|
||||
'common-tests.types-shape-interactions-test
|
||||
'common-tests.types.modifiers-test
|
||||
'common-tests.types.shape-interactions-test
|
||||
'common-tests.types.shape-decode-encode-test
|
||||
'common-tests.types.tokens-lib-test
|
||||
'common-tests.types.types-component-test
|
||||
'common-tests.types.types-libraries-test
|
||||
'common-tests.types.components-test
|
||||
'common-tests.types.absorb-assets-test
|
||||
'common-tests.uuid-test))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.types.types-libraries-test
|
||||
(ns common-tests.types.absorb-assets-test
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.test-helpers.components :as thc]
|
||||
|
@ -23,55 +23,7 @@
|
|||
|
||||
(t/use-fixtures :each thi/test-fixture)
|
||||
|
||||
(t/deftest test-create-file
|
||||
(let [f1 (thf/sample-file :file1)
|
||||
f2 (thf/sample-file :file2 :page-label :page1)
|
||||
f3 (thf/sample-file :file3 :name "testing file")
|
||||
f4 (-> (thf/sample-file :file4 :page-label :page2)
|
||||
(thf/add-sample-page :page3 :name "testing page")
|
||||
(ths/add-sample-shape :shape1))
|
||||
f5 (-> f4
|
||||
(ths/add-sample-shape :shape2)
|
||||
(thf/switch-to-page :page2)
|
||||
(ths/add-sample-shape :shape3 :name "testing shape" :width 100))
|
||||
s1 (ths/get-shape f4 :shape1)
|
||||
s2 (ths/get-shape f5 :shape2 :page-label :page3)
|
||||
s3 (ths/get-shape f5 :shape3)]
|
||||
|
||||
;; (thf/pprint-file f4)
|
||||
|
||||
(t/is (= (:name f1) "Test file"))
|
||||
(t/is (= (:name f3) "testing file"))
|
||||
(t/is (= (:id f2) (thi/id :file2)))
|
||||
(t/is (= (:id f4) (thi/id :file4)))
|
||||
(t/is (= (-> f4 :data :pages-index vals first :id) (thi/id :page2)))
|
||||
(t/is (= (-> f4 :data :pages-index vals first :name) "Page 1"))
|
||||
(t/is (= (-> f4 :data :pages-index vals second :id) (thi/id :page3)))
|
||||
(t/is (= (-> f4 :data :pages-index vals second :name) "testing page"))
|
||||
|
||||
(t/is (= (:id (thf/current-page f2)) (thi/id :page1)))
|
||||
(t/is (= (:id (thf/current-page f4)) (thi/id :page3)))
|
||||
(t/is (= (:id (thf/current-page f5)) (thi/id :page2)))
|
||||
|
||||
(t/is (= (:id s1) (thi/id :shape1)))
|
||||
(t/is (= (:name s1) "Rectangle"))
|
||||
(t/is (= (:id s2) (thi/id :shape2)))
|
||||
(t/is (= (:name s2) "Rectangle"))
|
||||
(t/is (= (:id s3) (thi/id :shape3)))
|
||||
(t/is (= (:name s3) "testing shape"))
|
||||
(t/is (= (:width s3) 100))
|
||||
(t/is (= (:width (:selrect s3)) 100))))
|
||||
|
||||
(t/deftest test-create-components
|
||||
(let [f1 (-> (thf/sample-file :file1)
|
||||
(tho/add-simple-component-with-copy :component1 :main-root :main-child :copy-root))]
|
||||
|
||||
#_(thf/dump-file f1)
|
||||
#_(thf/pprint-file f4)
|
||||
|
||||
(t/is (= (:name f1) "Test file"))))
|
||||
|
||||
(t/deftest test-absorb-components
|
||||
(t/deftest absorb-components
|
||||
(let [;; Setup
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(tho/add-simple-component :component1 :main-root :rect1))
|
||||
|
@ -105,7 +57,7 @@
|
|||
(t/is (ctk/is-main-of? main-root' copy-root' true))
|
||||
(t/is (ctk/main-instance-of? (:id main-root') (:id (second pages')) component'))))
|
||||
|
||||
(t/deftest test-absorb-colors
|
||||
(t/deftest absorb-colors
|
||||
(let [;; Setup
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(ths/add-sample-library-color :color1 {:name "Test color"
|
||||
|
@ -142,7 +94,7 @@
|
|||
(t/is (= (:fill-color-ref-id fill') (thi/id :color1)))
|
||||
(t/is (= (:fill-color-ref-file fill') (:id file')))))
|
||||
|
||||
(t/deftest test-absorb-typographies
|
||||
(t/deftest absorb-typographies
|
||||
(let [;; Setup
|
||||
library (-> (thf/sample-file :library :is-shared true)
|
||||
(ths/add-sample-typography :typography1 {:name "Test typography"}))
|
|
@ -4,7 +4,7 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.types.types-component-test
|
||||
(ns common-tests.types.components-test
|
||||
(:require
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.shapes :as ths]
|
|
@ -4,14 +4,14 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.types-modifiers-test
|
||||
(ns common-tests.types.modifiers-test
|
||||
(:require
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[clojure.test :as t]))
|
||||
|
||||
(t/deftest test-modifiers->transform
|
||||
(t/deftest modifiers->transform
|
||||
(let [modifiers
|
||||
(-> (ctm/empty)
|
||||
(ctm/move (gpt/point 100 200))
|
|
@ -4,7 +4,7 @@
|
|||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns common-tests.types-shape-interactions-test
|
||||
(ns common-tests.types.shape-interactions-test
|
||||
(:require
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.geom.point :as gpt]
|
||||
|
@ -50,7 +50,6 @@
|
|||
(t/is (= :after-delay (:event-type new-interaction)))
|
||||
(t/is (= 300 (:delay new-interaction)))))))
|
||||
|
||||
|
||||
(t/deftest set-action-type
|
||||
(let [interaction ctsi/default-interaction]
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue