mirror of
https://github.com/penpot/penpot.git
synced 2025-05-19 10:36:12 +02:00
Merge pull request #2884 from penpot/alotor-post-release-fixes
Post release fixes
This commit is contained in:
commit
fe76e0fab6
10 changed files with 178 additions and 62 deletions
|
@ -271,16 +271,89 @@
|
|||
(ptk/data-event :layout/update ids)
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
||||
(defn fix-child-sizing
|
||||
[objects parent-changes shape]
|
||||
|
||||
(let [parent (-> (cph/get-parent objects (:id shape))
|
||||
(d/deep-merge parent-changes))
|
||||
|
||||
auto-width? (ctl/auto-width? parent)
|
||||
auto-height? (ctl/auto-height? parent)
|
||||
col? (ctl/col? parent)
|
||||
row? (ctl/row? parent)
|
||||
|
||||
all-children (->> parent :shapes (map (d/getf objects)))]
|
||||
|
||||
(cond-> shape
|
||||
;; If the parent is hug width and the direction column
|
||||
;; change to fixed when ALL children are fill
|
||||
(and col? auto-width? (every? ctl/fill-width? all-children))
|
||||
(assoc :layout-item-h-sizing :fix)
|
||||
|
||||
;; If the parent is hug height and the direction is column
|
||||
;; change to fixed when ANY children is fill
|
||||
(and col? auto-height? (ctl/fill-height? shape))
|
||||
(assoc :layout-item-v-sizing :fix)
|
||||
|
||||
;; If the parent is hug width and the direction row
|
||||
;; change to fixed when ANY children is fill
|
||||
(and row? auto-width? (ctl/fill-width? shape))
|
||||
(assoc :layout-item-h-sizing :fix)
|
||||
|
||||
;; If the parent is hug height and the direction row
|
||||
;; change to fixed when ALL children are fill
|
||||
(and row? auto-height? (every? ctl/fill-height? all-children))
|
||||
(assoc :layout-item-v-sizing :fix))))
|
||||
|
||||
(defn fix-parent-sizing
|
||||
[objects ids-set changes parent]
|
||||
|
||||
(let [auto-width? (ctl/auto-width? parent)
|
||||
auto-height? (ctl/auto-height? parent)
|
||||
col? (ctl/col? parent)
|
||||
row? (ctl/row? parent)
|
||||
|
||||
all-children
|
||||
(->> parent :shapes
|
||||
(map (d/getf objects))
|
||||
(map (fn [shape]
|
||||
(if (contains? ids-set (:id shape))
|
||||
(d/deep-merge shape changes)
|
||||
shape))))]
|
||||
|
||||
(cond-> parent
|
||||
;; Col layout and parent is hug-width if all children are fill-width
|
||||
;; change parent to fixed
|
||||
(and col? auto-width? (every? ctl/fill-width? all-children))
|
||||
(assoc :layout-item-h-sizing :fix)
|
||||
|
||||
;; Col layout and parent is hug-height if any children is fill-height
|
||||
;; change parent to fixed
|
||||
(and col? auto-height? (some ctl/fill-height? all-children))
|
||||
(assoc :layout-item-v-sizing :fix)
|
||||
|
||||
;; Row layout and parent is hug-width if any children is fill-width
|
||||
;; change parent to fixed
|
||||
(and row? auto-width? (some ctl/fill-width? all-children))
|
||||
(assoc :layout-item-h-sizing :fix)
|
||||
|
||||
;; Row layout and parent is hug-height if all children are fill-height
|
||||
;; change parent to fixed
|
||||
(and row? auto-height? (every? ctl/fill-height? all-children))
|
||||
(assoc :layout-item-v-sizing :fix))))
|
||||
|
||||
(defn update-layout-child
|
||||
[ids changes]
|
||||
(ptk/reify ::update-layout-child
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
children-ids (->> ids (mapcat #(cph/get-children-ids objects %)))
|
||||
parent-ids (->> ids (map #(cph/get-parent-id objects %)))
|
||||
layout-ids (->> ids (filter (comp ctl/layout? (d/getf objects))))
|
||||
undo-id (js/Symbol)]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dwc/update-shapes ids #(d/deep-merge (or % {}) changes))
|
||||
(ptk/data-event :layout/update (d/concat-vec layout-ids parent-ids))
|
||||
(dwc/update-shapes children-ids (partial fix-child-sizing objects changes))
|
||||
(dwc/update-shapes parent-ids (partial fix-parent-sizing objects (set ids) changes))
|
||||
(ptk/data-event :layout/update ids)
|
||||
(dwu/commit-undo-transaction undo-id))))))
|
||||
|
|
|
@ -77,6 +77,11 @@
|
|||
;; Delete the thumbnail first so if we interrupt we can regenerate after
|
||||
(->> (rp/cmd! :upsert-file-object-thumbnail params)
|
||||
(rx/catch #(rx/empty)))
|
||||
|
||||
;; Remove the thumbnail temporary. If the user changes pages the thumbnail is regenerated
|
||||
(rx/of #(update % :workspace-thumbnails assoc object-id nil))
|
||||
|
||||
;; Send the update to the back-end
|
||||
(->> blob-result
|
||||
(rx/merge-map
|
||||
(fn [blob]
|
||||
|
|
|
@ -27,23 +27,21 @@
|
|||
|
||||
(defn- draw-thumbnail-canvas!
|
||||
[canvas-node img-node]
|
||||
(ts/raf
|
||||
(fn []
|
||||
(try
|
||||
(when (and (some? canvas-node) (some? img-node))
|
||||
(let [canvas-context (.getContext canvas-node "2d")
|
||||
canvas-width (.-width canvas-node)
|
||||
canvas-height (.-height canvas-node)]
|
||||
(.clearRect canvas-context 0 0 canvas-width canvas-height)
|
||||
(.drawImage canvas-context img-node 0 0 canvas-width canvas-height)
|
||||
(try
|
||||
(when (and (some? canvas-node) (some? img-node))
|
||||
(let [canvas-context (.getContext canvas-node "2d")
|
||||
canvas-width (.-width canvas-node)
|
||||
canvas-height (.-height canvas-node)]
|
||||
(.clearRect canvas-context 0 0 canvas-width canvas-height)
|
||||
(.drawImage canvas-context img-node 0 0 canvas-width canvas-height)
|
||||
|
||||
;; Set a true on the next animation frame, we make sure the drawImage is completed
|
||||
(ts/raf
|
||||
#(dom/set-data! canvas-node "ready" "true"))
|
||||
true))
|
||||
(catch :default err
|
||||
(.error js/console err)
|
||||
false)))))
|
||||
;; Set a true on the next animation frame, we make sure the drawImage is completed
|
||||
(ts/raf
|
||||
#(dom/set-data! canvas-node "ready" "true"))
|
||||
true))
|
||||
(catch :default err
|
||||
(.error js/console err)
|
||||
false)))
|
||||
|
||||
(defn- remove-image-loading
|
||||
"Remove the changes related to change a url for its embed value. This is necessary
|
||||
|
@ -78,8 +76,12 @@
|
|||
(gsh/selection-rect (concat [shape] all-children))
|
||||
(-> shape :points gsh/points->selrect))
|
||||
|
||||
fixed-width (mth/clamp width 250 2000)
|
||||
fixed-height (/ (* height fixed-width) width)
|
||||
[fixed-width fixed-height]
|
||||
(if (> width height)
|
||||
[(mth/clamp width 250 2000)
|
||||
(/ (* height (mth/clamp width 250 2000)) width)]
|
||||
[(/ (* width (mth/clamp height 250 2000)) height)
|
||||
(mth/clamp height 250 2000)])
|
||||
|
||||
image-url (mf/use-state nil)
|
||||
observer-ref (mf/use-var nil)
|
||||
|
@ -289,6 +291,6 @@
|
|||
:height height}
|
||||
[:img {:ref frame-image-ref
|
||||
:src @image-url
|
||||
:width width
|
||||
:height height
|
||||
:width fixed-width
|
||||
:height fixed-height
|
||||
:on-load on-image-load}]])])]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue