mirror of
https://github.com/penpot/penpot.git
synced 2025-07-30 12:28:37 +02:00
✨ Add better validation for recent-color change
This commit is contained in:
parent
52fbc678f3
commit
7e302cd21c
3 changed files with 7 additions and 8 deletions
|
@ -13,6 +13,7 @@
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.desc-native :as smd]
|
[app.common.schema.desc-native :as smd]
|
||||||
|
[app.common.types.color :as ctc]
|
||||||
[app.common.types.colors-list :as ctcl]
|
[app.common.types.colors-list :as ctcl]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.components-list :as ctkl]
|
[app.common.types.components-list :as ctkl]
|
||||||
|
@ -166,7 +167,7 @@
|
||||||
[:add-recent-color
|
[:add-recent-color
|
||||||
[:map {:title "AddRecentColorChange"}
|
[:map {:title "AddRecentColorChange"}
|
||||||
[:type [:= :add-recent-color]]
|
[:type [:= :add-recent-color]]
|
||||||
[:color :any]]]
|
[:color ::ctc/recent-color]]]
|
||||||
|
|
||||||
[:add-media
|
[:add-media
|
||||||
[:map {:title "AddMediaChange"}
|
[:map {:title "AddMediaChange"}
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
[:offset ::sm/safe-number]]]]])
|
[:offset ::sm/safe-number]]]]])
|
||||||
|
|
||||||
(sm/def! ::color
|
(sm/def! ::color
|
||||||
[:map
|
[:map {:title "Color"}
|
||||||
[:id {:optional true} ::sm/uuid]
|
[:id {:optional true} ::sm/uuid]
|
||||||
[:name {:optional true} :string]
|
[:name {:optional true} :string]
|
||||||
[:path {:optional true} [:maybe :string]]
|
[:path {:optional true} [:maybe :string]]
|
||||||
|
@ -83,8 +83,6 @@
|
||||||
[:gradient {:optional true} [:maybe ::gradient]]
|
[:gradient {:optional true} [:maybe ::gradient]]
|
||||||
[:image {:optional true} [:maybe ::image-color]]])
|
[:image {:optional true} [:maybe ::image-color]]])
|
||||||
|
|
||||||
|
|
||||||
;; FIXME: incomplete schema
|
|
||||||
(sm/def! ::recent-color
|
(sm/def! ::recent-color
|
||||||
[:and
|
[:and
|
||||||
[:map {:title "RecentColor"}
|
[:map {:title "RecentColor"}
|
||||||
|
@ -94,10 +92,10 @@
|
||||||
[:image {:optional true} [:maybe ::image-color]]]
|
[:image {:optional true} [:maybe ::image-color]]]
|
||||||
[::sm/contains-any {:strict true} [:color :gradient :image]]])
|
[::sm/contains-any {:strict true} [:color :gradient :image]]])
|
||||||
|
|
||||||
(def color?
|
(def valid-color?
|
||||||
(sm/pred-fn ::color))
|
(sm/pred-fn ::color))
|
||||||
|
|
||||||
(def recent-color?
|
(def valid-recent-color?
|
||||||
(sm/pred-fn ::recent-color))
|
(sm/pred-fn ::recent-color))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
|
|
||||||
(defn add-recent-color
|
(defn add-recent-color
|
||||||
[color]
|
[color]
|
||||||
(dm/assert! (ctc/recent-color? color))
|
(dm/assert! (ctc/valid-recent-color? color))
|
||||||
(ptk/reify ::add-recent-color
|
(ptk/reify ::add-recent-color
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [it _ _]
|
(watch [it _ _]
|
||||||
|
@ -143,7 +143,7 @@
|
||||||
|
|
||||||
(defn update-color
|
(defn update-color
|
||||||
[color file-id]
|
[color file-id]
|
||||||
(dm/assert! (ctc/color? color))
|
(dm/assert! (ctc/valid-color? color))
|
||||||
(dm/assert! (uuid? file-id))
|
(dm/assert! (uuid? file-id))
|
||||||
|
|
||||||
(ptk/reify ::update-color
|
(ptk/reify ::update-color
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue