♻️ Move component instantiation to new types module

This commit is contained in:
Andrés Moya 2022-06-28 11:05:45 +02:00
parent 5dc7bc213f
commit bdcbe46d0d
39 changed files with 542 additions and 409 deletions

View file

@ -10,6 +10,7 @@
[app.common.geom.point :as gpt]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.shape-tree :as ctt]
[app.common.types.shape.interactions :as ctsi]
[app.main.data.comments :as dcm]
[app.main.data.fonts :as df]
@ -116,8 +117,8 @@
(map (fn [page-id]
(let [data (get-in file [:data :pages-index page-id])]
[page-id (assoc data
:frames (cph/get-viewer-frames (:objects data))
:all-frames (cph/get-viewer-frames (:objects data) {:all-frames? true}))])))
:frames (ctt/get-viewer-frames (:objects data))
:all-frames (ctt/get-viewer-frames (:objects data) {:all-frames? true}))])))
(into {}))]
(ptk/reify ::bundle-fetched

View file

@ -21,6 +21,7 @@
[app.common.text :as txt]
[app.common.transit :as t]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[app.config :as cfg]
[app.main.data.events :as ev]
@ -59,7 +60,6 @@
[app.util.globals :as ug]
[app.util.http :as http]
[app.util.i18n :as i18n]
[app.util.names :as un]
[app.util.router :as rt]
[app.util.timers :as tm]
[app.util.webapi :as wapi]
@ -157,7 +157,7 @@
:workspace-project project
:workspace-file (assoc file :initialized true)
:workspace-data (-> (:data file)
(cph/start-object-indices)
(ctst/start-object-indices)
;; DEBUG: Uncomment this to try out migrations in local without changing
;; the version number
#_(assoc :version 17)
@ -270,8 +270,8 @@
ptk/WatchEvent
(watch [it state _]
(let [pages (get-in state [:workspace-data :pages-index])
unames (un/retrieve-used-names pages)
name (un/generate-unique-name unames "Page-1")
unames (ctst/retrieve-used-names pages)
name (ctst/generate-unique-name unames "Page-1")
changes (-> (pcb/empty-changes it)
(pcb/add-empty-page id name))]
@ -285,9 +285,9 @@
(watch [it state _]
(let [id (uuid/next)
pages (get-in state [:workspace-data :pages-index])
unames (un/retrieve-used-names pages)
unames (ctst/retrieve-used-names pages)
page (get-in state [:workspace-data :pages-index page-id])
name (un/generate-unique-name unames (:name page))
name (ctst/generate-unique-name unames (:name page))
no_thumbnails_objects (->> (:objects page)
(d/mapm (fn [_ val] (dissoc val :use-for-thumbnail?))))
@ -991,7 +991,7 @@
(let [selected (wsh/lookup-selected state)
pages (-> state :workspace-data :pages-index vals)
get-frames (fn [{:keys [objects id] :as page}]
(->> (cph/get-frames objects)
(->> (ctst/get-frames objects)
(sequence
(comp (filter :use-for-thumbnail?)
(map :id)
@ -1223,7 +1223,7 @@
;; selected and its parents
objects (cph/selected-subtree objects selected)
selected (->> (cph/sort-z-index objects selected)
selected (->> (ctst/sort-z-index objects selected)
(into (d/ordered-set)))]
(assoc data :selected selected)))
@ -1478,7 +1478,7 @@
[frame-id frame-id delta])
(empty? page-selected)
(let [frame-id (cph/frame-id-by-position page-objects mouse-pos)
(let [frame-id (ctst/frame-id-by-position page-objects mouse-pos)
delta (gpt/subtract mouse-pos orig-pos)]
[frame-id frame-id delta])
@ -1590,7 +1590,7 @@
height 16
page-id (:current-page-id state)
frame-id (-> (wsh/lookup-page-objects state page-id)
(cph/frame-id-by-position @ms/mouse-position))
(ctst/frame-id-by-position @ms/mouse-position))
shape (cp/setup-rect-selrect
{:id id
:type :text

View file

@ -11,11 +11,11 @@
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.path.shapes-to-path :as stp]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh]
[app.util.names :as un]
[beicon.core :as rx]
[cuerdas.core :as str]
[potok.core :as ptk]))
@ -90,8 +90,8 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state)
base-name (-> bool-type d/name str/capital (str "-1"))
name (-> (un/retrieve-used-names objects)
(un/generate-unique-name base-name))
name (-> (ctt/retrieve-used-names objects)
(ctt/generate-unique-name base-name))
shapes (selected-shapes state)]
(when-not (empty? shapes)

View file

@ -13,6 +13,7 @@
[app.common.pages.changes-spec :as pcs]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.data.workspace.undo :as dwu]
@ -165,7 +166,7 @@
(update-in state path (fn [file]
(-> file
(cp/process-changes redo-changes false)
(cph/update-object-indices page-id))))
(ctst/update-object-indices page-id))))
(catch :default err
(log/error :js/error err)

View file

@ -7,6 +7,15 @@
(ns app.main.data.workspace.common
(:require
[app.common.logging :as log]
[app.common.pages :as cp]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.page :as ctp]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctt]
[app.common.types.shape.interactions :as ctsi]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.undo :as dwu]
[app.main.worker :as uw]

View file

@ -11,6 +11,7 @@
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]
[app.main.data.workspace.drawing.common :as common]
[app.main.data.workspace.state-helpers :as wsh]
@ -65,7 +66,7 @@
focus (:workspace-focus-selected state)
zoom (get-in state [:workspace-local :zoom] 1)
fid (cph/frame-id-by-position objects initial)
fid (ctt/frame-id-by-position objects initial)
shape (get-in state [:workspace-drawing :object])
shape (-> shape

View file

@ -8,7 +8,7 @@
(:require
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.main.data.workspace.drawing.common :as common]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms]
@ -47,7 +47,7 @@
(let [objects (wsh/lookup-page-objects state)
content (get-in state [:workspace-drawing :object :content] [])
position (get-in content [0 :params] nil)
frame-id (cph/frame-id-by-position objects position)]
frame-id (ctt/frame-id-by-position objects position)]
(-> state
(assoc-in [:workspace-drawing :object :frame-id] frame-id))))))

