mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 23:31:21 -05:00
♻️ Move data.helpers to uxbox.common.pages ns.
This commit is contained in:
parent
85d7617143
commit
49023117c3
11 changed files with 139 additions and 207 deletions
|
@ -16,9 +16,106 @@
|
|||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.common.spec :as us]))
|
||||
|
||||
;; TODO: should be replaced when uuid is unified under
|
||||
;; uxbox.common.uuid namespace.
|
||||
(def uuid-zero #uuid "00000000-0000-0000-0000-000000000000")
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Page Data Structure Helpers
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defn get-children
|
||||
"Retrieve all children ids recursively for a given object"
|
||||
[id objects]
|
||||
(let [shapes (get-in objects [id :shapes])]
|
||||
(if shapes
|
||||
(d/concat shapes (mapcat #(get-children % objects) shapes))
|
||||
[])))
|
||||
|
||||
(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-parent
|
||||
"Retrieve the id of the parent for the shape-id (if exists)"
|
||||
[shape-id objects]
|
||||
(let [check-parenthood
|
||||
(fn [shape]
|
||||
(when (and (:shapes shape)
|
||||
((set (:shapes shape)) shape-id))
|
||||
(:id shape)))]
|
||||
(some check-parenthood (vals objects))))
|
||||
|
||||
(defn calculate-child-parent-map
|
||||
[objects]
|
||||
(let [red-fn
|
||||
(fn [acc {:keys [id shapes]}]
|
||||
;; Insert every pair shape -> parent into accumulated value
|
||||
(into acc (map #(vector % id) (or shapes []))))]
|
||||
(reduce red-fn {} (vals objects))))
|
||||
|
||||
(defn get-all-parents
|
||||
[shape-id objects]
|
||||
(let [child->parent (calculate-child-parent-map objects)
|
||||
rec-fn (fn [cur result]
|
||||
(if-let [parent (child->parent cur)]
|
||||
(recur parent (conj result parent))
|
||||
(vec (reverse result))))]
|
||||
(rec-fn shape-id [])))
|
||||
|
||||
(defn- calculate-invalid-targets
|
||||
[shape-id objects]
|
||||
(let [result #{shape-id}
|
||||
children (get-in objects [shape-id :shape])
|
||||
reduce-fn (fn [result child-id]
|
||||
(into result (calculate-invalid-targets child-id objects)))]
|
||||
(reduce reduce-fn result children)))
|
||||
|
||||
(defn- insert-at-index
|
||||
[shapes index ids]
|
||||
(let [[before after] (split-at index shapes)
|
||||
p? (set ids)]
|
||||
(d/concat []
|
||||
(remove p? before)
|
||||
ids
|
||||
(remove p? after))))
|
||||
|
||||
(defn select-toplevel-shapes
|
||||
[objects]
|
||||
(let [lookup #(get objects %)
|
||||
root (lookup uuid/zero)
|
||||
childs (:shapes root)]
|
||||
(loop [id (first childs)
|
||||
ids (rest childs)
|
||||
res []]
|
||||
(if (nil? id)
|
||||
res
|
||||
(let [obj (lookup id)
|
||||
typ (:type obj)]
|
||||
(recur (first ids)
|
||||
(rest ids)
|
||||
(if (= :frame typ)
|
||||
(into res (map lookup) (:shapes obj))
|
||||
(conj res obj))))))))
|
||||
|
||||
(defn select-frames
|
||||
[objects]
|
||||
(let [root (get objects uuid/zero)
|
||||
loopfn (fn loopfn [ids]
|
||||
(let [obj (get objects (first ids))]
|
||||
(cond
|
||||
(nil? obj)
|
||||
nil
|
||||
|
||||
(= :frame (:type obj))
|
||||
(lazy-seq (cons obj (loopfn (rest ids))))
|
||||
|
||||
:else
|
||||
(lazy-seq (loopfn (rest ids))))))]
|
||||
(loopfn (:shapes root))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Page Transformation Changes
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; --- Specs
|
||||
|
||||
|
@ -158,7 +255,7 @@
|
|||
(s/def ::change (s/multi-spec change-spec-impl :type))
|
||||
(s/def ::changes (s/coll-of ::change))
|
||||
|
||||
(def root #uuid "00000000-0000-0000-0000-000000000000")
|
||||
(def root uuid/zero)
|
||||
|
||||
(def default-page-data
|
||||
"A reference value of the empty page data."
|
||||
|
@ -176,7 +273,7 @@
|
|||
:fill-opacity 1})
|
||||
|
||||
(def default-frame-attrs
|
||||
{:frame-id uuid-zero
|
||||
{:frame-id uuid/zero
|
||||
:fill-color "#ffffff"
|
||||
:fill-opacity 1
|
||||
:shapes []})
|
||||
|
@ -237,32 +334,6 @@
|
|||
(seq shapes) ; Recursive delete all dependend objects
|
||||
(as-> $ (reduce #(or (process-change %1 {:type :del-obj :id %2}) %1) $ shapes))))))
|
||||
|
||||
(defn- calculate-child-parent-map
|
||||
[objects]
|
||||
(let [red-fn
|
||||
(fn [acc {:keys [id shapes]}]
|
||||
;; Insert every pair shape -> parent into accumulated value
|
||||
(into acc (map #(vector % id) (or shapes []))))]
|
||||
(reduce red-fn {} (vals objects))))
|
||||
|
||||
(defn- calculate-invalid-targets
|
||||
[shape-id objects]
|
||||
(let [result #{shape-id}
|
||||
children (get-in objects [shape-id :shape])
|
||||
reduce-fn (fn [result child-id]
|
||||
(into result (calculate-invalid-targets child-id objects)))]
|
||||
(reduce reduce-fn result children)))
|
||||
|
||||
(defn- insert-at-index
|
||||
[shapes index ids]
|
||||
(let [[before after] (split-at index shapes)
|
||||
p? (set ids)]
|
||||
(d/concat []
|
||||
(remove p? before)
|
||||
ids
|
||||
(remove p? after))))
|
||||
|
||||
|
||||
(defmethod process-change :mov-objects
|
||||
[data {:keys [parent-id shapes index] :as change}]
|
||||
(let [child->parent (calculate-child-parent-map (:objects data))
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns uxbox.main.data.helpers
|
||||
(:require [uxbox.common.data :as d]))
|
||||
|
||||
(defn get-children
|
||||
"Retrieve all children ids recursively for a given shape"
|
||||
[shape-id objects]
|
||||
(let [shapes (get-in objects [shape-id :shapes])]
|
||||
(if shapes
|
||||
(d/concat shapes (mapcat #(get-children % objects) shapes))
|
||||
[])))
|
||||
|
||||
(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-parent
|
||||
"Retrieve the id of the parent for the shape-id (if exists)"
|
||||
[shape-id objects]
|
||||
(let [check-parenthood
|
||||
(fn [shape] (when (and (:shapes shape)
|
||||
((set (:shapes shape)) shape-id))
|
||||
(:id shape)))]
|
||||
(some check-parenthood (vals objects))))
|
||||
|
||||
(defn calculate-child-parent-map
|
||||
[objects]
|
||||
(let [red-fn
|
||||
(fn [acc {:keys [id shapes]}]
|
||||
;; Insert every pair shape -> parent into accumulated value
|
||||
(into acc (map #(vector % id) (or shapes []))))]
|
||||
(reduce red-fn {} (vals objects))))
|
||||
|
||||
(defn get-all-parents
|
||||
[shape-id objects]
|
||||
(let [child->parent (calculate-child-parent-map objects)
|
||||
rec-fn (fn [cur result]
|
||||
(if-let [parent (child->parent cur)]
|
||||
(recur parent (conj result parent))
|
||||
(vec (reverse result))))]
|
||||
(rec-fn shape-id [])))
|
||||
|
||||
(defn replace-shapes
|
||||
"Replace inside shapes the value `to-replace-id` for the value in
|
||||
items keeping the same order. `to-replace-id` can be a set, a
|
||||
sequable or a single value. Any of these will be changed into a set
|
||||
to make the replacement"
|
||||
[shape to-replace-id items]
|
||||
(let [should-replace
|
||||
(cond
|
||||
(set? to-replace-id) to-replace-id
|
||||
(seqable? to-replace-id) (set to-replace-id)
|
||||
:else #{to-replace-id})
|
||||
|
||||
;; This function replaces the first ocurrence of the set `should-replace` for the
|
||||
;; value in `items`. Next elements that match are removed but not replaced again
|
||||
;; so for example:
|
||||
;; should-replace = #{2 3 5}
|
||||
;; (replace-fn [ 1 2 3 4 5] ["a" "b"] [])
|
||||
;; => [ 1 "a" "b" 4 ]
|
||||
replace-fn
|
||||
(fn [to-replace acc shapes]
|
||||
(if (empty? shapes)
|
||||
acc
|
||||
(let [cur (first shapes)
|
||||
rest (subvec shapes 1)]
|
||||
(if (should-replace cur)
|
||||
(recur [] (into acc to-replace) rest)
|
||||
(recur to-replace (conj acc cur) rest)))))
|
||||
|
||||
replace-shapes (partial replace-fn (if (seqable? items) items [items]) [])]
|
||||
|
||||
(update shape :shapes replace-shapes)))
|
|
@ -20,7 +20,6 @@
|
|||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.config :as cfg]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.data.helpers :as helpers]
|
||||
[uxbox.main.data.workspace.common :as dwc]
|
||||
[uxbox.main.data.workspace.notifications :as dwn]
|
||||
[uxbox.main.data.workspace.persistence :as dwp]
|
||||
|
@ -197,7 +196,7 @@
|
|||
(let [page-id (:current-page-id state)
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
groups-to-adjust (->> ids
|
||||
(mapcat #(reverse (helpers/get-all-parents % objects)))
|
||||
(mapcat #(reverse (cp/get-all-parents % objects)))
|
||||
(map #(get objects %))
|
||||
(filter #(= (:type %) :group))
|
||||
(map #(:id %))
|
||||
|
@ -413,7 +412,7 @@
|
|||
unames (retrieve-used-names objects)
|
||||
name (generate-unique-name unames (:name shape))
|
||||
|
||||
frames (dwc/retrieve-frames objects)
|
||||
frames (cp/select-frames objects)
|
||||
|
||||
frame-id (if (= :frame (:type shape))
|
||||
uuid/zero
|
||||
|
@ -627,7 +626,7 @@
|
|||
grouped #{:frame :group}]
|
||||
(update-in state [:workspace-data page-id :objects]
|
||||
(fn [objects]
|
||||
(->> (d/concat [id] (helpers/get-children id objects))
|
||||
(->> (d/concat [id] (cp/get-children id objects))
|
||||
(map #(get objects %))
|
||||
(remove #(grouped (:type %)))
|
||||
(reduce #(update %1 (:id %2) update-shape) objects)))))))))
|
||||
|
@ -707,13 +706,13 @@
|
|||
(let [page-id (:current-page-id state)
|
||||
session-id (:session-id state)
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
cpindex (helpers/calculate-child-parent-map objects)
|
||||
cpindex (cp/calculate-child-parent-map objects)
|
||||
|
||||
del-change #(array-map :type :del-obj :id %)
|
||||
|
||||
rchanges
|
||||
(reduce (fn [res id]
|
||||
(let [chd (helpers/get-children id objects)]
|
||||
(let [chd (cp/get-children id objects)]
|
||||
(into res (d/concat
|
||||
(mapv del-change (reverse chd))
|
||||
[(del-change id)]))))
|
||||
|
@ -806,7 +805,7 @@
|
|||
(let [page-id (:current-page-id state)
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
parent-id (helpers/get-parent ref-id objects)]
|
||||
parent-id (cp/get-parent ref-id objects)]
|
||||
(rx/of (dwc/commit-changes [{:type :mov-objects
|
||||
:parent-id parent-id
|
||||
:index index
|
||||
|
@ -1028,7 +1027,7 @@
|
|||
(update [_ state]
|
||||
(let [page-id (get-in state [:workspace-page :id])
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
childs (helpers/get-children id objects)]
|
||||
childs (cp/get-children id objects)]
|
||||
(update-in state [:workspace-data page-id :objects]
|
||||
(fn [objects]
|
||||
(reduce (fn [objects id]
|
||||
|
@ -1273,7 +1272,7 @@
|
|||
(when (and (= 1 (count selected))
|
||||
(= (:type group) :group))
|
||||
(let [shapes (:shapes group)
|
||||
parent-id (helpers/get-parent group-id objects)
|
||||
parent-id (cp/get-parent group-id objects)
|
||||
parent (get objects parent-id)
|
||||
index-in-parent (->> (:shapes parent)
|
||||
(map-indexed vector)
|
||||
|
|
|
@ -176,41 +176,6 @@
|
|||
|
||||
;; --- Common Helpers & Events
|
||||
|
||||
(defn retrieve-toplevel-shapes
|
||||
[objects]
|
||||
(let [lookup #(get objects %)
|
||||
root (lookup uuid/zero)
|
||||
childs (:shapes root)]
|
||||
(loop [id (first childs)
|
||||
ids (rest childs)
|
||||
res []]
|
||||
(if (nil? id)
|
||||
res
|
||||
(let [obj (lookup id)
|
||||
typ (:type obj)]
|
||||
(recur (first ids)
|
||||
(rest ids)
|
||||
(if (= :frame typ)
|
||||
(into res (map lookup) (:shapes obj))
|
||||
(conj res obj))))))))
|
||||
|
||||
|
||||
(defn retrieve-frames
|
||||
[objects]
|
||||
(let [root (get objects uuid/zero)
|
||||
loopfn (fn loopfn [ids]
|
||||
(let [obj (get objects (first ids))]
|
||||
(cond
|
||||
(nil? obj)
|
||||
nil
|
||||
|
||||
(= :frame (:type obj))
|
||||
(lazy-seq (cons obj (loopfn (rest ids))))
|
||||
|
||||
:else
|
||||
(lazy-seq (loopfn (rest ids))))))]
|
||||
(loopfn (:shapes root))))
|
||||
|
||||
(defn- calculate-frame-overlap
|
||||
[frames shape]
|
||||
(let [shape (geom/shape->rect-shape shape)
|
||||
|
@ -251,8 +216,8 @@
|
|||
(let [page-id (get-in state [:workspace-page :id])
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
|
||||
shapes (retrieve-toplevel-shapes objects)
|
||||
frames (retrieve-frames objects)
|
||||
shapes (cp/select-toplevel-shapes objects)
|
||||
frames (cp/select-frames objects)
|
||||
|
||||
[rch uch] (calculate-shape-to-frame-relationship-changes frames shapes)]
|
||||
(when-not (empty? rch)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[potok.core :as ptk]
|
||||
[uxbox.common.data :as d]
|
||||
[uxbox.common.spec :as us]
|
||||
[uxbox.main.data.helpers :as helpers]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.main.data.workspace.common :as dwc]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.store :as st]
|
||||
|
@ -77,7 +77,7 @@
|
|||
:bottom-right [x2 y2]
|
||||
:bottom [x2 y2]
|
||||
:bottom-left [x1 y2]
|
||||
:left [x1 y2])]
|
||||
:left [x1 y2])]
|
||||
(gpt/point x y)))
|
||||
|
||||
;; -- RESIZE
|
||||
|
@ -96,7 +96,7 @@
|
|||
deltav (-> (gpt/to-vec initial (if (= rotation 0) point-snap point))
|
||||
(gpt/transform (gmt/rotate-matrix (- rotation)))
|
||||
(gpt/multiply handler-modif))
|
||||
|
||||
|
||||
;; Resize vector
|
||||
scalev (gpt/divide (gpt/add shapev deltav) shapev)
|
||||
|
||||
|
@ -278,7 +278,7 @@
|
|||
(ptk/reify ::move-selected
|
||||
IDeref
|
||||
(-deref [_] direction)
|
||||
|
||||
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(if (nil? (get-in state [:workspace-local :current-move-selected]))
|
||||
|
@ -296,9 +296,9 @@
|
|||
(rx/filter #(= direction (deref %))))
|
||||
stopper (->> move-events
|
||||
(rx/debounce 100)
|
||||
(rx/first))
|
||||
(rx/first))
|
||||
mov-vec (get-displacement direction)]
|
||||
|
||||
|
||||
(rx/concat
|
||||
(rx/merge
|
||||
(->> move-events
|
||||
|
@ -306,7 +306,7 @@
|
|||
(rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0))
|
||||
(rx/map #(set-modifiers selected {:displacement (gmt/translate-matrix %)})))
|
||||
(rx/of (move-selected direction align?)))
|
||||
|
||||
|
||||
(rx/of (apply-modifiers selected)
|
||||
(fn [state] (-> state
|
||||
(update :workspace-local dissoc :current-move-selected))))
|
||||
|
@ -332,7 +332,8 @@
|
|||
(or recurse-frames? (not (= :frame (:type shape))))))
|
||||
|
||||
;; ID's + Children but remove frame children if the flag is set to false
|
||||
ids-with-children (concat ids (mapcat #(helpers/get-children % objects) (filter not-frame-id? ids)))
|
||||
ids-with-children (concat ids (mapcat #(cp/get-children % objects)
|
||||
(filter not-frame-id? ids)))
|
||||
|
||||
;; For each shape updates the modifiers given as arguments
|
||||
update-shape (fn [state shape-id]
|
||||
|
@ -373,7 +374,7 @@
|
|||
|
||||
(let [objects (get-in state [:workspace-data page-id :objects])
|
||||
id->obj #(get objects %)
|
||||
get-children (fn [shape] (map id->obj (helpers/get-children (:id shape) objects)))
|
||||
get-children (fn [shape] (map id->obj (cp/get-children (:id shape) objects)))
|
||||
shapes (concat shapes (mapcat get-children shapes))]
|
||||
(rotate-around-center state delta-rotation center shapes)))))))
|
||||
|
||||
|
@ -390,7 +391,7 @@
|
|||
objects (get-in state [:workspace-data page-id :objects])
|
||||
|
||||
;; ID's + Children
|
||||
ids-with-children (concat ids (mapcat #(helpers/get-children % objects) ids))
|
||||
ids-with-children (concat ids (mapcat #(cp/get-children % objects) ids))
|
||||
|
||||
;; For each shape applies the modifiers by transforming the objects
|
||||
update-shape
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
(:require
|
||||
[okulary.core :as l]
|
||||
[beicon.core :as rx]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.main.constants :as c]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.data.helpers :as helpers]))
|
||||
[uxbox.main.store :as st]))
|
||||
|
||||
(def route
|
||||
(l/derived :route st/state))
|
||||
|
@ -86,7 +86,7 @@
|
|||
objects (get-in state [:workspace-data page-id :objects])
|
||||
selected (get-in state [:workspace-local :selected])
|
||||
shape (get objects id)
|
||||
children (helpers/get-children id objects)]
|
||||
children (cp/get-children id objects)]
|
||||
(some selected children)))]
|
||||
(l/derived selector st/state)))
|
||||
|
||||
|
@ -98,7 +98,7 @@
|
|||
(let [selected (get-in state [:workspace-local :selected])
|
||||
page-id (get-in state [:workspace-page :id])
|
||||
objects (get-in state [:workspace-data page-id :objects])
|
||||
children (mapcat #(helpers/get-children % objects) selected)]
|
||||
children (mapcat #(cp/get-children % objects) selected)]
|
||||
(into selected children)))]
|
||||
(l/derived selector st/state)))
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
[uxbox.util.debug :refer [debug?]]
|
||||
["randomcolor" :as rdcolor]))
|
||||
|
||||
(defn fix [num]
|
||||
(defn fixed
|
||||
[num]
|
||||
(when num (.toFixed num 2)))
|
||||
|
||||
(mf/defc bounding-box
|
||||
|
@ -37,7 +38,7 @@
|
|||
:fill "red"
|
||||
:stroke "white"
|
||||
:stroke-width 0.1}
|
||||
(str/format "%s - (%s, %s)" (str/slice (str (:id shape)) 0 8) (fix (:x shape)) (fix (:y shape)))]
|
||||
(str/format "%s - (%s, %s)" (str/slice (str (:id shape)) 0 8) (fixed (:x shape)) (fixed (:y shape)))]
|
||||
|
||||
[:rect {:x (:x selrect)
|
||||
:y (:y selrect)
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
[rumext.alpha :as mf]
|
||||
[uxbox.builtins.icons :as i]
|
||||
[uxbox.common.data :as d]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.main.store :as st]
|
||||
[uxbox.main.data.viewer :as dv]
|
||||
[uxbox.main.data.helpers :as helpers]
|
||||
[uxbox.main.ui.components.dropdown :refer [dropdown']]
|
||||
[uxbox.main.ui.shapes.frame :as frame]
|
||||
[uxbox.main.exports :as exports]
|
||||
|
@ -86,7 +86,7 @@
|
|||
(gmt/translate-matrix))
|
||||
|
||||
frame-id (:id frame)
|
||||
modifier-ids (concat [frame-id] (helpers/get-children frame-id objects))
|
||||
modifier-ids (concat [frame-id] (cp/get-children frame-id objects))
|
||||
|
||||
update-fn (fn [state shape-id]
|
||||
(-> state
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
[uxbox.builtins.icons :as i]
|
||||
[uxbox.common.data :as d]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.main.data.helpers :as dh]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.main.data.workspace :as dw]
|
||||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.store :as st]
|
||||
|
@ -211,7 +211,7 @@
|
|||
old-obs (unchecked-get oprops "objects")]
|
||||
(and (= new-itm old-itm)
|
||||
(identical? new-idx old-idx)
|
||||
(let [childs (dh/get-children (:id new-itm) new-obs)
|
||||
(let [childs (cp/get-children (:id new-itm) new-obs)
|
||||
childs' (conj childs (:id new-itm))]
|
||||
(and (or (= new-sel old-sel)
|
||||
(not (or (boolean (some new-sel childs'))
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
(ns uxbox.util.geom.shapes
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.common.spec :as us]
|
||||
[uxbox.util.geom.matrix :as gmt]
|
||||
[uxbox.util.geom.point :as gpt]
|
||||
[uxbox.util.math :as mth]
|
||||
[uxbox.util.data :as d]
|
||||
[uxbox.util.debug :as debug]
|
||||
[uxbox.main.data.helpers :as helpers]))
|
||||
[uxbox.util.debug :as debug]))
|
||||
|
||||
;; --- Relative Movement
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
|||
(defn recursive-move
|
||||
"Move the shape and all its recursive children."
|
||||
[shape dpoint objects]
|
||||
(let [children-ids (helpers/get-children (:id shape) objects)
|
||||
(let [children-ids (cp/get-children (:id shape) objects)
|
||||
children (map #(get objects %) children-ids)]
|
||||
(map #(move % dpoint) (cons shape children))))
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
[cuerdas.core :as str]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.common.spec :as us]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.common.uuid :as uuid]
|
||||
[uxbox.worker.impl :as impl]
|
||||
[uxbox.util.geom.shapes :as geom]
|
||||
|
@ -25,7 +26,6 @@
|
|||
|
||||
(declare resolve-object)
|
||||
(declare index-object)
|
||||
(declare retrieve-toplevel-shapes)
|
||||
(declare calculate-bounds)
|
||||
(declare create-index)
|
||||
|
||||
|
@ -77,8 +77,7 @@
|
|||
(let [bounds (calculate-bounds objects)]
|
||||
(reduce index-object
|
||||
(qdt/create bounds)
|
||||
(->> (retrieve-toplevel-shapes objects)
|
||||
(map #(get objects %))))))
|
||||
(cp/select-toplevel-shapes objects))))
|
||||
|
||||
(defn- index-object
|
||||
[index {:keys [id x y width height] :as obj}]
|
||||
|
@ -96,21 +95,3 @@
|
|||
(assoc id item)
|
||||
(update ::width max width)
|
||||
(update ::height max height))))
|
||||
|
||||
(defn- retrieve-toplevel-shapes
|
||||
[objects]
|
||||
(let [lookup #(get objects %)
|
||||
root (lookup uuid/zero)
|
||||
childs (:shapes root)]
|
||||
(loop [id (first childs)
|
||||
ids (rest childs)
|
||||
res []]
|
||||
(if (nil? id)
|
||||
res
|
||||
(let [obj (lookup id)
|
||||
typ (:type obj)]
|
||||
(recur (first ids)
|
||||
(rest ids)
|
||||
(if (= :frame typ)
|
||||
(into res (:shapes obj))
|
||||
(conj res id))))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue