♻️ Refactor common.page.helpers namespace.

This commit is contained in:
Andrey Antukh 2022-02-07 12:37:54 +01:00 committed by Andrés Moya
parent 24724e3340
commit a1da4d4233
55 changed files with 1235 additions and 1348 deletions

View file

@ -7,7 +7,7 @@
(ns app.rpc.queries.files (ns app.rpc.queries.files
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.pages.migrations :as pmg] [app.common.pages.migrations :as pmg]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -242,13 +242,10 @@
(defn- trim-file-data (defn- trim-file-data
[file {:keys [page-id object-id]}] [file {:keys [page-id object-id]}]
(let [page (get-in file [:data :pages-index page-id]) (let [page (get-in file [:data :pages-index page-id])
objects (->> (:objects page) objects (->> (cph/get-children-with-self (:objects page) object-id)
(cp/get-object-with-children object-id) (map #(dissoc % :thumbnail))
(map #(dissoc % :thumbnail))) (d/index-by :id))
objects (d/index-by :id objects)
page (assoc page :objects objects)] page (assoc page :objects objects)]
(-> file (-> file
(update :data assoc :pages-index {page-id page}) (update :data assoc :pages-index {page-id page})
(update :data assoc :pages [page-id])))) (update :data assoc :pages [page-id]))))

View file

@ -10,7 +10,6 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.pages.changes :as changes] [app.common.pages.changes :as changes]
[app.common.pages.common :as common] [app.common.pages.common :as common]
[app.common.pages.helpers :as helpers]
[app.common.pages.indices :as indices] [app.common.pages.indices :as indices]
[app.common.pages.init :as init])) [app.common.pages.init :as init]))
@ -20,55 +19,6 @@
(d/export common/default-color) (d/export common/default-color)
(d/export common/component-sync-attrs) (d/export common/component-sync-attrs)
;; Helpers
(d/export helpers/walk-pages)
(d/export helpers/select-objects)
(d/export helpers/update-object-list)
(d/export helpers/get-component-shape)
(d/export helpers/get-root-shape)
(d/export helpers/make-container)
(d/export helpers/page?)
(d/export helpers/component?)
(d/export helpers/get-container)
(d/export helpers/get-shape)
(d/export helpers/get-component)
(d/export helpers/is-main-of)
(d/export helpers/get-component-root)
(d/export helpers/get-children)
(d/export helpers/get-children-objects)
(d/export helpers/get-object-with-children)
(d/export helpers/select-children)
(d/export helpers/is-shape-grouped)
(d/export helpers/get-parent)
(d/export helpers/get-parents)
(d/export helpers/get-frame)
(d/export helpers/clean-loops)
(d/export helpers/calculate-invalid-targets)
(d/export helpers/valid-frame-target)
(d/export helpers/position-on-parent)
(d/export helpers/insert-at-index)
(d/export helpers/append-at-the-end)
(d/export helpers/select-toplevel-shapes)
(d/export helpers/select-frames)
(d/export helpers/clone-object)
(d/export helpers/indexed-shapes)
(d/export helpers/expand-region-selection)
(d/export helpers/frame-id-by-position)
(d/export helpers/set-touched-group)
(d/export helpers/touched-group?)
(d/export helpers/get-base-shape)
(d/export helpers/is-parent?)
(d/export helpers/get-index-in-parent)
(d/export helpers/split-path)
(d/export helpers/join-path)
(d/export helpers/parse-path-name)
(d/export helpers/merge-path-item)
(d/export helpers/compact-path)
(d/export helpers/compact-name)
(d/export helpers/unframed-shape?)
(d/export helpers/children-seq)
;; Indices ;; Indices
(d/export indices/calculate-z-index) (d/export indices/calculate-z-index)
(d/export indices/update-z-index) (d/export indices/update-z-index)

View file

