diff --git a/frontend/src/app/main/data/workspace/drawing.cljs b/frontend/src/app/main/data/workspace/drawing.cljs index 9a3793b10..c4c3a148d 100644 --- a/frontend/src/app/main/data/workspace/drawing.cljs +++ b/frontend/src/app/main/data/workspace/drawing.cljs @@ -38,8 +38,7 @@ (watch [_ _ stream] (rx/merge (when (= tool :path) - (rx/of (start-drawing :path) - (dwc/hide-toolbar))) + (rx/of (start-drawing :path))) (when (= tool :curve) (let [stopper (rx/filter dwc/interrupt? stream)] diff --git a/frontend/src/app/main/data/workspace/edition.cljs b/frontend/src/app/main/data/workspace/edition.cljs index 781629a3f..97edd0649 100644 --- a/frontend/src/app/main/data/workspace/edition.cljs +++ b/frontend/src/app/main/data/workspace/edition.cljs @@ -7,8 +7,7 @@ (ns app.main.data.workspace.edition (:require [app.common.data.macros :as dm] - [app.common.types.shape.layout :as ctl] - [app.main.data.workspace.common :as dwc] + [app.main.data.workspace.path.common :as dwpc] [app.main.data.workspace.state-helpers :as wsh] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -33,25 +32,27 @@ state))) ptk/WatchEvent - (watch [_ state stream] - (let [objects (wsh/lookup-page-objects state)] - (rx/concat - (if (ctl/grid-layout? objects id) - (rx/of (dwc/hide-toolbar)) - (rx/empty)) - (->> stream - (rx/filter interrupt?) - (rx/take 1) - (rx/map (constantly clear-edition-mode)))))))) + (watch [_ _ stream] + (->> stream + (rx/filter interrupt?) + (rx/take 1) + (rx/map clear-edition-mode))))) ;; If these event change modules review /src/app/main/data/workspace/path/undo.cljs -(def clear-edition-mode +(defn clear-edition-mode + [] (ptk/reify ::clear-edition-mode ptk/UpdateEvent (update [_ state] + (-> state + (update :workspace-local dissoc :edition) + (update :workspace-drawing dissoc :tool :object :lock) + (dissoc :workspace-grid-edition))) + + ptk/WatchEvent + (watch [_ state _] (let [id (get-in state [:workspace-local :edition])] - (-> state - (update :workspace-local dissoc :edition) - (dissoc :workspace-grid-edition) - (assoc-in [:workspace-local :hide-toolbar] false) - (cond-> (some? id) (update-in [:workspace-local :edit-path] dissoc id))))))) + (rx/concat + (when (some? id) + (dwpc/finish-path))))))) + diff --git a/frontend/src/app/main/data/workspace/path/drawing.cljs b/frontend/src/app/main/data/workspace/path/drawing.cljs index c5760e99f..af492bc0f 100644 --- a/frontend/src/app/main/data/workspace/path/drawing.cljs +++ b/frontend/src/app/main/data/workspace/path/drawing.cljs @@ -16,7 +16,6 @@ [app.common.types.shape-tree :as ctst] [app.common.types.shape.layout :as ctl] [app.main.data.workspace.changes :as dch] - [app.main.data.workspace.common :as dwc] [app.main.data.workspace.drawing.common :as dwdc] [app.main.data.workspace.edition :as dwe] [app.main.data.workspace.path.changes :as changes] @@ -166,16 +165,16 @@ (ptk/reify ::start-path-from-point ptk/WatchEvent (watch [_ state stream] - (let [stoper (rx/merge - (->> stream - (rx/filter mse/mouse-event?) - (rx/filter mse/mouse-up-event?)) - (->> stream - (rx/filter helpers/end-path-event?))) + (let [stopper (rx/merge + (->> stream + (rx/filter mse/mouse-event?) + (rx/filter mse/mouse-up-event?)) + (->> stream + (rx/filter helpers/end-path-event?))) drag-events (->> (streams/position-stream state) (rx/map #(drag-handler %)) - (rx/take-until stoper))] + (rx/take-until stopper))] (rx/concat (rx/of (add-node position)) (streams/drag-stream @@ -197,16 +196,16 @@ "should be a pointer" (gpt/point? down-event)) - (let [stoper (rx/merge - (->> stream - (rx/filter mse/mouse-event?) - (rx/filter mse/mouse-up-event?)) - (->> stream - (rx/filter helpers/end-path-event?))) + (let [stopper (rx/merge + (->> stream + (rx/filter mse/mouse-event?) + (rx/filter mse/mouse-up-event?)) + (->> stream + (rx/filter helpers/end-path-event?))) drag-events (->> (streams/position-stream state) (rx/map #(drag-handler %)) - (rx/take-until stoper))] + (rx/take-until stopper))] (rx/concat (rx/of (add-node down-event)) (streams/drag-stream @@ -307,10 +306,8 @@ (ptk/reify ::handle-new-shape ptk/UpdateEvent (update [_ state] - (let [id (st/get-path-id state) - shape (cts/setup-shape {:type :path})] + (let [shape (cts/setup-shape {:type :path})] (-> state - (assoc-in [:workspace-local :edit-path id :snap-toggled] false) (update :workspace-drawing assoc :object shape)))) ptk/WatchEvent @@ -357,13 +354,14 @@ (let [id (st/get-path-id state) content (st/get-path state :content) old-content (get-in state [:workspace-local :edit-path id :old-content]) - mode (get-in state [:workspace-local :edit-path id :edit-mode])] - + mode (get-in state [:workspace-local :edit-path id :edit-mode]) + empty-content? (empty? content)] (cond - (not= content old-content) (rx/of (changes/save-path-content) - (start-draw-mode)) + (and (not= content old-content) (not empty-content?)) (rx/of (changes/save-path-content)) (= mode :draw) (rx/of :interrupt) - :else (rx/of (common/finish-path))))))) + :else (rx/of + (common/finish-path) + (dwdc/clear-drawing))))))) (defn change-edit-mode [mode] (ptk/reify ::change-edit-mode @@ -378,8 +376,7 @@ (let [id (st/get-path-id state)] (cond (and id (= :move mode)) (rx/of (common/finish-path)) - (and id (= :draw mode)) (rx/of (dwc/hide-toolbar) - (start-draw-mode)) + (and id (= :draw mode)) (rx/of (start-draw-mode)) :else (rx/empty)))))) (defn reset-last-handler diff --git a/frontend/src/app/main/data/workspace/path/edition.cljs b/frontend/src/app/main/data/workspace/path/edition.cljs index 7053aab62..a10b24b03 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -15,7 +15,6 @@ [app.common.svg.path.shapes-to-path :as upsp] [app.common.svg.path.subpath :as ups] [app.main.data.workspace.changes :as dch] - [app.main.data.workspace.common :as dwc] [app.main.data.workspace.edition :as dwe] [app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.drawing :as drawing] @@ -68,7 +67,7 @@ (let [changes (changes/generate-path-changes it objects page-id shape (:content shape) new-content)] (if (empty? new-content) (rx/of (dch/commit-changes changes) - dwe/clear-edition-mode) + (dwe/clear-edition-mode)) (rx/of (dch/commit-changes changes) (selection/update-selection point-change) (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))))) @@ -319,8 +318,7 @@ (= (ptk/type %) ::start-path-edit)))) interrupt (->> stream (rx/filter #(= % :interrupt)) (rx/take 1))] (rx/concat - (rx/of (dwc/hide-toolbar) - (undo/start-path-undo) + (rx/of (undo/start-path-undo) (drawing/change-edit-mode mode)) (->> interrupt (rx/map #(stop-path-edit id)) diff --git a/frontend/src/app/main/data/workspace/path/shortcuts.cljs b/frontend/src/app/main/data/workspace/path/shortcuts.cljs index 74e095468..653b6659e 100644 --- a/frontend/src/app/main/data/workspace/path/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/path/shortcuts.cljs @@ -8,7 +8,6 @@ (:require [app.main.data.shortcuts :as ds] [app.main.data.workspace :as dw] - [app.main.data.workspace.common :as dwc] [app.main.data.workspace.path :as drp] [app.main.store :as st] [beicon.v2.core :as rx] @@ -24,16 +23,12 @@ (ptk/reify ::esc-pressed ptk/WatchEvent (watch [_ state _] - ;; Not interrupt when we're editing a path + ;; Not interrupt when we're editing a path (let [edition-id (or (get-in state [:workspace-drawing :object :id]) (get-in state [:workspace-local :edition])) - content (get-in state [:workspace-drawing :object :content]) path-edit-mode (get-in state [:workspace-local :edit-path edition-id :edit-mode])] - (if-not (= :draw path-edit-mode) - (rx/of :interrupt) - (if (<= (count content) 1) - (rx/of (dwc/show-toolbar)) - (rx/empty))))))) + (when-not (= :draw path-edit-mode) + (rx/of :interrupt)))))) (def shortcuts {:move-nodes {:tooltip "M" diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index b302655f8..e75b53fc3 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -40,7 +40,7 @@ (rx/of (dch/update-shapes [id] upsp/convert-to-path)) (rx/of (dch/commit-changes changes) (when (empty? new-content) - dwe/clear-edition-mode)))))))))) + (dwe/clear-edition-mode))))))))))) (defn make-corner ([] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index 7d3ee4fec..617d628b3 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -196,8 +196,45 @@ (def context-menu (l/derived :context-menu workspace-local)) -(def toolbar-visibility - (l/derived :hide-toolbar workspace-local)) +(defn path-editing? + "Returns true if we're editing a path or creating a new one." + [state] + (let [selected (dm/get-in state [:workspace-local :selected]) + edition (dm/get-in state [:workspace-local :edition]) + + edit-path? (dm/get-in state [:workspace-local :edit-path edition]) + + drawing (dm/get-in state [:workspace-drawing]) + drawing-obj (:object drawing) + + shape (or drawing-obj (-> selected first)) + shape-id (:id shape) + + single? (= (count selected) 1) + editing? (and (some? shape-id) (some? edition) (= shape-id edition)) + + ;; we need to check if we're drawing a new object + ;; but we're not using the pencil tool. + draw-path? (and (some? drawing-obj) + (cph/path-shape? drawing-obj) + (not= :curve (:tool drawing))) + + path-edition? (or (and single? editing? + (and (not (cph/text-shape? shape)) + (not (cph/frame-shape? shape)))) + draw-path? + edit-path?)] + + path-edition?)) + +(def toolbar-hidden + (l/derived + (fn [state] + (let [visibility (dm/get-in state [:workspace-local :hide-toolbar]) + editing? (path-editing? state) + hidden? (if editing? true visibility)] + hidden?)) + st/state)) ;; page item that it is being edited (def editing-page-item diff --git a/frontend/src/app/main/ui/workspace/right_header.cljs b/frontend/src/app/main/ui/workspace/right_header.cljs index 83b216e73..dd9598e30 100644 --- a/frontend/src/app/main/ui/workspace/right_header.cljs +++ b/frontend/src/app/main/ui/workspace/right_header.cljs @@ -171,7 +171,7 @@ (mf/use-fn (fn [] (st/emit! :interrupt - dw/clear-edition-mode) + (dw/clear-edition-mode)) ;; Delay so anything that launched :interrupt can finish (ts/schedule 100 #(st/emit! (dw/select-for-drawing :comments))))) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs index df56144cb..7eace14e7 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/editor.cljs @@ -122,8 +122,7 @@ (fn [event] (dom/stop-propagation event) (when (kbd/esc? event) - (st/emit! :interrupt) - (st/emit! dw/clear-edition-mode))) + (st/emit! :interrupt (dw/clear-edition-mode)))) on-mount (fn [] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs index d12440b8e..abe2dbdd7 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/layout_container.cljs @@ -1279,7 +1279,7 @@ [:button {:on-click open-grid-help :class (stl/css :help-button)} i/help-refactor] [:button {:class (stl/css :exit-btn) - :on-click #(st/emit! udw/clear-edition-mode)} + :on-click #(st/emit! (udw/clear-edition-mode))} (tr "workspace.layout_grid.editor.options.exit")]] [:div {:class (stl/css :row :first-row)} diff --git a/frontend/src/app/main/ui/workspace/top_toolbar.cljs b/frontend/src/app/main/ui/workspace/top_toolbar.cljs index 10e46f32e..26d056fe4 100644 --- a/frontend/src/app/main/ui/workspace/top_toolbar.cljs +++ b/frontend/src/app/main/ui/workspace/top_toolbar.cljs @@ -33,7 +33,7 @@ on-click (mf/use-fn (fn [] - (st/emit! :interrupt dw/clear-edition-mode) + (st/emit! :interrupt (dw/clear-edition-mode)) (dom/click (mf/ref-val ref)))) on-selected @@ -73,7 +73,7 @@ read-only? (mf/use-ctx ctx/workspace-read-only?) rulers? (mf/deref refs/rulers?) - hide-toolbar? (mf/deref refs/toolbar-visibility) + hide-toolbar? (mf/deref refs/toolbar-hidden) interrupt (mf/use-fn #(st/emit! :interrupt)) @@ -84,8 +84,7 @@ (let [tool (-> (dom/get-current-target event) (dom/get-data "tool") (keyword))] - (st/emit! :interrupt - dw/clear-edition-mode) + (st/emit! :interrupt (dw/clear-edition-mode)) ;; Delay so anything that launched :interrupt can finish (ts/schedule 100 #(st/emit! (dw/select-for-drawing tool)))))) diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index ca982acd7..013a157dc 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -90,7 +90,7 @@ ::dwsp/interrupt) (when (and (not= edition id) (or text-editing? grid-editing?)) - (st/emit! dw/clear-edition-mode)) + (st/emit! (dw/clear-edition-mode))) (when (and (not text-editing?) (not blocked) diff --git a/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs b/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs index 153e59d52..19870dfa6 100644 --- a/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/drawarea.cljs @@ -8,6 +8,7 @@ "Drawing components." (:require [app.common.math :as mth] + [app.common.types.shape :as cts] [app.main.ui.shapes.path :refer [path-shape]] [app.main.ui.workspace.shapes :as shapes] [app.main.ui.workspace.shapes.path.editor :refer [path-editor]] @@ -19,14 +20,16 @@ (mf/defc draw-area [{:keys [shape zoom tool] :as props}] - [:g.draw-area - [:g {:style {:pointer-events "none"}} - [:& shapes/shape-wrapper {:shape shape}]] + ;; Prevent rendering something that it's not a shape. + (when (cts/shape? shape) + [:g.draw-area + [:g {:style {:pointer-events "none"}} + [:& shapes/shape-wrapper {:shape shape}]] - (case tool - :path [:& path-editor {:shape shape :zoom zoom}] - :curve [:& path-shape {:shape shape :zoom zoom}] - #_:default [:& generic-draw-area {:shape shape :zoom zoom}])]) + (case tool + :path [:& path-editor {:shape shape :zoom zoom}] + :curve [:& path-shape {:shape shape :zoom zoom}] + #_:default [:& generic-draw-area {:shape shape :zoom zoom}])])) (mf/defc generic-draw-area [{:keys [shape zoom]}] diff --git a/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs b/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs index 7f9a1af28..745631167 100644 --- a/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/grid_layout_editor.cljs @@ -61,7 +61,7 @@ :on-click #(st/emit! (dwge/locate-board (:id shape)))} (tr "workspace.layout_grid.editor.top-bar.locate")] [:button {:class (stl/css :done-btn) - :on-click #(st/emit! dw/clear-edition-mode)} + :on-click #(st/emit! (dw/clear-edition-mode))} (tr "workspace.layout_grid.editor.top-bar.done")]]]) (mf/defc grid-editor-frame diff --git a/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs b/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs index d7b7776f7..a7937e670 100644 --- a/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/top_bar.cljs @@ -69,7 +69,7 @@ [:& view-only-actions] path-edition? - [:div.viewport-actions + [:div {:class (stl/css :viewport-actions)} [:& path-actions {:shape shape}]] grid-edition?