Compare commits

...
Author SHA1 Message Date
Andrés Moya 069995b62f more wip 2022-12-14 16:56:01 +01:00
Andrés Moya d145716e52 this not fine 2022-12-14 16:56:01 +01:00
Andrés Moya a4916b8add wip otro más 2022-12-14 16:56:01 +01:00
Andrés Moya 14ee85ccd7 temporary deactivation 2022-12-14 16:56:01 +01:00
Andrés Moya e8bf9d5f41 wip mejor 2022-12-14 16:56:01 +01:00
Andrés Moya 5f33f54cff 💄 Do some cleanup 2022-12-14 16:56:01 +01:00
Andrés Moya 7fbc47ccdb Avoid setting touched flags in copies 2022-12-14 16:56:01 +01:00
Andrés Moya 8ccd9bedfa wip del gueno 2022-12-14 16:56:01 +01:00
Andrés Moya a4e36390e2 wip fixes 2022-12-14 16:56:01 +01:00
Andrés Moya 4eaa9394f6 🎉 Show transient changes in component copies 2022-12-14 16:56:01 +01:00
Andrés Moya 9bf0c6e681 🐛 Avoid loops in main instance sync 2022-12-14 16:56:01 +01:00
19 changed files with 957 additions and 165 deletions

No files matched your search

