From 493a7680e08eb1c8a343ab0ee9689923b76413ef Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 28 Dec 2021 11:12:33 +0100 Subject: [PATCH] :zap: Improve interactions and after-review fixes --- common/src/app/common/geom/shapes/bool.cljc | 16 ++++++---- frontend/src/app/main/refs.cljs | 13 ++++++-- frontend/src/app/main/store.cljs | 11 +++++-- .../src/app/main/ui/workspace/viewport.cljs | 6 ++-- .../ui/workspace/viewport/interactions.cljs | 30 +++++++++++-------- 5 files changed, 51 insertions(+), 25 deletions(-) diff --git a/common/src/app/common/geom/shapes/bool.cljc b/common/src/app/common/geom/shapes/bool.cljc index 99187a985..4d5bdb401 100644 --- a/common/src/app/common/geom/shapes/bool.cljc +++ b/common/src/app/common/geom/shapes/bool.cljc @@ -15,12 +15,16 @@ (defn calc-bool-content [shape objects] - (->> (:shapes shape) - (map (d/getf objects)) - (filter (comp not :hidden)) - (map #(stp/convert-to-path % objects)) - (mapv :content) - (pb/content-bool (:bool-type shape)))) + + (let [extract-content-xf + (comp (map (d/getf objects)) + (filter (comp not :hidden)) + (map #(stp/convert-to-path % objects)) + (map :content)) + + shapes-content + (into [] extract-content-xf (:shapes shape))] + (pb/content-bool (:bool-type shape) shapes-content))) (defn update-bool-selrect "Calculates the selrect+points for the boolean shape" diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index de3b45362..96432175a 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -116,6 +116,14 @@ :show-distances?]) workspace-local =)) +(def interactions-data + (l/derived #(select-keys % [:editing-interaction-index + :draw-interaction-to + :draw-interaction-to-frame + :move-overlay-to + :move-overlay-index]) + workspace-local =)) + (def local-displacement (l/derived #(select-keys % [:modifiers :selected]) workspace-local =)) @@ -235,9 +243,8 @@ [ids] (let [selector (fn [state] - (let [objects (wsh/lookup-page-objects state) - xform (comp (map (d/getf objects)) (remove nil?))] - (into [] xform ids)))] + (let [objects (wsh/lookup-page-objects state)] + (into [] (keep (d/getf objects)) ids)))] (l/derived selector st/state =))) (defn- set-content-modifiers [state] diff --git a/frontend/src/app/main/store.cljs b/frontend/src/app/main/store.cljs index 78efd738a..35936207d 100644 --- a/frontend/src/app/main/store.cljs +++ b/frontend/src/app/main/store.cljs @@ -46,10 +46,17 @@ (rx/subs #(reset! buffer (vec %)))) buffer)) -(def emit! (partial ptk/emit! state)) +(defn emit! + ([] nil) + ([event] + (ptk/emit! state event) + nil) + ([event & events] + (apply ptk/emit! state (cons event events)) + nil)) (defn emitf [& events] - #(ptk/emit! state events)) + #(apply ptk/emit! state events)) diff --git a/frontend/src/app/main/ui/workspace/viewport.cljs b/frontend/src/app/main/ui/workspace/viewport.cljs index 52bbb14b0..51c288e33 100644 --- a/frontend/src/app/main/ui/workspace/viewport.cljs +++ b/frontend/src/app/main/ui/workspace/viewport.cljs @@ -92,8 +92,7 @@ drawing-tool (:tool drawing) drawing-obj (:object drawing) - xf-select-shape (comp (map (d/getf objects-modified)) (filter some?)) - selected-shapes (into [] xf-select-shape selected) + selected-shapes (into [] (keep (d/getf objects-modified)) selected) selected-frames (into #{} (map :frame-id) selected-shapes) ;; Only when we have all the selected shapes in one frame @@ -329,6 +328,9 @@ (when show-prototypes? [:& interactions/interactions {:selected selected + :zoom zoom + :objects objects-modified + :current-transform transform :hover-disabled? hover-disabled?}]) (when show-selrect? diff --git a/frontend/src/app/main/ui/workspace/viewport/interactions.cljs b/frontend/src/app/main/ui/workspace/viewport/interactions.cljs index de2e50a88..90f120024 100644 --- a/frontend/src/app/main/ui/workspace/viewport/interactions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/interactions.cljs @@ -8,6 +8,7 @@ "Visually show shape interactions in workspace" (:require [app.common.data :as d] + [app.common.geom.shapes :as gsh] [app.common.pages :as cp] [app.common.types.interactions :as cti] [app.main.data.workspace :as dw] @@ -235,18 +236,23 @@ :fill "var(--color-primary)"}]])))) (mf/defc interactions - [{:keys [selected hover-disabled?] :as props}] - (let [local (mf/deref refs/workspace-local) - zoom (mf/deref refs/selected-zoom) - current-transform (:transform local) - objects (mf/deref refs/workspace-page-objects) - active-shapes (filter #(seq (:interactions %)) (vals objects)) - selected-shapes (map #(get objects %) selected) - editing-interaction-index (:editing-interaction-index local) - draw-interaction-to (:draw-interaction-to local) - draw-interaction-to-frame (:draw-interaction-to-frame local) - move-overlay-to (:move-overlay-to local) - move-overlay-index (:move-overlay-index local) + [{:keys [current-transform objects zoom selected hover-disabled?] :as props}] + (let [active-shapes (into [] + (comp (filter #(seq (:interactions %))) + (map gsh/transform-shape)) + (vals objects)) + + selected-shapes (into [] + (comp (map (d/getf objects)) + (map gsh/transform-shape)) + selected) + + {:keys [editing-interaction-index + draw-interaction-to + draw-interaction-to-frame + move-overlay-to + move-overlay-index]} (mf/deref refs/interactions-data) + first-selected (first selected-shapes) calc-level (fn [index interactions]