diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 34c96cc64a..37b6bc4a14 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1429,7 +1429,7 @@ (def ^:private valid-stroke? (sm/lazy-validator cts/schema:stroke)) -(defmethod migrate-data "0007-clear-invalid-strokes-and-fills" +(defmethod migrate-data "0007-clear-invalid-strokes-and-fills-v2" [data _] (letfn [(clear-color-image [image] (select-keys image types.color/image-attrs)) @@ -1473,13 +1473,18 @@ (d/update-when :strokes fix-strokes) (d/update-when :fills fix-fills))) + (fix-text-content [content] + (->> content + (txt/transform-nodes txt/is-content-node? fix-object) + (txt/transform-nodes txt/is-paragraph-set-node? #(dissoc % :fills)))) + (update-shape [object] (-> object (fix-object) ;; The text shape also can has strokes and fils on the ;; text fragments so we need to fix them there (cond-> (cfh/text-shape? object) - (update :content (partial txt/transform-nodes identity fix-object))))) + (update :content fix-text-content)))) (update-container [container] (d/update-when container :objects d/update-vals update-shape))] @@ -1560,5 +1565,5 @@ "0004-clean-shadow-and-colors" "0005-deprecate-image-type" "0006-fix-old-texts-fills" - "0007-clear-invalid-strokes-and-fills" + "0007-clear-invalid-strokes-and-fills-v2" "0008-fix-library-colors-opacity"])) diff --git a/common/src/app/common/text.cljc b/common/src/app/common/text.cljc index 5c6bcf3131..e2b0e640a6 100644 --- a/common/src/app/common/text.cljc +++ b/common/src/app/common/text.cljc @@ -133,6 +133,10 @@ (and (string? (:text node)) (not= (:text node) ""))) +(defn is-paragraph-set-node? + [node] + (= "paragraph-set" (:type node))) + (defn is-paragraph-node? [node] (= "paragraph" (:type node))) @@ -143,7 +147,17 @@ (defn is-node? [node] - (or (is-text-node? node) (is-paragraph-node? node) (is-root-node? node))) + (or ^boolean (is-text-node? node) + ^boolean (is-paragraph-node? node) + ^boolean (is-paragraph-set-node? node) + ^boolean (is-root-node? node))) + +(defn is-content-node? + "Only matches content nodes, ignoring the paragraph-set nodes." + [node] + (or ^boolean (is-text-node? node) + ^boolean (is-paragraph-node? node) + ^boolean (is-root-node? node))) (defn transform-nodes ([transform root]