From 003dec6c6b1f273737f9d00614dd85ba52fe63aa Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 19 Sep 2023 12:29:22 +0200 Subject: [PATCH] :lipstick: Add cosmetic changes to several viewer related react components --- frontend/src/app/main/ui/viewer.cljs | 17 ++-- .../src/app/main/ui/viewer/interactions.cljs | 87 +++++++++++-------- frontend/src/app/main/ui/viewer/shapes.cljs | 2 +- 3 files changed, 61 insertions(+), 45 deletions(-) diff --git a/frontend/src/app/main/ui/viewer.cljs b/frontend/src/app/main/ui/viewer.cljs index f44bc7d17..c10783e39 100644 --- a/frontend/src/app/main/ui/viewer.cljs +++ b/frontend/src/app/main/ui/viewer.cljs @@ -174,8 +174,10 @@ (mf/defc viewer-wrapper + {::mf/wrap-props false} [{: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 {:section section @@ -220,12 +222,13 @@ :interactions-mode interactions-mode}] (for [overlay overlays] - [:& viewer-overlay {:overlay overlay - :key (dm/str (:id overlay)) - :page page - :frame frame - :zoom zoom - :wrapper-size wrapper-size + [:& viewer-overlay + {:overlay overlay + :key (dm/str (:id overlay)) + :page page + :frame frame + :zoom zoom + :wrapper-size wrapper-size :interactions-mode interactions-mode}])]] diff --git a/frontend/src/app/main/ui/viewer/interactions.cljs b/frontend/src/app/main/ui/viewer/interactions.cljs index deab4db36..283ac8481 100644 --- a/frontend/src/app/main/ui/viewer/interactions.cljs +++ b/frontend/src/app/main/ui/viewer/interactions.cljs @@ -42,60 +42,72 @@ {::mf/wrap [mf/memo] ::mf/wrap-props false} [props] - (let [page (unchecked-get props "page") - frame (unchecked-get props "frame") - base (unchecked-get props "base") - offset (unchecked-get props "offset") - size (unchecked-get props "size") - delta (or (unchecked-get props "delta") (gpt/point 0 0)) - - vbox (:vbox size) + (let [page (unchecked-get props "page") + frame (unchecked-get props "frame") + base (unchecked-get props "base") + offset (unchecked-get props "offset") + size (unchecked-get props "size") + delta (or (unchecked-get props "delta") (gpt/point 0 0)) + vbox (:vbox size) fixed-ids (filter :fixed-scroll (vals (:objects page))) ;; 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 - (mapcat #(cons (:id %) (cph/get-parent-ids (:objects page) (:id %)))) - (remove #(= % uuid/zero))) + parent-children-ids + (->> fixed-ids + (mapcat #(cons (:id %) (cph/get-parent-ids (:objects page) (:id %)))) + (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))) - (remove #(= % uuid/zero))) + not-fixed-ids + (->> (remove (set fixed-ids) (keys (:objects page))) + (remove #(= % uuid/zero))) - calculate-objects (fn [ids] (->> ids - (map (d/getf (:objects page))) - (concat [frame]) - (d/index-by :id) - (prepare-objects frame size delta))) + calculate-objects + (fn [ids] + (->> ids + (map (d/getf (:objects page))) + (concat [frame]) + (d/index-by :id) + (prepare-objects frame size delta))) - objects-fixed (mf/with-memo [fixed-ids page frame size delta] - (calculate-objects fixed-ids)) + objects-fixed + (mf/with-memo [fixed-ids page frame size delta] + (calculate-objects fixed-ids)) - objects-not-fixed (mf/with-memo [not-fixed-ids page frame size delta] - (calculate-objects not-fixed-ids)) + objects-not-fixed + (mf/with-memo [not-fixed-ids page frame size delta] + (calculate-objects not-fixed-ids)) - all-objects (mf/with-memo [objects-fixed objects-not-fixed] - (merge objects-fixed objects-not-fixed)) + all-objects + (mf/with-memo [objects-fixed objects-not-fixed] + (merge objects-fixed objects-not-fixed)) - wrapper-fixed (mf/with-memo [page frame size] - (shapes/frame-container-factory objects-fixed all-objects)) + wrapper-fixed + (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] - (shapes/frame-container-factory objects-not-fixed all-objects)) + wrapper-not-fixed + (mf/with-memo [objects-not-fixed] + (shapes/frame-container-factory objects-not-fixed all-objects)) ;; Retrieve frames again with correct modifier frame (get all-objects (:id frame)) base (get all-objects (:id base)) - non-delay-interactions (->> (:interactions frame) - (filterv #(not= (:event-type %) :after-delay))) + non-delay-interactions + (->> (:interactions frame) + (filterv #(not= (:event-type %) :after-delay))) - fixed-frame (-> frame - (dissoc :fills) - (assoc :interactions non-delay-interactions))] + fixed-frame + (-> frame + (dissoc :fills) + (assoc :interactions non-delay-interactions))] [:& (mf/provider shapes/base-frame-ctx) {:value base} [:& (mf/provider shapes/frame-offset-ctx) {:value offset} @@ -124,8 +136,9 @@ ::mf/wrap-props false} [props] (let [;; NOTE: with `use-equal-memo` hook we ensure that all values - ;; conserves the reference identity for avoid unnecessary dummy - ;; rerenders. + ;; conserves the reference identity for avoid unnecessary + ;; dummy rerenders. + mode (h/use-equal-memo (unchecked-get props "interactions-mode")) offset (h/use-equal-memo (unchecked-get props "frame-offset")) size (h/use-equal-memo (unchecked-get props "size")) diff --git a/frontend/src/app/main/ui/viewer/shapes.cljs b/frontend/src/app/main/ui/viewer/shapes.cljs index 73e7ad22a..e98b366fa 100644 --- a/frontend/src/app/main/ui/viewer/shapes.cljs +++ b/frontend/src/app/main/ui/viewer/shapes.cljs @@ -469,7 +469,7 @@ (let [shape (if frame (gsh/translate-to-frame shape frame) shape) - + opts #js {:shape shape :objects objects :all-objects all-objects}]