mirror of
https://github.com/penpot/penpot.git
synced 2025-02-14 11:09:04 -05:00
🐛 Improve active frame behaviour for thumbnails
This commit is contained in:
parent
74612178d7
commit
d2983c1110
2 changed files with 53 additions and 23 deletions
|
@ -183,7 +183,7 @@
|
|||
(hooks/setup-hover-shapes page-id move-stream base-objects transform selected mod? hover hover-ids @hover-disabled? focus zoom)
|
||||
(hooks/setup-viewport-modifiers modifiers base-objects)
|
||||
(hooks/setup-shortcuts node-editing? drawing-path?)
|
||||
(hooks/setup-active-frames base-objects hover-ids selected active-frames zoom transform)
|
||||
(hooks/setup-active-frames base-objects hover-ids selected active-frames zoom transform vbox)
|
||||
|
||||
[:div.viewport
|
||||
[:div.viewport-overlays {:ref overlays-ref}
|
||||
|
|
|
@ -214,35 +214,65 @@
|
|||
|
||||
(defn inside-vbox [vbox objects frame-id]
|
||||
(let [frame (get objects frame-id)]
|
||||
|
||||
(and (some? frame)
|
||||
(gsh/overlaps? frame vbox))))
|
||||
(and (some? frame) (gsh/overlaps? frame vbox))))
|
||||
|
||||
(defn setup-active-frames
|
||||
[objects hover-ids selected active-frames zoom transform]
|
||||
[objects hover-ids selected active-frames zoom transform vbox]
|
||||
|
||||
(let [frame? #(= :frame (get-in objects [% :type]))
|
||||
all-frames (mf/use-memo (mf/deps objects) #(cph/get-frames-ids objects))
|
||||
selected-frames (mf/use-memo (mf/deps selected) #(->> all-frames (filter selected)))
|
||||
xf-selected-frame (comp (remove frame?) (map #(get-in objects [% :frame-id])))
|
||||
selected-shapes-frames (mf/use-memo (mf/deps selected) #(into #{} xf-selected-frame selected))
|
||||
|
||||
active-selection (when (and (not= transform :move) (= (count selected-frames) 1)) (first selected-frames))
|
||||
hover-frame (last @hover-ids)
|
||||
last-hover-frame (mf/use-var nil)]
|
||||
|
||||
(mf/use-effect
|
||||
(mf/deps objects @hover-ids selected zoom transform)
|
||||
(mf/deps hover-frame)
|
||||
(fn []
|
||||
(when (some? @hover-ids)
|
||||
(let [hover-frame (when (> zoom 0.25) (last @hover-ids))
|
||||
new-active-frames (if (some? hover-frame) #{hover-frame} #{})
|
||||
(when (some? hover-frame)
|
||||
(reset! last-hover-frame hover-frame))))
|
||||
|
||||
frame? #(= :frame (get-in objects [% :type]))
|
||||
(mf/use-effect
|
||||
(mf/deps objects @hover-ids selected zoom transform vbox)
|
||||
(fn []
|
||||
|
||||
selected-frames (->> selected (filter frame?))
|
||||
new-active-frames
|
||||
(cond-> new-active-frames
|
||||
(and (not= transform :move) (= (count selected-frames) 1))
|
||||
(conj new-active-frames (first selected-frames)))
|
||||
;; Rules for active frame:
|
||||
;; - If zoom < 25% displays thumbnail except when selecting a single frame or a child
|
||||
;; - We always active the current hovering frame for zoom > 25%
|
||||
;; - When zoom > 150% we activate the frames that are inside the vbox
|
||||
;; - If no hovering over any frames we keep the previous active one
|
||||
;; - Check always that the active frames are inside the vbox
|
||||
|
||||
(let [is-active-frame?
|
||||
(fn [id]
|
||||
(or
|
||||
;; Zoom > 150% shows every frame
|
||||
(> zoom 1.5)
|
||||
|
||||
;; Zoom >= 30% will show frames hovering
|
||||
(and
|
||||
(>= zoom 0.3)
|
||||
(or (= id hover-frame) (= id @last-hover-frame)))
|
||||
|
||||
;; Otherwise, if it's a selected frame
|
||||
(= id active-selection)
|
||||
|
||||
;; Or contains a selected shape
|
||||
(contains? selected-shapes-frames id)))
|
||||
|
||||
new-active-frames
|
||||
(into new-active-frames
|
||||
(comp
|
||||
(remove frame?)
|
||||
(map #(get-in objects [% :frame-id])))
|
||||
selected)]
|
||||
(reset! active-frames new-active-frames))))))
|
||||
(into #{}
|
||||
(comp (filter is-active-frame?)
|
||||
|
||||
;; We only allow active frames that are contained in the vbox
|
||||
(filter (partial inside-vbox vbox objects)))
|
||||
all-frames)]
|
||||
|
||||
(when (not= @active-frames new-active-frames)
|
||||
(reset! active-frames new-active-frames)))))))
|
||||
|
||||
;; NOTE: this is executed on each page change, maybe we need to move
|
||||
;; this shortcuts outside the viewport?
|
||||
|
|
Loading…
Add table
Reference in a new issue