mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
Merge pull request #2855 from penpot/alotor-migration-fix-frame-id
🐛 Add migration to fix problem with frame-id
This commit is contained in:
commit
f85a731969
5 changed files with 49 additions and 20 deletions
|
@ -9,7 +9,7 @@
|
|||
[app.common.colors :as clr]
|
||||
[app.common.uuid :as uuid]))
|
||||
|
||||
(def file-version 19)
|
||||
(def file-version 20)
|
||||
(def default-color clr/gray-20)
|
||||
(def root uuid/zero)
|
||||
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
(ns app.common.pages.migrations
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.path :as gsp]
|
||||
[app.common.geom.shapes.text :as gsht]
|
||||
[app.common.logging :as l]
|
||||
[app.common.logging :as log]
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
|
@ -23,13 +24,15 @@
|
|||
|
||||
(defmulti migrate :version)
|
||||
|
||||
(log/set-level! :info)
|
||||
|
||||
(defn migrate-data
|
||||
([data] (migrate-data data cp/file-version))
|
||||
([data to-version]
|
||||
(if (= (:version data) to-version)
|
||||
data
|
||||
(let [migrate-fn #(do
|
||||
(l/trace :hint "migrate file" :id (:id %) :version-from %2 :version-to (inc %2))
|
||||
(log/trace :hint "migrate file" :id (:id %) :version-from %2 :version-to (inc %2))
|
||||
(migrate (assoc %1 :version (inc %2))))]
|
||||
(reduce migrate-fn data (range (:version data 0) to-version))))))
|
||||
|
||||
|
@ -427,5 +430,31 @@
|
|||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
(defmethod migrate 20
|
||||
[data]
|
||||
(letfn [(update-object [objects object]
|
||||
(let [frame-id (:frame-id object)
|
||||
calculated-frame-id
|
||||
(or (->> (cph/get-parent-ids objects (:id object))
|
||||
(map (d/getf objects))
|
||||
(d/seek cph/frame-shape?)
|
||||
:id)
|
||||
;; If we cannot find any we let the frame-id as it was before
|
||||
frame-id)]
|
||||
(when (not= frame-id calculated-frame-id)
|
||||
(log/info :hint "Fix wrong frame-id"
|
||||
:shape (:name object)
|
||||
:id (:id object)
|
||||
:current (dm/get-in objects [frame-id :name])
|
||||
:calculated (get-in objects [calculated-frame-id :name])))
|
||||
(assoc object :frame-id calculated-frame-id)))
|
||||
|
||||
(update-container [container]
|
||||
(update container :objects #(update-vals % (partial update-object %))))]
|
||||
|
||||
(-> data
|
||||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
;; TODO: pending to do a migration for delete already not used fill
|
||||
;; and stroke props. This should be done for >1.14.x version.
|
||||
|
|
|
@ -155,21 +155,19 @@
|
|||
[base index-base-a index-base-b]))
|
||||
|
||||
(defn is-shape-over-shape?
|
||||
[objects base-shape-id over-shape-id {:keys [top-frames?]}]
|
||||
[objects base-shape-id over-shape-id]
|
||||
|
||||
(let [[base index-a index-b] (get-base objects base-shape-id over-shape-id)]
|
||||
(cond
|
||||
(= base base-shape-id)
|
||||
(and (not top-frames?)
|
||||
(let [object (get objects base-shape-id)]
|
||||
(or (cph/frame-shape? object)
|
||||
(cph/root-frame? object))))
|
||||
(let [object (get objects base-shape-id)]
|
||||
(or (cph/frame-shape? object)
|
||||
(cph/root-frame? object)))
|
||||
|
||||
(= base over-shape-id)
|
||||
(or top-frames?
|
||||
(let [object (get objects over-shape-id)]
|
||||
(or (not (cph/frame-shape? object))
|
||||
(not (cph/root-frame? object)))))
|
||||
(let [object (get objects over-shape-id)]
|
||||
(or (not (cph/frame-shape? object))
|
||||
(not (cph/root-frame? object))))
|
||||
|
||||
:else
|
||||
(< index-a index-b))))
|
||||
|
@ -183,20 +181,20 @@
|
|||
(let [type-a (dm/get-in objects [id-a :type])
|
||||
type-b (dm/get-in objects [id-b :type])]
|
||||
(cond
|
||||
(and (= :frame type-a) (not= :frame type-b))
|
||||
(if bottom-frames? 1 -1)
|
||||
|
||||
(and (not= :frame type-a) (= :frame type-b))
|
||||
(if bottom-frames? -1 1)
|
||||
|
||||
(and (= :frame type-a) (not= :frame type-b))
|
||||
(if bottom-frames? 1 -1)
|
||||
|
||||
(= id-a id-b)
|
||||
0
|
||||
|
||||
(is-shape-over-shape? objects id-a id-b options)
|
||||
1
|
||||
(is-shape-over-shape? objects id-b id-a)
|
||||
-1
|
||||
|
||||
:else
|
||||
-1)))]
|
||||
1)))]
|
||||
(sort comp ids))))
|
||||
|
||||
(defn frame-id-by-position
|
||||
|
@ -268,7 +266,7 @@
|
|||
(if all-frames?
|
||||
identity
|
||||
(remove :hide-in-viewer)))
|
||||
(sort-z-index objects (get-frames-ids objects) {:top-frames? true}))))
|
||||
(sort-z-index objects (get-frames-ids objects)))))
|
||||
|
||||
(defn start-page-index
|
||||
[objects]
|
||||
|
|
|
@ -432,7 +432,8 @@
|
|||
(or
|
||||
(= uuid/zero id)
|
||||
(and
|
||||
(str/includes? (str/lower (:name shape)) (str/lower search))
|
||||
(or (str/includes? (str/lower (:name shape)) (str/lower search))
|
||||
(str/includes? (dm/str (:id shape)) (str/lower search)))
|
||||
(or
|
||||
(empty? filters)
|
||||
(and
|
||||
|
|
|
@ -243,6 +243,7 @@
|
|||
(filter #(or (empty? focus) (cp/is-in-focus? objects focus %)))
|
||||
(first)
|
||||
(get objects))]
|
||||
|
||||
(reset! hover hover-shape)
|
||||
(reset! hover-ids ids)
|
||||
(reset! hover-top-frame-id (ctt/top-nested-frame objects (deref last-point-ref))))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue