mirror of
https://github.com/penpot/penpot.git
synced 2025-07-11 13:27:16 +02:00
🐛 Add migration for fix undecoded path content
This commit is contained in:
parent
898182e3d5
commit
a2b8f19ff3
7 changed files with 73 additions and 59 deletions
|
@ -1319,18 +1319,35 @@
|
||||||
(d/update-when :components d/update-vals update-container)
|
(d/update-when :components d/update-vals update-container)
|
||||||
(d/without-nils))))
|
(d/without-nils))))
|
||||||
|
|
||||||
(defmethod migrate-data "0003-convert-path-content"
|
(defmethod migrate-data "0003-convert-path-content-v2"
|
||||||
[data _]
|
[data _]
|
||||||
(some-> cfeat/*new* (swap! conj "fdata/path-data"))
|
(some-> cfeat/*new* (swap! conj "fdata/path-data"))
|
||||||
|
|
||||||
(letfn [(update-object [object]
|
(let [decode-segments
|
||||||
(if (or (cfh/bool-shape? object)
|
(sm/decoder path/schema:segments sm/json-transformer)
|
||||||
(cfh/path-shape? object))
|
|
||||||
(update object :content path/content)
|
|
||||||
object))
|
|
||||||
|
|
||||||
(update-container [container]
|
update-object
|
||||||
(d/update-when container :objects d/update-vals update-object))]
|
(fn [object]
|
||||||
|
(if (or (cfh/bool-shape? object)
|
||||||
|
(cfh/path-shape? object))
|
||||||
|
(let [content (get object :content)
|
||||||
|
content (cond
|
||||||
|
(path/content? content)
|
||||||
|
content
|
||||||
|
|
||||||
|
(nil? content)
|
||||||
|
(path/content [])
|
||||||
|
|
||||||
|
:else
|
||||||
|
(-> content
|
||||||
|
(decode-segments)
|
||||||
|
(path/content)))]
|
||||||
|
(assoc object :content content))
|
||||||
|
object))
|
||||||
|
|
||||||
|
update-container
|
||||||
|
(fn [container]
|
||||||
|
(d/update-when container :objects d/update-vals update-object))]
|
||||||
|
|
||||||
(-> data
|
(-> data
|
||||||
(update :pages-index d/update-vals update-container)
|
(update :pages-index d/update-vals update-container)
|
||||||
|
@ -1558,7 +1575,7 @@
|
||||||
"0002-normalize-bool-content-v2"
|
"0002-normalize-bool-content-v2"
|
||||||
"0002-clean-shape-interactions"
|
"0002-clean-shape-interactions"
|
||||||
"0003-fix-root-shape"
|
"0003-fix-root-shape"
|
||||||
"0003-convert-path-content"
|
"0003-convert-path-content-v2"
|
||||||
"0004-clean-shadow-color"
|
"0004-clean-shadow-color"
|
||||||
"0005-deprecate-image-type"
|
"0005-deprecate-image-type"
|
||||||
"0006-fix-old-texts-fills"
|
"0006-fix-old-texts-fills"
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
(def ^:const bool-style-properties bool/style-properties)
|
(def ^:const bool-style-properties bool/style-properties)
|
||||||
(def ^:const default-bool-fills bool/default-fills)
|
(def ^:const default-bool-fills bool/default-fills)
|
||||||
|
|
||||||
|
(def schema:content impl/schema:content)
|
||||||
|
(def schema:segments impl/schema:segments)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; TRANSFORMATIONS
|
;; TRANSFORMATIONS
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -48,9 +51,9 @@
|
||||||
[data]
|
[data]
|
||||||
(impl/from-string data))
|
(impl/from-string data))
|
||||||
|
|
||||||
(defn check-path-content
|
(defn check-content
|
||||||
[content]
|
[content]
|
||||||
(impl/check-content-like content))
|
(impl/check-content content))
|
||||||
|
|
||||||
(defn get-byte-size
|
(defn get-byte-size
|
||||||
"Get byte size of a path content"
|
"Get byte size of a path content"
|
||||||
|
@ -76,7 +79,7 @@
|
||||||
(defn apply-content-modifiers
|
(defn apply-content-modifiers
|
||||||
"Apply delta modifiers over the path content"
|
"Apply delta modifiers over the path content"
|
||||||
[content modifiers]
|
[content modifiers]
|
||||||
(assert (impl/check-content-like content))
|
(assert (impl/check-content content))
|
||||||
|
|
||||||
(letfn [(apply-to-index [content [index params]]
|
(letfn [(apply-to-index [content [index params]]
|
||||||
(if (contains? content index)
|
(if (contains? content index)
|
||||||
|
|
|
@ -507,18 +507,6 @@
|
||||||
(= (:command e1) :move-to))))}
|
(= (:command e1) :move-to))))}
|
||||||
schema:segment])
|
schema:segment])
|
||||||
|
|
||||||
(def schema:content-like
|
|
||||||
[:sequential schema:segment])
|
|
||||||
|
|
||||||
(def check-content-like
|
|
||||||
(sm/check-fn schema:content-like))
|
|
||||||
|
|
||||||
(def check-segment
|
|
||||||
(sm/check-fn schema:segment))
|
|
||||||
|
|
||||||
(def ^:private check-segments
|
|
||||||
(sm/check-fn schema:segments))
|
|
||||||
|
|
||||||
(defn path-data?
|
(defn path-data?
|
||||||
[o]
|
[o]
|
||||||
(instance? PathData o))
|
(instance? PathData o))
|
||||||
|
@ -526,37 +514,43 @@
|
||||||
(declare from-string)
|
(declare from-string)
|
||||||
(declare from-plain)
|
(declare from-plain)
|
||||||
|
|
||||||
;; Mainly used on backend: features/components_v2.clj
|
(def schema:content
|
||||||
(sm/register! ::path/segment schema:segment)
|
(sm/type-schema
|
||||||
(sm/register! ::path/segments schema:segments)
|
{:type ::path/content
|
||||||
|
:compile
|
||||||
|
(fn [_ _ _]
|
||||||
|
(let [decoder (delay (sm/decoder schema:segments sm/json-transformer))
|
||||||
|
generator (->> (sg/generator schema:segments)
|
||||||
|
(sg/filter not-empty)
|
||||||
|
(sg/fmap from-plain))]
|
||||||
|
{:pred path-data?
|
||||||
|
:type-properties
|
||||||
|
{:gen/gen generator
|
||||||
|
:encode/json identity
|
||||||
|
:decode/json (fn [s]
|
||||||
|
(cond
|
||||||
|
(string? s)
|
||||||
|
(from-string s)
|
||||||
|
|
||||||
(sm/register!
|
(vector? s)
|
||||||
{:type ::path/content
|
(let [decode-fn (deref decoder)]
|
||||||
:compile
|
(-> (decode-fn s)
|
||||||
(fn [_ _ _]
|
(from-plain)))
|
||||||
(let [decoder (delay (sm/decoder schema:segments sm/json-transformer))
|
|
||||||
generator (->> (sg/generator schema:segments)
|
|
||||||
(sg/filter not-empty)
|
|
||||||
(sg/fmap from-plain))]
|
|
||||||
{:pred path-data?
|
|
||||||
:type-properties
|
|
||||||
{:gen/gen generator
|
|
||||||
:encode/json identity
|
|
||||||
:decode/json (fn [s]
|
|
||||||
(cond
|
|
||||||
(string? s)
|
|
||||||
(from-string s)
|
|
||||||
|
|
||||||
(vector? s)
|
:else
|
||||||
(let [decode-fn (deref decoder)]
|
s))}}))}))
|
||||||
(-> (decode-fn s)
|
|
||||||
(from-plain)))
|
|
||||||
|
|
||||||
:else
|
(def check-plain-content
|
||||||
s))}}))})
|
(sm/check-fn schema:segments))
|
||||||
|
|
||||||
(def check-path-content
|
(def check-segment
|
||||||
(sm/check-fn ::path/content))
|
(sm/check-fn schema:segment))
|
||||||
|
|
||||||
|
(def ^:private check-segments
|
||||||
|
(sm/check-fn schema:segments))
|
||||||
|
|
||||||
|
(def check-content
|
||||||
|
(sm/check-fn schema:content))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; CONSTRUCTORS & PREDICATES
|
;; CONSTRUCTORS & PREDICATES
|
||||||
|
|
|
@ -246,7 +246,7 @@
|
||||||
[:map {:title "BoolAttrs"}
|
[:map {:title "BoolAttrs"}
|
||||||
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
|
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
|
||||||
[:bool-type [::sm/one-of bool-types]]
|
[:bool-type [::sm/one-of bool-types]]
|
||||||
[:content ::path/content]])
|
[:content path/schema:content]])
|
||||||
|
|
||||||
(def ^:private schema:rect-attrs
|
(def ^:private schema:rect-attrs
|
||||||
[:map {:title "RectAttrs"}])
|
[:map {:title "RectAttrs"}])
|
||||||
|
@ -271,7 +271,7 @@
|
||||||
|
|
||||||
(def ^:private schema:path-attrs
|
(def ^:private schema:path-attrs
|
||||||
[:map {:title "PathAttrs"}
|
[:map {:title "PathAttrs"}
|
||||||
[:content ::path/content]])
|
[:content path/schema:content]])
|
||||||
|
|
||||||
(def ^:private schema:text-attrs
|
(def ^:private schema:text-attrs
|
||||||
[:map {:title "TextAttrs"}
|
[:map {:title "TextAttrs"}
|
||||||
|
|
|
@ -113,10 +113,10 @@
|
||||||
{:num 500})))
|
{:num 500})))
|
||||||
|
|
||||||
(t/deftest shape-path-content-json-roundtrip
|
(t/deftest shape-path-content-json-roundtrip
|
||||||
(let [encode (sm/encoder ::path/content (sm/json-transformer))
|
(let [encode (sm/encoder path/schema:content (sm/json-transformer))
|
||||||
decode (sm/decoder ::path/content (sm/json-transformer))]
|
decode (sm/decoder path/schema:content (sm/json-transformer))]
|
||||||
(smt/check!
|
(smt/check!
|
||||||
(smt/for [path-content (sg/generator ::path/content)]
|
(smt/for [path-content (sg/generator path/schema:content)]
|
||||||
(let [path-content-1 (encode path-content)
|
(let [path-content-1 (encode path-content)
|
||||||
path-content-2 (json-roundtrip path-content-1)
|
path-content-2 (json-roundtrip path-content-1)
|
||||||
path-content-3 (decode path-content-2)]
|
path-content-3 (decode path-content-2)]
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
"Generates changes to update the new content of the shape"
|
"Generates changes to update the new content of the shape"
|
||||||
[it objects page-id shape old-content new-content]
|
[it objects page-id shape old-content new-content]
|
||||||
|
|
||||||
(assert (path/check-path-content old-content))
|
(assert (path/content? old-content))
|
||||||
(assert (path/check-path-content new-content))
|
(assert (path/content? new-content))
|
||||||
|
|
||||||
(let [shape-id (:id shape)
|
(let [shape-id (:id shape)
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [content (some-> (dm/get-in state [:workspace-drawing :object :content])
|
(let [content (some-> (dm/get-in state [:workspace-drawing :object :content])
|
||||||
(path/check-path-content))]
|
(path/check-content))]
|
||||||
(if (> (count content) 1)
|
(if (> (count content) 1)
|
||||||
(assoc-in state [:workspace-drawing :object :initialized?] true)
|
(assoc-in state [:workspace-drawing :object :initialized?] true)
|
||||||
state)))
|
state)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue