mirror of
https://github.com/penpot/penpot.git
synced 2025-03-14 08:41:48 -05:00
✨ Adapted viewer for new frames
This commit is contained in:
parent
8c5cc446b0
commit
c8ad379bf8
16 changed files with 148 additions and 115 deletions
|
@ -278,6 +278,11 @@
|
||||||
(rest frames))]
|
(rest frames))]
|
||||||
(or (:id top-frame) uuid/zero)))
|
(or (:id top-frame) uuid/zero)))
|
||||||
|
|
||||||
|
(defn frame-by-position
|
||||||
|
[objects position]
|
||||||
|
(let [frame-id (frame-id-by-position objects position)]
|
||||||
|
(get objects frame-id)))
|
||||||
|
|
||||||
(declare indexed-shapes)
|
(declare indexed-shapes)
|
||||||
|
|
||||||
(defn get-base-shape
|
(defn get-base-shape
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.spec.interactions :as cti]
|
[app.common.spec.interactions :as cti]
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.main.data.comments :as dcm]
|
[app.main.data.comments :as dcm]
|
||||||
[app.main.data.fonts :as df]
|
[app.main.data.fonts :as df]
|
||||||
[app.main.repo :as rp]
|
[app.main.repo :as rp]
|
||||||
|
@ -88,10 +87,10 @@
|
||||||
|
|
||||||
(defn select-frames
|
(defn select-frames
|
||||||
[{:keys [objects] :as page}]
|
[{:keys [objects] :as page}]
|
||||||
(let [root (get objects uuid/zero)]
|
(into []
|
||||||
(into [] (comp (map #(get objects %))
|
(comp (map (d/getf objects))
|
||||||
(filter #(= :frame (:type %))))
|
(remove :hide-in-viewer))
|
||||||
(reverse (:shapes root)))))
|
(cph/sort-z-index objects (cph/get-frames-ids objects))))
|
||||||
|
|
||||||
;; --- Data Fetching
|
;; --- Data Fetching
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.proportions :as gpr]
|
[app.common.geom.proportions :as gpr]
|
||||||
[app.common.geom.shapes :as gsh]
|
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.pages.changes-builder :as pcb]
|
[app.common.pages.changes-builder :as pcb]
|
||||||
|
@ -59,13 +58,6 @@
|
||||||
|
|
||||||
;; --- Common Helpers & Events
|
;; --- Common Helpers & Events
|
||||||
|
|
||||||
;; TODO: looks duplicate
|
|
||||||
|
|
||||||
(defn get-frame-at-point
|
|
||||||
[objects point]
|
|
||||||
(let [frames (cph/get-frames objects)]
|
|
||||||
(d/seek #(gsh/has-point? % point) frames)))
|
|
||||||
|
|
||||||
(defn- extract-numeric-suffix
|
(defn- extract-numeric-suffix
|
||||||
[basename]
|
[basename]
|
||||||
(if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
|
(if-let [[_ p1 p2] (re-find #"(.*)-([0-9]+)$" basename)]
|
||||||
|
|
|
@ -182,10 +182,17 @@
|
||||||
selected-shape (get objects selected-shape-id)
|
selected-shape (get objects selected-shape-id)
|
||||||
selected-shape-frame-id (:frame-id selected-shape)
|
selected-shape-frame-id (:frame-id selected-shape)
|
||||||
start-frame (get objects selected-shape-frame-id)
|
start-frame (get objects selected-shape-frame-id)
|
||||||
end-frame (dwc/get-frame-at-point objects position)]
|
end-frame (cph/frame-by-position objects position)
|
||||||
(cond-> state
|
|
||||||
(not= position initial-pos) (assoc-in [:workspace-local :draw-interaction-to] position)
|
position (when (not= position initial-pos) position)
|
||||||
(not= start-frame end-frame) (assoc-in [:workspace-local :draw-interaction-to-frame] end-frame))))))
|
end-frame (when (and (not= (:id end-frame) uuid/zero )
|
||||||
|
(not= (:id end-frame) (:id start-frame))
|
||||||
|
(not= (:id end-frame) selected-shape-id)
|
||||||
|
(not (:hide-in-viewer end-frame)))
|
||||||
|
end-frame)]
|
||||||
|
(-> state
|
||||||
|
(assoc-in [:workspace-local :draw-interaction-to] position)
|
||||||
|
(assoc-in [:workspace-local :draw-interaction-to-frame] end-frame))))))
|
||||||
|
|
||||||
(defn finish-edit-interaction
|
(defn finish-edit-interaction
|
||||||
[index initial-pos]
|
[index initial-pos]
|
||||||
|
@ -199,32 +206,49 @@
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [position @ms/mouse-position
|
(let [position @ms/mouse-position
|
||||||
page-id (:current-page-id state)
|
page-id (:current-page-id state)
|
||||||
objects (wsh/lookup-page-objects state page-id)
|
objects (wsh/lookup-page-objects state page-id)
|
||||||
frame (dwc/get-frame-at-point objects position)
|
target-frame (cph/frame-by-position objects position)
|
||||||
|
|
||||||
shape-id (-> state wsh/lookup-selected first)
|
shape-id (-> state wsh/lookup-selected first)
|
||||||
shape (get objects shape-id)]
|
shape (get objects shape-id)
|
||||||
|
|
||||||
(when (and shape (not (= position initial-pos)))
|
invalid-target? (or (nil? target-frame)
|
||||||
(if (nil? frame)
|
(= (:id target-frame) uuid/zero)
|
||||||
(when index
|
(= (:id target-frame) (:id shape))
|
||||||
(rx/of (remove-interaction shape index)))
|
(= (:id target-frame) (:frame-id shape))
|
||||||
(let [frame (if (or (= (:id frame) (:id shape))
|
(:hide-in-viewer target-frame))
|
||||||
(= (:id frame) (:frame-id shape)))
|
|
||||||
nil ;; Drop onto self frame -> set destination to none
|
change-interaction
|
||||||
frame)]
|
(fn [interaction]
|
||||||
(if (nil? index)
|
(cond-> interaction
|
||||||
(rx/of (add-new-interaction shape (:id frame)))
|
(not (csi/has-destination interaction))
|
||||||
(rx/of (update-interaction shape index
|
(csi/set-action-type :navigate)
|
||||||
(fn [interaction]
|
|
||||||
(cond-> interaction
|
:always
|
||||||
(not (csi/has-destination interaction))
|
(csi/set-destination (:id target-frame))))]
|
||||||
(csi/set-action-type :navigate)
|
|
||||||
|
(cond
|
||||||
|
(or (nil? shape)
|
||||||
|
|
||||||
|
;; Didn't changed the position for the interaction
|
||||||
|
(= position initial-pos)
|
||||||
|
|
||||||
|
;; New interaction but invalid target
|
||||||
|
(and (nil? index) invalid-target?))
|
||||||
|
nil
|
||||||
|
|
||||||
|
;; Dropped interaction in an invalid target. We remove it
|
||||||
|
(and (some? index) invalid-target?)
|
||||||
|
(rx/of (remove-interaction shape index))
|
||||||
|
|
||||||
|
(nil? index)
|
||||||
|
(rx/of (add-new-interaction shape (:id target-frame)))
|
||||||
|
|
||||||
|
:else
|
||||||
|
(rx/of (update-interaction shape index change-interaction)))))))
|
||||||
|
|
||||||
:always
|
|
||||||
(csi/set-destination (:id frame))))))))))))))
|
|
||||||
;; --- Overlays
|
;; --- Overlays
|
||||||
|
|
||||||
(declare move-overlay-pos)
|
(declare move-overlay-pos)
|
||||||
|
|
|
@ -762,8 +762,8 @@
|
||||||
(rx/map (partial set-modifiers ids))
|
(rx/map (partial set-modifiers ids))
|
||||||
(rx/take-until stopper))
|
(rx/take-until stopper))
|
||||||
|
|
||||||
(rx/of (apply-modifiers ids)
|
(rx/of (calculate-frame-for-move ids)
|
||||||
(calculate-frame-for-move ids)
|
(apply-modifiers ids)
|
||||||
(finish-transform)))))))))
|
(finish-transform)))))))))
|
||||||
|
|
||||||
(s/def ::direction #{:up :down :right :left})
|
(s/def ::direction #{:up :down :right :left})
|
||||||
|
@ -854,9 +854,8 @@
|
||||||
|
|
||||||
moving-shapes (->> ids
|
moving-shapes (->> ids
|
||||||
(cph/clean-loops objects)
|
(cph/clean-loops objects)
|
||||||
(map #(get objects %))
|
(keep #(get objects %))
|
||||||
(remove #(or (nil? %)
|
(remove #(= (:frame-id %) frame-id)))
|
||||||
(= (:frame-id %) frame-id))))
|
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it page-id)
|
changes (-> (pcb/empty-changes it page-id)
|
||||||
(pcb/with-objects objects)
|
(pcb/with-objects objects)
|
||||||
|
|
|
@ -240,16 +240,20 @@
|
||||||
|
|
||||||
(when (seq selected-shapes)
|
(when (seq selected-shapes)
|
||||||
[:g.measurement-feedback {:pointer-events "none"}
|
[:g.measurement-feedback {:pointer-events "none"}
|
||||||
[:& selection-guides {:selrect selected-selrect :bounds bounds :zoom zoom}]
|
[:& selection-guides {:selrect selected-selrect
|
||||||
|
:bounds bounds
|
||||||
|
:zoom zoom}]
|
||||||
[:& size-display {:selrect selected-selrect :zoom zoom}]
|
[:& size-display {:selrect selected-selrect :zoom zoom}]
|
||||||
|
|
||||||
(if (or (not hover-shape) (not hover-selected-shape?))
|
(if (or (not hover-shape) (not hover-selected-shape?))
|
||||||
(when (and frame (not= uuid/zero (:id frame)))
|
(when (and frame (not= uuid/zero (:id frame)))
|
||||||
[:g.hover-shapes
|
(let [frame-bb (-> (:points frame) (gsh/points->selrect))]
|
||||||
[:& distance-display {:from (:selrect frame)
|
[:g.hover-shapes
|
||||||
:to selected-selrect
|
[:& selection-rect {:type :hover :selrect frame-bb :zoom zoom}]
|
||||||
:zoom zoom
|
[:& distance-display {:from frame-bb
|
||||||
:bounds bounds-selrect}]])
|
:to selected-selrect
|
||||||
|
:zoom zoom
|
||||||
|
:bounds bounds-selrect}]]))
|
||||||
|
|
||||||
[:g.hover-shapes
|
[:g.hover-shapes
|
||||||
[:& selection-rect {:type :hover :selrect hover-selrect :zoom zoom}]
|
[:& selection-rect {:type :hover :selrect hover-selrect :zoom zoom}]
|
||||||
|
|
|
@ -8,8 +8,10 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.colors :as clr]
|
[app.common.colors :as clr]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.common.pages.helpers :as cph]
|
[app.common.pages.helpers :as cph]
|
||||||
[app.common.text :as txt]
|
[app.common.text :as txt]
|
||||||
[app.main.data.comments :as dcm]
|
[app.main.data.comments :as dcm]
|
||||||
|
@ -37,18 +39,23 @@
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
(defn- calculate-size
|
(defn- calculate-size
|
||||||
[frame zoom]
|
[frame zoom bounds]
|
||||||
(let [{:keys [_ _ width height]} (filters/get-filters-bounds frame)
|
(let [frame-bounds (filters/get-filters-bounds frame)
|
||||||
|
{:keys [x y width height]} (if (:show-content frame)
|
||||||
|
(gsh/join-rects [bounds frame-bounds])
|
||||||
|
frame-bounds)
|
||||||
padding (filters/calculate-padding frame)
|
padding (filters/calculate-padding frame)
|
||||||
x (- (:horizontal padding))
|
x (- x (:horizontal padding))
|
||||||
y (- (:vertical padding))
|
y (- y (:vertical padding))
|
||||||
width (+ width (* 2 (:horizontal padding)))
|
width (+ width (* 2 (:horizontal padding)))
|
||||||
height (+ height (* 2 (:vertical padding)))]
|
height (+ height (* 2 (:vertical padding)))]
|
||||||
{:base-width width
|
{:base-width width
|
||||||
:base-height height
|
:base-height height
|
||||||
|
:x x
|
||||||
|
:y y
|
||||||
:width (* width zoom)
|
:width (* width zoom)
|
||||||
:height (* height zoom)
|
:height (* height zoom)
|
||||||
:vbox (str x " " y " " width " " height)}))
|
:vbox (dm/fmt "% % % %" 0 0 width height)}))
|
||||||
|
|
||||||
(defn- calculate-wrapper
|
(defn- calculate-wrapper
|
||||||
[size1 size2 zoom]
|
[size1 size2 zoom]
|
||||||
|
@ -128,7 +135,7 @@
|
||||||
:interactions-mode interactions-mode}]
|
:interactions-mode interactions-mode}]
|
||||||
|
|
||||||
(for [overlay overlays]
|
(for [overlay overlays]
|
||||||
(let [size-over (calculate-size (:frame overlay) zoom)]
|
(let [size-over (calculate-size (:frame overlay) zoom children-bounds)]
|
||||||
[:*
|
[:*
|
||||||
(when (or (:close-click-outside overlay)
|
(when (or (:close-click-outside overlay)
|
||||||
(:background-overlay overlay))
|
(:background-overlay overlay))
|
||||||
|
@ -198,6 +205,13 @@
|
||||||
zoom (:zoom local)
|
zoom (:zoom local)
|
||||||
frames (:frames page)
|
frames (:frames page)
|
||||||
frame (get frames index)
|
frame (get frames index)
|
||||||
|
|
||||||
|
children-bounds
|
||||||
|
(mf/use-memo
|
||||||
|
(mf/deps page (:id frame))
|
||||||
|
#(-> (cph/get-children (:objects page) (:id frame))
|
||||||
|
(gsh/selection-rect)))
|
||||||
|
|
||||||
fullscreen? (mf/deref refs/viewer-fullscreen?)
|
fullscreen? (mf/deref refs/viewer-fullscreen?)
|
||||||
overlays (:overlays local)
|
overlays (:overlays local)
|
||||||
scroll (mf/use-state nil)
|
scroll (mf/use-state nil)
|
||||||
|
@ -207,12 +221,13 @@
|
||||||
(d/seek #(= (:id %) (:orig-frame-id current-animation)) frames))
|
(d/seek #(= (:id %) (:orig-frame-id current-animation)) frames))
|
||||||
|
|
||||||
size (mf/use-memo
|
size (mf/use-memo
|
||||||
(mf/deps frame zoom)
|
(mf/deps frame zoom children-bounds)
|
||||||
(fn [] (calculate-size frame zoom)))
|
(fn [] (calculate-size frame zoom children-bounds)))
|
||||||
|
|
||||||
orig-size (mf/use-memo
|
orig-size (mf/use-memo
|
||||||
(mf/deps orig-frame zoom)
|
(mf/deps orig-frame zoom)
|
||||||
(fn [] (when orig-frame (calculate-size orig-frame zoom))))
|
(fn [] (when orig-frame
|
||||||
|
(calculate-size orig-frame zoom children-bounds))))
|
||||||
|
|
||||||
wrapper-size (mf/use-memo
|
wrapper-size (mf/use-memo
|
||||||
(mf/deps size orig-size zoom)
|
(mf/deps size orig-size zoom)
|
||||||
|
@ -305,7 +320,7 @@
|
||||||
wrapper-size)))))
|
wrapper-size)))))
|
||||||
|
|
||||||
(mf/use-layout-effect
|
(mf/use-layout-effect
|
||||||
(mf/deps current-animation)
|
(mf/deps current-animation children-bounds)
|
||||||
(fn []
|
(fn []
|
||||||
;; Overlay animations may be started when needed.
|
;; Overlay animations may be started when needed.
|
||||||
(when current-animation
|
(when current-animation
|
||||||
|
@ -315,7 +330,7 @@
|
||||||
(let [overlay-viewport (dom/get-element (str "overlay-" (str (:overlay-id current-animation))))
|
(let [overlay-viewport (dom/get-element (str "overlay-" (str (:overlay-id current-animation))))
|
||||||
overlay (d/seek #(= (:id (:frame %)) (:overlay-id current-animation))
|
overlay (d/seek #(= (:id (:frame %)) (:overlay-id current-animation))
|
||||||
overlays)
|
overlays)
|
||||||
overlay-size (calculate-size (:frame overlay) zoom)
|
overlay-size (calculate-size (:frame overlay) zoom children-bounds)
|
||||||
overlay-position {:x (* (:x (:position overlay)) zoom)
|
overlay-position {:x (* (:x (:position overlay)) zoom)
|
||||||
:y (* (:y (:position overlay)) zoom)}]
|
:y (* (:y (:position overlay)) zoom)}]
|
||||||
(interactions/animate-open-overlay
|
(interactions/animate-open-overlay
|
||||||
|
@ -329,7 +344,7 @@
|
||||||
(let [overlay-viewport (dom/get-element (str "overlay-" (str (:overlay-id current-animation))))
|
(let [overlay-viewport (dom/get-element (str "overlay-" (str (:overlay-id current-animation))))
|
||||||
overlay (d/seek #(= (:id (:frame %)) (:overlay-id current-animation))
|
overlay (d/seek #(= (:id (:frame %)) (:overlay-id current-animation))
|
||||||
overlays)
|
overlays)
|
||||||
overlay-size (calculate-size (:frame overlay) zoom)
|
overlay-size (calculate-size (:frame overlay) zoom children-bounds)
|
||||||
overlay-position {:x (* (:x (:position overlay)) zoom)
|
overlay-position {:x (* (:x (:position overlay)) zoom)
|
||||||
:y (* (:y (:position overlay)) zoom)}]
|
:y (* (:y (:position overlay)) zoom)}]
|
||||||
(interactions/animate-close-overlay
|
(interactions/animate-close-overlay
|
||||||
|
@ -392,6 +407,7 @@
|
||||||
:file file
|
:file file
|
||||||
:section section
|
:section section
|
||||||
:local local
|
:local local
|
||||||
|
:size size}
|
||||||
:index index
|
:index index
|
||||||
:viewer-pagination viewer-pagination}]
|
:viewer-pagination viewer-pagination}]
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
(st/emit! (dv/select-shape (:id frame)))))
|
(st/emit! (dv/select-shape (:id frame)))))
|
||||||
|
|
||||||
(mf/defc viewport
|
(mf/defc viewport
|
||||||
[{:keys [local file page frame index viewer-pagination]}]
|
[{:keys [local file page frame index viewer-pagination size]}]
|
||||||
(let [on-mouse-wheel
|
(let [on-mouse-wheel
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(when (kbd/mod? event)
|
(when (kbd/mod? event)
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
[:div.handoff-svg-wrapper {:on-click (handle-select-frame frame)}
|
[:div.handoff-svg-wrapper {:on-click (handle-select-frame frame)}
|
||||||
[:& viewer-pagination {:index index :num-frames (count (:frames page)) :left-bar true :right-bar true}]
|
[:& viewer-pagination {:index index :num-frames (count (:frames page)) :left-bar true :right-bar true}]
|
||||||
[:div.handoff-svg-container
|
[:div.handoff-svg-container
|
||||||
[:& render-frame-svg {:frame frame :page page :local local}]]]
|
[:& render-frame-svg {:frame frame :page page :local local :size size}]]]
|
||||||
|
|
||||||
[:& right-sidebar {:frame frame
|
[:& right-sidebar {:frame frame
|
||||||
:selected (:selected local)
|
:selected (:selected local)
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.shapes.bool :as bool]
|
[app.main.ui.shapes.bool :as bool]
|
||||||
[app.main.ui.shapes.circle :as circle]
|
[app.main.ui.shapes.circle :as circle]
|
||||||
[app.main.ui.shapes.filters :as filters]
|
|
||||||
[app.main.ui.shapes.frame :as frame]
|
[app.main.ui.shapes.frame :as frame]
|
||||||
[app.main.ui.shapes.group :as group]
|
[app.main.ui.shapes.group :as group]
|
||||||
[app.main.ui.shapes.image :as image]
|
[app.main.ui.shapes.image :as image]
|
||||||
|
@ -154,6 +153,10 @@
|
||||||
(let [shape (unchecked-get props "shape")
|
(let [shape (unchecked-get props "shape")
|
||||||
frame (unchecked-get props "frame")
|
frame (unchecked-get props "frame")
|
||||||
|
|
||||||
|
frame-container
|
||||||
|
(mf/use-memo (mf/deps objects)
|
||||||
|
#(frame-container-factory objects))
|
||||||
|
|
||||||
group-container
|
group-container
|
||||||
(mf/use-memo (mf/deps objects)
|
(mf/use-memo (mf/deps objects)
|
||||||
#(group-container-factory objects))
|
#(group-container-factory objects))
|
||||||
|
@ -171,6 +174,7 @@
|
||||||
opts #js {:shape shape
|
opts #js {:shape shape
|
||||||
:frame frame}]
|
:frame frame}]
|
||||||
(case (:type shape)
|
(case (:type shape)
|
||||||
|
:frame [:> frame-container opts]
|
||||||
:text [:> text-wrapper opts]
|
:text [:> text-wrapper opts]
|
||||||
:rect [:> rect-wrapper opts]
|
:rect [:> rect-wrapper opts]
|
||||||
:path [:> path-wrapper opts]
|
:path [:> path-wrapper opts]
|
||||||
|
@ -181,46 +185,31 @@
|
||||||
:svg-raw [:> svg-raw-container opts])))))))
|
:svg-raw [:> svg-raw-container opts])))))))
|
||||||
|
|
||||||
(mf/defc render-frame-svg
|
(mf/defc render-frame-svg
|
||||||
[{:keys [page frame local]}]
|
[{:keys [page frame local size]}]
|
||||||
(let [objects (mf/use-memo
|
(let [objects (mf/use-memo
|
||||||
(mf/deps page frame)
|
(mf/deps page frame)
|
||||||
(prepare-objects page frame))
|
(prepare-objects page frame size))
|
||||||
|
|
||||||
|
|
||||||
;; Retrieve frame again with correct modifier
|
;; Retrieve frame again with correct modifier
|
||||||
frame (get objects (:id frame))
|
frame (get objects (:id frame))
|
||||||
|
|
||||||
zoom (:zoom local 1)
|
|
||||||
|
|
||||||
{:keys [_ _ width height]} (filters/get-filters-bounds frame)
|
|
||||||
padding (filters/calculate-padding frame)
|
|
||||||
x (- (:horizontal padding))
|
|
||||||
y (- (:vertical padding))
|
|
||||||
width (+ width (* 2 (:horizontal padding)))
|
|
||||||
height (+ height (* 2 (:vertical padding)))
|
|
||||||
|
|
||||||
vbox (str x " " y " " width " " height)
|
|
||||||
|
|
||||||
width (* width zoom)
|
|
||||||
height (* height zoom)
|
|
||||||
|
|
||||||
render (mf/use-memo
|
render (mf/use-memo
|
||||||
(mf/deps objects)
|
(mf/deps objects)
|
||||||
#(frame-container-factory objects))]
|
#(frame-container-factory objects))]
|
||||||
|
|
||||||
[:svg
|
[:svg
|
||||||
{:id "svg-frame"
|
{:id "svg-frame"
|
||||||
:view-box vbox
|
:view-box (:vbox size)
|
||||||
:width width
|
:width (:width size)
|
||||||
:height height
|
:height (:height size)
|
||||||
:version "1.1"
|
:version "1.1"
|
||||||
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
||||||
:xmlns "http://www.w3.org/2000/svg"
|
:xmlns "http://www.w3.org/2000/svg"
|
||||||
:fill "none"}
|
:fill "none"}
|
||||||
|
|
||||||
[:& render {:shape frame :view-box vbox}]
|
[:& render {:shape frame :view-box (:vbox size)}]
|
||||||
[:& selection-feedback
|
[:& selection-feedback
|
||||||
{:frame frame
|
{:frame frame
|
||||||
:objects objects
|
:objects objects
|
||||||
:local local}]]))
|
:local local
|
||||||
|
:size size}]]))
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.main.ui.measurements :refer [selection-guides size-display measurement]]
|
[app.main.ui.measurements :refer [size-display measurement]]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
|
@ -52,24 +52,23 @@
|
||||||
:stroke-width selection-rect-width}}]]))
|
:stroke-width selection-rect-width}}]]))
|
||||||
|
|
||||||
(mf/defc selection-feedback
|
(mf/defc selection-feedback
|
||||||
[{:keys [frame local objects]}]
|
[{:keys [frame local objects size]}]
|
||||||
(let [{:keys [hover selected zoom]} local
|
(let [{:keys [hover selected zoom]} local
|
||||||
hover-shape (-> (or (first (resolve-shapes objects [hover])) frame)
|
|
||||||
(gsh/translate-to-frame frame))
|
|
||||||
selected-shapes (->> (resolve-shapes objects selected))
|
|
||||||
|
|
||||||
selrect (gsh/selection-rect selected-shapes)
|
shapes (resolve-shapes objects [hover])
|
||||||
bounds (frame->bounds frame)]
|
hover-shape (or (first shapes) frame)
|
||||||
|
hover-shape (gsh/translate-to-frame hover-shape size)
|
||||||
|
|
||||||
|
selected-shapes (resolve-shapes objects selected)
|
||||||
|
selrect (gsh/selection-rect selected-shapes)]
|
||||||
|
|
||||||
(when (seq selected-shapes)
|
(when (d/not-empty? selected-shapes)
|
||||||
[:g.selection-feedback {:pointer-events "none"}
|
[:g.selection-feedback {:pointer-events "none"}
|
||||||
[:g.selected-shapes
|
[:g.selected-shapes
|
||||||
[:& selection-guides {:bounds bounds :selrect selrect :zoom zoom}]
|
|
||||||
[:& selection-rect {:selrect selrect :zoom zoom}]
|
[:& selection-rect {:selrect selrect :zoom zoom}]
|
||||||
[:& size-display {:selrect selrect :zoom zoom}]]
|
[:& size-display {:selrect selrect :zoom zoom}]]
|
||||||
|
|
||||||
[:& measurement {:bounds bounds
|
[:& measurement {:bounds (assoc size :x 0 :y 0)
|
||||||
:selected-shapes selected-shapes
|
:selected-shapes selected-shapes
|
||||||
:hover-shape hover-shape
|
:hover-shape hover-shape
|
||||||
:zoom zoom}]])))
|
:zoom zoom}]])))
|
||||||
|
|
|
@ -157,6 +157,7 @@
|
||||||
[:ul.dropdown
|
[:ul.dropdown
|
||||||
(for [id (get-in file [:data :pages])]
|
(for [id (get-in file [:data :pages])]
|
||||||
[:li {:id (str id)
|
[:li {:id (str id)
|
||||||
|
:key (str id)
|
||||||
:on-click (partial navigate-to id)}
|
:on-click (partial navigate-to id)}
|
||||||
(get-in file [:data :pages-index id :name])])]]]
|
(get-in file [:data :pages-index id :name])])]]]
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,11 @@
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
(defn prepare-objects
|
(defn prepare-objects
|
||||||
[page frame]
|
[page frame size]
|
||||||
(fn []
|
(fn []
|
||||||
(let [objects (:objects page)
|
(let [objects (:objects page)
|
||||||
frame-id (:id frame)
|
frame-id (:id frame)
|
||||||
modifier (-> (gpt/point (:x frame) (:y frame))
|
modifier (-> (gpt/point (:x size) (:y size))
|
||||||
(gpt/negate)
|
(gpt/negate)
|
||||||
(gmt/translate-matrix))
|
(gmt/translate-matrix))
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [page interactions-mode frame base-frame frame-offset size]}]
|
[{:keys [page interactions-mode frame base-frame frame-offset size]}]
|
||||||
(let [objects (mf/use-memo
|
(let [objects (mf/use-memo
|
||||||
(mf/deps page frame)
|
(mf/deps page frame size)
|
||||||
(prepare-objects page frame))
|
(prepare-objects page frame size))
|
||||||
|
|
||||||
wrapper (mf/use-memo
|
wrapper (mf/use-memo
|
||||||
(mf/deps objects)
|
(mf/deps objects)
|
||||||
|
|
|
@ -376,6 +376,10 @@
|
||||||
(mf/use-memo (mf/deps objects)
|
(mf/use-memo (mf/deps objects)
|
||||||
#(group-container-factory objects))
|
#(group-container-factory objects))
|
||||||
|
|
||||||
|
frame-container
|
||||||
|
(mf/use-memo (mf/deps objects)
|
||||||
|
#(frame-container-factory objects))
|
||||||
|
|
||||||
bool-container
|
bool-container
|
||||||
(mf/use-memo (mf/deps objects)
|
(mf/use-memo (mf/deps objects)
|
||||||
#(bool-container-factory objects))
|
#(bool-container-factory objects))
|
||||||
|
@ -391,7 +395,7 @@
|
||||||
opts #js {:shape shape
|
opts #js {:shape shape
|
||||||
:objects objects}]
|
:objects objects}]
|
||||||
(case (:type shape)
|
(case (:type shape)
|
||||||
:frame [:g.empty]
|
:frame [:> frame-container opts]
|
||||||
:text [:> text-wrapper opts]
|
:text [:> text-wrapper opts]
|
||||||
:rect [:> rect-wrapper opts]
|
:rect [:> rect-wrapper opts]
|
||||||
:path [:> path-wrapper opts]
|
:path [:> path-wrapper opts]
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.ui.viewer.thumbnails
|
(ns app.main.ui.viewer.thumbnails
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.data.macros :as dm]
|
||||||
[app.main.data.viewer :as dv]
|
[app.main.data.viewer :as dv]
|
||||||
[app.main.render :as render]
|
[app.main.render :as render]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -114,6 +115,7 @@
|
||||||
:total (count frames)}
|
:total (count frames)}
|
||||||
(for [[i frame] (d/enumerate frames)]
|
(for [[i frame] (d/enumerate frames)]
|
||||||
[:& thumbnail-item {:index i
|
[:& thumbnail-item {:index i
|
||||||
|
:key (dm/str (:id frame) "-" i)
|
||||||
:frame frame
|
:frame frame
|
||||||
:objects objects
|
:objects objects
|
||||||
:on-click on-item-click
|
:on-click on-item-click
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
(def ^:private type->options
|
(def ^:private type->options
|
||||||
{:bool #{:size :position :rotation}
|
{:bool #{:size :position :rotation}
|
||||||
:circle #{:size :position :rotation}
|
:circle #{:size :position :rotation}
|
||||||
:frame #{:presets :size :position :radius :clip-content :show-in-viewer}
|
:frame #{:presets :size :position :rotation :radius :clip-content :show-in-viewer}
|
||||||
:group #{:size :position :rotation}
|
:group #{:size :position :rotation}
|
||||||
:image #{:size :position :rotation :radius}
|
:image #{:size :position :rotation :radius}
|
||||||
:path #{:size :position :rotation}
|
:path #{:size :position :rotation}
|
||||||
|
|
|
@ -287,6 +287,7 @@
|
||||||
{:objects base-objects
|
{:objects base-objects
|
||||||
:hover #{(->> @hover-ids
|
:hover #{(->> @hover-ids
|
||||||
(filter #(cph/frame-shape? base-objects %))
|
(filter #(cph/frame-shape? base-objects %))
|
||||||
|
(remove selected)
|
||||||
(first))}
|
(first))}
|
||||||
:zoom zoom}])
|
:zoom zoom}])
|
||||||
|
|
||||||
|
@ -400,14 +401,6 @@
|
||||||
|
|
||||||
[:& widgets/viewport-actions]
|
[:& widgets/viewport-actions]
|
||||||
|
|
||||||
(when show-prototypes?
|
|
||||||
[:& interactions/interactions
|
|
||||||
{:selected selected
|
|
||||||
:zoom zoom
|
|
||||||
:objects objects-modified
|
|
||||||
:current-transform transform
|
|
||||||
:hover-disabled? hover-disabled?}])
|
|
||||||
|
|
||||||
[:& scroll-bars/viewport-scrollbars
|
[:& scroll-bars/viewport-scrollbars
|
||||||
{:objects base-objects
|
{:objects base-objects
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
|
@ -444,6 +437,12 @@
|
||||||
:shapes selected-shapes
|
:shapes selected-shapes
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:edition edition
|
:edition edition
|
||||||
:disable-handlers (or drawing-tool edition @space?)}]])
|
:disable-handlers (or drawing-tool edition @space?)}]
|
||||||
|
|
||||||
]]]))
|
(when show-prototypes?
|
||||||
|
[:& interactions/interactions
|
||||||
|
{:selected selected
|
||||||
|
:zoom zoom
|
||||||
|
:objects objects-modified
|
||||||
|
:current-transform transform
|
||||||
|
:hover-disabled? hover-disabled?}])])]]]))
|
||||||
|
|
Loading…
Add table
Reference in a new issue