Browse Source

Merge branch 'master' of https://github.com/DioxusLabs/dioxus into rusty-events

 Conflicts:
	packages/tui/tests/events.rs
Reinis Mazeiks 3 years ago
parent
commit
0777437243

+ 3 - 3
Cargo.toml

@@ -49,10 +49,9 @@ desktop = ["dioxus-desktop"]
 router = ["dioxus-router"]
 tui = ["dioxus-tui"]
 liveview = ["dioxus-liveview"]
-hot-reload = ["dioxus-core-macro/hot-reload", "dioxus-rsx-interpreter", "dioxus-desktop?/hot-reload", "dioxus-web?/hot-reload"]
+hot-reload = ["dioxus-core-macro/hot-reload", "dioxus-rsx-interpreter", "dioxus-desktop?/hot-reload", "dioxus-web?/hot-reload", "dioxus-router?/hot-reload"]
 native-core = ["dioxus-native-core", "dioxus-native-core-macro"]
 
-
 [workspace]
 members = [
     "packages/core",
@@ -71,6 +70,7 @@ members = [
     "packages/rsx_interpreter",
     "packages/native-core",
     "packages/native-core-macro",
+    "packages/rsx-prelude",
 ]
 
 [dev-dependencies]
@@ -85,7 +85,7 @@ serde_json = "1.0.79"
 rand = { version = "0.8.4", features = ["small_rng"] }
 tokio = { version = "1.16.1", features = ["full"] }
 reqwest = { version = "0.11.9", features = ["json"] }
-dioxus = { path = ".", features = ["desktop", "ssr", "router", "fermi", "tui"] }
+dioxus = { path = ".", features = ["desktop", "ssr", "router", "fermi", "tui", "hot-reload"] }
 fern = { version = "0.6.0", features = ["colored"] }
 criterion = "0.3.5"
 thiserror = "1.0.30"

+ 1 - 4
benches/jsframework.rs

@@ -13,10 +13,7 @@
 //! These numbers don't represent Dioxus with the heuristic engine installed, so I assume it'll be even faster.
 
 use criterion::{criterion_group, criterion_main, Criterion};
-use dioxus_core as dioxus;
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use rand::prelude::*;
 
 criterion_group!(mbenches, create_rows);

+ 29 - 0
packages/core-macro/tests/ifmt.rs

@@ -0,0 +1,29 @@
+use std::borrow::Borrow;
+
+use dioxus_core_macro::*;
+
+#[test]
+fn formatting_compiles() {
+    let x = (0, 1);
+    // escape sequences work
+    assert_eq!(
+        format_args_f!("{x:?} {{}}}}").to_string(),
+        format!("{:?} {{}}}}", x).to_string()
+    );
+    assert_eq!(
+        format_args_f!("{{{{}} {x:?}").to_string(),
+        format!("{{{{}} {:?}", x).to_string()
+    );
+
+    // paths in formating works
+    assert_eq!(
+        format_args_f!("{x.0}").to_string(),
+        format!("{}", x.0).to_string()
+    );
+
+    // function calls in formatings work
+    assert_eq!(
+        format_args_f!("{x.borrow():?}").to_string(),
+        format!("{:?}", x.borrow()).to_string()
+    );
+}

+ 1 - 3
packages/native-core-macro/Cargo.toml

@@ -20,9 +20,7 @@ quote = "1.0"
 dioxus-native-core = { path = "../native-core", version = "^0.2.0" }
 
 [dev-dependencies]
-dioxus-core = { path = "../core", version = "^0.2.1" }
-dioxus-html = { path = "../html", version = "^0.2.1" }
-dioxus-core-macro = { path = "../core-macro", version = "^0.2.1" }
+dioxus = { path = "../rsx-prelude", version = "^0.1.0",  package = "rsx-prelude" }
 
 smallvec = "1.6"
 fxhash = "0.2"

+ 3 - 4
packages/native-core-macro/tests/change_nodes.rs

@@ -1,7 +1,6 @@
-use dioxus_core::VNode;
-use dioxus_core::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::core as dioxus_core;
+use dioxus::core::{ElementId, VElement};
+use dioxus::prelude::*;
 use dioxus_native_core::real_dom::RealDom;
 use dioxus_native_core::state::State;
 use dioxus_native_core_macro::State;

+ 3 - 4
packages/native-core-macro/tests/initial_build.rs

@@ -1,9 +1,8 @@
 use std::cell::Cell;
 
-use dioxus_core::VNode;
-use dioxus_core::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::core as dioxus_core;
+use dioxus::core::{ElementId, VElement, VText};
+use dioxus::prelude::*;
 use dioxus_native_core::real_dom::RealDom;
 use dioxus_native_core::state::State;
 use dioxus_native_core_macro::State;

+ 2 - 17
packages/native-core-macro/tests/peristant_iterator.rs

@@ -1,3 +1,5 @@
+use dioxus::core as dioxus_core;
+use dioxus::prelude::*;
 use dioxus_native_core::{
     real_dom::{NodeType, RealDom},
     state::State,
@@ -11,10 +13,6 @@ struct Empty {}
 #[test]
 #[allow(unused_variables)]
 fn traverse() {
-    use dioxus_core::*;
-    use dioxus_core_macro::*;
-    use dioxus_html as dioxus_elements;
-
     #[allow(non_snake_case)]
     fn Base(cx: Scope) -> Element {
         rsx!(cx, div {})
@@ -108,11 +106,6 @@ fn traverse() {
 #[test]
 #[allow(unused_variables)]
 fn persist_removes() {
-    use dioxus_core::VNode;
-    use dioxus_core::*;
-    use dioxus_core_macro::*;
-    use dioxus_html as dioxus_elements;
-
     #[allow(non_snake_case)]
     fn Base(cx: Scope) -> Element {
         rsx!(cx, div {})
@@ -201,10 +194,6 @@ fn persist_removes() {
 #[test]
 #[allow(unused_variables)]
 fn persist_instertions_before() {
-    use dioxus_core::*;
-    use dioxus_core_macro::*;
-    use dioxus_html as dioxus_elements;
-
     #[allow(non_snake_case)]
     fn Base(cx: Scope) -> Element {
         rsx!(cx, div {})
@@ -271,10 +260,6 @@ fn persist_instertions_before() {
 #[test]
 #[allow(unused_variables)]
 fn persist_instertions_after() {
-    use dioxus_core::*;
-    use dioxus_core_macro::*;
-    use dioxus_html as dioxus_elements;
-
     #[allow(non_snake_case)]
     fn Base(cx: Scope) -> Element {
         rsx!(cx, div {})

+ 3 - 5
packages/native-core-macro/tests/update_state.rs

@@ -1,9 +1,7 @@
 use anymap::AnyMap;
-use dioxus_core::AttributeValue;
-use dioxus_core::VNode;
-use dioxus_core::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::core as dioxus_core;
+use dioxus::core::{AttributeValue, DomEdit, Mutations};
+use dioxus::prelude::*;
 use dioxus_native_core::node_ref::*;
 use dioxus_native_core::real_dom::*;
 use dioxus_native_core::state::{ChildDepState, NodeDepState, ParentDepState, State};

+ 2 - 3
packages/router/Cargo.toml

@@ -11,9 +11,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-dioxus-core = { path = "../core", version = "^0.2.1", default-features = false }
-dioxus-html = { path = "../html", version = "^0.2.1", default-features = false }
-dioxus-core-macro = { path = "../core-macro", version = "^0.2.1" }
+dioxus = { path = "../rsx-prelude", version = "^0.1.0",  package = "rsx-prelude" }
 futures-channel = "0.3.21"
 url = { version = "2.2.2", default-features = false }
 
@@ -44,6 +42,7 @@ default = ["query"]
 web = ["web-sys", "gloo-events", "js-sys", "wasm-bindgen"]
 query = ["serde", "serde_urlencoded"]
 wasm_test = []
+hot-reload = ["dioxus/hot-reload"]
 
 [dev-dependencies]
 console_error_panic_hook = "0.1.7"

+ 1 - 3
packages/router/examples/simple.rs

@@ -1,8 +1,6 @@
 #![allow(non_snake_case)]
 
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use dioxus_router::*;
 
 fn main() {

+ 1 - 4
packages/router/src/components/link.rs

@@ -1,10 +1,7 @@
 use std::sync::Arc;
 
 use crate::{use_route, RouterCore};
-use dioxus_core as dioxus;
-use dioxus_core::prelude::*;
-use dioxus_core_macro::{format_args_f, rsx, Props};
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 
 /// Props for the [`Link`](struct.Link.html) component.
 #[derive(Props)]

+ 1 - 3
packages/router/src/components/redirect.rs

@@ -1,6 +1,4 @@
-use dioxus_core as dioxus;
-use dioxus_core::prelude::*;
-use dioxus_core_macro::Props;
+use dioxus::prelude::*;
 
 use crate::use_router;
 

+ 1 - 6
packages/router/src/components/route.rs

@@ -1,11 +1,6 @@
+use dioxus::prelude::*;
 use std::sync::Arc;
 
-use dioxus_core as dioxus;
-use dioxus_core::prelude::*;
-use dioxus_core_macro::Props;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
-
 use crate::{RouteContext, RouterCore};
 
 /// Props for the [`Route`](struct.Route.html) component.

+ 1 - 4
packages/router/src/components/router.rs

@@ -1,9 +1,6 @@
 use crate::ParsedRoute;
 use crate::{cfg::RouterCfg, RouteEvent, RouterCore};
-use dioxus_core as dioxus;
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use futures_util::stream::StreamExt;
 use std::sync::Arc;
 

+ 1 - 1
packages/router/src/hooks/use_route.rs

@@ -1,5 +1,5 @@
 use crate::{ParsedRoute, RouteContext, RouterCore, RouterService};
-use dioxus_core::{ScopeId, ScopeState};
+use dioxus::core::{ScopeId, ScopeState};
 use std::{borrow::Cow, str::FromStr, sync::Arc};
 use url::Url;
 

+ 1 - 1
packages/router/src/hooks/use_router.rs

@@ -1,5 +1,5 @@
 use crate::RouterService;
-use dioxus_core::ScopeState;
+use dioxus::core::ScopeState;
 
 /// This hook provides access to the `RouterService` for the app.
 pub fn use_router(cx: &ScopeState) -> &RouterService {

+ 1 - 1
packages/router/src/service.rs

@@ -2,7 +2,7 @@
 // does each window have its own router? probably, lol
 
 use crate::cfg::RouterCfg;
-use dioxus_core::ScopeId;
+use dioxus::core::ScopeId;
 use futures_channel::mpsc::UnboundedSender;
 use std::any::Any;
 use std::{

+ 1 - 3
packages/router/tests/ssr_router.rs

@@ -1,8 +1,6 @@
 #![allow(non_snake_case)]
 
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use dioxus_router::*;
 
 #[test]

+ 1 - 3
packages/router/tests/web_router.rs

@@ -1,9 +1,7 @@
 #![cfg(target_arch = "wasm32")]
 #![allow(non_snake_case)]
 
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use dioxus_router::*;
 use gloo_utils::document;
 use wasm_bindgen_test::*;

+ 22 - 0
packages/rsx-prelude/Cargo.toml

@@ -0,0 +1,22 @@
+[package]
+name = "rsx-prelude"
+version = "0.1.0"
+authors = ["Jonathan Kelley"]
+edition = "2021"
+description = "Basic functionality for the dioxus rsx macro."
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/DioxusLabs/dioxus/"
+homepage = "https://dioxuslabs.com"
+documentation = "https://dioxuslabs.com"
+keywords = ["dom", "ui", "gui", "react", "wasm"]
+rust-version = "1.60.0"
+
+[dependencies]
+dioxus-core-macro = { path = "../core-macro", version = "^0.2.1" }
+dioxus-core = { path = "../core", version = "^0.2.1" }
+dioxus-html = { path = "../html", version = "^0.2.1" }
+dioxus-rsx-interpreter = { path = "../rsx_interpreter", version = "^0.1.0", optional = true }
+dioxus-hooks = { path = "../hooks", version = "^0.2.1" }
+
+[features]
+hot-reload = ["dioxus-core-macro/hot-reload", "dioxus-rsx-interpreter"]

+ 30 - 0
packages/rsx-prelude/src/lib.rs

@@ -0,0 +1,30 @@
+//! This package is meant for internal use within dioxus. It provides a prelude that enables basic components to work.
+
+pub use dioxus_core as core;
+
+pub mod hooks {
+    pub use dioxus_hooks::*;
+}
+
+pub use hooks::*;
+
+pub mod events {
+    pub use dioxus_html::{on::*, KeyCode};
+}
+
+#[cfg(feature = "hot-reload")]
+pub use dioxus_rsx_interpreter as rsx_interpreter;
+
+pub mod prelude {
+    pub use crate::hooks::*;
+    pub use dioxus_core::prelude::*;
+    pub use dioxus_core_macro::{format_args_f, inline_props, rsx, Props};
+    pub use dioxus_elements::{GlobalAttributes, SvgAttributes};
+    pub use dioxus_html as dioxus_elements;
+
+    #[cfg(feature = "hot-reload")]
+    pub use dioxus_rsx_interpreter::{
+        captuered_context::{CapturedContext, FormattedArg, IfmtArgs},
+        get_line_num, resolve_scope, CodeLocation, RsxContext,
+    };
+}

+ 12 - 2
packages/rsx/src/ifmt.rs

@@ -14,7 +14,7 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
     let mut expr_counter = 0;
     for segment in input.segments.iter() {
         match segment {
-            Segment::Literal(s) => format_literal += s,
+            Segment::Literal(s) => format_literal += &s.replace('{', "{{").replace('}', "}}"),
             Segment::Formatted {
                 format_args,
                 segment,
@@ -116,6 +116,17 @@ impl FromStr for IfmtInput {
                     current_captured.push(c);
                 }
             } else {
+                if '}' == c {
+                    if let Some(c) = chars.next_if(|c| *c == '}') {
+                        current_literal.push(c);
+                        continue;
+                    } else {
+                        return Err(Error::new(
+                            Span::call_site(),
+                            "unmatched closing '}' in format string",
+                        ));
+                    }
+                }
                 current_literal.push(c);
             }
         }
@@ -146,7 +157,6 @@ impl FormattedSegment {
                 return Ok(Self::Ident(ident));
             }
         }
-        // if let Ok(expr) = parse_str(&("{".to_string() + input + "}")) {
         if let Ok(expr) = parse_str(input) {
             Ok(Self::Expr(Box::new(expr)))
         } else {

+ 1 - 0
packages/rsx_interpreter/Cargo.toml

@@ -21,3 +21,4 @@ dioxus-hooks = { path = "../hooks"}
 [dev-dependencies]
 dioxus-core-macro = { path = "../core-macro" }
 bumpalo = { version = "3.6", features = ["collections", "boxed"] }
+dioxus = { path = "../rsx-prelude", version = "^0.1.0",  package = "rsx-prelude", features = ["hot-reload"] }

+ 1 - 1
packages/rsx_interpreter/src/interperter.rs

@@ -191,7 +191,7 @@ fn build_node<'a>(
                         None,
                     )),
                     Some(lit) => {
-                        let ifmt: IfmtInput = parse_str(&lit.value()).map_err(|err| {
+                        let ifmt: IfmtInput = lit.value().parse().map_err(|err| {
                             Error::ParseError(ParseError::new(err, ctx.location.clone()))
                         })?;
                         let key = bump.alloc(resolve_ifmt(&ifmt, &ctx.captured)?);

+ 1 - 7
packages/rsx_interpreter/tests/render.rs

@@ -1,10 +1,4 @@
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
-use dioxus_rsx_interpreter::{
-    captuered_context::{CapturedContext, FormattedArg, IfmtArgs},
-    CodeLocation,
-};
+use dioxus::prelude::*;
 
 #[test]
 #[allow(non_snake_case)]

+ 1 - 4
packages/ssr/Cargo.toml

@@ -15,11 +15,8 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
 [dependencies]
 dioxus-core = { path = "../core", version = "^0.2.1", features = ["serialize"] }
 
-
 [dev-dependencies]
-dioxus-hooks = { path = "../hooks" }
-dioxus-html = { path = "../html" }
-dioxus-core-macro = { path = "../core-macro" }
+dioxus = { path = "../rsx-prelude", version = "^0.1.0",  package = "rsx-prelude" }
 thiserror = "1.0.23"
 log = "0.4.13"
 fern = { version = "0.6.0", features = ["colored"] }

+ 1 - 3
packages/ssr/tests/renders.rs

@@ -1,6 +1,4 @@
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use dioxus_ssr::{render_lazy, render_vdom, render_vdom_cfg, SsrConfig, SsrRenderer, TextRenderer};
 
 static SIMPLE_APP: Component = |cx| {

+ 1 - 2
packages/tui/Cargo.toml

@@ -29,6 +29,5 @@ fxhash = "0.2"
 anymap = "0.12.1"
 
 [dev-dependencies]
-dioxus-core-macro = { path = "../core-macro", version = "^0.2.1" }
-dioxus-hooks = { path = "../hooks", version = "^0.2.1" }
+dioxus = { path = "../rsx-prelude", version = "^0.1.0",  package = "rsx-prelude" }
 tokio = { version = "1" }

+ 1 - 5
packages/tui/tests/events.rs

@@ -1,9 +1,5 @@
 use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers, MouseButton, MouseEvent};
-use dioxus_core::VNode;
-use dioxus_core::*;
-use dioxus_core_macro::*;
-use dioxus_hooks::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use dioxus_html::input_data::keyboard_types::Code;
 use dioxus_tui::TuiContext;
 use std::future::Future;

+ 2 - 2
packages/web/Cargo.toml

@@ -16,7 +16,7 @@ dioxus-html = { path = "../html", version = "^0.2.1", features = ["wasm-bind"] }
 dioxus-interpreter-js = { path = "../interpreter", version = "^0.2.1", features = [
     "web"
 ] }
-dioxus-rsx-interpreter = { path = "../rsx_interpreter", version = "*", optional = true }
+dioxus-rsx-interpreter = { path = "../rsx_interpreter", version = "^0.1.0", optional = true }
 
 js-sys = "0.3.56"
 wasm-bindgen = { version = "0.2.79", features = ["enable-interning"] }
@@ -80,7 +80,7 @@ panic_hook = ["console_error_panic_hook"]
 hot-reload = ["dioxus-rsx-interpreter", "web-sys/WebSocket", "web-sys/Location", "web-sys/MessageEvent", "web-sys/console", "serde_json"]
 
 [dev-dependencies]
-dioxus-core-macro = { path = "../core-macro" }
+dioxus = { path = "../rsx-prelude", version = "^0.1.0",  package = "rsx-prelude" }
 wasm-bindgen-test = "0.3.29"
 dioxus-ssr = { path = "../ssr" }
 wasm-logger = "0.2.0"

+ 1 - 3
packages/web/examples/hydrate.rs

@@ -1,6 +1,4 @@
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use web_sys::window;
 
 fn app(cx: Scope) -> Element {

+ 2 - 3
packages/web/src/lib.rs

@@ -58,10 +58,9 @@ use std::rc::Rc;
 
 pub use crate::cfg::WebConfig;
 pub use crate::util::use_eval;
-use dioxus::SchedulerMsg;
-use dioxus::VirtualDom;
-pub use dioxus_core as dioxus;
 use dioxus_core::prelude::Component;
+use dioxus_core::SchedulerMsg;
+use dioxus_core::VirtualDom;
 use futures_util::FutureExt;
 
 mod cache;

+ 1 - 3
packages/web/tests/hydrate.rs

@@ -1,6 +1,4 @@
-use dioxus_core::prelude::*;
-use dioxus_core_macro::*;
-use dioxus_html as dioxus_elements;
+use dioxus::prelude::*;
 use wasm_bindgen_test::wasm_bindgen_test;
 use web_sys::window;