0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 08:11:30 -05:00

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

This commit is contained in:
Andrey Antukh 2021-11-30 19:02:27 +01:00 committed by Alonso Torres
parent b897f202dd
commit 6a7600fd52
42 changed files with 461 additions and 383 deletions

View file

@ -6,7 +6,6 @@
(ns app.util.emails
(:require
[app.common.data :as d]
[app.common.exceptions :as ex]
[app.common.spec :as us]
[app.util.template :as tmpl]
@ -199,7 +198,7 @@
(ex/raise :type :internal
:code :missing-email-templates))
{:subject subj
:body (d/concat
:body (into
[{:type "text/plain"
:content text}]
(when html

View file

@ -37,7 +37,7 @@
;; --- Development Stuff
(defn- run-tests
([] (run-tests #"^app.common.tests.*"))
([] (run-tests #"^app.common.*-test$"))
([o]
(repl/refresh)
(cond

View file

@ -6,7 +6,7 @@
(ns app.common.data
"Data manipulation and query helper functions."
(:refer-clojure :exclude [concat read-string hash-map merge name])
(:refer-clojure :exclude [read-string hash-map merge name])
#?(:cljs
(:require-macros [app.common.data]))
(:require
@ -60,19 +60,37 @@
m)
(dissoc m k)))
(defn concat
[& colls]
(loop [result (transient (first colls))
colls (next colls)]
(defn- transient-concat
[c1 colls]
(loop [result (transient c1)
colls colls]
(if colls
(recur (reduce conj! result (first colls))
(next colls))
(persistent! result))))
(defn concat-set
([] #{})
([c1]
(if (set? c1) c1 (into #{} c1)))
([c1 & more]
(if (set? c1)
(transient-concat c1 more)
(transient-concat #{} (cons c1 more)))))
(defn concat-vec
([] [])
([c1]
(if (vector? c1) c1 (into [] c1)))
([c1 & more]
(if (vector? c1)
(transient-concat c1 more)
(transient-concat [] (cons c1 more)))))
(defn preconj
[coll elem]
(assert (vector? coll))
(concat [elem] coll))
(into [elem] coll))
(defn enumerate
([items] (enumerate items 0))
@ -144,10 +162,15 @@
(reduce #(dissoc! %1 %2) (transient data) keys))))
(defn remove-at-index
"Takes a vector and returns a vector with an element in the
specified index removed."
[v index]
(vec (core/concat
(subvec v 0 index)
(subvec v (inc index)))))
;; The subvec function returns a SubVector type that is an vector
;; but does not have transient impl, because of this, we need to
;; pass an explicit vector as first argument.
(concat-vec []
(subvec v 0 index)
(subvec v (inc index))))
(defn zip [col1 col2]
(map vector col1 col2))
@ -435,16 +458,16 @@
(defn with-next
"Given a collection will return a new collection where each element
is paired with the next item in the collection
(with-next (range 5)) => [[0 1] [1 2] [2 3] [3 4] [4 nil]"
(with-next (range 5)) => [[0 1] [1 2] [2 3] [3 4] [4 nil]]"
[coll]
(map vector
coll
(concat [] (rest coll) [nil])))
(concat (rest coll) [nil])))
(defn with-prev
"Given a collection will return a new collection where each element
is paired with the previous item in the collection
(with-prev (range 5)) => [[0 nil] [1 0] [2 1] [3 2] [4 3]"
(with-prev (range 5)) => [[0 nil] [1 0] [2 1] [3 2] [4 3]]"
[coll]
(map vector
coll
@ -453,12 +476,12 @@
(defn with-prev-next
"Given a collection will return a new collection where every item is paired
with the previous and the next item of a collection
(with-prev-next (range 5)) => [[0 nil 1] [1 0 2] [2 1 3] [3 2 4] [4 3 nil]"
(with-prev-next (range 5)) => [[0 nil 1] [1 0 2] [2 1 3] [3 2 4] [4 3 nil]]"
[coll]
(map vector
coll
(concat [nil] coll)
(concat [] (rest coll) [nil])))
(concat (rest coll) [nil])))
(defn prefix-keyword
"Given a keyword and a prefix will return a new keyword with the prefix attached

View file

@ -6,7 +6,6 @@
(ns app.common.geom.align
(:require
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[clojure.spec.alpha :as s]))
@ -16,11 +15,15 @@
(declare calc-align-pos)
;; TODO: revisit on how to reuse code and dont have this function
;; duplicated because the implementation right now differs from the
;; original function.
;; Duplicated from pages/helpers to remove cyclic dependencies
(defn- get-children [id objects]
(let [shapes (vec (get-in objects [id :shapes]))]
(if shapes
(d/concat shapes (mapcat #(get-children % objects) shapes))
(into shapes (mapcat #(get-children % objects)) shapes)
[])))
(defn- recursive-move

View file

@ -100,7 +100,7 @@
(defn curve-tangent
"Retrieve the tangent vector to the curve in the point `t`"
[[start end h1 h2] t]
(let [coords [[(:x start) (:x h1) (:x h2) (:x end)]
[(:y start) (:y h1) (:y h2) (:y end)]]
@ -316,15 +316,13 @@
:line-to [prev-point (command->point command)]
;; We return the bezier extremities
:curve-to (d/concat
[prev-point
(command->point command)]
(let [curve [prev-point
(command->point command)
(command->point command :c1)
(command->point command :c2)]]
(->> (curve-extremities curve)
(mapv #(curve-values curve %)))))
:curve-to (into [prev-point (command->point command)]
(let [curve [prev-point
(command->point command)
(command->point command :c1)
(command->point command :c2)]]
(->> (curve-extremities curve)
(map #(curve-values curve %)))))
[])
selrect (gpr/points->selrect points)]
(-> selrect
@ -342,20 +340,19 @@
(command->point command)]
;; We return the bezier extremities
:curve-to (d/concat
[(command->point prev)
(command->point command)]
(let [curve [(command->point prev)
(command->point command)
(command->point command :c1)
(command->point command :c2)]]
(->> (curve-extremities curve)
(mapv #(curve-values curve %)))))
:curve-to (into [(command->point prev)
(command->point command)]
(let [curve [(command->point prev)
(command->point command)
(command->point command :c1)
(command->point command :c2)]]
(->> (curve-extremities curve)
(map #(curve-values curve %)))))
[]))
extremities (mapcat calc-extremities
content
(d/concat [nil] content))
(concat [nil] content))
selrect (gpr/points->selrect extremities)]
@ -410,14 +407,16 @@
(let [initial (first segments)
lines (rest segments)]
(d/concat [{:command :move-to
:params (select-keys initial [:x :y])}]
(->> lines
(mapv #(hash-map :command :line-to
:params (select-keys % [:x :y]))))
(d/concat-vec
[{:command :move-to
:params (select-keys initial [:x :y])}]
(when closed?
[{:command :close-path}])))))
(->> lines
(map #(hash-map :command :line-to
:params (select-keys % [:x :y]))))
(when closed?
[{:command :close-path}])))))
(defonce num-segments 10)
@ -770,7 +769,7 @@
ts-3 (check-range c1-half c1-to c2-from c2-half)
ts-4 (check-range c1-half c1-to c2-half c2-to)]
(d/concat [] ts-1 ts-2 ts-3 ts-4)))))))
(d/concat-vec ts-1 ts-2 ts-3 ts-4)))))))
(remove-close-ts [{cp1 :p1 cp2 :p2}]
(fn [{:keys [p1 p2]}]

View file

@ -214,7 +214,7 @@
not-mask-shapes (without-obj shapes mask-id)
new-index (if (nil? index) nil (max (dec index) 0))
new-shapes (insert-items other-ids new-index not-mask-shapes)]
(d/concat [mask-id] new-shapes))))
(into [mask-id] new-shapes))))
(add-to-parent [parent index shapes]
(let [parent (-> parent

View file

@ -98,7 +98,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

@ -103,7 +103,6 @@
"Retrieve all children ids recursively for a given object. The
children's order will be breadth first."
[id objects]
(loop [result (transient [])
pending (transient [])
next id]
@ -221,8 +220,8 @@
(pos? (count after')))
(let [before' (conj before' (first after'))
after' (into [] (rest after'))]
(d/concat [] before' ids after'))
(d/concat [] before' ids after'))))
(d/concat-vec before' ids after'))
(d/concat-vec before' ids after'))))
(defn append-at-the-end
[prev-ids ids]
@ -238,24 +237,25 @@
([objects {:keys [include-frames? include-frame-children?]
:or {include-frames? false
include-frame-children? true}}]
(let [lookup #(get objects %)
root (lookup uuid/zero)
(let [lookup #(get objects %)
root (lookup uuid/zero)
root-children (:shapes root)
lookup-shapes
(fn [result id]
(if (nil? id)
result
(let [obj (lookup id)
typ (:type obj)
(let [obj (lookup id)
typ (:type obj)
children (:shapes obj)]
(cond-> result
(or (not= :frame typ) include-frames?)
(d/concat [obj])
(conj obj)
(and (= :frame typ) include-frame-children?)
(d/concat (map lookup children))))))]
(into (map lookup) children)))))]
(reduce lookup-shapes [] root-children))))
@ -304,15 +304,13 @@
(some? (:shapes object))
(assoc :shapes (mapv :id new-direct-children)))
new-object (update-new-object new-object object)
new-objects (d/concat [new-object] new-children)
updated-object (update-original-object object new-object)
new-object (update-new-object new-object object)
new-objects (into [new-object] new-children)
updated-object (update-original-object object new-object)
updated-objects (if (identical? object updated-object)
updated-children
(d/concat [updated-object] updated-children))]
(into [updated-object] updated-children))]
[new-object new-objects updated-objects])
@ -325,9 +323,9 @@
(recur
(next child-ids)
(d/concat new-direct-children [new-child])
(d/concat new-children new-child-objects)
(d/concat updated-children updated-child-objects))))))))
(into new-direct-children [new-child])
(into new-children new-child-objects)
(into updated-children updated-child-objects))))))))
(defn indexed-shapes
"Retrieves a list with the indexes for each element in the layer tree.

View file

@ -12,28 +12,25 @@
[clojure.set :as set]))
(defn calculate-frame-z-index [z-index frame-id objects]
(let [is-frame? (fn [id] (= :frame (get-in objects [id :type])))
(let [is-frame? (fn [id] (= :frame (get-in objects [id :type])))
frame-shapes (->> objects (vals) (filterv #(= (:frame-id %) frame-id)))
children (or (get-in objects [frame-id :shapes]) [])]
children (or (get-in objects [frame-id :shapes]) [])]
(if (empty? children)
z-index
(loop [current (peek children)
pending (pop children)
current-idx (count frame-shapes)
z-index z-index]
(let [children (get-in objects [current :shapes])
(let [children (get-in objects [current :shapes])
is-frame? (is-frame? current)
pending (if (not is-frame?)
(d/concat pending children)
pending)]
pending (if (not is-frame?)
(d/concat-vec pending children)
pending)]
(if (empty? pending)
(-> z-index
(assoc current current-idx))
(assoc z-index current current-idx)
(recur (peek pending)
(pop pending)
(dec current-idx)

View file

@ -213,26 +213,25 @@
;; Pick all segments in content-a that are not inside content-b
;; Pick all segments in content-b that are not inside content-a
(let [content
(d/concat
[]
(concat
(->> content-a-split (filter #(not (contains-segment? % content-b))))
(->> content-b-split (filter #(not (contains-segment? % content-a)))))
;; Overlapping segments should be added when they are part of the border
border-content
(->> content-b-split
(filterv #(and (contains-segment? % content-a)
(overlap-segment? % content-a-split)
(not (inside-segment? % content)))))]
(filter #(and (contains-segment? % content-a)
(overlap-segment? % content-a-split)
(not (inside-segment? % content)))))]
(d/concat content border-content)))
;; Ensure that the output is always a vector
(d/concat-vec content border-content)))
(defn create-difference [content-a content-a-split content-b content-b-split]
;; Pick all segments in content-a that are not inside content-b
;; Pick all segments in content b that are inside content-a
;; removing overlapping
(d/concat
[]
(d/concat-vec
(->> content-a-split (filter #(not (contains-segment? % content-b))))
;; Reverse second content so we can have holes inside other shapes
@ -243,15 +242,14 @@
(defn create-intersection [content-a content-a-split content-b content-b-split]
;; Pick all segments in content-a that are inside content-b
;; Pick all segments in content-b that are inside content-a
(d/concat
[]
(d/concat-vec
(->> content-a-split (filter #(contains-segment? % content-b)))
(->> content-b-split (filter #(contains-segment? % content-a)))))
(defn create-exclusion [content-a content-b]
;; Pick all segments
(d/concat [] content-a content-b))
(d/concat-vec content-a content-b))
(defn fix-move-to

View file

@ -31,23 +31,22 @@
:blur])
(def style-properties
(d/concat
style-group-properties
[:fill-color
:fill-opacity
:fill-color-gradient
:fill-color-ref-file
:fill-color-ref-id
:fill-image
:stroke-color
:stroke-color-ref-file
:stroke-color-ref-id
:stroke-opacity
:stroke-style
:stroke-width
:stroke-alignment
:stroke-cap-start
:stroke-cap-end]))
(into style-group-properties
[:fill-color
:fill-opacity
:fill-color-gradient
:fill-color-ref-file
:fill-color-ref-id
:fill-image
:stroke-color
:stroke-color-ref-file
:stroke-color-ref-id
:stroke-opacity
:stroke-style
:stroke-width
:stroke-alignment
:stroke-cap-start
:stroke-cap-end]))
(defn make-corner-arc
"Creates a curvle corner for border radius"

View file

@ -90,7 +90,7 @@
[subpath other]
(assert (pt= (:to subpath) (:from other)))
(-> subpath
(update :data d/concat (rest (:data other)))
(update :data d/concat-vec (rest (:data other)))
(assoc :to (:to other))))
(defn- merge-paths

View file

@ -0,0 +1,58 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) UXBOX Labs SL
(ns app.common.data-test
(:require
[app.common.data :as d]
[clojure.test :as t]))
(t/deftest concat-vec
(t/is (= [1 2 3]
(d/concat-vec [1] #{2} [3])))
(t/is (= [1 2]
(d/concat-vec '(1) [2])))
(t/is (= [1]
(d/concat-vec [1])))
(t/is (= [] (d/concat-vec))))
(t/deftest concat-set
(t/is (= #{} (d/concat-set)))
(t/is (= #{1 2}
(d/concat-set [1] [2]))))
(t/deftest remove-at-index
(t/is (= [1 2 3 4]
(d/remove-at-index [1 2 3 4 5] 4)))
(t/is (= [1 2 3 4]
(d/remove-at-index [5 1 2 3 4] 0)))
(t/is (= [1 2 3 4]
(d/remove-at-index [1 5 2 3 4] 1)))
)
(t/deftest with-next
(t/is (= [[0 1] [1 2] [2 3] [3 4] [4 nil]]
(d/with-next (range 5)))))
(t/deftest with-prev
(t/is (= [[0 nil] [1 0] [2 1] [3 2] [4 3]]
(d/with-prev (range 5)))))
(t/deftest with-prev-next
(t/is (= [[0 nil 1] [1 0 2] [2 1 3] [3 2 4] [4 3 nil]]
(d/with-prev-next (range 5)))))
(t/deftest join
(t/is (= [[1 :a] [1 :b] [2 :a] [2 :b] [3 :a] [3 :b]]
(d/join [1 2 3] [:a :b])))
(t/is (= [1 10 100 2 20 200 3 30 300]
(d/join [1 2 3] [1 10 100] *))))

View file

@ -201,7 +201,7 @@
(recur (->> (get svgdata "elements")
(filter #(= (get % "name") "g"))
(map (partial set-path-color id color mapping))
(update result "elements" d/concat))
(update result "elements" into))
(rest layers))
;; Now we have the result containing the svgdata of a
@ -232,8 +232,8 @@
elements (cond->> elements
(not (empty? gradient-defs))
(d/concat [{"type" "element" "name" "defs" "attributes" {}
"elements" gradient-defs}]))]
(into [{"type" "element" "name" "defs" "attributes" {}
"elements" gradient-defs}]))]
(-> result
(assoc "name" "g")

View file

@ -547,7 +547,7 @@
(disj flags flag)
(conj flags flag)))
stored
(into #{} flags)))))))
(d/concat-set flags)))))))
;; --- Set element options mode
@ -785,8 +785,7 @@
groups-to-delete)
u-del-change
(d/concat
[]
(concat
;; Create the groups
(map (fn [group-id]
(let [group (get objects group-id)]
@ -937,25 +936,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
@ -971,18 +970,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 #{}]
@ -996,7 +992,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)
@ -1023,6 +1019,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
@ -1204,7 +1204,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

@ -9,6 +9,7 @@
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.common.pages :as cp]
[app.common.spec :as us]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.state-helpers :as wsh]
@ -51,7 +52,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 +132,7 @@
uchanges (->> ids-to-delete
(reduce add-deleted-group uchanges))]
[group rchanges uchanges]))
(defn prepare-remove-group
@ -138,10 +140,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
@ -244,61 +249,67 @@
[(first shapes) [] []]
(prepare-create-group objects page-id shapes "Group-1" true))
;; Assertions just for documentation purposes
_ (us/assert vector? rchanges)
_ (us/assert vector? uchanges)
children (map #(get objects %) (:shapes group))
rchanges (d/concat rchanges
(for [child children]
{:type :mod-obj
:page-id page-id
:id (:id child)
:operations [{:type :set
:attr :constraints-h
:val :scale}
{:type :set
:attr :constraints-v
:val :scale}]})
[{: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
(for [child children]
{:type :mod-obj
:page-id page-id
:id (:id child)
:operations [{:type :set
:attr :constraints-h
:val :scale}
{:type :set
:attr :constraints-v
:val :scale}]})
[{: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 (d/concat uchanges
(for [child children]
{:type :mod-obj
:page-id page-id
:id (:id child)
:operations [{:type :set
:attr :constraints-h
:val (:constraints-h child)}
{:type :set
:attr :constraints-v
:val (:constraints-v child)}]})
[{: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
(for [child children]
{:type :mod-obj
:page-id page-id
:id (:id child)
:operations [{:type :set
:attr :constraints-h
:val (:constraints-h child)}
{:type :set
:attr :constraints-v
:val (:constraints-v child)}]})
[{: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 additionally 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}]
@ -270,10 +272,10 @@
on-convert-to-typography
(fn [_]
(let [set-values (-> (d/without-nils values)
(select-keys
(d/concat text-font-attrs
text-spacing-attrs
text-transform-attrs)))
(select-keys
(d/concat-vec text-font-attrs
text-spacing-attrs
text-transform-attrs)))
typography (merge txt/default-typography set-values)
typography (generate-typography-name typography)
id (uuid/next)]

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)])
[(into ids new-ids) (merge-attrs values new-values)])
[])))]
(reduce extract-attrs [[] []] shapes)))

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