From d9546d9504dd2cb2e675cdce1ad8a0a54e3719a7 Mon Sep 17 00:00:00 2001 From: Jon Kelley Date: Sat, 9 Jul 2022 15:15:20 -0400 Subject: [PATCH] Renderers are now packages, not features. (#387) * feat: use synchronous router design * feat: function to get router out of dom * chore: restructure workspace to use renderers as packages, not features --- .github/workflows/macos.yml | 2 +- .github/workflows/main.yml | 1 + .github/workflows/windows.yml | 4 +- Cargo.toml | 93 +++-------- docs/guide/Cargo.toml | 13 +- docs/guide/examples/boolean_attribute.rs | 2 +- .../examples/component_borrowed_props.rs | 2 +- docs/guide/examples/component_children.rs | 2 +- .../examples/component_children_inspect.rs | 2 +- .../guide/examples/component_element_props.rs | 2 +- docs/guide/examples/component_owned_props.rs | 2 +- .../guide/examples/component_props_options.rs | 2 +- docs/guide/examples/components.rs | 2 +- docs/guide/examples/conditional_rendering.rs | 2 +- docs/guide/examples/dangerous_inner_html.rs | 2 +- docs/guide/examples/event_click.rs | 2 +- docs/guide/examples/event_handler_prop.rs | 2 +- docs/guide/examples/event_nested.rs | 2 +- docs/guide/examples/event_prevent_default.rs | 2 +- docs/guide/examples/hello_world_desktop.rs | 2 +- docs/guide/examples/hello_world_tui.rs | 2 +- .../examples/hello_world_tui_no_ctrl_c.rs | 8 +- docs/guide/examples/hello_world_web.rs | 2 +- docs/guide/examples/hooks_bad.rs | 2 +- docs/guide/examples/hooks_counter.rs | 2 +- .../guide/examples/hooks_counter_two_state.rs | 2 +- docs/guide/examples/hooks_use_ref.rs | 2 +- docs/guide/examples/input_controlled.rs | 2 +- docs/guide/examples/input_uncontrolled.rs | 2 +- docs/guide/examples/meme_editor.rs | 2 +- docs/guide/examples/meme_editor_dark_mode.rs | 2 +- docs/guide/examples/rendering_lists.rs | 2 +- docs/guide/examples/rsx_overview.rs | 2 +- docs/guide/examples/spawn.rs | 2 +- docs/guide/examples/use_future.rs | 2 +- .../src/en/__unused/advanced-guides/rsx.md | 4 +- docs/guide/src/en/__unused/composing.md | 2 +- .../guide/src/en/__unused/event_javascript.rs | 2 +- docs/guide/src/en/__unused/index.md | 2 +- docs/guide/src/en/getting_started/mobile.md | 4 +- docs/guide/src/en/getting_started/ssr.md | 8 +- docs/guide/src/en/interactivity/index.md | 2 +- docs/posts/release.md | 14 +- docs/router/src/guide/getting-started.md | 2 +- examples/all_css.rs | 2 +- examples/all_events.rs | 2 +- examples/borrowed.rs | 2 +- examples/calculator.rs | 6 +- examples/core_reference/README.md | 21 --- examples/core_reference/custom_elements.rs | 44 ----- examples/core_reference/errorhandling.rs | 89 ---------- examples/core_reference/global_css.rs | 30 ---- examples/core_reference/inline_styles.rs | 29 ---- examples/core_reference/memo.rs | 84 ---------- examples/core_reference/spreadpattern.rs | 41 ----- examples/core_reference/suspense.rs | 38 ----- examples/core_reference/task.rs | 61 ------- examples/crm.rs | 3 +- examples/custom_assets.rs | 2 +- examples/custom_element.rs | 2 +- examples/custom_html.rs | 4 +- examples/disabled.rs | 2 +- examples/dog_app.rs | 5 +- examples/error_handle.rs | 2 +- examples/eval.rs | 5 +- examples/fermi.rs | 3 +- examples/file_explorer.rs | 2 +- examples/filedragdrop.rs | 2 +- examples/flat_router.rs | 5 +- examples/form.rs | 26 ++- examples/framework_benchmark.rs | 2 +- examples/heavy_compute.rs | 2 +- examples/hello_world.rs | 2 +- examples/hydration.rs | 5 +- examples/inlineprops.rs | 2 +- examples/inputs.rs | 2 +- examples/link.rs | 13 +- examples/login_form.rs | 2 +- examples/nested_listeners.rs | 2 +- examples/optional_props.rs | 2 +- examples/pattern_model.rs | 6 +- examples/pattern_reducer.rs | 2 +- examples/readme.rs | 2 +- examples/router.rs | 10 +- examples/rsx_compile_fail.rs | 2 +- examples/rsx_usage.rs | 2 +- examples/ssr.rs | 8 +- examples/suspense.rs | 4 +- examples/svg.rs | 2 +- examples/svg_basic.rs | 2 +- examples/tailwind.rs | 2 +- examples/tasks.rs | 2 +- examples/textarea.rs | 2 +- examples/todomvc.rs | 2 +- examples/window_event.rs | 4 +- examples/window_zoom.rs | 4 +- examples/xss_safety.rs | 2 +- notes/Parity.md | 46 ------ notes/README.md | 4 +- notes/ROADMAP.md | 90 ---------- notes/SAFETY.md | 26 --- notes/SUSPENSE.md | 28 ---- notes/TODO.md | 29 ---- notes/log.md | 70 -------- packages/autofmt/Cargo.toml | 2 +- packages/autofmt/src/buffer.rs | 4 +- packages/autofmt/src/element.rs | 2 +- packages/core-macro/src/lib.rs | 4 +- packages/core/src/lib.rs | 2 +- packages/desktop/src/desktop_context.rs | 4 +- packages/desktop/src/escape.rs | 2 +- packages/desktop/src/lib.rs | 12 +- packages/desktop/src/readme.md | 4 +- packages/dioxus/Cargo.toml | 51 ++++++ .../dioxus/benches}/create.rs | 0 .../dioxus/benches}/jsframework.rs | 0 packages/{rsx-prelude => dioxus}/src/lib.rs | 30 +++- .../dioxus/tests}/.rustfmt.toml | 0 {tests => packages/dioxus/tests}/README.md | 0 .../dioxus/tests}/borrowedstate.rs | 0 .../dioxus/tests}/create_dom.rs | 3 - {tests => packages/dioxus/tests}/diffing.rs | 16 +- .../dioxus/tests}/earlyabort.rs | 2 - {tests => packages/dioxus/tests}/lifecycle.rs | 7 +- .../dioxus/tests}/miri_stress.rs | 5 - {tests => packages/dioxus/tests}/passthru.rs | 4 - {tests => packages/dioxus/tests}/scheduler.rs | 0 .../dioxus/tests}/sharedstate.rs | 2 - {tests => packages/dioxus/tests}/task.rs | 0 .../dioxus/tests}/vdom_rebuild.rs | 0 packages/fermi/README.md | 14 +- packages/fermi/src/hooks/state.rs | 6 +- packages/hooks/src/usecoroutine.rs | 2 +- packages/hooks/src/useref.rs | 20 +-- packages/hooks/src/usestate.rs | 6 +- packages/html/src/elements.rs | 6 +- packages/html/src/events.rs | 2 +- packages/liveview/Cargo.toml | 2 +- packages/liveview/examples/axum.rs | 17 +- packages/liveview/examples/warp.rs | 22 +-- packages/mobile/README.md | 2 +- packages/native-core-macro/Cargo.toml | 2 +- packages/native-core/src/state.rs | 2 +- packages/router/Cargo.toml | 9 +- packages/router/examples/simple.rs | 2 - packages/router/src/components/link.rs | 6 +- packages/router/src/components/router.rs | 78 +-------- packages/router/src/service.rs | 155 +++++++++++------- packages/router/tests/ssr_router.rs | 28 ---- packages/router/usage.md | 6 +- packages/rsx-prelude/Cargo.toml | 22 --- packages/rsx/src/element.rs | 2 +- packages/rsx_interpreter/Cargo.toml | 2 +- packages/rsx_interpreter/src/elements.rs | 6 +- packages/ssr/Cargo.toml | 2 +- packages/ssr/README.md | 16 +- packages/tui/Cargo.toml | 9 +- .../tui/benches/update.rs | 16 +- .../tui/examples}/tui_all_events.rs | 2 +- .../tui/examples}/tui_border.rs | 2 +- .../tui/examples}/tui_buttons.rs | 2 +- .../tui/examples}/tui_color_test.rs | 4 +- .../tui/examples}/tui_colorpicker.rs | 2 +- .../tui/examples}/tui_components.rs | 2 +- .../tui/examples}/tui_frame.rs | 2 +- .../tui/examples}/tui_hover.rs | 2 +- .../tui/examples}/tui_keys.rs | 2 +- .../tui/examples}/tui_list.rs | 2 +- .../tui/examples}/tui_margin.rs | 2 +- .../tui/examples}/tui_quadrants.rs | 2 +- .../tui/examples}/tui_readme.rs | 2 +- .../tui/examples}/tui_task.rs | 2 +- .../tui/examples}/tui_text.rs | 2 +- packages/tui/examples/ui.rsx | 5 - packages/tui/src/query.rs | 6 +- packages/web/Cargo.toml | 2 +- packages/web/src/cfg.rs | 2 +- packages/web/src/lib.rs | 2 +- src/lib.rs | 70 -------- tests/fermi.rs | 46 ------ tests/test_logging.rs | 51 ------ 181 files changed, 487 insertions(+), 1463 deletions(-) delete mode 100644 examples/core_reference/README.md delete mode 100644 examples/core_reference/custom_elements.rs delete mode 100644 examples/core_reference/errorhandling.rs delete mode 100644 examples/core_reference/global_css.rs delete mode 100644 examples/core_reference/inline_styles.rs delete mode 100644 examples/core_reference/memo.rs delete mode 100644 examples/core_reference/spreadpattern.rs delete mode 100644 examples/core_reference/suspense.rs delete mode 100644 examples/core_reference/task.rs delete mode 100644 notes/Parity.md delete mode 100644 notes/ROADMAP.md delete mode 100644 notes/SAFETY.md delete mode 100644 notes/SUSPENSE.md delete mode 100644 notes/TODO.md delete mode 100644 notes/log.md create mode 100644 packages/dioxus/Cargo.toml rename {benches => packages/dioxus/benches}/create.rs (100%) rename {benches => packages/dioxus/benches}/jsframework.rs (100%) rename packages/{rsx-prelude => dioxus}/src/lib.rs (57%) rename {tests => packages/dioxus/tests}/.rustfmt.toml (100%) rename {tests => packages/dioxus/tests}/README.md (100%) rename {tests => packages/dioxus/tests}/borrowedstate.rs (100%) rename {tests => packages/dioxus/tests}/create_dom.rs (98%) rename {tests => packages/dioxus/tests}/diffing.rs (98%) rename {tests => packages/dioxus/tests}/earlyabort.rs (95%) rename {tests => packages/dioxus/tests}/lifecycle.rs (97%) rename {tests => packages/dioxus/tests}/miri_stress.rs (98%) rename {tests => packages/dioxus/tests}/passthru.rs (95%) rename {tests => packages/dioxus/tests}/scheduler.rs (100%) rename {tests => packages/dioxus/tests}/sharedstate.rs (99%) rename {tests => packages/dioxus/tests}/task.rs (100%) rename {tests => packages/dioxus/tests}/vdom_rebuild.rs (100%) delete mode 100644 packages/router/tests/ssr_router.rs delete mode 100644 packages/rsx-prelude/Cargo.toml rename benches/tui_update.rs => packages/tui/benches/update.rs (88%) rename {examples => packages/tui/examples}/tui_all_events.rs (98%) rename {examples => packages/tui/examples}/tui_border.rs (95%) rename {examples => packages/tui/examples}/tui_buttons.rs (98%) rename {examples => packages/tui/examples}/tui_color_test.rs (91%) rename {examples => packages/tui/examples}/tui_colorpicker.rs (96%) rename {examples => packages/tui/examples}/tui_components.rs (98%) rename {examples => packages/tui/examples}/tui_frame.rs (98%) rename {examples => packages/tui/examples}/tui_hover.rs (99%) rename {examples => packages/tui/examples}/tui_keys.rs (98%) rename {examples => packages/tui/examples}/tui_list.rs (94%) rename {examples => packages/tui/examples}/tui_margin.rs (97%) rename {examples => packages/tui/examples}/tui_quadrants.rs (98%) rename {examples => packages/tui/examples}/tui_readme.rs (91%) rename {examples => packages/tui/examples}/tui_task.rs (96%) rename {examples => packages/tui/examples}/tui_text.rs (99%) delete mode 100644 packages/tui/examples/ui.rsx delete mode 100644 src/lib.rs delete mode 100644 tests/fermi.rs delete mode 100644 tests/test_logging.rs diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 6ff2b1e9c..7d9415bca 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -40,4 +40,4 @@ jobs: - uses: actions-rs/cargo@v1 with: command: test - args: --features "desktop, ssr, router" + args: --all --tests diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 228e83f11..1ebe08005 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,6 +43,7 @@ jobs: - uses: actions-rs/cargo@v1 with: command: check + args: --all --examples --tests test: if: github.event.pull_request.draft == false diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 961adee97..9b5204d1c 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -71,6 +71,6 @@ jobs: rustc -Vv cargo -V set RUST_BACKTRACE=1 - cargo build --features "desktop, ssr, router" - cargo test --features "desktop, ssr, router" + cargo build --all --tests --examples + cargo test --all --tests shell: cmd diff --git a/Cargo.toml b/Cargo.toml index 3c3f78b7e..31a89c5bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,61 +1,10 @@ -[package] -name = "dioxus" -version = "0.2.4" -authors = ["Jonathan Kelley"] -edition = "2021" -description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences" -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 = { path = "./packages/core", version = "^0.2.1" } -dioxus-html = { path = "./packages/html", version = "^0.2.1", optional = true } -dioxus-core-macro = { path = "./packages/core-macro", version = "^0.2.1", optional = true } -dioxus-hooks = { path = "./packages/hooks", version = "^0.2.1", optional = true } -fermi = { path = "./packages/fermi", version = "^0.2.1", optional = true } - -dioxus-web = { path = "./packages/web", version = "^0.2.1", optional = true } -dioxus-desktop = { path = "./packages/desktop", version = "^0.2.3", optional = true } -dioxus-ssr = { path = "./packages/ssr", version = "^0.2.1", optional = true } - -dioxus-router = { path = "./packages/router", version = "^0.2.3", optional = true } -dioxus-interpreter-js = { path = "./packages/interpreter", version = "^0.2.1", optional = true } -dioxus-tui = { path = "./packages/tui", version = "^0.2.2", optional = true } - -dioxus-rsx = { path = "./packages/rsx", optional = true } -dioxus-rsx-interpreter = { path = "./packages/rsx_interpreter", optional = true } -dioxus-liveview = { path = "./packages/liveview", version = "^0.1.0", optional = true } - -dioxus-native-core = { path = "./packages/native-core", version = "^0.2.0", optional = true } -dioxus-native-core-macro = { path = "./packages/native-core-macro", version = "^0.2.0", optional = true } - -# dioxus-mobile = { path = "./packages/mobile", version = "^0.2.0", optional = true } -# dioxus-rsx = { path = "./packages/rsx", optional = true } -# macro = ["dioxus-core-macro", "dioxus-rsx"] - -[features] -default = ["macro", "hooks", "html"] - -macro = ["dioxus-core-macro", "dioxus-rsx"] -hooks = ["dioxus-hooks"] -html = ["dioxus-html"] -ssr = ["dioxus-ssr"] -web = ["dioxus-web", "dioxus-router?/web"] -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", "dioxus-router?/hot-reload"] -native-core = ["dioxus-native-core", "dioxus-native-core-macro"] [workspace] members = [ + "packages/dioxus", "packages/core", "packages/core-macro", + "packages/router", "packages/html", "packages/hooks", "packages/web", @@ -71,11 +20,32 @@ members = [ "packages/rsx_interpreter", "packages/native-core", "packages/native-core-macro", - "packages/rsx-prelude", "docs/guide", ] + +# This is a "virtual package" +# It is not meant to be published, but is used so "cargo run --example XYZ" works properly +[package] +name = "dioxus-examples" +version = "0.0.0" +authors = ["Jonathan Kelley"] +edition = "2021" +description = "Top level crate for the Dioxus repository" +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" + + [dev-dependencies] +dioxus = { path = "./packages/dioxus" } +dioxus-desktop = { path = "./packages/desktop" } +dioxus-ssr = { path = "./packages/ssr" } +dioxus-router = { path = "./packages/router" } +fermi = { path = "./packages/fermi" } futures-util = "0.3.21" log = "0.4.14" num-format = "0.4.0" @@ -87,21 +57,6 @@ 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", "hot-reload"] } fern = { version = "0.6.0", features = ["colored"] } -criterion = "0.3.5" thiserror = "1.0.30" env_logger = "0.9.0" - - -[[bench]] -name = "create" -harness = false - -[[bench]] -name = "jsframework" -harness = false - -[[bench]] -name = "tui_update" -harness = false diff --git a/docs/guide/Cargo.toml b/docs/guide/Cargo.toml index 50edb6d7e..0f544e071 100644 --- a/docs/guide/Cargo.toml +++ b/docs/guide/Cargo.toml @@ -6,7 +6,16 @@ description = "Dioxus guide, including testable examples" license = "MIT/Apache-2.0" [dev-dependencies] -dioxus = { path = "../..", features = ["desktop", "web", "ssr", "router", "fermi", "tui"] } +dioxus = { path = "../../packages/dioxus" } +dioxus-desktop = { path = "../../packages/desktop" } +dioxus-web = { path = "../../packages/web" } +dioxus-ssr = { path = "../../packages/ssr" } +dioxus-router = { path = "../../packages/router" } +dioxus-tui = { path = "../../packages/tui" } +fermi = { path = "../../packages/fermi" } + + +# dioxus = { path = "../../packages/dioxus", features = ["desktop", "web", "ssr", "router", "fermi", "tui"] } serde = { version = "1.0.138", features=["derive"] } reqwest = { version = "0.11.11", features = ["json"] } -tokio = { version = "1.19.2" , features=[]} \ No newline at end of file +tokio = { version = "1.19.2" , features=[]} diff --git a/docs/guide/examples/boolean_attribute.rs b/docs/guide/examples/boolean_attribute.rs index f624de331..14a824b69 100644 --- a/docs/guide/examples/boolean_attribute.rs +++ b/docs/guide/examples/boolean_attribute.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/component_borrowed_props.rs b/docs/guide/examples/component_borrowed_props.rs index ed6beb1af..ee78a1824 100644 --- a/docs/guide/examples/component_borrowed_props.rs +++ b/docs/guide/examples/component_borrowed_props.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: App diff --git a/docs/guide/examples/component_children.rs b/docs/guide/examples/component_children.rs index 37ba59ba8..d13a6480d 100644 --- a/docs/guide/examples/component_children.rs +++ b/docs/guide/examples/component_children.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/component_children_inspect.rs b/docs/guide/examples/component_children_inspect.rs index 1a239890f..d05a95a8b 100644 --- a/docs/guide/examples/component_children_inspect.rs +++ b/docs/guide/examples/component_children_inspect.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/component_element_props.rs b/docs/guide/examples/component_element_props.rs index 86ff67bc7..b8fe98879 100644 --- a/docs/guide/examples/component_element_props.rs +++ b/docs/guide/examples/component_element_props.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/component_owned_props.rs b/docs/guide/examples/component_owned_props.rs index 04fb6e2eb..3913f02c8 100644 --- a/docs/guide/examples/component_owned_props.rs +++ b/docs/guide/examples/component_owned_props.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: App diff --git a/docs/guide/examples/component_props_options.rs b/docs/guide/examples/component_props_options.rs index 28482e421..a32e65a33 100644 --- a/docs/guide/examples/component_props_options.rs +++ b/docs/guide/examples/component_props_options.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/components.rs b/docs/guide/examples/components.rs index 476eadc8d..85020c79c 100644 --- a/docs/guide/examples/components.rs +++ b/docs/guide/examples/components.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: App diff --git a/docs/guide/examples/conditional_rendering.rs b/docs/guide/examples/conditional_rendering.rs index 5dbadd29b..5a89ef4ed 100644 --- a/docs/guide/examples/conditional_rendering.rs +++ b/docs/guide/examples/conditional_rendering.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } pub fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/dangerous_inner_html.rs b/docs/guide/examples/dangerous_inner_html.rs index dafece034..f5f976e59 100644 --- a/docs/guide/examples/dangerous_inner_html.rs +++ b/docs/guide/examples/dangerous_inner_html.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/event_click.rs b/docs/guide/examples/event_click.rs index 457873d49..d6ccc0682 100644 --- a/docs/guide/examples/event_click.rs +++ b/docs/guide/examples/event_click.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/event_handler_prop.rs b/docs/guide/examples/event_handler_prop.rs index 4a9bbbb00..a333f86fe 100644 --- a/docs/guide/examples/event_handler_prop.rs +++ b/docs/guide/examples/event_handler_prop.rs @@ -4,7 +4,7 @@ use dioxus::events::MouseEvent; use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/event_nested.rs b/docs/guide/examples/event_nested.rs index 63096448e..512211707 100644 --- a/docs/guide/examples/event_nested.rs +++ b/docs/guide/examples/event_nested.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/event_prevent_default.rs b/docs/guide/examples/event_prevent_default.rs index f983400ae..120f74157 100644 --- a/docs/guide/examples/event_prevent_default.rs +++ b/docs/guide/examples/event_prevent_default.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/hello_world_desktop.rs b/docs/guide/examples/hello_world_desktop.rs index 373c1f9d6..91f0db03f 100644 --- a/docs/guide/examples/hello_world_desktop.rs +++ b/docs/guide/examples/hello_world_desktop.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: component diff --git a/docs/guide/examples/hello_world_tui.rs b/docs/guide/examples/hello_world_tui.rs index f16751d71..ef9b7ec47 100644 --- a/docs/guide/examples/hello_world_tui.rs +++ b/docs/guide/examples/hello_world_tui.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(App); + dioxus_tui::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/hello_world_tui_no_ctrl_c.rs b/docs/guide/examples/hello_world_tui_no_ctrl_c.rs index addf43671..652d17752 100644 --- a/docs/guide/examples/hello_world_tui_no_ctrl_c.rs +++ b/docs/guide/examples/hello_world_tui_no_ctrl_c.rs @@ -3,16 +3,16 @@ use dioxus::events::{KeyCode, KeyboardEvent}; use dioxus::prelude::*; -use dioxus::tui::TuiContext; +use dioxus_tui::TuiContext; fn main() { - dioxus::tui::launch_cfg( + dioxus_tui::launch_cfg( App, - dioxus::tui::Config::new() + dioxus_tui::Config::new() .without_ctrl_c_quit() // Some older terminals only support 16 colors or ANSI colors // If your terminal is one of these, change this to BaseColors or ANSI - .with_rendering_mode(dioxus::tui::RenderingMode::Rgb), + .with_rendering_mode(dioxus_tui::RenderingMode::Rgb), ); } diff --git a/docs/guide/examples/hello_world_web.rs b/docs/guide/examples/hello_world_web.rs index a0547b8e5..5f813bbe1 100644 --- a/docs/guide/examples/hello_world_web.rs +++ b/docs/guide/examples/hello_world_web.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::web::launch(App); + dioxus_web::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/hooks_bad.rs b/docs/guide/examples/hooks_bad.rs index bb4a43c26..1503f11bd 100644 --- a/docs/guide/examples/hooks_bad.rs +++ b/docs/guide/examples/hooks_bad.rs @@ -4,7 +4,7 @@ use dioxus::prelude::*; use std::collections::HashMap; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/hooks_counter.rs b/docs/guide/examples/hooks_counter.rs index 3a858c3e8..f717ba650 100644 --- a/docs/guide/examples/hooks_counter.rs +++ b/docs/guide/examples/hooks_counter.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: component diff --git a/docs/guide/examples/hooks_counter_two_state.rs b/docs/guide/examples/hooks_counter_two_state.rs index 5ad534b33..75fcb9117 100644 --- a/docs/guide/examples/hooks_counter_two_state.rs +++ b/docs/guide/examples/hooks_counter_two_state.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: component diff --git a/docs/guide/examples/hooks_use_ref.rs b/docs/guide/examples/hooks_use_ref.rs index c03993561..8c06247ac 100644 --- a/docs/guide/examples/hooks_use_ref.rs +++ b/docs/guide/examples/hooks_use_ref.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: component diff --git a/docs/guide/examples/input_controlled.rs b/docs/guide/examples/input_controlled.rs index 955fe7ef5..b58fe58a7 100644 --- a/docs/guide/examples/input_controlled.rs +++ b/docs/guide/examples/input_controlled.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: component diff --git a/docs/guide/examples/input_uncontrolled.rs b/docs/guide/examples/input_uncontrolled.rs index 66b77769a..5adc4aaad 100644 --- a/docs/guide/examples/input_uncontrolled.rs +++ b/docs/guide/examples/input_uncontrolled.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: component diff --git a/docs/guide/examples/meme_editor.rs b/docs/guide/examples/meme_editor.rs index b8b6858d3..67bef123b 100644 --- a/docs/guide/examples/meme_editor.rs +++ b/docs/guide/examples/meme_editor.rs @@ -5,7 +5,7 @@ use dioxus::events::FormEvent; use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(MemeEditor); + dioxus_desktop::launch(MemeEditor); } // ANCHOR: meme_editor diff --git a/docs/guide/examples/meme_editor_dark_mode.rs b/docs/guide/examples/meme_editor_dark_mode.rs index ed7de16b8..6c58a540b 100644 --- a/docs/guide/examples/meme_editor_dark_mode.rs +++ b/docs/guide/examples/meme_editor_dark_mode.rs @@ -5,7 +5,7 @@ use dioxus::events::FormEvent; use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } // ANCHOR: DarkMode_struct diff --git a/docs/guide/examples/rendering_lists.rs b/docs/guide/examples/rendering_lists.rs index 49fd2b7e2..9e873979d 100644 --- a/docs/guide/examples/rendering_lists.rs +++ b/docs/guide/examples/rendering_lists.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } #[derive(PartialEq, Clone)] diff --git a/docs/guide/examples/rsx_overview.rs b/docs/guide/examples/rsx_overview.rs index 124cf6ebc..8dc102e8a 100644 --- a/docs/guide/examples/rsx_overview.rs +++ b/docs/guide/examples/rsx_overview.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } pub fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/spawn.rs b/docs/guide/examples/spawn.rs index 17dd259f7..9ba8e18ff 100644 --- a/docs/guide/examples/spawn.rs +++ b/docs/guide/examples/spawn.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/examples/use_future.rs b/docs/guide/examples/use_future.rs index da52f8c63..445c8675a 100644 --- a/docs/guide/examples/use_future.rs +++ b/docs/guide/examples/use_future.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } #[derive(serde::Deserialize, Debug)] diff --git a/docs/guide/src/en/__unused/advanced-guides/rsx.md b/docs/guide/src/en/__unused/advanced-guides/rsx.md index 062246490..7c6761493 100644 --- a/docs/guide/src/en/__unused/advanced-guides/rsx.md +++ b/docs/guide/src/en/__unused/advanced-guides/rsx.md @@ -33,7 +33,7 @@ let name = "jane"; let pending = false; let count = 10; -dioxus::ssr::render_lazy(html! { +dioxus_ssr::render_lazy(html! {

"Hello, {name}!"

"Status: {pending}!"

@@ -51,7 +51,7 @@ When helpful, the Dioxus VSCode extension provides a way of converting a selecti It's also a bit easier on the eyes than HTML. ```rust -dioxus::ssr::render_lazy(rsx! { +dioxus_ssr::render_lazy(rsx! { div { p {"Hello, {name}!"} p {"Status: {pending}!"} diff --git a/docs/guide/src/en/__unused/composing.md b/docs/guide/src/en/__unused/composing.md index 5746d6477..b344fe1a3 100644 --- a/docs/guide/src/en/__unused/composing.md +++ b/docs/guide/src/en/__unused/composing.md @@ -159,7 +159,7 @@ force_render(ScopeId(0)); In our guides, we frequently use the phrase "re-render" to describe updates to our app. You'll often hear this paired with "preventing unnecessary re-renders." But what exactly does this mean? -When we call `dioxus::desktop::launch`, Dioxus will create a new `Scope` object and call the component we gave it. Our `rsx!` calls will create new nodes which we return back to the VirtualDom. Dioxus will then look through these nodes for child components, call their functions, and so on until every component has been "rendered." We consider these nodes "rendered" because they were created because of our explicit actions. +When we call `dioxus_desktop::launch`, Dioxus will create a new `Scope` object and call the component we gave it. Our `rsx!` calls will create new nodes which we return back to the VirtualDom. Dioxus will then look through these nodes for child components, call their functions, and so on until every component has been "rendered." We consider these nodes "rendered" because they were created because of our explicit actions. The tree of UI that dioxus creates will roughly look like the tree of components presented earlier: diff --git a/docs/guide/src/en/__unused/event_javascript.rs b/docs/guide/src/en/__unused/event_javascript.rs index 2b0a60340..a0618129d 100644 --- a/docs/guide/src/en/__unused/event_javascript.rs +++ b/docs/guide/src/en/__unused/event_javascript.rs @@ -12,7 +12,7 @@ Instead of passing a closure, you can also pass a string to event handlers – t use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/docs/guide/src/en/__unused/index.md b/docs/guide/src/en/__unused/index.md index 1732afdae..641611f52 100644 --- a/docs/guide/src/en/__unused/index.md +++ b/docs/guide/src/en/__unused/index.md @@ -16,7 +16,7 @@ For the simplest of apps, all of your state can enter the app from the root prop ```rust let all_content = get_all_content().await; -let output = dioxus::ssr::render_lazy(rsx!{ +let output = dioxus_ssr::render_lazy(rsx!{ div { RenderContent { content: all_content } } diff --git a/docs/guide/src/en/getting_started/mobile.md b/docs/guide/src/en/getting_started/mobile.md index 0dffdac30..25a276db5 100644 --- a/docs/guide/src/en/getting_started/mobile.md +++ b/docs/guide/src/en/getting_started/mobile.md @@ -24,7 +24,7 @@ cargo install --git https://github.com/BrainiumLLC/cargo-mobile And then initialize your app for the right platform. Use the `winit` template for now. Right now, there's no "Dioxus" template in cargo-mobile. ```shell -cargo mobile init +cargo mobile init ``` We're going to completely clear out the `dependencies` it generates for us, swapping out `winit` with `dioxus-mobile`. @@ -61,7 +61,7 @@ Edit your `lib.rs`: use dioxus::prelude::*; fn main() { - dioxus::mobile::launch(app); + dioxus_mobile::launch(app); } fn app(cx: Scope) -> Element { diff --git a/docs/guide/src/en/getting_started/ssr.md b/docs/guide/src/en/getting_started/ssr.md index 0b6ca0701..0e17c2c70 100644 --- a/docs/guide/src/en/getting_started/ssr.md +++ b/docs/guide/src/en/getting_started/ssr.md @@ -21,10 +21,10 @@ If you just want to render `rsx!` or a VirtualDom to HTML, check out the API doc // We can render VirtualDoms let mut vdom = VirtualDom::new(app); let _ = vdom.rebuild(); -println!("{}", dioxus::ssr::render_vdom(&vdom)); +println!("{}", dioxus_ssr::render_vdom(&vdom)); // Or we can render rsx! calls directly -println!( "{}", dioxus::ssr::render_lazy(rsx! { h1 { "Hello, world!" } } ); +println!( "{}", dioxus_ssr::render_lazy(rsx! { h1 { "Hello, world!" } } ); ``` However, for this guide, we're going to show how to use Dioxus SSR with `Axum`. @@ -84,7 +84,7 @@ And then add our endpoint. We can either render `rsx!` directly: ```rust async fn app_endpoint() -> Html { - Html(dioxus::ssr::render_lazy(rsx! { + Html(dioxus_ssr::render_lazy(rsx! { h1 { "hello world!" } })) } @@ -100,7 +100,7 @@ async fn app_endpoint() -> Html { let mut app = VirtualDom::new(app); let _ = app.rebuild(); - Html(dioxus::ssr::render_vdom(&app)) + Html(dioxus_ssr::render_vdom(&app)) } ``` diff --git a/docs/guide/src/en/interactivity/index.md b/docs/guide/src/en/interactivity/index.md index 5429402b0..fa24aaa31 100644 --- a/docs/guide/src/en/interactivity/index.md +++ b/docs/guide/src/en/interactivity/index.md @@ -1,3 +1,3 @@ # Interactivity -So far, we've learned how to describe the structure and properties of our user interfaces. However, most interfaces need to be interactive in order to be useful. In this chapter, we describe how to make a Dioxus app that responds to the user. \ No newline at end of file +So far, we've learned how to describe the structure and properties of our user interfaces. However, most interfaces need to be interactive in order to be useful. In this chapter, we describe how to make a Dioxus app that responds to the user. diff --git a/docs/posts/release.md b/docs/posts/release.md index 07030372a..80f8a0f4f 100644 --- a/docs/posts/release.md +++ b/docs/posts/release.md @@ -6,7 +6,7 @@ After many months of work, we're very excited to release the first version of Dioxus! -Dioxus is a new library for building interactive user interfaces (GUI) with Rust. It is built around a Virtual DOM, making it portable for the web, desktop, server, mobile, and more. +Dioxus is a new library for building interactive user interfaces (GUI) with Rust. It is built around a Virtual DOM, making it portable for the web, desktop, server, mobile, and more. Dioxus has the following design goals: @@ -24,7 +24,7 @@ To give you an idea of what Dioxus looks like, here's a simple counter app: use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app) + dioxus_desktop::launch(app) } fn app(cx: Scope) -> Element { @@ -187,7 +187,7 @@ We can add our counter from above. use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app) + dioxus_desktop::launch(app) } fn app(cx: Scope) -> Element { @@ -239,7 +239,7 @@ LazyNodes::new(|f| { The `rsx!` macro generates idiomatic Rust code that uses the factory API — no different than what you'd write by hand yourself. -To make it easier to work with RSX, we've built a small [VSCode extension](https://github.com/DioxusLabs/studio) with useful utilities. This extension provides a command that converts a selected block of HTML into RSX so you can easily reuse existing web templates. +To make it easier to work with RSX, we've built a small [VSCode extension](https://github.com/DioxusLabs/studio) with useful utilities. This extension provides a command that converts a selected block of HTML into RSX so you can easily reuse existing web templates. ## Dioxus prioritizes developer experience @@ -299,7 +299,7 @@ There's *way* more to this story, but hopefully we've convinced you that Dioxus' ## Dioxus is perfected for the IDE -Note: all IDE-related features have only been tested with [Rust-Analyzer](https://github.com/rust-analyzer/rust-analyzer). +Note: all IDE-related features have only been tested with [Rust-Analyzer](https://github.com/rust-analyzer/rust-analyzer). Dioxus code operates pleasantly with your IDE. For starters, most elements are documented through the Rustdoc system. A quick summary of the MDN docs is always under your finger tips: @@ -337,7 +337,7 @@ Dioxus is humbly built off the work done by [Dodrio](https://github.com/fitzgen/ Dioxus is *substantially* more performant than many of the other Rust DOM-based UI libraries (Yew/Percy) and is *significantly* more performant than React - roughly competitive with InfernoJS. While not as performant as libraries like SolidJS/Sycamore, Dioxus imposes roughly a ~3% overhead over DOM patching, so it's *plenty* fast. -## Works on Desktop and Mobile +## Works on Desktop and Mobile We’ve mentioned before that Dioxus works practically anywhere that Rust does. When running natively as a desktop or mobile app, your Dioxus code will run on its own thread, not inside of a web runtime. This means you can access hardware, file system, and platform APIs directly without needing to go through a shim layer. In our examples, we feature a [file explorer app](https://github.com/DioxusLabs/example-projects/tree/master/file-explorer) and [WiFi scanner app](https://github.com/DioxusLabs/example-projects/tree/master/wifi-scanner) where platform access occurs inside an asynchronous multithreaded coroutine. This solves the problem faced by React Native and other cross-platform toolkits where JavaScript apps incur a massive performance penalty with substantial maintenance overhead associated with platform API shims. A desktop app: @@ -401,7 +401,7 @@ Stay tuned for our next article, which will go over some of the optimization tec ## Community -The future is bright for Rust frontends! If you'd like to get involved, we have a [Discord server](https://discord.gg/XgGxMSkvUM), [a subreddit](http://reddit.com/r/dioxus), and [GitHub discussion pages](https://github.com/DioxusLabs/dioxus/discussions). +The future is bright for Rust frontends! If you'd like to get involved, we have a [Discord server](https://discord.gg/XgGxMSkvUM), [a subreddit](http://reddit.com/r/dioxus), and [GitHub discussion pages](https://github.com/DioxusLabs/dioxus/discussions). Let us know what you build! diff --git a/docs/router/src/guide/getting-started.md b/docs/router/src/guide/getting-started.md index 2cf4ef047..7bce3c30a 100644 --- a/docs/router/src/guide/getting-started.md +++ b/docs/router/src/guide/getting-started.md @@ -46,7 +46,7 @@ use dioxus::prelude::*; fn main() { // Launch Dioxus web app - dioxus::web::launch(app); + dioxus_web::launch(app); } // Our root component. diff --git a/examples/all_css.rs b/examples/all_css.rs index baf6294a4..768383b78 100644 --- a/examples/all_css.rs +++ b/examples/all_css.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/all_events.rs b/examples/all_events.rs index 77f7d9a22..d2c2ef0d7 100644 --- a/examples/all_events.rs +++ b/examples/all_events.rs @@ -1,7 +1,7 @@ use dioxus::{events::*, prelude::*}; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } #[derive(Debug)] diff --git a/examples/borrowed.rs b/examples/borrowed.rs index ddee43868..d5e06197c 100644 --- a/examples/borrowed.rs +++ b/examples/borrowed.rs @@ -19,7 +19,7 @@ and is proven to be safe with MIRI. use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/calculator.rs b/examples/calculator.rs index 75da8f1d3..df0ac4c04 100644 --- a/examples/calculator.rs +++ b/examples/calculator.rs @@ -4,12 +4,12 @@ This calculator version uses React-style state management. All state is held as */ use dioxus::events::*; +use dioxus::html::input_data::keyboard_types::Key; use dioxus::prelude::*; -use dioxus_html::input_data::keyboard_types::Key; fn main() { - use dioxus::desktop::tao::dpi::LogicalSize; - dioxus::desktop::launch_cfg(app, |cfg| { + use dioxus_desktop::tao::dpi::LogicalSize; + dioxus_desktop::launch_cfg(app, |cfg| { cfg.with_window(|w| { w.with_title("Calculator Demo") .with_resizable(false) diff --git a/examples/core_reference/README.md b/examples/core_reference/README.md deleted file mode 100644 index a9b3ea60b..000000000 --- a/examples/core_reference/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Reference Guide - -This folder holds a bunch of useful reference code. However, none of the code is meant to be executed (nothing special will happen). - - -| Reference: | What it does | -| --------------------------------------------------- | ------------------------------------------------------ | -| [Basics](./basics.rs) | How to render a simple app | -| [Empty](./empty.rs) | Components can return None | -| [Children](./children.rs) | Components can have children | -| [Suspense](./suspense.rs) | Suspense can be achieved with use_suspense | -| [Conditional Rendering](./conditional_rendering.rs) | Elements can be hidden conditionally | -| [Controlled Inputs](./controlled_inputs.rs) | Inputs are "controlled" similar to React | -| [Fragments](./fragments.rs) | Components can return multiple elements without a root | -| [Inline Styles](./inline_styles.rs) | Styles can be inlined as element attributes | -| [Spread Pattern for Props](./spreadpattern.rs) | Props can be spread into component calls | -| [Iterators](./iterators.rs) | Lists of elements can be made from iterators | -| [Listener](./listener.rs) | State can be updated from event listeners | -| [Memo](./memo.rs) | Memoization is controlled via PartialEq | -| [Custom Elements](./custom_elements.rs) | Define custom elements | -| [Anti-patterns](./antipatterns.rs) | What not to do! | diff --git a/examples/core_reference/custom_elements.rs b/examples/core_reference/custom_elements.rs deleted file mode 100644 index 6c7367d20..000000000 --- a/examples/core_reference/custom_elements.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Example: Web Components & Custom Elements -//! ----------------------------------------- -//! -//! Web components are a flavor of html elements that can be user-defined. -//! See: https://www.webcomponents.org for more information. -//! -//! Users who use webcomponents typically don't use Dioxus. However, if you would like to use webcomponents in Dioxus, -//! you can easily create a new custom element with compile-time correct wrappers around the webcomponent. -//! -//! We don't support building new webcomponents with Dioxus, however. :( - -use dioxus::prelude::*; - -pub fn Example(cx: Scope) -> Element { - cx.render(rsx! { - div { - custom_element { - custom_attr: "custom data on custom elements" - } - } - }) -} - -mod dioxus_elements { - use std::fmt::Arguments; - - use dioxus::prelude::DioxusElement; - - #[allow(non_camel_case_types)] - pub struct custom_element; - impl DioxusElement for custom_element { - const TAG_NAME: &'static str = "custom_element"; - const NAME_SPACE: Option<&'static str> = None; - } - impl custom_element { - pub fn custom_attr<'a>(&self, f: NodeFactory<'a>, val: Arguments) -> Attribute<'a> { - f.attr("custom_asttr", val, None, false) - } - } - - // Re-export the normal html namespace - pub use dioxus::prelude::dioxus_elements::*; - use dioxus_core::{nodes::Attribute, NodeFactory}; -} diff --git a/examples/core_reference/errorhandling.rs b/examples/core_reference/errorhandling.rs deleted file mode 100644 index 72b7d5468..000000000 --- a/examples/core_reference/errorhandling.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! Example: Error Handling -//! ------------------------ -//! -//! Error handling in Dioxus comes in a few flavors. Because Dioxus is a Rust project, Options and Results are obviously -//! the go-to way of wrapping possibly-errored data. However, if a component fails when "unwrapping," everything will crash, -//! the page will deadlock, and your users will be sad. -//! -//! So, obviously, you need to handle your errors. -//! -//! Fortunately, it's easy to avoid panics, even during quick prototyping. -//! -//! Here are a few strategies: -//! - Leverage the ability to return "None" and propagate None directly -//! - Instead of propagating "None" manually, use the "?" syntax sugar -//! - Convert Results into Options with .ok() -//! - Manually display a separate screen by matching on Options/Results -//! -//! There *are* plans to add helpful screens for when apps completely panic in Wasm. However, you should really try to -//! avoid panicking. -use dioxus::prelude::*; -fn main() {} - -/// This is one way to go about error handling (just toss things away with unwrap). -/// However, if you get it wrong, the whole app will crash. -/// This is pretty flimsy. -pub fn App(cx: Scope) -> Element { - let data = get_data().unwrap(); - cx.render(rsx!( div { "{data}" } )) -} - -/// This is a pretty verbose way of error handling -/// However, it's still pretty good since we don't panic, just fail to render anything -pub fn App1(cx: Scope) -> Element { - let data = match get_data() { - Some(data) => data, - None => return None, - }; - cx.render(rsx!( div { "{data}" } )) -} - -/// This is an even better form of error handling. -/// However, it _does_ make the component go blank, which might not be desirable. -/// -/// This type of error handling is good when you have "selectors" that produce Some/None based on some state that's -/// already controlled higher in the tree. i.e. displaying a "Username" in a component that should only be shown if -/// a user is logged in. -/// -/// Dioxus will throw an error in the console if the None-path is ever taken. -pub fn App2(cx: Scope) -> Element { - let data = get_data()?; - cx.render(rsx!( div { "{data}" } )) -} - -/// This is top-tier error handling since it displays a failure state. -/// -/// However, the error is lacking in context. -pub fn App3(cx: Scope) -> Element { - match get_data() { - Some(data) => cx.render(rsx!( div { "{data}" } )), - None => cx.render(rsx!( div { "Failed to load data :(" } )), - } -} - -/// For errors that return results, it's possible to short-circuit the match-based error handling with `.ok()` which converts -/// a Result into an Option and lets you abort rendering by early-returning `None` -pub fn App4(cx: Scope) -> Element { - let data = get_data_err().ok()?; - cx.render(rsx!( div { "{data}" } )) -} - -/// This is great error handling since it displays a failure state... with context! -/// -/// Hopefully you'll never need to display a screen like this. It's rather bad taste -pub fn App5(cx: Scope) -> Element { - match get_data_err() { - Ok(data) => cx.render(rsx!( div { "{data}" } )), - Err(c) => cx.render(rsx!( div { "Failed to load data: {c}" } )), - } -} - -// this fetching function produces "nothing" -fn get_data() -> Option { - None -} - -// this fetching function produces "nothing" -fn get_data_err() -> Result { - Result::Err("Failed!") -} diff --git a/examples/core_reference/global_css.rs b/examples/core_reference/global_css.rs deleted file mode 100644 index cd007b42f..000000000 --- a/examples/core_reference/global_css.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Examples: CSS -//! ------------- -//! -//! Originally taken from: -//! - https://www.w3schools.com/html/tryit.asp?filename=tryhtml_css_internal -//! -//! Include global styles in your app! -//! -//! You can simply drop in a "style" tag and set the inner contents to your stylesheet. -//! It's slightly more manual than React, but is less magical. -//! -//! A coming update with the assets system will make it possible to include global css from child components. - -use dioxus::prelude::*; - -const STYLE: &str = r#" -body {background-color: powderblue;} -h1 {color: blue;} -p {color: red;} -"#; - -pub fn Example(cx: Scope) -> Element { - cx.render(rsx! { - head { style { "{STYLE}" } } - body { - h1 {"This is a heading"} - p {"This is a paragraph"} - } - }) -} diff --git a/examples/core_reference/inline_styles.rs b/examples/core_reference/inline_styles.rs deleted file mode 100644 index 06cb3f705..000000000 --- a/examples/core_reference/inline_styles.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! Example: Inline Styles -//! ---------------------- -//! -//! This example shows how to use inline styles in Dioxus components. -//! -//! Inline styles function very similarly to regular attributes, just grouped together in "style". -//! -//! Inline styles in Dioxus are more performant than React since we're able to cache attributes and compare by pointers. -//! However, it's still not as performant as cascaded styles. Use with care. - -use dioxus::prelude::*; - -pub fn Example(cx: Scope) -> Element { - cx.render(rsx! { - head { - background_color: "powderblue" - } - body { - h1 { - color: "blue", - "This is a heading" - } - p { - color: "red", - "This is a paragraph" - } - } - }) -} diff --git a/examples/core_reference/memo.rs b/examples/core_reference/memo.rs deleted file mode 100644 index 0c2e0a156..000000000 --- a/examples/core_reference/memo.rs +++ /dev/null @@ -1,84 +0,0 @@ -//! Example: Memoization -//! -------------------- -//! -//! This example showcases how memoization works in Dioxus. -//! -//! Memoization is the process in which Dioxus skips diffing child components if their props don't change. -//! In React, components are never memoized unless wrapped in `memo` or configured with `shouldComponentUpdate`. -//! -//! Due to the safety guarantees of Rust, we can automatically memoize components in some circumstances. Whenever a -//! component's properties are valid for the `'static` lifetime, Dioxus will automatically compare the props before -//! diffing the component. If the props don't change (according to PartialEq), the component will not be re-rendered. -//! -//! However, if the props use some generics or borrow from their parent, then Dioxus can't safely supress updates, -//! and is forced to render the child. If you think that this behavior is wrong for your usecase, you can implement -//! the memo method yourself, but beware, doing so is UNSAFE and may cause issues if you do it wrong. -//! -//! If you want to gain that little bit extra performance, consider using global state management, signals, or -//! memoized collections like im-rc which are designed for this use case. - -use dioxus::prelude::*; - -// By default, components with no props are always memoized. -// A props of () is considered empty. -pub fn Example(cx: Scope) -> Element { - cx.render(rsx! { - div { "100% memoized!" } - }) -} - -// These props do not borrow any content, and therefore can be safely memoized. -// However, the parent *must* create a new string on every render. -// Notice how these props implement PartialEq - this is required for 'static props -#[derive(PartialEq, Props)] -pub struct MyProps1 { - name: String, -} - -pub fn Example1(cx: Scope) -> Element { - cx.render(rsx! { - div { "100% memoized! {cx.props.name}" } - }) -} - -// These props do not borrow any content, and therefore can be safely memoized. -// In contrast with the `String` example, these props use `Rc` which operates similar to strings in JavaScript. -// These strings cannot be modified, but may be cheaply shared in many places without issue. -#[derive(PartialEq, Props)] -pub struct MyProps2 { - name: std::rc::Rc, -} - -pub fn Example2(cx: Scope) -> Element { - cx.render(rsx! { - div { "100% memoized! {cx.props.name}" } - }) -} - -// These props *do* borrow any content, and therefore cannot be safely memoized!. -#[derive(PartialEq, Props)] -pub struct MyProps3<'a> { - name: &'a str, -} -// We need to manually specify a lifetime that ensures props and scope (the component's state) share the same lifetime. -// Using the `pub fn Example(cx: Scope): Component` pattern _will_ specify a lifetime, but that lifetime will be static which might -// not exactly be what you want -fn Example3(cx: Scope<'a, MyProps3<'a>>) -> DomTree { - cx.render(rsx! { - div { "Not memoized! {cx.props.name}" } - }) -} - -// These props *do* borrow any content, and therefore cannot be safely memoized!. -// However, they cannot be compared, so we don't need the PartialEq flag. -#[derive(Props)] -pub struct MyProps4<'a> { - onhandle: &'a dyn Fn(), -} - -// We need to manually specify a lifetime that ensures props and scope (the component's state) share the same lifetime. -fn Example4<'a>(cx: Scope<'a, MyProps4<'a>>) -> DomTree { - cx.render(rsx! { - div { "Not memoized!", onclick: move |_| (props.onhandle)() } - }) -} diff --git a/examples/core_reference/spreadpattern.rs b/examples/core_reference/spreadpattern.rs deleted file mode 100644 index 397fad294..000000000 --- a/examples/core_reference/spreadpattern.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Example: Spread pattern for Components -//! -------------------------------------- -//! -//! Dioxus supports the "spread" pattern for manually building a component's properties. This is useful when props -//! are passed down from a parent, or it's more ergonomic to construct props from outside the rsx! macro. -//! -//! To use the spread pattern, simply pass ".." followed by a Rust expression. This pattern also supports overriding -//! values, using the manual props as the base and then modifying fields specified with non-spread attributes. - -use dioxus::prelude::*; - -pub fn Example(cx: Scope) -> Element { - let props = MyProps { - count: 0, - live: true, - name: "Dioxus", - }; - cx.render(rsx! { - Example1 { ..props, count: 10, div {"child"} } - }) -} - -#[derive(Props)] -pub struct MyProps<'a> { - count: u32, - live: bool, - name: &'static str, - children: Element<'a>, -} - -pub fn Example1<'a>(cx: Scope<'a, MyProps<'a>>) -> Element { - let MyProps { count, live, name } = cx.props; - cx.render(rsx! { - div { - h1 { "Hello, {name}"} - h3 {"Are we alive? {live}"} - p {"Count is {count}"} - &cx.props.children - } - }) -} diff --git a/examples/core_reference/suspense.rs b/examples/core_reference/suspense.rs deleted file mode 100644 index ea1f92b96..000000000 --- a/examples/core_reference/suspense.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Example: Suspense -//! ----------------- -//! This example demonstrates how the use_suspense hook can be used to load and render asynchronous data. Suspense enables -//! components to wait on futures to complete before rendering the result into VNodes. These VNodes are immediately -//! available in a suspended" fashion and will automatically propagate to the UI when the future completes. -//! -//! Currently, suspense futures are non-restartable. In the future, we'll provide more granular control of how to start, -//! stop, and reset these futures. - -use dioxus::prelude::*; -#[derive(serde::Deserialize)] -struct DogApi { - message: String, -} -const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random"; - -pub fn Example(cx: Scope) -> Element { - let doggo = use_suspense( - cx, - || surf::get(ENDPOINT).recv_json::(), - |cx, res| match res { - Ok(res) => rsx!( - cx, - img { - src: "{res.message}" - } - ), - Err(_) => rsx!(cx, div { "No doggos for you :(" }), - }, - ); - - cx.render(rsx!( - div { - h1 {"Waiting for a doggo..."} - {doggo} - } - )) -} diff --git a/examples/core_reference/task.rs b/examples/core_reference/task.rs deleted file mode 100644 index 25f634517..000000000 --- a/examples/core_reference/task.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Example: Tasks -//! -------------- -//! -//! Built around the same system that powers suspense, Dioxus also allows users to write arbitrary tasks that can modify -//! state asynchronously. `use_task` takes a future and returns a task handle and an option that holds the tasks's return -//! value. When the task completes, the component will re-render with the result freshly available. -//! -//! Tasks don't necessarily need to complete, however. It would be completely reasonable to wire up a websocket receiver -//! in a task and have it work infinitely while the app is running. If the socket throws an error, the task could complete -//! and the UI could present a helpful error message. -//! -//! Tasks also return the `TaskHandle` type which lets other component logic start, stop, and restart the task at any time. -//! Tasks are very much like an async-flavoroued coroutine, making them incredibly powerful. -//! -//! Tasks must be valid for the 'static lifetime, so any state management neeeds to be cloned into the closure. `use_state` -//! has a method called `for_async` which generates an AsyncUseState wrapper. This has a very similar API to the regualr -//! `use_state` but is `static. -//! -//! Remeber `use_task` is a hook! Don't call it out of order or in loops. You might aaccidentally swap the task handles -//! and break things in subtle ways. -//! -//! Whenever a component is scheduled for deletion, the task is dropped. Make sure that whatever primitives used in the -//! task have a valid drop implementation and won't leave resources tied up. - -use dioxus::prelude::*; - -pub static Example: Component = |cx| { - let count = use_state(&cx, || 0); - let mut direction = use_state(&cx, || 1); - - // Tasks are 'static, so we need to copy relevant items in - let (async_count, dir) = (count.for_async(), *direction); - - let (task, result) = use_task(cx, move || async move { - loop { - gloo_timers::future::TimeoutFuture::new(250).await; - *async_count.get_mut() += dir; - } - }); - - cx.render(rsx! { - div { - h1 {"count is {count}"} - button { - onclick: move |_| task.stop(), - "Stop counting" - } - button { - onclick: move |_| task.resume(), - "Start counting" - } - button { - onclick: move |_| { - direction *= -1; - task.restart(); - } - "Switch counting direcion" - } - } - }) -}; diff --git a/examples/crm.rs b/examples/crm.rs index 5638c35ba..1943ed97c 100644 --- a/examples/crm.rs +++ b/examples/crm.rs @@ -2,9 +2,10 @@ Tiny CRM: A port of the Yew CRM example to Dioxus. */ use dioxus::prelude::*; +use dioxus_router::{Link, Route, Router}; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } #[derive(Clone, Debug, Default)] diff --git a/examples/custom_assets.rs b/examples/custom_assets.rs index e623d5b50..86d82acf4 100644 --- a/examples/custom_assets.rs +++ b/examples/custom_assets.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/custom_element.rs b/examples/custom_element.rs index e0b12d87e..1c870e157 100644 --- a/examples/custom_element.rs +++ b/examples/custom_element.rs @@ -10,7 +10,7 @@ fn main() { let mut dom = VirtualDom::new(app); let _ = dom.rebuild(); - let output = dioxus::ssr::render_vdom(&dom); + let output = dioxus_ssr::render_vdom(&dom); println!("{}", output); } diff --git a/examples/custom_html.rs b/examples/custom_html.rs index 02f603710..9c42b7e8f 100644 --- a/examples/custom_html.rs +++ b/examples/custom_html.rs @@ -4,11 +4,11 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch_cfg(app, |c| { + dioxus_desktop::launch_cfg(app, |c| { c.with_custom_head("".into()) }); - dioxus::desktop::launch_cfg(app, |c| { + dioxus_desktop::launch_cfg(app, |c| { c.with_custom_index( r#" diff --git a/examples/disabled.rs b/examples/disabled.rs index 087c270bc..2545748fd 100644 --- a/examples/disabled.rs +++ b/examples/disabled.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/dog_app.rs b/examples/dog_app.rs index a2a27c845..5c78ed0bf 100644 --- a/examples/dog_app.rs +++ b/examples/dog_app.rs @@ -2,12 +2,11 @@ //! Render a bunch of doggos! +use dioxus::prelude::*; use std::collections::HashMap; -use dioxus::prelude::*; - fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } #[derive(Debug, Clone, PartialEq, serde::Deserialize)] diff --git a/examples/error_handle.rs b/examples/error_handle.rs index 428ea09c6..1d5d82b6d 100644 --- a/examples/error_handle.rs +++ b/examples/error_handle.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/eval.rs b/examples/eval.rs index c0801b507..495288fcb 100644 --- a/examples/eval.rs +++ b/examples/eval.rs @@ -1,12 +1,12 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { let script = use_state(&cx, String::new); - let eval = use_eval(&cx); + let eval = dioxus_desktop::use_eval(&cx); cx.render(rsx! { div { @@ -17,7 +17,6 @@ fn app(cx: Scope) -> Element { } button { onclick: move |_| eval(script), - "Execute" } } diff --git a/examples/fermi.rs b/examples/fermi.rs index 79e3da1d6..06bc38fc5 100644 --- a/examples/fermi.rs +++ b/examples/fermi.rs @@ -1,9 +1,10 @@ #![allow(non_snake_case)] use dioxus::prelude::*; +use fermi::*; fn main() { - dioxus::desktop::launch(app) + dioxus_desktop::launch(app) } static NAME: Atom = |_| "world".to_string(); diff --git a/examples/file_explorer.rs b/examples/file_explorer.rs index cc578ba02..27f9bee6f 100644 --- a/examples/file_explorer.rs +++ b/examples/file_explorer.rs @@ -11,7 +11,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch_cfg(app, |c| c.with_window(|w| w.with_resizable(true))); + dioxus_desktop::launch_cfg(app, |c| c.with_window(|w| w.with_resizable(true))); } fn app(cx: Scope) -> Element { diff --git a/examples/filedragdrop.rs b/examples/filedragdrop.rs index e91334c50..caa86a529 100644 --- a/examples/filedragdrop.rs +++ b/examples/filedragdrop.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch_with_props(app, (), |c| { + dioxus_desktop::launch_with_props(app, (), |c| { c.with_file_drop_handler(|_w, e| { println!("{:?}", e); true diff --git a/examples/flat_router.rs b/examples/flat_router.rs index 24b0bc78b..fe1a7b112 100644 --- a/examples/flat_router.rs +++ b/examples/flat_router.rs @@ -1,10 +1,11 @@ -use dioxus::desktop::tao::dpi::LogicalSize; use dioxus::prelude::*; +use dioxus_desktop::tao::dpi::LogicalSize; +use dioxus_router::{Link, Route, Router}; fn main() { env_logger::init(); - dioxus::desktop::launch_cfg(app, |c| { + dioxus_desktop::launch_cfg(app, |c| { c.with_window(|c| { c.with_title("Spinsense Client") .with_inner_size(LogicalSize::new(600, 1000)) diff --git a/examples/form.rs b/examples/form.rs index 3b8d470b3..a7de142f3 100644 --- a/examples/form.rs +++ b/examples/form.rs @@ -6,24 +6,22 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { cx.render(rsx! { - Router { - div { - h1 { "Form" } - form { - onsubmit: move |ev| println!("Submitted {:?}", ev.values), - oninput: move |ev| println!("Input {:?}", ev.values), - input { r#type: "text", name: "username" } - input { r#type: "text", name: "full-name" } - input { r#type: "password", name: "password" } - input { r#type: "radio", name: "color", value: "red" } - input { r#type: "radio", name: "color", value: "blue" } - button { r#type: "submit", value: "Submit", "Submit the form" } - } + div { + h1 { "Form" } + form { + onsubmit: move |ev| println!("Submitted {:?}", ev.values), + oninput: move |ev| println!("Input {:?}", ev.values), + input { r#type: "text", name: "username" } + input { r#type: "text", name: "full-name" } + input { r#type: "password", name: "password" } + input { r#type: "radio", name: "color", value: "red" } + input { r#type: "radio", name: "color", value: "blue" } + button { r#type: "submit", value: "Submit", "Submit the form" } } } }) diff --git a/examples/framework_benchmark.rs b/examples/framework_benchmark.rs index 55cb1b853..a88946af4 100644 --- a/examples/framework_benchmark.rs +++ b/examples/framework_benchmark.rs @@ -4,7 +4,7 @@ use dioxus::prelude::*; use rand::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } #[derive(Clone, PartialEq)] diff --git a/examples/heavy_compute.rs b/examples/heavy_compute.rs index 6e10a2f1f..641037211 100644 --- a/examples/heavy_compute.rs +++ b/examples/heavy_compute.rs @@ -10,7 +10,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/hello_world.rs b/examples/hello_world.rs index ab7bfffa3..9553f5c7e 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/hydration.rs b/examples/hydration.rs index acfb3a320..c126d7dae 100644 --- a/examples/hydration.rs +++ b/examples/hydration.rs @@ -10,13 +10,12 @@ //! proof-of-concept for the hydration feature, but you'll probably only want to use hydration for the web. use dioxus::prelude::*; -use dioxus::ssr; fn main() { let vdom = VirtualDom::new(app); - let content = ssr::render_vdom_cfg(&vdom, |f| f.pre_render(true)); + let content = dioxus_ssr::render_vdom_cfg(&vdom, |f| f.pre_render(true)); - dioxus::desktop::launch_cfg(app, |c| c.with_prerendered(content)); + dioxus_desktop::launch_cfg(app, |c| c.with_prerendered(content)); } fn app(cx: Scope) -> Element { diff --git a/examples/inlineprops.rs b/examples/inlineprops.rs index e63d5977d..786714a2e 100644 --- a/examples/inlineprops.rs +++ b/examples/inlineprops.rs @@ -24,7 +24,7 @@ fn Thing4<'a>(cx: Scope<'a>, _a: &'a u32) -> Element<'a> { } fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/inputs.rs b/examples/inputs.rs index e0f8cd300..8be3fdee2 100644 --- a/examples/inputs.rs +++ b/examples/inputs.rs @@ -5,7 +5,7 @@ use dioxus::{events::FormEvent, prelude::*}; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } const FIELDS: &[(&str, &str)] = &[ diff --git a/examples/link.rs b/examples/link.rs index 6f7638c86..afef99cf2 100644 --- a/examples/link.rs +++ b/examples/link.rs @@ -1,25 +1,21 @@ use dioxus::prelude::*; +use dioxus_router::{Link, Route, Router}; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { cx.render(rsx! ( div { p { - a { - href: "http://dioxuslabs.com/", - "Default link - links outside of your app" - } + a { href: "http://dioxuslabs.com/", "Default link - links outside of your app" } } p { a { href: "http://dioxuslabs.com/", prevent_default: "onclick", - onclick: |_| { - println!("Hello Dioxus"); - }, + onclick: |_| println!("Hello Dioxus"), "Custom event link - links inside of your app", } } @@ -28,7 +24,6 @@ fn app(cx: Scope) -> Element { Router { Route { to: "/", h1 { "Home" } }, Route { to: "/settings", h1 { "settings" } }, - p { "----"} ul { Link { to: "/", li { "Router link to home" } }, diff --git a/examples/login_form.rs b/examples/login_form.rs index 0a0c77e87..a0bc85a17 100644 --- a/examples/login_form.rs +++ b/examples/login_form.rs @@ -5,7 +5,7 @@ use dioxus::events::*; use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/nested_listeners.rs b/examples/nested_listeners.rs index aef17526d..7e3a1a066 100644 --- a/examples/nested_listeners.rs +++ b/examples/nested_listeners.rs @@ -7,7 +7,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/optional_props.rs b/examples/optional_props.rs index 3c47b3aac..c5652a2e7 100644 --- a/examples/optional_props.rs +++ b/examples/optional_props.rs @@ -7,7 +7,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/pattern_model.rs b/examples/pattern_model.rs index c88bc78fb..71c854352 100644 --- a/examples/pattern_model.rs +++ b/examples/pattern_model.rs @@ -17,13 +17,13 @@ //! the RefCell will panic and crash. You can use `try_get_mut` or `.modify` to avoid this problem, or just not hold two //! RefMuts at the same time. -use dioxus::desktop::wry::application::dpi::LogicalSize; use dioxus::events::*; +use dioxus::html::input_data::keyboard_types::Key; use dioxus::prelude::*; -use dioxus_html::input_data::keyboard_types::Key; +use dioxus_desktop::wry::application::dpi::LogicalSize; fn main() { - dioxus::desktop::launch_cfg(app, |cfg| { + dioxus_desktop::launch_cfg(app, |cfg| { cfg.with_window(|w| { w.with_title("Calculator Demo") .with_resizable(false) diff --git a/examples/pattern_reducer.rs b/examples/pattern_reducer.rs index beb6f414f..c3d1a962d 100644 --- a/examples/pattern_reducer.rs +++ b/examples/pattern_reducer.rs @@ -11,7 +11,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/readme.rs b/examples/readme.rs index 4f4250343..59816357a 100644 --- a/examples/readme.rs +++ b/examples/readme.rs @@ -5,7 +5,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/router.rs b/examples/router.rs index c0c021a66..20b168670 100644 --- a/examples/router.rs +++ b/examples/router.rs @@ -1,11 +1,11 @@ #![allow(non_snake_case)] use dioxus::prelude::*; -use dioxus::router::{Link, Route, Router}; +use dioxus_router::{Link, Route, Router}; use serde::Deserialize; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { @@ -30,7 +30,7 @@ fn app(cx: Scope) -> Element { } fn BlogPost(cx: Scope) -> Element { - let post = dioxus::router::use_route(&cx).last_segment()?; + let post = dioxus_router::use_route(&cx).last_segment()?; cx.render(rsx! { div { @@ -46,9 +46,9 @@ struct Query { } fn User(cx: Scope) -> Element { - let post = dioxus::router::use_route(&cx).last_segment()?; + let post = dioxus_router::use_route(&cx).last_segment()?; - let query = dioxus::router::use_route(&cx) + let query = dioxus_router::use_route(&cx) .query::() .unwrap_or(Query { bold: false }); diff --git a/examples/rsx_compile_fail.rs b/examples/rsx_compile_fail.rs index 20760ef5b..4b9ac017b 100644 --- a/examples/rsx_compile_fail.rs +++ b/examples/rsx_compile_fail.rs @@ -7,7 +7,7 @@ fn main() { let mut vdom = VirtualDom::new(example); vdom.rebuild(); - let out = dioxus::ssr::render_vdom_cfg(&vdom, |c| c.newline(true).indent(true)); + let out = dioxus_ssr::render_vdom_cfg(&vdom, |c| c.newline(true).indent(true)); println!("{}", out); } diff --git a/examples/rsx_usage.rs b/examples/rsx_usage.rs index 774eb0ead..8a84fc1e2 100644 --- a/examples/rsx_usage.rs +++ b/examples/rsx_usage.rs @@ -39,7 +39,7 @@ //! - Allow top-level fragments //! fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } /// When trying to return "nothing" to Dioxus, you'll need to specify the type parameter or Rust will be sad. diff --git a/examples/ssr.rs b/examples/ssr.rs index 43240c99d..7d3e5b615 100644 --- a/examples/ssr.rs +++ b/examples/ssr.rs @@ -10,12 +10,12 @@ fn main() { // We can render VirtualDoms let mut vdom = VirtualDom::new(app); let _ = vdom.rebuild(); - println!("{}", dioxus::ssr::render_vdom(&vdom)); + println!("{}", dioxus_ssr::render_vdom(&vdom)); // Or we can render rsx! calls themselves println!( "{}", - dioxus::ssr::render_lazy(rsx! { + dioxus_ssr::render_lazy(rsx! { div { h1 { "Hello, world!" } } @@ -25,14 +25,14 @@ fn main() { // We can configure the SSR rendering to add ids for rehydration println!( "{}", - dioxus::ssr::render_vdom_cfg(&vdom, |c| c.pre_render(true)) + dioxus_ssr::render_vdom_cfg(&vdom, |c| c.pre_render(true)) ); // We can even render as a writer let mut file = String::new(); let _ = file.write_fmt(format_args!( "{}", - dioxus::ssr::TextRenderer::from_vdom(&vdom, Default::default()) + dioxus_ssr::TextRenderer::from_vdom(&vdom, Default::default()) )); println!("{}", file); } diff --git a/examples/suspense.rs b/examples/suspense.rs index ace5954f2..0c2d4959e 100644 --- a/examples/suspense.rs +++ b/examples/suspense.rs @@ -16,8 +16,8 @@ use dioxus::prelude::*; fn main() { - use dioxus::desktop::tao::dpi::LogicalSize; - dioxus::desktop::launch_cfg(app, |cfg| { + use dioxus_desktop::tao::dpi::LogicalSize; + dioxus_desktop::launch_cfg(app, |cfg| { cfg.with_window(|w| { w.with_title("Doggo Fetcher") .with_inner_size(LogicalSize::new(600.0, 800.0)) diff --git a/examples/svg.rs b/examples/svg.rs index d924f0222..8e993b3e3 100644 --- a/examples/svg.rs +++ b/examples/svg.rs @@ -3,7 +3,7 @@ use dioxus::{events::MouseEvent, prelude::*}; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/svg_basic.rs b/examples/svg_basic.rs index 40eb80b23..e950eb339 100644 --- a/examples/svg_basic.rs +++ b/examples/svg_basic.rs @@ -71,5 +71,5 @@ fn app(cx: Scope) -> Element { } fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } diff --git a/examples/tailwind.rs b/examples/tailwind.rs index e0cb2339a..77918b735 100644 --- a/examples/tailwind.rs +++ b/examples/tailwind.rs @@ -11,7 +11,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch_cfg(app, |c| { + dioxus_desktop::launch_cfg(app, |c| { c.with_custom_head("".to_string()) }); } diff --git a/examples/tasks.rs b/examples/tasks.rs index 728423993..7c192a593 100644 --- a/examples/tasks.rs +++ b/examples/tasks.rs @@ -6,7 +6,7 @@ use dioxus::prelude::*; use std::time::Duration; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/textarea.rs b/examples/textarea.rs index 9acc732cd..26283b23d 100644 --- a/examples/textarea.rs +++ b/examples/textarea.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/todomvc.rs b/examples/todomvc.rs index cf9a49410..f984957e0 100644 --- a/examples/todomvc.rs +++ b/examples/todomvc.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; use dioxus_elements::input_data::keyboard_types::Key; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } #[derive(PartialEq)] diff --git a/examples/window_event.rs b/examples/window_event.rs index 0be929ebb..ee2d3a752 100644 --- a/examples/window_event.rs +++ b/examples/window_event.rs @@ -1,13 +1,13 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch_cfg(app, |cfg| { + dioxus_desktop::launch_cfg(app, |cfg| { cfg.with_window(|w| w.with_title("BorderLess Demo").with_decorations(false)) }); } fn app(cx: Scope) -> Element { - let window = dioxus::desktop::use_window(&cx); + let window = dioxus_desktop::use_window(&cx); // if you want to make window fullscreen, you need close the resizable. // window.set_fullscreen(true); diff --git a/examples/window_zoom.rs b/examples/window_zoom.rs index cfb831550..d312b0af8 100644 --- a/examples/window_zoom.rs +++ b/examples/window_zoom.rs @@ -1,8 +1,8 @@ -use dioxus::desktop::use_window; use dioxus::prelude::*; +use dioxus_desktop::use_window; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/xss_safety.rs b/examples/xss_safety.rs index 36fc81a95..2d5eba20c 100644 --- a/examples/xss_safety.rs +++ b/examples/xss_safety.rs @@ -5,7 +5,7 @@ use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/notes/Parity.md b/notes/Parity.md deleted file mode 100644 index d4299dfd2..000000000 --- a/notes/Parity.md +++ /dev/null @@ -1,46 +0,0 @@ -# Parity with React - -Parity has moved to the homepage - -## Required services: - ---- - -Gloo is covering a lot of these. We want to build hooks around these and provide examples on how to use them. -https://github.com/rustwasm/gloo - -For example, resize observer would function like this: - -```rust -pub static Example: Component = |cx| { - let observer = use_resize_observer(); - - cx.render(rsx!( - div { ref: observer.node_ref - "Size, x: {observer.x} y: {observer.y}" - } - )) -} -``` - -However, resize observing is _not_ cross-platform, so this hook (internally) needs to abstract over the rendering platform. - -For other services, we shell out to gloo. If the gloo service doesn't exist, then we need to contribute to the project to make sure it exists. - -| Service | Hook examples | Current Projects | -| ---------------------------- | ------------- | ---------------- | -| Fetch | 👀 | Reqwest/surf | -| Local storage (cache) | 👀 | Gloo | -| Persistent storage (IndexDB) | 👀 | 👀 | -| WebSocket | 👀 | Gloo | -| 3D Renderer / WebGL | 👀 | Gloo | -| Web Worker | 👀 | 👀 | -| Router | 👀 | 👀 | -| Notifications | 👀 | 👀 | -| WebRTC Client | 👀 | 👀 | -| Service Workers | 👀 | 👀 | -| Resize Observer | 👀 | 👀 | -| Canvas | 👀 | 👀 | -| Clipboard | 👀 | 👀 | -| Fullscreen | 👀 | 👀 | -| History API | 👀 | 👀 | diff --git a/notes/README.md b/notes/README.md index 3655de0e9..1556afff4 100644 --- a/notes/README.md +++ b/notes/README.md @@ -44,7 +44,7 @@ To launch an app, we use the `launch` method for the specific renderer we want t use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { @@ -276,7 +276,7 @@ Using components, templates, and hooks, we can build a simple app. use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(App); + dioxus_desktop::launch(App); } fn App(cx: Scope) -> Element { diff --git a/notes/ROADMAP.md b/notes/ROADMAP.md deleted file mode 100644 index cdee47e6e..000000000 --- a/notes/ROADMAP.md +++ /dev/null @@ -1,90 +0,0 @@ -# Road map - -This release map gives a sense of the release cadence and features per update going forward into the future. PRs are required to be squashed before merging. For each point release, we save a branch on master (0.1, 0.2, 0.3, master). Eventually, we'll remove these in favor of higher point releases when dioxus is stabilized. Any live PRs will be merged into the dev branch. - -Until 0.3, Dioxus will be in stealth mode. The goal is to launch with a bountiful feature set and a cohesive API before OSS tears it apart :). - -## v0.1: Bare Necessities - -> Enable ergonomic and performant webapps - ---- - -Dioxus Core - -- Lifecycles for components -- Internal event system -- Diffing -- Patching - -Html macro - -- special formatting -- closure handlers -- child handlers -- iterator handlers - -Dioxus web - -- a - -Dioxus CLI - -- Develop -- Bundle -- Test - -Server-side-rendering - -- Write nodes to string -- Integration with tide, Actix, warp - -Dioxus WebView (desktop) - -- One-file setup for desktop apps -- Integration with the web browser for rapid development - -## v0.2: Bread and butter - -> Complex apps? CHECK - ---- - -State management - -- Dioxus-Reducer as the blessed redux alternative - - Includes thunks and reducers (async dispatches) -- Dioxus-DataFlow as the blessed recoil alternative - - The hip, new approach for granular state - -Dioxus CLI - -- Visual tool? -- Asset bundling service - -Dioxus DevTools integration with the web - -- Basic support for pure liveview/webview - -## v0.3: Superpowers - -> Enable LiveView for fullstack development - ---- - -Dioxus LiveView - -- Custom server built on Actix (or something fast) -- Ergonomic builders -- Concurrent system built into dioxus core - -Dioxus iOS - -- Initial support via webview -- Look into native support based on how Flutter/SwiftUI works - -Dioxus Android - -## v0.4: Community - -> Foster the incoming community diff --git a/notes/SAFETY.md b/notes/SAFETY.md deleted file mode 100644 index b3ac026e2..000000000 --- a/notes/SAFETY.md +++ /dev/null @@ -1,26 +0,0 @@ -# Safety - -We don't claim to be a "safe" library. We want to be 100% safe, and will create tests and validate that we are, but our priorities for this library are: - -- productivity -- performance -- safety - -We are willing to use sharp tools (ie transmuting self-referential pointer types) in order to achieve higher ergonomics (ie returning self-referential listeners). - -However, we can only use these sharp tools if we verify that it's not possible to write user-facing code that breaks safety guarantees. For internal code... well, whoever contributes needs to understand the architecture and read the comments related to safety. - -We are doing one of the more annoying things to do with Rust: self-referential graph structures. VNodes reference a bump arena which is contained by scope. Conveniently, the bump arenas also belong to scope, and now we have a self-referential struct. - -We */would/* use a solution like ourborous or self_referential, but these libraries generate "imaginary code" that doesn't integrate with RA. It's simpler and easier to review if we set some rules on what is/isn't allowed. - -Here's the two main sources of unsafety: -- 1) vnodes, bump arenas, and scope -- 2) context_api and use_context - -For 1), we can fairly confidently guarantee safety by being careful about lifetime casts and by using tools like refcell as flags. - -For 2), use_context authors (mostly state management) can implement either the Unsafe API or the Safe API. The Safe API is less performant, but will likely do everything you need. The Unsafe API is more performant, but will bite you if you don't implement it properly. Always validate with MIRI! - -Because of 2), we provide two state management solutions (D-Reducer and D-Dataflow) that use the Unsafe API, but will still be 100% safe. - diff --git a/notes/SUSPENSE.md b/notes/SUSPENSE.md deleted file mode 100644 index a3cb442cb..000000000 --- a/notes/SUSPENSE.md +++ /dev/null @@ -1,28 +0,0 @@ -# Suspense, Async, and More - -This doc goes into the design of asynchronicity in Dioxus. - - -## for UI elements - -`suspend`-ing a future submits an &mut future to Dioxus. the future must return VNodes. the future is still waiting before the component renders, the `.await` is dropped and tried again. users will want to attach their future to a hook so the future doesn't really get dropped. - - -## for tasks - -for more general tasks, we need some way of submitting a future or task into some sort of task system. - - -`use_task()` submits a future to Dioxus. the future is polled infinitely until it finishes. The caller of `use_task` may drop, pause, restart, or insert a new the task - -```rust - -let task = use_hook(|| { /* */ }); -cx.poll_future() -// let recoil_event_loop = cx.use_task(move |_| async move { -// loop { -// let msg = receiver.await?; -// } -// }); -// where suspend wraps use_task -``` diff --git a/notes/TODO.md b/notes/TODO.md deleted file mode 100644 index ce61996ec..000000000 --- a/notes/TODO.md +++ /dev/null @@ -1,29 +0,0 @@ -- [x] Move the builder API onto NodeFactory -- [x] Transition away from names and towards compile-time safe tags -- [x] Fix diffing of fragments -- [x] Properly integrate memoization to prevent safety issues with children -- [x] Understand and fix the issue with callbacks (outdated generations) -- [x] Fix examples for core, web, ssr, and general -- [] Finish up documentation -- [] Polish the Recoil (Dirac?) API -- [x] Find better names for things -- [] get the html macro up to parity with the rsx! macro -- [x] put warnings in for iterating w/o keys -- [] finish up the crate for generating code blocks -- [] make progress on the docusarus-style crate for generating the websites -- [] build the docsite -- [] find a way to serialize the virtualdom completely -- [] ...some how deserialize (hydrate) the dom state? -- [] Implement controlled inputs for select and textarea -- [] ...somehow... noderefs.... - -- [x] soup of the use_state hook -- [ ] wire up inline css -- [ ] compile-time correct inline CSS -- [ ] signals -- [ ] cooperative scheduler -- [ ] suspense -- [ ] task system -- [] wire up events for webview -- [] JIT for class-based style engines -- [] diff --git a/notes/log.md b/notes/log.md deleted file mode 100644 index e3f4e18ea..000000000 --- a/notes/log.md +++ /dev/null @@ -1,70 +0,0 @@ -# March 3, 2021 - -Still TODO: -- Wire up Nodebuilder to track listeners as they are added. (easyish) -- Wire up attrs on nodes to track listeners properly - - Could be done in the nodebuilder where the attrs are added automatically (easyish) - - Could just inject context into the diffing algorithm (hardish) -- Wire up component syntax (easy) -- Wire up component calling approach (easyish) -- Wire up component diffing (hardish) - - -Approach: -- move listeners out of vnode diffing -- move listeners onto scope via nodebuilder -- instead of a listeners list, store a list of listeners and their IDs - - this way means the diffing algorithm doesn't need to know that context -- This should fix our listener approach -- The only thing from here is child component - - -Thoughts: -- the macros should generate a static set of attrs into a [attr] array (faster, more predictable, no allocs) -- children should be generated as a static set if no parans are detected - - More complex in the macro sized, unfortunately, not *too* hard -- Listeners should also be a static set (dynamic listeners don't make too much sense) - - use the builder syntax if you're doing something wild and need this granular control -- Tags should also be &'static str - no reason to generate them on the fly - -Major milestones going forward: -- Scheduled updates -- String renderer (and methods for accessing vdom directly as a tree of nodes) - - good existing work on this in some places -- Suspense -- Child support, nested diffing -- State management -- Tests tests tests - -Done so far: -- websys -- webview -- rsx! macro -- html! macro -- lifecycles -- scopes -- hooks -- context API -- bump - - -## Solutions from today's thinking session... - -### To solve children: - -- maintain a map of `ScopeIdx` to `Node` in the renderer -- Add new patch commands - - traverse_to_known (idx) - - Pop known component onto stack (super easy) - - add_known (idx) - - Save top of stack as root associated with idx - - remove_known (idx) - - Remove node on top of stack from known roots - - ... Something like this -- Continue with BFS exploration of child components, DFS of VNodes - - Easier to write, easier to reason about - -### To solve listeners: - -- Map listeners directly as attrs before diffing via a listenerhandle -- Evaluation of nodes is now stateful where we track listeners as they are added diff --git a/packages/autofmt/Cargo.toml b/packages/autofmt/Cargo.toml index 5933bfdcb..fae35afd0 100644 --- a/packages/autofmt/Cargo.toml +++ b/packages/autofmt/Cargo.toml @@ -6,10 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +dioxus-rsx = { path = "../rsx" } proc-macro2 = { version = "1.0.6", features = ["span-locations"] } quote = "1.0" syn = { version = "1.0.11", features = ["full", "extra-traits"] } -dioxus-rsx = { path = "../rsx" } triple_accel = "0.4.0" serde = { version = "1.0.136", features = ["derive"] } prettyplease = { git = "https://github.com/DioxusLabs/prettyplease-macro-fmt.git", features = [ diff --git a/packages/autofmt/src/buffer.rs b/packages/autofmt/src/buffer.rs index 46f564dee..e7f82cd01 100644 --- a/packages/autofmt/src/buffer.rs +++ b/packages/autofmt/src/buffer.rs @@ -143,8 +143,8 @@ impl Buffer { let mut total = 0; for attr in attributes { - if self.current_span_is_primary(attr.attr.start()) { - 'line: for line in self.src[..attr.attr.start().start().line - 1].iter().rev() { + if self.current_span_is_primary(attr.attr.flart()) { + 'line: for line in self.src[..attr.attr.flart().start().line - 1].iter().rev() { match (line.trim().starts_with("//"), line.is_empty()) { (true, _) => return 100000, (_, true) => continue 'line, diff --git a/packages/autofmt/src/element.rs b/packages/autofmt/src/element.rs index b4ea342a9..697464300 100644 --- a/packages/autofmt/src/element.rs +++ b/packages/autofmt/src/element.rs @@ -153,7 +153,7 @@ impl Buffer { while let Some(attr) = attr_iter.next() { self.indent += 1; if !sameline { - self.write_comments(attr.attr.start())?; + self.write_comments(attr.attr.flart())?; } self.indent -= 1; diff --git a/packages/core-macro/src/lib.rs b/packages/core-macro/src/lib.rs index 35298703c..4247c17d9 100644 --- a/packages/core-macro/src/lib.rs +++ b/packages/core-macro/src/lib.rs @@ -29,7 +29,7 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token /// The rsx! macro makes it easy for developers to write jsx-style markup in their components. /// /// ## Complete Reference Guide: -/// ``` +/// ```ignore #[doc = include_str!("../../../examples/rsx_usage.rs")] /// ``` #[proc_macro] @@ -81,7 +81,7 @@ pub fn rsx(s: TokenStream) -> TokenStream { /// you would be repeating a lot of the usual Rust boilerplate. /// /// # Example -/// ``` +/// ```ignore /// #[inline_props] /// fn app(cx: Scope, bob: String) -> Element { /// cx.render(rsx!("hello, {bob}")) diff --git a/packages/core/src/lib.rs b/packages/core/src/lib.rs index 8b6c0477b..4e497d690 100644 --- a/packages/core/src/lib.rs +++ b/packages/core/src/lib.rs @@ -101,7 +101,7 @@ pub(crate) mod unsafe_utils { /// # Usage /// /// -/// ``` +/// ```ignore /// let (data) = use_ref(&cx, || {}); /// /// let handle_thing = move |_| { diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index d6d436a09..67a201f9f 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -24,7 +24,7 @@ pub fn use_window(cx: &ScopeState) -> &DesktopContext { /// /// you can use `cx.consume_context::` to get this context /// -/// ```rust +/// ```rust, ignore /// let desktop = cx.consume_context::().unwrap(); /// ``` #[derive(Clone)] @@ -43,7 +43,7 @@ impl DesktopContext { /// Moves the window with the left mouse button until the button is released. /// /// you need use it in `onmousedown` event: - /// ```rust + /// ```rust, ignore /// onmousedown: move |_| { desktop.drag_window(); } /// ``` pub fn drag(&self) { diff --git a/packages/desktop/src/escape.rs b/packages/desktop/src/escape.rs index 386a82b44..8ee564720 100644 --- a/packages/desktop/src/escape.rs +++ b/packages/desktop/src/escape.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Write}; /// /// # Example /// -/// ```rust,no_run +/// ```rust,ignore /// # use web_view::WebView; /// # use std::mem; /// # diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index f1c7fbab5..89c761b23 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -33,11 +33,11 @@ use wry::webview::WebViewBuilder; /// /// This function will start a multithreaded Tokio runtime as well the WebView event loop. /// -/// ```rust +/// ```rust, ignore /// use dioxus::prelude::*; /// /// fn main() { -/// dioxus::desktop::launch(app); +/// dioxus_desktop::launch(app); /// } /// /// fn app(cx: Scope) -> Element { @@ -56,11 +56,11 @@ pub fn launch(root: Component) { /// /// You can configure the WebView window with a configuration closure /// -/// ```rust +/// ```rust, ignore /// use dioxus::prelude::*; /// /// fn main() { -/// dioxus::desktop::launch_cfg(app, |c| c.with_window(|w| w.with_title("My App"))); +/// dioxus_desktop::launch_cfg(app, |c| c.with_window(|w| w.with_title("My App"))); /// } /// /// fn app(cx: Scope) -> Element { @@ -82,11 +82,11 @@ pub fn launch_cfg( /// /// You can configure the WebView window with a configuration closure /// -/// ```rust +/// ```rust, ignore /// use dioxus::prelude::*; /// /// fn main() { -/// dioxus::desktop::launch_cfg(app, AppProps { name: "asd" }, |c| c); +/// dioxus_desktop::launch_cfg(app, AppProps { name: "asd" }, |c| c); /// } /// /// struct AppProps { diff --git a/packages/desktop/src/readme.md b/packages/desktop/src/readme.md index db5d340fb..3ac0d66df 100644 --- a/packages/desktop/src/readme.md +++ b/packages/desktop/src/readme.md @@ -26,12 +26,12 @@ $ cargo add dioxus --features desktop Edit your `main.rs`: -```rust +```rust, ignore // main.rs use dioxus::prelude::*; fn main() { - dioxus::desktop::launch(app); + dioxus_desktop::launch(app); } fn app(cx: Scope) -> Element { diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml new file mode 100644 index 000000000..9a376140e --- /dev/null +++ b/packages/dioxus/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "dioxus" +version = "0.2.4" +authors = ["Jonathan Kelley"] +edition = "2021" +description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences" +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 = { path = "../core", version = "^0.2.1" } +dioxus-html = { path = "../html", version = "^0.2.1", optional = true } +dioxus-core-macro = { path = "../core-macro", version = "^0.2.1", optional = true } +dioxus-hooks = { path = "../hooks", version = "^0.2.1", optional = true } +dioxus-rsx = { path = "../rsx", optional = true } +dioxus-rsx-interpreter = { path = "../rsx_interpreter", optional = true } + + +# dioxus-interpreter-js = { path = "./packages/interpreter", version = "^0.2.1", optional = true } +# dioxus-native-core = { path = "./packages/native-core", version = "^0.2.0", optional = true } +# dioxus-native-core-macro = { path = "./packages/native-core-macro", version = "^0.2.0", optional = true } + +[features] +default = ["macro", "hooks", "html"] +macro = ["dioxus-core-macro", "dioxus-rsx"] +html = ["dioxus-html"] +hooks = ["dioxus-hooks"] +hot-reload = [ + "dioxus-core-macro/hot-reload", + "dioxus-rsx-interpreter", +] + +[dev-dependencies] +futures-util = "0.3.21" +log = "0.4.14" +rand = { version = "0.8.4", features = ["small_rng"] } +criterion = "0.3.5" +thiserror = "1.0.30" +env_logger = "0.9.0" + +[[bench]] +name = "create" +harness = false + +[[bench]] +name = "jsframework" +harness = false diff --git a/benches/create.rs b/packages/dioxus/benches/create.rs similarity index 100% rename from benches/create.rs rename to packages/dioxus/benches/create.rs diff --git a/benches/jsframework.rs b/packages/dioxus/benches/jsframework.rs similarity index 100% rename from benches/jsframework.rs rename to packages/dioxus/benches/jsframework.rs diff --git a/packages/rsx-prelude/src/lib.rs b/packages/dioxus/src/lib.rs similarity index 57% rename from packages/rsx-prelude/src/lib.rs rename to packages/dioxus/src/lib.rs index 9198dc28e..43462ab52 100644 --- a/packages/rsx-prelude/src/lib.rs +++ b/packages/dioxus/src/lib.rs @@ -1,27 +1,39 @@ -//! This package is meant for internal use within dioxus. It provides a prelude that enables basic components to work. +#![doc = include_str!("../../../notes/README.md")] pub use dioxus_core as core; -pub mod hooks { - pub use dioxus_hooks::*; -} - -pub use hooks::*; +#[cfg(feature = "hooks")] +pub use dioxus_hooks as hooks; pub mod events { + #[cfg(feature = "html")] pub use dioxus_html::{on::*, KeyCode}; } -#[cfg(feature = "hot-reload")] -pub use dioxus_rsx_interpreter as rsx_interpreter; +#[cfg(feature = "html")] +pub use dioxus_html as html; + +#[cfg(feature = "macro")] +pub use dioxus_rsx as rsx; + +#[cfg(feature = "macro")] +pub use dioxus_core_macro as core_macro; pub mod prelude { + #[cfg(feature = "hooks")] pub use crate::hooks::*; + pub use dioxus_core::prelude::*; + + #[cfg(feature = "macro")] pub use dioxus_core_macro::{format_args_f, inline_props, rsx, Props}; - pub use dioxus_elements::{GlobalAttributes, SvgAttributes}; + + #[cfg(feature = "html")] pub use dioxus_html as dioxus_elements; + #[cfg(feature = "html")] + pub use dioxus_elements::{GlobalAttributes, SvgAttributes}; + #[cfg(feature = "hot-reload")] pub use dioxus_rsx_interpreter::{ captuered_context::{CapturedContext, FormattedArg, IfmtArgs}, diff --git a/tests/.rustfmt.toml b/packages/dioxus/tests/.rustfmt.toml similarity index 100% rename from tests/.rustfmt.toml rename to packages/dioxus/tests/.rustfmt.toml diff --git a/tests/README.md b/packages/dioxus/tests/README.md similarity index 100% rename from tests/README.md rename to packages/dioxus/tests/README.md diff --git a/tests/borrowedstate.rs b/packages/dioxus/tests/borrowedstate.rs similarity index 100% rename from tests/borrowedstate.rs rename to packages/dioxus/tests/borrowedstate.rs diff --git a/tests/create_dom.rs b/packages/dioxus/tests/create_dom.rs similarity index 98% rename from tests/create_dom.rs rename to packages/dioxus/tests/create_dom.rs index f8b162e2b..33959e6a5 100644 --- a/tests/create_dom.rs +++ b/packages/dioxus/tests/create_dom.rs @@ -7,12 +7,9 @@ use dioxus::prelude::*; -mod test_logging; use dioxus_core::DomEdit::*; fn new_dom(app: Component

, props: P) -> VirtualDom { - const IS_LOGGING_ENABLED: bool = false; - test_logging::set_up_logging(IS_LOGGING_ENABLED); VirtualDom::new_with_props(app, props) } diff --git a/tests/diffing.rs b/packages/dioxus/tests/diffing.rs similarity index 98% rename from tests/diffing.rs rename to packages/dioxus/tests/diffing.rs index 3cc010673..21a9d4f38 100644 --- a/tests/diffing.rs +++ b/packages/dioxus/tests/diffing.rs @@ -8,11 +8,7 @@ use dioxus::prelude::*; -mod test_logging; - fn new_dom() -> VirtualDom { - const IS_LOGGING_ENABLED: bool = false; - test_logging::set_up_logging(IS_LOGGING_ENABLED); VirtualDom::new(|cx| rsx!(cx, "hi")) } @@ -224,7 +220,7 @@ fn two_fragments_with_differrent_elements_are_differet() { ); let (_create, changes) = dom.diff_lazynodes(left, right); - log::trace!("{:#?}", &changes); + println!("{:#?}", &changes); assert_eq!( changes.edits, [ @@ -360,7 +356,7 @@ fn keyed_diffing_out_of_order() { }); let (_, changes) = dom.diff_lazynodes(left, right); - log::trace!("{:?}", &changes); + println!("{:?}", &changes); assert_eq!( changes.edits, [PushRoot { root: 7 }, InsertBefore { root: 5, n: 1 }] @@ -546,7 +542,7 @@ fn keyed_diffing_additions_and_moves_on_ends() { }); let (_, change) = dom.diff_lazynodes(left, right); - log::trace!("{:?}", change); + println!("{:?}", change); assert_eq!( change.edits, [ @@ -579,7 +575,7 @@ fn keyed_diffing_additions_and_moves_in_middle() { // LIS: 4, 5, 6 let (_, change) = dom.diff_lazynodes(left, right); - log::trace!("{:#?}", change); + println!("{:#?}", change); assert_eq!( change.edits, [ @@ -616,7 +612,7 @@ fn controlled_keyed_diffing_out_of_order() { // LIS: 5, 6 let (_, changes) = dom.diff_lazynodes(left, right); - log::trace!("{:#?}", &changes); + println!("{:#?}", &changes); assert_eq!( changes.edits, [ @@ -653,7 +649,7 @@ fn controlled_keyed_diffing_out_of_order_max_test() { }); let (_, changes) = dom.diff_lazynodes(left, right); - log::trace!("{:#?}", &changes); + println!("{:#?}", &changes); assert_eq!( changes.edits, [ diff --git a/tests/earlyabort.rs b/packages/dioxus/tests/earlyabort.rs similarity index 95% rename from tests/earlyabort.rs rename to packages/dioxus/tests/earlyabort.rs index e0a698bb8..3de5e2f9c 100644 --- a/tests/earlyabort.rs +++ b/packages/dioxus/tests/earlyabort.rs @@ -7,13 +7,11 @@ use dioxus::prelude::*; -mod test_logging; use dioxus_core::{DomEdit::*, ScopeId}; const IS_LOGGING_ENABLED: bool = false; fn new_dom(app: Component

, props: P) -> VirtualDom { - test_logging::set_up_logging(IS_LOGGING_ENABLED); VirtualDom::new_with_props(app, props) } diff --git a/tests/lifecycle.rs b/packages/dioxus/tests/lifecycle.rs similarity index 97% rename from tests/lifecycle.rs rename to packages/dioxus/tests/lifecycle.rs index 6961f3f02..6f85954ea 100644 --- a/tests/lifecycle.rs +++ b/packages/dioxus/tests/lifecycle.rs @@ -6,9 +6,6 @@ use dioxus::prelude::*; use dioxus_core::DomEdit::*; use std::sync::{Arc, Mutex}; -mod test_logging; - -const IS_LOGGING_ENABLED: bool = true; type Shared = Arc>; #[test] @@ -31,7 +28,7 @@ fn manual_diffing() { let edits = dom.rebuild(); - log::trace!("edits: {:?}", edits); + println!("edits: {:?}", edits); } #[test] @@ -97,7 +94,7 @@ fn components_generate() { }; fn Child(cx: Scope) -> Element { - log::trace!("Running child"); + println!("Running child"); cx.render(rsx! { h1 {} }) diff --git a/tests/miri_stress.rs b/packages/dioxus/tests/miri_stress.rs similarity index 98% rename from tests/miri_stress.rs rename to packages/dioxus/tests/miri_stress.rs index d6eaa6598..329e62f9b 100644 --- a/tests/miri_stress.rs +++ b/packages/dioxus/tests/miri_stress.rs @@ -13,12 +13,7 @@ Specifically: use dioxus::prelude::*; use dioxus_core::SchedulerMsg; -mod test_logging; - -const IS_LOGGING_ENABLED: bool = false; - fn new_dom(app: Component

, props: P) -> VirtualDom { - test_logging::set_up_logging(IS_LOGGING_ENABLED); VirtualDom::new_with_props(app, props) } diff --git a/tests/passthru.rs b/packages/dioxus/tests/passthru.rs similarity index 95% rename from tests/passthru.rs rename to packages/dioxus/tests/passthru.rs index ffe4648e2..730a6b93e 100644 --- a/tests/passthru.rs +++ b/packages/dioxus/tests/passthru.rs @@ -9,11 +9,7 @@ use dioxus::prelude::*; -mod test_logging; - fn new_dom() -> VirtualDom { - const IS_LOGGING_ENABLED: bool = false; - test_logging::set_up_logging(IS_LOGGING_ENABLED); VirtualDom::new(|cx| rsx!(cx, "hi")) } diff --git a/tests/scheduler.rs b/packages/dioxus/tests/scheduler.rs similarity index 100% rename from tests/scheduler.rs rename to packages/dioxus/tests/scheduler.rs diff --git a/tests/sharedstate.rs b/packages/dioxus/tests/sharedstate.rs similarity index 99% rename from tests/sharedstate.rs rename to packages/dioxus/tests/sharedstate.rs index e07baaaed..f3b6fabf3 100644 --- a/tests/sharedstate.rs +++ b/packages/dioxus/tests/sharedstate.rs @@ -5,8 +5,6 @@ use dioxus_core::{DomEdit, Mutations, SchedulerMsg, ScopeId}; use std::rc::Rc; use DomEdit::*; -mod test_logging; - #[test] fn shared_state_test() { struct MySharedState(&'static str); diff --git a/tests/task.rs b/packages/dioxus/tests/task.rs similarity index 100% rename from tests/task.rs rename to packages/dioxus/tests/task.rs diff --git a/tests/vdom_rebuild.rs b/packages/dioxus/tests/vdom_rebuild.rs similarity index 100% rename from tests/vdom_rebuild.rs rename to packages/dioxus/tests/vdom_rebuild.rs diff --git a/packages/fermi/README.md b/packages/fermi/README.md index ae89ea73c..f751adb2e 100644 --- a/packages/fermi/README.md +++ b/packages/fermi/README.md @@ -36,14 +36,14 @@ Fermi is a global state management solution for Dioxus that's as easy as `use_st Inspired by atom-based state management solutions, all state in Fermi starts as an `atom`: -```rust +```rust, ignore static NAME: Atom<&str> = |_| "Dioxus"; ``` From anywhere in our app, we can read our the value of our atom: -```rust -fn NameCard(cx: Scope) -> Element { +```rust, ignore +fn NameCard(cx: Scope) -> Element { let name = use_read(&cx, NAME); cx.render(rsx!{ h1 { "Hello, {name}"} }) } @@ -51,8 +51,8 @@ fn NameCard(cx: Scope) -> Element { We can also set the value of our atom, also from anywhere in our app: -```rust -fn NameCard(cx: Scope) -> Element { +```rust, ignore +fn NameCard(cx: Scope) -> Element { let set_name = use_set(&cx, NAME); cx.render(rsx!{ button { @@ -68,7 +68,7 @@ It's that simple! ## Installation Fermi is currently under construction, so you have to use the `master` branch to get started. -```rust +```toml [dependencies] fermi = { git = "https://github.com/dioxuslabs/fermi" } ``` @@ -89,4 +89,4 @@ Broadly our feature set to required to be released includes: - [ ] Support for Atom Families - [ ] Support for memoized Selectors - [ ] Support for memoized SelectorFamilies -- [ ] Support for UseFermiCallback for access to fermi from async +- [ ] Support for UseFermiCallback for access to fermi from async diff --git a/packages/fermi/src/hooks/state.rs b/packages/fermi/src/hooks/state.rs index b698bb3c3..41e4e8ab0 100644 --- a/packages/fermi/src/hooks/state.rs +++ b/packages/fermi/src/hooks/state.rs @@ -124,7 +124,7 @@ impl AtomState { /// # Examples /// /// Basic usage: - /// ```rust + /// ```rust, ignore /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { @@ -219,7 +219,7 @@ impl AtomState { /// /// # Examples /// - /// ``` + /// ```ignore /// let val = use_state(&cx, || 0); /// /// val.with_mut(|v| *v = 1); @@ -242,7 +242,7 @@ impl AtomState { /// /// # Examples /// - /// ``` + /// ```ignore /// let val = use_state(&cx, || 0); /// /// *val.make_mut() += 1; diff --git a/packages/hooks/src/usecoroutine.rs b/packages/hooks/src/usecoroutine.rs index 55161f149..65a3ff52d 100644 --- a/packages/hooks/src/usecoroutine.rs +++ b/packages/hooks/src/usecoroutine.rs @@ -36,7 +36,7 @@ use std::future::Future; /// /// ## Example /// -/// ```rust +/// ```rust, ignore /// enum Action { /// Start, /// Stop, diff --git a/packages/hooks/src/useref.rs b/packages/hooks/src/useref.rs index 73ef99a59..476ef7d62 100644 --- a/packages/hooks/src/useref.rs +++ b/packages/hooks/src/useref.rs @@ -16,7 +16,7 @@ use std::{ /// writes through the `write` method. Whenever `write` is called, the component /// that initialized the hook will be marked as "dirty". /// -/// ```rust +/// ```rust, ignore /// let val = use_ref(|| HashMap::::new()); /// /// // using `write` will give us a `RefMut` to the inner value, which we can call methods on @@ -26,7 +26,7 @@ use std::{ /// /// You can avoid this default behavior with `write_silent` /// -/// ``` +/// ```ignore /// // with `write_silent`, the component will not be re-rendered /// val.write_silent().insert(2, "goodbye".to_string()); /// ``` @@ -35,7 +35,7 @@ use std::{ /// /// To read values out of the refcell, you can use the `read` method which will retrun a `Ref`. /// -/// ```rust +/// ```rust, ignore /// let map: Ref<_> = val.read(); /// /// let item = map.get(&1); @@ -43,7 +43,7 @@ use std::{ /// /// To get an &T out of the RefCell, you need to "reborrow" through the Ref: /// -/// ```rust +/// ```rust, ignore /// let read = val.read(); /// let map = &*read; /// ``` @@ -54,7 +54,7 @@ use std::{ /// Typically this will be a collection like a HashMap or a Vec. To create new /// elements from the collection, we can use `read()` directly in our rsx!. /// -/// ```rust +/// ```rust, ignore /// rsx!{ /// val.read().iter().map(|(k, v)| { /// rsx!{ key: "{k}", value: "{v}" } @@ -66,7 +66,7 @@ use std::{ /// "render" inside the iterator. For some cases you might need to collect into /// a temporary Vec. /// -/// ```rust +/// ```rust, ignore /// let items = val.read().iter().map(|(k, v)| { /// cx.render(rsx!{ key: "{k}", value: "{v}" }) /// }); @@ -82,7 +82,7 @@ use std::{ /// from the current scope's lifetime, making it a `'static` value. This is done /// by simply calling `ToOnwed` or `Clone`. /// -/// ```rust +/// ```rust, ignore /// let val = use_ref(|| HashMap::::new()); /// /// cx.spawn({ @@ -97,7 +97,7 @@ use std::{ /// If you're working with lots of values like UseState and UseRef, you can use the /// `clone!` macro to make it easier to write the above code. /// -/// ```rust +/// ```rust, ignore /// let val1 = use_ref(|| HashMap::::new()); /// let val2 = use_ref(|| HashMap::::new()); /// let val3 = use_ref(|| HashMap::::new()); @@ -194,7 +194,7 @@ impl UseRef { /// Note: You can always "reborrow" the value through the RefCell. /// This method just does it for you automatically. /// - /// ```rust + /// ```rust, ignore /// let val = use_ref(|| HashMap::::new()); /// /// @@ -214,7 +214,7 @@ impl UseRef { /// Note: You can always "reborrow" the value through the RefCell. /// This method just does it for you automatically. /// - /// ```rust + /// ```rust, ignore /// let val = use_ref(|| HashMap::::new()); /// /// diff --git a/packages/hooks/src/usestate.rs b/packages/hooks/src/usestate.rs index 68440ca52..b2b4e80af 100644 --- a/packages/hooks/src/usestate.rs +++ b/packages/hooks/src/usestate.rs @@ -140,7 +140,7 @@ impl UseState { /// # Examples /// /// Basic usage: - /// ```rust + /// ```rust, ignore /// # use dioxus_core::prelude::*; /// # use dioxus_hooks::*; /// fn component(cx: Scope) -> Element { @@ -236,7 +236,7 @@ impl UseState { /// /// # Examples /// - /// ``` + /// ```rust, ignore /// let val = use_state(&cx, || 0); /// /// val.with_mut(|v| *v = 1); @@ -268,7 +268,7 @@ impl UseState { /// /// # Examples /// - /// ``` + /// ```rust, ignore /// let val = use_state(&cx, || 0); /// /// *val.make_mut() += 1; diff --git a/packages/html/src/elements.rs b/packages/html/src/elements.rs index ad4f66b7b..fae0b7349 100644 --- a/packages/html/src/elements.rs +++ b/packages/html/src/elements.rs @@ -181,7 +181,7 @@ builder_constructors! { /// /// # Usage /// - /// ``` + /// ```rust, ignore /// html!(

A header element

) /// rsx!(h1 { "A header element" }) /// LazyNodes::new(|f| f.el(h1).children([f.text("A header element")]).finish()) @@ -201,7 +201,7 @@ builder_constructors! { /// - The `

` heading is usually a large bolded font. /// /// # Usage - /// ``` + /// ```rust, ignore /// html!(

A header element

) /// rsx!(h2 { "A header element" }) /// LazyNodes::new(|f| f.el(h2).children([f.text("A header element")]).finish()) @@ -274,7 +274,7 @@ builder_constructors! { /// Note: By default, browsers always place a line break before and after the
element. /// /// ## Usage - /// ``` + /// ```rust, ignore /// html!(
A header element
) /// rsx!(div { "A header element" }) /// LazyNodes::new(|f| f.element(div, &[], &[], &[], None)) diff --git a/packages/html/src/events.rs b/packages/html/src/events.rs index 430740f5b..59fd56102 100644 --- a/packages/html/src/events.rs +++ b/packages/html/src/events.rs @@ -193,7 +193,7 @@ pub mod on { /// `click` fires after both the `mousedown` and `mouseup` events have fired, in that order. /// /// ## Example - /// ``` + /// ```rust, ignore /// rsx!( button { "click me", onclick: move |_| log::info!("Clicked!`") } ) /// ``` /// diff --git a/packages/liveview/Cargo.toml b/packages/liveview/Cargo.toml index 6439b7e8a..3e460a7db 100644 --- a/packages/liveview/Cargo.toml +++ b/packages/liveview/Cargo.toml @@ -39,7 +39,7 @@ tower = { version = "0.4.12", optional = true } [dev-dependencies] tokio = { version = "1", features = ["full"] } -dioxus = { path = "../../" } +dioxus = { path = "../dioxus" } warp = "0.3" axum = { version = "0.5.1", features = ["ws"] } tower = "0.4.12" diff --git a/packages/liveview/examples/axum.rs b/packages/liveview/examples/axum.rs index 93bf9cae1..450af30ef 100644 --- a/packages/liveview/examples/axum.rs +++ b/packages/liveview/examples/axum.rs @@ -1,12 +1,17 @@ -#![cfg(feature = "axum")] - -use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router}; -use dioxus_core::{Element, LazyNodes, Scope}; +#[cfg(not(feature = "axum"))] +fn main() {} +#[cfg(feature = "axum")] #[tokio::main] async fn main() { + use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router}; + use dioxus_core::{Element, LazyNodes, Scope}; pretty_env_logger::init(); + fn app(cx: Scope) -> Element { + cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!")))) + } + let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into(); let view = dioxus_liveview::new(addr); @@ -27,7 +32,3 @@ async fn main() { .await .unwrap(); } - -fn app(cx: Scope) -> Element { - cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!")))) -} diff --git a/packages/liveview/examples/warp.rs b/packages/liveview/examples/warp.rs index 73c220881..7b2ddfef5 100644 --- a/packages/liveview/examples/warp.rs +++ b/packages/liveview/examples/warp.rs @@ -1,12 +1,18 @@ -#![cfg(feature = "warp")] - -use dioxus_core::{Element, LazyNodes, Scope}; -use dioxus_liveview as liveview; -use warp::ws::Ws; -use warp::Filter; +#[cfg(not(feature = "warp"))] +fn main() {} +#[cfg(feature = "warp")] #[tokio::main] async fn main() { + use dioxus_core::{Element, LazyNodes, Scope}; + use dioxus_liveview as liveview; + use warp::ws::Ws; + use warp::Filter; + + fn app(cx: Scope) -> Element { + cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!")))) + } + pretty_env_logger::init(); let addr = ([127, 0, 0, 1], 3030); @@ -27,7 +33,3 @@ async fn main() { })); warp::serve(routes).run(addr).await; } - -fn app(cx: Scope) -> Element { - cx.render(LazyNodes::new(|f| f.text(format_args!("hello world!")))) -} diff --git a/packages/mobile/README.md b/packages/mobile/README.md index aa3470761..87c6e12a1 100644 --- a/packages/mobile/README.md +++ b/packages/mobile/README.md @@ -59,7 +59,7 @@ Edit your `lib.rs`: use dioxus::prelude::*; fn main() { - dioxus::mobile::launch(app); + dioxus_mobile::launch(app); } fn app(cx: Scope) -> Element { diff --git a/packages/native-core-macro/Cargo.toml b/packages/native-core-macro/Cargo.toml index 4df7c3ca8..f847b84be 100644 --- a/packages/native-core-macro/Cargo.toml +++ b/packages/native-core-macro/Cargo.toml @@ -20,7 +20,7 @@ quote = "1.0" dioxus-native-core = { path = "../native-core", version = "^0.2.0" } [dev-dependencies] -dioxus = { path = "../rsx-prelude", version = "^0.1.0", package = "rsx-prelude" } +dioxus = { path = "../dioxus" } smallvec = "1.6" fxhash = "0.2" diff --git a/packages/native-core/src/state.rs b/packages/native-core/src/state.rs index 1cb4f5e14..bd67ee767 100644 --- a/packages/native-core/src/state.rs +++ b/packages/native-core/src/state.rs @@ -83,7 +83,7 @@ pub trait ParentDepState { /// Called when the current node's node properties are modified or a sibling's [NodeDepState] is modified. /// Called at most once per update. /// NodeDepState is the only state that can accept multiple dependancies, but only from the current node. -/// ```rust +/// ```rust, ignore /// impl<'a, 'b> NodeDepState<(&'a TextWrap, &'b ChildLayout)> for Layout { /// type Ctx = LayoutCache; /// const NODE_MASK: NodeMask = diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml index f5c038d22..bd05b0661 100644 --- a/packages/router/Cargo.toml +++ b/packages/router/Cargo.toml @@ -11,7 +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 = { path = "../rsx-prelude", version = "^0.1.0", package = "rsx-prelude" } +dioxus = { path = "../dioxus" } futures-channel = "0.3.21" url = { version = "2.2.2", default-features = false } @@ -26,7 +26,7 @@ web-sys = { version = "0.3", features = [ "Url", "UrlSearchParams", "Window", - "Location" + "Location", ], optional = true } wasm-bindgen = { version = "0.2", optional = true } js-sys = { version = "0.3", optional = true } @@ -46,14 +46,11 @@ hot-reload = ["dioxus/hot-reload"] [dev-dependencies] console_error_panic_hook = "0.1.7" -dioxus-web = { path = "../web" } log = "0.4.14" wasm-logger = "0.2.0" wasm-bindgen-test = "0.3" gloo-utils = "0.1.2" -dioxus-ssr = { path = "../ssr" } - -dioxus-router = { path = ".", default-features = false } +dioxus-web = { path = "../web" } [target.wasm32-unknown-unknown.dev-dependencies] dioxus-router = { path = ".", features = ["web"] } diff --git a/packages/router/examples/simple.rs b/packages/router/examples/simple.rs index e909204de..84b4f6d97 100644 --- a/packages/router/examples/simple.rs +++ b/packages/router/examples/simple.rs @@ -4,8 +4,6 @@ use dioxus::prelude::*; use dioxus_router::*; fn main() { - console_error_panic_hook::set_once(); - wasm_logger::init(wasm_logger::Config::new(log::Level::Debug)); dioxus_web::launch(app); } diff --git a/packages/router/src/components/link.rs b/packages/router/src/components/link.rs index 732ed8470..e742a97d1 100644 --- a/packages/router/src/components/link.rs +++ b/packages/router/src/components/link.rs @@ -120,15 +120,15 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element { id: format_args!("{}", id.unwrap_or("")), title: format_args!("{}", title.unwrap_or("")), prevent_default: "{prevent_default}", - target: format_args!("{}", if *new_tab { "_blank" } else { "" }), + target: format_args!("{}", if * new_tab { "_blank" } else { "" }), onclick: move |_| { if !outerlink { if let Some(service) = svc { service.push_route(to, cx.props.title.map(|f| f.to_string()), None); } else { log::error!( - "Attempted to create a Link to {} outside of a Router context", - cx.props.to, + "Attempted to create a Link to {} outside of a Router context", cx.props + .to, ); } } diff --git a/packages/router/src/components/router.rs b/packages/router/src/components/router.rs index d29c2ee4d..f4e40e79d 100644 --- a/packages/router/src/components/router.rs +++ b/packages/router/src/components/router.rs @@ -1,7 +1,5 @@ -use crate::ParsedRoute; -use crate::{cfg::RouterCfg, RouteEvent, RouterCore}; +use crate::{cfg::RouterCfg, RouterCore}; use dioxus::prelude::*; -use futures_util::stream::StreamExt; use std::sync::Arc; /// The props for the [`Router`](fn.Router.html) component. @@ -40,81 +38,13 @@ pub struct RouterProps<'a> { #[allow(non_snake_case)] pub fn Router<'a>(cx: Scope<'a, RouterProps<'a>>) -> Element { let svc = cx.use_hook(|_| { - let (tx, mut rx) = futures_channel::mpsc::unbounded::(); - - let svc = RouterCore::new( - tx, + cx.provide_context(RouterCore::new( + &cx, RouterCfg { base_url: cx.props.base_url.map(|s| s.to_string()), active_class: cx.props.active_class.map(|s| s.to_string()), }, - ); - - cx.spawn({ - let svc = svc.clone(); - let regen_route = cx.schedule_update_any(); - let router_id = cx.scope_id(); - - async move { - while let Some(msg) = rx.next().await { - match msg { - RouteEvent::Push { - route, - serialized_state, - title, - } => { - let new_route = Arc::new(ParsedRoute { - url: svc.current_location().url.join(&route).ok().unwrap(), - title, - serialized_state, - }); - - svc.history.push(&new_route); - svc.stack.borrow_mut().push(new_route); - } - - RouteEvent::Replace { - route, - title, - serialized_state, - } => { - let new_route = Arc::new(ParsedRoute { - url: svc.current_location().url.join(&route).ok().unwrap(), - title, - serialized_state, - }); - - svc.history.replace(&new_route); - *svc.stack.borrow_mut().last_mut().unwrap() = new_route; - } - - RouteEvent::Pop => { - let mut stack = svc.stack.borrow_mut(); - - if stack.len() == 1 { - continue; - } - - stack.pop(); - } - } - - svc.route_found.set(None); - - regen_route(router_id); - - for listener in svc.onchange_listeners.borrow().iter() { - regen_route(*listener); - } - - for route in svc.ordering.borrow().iter().rev() { - regen_route(*route); - } - } - } - }); - - cx.provide_context(svc) + )) }); // next time we run the rout_found will be filled diff --git a/packages/router/src/service.rs b/packages/router/src/service.rs index 72f35d51e..dcfa7024e 100644 --- a/packages/router/src/service.rs +++ b/packages/router/src/service.rs @@ -2,9 +2,9 @@ // does each window have its own router? probably, lol use crate::cfg::RouterCfg; -use dioxus::core::ScopeId; -use futures_channel::mpsc::UnboundedSender; +use dioxus::core::{ScopeId, ScopeState, VirtualDom}; use std::any::Any; +use std::sync::Weak; use std::{ cell::{Cell, RefCell}, collections::{HashMap, HashSet}, @@ -45,8 +45,6 @@ pub struct RouterCore { pub(crate) stack: RefCell>>, - pub(crate) tx: UnboundedSender, - pub(crate) slots: Rc>>, pub(crate) ordering: Rc>>, @@ -55,6 +53,10 @@ pub struct RouterCore { pub(crate) history: Box, + pub(crate) regen_any_route: Arc, + + pub(crate) router_id: ScopeId, + pub(crate) cfg: RouterCfg, } @@ -74,41 +76,38 @@ pub struct ParsedRoute { pub serialized_state: Option, } -#[derive(Debug)] -pub(crate) enum RouteEvent { - Push { - route: String, - title: Option, - serialized_state: Option, - }, - Replace { - route: String, - title: Option, - serialized_state: Option, - }, - Pop, -} - impl RouterCore { - pub(crate) fn new(tx: UnboundedSender, cfg: RouterCfg) -> Arc { + pub(crate) fn new(cx: &ScopeState, cfg: RouterCfg) -> Arc { #[cfg(feature = "web")] - let history = Box::new(web::new(tx.clone())); + let history = Box::new(web::new()); #[cfg(not(feature = "web"))] let history = Box::new(hash::new()); let route = Arc::new(history.init_location()); - Arc::new(Self { + let svc = Arc::new(Self { cfg, - tx, + regen_any_route: cx.schedule_update_any(), + router_id: cx.scope_id(), route_found: Cell::new(None), stack: RefCell::new(vec![route]), ordering: Default::default(), slots: Default::default(), onchange_listeners: Default::default(), history, - }) + }); + + svc.history.attach_listeners(Arc::downgrade(&svc)); + + svc + } + + /// Push a new route with no custom title or serialized state. + /// + /// This is a convenience method for easily navigating. + pub fn navigate_to(&self, route: &str) { + self.push_route(route, None, None); } /// Push a new route to the history. @@ -117,16 +116,16 @@ impl RouterCore { /// /// This does not modify the current route pub fn push_route(&self, route: &str, title: Option, serialized_state: Option) { - let _ = self.tx.unbounded_send(RouteEvent::Push { - route: route.to_string(), + let new_route = Arc::new(ParsedRoute { + url: self.current_location().url.join(route).ok().unwrap(), title, serialized_state, }); - } - /// Pop the current route from the history. - pub fn pop_route(&self) { - let _ = self.tx.unbounded_send(RouteEvent::Pop); + self.history.push(&new_route); + self.stack.borrow_mut().push(new_route); + + self.regen_routes(); } /// Instead of pushing a new route, replaces the current route. @@ -136,11 +135,44 @@ impl RouterCore { title: Option, serialized_state: Option, ) { - let _ = self.tx.unbounded_send(RouteEvent::Replace { - route: route.to_string(), + let new_route = Arc::new(ParsedRoute { + url: self.current_location().url.join(route).ok().unwrap(), title, serialized_state, }); + + self.history.replace(&new_route); + *self.stack.borrow_mut().last_mut().unwrap() = new_route; + + self.regen_routes(); + } + + /// Pop the current route from the history. + pub fn pop_route(&self) { + let mut stack = self.stack.borrow_mut(); + + if stack.len() > 1 { + stack.pop(); + } + + self.regen_routes(); + } + + /// Regenerate any routes that need to be regenerated, discarding the currently found route + /// + /// You probably don't need this method + pub fn regen_routes(&self) { + self.route_found.set(None); + + (self.regen_any_route)(self.router_id); + + for listener in self.onchange_listeners.borrow().iter() { + (self.regen_any_route)(*listener); + } + + for route in self.ordering.borrow().iter().rev() { + (self.regen_any_route)(*route); + } } /// Get the current location of the Router @@ -196,6 +228,20 @@ impl RouterCore { } } +/// Get the router service from an existing VirtualDom. +/// +/// Takes an optional target_scope parameter to specify the scope to use if ScopeId is not the component +/// that owns the router. +/// +/// This might change in the future. +pub fn get_router_from_vdom( + dom: &VirtualDom, + target_scope: Option, +) -> Option> { + dom.get_scope(target_scope.unwrap_or(ScopeId(0))) + .and_then(|scope| scope.consume_context::>()) +} + fn clean_route(route: String) -> String { if route.as_str() == "/" { return route; @@ -236,8 +282,6 @@ fn route_matches_path(cur: &Url, attempt: &str, base_url: Option<&String>) -> bo let attempt_pieces = clean_path(attempt).split('/').collect::>(); - log::trace!("Comparing {:?} to {:?}", cur_pieces, attempt_pieces); - if attempt_pieces.len() != cur_pieces.len() { return false; } @@ -262,6 +306,7 @@ pub(crate) trait RouterProvider { fn replace(&self, route: &ParsedRoute); fn native_location(&self) -> Box; fn init_location(&self) -> ParsedRoute; + fn attach_listeners(&self, svc: Weak); } #[cfg(not(feature = "web"))] @@ -291,22 +336,23 @@ mod hash { } fn replace(&self, _route: &ParsedRoute) {} + + fn attach_listeners(&self, _svc: Weak) {} } } #[cfg(feature = "web")] mod web { use super::RouterProvider; - use crate::{ParsedRoute, RouteEvent}; + use crate::ParsedRoute; - use futures_channel::mpsc::UnboundedSender; use gloo_events::EventListener; - use std::any::Any; + use std::{any::Any, cell::Cell}; use web_sys::History; pub struct WebRouter { // keep it around so it drops when the router is dropped - _listener: gloo_events::EventListener, + _listener: Cell>, window: web_sys::Window, history: History, @@ -358,30 +404,25 @@ mod web { serialized_state: None, } } + + fn attach_listeners(&self, svc: std::sync::Weak) { + self._listener.set(Some(EventListener::new( + &web_sys::window().unwrap(), + "popstate", + move |_| { + if let Some(svc) = svc.upgrade() { + svc.pop_route(); + } + }, + ))); + } } - pub(crate) fn new(tx: UnboundedSender) -> WebRouter { + pub(crate) fn new() -> WebRouter { WebRouter { history: web_sys::window().unwrap().history().unwrap(), window: web_sys::window().unwrap(), - _listener: EventListener::new(&web_sys::window().unwrap(), "popstate", move |_| { - let _ = tx.unbounded_send(RouteEvent::Pop); - }), + _listener: Cell::new(None), } } } - -/* - - - - - - -Route { to: "/blog/:id" } -Route { to: "/blog/:id" } -Route { to: "/blog/:id" } -Route { to: "/blog/:id" } -Route { to: "/blog/:id" } - -*/ diff --git a/packages/router/tests/ssr_router.rs b/packages/router/tests/ssr_router.rs deleted file mode 100644 index a362baa68..000000000 --- a/packages/router/tests/ssr_router.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(non_snake_case)] - -use dioxus::prelude::*; -use dioxus_router::*; - -#[test] -fn generates_without_error() { - let mut app = VirtualDom::new(app); - app.rebuild(); - - let out = dioxus_ssr::render_vdom(&app); - - assert_eq!(out, "default"); -} - -fn app(cx: Scope) -> Element { - cx.render(rsx! { - Router { - nav { "navbar" } - Route { to: "/", "default" } - Route { to: "/home", Home {} } - } - }) -} - -fn Home(cx: Scope) -> Element { - cx.render(rsx! { h1 { "Home" } }) -} diff --git a/packages/router/usage.md b/packages/router/usage.md index 58644d663..d5bc67aa8 100644 --- a/packages/router/usage.md +++ b/packages/router/usage.md @@ -73,10 +73,10 @@ If the active class is given on both, the `Router` and the `Link`, the one on th Router { active_class: "custom-active", // All active links in this router get this class. Link { to: "/", "Home" }, - Link { + Link { to: "/blog", active_class: "is-active", // Only for this Link. Overwrites "custom-active" from Router. - "Blog" + "Blog" }, } ``` @@ -207,7 +207,7 @@ let mut prerendered_pages = dom let _ = dom.rebuild(); // render the page and insert it into our map - (route, dioxus::ssr::render_vdom(&dom)) + (route, dioxus_ssr::render_vdom(&dom)) }) .collect::>(); ``` diff --git a/packages/rsx-prelude/Cargo.toml b/packages/rsx-prelude/Cargo.toml deleted file mode 100644 index 371a30679..000000000 --- a/packages/rsx-prelude/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[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"] diff --git a/packages/rsx/src/element.rs b/packages/rsx/src/element.rs index b2b832f04..6d9ffd5db 100644 --- a/packages/rsx/src/element.rs +++ b/packages/rsx/src/element.rs @@ -211,7 +211,7 @@ pub enum ElementAttr { } impl ElementAttr { - pub fn start(&self) -> Span { + pub fn flart(&self) -> Span { match self { ElementAttr::AttrText { name, .. } => name.span(), ElementAttr::AttrExpression { name, .. } => name.span(), diff --git a/packages/rsx_interpreter/Cargo.toml b/packages/rsx_interpreter/Cargo.toml index 75979882e..a9441f488 100644 --- a/packages/rsx_interpreter/Cargo.toml +++ b/packages/rsx_interpreter/Cargo.toml @@ -21,4 +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"] } \ No newline at end of file +dioxus = { path = "../dioxus", features = ["hot-reload"]} diff --git a/packages/rsx_interpreter/src/elements.rs b/packages/rsx_interpreter/src/elements.rs index b868b3537..f11789910 100644 --- a/packages/rsx_interpreter/src/elements.rs +++ b/packages/rsx_interpreter/src/elements.rs @@ -190,7 +190,7 @@ builder_constructors! { /// /// # Usage /// - /// ``` + /// ```rust, ignore /// html!(

