0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Improve shape specs and add missing specs for content.

This commit is contained in:
Andrey Antukh 2022-01-24 23:11:30 +01:00 committed by Alonso Torres
parent 9dfd5c0bcc
commit b4bc30e56f
3 changed files with 50 additions and 22 deletions

View file

@ -95,7 +95,6 @@
(s/def ::color ::spec/color) (s/def ::color ::spec/color)
(s/def ::data ::spec/data) (s/def ::data ::spec/data)
(s/def ::media-object ::spec/media-object) (s/def ::media-object ::spec/media-object)
(s/def ::minimal-shape ::spec/minimal-shape)
(s/def ::page ::spec/page) (s/def ::page ::spec/page)
(s/def ::recent-color ::spec/recent-color) (s/def ::recent-color ::spec/recent-color)
(s/def ::shape-attrs ::spec/shape-attrs) (s/def ::shape-attrs ::spec/shape-attrs)

View file

@ -173,7 +173,6 @@
;; Page Data related ;; Page Data related
(s/def :internal.shape/blocked boolean?) (s/def :internal.shape/blocked boolean?)
(s/def :internal.shape/collapsed boolean?) (s/def :internal.shape/collapsed boolean?)
(s/def :internal.shape/content any?)
(s/def :internal.shape/fill-color string?) (s/def :internal.shape/fill-color string?)
(s/def :internal.shape/fill-opacity ::us/safe-number) (s/def :internal.shape/fill-opacity ::us/safe-number)
@ -277,17 +276,21 @@
:luminosity}) :luminosity})
(s/def ::shape-attrs (s/def ::shape-attrs
(s/keys :opt-un [:internal.shape/selrect (s/keys :req-un [::type ::name]
:opt-un [::id
::component-id
::component-file
::component-root?
::shape-ref
:internal.shape/selrect
:internal.shape/points :internal.shape/points
:internal.shape/blocked :internal.shape/blocked
:internal.shape/collapsed :internal.shape/collapsed
:internal.shape/content
:internal.shape/fill-color :internal.shape/fill-color
:internal.shape/fill-opacity :internal.shape/fill-opacity
:internal.shape/fill-color-gradient :internal.shape/fill-color-gradient
:internal.shape/fill-color-ref-file :internal.shape/fill-color-ref-file
:internal.shape/fill-color-ref-id :internal.shape/fill-color-ref-id
:internal.shape/hide-fill-on-export ;; only for frames
:internal.shape/font-family :internal.shape/font-family
:internal.shape/font-size :internal.shape/font-size
:internal.shape/font-style :internal.shape/font-style
@ -332,22 +335,50 @@
:internal.shape/opacity :internal.shape/opacity
:internal.shape/blend-mode])) :internal.shape/blend-mode]))
(s/def :internal.shape.text/type #{"root" "paragraph-set" "paragraph"})
(s/def :internal.shape.text/children
(s/coll-of :internal.shape.text/content
:kind vector?
:min-count 1))
;; shapes-group is handled differently (s/def :internal.shape.text/text string?)
(s/def :internal.shape.text/key string?)
(s/def ::minimal-shape (s/def :internal.shape.text/content
(s/keys :req-un [::type ::name] (s/or :container
:opt-un [::id])) (s/keys :req-un [:internal.shape.text/type
:internal.shape.text/children]
:opt-un [:internal.shape.text/key])
:content
(s/keys :req-un [:internal.shape.text/text])))
(s/def ::shape (s/def :internal.shape.path/command keyword?)
(s/and ::minimal-shape (s/def :internal.shape.path/params (s/map-of keyword? any?))
::shape-attrs (s/def :internal.shape.path/command-item
(s/keys :opt-un [::id (s/keys :req-un [:internal.shape.path/command
::component-id :internal.shape.path/params]))
::component-file
::component-root?
::shape-ref])))
(s/def :internal.shape.path/content
(s/coll-of :internal.shape.path/command-item :kind vector?))
(defmulti shape-spec :type)
(defmethod shape-spec :default [_]
(s/spec ::shape-attrs))
(defmethod shape-spec :text [_]
(s/and ::shape-attrs
(s/keys :opt-un [:internal.shape.text/content])))
(defmethod shape-spec :path [_]
(s/and ::shape-attrs
(s/keys :opt-un [:internal.shape.path/content])))
(defmethod shape-spec :frame [_]
(s/and ::shape-attrs
(s/keys :opt-un [:internal.shape/hide-fill-on-export])))
(s/def ::shape (s/multi-spec shape-spec :type))
(s/def :internal.page/objects (s/map-of uuid? ::shape)) (s/def :internal.page/objects (s/map-of uuid? ::shape))
(s/def ::page (s/def ::page
@ -356,7 +387,6 @@
::cto/options ::cto/options
:internal.page/objects])) :internal.page/objects]))
(s/def ::recent-color (s/def ::recent-color
(s/keys :opt-un [:internal.color/value (s/keys :opt-un [:internal.color/value
:internal.color/color :internal.color/color

View file

@ -1243,7 +1243,7 @@
(defn update-shape-flags (defn update-shape-flags
[ids {:keys [blocked hidden] :as flags}] [ids {:keys [blocked hidden] :as flags}]
(us/verify (s/coll-of ::us/uuid) ids) (us/verify (s/coll-of ::us/uuid) ids)
(s/assert ::shape-attrs flags) (us/assert ::shape-attrs flags)
(ptk/reify ::update-shape-flags (ptk/reify ::update-shape-flags
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
@ -1445,7 +1445,6 @@
(defn show-shape-context-menu (defn show-shape-context-menu
[{:keys [shape] :as params}] [{:keys [shape] :as params}]
(us/verify (s/nilable ::cp/minimal-shape) shape)
(ptk/reify ::show-shape-context-menu (ptk/reify ::show-shape-context-menu
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
@ -1854,7 +1853,7 @@
(defn paste-text (defn paste-text
[text] [text]
(s/assert string? text) (us/assert string? text)
(ptk/reify ::paste-text (ptk/reify ::paste-text
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]
@ -1883,7 +1882,7 @@
(defn- paste-svg (defn- paste-svg
[text] [text]
(s/assert string? text) (us/assert string? text)
(ptk/reify ::paste-svg (ptk/reify ::paste-svg
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]