Review input validation for plugins

This commit is contained in:
alonso.torres 2024-06-19 11:17:04 +02:00
parent c5c8be4b4a
commit 1794859468
12 changed files with 1532 additions and 497 deletions

View file

@ -14,6 +14,7 @@
[app.main.data.workspace.viewport :as dwv]
[app.main.data.workspace.zoom :as dwz]
[app.main.store :as st]
[app.plugins.utils :as u]
[app.util.object :as obj]))
(deftype ViewportProxy [$plugin]
@ -51,7 +52,14 @@
(fn [_ value]
(let [new-x (obj/get value "x")
new-y (obj/get value "y")]
(when (and (us/safe-number? new-x) (us/safe-number? new-y))
(cond
(not (us/safe-number? new-x))
(u/display-not-valid :center-x new-x)
(not (us/safe-number? new-y))
(u/display-not-valid :center-y new-y)
:else
(let [vb (dm/get-in @st/state [:workspace-local :vbox])
old-x (+ (:x vb) (/ (:width vb) 2))
old-y (+ (:y vb) (/ (:height vb) 2))
@ -68,7 +76,11 @@
(dm/get-in @st/state [:workspace-local :zoom]))
:set
(fn [_ value]
(when (us/safe-number? value)
(cond
(not (us/safe-number? value))
(u/display-not-valid :zoom value)
:else
(let [z (dm/get-in @st/state [:workspace-local :zoom])]
(st/emit! (dwz/set-zoom (/ value z))))))}