♻️ Move component instantiation to new types module

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

View file

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

View file

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

View file

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