From e6d80e34b94073d60f071d35d7e2349948e7fefe Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 11 Jan 2023 12:58:37 +0100 Subject: [PATCH] :sparkles: Drawing shapes over flex layout checks its drop index --- .../app/main/data/workspace/drawing/box.cljs | 25 +++++++++++++------ .../main/data/workspace/drawing/curve.cljs | 13 +++++++--- .../app/main/data/workspace/path/drawing.cljs | 12 ++++++--- .../src/app/main/data/workspace/shapes.cljs | 7 +++--- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/frontend/src/app/main/data/workspace/drawing/box.cljs b/frontend/src/app/main/data/workspace/drawing/box.cljs index 39971af7c..54e5456fe 100644 --- a/frontend/src/app/main/data/workspace/drawing/box.cljs +++ b/frontend/src/app/main/data/workspace/drawing/box.cljs @@ -8,11 +8,13 @@ (:require [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] + [app.common.geom.shapes.flex-layout :as gsl] [app.common.math :as mth] [app.common.pages.helpers :as cph] [app.common.types.modifiers :as ctm] [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] + [app.common.types.shape.layout :as ctl] [app.common.uuid :as uuid] [app.main.data.workspace.drawing.common :as common] [app.main.data.workspace.state-helpers :as wsh] @@ -72,23 +74,30 @@ initial (cond-> @ms/mouse-position snap-pixel? gpt/round) - page-id (:current-page-id state) - objects (wsh/lookup-page-objects state page-id) - focus (:workspace-focus-selected state) - zoom (get-in state [:workspace-local :zoom] 1) - fid (ctst/top-nested-frame objects initial) + page-id (:current-page-id state) + objects (wsh/lookup-page-objects state page-id) + focus (:workspace-focus-selected state) + zoom (get-in state [:workspace-local :zoom] 1) + + fid (ctst/top-nested-frame objects initial) + layout? (ctl/layout? objects fid) + drop-index (when layout? (gsl/get-drop-index fid objects initial)) shape (get-in state [:workspace-drawing :object]) shape (-> shape (cts/setup-shape {:x (:x initial) - :y (:y initial) - :width 0.01 - :height 0.01}) + :y (:y initial) + :width 0.01 + :height 0.01}) (cond-> (and (cph/frame-shape? shape) (not= fid uuid/zero)) (assoc :fills [] :hide-in-viewer true)) (assoc :frame-id fid) + + (cond-> (some? drop-index) + (with-meta {:index drop-index})) + (assoc :initialized? true) (assoc :click-draw? true))] (rx/concat diff --git a/frontend/src/app/main/data/workspace/drawing/curve.cljs b/frontend/src/app/main/data/workspace/drawing/curve.cljs index 2206763e1..1f3000eb9 100644 --- a/frontend/src/app/main/data/workspace/drawing/curve.cljs +++ b/frontend/src/app/main/data/workspace/drawing/curve.cljs @@ -6,9 +6,12 @@ (ns app.main.data.workspace.drawing.curve (:require + [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] + [app.common.geom.shapes.flex-layout :as gsl] [app.common.geom.shapes.path :as gsp] [app.common.types.shape-tree :as ctst] + [app.common.types.shape.layout :as ctl] [app.main.data.workspace.drawing.common :as common] [app.main.data.workspace.state-helpers :as wsh] [app.main.streams :as ms] @@ -46,10 +49,14 @@ (let [objects (wsh/lookup-page-objects state) content (get-in state [:workspace-drawing :object :content] []) - position (get-in content [0 :params] nil) - frame-id (ctst/top-nested-frame objects position)] + position (gpt/point (get-in content [0 :params] nil)) + frame-id (ctst/top-nested-frame objects position) + layout? (ctl/layout? objects frame-id) + drop-index (when layout? (gsl/get-drop-index frame-id objects position))] (-> state - (assoc-in [:workspace-drawing :object :frame-id] frame-id)))))) + (assoc-in [:workspace-drawing :object :frame-id] frame-id) + (cond-> (some? drop-index) + (update-in [:workspace-drawing :object] with-meta {:index drop-index}))))))) (defn curve-to-path [{:keys [segments] :as shape}] (let [content (gsp/segments->content segments) diff --git a/frontend/src/app/main/data/workspace/path/drawing.cljs b/frontend/src/app/main/data/workspace/path/drawing.cljs index ad0f5e234..fddb6c914 100644 --- a/frontend/src/app/main/data/workspace/path/drawing.cljs +++ b/frontend/src/app/main/data/workspace/path/drawing.cljs @@ -7,11 +7,13 @@ (ns app.main.data.workspace.path.drawing (:require [app.common.geom.point :as gpt] + [app.common.geom.shapes.flex-layout :as gsl] [app.common.geom.shapes.path :as upg] [app.common.path.commands :as upc] [app.common.path.shapes-to-path :as upsp] [app.common.spec :as us] [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.drawing.common :as dwdc] [app.main.data.workspace.edition :as dwe] @@ -257,10 +259,14 @@ (update [_ state] (let [objects (wsh/lookup-page-objects state) content (get-in state [:workspace-drawing :object :content] []) - position (get-in content [0 :params] nil) - frame-id (ctst/top-nested-frame objects position)] + position (gpt/point (get-in content [0 :params] nil)) + frame-id (ctst/top-nested-frame objects position) + layout? (ctl/layout? objects frame-id) + drop-index (when layout? (gsl/get-drop-index frame-id objects position))] (-> state - (assoc-in [:workspace-drawing :object :frame-id] frame-id)))))) + (assoc-in [:workspace-drawing :object :frame-id] frame-id) + (cond-> (some? drop-index) + (update-in [:workspace-drawing :object] with-meta {:index drop-index}))))))) (defn handle-new-shape-result [shape-id] (ptk/reify ::handle-new-shape-result diff --git a/frontend/src/app/main/data/workspace/shapes.cljs b/frontend/src/app/main/data/workspace/shapes.cljs index 94ab70ebd..4bba01db8 100644 --- a/frontend/src/app/main/data/workspace/shapes.cljs +++ b/frontend/src/app/main/data/workspace/shapes.cljs @@ -96,11 +96,12 @@ objects selected) + index (:index (meta attrs)) changes (-> (pcb/empty-changes it page-id) (pcb/with-objects objects) - (cond-> (some? (:index (meta attrs))) - (pcb/add-object shape {:index (:index (meta attrs))})) - (cond-> (nil? (:index (meta attrs))) + (cond-> (some? index) + (pcb/add-object shape {:index index})) + (cond-> (nil? index) (pcb/add-object shape)) (cond-> (some? (:parent-id attrs)) (pcb/change-parent (:parent-id attrs) [shape])))