cleaning + fmt

This commit is contained in:
Martin Kavík 2024-10-08 18:54:21 +02:00
parent 1d20d3ac56
commit d7874e728b
6 changed files with 37 additions and 168 deletions

View file

@ -6,17 +6,14 @@ pub use excalidraw_canvas::ExcalidrawController;
#[derive(Clone)] #[derive(Clone)]
pub struct DiagramPanel { pub struct DiagramPanel {
canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>> canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>>,
} }
impl DiagramPanel { impl DiagramPanel {
pub fn new( pub fn new(
canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>>, canvas_controller: Mutable<Mutable<Option<SendWrapper<ExcalidrawController>>>>,
) -> impl Element { ) -> impl Element {
Self { Self { canvas_controller }.root()
canvas_controller
}
.root()
} }
fn root(&self) -> impl Element { fn root(&self) -> impl Element {
@ -26,7 +23,6 @@ impl DiagramPanel {
.s(Width::fill()) .s(Width::fill())
.s(Height::fill()) .s(Height::fill())
.s(Gap::new().y(20)) .s(Gap::new().y(20))
.item("Diagram panel")
.item(self.canvas()) .item(self.canvas())
} }
@ -38,7 +34,6 @@ impl DiagramPanel {
.s(Height::fill()) .s(Height::fill())
.task_with_controller(move |controller| { .task_with_controller(move |controller| {
canvas_controller.set(controller.clone()); canvas_controller.set(controller.clone());
zoon::println!("hello from task_with_controller");
async {} async {}
}) })
} }

View file

@ -4,10 +4,6 @@ use zoon::*;
pub struct ExcalidrawCanvas { pub struct ExcalidrawCanvas {
raw_el: RawHtmlEl<web_sys::HtmlElement>, raw_el: RawHtmlEl<web_sys::HtmlElement>,
controller: Mutable<Option<SendWrapper<js_bridge::ExcalidrawController>>>, controller: Mutable<Option<SendWrapper<js_bridge::ExcalidrawController>>>,
#[allow(dead_code)]
width: ReadOnlyMutable<u32>,
#[allow(dead_code)]
height: ReadOnlyMutable<u32>,
task_with_controller: Mutable<Option<TaskHandle>>, task_with_controller: Mutable<Option<TaskHandle>>,
} }
@ -32,35 +28,13 @@ impl ExcalidrawCanvas {
pub fn new() -> Self { pub fn new() -> Self {
let controller: Mutable<Option<SendWrapper<js_bridge::ExcalidrawController>>> = let controller: Mutable<Option<SendWrapper<js_bridge::ExcalidrawController>>> =
Mutable::new(None); Mutable::new(None);
let width = Mutable::new(0);
let height = Mutable::new(0);
let resize_task = Task::start_droppable(
map_ref! {
let width = width.signal(),
let height = height.signal() => (*width, *height)
}
.dedupe()
.throttle(|| Timer::sleep(50))
.for_each(
clone!((controller) move |(width, height)| clone!((controller) async move {
if let Some(controller) = controller.lock_ref().as_ref() {
controller.resize(width, height).await
}
})),
),
);
let task_with_controller = Mutable::new(None); let task_with_controller = Mutable::new(None);
Self { Self {
controller: controller.clone(), controller: controller.clone(),
width: width.read_only(),
height: height.read_only(),
task_with_controller: task_with_controller.clone(), task_with_controller: task_with_controller.clone(),
raw_el: El::new() raw_el: El::new()
.s(RoundedCorners::all(10))
.s(Clip::both()) .s(Clip::both())
.on_viewport_size_change(clone!((width, height) move |new_width, new_height| {
width.set_neq(new_width);
height.set_neq(new_height);
}))
.after_insert(clone!((controller) move |element| { .after_insert(clone!((controller) move |element| {
Task::start(async move { Task::start(async move {
let excalidraw_controller = SendWrapper::new(js_bridge::ExcalidrawController::new()); let excalidraw_controller = SendWrapper::new(js_bridge::ExcalidrawController::new());
@ -69,11 +43,7 @@ impl ExcalidrawCanvas {
}); });
})) }))
.after_remove(move |_| { .after_remove(move |_| {
drop(resize_task);
drop(task_with_controller); drop(task_with_controller);
if let Some(controller) = controller.take() {
controller.destroy();
}
}) })
.into_raw_el(), .into_raw_el(),
} }
@ -103,16 +73,5 @@ mod js_bridge {
#[wasm_bindgen(method)] #[wasm_bindgen(method)]
pub async fn init(this: &ExcalidrawController, parent_element: &JsValue); pub async fn init(this: &ExcalidrawController, parent_element: &JsValue);
#[wasm_bindgen(method)]
pub async fn resize(this: &ExcalidrawController, width: u32, height: u32);
#[wasm_bindgen(method)]
pub fn destroy(this: &ExcalidrawController);
// -- FastWave-specific --
#[wasm_bindgen(method)]
pub fn hello(this: &ExcalidrawController);
} }
} }

View file

@ -2,8 +2,6 @@ use crate::{platform, theme::*, Filename, Layout, Mode};
use std::sync::Arc; use std::sync::Arc;
use zoon::*; use zoon::*;
pub struct HeaderPanel { pub struct HeaderPanel {
hierarchy: Mutable<Option<Arc<wellen::Hierarchy>>>, hierarchy: Mutable<Option<Arc<wellen::Hierarchy>>>,
layout: Mutable<Layout>, layout: Mutable<Layout>,
@ -38,7 +36,7 @@ impl HeaderPanel {
.s(Gap::both(15)) .s(Gap::both(15))
.item(self.load_button()) .item(self.load_button())
.item(self.layout_switcher()) .item(self.layout_switcher())
.item(self.mode_switcher()) .item(self.mode_switcher()),
) )
} }

View file

@ -8,7 +8,7 @@ mod controls_panel;
use controls_panel::ControlsPanel; use controls_panel::ControlsPanel;
mod diagram_panel; mod diagram_panel;
use diagram_panel::{ExcalidrawController, DiagramPanel}; use diagram_panel::{DiagramPanel, ExcalidrawController};
mod waveform_panel; mod waveform_panel;
use waveform_panel::{PixiController, WaveformPanel}; use waveform_panel::{PixiController, WaveformPanel};

View file

@ -74737,51 +74737,29 @@ var require_client = __commonJS({
var import_excalidraw = __toESM(require_main()); var import_excalidraw = __toESM(require_main());
var React = __toESM(require_react()); var React = __toESM(require_react());
var ReactDOM = __toESM(require_client()); var ReactDOM = __toESM(require_client());
function attach_to_canvas() {
const App = () => {
return React.createElement(
React.Fragment,
null,
React.createElement(
"div",
{
style: { height: "500px" }
},
React.createElement(import_excalidraw.Excalidraw)
)
);
};
const excalidrawWrapper = document.getElementById("excalidraw_canvas");
const root = ReactDOM.createRoot(excalidrawWrapper);
}
var ExcalidrawController = class { var ExcalidrawController = class {
// app: Application
// // -- FastWave-specific --
// var_signal_rows: Array<VarSignalRow> = [];
// var_signal_rows_container = new Container();
// // @TODO reset `timeline_*` on file unload?
// timeline_zoom: number;
// timeline_viewport_width: number;
// timeline_viewport_x: number;
// row_height: number;
// row_gap: number;
// timeline_getter: TimelineGetter;
constructor() { constructor() {
this.hello();
} }
async init(parent_element) { async init(parent_element) {
} const App = () => {
async resize(width, _height) { return React.createElement(
} React.Fragment,
destroy() { null,
} React.createElement(
hello() { "div",
console.log("Hello from excalidraw_canvas TS"); {
style: { height: "100%" }
},
React.createElement(import_excalidraw.Excalidraw)
)
);
};
const root = ReactDOM.createRoot(parent_element);
root.render(React.createElement(App));
} }
}; };
export { export {
ExcalidrawController, ExcalidrawController
attach_to_canvas
}; };
/*! Bundled license information: /*! Bundled license information:

View file

@ -2,86 +2,25 @@ import { Excalidraw } from '@excalidraw/excalidraw'
import * as React from 'react' import * as React from 'react'
import * as ReactDOM from 'react-dom/client' import * as ReactDOM from 'react-dom/client'
export function attach_to_canvas() {
const App = () => {
return React.createElement(
React.Fragment,
null,
React.createElement(
"div",
{
style: { height: "500px" },
},
React.createElement(Excalidraw),
),
);
};
const excalidrawWrapper = document.getElementById("excalidraw_canvas");
const root = ReactDOM.createRoot(excalidrawWrapper!);
}
export class ExcalidrawController { export class ExcalidrawController {
// app: Application constructor() {}
// // -- FastWave-specific --
// var_signal_rows: Array<VarSignalRow> = [];
// var_signal_rows_container = new Container();
// // @TODO reset `timeline_*` on file unload?
// timeline_zoom: number;
// timeline_viewport_width: number;
// timeline_viewport_x: number;
// row_height: number;
// row_gap: number;
// timeline_getter: TimelineGetter;
constructor(
// timeline_zoom: number,
// timeline_viewport_width: number,
// timeline_viewport_x: number,
// row_height: number,
// row_gap: number,
// timeline_getter: TimelineGetter
) {
this.hello()
// this.app = new Application();
// // -- FastWave-specific --
// this.timeline_zoom = timeline_zoom;
// this.timeline_viewport_width = timeline_viewport_width;
// this.timeline_viewport_x = timeline_viewport_x;
// this.row_height = row_height;
// this.row_gap = row_gap;
// this.app.stage.addChild(this.var_signal_rows_container);
// this.timeline_getter = timeline_getter;
}
async init(parent_element: HTMLElement) { async init(parent_element: HTMLElement) {
// await this.app.init({ background: color_dark_slate_blue, antialias: true, resizeTo: parent_element }); const App = () => {
// parent_element.appendChild(this.app.canvas); return React.createElement(
} React.Fragment,
null,
async resize(width: number, _height: number) { React.createElement(
// // -- FastWave-specific -- "div",
// this.timeline_viewport_width = width; {
// await this.redraw_all_rows(); style: { height: "100%" },
// // -- // -- },
// this.app.queueResize(); React.createElement(Excalidraw),
} ),
);
destroy() { };
// const rendererDestroyOptions = { const root = ReactDOM.createRoot(parent_element);
// removeView: true root.render(React.createElement(App));
// }
// const options = {
// children: true,
// texture: true,
// textureSource: true,
// context: true,
// }
// this.app.destroy(rendererDestroyOptions, options);
}
hello() {
console.log("Hello from excalidraw_canvas TS")
} }
} }