0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-13 16:21:57 -05:00

Merge pull request #4161 from penpot/hiru-bugfixes-6

Some bugfixes
This commit is contained in:
Alejandro 2024-02-19 11:46:56 +01:00 committed by GitHub
commit 60173212e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 73 additions and 25 deletions

View file

@ -865,7 +865,7 @@
0)))))
(defn- add-component-for-swap
[shape file-id id-new-component index target-cell keep-props-values]
[shape file-id id-new-component index target-cell keep-props-values {:keys [undo-group]}]
(dm/assert! (uuid? id-new-component))
(dm/assert! (uuid? file-id))
(ptk/reify ::add-component-for-swap
@ -877,6 +877,7 @@
objects (:objects page)
position (gpt/point (:x shape) (:y shape))
changes (-> (pcb/empty-changes it (:id page))
(pcb/set-undo-group undo-group)
(pcb/with-objects objects))
position (-> position (with-meta {:cell target-cell}))
@ -925,10 +926,20 @@
index (find-shape-index objects (:parent-id shape) (:id shape))
;; Store the properties that need to be maintained when the component is swapped
keep-props-values (select-keys shape ctk/swap-keep-attrs)]
(rx/of (dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true})
(add-component-for-swap shape file-id id-new-component index target-cell keep-props-values)
(ptk/data-event :layout/update [(:parent-id shape)]))))))
keep-props-values (select-keys shape ctk/swap-keep-attrs)
undo-id (js/Symbol)
undo-group (uuid/next)]
(rx/of
(dwu/start-undo-transaction undo-id)
(dwsh/delete-shapes nil (d/ordered-set (:id shape)) {:component-swap true
:undo-id undo-id
:undo-group undo-group})
(add-component-for-swap shape file-id id-new-component index target-cell keep-props-values
{:undo-group undo-group})
(ptk/data-event :layout/update [(:parent-id shape)])
(dwu/commit-undo-transaction undo-id))))))
(defn component-multi-swap
"Swaps several components with another one"
@ -946,7 +957,6 @@
(rx/of (dwu/commit-undo-transaction undo-id))
(rx/of (dwsp/open-specialized-panel :component-swap)))))))
(def valid-asset-types
#{:colors :components :typographies})

View file

@ -64,6 +64,11 @@
"<local>"
(str "<" (get-in state [:workspace-libraries file-id :name]) ">")))
(defn pretty-uuid
[uuid]
(let [uuid-str (str uuid)]
(subs uuid-str (- (count uuid-str) 6))))
;; ---- Components and instances creation ----
(defn duplicate-component
@ -1004,7 +1009,10 @@
(defn- add-shape-to-instance
[changes component-shape index component-page container root-instance root-main omit-touched? set-remote-synced?]
(log/info :msg (str "ADD [P] " (:name component-shape)))
(log/info :msg (str "ADD [P " (pretty-uuid (:id container)) "] "
(:name component-shape)
" "
(pretty-uuid (:id component-shape))))
(let [component-parent-shape (ctn/get-shape component-page (:parent-id component-shape))
parent-shape (d/seek #(ctk/is-main-of? component-parent-shape %)
(cfh/get-children-with-self (:objects container)
@ -1075,7 +1083,10 @@
(defn- add-shape-to-main
[changes shape index component component-container page root-instance root-main]
(log/info :msg (str "ADD [C] " (:name shape)))
(log/info :msg (str "ADD [C " (pretty-uuid (:id component-container)) "] "
(:name shape)
" "
(pretty-uuid (:id shape))))
(let [parent-shape (ctn/get-shape page (:parent-id shape))
component-parent-shape (d/seek #(ctk/is-main-of? % parent-shape)
(cfh/get-children-with-self (:objects component-container)
@ -1176,8 +1187,11 @@
(defn- remove-shape
[changes shape container omit-touched?]
(log/info :msg (str "REMOVE-SHAPE "
(if (cfh/page? container) "[P] " "[C] ")
(:name shape)))
(if (cfh/page? container) "[P " "[C ")
(pretty-uuid (:id container)) "] "
(:name shape)
" "
(pretty-uuid (:id shape))))
(let [objects (get container :objects)
parents (cfh/get-parent-ids objects (:id shape))
parent (first parents)
@ -1225,9 +1239,12 @@
(defn- move-shape
[changes shape index-before index-after container omit-touched?]
(log/info :msg (str "MOVE "
(if (cfh/page? container) "[P] " "[C] ")
(if (cfh/page? container) "[P " "[C ")
(pretty-uuid (:id container)) "] "
(:name shape)
" "
(pretty-uuid (:id shape))
" "
index-before
" -> "
index-after))
@ -1263,8 +1280,11 @@
changes
(do
(log/info :msg (str "CHANGE-TOUCHED "
(if (cfh/page? container) "[P] " "[C] ")
(:name dest-shape))
(if (cfh/page? container) "[P " "[C ")
(pretty-uuid (:id container)) "] "
(:name dest-shape)
" "
(pretty-uuid (:id dest-shape)))
:options options)
(let [new-touched (cond
reset-touched?
@ -1298,8 +1318,11 @@
changes
(do
(log/info :msg (str "CHANGE-REMOTE-SYNCED? "
(if (cfh/page? container) "[P] " "[C] ")
(:name shape))
(if (cfh/page? container) "[P " "[C ")
(pretty-uuid (:id container)) "] "
(:name shape)
" "
(pretty-uuid (:id shape)))
:remote-synced remote-synced?)
(-> changes
(update :redo-changes conj (make-change
@ -1327,9 +1350,14 @@
(log/info :msg (str "SYNC "
(:name origin-shape)
" "
(pretty-uuid (:id origin-shape))
" -> "
(if (cfh/page? container) "[P] " "[C] ")
(:name dest-shape)))
(if (cfh/page? container) "[P " "[C ")
(pretty-uuid (:id container)) "] "
(:name dest-shape)
" "
(pretty-uuid (:id dest-shape))))
(let [;; To synchronize geometry attributes we need to make a prior
;; operation, because coordinates are absolute, but we need to

View file

@ -137,22 +137,25 @@
ids-to-hide)))))
[ids []])
undo-id (js/Symbol)]
undo-id (or (:undo-id options) (js/Symbol))]
(rx/concat
(rx/of (dwu/start-undo-transaction undo-id)
(update-shape-flags ids-to-hide {:hidden true}))
(real-delete-shapes file page objects ids-to-delete it components-v2 (:component-swap options))
(real-delete-shapes file page objects ids-to-delete it {:components-v2 components-v2
:ignore-touched (:component-swap options)
:undo-group (:undo-group options)})
(rx/of (dwu/commit-undo-transaction undo-id))))))))
(defn- real-delete-shapes-changes
([file page objects ids it components-v2 ignore-touched]
([file page objects ids it {:keys [undo-group] :as options}]
(let [changes (-> (pcb/empty-changes it (:id page))
(pcb/set-undo-group undo-group)
(pcb/with-page page)
(pcb/with-objects objects)
(pcb/with-library-data file))]
(real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched)))
([changes file page objects ids _it components-v2 ignore-touched]
(real-delete-shapes-changes changes file page objects ids it options)))
([changes file page objects ids _it {:keys [components-v2 ignore-touched]}]
(let [lookup (d/getf objects)
groups-to-unmask
(reduce (fn [group-ids id]
@ -275,12 +278,19 @@
(defn delete-shapes-changes
[changes file page objects ids it components-v2 ignore-touched]
(let [[changes _all-parents] (real-delete-shapes-changes changes file page objects ids it components-v2 ignore-touched)]
(let [[changes _all-parents] (real-delete-shapes-changes changes
file
page
objects
ids
it
{:components-v2 components-v2
:ignore-touched ignore-touched})]
changes))
(defn- real-delete-shapes
[file page objects ids it components-v2 ignore-touched]
(let [[changes all-parents] (real-delete-shapes-changes file page objects ids it components-v2 ignore-touched)
[file page objects ids it options]
(let [[changes all-parents] (real-delete-shapes-changes file page objects ids it options)
undo-id (js/Symbol)]
(rx/of (dwu/start-undo-transaction undo-id)
(dc/detach-comment-thread ids)