#![deny(unsafe_code)]
#![forbid(unstable_features)]
#![warn(missing_docs, rust_2018_idioms)]
use dioxus::prelude::*;
#[doc(no_inline)]
pub use taino_edit_core::{
base_keymap, lift, remove_mark, select_all, set_block_type, set_mark, split_block, toggle_mark,
wrap_in, AttrSpec, AttrValue, Attrs, Command, Dispatch, EditorState, KeyPress, Keymap, Mark,
MarkSpec, MarkType, Node, NodeSpec, NodeType, Plugin, PluginKey, PluginSet, ResolvedPos,
Schema, SchemaBuilder, Selection, Slice, Transaction, Transform,
};
#[doc(no_inline)]
pub use taino_edit_dom::{Decoration, EditorView, ViewDesc};
#[component]
pub fn TainoEditor(state: Signal<EditorState>) -> Element {
let mut runtime: Signal<Option<EditorView>> = use_signal(|| None);
use_effect(move || {
let snapshot = state.read().clone();
if let Some(view) = runtime.write().as_mut() {
view.update(snapshot.doc().clone());
if view.read_selection() != Some(snapshot.selection()) {
let _ = view.set_selection(snapshot.selection());
}
}
});
let on_mounted = move |evt: Event<MountedData>| {
let Some(html_el) = evt.data().downcast::<web_sys::Element>().cloned() else {
return;
};
let snapshot = state.read().clone();
let view = EditorView::mount(snapshot.doc().clone(), snapshot.schema().clone(), html_el);
runtime.set(Some(view));
};
rsx! {
div {
class: "taino-editor",
onmounted: on_mounted,
}
}
}