mirror of
https://github.com/penpot/penpot.git
synced 2025-08-04 05:18:24 +02:00
♻️ Move generate-xx methods to logic module
This commit is contained in:
parent
7280dfd3f7
commit
0b4fbc184d
15 changed files with 769 additions and 756 deletions
|
@ -7,7 +7,7 @@
|
|||
(ns common-tests.logic.comp-remove-swap-slots-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.libraries-helpers :as cflh]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]
|
||||
|
@ -57,13 +57,13 @@
|
|||
blue1 (thf/get-shape file :blue1)
|
||||
|
||||
;; ============================== Action ==============================
|
||||
changes (cflh/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
uuid/zero ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
uuid/zero ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
;; ============================== Get =================================
|
||||
|
@ -84,13 +84,13 @@
|
|||
blue1 (thf/get-shape file :blue1)
|
||||
|
||||
;; ============================== Action ==============================
|
||||
changes (cflh/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
uuid/zero ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
uuid/zero ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
@ -115,13 +115,13 @@
|
|||
|
||||
|
||||
;; ============================== Action ==============================
|
||||
changes (cflh/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
(:id b2) ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
(:id b2) ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
;; ============================== Get =================================
|
||||
|
@ -144,13 +144,13 @@
|
|||
|
||||
|
||||
;; ============================== Action ==============================
|
||||
changes (cflh/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
(:id b2) ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
(:id b2) ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
@ -174,26 +174,26 @@
|
|||
|
||||
;; ============================== Action ==============================
|
||||
;; Move blue1 into yellow
|
||||
changes (cflh/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
(:id yellow) ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
(:id yellow) ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
page' (thf/current-page file')
|
||||
yellow' (thf/get-shape file' :frame-yellow)
|
||||
|
||||
;; Move yellow into root
|
||||
changes' (cflh/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page')
|
||||
#{(:parent-id yellow')} ;; parents
|
||||
uuid/zero ;; parent-id
|
||||
(:id page') ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id yellow')}) ;; ids
|
||||
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page')
|
||||
#{(:parent-id yellow')} ;; parents
|
||||
uuid/zero ;; parent-id
|
||||
(:id page') ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id yellow')}) ;; ids
|
||||
file'' (thf/apply-changes file' changes')
|
||||
|
||||
;; ============================== Get =================================
|
||||
|
@ -216,26 +216,26 @@
|
|||
|
||||
;; ============================== Action ==============================
|
||||
;; Move blue1 into yellow
|
||||
changes (cflh/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
(:id yellow) ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
(:id yellow) ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
page' (thf/current-page file')
|
||||
yellow' (thf/get-shape file' :frame-yellow)
|
||||
|
||||
;; Move yellow into root
|
||||
changes' (cflh/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id yellow')} ;; ids
|
||||
uuid/zero ;; frame-id
|
||||
(:id page') ;; page-id
|
||||
(:objects page') ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id yellow')} ;; ids
|
||||
uuid/zero ;; frame-id
|
||||
(:id page') ;; page-id
|
||||
(:objects page') ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
file'' (thf/apply-changes file' changes')
|
||||
|
||||
;; ============================== Get =================================
|
||||
|
@ -259,13 +259,13 @@
|
|||
|
||||
;; ============================== Action ==============================
|
||||
;; Move blue1 into yellow
|
||||
changes (cflh/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
(:id yellow) ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page)
|
||||
#{(:parent-id blue1)} ;; parents
|
||||
(:id yellow) ;; parent-id
|
||||
(:id page) ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id blue1)}) ;; ids
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
page' (thf/current-page file')
|
||||
|
@ -273,13 +273,13 @@
|
|||
b2' (thf/get-shape file' :frame-b2)
|
||||
|
||||
;; Move yellow into b2
|
||||
changes' (cflh/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page')
|
||||
#{(:parent-id yellow')} ;; parents
|
||||
(:id b2') ;; parent-id
|
||||
(:id page') ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id yellow')}) ;; ids
|
||||
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
|
||||
(:objects page')
|
||||
#{(:parent-id yellow')} ;; parents
|
||||
(:id b2') ;; parent-id
|
||||
(:id page') ;; page-id
|
||||
0 ;; to-index
|
||||
#{(:id yellow')}) ;; ids
|
||||
file'' (thf/apply-changes file' changes')
|
||||
|
||||
;; ============================== Get =================================
|
||||
|
@ -302,13 +302,13 @@
|
|||
|
||||
;; ============================== Action ==============================
|
||||
;; Move blue1 into yellow
|
||||
changes (cflh/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
(:id yellow) ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id blue1)} ;; ids
|
||||
(:id yellow) ;; frame-id
|
||||
(:id page) ;; page-id
|
||||
(:objects page) ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
page' (thf/current-page file')
|
||||
|
@ -316,13 +316,13 @@
|
|||
b2' (thf/get-shape file' :frame-b2)
|
||||
|
||||
;; Move yellow into b2
|
||||
changes' (cflh/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id yellow')} ;; ids
|
||||
(:id b2') ;; frame-id
|
||||
(:id page') ;; page-id
|
||||
(:objects page') ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
|
||||
#{(:id yellow')} ;; ids
|
||||
(:id b2') ;; frame-id
|
||||
(:id page') ;; page-id
|
||||
(:objects page') ;; objects
|
||||
0 ;; drop-index
|
||||
nil) ;; cell
|
||||
|
||||
file'' (thf/apply-changes file' changes')
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
(ns common-tests.logic.component-creation-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.libraries-helpers :as cflh]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.files :as thf]
|
||||
[common-tests.helpers.ids-map :as thi]))
|
||||
|
@ -24,14 +24,14 @@
|
|||
|
||||
;; Action
|
||||
[_ component-id changes]
|
||||
(cflh/generate-add-component (pcb/empty-changes)
|
||||
[shape1]
|
||||
(:objects page)
|
||||
(:id page)
|
||||
(:id file)
|
||||
true
|
||||
nil
|
||||
nil)
|
||||
(cll/generate-add-component (pcb/empty-changes)
|
||||
[shape1]
|
||||
(:objects page)
|
||||
(:id page)
|
||||
(:id file)
|
||||
true
|
||||
nil
|
||||
nil)
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
(ns common-tests.logic.components-touched-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.libraries-helpers :as cflh]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.compositions :as tho]
|
||||
[common-tests.helpers.files :as thf]
|
||||
|
@ -31,11 +32,11 @@
|
|||
update-fn (fn [shape]
|
||||
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada")))
|
||||
|
||||
changes (cflh/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy-root)
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||
(:shapes copy-root)
|
||||
update-fn
|
||||
(:objects page)
|
||||
{})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
@ -67,13 +68,13 @@
|
|||
;; Action
|
||||
;; IMPORTANT: as modifying copies structure is now forbidden, this action
|
||||
;; will not have any effect, and so the parent shape won't also be touched.
|
||||
changes (cflh/generate-relocate-shapes (pcb/empty-changes)
|
||||
(:objects page)
|
||||
#{(:parent-id copy-root)} ; parents
|
||||
(thi/id :copy-root) ; parent-id
|
||||
(:id page) ; page-id
|
||||
0 ; to-index
|
||||
#{(thi/id :free-shape)}) ; ids
|
||||
changes (cls/generate-relocate-shapes (pcb/empty-changes)
|
||||
(:objects page)
|
||||
#{(:parent-id copy-root)} ; parents
|
||||
(thi/id :copy-root) ; parent-id
|
||||
(:id page) ; page-id
|
||||
0 ; to-index
|
||||
#{(thi/id :free-shape)}) ; ids
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
@ -100,12 +101,12 @@
|
|||
;; IMPORTANT: as modifying copies structure is now forbidden, this action will not
|
||||
;; delete the child shape, but hide it (thus setting the visibility group).
|
||||
[_all-parents changes]
|
||||
(cflh/generate-delete-shapes (pcb/empty-changes)
|
||||
file
|
||||
page
|
||||
(:objects page)
|
||||
(set (:shapes copy-root))
|
||||
{:components-v2 true})
|
||||
(cls/generate-delete-shapes (pcb/empty-changes)
|
||||
file
|
||||
page
|
||||
(:objects page)
|
||||
(set (:shapes copy-root))
|
||||
{:components-v2 true})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
@ -133,13 +134,13 @@
|
|||
;; Action
|
||||
;; IMPORTANT: as modifying copies structure is now forbidden, this action
|
||||
;; will not have any effect, and so the parent shape won't also be touched.
|
||||
changes (cflh/generate-relocate-shapes (pcb/empty-changes)
|
||||
(:objects page)
|
||||
#{(:parent-id copy-child1)} ; parents
|
||||
(thi/id :copy-root) ; parent-id
|
||||
(:id page) ; page-id
|
||||
2 ; to-index
|
||||
#{(:id copy-child1)}) ; ids
|
||||
changes (cls/generate-relocate-shapes (pcb/empty-changes)
|
||||
(:objects page)
|
||||
#{(:parent-id copy-child1)} ; parents
|
||||
(thi/id :copy-root) ; parent-id
|
||||
(:id page) ; page-id
|
||||
2 ; to-index
|
||||
#{(:id copy-child1)}) ; ids
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
|
|
@ -7,11 +7,9 @@
|
|||
(ns common-tests.logic.swap-and-reset-test
|
||||
(:require
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.files.libraries-helpers :as cflh]
|
||||
[app.common.pprint :as pp]
|
||||
[app.common.logic.libraries :as cll]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.test :as t]
|
||||
[common-tests.helpers.compositions :as thc]
|
||||
[common-tests.helpers.files :as thf]
|
||||
|
@ -34,16 +32,16 @@
|
|||
|
||||
;; Action
|
||||
[new-shape all-parents changes]
|
||||
(cflh/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
component-1-copy-root
|
||||
(:data file)
|
||||
page
|
||||
{(:id file) file}
|
||||
(:id component-2)
|
||||
0
|
||||
nil
|
||||
{})
|
||||
(cll/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
component-1-copy-root
|
||||
(:data file)
|
||||
page
|
||||
{(:id file) file}
|
||||
(:id component-2)
|
||||
0
|
||||
nil
|
||||
{})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
|
@ -82,16 +80,16 @@
|
|||
|
||||
;; Action
|
||||
[new-shape all-parents changes]
|
||||
(cflh/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
copy
|
||||
(:data file)
|
||||
page
|
||||
libraries
|
||||
(:id component-2)
|
||||
0
|
||||
nil
|
||||
{})
|
||||
(cll/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
copy
|
||||
(:data file)
|
||||
page
|
||||
libraries
|
||||
(:id component-2)
|
||||
0
|
||||
nil
|
||||
{})
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
libraries' {(:id file') file'}
|
||||
|
@ -137,27 +135,27 @@
|
|||
|
||||
;; Action
|
||||
[new-shape all-parents changes-swap]
|
||||
(cflh/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
copy
|
||||
(:data file)
|
||||
page
|
||||
{(:id file) file}
|
||||
(:id component-2)
|
||||
0
|
||||
nil
|
||||
{})
|
||||
(cll/generate-component-swap (pcb/empty-changes)
|
||||
(:objects page)
|
||||
copy
|
||||
(:data file)
|
||||
page
|
||||
{(:id file) file}
|
||||
(:id component-2)
|
||||
0
|
||||
nil
|
||||
{})
|
||||
|
||||
file-swap (thf/apply-changes file changes-swap)
|
||||
page-swap (thf/current-page file-swap)
|
||||
|
||||
changes
|
||||
(cflh/generate-reset-component (pcb/empty-changes)
|
||||
file-swap
|
||||
{(:id file-swap) file-swap}
|
||||
page-swap
|
||||
(:id new-shape)
|
||||
true)
|
||||
(cll/generate-reset-component (pcb/empty-changes)
|
||||
file-swap
|
||||
{(:id file-swap) file-swap}
|
||||
page-swap
|
||||
(:id new-shape)
|
||||
true)
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
page' (thf/current-page file')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue