mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
🐛 Fix shape validation schema
This commit is contained in:
parent
166d2b7b68
commit
5b84054eaa
5 changed files with 56 additions and 29 deletions
|
@ -5,6 +5,7 @@
|
|||
promesa.exec.csp/go-loop clojure.core/loop
|
||||
rumext.v2/defc clojure.core/defn
|
||||
promesa.util/with-open clojure.core/with-open
|
||||
app.common.schema.generators/let clojure.core/let
|
||||
app.common.data/export clojure.core/def
|
||||
app.common.data.macros/get-in clojure.core/get-in
|
||||
app.common.data.macros/with-open clojure.core/with-open
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
|
||||
(ns app.common.files.defaults)
|
||||
|
||||
(def version 41)
|
||||
(def version 42)
|
||||
|
|
|
@ -577,21 +577,6 @@
|
|||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
(defmethod migrate 30
|
||||
[data]
|
||||
(letfn [(update-object [object]
|
||||
(if (and (cfh/frame-shape? object)
|
||||
(not (:shapes object)))
|
||||
(assoc object :shapes [])
|
||||
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))))
|
||||
|
||||
(defmethod migrate 31
|
||||
[data]
|
||||
(letfn [(update-object [object]
|
||||
|
@ -778,3 +763,22 @@
|
|||
(-> data
|
||||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
(defmethod migrate 42
|
||||
[data]
|
||||
(letfn [(update-object [object]
|
||||
(if (and (or (cfh/frame-shape? object)
|
||||
(cfh/group-shape? object)
|
||||
(cfh/bool-shape? object))
|
||||
(not (:shapes object)))
|
||||
(assoc object :shapes [])
|
||||
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))))
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app.common.schema.generators
|
||||
(:refer-clojure :exclude [set subseq uuid for filter map])
|
||||
(:refer-clojure :exclude [set subseq uuid for filter map let])
|
||||
#?(:cljs (:require-macros [app.common.schema.generators]))
|
||||
(:require
|
||||
[app.common.schema.registry :as sr]
|
||||
|
@ -37,6 +37,10 @@
|
|||
[& params]
|
||||
`(tp/for-all ~@params))
|
||||
|
||||
(defmacro let
|
||||
[& params]
|
||||
`(tg/let ~@params))
|
||||
|
||||
(defn check!
|
||||
[p & {:keys [num] :or {num 20} :as options}]
|
||||
(tc/quick-check num p (assoc options :reporter-fn default-reporter-fn :max-size 50)))
|
||||
|
@ -124,6 +128,10 @@
|
|||
[f g]
|
||||
(tg/fmap f g))
|
||||
|
||||
(defn mcat
|
||||
[f g]
|
||||
(tg/bind g f))
|
||||
|
||||
(defn tuple
|
||||
[& opts]
|
||||
(apply tg/tuple opts))
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
:bool
|
||||
:rect
|
||||
:path
|
||||
:text
|
||||
:circle
|
||||
:svg-raw
|
||||
:image})
|
||||
|
@ -199,7 +200,7 @@
|
|||
(sm/define! ::group-attrs
|
||||
[:map {:title "GroupAttrs"}
|
||||
[:type [:= :group]]
|
||||
[:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]])
|
||||
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]])
|
||||
|
||||
(sm/define! ::frame-attrs
|
||||
[:map {:title "FrameAttrs"}
|
||||
|
@ -212,7 +213,7 @@
|
|||
(sm/define! ::bool-attrs
|
||||
[:map {:title "BoolAttrs"}
|
||||
[:type [:= :bool]]
|
||||
[:shapes {:optional true} [:maybe [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]]
|
||||
[:shapes [:vector {:gen/max 10 :gen/min 1} ::sm/uuid]]
|
||||
|
||||
;; FIXME: improve this schema
|
||||
[:bool-type :keyword]
|
||||
|
@ -271,63 +272,63 @@
|
|||
(sm/define! ::shape-map
|
||||
[:multi {:dispatch :type :title "Shape"}
|
||||
[:group
|
||||
[:merge {:title "GroupShape"}
|
||||
[:and {:title "GroupShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::group-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:frame
|
||||
[:merge {:title "FrameShape"}
|
||||
[:and {:title "FrameShape"}
|
||||
::minimal-shape-attrs
|
||||
::frame-attrs
|
||||
::ctsl/layout-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:bool
|
||||
[:merge {:title "BoolShape"}
|
||||
[:and {:title "BoolShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::bool-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:rect
|
||||
[:merge {:title "RectShape"}
|
||||
[:and {:title "RectShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::rect-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:circle
|
||||
[:merge {:title "CircleShape"}
|
||||
[:and {:title "CircleShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::circle-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:image
|
||||
[:merge {:title "ImageShape"}
|
||||
[:and {:title "ImageShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::image-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:svg-raw
|
||||
[:merge {:title "SvgRawShape"}
|
||||
[:and {:title "SvgRawShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::svg-raw-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:path
|
||||
[:merge {:title "PathShape"}
|
||||
[:and {:title "PathShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::path-attrs
|
||||
::ctsl/layout-child-attrs]]
|
||||
|
||||
[:text
|
||||
[:merge {:title "TextShape"}
|
||||
[:and {:title "TextShape"}
|
||||
::shape-attrs
|
||||
::minimal-shape-attrs
|
||||
::text-attrs
|
||||
|
@ -336,7 +337,20 @@
|
|||
(sm/define! ::shape
|
||||
[:and
|
||||
{:title "Shape"
|
||||
:gen/gen (->> (sg/generator ::shape-map)
|
||||
:gen/gen (->> (sg/generator ::minimal-shape-attrs)
|
||||
(sg/mcat (fn [{:keys [type] :as shape}]
|
||||
(sg/let [attrs1 (sg/generator ::shape-attrs)
|
||||
attrs2 (case type
|
||||
:text (sg/generator ::text-attrs)
|
||||
:path (sg/generator ::path-attrs)
|
||||
:svg-raw (sg/generator ::svg-raw-attrs)
|
||||
:image (sg/generator ::image-attrs)
|
||||
:circle (sg/generator ::circle-attrs)
|
||||
:rect (sg/generator ::rect-attrs)
|
||||
:bool (sg/generator ::bool-attrs)
|
||||
:group (sg/generator ::group-attrs)
|
||||
:frame (sg/generator ::frame-attrs))]
|
||||
(merge attrs1 shape attrs2))))
|
||||
(sg/fmap map->Shape))}
|
||||
::shape-map
|
||||
[:fn shape?]])
|
||||
|
|
Loading…
Add table
Reference in a new issue