mirror of
https://github.com/penpot/penpot.git
synced 2025-12-23 22:48:40 -05:00
Compare commits
11 Commits
revert-646
...
hiru-trans
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
069995b62f | ||
|
|
d145716e52 | ||
|
|
a4916b8add | ||
|
|
14ee85ccd7 | ||
|
|
e8bf9d5f41 | ||
|
|
5f33f54cff | ||
|
|
7fbc47ccdb | ||
|
|
8ccd9bedfa | ||
|
|
a4e36390e2 | ||
|
|
4eaa9394f6 | ||
|
|
9bf0c6e681 |
@@ -58,6 +58,21 @@
|
||||
[shape]
|
||||
(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?
|
||||
"Checks if one rect is fully inside the other"
|
||||
[rect other]
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.pages.changes-spec :as pcs]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.components-list :as ctkl]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.colors-list :as ctcl]
|
||||
@@ -116,7 +117,7 @@
|
||||
(cond-> parent
|
||||
(and (:shape-ref parent)
|
||||
(not ignore-touched))
|
||||
(-> (update :touched cph/set-touched-group :shapes-group)
|
||||
(-> (update :touched ctk/set-touched-group :shapes-group)
|
||||
(dissoc :remote-synced?)))))
|
||||
|
||||
(delete-from-objects [objects]
|
||||
@@ -221,7 +222,7 @@
|
||||
(update :shapes d/vec-without-nils))]
|
||||
(cond-> parent
|
||||
(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?)))))
|
||||
|
||||
(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] d/vec-without-nils)
|
||||
(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?)))))))))
|
||||
|
||||
(update-parent-id [objects id]
|
||||
@@ -416,7 +417,7 @@
|
||||
(not root-name?)
|
||||
(not (and ignore-geometry is-geometry?)))
|
||||
(->
|
||||
(update :touched cph/set-touched-group group)
|
||||
(update :touched ctk/set-touched-group group)
|
||||
(dissoc :remote-synced?))
|
||||
|
||||
(nil? val)
|
||||
@@ -459,7 +460,7 @@
|
||||
(defmulti components-changed (fn [_ change] (:type change)))
|
||||
|
||||
(defmethod components-changed :mod-obj
|
||||
[file-data {:keys [id page-id _component-id operations]}]
|
||||
[file-data {:keys [id page-id operations]}]
|
||||
(when page-id
|
||||
(let [page (ctpl/get-page file-data page-id)
|
||||
shape-and-parents (map #(ctn/get-shape page %)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
@@ -43,7 +44,7 @@
|
||||
|
||||
(defn with-container
|
||||
[changes container]
|
||||
(if (cph/page? container)
|
||||
(if (ctn/page? container)
|
||||
(vary-meta changes assoc ::page-id (:id container))
|
||||
(vary-meta changes assoc ::component-id (:id container))))
|
||||
|
||||
|
||||
@@ -190,71 +190,6 @@
|
||||
:else
|
||||
(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
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -7,10 +7,23 @@
|
||||
(ns app.common.types.component)
|
||||
|
||||
(defn instance-root?
|
||||
"Check if the shape is the root of an instance or a subinstance."
|
||||
[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?
|
||||
"Check if the shape is the root of a near instance of the component."
|
||||
[shape file-id component-id]
|
||||
(and (some? (:component-id shape))
|
||||
(some? (:component-file shape))
|
||||
@@ -18,8 +31,10 @@
|
||||
(= (:component-file shape) file-id)))
|
||||
|
||||
(defn is-main-of?
|
||||
"Check if the first shape is the near main of the second one."
|
||||
[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))
|
||||
(= (:shape-ref shape-inst) (:shape-ref shape-main)))))
|
||||
|
||||
@@ -35,11 +50,13 @@
|
||||
(= page-id (:main-instance-page component))))
|
||||
|
||||
(defn get-component-root
|
||||
"Get the root shape of the component."
|
||||
[component]
|
||||
(get-in component [:objects (:id component)]))
|
||||
|
||||
(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]
|
||||
(and (some? (:component-id shape))
|
||||
(= (:component-file shape) library-id)))
|
||||
@@ -49,3 +66,13 @@
|
||||
[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.shapes :as gsh]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[clojure.spec.alpha :as s]))
|
||||
|
||||
@@ -61,6 +62,40 @@
|
||||
[container 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
|
||||
"Clone the shape and all children. Generate new ids and detach
|
||||
from parent and frame. Update the original shapes to have links
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
(ns app.common.types.file
|
||||
(:require
|
||||
[app.common.pprint :refer [pprint]]
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.features :as ffeat]
|
||||
@@ -13,6 +14,7 @@
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.pages.common :refer [file-version]]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.color :as ctc]
|
||||
[app.common.types.colors-list :as ctcl]
|
||||
[app.common.types.component :as ctk]
|
||||
@@ -99,6 +101,17 @@
|
||||
(concat (map #(ctn/make-container % :page) (ctpl/pages-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
|
||||
"Update a container inside the file, it can be a page or a component"
|
||||
[file-data container f]
|
||||
@@ -500,7 +513,7 @@
|
||||
(show-component [shape objects]
|
||||
(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-file-id (when root-shape (:component-file root-shape))
|
||||
component-file (when component-file-id (get libraries component-file-id nil))
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[clojure.spec.alpha :as s]))
|
||||
@@ -45,7 +46,7 @@
|
||||
(cond-> (and (:shape-ref parent)
|
||||
(not= (:id parent) frame-id)
|
||||
(not ignore-touched))
|
||||
(-> (update :touched cph/set-touched-group :shapes-group)
|
||||
(-> (update :touched ctk/set-touched-group :shapes-group)
|
||||
(dissoc :remote-synced?)))))
|
||||
|
||||
;; TODO: this looks wrong, why we allow nil values?
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
[clojure.test :as t]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[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
|
||||
|
||||
@@ -81,7 +82,7 @@
|
||||
[page root-inst-id libraries]
|
||||
(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-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||
@@ -90,10 +91,10 @@
|
||||
|
||||
main-exists? (fn [shape]
|
||||
(let [component-shape
|
||||
(cph/get-component-shape (:objects page) shape)
|
||||
(ctn/get-component-shape (:objects page) shape)
|
||||
|
||||
component
|
||||
(cph/get-component libraries (:component-id component-shape))
|
||||
(ctf/get-component libraries (:component-id component-shape))
|
||||
|
||||
main-shape
|
||||
(ctn/get-shape component (:shape-ref shape))]
|
||||
@@ -117,7 +118,7 @@
|
||||
[page root-inst-id libraries]
|
||||
(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-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||
@@ -126,10 +127,10 @@
|
||||
|
||||
main-exists? (fn [shape]
|
||||
(let [component-shape
|
||||
(cph/get-component-shape (:objects page) shape)
|
||||
(ctn/get-component-shape (:objects page) shape)
|
||||
|
||||
component
|
||||
(cph/get-component libraries (:component-id component-shape))
|
||||
(ctf/get-component libraries (:component-id component-shape))
|
||||
|
||||
main-shape
|
||||
(ctn/get-shape component (:shape-ref shape))]
|
||||
@@ -144,7 +145,7 @@
|
||||
(defn resolve-component
|
||||
"Get the component with the given id and all its shapes."
|
||||
[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)
|
||||
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
|
||||
|
||||
|
||||
@@ -772,8 +772,8 @@
|
||||
(not (:component-root? shape)))
|
||||
|
||||
parent (get objects parent-id)
|
||||
component-shape (cph/get-component-shape objects shape)
|
||||
component-shape-parent (cph/get-component-shape objects parent)
|
||||
component-shape (ctn/get-component-shape objects shape)
|
||||
component-shape-parent (ctn/get-component-shape objects parent)
|
||||
|
||||
detach? (and instance-part? (not= (:id component-shape)
|
||||
(:id component-shape-parent)))
|
||||
@@ -1510,7 +1510,7 @@
|
||||
;; Check if the shape is an instance whose master is defined in a
|
||||
;; library that is not linked to the current file
|
||||
(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)]
|
||||
(and (some? root)
|
||||
(not= root-file-id (:current-file-id state))
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
(defn update-shapes
|
||||
([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}}]
|
||||
|
||||
(us/assert ::coll-of-uuid ids)
|
||||
@@ -52,7 +52,10 @@
|
||||
|
||||
changes (reduce
|
||||
(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/empty-changes it page-id)
|
||||
(pcb/set-save-undo? save-undo?)
|
||||
|
||||
@@ -372,7 +372,7 @@
|
||||
ptk/WatchEvent
|
||||
(watch [it 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)
|
||||
unames (into #{} (map :name) all-components)
|
||||
new-name (ctst/generate-unique-name unames (:name component))
|
||||
@@ -490,7 +490,7 @@
|
||||
(watch [it state _]
|
||||
(let [file (wsh/get-local-file state)
|
||||
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)
|
||||
(pcb/with-container container)
|
||||
@@ -506,7 +506,7 @@
|
||||
(let [page-id (:current-page-id state)
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
file (wsh/get-local-file state)
|
||||
container (cph/get-container file :page page-id)
|
||||
container (ctf/get-container file :page page-id)
|
||||
selected (->> state
|
||||
(wsh/lookup-selected)
|
||||
(cph/clean-loops objects))
|
||||
@@ -563,7 +563,7 @@
|
||||
libraries (wsh/get-libraries 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
|
||||
(features/active-feature? state :components-v2)
|
||||
@@ -599,7 +599,7 @@
|
||||
local-file (wsh/get-local-file 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)
|
||||
|
||||
changes
|
||||
@@ -729,7 +729,13 @@
|
||||
(when sync-typographies?
|
||||
(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
|
||||
(:redo-changes changes)
|
||||
@@ -850,10 +856,26 @@
|
||||
|
||||
check-changes
|
||||
(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))
|
||||
#{}
|
||||
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?)
|
||||
(log/info :msg "DETECTED COMPONENTS CHANGED"
|
||||
:ids (map str components-changed))
|
||||
@@ -861,11 +883,12 @@
|
||||
(map #(update-component-sync % (:id data))
|
||||
components-changed)))))]
|
||||
|
||||
(when components-v2
|
||||
(->> change-s
|
||||
(rx/with-latest-from workspace-data-s)
|
||||
(rx/map check-changes)
|
||||
(rx/take-until stopper)))))))
|
||||
;; (when components-v2
|
||||
;; (->> change-s
|
||||
;; (rx/with-latest-from workspace-data-s)
|
||||
;; (rx/map check-changes)
|
||||
;; (rx/take-until stopper)))
|
||||
))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Backend interactions
|
||||
@@ -898,6 +921,7 @@
|
||||
(let [state (dissoc state :files)]
|
||||
(assoc state :workspace-shared-files files)))))
|
||||
|
||||
|
||||
(defn fetch-shared-files
|
||||
[{:keys [team-id] :as params}]
|
||||
(us/assert ::us/uuid team-id)
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
(defn generate-instantiate-component
|
||||
"Generate changes to create a new instance from a component."
|
||||
[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]
|
||||
(ctn/make-component-instance page component file-id position)
|
||||
@@ -191,7 +191,7 @@
|
||||
asset-id
|
||||
library-id
|
||||
state
|
||||
(cph/make-container page :page)
|
||||
(ctn/make-container page :page)
|
||||
components-v2)))
|
||||
changes))))
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
asset-id
|
||||
library-id
|
||||
state
|
||||
(cph/make-container local-component :component)
|
||||
(ctn/make-container local-component :component)
|
||||
components-v2)))
|
||||
changes))))
|
||||
|
||||
@@ -236,7 +236,7 @@
|
||||
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]
|
||||
|
||||
(if (cph/page? container)
|
||||
(if (ctn/page? 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)))
|
||||
|
||||
@@ -451,7 +451,7 @@
|
||||
[changes libraries container shape-id reset? components-v2]
|
||||
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
|
||||
(let [shape-inst (ctn/get-shape container shape-id)
|
||||
component (cph/get-component libraries
|
||||
component (ctf/get-component libraries
|
||||
(:component-file shape-inst)
|
||||
(:component-id shape-inst))
|
||||
component (or component
|
||||
@@ -588,7 +588,7 @@
|
||||
[changes libraries container shape-id]
|
||||
(log/debug :msg "Sync shape inverse" :shape (str 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-id shape-inst))
|
||||
shape-main (ctn/get-shape component (:shape-ref shape-inst))
|
||||
@@ -618,7 +618,7 @@
|
||||
(if (nil? shape-main)
|
||||
;; This should not occur, but protect against it in any case
|
||||
changes
|
||||
(let [component-container (cph/make-container component :component)
|
||||
(let [component-container (ctn/make-container component :component)
|
||||
|
||||
omit-touched? false
|
||||
set-remote-synced? (not initial-root?)
|
||||
@@ -825,7 +825,7 @@
|
||||
:shapes all-parents}))
|
||||
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')))
|
||||
|
||||
@@ -908,7 +908,7 @@
|
||||
(defn- remove-shape
|
||||
[changes shape container omit-touched?]
|
||||
(log/info :msg (str "REMOVE-SHAPE "
|
||||
(if (cph/page? container) "[P] " "[C] ")
|
||||
(if (ctn/page? container) "[P] " "[C] ")
|
||||
(:name shape)))
|
||||
(let [objects (get container :objects)
|
||||
parents (cph/get-parent-ids objects (:id shape))
|
||||
@@ -946,14 +946,14 @@
|
||||
changes'
|
||||
(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')))
|
||||
|
||||
(defn- move-shape
|
||||
[changes shape index-before index-after container omit-touched?]
|
||||
(log/info :msg (str "MOVE "
|
||||
(if (cph/page? container) "[P] " "[C] ")
|
||||
(if (ctn/page? container) "[P] " "[C] ")
|
||||
(:name shape)
|
||||
" "
|
||||
index-before
|
||||
@@ -977,7 +977,7 @@
|
||||
:index index-before
|
||||
: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')))
|
||||
|
||||
@@ -989,7 +989,7 @@
|
||||
changes
|
||||
(do
|
||||
(log/info :msg (str "CHANGE-TOUCHED "
|
||||
(if (cph/page? container) "[P] " "[C] ")
|
||||
(if (ctn/page? container) "[P] " "[C] ")
|
||||
(:name dest-shape))
|
||||
:options options)
|
||||
(let [new-touched (cond
|
||||
@@ -1024,7 +1024,7 @@
|
||||
changes
|
||||
(do
|
||||
(log/info :msg (str "CHANGE-REMOTE-SYNCED? "
|
||||
(if (cph/page? container) "[P] " "[C] ")
|
||||
(if (ctn/page? container) "[P] " "[C] ")
|
||||
(:name shape))
|
||||
:remote-synced? remote-synced?)
|
||||
(-> changes
|
||||
@@ -1054,7 +1054,7 @@
|
||||
(log/info :msg (str "SYNC "
|
||||
(:name origin-shape)
|
||||
" -> "
|
||||
(if (cph/page? container) "[P] " "[C] ")
|
||||
(if (ctn/page? container) "[P] " "[C] ")
|
||||
(:name dest-shape)))
|
||||
|
||||
(let [; To synchronize geometry attributes we need to make a prior
|
||||
@@ -1133,7 +1133,7 @@
|
||||
|
||||
(defn- make-change
|
||||
[container change]
|
||||
(if (cph/page? container)
|
||||
(if (ctn/page? container)
|
||||
(assoc change :page-id (:id container))
|
||||
(assoc change :component-id (:id container))))
|
||||
|
||||
|
||||
@@ -10,11 +10,15 @@
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[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.pages.common :as cpc]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[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.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
@@ -27,6 +31,291 @@
|
||||
[cljs.spec.alpha :as s]
|
||||
[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 -------------------------------------------
|
||||
|
||||
;; During an interactive transformation of shapes (e.g. when resizing or rotating
|
||||
@@ -54,7 +343,7 @@
|
||||
shape
|
||||
|
||||
(nil? root)
|
||||
(cph/get-root-shape objects shape)
|
||||
(ctn/get-root-shape objects shape)
|
||||
|
||||
:else root)
|
||||
|
||||
@@ -64,7 +353,7 @@
|
||||
transformed-shape
|
||||
|
||||
(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 $)))))
|
||||
|
||||
:else transformed-root)
|
||||
@@ -235,12 +524,26 @@
|
||||
(wsh/lookup-page-objects state)
|
||||
|
||||
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 $
|
||||
(apply-text-modifiers $ (get state :workspace-text-modifier))
|
||||
;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path]))
|
||||
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?)))))
|
||||
modif-tree
|
||||
(as-> objects $
|
||||
(apply-text-modifiers $ (get state :workspace-text-modifier))
|
||||
;;(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
|
||||
([modif-tree]
|
||||
@@ -264,7 +567,7 @@
|
||||
(ptk/reify ::set-rotation-modifiers
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
ids
|
||||
(->> shapes
|
||||
(remove #(get % :blocked false))
|
||||
@@ -277,11 +580,23 @@
|
||||
|
||||
modif-tree
|
||||
(-> (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))))))
|
||||
|
||||
|
||||
(defn apply-modifiers
|
||||
([]
|
||||
(apply-modifiers nil))
|
||||
@@ -301,25 +616,27 @@
|
||||
shapes (map (d/getf objects) ids)
|
||||
ignore-tree (->> (map #(get-ignore-tree object-modifiers objects %) shapes)
|
||||
(reduce merge {}))
|
||||
undo-id (uuid/next)]
|
||||
undo-id (uuid/next)
|
||||
|
||||
(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
|
||||
(fn [shape]
|
||||
(let [modif (get-in object-modifiers [(:id shape) :modifiers])
|
||||
text-shape? (cph/text-shape? shape)]
|
||||
(-> shape
|
||||
(gsh/transform-shape modif)
|
||||
(cond-> text-shape?
|
||||
(update-grow-type shape)))))
|
||||
{:reg-objects? true
|
||||
update-fn
|
||||
(fn [shape]
|
||||
(let [modif (get-in object-modifiers [(:id shape) :modifiers])
|
||||
text-shape? (cph/text-shape? shape)]
|
||||
(-> shape
|
||||
(gsh/transform-shape modif)
|
||||
(cond-> text-shape?
|
||||
(update-grow-type shape)))))
|
||||
|
||||
ignore-touched-fn
|
||||
(fn [shape-id]
|
||||
;; When a modifier comes from copying a main component to copies,
|
||||
;; do not set the touched flag, because this change is synced.
|
||||
(let [modif (get-in object-modifiers [shape-id :modifiers])]
|
||||
(:copied-modifier? (meta modif))))
|
||||
|
||||
opts {:reg-objects? true
|
||||
: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
|
||||
;; all the attributes
|
||||
:attrs [:selrect
|
||||
@@ -336,8 +653,15 @@
|
||||
:flip-y
|
||||
:grow-type
|
||||
: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))
|
||||
(if undo-transation?
|
||||
(rx/of (dwu/commit-undo-transaction undo-id))
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.page :as ctp]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
@@ -159,7 +160,7 @@
|
||||
;; not the root. In this case, they must not be deleted,
|
||||
;; but hidden (to be able to recover them more easily).
|
||||
(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)
|
||||
(not= shape component-shape)
|
||||
(not (ctk/main-instance? component-shape)))))
|
||||
|
||||
@@ -14,14 +14,19 @@
|
||||
[app.common.geom.shapes.flex-layout :as gsl]
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages.changes-builder :as pcb]
|
||||
[app.common.pages.common :as cpc]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[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.shape-tree :as ctst]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[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.selection :as dws]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
@@ -97,7 +102,6 @@
|
||||
(update [_ state]
|
||||
(update state :workspace-local dissoc :transform))))
|
||||
|
||||
|
||||
;; -- Resize --------------------------------------------------------
|
||||
|
||||
(defn start-resize
|
||||
|
||||
@@ -11,12 +11,18 @@
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[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.main.data.workspace.transforms :as dwt]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.hooks :as hooks]
|
||||
[app.main.ui.workspace.viewport.utils :as vwu]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :as globals]
|
||||
[app.util.timers :as tm]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(defn get-shape-node
|
||||
@@ -190,14 +196,230 @@
|
||||
(-> modifiers
|
||||
(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
|
||||
[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/deps modifiers)
|
||||
(fn []
|
||||
(when (some? modifiers)
|
||||
;; (js/console.log "****modifiers" (clj->js modifiers))
|
||||
(when (seq modifiers)
|
||||
(d/mapm (fn [id {modifiers :modifiers}]
|
||||
(let [shape (get objects id)
|
||||
adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? modifiers)))
|
||||
@@ -213,13 +435,195 @@
|
||||
(mf/use-memo
|
||||
(mf/deps transforms)
|
||||
(fn []
|
||||
;; (js/console.log "transforms" (clj->js transforms))
|
||||
(->> (keys transforms)
|
||||
(filter #(some? (get transforms %)))
|
||||
(mapv (d/getf objects)))))
|
||||
|
||||
prev-shapes (mf/use-var nil)
|
||||
prev-modifiers (mf/use-var nil)
|
||||
prev-transforms (mf/use-var nil)]
|
||||
;; $$$
|
||||
;; transforms
|
||||
;; (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/deps add-children)
|
||||
@@ -265,6 +669,8 @@
|
||||
(when (d/not-empty? removed-shapes)
|
||||
(remove-transform! node @prev-shapes)))
|
||||
|
||||
(reset! prev-modifiers modifiers)
|
||||
(reset! prev-transforms transforms)
|
||||
(reset! prev-shapes shapes)))))
|
||||
(reset! prev-modifiers modifiers)
|
||||
(reset! prev-transforms transforms)
|
||||
(reset! prev-shapes shapes)
|
||||
;; (reset! prev-copies copies)
|
||||
))))
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[cljs.test :as t :include-macros true]
|
||||
@@ -91,7 +92,7 @@
|
||||
root-inst (ctn/get-shape page root-inst-id)
|
||||
|
||||
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-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||
@@ -100,10 +101,10 @@
|
||||
|
||||
main-exists? (fn [shape]
|
||||
(let [component-shape
|
||||
(cph/get-component-shape (:objects page) shape)
|
||||
(ctn/get-component-shape (:objects page) shape)
|
||||
|
||||
component
|
||||
(cph/get-component libs (:component-id component-shape))
|
||||
(ctf/get-component libs (:component-id component-shape))
|
||||
|
||||
main-shape
|
||||
(ctn/get-shape component (:shape-ref shape))]
|
||||
@@ -131,7 +132,7 @@
|
||||
root-inst (ctn/get-shape page root-inst-id)
|
||||
|
||||
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-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||
@@ -140,10 +141,10 @@
|
||||
|
||||
main-exists? (fn [shape]
|
||||
(let [component-shape
|
||||
(cph/get-component-shape (:objects page) shape)
|
||||
(ctn/get-component-shape (:objects page) shape)
|
||||
|
||||
component
|
||||
(cph/get-component libs (:component-id component-shape))
|
||||
(ctf/get-component libs (:component-id component-shape))
|
||||
|
||||
main-shape
|
||||
(ctn/get-shape component (:shape-ref shape))]
|
||||
@@ -160,7 +161,7 @@
|
||||
[state component-id]
|
||||
(let [page (thp/current-page 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)
|
||||
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
|
||||
|
||||
|
||||
@@ -302,7 +302,7 @@
|
||||
; Renamed component
|
||||
; Rect-1
|
||||
(let [libs (wsh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
component (ctf/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
(t/is (= (:name component)
|
||||
@@ -400,7 +400,7 @@
|
||||
(:id instance1))
|
||||
|
||||
libs (wsh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
component (ctf/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user