0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-30 16:41:20 -05:00

♻️ Move app.common.pages to app.common.files

This commit is contained in:
Andrey Antukh 2023-11-15 16:35:52 +01:00
parent 8345548a7a
commit 52fbc678f3
139 changed files with 1459 additions and 1510 deletions

View file

@ -10,6 +10,9 @@
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.features :as cfeat]
[app.common.files.changes :as cp]
[app.common.files.changes-builder :as fcb]
[app.common.files.helpers :as cph]
[app.common.files.libraries-helpers :as cflh]
[app.common.files.migrations :as pmg]
[app.common.files.shapes-helpers :as cfsh]
@ -18,9 +21,6 @@
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.logging :as l]
[app.common.pages.changes :as cp]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.svg :as csvg]
[app.common.svg.shapes-builder :as sbuilder]
[app.common.types.component :as ctk]
@ -540,13 +540,13 @@
(create-shapes-for-bitmap mobj position))
changes
(-> (pcb/empty-changes nil)
(pcb/set-save-undo? false)
(pcb/with-page page)
(pcb/with-objects (:objects page))
(pcb/with-library-data fdata)
(pcb/delete-media (:id mobj))
(pcb/add-objects (cons shape children)))
(-> (fcb/empty-changes nil)
(fcb/set-save-undo? false)
(fcb/with-page page)
(fcb/with-objects (:objects page))
(fcb/with-library-data fdata)
(fcb/delete-media (:id mobj))
(fcb/add-objects (cons shape children)))
;; NOTE: this is a workaround for `generate-add-component`, it
;; is needed because that function always starts from empty
@ -574,7 +574,7 @@
true
nil
cfsh/prepare-create-artboard-from-selection)
changes (pcb/concat-changes changes changes2)]
changes (fcb/concat-changes changes changes2)]
(:redo-changes changes)))

View file

@ -10,8 +10,8 @@
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.features :as cfeat]
[app.common.files.helpers :as cfh]
[app.common.files.migrations :as pmg]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.schema.desc-js-like :as-alias smdj]
[app.common.spec :as us]
@ -453,7 +453,7 @@
[page id-or-ids]
(update page :objects (fn [objects]
(reduce (fn [result object-id]
(->> (cph/get-children-with-self objects object-id)
(->> (cfh/get-children-with-self objects object-id)
(filter some?)
(d/index-by :id)
(merge result)))

View file

@ -8,7 +8,7 @@
(:require
[app.common.exceptions :as ex]
[app.common.features :as cfeat]
[app.common.pages :as cp]
[app.common.files.changes :as fch]
[app.common.spec :as us]
[app.common.uuid :as uuid]
[app.config :as cf]
@ -113,7 +113,7 @@
(let [data
(->> revs
(mapcat #(->> % :changes blob/decode))
(cp/process-changes (blob/decode (:data file))))]
(fch/process-changes (blob/decode (:data file))))]
(db/update! conn :file
{:deleted-at nil
:revn revn

View file

@ -9,8 +9,8 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.features :as cfeat]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.thumbnails :as thc]
[app.common.types.shape-tree :as ctt]
@ -127,14 +127,14 @@
;; all unneeded shapes if a concrete frame is provided. If no
;; frame, the objects is returned untouched.
(filter-objects [objects frame-id]
(d/index-by :id (cph/get-children-with-self objects frame-id)))
(d/index-by :id (cfh/get-children-with-self objects frame-id)))
;; function responsible of assoc available thumbnails
;; to frames and remove all children shapes from objects if
;; thumbnails is available
(assoc-thumbnails [objects page-id thumbnails]
(loop [objects objects
frames (filter cph/frame-shape? (vals objects))]
frames (filter cfh/frame-shape? (vals objects))]
(if-let [frame (-> frames first)]
(let [frame-id (:id frame)
@ -144,7 +144,7 @@
(dissoc frame :thumbnail))
children-ids
(cph/get-children-ids objects frame-id)
(cfh/get-children-ids objects frame-id)
bounds
(when (:show-content frame)

View file

@ -9,11 +9,10 @@
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.features :as cfeat]
[app.common.files.changes :as cpc]
[app.common.files.migrations :as pmg]
[app.common.files.validate :as val]
[app.common.logging :as l]
[app.common.pages :as cp]
[app.common.pages.changes :as cpc]
[app.common.schema :as sm]
[app.common.uuid :as uuid]
[app.config :as cf]
@ -291,7 +290,7 @@
(-> file
(update :revn inc)
(update :data cp/process-changes changes)
(update :data cpc/process-changes changes)
;; If `libs` is defined, then full validation is performed
(val/validate-file! libs)

View file

@ -8,10 +8,10 @@
"A collection of adhoc fixes scripts."
(:require
[app.common.data :as d]
[app.common.files.helpers :as cfh]
[app.common.files.validate :as cfv]
[app.common.geom.shapes :as gsh]
[app.common.logging :as l]
[app.common.pages.helpers :as cph]
[app.common.pprint :refer [pprint]]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
@ -139,7 +139,7 @@
(let [component (ctf/find-component libs (:component-id copy) {:include-deleted? true})
component-file (get libs (:component-file copy))
component-shapes (ctf/get-component-shapes (:data component-file) component)
copy-shapes (cph/get-children-with-self objects (:id copy))
copy-shapes (cfh/get-children-with-self objects (:id copy))
copy-updates (fix-copy-item true copy-shapes component-shapes (:id copy) (:main-instance-id component))]
(concat updates copy-updates)))
@ -301,8 +301,8 @@
(if-not (ctk/instance-head? shape)
shape
(let [component (ctf/get-component libs (:component-file shape) (:component-id shape) {:include-deleted? true})
[_path name] (cph/parse-path-name (:name shape))
full-name (cph/clean-path (str (:path component) "/" (:name component)))]
[_path name] (cfh/parse-path-name (:name shape))
full-name (cfh/clean-path (str (:path component) "/" (:name component)))]
(if (= name (:name component))
(assoc shape :name full-name)
shape))))
@ -355,12 +355,12 @@
(gsh/close-attrs? attr (get shape attr) (get ref-shape attr) 1)
true)
(gsh/close-attrs? attr (get shape attr) (get ref-shape attr)))]
(when (and (not equal?) (not (cph/touched-group? shape group)))
(when (and (not equal?) (not (cfh/touched-group? shape group)))
(println " -> set touched " (:name shape) (:id shape) attr group))
(cond-> shape
(and (not equal?) (not (cph/touched-group? shape group)))
(update :touched cph/set-touched-group group)))))
(and (not equal?) (not (cfh/touched-group? shape group)))
(update :touched cfh/set-touched-group group)))))
fix-touched-children
(fn [shape]
(let [matches? (fn [[child-id ref-child-id]]
@ -369,11 +369,11 @@
(= (:shape-ref child) ref-child-id))
false))
equal? (every? matches? (d/zip-all (:shapes shape) (:shapes ref-shape)))]
(when (and (not equal?) (not (cph/touched-group? shape :shapes-group)))
(when (and (not equal?) (not (cfh/touched-group? shape :shapes-group)))
(println " -> set touched " (:name shape) (:id shape) :shapes :shapes-group))
(cond-> shape
(and (not equal?) (not (cph/touched-group? shape :shapes-group)))
(update :touched cph/set-touched-group :shapes-group))))]
(and (not equal?) (not (cfh/touched-group? shape :shapes-group)))
(update :touched cfh/set-touched-group :shapes-group))))]
(as-> shape $
(reduce fix-touched-attr $ ctk/sync-attrs)

View file

@ -15,7 +15,6 @@
[app.common.features :as cfeat]
[app.common.files.migrations :as pmg]
[app.common.logging :as l]
[app.common.pages :as cp]
[app.common.pprint :refer [pprint]]
[app.common.spec :as us]
[app.common.uuid :as uuid]

View file

@ -12,7 +12,6 @@
[app.common.exceptions :as ex]
[app.common.features :as cfeat]
[app.common.flags :as flags]
[app.common.pages :as cp]
[app.common.pprint :as pp]
[app.common.schema :as sm]
[app.common.spec :as us]

View file

@ -9,10 +9,10 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.files.changes :as ch]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes :as ch]
[app.common.pprint :as pp]
[app.common.schema :as sm]
[app.common.types.components-list :as ctkl]

View file

