From 19ea85d9ccb6c12c24a283bede7604487b52b8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Thu, 18 May 2023 11:28:51 +0200 Subject: [PATCH 1/4] :bug: Launch component sync when adding or removing shapes --- common/src/app/common/pages/changes.cljc | 33 +++++++++++++++++-- .../app/main/data/workspace/libraries.cljs | 11 ++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index df19f0829b..4e4a429e5f 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -27,7 +27,8 @@ [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] [app.common.types.typographies-list :as ctyl] - [app.common.types.typography :as ctt])) + [app.common.types.typography :as ctt] + [clojure.set :as set])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; SCHEMAS @@ -665,7 +666,7 @@ (when page-id (let [page (ctpl/get-page file-data page-id) shape-and-parents (map #(ctn/get-shape page %) - (into [id] (cph/get-parent-ids (:objects page) id))) + (cons id (cph/get-parent-ids (:objects page) id))) need-sync? (fn [operation] ; We need to trigger a sync if the shape has changed any ; attribute that participates in components synchronization. @@ -677,6 +678,34 @@ (map :id))] (into #{} xform shape-and-parents)))))) +(defmethod components-changed :mov-objects + [file-data {:keys [page-id _component-id parent-id shapes] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id) + + xform (comp (filter :main-instance?) + (map :id)) + + check-shape + (fn [shape-id others] + (let [all-parents (map (partial ctn/get-shape page) + (concat others (cph/get-parent-ids (:objects page) shape-id)))] + (into #{} xform all-parents)))] + + (reduce #(set/union %1 (check-shape %2 [])) + (check-shape parent-id [parent-id]) + shapes)))) + +(defmethod components-changed :del-obj + [file-data {:keys [id page-id _component-id] :as change}] + (when page-id + (let [page (ctpl/get-page file-data page-id) + shape-and-parents (map (partial ctn/get-shape page) + (cons id (cph/get-parent-ids (:objects page) id))) + xform (comp (filter :main-instance?) + (map :id))] + (into #{} xform shape-and-parents)))) + (defmethod components-changed :default [_ _] nil) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index e86e83235a..afb3fc7cc9 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -871,7 +871,10 @@ workspace-data-s (->> (rx/concat (rx/of nil) - (rx/from-atom refs/workspace-data {:emit-current-value? true}))) + (rx/from-atom refs/workspace-data {:emit-current-value? true})) + ;; Need to get the file data before the change, so deleted shapes + ;; still exist, for example + (rx/buffer 3 1)) change-s (->> stream @@ -880,16 +883,16 @@ (rx/observe-on :async)) check-changes - (fn [[event data]] + (fn [[event [old-data _mid_data _new-data]]] (let [{:keys [changes save-undo? undo-group]} (deref event) - components-changed (reduce #(into %1 (ch/components-changed data %2)) + components-changed (reduce #(into %1 (ch/components-changed old-data %2)) #{} changes)] (when (and (d/not-empty? components-changed) save-undo?) (log/info :msg "DETECTED COMPONENTS CHANGED" :ids (map str components-changed)) (run! st/emit! - (map #(update-component-sync % (:id data) undo-group) + (map #(update-component-sync % (:id old-data) undo-group) components-changed)))))] (when components-v2 From 42a044fd227439ece09e3ef7f3bc99a255e76d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 19 May 2023 11:50:27 +0200 Subject: [PATCH 2/4] :fire: Remove unused code --- .../src/app/main/ui/workspace/effects.cljs | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 frontend/src/app/main/ui/workspace/effects.cljs diff --git a/frontend/src/app/main/ui/workspace/effects.cljs b/frontend/src/app/main/ui/workspace/effects.cljs deleted file mode 100644 index 8210ef068f..0000000000 --- a/frontend/src/app/main/ui/workspace/effects.cljs +++ /dev/null @@ -1,89 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) KALEIDOS INC - -(ns app.main.ui.workspace.effects - (:require - [app.main.data.workspace :as dw] - [app.main.data.workspace.selection :as dws] - [app.main.refs :as refs] - [app.main.store :as st] - [app.util.dom :as dom] - [app.util.keyboard :as kbd] - [rumext.v2 :as mf])) - -(defn use-pointer-enter - [{:keys [id]}] - (mf/use-callback - (mf/deps id) - (fn [] - (st/emit! (dws/change-hover-state id true))))) - -(defn use-pointer-leave - [{:keys [id]}] - (mf/use-callback - (mf/deps id) - (fn [] - (st/emit! (dws/change-hover-state id false))))) - -(defn use-pointer-down - [{:keys [id type blocked]}] - (mf/use-callback - (mf/deps id type blocked) - (fn [event] - (let [selected @refs/selected-shapes - edition @refs/selected-edition - selected? (contains? selected id) - drawing? @refs/selected-drawing-tool - button (.-which (.-nativeEvent event)) - shift? (kbd/shift? event) - - allow-click? (and (not blocked) - (not drawing?) - (not edition))] - - (when (and (= button 1) allow-click?) - (cond - (and (= type :frame) selected?) - (do - (dom/prevent-default event) - (dom/stop-propagation event) - (st/emit! (dw/start-move-selected))) - - (not= type :frame) - (do - (dom/prevent-default event) - (dom/stop-propagation event) - - (let [toggle-selected? (and selected? shift?) - deselect? (and (not selected?) (seq selected) (not shift?))] - (apply - st/emit! - (cond-> [] - ;; Deselect shapes before doing a selection or click outside - deselect? - (conj (dw/deselect-all)) - - ;; Shift click to add a shape to the selection - toggle-selected? - (conj (dw/select-shape id true)) - - ;; Simple click to select - (not selected?) - (conj (dw/select-shape id)) - - ;; Mouse down to start moving a shape - (not= edition id) - (conj (dw/start-move-selected)))))))))))) - -(defn use-double-click - "This effect will consume the event and stop the propagation so double clicks on shapes - will not select the frame" - [{:keys [id]}] - (mf/use-callback - (mf/deps id) - (fn [event] - (dom/stop-propagation event) - (dom/prevent-default event)))) From f73d7111b4f33fbf9c38621295f6f36e2128d825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 19 May 2023 16:38:29 +0200 Subject: [PATCH 3/4] :bug: Avoid crash when renaming a page with double click --- frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs b/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs index e16e787896..be7040ede7 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/sitemap.cljs @@ -49,8 +49,7 @@ (dom/prevent-default event) (dom/stop-propagation event) (when-not workspace-read-only? - (st/emit! (dw/start-rename-page-item id)) - (st/emit! (dw/hide-context-menu))))) + (st/emit! (dw/start-rename-page-item id))))) on-blur (mf/use-callback From 9d5b59e9bba55d03a6b86f32c750efbdf8643e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 22 May 2023 10:57:55 +0200 Subject: [PATCH 4/4] :bug: Fix grouping of undo transactions --- frontend/src/app/main/data/workspace/changes.cljs | 8 ++++---- frontend/src/app/main/data/workspace/libraries.cljs | 3 ++- frontend/src/app/main/data/workspace/transforms.cljs | 1 + frontend/src/app/main/data/workspace/undo.cljs | 11 ++++++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/main/data/workspace/changes.cljs b/frontend/src/app/main/data/workspace/changes.cljs index 94530b4f82..cfa5cb1a9f 100644 --- a/frontend/src/app/main/data/workspace/changes.cljs +++ b/frontend/src/app/main/data/workspace/changes.cljs @@ -172,10 +172,6 @@ [{:keys [redo-changes undo-changes origin save-undo? file-id undo-group tags stack-undo?] :or {save-undo? true stack-undo? false tags #{} undo-group (uuid/next)}}] - (log/debug :msg "commit-changes" - :js/undo-group (str undo-group) - :js/redo-changes redo-changes - :js/undo-changes undo-changes) (let [error (volatile! nil) page-id (:current-page-id @st/state) frames (changed-frames redo-changes (wsh/lookup-page-objects @st/state))] @@ -195,6 +191,10 @@ ptk/UpdateEvent (update [_ state] + (log/info :msg "commit-changes" + :js/undo-group (str undo-group) + :js/redo-changes redo-changes + :js/undo-changes undo-changes) (let [current-file-id (get state :current-file-id) file-id (or file-id current-file-id) path (if (= file-id current-file-id) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index afb3fc7cc9..f71ff34155 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -890,7 +890,8 @@ changes)] (when (and (d/not-empty? components-changed) save-undo?) (log/info :msg "DETECTED COMPONENTS CHANGED" - :ids (map str components-changed)) + :ids (map str components-changed) + :undo-group undo-group) (run! st/emit! (map #(update-component-sync % (:id old-data) undo-group) components-changed)))))] diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 3ea74b6f09..597effcf08 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -376,6 +376,7 @@ (some? id) (d/toggle-selection id shift?))] + ;; Take the first mouse position and start a move or a duplicate (when (or (d/not-empty? selected) (some? id)) (->> ms/mouse-position (rx/map #(gpt/to-vec initial %)) diff --git a/frontend/src/app/main/data/workspace/undo.cljs b/frontend/src/app/main/data/workspace/undo.cljs index 33cad6c230..e552cb50ac 100644 --- a/frontend/src/app/main/data/workspace/undo.cljs +++ b/frontend/src/app/main/data/workspace/undo.cljs @@ -8,10 +8,14 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.logging :as log] [app.common.pages.changes :as cpc] [app.common.schema :as sm] [potok.core :as ptk])) +;; Change this to :info :debug or :trace to debug this module +(log/set-level! :warn) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Undo / Redo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -74,7 +78,9 @@ (-> state (update-in [:workspace-undo :transaction :undo-changes] #(into undo-changes %)) (update-in [:workspace-undo :transaction :redo-changes] #(into % redo-changes)) - (assoc-in [:workspace-undo :transaction :undo-group] undo-group) + (cond-> + (nil? (get-in state [:workspace-undo :transaction :undo-group])) + (assoc-in [:workspace-undo :transaction :undo-group] undo-group)) (assoc-in [:workspace-undo :transaction :tags] tags))) (defn append-undo @@ -107,6 +113,7 @@ (ptk/reify ::start-undo-transaction ptk/UpdateEvent (update [_ state] + (log/info :msg "start-undo-transaction") ;; We commit the old transaction before starting the new one (let [current-tx (get-in state [:workspace-undo :transaction]) pending-tx (get-in state [:workspace-undo :transactions-pending])] @@ -119,12 +126,14 @@ (ptk/reify ::discard-undo-transaction ptk/UpdateEvent (update [_ state] + (log/info :msg "discard-undo-transaction") (update state :workspace-undo dissoc :transaction :transactions-pending)))) (defn commit-undo-transaction [id] (ptk/reify ::commit-undo-transaction ptk/UpdateEvent (update [_ state] + (log/info :msg "commit-undo-transaction") (let [state (update-in state [:workspace-undo :transactions-pending] disj id)] (if (empty? (get-in state [:workspace-undo :transactions-pending])) (-> state