0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-27 00:49:28 -05:00

💄 Add cosmetic changes to several viewer related react components

This commit is contained in:
Andrey Antukh 2023-09-19 12:29:22 +02:00 committed by Alonso Torres
parent df2d242746
commit 003dec6c6b
3 changed files with 61 additions and 45 deletions

View file

@ -174,8 +174,10 @@
(mf/defc viewer-wrapper (mf/defc viewer-wrapper
{::mf/wrap-props false}
[{:keys [wrapper-size orig-frame orig-viewport-ref orig-size page file users current-viewport-ref [{:keys [wrapper-size orig-frame orig-viewport-ref orig-size page file users current-viewport-ref
size frame interactions-mode overlays zoom section index] :as props}] size frame interactions-mode overlays zoom section index]}]
[:* [:*
[:& viewer-pagination-and-sidebar [:& viewer-pagination-and-sidebar
{:section section {:section section
@ -220,7 +222,8 @@
:interactions-mode interactions-mode}] :interactions-mode interactions-mode}]
(for [overlay overlays] (for [overlay overlays]
[:& viewer-overlay {:overlay overlay [:& viewer-overlay
{:overlay overlay
:key (dm/str (:id overlay)) :key (dm/str (:id overlay))
:page page :page page
:frame frame :frame frame

View file

@ -48,52 +48,64 @@
offset (unchecked-get props "offset") offset (unchecked-get props "offset")
size (unchecked-get props "size") size (unchecked-get props "size")
delta (or (unchecked-get props "delta") (gpt/point 0 0)) delta (or (unchecked-get props "delta") (gpt/point 0 0))
vbox (:vbox size) vbox (:vbox size)
fixed-ids (filter :fixed-scroll (vals (:objects page))) fixed-ids (filter :fixed-scroll (vals (:objects page)))
;; we have con consider the children if the fixed element is a group ;; we have con consider the children if the fixed element is a group
fixed-children-ids (into #{} (mapcat #(cph/get-children-ids (:objects page) (:id %)) fixed-ids)) fixed-children-ids
(into #{} (mapcat #(cph/get-children-ids (:objects page) (:id %)) fixed-ids))
parent-children-ids (->> fixed-ids parent-children-ids
(->> fixed-ids
(mapcat #(cons (:id %) (cph/get-parent-ids (:objects page) (:id %)))) (mapcat #(cons (:id %) (cph/get-parent-ids (:objects page) (:id %))))
(remove #(= % uuid/zero))) (remove #(= % uuid/zero)))
fixed-ids (concat fixed-children-ids parent-children-ids) fixed-ids
(concat fixed-children-ids parent-children-ids)
not-fixed-ids (->> (remove (set fixed-ids) (keys (:objects page))) not-fixed-ids
(->> (remove (set fixed-ids) (keys (:objects page)))
(remove #(= % uuid/zero))) (remove #(= % uuid/zero)))
calculate-objects (fn [ids] (->> ids calculate-objects
(fn [ids]
(->> ids
(map (d/getf (:objects page))) (map (d/getf (:objects page)))
(concat [frame]) (concat [frame])
(d/index-by :id) (d/index-by :id)
(prepare-objects frame size delta))) (prepare-objects frame size delta)))
objects-fixed (mf/with-memo [fixed-ids page frame size delta] objects-fixed
(mf/with-memo [fixed-ids page frame size delta]
(calculate-objects fixed-ids)) (calculate-objects fixed-ids))
objects-not-fixed (mf/with-memo [not-fixed-ids page frame size delta] objects-not-fixed
(mf/with-memo [not-fixed-ids page frame size delta]
(calculate-objects not-fixed-ids)) (calculate-objects not-fixed-ids))
all-objects (mf/with-memo [objects-fixed objects-not-fixed] all-objects
(mf/with-memo [objects-fixed objects-not-fixed]
(merge objects-fixed objects-not-fixed)) (merge objects-fixed objects-not-fixed))
wrapper-fixed (mf/with-memo [page frame size] wrapper-fixed
(shapes/frame-container-factory objects-fixed all-objects)) (mf/with-memo [page frame size]
(shapes/frame-container-factory (assoc objects-fixed ::fixed true) all-objects))
wrapper-not-fixed (mf/with-memo [objects-not-fixed] wrapper-not-fixed
(mf/with-memo [objects-not-fixed]
(shapes/frame-container-factory objects-not-fixed all-objects)) (shapes/frame-container-factory objects-not-fixed all-objects))
;; Retrieve frames again with correct modifier ;; Retrieve frames again with correct modifier
frame (get all-objects (:id frame)) frame (get all-objects (:id frame))
base (get all-objects (:id base)) base (get all-objects (:id base))
non-delay-interactions (->> (:interactions frame) non-delay-interactions
(->> (:interactions frame)
(filterv #(not= (:event-type %) :after-delay))) (filterv #(not= (:event-type %) :after-delay)))
fixed-frame (-> frame fixed-frame
(-> frame
(dissoc :fills) (dissoc :fills)
(assoc :interactions non-delay-interactions))] (assoc :interactions non-delay-interactions))]
@ -124,8 +136,9 @@
::mf/wrap-props false} ::mf/wrap-props false}
[props] [props]
(let [;; NOTE: with `use-equal-memo` hook we ensure that all values (let [;; NOTE: with `use-equal-memo` hook we ensure that all values
;; conserves the reference identity for avoid unnecessary dummy ;; conserves the reference identity for avoid unnecessary
;; rerenders. ;; dummy rerenders.
mode (h/use-equal-memo (unchecked-get props "interactions-mode")) mode (h/use-equal-memo (unchecked-get props "interactions-mode"))
offset (h/use-equal-memo (unchecked-get props "frame-offset")) offset (h/use-equal-memo (unchecked-get props "frame-offset"))
size (h/use-equal-memo (unchecked-get props "size")) size (h/use-equal-memo (unchecked-get props "size"))