@ -4,22 +4,18 @@
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.pages.changes
#_:clj-kondo/ignore
(ns app.common.files.changes
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.schema.desc-native :as smd]
[app.common.spec :as us]
[app.common.types.colors-list :as ctcl]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]
[app.common.types.page :as ctp]
@ -423,7 +419,7 @@
(let [lookup (d/getf objects)
update-fn #(d/update-when %1 %2 update-group %1)
xform (comp
(mapcat #(cons % (cph/get-parent-ids objects %)))
(mapcat #(cons % (cfh/get-parent-ids objects %)))
(filter #(contains? #{:group :bool} (-> % lookup :type)))
(distinct))]
@ -477,7 +473,7 @@
(let [invalid-targets (calculate-invalid-targets objects shape-id)]
(and (contains? objects shape-id)
(not (invalid-targets parent-id))
(not (cph/components-nesting-loop? objects shape-id parent-id))
(not (cfh/components-nesting-loop? objects shape-id parent-id))
(or component-swap
(not (ctk/in-component-copy? (get objects parent-id))))))) ;; We don't want to change the structure of component copies
@ -485,7 +481,7 @@
(let [prev-shapes (or prev-shapes [])]
(if index
(d/insert-at-index prev-shapes index shapes)
(cph/append-at-the-end prev-shapes shapes))))
(cfh/append-at-the-end prev-shapes shapes))))
(add-to-parent [parent index shapes]
(let [parent (-> parent
@ -498,7 +494,7 @@
(and (:shape-ref parent)
(#{:group :frame} (:type parent))
(not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group)
(-> (update :touched cfh/set-touched-group :shapes-group)
(dissoc :remote-synced)))))
(remove-from-old-parent [old-objects objects shape-id]
@ -517,7 +513,7 @@
(d/update-in-when [pid :shapes] d/without-obj sid)
(d/update-in-when [pid :shapes] d/vec-without-nils)
(cond-> component? (d/update-when pid #(-> %
(update :touched cph/set-touched-group :shapes-group)
(update :touched cfh/set-touched-group :shapes-group)
(dissoc :remote-synced)))))))))
(update-parent-id [objects id]
(-> objects
@ -698,7 +694,7 @@
;; geometric (position, width or transformation).
(and in-copy? group (not ignore) (not equal?)
(not (and ignore-geometry is-geometry?)))
(-> (update :touched cph/set-touched-group group)
(-> (update :touched cfh/set-touched-group group)
(dissoc :remote-synced))
(nil? val)
@ -744,7 +740,7 @@
(when page-id
(let [page (ctpl/get-page file-data page-id)
shape-and-parents (map #(ctn/get-shape page %)
(cons id (cph/get-parent-ids (:objects page) id)))
(cons id (cfh/get-parent-ids (:objects page) id)))
need-sync? (fn [operation]
; We need to trigger a sync if the shape has changed any
; attribute that participates in components synchronization.
@ -766,7 +762,7 @@
check-shape
(fn [shape-id others]
(let [all-parents (map (partial ctn/get-shape page)
(concat others (cph/get-parent-ids (:objects page) shape-id)))]
(concat others (cfh/get-parent-ids (:objects page) shape-id)))]
(into #{} xform all-parents)))]
(reduce #(set/union %1 (check-shape %2 []))
@ -778,7 +774,7 @@
(when page-id
(let [page (ctpl/get-page file-data page-id)
shape-and-parents (map (partial ctn/get-shape page)
(cons id (cph/get-parent-ids (:objects page) id)))
(cons id (cfh/get-parent-ids (:objects page) id)))
xform (comp (filter :main-instance)
(map :component-id))]
(into #{} xform shape-and-parents))))

View file

@ -4,18 +4,18 @@
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.pages.changes-builder
(ns app.common.files.changes-builder
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.features :as cfeat]
[app.common.files.changes :as cfc]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages :as cp]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.types.component :as ctk]
[app.common.types.file :as ctf]
@ -69,7 +69,7 @@
(defn with-container
[changes container]
(if (cph/page? container)
(if (cfh/page? container)
(vary-meta changes assoc ::page-id (:id container))
(vary-meta changes assoc ::component-id (:id container))))
@ -169,7 +169,7 @@
(assoc :page-id uuid/zero)
(dissoc :component-id))))
[])
new-file-data (cp/process-changes file-data new-changes)]
new-file-data (cfc/process-changes file-data new-changes)]
(vary-meta changes assoc ::file-data new-file-data
::applied-changes-count (count redo-changes)))
changes))
@ -332,7 +332,7 @@
mk-undo-change
(fn [undo-changes shape]
(let [prev-sibling (cph/get-prev-sibling objects (:id shape))]
(let [prev-sibling (cfh/get-prev-sibling objects (:id shape))]
(conj undo-changes
{:type :mov-objects
:page-id (::page-id (meta changes))
@ -465,7 +465,7 @@
:page-id page-id
:parent-id (:frame-id shape)
:frame-id (:frame-id shape)
:index (cph/get-position-on-parent objects id)
:index (cfh/get-position-on-parent objects id)
:obj (cond-> shape
(contains? shape :shapes)
(assoc :shapes []))})))
@ -473,7 +473,7 @@
add-undo-change-parent
(fn [change-set id]
(let [shape (get objects id)
prev-sibling (cph/get-prev-sibling objects (:id shape))]
prev-sibling (cfh/get-prev-sibling objects (:id shape))]
(conj
change-set
{:type :mov-objects
@ -499,7 +499,7 @@
objects (lookup-objects changes)
xform (comp
(mapcat #(cons % (cph/get-parent-ids objects %)))
(mapcat #(cons % (cfh/get-parent-ids objects %)))
(map (d/getf objects))
(filter #(contains? #{:group :bool} (:type %)))
(distinct))

View file

@ -4,10 +4,10 @@
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.pages.focus
(ns app.common.files.focus
(:require
[app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]))

View file

@ -8,7 +8,394 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.schema :as sm]))
[app.common.geom.shapes.common :as gco]
[app.common.schema :as sm]
[app.common.types.components-list :as ctkl]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[clojure.set :as set]
[cuerdas.core :as str]))
(declare reduce-objects)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GENERIC SHAPE SELECTORS AND PREDICATES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn root?
[shape]
(and (= (dm/get-prop shape :type) :frame)
(= (dm/get-prop shape :id) uuid/zero)))
(defn is-direct-child-of-root?
([objects id]
(is-direct-child-of-root? (get objects id)))
([shape]
(and (some? shape) (= (dm/get-prop shape :frame-id) uuid/zero))))
(defn root-frame?
([objects id]
(root-frame? (get objects id)))
([shape]
(and (some? shape)
(= (dm/get-prop shape :type) :frame)
(= (dm/get-prop shape :frame-id) uuid/zero))))
(defn frame-shape?
([objects id]
(frame-shape? (get objects id)))
([shape]
(and (some? shape)
(= :frame (dm/get-prop shape :type)))))
(defn group-shape?
([objects id]
(group-shape? (get objects id)))
([shape]
(and (some? shape)
(= :group (dm/get-prop shape :type)))))
(defn mask-shape?
([shape]
(and ^boolean (group-shape? shape)
^boolean (:masked-group shape)))
([objects id]
(mask-shape? (get objects id))))
(defn bool-shape?
[shape]
(and (some? shape)
(= :bool (dm/get-prop shape :type))))
(defn group-like-shape?
([objects id]
(group-like-shape? (get objects id)))
([shape]
(or ^boolean (group-shape? shape)
^boolean (bool-shape? shape))))
(defn text-shape?
[shape]
(and (some? shape)
(= :text (dm/get-prop shape :type))))
(defn rect-shape?
[shape]
(and (some? shape)
(= :rect (dm/get-prop shape :type))))
(defn circle-shape?
[{:keys [type]}]
(= type :circle))
(defn image-shape?
[shape]
(and (some? shape)
(= :image (dm/get-prop shape :type))))
(defn svg-raw-shape?
[shape]
(and (some? shape)
(= :svg-raw (dm/get-prop shape :type))))
(defn path-shape?
([objects id]
(path-shape? (get objects id)))
([shape]
(and (some? shape)
(= :path (dm/get-prop shape :type)))))
(defn unframed-shape?
"Checks if it's a non-frame shape in the top level."
[shape]
(and (some? shape)
(not (frame-shape? shape))
(= (dm/get-prop shape :frame-id) uuid/zero)))
(defn has-children?
([objects id]
(has-children? (get objects id)))
([shape]
(d/not-empty? (:shapes shape))))
;; ---- ACCESSORS
(defn get-children-ids
[objects id]
(letfn [(get-children-ids-rec [id processed]
(when (not (contains? processed id))
(when-let [shapes (-> (get objects id) :shapes (some-> vec))]
(into shapes (mapcat #(get-children-ids-rec % (conj processed id))) shapes))))]
(get-children-ids-rec id #{})))
(defn get-children-ids-with-self
[objects id]
(into [id] (get-children-ids objects id)))
(defn get-children
[objects id]
(mapv (d/getf objects) (get-children-ids objects id)))
(defn get-children-with-self
[objects id]
(mapv (d/getf objects) (get-children-ids-with-self objects id)))
(defn get-parent
"Retrieve the parent for the shape-id (if exists)"
[objects id]
(when-let [shape (get objects id)]
(get objects (dm/get-prop shape :parent-id))))
(defn get-parent-id
"Retrieve the id of the parent for the shape-id (if exists)"
[objects id]
(when-let [shape (get objects id)]
(dm/get-prop shape :parent-id)))
(defn get-parent-ids
"Returns a vector of parents of the specified shape."
[objects shape-id]
(loop [result []
id shape-id]
(let [parent-id (get-parent-id objects id)]
(if (and (some? parent-id) (not= parent-id id))
(recur (conj result parent-id) parent-id)
result))))
(defn get-parent-ids-seq
"Returns a sequence of parents of the specified shape."
[objects shape-id]
(let [parent-id (get-parent-id objects shape-id)]
(when (and (some? parent-id) (not= parent-id shape-id))
(lazy-seq (cons parent-id (get-parent-ids-seq objects parent-id))))))
(defn get-parent-ids-seq-with-self
"Returns a sequence of parents of the specified shape, including itself."
[objects shape-id]
(cons shape-id (get-parent-ids-seq objects shape-id)))
(defn get-parents
"Returns a vector of parents of the specified shape."
[objects shape-id]
(loop [result [] id shape-id]
(let [parent-id (dm/get-in objects [id :parent-id])]
(if (and (some? parent-id) (not= parent-id id))
(recur (conj result (get objects parent-id)) parent-id)
result))))
(defn get-parent-seq
"Returns a vector of parents of the specified shape."
([objects shape-id]
(get-parent-seq objects (get objects shape-id) shape-id))
([objects shape shape-id]
(let [parent-id (dm/get-prop shape :parent-id)
parent (get objects parent-id)]
(when (and (some? parent) (not= parent-id shape-id))
(lazy-seq (cons parent (get-parent-seq objects parent parent-id)))))))
(defn get-parents-with-self
[objects id]
(let [lookup (d/getf objects)]
(into [(lookup id)] (map lookup) (get-parent-ids objects id))))
(defn hidden-parent?
"Checks the parent for the hidden property"
[objects shape-id]
(let [parent-id (get-parent-id objects shape-id)]
(if (or (nil? parent-id) (nil? shape-id) (= shape-id uuid/zero) (= parent-id uuid/zero))
false
(if ^boolean (dm/get-in objects [parent-id :hidden])
true
(recur objects parent-id)))))
(defn get-parent-ids-with-index
"Returns a tuple with the list of parents and a map with the position within each parent"
[objects shape-id]
(loop [parent-list []
parent-indices {}
current shape-id]
(let [parent-id (get-parent-id objects current)
parent (get objects parent-id)]
(if (and (some? parent) (not= parent-id current))
(let [parent-list (conj parent-list parent-id)
parent-indices (assoc parent-indices parent-id (d/index-of (:shapes parent) current))]
(recur parent-list parent-indices parent-id))
[parent-list parent-indices]))))
(defn get-siblings-ids
[objects id]
(let [parent (get-parent objects id)]
(into [] (remove #(= % id)) (:shapes parent))))
(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 (dm/get-prop shape-or-id :frame-id)))
(= uuid/zero shape-or-id)
(get objects uuid/zero)
:else
(some->> shape-or-id
(get objects)
(get-frame objects)))))
(defn get-root-frame
[objects shape-id]
(let [frame-id
(if (frame-shape? objects shape-id)
shape-id
(dm/get-in objects [shape-id :frame-id]))
frame (get objects frame-id)]
(cond
(or (root? frame) (nil? frame))
nil
(root-frame? frame)
frame
:else
(get-root-frame objects (:frame-id frame)))))
(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-prev-sibling
[objects id]
(let [obj (get objects id)
pid (:parent-id obj)
prt (get objects pid)
shapes (:shapes prt)
pos (d/index-of shapes id)]
(if (= 0 pos) nil (nth shapes (dec pos)))))
(defn get-immediate-children
"Retrieve resolved shape objects that are immediate children
of the specified shape-id"
([objects] (get-immediate-children objects uuid/zero nil))
([objects shape-id] (get-immediate-children objects shape-id nil))
([objects shape-id {:keys [remove-hidden remove-blocked] :or {remove-hidden false remove-blocked false}}]
(let [lookup (d/getf objects)]
(->> (lookup shape-id)
(:shapes)
(keep (fn [cid]
(when-let [child (lookup cid)]
(when (and (or (not remove-hidden) (not (:hidden child)))
(or (not remove-blocked) (not (:blocked child))))
child))))
(remove gco/invalid-geometry?)))))
(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-id shape-id]
(cond
(= current-id parent-candidate)
true
(or (nil? current-id)
(= current-id uuid/zero)
(= current-id (get-in objects [current-id :parent-id])))
false
:else
(recur (get-in objects [current-id :parent-id])))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; COMPONENTS HELPERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn set-touched-group
[touched group]
(conj (or touched #{}) group))
(defn touched-group?
[shape group]
((or (:touched shape) #{}) group))
(defn make-container
[page-or-component type]
(assoc page-or-component :type type))
(defn page?
[container]
(= (:type container) :page))
(defn component?
[container]
(= (:type container) :component))
(defn get-container
[file type id]
(dm/assert! (map? file))
(dm/assert! (keyword? type))
(dm/assert! (uuid? id))
(-> (if (= type :page)
(ctpl/get-page file id)
(ctkl/get-component file id))
(assoc :type type)))
(defn component-touched?
"Check if any shape in the component is touched"
[objects root-id]
(->> (get-children-with-self objects root-id)
(filter (comp seq :touched))
seq))
(defn components-nesting-loop?
"Check if a nesting loop would be created if the given shape is moved below the given parent"
[objects shape-id parent-id]
(let [xf-get-component-id (keep :component-id)
children (get-children-with-self objects shape-id)
child-components (into #{} xf-get-component-id children)
parents (get-parents-with-self objects parent-id)
parent-components (into #{} xf-get-component-id parents)]
(seq (set/intersection child-components parent-components))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ALGORITHMS & TRANSFORMATIONS FOR SHAPES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn get-used-names
"Return a set with the all unique names used in the
@ -44,3 +431,320 @@
(if (contains? used candidate)
(recur (inc counter))
candidate))))))
(defn walk-pages
"Go through all pages of a file and apply a function to each one"
;; The function receives two parameters (page-id and page), and
;; returns the updated page.
[f data]
(update data :pages-index #(d/mapm f %)))
(defn update-object-list
"Update multiple objects in a page at once"
[page objects-list]
(update page :objects
#(into % (d/index-by :id objects-list))))
(defn append-at-the-end
[prev-ids ids]
(reduce (fn [acc id]
(if (some #{id} acc)
acc
(conj acc id)))
(vec prev-ids)
ids))
(defn clean-loops
"Clean a list of ids from circular references."
[objects ids]
(let [parent-selected?
(fn [id]
(let [parents (get-parent-ids objects id)]
(some ids parents)))
add-element
(fn [result id]
(cond-> result
(not (parent-selected? id))
(conj id)))]
(reduce add-element (d/ordered-set) ids)))
(defn indexed-shapes
"Retrieves a list with the indexes for each element in the layer tree.
This will be used for shift+selection."
[objects]
(letfn [(red-fn [cur-idx id]
(let [[prev-idx _] (first cur-idx)
prev-idx (or prev-idx 0)
cur-idx (conj cur-idx [(inc prev-idx) id])]
(rec-index cur-idx id)))
(rec-index [cur-idx id]
(let [object (get objects id)]
(reduce red-fn cur-idx (reverse (:shapes object)))))]
(into {} (rec-index '() uuid/zero))))
(defn expand-region-selection
"Given a selection selects all the shapes between the first and last in
an indexed manner (shift selection)"
[objects selection]
(let [indexed-shapes (indexed-shapes objects)
filter-indexes (->> indexed-shapes
(filter (comp selection second))
(map first))
from (apply min filter-indexes)
to (apply max filter-indexes)]
(->> indexed-shapes
(filter (fn [[idx _]] (and (>= idx from) (<= idx to))))
(map second)
(into #{}))))
(defn order-by-indexed-shapes
[objects ids]
(->> (indexed-shapes objects)
(sort-by first)
(filter (comp (into #{} ids) second))
(map second)))
(defn get-index-replacement
"Given a collection of shapes, calculate their positions
in the parent, find first index and return next one"
[shapes objects]
(->> shapes
(order-by-indexed-shapes objects)
first
(get-position-on-parent objects)
inc))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SHAPES ORGANIZATION (PATH MANAGEMENT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn split-path
"Decompose a string in the form 'one / two / three' into
a vector of strings, normalizing spaces."
[path]
(let [xf (comp (map str/trim)
(remove str/empty?))]
(->> (str/split path "/")
(into [] xf))))
(defn join-path
"Regenerate a path as a string, from a vector."
[path-vec]
(str/join " / " path-vec))
(defn clean-path
"Remove empty items from the path."
[path]
(->> (split-path path)
(join-path)))
(defn parse-path-name
"Parse a string in the form 'group / subgroup / name'.
Retrieve the path and the name in separated values, normalizing spaces."
[path-name]
(let [path-name-split (split-path path-name)
path (str/join " / " (butlast path-name-split))
name (or (last path-name-split) "")]
[path name]))
(defn merge-path-item
"Put the item at the end of the path."
[path name]
(if-not (empty? path)
(if-not (empty? name)
(str path " / " name)
path)
name))
(defn merge-path-item-with-dot
"Put the item at the end of the path."
[path name]
(if-not (empty? path)
(if-not (empty? name)
(str path "\u00A0\u2022\u00A0" name)
path)
name))
(defn compact-path
"Separate last item of the path, and truncate the others if too long:
'one' -> ['' 'one' false]
'one / two / three' -> ['one / two' 'three' false]
'one / two / three / four' -> ['one / two / ...' 'four' true]
'one-item-but-very-long / two' -> ['...' 'two' true] "
[path max-length dot?]
(let [path-split (split-path path)
last-item (last path-split)
merge-path (if dot?
merge-path-item-with-dot
merge-path-item)]
(loop [other-items (seq (butlast path-split))
other-path ""]
(if-let [item (first other-items)]
(let [full-path (-> other-path
(merge-path item)
(merge-path last-item))]
(if (> (count full-path) max-length)
[(merge-path other-path "...") last-item true]
(recur (next other-items)
(merge-path other-path item))))
[other-path last-item false]))))
(defn butlast-path
"Remove the last item of the path."
[path]
(let [split (split-path path)]
(if (= 1 (count split))
""
(join-path (butlast split)))))
(defn last-path
"Returns the last item of the path."
[path]
(last (split-path path)))
(defn compact-name
"Append the first item of the path and the name."
[path name]
(let [path-split (split-path path)]
(merge-path-item (first path-split) name)))
(defn get-frame-objects
"Retrieves a new objects map only with the objects under frame-id (with frame-id)"
[objects frame-id]
(let [ids (concat [frame-id] (get-children-ids objects frame-id))]
(select-keys objects ids)))
(defn objects-by-frame
"Returns a map of the `objects` grouped by frame. Every value of the map has
the same format as objects id->shape-data"
[objects]
;; Implemented with transients for performance. 30~50% better
(letfn [(process-shape [objects [id shape]]
(let [frame-id (if (= :frame (:type shape)) id (:frame-id shape))
cur (-> (or (get objects frame-id)
(transient {}))
(assoc! id shape))]
(assoc! objects frame-id cur)))]
(update-vals
(->> objects
(reduce process-shape (transient {}))
(persistent!))
persistent!)))
(defn selected-subtree
"Given a set of shapes, returns an objects subtree with the parents
of the selected items up to the root. Useful to calculate a partial z-index"
[objects selected]
(let [selected+parents
(into selected
(mapcat #(get-parent-ids objects %))
selected)
remove-children
(fn [shape]
(update shape :shapes #(filterv selected+parents %)))]
(-> (select-keys objects selected+parents)
(update-vals remove-children))))
(defn is-child?
[objects parent-id candidate-child-id]
(loop [cur-id candidate-child-id]
(let [cur-parent-id (dm/get-in objects [cur-id :parent-id])]
(cond
(= parent-id cur-parent-id)
true
(or (= cur-parent-id uuid/zero) (nil? cur-parent-id))
false
:else
(recur cur-parent-id)))))
(defn reduce-objects
([objects reducer-fn init-val]
(reduce-objects objects nil reducer-fn init-val))
([objects check-children? reducer-fn init-val]
(reduce-objects objects check-children? uuid/zero reducer-fn init-val))
([objects check-children? root-id reducer-fn init-val]
(let [root-children (get-in objects [root-id :shapes])]
(if (empty? root-children)
init-val
(loop [current-val init-val
current-id (first root-children)
pending-ids (rest root-children)
processed #{}]
(if (contains? processed current-id)
(recur current-val (first pending-ids) (rest pending-ids) processed)
(let [current-shape (get objects current-id)
processed (conj processed current-id)
next-val (reducer-fn current-val current-shape)
next-pending-ids
(if (or (nil? check-children?) (check-children? current-shape))
(concat (or (:shapes current-shape) []) pending-ids)
pending-ids)]
(if (empty? next-pending-ids)
next-val
(recur next-val (first next-pending-ids) (rest next-pending-ids) processed)))))))))
(defn selected-with-children
[objects selected]
(into selected
(mapcat #(get-children-ids objects %))
selected))
(defn get-shape-id-root-frame
[objects shape-id]
(->> (get-parent-ids objects shape-id)
(cons shape-id)
(map (d/getf objects))
(d/seek root-frame?)
:id))
(defn comparator-layout-z-index
[[idx-a child-a] [idx-b child-b]]
(cond
(> (ctl/layout-z-index child-a) (ctl/layout-z-index child-b)) 1
(< (ctl/layout-z-index child-a) (ctl/layout-z-index child-b)) -1
(< idx-a idx-b) 1
(> idx-a idx-b) -1
:else 0))
(defn sort-layout-children-z-index
[children]
(->> children
(d/enumerate)
(sort comparator-layout-z-index)
(mapv second)))
(defn common-parent-frame
"Search for the common frame for the selected shapes. Otherwise returns the root frame"
[objects selected]
(loop [frame-id (get-in objects [(first selected) :frame-id])
frame-parents (get-parent-ids objects frame-id)
selected (rest selected)]
(if (empty? selected)
frame-id
(let [current (first selected)
parent? (into #{} (get-parent-ids objects current))
[frame-id frame-parents]
(if (parent? frame-id)
[frame-id frame-parents]
(let [frame-id (d/seek parent? frame-parents)]
[frame-id (get-parent-ids objects frame-id)]))]
(recur frame-id frame-parents (rest selected))))))

View file

@ -4,9 +4,9 @@
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.pages.indices
(ns app.common.files.indices
(:require
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.uuid :as uuid]))
(defn generate-child-all-parents-index
@ -18,7 +18,7 @@
([objects shapes]
(let [shape->entry
(fn [shape]
[(:id shape) (cph/get-parent-ids objects (:id shape))])]
[(:id shape) (cfh/get-parent-ids objects (:id shape))])]
(into {} (map shape->entry) shapes))))
(defn create-clip-index

View file

@ -6,8 +6,8 @@
(ns app.common.files.libraries-helpers
(:require
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.uuid :as uuid]))
@ -15,7 +15,7 @@
(defn generate-add-component-changes
[changes root objects file-id page-id components-v2]
(let [name (:name root)
[path name] (cph/parse-path-name name)
[path name] (cfh/parse-path-name name)
[root-shape new-shapes updated-shapes]
(if-not components-v2

View file

@ -9,7 +9,9 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.features :as cfeat]
[app.common.files.changes :as cpc]
[app.common.files.defaults :refer [version]]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
@ -17,8 +19,6 @@
[app.common.geom.shapes.text :as gsht]
[app.common.logging :as l]
[app.common.math :as mth]
[app.common.pages.changes :as cpc]
[app.common.pages.helpers :as cph]
[app.common.svg :as csvg]
[app.common.text :as txt]
[app.common.types.shape :as cts]
@ -111,7 +111,7 @@
(#{:curve :path} (:type object))
(migrate-path)
(cph/frame-shape? object)
(cfh/frame-shape? object)
(fix-frames-selrects)
(and (empty? (:points object)) (not= (:id object) uuid/zero))
@ -258,7 +258,7 @@
(defmethod migrate 11
[data]
(letfn [(update-object [objects shape]
(if (cph/frame-shape? shape)
(if (cfh/frame-shape? shape)
(d/update-when shape :shapes (fn [shapes]
(filterv (fn [id] (contains? objects id)) shapes)))
shape))
@ -293,7 +293,7 @@
(update-object [object]
(cond-> object
(cph/image-shape? object)
(cfh/image-shape? object)
(fix-radius)))
(update-page [page]
@ -315,7 +315,7 @@
(update-container [{:keys [objects] :as container}]
(loop [objects objects
shapes (->> (vals objects)
(filter cph/image-shape?))]
(filter cfh/image-shape?))]
(if-let [shape (first shapes)]
(let [{:keys [id frame-id] :as shape'} (process-shape shape)]
(if (identical? shape shape')
@ -365,11 +365,11 @@
(update-object [object]
(cond-> object
(and (not (cph/text-shape? object))
(and (not (cfh/text-shape? object))
(not (contains? object :strokes)))
(assign-strokes)
(and (not (cph/text-shape? object))
(and (not (cfh/text-shape? object))
(not (contains? object :fills)))
(assign-fills)))
@ -383,7 +383,7 @@
(defmethod migrate 17
[data]
(letfn [(affected-object? [object]
(and (cph/image-shape? object)
(and (cfh/image-shape? object)
(some? (:fills object))
(= 1 (count (:fills object)))
(some? (:fill-color object))
@ -414,7 +414,7 @@
[data]
(letfn [(update-object [object]
(cond-> object
(cph/text-shape? object)
(cfh/text-shape? object)
(dissoc :position-data)))
(update-container [container]
@ -428,7 +428,7 @@
[data]
(letfn [(update-object [object]
(cond-> object
(and (cph/text-shape? object)
(and (cfh/text-shape? object)
(d/not-empty? (:position-data object))
(not (gsht/overlaps-position-data? object (:position-data object))))
(dissoc :position-data)))
@ -506,9 +506,9 @@
(letfn [(update-object [objects object]
(let [frame-id (:frame-id object)
calculated-frame-id
(or (->> (cph/get-parent-ids objects (:id object))
(or (->> (cfh/get-parent-ids objects (:id object))
(map (d/getf objects))
(d/seek cph/frame-shape?)
(d/seek cfh/frame-shape?)
:id)
;; If we cannot find any we let the frame-id as it was before
frame-id)]
@ -555,7 +555,7 @@
(update-object [object]
(let [invalid-node? (complement valid-node?)]
(cond-> object
(cph/text-shape? object)
(cfh/text-shape? object)
(update :content #(txt/transform-nodes invalid-node? fix-node %)))))
(update-container [container]
@ -568,7 +568,7 @@
(defmethod migrate 30
[data]
(letfn [(update-object [object]
(if (and (cph/frame-shape? object)
(if (and (cfh/frame-shape? object)
(not (:shapes object)))
(assoc object :shapes [])
object))
@ -631,8 +631,8 @@
(defmethod migrate 34
[data]
(letfn [(update-object [object]
(if (or (cph/path-shape? object)
(cph/bool-shape? object))
(if (or (cfh/path-shape? object)
(cfh/bool-shape? object))
(dissoc object :x :y :width :height)
object))
(update-container [container]

View file

@ -4,7 +4,7 @@
;;
;; Copyright (c) KALEIDOS INC
(ns app.common.pages.diff
(ns app.common.files.page-diff
"Given a page in its old version and the new will retrieve a map with
the differences that will have an impact in the snap data"
(:require

View file

@ -7,9 +7,9 @@
(ns app.common.files.repair
(:require
[app.common.data :as d]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.logging :as log]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn]
@ -85,7 +85,7 @@
(fn [shape]
; Locate the first frame in parents and set frame-id to it.
(let [page (ctpl/get-page file-data page-id)
frame (cph/get-frame (:objects page) (:parent-id shape))
frame (cfh/get-frame (:objects page) (:parent-id shape))
frame-id (or (:id frame) uuid/zero)]
(log/debug :hint " -> Set to " :frame-id frame-id)
(assoc shape :frame-id frame-id)))]
@ -101,7 +101,7 @@
(fn [shape]
; Locate the first frame in parents and set frame-id to it.
(let [page (ctpl/get-page file-data page-id)
frame (cph/get-frame (:objects page) (:parent-id shape))
frame (cfh/get-frame (:objects page) (:parent-id shape))
frame-id (or (:id frame) uuid/zero)]
(log/debug :hint " -> Set to " :frame-id frame-id)
(assoc shape :frame-id frame-id)))]
@ -143,7 +143,7 @@
(defmethod repair-error :component-not-found
[_ {:keys [shape page-id] :as error} file-data _]
(let [page (ctpl/get-page file-data page-id)
shape-ids (cph/get-children-ids-with-self (:objects page) (:id shape))
shape-ids (cfh/get-children-ids-with-self (:objects page) (:id shape))
repair-shape
(fn [shape]
@ -278,7 +278,7 @@
(pcb/with-file-data file-data)
(pcb/update-shapes [(:id shape)] reassign-shape))
(let [page (ctpl/get-page file-data page-id)
shape-ids (cph/get-children-ids-with-self (:objects page) (:id shape))]
shape-ids (cfh/get-children-ids-with-self (:objects page) (:id shape))]
(-> (pcb/empty-changes nil page-id)
(pcb/with-file-data file-data)
(pcb/update-shapes shape-ids detach-shape))))))

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.types.shape :as cts]
[app.common.types.shape.layout :as ctl]
@ -43,7 +43,7 @@
(defn prepare-move-shapes-into-frame
[changes frame-id shapes objects]
(let [ordered-indexes (cph/order-by-indexed-shapes objects shapes)
(let [ordered-indexes (cfh/order-by-indexed-shapes objects shapes)
parent-id (get-in objects [frame-id :parent-id])
ordered-indexes (->> ordered-indexes (remove #(= % parent-id)))
to-move-shapes (map (d/getf objects) ordered-indexes)]
@ -51,7 +51,7 @@
(-> changes
(cond-> (not (ctl/any-layout? objects frame-id))
(pcb/update-shapes ordered-indexes ctl/remove-layout-item-data))
(pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true)))
(pcb/update-shapes ordered-indexes #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true)))
(pcb/change-parent frame-id to-move-shapes 0)
(cond-> (ctl/grid-layout? objects frame-id)
(pcb/update-shapes [frame-id] ctl/assign-cells))
@ -62,7 +62,7 @@
[changes id parent-id objects selected index frame-name without-fill?]
(let [selected-objs (map #(get objects %) selected)
new-index (or index
(cph/get-index-replacement selected objects))]
(cfh/get-index-replacement selected objects))]
(when (d/not-empty? selected)
(let [srect (gsh/shapes->rect selected-objs)
selected-id (first selected)

View file

@ -8,7 +8,7 @@
(:require
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.schema :as sm]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
@ -114,7 +114,7 @@
(str/ffmt "Parent % not found" (:parent-id shape))
shape file page)
(do
(when-not (cph/root? shape)
(when-not (cfh/root? shape)
(when-not (some #{(:id shape)} (:shapes parent))
(report-error! :child-not-in-parent
(str/ffmt "Shape % not in parent's children list" (:id shape))

View file

@ -8,11 +8,11 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.points :as gpo]
[app.common.geom.shapes.transforms :as gtr]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.uuid :as uuid]))
@ -32,12 +32,12 @@
([{:keys [id] :as shape} bounds-map objects modif-tree current-ref]
(cond
(and (cph/mask-shape? shape) (d/not-empty? (:shapes shape)))
(and (cfh/mask-shape? shape) (d/not-empty? (:shapes shape)))
(create-bounds (get objects (first (:shapes shape))) bounds-map objects modif-tree)
(cph/group-shape? shape)
(cfh/group-shape? shape)
(let [modifiers (dm/get-in modif-tree [id :modifiers])
children (cph/get-immediate-children objects id)
children (cfh/get-immediate-children objects id)
shape-bounds (if current-ref @current-ref @(get bounds-map id))
current-bounds
(cond-> shape-bounds
@ -62,8 +62,8 @@
;; These are the new bounds calculated. Are the "modified" plus any groups they belong to
(let [ids (keys modif-tree)]
(into (set ids)
(mapcat #(->> (cph/get-parent-ids-seq objects %)
(take-while (partial cph/group-like-shape? objects))))
(mapcat #(->> (cfh/get-parent-ids-seq objects %)
(take-while (partial cfh/group-like-shape? objects))))
ids)))
:cljs
@ -77,8 +77,8 @@
(when (some? base-ids)
(let [cid (first base-ids)]
(loop [new-ids
(->> (cph/get-parent-seq objects cid)
(take-while #(and (cph/group-like-shape? %)
(->> (cfh/get-parent-seq objects cid)
(take-while #(and (cfh/group-like-shape? %)
(not (.has ids %))))
(seq))]
(when (some? new-ids)

View file

@ -7,7 +7,7 @@
(ns app.common.geom.modif-tree
(:require
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.modifiers :as ctm]))
(defn add-modifiers
@ -22,7 +22,7 @@
(cond-> modif-tree
(ctm/empty? new-modifiers)
(dissoc id)
(not (ctm/empty? new-modifiers))
(assoc-in [id :modifiers] new-modifiers)))))
@ -50,6 +50,6 @@
(and (ctm/has-structure? modifiers)
(ctm/has-structure-child? modifiers))
(update-children-structure-modifiers
(cph/get-children-ids objects id)
(cfh/get-children-ids objects id)
(ctm/select-child-structre-modifiers modifiers))))]
(reduce apply-shape objects modif-tree)))

View file

@ -8,6 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.bounds-map :as cgb]
[app.common.geom.modif-tree :as cgt]
[app.common.geom.point :as gpt]
@ -20,7 +21,6 @@
[app.common.geom.shapes.points :as gpo]
[app.common.geom.shapes.transforms :as gtr]
[app.common.geom.shapes.tree-seq :as cgst]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]))
@ -120,7 +120,7 @@
(let [bounds (cgb/transform-bounds-map bounds objects modif-tree (:shapes parent))
children
(->> (cph/get-immediate-children objects (:id parent) {:remove-hidden true})
(->> (cfh/get-immediate-children objects (:id parent) {:remove-hidden true})
(map (partial apply-modifiers bounds)))
grid-data (gcgl/calc-layout-data parent @transformed-parent-bounds children bounds objects)]
(loop [modif-tree modif-tree
@ -143,7 +143,7 @@
modifiers (-> (dm/get-in modif-tree [parent-id :modifiers])
(ctm/select-geometry))
has-modifiers? (ctm/child-modifiers? modifiers)
parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent))
parent? (or (cfh/group-like-shape? parent) (cfh/frame-shape? parent))
transformed-parent-bounds (delay (gtr/transform-bounds @(get bounds parent-id) modifiers))]
(cond-> modif-tree
@ -162,7 +162,7 @@
has-modifiers? (ctm/child-modifiers? modifiers)
flex-layout? (ctl/flex-layout? parent)
grid-layout? (ctl/grid-layout? parent)
parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent))
parent? (or (cfh/group-like-shape? parent) (cfh/frame-shape? parent))
transformed-parent-bounds (delay (gtr/transform-bounds @(get bounds parent-id) modifiers))
@ -221,7 +221,7 @@
(-> modifiers
(ctm/resize (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))
children (->> (cph/get-immediate-children objects parent-id)
children (->> (cfh/get-immediate-children objects parent-id)
(remove :hidden)
(remove gco/invalid-geometry?))
@ -274,7 +274,7 @@
[modif-tree bounds]
(let [from-layout
(->> (cph/get-parent-ids objects layout-id)
(->> (cfh/get-parent-ids objects layout-id)
(d/seek sizing-auto-layouts))
shapes

View file

@ -8,13 +8,13 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.rect :as grc]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]))
[app.common.math :as mth]))
(defn shape-stroke-margin
[shape stroke-width]
(if (cph/path-shape? shape)
(if (cfh/path-shape? shape)
;; TODO: Calculate with the stroke offset (not implemented yet
(mth/sqrt (* 2 stroke-width stroke-width))
(- (mth/sqrt (* 2 stroke-width stroke-width)) stroke-width)))
@ -81,7 +81,7 @@
(defn get-shape-filter-bounds
[shape]
(if (and (cph/svg-raw-shape? shape)
(if (and (cfh/svg-raw-shape? shape)
(not= :svg (dm/get-in shape [:content :tag])))
(dm/get-prop shape :selrect)
(let [filters (shape->filters shape)
@ -155,19 +155,19 @@
(or (:masked-group shape) (= :bool (:type shape)))
[(calculate-base-bounds shape)]
(and (cph/frame-shape? shape) (not (:show-content shape)))
(and (cfh/frame-shape? shape) (not (:show-content shape)))
[(calculate-base-bounds shape)]
:else
(cph/reduce-objects
(cfh/reduce-objects
objects
(fn [shape]
(and (d/not-empty? (:shapes shape))
(or (not (cph/frame-shape? shape))
(or (not (cfh/frame-shape? shape))
(:show-content shape))
(or (not (cph/group-shape? shape))
(or (not (cfh/group-shape? shape))
(not (:masked-group shape)))))
(:id shape)
(fn [result child]
@ -177,7 +177,7 @@
children-bounds
(cond->> (grc/join-rects bounds)
(not (cph/frame-shape? shape)) (or (:children-bounds shape)))
(not (cfh/frame-shape? shape)) (or (:children-bounds shape)))
filters (shape->filters shape)
blur-value (or (-> shape :blur :value) 0)]

View file

@ -7,6 +7,7 @@
(ns app.common.geom.shapes.flex-layout.drop-area
(:require
[app.common.data :as d]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
@ -14,7 +15,6 @@
[app.common.geom.shapes.flex-layout.layout-data :as fld]
[app.common.geom.shapes.points :as gpo]
[app.common.geom.shapes.transforms :as gtr]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl]))
@ -199,7 +199,7 @@
(defn get-drop-areas
[frame objects bounds]
(let [[frame modifiers] (get-flip-modifiers frame)
children (->> (cph/get-immediate-children objects (:id frame))
children (->> (cfh/get-immediate-children objects (:id frame))
(remove :hidden)
(map #(cond-> % (some? modifiers)
(gtr/transform-shape modifiers)))

View file

@ -8,13 +8,13 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.grid-layout.layout-data :as ld]
[app.common.geom.shapes.points :as gpo]
[app.common.geom.shapes.transforms :as gtr]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl]))
@ -252,7 +252,7 @@
[frame-id objects position]
(let [frame (get objects frame-id)
children (->> (cph/get-immediate-children objects (:id frame))
children (->> (cfh/get-immediate-children objects (:id frame))
(remove :hidden)
(map #(vector (gpo/parent-coords-bounds (:points %) (:points frame)) %)))

View file

@ -8,14 +8,14 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.path :as gpp]
[app.common.geom.shapes.text :as gte]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]))
[app.common.math :as mth]))
(defn orientation
"Given three ordered points gives the orientation
@ -315,15 +315,15 @@
(update :height + (* 2 swidth)))]
(or (not shape)
(cond
(cph/path-shape? shape)
(cfh/path-shape? shape)
(and (overlaps-rect-points? rect (:points shape))
(overlaps-path? shape rect true))
(cph/circle-shape? shape)
(cfh/circle-shape? shape)
(and (overlaps-rect-points? rect (:points shape))
(overlaps-ellipse? shape rect))
(cph/text-shape? shape)
(cfh/text-shape? shape)
(overlaps-text? shape rect)
:else
@ -354,9 +354,9 @@
(defn has-point?
[shape point]
(if (or ^boolean (cph/path-shape? shape)
^boolean (cph/bool-shape? shape)
^boolean (cph/circle-shape? shape))
(if (or ^boolean (cfh/path-shape? shape)
^boolean (cfh/bool-shape? shape)
^boolean (cfh/circle-shape? shape))
(slow-has-point? shape point)
(fast-has-point? shape point)))

View file

@ -7,12 +7,12 @@
(ns app.common.geom.shapes.min-size-layout
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes.flex-layout.bounds :as fb]
[app.common.geom.shapes.flex-layout.layout-data :as fd]
[app.common.geom.shapes.grid-layout.bounds :as gb]
[app.common.geom.shapes.grid-layout.layout-data :as gd]
[app.common.geom.shapes.points :as gpo]
[app.common.pages.helpers :as cph]
[app.common.types.shape.layout :as ctl]))
(defn child-min-width
@ -21,14 +21,14 @@
(and (ctl/fill-width? child) (ctl/flex-layout? child))
(ctl/child-min-width child)
;; Uncomment this to activate "auto" as min size
#_(let [children (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
#_(let [children (cfh/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
(max (ctl/child-min-width child)
(gpo/width-points (fb/layout-content-bounds bounds child children objects))))
(and (ctl/fill-width? child)
(ctl/grid-layout? child))
(let [children
(->> (cph/get-immediate-children objects (:id child) {:remove-hidden true})
(->> (cfh/get-immediate-children objects (:id child) {:remove-hidden true})
(map #(vector @(get bounds (:id %)) %)))
layout-data (gd/calc-layout-data child @(get bounds (:id child)) children bounds objects true)]
(max (ctl/child-min-width child)
@ -46,13 +46,13 @@
(and (ctl/fill-height? child) (ctl/flex-layout? child))
;; Uncomment this to activate "auto" as min size
(ctl/child-min-height child)
#_(let [children (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
#_(let [children (cfh/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
(max (ctl/child-min-height child)
(gpo/height-points (fb/layout-content-bounds bounds child children objects))))
(and (ctl/fill-height? child) (ctl/grid-layout? child))
(let [children
(->> (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})
(->> (cfh/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})
(map (fn [child] [@(get bounds (:id child)) child])))
layout-data (gd/calc-layout-data child (:points child) children bounds objects true)
auto-bounds (gb/layout-content-bounds bounds child layout-data)]

View file

@ -8,6 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
@ -15,7 +16,6 @@
[app.common.geom.shapes.points :as gpo]
[app.common.geom.shapes.transforms :as gtr]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]))
(defn size-pixel-precision
@ -30,7 +30,7 @@
transform (gtr/calculate-transform points center selrect)
transform-inverse (when (some? transform) (gmt/inverse transform))
path? (cph/path-shape? shape)
path? (cfh/path-shape? shape)
vertical-line? (and path? (<= curr-width 0.01))
horizontal-line? (and path? (<= curr-height 0.01))

View file

@ -8,6 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
@ -15,7 +16,6 @@
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.path :as gpa]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.record :as cr]
[app.common.types.modifiers :as ctm]))
@ -461,16 +461,16 @@
(reduce
(fn [objects id]
(let [shape (get objects id)
children (cph/get-immediate-children objects id)
children (cfh/get-immediate-children objects id)
shape
(cond
(cph/mask-shape? shape)
(cfh/mask-shape? shape)
(update-mask-selrect shape children)
(cph/bool-shape? shape)
(cfh/bool-shape? shape)
(update-bool-selrect shape children objects)
(cph/group-shape? shape)
(cfh/group-shape? shape)
(update-group-selrect shape children)
:else
@ -490,7 +490,7 @@
(let [transform (ctm/modifiers->transform modifiers)]
(cond-> shape
(and (some? transform)
(not (cph/root? shape)))
(not (cfh/root? shape)))
(apply-transform transform)
(ctm/has-structure? modifiers)
@ -545,7 +545,7 @@
(let [modifiers (cond-> (get-in modif-tree [(:id child) :modifiers])
propagate? (ctm/add-modifiers parent-modifiers))
child (transform-shape child modifiers)
parent? (cph/group-like-shape? child)
parent? (cfh/group-like-shape? child)
modif-tree
(cond-> modif-tree
@ -568,13 +568,13 @@
(map (d/getf objects) $)
(apply-children-modifiers objects modif-tree modifiers $ propagate?))]
(cond
(cph/mask-shape? group)
(cfh/mask-shape? group)
(update-mask-selrect group children)
(cph/bool-shape? group)
(cfh/bool-shape? group)
(transform-shape group modifiers)
(cph/group-shape? group)
(cfh/group-shape? group)
(update-group-selrect group children)
:else

View file

@ -8,7 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]))
@ -34,7 +34,7 @@
parent (get objects parent-id)]
(cond
;; Frame found, but not layout we return the last layout found (or the id)
(and ^boolean (cph/frame-shape? parent)
(and ^boolean (cfh/frame-shape? parent)
(not ^boolean (ctl/any-layout? parent)))
last-root
@ -59,12 +59,12 @@
(let [root (get-reflow-root id objects)
;; Remove the children from the current root
roots
(if ^boolean (cph/has-children? objects root)
(into #{} (remove (partial cph/is-child? objects root)) roots)
(if ^boolean (cfh/has-children? objects root)
(into #{} (remove (partial cfh/is-child? objects root)) roots)
roots)
contains-parent?
(->> (cph/get-parent-ids objects root)
(->> (cfh/get-parent-ids objects root)
(some (partial contains? roots)))]
(cond-> roots

View file

@ -7,10 +7,10 @@
(ns app.common.geom.snap
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]))
(defn rect->snap-points
@ -41,7 +41,7 @@
(defn shape->snap-points
[shape]
(if ^boolean (cph/frame-shape? shape)
(if ^boolean (cfh/frame-shape? shape)
(frame->snap-points shape)
(->> (dm/get-prop shape :points)
(into #{(gsh/shape->center shape)}))))
@ -51,7 +51,7 @@
(cond
(and (some? frame)
(not ^boolean (ctst/rotated-frame? frame))
(not ^boolean (cph/is-direct-child-of-root? frame)))
(not ^boolean (cfh/is-direct-child-of-root? frame)))
#{}
(= :x (:axis guide))

View file

@ -1,19 +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) KALEIDOS INC
(ns app.common.pages
"A common (clj/cljs) functions and specs for pages."
(:require
[app.common.data.macros :as dm]
[app.common.pages.changes :as changes]
[app.common.pages.indices :as indices]))
;; Indices
(dm/export indices/generate-child-all-parents-index)
(dm/export indices/create-clip-index)
;; Process changes
(dm/export changes/process-changes)

View file

@ -1,714 +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) KALEIDOS INC
(ns app.common.pages.helpers
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes.common :as gco]
[app.common.types.components-list :as ctkl]
[app.common.types.pages-list :as ctpl]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[clojure.set :as set]
[cuerdas.core :as str]))
(declare reduce-objects)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GENERIC SHAPE SELECTORS AND PREDICATES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn root?
[shape]
(and (= (dm/get-prop shape :type) :frame)
(= (dm/get-prop shape :id) uuid/zero)))
(defn is-direct-child-of-root?
([objects id]
(is-direct-child-of-root? (get objects id)))
([shape]
(and (some? shape) (= (dm/get-prop shape :frame-id) uuid/zero))))
(defn root-frame?
([objects id]
(root-frame? (get objects id)))
([shape]
(and (some? shape)
(= (dm/get-prop shape :type) :frame)
(= (dm/get-prop shape :frame-id) uuid/zero))))
(defn frame-shape?
([objects id]
(frame-shape? (get objects id)))
([shape]
(and (some? shape)
(= :frame (dm/get-prop shape :type)))))
(defn group-shape?
([objects id]
(group-shape? (get objects id)))
([shape]
(and (some? shape)
(= :group (dm/get-prop shape :type)))))
(defn mask-shape?
([shape]
(and ^boolean (group-shape? shape)
^boolean (:masked-group shape)))
([objects id]
(mask-shape? (get objects id))))
(defn bool-shape?
[shape]
(and (some? shape)
(= :bool (dm/get-prop shape :type))))
(defn group-like-shape?
([objects id]
(group-like-shape? (get objects id)))
([shape]
(or ^boolean (group-shape? shape)
^boolean (bool-shape? shape))))
(defn text-shape?
[shape]
(and (some? shape)
(= :text (dm/get-prop shape :type))))
(defn rect-shape?
[shape]
(and (some? shape)
(= :rect (dm/get-prop shape :type))))
(defn circle-shape?
[{:keys [type]}]
(= type :circle))
(defn image-shape?
[shape]
(and (some? shape)
(= :image (dm/get-prop shape :type))))
(defn svg-raw-shape?
[shape]
(and (some? shape)
(= :svg-raw (dm/get-prop shape :type))))
(defn path-shape?
([objects id]
(path-shape? (get objects id)))
([shape]
(and (some? shape)
(= :path (dm/get-prop shape :type)))))
(defn unframed-shape?
"Checks if it's a non-frame shape in the top level."
[shape]
(and (some? shape)
(not (frame-shape? shape))
(= (dm/get-prop shape :frame-id) uuid/zero)))
(defn has-children?
([objects id]
(has-children? (get objects id)))
([shape]
(d/not-empty? (:shapes shape))))
;; ---- ACCESSORS
(defn get-children-ids
[objects id]
(letfn [(get-children-ids-rec [id processed]
(when (not (contains? processed id))
(when-let [shapes (-> (get objects id) :shapes (some-> vec))]
(into shapes (mapcat #(get-children-ids-rec % (conj processed id))) shapes))))]
(get-children-ids-rec id #{})))
(defn get-children-ids-with-self
[objects id]
(into [id] (get-children-ids objects id)))
(defn get-children
[objects id]
(mapv (d/getf objects) (get-children-ids objects id)))
(defn get-children-with-self
[objects id]
(mapv (d/getf objects) (get-children-ids-with-self objects id)))
(defn get-parent
"Retrieve the parent for the shape-id (if exists)"
[objects id]
(when-let [shape (get objects id)]
(get objects (dm/get-prop shape :parent-id))))
(defn get-parent-id
"Retrieve the id of the parent for the shape-id (if exists)"
[objects id]
(when-let [shape (get objects id)]
(dm/get-prop shape :parent-id)))
(defn get-parent-ids
"Returns a vector of parents of the specified shape."
[objects shape-id]
(loop [result []
id shape-id]
(let [parent-id (get-parent-id objects id)]
(if (and (some? parent-id) (not= parent-id id))
(recur (conj result parent-id) parent-id)
result))))
(defn get-parent-ids-seq
"Returns a sequence of parents of the specified shape."
[objects shape-id]
(let [parent-id (get-parent-id objects shape-id)]
(when (and (some? parent-id) (not= parent-id shape-id))
(lazy-seq (cons parent-id (get-parent-ids-seq objects parent-id))))))
(defn get-parent-ids-seq-with-self
"Returns a sequence of parents of the specified shape, including itself."
[objects shape-id]
(cons shape-id (get-parent-ids-seq objects shape-id)))
(defn get-parents
"Returns a vector of parents of the specified shape."
[objects shape-id]
(loop [result [] id shape-id]
(let [parent-id (dm/get-in objects [id :parent-id])]
(if (and (some? parent-id) (not= parent-id id))
(recur (conj result (get objects parent-id)) parent-id)
result))))
(defn get-parent-seq
"Returns a vector of parents of the specified shape."
([objects shape-id]
(get-parent-seq objects (get objects shape-id) shape-id))
([objects shape shape-id]
(let [parent-id (dm/get-prop shape :parent-id)
parent (get objects parent-id)]
(when (and (some? parent) (not= parent-id shape-id))
(lazy-seq (cons parent (get-parent-seq objects parent parent-id)))))))
(defn get-parents-with-self
[objects id]
(let [lookup (d/getf objects)]
(into [(lookup id)] (map lookup) (get-parent-ids objects id))))
(defn hidden-parent?
"Checks the parent for the hidden property"
[objects shape-id]
(let [parent-id (get-parent-id objects shape-id)]
(if (or (nil? parent-id) (nil? shape-id) (= shape-id uuid/zero) (= parent-id uuid/zero))
false
(if ^boolean (dm/get-in objects [parent-id :hidden])
true
(recur objects parent-id)))))
(defn get-parent-ids-with-index
"Returns a tuple with the list of parents and a map with the position within each parent"
[objects shape-id]
(loop [parent-list []
parent-indices {}
current shape-id]
(let [parent-id (get-parent-id objects current)
parent (get objects parent-id)]
(if (and (some? parent) (not= parent-id current))
(let [parent-list (conj parent-list parent-id)
parent-indices (assoc parent-indices parent-id (d/index-of (:shapes parent) current))]
(recur parent-list parent-indices parent-id))
[parent-list parent-indices]))))
(defn get-siblings-ids
[objects id]
(let [parent (get-parent objects id)]
(into [] (remove #(= % id)) (:shapes parent))))
(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 (dm/get-prop shape-or-id :frame-id)))
(= uuid/zero shape-or-id)
(get objects uuid/zero)
:else
(some->> shape-or-id
(get objects)
(get-frame objects)))))
(defn get-root-frame
[objects shape-id]
(let [frame-id
(if (frame-shape? objects shape-id)
shape-id
(dm/get-in objects [shape-id :frame-id]))
frame (get objects frame-id)]
(cond
(or (root? frame) (nil? frame))
nil
(root-frame? frame)
frame
:else
(get-root-frame objects (:frame-id frame)))))
(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-prev-sibling
[objects id]
(let [obj (get objects id)
pid (:parent-id obj)
prt (get objects pid)
shapes (:shapes prt)
pos (d/index-of shapes id)]
(if (= 0 pos) nil (nth shapes (dec pos)))))
(defn get-immediate-children
"Retrieve resolved shape objects that are immediate children
of the specified shape-id"
([objects] (get-immediate-children objects uuid/zero nil))
([objects shape-id] (get-immediate-children objects shape-id nil))
([objects shape-id {:keys [remove-hidden remove-blocked] :or {remove-hidden false remove-blocked false}}]
(let [lookup (d/getf objects)]
(->> (lookup shape-id)
(:shapes)
(keep (fn [cid]
(when-let [child (lookup cid)]
(when (and (or (not remove-hidden) (not (:hidden child)))
(or (not remove-blocked) (not (:blocked child))))
child))))
(remove gco/invalid-geometry?)))))
(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-id shape-id]
(cond
(= current-id parent-candidate)
true
(or (nil? current-id)
(= current-id uuid/zero)
(= current-id (get-in objects [current-id :parent-id])))
false
:else
(recur (get-in objects [current-id :parent-id])))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; COMPONENTS HELPERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn set-touched-group
[touched group]
(conj (or touched #{}) group))
(defn touched-group?
[shape group]
((or (:touched shape) #{}) group))
(defn make-container
[page-or-component type]
(assoc page-or-component :type type))
(defn page?
[container]
(= (:type container) :page))
(defn component?
[container]
(= (:type container) :component))
(defn get-container
[file type id]
(dm/assert! (map? file))
(dm/assert! (keyword? type))
(dm/assert! (uuid? id))
(-> (if (= type :page)
(ctpl/get-page file id)
(ctkl/get-component file id))
(assoc :type type)))
(defn component-touched?
"Check if any shape in the component is touched"
[objects root-id]
(->> (get-children-with-self objects root-id)
(filter (comp seq :touched))
seq))
(defn components-nesting-loop?
"Check if a nesting loop would be created if the given shape is moved below the given parent"
[objects shape-id parent-id]
(let [xf-get-component-id (keep :component-id)
children (get-children-with-self objects shape-id)
child-components (into #{} xf-get-component-id children)
parents (get-parents-with-self objects parent-id)
parent-components (into #{} xf-get-component-id parents)]
(seq (set/intersection child-components parent-components))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ALGORITHMS & TRANSFORMATIONS FOR SHAPES
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn walk-pages
"Go through all pages of a file and apply a function to each one"
;; The function receives two parameters (page-id and page), and
;; returns the updated page.
[f data]
(update data :pages-index #(d/mapm f %)))
(defn update-object-list
"Update multiple objects in a page at once"
[page objects-list]
(update page :objects
#(into % (d/index-by :id objects-list))))
(defn append-at-the-end
[prev-ids ids]
(reduce (fn [acc id]
(if (some #{id} acc)
acc
(conj acc id)))
(vec prev-ids)
ids))
(defn clean-loops
"Clean a list of ids from circular references."
[objects ids]
(let [parent-selected?
(fn [id]
(let [parents (get-parent-ids objects id)]
(some ids parents)))
add-element
(fn [result id]
(cond-> result
(not (parent-selected? id))
(conj id)))]
(reduce add-element (d/ordered-set) ids)))
(defn indexed-shapes
"Retrieves a list with the indexes for each element in the layer tree.
This will be used for shift+selection."
[objects]
(letfn [(red-fn [cur-idx id]
(let [[prev-idx _] (first cur-idx)
prev-idx (or prev-idx 0)
cur-idx (conj cur-idx [(inc prev-idx) id])]
(rec-index cur-idx id)))
(rec-index [cur-idx id]
(let [object (get objects id)]
(reduce red-fn cur-idx (reverse (:shapes object)))))]
(into {} (rec-index '() uuid/zero))))
(defn expand-region-selection
"Given a selection selects all the shapes between the first and last in
an indexed manner (shift selection)"
[objects selection]
(let [indexed-shapes (indexed-shapes objects)
filter-indexes (->> indexed-shapes
(filter (comp selection second))
(map first))
from (apply min filter-indexes)
to (apply max filter-indexes)]
(->> indexed-shapes
(filter (fn [[idx _]] (and (>= idx from) (<= idx to))))
(map second)
(into #{}))))
(defn order-by-indexed-shapes
[objects ids]
(->> (indexed-shapes objects)
(sort-by first)
(filter (comp (into #{} ids) second))
(map second)))
(defn get-index-replacement
"Given a collection of shapes, calculate their positions
in the parent, find first index and return next one"
[shapes objects]
(->> shapes
(order-by-indexed-shapes objects)
first
(get-position-on-parent objects)
inc))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SHAPES ORGANIZATION (PATH MANAGEMENT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn split-path
"Decompose a string in the form 'one / two / three' into
a vector of strings, normalizing spaces."
[path]
(let [xf (comp (map str/trim)
(remove str/empty?))]
(->> (str/split path "/")
(into [] xf))))
(defn join-path
"Regenerate a path as a string, from a vector."
[path-vec]
(str/join " / " path-vec))
(defn clean-path
"Remove empty items from the path."
[path]
(->> (split-path path)
(join-path)))
(defn parse-path-name
"Parse a string in the form 'group / subgroup / name'.
Retrieve the path and the name in separated values, normalizing spaces."
[path-name]
(let [path-name-split (split-path path-name)
path (str/join " / " (butlast path-name-split))
name (or (last path-name-split) "")]
[path name]))
(defn merge-path-item
"Put the item at the end of the path."
[path name]
(if-not (empty? path)
(if-not (empty? name)
(str path " / " name)
path)
name))
(defn merge-path-item-with-dot
"Put the item at the end of the path."
[path name]
(if-not (empty? path)
(if-not (empty? name)
(str path "\u00A0\u2022\u00A0" name)
path)
name))
(defn compact-path
"Separate last item of the path, and truncate the others if too long:
'one' -> ['' 'one' false]
'one / two / three' -> ['one / two' 'three' false]
'one / two / three / four' -> ['one / two / ...' 'four' true]
'one-item-but-very-long / two' -> ['...' 'two' true] "
[path max-length dot?]
(let [path-split (split-path path)
last-item (last path-split)
merge-path (if dot?
merge-path-item-with-dot
merge-path-item)]
(loop [other-items (seq (butlast path-split))
other-path ""]
(if-let [item (first other-items)]
(let [full-path (-> other-path
(merge-path item)
(merge-path last-item))]
(if (> (count full-path) max-length)
[(merge-path other-path "...") last-item true]
(recur (next other-items)
(merge-path other-path item))))
[other-path last-item false]))))
(defn butlast-path
"Remove the last item of the path."
[path]
(let [split (split-path path)]
(if (= 1 (count split))
""
(join-path (butlast split)))))
(defn last-path
"Returns the last item of the path."
[path]
(last (split-path path)))
(defn compact-name
"Append the first item of the path and the name."
[path name]
(let [path-split (split-path path)]
(merge-path-item (first path-split) name)))
(defn get-frame-objects
"Retrieves a new objects map only with the objects under frame-id (with frame-id)"
[objects frame-id]
(let [ids (concat [frame-id] (get-children-ids objects frame-id))]
(select-keys objects ids)))
(defn objects-by-frame
"Returns a map of the `objects` grouped by frame. Every value of the map has
the same format as objects id->shape-data"
[objects]
;; Implemented with transients for performance. 30~50% better
(letfn [(process-shape [objects [id shape]]
(let [frame-id (if (= :frame (:type shape)) id (:frame-id shape))
cur (-> (or (get objects frame-id)
(transient {}))
(assoc! id shape))]
(assoc! objects frame-id cur)))]
(update-vals
(->> objects
(reduce process-shape (transient {}))
(persistent!))
persistent!)))
(defn selected-subtree
"Given a set of shapes, returns an objects subtree with the parents
of the selected items up to the root. Useful to calculate a partial z-index"
[objects selected]
(let [selected+parents
(into selected
(mapcat #(get-parent-ids objects %))
selected)
remove-children
(fn [shape]
(update shape :shapes #(filterv selected+parents %)))]
(-> (select-keys objects selected+parents)
(update-vals remove-children))))
(defn is-child?
[objects parent-id candidate-child-id]
(loop [cur-id candidate-child-id]
(let [cur-parent-id (dm/get-in objects [cur-id :parent-id])]
(cond
(= parent-id cur-parent-id)
true
(or (= cur-parent-id uuid/zero) (nil? cur-parent-id))
false
:else
(recur cur-parent-id)))))
(defn reduce-objects
([objects reducer-fn init-val]
(reduce-objects objects nil reducer-fn init-val))
([objects check-children? reducer-fn init-val]
(reduce-objects objects check-children? uuid/zero reducer-fn init-val))
([objects check-children? root-id reducer-fn init-val]
(let [root-children (get-in objects [root-id :shapes])]
(if (empty? root-children)
init-val
(loop [current-val init-val
current-id (first root-children)
pending-ids (rest root-children)
processed #{}]
(if (contains? processed current-id)
(recur current-val (first pending-ids) (rest pending-ids) processed)
(let [current-shape (get objects current-id)
processed (conj processed current-id)
next-val (reducer-fn current-val current-shape)
next-pending-ids
(if (or (nil? check-children?) (check-children? current-shape))
(concat (or (:shapes current-shape) []) pending-ids)
pending-ids)]
(if (empty? next-pending-ids)
next-val
(recur next-val (first next-pending-ids) (rest next-pending-ids) processed)))))))))
(defn selected-with-children
[objects selected]
(into selected
(mapcat #(get-children-ids objects %))
selected))
(defn get-shape-id-root-frame
[objects shape-id]
(->> (get-parent-ids objects shape-id)
(cons shape-id)
(map (d/getf objects))
(d/seek root-frame?)
:id))
(defn comparator-layout-z-index
[[idx-a child-a] [idx-b child-b]]
(cond
(> (ctl/layout-z-index child-a) (ctl/layout-z-index child-b)) 1
(< (ctl/layout-z-index child-a) (ctl/layout-z-index child-b)) -1
(< idx-a idx-b) 1
(> idx-a idx-b) -1
:else 0))
(defn sort-layout-children-z-index
[children]
(->> children
(d/enumerate)
(sort comparator-layout-z-index)
(mapv second)))
(defn common-parent-frame
"Search for the common frame for the selected shapes. Otherwise returns the root frame"
[objects selected]
(loop [frame-id (get-in objects [(first selected) :frame-id])
frame-parents (get-parent-ids objects frame-id)
selected (rest selected)]
(if (empty? selected)
frame-id
(let [current (first selected)
parent? (into #{} (get-parent-ids objects current))
[frame-id frame-parents]
(if (parent? frame-id)
[frame-id frame-parents]
(let [frame-id (d/seek parent? frame-parents)]
[frame-id (get-parent-ids objects frame-id)]))]
(recur frame-id frame-parents (rest selected))))))

View file

@ -10,7 +10,6 @@
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
@ -114,7 +113,7 @@
(nil? shape)
nil
(cph/root? shape)
(cfh/root? shape)
nil
(ctk/instance-root? shape)
@ -134,7 +133,7 @@
(nil? shape)
nil
(cph/root? shape)
(cfh/root? shape)
nil
(ctk/instance-head? shape)
@ -153,7 +152,7 @@
(nil? shape)
nil
(cph/root? shape)
(cfh/root? shape)
nil
(ctk/instance-root? shape)
@ -166,14 +165,14 @@
"Get the top shape of the copy."
[objects shape]
(when (:shape-ref shape)
(let [parent (cph/get-parent objects (:id shape))]
(let [parent (cfh/get-parent objects (:id shape))]
(or (get-copy-root objects parent) shape))))
(defn inside-component-main?
"Check if the shape is a component main instance or is inside one."
[objects shape]
(cond
(or (nil? shape) (cph/root? shape))
(or (nil? shape) (cfh/root? shape))
false
(nil? (:parent-id shape)) ; This occurs in the root of components v1
true
@ -203,7 +202,7 @@
:component-file file-id
:component-root true
:main-instance true)
new-children (->> (cph/get-children objects (:id root))
new-children (->> (cfh/get-children objects (:id root))
(map #(dissoc % :component-root)))]
[(assoc new-root :id new-id)
nil

View file

@ -10,10 +10,10 @@
[app.common.data.macros :as dm]
[app.common.features :as cfeat]
[app.common.files.defaults :refer [version]]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.logging :as l]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.text :as ct]
[app.common.types.color :as ctc]
@ -147,8 +147,8 @@
(let [components-v2 (dm/get-in file-data [:options :components-v2])]
(if (and components-v2 (not (:deleted component)))
(let [component-page (get-component-page file-data component)]
(cph/make-container component-page :page))
(cph/make-container component :component))))
(cfh/make-container component-page :page))
(cfh/make-container component :component))))
(defn get-component-root
"Retrieve the root shape of the component."
@ -220,7 +220,7 @@
(if (and components-v2
(not (:deleted component))) ;; the deleted components have its children in the :objects property
(let [instance-page (get-component-page file-data component)]
(cph/get-children-with-self (:objects instance-page) (:main-instance-id component)))
(cfh/get-children-with-self (:objects instance-page) (:main-instance-id component)))
(vals (:objects component)))))
;; Return true if the object is a component that exists on the file or its libraries (even a deleted one)
@ -241,7 +241,7 @@
(let [component-page (get-component-page file-data component)
page-objects (:objects component-page)
objects (->> (cons (:main-instance-id component)
(cph/get-children-ids page-objects (:main-instance-id component)))
(cfh/get-children-ids page-objects (:main-instance-id component)))
(map #(get page-objects %))
(d/index-by :id))]
(assoc component :objects objects))
@ -716,7 +716,7 @@
(find-used-components
[page root]
(let [children (cph/get-children-with-self (:objects page) (:id root))]
(let [children (cfh/get-children-with-self (:objects page) (:id root))]
(reduce (fn [libs-to-show shape]
(if (ctk/instance-head? shape)
(add-component libs-to-show (:component-file shape) (:component-id shape))

View file

@ -9,6 +9,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.common :as gco]
@ -16,7 +17,6 @@
[app.common.geom.shapes.effects :as gse]
[app.common.geom.shapes.strokes :as gss]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
[app.common.types.shape.layout :as ctl]
[clojure.core :as c]))
@ -739,7 +739,7 @@
(apply-scale-content
[shape value]
(cond-> shape
(cph/text-shape? shape)
(cfh/text-shape? shape)
(update-text-content scale-text-content value)
:always

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.bounds :as gsb]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]))
;; WARNING: options are not deleted when changing event or action type, so it can be
@ -182,7 +182,7 @@
(dm/assert!
"The `:after-delay` event type incompatible with frame shapes"
(or (not= event-type :after-delay)
(cph/frame-shape? shape)))
(cfh/frame-shape? shape)))
(if (= (:event-type interaction) event-type)
interaction
@ -497,12 +497,12 @@
(let [;; When the interactive item is inside a nested frame we need to add to the offset the position
;; of the parent-frame otherwise the position won't match
shape-frame (cph/get-frame objects shape)
shape-frame (cfh/get-frame objects shape)
frame-offset (if (or (not= :manual (:overlay-pos-type interaction))
(nil? shape-frame)
(cph/is-direct-child-of-root? shape-frame)
(cph/root? shape-frame))
(cfh/is-direct-child-of-root? shape-frame)
(cfh/root? shape-frame))
frame-offset
(gpt/add frame-offset (gpt/point shape-frame)))]

View file

@ -8,10 +8,10 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]))
@ -40,7 +40,7 @@
(update :shapes update-parent-shapes)
(update :shapes d/vec-without-nils)
(cond-> (and (ctk/in-component-copy? parent) (not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group)
(-> (update :touched cfh/set-touched-group :shapes-group)
(dissoc :remote-synced)))))
update-objects
@ -85,14 +85,14 @@
(let [parent (update parent :shapes d/without-obj shape-id)]
(cond-> parent
(and (:shape-ref parent) (not ignore-touched))
(-> (update :touched cph/set-touched-group :shapes-group)
(-> (update :touched cfh/set-touched-group :shapes-group)
(dissoc :remote-synced)))))
(delete-from-objects [objects]
(if-let [target (get objects shape-id)]
(let [parent-id (or (:parent-id target)
(:frame-id target))
children-ids (cph/get-children-ids objects shape-id)]
children-ids (cfh/get-children-ids objects shape-id)]
(-> (reduce dissoc objects (cons shape-id children-ids))
(d/update-when parent-id delete-from-parent)))
objects))]
@ -118,7 +118,7 @@
(let [lookup (d/getf objects)
xform (comp (remove #(= uuid/zero %))
(keep lookup)
(filter cph/frame-shape?))]
(filter cfh/frame-shape?))]
(->> (keys objects)
(sequence xform))))
(remove #(or (and ^boolean skip-components?
@ -137,21 +137,21 @@
(defn get-nested-frames
[objects frame-id]
(into #{}
(comp (filter cph/frame-shape?)
(comp (filter cfh/frame-shape?)
(map :id))
(cph/get-children objects frame-id)))
(cfh/get-children objects frame-id)))
(defn get-root-frames-ids
"Retrieves all frame objects as vector. It is not implemented in
function of `cph/get-immediate-children` for performance
function of `cfh/get-immediate-children` for performance
reasons. This function is executed in the render hot path."
[objects]
(let [add-frame
(fn [result shape]
(cond-> result
(cph/frame-shape? shape)
(cfh/frame-shape? shape)
(conj (:id shape))))]
(cph/reduce-objects objects (complement cph/frame-shape?) add-frame [])))
(cfh/reduce-objects objects (complement cfh/frame-shape?) add-frame [])))
(defn get-root-objects
"Get all the objects under the root object"
@ -159,7 +159,7 @@
(let [add-shape
(fn [result shape]
(conj result shape))]
(cph/reduce-objects objects (complement cph/frame-shape?) add-shape [])))
(cfh/reduce-objects objects (complement cfh/frame-shape?) add-shape [])))
(defn get-root-shapes
"Get all shapes that are not frames"
@ -167,9 +167,9 @@
(let [add-shape
(fn [result shape]
(cond-> result
(not (cph/frame-shape? shape))
(not (cfh/frame-shape? shape))
(conj shape)))]
(cph/reduce-objects objects (complement cph/frame-shape?) add-shape [])))
(cfh/reduce-objects objects (complement cfh/frame-shape?) add-shape [])))
(defn get-root-shapes-ids
[objects]
@ -179,8 +179,8 @@
(defn get-base
[objects id-a id-b]
(let [[parents-a parents-a-index] (cph/get-parent-ids-with-index objects id-a)
[parents-b parents-b-index] (cph/get-parent-ids-with-index objects id-b)
(let [[parents-a parents-a-index] (cfh/get-parent-ids-with-index objects id-a)
[parents-b parents-b-index] (cfh/get-parent-ids-with-index objects id-b)
parents-a (cons id-a parents-a)
parents-b (into #{id-b} parents-b)
@ -201,12 +201,12 @@
;; The base the base shape, so the other item is below (if not bottom-frames)
(= base-id base-shape-id)
(and ^boolean bottom-frames?
^boolean (cph/frame-shape? objects base-id))
^boolean (cfh/frame-shape? objects base-id))
;; The base is the testing over, so it's over (if not bottom-frames)
(= base-id over-shape-id)
(or (not ^boolean bottom-frames?)
(not ^boolean (cph/frame-shape? objects base-id)))
(not ^boolean (cfh/frame-shape? objects base-id)))
;; Check which index is lower
:else
@ -378,7 +378,7 @@
;; or the parent's frame-id otherwise. Only for the first cloned shapes. In recursive calls
;; this is not needed.
frame-id (cond
(and calc-frame? (cph/frame-shape? objects parent-id))
(and calc-frame? (cfh/frame-shape? objects parent-id))
parent-id
calc-frame?

View file

@ -8,7 +8,6 @@
(:require
[app.common.data :as d]
[app.common.files.migrations :as cpm]
[app.common.pages :as cp]
[app.common.uuid :as uuid]
[clojure.pprint :refer [pprint]]
[clojure.test :as t]))

View file

@ -7,7 +7,7 @@
(ns common-tests.helpers.components
(:require
[clojure.test :as t]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.file :as ctf]))
@ -58,7 +58,7 @@
verify that they are a well constructed instance tree."
[page root-inst-id]
(let [root-inst (ctn/get-shape page root-inst-id)
shapes-inst (cph/get-children-with-self (:objects page)
shapes-inst (cfh/get-children-with-self (:objects page)
root-inst-id)]
(check-instance-root (first shapes-inst))
(run! check-instance-inner (rest shapes-inst))
@ -70,7 +70,7 @@
verify that they are not a component instance."
[page root-inst-id]
(let [root-inst (ctn/get-shape page root-inst-id)
shapes-inst (cph/get-children-with-self (:objects page)
shapes-inst (cfh/get-children-with-self (:objects page)
root-inst-id)]
(run! check-noninstance shapes-inst)
@ -84,8 +84,8 @@
component (ctf/find-component libraries (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
unique-refs (into #{} (map :shape-ref) shapes-inst)
@ -120,8 +120,8 @@
component (ctf/find-component libraries (:component-id root-inst))
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id)
shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst))
unique-refs (into #{} (map :shape-ref) shapes-inst)
@ -147,7 +147,7 @@
[page component-id libraries]
(let [component (ctf/find-component libraries component-id)
root-main (ctk/get-component-root component)
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
shapes-main (cfh/get-children-with-self (:objects component) (:id root-main))]
;; Validate that the component tree is well constructed
(run! check-noninstance shapes-main)

View file

@ -8,12 +8,12 @@
(:require
[clojure.test :as t]
[clojure.pprint :refer [pprint]]
[app.common.pages.helpers :as cph]))
[app.common.files.helpers :as cfh]))
(t/deftest parse-path-name
(t/is (= ["foo" "bar"] (cph/parse-path-name "foo/bar")))
(t/is (= ["" "foo"] (cph/parse-path-name "foo")))
(t/is (= ["" "foo"] (cph/parse-path-name "/foo")))
(t/is (= ["" ""] (cph/parse-path-name "")))
(t/is (= ["" ""] (cph/parse-path-name nil))))
(t/is (= ["foo" "bar"] (cfh/parse-path-name "foo/bar")))
(t/is (= ["" "foo"] (cfh/parse-path-name "foo")))
(t/is (= ["" "foo"] (cfh/parse-path-name "/foo")))
(t/is (= ["" ""] (cfh/parse-path-name "")))
(t/is (= ["" ""] (cfh/parse-path-name nil))))

View file

@ -7,7 +7,7 @@
(ns common-tests.pages-test
(:require
[app.common.features :as ffeat]
[app.common.pages :as cp]
[app.common.files.changes :as ch]
[app.common.types.file :as ctf]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]
@ -28,7 +28,7 @@
:page-id page-id
:option :test
:value "test"}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(t/is (= "test" (get-in res [:pages-index page-id :options :test])))))
(t/testing "Sets option nested"
@ -40,7 +40,7 @@
:page-id page-id
:option [:values :test :b]
:value "b"}]
res (cp/process-changes data chgs)]
res (ch/process-changes data chgs)]
(t/is (= {:a "a" :b "b"}
(get-in res [:pages-index page-id :options :values :test])))))
@ -49,7 +49,7 @@
:page-id page-id
:option :test
:value nil}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(t/is (empty? (keys (get-in res [:pages-index page-id :options]))))))
(t/testing "Remove option nested 1"
@ -65,7 +65,7 @@
:page-id page-id
:option [:values :test]
:value nil}]
res (cp/process-changes data chgs)]
res (ch/process-changes data chgs)]
(t/is (empty? (keys (get-in res [:pages-index page-id :options]))))))
(t/testing "Remove option nested 2"
@ -81,7 +81,7 @@
:page-id page-id
:option [:values :test2]
:value nil}]
res (cp/process-changes data chgs)]
res (ch/process-changes data chgs)]
(t/is (= [:test1] (keys (get-in res [:pages-index page-id :options :values]))))))
))
@ -105,7 +105,7 @@
:id id-a
:type :rect
:name "rect"})}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(let [objects (get-in res [:pages-index page-id :objects])]
(t/is (= 2 (count objects)))
@ -126,7 +126,7 @@
:frame-id uuid/zero
:type :rect
:name (str id)})})
res (cp/process-changes data [(chg id-a 0)
res (ch/process-changes data [(chg id-a 0)
(chg id-b 0)
(chg id-c 1)])]
@ -152,7 +152,7 @@
:operations [{:type :set
:attr :name
:val "foobar"}]}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(let [objects (get-in res [:pages-index page-id :objects])]
(t/is (= "foobar" (get-in objects [uuid/zero :name]))))))
@ -163,7 +163,7 @@
:operations [{:type :set
:attr :name
:val "foobar"}]}
res (cp/process-changes data [chg])]
res (ch/process-changes data [chg])]
(t/is (= res data))))
))
@ -185,7 +185,7 @@
;; (let [chg {:type :del-obj
;; :page-id page-id
;; :id id}
;; res (cp/process-changes data [chg])]
;; res (ch/process-changes data [chg])]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= 1 (count objects)))
@ -195,8 +195,8 @@
;; (let [chg {:type :del-obj
;; :page-id page-id
;; :id id}
;; res1 (cp/process-changes data [chg])
;; res2 (cp/process-changes res1 [chg])]
;; res1 (ch/process-changes data [chg])
;; res2 (ch/process-changes res1 [chg])]
;; (t/is (= res1 res2))
;; (let [objects (get-in res1 [:pages-index page-id :objects])]
@ -304,7 +304,7 @@
;; :page-id page-id
;; :parent-id new-group-id
;; :shapes [rect-b-id rect-c-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (clojure.pprint/pprint data)
;; ;; (println "===============")
@ -324,7 +324,7 @@
;; :parent-id group-b-id
;; :index 0
;; :shapes [rect-a-id rect-c-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id rect-e-id]
@ -340,7 +340,7 @@
;; :parent-id group-b-id
;; :index 0
;; :shapes [rect-a-id rect-e-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id]
@ -356,7 +356,7 @@
;; :parent-id group-b-id
;; :index 0
;; :shapes [rect-a-id rect-e-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id]
@ -371,7 +371,7 @@
;; :page-id page-id
;; :parent-id group-a-id
;; :shapes [rect-d-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; (t/is (= [group-a-id group-b-id rect-e-id]
@ -383,7 +383,7 @@
;; :page-id page-id
;; :parent-id frame-b-id
;; :shapes [group-a-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (pprint (get-in data [:pages-index page-id :objects]))
;; ;; (println "==========")
@ -403,7 +403,7 @@
;; :parent-id uuid/zero
;; :shapes [group-a-id]
;; :index 0}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (let [objects (get-in res [:pages-index page-id :objects])]
;; ;; (pprint (get-in data [:objects uuid/zero]))
@ -418,7 +418,7 @@
;; :page-id page-id
;; :parent-id group-a-id
;; :shapes [group-a-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (t/is (= data res))))
;; ))
@ -462,7 +462,7 @@
;; :name "Shape 3"}}
;; ]
;; data (make-file-data file-id page-id)
;; data (cp/process-changes data changes)]
;; data (ch/process-changes data changes)]
;; (t/testing "preserve order on multiple shape mov 1"
;; (let [changes [{:type :mov-objects
@ -470,7 +470,7 @@
;; :shapes [shape-2-id shape-3-id]
;; :parent-id uuid/zero
;; :index 0}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (println "==> BEFORE")
;; ;; (pprint (get-in data [:objects]))
@ -488,7 +488,7 @@
;; :shapes [shape-3-id shape-2-id]
;; :parent-id uuid/zero
;; :index 0}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (println "==> BEFORE")
;; ;; (pprint (get-in data [:objects]))
@ -509,7 +509,7 @@
;; :page-id page-id
;; :shapes [shape-2-id]
;; :parent-id uuid/zero}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; (t/is (= (get-in res [:pages-index page-id :objects shape-1-id :frame-id])
;; (get-in data [:pages-index page-id :objects shape-1-id :frame-id])))
@ -569,7 +569,7 @@
;; :shapes [shape-1-id shape-2-id]}]
;; data (make-file-data file-id page-id)
;; data (cp/process-changes data changes)]
;; data (ch/process-changes data changes)]
;; (t/testing "case 1"
;; (let [changes [{:type :mov-objects
@ -577,7 +577,7 @@
;; :parent-id uuid/zero
;; :index 2
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -599,7 +599,7 @@
;; :parent-id group-1-id
;; :index 2
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -627,7 +627,7 @@
;; :parent-id group-1-id
;; :index 1
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -655,7 +655,7 @@
;; :parent-id group-1-id
;; :index 0
;; :shapes [shape-3-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; Before
@ -683,7 +683,7 @@
;; :parent-id uuid/zero
;; :index 0
;; :shapes [shape-2-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (pprint (get-in data [:pages-index page-id :objects uuid/zero]))
;; ;; (pprint (get-in res [:pages-index page-id :objects uuid/zero]))
@ -715,7 +715,7 @@
;; :parent-id uuid/zero
;; :index 0
;; :shapes [shape-2-id shape-1-id]}]
;; res (cp/process-changes data changes)]
;; res (ch/process-changes data changes)]
;; ;; (pprint (get-in data [:pages-index page-id :objects uuid/zero]))
;; ;; (pprint (get-in res [:pages-index page-id :objects uuid/zero]))

View file

@ -9,7 +9,7 @@
["js-beautify" :as beautify]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.shape-tree :as ctst]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.fonts :as fonts]
@ -23,7 +23,7 @@
(def style-type "css")
(def markup-type "html")
(def page-template
"<!DOCTYPE html>
@ -57,7 +57,7 @@
(defn shapes->fonts
[shapes]
(->> shapes
(filter cph/text-shape?)
(filter cfh/text-shape?)
(map (comp fonts/get-content-fonts :content))
(reduce set/union #{})))
@ -70,7 +70,7 @@
shape (get objects shape-id)
all-children
(->> (cph/selected-with-children objects [shape-id])
(->> (cfh/selected-with-children objects [shape-id])
(ctst/sort-z-index objects)
(keep (d/getf objects)))

View file

@ -8,8 +8,8 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.transit :as t]
[app.common.types.shape-tree :as ctt]
@ -688,7 +688,7 @@
(conj id))]
(-> state
(assoc-in [:viewer-local :selected]
(cph/expand-region-selection objects selection)))))))
(cfh/expand-region-selection objects selection)))))))
(defn select-all
[]

View file

@ -9,6 +9,7 @@
[app.common.attrs :as attrs]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.align :as gal]
[app.common.geom.point :as gpt]
@ -16,8 +17,6 @@
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.grid-layout :as gslg]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
[app.common.transit :as t]
[app.common.types.component :as ctk]
@ -495,7 +494,7 @@
objects (->> (:objects page)
(d/mapm (fn [_ val] (dissoc val :use-for-thumbnail))))
main-instances-ids (set (keep #(when (ctk/main-instance? (val %)) (key %)) objects))
ids-to-remove (set (apply concat (map #(cph/get-children-ids objects %) main-instances-ids)))
ids-to-remove (set (apply concat (map #(cfh/get-children-ids objects %) main-instances-ids)))
add-component-copy
(fn [objs id shape]
@ -688,7 +687,7 @@
(watch [_ state _]
(when-let [shape-id (dm/get-in state [:workspace-local :shape-for-rename])]
(let [shape (wsh/lookup-shape state shape-id)
name (cph/clean-path name)]
name (cfh/clean-path name)]
(rx/concat
;; Remove rename state from workspace local state
(rx/of #(update % :workspace-local dissoc :shape-for-rename))
@ -781,7 +780,7 @@
(defn relocate-shapes-changes [it objects parents parent-id page-id to-index ids
groups-to-delete groups-to-unmask shapes-to-detach
shapes-to-reroot shapes-to-deroot shapes-to-unconstraint]
(let [ordered-indexes (cph/order-by-indexed-shapes objects ids)
(let [ordered-indexes (cfh/order-by-indexed-shapes objects ids)
shapes (map (d/getf objects) ordered-indexes)
parent (get objects parent-id)]
@ -793,8 +792,8 @@
(pcb/update-shapes ordered-indexes ctl/remove-layout-item-data))
;; Remove the hide in viewer flag
(cond-> (and (not= uuid/zero parent-id) (cph/frame-shape? parent))
(pcb/update-shapes ordered-indexes #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true))))
(cond-> (and (not= uuid/zero parent-id) (cfh/frame-shape? parent))
(pcb/update-shapes ordered-indexes #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true))))
;; Move the shapes
(pcb/change-parent parent-id
@ -880,12 +879,12 @@
objects (wsh/lookup-page-objects state page-id)
;; Ignore any shape whose parent is also intended to be moved
ids (cph/clean-loops objects ids)
ids (cfh/clean-loops objects ids)
;; If we try to move a parent into a child we remove it
ids (filter #(not (cph/is-parent? objects parent-id %)) ids)
ids (filter #(not (cfh/is-parent? objects parent-id %)) ids)
all-parents (into #{parent-id} (map #(cph/get-parent-id objects %)) ids)
all-parents (into #{parent-id} (map #(cfh/get-parent-id objects %)) ids)
parents (if ignore-parents? #{parent-id} all-parents)
groups-to-delete
@ -904,7 +903,7 @@
(empty? (remove removed-id? (:shapes group))))
;; Adds group to the remove and check its parent
(let [to-check (concat to-check [(cph/get-parent-id objects current-id)])]
(let [to-check (concat to-check [(cfh/get-parent-id objects current-id)])]
(recur (first to-check)
(rest to-check)
(conj removed-id? current-id)
@ -955,7 +954,7 @@
(not component-shape-parent))
ids-to-detach (when detach?
(cons id (cph/get-children-ids objects id)))]
(cons id (cfh/get-children-ids objects id)))]
[(cond-> shapes-to-detach detach? (into ids-to-detach))
(cond-> shapes-to-deroot deroot? (conj id))
@ -1380,8 +1379,8 @@
page-id (get state :current-page-id)
pparams {:file-id file-id :project-id project-id}
qparams {:page-id page-id :layout :assets}
component-path (cph/split-path (get-in state [:workspace-data :components component-id :path]))
paths (map (fn [i] (cph/join-path (take (inc i) component-path))) (range (count component-path)))]
component-path (cfh/split-path (get-in state [:workspace-data :components component-id :path]))
paths (map (fn [i] (cfh/join-path (take (inc i) component-path))) (range (count component-path)))]
(rx/concat
(rx/from (map #(set-assets-group-open file-id :components % true) paths))
(rx/of (rt/nav :workspace pparams qparams)
@ -1462,7 +1461,7 @@
(watch [_ state _]
(let [selected (wsh/lookup-selected state)
objects (wsh/lookup-page-objects state)
all-selected (into [] (mapcat #(cph/get-children-with-self objects %)) selected)
all-selected (into [] (mapcat #(cfh/get-children-with-self objects %)) selected)
head (get objects (first selected))
not-group-like? (and (= (count selected) 1)
@ -1510,7 +1509,7 @@
;; Narrow the objects map so it contains only relevant data for
;; selected and its parents
objects (cph/selected-subtree objects selected)
objects (cfh/selected-subtree objects selected)
selected (->> (ctst/sort-z-index objects selected)
(reverse)
(into (d/ordered-set)))]
@ -1538,7 +1537,7 @@
(reduce into [])
(filter :fill-image)
(map :fill-image))
stroke-images-data (->> (:strokes obj)
(filter :stroke-image)
(map :stroke-image))
@ -1547,7 +1546,7 @@
stroke-images-data
(when (= type :image)
[(:metadata obj)]))]
(if (> (count images-data) 0)
(->> (rx/from images-data)
(rx/mapcat (fn [image-data]
@ -1587,9 +1586,9 @@
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects))
(cfh/clean-loops objects))
parent-frame-id (cph/common-parent-frame objects selected)
parent-frame-id (cfh/common-parent-frame objects selected)
pdata (reduce (partial collect-object-ids objects) {} selected)
initial {:type :copied-shapes
:file-id (:current-file-id state)
@ -1767,7 +1766,7 @@
(let [fills (mapv #(translate-staled-media % :fill-image media-idx) (:fills p-data))]
(assoc p-data :fills fills)))))
content (txt/transform-nodes #(translate-staled-media % :fill-image media-idx) (:content obj))]
(if (= (:type item) :add-obj)
(-> item
(update-in [:obj :metadata]
@ -1793,15 +1792,15 @@
orig-pos (gpt/point (:x1 wrapper) (:y1 wrapper))
frame-id (first page-selected)
frame-object (get page-objects frame-id)
base (cph/get-base-shape page-objects page-selected)
index (cph/get-position-on-parent page-objects (:id base))
base (cfh/get-base-shape page-objects page-selected)
index (cfh/get-position-on-parent page-objects (:id base))
tree-root (get-tree-root-shapes paste-objects)
only-one-root-shape? (and
(< 1 (count paste-objects))
(= 1 (count tree-root)))
all-objects (merge page-objects paste-objects)
comps-nesting-loop? (not (->> (keys paste-objects)
(map #(cph/components-nesting-loop? all-objects % (:id base)))
(map #(cfh/components-nesting-loop? all-objects % (:id base)))
(every? nil?)))]
(cond
@ -1904,8 +1903,8 @@
process-shape
(fn [_ shape]
(let [assign-shapes? (and (or (cph/group-shape? shape)
(cph/bool-shape? shape))
(let [assign-shapes? (and (or (cfh/group-shape? shape)
(cfh/bool-shape? shape))
(nil? (:shapes shape)))]
(-> shape
(assoc :frame-id frame-id :parent-id parent-id)
@ -2234,7 +2233,7 @@
copies-no-ref (filter #(not (:shape-ref %)) copies)
find-childs-no-ref (fn [acc-map item]
(let [id (:id item)
childs (->> (cph/get-children objects id)
childs (->> (cfh/get-children objects id)
(filter #(not (:shape-ref %))))]
(if (seq childs)
(assoc acc-map id childs)

View file

@ -7,9 +7,9 @@
(ns app.main.data.workspace.bool
(:require
[app.common.data :as d]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cph]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.svg.path.shapes-to-path :as stp]
[app.common.types.container :as ctn]
[app.common.types.shape :as cts]

View file

@ -9,11 +9,10 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.files.changes :as cpc]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cph]
[app.common.logging :as log]
[app.common.pages :as cp]
[app.common.pages.changes :as cpc]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
@ -218,7 +217,7 @@
(update-in state path (fn [file]
(-> file
(cp/process-changes redo-changes false)
(cpc/process-changes redo-changes false)
(ctst/update-object-indices page-id))))
(catch :default err

View file

@ -6,7 +6,7 @@
(ns app.main.data.workspace.collapse
(:require
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.uuid :as uuid]
[potok.core :as ptk]))
@ -20,7 +20,7 @@
(let [expand-fn (fn [expanded]
(merge expanded
(->> ids
(map #(cph/get-parent-ids objects %))
(map #(cfh/get-parent-ids objects %))
flatten
(remove #(= % uuid/zero))
(map (fn [id] {id true}))

View file

@ -9,7 +9,7 @@
[app.common.colors :as cc]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.schema :as sm]
[app.common.types.component :as ctk]
[app.main.broadcast :as mbc]
@ -231,7 +231,7 @@
(contains? attrs :image)
(assoc :stroke-image (:image attrs)))
attrs (->
attrs (->
(merge attrs color-attrs)
(dissoc :image)
(dissoc :gradient))]
@ -415,7 +415,7 @@
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects))
(cfh/clean-loops objects))
ids
(loop [pending (seq selected)
@ -424,8 +424,8 @@
result
(let [cur (first pending)
;; We treat frames that aren't components and with no fill the same as groups
group? (or (cph/group-shape? objects cur)
(and (cph/frame-shape? objects cur)
group? (or (cfh/group-shape? objects cur)
(and (cfh/frame-shape? objects cur)
(empty? (dm/get-in objects [cur :fills]))
(not (ctk/instance-head? (get objects cur)))))
@ -666,7 +666,7 @@
(let [selected (wsh/lookup-selected state)
shapes (wsh/lookup-shapes state selected)
shape (first shapes)
fills (if (cph/text-shape? shape)
fills (if (cfh/text-shape? shape)
(:fills (dwt/current-text-values
{:editor-state (dm/get-in state [:workspace-editor-state (:id shape)])
:shape shape

View file

@ -7,9 +7,9 @@
(ns app.main.data.workspace.comments
(:require
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes-builder :as pcb]
[app.common.schema :as sm]
[app.common.types.shape-tree :as ctst]
[app.main.data.comments :as dcm]

View file

@ -7,9 +7,9 @@
(ns app.main.data.workspace.drawing.common
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape :as cts]
[app.main.data.workspace.shapes :as dwsh]
@ -39,7 +39,7 @@
(rx/concat
(when (:initialized? shape)
(let [click-draw? (:click-draw? shape)
text? (cph/text-shape? shape)
text? (cfh/text-shape? shape)
vbox (dm/get-in state [:workspace-local :vbox])
min-side (mth/min 100
@ -70,19 +70,19 @@
;; Add & select the created shape to the workspace
(rx/concat
(if (cph/frame-shape? shape)
(if (cfh/frame-shape? shape)
(rx/of (dwu/start-undo-transaction (:id shape)))
(rx/empty))
(rx/of (dwsh/add-shape shape {:no-select? (= tool :curve)}))
(if (cph/frame-shape? shape)
(if (cfh/frame-shape? shape)
(rx/concat
(->> (uw/ask! {:cmd :selection/query
:page-id page-id
:rect (:selrect shape)
:include-frames? true
:full-frame? true})
(rx/map #(cph/clean-loops objects %))
(rx/map #(cfh/clean-loops objects %))
(rx/map #(dwsh/move-shapes-into-frame (:id shape) %)))
(rx/of (dwu/commit-undo-transaction (:id shape))))
(rx/empty)))))

View file

@ -7,7 +7,7 @@
(ns app.main.data.workspace.fix-deleted-fonts
(:require
[app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.text :as txt]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh]
@ -39,7 +39,7 @@
(defn should-fix-deleted-font-shape?
[shape]
(let [text-nodes (txt/node-seq txt/is-text-node? (:content shape))]
(and (cph/text-shape? shape) (some has-invalid-font-family text-nodes))))
(and (cfh/text-shape? shape) (some has-invalid-font-family text-nodes))))
(defn should-fix-deleted-font-component?
[component]

View file

@ -9,7 +9,7 @@
[app.common.colors :as clr]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.changes-builder :as pcb]
[app.common.files.changes-builder :as pcb]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.state-helpers :as wsh]
[beicon.core :as rx]

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.pages-list :as ctpl]
@ -29,7 +29,7 @@
(defn shapes-for-grouping
[objects selected]
(->> selected
(cph/order-by-indexed-shapes objects)
(cfh/order-by-indexed-shapes objects)
reverse
(map #(get objects %))))
@ -42,8 +42,8 @@
group, one (or many) groups can become empty because they have had a
single shape which is moved to the created group."
[objects parent-id shapes]
(let [ids (cph/clean-loops objects (into #{} (map :id) shapes))
parents (into #{} (map #(cph/get-parent-id objects %)) ids)]
(let [ids (cfh/clean-loops objects (into #{} (map :id) shapes))
parents (into #{} (map #(cfh/get-parent-id objects %)) ids)]
(loop [current-id (first parents)
to-check (rest parents)
removed-id? ids
@ -59,7 +59,7 @@
(empty? (remove removed-id? (:shapes group))))
;; Adds group to the remove and check its parent
(let [to-check (concat to-check [(cph/get-parent-id objects current-id)]) ]
(let [to-check (concat to-check [(cfh/get-parent-id objects current-id)]) ]
(recur (first to-check)
(rest to-check)
(conj removed-id? current-id)
@ -85,7 +85,7 @@
group-idx (->> shapes
last
:id
(cph/get-position-on-parent objects)
(cfh/get-position-on-parent objects)
inc)
group (cts/setup-shape {:type :group
@ -137,9 +137,9 @@
(defn remove-group-changes
[it page-id group objects]
(let [children (->> (:shapes group)
(cph/order-by-indexed-shapes objects)
(cfh/order-by-indexed-shapes objects)
(mapv #(get objects %)))
parent-id (cph/get-parent-id objects (:id group))
parent-id (cfh/get-parent-id objects (:id group))
parent (get objects parent-id)
index-in-parent
@ -152,7 +152,7 @@
;; Shapes that are in a component (including root) must be detached,
;; because cannot be easyly synchronized back to the main component.
shapes-to-detach (filter ctk/in-component-copy?
(cph/get-children-with-self objects (:id group)))]
(cfh/get-children-with-self objects (:id group)))]
(-> (pcb/empty-changes it page-id)
(pcb/with-objects objects)
@ -163,11 +163,11 @@
(defn remove-frame-changes
[it page-id frame objects]
(let [children (->> (:shapes frame)
(cph/order-by-indexed-shapes objects)
(cfh/order-by-indexed-shapes objects)
(mapv #(get objects %)))
parent-id (cph/get-parent-id objects (:id frame))
parent-id (cfh/get-parent-id objects (:id frame))
idx-in-parent (->> (:id frame)
(cph/get-position-on-parent objects)
(cfh/get-position-on-parent objects)
inc)]
(-> (pcb/empty-changes it page-id)
@ -228,7 +228,7 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects)
(cfh/clean-loops objects)
(remove #(ctn/has-any-copy-parent? objects (get objects %))))
shapes (shapes-for-grouping objects selected)
parents (into #{} (map :parent-id) shapes)]
@ -256,10 +256,10 @@
(ctk/main-instance? shape)
(remove-component-changes it page-id shape objects file-data file)
(or (cph/group-shape? shape) (cph/bool-shape? shape))
(or (cfh/group-shape? shape) (cfh/bool-shape? shape))
(remove-group-changes it page-id shape objects)
(cph/frame-shape? shape)
(cfh/frame-shape? shape)
(remove-frame-changes it page-id shape objects))]
(cond-> changes
@ -273,7 +273,7 @@
selected)
parents (into #{}
(comp (map #(cph/get-parent objects %))
(comp (map #(cfh/get-parent objects %))
(keep :id))
selected)
@ -301,7 +301,7 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects)
(cfh/clean-loops objects)
(remove #(ctn/has-any-copy-parent? objects (get objects %))))
shapes (shapes-for-grouping objects selected)
first-shape (first shapes)]

View file

@ -7,9 +7,9 @@
(ns app.main.data.workspace.guides
(:require
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes-builder :as pcb]
[app.common.types.page :as ctp]
[app.main.data.workspace.changes :as dwc]
[app.main.data.workspace.state-helpers :as wsh]

View file

@ -8,10 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.types.page :as ctp]
[app.common.types.shape-tree :as ctst]
[app.common.types.shape.interactions :as ctsi]
@ -100,7 +99,7 @@
"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)]
(let [children (cfh/get-children-with-self objects frame-id)]
(or (some ctsi/flow-origin? (map :interactions children))
(some #(ctsi/flow-to? % frame-id) (map :interactions (vals objects))))))
@ -112,7 +111,7 @@
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
frame (cph/get-root-frame objects (:id shape))
frame (cfh/get-root-frame objects (:id shape))
flows (get-in state [:workspace-data
:pages-index
page-id
@ -203,7 +202,7 @@
from-id (-> state wsh/lookup-selected first)
from-shape (wsh/lookup-shape state from-id)
from-frame-id (if (cph/frame-shape? from-shape)
from-frame-id (if (cfh/frame-shape? from-shape)
from-id (:frame-id from-shape))
target-frame (ctst/get-frame-by-position objects position)]
@ -307,7 +306,7 @@
overlay-pos (-> shape
(get-in [:interactions index])
:overlay-position)
orig-frame (cph/get-frame objects shape)
orig-frame (cfh/get-frame objects shape)
frame-pos (gpt/point (:x orig-frame) (:y orig-frame))
offset (-> initial-pos
(gpt/subtract overlay-pos)

View file

@ -8,14 +8,13 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes :as ch]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.files.libraries-helpers :as cflh]
[app.common.files.shapes-helpers :as cfsh]
[app.common.geom.point :as gpt]
[app.common.logging :as log]
[app.common.pages :as cp]
[app.common.pages.changes :as ch]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.types.color :as ctc]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
@ -85,7 +84,7 @@
(defn extract-path-if-missing
[item]
(let [[path name] (cph/parse-path-name (:name item))]
(let [[path name] (cfh/parse-path-name (:name item))]
(if (and
(= (:name item) name)
(contains? item :path))
@ -131,7 +130,7 @@
(defn- do-update-color
[it state color file-id]
(let [data (get state :workspace-data)
[path name] (cph/parse-path-name (:name color))
[path name] (cfh/parse-path-name (:name color))
color (assoc color :path path :name name)
changes (-> (pcb/empty-changes it)
(pcb/with-library-data data)
@ -202,7 +201,7 @@
(let [new-name (str/trim new-name)]
(if (str/empty? new-name)
(rx/empty)
(let [[path name] (cph/parse-path-name new-name)
(let [[path name] (cfh/parse-path-name new-name)
data (get state :workspace-data)
object (get-in data [:media id])
new-object (assoc object :path path :name name)
@ -274,7 +273,7 @@
(watch [it state _]
(when (and (some? new-name) (not= "" new-name))
(let [data (get state :workspace-data)
[path name] (cph/parse-path-name new-name)
[path name] (cfh/parse-path-name new-name)
object (get-in data [:typographies id])
new-object (assoc object :path path :name name)]
(do-update-tipography it state new-object file-id))))))
@ -326,7 +325,7 @@
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects)
(cfh/clean-loops objects)
(remove #(ctn/has-any-copy-parent? objects (get objects %)))) ;; We don't want to change the structure of component copies
components-v2 (features/active-feature? state "components/v2")]
(rx/of (add-component2 selected components-v2))))))
@ -340,7 +339,7 @@
(let [components-v2 (features/active-feature? state "components/v2")
objects (wsh/lookup-page-objects state)
selected (->> (wsh/lookup-selected state)
(cph/clean-loops objects)
(cfh/clean-loops objects)
(remove #(ctn/has-any-copy-parent? objects (get objects %)))) ;; We don't want to change the structure of component copies
added-components (map
#(add-component2 [%] components-v2)
@ -363,7 +362,7 @@
(if (str/empty? new-name)
(rx/empty)
(let [data (get state :workspace-data)
[path name] (cph/parse-path-name new-name)
[path name] (cfh/parse-path-name new-name)
components-v2 (features/active-feature? state "components/v2")
update-fn
@ -390,7 +389,7 @@
ptk/WatchEvent
(watch [_ state _]
(when-let [component (dm/get-in state [:workspace-data :components component-id])]
(let [name (cph/clean-path name)
(let [name (cfh/clean-path name)
shape-id (:main-instance-id component)
page-id (:main-instance-page component)]
(rx/concat
@ -544,7 +543,7 @@
(watch [it state _]
(let [file (wsh/get-local-file state)
page-id (get state :current-page-id)
container (cph/get-container file :page page-id)
container (cfh/get-container file :page page-id)
changes (-> (pcb/empty-changes it)
(pcb/with-container container)
@ -573,10 +572,10 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
file (wsh/get-local-file state)
container (cph/get-container file :page page-id)
container (cfh/get-container file :page page-id)
selected (->> state
(wsh/lookup-selected)
(cph/clean-loops objects))
(cfh/clean-loops objects))
changes (reduce
(fn [changes id]
@ -614,7 +613,7 @@
(update-in [:workspace-libraries library-id]
assoc :modified-at modified-at :revn revn)
(d/update-in-when [:workspace-libraries library-id :data]
cp/process-changes changes)))
ch/process-changes changes)))
ptk/WatchEvent
(watch [_ _ _]
@ -637,7 +636,7 @@
libraries (wsh/get-libraries state)
page-id (:current-page-id state)
container (cph/get-container file :page page-id)
container (cfh/get-container file :page page-id)
components-v2
(features/active-feature? state "components/v2")
@ -685,7 +684,7 @@
(log/info :msg "UPDATE-COMPONENT of shape" :id (str id) :undo-group undo-group)
(let [page-id (get state :current-page-id)
local-file (wsh/get-local-file state)
container (cph/get-container local-file :page page-id)
container (cfh/get-container local-file :page page-id)
shape (ctn/get-shape container id)
components-v2 (features/active-feature? state "components/v2")]

View file

@ -8,12 +8,12 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.grid-layout :as gslg]
[app.common.logging :as log]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.text :as txt]
[app.common.types.color :as ctc]
@ -116,14 +116,14 @@
; main nested in the original component.
(let [origin-shape-id (get @inverted-ids-map (:id shape))
objects (:objects main-instance-page)
parent-ids (cph/get-parent-ids-seq-with-self objects origin-shape-id)]
parent-ids (cfh/get-parent-ids-seq-with-self objects origin-shape-id)]
(cond-> shape
(@nested-main-heads origin-shape-id)
(dissoc :main-instance)
(some @nested-main-heads parent-ids)
(assoc :shape-ref origin-shape-id))))
xf-shape (comp (map remap-frame)
(map convert-nested-main))
@ -219,7 +219,7 @@
([changes library-data component-id it page delta old-id parent-id]
(let [component (ctkl/get-deleted-component library-data component-id)
shapes (cph/get-children-with-self (:objects component) (:main-instance-id component))
shapes (cfh/get-children-with-self (:objects component) (:main-instance-id component))
shapes (map #(gsh/move % delta) shapes)
first-shape (cond-> (first shapes)
(not (nil? parent-id))
@ -269,7 +269,7 @@
asset-id
library-id
state
(cph/make-container page :page)
(cfh/make-container page :page)
components-v2)))
changes))))
@ -305,7 +305,7 @@
asset-id
library-id
state
(cph/make-container local-component :component)
(cfh/make-container local-component :component)
components-v2)))
changes))))
@ -314,7 +314,7 @@
or a component) that use assets of the given type in the given library."
[it asset-type asset-id library-id state container components-v2]
(if (cph/page? container)
(if (cfh/page? container)
(log/debug :msg "Sync page in local file" :page-id (:id container))
(log/debug :msg "Sync component in local library" :component-id (:id container)))
@ -884,10 +884,10 @@
(log/info :msg (str "ADD [P] " (:name component-shape)))
(let [component-parent-shape (ctn/get-shape component-page (:parent-id component-shape))
parent-shape (d/seek #(ctk/is-main-of? component-parent-shape %)
(cph/get-children-with-self (:objects container)
(cfh/get-children-with-self (:objects container)
(:id root-instance)))
all-parents (into [(:id parent-shape)]
(cph/get-parent-ids (:objects container)
(cfh/get-parent-ids (:objects container)
(:id parent-shape)))
update-new-shape (fn [new-shape original-shape]
@ -945,7 +945,7 @@
:shapes all-parents}))
changes' (reduce del-obj-change changes' new-shapes)]
(if (and (cph/touched-group? parent-shape :shapes-group) omit-touched?)
(if (and (cfh/touched-group? parent-shape :shapes-group) omit-touched?)
changes
changes')))
@ -954,10 +954,10 @@
(log/info :msg (str "ADD [C] " (:name shape)))
(let [parent-shape (ctn/get-shape page (:parent-id shape))
component-parent-shape (d/seek #(ctk/is-main-of? % parent-shape)
(cph/get-children-with-self (:objects component-container)
(cfh/get-children-with-self (:objects component-container)
(:id root-main)))
all-parents (into [(:id component-parent-shape)]
(cph/get-parent-ids (:objects component-container)
(cfh/get-parent-ids (:objects component-container)
(:id component-parent-shape)))
update-new-shape (fn [new-shape _original-shape]
@ -1034,12 +1034,12 @@
(defn- remove-shape
[changes shape container omit-touched?]
(log/info :msg (str "REMOVE-SHAPE "
(if (cph/page? container) "[P] " "[C] ")
(if (cfh/page? container) "[P] " "[C] ")
(:name shape)))
(let [objects (get container :objects)
parents (cph/get-parent-ids objects (:id shape))
parents (cfh/get-parent-ids objects (:id shape))
parent (first parents)
children (cph/get-children-ids objects (:id shape))
children (cfh/get-children-ids objects (:id shape))
ids (into [(:id shape)] children)
add-redo-change (fn [changes id]
@ -1057,7 +1057,7 @@
container
(as-> {:type :add-obj
:id id
:index (cph/get-position-on-parent objects id)
:index (cfh/get-position-on-parent objects id)
:parent-id (:parent-id shape')
:ignore-touched true
:obj shape'} $
@ -1076,14 +1076,14 @@
changes'
children)]
(if (and (cph/touched-group? parent :shapes-group) omit-touched?)
(if (and (cfh/touched-group? parent :shapes-group) omit-touched?)
changes
changes')))
(defn- move-shape
[changes shape index-before index-after container omit-touched?]
(log/info :msg (str "MOVE "
(if (cph/page? container) "[P] " "[C] ")
(if (cfh/page? container) "[P] " "[C] ")
(:name shape)
" "
index-before
@ -1107,7 +1107,7 @@
:index index-before
:ignore-touched true})))]
(if (and (cph/touched-group? parent :shapes-group) omit-touched?)
(if (and (cfh/touched-group? parent :shapes-group) omit-touched?)
changes
changes')))
@ -1119,7 +1119,7 @@
changes
(do
(log/info :msg (str "CHANGE-TOUCHED "
(if (cph/page? container) "[P] " "[C] ")
(if (cfh/page? container) "[P] " "[C] ")
(:name dest-shape))
:options options)
(let [new-touched (cond
@ -1154,7 +1154,7 @@
changes
(do
(log/info :msg (str "CHANGE-REMOTE-SYNCED? "
(if (cph/page? container) "[P] " "[C] ")
(if (cfh/page? container) "[P] " "[C] ")
(:name shape))
:remote-synced remote-synced?)
(-> changes
@ -1184,7 +1184,7 @@
(log/info :msg (str "SYNC "
(:name origin-shape)
" -> "
(if (cph/page? container) "[P] " "[C] ")
(if (cfh/page? container) "[P] " "[C] ")
(:name dest-shape)))
(let [;; To synchronize geometry attributes we need to make a prior
@ -1205,7 +1205,7 @@
(if (nil? attr)
(if (empty? roperations)
changes
(let [all-parents (cph/get-parent-ids (:objects container)
(let [all-parents (cfh/get-parent-ids (:objects container)
(:id dest-shape))]
(-> changes
(update :redo-changes conj (make-change
@ -1259,7 +1259,7 @@
(defn- make-change
[container change]
(if (cph/page? container)
(if (cfh/page? container)
(assoc change :page-id (:id container))
(assoc change :component-id (:id container))))

View file

@ -9,9 +9,9 @@
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.files.builder :as fb]
[app.common.files.changes-builder :as pcb]
[app.common.logging :as log]
[app.common.math :as mth]
[app.common.pages.changes-builder :as pcb]
[app.common.schema :as sm]
[app.common.svg :refer [optimize]]
[app.common.svg.shapes-builder :as csvg.shapes-builder]
@ -259,7 +259,7 @@
(ptk/reify ::upload-fill-image
ptk/WatchEvent
(watch [_ state _]
(let [on-upload-success
(let [on-upload-success
(fn [image]
(on-success image)
(dmm/notify-finished-loading))

View file

@ -9,12 +9,12 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.modifiers :as gm]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm]
@ -95,7 +95,7 @@
(if (:component-root shape)
transformed-shape
(gsh/transform-shape root (dm/get-in modif-tree [(:id root) :modifiers])))]
(get-ignore-tree ignore-tree shape transformed-shape root transformed-root)))
([ignore-tree shape root transformed-root]
@ -112,7 +112,7 @@
(assoc
shape-id
(check-delta shape root transformed-shape transformed-root)))
set-child
(fn [ignore-tree child]
(get-ignore-tree ignore-tree child root transformed-root))]
@ -474,7 +474,7 @@
ids-with-children
(into ids
(mapcat (partial cph/get-children-ids objects))
(mapcat (partial cfh/get-children-ids objects))
ids)
ignore-tree
@ -492,7 +492,7 @@
ids
(fn [shape]
(let [modif (get-in object-modifiers [(:id shape) :modifiers])
text-shape? (cph/text-shape? shape)
text-shape? (cfh/text-shape? shape)
position-data (when text-shape?
(dm/get-in text-modifiers [(:id shape) :position-data]))]
(-> shape

View file

@ -8,7 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.changes :as cpc]
[app.common.files.changes :as cpc]
[app.common.schema :as sm]
[app.common.uuid :as uuid]
[app.main.data.common :refer [handle-notification]]

View file

@ -7,7 +7,7 @@
(ns app.main.data.workspace.path.changes
(:require
[app.common.data.macros :as dm]
[app.common.pages.changes-builder :as pcb]
[app.common.files.changes-builder :as pcb]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.path.common :refer [content?]]
[app.main.data.workspace.path.helpers :as helpers]

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as upg]
[app.common.pages.helpers :as cph]
[app.common.svg.path.command :as upc]
[app.common.svg.path.shapes-to-path :as upsp]
[app.common.svg.path.subpath :as ups]
@ -289,7 +289,7 @@
edit-path (dm/get-in state [:workspace-local :edit-path id])
content (st/get-path state :content)
state (cond-> state
(cph/path-shape? objects id)
(cfh/path-shape? objects id)
(st/set-content (ups/close-subpaths content)))]
(cond-> state
(or (not edit-path) (= :draw (:edit-mode edit-path)))

View file

@ -6,8 +6,8 @@
(ns app.main.data.workspace.path.shapes-to-path
(:require
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cph]
[app.common.svg.path.shapes-to-path :as upsp]
[app.common.types.container :as ctn]
[app.main.data.workspace.changes :as dch]

View file

@ -7,9 +7,8 @@
(ns app.main.data.workspace.persistence
(:require
[app.common.data.macros :as dm]
[app.common.files.changes :as cpc]
[app.common.logging :as log]
[app.common.pages :as cp]
[app.common.pages.changes :as cpc]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
@ -259,12 +258,12 @@
entries (seq changes)]
(if-let [[page-id changes] (first entries)]
(recur (-> fdata
(cp/process-changes changes)
(cpc/process-changes changes)
(ctst/update-object-indices page-id))
(rest entries))
fdata))))))
(-> state
(update-in [:workspace-libraries file-id :revn] max revn)
(update-in [:workspace-libraries file-id :data] cp/process-changes changes)))
(update-in [:workspace-libraries file-id :data] cpc/process-changes changes)))
state))))

View file

@ -8,14 +8,13 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.focus :as cpf]
[app.common.files.helpers :as cfh]
[app.common.files.libraries-helpers :as cflh]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.focus :as cpf]
[app.common.pages.helpers :as cph]
[app.common.record :as cr]
[app.common.types.component :as ctk]
[app.common.types.file :as ctf]
@ -202,7 +201,7 @@
ptk/UpdateEvent
(update [_ state]
(let [objects (or objects (wsh/lookup-page-objects state))
append-to-selection (cph/expand-region-selection objects (into #{} [(get-in state [:workspace-local :last-selected]) id]))
append-to-selection (cfh/expand-region-selection objects (into #{} [(get-in state [:workspace-local :last-selected]) id]))
selection (-> state
wsh/lookup-selected
(conj id))]
@ -259,7 +258,7 @@
(-> parents first lookup)
(lookup uuid/zero))
toselect (->> (cph/get-immediate-children objects (:id parent))
toselect (->> (cfh/get-immediate-children objects (:id parent))
(into (d/ordered-set) (comp (remove :hidden) (remove :blocked) (map :id))))]
(rx/of (select-shapes toselect))))))
@ -313,10 +312,10 @@
:ignore-groups? ignore-groups?
:full-frame? true
:using-selrect? true})
(rx/map #(cph/clean-loops objects %))
(rx/map #(cfh/clean-loops objects %))
(rx/map #(into initial-set (comp
(filter (complement blocked?))
(remove (partial cph/hidden-parent? objects))) %))
(remove (partial cfh/hidden-parent? objects))) %))
(rx/map select-shapes)))))))
(defn select-inside-group
@ -357,7 +356,7 @@
(let [shapes (map (d/getf all-objects) ids)
unames (volatile! (cfh/get-used-names (:objects page)))
update-unames! (fn [new-name] (vswap! unames conj new-name))
all-ids (reduce #(into %1 (cons %2 (cph/get-children-ids all-objects %2))) (d/ordered-set) ids)
all-ids (reduce #(into %1 (cons %2 (cfh/get-children-ids all-objects %2))) (d/ordered-set) ids)
ids-map (into {} (map #(vector % (uuid/next))) all-ids)
changes
@ -423,9 +422,9 @@
(prepare-duplicate-component-change changes objects page obj parent-id delta libraries library-data it)
:else
(let [frame? (cph/frame-shape? obj)
group? (cph/group-shape? obj)
bool? (cph/bool-shape? obj)
(let [frame? (cfh/frame-shape? obj)
group? (cfh/group-shape? obj)
bool? (cfh/bool-shape? obj)
new-id (ids-map (:id obj))
parent-id (or parent-id frame-id)
name (:name obj)
@ -554,7 +553,7 @@
(let [;; index-map is a map that goes from parent-id => vector([id index-in-parent])
index-map (reduce (fn [index-map id]
(let [parent-id (get-in objects [id :parent-id])
parent-index (cph/get-position-on-parent objects id)]
parent-index (cfh/get-position-on-parent objects id)]
(update index-map parent-id (fnil conj []) [id parent-index])))
{}
ids)
@ -608,7 +607,7 @@
[obj state objects]
(let [{:keys [id-original id-duplicated]}
(get-in state [:workspace-local :duplicated])
move? (and (cph/frame-shape? obj)
move? (and (cfh/frame-shape? obj)
(not (ctk/instance-head? obj)))]
(if (or (and (not= id-original (:id obj))
(not= id-duplicated (:id obj)))
@ -706,7 +705,7 @@
focus (-> (:workspace-focus-selected state)
(set/union added)
(set/difference removed))
focus (cph/clean-loops objects focus)]
focus (cfh/clean-loops objects focus)]
(-> state
(assoc :workspace-focus-selected focus))))))

View file

@ -9,9 +9,9 @@
[app.common.colors :as clr]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes.flex-layout :as flex]
[app.common.geom.shapes.grid-layout :as grid]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctc]
[app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl]
@ -78,13 +78,13 @@
(let [shape
(-> shape
(merge initial-layout-data)
;; (cond-> (= type :grid) (-> ctl/assign-cells ctl/reorder-grid-children))
;; If the original shape is not a frame we set clip content and show-viewer to false
(cond-> (not from-frame?)
(assoc :show-content true :hide-in-viewer true)))
params (calculate-params objects (cph/get-immediate-children objects (:id shape)) shape)]
params (calculate-params objects (cfh/get-immediate-children objects (:id shape)) shape)]
(cond-> (merge shape params)
(= type :grid) (-> ctl/assign-cells ctl/reorder-grid-children)))
@ -149,9 +149,9 @@
selected (wsh/lookup-selected state)
selected-shapes (map (d/getf objects) selected)
single? (= (count selected-shapes) 1)
has-group? (->> selected-shapes (d/seek cph/group-shape?))
has-group? (->> selected-shapes (d/seek cfh/group-shape?))
is-group? (and single? has-group?)
has-mask? (->> selected-shapes (d/seek cph/mask-shape?))
has-mask? (->> selected-shapes (d/seek cfh/mask-shape?))
is-mask? (and single? has-mask?)
has-component? (some true? (map ctc/instance-root? selected-shapes))
is-component? (and single? has-component?)
@ -167,7 +167,7 @@
(let [parent-id (:parent-id (first selected-shapes))
shapes-ids (:shapes (first selected-shapes))
ordered-ids (into (d/ordered-set) shapes-ids)
group-index (cph/get-index-replacement selected objects)]
group-index (cfh/get-index-replacement selected objects)]
(rx/of
(dwse/select-shapes ordered-ids)
(dws/create-artboard-from-selection new-shape-id parent-id group-index)
@ -186,7 +186,7 @@
(create-layout-from-id new-shape-id type false)
(dwc/update-shapes [new-shape-id] #(assoc % :layout-item-h-sizing :auto :layout-item-v-sizing :auto))
(dwc/update-shapes selected #(assoc % :layout-item-h-sizing :fix :layout-item-v-sizing :fix))))
(rx/of (ptk/data-event :layout/update [new-shape-id])
(dwu/commit-undo-transaction undo-id)))))))
@ -348,7 +348,7 @@
(defn fix-child-sizing
[objects parent-changes shape]
(let [parent (-> (cph/get-parent objects (:id shape))
(let [parent (-> (cfh/get-parent objects (:id shape))
(d/deep-merge parent-changes))
auto-width? (ctl/auto-width? parent)
@ -425,8 +425,8 @@
ptk/WatchEvent
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
children-ids (->> ids (mapcat #(cph/get-children-ids objects %)))
parent-ids (->> ids (map #(cph/get-parent-id objects %)))
children-ids (->> ids (mapcat #(cfh/get-children-ids objects %)))
parent-ids (->> ids (map #(cfh/get-parent-id objects %)))
undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(dwc/update-shapes ids (d/patch-object changes))

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.files.shapes-helpers :as cfsh]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.schema :as sm]
[app.common.types.container :as ctn]
[app.common.types.page :as ctp]
@ -52,7 +52,7 @@
(cfsh/prepare-add-shape shape objects selected))
changes (cond-> changes
(cph/text-shape? shape)
(cfh/text-shape? shape)
(pcb/set-undo-group (:id shape)))
undo-id (js/Symbol)]
@ -65,7 +65,7 @@
(when-not no-select?
(dws/select-shapes (d/ordered-set (:id shape))))
(dwu/commit-undo-transaction undo-id))
(when (cph/text-shape? shape)
(when (cfh/text-shape? shape)
(->> (rx/of (dwe/start-edition-mode (:id shape)))
(rx/observe-on :async)))))))))
@ -106,7 +106,7 @@
components-v2 (features/active-feature? state "components/v2")
ids (cph/clean-loops objects ids)
ids (cfh/clean-loops objects ids)
in-component-copy?
(fn [shape-id]
@ -194,14 +194,14 @@
all-parents
(reduce (fn [res id]
;; All parents of any deleted shape must be resized.
(into res (cph/get-parent-ids objects id)))
(into res (cfh/get-parent-ids objects id)))
(d/ordered-set)
ids)
all-children
(->> ids ;; Children of deleted shapes must be also deleted.
(reduce (fn [res id]
(into res (cph/get-children-ids objects id)))
(into res (cfh/get-children-ids objects id)))
[])
(reverse)
(into (d/ordered-set)))
@ -211,7 +211,7 @@
(let [all-ids (into empty-parents ids)
contains? (partial contains? all-ids)
xform (comp (map lookup)
(filter #(or (cph/group-shape? %) (cph/bool-shape? %)))
(filter #(or (cfh/group-shape? %) (cfh/bool-shape? %)))
(remove #(->> (:shapes %) (remove contains?) seq))
(map :id))
parents (into #{} xform all-parents)]
@ -298,10 +298,10 @@
(ctst/top-nested-frame {:x frame-x :y frame-y}))
selected (wsh/lookup-selected state)
base (cph/get-base-shape objects selected)
base (cfh/get-base-shape objects selected)
parent-id (if (or (and (= 1 (count selected))
(cph/frame-shape? (get objects (first selected))))
(cfh/frame-shape? (get objects (first selected))))
(empty? selected))
frame-id
(:parent-id base))
@ -339,7 +339,7 @@
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
selected (wsh/lookup-selected state)
selected (cph/clean-loops objects selected)
selected (cfh/clean-loops objects selected)
changes (-> (pcb/empty-changes it page-id)
(pcb/with-objects objects))
@ -390,7 +390,7 @@
;; We have change only the hidden behaviour, to hide only the
;; selected shape, block behaviour remains the same.
ids (if (boolean? blocked)
(into ids (->> ids (mapcat #(cph/get-children-ids objects %))))
(into ids (->> ids (mapcat #(cfh/get-children-ids objects %))))
ids)]
(rx/of (dch/update-shapes ids update-fn {:attrs #{:blocked :hidden}}))))))

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.svg.path.command :as upc]
[app.common.uuid :as uuid]))
@ -53,7 +53,7 @@
(and (contains? objects id)
(or (not omit-blocked?)
(not (get-in objects [id :blocked] false)))))]
(let [selected (->> selected (cph/clean-loops objects))]
(let [selected (->> selected (cfh/clean-loops objects))]
(into (d/ordered-set)
(filter selectable?)
selected)))))
@ -126,7 +126,7 @@
[parent-id state]
(let [objects (lookup-page-objects state)
modifiers (:workspace-modifiers state)
children-ids (cph/get-children-ids objects parent-id)
children-ids (cfh/get-children-ids objects parent-id)
children
(-> (select-keys objects children-ids)
(update-vals

View file

@ -8,8 +8,8 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.svg :as csvg]
[app.common.svg.shapes-builder :as csvg.shapes-builder]
[app.common.types.shape-tree :as ctst]
@ -69,7 +69,7 @@
objects (wsh/lookup-page-objects state page-id)
frame-id (ctst/top-nested-frame objects position)
selected (wsh/lookup-selected state)
base (cph/get-base-shape objects selected)
base (cfh/get-base-shape objects selected)
selected-id (first selected)
selected-frame? (and (= 1 (count selected))

View file

@ -9,10 +9,10 @@
[app.common.attrs :as attrs]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
[app.common.types.modifiers :as ctm]
[app.common.uuid :as uuid]
@ -277,8 +277,8 @@
(update-text-content shape txt/is-root-node? d/txt-merge attrs)
(assoc shape :content (d/txt-merge {:type "root"} attrs))))
shape-ids (cond (cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
shape-ids (cond (cfh/text-shape? shape) [id]
(cfh/group-shape? shape) (cfh/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids update-fn))))))
@ -304,8 +304,8 @@
update-fn #(update-text-content % txt/is-paragraph-node? merge-fn attrs)
shape-ids (cond
(cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
(cfh/text-shape? shape) [id]
(cfh/group-shape? shape) (cfh/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids update-fn))))))))
@ -325,8 +325,8 @@
(or (txt/is-text-node? node)
(txt/is-paragraph-node? node)))
shape-ids (cond
(cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))]
(cfh/text-shape? shape) [id]
(cfh/group-shape? shape) (cfh/get-children-ids objects id))]
(rx/of (dch/update-shapes shape-ids #(update-text-content % update-node? d/txt-merge attrs))))))))
@ -363,8 +363,8 @@
shape-ids
(cond
(cph/text-shape? shape) [id]
(cph/group-shape? shape) (cph/get-children-ids objects id))
(cfh/text-shape? shape) [id]
(cfh/group-shape? shape) (cfh/get-children-ids objects id))
update-content
(fn [content]
@ -677,7 +677,7 @@
objects (wsh/lookup-page-objects state)
xform (comp (keep (d/getf objects))
(filter cph/text-shape?))
(filter cfh/text-shape?))
shapes (into [] xform selected)
shape (first shapes)

View file

@ -7,8 +7,8 @@
(ns app.main.data.workspace.thumbnails
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.logging :as l]
[app.common.pages.helpers :as cph]
[app.common.thumbnails :as thc]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
@ -200,8 +200,8 @@
new-shape (get new-objects id)
old-shape (get old-objects id)
old-frame-id (if (cph/frame-shape? old-shape) id (:frame-id old-shape))
new-frame-id (if (cph/frame-shape? new-shape) id (:frame-id new-shape))]
old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape))
new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))]
(cond-> #{}
(and (some? old-frame-id) (not= uuid/zero old-frame-id))

View file

@ -9,6 +9,8 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes-builder :as pcb]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.modifiers :as gm]
[app.common.geom.point :as gpt]
@ -17,8 +19,6 @@
[app.common.geom.shapes.flex-layout :as gslf]
[app.common.geom.shapes.grid-layout :as gslg]
[app.common.math :as mth]
[app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.modifiers :as ctm]
@ -450,12 +450,12 @@
exclude-frames
(into #{}
(filter (partial cph/frame-shape? objects))
(cph/selected-with-children objects selected))
(filter (partial cfh/frame-shape? objects))
(cfh/selected-with-children objects selected))
exclude-frames-siblings
(into exclude-frames
(comp (mapcat (partial cph/get-siblings-ids objects))
(comp (mapcat (partial cfh/get-siblings-ids objects))
(filter (partial ctl/any-layout-immediate-child-id? objects)))
selected)
@ -514,7 +514,7 @@
:else
[move-vector nil])
nesting-loop? (some #(cph/components-nesting-loop? objects (:id %) target-frame) shapes)
nesting-loop? (some #(cfh/components-nesting-loop? objects (:id %) target-frame) shapes)
is-component-copy? (ctk/in-component-copy? (get objects target-frame))]
(cond-> (dwm/create-modif-tree ids (ctm/move-modifiers move-vector))
@ -578,7 +578,7 @@
(->> children
;; Add the position to move the children
(map (fn [id]
(let [position (cph/get-position-on-parent objects id)]
(let [position (cfh/get-position-on-parent objects id)]
[id (get-move-to-index parent-id position)])))
(sort-by second >)
(reduce (fn [changes [child-id index]]
@ -771,7 +771,7 @@
frame (get objects frame-id)
layout? (:layout frame)
shapes (->> ids (cph/clean-loops objects) (keep lookup))
shapes (->> ids (cfh/clean-loops objects) (keep lookup))
moving-shapes
(cond->> shapes
@ -782,12 +782,12 @@
(remove #(and (= (:frame-id %) frame-id)
(not= (:parent-id %) frame-id))))
ordered-indexes (cph/order-by-indexed-shapes objects (map :id moving-shapes))
ordered-indexes (cfh/order-by-indexed-shapes objects (map :id moving-shapes))
moving-shapes (map (d/getf objects) ordered-indexes)
all-parents
(reduce (fn [res id]
(into res (cph/get-parent-ids objects id)))
(into res (cfh/get-parent-ids objects id)))
(d/ordered-set)
ids)
@ -796,7 +796,7 @@
(let [all-ids (into empty-parents ids)
contains? (partial contains? all-ids)
xform (comp (map lookup)
(filter cph/group-shape?)
(filter cfh/group-shape?)
(remove #(->> (:shapes %) (remove contains?) seq))
(map :id))
parents (into #{} xform all-parents)]
@ -826,7 +826,7 @@
(let [shape-component (ctn/get-component-shape objects shape)]
(if (= (:id frame-component) (:id shape-component))
result
(into result (cph/get-children-ids-with-self objects (:id shape)))))
(into result (cfh/get-children-ids-with-self objects (:id shape)))))
result))
#{}
moving-shapes)
@ -840,7 +840,7 @@
;; Remove layout-item properties when moving a shape outside a layout
(cond-> (not (ctl/any-layout? objects frame-id))
(pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data))
(pcb/update-shapes moving-shapes-ids #(cond-> % (cph/frame-shape? %) (assoc :hide-in-viewer true)))
(pcb/update-shapes moving-shapes-ids #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true)))
(pcb/update-shapes shape-ids-to-detach ctk/detach-shape)
(pcb/change-parent frame-id moving-shapes drop-index)
(pcb/reorder-grid-children [frame-id])

View file

@ -8,8 +8,8 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.changes :as cpc]
[app.common.logging :as log]
[app.common.pages.changes :as cpc]
[app.common.schema :as sm]
[app.util.time :as dt]
[beicon.core :as rx]

View file

@ -8,12 +8,12 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.align :as gal]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as gpr]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms]
[beicon.core :as rx]
@ -40,7 +40,7 @@
(initialize [state local]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
shapes (cph/get-immediate-children objects)
shapes (cfh/get-immediate-children objects)
srect (gsh/shapes->rect shapes)
local (assoc local :vport size :zoom 1 :zoom-inverse 1 :hide-toolbar false)]

View file

@ -6,12 +6,12 @@
(ns app.main.data.workspace.zoom
(:require
[app.common.files.helpers :as cfh]
[app.common.geom.align :as gal]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.main.data.workspace.state-helpers :as wsh]
[app.main.streams :as ms]
[beicon.core :as rx]
@ -75,7 +75,7 @@
(update [_ state]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
shapes (cph/get-immediate-children objects)
shapes (cfh/get-immediate-children objects)
srect (gsh/shapes->rect shapes)]
(if (empty? shapes)
state

View file

@ -9,7 +9,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cph]
[app.common.types.shape-tree :as ctt]
[app.common.types.shape.layout :as ctl]
[app.main.data.workspace.state-helpers :as wsh]

View file

@ -16,13 +16,13 @@
[app.common.colors :as clr]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.bounds :as gsb]
[app.common.logging :as l]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.file :as ctf]
[app.common.types.modifiers :as ctm]
[app.common.types.shape-tree :as ctst]
@ -108,7 +108,7 @@
(mf/fnc bool-wrapper
[{:keys [shape] :as props}]
(let [childs (mf/with-memo [(:id shape) objects]
(->> (cph/get-children-ids objects (:id shape))
(->> (cfh/get-children-ids objects (:id shape))
(select-keys objects)))]
[:& bool-shape {:shape shape :childs childs}]))))
@ -166,7 +166,7 @@
(defn adapt-root-frame
[objects object]
(let [shapes (cph/get-immediate-children objects)
(let [shapes (cfh/get-immediate-children objects)
srect (gsh/shapes->rect shapes)
object (merge object (select-keys srect [:x :y :width :height]))]
(assoc object :fill-color "#f0f0f0")))
@ -175,7 +175,7 @@
[objects object-id]
(let [object (get objects object-id)
object (cond->> object
(cph/root? object)
(cfh/root? object)
(adapt-root-frame objects))
;; Replace the previous object with the new one
@ -184,7 +184,7 @@
vector (-> (gpt/point (:x object) (:y object))
(gpt/negate))
mod-ids (cons object-id (cph/get-children-ids objects object-id))
mod-ids (cons object-id (cfh/get-children-ids objects object-id))
updt-fn #(update %1 %2 gsh/transform-shape (ctm/move-modifiers vector))]
@ -195,7 +195,7 @@
[{:keys [data use-thumbnails embed include-metadata] :as props
:or {embed false include-metadata false}}]
(let [objects (:objects data)
shapes (cph/get-immediate-children objects)
shapes (cfh/get-immediate-children objects)
dim (calculate-dimensions objects)
vbox (format-viewbox dim)
bgcolor (dm/get-in data [:options :background] default-color)
@ -222,8 +222,8 @@
[:& export/export-page {:id (:id data) :options (:options data)}])
(let [shapes (->> shapes
(remove cph/frame-shape?)
(mapcat #(cph/get-children-with-self objects (:id %))))
(remove cfh/frame-shape?)
(mapcat #(cfh/get-children-with-self objects (:id %))))
fonts (ff/shapes->fonts shapes)]
[:& ff/fontfaces-style {:fonts fonts}])
@ -262,7 +262,7 @@
vector (gpt/negate delta-bounds)
children-ids
(cph/get-children-ids objects frame-id)
(cfh/get-children-ids objects frame-id)
objects
(mf/with-memo [frame-id objects vector]
@ -324,7 +324,7 @@
(mf/use-memo
(mf/deps vector objects root-shape-id)
(fn []
(let [children-ids (cons root-shape-id (cph/get-children-ids objects root-shape-id))
(let [children-ids (cons root-shape-id (cfh/get-children-ids objects root-shape-id))
update-fn #(update %1 %2 gsh/transform-shape (ctm/move-modifiers vector))]
(reduce update-fn objects children-ids))))
@ -538,7 +538,7 @@
fonts (ff/shape->fonts shape objects)
bounds (if (:show-content shape)
(let [ids (cph/get-children-ids objects shape-id)
(let [ids (cfh/get-children-ids objects shape-id)
children (sequence (keep (d/getf objects)) ids)]
(gsh/shapes->rect (cons shape children)))
(-> shape :points grc/points->rect))

View file

@ -8,13 +8,13 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.focus :as cpf]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.geom.snap :as sp]
[app.common.math :as mth]
[app.common.pages.focus :as cpf]
[app.common.pages.helpers :as cph]
[app.common.uuid :refer [zero]]
[app.main.refs :as refs]
[app.main.worker :as uw]
@ -220,7 +220,7 @@
:frame-id frame-id
:include-frames? true
:rect area})
(rx/map #(cph/clean-loops objects %))
(rx/map #(cfh/clean-loops objects %))
(rx/map #(set/difference % selected))
(rx/map #(map (d/getf objects) %))))

View file

@ -7,7 +7,7 @@
(ns app.main.ui.hooks
"A collection of general purpose react hooks."
(:require
[app.common.pages.focus :as cpf]
[app.common.files.focus :as cpf]
[app.main.broadcast :as mbc]
[app.main.data.shortcuts :as dsc]
[app.main.refs :as refs]

View file

@ -8,13 +8,13 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.flex-layout :as gsl]
[app.common.geom.shapes.points :as gpo]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.uuid :as uuid]
[app.main.data.workspace.modifiers :as dwm]
@ -692,7 +692,7 @@
:row-gap (if flip-y true false)}
objects (wsh/lookup-page-objects @st/state)
children (->> (cph/get-immediate-children objects frame-id)
children (->> (cfh/get-immediate-children objects frame-id)
(remove :layout-item-absolute)
(remove :hidden))

View file

@ -8,12 +8,12 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.bounds :as gsb]
[app.common.geom.shapes.text :as gst]
[app.common.pages.helpers :as cph]
[app.config :as cfg]
[app.config :as cf]
[app.main.ui.context :as muc]
[app.main.ui.shapes.attrs :as attrs]
[app.main.ui.shapes.embed :as embed]
@ -51,7 +51,7 @@
;; dependencies to really useful shape attrs instead of using
;; the shepe as-is.
selrect (mf/with-memo [shape]
(if (cph/text-shape? shape)
(if (cfh/text-shape? shape)
(gst/shape->rect shape)
(grc/points->rect (:points shape))))
@ -201,7 +201,7 @@
(mf/defc stroke-defs
{::mf/wrap-props false}
[{:keys [shape stroke render-id index]}]
(let [open-path? (and ^boolean (cph/path-shape? shape)
(let [open-path? (and ^boolean (cfh/path-shape? shape)
^boolean (gsh/open-path? shape))
gradient (:stroke-color-gradient stroke)
alignment (:stroke-alignment stroke :center)
@ -211,7 +211,7 @@
:gradient gradient
:shape shape}
stroke-image (:stroke-image stroke)
uri (when stroke-image (cfg/resolve-file-media stroke-image))
uri (when stroke-image (cf/resolve-file-media stroke-image))
embed (embed/use-data-uris [uri])
stroke-width (case (:stroke-alignment stroke :center)
@ -221,7 +221,7 @@
margin (gsb/shape-stroke-margin stroke stroke-width)
selrect (mf/with-memo [shape]
(if (cph/text-shape? shape)
(if (cfh/text-shape? shape)
(gst/shape->rect shape)
(grc/points->rect (:points shape))))
@ -398,7 +398,7 @@
has-stroke? (and (> stroke-width 0)
(not= stroke-style :none))
closed? (or (not ^boolean (cph/path-shape? shape))
closed? (or (not ^boolean (cfh/path-shape? shape))
(not ^boolean (gsh/open-path? shape)))
inner? (= :inner stroke-position)
outer? (= :outer stroke-position)]
@ -429,12 +429,12 @@
(obj/clone))
url-fill? (or ^boolean (some? (:fill-image shape))
^boolean (cph/image-shape? shape)
^boolean (cfh/image-shape? shape)
^boolean (> (count shape-fills) 1)
^boolean (some? (some :fill-color-gradient shape-fills))
^boolean (some? (some :fill-image shape-fills)))
props (if (cph/frame-shape? shape)
props (if (cfh/frame-shape? shape)
props
(if (or (some? (->> shape-shadow (remove :hidden) seq))
(and (some? shape-blur) (not ^boolean (:hidden shape-blur))))
@ -476,7 +476,7 @@
(let [fill (nth shape-fills 0)]
(obj/merge! style (attrs/get-fill-style fill render-id 0 (dm/get-prop shape :type))))
(and ^boolean (cph/path-shape? shape)
(and ^boolean (cfh/path-shape? shape)
^boolean (empty? shape-fills))
(obj/set! style "fill" "none"))
@ -540,7 +540,7 @@
shape-strokes (get shape :strokes)
props #js {:id stroke-id :className "strokes"}
props (if ^boolean (cph/frame-shape? shape)
props (if ^boolean (cfh/frame-shape? shape)
props
(cond
(and (some? shape-blur)

View file

@ -7,9 +7,9 @@
(ns app.main.ui.shapes.frame
(:require
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.shape.layout :as ctl]
[app.config :as cf]
[app.main.ui.context :as muc]
@ -32,7 +32,7 @@
{::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")]
(when (and ^boolean (cph/frame-shape? shape)
(when (and ^boolean (cfh/frame-shape? shape)
(not ^boolean (:show-content shape)))
(let [render-id (unchecked-get props "render-id")
@ -168,7 +168,7 @@
is-component? (mf/use-ctx muc/is-component?)
childs (cond-> childs
(ctl/any-layout? shape)
(cph/sort-layout-children-z-index))]
(cfh/sort-layout-children-z-index))]
[:> frame-container props
[:g.frame-children {:opacity (:opacity shape)}

View file

@ -8,11 +8,11 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.rect :as grc]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.main.ui.context :as muc]
[app.main.ui.shapes.export :as ed]
[app.util.object :as obj]
@ -32,7 +32,7 @@
{::mf/wrap-props false}
[{:keys [id gradient shape]}]
(let [transform (mf/with-memo [shape]
(when (cph/frame-shape? shape)
(when (cfh/frame-shape? shape)
(gsh/transform-matrix shape nil (gpt/point 0.5 0.5))))
metadata? (mf/use-ctx ed/include-metadata-ctx)
@ -56,7 +56,7 @@
(mf/defc radial-gradient
{::mf/wrap-props false}
[{:keys [id gradient shape]}]
(let [path? (cph/path-shape? shape)
(let [path? (cfh/path-shape? shape)
transform (when ^boolean path?
(dm/get-prop shape :transform))

View file

@ -8,12 +8,12 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.grid-layout :as gsg]
[app.common.geom.shapes.points :as gpo]
[app.common.pages.helpers :as cph]
[app.common.types.shape.layout :as ctl]
[app.main.refs :as refs]
[rumext.v2 :as mf]))
@ -89,7 +89,7 @@
bounds (d/lazy-map (keys objects) #(gsh/shape->points (get objects %)))
children
(->> (cph/get-immediate-children objects (:id shape))
(->> (cfh/get-immediate-children objects (:id shape))
(remove :hidden)
(map #(vector (gpo/parent-coords-bounds (:points %) (:points shape)) %)))

View file

@ -8,8 +8,8 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.rect :as grc]
[app.common.pages.helpers :as cph]
[app.main.ui.context :as muc]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
@ -55,7 +55,7 @@
(let [mask (unchecked-get props "mask")
render-id (mf/use-ctx muc/render-id)
svg-text? (and ^boolean (cph/text-shape? mask)
svg-text? (and ^boolean (cfh/text-shape? mask)
^boolean (some? (:position-data mask)))
points (dm/get-prop mask :points)

View file

@ -8,7 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.main.refs :as refs]
[app.main.ui.context :as muc]
[app.main.ui.hooks :as h]
@ -78,9 +78,9 @@
shape-without-shadows (assoc shape :shadow [])
filter-str
(when (and (or (cph/group-shape? shape)
(cph/frame-shape? shape)
(cph/svg-raw-shape? shape))
(when (and (or (cfh/group-shape? shape)
(cfh/frame-shape? shape)
(cfh/svg-raw-shape? shape))
(not disable-shadows?))
(filters/filter-str filter-id shape))

View file

@ -7,7 +7,7 @@
(ns app.main.ui.shapes.text.fontfaces
(:require
[app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.main.fonts :as fonts]
[app.main.ui.shapes.embed :as embed]
[app.util.object :as obj]
@ -93,17 +93,17 @@
(defn shape->fonts
[shape objects]
(let [initial (cond-> #{}
(cph/text-shape? shape)
(cfh/text-shape? shape)
(into (fonts/get-content-fonts (:content shape))))]
(->> (cph/get-children objects (:id shape))
(filter cph/text-shape?)
(->> (cfh/get-children objects (:id shape))
(filter cfh/text-shape?)
(map (comp fonts/get-content-fonts :content))
(reduce set/union initial))))
(defn shapes->fonts
[shapes]
(->> shapes
(filter cph/text-shape?)
(filter cfh/text-shape?)
(map (comp fonts/get-content-fonts :content))
(reduce set/union #{})))

View file

@ -10,9 +10,9 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.bounds :as gsb]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
[app.common.types.shape.interactions :as ctsi]
[app.main.data.comments :as dcm]
@ -276,7 +276,7 @@
(hooks/use-equal-memo
(->> (:objects page)
(vals)
(filter cph/text-shape?)))
(filter cfh/text-shape?)))
zoom (:zoom local)
zoom-type (:zoom-type local)

View file

@ -7,8 +7,8 @@
(ns app.main.ui.viewer.inspect.attributes.image
(:require-macros [app.main.style :as stl])
(:require
[app.common.files.helpers :as cfh]
[app.common.media :as cm]
[app.common.pages.helpers :as cph]
[app.config :as cf]
[app.main.ui.components.copy-button :refer [copy-button]]
[app.main.ui.context :as ctx]
@ -24,7 +24,7 @@
[{:keys [objects shapes]}]
(let [new-css-system (mf/use-ctx ctx/new-css-system)]
(if new-css-system
(for [shape (filter cph/image-shape? shapes)]
(for [shape (filter cfh/image-shape? shapes)]
[:div {:class (stl/css :attributes-block)
:key (str "image-" (:id shape))}
[:div {:class (stl/css :image-wrapper)}
@ -54,7 +54,7 @@
(tr "inspect.attributes.image.download")])])
(for [shape (filter cph/image-shape? shapes)]
(for [shape (filter cfh/image-shape? shapes)]
[:div.attributes-block {:key (str "image-" (:id shape))}
[:div.attributes-image-row
[:div.attributes-image

View file

@ -10,13 +10,12 @@
["js-beautify" :as beautify]
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.shape-tree :as ctst]
[app.config :as cfg]
[app.main.data.events :as ev]
[app.main.fonts :as fonts]
;; [app.main.data.preview :as dp]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.components.code-block :refer [code-block]]
@ -128,7 +127,7 @@
all-children (->> shapes
(map :id)
(cph/selected-with-children objects)
(cfh/selected-with-children objects)
(ctst/sort-z-index objects)
(map (d/getf objects)))

View file

@ -8,7 +8,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.component :as ctk]
[app.common.types.shape.layout :as ctl]
[app.main.data.viewer :as dv]
@ -90,7 +90,7 @@
:shape-touched? touched?
:hidden? hidden?
:selected? selected?
:type-frame (cph/frame-shape? item)
:type-frame (cfh/frame-shape? item)
:disabled-double-click true}]
(when (and (not disable-collapse?) (:shapes item))

View file

@ -7,9 +7,9 @@
(ns app.main.ui.viewer.inspect.render
"The main container for a frame in inspect mode"
(:require
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.main.data.viewer :as dv]
[app.main.store :as st]
[app.main.ui.shapes.bool :as bool]
@ -33,16 +33,16 @@
(defn handle-hover-shape
[shape hover?]
(fn [event]
(when-not (or (cph/group-shape? shape)
(cph/root-frame? shape))
(when-not (or (cfh/group-shape? shape)
(cfh/root-frame? shape))
(dom/prevent-default event)
(dom/stop-propagation event)
(st/emit! (dv/hover-shape (:id shape) hover?)))))
(defn select-shape [shape]
(fn [event]
(when-not (or (cph/group-shape? shape)
(cph/root-frame? shape))
(when-not (or (cfh/group-shape? shape)
(cfh/root-frame? shape))
(dom/stop-propagation event)
(dom/prevent-default event)
(cond
@ -119,7 +119,7 @@
{::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")
children (->> (cph/get-children-ids objects (:id shape))
children (->> (cfh/get-children-ids objects (:id shape))
(select-keys objects))
props (-> (obj/create)
(obj/merge! props)

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.page :as ctp]
[app.common.uuid :as uuid]
@ -34,7 +34,7 @@
(gpt/add delta)
(gpt/negate))
update-fn #(d/update-when %1 %2 gsh/transform-shape (ctm/move-modifiers vector))]
(->> (cph/get-children-ids objects frame-id)
(->> (cfh/get-children-ids objects frame-id)
(into [frame-id])
(reduce update-fn objects))))
@ -54,11 +54,11 @@
;; we have con consider the children if the fixed element is a group
fixed-children-ids
(into #{} (mapcat #(cph/get-children-ids (:objects page) (:id %)) fixed-ids))
(into #{} (mapcat #(cfh/get-children-ids (:objects page) (:id %)) fixed-ids))
parent-children-ids
(->> fixed-ids
(mapcat #(cons (:id %) (cph/get-parent-ids (:objects page) (:id %))))
(mapcat #(cons (:id %) (cfh/get-parent-ids (:objects page) (:id %))))
(remove #(= % uuid/zero)))
fixed-ids

View file

@ -8,8 +8,8 @@
"The main container for a frame in viewer mode"
(:require
[app.common.data :as d]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.shape.interactions :as ctsi]
[app.main.data.viewer :as dv]
[app.main.refs :as refs]
@ -40,9 +40,9 @@
(defn- find-relative-to-base-frame
[shape objects overlays-ids base-frame]
(cond
(cph/frame-shape? shape) shape
(or (empty? overlays-ids) (nil? shape) (cph/root? shape)) base-frame
:else (find-relative-to-base-frame (cph/get-parent objects (:id shape)) objects overlays-ids base-frame)))
(cfh/frame-shape? shape) shape
(or (empty? overlays-ids) (nil? shape) (cfh/root? shape)) base-frame
:else (find-relative-to-base-frame (cfh/get-parent objects (:id shape)) objects overlays-ids base-frame)))
(defn- activate-interaction
[interaction shape base-frame frame-offset objects overlays]
@ -416,7 +416,7 @@
(mf/fnc bool-container
{::mf/wrap-props false}
[props]
(let [childs (->> (cph/get-children-ids objects (:id (unchecked-get props "shape")))
(let [childs (->> (cfh/get-children-ids objects (:id (unchecked-get props "shape")))
(select-keys objects))
props (obj/merge! #js {} props
#js {:childs childs

View file

@ -8,8 +8,8 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.main.data.viewer :as dv]
[app.main.render :as render]
[app.main.store :as st]
@ -79,7 +79,7 @@
#(mf/deferred % ts/idle-then-raf)]}
[{:keys [selected? frame on-click index objects page-id thumbnail-data]}]
(let [children-ids (cph/get-children-ids objects (:id frame))
(let [children-ids (cfh/get-children-ids objects (:id frame))
children-bounds (gsh/shapes->rect (concat [frame] (->> children-ids (keep (d/getf objects)))))]
[:div.thumbnail-item {:on-click #(on-click % index)}
[:div.thumbnail-preview

View file

@ -10,7 +10,7 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.types.component :as ctk]
[app.common.types.container :as ctn]
[app.common.types.page :as ctp]
@ -234,7 +234,7 @@
(mf/defc context-menu-thumbnail
[{:keys [shapes]}]
(let [single? (= (count shapes) 1)
has-frame? (some cph/frame-shape? shapes)
has-frame? (some cfh/frame-shape? shapes)
do-toggle-thumbnail #(st/emit! (dw/toggle-file-thumbnail-selected))]
(when (and single? has-frame?)
[:*
@ -253,9 +253,9 @@
single? (= (count shapes) 1)
do-create-artboard-from-selection #(st/emit! (dwsh/create-artboard-from-selection))
has-frame? (->> shapes (d/seek cph/frame-shape?))
has-group? (->> shapes (d/seek cph/group-shape?))
has-bool? (->> shapes (d/seek cph/bool-shape?))
has-frame? (->> shapes (d/seek cfh/frame-shape?))
has-group? (->> shapes (d/seek cfh/group-shape?))
has-bool? (->> shapes (d/seek cfh/bool-shape?))
has-mask? (->> shapes (d/seek :masked-group))
is-group? (and single? has-group?)
@ -307,10 +307,10 @@
(let [multiple? (> (count shapes) 1)
single? (= (count shapes) 1)
has-group? (->> shapes (d/seek cph/group-shape?))
has-bool? (->> shapes (d/seek cph/bool-shape?))
has-frame? (->> shapes (d/seek cph/frame-shape?))
has-path? (->> shapes (d/seek cph/path-shape?))
has-group? (->> shapes (d/seek cfh/group-shape?))
has-bool? (->> shapes (d/seek cfh/bool-shape?))
has-frame? (->> shapes (d/seek cfh/frame-shape?))
has-path? (->> shapes (d/seek cfh/path-shape?))
is-group? (and single? has-group?)
is-bool? (and single? has-bool?)
@ -396,7 +396,7 @@
prototype? (= options-mode :prototype)
single? (= (count shapes) 1)
has-frame? (->> shapes (d/seek cph/frame-shape?))
has-frame? (->> shapes (d/seek cfh/frame-shape?))
is-frame? (and single? has-frame?)]
(when (and prototype? is-frame?)
@ -410,7 +410,7 @@
(mf/defc context-menu-flex
[{:keys [shapes]}]
(let [single? (= (count shapes) 1)
has-frame? (->> shapes (d/seek cph/frame-shape?))
has-frame? (->> shapes (d/seek cfh/frame-shape?))
is-flex-container? (and single? has-frame? (= :flex (:layout (first shapes))))
ids (->> shapes (map :id))

View file

@ -6,7 +6,7 @@
(ns app.main.ui.workspace.header
(:require
[app.common.pages.helpers :as cph]
[app.common.files.helpers :as cfh]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.common :refer [show-shared-dialog]]
@ -351,8 +351,8 @@
shared? (:is-shared file)
objects (mf/deref refs/workspace-page-objects)
frames (->> (cph/get-immediate-children objects uuid/zero)
(filterv cph/frame-shape?))
frames (->> (cfh/get-immediate-children objects uuid/zero)
(filterv cfh/frame-shape?))
add-shared-fn
(mf/use-fn

View file

@ -4,36 +4,37 @@
;;
;; Copyright (c) KALEIDOS INC
(ns app.main.ui.workspace.left-header (:require-macros [app.main.style :as stl])
(:require
[app.common.pages.helpers :as cph]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.common :refer [show-shared-dialog]]
[app.main.data.events :as ev]
[app.main.data.exports :as de]
[app.main.data.modal :as modal]
[app.main.data.shortcuts :as scd]
[app.main.data.workspace :as dw]
[app.main.data.workspace.colors :as dc]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.shortcuts :as sc]
[app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.components.dropdown-menu :refer [dropdown-menu dropdown-menu-item]]
[app.main.ui.context :as ctx]
[app.main.ui.hooks.resize :as r]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[beicon.core :as rx]
[cuerdas.core :as str]
[potok.core :as ptk]
[rumext.v2 :as mf]))
(ns app.main.ui.workspace.left-header
(:require-macros [app.main.style :as stl])
(:require
[app.common.files.helpers :as cfh]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.common :refer [show-shared-dialog]]
[app.main.data.events :as ev]
[app.main.data.exports :as de]
[app.main.data.modal :as modal]
[app.main.data.shortcuts :as scd]
[app.main.data.workspace :as dw]
[app.main.data.workspace.colors :as dc]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.shortcuts :as sc]
[app.main.refs :as refs]
[app.main.repo :as rp]
[app.main.store :as st]
[app.main.ui.components.dropdown-menu :refer [dropdown-menu dropdown-menu-item]]
[app.main.ui.context :as ctx]
[app.main.ui.hooks.resize :as r]
[app.main.ui.icons :as i]
[app.util.dom :as dom]
[app.util.i18n :as i18n :refer [tr]]
[app.util.keyboard :as kbd]
[app.util.router :as rt]
[beicon.core :as rx]
[cuerdas.core :as str]
[potok.core :as ptk]
[rumext.v2 :as mf]))
;; --- Header menu and submenus
@ -466,8 +467,8 @@
shared? (:is-shared file)
objects (mf/deref refs/workspace-page-objects)
frames (->> (cph/get-immediate-children objects uuid/zero)
(filterv cph/frame-shape?))
frames (->> (cfh/get-immediate-children objects uuid/zero)
(filterv cfh/frame-shape?))
add-shared-fn
(mf/use-fn

Some files were not shown because too many files have changed in this diff Show more