mirror of
https://github.com/penpot/penpot.git
synced 2025-06-09 16:21:40 +02:00
Merge pull request #4661 from penpot/hiru-improve-slot-validation
🐛 Add validate and repair for :misplaced-slot
This commit is contained in:
commit
928fec0903
5 changed files with 54 additions and 3 deletions
|
@ -6,4 +6,4 @@
|
||||||
|
|
||||||
(ns app.common.files.defaults)
|
(ns app.common.files.defaults)
|
||||||
|
|
||||||
(def version 47)
|
(def version 48)
|
||||||
|
|
|
@ -923,6 +923,20 @@
|
||||||
(-> data
|
(-> data
|
||||||
(update :pages-index update-vals update-page))))
|
(update :pages-index update-vals update-page))))
|
||||||
|
|
||||||
|
(defn migrate-up-48
|
||||||
|
[data]
|
||||||
|
(letfn [(fix-shape [shape]
|
||||||
|
(let [swap-slot (ctk/get-swap-slot shape)]
|
||||||
|
(if (and (some? swap-slot)
|
||||||
|
(not (ctk/subcopy-head? shape)))
|
||||||
|
(ctk/remove-swap-slot shape)
|
||||||
|
shape)))
|
||||||
|
|
||||||
|
(update-page [page]
|
||||||
|
(d/update-when page :objects update-vals fix-shape))]
|
||||||
|
(-> data
|
||||||
|
(update :pages-index update-vals update-page))))
|
||||||
|
|
||||||
(def migrations
|
(def migrations
|
||||||
"A vector of all applicable migrations"
|
"A vector of all applicable migrations"
|
||||||
[{:id 2 :migrate-up migrate-up-2}
|
[{:id 2 :migrate-up migrate-up-2}
|
||||||
|
@ -961,4 +975,5 @@
|
||||||
{:id 44 :migrate-up migrate-up-44}
|
{:id 44 :migrate-up migrate-up-44}
|
||||||
{:id 45 :migrate-up migrate-up-45}
|
{:id 45 :migrate-up migrate-up-45}
|
||||||
{:id 46 :migrate-up migrate-up-46}
|
{:id 46 :migrate-up migrate-up-46}
|
||||||
{:id 47 :migrate-up migrate-up-47}])
|
{:id 47 :migrate-up migrate-up-47}
|
||||||
|
{:id 48 :migrate-up migrate-up-48}])
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -130,6 +130,15 @@
|
||||||
(and (some? (:component-id shape))
|
(and (some? (:component-id shape))
|
||||||
(nil? (:component-root shape))))
|
(nil? (:component-root shape))))
|
||||||
|
|
||||||
|
(defn subcopy-head?
|
||||||
|
"Check if this shape is the head of a subinstance that is a copy."
|
||||||
|
[shape]
|
||||||
|
;; This is redundant with the previous one, but may give more security
|
||||||
|
;; in case of bugs.
|
||||||
|
(and (some? (:component-id shape))
|
||||||
|
(nil? (:component-root shape))
|
||||||
|
(some? (:shape-ref shape))))
|
||||||
|
|
||||||
(defn instance-of?
|
(defn instance-of?
|
||||||
[shape file-id component-id]
|
[shape file-id component-id]
|
||||||
(and (some? (:component-id shape))
|
(and (some? (:component-id shape))
|
||||||
|
@ -227,7 +236,6 @@
|
||||||
:shape-ref
|
:shape-ref
|
||||||
:touched))
|
:touched))
|
||||||
|
|
||||||
|
|
||||||
(defn- extract-ids [shape]
|
(defn- extract-ids [shape]
|
||||||
(if (map? shape)
|
(if (map? shape)
|
||||||
(let [current-id (:id shape)
|
(let [current-id (:id shape)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue