mirror of
https://github.com/penpot/penpot.git
synced 2026-04-25 11:18:36 +00:00
Merge pull request #9072 from penpot/alotor-fix-swap-component
🐛 Fix problem on component swap
This commit is contained in:
commit
c636517499
@ -61,23 +61,25 @@
|
||||
(js/requestAnimationFrame
|
||||
(fn [_]
|
||||
(try
|
||||
(let [objects (dsh/lookup-page-objects @st/state file-id page-id)
|
||||
frame (get objects frame-id)
|
||||
{:keys [width height]} (:selrect frame)
|
||||
max-size (mth/max width height)
|
||||
scale (mth/max 1 (/ target-size max-size))
|
||||
png-bytes (wasm.api/render-shape-pixels frame-id scale)]
|
||||
(if (or (nil? png-bytes) (zero? (.-length png-bytes)))
|
||||
(do
|
||||
(l/error :hint "render-shape-pixels returned empty" :frame-id (str frame-id))
|
||||
(rx/end! subs))
|
||||
(.then
|
||||
(png-bytes->data-uri png-bytes)
|
||||
(fn [data-uri]
|
||||
(rx/push! subs data-uri)
|
||||
(rx/end! subs))
|
||||
(fn [err]
|
||||
(rx/error! subs err)))))
|
||||
(let [objects (dsh/lookup-page-objects @st/state file-id page-id)]
|
||||
(if-let [frame (get objects frame-id)]
|
||||
(let [{:keys [width height]} (:selrect frame)
|
||||
max-size (mth/max width height)
|
||||
scale (mth/max 1 (/ target-size max-size))
|
||||
png-bytes (wasm.api/render-shape-pixels frame-id scale)]
|
||||
(if (or (nil? png-bytes) (zero? (.-length png-bytes)))
|
||||
(do
|
||||
(l/error :hint "render-shape-pixels returned empty" :frame-id (str frame-id))
|
||||
(rx/end! subs))
|
||||
(.then
|
||||
(png-bytes->data-uri png-bytes)
|
||||
(fn [data-uri]
|
||||
(rx/push! subs data-uri)
|
||||
(rx/end! subs))
|
||||
(fn [err]
|
||||
(rx/error! subs err)))))
|
||||
|
||||
(rx/error! subs "Frame not found")))
|
||||
(catch :default err
|
||||
(rx/error! subs err)))))]
|
||||
#(js/cancelAnimationFrame req-id)))))
|
||||
|
||||
@ -309,7 +309,7 @@
|
||||
;; while the component is still not rendered and the thumbnail URI
|
||||
;; is not available.
|
||||
(mf/use-effect
|
||||
(mf/deps is-hidden thumbnail-uri wasm? current-page-id)
|
||||
(mf/deps is-hidden thumbnail-uri wasm? current-page-id file-id page-id)
|
||||
(fn []
|
||||
(if (some? thumbnail-uri)
|
||||
(mf/set-ref-val! thumbnail-requested? false)
|
||||
|
||||
@ -589,7 +589,7 @@
|
||||
:on-click on-select
|
||||
:disabled loop}
|
||||
(when visible?
|
||||
[:> cmm/component-item-thumbnail* {:file-id (:file-id item)
|
||||
[:> cmm/component-item-thumbnail* {:file-id file-id
|
||||
:class (stl/css :swap-item-thumbnail)
|
||||
:root-shape root-shape
|
||||
:component item
|
||||
|
||||
@ -1017,6 +1017,10 @@ pub extern "C" fn render_shape_pixels(
|
||||
) -> Result<*mut u8> {
|
||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||
|
||||
if !scale.is_finite() {
|
||||
return Err(Error::CriticalError("Scale is not finite".to_string()));
|
||||
}
|
||||
|
||||
with_state_mut!(state, {
|
||||
let (data, width, height) =
|
||||
state.render_shape_pixels(&id, scale, performance::get_time())?;
|
||||
|
||||
@ -938,36 +938,49 @@ impl Surfaces {
|
||||
|
||||
if max_w > self.extra_tile_dims.width || max_h > self.extra_tile_dims.height {
|
||||
self.extra_tile_dims = skia::ISize::new(max_w, max_h);
|
||||
self.drop_shadows = self
|
||||
|
||||
if let Some(surface) = self
|
||||
.drop_shadows
|
||||
.new_surface_with_dimensions((max_w, max_h))
|
||||
.unwrap();
|
||||
self.inner_shadows = self
|
||||
{
|
||||
self.drop_shadows = surface;
|
||||
}
|
||||
|
||||
if let Some(surface) = self
|
||||
.inner_shadows
|
||||
.new_surface_with_dimensions((max_w, max_h))
|
||||
.unwrap();
|
||||
self.text_drop_shadows = self
|
||||
{
|
||||
self.inner_shadows = surface;
|
||||
}
|
||||
|
||||
if let Some(surface) = self
|
||||
.text_drop_shadows
|
||||
.new_surface_with_dimensions((max_w, max_h))
|
||||
.unwrap();
|
||||
self.text_drop_shadows = self
|
||||
.text_drop_shadows
|
||||
.new_surface_with_dimensions((max_w, max_h))
|
||||
.unwrap();
|
||||
self.shape_strokes = self
|
||||
{
|
||||
self.text_drop_shadows = surface;
|
||||
}
|
||||
|
||||
if let Some(surface) = self
|
||||
.shape_strokes
|
||||
.new_surface_with_dimensions((max_w, max_h))
|
||||
.unwrap();
|
||||
self.shape_fills = self
|
||||
{
|
||||
self.shape_strokes = surface;
|
||||
}
|
||||
|
||||
if let Some(surface) = self
|
||||
.shape_strokes
|
||||
.new_surface_with_dimensions((max_w, max_h))
|
||||
.unwrap();
|
||||
{
|
||||
self.shape_fills = surface;
|
||||
}
|
||||
}
|
||||
|
||||
self.export = self
|
||||
if let Some(surface) = self
|
||||
.export
|
||||
.new_surface_with_dimensions((target_w, target_h))
|
||||
.unwrap();
|
||||
{
|
||||
self.export = surface;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -314,9 +314,9 @@ pub extern "C" fn set_shape_grow_type(grow_type: u8) {
|
||||
with_current_shape_mut!(state, |shape: &mut Shape| {
|
||||
if let Type::Text(text_content) = &mut shape.shape_type {
|
||||
text_content.set_grow_type(GrowType::from(grow_type));
|
||||
} else {
|
||||
panic!("Trying to update grow type in a shape that it's not a text shape");
|
||||
}
|
||||
// Don't throw error if the object is not text.
|
||||
// On swap component opperations is convenient.
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user