+15
View File
@@ -58,6 +58,21 @@
[shape] [shape]
(or (:y shape) (:y (:selrect shape)))) ; Paths don't have :y attribute (or (:y shape) (:y (:selrect shape)))) ; Paths don't have :y attribute
(defn orig-pos
"Return the top left point of the shape wrapper BEFORE applying transformations."
[shape]
(gpt/point (left-bound shape) (top-bound shape)))
(defn width
"Return the width of the shape BEFORE transformations."
[shape]
(-> shape :selrect :width))
(defn height
"Return the height of the shape BEFORE transformations."
[shape]
(-> shape :selrect :height))
(defn fully-contained? (defn fully-contained?
"Checks if one rect is fully inside the other" "Checks if one rect is fully inside the other"
[rect other] [rect other]
+6 -5
View File
@@ -16,6 +16,7 @@
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.pages.changes-spec :as pcs] [app.common.pages.changes-spec :as pcs]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl] [app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.colors-list :as ctcl] [app.common.types.colors-list :as ctcl]
@@ -116,7 +117,7 @@
(cond-> parent (cond-> parent
(and (:shape-ref parent) (and (:shape-ref parent)
(not ignore-touched)) (not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group) (-> (update :touched ctk/set-touched-group :shapes-group)
(dissoc :remote-synced?))))) (dissoc :remote-synced?)))))
(delete-from-objects [objects] (delete-from-objects [objects]
@@ -221,7 +222,7 @@
(update :shapes d/vec-without-nils))] (update :shapes d/vec-without-nils))]
(cond-> parent (cond-> parent
(and (:shape-ref parent) (= (:type parent) :group) (not ignore-touched)) (and (:shape-ref parent) (= (:type parent) :group) (not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group) (-> (update :touched ctk/set-touched-group :shapes-group)
(dissoc :remote-synced?))))) (dissoc :remote-synced?)))))
(remove-from-old-parent [old-objects objects shape-id] (remove-from-old-parent [old-objects objects shape-id]
@@ -241,7 +242,7 @@
(d/update-in-when [pid :shapes] without-obj sid) (d/update-in-when [pid :shapes] without-obj sid)
(d/update-in-when [pid :shapes] d/vec-without-nils) (d/update-in-when [pid :shapes] d/vec-without-nils)
(cond-> component? (d/update-when pid #(-> % (cond-> component? (d/update-when pid #(-> %
(update :touched cph/set-touched-group :shapes-group) (update :touched ctk/set-touched-group :shapes-group)
(dissoc :remote-synced?))))))))) (dissoc :remote-synced?)))))))))
(update-parent-id [objects id] (update-parent-id [objects id]
@@ -416,7 +417,7 @@
(not root-name?) (not root-name?)
(not (and ignore-geometry is-geometry?))) (not (and ignore-geometry is-geometry?)))
(-> (->
(update :touched cph/set-touched-group group) (update :touched ctk/set-touched-group group)
(dissoc :remote-synced?)) (dissoc :remote-synced?))
(nil? val) (nil? val)
@@ -459,7 +460,7 @@
(defmulti components-changed (fn [_ change] (:type change))) (defmulti components-changed (fn [_ change] (:type change)))
(defmethod components-changed :mod-obj (defmethod components-changed :mod-obj
[file-data {:keys [id page-id _component-id operations]}] [file-data {:keys [id page-id operations]}]
(when page-id (when page-id
(let [page (ctpl/get-page file-data page-id) (let [page (ctpl/get-page file-data page-id)
shape-and-parents (map #(ctn/get-shape page %) shape-and-parents (map #(ctn/get-shape page %)
@@ -15,6 +15,7 @@
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.uuid :as uuid])) [app.common.uuid :as uuid]))
@@ -43,7 +44,7 @@
(defn with-container (defn with-container
[changes container] [changes container]
(if (cph/page? container) (if (ctn/page? container)
(vary-meta changes assoc ::page-id (:id container)) (vary-meta changes assoc ::page-id (:id container))
(vary-meta changes assoc ::component-id (:id container)))) (vary-meta changes assoc ::component-id (:id container))))
-65
View File
@@ -190,71 +190,6 @@
:else :else
(recur (get-in objects [current-id :parent-id]))))) (recur (get-in objects [current-id :parent-id])))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; COMPONENTS HELPERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn set-touched-group
[touched group]
(conj (or touched #{}) group))
(defn touched-group?
[shape group]
((or (:touched shape) #{}) group))
(defn get-component
"Retrieve a component from libraries, if no library-id is provided, we
iterate over all libraries and find the component on it."
([libraries component-id]
(some #(-> % :data :components (get component-id)) (vals libraries)))
([libraries library-id component-id]
(get-in libraries [library-id :data :components component-id])))
(defn get-component-shape
"Get the parent shape linked to a component for this shape, if any"
[objects shape]
(if-not (:shape-ref shape)
nil
(if (:component-id shape)
shape
(if-let [parent-id (:parent-id shape)]
(get-component-shape objects (get objects parent-id))
nil))))
(defn get-root-shape
"Get the root shape linked to a component for this shape, if any."
[objects shape]
(cond
(some? (:component-root? shape))
shape
(some? (:shape-ref shape))
(recur objects (get objects (:parent-id shape)))))
(defn make-container
[page-or-component type]
(assoc page-or-component :type type))
(defn page?
[container]
(= (:type container) :page))
(defn component?
[container]
(= (:type container) :component))
(defn get-container
[file type id]
(us/assert map? file)
(us/assert keyword? type)
(us/assert uuid? id)
(-> (if (= type :page)
(get-in file [:pages-index id])
(get-in file [:components id]))
(assoc :type type)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ALGORITHMS & TRANSFORMATIONS FOR SHAPES ;; ALGORITHMS & TRANSFORMATIONS FOR SHAPES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+29 -2
View File
@@ -7,10 +7,23 @@
(ns app.common.types.component) (ns app.common.types.component)
(defn instance-root? (defn instance-root?
"Check if the shape is the root of an instance or a subinstance."
[shape] [shape]
(some? (:component-id shape))) (some? (:component-id shape)))
(defn instance-tree-root?
"Check if the shape is the root of an instance that is no
subinstance of a higher one."
[shape]
(:component-root? shape))
(defn instance-shape?
"Check if the shape is part of any instance."
[shape]
(some? (:shape-ref shape)))
(defn instance-of? (defn instance-of?
"Check if the shape is the root of a near instance of the component."
[shape file-id component-id] [shape file-id component-id]
(and (some? (:component-id shape)) (and (some? (:component-id shape))
(some? (:component-file shape)) (some? (:component-file shape))
@@ -18,8 +31,10 @@
(= (:component-file shape) file-id))) (= (:component-file shape) file-id)))
(defn is-main-of? (defn is-main-of?
"Check if the first shape is the near main of the second one."
[shape-main shape-inst] [shape-main shape-inst]
(and (:shape-ref shape-inst) (and (not= (:id shape-main) (:id shape-inst))
(:shape-ref shape-inst)
(or (= (:shape-ref shape-inst) (:id shape-main)) (or (= (:shape-ref shape-inst) (:id shape-main))
(= (:shape-ref shape-inst) (:shape-ref shape-main))))) (= (:shape-ref shape-inst) (:shape-ref shape-main)))))
@@ -35,11 +50,13 @@
(= page-id (:main-instance-page component)))) (= page-id (:main-instance-page component))))
(defn get-component-root (defn get-component-root
"Get the root shape of the component."
[component] [component]
(get-in component [:objects (:id component)])) (get-in component [:objects (:id component)]))
(defn uses-library-components? (defn uses-library-components?
"Check if the shape uses any component in the given library." "Check if the shape is the root of an instance of any component in
the given library."
[shape library-id] [shape library-id]
(and (some? (:component-id shape)) (and (some? (:component-id shape))
(= (:component-file shape) library-id))) (= (:component-file shape) library-id)))
@@ -49,3 +66,13 @@
[shape] [shape]
(some? (:shape-ref shape))) (some? (:shape-ref shape)))
(defn set-touched-group
"Add a group to the touched flags."
[touched group]
(conj (or touched #{}) group))
(defn touched-group?
"Check if the touched flags contain the given group."
[shape group]
((or (:touched shape) #{}) group))
@@ -10,6 +10,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.component :as ctk]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))
@@ -61,6 +62,40 @@
[container shape-id f] [container shape-id f]
(update-in container [:objects shape-id] f)) (update-in container [:objects shape-id] f))
(defn get-component-shape
"Get the root shape of an instance, the one that is linked to the component.
If this is a subinstance, get the most direct root."
[objects shape]
(if-not (:shape-ref shape)
nil
(if (:component-id shape)
shape
(if-let [parent-id (:parent-id shape)]
(get-component-shape objects (get objects parent-id))
nil))))
(defn get-root-shape
"Get the topmost root shape of an instance, the one that is linked to the
component and without any container instance upwards."
[objects shape]
(cond
(some? (:component-root? shape))
shape
(some? (:shape-ref shape))
(recur objects (get objects (:parent-id shape)))))
(defn get-instances
"Get all shapes in the objects list that are near instances of the given one
---------------------------------------------------------------------------
TODO: Warning!!! this is a slow operation, since it needs to walk the whole
objects list. Perhaps there is a way of indexing this someway.
---------------------------------------------------------------------------"
[objects main-shape]
(filter #(ctk/is-main-of? main-shape %)
(vals objects)))
(defn make-component-shape (defn make-component-shape
"Clone the shape and all children. Generate new ids and detach "Clone the shape and all children. Generate new ids and detach
from parent and frame. Update the original shapes to have links from parent and frame. Update the original shapes to have links
+14 -1
View File
@@ -6,6 +6,7 @@
(ns app.common.types.file (ns app.common.types.file
(:require (:require
[app.common.pprint :refer [pprint]]
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.files.features :as ffeat] [app.common.files.features :as ffeat]
@@ -13,6 +14,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages.common :refer [file-version]] [app.common.pages.common :refer [file-version]]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.color :as ctc] [app.common.types.color :as ctc]
[app.common.types.colors-list :as ctcl] [app.common.types.colors-list :as ctcl]
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
@@ -99,6 +101,17 @@
(concat (map #(ctn/make-container % :page) (ctpl/pages-seq file-data)) (concat (map #(ctn/make-container % :page) (ctpl/pages-seq file-data))
(map #(ctn/make-container % :component) (ctkl/components-seq file-data)))) (map #(ctn/make-container % :component) (ctkl/components-seq file-data))))
(defn get-container
[file type id]
(us/assert map? file)
(us/assert :app.common.types.container/type type)
(us/assert uuid? id)
(-> (if (= type :page)
(get-in file [:pages-index id])
(get-in file [:components id]))
(assoc :type type)))
(defn update-container (defn update-container
"Update a container inside the file, it can be a page or a component" "Update a container inside the file, it can be a page or a component"
[file-data container f] [file-data container f]
@@ -500,7 +513,7 @@
(show-component [shape objects] (show-component [shape objects]
(if (nil? (:shape-ref shape)) (if (nil? (:shape-ref shape))
"" ""
(let [root-shape (cph/get-component-shape objects shape) (let [root-shape (ctn/get-component-shape objects shape)
component-id (when root-shape (:component-id root-shape)) component-id (when root-shape (:component-id root-shape))
component-file-id (when root-shape (:component-file root-shape)) component-file-id (when root-shape (:component-file root-shape))
component-file (when component-file-id (get libraries component-file-id nil)) component-file (when component-file-id (get libraries component-file-id nil))
+2 -1
View File
@@ -13,6 +13,7 @@
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.component :as ctk]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))
@@ -45,7 +46,7 @@
(cond-> (and (:shape-ref parent) (cond-> (and (:shape-ref parent)
(not= (:id parent) frame-id) (not= (:id parent) frame-id)
(not ignore-touched)) (not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group) (-> (update :touched ctk/set-touched-group :shapes-group)
(dissoc :remote-synced?))))) (dissoc :remote-synced?)))))
;; TODO: this looks wrong, why we allow nil values? ;; TODO: this looks wrong, why we allow nil values?
@@ -9,7 +9,8 @@
[clojure.test :as t] [clojure.test :as t]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.types.container :as ctn])) [app.common.types.container :as ctn]
[app.common.types.file :as ctf]))
;; ---- Helpers to manage libraries and synchronization ;; ---- Helpers to manage libraries and synchronization
@@ -81,7 +82,7 @@
[page root-inst-id libraries] [page root-inst-id libraries]
(let [root-inst (ctn/get-shape page root-inst-id) (let [root-inst (ctn/get-shape page root-inst-id)
component (cph/get-component libraries (:component-id root-inst)) component (ctf/get-component libraries (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id) shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst)) shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
@@ -90,10 +91,10 @@
main-exists? (fn [shape] main-exists? (fn [shape]
(let [component-shape (let [component-shape
(cph/get-component-shape (:objects page) shape) (ctn/get-component-shape (:objects page) shape)
component component
(cph/get-component libraries (:component-id component-shape)) (ctf/get-component libraries (:component-id component-shape))
main-shape main-shape
(ctn/get-shape component (:shape-ref shape))] (ctn/get-shape component (:shape-ref shape))]
@@ -117,7 +118,7 @@
[page root-inst-id libraries] [page root-inst-id libraries]
(let [root-inst (ctn/get-shape page root-inst-id) (let [root-inst (ctn/get-shape page root-inst-id)
component (cph/get-component libraries (:component-id root-inst)) component (ctf/get-component libraries (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id) shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst)) shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
@@ -126,10 +127,10 @@
main-exists? (fn [shape] main-exists? (fn [shape]
(let [component-shape (let [component-shape
(cph/get-component-shape (:objects page) shape) (ctn/get-component-shape (:objects page) shape)
component component
(cph/get-component libraries (:component-id component-shape)) (ctf/get-component libraries (:component-id component-shape))
main-shape main-shape
(ctn/get-shape component (:shape-ref shape))] (ctn/get-shape component (:shape-ref shape))]
@@ -144,7 +145,7 @@
(defn resolve-component (defn resolve-component
"Get the component with the given id and all its shapes." "Get the component with the given id and all its shapes."
[page component-id libraries] [page component-id libraries]
(let [component (cph/get-component libraries component-id) (let [component (ctf/get-component libraries component-id)
root-main (ctk/get-component-root component) root-main (ctk/get-component-root component)
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))] shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
+3 -3
View File
@@ -772,8 +772,8 @@
(not (:component-root? shape))) (not (:component-root? shape)))
parent (get objects parent-id) parent (get objects parent-id)
component-shape (cph/get-component-shape objects shape) component-shape (ctn/get-component-shape objects shape)
component-shape-parent (cph/get-component-shape objects parent) component-shape-parent (ctn/get-component-shape objects parent)
detach? (and instance-part? (not= (:id component-shape) detach? (and instance-part? (not= (:id component-shape)
(:id component-shape-parent))) (:id component-shape-parent)))
@@ -1510,7 +1510,7 @@
;; Check if the shape is an instance whose master is defined in a ;; Check if the shape is an instance whose master is defined in a
;; library that is not linked to the current file ;; library that is not linked to the current file
(foreign-instance? [shape paste-objects state] (foreign-instance? [shape paste-objects state]
(let [root (cph/get-root-shape paste-objects shape) (let [root (ctn/get-root-shape paste-objects shape)
root-file-id (:component-file root)] root-file-id (:component-file root)]
(and (some? root) (and (some? root)
(not= root-file-id (:current-file-id state)) (not= root-file-id (:current-file-id state))
@@ -37,7 +37,7 @@
(defn update-shapes (defn update-shapes
([ids update-fn] (update-shapes ids update-fn nil)) ([ids update-fn] (update-shapes ids update-fn nil))
([ids update-fn {:keys [reg-objects? save-undo? attrs ignore-tree page-id] ([ids update-fn {:keys [reg-objects? save-undo? attrs ignore-tree page-id ignore-touched-fn]
:or {reg-objects? false save-undo? true}}] :or {reg-objects? false save-undo? true}}]
(us/assert ::coll-of-uuid ids) (us/assert ::coll-of-uuid ids)
@@ -52,7 +52,10 @@
changes (reduce changes (reduce
(fn [changes id] (fn [changes id]
(let [opts {:attrs attrs :ignore-geometry? (get ignore-tree id)}] (let [opts {:attrs attrs
:ignore-geometry? (get ignore-tree id)
:ignore-touched (when ignore-touched-fn
(ignore-touched-fn id))}]
(pcb/update-shapes changes [id] update-fn opts))) (pcb/update-shapes changes [id] update-fn opts)))
(-> (pcb/empty-changes it page-id) (-> (pcb/empty-changes it page-id)
(pcb/set-save-undo? save-undo?) (pcb/set-save-undo? save-undo?)
@@ -372,7 +372,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [libraries (wsh/get-libraries state) (let [libraries (wsh/get-libraries state)
component (cph/get-component libraries id) component (ctf/get-component libraries id)
all-components (-> state :workspace-data :components vals) all-components (-> state :workspace-data :components vals)
unames (into #{} (map :name) all-components) unames (into #{} (map :name) all-components)
new-name (ctst/generate-unique-name unames (:name component)) new-name (ctst/generate-unique-name unames (:name component))
@@ -490,7 +490,7 @@
(watch [it state _] (watch [it state _]
(let [file (wsh/get-local-file state) (let [file (wsh/get-local-file state)
page-id (get state :current-page-id) page-id (get state :current-page-id)
container (cph/get-container file :page page-id) container (ctf/get-container file :page page-id)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-container container) (pcb/with-container container)
@@ -506,7 +506,7 @@
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
file (wsh/get-local-file state) file (wsh/get-local-file state)
container (cph/get-container file :page page-id) container (ctf/get-container file :page page-id)
selected (->> state selected (->> state
(wsh/lookup-selected) (wsh/lookup-selected)
(cph/clean-loops objects)) (cph/clean-loops objects))
@@ -563,7 +563,7 @@
libraries (wsh/get-libraries state) libraries (wsh/get-libraries state)
page-id (:current-page-id state) page-id (:current-page-id state)
container (cph/get-container file :page page-id) container (ctf/get-container file :page page-id)
components-v2 components-v2
(features/active-feature? state :components-v2) (features/active-feature? state :components-v2)
@@ -599,7 +599,7 @@
local-file (wsh/get-local-file state) local-file (wsh/get-local-file state)
libraries (wsh/get-libraries state) libraries (wsh/get-libraries state)
container (cph/get-container local-file :page page-id) container (ctf/get-container local-file :page page-id)
shape (ctn/get-shape container id) shape (ctn/get-shape container id)
changes changes
@@ -729,7 +729,13 @@
(when sync-typographies? (when sync-typographies?
(dwlh/generate-sync-file it file-id :typographies asset-id library-id state))]) (dwlh/generate-sync-file it file-id :typographies asset-id library-id state))])
changes (pcb/concat-changes library-changes file-changes)] changes (pcb/concat-changes library-changes file-changes)
changes (cond-> changes
; Store the origin component to avoid sync loops
(= asset-type :components)
(update :redo-changes
#(vary-meta % assoc :origin-component-id asset-id)))]
(log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes (log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes
(:redo-changes changes) (:redo-changes changes)
@@ -850,10 +856,26 @@
check-changes check-changes
(fn [[event data]] (fn [[event data]]
(let [{:keys [changes save-undo?]} (deref event) (let [page (wsh/lookup-page state)
{:keys [changes save-undo?]} (deref event)
components-changed (reduce #(into %1 (ch/components-changed data %2)) components-changed (reduce #(into %1 (ch/components-changed data %2))
#{} #{}
changes)] changes)
orig-component-id (get (meta changes) :origin-component-id)
is-orig (fn [shape-id]
(let [shape (ctn/get-shape page shape-id)]
(= (:component-id shape) orig-component-id)))
;; If the changes are derived of the synchronization of a main component,
;; ignore them to avoid entering loops.
components-changed (if orig-component-id
(set (remove is-orig components-changed))
components-changed)]
(when (and (d/not-empty? components-changed) save-undo?) (when (and (d/not-empty? components-changed) save-undo?)
(log/info :msg "DETECTED COMPONENTS CHANGED" (log/info :msg "DETECTED COMPONENTS CHANGED"
:ids (map str components-changed)) :ids (map str components-changed))
@@ -861,11 +883,12 @@
(map #(update-component-sync % (:id data)) (map #(update-component-sync % (:id data))
components-changed)))))] components-changed)))))]
(when components-v2 ;; (when components-v2
(->> change-s ;; (->> change-s
(rx/with-latest-from workspace-data-s) ;; (rx/with-latest-from workspace-data-s)
(rx/map check-changes) ;; (rx/map check-changes)
(rx/take-until stopper))))))) ;; (rx/take-until stopper)))
))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Backend interactions ;; Backend interactions
@@ -898,6 +921,7 @@
(let [state (dissoc state :files)] (let [state (dissoc state :files)]
(assoc state :workspace-shared-files files))))) (assoc state :workspace-shared-files files)))))
(defn fetch-shared-files (defn fetch-shared-files
[{:keys [team-id] :as params}] [{:keys [team-id] :as params}]
(us/assert ::us/uuid team-id) (us/assert ::us/uuid team-id)
@@ -127,7 +127,7 @@
(defn generate-instantiate-component (defn generate-instantiate-component
"Generate changes to create a new instance from a component." "Generate changes to create a new instance from a component."
[it file-id component-id position page libraries] [it file-id component-id position page libraries]
(let [component (cph/get-component libraries file-id component-id) (let [component (ctf/get-component libraries file-id component-id)
[new-shape new-shapes] [new-shape new-shapes]
(ctn/make-component-instance page component file-id position) (ctn/make-component-instance page component file-id position)
@@ -191,7 +191,7 @@
asset-id asset-id
library-id library-id
state state
(cph/make-container page :page) (ctn/make-container page :page)
components-v2))) components-v2)))
changes)))) changes))))
@@ -227,7 +227,7 @@
asset-id asset-id
library-id library-id
state state
(cph/make-container local-component :component) (ctn/make-container local-component :component)
components-v2))) components-v2)))
changes)))) changes))))
@@ -236,7 +236,7 @@
or a component) that use assets of the given type in the given library." or a component) that use assets of the given type in the given library."
[it asset-type asset-id library-id state container components-v2] [it asset-type asset-id library-id state container components-v2]
(if (cph/page? container) (if (ctn/page? container)
(log/debug :msg "Sync page in local file" :page-id (:id container)) (log/debug :msg "Sync page in local file" :page-id (:id container))
(log/debug :msg "Sync component in local library" :component-id (:id container))) (log/debug :msg "Sync component in local library" :component-id (:id container)))
@@ -451,7 +451,7 @@
[changes libraries container shape-id reset? components-v2] [changes libraries container shape-id reset? components-v2]
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?) (log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
(let [shape-inst (ctn/get-shape container shape-id) (let [shape-inst (ctn/get-shape container shape-id)
component (cph/get-component libraries component (ctf/get-component libraries
(:component-file shape-inst) (:component-file shape-inst)
(:component-id shape-inst)) (:component-id shape-inst))
component (or component component (or component
@@ -588,7 +588,7 @@
[changes libraries container shape-id] [changes libraries container shape-id]
(log/debug :msg "Sync shape inverse" :shape (str shape-id)) (log/debug :msg "Sync shape inverse" :shape (str shape-id))
(let [shape-inst (ctn/get-shape container shape-id) (let [shape-inst (ctn/get-shape container shape-id)
component (cph/get-component libraries component (ctf/get-component libraries
(:component-file shape-inst) (:component-file shape-inst)
(:component-id shape-inst)) (:component-id shape-inst))
shape-main (ctn/get-shape component (:shape-ref shape-inst)) shape-main (ctn/get-shape component (:shape-ref shape-inst))
@@ -618,7 +618,7 @@
(if (nil? shape-main) (if (nil? shape-main)
;; This should not occur, but protect against it in any case ;; This should not occur, but protect against it in any case
changes changes
(let [component-container (cph/make-container component :component) (let [component-container (ctn/make-container component :component)
omit-touched? false omit-touched? false
set-remote-synced? (not initial-root?) set-remote-synced? (not initial-root?)
@@ -825,7 +825,7 @@
:shapes all-parents})) :shapes all-parents}))
changes' (reduce del-obj-change changes' new-shapes)] changes' (reduce del-obj-change changes' new-shapes)]
(if (and (cph/touched-group? parent-shape :shapes-group) omit-touched?) (if (and (ctk/touched-group? parent-shape :shapes-group) omit-touched?)
changes changes
changes'))) changes')))
@@ -908,7 +908,7 @@
(defn- remove-shape (defn- remove-shape
[changes shape container omit-touched?] [changes shape container omit-touched?]
(log/info :msg (str "REMOVE-SHAPE " (log/info :msg (str "REMOVE-SHAPE "
(if (cph/page? container) "[P] " "[C] ") (if (ctn/page? container) "[P] " "[C] ")
(:name shape))) (:name shape)))
(let [objects (get container :objects) (let [objects (get container :objects)
parents (cph/get-parent-ids objects (:id shape)) parents (cph/get-parent-ids objects (:id shape))
@@ -946,14 +946,14 @@
changes' changes'
(map :id children))] (map :id children))]
(if (and (cph/touched-group? parent :shapes-group) omit-touched?) (if (and (ctk/touched-group? parent :shapes-group) omit-touched?)
changes changes
changes'))) changes')))
(defn- move-shape (defn- move-shape
[changes shape index-before index-after container omit-touched?] [changes shape index-before index-after container omit-touched?]
(log/info :msg (str "MOVE " (log/info :msg (str "MOVE "
(if (cph/page? container) "[P] " "[C] ") (if (ctn/page? container) "[P] " "[C] ")
(:name shape) (:name shape)
" " " "
index-before index-before
@@ -977,7 +977,7 @@
:index index-before :index index-before
:ignore-touched true})))] :ignore-touched true})))]
(if (and (cph/touched-group? parent :shapes-group) omit-touched?) (if (and (ctk/touched-group? parent :shapes-group) omit-touched?)
changes changes
changes'))) changes')))
@@ -989,7 +989,7 @@
changes changes
(do (do
(log/info :msg (str "CHANGE-TOUCHED " (log/info :msg (str "CHANGE-TOUCHED "
(if (cph/page? container) "[P] " "[C] ") (if (ctn/page? container) "[P] " "[C] ")
(:name dest-shape)) (:name dest-shape))
:options options) :options options)
(let [new-touched (cond (let [new-touched (cond
@@ -1024,7 +1024,7 @@
changes changes
(do (do
(log/info :msg (str "CHANGE-REMOTE-SYNCED? " (log/info :msg (str "CHANGE-REMOTE-SYNCED? "
(if (cph/page? container) "[P] " "[C] ") (if (ctn/page? container) "[P] " "[C] ")
(:name shape)) (:name shape))
:remote-synced? remote-synced?) :remote-synced? remote-synced?)
(-> changes (-> changes
@@ -1054,7 +1054,7 @@
(log/info :msg (str "SYNC " (log/info :msg (str "SYNC "
(:name origin-shape) (:name origin-shape)
" -> " " -> "
(if (cph/page? container) "[P] " "[C] ") (if (ctn/page? container) "[P] " "[C] ")
(:name dest-shape))) (:name dest-shape)))
(let [; To synchronize geometry attributes we need to make a prior (let [; To synchronize geometry attributes we need to make a prior
@@ -1133,7 +1133,7 @@
(defn- make-change (defn- make-change
[container change] [container change]
(if (cph/page? container) (if (ctn/page? container)
(assoc change :page-id (:id container)) (assoc change :page-id (:id container))
(assoc change :component-id (:id container)))) (assoc change :component-id (:id container))))
@@ -10,11 +10,15 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.rect :as gpr]
[app.common.geom.shapes.points :as gpo]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages.common :as cpc] [app.common.pages.common :as cpc]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@@ -27,6 +31,291 @@
[cljs.spec.alpha :as s] [cljs.spec.alpha :as s]
[potok.core :as ptk])) [potok.core :as ptk]))
;; -- copies --------------------------------------------------------
;; TBD...
(defn- get-copies
"If one or more of the shapes belongs to a component's main instance, find all copies of
the component in the same page.
Return a map {<main-root-id> [<main-root> [<copy-root> <copy-root>...]] ...}"
[shapes objects modif-tree]
(debug/logjs "==================================" "")
(debug/logjs "modif-tree" modif-tree)
(letfn [(get-copies-one [shape]
(let [root-shape (ctn/get-root-shape objects shape)]
(when (:main-instance? root-shape)
(let [children (->> root-shape
:shapes
(map #(get objects %))
;; (map #(gsh/transform-shape % (get-in modif-tree [(:id %) :modifiers])))
)
get-bounds (fn [shape]
(let [modifiers (-> (get modif-tree (:id shape)) :modifiers)]
;; (if (some? modifiers)
;; (-> (:points shape)
;; (gsh/transform-bounds modifiers)
;; (gpo/points->selrect))
;; (:selrect shape))))
(cond-> (:points shape)
(some? modifiers)
(-> (gsh/transform-bounds modifiers)
;; (gpo/points->selrect)
))))
_ (debug/logjs "points" (map get-bounds children))
;; ;; Update the bounds of the root group to accomodate the moved shapes,
;; ;; so its position is also synced to the copy root later.
;; root-shape (gsh/update-group-selrect root-shape children)
root-shape (assoc root-shape
:modif-selrect
;; (gpr/join-rects (map get-bounds children))
(-> (mapcat get-bounds children)
(gpr/points->selrect)))
;; (gpo/points->selrect)))
]
[(:id root-shape) [root-shape (ctn/get-instances objects root-shape)]]))))]
(into {} (map get-copies-one shapes))))
(defn- sync-shape
[main-shape copy-shape main-root copy-root modif-tree]
(debug/logjs "+++" "")
(debug/logjs "main-shape" main-shape)
(debug/logjs "copy-shape" copy-shape)
(debug/logjs "main-root" main-root)
(debug/logjs "copy-root" copy-root)
(let [;root-modif (-> modif-tree (:id main-root) :modifiers)
;shape-modif (-> modif-tree (:id main-shape) :modifiers)
orig (fn [obj] (gpt/point (:x obj) (:y obj)))
get-displacement (fn [shape]
;; Accumulate all :move modifiers of a shape
(let [modifiers (-> (get modif-tree (:id shape)) :modifiers)]
(reduce (fn [move modifier]
(if (= (:type modifier) :move)
(gpt/add move (:vector modifier))
move))
(gpt/point 0 0)
(:geometry-child modifiers))))
;; Distance from main-root to copy-root
root-delta (gpt/subtract (orig copy-root) (orig main-root))
;; Displacement from main-root to modified main-root
root-displacement (gpt/subtract (orig (:modif-selrect main-root))
(orig (:selrect main-root)))
;; Displacement to apply to the copy shape
shape-displacement (gpt/subtract (get-displacement main-shape)
root-displacement)
copy-rotation (fn [acc shape]
(let [modifiers (-> (get modif-tree (:id shape)) :modifiers)]
(reduce (fn [acc modifier]
(if (= (:type modifier) :rotation)
(let [center (:center modifier)
rotation (:rotation modifier)]
(ctm/rotation acc
(when (some? center)
(gpt/add center root-delta))
rotation))
acc))
acc
(:geometry-child modifiers))))
;; copy-move (fn [acc shape]
;; (let [modifiers (-> (get modif-tree (:id shape)) :modifiers)]
;; (reduce (fn [acc modifier]
;; (if (= (:type modifier) :move)
;; (let [vector (:vector modifier)]
;; (ctm/move acc (gpt/subtract vector root-displacement)))
;; acc))
;; acc
;; (:geometry-child modifiers))))
]
(debug/logjs "root-delta" root-delta)
(debug/logjs "root-displacement" root-displacement)
(-> (ctm/empty)
;; (ctm/rotation center rotation)
(ctm/move shape-displacement)
(copy-rotation main-shape)
;; (copy-move main-shape)
(vary-meta assoc :copied-modifier? true))))
;; $$ algoritmo tipo component sync (reposicionando la shape)
;; (defn- reposition-shape
;; [shape origin-root dest-root]
;; ;; (debug.logjs "+++" "")
;; ;; (debug.logjs "shape" shape)
;; ;; (debug.logjs "origin-root" origin-root)
;; ;; (debug.logjs "dest-root" dest-root)
;; (let [shape-pos (fn [shape]
;; (gpt/point (get-in shape [:selrect :x])
;; (get-in shape [:selrect :y])))
;;
;; origin-root-pos (shape-pos origin-root)
;; dest-root-pos (shape-pos dest-root)
;; delta (gpt/subtract dest-root-pos origin-root-pos)]
;; (gsh/move shape delta)))
;;
;; (defn- sync-shape
;; [main-shape copy-shape main-root copy-root]
;; (debug/logjs "+++" "")
;; (debug/logjs "main-shape" main-shape)
;; (debug/logjs "copy-shape" copy-shape)
;; (debug/logjs "main-root" main-root)
;; (debug/logjs "copy-root" copy-root)
;; (if (ctk/touched-group? copy-shape :geometry-group)
;; {}
;; (let [modif-shape (reposition-shape (:modif-shape main-shape) main-root copy-root)
;;
;; ;; _ (when (not= (:name main-shape) "Rect-1xx")
;; ;; (debug.logjs "+++" "")
;; ;; (debug.logjs "main-shape" main-shape)
;; ;; (debug.logjs "copy-shape" copy-shape)
;; ;; (debug.logjs "main-root" main-root)
;; ;; (debug.logjs "copy-root" copy-root)
;; ;; (debug.logjs "modif-shape" modif-shape))
;; translation (gpt/subtract (gsh/orig-pos modif-shape)
;; (gsh/orig-pos copy-shape))
;;
;; orig (gsh/orig-pos copy-shape)
;; mult-w (/ (gsh/width modif-shape) (gsh/width copy-shape))
;; mult-h (/ (gsh/height modif-shape) (gsh/height copy-shape))
;; resize (gpt/point mult-w mult-h)
;;
;; center (gsh/center-shape copy-shape)
;; rotation (- (:rotation modif-shape)
;; (:rotation copy-shape))]
;;
;; ;; (debug/logjs "..." "")
;; ;; (debug/logjs "translation" translation)
;; ;; (debug/logjs "resize" resize)
;; ;; (debug/logjs "orig" orig)
;; ;; (debug/logjs "rotation" rotation)
;; ;; (debug/logjs "center" center)
;; (-> (ctm/empty)
;; (ctm/rotation center rotation)
;; (ctm/move translation)
;; (ctm/resize resize orig)
;; (vary-meta assoc :copied-modifier? true)))))
;; =========nofun
;; (defn- shape-delta
;; [origin-shape dest-shape]
;; (let [shape-pos (fn [shape]
;; (gpt/point (get-in shape [:selrect :x])
;; (get-in shape [:selrect :y])))
;;
;; origin-pos (shape-pos origin-shape)
;; dest-pos (shape-pos dest-shape)]
;; (gpt/subtract dest-pos origin-pos)))
;;
;; (defn- sync-shape
;; [main-shape copy-shape main-root copy-root]
;; (let [delta (shape-delta main-root copy-root)
;; modifiers (:modifiers main-shape)
;;
;; copy-geometry
;; (fn [ops op]
;; (let [copy-op (case (:type op)
;; :move op
;; :resize (update op :origin gpt/add delta)
;; :rotation (update op :center gpt/add delta)
;; nil)]
;; (if (some? copy-op)
;; (conj ops op)
;; ops)))
;;
;; copy-structure
;; (fn [ops op]
;; (conj ops op))]
;;
;; (cond-> {}
;; (:geometry-parent modifiers)
;; (assoc :geometry-parent (reduce copy-geometry [] (:geometry-parent modifiers)))
;;
;; (:geometry-child modifiers)
;; (assoc :geometry-child (reduce copy-geometry [] (:geometry-child modifiers)))
;;
;; (:structure-parent modifiers)
;; (assoc :structure-parent (reduce copy-structure [] (:structure-parent modifiers)))
;;
;; (:structure-child modifiers)
;; (assoc :structure-child (reduce copy-structure [] (:structure-child modifiers))))))
;; =========fin nofun
(defn- process-text-modifiers
"For texts we only use the displacement because resize
needs to recalculate the text layout"
[shape modif-tree]
modif-tree)
;; (cond-> modifiers
;; (= :text (:type shape))
;; (select-keys [:displacement :rotation])))
(defn- add-modifiers
"Add modifiers to all necessary shapes inside the copies"
[copies objects modif-tree]
(letfn [(add-modifiers-shape [modif-tree copy-root copy-shape main-root main-shapes]
(let [main-shape (d/seek #(ctk/is-main-of? % copy-shape) main-shapes)
modifiers (sync-shape main-shape copy-shape main-root copy-root modif-tree)
;; %%(cond-> (sync-shape main-shape-modif copy-shape copy-root main-root)
;; %% (some? (:rotation (get-in modifiers [(:id main-shape-modif) :modifiers])))
;; %% (assoc :rotation (:rotation (get-in modifiers [(:id main-shape-modif) :modifiers])))
;; %% )
]
(debug/logjs "new modifiers" modifiers)
(if (seq modifiers)
(assoc-in modif-tree [(:id copy-shape) :modifiers] modifiers)
modif-tree)))
(add-modifiers-copy [modif-tree copy-root main-root main-shapes]
;; For each copy component, get all its shapes and proceed to sync with it
;; the changes in the corresponding one in the main component.
(let [copy-shapes (into [copy-root] (cph/get-children objects (:id copy-root)))]
(reduce #(add-modifiers-shape %1 copy-root %2 main-root main-shapes)
modif-tree
copy-shapes)))
(add-modifiers-component [modif-tree [main-root copy-roots]]
;; For each main component, get all its shapes, apply the modifiers to each one and
;; then proceed to sync changes with all copies.
(let [main-shapes (->> (into [main-root] (cph/get-children objects (:id main-root)))
(map (fn [shape]
(let [modifiers (get-in modif-tree [(:id shape) :modifiers])]
(assoc shape
:modifiers modifiers
:modif-shape (gsh/transform-shape shape modifiers))))))]
(reduce #(add-modifiers-copy %1 %2 main-root main-shapes)
modif-tree
copy-roots)))]
;; (let [main-shapes (into [main-root] (cph/get-children objects (:id main-root)))
;; main-shapes-modif (map (fn [shape]
;; (let [modifiers (get-in modif-tree [(:id shape) :modifiers])
;; points (:points shape)
;; bounds (gsh/transform-bounds points modifiers)]
;; (debug.logjs "..." "")
;; (debug.logjs "shape" shape)
;; (debug.logjs "modifiers" modifiers)
;; (debug.logjs "bounds" bounds)
;; (assoc shape :modif-bounds bounds)))
;; ;; (->> modifiers
;; ;; (process-text-modifiers shape)
;; ;; (gsh/transform-shape shape))))
;; main-shapes)]
;; (reduce #(add-modifiers-copy %1 %2 main-root main-shapes-modif)
;; modif-tree
;; copy-roots)))]
(reduce add-modifiers-component
modif-tree
(vals copies))))
;; -- temporary modifiers ------------------------------------------- ;; -- temporary modifiers -------------------------------------------
;; During an interactive transformation of shapes (e.g. when resizing or rotating ;; During an interactive transformation of shapes (e.g. when resizing or rotating
@@ -54,7 +343,7 @@
shape shape
(nil? root) (nil? root)
(cph/get-root-shape objects shape) (ctn/get-root-shape objects shape)
:else root) :else root)
@@ -64,7 +353,7 @@
transformed-shape transformed-shape
(nil? transformed-root) (nil? transformed-root)
(as-> (cph/get-root-shape objects transformed-shape) $ (as-> (ctn/get-root-shape objects transformed-shape) $
(gsh/transform-shape (merge $ (get modif-tree (:id $))))) (gsh/transform-shape (merge $ (get modif-tree (:id $)))))
:else transformed-root) :else transformed-root)
@@ -235,12 +524,26 @@
(wsh/lookup-page-objects state) (wsh/lookup-page-objects state)
snap-pixel? snap-pixel?
(and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))] (and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))
(as-> objects $ modif-tree
(apply-text-modifiers $ (get state :workspace-text-modifier)) (as-> objects $
;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path])) (apply-text-modifiers $ (get state :workspace-text-modifier))
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?))))) ;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path]))
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?))
shapes
(->> (keys modif-tree)
(map (d/getf objects)))
copies
(get-copies shapes objects modif-tree)
_ (debug/logjs "copies" copies)
;; TODO: mark new modifiers to be ignored in apply-modifiers
modif-tree (add-modifiers copies objects modif-tree)]
modif-tree)))
(defn set-modifiers (defn set-modifiers
([modif-tree] ([modif-tree]
@@ -264,7 +567,7 @@
(ptk/reify ::set-rotation-modifiers (ptk/reify ::set-rotation-modifiers
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
ids ids
(->> shapes (->> shapes
(remove #(get % :blocked false)) (remove #(get % :blocked false))
@@ -277,11 +580,23 @@
modif-tree modif-tree
(-> (build-modif-tree ids objects get-modifier) (-> (build-modif-tree ids objects get-modifier)
(gsh/set-objects-modifiers objects false false))] (gsh/set-objects-modifiers objects false false))
shapes
(->> (keys modif-tree)
(map (d/getf objects)))
copies
(get-copies shapes objects modif-tree)
;; _ (debug.logjs "==================" "")
;; _ (debug.logjs "modif-tree" modif-tree)
;; _ (debug.logjs "objects" objects)
;; _ (debug.logjs "copies" copies)
modif-tree (add-modifiers copies objects modif-tree)]
(assoc state :workspace-modifiers modif-tree)))))) (assoc state :workspace-modifiers modif-tree))))))
(defn apply-modifiers (defn apply-modifiers
([] ([]
(apply-modifiers nil)) (apply-modifiers nil))
@@ -301,25 +616,27 @@
shapes (map (d/getf objects) ids) shapes (map (d/getf objects) ids)
ignore-tree (->> (map #(get-ignore-tree object-modifiers objects %) shapes) ignore-tree (->> (map #(get-ignore-tree object-modifiers objects %) shapes)
(reduce merge {})) (reduce merge {}))
undo-id (uuid/next)] undo-id (uuid/next)
(rx/concat update-fn
(if undo-transation? (fn [shape]
(rx/of (dwu/start-undo-transaction undo-id)) (let [modif (get-in object-modifiers [(:id shape) :modifiers])
(rx/empty)) text-shape? (cph/text-shape? shape)]
(rx/of (ptk/event ::dwg/move-frame-guides ids-with-children) (-> shape
(ptk/event ::dwcm/move-frame-comment-threads ids-with-children) (gsh/transform-shape modif)
(dch/update-shapes (cond-> text-shape?
ids (update-grow-type shape)))))
(fn [shape]
(let [modif (get-in object-modifiers [(:id shape) :modifiers]) ignore-touched-fn
text-shape? (cph/text-shape? shape)] (fn [shape-id]
(-> shape ;; When a modifier comes from copying a main component to copies,
(gsh/transform-shape modif) ;; do not set the touched flag, because this change is synced.
(cond-> text-shape? (let [modif (get-in object-modifiers [shape-id :modifiers])]
(update-grow-type shape))))) (:copied-modifier? (meta modif))))
{:reg-objects? true
opts {:reg-objects? true
:ignore-tree ignore-tree :ignore-tree ignore-tree
:ignore-touched-fn ignore-touched-fn
;; Attributes that can change in the transform. This way we don't have to check ;; Attributes that can change in the transform. This way we don't have to check
;; all the attributes ;; all the attributes
:attrs [:selrect :attrs [:selrect
@@ -336,8 +653,15 @@
:flip-y :flip-y
:grow-type :grow-type
:layout-item-h-sizing :layout-item-h-sizing
:layout-item-v-sizing :layout-item-v-sizing]}]
]})
(rx/concat
(if undo-transation?
(rx/of (dwu/start-undo-transaction undo-id))
(rx/empty))
(rx/of (ptk/event ::dwg/move-frame-guides ids-with-children)
(ptk/event ::dwcm/move-frame-comment-threads ids-with-children)
(dch/update-shapes ids update-fn opts)
(clear-local-transform)) (clear-local-transform))
(if undo-transation? (if undo-transation?
(rx/of (dwu/commit-undo-transaction undo-id)) (rx/of (dwu/commit-undo-transaction undo-id))
@@ -14,6 +14,7 @@
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.page :as ctp] [app.common.types.page :as ctp]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
@@ -159,7 +160,7 @@
;; not the root. In this case, they must not be deleted, ;; not the root. In this case, they must not be deleted,
;; but hidden (to be able to recover them more easily). ;; but hidden (to be able to recover them more easily).
(let [shape (get objects shape-id) (let [shape (get objects shape-id)
component-shape (cph/get-component-shape objects shape)] component-shape (ctn/get-component-shape objects shape)]
(and (ctk/in-component-instance? shape) (and (ctk/in-component-instance? shape)
(not= shape component-shape) (not= shape component-shape)
(not (ctk/main-instance? component-shape))))) (not (ctk/main-instance? component-shape)))))
@@ -14,14 +14,19 @@
[app.common.geom.shapes.flex-layout :as gsl] [app.common.geom.shapes.flex-layout :as gsl]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages.changes-builder :as pcb] [app.common.pages.changes-builder :as pcb]
[app.common.pages.common :as cpc]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.collapse :as dwc] [app.main.data.workspace.collapse :as dwc]
[app.main.data.workspace.comments :as dwcm]
[app.main.data.workspace.guides :as dwg]
[app.main.data.workspace.modifiers :as dwm] [app.main.data.workspace.modifiers :as dwm]
[app.main.data.workspace.selection :as dws] [app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
@@ -97,7 +102,6 @@
(update [_ state] (update [_ state]
(update state :workspace-local dissoc :transform)))) (update state :workspace-local dissoc :transform))))
;; -- Resize -------------------------------------------------------- ;; -- Resize --------------------------------------------------------
(defn start-resize (defn start-resize
@@ -11,12 +11,18 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph] ; TODO: move this to ctst
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.main.data.workspace.transforms :as dwt]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
[app.main.ui.workspace.viewport.utils :as vwu] [app.main.ui.workspace.viewport.utils :as vwu]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.globals :as globals] [app.util.globals :as globals]
[app.util.timers :as tm]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
(defn get-shape-node (defn get-shape-node
@@ -190,14 +196,230 @@
(-> modifiers (-> modifiers
(ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape'))))) (ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape')))))
(defn- get-copies
"If one or more of the shapes belongs to a component's main instance, find all copies of
the component in the same page.
Return a map {<main-root-id> [<main-root> [<copy-root> <copy-root>...]] ...}"
[shapes objects modifiers]
(letfn [(get-copies-one [shape]
(let [root-shape (ctn/get-root-shape objects shape)]
(when (:main-instance? root-shape)
(let [children (->> root-shape
:shapes
(map #(get objects %))
;; %% (map #(gsh/apply-modifiers % (get-in modifiers [(:id %) :modifiers])))
)
root-shape (gsh/update-group-selrect root-shape children)]
[(:id root-shape) [root-shape (ctn/get-instances objects root-shape)]]))))]
(into {} (map get-copies-one shapes))))
(defn- reposition-shape
[shape origin-root dest-root]
(let [shape-pos (fn [shape]
(gpt/point (get-in shape [:selrect :x])
(get-in shape [:selrect :y])))
origin-root-pos (shape-pos origin-root)
dest-root-pos (shape-pos dest-root)
delta (gpt/subtract dest-root-pos origin-root-pos)]
(gsh/move shape delta)))
(defn- sync-shape
[main-shape copy-shape copy-root main-root]
;; (js/console.log "+++")
;; (js/console.log "main-shape" (clj->js main-shape))
;; (js/console.log "copy-shape" (clj->js copy-shape))
(if (ctk/touched-group? copy-shape :geometry-group)
{}
(let [main-shape (reposition-shape main-shape main-root copy-root)
translation (gpt/subtract (gsh/orig-pos main-shape)
(gsh/orig-pos copy-shape))
center (gsh/orig-pos copy-shape)
mult-w (/ (gsh/width main-shape) (gsh/width copy-shape))
mult-h (/ (gsh/height main-shape) (gsh/height copy-shape))
resize (gpt/point mult-w mult-h)]
(cond-> {}
(not (gpt/almost-zero? translation))
(assoc :displacement (gmt/translate-matrix translation))
(not (gpt/close? resize (gpt/point 1 1)))
(assoc :resize-vector resize
:resize-origin center)))))
;; (defn- sync-shape
;; [main-shape copy-shape copy-root main-root]
;; ;; (js/console.log "+++")
;; ;; (js/console.log "main-shape" (clj->js main-shape))
;; ;; (js/console.log "copy-shape" (clj->js copy-shape))
;; (if (ctk/touched-group? copy-shape :geometry-group)
;; (gmt/matrix)
;; (let [main-shape (reposition-shape main-shape main-root copy-root)
;;
;; translation (gpt/subtract (gsh/orig-pos main-shape)
;; (gsh/orig-pos copy-shape))
;;
;; center (gsh/orig-pos copy-shape)
;; mult-w (/ (gsh/width main-shape) (gsh/width copy-shape))
;; mult-h (/ (gsh/height main-shape) (gsh/height copy-shape))
;; resize (gpt/point mult-w mult-h)]
;;
;; (cond-> (gmt/matrix)
;; (not (gpt/almost-zero? translation))
;; (gmt/multiply (gmt/translate-matrix translation))
;;
;; (not (gpt/almost-zero? resize))
;; (gmt/multiply (gmt/scale-matrix resize center))))))
(defn- process-text-modifiers
"For texts we only use the displacement because resize
needs to recalculate the text layout"
[shape modifiers]
(cond-> modifiers
(= :text (:type shape))
(select-keys [:displacement :rotation])))
(defn- add-copies-modifiers
"Add modifiers to all necessary shapes inside the copies"
[copies objects modifiers]
;; (js/console.log "copies" (clj->js copies))
(letfn [(add-copy-modifiers-one [modifiers copy-shape copy-root main-root main-shapes main-shapes-modif]
;; (assert (not (contains? modifiers (:id copy-shape))) "Si peta esto, we have a problem")
(let [main-shape-modif (d/seek #(ctk/is-main-of? % copy-shape) main-shapes-modif)
;; copy-shape (cond-> copy-shape
;; (some? (:transform-inverse copy-shape))
;; (gsh/apply-transform (:transform-inverse copy-shape)))
modifier (cond-> (sync-shape main-shape-modif copy-shape copy-root main-root)
(some? (:rotation (get-in modifiers [(:id main-shape-modif) :modifiers])))
(assoc :rotation (:rotation (get-in modifiers [(:id main-shape-modif) :modifiers])))
)]
(if (seq modifier)
(assoc-in modifiers [(:id copy-shape) :modifiers] modifier)
modifiers)))
;; $$$
;; (add-copy-modifiers-one [modifiers copy-shape copy-root main-root main-shapes main-shapes-modif]
;; (update modifiers (:id copy-shape)
;; (fn [modifier]
;; (let [modifier (or modifier (gmt/matrix))
;; main-shape-modif (d/seek #(ctk/is-main-of? % copy-shape) main-shapes-modif)]
;; (gmt/multiply modifier (sync-shape main-shape-modif copy-shape copy-root main-root))))))
(add-copy-modifiers [modifiers copy-root main-root main-shapes main-shapes-modif]
(let [copy-shapes (into [copy-root] (cph/get-children objects (:id copy-root)))]
(reduce #(add-copy-modifiers-one %1 %2 copy-root main-root main-shapes main-shapes-modif)
modifiers
copy-shapes)))
(add-copies-modifiers-one [modifiers [main-root copy-roots]]
(let [main-shapes (into [main-root] (cph/get-children objects (:id main-root)))
main-shapes-modif (map (fn [shape]
(let [; shape (cond-> shape
; (some? (:transform-inverse shape))
; (gsh/apply-transform (:transform-inverse shape)))
]
(->> (get-in modifiers [(:id shape) :modifiers])
(process-text-modifiers shape)
;; %% (gsh/apply-modifiers shape)
)))
main-shapes)]
(reduce #(add-copy-modifiers %1 %2 main-root main-shapes main-shapes-modif)
modifiers
copy-roots)))]
(reduce add-copies-modifiers-one
modifiers
(vals copies))))
;; $$$
;; (defn- add-copies-transforms
;; "Add transform to all necessary shapes inside the copies"
;; [copies objects modifiers transforms]
;; ;; (js/console.log "copies" (clj->js copies))
;; (letfn [(add-copy-transforms-one [transforms copy-shape copy-root main-root main-shapes main-shapes-modif]
;; (update transforms (:id copy-shape)
;; (fn [transform]
;; (let [transform (or transform (gmt/matrix))
;; main-shape-modif (d/seek #(ctk/is-main-of? % copy-shape) main-shapes-modif)]
;; (gmt/multiply transform (sync-shape main-shape-modif copy-shape copy-root main-root))))))
;;
;; (add-copy-transforms [transforms copy-root main-root main-shapes main-shapes-modif]
;; (let [copy-shapes (into [copy-root] (cph/get-children objects (:id copy-root)))]
;; (reduce #(add-copy-transforms-one %1 %2 copy-root main-root main-shapes main-shapes-modif)
;; transforms
;; copy-shapes)))
;;
;; (add-copies-transforms-one [transforms [main-root copy-roots]]
;; (let [main-shapes (into [main-root] (cph/get-children objects (:id main-root)))
;; main-shapes-modif (map (fn [shape]
;; (->> (get-in modifiers [(:id shape) :modifiers])
;; (process-text-modifiers shape)
;; (gsh/apply-modifiers shape)))
;; main-shapes)]
;; (reduce #(add-copy-transforms %1 %2 main-root main-shapes main-shapes-modif)
;; transforms
;; copy-roots)))]
;;
;; (reduce add-copies-transforms-one
;; transforms
;; (vals copies))))
;; (defn get-copy-shapes
;; "If one or more of the shapes belongs to a component's main instance, find all copies of
;; the component in the same page. Ignore copies with the geometry values touched."
;; [shapes objects]
;; (letfn [(get-copy-shapes-one [shape]
;; (let [root-shape (ctn/get-root-shape objects shape)]
;; (when (:main-instance? root-shape)
;; (->> (ctn/get-instances objects shape)
;; (filter #(not (ctk/touched-group? % :geometry-group)))))))
;;
;; (pack-main-copies [shape]
;; (map #(vector shape %) (get-copy-shapes-one shape)))]
;;
;; (mapcat pack-main-copies shapes)))
(defn use-dynamic-modifiers (defn use-dynamic-modifiers
[objects node modifiers] [objects node modifiers]
(let [transforms (let [prev-shapes (mf/use-var nil)
prev-modifiers (mf/use-var nil)
prev-transforms (mf/use-var nil)
;; prev-copies (mf/use-var nil)
;; copies
;; (mf/use-memo ; TODO: ojo estas deps hay que revisarlas
;; (mf/deps modifiers (and (d/not-empty? @prev-modifiers) (d/not-empty? modifiers)))
;; (fn []
;; (let [shapes (->> (keys modifiers)
;; (mapv (d/getf objects)))]
;; (get-copies shapes objects modifiers))))
;; modifiers
;; (mf/use-memo
;; (mf/deps objects modifiers copies @prev-copies)
;; (fn []
;; (if (= (count copies) (count @prev-copies))
;; modifiers
;; (let [new-modifiers (add-copies-modifiers copies objects modifiers)]
;; (js/console.log "==================")
;; (js/console.log "modifiers (antes)" (clj->js modifiers))
;; (js/console.log "copies" (clj->js copies))
;; (js/console.log "modifiers (después)" (clj->js new-modifiers))
;; (when (seq new-modifiers)
;; (tm/schedule #(st/emit! (dwt/set-modifiers-raw new-modifiers))))
;; new-modifiers))))
transforms
(mf/use-memo (mf/use-memo
(mf/deps modifiers) (mf/deps modifiers)
(fn [] (fn []
(when (some? modifiers) ;; (js/console.log "****modifiers" (clj->js modifiers))
(when (seq modifiers)
(d/mapm (fn [id {modifiers :modifiers}] (d/mapm (fn [id {modifiers :modifiers}]
(let [shape (get objects id) (let [shape (get objects id)
adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? modifiers))) adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? modifiers)))
@@ -213,13 +435,195 @@
(mf/use-memo (mf/use-memo
(mf/deps transforms) (mf/deps transforms)
(fn [] (fn []
;; (js/console.log "transforms" (clj->js transforms))
(->> (keys transforms) (->> (keys transforms)
(filter #(some? (get transforms %))) (filter #(some? (get transforms %)))
(mapv (d/getf objects))))) (mapv (d/getf objects)))))
prev-shapes (mf/use-var nil) ;; $$$
prev-modifiers (mf/use-var nil) ;; transforms
prev-transforms (mf/use-var nil)] ;; (mf/use-memo
;; (mf/deps objects modifiers transforms copies)
;; (fn []
;; ;; (js/console.log "modifiers" (clj->js modifiers))
;; (add-copies-transforms copies objects modifiers transforms)))
;; copy-shapes
;; (mf/use-memo
;; (mf/deps (and (d/not-empty? @prev-modifiers) (d/not-empty? modifiers)))
;; (fn []
;; (get-copy-shapes shapes objects)))
;; transforms
;; (mf/use-memo
;; (mf/deps objects modifiers transforms copy-shapes)
;; (fn []
;; (let [add-copy-transforms
;; (fn [transforms main-shape copy-shape]
;; (let [main-bounds (gsh/bounding-box main-shape)
;; copy-bounds (gsh/bounding-box copy-shape)
;; delta (gpt/subtract (gpt/point (:x copy-bounds) (:y copy-bounds))
;; (gpt/point (:x main-bounds) (:y main-bounds)))
;;
;; ;; Move the modifier origin points to the position of the copy.
;; main-modifiers (get-in modifiers [(:id main-shape) :modifiers])
;; copy-modifiers (let [origin (:resize-origin main-modifiers)
;; origin-2 (:resize-origin-2 main-modifiers)]
;; (cond-> main-modifiers
;; (some? origin)
;; (assoc :resize-origin (gpt/add origin delta))
;;
;; (some? origin-2)
;; (assoc :resize-origin-2 (gpt/add origin-2 delta))))
;;
;; center (gsh/center-shape copy-shape)]
;;
;; (update transforms (:id copy-shape)
;; #(let [transform (or % (gmt/matrix))]
;; (gmt/multiply transform
;; (gsh/modifiers->transform center copy-modifiers))))))
;;
;; apply-delta
;; (fn [transforms shape-id delta]
;; (let [shape-ids (-> (cph/get-children-ids objects shape-id)
;; (conj shape-id))
;;
;; add-delta (fn [transform]
;; (let [transform (or transform (gmt/matrix))]
;; (gmt/multiply transform (gmt/translate-matrix delta))))]
;;
;; (reduce #(update %1 %2 add-delta)
;; transforms
;; shape-ids)))
;;
;; manage-root
;; (fn [transforms main-shape copy-shape]
;; (let [main-modifiers (get-in modifiers [(:id main-shape) :modifiers])
;; modified-main (gsh/apply-modifiers main-shape main-modifiers)
;;
;; delta (gpt/subtract (gsh/orig-pos main-shape)
;; (gsh/orig-pos modified-main))]
;;
;; (cond-> transforms
;; (not (gpt/almost-zero? delta))
;; (apply-delta (:id copy-shape) delta))))
;;
;; manage-nonroot
;; (fn [transforms main-shape copy-shape]
;; ; TODO: comparar el orig-pos de la main-shape modificada con el del su propio
;; ; root también modificado (antes de rotación). Si es menor que cero en alguno
;; ; de los dos ejes, añadir un desplazamiento al root y todos sus hijos
;; (let [main-root (ctn/get-root-shape objects main-shape)
;; main-root-modifiers (get-in modifiers [(:id main-root) :modifiers])
;; modified-main-root (gsh/apply-modifiers main-root main-root-modifiers)
;;
;; main-shape-modifiers (get-in modifiers [(:id main-shape) :modifiers])
;; modified-main-shape (gsh/apply-modifiers main-shape main-shape-modifiers)
;;
;; delta (gpt/subtract (gsh/orig-pos modified-main-shape)
;; (gsh/orig-pos modified-main-root))
;;
;; delta-x (- (min 0 (:x delta)))
;; delta-y (- (min 0 (:y delta)))]
;;
;; (if (or (pos? delta-x) (pos? delta-y))
;; (let [copy-root (ctn/get-root-shape objects copy-shape)]
;; (apply-delta transforms (:id copy-root) (gpt/point delta-x delta-y)))
;; transforms)))
;;
;; add-all-transforms
;; (fn [transforms [main-shape copy-shape]]
;; ;; (js/console.log "----------------------")
;; ;; (js/console.log "main-shape" (clj->js main-shape))
;; ;; (js/console.log "copy-shape" (clj->js copy-shape))
;; (as-> transforms $
;; (add-copy-transforms $ main-shape copy-shape)
;; (if (ctk/instance-root? main-shape)
;; (manage-root $ main-shape copy-shape)
;; (manage-nonroot $ main-shape copy-shape))))]
;;
;; ;; (js/console.log "==================")
;; (reduce add-all-transforms
;; transforms
;; copy-shapes))))
;; ---- old
;; (let [translate1
;; (fn [shape modifiers]
;; (let [root-shape (ctn/get-root-shape objects shape)
;; root-pos (gsh/orig-pos root-shape)
;;
;; modified-shape (gsh/apply-modifiers shape modifiers)
;; modified-pos (gsh/orig-pos modified-shape)]
;; ;; (js/console.log "root-pos" (clj->js root-pos))
;; ;; (js/console.log "modified-pos" (clj->js modified-pos))
;; (if (or (< (:x modified-pos) (:x root-pos))
;; (< (:y modified-pos) (:y root-pos)))
;; (let [displacement (get modifiers :displacement (gmt/matrix))
;; delta (gpt/point (max 0 (- (:x root-pos) (:x modified-pos)))
;; (max 0 (- (:y root-pos) (:y modified-pos))))]
;; [(assoc modifiers :displacement
;; (gmt/add-translate displacement
;; (gmt/translate-matrix delta)))
;; delta])
;; [modifiers (gpt/point 0 0)])))
;;
;; get-copy-transform
;; (fn [[main-shape copy-shape]]
;; (js/console.log "----------------------")
;; (js/console.log "main-shape" (clj->js main-shape))
;; (js/console.log "copy-shape" (clj->js copy-shape))
;; (let [[main-modifiers deltaa] (->> (get-in modifiers [(:id main-shape) :modifiers])
;; (translate1 main-shape))
;;
;; main-bounds (gsh/bounding-box main-shape)
;; copy-bounds (gpt/add (gpt/point
;; (:x (gsh/bounding-box copy-shape))
;; (:y (gsh/bounding-box copy-shape)))
;; deltaa)
;; delta (gpt/subtract (gpt/point (:x copy-bounds) (:y copy-bounds))
;; (gpt/point (:x main-bounds) (:y main-bounds)))
;;
;; root-shape (ctn/get-root-shape objects main-shape)
;; root-modifiers (get-in modifiers [(:id root-shape) :modifiers])
;; _ (js/console.log "main-modifiers" (clj->js main-modifiers))
;; _ (js/console.log "root-modifiers" (clj->js root-modifiers))
;;
;; ;; root-shape (ctn/get-root-shape objects copy-shape)
;; ;; root-pos (gsh/orig-pos root-shape)
;; ;; copy-pos (gsh/orig-pos copy-shape)
;;
;; ;; Move the modifier origin points to the position of the copy.
;; copy-modifiers (let [origin (:resize-origin main-modifiers)
;; origin-2 (:resize-origin-2 main-modifiers)]
;; (cond-> main-modifiers
;; (some? origin)
;; (assoc :resize-origin (gpt/add origin delta))
;;
;; (some? origin-2)
;; (assoc :resize-origin-2 (gpt/add origin-2 delta))
;;
;; ;; (gpt/close? root-pos copy-pos)
;; ;; (dissoc :displacement)
;; ))
;;
;; center (gsh/center-shape copy-shape)]
;;
;; ;; (js/console.log "delta" (clj->js delta))
;; ;; (js/console.log "main-modifiers" (clj->js main-modifiers))
;; ;; (js/console.log "main-transform" (str (gsh/modifiers->transform
;; ;; (gsh/center-shape main-shape)
;; ;; main-modifiers)))
;; ;; (js/console.log "copy-modifiers" (clj->js copy-modifiers))
;; ;; (js/console.log "copy-transform" (str (gsh/modifiers->transform
;; ;; center copy-modifiers)))
;; (gsh/modifiers->transform center copy-modifiers)))]
;;
;; (reduce #(assoc %1 (:id (second %2)) (get-copy-transform %2))
;; transforms
;; copy-shapes))))
]
(mf/use-effect (mf/use-effect
(mf/deps add-children) (mf/deps add-children)
@@ -265,6 +669,8 @@
(when (d/not-empty? removed-shapes) (when (d/not-empty? removed-shapes)
(remove-transform! node @prev-shapes))) (remove-transform! node @prev-shapes)))
(reset! prev-modifiers modifiers) (reset! prev-modifiers modifiers)
(reset! prev-transforms transforms) (reset! prev-transforms transforms)
(reset! prev-shapes shapes))))) (reset! prev-shapes shapes)
;; (reset! prev-copies copies)
))))
@@ -9,6 +9,7 @@
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.types.component :as ctk] [app.common.types.component :as ctk]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.file :as ctf]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[cljs.pprint :refer [pprint]] [cljs.pprint :refer [pprint]]
[cljs.test :as t :include-macros true] [cljs.test :as t :include-macros true]
@@ -91,7 +92,7 @@
root-inst (ctn/get-shape page root-inst-id) root-inst (ctn/get-shape page root-inst-id)
libs (wsh/get-libraries state) libs (wsh/get-libraries state)
component (cph/get-component libs (:component-id root-inst)) component (ctf/get-component libs (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id) shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst)) shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
@@ -100,10 +101,10 @@
main-exists? (fn [shape] main-exists? (fn [shape]
(let [component-shape (let [component-shape
(cph/get-component-shape (:objects page) shape) (ctn/get-component-shape (:objects page) shape)
component component
(cph/get-component libs (:component-id component-shape)) (ctf/get-component libs (:component-id component-shape))
main-shape main-shape
(ctn/get-shape component (:shape-ref shape))] (ctn/get-shape component (:shape-ref shape))]
@@ -131,7 +132,7 @@
root-inst (ctn/get-shape page root-inst-id) root-inst (ctn/get-shape page root-inst-id)
libs (wsh/get-libraries state) libs (wsh/get-libraries state)
component (cph/get-component libs (:component-id root-inst)) component (ctf/get-component libs (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id) shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst)) shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
@@ -140,10 +141,10 @@
main-exists? (fn [shape] main-exists? (fn [shape]
(let [component-shape (let [component-shape
(cph/get-component-shape (:objects page) shape) (ctn/get-component-shape (:objects page) shape)
component component
(cph/get-component libs (:component-id component-shape)) (ctf/get-component libs (:component-id component-shape))
main-shape main-shape
(ctn/get-shape component (:shape-ref shape))] (ctn/get-shape component (:shape-ref shape))]
@@ -160,7 +161,7 @@
[state component-id] [state component-id]
(let [page (thp/current-page state) (let [page (thp/current-page state)
libs (wsh/get-libraries state) libs (wsh/get-libraries state)
component (cph/get-component libs component-id) component (ctf/get-component libs component-id)
root-main (ctk/get-component-root component) root-main (ctk/get-component-root component)
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))] shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
@@ -302,7 +302,7 @@
; Renamed component ; Renamed component
; Rect-1 ; Rect-1
(let [libs (wsh/get-libraries new-state) (let [libs (wsh/get-libraries new-state)
component (cph/get-component libs component (ctf/get-component libs
(:component-file instance1) (:component-file instance1)
(:component-id instance1))] (:component-id instance1))]
(t/is (= (:name component) (t/is (= (:name component)
@@ -400,7 +400,7 @@
(:id instance1)) (:id instance1))
libs (wsh/get-libraries new-state) libs (wsh/get-libraries new-state)
component (cph/get-component libs component (ctf/get-component libs
(:component-file instance1) (:component-file instance1)
(:component-id instance1))] (:component-id instance1))]