A header element

) /// rsx!(h1 { "A header element" }) /// LazyNodes::new(|f| f.el(h1).children([f.text("A header element")]).finish()) @@ -210,7 +210,7 @@ builder_constructors! { /// - The `

` heading is usually a large bolded font. /// /// # Usage - /// ``` + /// ```rust, ignore /// html!(

A header element

) /// rsx!(h2 { "A header element" }) /// LazyNodes::new(|f| f.el(h2).children([f.text("A header element")]).finish()) @@ -283,7 +283,7 @@ builder_constructors! { /// Note: By default, browsers always place a line break before and after the
element. /// /// ## Usage - /// ``` + /// ```rust, ignore /// html!(
A header element
) /// rsx!(div { "A header element" }) /// LazyNodes::new(|f| f.element(div, &[], &[], &[], None)) diff --git a/packages/ssr/Cargo.toml b/packages/ssr/Cargo.toml index 984881633..2cdfa9ff6 100644 --- a/packages/ssr/Cargo.toml +++ b/packages/ssr/Cargo.toml @@ -16,7 +16,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"] dioxus-core = { path = "../core", version = "^0.2.1", features = ["serialize"] } [dev-dependencies] -dioxus = { path = "../rsx-prelude", version = "^0.1.0", package = "rsx-prelude" } +dioxus = { path = "../dioxus" } thiserror = "1.0.23" log = "0.4.13" fern = { version = "0.6.0", features = ["colored"] } diff --git a/packages/ssr/README.md b/packages/ssr/README.md index 7a7f1c4be..bcaea3044 100644 --- a/packages/ssr/README.md +++ b/packages/ssr/README.md @@ -23,7 +23,7 @@ let app: Component = |cx| cx.render(rsx!(div {"hello world!"})); let mut vdom = VirtualDom::new(app); let _ = vdom.rebuild(); -let text = dioxus::ssr::render_vdom(&vdom); +let text = dioxus_ssr::render_vdom(&vdom); assert_eq!(text, "
hello world!
") ``` @@ -33,7 +33,7 @@ assert_eq!(text, "
hello world!
") The simplest example is to simply render some `rsx!` nodes to html. This can be done with the [`render_lazy`] api. ```rust, ignore -let content = dioxus::ssr::render(rsx!{ +let content = dioxus_ssr::render(rsx!{ div { (0..5).map(|i| rsx!( "Number: {i}" @@ -48,14 +48,14 @@ let content = dioxus::ssr::render(rsx!{ let mut dom = VirtualDom::new(app); let _ = dom.rebuild(); -let content = dioxus::ssr::render_vdom(&dom); +let content = dioxus_ssr::render_vdom(&dom); ``` ## Configuring output It's possible to configure the output of the generated HTML. ```rust, ignore -let content = dioxus::ssr::render_vdom(&dom, |config| config.pretty(true).prerender(true)); +let content = dioxus_ssr::render_vdom(&dom, |config| config.pretty(true).prerender(true)); ``` ## Usage as a writer @@ -70,7 +70,7 @@ let mut buf = String::new(); let dom = VirtualDom::new(app); let _ = dom.rebuild(); -let args = dioxus::ssr::formatter(dom, |config| config); +let args = dioxus_ssr::formatter(dom, |config| config); buf.write_fmt!(format_args!("{}", args)); ``` @@ -95,7 +95,7 @@ To enable pre-rendering, simply configure the `SsrConfig` with pre-rendering ena ```rust, ignore let dom = VirtualDom::new(App); -let text = dioxus::ssr::render_vdom(App, |cfg| cfg.pre_render(true)); +let text = dioxus_ssr::render_vdom(App, |cfg| cfg.pre_render(true)); ``` ## Usage in server-side rendering @@ -103,7 +103,7 @@ let text = dioxus::ssr::render_vdom(App, |cfg| cfg.pre_render(true)); Dioxus SSR can also be to render on the server. Obviously, you can just render the VirtualDOM to a string and send that down. ```rust, ignore -let text = dioxus::ssr::render_vdom(&vdom); +let text = dioxus_ssr::render_vdom(&vdom); assert_eq!(text, "
hello world!
") ``` @@ -114,7 +114,7 @@ The rest of the space - IE doing this more efficiently, caching the virtualdom, Dioxus SSR needs an arena to allocate from - whether it be the VirtualDom or a dedicated Bump allocator. To render `rsx!` directly to a string, you'll want to create an `SsrRenderer` and call `render_lazy`. ```rust, ignore -let text = dioxus::ssr::SsrRenderer::new().render_lazy(rsx!{ +let text = dioxus_ssr::SsrRenderer::new().render_lazy(rsx!{ div { "hello world" } }); assert_eq!(text, "
hello world!
") diff --git a/packages/tui/Cargo.toml b/packages/tui/Cargo.toml index d201402e6..0e8533577 100644 --- a/packages/tui/Cargo.toml +++ b/packages/tui/Cargo.toml @@ -29,5 +29,10 @@ fxhash = "0.2" anymap = "0.12.1" [dev-dependencies] -dioxus = { path = "../rsx-prelude", version = "^0.1.0", package = "rsx-prelude" } -tokio = { version = "1" } \ No newline at end of file +dioxus = { path = "../dioxus" } +tokio = { version = "1" } +criterion = "0.3.5" + +[[bench]] +name = "update" +harness = false diff --git a/benches/tui_update.rs b/packages/tui/benches/update.rs similarity index 88% rename from benches/tui_update.rs rename to packages/tui/benches/update.rs index 811c40739..8db50a6a2 100644 --- a/benches/tui_update.rs +++ b/packages/tui/benches/update.rs @@ -17,14 +17,14 @@ fn tui_update(c: &mut Criterion) { &size, |b, size| { b.iter(|| match size { - 1 => dioxus::tui::launch_cfg(app3, Config::default().with_headless()), - 2 => dioxus::tui::launch_cfg(app6, Config::default().with_headless()), - 3 => dioxus::tui::launch_cfg(app9, Config::default().with_headless()), - 4 => dioxus::tui::launch_cfg(app12, Config::default().with_headless()), - 5 => dioxus::tui::launch_cfg(app15, Config::default().with_headless()), - 6 => dioxus::tui::launch_cfg(app18, Config::default().with_headless()), - 7 => dioxus::tui::launch_cfg(app21, Config::default().with_headless()), - 8 => dioxus::tui::launch_cfg(app24, Config::default().with_headless()), + 1 => dioxus_tui::launch_cfg(app3, Config::default().with_headless()), + 2 => dioxus_tui::launch_cfg(app6, Config::default().with_headless()), + 3 => dioxus_tui::launch_cfg(app9, Config::default().with_headless()), + 4 => dioxus_tui::launch_cfg(app12, Config::default().with_headless()), + 5 => dioxus_tui::launch_cfg(app15, Config::default().with_headless()), + 6 => dioxus_tui::launch_cfg(app18, Config::default().with_headless()), + 7 => dioxus_tui::launch_cfg(app21, Config::default().with_headless()), + 8 => dioxus_tui::launch_cfg(app24, Config::default().with_headless()), _ => (), }) }, diff --git a/examples/tui_all_events.rs b/packages/tui/examples/tui_all_events.rs similarity index 98% rename from examples/tui_all_events.rs rename to packages/tui/examples/tui_all_events.rs index 546a6f6f0..ffa03e039 100644 --- a/examples/tui_all_events.rs +++ b/packages/tui/examples/tui_all_events.rs @@ -3,7 +3,7 @@ use dioxus_html::on::{FocusData, KeyboardData, MouseData, WheelData}; use std::sync::Arc; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } #[derive(Debug)] diff --git a/examples/tui_border.rs b/packages/tui/examples/tui_border.rs similarity index 95% rename from examples/tui_border.rs rename to packages/tui/examples/tui_border.rs index 3e1c01849..1afa11b5f 100644 --- a/examples/tui_border.rs +++ b/packages/tui/examples/tui_border.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_buttons.rs b/packages/tui/examples/tui_buttons.rs similarity index 98% rename from examples/tui_buttons.rs rename to packages/tui/examples/tui_buttons.rs index f0c4b3948..5b9199baa 100644 --- a/examples/tui_buttons.rs +++ b/packages/tui/examples/tui_buttons.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; use dioxus_html::input_data::keyboard_types::Code; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } #[derive(PartialEq, Props)] diff --git a/examples/tui_color_test.rs b/packages/tui/examples/tui_color_test.rs similarity index 91% rename from examples/tui_color_test.rs rename to packages/tui/examples/tui_color_test.rs index 1a5a67457..f3972331e 100644 --- a/examples/tui_color_test.rs +++ b/packages/tui/examples/tui_color_test.rs @@ -1,9 +1,9 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch_cfg( + dioxus_tui::launch_cfg( app, - dioxus::tui::Config::default().with_rendering_mode(dioxus::tui::RenderingMode::Ansi), + dioxus_tui::Config::default().with_rendering_mode(dioxus_tui::RenderingMode::Ansi), ); } diff --git a/examples/tui_colorpicker.rs b/packages/tui/examples/tui_colorpicker.rs similarity index 96% rename from examples/tui_colorpicker.rs rename to packages/tui/examples/tui_colorpicker.rs index da3f179f8..354eb1dc3 100644 --- a/examples/tui_colorpicker.rs +++ b/packages/tui/examples/tui_colorpicker.rs @@ -3,7 +3,7 @@ use dioxus_tui::query::Query; use dioxus_tui::Size; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_components.rs b/packages/tui/examples/tui_components.rs similarity index 98% rename from examples/tui_components.rs rename to packages/tui/examples/tui_components.rs index 91e95deb8..651b9edd8 100644 --- a/examples/tui_components.rs +++ b/packages/tui/examples/tui_components.rs @@ -3,7 +3,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } #[derive(Props, PartialEq)] diff --git a/examples/tui_frame.rs b/packages/tui/examples/tui_frame.rs similarity index 98% rename from examples/tui_frame.rs rename to packages/tui/examples/tui_frame.rs index 13f3510e0..c7f728e4a 100644 --- a/examples/tui_frame.rs +++ b/packages/tui/examples/tui_frame.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_hover.rs b/packages/tui/examples/tui_hover.rs similarity index 99% rename from examples/tui_hover.rs rename to packages/tui/examples/tui_hover.rs index 5c3b2d832..4362876d2 100644 --- a/examples/tui_hover.rs +++ b/packages/tui/examples/tui_hover.rs @@ -4,7 +4,7 @@ use dioxus::{events::MouseData, prelude::*}; use dioxus_core::UiEvent; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_keys.rs b/packages/tui/examples/tui_keys.rs similarity index 98% rename from examples/tui_keys.rs rename to packages/tui/examples/tui_keys.rs index f947f97d0..3c3d04cf2 100644 --- a/examples/tui_keys.rs +++ b/packages/tui/examples/tui_keys.rs @@ -6,7 +6,7 @@ use dioxus_html::input_data::MouseButtonSet; use dioxus_html::on::{KeyboardEvent, MouseEvent}; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_list.rs b/packages/tui/examples/tui_list.rs similarity index 94% rename from examples/tui_list.rs rename to packages/tui/examples/tui_list.rs index 158cafae2..5f41de399 100644 --- a/examples/tui_list.rs +++ b/packages/tui/examples/tui_list.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_margin.rs b/packages/tui/examples/tui_margin.rs similarity index 97% rename from examples/tui_margin.rs rename to packages/tui/examples/tui_margin.rs index 6e476c1d6..d86bc116e 100644 --- a/examples/tui_margin.rs +++ b/packages/tui/examples/tui_margin.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_quadrants.rs b/packages/tui/examples/tui_quadrants.rs similarity index 98% rename from examples/tui_quadrants.rs rename to packages/tui/examples/tui_quadrants.rs index 0333e40c8..d9da5dcb5 100644 --- a/examples/tui_quadrants.rs +++ b/packages/tui/examples/tui_quadrants.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_readme.rs b/packages/tui/examples/tui_readme.rs similarity index 91% rename from examples/tui_readme.rs rename to packages/tui/examples/tui_readme.rs index 3e15cf7e3..816f20ca3 100644 --- a/examples/tui_readme.rs +++ b/packages/tui/examples/tui_readme.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_task.rs b/packages/tui/examples/tui_task.rs similarity index 96% rename from examples/tui_task.rs rename to packages/tui/examples/tui_task.rs index f53d01af9..32215c0b1 100644 --- a/examples/tui_task.rs +++ b/packages/tui/examples/tui_task.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/examples/tui_text.rs b/packages/tui/examples/tui_text.rs similarity index 99% rename from examples/tui_text.rs rename to packages/tui/examples/tui_text.rs index a2992a8a0..5268c59f6 100644 --- a/examples/tui_text.rs +++ b/packages/tui/examples/tui_text.rs @@ -1,7 +1,7 @@ use dioxus::prelude::*; fn main() { - dioxus::tui::launch(app); + dioxus_tui::launch(app); } fn app(cx: Scope) -> Element { diff --git a/packages/tui/examples/ui.rsx b/packages/tui/examples/ui.rsx deleted file mode 100644 index 962dbc3f1..000000000 --- a/packages/tui/examples/ui.rsx +++ /dev/null @@ -1,5 +0,0 @@ -div { - div { - - } -} diff --git a/packages/tui/src/query.rs b/packages/tui/src/query.rs index 7a850df42..0a8a886cc 100644 --- a/packages/tui/src/query.rs +++ b/packages/tui/src/query.rs @@ -17,11 +17,11 @@ use crate::Dom; /// # Example /// ```rust, ignore /// use dioxus::prelude::*; -/// use dioxus::tui::query::Query; -/// use dioxus::tui::Size; +/// use dioxus_tui::query::Query; +/// use dioxus_tui::Size; /// /// fn main() { -/// dioxus::tui::launch(app); +/// dioxus_tui::launch(app); /// } /// /// fn app(cx: Scope) -> Element { diff --git a/packages/web/Cargo.toml b/packages/web/Cargo.toml index 4760ef096..69ef21989 100644 --- a/packages/web/Cargo.toml +++ b/packages/web/Cargo.toml @@ -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 = { path = "../rsx-prelude", version = "^0.1.0", package = "rsx-prelude" } +dioxus = { path = "../dioxus" } wasm-bindgen-test = "0.3.29" dioxus-ssr = { path = "../ssr" } wasm-logger = "0.2.0" diff --git a/packages/web/src/cfg.rs b/packages/web/src/cfg.rs index 591868c34..d9c448f92 100644 --- a/packages/web/src/cfg.rs +++ b/packages/web/src/cfg.rs @@ -5,7 +5,7 @@ /// # Example /// /// ```rust, ignore -/// dioxus::web::launch(App, |cfg| cfg.hydrate(true).root_name("myroot")) +/// dioxus_web::launch(App, |cfg| cfg.hydrate(true).root_name("myroot")) /// ``` pub struct WebConfig { pub(crate) hydrate: bool, diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 3a68de7a0..afed73c11 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -102,7 +102,7 @@ pub fn launch(root_component: Component) { /// /// You can configure the WebView window with a configuration closure /// -/// ```rust +/// ```rust, ignore /// use dioxus::prelude::*; /// /// fn main() { diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index bd728ae2a..000000000 --- a/src/lib.rs +++ /dev/null @@ -1,70 +0,0 @@ -#![doc = include_str!("../notes/README.md")] - -pub use dioxus_core as core; - -pub mod hooks { - #[cfg(feature = "hooks")] - pub use dioxus_hooks::*; - - #[cfg(all(target_arch = "wasm32", feature = "web"))] - pub use dioxus_web::use_eval; - - #[cfg(all(not(target_arch = "wasm32"), feature = "desktop"))] - pub use dioxus_desktop::use_eval; -} - -#[cfg(feature = "router")] -pub use dioxus_router as router; - -#[cfg(feature = "ssr")] -pub use dioxus_ssr as ssr; - -#[cfg(feature = "web")] -pub use dioxus_web as web; - -#[cfg(feature = "liveview")] -pub use dioxus_liveview as liveview; - -#[cfg(feature = "desktop")] -pub use dioxus_desktop as desktop; - -#[cfg(feature = "tui")] -pub use dioxus_tui as tui; - -#[cfg(feature = "native-core")] -pub use dioxus_native_core as native_core; -#[cfg(feature = "native-core")] -pub use dioxus_native_core_macro as native_core_macro; - -#[cfg(feature = "fermi")] -pub use fermi; - -pub mod events { - #[cfg(feature = "html")] - pub use dioxus_html::{on::*, KeyCode}; -} - -pub use dioxus_rsx as rsx; - -#[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 = "router")] - pub use dioxus_router::{use_route, use_router, Link, Redirect, Route, Router, UseRoute}; - - #[cfg(feature = "fermi")] - pub use fermi::{use_atom_ref, use_init_atom_root, use_read, use_set, Atom, AtomRef}; - - #[cfg(feature = "hot-reload")] - pub use dioxus_rsx_interpreter::{ - captuered_context::{CapturedContext, FormattedArg, IfmtArgs}, - get_line_num, resolve_scope, CodeLocation, RsxContext, - }; -} diff --git a/tests/fermi.rs b/tests/fermi.rs deleted file mode 100644 index 1149539f0..000000000 --- a/tests/fermi.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![allow(non_snake_case)] - -use dioxus::prelude::*; -use fermi::*; - -#[test] -fn test_fermi() { - let mut app = VirtualDom::new(App); - app.rebuild(); -} - -static TITLE: Atom = |_| "".to_string(); -static USERS: AtomFamily = |_| Default::default(); - -fn App(cx: Scope) -> Element { - cx.render(rsx!( - Leaf { id: 0 } - Leaf { id: 1 } - Leaf { id: 2 } - )) -} - -#[derive(Debug, PartialEq, Props)] -struct LeafProps { - id: u32, -} - -fn Leaf(cx: Scope) -> Element { - let _user = use_read(&cx, TITLE); - let _user = use_read(&cx, USERS); - - rsx!(cx, div { - button { - onclick: move |_| {}, - "Start" - } - button { - onclick: move |_| {}, - "Stop" - } - button { - onclick: move |_| {}, - "Reverse" - } - }) -} diff --git a/tests/test_logging.rs b/tests/test_logging.rs deleted file mode 100644 index 54b5982ef..000000000 --- a/tests/test_logging.rs +++ /dev/null @@ -1,51 +0,0 @@ -pub fn set_up_logging(enabled: bool) { - use fern::colors::{Color, ColoredLevelConfig}; - - if !enabled { - return; - } - - // configure colors for the whole line - let colors_line = ColoredLevelConfig::new() - .error(Color::Red) - .warn(Color::Yellow) - // we actually don't need to specify the color for debug and info, they are white by default - .info(Color::White) - .debug(Color::White) - // depending on the terminals color scheme, this is the same as the background color - .trace(Color::BrightBlack); - - // configure colors for the name of the level. - // since almost all of them are the same as the color for the whole line, we - // just clone `colors_line` and overwrite our changes - let colors_level = colors_line.info(Color::Green); - // here we set up our fern Dispatch - - // when running tests in batch, the logger is re-used, so ignore the logger error - let _ = fern::Dispatch::new() - .format(move |out, message, record| { - out.finish(format_args!( - "{color_line}[{level}{color_line}] {message}\x1B[0m", - color_line = format_args!( - "\x1B[{}m", - colors_line.get_color(&record.level()).to_fg_str() - ), - level = colors_level.color(record.level()), - message = message, - )); - }) - // set the default log level. to filter out verbose log messages from dependencies, set - // this to Warn and overwrite the log level for your crate. - .level(log::LevelFilter::Debug) - // .level(log::LevelFilter::Warn) - // change log levels for individual modules. Note: This looks for the record's target - // field which defaults to the module path but can be overwritten with the `target` - // parameter: - // `info!(target="special_target", "This log message is about special_target");` - // .level_for("dioxus", log::LevelFilter::Debug) - // .level_for("dioxus", log::LevelFilter::Info) - // .level_for("pretty_colored", log::LevelFilter::Trace) - // output to stdout - .chain(std::io::stdout()) - .apply(); -}