wip: docs, html! macro, more
This commit is contained in:
1 parent
8f0bb5dc5b
commit
caf772cf24
27 files changed
+407
-191
No files matched your search
@@ -0,0 +1,27 @@
|
||||
//! Html body
|
||||
//! -------
|
||||
//!
|
||||
//!
|
||||
//! Since both HTML and RSX serialize to the same node structure, the HTML parser uses the same types as RSX,
|
||||
//! but has a different Parse implementation.
|
||||
|
||||
use crate::rsx::*;
|
||||
use quote::ToTokens;
|
||||
use syn::parse::Parse;
|
||||
|
||||
pub struct HtmlBody(RsxBody);
|
||||
|
||||
impl Parse for HtmlBody {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl ToTokens for HtmlBody {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
self.0.to_tokens(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HtmlNode(BodyNode);
|
||||
pub struct HtmlAmbigiousElement(AmbiguousElement);
|
||||
pub struct HtmlComponent(Component);
|
||||
@@ -4,6 +4,7 @@ use syn::parse_macro_input;
|
||||
|
||||
pub(crate) mod fc;
|
||||
pub(crate) mod htm;
|
||||
pub(crate) mod html;
|
||||
pub(crate) mod ifmt;
|
||||
pub(crate) mod props;
|
||||
pub(crate) mod rsx;
|
||||
@@ -237,7 +238,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
|
||||
/// ```
|
||||
#[proc_macro]
|
||||
pub fn rsx(s: TokenStream) -> TokenStream {
|
||||
match syn::parse::<rsx::RsxRender>(s) {
|
||||
match syn::parse::<rsx::RsxBody>(s) {
|
||||
Err(e) => e.to_compile_error().into(),
|
||||
Ok(s) => s.to_token_stream().into(),
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub struct Component {
|
||||
// accept any path-like argument
|
||||
name: syn::Path,
|
||||
body: Vec<ComponentField>,
|
||||
children: Vec<Node>,
|
||||
children: Vec<BodyNode>,
|
||||
manual_props: Option<Expr>,
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ impl Parse for Component {
|
||||
syn::braced!(content in stream);
|
||||
|
||||
let mut body: Vec<ComponentField> = Vec::new();
|
||||
let mut children: Vec<Node> = Vec::new();
|
||||
let mut children: Vec<BodyNode> = Vec::new();
|
||||
let mut manual_props = None;
|
||||
|
||||
parse_component_body(
|
||||
@@ -78,7 +78,7 @@ pub fn parse_component_body(
|
||||
content: &ParseBuffer,
|
||||
cfg: &BodyParseConfig,
|
||||
body: &mut Vec<ComponentField>,
|
||||
children: &mut Vec<Node>,
|
||||
children: &mut Vec<BodyNode>,
|
||||
manual_props: &mut Option<Expr>,
|
||||
) -> Result<()> {
|
||||
'parsing: loop {
|
||||
@@ -111,7 +111,7 @@ pub fn parse_component_body(
|
||||
"This item is not allowed to accept children.",
|
||||
));
|
||||
}
|
||||
children.push(content.parse::<Node>()?);
|
||||
children.push(content.parse::<BodyNode>()?);
|
||||
}
|
||||
|
||||
// consume comma if it exists
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct Element {
|
||||
key: Option<AttrType>,
|
||||
attributes: Vec<ElementAttr>,
|
||||
listeners: Vec<ElementAttr>,
|
||||
children: Vec<Node>,
|
||||
children: Vec<BodyNode>,
|
||||
is_static: bool,
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ impl Parse for Element {
|
||||
|
||||
let mut attributes: Vec<ElementAttr> = vec![];
|
||||
let mut listeners: Vec<ElementAttr> = vec![];
|
||||
let mut children: Vec<Node> = vec![];
|
||||
let mut children: Vec<BodyNode> = vec![];
|
||||
let mut key = None;
|
||||
|
||||
'parsing: loop {
|
||||
@@ -72,7 +72,7 @@ impl Parse for Element {
|
||||
name.clone(),
|
||||
)?;
|
||||
} else {
|
||||
children.push(content.parse::<Node>()?);
|
||||
children.push(content.parse::<BodyNode>()?);
|
||||
}
|
||||
|
||||
// consume comma if it exists
|
||||
@@ -238,20 +238,9 @@ impl ToTokens for ElementAttr {
|
||||
AttrType::BumpText(value) => tokens.append_all(quote! {
|
||||
dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
|
||||
}),
|
||||
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
|
||||
//
|
||||
// AttrType::BumpText(value) => tokens.append_all(quote! {
|
||||
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
|
||||
// }),
|
||||
AttrType::FieldTokens(exp) => tokens.append_all(quote! {
|
||||
dioxus_elements::#el_name.#nameident(__cx, #exp)
|
||||
}),
|
||||
// __cx.attr(#name_str, #exp, #namespace, false)
|
||||
|
||||
// AttrType::FieldTokens(exp) => tokens.append_all(quote! {
|
||||
// dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
|
||||
// __cx.attr(#name_str, #exp, #namespace, false)
|
||||
// }),
|
||||
|
||||
// todo: move event handlers on to the elements or onto the nodefactory
|
||||
AttrType::Event(event) => tokens.append_all(quote! {
|
||||
@@ -264,3 +253,15 @@ impl ToTokens for ElementAttr {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
|
||||
//
|
||||
// AttrType::BumpText(value) => tokens.append_all(quote! {
|
||||
// __cx.attr(#name, format_args_f!(#value), #namespace, false)
|
||||
// }),
|
||||
// __cx.attr(#name_str, #exp, #namespace, false)
|
||||
|
||||
// AttrType::FieldTokens(exp) => tokens.append_all(quote! {
|
||||
// dioxus_elements::#el_name.#nameident(__cx, format_args_f!(#value))
|
||||
// __cx.attr(#name_str, #exp, #namespace, false)
|
||||
// }),
|
||||
@@ -32,12 +32,12 @@ use syn::{
|
||||
Error, Ident, LitStr, Result, Token,
|
||||
};
|
||||
|
||||
pub struct RsxRender {
|
||||
pub struct RsxBody {
|
||||
custom_context: Option<Ident>,
|
||||
roots: Vec<Node>,
|
||||
roots: Vec<BodyNode>,
|
||||
}
|
||||
|
||||
impl Parse for RsxRender {
|
||||
impl Parse for RsxBody {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
// if input.peek(LitStr) {
|
||||
// return input.parse::<LitStr>()?.parse::<RsxRender>();
|
||||
@@ -83,7 +83,7 @@ impl Parse for RsxRender {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for RsxRender {
|
||||
impl ToTokens for RsxBody {
|
||||
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
||||
let inner = if self.roots.len() == 1 {
|
||||
let inner = &self.roots[0];
|
||||
|
||||
@@ -10,13 +10,13 @@ use syn::{
|
||||
// ==============================================
|
||||
// Parse any div {} as a VElement
|
||||
// ==============================================
|
||||
pub enum Node {
|
||||
pub enum BodyNode {
|
||||
Element(AmbiguousElement),
|
||||
Text(TextNode),
|
||||
RawExpr(Expr),
|
||||
}
|
||||
|
||||
impl Parse for Node {
|
||||
impl Parse for BodyNode {
|
||||
fn parse(stream: ParseStream) -> Result<Self> {
|
||||
// Supposedly this approach is discouraged due to inability to return proper errors
|
||||
// TODO: Rework this to provide more informative errors
|
||||
@@ -24,23 +24,23 @@ impl Parse for Node {
|
||||
if stream.peek(token::Brace) {
|
||||
let content;
|
||||
syn::braced!(content in stream);
|
||||
return Ok(Node::RawExpr(content.parse::<Expr>()?));
|
||||
return Ok(BodyNode::RawExpr(content.parse::<Expr>()?));
|
||||
}
|
||||
|
||||
if stream.peek(LitStr) {
|
||||
return Ok(Node::Text(stream.parse::<TextNode>()?));
|
||||
return Ok(BodyNode::Text(stream.parse::<TextNode>()?));
|
||||
}
|
||||
|
||||
Ok(Node::Element(stream.parse::<AmbiguousElement>()?))
|
||||
Ok(BodyNode::Element(stream.parse::<AmbiguousElement>()?))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for Node {
|
||||
impl ToTokens for BodyNode {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
match &self {
|
||||
Node::Element(el) => el.to_tokens(tokens),
|
||||
Node::Text(txt) => txt.to_tokens(tokens),
|
||||
Node::RawExpr(exp) => tokens.append_all(quote! {
|
||||
BodyNode::Element(el) => el.to_tokens(tokens),
|
||||
BodyNode::Text(txt) => txt.to_tokens(tokens),
|
||||
BodyNode::RawExpr(exp) => tokens.append_all(quote! {
|
||||
__cx.fragment_from_iter(#exp)
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{rsx::RsxRender, util::is_valid_svg_tag};
|
||||
use crate::{rsx::RsxBody, util::is_valid_svg_tag};
|
||||
|
||||
use {
|
||||
proc_macro::TokenStream,
|
||||
@@ -15,7 +15,7 @@ use {
|
||||
// Parse any stream coming from the html! macro
|
||||
// ==============================================
|
||||
pub struct RsxTemplate {
|
||||
inner: RsxRender,
|
||||
inner: RsxBody,
|
||||
}
|
||||
|
||||
impl Parse for RsxTemplate {
|
||||
@@ -35,7 +35,7 @@ impl Parse for RsxTemplate {
|
||||
let lit = LitStr::new(&value, lit.span());
|
||||
|
||||
// panic!("{:#?}", lit);
|
||||
match lit.parse::<crate::rsx::RsxRender>() {
|
||||
match lit.parse::<crate::rsx::RsxBody>() {
|
||||
Ok(r) => Ok(Self { inner: r }),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ use std::any::Any;
|
||||
/// target-specific Node type as well as easily serializing the edits to be sent over a network or IPC connection.
|
||||
pub trait RealDom<'a> {
|
||||
fn request_available_node(&mut self) -> RealDomNode;
|
||||
|
||||
fn raw_node_as_any(&self) -> &mut dyn Any;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Dioxus-webview is an attempt at making a simpler "Tauri" where creating desktop
|
||||
// main.rs
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
dioxus_webview::new(|cx| {
|
||||
dioxus_desktop::new(|cx| {
|
||||
let (count, set_count) = use_state(cx, || 0);
|
||||
cx.render(html! {
|
||||
<div>
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "webview-client"
|
||||
version = "0.1.0"
|
||||
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dioxus-core = {path = "../../core"}
|
||||
@@ -1,64 +0,0 @@
|
||||
use dioxus_core::patch::Edit;
|
||||
use dioxus_core::prelude::*;
|
||||
|
||||
static SERVER_RENDERED_KEY: &'static str = "abc123";
|
||||
#[derive(Debug, PartialEq, Props)]
|
||||
struct ServerRendered {
|
||||
name0: String,
|
||||
name1: String,
|
||||
name2: String,
|
||||
name3: String,
|
||||
name4: String,
|
||||
name5: String,
|
||||
name6: String,
|
||||
name7: String,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[cfg(old)]
|
||||
fn blah() {
|
||||
// connect to the host server
|
||||
|
||||
let server_rendered = use_server_rendered((111111, 11111, 11), SERVER_RENDERED_KEY, || {
|
||||
ServerRendered {
|
||||
name0: "abc".to_string(),
|
||||
name1: "abc".to_string(),
|
||||
name2: "abc".to_string(),
|
||||
name3: "abc".to_string(),
|
||||
name4: "abc".to_string(),
|
||||
name5: "abc".to_string(),
|
||||
name6: "abc".to_string(),
|
||||
name7: "abc".to_string(),
|
||||
}
|
||||
});
|
||||
|
||||
let handler = dioxus_liveview::new_handler()
|
||||
.from_directory("abc123") // serve a given directory as the root
|
||||
.with_context(|| SomeContext {}) // build out a new context for all of the server-rendered components to share
|
||||
.with_route(SERVER_RENDERED_KEY, |cx: &ServerRendered| {
|
||||
//
|
||||
})
|
||||
.with_route(SERVER_RENDERED_KEY, |cx| {
|
||||
//
|
||||
})
|
||||
.with_route(SERVER_RENDERED_KEY, |cx| {
|
||||
//
|
||||
})
|
||||
.with_route(SERVER_RENDERED_KEY, |cx| {
|
||||
//
|
||||
})
|
||||
.with_route(SERVER_RENDERED_KEY, |cx| {
|
||||
//
|
||||
})
|
||||
.with_route(SERVER_RENDERED_KEY, |cx| {
|
||||
//
|
||||
})
|
||||
// depend on the framework, build a different type of handler
|
||||
// there are instructions on how to integrate this the various rusty web frameworks in the guide
|
||||
.build();
|
||||
|
||||
server.get("abc", handler);
|
||||
}
|
||||
|
||||
fn use_server_rendered<F: Properties>(_p: impl PartialEq, name: &'static str, f: impl Fn() -> F) {}
|
||||
@@ -2,7 +2,7 @@ use dioxus_core as dioxus;
|
||||
use dioxus_core::prelude::*;
|
||||
|
||||
fn main() {
|
||||
dioxus_webview::launch(App, |f| f.with_maximized(true)).expect("Failed");
|
||||
dioxus_desktop::launch(App, |f| f.with_maximized(true)).expect("Failed");
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
|
||||
@@ -128,12 +128,9 @@
|
||||
</script>
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
<body>
|
||||
<div id="_dioxusroot">
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
||||
@@ -41,10 +41,7 @@ pub struct WebviewRenderer<T> {
|
||||
root: FC<T>,
|
||||
}
|
||||
enum RpcEvent<'a> {
|
||||
Initialize {
|
||||
//
|
||||
edits: Vec<DomEdit<'a>>,
|
||||
},
|
||||
Initialize { edits: Vec<DomEdit<'a>> },
|
||||
}
|
||||
|
||||
impl<T: Properties + 'static> WebviewRenderer<T> {
|
||||
@@ -129,7 +126,7 @@ impl<T: Properties + 'static> WebviewRenderer<T> {
|
||||
.build()?;
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Poll;
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::WindowEvent {
|
||||
|
||||
@@ -148,7 +148,8 @@ impl<'a, T: 'static> std::ops::Deref for UseState<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
use std::ops::{Add, AddAssign, Sub, SubAssign};
|
||||
use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Sub, SubAssign};
|
||||
|
||||
impl<'a, T: Copy + Add<T, Output = T>> Add<T> for UseState<'a, T> {
|
||||
type Output = T;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pub const App: FC<()> = |cx| {
|
||||
div { class: "overflow-hidden"
|
||||
link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel:"stylesheet" }
|
||||
Header {}
|
||||
// Entry {}
|
||||
Entry {}
|
||||
Hero {}
|
||||
Hero {}
|
||||
Hero {}
|
||||
|
||||
Reference in new issue
Block a user