View file

@ -11,10 +11,10 @@
[app.common.pages :as cp]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.state-helpers :as wsh]
[app.util.names :as un]
[beicon.core :as rx]
[potok.core :as ptk]))
@ -71,8 +71,8 @@
(= (count shapes) 1)
(= (:type (first shapes)) :group))
(:name (first shapes))
(-> (un/retrieve-used-names objects)
(un/generate-unique-name base-name)))
(-> (ctt/retrieve-used-names objects)
(ctt/generate-unique-name base-name)))
selrect (gsh/selection-rect shapes)
group (-> (cp/make-minimal-group frame-id selrect gname)

View file

@ -12,12 +12,12 @@
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.page :as ctp]
[app.common.types.shape-tree :as ctst]
[app.common.types.shape.interactions :as ctsi]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms]
[app.util.names :as un]
[beicon.core :as rx]
[potok.core :as ptk]))
@ -32,7 +32,7 @@
flows (get-in page [:options :flows] [])
unames (into #{} (map :name flows))
name (un/generate-unique-name unames "Flow-1")
name (ctst/generate-unique-name unames "Flow-1")
new-flow {:id (uuid/next)
:name name
@ -182,7 +182,7 @@
from-frame-id (if (cph/frame-shape? from-shape)
from-id (:frame-id from-shape))
target-frame (cph/frame-by-position objects position)]
target-frame (ctst/frame-by-position objects position)]
(when (and (not= (:id target-frame) uuid/zero)
(not= (:id target-frame) from-frame-id)

View file

@ -15,7 +15,9 @@
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.color :as ctc]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]
[app.common.types.shape-tree :as ctst]
[app.common.types.typography :as ctt]
[app.common.uuid :as uuid]
[app.main.data.dashboard :as dd]
@ -30,7 +32,6 @@
[app.main.repo :as rp]
[app.main.store :as st]
[app.util.i18n :refer [tr]]
[app.util.names :as un]
[app.util.router :as rt]
[app.util.time :as dt]
[beicon.core :as rx]
@ -352,7 +353,7 @@
component (cph/get-component libraries id)
all-components (-> state :workspace-data :components vals)
unames (into #{} (map :name) all-components)
new-name (un/generate-unique-name unames (:name component))
new-name (ctst/generate-unique-name unames (:name component))
[new-shape new-shapes _updated-shapes main-instance main-instance-page]
(dwlh/duplicate-component component)
@ -525,7 +526,7 @@
libraries (wsh/get-libraries state)
container (cph/get-container local-file :page page-id)
shape (cph/get-shape container id)
shape (ctn/get-shape container id)
changes
(-> (pcb/empty-changes it)

View file

@ -16,9 +16,10 @@
[app.common.spec :as us]
[app.common.text :as txt]
[app.common.types.color :as ctc]
[app.common.types.container :as ctn]
[app.common.types.shape-tree :as ctst]
[app.main.data.workspace.groups :as dwg]
[app.main.data.workspace.state-helpers :as wsh]
[app.util.names :as un]
[cljs.spec.alpha :as s]
[clojure.set :as set]))
@ -93,7 +94,7 @@
(some? (:parent-id new-shape))
(dissoc :component-root?)))]
(cph/clone-object shape nil objects update-new-shape update-original-shape)))
(ctst/clone-object shape nil objects update-new-shape update-original-shape)))
(defn generate-add-component
"If there is exactly one id, and it's a group, use it as root. Otherwise,
@ -131,7 +132,7 @@
ids from all of them."
[component]
(let [component-root (cph/get-component-root component)]
(cph/clone-object component-root
(ctst/clone-object component-root
nil
(get component :objects)
identity)))
@ -140,49 +141,9 @@
"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)
component-shape (cph/get-shape component component-id)
orig-pos (gpt/point (:x component-shape) (:y component-shape))
delta (gpt/subtract position orig-pos)
objects (:objects page)
unames (volatile! (un/retrieve-used-names objects))
frame-id (cph/frame-id-by-position objects (gpt/add orig-pos delta))
update-new-shape
(fn [new-shape original-shape]
(let [new-name (un/generate-unique-name @unames (:name new-shape))]
(when (nil? (:parent-id original-shape))
(vswap! unames conj new-name))
(cond-> new-shape
true
(as-> $
(gsh/move $ delta)
(assoc $ :frame-id frame-id)
(assoc $ :parent-id
(or (:parent-id $) (:frame-id $)))
(dissoc $ :touched))
(nil? (:shape-ref original-shape))
(assoc :shape-ref (:id original-shape))
(nil? (:parent-id original-shape))
(assoc :component-id (:id original-shape)
:component-file file-id
:component-root? true
:name new-name)
(some? (:parent-id original-shape))
(dissoc :component-root?))))
[new-shape new-shapes _]
(cph/clone-object component-shape
nil
(get component :objects)
update-new-shape)
[new-shape new-shapes]
(ctn/instantiate-component page component file-id position)
changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true})
(pcb/empty-changes it (:id page))
@ -484,12 +445,12 @@
instance, and all its children, from the given component."
[changes libraries container shape-id reset?]
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
(let [shape-inst (cph/get-shape container shape-id)
(let [shape-inst (ctn/get-shape container shape-id)
component (cph/get-component libraries
(:component-file shape-inst)
(:component-id shape-inst))
shape-main (when component
(cph/get-shape component (:shape-ref shape-inst)))
(ctn/get-shape component (:shape-ref shape-inst)))
initial-root? (:component-root? shape-inst)
@ -545,9 +506,9 @@
set-remote-synced?
(change-remote-synced shape-inst container true))
children-inst (mapv #(cph/get-shape container %)
children-inst (mapv #(ctn/get-shape container %)
(:shapes shape-inst))
children-main (mapv #(cph/get-shape component %)
children-main (mapv #(ctn/get-shape component %)
(:shapes shape-main))
only-inst (fn [changes child-inst]
@ -610,11 +571,11 @@
the values in the shape and all its children."
[changes libraries container shape-id]
(log/debug :msg "Sync shape inverse" :shape (str shape-id))
(let [shape-inst (cph/get-shape container shape-id)
(let [shape-inst (ctn/get-shape container shape-id)
component (cph/get-component libraries
(:component-file shape-inst)
(:component-id shape-inst))
shape-main (cph/get-shape component (:shape-ref shape-inst))
shape-main (ctn/get-shape component (:shape-ref shape-inst))
initial-root? (:component-root? shape-inst)
@ -670,9 +631,9 @@
set-remote-synced?
(change-remote-synced shape-inst container true))
children-inst (mapv #(cph/get-shape container %)
children-inst (mapv #(ctn/get-shape container %)
(:shapes shape-inst))
children-main (mapv #(cph/get-shape component %)
children-main (mapv #(ctn/get-shape component %)
(:shapes shape-main))
only-inst (fn [changes child-inst]
@ -787,7 +748,7 @@
(defn- add-shape-to-instance
[changes component-shape index component container root-instance root-main omit-touched? set-remote-synced?]
(log/info :msg (str "ADD [P] " (:name component-shape)))
(let [component-parent-shape (cph/get-shape component (:parent-id component-shape))
(let [component-parent-shape (ctn/get-shape component (:parent-id component-shape))
parent-shape (d/seek #(cph/is-main-of? component-parent-shape %)
(cph/get-children-with-self (:objects container)
(:id root-instance)))
@ -813,7 +774,7 @@
original-shape)
[_ new-shapes _]
(cph/clone-object component-shape
(ctst/clone-object component-shape
(:id parent-shape)
(get component :objects)
update-new-shape
@ -855,7 +816,7 @@
(defn- add-shape-to-main
[changes shape index component page root-instance root-main]
(log/info :msg (str "ADD [C] " (:name shape)))
(let [parent-shape (cph/get-shape page (:parent-id shape))
(let [parent-shape (ctn/get-shape page (:parent-id shape))
component-parent-shape (d/seek #(cph/is-main-of? % parent-shape)
(cph/get-children-with-self (:objects component)
(:id root-main)))
@ -875,7 +836,7 @@
original-shape))
[_new-shape new-shapes updated-shapes]
(cph/clone-object shape
(ctst/clone-object shape
(:id component-parent-shape)
(get page :objects)
update-new-shape
@ -982,7 +943,7 @@
index-before
" -> "
index-after))
(let [parent (cph/get-shape container (:parent-id shape))
(let [parent (ctn/get-shape container (:parent-id shape))
changes' (-> changes
(update :redo-changes conj (make-change

View file

@ -8,10 +8,10 @@
(:require
[app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as upg]
[app.common.pages.helpers :as cph]
[app.common.path.commands :as upc]
[app.common.path.shapes-to-path :as upsp]
[app.common.spec :as us]
[app.common.types.shape-tree :as ctt]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.drawing.common :as dwdc]
[app.main.data.workspace.edition :as dwe]
@ -258,7 +258,7 @@
(let [objects (wsh/lookup-page-objects state)
content (get-in state [:workspace-drawing :object :content] [])
position (get-in content [0 :params] nil)
frame-id (cph/frame-id-by-position objects position)]
frame-id (ctt/frame-id-by-position objects position)]
(-> state
(assoc-in [:workspace-drawing :object :frame-id] frame-id))))))

View file

@ -15,6 +15,7 @@
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.page :as ctp]
[app.common.types.shape-tree :as ctt]
[app.common.types.shape.interactions :as ctsi]
[app.common.uuid :as uuid]
[app.main.data.modal :as md]
@ -26,7 +27,6 @@
[app.main.refs :as refs]
[app.main.streams :as ms]
[app.main.worker :as uw]
[app.util.names :as un]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[clojure.set :as set]
@ -284,7 +284,7 @@
move to the desired position, and recalculate parents and frames as needed."
[all-objects page ids delta it]
(let [shapes (map (d/getf all-objects) ids)
unames (volatile! (un/retrieve-used-names (:objects page)))
unames (volatile! (ctt/retrieve-used-names (:objects page)))
update-unames! (fn [new-name] (vswap! unames conj new-name))
all-ids (reduce #(into %1 (cons %2 (cph/get-children-ids all-objects %2))) (d/ordered-set) ids)
ids-map (into {} (map #(vector % (uuid/next))) all-ids)
@ -319,7 +319,7 @@
(defn- prepare-duplicate-frame-change
[changes objects page unames update-unames! ids-map obj delta]
(let [new-id (ids-map (:id obj))
frame-name (un/generate-unique-name @unames (:name obj))
frame-name (ctt/generate-unique-name @unames (:name obj))
_ (update-unames! frame-name)
new-frame (-> obj
@ -354,7 +354,7 @@
(if (some? obj)
(let [new-id (ids-map (:id obj))
parent-id (or parent-id frame-id)
name (un/generate-unique-name @unames (:name obj))
name (ctt/generate-unique-name @unames (:name obj))
_ (update-unames! name)
new-obj (-> obj
@ -395,7 +395,7 @@
(let [update-flows (fn [flows]
(reduce
(fn [flows frame]
(let [name (un/generate-unique-name @unames "Flow-1")
(let [name (ctt/generate-unique-name @unames "Flow-1")
_ (vswap! unames conj name)
new-flow {:id (uuid/next)
:name name

View file

@ -16,6 +16,7 @@
[app.common.types.page :as csp]
[app.common.types.shape :as spec.shape]
[app.common.types.shape.interactions :as csi]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.edition :as dwe]
@ -23,7 +24,6 @@
[app.main.data.workspace.shape-layout :as dwsl]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms]
[app.util.names :as un]
[beicon.core :as rx]
[cljs.spec.alpha :as s]
[potok.core :as ptk]))
@ -84,8 +84,8 @@
id (or (:id attrs) (uuid/next))
name (-> objects
(un/retrieve-used-names)
(un/generate-unique-name (:name attrs)))
(ctst/retrieve-used-names)
(ctst/generate-unique-name (:name attrs)))
shape (make-new-shape
(assoc attrs :id id :name name)

View file

@ -13,15 +13,14 @@
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.spec :refer [max-safe-int min-safe-int]]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.selection :as dws]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.state-helpers :as wsh]
[app.util.color :as uc]
[app.util.names :as un]
[app.util.path.parser :as upp]
[app.util.svg :as usvg]
[beicon.core :as rx]
@ -360,7 +359,7 @@
(let [{:keys [tag attrs hidden]} element-data
attrs (usvg/format-styles attrs)
element-data (cond-> element-data (map? element-data) (assoc :attrs attrs))
name (un/generate-unique-name unames (or (:id attrs) (tag->name tag)))
name (ctt/generate-unique-name unames (or (:id attrs) (tag->name tag)))
att-refs (usvg/find-attr-references attrs)
references (usvg/find-def-references (:defs svg-data) att-refs)
@ -437,17 +436,17 @@
(try
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
frame-id (cph/frame-id-by-position objects position)
frame-id (ctt/frame-id-by-position objects position)
selected (wsh/lookup-selected state)
[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
x (- x vb-x (/ vb-width 2))
y (- y vb-y (/ vb-height 2))
unames (un/retrieve-used-names objects)
unames (ctt/retrieve-used-names objects)
svg-name (->> (str/replace (:name svg-data) ".svg" "")
(un/generate-unique-name unames))
(ctt/generate-unique-name unames))
svg-data (-> svg-data
(assoc :x x

View file

@ -16,6 +16,7 @@
[app.common.pages.common :as cpc]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.shape-tree :as ctt]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.collapse :as dwc]
[app.main.data.workspace.guides :as dwg]
@ -752,7 +753,7 @@
(let [position @ms/mouse-position
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
frame-id (cph/frame-id-by-position objects position)
frame-id (ctt/frame-id-by-position objects position)
moving-shapes
(->> ids

View file

@ -10,6 +10,7 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.store :as st]
[okulary.core :as l]))
@ -284,7 +285,7 @@
(l/derived :options workspace-page))
(def workspace-frames
(l/derived cph/get-frames workspace-page-objects =))
(l/derived ctt/get-frames workspace-page-objects =))
(def workspace-editor
(l/derived :workspace-editor st/state))

View file

@ -21,6 +21,7 @@
[app.common.geom.shapes.bounds :as gsb]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]
[app.config :as cfg]
[app.main.fonts :as fonts]
[app.main.ui.context :as muc]
@ -61,7 +62,7 @@
(defn- calculate-dimensions
[objects]
(let [bounds
(->> (cph/get-root-objects objects)
(->> (ctst/get-root-objects objects)
(map (partial gsb/get-object-bounds objects))
(gsh/join-rects))]
(-> bounds

View file

@ -10,6 +10,7 @@
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.types.page :as ctp]
[app.common.types.shape-tree :as ctt]
[app.common.types.shape.interactions :as ctsi]
[app.common.uuid :as uuid]
[app.main.data.workspace :as dw]
@ -182,7 +183,7 @@
(let [objects (deref refs/workspace-page-objects)
destination (get objects (:destination interaction))
frames (mf/with-memo [objects] (cph/get-viewer-frames objects {:all-frames? (not= :navigate (:action-type interaction))}))
frames (mf/with-memo [objects] (ctt/get-viewer-frames objects {:all-frames? (not= :navigate (:action-type interaction))}))
overlay-pos-type (:overlay-pos-type interaction)
close-click-outside? (:close-click-outside interaction false)

View file

@ -9,7 +9,7 @@
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[app.main.refs :as refs]
[app.util.geom.grid :as gg]
@ -134,7 +134,7 @@
[:g.grid-display {:style {:pointer-events "none"}}
(for [frame frames]
(when (and (not (is-transform? frame))
(not (cph/rotated-frame? frame))
(not (ctst/rotated-frame? frame))
(or (empty? focus) (contains? focus (:id frame))))
[:& grid-display-frame {:key (str "grid-" (:id frame))
:zoom zoom

View file

@ -11,6 +11,7 @@
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[app.main.data.workspace :as dw]
[app.main.refs :as refs]
@ -292,7 +293,7 @@
(when (or (nil? frame)
(and (cph/root-frame? frame)
(not (cph/rotated-frame? frame))))
(not (ctst/rotated-frame? frame))))
[:g.guide-area {:opacity (when frame-guide-outside? 0)}
(when-not disabled-guides?
(let [{:keys [x y width height]} (guide-area-axis pos vbox zoom frame axis)]

View file

@ -10,6 +10,7 @@
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.main.data.shortcuts :as dsc]
[app.main.data.workspace :as dw]
[app.main.data.workspace.path.shortcuts :as psc]
@ -183,7 +184,7 @@
ids (into
(d/ordered-set)
(cph/sort-z-index objects ids {:bottom-frames? mod?}))
(ctt/sort-z-index objects ids {:bottom-frames? mod?}))
grouped? (fn [id] (contains? #{:group :bool} (get-in objects [id :type])))
@ -218,7 +219,7 @@
(let [root-frame-ids
(mf/use-memo
(mf/deps objects)
#(cph/get-root-shapes-ids objects))
#(ctt/get-root-shapes-ids objects))
modifiers (select-keys modifiers root-frame-ids)]
(sfd/use-dynamic-modifiers objects globals/document modifiers)))
@ -229,7 +230,7 @@
(defn setup-active-frames
[objects hover-ids selected active-frames zoom transform vbox]
(let [all-frames (mf/use-memo (mf/deps objects) #(cph/get-root-frames-ids objects))
(let [all-frames (mf/use-memo (mf/deps objects) #(ctt/get-root-frames-ids objects))
selected-frames (mf/use-memo (mf/deps selected) #(->> all-frames (filter selected)))
xf-selected-frame (comp (remove cph/root-frame?)

View file

@ -10,7 +10,7 @@
[app.common.data.macros :as dm]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]
[app.main.data.workspace :as dw]
[app.main.data.workspace.interactions :as dwi]
@ -178,7 +178,7 @@
on-frame-enter (unchecked-get props "on-frame-enter")
on-frame-leave (unchecked-get props "on-frame-leave")
on-frame-select (unchecked-get props "on-frame-select")
frames (cph/get-frames objects)]
frames (ctt/get-frames objects)]
[:g.frame-titles
(for [frame frames]

View file

@ -8,7 +8,8 @@
(:require
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]))
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]))
(defn selrect-snap-points [{:keys [x y width height] :as selrect}]
#{(gpt/point x y)
@ -38,7 +39,7 @@
(cond
(and (some? frame)
(not (cph/rotated-frame? frame))
(not (ctst/rotated-frame? frame))
(not (cph/root-frame? frame)))
#{}

View file

@ -1,38 +0,0 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) UXBOX Labs SL
(ns app.util.names
(:require
[app.common.data :as d]
[app.common.spec :as us]
[cljs.spec.alpha :as s]))
(s/def ::set-of-string (s/every string? :kind set?))
(defn- extract-numeric-suffix
[basename]
(if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
[p1 (+ 1 (d/parse-integer p2))]
[basename 1]))
(defn retrieve-used-names
[objects]
(into #{} (comp (map :name) (remove nil?)) (vals objects)))
(defn generate-unique-name
"A unique name generator"
[used basename]
(s/assert ::set-of-string used)
(s/assert ::us/string basename)
(if-not (contains? used basename)
basename
(let [[prefix initial] (extract-numeric-suffix basename)]
(loop [counter initial]
(let [candidate (str prefix "-" counter)]
(if (contains? used candidate)
(recur (inc counter))
candidate))))))

View file

@ -12,6 +12,7 @@
[app.common.data :as d]
[app.common.pages.diff :as diff]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[app.util.geom.grid :as gg]
[app.util.geom.snap-points :as snap]
@ -55,7 +56,7 @@
(defn get-grids-snap-points
[frame coord]
(if (not (cph/rotated-frame? frame))
(if (not (ctst/rotated-frame? frame))
[]
(let [grid->snap (fn [[grid-type position]]
{:type :layout
@ -196,7 +197,7 @@
(defn add-page
"Adds page information"
[snap-data {:keys [objects options] :as page}]
(let [frames (cph/get-frames objects)
(let [frames (ctst/get-frames objects)
shapes (->> (vals (:objects page))
(remove cph/frame-shape?))
guides (vals (:guides options))