mirror of
https://github.com/penpot/penpot.git
synced 2026-07-23 06:28:14 +00:00
🐛 Fix plugin API board.guides invalid-schema on set/clear
Setting or clearing `board.guides` from a plugin threw a malli `:malli.core/invalid-schema` for every value, including `[]`. Causes: - `shape.cljs` validated against `[:vector ::ctg/grid]`, but the `:app.common.types.grid/grid` reference is no longer registered (direct schemas replaced the namespaced-keyword registrations). Use the direct var `ctg/schema:grid`, matching every other setter. - `parser.cljs` `parse-frame-guide` returned the `parse-frame-guide-column` / `parse-frame-guide-row` fns instead of calling them with the guide, so column/row guides parsed to a vector containing a function. - `parse-frame-guide-square` used `parse-frame-guide-column-params` instead of the dedicated `parse-frame-guide-square-params`. Adds a regression test parsing column/square guides and validating the result (and an empty vector) against `ctg/schema:grid`. Fixes #9773 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Filip Sajdak <filip.sajdak@siili.com>
This commit is contained in:
parent
8fe835a9cc
commit
76070008c2
@ -336,7 +336,7 @@
|
||||
(d/without-nils
|
||||
{:type (-> (obj/get guide "type") parse-keyword)
|
||||
:display (obj/get guide "display")
|
||||
:params (-> (obj/get guide "params") parse-frame-guide-column-params)})))
|
||||
:params (-> (obj/get guide "params") parse-frame-guide-square-params)})))
|
||||
|
||||
(defn parse-frame-guide
|
||||
[^js guide]
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
(ns frontend-tests.plugins.parser-test
|
||||
(:require
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.types.grid :as ctg]
|
||||
[app.plugins.parser :as parser]
|
||||
[cljs.test :as t :include-macros true]))
|
||||
|
||||
@ -61,3 +63,25 @@
|
||||
(t/is (= :row (:type row)))
|
||||
(t/is (= false (:display row)))
|
||||
(t/is (= :center (get-in row [:params :type])))))
|
||||
|
||||
(t/deftest test-parse-frame-guides
|
||||
;; Regression test for issue #9773.
|
||||
;;
|
||||
;; `parse-frame-guide` returned the parser fns for column/row instead of
|
||||
;; calling them with the guide, and the `board.guides` setter validated
|
||||
;; against an unregistered `::ctg/grid` reference (now `ctg/schema:grid`).
|
||||
;; Parsed guides must be plain maps that validate against the same direct
|
||||
;; schema the setter uses, and clearing (empty input) must validate too.
|
||||
(let [column #js {:type "column" :display true
|
||||
:params #js {:color #js {:color "#DE4762" :opacity 0.2}
|
||||
:type "stretch" :size 12 :gutter 16 :margin 16}}
|
||||
square #js {:type "square" :display true
|
||||
:params #js {:color #js {:color "#DE4762" :opacity 0.2} :size 8}}
|
||||
parsed (parser/parse-frame-guides #js [column square])]
|
||||
(t/is (= :column (-> parsed first :type)))
|
||||
(t/is (= :square (-> parsed second :type)))
|
||||
(t/is (map? (-> parsed first :params)))
|
||||
(t/is (sm/validate [:vector ctg/schema:grid] parsed)))
|
||||
|
||||
(t/testing "clearing guides with an empty vector validates"
|
||||
(t/is (sm/validate [:vector ctg/schema:grid] (parser/parse-frame-guides #js [])))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user