mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Add migration for fix fills on position-data
Some checks failed
Commit Message Check / Check Commit Message (push) Has been cancelled
Some checks failed
Commit Message Check / Check Commit Message (push) Has been cancelled
This commit is contained in:
@@ -1433,74 +1433,6 @@
|
||||
(update :pages-index d/update-vals update-container)
|
||||
(d/update-when :components d/update-vals update-container))))
|
||||
|
||||
(def ^:private valid-stroke?
|
||||
(sm/lazy-validator cts/schema:stroke))
|
||||
|
||||
(defmethod migrate-data "0007-clear-invalid-strokes-and-fills-v2"
|
||||
[data _]
|
||||
(letfn [(clear-color-image [image]
|
||||
(select-keys image types.color/image-attrs))
|
||||
|
||||
(clear-color-gradient [gradient]
|
||||
(select-keys gradient types.color/gradient-attrs))
|
||||
|
||||
(clear-stroke [stroke]
|
||||
(-> stroke
|
||||
(select-keys cts/stroke-attrs)
|
||||
(d/update-when :stroke-color-gradient clear-color-gradient)
|
||||
(d/update-when :stroke-image clear-color-image)
|
||||
(d/update-when :stroke-style #(if (#{:svg :none} %) :solid %))))
|
||||
|
||||
(fix-strokes [strokes]
|
||||
(->> (map clear-stroke strokes)
|
||||
(filterv valid-stroke?)))
|
||||
|
||||
;; Fixes shapes with nested :fills in the :fills attribute
|
||||
;; introduced in a migration `0006-fix-old-texts-fills` when
|
||||
;; types.text/transform-nodes with identity pred was broken
|
||||
(remove-nested-fills [[fill :as fills]]
|
||||
(if (and (= 1 (count fills))
|
||||
(contains? fill :fills))
|
||||
(:fills fill)
|
||||
fills))
|
||||
|
||||
(clear-fill [fill]
|
||||
(-> fill
|
||||
(select-keys types.fills/fill-attrs)
|
||||
(d/update-when :fill-image clear-color-image)
|
||||
(d/update-when :fill-color-gradient clear-color-gradient)))
|
||||
|
||||
(fix-fills [fills]
|
||||
(->> fills
|
||||
(remove-nested-fills)
|
||||
(map clear-fill)
|
||||
(filterv valid-fill?)))
|
||||
|
||||
(fix-object [object]
|
||||
(-> object
|
||||
(d/update-when :strokes fix-strokes)
|
||||
(d/update-when :fills fix-fills)))
|
||||
|
||||
(fix-text-content [content]
|
||||
(->> content
|
||||
(types.text/transform-nodes types.text/is-content-node? fix-object)
|
||||
(types.text/transform-nodes types.text/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 fix-text-content))))
|
||||
|
||||
(update-container [container]
|
||||
(d/update-when container :objects d/update-vals update-shape))]
|
||||
|
||||
(-> data
|
||||
(update :pages-index d/update-vals update-container)
|
||||
(d/update-when :components d/update-vals update-container))))
|
||||
|
||||
(defmethod migrate-data "0008-fix-library-colors-v4"
|
||||
[data _]
|
||||
(letfn [(clear-color-opacity [color]
|
||||
@@ -1605,6 +1537,76 @@
|
||||
(update :pages-index d/update-vals update-container)
|
||||
(d/update-when :components d/update-vals update-container))))
|
||||
|
||||
(def ^:private valid-stroke?
|
||||
(sm/lazy-validator cts/schema:stroke))
|
||||
|
||||
(defmethod migrate-data "0013-clear-invalid-strokes-and-fills"
|
||||
[data _]
|
||||
(letfn [(clear-color-image [image]
|
||||
(select-keys image types.color/image-attrs))
|
||||
|
||||
(clear-color-gradient [gradient]
|
||||
(select-keys gradient types.color/gradient-attrs))
|
||||
|
||||
(clear-stroke [stroke]
|
||||
(-> stroke
|
||||
(select-keys cts/stroke-attrs)
|
||||
(d/update-when :stroke-color-gradient clear-color-gradient)
|
||||
(d/update-when :stroke-image clear-color-image)
|
||||
(d/update-when :stroke-style #(if (#{:svg :none} %) :solid %))))
|
||||
|
||||
(fix-strokes [strokes]
|
||||
(->> (map clear-stroke strokes)
|
||||
(filterv valid-stroke?)))
|
||||
|
||||
;; Fixes shapes with nested :fills in the :fills attribute
|
||||
;; introduced in a migration `0006-fix-old-texts-fills` when
|
||||
;; types.text/transform-nodes with identity pred was broken
|
||||
(remove-nested-fills [[fill :as fills]]
|
||||
(if (and (= 1 (count fills))
|
||||
(contains? fill :fills))
|
||||
(:fills fill)
|
||||
fills))
|
||||
|
||||
(clear-fill [fill]
|
||||
(-> fill
|
||||
(select-keys types.fills/fill-attrs)
|
||||
(d/update-when :fill-image clear-color-image)
|
||||
(d/update-when :fill-color-gradient clear-color-gradient)))
|
||||
|
||||
(fix-fills [fills]
|
||||
(->> fills
|
||||
(remove-nested-fills)
|
||||
(map clear-fill)
|
||||
(filterv valid-fill?)))
|
||||
|
||||
(fix-object [object]
|
||||
(-> object
|
||||
(d/update-when :strokes fix-strokes)
|
||||
(d/update-when :fills fix-fills)))
|
||||
|
||||
(fix-text-content [content]
|
||||
(->> content
|
||||
(types.text/transform-nodes types.text/is-content-node? fix-object)
|
||||
(types.text/transform-nodes types.text/is-paragraph-set-node? #(dissoc % :fills))))
|
||||
|
||||
(update-shape [object]
|
||||
(-> object
|
||||
(fix-object)
|
||||
(d/update-when :position-data #(mapv fix-object %))
|
||||
|
||||
;; The text shape can also have strokes and fills on
|
||||
;; the text fragments, so we need to fix them there.
|
||||
(cond-> (cfh/text-shape? object)
|
||||
(update :content fix-text-content))))
|
||||
|
||||
(update-container [container]
|
||||
(d/update-when container :objects d/update-vals update-shape))]
|
||||
|
||||
(-> data
|
||||
(update :pages-index d/update-vals update-container)
|
||||
(d/update-when :components d/update-vals update-container))))
|
||||
|
||||
(def available-migrations
|
||||
(into (d/ordered-set)
|
||||
["legacy-2"
|
||||
@@ -1667,10 +1669,10 @@
|
||||
"0004-clean-shadow-color"
|
||||
"0005-deprecate-image-type"
|
||||
"0006-fix-old-texts-fills"
|
||||
"0007-clear-invalid-strokes-and-fills-v2"
|
||||
"0008-fix-library-colors-v4"
|
||||
"0009-clean-library-colors"
|
||||
"0009-add-partial-text-touched-flags"
|
||||
"0010-fix-swap-slots-pointing-non-existent-shapes"
|
||||
"0011-fix-invalid-text-touched-flags"
|
||||
"0012-fix-position-data"]))
|
||||
"0012-fix-position-data"
|
||||
"0013-clear-invalid-strokes-and-fills"]))
|
||||
|
||||
Reference in New Issue
Block a user