From 66e877ed40703d52fdbf53e2fcdc4d8f555daf58 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 4 Aug 2023 08:41:20 +0200 Subject: [PATCH 1/3] :bug: Fix stroke-width parsing on svg upload And refactor a bit the stroke parsing function --- .../app/main/data/workspace/svg_upload.cljs | 94 ++++++++++--------- frontend/src/app/main/ui/shapes/attrs.cljs | 2 +- frontend/src/app/util/color.cljs | 17 ++-- 3 files changed, 63 insertions(+), 50 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index 53fbbbafb..b2b9ff629 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -8,6 +8,7 @@ (:require [app.common.colors :as clr] [app.common.data :as d] + [app.common.data.macros :as dm] [app.common.exceptions :as ex] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] @@ -123,56 +124,65 @@ (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :fill-opacity]) (d/parse-double 1))))))) -(defn setup-stroke [shape] - (let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap]) - (get-in shape [:svg-attrs :style :stroke-linecap])) - ((d/nilf str/trim)) - ((d/nilf keyword))) - color-attr (str/trim (get-in shape [:svg-attrs :stroke])) - color-attr (if (= color-attr "currentColor") clr/black color-attr) - color-style (str/trim (get-in shape [:svg-attrs :style :stroke])) - color-style (if (= color-style "currentColor") clr/black color-style) - shape - (cond-> shape - ;; Color present as attribute - (uc/color? color-attr) - (-> (update :svg-attrs dissoc :stroke) - (assoc-in [:strokes 0 :stroke-color] (uc/parse-color color-attr))) +(defn- setup-stroke + [shape] + (let [attrs (get shape :svg-attrs) + style (get attrs :style) - ;; Color present as style - (uc/color? color-style) - (-> (update-in [:svg-attrs :style] dissoc :stroke) - (assoc-in [:strokes 0 :stroke-color] (uc/parse-color color-style))) + stroke (or (str/trim (:stroke attrs)) + (str/trim (:stroke style))) - (get-in shape [:svg-attrs :stroke-opacity]) - (-> (update :svg-attrs dissoc :stroke-opacity) - (assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :stroke-opacity]) - (d/parse-double 1)))) + color (cond + (= stroke "currentColor") clr/black + (= stroke "none") nil + :else (uc/parse-color stroke)) - (get-in shape [:svg-attrs :style :stroke-opacity]) - (-> (update-in [:svg-attrs :style] dissoc :stroke-opacity) - (assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :style :stroke-opacity]) - (d/parse-double 1)))) + opacity (when (some? color) + (d/parse-double + (or (:stroke-opacity attrs) + (:stroke-opacity style)) + 1)) - (get-in shape [:svg-attrs :stroke-width]) - (-> (update :svg-attrs dissoc :stroke-width) - (assoc-in [:strokes 0 :stroke-width] (-> (get-in shape [:svg-attrs :stroke-width]) - (d/parse-double)))) + width (when (some? color) + (d/parse-double + (or (:stroke-width attrs) + (:stroke-width style)) + 1)) - (get-in shape [:svg-attrs :style :stroke-width]) - (-> (update-in [:svg-attrs :style] dissoc :stroke-width) - (assoc-in [:strokes 0 :stroke-width] (-> (get-in shape [:svg-attrs :style :stroke-width]) - (d/parse-double)))) + linecap (or (get attrs :stroke-linecap) + (get style :stroke-linecap)) + linecap (some-> linecap str/trim keyword) - (and stroke-linecap (= (:type shape) :path)) - (-> (update-in [:svg-attrs :style] dissoc :stroke-linecap) - (cond-> (#{:round :square} stroke-linecap) - (assoc :stroke-cap-start stroke-linecap - :stroke-cap-end stroke-linecap))))] + attrs (-> attrs + (dissoc :stroke) + (dissoc :stroke-width) + (dissoc :stroke-opacity) + (update :style (fn [style] + (-> style + (dissoc :stroke) + (dissoc :stroke-linecap) + (dissoc :stroke-width) + (dissoc :stroke-opacity)))))] - (cond-> shape - (d/any-key? (get-in shape [:strokes 0]) :stroke-color :stroke-opacity :stroke-width :stroke-cap-start :stroke-cap-end) + (cond-> (assoc shape :svg-attrs attrs) + (some? color) + (assoc-in [:strokes 0 :stroke-color] color) + + (and (some? color) (some? opacity)) + (assoc-in [:strokes 0 :stroke-opacity] opacity) + + (and (some? color) (some? width)) + (assoc-in [:strokes 0 :stroke-width] width) + + (and (some? linecap) (= (:type shape) :path) + (or (= linecap :round) (= linecap :square))) + (assoc :stroke-cap-start linecap + :stroke-cap-end linecap) + + (d/any-key? (dm/get-in shape [:strokes 0]) + :stroke-color :stroke-opacity :stroke-width + :stroke-cap-start :stroke-cap-end) (assoc-in [:strokes 0 :stroke-style] :svg)))) (defn setup-opacity [shape] diff --git a/frontend/src/app/main/ui/shapes/attrs.cljs b/frontend/src/app/main/ui/shapes/attrs.cljs index d736e2cf4..8ea32ef4e 100644 --- a/frontend/src/app/main/ui/shapes/attrs.cljs +++ b/frontend/src/app/main/ui/shapes/attrs.cljs @@ -89,7 +89,7 @@ (obj/merge! attrs (clj->js fill-attrs))))) (defn add-stroke [attrs stroke-data render-id index] - (let [stroke-style (:stroke-style stroke-data :none) + (let [stroke-style (:stroke-style stroke-data :solid) stroke-color-gradient-id (str "stroke-color-gradient_" render-id "_" index) stroke-width (:stroke-width stroke-data 1)] (if (not= stroke-style :none) diff --git a/frontend/src/app/util/color.cljs b/frontend/src/app/util/color.cljs index 30f49882e..5b8ca29fd 100644 --- a/frontend/src/app/util/color.cljs +++ b/frontend/src/app/util/color.cljs @@ -8,6 +8,7 @@ "Color conversion utils." (:require [app.common.data :as d] + [app.common.data.macros :as dm] [app.util.i18n :as i18n :refer [tr]] [app.util.object :as obj] [app.util.strings :as ust] @@ -176,14 +177,16 @@ (= id :multiple) (= file-id :multiple))) -(defn color? [^string color-str] - (and (not (nil? color-str)) - (seq color-str) - (gcolor/isValidColor color-str))) +(defn color? + [color] + (and (string? color) + (gcolor/isValidColor color))) -(defn parse-color [^string color-str] - (let [result (gcolor/parse color-str)] - (str (.-hex ^js result)))) +(defn parse-color + [color] + (when (color? color) + (let [result (gcolor/parse color)] + (dm/str (.-hex ^js result))))) (def color-names (obj/get-keys ^js gcolor/names)) From 2ba79961167550da6c427ba1e2af28090541c1a4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 4 Aug 2023 08:58:44 +0200 Subject: [PATCH 2/3] :bug: Fix unexpected viewport update on leave workspace --- frontend/src/app/main/ui/hooks/resize.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/main/ui/hooks/resize.cljs b/frontend/src/app/main/ui/hooks/resize.cljs index 1782048ca..2811805a0 100644 --- a/frontend/src/app/main/ui/hooks/resize.cljs +++ b/frontend/src/app/main/ui/hooks/resize.cljs @@ -106,7 +106,7 @@ (mf/set-ref-val! prev-val-ref node))))] - (mf/with-effect [] + (mf/with-layout-effect [] ;; On dismount we need to disconnect the current observer (fn [] (when-let [observer (mf/ref-val observer-ref)] From 259b05db510aedf1661946257944763bfff99672 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 4 Aug 2023 10:45:17 +0200 Subject: [PATCH 3/3] :sparkles: Add more improvements to error reporting --- backend/src/app/loggers/database.clj | 5 ++--- backend/src/app/worker.clj | 20 ++++++-------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/backend/src/app/loggers/database.clj b/backend/src/app/loggers/database.clj index 093175ada..16818e57e 100644 --- a/backend/src/app/loggers/database.clj +++ b/backend/src/app/loggers/database.clj @@ -47,7 +47,7 @@ (assoc :public-uri (cf/get :public-uri)) (assoc :logger/name logger) (assoc :logger/level level) - (dissoc :request/params))] + (dissoc :request/params :value :params :data))] (merge {:context (-> (into (sorted-map) context) (pp/pprint-str :width 200 :length 50 :level 10)) @@ -55,7 +55,7 @@ :hint (or (ex-message cause) @message) :trace (ex/format-throwable cause :data? false :explain? false :header? false :summary? false)} - (when-let [params (:request/params context)] + (when-let [params (or (:request/params context) (:params context))] {:params (pp/pprint-str params :width 200)}) (when-let [value (:value context)] @@ -67,7 +67,6 @@ (when-let [explain (ex/explain data {:level 10 :length 50})] {:explain explain})))) - (defn error-record? [{:keys [::l/level ::l/cause]}] (and (= :error level) diff --git a/backend/src/app/worker.clj b/backend/src/app/worker.clj index e11c68d2a..05c27f7f8 100644 --- a/backend/src/app/worker.clj +++ b/backend/src/app/worker.clj @@ -489,16 +489,8 @@ (l/error :hint "worker: unhandled exception" :cause cause)))))) (defn- get-error-context - [error item] - (let [data (ex-data error)] - (merge - {:hint (ex-message error) - :spec-problems (some->> data ::s/problems (take 10) seq vec) - :spec-value (some->> data ::s/value) - :data (some-> data (dissoc ::s/problems ::s/value ::s/spec)) - :params item} - (when-let [explain (ex/explain data)] - {:spec-explain explain})))) + [_ item] + {:params item}) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CRON @@ -597,10 +589,10 @@ (catch InterruptedException _ (l/debug :hint "cron: task interrupted" :task-id id)) (catch Throwable cause - (l/error :hint "cron: unhandled exception on running task" - ::l/context (get-error-context cause task) - :task-id id - :cause cause)) + (binding [l/*context* (get-error-context cause task)] + (l/error :hint "cron: unhandled exception on running task" + :task-id id + :cause cause))) (finally (when-not (px/interrupted? :current) (schedule-cron-task cfg task))))))