From 04f3d99def13e2b6c27242ce20747fcb31a8fa4d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 9 Jan 2024 18:48:09 +0100 Subject: [PATCH] :bug: Fix type inconsistency on gradient type Normalize to keyword and add migration for ensure that all shapes uses the correct type --- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 28 +++++++++++++++++++++ common/src/app/common/types/color.cljc | 2 +- common/src/app/common/types/shape.cljc | 6 ++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index 862330dad0..12e18921eb 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 37) +(def version 38) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 86145dc97f..c5952d5718 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -671,3 +671,31 @@ (defmethod migrate 37 [data] (d/without-nils data)) + +(defmethod migrate 38 + [data] + (letfn [(fix-gradient [{:keys [type] :as gradient}] + (if (string? type) + (assoc gradient :type (keyword type)) + gradient)) + + (update-fill [fill] + (d/update-when fill :fill-color-gradient fix-gradient)) + + (update-object [object] + (d/update-when object :fills #(mapv update-fill %))) + + (update-shape [shape] + (let [shape (update-object shape)] + (if (cfh/text-shape? shape) + (-> shape + (update :content (partial txt/transform-nodes identity update-fill)) + (d/update-when :position-data #(mapv update-object %))) + shape))) + + (update-container [container] + (update container :objects update-vals update-shape))] + + (-> data + (update :pages-index update-vals update-container) + (update :components update-vals update-container)))) diff --git a/common/src/app/common/types/color.cljc b/common/src/app/common/types/color.cljc index 00823c631d..8049628941 100644 --- a/common/src/app/common/types/color.cljc +++ b/common/src/app/common/types/color.cljc @@ -56,7 +56,7 @@ (sm/define! ::gradient [:map {:title "Gradient"} - [:type [::sm/one-of #{:linear :radial "linear" "radial"}]] + [:type [::sm/one-of #{:linear :radial}]] [:start-x ::sm/safe-number] [:start-y ::sm/safe-number] [:end-x ::sm/safe-number] diff --git a/common/src/app/common/types/shape.cljc b/common/src/app/common/types/shape.cljc index fb6df40679..28289219d4 100644 --- a/common/src/app/common/types/shape.cljc +++ b/common/src/app/common/types/shape.cljc @@ -375,8 +375,8 @@ {:frame-id uuid/zero :fills [{:fill-color clr/white :fill-opacity 1}] - :name "Board" :strokes [] + :name "Board" :shapes [] :hide-fill-on-export false}) @@ -390,11 +390,15 @@ (def ^:private minimal-group-attrs {:type :group :name "Group" + :fills [] + :strokes [] :shapes []}) (def ^:private minimal-bool-attrs {:type :bool :name "Bool" + :fills [] + :strokes [] :shapes []}) (def ^:private minimal-text-attrs