mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 00:21:40 +02:00
🐛 Fix broken path content on comp-v2 migration
This commit is contained in:
parent
df4be5106b
commit
70b57f92b4
4 changed files with 88 additions and 10 deletions
|
@ -19,6 +19,7 @@
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.rect :as grc]
|
[app.common.geom.rect :as grc]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.geom.shapes.path :as gshp]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
[app.common.types.pages-list :as ctpl]
|
[app.common.types.pages-list :as ctpl]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
|
[app.common.types.shape.path :as ctsp]
|
||||||
[app.common.types.shape.text :as ctsx]
|
[app.common.types.shape.text :as ctsx]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
|
@ -110,6 +112,12 @@
|
||||||
(def valid-text-content?
|
(def valid-text-content?
|
||||||
(sm/lazy-validator ::ctsx/content))
|
(sm/lazy-validator ::ctsx/content))
|
||||||
|
|
||||||
|
(def valid-path-content?
|
||||||
|
(sm/lazy-validator ::ctsp/content))
|
||||||
|
|
||||||
|
(def valid-path-segment?
|
||||||
|
(sm/lazy-validator ::ctsp/segment))
|
||||||
|
|
||||||
(defn- prepare-file-data
|
(defn- prepare-file-data
|
||||||
"Apply some specific migrations or fixes to things that are allowed in v1 but not in v2,
|
"Apply some specific migrations or fixes to things that are allowed in v1 but not in v2,
|
||||||
or that are the result of old bugs."
|
or that are the result of old bugs."
|
||||||
|
@ -271,6 +279,35 @@
|
||||||
(update :pages-index update-vals fix-container)
|
(update :pages-index update-vals fix-container)
|
||||||
(d/update-when :components update-vals fix-container))))
|
(d/update-when :components update-vals fix-container))))
|
||||||
|
|
||||||
|
fix-broken-paths
|
||||||
|
(fn [file-data]
|
||||||
|
(letfn [(fix-container [container]
|
||||||
|
(d/update-when container :objects update-vals fix-shape))
|
||||||
|
|
||||||
|
(fix-shape [shape]
|
||||||
|
(if (and (cfh/path-shape? shape)
|
||||||
|
(seq (:content shape))
|
||||||
|
(not (valid-path-content? (:content shape))))
|
||||||
|
(let [shape (update shape :content fix-path-content)
|
||||||
|
[points selrect] (gshp/content->points+selrect shape (:content shape))]
|
||||||
|
(-> shape
|
||||||
|
(dissoc :bool-content)
|
||||||
|
(dissoc :bool-type)
|
||||||
|
(assoc :points points)
|
||||||
|
(assoc :selrect selrect)))
|
||||||
|
shape))
|
||||||
|
|
||||||
|
(fix-path-content [content]
|
||||||
|
(let [[seg1 :as content] (filterv valid-path-segment? content)]
|
||||||
|
(if (and seg1 (not= :move-to (:command seg1)))
|
||||||
|
(let [params (select-keys (:params seg1) [:x :y])]
|
||||||
|
(into [{:command :move-to :params params}] content))
|
||||||
|
content)))]
|
||||||
|
|
||||||
|
(-> file-data
|
||||||
|
(update :pages-index update-vals fix-container)
|
||||||
|
(d/update-when :components update-vals fix-container))))
|
||||||
|
|
||||||
fix-recent-colors
|
fix-recent-colors
|
||||||
(fn [file-data]
|
(fn [file-data]
|
||||||
;; Remove invalid colors in :recent-colors
|
;; Remove invalid colors in :recent-colors
|
||||||
|
@ -562,6 +599,7 @@
|
||||||
(fix-recent-colors)
|
(fix-recent-colors)
|
||||||
(fix-missing-image-metadata)
|
(fix-missing-image-metadata)
|
||||||
(fix-text-shapes-converted-to-path)
|
(fix-text-shapes-converted-to-path)
|
||||||
|
(fix-broken-paths)
|
||||||
(delete-big-geometry-shapes)
|
(delete-big-geometry-shapes)
|
||||||
(fix-broken-parents)
|
(fix-broken-parents)
|
||||||
(fix-orphan-shapes)
|
(fix-orphan-shapes)
|
||||||
|
|
|
@ -981,6 +981,7 @@
|
||||||
selrect (-> points
|
selrect (-> points
|
||||||
(gco/transform-points points-center transform-inverse)
|
(gco/transform-points points-center transform-inverse)
|
||||||
(grc/points->rect))]
|
(grc/points->rect))]
|
||||||
|
|
||||||
[points selrect]))
|
[points selrect]))
|
||||||
|
|
||||||
(defn open-path?
|
(defn open-path?
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
[app.common.types.shape.export :as ctse]
|
[app.common.types.shape.export :as ctse]
|
||||||
[app.common.types.shape.interactions :as ctsi]
|
[app.common.types.shape.interactions :as ctsi]
|
||||||
[app.common.types.shape.layout :as ctsl]
|
[app.common.types.shape.layout :as ctsl]
|
||||||
|
[app.common.types.shape.path :as ctsp]
|
||||||
[app.common.types.shape.shadow :as ctss]
|
[app.common.types.shape.shadow :as ctss]
|
||||||
[app.common.types.shape.text :as ctsx]
|
[app.common.types.shape.text :as ctsx]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
@ -256,16 +257,7 @@
|
||||||
(sm/define! ::path-attrs
|
(sm/define! ::path-attrs
|
||||||
[:map {:title "PathAttrs"}
|
[:map {:title "PathAttrs"}
|
||||||
[:type [:= :path]]
|
[:type [:= :path]]
|
||||||
[:x {:optional true} [:maybe ::sm/safe-number]]
|
[:content ::ctsp/content]])
|
||||||
[:y {:optional true} [:maybe ::sm/safe-number]]
|
|
||||||
[:width {:optional true} [:maybe ::sm/safe-number]]
|
|
||||||
[:height {:optional true} [:maybe ::sm/safe-number]]
|
|
||||||
[:content
|
|
||||||
{:optional true}
|
|
||||||
[:vector
|
|
||||||
[:map
|
|
||||||
[:command :keyword]
|
|
||||||
[:params {:optional true} [:maybe :map]]]]]])
|
|
||||||
|
|
||||||
(sm/define! ::text-attrs
|
(sm/define! ::text-attrs
|
||||||
[:map {:title "TextAttrs"}
|
[:map {:title "TextAttrs"}
|
||||||
|
|
47
common/src/app/common/types/shape/path.cljc
Normal file
47
common/src/app/common/types/shape/path.cljc
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns app.common.types.shape.path
|
||||||
|
(:require
|
||||||
|
[app.common.schema :as sm]))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; SCHEMA
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(sm/define! ::segment
|
||||||
|
[:multi {:title "PathSegment" :dispatch :command}
|
||||||
|
[:line-to
|
||||||
|
[:map
|
||||||
|
[:command [:= :line-to]]
|
||||||
|
[:params
|
||||||
|
[:map
|
||||||
|
[:x ::sm/safe-number]
|
||||||
|
[:y ::sm/safe-number]]]]]
|
||||||
|
[:close-path
|
||||||
|
[:map
|
||||||
|
[:command [:= :close-path]]]]
|
||||||
|
[:move-to
|
||||||
|
[:map
|
||||||
|
[:command [:= :move-to]]
|
||||||
|
[:params
|
||||||
|
[:map
|
||||||
|
[:x ::sm/safe-number]
|
||||||
|
[:y ::sm/safe-number]]]]]
|
||||||
|
[:curve-to
|
||||||
|
[:map
|
||||||
|
[:command [:= :curve-to]]
|
||||||
|
[:params
|
||||||
|
[:map
|
||||||
|
[:x ::sm/safe-number]
|
||||||
|
[:y ::sm/safe-number]
|
||||||
|
[:c1x ::sm/safe-number]
|
||||||
|
[:c1y ::sm/safe-number]
|
||||||
|
[:c2x ::sm/safe-number]
|
||||||
|
[:c2y ::sm/safe-number]]]]]])
|
||||||
|
|
||||||
|
(sm/define! ::content
|
||||||
|
[:vector ::segment])
|
Loading…
Add table
Add a link
Reference in a new issue