💄 Add cosmetic changes to stoke related functions frontend

This commit is contained in:
Andrey Antukh 2023-05-22 13:04:40 +02:00
parent 98a6c63ad6
commit 73ed37f57a

View file

@ -201,7 +201,6 @@
(if (= (:type shape) :frame) (if (= (:type shape) :frame)
(d/merge shape attrs) (d/merge shape attrs)
shape)))))))) shape))))))))
(defn change-stroke (defn change-stroke
[ids attrs index] [ids attrs index]
(ptk/reify ::change-stroke (ptk/reify ::change-stroke
@ -225,24 +224,28 @@
attrs (merge attrs color-attrs)] attrs (merge attrs color-attrs)]
(rx/of (dch/update-shapes ids (fn [shape] (rx/of (dch/update-shapes
(let [new-attrs (merge (get-in shape [:strokes index]) attrs) ids
new-attrs (cond-> new-attrs (fn [shape]
(not (contains? new-attrs :stroke-width)) (let [new-attrs (merge (get-in shape [:strokes index]) attrs)
(assoc :stroke-width 1) new-attrs (cond-> new-attrs
(not (contains? new-attrs :stroke-width))
(assoc :stroke-width 1)
(not (contains? new-attrs :stroke-style)) (not (contains? new-attrs :stroke-style))
(assoc :stroke-style :solid) (assoc :stroke-style :solid)
(not (contains? new-attrs :stroke-alignment)) (not (contains? new-attrs :stroke-alignment))
(assoc :stroke-alignment :center) (assoc :stroke-alignment :center)
:always :always
(d/without-nils))] (d/without-nils))]
(-> shape (cond-> shape
(cond-> (not (contains? shape :strokes)) (not (contains? shape :strokes))
(assoc :strokes [])) (assoc :strokes [])
(assoc-in [:strokes index] new-attrs))))))))))
:always
(assoc-in [:strokes index] new-attrs))))))))))
(defn change-shadow (defn change-shadow
[ids attrs index] [ids attrs index]
@ -276,34 +279,29 @@
(ptk/reify ::add-stroke (ptk/reify ::add-stroke
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(let [add (fn [shape attrs] (assoc shape :strokes (into [attrs] (:strokes shape))))] (let [add-stroke (fn [shape] (update shape :strokes #(into [stroke] %)))]
(rx/of (dch/update-shapes (rx/of (dch/update-shapes ids add-stroke))))))
ids
#(add % stroke)))))))
(defn remove-stroke (defn remove-stroke
[ids position] [ids position]
(ptk/reify ::remove-stroke (ptk/reify ::remove-stroke
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(let [remove-fill-by-index (fn [values index] (->> (d/enumerate values) (letfn [(remove-fill-by-index [values index]
(filterv (fn [[idx _]] (not= idx index))) (->> (d/enumerate values)
(mapv second))) (filterv (fn [[idx _]] (not= idx index)))
(mapv second)))
remove (fn [shape] (update shape :strokes remove-fill-by-index position))] (remove-stroke [shape]
(rx/of (dch/update-shapes (update shape :strokes remove-fill-by-index position))]
ids (rx/of (dch/update-shapes ids remove-stroke))))))
#(remove %)))))))
(defn remove-all-strokes (defn remove-all-strokes
[ids] [ids]
(ptk/reify ::remove-all-strokes (ptk/reify ::remove-all-strokes
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ _] (watch [_ _ _]
(let [remove-all (fn [shape] (assoc shape :strokes []))] (let [remove-all #(assoc % :strokes [])]
(rx/of (dch/update-shapes (rx/of (dch/update-shapes ids remove-all))))))
ids
#(remove-all %)))))))
(defn reorder-shadows (defn reorder-shadows
[ids index new-index] [ids index new-index]