0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -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 ::data ::spec/data)
(s/def ::media-object ::spec/media-object)
(s/def ::minimal-shape ::spec/minimal-shape)
(s/def ::page ::spec/page)
(s/def ::recent-color ::spec/recent-color)
(s/def ::shape-attrs ::spec/shape-attrs)

View file

@ -173,7 +173,6 @@
;; Page Data related
(s/def :internal.shape/blocked 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-opacity ::us/safe-number)
@ -277,17 +276,21 @@
:luminosity})
(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/blocked
:internal.shape/collapsed
:internal.shape/content
:internal.shape/fill-color
:internal.shape/fill-opacity
:internal.shape/fill-color-gradient
:internal.shape/fill-color-ref-file
:internal.shape/fill-color-ref-id
:internal.shape/hide-fill-on-export ;; only for frames
:internal.shape/font-family
:internal.shape/font-size
:internal.shape/font-style
@ -332,22 +335,50 @@
:internal.shape/opacity
: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/keys :req-un [::type ::name]
:opt-un [::id]))
(s/def :internal.shape.text/content
(s/or :container
(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/and ::minimal-shape
::shape-attrs
(s/keys :opt-un [::id
::component-id
::component-file
::component-root?
::shape-ref])))
(s/def :internal.shape.path/command keyword?)
(s/def :internal.shape.path/params (s/map-of keyword? any?))
(s/def :internal.shape.path/command-item
(s/keys :req-un [:internal.shape.path/command
:internal.shape.path/params]))
(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 ::page
@ -356,7 +387,6 @@
::cto/options
:internal.page/objects]))
(s/def ::recent-color
(s/keys :opt-un [:internal.color/value
:internal.color/color

View file

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