0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-27 23:21:47 -05:00

Add better validation for recent-color change

This commit is contained in:
Andrey Antukh 2023-11-15 16:56:51 +01:00
parent 52fbc678f3
commit 7e302cd21c
3 changed files with 7 additions and 8 deletions

View file

@ -13,6 +13,7 @@
[app.common.geom.shapes :as gsh]
[app.common.schema :as sm]
[app.common.schema.desc-native :as smd]
[app.common.types.color :as ctc]
[app.common.types.colors-list :as ctcl]
[app.common.types.component :as ctk]
[app.common.types.components-list :as ctkl]
@ -166,7 +167,7 @@
[:add-recent-color
[:map {:title "AddRecentColorChange"}
[:type [:= :add-recent-color]]
[:color :any]]]
[:color ::ctc/recent-color]]]
[:add-media
[:map {:title "AddMediaChange"}

View file

@ -70,7 +70,7 @@
[:offset ::sm/safe-number]]]]])
(sm/def! ::color
[:map
[:map {:title "Color"}
[:id {:optional true} ::sm/uuid]
[:name {:optional true} :string]
[:path {:optional true} [:maybe :string]]
@ -83,8 +83,6 @@
[:gradient {:optional true} [:maybe ::gradient]]
[:image {:optional true} [:maybe ::image-color]]])
;; FIXME: incomplete schema
(sm/def! ::recent-color
[:and
[:map {:title "RecentColor"}
@ -94,10 +92,10 @@
[:image {:optional true} [:maybe ::image-color]]]
[::sm/contains-any {:strict true} [:color :gradient :image]]])
(def color?
(def valid-color?
(sm/pred-fn ::color))
(def recent-color?
(def valid-recent-color?
(sm/pred-fn ::recent-color))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -113,7 +113,7 @@
(defn add-recent-color
[color]
(dm/assert! (ctc/recent-color? color))
(dm/assert! (ctc/valid-recent-color? color))
(ptk/reify ::add-recent-color
ptk/WatchEvent
(watch [it _ _]
@ -143,7 +143,7 @@
(defn update-color
[color file-id]
(dm/assert! (ctc/color? color))
(dm/assert! (ctc/valid-color? color))
(dm/assert! (uuid? file-id))
(ptk/reify ::update-color