From a1c9d920ed4bd26a50fd6150c4124b050a9dc8d4 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 29 Oct 2025 09:15:04 +0100 Subject: [PATCH] wip2 --- common/src/app/common/logic/libraries.cljc | 51 +++++++++++++++++-- .../app/main/data/workspace/libraries.cljs | 2 +- frontend/src/debug.cljs | 17 ++++++- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 591859c688..fcf7b0728d 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -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) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 5dceb6818f..d7aa65fc23 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1022,7 +1022,7 @@ (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})) + #_(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 diff --git a/frontend/src/debug.cljs b/frontend/src/debug.cljs index b87b4220ca..c0bb7f2647 100644 --- a/frontend/src/debug.cljs +++ b/frontend/src/debug.cljs @@ -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)) \ No newline at end of file