mirror of
https://github.com/penpot/penpot.git
synced 2025-12-24 06:58:34 -05:00
Compare commits
2 Commits
develop
...
palba-fix-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1c9d920ed | ||
|
|
a4ca140385 |
@@ -13,6 +13,7 @@
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.files.variant :as cfv]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logging :as log]
|
||||
[app.common.logic.shapes :as cls]
|
||||
@@ -98,6 +99,7 @@
|
||||
(declare update-flex-child-main-attrs)
|
||||
(declare update-flex-child-copy-attrs)
|
||||
(declare reposition-shape)
|
||||
(declare move-shape-to)
|
||||
(declare make-change)
|
||||
|
||||
(defn pretty-file
|
||||
@@ -1976,8 +1978,31 @@
|
||||
[changes current-shape previous-shape current-root prev-root origin-ref-shape container]
|
||||
(let [;; We need to sync only the position relative to the origin of the component.
|
||||
;; (see update-attrs for a full explanation)
|
||||
previous-shape (reposition-shape previous-shape prev-root current-root)
|
||||
touched (get previous-shape :touched #{})]
|
||||
previous-shape (reposition-shape previous-shape prev-root current-root)
|
||||
|
||||
;; Similar for origin-ref-shape, but we don't have the root info, so
|
||||
;; we move it to the coords of previous-shape
|
||||
origin-ref-shape (move-shape-to origin-ref-shape previous-shape)
|
||||
touched (get previous-shape :touched #{})
|
||||
|
||||
|
||||
is-frame? (= (:type current-shape) :frame)
|
||||
fake-shape (when is-frame?
|
||||
(cond-> current-shape
|
||||
(not= (:width previous-shape) (:width origin-ref-shape))
|
||||
(assoc :width (:width previous-shape))
|
||||
(not= (:heigth previous-shape) (:heigth origin-ref-shape))
|
||||
(assoc :heigth (:heigth previous-shape))))
|
||||
selrect (when fake-shape (gsh/shape->rect fake-shape))
|
||||
points (when selrect (grc/rect->points selrect))
|
||||
|
||||
;; _ (prn "")
|
||||
;; _ (prn "")
|
||||
;; _ (prn "=========================")
|
||||
;; _ (prn "current" (:id current-shape) (:x current-shape))
|
||||
;; _ (prn "previous-shape" (:id previous-shape) (:x previous-shape))
|
||||
;; _ (prn "origin-ref-shape" (:id origin-ref-shape) (:x origin-ref-shape))
|
||||
_ (prn "update-attrs-on-switch")]
|
||||
|
||||
(loop [attrs updatable-attrs
|
||||
roperations [{:type :set-touched :touched (:touched previous-shape)}]
|
||||
@@ -2030,7 +2055,7 @@
|
||||
reset-pos-data? (and
|
||||
(not skip-operations?)
|
||||
(cfh/text-shape? previous-shape)
|
||||
(or (= attr :position-data) (= attr :selrect))
|
||||
(= attr :position-data)
|
||||
(not= (:position-data previous-shape) (:position-data current-shape))
|
||||
(touched :geometry-group))
|
||||
|
||||
@@ -2052,6 +2077,12 @@
|
||||
(:content origin-ref-shape)
|
||||
touched)
|
||||
|
||||
(and is-frame? (= attr :points))
|
||||
points
|
||||
|
||||
(and is-frame? (= attr :selrect))
|
||||
selrect
|
||||
|
||||
:else
|
||||
(get previous-shape attr)))
|
||||
|
||||
@@ -2059,6 +2090,9 @@
|
||||
skip-operations? (or skip-operations?
|
||||
(= attr-val (get current-shape attr)))
|
||||
|
||||
debug #(prn "current" (:id current-shape) attr (get current-shape attr) "-->" attr-val)
|
||||
_ (when (not skip-operations?) (debug))
|
||||
|
||||
;; On a text-change, we want to force a position-data reset
|
||||
;; so it's calculated again
|
||||
[roperations uoperations]
|
||||
@@ -2251,6 +2285,17 @@
|
||||
delta (gpt/subtract dest-root-pos origin-root-pos)]
|
||||
(gsh/move shape delta)))
|
||||
|
||||
(defn- move-shape-to
|
||||
[shape dest-shape]
|
||||
(let [shape-pos (fn [shape]
|
||||
(gpt/point (:x shape)
|
||||
(:y shape)))
|
||||
|
||||
pos (shape-pos shape)
|
||||
dest-shape-pos (shape-pos dest-shape)
|
||||
delta (gpt/subtract dest-shape-pos pos)]
|
||||
(gsh/move shape delta)))
|
||||
|
||||
(defn- make-change
|
||||
[container change]
|
||||
(if (cfh/page? container)
|
||||
|
||||
@@ -1018,12 +1018,19 @@
|
||||
(clv/generate-keep-touched changes new-shape shape orig-shapes page libraries ldata)
|
||||
[changes []])
|
||||
update-layout-ids (concat all-parents parents-of-swapped new-children-ids)]
|
||||
(rx/of
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
(dch/commit-changes changes)
|
||||
(ptk/data-event :layout/update {:ids update-layout-ids :undo-group undo-group})
|
||||
(dwu/commit-undo-transaction undo-id)
|
||||
(dws/select-shape (:id new-shape) false))))))
|
||||
(rx/concat
|
||||
(rx/of
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
(dch/commit-changes changes)
|
||||
#_(ptk/data-event :layout/update {:ids update-layout-ids :undo-group undo-group}))
|
||||
;; NOTE: we need to schedule a commit into a
|
||||
;; microtask for ensure that all the scheduled
|
||||
;; microtask of previous events execute before the
|
||||
;; commit (specifically the layout/update)
|
||||
(->> (rx/of (dwu/commit-undo-transaction undo-id)
|
||||
(dws/select-shape (:id new-shape) false))
|
||||
(rx/observe-on :async)
|
||||
(rx/delay 1000)))))))
|
||||
|
||||
(defn component-multi-swap
|
||||
"Swaps several components with another one"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.files.helpers :as cfh]
|
||||
[app.common.files.repair :as cfr]
|
||||
[app.common.files.validate :as cfv]
|
||||
[app.common.json :as json]
|
||||
@@ -113,7 +114,11 @@
|
||||
(defn ^:export logjs
|
||||
([str] (tap (partial logjs str)))
|
||||
([str val]
|
||||
(js/console.log str (json/->js val))
|
||||
(prn (type val))
|
||||
(let [data (json/->js val)
|
||||
_ (prn data)
|
||||
_ (prn (type data))]
|
||||
(js/console.log str data))
|
||||
val))
|
||||
|
||||
(when (exists? js/window)
|
||||
@@ -456,3 +461,13 @@
|
||||
(defn ^:export network-averages
|
||||
[]
|
||||
(.log js/console (clj->js @http/network-averages)))
|
||||
|
||||
|
||||
|
||||
(defn ^:export dump-selected-recursive
|
||||
[]
|
||||
(let [objects (dsh/lookup-page-objects @st/state)
|
||||
id (first (get-selected @st/state))
|
||||
result (cfh/get-children-with-self objects id)]
|
||||
(logjs "selected" result)
|
||||
nil))
|
||||
Reference in New Issue
Block a user