From 4e52de90f63cb9fad3835886f54640cf312f526e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 19 Jan 2026 17:43:49 +0100 Subject: [PATCH] WIP --- .../app/main/data/workspace/path/changes.cljs | 8 +-- .../app/main/data/workspace/path/edition.cljs | 64 ++++++++++++++----- .../main/data/workspace/path/selection.cljs | 5 +- .../app/main/data/workspace/path/state.cljs | 2 +- .../app/main/data/workspace/path/tools.cljs | 2 +- 5 files changed, 54 insertions(+), 27 deletions(-) diff --git a/frontend/src/app/main/data/workspace/path/changes.cljs b/frontend/src/app/main/data/workspace/path/changes.cljs index d766487e7e..0b9e0ee538 100644 --- a/frontend/src/app/main/data/workspace/path/changes.cljs +++ b/frontend/src/app/main/data/workspace/path/changes.cljs @@ -17,14 +17,12 @@ (defn generate-path-changes "Generates changes to update the new content of the shape" - [it objects page-id shape old-content new-content] + [it objects page-id shape-id old-content new-content] (assert (path/content? old-content)) (assert (path/content? new-content)) - (let [shape-id (:id shape) - - ;; We set the old values so the update-shapes works + (let [;; We set the old values so the update-shapes works objects (update objects shape-id (fn [shape] @@ -82,7 +80,7 @@ shape (st/get-path state)] (if (and (some? old-content) (some? (:id shape))) - (let [changes (generate-path-changes it objects page-id shape old-content (:content shape))] + (let [changes (generate-path-changes it objects page-id id old-content (:content shape))] (rx/of (dch/commit-changes changes))) (rx/empty))))))) diff --git a/frontend/src/app/main/data/workspace/path/edition.cljs b/frontend/src/app/main/data/workspace/path/edition.cljs index 1210111f71..60056d88bd 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -65,14 +65,45 @@ point-change (->> (map hash-map old-points new-points) (reduce merge))] (when (and (some? new-content) (some? shape)) - (let [changes (changes/generate-path-changes it objects page-id shape (:content shape) new-content)] + (let [changes (changes/generate-path-changes it objects page-id id (:content shape) new-content)] (if (empty? new-content) (rx/of (dch/commit-changes changes) (dwe/clear-edition-mode)) (rx/of (dch/commit-changes changes) - (selection/update-selection point-change) + (selection/update-selection id point-change) (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))))))) + + +(defn apply-content-modifiers2 + [shape-id old-content] + (ptk/reify ::apply-content-modifiers2 + ptk/WatchEvent + (watch [it state _] + (let [ ;; FIXME: hide under getter function under state + content-modifiers + (dm/get-in state [:workspace-local :edit-path shape-id :content-modifiers])] + + (if (nil? content-modifiers) + (rx/of (dwe/clear-edition-mode)) + (let [page-id (get state :current-page-id) + objects (dsh/lookup-page-objects state page-id) + new-content (path/apply-content-modifiers old-content content-modifiers) + point-change (->> (map hash-map + (path.segment/get-points old-content) + (path.segment/get-points new-content)) + (reduce merge)) + changes (changes/generate-path-changes it objects page-id shape-id old-content new-content)] + + (if (empty? new-content) + (rx/of (dch/commit-changes changes) + (dwe/clear-edition-mode)) + (rx/of (dch/commit-changes changes) + (selection/update-selection shape-id point-change) + (fn [state] + (update-in state [:workspace-local :edit-path shape-id] + dissoc :content-modifiers :moving-nodes :moving-handler)))))))))) + (defn modify-content-point [content {dx :x dy :y} modifiers point] (let [point-indices (path.segment/point-indices content point) ;; [indices] @@ -335,22 +366,21 @@ (watch [_ _ _] (rx/of (ptk/data-event :layout/update {:ids [id]}))))) -(defn split-segments - [{:keys [from-p to-p t]}] +(defn- split-segments + [shape-id {:keys [from-p to-p t]}] (ptk/reify ::split-segments - ptk/UpdateEvent - (update [_ state] - (let [id (st/get-path-id state) - content (st/get-path state :content)] - (-> state - (assoc-in [:workspace-local :edit-path id :old-content] content) - (st/set-content (-> content - (path.segment/split-segments #{from-p to-p} t) - (path/content)))))) - ptk/WatchEvent - (watch [_ _ _] - (rx/of (changes/save-path-content {:preserve-move-to true}))))) + (watch [it state _] + (let [page-id (get state :current-page-id) + objects (dsh/lookup-page-objects state page-id) + shape (get objects shape-id) + old-content (get shape :content) + new-content (-> old-content + (path.segment/split-segments #{from-p to-p} t) + (path/content)) + changes (changes/generate-path-changes it objects page-id shape-id old-content new-content)] + + (rx/of (dch/commit-changes changes)))))) (defn create-node-at-position [event] @@ -359,4 +389,4 @@ (watch [_ state _] (let [id (st/get-path-id state)] (rx/of (dwsh/update-shapes [id] path/convert-to-path) - (split-segments event)))))) + (split-segments id event)))))) diff --git a/frontend/src/app/main/data/workspace/path/selection.cljs b/frontend/src/app/main/data/workspace/path/selection.cljs index 81210ab9fb..0c002f749f 100644 --- a/frontend/src/app/main/data/workspace/path/selection.cljs +++ b/frontend/src/app/main/data/workspace/path/selection.cljs @@ -149,12 +149,11 @@ (rx/of (clear-area-selection)))))))) (defn update-selection - [point-change] + [id point-change] (ptk/reify ::update-selection ptk/UpdateEvent (update [_ state] - (let [id (st/get-path-id state) - selected-points (dm/get-in state [:workspace-local :edit-path id :selected-points] #{}) + (let [selected-points (dm/get-in state [:workspace-local :edit-path id :selected-points] #{}) selected-points (into #{} (map point-change) selected-points)] (-> state (assoc-in [:workspace-local :edit-path id :selected-points] selected-points)))))) diff --git a/frontend/src/app/main/data/workspace/path/state.cljs b/frontend/src/app/main/data/workspace/path/state.cljs index 6a89ed127a..1ab0d51a6b 100644 --- a/frontend/src/app/main/data/workspace/path/state.cljs +++ b/frontend/src/app/main/data/workspace/path/state.cljs @@ -10,7 +10,7 @@ [app.common.types.path.shape-to-path :as stp])) (defn get-path-id - "Retrieves the currently editing path id" + "Retrieves the currently editing shape path id" [state] (or (dm/get-in state [:workspace-local :edition]) (dm/get-in state [:workspace-drawing :object :id]))) diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index 0fd108f41c..8a3c8c8438 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -44,7 +44,7 @@ (path/close-subpaths)) changes - (changes/generate-path-changes it objects page-id shape (:content shape) new-content)] + (changes/generate-path-changes it objects page-id (:id shape) (:content shape) new-content)] (rx/concat (rx/of (dwsh/update-shapes [id] path/convert-to-path)