@ -160,7 +160,7 @@
(let [lookup (d/getf objects) (let [lookup (d/getf objects)
update-fn #(d/update-when %1 %2 update-group %1) update-fn #(d/update-when %1 %2 update-group %1)
xform (comp xform (comp
(mapcat #(cons % (cph/get-parents % objects))) (mapcat #(cons % (cph/get-parent-ids objects %)))
(filter #(contains? #{:group :bool} (-> % lookup :type))) (filter #(contains? #{:group :bool} (-> % lookup :type)))
(distinct))] (distinct))]
@ -202,11 +202,16 @@
(defmethod process-change :mov-objects (defmethod process-change :mov-objects
[data {:keys [parent-id shapes index page-id component-id ignore-touched]}] [data {:keys [parent-id shapes index page-id component-id ignore-touched]}]
(letfn [(is-valid-move? [objects shape-id] (letfn [(calculate-invalid-targets [objects shape-id]
(let [invalid-targets (cph/calculate-invalid-targets shape-id objects)] (let [reduce-fn #(into %1 (calculate-invalid-targets objects %2))]
(->> (get-in objects [shape-id :shapes])
(reduce reduce-fn #{shape-id}))))
(is-valid-move? [objects shape-id]
(let [invalid-targets (calculate-invalid-targets objects shape-id)]
(and (contains? objects shape-id) (and (contains? objects shape-id)
(not (invalid-targets parent-id)) (not (invalid-targets parent-id))
(cph/valid-frame-target shape-id parent-id objects)))) (cph/valid-frame-target? objects parent-id shape-id))))
(insert-items [prev-shapes index shapes] (insert-items [prev-shapes index shapes]
(let [prev-shapes (or prev-shapes [])] (let [prev-shapes (or prev-shapes [])]

View file

@ -7,8 +7,7 @@
(ns app.common.pages.changes-builder (ns app.common.pages.changes-builder
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]))
[app.common.pages.helpers :as h]))
;; Auxiliary functions to help create a set of changes (undo + redo) ;; Auxiliary functions to help create a set of changes (undo + redo)
@ -78,7 +77,7 @@
:page-id (::page-id (meta changes)) :page-id (::page-id (meta changes))
:parent-id (:parent-id shape) :parent-id (:parent-id shape)
:shapes [(:id shape)] :shapes [(:id shape)]
:index (cp/position-on-parent (:id shape) objects)}))] :index (cph/get-position-on-parent objects (:id shape))}))]
(-> changes (-> changes
(update :redo-changes conj set-parent-change) (update :redo-changes conj set-parent-change)
@ -171,7 +170,7 @@
:page-id page-id :page-id page-id
:parent-id (:parent-id shape) :parent-id (:parent-id shape)
:shapes [id] :shapes [id]
:index (h/position-on-parent id objects) :index (cph/get-position-on-parent objects id)
:ignore-touched true})))] :ignore-touched true})))]
(-> changes (-> changes

View file

@ -9,43 +9,234 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.interactions :as cti] [app.common.spec.page :as spec.page]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[cuerdas.core :as str])) [cuerdas.core :as str]))
(defn walk-pages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
"Go through all pages of a file and apply a function to each one" ;; GENERIC SHAPE SELECTORS AND PREDICATES
;; The function receives two parameters (page-id and page), and ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; returns the updated page.
[f data]
(update data :pages-index #(d/mapm f %)))
(defn select-objects (defn ^boolean root-frame?
"Get a list of all objects in a container (a page or a component) that [{:keys [id type]}]
satisfy a condition" (and (= type :frame)
[f container] (= id uuid/zero)))
(filter f (vals (get container :objects))))
(defn update-object-list (defn ^boolean frame-shape?
"Update multiple objects in a page at once" [{:keys [type]}]
[page objects-list] (= type :frame))
(update page :objects
#(into % (d/index-by :id objects-list)))) (defn ^boolean group-shape?
[{:keys [type]}]
(= type :group))
(defn ^boolean text-shape?
[{:keys [type]}]
(= type :text))
(defn ^boolean unframed-shape?
"Checks if it's a non-frame shape in the top level."
[shape]
(and (not (frame-shape? shape))
(= (:frame-id shape) uuid/zero)))
(defn get-shape
[container shape-id]
(us/assert ::spec.page/container container)
(us/assert ::us/uuid shape-id)
(-> container
(get :objects)
(get shape-id)))
(defn get-children-ids
[objects id]
(if-let [shapes (-> (get objects id) :shapes (some-> vec))]
(into shapes (mapcat #(get-children-ids objects %)) shapes)
[]))
(defn get-children
[objects id]
(mapv (d/getf objects) (get-children-ids objects id)))
(defn get-children-with-self
[objects id]
(let [lookup (d/getf objects)]
(into [(lookup id)] (map lookup) (get-children-ids objects id))))
(defn get-parent
"Retrieve the id of the parent for the shape-id (if exists)"
[objects id]
(let [lookup (d/getf objects)]
(-> id lookup :parent-id lookup)))
(defn get-parent-id
"Retrieve the id of the parent for the shape-id (if exists)"
[objects id]
(-> objects (get id) :parent-id))
(defn get-parent-ids
"Returns a vector of parents of the specified shape."
[objects shape-id]
(loop [result [] id shape-id]
(if-let [parent-id (->> id (get objects) :parent-id)]
(recur (conj result parent-id) parent-id)
result)))
(defn get-frame
"Get the frame that contains the shape. If the shape is already a
frame, get itself. If no shape is provided, returns the root frame."
([objects]
(get objects uuid/zero))
([objects shape-or-id]
(cond
(map? shape-or-id)
(if (frame-shape? shape-or-id)
shape-or-id
(get objects (:frame-id shape-or-id)))
(= uuid/zero shape-or-id)
(get objects uuid/zero)
:else
(some->> shape-or-id
(get objects)
(get-frame objects)))))
(defn valid-frame-target?
[objects parent-id shape-id]
(let [shape (get objects shape-id)]
(or (not (frame-shape? shape))
(= parent-id uuid/zero))))
(defn get-position-on-parent
[objects id]
(let [obj (get objects id)
pid (:parent-id obj)
prt (get objects pid)]
(d/index-of (:shapes prt) id)))
(defn get-immediate-children
"Retrieve resolved shape objects that are immediate children
of the specified shape-id"
([objects] (get-immediate-children objects uuid/zero))
([objects shape-id]
(let [lookup (d/getf objects)]
(->> (lookup shape-id)
(:shapes)
(keep lookup)))))
(defn get-frames
"Retrieves all frame objects as vector. It is not implemented in
function of `get-immediate-children` for performance reasons. This
function is executed in the render hot path."
[objects]
(let [lookup (d/getf objects)
xform (comp (keep lookup)
(filter frame-shape?))]
(->> (:shapes (lookup uuid/zero))
(into [] xform))))
(defn frame-id-by-position
[objects position]
(let [frames (get-frames objects)]
(or
(->> frames
(reverse)
(d/seek #(and position (gsh/has-point? % position)))
:id)
uuid/zero)))
(declare indexed-shapes)
(defn get-base-shape
"Selects the shape that will be the base to add the shapes over"
[objects selected]
(let [;; Gets the tree-index for all the shapes
indexed-shapes (indexed-shapes objects)
;; Filters the selected and retrieve a list of ids
sorted-ids (->> indexed-shapes
(filter (comp selected second))
(map second))]
;; The first id will be the top-most
(get objects (first sorted-ids))))
(defn is-parent?
"Check if `parent-candidate` is parent of `shape-id`"
[objects shape-id parent-candidate]
(loop [current (get objects parent-candidate)
done #{}
pending (:shapes current)]
(cond
(contains? done (:id current))
(recur (get objects (first pending))
done
(rest pending))
(empty? pending) false
(and current (contains? (set (:shapes current)) shape-id)) true
:else
(recur (get objects (first pending))
(conj done (:id current))
(concat (rest pending) (:shapes current))))))
(defn get-index-in-parent
"Retrieves the index in the parent"
[objects shape-id]
(let [shape (get objects shape-id)
parent (get objects (:parent-id shape))
[parent-idx _] (d/seek (fn [[_idx child-id]] (= child-id shape-id))
(d/enumerate (:shapes parent)))]
parent-idx))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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 #(-> % :components (get component-id)) (vals libraries)))
([libraries library-id component-id]
(get-in libraries [library-id :components component-id])))
(defn ^boolean is-main-of?
[shape-main shape-inst]
(and (:shape-ref shape-inst)
(or (= (:shape-ref shape-inst) (:id shape-main))
(= (:shape-ref shape-inst) (:shape-ref shape-main)))))
(defn get-component-root
[component]
(get-in component [:objects (:id component)]))
(defn get-component-shape (defn get-component-shape
"Get the parent shape linked to a component for this shape, if any" "Get the parent shape linked to a component for this shape, if any"
[shape objects] [objects shape]
(if-not (:shape-ref shape) (if-not (:shape-ref shape)
nil nil
(if (:component-id shape) (if (:component-id shape)
shape shape
(if-let [parent-id (:parent-id shape)] (if-let [parent-id (:parent-id shape)]
(get-component-shape (get objects parent-id) objects) (get-component-shape objects (get objects parent-id))
nil)))) nil))))
(defn get-root-shape (defn get-root-shape
"Get the root shape linked to a component for this shape, if any" "Get the root shape linked to a component for this shape, if any."
[shape objects] [objects shape]
(cond (cond
(some? (:component-root? shape)) (some? (:component-root? shape))
@ -57,12 +248,10 @@
(defn make-container (defn make-container
[page-or-component type] [page-or-component type]
(assoc page-or-component (assoc page-or-component :type type))
:type type))
(defn page? (defn page?
[container] [container]
(us/assert some? (:type container))
(= (:type container) :page)) (= (:type container) :page))
(defn component? (defn component?
@ -70,120 +259,32 @@
(= (:type container) :component)) (= (:type container) :component))
(defn get-container (defn get-container
[id type local-file] [file type id]
(assert (some? type)) (us/assert map? file)
(us/assert keyword? type)
(us/assert uuid? id)
(-> (if (= type :page) (-> (if (= type :page)
(get-in local-file [:pages-index id]) (get-in file [:pages-index id])
(get-in local-file [:components id])) (get-in file [:components id]))
(assoc :type type))) (assoc :type type)))
(defn get-shape ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[container shape-id] ;; ALGORITHMS & TRANSFORMATIONS FOR SHAPES
(get-in container [:objects shape-id])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn get-component (defn walk-pages
[component-id library-id local-library libraries] "Go through all pages of a file and apply a function to each one"
(assert (some? (:id local-library))) ;; The function receives two parameters (page-id and page), and
(let [file (if (= library-id (:id local-library)) ;; returns the updated page.
local-library [f data]
(get-in libraries [library-id :data]))] (update data :pages-index #(d/mapm f %)))
(get-in file [:components component-id])))
(defn is-main-of (defn update-object-list
[shape-main shape-inst] "Update multiple objects in a page at once"
(and (:shape-ref shape-inst) [page objects-list]
(or (= (:shape-ref shape-inst) (:id shape-main)) (update page :objects
(= (:shape-ref shape-inst) (:shape-ref shape-main))))) #(into % (d/index-by :id objects-list))))
(defn get-component-root
[component]
(get-in component [:objects (:id component)]))
(defn get-children [id objects]
(if-let [shapes (-> (get objects id) :shapes (some-> vec))]
(into shapes (mapcat #(get-children % objects)) shapes)
[]))
(defn get-children-objects
"Retrieve all children objects recursively for a given object"
[id objects]
(mapv #(get objects %) (get-children id objects)))
(defn get-object-with-children
"Retrieve a vector with an object and all of its children"
[id objects]
(mapv #(get objects %) (cons id (get-children id objects))))
(defn select-children [id objects]
(->> (get-children id objects)
(select-keys objects)))
(defn is-shape-grouped
"Checks if a shape is inside a group"
[shape-id objects]
(let [contains-shape-fn (fn [{:keys [shapes]}] ((set shapes) shape-id))
shapes (remove #(= (:type %) :frame) (vals objects))]
(some contains-shape-fn shapes)))
(defn get-top-frame
[objects]
(get objects uuid/zero))
(defn get-parent
"Retrieve the id of the parent for the shape-id (if exists)"
[shape-id objects]
(let [obj (get objects shape-id)]
(:parent-id obj)))
(defn get-parents
[shape-id objects]
(when-let [parent-id (->> shape-id (get objects) :parent-id)]
(lazy-seq (cons parent-id (get-parents parent-id objects)))))
(defn get-frame
"Get the frame that contains the shape. If the shape is already a frame, get itself."
[shape objects]
(if (= (:type shape) :frame)
shape
(get objects (:frame-id shape))))
(defn clean-loops
"Clean a list of ids from circular references."
[objects ids]
(let [parent-selected?
(fn [id]
(let [parents (get-parents id objects)]
(some ids parents)))
add-element
(fn [result id]
(cond-> result
(not (parent-selected? id))
(conj id)))]
(reduce add-element (d/ordered-set) ids)))
(defn calculate-invalid-targets
[shape-id objects]
(let [result #{shape-id}
children (get-in objects [shape-id :shapes])
reduce-fn (fn [result child-id]
(into result (calculate-invalid-targets child-id objects)))]
(reduce reduce-fn result children)))
(defn valid-frame-target
[shape-id parent-id objects]
(let [shape (get objects shape-id)]
(or (not= (:type shape) :frame)
(= parent-id uuid/zero))))
(defn position-on-parent
[id objects]
(let [obj (get objects id)
pid (:parent-id obj)
prt (get objects pid)]
(d/index-of (:shapes prt) id)))
(defn insert-at-index (defn insert-at-index
[objects index ids] [objects index ids]
@ -203,41 +304,22 @@
(vec prev-ids) (vec prev-ids)
ids)) ids))
(defn select-toplevel-shapes (defn clean-loops
([objects] (select-toplevel-shapes objects nil)) "Clean a list of ids from circular references."
([objects {:keys [include-frames? include-frame-children?] [objects ids]
:or {include-frames? false
include-frame-children? true}}]
(let [lookup #(get objects %) (let [parent-selected?
root (lookup uuid/zero) (fn [id]
root-children (:shapes root) (let [parents (get-parent-ids objects id)]
(some ids parents)))
lookup-shapes add-element
(fn [result id] (fn [result id]
(if (nil? id)
result
(let [obj (lookup id)
typ (:type obj)
children (:shapes obj)]
(cond-> result (cond-> result
(or (not= :frame typ) include-frames?) (not (parent-selected? id))
(conj obj) (conj id)))]
(and (= :frame typ) include-frame-children?) (reduce add-element (d/ordered-set) ids)))
(into (map lookup) children)))))]
(reduce lookup-shapes [] root-children))))
(defn select-frames
[objects]
(let [lookup #(get objects %)
frame? #(= :frame (:type %))
xform (comp (map lookup)
(filter frame?))]
(->> (:shapes (lookup uuid/zero))
(into [] xform))))
(defn clone-object (defn clone-object
"Gets a copy of the object and all its children, with new ids "Gets a copy of the object and all its children, with new ids
@ -304,8 +386,6 @@
(reduce red-fn cur-idx (reverse (:shapes object)))))] (reduce red-fn cur-idx (reverse (:shapes object)))))]
(into {} (rec-index '() uuid/zero)))) (into {} (rec-index '() uuid/zero))))
(defn expand-region-selection (defn expand-region-selection
"Given a selection selects all the shapes between the first and last in "Given a selection selects all the shapes between the first and last in
an indexed manner (shift selection)" an indexed manner (shift selection)"
@ -322,67 +402,9 @@
(map second) (map second)
(into #{})))) (into #{}))))
(defn frame-id-by-position [objects position] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(let [frames (select-frames objects)] ;; SHAPES ORGANIZATION (PATH MANAGEMENT)
(or ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(->> frames
(reverse)
(d/seek #(and position (gsh/has-point? % position)))
:id)
uuid/zero)))
(defn set-touched-group
[touched group]
(conj (or touched #{}) group))
(defn touched-group?
[shape group]
((or (:touched shape) #{}) group))
(defn get-base-shape
"Selects the shape that will be the base to add the shapes over"
[objects selected]
(let [;; Gets the tree-index for all the shapes
indexed-shapes (indexed-shapes objects)
;; Filters the selected and retrieve a list of ids
sorted-ids (->> indexed-shapes
(filter (comp selected second))
(map second))]
;; The first id will be the top-most
(get objects (first sorted-ids))))
(defn is-parent?
"Check if `parent-candidate` is parent of `shape-id`"
[objects shape-id parent-candidate]
(loop [current (get objects parent-candidate)
done #{}
pending (:shapes current)]
(cond
(contains? done (:id current))
(recur (get objects (first pending))
done
(rest pending))
(empty? pending) false
(and current (contains? (set (:shapes current)) shape-id)) true
:else
(recur (get objects (first pending))
(conj done (:id current))
(concat (rest pending) (:shapes current))))))
(defn get-index-in-parent
"Retrieves the index in the parent"
[objects shape-id]
(let [shape (get objects shape-id)
parent (get objects (:parent-id shape))
[parent-idx _] (d/seek (fn [[_idx child-id]] (= child-id shape-id))
(d/enumerate (:shapes parent)))]
parent-idx))
(defn split-path (defn split-path
"Decompose a string in the form 'one / two / three' into "Decompose a string in the form 'one / two / three' into
@ -442,26 +464,3 @@
[path name] [path name]
(let [path-split (split-path path)] (let [path-split (split-path path)]
(merge-path-item (first path-split) name))) (merge-path-item (first path-split) name)))
(defn connected-frame?
"Check if some frame is origin or destination of any navigate interaction
in the page"
[frame-id objects]
(let [children (get-object-with-children frame-id objects)]
(or (some cti/flow-origin? (map :interactions children))
(some #(cti/flow-to? % frame-id) (map :interactions (vals objects))))))
(defn unframed-shape?
"Checks if it's a non-frame shape in the top level."
[shape]
(and (not= (:type shape) :frame)
(= (:frame-id shape) uuid/zero)))
(defn children-seq
"Creates a sequence of shapes through the objects tree"
[shape objects]
(let [getter (partial get objects)]
(tree-seq #(d/not-empty? (get shape :shapes))
#(->> (get % :shapes) (map getter))
shape)))

View file

@ -7,7 +7,7 @@
(ns app.common.pages.indices (ns app.common.pages.indices
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages.helpers :as helpers] [app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[clojure.set :as set])) [clojure.set :as set]))
@ -45,7 +45,7 @@
means is displayed over other shapes with less index." means is displayed over other shapes with less index."
[objects] [objects]
(let [frames (helpers/select-frames objects) (let [frames (cph/get-frames objects)
z-index (calculate-frame-z-index {} uuid/zero objects)] z-index (calculate-frame-z-index {} uuid/zero objects)]
(->> frames (->> frames
(map :id) (map :id)
@ -61,7 +61,7 @@
changed-frames (set/union old-frames new-frames) changed-frames (set/union old-frames new-frames)
frames (->> (helpers/select-frames new-objects) frames (->> (cph/get-frames new-objects)
(map :id) (map :id)
(filter #(contains? changed-frames %))) (filter #(contains? changed-frames %)))
@ -84,13 +84,10 @@
(generate-child-all-parents-index objects (vals objects))) (generate-child-all-parents-index objects (vals objects)))
([objects shapes] ([objects shapes]
(let [shape->parents (let [xf-parents (comp
(fn [shape] (map :id)
(->> (helpers/get-parents (:id shape) objects) (map #(vector % (cph/get-parent-ids objects %))))]
(into [])))] (into {} xf-parents shapes))))
(->> shapes
(map #(vector (:id %) (shape->parents %)))
(into {})))))
(defn create-clip-index (defn create-clip-index
"Retrieves the mask information for an object" "Retrieves the mask information for an object"

View file

@ -11,7 +11,6 @@
[app.common.spec.shape :as shape] [app.common.spec.shape :as shape]
[clojure.spec.alpha :as s])) [clojure.spec.alpha :as s]))
;; --- Grid options ;; --- Grid options
(s/def :internal.grid.color/color string?) (s/def :internal.grid.color/color string?)

View file

@ -8,7 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.interactions :as cti] [app.common.spec.interactions :as cti]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -571,7 +571,7 @@
(conj id))] (conj id))]
(-> state (-> state
(assoc-in [:viewer-local :selected] (assoc-in [:viewer-local :selected]
(cp/expand-region-selection objects selection))))))) (cph/expand-region-selection objects selection)))))))
(defn select-all (defn select-all
[] []

View file

@ -484,7 +484,7 @@
(initialize [state local] (initialize [state local]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
shapes (cp/select-toplevel-shapes objects {:include-frames? true}) shapes (cph/get-immediate-children objects)
srect (gsh/selection-rect shapes) srect (gsh/selection-rect shapes)
local (assoc local :vport size :zoom 1)] local (assoc local :vport size :zoom 1)]
(cond (cond
@ -675,7 +675,7 @@
(update [_ state] (update [_ state]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
shapes (cp/select-toplevel-shapes objects {:include-frames? true}) shapes (cph/get-immediate-children objects)
srect (gsh/selection-rect shapes)] srect (gsh/selection-rect shapes)]
(if (empty? shapes) (if (empty? shapes)
state state
@ -794,7 +794,7 @@
:frame-id (:frame-id obj) :frame-id (:frame-id obj)
:page-id page-id :page-id page-id
:shapes [id] :shapes [id]
:index (cp/position-on-parent id objects)})) :index (cph/get-position-on-parent objects id)}))
selected)] selected)]
;; TODO: maybe missing the :reg-objects event? ;; TODO: maybe missing the :reg-objects event?
(rx/of (dch/commit-changes {:redo-changes rchanges (rx/of (dch/commit-changes {:redo-changes rchanges
@ -821,7 +821,7 @@
{:type :mov-objects {:type :mov-objects
:parent-id (:parent-id obj) :parent-id (:parent-id obj)
:page-id page-id :page-id page-id
:index (cp/position-on-parent id objects) :index (cph/get-position-on-parent objects id)
:shapes [id]})) :shapes [id]}))
(reverse ids)) (reverse ids))
@ -1023,11 +1023,11 @@
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
;; Ignore any shape whose parent is also intented to be moved ;; Ignore any shape whose parent is also intented to be moved
ids (cp/clean-loops objects ids) ids (cph/clean-loops objects ids)
;; If we try to move a parent into a child we remove it ;; If we try to move a parent into a child we remove it
ids (filter #(not (cp/is-parent? objects parent-id %)) ids) ids (filter #(not (cph/is-parent? objects parent-id %)) ids)
parents (into #{parent-id} (map #(cp/get-parent % objects)) ids) parents (into #{parent-id} (map #(cph/get-parent-id objects %)) ids)
groups-to-delete groups-to-delete
(loop [current-id (first parents) (loop [current-id (first parents)
@ -1045,7 +1045,7 @@
(empty? (remove removed-id? (:shapes group)))) (empty? (remove removed-id? (:shapes group))))
;; Adds group to the remove and check its parent ;; Adds group to the remove and check its parent
(let [to-check (concat to-check [(cp/get-parent current-id objects)])] (let [to-check (concat to-check [(cph/get-parent-id objects current-id)])]
(recur (first to-check) (recur (first to-check)
(rest to-check) (rest to-check)
(conj removed-id? current-id) (conj removed-id? current-id)
@ -1090,8 +1090,8 @@
(not (:component-root? shape))) (not (:component-root? shape)))
parent (get objects parent-id) parent (get objects parent-id)
component-shape (cph/get-component-shape shape objects) component-shape (cph/get-component-shape objects shape)
component-shape-parent (cph/get-component-shape parent objects) component-shape-parent (cph/get-component-shape objects parent)
detach? (and instance-part? (not= (:id component-shape) detach? (and instance-part? (not= (:id component-shape)
(:id component-shape-parent))) (:id component-shape-parent)))
@ -1099,7 +1099,7 @@
reroot? (and sub-instance? (not component-shape-parent)) reroot? (and sub-instance? (not component-shape-parent))
ids-to-detach (when detach? ids-to-detach (when detach?
(cons id (cph/get-children id objects)))] (cons id (cph/get-children-ids objects id)))]
[(cond-> shapes-to-detach detach? (into ids-to-detach)) [(cond-> shapes-to-detach detach? (into ids-to-detach))
(cond-> shapes-to-deroot deroot? (conj id)) (cond-> shapes-to-deroot deroot? (conj id))
@ -1286,7 +1286,7 @@
(boolean? blocked) (assoc :blocked blocked) (boolean? blocked) (assoc :blocked blocked)
(boolean? hidden) (assoc :hidden hidden))) (boolean? hidden) (assoc :hidden hidden)))
objects (wsh/lookup-page-objects state) objects (wsh/lookup-page-objects state)
ids (into ids (->> ids (mapcat #(cp/get-children % objects))))] ids (into ids (->> ids (mapcat #(cph/get-children-ids objects %))))]
(rx/of (dch/update-shapes ids update-fn)))))) (rx/of (dch/update-shapes ids update-fn))))))
(defn toggle-visibility-selected (defn toggle-visibility-selected
@ -1483,7 +1483,7 @@
(watch [_ state _] (watch [_ state _]
(let [selected (wsh/lookup-selected state) (let [selected (wsh/lookup-selected state)
objects (wsh/lookup-page-objects state) objects (wsh/lookup-page-objects state)
all-selected (into [] (mapcat #(cp/get-object-with-children % objects)) selected) all-selected (into [] (mapcat #(cph/get-children-with-self objects %)) selected)
head (get objects (first selected)) head (get objects (first selected))
not-group-like? (and (= (count selected) 1) not-group-like? (and (= (count selected) 1)
@ -1588,7 +1588,7 @@
(watch [_ state _] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state) selected (->> (wsh/lookup-selected state)
(cp/clean-loops objects)) (cph/clean-loops objects))
pdata (reduce (partial collect-object-ids objects) {} selected) pdata (reduce (partial collect-object-ids objects) {} selected)
initial {:type :copied-shapes initial {:type :copied-shapes
:file-id (:current-file-id state) :file-id (:current-file-id state)
@ -1771,13 +1771,13 @@
[frame-id frame-id delta]) [frame-id frame-id delta])
(empty? page-selected) (empty? page-selected)
(let [frame-id (cp/frame-id-by-position page-objects mouse-pos) (let [frame-id (cph/frame-id-by-position page-objects mouse-pos)
delta (gpt/subtract mouse-pos orig-pos)] delta (gpt/subtract mouse-pos orig-pos)]
[frame-id frame-id delta]) [frame-id frame-id delta])
:else :else
(let [base (cp/get-base-shape page-objects page-selected) (let [base (cph/get-base-shape page-objects page-selected)
index (cp/position-on-parent (:id base) page-objects) index (cph/get-position-on-parent page-objects (:id base))
frame-id (:frame-id base) frame-id (:frame-id base)
parent-id (:parent-id base) parent-id (:parent-id base)
delta (if in-viewport? delta (if in-viewport?
@ -1804,7 +1804,7 @@
;; Check if the shape is an instance whose master is defined in a ;; Check if the shape is an instance whose master is defined in a
;; library that is not linked to the current file ;; library that is not linked to the current file
(foreign-instance? [shape paste-objects state] (foreign-instance? [shape paste-objects state]
(let [root (cph/get-root-shape shape paste-objects) (let [root (cph/get-root-shape paste-objects shape)
root-file-id (:component-file root)] root-file-id (:component-file root)]
(and (some? root) (and (some? root)
(not= root-file-id (:current-file-id state)) (not= root-file-id (:current-file-id state))
@ -1896,7 +1896,7 @@
height 16 height 16
page-id (:current-page-id state) page-id (:current-page-id state)
frame-id (-> (wsh/lookup-page-objects state page-id) frame-id (-> (wsh/lookup-page-objects state page-id)
(cp/frame-id-by-position @ms/mouse-position)) (cph/frame-id-by-position @ms/mouse-position))
shape (gsh/setup-selrect shape (gsh/setup-selrect
{:id id {:id id
:type :text :type :text
@ -1987,7 +1987,7 @@
(watch [_ state _] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
shapes (cp/select-toplevel-shapes objects {:include-frames? true}) shapes (cph/get-immediate-children objects)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
selected-objs (map #(get objects %) selected) selected-objs (map #(get objects %) selected)
has-frame? (some #(= (:type %) :frame) selected-objs)] has-frame? (some #(= (:type %) :frame) selected-objs)]

View file

@ -9,8 +9,8 @@
[app.common.colors :as clr] [app.common.colors :as clr]
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.pages.changes-builder :as cb] [app.common.pages.changes-builder :as cb]
[app.common.pages.helpers :as cph]
[app.common.path.shapes-to-path :as stp] [app.common.path.shapes-to-path :as stp]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
@ -24,10 +24,10 @@
[state] [state]
(let [objects (wsh/lookup-page-objects state)] (let [objects (wsh/lookup-page-objects state)]
(->> (wsh/lookup-selected state) (->> (wsh/lookup-selected state)
(cp/clean-loops objects) (cph/clean-loops objects)
(map #(get objects %)) (map (d/getf objects))
(filter #(not= :frame (:type %))) (remove cph/frame-shape?)
(map #(assoc % ::index (cp/position-on-parent (:id %) objects))) (map #(assoc % ::index (cph/get-position-on-parent objects (:id %))))
(sort-by ::index)))) (sort-by ::index))))
(defn create-bool-data (defn create-bool-data
@ -51,7 +51,7 @@
(merge head-data) (merge head-data)
(gsh/update-bool-selrect shapes objects))] (gsh/update-bool-selrect shapes objects))]
[bool-shape (cp/position-on-parent (:id head) objects)])) [bool-shape (cph/get-position-on-parent objects (:id head))]))
(defn group->bool (defn group->bool
[group bool-type objects] [group bool-type objects]

View file

@ -11,6 +11,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.interactions :as csi] [app.common.spec.interactions :as csi]
[app.common.spec.page :as csp] [app.common.spec.page :as csp]
@ -58,12 +59,13 @@
;; --- Common Helpers & Events ;; --- Common Helpers & Events
;; TODO: looks duplicate
(defn get-frame-at-point (defn get-frame-at-point
[objects point] [objects point]
(let [frames (cp/select-frames objects)] (let [frames (cph/get-frames objects)]
(d/seek #(gsh/has-point? % point) frames))) (d/seek #(gsh/has-point? % point) frames)))
(defn- extract-numeric-suffix (defn- extract-numeric-suffix
[basename] [basename]
(if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)] (if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
@ -195,9 +197,9 @@
(let [expand-fn (fn [expanded] (let [expand-fn (fn [expanded]
(merge expanded (merge expanded
(->> ids (->> ids
(map #(cp/get-parents % objects)) (map #(cph/get-parent-ids objects %))
flatten flatten
(filter #(not= % uuid/zero)) (remove #(= % uuid/zero))
(map (fn [id] {id true})) (map (fn [id] {id true}))
(into {}))))] (into {}))))]
(update-in state [:workspace-local :expanded] expand-fn))))) (update-in state [:workspace-local :expanded] expand-fn)))))
@ -264,9 +266,9 @@
;; Calculate the frame over which we're drawing ;; Calculate the frame over which we're drawing
(let [position @ms/mouse-position (let [position @ms/mouse-position
frame-id (:frame-id attrs (cp/frame-id-by-position objects position)) frame-id (:frame-id attrs (cph/frame-id-by-position objects position))
shape (when-not (empty? selected) shape (when-not (empty? selected)
(cp/get-base-shape objects selected))] (cph/get-base-shape objects selected))]
;; When no shapes has been selected or we're over a different frame ;; When no shapes has been selected or we're over a different frame
;; we add it as the latest shape of that frame ;; we add it as the latest shape of that frame
@ -274,7 +276,7 @@
[frame-id frame-id nil] [frame-id frame-id nil]
;; Otherwise, we add it to next to the selected shape ;; Otherwise, we add it to next to the selected shape
(let [index (cp/position-on-parent (:id shape) objects) (let [index (cph/get-position-on-parent objects (:id shape))
{:keys [frame-id parent-id]} shape] {:keys [frame-id parent-id]} shape]
[frame-id parent-id (inc index)]))))) [frame-id parent-id (inc index)])))))
@ -356,8 +358,9 @@
(watch [it state _] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
to-move-shapes (->> (cp/select-toplevel-shapes objects {:include-frames? false})
(filterv #(= (:frame-id %) uuid/zero)) to-move-shapes (->> (cph/get-immediate-children objects)
(remove cph/frame-shape?)
(mapv :id) (mapv :id)
(d/enumerate) (d/enumerate)
(filterv (comp shapes second))) (filterv (comp shapes second)))
@ -394,7 +397,7 @@
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
options (wsh/lookup-page-options state page-id) options (wsh/lookup-page-options state page-id)
ids (cp/clean-loops objects ids) ids (cph/clean-loops objects ids)
flows (:flows options) flows (:flows options)
groups-to-unmask groups-to-unmask
@ -434,14 +437,14 @@
all-parents all-parents
(reduce (fn [res id] (reduce (fn [res id]
(into res (cp/get-parents id objects))) (into res (cph/get-parent-ids objects id)))
(d/ordered-set) (d/ordered-set)
ids) ids)
all-children all-children
(->> ids (->> ids
(reduce (fn [res id] (reduce (fn [res id]
(into res (cp/get-children id objects))) (into res (cph/get-children-ids objects id)))
[]) [])
(reverse) (reverse)
(into (d/ordered-set))) (into (d/ordered-set)))
@ -463,7 +466,7 @@
{:type :add-obj {:type :add-obj
:id (:id item) :id (:id item)
:page-id page-id :page-id page-id
:index (cp/position-on-parent id objects) :index (cph/get-position-on-parent objects id)
:frame-id (:frame-id item) :frame-id (:frame-id item)
:parent-id (:parent-id item) :parent-id (:parent-id item)
:obj item})))) :obj item}))))
@ -588,7 +591,7 @@
y (:y data (- vbc-y (/ height 2))) y (:y data (- vbc-y (/ height 2)))
page-id (:current-page-id state) page-id (:current-page-id state)
frame-id (-> (wsh/lookup-page-objects state page-id) frame-id (-> (wsh/lookup-page-objects state page-id)
(cp/frame-id-by-position {:x frame-x :y frame-y})) (cph/frame-id-by-position {:x frame-x :y frame-y}))
shape (-> (cp/make-minimal-shape type) shape (-> (cp/make-minimal-shape type)
(merge data) (merge data)
(merge {:x x :y y}) (merge {:x x :y y})

View file

@ -9,7 +9,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.drawing.common :as common] [app.main.data.workspace.drawing.common :as common]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
@ -62,7 +62,7 @@
layout (get state :workspace-layout) layout (get state :workspace-layout)
zoom (get-in state [:workspace-local :zoom] 1) zoom (get-in state [:workspace-local :zoom] 1)
frames (cp/select-frames objects) frames (cph/get-frames objects)
fid (or (->> frames fid (or (->> frames
(filter #(gsh/has-point? % initial)) (filter #(gsh/has-point? % initial))
first first

View file

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

View file

@ -10,6 +10,7 @@
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.changes-builder :as cb] [app.common.pages.changes-builder :as cb]
[app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
@ -22,7 +23,7 @@
(->> selected (->> selected
(map #(get objects %)) (map #(get objects %))
(filter #(not= :frame (:type %))) (filter #(not= :frame (:type %)))
(map #(assoc % ::index (cp/position-on-parent (:id %) objects))) (map #(assoc % ::index (cph/get-position-on-parent objects (:id %))))
(sort-by ::index))) (sort-by ::index)))
(defn- get-empty-groups-after-group-creation (defn- get-empty-groups-after-group-creation
@ -34,10 +35,8 @@
group, one (or many) groups can become empty because they have had a group, one (or many) groups can become empty because they have had a
single shape which is moved to the created group." single shape which is moved to the created group."
[objects parent-id shapes] [objects parent-id shapes]
(let [ids (cp/clean-loops objects (into #{} (map :id) shapes)) (let [ids (cph/clean-loops objects (into #{} (map :id) shapes))
parents (->> ids parents (into #{} (map #(cph/get-parent-id objects %)) ids)]
(reduce #(conj %1 (cp/get-parent %2 objects))
#{}))]
(loop [current-id (first parents) (loop [current-id (first parents)
to-check (rest parents) to-check (rest parents)
removed-id? ids removed-id? ids
@ -53,7 +52,7 @@
(empty? (remove removed-id? (:shapes group)))) (empty? (remove removed-id? (:shapes group))))
;; Adds group to the remove and check its parent ;; Adds group to the remove and check its parent
(let [to-check (concat to-check [(cp/get-parent current-id objects)]) ] (let [to-check (concat to-check [(cph/get-parent-id objects current-id)]) ]
(recur (first to-check) (recur (first to-check)
(rest to-check) (rest to-check)
(conj removed-id? current-id) (conj removed-id? current-id)
@ -139,7 +138,7 @@
(defn prepare-remove-group (defn prepare-remove-group
[it page-id group objects] [it page-id group objects]
(let [children (mapv #(get objects %) (:shapes group)) (let [children (mapv #(get objects %) (:shapes group))
parent-id (cp/get-parent (:id group) objects) parent-id (cph/get-parent-id objects (:id group))
parent (get objects parent-id) parent (get objects parent-id)
index-in-parent index-in-parent
@ -149,7 +148,7 @@
(ffirst)) (ffirst))
ids-to-detach (when (:component-id group) ids-to-detach (when (:component-id group)
(cp/get-children (:id group) objects)) (cph/get-children-ids objects (:id group)))
detach-fn (fn [attrs] detach-fn (fn [attrs]
(dissoc attrs (dissoc attrs
@ -202,7 +201,7 @@
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
selected (cp/clean-loops objects selected) selected (cph/clean-loops objects selected)
shapes (shapes-for-grouping objects selected)] shapes (shapes-for-grouping objects selected)]
(when-not (empty? shapes) (when-not (empty? shapes)
(let [[group rchanges uchanges] (let [[group rchanges uchanges]
@ -241,7 +240,7 @@
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
selected (cp/clean-loops objects selected) selected (cph/clean-loops objects selected)
shapes (shapes-for-grouping objects selected)] shapes (shapes-for-grouping objects selected)]
(when-not (empty? shapes) (when-not (empty? shapes)
(let [;; If the selected shape is a group, we can use it. If not, (let [;; If the selected shape is a group, we can use it. If not,

View file

@ -126,6 +126,14 @@
;; --- Interactions ;; --- Interactions
(defn- connected-frame?
"Check if some frame is origin or destination of any navigate interaction
in the page"
[objects frame-id]
(let [children (cph/get-children-with-self objects frame-id)]
(or (some csi/flow-origin? (map :interactions children))
(some #(csi/flow-to? % frame-id) (map :interactions (vals objects))))))
(defn add-new-interaction (defn add-new-interaction
([shape] (add-new-interaction shape nil)) ([shape] (add-new-interaction shape nil))
([shape destination] ([shape destination]
@ -134,7 +142,7 @@
(watch [_ state _] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
frame (cph/get-frame shape objects) frame (cph/get-frame objects shape)
flows (get-in state [:workspace-data flows (get-in state [:workspace-data
:pages-index :pages-index
page-id page-id
@ -149,7 +157,7 @@
destination)] destination)]
(update shape :interactions (update shape :interactions
csi/add-interaction new-interaction))))) csi/add-interaction new-interaction)))))
(when (and (not (cph/connected-frame? (:id frame) objects)) (when (and (not (connected-frame? objects (:id frame)))
(nil? flow)) (nil? flow))
(rx/of (add-flow (:id frame)))))))))) (rx/of (add-flow (:id frame))))))))))
@ -278,7 +286,7 @@
overlay-pos (-> shape overlay-pos (-> shape
(get-in [:interactions index]) (get-in [:interactions index])
:overlay-position) :overlay-position)
orig-frame (cph/get-frame shape objects) orig-frame (cph/get-frame objects shape)
frame-pos (gpt/point (:x orig-frame) (:y orig-frame)) frame-pos (gpt/point (:x orig-frame) (:y orig-frame))
offset (-> initial-pos offset (-> initial-pos
(gpt/subtract overlay-pos) (gpt/subtract overlay-pos)

View file

@ -11,6 +11,7 @@
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.change :as spec.change] [app.common.spec.change :as spec.change]
[app.common.spec.color :as spec.color] [app.common.spec.color :as spec.color]
@ -132,7 +133,7 @@
(ptk/reify ::update-color (ptk/reify ::update-color
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [[path name] (cp/parse-path-name (:name color)) (let [[path name] (cph/parse-path-name (:name color))
color (assoc color :path path :name name) color (assoc color :path path :name name)
prev (get-in state [:workspace-data :colors id]) prev (get-in state [:workspace-data :colors id])
rchg {:type :mod-color rchg {:type :mod-color
@ -184,7 +185,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [object (get-in state [:workspace-data :media id]) (let [object (get-in state [:workspace-data :media id])
[path name] (cp/parse-path-name new-name) [path name] (cph/parse-path-name new-name)
rchanges [{:type :mod-media rchanges [{:type :mod-media
:object {:id id :object {:id id
@ -244,7 +245,7 @@
(ptk/reify ::update-typography (ptk/reify ::update-typography
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [[path name] (cp/parse-path-name (:name typography)) (let [[path name] (cph/parse-path-name (:name typography))
typography (assoc typography :path path :name name) typography (assoc typography :path path :name name)
prev (get-in state [:workspace-data :typographies (:id typography)]) prev (get-in state [:workspace-data :typographies (:id typography)])
rchg {:type :mod-typography rchg {:type :mod-typography
@ -307,7 +308,7 @@
(watch [_ state _] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state) selected (->> (wsh/lookup-selected state)
(cp/clean-loops objects))] (cph/clean-loops objects))]
(rx/of (add-component2 selected)))))) (rx/of (add-component2 selected))))))
(defn rename-component (defn rename-component
@ -318,7 +319,7 @@
(ptk/reify ::rename-component (ptk/reify ::rename-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [[path name] (cp/parse-path-name new-name) (let [[path name] (cph/parse-path-name new-name)
component (get-in state [:workspace-data :components id]) component (get-in state [:workspace-data :components id])
objects (get component :objects) objects (get component :objects)
; Give the same name to the root shape ; Give the same name to the root shape
@ -348,12 +349,10 @@
(ptk/reify ::duplicate-component (ptk/reify ::duplicate-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [component (cp/get-component id (let [libraries (dwlh/get-libraries state)
(:current-file-id state) component (cph/get-component libraries id)
(dwlh/get-local-file state) all-components (-> state :workspace-data :components vals)
nil) unames (into #{} (map :name) all-components)
all-components (vals (get-in state [:workspace-data :components]))
unames (set (map :name all-components))
new-name (dwc/generate-unique-name unames (:name component)) new-name (dwc/generate-unique-name unames (:name component))
[new-shape new-shapes _updated-shapes] [new-shape new-shapes _updated-shapes]
@ -404,10 +403,9 @@
(ptk/reify ::instantiate-component (ptk/reify ::instantiate-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [local-library (dwlh/get-local-file state) (let [libraries (dwlh/get-libraries state)
libraries (get state :workspace-libraries) component (cph/get-component libraries file-id component-id)
component (cp/get-component component-id file-id local-library libraries) component-shape (cph/get-shape component component-id)
component-shape (cp/get-shape component component-id)
orig-pos (gpt/point (:x component-shape) (:y component-shape)) orig-pos (gpt/point (:x component-shape) (:y component-shape))
delta (gpt/subtract position orig-pos) delta (gpt/subtract position orig-pos)
@ -416,7 +414,7 @@
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
unames (volatile! (dwc/retrieve-used-names objects)) unames (volatile! (dwc/retrieve-used-names objects))
frame-id (cp/frame-id-by-position objects (gpt/add orig-pos delta)) frame-id (cph/frame-id-by-position objects (gpt/add orig-pos delta))
update-new-shape update-new-shape
(fn [new-shape original-shape] (fn [new-shape original-shape]
@ -447,7 +445,7 @@
(dissoc :component-root?)))) (dissoc :component-root?))))
[new-shape new-shapes _] [new-shape new-shapes _]
(cp/clone-object component-shape (cph/clone-object component-shape
nil nil
(get component :objects) (get component :objects)
update-new-shape) update-new-shape)
@ -482,13 +480,12 @@
(ptk/reify ::detach-component (ptk/reify ::detach-component
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(let [local-library (dwlh/get-local-file state) (let [file (dwlh/get-local-file state)
container (cp/get-container (get state :current-page-id) page-id (get state :current-page-id)
:page container (cph/get-container file :page page-id)
local-library)
[rchanges uchanges] [rchanges uchanges]
(dwlh/generate-detach-instance id container)] (dwlh/generate-detach-instance container id)]
(rx/of (dch/commit-changes {:redo-changes rchanges (rx/of (dch/commit-changes {:redo-changes rchanges
:undo-changes uchanges :undo-changes uchanges
@ -500,18 +497,17 @@
(watch [it state _] (watch [it state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
local-library (dwlh/get-local-file state) file (dwlh/get-local-file state)
container (cp/get-container page-id :page local-library) container (cph/get-container file :page page-id)
selected (->> state selected (->> state
(wsh/lookup-selected) (wsh/lookup-selected)
(cp/clean-loops objects)) (cph/clean-loops objects))
[rchanges uchanges] [rchanges uchanges]
(reduce (fn [changes id] (reduce (fn [changes id]
(dwlh/concat-changes (dwlh/concat-changes
changes changes
(dwlh/generate-detach-instance id container))) (dwlh/generate-detach-instance container id)))
dwlh/empty-changes dwlh/empty-changes
selected)] selected)]
@ -557,21 +553,18 @@
ptk/WatchEvent ptk/WatchEvent
(watch [it state _] (watch [it state _]
(log/info :msg "RESET-COMPONENT of shape" :id (str id)) (log/info :msg "RESET-COMPONENT of shape" :id (str id))
(let [local-library (dwlh/get-local-file state) (let [file (dwlh/get-local-file state)
libraries (dwlh/get-libraries state) libraries (dwlh/get-libraries state)
container (cp/get-container (get state :current-page-id)
:page page-id (:current-page-id state)
local-library) container (cph/get-container file :page page-id)
[rchanges uchanges] [rchanges uchanges]
(dwlh/generate-sync-shape-direct container (dwlh/generate-sync-shape-direct libraries container id true)]
id
local-library
libraries
true)]
(log/debug :msg "RESET-COMPONENT finished" :js/rchanges (log-changes (log/debug :msg "RESET-COMPONENT finished" :js/rchanges (log-changes
rchanges rchanges
local-library)) file))
(rx/of (dch/commit-changes {:redo-changes rchanges (rx/of (dch/commit-changes {:redo-changes rchanges
:undo-changes uchanges :undo-changes uchanges
:origin it})))))) :origin it}))))))
@ -592,17 +585,16 @@
(watch [it state _] (watch [it state _]
(log/info :msg "UPDATE-COMPONENT of shape" :id (str id)) (log/info :msg "UPDATE-COMPONENT of shape" :id (str id))
(let [page-id (get state :current-page-id) (let [page-id (get state :current-page-id)
local-library (dwlh/get-local-file state)
local-file (dwlh/get-local-file state)
libraries (dwlh/get-libraries state) libraries (dwlh/get-libraries state)
[rchanges uchanges] container (cph/get-container local-file :page page-id)
(dwlh/generate-sync-shape-inverse page-id shape (cph/get-shape container id)
id
local-library [rchanges uchanges]
libraries) (dwlh/generate-sync-shape-inverse libraries container id)
container (cp/get-container page-id :page local-library)
shape (cp/get-shape container id)
file-id (:component-file shape) file-id (:component-file shape)
file (dwlh/get-file state file-id) file (dwlh/get-file state file-id)
@ -623,16 +615,17 @@
(log/debug :msg "UPDATE-COMPONENT finished" (log/debug :msg "UPDATE-COMPONENT finished"
:js/local-rchanges (log-changes :js/local-rchanges (log-changes
local-rchanges local-rchanges
local-library) file)
:js/rchanges (log-changes :js/rchanges (log-changes
rchanges rchanges
file)) file))
(rx/of (when (seq local-rchanges) (rx/of
(when (seq local-rchanges)
(dch/commit-changes {:redo-changes local-rchanges (dch/commit-changes {:redo-changes local-rchanges
:undo-changes local-uchanges :undo-changes local-uchanges
:origin it :origin it
:file-id (:id local-library)})) :file-id (:id local-file)}))
(when (seq rchanges) (when (seq rchanges)
(dch/commit-changes {:redo-changes rchanges (dch/commit-changes {:redo-changes rchanges
:undo-changes uchanges :undo-changes uchanges

View file

@ -11,6 +11,7 @@
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.text :as txt] [app.common.text :as txt]
[app.main.data.workspace.groups :as dwg] [app.main.data.workspace.groups :as dwg]
@ -57,7 +58,7 @@
(letfn [(concat-changes' [[rchanges1 uchanges1] [rchanges2 uchanges2]] (letfn [(concat-changes' [[rchanges1 uchanges1] [rchanges2 uchanges2]]
[(d/concat-vec rchanges1 rchanges2) [(d/concat-vec rchanges1 rchanges2)
(d/concat-vec uchanges1 uchanges2)])] (d/concat-vec uchanges1 uchanges2)])]
(transduce (remove nil?) concat-changes' empty-changes rest))) (transduce (remove nil?) (completing concat-changes') empty-changes rest)))
(defn get-local-file (defn get-local-file
[state] [state]
@ -70,8 +71,11 @@
(get-in state [:workspace-libraries file-id :data]))) (get-in state [:workspace-libraries file-id :data])))
(defn get-libraries (defn get-libraries
"Retrieve all libraries, including the local file."
[state] [state]
(get state :workspace-libraries)) (let [{:keys [id] :as local} (:workspace-data state)]
(-> (:workspace-libraries state)
(assoc id local))))
(defn pretty-file (defn pretty-file
[file-id state] [file-id state]
@ -120,7 +124,7 @@
(some? (:parent-id new-shape)) (some? (:parent-id new-shape))
(dissoc :component-root?)))] (dissoc :component-root?)))]
(cp/clone-object shape nil objects update-new-shape update-original-shape))) (cph/clone-object shape nil objects update-new-shape update-original-shape)))
(defn generate-add-component (defn generate-add-component
"If there is exactly one id, and it's a group, use it as root. Otherwise, "If there is exactly one id, and it's a group, use it as root. Otherwise,
@ -204,8 +208,8 @@
"Clone the root shape of the component and all children. Generate new "Clone the root shape of the component and all children. Generate new
ids from all of them." ids from all of them."
[component] [component]
(let [component-root (cp/get-component-root component)] (let [component-root (cph/get-component-root component)]
(cp/clone-object component-root (cph/clone-object component-root
nil nil
(get component :objects) (get component :objects)
identity))) identity)))
@ -213,9 +217,9 @@
(defn generate-detach-instance (defn generate-detach-instance
"Generate changes to remove the links between a shape and all its children "Generate changes to remove the links between a shape and all its children
with a component." with a component."
[shape-id container] [container shape-id]
(log/debug :msg "Detach instance" :shape-id shape-id :container (:id container)) (log/debug :msg "Detach instance" :shape-id shape-id :container (:id container))
(let [shapes (cp/get-object-with-children shape-id (:objects container)) (let [shapes (cph/get-children-with-self (:objects container) shape-id)
rchanges (mapv (fn [obj] rchanges (mapv (fn [obj]
(make-change (make-change
container container
@ -293,7 +297,7 @@
(generate-sync-container asset-type (generate-sync-container asset-type
library-id library-id
state state
(cp/make-container page :page))] (cph/make-container page :page))]
(recur (next pages) (recur (next pages)
(into rchanges page-rchanges) (into rchanges page-rchanges)
(into uchanges page-uchanges))) (into uchanges page-uchanges)))
@ -319,8 +323,7 @@
(generate-sync-container asset-type (generate-sync-container asset-type
library-id library-id
state state
(cp/make-container local-component (cph/make-container local-component :component))]
:component))]
(recur (next local-components) (recur (next local-components)
(into rchanges comp-rchanges) (into rchanges comp-rchanges)
(into uchanges comp-uchanges))) (into uchanges comp-uchanges)))
@ -331,12 +334,13 @@
or a component) that use assets of the given type in the given library." or a component) that use assets of the given type in the given library."
[asset-type library-id state container] [asset-type library-id state container]
(if (cp/page? container) (if (cph/page? container)
(log/debug :msg "Sync page in local file" :page-id (:id container)) (log/debug :msg "Sync page in local file" :page-id (:id container))
(log/debug :msg "Sync component in local library" :component-id (:id container))) (log/debug :msg "Sync component in local library" :component-id (:id container)))
(let [has-asset-reference? (has-asset-reference-fn asset-type library-id (cp/page? container)) (let [has-asset-reference? (has-asset-reference-fn asset-type library-id (cph/page? container))
linked-shapes (cp/select-objects has-asset-reference? container)] linked-shapes (->> (vals (:objects container))
(filter has-asset-reference?))]
(loop [shapes (seq linked-shapes) (loop [shapes (seq linked-shapes)
rchanges [] rchanges []
uchanges []] uchanges []]
@ -398,11 +402,9 @@
(defmethod generate-sync-shape :components (defmethod generate-sync-shape :components
[_ _ state container shape] [_ _ state container shape]
(generate-sync-shape-direct container (let [shape-id (:id shape)
(:id shape) libraries (get-libraries state)]
(get-local-file state) (generate-sync-shape-direct libraries container shape-id false)))
(get-libraries state)
false))
(defn- generate-sync-text-shape (defn- generate-sync-text-shape
[shape container update-node] [shape container update-node]
@ -624,19 +626,18 @@
(defn generate-sync-shape-direct (defn generate-sync-shape-direct
"Generate changes to synchronize one shape that the root of a component "Generate changes to synchronize one shape that the root of a component
instance, and all its children, from the given component." instance, and all its children, from the given component."
[container shape-id local-library libraries reset?] [libraries container shape-id reset?]
(log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?) (log/debug :msg "Sync shape direct" :shape (str shape-id) :reset? reset?)
(let [shape-inst (cp/get-shape container shape-id) (let [shape-inst (cph/get-shape container shape-id)
component (cp/get-component (:component-id shape-inst) component (cph/get-component libraries
(:component-file shape-inst) (:component-file shape-inst)
local-library (:component-id shape-inst))
libraries) shape-main (cph/get-shape component (:shape-ref shape-inst))
shape-main (cp/get-shape component (:shape-ref shape-inst))
initial-root? (:component-root? shape-inst) initial-root? (:component-root? shape-inst)
root-inst shape-inst root-inst shape-inst
root-main (cp/get-component-root component)] root-main (cph/get-component-root component)]
(if component (if component
(generate-sync-shape-direct-recursive container (generate-sync-shape-direct-recursive container
@ -683,9 +684,9 @@
(when set-remote-synced? (when set-remote-synced?
(change-remote-synced shape-inst container true))) (change-remote-synced shape-inst container true)))
children-inst (mapv #(cp/get-shape container %) children-inst (mapv #(cph/get-shape container %)
(:shapes shape-inst)) (:shapes shape-inst))
children-main (mapv #(cp/get-shape component %) children-main (mapv #(cph/get-shape component %)
(:shapes shape-main)) (:shapes shape-main))
only-inst (fn [child-inst] only-inst (fn [child-inst]
@ -743,20 +744,18 @@
(defn generate-sync-shape-inverse (defn generate-sync-shape-inverse
"Generate changes to update the component a shape is linked to, from "Generate changes to update the component a shape is linked to, from
the values in the shape and all its children." the values in the shape and all its children."
[page-id shape-id local-library libraries] [libraries container shape-id]
(log/debug :msg "Sync shape inverse" :shape (str shape-id)) (log/debug :msg "Sync shape inverse" :shape (str shape-id))
(let [container (cp/get-container page-id :page local-library) (let [shape-inst (cph/get-shape container shape-id)
shape-inst (cp/get-shape container shape-id) component (cph/get-component libraries
component (cp/get-component (:component-id shape-inst)
(:component-file shape-inst) (:component-file shape-inst)
local-library (:component-id shape-inst))
libraries) shape-main (cph/get-shape component (:shape-ref shape-inst))
shape-main (cp/get-shape component (:shape-ref shape-inst))
initial-root? (:component-root? shape-inst) initial-root? (:component-root? shape-inst)
root-inst shape-inst root-inst shape-inst
root-main (cp/get-component-root component)] root-main (cph/get-component-root component)]
(if component (if component
(generate-sync-shape-inverse-recursive container (generate-sync-shape-inverse-recursive container
@ -777,7 +776,7 @@
(if (nil? shape-main) (if (nil? shape-main)
;; This should not occur, but protect against it in any case ;; This should not occur, but protect against it in any case
empty-changes empty-changes
(let [component-container (cp/make-container component :component) (let [component-container (cph/make-container component :component)
omit-touched? false omit-touched? false
set-remote-synced? (not initial-root?) set-remote-synced? (not initial-root?)
@ -805,9 +804,9 @@
(when set-remote-synced? (when set-remote-synced?
(change-remote-synced shape-inst container true))) (change-remote-synced shape-inst container true)))
children-inst (mapv #(cp/get-shape container %) children-inst (mapv #(cph/get-shape container %)
(:shapes shape-inst)) (:shapes shape-inst))
children-main (mapv #(cp/get-shape component %) children-main (mapv #(cph/get-shape component %)
(:shapes shape-main)) (:shapes shape-main))
only-inst (fn [child-inst] only-inst (fn [child-inst]
@ -885,13 +884,13 @@
(transduce (map only-inst-cb) concat-changes changes children-inst) (transduce (map only-inst-cb) concat-changes changes children-inst)
:else :else
(if (cp/is-main-of child-main child-inst) (if (cph/is-main-of? child-main child-inst)
(recur (next children-inst) (recur (next children-inst)
(next children-main) (next children-main)
(concat-changes changes (both-cb child-inst child-main))) (concat-changes changes (both-cb child-inst child-main)))
(let [child-inst' (d/seek #(cp/is-main-of child-main %) children-inst) (let [child-inst' (d/seek #(cph/is-main-of? child-main %) children-inst)
child-main' (d/seek #(cp/is-main-of % child-inst) children-main)] child-main' (d/seek #(cph/is-main-of? % child-inst) children-main)]
(cond (cond
(nil? child-inst') (nil? child-inst')
(recur children-inst (recur children-inst
@ -919,13 +918,13 @@
(defn- add-shape-to-instance (defn- add-shape-to-instance
[component-shape index component container root-instance root-main omit-touched? set-remote-synced?] [component-shape index component container root-instance root-main omit-touched? set-remote-synced?]
(log/info :msg (str "ADD [P] " (:name component-shape))) (log/info :msg (str "ADD [P] " (:name component-shape)))
(let [component-parent-shape (cp/get-shape component (:parent-id component-shape)) (let [component-parent-shape (cph/get-shape component (:parent-id component-shape))
parent-shape (d/seek #(cp/is-main-of component-parent-shape %) parent-shape (d/seek #(cph/is-main-of? component-parent-shape %)
(cp/get-object-with-children (:id root-instance) (cph/get-children-with-self (:objects container)
(:objects container))) (:id root-instance)))
all-parents (vec (cons (:id parent-shape) all-parents (into [(:id parent-shape)]
(cp/get-parents (:id parent-shape) (cph/get-parent-ids (:objects container)
(:objects container)))) (:id parent-shape)))
update-new-shape (fn [new-shape original-shape] update-new-shape (fn [new-shape original-shape]
(let [new-shape (reposition-shape new-shape (let [new-shape (reposition-shape new-shape
@ -945,7 +944,7 @@
original-shape) original-shape)
[_ new-shapes _] [_ new-shapes _]
(cp/clone-object component-shape (cph/clone-object component-shape
(:id parent-shape) (:id parent-shape)
(get component :objects) (get component :objects)
update-new-shape update-new-shape
@ -978,20 +977,20 @@
:ignore-touched true})) :ignore-touched true}))
new-shapes)] new-shapes)]
(if (and (cp/touched-group? parent-shape :shapes-group) omit-touched?) (if (and (cph/touched-group? parent-shape :shapes-group) omit-touched?)
empty-changes empty-changes
[rchanges uchanges]))) [rchanges uchanges])))
(defn- add-shape-to-main (defn- add-shape-to-main
[shape index component page root-instance root-main] [shape index component page root-instance root-main]
(log/info :msg (str "ADD [C] " (:name shape))) (log/info :msg (str "ADD [C] " (:name shape)))
(let [parent-shape (cp/get-shape page (:parent-id shape)) (let [parent-shape (cph/get-shape page (:parent-id shape))
component-parent-shape (d/seek #(cp/is-main-of % parent-shape) component-parent-shape (d/seek #(cph/is-main-of? % parent-shape)
(cp/get-object-with-children (:id root-main) (cph/get-children-with-self (:objects component)
(:objects component))) (:id root-main)))
all-parents (vec (cons (:id component-parent-shape) all-parents (into [(:id component-parent-shape)]
(cp/get-parents (:id component-parent-shape) (cph/get-parent-ids (:objects component)
(:objects component)))) (:id component-parent-shape)))
update-new-shape (fn [new-shape _original-shape] update-new-shape (fn [new-shape _original-shape]
(reposition-shape new-shape (reposition-shape new-shape
@ -1005,7 +1004,7 @@
original-shape)) original-shape))
[_new-shape new-shapes updated-shapes] [_new-shape new-shapes updated-shapes]
(cp/clone-object shape (cph/clone-object shape
(:id component-parent-shape) (:id component-parent-shape)
(get page :objects) (get page :objects)
update-new-shape update-new-shape
@ -1057,12 +1056,12 @@
(defn- remove-shape (defn- remove-shape
[shape container omit-touched?] [shape container omit-touched?]
(log/info :msg (str "REMOVE-SHAPE " (log/info :msg (str "REMOVE-SHAPE "
(if (cp/page? container) "[P] " "[C] ") (if (cph/page? container) "[P] " "[C] ")
(:name shape))) (:name shape)))
(let [objects (get container :objects) (let [objects (get container :objects)
parents (cp/get-parents (:id shape) objects) parents (cph/get-parent-ids objects (:id shape))
parent (first parents) parent (first parents)
children (cp/get-children (:id shape) objects) children (cph/get-children-ids objects (:id shape))
rchanges [(make-change rchanges [(make-change
container container
@ -1080,7 +1079,7 @@
container container
(as-> {:type :add-obj (as-> {:type :add-obj
:id id :id id
:index (cp/position-on-parent id objects) :index (cph/get-position-on-parent objects id)
:parent-id (:parent-id shape') :parent-id (:parent-id shape')
:ignore-touched true :ignore-touched true
:obj shape'} $ :obj shape'} $
@ -1096,20 +1095,20 @@
{:type :reg-objects {:type :reg-objects
:shapes (vec parents)})])] :shapes (vec parents)})])]
(if (and (cp/touched-group? parent :shapes-group) omit-touched?) (if (and (cph/touched-group? parent :shapes-group) omit-touched?)
empty-changes empty-changes
[rchanges uchanges]))) [rchanges uchanges])))
(defn- move-shape (defn- move-shape
[shape index-before index-after container omit-touched?] [shape index-before index-after container omit-touched?]
(log/info :msg (str "MOVE " (log/info :msg (str "MOVE "
(if (cp/page? container) "[P] " "[C] ") (if (cph/page? container) "[P] " "[C] ")
(:name shape) (:name shape)
" " " "
index-before index-before
" -> " " -> "
index-after)) index-after))
(let [parent (cp/get-shape container (:parent-id shape)) (let [parent (cph/get-shape container (:parent-id shape))
rchanges [(make-change rchanges [(make-change
container container
@ -1126,7 +1125,7 @@
:index index-before :index index-before
:ignore-touched true})]] :ignore-touched true})]]
(if (and (cp/touched-group? parent :shapes-group) omit-touched?) (if (and (cph/touched-group? parent :shapes-group) omit-touched?)
empty-changes empty-changes
[rchanges uchanges]))) [rchanges uchanges])))
@ -1138,7 +1137,7 @@
empty-changes empty-changes
(do (do
(log/info :msg (str "CHANGE-TOUCHED " (log/info :msg (str "CHANGE-TOUCHED "
(if (cp/page? container) "[P] " "[C] ") (if (cph/page? container) "[P] " "[C] ")
(:name dest-shape)) (:name dest-shape))
:options options) :options options)
(let [new-touched (cond (let [new-touched (cond
@ -1174,7 +1173,7 @@
empty-changes empty-changes
(do (do
(log/info :msg (str "CHANGE-REMOTE-SYNCED? " (log/info :msg (str "CHANGE-REMOTE-SYNCED? "
(if (cp/page? container) "[P] " "[C] ") (if (cph/page? container) "[P] " "[C] ")
(:name shape)) (:name shape))
:remote-synced? remote-synced?) :remote-synced? remote-synced?)
(let [rchanges [(make-change (let [rchanges [(make-change
@ -1205,7 +1204,7 @@
(log/info :msg (str "SYNC " (log/info :msg (str "SYNC "
(:name origin-shape) (:name origin-shape)
" -> " " -> "
(if (cp/page? container) "[P] " "[C] ") (if (cph/page? container) "[P] " "[C] ")
(:name dest-shape))) (:name dest-shape)))
(let [; To synchronize geometry attributes we need to make a prior (let [; To synchronize geometry attributes we need to make a prior
@ -1224,8 +1223,8 @@
(let [attr (first attrs)] (let [attr (first attrs)]
(if (nil? attr) (if (nil? attr)
(let [all-parents (vec (or (cp/get-parents (:id dest-shape) (let [all-parents (cph/get-parent-ids (:objects container)
(:objects container)) [])) (:id dest-shape))
rchanges [(make-change rchanges [(make-change
container container
{:type :mod-obj {:type :mod-obj
@ -1285,7 +1284,7 @@
(defn- make-change (defn- make-change
[container change] [container change]
(if (cp/page? container) (if (cph/page? container)
(assoc change :page-id (:id container)) (assoc change :page-id (:id container))
(assoc change :component-id (:id container)))) (assoc change :component-id (:id container))))

View file

@ -6,7 +6,7 @@
(ns app.main.data.workspace.path.changes (ns app.main.data.workspace.path.changes
(:require (:require
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.path.helpers :as helpers] [app.main.data.workspace.path.helpers :as helpers]
@ -24,7 +24,7 @@
(let [shape-id (:id shape) (let [shape-id (:id shape)
frame-id (:frame-id shape) frame-id (:frame-id shape)
parent-id (:parent-id shape) parent-id (:parent-id shape)
parent-index (cp/position-on-parent shape-id objects) parent-index (cph/get-position-on-parent objects shape-id)
[old-points old-selrect] (helpers/content->points+selrect shape old-content) [old-points old-selrect] (helpers/content->points+selrect shape old-content)
[new-points new-selrect] (helpers/content->points+selrect shape new-content) [new-points new-selrect] (helpers/content->points+selrect shape new-content)

View file

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

View file

@ -6,8 +6,8 @@
(ns app.main.data.workspace.path.shapes-to-path (ns app.main.data.workspace.path.shapes-to-path
(:require (:require
[app.common.pages :as cp]
[app.common.pages.changes-builder :as cb] [app.common.pages.changes-builder :as cb]
[app.common.pages.helpers :as cph]
[app.common.path.shapes-to-path :as upsp] [app.common.path.shapes-to-path :as upsp]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
@ -24,7 +24,7 @@
children-ids children-ids
(into #{} (into #{}
(mapcat #(cp/get-children % objects)) (mapcat #(cph/get-children-ids objects %))
selected) selected)
changes changes

View file

@ -9,6 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.change :as spec.change] [app.common.spec.change :as spec.change]
[app.common.spec.file :as spec.file] [app.common.spec.file :as spec.file]
@ -658,7 +659,7 @@
(rx/map extract-frame-changes) (rx/map extract-frame-changes)
(rx/share)) (rx/share))
frames (-> state wsh/lookup-page-objects cp/select-frames) frames (-> state wsh/lookup-page-objects cph/get-frames)
no-thumb-frames (->> frames no-thumb-frames (->> frames
(filter (comp nil? :thumbnail)) (filter (comp nil? :thumbnail))
(mapv :id))] (mapv :id))]

View file

@ -10,7 +10,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.spec.interactions :as cti] [app.common.spec.interactions :as cti]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -151,7 +151,7 @@
(conj id))] (conj id))]
(-> state (-> state
(assoc-in [:workspace-local :selected] (assoc-in [:workspace-local :selected]
(cp/expand-region-selection objects selection)))))))) (cph/expand-region-selection objects selection))))))))
(defn select-shapes (defn select-shapes
[ids] [ids]
@ -173,37 +173,21 @@
(watch [_ state _] (watch [_ state _]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
new-selected (let [selected-objs
(->> (wsh/lookup-selected state)
(map #(get objects %)))
frame-ids selected (let [frame-ids (into #{} (comp
(reduce #(conj %1 (:frame-id %2)) (map (d/getf objects))
#{} (map :frame-id))
selected-objs) (wsh/lookup-selected state))
frame-id (if (= 1 (count frame-ids))
(first frame-ids)
uuid/zero)]
(cph/get-immediate-children objects frame-id))
common-frame-id selected (into (d/ordered-set)
(when (= (count frame-ids) 1) (first frame-ids))] (remove :blocked)
selected)]
(if (and common-frame-id (rx/of (select-shapes selected))))))
(not= (:id common-frame-id) uuid/zero))
(-> (get objects common-frame-id)
:shapes)
(->> (cp/select-toplevel-shapes objects
{:include-frames? true
:include-frame-children? false})
(map :id))))
is-not-blocked (fn [shape-id] (not (get-in state [:workspace-data
:pages-index page-id
:objects shape-id
:blocked] false)))
selected-ids (into lks/empty-linked-set
(comp (filter some?)
(filter is-not-blocked))
new-selected)]
(rx/of (select-shapes selected-ids))))))
(defn deselect-all (defn deselect-all
"Clear all possible state of drawing, edition "Clear all possible state of drawing, edition
@ -250,7 +234,7 @@
:include-frames? true :include-frames? true
:ignore-groups? ignore-groups? :ignore-groups? ignore-groups?
:full-frame? true}) :full-frame? true})
(rx/map #(cp/clean-loops objects %)) (rx/map #(cph/clean-loops objects %))
(rx/map #(into initial-set (filter (comp not blocked?)) %)) (rx/map #(into initial-set (filter (comp not blocked?)) %))
(rx/map select-shapes))))))) (rx/map select-shapes)))))))
@ -314,11 +298,8 @@
[objects page-id unames ids delta] [objects page-id unames ids delta]
(let [unames (volatile! unames) (let [unames (volatile! unames)
update-unames! (fn [new-name] (vswap! unames conj new-name)) update-unames! (fn [new-name] (vswap! unames conj new-name))
all-ids (reduce (fn [ids-set id] all-ids (reduce #(into %1 (cons %2 (cph/get-children-ids objects %2))) #{} ids)
(into ids-set (cons id (cp/get-children id objects)))) ids-map (into {} (map #(vector % (uuid/next))) all-ids)]
#{}
ids)
ids-map (into {} (map #(vector % (uuid/next)) all-ids))]
(loop [ids (seq ids) (loop [ids (seq ids)
chgs []] chgs []]
(if ids (if ids
@ -337,7 +318,7 @@
(let [process-id (let [process-id
(fn [index-map id] (fn [index-map id]
(let [parent-id (get-in objects [id :parent-id]) (let [parent-id (get-in objects [id :parent-id])
parent-index (cp/position-on-parent id objects)] parent-index (cph/get-position-on-parent objects id)]
(update index-map parent-id (fnil conj []) [id parent-index]))) (update index-map parent-id (fnil conj []) [id parent-index])))
index-map (reduce process-id {} ids)] index-map (reduce process-id {} ids)]
(-> changes (update-indices index-map)))) (-> changes (update-indices index-map))))
@ -345,7 +326,7 @@
(defn- prepare-duplicate-change (defn- prepare-duplicate-change
[objects page-id unames update-unames! ids-map id delta] [objects page-id unames update-unames! ids-map id delta]
(let [obj (get objects id)] (let [obj (get objects id)]
(if (= :frame (:type obj)) (if (cph/frame-shape? obj)
(prepare-duplicate-frame-change objects page-id unames update-unames! ids-map obj delta) (prepare-duplicate-frame-change objects page-id unames update-unames! ids-map obj delta)
(prepare-duplicate-shape-change objects page-id unames update-unames! ids-map obj delta (:frame-id obj) (:parent-id obj))))) (prepare-duplicate-shape-change objects page-id unames update-unames! ids-map obj delta (:frame-id obj) (:parent-id obj)))))
@ -449,7 +430,7 @@
;; The default is leave normal shapes in place, but put ;; The default is leave normal shapes in place, but put
;; new frames to the right of the original. ;; new frames to the right of the original.
(if (= (:type obj) :frame) (if (cph/frame-shape? obj)
(gpt/point (+ (:width obj) 50) 0) (gpt/point (+ (:width obj) 50) 0)
(gpt/point 0 0)) (gpt/point 0 0))

View file

@ -7,7 +7,7 @@
(ns app.main.data.workspace.state-helpers (ns app.main.data.workspace.state-helpers
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp])) [app.common.pages.helpers :as cph]))
(defn lookup-page (defn lookup-page
([state] ([state]
@ -43,7 +43,7 @@
:or {omit-blocked? false}}] :or {omit-blocked? false}}]
(let [objects (lookup-page-objects state) (let [objects (lookup-page-objects state)
selected (->> (get-in state [:workspace-local :selected]) selected (->> (get-in state [:workspace-local :selected])
(cp/clean-loops objects)) (cph/clean-loops objects))
selectable? (fn [id] selectable? (fn [id]
(and (contains? objects id) (and (contains? objects id)
(or (not omit-blocked?) (or (not omit-blocked?)

View file

@ -12,7 +12,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :refer [max-safe-int min-safe-int]] [app.common.spec :refer [max-safe-int min-safe-int]]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
@ -456,7 +456,7 @@
(try (try
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
frame-id (cp/frame-id-by-position objects position) frame-id (cph/frame-id-by-position objects position)
selected (wsh/lookup-selected state) selected (wsh/lookup-selected state)
[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data) [vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)

View file

@ -10,7 +10,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.text :as txt] [app.common.text :as txt]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
@ -160,8 +160,9 @@
shape (get objects id) shape (get objects id)
update-fn #(update-shape % txt/is-root-node? attrs/merge attrs) update-fn #(update-shape % txt/is-root-node? attrs/merge attrs)
shape-ids (cond (= (:type shape) :text) [id]
(= (:type shape) :group) (cp/get-children id objects))] shape-ids (cond (cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids update-fn)))))) (rx/of (dch/update-shapes shape-ids update-fn))))))
@ -186,8 +187,9 @@
attrs)) attrs))
update-fn #(update-shape % txt/is-paragraph-node? merge-fn attrs) update-fn #(update-shape % txt/is-paragraph-node? merge-fn attrs)
shape-ids (cond (= (:type shape) :text) [id] shape-ids (cond
(= (:type shape) :group) (cp/get-children id objects))] (cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids update-fn)))))))) (rx/of (dch/update-shapes shape-ids update-fn))))))))
@ -208,8 +210,9 @@
(txt/is-paragraph-node? node))) (txt/is-paragraph-node? node)))
update-fn #(update-shape % update-node? attrs/merge attrs) update-fn #(update-shape % update-node? attrs/merge attrs)
shape-ids (cond (= (:type shape) :text) [id] shape-ids (cond
(= (:type shape) :group) (cp/get-children id objects))] (cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids update-fn))))))) (rx/of (dch/update-shapes shape-ids update-fn)))))))
;; --- RESIZE UTILS ;; --- RESIZE UTILS

View file

@ -12,7 +12,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
@ -144,9 +144,7 @@
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
shapes (->> shapes shapes (->> shapes
(remove #(get % :blocked false)) (remove #(get % :blocked false))
(mapcat (fn [shape] (mapcat #(cph/get-children objects (:id %)))
(->> (cp/get-children (:id shape) objects)
(map #(get objects %)))))
(concat shapes)) (concat shapes))
update-shape update-shape
@ -156,8 +154,6 @@
(update state :workspace-modifiers #(reduce update-shape % shapes))))))) (update state :workspace-modifiers #(reduce update-shape % shapes)))))))
(defn- apply-modifiers (defn- apply-modifiers
[ids] [ids]
(us/verify (s/coll-of uuid?) ids) (us/verify (s/coll-of uuid?) ids)
@ -165,8 +161,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
children-ids (->> ids (mapcat #(cp/get-children % objects))) ids-with-children (into (vec ids) (mapcat #(cph/get-children-ids objects %)) ids)
ids-with-children (d/concat-vec children-ids ids)
object-modifiers (get state :workspace-modifiers) object-modifiers (get state :workspace-modifiers)
ignore-tree (get-ignore-tree object-modifiers objects ids)] ignore-tree (get-ignore-tree object-modifiers objects ids)]
@ -203,7 +198,7 @@
shape shape
(nil? root) (nil? root)
(cp/get-root-shape shape objects) (cph/get-root-shape objects shape)
:else root) :else root)
@ -213,7 +208,7 @@
transformed-shape transformed-shape
(nil? transformed-root) (nil? transformed-root)
(cp/get-root-shape transformed-shape objects) (cph/get-root-shape objects transformed-shape)
:else transformed-root) :else transformed-root)
@ -663,10 +658,10 @@
(let [position @ms/mouse-position (let [position @ms/mouse-position
page-id (:current-page-id state) page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
frame-id (cp/frame-id-by-position objects position) frame-id (cph/frame-id-by-position objects position)
moving-shapes (->> ids moving-shapes (->> ids
(cp/clean-loops objects) (cph/clean-loops objects)
(map #(get objects %)) (map #(get objects %))
(remove #(or (nil? %) (remove #(or (nil? %)
(= (:frame-id %) frame-id)))) (= (:frame-id %) frame-id))))
@ -683,7 +678,7 @@
{:type :mov-objects {:type :mov-objects
:page-id page-id :page-id page-id
:parent-id (:parent-id shape) :parent-id (:parent-id shape)
:index (cp/get-index-in-parent objects (:id shape)) :index (cph/get-index-in-parent objects (:id shape))
:shapes [(:id shape)]})))] :shapes [(:id shape)]})))]
(when-not (empty? uch) (when-not (empty? uch)

View file

@ -9,7 +9,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.path.commands :as upc] [app.common.path.commands :as upc]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.store :as st] [app.main.store :as st]
@ -218,7 +218,7 @@
:media :media
:typographies :typographies
:components])) :components]))
st/state)) st/state =))
(def workspace-libraries (def workspace-libraries
(l/derived :workspace-libraries st/state)) (l/derived :workspace-libraries st/state))
@ -246,7 +246,7 @@
(l/derived :options workspace-page)) (l/derived :options workspace-page))
(def workspace-frames (def workspace-frames
(l/derived cp/select-frames workspace-page-objects =)) (l/derived cph/get-frames workspace-page-objects =))
(def workspace-editor (def workspace-editor
(l/derived :workspace-editor st/state)) (l/derived :workspace-editor st/state))
@ -277,8 +277,10 @@
(let [selector (let [selector
(fn [state] (fn [state]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
modifiers (:workspace-modifiers state)] modifiers (:workspace-modifiers state)
(as-> (cp/select-children id objects) $ children (->> (cph/get-children-ids objects id)
(select-keys objects))]
(as-> children $
(gsh/merge-modifiers $ modifiers) (gsh/merge-modifiers $ modifiers)
(d/mapm (set-content-modifiers state) $))))] (d/mapm (set-content-modifiers state) $))))]
(l/derived selector st/state =))) (l/derived selector st/state =)))
@ -293,7 +295,7 @@
(defn is-child-selected? (defn is-child-selected?
[id] [id]
(letfn [(selector [{:keys [selected objects]}] (letfn [(selector [{:keys [selected objects]}]
(let [children (cp/get-children id objects)] (let [children (cph/get-children-ids objects id)]
(some #(contains? selected %) children)))] (some #(contains? selected %) children)))]
(l/derived selector selected-data =))) (l/derived selector selected-data =)))
@ -307,7 +309,7 @@
(def selected-shapes-with-children (def selected-shapes-with-children
(letfn [(selector [{:keys [selected objects]}] (letfn [(selector [{:keys [selected objects]}]
(let [xform (comp (remove nil?) (let [xform (comp (remove nil?)
(mapcat #(cp/get-children % objects))) (mapcat #(cph/get-children-ids objects %)))
shapes (into selected xform selected)] shapes (into selected xform selected)]
(mapv (d/getf objects) shapes)))] (mapv (d/getf objects) shapes)))]
(l/derived selector selected-data =))) (l/derived selector selected-data =)))

View file

@ -19,8 +19,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.uuid :as uuid]
[app.config :as cfg] [app.config :as cfg]
[app.main.fonts :as fonts] [app.main.fonts :as fonts]
[app.main.ui.shapes.bool :as bool] [app.main.ui.shapes.bool :as bool]
@ -59,8 +58,7 @@
(defn- calculate-dimensions (defn- calculate-dimensions
[{:keys [objects] :as data} vport] [{:keys [objects] :as data} vport]
(let [shapes (cp/select-toplevel-shapes objects {:include-frames? true (let [shapes (cph/get-immediate-children objects)
:include-frame-children? false})
to-finite (fn [val fallback] (if (not (mth/finite? val)) fallback val)) to-finite (fn [val fallback] (if (not (mth/finite? val)) fallback val))
rect (cond->> (gsh/selection-rect shapes) rect (cond->> (gsh/selection-rect shapes)
(some? vport) (some? vport)
@ -101,11 +99,9 @@
bool-shape (bool/bool-shape shape-wrapper)] bool-shape (bool/bool-shape shape-wrapper)]
(mf/fnc bool-wrapper (mf/fnc bool-wrapper
[{:keys [shape] :as props}] [{:keys [shape] :as props}]
(let [childs (mf/use-memo (let [childs (mf/with-memo [(:id shape) objects]
(mf/deps (:id shape) objects) (->> (cph/get-children-ids objects (:id shape))
(fn [] (select-keys objects)))]
(->> (cp/get-children (:id shape) objects)
(select-keys objects))))]
[:& bool-shape {:shape shape :childs childs}])))) [:& bool-shape {:shape shape :childs childs}]))))
(defn svg-raw-wrapper-factory (defn svg-raw-wrapper-factory
@ -166,15 +162,12 @@
[{:keys [data width height thumbnails? embed? include-metadata?] :as props [{:keys [data width height thumbnails? embed? include-metadata?] :as props
:or {embed? false include-metadata? false}}] :or {embed? false include-metadata? false}}]
(let [objects (:objects data) (let [objects (:objects data)
root (get objects uuid/zero) shapes (cph/get-immediate-children objects)
shapes
(->> (:shapes root)
(map #(get objects %)))
root-children root-children
(->> shapes (->> shapes
(filter #(not= :frame (:type %))) (remove cph/frame-shape?)
(mapcat #(cp/get-object-with-children (:id %) objects))) (mapcat #(cph/get-children-with-self objects (:id %))))
vport (when (and (some? width) (some? height)) vport (when (and (some? width) (some? height))
{:width width :height height}) {:width width :height height})
@ -237,7 +230,7 @@
objects objects
(mf/with-memo [frame-id objects modifier] (mf/with-memo [frame-id objects modifier]
(let [update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)] (let [update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)]
(->> (cp/get-children frame-id objects) (->> (cph/get-children-ids objects frame-id)
(into [frame-id]) (into [frame-id])
(reduce update-fn objects)))) (reduce update-fn objects))))
@ -280,7 +273,7 @@
(mf/use-memo (mf/use-memo
(mf/deps modifier objects group-id) (mf/deps modifier objects group-id)
(fn [] (fn []
(let [modifier-ids (concat [group-id] (cp/get-children group-id objects)) (let [modifier-ids (cons group-id (cph/get-children-ids objects group-id))
update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier) update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)
modifiers (reduce update-fn {} modifier-ids)] modifiers (reduce update-fn {} modifier-ids)]
(gsh/merge-modifiers objects modifiers)))) (gsh/merge-modifiers objects modifiers))))
@ -334,7 +327,7 @@
(mf/use-memo (mf/use-memo
(mf/deps modifier id objects) (mf/deps modifier id objects)
(fn [] (fn []
(let [modifier-ids (concat [id] (cp/get-children id objects)) (let [modifier-ids (cons id (cph/get-children-ids objects id))
update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)] update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)]
(reduce update-fn objects modifier-ids)))) (reduce update-fn objects modifier-ids))))

View file

@ -10,7 +10,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.uuid :refer [zero]] [app.common.uuid :refer [zero]]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.worker :as uw] [app.main.worker :as uw]
@ -202,9 +202,9 @@
:frame-id (->> shapes first :frame-id) :frame-id (->> shapes first :frame-id)
:include-frames? true :include-frames? true
:rect area-selrect}) :rect area-selrect})
(rx/map #(cp/clean-loops objects %)) (rx/map #(cph/clean-loops objects %))
(rx/map #(set/difference % (into #{} (map :id shapes)))) (rx/map #(set/difference % (into #{} (map :id shapes))))
(rx/map (fn [ids] (map #(get objects %) ids))))) (rx/map #(map (d/getf objects) %))))
(defn closest-distance-snap (defn closest-distance-snap
[page-id shapes objects zoom movev] [page-id shapes objects zoom movev]

View file

@ -10,7 +10,7 @@
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.fonts :as df] [app.main.data.fonts :as df]
[app.main.render :as render] [app.main.render :as render]
@ -60,7 +60,7 @@
(gpt/negate) (gpt/negate)
(gmt/translate-matrix)) (gmt/translate-matrix))
mod-ids (cons frame-id (cp/get-children frame-id objects)) mod-ids (cons frame-id (cph/get-children-ids objects frame-id))
updt-fn #(-> %1 updt-fn #(-> %1
(assoc-in [%2 :modifiers :displacement] modifier) (assoc-in [%2 :modifiers :displacement] modifier)
(update %2 gsh/transform-shape)) (update %2 gsh/transform-shape))
@ -133,7 +133,7 @@
[objects object-id] [objects object-id]
(if (uuid/zero? object-id) (if (uuid/zero? object-id)
(let [object (get objects object-id) (let [object (get objects object-id)
shapes (cp/select-toplevel-shapes objects {:include-frames? true}) shapes (cph/get-immediate-children objects)
srect (gsh/selection-rect shapes) srect (gsh/selection-rect shapes)
object (merge object (select-keys srect [:x :y :width :height])) object (merge object (select-keys srect [:x :y :width :height]))
object (gsh/transform-shape object) object (gsh/transform-shape object)

View file

@ -8,7 +8,7 @@
"The main container for a frame in handoff mode" "The main container for a frame in handoff mode"
(:require (:require
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.shapes.bool :as bool] [app.main.ui.shapes.bool :as bool]
@ -117,11 +117,11 @@
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [shape (unchecked-get props "shape") (let [shape (unchecked-get props "shape")
children-ids (cp/get-children (:id shape) objects) children (->> (cph/get-children-ids objects (:id shape))
childs (select-keys objects children-ids) (select-keys objects))
props (-> (obj/new) props (-> (obj/new)
(obj/merge! props) (obj/merge! props)
(obj/merge! #js {:childs childs}))] (obj/merge! #js {:childs children}))]
[:> bool-wrapper props])))) [:> bool-wrapper props]))))
(defn svg-raw-container-factory (defn svg-raw-container-factory

View file

@ -9,7 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec.page :as csp] [app.common.spec.page :as csp]
[app.main.data.comments :as dcm] [app.main.data.comments :as dcm]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
@ -35,11 +35,10 @@
update-fn #(d/update-when %1 %2 assoc-in [:modifiers :displacement] modifier)] update-fn #(d/update-when %1 %2 assoc-in [:modifiers :displacement] modifier)]
(->> (cp/get-children frame-id objects) (->> (cph/get-children-ids objects frame-id)
(into [frame-id]) (into [frame-id])
(reduce update-fn objects))))) (reduce update-fn objects)))))
(mf/defc viewport (mf/defc viewport
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [page interactions-mode frame base-frame frame-offset size]}] [{:keys [page interactions-mode frame base-frame frame-offset size]}]

View file

@ -10,7 +10,7 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as geom]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec.interactions :as cti] [app.common.spec.interactions :as cti]
[app.main.data.viewer :as dv] [app.main.data.viewer :as dv]
[app.main.refs :as refs] [app.main.refs :as refs]
@ -330,7 +330,8 @@
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [shape (unchecked-get props "shape") (let [shape (unchecked-get props "shape")
childs (select-keys objects (cp/get-children (:id shape) objects)) childs (->> (cph/get-children-ids objects (:id shape))
(select-keys objects))
props (obj/merge! #js {} props props (obj/merge! #js {} props
#js {:childs childs #js {:childs childs
:objects objects})] :objects objects})]
@ -399,7 +400,7 @@
update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier) update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)
frame-id (:id frame) frame-id (:id frame)
modifier-ids (into [frame-id] (cp/get-children frame-id objects)) modifier-ids (into [frame-id] (cph/get-children-ids objects frame-id))
objects (reduce update-fn objects modifier-ids) objects (reduce update-fn objects modifier-ids)
frame (assoc-in frame [:modifiers :displacement] modifier) frame (assoc-in frame [:modifiers :displacement] modifier)

View file

@ -103,10 +103,8 @@
(let [show-menu? (mf/use-state false) (let [show-menu? (mf/use-state false)
show-sub-menu? (mf/use-state false) show-sub-menu? (mf/use-state false)
editing? (mf/use-state false) editing? (mf/use-state false)
frames (mf/deref refs/workspace-frames)
edit-input-ref (mf/use-ref nil) edit-input-ref (mf/use-ref nil)
frames (mf/deref refs/workspace-frames)
add-shared-fn add-shared-fn
(st/emitf (dw/set-file-shared (:id file) true)) (st/emitf (dw/set-file-shared (:id file) true))

View file

@ -12,9 +12,7 @@
others are defined using a generic wrapper implemented in others are defined using a generic wrapper implemented in
common." common."
(:require (:require
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.uuid :as uuid]
[app.main.refs :as refs]
[app.main.ui.shapes.circle :as circle] [app.main.ui.shapes.circle :as circle]
[app.main.ui.shapes.image :as image] [app.main.ui.shapes.image :as image]
[app.main.ui.shapes.rect :as rect] [app.main.ui.shapes.rect :as rect]
@ -29,7 +27,6 @@
[app.main.ui.workspace.shapes.text :as text] [app.main.ui.workspace.shapes.text :as text]
[app.util.object :as obj] [app.util.object :as obj]
[debug :refer [debug?]] [debug :refer [debug?]]
[okulary.core :as l]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(declare shape-wrapper) (declare shape-wrapper)
@ -42,31 +39,23 @@
(def image-wrapper (common/generic-wrapper-factory image/image-shape)) (def image-wrapper (common/generic-wrapper-factory image/image-shape))
(def rect-wrapper (common/generic-wrapper-factory rect/rect-shape)) (def rect-wrapper (common/generic-wrapper-factory rect/rect-shape))
(defn make-is-moving-ref
[id]
(fn []
(let [check-moving (fn [local]
(and (= :move (:transform local))
(contains? (:selected local) id)))]
(l/derived check-moving refs/workspace-local))))
(mf/defc root-shape (mf/defc root-shape
"Draws the root shape of the viewport and recursively all the shapes" "Draws the root shape of the viewport and recursively all the shapes"
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [objects (obj/get props "objects") (let [objects (obj/get props "objects")
active-frames (obj/get props "active-frames") active-frames (obj/get props "active-frames")
root-shapes (get-in objects [uuid/zero :shapes]) shapes (cph/get-immediate-children objects)]
shapes (->> root-shapes (mapv #(get objects %)))
root-children (->> shapes
(filter #(not= :frame (:type %)))
(mapcat #(cp/get-object-with-children (:id %) objects)))]
[:* [:*
[:& ff/fontfaces-style {:shapes root-children}] ;; Render font faces only for shapes that are part of the root
;; frame but don't belongs to any other frame.
(let [xform (comp
(remove cph/frame-shape?)
(mapcat #(cph/get-children-with-self objects (:id %))))]
[:& ff/fontfaces-style {:shapes (into [] xform shapes)}])
(for [item shapes] (for [item shapes]
(if (= (:type item) :frame) (if (cph/frame-shape? item)
[:& frame-wrapper {:shape item [:& frame-wrapper {:shape item
:key (:id item) :key (:id item)
:objects objects :objects objects

View file

@ -7,7 +7,7 @@
(ns app.main.ui.workspace.shapes.frame (ns app.main.ui.workspace.shapes.frame
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
[app.main.ui.shapes.frame :as frame] [app.main.ui.shapes.frame :as frame]
[app.main.ui.shapes.shape :refer [shape-container]] [app.main.ui.shapes.shape :refer [shape-container]]
@ -105,7 +105,7 @@
(hooks/use-equal-memo)) (hooks/use-equal-memo))
all-children all-children
(-> (cp/get-children-objects (:id shape) objects) (-> (cph/get-children objects (:id shape))
(hooks/use-equal-memo)) (hooks/use-equal-memo))
show-thumbnail? show-thumbnail?

View file

@ -8,7 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.media :as cm] [app.common.media :as cm]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.text :as txt] [app.common.text :as txt]
[app.config :as cfg] [app.config :as cfg]
@ -43,18 +43,18 @@
[potok.core :as ptk] [potok.core :as ptk]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
; TODO: refactor to remove duplicate code and less parameter passing. ;; TODO: refactor to remove duplicate code and less parameter passing.
; - Move all state to [:workspace-local :assets-bar file-id :open-boxes {} ;; - Move all state to [:workspace-local :assets-bar file-id :open-boxes {}
; :open-groups {} ;; :open-groups {}
; :reverse-sort? ;; :reverse-sort?
; :listing-thumbs? ;; :listing-thumbs?
; :selected-assets {}] ;; :selected-assets {}]
; - Move selection code to independent functions that receive the state as a parameter. ;; - Move selection code to independent functions that receive the state as a parameter.
; ;;
; TODO: change update operations to admit multiple ids, thus avoiding the need of ;; TODO: change update operations to admit multiple ids, thus avoiding the need of
; emitting many events and opening an undo transaction. Also move the logic ;; emitting many events and opening an undo transaction. Also move the logic
; of grouping, deleting, etc. to events in the data module, since now the ;; of grouping, deleting, etc. to events in the data module, since now the
; selection info is in the global state. ;; selection info is in the global state.
;; ---- Group assets management ---- ;; ---- Group assets management ----
@ -74,7 +74,7 @@
(compare (d/name key1) (d/name key2))))] (compare (d/name key1) (d/name key2))))]
(when-not (empty? assets) (when-not (empty? assets)
(reduce (fn [groups asset] (reduce (fn [groups asset]
(let [path-vector (cp/split-path (or (:path asset) ""))] (let [path-vector (cph/split-path (or (:path asset) ""))]
(update-in groups (conj path-vector "") (update-in groups (conj path-vector "")
(fn [group] (fn [group]
(if-not group (if-not group
@ -86,30 +86,30 @@
(defn add-group (defn add-group
[asset group-name] [asset group-name]
(-> (:path asset) (-> (:path asset)
(cp/merge-path-item group-name) (cph/merge-path-item group-name)
(cp/merge-path-item (:name asset)))) (cph/merge-path-item (:name asset))))
(defn rename-group (defn rename-group
[asset path last-path] [asset path last-path]
(-> (:path asset) (-> (:path asset)
(str/slice 0 (count path)) (str/slice 0 (count path))
(cp/split-path) (cph/split-path)
butlast butlast
(vec) (vec)
(conj last-path) (conj last-path)
(cp/join-path) (cph/join-path)
(str (str/slice (:path asset) (count path))) (str (str/slice (:path asset) (count path)))
(cp/merge-path-item (:name asset)))) (cph/merge-path-item (:name asset))))
(defn ungroup (defn ungroup
[asset path] [asset path]
(-> (:path asset) (-> (:path asset)
(str/slice 0 (count path)) (str/slice 0 (count path))
(cp/split-path) (cph/split-path)
butlast butlast
(cp/join-path) (cph/join-path)
(str (str/slice (:path asset) (count path))) (str (str/slice (:path asset) (count path)))
(cp/merge-path-item (:name asset)))) (cph/merge-path-item (:name asset))))
(s/def ::asset-name ::us/not-empty-string) (s/def ::asset-name ::us/not-empty-string)
(s/def ::name-group-form (s/def ::name-group-form
@ -225,7 +225,7 @@
(mf/defc asset-group-title (mf/defc asset-group-title
[{:keys [file-id box path group-open? on-rename on-ungroup]}] [{:keys [file-id box path group-open? on-rename on-ungroup]}]
(when-not (empty? path) (when-not (empty? path)
(let [[other-path last-path truncated] (cp/compact-path path 35) (let [[other-path last-path truncated] (cph/compact-path path 35)
menu-state (mf/use-state auto-pos-menu-state) menu-state (mf/use-state auto-pos-menu-state)
on-fold-group on-fold-group
@ -286,11 +286,11 @@
:cell-name @listing-thumbs? :cell-name @listing-thumbs?
:item-name (not @listing-thumbs?) :item-name (not @listing-thumbs?)
:editing renaming?) :editing renaming?)
:value (cp/merge-path-item (:path component) (:name component)) :value (cph/merge-path-item (:path component) (:name component))
:tooltip (cp/merge-path-item (:path component) (:name component)) :tooltip (cph/merge-path-item (:path component) (:name component))
:display-value (if @listing-thumbs? :display-value (if @listing-thumbs?
(:name component) (:name component)
(cp/compact-name (:path component) (cph/compact-name (:path component)
(:name component))) (:name component)))
:editing? renaming? :editing? renaming?
:disable-dbl-click? true :disable-dbl-click? true
@ -329,7 +329,7 @@
(for [[path-item content] groups] (for [[path-item content] groups]
(when-not (empty? path-item) (when-not (empty? path-item)
[:& components-group {:file-id file-id [:& components-group {:file-id file-id
:prefix (cp/merge-path-item prefix path-item) :prefix (cph/merge-path-item prefix path-item)
:groups content :groups content
:open-groups open-groups :open-groups open-groups
:renaming renaming :renaming renaming
@ -538,11 +538,11 @@
:cell-name @listing-thumbs? :cell-name @listing-thumbs?
:item-name (not @listing-thumbs?) :item-name (not @listing-thumbs?)
:editing renaming?) :editing renaming?)
:value (cp/merge-path-item (:path object) (:name object)) :value (cph/merge-path-item (:path object) (:name object))
:tooltip (cp/merge-path-item (:path object) (:name object)) :tooltip (cph/merge-path-item (:path object) (:name object))
:display-value (if @listing-thumbs? :display-value (if @listing-thumbs?
(:name object) (:name object)
(cp/compact-name (:path object) (cph/compact-name (:path object)
(:name object))) (:name object)))
:editing? renaming? :editing? renaming?
:disable-dbl-click? true :disable-dbl-click? true
@ -581,7 +581,7 @@
(for [[path-item content] groups] (for [[path-item content] groups]
(when-not (empty? path-item) (when-not (empty? path-item)
[:& graphics-group {:file-id file-id [:& graphics-group {:file-id file-id
:prefix (cp/merge-path-item prefix path-item) :prefix (cph/merge-path-item prefix path-item)
:groups content :groups content
:open-groups open-groups :open-groups open-groups
:renaming renaming :renaming renaming
@ -808,7 +808,7 @@
edit-color edit-color
(fn [new-color] (fn [new-color]
(let [old-data (-> (select-keys color [:id :file-id]) (let [old-data (-> (select-keys color [:id :file-id])
(assoc :name (cp/merge-path-item (:path color) (:name color)))) (assoc :name (cph/merge-path-item (:path color) (:name color))))
updated-color (merge new-color old-data)] updated-color (merge new-color old-data)]
(st/emit! (dwl/update-color updated-color file-id)))) (st/emit! (dwl/update-color updated-color file-id))))
@ -890,7 +890,7 @@
:on-blur input-blur :on-blur input-blur
:on-key-down input-key-down :on-key-down input-key-down
:auto-focus true :auto-focus true
:default-value (cp/merge-path-item (:path color) (:name color))}] :default-value (cph/merge-path-item (:path color) (:name color))}]
[:div.name-block {:on-double-click rename-color-clicked} [:div.name-block {:on-double-click rename-color-clicked}
(:name color) (:name color)
@ -945,7 +945,7 @@
(for [[path-item content] groups] (for [[path-item content] groups]
(when-not (empty? path-item) (when-not (empty? path-item)
[:& colors-group {:file-id file-id [:& colors-group {:file-id file-id
:prefix (cp/merge-path-item prefix path-item) :prefix (cph/merge-path-item prefix path-item)
:key (str "group-" path-item) :key (str "group-" path-item)
:groups content :groups content
:open-groups open-groups :open-groups open-groups
@ -1120,7 +1120,7 @@
(for [[path-item content] groups] (for [[path-item content] groups]
(when-not (empty? path-item) (when-not (empty? path-item)
[:& typographies-group {:file-id file-id [:& typographies-group {:file-id file-id
:prefix (cp/merge-path-item prefix path-item) :prefix (cph/merge-path-item prefix path-item)
:groups content :groups content
:open-groups open-groups :open-groups open-groups
:file file :file file
@ -1379,7 +1379,7 @@
(matches-search (:value item "!$!") (:term filters))))) (matches-search (:value item "!$!") (:term filters)))))
; Sort by folder order, but putting all "root" items always first, ; Sort by folder order, but putting all "root" items always first,
; independently of sort order. ; independently of sort order.
(sort-by #(str/lower (cp/merge-path-item (if (empty? (:path %)) (sort-by #(str/lower (cph/merge-path-item (if (empty? (:path %))
(if reverse-sort? "z" "a") (if reverse-sort? "z" "a")
(:path %)) (:path %))
(:name %))) (:name %)))

View file

@ -7,7 +7,7 @@
(ns app.main.ui.workspace.sidebar.layers (ns app.main.ui.workspace.sidebar.layers
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
@ -58,18 +58,16 @@
(when (kbd/enter? event) (accept-edit)) (when (kbd/enter? event) (accept-edit))
(when (kbd/esc? event) (cancel-edit)))] (when (kbd/esc? event) (cancel-edit)))]
(mf/use-effect (mf/with-effect [shape-for-rename]
(mf/deps shape-for-rename) (when (and (= shape-for-rename (:id shape))
#(when (and (= shape-for-rename (:id shape))
(not (:edition @local))) (not (:edition @local)))
(start-edit))) (start-edit)))
(mf/use-effect (mf/with-effect [(:edition @local)]
(mf/deps (:edition @local)) (when (:edition @local)
#(when (:edition @local)
(let [name-input (mf/ref-val name-ref)] (let [name-input (mf/ref-val name-ref)]
(dom/select-text! name-input)) (dom/select-text! name-input)
nil)) nil)))
(if (:edition @local) (if (:edition @local)
[:input.element-name [:input.element-name
@ -94,7 +92,8 @@
[{:keys [index item selected objects] :as props}] [{:keys [index item selected objects] :as props}]
(let [id (:id item) (let [id (:id item)
selected? (contains? selected id) selected? (contains? selected id)
container? (or (= (:type item) :frame) (= (:type item) :group)) container? (or (cph/frame-shape? item)
(cph/group-shape? item))
disable-drag (mf/use-state false) disable-drag (mf/use-state false)
@ -160,7 +159,7 @@
(if (= side :center) (if (= side :center)
(st/emit! (dw/relocate-selected-shapes (:id item) 0)) (st/emit! (dw/relocate-selected-shapes (:id item) 0))
(let [to-index (if (= side :top) (inc index) index) (let [to-index (if (= side :top) (inc index) index)
parent-id (cp/get-parent (:id item) objects)] parent-id (cph/get-parent-id objects (:id item))]
(st/emit! (dw/relocate-selected-shapes parent-id to-index))))) (st/emit! (dw/relocate-selected-shapes parent-id to-index)))))
on-hold on-hold

View file

@ -6,7 +6,7 @@
(ns app.main.ui.workspace.sidebar.options.menus.component (ns app.main.ui.workspace.sidebar.options.menus.component
(:require (:require
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.data.modal :as modal] [app.main.data.modal :as modal]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.libraries :as dwl]
@ -16,7 +16,7 @@
[app.main.ui.context :as ctx] [app.main.ui.context :as ctx]
[app.main.ui.icons :as i] [app.main.ui.icons :as i]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.i18n :as i18n :refer [t]] [app.util.i18n :as i18n :refer [tr]]
[rumext.alpha :as mf])) [rumext.alpha :as mf]))
(def component-attrs [:component-id :component-file :shape-ref]) (def component-attrs [:component-id :component-file :shape-ref])
@ -26,46 +26,58 @@
(let [current-file-id (mf/use-ctx ctx/current-file-id) (let [current-file-id (mf/use-ctx ctx/current-file-id)
id (first ids) id (first ids)
locale (mf/deref i18n/locale)
local (mf/use-state {:menu-open false}) local (mf/use-state {:menu-open false})
show? (some? (:component-id values)) component-id (:component-id values)
local-library (mf/deref refs/workspace-local-library) library-id (:component-file values)
libraries (mf/deref refs/workspace-libraries)
{:keys [component-id component-file]} values
component (cp/get-component component-id component-file local-library libraries) local-file (deref refs/workspace-local-library)
libraries (deref refs/workspace-libraries)
on-menu-click (mf/use-callback ;; NOTE: this is necessary because the `cph/get-component`
;; expects a map of all libraries, including the local one.
libraries (assoc libraries (:id local-file) local-file)
component (cph/get-component libraries library-id component-id)
show? (some? component-id)
on-menu-click
(mf/use-callback
(fn [event] (fn [event]
(dom/prevent-default event) (dom/prevent-default event)
(dom/stop-propagation event) (dom/stop-propagation event)
(swap! local assoc :menu-open true))) (swap! local assoc :menu-open true)))
on-menu-close (mf/use-callback on-menu-close
(mf/use-callback
#(swap! local assoc :menu-open false)) #(swap! local assoc :menu-open false))
do-detach-component (st/emitf (dwl/detach-component id)) do-detach-component
do-reset-component (st/emitf (dwl/reset-component id)) (st/emitf (dwl/detach-component id))
do-update-component (st/emitf (dwl/update-component-sync id component-file))
do-reset-component
(st/emitf (dwl/reset-component id))
do-update-component
(st/emitf (dwl/update-component-sync id library-id))
do-update-remote-component do-update-remote-component
(st/emitf (modal/show (st/emitf (modal/show
{:type :confirm {:type :confirm
:message "" :message ""
:title (t locale "modals.update-remote-component.message") :title (tr "modals.update-remote-component.message")
:hint (t locale "modals.update-remote-component.hint") :hint (tr "modals.update-remote-component.hint")
:cancel-label (t locale "modals.update-remote-component.cancel") :cancel-label (tr "modals.update-remote-component.cancel")
:accept-label (t locale "modals.update-remote-component.accept") :accept-label (tr "modals.update-remote-component.accept")
:accept-style :primary :accept-style :primary
:on-accept do-update-component})) :on-accept do-update-component}))
do-show-component (st/emitf (dw/go-to-component component-id)) do-show-component (st/emitf (dw/go-to-component component-id))
do-navigate-component-file (st/emitf (dwl/nav-to-component-file component-file))] do-navigate-component-file (st/emitf (dwl/nav-to-component-file library-id))]
(when show? (when show?
[:div.element-set [:div.element-set
[:div.element-set-title [:div.element-set-title
[:span (t locale "workspace.options.component")]] [:span (tr "workspace.options.component")]]
[:div.element-set-content [:div.element-set-content
[:div.row-flex.component-row [:div.row-flex.component-row
i/component i/component
@ -78,14 +90,14 @@
;; app/main/ui/workspace/context_menu.cljs ;; app/main/ui/workspace/context_menu.cljs
[:& context-menu {:on-close on-menu-close [:& context-menu {:on-close on-menu-close
:show (:menu-open @local) :show (:menu-open @local)
:options (if (= (:component-file values) current-file-id) :options (if (= library-id current-file-id)
[[(t locale "workspace.shape.menu.detach-instance") do-detach-component] [[(tr "workspace.shape.menu.detach-instance") do-detach-component]
[(t locale "workspace.shape.menu.reset-overrides") do-reset-component] [(tr "workspace.shape.menu.reset-overrides") do-reset-component]
[(t locale "workspace.shape.menu.update-main") do-update-component] [(tr "workspace.shape.menu.update-main") do-update-component]
[(t locale "workspace.shape.menu.show-main") do-show-component]] [(tr "workspace.shape.menu.show-main") do-show-component]]
[[(t locale "workspace.shape.menu.detach-instance") do-detach-component] [[(tr "workspace.shape.menu.detach-instance") do-detach-component]
[(t locale "workspace.shape.menu.reset-overrides") do-reset-component] [(tr "workspace.shape.menu.reset-overrides") do-reset-component]
[(t locale "workspace.shape.menu.go-main") do-navigate-component-file] [(tr "workspace.shape.menu.go-main") do-navigate-component-file]
[(t locale "workspace.shape.menu.update-main") do-update-remote-component]])}]]]]]))) [(tr "workspace.shape.menu.update-main") do-update-remote-component]])}]]]]])))

View file

@ -7,7 +7,7 @@
(ns app.main.ui.workspace.sidebar.options.menus.interactions (ns app.main.ui.workspace.sidebar.options.menus.interactions
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec.interactions :as csi] [app.common.spec.interactions :as csi]
[app.common.spec.page :as csp] [app.common.spec.page :as csp]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
@ -180,8 +180,8 @@
[{:keys [index shape interaction update-interaction remove-interaction]}] [{:keys [index shape interaction update-interaction remove-interaction]}]
(let [objects (deref refs/workspace-page-objects) (let [objects (deref refs/workspace-page-objects)
destination (get objects (:destination interaction)) destination (get objects (:destination interaction))
frames (mf/use-memo (mf/deps objects) frames (mf/with-memo [objects]
#(cp/select-frames objects)) (cph/get-frames objects))
overlay-pos-type (:overlay-pos-type interaction) overlay-pos-type (:overlay-pos-type interaction)
close-click-outside? (:close-click-outside interaction false) close-click-outside? (:close-click-outside interaction false)
@ -550,7 +550,7 @@
[:& page-flows {:flows flows}]) [:& page-flows {:flows flows}])
[:div.element-set.interactions-options [:div.element-set.interactions-options
(when (and shape (not (cp/unframed-shape? shape))) (when (and shape (not (cph/unframed-shape? shape)))
[:div.element-set-title [:div.element-set-title
[:span (tr "workspace.options.interactions")] [:span (tr "workspace.options.interactions")]
[:div.add-page {:on-click add-interaction} [:div.add-page {:on-click add-interaction}
@ -558,7 +558,7 @@
[:div.element-set-content [:div.element-set-content
(when (= (count interactions) 0) (when (= (count interactions) 0)
[:* [:*
(when (and shape (not (cp/unframed-shape? shape))) (when (and shape (not (cph/unframed-shape? shape)))
[:* [:*
[:div.interactions-help-icon i/plus] [:div.interactions-help-icon i/plus]
[:div.interactions-help.separator (tr "workspace.options.add-interaction")]]) [:div.interactions-help.separator (tr "workspace.options.add-interaction")]])

View file

@ -9,7 +9,7 @@
["react-virtualized" :as rvt] ["react-virtualized" :as rvt]
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.text :as txt] [app.common.text :as txt]
[app.main.data.fonts :as fts] [app.main.data.fonts :as fts]
[app.main.data.shortcuts :as dsc] [app.main.data.shortcuts :as dsc]
@ -575,7 +575,7 @@
[:input.element-name.adv-typography-name [:input.element-name.adv-typography-name
{:type "text" {:type "text"
:ref name-input-ref :ref name-input-ref
:default-value (cp/merge-path-item (:path typography) (:name typography)) :default-value (cph/merge-path-item (:path typography) (:name typography))
:on-blur on-name-blur :on-blur on-name-blur
:on-change on-name-change}] :on-change on-name-change}]

View file

@ -8,7 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.data.shortcuts :as dsc] [app.main.data.shortcuts :as dsc]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.path.shortcuts :as psc] [app.main.data.workspace.path.shortcuts :as psc]
@ -154,13 +154,13 @@
selected (mf/ref-val selected-ref) selected (mf/ref-val selected-ref)
remove-xfm (mapcat #(cp/get-parents % objects)) remove-xfm (mapcat #(cph/get-parent-ids objects %))
remove-id? (cond-> (into #{} remove-xfm selected) remove-id? (cond-> (into #{} remove-xfm selected)
@ctrl? @ctrl?
(into (filter is-group?) ids)) (into (filter is-group?) ids))
hover-shape (->> ids hover-shape (->> ids
(filterv (comp not remove-id?)) (filter (comp not remove-id?))
(first) (first)
(get objects))] (get objects))]
(reset! hover hover-shape) (reset! hover hover-shape)

View file

@ -9,7 +9,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec.interactions :as cti] [app.common.spec.interactions :as cti]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.refs :as refs] [app.main.refs :as refs]
@ -210,7 +210,7 @@
(st/emit! (dw/start-move-overlay-pos index)))] (st/emit! (dw/start-move-overlay-pos index)))]
(when dest-shape (when dest-shape
(let [orig-frame (cp/get-frame orig-shape objects) (let [orig-frame (cph/get-frame objects orig-shape)
marker-x (+ (:x orig-frame) (:x position)) marker-x (+ (:x orig-frame) (:x position))
marker-y (+ (:y orig-frame) (:y position)) marker-y (+ (:y orig-frame) (:y position))
width (:width dest-shape) width (:width dest-shape)
@ -326,7 +326,7 @@
:objects objects :objects objects
:hover-disabled? hover-disabled?}]))]))) :hover-disabled? hover-disabled?}]))])))
(when (and shape (when (and shape
(not (cp/unframed-shape? shape)) (not (cph/unframed-shape? shape))
(not (#{:move :rotate} current-transform))) (not (#{:move :rotate} current-transform)))
[:& interaction-handle {:key (:id shape) [:& interaction-handle {:key (:id shape)
:index nil :index nil

View file

@ -8,7 +8,7 @@
(:require (:require
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.util.object :as obj] [app.util.object :as obj]
[app.util.path.format :as upf] [app.util.path.format :as upf]
@ -89,7 +89,7 @@
transform (mf/deref refs/current-transform) transform (mf/deref refs/current-transform)
outlines-ids (->> (set/union selected hover) outlines-ids (->> (set/union selected hover)
(cp/clean-loops objects)) (cph/clean-loops objects))
show-outline? (fn [shape] (and (not (:hidden shape)) show-outline? (fn [shape] (and (not (:hidden shape))
(not (:blocked shape)))) (not (:blocked shape))))

View file

@ -50,13 +50,10 @@
vbox-x (:x vbox) vbox-x (:x vbox)
vbox-y (:y vbox) vbox-y (:y vbox)
base-objects-rect base-objects-rect (mf/with-memo [objects]
(mf/use-memo (-> objects
(mf/deps objects) (cph/get-immediate-children)
(fn [] (gsh/selection-rect)))
(let [root-shapes (-> objects cph/get-top-frame :shapes)
shapes (->> root-shapes (mapv #(get objects %)))]
(gsh/selection-rect shapes))))
inv-zoom (/ 1 zoom) inv-zoom (/ 1 zoom)
vbox-height (- (:height vbox) (* inv-zoom scroll-height)) vbox-height (- (:height vbox) (* inv-zoom scroll-height))

View file

@ -9,7 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.worker :as uw] [app.main.worker :as uw]
[beicon.core :as rx] [beicon.core :as rx]
@ -225,7 +225,7 @@
:frame-id (:id frame) :frame-id (:id frame)
:include-frames? true :include-frames? true
:rect rect}) :rect rect})
(rx/map #(cp/clean-loops @refs/workspace-page-objects %)) (rx/map #(cph/clean-loops @refs/workspace-page-objects %))
(rx/map #(set/difference % selected)) (rx/map #(set/difference % selected))
(rx/map #(->> % (map (partial get @refs/workspace-page-objects))))) (rx/map #(->> % (map (partial get @refs/workspace-page-objects)))))
(rx/of nil))))] (rx/of nil))))]

View file

@ -9,7 +9,8 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.main.snap :as snap] [app.main.snap :as snap]
[app.util.geom.snap-points :as sp] [app.util.geom.snap-points :as sp]
[beicon.core :as rx] [beicon.core :as rx]
@ -151,18 +152,14 @@
(mf/defc snap-points (mf/defc snap-points
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo]}
[{:keys [layout zoom objects selected page-id drawing transform modifiers] :as props}] [{:keys [layout zoom objects selected page-id drawing transform modifiers] :as props}]
(us/assert set? selected)
(let [shapes (into [] (keep (d/getf objects)) selected) (let [shapes (into [] (keep (d/getf objects)) selected)
filter-shapes filter-shapes
(into #{} (into selected (mapcat #(cph/get-children-ids objects %)) selected)
(comp (mapcat #(cp/get-object-with-children % objects))
(map :id))
selected)
remove-snap? (mf/use-memo remove-snap? (mf/with-memo [layout filter-shapes]
(mf/deps layout filter-shapes) (snap/make-remove-snap layout filter-shapes))
#(snap/make-remove-snap layout filter-shapes))
shapes (if drawing [drawing] shapes)] shapes (if drawing [drawing] shapes)]
(when (or drawing transform) (when (or drawing transform)

View file

@ -8,7 +8,7 @@
(:require (:require
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.interactions :as dwi] [app.main.data.workspace.interactions :as dwi]
[app.main.refs :as refs] [app.main.refs :as refs]
@ -161,7 +161,7 @@
on-frame-enter (unchecked-get props "on-frame-enter") on-frame-enter (unchecked-get props "on-frame-enter")
on-frame-leave (unchecked-get props "on-frame-leave") on-frame-leave (unchecked-get props "on-frame-leave")
on-frame-select (unchecked-get props "on-frame-select") on-frame-select (unchecked-get props "on-frame-select")
frames (cp/select-frames objects)] frames (cph/get-frames objects)]
[:g.frame-titles [:g.frame-titles
(for [frame frames] (for [frame frames]

View file

@ -10,8 +10,8 @@
https://en.wikipedia.org/wiki/Range_tree" https://en.wikipedia.org/wiki/Range_tree"
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.pages :as cp]
[app.common.pages.diff :as diff] [app.common.pages.diff :as diff]
[app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.util.geom.grid :as gg] [app.util.geom.grid :as gg]
[app.util.geom.snap-points :as snap] [app.util.geom.snap-points :as snap]
@ -187,9 +187,9 @@
(defn add-page (defn add-page
"Adds page information" "Adds page information"
[snap-data {:keys [objects options] :as page}] [snap-data {:keys [objects options] :as page}]
(let [frames (cph/get-frames objects)
(let [frames (cp/select-frames objects) shapes (->> (vals (:objects page))
shapes (cp/select-objects #(not= :frame (:type %)) page) (remove cph/frame-shape?))
guides (vals (:guides options)) guides (vals (:guides options))
page-data page-data

View file

@ -9,6 +9,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.util.quadtree :as qdt] [app.util.quadtree :as qdt]
[app.worker.impl :as impl] [app.worker.impl :as impl]
@ -86,7 +87,7 @@
changed-ids (into #{} changed-ids (into #{}
(comp (filter #(not= % uuid/zero)) (comp (filter #(not= % uuid/zero))
(filter changes?) (filter changes?)
(mapcat #(into [%] (cp/get-children % new-objects)))) (mapcat #(into [%] (cph/get-children-ids new-objects %))))
(set/union (set (keys old-objects)) (set/union (set (keys old-objects))
(set (keys new-objects)))) (set (keys new-objects))))

View file

@ -8,7 +8,7 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages.helpers :as cph]
[app.common.transit :as t] [app.common.transit :as t]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
@ -208,7 +208,7 @@
(show-component [shape objects] (show-component [shape objects]
(if (nil? (:shape-ref shape)) (if (nil? (:shape-ref shape))
"" ""
(let [root-shape (cp/get-component-shape shape objects) (let [root-shape (cph/get-component-shape objects shape)
component-id (when root-shape (:component-id root-shape)) component-id (when root-shape (:component-id root-shape))
component-file-id (when root-shape (:component-file root-shape)) component-file-id (when root-shape (:component-file root-shape))
component-file (when component-file-id (get libraries component-file-id nil)) component-file (when component-file-id (get libraries component-file-id nil))

View file

@ -197,13 +197,10 @@
"Renamed component")) "Renamed component"))
(rx/do (rx/do
(fn [new-state] (fn [new-state]
(let [file (dwlh/get-local-file new-state) (let [libs (dwlh/get-libraries new-state)
component (cph/get-component component (cph/get-component libs
(:component-id instance1)
(:component-file instance1) (:component-file instance1)
file (:component-id instance1))]
{})]
(t/is (= (:name component) (t/is (= (:name component)
"Renamed component"))))) "Renamed component")))))
@ -274,13 +271,10 @@
new-state new-state
(:id instance1)) (:id instance1))
file (dwlh/get-local-file new-state) libs (dwlh/get-libraries new-state)
component (cph/get-component component (cph/get-component libs
(:component-id instance1)
(:component-file instance1) (:component-file instance1)
file (:component-id instance1))]
{})]
(t/is (nil? component))))) (t/is (nil? component)))))
(rx/subs done #(throw %)))))) (rx/subs done #(throw %))))))

View file

@ -3,7 +3,6 @@
[app.common.colors :as clr] [app.common.colors :as clr]
[app.common.data :as d] [app.common.data :as d]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.pages.helpers :as cph]
[app.main.data.workspace.changes :as dwc] [app.main.data.workspace.changes :as dwc]
[app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.libraries-helpers :as dwlh] [app.main.data.workspace.libraries-helpers :as dwlh]

View file

@ -7,7 +7,6 @@
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.main.data.workspace :as dw] [app.main.data.workspace :as dw]
[app.main.data.workspace.libraries-helpers :as dwlh] [app.main.data.workspace.libraries-helpers :as dwlh]
@ -57,12 +56,10 @@
[state root-inst-id] [state root-inst-id]
(let [page (thp/current-page state) (let [page (thp/current-page state)
root-inst (cph/get-shape page root-inst-id) root-inst (cph/get-shape page root-inst-id)
shapes-inst (cph/get-object-with-children shapes-inst (cph/get-children-with-self (:objects page)
root-inst-id root-inst-id)]
(:objects page))]
;; Validate that the instance tree is well constructed ;; Validate that the instance tree is well constructed
(t/is (is-instance-root (first shapes-inst))) (is-instance-root (first shapes-inst))
(run! is-instance-child (rest shapes-inst)) (run! is-instance-child (rest shapes-inst))
shapes-inst)) shapes-inst))
@ -71,10 +68,8 @@
[state root-inst-id] [state root-inst-id]
(let [page (thp/current-page state) (let [page (thp/current-page state)
root-inst (cph/get-shape page root-inst-id) root-inst (cph/get-shape page root-inst-id)
shapes-inst (cph/get-object-with-children shapes-inst (cph/get-children-with-self (:objects page)
root-inst-id root-inst-id)]
(:objects page))]
;; Validate that the tree is not an instance ;; Validate that the tree is not an instance
(run! is-noninstance shapes-inst) (run! is-noninstance shapes-inst)
@ -85,28 +80,20 @@
(let [page (thp/current-page state) (let [page (thp/current-page state)
root-inst (cph/get-shape page root-inst-id) root-inst (cph/get-shape page root-inst-id)
file (dwlh/get-local-file state) libs (dwlh/get-libraries state)
component (cph/get-component component (cph/get-component libs (:component-id root-inst))
(:component-id root-inst)
(:id file)
file
nil)
shapes-inst (cph/get-object-with-children shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
root-inst-id shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
(:objects page))
shapes-main (cph/get-object-with-children
(:shape-ref root-inst)
(:objects component))
unique-refs (into #{} (map :shape-ref shapes-inst)) unique-refs (into #{} (map :shape-ref) shapes-inst)
main-exists? (fn [shape] main-exists? (fn [shape]
(t/is (some #(= (:id %) (:shape-ref shape)) (t/is (some #(= (:id %) (:shape-ref shape))
shapes-main)))] shapes-main)))]
;; Validate that the instance tree is well constructed ;; Validate that the instance tree is well constructed
(t/is (is-instance-root (first shapes-inst))) (is-instance-root (first shapes-inst))
(run! is-instance-child (rest shapes-inst)) (run! is-instance-child (rest shapes-inst))
(run! is-noninstance shapes-main) (run! is-noninstance shapes-main)
(t/is (= (count shapes-inst) (t/is (= (count shapes-inst)
@ -119,19 +106,10 @@
(defn resolve-component (defn resolve-component
[state component-id] [state component-id]
(let [page (thp/current-page state) (let [page (thp/current-page state)
libs (dwlh/get-libraries state)
file (dwlh/get-local-file state) component (cph/get-component libs component-id)
component (cph/get-component root-main (cph/get-component-root component)
component-id shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
(:id file)
file
nil)
root-main (cph/get-component-root
component)
shapes-main (cph/get-object-with-children
(:id root-main)
(:objects component))]
;; Validate that the component tree is well constructed ;; Validate that the component tree is well constructed
(run! is-noninstance shapes-main) (run! is-noninstance shapes-main)

View file

@ -66,7 +66,7 @@
([state label type] (sample-shape state type {})) ([state label type] (sample-shape state type {}))
([state label type props] ([state label type props]
(let [page (current-page state) (let [page (current-page state)
frame (cph/get-top-frame (:objects page)) frame (cph/get-frame (:objects page))
shape (-> (cp/make-minimal-shape type) shape (-> (cp/make-minimal-shape type)
(gsh/setup {:x 0 :y 0 :width 1 :height 1}) (gsh/setup {:x 0 :y 0 :width 1 :height 1})
(merge props))] (merge props))]