🐛 Fixes some issues with text shape

This commit is contained in:
alonso.torres 2020-12-04 17:35:13 +01:00 committed by Alonso Torres
parent 62d98ad265
commit d0306ac92c
7 changed files with 30 additions and 29 deletions

View file

@ -39,8 +39,6 @@
(watch [_ state stream] (watch [_ state stream]
(let [stoper (rx/filter (ptk/type? ::clear-drawing) stream)] (let [stoper (rx/filter (ptk/type? ::clear-drawing) stream)]
(rx/merge (rx/merge
(rx/of (dws/deselect-all))
(when (= tool :path) (when (= tool :path)
(rx/of (start-drawing :path))) (rx/of (start-drawing :path)))

View file

@ -16,7 +16,7 @@
[clojure.walk :as walk] [clojure.walk :as walk]
[goog.object :as gobj] [goog.object :as gobj]
[potok.core :as ptk] [potok.core :as ptk]
[app.common.geom.shapes :as geom] [app.common.geom.shapes :as gsh]
[app.common.attrs :as attrs] [app.common.attrs :as attrs]
[app.main.data.workspace.common :as dwc] [app.main.data.workspace.common :as dwc]
[app.main.data.workspace.transforms :as dwt] [app.main.data.workspace.transforms :as dwt]
@ -218,32 +218,28 @@
(watch [_ state stream] (watch [_ state stream]
(let [page-id (:current-page-id state) (let [page-id (:current-page-id state)
shape (get-in state [:workspace-data :pages-index page-id :objects id]) shape (get-in state [:workspace-data :pages-index page-id :objects id])
{:keys [selrect grow-type overflow-text]} shape {:keys [selrect grow-type overflow-text]} (gsh/transform-shape shape)
{shape-width :width shape-height :height} selrect {shape-width :width shape-height :height} selrect
undo-transaction (get-in state [:workspace-undo :transaction]) undo-transaction (get-in state [:workspace-undo :transaction])
events (when (and (> new-width 0) (> new-height 0)) events
(cond (cond-> []
(and overflow-text (not= :fixed grow-type)) (and overflow-text (not= :fixed grow-type))
[(update-overflow-text id false)] (conj (update-overflow-text id false))
(and (= :fixed grow-type) (not overflow-text) (> new-height shape-height)) (and (= :fixed grow-type) (not overflow-text) (> new-height shape-height))
[(update-overflow-text id true)] (conj (update-overflow-text id true))
(and (= :fixed grow-type) overflow-text (<= new-height shape-height)) (and (= :fixed grow-type) overflow-text (<= new-height shape-height))
[(update-overflow-text id false)] (conj (update-overflow-text id false))
(and (or (not= shape-width new-width) (and (or (not= shape-width new-width) (not= shape-height new-height))
(not= shape-height new-height)) (= grow-type :auto-width))
(= grow-type :auto-width)) (conj (dwt/update-dimensions [id] :width new-width)
(when (and (pos? shape-width) (dwt/update-dimensions [id] :height new-height))
(pos? shape-height))
[(dwt/update-dimensions [id] :width new-width)
(dwt/update-dimensions [id] :height new-height)])
(and (not= shape-height new-height) (= grow-type :auto-height)) (and (not= shape-height new-height) (= grow-type :auto-height))
(when (pos? shape-height) (conj (dwt/update-dimensions [id] :height new-height)))]
[(dwt/update-dimensions [id] :height new-height)])))]
(if (not (empty? events)) (if (not (empty? events))
(rx/concat (rx/concat

View file

@ -488,5 +488,4 @@
(ptk/reify ::update-dimensions (ptk/reify ::update-dimensions
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
#_(prn "??? update-dimensions" ids attr value)
(rx/of (dwc/update-shapes ids #(gsh/resize-rect % attr value) {:reg-objects? true}))))) (rx/of (dwc/update-shapes ids #(gsh/resize-rect % attr value) {:reg-objects? true})))))

View file

@ -15,7 +15,7 @@
[app.common.pages-helpers :as cph] [app.common.pages-helpers :as cph]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.util.storage :refer [storage]] [app.util.storage :refer [storage]]
[app.util.debug :refer [debug? logjs]])) [app.util.debug :refer [debug? debug-exclude-events logjs]]))
(enable-console-print!) (enable-console-print!)
@ -43,7 +43,8 @@
(defonce debug-subscription (defonce debug-subscription
(->> stream (->> stream
(rx/filter ptk/event?) (rx/filter ptk/event?)
(rx/filter (fn [s] (debug? :events))) (rx/filter (fn [s] (and (debug? :events)
(not (debug-exclude-events (ptk/type s))))))
(rx/subs #(println "[stream]: " (repr-event %)))))) (rx/subs #(println "[stream]: " (repr-event %))))))
(defn emit! (defn emit!
([] nil) ([] nil)

View file

@ -48,7 +48,7 @@
(mf/defc text-wrapper (mf/defc text-wrapper
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [{:keys [id name x y width height] :as shape} (unchecked-get props "shape") (let [{:keys [id name x y width height grow-type] :as shape} (unchecked-get props "shape")
selected-iref (mf/use-memo (mf/deps (:id shape)) selected-iref (mf/use-memo (mf/deps (:id shape))
#(refs/make-selected-ref (:id shape))) #(refs/make-selected-ref (:id shape)))
selected? (mf/deref selected-iref) selected? (mf/deref selected-iref)
@ -79,6 +79,7 @@
(timers/raf (timers/raf
#(let [width (obj/get-in entries [0 "contentRect" "width"]) #(let [width (obj/get-in entries [0 "contentRect" "width"])
height (obj/get-in entries [0 "contentRect" "height"])] height (obj/get-in entries [0 "contentRect" "height"])]
(log/debug :msg "Resize detected" :shape-id id :width width :height height)
(st/emit! (dwt/resize-text id (mth/ceil width) (mth/ceil height)))))))) (st/emit! (dwt/resize-text id (mth/ceil width) (mth/ceil height))))))))
text-ref-cb text-ref-cb
@ -93,7 +94,7 @@
(reset! paragraph-ref ps-node))))))))] (reset! paragraph-ref ps-node))))))))]
(mf/use-effect (mf/use-effect
(mf/deps @paragraph-ref handle-resize-text) (mf/deps @paragraph-ref handle-resize-text grow-type)
(fn [] (fn []
(when-let [paragraph-node @paragraph-ref] (when-let [paragraph-node @paragraph-ref]
(let [observer (js/ResizeObserver. handle-resize-text)] (let [observer (js/ResizeObserver. handle-resize-text)]
@ -101,6 +102,7 @@
(.observe observer paragraph-node) (.observe observer paragraph-node)
#(.disconnect observer))))) #(.disconnect observer)))))
[:> shape-container {:shape shape} [:> shape-container {:shape shape}
;; We keep hidden the shape when we're editing so it keeps track of the size ;; We keep hidden the shape when we're editing so it keeps track of the size
;; and updates the selrect acordingly ;; and updates the selrect acordingly

View file

@ -165,13 +165,13 @@
on-click-outside on-click-outside
(fn [event] (fn [event]
(let [sidebar (dom/get-element "settings-bar") (let [options (dom/get-element-by-class "element-options")
assets (dom/get-element-by-class "assets-bar") assets (dom/get-element-by-class "assets-bar")
cpicker (dom/get-element-by-class "colorpicker-tooltip") cpicker (dom/get-element-by-class "colorpicker-tooltip")
self (mf/ref-val self-ref) self (mf/ref-val self-ref)
target (dom/get-target event) target (dom/get-target event)
selecting? (mf/ref-val selecting-ref)] selecting? (mf/ref-val selecting-ref)]
(when-not (or (and sidebar (.contains sidebar target)) (when-not (or (and options (.contains options target))
(and assets (.contains assets target)) (and assets (.contains assets target))
(and self (.contains self target)) (and self (.contains self target))
(and cpicker (.contains cpicker target))) (and cpicker (.contains cpicker target)))

View file

@ -4,6 +4,11 @@
(def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center #_:simple-selection}) (def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center #_:simple-selection})
;; These events are excluded when we activate the :events flag
(def debug-exclude-events
#{:app.main.data.workspace.notifications/handle-pointer-update
:app.main.data.workspace.selection/change-hover-state})
(defonce ^:dynamic *debug* (atom #{})) (defonce ^:dynamic *debug* (atom #{}))
(defn debug-all! [] (reset! *debug* debug-options)) (defn debug-all! [] (reset! *debug* debug-options))