From 2950259f971f017f0b50755fffa283f2d6d7dc9a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 24 Jan 2024 15:07:50 +0100 Subject: [PATCH] :bug: Fix invalid text shapes with invalid nodes --- backend/src/app/features/components_v2.clj | 6 ++---- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 23 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 78b02da32..422ef171a 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -205,12 +205,10 @@ fix-misc-shape-issues (fn [file-data] - (letfn [(fix-container - [container] + (letfn [(fix-container [container] (d/update-when container :objects update-vals fix-shape)) - (fix-shape - [shape] + (fix-shape [shape] (cond-> shape ;; Some shapes has invalid gap value (contains? shape :layout-gap) diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index bb448f997..08a590111 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 42) +(def version 43) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 1cc3f4c8b..d2213168c 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -19,6 +19,7 @@ [app.common.geom.shapes.text :as gsht] [app.common.logging :as l] [app.common.math :as mth] + [app.common.schema :as sm] [app.common.svg :as csvg] [app.common.text :as txt] [app.common.types.shape :as cts] @@ -780,3 +781,25 @@ (-> data (update :pages-index update-vals update-container) (update :components update-vals update-container)))) + +(def ^:private valid-fill? + (sm/lazy-validator ::cts/fill)) + +(defmethod migrate 43 + [data] + (letfn [(update-text-node [node] + (-> node + (d/update-when :fills #(filterv valid-fill? %)) + (d/without-nils))) + + (update-object [object] + (if (cfh/text-shape? object) + (update object :content #(txt/transform-nodes identity update-text-node %)) + object)) + + (update-container [container] + (d/update-when container :objects update-vals update-object))] + + (-> data + (update :pages-index update-vals update-container) + (update :components update-vals update-container))))