♻️ Ensure a correct usage of concat/into operations.

This commit is contained in:
Andrey Antukh 2021-11-30 19:02:27 +01:00
parent 4ad34ab5c8
commit 8a2a1d6d70
43 changed files with 446 additions and 373 deletions

View file

@ -546,7 +546,7 @@
(disj flags flag)
(conj flags flag)))
stored
(into #{} flags)))))))
(d/concat-set flags)))))))
;; --- Set element options mode
@ -784,8 +784,7 @@
groups-to-delete)
u-del-change
(d/concat
[]
(concat
;; Create the groups
(map (fn [group-id]
(let [group (get objects group-id)]
@ -936,25 +935,25 @@
:page-id page-id
:shapes (vec parents)}]
rchanges (d/concat []
r-mov-change
r-del-change
r-mask-change
r-detach-change
r-deroot-change
r-reroot-change
r-unconstraint-change
r-reg-change)
rchanges (d/concat-vec
r-mov-change
r-del-change
r-mask-change
r-detach-change
r-deroot-change
r-reroot-change
r-unconstraint-change
r-reg-change)
uchanges (d/concat []
u-del-change
u-reroot-change
u-deroot-change
u-detach-change
u-mask-change
u-mov-change
u-unconstraint-change
u-reg-change)]
uchanges (d/concat-vec
u-del-change
u-reroot-change
u-deroot-change
u-detach-change
u-mask-change
u-mov-change
u-unconstraint-change
u-reg-change)]
[rchanges uchanges]))
(defn relocate-shapes
@ -970,18 +969,15 @@
objects (wsh/lookup-page-objects state page-id)
;; Ignore any shape whose parent is also intented to be moved
ids (cp/clean-loops objects ids)
ids (cp/clean-loops objects ids)
;; If we try to move a parent into a child we remove it
ids (filter #(not (cp/is-parent? objects parent-id %)) ids)
parents (reduce (fn [result id]
(conj result (cp/get-parent id objects)))
#{parent-id} ids)
ids (filter #(not (cp/is-parent? objects parent-id %)) ids)
parents (into #{parent-id} (map #(cp/get-parent % objects)) ids)
groups-to-delete
(loop [current-id (first parents)
to-check (rest parents)
(loop [current-id (first parents)
to-check (rest parents)
removed-id? (set ids)
result #{}]
@ -995,7 +991,7 @@
(empty? (remove removed-id? (:shapes group))))
;; Adds group to the remove and check its parent
(let [to-check (d/concat [] to-check [(cp/get-parent current-id objects)]) ]
(let [to-check (concat to-check [(cp/get-parent current-id objects)])]
(recur (first to-check)
(rest to-check)
(conj removed-id? current-id)
@ -1022,6 +1018,10 @@
#{}
ids)
;; TODO: Probably implementing this using loop/recur will
;; be more efficient than using reduce and continuos data
;; desturcturing.
;; Sets the correct components metadata for the moved shapes
;; `shapes-to-detach` Detach from a component instance a shape that was inside a component and is moved outside
;; `shapes-to-deroot` Removes the root flag from a component instance moved inside another component
@ -1111,7 +1111,7 @@
(defn relocate-page
[id index]
(ptk/reify ::relocate-pages
(ptk/reify ::relocate-page
ptk/WatchEvent
(watch [it state _]
(let [cidx (-> (get-in state [:workspace-data :pages])
@ -1209,7 +1209,7 @@
(boolean? hidden) (assoc :hidden hidden)))
objects (wsh/lookup-page-objects state)
ids (d/concat [id] (cp/get-children id objects))]
ids (into [id] (cp/get-children id objects))]
(rx/of (dch/update-shapes ids update-fn))))))

View file

@ -50,7 +50,7 @@
(let [old-obj (get objects id)
new-obj (update-fn old-obj)
attrs (or attrs (d/concat #{} (keys old-obj) (keys new-obj)))
attrs (or attrs (d/concat-set (keys old-obj) (keys new-obj)))
{rops :rops uops :uops}
(reduce #(generate-operation %1 %2 old-obj new-obj ignore-geometry?)

View file

@ -51,7 +51,7 @@
(empty? (remove removed-id? (:shapes group))))
;; Adds group to the remove and check its parent
(let [to-check (d/concat [] to-check [(cp/get-parent current-id objects)]) ]
(let [to-check (concat to-check [(cp/get-parent current-id objects)]) ]
(recur (first to-check)
(rest to-check)
(conj removed-id? current-id)
@ -131,6 +131,7 @@
uchanges (->> ids-to-delete
(reduce add-deleted-group uchanges))]
[group rchanges uchanges]))
(defn prepare-remove-group
@ -138,10 +139,13 @@
(let [shapes (:shapes group)
parent-id (cp/get-parent (:id group) objects)
parent (get objects parent-id)
index-in-parent (->> (:shapes parent)
(map-indexed vector)
(filter #(#{(:id group)} (second %)))
(ffirst))
index-in-parent
(->> (:shapes parent)
(map-indexed vector)
(filter #(#{(:id group)} (second %)))
(ffirst))
rchanges [{:type :mov-objects
:page-id page-id
:parent-id parent-id
@ -223,39 +227,41 @@
[(first shapes) [] []]
(prepare-create-group objects page-id shapes "Group-1" true))
rchanges (d/concat rchanges
[{:type :mod-obj
:page-id page-id
:id (:id group)
:operations [{:type :set
:attr :masked-group?
:val true}
{:type :set
:attr :selrect
:val (-> shapes first :selrect)}
{:type :set
:attr :points
:val (-> shapes first :points)}
{:type :set
:attr :transform
:val (-> shapes first :transform)}
{:type :set
:attr :transform-inverse
:val (-> shapes first :transform-inverse)}]}
{:type :reg-objects
:page-id page-id
:shapes [(:id group)]}])
rchanges (d/concat-vec
rchanges
[{:type :mod-obj
:page-id page-id
:id (:id group)
:operations [{:type :set
:attr :masked-group?
:val true}
{:type :set
:attr :selrect
:val (-> shapes first :selrect)}
{:type :set
:attr :points
:val (-> shapes first :points)}
{:type :set
:attr :transform
:val (-> shapes first :transform)}
{:type :set
:attr :transform-inverse
:val (-> shapes first :transform-inverse)}]}
{:type :reg-objects
:page-id page-id
:shapes [(:id group)]}])
uchanges (conj uchanges
{:type :mod-obj
:page-id page-id
:id (:id group)
:operations [{:type :set
:attr :masked-group?
:val nil}]}
{:type :reg-objects
:page-id page-id
:shapes [(:id group)]})]
uchanges (d/concat-vec
uchanges
{:type :mod-obj
:page-id page-id
:id (:id group)
:operations [{:type :set
:attr :masked-group?
:val nil}]}
{:type :reg-objects
:page-id page-id
:shapes [(:id group)]})]
(rx/of (dch/commit-changes {:redo-changes rchanges
:undo-changes uchanges

View file

@ -666,14 +666,14 @@
(dwlh/generate-sync-file file-id :typographies library-id state)]
xf-fcat (comp (remove nil?) (map first) (mapcat identity))
rchanges (d/concat []
(sequence xf-fcat library-changes)
(sequence xf-fcat file-changes))
rchanges (d/concat-vec
(sequence xf-fcat library-changes)
(sequence xf-fcat file-changes))
xf-scat (comp (remove nil?) (map second) (mapcat identity))
uchanges (d/concat []
(sequence xf-scat library-changes)
(sequence xf-scat file-changes))]
uchanges (d/concat-vec
(sequence xf-scat library-changes)
(sequence xf-scat file-changes))]
(log/debug :msg "SYNC-FILE finished" :js/rchanges (log-changes
rchanges
@ -720,8 +720,8 @@
(let [file (dwlh/get-file state file-id)
[rchanges1 uchanges1] (dwlh/generate-sync-file file-id :components library-id state)
[rchanges2 uchanges2] (dwlh/generate-sync-library file-id :components library-id state)
rchanges (d/concat rchanges1 rchanges2)
uchanges (d/concat uchanges1 uchanges2)]
rchanges (d/concat-vec rchanges1 rchanges2)
uchanges (d/concat-vec uchanges1 uchanges2)]
(when rchanges
(log/debug :msg "SYNC-FILE (2nd stage) finished" :js/rchanges (log-changes
rchanges

View file

@ -54,8 +54,8 @@
(defn concat-changes
[[rchanges1 uchanges1] [rchanges2 uchanges2]]
[(d/concat rchanges1 rchanges2)
(d/concat uchanges1 uchanges2)])
[(d/concat-vec rchanges1 rchanges2)
(d/concat-vec uchanges1 uchanges2)])
(defn get-local-file
[state]
@ -134,6 +134,10 @@
[(first shapes) [] []]
(dwg/prepare-create-group objects page-id shapes "Component-1" true))
;; Asserts for documentation purposes
_ (us/assert vector? rchanges)
_ (us/assert vector? uchanges)
[new-shape new-shapes updated-shapes]
(make-component-shape group objects file-id)
@ -288,8 +292,8 @@
state
(cp/make-container page :page))]
(recur (next pages)
(d/concat rchanges page-rchanges)
(d/concat uchanges page-uchanges)))
(into rchanges page-rchanges)
(into uchanges page-uchanges)))
[rchanges uchanges]))))
(defn generate-sync-library
@ -315,8 +319,8 @@
(cp/make-container local-component
:component))]
(recur (next local-components)
(d/concat rchanges comp-rchanges)
(d/concat uchanges comp-uchanges)))
(into rchanges comp-rchanges)
(into uchanges comp-uchanges)))
[rchanges uchanges]))))
(defn- generate-sync-container
@ -341,8 +345,8 @@
container
shape)]
(recur (next shapes)
(d/concat rchanges shape-rchanges)
(d/concat uchanges shape-uchanges)))
(into rchanges shape-rchanges)
(into uchanges shape-uchanges)))
[rchanges uchanges]))))
(defn- has-asset-reference-fn
@ -438,7 +442,7 @@
:fill-color-ref-id nil
:fill-color-ref-file nil)))]
(generate-sync-text-shape shape container update-node))
(loop [attrs (seq color-sync-attrs)
(loop [attrs (seq color-sync-attrs)
roperations []
uoperations []]
(let [[attr-ref-id attr-ref-file color-attr attr] (first attrs)]
@ -490,8 +494,8 @@
:val (get shape attr-ref-file)
:ignore-touched true}])]
(recur (next attrs)
(concat roperations roperations')
(concat uoperations uoperations'))))))))))
(into roperations roperations')
(into uoperations uoperations'))))))))))
(defmethod generate-sync-shape :typographies
[_ library-id state container shape]
@ -734,8 +738,8 @@
moved
false)]
[(d/concat rchanges child-rchanges)
(d/concat uchanges child-uchanges)])))
[(d/concat-vec rchanges child-rchanges)
(d/concat-vec uchanges child-uchanges)])))
(defn generate-sync-shape-inverse
"Generate changes to update the component a shape is linked to, from
@ -862,8 +866,8 @@
rchanges (mapv check-local rchanges)
uchanges (mapv check-local uchanges)]
[(d/concat rchanges child-rchanges)
(d/concat uchanges child-uchanges)])))
[(d/concat-vec rchanges child-rchanges)
(d/concat-vec uchanges child-uchanges)])))
; ---- Operation generation helpers ----
@ -963,33 +967,32 @@
update-new-shape
update-original-shape)
rchanges (d/concat
(mapv (fn [shape']
(make-change
container
(as-> {:type :add-obj
:id (:id shape')
:parent-id (:parent-id shape')
:index index
:ignore-touched true
:obj shape'} $
(cond-> $
(:frame-id shape')
(assoc :frame-id (:frame-id shape'))))))
new-shapes)
[(make-change
container
{:type :reg-objects
:shapes all-parents})])
rchanges (d/concat-vec
(map (fn [shape']
(make-change
container
(as-> {:type :add-obj
:id (:id shape')
:parent-id (:parent-id shape')
:index index
:ignore-touched true
:obj shape'} $
(cond-> $
(:frame-id shape')
(assoc :frame-id (:frame-id shape'))))))
new-shapes)
[(make-change
container
{:type :reg-objects
:shapes all-parents})])
uchanges (d/concat
(mapv (fn [shape']
(make-change
container
{:type :del-obj
:id (:id shape')
:ignore-touched true}))
new-shapes))]
uchanges (mapv (fn [shape']
(make-change
container
{:type :del-obj
:id (:id shape')
:ignore-touched true}))
new-shapes)]
(if (and (cp/touched-group? parent-shape :shapes-group) omit-touched?)
empty-changes
@ -1024,47 +1027,46 @@
update-new-shape
update-original-shape)
rchanges (d/concat
(mapv (fn [shape']
{:type :add-obj
:id (:id shape')
:component-id (:id component)
:parent-id (:parent-id shape')
:index index
:ignore-touched true
:obj shape'})
new-shapes)
[{:type :reg-objects
:component-id (:id component)
:shapes all-parents}]
(mapv (fn [shape']
{:type :mod-obj
:page-id (:id page)
:id (:id shape')
:operations [{:type :set
:attr :component-id
:val (:component-id shape')}
{:type :set
:attr :component-file
:val (:component-file shape')}
{:type :set
:attr :component-root?
:val (:component-root? shape')}
{:type :set
:attr :shape-ref
:val (:shape-ref shape')}
{:type :set
:attr :touched
:val (:touched shape')}]})
updated-shapes))
rchanges (d/concat-vec
(map (fn [shape']
{:type :add-obj
:id (:id shape')
:component-id (:id component)
:parent-id (:parent-id shape')
:index index
:ignore-touched true
:obj shape'})
new-shapes)
[{:type :reg-objects
:component-id (:id component)
:shapes all-parents}]
(map (fn [shape']
{:type :mod-obj
:page-id (:id page)
:id (:id shape')
:operations [{:type :set
:attr :component-id
:val (:component-id shape')}
{:type :set
:attr :component-file
:val (:component-file shape')}
{:type :set
:attr :component-root?
:val (:component-root? shape')}
{:type :set
:attr :shape-ref
:val (:shape-ref shape')}
{:type :set
:attr :touched
:val (:touched shape')}]})
updated-shapes))
uchanges (d/concat
(mapv (fn [shape']
{:type :del-obj
:id (:id shape')
:page-id (:id page)
:ignore-touched true})
new-shapes))]
uchanges (mapv (fn [shape']
{:type :del-obj
:id (:id shape')
:page-id (:id page)
:ignore-touched true})
new-shapes)]
[rchanges uchanges]))
@ -1102,13 +1104,13 @@
(:frame-id shape')
(assoc :frame-id (:frame-id shape')))))))
uchanges (d/concat
[(add-change (:id shape))]
(map add-change children)
[(make-change
container
{:type :reg-objects
:shapes (vec parents)})])]
uchanges (d/concat-vec
[(add-change (:id shape))]
(map add-change children)
[(make-change
container
{:type :reg-objects
:shapes (vec parents)})])]
(if (and (cp/touched-group? parent :shapes-group) omit-touched?)
empty-changes

View file

@ -6,7 +6,6 @@
(ns app.main.data.workspace.path.state
(:require
[app.common.data :as d]
[app.common.path.shapes-to-path :as upsp]))
(defn get-path-id
@ -19,11 +18,10 @@
[state & ks]
(let [edit-id (get-in state [:workspace-local :edition])
page-id (:current-page-id state)]
(d/concat
(if edit-id
[:workspace-data :pages-index page-id :objects edit-id]
[:workspace-drawing :object])
ks)))
(into (if edit-id
[:workspace-data :pages-index page-id :objects edit-id]
[:workspace-drawing :object])
ks)))
(defn get-path
"Retrieves the location of the path object and additionaly can pass

View file

@ -409,8 +409,10 @@
:shapes [shape-id]}]
;; Careful! the undo changes are concatenated reversed (we undo in reverse order
changes [(d/concat rchs rch1 rch2) (d/concat uch1 uchs)]
unames (conj unames (:name shape))
changes [(d/concat-vec rchs rch1 rch2)
(d/concat-vec uch1 uchs)]
unames (conj unames (:name shape))
reducer-fn (partial add-svg-child-changes page-id objects selected frame-id shape-id svg-data)]
(reduce reducer-fn [unames changes] (d/enumerate children)))

View file

@ -25,7 +25,6 @@
[cljs.spec.alpha :as s]
[potok.core :as ptk]))
;; -- Helpers --------------------------------------------------------
;; For each of the 8 handlers gives the multiplier for resize
@ -123,8 +122,7 @@
(let [modifiers (or modifiers (get-in state [:workspace-local :modifiers] {}))
page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
ids (->> ids (into #{} (remove #(get-in objects [% :blocked] false))))]
ids (into #{} (remove #(get-in objects [% :blocked] false)) ids)]
(reduce (fn [state id]
(update state :workspace-modifiers
@ -148,20 +146,19 @@
ptk/UpdateEvent
(update [_ state]
(let [objects (wsh/lookup-page-objects state)
id->obj #(get objects %)
get-children (fn [shape] (map id->obj (cp/get-children (:id shape) objects)))
shapes (->> shapes (into [] (remove #(get % :blocked false))))
shapes (->> shapes (mapcat get-children) (concat shapes))
shapes (->> shapes
(remove #(get % :blocked false))
(mapcat (fn [shape]
(->> (cp/get-children (:id shape) objects)
(map #(get objects %)))))
(concat shapes))
update-shape
(fn [modifiers shape]
(let [rotate-modifiers (gsh/rotation-modifiers shape center angle)]
(assoc-in modifiers [(:id shape) :modifiers] rotate-modifiers)))]
(-> state
(update :workspace-modifiers
#(reduce update-shape % shapes))))))))
(update state :workspace-modifiers #(reduce update-shape % shapes)))))))
(defn- apply-modifiers
[ids]
@ -169,11 +166,11 @@
(ptk/reify ::apply-modifiers
ptk/WatchEvent
(watch [_ state _]
(let [objects (wsh/lookup-page-objects state)
children-ids (->> ids (mapcat #(cp/get-children % objects)))
ids-with-children (d/concat [] children-ids ids)
object-modifiers (get state :workspace-modifiers)
ignore-tree (d/mapm #(get-in %2 [:modifiers :ignore-geometry?]) object-modifiers)]
(let [objects (wsh/lookup-page-objects state)
children-ids (->> ids (mapcat #(cp/get-children % objects)))
ids-with-children (d/concat-vec children-ids ids)
object-modifiers (get state :workspace-modifiers)
ignore-tree (d/mapm #(get-in %2 [:modifiers :ignore-geometry?]) object-modifiers)]
(rx/of (dwu/start-undo-transaction)
(dch/update-shapes
@ -423,7 +420,10 @@
(watch [_ state _]
(let [page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id)
ids (d/concat [] ids (mapcat #(cp/get-children % objects) ids))]
;; TODO: looks completly redundant operation because
;; apply-modifiers already finds all children.
ids (d/concat-vec ids (mapcat #(cp/get-children % objects) ids))]
(rx/of (apply-modifiers ids))))))

View file

@ -168,9 +168,8 @@
(map between-snap))
;; Search the minimum snap
snap-list (-> [] (d/concat lt-snap) (d/concat gt-snap) (d/concat between-snap))
min-snap (reduce best-snap ##Inf snap-list)]
snap-list (d/concat-vec lt-snap gt-snap between-snap)
min-snap (reduce best-snap ##Inf snap-list)]
(if (mth/finite? min-snap) [0 min-snap] nil)))
@ -291,8 +290,7 @@
(set (keys other)))]
(into {}
(map (fn [key]
[key
(d/concat [] (get matches key []) (get other key []))]))
[key (d/concat-vec (get matches key []) (get other key []))]))
keys)))]
(-> matches

View file

@ -192,7 +192,7 @@
h-lines (->> (calculate-distance-lines (:x1 from) (:x2 from) (:x1 to) (:x2 to))
(map (fn [[start end]] [start fixed-y end fixed-y])))
lines (d/concat [] v-lines h-lines)
lines (d/concat-vec v-lines h-lines)
distance-line-stroke (/ distance-line-stroke zoom)]

View file

@ -6,7 +6,6 @@
(ns app.main.ui.settings.options
(:require
[app.common.data :as d]
[app.common.spec :as us]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
@ -49,8 +48,8 @@
[:h2 (t locale "labels.language")]
[:div.fields-row
[:& fm/select {:options (d/concat [{:label "Auto (browser)" :value ""}]
i18n/supported-locales)
[:& fm/select {:options (into [{:label "Auto (browser)" :value ""}]
i18n/supported-locales)
:label (t locale "dashboard.select-ui-language")
:default ""
:name :lang}]]

View file

@ -149,8 +149,7 @@
(defn shape->filters
[shape]
(d/concat
[]
(d/concat-vec
[{:id "BackgroundImageFix" :type :image-fix}]
;; Background blur won't work in current SVG specification

View file

@ -53,7 +53,7 @@
(fn [index]
(swap! exports (fn [exports]
(let [[before after] (split-at index exports)]
(d/concat [] before (rest after)))))))
(d/concat-vec before (rest after)))))))
on-scale-change
(mf/use-callback

View file

@ -36,7 +36,7 @@
update-fn #(d/update-when %1 %2 assoc-in [:modifiers :displacement] modifier)]
(->> (cp/get-children frame-id objects)
(d/concat [frame-id])
(into [frame-id])
(reduce update-fn objects)))))

View file

@ -7,7 +7,6 @@
(ns app.main.ui.viewer.shapes
"The main container for a frame in viewer mode"
(:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as geom]
@ -396,7 +395,7 @@
update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)
frame-id (:id frame)
modifier-ids (d/concat [frame-id] (cp/get-children frame-id objects))
modifier-ids (into [frame-id] (cp/get-children frame-id objects))
objects (reduce update-fn objects modifier-ids)
frame (assoc-in frame [:modifiers :displacement] modifier)

View file

@ -6,7 +6,6 @@
(ns app.main.ui.workspace.shapes.path.editor
(:require
[app.common.data :as d]
[app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as gsp]
[app.common.path.commands :as upc]
@ -166,9 +165,9 @@
:zoom zoom}]])
(mf/defc path-snap [{:keys [selected points zoom]}]
(let [ranges (mf/use-memo (mf/deps selected points) #(snap/create-ranges points selected))
(let [ranges (mf/use-memo (mf/deps selected points) #(snap/create-ranges points selected))
snap-matches (snap/get-snap-delta-match selected ranges (/ 1 zoom))
matches (d/concat [] (second (:x snap-matches)) (second (:y snap-matches)))]
matches (concat (second (:x snap-matches)) (second (:y snap-matches)))]
[:g.snap-paths
(for [[from to] matches]

View file

@ -75,7 +75,7 @@
(mf/deps shape)
(fn [index]
(let [[before after] (split-at index exports)
exports (d/concat [] before (rest after))]
exports (d/concat-vec before (rest after))]
(st/emit! (udw/update-shape (:id shape)
{:exports exports})))))

View file

@ -68,17 +68,19 @@
(def root-attrs text-valign-attrs)
(def paragraph-attrs
(d/concat text-align-attrs
text-direction-attrs))
(d/concat-vec
text-align-attrs
text-direction-attrs))
(def text-attrs
(d/concat text-typography-attrs
text-font-attrs
text-spacing-attrs
text-decoration-attrs
text-transform-attrs))
(d/concat-vec
text-typography-attrs
text-font-attrs
text-spacing-attrs
text-decoration-attrs
text-transform-attrs))
(def attrs (d/concat #{} shape-attrs root-attrs paragraph-attrs text-attrs))
(def attrs (d/concat-set shape-attrs root-attrs paragraph-attrs text-attrs))
(mf/defc text-align-options
[{:keys [values on-change on-blur] :as props}]
@ -271,12 +273,12 @@
(fn [_]
(let [setted-values (-> (d/without-nils values)
(select-keys
(d/concat text-font-attrs
text-spacing-attrs
text-transform-attrs)))
typography (merge txt/default-typography setted-values)
typography (generate-typography-name typography)
id (uuid/next)]
(d/concat-vec text-font-attrs
text-spacing-attrs
text-transform-attrs)))
typography (merge txt/default-typography setted-values)
typography (generate-typography-name typography)
id (uuid/next)]
(st/emit! (dwl/add-typography (assoc typography :id id) false))
(run! #(emit-update! % {:typography-ref-id id
:typography-ref-file file-id}) ids)))

View file

@ -183,7 +183,7 @@
(attrs/get-attrs-multi (txt/node-seq content) attrs))))]
:children (let [children (->> (:shapes shape []) (map #(get objects %)))
[new-ids new-values] (get-attrs children objects attr-type)]
[(d/concat ids new-ids) (merge-attrs values new-values)])
[(d/concat-vec ids new-ids) (merge-attrs values new-values)])
[])))]
(reduce extract-attrs [[] []] shapes)))

View file

@ -82,7 +82,7 @@
on-drop
(mf/use-callback
(mf/deps id)
(mf/deps id index)
(fn [side {:keys [id] :as data}]
(let [index (if (= :bot side) (inc index) index)]
(st/emit! (dw/relocate-page id index)))))

View file

@ -6,7 +6,6 @@
(ns app.main.ui.workspace.viewport.hooks
(:require
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.main.data.shortcuts :as dsc]
@ -162,10 +161,9 @@
remove-xfm (mapcat #(cp/get-parents % objects))
remove-id? (cond-> (into #{} remove-xfm selected)
@ctrl?
(d/concat (filterv is-group? ids)))
ids (->> ids (filterv (comp not remove-id?)))
(into (filter is-group?) ids))
ids (filterv (comp not remove-id?) ids)
hover-shape (get objects (first ids))]
(reset! hover hover-shape)

View file

@ -163,12 +163,12 @@
show-candidate? #(check-in-set % distances)
;; Checks the distances between elements for distances that match the set of distances
distance-coincidences (d/concat (get-shapes-match show-candidate? lt-shapes)
(get-shapes-match show-candidate? gt-shapes))
distance-coincidences (d/concat-vec
(get-shapes-match show-candidate? lt-shapes)
(get-shapes-match show-candidate? gt-shapes))
;; Stores the distance candidates to be shown
distance-candidates (d/concat
#{}
distance-candidates (d/concat-set
(map first distance-coincidences)
(filter #(check-in-set % lt-distances) gt-distances)
(filter #(check-in-set % gt-distances) lt-distances))
@ -194,7 +194,7 @@
(filter #(show-distance? (distance-to-selrect %)))
(map #(vector selrect (:selrect %))))
segments-to-display (d/concat #{} other-shapes-segments selection-segments)]
segments-to-display (d/concat-set other-shapes-segments selection-segments)]
segments-to-display))
(mf/defc shape-distance

View file

@ -121,7 +121,7 @@
(rx/switch-map #(rx/combine-latest (get-snap :x %)
(get-snap :y %)))
(rx/map (fn [result]
(apply d/concat (seq result))))
(apply d/concat-vec (seq result))))
(rx/subs #(let [rs (filter (fn [[_ snaps _]] (> (count snaps) 0)) %)]
(reset! state rs))))]

View file

@ -60,14 +60,14 @@
param-list (extract-params cmd [[:x :number]
[:y :number]])]
(d/concat [{:command :move-to
:relative relative
:params (first param-list)}]
(into [{:command :move-to
:relative relative
:params (first param-list)}]
(for [params (rest param-list)]
{:command :line-to
:relative relative
:params params}))))
(for [params (rest param-list)]
{:command :line-to
:relative relative
:params params}))))
(defmethod parse-command "Z" [_]
[{:command :close-path}])
@ -259,7 +259,7 @@
(update :params merge (quadratic->curve prev-pos (gpt/point params) (upg/calculate-opposite-handler prev-pos prev-qc)))))
result (if (= :elliptical-arc (:command command))
(d/concat result (arc->beziers prev-pos command))
(into result (arc->beziers prev-pos command))
(conj result command))
next-cc (case (:command orig-command)

View file

@ -304,7 +304,7 @@
[content points]
(let [segments-set (into #{}
(map (fn [{:keys [start end]}] [start end]))
(juxt :start :end)
(get-segments content points))
create-line-command (fn [point other]
@ -318,7 +318,7 @@
(flatten)
(into []))]
(d/concat content new-content)))
(into content new-content)))
(defn separate-nodes

View file

@ -630,8 +630,7 @@
(defn find-node-references [node]
(let [current (->> (find-attr-references (:attrs node)) (into #{}))
children (->> (:content node) (map find-node-references) (flatten) (into #{}))]
(-> (d/concat current children)
(vec))))
(vec (into current children))))
(defn find-def-references [defs references]
(loop [result (into #{} references)
@ -653,7 +652,7 @@
(let [node (get defs to-check)
new-refs (find-node-references node)
pending (concat pending new-refs)]
(recur (d/concat result new-refs)
(recur (into result new-refs)
(conj checked? to-check)
(first pending)
(rest pending))))))

View file

@ -292,7 +292,7 @@
:file-id (:component-file shape)})
(= :text (:type shape))
(d/concat (get-text-refs (:content shape)))))]
(into (get-text-refs (:content shape)))))]
(->> (get-in file [:data :pages-index])
(vals)

View file

@ -66,7 +66,7 @@
changed-ids (into #{}
(comp (filter #(not= % uuid/zero))
(filter changes?)
(mapcat #(d/concat [%] (cp/get-children % new-objects))))
(mapcat #(into [%] (cp/get-children % new-objects))))
(set/union (set (keys old-objects))
(set (keys new-objects))))

View file

@ -22,13 +22,11 @@
(let [points (when-not (:hidden shape) (snap/shape-snap-points shape))
shape-data (->> points (mapv #(vector % (:id shape))))]
(if (= (:id shape) frame-id)
(d/concat
shape-data
;; The grid points are only added by the "root" of the coord-dat
(->> (gg/grid-snap-points shape coord)
(map #(vector % :layout))))
(into shape-data
;; The grid points are only added by the "root" of the coord-dat
(->> (gg/grid-snap-points shape coord)
(map #(vector % :layout))))
shape-data))))
(defn- add-coord-data