fork: remove dodrio and stdweb stuff for now

This commit is contained in:
Ashley Williams 2022-12-15 17:27:58 -06:00
parent d4bec7a233
commit 37c410a53c
6 changed files with 3 additions and 253 deletions

View File

@ -9,8 +9,8 @@ description = "Type checked JSX for Rust (proc_macro crate)"
repository = "https://github.com/bodil/typed-html"
documentation = "http://docs.rs/typed-html/"
readme = "../README.md"
categories = ["template-engine", "wasm", "web-programming"]
keywords = ["jsx", "html", "wasm"]
categories = ["template-engine", "web-programming"]
keywords = ["jsx", "html"]
[lib]
proc-macro = true
@ -24,6 +24,3 @@ quote = "1.0.2"
[build-dependencies]
lalrpop = "0.19"
version_check = "0.9.1"
[features]
dodrio = []

View File

@ -60,26 +60,6 @@ impl Node {
}
}
}
#[cfg(feature = "dodrio")]
pub fn into_dodrio_token_stream(
self,
bump: &Ident,
is_req_child: bool,
) -> Result<TokenStream, TokenStream> {
match self {
Node::Element(el) => el.into_dodrio_token_stream(bump, is_req_child),
Node::Text(text) => Ok(dodrio_text_node(text)),
Node::Block(group) => {
let span = group.span();
let error =
"you cannot use a block as a top level element or a required child element";
Err(quote_spanned! { span=>
compile_error! { #error }
})
}
}
}
}
#[derive(Clone)]
@ -89,12 +69,6 @@ pub struct Element {
pub children: Vec<Node>,
}
#[cfg(feature = "dodrio")]
fn dodrio_text_node(text: Literal) -> TokenStream {
let text = TokenTree::Literal(text);
quote!(dodrio::builder::text(#text))
}
fn extract_data_attrs(attrs: &mut StringyMap<Ident, TokenTree>) -> StringyMap<String, TokenTree> {
let mut data = StringyMap::new();
let keys: Vec<Ident> = attrs.keys().cloned().collect();

View File

@ -163,8 +163,7 @@
//! The DOM tree structure also implements a method called `vnode()`, which renders
//! the tree to a tree of [`VNode`][VNode]s, which is a mirror of the generated tree
//! with every attribute value rendered into `String`s. You can walk this virtual
//! DOM tree and use it to build an actual DOM tree with `stdweb` or pass it on to
//! your favourite virtual DOM system.
//! DOM tree and pass it on to your favourite virtual DOM system.
//!
//! # License
//!
@ -193,13 +192,9 @@ use std::fmt::Display;
pub use axohtml_macros::html;
#[cfg(feature = "dodrio_macro")]
pub use axohtml_macros::dodrio;
pub mod dom;
pub mod elements;
pub mod events;
pub mod output;
pub mod types;
/// Marker trait for outputs

View File

@ -1,20 +0,0 @@
use std::fmt::{Display, Error, Formatter};
use crate::OutputType;
/// DOM output using the Dodrio virtual DOM
pub struct Dodrio;
impl OutputType for Dodrio {
type Events = Events;
type EventTarget = ();
type EventListenerHandle = ();
}
#[derive(Default)]
pub struct Events;
impl Display for Events {
fn fmt(&self, _: &mut Formatter) -> Result<(), Error> {
unimplemented!()
}
}

View File

@ -1,4 +0,0 @@
#[cfg(feature = "dodrio_macro")]
pub mod dodrio;
#[cfg(feature = "stdweb")]
pub mod stdweb;

View File

@ -1,192 +0,0 @@
use std::fmt::{Display, Error, Formatter};
use std::marker::PhantomData;
use stdweb::web::event::*;
use stdweb::web::{self, Element, EventListenerHandle, IElement, IEventTarget, INode};
use crate::dom::VNode;
use crate::events::EventHandler;
use crate::OutputType;
/// DOM output using the stdweb crate
pub struct Stdweb;
impl OutputType for Stdweb {
type Events = Events;
type EventTarget = Element;
type EventListenerHandle = EventListenerHandle;
}
macro_rules! declare_events {
($($name:ident : $type:ty ,)*) => {
/// Container type for DOM events.
pub struct Events {
$(
pub $name: Option<Box<dyn EventHandler<Stdweb, $type> + Send>>,
)*
}
impl Default for Events {
fn default() -> Self {
Events {
$(
$name: None,
)*
}
}
}
/// Iterate over the defined events on a DOM object.
#[macro_export]
macro_rules! for_events {
($event:ident in $events:expr => $body:block) => {
$(
if let Some(ref mut $event) = $events.$name $body
)*
}
}
}
}
// TODO? these are all the "on*" attributes defined in the HTML5 standard, with
// the ones I've been unable to match to stdweb event types commented out.
//
// This needs review.
declare_events! {
abort: ResourceAbortEvent,
// autocomplete: Event,
// autocompleteerror: Event,
blur: BlurEvent,
// cancel: Event,
// canplay: Event,
// canplaythrough: Event,
change: ChangeEvent,
click: ClickEvent,
// close: Event,
contextmenu: ContextMenuEvent,
// cuechange: Event,
dblclick: DoubleClickEvent,
drag: DragEvent,
dragend: DragEndEvent,
dragenter: DragEnterEvent,
dragexit: DragExitEvent,
dragleave: DragLeaveEvent,
dragover: DragOverEvent,
dragstart: DragStartEvent,
drop: DragDropEvent,
// durationchange: Event,
// emptied: Event,
// ended: Event,
error: ResourceErrorEvent,
focus: FocusEvent,
input: InputEvent,
// invalid: Event,
keydown: KeyDownEvent,
keypress: KeyPressEvent,
keyup: KeyUpEvent,
load: ResourceLoadEvent,
// loadeddata: Event,
// loadedmetadata: Event,
loadstart: LoadStartEvent,
mousedown: MouseDownEvent,
mouseenter: MouseEnterEvent,
mouseleave: MouseLeaveEvent,
mousemove: MouseMoveEvent,
mouseout: MouseOutEvent,
mouseover: MouseOverEvent,
mouseup: MouseUpEvent,
mousewheel: MouseWheelEvent,
// pause: Event,
// play: Event,
// playing: Event,
progress: ProgressEvent,
// ratechange: Event,
// reset: Event,
resize: ResizeEvent,
scroll: ScrollEvent,
// seeked: Event,
// seeking: Event,
// select: Event,
// show: Event,
// sort: Event,
// stalled: Event,
submit: SubmitEvent,
// suspend: Event,
// timeupdate: Event,
// toggle: Event,
// volumechange: Event,
// waiting: Event,
}
impl Display for Events {
fn fmt(&self, _f: &mut Formatter) -> Result<(), Error> {
Ok(())
}
}
/// Wrapper type for closures as event handlers.
pub struct EFn<F, E>(Option<F>, PhantomData<E>);
impl<F, E> EFn<F, E>
where
F: FnMut(E) + 'static + Send,
{
pub fn new(f: F) -> Self {
EFn(Some(f), PhantomData)
}
}
impl<F, E> From<F> for Box<dyn EventHandler<Stdweb, E> + Send>
where
F: FnMut(E) + 'static + Send,
E: ConcreteEvent + 'static + Send,
{
fn from(f: F) -> Self {
Box::new(EFn::new(f))
}
}
impl<F, E> EventHandler<Stdweb, E> for EFn<F, E>
where
F: FnMut(E) + 'static + Send,
E: ConcreteEvent + 'static + Send,
{
fn attach(&mut self, target: &mut <Stdweb as OutputType>::EventTarget) -> EventListenerHandle {
let handler = self.0.take().unwrap();
target.add_event_listener(handler)
}
fn render(&self) -> Option<String> {
None
}
}
impl Stdweb {
pub fn install_handlers(target: &mut Element, handlers: &mut Events) {
for_events!(handler in handlers => {
handler.attach(target);
});
}
pub fn build(
document: &web::Document,
vnode: VNode<'_, Stdweb>,
) -> Result<web::Node, web::error::InvalidCharacterError> {
match vnode {
VNode::Text(text) => Ok(document.create_text_node(text).into()),
VNode::UnsafeText(text) => Ok(document.create_text_node(text).into()),
VNode::Element(element) => {
let mut node = document.create_element(element.name)?;
for (key, value) in element.attributes {
node.set_attribute(key, &value)?;
}
Stdweb::install_handlers(&mut node, element.events);
for child in element.children {
let child_node = Stdweb::build(document, child)?;
node.append_child(&child_node);
}
Ok(node.into())
}
}
}
}