diff --git a/frontend/src/app/main/data/workspace/path/changes.cljs b/frontend/src/app/main/data/workspace/path/changes.cljs index 0df544a4f..15c5c6c9b 100644 --- a/frontend/src/app/main/data/workspace/path/changes.cljs +++ b/frontend/src/app/main/data/workspace/path/changes.cljs @@ -6,42 +6,67 @@ (ns app.main.data.workspace.path.changes (:require + [app.common.pages :as cp] [app.common.spec :as us] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.path.helpers :as helpers] [app.main.data.workspace.path.spec :as spec] [app.main.data.workspace.path.state :as st] + [app.main.data.workspace.state-helpers :as wsh] [beicon.core :as rx] [potok.core :as ptk])) (defn generate-path-changes "Generates content changes and the undos for the content given" - [page-id shape old-content new-content] + [objects page-id shape old-content new-content] (us/verify ::spec/content old-content) (us/verify ::spec/content new-content) (let [shape-id (:id shape) + frame-id (:frame-id shape) + parent-id (:parent-id shape) + parent-index (cp/position-on-parent shape-id objects) + [old-points old-selrect] (helpers/content->points+selrect shape old-content) [new-points new-selrect] (helpers/content->points+selrect shape new-content) - rch [{:type :mod-obj - :id shape-id - :page-id page-id - :operations [{:type :set :attr :content :val new-content} - {:type :set :attr :selrect :val new-selrect} - {:type :set :attr :points :val new-points}]} - {:type :reg-objects - :page-id page-id - :shapes [shape-id]}] + rch (if (empty? new-content) + [{:type :del-obj + :id shape-id + :page-id page-id} + {:type :reg-objects + :page-id page-id + :shapes [shape-id]}] - uch [{:type :mod-obj - :id shape-id - :page-id page-id - :operations [{:type :set :attr :content :val old-content} - {:type :set :attr :selrect :val old-selrect} - {:type :set :attr :points :val old-points}]} - {:type :reg-objects - :page-id page-id - :shapes [shape-id]}]] + [{:type :mod-obj + :id shape-id + :page-id page-id + :operations [{:type :set :attr :content :val new-content} + {:type :set :attr :selrect :val new-selrect} + {:type :set :attr :points :val new-points}]} + {:type :reg-objects + :page-id page-id + :shapes [shape-id]}]) + + uch (if (empty? new-content) + [{:type :add-obj + :id shape-id + :obj shape + :page-id page-id + :frame-id frame-id + :parent-id parent-id + :index parent-index} + {:type :reg-objects + :page-id page-id + :shapes [shape-id]}] + [{:type :mod-obj + :id shape-id + :page-id page-id + :operations [{:type :set :attr :content :val old-content} + {:type :set :attr :selrect :val old-selrect} + {:type :set :attr :points :val old-points}]} + {:type :reg-objects + :page-id page-id + :shapes [shape-id]}])] [rch uch])) (defn save-path-content @@ -61,12 +86,13 @@ ptk/WatchEvent (watch [_ state stream] - (let [id (get-in state [:workspace-local :edition]) + (let [objects (wsh/lookup-page-objects state) + id (get-in state [:workspace-local :edition]) old-content (get-in state [:workspace-local :edit-path id :old-content])] (if (some? old-content) (let [shape (get-in state (st/get-path state)) page-id (:current-page-id state) - [rch uch] (generate-path-changes page-id shape old-content (:content shape))] + [rch uch] (generate-path-changes objects page-id shape old-content (:content shape))] (rx/of (dch/commit-changes rch uch {:commit-local? true}))) (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 9911a4b98..ad4f5ce24 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -12,17 +12,18 @@ [app.main.data.workspace.changes :as dch] [app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.common :as common] + [app.main.data.workspace.path.drawing :as drawing] [app.main.data.workspace.path.helpers :as helpers] [app.main.data.workspace.path.selection :as selection] [app.main.data.workspace.path.state :as st] [app.main.data.workspace.path.streams :as streams] - [app.main.data.workspace.path.drawing :as drawing] [app.main.data.workspace.path.undo :as undo] + [app.main.data.workspace.state-helpers :as wsh] [app.main.streams :as ms] [app.util.path.commands :as upc] [app.util.path.geom :as upg] - [app.util.path.tools :as upt] [app.util.path.subpaths :as ups] + [app.util.path.tools :as upt] [beicon.core :as rx] [potok.core :as ptk])) @@ -46,7 +47,9 @@ (ptk/reify ::apply-content-modifiers ptk/WatchEvent (watch [_ state stream] - (let [id (st/get-path-id state) + (let [objects (wsh/lookup-page-objects state) + + id (st/get-path-id state) page-id (:current-page-id state) shape (get-in state (st/get-path state)) content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers]) @@ -58,7 +61,7 @@ new-points (->> new-content upg/content->points) point-change (->> (map hash-map old-points new-points) (reduce merge)) - [rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)] + [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] (rx/of (dch/commit-changes rch uch {:commit-local? true}) (selection/update-selection point-change) diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index eec709971..b1c49f754 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -6,13 +6,14 @@ (ns app.main.data.workspace.path.tools (:require + [app.common.geom.point :as gpt] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.common :as common] [app.main.data.workspace.path.state :as st] - [app.util.path.tools :as upt] + [app.main.data.workspace.state-helpers :as wsh] [app.util.path.subpaths :as ups] - [app.common.geom.point :as gpt] + [app.util.path.tools :as upt] [beicon.core :as rx] [potok.core :as ptk])) @@ -24,14 +25,15 @@ (ptk/reify ::process-path-tool ptk/WatchEvent (watch [_ state stream] - (let [id (st/get-path-id state) + (let [objects (wsh/lookup-page-objects state) + id (st/get-path-id state) page-id (:current-page-id state) shape (get-in state (st/get-path state)) selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) points (or points selected-points) new-content (-> (tool-fn (:content shape) points) (ups/close-subpaths)) - [rch uch] (changes/generate-path-changes page-id shape (:content shape) new-content)] + [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] (rx/of (dch/commit-changes rch uch {:commit-local? true}))))))) (defn make-corner