mirror of
https://github.com/penpot/penpot.git
synced 2026-09-13 15:38:38 +00:00
🐛 Add validate and repair for :misplaced-slot
This commit is contained in:
parent
1b17742fc3
commit
3472359168
@ -460,6 +460,19 @@
|
|||||||
(pcb/with-library-data file-data)
|
(pcb/with-library-data file-data)
|
||||||
(pcb/update-component (:id shape) repair-component))))
|
(pcb/update-component (:id shape) repair-component))))
|
||||||
|
|
||||||
|
(defmethod repair-error :misplaced-slot
|
||||||
|
[_ {:keys [shape page-id] :as error} file-data _]
|
||||||
|
(let [repair-shape
|
||||||
|
(fn [shape]
|
||||||
|
;; Remove the swap slot
|
||||||
|
(log/debug :hint (str " -> remove swap-slot"))
|
||||||
|
(ctk/remove-swap-slot shape))]
|
||||||
|
|
||||||
|
(log/dbg :hint "repairing shape :misplaced-slot" :id (:id shape) :name (:name shape) :page-id page-id)
|
||||||
|
(-> (pcb/empty-changes nil page-id)
|
||||||
|
(pcb/with-file-data file-data)
|
||||||
|
(pcb/update-shapes [(:id shape)] repair-shape))))
|
||||||
|
|
||||||
(defmethod repair-error :missing-slot
|
(defmethod repair-error :missing-slot
|
||||||
[_ {:keys [shape page-id args] :as error} file-data _]
|
[_ {:keys [shape page-id args] :as error} file-data _]
|
||||||
(let [repair-shape
|
(let [repair-shape
|
||||||
|
|||||||
@ -52,6 +52,7 @@
|
|||||||
:not-component-not-allowed
|
:not-component-not-allowed
|
||||||
:component-nil-objects-not-allowed
|
:component-nil-objects-not-allowed
|
||||||
:instance-head-not-frame
|
:instance-head-not-frame
|
||||||
|
:misplaced-slot
|
||||||
:missing-slot})
|
:missing-slot})
|
||||||
|
|
||||||
(def ^:private
|
(def ^:private
|
||||||
@ -287,6 +288,14 @@
|
|||||||
"Shape inside main instance should not have shape-ref"
|
"Shape inside main instance should not have shape-ref"
|
||||||
shape file page)))
|
shape file page)))
|
||||||
|
|
||||||
|
(defn- check-empty-swap-slot
|
||||||
|
"Validate that this shape does not have any swap slot."
|
||||||
|
[shape file page]
|
||||||
|
(when (some? (ctk/get-swap-slot shape))
|
||||||
|
(report-error :misplaced-slot
|
||||||
|
"This shape should not have swap slot"
|
||||||
|
shape file page)))
|
||||||
|
|
||||||
(defn- check-shape-main-root-top
|
(defn- check-shape-main-root-top
|
||||||
"Root shape of a top main instance:
|
"Root shape of a top main instance:
|
||||||
|
|
||||||
@ -298,6 +307,7 @@
|
|||||||
(check-component-main-head shape file page libraries)
|
(check-component-main-head shape file page libraries)
|
||||||
(check-component-root shape file page)
|
(check-component-root shape file page)
|
||||||
(check-component-not-ref shape file page)
|
(check-component-not-ref shape file page)
|
||||||
|
(check-empty-swap-slot shape file page)
|
||||||
(run! #(check-shape % file page libraries :context :main-top) (:shapes shape)))
|
(run! #(check-shape % file page libraries :context :main-top) (:shapes shape)))
|
||||||
|
|
||||||
(defn- check-shape-main-root-nested
|
(defn- check-shape-main-root-nested
|
||||||
@ -309,6 +319,7 @@
|
|||||||
(check-component-main-head shape file page libraries)
|
(check-component-main-head shape file page libraries)
|
||||||
(check-component-not-root shape file page)
|
(check-component-not-root shape file page)
|
||||||
(check-component-not-ref shape file page)
|
(check-component-not-ref shape file page)
|
||||||
|
(check-empty-swap-slot shape file page)
|
||||||
(run! #(check-shape % file page libraries :context :main-nested) (:shapes shape)))
|
(run! #(check-shape % file page libraries :context :main-nested) (:shapes shape)))
|
||||||
|
|
||||||
(defn- check-shape-copy-root-top
|
(defn- check-shape-copy-root-top
|
||||||
@ -323,6 +334,7 @@
|
|||||||
(check-component-not-main-head shape file page libraries)
|
(check-component-not-main-head shape file page libraries)
|
||||||
(check-component-root shape file page)
|
(check-component-root shape file page)
|
||||||
(check-component-ref shape file page libraries)
|
(check-component-ref shape file page libraries)
|
||||||
|
(check-empty-swap-slot shape file page)
|
||||||
(run! #(check-shape % file page libraries :context :copy-top :library-exists library-exists) (:shapes shape))))
|
(run! #(check-shape % file page libraries :context :copy-top :library-exists library-exists) (:shapes shape))))
|
||||||
|
|
||||||
(defn- check-shape-copy-root-nested
|
(defn- check-shape-copy-root-nested
|
||||||
@ -345,6 +357,7 @@
|
|||||||
(check-component-not-main-not-head shape file page)
|
(check-component-not-main-not-head shape file page)
|
||||||
(check-component-not-root shape file page)
|
(check-component-not-root shape file page)
|
||||||
(check-component-not-ref shape file page)
|
(check-component-not-ref shape file page)
|
||||||
|
(check-empty-swap-slot shape file page)
|
||||||
(run! #(check-shape % file page libraries :context :main-any) (:shapes shape)))
|
(run! #(check-shape % file page libraries :context :main-any) (:shapes shape)))
|
||||||
|
|
||||||
(defn- check-shape-copy-not-root
|
(defn- check-shape-copy-not-root
|
||||||
@ -353,6 +366,7 @@
|
|||||||
(check-component-not-main-not-head shape file page)
|
(check-component-not-main-not-head shape file page)
|
||||||
(check-component-not-root shape file page)
|
(check-component-not-root shape file page)
|
||||||
(check-component-ref shape file page libraries)
|
(check-component-ref shape file page libraries)
|
||||||
|
(check-empty-swap-slot shape file page)
|
||||||
(run! #(check-shape % file page libraries :context :copy-any) (:shapes shape)))
|
(run! #(check-shape % file page libraries :context :copy-any) (:shapes shape)))
|
||||||
|
|
||||||
(defn- check-shape-not-component
|
(defn- check-shape-not-component
|
||||||
@ -362,6 +376,7 @@
|
|||||||
(check-component-not-main-not-head shape file page)
|
(check-component-not-main-not-head shape file page)
|
||||||
(check-component-not-root shape file page)
|
(check-component-not-root shape file page)
|
||||||
(check-component-not-ref shape file page)
|
(check-component-not-ref shape file page)
|
||||||
|
(check-empty-swap-slot shape file page)
|
||||||
(run! #(check-shape % file page libraries :context :not-component) (:shapes shape)))
|
(run! #(check-shape % file page libraries :context :not-component) (:shapes shape)))
|
||||||
|
|
||||||
(defn- check-shape
|
(defn- check-shape
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user