mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 07:50:43 -05:00
🐛 Fix reflow layout when changes in paths and texts
This commit is contained in:
parent
54fd836dd4
commit
441e142349
7 changed files with 100 additions and 37 deletions
|
@ -55,7 +55,6 @@
|
|||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.data.workspace.shapes-update-layout :as dwul]
|
||||
[app.main.data.workspace.shapes-update-layout :as dwul]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.workspace.thumbnails :as dwth]
|
||||
[app.main.data.workspace.transforms :as dwt]
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.comments :as-alias dwcm]
|
||||
|
@ -188,6 +189,42 @@
|
|||
[(get-in objects [k :name]) v]))
|
||||
modif-tree)))
|
||||
|
||||
(defn apply-text-modifiers
|
||||
[objects text-modifiers]
|
||||
(letfn [(apply-text-modifier
|
||||
[shape {:keys [width height]}]
|
||||
(cond-> shape
|
||||
(some? width)
|
||||
(assoc :width width)
|
||||
|
||||
(some? height)
|
||||
(assoc :height height)
|
||||
|
||||
(or (some? width) (some? height))
|
||||
(cts/setup-rect-selrect)))]
|
||||
(loop [modifiers (seq text-modifiers)
|
||||
result objects]
|
||||
(if (empty? modifiers)
|
||||
result
|
||||
(let [[id text-modifier] (first modifiers)]
|
||||
(recur (rest modifiers)
|
||||
(update objects id apply-text-modifier text-modifier)))))))
|
||||
|
||||
#_(defn apply-path-modifiers
|
||||
[objects path-modifiers]
|
||||
(letfn [(apply-path-modifier
|
||||
[shape {:keys [content-modifiers]}]
|
||||
(let [shape (update shape :content upc/apply-content-modifiers content-modifiers)
|
||||
[points selrect] (helpers/content->points+selrect shape (:content shape))]
|
||||
(assoc shape :selrect selrect :points points)))]
|
||||
(loop [modifiers (seq path-modifiers)
|
||||
result objects]
|
||||
(if (empty? modifiers)
|
||||
result
|
||||
(let [[id path-modifier] (first modifiers)]
|
||||
(recur (rest modifiers)
|
||||
(update objects id apply-path-modifier path-modifier)))))))
|
||||
|
||||
(defn set-modifiers
|
||||
([modif-tree]
|
||||
(set-modifiers modif-tree false))
|
||||
|
@ -206,7 +243,10 @@
|
|||
(and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))
|
||||
|
||||
modif-tree
|
||||
(gsh/set-objects-modifiers modif-tree objects ignore-constraints snap-pixel?)]
|
||||
(as-> objects $
|
||||
(apply-text-modifiers $ (get state :workspace-text-modifier))
|
||||
;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path]))
|
||||
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?))]
|
||||
|
||||
(assoc state :workspace-modifiers modif-tree))))))
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
[app.main.data.workspace.path.state :as st]
|
||||
[app.main.data.workspace.path.streams :as streams]
|
||||
[app.main.data.workspace.path.undo :as undo]
|
||||
[app.main.data.workspace.shapes-update-layout :as dwul]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.streams :as ms]
|
||||
[app.util.path.tools :as upt]
|
||||
|
@ -297,22 +298,25 @@
|
|||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state stream]
|
||||
(let [mode (get-in state [:workspace-local :edit-path id :edit-mode])]
|
||||
(let [mode (get-in state [:workspace-local :edit-path id :edit-mode])
|
||||
stopper (->> stream (rx/filter (ptk/type? ::start-path-edit)))
|
||||
interrupt (->> stream (rx/filter #(= % :interrupt)) (rx/take 1))]
|
||||
(rx/concat
|
||||
(rx/of (undo/start-path-undo))
|
||||
(rx/of (drawing/change-edit-mode mode))
|
||||
(->> stream
|
||||
(rx/take-until (->> stream (rx/filter (ptk/type? ::start-path-edit))))
|
||||
(rx/filter #(= % :interrupt))
|
||||
(rx/take 1)
|
||||
(rx/map #(stop-path-edit))))))))
|
||||
(->> interrupt
|
||||
(rx/map #(stop-path-edit id))
|
||||
(rx/take-until stopper)))))))
|
||||
|
||||
(defn stop-path-edit []
|
||||
(defn stop-path-edit [id]
|
||||
(ptk/reify ::stop-path-edit
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(let [id (get-in state [:workspace-local :edition])]
|
||||
(update state :workspace-local dissoc :edit-path id)))))
|
||||
(update state :workspace-local dissoc :edit-path id))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(rx/of (dwul/update-layout-positions [id])))))
|
||||
|
||||
(defn split-segments
|
||||
[{:keys [from-p to-p t]}]
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.data.workspace.modifiers :as dwm]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
|
@ -18,11 +16,9 @@
|
|||
[ids]
|
||||
(ptk/reify ::update-layout-positions
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
ids (->> ids (filter (partial ctl/layout? objects)))]
|
||||
(if (d/not-empty? ids)
|
||||
(let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))]
|
||||
(rx/of (dwm/set-modifiers modif-tree)
|
||||
(dwm/apply-modifiers)))
|
||||
(rx/empty))))))
|
||||
(watch [_ _ _]
|
||||
(if (d/not-empty? ids)
|
||||
(let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))]
|
||||
(rx/of (dwm/set-modifiers modif-tree)
|
||||
(dwm/apply-modifiers)))
|
||||
(rx/empty)))))
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
[app.common.pages.helpers :as cph]
|
||||
[app.common.text :as txt]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.selection :as dws]
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.data.workspace.shapes-update-layout :as dwul]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.workspace.undo :as dwu]
|
||||
[app.util.router :as rt]
|
||||
|
@ -75,7 +77,8 @@
|
|||
(dch/update-shapes [id] (fn [shape]
|
||||
(-> shape
|
||||
(assoc :content content)
|
||||
(merge modifiers))))
|
||||
(merge modifiers)
|
||||
(cts/setup-rect-selrect))))
|
||||
(dwu/commit-undo-transaction)))))
|
||||
|
||||
(when (some? id)
|
||||
|
@ -316,19 +319,24 @@
|
|||
[id new-width new-height]
|
||||
(ptk/reify ::resize-text
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(letfn [(update-fn [shape]
|
||||
(let [{:keys [selrect grow-type]} shape
|
||||
{shape-width :width shape-height :height} selrect]
|
||||
(cond-> shape
|
||||
(and (not-changed? shape-width new-width) (= grow-type :auto-width))
|
||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :width new-width))
|
||||
(watch [_ state _]
|
||||
(let [shape (wsh/lookup-shape state id)]
|
||||
(letfn [(update-fn [shape]
|
||||
(let [{:keys [selrect grow-type]} shape
|
||||
{shape-width :width shape-height :height} selrect]
|
||||
(cond-> shape
|
||||
(and (not-changed? shape-width new-width) (= grow-type :auto-width))
|
||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :width new-width))
|
||||
|
||||
(and (not-changed? shape-height new-height)
|
||||
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height)))))]
|
||||
(and (not-changed? shape-height new-height)
|
||||
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height)))))]
|
||||
|
||||
(rx/of (dch/update-shapes [id] update-fn {:reg-objects? true :save-undo? false}))))))
|
||||
(when (or (and (not-changed? (:width shape) new-width) (= (:grow-type shape) :auto-width))
|
||||
(and (not-changed? (:height shape) new-height)
|
||||
(or (= (:grow-type shape) :auto-height) (= (:grow-type shape) :auto-width))))
|
||||
(rx/of (dch/update-shapes [id] update-fn {:reg-objects? true :save-undo? false})
|
||||
(dwul/update-layout-positions [id]))))))))
|
||||
|
||||
(defn save-font
|
||||
[data]
|
||||
|
@ -368,7 +376,16 @@
|
|||
(ptk/reify ::update-text-modifier
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(update-in state [:workspace-text-modifier id] (fnil merge {}) props))))
|
||||
(update-in state [:workspace-text-modifier id] (fnil merge {}) props))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [shape (wsh/lookup-shape state id)]
|
||||
(when (or (and (some? (:width props))
|
||||
(not (mth/close? (:width props) (:width shape))))
|
||||
(and (some? (:height props))
|
||||
(not (mth/close? (:height props) (:height shape)))))
|
||||
(rx/of (dwul/update-layout-positions [id])))))))
|
||||
|
||||
(defn clean-text-modifier
|
||||
[id]
|
||||
|
|
|
@ -28,9 +28,12 @@
|
|||
(let [selfn #(get-in % [:edit-path id])]
|
||||
#(l/derived selfn refs/workspace-local))))
|
||||
|
||||
(defn content-modifiers-ref
|
||||
[id]
|
||||
(l/derived #(get-in % [:edit-path id :content-modifiers]) refs/workspace-local))
|
||||
|
||||
(defn make-content-modifiers-ref [id]
|
||||
(mf/use-memo
|
||||
(mf/deps id)
|
||||
(let [selfn #(get-in % [:edit-path id :content-modifiers])]
|
||||
#(l/derived selfn refs/workspace-local))))
|
||||
#(content-modifiers-ref id)))
|
||||
|
||||
|
|
|
@ -155,7 +155,11 @@
|
|||
(not (identical? old-shape new-shape))
|
||||
(not= (dissoc old-shape :migrate)
|
||||
(dissoc new-shape :migrate)))
|
||||
(not= new-modifiers old-modifiers)
|
||||
(and (not= new-modifiers old-modifiers)
|
||||
(or (nil? new-modifiers)
|
||||
(nil? old-modifiers)
|
||||
(not (ctm/only-move? new-modifiers))
|
||||
(not (ctm/only-move? old-modifiers))))
|
||||
|
||||
;; When the position data is nil we force to recalculate
|
||||
(:migrate new-shape))))
|
||||
|
|
Loading…
Reference in a new issue