Merge remote-tracking branch 'origin/staging' into develop

This commit is contained in:
alonso.torres 2021-04-05 11:39:31 +02:00
commit 2b66d0ea06
6 changed files with 26 additions and 20 deletions

View file

@ -346,10 +346,12 @@
(defn check-num (defn check-num
"Function that checks if a number is nil or nan. Will return 0 when not "Function that checks if a number is nil or nan. Will return 0 when not
valid and the number otherwise." valid and the number otherwise."
[v] ([v]
(check-num v 0))
([v default]
(if (or (not v) (if (or (not v)
(not (mth/finite? v)) (not (mth/finite? v))
(mth/nan? v)) 0 v)) (mth/nan? v)) default v)))
(defmacro export (defmacro export

View file

@ -547,8 +547,8 @@
(update [_ state] (update [_ state]
(let [id (get-in state [:workspace-local :edition])] (let [id (get-in state [:workspace-local :edition])]
(-> state (-> state
(update-in [:workspace-local :hover] disj id) (update :workspace-local dissoc :edition)
(update :workspace-local dissoc :edition)))))) (cond-> (some? id) (update-in [:workspace-local :edit-path] dissoc id)))))))
(defn get-shape-layer-position (defn get-shape-layer-position
[objects selected attrs] [objects selected attrs]

View file

@ -9,6 +9,7 @@
(ns app.main.ui.workspace.viewport (ns app.main.ui.workspace.viewport
(:require (:require
[app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.main.refs :as refs] [app.main.refs :as refs]
[app.main.ui.context :as ctx] [app.main.ui.context :as ctx]
@ -83,14 +84,15 @@
;; STREAMS ;; STREAMS
move-stream (mf/use-memo #(rx/subject)) move-stream (mf/use-memo #(rx/subject))
zoom (or zoom 1) zoom (d/check-num zoom 1)
drawing-tool (:tool drawing) drawing-tool (:tool drawing)
drawing-obj (:object drawing) drawing-obj (:object drawing)
drawing-path? (and edition (= :draw (get-in edit-path [edition :edit-mode]))) drawing-path? (or (and edition (= :draw (get-in edit-path [edition :edit-mode])))
(and (some? drawing-obj) (= :path (:type drawing-obj))))
text-editing? (and edition (= :text (get-in objects [edition :type]))) text-editing? (and edition (= :text (get-in objects [edition :type])))
on-click (actions/on-click hover selected) on-click (actions/on-click hover selected edition drawing-path?)
on-context-menu (actions/on-context-menu hover) on-context-menu (actions/on-context-menu hover)
on-double-click (actions/on-double-click hover hover-ids drawing-path? objects) on-double-click (actions/on-double-click hover hover-ids drawing-path? objects)
on-drag-enter (actions/on-drag-enter) on-drag-enter (actions/on-drag-enter)
@ -115,7 +117,7 @@
show-draw-area? drawing-obj show-draw-area? drawing-obj
show-gradient-handlers? (= (count selected) 1) show-gradient-handlers? (= (count selected) 1)
show-grids? (contains? layout :display-grid) show-grids? (contains? layout :display-grid)
show-outlines? (and (nil? transform) (not edit-path)) show-outlines? (and (nil? transform) (not edition) (not drawing-obj))
show-pixel-grid? (>= zoom 8) show-pixel-grid? (>= zoom 8)
show-presence? page-id show-presence? page-id
show-prototypes? (= options-mode :prototype) show-prototypes? (= options-mode :prototype)

View file

@ -32,7 +32,7 @@
(defn on-mouse-down (defn on-mouse-down
[{:keys [id blocked hidden type]} drawing-tool text-editing? edition edit-path selected] [{:keys [id blocked hidden type]} drawing-tool text-editing? edition edit-path selected]
(mf/use-callback (mf/use-callback
(mf/deps id blocked hidden type drawing-tool text-editing? edition selected) (mf/deps id blocked hidden type drawing-tool text-editing? edition edit-path selected)
(fn [bevent] (fn [bevent]
(when (dom/class? (dom/get-target bevent) "viewport-controls") (when (dom/class? (dom/get-target bevent) "viewport-controls")
(dom/stop-propagation bevent) (dom/stop-propagation bevent)
@ -63,14 +63,14 @@
(and drawing-tool (not (#{:comments :path} drawing-tool))) (and drawing-tool (not (#{:comments :path} drawing-tool)))
(st/emit! (dd/start-drawing drawing-tool)) (st/emit! (dd/start-drawing drawing-tool))
edit-path (and edit-path (contains? edit-path edition))
;; Handle node select-drawing. NOP at the moment ;; Handle node select-drawing. NOP at the moment
nil nil
(or (not id) (and frame? (not selected?))) (or (not id) (and frame? (not selected?)))
(st/emit! (dw/handle-selection shift?)) (st/emit! (dw/handle-selection shift?))
:else (not drawing-tool)
(st/emit! (when (or shift? (not selected?)) (st/emit! (when (or shift? (not selected?))
(dw/select-shape id shift?)) (dw/select-shape id shift?))
(when (not shift?) (when (not shift?)
@ -119,9 +119,9 @@
(reset! frame-hover nil)))) (reset! frame-hover nil))))
(defn on-click (defn on-click
[hover selected] [hover selected edition drawing-path?]
(mf/use-callback (mf/use-callback
(mf/deps @hover selected) (mf/deps @hover selected edition drawing-path?)
(fn [event] (fn [event]
(when (dom/class? (dom/get-target event) "viewport-controls") (when (dom/class? (dom/get-target event) "viewport-controls")
(let [ctrl? (kbd/ctrl? event) (let [ctrl? (kbd/ctrl? event)
@ -133,7 +133,7 @@
selected? (contains? selected (:id @hover))] selected? (contains? selected (:id @hover))]
(st/emit! (ms/->MouseEvent :click ctrl? shift? alt?)) (st/emit! (ms/->MouseEvent :click ctrl? shift? alt?))
(when (and hovering? (not shift?) (not frame?) (not selected?)) (when (and hovering? (not shift?) (not frame?) (not selected?) (not edition) (not drawing-path?))
(st/emit! (dw/select-shape (:id @hover))))))))) (st/emit! (dw/select-shape (:id @hover)))))))))
(defn on-double-click (defn on-double-click
@ -178,7 +178,8 @@
(mf/use-callback (mf/use-callback
(mf/deps @hover) (mf/deps @hover)
(fn [event] (fn [event]
(when (dom/class? (dom/get-target event) "viewport-controls") (when (or (dom/class? (dom/get-target event) "viewport-controls")
(dom/class? (dom/get-target event) "viewport-selrect"))
(dom/prevent-default event) (dom/prevent-default event)
(let [position (dom/get-client-position event)] (let [position (dom/get-client-position event)]

View file

@ -21,8 +21,9 @@
(mf/defc outline (mf/defc outline
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [shape (unchecked-get props "shape") (let [shape (obj/get props "shape")
zoom (unchecked-get props "zoom") zoom (obj/get props "zoom" 1)
color (unchecked-get props "color") color (unchecked-get props "color")
transform (gsh/transform-matrix shape) transform (gsh/transform-matrix shape)
path? (= :path (:type shape)) path? (= :path (:type shape))

View file

@ -49,7 +49,7 @@
(mf/defc selection-rect [{:keys [transform rect zoom color on-move-selected]}] (mf/defc selection-rect [{:keys [transform rect zoom color on-move-selected]}]
(when rect (when rect
(let [{:keys [x y width height]} rect] (let [{:keys [x y width height]} rect]
[:rect.main [:rect.main.viewport-selrect
{:x x {:x x
:y y :y y
:width width :width width