mirror of
https://github.com/penpot/penpot.git
synced 2026-05-30 12:18:13 +00:00
♻️ Rename measurement and svg-defs components to defc* form (#9306)
Adopts the rumext * suffix convention for the following components,
invoking them with the [:> JS-style syntax to match the rest of the
codebase (see e.g. rea*, single-selection* in viewport/selection):
- measurements: size-display, distance-display-pill, selection-rect,
distance-display, selection-guides, measurement
- shapes/svg-defs: svg-node, svg-defs (also drop the now-redundant
{::mf/wrap-props false} annotations)
Updates all call sites in inspect/selection_feedback, shapes/shape,
workspace/viewport, and workspace/viewport_wasm. Pure rename — no
behavioral change.
Signed-off-by: bitcompass <devwiz.sh@gmail.com>
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
3885c9ee74
commit
3433b41aa8
@ -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 [size-display measurement]]
|
[app.main.ui.measurements :refer [size-display* measurement*]]
|
||||||
[rumext.v2 :as mf]))
|
[rumext.v2 :as mf]))
|
||||||
|
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
@ -64,9 +64,9 @@
|
|||||||
[:g.selection-feedback {:pointer-events "none"}
|
[:g.selection-feedback {:pointer-events "none"}
|
||||||
[:g.selected-shapes
|
[:g.selected-shapes
|
||||||
[:& 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 (assoc size :x 0 :y 0)
|
[:> 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}]])))
|
||||||
|
|||||||
@ -96,7 +96,7 @@
|
|||||||
;; COMPONENTS
|
;; COMPONENTS
|
||||||
;; ------------------------------------------------
|
;; ------------------------------------------------
|
||||||
|
|
||||||
(mf/defc size-display [{:keys [selrect zoom]}]
|
(mf/defc size-display* [{:keys [selrect zoom]}]
|
||||||
(let [{:keys [x y width height]} selrect
|
(let [{:keys [x y width height]} selrect
|
||||||
size-label (dm/str (fmt/format-number width) " x " (fmt/format-number height))
|
size-label (dm/str (fmt/format-number width) " x " (fmt/format-number height))
|
||||||
|
|
||||||
@ -123,7 +123,7 @@
|
|||||||
:font-size (/ font-size zoom)}}
|
:font-size (/ font-size zoom)}}
|
||||||
size-label]]))
|
size-label]]))
|
||||||
|
|
||||||
(mf/defc distance-display-pill [{:keys [x y zoom distance bounds]}]
|
(mf/defc distance-display-pill* [{:keys [x y zoom distance bounds]}]
|
||||||
(let [distance-pill-width (/ distance-pill-width zoom)
|
(let [distance-pill-width (/ distance-pill-width zoom)
|
||||||
distance-pill-height (/ distance-pill-height zoom)
|
distance-pill-height (/ distance-pill-height zoom)
|
||||||
font-size (/ font-size zoom)
|
font-size (/ font-size zoom)
|
||||||
@ -167,7 +167,7 @@
|
|||||||
:font-size font-size}}
|
:font-size font-size}}
|
||||||
(fmt/format-pixels distance)]]))
|
(fmt/format-pixels distance)]]))
|
||||||
|
|
||||||
(mf/defc selection-rect [{:keys [selrect zoom]}]
|
(mf/defc selection-rect* [{:keys [selrect zoom]}]
|
||||||
(let [{:keys [x y width height]} selrect
|
(let [{:keys [x y width height]} selrect
|
||||||
selection-rect-width (/ selection-rect-width zoom)]
|
selection-rect-width (/ selection-rect-width zoom)]
|
||||||
[:g.selection-rect
|
[:g.selection-rect
|
||||||
@ -179,7 +179,7 @@
|
|||||||
:stroke hover-color
|
:stroke hover-color
|
||||||
:stroke-width selection-rect-width}}]]))
|
:stroke-width selection-rect-width}}]]))
|
||||||
|
|
||||||
(mf/defc distance-display [{:keys [from to zoom bounds]}]
|
(mf/defc distance-display* [{:keys [from to zoom bounds]}]
|
||||||
(let [fixed-x (if (gsh/fully-contained? from to)
|
(let [fixed-x (if (gsh/fully-contained? from to)
|
||||||
(+ (:x to) (/ (:width to) 2))
|
(+ (:x to) (/ (:width to) 2))
|
||||||
(+ (:x from) (/ (:width from) 2)))
|
(+ (:x from) (/ (:width from) 2)))
|
||||||
@ -211,14 +211,14 @@
|
|||||||
:style {:stroke distance-color
|
:style {:stroke distance-color
|
||||||
:stroke-width distance-line-stroke}}]
|
:stroke-width distance-line-stroke}}]
|
||||||
|
|
||||||
[:& distance-display-pill
|
[:> distance-display-pill*
|
||||||
{:x center-x
|
{:x center-x
|
||||||
:y center-y
|
:y center-y
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:distance distance
|
:distance distance
|
||||||
:bounds bounds}]])))))
|
:bounds bounds}]])))))
|
||||||
|
|
||||||
(mf/defc selection-guides [{:keys [bounds selrect zoom]}]
|
(mf/defc selection-guides* [{:keys [bounds selrect zoom]}]
|
||||||
[:g.selection-guides
|
[:g.selection-guides
|
||||||
(for [[idx [x1 y1 x2 y2]] (d/enumerate (calculate-guides bounds selrect))]
|
(for [[idx [x1 y1 x2 y2]] (d/enumerate (calculate-guides bounds selrect))]
|
||||||
[:line {:key (dm/str "guide-" idx)
|
[:line {:key (dm/str "guide-" idx)
|
||||||
@ -230,7 +230,7 @@
|
|||||||
:stroke-width (/ select-guide-width zoom)
|
:stroke-width (/ select-guide-width zoom)
|
||||||
:stroke-dasharray (/ select-guide-dasharray zoom)}}])])
|
:stroke-dasharray (/ select-guide-dasharray zoom)}}])])
|
||||||
|
|
||||||
(mf/defc measurement
|
(mf/defc measurement*
|
||||||
[{:keys [bounds frame selected-shapes hover-shape zoom]}]
|
[{:keys [bounds frame selected-shapes hover-shape zoom]}]
|
||||||
(let [selected-ids (into #{} (map :id) selected-shapes)
|
(let [selected-ids (into #{} (map :id) selected-shapes)
|
||||||
selected-selrect (gsh/shapes->rect selected-shapes)
|
selected-selrect (gsh/shapes->rect selected-shapes)
|
||||||
@ -240,23 +240,23 @@
|
|||||||
|
|
||||||
(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
|
[:> selection-guides* {:selrect selected-selrect
|
||||||
:bounds bounds
|
:bounds bounds
|
||||||
:zoom zoom}]
|
: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)))
|
||||||
(let [frame-bb (-> (:points frame) (grc/points->rect))]
|
(let [frame-bb (-> (:points frame) (grc/points->rect))]
|
||||||
[:g.hover-shapes
|
[:g.hover-shapes
|
||||||
[:& selection-rect {:type :hover :selrect frame-bb :zoom zoom}]
|
[:> selection-rect* {:type :hover :selrect frame-bb :zoom zoom}]
|
||||||
[:& distance-display {:from frame-bb
|
[:> distance-display* {:from frame-bb
|
||||||
:to selected-selrect
|
:to selected-selrect
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
:bounds bounds-selrect}]]))
|
: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}]
|
||||||
[:& size-display {:selrect hover-selrect :zoom zoom}]
|
[:> size-display* {:selrect hover-selrect :zoom zoom}]
|
||||||
[:& distance-display {:from hover-selrect :to selected-selrect :zoom zoom :bounds bounds-selrect}]])])))
|
[:> distance-display* {:from hover-selrect :to selected-selrect :zoom zoom :bounds bounds-selrect}]])])))
|
||||||
|
|
||||||
|
|||||||
@ -125,7 +125,7 @@
|
|||||||
[:& ed/export-data {:shape shape}])
|
[:& ed/export-data {:shape shape}])
|
||||||
|
|
||||||
[:defs
|
[:defs
|
||||||
[:& defs/svg-defs {:shape shape :render-id render-id}]
|
[:> defs/svg-defs* {:shape shape :render-id render-id}]
|
||||||
|
|
||||||
;; The filters for frames should be setup inside the container.
|
;; The filters for frames should be setup inside the container.
|
||||||
(when-not (cfh/frame-shape? shape)
|
(when-not (cfh/frame-shape? shape)
|
||||||
|
|||||||
@ -24,8 +24,7 @@
|
|||||||
(str transform-matrix " " val)
|
(str transform-matrix " " val)
|
||||||
(str transform-matrix)))))
|
(str transform-matrix)))))
|
||||||
|
|
||||||
(mf/defc svg-node
|
(mf/defc svg-node*
|
||||||
{::mf/wrap-props false}
|
|
||||||
[{:keys [type node prefix-id transform bounds]}]
|
[{:keys [type node prefix-id transform bounds]}]
|
||||||
(cond
|
(cond
|
||||||
(string? node) node
|
(string? node) node
|
||||||
@ -91,12 +90,12 @@
|
|||||||
[:> (name tag) props
|
[:> (name tag) props
|
||||||
[:> wrapper wrapper-props
|
[:> wrapper wrapper-props
|
||||||
(for [[index node] (d/enumerate content)]
|
(for [[index node] (d/enumerate content)]
|
||||||
[:& svg-node {:key (dm/str "node-" index)
|
[:> svg-node* {:key (dm/str "node-" index)
|
||||||
:type type
|
:type type
|
||||||
:node node
|
:node node
|
||||||
:prefix-id prefix-id
|
:prefix-id prefix-id
|
||||||
:transform transform
|
:transform transform
|
||||||
:bounds bounds}])]])))
|
:bounds bounds}])]])))
|
||||||
|
|
||||||
(defn- get-svg-def-bounds
|
(defn- get-svg-def-bounds
|
||||||
[{:keys [tag attrs] :as node} shape transform]
|
[{:keys [tag attrs] :as node} shape transform]
|
||||||
@ -108,8 +107,7 @@
|
|||||||
(gsh/transform-rect transform))
|
(gsh/transform-rect transform))
|
||||||
(gsb/get-shape-filter-bounds shape)))
|
(gsb/get-shape-filter-bounds shape)))
|
||||||
|
|
||||||
(mf/defc svg-defs
|
(mf/defc svg-defs*
|
||||||
{::mf/wrap-props false}
|
|
||||||
[{:keys [shape render-id]}]
|
[{:keys [shape render-id]}]
|
||||||
(let [defs (:svg-defs shape)
|
(let [defs (:svg-defs shape)
|
||||||
|
|
||||||
@ -131,9 +129,9 @@
|
|||||||
(contains? defs id) (str render-id "-"))))]
|
(contains? defs id) (str render-id "-"))))]
|
||||||
|
|
||||||
(for [[key node] defs]
|
(for [[key node] defs]
|
||||||
[:& svg-node {:key (dm/str key)
|
[:> svg-node* {:key (dm/str key)
|
||||||
:type (:type shape)
|
:type (:type shape)
|
||||||
:node node
|
:node node
|
||||||
:prefix-id prefix-id
|
:prefix-id prefix-id
|
||||||
:transform transform
|
:transform transform
|
||||||
:bounds (get-svg-def-bounds node shape transform)}])))
|
:bounds (get-svg-def-bounds node shape transform)}])))
|
||||||
|
|||||||
@ -501,7 +501,7 @@
|
|||||||
:modifiers modifiers}])
|
:modifiers modifiers}])
|
||||||
|
|
||||||
(when show-measures?
|
(when show-measures?
|
||||||
[:& msr/measurement
|
[:> msr/measurement*
|
||||||
{:bounds vbox
|
{:bounds vbox
|
||||||
:selected-shapes selected-shapes
|
:selected-shapes selected-shapes
|
||||||
:frame selected-frame
|
:frame selected-frame
|
||||||
@ -510,7 +510,7 @@
|
|||||||
|
|
||||||
;; Show distances during movement with ALT
|
;; Show distances during movement with ALT
|
||||||
(when (and (= transform :move) @alt? (seq selected-shapes))
|
(when (and (= transform :move) @alt? (seq selected-shapes))
|
||||||
[:& msr/measurement
|
[:> msr/measurement*
|
||||||
{:bounds vbox
|
{:bounds vbox
|
||||||
:selected-shapes selected-shapes
|
:selected-shapes selected-shapes
|
||||||
:frame selected-frame
|
:frame selected-frame
|
||||||
@ -522,7 +522,7 @@
|
|||||||
duplicated-info (get-in @(deref state-var) [:workspace-local :duplicated])]
|
duplicated-info (get-in @(deref state-var) [:workspace-local :duplicated])]
|
||||||
(when (and (= transform :move) @alt? duplicated-info)
|
(when (and (= transform :move) @alt? duplicated-info)
|
||||||
[:g.duplicated-distance
|
[:g.duplicated-distance
|
||||||
[:& msr/distance-display
|
[:> msr/distance-display*
|
||||||
{:from (get duplicated-info :selrect-original)
|
{:from (get duplicated-info :selrect-original)
|
||||||
:to (get duplicated-info :selrect-duplicated)
|
:to (get duplicated-info :selrect-duplicated)
|
||||||
:zoom zoom
|
:zoom zoom
|
||||||
|
|||||||
@ -654,7 +654,7 @@
|
|||||||
:zoom zoom}])
|
:zoom zoom}])
|
||||||
|
|
||||||
(when show-measures?
|
(when show-measures?
|
||||||
[:& msr/measurement
|
[:> msr/measurement*
|
||||||
{:bounds vbox
|
{:bounds vbox
|
||||||
:selected-shapes selected-shapes
|
:selected-shapes selected-shapes
|
||||||
:frame selected-frame
|
:frame selected-frame
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user