diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 000000000..e2fd03ad8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,8 @@ +ARG VARIANT="nightly-bookworm-slim" +FROM rustlang/rust:${VARIANT} +ENV DEBIAN_FRONTEND noninteractive +RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive + +RUN apt-get -qq install build-essential libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev \ No newline at end of file diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 000000000..570435663 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,26 @@ +# Dev Container + +A dev container in the most simple context allows one to create a consistent development environment within a docker container that can easily be opened locally or remotely via codespaces such that contributors don't need to install anything to contribute. + +## Useful Links + +- +- +- +- + +## Using A Dev Container + +### Locally + +To use this dev container locally, make sure Docker is installed and in VSCode install the `ms-vscode-remote.remote-containers` extension. Then from the root of Dioxus you can type `Ctrl + Shift + P`, then choose `Dev Containers: Rebuild and Reopen in Devcontainer`. + +### Codespaces + +[Codespaces Setup](https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace-for-a-repository#creating-a-codespace-for-a-repository) + +## Troubleshooting + +If having difficulty commiting with github, and you use ssh or gpg keys, you may need to ensure that the keys are being shared properly between your host and VSCode. + +Though VSCode does a pretty good job sharing credentials between host and devcontainer, to save some time you can always just reopen the container locally to commit with `Ctrl + Shift + P`, then choose `Dev Containers: Reopen Folder Locally` diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..aa536ab53 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +{ + "name": "dioxus", + "remoteUser": "vscode", + "build": { + "dockerfile": "./Dockerfile", + "context": "." + }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "true", + "username": "vscode", + "uid": "1000", + "gid": "1000", + "upgradePackages": "true" + } + }, + "containerEnv": { + "RUST_LOG": "INFO" + }, + "customizations": { + "vscode": { + "settings": { + "files.watcherExclude": { + "**/target/**": true + }, + "[rust]": { + "editor.formatOnSave": true + } + }, + "extensions": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "serayuzgur.crates" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/docs stable.yml b/.github/workflows/docs stable.yml index 2790b1d51..98245fa89 100644 --- a/.github/workflows/docs stable.yml +++ b/.github/workflows/docs stable.yml @@ -29,7 +29,7 @@ jobs: # cd fermi && mdbook build -d ../nightly/fermi && cd .. - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@v4.4.1 + uses: JamesIves/github-pages-deploy-action@v4.4.2 with: branch: gh-pages # The branch the action should deploy to. folder: docs/nightly # The folder the action should deploy. diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 07a8b462b..d209c0c1a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -34,7 +34,7 @@ jobs: # cd fermi && mdbook build -d ../nightly/fermi && cd .. - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@v4.4.1 + uses: JamesIves/github-pages-deploy-action@v4.4.2 with: branch: gh-pages # The branch the action should deploy to. folder: docs/nightly # The folder the action should deploy. diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c5616322e..b80a7b1f5 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -30,14 +30,7 @@ jobs: name: Test Suite runs-on: macos-latest steps: - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - uses: actions/checkout@v3 - - uses: actions-rs/cargo@v1 - with: - command: test - args: --all --tests + - run: cargo test --all --tests diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a3bff9fc6..1a4b156cd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,30 +32,19 @@ jobs: name: Check runs-on: ubuntu-latest steps: - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: sudo apt-get update - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev - uses: actions/checkout@v3 - - uses: actions-rs/cargo@v1 - with: - command: check - args: --all --examples --tests + - run: cargo check --all --examples --tests test: if: github.event.pull_request.draft == false name: Test Suite runs-on: ubuntu-latest steps: - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: sudo apt-get update - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev @@ -63,48 +52,31 @@ jobs: - uses: browser-actions/setup-firefox@latest - uses: jetli/wasm-pack-action@v0.4.0 - uses: actions/checkout@v3 - - uses: actions-rs/cargo@v1 - with: - command: make - args: tests + - run: cargo make tests fmt: if: github.event.pull_request.draft == false name: Rustfmt runs-on: ubuntu-latest steps: - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: rustup component add rustfmt - uses: actions/checkout@v3 - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo fmt --all -- --check clippy: if: github.event.pull_request.draft == false name: Clippy runs-on: ubuntu-latest steps: - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - run: sudo apt-get update - run: sudo apt install libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev - run: rustup component add clippy - uses: actions/checkout@v3 - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --workspace --examples --tests -- -D warnings + - run: cargo clippy --workspace --examples --tests -- -D warnings # Coverage is disabled until we can fix it # coverage: diff --git a/.mailmap b/.mailmap new file mode 100644 index 000000000..8562f720b --- /dev/null +++ b/.mailmap @@ -0,0 +1 @@ +Jonathan Kelley diff --git a/Cargo.toml b/Cargo.toml index 7b6a08a39..84c28b054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "packages/dioxus", "packages/core", + "packages/cli", "packages/core-macro", "packages/router", "packages/html", @@ -22,9 +23,53 @@ members = [ "packages/rsx-rosetta", "packages/signals", "packages/hot-reload", + "packages/fullstack", + "packages/fullstack/server-macro", + "packages/fullstack/examples/axum-hello-world", + "packages/fullstack/examples/axum-router", + "packages/fullstack/examples/axum-desktop", + "packages/fullstack/examples/salvo-hello-world", + "packages/fullstack/examples/warp-hello-world", "docs/guide", + # Full project examples + "examples/tailwind", + "examples/PWA-example", ] +# dependencies that are shared across packages +[workspace.dependencies] +dioxus = { path = "packages/dioxus" } +dioxus-core = { path = "packages/core" } +dioxus-core-macro = { path = "packages/core-macro" } +dioxus-router = { path = "packages/router" } +dioxus-html = { path = "packages/html" } +dioxus-hooks = { path = "packages/hooks" } +dioxus-web = { path = "packages/web" } +dioxus-ssr = { path = "packages/ssr" } +dioxus-desktop = { path = "packages/desktop" } +dioxus-mobile = { path = "packages/mobile" } +dioxus-interpreter-js = { path = "packages/interpreter" } +fermi = { path = "packages/fermi" } +dioxus-liveview = { path = "packages/liveview" } +dioxus-autofmt = { path = "packages/autofmt" } +dioxus-rsx = { path = "packages/rsx" } +dioxus-tui = { path = "packages/dioxus-tui" } +rink = { path = "packages/rink" } +dioxus-native-core = { path = "packages/native-core" } +dioxus-native-core-macro = { path = "packages/native-core-macro" } +dioxus-rsx-rosetta = { path = "packages/rsx-rosetta" } +dioxus-signals = { path = "packages/signals" } +dioxus-hot-reload = { path = "packages/hot-reload" } +dioxus-fullstack = { path = "packages/fullstack" } +dioxus_server_macro = { path = "packages/fullstack/server-macro" } +log = "0.4.19" +tokio = "1.28" +slab = "0.4.2" +futures-channel = "0.3.21" +futures-util = { version = "0.3", default-features = false } +rustc-hash = "1.1.0" +wasm-bindgen = "0.2.79" + # This is a "virtual package" # It is not meant to be published, but is used so "cargo run --example XYZ" works properly [package] @@ -42,12 +87,12 @@ rust-version = "1.60.0" publish = false [dev-dependencies] -dioxus = { path = "./packages/dioxus" } -dioxus-desktop = { path = "./packages/desktop", features = ["transparent"] } -dioxus-ssr = { path = "./packages/ssr" } -dioxus-router = { path = "./packages/router" } -dioxus-signals = { path = "./packages/signals" } -fermi = { path = "./packages/fermi" } +dioxus = { workspace = true } +dioxus-desktop = { workspace = true, features = ["transparent"] } +dioxus-ssr = { workspace = true } +dioxus-router = { workspace = true } +dioxus-signals = { workspace = true } +fermi = { workspace = true } futures-util = "0.3.21" log = "0.4.14" num-format = "0.4.0" @@ -61,7 +106,7 @@ tokio = { version = "1.16.1", features = ["full"] } reqwest = { version = "0.11.9", features = ["json"] } fern = { version = "0.6.0", features = ["colored"] } thiserror = "1.0.30" -env_logger = "0.9.0" +env_logger = "0.10.0" simple_logger = "4.0.0" [profile.release] diff --git a/Makefile.toml b/Makefile.toml index 8ecbe6b2e..6f331b98f 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -42,10 +42,10 @@ private = true [tasks.test] dependencies = ["build"] command = "cargo" -args = ["test", "--lib", "--bins", "--tests", "--examples", "--workspace", "--exclude", "dioxus-router"] +args = ["test", "--lib", "--bins", "--tests", "--examples", "--workspace", "--exclude", "dioxus-router", "--exclude", "dioxus-desktop"] private = true [tasks.test-with-browser] -env = { CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["**/packages/router"] } +env = { CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["**/packages/router", "**/packages/desktop"] } private = true workspace = true diff --git a/README.md b/README.md index 40981401e..9a1c347c9 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ fn app(cx: Scope) -> Element { } ``` -Dioxus can be used to deliver webapps, desktop apps, static sites, mobile apps, TUI apps, liveview apps, and more. Dioxus is entirely renderer agnostic and can be used as platform for any renderer. +Dioxus can be used to deliver webapps, desktop apps, static sites, mobile apps, TUI apps, liveview apps, and more. Dioxus is entirely renderer agnostic and can be used as a platform for any renderer. If you know React, then you already know Dioxus. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..766752ecf --- /dev/null +++ b/docs/README.md @@ -0,0 +1,19 @@ +# Building the Documentation + +Dioxus uses a fork of MdBook with multilanguage support. To build the documentation, you will need to install the forked version of MdBook. + +```sh +cargo install mdbook --git https://github.com/Demonthos/mdBook.git --branch master +``` + +Then, you can build the documentation by running: + +```sh +cd docs +cd guide +mdbook build -d ../nightly/guide +cd .. +cd router +mdbook build -d ../nightly/router +cd ../../ +``` diff --git a/docs/guide/Cargo.toml b/docs/guide/Cargo.toml index 227bdfa35..06b17b0e9 100644 --- a/docs/guide/Cargo.toml +++ b/docs/guide/Cargo.toml @@ -16,12 +16,12 @@ dioxus-native-core-macro = { path = "../../packages/native-core-macro" } dioxus-router = { path = "../../packages/router" } dioxus-liveview = { path = "../../packages/liveview", features = ["axum"] } dioxus-tui = { path = "../../packages/dioxus-tui" } +dioxus-fullstack = { path = "../../packages/fullstack" } +# dioxus = { path = "../../packages/dioxus", features = ["desktop", "web", "ssr", "router", "fermi", "tui"] } fermi = { path = "../../packages/fermi" } shipyard = "0.6.2" - - -# 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=[]} +tokio = { version = "1.19.2", features = ["full"] } axum = { version = "0.6.1", features = ["ws"] } +gloo-storage = "0.2.2" diff --git a/docs/guide/examples/event_prevent_default.rs b/docs/guide/examples/event_prevent_default.rs index b109700bf..32443d017 100644 --- a/docs/guide/examples/event_prevent_default.rs +++ b/docs/guide/examples/event_prevent_default.rs @@ -10,8 +10,7 @@ fn App(cx: Scope) -> Element { // ANCHOR: prevent_default cx.render(rsx! { input { - prevent_default: "oninput", - prevent_default: "onclick", + prevent_default: "oninput onclick", } }) // ANCHOR_END: prevent_default diff --git a/docs/guide/examples/hello_world_ssr.rs b/docs/guide/examples/hello_world_ssr.rs new file mode 100644 index 000000000..0f8db0b46 --- /dev/null +++ b/docs/guide/examples/hello_world_ssr.rs @@ -0,0 +1,63 @@ +#![allow(unused)] +#![allow(non_snake_case)] +// ANCHOR: all + +// ANCHOR: main +#![allow(non_snake_case)] +use axum::{response::Html, routing::get, Router}; +// import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types +use dioxus::prelude::*; + +#[tokio::main] +async fn main() { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000)); + println!("listening on http://{}", addr); + + axum::Server::bind(&addr) + .serve( + Router::new() + .route("/", get(app_endpoint)) + .into_make_service(), + ) + .await + .unwrap(); +} + +// ANCHOR_END: main + +// ANCHOR: endpoint +async fn app_endpoint() -> Html { + // render the rsx! macro to HTML + Html(dioxus_ssr::render_lazy(rsx! { + div { "hello world!" } + })) +} +// ANCHOR_END: endpoint + +// ANCHOR: second_endpoint +async fn second_app_endpoint() -> Html { + // create a component that renders a div with the text "hello world" + fn app(cx: Scope) -> Element { + cx.render(rsx!(div { "hello world" })) + } + // create a VirtualDom with the app component + let mut app = VirtualDom::new(app); + // rebuild the VirtualDom before rendering + let _ = app.rebuild(); + + // render the VirtualDom to HTML + Html(dioxus_ssr::render(&app)) +} +// ANCHOR_END: second_endpoint + +// ANCHOR: component +// define a component that renders a div with the text "Hello, world!" +fn App(cx: Scope) -> Element { + cx.render(rsx! { + div { + "Hello, world!" + } + }) +} +// ANCHOR_END: component +// ANCHOR_END: all diff --git a/docs/guide/examples/hooks_anti_patterns.rs b/docs/guide/examples/hooks_anti_patterns.rs new file mode 100644 index 000000000..2119b8601 --- /dev/null +++ b/docs/guide/examples/hooks_anti_patterns.rs @@ -0,0 +1,38 @@ +#![allow(unused)] + +use dioxus::prelude::*; + +fn main() {} + +// ANCHOR: non_clone_state +use std::cell::RefCell; +use std::rc::Rc; +use std::sync::Arc; + +struct UseState<'a, T> { + value: &'a RefCell, + update: Arc, +} + +fn my_use_state(cx: &ScopeState, init: impl FnOnce() -> T) -> UseState { + // The update function will trigger a re-render in the component cx is attached to + let update = cx.schedule_update(); + // Create the initial state + let value = cx.use_hook(|| RefCell::new(init())); + + UseState { value, update } +} + +impl UseState<'_, T> { + fn get(&self) -> T { + self.value.borrow().clone() + } + + fn set(&self, value: T) { + // Update the state + *self.value.borrow_mut() = value; + // Trigger a re-render on the component the state is from + (self.update)(); + } +} +// ANCHOR_END: non_clone_state diff --git a/docs/guide/examples/hooks_composed.rs b/docs/guide/examples/hooks_composed.rs index 801474aa3..782a19d7d 100644 --- a/docs/guide/examples/hooks_composed.rs +++ b/docs/guide/examples/hooks_composed.rs @@ -11,3 +11,57 @@ fn use_settings(cx: &ScopeState) -> &UseSharedState { use_shared_state::(cx).expect("App settings not provided") } // ANCHOR_END: wrap_context + +// ANCHOR: use_storage +use gloo_storage::{LocalStorage, Storage}; +use serde::{de::DeserializeOwned, Serialize}; + +/// A persistent storage hook that can be used to store data across application reloads. +#[allow(clippy::needless_return)] +pub fn use_persistent( + cx: &ScopeState, + // A unique key for the storage entry + key: impl ToString, + // A function that returns the initial value if the storage entry is empty + init: impl FnOnce() -> T, +) -> &UsePersistent { + // Use the use_ref hook to create a mutable state for the storage entry + let state = use_ref(cx, move || { + // This closure will run when the hook is created + let key = key.to_string(); + let value = LocalStorage::get(key.as_str()).ok().unwrap_or_else(init); + StorageEntry { key, value } + }); + + // Wrap the state in a new struct with a custom API + // Note: We use use_hook here so that this hook is easier to use in closures in the rsx. Any values with the same lifetime as the ScopeState can be used in the closure without cloning. + cx.use_hook(|| UsePersistent { + inner: state.clone(), + }) +} + +struct StorageEntry { + key: String, + value: T, +} + +/// Storage that persists across application reloads +pub struct UsePersistent { + inner: UseRef>, +} + +impl UsePersistent { + /// Returns a reference to the value + pub fn get(&self) -> T { + self.inner.read().value.clone() + } + + /// Sets the value + pub fn set(&self, value: T) { + let mut inner = self.inner.write(); + // Write the new value to local storage + LocalStorage::set(inner.key.as_str(), &value); + inner.value = value; + } +} +// ANCHOR_END: use_storage diff --git a/docs/guide/examples/hooks_custom_logic.rs b/docs/guide/examples/hooks_custom_logic.rs new file mode 100644 index 000000000..2323ddb11 --- /dev/null +++ b/docs/guide/examples/hooks_custom_logic.rs @@ -0,0 +1,57 @@ +#![allow(unused)] + +use dioxus::prelude::*; + +fn main() {} + +// ANCHOR: use_state +use std::cell::RefCell; +use std::rc::Rc; +use std::sync::Arc; + +#[derive(Clone)] +struct UseState { + value: Rc>, + update: Arc, +} + +fn my_use_state(cx: &ScopeState, init: impl FnOnce() -> T) -> &UseState { + cx.use_hook(|| { + // The update function will trigger a re-render in the component cx is attached to + let update = cx.schedule_update(); + // Create the initial state + let value = Rc::new(RefCell::new(init())); + + UseState { value, update } + }) +} + +impl UseState { + fn get(&self) -> T { + self.value.borrow().clone() + } + + fn set(&self, value: T) { + // Update the state + *self.value.borrow_mut() = value; + // Trigger a re-render on the component the state is from + (self.update)(); + } +} +// ANCHOR_END: use_state + +// ANCHOR: use_context +pub fn use_context(cx: &ScopeState) -> Option<&T> { + cx.use_hook(|| cx.consume_context::()).as_ref() +} + +pub fn use_context_provider(cx: &ScopeState, f: impl FnOnce() -> T) -> &T { + cx.use_hook(|| { + let val = f(); + // Provide the context state to the scope + cx.provide_context(val.clone()); + val + }) +} + +// ANCHOR_END: use_context diff --git a/docs/guide/examples/hydration.rs b/docs/guide/examples/hydration.rs new file mode 100644 index 000000000..31574edce --- /dev/null +++ b/docs/guide/examples/hydration.rs @@ -0,0 +1,34 @@ +#![allow(non_snake_case, unused)] +use dioxus::prelude::*; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true)); + #[cfg(feature = "ssr")] + { + use dioxus_fullstack::prelude::*; + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + .serve_dioxus_application("", ServeConfigBuilder::new(app, ())) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || 0); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + }) +} diff --git a/docs/guide/examples/hydration_props.rs b/docs/guide/examples/hydration_props.rs new file mode 100644 index 000000000..4e6bb1752 --- /dev/null +++ b/docs/guide/examples/hydration_props.rs @@ -0,0 +1,74 @@ +#![allow(non_snake_case, unused)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + // Get the root props from the document + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + use axum::extract::Path; + use axum::extract::State; + use axum::routing::get; + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + // Serve the dist folder with the static javascript and WASM files created by the dixous CLI + .serve_static_assets("./dist") + // Register server functions + .register_server_fns("") + // Connect to the hot reload server in debug mode + .connect_hot_reload() + // Render the application. This will serialize the root props (the intial count) into the HTML + .route( + "/", + get(move | State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + 0, + ) + .build(), + ) + )}), + ) + // Render the application with a different intial count + .route( + "/:initial_count", + get(move |Path(intial_count): Path, State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + intial_count, + ) + .build(), + ) + )}), + ) + .with_state(SSRState::default()) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || *cx.props); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + }) +} diff --git a/docs/guide/examples/readme_expanded.rs b/docs/guide/examples/readme_expanded.rs new file mode 100644 index 000000000..896d365e5 --- /dev/null +++ b/docs/guide/examples/readme_expanded.rs @@ -0,0 +1,107 @@ +use dioxus::prelude::*; + +fn main() { + dioxus_desktop::launch(app); +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || 0); + + cx.render( + // rsx expands to LazyNodes::new + ::dioxus::core::LazyNodes::new( + move |__cx: &::dioxus::core::ScopeState| -> ::dioxus::core::VNode { + // The template is every static part of the rsx + static TEMPLATE: ::dioxus::core::Template = ::dioxus::core::Template { + // This is the source location of the rsx that generated this template. This is used to make hot rsx reloading work. Hot rsx reloading just replaces the template with a new one generated from the rsx by the CLI. + name: "examples\\readme.rs:14:15:250", + // The root nodes are the top level nodes of the rsx + roots: &[ + // The h1 node + ::dioxus::core::TemplateNode::Element { + // Find the built in h1 tag in the dioxus_elements crate exported by the dioxus html crate + tag: dioxus_elements::h1::TAG_NAME, + namespace: dioxus_elements::h1::NAME_SPACE, + attrs: &[], + // The children of the h1 node + children: &[ + // The dynamic count text node + // Any nodes that are dynamic have a dynamic placeholder with a unique index + ::dioxus::core::TemplateNode::DynamicText { + // This index is used to find what element in `dynamic_nodes` to use instead of the placeholder + id: 0usize, + }, + ], + }, + // The up high button node + ::dioxus::core::TemplateNode::Element { + tag: dioxus_elements::button::TAG_NAME, + namespace: dioxus_elements::button::NAME_SPACE, + attrs: &[ + // The dynamic onclick listener attribute + // Any attributes that are dynamic have a dynamic placeholder with a unique index. + ::dioxus::core::TemplateAttribute::Dynamic { + // Similar to dynamic nodes, dynamic attributes have a unique index used to find the attribute in `dynamic_attrs` to use instead of the placeholder + id: 0usize, + }, + ], + children: &[::dioxus::core::TemplateNode::Text { text: "Up high!" }], + }, + // The down low button node + ::dioxus::core::TemplateNode::Element { + tag: dioxus_elements::button::TAG_NAME, + namespace: dioxus_elements::button::NAME_SPACE, + attrs: &[ + // The dynamic onclick listener attribute + ::dioxus::core::TemplateAttribute::Dynamic { id: 1usize }, + ], + children: &[::dioxus::core::TemplateNode::Text { text: "Down low!" }], + }, + ], + // Node paths is a list of paths to every dynamic node in the rsx + node_paths: &[ + // The first node path is the path to the dynamic node with an id of 0 (the count text node) + &[ + // Go to the index 0 root node + 0u8, + // + // Go to the first child of the root node + 0u8, + ], + ], + // Attr paths is a list of paths to every dynamic attribute in the rsx + attr_paths: &[ + // The first attr path is the path to the dynamic attribute with an id of 0 (the up high button onclick listener) + &[ + // Go to the index 1 root node + 1u8, + ], + // The second attr path is the path to the dynamic attribute with an id of 1 (the down low button onclick listener) + &[ + // Go to the index 2 root node + 2u8, + ], + ], + }; + // The VNode is a reference to the template with the dynamic parts of the rsx + ::dioxus::core::VNode { + parent: None, + key: None, + // The static template this node will use. The template is stored in a Cell so it can be replaced with a new template when hot rsx reloading is enabled + template: std::cell::Cell::new(TEMPLATE), + root_ids: Default::default(), + dynamic_nodes: __cx.bump().alloc([ + // The dynamic count text node (dynamic node id 0) + __cx.text_node(format_args!("High-Five counter: {0}", count)), + ]), + dynamic_attrs: __cx.bump().alloc([ + // The dynamic up high button onclick listener (dynamic attribute id 0) + dioxus_elements::events::onclick(__cx, move |_| count += 1), + // The dynamic down low button onclick listener (dynamic attribute id 1) + dioxus_elements::events::onclick(__cx, move |_| count -= 1), + ]), + } + }, + ), + ) +} diff --git a/docs/guide/examples/server_basic.rs b/docs/guide/examples/server_basic.rs new file mode 100644 index 000000000..858fcfd50 --- /dev/null +++ b/docs/guide/examples/server_basic.rs @@ -0,0 +1,30 @@ +#![allow(non_snake_case, unused)] +use dioxus::prelude::*; + +#[tokio::main] +async fn main() { + #[cfg(feature = "ssr")] + { + use dioxus_fullstack::prelude::*; + + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + .serve_dioxus_application("", ServeConfigBuilder::new(app, ())) + .into_make_service(), + ) + .await + .unwrap(); + } +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || 0); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + }) +} diff --git a/docs/guide/examples/server_context.rs b/docs/guide/examples/server_context.rs new file mode 100644 index 000000000..eb3c5e9c1 --- /dev/null +++ b/docs/guide/examples/server_context.rs @@ -0,0 +1,109 @@ +#![allow(non_snake_case, unused)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + // Get the root props from the document + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + use axum::extract::Path; + use axum::extract::State; + use axum::routing::get; + + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + // Serve the dist folder with the static javascript and WASM files created by the dixous CLI + .serve_static_assets("./dist") + // Register server functions + .register_server_fns("") + // Connect to the hot reload server in debug mode + .connect_hot_reload() + // Render the application. This will serialize the root props (the intial count) into the HTML + .route( + "/", + get(move |State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + 0, + ) + .build(), + ) + )}), + ) + // Render the application with a different intial count + .route( + "/:initial_count", + get(move |Path(intial_count): Path, State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + intial_count, + ) + .build(), + ) + )}), + ) + .with_state(SSRState::default()) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || *cx.props); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![count]; + let sc = cx.sc(); + async move { + // Call the server function just like a local async function + if let Ok(new_count) = double_server(sc, *count.current()).await { + count.set(new_count); + } + } + }, + "Double" + } + }) +} + +// We use the "getcbor" encoding to make caching easier +#[server(DoubleServer, "", "getcbor")] +async fn double_server(cx: DioxusServerContext, number: usize) -> Result { + // Perform some expensive computation or access a database on the server + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + let result = number * 2; + + println!( + "User Agent {:?}", + cx.request_parts().headers.get("User-Agent") + ); + + // Set the cache control header to 1 hour on the post request + cx.response_headers_mut() + .insert("Cache-Control", "max-age=3600".parse().unwrap()); + + println!("server calculated {result}"); + + Ok(result) +} diff --git a/docs/guide/examples/server_context_state.rs b/docs/guide/examples/server_context_state.rs new file mode 100644 index 000000000..c75496561 --- /dev/null +++ b/docs/guide/examples/server_context_state.rs @@ -0,0 +1,134 @@ +#![allow(non_snake_case, unused)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; + +#[cfg(feature = "ssr")] +#[derive(Default, Clone)] +struct ServerFunctionState { + call_count: std::sync::Arc, +} + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + // Get the root props from the document + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + use axum::body::Body; + use axum::extract::Path; + use axum::extract::State; + use axum::http::Request; + use axum::routing::get; + use std::sync::Arc; + + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + // Serve the dist folder with the static javascript and WASM files created by the dixous CLI + .serve_static_assets("./dist") + // Register server functions + .register_server_fns_with_handler("", |func| { + move |State(server_fn_state): State, req: Request| async move { + let (parts, body) = req.into_parts(); + let parts: Arc = Arc::new(parts.into()); + let mut server_context = DioxusServerContext::new(parts.clone()); + server_context.insert(server_fn_state); + server_fn_handler(server_context, func.clone(), parts, body).await + } + }) + .with_state(ServerFunctionState::default()) + // Connect to the hot reload server in debug mode + .connect_hot_reload() + // Render the application. This will serialize the root props (the intial count) into the HTML + .route( + "/", + get(move |State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + 0, + ) + .build(), + ) + )}), + ) + // Render the application with a different intial count + .route( + "/:initial_count", + get(move |Path(intial_count): Path, State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + intial_count, + ) + .build(), + ) + )}), + ) + .with_state(SSRState::default()) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || *cx.props); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![count]; + let sc = cx.sc(); + async move { + // Call the server function just like a local async function + if let Ok(new_count) = double_server(sc, *count.current()).await { + count.set(new_count); + } + } + }, + "Double" + } + }) +} + +// We use the "getcbor" encoding to make caching easier +#[server(DoubleServer, "", "getcbor")] +async fn double_server(cx: DioxusServerContext, number: usize) -> Result { + // Perform some expensive computation or access a database on the server + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + let result = number * 2; + + println!( + "User Agent {:?}", + cx.request_parts().headers.get("User-Agent") + ); + + // Set the cache control header to 1 hour on the post request + cx.response_headers_mut() + .insert("Cache-Control", "max-age=3600".parse().unwrap()); + + // Get the server function state + let server_fn_state = cx.get::().unwrap(); + let call_count = server_fn_state + .call_count + .fetch_add(1, std::sync::atomic::Ordering::SeqCst); + println!("server functions have been called {call_count} times"); + + println!("server calculated {result}"); + + Ok(result) +} diff --git a/docs/guide/examples/server_function.rs b/docs/guide/examples/server_function.rs new file mode 100644 index 000000000..55f5104f9 --- /dev/null +++ b/docs/guide/examples/server_function.rs @@ -0,0 +1,96 @@ +#![allow(non_snake_case, unused)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + // Get the root props from the document + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + use axum::extract::Path; + use axum::extract::State; + use axum::routing::get; + + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + // Serve the dist folder with the static javascript and WASM files created by the dixous CLI + .serve_static_assets("./dist") + // Register server functions + .register_server_fns("") + // Connect to the hot reload server in debug mode + .connect_hot_reload() + // Render the application. This will serialize the root props (the intial count) into the HTML + .route( + "/", + get(move |Path(intial_count): Path, State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + intial_count, + ) + .build(), + ) + )}), + ) + // Render the application with a different intial count + .route( + "/:initial_count", + get(move |Path(intial_count): Path, State(ssr_state): State| async move { axum::body::Full::from( + ssr_state.render( + &ServeConfigBuilder::new( + app, + intial_count, + ) + .build(), + ) + )}), + ) + .with_state(SSRState::default()) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || *cx.props); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![count]; + async move { + // Call the server function just like a local async function + if let Ok(new_count) = double_server(*count.current()).await { + count.set(new_count); + } + } + }, + "Double" + } + }) +} + +#[server(DoubleServer)] +async fn double_server(number: usize) -> Result { + // Perform some expensive computation or access a database on the server + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + let result = number * 2; + println!("server calculated {result}"); + Ok(result) +} diff --git a/docs/guide/src/en/SUMMARY.md b/docs/guide/src/en/SUMMARY.md index f9f31ed52..62ef5adf7 100644 --- a/docs/guide/src/en/SUMMARY.md +++ b/docs/guide/src/en/SUMMARY.md @@ -6,6 +6,7 @@ - [Desktop](getting_started/desktop.md) - [Web](getting_started/web.md) - [Server-Side Rendering](getting_started/ssr.md) + - [Fullstack](getting_started/fullstack.md) - [Liveview](getting_started/liveview.md) - [Terminal UI](getting_started/tui.md) - [Mobile](getting_started/mobile.md) @@ -31,14 +32,24 @@ - [Error Handling](best_practices/error_handling.md) - [Antipatterns](best_practices/antipatterns.md) - [Publishing](publishing/index.md) + - [Desktop](publishing/desktop.md) - [Web](publishing/web.md) --- +- [Fullstack](fullstack/index.md) + - [Getting Started](fullstack/getting_started.md) + - [Communicating with the Server](fullstack/server_functions.md) + +--- + - [Custom Renderer](custom_renderer/index.md) --- -[Roadmap](roadmap.md) -[Contributing](contributing.md) +- [Contributing](contributing/index.md) + - [Project Structure](contributing/project_structure.md) + - [Walkthrough of Internals](contributing/walkthrough_readme.md) + - [Guiding Principles](contributing/guiding_principles.md) + - [Roadmap](contributing/roadmap.md) diff --git a/docs/guide/src/en/__unused/advanced-guides/06-subscription-api.md b/docs/guide/src/en/__unused/advanced-guides/06-subscription-api.md index 19ec66563..1d53a8d61 100644 --- a/docs/guide/src/en/__unused/advanced-guides/06-subscription-api.md +++ b/docs/guide/src/en/__unused/advanced-guides/06-subscription-api.md @@ -2,7 +2,7 @@ Yew subscriptions are used to schedule update for components into the future. The `Context` object can create subscriptions: -```rust +```rust, no_run fn Component(cx: Component) -> DomTree { let update = cx.schedule(); @@ -19,7 +19,7 @@ The subscription API exposes this functionality allowing hooks and state managem some state or event occurs outside of the component. For instance, the `use_context` hook uses this to subscribe components that use a particular context. -```rust +```rust, no_run fn use_context(cx: Scope) -> I { } diff --git a/docs/guide/src/en/__unused/advanced-guides/10-concurrent-mode.md b/docs/guide/src/en/__unused/advanced-guides/10-concurrent-mode.md index 6bbebbeed..b92897157 100644 --- a/docs/guide/src/en/__unused/advanced-guides/10-concurrent-mode.md +++ b/docs/guide/src/en/__unused/advanced-guides/10-concurrent-mode.md @@ -4,7 +4,7 @@ Concurrent mode provides a mechanism for building efficient asynchronous compone To make a component asynchronous, simply change its function signature to async. -```rust +```rust, no_run fn Example(cx: Scope) -> Vnode { rsx!{
"Hello world!"
} } @@ -12,7 +12,7 @@ fn Example(cx: Scope) -> Vnode { becomes -```rust +```rust, no_run async fn Example(cx: Scope) -> Vnode { rsx!{
"Hello world!"
} } @@ -20,7 +20,7 @@ async fn Example(cx: Scope) -> Vnode { Now, logic in components can be awaited to delay updates of the component and its children. Like so: -```rust +```rust, no_run async fn Example(cx: Scope) -> Vnode { let name = fetch_name().await; rsx!{
"Hello {name}"
} @@ -39,7 +39,7 @@ Instead, we suggest using hooks and future combinators that can safely utilize t As part of our Dioxus hooks crate, we provide a data loader hook which pauses a component until its async dependencies are ready. This caches requests, reruns the fetch if dependencies have changed, and provides the option to render something else while the component is loading. -```rust +```rust, no_run async fn ExampleLoader(cx: Scope) -> Vnode { /* Fetch, pause the component from rendering at all. @@ -61,7 +61,7 @@ async fn ExampleLoader(cx: Scope) -> Vnode { } ``` -```rust +```rust, no_run async fn Example(cx: Scope) -> DomTree { // Diff this set between the last set // Check if we have any outstanding tasks? diff --git a/docs/guide/src/en/__unused/advanced-guides/11-arena-memo.md b/docs/guide/src/en/__unused/advanced-guides/11-arena-memo.md index ca44a6b7e..49fedda11 100644 --- a/docs/guide/src/en/__unused/advanced-guides/11-arena-memo.md +++ b/docs/guide/src/en/__unused/advanced-guides/11-arena-memo.md @@ -10,7 +10,7 @@ https://dmitripavlutin.com/use-react-memo-wisely/ This behavior is defined as an attribute implicit to user components. When in React land you might wrap a component with `react.memo`, Dioxus components are automatically memoized via an implicit attribute. You can manually configure this behavior on any component with "nomemo" to disable memoization. -```rust +```rust, no_run fn test() -> DomTree { html! { <> @@ -42,7 +42,7 @@ fn test_component(cx: Scope, name: String) -> Element { Take a component like this: -```rust +```rust, no_run fn test(cx: Scope) -> DomTree { let Bundle { alpha, beta, gamma } = use_context::(cx); html! { diff --git a/docs/guide/src/en/__unused/advanced-guides/12-signals.md b/docs/guide/src/en/__unused/advanced-guides/12-signals.md index c7012a119..df13b91d8 100644 --- a/docs/guide/src/en/__unused/advanced-guides/12-signals.md +++ b/docs/guide/src/en/__unused/advanced-guides/12-signals.md @@ -10,7 +10,7 @@ By default, Dioxus will only try to diff subtrees of components with dynamic con Your component today might look something like this: -```rust +```rust, no_run fn Comp(cx: Scope) -> DomTree { let (title, set_title) = use_state(cx, || "Title".to_string()); cx.render(rsx!{ @@ -24,7 +24,7 @@ fn Comp(cx: Scope) -> DomTree { This component is fairly straightforward – the input updates its own value on every change. However, every call to set_title will re-render the component. If we add a large list, then every time we update the title input, Dioxus will need to diff the entire list, over, and over, and over. This is **a lot** of wasted clock-cycles! -```rust +```rust, no_run fn Comp(cx: Scope) -> DomTree { let (title, set_title) = use_state(cx, || "Title".to_string()); cx.render(rsx!{ @@ -47,7 +47,7 @@ Many experienced React developers will just say "this is bad design" – but we We can use signals to generate a two-way binding between data and the input box. Our text input is now just a two-line component! -```rust +```rust, no_run fn Comp(cx: Scope) -> DomTree { let mut title = use_signal(cx, || String::from("Title")); cx.render(rsx!(input { value: title })) @@ -56,7 +56,7 @@ fn Comp(cx: Scope) -> DomTree { For a slightly more interesting example, this component calculates the sum between two numbers, but totally skips the diffing process. -```rust +```rust, no_run fn Calculator(cx: Scope) -> DomTree { let mut a = use_signal(cx, || 0); let mut b = use_signal(cx, || 0); @@ -71,7 +71,7 @@ fn Calculator(cx: Scope) -> DomTree { Do you notice how we can use built-in operations on signals? Under the hood, we actually create a new derived signal that depends on `a` and `b`. Whenever `a` or `b` update, then `c` will update. If we need to create a new derived signal that's more complex than a basic operation (`std::ops`) we can either chain signals together or combine them: -```rust +```rust, no_run let mut a = use_signal(cx, || 0); let mut b = use_signal(cx, || 0); @@ -83,7 +83,7 @@ let c = a.with(b).map(|(a, b)| *a + *b); If we ever need to get the value out of a signal, we can simply `deref` it. -```rust +```rust, no_run let mut a = use_signal(cx, || 0); let c = *a + *b; ``` @@ -94,7 +94,7 @@ Calling `deref` or `deref_mut` is actually more complex than it seems. When a va Sometimes you want a signal to propagate across your app, either through far-away siblings or through deeply-nested components. In these cases, we use Dirac: Dioxus's first-class state management toolkit. Dirac atoms automatically implement the Signal API. This component will bind the input element to the `TITLE` atom. -```rust +```rust, no_run const TITLE: Atom = || "".to_string(); const Provider: Component = |cx|{ let title = use_signal(cx, &TITLE); @@ -104,7 +104,7 @@ const Provider: Component = |cx|{ If we use the `TITLE` atom in another component, we can cause updates to flow between components without calling render or diffing either component trees: -```rust +```rust, no_run const Receiver: Component = |cx|{ let title = use_signal(cx, &TITLE); log::info!("This will only be called once!"); @@ -130,7 +130,7 @@ By default, Dioxus is limited when you use iter/map. With the `For` component, y Dioxus automatically understands how to use your signals when mixed with iterators through `Deref`/`DerefMut`. This lets you efficiently map collections while avoiding the re-rendering of lists. In essence, signals act as a hint to Dioxus on how to avoid un-necessary checks and renders, making your app faster. -```rust +```rust, no_run const DICT: AtomFamily = |_| {}; const List: Component = |cx|{ let dict = use_signal(cx, &DICT); @@ -146,7 +146,7 @@ const List: Component = |cx|{ Apps that use signals will enjoy a pleasant hybrid of server-side and client-side rendering. -```rust +```rust, no_run ``` diff --git a/docs/guide/src/en/__unused/advanced-guides/13-subtrees.md b/docs/guide/src/en/__unused/advanced-guides/13-subtrees.md index 0108186eb..d7a8ba1d7 100644 --- a/docs/guide/src/en/__unused/advanced-guides/13-subtrees.md +++ b/docs/guide/src/en/__unused/advanced-guides/13-subtrees.md @@ -22,13 +22,11 @@ The desktop renderer comes pre-loaded with the window and notification subtree p Subtrees also solve the "bridging" issues in React where two different renderers need two different VirtualDoms to work properly. In Dioxus, you only ever need one VirtualDom and the right renderer plugins. - ## API Due to their importance in the hierarchy, Components – not nodes – are treated as subtree roots. - -```rust +```rust, no_run fn Subtree

(cx: Scope

) -> DomTree { diff --git a/docs/guide/src/en/__unused/advanced-guides/custom-renderer.md b/docs/guide/src/en/__unused/advanced-guides/custom-renderer.md index 194fff54a..b14243dae 100644 --- a/docs/guide/src/en/__unused/advanced-guides/custom-renderer.md +++ b/docs/guide/src/en/__unused/advanced-guides/custom-renderer.md @@ -22,7 +22,7 @@ For reference, check out the WebSys renderer as a starting point for your custom The current `RealDom` trait lives in `dioxus-core/diff`. A version of it is provided here (but might not be up-to-date): -```rust +```rust, no_run pub trait RealDom<'a> { fn handle_edit(&mut self, edit: DomEdit); fn request_available_node(&mut self) -> ElementId; @@ -32,7 +32,7 @@ pub trait RealDom<'a> { For reference, the "DomEdit" type is a serialized enum that represents an atomic operation occurring on the RealDom. The variants roughly follow this set: -```rust +```rust, no_run enum DomEdit { PushRoot, AppendChildren, @@ -51,12 +51,11 @@ enum DomEdit { The Dioxus diffing mechanism operates as a [stack machine](https://en.wikipedia.org/wiki/Stack_machine) where the "push_root" method pushes a new "real" DOM node onto the stack and "append_child" and "replace_with" both remove nodes from the stack. - ### An example For the sake of understanding, lets consider this example – a very simple UI declaration: -```rust +```rust, no_run rsx!( h1 {"hello world"} ) ``` @@ -64,7 +63,7 @@ To get things started, Dioxus must first navigate to the container of this h1 ta When the renderer receives this instruction, it pushes the actual Node onto its own stack. The real renderer's stack will look like this: -```rust +```rust, no_run instructions: [ PushRoot(Container) ] @@ -75,7 +74,7 @@ stack: [ Next, Dioxus will encounter the h1 node. The diff algorithm decides that this node needs to be created, so Dioxus will generate the DomEdit `CreateElement`. When the renderer receives this instruction, it will create an unmounted node and push into its own stack: -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -85,8 +84,10 @@ stack: [ h1, ] ``` + Next, Dioxus sees the text node, and generates the `CreateTextNode` DomEdit: -```rust + +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -98,9 +99,10 @@ stack: [ "hello world" ] ``` + Remember, the text node is not attached to anything (it is unmounted) so Dioxus needs to generate an Edit that connects the text node to the h1 element. It depends on the situation, but in this case we use `AppendChildren`. This pops the text node off the stack, leaving the h1 element as the next element in line. -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -112,8 +114,10 @@ stack: [ h1 ] ``` + We call `AppendChildren` again, popping off the h1 node and attaching it to the parent: -```rust + +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -125,8 +129,10 @@ stack: [ ContainerNode, ] ``` + Finally, the container is popped since we don't need it anymore. -```rust + +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -137,8 +143,10 @@ instructions: [ ] stack: [] ``` + Over time, our stack looked like this: -```rust + +```rust, no_run [] [Container] [Container, h1] @@ -164,7 +172,7 @@ Like most GUIs, Dioxus relies on an event loop to progress the VirtualDOM. The V The code for the WebSys implementation is straightforward, so we'll add it here to demonstrate how simple an event loop is: -```rust +```rust, no_run pub async fn run(&mut self) -> dioxus_core::error::Result<()> { // Push the body element onto the WebsysDom's stack machine let mut websys_dom = crate::new::WebsysDom::new(prepare_websys_dom()); @@ -194,7 +202,7 @@ pub async fn run(&mut self) -> dioxus_core::error::Result<()> { It's important that you decode the real events from your event system into Dioxus' synthetic event system (synthetic meaning abstracted). This simply means matching your event type and creating a Dioxus `VirtualEvent` type. Your custom event must implement the corresponding event trait. Right now, the VirtualEvent system is modeled almost entirely around the HTML spec, but we are interested in slimming it down. -```rust +```rust, no_run fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent { match event.type_().as_str() { "keydown" | "keypress" | "keyup" => { @@ -224,7 +232,7 @@ These custom elements are defined as unit structs with trait implementations. For example, the `div` element is (approximately!) defined as such: -```rust +```rust, no_run struct div; impl div { /// Some glorious documentation about the class property. @@ -235,8 +243,8 @@ impl div { // more attributes } ``` -You've probably noticed that many elements in the `rsx!` and `html!` macros support on-hover documentation. The approach we take to custom elements means that the unit struct is created immediately where the element is used in the macro. When the macro is expanded, the doc comments still apply to the unit struct, giving tons of in-editor feedback, even inside a proc macro. +You've probably noticed that many elements in the `rsx!` and `html!` macros support on-hover documentation. The approach we take to custom elements means that the unit struct is created immediately where the element is used in the macro. When the macro is expanded, the doc comments still apply to the unit struct, giving tons of in-editor feedback, even inside a proc macro. ## Compatibility @@ -252,7 +260,7 @@ The best hooks will properly detect the target platform and still provide functi This particular code _will panic_ due to the unwrap on downcast_ref. Try to avoid these types of patterns. -```rust +```rust, no_run let div_ref = use_node_ref(cx); cx.render(rsx!{ diff --git a/docs/guide/src/en/__unused/advanced-guides/rsx.md b/docs/guide/src/en/__unused/advanced-guides/rsx.md index 062246490..169a57875 100644 --- a/docs/guide/src/en/__unused/advanced-guides/rsx.md +++ b/docs/guide/src/en/__unused/advanced-guides/rsx.md @@ -5,11 +5,14 @@ Many modern frameworks provide a domain-specific-language for declaring user-int With Dioxus, we actually ship two different macros – a macro that mimics JSX (the `html!` macro) and a macro that mimics Rust's native nested-struct syntax (the `rsx!` macro). These macros simply transform their inputs into NodeFactory calls. For instance, this html! call: -```rust + +```rust, no_run html!(

"hello world"
) ``` + becomes this NodeFactory call: -```rust + +```rust, no_run |f| f.element( dioxus_elements::div, // tag [], // listeners @@ -18,6 +21,7 @@ becomes this NodeFactory call: None // key ) ``` + The NodeFactory API is fairly ergonomic, making it a viable option to use directly. The NodeFactory API is also compile-time correct and has incredible syntax highlighting support. We use what Rust calls a "unit type" – the `dioxus_elements::div` and associated methods to ensure that a `div` can only have attributes associated with `div`s. This lets us tack on relevant documentation, autocomplete support, and jump-to-definition for methods and attributes. ![Compile time correct syntax](../images/compiletimecorrect.png) @@ -28,7 +32,7 @@ The html! macro supports a limited subset of the html standard. Rust's macro par However, writing HTML by hand is a bit tedious – IDE tools for Rust don't support linting/autocomplete/syntax highlighting. We suggest using RSX – it's more natural for Rust programs and _does_ integrate well with Rust IDE tools. -```rust +```rust, no_run let name = "jane"; let pending = false; let count = 10; @@ -50,7 +54,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 +```rust, no_run dioxus::ssr::render_lazy(rsx! { div { p {"Hello, {name}!"} diff --git a/docs/guide/src/en/__unused/advanced-guides/testing.md b/docs/guide/src/en/__unused/advanced-guides/testing.md index 2f0f97b67..87e72309c 100644 --- a/docs/guide/src/en/__unused/advanced-guides/testing.md +++ b/docs/guide/src/en/__unused/advanced-guides/testing.md @@ -2,7 +2,7 @@ To test your Rust code, you can annotate any function with the `#[test]` block. In VSCode with RA, this will provide a lens to click and run the test. -```rust +```rust, no_run #[test] fn component_runs() { assert!(true) @@ -11,7 +11,7 @@ fn component_runs() { This will test your Rust code _without_ going through the browser. This is ideal for squashing logic bugs and ensuring components render appropriately when the browsers's DOM is not needed. If you need to run tests in the browser, you can annotate your blocks with the `#[dioxus::test]` block. -```rust +```rust, no_run #[dioxus::test] fn runs_in_browser() { // ... diff --git a/docs/guide/src/en/__unused/attribute_spreading.md b/docs/guide/src/en/__unused/attribute_spreading.md index fcf799f3d..9bbb30698 100644 --- a/docs/guide/src/en/__unused/attribute_spreading.md +++ b/docs/guide/src/en/__unused/attribute_spreading.md @@ -1,6 +1,6 @@ In the cases where you need to pass arbitrary element properties into a component – say to add more functionality to the `` tag, Dioxus will accept any quoted fields. This is similar to adding arbitrary fields to regular elements using quotes. -```rust +```rust, no_run rsx!( Clickable { @@ -13,7 +13,7 @@ rsx!( For a component to accept these attributes, you must add an `attributes` field to your component's properties. We can use the spread syntax to add these attributes to whatever nodes are in our component. -```rust +```rust, no_run #[derive(Props)] struct ClickableProps<'a> { attributes: Attributes<'a> @@ -26,4 +26,5 @@ fn clickable(cx: Scope>) -> Element { "Any link, anywhere" } )) -} \ No newline at end of file +} +``` diff --git a/docs/guide/src/en/__unused/composing.md b/docs/guide/src/en/__unused/composing.md index 06648a4c1..82435d6f3 100644 --- a/docs/guide/src/en/__unused/composing.md +++ b/docs/guide/src/en/__unused/composing.md @@ -1,6 +1,6 @@ # Thinking in Reactively -We've finally reached the point in our tutorial where we can talk about the theory of Reactivity. We've talked about defining a declarative view, but not about the aspects that make our code *reactive*. +We've finally reached the point in our tutorial where we can talk about the theory of Reactivity. We've talked about defining a declarative view, but not about the aspects that make our code _reactive_. Understanding the theory of reactive programming is essential to making sense of Dioxus and writing effective, performant UIs. @@ -15,7 +15,7 @@ This section is a bit long, but worth the read. We recommend coffee, tea, and/or ## Reactive Programming -Dioxus is one of a handful of Rust libraries that provide a "Reactive Programming Model". The term "Reactive programming" is a classification of programming paradigm – much like functional or imperative programming. This is a very important distinction since it affects how we *think* about our code. +Dioxus is one of a handful of Rust libraries that provide a "Reactive Programming Model". The term "Reactive programming" is a classification of programming paradigm – much like functional or imperative programming. This is a very important distinction since it affects how we _think_ about our code. Reactive programming is a programming model concerned with deriving computations from asynchronous data flow. Most reactive programs are comprised of datasources, intermediate computations, and a final result. @@ -33,7 +33,7 @@ In Reactive Programming, we don't think about whether or not we should reevaluat In Rust, our reactive app would look something like: -```rust +```rust, no_run fn compute_g(t: i32, seconds: i32) -> bool { t > seconds } @@ -55,7 +55,7 @@ The Dioxus VirtualDom provides us a framework for reactive programming. When we If we represented the reactive graph presented above in Dioxus, it would look very similar: -```rust +```rust, no_run // Declare a component that holds our datasources and calculates `g` fn RenderGraph(cx: Scope) -> Element { let seconds = use_datasource(SECONDS); @@ -83,11 +83,11 @@ fn RenderT(cx: Scope, seconds: i32, constant: i32) -> Element { With this app, we've defined three components. Our top-level component provides our datasources (the hooks), computation nodes (child components), and a final value (what's "rendered"). -Now, whenever the `constant` changes, our `RenderT` component will be re-rendered. However, if `seconds` doesn't change, then we don't need to re-render `RenderG` because the input is the same. If `seconds` *does* change, then both RenderG and RenderT will be reevaluated. +Now, whenever the `constant` changes, our `RenderT` component will be re-rendered. However, if `seconds` doesn't change, then we don't need to re-render `RenderG` because the input is the same. If `seconds` _does_ change, then both RenderG and RenderT will be reevaluated. Dioxus is "Reactive" because it provides this framework for us. All we need to do is write our own tiny units of computation and Dioxus figures out which components need to be reevaluated automatically. -These extra checks and algorithms add some overhead, which is why you see projects like [Sycamore](http://sycamore-rs.netlify.app) and [SolidJS](http://solidjs.com) eliminating them altogether. Dioxus is *really* fast, so we're willing to exchange the added overhead for improved developer experience. +These extra checks and algorithms add some overhead, which is why you see projects like [Sycamore](http://sycamore-rs.netlify.app) and [SolidJS](http://solidjs.com) eliminating them altogether. Dioxus is _really_ fast, so we're willing to exchange the added overhead for improved developer experience. ## How do we update values in our dataflow graph? @@ -104,7 +104,7 @@ Technically, the root props of the VirtualDom are a third datasource, but since For local state in hooks, Dioxus gives us the `use_hook` method which returns an `&mut T` without any requirements. This means raw hook values are not tracked by Dioxus. In fact, we could write a component that modifies a hook value directly: -```rust +```rust, no_run fn app(cx: Scope) -> Element { let mut count = cx.use_hook(|_| 0); cx.render(rsx!{ @@ -118,7 +118,7 @@ fn app(cx: Scope) -> Element { However, when this value is written to, the component does not know to be reevaluated. We must explicitly tell Dioxus that this component is "dirty" and needs to be re-rendered. This is done through the `cx.needs_update` method: -```rust +```rust, no_run button { onclick: move |_| { *count += 1; @@ -130,7 +130,7 @@ button { Now, whenever we click the button, the value will change and the component will be re-rendered. -> Re-rendering is when Dioxus calls your function component *again*. Component functions will be called over and over throughout their lifetime, so they should be mostly side-effect free. +> Re-rendering is when Dioxus calls your function component _again_. Component functions will be called over and over throughout their lifetime, so they should be mostly side-effect free. ### Understand this! @@ -146,9 +146,9 @@ To make app-global state easier to reason about, Dioxus makes all values provide In these cases, App-Global state needs to manually track which components need to be re-generated. -To regenerate *any* component in your app, you can get a handle to the Dioxus' internal scheduler through `schedule_update_any`: +To regenerate _any_ component in your app, you can get a handle to the Dioxus' internal scheduler through `schedule_update_any`: -```rust +```rust, no_run let force_render = cx.schedule_update_any(); // force a render of the root component @@ -179,9 +179,9 @@ From here, Dioxus computes the difference between these trees and updates the Re ## Suppressing Renders -So, we know how to make Dioxus render, but how do we *stop* it? What if we *know* that our state didn't change and we shouldn't render and diff new nodes because they'll be exactly the same as the last time? +So, we know how to make Dioxus render, but how do we _stop_ it? What if we _know_ that our state didn't change and we shouldn't render and diff new nodes because they'll be exactly the same as the last time? -In these cases, you want to reach for *memoization*. In Dioxus, memoization involves preventing a component from rendering again if its props didn't change since the last time it attempted to render. +In these cases, you want to reach for _memoization_. In Dioxus, memoization involves preventing a component from rendering again if its props didn't change since the last time it attempted to render. Visually, you can tell that a component will only re-render if the new value is sufficiently different than the old one. @@ -196,7 +196,7 @@ Visually, you can tell that a component will only re-render if the new value is This is why when you `derive(Props)`, you must also implement the `PartialEq` trait. To override the memoization strategy for a component, you can simply implement your own PartialEq. -```rust +```rust, no_run struct CustomProps { val: i32, } @@ -215,7 +215,7 @@ However, for components that borrow data, it doesn't make sense to implement Par You can technically override this behavior by implementing the `Props` trait manually, though it's unsafe and easy to mess up: -```rust +```rust, no_run unsafe impl Properties for CustomProps { fn memoize(&self, other &Self) -> bool { self != other @@ -224,6 +224,7 @@ unsafe impl Properties for CustomProps { ``` TLDR: + - Dioxus checks if props changed between renders - If props changed according to PartialEq, Dioxus re-renders the component - Props that have a lifetime (ie `<'a>`) will always be re-rendered diff --git a/docs/guide/src/en/__unused/fanout.md b/docs/guide/src/en/__unused/fanout.md index 20c4c9974..63b7d3403 100644 --- a/docs/guide/src/en/__unused/fanout.md +++ b/docs/guide/src/en/__unused/fanout.md @@ -6,7 +6,7 @@ One of the most reliable state management patterns in large Dioxus apps is `fan- With `fan-out`, our individual components at "leaf" position of our VirtualDom are "pure", making them easily reusable, testable, and deterministic. For instance, the "title" bar of our app might be a fairly complicated component. -```rust +```rust, no_run #[derive(Props, PartialEq)] struct TitlebarProps { title: String, @@ -26,7 +26,7 @@ fn Titlebar(cx: Scope) -> Element { If we used global state like use_context or fermi, we might be tempted to inject our `use_read` directly into the component. -```rust +```rust, no_run fn Titlebar(cx: Scope) -> Element { let title = use_read(cx, TITLE); let subtitle = use_read(cx, SUBTITLE); @@ -41,7 +41,7 @@ For many apps – this is a fine pattern, especially if the component is a one-o To enable our titlebar component to be used across apps, we want to lift our atoms upwards and out of the Titlebar component. We would organize a bunch of other components in this section of the app to share some of the same state. -```rust +```rust, no_run fn DocsiteTitlesection(cx: Scope) { let title = use_read(cx, TITLE); let subtitle = use_read(cx, SUBTITLE); diff --git a/docs/guide/src/en/__unused/index.md b/docs/guide/src/en/__unused/index.md index 1732afdae..d1863a465 100644 --- a/docs/guide/src/en/__unused/index.md +++ b/docs/guide/src/en/__unused/index.md @@ -4,16 +4,15 @@ Every app you'll build with Dioxus will have some sort of state that needs to be In this chapter, we'll cover the various ways to manage state, the appropriate terminology, various patterns, and some problems you might run into. - ## The Problem Why do people say state management is so difficult? What does it mean? -Generally, state management is the code you need to write to ensure that your app renders the *correct* content. If the user inputs a name, then you need to display the appropriate response – like alerts, validation, and disable/enable various elements on the page. Things can quickly become tricky if you need loading screens and cancellable tasks. +Generally, state management is the code you need to write to ensure that your app renders the _correct_ content. If the user inputs a name, then you need to display the appropriate response – like alerts, validation, and disable/enable various elements on the page. Things can quickly become tricky if you need loading screens and cancellable tasks. -For the simplest of apps, all of your state can enter the app from the root props. This is common in server-side rendering – we can collect all of the required state *before* rendering the content. +For the simplest of apps, all of your state can enter the app from the root props. This is common in server-side rendering – we can collect all of the required state _before_ rendering the content. -```rust +```rust, no_run let all_content = get_all_content().await; let output = dioxus::ssr::render_lazy(rsx!{ @@ -27,7 +26,6 @@ With this incredibly simple setup, it is highly unlikely that you'll have render However, most of your apps will store state inside of the Dioxus VirtualDom – either through local state or global state. - ## Your options To deal with complexity, you have a couple of options: diff --git a/docs/guide/src/en/__unused/localstate.md b/docs/guide/src/en/__unused/localstate.md index 2a20d77d4..fbc04272a 100644 --- a/docs/guide/src/en/__unused/localstate.md +++ b/docs/guide/src/en/__unused/localstate.md @@ -6,7 +6,7 @@ The first step to dealing with complexity in your app is to refactor your state Let's say we're managing the state for a list of Todos. Whenever we edit the todo, we want the list to update. We might've started building our app but putting everything into a single `use_ref`. -```rust +```rust, no_run struct Todo { contents: String, is_hovered: bool, @@ -29,7 +29,7 @@ cx.render(rsx!{ As shown above, whenever the todo is hovered, we want to set its state: -```rust +```rust, no_run todos.write()[0].is_hovered = true; ``` @@ -37,7 +37,7 @@ As the amount of interactions goes up, so does the complexity of our state. Shou Instead, let's refactor our Todo component to handle its own state: -```rust +```rust, no_run #[inline_props] fn Todo<'a>(cx: Scope, todo: &'a Todo) -> Element { let is_hovered = use_state(cx, || false); @@ -53,16 +53,15 @@ fn Todo<'a>(cx: Scope, todo: &'a Todo) -> Element { Now, we can simplify our Todo data model to get rid of local UI state: -```rust +```rust, no_run struct Todo { contents: String, } ``` -This is not only better for encapsulation and abstraction, but it's only more performant! Whenever a Todo is hovered, we won't need to re-render *every* Todo again – only the Todo that's currently being hovered. +This is not only better for encapsulation and abstraction, but it's only more performant! Whenever a Todo is hovered, we won't need to re-render _every_ Todo again – only the Todo that's currently being hovered. - -Wherever possible, you should try to refactor the "view" layer *out* of your data model. +Wherever possible, you should try to refactor the "view" layer _out_ of your data model. ## Immutability @@ -72,7 +71,7 @@ In these scenarios consider breaking your `use_ref` into individual `use_state`s You might've started modeling your component with a struct and use_ref -```rust +```rust, no_run struct State { count: i32, color: &'static str, @@ -85,17 +84,17 @@ let state = use_ref(cx, State::new) The "better" approach for this particular component would be to break the state apart into different values: -```rust +```rust, no_run let count = use_state(cx, || 0); let color = use_state(cx, || "red"); let names = use_state(cx, HashMap::new); ``` -You might recognize that our "names" value is a HashMap – which is not terribly cheap to clone every time we update its value. To solve this issue, we *highly* suggest using a library like [`im`](https://crates.io/crates/im) which will take advantage of structural sharing to make clones and mutations much cheaper. +You might recognize that our "names" value is a HashMap – which is not terribly cheap to clone every time we update its value. To solve this issue, we _highly_ suggest using a library like [`im`](https://crates.io/crates/im) which will take advantage of structural sharing to make clones and mutations much cheaper. When combined with the `make_mut` method on `use_state`, you can get really succinct updates to collections: -```rust +```rust, no_run let todos = use_state(cx, im_rc::HashMap::default); todos.make_mut().insert("new todo", Todo { @@ -106,5 +105,3 @@ todos.make_mut().insert("new todo", Todo { ## Moving on This particular local patterns are powerful but is not a cure-all for state management problems. Sometimes your state problems are much larger than just staying local to a component. - - diff --git a/docs/guide/src/en/__unused/memoization.md b/docs/guide/src/en/__unused/memoization.md index 9bd0e8b24..4baa73be9 100644 --- a/docs/guide/src/en/__unused/memoization.md +++ b/docs/guide/src/en/__unused/memoization.md @@ -1,11 +1,10 @@ - ## Memoization Dioxus uses Memoization for a more efficient user interface. Memoization is the process in which we check if a component actually needs to be re-rendered when its props change. If a component's properties change but they wouldn't affect the output, then we don't need to re-render the component, saving time! For example, let's say we have a component that has two children: -```rust +```rust, no_run fn Demo(cx: Scope) -> Element { // don't worry about these 2, we'll cover them later let name = use_state(cx, || String::from("bob")); @@ -25,4 +24,3 @@ Dioxus memoizes owned components. It uses `PartialEq` to determine if a componen > This means you can always rely on props with `PartialEq` or no props at all to act as barriers in your app. This can be extremely useful when building larger apps where properties frequently change. By moving our state into a global state management solution, we can achieve precise, surgical re-renders, improving the performance of our app. Borrowed Props cannot be safely memoized. However, this is not a problem – Dioxus relies on the memoization of their parents to determine if they need to be rerendered. - diff --git a/docs/guide/src/en/__unused/model_pattern.md b/docs/guide/src/en/__unused/model_pattern.md index e66b6981c..c9bf9f6b5 100644 --- a/docs/guide/src/en/__unused/model_pattern.md +++ b/docs/guide/src/en/__unused/model_pattern.md @@ -1,12 +1,10 @@ - - ## Using UseRef with "models" One option for state management that UseRef enables is the development of a "model" for your components. This particular pattern enables you to model your state with regular structs. For instance, our calculator example uses a struct to model the state. -```rust +```rust, no_run struct Calculator { display_value: String, @@ -18,7 +16,7 @@ struct Calculator { Our component is really simple – we just call `use_ref` to get an initial calculator state. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let state = use_ref(cx, Calculator::new); @@ -30,7 +28,7 @@ fn app(cx: Scope) -> Element { In our UI, we can then use `read` and a helper method to get data out of the model. -```rust +```rust, no_run // Our accessor method impl Calculator { fn formatted_display(&self) -> String { @@ -49,7 +47,7 @@ cx.render(rsx!{ To modify the state, we can setup a helper method and then attach it to a callback. -```rust +```rust, no_run // our helper impl Calculator { fn clear_display(&mut self) { @@ -64,4 +62,3 @@ cx.render(rsx!{ } }) ``` - diff --git a/docs/guide/src/en/async/spawn.md b/docs/guide/src/en/async/spawn.md index b29f63ebf..2f86ad159 100644 --- a/docs/guide/src/en/async/spawn.md +++ b/docs/guide/src/en/async/spawn.md @@ -2,11 +2,11 @@ The `use_future` and `use_coroutine` hooks are useful if you want to unconditionally spawn the future. Sometimes, though, you'll want to only spawn a future in response to an event, such as a mouse click. For example, suppose you need to send a request when the user clicks a "log in" button. For this, you can use `cx.spawn`: -```rust +```rust, no_run {{#include ../../../examples/spawn.rs:spawn}} ``` -> Note: `spawn` will always spawn a *new* future. You most likely don't want to call it on every render. +> Note: `spawn` will always spawn a _new_ future. You most likely don't want to call it on every render. Calling `spawn` will give you a `JoinHandle` which lets you cancel or pause the future. @@ -14,6 +14,6 @@ Calling `spawn` will give you a `JoinHandle` which lets you cancel or pause the Sometimes, you might want to spawn a background task that needs multiple threads or talk to hardware that might block your app code. In these cases, we can directly spawn a Tokio task from our future. For Dioxus-Desktop, your task will be spawned onto Tokio's Multithreaded runtime: -```rust +```rust, no_run {{#include ../../../examples/spawn.rs:tokio}} ``` diff --git a/docs/guide/src/en/async/use_coroutine.md b/docs/guide/src/en/async/use_coroutine.md index 537e27ea4..8d4b8f99a 100644 --- a/docs/guide/src/en/async/use_coroutine.md +++ b/docs/guide/src/en/async/use_coroutine.md @@ -8,7 +8,7 @@ Like regular futures, code in a coroutine will run until the next `await` point The `use_coroutine` hook allows you to create a coroutine. Most coroutines we write will be polling loops using async/await. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let ws: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // Connect to some sort of service @@ -26,7 +26,7 @@ For many services, a simple async loop will handle the majority of use cases. However, if we want to temporarily disable the coroutine, we can "pause" it using the `pause` method, and "resume" it using the `resume` method: -```rust +```rust, no_run let sync: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // code for syncing }); @@ -58,7 +58,7 @@ The future must be `'static` – so any values captured by the task cannot carry You can use [to_owned](https://doc.rust-lang.org/std/borrow/trait.ToOwned.html#tymethod.to_owned) to create a clone of the hook handle which can be moved into the async closure. -```rust +```rust, no_run let sync_status = use_state(cx, || Status::Launching); let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { let sync_status = sync_status.to_owned(); @@ -73,7 +73,7 @@ let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { To make this a bit less verbose, Dioxus exports the `to_owned!` macro which will create a binding as shown above, which can be quite helpful when dealing with many values. -```rust +```rust, no_run let sync_status = use_state(cx, || Status::Launching); let load_status = use_state(cx, || Status::Launching); let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { @@ -88,10 +88,9 @@ let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { You might've noticed the `use_coroutine` closure takes an argument called `rx`. What is that? Well, a common pattern in complex apps is to handle a bunch of async code at once. With libraries like Redux Toolkit, managing multiple promises at once can be challenging and a common source of bugs. -With Coroutines, we can centralize our async logic. The `rx` parameter is an Channel that allows code external to the coroutine to send data *into* the coroutine. Instead of looping on an external service, we can loop on the channel itself, processing messages from within our app without needing to spawn a new future. To send data into the coroutine, we would call "send" on the handle. +With Coroutines, we can centralize our async logic. The `rx` parameter is an Channel that allows code external to the coroutine to send data _into_ the coroutine. Instead of looping on an external service, we can loop on the channel itself, processing messages from within our app without needing to spawn a new future. To send data into the coroutine, we would call "send" on the handle. - -```rust +```rust, no_run use futures_util::stream::StreamExt; enum ProfileUpdate { @@ -119,13 +118,11 @@ cx.render(rsx!{ }) ``` - > Note: In order to use/run the `rx.next().await` statement you will need to extend the [`Stream`] trait (used by [`UnboundedReceiver`]) by adding 'futures_util' as a dependency to your project and adding the `use futures_util::stream::StreamExt;`. - For sufficiently complex apps, we could build a bunch of different useful "services" that loop on channels to update the app. -```rust +```rust, no_run let profile = use_coroutine(cx, profile_service); let editor = use_coroutine(cx, editor_service); let sync = use_coroutine(cx, sync_service); @@ -143,9 +140,9 @@ async fn editor_service(rx: UnboundedReceiver) { } ``` -We can combine coroutines with [Fermi](https://docs.rs/fermi/latest/fermi/index.html) to emulate Redux Toolkit's Thunk system with much less headache. This lets us store all of our app's state *within* a task and then simply update the "view" values stored in Atoms. It cannot be understated how powerful this technique is: we get all the perks of native Rust tasks with the optimizations and ergonomics of global state. This means your *actual* state does not need to be tied up in a system like Fermi or Redux – the only Atoms that need to exist are those that are used to drive the display/UI. +We can combine coroutines with [Fermi](https://docs.rs/fermi/latest/fermi/index.html) to emulate Redux Toolkit's Thunk system with much less headache. This lets us store all of our app's state _within_ a task and then simply update the "view" values stored in Atoms. It cannot be understated how powerful this technique is: we get all the perks of native Rust tasks with the optimizations and ergonomics of global state. This means your _actual_ state does not need to be tied up in a system like Fermi or Redux – the only Atoms that need to exist are those that are used to drive the display/UI. -```rust +```rust, no_run static USERNAME: Atom = |_| "default".to_string(); fn app(cx: Scope) -> Element { @@ -169,7 +166,7 @@ fn Banner(cx: Scope) -> Element { Now, in our sync service, we can structure our state however we want. We only need to update the view values when ready. -```rust +```rust, no_run use futures_util::stream::StreamExt; enum SyncAction { @@ -198,7 +195,7 @@ async fn sync_service(mut rx: UnboundedReceiver, atoms: AtomRoot) { Coroutine handles are automatically injected through the context API. You can use the `use_coroutine_handle` hook with the message type as a generic to fetch a handle. -```rust +```rust, no_run fn Child(cx: Scope) -> Element { let sync_task = use_coroutine_handle::(cx); diff --git a/docs/guide/src/en/async/use_future.md b/docs/guide/src/en/async/use_future.md index 864dd5acb..c7b262c61 100644 --- a/docs/guide/src/en/async/use_future.md +++ b/docs/guide/src/en/async/use_future.md @@ -4,21 +4,20 @@ For example, we can make an API request (using [reqwest](https://docs.rs/reqwest/latest/reqwest/index.html)) inside `use_future`: -```rust +```rust, no_run {{#include ../../../examples/use_future.rs:use_future}} ``` The code inside `use_future` will be submitted to the Dioxus scheduler once the component has rendered. -We can use `.value()` to get the result of the future. On the first run, since there's no data ready when the component loads, its value will be `None`. However, once the future is finished, the component will be re-rendered and the value will now be `Some(...)`, containing the return value of the closure. +We can use `.value()` to get the result of the future. On the first run, since there's no data ready when the component loads, its value will be `None`. However, once the future is finished, the component will be re-rendered and the value will now be `Some(...)`, containing the return value of the closure. We can then render that result: -```rust +```rust, no_run {{#include ../../../examples/use_future.rs:render}} ``` - ## Restarting the Future The `UseFuture` handle provides a `restart` method. It can be used to execute the future again, producing a new value. @@ -27,7 +26,6 @@ The `UseFuture` handle provides a `restart` method. It can be used to execute th Often, you will need to run the future again every time some value (e.g. a prop) changes. Rather than calling `restart` manually, you can provide a tuple of "dependencies" to the hook. It will automatically re-run the future when any of those dependencies change. Example: - -```rust +```rust, no_run {{#include ../../../examples/use_future.rs:dependency}} ``` diff --git a/docs/guide/src/en/best_practices/antipatterns.md b/docs/guide/src/en/best_practices/antipatterns.md index 873af6e39..771ffe75f 100644 --- a/docs/guide/src/en/best_practices/antipatterns.md +++ b/docs/guide/src/en/best_practices/antipatterns.md @@ -8,7 +8,7 @@ Fragments don't mount a physical element to the DOM immediately, so Dioxus must Only Component and Fragment nodes are susceptible to this issue. Dioxus mitigates this with components by providing an API for registering shared state without the Context Provider pattern. -```rust +```rust, no_run {{#include ../../../examples/anti_patterns.rs:nested_fragments}} ``` @@ -16,7 +16,7 @@ Only Component and Fragment nodes are susceptible to this issue. Dioxus mitigate As described in the [dynamic rendering chapter](../interactivity/dynamic_rendering.md#the-key-attribute), list items must have unique keys that are associated with the same items across renders. This helps Dioxus associate state with the contained components and ensures good diffing performance. Do not omit keys, unless you know that the list will never change. -```rust +```rust, no_run {{#include ../../../examples/anti_patterns.rs:iter_keys}} ``` @@ -30,4 +30,4 @@ Suppose you have a struct `User` containing the field `username: String`. If you Every time you update the state, Dioxus needs to re-render the component – this is inefficient! Consider refactoring your code to avoid this. -Also, if you unconditionally update the state during render, it will be re-rendered in an infinite loop. \ No newline at end of file +Also, if you unconditionally update the state during render, it will be re-rendered in an infinite loop. diff --git a/docs/guide/src/en/best_practices/error_handling.md b/docs/guide/src/en/best_practices/error_handling.md index afbb45417..fad8f1c10 100644 --- a/docs/guide/src/en/best_practices/error_handling.md +++ b/docs/guide/src/en/best_practices/error_handling.md @@ -4,23 +4,21 @@ A selling point of Rust for web development is the reliability of always knowing However, we haven't talked about error handling at all in this guide! In this chapter, we'll cover some strategies in handling errors to ensure your app never crashes. - - ## The simplest – returning None Astute observers might have noticed that `Element` is actually a type alias for `Option`. You don't need to know what a `VNode` is, but it's important to recognize that we could actually return nothing at all: -```rust +```rust, no_run fn App(cx: Scope) -> Element { None } ``` -This lets us add in some syntactic sugar for operations we think *shouldn't* fail, but we're still not confident enough to "unwrap" on. +This lets us add in some syntactic sugar for operations we think _shouldn't_ fail, but we're still not confident enough to "unwrap" on. > The nature of `Option` might change in the future as the `try` trait gets upgraded. -```rust +```rust, no_run fn App(cx: Scope) -> Element { // immediately return "None" let name = cx.use_hook(|_| Some("hi"))?; @@ -31,7 +29,7 @@ fn App(cx: Scope) -> Element { Because Rust can't accept both Options and Results with the existing try infrastructure, you'll need to manually handle Results. This can be done by converting them into Options or by explicitly handling them. -```rust +```rust, no_run fn App(cx: Scope) -> Element { // Convert Result to Option let name = cx.use_hook(|_| "1.234").parse().ok()?; @@ -46,8 +44,7 @@ fn App(cx: Scope) -> Element { } ``` -Notice that while hooks in Dioxus do not like being called in conditionals or loops, they *are* okay with early returns. Returning an error state early is a completely valid way of handling errors. - +Notice that while hooks in Dioxus do not like being called in conditionals or loops, they _are_ okay with early returns. Returning an error state early is a completely valid way of handling errors. ## Match results @@ -55,14 +52,13 @@ The next "best" way of handling errors in Dioxus is to match on the error locall To do this, we simply have an error state built into our component: -```rust +```rust, no_run let err = use_state(cx, || None); ``` Whenever we perform an action that generates an error, we'll set that error state. We can then match on the error in a number of ways (early return, return Element, etc). - -```rust +```rust, no_run fn Commandline(cx: Scope) -> Element { let error = use_state(cx, || None); @@ -83,7 +79,7 @@ fn Commandline(cx: Scope) -> Element { If you're dealing with a handful of components with minimal nesting, you can just pass the error handle into child components. -```rust +```rust, no_run fn Commandline(cx: Scope) -> Element { let error = use_state(cx, || None); @@ -110,8 +106,7 @@ To get started, consider using a built-in hook like `use_context` and `use_conte At the "top" of our architecture, we're going to want to explicitly declare a value that could be an error. - -```rust +```rust, no_run enum InputError { None, TooLong, @@ -123,7 +118,7 @@ static INPUT_ERROR: Atom = |_| InputError::None; Then, in our top level component, we want to explicitly handle the possible error state for this part of the tree. -```rust +```rust, no_run fn TopLevel(cx: Scope) -> Element { let error = use_read(cx, INPUT_ERROR); @@ -137,7 +132,7 @@ fn TopLevel(cx: Scope) -> Element { Now, whenever a downstream component has an error in its actions, it can simply just set its own error state: -```rust +```rust, no_run fn Commandline(cx: Scope) -> Element { let set_error = use_set(cx, INPUT_ERROR); diff --git a/docs/guide/src/en/contributing/guiding_principles.md b/docs/guide/src/en/contributing/guiding_principles.md new file mode 100644 index 000000000..5c730d622 --- /dev/null +++ b/docs/guide/src/en/contributing/guiding_principles.md @@ -0,0 +1,37 @@ +# Overall Goals + +This document outlines some of the overall goals for Dioxus. These goals are not set in stone, but they represent general guidelines for the project. + +The goal of Dioxus is to make it easy to build **cross-platform applications that scale**. + +## Cross-Platform + +Dioxus is designed to be cross-platform by default. This means that it should be easy to build applications that run on the web, desktop, and mobile. However, Dioxus should also be flexible enough to allow users to opt into platform-specific features when needed. The `use_eval` is one example of this. By default, Dioxus does not assume that the platform supports JavaScript, but it does provide a hook that allows users to opt into JavaScript when needed. + +## Performance + +As Dioxus applications grow, they should remain relatively performant without the need for manual optimizations. There will be cases where manual optimizations are needed, but Dioxus should try to make these cases as rare as possible. + +One of the benefits of the core architecture of Dioxus is that it delivers reasonable performance even when components are rerendered often. It is based on a Virtual Dom which performs diffing which should prevent unnecessary re-renders even when large parts of the component tree are rerun. On top of this, Dioxus groups static parts of the RSX tree together to skip diffing them entirely. + +## Type Safety + +As teams grow, the Type safety of Rust is a huge advantage. Dioxus should leverage this advantage to make it easy to build applications with large teams. + +To take full advantage of Rust's type system, Dioxus should try to avoid exposing public `Any` types and string-ly typed APIs where possible. + +## Developer Experience + +Dioxus should be easy to learn and ergonomic to use. + +- The API of Dioxus attempts to remain close to React's API where possible. This makes it easier for people to learn Dioxus if they already know React + +- We can avoid the tradeoff between simplicity and flexibility by providing multiple layers of API: One for the very common use case, one for low-level control + + - Hooks: the hooks crate has the most common use cases, but `cx.hook` provides a way to access the underlying persistent reference if needed. + - The builder pattern in platform Configs: The builder pattern is used to default to the most common use case, but users can change the defaults if needed. + +- Documentation: + - All public APIs should have rust documentation + - Examples should be provided for all public features. These examples both serve as documentation and testing. They are checked by CI to ensure that they continue to compile + - The most common workflows should be documented in the guide diff --git a/docs/guide/src/en/contributing.md b/docs/guide/src/en/contributing/index.md similarity index 54% rename from docs/guide/src/en/contributing.md rename to docs/guide/src/en/contributing/index.md index 35efa11ac..0e37db2ad 100644 --- a/docs/guide/src/en/contributing.md +++ b/docs/guide/src/en/contributing/index.md @@ -10,7 +10,7 @@ If you'd like to improve the docs, PRs are welcome! Both Rust docs ([source](htt ## Working on the Ecosystem -Part of what makes React great is the rich ecosystem. We'd like the same for Dioxus! So if you have a library in mind that you'd like to write and many people would benefit from, it will be appreciated. You can [browse npm.js](https://www.npmjs.com/search?q=keywords:react-component) for inspiration. +Part of what makes React great is the rich ecosystem. We'd like the same for Dioxus! So if you have a library in mind that you'd like to write and many people would benefit from, it will be appreciated. You can [browse npm.js](https://www.npmjs.com/search?q=keywords:react-component) for inspiration. Once you are done, add your library to the [awesome dioxus](https://github.com/DioxusLabs/awesome-dioxus) list or share it in the `#I-made-a-thing` channel on [Discord](https://discord.gg/XgGxMSkvUM). ## Bugs & Features @@ -18,3 +18,34 @@ If you've fixed [an open issue](https://github.com/DioxusLabs/dioxus/issues), fe All pull requests (including those made by a team member) must be approved by at least one other team member. Larger, more nuanced decisions about design, architecture, breaking changes, trade-offs, etc. are made by team consensus. + +## Tools + +The following tools can be helpful when developing Dioxus. Many of these tools are used in the CI pipeline. Running them locally before submitting a PR instead of waiting for CI can save time. + +- All code is tested with [cargo test](https://doc.rust-lang.org/cargo/commands/cargo-test.html) + +```sh +cargo fmt --all +``` + +- All code is formatted with [rustfmt](https://github.com/rust-lang/rustfmt) + +```sh +cargo check --workspace --examples --tests +``` + +- All code is linted with [Clippy](https://doc.rust-lang.org/clippy/) + +```sh +cargo clippy --workspace --examples --tests -- -D warnings +``` + +- Crates that use unsafe are checked for undefined behavior with [MIRI](https://github.com/rust-lang/miri). MIRI can be helpful to debug what unsafe code is causing issues. Only code that does not interact with system calls can be checked with MIRI. Currently, this is used for the two MIRI tests in `dioxus-core` and `dioxus-native-core`. + +```sh +cargo miri test --package dioxus-core --test miri_stress +cargo miri test --package dioxus-native-core --test miri_native +``` + +- [Rust analyzer](https://rust-analyzer.github.io/) can be very helpful for quick feedback in your IDE. diff --git a/docs/guide/src/en/contributing/project_structure.md b/docs/guide/src/en/contributing/project_structure.md new file mode 100644 index 000000000..0f4fa64c8 --- /dev/null +++ b/docs/guide/src/en/contributing/project_structure.md @@ -0,0 +1,50 @@ +# Project Struture + +There are many packages in the Dioxus organization. This document will help you understand the purpose of each package and how they fit together. + +## Renderers + +- [Desktop](https://github.com/DioxusLabs/dioxus/tree/master/packages/desktop): A Render that Runs Dioxus applications natively, but renders them with the system webview +- [Mobile](https://github.com/DioxusLabs/dioxus/tree/master/packages/mobile): A Render that Runs Dioxus applications natively, but renders them with the system webview. This is currently a copy of the desktop render +- [Web](https://github.com/DioxusLabs/dioxus/tree/master/packages/Web): Renders Dioxus applications in the browser by compiling to WASM and manipulating the DOM +- [Liveview](https://github.com/DioxusLabs/dioxus/tree/master/packages/liveview): A Render that Runs on the server, and renders using a websocket proxy in the browser +- [Rink](https://github.com/DioxusLabs/dioxus/tree/master/packages/rink): A Renderer that renders a HTML-like tree into a terminal +- [TUI](https://github.com/DioxusLabs/dioxus/tree/master/packages/dioxus-tui): A Renderer that uses Rink to render a Dioxus application in a terminal +- [Blitz-Core](https://github.com/DioxusLabs/blitz/tree/master/blitz-core): An experimental native renderer that renders a HTML-like tree using WGPU. +- [Blitz](https://github.com/DioxusLabs/blitz): An experimental native renderer that uses Blitz-Core to render a Dioxus application using WGPU. +- [SSR](https://github.com/DioxusLabs/dioxus/tree/master/packages/ssr): A Render that Runs Dioxus applications on the server, and renders them to HTML + +## State Management/Hooks + +- [Hooks](https://github.com/DioxusLabs/dioxus/tree/master/packages/hooks): A collection of common hooks for Dioxus applications +- [Signals](https://github.com/DioxusLabs/dioxus/tree/master/packages/signals): A experimental state management library for Dioxus applications. This currently contains a `Copy` version of UseRef +- [Dioxus STD](https://github.com/DioxusLabs/dioxus-std): A collection of platform agnostic hooks to interact with system interfaces (The clipboard, camera, etc.). +- [Fermi](https://github.com/DioxusLabs/dioxus/tree/master/packages/fermi): A global state management library for Dioxus applications. + [Router](https://github.com/DioxusLabs/dioxus/tree/master/packages/router): A client-side router for Dioxus applications + +## Core utilities + +- [core](https://github.com/DioxusLabs/dioxus/tree/master/packages/core): The core virtual dom implementation every Dioxus application uses + - You can read more about the archetecture of the core [in this blog post](https://dioxuslabs.com/blog/templates-diffing/) and the [custom renderer section of the guide](../custom_renderer/index.md) +- [RSX](https://github.com/DioxusLabs/dioxus/tree/master/packages/RSX): The core parsing for RSX used for hot reloading, autoformatting, and the macro +- [core-macro](https://github.com/DioxusLabs/dioxus/tree/master/packages/core-macro): The rsx! macro used to write Dioxus applications. (This is a wrapper over the RSX crate) +- [HTML macro](https://github.com/DioxusLabs/dioxus-html-macro): A html-like alternative to the RSX macro + +## Native Renderer Utilities + +- [native-core](https://github.com/DioxusLabs/dioxus/tree/master/packages/native-core): Incrementally computed tree of states (mostly styles) + - You can read more about how native-core can help you build native renderers in the [custom renderer section of the guide](../custom_renderer/index.html#native-core) +- [native-core-macro](https://github.com/DioxusLabs/dioxus/tree/master/packages/native-core-macro): A helper macro for native core +- [Taffy](https://github.com/DioxusLabs/taffy): Layout engine powering Blitz-Core, Rink, and Bevy UI + +## Web renderer tooling + +- [HTML](https://github.com/DioxusLabs/dioxus/tree/master/packages/html): defines html specific elements, events, and attributes +- [Interpreter](https://github.com/DioxusLabs/dioxus/tree/master/packages/interpreter): defines browser bindings used by the web and desktop renderers + +## Developer tooling + +- [hot-reload](https://github.com/DioxusLabs/dioxus/tree/master/packages/hot-reload): Macro that uses the RSX crate to hot reload static parts of any rsx! macro. This macro works with any non-web renderer with an [integration](https://crates.io/crates/dioxus-hot-reload) +- [autofmt](https://github.com/DioxusLabs/dioxus/tree/master/packages/autofmt): Formats RSX code +- [rsx-rosetta](https://github.com/DioxusLabs/dioxus/tree/master/packages/RSX-rosetta): Handles conversion between HTML and RSX +- [CLI](https://github.com/DioxusLabs/cli): A Command Line Interface and VSCode extension to assist with Dioxus usage diff --git a/docs/guide/src/en/roadmap.md b/docs/guide/src/en/contributing/roadmap.md similarity index 53% rename from docs/guide/src/en/roadmap.md rename to docs/guide/src/en/contributing/roadmap.md index 5e7318de9..fba5913db 100644 --- a/docs/guide/src/en/roadmap.md +++ b/docs/guide/src/en/contributing/roadmap.md @@ -17,53 +17,55 @@ Generally, here's the status of each platform: - **LiveView**: LiveView support is very young. You'll be figuring things out as you go. Thankfully, none of it is too hard and any work can be upstreamed into Dioxus. ## Features + --- | Feature | Status | Description | | ------------------------- | ------ | -------------------------------------------------------------------- | -| Conditional Rendering | ✅ | if/then to hide/show component | -| Map, Iterator | ✅ | map/filter/reduce to produce rsx! | -| Keyed Components | ✅ | advanced diffing with keys | -| Web | ✅ | renderer for web browser | -| Desktop (webview) | ✅ | renderer for desktop | -| Shared State (Context) | ✅ | share state through the tree | -| Hooks | ✅ | memory cells in components | -| SSR | ✅ | render directly to string | -| Component Children | ✅ | cx.children() as a list of nodes | -| Headless components | ✅ | components that don't return real elements | -| Fragments | ✅ | multiple elements without a real root | -| Manual Props | ✅ | Manually pass in props with spread syntax | -| Controlled Inputs | ✅ | stateful wrappers around inputs | -| CSS/Inline Styles | ✅ | syntax for inline styles/attribute groups | -| Custom elements | ✅ | Define new element primitives | -| Suspense | ✅ | schedule future render from future/promise | -| Integrated error handling | ✅ | Gracefully handle errors with ? syntax | -| NodeRef | ✅ | gain direct access to nodes | -| Re-hydration | ✅ | Pre-render to HTML to speed up first contentful paint | -| Jank-Free Rendering | ✅ | Large diffs are segmented across frames for silky-smooth transitions | -| Effects | ✅ | Run effects after a component has been committed to render | +| Conditional Rendering | ✅ | if/then to hide/show component | +| Map, Iterator | ✅ | map/filter/reduce to produce rsx! | +| Keyed Components | ✅ | advanced diffing with keys | +| Web | ✅ | renderer for web browser | +| Desktop (webview) | ✅ | renderer for desktop | +| Shared State (Context) | ✅ | share state through the tree | +| Hooks | ✅ | memory cells in components | +| SSR | ✅ | render directly to string | +| Component Children | ✅ | cx.children() as a list of nodes | +| Headless components | ✅ | components that don't return real elements | +| Fragments | ✅ | multiple elements without a real root | +| Manual Props | ✅ | Manually pass in props with spread syntax | +| Controlled Inputs | ✅ | stateful wrappers around inputs | +| CSS/Inline Styles | ✅ | syntax for inline styles/attribute groups | +| Custom elements | ✅ | Define new element primitives | +| Suspense | ✅ | schedule future render from future/promise | +| Integrated error handling | ✅ | Gracefully handle errors with ? syntax | +| NodeRef | ✅ | gain direct access to nodes | +| Re-hydration | ✅ | Pre-render to HTML to speed up first contentful paint | +| Jank-Free Rendering | ✅ | Large diffs are segmented across frames for silky-smooth transitions | +| Effects | ✅ | Run effects after a component has been committed to render | | Portals | 🛠 | Render nodes outside of the traditional tree structure | | Cooperative Scheduling | 🛠 | Prioritize important events over non-important events | | Server Components | 🛠 | Hybrid components for SPA and Server | -| Bundle Splitting | 👀 | Efficiently and asynchronously load the app | -| Lazy Components | 👀 | Dynamically load the new components as the page is loaded | -| 1st class global state | ✅ | redux/recoil/mobx on top of context | -| Runs natively | ✅ | runs as a portable binary w/o a runtime (Node) | -| Subtree Memoization | ✅ | skip diffing static element subtrees | -| High-efficiency templates | ✅ | rsx! calls are translated to templates on the DOM's side | -| Compile-time correct | ✅ | Throw errors on invalid template layouts | -| Heuristic Engine | ✅ | track component memory usage to minimize future allocations | -| Fine-grained reactivity | 👀 | Skip diffing for fine-grain updates | +| Bundle Splitting | 👀 | Efficiently and asynchronously load the app | +| Lazy Components | 👀 | Dynamically load the new components as the page is loaded | +| 1st class global state | ✅ | redux/recoil/mobx on top of context | +| Runs natively | ✅ | runs as a portable binary w/o a runtime (Node) | +| Subtree Memoization | ✅ | skip diffing static element subtrees | +| High-efficiency templates | ✅ | rsx! calls are translated to templates on the DOM's side | +| Compile-time correct | ✅ | Throw errors on invalid template layouts | +| Heuristic Engine | ✅ | track component memory usage to minimize future allocations | +| Fine-grained reactivity | 👀 | Skip diffing for fine-grain updates | - ✅ = implemented and working - 🛠 = actively being worked on - 👀 = not yet implemented or being worked on - ## Roadmap + These Features are planned for the future of Dioxus: ### Core + - [x] Release of Dioxus Core - [x] Upgrade documentation to include more theory and be more comprehensive - [x] Support for HTML-side templates for lightning-fast dom manipulation @@ -72,16 +74,18 @@ These Features are planned for the future of Dioxus: - [ ] Support for Portals ### SSR + - [x] SSR Support + Hydration - [ ] Integrated suspense support for SSR ### Desktop + - [ ] Declarative window management - [ ] Templates for building/bundling -- [ ] Fully native renderer - [ ] Access to Canvas/WebGL context natively ### Mobile + - [ ] Mobile standard library - [ ] GPS - [ ] Camera @@ -92,9 +96,9 @@ These Features are planned for the future of Dioxus: - [ ] Notifications - [ ] Clipboard - [ ] Animations -- [ ] Native Renderer ### Bundling (CLI) + - [x] Translation from HTML into RSX - [x] Dev server - [x] Live reload @@ -106,11 +110,11 @@ These Features are planned for the future of Dioxus: - [ ] Image pipeline ### Essential hooks + - [x] Router - [x] Global state management - [ ] Resize observer - ## Work in Progress ### Build Tool diff --git a/docs/guide/src/en/contributing/walkthrough_readme.md b/docs/guide/src/en/contributing/walkthrough_readme.md new file mode 100644 index 000000000..5334630c9 --- /dev/null +++ b/docs/guide/src/en/contributing/walkthrough_readme.md @@ -0,0 +1,126 @@ +# Walkthrough of the Hello World Example Internals + +This walkthrough will take you through the internals of the Hello World example program. It will explain how major parts of Dioxus internals interact with each other to take the readme example from a source file to a running application. This guide should serve as a high-level overview of the internals of Dioxus. It is not meant to be a comprehensive guide. + +## The Source File + +We start will a hello world program. This program renders a desktop app with the text "Hello World" in a webview. + +```rust, no_run +{{#include ../../../../../examples/readme.rs}} +``` + +[![](https://mermaid.ink/img/pako:eNqNkT1vwyAQhv8KvSlR48HphtQtqjK0S6tuSBGBS0CxwcJHk8rxfy_YVqxKVdR3ug_u4YXrQHmNwOFQ-bMyMhB7fReOJbVxfwyyMSy0l7GSpW1ARda727ksUy5MuSyKgvBC5ULA1h5N8WK_kCkfHWHgrBuiXsBynrvdsY9E3u1iM_eyvFOVVadMnELOap-o1911JLPHZ1b-YqLTc3LjTt7WifTZMJPsPdx1ov3Z_ellfcdL8R8vmTy5eUqsTUpZ-vzZzjAEK6gx1NLqtJwuNwSQwRoF8BRqGU4ChOvTORnJf3w7BZxCxBXERkvCjZXpQTXwg6zaVEVtyYe3cdvD0vsf4bucgw?type=png)](https://mermaid.live/edit#pako:eNqNkT1vwyAQhv8KvSlR48HphtQtqjK0S6tuSBGBS0CxwcJHk8rxfy_YVqxKVdR3ug_u4YXrQHmNwOFQ-bMyMhB7fReOJbVxfwyyMSy0l7GSpW1ARda727ksUy5MuSyKgvBC5ULA1h5N8WK_kCkfHWHgrBuiXsBynrvdsY9E3u1iM_eyvFOVVadMnELOap-o1911JLPHZ1b-YqLTc3LjTt7WifTZMJPsPdx1ov3Z_ellfcdL8R8vmTy5eUqsTUpZ-vzZzjAEK6gx1NLqtJwuNwSQwRoF8BRqGU4ChOvTORnJf3w7BZxCxBXERkvCjZXpQTXwg6zaVEVtyYe3cdvD0vsf4bucgw) + +## The rsx! Macro + +Before the Rust compiler runs the program, it will expand all macros. Here is what the hello world example looks like expanded: + +```rust, no_run +{{#include ../../../examples/readme_expanded.rs}} +``` + +The rsx macro separates the static parts of the rsx (the template) and the dynamic parts (the dynamic_nodes and dynamic_attributes). + +The static template only contains the parts of the rsx that cannot change at runtime with holes for the dynamic parts: + +[![](https://mermaid.ink/img/pako:eNqdksFuwjAMhl8l8wkkKtFx65njdtm0E0GVSQKJoEmVOgKEeHecUrXStO0wn5Lf9u8vcm6ggjZQwf4UzspiJPH2Ib3g6NLuELG1oiMkp0TsLs9EDu2iUeSCH8tz2HJmy3lRFPrqsXGq9mxeLzcbCU6LZSUGXWRdwnY7tY7Tdoko-Dq1U64fODgiUfzJMeuOe7_ZGq-ny2jNhGQu9DqT8NUK6w72RcL8dxgdzv4PnHLAKf-Fk80HoBUDrfkqeBkTUd8EC2hMbNBpXtYtJySQNQ0PqPioMR4lSH_nOkwUPq9eQUUxmQWkViOZtUN-UwPVHk8dq0Y7CvH9uf3-E9wfrmuk1A?type=png)](https://mermaid.live/edit#pako:eNqdksFuwjAMhl8l8wkkKtFx65njdtm0E0GVSQKJoEmVOgKEeHecUrXStO0wn5Lf9u8vcm6ggjZQwf4UzspiJPH2Ib3g6NLuELG1oiMkp0TsLs9EDu2iUeSCH8tz2HJmy3lRFPrqsXGq9mxeLzcbCU6LZSUGXWRdwnY7tY7Tdoko-Dq1U64fODgiUfzJMeuOe7_ZGq-ny2jNhGQu9DqT8NUK6w72RcL8dxgdzv4PnHLAKf-Fk80HoBUDrfkqeBkTUd8EC2hMbNBpXtYtJySQNQ0PqPioMR4lSH_nOkwUPq9eQUUxmQWkViOZtUN-UwPVHk8dq0Y7CvH9uf3-E9wfrmuk1A) + +The dynamic_nodes and dynamic_attributes are the parts of the rsx that can change at runtime: + +[![](https://mermaid.ink/img/pako:eNp1UcFOwzAM_RXLVzZpvUbighDiABfgtkxTlnirtSaZUgc0df130hZEEcwny35-79nu0EZHqHDfxA9bmyTw9KIDlGjz7pDMqQZ3DsazhVCQ7dQbwnEiKxwDvN3NqhN4O4C3q_VaIztYKXjkQ7184HcCG3MQSgq6Mes1bjbTPAV3RdqIJN5l-V__2_Fcf5iY68dgG7ZHBT4WD5ftZfIBN7dQ_Tj4w1B9MVTXGZa_GMYdcIGekjfsymW7oaFRavKkUZXUmXTUqENfcCZLfD0Hi0pSpgXmkzNC92zKATyqvWnaUiXHEtPz9KrxY_0nzYOPmA?type=png)](https://mermaid.live/edit#pako:eNp1UcFOwzAM_RXLVzZpvUbighDiABfgtkxTlnirtSaZUgc0df130hZEEcwny35-79nu0EZHqHDfxA9bmyTw9KIDlGjz7pDMqQZ3DsazhVCQ7dQbwnEiKxwDvN3NqhN4O4C3q_VaIztYKXjkQ7184HcCG3MQSgq6Mes1bjbTPAV3RdqIJN5l-V__2_Fcf5iY68dgG7ZHBT4WD5ftZfIBN7dQ_Tj4w1B9MVTXGZa_GMYdcIGekjfsymW7oaFRavKkUZXUmXTUqENfcCZLfD0Hi0pSpgXmkzNC92zKATyqvWnaUiXHEtPz9KrxY_0nzYOPmA) + +## Launching the App + +The app is launched by calling the `launch` function with the root component. Internally, this function will create a new web view using [wry](https://docs.rs/wry/latest/wry/) and create a virtual dom with the root component. This guide will not explain the renderer in-depth, but you can read more about it in the [custom renderer](/guide/custom-renderer) section. + +## The Virtual DOM + +Before we dive into the initial render in the virtual dom, we need to discuss what the virtual dom is. The virtual dom is a representation of the dom that is used to diff the current dom from the new dom. This diff is then used to create a list of mutations that need to be applied to the dom. + +The Virtual Dom roughly looks like this: + +```rust, no_run +pub struct VirtualDom { + // All the templates that have been created or set durring hot reloading + pub(crate) templates: FxHashMap>>, + + // A slab of all the scopes that have been created + pub(crate) scopes: ScopeSlab, + + // All scopes that have been marked as dirty + pub(crate) dirty_scopes: BTreeSet, + + // Every element is actually a dual reference - one to the template and the other to the dynamic node in that template + pub(crate) elements: Slab, + + // This receiver is used to receive messages from hooks about what scopes need to be marked as dirty + pub(crate) rx: futures_channel::mpsc::UnboundedReceiver, + + // The changes queued up to be sent to the renderer + pub(crate) mutations: Mutations<'static>, +} +``` + +> What is a [slab](https://docs.rs/slab/latest/slab/)? +> A slab acts like a hashmap with integer keys if you don't care about the value of the keys. It is internally backed by a dense vector which makes it more efficient than a hashmap. When you insert a value into a slab, it returns an integer key that you can use to retrieve the value later. + +> How does Dioxus use slabs? +> Dioxus uses "synchronized slabs" to communicate between the renderer and the VDOM. When an node is created in the Virtual Dom, a ElementId is passed along with the mutation to the renderer to identify the node. These ids are used by the Virtual Dom to reference that nodes in future mutations like setting an attribute on a node or removing a node. +> When the renderer sends an event to the Virtual Dom, it sends the ElementId of the node that the event was triggered on. The Virtual Dom uses this id to find the node in the slab and then run the necessary event handlers. + +The virtual dom is a tree of scopes. A new scope is created for every component when it is first rendered and recycled when the component is unmounted. + +Scopes serve three main purposes: + +1. They store the state of hooks used by the component +2. They store the state for the context API +3. They store the current and previous VNode that was rendered for diffing + +### The Initial Render + +The root scope is created and rebuilt: + +1. The root component is run +2. The root component returns a VNode +3. Mutations for the VNode are created and added to the mutation list (this may involve creating new child components) +4. The VNode is stored in the root scope + +After the root scope is built, the mutations are sent to the renderer to be applied to the dom. + +After the initial render, the root scope looks like this: + +[![](https://mermaid.ink/img/pako:eNqtVE1P4zAQ_SuzPrWikRpWXCLtBRDisItWsOxhCaqM7RKricdyJrQV8N93QtvQNCkfEnOynydv3nxkHoVCbUQipjnOVSYDwc_L1AFbWd3dB-kzuEQkuFLoDUwDFkCZAek9nGDh0RlHK__atA1GkUUHf45f0YbppAqB_aOzIAvz-t7-chN_Y-1bw1WSJKsglIu2w9tktWXxIIuHURT5XCqTYa5NmDguw2R8c5MKq2GcgF46WTB_jafi9rZL0yi5q4jQTSrf9altO4okCn1Ratwyz55Qxuku2ITlTMgs6HCQimsPmb3PvqVi-L5gjXP3QcnxWnL8JZLrwGvR31n0KV-Bx6-r-oVkT_-3G1S-NQLbk9i8rj7udP2cixed2QcDCitHJiQw7ub3EVlNecrPjudG2-6soFO5VbMECmR9T5OnlUY4-AFxfw9aTFst3McU9TK1Otm6NEn_DubBYlX2_dglLXOz48FgwJmJ5lZTlhz6xWgNaFnyDgpymcARHO0W2a9J_l5w2wYXvHuGPcqaQ-rESBQmFNJq3nCPNZoK3l4sUSR81DLMUpG6Z_aTFeHV0imRUKjMSFReSzKnVnKGhUimMi8ZNdoShl-rlfmyOUfCS_cPcePz_B_Wl4pc?type=png)](https://mermaid.live/edit#pako:eNqtVE1P4zAQ_SuzPrWikRpWXCLtBRDisItWsOxhCaqM7RKricdyJrQV8N93QtvQNCkfEnOynydv3nxkHoVCbUQipjnOVSYDwc_L1AFbWd3dB-kzuEQkuFLoDUwDFkCZAek9nGDh0RlHK__atA1GkUUHf45f0YbppAqB_aOzIAvz-t7-chN_Y-1bw1WSJKsglIu2w9tktWXxIIuHURT5XCqTYa5NmDguw2R8c5MKq2GcgF46WTB_jafi9rZL0yi5q4jQTSrf9altO4okCn1Ratwyz55Qxuku2ITlTMgs6HCQimsPmb3PvqVi-L5gjXP3QcnxWnL8JZLrwGvR31n0KV-Bx6-r-oVkT_-3G1S-NQLbk9i8rj7udP2cixed2QcDCitHJiQw7ub3EVlNecrPjudG2-6soFO5VbMECmR9T5OnlUY4-AFxfw9aTFst3McU9TK1Otm6NEn_DubBYlX2_dglLXOz48FgwJmJ5lZTlhz6xWgNaFnyDgpymcARHO0W2a9J_l5w2wYXvHuGPcqaQ-rESBQmFNJq3nCPNZoK3l4sUSR81DLMUpG6Z_aTFeHV0imRUKjMSFReSzKnVnKGhUimMi8ZNdoShl-rlfmyOUfCS_cPcePz_B_Wl4pc) + +### Waiting for Events + +The Virtual Dom will only ever rerender a scope if it is marked as dirty. Each hook is responsible for marking the scope as dirty if the state has changed. Hooks can mark a scope as dirty by sending a message to the Virtual Dom's channel. + +There are generally two ways a scope is marked as dirty: + +1. The renderer triggers an event: This causes an event listener to be called if needed which may mark a component as dirty +2. The renderer calls wait for work: This polls futures which may mark a component as dirty + +Once at least one scope is marked as dirty, the renderer can call `render_with_deadline` to diff the dirty scopes. + +### Diffing Scopes + +If the user clicked the "up high" button, the root scope would be marked as dirty by the use_state hook. Once the desktop renderer calls `render_with_deadline`, the root scope would be diffed. + +To start the diffing process, the component is run. After the root component is run it will look like this: + +[![](https://mermaid.ink/img/pako:eNrFVlFP2zAQ_iuen0BrpCaIl0i8AEJ72KQJtpcRFBnbJVYTn-U4tBXw33dpG5M2CetoBfdkny_ffb67fPIT5SAkjekkhxnPmHXk-3WiCVpZ3T9YZjJyDeDIDQcjycRCQVwmCTOGXEBhQEvtVvG1CWUldwo0-XX-6vVIF5W1GB9cWVbI1_PNL5v8jW3uPFbpmFOc2HK-GfA2WG1ZeJSFx0EQmJxxmUEupE01liEd394mVAkyjolYaFYgfu1P6N1dF8Yzua-cA51WphtTWzsLc872Zan9CnEGUkktuk6fFm_i5NxFRwn9bUimHrIvCT3-N2EBM70j5XBNOTwI5TrxmvQJkr7ELcHx67Jeggz0v92g8q0RaE-iP1193On6NyxecKUeJeFQaSdtTMLu_Xah5ctT_u94Nty2ZwU0zxWfxqQA5PecPq84kq9nfRw7SK0WDiEFZ4O37d34S_-08lFBVfb92KVb5HIrAp0WpjKYKeGyODLz0dohWIkaZNkiJqfkdLvIH6oRaTSoEmm0n06k0a5K0ZdpL61Io0Yt0nfpxc7UQ0_9cJrhyZ8syX-6brS706Mc489Vjja7fbWj3cxDqIdfJJqOaCFtwZTAV8hT7U0ovjBQRmiMS8HsNKGJfsE4Vjm4WWhOY2crOaKVEczJS8WwgAWNJywv0SuFcmB_rJ41y9fNiBqm_wA0MS9_AUuAiy0?type=png)](https://mermaid.live/edit#pako:eNrFVlFP2zAQ_iuen0BrpCaIl0i8AEJ72KQJtpcRFBnbJVYTn-U4tBXw33dpG5M2CetoBfdkny_ffb67fPIT5SAkjekkhxnPmHXk-3WiCVpZ3T9YZjJyDeDIDQcjycRCQVwmCTOGXEBhQEvtVvG1CWUldwo0-XX-6vVIF5W1GB9cWVbI1_PNL5v8jW3uPFbpmFOc2HK-GfA2WG1ZeJSFx0EQmJxxmUEupE01liEd394mVAkyjolYaFYgfu1P6N1dF8Yzua-cA51WphtTWzsLc872Zan9CnEGUkktuk6fFm_i5NxFRwn9bUimHrIvCT3-N2EBM70j5XBNOTwI5TrxmvQJkr7ELcHx67Jeggz0v92g8q0RaE-iP1193On6NyxecKUeJeFQaSdtTMLu_Xah5ctT_u94Nty2ZwU0zxWfxqQA5PecPq84kq9nfRw7SK0WDiEFZ4O37d34S_-08lFBVfb92KVb5HIrAp0WpjKYKeGyODLz0dohWIkaZNkiJqfkdLvIH6oRaTSoEmm0n06k0a5K0ZdpL61Io0Yt0nfpxc7UQ0_9cJrhyZ8syX-6brS706Mc489Vjja7fbWj3cxDqIdfJJqOaCFtwZTAV8hT7U0ovjBQRmiMS8HsNKGJfsE4Vjm4WWhOY2crOaKVEczJS8WwgAWNJywv0SuFcmB_rJ41y9fNiBqm_wA0MS9_AUuAiy0) + +Next, the Virtual Dom will compare the new VNode with the previous VNode and only update the parts of the tree that have changed. + +When a component is re-rendered, the Virtual Dom will compare the new VNode with the previous VNode and only update the parts of the tree that have changed. + +The diffing algorithm goes through the list of dynamic attributes and nodes and compares them to the previous VNode. If the attribute or node has changed, a mutation that describes the change is added to the mutation list. + +Here is what the diffing algorithm looks like for the root scope (red lines indicate that a mutation was generated, and green lines indicate that no mutation was generated) + +[![](https://mermaid.ink/img/pako:eNrFlFFPwjAQx7_KpT7Kko2Elya8qCE-aGLAJ5khpe1Yw9Zbug4k4He3OJjbGPig0T5t17tf_nf777aEo5CEkijBNY-ZsfAwDjW4kxfzhWFZDGNECxOOmYTIYAo2lsCyDG4xzVBLbcv8_RHKSG4V6orSIN0Wxrh8b2RYKr_uTyubd1W92GiWKg7aac6bOU3G803HbVk82xfP_Ok0JEqAT-FeLWJvpFYSOBbaSkMhCMnra5MgtfhWFrPWqHlhL2urT6atbU-oa0PNE8WXFFJ0-nazXakRroddGk9IwYEUnCd5w7Pddr5UTT8ZuVJY5F0fM7ebRLYyXNDgUnprJWxM-9lb7xAQLHe-M2xDYQCD9pD_2hez_kVn-P_rjLq6n3qjYv2iO5qz9DyvPdyv1ETp5eTTJ_7BGvQq8v1TVtl5jXUcRRcrqFh-dI4VtFlBN6t_ynLNkh5JpUmZEm5rbvfhkLiN6H4BQt2jYGYZklC_uzxWWJxsNCfUmkL2SJEJZuWdYs4cKaERS3IXlUJZNI_lGv7cxj2SMf2CeMx5_wBcbK19?type=png)](https://mermaid.live/edit#pako:eNrFlFFPwjAQx7_KpT7Kko2Elya8qCE-aGLAJ5khpe1Yw9Zbug4k4He3OJjbGPig0T5t17tf_nf777aEo5CEkijBNY-ZsfAwDjW4kxfzhWFZDGNECxOOmYTIYAo2lsCyDG4xzVBLbcv8_RHKSG4V6orSIN0Wxrh8b2RYKr_uTyubd1W92GiWKg7aac6bOU3G803HbVk82xfP_Ok0JEqAT-FeLWJvpFYSOBbaSkMhCMnra5MgtfhWFrPWqHlhL2urT6atbU-oa0PNE8WXFFJ0-nazXakRroddGk9IwYEUnCd5w7Pddr5UTT8ZuVJY5F0fM7ebRLYyXNDgUnprJWxM-9lb7xAQLHe-M2xDYQCD9pD_2hez_kVn-P_rjLq6n3qjYv2iO5qz9DyvPdyv1ETp5eTTJ_7BGvQq8v1TVtl5jXUcRRcrqFh-dI4VtFlBN6t_ynLNkh5JpUmZEm5rbvfhkLiN6H4BQt2jYGYZklC_uzxWWJxsNCfUmkL2SJEJZuWdYs4cKaERS3IXlUJZNI_lGv7cxj2SMf2CeMx5_wBcbK19) + +## Conclusion + +This is only a brief overview of how the Virtual Dom works. There are several aspects not yet covered in this guide including how the Virtual Dom handles async-components, keyed diffing, and how it uses [bump allocation](https://github.com/fitzgen/bumpalo) to efficiently allocate VNodes. If need more information about the Virtual Dom, you can read the code of the [core](https://github.com/DioxusLabs/dioxus/tree/master/packages/core) crate or reach out to us on [Discord](https://discord.gg/XgGxMSkvUM). diff --git a/docs/guide/src/en/custom_renderer/index.md b/docs/guide/src/en/custom_renderer/index.md index 2d4ddb759..3b6888b0d 100644 --- a/docs/guide/src/en/custom_renderer/index.md +++ b/docs/guide/src/en/custom_renderer/index.md @@ -15,7 +15,7 @@ Essentially, your renderer needs to process edits and generate events to update Internally, Dioxus handles the tree relationship, diffing, memory management, and the event system, leaving as little as possible required for renderers to implement themselves. -For reference, check out the [javascript interpreter](https://github.com/DioxusLabs/dioxus/tree/master/packages/interpreter) or [tui renderer](https://github.com/DioxusLabs/dioxus/tree/master/packages/tui) as a starting point for your custom renderer. +For reference, check out the [javascript interpreter](https://github.com/DioxusLabs/dioxus/tree/master/packages/interpreter) or [tui renderer](https://github.com/DioxusLabs/dioxus/tree/master/packages/dioxus-tui) as a starting point for your custom renderer. ## Templates @@ -25,7 +25,7 @@ Dioxus is built around the concept of [Templates](https://docs.rs/dioxus-core/la The `Mutation` type is a serialized enum that represents an operation that should be applied to update the UI. The variants roughly follow this set: -```rust +```rust, no_run enum Mutation { AppendChildren, AssignId, @@ -58,7 +58,7 @@ Whenever a `CreateElement` edit is generated during diffing, Dioxus increments i For the sake of understanding, let's consider this example – a very simple UI declaration: -```rust +```rust, no_run rsx!( h1 {"count: {x}"} ) ``` @@ -68,7 +68,7 @@ The above rsx will create a template that contains one static h1 tag and a place The template will look something like this: -```rust +```rust, no_run Template { // Some id that is unique for the entire project name: "main.rs:1:1:0", @@ -118,7 +118,7 @@ After the renderer has created all of the new templates, it can begin to process When the renderer starts, it should contain the Root node on the stack and store the Root node with an id of 0. The Root node is the top-level node of the UI. In HTML, this is the `
` element. -```rust +```rust, no_run instructions: [] stack: [ RootNode, @@ -130,7 +130,7 @@ nodes: [ The first mutation is a `LoadTemplate` mutation. This tells the renderer to load a root from the template with the given id. The renderer will then push the root node of the template onto the stack and store it with an id for later. In this case, the root node is an h1 element. -```rust +```rust, no_run instructions: [ LoadTemplate { // the id of the template @@ -153,7 +153,7 @@ nodes: [ Next, Dioxus will create the dynamic text node. The diff algorithm decides that this node needs to be created, so Dioxus will generate the Mutation `HydrateText`. When the renderer receives this instruction, it will navigate to the placeholder text node in the template and replace it with the new text. -```rust +```rust, no_run instructions: [ LoadTemplate { name: "main.rs:1:1:0", @@ -180,7 +180,7 @@ nodes: [ Remember, the h1 node is not attached to anything (it is unmounted) so Dioxus needs to generate an Edit that connects the h1 node to the Root. It depends on the situation, but in this case, we use `AppendChildren`. This pops the text node off the stack, leaving the Root element as the next element on the stack. -```rust +```rust, no_run instructions: [ LoadTemplate { name: "main.rs:1:1:0", @@ -210,7 +210,7 @@ nodes: [ Over time, our stack looked like this: -```rust +```rust, no_run [Root] [Root,

""

] [Root,

"count: 0"

] @@ -229,7 +229,7 @@ Like most GUIs, Dioxus relies on an event loop to progress the VirtualDOM. The V The code for the WebSys implementation is straightforward, so we'll add it here to demonstrate how simple an event loop is: -```rust, ignore +```rust, no_run, ignore pub async fn run(&mut self) -> dioxus_core::error::Result<()> { // Push the body element onto the WebsysDom's stack machine let mut websys_dom = crate::new::WebsysDom::new(prepare_websys_dom()); @@ -259,7 +259,7 @@ pub async fn run(&mut self) -> dioxus_core::error::Result<()> { It's important to decode what the real events are for your event system into Dioxus' synthetic event system (synthetic meaning abstracted). This simply means matching your event type and creating a Dioxus `UserEvent` type. Right now, the virtual event system is modeled almost entirely around the HTML spec, but we are interested in slimming it down. -```rust, ignore +```rust, no_run, ignore fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent { match event.type_().as_str() { "keydown" => { @@ -308,7 +308,7 @@ The `RealDom` is a higher-level abstraction over updating the Dom. It uses an en Let's build a toy renderer with borders, size, and text color. Before we start let's take a look at an example element we can render: -```rust +```rust, no_run cx.render(rsx!{ div{ color: "red", @@ -380,19 +380,19 @@ To help in building a Dom, native-core provides the State trait and a RealDom st Native Core cannot create all of the required methods for the State trait, but it can derive some of them. To implement the State trait, you must implement the following methods and let the `#[partial_derive_state]` macro handle the rest: -```rust, ignore +```rust, no_run, ignore {{#include ../../../examples/custom_renderer.rs:derive_state}} ``` Lets take a look at how to implement the State trait for a simple renderer. -```rust +```rust, no_run {{#include ../../../examples/custom_renderer.rs:state_impl}} ``` Now that we have our state, we can put it to use in our RealDom. We can update the RealDom with apply_mutations to update the structure of the dom (adding, removing, and changing properties of nodes) and then update_state to update the States for each of the nodes that changed. -```rust +```rust, no_run {{#include ../../../examples/custom_renderer.rs:rendering}} ``` @@ -404,7 +404,7 @@ For most platforms, the layout of the Elements will stay the same. The [layout_a To make it easier to implement text editing in rust renderers, `native-core` also contains a renderer-agnostic cursor system. The cursor can handle text editing, selection, and movement with common keyboard shortcuts integrated. -```rust +```rust, no_run {{#include ../../../examples/custom_renderer.rs:cursor}} ``` diff --git a/docs/guide/src/en/describing_ui/component_children.md b/docs/guide/src/en/describing_ui/component_children.md index 02be25cd5..7e329abbc 100644 --- a/docs/guide/src/en/describing_ui/component_children.md +++ b/docs/guide/src/en/describing_ui/component_children.md @@ -2,13 +2,13 @@ In some cases, you may wish to create a component that acts as a container for some other content, without the component needing to know what that content is. To achieve this, create a prop of type `Element`: -```rust +```rust, no_run {{#include ../../../examples/component_element_props.rs:Clickable}} ``` Then, when rendering the component, you can pass in the output of `cx.render(rsx!(...))`: -```rust +```rust, no_run {{#include ../../../examples/component_element_props.rs:Clickable_usage}} ``` @@ -20,12 +20,12 @@ Then, when rendering the component, you can pass in the output of `cx.render(rsx Rather than passing the RSX through a regular prop, you may wish to accept children similarly to how elements can have children. The "magic" `children` prop lets you achieve this: -```rust +```rust, no_run {{#include ../../../examples/component_children.rs:Clickable}} ``` This makes using the component much simpler: simply put the RSX inside the `{}` brackets – and there is no need for a `render` call or another macro! -```rust +```rust, no_run {{#include ../../../examples/component_children.rs:Clickable_usage}} ``` diff --git a/docs/guide/src/en/describing_ui/component_props.md b/docs/guide/src/en/describing_ui/component_props.md index 9c5cd4be3..947ec5f70 100644 --- a/docs/guide/src/en/describing_ui/component_props.md +++ b/docs/guide/src/en/describing_ui/component_props.md @@ -7,6 +7,7 @@ Just like you can pass arguments to a function, you can pass props to a componen Component props are a single struct annotated with `#[derive(Props)]`. For a component to accept props, the type of its argument must be `Scope`. Then, you can access the value of the props using `cx.props`. There are 2 flavors of Props structs: + - Owned props: - Don't have an associated lifetime - Implement `PartialEq`, allow for memoization (if the props don't change, Dioxus won't re-render the component) @@ -14,17 +15,17 @@ There are 2 flavors of Props structs: - [Borrow](https://doc.rust-lang.org/beta/rust-by-example/scope/borrow.html) from a parent component - Cannot be memoized due to lifetime constraints - ### Owned Props Owned Props are very simple – they don't borrow anything. Example: -```rust +```rust, no_run {{#include ../../../examples/component_owned_props.rs:Likes}} ``` You can then pass prop values to the component the same way you would pass attributes to an element: -```rust + +```rust, no_run {{#include ../../../examples/component_owned_props.rs:App}} ``` @@ -36,18 +37,19 @@ Owned props work well if your props are easy to copy around – like a single nu Rust allows for something more efficient – borrowing the String as a `&str` – this is what Borrowed Props are for! -```rust +```rust, no_run {{#include ../../../examples/component_borrowed_props.rs:TitleCard}} ``` We can then use the component like this: -```rust +```rust, no_run {{#include ../../../examples/component_borrowed_props.rs:App}} ``` + ![Screenshot: TitleCard component](./images/component_borrowed_props_screenshot.png) -Borrowed props can be very useful, but they do not allow for memorization so they will *always* rerun when the parent scope is rerendered. Because of this Borrowed Props should be reserved for components that are cheap to rerun or places where cloning data is an issue. Using Borrowed Props everywhere will result in large parts of your app rerunning every interaction. +Borrowed props can be very useful, but they do not allow for memorization so they will _always_ rerun when the parent scope is rerendered. Because of this Borrowed Props should be reserved for components that are cheap to rerun or places where cloning data is an issue. Using Borrowed Props everywhere will result in large parts of your app rerunning every interaction. ## Prop Options @@ -57,13 +59,13 @@ The `#[derive(Props)]` macro has some features that let you customize the behavi You can create optional fields by using the `Option<…>` type for a field: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:OptionalProps}} ``` Then, you can choose to either provide them or not: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:OptionalProps_usage}} ``` @@ -71,13 +73,13 @@ Then, you can choose to either provide them or not: If you want to explicitly require an `Option`, and not an optional prop, you can annotate it with `#[props(!optional)]`: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:ExplicitOption}} ``` Then, you have to explicitly pass either `Some("str")` or `None`: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:ExplicitOption_usage}} ``` @@ -85,13 +87,13 @@ Then, you have to explicitly pass either `Some("str")` or `None`: You can use `#[props(default = 42)]` to make a field optional and specify its default value: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:DefaultComponent}} ``` Then, similarly to optional props, you don't have to provide it: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:DefaultComponent_usage}} ``` @@ -99,13 +101,13 @@ Then, similarly to optional props, you don't have to provide it: It is common for Rust functions to accept `impl Into` rather than just `SomeType` to support a wider range of parameters. If you want similar functionality with props, you can use `#[props(into)]`. For example, you could add it on a `String` prop – and `&str` will also be automatically accepted, as it can be converted into `String`: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:IntoComponent}} ``` Then, you can use it so: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:IntoComponent_usage}} ``` @@ -115,7 +117,7 @@ So far, every Component function we've seen had a corresponding ComponentProps s `inline_props` allows you to do just that. Instead of typing the "full" version: -```rust +```rust, no_run #[derive(Props, PartialEq)] struct TitleCardProps { title: String, @@ -130,7 +132,7 @@ fn TitleCard(cx: Scope) -> Element { ...you can define a function that accepts props as arguments. Then, just annotate it with `#[inline_props]`, and the macro will turn it into a regular Component for you: -```rust +```rust, no_run #[inline_props] fn TitleCard(cx: Scope, title: String) -> Element { cx.render(rsx!{ diff --git a/docs/guide/src/en/describing_ui/components.md b/docs/guide/src/en/describing_ui/components.md index 9da0d6605..2b72fcaf2 100644 --- a/docs/guide/src/en/describing_ui/components.md +++ b/docs/guide/src/en/describing_ui/components.md @@ -4,7 +4,7 @@ Just like you wouldn't want to write a complex program in a single, long, `main` A component is a Rust function, named in UpperCammelCase, that takes a `Scope` parameter and returns an `Element` describing the UI it wants to render. In fact, our `App` function is a component! -```rust +```rust, no_run {{#include ../../../examples/hello_world_desktop.rs:component}} ``` @@ -12,13 +12,13 @@ A component is a Rust function, named in UpperCammelCase, that takes a `Scope` p A Component is responsible for some rendering task – typically, rendering an isolated part of the user interface. For example, you could have an `About` component that renders a short description of Dioxus Labs: -```rust +```rust, no_run {{#include ../../../examples/components.rs:About}} ``` Then, you can render your component in another component, similarly to how elements are rendered: -```rust +```rust, no_run {{#include ../../../examples/components.rs:App}} ``` diff --git a/docs/guide/src/en/describing_ui/index.md b/docs/guide/src/en/describing_ui/index.md index 808e6af3c..8e5b3fe8f 100644 --- a/docs/guide/src/en/describing_ui/index.md +++ b/docs/guide/src/en/describing_ui/index.md @@ -1,35 +1,42 @@ # Describing the UI -Dioxus is a *declarative* framework. This means that instead of telling Dioxus what to do (e.g. to "create an element" or "set the color to red") we simply *declare* what we want the UI to look like using RSX. +Dioxus is a _declarative_ framework. This means that instead of telling Dioxus what to do (e.g. to "create an element" or "set the color to red") we simply _declare_ what we want the UI to look like using RSX. You have already seen a simple example of RSX syntax in the "hello world" application: -```rust +```rust, no_run {{#include ../../../examples/hello_world_desktop.rs:component}} ``` -Here, we use the `rsx!` macro to *declare* that we want a `div` element, containing the text `"Hello, world!"`. Dioxus takes the RSX and constructs a UI from it. +Here, we use the `rsx!` macro to _declare_ that we want a `div` element, containing the text `"Hello, world!"`. Dioxus takes the RSX and constructs a UI from it. ## RSX Features RSX is very similar to HTML in that it describes elements with attributes and children. Here's an empty `div` element in RSX, as well as the resulting HTML: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:empty}} ``` + ```html
``` - ### Attributes Attributes (and [listeners](../interactivity/index.md)) modify the behavior or appearance of the element they are attached to. They are specified inside the `{}` brackets, using the `name: value` syntax. You can provide the value as a literal in the RSX: -```rust + +```rust, no_run {{#include ../../../examples/rsx_overview.rs:attributes}} ``` + ```html -
+ ``` > Note: All attributes defined in `dioxus-html` follow the snake_case naming convention. They transform their `snake_case` names to HTML's `camelCase` attributes. @@ -40,26 +47,27 @@ Attributes (and [listeners](../interactivity/index.md)) modify the behavior or a Dioxus has a pre-configured set of attributes that you can use. RSX is validated at compile time to make sure you didn't specify an invalid attribute. If you want to override this behavior with a custom attribute name, specify the attribute in quotes: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:custom_attributes}} ``` + ```html - - + ``` ### Interpolation Similarly to how you can [format](https://doc.rust-lang.org/rust-by-example/hello/print/fmt.html) Rust strings, you can also interpolate in RSX text. Use `{variable}` to Display the value of a variable in a string, or `{variable:?}` to use the Debug representation: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:formatting}} ``` + ```html
-
ES
-
42
-
{}
+
ES
+
42
+
{}
``` @@ -67,14 +75,15 @@ Similarly to how you can [format](https://doc.rust-lang.org/rust-by-example/hell To add children to an element, put them inside the `{}` brackets after all attributes and listeners in the element. They can be other elements, text, or [components](components.md). For example, you could have an `ol` (ordered list) element, containing 3 `li` (list item) elements, each of which contains some text: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:children}} ``` + ```html
    -
  1. First Item
  2. -
  3. Second Item
  4. -
  5. Third Item
  6. +
  7. First Item
  8. +
  9. Second Item
  10. +
  11. Third Item
``` @@ -82,7 +91,7 @@ To add children to an element, put them inside the `{}` brackets after all attri You can render multiple elements at the top level of `rsx!` and they will be automatically grouped. -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:manyroots}} ``` @@ -95,9 +104,10 @@ You can render multiple elements at the top level of `rsx!` and they will be aut You can include arbitrary Rust expressions as children within RSX that implements [IntoDynNode](https://docs.rs/dioxus-core/0.3/dioxus_core/trait.IntoDynNode.html). This is useful for displaying data from an [iterator](https://doc.rust-lang.org/stable/book/ch13-02-iterators.html#processing-a-series-of-items-with-iterators): -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:expression}} ``` + ```html DIOXUS0123456789 ``` @@ -106,9 +116,10 @@ You can include arbitrary Rust expressions as children within RSX that implement In addition to iterators you can also use for loops directly within RSX: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:loops}} ``` + ```html
0
1
@@ -122,9 +133,10 @@ In addition to iterators you can also use for loops directly within RSX: You can also use if statements without an else branch within RSX: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:ifstatements}} ``` + ```html
true
-``` \ No newline at end of file +``` diff --git a/docs/guide/src/en/describing_ui/special_attributes.md b/docs/guide/src/en/describing_ui/special_attributes.md index 7bed1ef94..4ba7a40f1 100644 --- a/docs/guide/src/en/describing_ui/special_attributes.md +++ b/docs/guide/src/en/describing_ui/special_attributes.md @@ -8,8 +8,7 @@ If you're working with pre-rendered assets, output from templates, or output fro For example, shipping a markdown-to-Dioxus converter might significantly bloat your final application size. Instead, you'll want to pre-render your markdown to HTML and then include the HTML directly in your output. We use this approach for the [Dioxus homepage](https://dioxuslabs.com): - -```rust +```rust, no_run {{#include ../../../examples/dangerous_inner_html.rs:dangerous_inner_html}} ``` @@ -17,21 +16,21 @@ For example, shipping a markdown-to-Dioxus converter might significantly bloat y > > If you're handling untrusted input, make sure to sanitize your HTML before passing it into `dangerous_inner_html` – or just pass it to a Text Element to escape any HTML tags. - ## Boolean Attributes Most attributes, when rendered, will be rendered exactly as the input you provided. However, some attributes are considered "boolean" attributes and just their presence determines whether they affect the output. For these attributes, a provided value of `"false"` will cause them to be removed from the target element. So this RSX wouldn't actually render the `hidden` attribute: -```rust +```rust, no_run {{#include ../../../examples/boolean_attribute.rs:boolean_attribute}} ``` + ```html
hello
``` -Not all attributes work like this however. *Only the following attributes* have this behavior: +Not all attributes work like this however. _Only the following attributes_ have this behavior: - `allowfullscreen` - `allowpaymentrequest` diff --git a/docs/guide/src/en/fullstack/getting_started.md b/docs/guide/src/en/fullstack/getting_started.md new file mode 100644 index 000000000..9511b8a6c --- /dev/null +++ b/docs/guide/src/en/fullstack/getting_started.md @@ -0,0 +1,102 @@ +> This guide assumes you read the [Web](web.md) guide and installed the [Dioxus-cli](https://github.com/DioxusLabs/cli) + +# Getting Started + +## Setup + +For this guide, we're going to show how to use Dioxus with [Axum](https://docs.rs/axum/latest/axum/), but `dioxus-fullstack` also integrates with the [Warp](https://docs.rs/warp/latest/warp/) and [Salvo](https://docs.rs/salvo/latest/salvo/) web frameworks. + +Make sure you have Rust and Cargo installed, and then create a new project: + +```shell +cargo new --bin demo +cd demo +``` + +Add `dioxus` and `dioxus-fullstack` as dependencies: + +```shell +cargo add dioxus +cargo add dioxus-fullstack --features axum, ssr +``` + +Next, add all the Axum dependencies. This will be different if you're using a different Web Framework + +```shell +cargo add tokio --features full +cargo add axum +``` + +Your dependencies should look roughly like this: + +```toml +[dependencies] +axum = "*" +dioxus = { version = "*" } +dioxus-fullstack = { version = "*", features = ["axum", "ssr"] } +tokio = { version = "*", features = ["full"] } +``` + +Now, set up your Axum app to serve the Dioxus app. + +```rust, no_run +{{#include ../../../examples/server_basic.rs}} +``` + +Now, run your app with `cargo run` and open `http://localhost:8080` in your browser. You should see a server-side rendered page with a counter. + +## Hydration + +Right now, the page is static. We can't interact with the buttons. To fix this, we can hydrate the page with `dioxus-web`. + +First, modify your `Cargo.toml` to include two features, one for the server called `ssr`, and one for the client called `web`. + +```toml +[dependencies] +# Common dependancies +dioxus = { version = "*" } +dioxus-fullstack = { version = "*" } + +# Web dependancies +dioxus-web = { version = "*", features=["hydrate"], optional = true } + +# Server dependancies +axum = { version = "0.6.12", optional = true } +tokio = { version = "1.27.0", features = ["full"], optional = true } + +[features] +default = [] +ssr = ["axum", "tokio", "dioxus-fullstack/axum"] +web = ["dioxus-web"] +``` + +Next, we need to modify our `main.rs` to use either hydrate on the client or render on the server depending on the active features. + +```rust, no_run +{{#include ../../../examples/hydration.rs}} +``` + +Now, build your client-side bundle with `dioxus build --features web` and run your server with `cargo run --features ssr`. You should see the same page as before, but now you can interact with the buttons! + +## Sycronizing props between the server and client + +Let's make the initial count of the counter dynamic based on the current page. + +### Modifying the server + +To do this, we must remove the serve_dioxus_application and replace it with a custom implementation of its four key functions: + +- Serve static WASM and JS files with serve_static_assets +- Register server functions with register_server_fns (more information on server functions later) +- Connect to the hot reload server with connect_hot_reload +- A custom route that uses SSRState to server-side render the application + +### Modifying the client + +The only thing we need to change on the client is the props. `dioxus-fullstack` will automatically serialize the props it uses to server render the app and send them to the client. In the client section of `main.rs`, we need to add `get_root_props_from_document` to deserialize the props before we hydrate the app. + +```rust, no_run +{{#include ../../../examples/hydration_props.rs}} +``` + +Now, build your client-side bundle with `dioxus build --features web` and run your server with `cargo run --features ssr`. Navigate to `http://localhost:8080/1` and you should see the counter start at 1. Navigate to `http://localhost:8080/2` and you should see the counter start at 2. diff --git a/docs/guide/src/en/fullstack/index.md b/docs/guide/src/en/fullstack/index.md new file mode 100644 index 000000000..a9b39c8f1 --- /dev/null +++ b/docs/guide/src/en/fullstack/index.md @@ -0,0 +1,59 @@ +# Fullstack development + +So far you have learned about three different approaches to target the web with Dioxus: + +- [Client-side rendering with dioxus-web](../getting_started/web.md) +- [Server-side rendering with dioxus-liveview](../getting_started/liveview.md) +- [Server-side static HTML generation with dioxus-ssr](../getting_started/ssr.md) + +## Summary of Existing Approaches + +Each approach has its tradeoffs: + +### Client-side rendering + +- With Client side rendering, you send the entire content of your application to the client, and then the client generates all of the HTML of the page dynamically. + +- This means that the page will be blank until the JavaScript bundle has loaded and the application has initialized. This can result in **slower first render times and makes the page less SEO-friendly**. + +> SEO stands for Search Engine Optimization. It refers to the practice of making your website more likely to appear in search engine results. Search engines like Google and Bing use web crawlers to index the content of websites. Most of these crawlers are not able to run JavaScript, so they will not be able to index the content of your page if it is rendered client-side. + +- Client-side rendered applications need to use **weakly typed requests to communicate with the server** + +> Client-side rendering is a good starting point for most applications. It is well supported and makes it easy to communicate with the client/browser APIs + +### Liveview + +- Liveview rendering communicates with the server over a WebSocket connection. It essentially moves all of the work that Client-side rendering does to the server. + +- This makes it **easy to communicate with the server, but more difficult to communicate with the client/browser APIS**. + +- Each interaction also requires a message to be sent to the server and back which can cause **issues with latency**. + +- Because Liveview uses a websocket to render, the page will be blank until the WebSocket connection has been established and the first renderer has been sent form the websocket. Just like with client side rendering, this can make the page **less SEO-friendly**. + +- Because the page is rendered on the server and the page is sent to the client piece by piece, you never need to send the entire application to the client. The initial load time can be faster than client-side rendering with large applications because Liveview only needs to send a constant small websocket script regardless of the size of the application. + +> Liveview is a good fit for applications that already need to communicate with the server frequently (like real time collaborative apps), but don't need to communicate with as many client/browser APIs + +### Server-side rendering + +- Server-side rendering generates all of the HTML of the page on the server before the page is sent to the client. This means that the page will be fully rendered when it is sent to the client. This results in a faster first render time and makes the page more SEO-friendly. However, it **only works for static pages**. + +> Server-side rendering is not a good fit for purely static sites like a blog + +## A New Approach + +Each of these approaches has its tradeoffs. What if we could combine the best parts of each approach? + +- **Fast initial render** time like SSR +- **Works well with SEO** like SSR +- **Type safe easy communication with the server** like Liveview +- **Access to the client/browser APIs** like Client-side rendering +- **Fast interactivity** like Client-side rendering + +We can achieve this by rendering the initial page on the server (SSR) and then taking over rendering on the client (Client-side rendering). Taking over rendering on the client is called **hydration**. + +Finally, we can use [server functions](server_functions.md) to communicate with the server in a type-safe way. + +This approach uses both the dioxus-web and dioxus-ssr crates. To integrate those two packages and `axum`, `warp`, or `salvo`, Dioxus provides the `dioxus-fullstack` crate. diff --git a/docs/guide/src/en/fullstack/server_functions.md b/docs/guide/src/en/fullstack/server_functions.md new file mode 100644 index 000000000..57883885a --- /dev/null +++ b/docs/guide/src/en/fullstack/server_functions.md @@ -0,0 +1,31 @@ +# Communicating with the server + +`dixous-server` provides server functions that allow you to call an automatically generated API on the server from the client as if it were a local function. + +To make a server function, simply add the `#[server(YourUniqueType)]` attribute to a function. The function must: + +- Be an async function +- Have arguments and a return type that both implement serialize and deserialize (with [serde](https://serde.rs/)). +- Return a `Result` with an error type of ServerFnError + +You must call `register` on the type you passed into the server macro in your main function before starting your server to tell Dioxus about the server function. + +Let's continue building on the app we made in the [getting started](./getting_started.md) guide. We will add a server function to our app that allows us to double the count on the server. + +First, add serde as a dependency: + +```shell +cargo add serde +``` + +Next, add the server function to your `main.rs`: + +```rust, no_run +{{#include ../../../examples/server_function.rs}} +``` + +Now, build your client-side bundle with `dioxus build --features web` and run your server with `cargo run --features ssr`. You should see a new button that multiplies the count by 2. + +## Conclusion + +That's it! You've created a full-stack Dioxus app. You can find more examples of full-stack apps and information about how to integrate with other frameworks and desktop renderers in the [dioxus-fullstack examples directory](https://github.com/DioxusLabs/dioxus/tree/master/packages/server/examples). diff --git a/docs/guide/src/en/getting_started/desktop.md b/docs/guide/src/en/getting_started/desktop.md index b24215218..42fe5c1a2 100644 --- a/docs/guide/src/en/getting_started/desktop.md +++ b/docs/guide/src/en/getting_started/desktop.md @@ -72,6 +72,6 @@ cargo add dioxus-desktop Edit your `main.rs`: -```rust +```rust, no_run {{#include ../../../examples/hello_world_desktop.rs:all}} ``` diff --git a/docs/guide/src/en/getting_started/fullstack.md b/docs/guide/src/en/getting_started/fullstack.md new file mode 100644 index 000000000..fa3ba67c2 --- /dev/null +++ b/docs/guide/src/en/getting_started/fullstack.md @@ -0,0 +1 @@ +# Fullstack diff --git a/docs/guide/src/en/getting_started/hot_reload.md b/docs/guide/src/en/getting_started/hot_reload.md index 599ce57da..b14de30a4 100644 --- a/docs/guide/src/en/getting_started/hot_reload.md +++ b/docs/guide/src/en/getting_started/hot_reload.md @@ -5,31 +5,38 @@ 3. Currently the cli only implements hot reloading for the web renderer. For TUI, desktop, and LiveView you can use the hot reload macro instead. # Web + For the web renderer, you can use the dioxus cli to serve your application with hot reloading enabled. ## Setup + Install [dioxus-cli](https://github.com/DioxusLabs/cli). Hot reloading is automatically enabled when using the web renderer on debug builds. ## Usage + 1. Run: -```bash + +```bash dioxus serve --hot-reload ``` + 2. Change some code within a rsx or render macro 3. Open your localhost in a browser 4. Save and watch the style change without recompiling -# Desktop/Liveview/TUI +# Desktop/Liveview/TUI/Server + For desktop, LiveView, and tui, you can place the hot reload macro at the top of your main function to enable hot reloading. Hot reloading is automatically enabled on debug builds. For more information about hot reloading on native platforms and configuration options see the [dioxus-hot-reload](https://crates.io/crates/dioxus-hot-reload) crate. ## Setup + Add the following to your main function: -```rust +```rust, no_run fn main() { hot_reload_init!(); // launch your application @@ -37,13 +44,17 @@ fn main() { ``` ## Usage + 1. Run: + ```bash cargo run ``` + 2. Change some code within a rsx or render macro 3. Save and watch the style change without recompiling # Limitations + 1. The interpreter can only use expressions that existed on the last full recompile. If you introduce a new variable or expression to the rsx call, it will require a full recompile to capture the expression. 2. Components, Iterators, and some attributes can contain arbitrary rust code and will trigger a full recompile when changed. diff --git a/docs/guide/src/en/getting_started/liveview.md b/docs/guide/src/en/getting_started/liveview.md index 54f792e74..56847cab5 100644 --- a/docs/guide/src/en/getting_started/liveview.md +++ b/docs/guide/src/en/getting_started/liveview.md @@ -1,18 +1,17 @@ # Liveview -Liveview allows apps to *run* on the server and *render* in the browser. It uses WebSockets to communicate between the server and the browser. +Liveview allows apps to _run_ on the server and _render_ in the browser. It uses WebSockets to communicate between the server and the browser. Examples: + - [Axum Example](https://github.com/DioxusLabs/dioxus/tree/master/packages/liveview/examples/axum.rs) - [Salvo Example](https://github.com/DioxusLabs/dioxus/tree/master/packages/liveview/examples/salvo.rs) - [Warp Example](https://github.com/DioxusLabs/dioxus/tree/master/packages/liveview/examples/warp.rs) - ## Support Liveview is currently limited in capability when compared to the Web platform. Liveview apps run on the server in a native thread. This means that browser APIs are not available, so rendering WebGL, Canvas, etc is not as easy as the Web. However, native system APIs are accessible, so streaming, WebSockets, filesystem, etc are all viable APIs. - ## Setup For this guide, we're going to show how to use Dioxus Liveview with [Axum](https://docs.rs/axum/latest/axum/). @@ -50,17 +49,14 @@ tokio = { version = "1.15.0", features = ["full"] } Now, set up your Axum app to respond on an endpoint. - -```rust +```rust, no_run {{#include ../../../examples/hello_world_liveview.rs:glue}} ``` - And then add our app component: -```rust +```rust, no_run {{#include ../../../examples/hello_world_liveview.rs:app}} ``` And that's it! - diff --git a/docs/guide/src/en/getting_started/mobile.md b/docs/guide/src/en/getting_started/mobile.md index 2f93b807c..72d597f51 100644 --- a/docs/guide/src/en/getting_started/mobile.md +++ b/docs/guide/src/en/getting_started/mobile.md @@ -5,8 +5,8 @@ Build a mobile app with Dioxus! Example: [Todo App](https://github.com/DioxusLabs/example-projects/blob/master/ios_demo) ## Support -Mobile is currently the least-supported renderer target for Dioxus. Mobile apps are rendered with either the platform's WebView or experimentally through [WGPU](https://github.com/DioxusLabs/blitz). WebView doesn't support animations, transparency, and native widgets. +Mobile is currently the least-supported renderer target for Dioxus. Mobile apps are rendered with either the platform's WebView or experimentally through [WGPU](https://github.com/DioxusLabs/blitz). WebView doesn't support animations, transparency, and native widgets. Mobile support is currently best suited for CRUD-style apps, ideally for internal teams who need to develop quickly but don't care much about animations or native widgets. @@ -59,7 +59,7 @@ simple_logger = "*" Edit your `lib.rs`: -```rust +```rust, no_run use dioxus::prelude::*; fn main() { @@ -73,4 +73,4 @@ fn app(cx: Scope) -> Element { } }) } -``` \ No newline at end of file +``` diff --git a/docs/guide/src/en/getting_started/ssr.md b/docs/guide/src/en/getting_started/ssr.md index 9654003cf..080efbb6d 100644 --- a/docs/guide/src/en/getting_started/ssr.md +++ b/docs/guide/src/en/getting_started/ssr.md @@ -1,17 +1,6 @@ # Server-Side Rendering -The Dioxus VirtualDom can be rendered server-side. - -[Example: Dioxus DocSite](https://github.com/dioxusLabs/docsite) - -## Multithreaded Support - -The Dioxus VirtualDom, sadly, is not currently `Send`. Internally, we use quite a bit of interior mutability which is not thread-safe. This means you can't easily use Dioxus with most web frameworks like Tide, Rocket, Axum, etc. - -To solve this, you'll want to spawn a VirtualDom on its own thread and communicate with it via channels. - -When working with web frameworks that require `Send`, it is possible to render a VirtualDom immediately to a String – but you cannot hold the VirtualDom across an await point. For retained-state SSR (essentially LiveView), you'll need to create a pool of VirtualDoms. - +For lower-level control over the rendering process, you can use the `dioxus-ssr` crate directly. This can be useful when integrating with a web framework that `dioxus-server` does not support, or pre-rendering pages. ## Setup @@ -21,7 +10,7 @@ Make sure you have Rust and Cargo installed, and then create a new project: ```shell cargo new --bin demo -cd app +cd demo ``` Add Dioxus and the ssr renderer as dependencies: @@ -50,55 +39,33 @@ tokio = { version = "1.15.0", features = ["full"] } Now, set up your Axum app to respond on an endpoint. -```rust -use axum::{response::Html, routing::get, Router}; -use dioxus::prelude::*; - -#[tokio::main] -async fn main() { - let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000)); - println!("listening on http://{}", addr); - - axum::Server::bind(&addr) - .serve( - Router::new() - .route("/", get(app_endpoint)) - .into_make_service(), - ) - .await - .unwrap(); -} +```rust, no_run +{{#include ../../../examples/hello_world_ssr.rs:main}} ``` And then add our endpoint. We can either render `rsx!` directly: -```rust -async fn app_endpoint() -> Html { - // render the rsx! macro to HTML - Html(dioxus_ssr::render_lazy(rsx! { - div { "hello world!" } - })) -} +```rust, no_run +{{#include ../../../examples/hello_world_ssr.rs:endpoint}} ``` Or we can render VirtualDoms. -```rust -async fn app_endpoint() -> Html { - // create a component that renders a div with the text "hello world" - fn app(cx: Scope) -> Element { - cx.render(rsx!(div { "hello world" })) - } - // create a VirtualDom with the app component - let mut app = VirtualDom::new(app); - // rebuild the VirtualDom before rendering - let _ = app.rebuild(); +```rust, no_run +{{#include ../../../examples/hello_world_ssr.rs:second_endpoint}} +``` - // render the VirtualDom to HTML - Html(dioxus_ssr::render_vdom(&app)) -} +And then add our app component: + +```rust +{{#include ../../../examples/hello_world_ssr.rs:component}} ``` And that's it! -> You might notice that you cannot hold the VirtualDom across an await point. Dioxus is currently not ThreadSafe, so it _must_ remain on the thread it started. We are working on loosening this requirement. \ No newline at end of file + +## Multithreaded Support + +The Dioxus VirtualDom, sadly, is not currently `Send`. Internally, we use quite a bit of interior mutability which is not thread-safe. +When working with web frameworks that require `Send`, it is possible to render a VirtualDom immediately to a String – but you cannot hold the VirtualDom across an await point. For retained-state SSR (essentially LiveView), you'll need to spawn a VirtualDom on its own thread and communicate with it via channels or create a pool of VirtualDoms. +You might notice that you cannot hold the VirtualDom across an await point. Because Dioxus is currently not ThreadSafe, it _must_ remain on the thread it started. We are working on loosening this requirement. diff --git a/docs/guide/src/en/getting_started/tui.md b/docs/guide/src/en/getting_started/tui.md index e49cb84a8..504c01212 100644 --- a/docs/guide/src/en/getting_started/tui.md +++ b/docs/guide/src/en/getting_started/tui.md @@ -12,14 +12,12 @@ TUI support is currently quite experimental. But, if you're willing to venture i - It uses flexbox for the layout - It only supports a subset of the attributes and elements -- Regular widgets will not work in the tui render, but the tui renderer has its own widget components that start with a capital letter. See the [widgets example](https://github.com/DioxusLabs/dioxus/blob/master/packages/tui/examples/widgets.rs) +- Regular widgets will not work in the tui render, but the tui renderer has its own widget components that start with a capital letter. See the [widgets example](https://github.com/DioxusLabs/dioxus/blob/master/packages/dioxus-tui/examples/widgets.rs) - 1px is one character line height. Your regular CSS px does not translate - If your app panics, your terminal is wrecked. This will be fixed eventually - ## Getting Set up - Start by making a new package and adding Dioxus and the TUI renderer as dependancies. ```shell @@ -31,7 +29,7 @@ cargo add dioxus-tui Then, edit your `main.rs` with the basic template. -```rust +```rust, no_run {{#include ../../../examples/hello_world_tui.rs}} ``` @@ -43,6 +41,6 @@ cargo run Press "ctrl-c" to close the app. To switch from "ctrl-c" to just "q" to quit you can launch the app with a configuration to disable the default quit and use the root TuiContext to quit on your own. -```rust +```rust, no_run {{#include ../../../examples/hello_world_tui_no_ctrl_c.rs}} ``` diff --git a/docs/guide/src/en/getting_started/web.md b/docs/guide/src/en/getting_started/web.md index 76e3b9541..32d4d3d0f 100644 --- a/docs/guide/src/en/getting_started/web.md +++ b/docs/guide/src/en/getting_started/web.md @@ -5,6 +5,7 @@ Build single-page applications that run in the browser with Dioxus. To run on th A build of Dioxus for the web will be roughly equivalent to the size of a React build (70kb vs 65kb) but it will load significantly faster because [WebAssembly can be compiled as it is streamed](https://hacks.mozilla.org/2018/01/making-webassembly-even-faster-firefoxs-new-streaming-and-tiering-compiler/). Examples: + - [TodoMVC](https://github.com/DioxusLabs/example-projects/tree/master/todomvc) - [ECommerce](https://github.com/DioxusLabs/example-projects/tree/master/ecommerce-site) @@ -17,7 +18,7 @@ Examples: The Web is the best-supported target platform for Dioxus. - Because your app will be compiled to WASM you have access to browser APIs through [wasm-bingen](https://rustwasm.github.io/docs/wasm-bindgen/introduction.html). -- Dioxus provides hydration to resume apps that are rendered on the server. See the [hydration example](https://github.com/DioxusLabs/dioxus/blob/master/packages/web/examples/hydrate.rs) for more details. +- Dioxus provides hydration to resume apps that are rendered on the server. See the [fullstack](fullstack.md) getting started guide for more information. ## Tooling @@ -28,6 +29,7 @@ cargo install dioxus-cli ``` Make sure the `wasm32-unknown-unknown` target for rust is installed: + ```shell rustup target add wasm32-unknown-unknown ``` @@ -49,11 +51,11 @@ cargo add dioxus-web ``` Edit your `main.rs`: -```rust + +```rust, no_run {{#include ../../../examples/hello_world_web.rs}} ``` - And to serve our app: ```bash diff --git a/docs/guide/src/en/index.md b/docs/guide/src/en/index.md index 332d5957b..bbebb0bc9 100644 --- a/docs/guide/src/en/index.md +++ b/docs/guide/src/en/index.md @@ -4,7 +4,7 @@ Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust. This guide will help you get started with writing Dioxus apps for the Web, Desktop, Mobile, and more. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let mut count = use_state(cx, || 0); @@ -18,7 +18,7 @@ fn app(cx: Scope) -> Element { Dioxus is heavily inspired by React. If you know React, getting started with Dioxus will be a breeze. -> This guide assumes you already know some [Rust](https://www.rust-lang.org/)! If not, we recommend reading [*the book*](https://doc.rust-lang.org/book/ch01-00-getting-started.html) to learn Rust first. +> This guide assumes you already know some [Rust](https://www.rust-lang.org/)! If not, we recommend reading [_the book_](https://doc.rust-lang.org/book/ch01-00-getting-started.html) to learn Rust first. ## Features @@ -31,9 +31,10 @@ Dioxus is heavily inspired by React. If you know React, getting started with Dio ### Multiplatform -Dioxus is a *portable* toolkit, meaning the Core implementation can run anywhere with no platform-dependent linking. Unlike many other Rust frontend toolkits, Dioxus is not intrinsically linked to WebSys. In fact, every element and event listener can be swapped out at compile time. By default, Dioxus ships with the `html` feature enabled, but this can be disabled depending on your target renderer. +Dioxus is a _portable_ toolkit, meaning the Core implementation can run anywhere with no platform-dependent linking. Unlike many other Rust frontend toolkits, Dioxus is not intrinsically linked to WebSys. In fact, every element and event listener can be swapped out at compile time. By default, Dioxus ships with the `html` feature enabled, but this can be disabled depending on your target renderer. Right now, we have several 1st-party renderers: + - WebSys (for WASM): Great support - Tao/Tokio (for Desktop apps): Good support - Tao/Tokio (for Mobile apps): Poor support diff --git a/docs/guide/src/en/interactivity/custom_hooks.md b/docs/guide/src/en/interactivity/custom_hooks.md index 07472bb95..d075bb632 100644 --- a/docs/guide/src/en/interactivity/custom_hooks.md +++ b/docs/guide/src/en/interactivity/custom_hooks.md @@ -2,16 +2,24 @@ Hooks are a great way to encapsulate business logic. If none of the existing hooks work for your problem, you can write your own. +When writing your hook, you can make a function that accepts `cx: &ScopeState` as a parameter to accept a scope with any Props. + ## Composing Hooks To avoid repetition, you can encapsulate business logic based on existing hooks to create a new hook. For example, if many components need to access an `AppSettings` struct, you can create a "shortcut" hook: -```rust +```rust, no_run {{#include ../../../examples/hooks_composed.rs:wrap_context}} ``` +Or if you want to wrap a hook that persists reloads with the storage API, you can build on top of the use_ref hook to work with mutable state: + +```rust, no_run +{{#include ../../../examples/hooks_composed.rs:use_storage}} +``` + ## Custom Hook Logic You can use [`cx.use_hook`](https://docs.rs/dioxus/latest/dioxus/prelude/struct.ScopeState.html#method.use_hook) to build your own hooks. In fact, this is what all the standard hooks are built on! @@ -23,4 +31,61 @@ You can use [`cx.use_hook`](https://docs.rs/dioxus/latest/dioxus/prelude/struct. Inside the initialization closure, you will typically make calls to other `cx` methods. For example: - The `use_state` hook tracks state in the hook value, and uses [`cx.schedule_update`](https://docs.rs/dioxus/latest/dioxus/prelude/struct.ScopeState.html#method.schedule_update) to make Dioxus re-render the component whenever it changes. + +Here is a simplified implementation of the `use_state` hook: + +```rust, no_run +{{#include ../../../examples/hooks_custom_logic.rs:use_state}} +``` + - The `use_context` hook calls [`cx.consume_context`](https://docs.rs/dioxus/latest/dioxus/prelude/struct.ScopeState.html#method.consume_context) (which would be expensive to call on every render) to get some context from the scope + +Here is an implementation of the `use_context` and `use_context_provider` hooks: + +```rust, no_run +{{#include ../../../examples/hooks_custom_logic.rs:use_context}} +``` + +## Hook Anti-Patterns + +When writing a custom hook, you should avoid the following anti-patterns: + +- !Clone Hooks: To allow hooks to be used within async blocks, the hooks must be Clone. To make a hook clone, you can wrap data in Rc or Arc and avoid lifetimes in hooks. + +This version of use_state may seem more efficient, but it is not cloneable: + +```rust, no_run +{{#include ../../../examples/hooks_anti_patterns.rs:non_clone_state}} +``` + +If we try to use this hook in an async block, we will get a compile error: + +```rust, no_run +fn FutureComponent(cx: &ScopeState) -> Element { + let my_state = my_use_state(cx, || 0); + cx.spawn({ + to_owned![my_state]; + async move { + my_state.set(1); + } + }); + + todo!() +} +``` + +But with the original version, we can use it in an async block: + +```rust, no_run +fn FutureComponent(cx: &ScopeState) -> Element { + let my_state = use_state(cx, || 0); + cx.spawn({ + to_owned![my_state]; + async move { + my_state.set(1); + } + }); + + todo!() +} +``` diff --git a/docs/guide/src/en/interactivity/dynamic_rendering.md b/docs/guide/src/en/interactivity/dynamic_rendering.md index 290871e9c..8d91650c3 100644 --- a/docs/guide/src/en/interactivity/dynamic_rendering.md +++ b/docs/guide/src/en/interactivity/dynamic_rendering.md @@ -6,7 +6,7 @@ Sometimes you want to render different things depending on the state/props. With To render different elements based on a condition, you could use an `if-else` statement: -```rust +```rust, no_run {{#include ../../../examples/conditional_rendering.rs:if_else}} ``` @@ -18,7 +18,7 @@ You may have noticed some repeated code in the `if-else` example above. Repeatin We can improve this example by splitting up the dynamic parts and inserting them where they are needed. -```rust +```rust, no_run {{#include ../../../examples/conditional_rendering.rs:if_else_improved}} ``` @@ -26,18 +26,17 @@ We can improve this example by splitting up the dynamic parts and inserting them Since `Element` is a `Option`, components accepting `Element` as a prop can inspect its contents, and render different things based on that. Example: -```rust +```rust, no_run {{#include ../../../examples/component_children_inspect.rs:Clickable}} ``` You can't mutate the `Element`, but if you need a modified version of it, you can construct a new one based on its attributes/children/etc. - ## Rendering Nothing To render nothing, you can return `None` from a component. This is useful if you want to conditionally hide something: -```rust +```rust, no_run {{#include ../../../examples/conditional_rendering.rs:conditional_none}} ``` @@ -58,15 +57,15 @@ For this, Dioxus accepts iterators that produce `Element`s. So we need to: Example: suppose you have a list of comments you want to render. Then, you can render them like this: -```rust +```rust, no_run {{#include ../../../examples/rendering_lists.rs:render_list}} ``` ### Inline for loops -Because of how common it is to render a list of items, Dioxus provides a shorthand for this. Instead of using `.iter, `.map`, and `rsx`, you can use a `for` loop with a body of rsx code: +Because of how common it is to render a list of items, Dioxus provides a shorthand for this. Instead of using `.iter`, `.map`, and `rsx`, you can use a `for` loop with a body of rsx code: -```rust +```rust, no_run {{#include ../../../examples/rendering_lists.rs:render_list_for_loop}} ``` diff --git a/docs/guide/src/en/interactivity/event_handlers.md b/docs/guide/src/en/interactivity/event_handlers.md index 5e12ce259..4c77cef1e 100644 --- a/docs/guide/src/en/interactivity/event_handlers.md +++ b/docs/guide/src/en/interactivity/event_handlers.md @@ -8,7 +8,7 @@ Event handlers are similar to regular attributes, but their name usually starts For example, to handle clicks on an element, we can specify an `onclick` handler: -```rust +```rust, no_run {{#include ../../../examples/event_click.rs:rsx}} ``` @@ -29,11 +29,11 @@ To learn what the different event types for HTML provide, read the [events modul Some events will trigger first on the element the event originated at upward. For example, a click event on a `button` inside a `div` would first trigger the button's event listener and then the div's event listener. -> For more information about event propigation see [the mdn docs on event bubling](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#event_bubbling) +> For more information about event propagation see [the mdn docs on event bubbling](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#event_bubbling) -If you want to prevent this behavior, you can call `stop_propogation()` on the event: +If you want to prevent this behavior, you can call `stop_propagation()` on the event: -```rust +```rust, no_run {{#include ../../../examples/event_nested.rs:rsx}} ``` @@ -41,27 +41,27 @@ If you want to prevent this behavior, you can call `stop_propogation()` on the e Some events have a default behavior. For keyboard events, this might be entering the typed character. For mouse events, this might be selecting some text. -In some instances, might want to avoid this default behavior. For this, you can add the `prevent_default` attribute with the name of the handler whose default behavior you want to stop. This attribute is special: you can attach it multiple times for multiple attributes: +In some instances, might want to avoid this default behavior. For this, you can add the `prevent_default` attribute with the name of the handler whose default behavior you want to stop. This attribute can be used for multiple handlers using their name separated by spaces: -```rust +```rust, no_run {{#include ../../../examples/event_prevent_default.rs:prevent_default}} ``` Any event handlers will still be called. -> Normally, in React or JavaScript, you'd call "preventDefault" on the event in the callback. Dioxus does *not* currently support this behavior. Note: this means you cannot conditionally prevent default behavior based on the data in the event. +> Normally, in React or JavaScript, you'd call "preventDefault" on the event in the callback. Dioxus does _not_ currently support this behavior. Note: this means you cannot conditionally prevent default behavior based on the data in the event. ## Handler Props Sometimes, you might want to make a component that accepts an event handler. A simple example would be a `FancyButton` component, which accepts an `on_click` handler: -```rust +```rust, no_run {{#include ../../../examples/event_handler_prop.rs:component_with_handler}} ``` Then, you can use it like any other handler: -```rust +```rust, no_run {{#include ../../../examples/event_handler_prop.rs:usage}} ``` diff --git a/docs/guide/src/en/interactivity/hooks.md b/docs/guide/src/en/interactivity/hooks.md index 3539e5884..6851aacbf 100644 --- a/docs/guide/src/en/interactivity/hooks.md +++ b/docs/guide/src/en/interactivity/hooks.md @@ -14,9 +14,10 @@ Hooks allow us to create state in our components. Hooks are Rust functions that For example, you might have seen the counter example, in which state (a number) is tracked using the `use_state` hook: -```rust +```rust, no_run {{#include ../../../examples/hooks_counter.rs:component}} ``` + ![Screenshot: counter app](./images/counter.png) Every time the component's state changes, it re-renders, and the component function is called, so you can describe what you want the new UI to look like. You don't have to worry about "changing" anything – just describe what you want in terms of the state, and Dioxus will take care of the rest! @@ -25,9 +26,10 @@ Every time the component's state changes, it re-renders, and the component funct You can use multiple hooks in the same component if you want: -```rust +```rust, no_run {{#include ../../../examples/hooks_counter_two_state.rs:component}} ``` + ![Screenshot: app with two counters](./images/counter_two_state.png) ## Rules of Hooks @@ -36,7 +38,7 @@ The above example might seem a bit magic, since Rust functions are typically not But how can Dioxus differentiate between multiple hooks in the same component? As you saw in the second example, both `use_state` functions were called with the same parameters, so how come they can return different things when the counters are different? -```rust +```rust, no_run {{#include ../../../examples/hooks_counter_two_state.rs:use_state_calls}} ``` @@ -44,24 +46,27 @@ This is only possible because the two hooks are always called in the same order, 1. Hooks may be only used in components or other hooks (we'll get to that later) 2. On every call to the component function - 1. The same hooks must be called + 1. The same hooks must be called (except in the case of early returns, as explained later in the [Error Handling chapter](../best_practices/error_handling.md)) 2. In the same order 3. Hooks name's should start with `use_` so you don't accidentally confuse them with regular functions These rules mean that there are certain things you can't do with hooks: ### No Hooks in Conditionals -```rust + +```rust, no_run {{#include ../../../examples/hooks_bad.rs:conditional}} ``` ### No Hooks in Closures -```rust + +```rust, no_run {{#include ../../../examples/hooks_bad.rs:closure}} ``` ### No Hooks in Loops -```rust + +```rust, no_run {{#include ../../../examples/hooks_bad.rs:loop}} ``` @@ -75,9 +80,8 @@ Thankfully, there is another hook for that, `use_ref`! It is similar to `use_sta Here's a simple example that keeps a list of events in a `use_ref`. We can acquire write access to the state with `.with_mut()`, and then just `.push` a new value to the state: -```rust +```rust, no_run {{#include ../../../examples/hooks_use_ref.rs:component}} ``` > The return values of `use_state` and `use_ref` (`UseState` and `UseRef`, respectively) are in some ways similar to [`Cell`](https://doc.rust-lang.org/std/cell/) and [`RefCell`](https://doc.rust-lang.org/std/cell/struct.RefCell.html) – they provide interior mutability. However, these Dioxus wrappers also ensure that the component gets re-rendered whenever you change the state. - diff --git a/docs/guide/src/en/interactivity/router.md b/docs/guide/src/en/interactivity/router.md index 90a90e8a9..c5f8c7c36 100644 --- a/docs/guide/src/en/interactivity/router.md +++ b/docs/guide/src/en/interactivity/router.md @@ -4,7 +4,6 @@ In many of your apps, you'll want to have different "scenes". For a webpage, the To unify these platforms, Dioxus provides a first-party solution for scene management called Dioxus Router. - ## What is it? For an app like the Dioxus landing page (https://dioxuslabs.com), we want to have several different scenes: @@ -20,12 +19,11 @@ The Dioxus router makes it easy to create these scenes. To make sure we're using cargo add dioxus-router ``` - ## Using the router Unlike other routers in the Rust ecosystem, our router is built declaratively. This makes it possible to compose our app layout simply by arranging components. -```rust +```rust, no_run rsx!{ // All of our routes will be rendered inside this Router component Router { @@ -43,7 +41,7 @@ We can fix this one of two ways: - A fallback 404 page -```rust +```rust, no_run rsx!{ Router { Route { to: "/home", Home {} } @@ -54,10 +52,9 @@ rsx!{ } ``` - - Redirect 404 to home -```rust +```rust, no_run rsx!{ Router { Route { to: "/home", Home {} } @@ -72,8 +69,7 @@ rsx!{ For our app to navigate these routes, we can provide clickable elements called Links. These simply wrap `` elements that, when clicked, navigate the app to the given location. - -```rust +```rust, no_run rsx!{ Link { to: "/home", @@ -84,4 +80,4 @@ rsx!{ ## More reading -This page is just a very brief overview of the router. For more information, check out [the router book](https://dioxuslabs.com/router/guide/) or some of [the router examples](https://github.com/DioxusLabs/dioxus/blob/master/examples/router.rs). +This page is just a very brief overview of the router. For more information, check out [the router book](https://dioxuslabs.com/docs/0.3/router/) or some of [the router examples](https://github.com/DioxusLabs/dioxus/blob/master/examples/router.rs). diff --git a/docs/guide/src/en/interactivity/sharing_state.md b/docs/guide/src/en/interactivity/sharing_state.md index 75ace8973..4c97e53bf 100644 --- a/docs/guide/src/en/interactivity/sharing_state.md +++ b/docs/guide/src/en/interactivity/sharing_state.md @@ -11,7 +11,8 @@ Suppose we want to build a meme editor. We want to have an input to edit the mem > Of course, in this simple example, we could write everything in one component – but it is better to split everything out in smaller components to make the code more reusable, maintainable, and performant (this is even more important for larger, complex apps). We start with a `Meme` component, responsible for rendering a meme with a given caption: -```rust + +```rust, no_run {{#include ../../../examples/meme_editor.rs:meme_component}} ``` @@ -19,14 +20,16 @@ We start with a `Meme` component, responsible for rendering a meme with a given We also create a caption editor, completely decoupled from the meme. The caption editor must not store the caption itself – otherwise, how will we provide it to the `Meme` component? Instead, it should accept the current caption as a prop, as well as an event handler to delegate input events to: -```rust +```rust, no_run {{#include ../../../examples/meme_editor.rs:caption_editor}} ``` Finally, a third component will render the other two as children. It will be responsible for keeping the state and passing down the relevant props. -```rust + +```rust, no_run {{#include ../../../examples/meme_editor.rs:meme_editor}} ``` + ![Meme Editor Screenshot: An old plastic skeleton sitting on a park bench. Caption: "me waiting for a language feature"](./images/meme_editor_screenshot.png) ## Using Context @@ -43,24 +46,26 @@ Dioxus offers a better solution than this "prop drilling" – providing context. First, we have to create a struct for our dark mode configuration: -```rust +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:DarkMode_struct}} ``` Now, in a top-level component (like `App`), we can provide the `DarkMode` context to all children components: -```rust + +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:context_provider}} ``` As a result, any child component of `App` (direct or not), can access the `DarkMode` context. -```rust + +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:use_context}} ``` > `use_context` returns `Option>` here. If the context has been provided, the value is `Some(UseSharedState)`, which you can call `.read` or `.write` on, similarly to `UseRef`. Otherwise, the value is `None`. For example, here's how we would implement the dark mode toggle, which both reads the context (to determine what color it should render) and writes to it (to toggle dark mode): -```rust + +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:toggle}} ``` - diff --git a/docs/guide/src/en/interactivity/user_input.md b/docs/guide/src/en/interactivity/user_input.md index e39dbcde5..6470588e5 100644 --- a/docs/guide/src/en/interactivity/user_input.md +++ b/docs/guide/src/en/interactivity/user_input.md @@ -6,11 +6,12 @@ Interfaces often need to provide a way to input data: e.g. text, numbers, checkb With controlled inputs, you are directly in charge of the state of the input. This gives you a lot of flexibility, and makes it easy to keep things in sync. For example, this is how you would create a controlled text input: -```rust +```rust, no_run {{#include ../../../examples/input_controlled.rs:component}} ``` Notice the flexibility – you can: + - Also display the same contents in another element, and they will be in sync - Transform the input every time it is modified (e.g. to make sure it is upper case) - Validate the input every time it changes @@ -23,9 +24,10 @@ As an alternative to controlled inputs, you can simply let the platform keep tra Since you don't necessarily have the current value of the uncontrolled input in state, you can access it either by listening to `oninput` events (similarly to controlled components), or, if the input is part of a form, you can access the form data in the form events (e.g. `oninput` or `onsubmit`): -```rust +```rust, no_run {{#include ../../../examples/input_uncontrolled.rs:component}} ``` + ``` Submitted! UiEvent { data: FormData { value: "", values: {"age": "very old", "date": "1966", "name": "Fred"} } } -``` \ No newline at end of file +``` diff --git a/docs/guide/src/pt-br/async/spawn.md b/docs/guide/src/pt-br/async/spawn.md index 95f7e2e3f..3c00934cf 100644 --- a/docs/guide/src/pt-br/async/spawn.md +++ b/docs/guide/src/pt-br/async/spawn.md @@ -2,7 +2,7 @@ Os **"hooks"** `use_future` e `use_coroutine` são úteis se você quiser gerar incondicionalmente o `Future`. Às vezes, porém, você desejará apenas gerar um `Future` em resposta a um evento, como um clique do mouse. Por exemplo, suponha que você precise enviar uma solicitação quando o usuário clicar em um botão "log in". Para isso, você pode usar `cx.spawn`: -```rust +```rust, no_run {{#include ../../../examples/spawn.rs:spawn}} ``` @@ -14,7 +14,7 @@ No entanto, como você normalmente precisa de uma maneira de atualizar o valor d Para tornar isso um pouco menos detalhado, o Dioxus exporta a macro `to_owned!` que criará uma ligação como mostrado acima, o que pode ser bastante útil ao lidar com muitos valores. -```rust +```rust, no_run {{#include ../../../examples/spawn.rs:to_owned_macro}} ``` @@ -24,6 +24,6 @@ Calling `spawn` will give you a `JoinHandle` which lets you cancel or pause the Às vezes, você pode querer gerar uma tarefa em segundo plano que precise de vários _threads_ ou conversar com o hardware que pode bloquear o código do seu aplicativo. Nesses casos, podemos gerar diretamente uma tarefa Tokio do nosso `Future`. Para Dioxus-Desktop, sua tarefa será gerada no tempo de execução Multi-Tarefado do Tokio: -```rust +```rust, no_run {{#include ../../../examples/spawn.rs:tokio}} ``` diff --git a/docs/guide/src/pt-br/async/use_coroutine.md b/docs/guide/src/pt-br/async/use_coroutine.md index cd7cbff11..d7edbd8cc 100644 --- a/docs/guide/src/pt-br/async/use_coroutine.md +++ b/docs/guide/src/pt-br/async/use_coroutine.md @@ -8,7 +8,7 @@ Assim como os `Futures` regulares, o código em uma corrotina Dioxus será execu A configuração básica para corrotinas é o _hook_ `use_coroutine`. A maioria das corrotinas que escrevemos serão _loops_ de pesquisa usando `async`/`await`. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let ws: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // Connect to some sort of service @@ -26,7 +26,7 @@ Para muitos serviços, um _loop_ assíncrono simples lidará com a maioria dos c No entanto, se quisermos desabilitar temporariamente a corrotina, podemos "pausá-la" usando o método `pause` e "retomá-la" usando o método `resume`: -```rust +```rust, no_run let sync: &UseCoroutine<()> = use_coroutine(cx, |rx| async move { // code for syncing }); @@ -56,7 +56,7 @@ Você deve ter notado que o encerramento `use_coroutine` recebe um argumento cha Usando corrotinas, temos a oportunidade de centralizar nossa lógica assíncrona. O parâmetro `rx` é um canal ilimitado para código externo à corrotina para enviar dados _para_ a corrotina. Em vez de fazer um _loop_ em um serviço externo, podemos fazer um _loop_ no próprio canal, processando mensagens de dentro de nosso aplicativo sem precisar gerar um novo `Future`. Para enviar dados para a corrotina, chamaríamos "send" no _handle_. -```rust +```rust, no_run enum ProfileUpdate { SetUsername(String), SetAge(i32) @@ -84,7 +84,7 @@ cx.render(rsx!{ Para aplicativos suficientemente complexos, poderíamos criar vários "serviços" úteis diferentes que fazem um _loop_ nos canais para atualizar o aplicativo. -```rust +```rust, no_run let profile = use_coroutine(cx, profile_service); let editor = use_coroutine(cx, editor_service); let sync = use_coroutine(cx, sync_service); @@ -104,7 +104,7 @@ async fn editor_service(rx: UnboundedReceiver) { Podemos combinar corrotinas com `Fermi` para emular o sistema `Thunk` do **Redux Toolkit** com muito menos dor de cabeça. Isso nos permite armazenar todo o estado do nosso aplicativo _dentro_ de uma tarefa e, em seguida, simplesmente atualizar os valores de "visualização" armazenados em `Atoms`. Não pode ser subestimado o quão poderosa é essa técnica: temos todas as vantagens das tarefas nativas do Rust com as otimizações e ergonomia do estado global. Isso significa que seu estado _real_ não precisa estar vinculado a um sistema como `Fermi` ou `Redux` – os únicos `Atoms` que precisam existir são aqueles que são usados para controlar a interface. -```rust +```rust, no_run static USERNAME: Atom = |_| "default".to_string(); fn app(cx: Scope) -> Element { @@ -128,7 +128,7 @@ fn Banner(cx: Scope) -> Element { Agora, em nosso serviço de sincronização, podemos estruturar nosso estado como quisermos. Só precisamos atualizar os valores da _view_ quando estiver pronto. -```rust +```rust, no_run enum SyncAction { SetUsername(String), } @@ -155,7 +155,7 @@ async fn sync_service(mut rx: UnboundedReceiver, atoms: AtomRoot) { Para obter valores de uma corrotina, basta usar um identificador `UseState` e definir o valor sempre que sua corrotina concluir seu trabalho. -```rust +```rust, no_run let sync_status = use_state(cx, || Status::Launching); let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { to_owned![sync_status]; @@ -172,7 +172,7 @@ let sync_task = use_coroutine(cx, |rx: UnboundedReceiver| { Os identificadores de corrotina são injetados automaticamente por meio da API de contexto. `use_coroutine_handle` com o tipo de mensagem como genérico pode ser usado para buscar um _handle_. -```rust +```rust, no_run fn Child(cx: Scope) -> Element { let sync_task = use_coroutine_handle::(cx); diff --git a/docs/guide/src/pt-br/async/use_future.md b/docs/guide/src/pt-br/async/use_future.md index 85f435e35..1e7030ddf 100644 --- a/docs/guide/src/pt-br/async/use_future.md +++ b/docs/guide/src/pt-br/async/use_future.md @@ -4,7 +4,7 @@ Por exemplo, podemos fazer uma solicitação de API dentro de `use_future`: -```rust +```rust, no_run {{#include ../../../examples/use_future.rs:use_future}} ``` @@ -14,7 +14,7 @@ Podemos usar `.value()` para obter o resultado do `Future`. Na primeira execuç Podemos então renderizar esse resultado: -```rust +```rust, no_run {{#include ../../../examples/use_future.rs:render}} ``` @@ -26,6 +26,6 @@ O identificador `UseFuture` fornece um método `restart`. Ele pode ser usado par Muitas vezes, você precisará executar o `Future` novamente toda vez que algum valor (por exemplo, uma prop) mudar. Ao invés de `.restart` manualmente, você pode fornecer uma tupla de "dependências" para o gancho. Ele executará automaticamente o `Future` quando qualquer uma dessas dependências for alterada. Exemplo: -```rust +```rust, no_run {{#include ../../../examples/use_future.rs:dependency}} ``` diff --git a/docs/guide/src/pt-br/best_practices/antipatterns.md b/docs/guide/src/pt-br/best_practices/antipatterns.md index 53fa71df0..fa57ba125 100644 --- a/docs/guide/src/pt-br/best_practices/antipatterns.md +++ b/docs/guide/src/pt-br/best_practices/antipatterns.md @@ -8,7 +8,7 @@ Os fragmentos não montam um elemento físico no DOM imediatamente, então o Dio Apenas os nós Componente e Fragmento são suscetíveis a esse problema. O Dioxus atenua isso com componentes fornecendo uma API para registrar o estado compartilhado sem o padrão _Context Provider_. -```rust +```rust, no_run {{#include ../../../examples/anti_patterns.rs:nested_fragments}} ``` @@ -16,7 +16,7 @@ Apenas os nós Componente e Fragmento são suscetíveis a esse problema. O Dioxu Conforme descrito no capítulo de renderização condicional, os itens da lista devem ter _keys_ exclusivas associadas aos mesmos itens nas renderizações. Isso ajuda o Dioxus a associar o estado aos componentes contidos e garante um bom desempenho de diferenciação. Não omita as _keys_, a menos que você saiba que a lista é estática e nunca será alterada. -```rust +```rust, no_run {{#include ../../../examples/anti_patterns.rs:iter_keys}} ``` diff --git a/docs/guide/src/pt-br/best_practices/error_handling.md b/docs/guide/src/pt-br/best_practices/error_handling.md index 938322234..7e027e9d0 100644 --- a/docs/guide/src/pt-br/best_practices/error_handling.md +++ b/docs/guide/src/pt-br/best_practices/error_handling.md @@ -8,7 +8,7 @@ No entanto, não falamos sobre tratamento de erros neste guia! Neste capítulo, Observadores astutos podem ter notado que `Element` é na verdade um alias de tipo para `Option`. Você não precisa saber o que é um `VNode`, mas é importante reconhecer que não poderíamos retornar nada: -```rust +```rust, no_run fn App(cx: Scope) -> Element { None } @@ -18,7 +18,7 @@ Isso nos permite adicionar um pouco de açúcar sintático para operações que > A natureza de `Option` pode mudar no futuro à medida que a característica `try` for atualizada. -```rust +```rust, no_run fn App(cx: Scope) -> Element { // immediately return "None" let name = cx.use_hook(|_| Some("hi"))?; @@ -29,7 +29,7 @@ fn App(cx: Scope) -> Element { Como o Rust não pode aceitar opções e resultados com a infraestrutura _try_ existente, você precisará manipular os resultados manualmente. Isso pode ser feito convertendo-os em `Option` ou manipulando-os explicitamente. -```rust +```rust, no_run fn App(cx: Scope) -> Element { // Convert Result to Option let name = cx.use_hook(|_| "1.234").parse().ok()?; @@ -52,13 +52,13 @@ A próxima "melhor" maneira de lidar com erros no Dioxus é combinar (`match`) o Para fazer isso, simplesmente temos um estado de erro embutido em nosso componente: -```rust +```rust, no_run let err = use_state(cx, || None); ``` Sempre que realizarmos uma ação que gere um erro, definiremos esse estado de erro. Podemos então combinar o erro de várias maneiras (retorno antecipado, elemento de retorno etc.). -```rust +```rust, no_run fn Commandline(cx: Scope) -> Element { let error = use_state(cx, || None); @@ -79,7 +79,7 @@ fn Commandline(cx: Scope) -> Element { Se você estiver lidando com alguns componentes com um mínimo de aninhamento, basta passar o identificador de erro para componentes filhos. -```rust +```rust, no_run fn Commandline(cx: Scope) -> Element { let error = use_state(cx, || None); @@ -106,7 +106,7 @@ Para começar, considere usar um _hook_ embutido como `use_context` e `use_conte No "topo" de nossa arquitetura, queremos declarar explicitamente um valor que pode ser um erro. -```rust +```rust, no_run enum InputError { None, TooLong, @@ -118,7 +118,7 @@ static INPUT_ERROR: Atom = |_| InputError::None; Então, em nosso componente de nível superior, queremos tratar explicitamente o possível estado de erro para esta parte da árvore. -```rust +```rust, no_run fn TopLevel(cx: Scope) -> Element { let error = use_read(cx, INPUT_ERROR); @@ -132,7 +132,7 @@ fn TopLevel(cx: Scope) -> Element { Agora, sempre que um componente _downstream_ tiver um erro em suas ações, ele pode simplesmente definir seu próprio estado de erro: -```rust +```rust, no_run fn Commandline(cx: Scope) -> Element { let set_error = use_set(cx, INPUT_ERROR); diff --git a/docs/guide/src/pt-br/custom_renderer/index.md b/docs/guide/src/pt-br/custom_renderer/index.md index 68881382a..195f9d6ca 100644 --- a/docs/guide/src/pt-br/custom_renderer/index.md +++ b/docs/guide/src/pt-br/custom_renderer/index.md @@ -21,7 +21,7 @@ Como referência, confira o interpretador `javascript` ou o renderizador `tui` c O tipo "DomEdit" é uma `enum` serializada que representa uma operação atômica que ocorre no `RealDom`. As variantes seguem aproximadamente este conjunto: -```rust +```rust, no_run enum DomEdit { PushRoot, AppendChildren, @@ -48,7 +48,7 @@ O mecanismo de diferenciação Dioxus opera como uma [máquina de pilha] (https: Para fins de compreensão, vamos considerar este exemplo – uma declaração de interface do usuário muito simples: -```rust +```rust, no_run rsx!( h1 {"hello world"} ) ``` @@ -56,7 +56,7 @@ Para começar, o Dioxus deve primeiro navegar até o contêiner dessa tag h1. Pa Quando o renderizador recebe essa instrução, ele empurra o `Node` real para sua própria pilha. A pilha do renderizador real ficará assim: -```rust +```rust, no_run instructions: [ PushRoot(Container) ] @@ -67,7 +67,7 @@ stack: [ Em seguida, o Dioxus encontrará o nó `h1`. O algoritmo `diff` decide que este nó precisa ser criado, então o Dioxus irá gerar o DomEdit `CreateElement`. Quando o renderizador receber esta instrução, ele criará um nó desmontado e o enviará para sua própria pilha (_stack_): -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -80,7 +80,7 @@ stack: [ Em seguida, Dioxus vê o nó de texto e gera o DomEdit `CreateTextNode`: -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -95,7 +95,7 @@ stack: [ Lembre-se, o nó de texto não está anexado a nada (ele está desmontado), então o Dioxus precisa gerar um _Edit_ que conecte o nó de texto ao elemento `h1`. Depende da situação, mas neste caso usamos `AppendChildren`. Isso remove o nó de texto da _stack_, deixando o elemento `h1` como o próximo elemento na linha. -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -110,7 +110,7 @@ stack: [ Chamamos `AppendChildren` novamente, retirando o nó `h1` e anexando-o ao pai: -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -125,7 +125,7 @@ stack: [ Finalmente, o contêiner é aberto, pois não precisamos mais dele. -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -139,7 +139,7 @@ stack: [] Com o tempo, nossa _stack_ ficou assim: -```rust +```rust, no_run [] [Container] [Container, h1] @@ -165,7 +165,7 @@ Como a maioria das GUIs, o Dioxus conta com um _loop_ de eventos para progredir O código para a implementação do `WebSys` é direto, então vamos adicioná-lo aqui para demonstrar como um `loop` de eventos é simples: -```rust +```rust, no_run pub async fn run(&mut self) -> dioxus_core::error::Result<()> { // Push the body element onto the WebsysDom's stack machine let mut websys_dom = crate::new::WebsysDom::new(prepare_websys_dom()); @@ -195,7 +195,7 @@ pub async fn run(&mut self) -> dioxus_core::error::Result<()> { É importante que você decodifique os eventos reais do seu sistema de eventos no sistema de eventos sintético do Dioxus (entenda sintético como abstraído). Isso significa simplesmente combinar seu tipo de evento e criar um tipo Dioxus `UserEvent`. No momento, o sistema `VirtualEvent` é modelado quase inteiramente em torno da especificação HTML, mas estamos interessados em reduzi-lo. -```rust +```rust, no_run fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent { match event.type_().as_str() { "keydown" => { @@ -233,7 +233,7 @@ Esses elementos personalizados são definidos como estruturas de unidade com imp Por exemplo, o elemento `div` é (aproximadamente!) definido assim: -```rust +```rust, no_run struct div; impl div { /// Some glorious documentation about the class property. @@ -262,7 +262,7 @@ O `RealDom` é uma abstração de nível superior sobre a atualização do Dom. Vamos construir um renderizador de exemplo com bordas, tamanho e cor do texto. Antes de começarmos, vamos dar uma olhada em um elemento de exemplo que podemos renderizar: -```rust +```rust, no_run cx.render(rsx!{ div{ color: "red", @@ -280,50 +280,50 @@ No diagrama a seguir, as setas representam o fluxo de dados: [![](https://mermaid.ink/img/pako:eNqdVNFqgzAU_RXJXizUUZPJmIM-jO0LukdhpCbO0JhIGteW0n9fNK1Oa0brfUnu9VxyzzkXjyCVhIIYZFzu0hwr7X2-JcIzsa3W3wqXuZdKoele22oddfa1Y0Tnfn31muvMfqeCDNq3GmvaNROmaKqZFO1DPTRhP8MOd1fTWYNDvzlmQbBMJZcq9JtjNgY1mLVUhBqQPQeojl3wGCw5PsjqnIe-zXqEL8GZ2Kz0gVMPmoeU3ND4IcuiaLGY2zRouuKncv_qGKv3VodpJe0JVU6QCQ5kgqMyWQVr8hbk4hm1PBcmsuwmnrCVH94rP7xN_ucp8sOB_EPSfz9drYVrkpc_AmH8_yTjJueUc-ntpOJkgt2os9tKjcYlt-DLUiD3UsB2KZCLcwjv3Aq33-g2v0M0xXA0MBy5DUdXi-gcJZriuLmAOSioKjAj5ld8rMsJ0DktaAJicyVYbRKQiJPBVSUx438QpqUCcYb5ls4BrrRcHUTaFizqnWGzR8W5evoFI-bJdw)](https://mermaid-js.github.io/mermaid-live-editor/edit#pako:eNqdVNFqgzAU_RXJXizUUZPJmIM-jO0LukdhpCbO0JhIGteW0n9fNK1Oa0brfUnu9VxyzzkXjyCVhIIYZFzu0hwr7X2-JcIzsa3W3wqXuZdKoele22oddfa1Y0Tnfn31muvMfqeCDNq3GmvaNROmaKqZFO1DPTRhP8MOd1fTWYNDvzlmQbBMJZcq9JtjNgY1mLVUhBqQPQeojl3wGCw5PsjqnIe-zXqEL8GZ2Kz0gVMPmoeU3ND4IcuiaLGY2zRouuKncv_qGKv3VodpJe0JVU6QCQ5kgqMyWQVr8hbk4hm1PBcmsuwmnrCVH94rP7xN_ucp8sOB_EPSfz9drYVrkpc_AmH8_yTjJueUc-ntpOJkgt2os9tKjcYlt-DLUiD3UsB2KZCLcwjv3Aq33-g2v0M0xXA0MBy5DUdXi-gcJZriuLmAOSioKjAj5ld8rMsJ0DktaAJicyVYbRKQiJPBVSUx438QpqUCcYb5ls4BrrRcHUTaFizqnWGzR8W5evoFI-bJdw) -[//]: # '%% mermaid flow chart' -[//]: # 'flowchart TB' -[//]: # ' subgraph context' -[//]: # ' text_width(text width)' -[//]: # ' end' -[//]: # ' subgraph state' -[//]: # ' direction TB' -[//]: # ' subgraph div state' -[//]: # ' direction TB' -[//]: # ' state1(state)-->color1(color)' -[//]: # ' state1-->border1(border)' -[//]: # ' text_width-.->layout_width1(layout width)' -[//]: # ' linkStyle 2 stroke:#ff5500,stroke-width:4px;' -[//]: # ' state1-->layout_width1' -[//]: # ' end' -[//]: # ' subgraph p state' -[//]: # ' direction TB' -[//]: # ' state2(state)-->color2(color)' -[//]: # ' color1-.->color2' -[//]: # ' linkStyle 5 stroke:#0000ff,stroke-width:4px;' -[//]: # ' state2-->border2(border)' -[//]: # ' text_width-.->layout_width2(layout width)' -[//]: # ' linkStyle 7 stroke:#ff5500,stroke-width:4px;' -[//]: # ' state2-->layout_width2' -[//]: # ' layout_width2-.->layout_width1' -[//]: # ' linkStyle 9 stroke:#00aa00,stroke-width:4px;' -[//]: # ' end' -[//]: # ' subgraph hello world state' -[//]: # ' direction TB' -[//]: # ' state3(state)-->border3(border)' -[//]: # ' state3-->color3(color)' -[//]: # ' color2-.->color3' -[//]: # ' linkStyle 12 stroke:#0000ff,stroke-width:4px;' -[//]: # ' text_width-.->layout_width3(layout width)' -[//]: # ' linkStyle 13 stroke:#ff5500,stroke-width:4px;' -[//]: # ' state3-->layout_width3' -[//]: # ' layout_width3-.->layout_width2' -[//]: # ' linkStyle 15 stroke:#00aa00,stroke-width:4px;' -[//]: # ' end' -[//]: # ' end' +[//]: # "%% mermaid flow chart" +[//]: # "flowchart TB" +[//]: # " subgraph context" +[//]: # " text_width(text width)" +[//]: # " end" +[//]: # " subgraph state" +[//]: # " direction TB" +[//]: # " subgraph div state" +[//]: # " direction TB" +[//]: # " state1(state)-->color1(color)" +[//]: # " state1-->border1(border)" +[//]: # " text_width-.->layout_width1(layout width)" +[//]: # " linkStyle 2 stroke:#ff5500,stroke-width:4px;" +[//]: # " state1-->layout_width1" +[//]: # " end" +[//]: # " subgraph p state" +[//]: # " direction TB" +[//]: # " state2(state)-->color2(color)" +[//]: # " color1-.->color2" +[//]: # " linkStyle 5 stroke:#0000ff,stroke-width:4px;" +[//]: # " state2-->border2(border)" +[//]: # " text_width-.->layout_width2(layout width)" +[//]: # " linkStyle 7 stroke:#ff5500,stroke-width:4px;" +[//]: # " state2-->layout_width2" +[//]: # " layout_width2-.->layout_width1" +[//]: # " linkStyle 9 stroke:#00aa00,stroke-width:4px;" +[//]: # " end" +[//]: # " subgraph hello world state" +[//]: # " direction TB" +[//]: # " state3(state)-->border3(border)" +[//]: # " state3-->color3(color)" +[//]: # " color2-.->color3" +[//]: # " linkStyle 12 stroke:#0000ff,stroke-width:4px;" +[//]: # " text_width-.->layout_width3(layout width)" +[//]: # " linkStyle 13 stroke:#ff5500,stroke-width:4px;" +[//]: # " state3-->layout_width3" +[//]: # " layout_width3-.->layout_width2" +[//]: # " linkStyle 15 stroke:#00aa00,stroke-width:4px;" +[//]: # " end" +[//]: # " end" Para ajudar na construção de um DOM, o núcleo nativo fornece quatro `traits`: `State`, `ChildDepState`, `ParentDepState` e `NodeDepState` e uma estrutura `RealDom`. O `ChildDepState`, `ParentDepState` e `NodeDepState` fornecem uma maneira de descrever como algumas informações em um nó se relacionam com as de seus parentes. Ao fornecer como construir um único nó a partir de suas relações, o native-core derivará uma maneira de atualizar o estado de todos os nós para você com `#[derive(State)]`. Depois de ter um estado, você pode fornecê-lo como genérico ao `RealDom`. `RealDom` fornece todos os métodos para interagir e atualizar seu novo dom. -```rust +```rust, no_run use dioxus_native_core::node_ref::*; use dioxus_native_core::state::{ChildDepState, NodeDepState, ParentDepState, State}; use dioxus_native_core_macro::{sorted_str_slice, State}; @@ -455,7 +455,7 @@ struct ToyState { Agora que temos nosso estado, podemos colocá-lo em uso em nosso DOM. Você pode atualizar o DOM com `update_state` para atualizar a estrutura do dom (adicionando, removendo e alterando as propriedades dos nós) e então `apply_mutations` para atualizar o `ToyState` para cada um dos nós que foram alterados. -```rust +```rust, no_run fn main(){ fn app(cx: Scope) -> Element { cx.render(rsx!{ diff --git a/docs/guide/src/pt-br/describing_ui/component_children.md b/docs/guide/src/pt-br/describing_ui/component_children.md index 433213616..9663dca19 100644 --- a/docs/guide/src/pt-br/describing_ui/component_children.md +++ b/docs/guide/src/pt-br/describing_ui/component_children.md @@ -2,13 +2,13 @@ Em alguns casos, você pode desejar criar um componente que atue como um contêiner para algum outro conteúdo, sem que o componente precise saber qual é esse conteúdo. Para conseguir isso, crie uma _prop_ do tipo `Element`: -```rust +```rust, no_run {{#include ../../../examples/component_element_props.rs:Clickable}} ``` Então, ao renderizar o componente, você pode passar a saída de `cx.render(rsx!(...))`: -```rust +```rust, no_run {{#include ../../../examples/component_element_props.rs:Clickable_usage}} ``` @@ -20,12 +20,12 @@ Então, ao renderizar o componente, você pode passar a saída de `cx.render(rsx Em vez de passar o `RSX` através de uma _prop_ regular, você pode querer aceitar filhos da mesma forma que os elementos podem ter filhos. O prop "mágico" `children` permite que você consiga isso: -```rust +```rust, no_run {{#include ../../../examples/component_children.rs:Clickable}} ``` Isso torna o uso do componente muito mais simples: basta colocar o `RSX` dentro dos colchetes `{}` – e não há necessidade de uma chamada `render` ou outra macro! -```rust +```rust, no_run {{#include ../../../examples/component_children.rs:Clickable_usage}} ``` diff --git a/docs/guide/src/pt-br/describing_ui/component_props.md b/docs/guide/src/pt-br/describing_ui/component_props.md index 7d3b8e976..4cb5a50ca 100644 --- a/docs/guide/src/pt-br/describing_ui/component_props.md +++ b/docs/guide/src/pt-br/describing_ui/component_props.md @@ -19,13 +19,13 @@ Existem 2 tipos de estruturas Props: _Props_ próprios são muito simples – eles não emprestam nada. Exemplo: -```rust +```rust, no_run {{#include ../../../examples/component_owned_props.rs:Likes}} ``` Você pode então passar valores de _prop_ para o componente da mesma forma que você passaria atributos para um elemento: -```rust +```rust, no_run {{#include ../../../examples/component_owned_props.rs:App}} ``` @@ -37,13 +37,13 @@ Possuir _props_ funciona bem se seus _props_ forem fáceis de copiar – como um Rust permite algo mais eficiente – emprestar a `String` como um `&str` – é para isso que servem as _props emprestadas_! -```rust +```rust, no_run {{#include ../../../examples/component_borrowed_props.rs:TitleCard}} ``` Podemos então usar o componente assim: -```rust +```rust, no_run {{#include ../../../examples/component_borrowed_props.rs:App}} ``` @@ -57,13 +57,13 @@ A macro `#[derive(Props)]` tem alguns recursos que permitem personalizar o compo Você pode criar campos opcionais usando o tipo `Option<…>` para um campo: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:OptionalProps}} ``` Em seguida, você pode optar por fornecê-los ou não: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:OptionalProps_usage}} ``` @@ -71,13 +71,13 @@ Em seguida, você pode optar por fornecê-los ou não: Se você quiser exigir explicitamente uma `Option`, e não uma _prop_ opcional, você pode anotá-la com `#[props(!optional)]`: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:ExplicitOption}} ``` Então, você tem que passar explicitamente `Some("str")` ou `None`: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:ExplicitOption_usage}} ``` @@ -85,13 +85,13 @@ Então, você tem que passar explicitamente `Some("str")` ou `None`: Você pode usar `#[props(default = 42)]` para tornar um campo opcional e especificar seu valor padrão: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:DefaultComponent}} ``` Então, da mesma forma que _props_ opcionais, você não precisa fornecê-lo: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:DefaultComponent_usage}} ``` @@ -99,13 +99,13 @@ Então, da mesma forma que _props_ opcionais, você não precisa fornecê-lo: É comum que as funções Rust aceitem `impl Into` em vez de apenas `SomeType` para suportar uma ampla gama de parâmetros. Se você quiser uma funcionalidade semelhante com _props_, você pode usar `#[props(into)]`. Por exemplo, você pode adicioná-lo em uma prop `String` – e `&str` também será aceito automaticamente, pois pode ser convertido em `String`: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:IntoComponent}} ``` Então, você pode usá-lo assim: -```rust +```rust, no_run {{#include ../../../examples/component_props_options.rs:IntoComponent_usage}} ``` @@ -115,7 +115,7 @@ Até agora, todas as funções `Component` que vimos tinham uma _struct_ `Compon `inline_props` permite que você faça exatamente isso. Em vez de digitar a versão "completa": -```rust +```rust, no_run #[derive(Props, PartialEq)] struct TitleCardProps { title: String, @@ -130,7 +130,7 @@ fn TitleCard(cx: Scope) -> Element { ...você pode definir uma função que aceita _props_ como argumentos. Então, basta anotá-lo com `#[inline_props]`, e a macro irá transformá-lo em um componente regular para você: -```rust +```rust, no_run #[inline_props] fn TitleCard(cx: Scope, title: String) -> Element { cx.render(rsx!{ diff --git a/docs/guide/src/pt-br/describing_ui/components.md b/docs/guide/src/pt-br/describing_ui/components.md index d33585cea..91123b5f8 100644 --- a/docs/guide/src/pt-br/describing_ui/components.md +++ b/docs/guide/src/pt-br/describing_ui/components.md @@ -4,7 +4,7 @@ Assim como você não gostaria de escrever um programa complexo em uma única e Um componente é uma função Rust, nomeada em _UpperCammelCase_, que recebe um parâmetro `Scope` e retorna um `Element` descrevendo a interface do usuário que deseja renderizar. Na verdade, nossa função `App` é um componente! -```rust +```rust, no_run {{#include ../../../examples/hello_world_desktop.rs:component}} ``` @@ -12,13 +12,13 @@ Um componente é uma função Rust, nomeada em _UpperCammelCase_, que recebe um Um Componente é responsável por alguma tarefa de renderização – normalmente, renderizando uma parte isolada da interface do usuário. Por exemplo, você pode ter um componente `About` que renderiza uma breve descrição do Dioxus Labs: -```rust +```rust, no_run {{#include ../../../examples/components.rs:About}} ``` Em seguida, você pode renderizar seu componente em outro componente, da mesma forma que os elementos são renderizados: -```rust +```rust, no_run {{#include ../../../examples/components.rs:App}} ``` diff --git a/docs/guide/src/pt-br/describing_ui/index.md b/docs/guide/src/pt-br/describing_ui/index.md index 8da134903..212e67921 100644 --- a/docs/guide/src/pt-br/describing_ui/index.md +++ b/docs/guide/src/pt-br/describing_ui/index.md @@ -4,7 +4,7 @@ Dioxus é uma estrutura _declarativa_. Isso significa que, em vez de dizer ao Di Você já viu um exemplo simples ou sintaxe `RSX` no aplicativo "hello world": -```rust +```rust, no_run {{#include ../../../examples/hello_world_desktop.rs:component}} ``` @@ -14,7 +14,7 @@ Aqui, usamos a macro `rsx!` para _declarar_ que queremos um elemento `div`, cont O RSX é muito semelhante ao HTML, pois descreve elementos com atributos e filhos. Aqui está um elemento `div` vazio no RSX, bem como o HTML resultante: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:empty}} ``` @@ -26,7 +26,7 @@ O RSX é muito semelhante ao HTML, pois descreve elementos com atributos e filho Para adicionar filhos a um elemento, coloque-os dentro dos colchetes `{}`. Eles podem ser outros elementos ou texto. Por exemplo, você pode ter um elemento `ol` (lista ordenada), contendo 3 elementos `li` (item da lista), cada um dos quais contém algum texto: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:children}} ``` @@ -44,7 +44,7 @@ Você também pode "agrupar" elementos envolvendo-os em `Fragment {}`. Isso não > Nota: você também pode renderizar vários elementos no nível superior de `rsx!` e eles serão agrupados automaticamente – não há necessidade de um `Fragment {}` explícito lá. -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:fragments}} ``` @@ -60,7 +60,7 @@ Você também pode "agrupar" elementos envolvendo-os em `Fragment {}`. Isso não Os atributos também são especificados dentro dos colchetes `{}`, usando a sintaxe `name: value`. Você pode fornecer o valor como um literal no RSX: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:attributes}} ``` @@ -79,7 +79,7 @@ Os atributos também são especificados dentro dos colchetes `{}`, usando a sint Dioxus tem um conjunto pré-configurado de atributos que você pode usar. O RSX é validado em tempo de compilação para garantir que você não especificou um atributo inválido. Se você quiser substituir esse comportamento por um nome de atributo personalizado, especifique o atributo entre aspas: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:custom_attributes}} ``` @@ -91,7 +91,7 @@ Dioxus tem um conjunto pré-configurado de atributos que você pode usar. O RSX Da mesma forma que você pode [formatar](https://doc.rust-lang.org/rust-by-example/hello/print/fmt.html) Rust _strings_, você também pode interpolar no texto RSX. Use `{variable}` para exibir o valor de uma variável em uma _string_, ou `{variable:?}` para usar a representação `Debug`: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:formatting}} ``` @@ -107,7 +107,7 @@ Da mesma forma que você pode [formatar](https://doc.rust-lang.org/rust-by-examp Você pode incluir expressões Rust arbitrárias dentro do RSX, mas deve escapá-las entre colchetes `[]`: -```rust +```rust, no_run {{#include ../../../examples/rsx_overview.rs:expression}} ``` diff --git a/docs/guide/src/pt-br/describing_ui/special_attributes.md b/docs/guide/src/pt-br/describing_ui/special_attributes.md index e196f667b..01bfe9b25 100644 --- a/docs/guide/src/pt-br/describing_ui/special_attributes.md +++ b/docs/guide/src/pt-br/describing_ui/special_attributes.md @@ -8,7 +8,7 @@ Se você estiver trabalhando com itens pré-renderizados, modelos ou uma bibliot Por exemplo, enviar um conversor de markdown para Dioxus pode aumentar significativamente o tamanho final do aplicativo. Em vez disso, você desejará pré-renderizar sua remarcação para HTML e, em seguida, incluir o HTML diretamente em sua saída. Usamos essa abordagem para a [página inicial do Dioxus](https://dioxuslabs.com): -```rust +```rust, no_run {{#include ../../../examples/dangerous_inner_html.rs:dangerous_inner_html}} ``` @@ -22,7 +22,7 @@ A maioria dos atributos, quando renderizados, serão renderizados exatamente com Portanto, este RSX não renderizaria o atributo `hidden`: -```rust +```rust, no_run {{#include ../../../examples/boolean_attribute.rs:boolean_attribute}} ``` diff --git a/docs/guide/src/pt-br/getting_started/desktop.md b/docs/guide/src/pt-br/getting_started/desktop.md index 5c6940b96..70f71aa1a 100644 --- a/docs/guide/src/pt-br/getting_started/desktop.md +++ b/docs/guide/src/pt-br/getting_started/desktop.md @@ -35,6 +35,6 @@ cargo add dioxus-desktop Edite seu `main.rs`: -```rust +```rust, no_run {{#include ../../../examples/hello_world_desktop.rs:all}} ``` diff --git a/docs/guide/src/pt-br/getting_started/mobile.md b/docs/guide/src/pt-br/getting_started/mobile.md index edcfbfba7..66a17272b 100644 --- a/docs/guide/src/pt-br/getting_started/mobile.md +++ b/docs/guide/src/pt-br/getting_started/mobile.md @@ -59,7 +59,7 @@ simple_logger = "*" Edite seu `lib.rs`: -```rust +```rust, no_run use dioxus::prelude::*; fn main() { diff --git a/docs/guide/src/pt-br/getting_started/ssr.md b/docs/guide/src/pt-br/getting_started/ssr.md index ddb02a289..ebf478163 100644 --- a/docs/guide/src/pt-br/getting_started/ssr.md +++ b/docs/guide/src/pt-br/getting_started/ssr.md @@ -16,7 +16,7 @@ Ao trabalhar com frameworks web que requerem `Send`, é possível renderizar um Se você quer apenas renderizar `rsx!` ou um VirtualDom para HTML, confira os documentos da API. É bem simples: -```rust +```rust, no_run // We can render VirtualDoms let mut vdom = VirtualDom::new(app); let _ = vdom.rebuild(); @@ -61,7 +61,7 @@ tokio = { version = "1.15.0", features = ["full"] } Agora, configure seu aplicativo Axum para responder em um _endpoint_. -```rust +```rust, no_run use axum::{response::Html, routing::get, Router}; use dioxus::prelude::*; @@ -83,7 +83,7 @@ async fn main() { E, em seguida, adicione nosso _endpoint_. Podemos renderizar `rsx!` diretamente: -```rust +```rust, no_run async fn app_endpoint() -> Html { Html(dioxus_ssr::render_lazy(rsx! { h1 { "hello world!" } @@ -93,7 +93,7 @@ async fn app_endpoint() -> Html { Ou podemos renderizar `VirtualDoms`. -```rust +```rust, no_run async fn app_endpoint() -> Html { fn app(cx: Scope) -> Element { cx.render(rsx!(h1 { "hello world" })) diff --git a/docs/guide/src/pt-br/getting_started/tui.md b/docs/guide/src/pt-br/getting_started/tui.md index deaf060b6..ba4e2ecda 100644 --- a/docs/guide/src/pt-br/getting_started/tui.md +++ b/docs/guide/src/pt-br/getting_started/tui.md @@ -23,7 +23,7 @@ cargo add dioxus-tui Em seguida, edite seu `main.rs` com o modelo básico. -```rust +```rust, no_run {{#include ../../../examples/hello_world_tui.rs}} ``` @@ -35,7 +35,7 @@ cargo run Pressione "ctrl-c" para fechar o aplicativo. Para mudar de "ctrl-c" para apenas "q" para sair, você pode iniciar o aplicativo com uma configuração para desativar o sair padrão e usar a raiz TuiContext para sair por conta própria. -```rust +```rust, no_run {{#include ../../../examples/hello_world_tui_no_ctrl_c.rs}} ``` diff --git a/docs/guide/src/pt-br/getting_started/web.md b/docs/guide/src/pt-br/getting_started/web.md index ffb322a25..47991b595 100644 --- a/docs/guide/src/pt-br/getting_started/web.md +++ b/docs/guide/src/pt-br/getting_started/web.md @@ -64,7 +64,7 @@ Adicione um `index.html` para o `Trunk` usar. Certifique-se de que seu elemento Edite seu `main.rs`: -```rust +```rust, no_run {{#include ../../../examples/hello_world_web.rs}} ``` diff --git a/docs/guide/src/pt-br/index.md b/docs/guide/src/pt-br/index.md index 121f3ef45..e3d32ebc2 100644 --- a/docs/guide/src/pt-br/index.md +++ b/docs/guide/src/pt-br/index.md @@ -4,7 +4,7 @@ Dioxus é uma estrutura portátil, de alto desempenho e ergonômica para a construção de interfaces de usuário multiplataforma no Rust. Este guia irá ajudá-lo a começar a escrever aplicativos Dioxus para a Web, Desktop, Mobile e muito mais. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let mut count = use_state(cx, || 0); diff --git a/docs/guide/src/pt-br/interactivity/custom_hooks.md b/docs/guide/src/pt-br/interactivity/custom_hooks.md index 881a0946a..c2ac570c4 100644 --- a/docs/guide/src/pt-br/interactivity/custom_hooks.md +++ b/docs/guide/src/pt-br/interactivity/custom_hooks.md @@ -8,7 +8,7 @@ Para evitar a repetição, você pode encapsular a lógica de negócios com base Por exemplo, se muitos componentes precisam acessar uma _struct_ `AppSettings`, você pode criar um gancho de "atalho": -```rust +```rust, no_run {{#include ../../../examples/hooks_composed.rs:wrap_context}} ``` diff --git a/docs/guide/src/pt-br/interactivity/dynamic_rendering.md b/docs/guide/src/pt-br/interactivity/dynamic_rendering.md index 2298735e5..58c120926 100644 --- a/docs/guide/src/pt-br/interactivity/dynamic_rendering.md +++ b/docs/guide/src/pt-br/interactivity/dynamic_rendering.md @@ -6,7 +6,7 @@ Para renderizar diferentes elementos com base em uma condição, você pode usar uma instrução `if-else`: -```rust +```rust, no_run {{#include ../../../examples/conditional_rendering.rs:if_else}} ``` @@ -16,7 +16,7 @@ Para renderizar diferentes elementos com base em uma condição, você pode usar Como `Element` é uma `Option`, os componentes que aceitam `Element` como _prop_ podem realmente inspecionar seu conteúdo e renderizar coisas diferentes com base nisso. Exemplo: -```rust +```rust, no_run {{#include ../../../examples/component_children_inspect.rs:Clickable}} ``` @@ -26,7 +26,7 @@ Você não pode modificar o `Element`, mas se precisar de uma versão modificada Para renderizar nada, você pode retornar `None` de um componente. Isso é útil se você deseja ocultar algo condicionalmente: -```rust +```rust, no_run {{#include ../../../examples/conditional_rendering.rs:conditional_none}} ``` @@ -47,7 +47,7 @@ Para isso, o Dioxus aceita iteradores que produzem `Element`s. Então precisamos Exemplo: suponha que você tenha uma lista de comentários que deseja renderizar. Então, você pode renderizá-los assim: -```rust +```rust, no_run {{#include ../../../examples/rendering_lists.rs:render_list}} ``` diff --git a/docs/guide/src/pt-br/interactivity/event_handlers.md b/docs/guide/src/pt-br/interactivity/event_handlers.md index 2143dba4a..12aad321e 100644 --- a/docs/guide/src/pt-br/interactivity/event_handlers.md +++ b/docs/guide/src/pt-br/interactivity/event_handlers.md @@ -8,7 +8,7 @@ Os manipuladores de eventos são semelhantes aos atributos regulares, mas seus n Por exemplo, para manipular cliques em um elemento, podemos especificar um manipulador `onclick`: -```rust +```rust, no_run {{#include ../../../examples/event_click.rs:rsx}} ``` @@ -29,7 +29,7 @@ Para saber o que os diferentes tipos de eventos fornecem, leia os [documentos do Quando você tem, por exemplo um `button` dentro de um `div`, qualquer clique no `button` também é um clique no `div`. Por esta razão, Dioxus propaga o evento click: primeiro, ele é acionado no elemento alvo, depois nos elementos pai. Se você quiser evitar esse comportamento, você pode chamar `cancel_bubble()` no evento: -```rust +```rust, no_run {{#include ../../../examples/event_click.rs:rsx}} ``` @@ -39,7 +39,7 @@ Alguns eventos têm um comportamento padrão. Para eventos de teclado, isso pode Em alguns casos, você pode querer evitar esse comportamento padrão. Para isso, você pode adicionar o atributo `prevent_default` com o nome do manipulador cujo comportamento padrão você deseja interromper. Este atributo é especial: você pode anexá-lo várias vezes para vários atributos: -```rust +```rust, no_run {{#include ../../../examples/event_prevent_default.rs:prevent_default}} ``` @@ -51,13 +51,13 @@ Quaisquer manipuladores de eventos ainda serão chamados. Às vezes, você pode querer criar um componente que aceite um manipulador de eventos. Um exemplo simples seria um componente `FancyButton`, que aceita um manipulador `on_click`: -```rust +```rust, no_run {{#include ../../../examples/event_handler_prop.rs:component_with_handler}} ``` Então, você pode usá-lo como qualquer outro manipulador: -```rust +```rust, no_run {{#include ../../../examples/event_handler_prop.rs:usage}} ``` diff --git a/docs/guide/src/pt-br/interactivity/hooks.md b/docs/guide/src/pt-br/interactivity/hooks.md index 5f918f623..c5dd85d41 100644 --- a/docs/guide/src/pt-br/interactivity/hooks.md +++ b/docs/guide/src/pt-br/interactivity/hooks.md @@ -14,7 +14,7 @@ Para lógica com estado, você pode usar _hooks_. _Hooks_ são funções Rust qu Por exemplo, você pode ter visto o exemplo do contador, no qual o estado (um número) é rastreado usando o _hook_ `use_state`: -```rust +```rust, no_run {{#include ../../../examples/hooks_counter.rs:component}} ``` @@ -26,7 +26,7 @@ Toda vez que o estado do componente muda, ele é renderizado novamente e a funç Você pode usar vários _hooks_ no mesmo componente se quiser: -```rust +```rust, no_run {{#include ../../../examples/hooks_counter_two_state.rs:component}} ``` @@ -38,7 +38,7 @@ O exemplo acima pode parecer um pouco mágico, já que as funções Rust normalm Mas como Dioxus pode diferenciar entre vários _hooks_ no mesmo componente? Como você viu no segundo exemplo, ambas as funções `use_state` foram chamadas com os mesmos parâmetros, então como elas podem retornar coisas diferentes quando os contadores são diferentes? -```rust +```rust, no_run {{#include ../../../examples/hooks_counter_two_state.rs:use_state_calls}} ``` @@ -54,19 +54,19 @@ Essas regras significam que há certas coisas que você não pode fazer com _hoo ### Sem Hooks em Condicionais -```rust +```rust, no_run {{#include ../../../examples/hooks_bad.rs:conditional}} ``` ### Sem Hooks em Closures -```rust +```rust, no_run {{#include ../../../examples/hooks_bad.rs:closure}} ``` ### Sem Hooks em Loops -```rust +```rust, no_run {{#include ../../../examples/hooks_bad.rs:loop}} ``` @@ -80,7 +80,7 @@ Felizmente, existe outro _hook_ para isso, `use_ref`! É semelhante ao `use_stat Aqui está um exemplo simples que mantém uma lista de eventos em um `use_ref`. Podemos adquirir acesso de escrita ao estado com `.write()`, e então apenas `.push` um novo valor para o estado: -```rust +```rust, no_run {{#include ../../../examples/hooks_use_ref.rs:component}} ``` diff --git a/docs/guide/src/pt-br/interactivity/router.md b/docs/guide/src/pt-br/interactivity/router.md index d3ac7abb9..398546c0c 100644 --- a/docs/guide/src/pt-br/interactivity/router.md +++ b/docs/guide/src/pt-br/interactivity/router.md @@ -26,7 +26,7 @@ dioxus-router = { version = "*" } Ao contrário de outros roteadores no ecossistema Rust, nosso roteador é construído de forma declarativa. Isso torna possível compor o layout do nosso aplicativo simplesmente organizando os componentes. -```rust +```rust, no_run rsx!{ Router { Route { to: "/home", Home {} } @@ -41,7 +41,7 @@ Podemos corrigir isso de duas maneiras: - Uma página 404 de _fallback_ -```rust +```rust, no_run rsx!{ Router { Route { to: "/home", Home {} } @@ -53,7 +53,7 @@ rsx!{ - Redirecionar 404 para _Home_ -```rust +```rust, no_run rsx!{ Router { Route { to: "/home", Home {} } @@ -67,7 +67,7 @@ rsx!{ Para que nosso aplicativo navegue nessas rotas, podemos fornecer elementos clicáveis chamados Links. Eles simplesmente envolvem elementos `` que, quando clicados, navegam no aplicativo para o local determinado. -```rust +```rust, no_run rsx!{ Link { to: "/home", @@ -80,4 +80,4 @@ rsx!{ Esta página é apenas uma breve visão geral do roteador para mostrar que existe uma solução poderosa já construída para um problema muito comum. Para obter mais informações sobre o roteador, confira seu livro ou confira alguns dos exemplos. -O roteador tem sua própria documentação! [Disponível aqui](https://dioxuslabs.com/router/guide/). +O roteador tem sua própria documentação! [Disponível aqui](https://dioxuslabs.com/docs/0.3/router/). diff --git a/docs/guide/src/pt-br/interactivity/sharing_state.md b/docs/guide/src/pt-br/interactivity/sharing_state.md index dba11f17c..b9b829c0c 100644 --- a/docs/guide/src/pt-br/interactivity/sharing_state.md +++ b/docs/guide/src/pt-br/interactivity/sharing_state.md @@ -12,7 +12,7 @@ Por exemplo, suponha que queremos construir um editor de memes. Queremos ter uma Começamos com um componente `Meme`, responsável por renderizar um meme com uma determinada legenda: -```rust +```rust, no_run {{#include ../../../examples/meme_editor.rs:meme_component}} ``` @@ -20,13 +20,13 @@ Começamos com um componente `Meme`, responsável por renderizar um meme com uma Também criamos um editor de legendas, totalmente desacoplado do meme. O editor de legendas não deve armazenar a legenda em si – caso contrário, como iremos fornecê-la ao componente `Meme`? Em vez disso, ele deve aceitar a legenda atual como um suporte, bem como um manipulador de eventos para delegar eventos de entrada para: -```rust +```rust, no_run {{#include ../../../examples/meme_editor.rs:caption_editor}} ``` Finalmente, um terceiro componente renderizará os outros dois como filhos. Ele será responsável por manter o estado e passar os _props_ relevantes. -```rust +```rust, no_run {{#include ../../../examples/meme_editor.rs:meme_editor}} ``` @@ -46,19 +46,19 @@ A Dioxus oferece uma solução melhor do que esta "perfuração com hélice" – Primeiro, temos que criar um _struct_ para nossa configuração de modo escuro: -```rust +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:DarkMode_struct}} ``` Agora, em um componente de nível superior (como `App`), podemos fornecer o contexto `DarkMode` para todos os componentes filhos: -```rust +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:context_provider}} ``` Como resultado, qualquer componente filho de `App` (direto ou não), pode acessar o contexto `DarkMode`. -```rust +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:use_context}} ``` @@ -66,6 +66,6 @@ Como resultado, qualquer componente filho de `App` (direto ou não), pode acessa Por exemplo, aqui está como implementaríamos a alternância do modo escuro, que lê o contexto (para determinar a cor que deve renderizar) e grava nele (para alternar o modo escuro): -```rust +```rust, no_run {{#include ../../../examples/meme_editor_dark_mode.rs:toggle}} ``` diff --git a/docs/guide/src/pt-br/interactivity/user_input.md b/docs/guide/src/pt-br/interactivity/user_input.md index 1afbce439..94a091e38 100644 --- a/docs/guide/src/pt-br/interactivity/user_input.md +++ b/docs/guide/src/pt-br/interactivity/user_input.md @@ -6,7 +6,7 @@ As interfaces geralmente precisam fornecer uma maneira de inserir dados: por exe Com entradas controladas, você fica diretamente responsável pelo estado da entrada. Isso lhe dá muita flexibilidade e facilita manter as coisas em sincronia. Por exemplo, é assim que você criaria uma entrada de texto controlada: -```rust +```rust, no_run {{#include ../../../examples/input_controlled.rs:component}} ``` @@ -24,7 +24,7 @@ Como alternativa às entradas controladas, você pode simplesmente deixar a plat Como você não tem necessariamente o valor atual da entrada não controlada no estado, você pode acessá-lo ouvindo os eventos `oninput` (de maneira semelhante aos componentes controlados) ou, se a entrada for parte de um formulário, você pode acessar os dados do formulário nos eventos do formulário (por exemplo, `oninput` ou `onsubmit`): -```rust +```rust, no_run {{#include ../../../examples/input_uncontrolled.rs:component}} ``` diff --git a/docs/posts/release-0-2-0.md b/docs/posts/release-0-2-0.md index 7aed2fda6..7901ee8b0 100644 --- a/docs/posts/release-0-2-0.md +++ b/docs/posts/release-0-2-0.md @@ -20,12 +20,11 @@ Thanks to these amazing folks for their code contributions: - [@oovm](https://github.com/oovm) - [@6asaaki](https://github.com/6asaaki) - Just over two months in, and we already a ton of awesome changes to Dioxus! Dioxus is a recently-released 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 looks and feels just like React, so if you know React, then you'll feel right at home. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let mut count = use_state(cx, || 0); @@ -39,7 +38,7 @@ fn app(cx: Scope) -> Element { # What's new? -A *ton* of stuff happened in this release; 550+ commits, 23 contributors, 2 minor releases, and 6 backers on Open Collective. +A _ton_ of stuff happened in this release; 550+ commits, 23 contributors, 2 minor releases, and 6 backers on Open Collective. Some of the major new features include: @@ -52,12 +51,10 @@ Some of the major new features include: We also fixed and improved a bunch of stuff - check out the full list down below. - ## A New Renderer: Your terminal! When Dioxus was initially released, we had very simple support for logging Dioxus elements out as TUI elements. In the past month or so, [@Demonthos](https://github.com/Demonthos) really stepped up and made the new crate a reality. - ![Imgur](https://i.imgur.com/GL7uu3r.png) The new TUI renderer even supports mouse movements, keyboard input, async tasks, borders, and a ton more. @@ -66,15 +63,13 @@ The new TUI renderer even supports mouse movements, keyboard input, async tasks, - - ## New Router We totally revamped the router, switching away from the old yew-router approach to the more familiar [React-Router](http://reactrouter.com). It's less type-safe but provides more flexibility and support for beautiful URLs. -Apps with routers are *really* simple now. It's easy to compose the "Router", a "Route", and "Links" to define how your app is laid out: +Apps with routers are _really_ simple now. It's easy to compose the "Router", a "Route", and "Links" to define how your app is laid out: -```rust +```rust, no_run fn app(cx: Scope) -> Element { cx.render(rsx! { Router { @@ -97,7 +92,7 @@ fn app(cx: Scope) -> Element { We're also using hooks to parse the URL parameters and segments so you can interact with the router from anywhere deeply nested in your app. -```rust +```rust, no_run #[derive(Deserialize)] struct Query { name: String } @@ -122,7 +117,7 @@ Managing state in your app can be challenging. Building global state management Fermi uses the concept of "Atoms" for global state. These individual values can be get/set from anywhere in your app. Using state with Fermi is basically as simple as `use_state`. -```rust +```rust, no_run // Create a single value in an "Atom" static TITLE: Atom<&str> = |_| "Hello"; @@ -152,7 +147,8 @@ fn Child(cx: Scope) -> Element { For internal components, explicitly declaring props structs can become tedious. That's why we've built the new `inline_props` macro. This macro lets you inline your props definition right into your component function arguments. Simply add the `inline_props` macro to your component: -```rust + +```rust, no_run #[inline_props] fn Child<'a>( cx: Scope, @@ -174,9 +170,9 @@ You won't be able to document each field or attach attributes so you should refr ## Props optional fields -Sometimes you don't want to specify *every* value in a component's props, since there might a lot. That's why the `Props` macro now supports optional fields. You can use a combination of `default`, `strip_option`, and `optional` to tune the exact behavior of properties fields. +Sometimes you don't want to specify _every_ value in a component's props, since there might a lot. That's why the `Props` macro now supports optional fields. You can use a combination of `default`, `strip_option`, and `optional` to tune the exact behavior of properties fields. -```rust +```rust, no_run #[derive(Props, PartialEq)] struct ChildProps { #[props(default = "client")] @@ -207,16 +203,15 @@ Under the hood, we have a new string interning engine to cache commonly used tag Overall, Dioxus apps are even more snappy than before. - Before and after: ![Before and After](https://imgur.com/byTBGlO.png) - ## Dioxus Desktop Window Context A very welcome change, thanks AGAIN to [@mrxiaozhuox](https://github.com/mrxiaozhuox) is support for imperatively controlling the desktop window from your Dioxus code. A bunch of new methods were added: + - Minimize and maximize window - Close window - Focus window @@ -240,10 +235,9 @@ Unlike its counterpart, `Trunk.rs`, the dioxus-cli supports running examples and Working with async isn't the easiest part of Rust. To help improve things, we've upgraded async support across the board in Dioxus. - First, we upgraded the `use_future` hook. It now supports dependencies, which let you regenerate a future on the fly as its computed values change. It's never been easier to add datafetching to your Rust Web Apps: -```rust +```rust, no_run fn RenderDog(cx: Scope, breed: String) -> Element { let dog_request = use_future(cx, (breed,), |(breed,)| async move { reqwest::get(format!("https://dog.ceo/api/breed/{}/images/random", breed)) @@ -263,7 +257,7 @@ fn RenderDog(cx: Scope, breed: String) -> Element { Additionally, we added better support for coroutines. You can now start, stop, resume, and message with asynchronous tasks. The coroutine is automatically exposed to the rest of your app via the Context API. For the vast majority of apps, Coroutines can satisfy all of your state management needs: -```rust +```rust, no_run fn App(cx: Scope) -> Element { let sync_task = use_coroutine(cx, |rx| async move { connect_to_server().await; @@ -313,6 +307,7 @@ We've covered the major headlining features, but there were so many more! - Right-click menus are now disabled by default ## Fixes + - Windows support improved across the board - Linux support improved across the board - Bug in Calculator example @@ -329,6 +324,7 @@ A ton more! Dioxus is now much more stable than it was at release! - The ContextAPI no longer uses RC to share state - anything that is `Clone` can be shared ## Community Additions + - [Styled Components macro](https://github.com/Zomatree/Revolt-Client/blob/master/src/utils.rs#14-27) [@Zomatree](https://github.com/Zomatree) - [Dioxus-Websocket hook](https://github.com/FruitieX/dioxus-websocket-hooks) [@FruitieX](https://github.com/FruitieX) - [Home automation server app](https://github.com/FruitieX/homectl) [@FruitieX](https://github.com/FruitieX) @@ -363,5 +359,3 @@ If you're interested in building an app with Dioxus, make sure to check us out o - [Reddit](http://reddit.com/r/dioxus/) - [Discord](https://discord.gg/XgGxMSkvUM) - [Twitter](http://twitter.com/dioxuslabs) - - diff --git a/docs/posts/release.md b/docs/posts/release.md index 171664dd3..06aca2ef5 100644 --- a/docs/posts/release.md +++ b/docs/posts/release.md @@ -20,7 +20,7 @@ Dioxus is designed to be familiar for developers already comfortable with React To give you an idea of what Dioxus looks like, here's a simple counter app: -```rust +```rust, no_run use dioxus::prelude::*; fn main() { @@ -112,8 +112,8 @@ Semantically, TypeScript-React and Rust-Dioxus are very similar. In TypeScript, ```tsx type CardProps = { - title: string, - paragraph: string, + title: string; + paragraph: string; }; const Card: FunctionComponent = (props) => { @@ -122,7 +122,7 @@ const Card: FunctionComponent = (props) => { ); }; @@ -130,7 +130,7 @@ const Card: FunctionComponent = (props) => { In Dioxus, we would define the same component in a similar fashion: -```rust +```rust, no_run #[derive(Props, PartialEq)] struct CardProps { title: String, @@ -176,14 +176,14 @@ $ cd dioxus_example We then add a dependency on Dioxus to the `Cargo.toml` file, with the "desktop" feature enabled: -```rust +```rust, no_run [dependencies] dioxus = { version = "*", features = ["desktop"] } ``` We can add our counter from above. -```rust +```rust, no_run use dioxus::prelude::*; fn main() { @@ -203,14 +203,13 @@ fn app(cx: Scope) -> Element { And voilà! We can `cargo run` our app - ![Simple Counter Desktop App](/static/counter.png) ## Support for JSX-style templating Dioxus ships with a templating macro called RSX, a spin on React's JSX. RSX is very similar to regular struct syntax for Rust so it integrates well with your IDE. If used with [Rust-Analyzer](https://github.com/rust-analyzer/rust-analyzer) (not tested anywhere else) RSX supports code-folding, block selection, bracket pair colorizing, autocompletion, symbol renaming — pretty much anything you would expect from writing regular struct-style code. -```rust +```rust, no_run rsx! { div { "Hello world" } button { @@ -222,7 +221,7 @@ rsx! { If macros aren't your style, you can always drop down to the factory API: -```rust +```rust, no_run LazyNodes::new(|f| { f.fragment([ f.element(div, [f.text("hello world")], [], None, None) @@ -245,9 +244,9 @@ To make it easier to work with RSX, we've built a small [VSCode extension](https Many of the Rust UI frameworks are particularly difficult to work with. Even the ones branded as "ergonomic" are quite challenging to in comparison to TSX/JSX. With Dioxus, we've innovated on a number of Rust patterns to deliver a framework that is actually enjoyable to develop in. -For example, many Rust frameworks require you to clone your data in for *every* closure and handler you use. This can get really clumsy for large apps. +For example, many Rust frameworks require you to clone your data in for _every_ closure and handler you use. This can get really clumsy for large apps. -```rust +```rust, no_run div() .children([ button().onclick(cloned!(name, date, age, description => move |evt| { /* */ }) @@ -258,8 +257,7 @@ div() Dioxus understands the lifetimes of data borrowed from `Scope`, so you can safely return any borrowed data without declaring explicit captures. Hook handles all implement `Copy` so they can be shared between listeners without any ceremony. - -```rust +```rust, no_run let name = use_state(cx, || "asd"); rsx! { div { @@ -272,7 +270,7 @@ rsx! { Because we know the lifetime of your handlers, we can also expose this to children. No other Rust frameworks let us share borrowed state through the tree, forcing use of Rc/Arc everywhere. With Dioxus, all the Rc/Arc magic is tucked away in hooks, and just beautiful borrowed interfaces are exposed to your code. You don't need to know how Rc/RefCell work to build a competent Dioxus app. -```rust +```rust, no_run fn app(cx: Scope) -> Element { let name = use_state(cx, || "asd"); cx.render(rsx!{ @@ -294,8 +292,7 @@ fn Button<'a>(cx: Scope<'a, Childprops<'a>>) -> Element { } ``` -There's *way* more to this story, but hopefully we've convinced you that Dioxus' DX somewhat approximates JSX/React. - +There's _way_ more to this story, but hopefully we've convinced you that Dioxus' DX somewhat approximates JSX/React. ## Dioxus is perfected for the IDE @@ -335,9 +332,10 @@ We take the performance of Dioxus seriously. Instead of resolving to "good enoug Dioxus is humbly built off the work done by [Dodrio](https://github.com/fitzgen/dodrio), a now-archived research project by fitzgen exploring the use of bump allocators in UI frameworks. -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. +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 + 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: diff --git a/docs/reference/src/guide/custom_renderer_pt-br.md b/docs/reference/src/guide/custom_renderer_pt-br.md index fb40504a7..eada5f0a6 100644 --- a/docs/reference/src/guide/custom_renderer_pt-br.md +++ b/docs/reference/src/guide/custom_renderer_pt-br.md @@ -21,7 +21,7 @@ Para referência, confira o interpretador JavaScript ou o renderizador TUI como O tipo "DomEdit" é uma enumeração serializada que representa uma operação atômica que ocorre no `RealDom`. As variantes seguem aproximadamente este conjunto: -```rust +```rust, no_run enum DomEdit { PushRoot, AppendChildren, @@ -48,7 +48,7 @@ O mecanismo de diferenciação do Dioxus opera como uma [máquina de pilha] (htt Por uma questão de compreensão, vamos considerar este exemplo - uma declaração de interface do usuário muito simples: -```rust +```rust, no_run rsx!( h1 {"hello world"} ) ``` @@ -56,7 +56,7 @@ To get things started, Dioxus must first navigate to the container of this h1 ta When the renderer receives this instruction, it pushes the actual Node onto its own stack. The real renderer's stack will look like this: -```rust +```rust, no_run instructions: [ PushRoot(Container) ] @@ -67,7 +67,7 @@ stack: [ Em seguida, o Dioxus encontrará o nó `h1`. O algoritmo `diff` decide que este nó precisa ser criado, então o Dioxus irá gerar o DomEdit `CreateElement`. Quando o renderizador receber esta instrução, ele criará um nó desmontado e o enviará para sua própria pilha: -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -80,7 +80,7 @@ stack: [ Em seguida, Dioxus vê o nó de texto e gera o DomEdit `CreateTextNode`: -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -95,7 +95,7 @@ stack: [ Lembre-se, o nó de texto não está anexado a nada (ele está desmontado), então o Dioxus precisa gerar um `Edit` que conecte o nó de texto ao elemento `h1`. Depende da situação, mas neste caso usamos `AppendChildren`. Isso remove o nó de texto da pilha, deixando o elemento `h1` como o próximo elemento na linha. -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -110,7 +110,7 @@ stack: [ Chamamos `AppendChildren` novamente, retirando o nó `h1` e anexando-o ao pai: -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -125,7 +125,7 @@ stack: [ Finalmente, o contêiner é aberto, pois não precisamos mais dele. -```rust +```rust, no_run instructions: [ PushRoot(Container), CreateElement(h1), @@ -139,7 +139,7 @@ stack: [] Com o tempo, nossa pilha ficou assim: -```rust +```rust, no_run [] [Container] [Container, h1] @@ -165,7 +165,7 @@ Como a maioria das GUIs, o Dioxus conta com um `loop` de eventos para progredir O código para a implementação do `WebSys` é direto, então vamos adicioná-lo aqui para demonstrar como um `loop` de eventos é simples: -```rust +```rust, no_run pub async fn run(&mut self) -> dioxus_core::error::Result<()> { // Push the body element onto the WebsysDom's stack machine let mut websys_dom = crate::new::WebsysDom::new(prepare_websys_dom()); @@ -195,7 +195,7 @@ pub async fn run(&mut self) -> dioxus_core::error::Result<()> { É importante que você decodifique os eventos reais do seu sistema de eventos no sistema de eventos sintético do Dioxus (significado sintético abstraído). Isso significa simplesmente combinar seu tipo de evento e criar um tipo Dioxus `UserEvent`. No momento, o sistema `VirtualEvent` é modelado quase inteiramente em torno da especificação HTML, mas estamos interessados em reduzi-lo. -```rust +```rust, no_run fn virtual_event_from_websys_event(event: &web_sys::Event) -> VirtualEvent { match event.type_().as_str() { "keydown" => { @@ -234,7 +234,7 @@ Esses elementos personalizados são definidos como `unit struct` com implementa Por exemplo, o elemento `div` é (aproximadamente!) definido assim: -```rust +```rust, no_run struct div; impl div { /// Some glorious documentation about the class property. @@ -263,7 +263,7 @@ O `RealDom` é uma abstração de nível superior sobre a atualização do DOM. Vamos construir um renderizador de brinquedo com bordas, tamanho e cor do texto. Antes de começarmos, vamos dar uma olhada em um elemento de exemplo que podemos renderizar: -```rust +```rust, no_run cx.render(rsx!{ div{ color: "red", @@ -315,7 +315,7 @@ flowchart TB Para ajudar na construção de um Dom, o núcleo nativo fornece quatro características: `State`, `ChildDepState`, `ParentDepState` e `NodeDepState` e uma estrutura `RealDom`. -```rust +```rust, no_run use dioxus_native_core::node_ref::*; use dioxus_native_core::state::{ChildDepState, NodeDepState, ParentDepState, State}; use dioxus_native_core_macro::{sorted_str_slice, State}; @@ -447,7 +447,7 @@ struct ToyState { Agora que temos nosso estado, podemos colocá-lo em uso em nosso DOM. Nós podemos atualizar o DOM com `update_state` para atualizar a estrutura do `DOM` (adicionando, removendo e alterando as propriedades dos nós) e então `apply_mutations` para atualizar o `ToyState` para cada um dos nós que foram alterados. -```rust +```rust, no_run fn main(){ fn app(cx: Scope) -> Element { cx.render(rsx!{ diff --git a/docs/reference/src/guide/rsx_in_depth.md b/docs/reference/src/guide/rsx_in_depth.md index 75e1f4a98..1a76f7c41 100644 --- a/docs/reference/src/guide/rsx_in_depth.md +++ b/docs/reference/src/guide/rsx_in_depth.md @@ -2,7 +2,7 @@ The RSX macro makes it very easy to assemble complex UIs with a very natural Rust syntax: -```rust +```rust, no_run rsx!( div { button { @@ -30,7 +30,7 @@ In this section, we'll cover the `rsx!` macro in depth. If you prefer to learn t Attributes must come before child elements -```rust +```rust, no_run div { hidden: "false", "some text" @@ -57,7 +57,7 @@ The `render` function provides an **extremely efficient** allocator for VNodes a Sometimes, writing `cx.render` is a hassle. The `rsx! macro will accept any token followed by a comma as the target to call "render" on: -```rust +```rust, no_run cx.render(rsx!( div {} )) // becomes render!(div {}) @@ -67,7 +67,7 @@ render!(div {}) Sometimes, you might not want to render an element given a condition. The rsx! macro will accept any tokens directly contained with curly braces, provided they resolve to a type that implements `IntoIterator`. This lets us write any Rust expression that resolves to a VNode: -```rust +```rust, no_run rsx!({ if enabled { render!(div {"enabled"}) @@ -79,7 +79,7 @@ rsx!({ A convenient way of hiding/showing an element is returning an `Option`. When combined with `and_then`, we can succinctly control the display state given some boolean: -```rust +```rust, no_run rsx!({ a.and_then(rsx!(div {"enabled"})) }) @@ -87,7 +87,7 @@ rsx!({ It's important to note that the expression `rsx!()` is typically lazy - this expression must be _rendered_ to produce a VNode. When using match statements, we must render every arm as to avoid the `no two closures are identical` rule that Rust imposes: -```rust +```rust, no_run // this will not compile! match case { true => rsx!(div {}), @@ -105,7 +105,7 @@ match case { Again, because anything that implements `IntoIterator` is valid, we can use lists directly in our `rsx!`: -```rust +```rust, no_run let items = vec!["a", "b", "c"]; cx.render(rsx!{ @@ -117,7 +117,7 @@ cx.render(rsx!{ Sometimes, it makes sense to render VNodes into a list: -```rust +```rust, no_run let mut items = vec![]; for _ in 0..5 { @@ -135,7 +135,7 @@ However, with lists, Dioxus does not exactly know how to determine which element In these cases, it is vitally important to specify a "key" alongside the element. Keys should be persistent between renders. -```rust +```rust, no_run fn render_list(cx: Scope, items: HashMap) -> DomTree { render!(ul { {items.iter().map(|key, item| { @@ -156,7 +156,7 @@ There have been many guides made for keys in React, so we recommend reading up t ### Complete Reference -```rust +```rust, no_run let text = "example"; cx.render(rsx!{ diff --git a/docs/reference/src/guide/rsx_in_depth_pt-br.md b/docs/reference/src/guide/rsx_in_depth_pt-br.md index 82c4f9298..4c981bd0a 100644 --- a/docs/reference/src/guide/rsx_in_depth_pt-br.md +++ b/docs/reference/src/guide/rsx_in_depth_pt-br.md @@ -2,7 +2,7 @@ A macro RSX facilita muito a montagem de interfaces de usuário complexas com uma sintaxe Rust muito natural: -```rust +```rust, no_run rsx!( div { button { @@ -30,7 +30,7 @@ Nesta seção, abordaremos a macro `rsx!` em profundidade. Se você preferir apr Os atributos devem vir antes dos elementos filhos -```rust +```rust, no_run div { hidden: "false", "some text" @@ -57,7 +57,7 @@ A função `render` fornece um alocador **extremamente eficiente** para `VNodes` Às vezes, escrever `cx.render` é um aborrecimento. O `rsx!` macro aceitará qualquer token seguido por uma vírgula como destino para chamar "render" em: -```rust +```rust, no_run cx.render(rsx!( div {} )) // becomes render!(div {}) @@ -67,7 +67,7 @@ render!(div {}) Às vezes, você pode não querer renderizar um elemento dada uma condição. O `rsx!` macro aceitará quaisquer tokens contidos diretamente com chaves, desde que resolvam para um tipo que implemente `IntoIterator`. Isso nos permite escrever qualquer expressão Rust que resolva para um `VNode`: -```rust +```rust, no_run rsx!({ if enabled { render!(div {"enabled"}) @@ -79,7 +79,7 @@ rsx!({ Uma maneira conveniente de ocultar/mostrar um elemento é retornar um `Option`. Quando combinado com `and_then`, podemos controlar sucintamente o estado de exibição dado alguns booleanos: -```rust +```rust, no_run rsx!({ a.and_then(rsx!(div {"enabled"})) }) @@ -87,7 +87,7 @@ rsx!({ É importante notar que a expressão `rsx!()` é tipicamente tardia - esta expressão deve ser _renderizada_ para produzir um `VNode`. Ao usar declarações de `match`, devemos renderizar todos os braços para evitar a regra 'não há dois fechamentos idênticos' que o Rust impõe: -```rust +```rust, no_run // this will not compile! match case { true => rsx!(div {}), @@ -105,7 +105,7 @@ match case { Novamente, porque qualquer coisa que implemente `IntoIterator` é válida, podemos usar listas diretamente em nosso `rsx!`: -```rust +```rust, no_run let items = vec!["a", "b", "c"]; cx.render(rsx!{ @@ -117,7 +117,7 @@ cx.render(rsx!{ Às vezes, faz sentido renderizar `VNodes` em uma lista: -```rust +```rust, no_run let mut items = vec![]; for _ in 0..5 { @@ -135,7 +135,7 @@ No entanto, com listas, Dioxus não sabe exatamente como determinar quais elemen Nesses casos, é de vital importância especificar uma "chave" ao lado do elemento. As chaves devem ser persistentes entre as renderizações. -```rust +```rust, no_run fn render_list(cx: Scope, items: HashMap) -> DomTree { render!(ul { {items.iter().map(|key, item| { @@ -156,7 +156,7 @@ Existem muitos guias feitos para chaves no React, então recomendamos a leitura ### Referência Completa -```rust +```rust, no_run let text = "example"; cx.render(rsx!{ diff --git a/docs/reference/src/platforms/desktop.md b/docs/reference/src/platforms/desktop.md index dcdcca778..30fe698ff 100644 --- a/docs/reference/src/platforms/desktop.md +++ b/docs/reference/src/platforms/desktop.md @@ -21,7 +21,7 @@ $ cargo add dioxus --features desktop Edit your `main.rs`: -```rust +```rust, no_run // main.rs use dioxus::prelude::*; diff --git a/examples/PWA-example/Cargo.toml b/examples/PWA-example/Cargo.toml new file mode 100644 index 000000000..f11d80713 --- /dev/null +++ b/examples/PWA-example/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "dioxus-pwa-example" +version = "0.1.0" +authors = ["Antonio Curavalea "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus = { path = "../../packages/dioxus", version = "^0.3.0"} +dioxus-web = { path = "../../packages/web", version = "^0.3.0"} + +log = "0.4.6" + +# WebAssembly Debug +wasm-logger = "0.2.0" +console_error_panic_hook = "0.1.7" diff --git a/examples/PWA-example/Dioxus.toml b/examples/PWA-example/Dioxus.toml new file mode 100644 index 000000000..e3a472520 --- /dev/null +++ b/examples/PWA-example/Dioxus.toml @@ -0,0 +1,42 @@ +[application] + +# App (Project) Name +name = "dioxus-pwa-example" + +# Dioxus App Default Platform +# desktop, web, mobile, ssr +default_platform = "web" + +# `build` & `serve` dist path +out_dir = "dist" + +# resource (public) file folder +asset_dir = "public" + +[web.app] + +# HTML title tag content +title = "dioxus | ⛺" + +[web.watcher] + +# when watcher trigger, regenerate the `index.html` +reload_html = true + +# which files or dirs will be watcher monitoring +watch_path = ["src", "public"] + +# include `assets` in web platform +[web.resource] + +# CSS style file +style = [] + +# Javascript code file +script = [] + +[web.resource.dev] + +# Javascript code file +# serve: [dev-server] only +script = [] diff --git a/examples/PWA-example/LICENSE b/examples/PWA-example/LICENSE new file mode 100644 index 000000000..bcdd828e9 --- /dev/null +++ b/examples/PWA-example/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Dioxus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/PWA-example/README.md b/examples/PWA-example/README.md new file mode 100644 index 000000000..dfd986302 --- /dev/null +++ b/examples/PWA-example/README.md @@ -0,0 +1,44 @@ +# Dioxus PWA example + +This is a basic example of a progressive web app (PWA) using Dioxus and Dioxus CLI. +Currently PWA functionality requires the use of a service worker and manifest file, so this isn't 100% Rust yet. + +It is also very much usable as a template for your projects, if you're aiming to create a PWA. + +## Try the example + +Make sure you have Dioxus CLI installed (if you're unsure, run `cargo install dioxus-cli`). + +You can run `dioxus serve` in this directory to start the web server locally, or run +`dioxus build --release` to build the project so you can deploy it on a separate web-server. + +## Project Structure +``` +├── Cargo.toml +├── Dioxus.toml +├── index.html // Custom HTML is needed for this, to load the SW and manifest. +├── LICENSE +├── public +│ ├── favicon.ico +│ ├── logo_192.png +│ ├── logo_512.png +│ ├── manifest.json // The manifest file - edit this as you need to. +│ └── sw.js // The service worker - you must edit this for actual projects. +├── README.md +└── src + └── main.rs +``` + +## Resources + +If you're just getting started with PWAs, here are some useful resources: + +* [PWABuilder docs](https://docs.pwabuilder.com/#/) +* [MDN article on PWAs](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps) + +For service worker scripting (in JavaScript): + +* [Service worker guide from PWABuilder](https://docs.pwabuilder.com/#/home/sw-intro) +* [Service worker examples, also from PWABuilder](https://github.com/pwa-builder/pwabuilder-serviceworkers) + +If you want to stay as close to 100% Rust as possible, you can try using [wasi-worker](https://github.com/dunnock/wasi-worker) to replace the JS service worker file. The JSON manifest will still be required though. \ No newline at end of file diff --git a/examples/PWA-example/index.html b/examples/PWA-example/index.html new file mode 100644 index 000000000..44bfa59cc --- /dev/null +++ b/examples/PWA-example/index.html @@ -0,0 +1,30 @@ + + + + {app_title} + + + + + + {style_include} + + +
+ + {script_include} + + \ No newline at end of file diff --git a/examples/PWA-example/public/favicon.ico b/examples/PWA-example/public/favicon.ico new file mode 100644 index 000000000..b11015bdb Binary files /dev/null and b/examples/PWA-example/public/favicon.ico differ diff --git a/examples/PWA-example/public/logo_192.png b/examples/PWA-example/public/logo_192.png new file mode 100644 index 000000000..112eb5ee4 Binary files /dev/null and b/examples/PWA-example/public/logo_192.png differ diff --git a/examples/PWA-example/public/logo_512.png b/examples/PWA-example/public/logo_512.png new file mode 100644 index 000000000..43129772a Binary files /dev/null and b/examples/PWA-example/public/logo_512.png differ diff --git a/examples/PWA-example/public/manifest.json b/examples/PWA-example/public/manifest.json new file mode 100644 index 000000000..ef542899d --- /dev/null +++ b/examples/PWA-example/public/manifest.json @@ -0,0 +1,34 @@ +{ + "name": "Dioxus", + "icons": [ + { + "src": "logo_192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo_512.png", + "type": "image/png", + "sizes": "512x512", + "purpose": "any" + }, + { + "src": "logo_512.png", + "type": "image/png", + "sizes": "any", + "purpose": "any" + } + ], + "start_url": "/", + "id": "/", + "display": "standalone", + "display_override": ["window-control-overlay", "standalone"], + "scope": "/", + "theme_color": "#000000", + "background_color": "#ffffff", + "short_name": "Dioxus", + "description": "Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.", + "dir": "ltr", + "lang": "en", + "orientation": "portrait" +} \ No newline at end of file diff --git a/examples/PWA-example/public/sw.js b/examples/PWA-example/public/sw.js new file mode 100644 index 000000000..162d37f4a --- /dev/null +++ b/examples/PWA-example/public/sw.js @@ -0,0 +1,198 @@ +"use strict"; + +//console.log('WORKER: executing.'); + +/* A version number is useful when updating the worker logic, + allowing you to remove outdated cache entries during the update. +*/ +var version = 'v1.0.0::'; + +/* These resources will be downloaded and cached by the service worker + during the installation process. If any resource fails to be downloaded, + then the service worker won't be installed either. +*/ +var offlineFundamentals = [ + // add here the files you want to cache + 'favicon.ico' +]; + +/* The install event fires when the service worker is first installed. + You can use this event to prepare the service worker to be able to serve + files while visitors are offline. +*/ +self.addEventListener("install", function (event) { + //console.log('WORKER: install event in progress.'); + /* Using event.waitUntil(p) blocks the installation process on the provided + promise. If the promise is rejected, the service worker won't be installed. + */ + event.waitUntil( + /* The caches built-in is a promise-based API that helps you cache responses, + as well as finding and deleting them. + */ + caches + /* You can open a cache by name, and this method returns a promise. We use + a versioned cache name here so that we can remove old cache entries in + one fell swoop later, when phasing out an older service worker. + */ + .open(version + 'fundamentals') + .then(function (cache) { + /* After the cache is opened, we can fill it with the offline fundamentals. + The method below will add all resources in `offlineFundamentals` to the + cache, after making requests for them. + */ + return cache.addAll(offlineFundamentals); + }) + .then(function () { + //console.log('WORKER: install completed'); + }) + ); +}); + +/* The fetch event fires whenever a page controlled by this service worker requests + a resource. This isn't limited to `fetch` or even XMLHttpRequest. Instead, it + comprehends even the request for the HTML page on first load, as well as JS and + CSS resources, fonts, any images, etc. +*/ +self.addEventListener("fetch", function (event) { + //console.log('WORKER: fetch event in progress.'); + + /* We should only cache GET requests, and deal with the rest of method in the + client-side, by handling failed POST,PUT,PATCH,etc. requests. + */ + if (event.request.method !== 'GET') { + /* If we don't block the event as shown below, then the request will go to + the network as usual. + */ + //console.log('WORKER: fetch event ignored.', event.request.method, event.request.url); + return; + } + /* Similar to event.waitUntil in that it blocks the fetch event on a promise. + Fulfillment result will be used as the response, and rejection will end in a + HTTP response indicating failure. + */ + event.respondWith( + caches + /* This method returns a promise that resolves to a cache entry matching + the request. Once the promise is settled, we can then provide a response + to the fetch request. + */ + .match(event.request) + .then(function (cached) { + /* Even if the response is in our cache, we go to the network as well. + This pattern is known for producing "eventually fresh" responses, + where we return cached responses immediately, and meanwhile pull + a network response and store that in the cache. + + Read more: + https://ponyfoo.com/articles/progressive-networking-serviceworker + */ + var networked = fetch(event.request) + // We handle the network request with success and failure scenarios. + .then(fetchedFromNetwork, unableToResolve) + // We should catch errors on the fetchedFromNetwork handler as well. + .catch(unableToResolve); + + /* We return the cached response immediately if there is one, and fall + back to waiting on the network as usual. + */ + //console.log('WORKER: fetch event', cached ? '(cached)' : '(network)', event.request.url); + return cached || networked; + + function fetchedFromNetwork(response) { + /* We copy the response before replying to the network request. + This is the response that will be stored on the ServiceWorker cache. + */ + var cacheCopy = response.clone(); + + //console.log('WORKER: fetch response from network.', event.request.url); + + caches + // We open a cache to store the response for this request. + .open(version + 'pages') + .then(function add(cache) { + /* We store the response for this request. It'll later become + available to caches.match(event.request) calls, when looking + for cached responses. + */ + cache.put(event.request, cacheCopy); + }) + .then(function () { + //console.log('WORKER: fetch response stored in cache.', event.request.url); + }); + + // Return the response so that the promise is settled in fulfillment. + return response; + } + + /* When this method is called, it means we were unable to produce a response + from either the cache or the network. This is our opportunity to produce + a meaningful response even when all else fails. It's the last chance, so + you probably want to display a "Service Unavailable" view or a generic + error response. + */ + function unableToResolve() { + /* There's a couple of things we can do here. + - Test the Accept header and then return one of the `offlineFundamentals` + e.g: `return caches.match('/some/cached/image.png')` + - You should also consider the origin. It's easier to decide what + "unavailable" means for requests against your origins than for requests + against a third party, such as an ad provider. + - Generate a Response programmaticaly, as shown below, and return that. + */ + + //console.log('WORKER: fetch request failed in both cache and network.'); + + /* Here we're creating a response programmatically. The first parameter is the + response body, and the second one defines the options for the response. + */ + return new Response('

Service Unavailable

', { + status: 503, + statusText: 'Service Unavailable', + headers: new Headers({ + 'Content-Type': 'text/html' + }) + }); + } + }) + ); +}); + +/* The activate event fires after a service worker has been successfully installed. + It is most useful when phasing out an older version of a service worker, as at + this point you know that the new worker was installed correctly. In this example, + we delete old caches that don't match the version in the worker we just finished + installing. +*/ +self.addEventListener("activate", function (event) { + /* Just like with the install event, event.waitUntil blocks activate on a promise. + Activation will fail unless the promise is fulfilled. + */ + //console.log('WORKER: activate event in progress.'); + + event.waitUntil( + caches + /* This method returns a promise which will resolve to an array of available + cache keys. + */ + .keys() + .then(function (keys) { + // We return a promise that settles when all outdated caches are deleted. + return Promise.all( + keys + .filter(function (key) { + // Filter by keys that don't start with the latest version prefix. + return !key.startsWith(version); + }) + .map(function (key) { + /* Return a promise that's fulfilled + when each outdated cache is deleted. + */ + return caches.delete(key); + }) + ); + }) + .then(function () { + //console.log('WORKER: activate completed.'); + }) + ); +}); diff --git a/examples/PWA-example/src/main.rs b/examples/PWA-example/src/main.rs new file mode 100644 index 000000000..4c09a9bc5 --- /dev/null +++ b/examples/PWA-example/src/main.rs @@ -0,0 +1,20 @@ +use dioxus::prelude::*; + +fn main() { + // init debug tool for WebAssembly + wasm_logger::init(wasm_logger::Config::default()); + console_error_panic_hook::set_once(); + + dioxus_web::launch(app); +} + +fn app(cx: Scope) -> Element { + cx.render(rsx! ( + div { + style: "text-align: center;", + h1 { "🌗 Dioxus 🚀" } + h3 { "Frontend that scales." } + p { "Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust." } + } + )) +} diff --git a/examples/README.md b/examples/README.md index 3963d186d..93530ba30 100644 --- a/examples/README.md +++ b/examples/README.md @@ -40,7 +40,7 @@ cargo run --example hello_world [all_css](./all_css.rs) - You can specify any CSS attribute -[tailwind](./tailwind.rs) - You can use a library for styling +[tailwind](./tailwind/) - You can use a library for styling ## Input Handling diff --git a/examples/control_focus.rs b/examples/control_focus.rs new file mode 100644 index 000000000..4f4c2ddcb --- /dev/null +++ b/examples/control_focus.rs @@ -0,0 +1,44 @@ +use std::rc::Rc; + +use dioxus::prelude::*; + +fn main() { + dioxus_desktop::launch(app); +} + +fn app(cx: Scope) -> Element { + let elements: &UseRef>> = use_ref(cx, Vec::new); + let running = use_state(cx, || true); + + use_future!(cx, |(elements, running)| async move { + let mut focused = 0; + if *running.current() { + loop { + tokio::time::sleep(std::time::Duration::from_millis(10)).await; + if let Some(element) = elements.read().get(focused) { + element.set_focus(true); + } else { + focused = 0; + } + focused += 1; + } + } + }); + + cx.render(rsx!( + div { + h1 { "Input Roulette" } + for i in 0..100 { + input { + value: "{i}", + onmounted: move |cx| { + elements.write().push(cx.inner().clone()); + }, + oninput: move |_| { + running.set(false); + } + } + } + } + )) +} diff --git a/examples/file_upload.rs b/examples/file_upload.rs new file mode 100644 index 000000000..b23648b50 --- /dev/null +++ b/examples/file_upload.rs @@ -0,0 +1,37 @@ +#![allow(non_snake_case)] +use dioxus::prelude::*; + +fn main() { + dioxus_desktop::launch(App); +} + +fn App(cx: Scope) -> Element { + let files_uploaded: &UseRef> = use_ref(cx, Vec::new); + + cx.render(rsx! { + input { + r#type: "file", + accept: ".txt, .rs", + multiple: true, + onchange: |evt| { + to_owned![files_uploaded]; + async move { + if let Some(file_engine) = &evt.files { + let files = file_engine.files(); + for file_name in &files { + if let Some(file) = file_engine.read_file_to_string(file_name).await{ + files_uploaded.write().push(file); + } + } + } + } + }, + } + + ul { + for file in files_uploaded.read().iter() { + li { "{file}" } + } + } + }) +} diff --git a/examples/generic_component.rs b/examples/generic_component.rs index 9757b1032..3d6171a9b 100644 --- a/examples/generic_component.rs +++ b/examples/generic_component.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use dioxus::prelude::*; fn main() { @@ -5,9 +7,20 @@ fn main() { } fn app(cx: Scope) -> Element { - cx.render(rsx! { generic_child::{} }) + cx.render(rsx! { generic_child { + data: 0i32 + } }) } -fn generic_child(cx: Scope) -> Element { - cx.render(rsx! { div {} }) +#[derive(PartialEq, Props)] +struct GenericChildProps { + data: T, +} + +fn generic_child(cx: Scope>) -> Element { + let data = &cx.props.data; + + cx.render(rsx! { div { + "{data}" + } }) } diff --git a/examples/inputs.rs b/examples/inputs.rs index cf848d99e..311afc1f0 100644 --- a/examples/inputs.rs +++ b/examples/inputs.rs @@ -37,6 +37,7 @@ const FIELDS: &[(&str, &str)] = &[ fn app(cx: Scope) -> Element { cx.render(rsx! { div { margin_left: "30px", + select_example(cx), div { // handling inputs on divs will catch all input events below // so the value of our input event will be either huey, dewey, louie, or true/false (because of the checkboxe) @@ -134,3 +135,34 @@ fn app(cx: Scope) -> Element { } }) } + +fn select_example(cx: Scope) -> Element { + cx.render(rsx! { + div { + select { + id: "selection", + name: "selection", + multiple: true, + oninput: move |evt| { + println!("{evt:?}"); + }, + option { + value : "Option 1", + label : "Option 1", + } + option { + value : "Option 2", + label : "Option 2", + selected : true, + }, + option { + value : "Option 3", + label : "Option 3", + } + } + label { + r#for: "selection", + "select element" + } + }}) +} diff --git a/examples/read_size.rs b/examples/read_size.rs new file mode 100644 index 000000000..806f71f80 --- /dev/null +++ b/examples/read_size.rs @@ -0,0 +1,60 @@ +#![allow(clippy::await_holding_refcell_ref)] +use std::rc::Rc; + +use dioxus::{html::geometry::euclid::Rect, prelude::*}; + +fn main() { + dioxus_desktop::launch_cfg( + app, + dioxus_desktop::Config::default().with_custom_head( + r#" + +"# + .to_owned(), + ), + ); +} + +fn app(cx: Scope) -> Element { + let div_element: &UseRef>> = use_ref(cx, || None); + + let dimentions = use_ref(cx, Rect::zero); + + cx.render(rsx!( + div { + width: "50%", + height: "50%", + background_color: "red", + onmounted: move |cx| { + div_element.set(Some(cx.inner().clone())); + }, + "This element is {dimentions.read():?}" + } + + button { + onclick: move |_| { + to_owned![div_element, dimentions]; + async move { + let read = div_element.read(); + let client_rect = read.as_ref().map(|el| el.get_client_rect()); + if let Some(client_rect) = client_rect { + if let Ok(rect) = client_rect.await { + dimentions.set(rect); + } + } + } + }, + "Read dimentions" + } + )) +} diff --git a/examples/scroll_to_top.rs b/examples/scroll_to_top.rs new file mode 100644 index 000000000..4eb38a451 --- /dev/null +++ b/examples/scroll_to_top.rs @@ -0,0 +1,33 @@ +use dioxus::prelude::*; + +fn main() { + dioxus_desktop::launch(app); +} + +fn app(cx: Scope) -> Element { + let header_element = use_ref(cx, || None); + + cx.render(rsx!( + div { + h1 { + onmounted: move |cx| { + header_element.set(Some(cx.inner().clone())); + }, + "Scroll to top example" + } + + for i in 0..100 { + div { "Item {i}" } + } + + button { + onclick: move |_| { + if let Some(header) = header_element.read().as_ref() { + header.scroll_to(ScrollBehavior::Smooth); + } + }, + "Scroll to top" + } + } + )) +} diff --git a/examples/svg.rs b/examples/svg.rs index 829a559ad..329cbe6ae 100644 --- a/examples/svg.rs +++ b/examples/svg.rs @@ -26,7 +26,7 @@ fn app(cx: Scope) -> Element { onclick: move |_| { use rand::Rng; let mut rng = rand::thread_rng(); - val.set(rng.gen_range(1..6)); + val.set(rng.gen_range(1..=6)); } } } diff --git a/examples/tailwind/Cargo.toml b/examples/tailwind/Cargo.toml new file mode 100644 index 000000000..5c2fbe666 --- /dev/null +++ b/examples/tailwind/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "dioxus-tailwind" +version = "0.0.0" +authors = [] +edition = "2021" +description = "A tailwindcss example using Dioxus" +license = "MIT OR Apache-2.0" +repository = "https://github.com/DioxusLabs/dioxus/" +homepage = "https://dioxuslabs.com" +documentation = "https://dioxuslabs.com" +rust-version = "1.60.0" +publish = false + +[dependencies] +dioxus = { path = "../../packages/dioxus" } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +dioxus-desktop = { path = "../../packages/desktop" } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +dioxus-web = { path = "../../packages/web" } \ No newline at end of file diff --git a/examples/tailwind/Dioxus.toml b/examples/tailwind/Dioxus.toml new file mode 100644 index 000000000..67a63e686 --- /dev/null +++ b/examples/tailwind/Dioxus.toml @@ -0,0 +1,46 @@ +[application] + +# App (Project) Name +name = "Tailwind CSS + Dioxus" + +# Dioxus App Default Platform +# desktop, web, mobile, ssr +default_platform = "web" + +# `build` & `serve` dist path +out_dir = "dist" + +# resource (public) file folder +asset_dir = "public" + +[web.app] + +# HTML title tag content +title = "dioxus | ⛺" + +[web.watcher] + +# when watcher trigger, regenerate the `index.html` +reload_html = true + +# which files or dirs will be watcher monitoring +watch_path = ["src", "public"] + +# include `assets` in web platform +[web.resource] + +# CSS style file +style = ["tailwind.css"] + +# Javascript code file +script = [] + +[web.resource.dev] + +# serve: [dev-server] only + +# CSS style file +style = [] + +# Javascript code file +script = [] diff --git a/examples/tailwind/README.md b/examples/tailwind/README.md new file mode 100644 index 000000000..0498ecbd3 --- /dev/null +++ b/examples/tailwind/README.md @@ -0,0 +1,136 @@ +Example: Basic Tailwind usage + +This example shows how an app might be styled with TailwindCSS. + +# Setup + +1. Install the Dioxus CLI: + +```bash +cargo install --git https://github.com/DioxusLabs/cli +``` + +2. Install npm: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm +3. Install the tailwind css cli: https://tailwindcss.com/docs/installation +4. Initialize the tailwind css project: + +```bash +npx tailwindcss init +``` + +This should create a `tailwind.config.js` file in the root of the project. + +5. Edit the `tailwind.config.js` file to include rust files: + +```json +module.exports = { + mode: "all", + content: [ + // include all rust, html and css files in the src directory + "./src/**/*.{rs,html,css}", + // include all html files in the output (dist) directory + "./dist/**/*.html", + ], + theme: { + extend: {}, + }, + plugins: [], +} +``` + +6. Create a `input.css` file with the following content: + +```css +@tailwind base; +@tailwind components; +@tailwind utilities; +``` + +7. Create a `Dioxus.toml` file with the following content that links to the `tailwind.css` file: + +```toml +[application] + +# App (Project) Name +name = "Tailwind CSS + Dioxus" + +# Dioxus App Default Platform +# desktop, web, mobile, ssr +default_platform = "web" + +# `build` & `serve` dist path +out_dir = "dist" + +# resource (public) file folder +asset_dir = "public" + +[web.app] + +# HTML title tag content +title = "dioxus | ⛺" + +[web.watcher] + +# when watcher trigger, regenerate the `index.html` +reload_html = true + +# which files or dirs will be watcher monitoring +watch_path = ["src", "public"] + +# include `assets` in web platform +[web.resource] + +# CSS style file +style = ["tailwind.css"] + +# Javascript code file +script = [] + +[web.resource.dev] + +# serve: [dev-server] only + +# CSS style file +style = [] + +# Javascript code file +script = [] +``` + +## Bonus Steps + +8. Install the tailwind css vs code extension +9. Go to the settings for the extension and find the experimental regex support section. Edit the setting.json file to look like this: + +```json +"tailwindCSS.experimental.classRegex": ["class: \"(.*)\""], +"tailwindCSS.includeLanguages": { + "rust": "html" +}, +``` + +# Development + +1. Run the following command in the root of the project to start the tailwind css compiler: + +```bash +npx tailwindcss -i ./input.css -o ./public/tailwind.css --watch +``` + +## Web + +- Run the following command in the root of the project to start the dioxus dev server: + +```bash +dioxus serve --hot-reload +``` + +- Open the browser to http://localhost:8080 + +## Desktop + +- Launch the dioxus desktop app + +```bash +cargo run +``` diff --git a/examples/tailwind/input.css b/examples/tailwind/input.css new file mode 100644 index 000000000..bd6213e1d --- /dev/null +++ b/examples/tailwind/input.css @@ -0,0 +1,3 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; \ No newline at end of file diff --git a/examples/tailwind/public/tailwind.css b/examples/tailwind/public/tailwind.css new file mode 100644 index 000000000..65b95316e --- /dev/null +++ b/examples/tailwind/public/tailwind.css @@ -0,0 +1,833 @@ +/* +! tailwindcss v3.2.7 | MIT License | https://tailwindcss.com +*/ + +/* +1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4) +2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116) +*/ + +*, +::before, +::after { + box-sizing: border-box; + /* 1 */ + border-width: 0; + /* 2 */ + border-style: solid; + /* 2 */ + border-color: #e5e7eb; + /* 2 */ +} + +::before, +::after { + --tw-content: ''; +} + +/* +1. Use a consistent sensible line-height in all browsers. +2. Prevent adjustments of font size after orientation changes in iOS. +3. Use a more readable tab size. +4. Use the user's configured `sans` font-family by default. +5. Use the user's configured `sans` font-feature-settings by default. +*/ + +html { + line-height: 1.5; + /* 1 */ + -webkit-text-size-adjust: 100%; + /* 2 */ + -moz-tab-size: 4; + /* 3 */ + -o-tab-size: 4; + tab-size: 4; + /* 3 */ + font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + /* 4 */ + font-feature-settings: normal; + /* 5 */ +} + +/* +1. Remove the margin in all browsers. +2. Inherit line-height from `html` so users can set them as a class directly on the `html` element. +*/ + +body { + margin: 0; + /* 1 */ + line-height: inherit; + /* 2 */ +} + +/* +1. Add the correct height in Firefox. +2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) +3. Ensure horizontal rules are visible by default. +*/ + +hr { + height: 0; + /* 1 */ + color: inherit; + /* 2 */ + border-top-width: 1px; + /* 3 */ +} + +/* +Add the correct text decoration in Chrome, Edge, and Safari. +*/ + +abbr:where([title]) { + -webkit-text-decoration: underline dotted; + text-decoration: underline dotted; +} + +/* +Remove the default font size and weight for headings. +*/ + +h1, +h2, +h3, +h4, +h5, +h6 { + font-size: inherit; + font-weight: inherit; +} + +/* +Reset links to optimize for opt-in styling instead of opt-out. +*/ + +a { + color: inherit; + text-decoration: inherit; +} + +/* +Add the correct font weight in Edge and Safari. +*/ + +b, +strong { + font-weight: bolder; +} + +/* +1. Use the user's configured `mono` font family by default. +2. Correct the odd `em` font sizing in all browsers. +*/ + +code, +kbd, +samp, +pre { + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + /* 1 */ + font-size: 1em; + /* 2 */ +} + +/* +Add the correct font size in all browsers. +*/ + +small { + font-size: 80%; +} + +/* +Prevent `sub` and `sup` elements from affecting the line height in all browsers. +*/ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* +1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) +2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) +3. Remove gaps between table borders by default. +*/ + +table { + text-indent: 0; + /* 1 */ + border-color: inherit; + /* 2 */ + border-collapse: collapse; + /* 3 */ +} + +/* +1. Change the font styles in all browsers. +2. Remove the margin in Firefox and Safari. +3. Remove default padding in all browsers. +*/ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; + /* 1 */ + font-size: 100%; + /* 1 */ + font-weight: inherit; + /* 1 */ + line-height: inherit; + /* 1 */ + color: inherit; + /* 1 */ + margin: 0; + /* 2 */ + padding: 0; + /* 3 */ +} + +/* +Remove the inheritance of text transform in Edge and Firefox. +*/ + +button, +select { + text-transform: none; +} + +/* +1. Correct the inability to style clickable types in iOS and Safari. +2. Remove default button styles. +*/ + +button, +[type='button'], +[type='reset'], +[type='submit'] { + -webkit-appearance: button; + /* 1 */ + background-color: transparent; + /* 2 */ + background-image: none; + /* 2 */ +} + +/* +Use the modern Firefox focus style for all focusable elements. +*/ + +:-moz-focusring { + outline: auto; +} + +/* +Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737) +*/ + +:-moz-ui-invalid { + box-shadow: none; +} + +/* +Add the correct vertical alignment in Chrome and Firefox. +*/ + +progress { + vertical-align: baseline; +} + +/* +Correct the cursor style of increment and decrement buttons in Safari. +*/ + +::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + height: auto; +} + +/* +1. Correct the odd appearance in Chrome and Safari. +2. Correct the outline style in Safari. +*/ + +[type='search'] { + -webkit-appearance: textfield; + /* 1 */ + outline-offset: -2px; + /* 2 */ +} + +/* +Remove the inner padding in Chrome and Safari on macOS. +*/ + +::-webkit-search-decoration { + -webkit-appearance: none; +} + +/* +1. Correct the inability to style clickable types in iOS and Safari. +2. Change font properties to `inherit` in Safari. +*/ + +::-webkit-file-upload-button { + -webkit-appearance: button; + /* 1 */ + font: inherit; + /* 2 */ +} + +/* +Add the correct display in Chrome and Safari. +*/ + +summary { + display: list-item; +} + +/* +Removes the default spacing and border for appropriate elements. +*/ + +blockquote, +dl, +dd, +h1, +h2, +h3, +h4, +h5, +h6, +hr, +figure, +p, +pre { + margin: 0; +} + +fieldset { + margin: 0; + padding: 0; +} + +legend { + padding: 0; +} + +ol, +ul, +menu { + list-style: none; + margin: 0; + padding: 0; +} + +/* +Prevent resizing textareas horizontally by default. +*/ + +textarea { + resize: vertical; +} + +/* +1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300) +2. Set the default placeholder color to the user's configured gray 400 color. +*/ + +input::-moz-placeholder, textarea::-moz-placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +input::placeholder, +textarea::placeholder { + opacity: 1; + /* 1 */ + color: #9ca3af; + /* 2 */ +} + +/* +Set the default cursor for buttons. +*/ + +button, +[role="button"] { + cursor: pointer; +} + +/* +Make sure disabled buttons don't get the pointer cursor. +*/ + +:disabled { + cursor: default; +} + +/* +1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14) +2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210) + This can trigger a poorly considered lint error in some tools but is included by design. +*/ + +img, +svg, +video, +canvas, +audio, +iframe, +embed, +object { + display: block; + /* 1 */ + vertical-align: middle; + /* 2 */ +} + +/* +Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14) +*/ + +img, +video { + max-width: 100%; + height: auto; +} + +/* Make elements with the HTML hidden attribute stay hidden by default */ + +[hidden] { + display: none; +} + +*, ::before, ::after { + --tw-border-spacing-x: 0; + --tw-border-spacing-y: 0; + --tw-translate-x: 0; + --tw-translate-y: 0; + --tw-rotate: 0; + --tw-skew-x: 0; + --tw-skew-y: 0; + --tw-scale-x: 1; + --tw-scale-y: 1; + --tw-pan-x: ; + --tw-pan-y: ; + --tw-pinch-zoom: ; + --tw-scroll-snap-strictness: proximity; + --tw-ordinal: ; + --tw-slashed-zero: ; + --tw-numeric-figure: ; + --tw-numeric-spacing: ; + --tw-numeric-fraction: ; + --tw-ring-inset: ; + --tw-ring-offset-width: 0px; + --tw-ring-offset-color: #fff; + --tw-ring-color: rgb(59 130 246 / 0.5); + --tw-ring-offset-shadow: 0 0 #0000; + --tw-ring-shadow: 0 0 #0000; + --tw-shadow: 0 0 #0000; + --tw-shadow-colored: 0 0 #0000; + --tw-blur: ; + --tw-brightness: ; + --tw-contrast: ; + --tw-grayscale: ; + --tw-hue-rotate: ; + --tw-invert: ; + --tw-saturate: ; + --tw-sepia: ; + --tw-drop-shadow: ; + --tw-backdrop-blur: ; + --tw-backdrop-brightness: ; + --tw-backdrop-contrast: ; + --tw-backdrop-grayscale: ; + --tw-backdrop-hue-rotate: ; + --tw-backdrop-invert: ; + --tw-backdrop-opacity: ; + --tw-backdrop-saturate: ; + --tw-backdrop-sepia: ; +} + +::backdrop { + --tw-border-spacing-x: 0; + --tw-border-spacing-y: 0; + --tw-translate-x: 0; + --tw-translate-y: 0; + --tw-rotate: 0; + --tw-skew-x: 0; + --tw-skew-y: 0; + --tw-scale-x: 1; + --tw-scale-y: 1; + --tw-pan-x: ; + --tw-pan-y: ; + --tw-pinch-zoom: ; + --tw-scroll-snap-strictness: proximity; + --tw-ordinal: ; + --tw-slashed-zero: ; + --tw-numeric-figure: ; + --tw-numeric-spacing: ; + --tw-numeric-fraction: ; + --tw-ring-inset: ; + --tw-ring-offset-width: 0px; + --tw-ring-offset-color: #fff; + --tw-ring-color: rgb(59 130 246 / 0.5); + --tw-ring-offset-shadow: 0 0 #0000; + --tw-ring-shadow: 0 0 #0000; + --tw-shadow: 0 0 #0000; + --tw-shadow-colored: 0 0 #0000; + --tw-blur: ; + --tw-brightness: ; + --tw-contrast: ; + --tw-grayscale: ; + --tw-hue-rotate: ; + --tw-invert: ; + --tw-saturate: ; + --tw-sepia: ; + --tw-drop-shadow: ; + --tw-backdrop-blur: ; + --tw-backdrop-brightness: ; + --tw-backdrop-contrast: ; + --tw-backdrop-grayscale: ; + --tw-backdrop-hue-rotate: ; + --tw-backdrop-invert: ; + --tw-backdrop-opacity: ; + --tw-backdrop-saturate: ; + --tw-backdrop-sepia: ; +} + +.container { + width: 100%; +} + +@media (min-width: 640px) { + .container { + max-width: 640px; + } +} + +@media (min-width: 768px) { + .container { + max-width: 768px; + } +} + +@media (min-width: 1024px) { + .container { + max-width: 1024px; + } +} + +@media (min-width: 1280px) { + .container { + max-width: 1280px; + } +} + +@media (min-width: 1536px) { + .container { + max-width: 1536px; + } +} + +.mx-auto { + margin-left: auto; + margin-right: auto; +} + +.mb-16 { + margin-bottom: 4rem; +} + +.mb-4 { + margin-bottom: 1rem; +} + +.mb-8 { + margin-bottom: 2rem; +} + +.ml-1 { + margin-left: 0.25rem; +} + +.ml-3 { + margin-left: 0.75rem; +} + +.ml-4 { + margin-left: 1rem; +} + +.mr-5 { + margin-right: 1.25rem; +} + +.mt-4 { + margin-top: 1rem; +} + +.flex { + display: flex; +} + +.inline-flex { + display: inline-flex; +} + +.hidden { + display: none; +} + +.h-10 { + height: 2.5rem; +} + +.h-4 { + height: 1rem; +} + +.w-10 { + width: 2.5rem; +} + +.w-4 { + width: 1rem; +} + +.w-5\/6 { + width: 83.333333%; +} + +.flex-col { + flex-direction: column; +} + +.flex-wrap { + flex-wrap: wrap; +} + +.items-center { + align-items: center; +} + +.justify-center { + justify-content: center; +} + +.rounded { + border-radius: 0.25rem; +} + +.rounded-full { + border-radius: 9999px; +} + +.border-0 { + border-width: 0px; +} + +.bg-gray-800 { + --tw-bg-opacity: 1; + background-color: rgb(31 41 55 / var(--tw-bg-opacity)); +} + +.bg-gray-900 { + --tw-bg-opacity: 1; + background-color: rgb(17 24 39 / var(--tw-bg-opacity)); +} + +.bg-indigo-500 { + --tw-bg-opacity: 1; + background-color: rgb(99 102 241 / var(--tw-bg-opacity)); +} + +.object-cover { + -o-object-fit: cover; + object-fit: cover; +} + +.object-center { + -o-object-position: center; + object-position: center; +} + +.p-2 { + padding: 0.5rem; +} + +.p-5 { + padding: 1.25rem; +} + +.px-3 { + padding-left: 0.75rem; + padding-right: 0.75rem; +} + +.px-5 { + padding-left: 1.25rem; + padding-right: 1.25rem; +} + +.px-6 { + padding-left: 1.5rem; + padding-right: 1.5rem; +} + +.py-1 { + padding-top: 0.25rem; + padding-bottom: 0.25rem; +} + +.py-2 { + padding-top: 0.5rem; + padding-bottom: 0.5rem; +} + +.py-24 { + padding-top: 6rem; + padding-bottom: 6rem; +} + +.text-center { + text-align: center; +} + +.text-3xl { + font-size: 1.875rem; + line-height: 2.25rem; +} + +.text-base { + font-size: 1rem; + line-height: 1.5rem; +} + +.text-lg { + font-size: 1.125rem; + line-height: 1.75rem; +} + +.text-xl { + font-size: 1.25rem; + line-height: 1.75rem; +} + +.font-medium { + font-weight: 500; +} + +.leading-relaxed { + line-height: 1.625; +} + +.text-gray-400 { + --tw-text-opacity: 1; + color: rgb(156 163 175 / var(--tw-text-opacity)); +} + +.text-white { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); +} + +.hover\:bg-gray-700:hover { + --tw-bg-opacity: 1; + background-color: rgb(55 65 81 / var(--tw-bg-opacity)); +} + +.hover\:bg-indigo-600:hover { + --tw-bg-opacity: 1; + background-color: rgb(79 70 229 / var(--tw-bg-opacity)); +} + +.hover\:text-white:hover { + --tw-text-opacity: 1; + color: rgb(255 255 255 / var(--tw-text-opacity)); +} + +.focus\:outline-none:focus { + outline: 2px solid transparent; + outline-offset: 2px; +} + +@media (min-width: 640px) { + .sm\:text-4xl { + font-size: 2.25rem; + line-height: 2.5rem; + } +} + +@media (min-width: 768px) { + .md\:mb-0 { + margin-bottom: 0px; + } + + .md\:ml-auto { + margin-left: auto; + } + + .md\:mt-0 { + margin-top: 0px; + } + + .md\:w-1\/2 { + width: 50%; + } + + .md\:flex-row { + flex-direction: row; + } + + .md\:items-start { + align-items: flex-start; + } + + .md\:pr-16 { + padding-right: 4rem; + } + + .md\:text-left { + text-align: left; + } +} + +@media (min-width: 1024px) { + .lg\:inline-block { + display: inline-block; + } + + .lg\:w-full { + width: 100%; + } + + .lg\:max-w-lg { + max-width: 32rem; + } + + .lg\:flex-grow { + flex-grow: 1; + } + + .lg\:pr-24 { + padding-right: 6rem; + } +} \ No newline at end of file diff --git a/examples/tailwind.rs b/examples/tailwind/src/main.rs similarity index 90% rename from examples/tailwind.rs rename to examples/tailwind/src/main.rs index af6bc4c4f..2dbb183c9 100644 --- a/examples/tailwind.rs +++ b/examples/tailwind/src/main.rs @@ -1,22 +1,16 @@ #![allow(non_snake_case)] -//! Example: Basic Tailwind usage -//! -//! This example shows how an app might be styled with TailwindCSS. -//! -//! To minify your tailwind bundle, currently you need to use npm. Follow these instructions: -//! -//! https://dev.to/arctic_hen7/how-to-set-up-tailwind-css-with-yew-and-trunk-il9 - use dioxus::prelude::*; -use dioxus_desktop::Config; fn main() { + #[cfg(not(target_arch = "wasm32"))] dioxus_desktop::launch_cfg( app, - Config::new() - .with_custom_head("".to_string()), + dioxus_desktop::Config::new() + .with_custom_head(r#""#.to_string()), ); + #[cfg(target_arch = "wasm32")] + dioxus_web::launch(app); } pub fn app(cx: Scope) -> Element { diff --git a/examples/tailwind/tailwind.config.js b/examples/tailwind/tailwind.config.js new file mode 100644 index 000000000..2a69d5803 --- /dev/null +++ b/examples/tailwind/tailwind.config.js @@ -0,0 +1,9 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + mode: "all", + content: ["./src/**/*.{rs,html,css}", "./dist/**/*.html"], + theme: { + extend: {}, + }, + plugins: [], +}; diff --git a/examples/web_component.rs b/examples/web_component.rs new file mode 100644 index 000000000..bd0f7eb15 --- /dev/null +++ b/examples/web_component.rs @@ -0,0 +1,13 @@ +use dioxus::prelude::*; + +fn main() { + dioxus_desktop::launch(app); +} + +fn app(cx: Scope) -> Element { + cx.render(rsx! { + web-component { + "my-prop": "5%", + } + }) +} diff --git a/notes/CONTRIBUTING.md b/notes/CONTRIBUTING.md index e69de29bb..150b60c88 100644 --- a/notes/CONTRIBUTING.md +++ b/notes/CONTRIBUTING.md @@ -0,0 +1,13 @@ +# Contributing + +On Linux, install the following packages: + +```bash +sudo apt install libgdk3.0-cil libatk1.0-dev libcairo2-dev libpango1.0-dev libgdk-pixbuf2.0-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev +``` + +Then run: + +```bash +cargo test --workspace --tests +``` diff --git a/packages/autofmt/Cargo.toml b/packages/autofmt/Cargo.toml index ccb6fed24..1c947dc21 100644 --- a/packages/autofmt/Cargo.toml +++ b/packages/autofmt/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["dom", "ui", "gui", "react"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-rsx = { path = "../rsx", version = "^0.0.3" } +dioxus-rsx = { workspace = true } proc-macro2 = { version = "1.0.6", features = ["span-locations"] } quote = "1.0" syn = { version = "1.0.11", features = ["full", "extra-traits"] } diff --git a/packages/autofmt/src/buffer.rs b/packages/autofmt/src/buffer.rs index 26c47f54b..fea5a4a3f 100644 --- a/packages/autofmt/src/buffer.rs +++ b/packages/autofmt/src/buffer.rs @@ -8,6 +8,8 @@ use std::fmt::{Result, Write}; use dioxus_rsx::IfmtInput; +use crate::write_ifmt; + /// The output buffer that tracks indent and string #[derive(Debug, Default)] pub struct Buffer { @@ -48,7 +50,7 @@ impl Buffer { } pub fn write_text(&mut self, text: &IfmtInput) -> Result { - write!(self.buf, "\"{}\"", text.source.as_ref().unwrap().value()) + write_ifmt(text, &mut self.buf) } } diff --git a/packages/autofmt/src/component.rs b/packages/autofmt/src/component.rs index 89ebe2229..d5d92b79a 100644 --- a/packages/autofmt/src/component.rs +++ b/packages/autofmt/src/component.rs @@ -1,4 +1,4 @@ -use crate::{writer::Location, Writer}; +use crate::{ifmt_to_string, writer::Location, Writer}; use dioxus_rsx::*; use quote::ToTokens; use std::fmt::{Result, Write}; @@ -170,9 +170,9 @@ impl Writer<'_> { ContentField::Formatted(s) => { write!( self.out, - "{}: \"{}\"", + "{}: {}", name, - s.source.as_ref().unwrap().value() + s.source.as_ref().unwrap().to_token_stream() )?; } ContentField::OnHandlerRaw(exp) => { @@ -215,7 +215,7 @@ impl Writer<'_> { let attr_len = fields .iter() .map(|field| match &field.content { - ContentField::Formatted(s) => s.source.as_ref().unwrap().value().len() , + ContentField::Formatted(s) => ifmt_to_string(s).len() , ContentField::OnHandlerRaw(exp) | ContentField::ManExpr(exp) => { let formatted = prettyplease::unparse_expr(exp); let len = if formatted.contains('\n') { diff --git a/packages/autofmt/src/element.rs b/packages/autofmt/src/element.rs index 6d2cdc830..50a991897 100644 --- a/packages/autofmt/src/element.rs +++ b/packages/autofmt/src/element.rs @@ -1,6 +1,7 @@ -use crate::Writer; +use crate::{ifmt_to_string, Writer}; use dioxus_rsx::*; use proc_macro2::Span; +use quote::ToTokens; use std::{ fmt::Result, fmt::{self, Write}, @@ -175,11 +176,7 @@ impl Writer<'_> { if !sameline { self.out.indented_tabbed_line()?; } - write!( - self.out, - "key: \"{}\"", - key.source.as_ref().unwrap().value() - )?; + write!(self.out, "key: {}", ifmt_to_string(key))?; if !attributes.is_empty() { write!(self.out, ",")?; if sameline { @@ -216,11 +213,7 @@ impl Writer<'_> { fn write_attribute(&mut self, attr: &ElementAttrNamed) -> Result { match &attr.attr { ElementAttr::AttrText { name, value } => { - write!( - self.out, - "{name}: \"{value}\"", - value = value.source.as_ref().unwrap().value() - )?; + write!(self.out, "{name}: {value}", value = ifmt_to_string(value))?; } ElementAttr::AttrExpression { name, value } => { let out = prettyplease::unparse_expr(value); @@ -230,15 +223,15 @@ impl Writer<'_> { ElementAttr::CustomAttrText { name, value } => { write!( self.out, - "\"{name}\": \"{value}\"", - name = name.value(), - value = value.source.as_ref().unwrap().value() + "{name}: {value}", + name = name.to_token_stream(), + value = ifmt_to_string(value) )?; } ElementAttr::CustomAttrExpression { name, value } => { let out = prettyplease::unparse_expr(value); - write!(self.out, "\"{}\": {}", name.value(), out)?; + write!(self.out, "{}: {}", name.to_token_stream(), out)?; } ElementAttr::EventTokens { name, tokens } => { @@ -276,13 +269,12 @@ impl Writer<'_> { let start = location.start(); let line_start = start.line - 1; - let this_line = self.src[line_start]; - - let beginning = if this_line.len() > start.column { - this_line[..start.column].trim() - } else { - "" - }; + let beginning = self + .src + .get(line_start) + .filter(|this_line| this_line.len() > start.column) + .map(|this_line| this_line[..start.column].trim()) + .unwrap_or_default(); beginning.is_empty() } @@ -316,7 +308,7 @@ impl Writer<'_> { } match children { - [BodyNode::Text(ref text)] => Some(text.source.as_ref().unwrap().value().len()), + [BodyNode::Text(ref text)] => Some(ifmt_to_string(text).len()), [BodyNode::Component(ref comp)] => { let attr_len = self.field_len(&comp.fields, &comp.manual_props); @@ -339,7 +331,7 @@ impl Writer<'_> { if el.children.len() == 1 { if let BodyNode::Text(ref text) = el.children[0] { - let value = text.source.as_ref().unwrap().value(); + let value = ifmt_to_string(text); if value.len() + el.name.to_string().len() + attr_len < 80 { return Some(value.len() + el.name.to_string().len() + attr_len); @@ -357,7 +349,7 @@ impl Writer<'_> { match item { BodyNode::Component(_) | BodyNode::Element(_) => return None, BodyNode::Text(text) => { - total_count += text.source.as_ref().unwrap().value().len() + total_count += ifmt_to_string(text).len(); } BodyNode::RawExpr(expr) => match get_expr_length(expr) { Some(len) => total_count += len, diff --git a/packages/autofmt/src/lib.rs b/packages/autofmt/src/lib.rs index 12bf00585..0d2426a0b 100644 --- a/packages/autofmt/src/lib.rs +++ b/packages/autofmt/src/lib.rs @@ -1,7 +1,10 @@ +use std::fmt::{Display, Write}; + use crate::writer::*; use collect_macros::byte_offset; -use dioxus_rsx::{BodyNode, CallBody}; +use dioxus_rsx::{BodyNode, CallBody, IfmtInput}; use proc_macro2::LineColumn; +use quote::ToTokens; use syn::{ExprMacro, MacroDelimiter}; mod buffer; @@ -130,8 +133,6 @@ pub fn write_block_out(body: CallBody) -> Option { } fn write_body(buf: &mut Writer, body: &CallBody) { - use std::fmt::Write; - if buf.is_short_children(&body.roots).is_some() { // write all the indents with spaces and commas between for idx in 0..body.roots.len() - 1 { @@ -208,3 +209,24 @@ pub fn apply_formats(input: &str, blocks: Vec) -> String { out } + +struct DisplayIfmt<'a>(&'a IfmtInput); + +impl Display for DisplayIfmt<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let inner_tokens = self.0.source.as_ref().unwrap().to_token_stream(); + inner_tokens.fmt(f) + } +} + +pub(crate) fn ifmt_to_string(input: &IfmtInput) -> String { + let mut buf = String::new(); + let display = DisplayIfmt(input); + write!(&mut buf, "{}", display).unwrap(); + buf +} + +pub(crate) fn write_ifmt(input: &IfmtInput, writable: &mut impl Write) -> std::fmt::Result { + let display = DisplayIfmt(input); + write!(writable, "{}", display) +} diff --git a/packages/autofmt/src/writer.rs b/packages/autofmt/src/writer.rs index 6a0e38d82..59f135592 100644 --- a/packages/autofmt/src/writer.rs +++ b/packages/autofmt/src/writer.rs @@ -8,6 +8,7 @@ use std::{ use syn::{spanned::Spanned, Expr, ExprIf}; use crate::buffer::Buffer; +use crate::ifmt_to_string; #[derive(Debug)] pub struct Writer<'a> { @@ -147,16 +148,16 @@ impl<'a> Writer<'a> { total += match &attr.attr { ElementAttr::AttrText { value, name } => { - value.source.as_ref().unwrap().value().len() + name.span().line_length() + 6 + ifmt_to_string(value).len() + name.span().line_length() + 6 } ElementAttr::AttrExpression { name, value } => { value.span().line_length() + name.span().line_length() + 6 } ElementAttr::CustomAttrText { value, name } => { - value.source.as_ref().unwrap().value().len() + name.value().len() + 6 + ifmt_to_string(value).len() + name.to_token_stream().to_string().len() + 6 } ElementAttr::CustomAttrExpression { name, value } => { - name.value().len() + value.span().line_length() + 6 + name.to_token_stream().to_string().len() + value.span().line_length() + 6 } ElementAttr::EventTokens { tokens, name } => { let location = Location::new(tokens.span().start()); diff --git a/packages/autofmt/tests/samples.rs b/packages/autofmt/tests/samples.rs index 19e636926..8145b0e8e 100644 --- a/packages/autofmt/tests/samples.rs +++ b/packages/autofmt/tests/samples.rs @@ -4,8 +4,8 @@ macro_rules! twoway { // doc attrs $( #[doc = $doc:expr] )* - $name:ident - ),* + $name:ident, + )* ) => { $( $( #[doc = $doc] )* @@ -14,6 +14,9 @@ macro_rules! twoway { let src = include_str!(concat!("./samples/", stringify!($name), ".rsx")); let formatted = dioxus_autofmt::fmt_file(src); let out = dioxus_autofmt::apply_formats(src, formatted); + // normalize line endings + let out = out.replace("\r", ""); + let src = src.replace("\r", ""); pretty_assertions::assert_eq!(&src, &out); } )* @@ -21,24 +24,25 @@ macro_rules! twoway { } twoway![ - simple, - comments, attributes, - manual_props, + collapse_expr, + comments, + commentshard, complex, + emoji, + ifchain_forloop, + immediate_expr, + key, + long_exprs, + long, + manual_props, + messy_indent, + multirsx, + raw_strings, + reallylong, + simple, + t2, tiny, tinynoopt, - long, - key, - multirsx, - commentshard, - emoji, - messy_indent, - long_exprs, - ifchain_forloop, - t2, - reallylong, - immediate_expr, - collapse_expr, - trailing_expr + trailing_expr, ]; diff --git a/packages/autofmt/tests/samples/complex.rsx b/packages/autofmt/tests/samples/complex.rsx index 598d08a82..1bf29a767 100644 --- a/packages/autofmt/tests/samples/complex.rsx +++ b/packages/autofmt/tests/samples/complex.rsx @@ -13,7 +13,9 @@ rsx! { // Complex nesting with handlers li { - Link { class: "flex items-center pl-3 py-3 pr-4 {active_class} rounded", to: "{to}", + Link { + class: "flex items-center pl-3 py-3 pr-4 {active_class} rounded", + to: "{to}", span { class: "inline-block mr-3", icons::icon_0 {} } span { "{name}" } children.is_some().then(|| rsx! { diff --git a/packages/autofmt/tests/samples/raw_strings.rsx b/packages/autofmt/tests/samples/raw_strings.rsx new file mode 100644 index 000000000..8a4d0c38f --- /dev/null +++ b/packages/autofmt/tests/samples/raw_strings.rsx @@ -0,0 +1,12 @@ +rsx! { + // Raw text strings + button { r#"Click me"#, r##"Click me"##, r######"Click me"######, r#"dynamic {1}"# } + + // Raw attribute strings + div { + width: r#"10px"#, + height: r##"{10}px"##, + "raw-attr": r###"raw-attr"###, + "raw-attr2": r###"{100}"### + } +} diff --git a/packages/autofmt/tests/wrong.rs b/packages/autofmt/tests/wrong.rs index acf930b40..5a0fb8a87 100644 --- a/packages/autofmt/tests/wrong.rs +++ b/packages/autofmt/tests/wrong.rs @@ -6,6 +6,11 @@ macro_rules! twoway { let src_wrong = include_str!(concat!("./wrong/", $val, ".wrong.rsx")); let formatted = dioxus_autofmt::fmt_file(src_wrong); let out = dioxus_autofmt::apply_formats(src_wrong, formatted); + + // normalize line endings + let out = out.replace("\r", ""); + let src_right = src_right.replace("\r", ""); + pretty_assertions::assert_eq!(&src_right, &out); } }; diff --git a/packages/cli/.github/workflows/build.yml b/packages/cli/.github/workflows/build.yml new file mode 100644 index 000000000..f0765e951 --- /dev/null +++ b/packages/cli/.github/workflows/build.yml @@ -0,0 +1,31 @@ +# .github/workflows/build.yml + +on: + release: + types: [created] + +jobs: + release: + name: release ${{ matrix.target }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: x86_64-unknown-linux-gnu + archive: tar.gz tar.xz + - target: x86_64-unknown-linux-musl + archive: tar.gz tar.xz + - target: x86_64-apple-darwin + archive: tar.gz tar.xz + - target: x86_64-pc-windows-gnu + archive: zip + + steps: + - uses: actions/checkout@master + - name: Compile and release + uses: rust-build/rust-build.action@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUSTTARGET: ${{ matrix.target }} + ARCHIVE_TYPES: ${{ matrix.archive }} diff --git a/packages/cli/.github/workflows/docs.yml b/packages/cli/.github/workflows/docs.yml new file mode 100644 index 000000000..d8765cac8 --- /dev/null +++ b/packages/cli/.github/workflows/docs.yml @@ -0,0 +1,34 @@ +name: github pages + +on: + push: + paths: + - docs/** + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v2 + + - name: Setup mdBook + uses: peaceiris/actions-mdbook@v1 + with: + mdbook-version: '0.4.10' + # mdbook-version: 'latest' + + - run: cd docs && mdbook build + + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@v4.2.3 + with: + branch: gh-pages # The branch the action should deploy to. + folder: docs/book # The folder the action should deploy. + target-folder: docs/nightly/cli + repository-name: dioxuslabs/docsite + clean: false + token: ${{ secrets.DEPLOY_KEY }} # let's pretend I don't need it for now diff --git a/packages/cli/.github/workflows/main.yml b/packages/cli/.github/workflows/main.yml new file mode 100644 index 000000000..f978ba7a2 --- /dev/null +++ b/packages/cli/.github/workflows/main.yml @@ -0,0 +1,68 @@ +on: [push, pull_request] + +name: Rust CI + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/cargo@v1 + with: + command: test + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v1 + - run: rustup component add rustfmt + - uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + # clippy: + # name: Clippy + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v2 + # - uses: actions-rs/toolchain@v1 + # with: + # profile: minimal + # toolchain: stable + # override: true + # - uses: Swatinem/rust-cache@v1 + # - run: rustup component add clippy + # - uses: actions-rs/cargo@v1 + # with: + # command: clippy + # args: -- -D warnings diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore new file mode 100644 index 000000000..6700b1332 --- /dev/null +++ b/packages/cli/.gitignore @@ -0,0 +1,4 @@ +/target +Cargo.lock +.DS_Store +.idea/ diff --git a/packages/cli/.vscode/settings.json b/packages/cli/.vscode/settings.json new file mode 100644 index 000000000..40461adda --- /dev/null +++ b/packages/cli/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "Lua.diagnostics.globals": [ + "plugin_logger", + "PLUGIN_DOWNLOADER" + ] +} diff --git a/packages/cli/Cargo.lock b/packages/cli/Cargo.lock new file mode 100644 index 000000000..707a02b6e --- /dev/null +++ b/packages/cli/Cargo.lock @@ -0,0 +1,4778 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aes" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.10", + "once_cell", + "version_check", +] + +[[package]] +name = "ahash" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +dependencies = [ + "cfg-if", + "const-random", + "getrandom 0.2.10", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "aho-corasick" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +dependencies = [ + "memchr", +] + +[[package]] +name = "aligned" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80a21b9440a626c7fc8573a9e3d3a06b75c7c97754c2949bc7857b90353ca655" +dependencies = [ + "as-slice", +] + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" + +[[package]] +name = "anymap2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d301b3b94cb4b2f23d7917810addbbaff90738e0ca2be692bd027e70d7e0330c" + +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "as-slice" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "async-compression" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" +dependencies = [ + "brotli", + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "async-trait" +version = "0.1.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "axum" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43" +dependencies = [ + "async-trait", + "axum-core", + "base64 0.13.1", + "bitflags", + "bytes", + "futures-util", + "headers", + "http", + "http-body", + "hyper", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "sha-1", + "sync_wrapper", + "tokio", + "tokio-tungstenite", + "tower", + "tower-http 0.3.5", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum-core" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "mime", + "tower-layer", + "tower-service", +] + +[[package]] +name = "backtrace" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide 0.6.2", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" +dependencies = [ + "byteorder", + "safemem", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "binary-install" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5bc5f8c50dd6a80d0b303ddab79f42ddcb52fd43d68107ecf622c551fd4cd4" +dependencies = [ + "curl", + "dirs 1.0.5", + "failure", + "flate2", + "hex 0.3.2", + "is_executable", + "siphasher", + "tar", + "zip 0.5.13", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "brotli" +version = "3.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b6561fd3f895a11e8f72af2cb7d22e08366bebc2b6b57f7744c4bda27034744" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "memchr", +] + +[[package]] +name = "bstr" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5" +dependencies = [ + "memchr", + "once_cell", + "regex-automata", + "serde", +] + +[[package]] +name = "btoi" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd6407f73a9b8b6162d8a2ef999fe6afd7cc15902ebf42c5cd296addf17e0ad" +dependencies = [ + "num-traits", +] + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "bumpslab" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5816c875b50b9866d759fa24d46159dccab0d7942c0ccbfd700b4f45dd961e" +dependencies = [ + "bumpalo", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "camino" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-generate" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7b2f627381dc7523340c606559dddf6083cb2e6134368381da5778638f906d8" +dependencies = [ + "anyhow", + "clap", + "console", + "dialoguer", + "env_logger", + "git2", + "gix-config", + "heck 0.4.1", + "home", + "ignore", + "indicatif", + "liquid", + "liquid-core", + "liquid-derive", + "liquid-lib", + "log", + "names", + "paste", + "path-absolutize", + "regex", + "remove_dir_all", + "rhai", + "sanitize-filename", + "semver", + "serde", + "tempfile", + "thiserror", + "toml 0.7.5", + "walkdir", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cargo_toml" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e72c3ff59e3b7d24630206bb63a73af65da4ed5df1f76ee84dfafb9fee2ba60e" +dependencies = [ + "serde", + "serde_derive", + "toml 0.5.11", +] + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cfg-expr" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bbc13bf6290a6b202cc3efb36f7ec2b739a80634215630c8053a313edf6abef" +dependencies = [ + "smallvec", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "time 0.1.45", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clap" +version = "4.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "clap_lex" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "colored" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "console" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.45.0", +] + +[[package]] +name = "const-random" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368a7a772ead6ce7e1de82bfb04c485f3db8ec744f72925af5735e29a22cc18e" +dependencies = [ + "const-random-macro", + "proc-macro-hack", +] + +[[package]] +name = "const-random-macro" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d7d6ab3c3a2282db210df5f02c4dab6e0a7057af0fb7ebd4070f30fe05c0ddb" +dependencies = [ + "getrandom 0.2.10", + "once_cell", + "proc-macro-hack", + "tiny-keccak", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "convert_case" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "cpufeatures" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "ctrlc" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a011bbe2c35ce9c1f143b7af6f94f29a167beb4cd1d29e6740ce836f723120e" +dependencies = [ + "nix", + "windows-sys 0.48.0", +] + +[[package]] +name = "curl" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2 0.4.9", + "winapi", +] + +[[package]] +name = "curl-sys" +version = "0.4.63+curl-8.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb0fef7046022a1e2ad67a004978f0e3cacb9e3123dc62ce768f92197b771dc" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", +] + +[[package]] +name = "cvt" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ae9bf77fbf2d39ef573205d554d87e86c12f1994e9ea335b0651b9b278bcf1" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "darling" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab8bfa2e259f8ee1ce5e97824a3c55ec4404a0d772ca7fa96bf19f0752a046eb" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "darling_macro" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "data-encoding" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" + +[[package]] +name = "dialoguer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59c6f2989294b9a498d3ad5491a79c6deb604617378e1cdc4bfc1c1361fe2f87" +dependencies = [ + "console", + "shell-words", + "tempfile", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "dioxus-autofmt" +version = "0.3.0" +source = "git+https://github.com/DioxusLabs/dioxus#11c9abcf7ce731ccb4a44c52de383c090ab319af" +dependencies = [ + "dioxus-rsx", + "prettier-please", + "proc-macro2", + "quote", + "serde", + "syn 1.0.109", +] + +[[package]] +name = "dioxus-cli" +version = "0.3.1" +dependencies = [ + "anyhow", + "atty", + "axum", + "binary-install", + "cargo-generate", + "cargo_metadata", + "cargo_toml", + "chrono", + "clap", + "colored 2.0.0", + "convert_case", + "ctrlc", + "dioxus-autofmt", + "dioxus-core", + "dioxus-html", + "dioxus-rsx", + "dirs 4.0.0", + "fern", + "flate2", + "fs_extra", + "futures", + "gitignore", + "headers", + "html_parser", + "hyper", + "hyper-rustls 0.23.2", + "indicatif", + "lazy_static", + "log", + "mlua", + "notify", + "open", + "proc-macro2", + "regex", + "reqwest", + "rsx-rosetta", + "serde", + "serde_json", + "subprocess", + "syn 1.0.109", + "tar", + "thiserror", + "tokio", + "toml 0.5.11", + "toml_edit", + "tower", + "tower-http 0.2.5", + "walkdir", + "wasm-bindgen-cli-support", + "zip 0.6.6", +] + +[[package]] +name = "dioxus-core" +version = "0.3.3" +source = "git+https://github.com/DioxusLabs/dioxus#11c9abcf7ce731ccb4a44c52de383c090ab319af" +dependencies = [ + "bumpalo", + "bumpslab", + "futures-channel", + "futures-util", + "indexmap 1.9.3", + "log", + "longest-increasing-subsequence", + "rustc-hash", + "serde", + "slab", + "smallbox", +] + +[[package]] +name = "dioxus-html" +version = "0.3.1" +source = "git+https://github.com/DioxusLabs/dioxus#11c9abcf7ce731ccb4a44c52de383c090ab319af" +dependencies = [ + "async-trait", + "dioxus-core", + "dioxus-rsx", + "enumset", + "euclid", + "keyboard-types", + "serde", + "serde-value", + "serde_repr", +] + +[[package]] +name = "dioxus-rsx" +version = "0.0.3" +source = "git+https://github.com/DioxusLabs/dioxus#11c9abcf7ce731ccb4a44c52de383c090ab319af" +dependencies = [ + "dioxus-core", + "internment", + "krates", + "proc-macro2", + "quote", + "serde", + "syn 1.0.109", +] + +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users 0.3.5", + "winapi", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users 0.4.3", + "winapi", +] + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "encoding_rs" +version = "0.8.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "enum-as-inner" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "enumset" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e875f1719c16de097dee81ed675e2d9bb63096823ed3f0ca827b7dea3028bbbb" +dependencies = [ + "enumset_derive", +] + +[[package]] +name = "enumset_derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08b6c6ab82d70f08844964ba10c7babb716de2ecaeab9be5717918a5177d3af" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "equivalent" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "euclid" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f253bc5c813ca05792837a0ff4b3a580336b224512d48f7eda1d7dd9210787" +dependencies = [ + "num-traits", + "serde", +] + +[[package]] +name = "failure" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", + "failure_derive", +] + +[[package]] +name = "failure_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "synstructure", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fern" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f0c14694cbd524c8720dd69b0e3179344f04ebb5f90f2e4a440c6ea3b2f1ee" +dependencies = [ + "colored 1.9.3", + "log", +] + +[[package]] +name = "filetime" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.2.16", + "windows-sys 0.48.0", +] + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "flate2" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +dependencies = [ + "crc32fast", + "miniz_oxide 0.7.1", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs_at" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15550ecca96ea332ec143fb450701074143b70d358e50b32b1f847ccff2e1cf7" +dependencies = [ + "aligned", + "cfg-if", + "cvt", + "libc", + "nix", + "windows-sys 0.48.0", +] + +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "futures-task" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" + +[[package]] +name = "futures-util" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + +[[package]] +name = "git2" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + +[[package]] +name = "gitignore" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d051488d9a601181a9b90c9ad8ae7e8251d642ddd2463008f2f5019d255bd89" +dependencies = [ + "glob", +] + +[[package]] +name = "gix-actor" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc22b0cdc52237667c301dd7cdc6ead8f8f73c9f824e9942c8ebd6b764f6c0bf" +dependencies = [ + "bstr 1.5.0", + "btoi", + "gix-date", + "itoa", + "nom", + "thiserror", +] + +[[package]] +name = "gix-config" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fbad5ce54a8fc997acc50febd89ec80fa6e97cb7f8d0654cb229936407489d8" +dependencies = [ + "bstr 1.5.0", + "gix-config-value", + "gix-features 0.28.1", + "gix-glob", + "gix-path", + "gix-ref", + "gix-sec", + "log", + "memchr", + "nom", + "once_cell", + "smallvec", + "thiserror", + "unicode-bom", +] + +[[package]] +name = "gix-config-value" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d09154c0c8677e4da0ec35e896f56ee3e338e741b9599fae06075edd83a4081c" +dependencies = [ + "bitflags", + "bstr 1.5.0", + "gix-path", + "libc", + "thiserror", +] + +[[package]] +name = "gix-date" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96271912ce39822501616f177dea7218784e6c63be90d5f36322ff3a722aae2" +dependencies = [ + "bstr 1.5.0", + "itoa", + "thiserror", + "time 0.3.22", +] + +[[package]] +name = "gix-features" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b76f9a80f6dd7be66442ae86e1f534effad9546676a392acc95e269d0c21c22" +dependencies = [ + "gix-hash 0.10.4", + "libc", + "sha1_smol", + "walkdir", +] + +[[package]] +name = "gix-features" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf69b0f5c701cc3ae22d3204b671907668f6437ca88862d355eaf9bc47a4f897" +dependencies = [ + "gix-hash 0.11.3", + "libc", +] + +[[package]] +name = "gix-fs" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b37a1832f691fdc09910bd267f9a2e413737c1f9ec68c6e31f9e802616278a9" +dependencies = [ + "gix-features 0.29.0", +] + +[[package]] +name = "gix-glob" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e43efd776bc543f46f0fd0ca3d920c37af71a764a16f2aebd89765e9ff2993" +dependencies = [ + "bitflags", + "bstr 1.5.0", +] + +[[package]] +name = "gix-hash" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a258595457bc192d1f1c59d0d168a1e34e2be9b97a614e14995416185de41a7" +dependencies = [ + "hex 0.4.3", + "thiserror", +] + +[[package]] +name = "gix-hash" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0dd58cdbe7ffa4032fc111864c80d5f8cecd9a2c9736c97ae7e5be834188272" +dependencies = [ + "hex 0.4.3", + "thiserror", +] + +[[package]] +name = "gix-lock" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c693d7f05730fa74a7c467150adc7cea393518410c65f0672f80226b8111555" +dependencies = [ + "gix-tempfile", + "gix-utils", + "thiserror", +] + +[[package]] +name = "gix-object" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df068db9180ee935fbb70504848369e270bdcb576b05c0faa8b9fd3b86fc017" +dependencies = [ + "bstr 1.5.0", + "btoi", + "gix-actor", + "gix-features 0.28.1", + "gix-hash 0.10.4", + "gix-validate", + "hex 0.4.3", + "itoa", + "nom", + "smallvec", + "thiserror", +] + +[[package]] +name = "gix-path" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32370dce200bb951df013e03dff35b4233fc7a89458642b047629b91734a7e19" +dependencies = [ + "bstr 1.5.0", + "thiserror", +] + +[[package]] +name = "gix-ref" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4e909396ed3b176823991ccc391c276ae2a015e54edaafa3566d35123cfac9d" +dependencies = [ + "gix-actor", + "gix-features 0.28.1", + "gix-hash 0.10.4", + "gix-lock", + "gix-object", + "gix-path", + "gix-tempfile", + "gix-validate", + "memmap2", + "nom", + "thiserror", +] + +[[package]] +name = "gix-sec" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ffa5bf0772f9b01de501c035b6b084cf9b8bb07dec41e3afc6a17336a65f47" +dependencies = [ + "bitflags", + "dirs 4.0.0", + "gix-path", + "libc", + "windows 0.43.0", +] + +[[package]] +name = "gix-tempfile" +version = "5.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71a0d32f34e71e86586124225caefd78dabc605d0486de580d717653addf182" +dependencies = [ + "gix-fs", + "libc", + "once_cell", + "parking_lot", + "tempfile", +] + +[[package]] +name = "gix-utils" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca284c260845bc0724050aec59c7a596407678342614cdf5a1d69e044f29a36" +dependencies = [ + "fastrand", +] + +[[package]] +name = "gix-validate" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d092b594c8af00a3a31fe526d363ee8a51a6f29d8496cdb991ed2f01ec0ec13" +dependencies = [ + "bstr 1.5.0", + "thiserror", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "globset" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +dependencies = [ + "aho-corasick 0.7.20", + "bstr 1.5.0", + "fnv", + "log", + "regex", +] + +[[package]] +name = "h2" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap 1.9.3", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.6", +] + +[[package]] +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" + +[[package]] +name = "headers" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" +dependencies = [ + "base64 0.13.1", + "bitflags", + "bytes", + "headers-core", + "http", + "httpdate", + "mime", + "sha1", +] + +[[package]] +name = "headers-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" +dependencies = [ + "http", +] + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "hostname" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" +dependencies = [ + "libc", + "match_cfg", + "winapi", +] + +[[package]] +name = "html_parser" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec016cabcf7c9c48f9d5fdc6b03f273585bfce640a0f47a69552039e92b1959a" +dependencies = [ + "pest", + "pest_derive", + "serde", + "serde_derive", + "serde_json", + "thiserror", +] + +[[package]] +name = "http" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "http-range-header" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "hyper" +version = "0.14.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.4.9", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +dependencies = [ + "http", + "hyper", + "log", + "rustls 0.20.8", + "rustls-native-certs", + "tokio", + "tokio-rustls 0.23.4", +] + +[[package]] +name = "hyper-rustls" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" +dependencies = [ + "http", + "hyper", + "rustls 0.21.2", + "tokio", + "tokio-rustls 0.24.1", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows 0.48.0", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", +] + +[[package]] +name = "indicatif" +version = "0.17.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ff8cc23a7393a397ed1d7f56e6365cba772aba9f9912ab968b03043c395d057" +dependencies = [ + "console", + "instant", + "number_prefix", + "portable-atomic", + "unicode-width", +] + +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "internment" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161079c3ad892faa215fcfcf3fd7a6a3c9288df2b06a2c2bad7fbfad4f01d69d" +dependencies = [ + "hashbrown 0.12.3", + "parking_lot", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "ipconfig" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" +dependencies = [ + "socket2 0.5.3", + "widestring", + "windows-sys 0.48.0", + "winreg 0.50.0", +] + +[[package]] +name = "ipnet" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" + +[[package]] +name = "iri-string" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f0f7638c1e223529f1bfdc48c8b133b9e0b434094d1d28473161ee48b235f78" +dependencies = [ + "nom", +] + +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + +[[package]] +name = "is_executable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577" +dependencies = [ + "winapi", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "keyboard-types" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7668b7cff6a51fe61cdde64cd27c8a220786f399501b57ebe36f7d8112fd68" +dependencies = [ + "bitflags", + "serde", + "unicode-segmentation", +] + +[[package]] +name = "kqueue" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "krates" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942c43a6cba1c201dfe81a943c89fa5c9140b34993e0c027f542c80b92e319a7" +dependencies = [ + "cargo_metadata", + "cfg-expr", + "petgraph", + "semver", +] + +[[package]] +name = "kstring" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747" +dependencies = [ + "serde", + "static_assertions", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "libgit2-sys" +version = "0.15.2+1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a80df2e11fb4a61f4ba2ab42dbe7f74468da143f1a75c74e11dee7c813f694fa" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + +[[package]] +name = "libssh2-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc8a030b787e2119a731f1951d6a773e2280c660f8ec4b0f5e1505a386e71ee" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libz-sys" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ee889ecc9568871456d42f603d6a0ce59ff328d291063a45cbdf0036baf6db" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + +[[package]] +name = "liquid" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f68ae1011499ae2ef879f631891f21c78e309755f4a5e483c4a8f12e10b609" +dependencies = [ + "doc-comment", + "liquid-core", + "liquid-derive", + "liquid-lib", + "serde", +] + +[[package]] +name = "liquid-core" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79e0724dfcaad5cfb7965ea0f178ca0870b8d7315178f4a7179f5696f7f04d5f" +dependencies = [ + "anymap2", + "itertools", + "kstring", + "liquid-derive", + "num-traits", + "pest", + "pest_derive", + "regex", + "serde", + "time 0.3.22", +] + +[[package]] +name = "liquid-derive" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2fb41a9bb4257a3803154bdf7e2df7d45197d1941c9b1a90ad815231630721" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "liquid-lib" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a17e273a6fb1fb6268f7a5867ddfd0bd4683c7e19b51084f3d567fad4348c0" +dependencies = [ + "itertools", + "liquid-core", + "once_cell", + "percent-encoding", + "regex", + "time 0.3.22", + "unicode-segmentation", +] + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" + +[[package]] +name = "longest-increasing-subsequence" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bd0dd2cd90571056fdb71f6275fada10131182f84899f4b2a916e565d81d86" + +[[package]] +name = "lru-cache" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "lua-src" +version = "546.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cb00c1380f1b4b4928dd211c07301ffa34872a239e590bd3219d9e5b213face" +dependencies = [ + "cc", +] + +[[package]] +name = "luajit-src" +version = "210.4.5+resty2cf5186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b7992a40e602786272d84c6f2beca44a588ededcfd57b48ec6f82008a7cb97" +dependencies = [ + "cc", +] + +[[package]] +name = "match_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" + +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + +[[package]] +name = "matchit" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.48.0", +] + +[[package]] +name = "mlua" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07366ed2cd22a3b000aed076e2b68896fb46f06f1f5786c5962da73c0af01577" +dependencies = [ + "bstr 0.2.17", + "cc", + "futures-core", + "futures-task", + "futures-util", + "lua-src", + "luajit-src", + "mlua_derive", + "num-traits", + "once_cell", + "pkg-config", + "rustc-hash", +] + +[[package]] +name = "mlua_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9214e60d3cf1643013b107330fcd374ccec1e4ba1eef76e7e5da5e8202e71c0" +dependencies = [ + "itertools", + "once_cell", + "proc-macro-error", + "proc-macro2", + "quote", + "regex", + "syn 1.0.109", +] + +[[package]] +name = "names" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bddcd3bf5144b6392de80e04c347cd7fab2508f6df16a85fc496ecd5cec39bc" +dependencies = [ + "rand", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "nix" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +dependencies = [ + "bitflags", + "cfg-if", + "libc", + "static_assertions", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "normpath" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec60c60a693226186f5d6edf073232bfb6464ed97eb22cf3b01c1e8198fd97f5" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "notify" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "729f63e1ca555a43fe3efa4f3efdf4801c479da85b432242a7b726f353c88486" +dependencies = [ + "bitflags", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "mio", + "serde", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "object" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "open" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a083c0c7e5e4a8ec4176346cf61f67ac674e8bfb059d9226e1c54a96b377c12" +dependencies = [ + "is-wsl", + "libc", + "pathdiff", +] + +[[package]] +name = "openssl" +version = "0.10.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "ordered-float" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +dependencies = [ + "num-traits", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets 0.48.0", +] + +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "paste" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" + +[[package]] +name = "path-absolutize" +version = "3.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f1d4993b16f7325d90c18c3c6a3327db7808752db8d208cea0acee0abd52c52" +dependencies = [ + "path-dedot", +] + +[[package]] +name = "path-dedot" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d55e486337acb9973cdea3ec5638c1b3bcb22e573b2b7b41969e0c744d5a15e" +dependencies = [ + "once_cell", +] + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + +[[package]] +name = "pest" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" +dependencies = [ + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "pest_meta" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "petgraph" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4" +dependencies = [ + "fixedbitset", + "indexmap 1.9.3", +] + +[[package]] +name = "pin-project" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" + +[[package]] +name = "portable-atomic" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "767eb9f07d4a5ebcb39bbf2d452058a93c011373abf6832e24194a1c3f004794" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "prettier-please" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be31b7957122175fcf33c6d8f54489a5262176020bf096026a86b308b7fa5b23" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + +[[package]] +name = "proc-macro2" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.10", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom 0.1.16", + "redox_syscall 0.1.57", + "rust-argon2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.10", + "redox_syscall 0.2.16", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +dependencies = [ + "aho-corasick 1.0.2", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + +[[package]] +name = "regex-syntax" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" + +[[package]] +name = "remove_dir_all" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23895cfadc1917fed9c6ed76a8c2903615fa3704f7493ff82b364c6540acc02b" +dependencies = [ + "aligned", + "cfg-if", + "cvt", + "fs_at", + "lazy_static", + "libc", + "normpath", + "windows-sys 0.45.0", +] + +[[package]] +name = "reqwest" +version = "0.11.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +dependencies = [ + "base64 0.21.2", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls 0.24.0", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls 0.21.2", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tokio-rustls 0.24.1", + "tokio-util", + "tower-service", + "trust-dns-resolver", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", + "winreg 0.10.1", +] + +[[package]] +name = "resolv-conf" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" +dependencies = [ + "hostname", + "quick-error", +] + +[[package]] +name = "rhai" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd29fa1f740be6dc91982013957e08c3c4232d7efcfe19e12da87d50bad47758" +dependencies = [ + "ahash 0.8.3", + "bitflags", + "instant", + "num-traits", + "rhai_codegen", + "smallvec", + "smartstring", +] + +[[package]] +name = "rhai_codegen" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db74e3fdd29d969a0ec1f8e79171a6f0f71d0429293656901db382d248c4c021" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "rsx-rosetta" +version = "0.3.0" +source = "git+https://github.com/DioxusLabs/dioxus#11c9abcf7ce731ccb4a44c52de383c090ab319af" +dependencies = [ + "convert_case", + "dioxus-autofmt", + "dioxus-rsx", + "html_parser", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64 0.13.1", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.37.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustls" +version = "0.20.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +dependencies = [ + "log", + "ring", + "sct", + "webpki", +] + +[[package]] +name = "rustls" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e32ca28af694bc1bbf399c33a516dbdf1c90090b8ab23c2bc24f834aa2247f5f" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-native-certs" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +dependencies = [ + "openssl-probe", + "rustls-pemfile", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pemfile" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +dependencies = [ + "base64 0.21.2", +] + +[[package]] +name = "rustls-webpki" +version = "0.100.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "safemem" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "sanitize-filename" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c502bdb638f1396509467cb0580ef3b29aa2a45c5d43e5d84928241280296c" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "schannel" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys 0.42.0", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "sct" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "security-framework" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +dependencies = [ + "serde", +] + +[[package]] +name = "serde" +version = "1.0.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "serde_json" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_repr" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "serde_spanned" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" + +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "siphasher" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" + +[[package]] +name = "slab" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallbox" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4679d6eef28b85020158619fc09769de89e90886c5de7157587d87cb72648faa" + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subprocess" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2efbeae7acf4eabd6bcdcbd11c92f45231ddda7539edc7806bd1a04a03b24616" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "unicode-xid", +] + +[[package]] +name = "tar" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "tempfile" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall 0.3.5", + "rustix", + "windows-sys 0.45.0", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "time" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +dependencies = [ + "itoa", + "libc", + "num_threads", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + +[[package]] +name = "time-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +dependencies = [ + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" +dependencies = [ + "autocfg", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.4.9", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.23.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +dependencies = [ + "rustls 0.20.8", + "tokio", + "webpki", +] + +[[package]] +name = "tokio-rustls" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +dependencies = [ + "rustls 0.21.2", + "tokio", +] + +[[package]] +name = "tokio-tungstenite" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f714dd15bead90401d77e04243611caec13726c2408afd5b31901dfcdcb3b181" +dependencies = [ + "futures-util", + "log", + "tokio", + "tungstenite", +] + +[[package]] +name = "tokio-util" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebafdf5ad1220cb59e7d17cf4d2c72015297b75b19a10472f99b89225089240" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" +dependencies = [ + "indexmap 2.0.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aba3f3efabf7fb41fae8534fc20a817013dd1c12cb45441efb6c82e6556b4cd8" +dependencies = [ + "async-compression", + "base64 0.13.1", + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "httpdate", + "iri-string", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "tokio", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f873044bf02dd1e8239e9c1293ea39dad76dc594ec16185d0a1bf31d8dc8d858" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-range-header", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "trust-dns-proto" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.2.3", + "ipnet", + "lazy_static", + "rand", + "smallvec", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "trust-dns-resolver" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe" +dependencies = [ + "cfg-if", + "futures-util", + "ipconfig", + "lazy_static", + "lru-cache", + "parking_lot", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", + "trust-dns-proto", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + +[[package]] +name = "tungstenite" +version = "0.17.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" +dependencies = [ + "base64 0.13.1", + "byteorder", + "bytes", + "http", + "httparse", + "log", + "rand", + "sha-1", + "thiserror", + "url", + "utf-8", +] + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "ucd-trie" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + +[[package]] +name = "unicode-bom" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63ec69f541d875b783ca40184d655f2927c95f0bffd486faa83cd3ac3529ec32" + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "url" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +dependencies = [ + "form_urlencoded", + "idna 0.4.0", + "percent-encoding", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "walrus" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb08e48cde54c05f363d984bb54ce374f49e242def9468d2e1b6c2372d291f8" +dependencies = [ + "anyhow", + "id-arena", + "leb128", + "log", + "walrus-macro", + "wasmparser", +] + +[[package]] +name = "walrus-macro" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7" +dependencies = [ + "heck 0.3.3", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.22", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-cli-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d21c60239a09bf9bab8dfa752be4e6c637db22296b9ded493800090448692da9" +dependencies = [ + "anyhow", + "base64 0.9.3", + "log", + "rustc-demangle", + "serde_json", + "tempfile", + "unicode-ident", + "walrus", + "wasm-bindgen-externref-xform", + "wasm-bindgen-multi-value-xform", + "wasm-bindgen-shared", + "wasm-bindgen-threads-xform", + "wasm-bindgen-wasm-conventions", + "wasm-bindgen-wasm-interpreter", +] + +[[package]] +name = "wasm-bindgen-externref-xform" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bafbe1984f67cc12645f12ab65e6145e8ddce1ab265d0be58435f25bb0ce2608" +dependencies = [ + "anyhow", + "walrus", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.22", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-multi-value-xform" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581419e3995571a1d2d066e360ca1c0c09da097f5a53c98e6f00d96eddaf0ffe" +dependencies = [ + "anyhow", + "walrus", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" + +[[package]] +name = "wasm-bindgen-threads-xform" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05d272073981137e8426cf2a6830d43d1f84f988a050b2f8b210f0e266b8983" +dependencies = [ + "anyhow", + "walrus", + "wasm-bindgen-wasm-conventions", +] + +[[package]] +name = "wasm-bindgen-wasm-conventions" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9c65b1ff5041ea824ca24c519948aec16fb6611c617d601623c0657dfcd47b" +dependencies = [ + "anyhow", + "walrus", +] + +[[package]] +name = "wasm-bindgen-wasm-interpreter" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c5c796220738ab5d44666f37205728a74141c0039d1166bcf8110b26bafaa1e" +dependencies = [ + "anyhow", + "log", + "walrus", + "wasm-bindgen-wasm-conventions", +] + +[[package]] +name = "wasm-streams" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bbae3363c08332cadccd13b67db371814cd214c2524020932f0804b8cf7c078" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "wasmparser" +version = "0.77.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fe3d5405e9ea6c1317a656d6e0820912d8b7b3607823a7596117c8f666daf6f" + +[[package]] +name = "web-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "webpki-roots" +version = "0.22.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +dependencies = [ + "webpki", +] + +[[package]] +name = "widestring" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows" +version = "0.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winnow" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "xattr" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +dependencies = [ + "libc", +] + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" + +[[package]] +name = "zip" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +dependencies = [ + "byteorder", + "bzip2", + "crc32fast", + "flate2", + "thiserror", + "time 0.1.45", +] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2", + "sha1", + "time 0.3.22", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.8+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +dependencies = [ + "cc", + "libc", + "pkg-config", +] diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml new file mode 100644 index 000000000..de3644f9f --- /dev/null +++ b/packages/cli/Cargo.toml @@ -0,0 +1,92 @@ +[package] +name = "dioxus-cli" +version = "0.3.1" +authors = ["Jonathan Kelley"] +edition = "2021" +description = "CLI tool for developing, testing, and publishing Dioxus apps" +license = "MIT/Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +# cli core +clap = { version = "4.2", features = ["derive"] } +thiserror = "1.0.30" +wasm-bindgen-cli-support = "0.2" +colored = "2.0.0" + +# features +log = "0.4.14" +fern = { version = "0.6.0", features = ["colored"] } +serde = { version = "1.0.136", features = ["derive"] } +serde_json = "1.0.79" +toml = "0.5.8" +fs_extra = "1.2.0" +cargo_toml = "0.11.4" +futures = "0.3.21" +notify = { version = "5.0.0-pre.16", features = ["serde"] } +html_parser = "0.6.2" +binary-install = "0.0.2" +convert_case = "0.5.0" +cargo_metadata = "0.15.0" +tokio = { version = "1.16.1", features = ["full"] } +atty = "0.2.14" +regex = "1.5.4" +chrono = "0.4.19" +anyhow = "1.0.53" +hyper = "0.14.17" +hyper-rustls = "0.23.2" +indicatif = "0.17.0-rc.11" +subprocess = "0.2.9" + +axum = { version = "0.5.1", features = ["ws", "headers"] } +tower-http = { version = "0.2.2", features = ["full"] } +headers = "0.3.7" + +walkdir = "2" + +# tools download +dirs = "4.0.0" +reqwest = { version = "0.11", features = [ + "rustls-tls", + "stream", + "trust-dns", + "blocking", +] } +flate2 = "1.0.22" +tar = "0.4.38" +zip = "0.6.2" +tower = "0.4.12" + +syn = { version = "1.0", features = ["full", "extra-traits"] } + + +proc-macro2 = { version = "1.0", features = ["span-locations"] } +lazy_static = "1.4.0" + +# plugin packages +mlua = { version = "0.8.1", features = [ + "lua54", + "vendored", + "async", + "send", + "macros", +] } +ctrlc = "3.2.3" +# dioxus-rsx = "0.0.1" +gitignore = "1.0.7" + +dioxus-rsx = { git = "https://github.com/DioxusLabs/dioxus" } +dioxus-html = { git = "https://github.com/DioxusLabs/dioxus", features = ["hot-reload-context"] } +dioxus-core = { git = "https://github.com/DioxusLabs/dioxus", features = ["serialize"] } +dioxus-autofmt = { git = "https://github.com/DioxusLabs/dioxus" } +rsx-rosetta = { git = "https://github.com/DioxusLabs/dioxus" } +open = "4.1.0" +cargo-generate = "0.18.3" +toml_edit = "0.19.11" + +[[bin]] +path = "src/main.rs" + +name = "dioxus" diff --git a/packages/cli/Dioxus.toml b/packages/cli/Dioxus.toml new file mode 100644 index 000000000..c3e0dd8a0 --- /dev/null +++ b/packages/cli/Dioxus.toml @@ -0,0 +1,45 @@ +[application] + +# dioxus project name +name = "dioxus-cli" + +# default platfrom +# you can also use `dioxus serve/build --platform XXX` to use other platform +# value: web | desktop +default_platform = "desktop" + +# Web `build` & `serve` dist path +out_dir = "dist" + +# resource (static) file folder +asset_dir = "public" + +[web.app] + +# HTML title tag content +title = "dioxus | ⛺" + +[web.watcher] + +watch_path = ["src"] + +# include `assets` in web platform +[web.resource] + +# CSS style file +style = [] + +# Javascript code file +script = [] + +[web.resource.dev] + +# Javascript code file +# serve: [dev-server] only +script = [] + +[application.tools] + +# use binaryen.wasm-opt for output Wasm file +# binaryen just will trigger in `web` platform +binaryen = { wasm_opt = true } \ No newline at end of file diff --git a/packages/cli/README.md b/packages/cli/README.md new file mode 100644 index 000000000..6f0826e10 --- /dev/null +++ b/packages/cli/README.md @@ -0,0 +1,43 @@ +
+

📦✨ Dioxus CLI

+

Tooling to supercharge Dioxus projects

+
+**dioxus-cli** (inspired by wasm-pack and webpack) is a tool for getting Dioxus projects up and running. +It handles all build, bundling, development and publishing to simplify web development. + + +## Installation + +### Install stable version +``` +cargo install dioxus-cli +``` +### Install from git repository +``` +cargo install --git https://github.com/DioxusLabs/dioxus dioxus-cli +``` +### Install from local folder +``` +cargo install --path . --debug +``` + + +## Get Started + +Use `dioxus create project-name` to initialize a new Dioxus project.
+ +It will be cloned from the [dioxus-template](https://github.com/DioxusLabs/dioxus-template) repository. + +
+ +Alternatively, you can specify the template path: + +``` +dioxus create hello --template gh:dioxuslabs/dioxus-template +``` + +## Dioxus Config File + +Dioxus CLI will use `Dioxus.toml` file to Identify some project info and switch some cli feature. + +You can get more configure information from [Dioxus CLI Document](https://dioxuslabs.com/cli/configure.html). diff --git a/packages/cli/build.rs b/packages/cli/build.rs new file mode 100644 index 000000000..15935e2da --- /dev/null +++ b/packages/cli/build.rs @@ -0,0 +1,50 @@ +//! Construct version in the `commit-hash date channel` format + +use std::{env, path::PathBuf, process::Command}; + +fn main() { + set_rerun(); + set_commit_info(); + if option_env!("CFG_RELEASE").is_none() { + println!("cargo:rustc-env=POKE_RA_DEVS=1"); + } +} + +fn set_rerun() { + println!("cargo:rerun-if-env-changed=CFG_RELEASE"); + + let mut manifest_dir = PathBuf::from( + env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."), + ); + + while manifest_dir.parent().is_some() { + let head_ref = manifest_dir.join(".git/HEAD"); + if head_ref.exists() { + println!("cargo:rerun-if-changed={}", head_ref.display()); + return; + } + + manifest_dir.pop(); + } + + println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!"); +} + +fn set_commit_info() { + let output = match Command::new("git") + .arg("log") + .arg("-1") + .arg("--date=short") + .arg("--format=%H %h %cd") + .output() + { + Ok(output) if output.status.success() => output, + _ => return, + }; + let stdout = String::from_utf8(output.stdout).unwrap(); + let mut parts = stdout.split_whitespace(); + let mut next = || parts.next().unwrap(); + println!("cargo:rustc-env=RA_COMMIT_HASH={}", next()); + println!("cargo:rustc-env=RA_COMMIT_SHORT_HASH={}", next()); + println!("cargo:rustc-env=RA_COMMIT_DATE={}", next()) +} diff --git a/packages/cli/docs/.gitignore b/packages/cli/docs/.gitignore new file mode 100644 index 000000000..7585238ef --- /dev/null +++ b/packages/cli/docs/.gitignore @@ -0,0 +1 @@ +book diff --git a/packages/cli/docs/book.toml b/packages/cli/docs/book.toml new file mode 100644 index 000000000..c5c216fe4 --- /dev/null +++ b/packages/cli/docs/book.toml @@ -0,0 +1,6 @@ +[book] +authors = ["YuKun Liu"] +language = "en" +multilingual = false +src = "src" +title = "Dioxus Cli" diff --git a/packages/cli/docs/src/SUMMARY.md b/packages/cli/docs/src/SUMMARY.md new file mode 100644 index 000000000..b5e3b91ae --- /dev/null +++ b/packages/cli/docs/src/SUMMARY.md @@ -0,0 +1,18 @@ +# Summary + +- [Introduction](./introduction.md) +- [Installation](./installation.md) +- [Create a Project](./creating.md) +- [Configure Project](./configure.md) +- [Commands](./cmd/README.md) + - [Build](./cmd/build.md) + - [Serve](./cmd/serve.md) + - [Clean](./cmd/clean.md) + - [Translate](./cmd/translate.md) +- [Plugin Development](./plugin/README.md) + - [API.Log](./plugin/interface/log.md) + - [API.Command](./plugin/interface/command.md) + - [API.OS](./plugin/interface/os.md) + - [API.Directories](./plugin/interface/dirs.md) + - [API.Network](./plugin/interface/network.md) + - [API.Path](./plugin/interface/path.md) \ No newline at end of file diff --git a/packages/cli/docs/src/cmd/README.md b/packages/cli/docs/src/cmd/README.md new file mode 100644 index 000000000..dae226577 --- /dev/null +++ b/packages/cli/docs/src/cmd/README.md @@ -0,0 +1,26 @@ +# Commands + +In this chapter we will introduce all `dioxus-cli` commands. + +> You can also use `dioxus --help` to get cli help info. + +``` +dioxus +Build, bundle, & ship your Dioxus app + +USAGE: + dioxus [OPTIONS] + +OPTIONS: + -h, --help Print help information + -v Enable verbose logging + +SUBCOMMANDS: + build Build the Dioxus application and all of its assets + clean Clean output artifacts + config Dioxus config file controls + create Init a new project for Dioxus + help Print this message or the help of the given subcommand(s) + serve Build, watch & serve the Rust WASM app and all of its assets + translate Translate some html file into a Dioxus component +``` \ No newline at end of file diff --git a/packages/cli/docs/src/cmd/build.md b/packages/cli/docs/src/cmd/build.md new file mode 100644 index 000000000..1fb892475 --- /dev/null +++ b/packages/cli/docs/src/cmd/build.md @@ -0,0 +1,47 @@ +# Build + +The `dioxus build` command can help you `pack & build` a dioxus project. + +``` +dioxus-build +Build the Rust WASM app and all of its assets + +USAGE: + dioxus build [OPTIONS] + +OPTIONS: + --example [default: ""] + --platform [default: "default_platform"] + --release [default: false] +``` + +You can use this command to build a project: + +``` +dioxus build --release +``` + +## Target platform + +Use the `platform` option to choose your target platform: + +``` +# for desktop project +dioxus build --platform desktop +``` + +`platform` currently only supports `desktop` & `web`. + +``` +# for web project +dioxus build --platform web +``` + +## Build Example + +You can use the `example` option to select a example to build: + +``` +# build the `test` example +dioxus build --exmaple test +``` \ No newline at end of file diff --git a/packages/cli/docs/src/cmd/clean.md b/packages/cli/docs/src/cmd/clean.md new file mode 100644 index 000000000..bbb3a132e --- /dev/null +++ b/packages/cli/docs/src/cmd/clean.md @@ -0,0 +1,18 @@ +# Clean + +`dioxus clean` will clear the build artifacts (the out_dir and the cargo cache) + +``` +dioxus-clean +Clean build artifacts + +USAGE: + dioxus clean +``` + +# Example + +``` +dioxus clean +``` + diff --git a/packages/cli/docs/src/cmd/serve.md b/packages/cli/docs/src/cmd/serve.md new file mode 100644 index 000000000..41abf5350 --- /dev/null +++ b/packages/cli/docs/src/cmd/serve.md @@ -0,0 +1,61 @@ +# Serve + +The `dioxus serve` can start a dev server with hot-reloading + +``` +dioxus-serve +Build, watch & serve the Rust WASM app and all of its assets + +USAGE: + dioxus serve [OPTIONS] + +OPTIONS: + --example [default: ""] + --platform [default: "default_platform"] + --release [default: false] + --hot-reload [default: false]ß +``` + +You can use this command to build project and start a dev server: + +``` +dioxus serve +``` + +## Serve Example + +You can use the `example` option to serve a example: + +``` +# serve the `test` example +dioxus serve --exmaple test +``` + +## Open Browser + +You can add the `--open` option to open system default browser when server startup: + +``` +dioxus serve --open +``` + +## RSX Hot Reloading + +You can add the `--hot-reload` flag to enable [rsx hot reloading](https://dioxuslabs.com/docs/0.3/guide/en/getting_started/hot_reload.html). This will allow you to reload some rsx changes without a full recompile: + +``` +dioxus serve --open +``` + +## Cross Origin Policy + +You can add the `cross-origin-policy` option to change cross-origin header to: + +``` + Cross-Origin-Opener-Policy: same-origin + Cross-Origin-Embedder-Policy: require-corp +``` + +``` +dioxus serve --corss-origin-policy +``` \ No newline at end of file diff --git a/packages/cli/docs/src/cmd/translate.md b/packages/cli/docs/src/cmd/translate.md new file mode 100644 index 000000000..7237e1dcf --- /dev/null +++ b/packages/cli/docs/src/cmd/translate.md @@ -0,0 +1,68 @@ +# Translate + +`dioxus translate` can translate some `html` file into a Dioxus compoent + +``` +dioxus-translate +Translate some source file into a Dioxus component + +USAGE: + dioxus translate [OPTIONS] [OUTPUT] + +ARGS: + Output file, defaults to stdout if not present + +OPTIONS: + -c, --component Activate debug mode + -f, --file Input file +``` + +## Translate HTML to stdout + +You can use the `file` option to set path to the `html` file to translate: + +``` +dioxus transtale --file ./index.html +``` + +## Output rsx to a file + +You can pass a file to the traslate command to set the path to write the output of the command to: + +``` +dioxus translate --file ./index.html component.rsx +``` + +## Output rsx to a file + +Setting the `component` option will create a compoent from the HTML: + +``` +dioxus translate --file ./index.html --component +``` + +## Example + +This HTML: +```html +
+``` + +Translates into this Dioxus component: + +```rust +fn component(cx: Scope) -> Element { + cx.render(rsx! { + div { + h1 { "Hello World" }, + a { + href: "https://dioxuslabs.com/", + "Link" + } + } + }) +} +``` \ No newline at end of file diff --git a/packages/cli/docs/src/configure.md b/packages/cli/docs/src/configure.md new file mode 100644 index 000000000..35904caae --- /dev/null +++ b/packages/cli/docs/src/configure.md @@ -0,0 +1,208 @@ +# Configure Project + + +This chapter will introduce you to how to configure the CLI with your `Dioxus.toml` file + +Be aware that if the config file is present in the folder, some fields must be filled out, or the CLI tool will abort. The mandatory [table headers](https://toml.io/en/v1.0.0#table) and keys will have a '✍' sign beside it. + +## Structure + +The CLI uses a `Dioxus.toml` file in the root of your crate to define some configuration for your `dioxus` project. + +### Application ✍ + +General application confiration: + +``` +[application] +# configuration +``` +1. ***name*** ✍ - project name & title +2. ***default_platform*** ✍ - which platform target for this project. + + ``` + name = "my-project" + ``` +2. ***default_platform*** - The platform this project targets + ```ß + # current supported platforms: web, desktop + # default: web + default_platform = "web" + ``` + if you change this to `desktop`, the `dioxus build` will default building a desktop app +3. ***out_dir*** - The directory to place the build artifacts from `dioxus build` or `dioxus service` into. This is also where the `assets` directory will be copied to + ``` + out_dir = "dist" + ``` +4. ***asset_dir*** - The directory with your static assets. The CLI will automatically copy these assets into the ***out_dir*** after a build/serve. + ``` + asset_dir = "public" + ``` +5. ***sub_package*** - The sub package in the workspace to build by default + ``` + sub_package = "my-crate" + ``` + +### Web.App ✍ + +Configeration specific to web applications: + +``` +[web.app] +# configuration +``` + +1. ***title*** - The title of the web page + ``` + # HTML title tag content + title = "dioxus app | ⛺" + ``` +2. ***base_path*** - The base path to build the appliation for serving at. This can be useful when serving your application in a subdirectory under a domain. For example when building a site to be served on github pages. + ``` + # The application will be served at domain.com/my_application/, so we need to modify the base_path to the path where the application will be served + base_path = "my_application" + ``` + +### Web.Watcher ✍ + +Configeration related to the development server: + +``` +[web.watcher] +# configuration +``` + +1. ***reload_html*** - If this is true, the cli will rebuild the index.html file every time the application is rebuilt + ``` + reload_html = true + ``` +2. ***watch_path*** - The files & directories to moniter for changes + ``` + watch_path = ["src", "public"] + ``` +3. ***index_on_404*** - If enabled, Dioxus CLI will serve the root page when a route is not found. *This is needed when serving an application that uses the router* + ``` + index_on_404 = true + ``` + +### Web.Resource ✍ + +Configeration related to static resources your application uses: +``` +[web.resource] +# configuration +``` + +1. ***style*** - The styles (`.css` files) to include in your application + ``` + style = [ + # include from public_dir. + "./assets/style.css", + # or some asset from online cdn. + "https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css" + ] + ``` +2. ***script*** - The additional scripts (`.js` files) to include in your application + ``` + style = [ + # include from public_dir. + "./assets/index.js", + # or some asset from online cdn. + "https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js" + ] + ``` + +### Web.Resource.Dev ✍ + +Configeration related to static resources your application uses in development: +``` +[web.resource.dev] +# configuration +``` + +1. ***style*** - The styles (`.css` files) to include in your application + ``` + style = [ + # include from public_dir. + "./assets/style.css", + # or some asset from online cdn. + "https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.css" + ] + ``` +2. ***script*** - The additional scripts (`.js` files) to include in your application + ``` + style = [ + # include from public_dir. + "./assets/index.js", + # or some asset from online cdn. + "https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.js" + ] + ``` + +### Web.Proxy + +Configeration related to any proxies your application requires durring development. Proxies will forward requests to a new service + +``` +[web.proxy] +# configuration +``` + +1. ***backend*** - The URL to the server to proxy. The CLI will forward any requests under the backend relative route to the backend instead of returning 404 + ``` + backend = "http://localhost:8000/api/" + ``` + This will cause any requests made to the dev server with prefix /api/ to be redirected to the backend server at http://localhost:8000. The path and query parameters will be passed on as-is (path rewriting is not currently supported). + +## Config example + +```toml +[application] + +# App (Project) Name +name = "{{project-name}}" + +# The Dioxus platform to default to +default_platform = "web" + +# `build` & `serve` output path +out_dir = "dist" + +# the static resource path +asset_dir = "public" + +[web.app] + +# HTML title tag content +title = "dioxus | ⛺" + +[web.watcher] + +# when watcher is triggered, regenerate the `index.html` +reload_html = true + +# which files or dirs will be monitored +watch_path = ["src", "public"] + +# include `assets` in web platform +[web.resource] + +# CSS style file +style = [] + +# Javascript code file +script = [] + +[web.resource.dev] + +# serve: [dev-server] only + +# CSS style file +style = [] + +# Javascript code file +script = [] + +[[web.proxy]] +backend = "http://localhost:8000/api/" +``` diff --git a/packages/cli/docs/src/creating.md b/packages/cli/docs/src/creating.md new file mode 100644 index 000000000..5bb98fd10 --- /dev/null +++ b/packages/cli/docs/src/creating.md @@ -0,0 +1,39 @@ +# Create a Project + +Once you have the Dioxus CLI tool installed, you can use it to create dioxus project. + +## Initializing a default project + +First, run the `dioxus create` command to create a new project ready to be used with Dioxus and the Dioxus CLI: + +``` +dioxus create hello-dioxus +``` + +> It will clone a default template from github template: [DioxusLabs/dioxus-template](https://github.com/DioxusLabs/dioxus-template) +> This default template is use for `web` platform application. +> +> You can choose to create your project from a different template by passing the `template` argument: +> ``` +> dioxus init hello-dioxus --template=gh:dioxuslabs/dioxus-template +> ``` + +Next, move the current directory into your new project: + +``` +cd hello-dioxus +``` + +> Make sure `wasm32 target` is installed before running the Web project. +> You can install the wasm target for rust using rustup: +> ``` +> rustup target add wasm32-unknown-unknown +> ``` + +Finally, create serve your project with the Dioxus CLI: + +``` +dioxus serve +``` + +By default, the CLI serve your site at: [`http://127.0.0.1:8080/`](http://127.0.0.1:8080/) diff --git a/packages/cli/docs/src/installation.md b/packages/cli/docs/src/installation.md new file mode 100644 index 000000000..b4326d296 --- /dev/null +++ b/packages/cli/docs/src/installation.md @@ -0,0 +1,22 @@ +# Installation + +Choose any one of the methods below to install the Dioxus CLI: + +## Install from latest git version + +To get the most up to date bug fixes and features of the Dioxus CLI, you can install the development version from git. + +``` +cargo install --git https://github.com/Dioxuslabs/cli +``` + +This will automatically download `Dioxus-CLI` source from github master branch, +and install it in Cargo's global binary directory (`~/.cargo/bin/` by default). + +## Install from `crates.io` version + +The published version of the Dioxus CLI is updated less often, but should be more stable than the git version of the Dioxus CLI. + +``` +cargo install dioxus-cli +``` diff --git a/packages/cli/docs/src/introduction.md b/packages/cli/docs/src/introduction.md new file mode 100644 index 000000000..2f857a2a5 --- /dev/null +++ b/packages/cli/docs/src/introduction.md @@ -0,0 +1,21 @@ +# Introduction + +📦✨ **Dioxus-Cli** is a tool to help get dioxus projects off the ground. + +![dioxus-logo](https://dioxuslabs.com/guide/images/dioxuslogo_full.png) + +It includes `dev server`, `hot reload` and some `quick command` to help you use dioxus. + +## Features + +- [x] `html` to `rsx` conversion tool +- [x] hot reload for `web` platform +- [x] create dioxus project from `git` repo +- [x] build & pack dioxus project +- [ ] autoformat dioxus `rsx` code + +## Contributors + +Contributors to this guide: + +- [mrxiaozhuox](https://github.com/mrxiaozhuox) \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/README.md b/packages/cli/docs/src/plugin/README.md new file mode 100644 index 000000000..9983f024b --- /dev/null +++ b/packages/cli/docs/src/plugin/README.md @@ -0,0 +1,79 @@ +# CLI Plugin Development + +> For Cli 0.2.0 we will add `plugin-develop` support. + +Before the 0.2.0 we use `dioxus tool` to use & install some plugin, but we think that is not good for extend cli program, some people want tailwind support, some people want sass support, we can't add all this thing in to the cli source code and we don't have time to maintain a lot of tools that user request, so maybe user make plugin by themself is a good choice. + +### Why Lua ? + +We choose `Lua: 5.4` to be the plugin develop language, because cli plugin is not complex, just like a workflow, and user & developer can write some easy code for their plugin. We have **vendored** lua in cli program, and user don't need install lua runtime in their computer, and the lua parser & runtime doesn't take up much disk memory. + +### Event Management + +The plugin library have pre-define some important event you can control: + +- `build.on_start` +- `build.on_finished` +- `serve.on_start` +- `serve.on_rebuild` +- `serve.on_shutdown` + +### Plugin Template + +```lua +package.path = library_dir .. "/?.lua" + +local plugin = require("plugin") +local manager = require("manager") + +-- deconstruct api functions +local log = plugin.log + +-- plugin information +manager.name = "Hello Dixous Plugin" +manager.repository = "https://github.com/mrxiaozhuox/hello-dioxus-plugin" +manager.author = "YuKun Liu " +manager.version = "0.0.1" + +-- init manager info to plugin api +plugin.init(manager) + +manager.on_init = function () + -- when the first time plugin been load, this function will be execute. + -- system will create a `dcp.json` file to verify init state. + log.info("[plugin] Start to init plugin: " .. manager.name) +end + +---@param info BuildInfo +manager.build.on_start = function (info) + -- before the build work start, system will execute this function. + log.info("[plugin] Build starting: " .. info.name) +end + +---@param info BuildInfo +manager.build.on_finish = function (info) + -- when the build work is done, system will execute this function. + log.info("[plugin] Build finished: " .. info.name) +end + +---@param info ServeStartInfo +manager.serve.on_start = function (info) + -- this function will after clean & print to run, so you can print some thing. + log.info("[plugin] Serve start: " .. info.name) +end + +---@param info ServeRebuildInfo +manager.serve.on_rebuild = function (info) + -- this function will after clean & print to run, so you can print some thing. + local files = plugin.tool.dump(info.changed_files) + log.info("[plugin] Serve rebuild: '" .. files .. "'") +end + +manager.serve.on_shutdown = function () + log.info("[plugin] Serve shutdown") +end + +manager.serve.interval = 1000 + +return manager +``` \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/command.md b/packages/cli/docs/src/plugin/interface/command.md new file mode 100644 index 000000000..18cd32769 --- /dev/null +++ b/packages/cli/docs/src/plugin/interface/command.md @@ -0,0 +1,21 @@ +# Command Functions + +> you can use command functions to execute some code & script + +Type Define: +``` +Stdio: "Inherit" | "Piped" | "Null" +``` + +### `exec(commands: [string], stdout: Stdio, stderr: Stdio)` + +you can use this function to run some command on the current system. + +```lua +local cmd = plugin.command + +manager.test = function () + cmd.exec({"git", "clone", "https://github.com/DioxusLabs/cli-plugin-library"}) +end +``` +> Warning: This function don't have exception catch. \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/dirs.md b/packages/cli/docs/src/plugin/interface/dirs.md new file mode 100644 index 000000000..4173c922f --- /dev/null +++ b/packages/cli/docs/src/plugin/interface/dirs.md @@ -0,0 +1,35 @@ +# Dirs Functions + +> you can use Dirs functions to get some directory path + + +### plugin_dir() -> string + +You can get current plugin **root** directory path + +```lua +local path = plugin.dirs.plugin_dir() +-- example: ~/Development/DioxusCli/plugin/test-plugin/ +``` + +### bin_dir() -> string + +You can get plugin **bin** direcotry path + +Sometime you need install some binary file like `tailwind-cli` & `sass-cli` to help your plugin work, then you should put binary file in this directory. + +```lua +local path = plugin.dirs.bin_dir() +-- example: ~/Development/DioxusCli/plugin/test-plugin/bin/ +``` + +### temp_dir() -> string + +You can get plugin **temp** direcotry path + +Just put some temporary file in this directory. + +```lua +local path = plugin.dirs.bin_dir() +-- example: ~/Development/DioxusCli/plugin/test-plugin/temp/ +``` \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/log.md b/packages/cli/docs/src/plugin/interface/log.md new file mode 100644 index 000000000..fcd72595b --- /dev/null +++ b/packages/cli/docs/src/plugin/interface/log.md @@ -0,0 +1,48 @@ +# Log Functions + +> You can use log function to print some useful log info + +### Trace(info: string) + +Print trace log info + +```lua +local log = plugin.log +log.trace("trace information") +``` + +### Debug(info: string) + +Print debug log info + +```lua +local log = plugin.log +log.debug("debug information") +``` + +### Info(info: string) + +Print info log info + +```lua +local log = plugin.log +log.info("info information") +``` + +### Warn(info: string) + +Print warning log info + +```lua +local log = plugin.log +log.warn("warn information") +``` + +### Error(info: string) + +Print error log info + +```lua +local log = plugin.log +log.error("error information") +``` \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/network.md b/packages/cli/docs/src/plugin/interface/network.md new file mode 100644 index 000000000..358c9c498 --- /dev/null +++ b/packages/cli/docs/src/plugin/interface/network.md @@ -0,0 +1,34 @@ +# Network Functions + +> you can use Network functions to download & read some data from internet + +### download_file(url: string, path: string) -> boolean + +This function can help you download some file from url, and it will return a *boolean* value to check the download status. (true: success | false: fail) + +You need pass a target url and a local path (where you want to save this file) + +```lua +-- this file will download to plugin temp directory +local status = plugin.network.download_file( + "http://xxx.com/xxx.zip", + plugin.dirs.temp_dir() +) +if status != true then + log.error("Download Failed") +end +``` + +### clone_repo(url: string, path: string) -> boolean + +This function can help you use `git clone` command (this system must have been installed git) + +```lua +local status = plugin.network.clone_repo( + "http://github.com/mrxiaozhuox/dioxus-starter", + plugin.dirs.bin_dir() +) +if status != true then + log.error("Clone Failed") +end +``` \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/os.md b/packages/cli/docs/src/plugin/interface/os.md new file mode 100644 index 000000000..72a17c336 --- /dev/null +++ b/packages/cli/docs/src/plugin/interface/os.md @@ -0,0 +1,11 @@ +# OS Functions + +> you can use OS functions to get some system information + +### current_platform() -> string ("windows" | "macos" | "linux") + +This function can help you get system & platform type: + +```lua +local platform = plugin.os.current_platform() +``` \ No newline at end of file diff --git a/packages/cli/docs/src/plugin/interface/path.md b/packages/cli/docs/src/plugin/interface/path.md new file mode 100644 index 000000000..ee787ecf9 --- /dev/null +++ b/packages/cli/docs/src/plugin/interface/path.md @@ -0,0 +1,35 @@ +# Path Functions + +> you can use path functions to operate valid path string + +### join(path: string, extra: string) -> string + +This function can help you extend a path, you can extend any path, dirname or filename. + +```lua +local current_path = "~/hello/dioxus" +local new_path = plugin.path.join(current_path, "world") +-- new_path = "~/hello/dioxus/world" +``` + +### parent(path: string) -> string + +This function will return `path` parent-path string, back to the parent. + +```lua +local current_path = "~/hello/dioxus" +local new_path = plugin.path.parent(current_path) +-- new_path = "~/hello/" +``` + +### exists(path: string) -> boolean + +This function can check some path (dir & file) is exists. + +### is_file(path: string) -> boolean + +This function can check some path is a exist file. + +### is_dir(path: string) -> boolean + +This function can check some path is a exist dir. \ No newline at end of file diff --git a/packages/cli/examples/README.md b/packages/cli/examples/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/cli/examples/plugin/init.lua b/packages/cli/examples/plugin/init.lua new file mode 100644 index 000000000..7d6b710ef --- /dev/null +++ b/packages/cli/examples/plugin/init.lua @@ -0,0 +1,18 @@ +local Api = require("./interface") +local log = Api.log; + +local manager = { + name = "Dioxus-CLI Plugin Demo", + repository = "http://github.com/DioxusLabs/cli", + author = "YuKun Liu ", +} + +manager.onLoad = function () + log.info("plugin loaded.") +end + +manager.onStartBuild = function () + log.warn("system start to build") +end + +return manager \ No newline at end of file diff --git a/packages/cli/examples/plugin/interface.lua b/packages/cli/examples/plugin/interface.lua new file mode 100644 index 000000000..bc6c91cb1 --- /dev/null +++ b/packages/cli/examples/plugin/interface.lua @@ -0,0 +1,25 @@ +local interface = {} + +if plugin_logger ~= nil then + interface.log = plugin_logger +else + interface.log = { + trace = function (info) + print("trace: " .. info) + end, + debug = function (info) + print("debug: " .. info) + end, + info = function (info) + print("info: " .. info) + end, + warn = function (info) + print("warn: " .. info) + end, + error = function (info) + print("error: " .. info) + end, + } +end + +return interface \ No newline at end of file diff --git a/packages/cli/extension/.eslintrc.js b/packages/cli/extension/.eslintrc.js new file mode 100644 index 000000000..8b6c769fd --- /dev/null +++ b/packages/cli/extension/.eslintrc.js @@ -0,0 +1,20 @@ +/**@type {import('eslint').Linter.Config} */ +// eslint-disable-next-line no-undef +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + plugins: [ + '@typescript-eslint', + ], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + ], + rules: { + 'semi': [2, "always"], + '@typescript-eslint/no-unused-vars': 0, + '@typescript-eslint/no-explicit-any': 0, + '@typescript-eslint/explicit-module-boundary-types': 0, + '@typescript-eslint/no-non-null-assertion': 0, + } +}; diff --git a/packages/cli/extension/.gitignore b/packages/cli/extension/.gitignore new file mode 100644 index 000000000..548955b60 --- /dev/null +++ b/packages/cli/extension/.gitignore @@ -0,0 +1,13 @@ +.DS_Store +npm-debug.log +Thumbs.db +*/node_modules/ +node_modules/ +*/out/ +out/ +*/.vs/ +.vs/ +tsconfig.lsif.json +*.lsif +*.db +*.vsix diff --git a/packages/cli/extension/DEV.md b/packages/cli/extension/DEV.md new file mode 100644 index 000000000..54d0c396a --- /dev/null +++ b/packages/cli/extension/DEV.md @@ -0,0 +1,10 @@ + +## packaging + +``` +$ cd myExtension +$ vsce package +# myExtension.vsix generated +$ vsce publish +# .myExtension published to VS Code Marketplace +``` diff --git a/packages/cli/extension/LICENSE.txt b/packages/cli/extension/LICENSE.txt new file mode 100644 index 000000000..6fd3d45f6 --- /dev/null +++ b/packages/cli/extension/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 DioxusLabs + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/packages/cli/extension/README.md b/packages/cli/extension/README.md new file mode 100644 index 000000000..fe67f1587 --- /dev/null +++ b/packages/cli/extension/README.md @@ -0,0 +1,14 @@ +# Dioxus VSCode Extension + +![Dioxus Logo](https://dioxuslabs.com/guide/images/dioxuslogo_full.png) + +This extension wraps functionality in Dioxus CLI to be used in your editor! Make sure the dioxus-cli is installed before using this extension. + +## Current commands: + +### Convert HTML to RSX +Converts a selection of html to valid rsx. + +### Convert HTML to Dioxus Component + +Converts a selection of html to a valid Dioxus component with all SVGs factored out into their own module. diff --git a/packages/cli/extension/dist/.gitignore b/packages/cli/extension/dist/.gitignore new file mode 100644 index 000000000..1287e9bd7 --- /dev/null +++ b/packages/cli/extension/dist/.gitignore @@ -0,0 +1,2 @@ +** +!.gitignore diff --git a/packages/cli/extension/package-lock.json b/packages/cli/extension/package-lock.json new file mode 100644 index 000000000..c671ca72c --- /dev/null +++ b/packages/cli/extension/package-lock.json @@ -0,0 +1,5079 @@ +{ + "name": "dioxus", + "version": "0.0.1", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "dioxus", + "version": "0.0.1", + "license": "MIT", + "dependencies": { + "vsce": "^2.9.2" + }, + "devDependencies": { + "@types/node": "^18.0.2", + "@types/vscode": "^1.68.1", + "@typescript-eslint/eslint-plugin": "^5.30.5", + "@typescript-eslint/parser": "^5.30.5", + "cross-env": "^7.0.3", + "esbuild": "^0.14.27", + "eslint": "^8.19.0", + "eslint-config-prettier": "^8.5.0", + "ovsx": "^0.5.1", + "prettier": "^2.6.2", + "tslib": "^2.3.0", + "typescript": "^4.7.4", + "vsce": "^2.7.0" + }, + "engines": { + "vscode": "^1.68.1" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", + "dev": true, + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@humanwhocodes/config-array": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", + "integrity": "sha512-ObyMyWxZiCu/yTisA7uzx81s40xR2fD5Cg/2Kq7G02ajkNubJf6BopgDTmDyc3U7sXpNKM8cYOw7s7Tyr+DnCw==", + "dev": true, + "dependencies": { + "@humanwhocodes/object-schema": "^1.2.1", + "debug": "^4.1.1", + "minimatch": "^3.0.4" + }, + "engines": { + "node": ">=10.10.0" + } + }, + "node_modules/@humanwhocodes/object-schema": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", + "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "dev": true + }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@types/json-schema": { + "version": "7.0.11", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", + "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", + "dev": true + }, + "node_modules/@types/node": { + "version": "18.0.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.2.tgz", + "integrity": "sha512-b947SdS4GH+g2W33wf5FzUu1KLj5FcSIiNWbU1ZyMvt/X7w48ZsVcsQoirIgE/Oq03WT5Qbn/dkY0hePi4ZXcQ==", + "dev": true + }, + "node_modules/@types/vscode": { + "version": "1.68.1", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.68.1.tgz", + "integrity": "sha512-fXlaq13NT5yHh6yZ3c+UxXloTSk34mIvsNFYyQCeO5Po2BLFAwz7EZT4kQ43B64/aPcnAenyWy3QasrTofBOnQ==", + "dev": true + }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz", + "integrity": "sha512-lftkqRoBvc28VFXEoRgyZuztyVUQ04JvUnATSPtIRFAccbXTWL6DEtXGYMcbg998kXw1NLUJm7rTQ9eUt+q6Ig==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "5.30.5", + "@typescript-eslint/type-utils": "5.30.5", + "@typescript-eslint/utils": "5.30.5", + "debug": "^4.3.4", + "functional-red-black-tree": "^1.0.1", + "ignore": "^5.2.0", + "regexpp": "^3.2.0", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^5.0.0", + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.30.5.tgz", + "integrity": "sha512-zj251pcPXI8GO9NDKWWmygP6+UjwWmrdf9qMW/L/uQJBM/0XbU2inxe5io/234y/RCvwpKEYjZ6c1YrXERkK4Q==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "5.30.5", + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/typescript-estree": "5.30.5", + "debug": "^4.3.4" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.30.5.tgz", + "integrity": "sha512-NJ6F+YHHFT/30isRe2UTmIGGAiXKckCyMnIV58cE3JkHmaD6e5zyEYm5hBDv0Wbin+IC0T1FWJpD3YqHUG/Ydg==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/visitor-keys": "5.30.5" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.30.5.tgz", + "integrity": "sha512-k9+ejlv1GgwN1nN7XjVtyCgE0BTzhzT1YsQF0rv4Vfj2U9xnslBgMYYvcEYAFVdvhuEscELJsB7lDkN7WusErw==", + "dev": true, + "dependencies": { + "@typescript-eslint/utils": "5.30.5", + "debug": "^4.3.4", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "*" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/types": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.30.5.tgz", + "integrity": "sha512-kZ80w/M2AvsbRvOr3PjaNh6qEW1LFqs2pLdo2s5R38B2HYXG8Z0PP48/4+j1QHJFL3ssHIbJ4odPRS8PlHrFfw==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.5.tgz", + "integrity": "sha512-qGTc7QZC801kbYjAr4AgdOfnokpwStqyhSbiQvqGBLixniAKyH+ib2qXIVo4P9NgGzwyfD9I0nlJN7D91E1VpQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/visitor-keys": "5.30.5", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.30.5.tgz", + "integrity": "sha512-o4SSUH9IkuA7AYIfAvatldovurqTAHrfzPApOZvdUq01hHojZojCFXx06D/aFpKCgWbMPRdJBWAC3sWp3itwTA==", + "dev": true, + "dependencies": { + "@types/json-schema": "^7.0.9", + "@typescript-eslint/scope-manager": "5.30.5", + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/typescript-estree": "5.30.5", + "eslint-scope": "^5.1.1", + "eslint-utils": "^3.0.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.5.tgz", + "integrity": "sha512-D+xtGo9HUMELzWIUqcQc0p2PO4NyvTrgIOK/VnSH083+8sq0tiLozNRKuLarwHYGRuA6TVBQSuuLwJUDWd3aaA==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.30.5", + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/acorn": { + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/azure-devops-node-api": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/azure-devops-node-api/-/azure-devops-node-api-11.1.1.tgz", + "integrity": "sha512-XDG91XzLZ15reP12s3jFkKS8oiagSICjnLwxEYieme4+4h3ZveFOFRA4iYIG40RyHXsiI0mefFYYMFIJbMpWcg==", + "dev": true, + "dependencies": { + "tunnel": "0.0.6", + "typed-rest-client": "^1.8.4" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "dev": true, + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/cheerio": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz", + "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==", + "dev": true, + "dependencies": { + "cheerio-select": "^2.1.0", + "dom-serializer": "^2.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1", + "htmlparser2": "^8.0.1", + "parse5": "^7.0.0", + "parse5-htmlparser2-tree-adapter": "^7.0.0" + }, + "engines": { + "node": ">= 6" + }, + "funding": { + "url": "https://github.com/cheeriojs/cheerio?sponsor=1" + } + }, + "node_modules/cheerio-select": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", + "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", + "dev": true, + "dependencies": { + "boolbase": "^1.0.0", + "css-select": "^5.1.0", + "css-what": "^6.1.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/chownr": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", + "dev": true + }, + "node_modules/ci-info": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", + "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", + "dev": true + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true + }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/css-select": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", + "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "dev": true, + "dependencies": { + "boolbase": "^1.0.0", + "css-what": "^6.1.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "nth-check": "^2.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/css-what": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", + "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", + "dev": true, + "engines": { + "node": ">= 6" + }, + "funding": { + "url": "https://github.com/sponsors/fb55" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "dev": true, + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, + "node_modules/detect-libc": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", + "integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "dev": true, + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + }, + "funding": { + "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" + } + }, + "node_modules/domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ] + }, + "node_modules/domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "dev": true, + "dependencies": { + "domelementtype": "^2.3.0" + }, + "engines": { + "node": ">= 4" + }, + "funding": { + "url": "https://github.com/fb55/domhandler?sponsor=1" + } + }, + "node_modules/domutils": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", + "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", + "dev": true, + "dependencies": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.1" + }, + "funding": { + "url": "https://github.com/fb55/domutils?sponsor=1" + } + }, + "node_modules/end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "dev": true, + "dependencies": { + "once": "^1.4.0" + } + }, + "node_modules/entities": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.3.1.tgz", + "integrity": "sha512-o4q/dYJlmyjP2zfnaWDUC6A3BQFmVTX+tZPezK7k0GLSU9QYCauscf5Y+qcEPzKL+EixVouYDgLQK5H9GrLpkg==", + "dev": true, + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/esbuild": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.48.tgz", + "integrity": "sha512-w6N1Yn5MtqK2U1/WZTX9ZqUVb8IOLZkZ5AdHkT6x3cHDMVsYWC7WPdiLmx19w3i4Rwzy5LqsEMtVihG3e4rFzA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "esbuild-android-64": "0.14.48", + "esbuild-android-arm64": "0.14.48", + "esbuild-darwin-64": "0.14.48", + "esbuild-darwin-arm64": "0.14.48", + "esbuild-freebsd-64": "0.14.48", + "esbuild-freebsd-arm64": "0.14.48", + "esbuild-linux-32": "0.14.48", + "esbuild-linux-64": "0.14.48", + "esbuild-linux-arm": "0.14.48", + "esbuild-linux-arm64": "0.14.48", + "esbuild-linux-mips64le": "0.14.48", + "esbuild-linux-ppc64le": "0.14.48", + "esbuild-linux-riscv64": "0.14.48", + "esbuild-linux-s390x": "0.14.48", + "esbuild-netbsd-64": "0.14.48", + "esbuild-openbsd-64": "0.14.48", + "esbuild-sunos-64": "0.14.48", + "esbuild-windows-32": "0.14.48", + "esbuild-windows-64": "0.14.48", + "esbuild-windows-arm64": "0.14.48" + } + }, + "node_modules/esbuild-android-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.14.48.tgz", + "integrity": "sha512-3aMjboap/kqwCUpGWIjsk20TtxVoKck8/4Tu19rubh7t5Ra0Yrpg30Mt1QXXlipOazrEceGeWurXKeFJgkPOUg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-android-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.48.tgz", + "integrity": "sha512-vptI3K0wGALiDq+EvRuZotZrJqkYkN5282iAfcffjI5lmGG9G1ta/CIVauhY42MBXwEgDJkweiDcDMRLzBZC4g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-darwin-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.48.tgz", + "integrity": "sha512-gGQZa4+hab2Va/Zww94YbshLuWteyKGD3+EsVon8EWTWhnHFRm5N9NbALNbwi/7hQ/hM1Zm4FuHg+k6BLsl5UA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-darwin-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.48.tgz", + "integrity": "sha512-bFjnNEXjhZT+IZ8RvRGNJthLWNHV5JkCtuOFOnjvo5pC0sk2/QVk0Qc06g2PV3J0TcU6kaPC3RN9yy9w2PSLEA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-freebsd-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.48.tgz", + "integrity": "sha512-1NOlwRxmOsnPcWOGTB10JKAkYSb2nue0oM1AfHWunW/mv3wERfJmnYlGzL3UAOIUXZqW8GeA2mv+QGwq7DToqA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-freebsd-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.48.tgz", + "integrity": "sha512-gXqKdO8wabVcYtluAbikDH2jhXp+Klq5oCD5qbVyUG6tFiGhrC9oczKq3vIrrtwcxDQqK6+HDYK8Zrd4bCA9Gw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-32": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.48.tgz", + "integrity": "sha512-ghGyDfS289z/LReZQUuuKq9KlTiTspxL8SITBFQFAFRA/IkIvDpnZnCAKTCjGXAmUqroMQfKJXMxyjJA69c/nQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.48.tgz", + "integrity": "sha512-vni3p/gppLMVZLghI7oMqbOZdGmLbbKR23XFARKnszCIBpEMEDxOMNIKPmMItQrmH/iJrL1z8Jt2nynY0bE1ug==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-arm": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.48.tgz", + "integrity": "sha512-+VfSV7Akh1XUiDNXgqgY1cUP1i2vjI+BmlyXRfVz5AfV3jbpde8JTs5Q9sYgaoq5cWfuKfoZB/QkGOI+QcL1Tw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.48.tgz", + "integrity": "sha512-3CFsOlpoxlKPRevEHq8aAntgYGYkE1N9yRYAcPyng/p4Wyx0tPR5SBYsxLKcgPB9mR8chHEhtWYz6EZ+H199Zw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-mips64le": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.48.tgz", + "integrity": "sha512-cs0uOiRlPp6ymknDnjajCgvDMSsLw5mST2UXh+ZIrXTj2Ifyf2aAP3Iw4DiqgnyYLV2O/v/yWBJx+WfmKEpNLA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-ppc64le": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.48.tgz", + "integrity": "sha512-+2F0vJMkuI0Wie/wcSPDCqXvSFEELH7Jubxb7mpWrA/4NpT+/byjxDz0gG6R1WJoeDefcrMfpBx4GFNN1JQorQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-riscv64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.48.tgz", + "integrity": "sha512-BmaK/GfEE+5F2/QDrIXteFGKnVHGxlnK9MjdVKMTfvtmudjY3k2t8NtlY4qemKSizc+QwyombGWTBDc76rxePA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-linux-s390x": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.48.tgz", + "integrity": "sha512-tndw/0B9jiCL+KWKo0TSMaUm5UWBLsfCKVdbfMlb3d5LeV9WbijZ8Ordia8SAYv38VSJWOEt6eDCdOx8LqkC4g==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-netbsd-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.48.tgz", + "integrity": "sha512-V9hgXfwf/T901Lr1wkOfoevtyNkrxmMcRHyticybBUHookznipMOHoF41Al68QBsqBxnITCEpjjd4yAos7z9Tw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-openbsd-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.48.tgz", + "integrity": "sha512-+IHf4JcbnnBl4T52egorXMatil/za0awqzg2Vy6FBgPcBpisDWT2sVz/tNdrK9kAqj+GZG/jZdrOkj7wsrNTKA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-sunos-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.48.tgz", + "integrity": "sha512-77m8bsr5wOpOWbGi9KSqDphcq6dFeJyun8TA+12JW/GAjyfTwVtOnN8DOt6DSPUfEV+ltVMNqtXUeTeMAxl5KA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-windows-32": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.48.tgz", + "integrity": "sha512-EPgRuTPP8vK9maxpTGDe5lSoIBHGKO/AuxDncg5O3NkrPeLNdvvK8oywB0zGaAZXxYWfNNSHskvvDgmfVTguhg==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-windows-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.48.tgz", + "integrity": "sha512-YmpXjdT1q0b8ictSdGwH3M8VCoqPpK1/UArze3X199w6u8hUx3V8BhAi1WjbsfDYRBanVVtduAhh2sirImtAvA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/esbuild-windows-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.48.tgz", + "integrity": "sha512-HHaOMCsCXp0rz5BT2crTka6MPWVno121NKApsGs/OIW5QC0ggC69YMGs1aJct9/9FSUF4A1xNE/cLvgB5svR4g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.19.0.tgz", + "integrity": "sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw==", + "dev": true, + "dependencies": { + "@eslint/eslintrc": "^1.3.0", + "@humanwhocodes/config-array": "^0.9.2", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.1.1", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^3.3.0", + "espree": "^9.3.2", + "esquery": "^1.4.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^6.0.1", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "regexpp": "^3.2.0", + "strip-ansi": "^6.0.1", + "strip-json-comments": "^3.1.0", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-config-prettier": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", + "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "dev": true, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/eslint-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^2.0.0" + }, + "engines": { + "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=5" + } + }, + "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/eslint/node_modules/eslint-scope": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", + "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/eslint/node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/espree": { + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", + "dev": true, + "dependencies": { + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/esquery": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", + "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", + "dev": true, + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esquery/node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esrecurse/node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/expand-template": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", + "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "node_modules/fast-glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", + "integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "node_modules/fastq": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", + "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "dev": true, + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", + "dev": true, + "dependencies": { + "pend": "~1.2.0" + } + }, + "node_modules/file-entry-cache": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "dev": true, + "dependencies": { + "flat-cache": "^3.0.4" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/flat-cache": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "dev": true, + "dependencies": { + "flatted": "^3.1.0", + "rimraf": "^3.0.2" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/flatted": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.6.tgz", + "integrity": "sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==", + "dev": true + }, + "node_modules/follow-redirects": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", + "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", + "dev": true + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "node_modules/functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", + "dev": true + }, + "node_modules/get-intrinsic": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz", + "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", + "dev": true + }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/globals": { + "version": "13.16.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.16.0.tgz", + "integrity": "sha512-A1lrQfpNF+McdPOnnFqY3kSN0AFTy485bTi1bkLk4mVPODIUEcSfhHgRqA+QdXPksrSTTztYXx37NFV+GpGk3Q==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hosted-git-info": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-4.1.0.tgz", + "integrity": "sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/htmlparser2": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.1.tgz", + "integrity": "sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==", + "dev": true, + "funding": [ + "https://github.com/fb55/htmlparser2?sponsor=1", + { + "type": "github", + "url": "https://github.com/sponsors/fb55" + } + ], + "dependencies": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "entities": "^4.3.0" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/ignore": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "node_modules/ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "dev": true + }, + "node_modules/is-ci": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", + "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", + "dev": true, + "dependencies": { + "ci-info": "^2.0.0" + }, + "bin": { + "is-ci": "bin.js" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, + "node_modules/keytar": { + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/keytar/-/keytar-7.9.0.tgz", + "integrity": "sha512-VPD8mtVtm5JNtA2AErl6Chp06JBfy7diFQ7TQQhdpWOl6MrCRB+eRbvAZUsbGQS9kiMq0coJsy0W0vHpDCkWsQ==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "node-addon-api": "^4.3.0", + "prebuild-install": "^7.0.1" + } + }, + "node_modules/leven": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", + "integrity": "sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/linkify-it": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz", + "integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==", + "dev": true, + "dependencies": { + "uc.micro": "^1.0.1" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/markdown-it": { + "version": "12.3.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", + "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1", + "entities": "~2.1.0", + "linkify-it": "^3.0.1", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + }, + "bin": { + "markdown-it": "bin/markdown-it.js" + } + }, + "node_modules/markdown-it/node_modules/entities": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", + "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==", + "dev": true, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, + "node_modules/mdurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==", + "dev": true + }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "dependencies": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "dev": true, + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "dev": true + }, + "node_modules/mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", + "dev": true + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node_modules/mute-stream": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", + "dev": true + }, + "node_modules/napi-build-utils": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", + "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==", + "dev": true + }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true + }, + "node_modules/node-abi": { + "version": "3.22.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.22.0.tgz", + "integrity": "sha512-u4uAs/4Zzmp/jjsD9cyFYDXeISfUWaAVWshPmDZOFOv4Xl4SbzTXm53I04C2uRueYJ+0t5PEtLH/owbn2Npf/w==", + "dev": true, + "dependencies": { + "semver": "^7.3.5" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==", + "dev": true + }, + "node_modules/nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "dev": true, + "dependencies": { + "boolbase": "^1.0.0" + }, + "funding": { + "url": "https://github.com/fb55/nth-check?sponsor=1" + } + }, + "node_modules/object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/ovsx": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/ovsx/-/ovsx-0.5.1.tgz", + "integrity": "sha512-3OWq0l7DuVHi2bd2aQe5+QVQlFIqvrcw3/2vGXL404L6Tr+R4QHtzfnYYghv8CCa85xJHjU0RhcaC7pyXkAUbg==", + "dev": true, + "dependencies": { + "commander": "^6.1.0", + "follow-redirects": "^1.14.6", + "is-ci": "^2.0.0", + "leven": "^3.1.0", + "tmp": "^0.2.1", + "vsce": "^2.6.3" + }, + "bin": { + "ovsx": "lib/ovsx" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/parse-semver": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/parse-semver/-/parse-semver-1.1.1.tgz", + "integrity": "sha512-Eg1OuNntBMH0ojvEKSrvDSnwLmvVuUOSdylH/pSCPNMIspLlweJyIWXCE+k/5hm3cj/EBUYwmWkjhBALNP4LXQ==", + "dev": true, + "dependencies": { + "semver": "^5.1.0" + } + }, + "node_modules/parse-semver/node_modules/semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true, + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/parse5": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.0.0.tgz", + "integrity": "sha512-y/t8IXSPWTuRZqXc0ajH/UwDj4mnqLEbSttNbThcFhGrZuOyoyvNBO85PBp2jQa55wY9d07PBNjsK8ZP3K5U6g==", + "dev": true, + "dependencies": { + "entities": "^4.3.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/parse5-htmlparser2-tree-adapter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", + "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "dev": true, + "dependencies": { + "domhandler": "^5.0.2", + "parse5": "^7.0.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", + "dev": true + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/prebuild-install": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.1.tgz", + "integrity": "sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==", + "dev": true, + "dependencies": { + "detect-libc": "^2.0.0", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp-classic": "^0.5.3", + "napi-build-utils": "^1.0.1", + "node-abi": "^3.3.0", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^4.0.0", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0" + }, + "bin": { + "prebuild-install": "bin.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "dev": true, + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/rc": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "dev": true, + "dependencies": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "bin": { + "rc": "cli.js" + } + }, + "node_modules/rc/node_modules/strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/read": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", + "integrity": "sha512-rSOKNYUmaxy0om1BNjMN4ezNT6VKK+2xF4GBhc81mkH7L60i6dp8qPYrkndNLT3QPphoII3maL9PVC9XmhHwVQ==", + "dev": true, + "dependencies": { + "mute-stream": "~0.0.4" + }, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/regexpp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", + "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + } + }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true, + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "dev": true + }, + "node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/simple-get": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", + "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "decompress-response": "^6.0.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, + "node_modules/slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dev": true, + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/tar-fs": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", + "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "dev": true, + "dependencies": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "node_modules/tar-stream": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "dev": true, + "dependencies": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, + "node_modules/tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "dependencies": { + "rimraf": "^3.0.0" + }, + "engines": { + "node": ">=8.17.0" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "dev": true + }, + "node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, + "node_modules/tsutils/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "dev": true, + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.0.1" + }, + "engines": { + "node": "*" + } + }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/typed-rest-client": { + "version": "1.8.9", + "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.8.9.tgz", + "integrity": "sha512-uSmjE38B80wjL85UFX3sTYEUlvZ1JgCRhsWj/fJ4rZ0FqDUFoIuodtiVeE+cUqiVTOKPdKrp/sdftD15MDek6g==", + "dev": true, + "dependencies": { + "qs": "^6.9.1", + "tunnel": "0.0.6", + "underscore": "^1.12.1" + } + }, + "node_modules/typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", + "dev": true + }, + "node_modules/underscore": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.4.tgz", + "integrity": "sha512-BQFnUDuAQ4Yf/cYY5LNrK9NCJFKriaRbD9uR1fTeXnBeoa97W0i41qkZfGO9pSo8I5KzjAcSY2XYtdf0oKd7KQ==", + "dev": true + }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "dependencies": { + "punycode": "^2.1.0" + } + }, + "node_modules/url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==", + "dev": true + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true + }, + "node_modules/v8-compile-cache": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", + "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", + "dev": true + }, + "node_modules/vsce": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/vsce/-/vsce-2.9.2.tgz", + "integrity": "sha512-xyLqL4U82BilUX1t6Ym2opQEa2tLGWYjbgB7+ETeNVXlIJz5sWBJjQJSYJVFOKJSpiOtQclolu88cj7oY6vvPQ==", + "dev": true, + "dependencies": { + "azure-devops-node-api": "^11.0.1", + "chalk": "^2.4.2", + "cheerio": "^1.0.0-rc.9", + "commander": "^6.1.0", + "glob": "^7.0.6", + "hosted-git-info": "^4.0.2", + "keytar": "^7.7.0", + "leven": "^3.1.0", + "markdown-it": "^12.3.2", + "mime": "^1.3.4", + "minimatch": "^3.0.3", + "parse-semver": "^1.1.1", + "read": "^1.0.7", + "semver": "^5.1.0", + "tmp": "^0.2.1", + "typed-rest-client": "^1.8.4", + "url-join": "^4.0.1", + "xml2js": "^0.4.23", + "yauzl": "^2.3.1", + "yazl": "^2.2.2" + }, + "bin": { + "vsce": "vsce" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/vsce/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/vsce/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/vsce/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/vsce/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/vsce/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/vsce/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/vsce/node_modules/semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true, + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/vsce/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true + }, + "node_modules/xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "dev": true, + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", + "dev": true, + "dependencies": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } + }, + "node_modules/yazl": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/yazl/-/yazl-2.5.1.tgz", + "integrity": "sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==", + "dev": true, + "dependencies": { + "buffer-crc32": "~0.2.3" + } + } + }, + "dependencies": { + "@eslint/eslintrc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", + "dev": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + } + }, + "@humanwhocodes/config-array": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", + "integrity": "sha512-ObyMyWxZiCu/yTisA7uzx81s40xR2fD5Cg/2Kq7G02ajkNubJf6BopgDTmDyc3U7sXpNKM8cYOw7s7Tyr+DnCw==", + "dev": true, + "requires": { + "@humanwhocodes/object-schema": "^1.2.1", + "debug": "^4.1.1", + "minimatch": "^3.0.4" + } + }, + "@humanwhocodes/object-schema": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", + "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "dev": true + }, + "@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + } + }, + "@types/json-schema": { + "version": "7.0.11", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", + "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", + "dev": true + }, + "@types/node": { + "version": "18.0.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.2.tgz", + "integrity": "sha512-b947SdS4GH+g2W33wf5FzUu1KLj5FcSIiNWbU1ZyMvt/X7w48ZsVcsQoirIgE/Oq03WT5Qbn/dkY0hePi4ZXcQ==", + "dev": true + }, + "@types/vscode": { + "version": "1.68.1", + "resolved": "https://registry.npmjs.org/@types/vscode/-/vscode-1.68.1.tgz", + "integrity": "sha512-fXlaq13NT5yHh6yZ3c+UxXloTSk34mIvsNFYyQCeO5Po2BLFAwz7EZT4kQ43B64/aPcnAenyWy3QasrTofBOnQ==", + "dev": true + }, + "@typescript-eslint/eslint-plugin": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.30.5.tgz", + "integrity": "sha512-lftkqRoBvc28VFXEoRgyZuztyVUQ04JvUnATSPtIRFAccbXTWL6DEtXGYMcbg998kXw1NLUJm7rTQ9eUt+q6Ig==", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "5.30.5", + "@typescript-eslint/type-utils": "5.30.5", + "@typescript-eslint/utils": "5.30.5", + "debug": "^4.3.4", + "functional-red-black-tree": "^1.0.1", + "ignore": "^5.2.0", + "regexpp": "^3.2.0", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/parser": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.30.5.tgz", + "integrity": "sha512-zj251pcPXI8GO9NDKWWmygP6+UjwWmrdf9qMW/L/uQJBM/0XbU2inxe5io/234y/RCvwpKEYjZ6c1YrXERkK4Q==", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "5.30.5", + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/typescript-estree": "5.30.5", + "debug": "^4.3.4" + } + }, + "@typescript-eslint/scope-manager": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.30.5.tgz", + "integrity": "sha512-NJ6F+YHHFT/30isRe2UTmIGGAiXKckCyMnIV58cE3JkHmaD6e5zyEYm5hBDv0Wbin+IC0T1FWJpD3YqHUG/Ydg==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/visitor-keys": "5.30.5" + } + }, + "@typescript-eslint/type-utils": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.30.5.tgz", + "integrity": "sha512-k9+ejlv1GgwN1nN7XjVtyCgE0BTzhzT1YsQF0rv4Vfj2U9xnslBgMYYvcEYAFVdvhuEscELJsB7lDkN7WusErw==", + "dev": true, + "requires": { + "@typescript-eslint/utils": "5.30.5", + "debug": "^4.3.4", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/types": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.30.5.tgz", + "integrity": "sha512-kZ80w/M2AvsbRvOr3PjaNh6qEW1LFqs2pLdo2s5R38B2HYXG8Z0PP48/4+j1QHJFL3ssHIbJ4odPRS8PlHrFfw==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.5.tgz", + "integrity": "sha512-qGTc7QZC801kbYjAr4AgdOfnokpwStqyhSbiQvqGBLixniAKyH+ib2qXIVo4P9NgGzwyfD9I0nlJN7D91E1VpQ==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/visitor-keys": "5.30.5", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + } + }, + "@typescript-eslint/utils": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.30.5.tgz", + "integrity": "sha512-o4SSUH9IkuA7AYIfAvatldovurqTAHrfzPApOZvdUq01hHojZojCFXx06D/aFpKCgWbMPRdJBWAC3sWp3itwTA==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.9", + "@typescript-eslint/scope-manager": "5.30.5", + "@typescript-eslint/types": "5.30.5", + "@typescript-eslint/typescript-estree": "5.30.5", + "eslint-scope": "^5.1.1", + "eslint-utils": "^3.0.0" + } + }, + "@typescript-eslint/visitor-keys": { + "version": "5.30.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.5.tgz", + "integrity": "sha512-D+xtGo9HUMELzWIUqcQc0p2PO4NyvTrgIOK/VnSH083+8sq0tiLozNRKuLarwHYGRuA6TVBQSuuLwJUDWd3aaA==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.30.5", + "eslint-visitor-keys": "^3.3.0" + } + }, + "acorn": { + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", + "dev": true + }, + "acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "requires": {} + }, + "ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true + }, + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, + "azure-devops-node-api": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/azure-devops-node-api/-/azure-devops-node-api-11.1.1.tgz", + "integrity": "sha512-XDG91XzLZ15reP12s3jFkKS8oiagSICjnLwxEYieme4+4h3ZveFOFRA4iYIG40RyHXsiI0mefFYYMFIJbMpWcg==", + "dev": true, + "requires": { + "tunnel": "0.0.6", + "typed-rest-client": "^1.8.4" + } + }, + "balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true + }, + "bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "dev": true, + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", + "dev": true + }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true + }, + "chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "cheerio": { + "version": "1.0.0-rc.12", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.12.tgz", + "integrity": "sha512-VqR8m68vM46BNnuZ5NtnGBKIE/DfN0cRIzg9n40EIq9NOv90ayxLBXA8fXC5gquFRGJSTRqBq25Jt2ECLR431Q==", + "dev": true, + "requires": { + "cheerio-select": "^2.1.0", + "dom-serializer": "^2.0.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1", + "htmlparser2": "^8.0.1", + "parse5": "^7.0.0", + "parse5-htmlparser2-tree-adapter": "^7.0.0" + } + }, + "cheerio-select": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cheerio-select/-/cheerio-select-2.1.0.tgz", + "integrity": "sha512-9v9kG0LvzrlcungtnJtpGNxY+fzECQKhK4EGJX2vByejiMX84MFNQw4UxPJl3bFbTMw+Dfs37XaIkCwTZfLh4g==", + "dev": true, + "requires": { + "boolbase": "^1.0.0", + "css-select": "^5.1.0", + "css-what": "^6.1.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.3", + "domutils": "^3.0.1" + } + }, + "chownr": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", + "dev": true + }, + "ci-info": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", + "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", + "dev": true + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true + }, + "cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.1" + } + }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, + "css-select": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", + "integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==", + "dev": true, + "requires": { + "boolbase": "^1.0.0", + "css-what": "^6.1.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "nth-check": "^2.0.1" + } + }, + "css-what": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.1.0.tgz", + "integrity": "sha512-HTUrgRJ7r4dsZKU6GjmpfRK1O76h97Z8MfS1G0FozR+oF2kG6Vfe8JE6zwrkbxigziPHinCJ+gCPjA9EaBDtRw==", + "dev": true + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "dev": true, + "requires": { + "mimic-response": "^3.1.0" + } + }, + "deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "dev": true + }, + "deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, + "detect-libc": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", + "integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==", + "dev": true + }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "dev": true, + "requires": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + } + }, + "domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "dev": true + }, + "domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "dev": true, + "requires": { + "domelementtype": "^2.3.0" + } + }, + "domutils": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", + "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", + "dev": true, + "requires": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.1" + } + }, + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "dev": true, + "requires": { + "once": "^1.4.0" + } + }, + "entities": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.3.1.tgz", + "integrity": "sha512-o4q/dYJlmyjP2zfnaWDUC6A3BQFmVTX+tZPezK7k0GLSU9QYCauscf5Y+qcEPzKL+EixVouYDgLQK5H9GrLpkg==", + "dev": true + }, + "esbuild": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.48.tgz", + "integrity": "sha512-w6N1Yn5MtqK2U1/WZTX9ZqUVb8IOLZkZ5AdHkT6x3cHDMVsYWC7WPdiLmx19w3i4Rwzy5LqsEMtVihG3e4rFzA==", + "dev": true, + "requires": { + "esbuild-android-64": "0.14.48", + "esbuild-android-arm64": "0.14.48", + "esbuild-darwin-64": "0.14.48", + "esbuild-darwin-arm64": "0.14.48", + "esbuild-freebsd-64": "0.14.48", + "esbuild-freebsd-arm64": "0.14.48", + "esbuild-linux-32": "0.14.48", + "esbuild-linux-64": "0.14.48", + "esbuild-linux-arm": "0.14.48", + "esbuild-linux-arm64": "0.14.48", + "esbuild-linux-mips64le": "0.14.48", + "esbuild-linux-ppc64le": "0.14.48", + "esbuild-linux-riscv64": "0.14.48", + "esbuild-linux-s390x": "0.14.48", + "esbuild-netbsd-64": "0.14.48", + "esbuild-openbsd-64": "0.14.48", + "esbuild-sunos-64": "0.14.48", + "esbuild-windows-32": "0.14.48", + "esbuild-windows-64": "0.14.48", + "esbuild-windows-arm64": "0.14.48" + } + }, + "esbuild-android-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.14.48.tgz", + "integrity": "sha512-3aMjboap/kqwCUpGWIjsk20TtxVoKck8/4Tu19rubh7t5Ra0Yrpg30Mt1QXXlipOazrEceGeWurXKeFJgkPOUg==", + "dev": true, + "optional": true + }, + "esbuild-android-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.48.tgz", + "integrity": "sha512-vptI3K0wGALiDq+EvRuZotZrJqkYkN5282iAfcffjI5lmGG9G1ta/CIVauhY42MBXwEgDJkweiDcDMRLzBZC4g==", + "dev": true, + "optional": true + }, + "esbuild-darwin-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.48.tgz", + "integrity": "sha512-gGQZa4+hab2Va/Zww94YbshLuWteyKGD3+EsVon8EWTWhnHFRm5N9NbALNbwi/7hQ/hM1Zm4FuHg+k6BLsl5UA==", + "dev": true, + "optional": true + }, + "esbuild-darwin-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.48.tgz", + "integrity": "sha512-bFjnNEXjhZT+IZ8RvRGNJthLWNHV5JkCtuOFOnjvo5pC0sk2/QVk0Qc06g2PV3J0TcU6kaPC3RN9yy9w2PSLEA==", + "dev": true, + "optional": true + }, + "esbuild-freebsd-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.48.tgz", + "integrity": "sha512-1NOlwRxmOsnPcWOGTB10JKAkYSb2nue0oM1AfHWunW/mv3wERfJmnYlGzL3UAOIUXZqW8GeA2mv+QGwq7DToqA==", + "dev": true, + "optional": true + }, + "esbuild-freebsd-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.48.tgz", + "integrity": "sha512-gXqKdO8wabVcYtluAbikDH2jhXp+Klq5oCD5qbVyUG6tFiGhrC9oczKq3vIrrtwcxDQqK6+HDYK8Zrd4bCA9Gw==", + "dev": true, + "optional": true + }, + "esbuild-linux-32": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.48.tgz", + "integrity": "sha512-ghGyDfS289z/LReZQUuuKq9KlTiTspxL8SITBFQFAFRA/IkIvDpnZnCAKTCjGXAmUqroMQfKJXMxyjJA69c/nQ==", + "dev": true, + "optional": true + }, + "esbuild-linux-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.48.tgz", + "integrity": "sha512-vni3p/gppLMVZLghI7oMqbOZdGmLbbKR23XFARKnszCIBpEMEDxOMNIKPmMItQrmH/iJrL1z8Jt2nynY0bE1ug==", + "dev": true, + "optional": true + }, + "esbuild-linux-arm": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.48.tgz", + "integrity": "sha512-+VfSV7Akh1XUiDNXgqgY1cUP1i2vjI+BmlyXRfVz5AfV3jbpde8JTs5Q9sYgaoq5cWfuKfoZB/QkGOI+QcL1Tw==", + "dev": true, + "optional": true + }, + "esbuild-linux-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.48.tgz", + "integrity": "sha512-3CFsOlpoxlKPRevEHq8aAntgYGYkE1N9yRYAcPyng/p4Wyx0tPR5SBYsxLKcgPB9mR8chHEhtWYz6EZ+H199Zw==", + "dev": true, + "optional": true + }, + "esbuild-linux-mips64le": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.48.tgz", + "integrity": "sha512-cs0uOiRlPp6ymknDnjajCgvDMSsLw5mST2UXh+ZIrXTj2Ifyf2aAP3Iw4DiqgnyYLV2O/v/yWBJx+WfmKEpNLA==", + "dev": true, + "optional": true + }, + "esbuild-linux-ppc64le": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.48.tgz", + "integrity": "sha512-+2F0vJMkuI0Wie/wcSPDCqXvSFEELH7Jubxb7mpWrA/4NpT+/byjxDz0gG6R1WJoeDefcrMfpBx4GFNN1JQorQ==", + "dev": true, + "optional": true + }, + "esbuild-linux-riscv64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.48.tgz", + "integrity": "sha512-BmaK/GfEE+5F2/QDrIXteFGKnVHGxlnK9MjdVKMTfvtmudjY3k2t8NtlY4qemKSizc+QwyombGWTBDc76rxePA==", + "dev": true, + "optional": true + }, + "esbuild-linux-s390x": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.48.tgz", + "integrity": "sha512-tndw/0B9jiCL+KWKo0TSMaUm5UWBLsfCKVdbfMlb3d5LeV9WbijZ8Ordia8SAYv38VSJWOEt6eDCdOx8LqkC4g==", + "dev": true, + "optional": true + }, + "esbuild-netbsd-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.48.tgz", + "integrity": "sha512-V9hgXfwf/T901Lr1wkOfoevtyNkrxmMcRHyticybBUHookznipMOHoF41Al68QBsqBxnITCEpjjd4yAos7z9Tw==", + "dev": true, + "optional": true + }, + "esbuild-openbsd-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.48.tgz", + "integrity": "sha512-+IHf4JcbnnBl4T52egorXMatil/za0awqzg2Vy6FBgPcBpisDWT2sVz/tNdrK9kAqj+GZG/jZdrOkj7wsrNTKA==", + "dev": true, + "optional": true + }, + "esbuild-sunos-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.48.tgz", + "integrity": "sha512-77m8bsr5wOpOWbGi9KSqDphcq6dFeJyun8TA+12JW/GAjyfTwVtOnN8DOt6DSPUfEV+ltVMNqtXUeTeMAxl5KA==", + "dev": true, + "optional": true + }, + "esbuild-windows-32": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.48.tgz", + "integrity": "sha512-EPgRuTPP8vK9maxpTGDe5lSoIBHGKO/AuxDncg5O3NkrPeLNdvvK8oywB0zGaAZXxYWfNNSHskvvDgmfVTguhg==", + "dev": true, + "optional": true + }, + "esbuild-windows-64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.48.tgz", + "integrity": "sha512-YmpXjdT1q0b8ictSdGwH3M8VCoqPpK1/UArze3X199w6u8hUx3V8BhAi1WjbsfDYRBanVVtduAhh2sirImtAvA==", + "dev": true, + "optional": true + }, + "esbuild-windows-arm64": { + "version": "0.14.48", + "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.48.tgz", + "integrity": "sha512-HHaOMCsCXp0rz5BT2crTka6MPWVno121NKApsGs/OIW5QC0ggC69YMGs1aJct9/9FSUF4A1xNE/cLvgB5svR4g==", + "dev": true, + "optional": true + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "eslint": { + "version": "8.19.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.19.0.tgz", + "integrity": "sha512-SXOPj3x9VKvPe81TjjUJCYlV4oJjQw68Uek+AM0X4p+33dj2HY5bpTZOgnQHcG2eAm1mtCU9uNMnJi7exU/kYw==", + "dev": true, + "requires": { + "@eslint/eslintrc": "^1.3.0", + "@humanwhocodes/config-array": "^0.9.2", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.1.1", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^3.3.0", + "espree": "^9.3.2", + "esquery": "^1.4.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^6.0.1", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "regexpp": "^3.2.0", + "strip-ansi": "^6.0.1", + "strip-json-comments": "^3.1.0", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "eslint-scope": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", + "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + } + }, + "estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true + } + } + }, + "eslint-config-prettier": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", + "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "dev": true, + "requires": {} + }, + "eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^2.0.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true + } + } + }, + "eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true + }, + "espree": { + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", + "dev": true, + "requires": { + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.3.0" + } + }, + "esquery": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", + "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", + "dev": true, + "requires": { + "estraverse": "^5.1.0" + }, + "dependencies": { + "estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true + } + } + }, + "esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "requires": { + "estraverse": "^5.2.0" + }, + "dependencies": { + "estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true + } + } + }, + "estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true + }, + "esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true + }, + "expand-template": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", + "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", + "dev": true + }, + "fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "fast-glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", + "integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "dependencies": { + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + } + } + }, + "fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "fastq": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", + "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, + "fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", + "dev": true, + "requires": { + "pend": "~1.2.0" + } + }, + "file-entry-cache": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "dev": true, + "requires": { + "flat-cache": "^3.0.4" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "flat-cache": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "dev": true, + "requires": { + "flatted": "^3.1.0", + "rimraf": "^3.0.2" + } + }, + "flatted": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.6.tgz", + "integrity": "sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==", + "dev": true + }, + "follow-redirects": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", + "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", + "dev": true + }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", + "dev": true + }, + "get-intrinsic": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz", + "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==", + "dev": true, + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + } + }, + "github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", + "dev": true + }, + "glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "requires": { + "is-glob": "^4.0.3" + } + }, + "globals": { + "version": "13.16.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.16.0.tgz", + "integrity": "sha512-A1lrQfpNF+McdPOnnFqY3kSN0AFTy485bTi1bkLk4mVPODIUEcSfhHgRqA+QdXPksrSTTztYXx37NFV+GpGk3Q==", + "dev": true, + "requires": { + "type-fest": "^0.20.2" + } + }, + "globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true + }, + "hosted-git-info": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-4.1.0.tgz", + "integrity": "sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "htmlparser2": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-8.0.1.tgz", + "integrity": "sha512-4lVbmc1diZC7GUJQtRQ5yBAeUCL1exyMwmForWkRLnwyzWBFxN633SALPMGYaWZvKe9j1pRZJpauvmxENSp/EA==", + "dev": true, + "requires": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "domutils": "^3.0.1", + "entities": "^4.3.0" + } + }, + "ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true + }, + "ignore": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "dev": true + }, + "import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "dev": true + }, + "is-ci": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-2.0.0.tgz", + "integrity": "sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==", + "dev": true, + "requires": { + "ci-info": "^2.0.0" + } + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true + }, + "is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, + "js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "requires": { + "argparse": "^2.0.1" + } + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, + "keytar": { + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/keytar/-/keytar-7.9.0.tgz", + "integrity": "sha512-VPD8mtVtm5JNtA2AErl6Chp06JBfy7diFQ7TQQhdpWOl6MrCRB+eRbvAZUsbGQS9kiMq0coJsy0W0vHpDCkWsQ==", + "dev": true, + "requires": { + "node-addon-api": "^4.3.0", + "prebuild-install": "^7.0.1" + } + }, + "leven": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", + "integrity": "sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==", + "dev": true + }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, + "linkify-it": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz", + "integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==", + "dev": true, + "requires": { + "uc.micro": "^1.0.1" + } + }, + "lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "markdown-it": { + "version": "12.3.2", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", + "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", + "dev": true, + "requires": { + "argparse": "^2.0.1", + "entities": "~2.1.0", + "linkify-it": "^3.0.1", + "mdurl": "^1.0.1", + "uc.micro": "^1.0.5" + }, + "dependencies": { + "entities": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", + "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==", + "dev": true + } + } + }, + "mdurl": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", + "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==", + "dev": true + }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, + "micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "dev": true + }, + "mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "dev": true + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==", + "dev": true + }, + "mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "mute-stream": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", + "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", + "dev": true + }, + "napi-build-utils": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", + "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==", + "dev": true + }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true + }, + "node-abi": { + "version": "3.22.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.22.0.tgz", + "integrity": "sha512-u4uAs/4Zzmp/jjsD9cyFYDXeISfUWaAVWshPmDZOFOv4Xl4SbzTXm53I04C2uRueYJ+0t5PEtLH/owbn2Npf/w==", + "dev": true, + "requires": { + "semver": "^7.3.5" + } + }, + "node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==", + "dev": true + }, + "nth-check": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", + "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", + "dev": true, + "requires": { + "boolbase": "^1.0.0" + } + }, + "object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, + "ovsx": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/ovsx/-/ovsx-0.5.1.tgz", + "integrity": "sha512-3OWq0l7DuVHi2bd2aQe5+QVQlFIqvrcw3/2vGXL404L6Tr+R4QHtzfnYYghv8CCa85xJHjU0RhcaC7pyXkAUbg==", + "dev": true, + "requires": { + "commander": "^6.1.0", + "follow-redirects": "^1.14.6", + "is-ci": "^2.0.0", + "leven": "^3.1.0", + "tmp": "^0.2.1", + "vsce": "^2.6.3" + } + }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + } + }, + "parse-semver": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/parse-semver/-/parse-semver-1.1.1.tgz", + "integrity": "sha512-Eg1OuNntBMH0ojvEKSrvDSnwLmvVuUOSdylH/pSCPNMIspLlweJyIWXCE+k/5hm3cj/EBUYwmWkjhBALNP4LXQ==", + "dev": true, + "requires": { + "semver": "^5.1.0" + }, + "dependencies": { + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } + } + }, + "parse5": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.0.0.tgz", + "integrity": "sha512-y/t8IXSPWTuRZqXc0ajH/UwDj4mnqLEbSttNbThcFhGrZuOyoyvNBO85PBp2jQa55wY9d07PBNjsK8ZP3K5U6g==", + "dev": true, + "requires": { + "entities": "^4.3.0" + } + }, + "parse5-htmlparser2-tree-adapter": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-7.0.0.tgz", + "integrity": "sha512-B77tOZrqqfUfnVcOrUvfdLbz4pu4RopLD/4vmu3HUPswwTA8OH0EMW9BlWR2B0RCoiZRAHEUu7IxeP1Pd1UU+g==", + "dev": true, + "requires": { + "domhandler": "^5.0.2", + "parse5": "^7.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "dev": true + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, + "pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", + "dev": true + }, + "picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true + }, + "prebuild-install": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.1.tgz", + "integrity": "sha512-jAXscXWMcCK8GgCoHOfIr0ODh5ai8mj63L2nWrjuAgXE6tDyYGnx4/8o/rCgU+B4JSyZBKbeZqzhtwtC3ovxjw==", + "dev": true, + "requires": { + "detect-libc": "^2.0.0", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp-classic": "^0.5.3", + "napi-build-utils": "^1.0.1", + "node-abi": "^3.3.0", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^4.0.0", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0" + } + }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, + "prettier": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", + "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", + "dev": true + }, + "pump": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", + "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", + "dev": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "requires": { + "side-channel": "^1.0.4" + } + }, + "queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true + }, + "rc": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "dev": true, + "requires": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "dependencies": { + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", + "dev": true + } + } + }, + "read": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz", + "integrity": "sha512-rSOKNYUmaxy0om1BNjMN4ezNT6VKK+2xF4GBhc81mkH7L60i6dp8qPYrkndNLT3QPphoII3maL9PVC9XmhHwVQ==", + "dev": true, + "requires": { + "mute-stream": "~0.0.4" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "regexpp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", + "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", + "dev": true + }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, + "run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "requires": { + "queue-microtask": "^1.2.2" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true + }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "dev": true + }, + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, + "simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", + "dev": true + }, + "simple-get": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", + "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", + "dev": true, + "requires": { + "decompress-response": "^6.0.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, + "slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "dev": true + }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dev": true, + "requires": { + "safe-buffer": "~5.2.0" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.1" + } + }, + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + }, + "tar-fs": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", + "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "dev": true, + "requires": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "tar-stream": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "dev": true, + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + } + }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, + "tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dev": true, + "requires": { + "rimraf": "^3.0.0" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + }, + "tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "dev": true + }, + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + }, + "dependencies": { + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + } + } + }, + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "dev": true + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", + "dev": true, + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1" + } + }, + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true + }, + "typed-rest-client": { + "version": "1.8.9", + "resolved": "https://registry.npmjs.org/typed-rest-client/-/typed-rest-client-1.8.9.tgz", + "integrity": "sha512-uSmjE38B80wjL85UFX3sTYEUlvZ1JgCRhsWj/fJ4rZ0FqDUFoIuodtiVeE+cUqiVTOKPdKrp/sdftD15MDek6g==", + "dev": true, + "requires": { + "qs": "^6.9.1", + "tunnel": "0.0.6", + "underscore": "^1.12.1" + } + }, + "typescript": { + "version": "4.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", + "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", + "dev": true + }, + "uc.micro": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", + "dev": true + }, + "underscore": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.4.tgz", + "integrity": "sha512-BQFnUDuAQ4Yf/cYY5LNrK9NCJFKriaRbD9uR1fTeXnBeoa97W0i41qkZfGO9pSo8I5KzjAcSY2XYtdf0oKd7KQ==", + "dev": true + }, + "uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "requires": { + "punycode": "^2.1.0" + } + }, + "url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==", + "dev": true + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true + }, + "v8-compile-cache": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", + "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", + "dev": true + }, + "vsce": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/vsce/-/vsce-2.9.2.tgz", + "integrity": "sha512-xyLqL4U82BilUX1t6Ym2opQEa2tLGWYjbgB7+ETeNVXlIJz5sWBJjQJSYJVFOKJSpiOtQclolu88cj7oY6vvPQ==", + "dev": true, + "requires": { + "azure-devops-node-api": "^11.0.1", + "chalk": "^2.4.2", + "cheerio": "^1.0.0-rc.9", + "commander": "^6.1.0", + "glob": "^7.0.6", + "hosted-git-info": "^4.0.2", + "keytar": "^7.7.0", + "leven": "^3.1.0", + "markdown-it": "^12.3.2", + "mime": "^1.3.4", + "minimatch": "^3.0.3", + "parse-semver": "^1.1.1", + "read": "^1.0.7", + "semver": "^5.1.0", + "tmp": "^0.2.1", + "typed-rest-client": "^1.8.4", + "url-join": "^4.0.1", + "xml2js": "^0.4.23", + "yauzl": "^2.3.1", + "yazl": "^2.2.2" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true + }, + "xml2js": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", + "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", + "dev": true, + "requires": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + } + }, + "xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "dev": true + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", + "dev": true, + "requires": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } + }, + "yazl": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/yazl/-/yazl-2.5.1.tgz", + "integrity": "sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==", + "dev": true, + "requires": { + "buffer-crc32": "~0.2.3" + } + } + } +} diff --git a/packages/cli/extension/package.json b/packages/cli/extension/package.json new file mode 100644 index 000000000..11b32ec88 --- /dev/null +++ b/packages/cli/extension/package.json @@ -0,0 +1,102 @@ +{ + "name": "dioxus", + "displayName": "Dioxus", + "description": "Useful tools for working with Dioxus", + "version": "0.0.1", + "publisher": "DioxusLabs", + "private": true, + "license": "MIT", + "icon": "static/icon.png", + "repository": { + "type": "git", + "url": "https://github.com/DioxusLabs/cli" + }, + "engines": { + "vscode": "^1.68.1" + }, + "categories": [ + "Programming Languages" + ], + "activationEvents": [ + "onCommand:extension.htmlToDioxusRsx", + "onCommand:extension.htmlToDioxusComponent", + "onCommand:extension.formatRsx", + "onCommand:extension.formatRsxDocument" + ], + "main": "./out/main", + "contributes": { + "commands": [ + { + "command": "extension.htmlToDioxusRsx", + "title": "Dioxus: Convert HTML to RSX" + }, + { + "command": "extension.htmlToDioxusComponent", + "title": "Dioxus: Convert HTML to Component" + }, + { + "command": "extension.formatRsx", + "title": "Dioxus: Format RSX" + }, + { + "command": "extension.formatRsxDocument", + "title": "Dioxus: Format RSX Document" + } + ], + "configuration": { + "properties": { + "dioxus.formatOnSave": { + "type": [ + "string" + ], + "default": "followFormatOnSave", + "enum": [ + "followFormatOnSave", + "enabled", + "disabled" + ], + "enumItemLabels": [ + "Follow the normal formatOnSave config", + "Enabled", + "Disabled" + ], + "enumDescriptions": [ + "Only format Rsx when saving files if the editor.formatOnSave config is enabled", + "Always format Rsx when a Rust file is saved", + "Never format Rsx when a file is saved" + ], + "description": "Format RSX when a file is saved." + } + } + } + }, + "scripts": { + "vscode:prepublish": "npm run build-base -- --minify", + "package": "vsce package -o rust-analyzer.vsix", + "build-base": "esbuild ./src/main.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --target=node16", + "build": "npm run build-base -- --sourcemap", + "watch": "npm run build-base -- --sourcemap --watch", + "lint": "prettier --check . && eslint -c .eslintrc.js --ext ts ./src ./tests", + "fix": "prettier --write . && eslint -c .eslintrc.js --ext ts ./src ./tests --fix", + "pretest": "tsc && npm run build", + "test": "cross-env TEST_VARIABLE=test node ./out/tests/runTests.js" + }, + "devDependencies": { + "@types/node": "^18.0.2", + "@types/vscode": "^1.68.1", + "@typescript-eslint/eslint-plugin": "^5.30.5", + "@typescript-eslint/parser": "^5.30.5", + "cross-env": "^7.0.3", + "esbuild": "^0.14.27", + "eslint": "^8.19.0", + "typescript": "^4.7.4", + "eslint-config-prettier": "^8.5.0", + "ovsx": "^0.5.1", + "prettier": "^2.6.2", + "tslib": "^2.3.0", + "vsce": "^2.7.0" + }, + "dependencies": { + "vsce": "^2.9.2" + } +} \ No newline at end of file diff --git a/packages/cli/extension/server/.gitignore b/packages/cli/extension/server/.gitignore new file mode 100644 index 000000000..f42761bea --- /dev/null +++ b/packages/cli/extension/server/.gitignore @@ -0,0 +1,3 @@ +** +!Readme.md +!.gitignore diff --git a/packages/cli/extension/src/main.ts b/packages/cli/extension/src/main.ts new file mode 100644 index 000000000..adaed0a7d --- /dev/null +++ b/packages/cli/extension/src/main.ts @@ -0,0 +1,282 @@ +import * as vscode from 'vscode'; +import { spawn } from "child_process"; +import { TextEncoder } from 'util'; + +let serverPath: string = "dioxus"; + +export async function activate(context: vscode.ExtensionContext) { + let somePath = await bootstrap(context); + + if (somePath == undefined) { + await vscode.window.showErrorMessage('Could not find bundled Dioxus-CLI. Please install it manually.'); + return; + } else { + serverPath = somePath; + } + + context.subscriptions.push( + // vscode.commands.registerTextEditorCommand('editor.action.clipboardPasteAction', onPasteHandler), + vscode.commands.registerCommand('extension.htmlToDioxusRsx', translateBlock), + vscode.commands.registerCommand('extension.htmlToDioxusComponent', translateComponent), + vscode.commands.registerCommand('extension.formatRsx', fmtSelection), + vscode.commands.registerCommand('extension.formatRsxDocument', formatRsxDocument), + vscode.workspace.onWillSaveTextDocument(fmtDocumentOnSave) + ); +} + + +function translateComponent() { + translate(true) +} + +function translateBlock() { + translate(false) +} + +function translate(component: boolean) { + const editor = vscode.window.activeTextEditor; + + if (!editor) return; + + const html = editor.document.getText(editor.selection); + if (html.length == 0) { + vscode.window.showWarningMessage("Please select HTML fragment before invoking this command!"); + return; + } + + let params = ["translate"]; + if (component) params.push("--component"); + params.push("--raw", html); + + const child_proc = spawn(serverPath, params); + + let result = ''; + child_proc.stdout?.on('data', data => result += data); + + child_proc.on('close', () => { + if (result.length > 0) editor.edit(editBuilder => editBuilder.replace(editor.selection, result)); + }); + + child_proc.on('error', (err) => { + vscode.window.showWarningMessage(`Errors occurred while translating. Make sure you have the most recent Dioxus-CLI installed! \n${err}`); + }); +} + +function onPasteHandler() { + // check settings to see if we should convert HTML to Rsx + if (vscode.workspace.getConfiguration('dioxus').get('convertOnPaste')) { + convertHtmlToRsxOnPaste(); + } +} + +function convertHtmlToRsxOnPaste() { + const editor = vscode.window.activeTextEditor; + if (!editor) return; + + // get the cursor location + const cursor = editor.selection.active; + + // try to parse the HTML at the cursor location + const html = editor.document.getText(new vscode.Range(cursor, cursor)); +} + +function formatRsxDocument() { + const editor = vscode.window.activeTextEditor; + if (!editor) return; + fmtDocument(editor.document); +} + +function fmtSelection() { + const editor = vscode.window.activeTextEditor; + if (!editor) return; + + const unformatted = editor.document.getText(editor.selection); + + if (unformatted.length == 0) { + vscode.window.showWarningMessage("Please select rsx invoking this command!"); + return; + } + + const fileDir = editor.document.fileName.slice(0, editor.document.fileName.lastIndexOf('\\')); + + const child_proc = spawn(serverPath, ["fmt", "--raw", unformatted.toString()], { + cwd: fileDir ? fileDir : undefined, + }); + let result = ''; + + child_proc.stdout?.on('data', data => result += data); + + child_proc.on('close', () => { + if (result.length > 0) editor.edit(editBuilder => editBuilder.replace(editor.selection, result)); + }); + + child_proc.on('error', (err) => { + vscode.window.showWarningMessage(`Errors occurred while translating. Make sure you have the most recent Dioxus-CLI installed! \n${err}`); + }); +} + +function fmtDocumentOnSave(e: vscode.TextDocumentWillSaveEvent) { + // check the settings to make sure format on save is configured + const dioxusConfig = vscode.workspace.getConfiguration('dioxus', e.document).get('formatOnSave'); + const globalConfig = vscode.workspace.getConfiguration('editor', e.document).get('formatOnSave'); + if ( + (dioxusConfig === 'enabled') || + (dioxusConfig !== 'disabled' && globalConfig) + ) { + fmtDocument(e.document); + } +} + +function fmtDocument(document: vscode.TextDocument) { + try { + if (document.languageId !== "rust" || document.uri.scheme !== "file") { + return; + } + + const [editor,] = vscode.window.visibleTextEditors.filter(editor => editor.document.fileName === document.fileName); + if (!editor) return; // Need an editor to apply text edits. + + const fileDir = document.fileName.slice(0, document.fileName.lastIndexOf('\\')); + const child_proc = spawn(serverPath, ["fmt", "--file", document.fileName], { + cwd: fileDir ? fileDir : undefined, + }); + + let result = ''; + child_proc.stdout?.on('data', data => result += data); + + /*type RsxEdit = { + formatted: string, + start: number, + end: number + }*/ + + child_proc.on('close', () => { + if (child_proc.exitCode !== 0) { + vscode.window.showWarningMessage(`Errors occurred while formatting. Make sure you have the most recent Dioxus-CLI installed!\nDioxus-CLI exited with exit code ${child_proc.exitCode}\n\nData from Dioxus-CLI:\n${result}`); + return; + } + /*if (result.length === 0) return; + + // Used for error message: + const originalResult = result; + try { + // Only parse the last non empty line, to skip log warning messages: + const lines = result.replaceAll('\r\n', '\n').split('\n'); + const nonEmptyLines = lines.filter(line => line.trim().length !== 0); + result = nonEmptyLines[nonEmptyLines.length - 1] ?? ''; + + if (result.length === 0) return; + + const decoded: RsxEdit[] = JSON.parse(result); + if (decoded.length === 0) return; + + // Preform edits at the end of the file + // first (to not change previous text file + // offsets): + decoded.sort((a, b) => b.start - a.start); + + + // Convert from utf8 offsets to utf16 offsets used by VS Code: + + const utf8Text = new TextEncoder().encode(text); + const utf8ToUtf16Pos = (posUtf8: number) => { + // Find the line of the position as well as the utf8 and + // utf16 indexes for the start of that line: + let startOfLineUtf8 = 0; + let lineIndex = 0; + const newLineUtf8 = '\n'.charCodeAt(0); + // eslint-disable-next-line no-constant-condition + while (true) { + const nextLineAt = utf8Text.indexOf(newLineUtf8, startOfLineUtf8); + if (nextLineAt < 0 || posUtf8 <= nextLineAt) break; + startOfLineUtf8 = nextLineAt + 1; + lineIndex++; + } + const lineUtf16 = document.lineAt(lineIndex); + + // Move forward from a synced position in the text until the + // target pos is found: + let currentUtf8 = startOfLineUtf8; + let currentUtf16 = document.offsetAt(lineUtf16.range.start); + + const decodeBuffer = new Uint8Array(10); + const utf8Encoder = new TextEncoder(); + while (currentUtf8 < posUtf8) { + const { written } = utf8Encoder.encodeInto(text.charAt(currentUtf16), decodeBuffer); + currentUtf8 += written; + currentUtf16++; + } + return currentUtf16; + }; + + + type FixedEdit = { + range: vscode.Range, + formatted: string, + }; + + const edits: FixedEdit[] = []; + for (const edit of decoded) { + // Convert from utf8 to utf16: + const range = new vscode.Range( + document.positionAt(utf8ToUtf16Pos(edit.start)), + document.positionAt(utf8ToUtf16Pos(edit.end)) + ); + + if (editor.document.getText(range) !== document.getText(range)) { + // The text that was formatted has changed while we were working. + vscode.window.showWarningMessage(`Dioxus formatting was ignored since the source file changed before the change could be applied.`); + continue; + } + + edits.push({ + range, + formatted: edit.formatted, + }); + } + + + // Apply edits: + editor.edit(editBuilder => { + edits.forEach((edit) => editBuilder.replace(edit.range, edit.formatted)); + }, { + undoStopAfter: false, + undoStopBefore: false + }); + + } catch (err) { + vscode.window.showWarningMessage(`Errors occurred while formatting. Make sure you have the most recent Dioxus-CLI installed!\n${err}\n\nData from Dioxus-CLI:\n${originalResult}`); + }*/ + }); + + child_proc.on('error', (err) => { + vscode.window.showWarningMessage(`Errors occurred while formatting. Make sure you have the most recent Dioxus-CLI installed! \n${err}`); + }); + } catch (error) { + vscode.window.showWarningMessage(`Errors occurred while formatting. Make sure you have the most recent Dioxus-CLI installed! \n${error}`); + } +} + + + +// I'm using the approach defined in rust-analyzer here +// +// We ship the server as part of the extension, but we need to handle external paths and such +// +// https://github.com/rust-lang/rust-analyzer/blob/fee5555cfabed4b8abbd40983fc4442df4007e49/editors/code/src/main.ts#L270 +async function bootstrap(context: vscode.ExtensionContext): Promise { + + const ext = process.platform === "win32" ? ".exe" : ""; + const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `dioxus${ext}`); + const bundledExists = await vscode.workspace.fs.stat(bundled).then( + () => true, + () => false + ); + + // if bunddled doesn't exist, try using a locally-installed version + if (!bundledExists) { + return "dioxus"; + } + + return bundled.fsPath; +} diff --git a/packages/cli/extension/static/icon.png b/packages/cli/extension/static/icon.png new file mode 100644 index 000000000..42c355c26 Binary files /dev/null and b/packages/cli/extension/static/icon.png differ diff --git a/packages/cli/extension/tsconfig.json b/packages/cli/extension/tsconfig.json new file mode 100644 index 000000000..32dda5bc9 --- /dev/null +++ b/packages/cli/extension/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es2021", + "lib": ["ES2021"], + "outDir": "out", + "sourceMap": true, + "strict": true, + "rootDir": "src" + }, + "exclude": ["node_modules", ".vscode-test"] +} diff --git a/packages/cli/src/assets/autoreload.js b/packages/cli/src/assets/autoreload.js new file mode 100644 index 000000000..fffb3e26c --- /dev/null +++ b/packages/cli/src/assets/autoreload.js @@ -0,0 +1,25 @@ +// Dioxus-CLI +// https://github.com/DioxusLabs/cli + +(function () { + var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + var url = protocol + '//' + window.location.host + '/_dioxus/ws'; + var poll_interval = 8080; + var reload_upon_connect = () => { + window.setTimeout( + () => { + var ws = new WebSocket(url); + ws.onopen = () => window.location.reload(); + ws.onclose = reload_upon_connect; + }, + poll_interval); + }; + + var ws = new WebSocket(url); + ws.onmessage = (ev) => { + if (ev.data == "reload") { + window.location.reload(); + } + }; + ws.onclose = reload_upon_connect; +})() \ No newline at end of file diff --git a/packages/cli/src/assets/dioxus.toml b/packages/cli/src/assets/dioxus.toml new file mode 100644 index 000000000..3827d0f8f --- /dev/null +++ b/packages/cli/src/assets/dioxus.toml @@ -0,0 +1,47 @@ +[application] + +# dioxus project name +name = "{{project-name}}" + +# default platfrom +# you can also use `dioxus serve/build --platform XXX` to use other platform +# value: web | desktop +default_platform = "{{default-platform}}" + +# Web `build` & `serve` dist path +out_dir = "dist" + +# resource (static) file folder +asset_dir = "public" + +[web.app] + +# HTML title tag content +title = "Dioxus | An elegant GUI library for Rust" + +[web.watcher] + +index_on_404 = true + +watch_path = ["src"] + +# include `assets` in web platform +[web.resource] + +# CSS style file +style = [] + +# Javascript code file +script = [] + +[web.resource.dev] + +# Javascript code file +# serve: [dev-server] only +script = [] + +[application.plugins] + +available = true + +required = [] diff --git a/packages/cli/src/assets/index.html b/packages/cli/src/assets/index.html new file mode 100644 index 000000000..ed3d48135 --- /dev/null +++ b/packages/cli/src/assets/index.html @@ -0,0 +1,22 @@ + + + + {app_title} + + + + {style_include} + + +
+ + {script_include} + + \ No newline at end of file diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs new file mode 100644 index 000000000..6f50fc49d --- /dev/null +++ b/packages/cli/src/builder.rs @@ -0,0 +1,725 @@ +use crate::{ + config::{CrateConfig, ExecutableType}, + error::{Error, Result}, + tools::Tool, + DioxusConfig, +}; +use cargo_metadata::{diagnostic::Diagnostic, Message}; +use indicatif::{ProgressBar, ProgressStyle}; +use serde::Serialize; +use std::{ + fs::{copy, create_dir_all, File}, + io::Read, + panic, + path::PathBuf, + process::Command, + time::Duration, +}; +use wasm_bindgen_cli_support::Bindgen; + +#[derive(Serialize, Debug, Clone)] +pub struct BuildResult { + pub warnings: Vec, + pub elapsed_time: u128, +} + +pub fn build(config: &CrateConfig, quiet: bool) -> Result { + // [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?) + // [2] Generate the appropriate build folders + // [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm + // [4] Wasm-opt the .wasm file with whatever optimizations need to be done + // [5][OPTIONAL] Builds the Tailwind CSS file using the Tailwind standalone binary + // [6] Link up the html page to the wasm module + + let CrateConfig { + out_dir, + crate_dir, + target_dir, + asset_dir, + executable, + dioxus_config, + .. + } = config; + + // start to build the assets + let ignore_files = build_assets(config)?; + + let t_start = std::time::Instant::now(); + + // [1] Build the .wasm module + log::info!("🚅 Running build command..."); + let cmd = subprocess::Exec::cmd("cargo"); + let cmd = cmd + .cwd(crate_dir) + .arg("build") + .arg("--target") + .arg("wasm32-unknown-unknown") + .arg("--message-format=json"); + + let cmd = if config.release { + cmd.arg("--release") + } else { + cmd + }; + let cmd = if config.verbose { + cmd.arg("--verbose") + } else { + cmd + }; + + let cmd = if quiet { cmd.arg("--quiet") } else { cmd }; + + let cmd = if config.custom_profile.is_some() { + let custom_profile = config.custom_profile.as_ref().unwrap(); + cmd.arg("--profile").arg(custom_profile) + } else { + cmd + }; + + let cmd = if config.features.is_some() { + let features_str = config.features.as_ref().unwrap().join(" "); + cmd.arg("--features").arg(features_str) + } else { + cmd + }; + + let cmd = match executable { + ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), + ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), + ExecutableType::Example(name) => cmd.arg("--example").arg(name), + }; + + let warning_messages = prettier_build(cmd)?; + + // [2] Establish the output directory structure + let bindgen_outdir = out_dir.join("assets").join("dioxus"); + + let release_type = match config.release { + true => "release", + false => "debug", + }; + + let input_path = match executable { + ExecutableType::Binary(name) | ExecutableType::Lib(name) => target_dir + .join(format!("wasm32-unknown-unknown/{}", release_type)) + .join(format!("{}.wasm", name)), + + ExecutableType::Example(name) => target_dir + .join(format!("wasm32-unknown-unknown/{}/examples", release_type)) + .join(format!("{}.wasm", name)), + }; + + let bindgen_result = panic::catch_unwind(move || { + // [3] Bindgen the final binary for use easy linking + let mut bindgen_builder = Bindgen::new(); + + bindgen_builder + .input_path(input_path) + .web(true) + .unwrap() + .debug(true) + .demangle(true) + .keep_debug(true) + .remove_name_section(false) + .remove_producers_section(false) + .out_name(&dioxus_config.application.name) + .generate(&bindgen_outdir) + .unwrap(); + }); + if bindgen_result.is_err() { + return Err(Error::BuildFailed("Bindgen build failed! \nThis is probably due to the Bindgen version, dioxus-cli using `0.2.81` Bindgen crate.".to_string())); + } + + // check binaryen:wasm-opt tool + let dioxus_tools = dioxus_config.application.tools.clone().unwrap_or_default(); + if dioxus_tools.contains_key("binaryen") { + let info = dioxus_tools.get("binaryen").unwrap(); + let binaryen = crate::tools::Tool::Binaryen; + + if binaryen.is_installed() { + if let Some(sub) = info.as_table() { + if sub.contains_key("wasm_opt") + && sub.get("wasm_opt").unwrap().as_bool().unwrap_or(false) + { + log::info!("Optimizing WASM size with wasm-opt..."); + let target_file = out_dir + .join("assets") + .join("dioxus") + .join(format!("{}_bg.wasm", dioxus_config.application.name)); + if target_file.is_file() { + let mut args = vec![ + target_file.to_str().unwrap(), + "-o", + target_file.to_str().unwrap(), + ]; + if config.release { + args.push("-Oz"); + } + binaryen.call("wasm-opt", args)?; + } + } + } + } else { + log::warn!( + "Binaryen tool not found, you can use `dioxus tool add binaryen` to install it." + ); + } + } + + // [5][OPTIONAL] If tailwind is enabled and installed we run it to generate the CSS + if dioxus_tools.contains_key("tailwindcss") { + let info = dioxus_tools.get("tailwindcss").unwrap(); + let tailwind = crate::tools::Tool::Tailwind; + + if tailwind.is_installed() { + if let Some(sub) = info.as_table() { + log::info!("Building Tailwind bundle CSS file..."); + + let input_path = match sub.get("input") { + Some(val) => val.as_str().unwrap(), + None => "./public", + }; + let config_path = match sub.get("config") { + Some(val) => val.as_str().unwrap(), + None => "./src/tailwind.config.js", + }; + let mut args = vec![ + "-i", + input_path, + "-o", + "dist/tailwind.css", + "-c", + config_path, + ]; + + if config.release { + args.push("--minify"); + } + + tailwind.call("tailwindcss", args)?; + } + } else { + log::warn!( + "Tailwind tool not found, you can use `dioxus tool add tailwindcss` to install it." + ); + } + } + + // this code will copy all public file to the output dir + let copy_options = fs_extra::dir::CopyOptions { + overwrite: true, + skip_exist: false, + buffer_size: 64000, + copy_inside: false, + content_only: false, + depth: 0, + }; + if asset_dir.is_dir() { + for entry in std::fs::read_dir(asset_dir)? { + let path = entry?.path(); + if path.is_file() { + std::fs::copy(&path, out_dir.join(path.file_name().unwrap()))?; + } else { + match fs_extra::dir::copy(&path, out_dir, ©_options) { + Ok(_) => {} + Err(_e) => { + log::warn!("Error copying dir: {}", _e); + } + } + for ignore in &ignore_files { + let ignore = ignore.strip_prefix(&config.asset_dir).unwrap(); + let ignore = config.out_dir.join(ignore); + if ignore.is_file() { + std::fs::remove_file(ignore)?; + } + } + } + } + } + + let t_end = std::time::Instant::now(); + Ok(BuildResult { + warnings: warning_messages, + elapsed_time: (t_end - t_start).as_millis(), + }) +} + +pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<()> { + log::info!("🚅 Running build [Desktop] command..."); + + let ignore_files = build_assets(config)?; + + let mut cmd = Command::new("cargo"); + cmd.current_dir(&config.crate_dir) + .arg("build") + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()); + + if config.release { + cmd.arg("--release"); + } + if config.verbose { + cmd.arg("--verbose"); + } + + if config.custom_profile.is_some() { + let custom_profile = config.custom_profile.as_ref().unwrap(); + cmd.arg("--profile"); + cmd.arg(custom_profile); + } + + if config.features.is_some() { + let features_str = config.features.as_ref().unwrap().join(" "); + cmd.arg("--features"); + cmd.arg(features_str); + } + + match &config.executable { + crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), + crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), + crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name), + }; + + let output = cmd.output()?; + + if !output.status.success() { + return Err(Error::BuildFailed("Program build failed.".into())); + } + + if output.status.success() { + let release_type = match config.release { + true => "release", + false => "debug", + }; + + let file_name: String; + let mut res_path = match &config.executable { + crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => { + file_name = name.clone(); + config.target_dir.join(release_type).join(name) + } + crate::ExecutableType::Example(name) => { + file_name = name.clone(); + config + .target_dir + .join(release_type) + .join("examples") + .join(name) + } + }; + + let target_file = if cfg!(windows) { + res_path.set_extension("exe"); + format!("{}.exe", &file_name) + } else { + file_name + }; + + if !config.out_dir.is_dir() { + create_dir_all(&config.out_dir)?; + } + copy(res_path, &config.out_dir.join(target_file))?; + + // this code will copy all public file to the output dir + if config.asset_dir.is_dir() { + let copy_options = fs_extra::dir::CopyOptions { + overwrite: true, + skip_exist: false, + buffer_size: 64000, + copy_inside: false, + content_only: false, + depth: 0, + }; + + for entry in std::fs::read_dir(&config.asset_dir)? { + let path = entry?.path(); + if path.is_file() { + std::fs::copy(&path, &config.out_dir.join(path.file_name().unwrap()))?; + } else { + match fs_extra::dir::copy(&path, &config.out_dir, ©_options) { + Ok(_) => {} + Err(e) => { + log::warn!("Error copying dir: {}", e); + } + } + for ignore in &ignore_files { + let ignore = ignore.strip_prefix(&config.asset_dir).unwrap(); + let ignore = config.out_dir.join(ignore); + if ignore.is_file() { + std::fs::remove_file(ignore)?; + } + } + } + } + } + + log::info!( + "🚩 Build completed: [./{}]", + config + .dioxus_config + .application + .out_dir + .clone() + .unwrap_or_else(|| PathBuf::from("dist")) + .display() + ); + } + + Ok(()) +} + +fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { + let mut warning_messages: Vec = vec![]; + + let pb = ProgressBar::new_spinner(); + pb.enable_steady_tick(Duration::from_millis(200)); + pb.set_style( + ProgressStyle::with_template("{spinner:.dim.bold} {wide_msg}") + .unwrap() + .tick_chars("/|\\- "), + ); + pb.set_message("💼 Waiting to start build the project..."); + + struct StopSpinOnDrop(ProgressBar); + + impl Drop for StopSpinOnDrop { + fn drop(&mut self) { + self.0.finish_and_clear(); + } + } + + StopSpinOnDrop(pb.clone()); + + let stdout = cmd.detached().stream_stdout()?; + let reader = std::io::BufReader::new(stdout); + for message in cargo_metadata::Message::parse_stream(reader) { + match message.unwrap() { + Message::CompilerMessage(msg) => { + let message = msg.message; + match message.level { + cargo_metadata::diagnostic::DiagnosticLevel::Error => { + return { + Err(anyhow::anyhow!(message + .rendered + .unwrap_or("Unknown".into()))) + }; + } + cargo_metadata::diagnostic::DiagnosticLevel::Warning => { + warning_messages.push(message.clone()); + } + _ => {} + } + } + Message::CompilerArtifact(artifact) => { + pb.set_message(format!("Compiling {} ", artifact.package_id)); + pb.tick(); + } + Message::BuildScriptExecuted(script) => { + let _package_id = script.package_id.to_string(); + } + Message::BuildFinished(finished) => { + if finished.success { + log::info!("👑 Build done."); + } else { + std::process::exit(1); + } + } + _ => (), // Unknown message + } + } + Ok(warning_messages) +} + +pub fn gen_page(config: &DioxusConfig, serve: bool) -> String { + let crate_root = crate::cargo::crate_root().unwrap(); + let custom_html_file = crate_root.join("index.html"); + let mut html = if custom_html_file.is_file() { + let mut buf = String::new(); + let mut file = File::open(custom_html_file).unwrap(); + if file.read_to_string(&mut buf).is_ok() { + buf + } else { + String::from(include_str!("./assets/index.html")) + } + } else { + String::from(include_str!("./assets/index.html")) + }; + + let resouces = config.web.resource.clone(); + + let mut style_list = resouces.style.unwrap_or_default(); + let mut script_list = resouces.script.unwrap_or_default(); + + if serve { + let mut dev_style = resouces.dev.style.clone().unwrap_or_default(); + let mut dev_script = resouces.dev.script.unwrap_or_default(); + style_list.append(&mut dev_style); + script_list.append(&mut dev_script); + } + + let mut style_str = String::new(); + for style in style_list { + style_str.push_str(&format!( + "\n", + &style.to_str().unwrap(), + )) + } + if config + .application + .tools + .clone() + .unwrap_or_default() + .contains_key("tailwindcss") + { + style_str.push_str("\n"); + } + + replace_or_insert_before("{style_include}", &style_str, "\n", + &script.to_str().unwrap(), + )) + } + + replace_or_insert_before("{script_include}", &script_str, "{}", + include_str!("./assets/autoreload.js") + ); + } + + let base_path = match &config.web.app.base_path { + Some(path) => path, + None => ".", + }; + let app_name = &config.application.name; + // Check if a script already exists + if html.contains("{app_name}") && html.contains("{base_path}") { + html = html.replace("{app_name}", app_name); + + html = html.replace("{base_path}", base_path); + } else { + // If not, insert the script + html = html.replace( + " + import init from "/{base_path}/assets/dioxus/{app_name}.js"; + init("/{base_path}/assets/dioxus/{app_name}_bg.wasm").then(wasm => {{ + if (wasm.__wbindgen_start == undefined) {{ + wasm.main(); + }} + }}); + + Result> { + let mut result = vec![]; + + let dioxus_config = &config.dioxus_config; + let dioxus_tools = dioxus_config.application.tools.clone().unwrap_or_default(); + + // check sass tool state + let sass = Tool::Sass; + if sass.is_installed() && dioxus_tools.contains_key("sass") { + let sass_conf = dioxus_tools.get("sass").unwrap(); + if let Some(tab) = sass_conf.as_table() { + let source_map = tab.contains_key("source_map"); + let source_map = if source_map && tab.get("source_map").unwrap().is_bool() { + if tab.get("source_map").unwrap().as_bool().unwrap_or_default() { + "--source-map" + } else { + "--no-source-map" + } + } else { + "--source-map" + }; + + if tab.contains_key("input") { + if tab.get("input").unwrap().is_str() { + let file = tab.get("input").unwrap().as_str().unwrap().trim(); + + if file == "*" { + // if the sass open auto, we need auto-check the assets dir. + let asset_dir = config.asset_dir.clone(); + if asset_dir.is_dir() { + for entry in walkdir::WalkDir::new(&asset_dir) + .into_iter() + .filter_map(|e| e.ok()) + { + let temp = entry.path(); + if temp.is_file() { + let suffix = temp.extension(); + if suffix.is_none() { + continue; + } + let suffix = suffix.unwrap().to_str().unwrap(); + if suffix == "scss" || suffix == "sass" { + // if file suffix is `scss` / `sass` we need transform it. + let out_file = format!( + "{}.css", + temp.file_stem().unwrap().to_str().unwrap() + ); + let target_path = config + .out_dir + .join( + temp.strip_prefix(&asset_dir) + .unwrap() + .parent() + .unwrap(), + ) + .join(out_file); + let res = sass.call( + "sass", + vec![ + temp.to_str().unwrap(), + target_path.to_str().unwrap(), + source_map, + ], + ); + if res.is_ok() { + result.push(temp.to_path_buf()); + } + } + } + } + } + } else { + // just transform one file. + let relative_path = if &file[0..1] == "/" { + &file[1..file.len()] + } else { + file + }; + let path = config.asset_dir.join(relative_path); + let out_file = + format!("{}.css", path.file_stem().unwrap().to_str().unwrap()); + let target_path = config + .out_dir + .join(PathBuf::from(relative_path).parent().unwrap()) + .join(out_file); + if path.is_file() { + let res = sass.call( + "sass", + vec![ + path.to_str().unwrap(), + target_path.to_str().unwrap(), + source_map, + ], + ); + if res.is_ok() { + result.push(path); + } else { + log::error!("{:?}", res); + } + } + } + } else if tab.get("input").unwrap().is_array() { + // check files list. + let list = tab.get("input").unwrap().as_array().unwrap(); + for i in list { + if i.is_str() { + let path = i.as_str().unwrap(); + let relative_path = if &path[0..1] == "/" { + &path[1..path.len()] + } else { + path + }; + let path = config.asset_dir.join(relative_path); + let out_file = + format!("{}.css", path.file_stem().unwrap().to_str().unwrap()); + let target_path = config + .out_dir + .join(PathBuf::from(relative_path).parent().unwrap()) + .join(out_file); + if path.is_file() { + let res = sass.call( + "sass", + vec![ + path.to_str().unwrap(), + target_path.to_str().unwrap(), + source_map, + ], + ); + if res.is_ok() { + result.push(path); + } + } + } + } + } + } + } + } + // SASS END + + Ok(result) +} + +// use binary_install::{Cache, Download}; + +// /// Attempts to find `wasm-opt` in `PATH` locally, or failing that downloads a +// /// precompiled binary. +// /// +// /// Returns `Some` if a binary was found or it was successfully downloaded. +// /// Returns `None` if a binary wasn't found in `PATH` and this platform doesn't +// /// have precompiled binaries. Returns an error if we failed to download the +// /// binary. +// pub fn find_wasm_opt( +// cache: &Cache, +// install_permitted: bool, +// ) -> Result { +// // First attempt to look up in PATH. If found assume it works. +// if let Ok(path) = which::which("wasm-opt") { +// PBAR.info(&format!("found wasm-opt at {:?}", path)); + +// match path.as_path().parent() { +// Some(path) => return Ok(install::Status::Found(Download::at(path))), +// None => {} +// } +// } + +// let version = "version_78"; +// Ok(install::download_prebuilt( +// &install::Tool::WasmOpt, +// cache, +// version, +// install_permitted, +// )?) +// } diff --git a/packages/cli/src/cargo.rs b/packages/cli/src/cargo.rs new file mode 100644 index 000000000..b52fa4b09 --- /dev/null +++ b/packages/cli/src/cargo.rs @@ -0,0 +1,94 @@ +//! Utilities for working with cargo and rust files +use crate::error::{Error, Result}; +use std::{ + env, fs, + path::{Path, PathBuf}, + process::Command, + str, +}; + +/// How many parent folders are searched for a `Cargo.toml` +const MAX_ANCESTORS: u32 = 10; + +/// Some fields parsed from `cargo metadata` command +pub struct Metadata { + pub workspace_root: PathBuf, + pub target_directory: PathBuf, +} + +/// Returns the root of the crate that the command is run from +/// +/// If the command is run from the workspace root, this will return the top-level Cargo.toml +pub fn crate_root() -> Result { + // From the current directory we work our way up, looking for `Cargo.toml` + env::current_dir() + .ok() + .and_then(|mut wd| { + for _ in 0..MAX_ANCESTORS { + if contains_manifest(&wd) { + return Some(wd); + } + if !wd.pop() { + break; + } + } + None + }) + .ok_or_else(|| { + Error::CargoError("Failed to find directory containing Cargo.toml".to_string()) + }) +} + +/// Checks if the directory contains `Cargo.toml` +fn contains_manifest(path: &Path) -> bool { + fs::read_dir(path) + .map(|entries| { + entries + .filter_map(Result::ok) + .any(|ent| &ent.file_name() == "Cargo.toml") + }) + .unwrap_or(false) +} + +impl Metadata { + /// Returns the struct filled from `cargo metadata` output + /// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow) + pub fn get() -> Result { + let output = Command::new("cargo") + .args(["metadata"]) + .output() + .map_err(|_| Error::CargoError("Manifset".to_string()))?; + + if !output.status.success() { + let mut msg = str::from_utf8(&output.stderr).unwrap().trim(); + if msg.starts_with("error: ") { + msg = &msg[7..]; + } + + return Err(Error::CargoError(msg.to_string())); + } + + let stdout = str::from_utf8(&output.stdout).unwrap(); + if let Some(line) = stdout.lines().next() { + let meta: serde_json::Value = serde_json::from_str(line) + .map_err(|_| Error::CargoError("InvalidOutput".to_string()))?; + + let workspace_root = meta["workspace_root"] + .as_str() + .ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))? + .into(); + + let target_directory = meta["target_directory"] + .as_str() + .ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))? + .into(); + + return Ok(Self { + workspace_root, + target_directory, + }); + } + + Err(Error::CargoError("InvalidOutput".to_string())) + } +} diff --git a/packages/cli/src/cli/autoformat/mod.rs b/packages/cli/src/cli/autoformat/mod.rs new file mode 100644 index 000000000..257e237f2 --- /dev/null +++ b/packages/cli/src/cli/autoformat/mod.rs @@ -0,0 +1,210 @@ +use futures::{stream::FuturesUnordered, StreamExt}; +use std::{fs, path::Path, process::exit}; + +use super::*; + +// For reference, the rustfmt main.rs file +// https://github.com/rust-lang/rustfmt/blob/master/src/bin/main.rs + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Parser)] +pub struct Autoformat { + /// Run in 'check' mode. Exits with 0 if input is formatted correctly. Exits + /// with 1 and prints a diff if formatting is required. + #[clap(short, long)] + pub check: bool, + + /// Input rsx (selection) + #[clap(short, long)] + pub raw: Option, + + /// Input file + #[clap(short, long)] + pub file: Option, +} + +impl Autoformat { + // Todo: autoformat the entire crate + pub async fn autoformat(self) -> Result<()> { + // Default to formatting the project + if self.raw.is_none() && self.file.is_none() { + if let Err(e) = autoformat_project(self.check).await { + eprintln!("error formatting project: {}", e); + exit(1); + } + } + + if let Some(raw) = self.raw { + if let Some(inner) = dioxus_autofmt::fmt_block(&raw, 0) { + println!("{}", inner); + } else { + // exit process with error + eprintln!("error formatting codeblock"); + exit(1); + } + } + + // Format single file + if let Some(file) = self.file { + let file_content = fs::read_to_string(&file); + + match file_content { + Ok(s) => { + let edits = dioxus_autofmt::fmt_file(&s); + let out = dioxus_autofmt::apply_formats(&s, edits); + match fs::write(&file, out) { + Ok(_) => { + println!("formatted {}", file); + } + Err(e) => { + eprintln!("failed to write formatted content to file: {}", e); + } + } + } + Err(e) => { + eprintln!("failed to open file: {}", e); + exit(1); + } + } + } + + Ok(()) + } +} + +/// Read every .rs file accessible when considering the .gitignore and try to format it +/// +/// Runs using Tokio for multithreading, so it should be really really fast +/// +/// Doesn't do mod-descending, so it will still try to format unreachable files. TODO. +async fn autoformat_project(check: bool) -> Result<()> { + let crate_config = crate::CrateConfig::new()?; + + let mut files_to_format = vec![]; + collect_rs_files(&crate_config.crate_dir, &mut files_to_format); + + let counts = files_to_format + .into_iter() + .filter(|file| { + if file.components().any(|f| f.as_os_str() == "target") { + return false; + } + + true + }) + .map(|path| async { + let _path = path.clone(); + let res = tokio::spawn(async move { + let contents = tokio::fs::read_to_string(&path).await?; + + let edits = dioxus_autofmt::fmt_file(&contents); + let len = edits.len(); + + if !edits.is_empty() { + let out = dioxus_autofmt::apply_formats(&contents, edits); + tokio::fs::write(&path, out).await?; + } + + Ok(len) as Result + }) + .await; + + if res.is_err() { + eprintln!("error formatting file: {}", _path.display()); + } + + res + }) + .collect::>() + .collect::>() + .await; + + let files_formatted: usize = counts + .into_iter() + .map(|f| match f { + Ok(Ok(res)) => res, + _ => 0, + }) + .sum(); + + if files_formatted > 0 && check { + eprintln!("{} files needed formatting", files_formatted); + exit(1); + } + + Ok(()) +} + +fn collect_rs_files(folder: &Path, files: &mut Vec) { + let Ok(folder) = folder.read_dir() else { return }; + + // load the gitignore + + for entry in folder { + let Ok(entry) = entry else { continue; }; + + let path = entry.path(); + + if path.is_dir() { + collect_rs_files(&path, files); + } + + if let Some(ext) = path.extension() { + if ext == "rs" { + files.push(path); + } + } + } +} + +#[tokio::test] +async fn test_auto_fmt() { + let test_rsx = r#" + // + + rsx! { + + div {} + } + + // + // + // + + "# + .to_string(); + + let fmt = Autoformat { + check: false, + raw: Some(test_rsx), + file: None, + }; + + fmt.autoformat().await.unwrap(); +} + +/*#[test] +fn spawn_properly() { + let out = Command::new("dioxus") + .args([ + "fmt", + "-f", + r#" +// + +rsx! { + + div {} +} + +// +// +// + + "#, + ]) + .output() + .expect("failed to execute process"); + + dbg!(out); +}*/ diff --git a/packages/cli/src/cli/build/mod.rs b/packages/cli/src/cli/build/mod.rs new file mode 100644 index 000000000..8fbe132ae --- /dev/null +++ b/packages/cli/src/cli/build/mod.rs @@ -0,0 +1,76 @@ +use crate::plugin::PluginManager; + +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Parser)] +#[clap(name = "build")] +pub struct Build { + #[clap(flatten)] + pub build: ConfigOptsBuild, +} + +impl Build { + pub fn build(self) -> Result<()> { + let mut crate_config = crate::CrateConfig::new()?; + + // change the release state. + crate_config.with_release(self.build.release); + crate_config.with_verbose(self.build.verbose); + + if self.build.example.is_some() { + crate_config.as_example(self.build.example.unwrap()); + } + + if self.build.profile.is_some() { + crate_config.set_profile(self.build.profile.unwrap()); + } + + if self.build.features.is_some() { + crate_config.set_features(self.build.features.unwrap()); + } + + let platform = self.build.platform.unwrap_or_else(|| { + crate_config + .dioxus_config + .application + .default_platform + .clone() + }); + + let _ = PluginManager::on_build_start(&crate_config, &platform); + + match platform.as_str() { + "web" => { + crate::builder::build(&crate_config, false)?; + } + "desktop" => { + crate::builder::build_desktop(&crate_config, false)?; + } + _ => { + return custom_error!("Unsupported platform target."); + } + } + + let temp = gen_page(&crate_config.dioxus_config, false); + + let mut file = std::fs::File::create( + crate_config + .crate_dir + .join( + crate_config + .dioxus_config + .application + .out_dir + .clone() + .unwrap_or_else(|| PathBuf::from("dist")), + ) + .join("index.html"), + )?; + file.write_all(temp.as_bytes())?; + + let _ = PluginManager::on_build_finish(&crate_config, &platform); + + Ok(()) + } +} diff --git a/packages/cli/src/cli/cfg.rs b/packages/cli/src/cli/cfg.rs new file mode 100644 index 000000000..30ca89ce9 --- /dev/null +++ b/packages/cli/src/cli/cfg.rs @@ -0,0 +1,96 @@ +use super::*; + +/// Config options for the build system. +#[derive(Clone, Debug, Default, Deserialize, Parser)] +pub struct ConfigOptsBuild { + /// The index HTML file to drive the bundling process [default: index.html] + #[arg(long)] + pub target: Option, + + /// Build in release mode [default: false] + #[clap(long)] + #[serde(default)] + pub release: bool, + + // Use verbose output [default: false] + #[clap(long)] + #[serde(default)] + pub verbose: bool, + + /// Build a example [default: ""] + #[clap(long)] + pub example: Option, + + /// Build with custom profile + #[clap(long)] + pub profile: Option, + + /// Build platform: support Web & Desktop [default: "default_platform"] + #[clap(long)] + pub platform: Option, + + /// Space separated list of features to activate + #[clap(long)] + pub features: Option>, +} + +#[derive(Clone, Debug, Default, Deserialize, Parser)] +pub struct ConfigOptsServe { + /// The index HTML file to drive the bundling process [default: index.html] + #[arg(short, long)] + pub target: Option, + + /// Port of dev server + #[clap(long)] + #[clap(default_value_t = 8080)] + pub port: u16, + + /// Open the app in the default browser [default: false] + #[clap(long)] + #[serde(default)] + pub open: bool, + + /// Build a example [default: ""] + #[clap(long)] + pub example: Option, + + /// Build in release mode [default: false] + #[clap(long)] + #[serde(default)] + pub release: bool, + + // Use verbose output [default: false] + #[clap(long)] + #[serde(default)] + pub verbose: bool, + + /// Build with custom profile + #[clap(long)] + pub profile: Option, + + /// Build platform: support Web & Desktop [default: "default_platform"] + #[clap(long)] + pub platform: Option, + + /// Build with hot reloading rsx [default: false] + #[clap(long)] + #[serde(default)] + pub hot_reload: bool, + + /// Set cross-origin-policy to same-origin [default: false] + #[clap(name = "cross-origin-policy")] + #[clap(long)] + #[serde(default)] + pub cross_origin_policy: bool, + + /// Space separated list of features to activate + #[clap(long)] + pub features: Option>, +} + +/// Ensure the given value for `--public-url` is formatted correctly. +pub fn parse_public_url(val: &str) -> String { + let prefix = if !val.starts_with('/') { "/" } else { "" }; + let suffix = if !val.ends_with('/') { "/" } else { "" }; + format!("{}{}{}", prefix, val, suffix) +} diff --git a/packages/cli/src/cli/clean/mod.rs b/packages/cli/src/cli/clean/mod.rs new file mode 100644 index 000000000..d380f5265 --- /dev/null +++ b/packages/cli/src/cli/clean/mod.rs @@ -0,0 +1,33 @@ +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Parser)] +#[clap(name = "clean")] +pub struct Clean {} + +impl Clean { + pub fn clean(self) -> Result<()> { + let crate_config = crate::CrateConfig::new()?; + + let output = Command::new("cargo") + .arg("clean") + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output()?; + + if !output.status.success() { + return custom_error!("Cargo clean failed."); + } + + let out_dir = crate_config + .dioxus_config + .application + .out_dir + .unwrap_or_else(|| PathBuf::from("dist")); + if crate_config.crate_dir.join(&out_dir).is_dir() { + remove_dir_all(crate_config.crate_dir.join(&out_dir))?; + } + + Ok(()) + } +} diff --git a/packages/cli/src/cli/config/mod.rs b/packages/cli/src/cli/config/mod.rs new file mode 100644 index 000000000..5f9fa20d0 --- /dev/null +++ b/packages/cli/src/cli/config/mod.rs @@ -0,0 +1,63 @@ +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Deserialize, Subcommand)] +#[clap(name = "config")] +pub enum Config { + /// Init `Dioxus.toml` for project/folder. + Init { + /// Init project name + name: String, + + /// Cover old config + #[clap(long)] + #[serde(default)] + force: bool, + + /// Project default platform + #[clap(long, default_value = "web")] + platform: String, + }, + /// Format print Dioxus config. + FormatPrint {}, + /// Create a custom html file. + CustomHtml {}, +} + +impl Config { + pub fn config(self) -> Result<()> { + let crate_root = crate::cargo::crate_root()?; + match self { + Config::Init { + name, + force, + platform, + } => { + let conf_path = crate_root.join("Dioxus.toml"); + if conf_path.is_file() && !force { + log::warn!( + "config file `Dioxus.toml` already exist, use `--force` to overwrite it." + ); + return Ok(()); + } + let mut file = File::create(conf_path)?; + let content = String::from(include_str!("../../assets/dioxus.toml")) + .replace("{{project-name}}", &name) + .replace("{{default-platform}}", &platform); + file.write_all(content.as_bytes())?; + log::info!("🚩 Init config file completed."); + } + Config::FormatPrint {} => { + println!("{:#?}", crate::CrateConfig::new()?.dioxus_config); + } + Config::CustomHtml {} => { + let html_path = crate_root.join("index.html"); + let mut file = File::create(html_path)?; + let content = include_str!("../../assets/index.html"); + file.write_all(content.as_bytes())?; + log::info!("🚩 Create custom html file done."); + } + } + Ok(()) + } +} diff --git a/packages/cli/src/cli/create/mod.rs b/packages/cli/src/cli/create/mod.rs new file mode 100644 index 000000000..b2323d0a2 --- /dev/null +++ b/packages/cli/src/cli/create/mod.rs @@ -0,0 +1,76 @@ +use super::*; +use cargo_generate::{GenerateArgs, TemplatePath}; + +#[derive(Clone, Debug, Default, Deserialize, Parser)] +#[clap(name = "create")] +pub struct Create { + /// Template path + #[clap(default_value = "gh:dioxuslabs/dioxus-template", long)] + template: String, +} + +impl Create { + pub fn create(self) -> Result<()> { + let args = GenerateArgs { + template_path: TemplatePath { + auto_path: Some(self.template), + ..Default::default() + }, + ..Default::default() + }; + + let path = cargo_generate::generate(args)?; + + // first run cargo fmt + let mut cmd = Command::new("cargo"); + let cmd = cmd.arg("fmt").current_dir(&path); + let output = cmd.output().expect("failed to execute process"); + if !output.status.success() { + log::error!("cargo fmt failed"); + log::error!("stdout: {}", String::from_utf8_lossy(&output.stdout)); + log::error!("stderr: {}", String::from_utf8_lossy(&output.stderr)); + } + + // then format the toml + let toml_paths = [path.join("Cargo.toml"), path.join("Dioxus.toml")]; + for toml_path in &toml_paths { + let toml = std::fs::read_to_string(toml_path)?; + let mut toml = toml.parse::().map_err(|e| { + anyhow::anyhow!( + "failed to parse toml at {}: {}", + toml_path.display(), + e.to_string() + ) + })?; + + toml.as_table_mut().fmt(); + + let as_string = toml.to_string(); + let new_string = remove_tripple_newlines(&as_string); + let mut file = std::fs::File::create(toml_path)?; + file.write_all(new_string.as_bytes())?; + } + + // remove any tripple newlines from the readme + let readme_path = path.join("README.md"); + let readme = std::fs::read_to_string(&readme_path)?; + let new_readme = remove_tripple_newlines(&readme); + let mut file = std::fs::File::create(readme_path)?; + file.write_all(new_readme.as_bytes())?; + + log::info!("Generated project at {}", path.display()); + + Ok(()) + } +} + +fn remove_tripple_newlines(string: &str) -> String { + let mut new_string = String::new(); + for char in string.chars() { + if char == '\n' && new_string.ends_with("\n\n") { + continue; + } + new_string.push(char); + } + new_string +} diff --git a/packages/cli/src/cli/mod.rs b/packages/cli/src/cli/mod.rs new file mode 100644 index 000000000..4ad4fcd89 --- /dev/null +++ b/packages/cli/src/cli/mod.rs @@ -0,0 +1,89 @@ +pub mod autoformat; +pub mod build; +pub mod cfg; +pub mod clean; +pub mod config; +pub mod create; +pub mod plugin; +pub mod serve; +pub mod translate; +pub mod version; + +use crate::{ + cfg::{ConfigOptsBuild, ConfigOptsServe}, + custom_error, + error::Result, + gen_page, server, CrateConfig, Error, +}; +use clap::{Parser, Subcommand}; +use html_parser::Dom; +use serde::Deserialize; +use std::{ + fmt::Display, + fs::{remove_dir_all, File}, + io::{Read, Write}, + path::PathBuf, + process::{Command, Stdio}, +}; + +/// Build, Bundle & Ship Dioxus Apps. +#[derive(Parser)] +#[clap(name = "dioxus", version)] +pub struct Cli { + #[clap(subcommand)] + pub action: Commands, + + /// Enable verbose logging. + #[clap(short)] + pub v: bool, +} + +#[derive(Parser)] +pub enum Commands { + /// Build the Rust WASM app and all of its assets. + Build(build::Build), + + /// Translate some source file into Dioxus code. + Translate(translate::Translate), + + /// Build, watch & serve the Rust WASM app and all of its assets. + Serve(serve::Serve), + + /// Init a new project for Dioxus. + Create(create::Create), + + /// Clean output artifacts. + Clean(clean::Clean), + + /// Print the version of this extension + #[clap(name = "version")] + Version(version::Version), + + /// Format some rsx + #[clap(name = "fmt")] + Autoformat(autoformat::Autoformat), + + /// Dioxus config file controls. + #[clap(subcommand)] + Config(config::Config), + + /// Manage plugins for dioxus cli + #[clap(subcommand)] + Plugin(plugin::Plugin), +} + +impl Display for Commands { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Commands::Build(_) => write!(f, "build"), + Commands::Translate(_) => write!(f, "translate"), + Commands::Serve(_) => write!(f, "serve"), + Commands::Create(_) => write!(f, "create"), + Commands::Clean(_) => write!(f, "clean"), + Commands::Config(_) => write!(f, "config"), + Commands::Plugin(_) => write!(f, "plugin"), + Commands::Version(_) => write!(f, "version"), + Commands::Autoformat(_) => write!(f, "fmt"), + } + } +} diff --git a/packages/cli/src/cli/plugin/mod.rs b/packages/cli/src/cli/plugin/mod.rs new file mode 100644 index 000000000..d838a84a5 --- /dev/null +++ b/packages/cli/src/cli/plugin/mod.rs @@ -0,0 +1,37 @@ +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Deserialize, Subcommand)] +#[clap(name = "plugin")] +pub enum Plugin { + /// Return all dioxus-cli support tools. + List {}, + /// Get default app install path. + AppPath {}, + /// Install a new tool. + Add { name: String }, +} + +impl Plugin { + pub async fn plugin(self) -> Result<()> { + match self { + Plugin::List {} => { + for item in crate::plugin::PluginManager::plugin_list() { + println!("- {item}"); + } + } + Plugin::AppPath {} => { + let plugin_dir = crate::plugin::PluginManager::init_plugin_dir(); + if let Some(v) = plugin_dir.to_str() { + println!("{}", v); + } else { + log::error!("Plugin path get failed."); + } + } + Plugin::Add { name: _ } => { + log::info!("You can use `dioxus plugin app-path` to get Installation position"); + } + } + Ok(()) + } +} diff --git a/packages/cli/src/cli/serve/mod.rs b/packages/cli/src/cli/serve/mod.rs new file mode 100644 index 000000000..2e0477d42 --- /dev/null +++ b/packages/cli/src/cli/serve/mod.rs @@ -0,0 +1,100 @@ +use super::*; +use std::{ + fs::create_dir_all, + io::Write, + path::PathBuf, + process::{Command, Stdio}, +}; + +/// Run the WASM project on dev-server +#[derive(Clone, Debug, Parser)] +#[clap(name = "serve")] +pub struct Serve { + #[clap(flatten)] + pub serve: ConfigOptsServe, +} + +impl Serve { + pub async fn serve(self) -> Result<()> { + let mut crate_config = crate::CrateConfig::new()?; + + // change the relase state. + crate_config.with_hot_reload(self.serve.hot_reload); + crate_config.with_cross_origin_policy(self.serve.cross_origin_policy); + crate_config.with_release(self.serve.release); + crate_config.with_verbose(self.serve.verbose); + + if self.serve.example.is_some() { + crate_config.as_example(self.serve.example.unwrap()); + } + + if self.serve.profile.is_some() { + crate_config.set_profile(self.serve.profile.unwrap()); + } + + if self.serve.features.is_some() { + crate_config.set_features(self.serve.features.unwrap()); + } + + // Subdirectories don't work with the server + crate_config.dioxus_config.web.app.base_path = None; + + let platform = self.serve.platform.unwrap_or_else(|| { + crate_config + .dioxus_config + .application + .default_platform + .clone() + }); + + if platform.as_str() == "desktop" { + crate::builder::build_desktop(&crate_config, true)?; + + match &crate_config.executable { + crate::ExecutableType::Binary(name) + | crate::ExecutableType::Lib(name) + | crate::ExecutableType::Example(name) => { + let mut file = crate_config.out_dir.join(name); + if cfg!(windows) { + file.set_extension("exe"); + } + Command::new(file.to_str().unwrap()) + .stdout(Stdio::inherit()) + .output()?; + } + } + return Ok(()); + } else if platform != "web" { + return custom_error!("Unsupported platform target."); + } + + // generate dev-index page + Serve::regen_dev_page(&crate_config)?; + + // start the develop server + server::startup(self.serve.port, crate_config.clone(), self.serve.open).await?; + + Ok(()) + } + + pub fn regen_dev_page(crate_config: &CrateConfig) -> Result<()> { + let serve_html = gen_page(&crate_config.dioxus_config, true); + + let dist_path = crate_config.crate_dir.join( + crate_config + .dioxus_config + .application + .out_dir + .clone() + .unwrap_or_else(|| PathBuf::from("dist")), + ); + if !dist_path.is_dir() { + create_dir_all(&dist_path)?; + } + let index_path = dist_path.join("index.html"); + let mut file = std::fs::File::create(index_path)?; + file.write_all(serve_html.as_bytes())?; + + Ok(()) + } +} diff --git a/packages/cli/src/cli/tool/mod.rs b/packages/cli/src/cli/tool/mod.rs new file mode 100644 index 000000000..2edccf7ea --- /dev/null +++ b/packages/cli/src/cli/tool/mod.rs @@ -0,0 +1,64 @@ +use crate::tools; + +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Deserialize, Subcommand)] +#[clap(name = "tool")] +pub enum Tool { + /// Return all dioxus-cli support tools. + List {}, + /// Get default app install path. + AppPath {}, + /// Install a new tool. + Add { name: String }, +} + +impl Tool { + pub async fn tool(self) -> Result<()> { + match self { + Tool::List {} => { + for item in tools::tool_list() { + if tools::Tool::from_str(item).unwrap().is_installed() { + println!("- {item} [installed]"); + } else { + println!("- {item}"); + } + } + } + Tool::AppPath {} => { + if let Some(v) = tools::tools_path().to_str() { + println!("{}", v); + } else { + return custom_error!("Tools path get failed."); + } + } + Tool::Add { name } => { + let tool_list = tools::tool_list(); + + if !tool_list.contains(&name.as_str()) { + return custom_error!("Tool {name} not found."); + } + let target_tool = tools::Tool::from_str(&name).unwrap(); + + if target_tool.is_installed() { + log::warn!("Tool {name} is installed."); + return Ok(()); + } + + log::info!("Start to download tool package..."); + if let Err(e) = target_tool.download_package().await { + return custom_error!("Tool download failed: {e}"); + } + + log::info!("Start to install tool package..."); + if let Err(e) = target_tool.install_package().await { + return custom_error!("Tool install failed: {e}"); + } + + log::info!("Tool {name} installed successfully!"); + } + } + Ok(()) + } +} diff --git a/packages/cli/src/cli/translate/mod.rs b/packages/cli/src/cli/translate/mod.rs new file mode 100644 index 000000000..81f0da3e6 --- /dev/null +++ b/packages/cli/src/cli/translate/mod.rs @@ -0,0 +1,138 @@ +use std::process::exit; + +use dioxus_rsx::{BodyNode, CallBody}; + +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Parser)] +#[clap(name = "translate")] +pub struct Translate { + /// Activate debug mode + // short and long flags (-d, --debug) will be deduced from the field's name + #[clap(short, long)] + pub component: bool, + + /// Input file + #[clap(short, long)] + pub file: Option, + + /// Input file + #[clap(short, long)] + pub raw: Option, + + /// Output file, stdout if not present + #[arg(short, long)] + pub output: Option, +} + +impl Translate { + pub fn translate(self) -> Result<()> { + // Get the right input for the translation + let contents = determine_input(self.file, self.raw)?; + + // Ensure we're loading valid HTML + let dom = html_parser::Dom::parse(&contents)?; + + // Convert the HTML to RSX + let out = convert_html_to_formatted_rsx(&dom, self.component); + + // Write the output + match self.output { + Some(output) => std::fs::write(output, out)?, + None => print!("{}", out), + } + + Ok(()) + } +} + +pub fn convert_html_to_formatted_rsx(dom: &Dom, component: bool) -> String { + let callbody = rsx_rosetta::rsx_from_html(dom); + + match component { + true => write_callbody_with_icon_section(callbody), + false => dioxus_autofmt::write_block_out(callbody).unwrap(), + } +} + +fn write_callbody_with_icon_section(mut callbody: CallBody) -> String { + let mut svgs = vec![]; + + rsx_rosetta::collect_svgs(&mut callbody.roots, &mut svgs); + + let mut out = write_component_body(dioxus_autofmt::write_block_out(callbody).unwrap()); + + if !svgs.is_empty() { + write_svg_section(&mut out, svgs); + } + + out +} + +fn write_component_body(raw: String) -> String { + let mut out = String::from("fn component(cx: Scope) -> Element {\n cx.render(rsx! {"); + indent_and_write(&raw, 1, &mut out); + out.push_str(" })\n}"); + out +} + +fn write_svg_section(out: &mut String, svgs: Vec) { + out.push_str("\n\nmod icons {"); + out.push_str("\n use super::*;"); + for (idx, icon) in svgs.into_iter().enumerate() { + let raw = dioxus_autofmt::write_block_out(CallBody { roots: vec![icon] }).unwrap(); + out.push_str("\n\n pub fn icon_"); + out.push_str(&idx.to_string()); + out.push_str("(cx: Scope) -> Element {\n cx.render(rsx! {"); + indent_and_write(&raw, 2, out); + out.push_str(" })\n }"); + } + + out.push_str("\n}"); +} + +fn indent_and_write(raw: &str, idx: usize, out: &mut String) { + for line in raw.lines() { + for _ in 0..idx { + out.push_str(" "); + } + out.push_str(line); + out.push('\n'); + } +} + +fn determine_input(file: Option, raw: Option) -> Result { + // Make sure not both are specified + if file.is_some() && raw.is_some() { + log::error!("Only one of --file or --raw should be specified."); + exit(0); + } + + if let Some(raw) = raw { + return Ok(raw); + } + + if let Some(file) = file { + return Ok(std::fs::read_to_string(file)?); + } + + // If neither exist, we try to read from stdin + if atty::is(atty::Stream::Stdin) { + return custom_error!("No input file, source, or stdin to translate from."); + } + + let mut buffer = String::new(); + std::io::stdin().read_to_string(&mut buffer).unwrap(); + + Ok(buffer.trim().to_string()) +} + +#[test] +fn generates_svgs() { + let st = include_str!("../../../tests/svg.html"); + + let out = convert_html_to_formatted_rsx(&html_parser::Dom::parse(st).unwrap(), true); + + println!("{}", out); +} diff --git a/packages/cli/src/cli/version.rs b/packages/cli/src/cli/version.rs new file mode 100644 index 000000000..3c77ba419 --- /dev/null +++ b/packages/cli/src/cli/version.rs @@ -0,0 +1,76 @@ +use super::*; + +/// Build the Rust WASM app and all of its assets. +#[derive(Clone, Debug, Parser)] +#[clap(name = "version")] +pub struct Version {} + +impl Version { + pub fn version(self) -> VersionInfo { + version() + } +} + +use std::fmt; + +/// Information about the git repository where rust-analyzer was built from. +pub struct CommitInfo { + pub short_commit_hash: &'static str, + pub commit_hash: &'static str, + pub commit_date: &'static str, +} + +/// Cargo's version. +pub struct VersionInfo { + /// rust-analyzer's version, such as "1.57.0", "1.58.0-beta.1", "1.59.0-nightly", etc. + pub version: &'static str, + + /// The release channel we were built for (stable/beta/nightly/dev). + /// + /// `None` if not built via rustbuild. + pub release_channel: Option<&'static str>, + + /// Information about the Git repository we may have been built from. + /// + /// `None` if not built from a git repo. + pub commit_info: Option, +} + +impl fmt::Display for VersionInfo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.version)?; + + if let Some(ci) = &self.commit_info { + write!(f, " ({} {})", ci.short_commit_hash, ci.commit_date)?; + }; + Ok(()) + } +} + +/// Returns information about cargo's version. +pub const fn version() -> VersionInfo { + let version = match option_env!("CFG_RELEASE") { + Some(x) => x, + None => "0.0.0", + }; + + let release_channel = option_env!("CFG_RELEASE_CHANNEL"); + let commit_info = match ( + option_env!("RA_COMMIT_SHORT_HASH"), + option_env!("RA_COMMIT_HASH"), + option_env!("RA_COMMIT_DATE"), + ) { + (Some(short_commit_hash), Some(commit_hash), Some(commit_date)) => Some(CommitInfo { + short_commit_hash, + commit_hash, + commit_date, + }), + _ => None, + }; + + VersionInfo { + version, + release_channel, + commit_info, + } +} diff --git a/packages/cli/src/config.rs b/packages/cli/src/config.rs new file mode 100644 index 000000000..6324f725f --- /dev/null +++ b/packages/cli/src/config.rs @@ -0,0 +1,266 @@ +use crate::error::Result; +use serde::{Deserialize, Serialize}; +use std::{collections::HashMap, path::PathBuf}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DioxusConfig { + pub application: ApplicationConfig, + + pub web: WebConfig, + + #[serde(default = "default_plugin")] + pub plugin: toml::Value, +} + +fn default_plugin() -> toml::Value { + toml::Value::Boolean(true) +} + +impl DioxusConfig { + pub fn load() -> crate::error::Result> { + let Ok(crate_dir) = crate::cargo::crate_root() else { return Ok(None); }; + + // we support either `Dioxus.toml` or `Cargo.toml` + let Some(dioxus_conf_file) = acquire_dioxus_toml(crate_dir) else { + return Ok(None); + }; + + toml::from_str::(&std::fs::read_to_string(dioxus_conf_file)?) + .map_err(|_| crate::Error::Unique("Dioxus.toml parse failed".into())) + .map(Some) + } +} + +fn acquire_dioxus_toml(dir: PathBuf) -> Option { + // prefer uppercase + if dir.join("Dioxus.toml").is_file() { + return Some(dir.join("Dioxus.toml")); + } + + // lowercase is fine too + if dir.join("dioxus.toml").is_file() { + return Some(dir.join("Dioxus.toml")); + } + + None +} + +impl Default for DioxusConfig { + fn default() -> Self { + Self { + application: ApplicationConfig { + name: "dioxus".into(), + default_platform: "web".to_string(), + out_dir: Some(PathBuf::from("dist")), + asset_dir: Some(PathBuf::from("public")), + + tools: None, + + sub_package: None, + }, + web: WebConfig { + app: WebAppConfig { + title: Some("dioxus | ⛺".into()), + base_path: None, + }, + proxy: Some(vec![]), + watcher: WebWatcherConfig { + watch_path: Some(vec![PathBuf::from("src")]), + reload_html: Some(false), + index_on_404: Some(true), + }, + resource: WebResourceConfig { + dev: WebDevResourceConfig { + style: Some(vec![]), + script: Some(vec![]), + }, + style: Some(vec![]), + script: Some(vec![]), + }, + }, + plugin: toml::Value::Table(toml::map::Map::new()), + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ApplicationConfig { + pub name: String, + pub default_platform: String, + pub out_dir: Option, + pub asset_dir: Option, + + pub tools: Option>, + + pub sub_package: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebConfig { + pub app: WebAppConfig, + pub proxy: Option>, + pub watcher: WebWatcherConfig, + pub resource: WebResourceConfig, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebAppConfig { + pub title: Option, + pub base_path: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebProxyConfig { + pub backend: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebWatcherConfig { + pub watch_path: Option>, + pub reload_html: Option, + pub index_on_404: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebResourceConfig { + pub dev: WebDevResourceConfig, + pub style: Option>, + pub script: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct WebDevResourceConfig { + pub style: Option>, + pub script: Option>, +} + +#[derive(Debug, Clone)] +pub struct CrateConfig { + pub out_dir: PathBuf, + pub crate_dir: PathBuf, + pub workspace_dir: PathBuf, + pub target_dir: PathBuf, + pub asset_dir: PathBuf, + pub manifest: cargo_toml::Manifest, + pub executable: ExecutableType, + pub dioxus_config: DioxusConfig, + pub release: bool, + pub hot_reload: bool, + pub cross_origin_policy: bool, + pub verbose: bool, + pub custom_profile: Option, + pub features: Option>, +} + +#[derive(Debug, Clone)] +pub enum ExecutableType { + Binary(String), + Lib(String), + Example(String), +} + +impl CrateConfig { + pub fn new() -> Result { + let dioxus_config = DioxusConfig::load()?.unwrap_or_default(); + + let crate_dir = if let Some(package) = &dioxus_config.application.sub_package { + crate::cargo::crate_root()?.join(package) + } else { + crate::cargo::crate_root()? + }; + let meta = crate::cargo::Metadata::get()?; + let workspace_dir = meta.workspace_root; + let target_dir = meta.target_directory; + + let out_dir = match dioxus_config.application.out_dir { + Some(ref v) => crate_dir.join(v), + None => crate_dir.join("dist"), + }; + + let cargo_def = &crate_dir.join("Cargo.toml"); + + let asset_dir = match dioxus_config.application.asset_dir { + Some(ref v) => crate_dir.join(v), + None => crate_dir.join("public"), + }; + + let manifest = cargo_toml::Manifest::from_path(cargo_def).unwrap(); + + let output_filename = { + match &manifest.package.as_ref().unwrap().default_run { + Some(default_run_target) => default_run_target.to_owned(), + None => manifest + .bin + .iter() + .find(|b| b.name == manifest.package.as_ref().map(|pkg| pkg.name.clone())) + .or(manifest + .bin + .iter() + .find(|b| b.path == Some("src/main.rs".to_owned()))) + .or(manifest.bin.first()) + .or(manifest.lib.as_ref()) + .and_then(|prod| prod.name.clone()) + .expect("No executable or library found from cargo metadata."), + } + }; + let executable = ExecutableType::Binary(output_filename); + + let release = false; + let hot_reload = false; + let verbose = false; + let custom_profile = None; + let features = None; + + Ok(Self { + out_dir, + crate_dir, + workspace_dir, + target_dir, + asset_dir, + manifest, + executable, + release, + dioxus_config, + hot_reload, + cross_origin_policy: false, + custom_profile, + features, + verbose, + }) + } + + pub fn as_example(&mut self, example_name: String) -> &mut Self { + self.executable = ExecutableType::Example(example_name); + self + } + + pub fn with_release(&mut self, release: bool) -> &mut Self { + self.release = release; + self + } + + pub fn with_hot_reload(&mut self, hot_reload: bool) -> &mut Self { + self.hot_reload = hot_reload; + self + } + + pub fn with_cross_origin_policy(&mut self, cross_origin_policy: bool) -> &mut Self { + self.cross_origin_policy = cross_origin_policy; + self + } + + pub fn with_verbose(&mut self, verbose: bool) -> &mut Self { + self.verbose = verbose; + self + } + + pub fn set_profile(&mut self, profile: String) -> &mut Self { + self.custom_profile = Some(profile); + self + } + + pub fn set_features(&mut self, features: Vec) -> &mut Self { + self.features = Some(features); + self + } +} diff --git a/packages/cli/src/error.rs b/packages/cli/src/error.rs new file mode 100644 index 000000000..7832ab326 --- /dev/null +++ b/packages/cli/src/error.rs @@ -0,0 +1,80 @@ +use thiserror::Error as ThisError; + +pub type Result = std::result::Result; + +#[derive(ThisError, Debug)] +pub enum Error { + /// Used when errors need to propogate but are too unique to be typed + #[error("{0}")] + Unique(String), + + #[error("I/O Error: {0}")] + IO(#[from] std::io::Error), + + #[error("Format Error: {0}")] + FormatError(#[from] std::fmt::Error), + + #[error("Format failed: {0}")] + ParseError(String), + + #[error("Runtime Error: {0}")] + RuntimeError(String), + + #[error("Failed to write error")] + FailedToWrite, + + #[error("Build Failed: {0}")] + BuildFailed(String), + + #[error("Cargo Error: {0}")] + CargoError(String), + + #[error("{0}")] + CustomError(String), + + #[error("Invalid proxy URL: {0}")] + InvalidProxy(#[from] hyper::http::uri::InvalidUri), + + #[error("Error proxying request: {0}")] + ProxyRequestError(hyper::Error), + + #[error(transparent)] + Other(#[from] anyhow::Error), +} + +impl From<&str> for Error { + fn from(s: &str) -> Self { + Error::Unique(s.to_string()) + } +} + +impl From for Error { + fn from(s: String) -> Self { + Error::Unique(s) + } +} + +impl From for Error { + fn from(e: html_parser::Error) -> Self { + Self::ParseError(e.to_string()) + } +} + +impl From for Error { + fn from(e: hyper::Error) -> Self { + Self::RuntimeError(e.to_string()) + } +} + +#[macro_export] +macro_rules! custom_error { + ($msg:literal $(,)?) => { + Err(Error::CustomError(format!($msg))) + }; + ($err:expr $(,)?) => { + Err(Error::from($err)) + }; + ($fmt:expr, $($arg:tt)*) => { + Err(Error::CustomError(format!($fmt, $($arg)*))) + }; +} diff --git a/packages/cli/src/lib.rs b/packages/cli/src/lib.rs new file mode 100644 index 000000000..13758a828 --- /dev/null +++ b/packages/cli/src/lib.rs @@ -0,0 +1,24 @@ +pub const DIOXUS_CLI_VERSION: &str = "0.1.5"; + +pub mod builder; +pub mod server; +pub mod tools; + +pub use builder::*; + +pub mod cargo; +pub use cargo::*; + +pub mod cli; +pub use cli::*; + +pub mod config; +pub use config::*; + +pub mod error; +pub use error::*; + +pub mod logging; +pub use logging::*; + +pub mod plugin; diff --git a/packages/cli/src/logging.rs b/packages/cli/src/logging.rs new file mode 100644 index 000000000..48c2a2788 --- /dev/null +++ b/packages/cli/src/logging.rs @@ -0,0 +1,35 @@ +use fern::colors::{Color, ColoredLevelConfig}; + +pub fn set_up_logging() { + // 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 + 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, + )); + }) + .level(log::LevelFilter::Info) + .chain(std::io::stdout()) + .apply() + .unwrap(); +} diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs new file mode 100644 index 000000000..f3c5c6e48 --- /dev/null +++ b/packages/cli/src/main.rs @@ -0,0 +1,65 @@ +use anyhow::anyhow; +use clap::Parser; +use dioxus_cli::{plugin::PluginManager, *}; +use Commands::*; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let args = Cli::parse(); + + set_up_logging(); + + let dioxus_config = DioxusConfig::load() + .map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))? + .unwrap_or_else(|| { + log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config"); + DioxusConfig::default() + }); + + PluginManager::init(dioxus_config.plugin) + .map_err(|e| anyhow!("🚫 Plugin system initialization failed: {e}"))?; + + match args.action { + Translate(opts) => opts + .translate() + .map_err(|e| anyhow!("🚫 Translation of HTML into RSX failed: {}", e)), + + Build(opts) => opts + .build() + .map_err(|e| anyhow!("🚫 Building project failed: {}", e)), + + Clean(opts) => opts + .clean() + .map_err(|e| anyhow!("🚫 Cleaning project failed: {}", e)), + + Serve(opts) => opts + .serve() + .await + .map_err(|e| anyhow!("🚫 Serving project failed: {}", e)), + + Create(opts) => opts + .create() + .map_err(|e| anyhow!("🚫 Creating new project failed: {}", e)), + + Config(opts) => opts + .config() + .map_err(|e| anyhow!("🚫 Configuring new project failed: {}", e)), + + Plugin(opts) => opts + .plugin() + .await + .map_err(|e| anyhow!("🚫 Error with plugin: {}", e)), + + Autoformat(opts) => opts + .autoformat() + .await + .map_err(|e| anyhow!("🚫 Error autoformatting RSX: {}", e)), + + Version(opt) => { + let version = opt.version(); + println!("{}", version); + + Ok(()) + } + } +} diff --git a/packages/cli/src/plugin/interface/command.rs b/packages/cli/src/plugin/interface/command.rs new file mode 100644 index 000000000..14a2650fe --- /dev/null +++ b/packages/cli/src/plugin/interface/command.rs @@ -0,0 +1,65 @@ +use std::process::{Command, Stdio}; + +use mlua::{FromLua, UserData}; + +#[derive(Debug, Clone, Copy)] +enum StdioFromString { + Inherit, + Piped, + Null, +} +impl<'lua> FromLua<'lua> for StdioFromString { + fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result { + if let mlua::Value::String(v) = lua_value { + let v = v.to_str().unwrap(); + return Ok(match v.to_lowercase().as_str() { + "inherit" => Self::Inherit, + "piped" => Self::Piped, + "null" => Self::Null, + _ => Self::Inherit, + }); + } + Ok(Self::Inherit) + } +} +impl StdioFromString { + pub fn to_stdio(self) -> Stdio { + match self { + StdioFromString::Inherit => Stdio::inherit(), + StdioFromString::Piped => Stdio::piped(), + StdioFromString::Null => Stdio::null(), + } + } +} + +pub struct PluginCommander; +impl UserData for PluginCommander { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_function( + "exec", + |_, args: (Vec, StdioFromString, StdioFromString)| { + let cmd = args.0; + let stdout = args.1; + let stderr = args.2; + + if cmd.is_empty() { + return Ok(()); + } + let cmd_name = cmd.get(0).unwrap(); + let mut command = Command::new(cmd_name); + let t = cmd + .iter() + .enumerate() + .filter(|(i, _)| *i > 0) + .map(|v| v.1.clone()) + .collect::>(); + command.args(t); + command.stdout(stdout.to_stdio()).stderr(stderr.to_stdio()); + command.output()?; + Ok(()) + }, + ); + } + + fn add_fields<'lua, F: mlua::UserDataFields<'lua, Self>>(_fields: &mut F) {} +} diff --git a/packages/cli/src/plugin/interface/dirs.rs b/packages/cli/src/plugin/interface/dirs.rs new file mode 100644 index 000000000..afce56b5c --- /dev/null +++ b/packages/cli/src/plugin/interface/dirs.rs @@ -0,0 +1,13 @@ +use mlua::UserData; + +use crate::tools::app_path; + +pub struct PluginDirs; +impl UserData for PluginDirs { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_function("plugins_dir", |_, ()| { + let path = app_path().join("plugins"); + Ok(path.to_str().unwrap().to_string()) + }); + } +} diff --git a/packages/cli/src/plugin/interface/fs.rs b/packages/cli/src/plugin/interface/fs.rs new file mode 100644 index 000000000..5668dbe33 --- /dev/null +++ b/packages/cli/src/plugin/interface/fs.rs @@ -0,0 +1,85 @@ +use std::{ + fs::{create_dir, create_dir_all, remove_dir_all, File}, + io::{Read, Write}, + path::PathBuf, +}; + +use crate::tools::extract_zip; +use flate2::read::GzDecoder; +use mlua::UserData; +use tar::Archive; + +pub struct PluginFileSystem; +impl UserData for PluginFileSystem { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_function("create_dir", |_, args: (String, bool)| { + let path = args.0; + let recursive = args.1; + let path = PathBuf::from(path); + if !path.exists() { + let v = if recursive { + create_dir_all(path) + } else { + create_dir(path) + }; + return Ok(v.is_ok()); + } + Ok(true) + }); + methods.add_function("remove_dir", |_, path: String| { + let path = PathBuf::from(path); + let r = remove_dir_all(path); + Ok(r.is_ok()) + }); + methods.add_function("file_get_content", |_, path: String| { + let path = PathBuf::from(path); + let mut file = std::fs::File::open(path)?; + let mut buffer = String::new(); + file.read_to_string(&mut buffer)?; + Ok(buffer) + }); + methods.add_function("file_set_content", |_, args: (String, String)| { + let path = args.0; + let content = args.1; + let path = PathBuf::from(path); + + let file = std::fs::File::create(path); + if file.is_err() { + return Ok(false); + } + + if file.unwrap().write_all(content.as_bytes()).is_err() { + return Ok(false); + } + + Ok(true) + }); + methods.add_function("unzip_file", |_, args: (String, String)| { + let file = PathBuf::from(args.0); + let target = PathBuf::from(args.1); + let res = extract_zip(&file, &target); + if res.is_err() { + return Ok(false); + } + Ok(true) + }); + methods.add_function("untar_gz_file", |_, args: (String, String)| { + let file = PathBuf::from(args.0); + let target = PathBuf::from(args.1); + + let tar_gz = if let Ok(v) = File::open(file) { + v + } else { + return Ok(false); + }; + + let tar = GzDecoder::new(tar_gz); + let mut archive = Archive::new(tar); + if archive.unpack(&target).is_err() { + return Ok(false); + } + + Ok(true) + }); + } +} diff --git a/packages/cli/src/plugin/interface/log.rs b/packages/cli/src/plugin/interface/log.rs new file mode 100644 index 000000000..bed8e2cbb --- /dev/null +++ b/packages/cli/src/plugin/interface/log.rs @@ -0,0 +1,28 @@ +use log; +use mlua::UserData; + +pub struct PluginLogger; +impl UserData for PluginLogger { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_function("trace", |_, info: String| { + log::trace!("{}", info); + Ok(()) + }); + methods.add_function("info", |_, info: String| { + log::info!("{}", info); + Ok(()) + }); + methods.add_function("debug", |_, info: String| { + log::debug!("{}", info); + Ok(()) + }); + methods.add_function("warn", |_, info: String| { + log::warn!("{}", info); + Ok(()) + }); + methods.add_function("error", |_, info: String| { + log::error!("{}", info); + Ok(()) + }); + } +} diff --git a/packages/cli/src/plugin/interface/mod.rs b/packages/cli/src/plugin/interface/mod.rs new file mode 100644 index 000000000..5ed2ed827 --- /dev/null +++ b/packages/cli/src/plugin/interface/mod.rs @@ -0,0 +1,233 @@ +use mlua::{FromLua, Function, ToLua}; + +pub mod command; +pub mod dirs; +pub mod fs; +pub mod log; +pub mod network; +pub mod os; +pub mod path; + +#[derive(Debug, Clone)] +pub struct PluginInfo<'lua> { + pub name: String, + pub repository: String, + pub author: String, + pub version: String, + + pub inner: PluginInner, + + pub on_init: Option>, + pub build: PluginBuildInfo<'lua>, + pub serve: PluginServeInfo<'lua>, +} + +impl<'lua> FromLua<'lua> for PluginInfo<'lua> { + fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result { + let mut res = Self { + name: String::default(), + repository: String::default(), + author: String::default(), + version: String::from("0.1.0"), + + inner: Default::default(), + + on_init: None, + build: Default::default(), + serve: Default::default(), + }; + if let mlua::Value::Table(tab) = lua_value { + if let Ok(v) = tab.get::<_, String>("name") { + res.name = v; + } + if let Ok(v) = tab.get::<_, String>("repository") { + res.repository = v; + } + if let Ok(v) = tab.get::<_, String>("author") { + res.author = v; + } + if let Ok(v) = tab.get::<_, String>("version") { + res.version = v; + } + + if let Ok(v) = tab.get::<_, PluginInner>("inner") { + res.inner = v; + } + + if let Ok(v) = tab.get::<_, Function>("on_init") { + res.on_init = Some(v); + } + + if let Ok(v) = tab.get::<_, PluginBuildInfo>("build") { + res.build = v; + } + + if let Ok(v) = tab.get::<_, PluginServeInfo>("serve") { + res.serve = v; + } + } + + Ok(res) + } +} + +impl<'lua> ToLua<'lua> for PluginInfo<'lua> { + fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { + let res = lua.create_table()?; + + res.set("name", self.name.to_string())?; + res.set("repository", self.repository.to_string())?; + res.set("author", self.author.to_string())?; + res.set("version", self.version.to_string())?; + + res.set("inner", self.inner)?; + + if let Some(e) = self.on_init { + res.set("on_init", e)?; + } + res.set("build", self.build)?; + res.set("serve", self.serve)?; + + Ok(mlua::Value::Table(res)) + } +} + +#[derive(Debug, Clone, Default)] +pub struct PluginInner { + pub plugin_dir: String, + pub from_loader: bool, +} + +impl<'lua> FromLua<'lua> for PluginInner { + fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result { + let mut res = Self { + plugin_dir: String::new(), + from_loader: false, + }; + + if let mlua::Value::Table(t) = lua_value { + if let Ok(v) = t.get::<_, String>("plugin_dir") { + res.plugin_dir = v; + } + if let Ok(v) = t.get::<_, bool>("from_loader") { + res.from_loader = v; + } + } + Ok(res) + } +} + +impl<'lua> ToLua<'lua> for PluginInner { + fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { + let res = lua.create_table()?; + + res.set("plugin_dir", self.plugin_dir)?; + res.set("from_loader", self.from_loader)?; + + Ok(mlua::Value::Table(res)) + } +} + +#[derive(Debug, Clone, Default)] +pub struct PluginBuildInfo<'lua> { + pub on_start: Option>, + pub on_finish: Option>, +} + +impl<'lua> FromLua<'lua> for PluginBuildInfo<'lua> { + fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result { + let mut res = Self { + on_start: None, + on_finish: None, + }; + + if let mlua::Value::Table(t) = lua_value { + if let Ok(v) = t.get::<_, Function>("on_start") { + res.on_start = Some(v); + } + if let Ok(v) = t.get::<_, Function>("on_finish") { + res.on_finish = Some(v); + } + } + + Ok(res) + } +} + +impl<'lua> ToLua<'lua> for PluginBuildInfo<'lua> { + fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { + let res = lua.create_table()?; + + if let Some(v) = self.on_start { + res.set("on_start", v)?; + } + + if let Some(v) = self.on_finish { + res.set("on_finish", v)?; + } + + Ok(mlua::Value::Table(res)) + } +} + +#[derive(Debug, Clone, Default)] +pub struct PluginServeInfo<'lua> { + pub interval: i32, + + pub on_start: Option>, + pub on_interval: Option>, + pub on_rebuild: Option>, + pub on_shutdown: Option>, +} + +impl<'lua> FromLua<'lua> for PluginServeInfo<'lua> { + fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result { + let mut res = Self::default(); + + if let mlua::Value::Table(tab) = lua_value { + if let Ok(v) = tab.get::<_, i32>("interval") { + res.interval = v; + } + if let Ok(v) = tab.get::<_, Function>("on_start") { + res.on_start = Some(v); + } + if let Ok(v) = tab.get::<_, Function>("on_interval") { + res.on_interval = Some(v); + } + if let Ok(v) = tab.get::<_, Function>("on_rebuild") { + res.on_rebuild = Some(v); + } + if let Ok(v) = tab.get::<_, Function>("on_shutdown") { + res.on_shutdown = Some(v); + } + } + + Ok(res) + } +} + +impl<'lua> ToLua<'lua> for PluginServeInfo<'lua> { + fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { + let res = lua.create_table()?; + + res.set("interval", self.interval)?; + + if let Some(v) = self.on_start { + res.set("on_start", v)?; + } + + if let Some(v) = self.on_interval { + res.set("on_interval", v)?; + } + + if let Some(v) = self.on_rebuild { + res.set("on_rebuild", v)?; + } + + if let Some(v) = self.on_shutdown { + res.set("on_shutdown", v)?; + } + + Ok(mlua::Value::Table(res)) + } +} diff --git a/packages/cli/src/plugin/interface/network.rs b/packages/cli/src/plugin/interface/network.rs new file mode 100644 index 000000000..8d940ddc4 --- /dev/null +++ b/packages/cli/src/plugin/interface/network.rs @@ -0,0 +1,27 @@ +use std::{io::Cursor, path::PathBuf}; + +use mlua::UserData; + +pub struct PluginNetwork; +impl UserData for PluginNetwork { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_function("download_file", |_, args: (String, String)| { + let url = args.0; + let path = args.1; + + let resp = reqwest::blocking::get(url); + if let Ok(resp) = resp { + let mut content = Cursor::new(resp.bytes().unwrap()); + let file = std::fs::File::create(PathBuf::from(path)); + if file.is_err() { + return Ok(false); + } + let mut file = file.unwrap(); + let res = std::io::copy(&mut content, &mut file); + return Ok(res.is_ok()); + } + + Ok(false) + }); + } +} diff --git a/packages/cli/src/plugin/interface/os.rs b/packages/cli/src/plugin/interface/os.rs new file mode 100644 index 000000000..73295d930 --- /dev/null +++ b/packages/cli/src/plugin/interface/os.rs @@ -0,0 +1,18 @@ +use mlua::UserData; + +pub struct PluginOS; +impl UserData for PluginOS { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_function("current_platform", |_, ()| { + if cfg!(target_os = "windows") { + Ok("windows") + } else if cfg!(target_os = "macos") { + Ok("macos") + } else if cfg!(target_os = "linux") { + Ok("linux") + } else { + panic!("unsupported platformm"); + } + }); + } +} diff --git a/packages/cli/src/plugin/interface/path.rs b/packages/cli/src/plugin/interface/path.rs new file mode 100644 index 000000000..dcc9071b5 --- /dev/null +++ b/packages/cli/src/plugin/interface/path.rs @@ -0,0 +1,41 @@ +use std::path::PathBuf; + +use mlua::{UserData, Variadic}; + +pub struct PluginPath; +impl UserData for PluginPath { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + // join function + methods.add_function("join", |_, args: Variadic| { + let mut path = PathBuf::new(); + for i in args { + path = path.join(i); + } + Ok(path.to_str().unwrap().to_string()) + }); + + // parent function + methods.add_function("parent", |_, path: String| { + let current_path = PathBuf::from(&path); + let parent = current_path.parent(); + + if let Some(parent) = parent { + Ok(parent.to_str().unwrap().to_string()) + } else { + Ok(path) + } + }); + methods.add_function("exists", |_, path: String| { + let path = PathBuf::from(path); + Ok(path.exists()) + }); + methods.add_function("is_dir", |_, path: String| { + let path = PathBuf::from(path); + Ok(path.is_dir()) + }); + methods.add_function("is_file", |_, path: String| { + let path = PathBuf::from(path); + Ok(path.is_file()) + }); + } +} diff --git a/packages/cli/src/plugin/mod.rs b/packages/cli/src/plugin/mod.rs new file mode 100644 index 000000000..481dd0984 --- /dev/null +++ b/packages/cli/src/plugin/mod.rs @@ -0,0 +1,331 @@ +use std::{ + io::{Read, Write}, + path::PathBuf, + sync::Mutex, +}; + +use mlua::{Lua, Table}; +use serde_json::json; + +use crate::{ + tools::{app_path, clone_repo}, + CrateConfig, +}; + +use self::{ + interface::{ + command::PluginCommander, dirs::PluginDirs, fs::PluginFileSystem, log::PluginLogger, + network::PluginNetwork, os::PluginOS, path::PluginPath, PluginInfo, + }, + types::PluginConfig, +}; + +pub mod interface; +mod types; + +lazy_static::lazy_static! { + static ref LUA: Mutex = Mutex::new(Lua::new()); +} + +pub struct PluginManager; + +impl PluginManager { + pub fn init(config: toml::Value) -> anyhow::Result<()> { + let config = PluginConfig::from_toml_value(config); + + if !config.available { + return Ok(()); + } + + let lua = LUA.lock().unwrap(); + + let manager = lua.create_table().unwrap(); + let name_index = lua.create_table().unwrap(); + + let plugin_dir = Self::init_plugin_dir(); + + let api = lua.create_table().unwrap(); + + api.set("log", PluginLogger).unwrap(); + api.set("command", PluginCommander).unwrap(); + api.set("network", PluginNetwork).unwrap(); + api.set("dirs", PluginDirs).unwrap(); + api.set("fs", PluginFileSystem).unwrap(); + api.set("path", PluginPath).unwrap(); + api.set("os", PluginOS).unwrap(); + + lua.globals().set("plugin_lib", api).unwrap(); + lua.globals() + .set("library_dir", plugin_dir.to_str().unwrap()) + .unwrap(); + lua.globals().set("config_info", config.clone())?; + + let mut index: u32 = 1; + let dirs = std::fs::read_dir(&plugin_dir)?; + + let mut path_list = dirs + .filter(|v| v.is_ok()) + .map(|v| (v.unwrap().path(), false)) + .collect::>(); + for i in &config.loader { + let path = PathBuf::from(i); + if !path.is_dir() { + // for loader dir, we need check first, because we need give a error log. + log::error!("Plugin loader: {:?} path is not a exists directory.", path); + } + path_list.push((path, true)); + } + + for entry in path_list { + let plugin_dir = entry.0.to_path_buf(); + + if plugin_dir.is_dir() { + let init_file = plugin_dir.join("init.lua"); + if init_file.is_file() { + let mut file = std::fs::File::open(init_file).unwrap(); + let mut buffer = String::new(); + file.read_to_string(&mut buffer).unwrap(); + + let current_plugin_dir = plugin_dir.to_str().unwrap().to_string(); + let from_loader = entry.1; + + lua.globals() + .set("_temp_plugin_dir", current_plugin_dir.clone())?; + lua.globals().set("_temp_from_loader", from_loader)?; + + let info = lua.load(&buffer).eval::(); + match info { + Ok(mut info) => { + if name_index.contains_key(info.name.clone()).unwrap_or(false) + && !from_loader + { + // found same name plugin, intercept load + log::warn!( + "Plugin {} has been intercepted. [mulit-load]", + info.name + ); + continue; + } + info.inner.plugin_dir = current_plugin_dir; + info.inner.from_loader = from_loader; + + // call `on_init` if file "dcp.json" not exists + let dcp_file = plugin_dir.join("dcp.json"); + if !dcp_file.is_file() { + if let Some(func) = info.clone().on_init { + let result = func.call::<_, bool>(()); + match result { + Ok(true) => { + // plugin init success, create `dcp.json` file. + let mut file = std::fs::File::create(dcp_file).unwrap(); + let value = json!({ + "name": info.name, + "author": info.author, + "repository": info.repository, + "version": info.version, + "generate_time": chrono::Local::now().timestamp(), + }); + let buffer = + serde_json::to_string_pretty(&value).unwrap(); + let buffer = buffer.as_bytes(); + file.write_all(buffer).unwrap(); + + // insert plugin-info into plugin-manager + if let Ok(index) = + name_index.get::<_, u32>(info.name.clone()) + { + let _ = manager.set(index, info.clone()); + } else { + let _ = manager.set(index, info.clone()); + index += 1; + let _ = name_index.set(info.name, index); + } + } + Ok(false) => { + log::warn!( + "Plugin init function result is `false`, init failed." + ); + } + Err(e) => { + log::warn!("Plugin init failed: {e}"); + } + } + } + } else if let Ok(index) = name_index.get::<_, u32>(info.name.clone()) { + let _ = manager.set(index, info.clone()); + } else { + let _ = manager.set(index, info.clone()); + index += 1; + let _ = name_index.set(info.name, index); + } + } + Err(_e) => { + let dir_name = plugin_dir.file_name().unwrap().to_str().unwrap(); + log::error!("Plugin '{dir_name}' load failed."); + } + } + } + } + } + + lua.globals().set("manager", manager).unwrap(); + + Ok(()) + } + + pub fn on_build_start(crate_config: &CrateConfig, platform: &str) -> anyhow::Result<()> { + let lua = LUA.lock().unwrap(); + + if !lua.globals().contains_key("manager")? { + return Ok(()); + } + let manager = lua.globals().get::<_, Table>("manager")?; + + let args = lua.create_table()?; + args.set("name", crate_config.dioxus_config.application.name.clone())?; + args.set("platform", platform)?; + args.set("out_dir", crate_config.out_dir.to_str().unwrap())?; + args.set("asset_dir", crate_config.asset_dir.to_str().unwrap())?; + + for i in 1..(manager.len()? as i32 + 1) { + let info = manager.get::(i)?; + if let Some(func) = info.build.on_start { + func.call::(args.clone())?; + } + } + + Ok(()) + } + + pub fn on_build_finish(crate_config: &CrateConfig, platform: &str) -> anyhow::Result<()> { + let lua = LUA.lock().unwrap(); + + if !lua.globals().contains_key("manager")? { + return Ok(()); + } + let manager = lua.globals().get::<_, Table>("manager")?; + + let args = lua.create_table()?; + args.set("name", crate_config.dioxus_config.application.name.clone())?; + args.set("platform", platform)?; + args.set("out_dir", crate_config.out_dir.to_str().unwrap())?; + args.set("asset_dir", crate_config.asset_dir.to_str().unwrap())?; + + for i in 1..(manager.len()? as i32 + 1) { + let info = manager.get::(i)?; + if let Some(func) = info.build.on_finish { + func.call::(args.clone())?; + } + } + + Ok(()) + } + + pub fn on_serve_start(crate_config: &CrateConfig) -> anyhow::Result<()> { + let lua = LUA.lock().unwrap(); + + if !lua.globals().contains_key("manager")? { + return Ok(()); + } + let manager = lua.globals().get::<_, Table>("manager")?; + + let args = lua.create_table()?; + args.set("name", crate_config.dioxus_config.application.name.clone())?; + + for i in 1..(manager.len()? as i32 + 1) { + let info = manager.get::(i)?; + if let Some(func) = info.serve.on_start { + func.call::(args.clone())?; + } + } + + Ok(()) + } + + pub fn on_serve_rebuild(timestamp: i64, files: Vec) -> anyhow::Result<()> { + let lua = LUA.lock().unwrap(); + + let manager = lua.globals().get::<_, Table>("manager")?; + + let args = lua.create_table()?; + args.set("timestamp", timestamp)?; + let files: Vec = files + .iter() + .map(|v| v.to_str().unwrap().to_string()) + .collect(); + args.set("changed_files", files)?; + + for i in 1..(manager.len()? as i32 + 1) { + let info = manager.get::(i)?; + if let Some(func) = info.serve.on_rebuild { + func.call::(args.clone())?; + } + } + + Ok(()) + } + + pub fn on_serve_shutdown(crate_config: &CrateConfig) -> anyhow::Result<()> { + let lua = LUA.lock().unwrap(); + + if !lua.globals().contains_key("manager")? { + return Ok(()); + } + let manager = lua.globals().get::<_, Table>("manager")?; + + let args = lua.create_table()?; + args.set("name", crate_config.dioxus_config.application.name.clone())?; + + for i in 1..(manager.len()? as i32 + 1) { + let info = manager.get::(i)?; + if let Some(func) = info.serve.on_shutdown { + func.call::(args.clone())?; + } + } + + Ok(()) + } + + pub fn init_plugin_dir() -> PathBuf { + let app_path = app_path(); + let plugin_path = app_path.join("plugins"); + if !plugin_path.is_dir() { + log::info!("📖 Start to init plugin library ..."); + let url = "https://github.com/DioxusLabs/cli-plugin-library"; + if let Err(err) = clone_repo(&plugin_path, url) { + log::error!("Failed to init plugin dir, error caused by {}. ", err); + } + } + plugin_path + } + + pub fn plugin_list() -> Vec { + let mut res = vec![]; + + if let Ok(lua) = LUA.lock() { + let list = lua + .load(mlua::chunk!( + local list = {} + for key, value in ipairs(manager) do + table.insert(list, {name = value.name, loader = value.inner.from_loader}) + end + return list + )) + .eval::>() + .unwrap_or_default(); + for i in list { + let name = i.get::<_, String>("name").unwrap(); + let loader = i.get::<_, bool>("loader").unwrap(); + + let text = if loader { + format!("{name} [:loader]") + } else { + name + }; + res.push(text); + } + } + + res + } +} diff --git a/packages/cli/src/plugin/types.rs b/packages/cli/src/plugin/types.rs new file mode 100644 index 000000000..d22c1423c --- /dev/null +++ b/packages/cli/src/plugin/types.rs @@ -0,0 +1,138 @@ +use std::collections::HashMap; + +use mlua::ToLua; + +#[derive(Debug, Clone)] +pub struct PluginConfig { + pub available: bool, + pub loader: Vec, + pub config_info: HashMap>, +} + +impl<'lua> ToLua<'lua> for PluginConfig { + fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { + let table = lua.create_table()?; + + table.set("available", self.available)?; + table.set("loader", self.loader)?; + + let config_info = lua.create_table()?; + + for (name, data) in self.config_info { + config_info.set(name, data)?; + } + + table.set("config_info", config_info)?; + + Ok(mlua::Value::Table(table)) + } +} + +impl PluginConfig { + pub fn from_toml_value(val: toml::Value) -> Self { + if let toml::Value::Table(tab) = val { + let available = tab + .get::<_>("available") + .unwrap_or(&toml::Value::Boolean(true)); + let available = available.as_bool().unwrap_or(true); + + let mut loader = vec![]; + if let Some(origin) = tab.get("loader") { + if origin.is_array() { + for i in origin.as_array().unwrap() { + loader.push(i.as_str().unwrap_or_default().to_string()); + } + } + } + + let mut config_info = HashMap::new(); + + for (name, value) in tab { + if name == "available" || name == "loader" { + continue; + } + if let toml::Value::Table(value) = value { + let mut map = HashMap::new(); + for (item, info) in value { + map.insert(item, Value::from_toml(info)); + } + config_info.insert(name, map); + } + } + + Self { + available, + loader, + config_info, + } + } else { + Self { + available: false, + loader: vec![], + config_info: HashMap::new(), + } + } + } +} + +#[allow(dead_code)] +#[derive(Debug, Clone)] +pub enum Value { + String(String), + Integer(i64), + Float(f64), + Boolean(bool), + Array(Vec), + Table(HashMap), +} + +impl Value { + pub fn from_toml(origin: toml::Value) -> Self { + match origin { + cargo_toml::Value::String(s) => Value::String(s), + cargo_toml::Value::Integer(i) => Value::Integer(i), + cargo_toml::Value::Float(f) => Value::Float(f), + cargo_toml::Value::Boolean(b) => Value::Boolean(b), + cargo_toml::Value::Datetime(d) => Value::String(d.to_string()), + cargo_toml::Value::Array(a) => { + let mut v = vec![]; + for i in a { + v.push(Value::from_toml(i)); + } + Value::Array(v) + } + cargo_toml::Value::Table(t) => { + let mut h = HashMap::new(); + for (n, v) in t { + h.insert(n, Value::from_toml(v)); + } + Value::Table(h) + } + } + } +} + +impl<'lua> ToLua<'lua> for Value { + fn to_lua(self, lua: &'lua mlua::Lua) -> mlua::Result> { + Ok(match self { + Value::String(s) => mlua::Value::String(lua.create_string(&s)?), + Value::Integer(i) => mlua::Value::Integer(i), + Value::Float(f) => mlua::Value::Number(f), + Value::Boolean(b) => mlua::Value::Boolean(b), + Value::Array(a) => { + let table = lua.create_table()?; + for (i, v) in a.iter().enumerate() { + table.set(i, v.clone())?; + } + mlua::Value::Table(table) + } + Value::Table(t) => { + let table = lua.create_table()?; + for (i, v) in t.iter() { + table.set(i.clone(), v.clone())?; + } + mlua::Value::Table(table) + } + }) + } +} diff --git a/packages/cli/src/server/mod.rs b/packages/cli/src/server/mod.rs new file mode 100644 index 000000000..e7c62db82 --- /dev/null +++ b/packages/cli/src/server/mod.rs @@ -0,0 +1,752 @@ +use crate::{builder, plugin::PluginManager, serve::Serve, BuildResult, CrateConfig, Result}; +use axum::{ + body::{Full, HttpBody}, + extract::{ws::Message, Extension, TypedHeader, WebSocketUpgrade}, + http::{ + header::{HeaderName, HeaderValue}, + Method, Response, StatusCode, + }, + response::IntoResponse, + routing::{get, get_service}, + Router, +}; +use cargo_metadata::diagnostic::Diagnostic; +use colored::Colorize; +use dioxus_core::Template; +use dioxus_html::HtmlCtx; +use dioxus_rsx::hot_reload::*; +use notify::{RecommendedWatcher, Watcher}; +use std::{ + net::UdpSocket, + path::PathBuf, + process::Command, + sync::{Arc, Mutex}, +}; +use tokio::sync::broadcast; +use tower::ServiceBuilder; +use tower_http::services::fs::{ServeDir, ServeFileSystemResponseBody}; +use tower_http::{ + cors::{Any, CorsLayer}, + ServiceBuilderExt, +}; +mod proxy; + +pub struct BuildManager { + config: CrateConfig, + reload_tx: broadcast::Sender<()>, +} + +impl BuildManager { + fn rebuild(&self) -> Result { + log::info!("🪁 Rebuild project"); + let result = builder::build(&self.config, true)?; + // change the websocket reload state to true; + // the page will auto-reload. + if self + .config + .dioxus_config + .web + .watcher + .reload_html + .unwrap_or(false) + { + let _ = Serve::regen_dev_page(&self.config); + } + let _ = self.reload_tx.send(()); + Ok(result) + } +} + +struct WsReloadState { + update: broadcast::Sender<()>, +} + +pub async fn startup(port: u16, config: CrateConfig, start_browser: bool) -> Result<()> { + // ctrl-c shutdown checker + let crate_config = config.clone(); + let _ = ctrlc::set_handler(move || { + let _ = PluginManager::on_serve_shutdown(&crate_config); + std::process::exit(0); + }); + + let ip = get_ip().unwrap_or(String::from("0.0.0.0")); + + if config.hot_reload { + startup_hot_reload(ip, port, config, start_browser).await? + } else { + startup_default(ip, port, config, start_browser).await? + } + Ok(()) +} + +pub struct HotReloadState { + pub messages: broadcast::Sender>, + pub build_manager: Arc, + pub file_map: Arc>>, + pub watcher_config: CrateConfig, +} + +pub async fn hot_reload_handler( + ws: WebSocketUpgrade, + _: Option>, + Extension(state): Extension>, +) -> impl IntoResponse { + ws.on_upgrade(|mut socket| async move { + log::info!("🔥 Hot Reload WebSocket connected"); + { + // update any rsx calls that changed before the websocket connected. + { + log::info!("🔮 Finding updates since last compile..."); + let templates: Vec<_> = { + state + .file_map + .lock() + .unwrap() + .map + .values() + .filter_map(|(_, template_slot)| *template_slot) + .collect() + }; + for template in templates { + if socket + .send(Message::Text(serde_json::to_string(&template).unwrap())) + .await + .is_err() + { + return; + } + } + } + log::info!("finished"); + } + + let mut rx = state.messages.subscribe(); + loop { + if let Ok(rsx) = rx.recv().await { + if socket + .send(Message::Text(serde_json::to_string(&rsx).unwrap())) + .await + .is_err() + { + break; + }; + } + } + }) +} + +#[allow(unused_assignments)] +pub async fn startup_hot_reload( + ip: String, + port: u16, + config: CrateConfig, + start_browser: bool, +) -> Result<()> { + let first_build_result = crate::builder::build(&config, false)?; + + log::info!("🚀 Starting development server..."); + + PluginManager::on_serve_start(&config)?; + + let dist_path = config.out_dir.clone(); + let (reload_tx, _) = broadcast::channel(100); + let FileMapBuildResult { map, errors } = + FileMap::::create(config.crate_dir.clone()).unwrap(); + for err in errors { + log::error!("{}", err); + } + let file_map = Arc::new(Mutex::new(map)); + let build_manager = Arc::new(BuildManager { + config: config.clone(), + reload_tx: reload_tx.clone(), + }); + let hot_reload_tx = broadcast::channel(100).0; + let hot_reload_state = Arc::new(HotReloadState { + messages: hot_reload_tx.clone(), + build_manager: build_manager.clone(), + file_map: file_map.clone(), + watcher_config: config.clone(), + }); + + let crate_dir = config.crate_dir.clone(); + let ws_reload_state = Arc::new(WsReloadState { + update: reload_tx.clone(), + }); + + // file watcher: check file change + let allow_watch_path = config + .dioxus_config + .web + .watcher + .watch_path + .clone() + .unwrap_or_else(|| vec![PathBuf::from("src")]); + + let watcher_config = config.clone(); + let watcher_ip = ip.clone(); + let mut last_update_time = chrono::Local::now().timestamp(); + + let mut watcher = RecommendedWatcher::new( + move |evt: notify::Result| { + let config = watcher_config.clone(); + // Give time for the change to take effect before reading the file + std::thread::sleep(std::time::Duration::from_millis(100)); + if chrono::Local::now().timestamp() > last_update_time { + if let Ok(evt) = evt { + let mut messages: Vec> = Vec::new(); + for path in evt.paths.clone() { + // if this is not a rust file, rebuild the whole project + if path.extension().and_then(|p| p.to_str()) != Some("rs") { + match build_manager.rebuild() { + Ok(res) => { + print_console_info( + &watcher_ip, + port, + &config, + PrettierOptions { + changed: evt.paths, + warnings: res.warnings, + elapsed_time: res.elapsed_time, + }, + ); + } + Err(err) => { + log::error!("{}", err); + } + } + return; + } + // find changes to the rsx in the file + let mut map = file_map.lock().unwrap(); + + match map.update_rsx(&path, &crate_dir) { + Ok(UpdateResult::UpdatedRsx(msgs)) => { + messages.extend(msgs); + } + Ok(UpdateResult::NeedsRebuild) => { + match build_manager.rebuild() { + Ok(res) => { + print_console_info( + &watcher_ip, + port, + &config, + PrettierOptions { + changed: evt.paths, + warnings: res.warnings, + elapsed_time: res.elapsed_time, + }, + ); + } + Err(err) => { + log::error!("{}", err); + } + } + return; + } + Err(err) => { + log::error!("{}", err); + } + } + } + for msg in messages { + let _ = hot_reload_tx.send(msg); + } + } + last_update_time = chrono::Local::now().timestamp(); + } + }, + notify::Config::default(), + ) + .unwrap(); + + for sub_path in allow_watch_path { + if let Err(err) = watcher.watch( + &config.crate_dir.join(&sub_path), + notify::RecursiveMode::Recursive, + ) { + log::error!("error watching {sub_path:?}: \n{}", err); + } + } + + // start serve dev-server at 0.0.0.0:8080 + print_console_info( + &ip, + port, + &config, + PrettierOptions { + changed: vec![], + warnings: first_build_result.warnings, + elapsed_time: first_build_result.elapsed_time, + }, + ); + + let cors = CorsLayer::new() + // allow `GET` and `POST` when accessing the resource + .allow_methods([Method::GET, Method::POST]) + // allow requests from any origin + .allow_origin(Any) + .allow_headers(Any); + + let (coep, coop) = if config.cross_origin_policy { + ( + HeaderValue::from_static("require-corp"), + HeaderValue::from_static("same-origin"), + ) + } else { + ( + HeaderValue::from_static("unsafe-none"), + HeaderValue::from_static("unsafe-none"), + ) + }; + + let file_service_config = config.clone(); + let file_service = ServiceBuilder::new() + .override_response_header( + HeaderName::from_static("cross-origin-embedder-policy"), + coep, + ) + .override_response_header(HeaderName::from_static("cross-origin-opener-policy"), coop) + .and_then( + move |response: Response| async move { + let response = if file_service_config + .dioxus_config + .web + .watcher + .index_on_404 + .unwrap_or(false) + && response.status() == StatusCode::NOT_FOUND + { + let body = Full::from( + // TODO: Cache/memoize this. + std::fs::read_to_string( + file_service_config + .crate_dir + .join(file_service_config.out_dir) + .join("index.html"), + ) + .ok() + .unwrap(), + ) + .map_err(|err| match err {}) + .boxed(); + Response::builder() + .status(StatusCode::OK) + .body(body) + .unwrap() + } else { + response.map(|body| body.boxed()) + }; + Ok(response) + }, + ) + .service(ServeDir::new(config.crate_dir.join(&dist_path))); + + let mut router = Router::new().route("/_dioxus/ws", get(ws_handler)); + for proxy_config in config.dioxus_config.web.proxy.unwrap_or_default() { + router = proxy::add_proxy(router, &proxy_config)?; + } + router = router.fallback(get_service(file_service).handle_error( + |error: std::io::Error| async move { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Unhandled internal error: {}", error), + ) + }, + )); + + let router = router + .route("/_dioxus/hot_reload", get(hot_reload_handler)) + .layer(cors) + .layer(Extension(ws_reload_state)) + .layer(Extension(hot_reload_state)); + + let addr = format!("0.0.0.0:{}", port).parse().unwrap(); + + let server = axum::Server::bind(&addr).serve(router.into_make_service()); + + if start_browser { + let _ = open::that(format!("http://{}", addr)); + } + + server.await?; + + Ok(()) +} + +pub async fn startup_default( + ip: String, + port: u16, + config: CrateConfig, + start_browser: bool, +) -> Result<()> { + let first_build_result = crate::builder::build(&config, false)?; + + log::info!("🚀 Starting development server..."); + + let dist_path = config.out_dir.clone(); + + let (reload_tx, _) = broadcast::channel(100); + + let build_manager = BuildManager { + config: config.clone(), + reload_tx: reload_tx.clone(), + }; + + let ws_reload_state = Arc::new(WsReloadState { + update: reload_tx.clone(), + }); + + let mut last_update_time = chrono::Local::now().timestamp(); + + // file watcher: check file change + let allow_watch_path = config + .dioxus_config + .web + .watcher + .watch_path + .clone() + .unwrap_or_else(|| vec![PathBuf::from("src")]); + + let watcher_config = config.clone(); + let watcher_ip = ip.clone(); + let mut watcher = notify::recommended_watcher(move |info: notify::Result| { + let config = watcher_config.clone(); + if let Ok(e) = info { + if chrono::Local::now().timestamp() > last_update_time { + match build_manager.rebuild() { + Ok(res) => { + last_update_time = chrono::Local::now().timestamp(); + print_console_info( + &watcher_ip, + port, + &config, + PrettierOptions { + changed: e.paths.clone(), + warnings: res.warnings, + elapsed_time: res.elapsed_time, + }, + ); + let _ = PluginManager::on_serve_rebuild( + chrono::Local::now().timestamp(), + e.paths, + ); + } + Err(e) => log::error!("{}", e), + } + } + } + }) + .unwrap(); + + for sub_path in allow_watch_path { + watcher + .watch( + &config.crate_dir.join(sub_path), + notify::RecursiveMode::Recursive, + ) + .unwrap(); + } + + // start serve dev-server at 0.0.0.0 + print_console_info( + &ip, + port, + &config, + PrettierOptions { + changed: vec![], + warnings: first_build_result.warnings, + elapsed_time: first_build_result.elapsed_time, + }, + ); + + PluginManager::on_serve_start(&config)?; + + let cors = CorsLayer::new() + // allow `GET` and `POST` when accessing the resource + .allow_methods([Method::GET, Method::POST]) + // allow requests from any origin + .allow_origin(Any) + .allow_headers(Any); + + let (coep, coop) = if config.cross_origin_policy { + ( + HeaderValue::from_static("require-corp"), + HeaderValue::from_static("same-origin"), + ) + } else { + ( + HeaderValue::from_static("unsafe-none"), + HeaderValue::from_static("unsafe-none"), + ) + }; + + let file_service_config = config.clone(); + let file_service = ServiceBuilder::new() + .override_response_header( + HeaderName::from_static("cross-origin-embedder-policy"), + coep, + ) + .override_response_header(HeaderName::from_static("cross-origin-opener-policy"), coop) + .and_then( + move |response: Response| async move { + let response = if file_service_config + .dioxus_config + .web + .watcher + .index_on_404 + .unwrap_or(false) + && response.status() == StatusCode::NOT_FOUND + { + let body = Full::from( + // TODO: Cache/memoize this. + std::fs::read_to_string( + file_service_config + .crate_dir + .join(file_service_config.out_dir) + .join("index.html"), + ) + .ok() + .unwrap(), + ) + .map_err(|err| match err {}) + .boxed(); + Response::builder() + .status(StatusCode::OK) + .body(body) + .unwrap() + } else { + response.map(|body| body.boxed()) + }; + Ok(response) + }, + ) + .service(ServeDir::new(config.crate_dir.join(&dist_path))); + + let mut router = Router::new().route("/_dioxus/ws", get(ws_handler)); + for proxy_config in config.dioxus_config.web.proxy.unwrap_or_default() { + router = proxy::add_proxy(router, &proxy_config)?; + } + router = router + .fallback( + get_service(file_service).handle_error(|error: std::io::Error| async move { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Unhandled internal error: {}", error), + ) + }), + ) + .layer(cors) + .layer(Extension(ws_reload_state)); + + let addr = format!("0.0.0.0:{}", port).parse().unwrap(); + let server = axum::Server::bind(&addr).serve(router.into_make_service()); + + if start_browser { + let _ = open::that(format!("http://{}", addr)); + } + + server.await?; + + Ok(()) +} + +#[derive(Debug, Default)] +pub struct PrettierOptions { + changed: Vec, + warnings: Vec, + elapsed_time: u128, +} + +fn print_console_info(ip: &String, port: u16, config: &CrateConfig, options: PrettierOptions) { + if let Ok(native_clearseq) = Command::new(if cfg!(target_os = "windows") { + "cls" + } else { + "clear" + }) + .output() + { + print!("{}", String::from_utf8_lossy(&native_clearseq.stdout)); + } else { + // Try ANSI-Escape characters + print!("\x1b[2J\x1b[H"); + } + + // for path in &changed { + // let path = path + // .strip_prefix(crate::crate_root().unwrap()) + // .unwrap() + // .to_path_buf(); + // log::info!("Updated {}", format!("{}", path.to_str().unwrap()).green()); + // } + + let mut profile = if config.release { "Release" } else { "Debug" }.to_string(); + if config.custom_profile.is_some() { + profile = config.custom_profile.as_ref().unwrap().to_string(); + } + let hot_reload = if config.hot_reload { "RSX" } else { "Normal" }; + let crate_root = crate::cargo::crate_root().unwrap(); + let custom_html_file = if crate_root.join("index.html").is_file() { + "Custom [index.html]" + } else { + "Default" + }; + let url_rewrite = if config + .dioxus_config + .web + .watcher + .index_on_404 + .unwrap_or(false) + { + "True" + } else { + "False" + }; + + let proxies = config.dioxus_config.web.proxy.as_ref(); + + if options.changed.is_empty() { + println!( + "{} @ v{} [{}] \n", + "Dioxus".bold().green(), + crate::DIOXUS_CLI_VERSION, + chrono::Local::now().format("%H:%M:%S").to_string().dimmed() + ); + } else { + println!( + "Project Reloaded: {}\n", + format!( + "Changed {} files. [{}]", + options.changed.len(), + chrono::Local::now().format("%H:%M:%S").to_string().dimmed() + ) + .purple() + .bold() + ); + } + println!( + "\t> Local : {}", + format!("http://localhost:{}/", port).blue() + ); + println!( + "\t> Network : {}", + format!("http://{}:{}/", ip, port).blue() + ); + println!(); + println!("\t> Profile : {}", profile.green()); + println!("\t> Hot Reload : {}", hot_reload.cyan()); + if let Some(proxies) = proxies { + if !proxies.is_empty() { + println!("\t> Proxies :"); + for proxy in proxies { + println!("\t\t- {}", proxy.backend.blue()); + } + } + } + println!("\t> Index Template : {}", custom_html_file.green()); + println!("\t> URL Rewrite [index_on_404] : {}", url_rewrite.purple()); + println!(); + println!( + "\t> Build Time Use : {} millis", + options.elapsed_time.to_string().green().bold() + ); + println!(); + + if options.warnings.is_empty() { + log::info!("{}\n", "A perfect compilation!".green().bold()); + } else { + log::warn!( + "{}", + format!( + "There were {} warning messages during the build.", + options.warnings.len() - 1 + ) + .yellow() + .bold() + ); + // for info in &options.warnings { + // let message = info.message.clone(); + // if message == format!("{} warnings emitted", options.warnings.len() - 1) { + // continue; + // } + // let mut console = String::new(); + // for span in &info.spans { + // let file = &span.file_name; + // let line = (span.line_start, span.line_end); + // let line_str = if line.0 == line.1 { + // line.0.to_string() + // } else { + // format!("{}~{}", line.0, line.1) + // }; + // let code = span.text.clone(); + // let span_info = if code.len() == 1 { + // let code = code.get(0).unwrap().text.trim().blue().bold().to_string(); + // format!( + // "[{}: {}]: '{}' --> {}", + // file, + // line_str, + // code, + // message.yellow().bold() + // ) + // } else { + // let code = code + // .iter() + // .enumerate() + // .map(|(_i, s)| format!("\t{}\n", s.text).blue().bold().to_string()) + // .collect::(); + // format!("[{}: {}]:\n{}\n#:{}", file, line_str, code, message) + // }; + // console = format!("{console}\n\t{span_info}"); + // } + // println!("{console}"); + // } + // println!( + // "\n{}\n", + // "Resolving all warnings will help your code run better!".yellow() + // ); + } +} + +fn get_ip() -> Option { + let socket = match UdpSocket::bind("0.0.0.0:0") { + Ok(s) => s, + Err(_) => return None, + }; + + match socket.connect("8.8.8.8:80") { + Ok(()) => (), + Err(_) => return None, + }; + + match socket.local_addr() { + Ok(addr) => Some(addr.ip().to_string()), + Err(_) => None, + } +} + +async fn ws_handler( + ws: WebSocketUpgrade, + _: Option>, + Extension(state): Extension>, +) -> impl IntoResponse { + ws.on_upgrade(|mut socket| async move { + let mut rx = state.update.subscribe(); + let reload_watcher = tokio::spawn(async move { + loop { + rx.recv().await.unwrap(); + // ignore the error + if socket + .send(Message::Text(String::from("reload"))) + .await + .is_err() + { + break; + } + + // flush the errors after recompling + rx = rx.resubscribe(); + } + }); + + reload_watcher.await.unwrap(); + }) +} diff --git a/packages/cli/src/server/proxy.rs b/packages/cli/src/server/proxy.rs new file mode 100644 index 000000000..8de65f4db --- /dev/null +++ b/packages/cli/src/server/proxy.rs @@ -0,0 +1,171 @@ +use crate::{Result, WebProxyConfig}; + +use anyhow::Context; +use axum::{http::StatusCode, routing::any, Router}; +use hyper::{Request, Response, Uri}; + +#[derive(Debug, Clone)] +struct ProxyClient { + inner: hyper::Client>, + url: Uri, +} + +impl ProxyClient { + fn new(url: Uri) -> Self { + let https = hyper_rustls::HttpsConnectorBuilder::new() + .with_native_roots() + .https_or_http() + .enable_http1() + .build(); + Self { + inner: hyper::Client::builder().build(https), + url, + } + } + + async fn send( + &self, + mut req: Request, + ) -> Result> { + let mut uri_parts = req.uri().clone().into_parts(); + uri_parts.authority = self.url.authority().cloned(); + uri_parts.scheme = self.url.scheme().cloned(); + *req.uri_mut() = Uri::from_parts(uri_parts).context("Invalid URI parts")?; + self.inner + .request(req) + .await + .map_err(crate::error::Error::ProxyRequestError) + } +} + +/// Add routes to the router handling the specified proxy config. +/// +/// We will proxy requests directed at either: +/// +/// - the exact path of the proxy config's backend URL, e.g. /api +/// - the exact path with a trailing slash, e.g. /api/ +/// - any subpath of the backend URL, e.g. /api/foo/bar +pub fn add_proxy(mut router: Router, proxy: &WebProxyConfig) -> Result { + let url: Uri = proxy.backend.parse()?; + let path = url.path().to_string(); + let client = ProxyClient::new(url); + + // We also match everything after the path using a wildcard matcher. + let wildcard_client = client.clone(); + + router = router.route( + // Always remove trailing /'s so that the exact route + // matches. + path.trim_end_matches('/'), + any(move |req| async move { + client + .send(req) + .await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) + }), + ); + + // Wildcard match anything else _after_ the backend URL's path. + // Note that we know `path` ends with a trailing `/` in this branch, + // so `wildcard` will look like `http://localhost/api/*proxywildcard`. + let wildcard = format!("{}/*proxywildcard", path.trim_end_matches('/')); + router = router.route( + &wildcard, + any(move |req| async move { + wildcard_client + .send(req) + .await + .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) + }), + ); + Ok(router) +} + +#[cfg(test)] +mod test { + + use super::*; + + use axum::{extract::Path, Router}; + + fn setup_servers( + mut config: WebProxyConfig, + ) -> ( + tokio::task::JoinHandle<()>, + tokio::task::JoinHandle<()>, + String, + ) { + let backend_router = Router::new().route( + "/*path", + any(|path: Path| async move { format!("backend: {}", path.0) }), + ); + let backend_server = axum::Server::bind(&"127.0.0.1:0".parse().unwrap()) + .serve(backend_router.into_make_service()); + let backend_addr = backend_server.local_addr(); + let backend_handle = tokio::spawn(async move { backend_server.await.unwrap() }); + config.backend = format!("http://{}{}", backend_addr, config.backend); + let router = super::add_proxy(Router::new(), &config); + let server = axum::Server::bind(&"127.0.0.1:0".parse().unwrap()) + .serve(router.unwrap().into_make_service()); + let server_addr = server.local_addr(); + let server_handle = tokio::spawn(async move { server.await.unwrap() }); + (backend_handle, server_handle, server_addr.to_string()) + } + + async fn test_proxy_requests(path: String) { + let config = WebProxyConfig { + // Normally this would be an absolute URL including scheme/host/port, + // but in these tests we need to let the OS choose the port so tests + // don't conflict, so we'll concatenate the final address and this + // path together. + // So in day to day usage, use `http://localhost:8000/api` instead! + backend: path, + }; + let (backend_handle, server_handle, server_addr) = setup_servers(config); + let resp = hyper::Client::new() + .get(format!("http://{}/api", server_addr).parse().unwrap()) + .await + .unwrap(); + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!( + hyper::body::to_bytes(resp.into_body()).await.unwrap(), + "backend: /api" + ); + + let resp = hyper::Client::new() + .get(format!("http://{}/api/", server_addr).parse().unwrap()) + .await + .unwrap(); + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!( + hyper::body::to_bytes(resp.into_body()).await.unwrap(), + "backend: /api/" + ); + + let resp = hyper::Client::new() + .get( + format!("http://{}/api/subpath", server_addr) + .parse() + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(resp.status(), StatusCode::OK); + assert_eq!( + hyper::body::to_bytes(resp.into_body()).await.unwrap(), + "backend: /api/subpath" + ); + backend_handle.abort(); + server_handle.abort(); + } + + #[tokio::test] + async fn add_proxy() { + test_proxy_requests("/api".to_string()).await; + } + + #[tokio::test] + async fn add_proxy_trailing_slash() { + test_proxy_requests("/api/".to_string()).await; + } +} diff --git a/packages/cli/src/tools.rs b/packages/cli/src/tools.rs new file mode 100644 index 000000000..98d4f9dbe --- /dev/null +++ b/packages/cli/src/tools.rs @@ -0,0 +1,349 @@ +use std::{ + fs::{create_dir_all, File}, + io::{ErrorKind, Read, Write}, + path::{Path, PathBuf}, + process::Command, +}; + +use anyhow::Context; +use flate2::read::GzDecoder; +use futures::StreamExt; +use tar::Archive; +use tokio::io::AsyncWriteExt; + +#[derive(Debug, PartialEq, Eq)] +pub enum Tool { + Binaryen, + Sass, + Tailwind, +} + +// pub fn tool_list() -> Vec<&'static str> { +// vec!["binaryen", "sass", "tailwindcss"] +// } + +pub fn app_path() -> PathBuf { + let data_local = dirs::data_local_dir().unwrap(); + let dioxus_dir = data_local.join("dioxus"); + if !dioxus_dir.is_dir() { + create_dir_all(&dioxus_dir).unwrap(); + } + dioxus_dir +} + +pub fn temp_path() -> PathBuf { + let app_path = app_path(); + let temp_path = app_path.join("temp"); + if !temp_path.is_dir() { + create_dir_all(&temp_path).unwrap(); + } + temp_path +} + +pub fn clone_repo(dir: &Path, url: &str) -> anyhow::Result<()> { + let target_dir = dir.parent().unwrap(); + let dir_name = dir.file_name().unwrap(); + + let mut cmd = Command::new("git"); + let cmd = cmd.current_dir(target_dir); + let res = cmd.arg("clone").arg(url).arg(dir_name).output(); + if let Err(err) = res { + if ErrorKind::NotFound == err.kind() { + log::warn!("Git program not found. Hint: Install git or check $PATH."); + return Err(err.into()); + } + } + Ok(()) +} + +pub fn tools_path() -> PathBuf { + let app_path = app_path(); + let temp_path = app_path.join("tools"); + if !temp_path.is_dir() { + create_dir_all(&temp_path).unwrap(); + } + temp_path +} + +#[allow(clippy::should_implement_trait)] +impl Tool { + /// from str to tool enum + pub fn from_str(name: &str) -> Option { + match name { + "binaryen" => Some(Self::Binaryen), + "sass" => Some(Self::Sass), + "tailwindcss" => Some(Self::Tailwind), + _ => None, + } + } + + /// get current tool name str + pub fn name(&self) -> &str { + match self { + Self::Binaryen => "binaryen", + Self::Sass => "sass", + Self::Tailwind => "tailwindcss", + } + } + + /// get tool bin dir path + pub fn bin_path(&self) -> &str { + match self { + Self::Binaryen => "bin", + Self::Sass => ".", + Self::Tailwind => ".", + } + } + + /// get target platform + pub fn target_platform(&self) -> &str { + match self { + Self::Binaryen => { + if cfg!(target_os = "windows") { + "windows" + } else if cfg!(target_os = "macos") { + "macos" + } else if cfg!(target_os = "linux") { + "linux" + } else { + panic!("unsupported platformm"); + } + } + Self::Sass => { + if cfg!(target_os = "windows") { + "windows" + } else if cfg!(target_os = "macos") { + "macos" + } else if cfg!(target_os = "linux") { + "linux" + } else { + panic!("unsupported platformm"); + } + } + Self::Tailwind => { + if cfg!(target_os = "windows") { + "windows" + } else if cfg!(target_os = "macos") { + "macos" + } else if cfg!(target_os = "linux") { + "linux" + } else { + panic!("unsupported platformm"); + } + } + } + } + + /// get tool version + pub fn tool_version(&self) -> &str { + match self { + Self::Binaryen => "version_105", + Self::Sass => "1.51.0", + Self::Tailwind => "v3.1.6", + } + } + + /// get tool package download url + pub fn download_url(&self) -> String { + match self { + Self::Binaryen => { + format!( + "https://github.com/WebAssembly/binaryen/releases/download/{version}/binaryen-{version}-x86_64-{target}.tar.gz", + version = self.tool_version(), + target = self.target_platform() + ) + } + Self::Sass => { + format!( + "https://github.com/sass/dart-sass/releases/download/{version}/dart-sass-{version}-{target}-x64.{extension}", + version = self.tool_version(), + target = self.target_platform(), + extension = self.extension() + ) + } + Self::Tailwind => { + let windows_extension = match self.target_platform() { + "windows" => ".exe", + _ => "", + }; + format!( + "https://github.com/tailwindlabs/tailwindcss/releases/download/{version}/tailwindcss-{target}-x64{optional_ext}", + version = self.tool_version(), + target = self.target_platform(), + optional_ext = windows_extension + ) + } + } + } + + /// get package extension name + pub fn extension(&self) -> &str { + match self { + Self::Binaryen => "tar.gz", + Self::Sass => { + if cfg!(target_os = "windows") { + "zip" + } else { + "tar.gz" + } + } + Self::Tailwind => "bin", + } + } + + /// check tool state + pub fn is_installed(&self) -> bool { + tools_path().join(self.name()).is_dir() + } + + /// get download temp path + pub fn temp_out_path(&self) -> PathBuf { + temp_path().join(format!("{}-tool.tmp", self.name())) + } + + /// start to download package + pub async fn download_package(&self) -> anyhow::Result { + let download_url = self.download_url(); + let temp_out = self.temp_out_path(); + let mut file = tokio::fs::File::create(&temp_out) + .await + .context("failed creating temporary output file")?; + + let resp = reqwest::get(download_url).await.unwrap(); + + let mut res_bytes = resp.bytes_stream(); + while let Some(chunk_res) = res_bytes.next().await { + let chunk = chunk_res.context("error reading chunk from download")?; + let _ = file.write(chunk.as_ref()).await; + } + // log::info!("temp file path: {:?}", temp_out); + Ok(temp_out) + } + + /// start to install package + pub async fn install_package(&self) -> anyhow::Result<()> { + let temp_path = self.temp_out_path(); + let tool_path = tools_path(); + + let dir_name = match self { + Self::Binaryen => format!("binaryen-{}", self.tool_version()), + Self::Sass => "dart-sass".to_string(), + Self::Tailwind => self.name().to_string(), + }; + + if self.extension() == "tar.gz" { + let tar_gz = File::open(temp_path)?; + let tar = GzDecoder::new(tar_gz); + let mut archive = Archive::new(tar); + archive.unpack(&tool_path)?; + std::fs::rename(tool_path.join(dir_name), tool_path.join(self.name()))?; + } else if self.extension() == "zip" { + // decompress the `zip` file + extract_zip(&temp_path, &tool_path)?; + std::fs::rename(tool_path.join(dir_name), tool_path.join(self.name()))?; + } else if self.extension() == "bin" { + let bin_path = match self.target_platform() { + "windows" => tool_path.join(&dir_name).join(self.name()).join(".exe"), + _ => tool_path.join(&dir_name).join(self.name()), + }; + // Manualy creating tool directory because we directly download the binary via Github + std::fs::create_dir(tool_path.join(dir_name))?; + + let mut final_file = std::fs::File::create(&bin_path)?; + let mut temp_file = File::open(&temp_path)?; + let mut content = Vec::new(); + + temp_file.read_to_end(&mut content)?; + final_file.write_all(&content)?; + + if self.target_platform() == "linux" { + // This code does not update permissions idk why + // let mut perms = final_file.metadata()?.permissions(); + // perms.set_mode(0o744); + + // Adding to the binary execution rights with "chmod" + let mut command = Command::new("chmod"); + + let _ = command + .args(vec!["+x", bin_path.to_str().unwrap()]) + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()) + .output()?; + } + + std::fs::remove_file(&temp_path)?; + } + + Ok(()) + } + + pub fn call(&self, command: &str, args: Vec<&str>) -> anyhow::Result> { + let bin_path = tools_path().join(self.name()).join(self.bin_path()); + + let command_file = match self { + Tool::Binaryen => { + if cfg!(target_os = "windows") { + format!("{}.exe", command) + } else { + command.to_string() + } + } + Tool::Sass => { + if cfg!(target_os = "windows") { + format!("{}.bat", command) + } else { + command.to_string() + } + } + Tool::Tailwind => { + if cfg!(target_os = "windows") { + format!("{}.exe", command) + } else { + command.to_string() + } + } + }; + + if !bin_path.join(&command_file).is_file() { + return Err(anyhow::anyhow!("Command file not found.")); + } + + let mut command = Command::new(bin_path.join(&command_file).to_str().unwrap()); + + let output = command + .args(&args[..]) + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()) + .output()?; + Ok(output.stdout) + } +} + +pub fn extract_zip(file: &Path, target: &Path) -> anyhow::Result<()> { + let zip_file = std::fs::File::open(file)?; + let mut zip = zip::ZipArchive::new(zip_file)?; + + if !target.exists() { + std::fs::create_dir_all(target)?; + } + + for i in 0..zip.len() { + let mut file = zip.by_index(i)?; + if file.is_dir() { + // dir + let target = target.join(Path::new(&file.name().replace('\\', ""))); + std::fs::create_dir_all(target)?; + } else { + // file + let file_path = target.join(Path::new(file.name())); + let mut target_file = if !file_path.exists() { + std::fs::File::create(file_path)? + } else { + std::fs::File::open(file_path)? + }; + let _num = std::io::copy(&mut file, &mut target_file)?; + } + } + + Ok(()) +} diff --git a/packages/cli/tests/main.rs b/packages/cli/tests/main.rs new file mode 100644 index 000000000..1849f5dc8 --- /dev/null +++ b/packages/cli/tests/main.rs @@ -0,0 +1,4 @@ +#[test] +fn ready() { + println!("Compiled successfully!") +} diff --git a/packages/cli/tests/svg.html b/packages/cli/tests/svg.html new file mode 100644 index 000000000..4d5d5ab8f --- /dev/null +++ b/packages/cli/tests/svg.html @@ -0,0 +1,30 @@ +
+ + + + + + + + + + + + +
\ No newline at end of file diff --git a/packages/cli/tests/test.html b/packages/cli/tests/test.html new file mode 100644 index 000000000..05ccd7b18 --- /dev/null +++ b/packages/cli/tests/test.html @@ -0,0 +1,48 @@ +
+
+
+
+
+ content +
+

+ Buy YouTube Videos +

+

+ Williamsburg occupy sustainable snackwave gochujang. Pinterest + cornhole brunch, slow-carb neutra irony. +

+ +
+
+
+ content +
+

+ The Catalyzer +

+

+ Williamsburg occupy sustainable snackwave gochujang. Pinterest + cornhole brunch, slow-carb neutra irony. +

+ +
+
+
+
diff --git a/packages/core-macro/Cargo.toml b/packages/core-macro/Cargo.toml index 843470646..2f9eef4d4 100644 --- a/packages/core-macro/Cargo.toml +++ b/packages/core-macro/Cargo.toml @@ -18,7 +18,7 @@ proc-macro = true proc-macro2 = { version = "1.0" } quote = "1.0" syn = { version = "1.0", features = ["full", "extra-traits"] } -dioxus-rsx = { path = "../rsx", version = "^0.0.3" } +dioxus-rsx = { workspace = true } # testing [dev-dependencies] diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index b86466692..3fd0c62cf 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dioxus-core" -version = "0.3.2" +version = "0.3.3" authors = ["Jonathan Kelley"] edition = "2018" description = "Core functionality for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences" @@ -18,23 +18,23 @@ keywords = ["dom", "ui", "gui", "react"] bumpalo = { version = "3.6", features = ["collections", "boxed"] } # faster hashmaps -rustc-hash = "1.1.0" +rustc-hash = { workspace = true } # Used in diffing longest-increasing-subsequence = "0.1.0" -futures-util = { version = "0.3", default-features = false, features = [ +futures-util = { workspace = true, default-features = false, features = [ "alloc", ] } -slab = "0.4" +slab = { workspace = true } -futures-channel = "0.3.21" +futures-channel = { workspace = true } indexmap = "1.7" smallbox = "0.8.1" -log = "0.4.17" +log = { workspace = true } # Serialize the Edits for use in Webview/Liveview instances serde = { version = "1", features = ["derive"], optional = true } @@ -42,8 +42,8 @@ serde = { version = "1", features = ["derive"], optional = true } bumpslab = { version = "0.2.0" } [dev-dependencies] -tokio = { version = "1", features = ["full"] } -dioxus = { path = "../dioxus" } +tokio = { workspace = true, features = ["full"] } +dioxus = { workspace = true } pretty_assertions = "1.3.0" rand = "0.8.5" diff --git a/packages/core/src/diff.rs b/packages/core/src/diff.rs index 56a2d05de..a8b913440 100644 --- a/packages/core/src/diff.rs +++ b/packages/core/src/diff.rs @@ -7,7 +7,7 @@ use crate::{ nodes::{DynamicNode, VNode}, scopes::ScopeId, virtual_dom::VirtualDom, - Attribute, AttributeValue, TemplateNode, + Attribute, TemplateNode, }; use rustc_hash::{FxHashMap, FxHashSet}; @@ -125,10 +125,8 @@ impl<'b> VirtualDom { .mounted_element .set(left_attr.mounted_element.get()); - // We want to make sure anything listener that gets pulled is valid - if let AttributeValue::Listener(_) = right_attr.value { - self.update_template(left_attr.mounted_element.get(), right_template); - } + // We want to make sure anything that gets pulled is valid + self.update_template(left_attr.mounted_element.get(), right_template); // If the attributes are different (or volatile), we need to update them if left_attr.value != right_attr.value || left_attr.volatile { diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index da139e78a..dabb479cb 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -284,6 +284,17 @@ where Ok(&*Box::leak(deserialized)) } +#[cfg(feature = "serialize")] +fn deserialize_option_leaky<'a, 'de, D>(deserializer: D) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + use serde::Deserialize; + + let deserialized = Option::::deserialize(deserializer)?; + Ok(deserialized.map(|deserialized| &*Box::leak(deserialized.into_boxed_str()))) +} + impl<'a> Template<'a> { /// Is this template worth caching at all, since it's completely runtime? /// @@ -319,6 +330,10 @@ pub enum TemplateNode<'a> { /// /// In HTML, this would be a valid URI that defines a namespace for all elements below it /// SVG is an example of this namespace + #[cfg_attr( + feature = "serialize", + serde(deserialize_with = "deserialize_option_leaky") + )] namespace: Option<&'a str>, /// A list of possibly dynamic attribues for this element diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 2269815aa..b118cd59a 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -384,51 +384,79 @@ impl VirtualDom { data, }; - // Loop through each dynamic attribute in this template before moving up to the template's parent. - while let Some(el_ref) = parent_path { - // safety: we maintain references of all vnodes in the element slab - let template = unsafe { el_ref.template.unwrap().as_ref() }; - let node_template = template.template.get(); - let target_path = el_ref.path; + // If the event bubbles, we traverse through the tree until we find the target element. + if bubbles { + // Loop through each dynamic attribute (in a depth first order) in this template before moving up to the template's parent. + while let Some(el_ref) = parent_path { + // safety: we maintain references of all vnodes in the element slab + if let Some(template) = el_ref.template { + let template = unsafe { template.as_ref() }; + let node_template = template.template.get(); + let target_path = el_ref.path; - for (idx, attr) in template.dynamic_attrs.iter().enumerate() { - let this_path = node_template.attr_paths[idx]; + for (idx, attr) in template.dynamic_attrs.iter().enumerate() { + let this_path = node_template.attr_paths[idx]; - // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one - if attr.name.trim_start_matches("on") == name - && target_path.is_decendant(&this_path) - { - listeners.push(&attr.value); + // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one + if attr.name.trim_start_matches("on") == name + && target_path.is_decendant(&this_path) + { + listeners.push(&attr.value); - // Break if the event doesn't bubble anyways - if !bubbles { - break; + // Break if this is the exact target element. + // This means we won't call two listeners with the same name on the same element. This should be + // documented, or be rejected from the rsx! macro outright + if target_path == this_path { + break; + } + } } - // Break if this is the exact target element. - // This means we won't call two listeners with the same name on the same element. This should be - // documented, or be rejected from the rsx! macro outright - if target_path == this_path { - break; + // Now that we've accumulated all the parent attributes for the target element, call them in reverse order + // We check the bubble state between each call to see if the event has been stopped from bubbling + for listener in listeners.drain(..).rev() { + if let AttributeValue::Listener(listener) = listener { + if let Some(cb) = listener.borrow_mut().as_deref_mut() { + cb(uievent.clone()); + } + + if !uievent.propagates.get() { + return; + } + } + } + + parent_path = template.parent.and_then(|id| self.elements.get(id.0)); + } else { + break; + } + } + } else { + // Otherwise, we just call the listener on the target element + if let Some(el_ref) = parent_path { + // safety: we maintain references of all vnodes in the element slab + if let Some(template) = el_ref.template { + let template = unsafe { template.as_ref() }; + let node_template = template.template.get(); + let target_path = el_ref.path; + + for (idx, attr) in template.dynamic_attrs.iter().enumerate() { + let this_path = node_template.attr_paths[idx]; + + // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one + // Only call the listener if this is the exact target element. + if attr.name.trim_start_matches("on") == name && target_path == this_path { + if let AttributeValue::Listener(listener) = &attr.value { + if let Some(cb) = listener.borrow_mut().as_deref_mut() { + cb(uievent.clone()); + } + + break; + } + } } } } - - // Now that we've accumulated all the parent attributes for the target element, call them in reverse order - // We check the bubble state between each call to see if the event has been stopped from bubbling - for listener in listeners.drain(..).rev() { - if let AttributeValue::Listener(listener) = listener { - if let Some(cb) = listener.borrow_mut().as_deref_mut() { - cb(uievent.clone()); - } - - if !uievent.propagates.get() { - return; - } - } - } - - parent_path = template.parent.and_then(|id| self.elements.get(id.0)); } } diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index 5722a42a2..e2ee6ff3b 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -12,30 +12,33 @@ keywords = ["dom", "ui", "gui", "react"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0", features = ["serialize"] } -dioxus-html = { path = "../html", features = ["serialize"], version = "^0.3.0" } -dioxus-interpreter-js = { path = "../interpreter", version = "^0.3.0" } -dioxus-hot-reload = { path = "../hot-reload", optional = true } +dioxus-core = { workspace = true, features = ["serialize"] } +dioxus-html = { workspace = true, features = ["serialize", "native-bind"] } +dioxus-interpreter-js = { workspace = true } +dioxus-hot-reload = { workspace = true, optional = true } serde = "1.0.136" serde_json = "1.0.79" thiserror = "1.0.30" -log = "0.4.14" +log = { workspace = true } wry = { version = "0.27.2" } -futures-channel = "0.3.21" -tokio = { version = "1.16.1", features = [ +futures-channel = { workspace = true } +tokio = { workspace = true, features = [ "sync", "rt-multi-thread", "rt", "time", "macros", -], optional = true, default-features = false } + "fs", +], optional = true } webbrowser = "0.8.0" infer = "0.11.0" dunce = "1.0.2" -slab = "0.4" +slab = { workspace = true } -futures-util = "0.3.25" +futures-util = { workspace = true } +rfd = "0.11.3" +urlencoding = "2.1.2" [target.'cfg(target_os = "ios")'.dependencies] objc = "0.2.7" @@ -53,6 +56,19 @@ tray = ["wry/tray"] hot-reload = ["dioxus-hot-reload"] [dev-dependencies] -dioxus-core-macro = { path = "../core-macro" } -dioxus-hooks = { path = "../hooks" } -# image = "0.24.0" # enable this when generating a new desktop image +dioxus-core-macro = { workspace = true } +dioxus-hooks = { workspace = true } +dioxus = { workspace = true } +exitcode = "1.1.2" +scraper = "0.16.0" + +# These tests need to be run on the main thread, so they cannot use rust's test harness. +[[test]] +name = "check_events" +path = "headless_tests/events.rs" +harness = false + +[[test]] +name = "check_rendering" +path = "headless_tests/rendering.rs" +harness = false diff --git a/packages/desktop/headless_tests/events.rs b/packages/desktop/headless_tests/events.rs new file mode 100644 index 000000000..0281969ec --- /dev/null +++ b/packages/desktop/headless_tests/events.rs @@ -0,0 +1,351 @@ +use dioxus::html::geometry::euclid::Vector3D; +use dioxus::prelude::*; +use dioxus_desktop::DesktopContext; + +pub(crate) fn check_app_exits(app: Component) { + use dioxus_desktop::tao::window::WindowBuilder; + use dioxus_desktop::Config; + // This is a deadman's switch to ensure that the app exits + let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true)); + let should_panic_clone = should_panic.clone(); + std::thread::spawn(move || { + std::thread::sleep(std::time::Duration::from_secs(100)); + if should_panic_clone.load(std::sync::atomic::Ordering::SeqCst) { + std::process::exit(exitcode::SOFTWARE); + } + }); + + dioxus_desktop::launch_cfg( + app, + Config::new().with_window(WindowBuilder::new().with_visible(false)), + ); + + should_panic.store(false, std::sync::atomic::Ordering::SeqCst); +} + +pub fn main() { + check_app_exits(app); +} + +fn mock_event(cx: &ScopeState, id: &'static str, value: &'static str) { + use_effect(cx, (), |_| { + let desktop_context: DesktopContext = cx.consume_context().unwrap(); + async move { + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + desktop_context.eval(&format!( + r#"let element = document.getElementById('{}'); + // Dispatch a synthetic event + const event = {}; + console.log(element, event); + element.dispatchEvent(event); + "#, + id, value + )); + } + }); +} + +#[allow(deprecated)] +fn app(cx: Scope) -> Element { + let desktop_context: DesktopContext = cx.consume_context().unwrap(); + let recieved_events = use_state(cx, || 0); + + // button + mock_event( + cx, + "button", + r#"new MouseEvent("click", { + view: window, + bubbles: true, + cancelable: true, + button: 0, + })"#, + ); + // mouse_move_div + mock_event( + cx, + "mouse_move_div", + r#"new MouseEvent("mousemove", { + view: window, + bubbles: true, + cancelable: true, + buttons: 2, + })"#, + ); + // mouse_click_div + mock_event( + cx, + "mouse_click_div", + r#"new MouseEvent("click", { + view: window, + bubbles: true, + cancelable: true, + buttons: 2, + button: 2, + })"#, + ); + // mouse_dblclick_div + mock_event( + cx, + "mouse_dblclick_div", + r#"new MouseEvent("dblclick", { + view: window, + bubbles: true, + cancelable: true, + buttons: 1|2, + button: 2, + })"#, + ); + // mouse_down_div + mock_event( + cx, + "mouse_down_div", + r#"new MouseEvent("mousedown", { + view: window, + bubbles: true, + cancelable: true, + buttons: 2, + button: 2, + })"#, + ); + // mouse_up_div + mock_event( + cx, + "mouse_up_div", + r#"new MouseEvent("mouseup", { + view: window, + bubbles: true, + cancelable: true, + buttons: 0, + button: 0, + })"#, + ); + // wheel_div + mock_event( + cx, + "wheel_div", + r#"new WheelEvent("wheel", { + view: window, + deltaX: 1.0, + deltaY: 2.0, + deltaZ: 3.0, + deltaMode: 0x00, + bubbles: true, + })"#, + ); + // key_down_div + mock_event( + cx, + "key_down_div", + r#"new KeyboardEvent("keydown", { + key: "a", + code: "KeyA", + location: 0, + repeat: true, + keyCode: 65, + charCode: 97, + char: "a", + charCode: 0, + altKey: false, + ctrlKey: false, + metaKey: false, + shiftKey: false, + isComposing: false, + which: 65, + bubbles: true, + })"#, + ); + // key_up_div + mock_event( + cx, + "key_up_div", + r#"new KeyboardEvent("keyup", { + key: "a", + code: "KeyA", + location: 0, + repeat: false, + keyCode: 65, + charCode: 97, + char: "a", + charCode: 0, + altKey: false, + ctrlKey: false, + metaKey: false, + shiftKey: false, + isComposing: false, + which: 65, + bubbles: true, + })"#, + ); + // key_press_div + mock_event( + cx, + "key_press_div", + r#"new KeyboardEvent("keypress", { + key: "a", + code: "KeyA", + location: 0, + repeat: false, + keyCode: 65, + charCode: 97, + char: "a", + charCode: 0, + altKey: false, + ctrlKey: false, + metaKey: false, + shiftKey: false, + isComposing: false, + which: 65, + bubbles: true, + })"#, + ); + // focus_in_div + mock_event( + cx, + "focus_in_div", + r#"new FocusEvent("focusin", {bubbles: true})"#, + ); + // focus_out_div + mock_event( + cx, + "focus_out_div", + r#"new FocusEvent("focusout",{bubbles: true})"#, + ); + + if **recieved_events == 12 { + println!("all events recieved"); + desktop_context.close(); + } + + cx.render(rsx! { + div { + button { + id: "button", + onclick: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert!(event.data.held_buttons().is_empty()); + assert_eq!(event.data.trigger_button(), Some(dioxus_html::input_data::MouseButton::Primary)); + recieved_events.modify(|x| *x + 1) + }, + } + div { + id: "mouse_move_div", + onmousemove: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert!(event.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Secondary)); + recieved_events.modify(|x| *x + 1) + }, + } + div { + id: "mouse_click_div", + onclick: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert!(event.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Secondary)); + assert_eq!(event.data.trigger_button(), Some(dioxus_html::input_data::MouseButton::Secondary)); + recieved_events.modify(|x| *x + 1) + }, + } + div{ + id: "mouse_dblclick_div", + ondblclick: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert!(event.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Primary)); + assert!(event.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Secondary)); + assert_eq!(event.data.trigger_button(), Some(dioxus_html::input_data::MouseButton::Secondary)); + recieved_events.modify(|x| *x + 1) + } + } + div{ + id: "mouse_down_div", + onmousedown: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert!(event.data.held_buttons().contains(dioxus_html::input_data::MouseButton::Secondary)); + assert_eq!(event.data.trigger_button(), Some(dioxus_html::input_data::MouseButton::Secondary)); + recieved_events.modify(|x| *x + 1) + } + } + div{ + id: "mouse_up_div", + onmouseup: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert!(event.data.held_buttons().is_empty()); + assert_eq!(event.data.trigger_button(), Some(dioxus_html::input_data::MouseButton::Primary)); + recieved_events.modify(|x| *x + 1) + } + } + div{ + id: "wheel_div", + width: "100px", + height: "100px", + background_color: "red", + onwheel: move |event| { + println!("{:?}", event.data); + let dioxus_html::geometry::WheelDelta::Pixels(delta)= event.data.delta()else{ + panic!("Expected delta to be in pixels") + }; + assert_eq!(delta, Vector3D::new(1.0, 2.0, 3.0)); + recieved_events.modify(|x| *x + 1) + } + } + input{ + id: "key_down_div", + onkeydown: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert_eq!(event.data.key().to_string(), "a"); + assert_eq!(event.data.code().to_string(), "KeyA"); + assert_eq!(event.data.location, 0); + assert!(event.data.is_auto_repeating()); + + recieved_events.modify(|x| *x + 1) + } + } + input{ + id: "key_up_div", + onkeyup: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert_eq!(event.data.key().to_string(), "a"); + assert_eq!(event.data.code().to_string(), "KeyA"); + assert_eq!(event.data.location, 0); + assert!(!event.data.is_auto_repeating()); + + recieved_events.modify(|x| *x + 1) + } + } + input{ + id: "key_press_div", + onkeypress: move |event| { + println!("{:?}", event.data); + assert!(event.data.modifiers().is_empty()); + assert_eq!(event.data.key().to_string(), "a"); + assert_eq!(event.data.code().to_string(), "KeyA"); + assert_eq!(event.data.location, 0); + assert!(!event.data.is_auto_repeating()); + + recieved_events.modify(|x| *x + 1) + } + } + input{ + id: "focus_in_div", + onfocusin: move |event| { + println!("{:?}", event.data); + recieved_events.modify(|x| *x + 1) + } + } + input{ + id: "focus_out_div", + onfocusout: move |event| { + println!("{:?}", event.data); + recieved_events.modify(|x| *x + 1) + } + } + } + }) +} diff --git a/packages/desktop/headless_tests/rendering.rs b/packages/desktop/headless_tests/rendering.rs new file mode 100644 index 000000000..635da9c23 --- /dev/null +++ b/packages/desktop/headless_tests/rendering.rs @@ -0,0 +1,94 @@ +use dioxus::prelude::*; +use dioxus_desktop::DesktopContext; + +pub(crate) fn check_app_exits(app: Component) { + use dioxus_desktop::tao::window::WindowBuilder; + use dioxus_desktop::Config; + // This is a deadman's switch to ensure that the app exits + let should_panic = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true)); + let should_panic_clone = should_panic.clone(); + std::thread::spawn(move || { + std::thread::sleep(std::time::Duration::from_secs(100)); + if should_panic_clone.load(std::sync::atomic::Ordering::SeqCst) { + std::process::exit(exitcode::SOFTWARE); + } + }); + + dioxus_desktop::launch_cfg( + app, + Config::new().with_window(WindowBuilder::new().with_visible(false)), + ); + + should_panic.store(false, std::sync::atomic::Ordering::SeqCst); +} + +fn main() { + check_app_exits(check_html_renders); +} + +fn use_inner_html(cx: &ScopeState, id: &'static str) -> Option { + let value: &UseRef> = use_ref(cx, || None); + use_effect(cx, (), |_| { + to_owned![value]; + let desktop_context: DesktopContext = cx.consume_context().unwrap(); + async move { + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + let html = desktop_context + .eval(&format!( + r#"let element = document.getElementById('{}'); + return element.innerHTML;"#, + id + )) + .await; + if let Ok(serde_json::Value::String(html)) = html { + println!("html: {}", html); + value.set(Some(html)); + } + } + }); + value.read().clone() +} + +const EXPECTED_HTML: &str = r#"

text

hello world

"#; + +fn check_html_renders(cx: Scope) -> Element { + let inner_html = use_inner_html(cx, "main_div"); + let desktop_context: DesktopContext = cx.consume_context().unwrap(); + + if let Some(raw_html) = inner_html.as_deref() { + let fragment = scraper::Html::parse_fragment(raw_html); + println!("fragment: {:?}", fragment.html()); + let expected = scraper::Html::parse_fragment(EXPECTED_HTML); + println!("fragment: {:?}", expected.html()); + if fragment == expected { + println!("html matches"); + desktop_context.close(); + } + } + + let dyn_value = 0; + let dyn_element = rsx! { + div { + dangerous_inner_html: "

hello world

", + } + }; + + render! { + div { + id: "main_div", + div { + width: "100px", + height: "100px", + color: "rgb({dyn_value}, {dyn_value}, {dyn_value})", + id: 5, + input { + "type": "checkbox", + }, + h1 { + "text" + } + dyn_element + } + } + } +} diff --git a/packages/desktop/src/cfg.rs b/packages/desktop/src/cfg.rs index d7f1b5dfa..619a6801a 100644 --- a/packages/desktop/src/cfg.rs +++ b/packages/desktop/src/cfg.rs @@ -23,6 +23,7 @@ pub struct Config { pub(crate) custom_head: Option, pub(crate) custom_index: Option, pub(crate) root_name: String, + pub(crate) background_color: Option<(u8, u8, u8, u8)>, } type DropHandler = Box bool>; @@ -50,6 +51,7 @@ impl Config { custom_head: None, custom_index: None, root_name: "main".to_string(), + background_color: None, } } @@ -137,6 +139,14 @@ impl Config { self.root_name = name.into(); self } + + /// Sets the background color of the WebView. + /// This will be set before the HTML is rendered and can be used to prevent flashing when the page loads. + /// Accepts a color in RGBA format + pub fn with_background_color(mut self, color: (u8, u8, u8, u8)) -> Self { + self.background_color = Some(color); + self + } } impl Default for Config { diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 2ed4bbee9..0db972c73 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -5,6 +5,7 @@ use std::rc::Weak; use crate::create_new_window; use crate::eval::EvalResult; use crate::events::IpcMessage; +use crate::query::QueryEngine; use crate::shortcut::IntoKeyCode; use crate::shortcut::IntoModifersState; use crate::shortcut::ShortcutId; @@ -16,7 +17,6 @@ use dioxus_core::ScopeState; use dioxus_core::VirtualDom; #[cfg(all(feature = "hot-reload", debug_assertions))] use dioxus_hot_reload::HotReloadMsg; -use serde_json::Value; use slab::Slab; use wry::application::event::Event; use wry::application::event_loop::EventLoopProxy; @@ -51,16 +51,15 @@ pub(crate) type WebviewQueue = Rc>>; /// ```rust, ignore /// let desktop = cx.consume_context::().unwrap(); /// ``` -#[derive(Clone)] -pub struct DesktopContext { +pub struct DesktopService { /// The wry/tao proxy to the current window - pub webview: Rc, + pub webview: WebView, /// The proxy to the event loop pub proxy: ProxyType, - /// The receiver for eval results since eval is async - pub(super) eval: tokio::sync::broadcast::Sender, + /// The receiver for queries about the current window + pub(super) query: QueryEngine, pub(super) pending_windows: WebviewQueue, @@ -74,8 +73,10 @@ pub struct DesktopContext { pub(crate) views: Rc>>, } +pub type DesktopContext = Rc; + /// A smart pointer to the current window. -impl std::ops::Deref for DesktopContext { +impl std::ops::Deref for DesktopService { type Target = Window; fn deref(&self) -> &Self::Target { @@ -83,9 +84,9 @@ impl std::ops::Deref for DesktopContext { } } -impl DesktopContext { +impl DesktopService { pub(crate) fn new( - webview: Rc, + webview: WebView, proxy: ProxyType, event_loop: EventLoopWindowTarget, webviews: WebviewQueue, @@ -96,7 +97,7 @@ impl DesktopContext { webview, proxy, event_loop, - eval: tokio::sync::broadcast::channel(8).0, + query: Default::default(), pending_windows: webviews, event_handlers, shortcut_manager, @@ -112,7 +113,7 @@ impl DesktopContext { /// You can use this to control other windows from the current window. /// /// Be careful to not create a cycle of windows, or you might leak memory. - pub fn new_window(&self, dom: VirtualDom, cfg: Config) -> Weak { + pub fn new_window(&self, dom: VirtualDom, cfg: Config) -> Weak { let window = create_new_window( cfg, &self.event_loop, @@ -123,7 +124,13 @@ impl DesktopContext { self.shortcut_manager.clone(), ); - let id = window.webview.window().id(); + let desktop_context = window + .dom + .base_scope() + .consume_context::>() + .unwrap(); + + let id = window.desktop_context.webview.window().id(); self.proxy .send_event(UserWindowEvent(EventData::NewWindow, id)) @@ -133,11 +140,9 @@ impl DesktopContext { .send_event(UserWindowEvent(EventData::Poll, id)) .unwrap(); - let webview = window.webview.clone(); - self.pending_windows.borrow_mut().push(window); - Rc::downgrade(&webview) + Rc::downgrade(&desktop_context) } /// trigger the drag-window event @@ -210,28 +215,10 @@ impl DesktopContext { /// Evaluate a javascript expression pub fn eval(&self, code: &str) -> EvalResult { - // Embed the return of the eval in a function so we can send it back to the main thread - let script = format!( - r#" - window.ipc.postMessage( - JSON.stringify({{ - "method":"eval_result", - "params": ( - function(){{ - {code} - }} - )() - }}) - ); - "# - ); + // the query id lets us keep track of the eval result and send it back to the main thread + let query = self.query.new_query(code, &self.webview); - if let Err(e) = self.webview.evaluate_script(&script) { - // send an error to the eval receiver - log::warn!("Eval script error: {e}"); - } - - EvalResult::new(self.eval.clone()) + EvalResult::new(query) } /// Create a wry event handler that listens for wry events. @@ -423,7 +410,7 @@ pub fn use_wry_event_handler( let id = desktop.create_wry_event_handler(handler); WryEventHandler { - handlers: desktop.event_handlers, + handlers: desktop.event_handlers.clone(), id, } }) diff --git a/packages/desktop/src/element.rs b/packages/desktop/src/element.rs new file mode 100644 index 000000000..94db28f0b --- /dev/null +++ b/packages/desktop/src/element.rs @@ -0,0 +1,123 @@ +use std::rc::Rc; + +use dioxus_core::ElementId; +use dioxus_html::{geometry::euclid::Rect, MountedResult, RenderedElementBacking}; +use wry::webview::WebView; + +use crate::query::QueryEngine; + +/// A mounted element passed to onmounted events +pub struct DesktopElement { + id: ElementId, + webview: Rc, + query: QueryEngine, +} + +impl DesktopElement { + pub(crate) fn new(id: ElementId, webview: Rc, query: QueryEngine) -> Self { + Self { id, webview, query } + } +} + +impl RenderedElementBacking for DesktopElement { + fn get_raw_element(&self) -> dioxus_html::MountedResult<&dyn std::any::Any> { + Ok(self) + } + + fn get_client_rect( + &self, + ) -> std::pin::Pin< + Box< + dyn futures_util::Future< + Output = dioxus_html::MountedResult>, + >, + >, + > { + let script = format!("return window.interpreter.GetClientRect({});", self.id.0); + + let fut = self + .query + .new_query::>>(&script, &self.webview) + .resolve(); + Box::pin(async move { + match fut.await { + Ok(Some(rect)) => Ok(rect), + Ok(None) => MountedResult::Err(dioxus_html::MountedError::OperationFailed( + Box::new(DesktopQueryError::FailedToQuery), + )), + Err(err) => { + MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err))) + } + } + }) + } + + fn scroll_to( + &self, + behavior: dioxus_html::ScrollBehavior, + ) -> std::pin::Pin>>> { + let script = format!( + "return window.interpreter.ScrollTo({}, {});", + self.id.0, + serde_json::to_string(&behavior).expect("Failed to serialize ScrollBehavior") + ); + + let fut = self + .query + .new_query::(&script, &self.webview) + .resolve(); + Box::pin(async move { + match fut.await { + Ok(true) => Ok(()), + Ok(false) => MountedResult::Err(dioxus_html::MountedError::OperationFailed( + Box::new(DesktopQueryError::FailedToQuery), + )), + Err(err) => { + MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err))) + } + } + }) + } + + fn set_focus( + &self, + focus: bool, + ) -> std::pin::Pin>>> { + let script = format!( + "return window.interpreter.SetFocus({}, {});", + self.id.0, focus + ); + + let fut = self + .query + .new_query::(&script, &self.webview) + .resolve(); + + Box::pin(async move { + match fut.await { + Ok(true) => Ok(()), + Ok(false) => MountedResult::Err(dioxus_html::MountedError::OperationFailed( + Box::new(DesktopQueryError::FailedToQuery), + )), + Err(err) => { + MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err))) + } + } + }) + } +} + +#[derive(Debug)] +enum DesktopQueryError { + FailedToQuery, +} + +impl std::fmt::Display for DesktopQueryError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + DesktopQueryError::FailedToQuery => write!(f, "Failed to query the element"), + } + } +} + +impl std::error::Error for DesktopQueryError {} diff --git a/packages/desktop/src/eval.rs b/packages/desktop/src/eval.rs index 7a92bedf5..1e11cad18 100644 --- a/packages/desktop/src/eval.rs +++ b/packages/desktop/src/eval.rs @@ -1,36 +1,32 @@ use std::rc::Rc; +use crate::query::Query; +use crate::query::QueryError; use crate::use_window; use dioxus_core::ScopeState; -use serde::de::Error; use std::future::Future; use std::future::IntoFuture; use std::pin::Pin; /// A future that resolves to the result of a JavaScript evaluation. pub struct EvalResult { - pub(crate) broadcast: tokio::sync::broadcast::Sender, + pub(crate) query: Query, } impl EvalResult { - pub(crate) fn new(sender: tokio::sync::broadcast::Sender) -> Self { - Self { broadcast: sender } + pub(crate) fn new(query: Query) -> Self { + Self { query } } } impl IntoFuture for EvalResult { - type Output = Result; + type Output = Result; - type IntoFuture = Pin>>>; + type IntoFuture = Pin>>>; fn into_future(self) -> Self::IntoFuture { - Box::pin(async move { - let mut reciever = self.broadcast.subscribe(); - match reciever.recv().await { - Ok(result) => Ok(result), - Err(_) => Err(serde_json::Error::custom("No result returned")), - } - }) as Pin>>> + Box::pin(self.query.resolve()) + as Pin>>> } } diff --git a/packages/desktop/src/file_upload.rs b/packages/desktop/src/file_upload.rs new file mode 100644 index 000000000..1b24ffc55 --- /dev/null +++ b/packages/desktop/src/file_upload.rs @@ -0,0 +1,77 @@ +use std::{path::PathBuf, str::FromStr}; + +use serde::Deserialize; + +#[derive(Debug, Deserialize)] +pub(crate) struct FileDiologRequest { + #[serde(default)] + accept: Option, + multiple: bool, + pub event: String, + pub target: usize, + pub bubbles: bool, +} + +pub(crate) fn get_file_event(request: &FileDiologRequest) -> Vec { + let mut dialog = rfd::FileDialog::new(); + + let filters: Vec<_> = request + .accept + .as_deref() + .unwrap_or_default() + .split(',') + .filter_map(|s| Filters::from_str(s).ok()) + .collect(); + + let file_extensions: Vec<_> = filters + .iter() + .flat_map(|f| f.as_extensions().into_iter()) + .collect(); + + dialog = dialog.add_filter("name", file_extensions.as_slice()); + + let files: Vec<_> = if request.multiple { + dialog.pick_files().into_iter().flatten().collect() + } else { + dialog.pick_file().into_iter().collect() + }; + + files +} + +enum Filters { + Extension(String), + Mime(String), + Audio, + Video, + Image, +} + +impl Filters { + fn as_extensions(&self) -> Vec<&str> { + match self { + Filters::Extension(extension) => vec![extension.as_str()], + Filters::Mime(_) => vec![], + Filters::Audio => vec!["mp3", "wav", "ogg"], + Filters::Video => vec!["mp4", "webm"], + Filters::Image => vec!["png", "jpg", "jpeg", "gif", "webp"], + } + } +} + +impl FromStr for Filters { + type Err = String; + + fn from_str(s: &str) -> Result { + if let Some(extension) = s.strip_prefix('.') { + Ok(Filters::Extension(extension.to_string())) + } else { + match s { + "audio/*" => Ok(Filters::Audio), + "video/*" => Ok(Filters::Video), + "image/*" => Ok(Filters::Image), + _ => Ok(Filters::Mime(s.to_string())), + } + } + } +} diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index cdb592f72..fc574dfc0 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -5,28 +5,36 @@ mod cfg; mod desktop_context; +mod element; mod escape; mod eval; mod events; +mod file_upload; mod protocol; +mod query; mod shortcut; mod waker; mod webview; +use crate::query::QueryResult; pub use cfg::Config; pub use desktop_context::{ - use_window, use_wry_event_handler, DesktopContext, WryEventHandler, WryEventHandlerId, + use_window, use_wry_event_handler, DesktopService, WryEventHandler, WryEventHandlerId, +}; +use desktop_context::{ + DesktopContext, EventData, UserWindowEvent, WebviewQueue, WindowEventHandlers, }; -use desktop_context::{EventData, UserWindowEvent, WebviewQueue, WindowEventHandlers}; use dioxus_core::*; -use dioxus_html::HtmlEvent; +use dioxus_html::MountedData; +use dioxus_html::{native_bind::NativeFileEngine, FormData, HtmlEvent}; +use element::DesktopElement; pub use eval::{use_eval, EvalResult}; use futures_util::{pin_mut, FutureExt}; use shortcut::ShortcutRegistry; pub use shortcut::{use_global_shortcut, ShortcutHandle, ShortcutId, ShortcutRegistryError}; -use std::collections::HashMap; use std::rc::Rc; use std::task::Waker; +use std::{collections::HashMap, sync::Arc}; pub use tao::dpi::{LogicalSize, PhysicalSize}; use tao::event_loop::{EventLoopProxy, EventLoopWindowTarget}; pub use tao::window::WindowBuilder; @@ -144,8 +152,7 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) let shortcut_manager = ShortcutRegistry::new(&event_loop); - // By default, we'll create a new window when the app starts - queue.borrow_mut().push(create_new_window( + let web_view = create_new_window( cfg, &event_loop, &proxy, @@ -153,7 +160,10 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) &queue, &event_handlers, shortcut_manager.clone(), - )); + ); + + // By default, we'll create a new window when the app starts + queue.borrow_mut().push(web_view); event_loop.run(move |window_event, event_loop, control_flow| { *control_flow = ControlFlow::Wait; @@ -184,7 +194,7 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) Event::NewEvents(StartCause::Init) | Event::UserEvent(UserWindowEvent(EventData::NewWindow, _)) => { for handler in queue.borrow_mut().drain(..) { - let id = handler.webview.window().id(); + let id = handler.desktop_context.webview.window().id(); webviews.insert(id, handler); _ = proxy.send_event(UserWindowEvent(EventData::Poll, id)); } @@ -220,37 +230,63 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) } EventData::Ipc(msg) if msg.method() == "user_event" => { - let evt = match serde_json::from_value::(msg.params()) { + let params = msg.params(); + + let evt = match serde_json::from_value::(params) { Ok(value) => value, Err(_) => return, }; + let HtmlEvent { + element, + name, + bubbles, + data, + } = evt; + let view = webviews.get_mut(&event.1).unwrap(); - view.dom - .handle_event(&evt.name, evt.data.into_any(), evt.element, evt.bubbles); + // check for a mounted event placeholder and replace it with a desktop specific element + let as_any = if let dioxus_html::EventData::Mounted = &data { + let query = view + .dom + .base_scope() + .consume_context::() + .unwrap() + .query; - send_edits(view.dom.render_immediate(), &view.webview); + let element = DesktopElement::new(element, view.webview.clone(), query); + + Rc::new(MountedData::new(element)) + } else { + data.into_any() + }; + + view.dom.handle_event(&name, as_any, element, bubbles); + + send_edits(view.dom.render_immediate(), &view.desktop_context.webview); + } + + // When the webview sends a query, we need to send it to the query manager which handles dispatching the data to the correct pending query + EventData::Ipc(msg) if msg.method() == "query" => { + let params = msg.params(); + + if let Ok(result) = serde_json::from_value::(params) { + let view = webviews.get(&event.1).unwrap(); + let query = view + .dom + .base_scope() + .consume_context::() + .unwrap() + .query; + + query.send(result); + } } EventData::Ipc(msg) if msg.method() == "initialize" => { let view = webviews.get_mut(&event.1).unwrap(); - send_edits(view.dom.rebuild(), &view.webview); - } - - // When the webview chirps back with the result of the eval, we send it to the active receiver - // - // This currently doesn't perform any targeting to the callsite, so if you eval multiple times at once, - // you might the wrong result. This should be fixed - EventData::Ipc(msg) if msg.method() == "eval_result" => { - webviews[&event.1] - .dom - .base_scope() - .consume_context::() - .unwrap() - .eval - .send(msg.params()) - .unwrap(); + send_edits(view.dom.rebuild(), &view.desktop_context.webview); } EventData::Ipc(msg) if msg.method() == "browser_open" => { @@ -264,6 +300,34 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) } } + EventData::Ipc(msg) if msg.method() == "file_diolog" => { + if let Ok(file_diolog) = + serde_json::from_value::(msg.params()) + { + let id = ElementId(file_diolog.target); + let event_name = &file_diolog.event; + let event_bubbles = file_diolog.bubbles; + let files = file_upload::get_file_event(&file_diolog); + let data = Rc::new(FormData { + value: Default::default(), + values: Default::default(), + files: Some(Arc::new(NativeFileEngine::new(files))), + }); + + let view = webviews.get_mut(&event.1).unwrap(); + + if event_name == "change&input" { + view.dom + .handle_event("input", data.clone(), id, event_bubbles); + view.dom.handle_event("change", data, id, event_bubbles); + } else { + view.dom.handle_event(event_name, data, id, event_bubbles); + } + + send_edits(view.dom.render_immediate(), &view.webview); + } + } + _ => {} }, Event::GlobalShortcutEvent(id) => shortcut_manager.call_handlers(id), @@ -282,9 +346,8 @@ fn create_new_window( shortcut_manager: ShortcutRegistry, ) -> WebviewHandler { let (webview, web_context) = webview::build(&mut cfg, event_loop, proxy.clone()); - - dom.base_scope().provide_context(DesktopContext::new( - webview.clone(), + let desktop_context = Rc::from(DesktopService::new( + webview, proxy.clone(), event_loop.clone(), queue.clone(), @@ -292,11 +355,14 @@ fn create_new_window( shortcut_manager, )); - let id = webview.window().id(); + dom.base_scope().provide_context(desktop_context.clone()); + + let id = desktop_context.webview.window().id(); // We want to poll the virtualdom and the event loop at the same time, so the waker will be connected to both + WebviewHandler { - webview, + desktop_context, dom, waker: waker::tao_waker(proxy, id), web_context, @@ -305,7 +371,7 @@ fn create_new_window( struct WebviewHandler { dom: VirtualDom, - webview: Rc, + desktop_context: DesktopContext, waker: Waker, // This is nessisary because of a bug in wry. Wry assumes the webcontext is alive for the lifetime of the webview. We need to keep the webcontext alive, otherwise the webview will crash #[allow(dead_code)] @@ -331,7 +397,7 @@ fn poll_vdom(view: &mut WebviewHandler) { } } - send_edits(view.dom.render_immediate(), &view.webview); + send_edits(view.dom.render_immediate(), &view.desktop_context.webview); } } diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs index efdc849a5..6be5d08b4 100644 --- a/packages/desktop/src/protocol.rs +++ b/packages/desktop/src/protocol.rs @@ -1,4 +1,4 @@ -use dioxus_interpreter_js::INTERPRETER_JS; +use dioxus_interpreter_js::{COMMON_JS, INTERPRETER_JS}; use std::{ borrow::Cow, path::{Path, PathBuf}, @@ -9,15 +9,41 @@ use wry::{ }; fn module_loader(root_name: &str) -> String { + let js = INTERPRETER_JS.replace( + "/*POST_HANDLE_EDITS*/", + r#"// Prevent file inputs from opening the file dialog on click + let inputs = document.querySelectorAll("input"); + for (let input of inputs) { + if (!input.getAttribute("data-dioxus-file-listener")) { + // prevent file inputs from opening the file dialog on click + const type = input.getAttribute("type"); + if (type === "file") { + input.setAttribute("data-dioxus-file-listener", true); + input.addEventListener("click", (event) => { + let target = event.target; + let target_id = find_real_id(target); + if (target_id !== null) { + const send = (event_name) => { + const message = serializeIpcMessage("file_diolog", { accept: target.getAttribute("accept"), multiple: target.hasAttribute("multiple"), target: parseInt(target_id), bubbles: event_bubbles(event_name), event: event_name }); + window.ipc.postMessage(message); + }; + send("change&input"); + } + event.preventDefault(); + }); + } + } + }"#, + ); format!( r#" - @@ -58,10 +84,17 @@ pub(super) fn desktop_handler( .header("Content-Type", "text/html") .body(Cow::from(body)) .map_err(From::from); + } else if request.uri().path() == "/common.js" { + return Response::builder() + .header("Content-Type", "text/javascript") + .body(Cow::from(COMMON_JS.as_bytes())) + .map_err(From::from); } // Else, try to serve a file from the filesystem. - let path = PathBuf::from(request.uri().path().trim_start_matches('/')); + let decoded = urlencoding::decode(request.uri().path().trim_start_matches('/')) + .expect("expected URL to be UTF-8 encoded"); + let path = PathBuf::from(&*decoded); // If the path is relative, we'll try to serve it from the assets directory. let mut asset = get_asset_root() diff --git a/packages/desktop/src/query.rs b/packages/desktop/src/query.rs new file mode 100644 index 000000000..fb23dc487 --- /dev/null +++ b/packages/desktop/src/query.rs @@ -0,0 +1,110 @@ +use std::{cell::RefCell, rc::Rc}; + +use serde::{de::DeserializeOwned, Deserialize}; +use serde_json::Value; +use slab::Slab; +use thiserror::Error; +use tokio::sync::broadcast::error::RecvError; +use wry::webview::WebView; + +/// Tracks what query ids are currently active +#[derive(Default, Clone)] +struct SharedSlab { + slab: Rc>>, +} + +/// Handles sending and receiving arbitrary queries from the webview. Queries can be resolved non-sequentially, so we use ids to track them. +#[derive(Clone)] +pub(crate) struct QueryEngine { + sender: Rc>, + active_requests: SharedSlab, +} + +impl Default for QueryEngine { + fn default() -> Self { + let (sender, _) = tokio::sync::broadcast::channel(1000); + Self { + sender: Rc::new(sender), + active_requests: SharedSlab::default(), + } + } +} + +impl QueryEngine { + /// Creates a new query and returns a handle to it. The query will be resolved when the webview returns a result with the same id. + pub fn new_query(&self, script: &str, webview: &WebView) -> Query { + let request_id = self.active_requests.slab.borrow_mut().insert(()); + + // start the query + // We embed the return of the eval in a function so we can send it back to the main thread + if let Err(err) = webview.evaluate_script(&format!( + r#"window.ipc.postMessage( + JSON.stringify({{ + "method":"query", + "params": {{ + "id": {request_id}, + "data": (function(){{{script}}})() + }} + }}) + );"# + )) { + log::warn!("Query error: {err}"); + } + + Query { + slab: self.active_requests.clone(), + id: request_id, + reciever: self.sender.subscribe(), + phantom: std::marker::PhantomData, + } + } + + /// Send a query result + pub fn send(&self, data: QueryResult) { + let _ = self.sender.send(data); + } +} + +pub(crate) struct Query { + slab: SharedSlab, + id: usize, + reciever: tokio::sync::broadcast::Receiver, + phantom: std::marker::PhantomData, +} + +impl Query { + /// Resolve the query + pub async fn resolve(mut self) -> Result { + let result = loop { + match self.reciever.recv().await { + Ok(result) => { + if result.id == self.id { + break V::deserialize(result.data).map_err(QueryError::DeserializeError); + } + } + Err(err) => { + break Err(QueryError::RecvError(err)); + } + } + }; + + // Remove the query from the slab + self.slab.slab.borrow_mut().remove(self.id); + + result + } +} + +#[derive(Error, Debug)] +pub enum QueryError { + #[error("Error receiving query result: {0}")] + RecvError(RecvError), + #[error("Error deserializing query result: {0}")] + DeserializeError(serde_json::Error), +} + +#[derive(Clone, Debug, Deserialize)] +pub(crate) struct QueryResult { + id: usize, + data: Value, +} diff --git a/packages/desktop/src/shortcut.rs b/packages/desktop/src/shortcut.rs index 5232bdb8b..ffa87dd05 100644 --- a/packages/desktop/src/shortcut.rs +++ b/packages/desktop/src/shortcut.rs @@ -10,7 +10,7 @@ use wry::application::{ keyboard::{KeyCode, ModifiersState}, }; -use crate::{use_window, DesktopContext}; +use crate::{desktop_context::DesktopContext, use_window}; #[derive(Clone)] pub(crate) struct ShortcutRegistry { @@ -41,17 +41,10 @@ impl Shortcut { impl ShortcutRegistry { pub fn new(target: &EventLoopWindowTarget) -> Self { - let myself = Self { + Self { manager: Rc::new(RefCell::new(ShortcutManager::new(target))), shortcuts: Rc::new(RefCell::new(HashMap::new())), - }; - // prevent CTRL+R from reloading the page which breaks apps - let _ = myself.add_shortcut( - Some(ModifiersState::CONTROL), - KeyCode::KeyR, - Box::new(|| {}), - ); - myself + } } pub(crate) fn call_handlers(&self, id: AcceleratorId) { diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index 5d3acf44f..469aa8068 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -1,5 +1,3 @@ -use std::rc::Rc; - use crate::desktop_context::EventData; use crate::protocol; use crate::{desktop_context::UserWindowEvent, Config}; @@ -13,7 +11,7 @@ pub fn build( cfg: &mut Config, event_loop: &EventLoopWindowTarget, proxy: EventLoopProxy, -) -> (Rc, WebContext) { +) -> (WebView, WebContext) { let builder = cfg.window.clone(); let window = builder.build(event_loop).unwrap(); let file_handler = cfg.file_drop_handler.take(); @@ -64,6 +62,10 @@ pub fn build( webview = webview.with_browser_accelerator_keys(false); } + if let Some(color) = cfg.background_color { + webview = webview.with_background_color(color); + } + // These are commented out because wry is currently broken in wry // let mut web_context = WebContext::new(cfg.data_dir.clone()); // .with_web_context(&mut web_context); @@ -92,5 +94,5 @@ pub fn build( webview = webview.with_devtools(true); } - (Rc::new(webview.build().unwrap()), web_context) + (webview.build().unwrap(), web_context) } diff --git a/packages/dioxus-tui/Cargo.toml b/packages/dioxus-tui/Cargo.toml index 18388b12e..1b225a005 100644 --- a/packages/dioxus-tui/Cargo.toml +++ b/packages/dioxus-tui/Cargo.toml @@ -13,21 +13,21 @@ license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus = { path = "../dioxus", version = "^0.3.0" } -dioxus-core = { path = "../core", version = "^0.3.0", features = ["serialize"] } -dioxus-html = { path = "../html", version = "^0.3.0" } -dioxus-native-core = { path = "../native-core", version = "^0.2.0", features = ["dioxus"] } -dioxus-native-core-macro = { path = "../native-core-macro", version = "^0.3.0" } -dioxus-hot-reload = { path = "../hot-reload", optional = true } -rink = { path = "../rink" } +dioxus = { workspace = true } +dioxus-core = { workspace = true, features = ["serialize"] } +dioxus-html = { workspace = true } +dioxus-native-core = { workspace = true, features = ["dioxus"] } +dioxus-native-core-macro = { workspace = true } +dioxus-hot-reload = { workspace = true, optional = true } +rink = { workspace = true } crossterm = "0.26.0" -tokio = { version = "1.15.0", features = ["full"] } +tokio = { workspace = true, features = ["full"] } futures = "0.3.19" -taffy = "0.2.1" +taffy = "0.3.12" [dev-dependencies] -dioxus = { path = "../dioxus" } +dioxus = { workspace = true } tokio = { version = "1" } criterion = "0.3.5" diff --git a/packages/dioxus-tui/examples/all_events.rs b/packages/dioxus-tui/examples/all_terminal_events.rs similarity index 100% rename from packages/dioxus-tui/examples/all_events.rs rename to packages/dioxus-tui/examples/all_terminal_events.rs diff --git a/packages/dioxus-tui/examples/components.rs b/packages/dioxus-tui/examples/components.rs deleted file mode 100644 index 45ed56338..000000000 --- a/packages/dioxus-tui/examples/components.rs +++ /dev/null @@ -1,67 +0,0 @@ -#![allow(non_snake_case)] - -use dioxus::prelude::*; -use dioxus_tui::Config; - -fn main() { - dioxus_tui::launch_cfg(app, Config::default()); -} - -#[derive(Props, PartialEq)] -struct QuadrentProps { - color: String, - text: String, -} - -fn Quadrant(cx: Scope) -> Element { - cx.render(rsx! { - div { - border_width: "1px", - width: "50%", - height: "100%", - background_color: "{cx.props.color}", - justify_content: "center", - align_items: "center", - - "{cx.props.text}" - } - }) -} - -fn app(cx: Scope) -> Element { - cx.render(rsx! { - div { - width: "100%", - height: "100%", - flex_direction: "column", - - div { - width: "100%", - height: "50%", - flex_direction: "row", - Quadrant{ - color: "red".to_string(), - text: "[A]".to_string() - }, - Quadrant{ - color: "black".to_string(), - text: "[B]".to_string() - } - } - - div { - width: "100%", - height: "50%", - flex_direction: "row", - Quadrant{ - color: "green".to_string(), - text: "[C]".to_string() - }, - Quadrant{ - color: "blue".to_string(), - text: "[D]".to_string() - } - } - } - }) -} diff --git a/packages/dioxus-tui/examples/stress.rs b/packages/dioxus-tui/examples/many_small_edit_stress.rs similarity index 100% rename from packages/dioxus-tui/examples/stress.rs rename to packages/dioxus-tui/examples/many_small_edit_stress.rs diff --git a/packages/dioxus-tui/examples/quadrants.rs b/packages/dioxus-tui/examples/quadrants.rs index d9da5dcb5..45ed56338 100644 --- a/packages/dioxus-tui/examples/quadrants.rs +++ b/packages/dioxus-tui/examples/quadrants.rs @@ -1,7 +1,31 @@ +#![allow(non_snake_case)] + use dioxus::prelude::*; +use dioxus_tui::Config; fn main() { - dioxus_tui::launch(app); + dioxus_tui::launch_cfg(app, Config::default()); +} + +#[derive(Props, PartialEq)] +struct QuadrentProps { + color: String, + text: String, +} + +fn Quadrant(cx: Scope) -> Element { + cx.render(rsx! { + div { + border_width: "1px", + width: "50%", + height: "100%", + background_color: "{cx.props.color}", + justify_content: "center", + align_items: "center", + + "{cx.props.text}" + } + }) } fn app(cx: Scope) -> Element { @@ -15,22 +39,13 @@ fn app(cx: Scope) -> Element { width: "100%", height: "50%", flex_direction: "row", - div { - border_width: "1px", - width: "50%", - height: "100%", - background_color: "red", - justify_content: "center", - align_items: "center", - "[A]" - } - div { - width: "50%", - height: "100%", - background_color: "black", - justify_content: "center", - align_items: "center", - "[B]" + Quadrant{ + color: "red".to_string(), + text: "[A]".to_string() + }, + Quadrant{ + color: "black".to_string(), + text: "[B]".to_string() } } @@ -38,21 +53,13 @@ fn app(cx: Scope) -> Element { width: "100%", height: "50%", flex_direction: "row", - div { - width: "50%", - height: "100%", - background_color: "green", - justify_content: "center", - align_items: "center", - "[C]" - } - div { - width: "50%", - height: "100%", - background_color: "blue", - justify_content: "center", - align_items: "center", - "[D]" + Quadrant{ + color: "green".to_string(), + text: "[C]".to_string() + }, + Quadrant{ + color: "blue".to_string(), + text: "[D]".to_string() } } } diff --git a/packages/dioxus-tui/examples/readme.rs b/packages/dioxus-tui/examples/readme_hello_world.rs similarity index 100% rename from packages/dioxus-tui/examples/readme.rs rename to packages/dioxus-tui/examples/readme_hello_world.rs diff --git a/packages/dioxus-tui/src/element.rs b/packages/dioxus-tui/src/element.rs new file mode 100644 index 000000000..152de4a10 --- /dev/null +++ b/packages/dioxus-tui/src/element.rs @@ -0,0 +1,99 @@ +use std::{ + any::Any, + fmt::{Display, Formatter}, + rc::Rc, +}; + +use dioxus_core::{ElementId, Mutations, VirtualDom}; +use dioxus_html::{ + geometry::euclid::{Point2D, Rect, Size2D}, + MountedData, MountedError, RenderedElementBacking, +}; + +use dioxus_native_core::NodeId; +use rink::query::{ElementRef, Query}; + +pub(crate) fn find_mount_events(mutations: &Mutations) -> Vec { + let mut mount_events = Vec::new(); + for mutation in &mutations.edits { + if let dioxus_core::Mutation::NewEventListener { + name: "mounted", + id, + } = mutation + { + mount_events.push(*id); + } + } + mount_events +} + +// We need to queue the mounted events to give rink time to rendere and resolve the layout of elements after they are created +pub(crate) fn create_mounted_events( + vdom: &VirtualDom, + events: &mut Vec<(ElementId, &'static str, Rc, bool)>, + mount_events: impl Iterator, +) { + let query: Query = vdom + .base_scope() + .consume_context() + .expect("Query should be in context"); + for (id, node_id) in mount_events { + let element = TuiElement { + query: query.clone(), + id: node_id, + }; + events.push((id, "mounted", Rc::new(MountedData::new(element)), false)); + } +} + +struct TuiElement { + query: Query, + id: NodeId, +} + +impl TuiElement { + pub(crate) fn element(&self) -> ElementRef { + self.query.get(self.id) + } +} + +impl RenderedElementBacking for TuiElement { + fn get_client_rect( + &self, + ) -> std::pin::Pin< + Box< + dyn futures::Future< + Output = dioxus_html::MountedResult>, + >, + >, + > { + let layout = self.element().layout(); + Box::pin(async move { + match layout { + Some(layout) => { + let x = layout.location.x as f64; + let y = layout.location.y as f64; + let width = layout.size.width as f64; + let height = layout.size.height as f64; + Ok(Rect::new(Point2D::new(x, y), Size2D::new(width, height))) + } + None => Err(MountedError::OperationFailed(Box::new(TuiElementNotFound))), + } + }) + } + + fn get_raw_element(&self) -> dioxus_html::MountedResult<&dyn std::any::Any> { + Ok(self) + } +} + +#[derive(Debug)] +struct TuiElementNotFound; + +impl Display for TuiElementNotFound { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "TUI element not found") + } +} + +impl std::error::Error for TuiElementNotFound {} diff --git a/packages/dioxus-tui/src/lib.rs b/packages/dioxus-tui/src/lib.rs index 296fd4697..46ada5537 100644 --- a/packages/dioxus-tui/src/lib.rs +++ b/packages/dioxus-tui/src/lib.rs @@ -1,7 +1,9 @@ +mod element; pub mod prelude; pub mod widgets; use std::{ + any::Any, ops::Deref, rc::Rc, sync::{Arc, RwLock}, @@ -12,6 +14,7 @@ use dioxus_html::EventData; use dioxus_native_core::dioxus::{DioxusState, NodeImmutableDioxusExt}; use dioxus_native_core::prelude::*; +use element::{create_mounted_events, find_mount_events}; pub use rink::{query::Query, Config, RenderingMode, Size, TuiContext}; use rink::{render, Driver}; @@ -37,14 +40,32 @@ pub fn launch_cfg_with_props(app: Component, props: Props mapping: dioxus_state.clone(), }); let muts = vdom.rebuild(); - let mut rdom = rdom.write().unwrap(); - dioxus_state - .write() - .unwrap() - .apply_mutations(&mut rdom, muts); + + let mut queued_events = Vec::new(); + + { + let mut rdom = rdom.write().unwrap(); + let mut dioxus_state = dioxus_state.write().unwrap(); + + // Find any mount events + let mounted = dbg!(find_mount_events(&muts)); + + dioxus_state.apply_mutations(&mut rdom, muts); + + // Send the mount events + create_mounted_events( + &vdom, + &mut queued_events, + mounted + .iter() + .map(|id| (*dbg!(id), dioxus_state.element_to_node_id(*id))), + ); + } + DioxusRenderer { vdom, dioxus_state, + queued_events, #[cfg(all(feature = "hot-reload", debug_assertions))] hot_reload_rx: { let (hot_reload_tx, hot_reload_rx) = @@ -62,6 +83,8 @@ pub fn launch_cfg_with_props(app: Component, props: Props struct DioxusRenderer { vdom: VirtualDom, dioxus_state: Rc>, + // Events that are queued up to be sent to the vdom next time the vdom is polled + queued_events: Vec<(ElementId, &'static str, Rc, bool)>, #[cfg(all(feature = "hot-reload", debug_assertions))] hot_reload_rx: tokio::sync::mpsc::UnboundedReceiver, } @@ -71,10 +94,23 @@ impl Driver for DioxusRenderer { let muts = self.vdom.render_immediate(); { let mut rdom = rdom.write().unwrap(); - self.dioxus_state - .write() - .unwrap() - .apply_mutations(&mut rdom, muts); + + { + // Find any mount events + let mounted = find_mount_events(&muts); + + let mut dioxus_state = self.dioxus_state.write().unwrap(); + dioxus_state.apply_mutations(&mut rdom, muts); + + // Send the mount events + create_mounted_events( + &self.vdom, + &mut self.queued_events, + mounted + .iter() + .map(|id| (*id, dioxus_state.element_to_node_id(*id))), + ); + } } } @@ -94,6 +130,11 @@ impl Driver for DioxusRenderer { } fn poll_async(&mut self) -> std::pin::Pin + '_>> { + // Add any queued events + for (id, event, value, bubbles) in self.queued_events.drain(..) { + self.vdom.handle_event(event, value, id, bubbles); + } + #[cfg(all(feature = "hot-reload", debug_assertions))] return Box::pin(async { let hot_reload_wait = self.hot_reload_rx.recv(); diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index bc2098285..456a10085 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -12,14 +12,14 @@ keywords = ["dom", "ui", "gui", "react", "wasm"] rust-version = "1.65.0" [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0" } -dioxus-html = { path = "../html", version = "^0.3.0", optional = true } -dioxus-core-macro = { path = "../core-macro", version = "^0.3.0", optional = true } -dioxus-hooks = { path = "../hooks", version = "^0.3.0", optional = true } -dioxus-rsx = { path = "../rsx", version = "^0.0.3", optional = true } +dioxus-core = { workspace = true } +dioxus-html = { workspace = true, optional = true } +dioxus-core-macro = { workspace = true, optional = true } +dioxus-hooks = { workspace = true, optional = true } +dioxus-rsx = { workspace = true, optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -dioxus-hot-reload = { path = "../hot-reload", version = "0.1.0", optional = true } +dioxus-hot-reload = { workspace = true, optional = true } [features] default = ["macro", "hooks", "html", "hot-reload"] @@ -30,14 +30,14 @@ hot-reload = ["dioxus-hot-reload"] [dev-dependencies] -futures-util = "0.3.21" -log = "0.4.14" +futures-util = { workspace = true } +log = { workspace = true } rand = { version = "0.8.4", features = ["small_rng"] } criterion = "0.3.5" thiserror = "1.0.30" -env_logger = "0.9.0" -tokio = { version = "1.21.2", features = ["full"] } -# dioxus-edit-stream = { path = "../edit-stream" } +env_logger = "0.10.0" +tokio = { workspace = true, features = ["full"] } +# dioxus-edit-stream = { workspace = true } [[bench]] diff --git a/packages/fermi/Cargo.toml b/packages/fermi/Cargo.toml index 9591a4f25..40bbb1b40 100644 --- a/packages/fermi/Cargo.toml +++ b/packages/fermi/Cargo.toml @@ -13,9 +13,9 @@ keywords = ["dom", "ui", "gui", "react", "state-management"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0" } +dioxus-core = { workspace = true } im-rc = { version = "15.0.0", features = ["serde"] } -log = "0.4.14" +log = { workspace = true } [dev-dependencies] closure = "0.3.0" diff --git a/packages/fermi/README.md b/packages/fermi/README.md index f04ec5961..f276dbff5 100644 --- a/packages/fermi/README.md +++ b/packages/fermi/README.md @@ -9,22 +9,22 @@

- - + Crates.io version - - + Download - + docs.rs docs - + CI status diff --git a/packages/fermi/src/hooks/atom_ref.rs b/packages/fermi/src/hooks/atom_ref.rs index fc7df59fc..95732c491 100644 --- a/packages/fermi/src/hooks/atom_ref.rs +++ b/packages/fermi/src/hooks/atom_ref.rs @@ -70,17 +70,46 @@ impl UseAtomRef { self.value.borrow() } + /// This is silent operation + /// call `.force_update()` manually if required + pub fn with_mut_silent(&self, cb: impl FnOnce(&mut T)) { + cb(&mut *self.write_silent()) + } + pub fn write(&self) -> RefMut { self.root.force_update(self.ptr); self.value.borrow_mut() } + /// Silent write to AtomRef + /// does not update Subscribed scopes pub fn write_silent(&self) -> RefMut { self.value.borrow_mut() } + /// Replace old value with new one pub fn set(&self, new: T) { self.root.force_update(self.ptr); self.root.set(self.ptr, new); } + + /// Do not update provided context on Write ops + /// Example: + /// ```ignore + /// static ATOM_DATA: AtomRef = |_| Default::default(); + /// fn App(cx: Scope) { + /// use_init_atom_root(cx); + /// let atom_data = use_atom_ref(cx, ATOM_DATA); + /// atom_data.unsubscribe(cx); + /// atom_data.write().update(); + /// } + /// ``` + pub fn unsubscribe(&self, cx: &ScopeState) { + self.root.unsubscribe(self.ptr, cx.scope_id()); + } + + /// Force update of subscribed Scopes + pub fn force_update(&self) { + self.root.force_update(self.ptr); + } } diff --git a/packages/fullstack/.gitignore b/packages/fullstack/.gitignore new file mode 100644 index 000000000..1de565933 --- /dev/null +++ b/packages/fullstack/.gitignore @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml new file mode 100644 index 000000000..167476909 --- /dev/null +++ b/packages/fullstack/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "dioxus-fullstack" +version = "0.1.0" +edition = "2021" +description = "Fullstack Dioxus Utilities" +license = "MIT/Apache-2.0" +repository = "https://github.com/DioxusLabs/dioxus/" +homepage = "https://dioxuslabs.com" +documentation = "https://dioxuslabs.com" +keywords = ["dom", "ui", "gui", "react", "ssr", "fullstack"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# server functions +server_fn = { git = "https://github.com/leptos-rs/leptos", rev = "15a4e54435eb5a539afb75891292bcccd2cc8e85", default-features = false, features = ["stable"] } +dioxus_server_macro = { path = "server-macro" } + +# warp +warp = { version = "0.3.3", optional = true } +http-body = { version = "0.4.5", optional = true } + +# axum +axum = { version = "0.6.1", features = ["ws"], optional = true } +tower-http = { version = "0.4.0", optional = true, features = ["fs"] } +axum-macros = "0.3.7" + +# salvo +salvo = { version = "0.37.7", optional = true, features = ["serve-static", "ws"] } +serde = "1.0.159" + +# Dioxus + SSR +dioxus-core = { workspace = true } +dioxus-ssr = { workspace = true, optional = true } +hyper = { version = "0.14.25", optional = true } +http = { version = "0.2.9", optional = true } + +log = { workspace = true } +once_cell = "1.17.1" +thiserror = "1.0.40" +tokio = { workspace = true, features = ["full"], optional = true } +object-pool = "0.5.4" +anymap = "0.12.1" + +serde_json = { version = "1.0.95", optional = true } +tokio-stream = { version = "0.1.12", features = ["sync"], optional = true } +futures-util = { workspace = true, optional = true } +postcard = { version = "1.0.4", features = ["use-std"] } +yazi = "0.1.5" +base64 = "0.21.0" + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +dioxus-hot-reload = { workspace = true } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] } + +[features] +default = ["hot-reload", "default-tls"] +hot-reload = ["serde_json", "tokio-stream", "futures-util"] +warp = ["dep:warp", "http-body", "ssr"] +axum = ["dep:axum", "tower-http", "ssr"] +salvo = ["dep:salvo", "ssr"] +ssr = ["server_fn/ssr", "tokio", "dioxus-ssr", "hyper", "http"] +default-tls = ["server_fn/default-tls"] +rustls = ["server_fn/rustls"] diff --git a/packages/fullstack/README.md b/packages/fullstack/README.md new file mode 100644 index 000000000..ecd003ee8 --- /dev/null +++ b/packages/fullstack/README.md @@ -0,0 +1,107 @@ +# Dioxus Fullstack + +[![Crates.io][crates-badge]][crates-url] +[![MIT licensed][mit-badge]][mit-url] +[![Build Status][actions-badge]][actions-url] +[![Discord chat][discord-badge]][discord-url] + +[crates-badge]: https://img.shields.io/crates/v/dioxus-fullstack.svg +[crates-url]: https://crates.io/crates/dioxus-fullstack +[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg +[mit-url]: https://github.com/dioxuslabs/dioxus/blob/master/LICENSE +[actions-badge]: https://github.com/dioxuslabs/dioxus/actions/workflows/main.yml/badge.svg +[actions-url]: https://github.com/dioxuslabs/dioxus/actions?query=workflow%3ACI+branch%3Amaster +[discord-badge]: https://img.shields.io/discord/899851952891002890.svg?logo=discord&style=flat-square +[discord-url]: https://discord.gg/XgGxMSkvUM + +[Website](https://dioxuslabs.com) | +[Guides](https://dioxuslabs.com/docs/0.3/guide/en/) | +[API Docs](https://docs.rs/dioxus-fullstack/latest/dioxus_sever) | +[Chat](https://discord.gg/XgGxMSkvUM) + +Fullstack utilities for the [`Dioxus`](https://dioxuslabs.com) framework. + +# Features + +- Intigrations with the [Axum](https::/docs.rs/dioxus-fullstack/latest/dixous_server/axum_adapter/index.html), [Salvo](https::/docs.rs/dioxus-fullstack/latest/dixous_server/salvo_adapter/index.html), and [Warp](https::/docs.rs/dioxus-fullstack/latest/dixous_server/warp_adapter/index.html) server frameworks with utilities for serving and rendering Dioxus applications. +- [Server functions](https::/docs.rs/dioxus-fullstack/latest/dixous_server/prelude/attr.server.html) allow you to call code on the server from the client as if it were a normal function. +- Instant RSX Hot reloading with [`dioxus-hot-reload`](https://crates.io/crates/dioxus-hot-reload). +- Passing root props from the server to the client. + +# Example + +Full stack Dioxus in under 50 lines of code + +```rust +#![allow(non_snake_case)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + warp::serve( + // Automatically handles server side rendering, hot reloading intigration, and hosting server functions + serve_dioxus_application( + "", + ServeConfigBuilder::new(app, ()), + ) + ) + .run(([127, 0, 0, 1], 8080)) + .await; + }); + } +} + +fn app(cx: Scope) -> Element { + let meaning = use_state(cx, || None); + cx.render(rsx! { + button { + onclick: move |_| { + to_owned![meaning]; + async move { + if let Ok(data) = get_meaning("life the universe and everything".into()).await { + meaning.set(data); + } + } + }, + "Run a server function" + } + "Server said: {meaning:?}" + }) +} + +// This code will only run on the server +#[server(GetMeaning)] +async fn get_meaning(of: String) -> Result, ServerFnError> { + Ok(of.contains("life").then(|| 42)) +} +``` + +## Getting Started + +To get started with full stack Dioxus, check out our [getting started guide](https://dioxuslabs.com/docs/nightly/guide/en/getting_started/ssr.html), or the [full stack examples](https://github.com/DioxusLabs/dioxus/tree/master/packages/fullstack/examples). + +## Contributing + +- Report issues on our [issue tracker](https://github.com/dioxuslabs/dioxus/issues). +- Join the discord and ask questions! + +## License + +This project is licensed under the [MIT license]. + +[mit license]: https://github.com/DioxusLabs/dioxus/blob/master/LICENSE-MIT + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in Dioxus by you shall be licensed as MIT without any additional +terms or conditions. diff --git a/packages/fullstack/examples/axum-desktop/.gitignore b/packages/fullstack/examples/axum-desktop/.gitignore new file mode 100644 index 000000000..6047329c6 --- /dev/null +++ b/packages/fullstack/examples/axum-desktop/.gitignore @@ -0,0 +1,2 @@ +dist +target \ No newline at end of file diff --git a/packages/fullstack/examples/axum-desktop/Cargo.toml b/packages/fullstack/examples/axum-desktop/Cargo.toml new file mode 100644 index 000000000..459a6c9b7 --- /dev/null +++ b/packages/fullstack/examples/axum-desktop/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "axum-desktop" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] + +[dependencies] +dioxus-desktop = { workspace = true, optional = true } +dioxus = { workspace = true } +dioxus-router = { workspace = true } +dioxus-fullstack = { workspace = true } +axum = { version = "0.6.12", optional = true } +tokio = { workspace = true, features = ["full"], optional = true } +serde = "1.0.159" + +[features] +default = [] +ssr = ["axum", "tokio", "dioxus-fullstack/axum"] +desktop = ["dioxus-desktop"] + +[[bin]] +name = "client" +path = "src/client.rs" +required-features = ["desktop"] + +[[bin]] +name = "server" +path = "src/server.rs" +required-features = ["ssr"] diff --git a/packages/fullstack/examples/axum-desktop/src/client.rs b/packages/fullstack/examples/axum-desktop/src/client.rs new file mode 100644 index 000000000..8cb5b6cff --- /dev/null +++ b/packages/fullstack/examples/axum-desktop/src/client.rs @@ -0,0 +1,13 @@ +// Run with: +// ```bash +// cargo run --bin client --features="desktop" +// ``` + +use axum_desktop::*; +use dioxus_fullstack::prelude::server_fn::set_server_url; + +fn main() { + // Set the url of the server where server functions are hosted. + set_server_url("http://localhost:8080"); + dioxus_desktop::launch(app) +} diff --git a/packages/fullstack/examples/axum-desktop/src/lib.rs b/packages/fullstack/examples/axum-desktop/src/lib.rs new file mode 100644 index 000000000..1ac655ce1 --- /dev/null +++ b/packages/fullstack/examples/axum-desktop/src/lib.rs @@ -0,0 +1,40 @@ +#![allow(non_snake_case)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; + +pub fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || 0); + let text = use_state(cx, || "...".to_string()); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![text]; + async move { + if let Ok(data) = get_server_data().await { + println!("Client received: {}", data); + text.set(data.clone()); + post_server_data(data).await.unwrap(); + } + } + }, + "Run a server function" + } + "Server said: {text}" + }) +} + +#[server(PostServerData)] +async fn post_server_data(data: String) -> Result<(), ServerFnError> { + println!("Server received: {}", data); + + Ok(()) +} + +#[server(GetServerData)] +async fn get_server_data() -> Result { + Ok("Hello from the server!".to_string()) +} diff --git a/packages/fullstack/examples/axum-desktop/src/server.rs b/packages/fullstack/examples/axum-desktop/src/server.rs new file mode 100644 index 000000000..6098ae3f4 --- /dev/null +++ b/packages/fullstack/examples/axum-desktop/src/server.rs @@ -0,0 +1,20 @@ +// Run with: +// ```bash +// cargo run --bin server --features="ssr" +// ``` + +use axum_desktop::*; +use dioxus_fullstack::prelude::*; + +#[tokio::main] +async fn main() { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + .register_server_fns("") + .into_make_service(), + ) + .await + .unwrap(); +} diff --git a/packages/fullstack/examples/axum-hello-world/.gitignore b/packages/fullstack/examples/axum-hello-world/.gitignore new file mode 100644 index 000000000..6047329c6 --- /dev/null +++ b/packages/fullstack/examples/axum-hello-world/.gitignore @@ -0,0 +1,2 @@ +dist +target \ No newline at end of file diff --git a/packages/fullstack/examples/axum-hello-world/Cargo.toml b/packages/fullstack/examples/axum-hello-world/Cargo.toml new file mode 100644 index 000000000..b41225206 --- /dev/null +++ b/packages/fullstack/examples/axum-hello-world/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "axum-hello-world" +version = "0.1.0" +edition = "2021" +publish = false + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus-web = { workspace = true, features=["hydrate"], optional = true } +dioxus = { workspace = true } +dioxus-fullstack = { workspace = true } +axum = { version = "0.6.12", optional = true } +tokio = { workspace = true, features = ["full"], optional = true } +serde = "1.0.159" +execute = "0.2.12" + +[features] +default = ["web"] +ssr = ["axum", "tokio", "dioxus-fullstack/axum"] +web = ["dioxus-web"] diff --git a/packages/fullstack/examples/axum-hello-world/src/main.rs b/packages/fullstack/examples/axum-hello-world/src/main.rs new file mode 100644 index 000000000..66c3af096 --- /dev/null +++ b/packages/fullstack/examples/axum-hello-world/src/main.rs @@ -0,0 +1,99 @@ +//! Run with: +//! +//! ```sh +//! dioxus build --features web +//! cargo run --features ssr --no-default-features +//! ``` + +#![allow(non_snake_case)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; +use serde::{Deserialize, Serialize}; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + // Start hot reloading + hot_reload_init!(dioxus_hot_reload::Config::new().with_rebuild_callback(|| { + execute::shell("dioxus build --features web") + .spawn() + .unwrap() + .wait() + .unwrap(); + execute::shell("cargo run --features ssr --no-default-features") + .spawn() + .unwrap(); + true + })); + + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + axum::Server::bind(&addr) + .serve( + axum::Router::new() + .serve_dioxus_application( + "", + ServeConfigBuilder::new(app, AppProps { count: 12345 }).build(), + ) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +#[derive(Props, PartialEq, Debug, Default, Serialize, Deserialize, Clone)] +struct AppProps { + count: i32, +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || cx.props.count); + let text = use_state(cx, || "...".to_string()); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![text]; + let sc = cx.sc(); + async move { + if let Ok(data) = get_server_data().await { + println!("Client received: {}", data); + text.set(data.clone()); + post_server_data(sc, data).await.unwrap(); + } + } + }, + "Run a server function! testing1234" + } + "Server said: {text}" + }) +} + +#[server(PostServerData)] +async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> { + // The server context contains information about the current request and allows you to modify the response. + cx.response_headers_mut() + .insert("Set-Cookie", "foo=bar".parse().unwrap()); + println!("Server received: {}", data); + println!("Request parts are {:?}", cx.request_parts()); + + Ok(()) +} + +#[server(GetServerData)] +async fn get_server_data() -> Result { + Ok("Hello from the server!".to_string()) +} diff --git a/packages/fullstack/examples/axum-router/.gitignore b/packages/fullstack/examples/axum-router/.gitignore new file mode 100644 index 000000000..6047329c6 --- /dev/null +++ b/packages/fullstack/examples/axum-router/.gitignore @@ -0,0 +1,2 @@ +dist +target \ No newline at end of file diff --git a/packages/fullstack/examples/axum-router/Cargo.toml b/packages/fullstack/examples/axum-router/Cargo.toml new file mode 100644 index 000000000..fbd59bfc0 --- /dev/null +++ b/packages/fullstack/examples/axum-router/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "axum-router" +version = "0.1.0" +edition = "2021" +publish = false + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus-web = { workspace = true, features=["hydrate"], optional = true } +dioxus = { workspace = true } +dioxus-router = { workspace = true } +dioxus-fullstack = { workspace = true } +axum = { version = "0.6.12", optional = true } +tokio = { workspace = true, features = ["full"], optional = true } +serde = "1.0.159" +tower-http = { version = "0.4.0", features = ["fs"], optional = true } +http = { version = "0.2.9", optional = true } +execute = "0.2.12" + +[features] +default = ["web"] +ssr = ["axum", "tokio", "dioxus-fullstack/axum", "tower-http", "http"] +web = ["dioxus-web", "dioxus-router/web"] diff --git a/packages/fullstack/examples/axum-router/src/main.rs b/packages/fullstack/examples/axum-router/src/main.rs new file mode 100644 index 000000000..2b98ad842 --- /dev/null +++ b/packages/fullstack/examples/axum-router/src/main.rs @@ -0,0 +1,151 @@ +//! Run with: +//! +//! ```sh +//! dioxus build --features web +//! cargo run --features ssr --no-default-features +//! ``` + +#![allow(non_snake_case)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; +use dioxus_router::*; +use serde::{Deserialize, Serialize}; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + App, + AppProps { route: None }, + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + // Start hot reloading + hot_reload_init!(dioxus_hot_reload::Config::new().with_rebuild_callback(|| { + execute::shell("dioxus build --features web") + .spawn() + .unwrap() + .wait() + .unwrap(); + execute::shell("cargo run --features ssr --no-default-features") + .spawn() + .unwrap(); + true + })); + + use axum::extract::State; + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + + axum::Server::bind(&addr) + .serve( + axum::Router::new() + // Serve the dist/assets folder with the javascript and WASM files created by the CLI + .serve_static_assets("./dist") + // Register server functions + .register_server_fns("") + // Connect to the hot reload server + .connect_hot_reload() + // If the path is unknown, render the application + .fallback( + move |uri: http::uri::Uri, State(ssr_state): State| { + let rendered = ssr_state.render( + &ServeConfigBuilder::new( + App, + AppProps { + route: Some(format!("http://{addr}{uri}")), + }, + ) + .build(), + ); + async move { axum::body::Full::from(rendered) } + }, + ) + .with_state(SSRState::default()) + .into_make_service(), + ) + .await + .unwrap(); + }); + } +} + +#[derive(Clone, Debug, Props, PartialEq, Serialize, Deserialize)] +struct AppProps { + route: Option, +} + +fn App(cx: Scope) -> Element { + cx.render(rsx! { + Router { + initial_url: cx.props.route.clone(), + + Route { to: "/blog", + Link { + to: "/", + "Go to counter" + } + table { + tbody { + for _ in 0..100 { + tr { + for _ in 0..100 { + td { "hello world!" } + } + } + } + } + } + }, + // Fallback + Route { to: "", + Counter {} + }, + } + }) +} + +fn Counter(cx: Scope) -> Element { + let mut count = use_state(cx, || 0); + let text = use_state(cx, || "...".to_string()); + + cx.render(rsx! { + Link { + to: "/blog", + "Go to blog" + } + div{ + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![text]; + async move { + if let Ok(data) = get_server_data().await { + println!("Client received: {}", data); + text.set(data.clone()); + post_server_data(data).await.unwrap(); + } + } + }, + "Run a server function" + } + "Server said: {text}" + } + }) +} + +#[server(PostServerData)] +async fn post_server_data(data: String) -> Result<(), ServerFnError> { + println!("Server received: {}", data); + + Ok(()) +} + +#[server(GetServerData)] +async fn get_server_data() -> Result { + Ok("Hello from the server!".to_string()) +} diff --git a/packages/fullstack/examples/salvo-hello-world/.gitignore b/packages/fullstack/examples/salvo-hello-world/.gitignore new file mode 100644 index 000000000..6047329c6 --- /dev/null +++ b/packages/fullstack/examples/salvo-hello-world/.gitignore @@ -0,0 +1,2 @@ +dist +target \ No newline at end of file diff --git a/packages/fullstack/examples/salvo-hello-world/Cargo.toml b/packages/fullstack/examples/salvo-hello-world/Cargo.toml new file mode 100644 index 000000000..6895b85f6 --- /dev/null +++ b/packages/fullstack/examples/salvo-hello-world/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "salvo-hello-world" +version = "0.1.0" +edition = "2021" +publish = false + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus-web = { workspace = true, features=["hydrate"], optional = true } +dioxus = { workspace = true } +dioxus-fullstack = { workspace = true } +tokio = { workspace = true, features = ["full"], optional = true } +serde = "1.0.159" +salvo = { version = "0.37.9", optional = true } +execute = "0.2.12" + +[features] +default = ["web"] +ssr = ["salvo", "tokio", "dioxus-fullstack/salvo"] +web = ["dioxus-web"] diff --git a/packages/fullstack/examples/salvo-hello-world/src/main.rs b/packages/fullstack/examples/salvo-hello-world/src/main.rs new file mode 100644 index 000000000..01b67ff99 --- /dev/null +++ b/packages/fullstack/examples/salvo-hello-world/src/main.rs @@ -0,0 +1,95 @@ +//! Run with: +//! +//! ```sh +//! dioxus build --features web +//! cargo run --features ssr --no-default-features +//! ``` + +#![allow(non_snake_case)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; +use serde::{Deserialize, Serialize}; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + // Start hot reloading + hot_reload_init!(dioxus_hot_reload::Config::new().with_rebuild_callback(|| { + execute::shell("dioxus build --features web") + .spawn() + .unwrap() + .wait() + .unwrap(); + execute::shell("cargo run --features ssr --no-default-features") + .spawn() + .unwrap(); + true + })); + + use salvo::prelude::*; + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let router = Router::new().serve_dioxus_application( + "", + ServeConfigBuilder::new(app, AppProps { count: 12345 }), + ); + Server::new(TcpListener::bind("127.0.0.1:8080")) + .serve(router) + .await; + }); + } +} + +#[derive(Props, PartialEq, Debug, Default, Serialize, Deserialize, Clone)] +struct AppProps { + count: i32, +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || cx.props.count); + let text = use_state(cx, || "...".to_string()); + let server_context = cx.sc(); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 1, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![text, server_context]; + async move { + if let Ok(data) = get_server_data().await { + println!("Client received: {}", data); + text.set(data.clone()); + post_server_data(server_context, data).await.unwrap(); + } + } + }, + "Run a server function" + } + "Server said: {text}" + }) +} + +#[server(PostServerData)] +async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> { + // The server context contains information about the current request and allows you to modify the response. + cx.response_headers_mut() + .insert("Set-Cookie", "foo=bar".parse().unwrap()); + println!("Server received: {}", data); + println!("Request parts are {:?}", cx.request_parts()); + + Ok(()) +} + +#[server(GetServerData)] +async fn get_server_data() -> Result { + Ok("Hello from the server!".to_string()) +} diff --git a/packages/fullstack/examples/warp-hello-world/.gitignore b/packages/fullstack/examples/warp-hello-world/.gitignore new file mode 100644 index 000000000..6047329c6 --- /dev/null +++ b/packages/fullstack/examples/warp-hello-world/.gitignore @@ -0,0 +1,2 @@ +dist +target \ No newline at end of file diff --git a/packages/fullstack/examples/warp-hello-world/Cargo.toml b/packages/fullstack/examples/warp-hello-world/Cargo.toml new file mode 100644 index 000000000..58b842853 --- /dev/null +++ b/packages/fullstack/examples/warp-hello-world/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "warp-hello-world" +version = "0.1.0" +edition = "2021" +publish = false + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus-web = { workspace = true, features=["hydrate"], optional = true } +dioxus = { workspace = true } +dioxus-fullstack = { workspace = true } +tokio = { workspace = true, features = ["full"], optional = true } +serde = "1.0.159" +warp = { version = "0.3.3", optional = true } +execute = "0.2.12" + +[features] +default = ["web"] +ssr = ["warp", "tokio", "dioxus-fullstack/warp"] +web = ["dioxus-web"] diff --git a/packages/fullstack/examples/warp-hello-world/src/main.rs b/packages/fullstack/examples/warp-hello-world/src/main.rs new file mode 100644 index 000000000..34fc24c77 --- /dev/null +++ b/packages/fullstack/examples/warp-hello-world/src/main.rs @@ -0,0 +1,92 @@ +//! Run with: +//! +//! ```sh +//! dioxus build --features web +//! cargo run --features ssr --no-default-features +//! ``` + +#![allow(non_snake_case)] +use dioxus::prelude::*; +use dioxus_fullstack::prelude::*; +use serde::{Deserialize, Serialize}; + +fn main() { + #[cfg(feature = "web")] + dioxus_web::launch_with_props( + app, + get_root_props_from_document().unwrap_or_default(), + dioxus_web::Config::new().hydrate(true), + ); + #[cfg(feature = "ssr")] + { + // Start hot reloading + hot_reload_init!(dioxus_hot_reload::Config::new().with_rebuild_callback(|| { + execute::shell("dioxus build --features web") + .spawn() + .unwrap() + .wait() + .unwrap(); + execute::shell("cargo run --features ssr --no-default-features") + .spawn() + .unwrap(); + true + })); + + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async move { + let routes = serve_dioxus_application( + "", + ServeConfigBuilder::new(app, AppProps { count: 12345 }), + ); + warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; + }); + } +} + +#[derive(Props, PartialEq, Debug, Default, Serialize, Deserialize, Clone)] +struct AppProps { + count: i32, +} + +fn app(cx: Scope) -> Element { + let mut count = use_state(cx, || cx.props.count); + let text = use_state(cx, || "...".to_string()); + let server_context = cx.sc(); + + cx.render(rsx! { + h1 { "High-Five counter: {count}" } + button { onclick: move |_| count += 10, "Up high!" } + button { onclick: move |_| count -= 1, "Down low!" } + button { + onclick: move |_| { + to_owned![text, server_context]; + async move { + if let Ok(data) = get_server_data().await { + println!("Client received: {}", data); + text.set(data.clone()); + post_server_data(server_context, data).await.unwrap(); + } + } + }, + "Run a server function" + } + "Server said: {text}" + }) +} + +#[server(PostServerData)] +async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> { + // The server context contains information about the current request and allows you to modify the response. + cx.response_headers_mut() + .insert("Set-Cookie", "foo=bar".parse().unwrap()); + println!("Server received: {}", data); + println!("Request parts are {:?}", cx.request_parts()); + + Ok(()) +} + +#[server(GetServerData)] +async fn get_server_data() -> Result { + Ok("Hello from the server!".to_string()) +} diff --git a/packages/fullstack/server-macro/Cargo.toml b/packages/fullstack/server-macro/Cargo.toml new file mode 100644 index 000000000..cb039057b --- /dev/null +++ b/packages/fullstack/server-macro/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "dioxus_server_macro" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +quote = "1.0.26" +server_fn_macro = { git = "https://github.com/leptos-rs/leptos", rev = "15a4e54435eb5a539afb75891292bcccd2cc8e85", features = ["stable"] } +syn = { version = "2", features = ["full"] } + +[lib] +proc-macro = true diff --git a/packages/fullstack/server-macro/src/lib.rs b/packages/fullstack/server-macro/src/lib.rs new file mode 100644 index 000000000..9a1a2c9c7 --- /dev/null +++ b/packages/fullstack/server-macro/src/lib.rs @@ -0,0 +1,71 @@ +use proc_macro::TokenStream; +use quote::ToTokens; +use server_fn_macro::*; + +/// Declares that a function is a [server function](dioxus_fullstack). This means that +/// its body will only run on the server, i.e., when the `ssr` feature is enabled. +/// +/// If you call a server function from the client (i.e., when the `csr` or `hydrate` features +/// are enabled), it will instead make a network request to the server. +/// +/// You can specify one, two, or three arguments to the server function: +/// 1. **Required**: A type name that will be used to identify and register the server function +/// (e.g., `MyServerFn`). +/// 2. *Optional*: A URL prefix at which the function will be mounted when it’s registered +/// (e.g., `"/api"`). Defaults to `"/"`. +/// 3. *Optional*: either `"Cbor"` (specifying that it should use the binary `cbor` format for +/// serialization), `"Url"` (specifying that it should be use a URL-encoded form-data string). +/// Defaults to `"Url"`. If you want to use this server function +/// using Get instead of Post methods, the encoding must be `"GetCbor"` or `"GetJson"`. +/// +/// The server function itself can take any number of arguments, each of which should be serializable +/// and deserializable with `serde`. Optionally, its first argument can be a [DioxusServerContext](https::/docs.rs/dioxus-fullstack/latest/dixous_server/prelude/struct.DioxusServerContext.html), +/// which will be injected *on the server side.* This can be used to inject the raw HTTP request or other +/// server-side context into the server function. +/// +/// ```ignore +/// # use dioxus_fullstack::prelude::*; use serde::{Serialize, Deserialize}; +/// # #[derive(Serialize, Deserialize)] +/// # pub struct Post { } +/// #[server(ReadPosts, "/api")] +/// pub async fn read_posts(how_many: u8, query: String) -> Result, ServerFnError> { +/// // do some work on the server to access the database +/// todo!() +/// } +/// ``` +/// +/// Note the following: +/// - **Server functions must be `async`.** Even if the work being done inside the function body +/// can run synchronously on the server, from the client’s perspective it involves an asynchronous +/// function call. +/// - **Server functions must return `Result`.** Even if the work being done +/// inside the function body can’t fail, the processes of serialization/deserialization and the +/// network call are fallible. +/// - **Return types must implement [`Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html).** +/// This should be fairly obvious: we have to serialize arguments to send them to the server, and we +/// need to deserialize the result to return it to the client. +/// - **Arguments must be implement [`Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html) +/// and [`DeserializeOwned`](https://docs.rs/serde/latest/serde/de/trait.DeserializeOwned.html).** +/// They are serialized as an `application/x-www-form-urlencoded` +/// form data using [`serde_urlencoded`](https://docs.rs/serde_urlencoded/latest/serde_urlencoded/) or as `application/cbor` +/// using [`cbor`](https://docs.rs/cbor/latest/cbor/). +/// - **The [DioxusServerContext](https::/docs.rs/dioxus-fullstack/latest/dixous_server/prelude/struct.DioxusServerContext.html) comes from the server.** Optionally, the first argument of a server function +/// can be a [DioxusServerContext](https::/docs.rs/dioxus-fullstack/latest/dixous_server/prelude/struct.DioxusServerContext.html). This scope can be used to inject dependencies like the HTTP request +/// or response or other server-only dependencies, but it does *not* have access to reactive state that exists in the client. +#[proc_macro_attribute] +pub fn server(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream { + let context = ServerContext { + ty: syn::parse_quote!(DioxusServerContext), + path: syn::parse_quote!(::dioxus_fullstack::prelude::DioxusServerContext), + }; + match server_macro_impl( + args.into(), + s.into(), + syn::parse_quote!(::dioxus_fullstack::prelude::ServerFnTraitObj), + Some(context), + Some(syn::parse_quote!(::dioxus_fullstack::prelude::server_fn)), + ) { + Err(e) => e.to_compile_error().into(), + Ok(s) => s.to_token_stream().into(), + } +} diff --git a/packages/fullstack/src/adapters/axum_adapter.rs b/packages/fullstack/src/adapters/axum_adapter.rs new file mode 100644 index 000000000..1ff136d4d --- /dev/null +++ b/packages/fullstack/src/adapters/axum_adapter.rs @@ -0,0 +1,491 @@ +//! Dioxus utilities for the [Axum](https://docs.rs/axum/latest/axum/index.html) server framework. +//! +//! # Example +//! ```rust +//! #![allow(non_snake_case)] +//! use dioxus::prelude::*; +//! use dioxus_fullstack::prelude::*; +//! +//! fn main() { +//! #[cfg(feature = "web")] +//! // Hydrate the application on the client +//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true)); +//! #[cfg(feature = "ssr")] +//! { +//! tokio::runtime::Runtime::new() +//! .unwrap() +//! .block_on(async move { +//! let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); +//! axum::Server::bind(&addr) +//! .serve( +//! axum::Router::new() +//! // Server side render the application, serve static assets, and register server functions +//! .serve_dioxus_application("", ServeConfigBuilder::new(app, ())) +//! .into_make_service(), +//! ) +//! .await +//! .unwrap(); +//! }); +//! } +//! } +//! +//! fn app(cx: Scope) -> Element { +//! let text = use_state(cx, || "...".to_string()); +//! +//! cx.render(rsx! { +//! button { +//! onclick: move |_| { +//! to_owned![text]; +//! async move { +//! if let Ok(data) = get_server_data().await { +//! text.set(data); +//! } +//! } +//! }, +//! "Run a server function" +//! } +//! "Server said: {text}" +//! }) +//! } +//! +//! #[server(GetServerData)] +//! async fn get_server_data() -> Result { +//! Ok("Hello from the server!".to_string()) +//! } +//! ``` + +use axum::{ + body::{self, Body, BoxBody, Full}, + extract::{State, WebSocketUpgrade}, + handler::Handler, + http::{Request, Response, StatusCode}, + response::IntoResponse, + routing::{get, post}, + Router, +}; +use dioxus_core::VirtualDom; +use server_fn::{Encoding, Payload, ServerFunctionRegistry}; +use std::error::Error; +use std::sync::Arc; +use tokio::task::spawn_blocking; + +use crate::{ + prelude::*, render::SSRState, serve_config::ServeConfig, server_context::DioxusServerContext, + server_fn::DioxusServerFnRegistry, +}; + +/// A extension trait with utilities for integrating Dioxus with your Axum router. +pub trait DioxusRouterExt { + /// Registers server functions with a custom handler function. This allows you to pass custom context to your server functions by generating a [`DioxusServerContext`] from the request. + /// + /// # Example + /// ```rust + /// use dioxus::prelude::*; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + /// axum::Server::bind(&addr) + /// .serve( + /// axum::Router::new() + /// .register_server_fns_with_handler("", |func| { + /// move |req: Request| async move { + /// let (parts, body) = req.into_parts(); + /// let parts: Arc = Arc::new(parts.into()); + /// let server_context = DioxusServerContext::new(parts.clone()); + /// server_fn_handler(server_context, func.clone(), parts, body).await + /// } + /// }) + /// .into_make_service(), + /// ) + /// .await + /// .unwrap(); + /// } + /// ``` + fn register_server_fns_with_handler( + self, + server_fn_route: &'static str, + handler: impl FnMut(server_fn::ServerFnTraitObj) -> H, + ) -> Self + where + H: Handler, + T: 'static, + S: Clone + Send + Sync + 'static; + + /// Registers server functions with the default handler. This handler function will pass an empty [`DioxusServerContext`] to your server functions. + /// + /// # Example + /// ```rust + /// use dioxus::prelude::*; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + /// axum::Server::bind(&addr) + /// .serve( + /// axum::Router::new() + /// // Register server functions routes with the default handler + /// .register_server_fns("") + /// .into_make_service(), + /// ) + /// .await + /// .unwrap(); + /// } + /// ``` + fn register_server_fns(self, server_fn_route: &'static str) -> Self; + + /// Register the web RSX hot reloading endpoint. This will enable hot reloading for your application in debug mode when you call [`dioxus_hot_reload::hot_reload_init`]. + /// + /// # Example + /// ```rust + /// #![allow(non_snake_case)] + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// hot_reload_init!(); + /// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + /// axum::Server::bind(&addr) + /// .serve( + /// axum::Router::new() + /// // Connect to hot reloading in debug mode + /// .connect_hot_reload() + /// .into_make_service(), + /// ) + /// .await + /// .unwrap(); + /// } + /// ``` + fn connect_hot_reload(self) -> Self; + + /// Serves the static WASM for your Dioxus application (except the generated index.html). + /// + /// # Example + /// ```rust + /// #![allow(non_snake_case)] + /// use dioxus::prelude::*; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + /// axum::Server::bind(&addr) + /// .serve( + /// axum::Router::new() + /// // Server side render the application, serve static assets, and register server functions + /// .serve_static_assets(ServeConfigBuilder::new(app, ())) + /// // Server render the application + /// // ... + /// .into_make_service(), + /// ) + /// .await + /// .unwrap(); + /// } + /// + /// fn app(cx: Scope) -> Element { + /// todo!() + /// } + /// ``` + fn serve_static_assets(self, assets_path: impl Into) -> Self; + + /// Serves the Dioxus application. This will serve a complete server side rendered application. + /// This will serve static assets, server render the application, register server functions, and intigrate with hot reloading. + /// + /// # Example + /// ```rust + /// #![allow(non_snake_case)] + /// use dioxus::prelude::*; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080)); + /// axum::Server::bind(&addr) + /// .serve( + /// axum::Router::new() + /// // Server side render the application, serve static assets, and register server functions + /// .serve_dioxus_application("", ServeConfigBuilder::new(app, ())) + /// .into_make_service(), + /// ) + /// .await + /// .unwrap(); + /// } + /// + /// fn app(cx: Scope) -> Element { + /// todo!() + /// } + /// ``` + fn serve_dioxus_application( + self, + server_fn_route: &'static str, + cfg: impl Into>, + ) -> Self; +} + +impl DioxusRouterExt for Router +where + S: Send + Sync + Clone + 'static, +{ + fn register_server_fns_with_handler( + self, + server_fn_route: &'static str, + mut handler: impl FnMut(server_fn::ServerFnTraitObj) -> H, + ) -> Self + where + H: Handler, + T: 'static, + S: Clone + Send + Sync + 'static, + { + let mut router = self; + for server_fn_path in DioxusServerFnRegistry::paths_registered() { + let func = DioxusServerFnRegistry::get(server_fn_path).unwrap(); + let full_route = format!("{server_fn_route}/{server_fn_path}"); + match func.encoding() { + Encoding::Url | Encoding::Cbor => { + router = router.route(&full_route, post(handler(func))); + } + Encoding::GetJSON | Encoding::GetCBOR => { + router = router.route(&full_route, get(handler(func))); + } + } + } + router + } + + fn register_server_fns(self, server_fn_route: &'static str) -> Self { + self.register_server_fns_with_handler(server_fn_route, |func| { + move |req: Request| async move { + let (parts, body) = req.into_parts(); + let parts: Arc = Arc::new(parts.into()); + let server_context = DioxusServerContext::new(parts.clone()); + server_fn_handler(server_context, func.clone(), parts, body).await + } + }) + } + + fn serve_static_assets(mut self, assets_path: impl Into) -> Self { + use tower_http::services::{ServeDir, ServeFile}; + + let assets_path = assets_path.into(); + + // Serve all files in dist folder except index.html + let dir = std::fs::read_dir(&assets_path).unwrap_or_else(|e| { + panic!( + "Couldn't read assets directory at {:?}: {}", + &assets_path, e + ) + }); + + for entry in dir.flatten() { + let path = entry.path(); + if path.ends_with("index.html") { + continue; + } + let route = path + .strip_prefix(&assets_path) + .unwrap() + .iter() + .map(|segment| { + segment.to_str().unwrap_or_else(|| { + panic!("Failed to convert path segment {:?} to string", segment) + }) + }) + .collect::>() + .join("/"); + let route = format!("/{}", route); + if path.is_dir() { + self = self.nest_service(&route, ServeDir::new(path)); + } else { + self = self.nest_service(&route, ServeFile::new(path)); + } + } + + self + } + + fn serve_dioxus_application( + self, + server_fn_route: &'static str, + cfg: impl Into>, + ) -> Self { + let cfg = cfg.into(); + + // Add server functions and render index.html + self.serve_static_assets(cfg.assets_path) + .route( + "/", + get(render_handler).with_state((cfg, SSRState::default())), + ) + .connect_hot_reload() + .register_server_fns(server_fn_route) + } + + fn connect_hot_reload(self) -> Self { + #[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] + { + self.nest( + "/_dioxus", + Router::new() + .route( + "/disconnect", + get(|ws: WebSocketUpgrade| async { + ws.on_upgrade(|mut ws| async move { + use axum::extract::ws::Message; + let _ = ws.send(Message::Text("connected".into())).await; + loop { + if ws.recv().await.is_none() { + break; + } + } + }) + }), + ) + .route("/hot_reload", get(hot_reload_handler)), + ) + } + #[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))] + { + self + } + } +} + +async fn render_handler( + State((cfg, ssr_state)): State<(ServeConfig

, SSRState)>, + request: Request, +) -> impl IntoResponse { + let (parts, _) = request.into_parts(); + let parts: Arc = Arc::new(parts.into()); + let server_context = DioxusServerContext::new(parts); + let mut vdom = + VirtualDom::new_with_props(cfg.app, cfg.props.clone()).with_root_context(server_context); + let _ = vdom.rebuild(); + + let rendered = ssr_state.render_vdom(&vdom, &cfg); + Full::from(rendered) +} + +/// A default handler for server functions. It will deserialize the request, call the server function, and serialize the response. +pub async fn server_fn_handler( + server_context: DioxusServerContext, + function: server_fn::ServerFnTraitObj, + parts: Arc, + body: Body, +) -> impl IntoResponse { + let body = hyper::body::to_bytes(body).await; + let Ok(body) = body else { + return report_err(body.err().unwrap()); + }; + + // Because the future returned by `server_fn_handler` is `Send`, and the future returned by this function must be send, we need to spawn a new runtime + let (resp_tx, resp_rx) = tokio::sync::oneshot::channel(); + let query_string = parts.uri.query().unwrap_or_default().to_string(); + spawn_blocking({ + move || { + tokio::runtime::Runtime::new() + .expect("couldn't spawn runtime") + .block_on(async { + let query = &query_string.into(); + let data = match &function.encoding() { + Encoding::Url | Encoding::Cbor => &body, + Encoding::GetJSON | Encoding::GetCBOR => query, + }; + let resp = match function.call(server_context.clone(), data).await { + Ok(serialized) => { + // if this is Accept: application/json then send a serialized JSON response + let accept_header = parts + .headers + .get("Accept") + .and_then(|value| value.to_str().ok()); + let mut res = Response::builder(); + *res.headers_mut().expect("empty response should be valid") = + server_context.take_response_headers(); + if accept_header == Some("application/json") + || accept_header + == Some( + "application/\ + x-www-form-urlencoded", + ) + || accept_header == Some("application/cbor") + { + res = res.status(StatusCode::OK); + } + + let resp = match serialized { + Payload::Binary(data) => res + .header("Content-Type", "application/cbor") + .body(body::boxed(Full::from(data))), + Payload::Url(data) => res + .header( + "Content-Type", + "application/\ + x-www-form-urlencoded", + ) + .body(body::boxed(data)), + Payload::Json(data) => res + .header("Content-Type", "application/json") + .body(body::boxed(data)), + }; + + resp.unwrap() + } + Err(e) => report_err(e), + }; + + resp_tx.send(resp).unwrap(); + }) + } + }); + resp_rx.await.unwrap() +} + +fn report_err(e: E) -> Response { + Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(body::boxed(format!("Error: {}", e))) + .unwrap() +} + +/// A handler for Dioxus web hot reload websocket. This will send the updated static parts of the RSX to the client when they change. +#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] +pub async fn hot_reload_handler(ws: WebSocketUpgrade) -> impl IntoResponse { + use axum::extract::ws::Message; + use futures_util::StreamExt; + + let state = crate::hot_reload::spawn_hot_reload().await; + + ws.on_upgrade(move |mut socket| async move { + println!("🔥 Hot Reload WebSocket connected"); + { + // update any rsx calls that changed before the websocket connected. + { + println!("🔮 Finding updates since last compile..."); + let templates_read = state.templates.read().await; + + for template in &*templates_read { + if socket + .send(Message::Text(serde_json::to_string(&template).unwrap())) + .await + .is_err() + { + return; + } + } + } + println!("finished"); + } + + let mut rx = + tokio_stream::wrappers::WatchStream::from_changes(state.message_receiver.clone()); + while let Some(change) = rx.next().await { + if let Some(template) = change { + let template = { serde_json::to_string(&template).unwrap() }; + if socket.send(Message::Text(template)).await.is_err() { + break; + }; + } + } + }) +} diff --git a/packages/fullstack/src/adapters/mod.rs b/packages/fullstack/src/adapters/mod.rs new file mode 100644 index 000000000..5809132b8 --- /dev/null +++ b/packages/fullstack/src/adapters/mod.rs @@ -0,0 +1,18 @@ +//! # Adapters +//! Adapters for different web frameworks. +//! +//! Each adapter provides a set of utilities that is ergonomic to use with the framework. +//! +//! Each framework has utilies for some or all of the following: +//! - Server functions +//! - A generic way to register server functions +//! - A way to register server functions with a custom handler that allows users to pass in a custom [`crate::server_context::DioxusServerContext`] based on the state of the server framework. +//! - A way to register static WASM files that is accepts [`crate::serve_config::ServeConfig`] +//! - A hot reloading web socket that intigrates with [`dioxus-hot-reload`](https://crates.io/crates/dioxus-hot-reload) + +#[cfg(feature = "axum")] +pub mod axum_adapter; +#[cfg(feature = "salvo")] +pub mod salvo_adapter; +#[cfg(feature = "warp")] +pub mod warp_adapter; diff --git a/packages/fullstack/src/adapters/salvo_adapter.rs b/packages/fullstack/src/adapters/salvo_adapter.rs new file mode 100644 index 000000000..59b7c36ea --- /dev/null +++ b/packages/fullstack/src/adapters/salvo_adapter.rs @@ -0,0 +1,556 @@ +//! Dioxus utilities for the [Salvo](https://salvo.rs) server framework. +//! +//! # Example +//! ```rust +//! #![allow(non_snake_case)] +//! use dioxus::prelude::*; +//! use dioxus_fullstack::prelude::*; +//! +//! fn main() { +//! #[cfg(feature = "web")] +//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true)); +//! #[cfg(feature = "ssr")] +//! { +//! use salvo::prelude::*; +//! tokio::runtime::Runtime::new() +//! .unwrap() +//! .block_on(async move { +//! let router = +//! Router::new().serve_dioxus_application("", ServeConfigBuilder::new(app, ())); +//! Server::new(TcpListener::bind("127.0.0.1:8080")) +//! .serve(router) +//! .await; +//! }); +//! } +//! } +//! +//! fn app(cx: Scope) -> Element { +//! let text = use_state(cx, || "...".to_string()); +//! +//! cx.render(rsx! { +//! button { +//! onclick: move |_| { +//! to_owned![text]; +//! async move { +//! if let Ok(data) = get_server_data().await { +//! text.set(data); +//! } +//! } +//! }, +//! "Run a server function" +//! } +//! "Server said: {text}" +//! }) +//! } +//! +//! #[server(GetServerData)] +//! async fn get_server_data() -> Result { +//! Ok("Hello from the server!".to_string()) +//! } +//! ``` + +use dioxus_core::VirtualDom; +use hyper::{http::HeaderValue, StatusCode}; +use salvo::{ + async_trait, handler, + serve_static::{StaticDir, StaticFile}, + Depot, FlowCtrl, Handler, Request, Response, Router, +}; +use server_fn::{Encoding, Payload, ServerFunctionRegistry}; +use std::error::Error; +use std::sync::Arc; +use tokio::task::spawn_blocking; + +use crate::{ + prelude::*, render::SSRState, serve_config::ServeConfig, server_fn::DioxusServerFnRegistry, +}; + +/// A extension trait with utilities for integrating Dioxus with your Salvo router. +pub trait DioxusRouterExt { + /// Registers server functions with a custom handler function. This allows you to pass custom context to your server functions by generating a [`DioxusServerContext`] from the request. + /// + /// # Example + /// ```rust + /// use salvo::prelude::*; + /// use std::{net::TcpListener, sync::Arc}; + /// use dioxus_fullstack::prelude::*; + /// + /// struct ServerFunctionHandler { + /// server_fn: server_fn::ServerFnTraitObj, + /// } + /// + /// #[handler] + /// impl ServerFunctionHandler { + /// async fn handle( + /// &self, + /// req: &mut Request, + /// depot: &mut Depot, + /// res: &mut Response, + /// flow: &mut FlowCtrl, + /// ) { + /// // Add the headers to server context + /// ServerFnHandler::new((req.headers().clone(),), self.server_fn.clone()) + /// .handle(req, depot, res, flow) + /// .await + /// } + /// } + /// + /// #[tokio::main] + /// async fn main() { + /// let router = Router::new() + /// .register_server_fns_with_handler("", |func| { + /// ServerFnHandler::new(DioxusServerContext::default(), func) + /// }); + /// Server::new(TcpListener::bind("127.0.0.1:8080")) + /// .serve(router) + /// .await; + /// } + /// ``` + fn register_server_fns_with_handler( + self, + server_fn_route: &'static str, + handler: impl Fn(server_fn::ServerFnTraitObj) -> H, + ) -> Self + where + H: Handler + 'static; + + /// Registers server functions with the default handler. This handler function will pass an empty [`DioxusServerContext`] to your server functions. + /// + /// # Example + /// ```rust + /// use salvo::prelude::*; + /// use std::{net::TcpListener, sync::Arc}; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let router = Router::new() + /// .register_server_fns(""); + /// Server::new(TcpListener::bind("127.0.0.1:8080")) + /// .serve(router) + /// .await; + /// } + /// + /// ``` + fn register_server_fns(self, server_fn_route: &'static str) -> Self; + + /// Register the web RSX hot reloading endpoint. This will enable hot reloading for your application in debug mode when you call [`dioxus_hot_reload::hot_reload_init`]. + /// + /// # Example + /// ```rust + /// use salvo::prelude::*; + /// use std::{net::TcpListener, sync::Arc}; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let router = Router::new() + /// .connect_hot_reload(); + /// Server::new(TcpListener::bind("127.0.0.1:8080")) + /// .serve(router) + /// .await; + /// } + fn connect_hot_reload(self) -> Self; + + /// Serves the static WASM for your Dioxus application (except the generated index.html). + /// + /// # Example + /// ```rust + /// use salvo::prelude::*; + /// use std::{net::TcpListener, sync::Arc}; + /// use dioxus_fullstack::prelude::*; + /// + /// #[tokio::main] + /// async fn main() { + /// let router = Router::new() + /// .server_static_assets("/dist"); + /// Server::new(TcpListener::bind("127.0.0.1:8080")) + /// .serve(router) + /// .await; + /// } + /// ``` + fn serve_static_assets(self, assets_path: impl Into) -> Self; + + /// Serves the Dioxus application. This will serve a complete server side rendered application. + /// This will serve static assets, server render the application, register server functions, and intigrate with hot reloading. + /// + /// # Example + /// ```rust + /// #![allow(non_snake_case)] + /// use dioxus::prelude::*; + /// use dioxus_fullstack::prelude::*; + /// use salvo::prelude::*; + /// use std::{net::TcpListener, sync::Arc}; + /// + /// #[tokio::main] + /// async fn main() { + /// let router = Router::new().serve_dioxus_application("", ServeConfigBuilder::new(app, ())); + /// Server::new(TcpListener::bind("127.0.0.1:8080")) + /// .serve(router) + /// .await; + /// } + /// + /// fn app(cx: Scope) -> Element {todo!()} + /// ``` + fn serve_dioxus_application( + self, + server_fn_path: &'static str, + cfg: impl Into>, + ) -> Self; +} + +impl DioxusRouterExt for Router { + fn register_server_fns_with_handler( + self, + server_fn_route: &'static str, + mut handler: impl FnMut(server_fn::ServerFnTraitObj) -> H, + ) -> Self + where + H: Handler + 'static, + { + let mut router = self; + for server_fn_path in DioxusServerFnRegistry::paths_registered() { + let func = DioxusServerFnRegistry::get(server_fn_path).unwrap(); + let full_route = format!("{server_fn_route}/{server_fn_path}"); + match func.encoding() { + Encoding::Url | Encoding::Cbor => { + router = router.push(Router::with_path(&full_route).post(handler(func))); + } + Encoding::GetJSON | Encoding::GetCBOR => { + router = router.push(Router::with_path(&full_route).get(handler(func))); + } + } + } + router + } + + fn register_server_fns(self, server_fn_route: &'static str) -> Self { + self.register_server_fns_with_handler(server_fn_route, |func| ServerFnHandler { + server_context: DioxusServerContext::default(), + function: func, + }) + } + + fn serve_static_assets(mut self, assets_path: impl Into) -> Self { + let assets_path = assets_path.into(); + + // Serve all files in dist folder except index.html + let dir = std::fs::read_dir(&assets_path).unwrap_or_else(|e| { + panic!( + "Couldn't read assets directory at {:?}: {}", + &assets_path, e + ) + }); + + for entry in dir.flatten() { + let path = entry.path(); + if path.ends_with("index.html") { + continue; + } + let route = path + .strip_prefix(&assets_path) + .unwrap() + .iter() + .map(|segment| { + segment.to_str().unwrap_or_else(|| { + panic!("Failed to convert path segment {:?} to string", segment) + }) + }) + .collect::>() + .join("/"); + if path.is_file() { + let route = format!("/{}", route); + let serve_dir = StaticFile::new(path.clone()); + self = self.push(Router::with_path(route).get(serve_dir)) + } else { + let route = format!("/{}/<**path>", route); + let serve_dir = StaticDir::new([path.clone()]); + self = self.push(Router::with_path(route).get(serve_dir)) + } + } + + self + } + + fn serve_dioxus_application( + self, + server_fn_path: &'static str, + cfg: impl Into>, + ) -> Self { + let cfg = cfg.into(); + + self.serve_static_assets(cfg.assets_path) + .connect_hot_reload() + .register_server_fns(server_fn_path) + .push(Router::with_path("/").get(SSRHandler { cfg })) + } + + fn connect_hot_reload(self) -> Self { + let mut _dioxus_router = Router::with_path("_dioxus"); + _dioxus_router = + _dioxus_router.push(Router::with_path("hot_reload").handle(HotReloadHandler)); + #[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] + { + _dioxus_router = _dioxus_router.push(Router::with_path("disconnect").handle(ignore_ws)); + } + self.push(_dioxus_router) + } +} + +/// Extracts the parts of a request that are needed for server functions. This will take parts of the request and replace them with empty values. +pub fn extract_parts(req: &mut Request) -> RequestParts { + RequestParts { + method: std::mem::take(req.method_mut()), + uri: std::mem::take(req.uri_mut()), + version: req.version(), + headers: std::mem::take(req.headers_mut()), + extensions: std::mem::take(req.extensions_mut()), + } +} + +struct SSRHandler { + cfg: ServeConfig

, +} + +#[async_trait] +impl Handler for SSRHandler

{ + async fn handle( + &self, + req: &mut Request, + depot: &mut Depot, + res: &mut Response, + _flow: &mut FlowCtrl, + ) { + // Get the SSR renderer from the depot or create a new one if it doesn't exist + let renderer_pool = if let Some(renderer) = depot.obtain::() { + renderer.clone() + } else { + let renderer = SSRState::default(); + depot.inject(renderer.clone()); + renderer + }; + let parts: Arc = Arc::new(extract_parts(req)); + let server_context = DioxusServerContext::new(parts); + let mut vdom = VirtualDom::new_with_props(self.cfg.app, self.cfg.props.clone()) + .with_root_context(server_context.clone()); + let _ = vdom.rebuild(); + + res.write_body(renderer_pool.render_vdom(&vdom, &self.cfg)) + .unwrap(); + + *res.headers_mut() = server_context.take_response_headers(); + } +} + +/// A default handler for server functions. It will deserialize the request body, call the server function, and serialize the response. +pub struct ServerFnHandler { + server_context: DioxusServerContext, + function: server_fn::ServerFnTraitObj, +} + +impl ServerFnHandler { + /// Create a new server function handler with the given server context and server function. + pub fn new( + server_context: impl Into, + function: server_fn::ServerFnTraitObj, + ) -> Self { + let server_context = server_context.into(); + Self { + server_context, + function, + } + } +} + +#[handler] +impl ServerFnHandler { + async fn handle(&self, req: &mut Request, _depot: &mut Depot, res: &mut Response) { + let Self { + server_context, + function, + } = self; + + let query = req + .uri() + .query() + .unwrap_or_default() + .as_bytes() + .to_vec() + .into(); + let body = hyper::body::to_bytes(req.body_mut().unwrap()).await; + let Ok(body)=body else { + handle_error(body.err().unwrap(), res); + return; + }; + let headers = req.headers(); + let accept_header = headers.get("Accept").cloned(); + + let parts = Arc::new(extract_parts(req)); + + // Because the future returned by `server_fn_handler` is `Send`, and the future returned by this function must be send, we need to spawn a new runtime + let (resp_tx, resp_rx) = tokio::sync::oneshot::channel(); + spawn_blocking({ + let function = function.clone(); + let mut server_context = server_context.clone(); + server_context.parts = parts; + move || { + tokio::runtime::Runtime::new() + .expect("couldn't spawn runtime") + .block_on(async move { + let data = match function.encoding() { + Encoding::Url | Encoding::Cbor => &body, + Encoding::GetJSON | Encoding::GetCBOR => &query, + }; + let resp = function.call(server_context, data).await; + + resp_tx.send(resp).unwrap(); + }) + } + }); + let result = resp_rx.await.unwrap(); + + // Set the headers from the server context + *res.headers_mut() = server_context.take_response_headers(); + + match result { + Ok(serialized) => { + // if this is Accept: application/json then send a serialized JSON response + let accept_header = accept_header.as_ref().and_then(|value| value.to_str().ok()); + if accept_header == Some("application/json") + || accept_header + == Some( + "application/\ + x-www-form-urlencoded", + ) + || accept_header == Some("application/cbor") + { + res.set_status_code(StatusCode::OK); + } + + match serialized { + Payload::Binary(data) => { + res.headers_mut() + .insert("Content-Type", HeaderValue::from_static("application/cbor")); + res.write_body(data).unwrap(); + } + Payload::Url(data) => { + res.headers_mut().insert( + "Content-Type", + HeaderValue::from_static( + "application/\ + x-www-form-urlencoded", + ), + ); + res.write_body(data).unwrap(); + } + Payload::Json(data) => { + res.headers_mut() + .insert("Content-Type", HeaderValue::from_static("application/json")); + res.write_body(data).unwrap(); + } + } + } + Err(err) => handle_error(err, res), + } + } +} + +fn handle_error(error: impl Error + Send + Sync, res: &mut Response) { + let mut resp_err = Response::new(); + resp_err.set_status_code(StatusCode::INTERNAL_SERVER_ERROR); + resp_err.render(format!("Internal Server Error: {}", error)); + *res = resp_err; +} + +/// A handler for Dioxus web hot reload websocket. This will send the updated static parts of the RSX to the client when they change. +#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))] +#[derive(Default)] +pub struct HotReloadHandler; + +#[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))] +#[handler] +impl HotReloadHandler { + async fn handle( + &self, + _req: &mut Request, + _depot: &mut Depot, + _res: &mut Response, + ) -> Result<(), salvo::http::StatusError> { + Err(salvo::http::StatusError::not_found()) + } +} + +/// A handler for Dioxus web hot reload websocket. This will send the updated static parts of the RSX to the client when they change. +#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] +#[derive(Default)] +pub struct HotReloadHandler; + +#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] +#[handler] +impl HotReloadHandler { + async fn handle( + &self, + req: &mut Request, + _depot: &mut Depot, + res: &mut Response, + ) -> Result<(), salvo::http::StatusError> { + use salvo::ws::Message; + use salvo::ws::WebSocketUpgrade; + + let state = crate::hot_reload::spawn_hot_reload().await; + + WebSocketUpgrade::new() + .upgrade(req, res, move |mut websocket| async move { + use futures_util::StreamExt; + + println!("🔥 Hot Reload WebSocket connected"); + { + // update any rsx calls that changed before the websocket connected. + { + println!("🔮 Finding updates since last compile..."); + let templates_read = state.templates.read().await; + + for template in &*templates_read { + if websocket + .send(Message::text(serde_json::to_string(&template).unwrap())) + .await + .is_err() + { + return; + } + } + } + println!("finished"); + } + + let mut rx = tokio_stream::wrappers::WatchStream::from_changes( + state.message_receiver.clone(), + ); + while let Some(change) = rx.next().await { + if let Some(template) = change { + let template = { serde_json::to_string(&template).unwrap() }; + if websocket.send(Message::text(template)).await.is_err() { + break; + }; + } + } + }) + .await + } +} + +#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] +#[handler] +async fn ignore_ws(req: &mut Request, res: &mut Response) -> Result<(), salvo::http::StatusError> { + use salvo::ws::WebSocketUpgrade; + WebSocketUpgrade::new() + .upgrade(req, res, |mut ws| async move { + let _ = ws.send(salvo::ws::Message::text("connected")).await; + while let Some(msg) = ws.recv().await { + if msg.is_err() { + return; + }; + } + }) + .await +} diff --git a/packages/fullstack/src/adapters/warp_adapter.rs b/packages/fullstack/src/adapters/warp_adapter.rs new file mode 100644 index 000000000..b9f23ae7f --- /dev/null +++ b/packages/fullstack/src/adapters/warp_adapter.rs @@ -0,0 +1,443 @@ +//! Dioxus utilities for the [Warp](https://docs.rs/warp/latest/warp/index.html) server framework. +//! +//! # Example +//! ```rust +//! #![allow(non_snake_case)] +//! use dioxus::prelude::*; +//! use dioxus_fullstack::prelude::*; +//! +//! fn main() { +//! #[cfg(feature = "web")] +//! dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true)); +//! #[cfg(feature = "ssr")] +//! { +//! tokio::runtime::Runtime::new() +//! .unwrap() +//! .block_on(async move { +//! let routes = serve_dioxus_application("", ServeConfigBuilder::new(app, ())); +//! warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; +//! }); +//! } +//! } +//! +//! fn app(cx: Scope) -> Element { +//! let text = use_state(cx, || "...".to_string()); +//! +//! cx.render(rsx! { +//! button { +//! onclick: move |_| { +//! to_owned![text]; +//! async move { +//! if let Ok(data) = get_server_data().await { +//! text.set(data); +//! } +//! } +//! }, +//! "Run a server function" +//! } +//! "Server said: {text}" +//! }) +//! } +//! +//! #[server(GetServerData)] +//! async fn get_server_data() -> Result { +//! Ok("Hello from the server!".to_string()) +//! } +//! +//! ``` + +use crate::{ + prelude::*, render::SSRState, serve_config::ServeConfig, server_fn::DioxusServerFnRegistry, +}; + +use dioxus_core::VirtualDom; +use server_fn::{Encoding, Payload, ServerFunctionRegistry}; +use std::error::Error; +use std::sync::Arc; +use tokio::task::spawn_blocking; +use warp::path::FullPath; +use warp::{ + filters::BoxedFilter, + http::{Response, StatusCode}, + hyper::body::Bytes, + path, Filter, Reply, +}; + +/// Registers server functions with a custom handler function. This allows you to pass custom context to your server functions by generating a [`DioxusServerContext`] from the request. +/// +/// # Example +/// ```rust +/// use warp::{body, header, hyper::HeaderMap, path, post, Filter}; +/// +/// #[tokio::main] +/// async fn main() { +/// let routes = register_server_fns_with_handler("", |full_route, func| { +/// path(full_route) +/// .and(post()) +/// .and(header::headers_cloned()) +/// .and(body::bytes()) +/// .and_then(move |headers: HeaderMap, body| { +/// let func = func.clone(); +/// async move { +/// // Add the headers to the server function context +/// server_fn_handler((headers.clone(),), func, headers, body).await +/// } +/// }) +/// }); +/// warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; +/// } +/// ``` +pub fn register_server_fns_with_handler( + server_fn_route: &'static str, + mut handler: H, +) -> BoxedFilter<(R,)> +where + H: FnMut(String, server_fn::ServerFnTraitObj) -> F, + F: Filter + Send + Sync + 'static, + F::Extract: Send, + R: Reply + 'static, +{ + let mut filter: Option> = None; + for server_fn_path in DioxusServerFnRegistry::paths_registered() { + let func = DioxusServerFnRegistry::get(server_fn_path).unwrap(); + let full_route = format!("{server_fn_route}/{server_fn_path}") + .trim_start_matches('/') + .to_string(); + let route = handler(full_route, func).boxed(); + if let Some(boxed_filter) = filter.take() { + filter = Some(boxed_filter.or(route).unify().boxed()); + } else { + filter = Some(route); + } + } + filter.expect("No server functions found") +} + +/// Registers server functions with the default handler. This handler function will pass an empty [`DioxusServerContext`] to your server functions. +/// +/// # Example +/// ```rust +/// use dioxus_fullstack::prelude::*; +/// +/// #[tokio::main] +/// async fn main() { +/// let routes = register_server_fns(""); +/// warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; +/// } +/// ``` +pub fn register_server_fns(server_fn_route: &'static str) -> BoxedFilter<(impl Reply,)> { + register_server_fns_with_handler(server_fn_route, |full_route, func| { + path(full_route) + .and(warp::post().or(warp::get()).unify()) + .and(request_parts()) + .and(warp::body::bytes()) + .and_then(move |parts, bytes| { + let func = func.clone(); + async move { + server_fn_handler(DioxusServerContext::default(), func, parts, bytes).await + } + }) + }) +} + +/// Serves the Dioxus application. This will serve a complete server side rendered application. +/// This will serve static assets, server render the application, register server functions, and intigrate with hot reloading. +/// +/// # Example +/// ```rust +/// #![allow(non_snake_case)] +/// use dioxus::prelude::*; +/// use dioxus_fullstack::prelude::*; +/// +/// #[tokio::main] +/// async fn main() { +/// let routes = serve_dioxus_application("", ServeConfigBuilder::new(app, ())); +/// warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; +/// } +/// +/// fn app(cx: Scope) -> Element { +/// todo!() +/// } +/// ``` +pub fn serve_dioxus_application( + server_fn_route: &'static str, + cfg: impl Into>, +) -> BoxedFilter<(impl Reply,)> { + let cfg = cfg.into(); + // Serve the dist folder and the index.html file + let serve_dir = warp::fs::dir(cfg.assets_path); + + connect_hot_reload() + .or(register_server_fns(server_fn_route)) + .or(warp::path::end().and(render_ssr(cfg))) + .or(serve_dir) + .boxed() +} + +/// Server render the application. +pub fn render_ssr( + cfg: ServeConfig

, +) -> impl Filter + Clone { + warp::get() + .and(request_parts()) + .and(with_ssr_state()) + .map(move |parts, renderer: SSRState| { + let parts = Arc::new(parts); + + let server_context = DioxusServerContext::new(parts); + + let mut vdom = VirtualDom::new_with_props(cfg.app, cfg.props.clone()) + .with_root_context(server_context.clone()); + let _ = vdom.rebuild(); + + let html = renderer.render_vdom(&vdom, &cfg); + + let mut res = Response::builder(); + + *res.headers_mut().expect("empty request should be valid") = + server_context.take_response_headers(); + + res.header("Content-Type", "text/html") + .body(Bytes::from(html)) + .unwrap() + }) +} + +/// An extractor for the request parts (used in [DioxusServerContext]). This will extract the method, uri, query, and headers from the request. +pub fn request_parts( +) -> impl Filter + Clone { + warp::method() + .and(warp::filters::path::full()) + .and( + warp::filters::query::raw() + .or(warp::any().map(String::new)) + .unify(), + ) + .and(warp::header::headers_cloned()) + .and_then(move |method, path: FullPath, query, headers| async move { + http::uri::Builder::new() + .path_and_query(format!("{}?{}", path.as_str(), query)) + .build() + .map_err(|err| { + warp::reject::custom(FailedToReadBody(format!("Failed to build uri: {}", err))) + }) + .map(|uri| RequestParts { + method, + uri, + headers, + ..Default::default() + }) + }) +} + +fn with_ssr_state() -> impl Filter + Clone +{ + let state = SSRState::default(); + warp::any().map(move || state.clone()) +} + +#[derive(Debug)] +struct FailedToReadBody(String); + +impl warp::reject::Reject for FailedToReadBody {} + +#[derive(Debug)] +struct RecieveFailed(String); + +impl warp::reject::Reject for RecieveFailed {} + +/// A default handler for server functions. It will deserialize the request body, call the server function, and serialize the response. +pub async fn server_fn_handler( + server_context: impl Into, + function: server_fn::ServerFnTraitObj, + parts: RequestParts, + body: Bytes, +) -> Result, warp::Rejection> { + let mut server_context = server_context.into(); + + let parts = Arc::new(parts); + + server_context.parts = parts.clone(); + + // Because the future returned by `server_fn_handler` is `Send`, and the future returned by this function must be send, we need to spawn a new runtime + let (resp_tx, resp_rx) = tokio::sync::oneshot::channel(); + spawn_blocking({ + move || { + tokio::runtime::Runtime::new() + .expect("couldn't spawn runtime") + .block_on(async move { + let query = parts + .uri + .query() + .unwrap_or_default() + .as_bytes() + .to_vec() + .into(); + let data = match function.encoding() { + Encoding::Url | Encoding::Cbor => &body, + Encoding::GetJSON | Encoding::GetCBOR => &query, + }; + let resp = match function.call(server_context.clone(), data).await { + Ok(serialized) => { + // if this is Accept: application/json then send a serialized JSON response + let accept_header = parts + .headers + .get("Accept") + .as_ref() + .and_then(|value| value.to_str().ok()); + let mut res = Response::builder(); + + *res.headers_mut().expect("empty request should be valid") = + server_context.take_response_headers(); + + if accept_header == Some("application/json") + || accept_header + == Some( + "application/\ + x-www-form-urlencoded", + ) + || accept_header == Some("application/cbor") + { + res = res.status(StatusCode::OK); + } + + let resp = match serialized { + Payload::Binary(data) => res + .header("Content-Type", "application/cbor") + .body(Bytes::from(data)), + Payload::Url(data) => res + .header( + "Content-Type", + "application/\ + x-www-form-urlencoded", + ) + .body(Bytes::from(data)), + Payload::Json(data) => res + .header("Content-Type", "application/json") + .body(Bytes::from(data)), + }; + + Box::new(resp.unwrap()) + } + Err(e) => report_err(e), + }; + + if resp_tx.send(resp).is_err() { + eprintln!("Error sending response"); + } + }) + } + }); + resp_rx.await.map_err(|err| { + warp::reject::custom(RecieveFailed(format!("Failed to recieve response {err}"))) + }) +} + +fn report_err(e: E) -> Box { + Box::new( + Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .body(format!("Error: {}", e)) + .unwrap(), + ) as Box +} + +/// Register the web RSX hot reloading endpoint. This will enable hot reloading for your application in debug mode when you call [`dioxus_hot_reload::hot_reload_init`]. +/// +/// # Example +/// ```rust +/// #![allow(non_snake_case)] +/// use dioxus_fullstack::prelude::*; +/// +/// #[tokio::main] +/// async fn main() { +/// let routes = connect_hot_reload(); +/// warp::serve(routes).run(([127, 0, 0, 1], 8080)).await; +/// } +/// ``` +pub fn connect_hot_reload() -> impl Filter + Clone +{ + #[cfg(not(all(debug_assertions, feature = "hot-reload", feature = "ssr")))] + { + warp::path!("_dioxus" / "hot_reload") + .and(warp::ws()) + .map(warp::reply) + .map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND)); + } + #[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] + { + use crate::hot_reload::HotReloadState; + use futures_util::sink::SinkExt; + use futures_util::StreamExt; + use warp::ws::Message; + + let hot_reload = warp::path!("_dioxus" / "hot_reload") + .and(warp::any().then(crate::hot_reload::spawn_hot_reload)) + .and(warp::ws()) + .map(move |state: &'static HotReloadState, ws: warp::ws::Ws| { + #[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] + ws.on_upgrade(move |mut websocket| { + async move { + println!("🔥 Hot Reload WebSocket connected"); + { + // update any rsx calls that changed before the websocket connected. + { + println!("🔮 Finding updates since last compile..."); + let templates_read = state.templates.read().await; + + for template in &*templates_read { + if websocket + .send(Message::text( + serde_json::to_string(&template).unwrap(), + )) + .await + .is_err() + { + return; + } + } + } + println!("finished"); + } + + let mut rx = tokio_stream::wrappers::WatchStream::from_changes( + state.message_receiver.clone(), + ); + while let Some(change) = rx.next().await { + if let Some(template) = change { + let template = { serde_json::to_string(&template).unwrap() }; + if websocket.send(Message::text(template)).await.is_err() { + break; + }; + } + } + } + }) + }); + let disconnect = + warp::path!("_dioxus" / "disconnect") + .and(warp::ws()) + .map(move |ws: warp::ws::Ws| { + println!("disconnect"); + #[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] + ws.on_upgrade(move |mut websocket| async move { + struct DisconnectOnDrop(Option); + impl Drop for DisconnectOnDrop { + fn drop(&mut self) { + std::mem::drop(self.0.take().unwrap().close()); + } + } + + let _ = websocket.send(Message::text("connected")).await; + let mut ws = DisconnectOnDrop(Some(websocket)); + + loop { + if ws.0.as_mut().unwrap().next().await.is_none() { + break; + } + } + }) + }); + disconnect.or(hot_reload) + } +} diff --git a/packages/fullstack/src/hot_reload.rs b/packages/fullstack/src/hot_reload.rs new file mode 100644 index 000000000..31a05e1c9 --- /dev/null +++ b/packages/fullstack/src/hot_reload.rs @@ -0,0 +1,61 @@ +use std::sync::Arc; + +use dioxus_core::Template; +use tokio::sync::{ + watch::{channel, Receiver}, + RwLock, +}; + +#[derive(Clone)] +pub struct HotReloadState { + // The cache of all templates that have been modified since the last time we checked + pub(crate) templates: Arc>>>, + // The channel to send messages to the hot reload thread + pub(crate) message_receiver: Receiver>>, +} + +impl Default for HotReloadState { + fn default() -> Self { + let templates = Arc::new(RwLock::new(std::collections::HashSet::new())); + let (tx, rx) = channel(None); + + dioxus_hot_reload::connect({ + let templates = templates.clone(); + move |msg| match msg { + dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => { + { + let mut templates = templates.blocking_write(); + templates.insert(template); + } + + if let Err(err) = tx.send(Some(template)) { + log::error!("Failed to send hot reload message: {}", err); + } + } + dioxus_hot_reload::HotReloadMsg::Shutdown => { + std::process::exit(0); + } + } + }); + + Self { + templates, + message_receiver: rx, + } + } +} + +// Hot reloading can be expensive to start so we spawn a new thread +static HOT_RELOAD_STATE: tokio::sync::OnceCell = tokio::sync::OnceCell::const_new(); +pub(crate) async fn spawn_hot_reload() -> &'static HotReloadState { + HOT_RELOAD_STATE + .get_or_init(|| async { + println!("spinning up hot reloading"); + let r = tokio::task::spawn_blocking(HotReloadState::default) + .await + .unwrap(); + println!("hot reloading ready"); + r + }) + .await +} diff --git a/packages/fullstack/src/lib.rs b/packages/fullstack/src/lib.rs new file mode 100644 index 000000000..18cde9adb --- /dev/null +++ b/packages/fullstack/src/lib.rs @@ -0,0 +1,42 @@ +#![doc = include_str!("../README.md")] +#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")] +#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")] +#![deny(missing_docs)] + +pub use adapters::*; + +mod props_html; + +mod adapters; +#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))] +mod hot_reload; +#[cfg(feature = "ssr")] +mod render; +#[cfg(feature = "ssr")] +mod serve_config; +mod server_context; +mod server_fn; + +/// A prelude of commonly used items in dioxus-fullstack. +pub mod prelude { + #[cfg(feature = "axum")] + pub use crate::adapters::axum_adapter::*; + #[cfg(feature = "salvo")] + pub use crate::adapters::salvo_adapter::*; + #[cfg(feature = "warp")] + pub use crate::adapters::warp_adapter::*; + #[cfg(not(feature = "ssr"))] + pub use crate::props_html::deserialize_props::get_root_props_from_document; + #[cfg(feature = "ssr")] + pub use crate::render::SSRState; + #[cfg(feature = "ssr")] + pub use crate::serve_config::{ServeConfig, ServeConfigBuilder}; + #[cfg(feature = "ssr")] + pub use crate::server_context::RequestParts; + pub use crate::server_context::{DioxusServerContext, HasServerContext}; + pub use crate::server_fn::DioxusServerFn; + #[cfg(feature = "ssr")] + pub use crate::server_fn::{ServerFnTraitObj, ServerFunction}; + pub use dioxus_server_macro::*; + pub use server_fn::{self, ServerFn as _, ServerFnError}; +} diff --git a/packages/fullstack/src/props_html/deserialize_props.rs b/packages/fullstack/src/props_html/deserialize_props.rs new file mode 100644 index 000000000..35e54a1e5 --- /dev/null +++ b/packages/fullstack/src/props_html/deserialize_props.rs @@ -0,0 +1,32 @@ +use serde::de::DeserializeOwned; + +use base64::engine::general_purpose::STANDARD; +use base64::Engine; + +#[allow(unused)] +pub(crate) fn serde_from_string(string: &str) -> Option { + let decompressed = STANDARD.decode(string.as_bytes()).ok()?; + let (decompressed, _) = yazi::decompress(&decompressed, yazi::Format::Zlib).unwrap(); + + postcard::from_bytes(&decompressed).ok() +} + +#[cfg(not(feature = "ssr"))] +/// Get the props from the document. This is only available in the browser. +/// +/// When dioxus-fullstack renders the page, it will serialize the root props and put them in the document. This function gets them from the document. +pub fn get_root_props_from_document() -> Option { + #[cfg(not(target_arch = "wasm32"))] + { + None + } + #[cfg(target_arch = "wasm32")] + { + let attribute = web_sys::window()? + .document()? + .get_element_by_id("dioxus-storage")? + .get_attribute("data-serialized")?; + + serde_from_string(&attribute) + } +} diff --git a/packages/fullstack/src/props_html/mod.rs b/packages/fullstack/src/props_html/mod.rs new file mode 100644 index 000000000..048e2aa90 --- /dev/null +++ b/packages/fullstack/src/props_html/mod.rs @@ -0,0 +1,54 @@ +pub(crate) mod deserialize_props; + +pub(crate) mod serialize_props; + +#[test] +fn serialized_and_deserializes() { + use postcard::to_allocvec; + + #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)] + struct Data { + a: u32, + b: String, + bytes: Vec, + nested: Nested, + } + + #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)] + struct Nested { + a: u32, + b: u16, + c: u8, + } + + for x in 0..10usize { + for y in 0..10 { + let mut as_string = String::new(); + let data = vec![ + Data { + a: x as u32, + b: "hello".to_string(), + bytes: vec![0; x], + nested: Nested { + a: 1, + b: x as u16, + c: 3 + }, + }; + y + ]; + serialize_props::serde_to_writable(&data, &mut as_string).unwrap(); + + println!("{}", as_string); + println!( + "original size: {}", + std::mem::size_of::() * data.len() + ); + println!("serialized size: {}", to_allocvec(&data).unwrap().len()); + println!("compressed size: {}", as_string.len()); + + let decoded: Vec = deserialize_props::serde_from_string(&as_string).unwrap(); + assert_eq!(data, decoded); + } + } +} diff --git a/packages/fullstack/src/props_html/serialize_props.rs b/packages/fullstack/src/props_html/serialize_props.rs new file mode 100644 index 000000000..0012afb9c --- /dev/null +++ b/packages/fullstack/src/props_html/serialize_props.rs @@ -0,0 +1,31 @@ +use serde::Serialize; + +use base64::engine::general_purpose::STANDARD; +use base64::Engine; + +#[allow(unused)] +pub(crate) fn serde_to_writable( + value: &T, + mut write_to: impl std::fmt::Write, +) -> std::fmt::Result { + let serialized = postcard::to_allocvec(value).unwrap(); + let compressed = yazi::compress( + &serialized, + yazi::Format::Zlib, + yazi::CompressionLevel::BestSize, + ) + .unwrap(); + write_to.write_str(&STANDARD.encode(compressed)); + Ok(()) +} + +#[cfg(feature = "ssr")] +/// Encode data into a element. This is inteded to be used in the server to send data to the client. +pub(crate) fn encode_in_element( + data: T, + mut write_to: impl std::fmt::Write, +) -> std::fmt::Result { + write_to.write_str(r#""#) +} diff --git a/packages/fullstack/src/render.rs b/packages/fullstack/src/render.rs new file mode 100644 index 000000000..b56016d5e --- /dev/null +++ b/packages/fullstack/src/render.rs @@ -0,0 +1,100 @@ +//! A shared pool of renderers for efficient server side rendering. + +use std::sync::Arc; + +use dioxus_core::VirtualDom; +use dioxus_ssr::Renderer; + +use crate::prelude::ServeConfig; + +/// State used in server side rendering. This utilizes a pool of [`dioxus_ssr::Renderer`]s to cache static templates between renders. +#[derive(Clone)] +pub struct SSRState { + // We keep a pool of renderers to avoid re-creating them on every request. They are boxed to make them very cheap to move + renderers: Arc>, +} + +impl Default for SSRState { + fn default() -> Self { + Self { + renderers: Arc::new(object_pool::Pool::new(10, pre_renderer)), + } + } +} + +impl SSRState { + /// Render the application to HTML. + pub fn render(&self, cfg: &ServeConfig

) -> String { + let ServeConfig { app, props, .. } = cfg; + + let mut vdom = VirtualDom::new_with_props(*app, props.clone()); + + let _ = vdom.rebuild(); + + self.render_vdom(&vdom, cfg) + } + + /// Render a VirtualDom to HTML. + pub fn render_vdom( + &self, + vdom: &VirtualDom, + cfg: &ServeConfig

, + ) -> String { + let ServeConfig { index, .. } = cfg; + + let mut renderer = self.renderers.pull(pre_renderer); + + let mut html = String::new(); + + html += &index.pre_main; + + let _ = renderer.render_to(&mut html, vdom); + + // serialize the props + let _ = crate::props_html::serialize_props::encode_in_element(&cfg.props, &mut html); + + #[cfg(all(debug_assertions, feature = "hot-reload"))] + { + // In debug mode, we need to add a script to the page that will reload the page if the websocket disconnects to make full recompile hot reloads work + let disconnect_js = r#"(function () { + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + const url = protocol + '//' + window.location.host + '/_dioxus/disconnect'; + const poll_interval = 1000; + const reload_upon_connect = () => { + console.log('Disconnected from server. Attempting to reconnect...'); + window.setTimeout( + () => { + // Try to reconnect to the websocket + const ws = new WebSocket(url); + ws.onopen = () => { + // If we reconnect, reload the page + window.location.reload(); + } + // Otherwise, try again in a second + reload_upon_connect(); + }, + poll_interval); + }; + + // on initial page load connect to the disconnect ws + const ws = new WebSocket(url); + // if we disconnect, start polling + ws.onclose = reload_upon_connect; +})()"#; + + html += r#""#; + } + + html += &index.post_main; + + html + } +} + +fn pre_renderer() -> Renderer { + let mut renderer = Renderer::default(); + renderer.pre_render = true; + renderer +} diff --git a/packages/fullstack/src/serve_config.rs b/packages/fullstack/src/serve_config.rs new file mode 100644 index 000000000..b7b29e9fb --- /dev/null +++ b/packages/fullstack/src/serve_config.rs @@ -0,0 +1,115 @@ +//! Configeration for how to serve a Dioxus application + +use std::fs::File; +use std::io::Read; +use std::path::PathBuf; + +use dioxus_core::Component; + +/// A ServeConfig is used to configure how to serve a Dioxus application. It contains information about how to serve static assets, and what content to render with [`dioxus-ssr`]. +#[derive(Clone)] +pub struct ServeConfigBuilder { + pub(crate) app: Component

, + pub(crate) props: P, + pub(crate) root_id: Option<&'static str>, + pub(crate) index_path: Option<&'static str>, + pub(crate) assets_path: Option<&'static str>, +} + +impl ServeConfigBuilder

{ + /// Create a new ServeConfigBuilder with the root component and props to render on the server. + pub fn new(app: Component

, props: P) -> Self { + Self { + app, + props, + root_id: None, + index_path: None, + assets_path: None, + } + } + + /// Set the path of the index.html file to be served. (defaults to {assets_path}/index.html) + pub fn index_path(mut self, index_path: &'static str) -> Self { + self.index_path = Some(index_path); + self + } + + /// Set the id of the root element in the index.html file to place the prerendered content into. (defaults to main) + pub fn root_id(mut self, root_id: &'static str) -> Self { + self.root_id = Some(root_id); + self + } + + /// Set the path of the assets folder generated by the Dioxus CLI. (defaults to dist) + pub fn assets_path(mut self, assets_path: &'static str) -> Self { + self.assets_path = Some(assets_path); + self + } + + /// Build the ServeConfig + pub fn build(self) -> ServeConfig

{ + let assets_path = self.assets_path.unwrap_or("dist"); + + let index_path = self + .index_path + .map(PathBuf::from) + .unwrap_or_else(|| format!("{assets_path}/index.html").into()); + + let root_id = self.root_id.unwrap_or("main"); + + let index = load_index_html(index_path, root_id); + + ServeConfig { + app: self.app, + props: self.props, + index, + assets_path, + } + } +} + +fn load_index_html(path: PathBuf, root_id: &'static str) -> IndexHtml { + let mut file = File::open(path).expect("Failed to find index.html. Make sure the index_path is set correctly and the WASM application has been built."); + + let mut contents = String::new(); + file.read_to_string(&mut contents) + .expect("Failed to read index.html"); + + let (pre_main, post_main) = contents.split_once(&format!("id=\"{root_id}\"")).unwrap_or_else(|| panic!("Failed to find id=\"{root_id}\" in index.html. The id is used to inject the application into the page.")); + + let post_main = post_main.split_once('>').unwrap_or_else(|| { + panic!("Failed to find closing > after id=\"{root_id}\" in index.html.") + }); + + let (pre_main, post_main) = ( + pre_main.to_string() + &format!("id=\"{root_id}\"") + post_main.0 + ">", + post_main.1.to_string(), + ); + + IndexHtml { + pre_main, + post_main, + } +} + +#[derive(Clone)] +pub(crate) struct IndexHtml { + pub(crate) pre_main: String, + pub(crate) post_main: String, +} + +/// Used to configure how to serve a Dioxus application. It contains information about how to serve static assets, and what content to render with [`dioxus-ssr`]. +/// See [`ServeConfigBuilder`] to create a ServeConfig +#[derive(Clone)] +pub struct ServeConfig { + pub(crate) app: Component

, + pub(crate) props: P, + pub(crate) index: IndexHtml, + pub(crate) assets_path: &'static str, +} + +impl From> for ServeConfig

{ + fn from(builder: ServeConfigBuilder

) -> Self { + builder.build() + } +} diff --git a/packages/fullstack/src/server_context.rs b/packages/fullstack/src/server_context.rs new file mode 100644 index 000000000..f225526ec --- /dev/null +++ b/packages/fullstack/src/server_context.rs @@ -0,0 +1,160 @@ +use dioxus_core::ScopeState; + +/// A trait for an object that contains a server context +pub trait HasServerContext { + /// Get the server context from the state + fn server_context(&self) -> DioxusServerContext; + + /// A shortcut for `self.server_context()` + fn sc(&self) -> DioxusServerContext { + self.server_context() + } +} + +impl HasServerContext for &ScopeState { + fn server_context(&self) -> DioxusServerContext { + #[cfg(feature = "ssr")] + { + self.consume_context().expect("No server context found") + } + #[cfg(not(feature = "ssr"))] + { + DioxusServerContext {} + } + } +} + +/// A shared context for server functions that contains infomation about the request and middleware state. +/// This allows you to pass data between your server framework and the server functions. This can be used to pass request information or information about the state of the server. For example, you could pass authentication data though this context to your server functions. +/// +/// You should not construct this directly inside components. Instead use the `HasServerContext` trait to get the server context from the scope. +#[derive(Clone)] +pub struct DioxusServerContext { + #[cfg(feature = "ssr")] + shared_context: std::sync::Arc< + std::sync::RwLock>, + >, + #[cfg(feature = "ssr")] + headers: std::sync::Arc>, + #[cfg(feature = "ssr")] + pub(crate) parts: std::sync::Arc, +} + +#[allow(clippy::derivable_impls)] +impl Default for DioxusServerContext { + fn default() -> Self { + Self { + #[cfg(feature = "ssr")] + shared_context: std::sync::Arc::new(std::sync::RwLock::new(anymap::Map::new())), + #[cfg(feature = "ssr")] + headers: Default::default(), + #[cfg(feature = "ssr")] + parts: Default::default(), + } + } +} + +#[cfg(feature = "ssr")] +pub use server_fn_impl::*; + +#[cfg(feature = "ssr")] +mod server_fn_impl { + use super::*; + use std::sync::LockResult; + use std::sync::{Arc, PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}; + + use anymap::{any::Any, Map}; + type SendSyncAnyMap = Map; + + impl DioxusServerContext { + /// Create a new server context from a request + pub fn new(parts: impl Into>) -> Self { + Self { + parts: parts.into(), + shared_context: Arc::new(RwLock::new(SendSyncAnyMap::new())), + headers: Default::default(), + } + } + + /// Clone a value from the shared server context + pub fn get(&self) -> Option { + self.shared_context.read().ok()?.get::().cloned() + } + + /// Insert a value into the shared server context + pub fn insert( + &mut self, + value: T, + ) -> Result<(), PoisonError>> { + self.shared_context + .write() + .map(|mut map| map.insert(value)) + .map(|_| ()) + } + + /// Get the headers from the server context + pub fn response_headers(&self) -> RwLockReadGuard<'_, hyper::header::HeaderMap> { + self.try_response_headers() + .expect("Failed to get headers from server context") + } + + /// Try to get the headers from the server context + pub fn try_response_headers( + &self, + ) -> LockResult> { + self.headers.read() + } + + /// Get the headers mutably from the server context + pub fn response_headers_mut(&self) -> RwLockWriteGuard<'_, hyper::header::HeaderMap> { + self.try_response_headers_mut() + .expect("Failed to get headers mutably from server context") + } + + /// Try to get the headers mut from the server context + pub fn try_response_headers_mut( + &self, + ) -> LockResult> { + self.headers.write() + } + + pub(crate) fn take_response_headers(&self) -> hyper::header::HeaderMap { + let mut headers = self.headers.write().unwrap(); + std::mem::take(&mut *headers) + } + + /// Get the request that triggered: + /// - The initial SSR render if called from a ScopeState or ServerFn + /// - The server function to be called if called from a server function after the initial render + pub fn request_parts(&self) -> &RequestParts { + &self.parts + } + } + + /// Associated parts of an HTTP Request + #[derive(Debug, Default)] + pub struct RequestParts { + /// The request's method + pub method: http::Method, + /// The request's URI + pub uri: http::Uri, + /// The request's version + pub version: http::Version, + /// The request's headers + pub headers: http::HeaderMap, + /// The request's extensions + pub extensions: http::Extensions, + } + + impl From for RequestParts { + fn from(parts: http::request::Parts) -> Self { + Self { + method: parts.method, + uri: parts.uri, + version: parts.version, + headers: parts.headers, + extensions: parts.extensions, + } + } + } +} diff --git a/packages/fullstack/src/server_fn.rs b/packages/fullstack/src/server_fn.rs new file mode 100644 index 000000000..231285149 --- /dev/null +++ b/packages/fullstack/src/server_fn.rs @@ -0,0 +1,166 @@ +use crate::server_context::DioxusServerContext; + +#[cfg(any(feature = "ssr", doc))] +#[derive(Clone)] +/// A trait object for a function that be called on serializable arguments and returns a serializable result. +pub struct ServerFnTraitObj(server_fn::ServerFnTraitObj); + +#[cfg(any(feature = "ssr", doc))] +impl std::ops::Deref for ServerFnTraitObj { + type Target = server_fn::ServerFnTraitObj; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[cfg(any(feature = "ssr", doc))] +impl std::ops::DerefMut for ServerFnTraitObj { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +#[cfg(any(feature = "ssr", doc))] +impl ServerFnTraitObj { + fn new( + prefix: &'static str, + url: &'static str, + encoding: server_fn::Encoding, + run: ServerFunction, + ) -> Self { + Self(server_fn::ServerFnTraitObj::new(prefix, url, encoding, run)) + } + + /// Create a new `ServerFnTraitObj` from a `server_fn::ServerFnTraitObj`. + pub const fn from_generic_server_fn( + server_fn: server_fn::ServerFnTraitObj, + ) -> Self { + Self(server_fn) + } +} + +#[cfg(any(feature = "ssr", doc))] +server_fn::inventory::collect!(ServerFnTraitObj); + +#[cfg(any(feature = "ssr", doc))] +/// A server function that can be called on serializable arguments and returns a serializable result. +pub type ServerFunction = server_fn::SerializedFnTraitObj; + +#[cfg(any(feature = "ssr", doc))] +#[allow(clippy::type_complexity)] +static REGISTERED_SERVER_FUNCTIONS: once_cell::sync::Lazy< + std::sync::Arc>>, +> = once_cell::sync::Lazy::new(|| { + let mut map = std::collections::HashMap::new(); + for server_fn in server_fn::inventory::iter:: { + map.insert(server_fn.0.url(), server_fn.clone()); + } + std::sync::Arc::new(std::sync::RwLock::new(map)) +}); + +#[cfg(any(feature = "ssr", doc))] +/// The registry of all Dioxus server functions. +pub struct DioxusServerFnRegistry; + +#[cfg(feature = "ssr")] +impl server_fn::ServerFunctionRegistry for DioxusServerFnRegistry { + type Error = ServerRegistrationFnError; + + fn register_explicit( + prefix: &'static str, + url: &'static str, + server_function: ServerFunction, + encoding: server_fn::Encoding, + ) -> Result<(), Self::Error> { + // store it in the hashmap + let mut write = REGISTERED_SERVER_FUNCTIONS + .write() + .map_err(|e| ServerRegistrationFnError::Poisoned(e.to_string()))?; + let prev = write.insert( + url, + ServerFnTraitObj::new(prefix, url, encoding, server_function), + ); + + // if there was already a server function with this key, + // return Err + match prev { + Some(_) => Err(ServerRegistrationFnError::AlreadyRegistered(format!( + "There was already a server function registered at {:?}. \ + This can happen if you use the same server function name \ + in two different modules + on `stable` or in `release` mode.", + url + ))), + None => Ok(()), + } + } + + fn register( + url: &'static str, + server_function: ServerFunction, + encoding: server_fn::Encoding, + ) -> Result<(), Self::Error> { + Self::register_explicit("", url, server_function, encoding) + } + + /// Returns the server function registered at the given URL, or `None` if no function is registered at that URL. + fn get(url: &str) -> Option> { + REGISTERED_SERVER_FUNCTIONS + .read() + .ok() + .and_then(|fns| fns.get(url).map(|inner| inner.0.clone())) + } + + /// Returns the server function registered at the given URL, or `None` if no function is registered at that URL. + fn get_trait_obj(url: &str) -> Option> { + Self::get(url) + } + + fn get_encoding(url: &str) -> Option { + REGISTERED_SERVER_FUNCTIONS + .read() + .ok() + .and_then(|fns| fns.get(url).map(|f| f.encoding())) + } + + /// Returns a list of all registered server functions. + fn paths_registered() -> Vec<&'static str> { + REGISTERED_SERVER_FUNCTIONS + .read() + .ok() + .map(|fns| fns.keys().cloned().collect()) + .unwrap_or_default() + } +} + +#[cfg(any(feature = "ssr", doc))] +/// Errors that can occur when registering a server function. +#[derive(thiserror::Error, Debug, Clone, serde::Serialize, serde::Deserialize)] +pub enum ServerRegistrationFnError { + /// The server function is already registered. + #[error("The server function {0} is already registered")] + AlreadyRegistered(String), + /// The server function registry is poisoned. + #[error("The server function registry is poisoned: {0}")] + Poisoned(String), +} + +/// Defines a "server function." A server function can be called from the server or the client, +/// but the body of its code will only be run on the server, i.e., if a crate feature `ssr` is enabled. +/// +/// Server functions are created using the `server` macro. +/// +/// The set of server functions +/// can be queried on the server for routing purposes by calling [server_fn::ServerFunctionRegistry::get]. +/// +/// Technically, the trait is implemented on a type that describes the server function's arguments, not the function itself. +pub trait DioxusServerFn: server_fn::ServerFn { + /// Registers the server function, allowing the client to query it by URL. + #[cfg(any(feature = "ssr", doc))] + fn register_explicit() -> Result<(), server_fn::ServerFnError> { + Self::register_in_explicit::() + } +} + +impl DioxusServerFn for T where T: server_fn::ServerFn {} diff --git a/packages/hooks/Cargo.toml b/packages/hooks/Cargo.toml index c0e1ea783..c239da698 100644 --- a/packages/hooks/Cargo.toml +++ b/packages/hooks/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "dioxus-hooks" -version = "0.3.0" +version = "0.3.1" authors = ["Jonathan Kelley"] edition = "2018" -description = "Dioxus VirtualDOM renderer for a remote webview instance" +description = "Basic useful hooks for Dioxus." license = "MIT/Apache-2.0" repository = "https://github.com/DioxusLabs/dioxus/" homepage = "https://dioxuslabs.com" @@ -12,12 +12,12 @@ keywords = ["dom", "ui", "gui", "react"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-core = { path = "../../packages/core", version = "^0.3.0" } -futures-channel = "0.3.21" -log = "0.4" +dioxus-core = { workspace = true } +futures-channel = { workspace = true } +log = { workspace = true } [dev-dependencies] -futures-util = { version = "0.3", default-features = false } -dioxus-core = { path = "../../packages/core", version = "^0.3.0" } -dioxus = { path = "../../packages/dioxus", version = "^0.3.0" } +futures-util = { workspace = true, default-features = false } +dioxus-core = { workspace = true } +dioxus = { workspace = true } diff --git a/packages/hooks/src/use_shared_state.rs b/packages/hooks/src/use_shared_state.rs index eb836a211..3a3a4d639 100644 --- a/packages/hooks/src/use_shared_state.rs +++ b/packages/hooks/src/use_shared_state.rs @@ -71,7 +71,7 @@ impl ProvidedStateInner { /// let current_theme = *theme.read(); /// /// render! { -/// match &*theme.read() { +/// match current_theme { /// Theme::Dark => { /// "Dark mode" /// } diff --git a/packages/hooks/src/usecoroutine.rs b/packages/hooks/src/usecoroutine.rs index bc97735b9..b19a355d0 100644 --- a/packages/hooks/src/usecoroutine.rs +++ b/packages/hooks/src/usecoroutine.rs @@ -34,6 +34,10 @@ use std::future::Future; /// don't care about actions in your app being synchronized, you can use [`use_callback`] /// hook to spawn multiple tasks and run them concurrently. /// +/// ### Notice +/// In order to use ``rx.next().await``, you will need to extend the ``Stream`` trait (used by ``UnboundedReceiver``) +/// by adding the ``futures-util`` crate as a dependency and adding ``StreamExt`` into scope via ``use futures_util::stream::StreamExt;`` +/// /// ## Example /// /// ```rust, ignore diff --git a/packages/hooks/src/usefuture.rs b/packages/hooks/src/usefuture.rs index f540e0a6e..18bf50310 100644 --- a/packages/hooks/src/usefuture.rs +++ b/packages/hooks/src/usefuture.rs @@ -89,6 +89,14 @@ pub struct UseFuture { values: Rc>>, } +impl Drop for UseFuture { + fn drop(&mut self) { + for value in self.values.take().into_iter() { + drop(unsafe { Box::from_raw(value) }) + } + } +} + pub enum UseFutureState<'a, T> { Pending, Complete(&'a T), diff --git a/packages/hot-reload/Cargo.toml b/packages/hot-reload/Cargo.toml index 2d88bf029..b53a87809 100644 --- a/packages/hot-reload/Cargo.toml +++ b/packages/hot-reload/Cargo.toml @@ -12,13 +12,13 @@ keywords = ["dom", "ui", "gui", "react", "hot-reloading"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-rsx = { path = "../rsx" , version = "^0.0.3" } -dioxus-core = { path = "../core", features = ["serialize"], version = "^0.3.2"} -dioxus-html = { path = "../html", features = ["hot-reload-context"], version = "^0.3.0" } +dioxus-rsx = { workspace = true } +dioxus-core = { workspace = true, features = ["serialize"] } +dioxus-html = { workspace = true, features = ["hot-reload-context"] } -interprocess = { version = "1.2.1" } +interprocess-docfix = { version = "1.2.1" } notify = "5.0.0" -chrono = "0.4.23" +chrono = { version = "0.4.24", default-features = false, features = ["clock"] } serde_json = "1.0.91" serde = { version = "1", features = ["derive"] } execute = "0.2.11" diff --git a/packages/hot-reload/src/lib.rs b/packages/hot-reload/src/lib.rs index d144fccfc..48ee50a59 100644 --- a/packages/hot-reload/src/lib.rs +++ b/packages/hot-reload/src/lib.rs @@ -10,7 +10,7 @@ use dioxus_rsx::{ hot_reload::{FileMap, FileMapBuildResult, UpdateResult}, HotReloadingContext, }; -use interprocess::local_socket::{LocalSocketListener, LocalSocketStream}; +use interprocess_docfix::local_socket::{LocalSocketListener, LocalSocketStream}; use notify::{RecommendedWatcher, RecursiveMode, Watcher}; pub use dioxus_html::HtmlCtx; @@ -159,173 +159,190 @@ pub fn init(cfg: Config) { } let file_map = Arc::new(Mutex::new(file_map)); - if let Ok(local_socket_stream) = LocalSocketListener::bind("@dioxusin") { - let aborted = Arc::new(Mutex::new(false)); - - // listen for connections - std::thread::spawn({ - let file_map = file_map.clone(); - let channels = channels.clone(); - let aborted = aborted.clone(); - let _ = local_socket_stream.set_nonblocking(true); - move || { - loop { - if let Ok(mut connection) = local_socket_stream.accept() { - // send any templates than have changed before the socket connected - let templates: Vec<_> = { - file_map - .lock() - .unwrap() - .map - .values() - .filter_map(|(_, template_slot)| *template_slot) - .collect() - }; - for template in templates { - if !send_msg( - HotReloadMsg::UpdateTemplate(template), - &mut connection, - ) { - continue; - } - } - channels.lock().unwrap().push(connection); - if log { - println!("Connected to hot reloading 🚀"); - } - } - std::thread::sleep(std::time::Duration::from_millis(10)); - if *aborted.lock().unwrap() { - break; - } - } + #[cfg(target_os = "macos")] + { + // On unix, if you force quit the application, it can leave the file socket open + // This will cause the local socket listener to fail to open + // We check if the file socket is already open from an old session and then delete it + let paths = ["./dioxusin", "./@dioxusin"]; + for path in paths { + let path = PathBuf::from(path); + if path.exists() { + let _ = std::fs::remove_file(path); } - }); + } + } - // watch for changes - std::thread::spawn(move || { - let mut last_update_time = chrono::Local::now().timestamp(); + match LocalSocketListener::bind("@dioxusin") { + Ok(local_socket_stream) => { + let aborted = Arc::new(Mutex::new(false)); - let (tx, rx) = std::sync::mpsc::channel(); - - let mut watcher = RecommendedWatcher::new(tx, notify::Config::default()).unwrap(); - - for path in listening_paths { - let full_path = crate_dir.join(path); - if let Err(err) = watcher.watch(&full_path, RecursiveMode::Recursive) { - if log { - println!( - "hot reloading failed to start watching {full_path:?}:\n{err:?}", - ); - } - } - } - - let mut rebuild = { - let aborted = aborted.clone(); + // listen for connections + std::thread::spawn({ + let file_map = file_map.clone(); let channels = channels.clone(); + let aborted = aborted.clone(); + let _ = local_socket_stream.set_nonblocking(true); move || { - if let Some(rebuild_callback) = &mut rebuild_with { - if log { - println!("Rebuilding the application..."); - } - let shutdown = rebuild_callback(); - - if shutdown { - *aborted.lock().unwrap() = true; - } - - for channel in &mut *channels.lock().unwrap() { - send_msg(HotReloadMsg::Shutdown, channel); - } - - return shutdown; - } else if log { - println!( - "Rebuild needed... shutting down hot reloading.\nManually rebuild the application to view futher changes." - ); - } - true - } - }; - - for evt in rx { - if chrono::Local::now().timestamp() > last_update_time { - if let Ok(evt) = evt { - let real_paths = evt - .paths - .iter() - .filter(|path| { - // skip non rust files - matches!( - path.extension().and_then(|p| p.to_str()), - Some("rs" | "toml" | "css" | "html" | "js") - ) && - // skip excluded paths - !excluded_paths.iter().any(|p| path.starts_with(p)) && - // respect .gitignore - !gitignore - .matched_path_or_any_parents(path, false) - .is_ignore() - }) - .collect::>(); - - // Give time for the change to take effect before reading the file - if !real_paths.is_empty() { - std::thread::sleep(std::time::Duration::from_millis(10)); - } - - let mut channels = channels.lock().unwrap(); - for path in real_paths { - // if this file type cannot be hot reloaded, rebuild the application - if path.extension().and_then(|p| p.to_str()) != Some("rs") - && rebuild() - { - return; + loop { + if let Ok(mut connection) = local_socket_stream.accept() { + // send any templates than have changed before the socket connected + let templates: Vec<_> = { + file_map + .lock() + .unwrap() + .map + .values() + .filter_map(|(_, template_slot)| *template_slot) + .collect() + }; + for template in templates { + if !send_msg( + HotReloadMsg::UpdateTemplate(template), + &mut connection, + ) { + continue; + } } - // find changes to the rsx in the file - match file_map - .lock() - .unwrap() - .update_rsx(path, crate_dir.as_path()) - { - Ok(UpdateResult::UpdatedRsx(msgs)) => { - for msg in msgs { - let mut i = 0; - while i < channels.len() { - let channel = &mut channels[i]; - if send_msg( - HotReloadMsg::UpdateTemplate(msg), - channel, - ) { - i += 1; - } else { - channels.remove(i); + channels.lock().unwrap().push(connection); + if log { + println!("Connected to hot reloading 🚀"); + } + } + if *aborted.lock().unwrap() { + break; + } + } + } + }); + + // watch for changes + std::thread::spawn(move || { + let mut last_update_time = chrono::Local::now().timestamp(); + + let (tx, rx) = std::sync::mpsc::channel(); + + let mut watcher = + RecommendedWatcher::new(tx, notify::Config::default()).unwrap(); + + for path in listening_paths { + let full_path = crate_dir.join(path); + if let Err(err) = watcher.watch(&full_path, RecursiveMode::Recursive) { + if log { + println!( + "hot reloading failed to start watching {full_path:?}:\n{err:?}", + ); + } + } + } + + let mut rebuild = { + let aborted = aborted.clone(); + let channels = channels.clone(); + move || { + if let Some(rebuild_callback) = &mut rebuild_with { + if log { + println!("Rebuilding the application..."); + } + let shutdown = rebuild_callback(); + + if shutdown { + *aborted.lock().unwrap() = true; + } + + for channel in &mut *channels.lock().unwrap() { + send_msg(HotReloadMsg::Shutdown, channel); + } + + return shutdown; + } else if log { + println!( + "Rebuild needed... shutting down hot reloading.\nManually rebuild the application to view futher changes." + ); + } + true + } + }; + + for evt in rx { + if chrono::Local::now().timestamp_millis() >= last_update_time { + if let Ok(evt) = evt { + let real_paths = evt + .paths + .iter() + .filter(|path| { + // skip non rust files + matches!( + path.extension().and_then(|p| p.to_str()), + Some("rs" | "toml" | "css" | "html" | "js") + ) && + // skip excluded paths + !excluded_paths.iter().any(|p| path.starts_with(p)) && + // respect .gitignore + !gitignore + .matched_path_or_any_parents(path, false) + .is_ignore() + }) + .collect::>(); + + // Give time for the change to take effect before reading the file + if !real_paths.is_empty() { + std::thread::sleep(std::time::Duration::from_millis(10)); + } + + let mut channels = channels.lock().unwrap(); + for path in real_paths { + // if this file type cannot be hot reloaded, rebuild the application + if path.extension().and_then(|p| p.to_str()) != Some("rs") + && rebuild() + { + return; + } + // find changes to the rsx in the file + match file_map + .lock() + .unwrap() + .update_rsx(path, crate_dir.as_path()) + { + Ok(UpdateResult::UpdatedRsx(msgs)) => { + for msg in msgs { + let mut i = 0; + while i < channels.len() { + let channel = &mut channels[i]; + if send_msg( + HotReloadMsg::UpdateTemplate(msg), + channel, + ) { + i += 1; + } else { + channels.remove(i); + } } } } - } - Ok(UpdateResult::NeedsRebuild) => { - drop(channels); - if rebuild() { - return; + Ok(UpdateResult::NeedsRebuild) => { + drop(channels); + if rebuild() { + return; + } + break; } - break; - } - Err(err) => { - if log { - println!( - "hot reloading failed to update rsx:\n{err:?}" - ); + Err(err) => { + if log { + println!( + "hot reloading failed to update rsx:\n{err:?}" + ); + } } } } } + last_update_time = chrono::Local::now().timestamp_millis(); } - last_update_time = chrono::Local::now().timestamp(); } - } - }); + }); + } + Err(error) => println!("failed to connect to hot reloading\n{error}"), } } } diff --git a/packages/html/Cargo.toml b/packages/html/Cargo.toml index e60fcd8e5..5a9a51aa8 100644 --- a/packages/html/Cargo.toml +++ b/packages/html/Cargo.toml @@ -11,16 +11,18 @@ documentation = "https://dioxuslabs.com" keywords = ["dom", "ui", "gui", "react"] [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0" } -dioxus-rsx = { path = "../rsx", version = "^0.0.3", optional = true } +dioxus-core = { workspace = true } +dioxus-rsx = { workspace = true, optional = true } serde = { version = "1", features = ["derive"], optional = true } serde_repr = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2.79", optional = true } +wasm-bindgen = { workspace = true, optional = true } euclid = "0.22.7" enumset = "1.0.11" keyboard-types = "0.6.2" async-trait = "0.1.58" serde-value = "0.7.0" +tokio = { workspace = true, features = ["fs", "io-util"], optional = true } +rfd = { version = "0.11.3", optional = true } [dependencies.web-sys] optional = true @@ -39,6 +41,11 @@ features = [ "FocusEvent", "CompositionEvent", "ClipboardEvent", + "Element", + "DomRect", + "ScrollIntoViewOptions", + "ScrollLogicalPosition", + "ScrollBehavior", ] [dev-dependencies] @@ -48,4 +55,5 @@ serde_json = "1" default = ["serialize"] serialize = ["serde", "serde_repr", "euclid/serde", "keyboard-types/serde", "dioxus-core/serialize"] wasm-bind = ["web-sys", "wasm-bindgen"] +native-bind = ["tokio", "rfd"] hot-reload-context = ["dioxus-rsx"] diff --git a/packages/html/src/elements.rs b/packages/html/src/elements.rs index 3fc400ea9..e1e80057e 100644 --- a/packages/html/src/elements.rs +++ b/packages/html/src/elements.rs @@ -31,16 +31,16 @@ macro_rules! impl_attribute { ( $(#[$attr_method:meta])* - $fil:ident: $vil:ident (in $ns:ident), + $fil:ident: $vil:ident (in $ns:literal), ) => { - pub const $fil: AttributeDiscription = (stringify!($fil), Some(stringify!($ns)), false) + pub const $fil: AttributeDiscription = (stringify!($fil), Some($ns), false) }; ( $(#[$attr_method:meta])* - $fil:ident: $vil:ident (in $ns:ident : volatile), + $fil:ident: $vil:ident (in $ns:literal : volatile), ) => { - pub const $fil: AttributeDiscription = (stringify!($fil), Some(stringify!($ns)), true) + pub const $fil: AttributeDiscription = (stringify!($fil), Some($ns), true) }; } @@ -71,10 +71,10 @@ macro_rules! impl_attribute_match { }; ( - $attr:ident $fil:ident: $vil:ident (in $ns:ident), + $attr:ident $fil:ident: $vil:ident (in $ns:literal), ) => { if $attr == stringify!($fil) { - return Some((stringify!(fil), Some(stringify!(ns)))); + return Some((stringify!(fil), Some(ns))); } }; } @@ -110,7 +110,7 @@ macro_rules! impl_element { ( $(#[$attr:meta])* - $name:ident $namespace:tt { + $name:ident $namespace:literal { $( $(#[$attr_method:meta])* $fil:ident: $vil:ident $extra:tt, @@ -130,7 +130,35 @@ macro_rules! impl_element { $( impl_attribute!( $(#[$attr_method])* - $fil: $vil in $namespace $extra + $fil: $vil ($extra), + ); + )* + } + }; + + ( + $(#[$attr:meta])* + $element:ident [$name:literal, $namespace:tt] { + $( + $(#[$attr_method:meta])* + $fil:ident: $vil:ident $extra:tt, + )* + } + ) => { + #[allow(non_camel_case_types)] + $(#[$attr])* + pub struct $element; + + impl SvgAttributes for $element {} + + impl $element { + pub const TAG_NAME: &'static str = $name; + pub const NAME_SPACE: Option<&'static str> = Some($namespace); + + $( + impl_attribute!( + $(#[$attr_method])* + $fil: $vil ($extra), ); )* } @@ -192,7 +220,7 @@ macro_rules! impl_element_match_attributes { if $el == stringify!($name) { $( impl_attribute_match!( - $attr $fil: $vil in $namespace $extra + $attr $fil: $vil ($extra), ); )* } @@ -359,6 +387,11 @@ builder_constructors! { /// element. header None {}; + /// Build a + /// [`

`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hgroup) + /// element. + hgroup None {}; + /// Build a /// [`

`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1) /// element. @@ -1121,6 +1154,7 @@ builder_constructors! { r#type: InputType "type", // value: String, value: String volatile, + initial_value: String DEFAULT, }; /// Build a @@ -1594,7 +1628,7 @@ builder_constructors! { // /// Build a // /// [``](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use) // /// element. - // use "http://www.w3.org/2000/svg" {}; - - + r#use ["use", "http://www.w3.org/2000/svg"] { + href: String DEFAULT, + }; } diff --git a/packages/html/src/events.rs b/packages/html/src/events.rs index 853400c28..85a408d0b 100644 --- a/packages/html/src/events.rs +++ b/packages/html/src/events.rs @@ -33,6 +33,7 @@ mod form; mod image; mod keyboard; mod media; +mod mounted; mod mouse; mod pointer; mod scroll; @@ -51,6 +52,7 @@ pub use form::*; pub use image::*; pub use keyboard::*; pub use media::*; +pub use mounted::*; pub use mouse::*; pub use pointer::*; pub use scroll::*; @@ -144,6 +146,7 @@ pub fn event_bubbles(evt: &str) -> bool { "animationiteration" => true, "transitionend" => true, "toggle" => true, + "mounted" => false, _ => true, } } diff --git a/packages/html/src/events/form.rs b/packages/html/src/events/form.rs index 361ebe2d4..113c765c5 100644 --- a/packages/html/src/events/form.rs +++ b/packages/html/src/events/form.rs @@ -10,12 +10,61 @@ pub type FormEvent = Event; pub struct FormData { pub value: String, - pub values: HashMap, + pub values: HashMap>, - #[cfg_attr(feature = "serialize", serde(skip))] + #[cfg_attr( + feature = "serialize", + serde( + default, + skip_serializing, + deserialize_with = "deserialize_file_engine" + ) + )] pub files: Option>, } +#[cfg(feature = "serialize")] +#[derive(serde::Serialize, serde::Deserialize)] +struct SerializedFileEngine { + files: HashMap>, +} + +#[cfg(feature = "serialize")] +#[async_trait::async_trait(?Send)] +impl FileEngine for SerializedFileEngine { + fn files(&self) -> Vec { + self.files.keys().cloned().collect() + } + + async fn read_file(&self, file: &str) -> Option> { + self.files.get(file).cloned() + } + + async fn read_file_to_string(&self, file: &str) -> Option { + self.read_file(file) + .await + .map(|bytes| String::from_utf8_lossy(&bytes).to_string()) + } +} + +#[cfg(feature = "serialize")] +fn deserialize_file_engine<'de, D>( + deserializer: D, +) -> Result>, D::Error> +where + D: serde::Deserializer<'de>, +{ + use serde::Deserialize; + + let Ok(file_engine) = + SerializedFileEngine::deserialize(deserializer) else{ + return Ok(None); + }; + + let file_engine = std::sync::Arc::new(file_engine); + Ok(Some(file_engine)) +} + impl PartialEq for FormData { fn eq(&self, other: &Self) -> bool { self.value == other.value && self.values == other.values diff --git a/packages/html/src/events/mounted.rs b/packages/html/src/events/mounted.rs new file mode 100644 index 000000000..293b51b9e --- /dev/null +++ b/packages/html/src/events/mounted.rs @@ -0,0 +1,131 @@ +//! Handles quering data from the renderer + +use euclid::Rect; + +use std::{ + any::Any, + fmt::{Display, Formatter}, + future::Future, + pin::Pin, + rc::Rc, +}; + +/// An Element that has been rendered and allows reading and modifying information about it. +/// +/// Different platforms will have different implementations and different levels of support for this trait. Renderers that do not support specific features will return `None` for those queries. +// we can not use async_trait here because it does not create a trait that is object safe +pub trait RenderedElementBacking { + /// Get the renderer specific element for the given id + fn get_raw_element(&self) -> MountedResult<&dyn Any> { + Err(MountedError::NotSupported) + } + + /// Get the bounding rectangle of the element relative to the viewport (this does not include the scroll position) + #[allow(clippy::type_complexity)] + fn get_client_rect(&self) -> Pin>>>> { + Box::pin(async { Err(MountedError::NotSupported) }) + } + + /// Scroll to make the element visible + fn scroll_to( + &self, + _behavior: ScrollBehavior, + ) -> Pin>>> { + Box::pin(async { Err(MountedError::NotSupported) }) + } + + /// Set the focus on the element + fn set_focus(&self, _focus: bool) -> Pin>>> { + Box::pin(async { Err(MountedError::NotSupported) }) + } +} + +impl RenderedElementBacking for () {} + +/// The way that scrolling should be performed +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +pub enum ScrollBehavior { + /// Scroll to the element immediately + #[cfg_attr(feature = "serialize", serde(rename = "instant"))] + Instant, + /// Scroll to the element smoothly + #[cfg_attr(feature = "serialize", serde(rename = "smooth"))] + Smooth, +} + +/// An Element that has been rendered and allows reading and modifying information about it. +/// +/// Different platforms will have different implementations and different levels of support for this trait. Renderers that do not support specific features will return `None` for those queries. +pub struct MountedData { + inner: Rc, +} + +impl MountedData { + /// Create a new MountedData + pub fn new(registry: impl RenderedElementBacking + 'static) -> Self { + Self { + inner: Rc::new(registry), + } + } + + /// Get the renderer specific element for the given id + pub fn get_raw_element(&self) -> MountedResult<&dyn Any> { + self.inner.get_raw_element() + } + + /// Get the bounding rectangle of the element relative to the viewport (this does not include the scroll position) + pub async fn get_client_rect(&self) -> MountedResult> { + self.inner.get_client_rect().await + } + + /// Scroll to make the element visible + pub fn scroll_to( + &self, + behavior: ScrollBehavior, + ) -> Pin>>> { + self.inner.scroll_to(behavior) + } + + /// Set the focus on the element + pub fn set_focus(&self, focus: bool) -> Pin>>> { + self.inner.set_focus(focus) + } +} + +use dioxus_core::Event; + +pub type MountedEvent = Event; + +impl_event! [ + MountedData; + + /// mounted + onmounted +]; + +/// The MountedResult type for the MountedData +pub type MountedResult = Result; + +#[derive(Debug)] +/// The error type for the MountedData +pub enum MountedError { + /// The renderer does not support the requested operation + NotSupported, + /// The element was not found + OperationFailed(Box), +} + +impl Display for MountedError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + MountedError::NotSupported => { + write!(f, "The renderer does not support the requested operation") + } + MountedError::OperationFailed(e) => { + write!(f, "The operation failed: {}", e) + } + } + } +} + +impl std::error::Error for MountedError {} diff --git a/packages/html/src/lib.rs b/packages/html/src/lib.rs index 55e2e3f30..e02ba2d5a 100644 --- a/packages/html/src/lib.rs +++ b/packages/html/src/lib.rs @@ -20,6 +20,8 @@ pub mod events; pub mod geometry; mod global_attributes; pub mod input_data; +#[cfg(feature = "native-bind")] +pub mod native_bind; mod render_template; #[cfg(feature = "wasm-bind")] mod web_sys_bind; diff --git a/packages/html/src/native_bind/mod.rs b/packages/html/src/native_bind/mod.rs new file mode 100644 index 000000000..4d84a4ab3 --- /dev/null +++ b/packages/html/src/native_bind/mod.rs @@ -0,0 +1,3 @@ +mod native_file_engine; + +pub use native_file_engine::*; diff --git a/packages/html/src/native_bind/native_file_engine.rs b/packages/html/src/native_bind/native_file_engine.rs new file mode 100644 index 000000000..e3291fa36 --- /dev/null +++ b/packages/html/src/native_bind/native_file_engine.rs @@ -0,0 +1,43 @@ +use std::path::PathBuf; + +use crate::FileEngine; +use tokio::fs::File; +use tokio::io::AsyncReadExt; + +pub struct NativeFileEngine { + files: Vec, +} + +impl NativeFileEngine { + pub fn new(files: Vec) -> Self { + Self { files } + } +} + +#[async_trait::async_trait(?Send)] +impl FileEngine for NativeFileEngine { + fn files(&self) -> Vec { + self.files + .iter() + .filter_map(|f| Some(f.to_str()?.to_string())) + .collect() + } + + async fn read_file(&self, file: &str) -> Option> { + let mut file = File::open(file).await.ok()?; + + let mut contents = Vec::new(); + file.read_to_end(&mut contents).await.ok()?; + + Some(contents) + } + + async fn read_file_to_string(&self, file: &str) -> Option { + let mut file = File::open(file).await.ok()?; + + let mut contents = String::new(); + file.read_to_string(&mut contents).await.ok()?; + + Some(contents) + } +} diff --git a/packages/html/src/transit.rs b/packages/html/src/transit.rs index 651b7e4f6..ef0e7c70d 100644 --- a/packages/html/src/transit.rs +++ b/packages/html/src/transit.rs @@ -113,6 +113,9 @@ fn fun_name( // Toggle "toggle" => Toggle(de(data)?), + // Mounted + "mounted" => Mounted, + // ImageData => "load" | "error"; // OtherData => "abort" | "afterprint" | "beforeprint" | "beforeunload" | "hashchange" | "languagechange" | "message" | "offline" | "online" | "pagehide" | "pageshow" | "popstate" | "rejectionhandled" | "storage" | "unhandledrejection" | "unload" | "userproximity" | "vrdisplayactivate" | "vrdisplayblur" | "vrdisplayconnect" | "vrdisplaydeactivate" | "vrdisplaydisconnect" | "vrdisplayfocus" | "vrdisplaypointerrestricted" | "vrdisplaypointerunrestricted" | "vrdisplaypresentchange"; other => { @@ -151,6 +154,7 @@ pub enum EventData { Animation(AnimationData), Transition(TransitionData), Toggle(ToggleData), + Mounted, } impl EventData { @@ -172,6 +176,7 @@ impl EventData { EventData::Animation(data) => Rc::new(data) as Rc, EventData::Transition(data) => Rc::new(data) as Rc, EventData::Toggle(data) => Rc::new(data) as Rc, + EventData::Mounted => Rc::new(MountedData::new(())) as Rc, } } } diff --git a/packages/html/src/web_sys_bind/events.rs b/packages/html/src/web_sys_bind/events.rs index 196099444..bcbe80dda 100644 --- a/packages/html/src/web_sys_bind/events.rs +++ b/packages/html/src/web_sys_bind/events.rs @@ -4,14 +4,18 @@ use crate::events::{ }; use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint}; use crate::input_data::{decode_key_location, decode_mouse_button_set, MouseButton}; -use crate::DragData; +use crate::{ + DragData, MountedData, MountedError, MountedResult, RenderedElementBacking, ScrollBehavior, +}; use keyboard_types::{Code, Key, Modifiers}; use std::convert::TryInto; +use std::future::Future; +use std::pin::Pin; use std::str::FromStr; -use wasm_bindgen::JsCast; +use wasm_bindgen::{JsCast, JsValue}; use web_sys::{ - AnimationEvent, CompositionEvent, Event, KeyboardEvent, MouseEvent, PointerEvent, TouchEvent, - TransitionEvent, WheelEvent, + AnimationEvent, CompositionEvent, Event, KeyboardEvent, MouseEvent, PointerEvent, + ScrollIntoViewOptions, TouchEvent, TransitionEvent, WheelEvent, }; macro_rules! uncheck_convert { @@ -193,3 +197,64 @@ impl From<&TransitionEvent> for TransitionData { } } } + +impl From<&web_sys::Element> for MountedData { + fn from(e: &web_sys::Element) -> Self { + MountedData::new(e.clone()) + } +} + +impl RenderedElementBacking for web_sys::Element { + fn get_client_rect( + &self, + ) -> Pin>>>> { + let rect = self.get_bounding_client_rect(); + let result = Ok(euclid::Rect::new( + euclid::Point2D::new(rect.left(), rect.top()), + euclid::Size2D::new(rect.width(), rect.height()), + )); + Box::pin(async { result }) + } + + fn get_raw_element(&self) -> MountedResult<&dyn std::any::Any> { + Ok(self) + } + + fn scroll_to( + &self, + behavior: ScrollBehavior, + ) -> Pin>>> { + match behavior { + ScrollBehavior::Instant => self.scroll_into_view_with_scroll_into_view_options( + ScrollIntoViewOptions::new().behavior(web_sys::ScrollBehavior::Instant), + ), + ScrollBehavior::Smooth => self.scroll_into_view_with_scroll_into_view_options( + ScrollIntoViewOptions::new().behavior(web_sys::ScrollBehavior::Smooth), + ), + } + + Box::pin(async { Ok(()) }) + } + + fn set_focus(&self, focus: bool) -> Pin>>> { + let result = self + .dyn_ref::() + .ok_or_else(|| MountedError::OperationFailed(Box::new(FocusError(self.into())))) + .and_then(|e| { + (if focus { e.focus() } else { e.blur() }) + .map_err(|err| MountedError::OperationFailed(Box::new(FocusError(err)))) + }); + Box::pin(async { result }) + } +} + +#[derive(Debug)] +struct FocusError(JsValue); + +impl std::fmt::Display for FocusError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "failed to focus element {:?}", self.0) + } +} + +impl std::error::Error for FocusError {} diff --git a/packages/interpreter/Cargo.toml b/packages/interpreter/Cargo.toml index 76f9e19ca..b54a61e44 100644 --- a/packages/interpreter/Cargo.toml +++ b/packages/interpreter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dioxus-interpreter-js" -version = "0.3.1" +version = "0.3.3" edition = "2018" authors = ["Jonathan Kelley"] description = "JS Intepreter for Dioxus - a concurrent renderer-agnostic Virtual DOM for interactive user experiences" @@ -13,13 +13,16 @@ keywords = ["dom", "ui", "gui", "react", "wasm"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -wasm-bindgen = { version = "0.2.79", optional = true } +wasm-bindgen = { workspace = true, optional = true } js-sys = { version = "0.3.56", optional = true } web-sys = { version = "0.3.56", optional = true, features = ["Element", "Node"] } sledgehammer_bindgen = { version = "0.2.1", optional = true } sledgehammer_utils = { version = "0.1.1", optional = true } +serde = { version = "1.0", features = ["derive"], optional = true } [features] default = [] +serialize = ["serde"] web = ["wasm-bindgen", "js-sys", "web-sys"] sledgehammer = ["wasm-bindgen", "js-sys", "web-sys", "sledgehammer_bindgen", "sledgehammer_utils"] +minimal_bindings = [] diff --git a/packages/interpreter/src/bindings.rs b/packages/interpreter/src/bindings.rs index 478b8ca5c..4fd9016f1 100644 --- a/packages/interpreter/src/bindings.rs +++ b/packages/interpreter/src/bindings.rs @@ -6,10 +6,14 @@ use web_sys::Element; #[wasm_bindgen(module = "/src/interpreter.js")] extern "C" { + pub type InterpreterConfig; + #[wasm_bindgen(constructor)] + pub fn new(intercept_link_redirects: bool) -> InterpreterConfig; + pub type Interpreter; #[wasm_bindgen(constructor)] - pub fn new(arg: Element) -> Interpreter; + pub fn new(arg: Element, config: InterpreterConfig) -> Interpreter; #[wasm_bindgen(method)] pub fn SaveTemplate(this: &Interpreter, template: JsValue); diff --git a/packages/interpreter/src/common.js b/packages/interpreter/src/common.js new file mode 100644 index 000000000..c93f9eb60 --- /dev/null +++ b/packages/interpreter/src/common.js @@ -0,0 +1,72 @@ +const bool_attrs = { + allowfullscreen: true, + allowpaymentrequest: true, + async: true, + autofocus: true, + autoplay: true, + checked: true, + controls: true, + default: true, + defer: true, + disabled: true, + formnovalidate: true, + hidden: true, + ismap: true, + itemscope: true, + loop: true, + multiple: true, + muted: true, + nomodule: true, + novalidate: true, + open: true, + playsinline: true, + readonly: true, + required: true, + reversed: true, + selected: true, + truespeed: true, +}; + +export function setAttributeInner(node, field, value, ns) { + const name = field; + if (ns === "style") { + // ????? why do we need to do this + if (node.style === undefined) { + node.style = {}; + } + node.style[name] = value; + } else if (ns != null && ns != undefined) { + node.setAttributeNS(ns, name, value); + } else { + switch (name) { + case "value": + if (value !== node.value) { + node.value = value; + } + break; + case "initial_value": + node.defaultValue = value; + break; + case "checked": + node.checked = truthy(value); + break; + case "selected": + node.selected = truthy(value); + break; + case "dangerous_inner_html": + node.innerHTML = value; + break; + default: + // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 + if (!truthy(value) && bool_attrs.hasOwnProperty(name)) { + node.removeAttribute(name); + } else { + node.setAttribute(name, value); + } + } + } +} + +function truthy(val) { + return val === "true" || val === true; +} diff --git a/packages/interpreter/src/interpreter.js b/packages/interpreter/src/interpreter.js index b921c7c22..a6995cdf6 100644 --- a/packages/interpreter/src/interpreter.js +++ b/packages/interpreter/src/interpreter.js @@ -1,3 +1,5 @@ +import { setAttributeInner } from "./common.js"; + class ListenerMap { constructor(root) { // bubbling events can listen at the root element @@ -17,8 +19,7 @@ class ListenerMap { } else { this.global[event_name].active++; } - } - else { + } else { const id = element.getAttribute("data-dioxus-id"); if (!this.local[id]) { this.local[id] = {}; @@ -32,11 +33,13 @@ class ListenerMap { if (bubbles) { this.global[event_name].active--; if (this.global[event_name].active === 0) { - this.root.removeEventListener(event_name, this.global[event_name].callback); + this.root.removeEventListener( + event_name, + this.global[event_name].callback + ); delete this.global[event_name]; } - } - else { + } else { const id = element.getAttribute("data-dioxus-id"); delete this.local[id][event_name]; if (this.local[id].length === 0) { @@ -52,8 +55,15 @@ class ListenerMap { } } +class InterpreterConfig { + constructor(intercept_link_redirects) { + this.intercept_link_redirects = intercept_link_redirects; + } +} + class Interpreter { - constructor(root) { + constructor(root, config) { + this.config = config; this.root = root; this.listeners = new ListenerMap(root); this.nodes = [root]; @@ -143,46 +153,9 @@ class Interpreter { SetAttribute(id, field, value, ns) { if (value === null) { this.RemoveAttribute(id, field, ns); - } - else { - const node = this.nodes[id]; - this.SetAttributeInner(node, field, value, ns); - } - } - SetAttributeInner(node, field, value, ns) { - const name = field; - if (ns === "style") { - // ????? why do we need to do this - if (node.style === undefined) { - node.style = {}; - } - node.style[name] = value; - } else if (ns != null && ns != undefined) { - node.setAttributeNS(ns, name, value); } else { - switch (name) { - case "value": - if (value !== node.value) { - node.value = value; - } - break; - case "checked": - node.checked = value === "true"; - break; - case "selected": - node.selected = value === "true"; - break; - case "dangerous_inner_html": - node.innerHTML = value; - break; - default: - // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 - if (value === "false" && bool_attrs.hasOwnProperty(name)) { - node.removeAttribute(name); - } else { - node.setAttribute(name, value); - } - } + const node = this.nodes[id]; + setAttributeInner(node, field, value, ns); } } RemoveAttribute(root, field, ns) { @@ -204,6 +177,45 @@ class Interpreter { node.removeAttribute(name); } } + + GetClientRect(id) { + const node = this.nodes[id]; + if (!node) { + return; + } + const rect = node.getBoundingClientRect(); + return { + type: "GetClientRect", + origin: [rect.x, rect.y], + size: [rect.width, rect.height], + }; + } + + ScrollTo(id, behavior) { + const node = this.nodes[id]; + if (!node) { + return false; + } + node.scrollIntoView({ + behavior: behavior, + }); + return true; + } + + /// Set the focus on the element + SetFocus(id, focus) { + const node = this.nodes[id]; + if (!node) { + return false; + } + if (focus) { + node.focus(); + } else { + node.blur(); + } + return true; + } + handleEdits(edits) { for (let template of edits.templates) { this.SaveTemplate(template); @@ -212,6 +224,8 @@ class Interpreter { for (let edit of edits.edits) { this.handleEdit(edit); } + + /*POST_HANDLE_EDITS*/ } SaveTemplate(template) { @@ -243,7 +257,7 @@ class Interpreter { for (let attr of node.attrs) { if (attr.type == "Static") { - this.SetAttributeInner(el, attr.name, attr.value, attr.namespace); + setAttributeInner(el, attr.name, attr.value, attr.namespace); } } @@ -342,107 +356,131 @@ class Interpreter { this.RemoveEventListener(edit.id, edit.name); break; case "NewEventListener": - let bubbles = event_bubbles(edit.name); - // this handler is only provided on desktop implementations since this - // method is not used by the web implementation - let handler = (event) => { - let target = event.target; - if (target != null) { - let realId = target.getAttribute(`data-dioxus-id`); - let shouldPreventDefault = target.getAttribute( - `dioxus-prevent-default` - ); - - if (event.type === "click") { - // todo call prevent default if it's the right type of event - let a_element = target.closest("a"); - if (a_element != null) { - event.preventDefault(); - if (shouldPreventDefault !== `onclick` && a_element.getAttribute(`dioxus-prevent-default`) !== `onclick`) { - const href = a_element.getAttribute("href"); - if (href !== "" && href !== null && href !== undefined) { - window.ipc.postMessage( - serializeIpcMessage("browser_open", { href }) - ); - } - } - } - - // also prevent buttons from submitting - if (target.tagName === "BUTTON" && event.type == "submit") { - event.preventDefault(); - } - } - // walk the tree to find the real element - while (realId == null) { - // we've reached the root we don't want to send an event - if (target.parentElement === null) { - return; - } - - target = target.parentElement; - realId = target.getAttribute(`data-dioxus-id`); - } - - shouldPreventDefault = target.getAttribute( - `dioxus-prevent-default` - ); - - let contents = serialize_event(event); - - if (shouldPreventDefault === `on${event.type}`) { - event.preventDefault(); - } - - if (event.type === "submit") { - event.preventDefault(); - } - - if ( - target.tagName === "FORM" && - (event.type === "submit" || event.type === "input") - ) { - for (let x = 0; x < target.elements.length; x++) { - let element = target.elements[x]; - let name = element.getAttribute("name"); - if (name != null) { - if (element.getAttribute("type") === "checkbox") { - // @ts-ignore - contents.values[name] = element.checked ? "true" : "false"; - } else if (element.getAttribute("type") === "radio") { - if (element.checked) { - contents.values[name] = element.value; - } - } else { - // @ts-ignore - contents.values[name] = - element.value ?? element.textContent; - } - } - } - } - - if (realId === null) { - return; - } - window.ipc.postMessage( - serializeIpcMessage("user_event", { - name: edit.name, - element: parseInt(realId), - data: contents, - bubbles, - }) - ); - } - }; - this.NewEventListener(edit.name, edit.id, bubbles, handler); + // if this is a mounted listener, we send the event immediately + if (edit.name === "mounted") { + window.ipc.postMessage( + serializeIpcMessage("user_event", { + name: edit.name, + element: edit.id, + data: null, + bubbles, + }) + ); + } else { + this.NewEventListener(edit.name, edit.id, bubbles, (event) => { + handler(event, edit.name, bubbles, this.config); + }); + } break; } } } +// this handler is only provided on the desktop and liveview implementations since this +// method is not used by the web implementation +function handler(event, name, bubbles, config) { + let target = event.target; + if (target != null) { + let preventDefaultRequests = target.getAttribute(`dioxus-prevent-default`); + + if (event.type === "click") { + // todo call prevent default if it's the right type of event + if (config.intercept_link_redirects) { + let a_element = target.closest("a"); + if (a_element != null) { + event.preventDefault(); + + let elementShouldPreventDefault = + preventDefaultRequests && preventDefaultRequests.includes(`onclick`); + let aElementShouldPreventDefault = a_element.getAttribute( + `dioxus-prevent-default` + ); + let linkShouldPreventDefault = + aElementShouldPreventDefault && + aElementShouldPreventDefault.includes(`onclick`); + + if (!elementShouldPreventDefault && !linkShouldPreventDefault) { + const href = a_element.getAttribute("href"); + if (href !== "" && href !== null && href !== undefined) { + window.ipc.postMessage( + serializeIpcMessage("browser_open", { href }) + ); + } + } + } + } + + // also prevent buttons from submitting + if (target.tagName === "BUTTON" && event.type == "submit") { + event.preventDefault(); + } + } + + const realId = find_real_id(target); + + if ( + preventDefaultRequests && + preventDefaultRequests.includes(`on${event.type}`) + ) { + event.preventDefault(); + } + + if (event.type === "submit") { + event.preventDefault(); + } + + let contents = serialize_event(event); + + /*POST_EVENT_SERIALIZATION*/ + + if ( + target.tagName === "FORM" && + (event.type === "submit" || event.type === "input") + ) { + if ( + target.tagName === "FORM" && + (event.type === "submit" || event.type === "input") + ) { + const formData = new FormData(target); + + for (let name of formData.keys()) { + let value = formData.getAll(name); + contents.values[name] = value; + } + } + } + + if (realId === null) { + return; + } + window.ipc.postMessage( + serializeIpcMessage("user_event", { + name: name, + element: parseInt(realId), + data: contents, + bubbles, + }) + ); + } +} + +function find_real_id(target) { + let realId = target.getAttribute(`data-dioxus-id`); + // walk the tree to find the real element + while (realId == null) { + // we've reached the root we don't want to send an event + if (target.parentElement === null) { + return; + } + + target = target.parentElement; + realId = target.getAttribute(`data-dioxus-id`); + } + return realId; +} + function get_mouse_data(event) { const { altKey, @@ -722,34 +760,6 @@ function serialize_event(event) { function serializeIpcMessage(method, params = {}) { return JSON.stringify({ method, params }); } -const bool_attrs = { - allowfullscreen: true, - allowpaymentrequest: true, - async: true, - autofocus: true, - autoplay: true, - checked: true, - controls: true, - default: true, - defer: true, - disabled: true, - formnovalidate: true, - hidden: true, - ismap: true, - itemscope: true, - loop: true, - multiple: true, - muted: true, - nomodule: true, - novalidate: true, - open: true, - playsinline: true, - readonly: true, - required: true, - reversed: true, - selected: true, - truespeed: true, -}; function is_element_node(node) { return node.nodeType == 1; @@ -921,6 +931,8 @@ function event_bubbles(event) { return true; case "toggle": return true; + case "mounted": + return false; } return true; diff --git a/packages/interpreter/src/lib.rs b/packages/interpreter/src/lib.rs index 962bd6bbb..47093c29c 100644 --- a/packages/interpreter/src/lib.rs +++ b/packages/interpreter/src/lib.rs @@ -1,4 +1,5 @@ pub static INTERPRETER_JS: &str = include_str!("./interpreter.js"); +pub static COMMON_JS: &str = include_str!("./common.js"); #[cfg(feature = "sledgehammer")] mod sledgehammer_bindings; @@ -10,3 +11,13 @@ mod bindings; #[cfg(feature = "web")] pub use bindings::Interpreter; + +// Common bindings for minimal usage. +#[cfg(feature = "minimal_bindings")] +pub mod minimal_bindings { + use wasm_bindgen::{prelude::wasm_bindgen, JsValue}; + #[wasm_bindgen(module = "/src/common.js")] + extern "C" { + pub fn setAttributeInner(node: JsValue, name: &str, value: JsValue, ns: Option<&str>); + } +} diff --git a/packages/interpreter/src/sledgehammer_bindings.rs b/packages/interpreter/src/sledgehammer_bindings.rs index b1b82823c..e661a7c16 100644 --- a/packages/interpreter/src/sledgehammer_bindings.rs +++ b/packages/interpreter/src/sledgehammer_bindings.rs @@ -74,18 +74,21 @@ mod js { node.value = value; } break; + case "initial_value": + node.defaultValue = value; + break; case "checked": - node.checked = value === "true"; + node.checked = truthy(value); break; case "selected": - node.selected = value === "true"; + node.selected = truthy(value); break; case "dangerous_inner_html": node.innerHTML = value; break; default: // https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364 - if (value === "false" && bool_attrs.hasOwnProperty(name)) { + if (!truthy(value) && bool_attrs.hasOwnProperty(name)) { node.removeAttribute(name); } else { node.setAttribute(name, value); @@ -117,6 +120,9 @@ mod js { export function set_node(id, node) { nodes[id] = node; } + export function get_node(id) { + return nodes[id]; + } export function initilize(root, handler) { listeners.handler = handler; nodes = [root]; @@ -158,6 +164,9 @@ mod js { selected: true, truespeed: true, }; + function truthy(val) { + return val === "true" || val === true; + } "#; extern "C" { @@ -167,6 +176,9 @@ mod js { #[wasm_bindgen] pub fn set_node(id: u32, node: Node); + #[wasm_bindgen] + pub fn get_node(id: u32) -> Node; + #[wasm_bindgen] pub fn initilize(root: Node, handler: &Function); } diff --git a/packages/liveview/Cargo.toml b/packages/liveview/Cargo.toml index 5269927b0..4400541ea 100644 --- a/packages/liveview/Cargo.toml +++ b/packages/liveview/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dioxus-liveview" -version = "0.3.0" +version = "0.3.1" edition = "2021" repository = "https://github.com/DioxusLabs/dioxus/" homepage = "https://dioxuslabs.com" @@ -14,19 +14,21 @@ license = "MIT/Apache-2.0" [dependencies] thiserror = "1.0.38" -futures-util = { version = "0.3.25", default-features = false, features = [ +log = { workspace = true } +slab = { workspace = true } +futures-util = { workspace = true, default-features = false, features = [ "sink", ] } -futures-channel = { version = "0.3.25", features = ["sink"] } -tokio = { version = "1.22.0", features = ["time"] } +futures-channel = { workspace = true } +tokio = { workspace = true, features = ["time", "macros"] } tokio-stream = { version = "0.1.11", features = ["net"] } tokio-util = { version = "0.7.4", features = ["rt"] } serde = { version = "1.0.151", features = ["derive"] } serde_json = "1.0.91" -dioxus-html = { path = "../html", features = ["serialize"], version = "^0.3.0" } -dioxus-core = { path = "../core", features = ["serialize"], version = "^0.3.0" } -dioxus-interpreter-js = { path = "../interpreter", version = "0.3.0" } -dioxus-hot-reload = { path = "../hot-reload", optional = true } +dioxus-html = { workspace = true, features = ["serialize"] } +dioxus-core = { workspace = true, features = ["serialize"] } +dioxus-interpreter-js = { workspace = true } +dioxus-hot-reload = { workspace = true, optional = true } # warp warp = { version = "0.3.3", optional = true } @@ -35,7 +37,8 @@ warp = { version = "0.3.3", optional = true } axum = { version = "0.6.1", optional = true, features = ["ws"] } # salvo -salvo = { version = "0.37.7", optional = true, features = ["ws"] } +salvo = { version = "0.44.1", optional = true, features = ["ws"] } +once_cell = "1.17.1" # actix is ... complicated? # actix-files = { version = "0.6.2", optional = true } @@ -43,12 +46,12 @@ salvo = { version = "0.37.7", optional = true, features = ["ws"] } # actix-ws = { version = "0.2.5", optional = true } [dev-dependencies] -pretty_env_logger = { version = "0.4.0" } -tokio = { version = "1.22.0", features = ["full"] } -dioxus = { path = "../dioxus", version = "0.3.0" } +pretty_env_logger = { version = "0.5.0" } +tokio = { workspace = true, features = ["full"] } +dioxus = { workspace = true } warp = "0.3.3" axum = { version = "0.6.1", features = ["ws"] } -salvo = { version = "0.37.7", features = ["affix", "ws"] } +salvo = { version = "0.44.1", features = ["affix", "ws"] } tower = "0.4.13" [features] diff --git a/packages/liveview/examples/salvo.rs b/packages/liveview/examples/salvo.rs index 015892702..9cb8c7115 100644 --- a/packages/liveview/examples/salvo.rs +++ b/packages/liveview/examples/salvo.rs @@ -20,7 +20,8 @@ fn app(cx: Scope) -> Element { async fn main() { pretty_env_logger::init(); - let addr: SocketAddr = ([127, 0, 0, 1], 3030).into(); + let addr = "127.0.0.1:3030"; + let acceptor = TcpListener::new(addr).bind().await; let view = LiveViewPool::new(); @@ -31,7 +32,7 @@ async fn main() { println!("Listening on http://{}", addr); - Server::new(TcpListener::bind(addr)).serve(router).await; + Server::new(acceptor).serve(router).await; } #[handler] diff --git a/packages/liveview/src/element.rs b/packages/liveview/src/element.rs new file mode 100644 index 000000000..21be23bee --- /dev/null +++ b/packages/liveview/src/element.rs @@ -0,0 +1,125 @@ +use dioxus_core::ElementId; +use dioxus_html::{geometry::euclid::Rect, MountedResult, RenderedElementBacking}; +use tokio::sync::mpsc::UnboundedSender; + +use crate::query::QueryEngine; + +/// A mounted element passed to onmounted events +pub struct LiveviewElement { + id: ElementId, + query_tx: UnboundedSender, + query: QueryEngine, +} + +impl LiveviewElement { + pub(crate) fn new(id: ElementId, tx: UnboundedSender, query: QueryEngine) -> Self { + Self { + id, + query_tx: tx, + query, + } + } +} + +impl RenderedElementBacking for LiveviewElement { + fn get_raw_element(&self) -> dioxus_html::MountedResult<&dyn std::any::Any> { + Ok(self) + } + + fn get_client_rect( + &self, + ) -> std::pin::Pin< + Box< + dyn futures_util::Future< + Output = dioxus_html::MountedResult>, + >, + >, + > { + let script = format!("return window.interpreter.GetClientRect({});", self.id.0); + + let fut = self + .query + .new_query::>>(&script, &self.query_tx) + .resolve(); + Box::pin(async move { + match fut.await { + Ok(Some(rect)) => Ok(rect), + Ok(None) => MountedResult::Err(dioxus_html::MountedError::OperationFailed( + Box::new(DesktopQueryError::FailedToQuery), + )), + Err(err) => { + MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err))) + } + } + }) + } + + fn scroll_to( + &self, + behavior: dioxus_html::ScrollBehavior, + ) -> std::pin::Pin>>> { + let script = format!( + "return window.interpreter.ScrollTo({}, {});", + self.id.0, + serde_json::to_string(&behavior).expect("Failed to serialize ScrollBehavior") + ); + + let fut = self + .query + .new_query::(&script, &self.query_tx) + .resolve(); + Box::pin(async move { + match fut.await { + Ok(true) => Ok(()), + Ok(false) => MountedResult::Err(dioxus_html::MountedError::OperationFailed( + Box::new(DesktopQueryError::FailedToQuery), + )), + Err(err) => { + MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err))) + } + } + }) + } + + fn set_focus( + &self, + focus: bool, + ) -> std::pin::Pin>>> { + let script = format!( + "return window.interpreter.SetFocus({}, {});", + self.id.0, focus + ); + + let fut = self + .query + .new_query::(&script, &self.query_tx) + .resolve(); + + Box::pin(async move { + match fut.await { + Ok(true) => Ok(()), + Ok(false) => MountedResult::Err(dioxus_html::MountedError::OperationFailed( + Box::new(DesktopQueryError::FailedToQuery), + )), + Err(err) => { + MountedResult::Err(dioxus_html::MountedError::OperationFailed(Box::new(err))) + } + } + }) + } +} + +#[derive(Debug)] +enum DesktopQueryError { + FailedToQuery, +} + +impl std::fmt::Display for DesktopQueryError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + DesktopQueryError::FailedToQuery => write!(f, "Failed to query the element"), + } + } +} + +impl std::error::Error for DesktopQueryError {} diff --git a/packages/liveview/src/lib.rs b/packages/liveview/src/lib.rs index ffddf0272..ff02febac 100644 --- a/packages/liveview/src/lib.rs +++ b/packages/liveview/src/lib.rs @@ -18,7 +18,9 @@ pub mod adapters { pub use adapters::*; +mod element; pub mod pool; +mod query; use futures_util::{SinkExt, StreamExt}; pub use pool::*; @@ -34,7 +36,57 @@ pub enum LiveViewError { SendingFailed, } -use dioxus_interpreter_js::INTERPRETER_JS; +use once_cell::sync::Lazy; + +static INTERPRETER_JS: Lazy = Lazy::new(|| { + let interpreter = dioxus_interpreter_js::INTERPRETER_JS; + let serialize_file_uploads = r#"if ( + target.tagName === "INPUT" && + (event.type === "change" || event.type === "input") + ) { + const type = target.getAttribute("type"); + if (type === "file") { + async function read_files() { + const files = target.files; + const file_contents = {}; + + for (let i = 0; i < files.length; i++) { + const file = files[i]; + + file_contents[file.name] = Array.from( + new Uint8Array(await file.arrayBuffer()) + ); + } + let file_engine = { + files: file_contents, + }; + contents.files = file_engine; + + if (realId === null) { + return; + } + const message = serializeIpcMessage("user_event", { + name: name, + element: parseInt(realId), + data: contents, + bubbles, + }); + window.ipc.postMessage(message); + } + read_files(); + return; + } + }"#; + + let interpreter = interpreter.replace("/*POST_EVENT_SERIALIZATION*/", serialize_file_uploads); + interpreter.replace("import { setAttributeInner } from \"./common.js\";", "") +}); + +static COMMON_JS: Lazy = Lazy::new(|| { + let common = dioxus_interpreter_js::COMMON_JS; + common.replace("export", "") +}); + static MAIN_JS: &str = include_str!("./main.js"); /// This script that gets injected into your app connects this page to the websocket endpoint @@ -42,11 +94,14 @@ static MAIN_JS: &str = include_str!("./main.js"); /// Once the endpoint is connected, it will send the initial state of the app, and then start /// processing user events and returning edits to the liveview instance pub fn interpreter_glue(url: &str) -> String { + let js = &*INTERPRETER_JS; + let common = &*COMMON_JS; format!( r#" diff --git a/packages/liveview/src/main.js b/packages/liveview/src/main.js index 7dd9758d6..e98d02a9c 100644 --- a/packages/liveview/src/main.js +++ b/packages/liveview/src/main.js @@ -8,7 +8,7 @@ function main() { class IPC { constructor(root) { // connect to the websocket - window.interpreter = new Interpreter(root); + window.interpreter = new Interpreter(root, new InterpreterConfig(false)); let ws = new WebSocket(WS_ADDR); @@ -26,11 +26,19 @@ class IPC { // todo: retry the connection }; - ws.onmessage = (event) => { + ws.onmessage = (message) => { // Ignore pongs - if (event.data != "__pong__") { - let edits = JSON.parse(event.data); - window.interpreter.handleEdits(edits); + if (message.data != "__pong__") { + const event = JSON.parse(message.data); + switch (event.type) { + case "edits": + let edits = event.data; + window.interpreter.handleEdits(edits); + break; + case "query": + Function("Eval", `"use strict";${event.data};`)(); + break; + } } }; diff --git a/packages/liveview/src/pool.rs b/packages/liveview/src/pool.rs index e02c8195b..089d0bad4 100644 --- a/packages/liveview/src/pool.rs +++ b/packages/liveview/src/pool.rs @@ -1,8 +1,13 @@ -use crate::LiveViewError; -use dioxus_core::prelude::*; -use dioxus_html::HtmlEvent; +use crate::{ + element::LiveviewElement, + query::{QueryEngine, QueryResult}, + LiveViewError, +}; +use dioxus_core::{prelude::*, Mutations}; +use dioxus_html::{EventData, HtmlEvent, MountedData}; use futures_util::{pin_mut, SinkExt, StreamExt}; -use std::time::Duration; +use serde::Serialize; +use std::{rc::Rc, time::Duration}; use tokio_util::task::LocalPoolHandle; #[derive(Clone)] @@ -115,7 +120,7 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li }; // todo: use an efficient binary packed format for this - let edits = serde_json::to_string(&vdom.rebuild()).unwrap(); + let edits = serde_json::to_string(&ClientUpdate::Edits(vdom.rebuild())).unwrap(); // pin the futures so we can use select! pin_mut!(ws); @@ -123,11 +128,19 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li // send the initial render to the client ws.send(edits).await?; + // Create the a proxy for query engine + let (query_tx, mut query_rx) = tokio::sync::mpsc::unbounded_channel(); + let query_engine = QueryEngine::default(); + // desktop uses this wrapper struct thing around the actual event itself // this is sorta driven by tao/wry - #[derive(serde::Deserialize)] - struct IpcMessage { - params: HtmlEvent, + #[derive(serde::Deserialize, Debug)] + #[serde(tag = "method", content = "params")] + enum IpcMessage { + #[serde(rename = "user_event")] + Event(HtmlEvent), + #[serde(rename = "query")] + Query(QueryResult), } loop { @@ -147,16 +160,45 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li ws.send("__pong__".to_string()).await?; } Some(Ok(evt)) => { - if let Ok(IpcMessage { params }) = serde_json::from_str::(evt) { - vdom.handle_event(¶ms.name, params.data.into_any(), params.element, params.bubbles); + if let Ok(message) = serde_json::from_str::(evt) { + match message { + IpcMessage::Event(evt) => { + // Intercept the mounted event and insert a custom element type + if let EventData::Mounted = &evt.data { + let element = LiveviewElement::new(evt.element, query_tx.clone(), query_engine.clone()); + vdom.handle_event( + &evt.name, + Rc::new(MountedData::new(element)), + evt.element, + evt.bubbles, + ); + } + else{ + vdom.handle_event( + &evt.name, + evt.data.into_any(), + evt.element, + evt.bubbles, + ); + } + } + IpcMessage::Query(result) => { + query_engine.send(result); + }, + } } } // log this I guess? when would we get an error here? - Some(Err(_e)) => {}, + Some(Err(_e)) => {} None => return Ok(()), } } + // handle any new queries + Some(query) = query_rx.recv() => { + ws.send(serde_json::to_string(&ClientUpdate::Query(query)).unwrap()).await?; + } + Some(msg) = hot_reload_wait => { #[cfg(all(feature = "hot-reload", debug_assertions))] match msg{ @@ -176,6 +218,16 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li .render_with_deadline(tokio::time::sleep(Duration::from_millis(10))) .await; - ws.send(serde_json::to_string(&edits).unwrap()).await?; + ws.send(serde_json::to_string(&ClientUpdate::Edits(edits)).unwrap()) + .await?; } } + +#[derive(Serialize)] +#[serde(tag = "type", content = "data")] +enum ClientUpdate<'a> { + #[serde(rename = "edits")] + Edits(Mutations<'a>), + #[serde(rename = "query")] + Query(String), +} diff --git a/packages/liveview/src/query.rs b/packages/liveview/src/query.rs new file mode 100644 index 000000000..04d531a63 --- /dev/null +++ b/packages/liveview/src/query.rs @@ -0,0 +1,113 @@ +use std::{cell::RefCell, rc::Rc}; + +use serde::{de::DeserializeOwned, Deserialize}; +use serde_json::Value; +use slab::Slab; +use thiserror::Error; +use tokio::sync::{broadcast::error::RecvError, mpsc::UnboundedSender}; + +/// Tracks what query ids are currently active +#[derive(Default, Clone)] +struct SharedSlab { + slab: Rc>>, +} + +/// Handles sending and receiving arbitrary queries from the webview. Queries can be resolved non-sequentially, so we use ids to track them. +#[derive(Clone)] +pub(crate) struct QueryEngine { + sender: Rc>, + active_requests: SharedSlab, +} + +impl Default for QueryEngine { + fn default() -> Self { + let (sender, _) = tokio::sync::broadcast::channel(8); + Self { + sender: Rc::new(sender), + active_requests: SharedSlab::default(), + } + } +} + +impl QueryEngine { + /// Creates a new query and returns a handle to it. The query will be resolved when the webview returns a result with the same id. + pub fn new_query( + &self, + script: &str, + tx: &UnboundedSender, + ) -> Query { + let request_id = self.active_requests.slab.borrow_mut().insert(()); + + // start the query + // We embed the return of the eval in a function so we can send it back to the main thread + if let Err(err) = tx.send(format!( + r#"window.ipc.postMessage( + JSON.stringify({{ + "method":"query", + "params": {{ + "id": {request_id}, + "data": (function(){{{script}}})() + }} + }}) + );"# + )) { + log::warn!("Query error: {err}"); + } + + Query { + slab: self.active_requests.clone(), + id: request_id, + reciever: self.sender.subscribe(), + phantom: std::marker::PhantomData, + } + } + + /// Send a query result + pub fn send(&self, data: QueryResult) { + let _ = self.sender.send(data); + } +} + +pub(crate) struct Query { + slab: SharedSlab, + id: usize, + reciever: tokio::sync::broadcast::Receiver, + phantom: std::marker::PhantomData, +} + +impl Query { + /// Resolve the query + pub async fn resolve(mut self) -> Result { + let result = loop { + match self.reciever.recv().await { + Ok(result) => { + if result.id == self.id { + break V::deserialize(result.data).map_err(QueryError::DeserializeError); + } + } + Err(err) => { + break Err(QueryError::RecvError(err)); + } + } + }; + + // Remove the query from the slab + self.slab.slab.borrow_mut().remove(self.id); + + result + } +} + +#[derive(Error, Debug)] +pub enum QueryError { + #[error("Error receiving query result: {0}")] + RecvError(RecvError), + #[error("Error deserializing query result: {0}")] + DeserializeError(serde_json::Error), +} + +#[derive(Clone, Debug, Deserialize)] +pub(crate) struct QueryResult { + id: usize, + data: Value, +} diff --git a/packages/mobile/Cargo.toml b/packages/mobile/Cargo.toml index 3595e76d7..6d900d704 100644 --- a/packages/mobile/Cargo.toml +++ b/packages/mobile/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-desktop = { path = "../desktop", version = "^0.3.0" } +dioxus-desktop = { workspace = true } [lib] doctest = false diff --git a/packages/native-core-macro/Cargo.toml b/packages/native-core-macro/Cargo.toml index ed8648f93..1f06f601e 100644 --- a/packages/native-core-macro/Cargo.toml +++ b/packages/native-core-macro/Cargo.toml @@ -20,7 +20,7 @@ quote = "1.0" [dev-dependencies] smallvec = "1.6" -rustc-hash = "1.1.0" +rustc-hash = { workspace = true } anymap = "0.12.1" -dioxus = { path = "../dioxus" } -dioxus-native-core = { path = "../native-core" } +dioxus = { workspace = true } +dioxus-native-core = { workspace = true } diff --git a/packages/native-core/Cargo.toml b/packages/native-core/Cargo.toml index 9ea6d4c9f..5e8d7d94b 100644 --- a/packages/native-core/Cargo.toml +++ b/packages/native-core/Cargo.toml @@ -11,14 +11,14 @@ keywords = ["dom", "ui", "gui", "react"] [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0", optional = true } +dioxus-core = { workspace = true, optional = true } keyboard-types = "0.6.2" -taffy = "0.2.1" +taffy = "0.3.12" smallvec = "1.6" -rustc-hash = "1.1.0" +rustc-hash = { workspace = true } anymap = "1.0.0-beta.2" -slab = "0.4" +slab = { workspace = true } parking_lot = { version = "0.12.1", features = ["send_guard"] } crossbeam-deque = "0.8.2" dashmap = "5.4.0" @@ -29,14 +29,13 @@ lightningcss = "1.0.0-alpha.39" rayon = "1.6.1" shipyard = { version = "0.6.2", features = ["proc", "std"], default-features = false } -shipyard_hierarchy = "0.6.0" [dev-dependencies] rand = "0.8.5" -dioxus = { path = "../dioxus", version = "^0.3.0" } -tokio = { version = "*", features = ["full"] } -dioxus-native-core = { path = ".", features = ["dioxus"] } -dioxus-native-core-macro = { path = "../native-core-macro" } +dioxus = { workspace = true } +tokio = { workspace = true, features = ["full"] } +dioxus-native-core = { workspace = true, features = ["dioxus"] } +dioxus-native-core-macro = { workspace = true } [features] default = [] diff --git a/packages/native-core/src/layout_attributes.rs b/packages/native-core/src/layout_attributes.rs index 84fd61ac4..4eb39292b 100644 --- a/packages/native-core/src/layout_attributes.rs +++ b/packages/native-core/src/layout_attributes.rs @@ -2,7 +2,7 @@ /* - [ ] pub display: Display, ----> taffy doesnt support all display types -- [x] pub position_type: PositionType, --> taffy doesnt support everything +- [x] pub position: Position, --> taffy doesnt support everything - [x] pub direction: Direction, - [x] pub flex_direction: FlexDirection, @@ -11,6 +11,14 @@ - [x] pub flex_shrink: f32, - [x] pub flex_basis: Dimension, +- [x]pub grid_auto_flow: GridAutoFlow, +- [x]pub grid_template_rows: GridTrackVec, +- [x]pub grid_template_columns: GridTrackVec, +- [x]pub grid_auto_rows: GridTrackVec, +- [x]pub grid_auto_columns: GridTrackVec, +- [x]pub grid_row: Line, +- [x]pub grid_column: Line, + - [x] pub overflow: Overflow, ---> taffy doesnt have support for directional overflow - [x] pub align_items: AlignItems, @@ -21,20 +29,22 @@ - [x] pub padding: Rect, - [x] pub justify_content: JustifyContent, -- [x] pub position: Rect, +- [x] pub inset: Rect, - [x] pub border: Rect, - [ ] pub size: Size, ----> seems to only be relevant for input? - [ ] pub min_size: Size, - [ ] pub max_size: Size, -- [ ] pub aspect_ratio: Number, ----> parsing is done, but taffy doesnt support it +- [x] pub aspect_ratio: Number, */ use lightningcss::properties::border::LineStyle; -use lightningcss::properties::{align, display, flex, position, size}; +use lightningcss::properties::grid::{TrackBreadth, TrackSizing}; +use lightningcss::properties::{align, border, display, flex, grid, position, size}; +use lightningcss::values::percentage::Percentage; use lightningcss::{ - properties::{align::GapValue, border::BorderSideWidth, Property, PropertyId}, + properties::{Property, PropertyId}, stylesheet::ParserOptions, traits::Parse, values::{ @@ -45,7 +55,7 @@ use lightningcss::{ }; use taffy::{ prelude::*, - style::{FlexDirection, PositionType}, + style::{FlexDirection, Position}, }; /// Default values for layout attributes @@ -95,33 +105,35 @@ pub fn apply_layout_attributes_cfg( display::Display::Keyword(display::DisplayKeyword::None) => { style.display = Display::None } - display::Display::Pair(pair) => { - if let display::DisplayInside::Flex(_) = pair.inside { - style.display = Display::Flex + display::Display::Pair(pair) => match pair.inside { + display::DisplayInside::Flex(_) => { + style.display = Display::Flex; } - } - _ => (), + display::DisplayInside::Grid => { + style.display = Display::Grid; + } + _ => {} + }, + _ => {} }, Property::Position(position) => { - style.position_type = match position { - position::Position::Relative => PositionType::Relative, - position::Position::Absolute => PositionType::Absolute, + style.position = match position { + position::Position::Relative => Position::Relative, + position::Position::Absolute => Position::Absolute, _ => return, } } - Property::Top(top) => style.position.top = convert_length_percentage_or_auto(top), + Property::Top(top) => style.inset.top = convert_length_percentage_or_auto(top), Property::Bottom(bottom) => { - style.position.bottom = convert_length_percentage_or_auto(bottom) - } - Property::Left(left) => style.position.left = convert_length_percentage_or_auto(left), - Property::Right(right) => { - style.position.right = convert_length_percentage_or_auto(right) + style.inset.bottom = convert_length_percentage_or_auto(bottom) } + Property::Left(left) => style.inset.left = convert_length_percentage_or_auto(left), + Property::Right(right) => style.inset.right = convert_length_percentage_or_auto(right), Property::Inset(inset) => { - style.position.top = convert_length_percentage_or_auto(inset.top); - style.position.bottom = convert_length_percentage_or_auto(inset.bottom); - style.position.left = convert_length_percentage_or_auto(inset.left); - style.position.right = convert_length_percentage_or_auto(inset.right); + style.inset.top = convert_length_percentage_or_auto(inset.top); + style.inset.bottom = convert_length_percentage_or_auto(inset.bottom); + style.inset.left = convert_length_percentage_or_auto(inset.left); + style.inset.right = convert_length_percentage_or_auto(inset.right); } Property::BorderTopWidth(width) => { style.border.top = convert_border_side_width(width, &config.border_widths); @@ -164,46 +176,64 @@ pub fn apply_layout_attributes_cfg( } Property::BorderTopStyle(line_style) => { if line_style != LineStyle::None { - style.border.top = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.top = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } } Property::BorderBottomStyle(line_style) => { if line_style != LineStyle::None { - style.border.bottom = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.bottom = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } } Property::BorderLeftStyle(line_style) => { if line_style != LineStyle::None { - style.border.left = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.left = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } } Property::BorderRightStyle(line_style) => { if line_style != LineStyle::None { - style.border.right = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.right = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } } Property::BorderStyle(styles) => { if styles.top != LineStyle::None { - style.border.top = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.top = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } if styles.bottom != LineStyle::None { - style.border.bottom = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.bottom = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } if styles.left != LineStyle::None { - style.border.left = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.left = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } if styles.right != LineStyle::None { - style.border.right = - convert_border_side_width(BorderSideWidth::Medium, &config.border_widths); + style.border.right = convert_border_side_width( + border::BorderSideWidth::Medium, + &config.border_widths, + ); } } + + // Flexbox properties Property::FlexDirection(flex_direction, _) => { use FlexDirection::*; style.flex_direction = match flex_direction { @@ -228,75 +258,123 @@ pub fn apply_layout_attributes_cfg( style.flex_shrink = shrink; } Property::FlexBasis(basis, _) => { - style.flex_basis = convert_length_percentage_or_auto(basis); + style.flex_basis = convert_length_percentage_or_auto(basis).into(); } Property::Flex(flex, _) => { style.flex_grow = flex.grow; style.flex_shrink = flex.shrink; - style.flex_basis = convert_length_percentage_or_auto(flex.basis); + style.flex_basis = convert_length_percentage_or_auto(flex.basis).into(); } + + // Grid properties + Property::GridAutoFlow(grid_auto_flow) => { + let is_row = grid_auto_flow.contains(grid::GridAutoFlow::Row); + let is_dense = grid_auto_flow.contains(grid::GridAutoFlow::Dense); + style.grid_auto_flow = match (is_row, is_dense) { + (true, false) => GridAutoFlow::Row, + (false, false) => GridAutoFlow::Column, + (true, true) => GridAutoFlow::RowDense, + (false, true) => GridAutoFlow::ColumnDense, + }; + } + Property::GridTemplateColumns(TrackSizing::TrackList(track_list)) => { + style.grid_template_columns = track_list + .items + .into_iter() + .map(convert_grid_track_item) + .collect(); + } + Property::GridTemplateRows(TrackSizing::TrackList(track_list)) => { + style.grid_template_rows = track_list + .items + .into_iter() + .map(convert_grid_track_item) + .collect(); + } + Property::GridAutoColumns(grid::TrackSizeList(track_size_list)) => { + style.grid_auto_columns = track_size_list + .into_iter() + .map(convert_grid_track_size) + .collect(); + } + Property::GridAutoRows(grid::TrackSizeList(track_size_list)) => { + style.grid_auto_rows = track_size_list + .into_iter() + .map(convert_grid_track_size) + .collect(); + } + Property::GridRow(grid_row) => { + style.grid_row = Line { + start: convert_grid_placement(grid_row.start), + end: convert_grid_placement(grid_row.end), + }; + } + Property::GridColumn(grid_column) => { + style.grid_column = Line { + start: convert_grid_placement(grid_column.start), + end: convert_grid_placement(grid_column.end), + }; + } + + // Alignment properties Property::AlignContent(align, _) => { use AlignContent::*; style.align_content = match align { align::AlignContent::ContentDistribution(distribution) => match distribution { - align::ContentDistribution::SpaceBetween => SpaceBetween, - align::ContentDistribution::SpaceAround => SpaceAround, - align::ContentDistribution::SpaceEvenly => SpaceEvenly, - align::ContentDistribution::Stretch => Stretch, + align::ContentDistribution::SpaceBetween => Some(SpaceBetween), + align::ContentDistribution::SpaceAround => Some(SpaceAround), + align::ContentDistribution::SpaceEvenly => Some(SpaceEvenly), + align::ContentDistribution::Stretch => Some(Stretch), }, align::AlignContent::ContentPosition { value: position, .. } => match position { - align::ContentPosition::Center => Center, - align::ContentPosition::Start | align::ContentPosition::FlexStart => { - FlexStart - } - align::ContentPosition::End | align::ContentPosition::FlexEnd => FlexEnd, + align::ContentPosition::Center => Some(Center), + align::ContentPosition::Start => Some(Start), + align::ContentPosition::FlexStart => Some(FlexStart), + align::ContentPosition::End => Some(End), + align::ContentPosition::FlexEnd => Some(FlexEnd), }, _ => return, }; } Property::JustifyContent(justify, _) => { - use JustifyContent::*; + use AlignContent::*; style.justify_content = match justify { align::JustifyContent::ContentDistribution(distribution) => { match distribution { - align::ContentDistribution::SpaceBetween => SpaceBetween, - align::ContentDistribution::SpaceAround => SpaceAround, - align::ContentDistribution::SpaceEvenly => SpaceEvenly, + align::ContentDistribution::SpaceBetween => Some(SpaceBetween), + align::ContentDistribution::SpaceAround => Some(SpaceAround), + align::ContentDistribution::SpaceEvenly => Some(SpaceEvenly), _ => return, } } align::JustifyContent::ContentPosition { value: position, .. } => match position { - align::ContentPosition::Center => Center, - // start ignores -reverse flex-direction but there is no way to specify that in Taffy - align::ContentPosition::Start | align::ContentPosition::FlexStart => { - FlexStart - } - // end ignores -reverse flex-direction but there is no way to specify that in Taffy - align::ContentPosition::End | align::ContentPosition::FlexEnd => FlexEnd, + align::ContentPosition::Center => Some(Center), + align::ContentPosition::Start => Some(Start), + align::ContentPosition::FlexStart => Some(FlexStart), + align::ContentPosition::End => Some(End), + align::ContentPosition::FlexEnd => Some(FlexEnd), }, _ => return, }; } Property::AlignSelf(align, _) => { - use AlignSelf::*; + use AlignItems::*; style.align_self = match align { - align::AlignSelf::Auto => Auto, - align::AlignSelf::Stretch => Stretch, - align::AlignSelf::BaselinePosition(_) => Baseline, + align::AlignSelf::Auto => None, + align::AlignSelf::Stretch => Some(Stretch), + align::AlignSelf::BaselinePosition(_) => Some(Baseline), align::AlignSelf::SelfPosition { value: position, .. } => match position { - align::SelfPosition::Center => Center, - align::SelfPosition::Start - | align::SelfPosition::SelfStart - | align::SelfPosition::FlexStart => FlexStart, - align::SelfPosition::End - | align::SelfPosition::SelfEnd - | align::SelfPosition::FlexEnd => FlexEnd, + align::SelfPosition::Center => Some(Center), + align::SelfPosition::Start | align::SelfPosition::SelfStart => Some(Start), + align::SelfPosition::FlexStart => Some(FlexStart), + align::SelfPosition::End | align::SelfPosition::SelfEnd => Some(End), + align::SelfPosition::FlexEnd => Some(FlexEnd), }, _ => return, }; @@ -304,15 +382,18 @@ pub fn apply_layout_attributes_cfg( Property::AlignItems(align, _) => { use AlignItems::*; style.align_items = match align { - align::AlignItems::BaselinePosition(_) => Baseline, - align::AlignItems::Stretch => Stretch, + align::AlignItems::BaselinePosition(_) => Some(Baseline), + align::AlignItems::Stretch => Some(Stretch), align::AlignItems::SelfPosition { value: position, .. } => match position { - align::SelfPosition::Center => Center, - align::SelfPosition::FlexStart => FlexStart, - align::SelfPosition::FlexEnd => FlexEnd, - _ => return, + align::SelfPosition::Center => Some(Center), + align::SelfPosition::FlexStart => Some(FlexStart), + align::SelfPosition::FlexEnd => Some(FlexEnd), + align::SelfPosition::Start | align::SelfPosition::SelfStart => { + Some(FlexEnd) + } + align::SelfPosition::End | align::SelfPosition::SelfEnd => Some(FlexEnd), }, _ => return, }; @@ -350,23 +431,23 @@ pub fn apply_layout_attributes_cfg( }; } Property::PaddingTop(padding) => { - style.padding.top = convert_length_percentage_or_auto(padding); + style.padding.top = convert_padding(padding); } Property::PaddingBottom(padding) => { - style.padding.bottom = convert_length_percentage_or_auto(padding); + style.padding.bottom = convert_padding(padding); } Property::PaddingLeft(padding) => { - style.padding.left = convert_length_percentage_or_auto(padding); + style.padding.left = convert_padding(padding); } Property::PaddingRight(padding) => { - style.padding.right = convert_length_percentage_or_auto(padding); + style.padding.right = convert_padding(padding); } Property::Padding(padding) => { style.padding = Rect { - top: convert_length_percentage_or_auto(padding.top), - bottom: convert_length_percentage_or_auto(padding.bottom), - left: convert_length_percentage_or_auto(padding.left), - right: convert_length_percentage_or_auto(padding.right), + top: convert_padding(padding.top), + bottom: convert_padding(padding.bottom), + left: convert_padding(padding.left), + right: convert_padding(padding.right), }; } Property::Width(width) => { @@ -386,59 +467,157 @@ pub fn apply_layout_attributes_cfg( } } -fn convert_length_value(length_value: LengthValue) -> Dimension { +fn extract_px_value(length_value: LengthValue) -> f32 { match length_value { - LengthValue::Px(value) => Dimension::Points(value), + LengthValue::Px(value) => value, _ => todo!(), } } -fn convert_dimension_percentage( +fn convert_length_percentage( dimension_percentage: DimensionPercentage, -) -> Dimension { +) -> LengthPercentage { match dimension_percentage { - DimensionPercentage::Dimension(value) => convert_length_value(value), - DimensionPercentage::Percentage(percentage) => Dimension::Percent(percentage.0), - _ => todo!(), + DimensionPercentage::Dimension(value) => LengthPercentage::Points(extract_px_value(value)), + DimensionPercentage::Percentage(percentage) => LengthPercentage::Percent(percentage.0), + DimensionPercentage::Calc(_) => todo!(), + } +} + +fn convert_padding(dimension_percentage: LengthPercentageOrAuto) -> LengthPercentage { + match dimension_percentage { + LengthPercentageOrAuto::Auto => unimplemented!(), + LengthPercentageOrAuto::LengthPercentage(lp) => match lp { + DimensionPercentage::Dimension(value) => { + LengthPercentage::Points(extract_px_value(value)) + } + DimensionPercentage::Percentage(percentage) => LengthPercentage::Percent(percentage.0), + DimensionPercentage::Calc(_) => unimplemented!(), + }, } } fn convert_length_percentage_or_auto( - length_percentage_or_auto: LengthPercentageOrAuto, -) -> Dimension { - match length_percentage_or_auto { - LengthPercentageOrAuto::Auto => Dimension::Auto, - LengthPercentageOrAuto::LengthPercentage(percentage) => { - convert_dimension_percentage(percentage) - } + dimension_percentage: LengthPercentageOrAuto, +) -> LengthPercentageAuto { + match dimension_percentage { + LengthPercentageOrAuto::Auto => LengthPercentageAuto::Auto, + LengthPercentageOrAuto::LengthPercentage(lp) => match lp { + DimensionPercentage::Dimension(value) => { + LengthPercentageAuto::Points(extract_px_value(value)) + } + DimensionPercentage::Percentage(percentage) => { + LengthPercentageAuto::Percent(percentage.0) + } + DimensionPercentage::Calc(_) => todo!(), + }, + } +} + +fn convert_dimension(dimension_percentage: DimensionPercentage) -> Dimension { + match dimension_percentage { + DimensionPercentage::Dimension(value) => Dimension::Points(extract_px_value(value)), + DimensionPercentage::Percentage(percentage) => Dimension::Percent(percentage.0), + DimensionPercentage::Calc(_) => todo!(), } } fn convert_border_side_width( - border_side_width: BorderSideWidth, + border_side_width: border::BorderSideWidth, border_width_config: &BorderWidths, -) -> Dimension { +) -> LengthPercentage { match border_side_width { - BorderSideWidth::Length(Length::Value(value)) => convert_length_value(value), - BorderSideWidth::Thick => Dimension::Points(border_width_config.thick), - BorderSideWidth::Medium => Dimension::Points(border_width_config.medium), - BorderSideWidth::Thin => Dimension::Points(border_width_config.thin), - _ => todo!(), + border::BorderSideWidth::Length(Length::Value(value)) => { + LengthPercentage::Points(extract_px_value(value)) + } + border::BorderSideWidth::Thick => LengthPercentage::Points(border_width_config.thick), + border::BorderSideWidth::Medium => LengthPercentage::Points(border_width_config.medium), + border::BorderSideWidth::Thin => LengthPercentage::Points(border_width_config.thin), + border::BorderSideWidth::Length(_) => unimplemented!(), } } -fn convert_gap_value(gap_value: GapValue) -> Dimension { +fn convert_gap_value(gap_value: align::GapValue) -> LengthPercentage { match gap_value { - GapValue::LengthPercentage(dim) => convert_dimension_percentage(dim), - GapValue::Normal => Dimension::Auto, + align::GapValue::LengthPercentage(dim) => convert_length_percentage(dim), + align::GapValue::Normal => LengthPercentage::Points(0.0), } } fn convert_size(size: size::Size) -> Dimension { match size { size::Size::Auto => Dimension::Auto, - size::Size::LengthPercentage(length) => convert_dimension_percentage(length), - _ => todo!(), + size::Size::LengthPercentage(length) => convert_dimension(length), + size::Size::MinContent(_) => Dimension::Auto, // Unimplemented, so default auto + size::Size::MaxContent(_) => Dimension::Auto, // Unimplemented, so default auto + size::Size::FitContent(_) => Dimension::Auto, // Unimplemented, so default auto + size::Size::FitContentFunction(_) => Dimension::Auto, // Unimplemented, so default auto + size::Size::Stretch(_) => Dimension::Auto, // Unimplemented, so default auto + size::Size::Contain => Dimension::Auto, // Unimplemented, so default auto + } +} + +fn convert_grid_placement(input: grid::GridLine) -> GridPlacement { + match input { + grid::GridLine::Auto => GridPlacement::Auto, + grid::GridLine::Line { index, .. } => line(index as i16), + grid::GridLine::Span { index, .. } => span(index as u16), + grid::GridLine::Area { .. } => unimplemented!(), + } +} + +fn convert_grid_track_item(input: grid::TrackListItem) -> TrackSizingFunction { + match input { + grid::TrackListItem::TrackSize(size) => { + TrackSizingFunction::Single(convert_grid_track_size(size)) + } + grid::TrackListItem::TrackRepeat(_) => todo!(), // TODO: requires TrackRepeat fields to be public! + } +} + +fn convert_grid_track_size(input: grid::TrackSize) -> NonRepeatedTrackSizingFunction { + match input { + grid::TrackSize::TrackBreadth(breadth) => minmax( + convert_track_breadth_min(&breadth), + convert_track_breadth_max(&breadth), + ), + grid::TrackSize::MinMax { min, max } => minmax( + convert_track_breadth_min(&min), + convert_track_breadth_max(&max), + ), + grid::TrackSize::FitContent(limit) => match limit { + DimensionPercentage::Dimension(LengthValue::Px(len)) => minmax(auto(), points(len)), + DimensionPercentage::Percentage(Percentage(pct)) => minmax(auto(), percent(pct)), + _ => unimplemented!(), + }, + } +} + +fn convert_track_breadth_max(breadth: &TrackBreadth) -> MaxTrackSizingFunction { + match breadth { + grid::TrackBreadth::Length(length_percentage) => match length_percentage { + DimensionPercentage::Dimension(LengthValue::Px(len)) => points(*len), + DimensionPercentage::Percentage(Percentage(pct)) => percent(*pct), + _ => unimplemented!(), + }, + grid::TrackBreadth::Flex(fraction) => fr(*fraction), + grid::TrackBreadth::MinContent => MaxTrackSizingFunction::MinContent, + grid::TrackBreadth::MaxContent => MaxTrackSizingFunction::MaxContent, + grid::TrackBreadth::Auto => MaxTrackSizingFunction::Auto, + } +} + +fn convert_track_breadth_min(breadth: &TrackBreadth) -> MinTrackSizingFunction { + match breadth { + grid::TrackBreadth::Length(length_percentage) => match length_percentage { + DimensionPercentage::Dimension(LengthValue::Px(len)) => points(*len), + DimensionPercentage::Percentage(Percentage(pct)) => percent(*pct), + _ => unimplemented!(), + }, + grid::TrackBreadth::MinContent => MinTrackSizingFunction::MinContent, + grid::TrackBreadth::MaxContent => MinTrackSizingFunction::MaxContent, + grid::TrackBreadth::Auto => MinTrackSizingFunction::Auto, + grid::TrackBreadth::Flex(_) => MinTrackSizingFunction::Auto, } } diff --git a/packages/native-core/src/tree.rs b/packages/native-core/src/tree.rs index df25deac3..e0c55eece 100644 --- a/packages/native-core/src/tree.rs +++ b/packages/native-core/src/tree.rs @@ -178,7 +178,7 @@ impl<'a> TreeMut for TreeMutView<'a> { fn set_height(tree: &mut TreeMutView<'_>, node: NodeId, height: u16) { let children = { let mut node_data_mut = &mut tree.1; - let mut node = (&mut node_data_mut).get(node).unwrap(); + let node = (&mut node_data_mut).get(node).unwrap(); node.height = height; node.children.clone() }; diff --git a/packages/rink/Cargo.toml b/packages/rink/Cargo.toml index e6af1ef98..a339d6ea1 100644 --- a/packages/rink/Cargo.toml +++ b/packages/rink/Cargo.toml @@ -13,20 +13,20 @@ license = "MIT/Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-html = { path = "../html", version = "^0.3.0" } -dioxus-native-core = { path = "../native-core", version = "^0.2.0" } -dioxus-native-core-macro = { path = "../native-core-macro", version = "^0.3.0" } +dioxus-html = { workspace = true } +dioxus-native-core = { workspace = true } +dioxus-native-core-macro = { workspace = true } tui = "0.17.0" crossterm = "0.26.1" anyhow = "1.0.42" -tokio = { version = "1.15.0", features = ["full"] } +tokio = { workspace = true, features = ["full"] } futures = "0.3.19" -taffy = "0.2.1" +taffy = "0.3.12" smallvec = "1.6" -rustc-hash = "1.1.0" +rustc-hash = { workspace = true } anymap = "1.0.0-beta.2" -futures-channel = "0.3.25" +futures-channel = { workspace = true } shipyard = { version = "0.6.2", features = ["proc", "std"], default-features = false } once_cell = "1.17.1" diff --git a/packages/rink/examples/counter.rs b/packages/rink/examples/counter_button.rs similarity index 100% rename from packages/rink/examples/counter.rs rename to packages/rink/examples/counter_button.rs diff --git a/packages/rink/src/layout.rs b/packages/rink/src/layout.rs index b7eff57a6..944d39400 100644 --- a/packages/rink/src/layout.rs +++ b/packages/rink/src/layout.rs @@ -81,10 +81,11 @@ impl State for TaffyLayout { }; if let PossiblyUninitalized::Initialized(n) = self.node { if self.style != style { - taffy.set_style(n, style).unwrap(); + taffy.set_style(n, style.clone()).unwrap(); } } else { - self.node = PossiblyUninitalized::Initialized(taffy.new_leaf(style).unwrap()); + self.node = + PossiblyUninitalized::Initialized(taffy.new_leaf(style.clone()).unwrap()); changed = true; } } else { @@ -117,69 +118,90 @@ impl State for TaffyLayout { child_layout.push(l.node.unwrap()); } - fn scale_dimention(d: Dimension) -> Dimension { + fn scale_dimension(d: Dimension) -> Dimension { match d { Dimension::Points(p) => Dimension::Points(unit_to_layout_space(p)), Dimension::Percent(p) => Dimension::Percent(p), Dimension::Auto => Dimension::Auto, - Dimension::Undefined => Dimension::Undefined, } } - let style = Style { - position: Rect { - left: scale_dimention(style.position.left), - right: scale_dimention(style.position.right), - top: scale_dimention(style.position.top), - bottom: scale_dimention(style.position.bottom), + + fn scale_length_percentage_auto(d: LengthPercentageAuto) -> LengthPercentageAuto { + match d { + LengthPercentageAuto::Points(p) => { + LengthPercentageAuto::Points(unit_to_layout_space(p)) + } + LengthPercentageAuto::Percent(p) => LengthPercentageAuto::Percent(p), + LengthPercentageAuto::Auto => LengthPercentageAuto::Auto, + } + } + + fn scale_length_percentage(d: LengthPercentage) -> LengthPercentage { + match d { + LengthPercentage::Points(p) => { + LengthPercentage::Points(unit_to_layout_space(p)) + } + LengthPercentage::Percent(p) => LengthPercentage::Percent(p), + } + } + + let scaled_style = Style { + inset: Rect { + left: scale_length_percentage_auto(style.inset.left), + right: scale_length_percentage_auto(style.inset.right), + top: scale_length_percentage_auto(style.inset.top), + bottom: scale_length_percentage_auto(style.inset.bottom), }, margin: Rect { - left: scale_dimention(style.margin.left), - right: scale_dimention(style.margin.right), - top: scale_dimention(style.margin.top), - bottom: scale_dimention(style.margin.bottom), + left: scale_length_percentage_auto(style.margin.left), + right: scale_length_percentage_auto(style.margin.right), + top: scale_length_percentage_auto(style.margin.top), + bottom: scale_length_percentage_auto(style.margin.bottom), }, padding: Rect { - left: scale_dimention(style.padding.left), - right: scale_dimention(style.padding.right), - top: scale_dimention(style.padding.top), - bottom: scale_dimention(style.padding.bottom), + left: scale_length_percentage(style.padding.left), + right: scale_length_percentage(style.padding.right), + top: scale_length_percentage(style.padding.top), + bottom: scale_length_percentage(style.padding.bottom), }, border: Rect { - left: scale_dimention(style.border.left), - right: scale_dimention(style.border.right), - top: scale_dimention(style.border.top), - bottom: scale_dimention(style.border.bottom), + left: scale_length_percentage(style.border.left), + right: scale_length_percentage(style.border.right), + top: scale_length_percentage(style.border.top), + bottom: scale_length_percentage(style.border.bottom), }, gap: Size { - width: scale_dimention(style.gap.width), - height: scale_dimention(style.gap.height), + width: scale_length_percentage(style.gap.width), + height: scale_length_percentage(style.gap.height), }, - flex_basis: scale_dimention(style.flex_basis), + flex_basis: scale_dimension(style.flex_basis), size: Size { - width: scale_dimention(style.size.width), - height: scale_dimention(style.size.height), + width: scale_dimension(style.size.width), + height: scale_dimension(style.size.height), }, min_size: Size { - width: scale_dimention(style.min_size.width), - height: scale_dimention(style.min_size.height), + width: scale_dimension(style.min_size.width), + height: scale_dimension(style.min_size.height), }, max_size: Size { - width: scale_dimention(style.max_size.width), - height: scale_dimention(style.max_size.height), + width: scale_dimension(style.max_size.width), + height: scale_dimension(style.max_size.height), }, - ..style + ..style.clone() }; if let PossiblyUninitalized::Initialized(n) = self.node { if self.style != style { - taffy.set_style(n, style).unwrap(); + taffy.set_style(n, scaled_style).unwrap(); } if taffy.children(n).unwrap() != child_layout { taffy.set_children(n, &child_layout).unwrap(); } } else { self.node = PossiblyUninitalized::Initialized( - taffy.new_with_children(style, &child_layout).unwrap(), + taffy + .new_with_children(scaled_style, &child_layout) + .unwrap(), ); changed = true; } diff --git a/packages/rink/src/lib.rs b/packages/rink/src/lib.rs index 5c7b644c0..66b7ffda9 100644 --- a/packages/rink/src/lib.rs +++ b/packages/rink/src/lib.rs @@ -98,7 +98,8 @@ pub fn render( let event_tx_clone = event_tx.clone(); if !cfg.headless { std::thread::spawn(move || { - let tick_rate = Duration::from_millis(1000); + // Timeout after 10ms when waiting for events + let tick_rate = Duration::from_millis(10); loop { if crossterm::event::poll(tick_rate).unwrap() { let evt = crossterm::event::read().unwrap(); @@ -171,7 +172,7 @@ pub fn render( .unwrap(); // the root node fills the entire area - let mut style = *taffy.style(root_node).unwrap(); + let mut style = taffy.style(root_node).unwrap().clone(); let new_size = Size { width: Dimension::Points(width), height: Dimension::Points(height), diff --git a/packages/rink/src/query.rs b/packages/rink/src/query.rs index 1cf113310..2f4fe02e0 100644 --- a/packages/rink/src/query.rs +++ b/packages/rink/src/query.rs @@ -91,15 +91,7 @@ impl<'a> ElementRef<'a> { pub fn layout(&self) -> Option { let layout = self .stretch - .layout( - self.inner - .get(self.id) - .unwrap() - .get::() - .unwrap() - .node - .ok()?, - ) + .layout(self.inner.get(self.id)?.get::()?.node.ok()?) .ok(); layout.map(|layout| Layout { order: layout.order, diff --git a/packages/rink/src/widget.rs b/packages/rink/src/widget.rs index 7c6645692..ab9044998 100644 --- a/packages/rink/src/widget.rs +++ b/packages/rink/src/widget.rs @@ -26,7 +26,7 @@ impl<'a> RinkBuffer<'a> { // panic!("({x}, {y}) is not in {area:?}"); return; } - let mut cell = self.buf.get_mut(x, y); + let cell = self.buf.get_mut(x, y); cell.bg = convert(self.cfg.rendering_mode, new.bg.blend(cell.bg)); if new.symbol.is_empty() { if !cell.symbol.is_empty() { diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml index e1f442ab4..df6e1000a 100644 --- a/packages/router/Cargo.toml +++ b/packages/router/Cargo.toml @@ -11,8 +11,8 @@ 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 = "../dioxus", version = "0.3.0"} -futures-channel = "0.3.21" +dioxus = { workspace = true} +futures-channel = { workspace = true } url = { version = "2.2.2", default-features = false } # for wasm @@ -28,12 +28,12 @@ web-sys = { version = "0.3", features = [ "Window", "Location", ], optional = true } -wasm-bindgen = { version = "0.2", optional = true } +wasm-bindgen = { workspace = true, optional = true } js-sys = { version = "0.3", optional = true } gloo-events = { version = "0.1.1", optional = true } -log = "0.4.14" +log = { workspace = true } thiserror = "1.0.30" -futures-util = "0.3.21" +futures-util = { workspace = true } serde = { version = "1", optional = true } serde_urlencoded = { version = "0.7.1", optional = true } @@ -48,13 +48,13 @@ console_error_panic_hook = "0.1.7" wasm-logger = "0.2.0" wasm-bindgen-test = "0.3" gloo-utils = "0.1.2" -dioxus-web = { path = "../web", version = "0.3.0" } -# dioxus-desktop = { path = "../desktop", optional = true } +dioxus-web = { workspace = true } +# dioxus-desktop = { workspace = true, optional = true } # not wasm [target.wasm32-unknown-unknown.dev-dependencies] -dioxus-router = { path = ".", features = ["web"] } +dioxus-router = { workspace = true, features = ["web"] } [dev-dependencies.web-sys] version = "0.3" diff --git a/packages/router/examples/simple.rs b/packages/router/examples/simple_routes.rs similarity index 100% rename from packages/router/examples/simple.rs rename to packages/router/examples/simple_routes.rs diff --git a/packages/router/src/components/route.rs b/packages/router/src/components/route.rs index cf665d2e1..7bfc48993 100644 --- a/packages/router/src/components/route.rs +++ b/packages/router/src/components/route.rs @@ -45,13 +45,13 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element { router_root.register_total_route(route_context.total_route, cx.scope_id()); }); - log::debug!("Checking Route: {:?}", cx.props.to); + log::trace!("Checking Route: {:?}", cx.props.to); if router_root.should_render(cx.scope_id()) { - log::debug!("Route should render: {:?}", cx.scope_id()); + log::trace!("Route should render: {:?}", cx.scope_id()); cx.render(rsx!(&cx.props.children)) } else { - log::debug!("Route should *not* render: {:?}", cx.scope_id()); + log::trace!("Route should *not* render: {:?}", cx.scope_id()); cx.render(rsx!(())) } } diff --git a/packages/router/src/components/router.rs b/packages/router/src/components/router.rs index 54131a13a..8d5365c35 100644 --- a/packages/router/src/components/router.rs +++ b/packages/router/src/components/router.rs @@ -29,7 +29,9 @@ pub struct RouterProps<'a> { pub active_class: Option<&'a str>, /// Set the initial url. - pub initial_url: Option, + // This is Option> because we want to be able to either omit the prop or pass in Option + #[props(into)] + pub initial_url: Option>, } /// A component that conditionally renders children based on the current location of the app. @@ -45,7 +47,7 @@ pub fn Router<'a>(cx: Scope<'a, RouterProps<'a>>) -> Element { RouterCfg { base_url: cx.props.base_url.map(|s| s.to_string()), active_class: cx.props.active_class.map(|s| s.to_string()), - initial_url: cx.props.initial_url.clone(), + initial_url: cx.props.initial_url.clone().flatten(), }, )) }); diff --git a/packages/router/tests/web_router.rs b/packages/router/tests/web_router.rs index 9c4ed9712..13e2847a4 100644 --- a/packages/router/tests/web_router.rs +++ b/packages/router/tests/web_router.rs @@ -22,7 +22,7 @@ fn simple_test() { onchange: move |router: RouterContext| log::trace!("route changed to {:?}", router.current_location()), active_class: "is-active", Route { to: "/", Home {} } - Route { to: "blog" + Route { to: "blog", Route { to: "/", BlogList {} } Route { to: ":id", BlogPost {} } } diff --git a/packages/rsx-rosetta/Cargo.toml b/packages/rsx-rosetta/Cargo.toml index d160d2bf9..5a096d56a 100644 --- a/packages/rsx-rosetta/Cargo.toml +++ b/packages/rsx-rosetta/Cargo.toml @@ -13,8 +13,8 @@ keywords = ["dom", "ui", "gui", "react"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-autofmt = { path = "../autofmt", version = "0.3.0" } -dioxus-rsx = { path = "../rsx" , version = "^0.0.3" } +dioxus-autofmt = { workspace = true } +dioxus-rsx = { workspace = true } html_parser = "0.6.3" proc-macro2 = "1.0.49" quote = "1.0.23" @@ -25,3 +25,6 @@ convert_case = "0.5.0" # default = ["html"] # eventually more output options + +[dev-dependencies] +pretty_assertions = "1.2.1" \ No newline at end of file diff --git a/packages/rsx-rosetta/src/lib.rs b/packages/rsx-rosetta/src/lib.rs index 64fed1e18..4f30c0081 100644 --- a/packages/rsx-rosetta/src/lib.rs +++ b/packages/rsx-rosetta/src/lib.rs @@ -1,6 +1,6 @@ use convert_case::{Case, Casing}; use dioxus_rsx::{ - BodyNode, CallBody, Component, Element, ElementAttr, ElementAttrNamed, IfmtInput, + BodyNode, CallBody, Component, Element, ElementAttr, ElementAttrNamed, ElementName, IfmtInput, }; pub use html_parser::{Dom, Node}; use proc_macro2::{Ident, Span}; @@ -21,7 +21,7 @@ pub fn rsx_node_from_html(node: &Node) -> Option { Node::Text(text) => Some(BodyNode::Text(ifmt_from_text(text))), Node::Element(el) => { let el_name = el.name.to_case(Case::Snake); - let el_name = Ident::new(el_name.as_str(), Span::call_site()); + let el_name = ElementName::Ident(Ident::new(el_name.as_str(), Span::call_site())); let mut attributes: Vec<_> = el .attributes diff --git a/packages/rsx-rosetta/tests/simple.rs b/packages/rsx-rosetta/tests/simple.rs new file mode 100644 index 000000000..b8fd095e1 --- /dev/null +++ b/packages/rsx-rosetta/tests/simple.rs @@ -0,0 +1,68 @@ +use html_parser::Dom; + +#[test] +fn simple_elements() { + let html = r#" +
+
hello world!
+
hello world!
+
hello world!
+
hello world!
+
hello world!
+
hello world!
+ hello world! +
+ "# + .trim(); + + let dom = Dom::parse(html).unwrap(); + + let body = rsx_rosetta::rsx_from_html(&dom); + + let out = dioxus_autofmt::write_block_out(body).unwrap(); + + let expected = r#" + div { + div { class: "asd", "hello world!" } + div { id: "asd", "hello world!" } + div { id: "asd", "hello world!" } + div { r#for: "asd", "hello world!" } + div { r#async: "asd", "hello world!" } + div { large_thing: "asd", "hello world!" } + ai_is_awesome { "hello world!" } + }"#; + pretty_assertions::assert_eq!(&out, &expected); +} + +#[test] +fn deeply_nested() { + let html = r#" +
+
+
+
+
+
+
+
+
+
+ "# + .trim(); + + let dom = Dom::parse(html).unwrap(); + + let body = rsx_rosetta::rsx_from_html(&dom); + + let out = dioxus_autofmt::write_block_out(body).unwrap(); + + let expected = r#" + div { + div { class: "asd", + div { class: "asd", + div { class: "asd", div { class: "asd" } } + } + } + }"#; + pretty_assertions::assert_eq!(&out, &expected); +} diff --git a/packages/rsx/Cargo.toml b/packages/rsx/Cargo.toml index 055a97132..d4b997187 100644 --- a/packages/rsx/Cargo.toml +++ b/packages/rsx/Cargo.toml @@ -13,7 +13,7 @@ keywords = ["dom", "ui", "gui", "react"] [dependencies] proc-macro2 = { version = "1.0", features = ["span-locations"] } -dioxus-core = { path = "../core", version = "^0.3.0"} +dioxus-core = { workspace = true} syn = { version = "1.0", features = ["full", "extra-traits"] } quote = { version = "1.0" } serde = { version = "1.0", features = ["derive"] } diff --git a/packages/rsx/src/component.rs b/packages/rsx/src/component.rs index 5dc18e0e6..45078b65f 100644 --- a/packages/rsx/src/component.rs +++ b/packages/rsx/src/component.rs @@ -230,30 +230,28 @@ impl Parse for ComponentField { let name = Ident::parse_any(input)?; input.parse::()?; - if name.to_string().starts_with("on") { - let content = ContentField::OnHandlerRaw(input.parse()?); - return Ok(Self { name, content }); - } - - if name == "key" { - let content = ContentField::Formatted(input.parse()?); - return Ok(Self { name, content }); - } - if input.peek(LitStr) { - let forked = input.fork(); - let t: LitStr = forked.parse()?; - // the string literal must either be the end of the input or a followed by a comma - if (forked.is_empty() || forked.peek(Token![,])) && is_literal_foramtted(&t) { + let content = { + if name.to_string().starts_with("on") { + ContentField::OnHandlerRaw(input.parse()?) + } else if name == "key" { let content = ContentField::Formatted(input.parse()?); return Ok(Self { name, content }); + } else if input.peek(LitStr) { + let forked = input.fork(); + let t: LitStr = forked.parse()?; + // the string literal must either be the end of the input or a followed by a comma + if (forked.is_empty() || forked.peek(Token![,])) && is_literal_foramtted(&t) { + ContentField::Formatted(input.parse()?) + } else { + ContentField::ManExpr(input.parse()?) + } + } else { + ContentField::ManExpr(input.parse()?) } + }; + if input.peek(LitStr) || input.peek(Ident) { + missing_trailing_comma!(content.span()); } - - if input.peek(LitStr) && input.peek2(LitStr) { - missing_trailing_comma!(input.span()); - } - - let content = ContentField::ManExpr(input.parse()?); Ok(Self { name, content }) } } diff --git a/packages/rsx/src/element.rs b/packages/rsx/src/element.rs index e47c2e02a..466200eca 100644 --- a/packages/rsx/src/element.rs +++ b/packages/rsx/src/element.rs @@ -1,9 +1,13 @@ +use std::fmt::{Display, Formatter}; + use super::*; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{quote, ToTokens, TokenStreamExt}; use syn::{ parse::{Parse, ParseBuffer, ParseStream}, + punctuated::Punctuated, + spanned::Spanned, Error, Expr, Ident, LitStr, Result, Token, }; @@ -12,7 +16,7 @@ use syn::{ // ======================================= #[derive(PartialEq, Eq, Clone, Debug, Hash)] pub struct Element { - pub name: Ident, + pub name: ElementName, pub key: Option, pub attributes: Vec, pub children: Vec, @@ -22,7 +26,7 @@ pub struct Element { impl Parse for Element { fn parse(stream: ParseStream) -> Result { - let el_name = Ident::parse(stream)?; + let el_name = ElementName::parse(stream)?; // parse the guts let content: ParseBuffer; @@ -181,7 +185,7 @@ impl ToTokens for Element { tokens.append_all(quote! { __cx.element( - dioxus_elements::#name, + #name, __cx.bump().alloc([ #(#listeners),* ]), __cx.bump().alloc([ #(#attr),* ]), __cx.bump().alloc([ #(#children),* ]), @@ -191,6 +195,75 @@ impl ToTokens for Element { } } +#[derive(PartialEq, Eq, Clone, Debug, Hash)] +pub enum ElementName { + Ident(Ident), + Custom(LitStr), +} + +impl ElementName { + pub(crate) fn tag_name(&self) -> TokenStream2 { + match self { + ElementName::Ident(i) => quote! { dioxus_elements::#i::TAG_NAME }, + ElementName::Custom(s) => quote! { #s }, + } + } +} + +impl ElementName { + pub fn span(&self) -> Span { + match self { + ElementName::Ident(i) => i.span(), + ElementName::Custom(s) => s.span(), + } + } +} + +impl PartialEq<&str> for ElementName { + fn eq(&self, other: &&str) -> bool { + match self { + ElementName::Ident(i) => i == *other, + ElementName::Custom(s) => s.value() == *other, + } + } +} + +impl Display for ElementName { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + ElementName::Ident(i) => write!(f, "{}", i), + ElementName::Custom(s) => write!(f, "{}", s.value()), + } + } +} + +impl Parse for ElementName { + fn parse(stream: ParseStream) -> Result { + let raw = Punctuated::::parse_separated_nonempty(stream)?; + if raw.len() == 1 { + Ok(ElementName::Ident(raw.into_iter().next().unwrap())) + } else { + let span = raw.span(); + let tag = raw + .into_iter() + .map(|ident| ident.to_string()) + .collect::>() + .join("-"); + let tag = LitStr::new(&tag, span); + Ok(ElementName::Custom(tag)) + } + } +} + +impl ToTokens for ElementName { + fn to_tokens(&self, tokens: &mut TokenStream2) { + match self { + ElementName::Ident(i) => tokens.append_all(quote! { dioxus_elements::#i }), + ElementName::Custom(s) => tokens.append_all(quote! { #s }), + } + } +} + #[derive(PartialEq, Eq, Clone, Debug, Hash)] pub enum ElementAttr { /// `attribute: "value"` @@ -234,7 +307,7 @@ impl ElementAttr { #[derive(PartialEq, Eq, Clone, Debug, Hash)] pub struct ElementAttrNamed { - pub el_name: Ident, + pub el_name: ElementName, pub attr: ElementAttr, } @@ -242,24 +315,46 @@ impl ToTokens for ElementAttrNamed { fn to_tokens(&self, tokens: &mut TokenStream2) { let ElementAttrNamed { el_name, attr } = self; - tokens.append_all(match attr { + let ns = |name| match el_name { + ElementName::Ident(i) => quote! { dioxus_elements::#i::#name.1 }, + ElementName::Custom(_) => quote! { None }, + }; + let volitile = |name| match el_name { + ElementName::Ident(_) => quote! { #el_name::#name.2 }, + ElementName::Custom(_) => quote! { false }, + }; + let attribute = |name: &Ident| match el_name { + ElementName::Ident(_) => quote! { #el_name::#name.0 }, + ElementName::Custom(_) => { + let as_string = name.to_string(); + quote!(#as_string) + } + }; + + let attribute = match attr { ElementAttr::AttrText { name, value } => { + let ns = ns(name); + let volitile = volitile(name); + let attribute = attribute(name); quote! { __cx.attr( - dioxus_elements::#el_name::#name.0, + #attribute, #value, - dioxus_elements::#el_name::#name.1, - dioxus_elements::#el_name::#name.2 + #ns, + #volitile ) } } ElementAttr::AttrExpression { name, value } => { + let ns = ns(name); + let volitile = volitile(name); + let attribute = attribute(name); quote! { __cx.attr( - dioxus_elements::#el_name::#name.0, + #attribute, #value, - dioxus_elements::#el_name::#name.1, - dioxus_elements::#el_name::#name.2 + #ns, + #volitile ) } } @@ -288,7 +383,9 @@ impl ToTokens for ElementAttrNamed { dioxus_elements::events::#name(__cx, #tokens) } } - }); + }; + + tokens.append_all(attribute); } } diff --git a/packages/rsx/src/lib.rs b/packages/rsx/src/lib.rs index d22b122e9..07c887e65 100644 --- a/packages/rsx/src/lib.rs +++ b/packages/rsx/src/lib.rs @@ -426,13 +426,25 @@ impl<'a> DynamicContext<'a> { match root { BodyNode::Element(el) => { let el_name = &el.name; + let ns = |name| match el_name { + ElementName::Ident(i) => quote! { dioxus_elements::#i::#name }, + ElementName::Custom(_) => quote! { None }, + }; let static_attrs = el.attributes.iter().map(|attr| match &attr.attr { ElementAttr::AttrText { name, value } if value.is_static() => { let value = value.to_static().unwrap(); + let ns = ns(quote!(#name.1)); + let name = match el_name { + ElementName::Ident(_) => quote! { #el_name::#name.0 }, + ElementName::Custom(_) => { + let as_string = name.to_string(); + quote! { #as_string } + } + }; quote! { ::dioxus::core::TemplateAttribute::Static { - name: dioxus_elements::#el_name::#name.0, - namespace: dioxus_elements::#el_name::#name.1, + name: #name, + namespace: #ns, value: #value, // todo: we don't diff these so we never apply the volatile flag @@ -479,10 +491,13 @@ impl<'a> DynamicContext<'a> { let _opt = el.children.len() == 1; let children = quote! { #(#children),* }; + let ns = ns(quote!(NAME_SPACE)); + let el_name = el_name.tag_name(); + quote! { ::dioxus::core::TemplateNode::Element { - tag: dioxus_elements::#el_name::TAG_NAME, - namespace: dioxus_elements::#el_name::NAME_SPACE, + tag: #el_name, + namespace: #ns, attrs: &[ #attrs ], children: &[ #children ], } diff --git a/packages/rsx/src/node.rs b/packages/rsx/src/node.rs index 0d5556552..54448c883 100644 --- a/packages/rsx/src/node.rs +++ b/packages/rsx/src/node.rs @@ -50,7 +50,16 @@ impl Parse for BodyNode { return Ok(BodyNode::Text(stream.parse()?)); } + // if this is a dash-separated path, it's a web component (custom element) let body_stream = stream.fork(); + if let Ok(ElementName::Custom(name)) = body_stream.parse::() { + if name.value().contains('-') && body_stream.peek(token::Brace) { + return Ok(BodyNode::Element(stream.parse::()?)); + } + } + + let body_stream = stream.fork(); + if let Ok(path) = body_stream.parse::() { // this is an Element if path match of: // - one ident diff --git a/packages/signals/Cargo.toml b/packages/signals/Cargo.toml index 9a12c787d..3ccd6b9b8 100644 --- a/packages/signals/Cargo.toml +++ b/packages/signals/Cargo.toml @@ -6,5 +6,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-core = { path = "../core" } -slab = "0.4.7" +dioxus-core = { workspace = true } +slab = { workspace = true } diff --git a/packages/ssr/Cargo.toml b/packages/ssr/Cargo.toml index 02900ca0e..ed1d443ea 100644 --- a/packages/ssr/Cargo.toml +++ b/packages/ssr/Cargo.toml @@ -13,13 +13,13 @@ keywords = ["dom", "ui", "gui", "react", "ssr"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0", features = ["serialize"] } +dioxus-core = { workspace = true, features = ["serialize"] } askama_escape = "0.10.3" [dev-dependencies] -dioxus = { path = "../dioxus", version = "0.3.0" } +dioxus = { workspace = true } thiserror = "1.0.23" -log = "0.4.13" +log = { workspace = true } fern = { version = "0.6.0", features = ["colored"] } anyhow = "1.0" argh = "0.1.4" diff --git a/packages/ssr/src/renderer.rs b/packages/ssr/src/renderer.rs index 6f6808c74..a85a3ea7e 100644 --- a/packages/ssr/src/renderer.rs +++ b/packages/ssr/src/renderer.rs @@ -3,7 +3,7 @@ use crate::cache::StringCache; use dioxus_core::{prelude::*, AttributeValue, DynamicNode, RenderReturn}; use std::collections::HashMap; use std::fmt::Write; -use std::rc::Rc; +use std::sync::Arc; /// A virtualdom renderer that caches the templates it has seen for faster rendering #[derive(Default)] @@ -25,7 +25,7 @@ pub struct Renderer { pub skip_components: bool, /// A cache of templates that have been rendered - template_cache: HashMap<&'static str, Rc>, + template_cache: HashMap<&'static str, Arc>, } impl Renderer { @@ -67,7 +67,7 @@ impl Renderer { let entry = self .template_cache .entry(template.template.get().name) - .or_insert_with(|| Rc::new(StringCache::from_template(template).unwrap())) + .or_insert_with(|| Arc::new(StringCache::from_template(template).unwrap())) .clone(); let mut inner_html = None; diff --git a/packages/web/Cargo.toml b/packages/web/Cargo.toml index 7adfbf13a..daa296bb8 100644 --- a/packages/web/Cargo.toml +++ b/packages/web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dioxus-web" -version = "0.3.1" +version = "0.3.2" authors = ["Jonathan Kelley"] edition = "2018" description = "Dioxus VirtualDOM renderer for the web browser using websys" @@ -11,27 +11,29 @@ documentation = "https://dioxuslabs.com" keywords = ["dom", "ui", "gui", "react", "wasm"] [dependencies] -dioxus-core = { path = "../core", version = "^0.3.0", features = ["serialize"] } -dioxus-html = { path = "../html", version = "^0.3.0", features = ["wasm-bind"] } -dioxus-interpreter-js = { path = "../interpreter", version = "^0.3.0", features = [ - "sledgehammer" +dioxus-core = { workspace = true, features = ["serialize"] } +dioxus-html = { workspace = true, features = ["wasm-bind"] } +dioxus-interpreter-js = { workspace = true, features = [ + "sledgehammer", + "minimal_bindings", ] } js-sys = "0.3.56" -wasm-bindgen = { version = "0.2.79", features = ["enable-interning"] } +wasm-bindgen = { workspace = true, features = ["enable-interning"] } wasm-bindgen-futures = "0.4.29" -log = "0.4.14" -rustc-hash = "1.1.0" +log = { workspace = true } +rustc-hash = { workspace = true } console_error_panic_hook = { version = "0.1.7", optional = true } once_cell = "1.9.0" anyhow = "1.0.53" gloo-timers = { version = "0.2.3", features = ["futures"] } -futures-util = "0.3.19" +futures-util = { workspace = true, features = ["std", "async-await", "async-await-macro"] } smallstr = "0.2.0" -futures-channel = "0.3.21" +futures-channel = { workspace = true } serde_json = { version = "1.0" } serde = { version = "1.0" } serde-wasm-bindgen = "0.4.5" +async-trait = "0.1.58" [dependencies.web-sys] version = "0.3.56" @@ -76,6 +78,9 @@ features = [ "Location", "MessageEvent", "console", + "FileList", + "File", + "FileReader" ] [features] @@ -84,8 +89,8 @@ panic_hook = ["console_error_panic_hook"] hydrate = [] [dev-dependencies] -dioxus = { path = "../dioxus", version = "0.3.0" } +dioxus = { workspace = true } wasm-bindgen-test = "0.3.29" -dioxus-ssr = { path = "../ssr", version = "0.3.0"} +dioxus-ssr = { workspace = true} wasm-logger = "0.2.0" -dioxus-web = { path = ".", features = ["hydrate"] } +dioxus-web = { workspace = true, features = ["hydrate"] } diff --git a/packages/web/src/dom.rs b/packages/web/src/dom.rs index 4d17749d8..b9fb6b942 100644 --- a/packages/web/src/dom.rs +++ b/packages/web/src/dom.rs @@ -10,15 +10,16 @@ use dioxus_core::{ BorrowedAttributeValue, ElementId, Mutation, Template, TemplateAttribute, TemplateNode, }; -use dioxus_html::{event_bubbles, CompositionData, FormData}; -use dioxus_interpreter_js::{save_template, Channel}; +use dioxus_html::{event_bubbles, CompositionData, FileEngine, FormData, MountedData}; +use dioxus_interpreter_js::{get_node, minimal_bindings, save_template, Channel}; use futures_channel::mpsc; +use js_sys::Array; use rustc_hash::FxHashMap; -use std::{any::Any, rc::Rc}; -use wasm_bindgen::{closure::Closure, JsCast}; -use web_sys::{Document, Element, Event, HtmlElement}; +use std::{any::Any, rc::Rc, sync::Arc}; +use wasm_bindgen::{closure::Closure, prelude::wasm_bindgen, JsCast, JsValue}; +use web_sys::{console, Document, Element, Event}; -use crate::Config; +use crate::{file_engine::WebFileEngine, Config}; pub struct WebsysDom { document: Document, @@ -27,6 +28,7 @@ pub struct WebsysDom { templates: FxHashMap, max_template_id: u32, pub(crate) interpreter: Channel, + event_channel: mpsc::UnboundedSender, } pub struct UiEvent { @@ -34,7 +36,6 @@ pub struct UiEvent { pub bubbles: bool, pub element: ElementId, pub data: Rc, - pub event: Event, } impl WebsysDom { @@ -48,19 +49,24 @@ impl WebsysDom { }; let interpreter = Channel::default(); - let handler: Closure = - Closure::wrap(Box::new(move |event: &web_sys::Event| { + let handler: Closure = Closure::wrap(Box::new({ + let event_channel = event_channel.clone(); + move |event: &web_sys::Event| { let name = event.type_(); let element = walk_event_for_id(event); let bubbles = dioxus_html::event_bubbles(name.as_str()); if let Some((element, target)) = element { - if target + if let Some(prevent_requests) = target .get_attribute("dioxus-prevent-default") .as_deref() - .map(|f| f.trim_start_matches("on")) - == Some(&name) + .map(|f| f.split_whitespace()) { - event.prevent_default(); + if prevent_requests + .map(|f| f.trim_start_matches("on")) + .any(|f| f == name) + { + event.prevent_default(); + } } let data = virtual_event_from_websys_event(event.clone(), target); @@ -69,10 +75,10 @@ impl WebsysDom { bubbles, element, data, - event: event.clone(), }); } - })); + } + })); dioxus_interpreter_js::initilize( root.clone().unchecked_into(), @@ -85,6 +91,7 @@ impl WebsysDom { interpreter, templates: FxHashMap::default(), max_template_id: 0, + event_channel, } } @@ -128,14 +135,12 @@ impl WebsysDom { namespace, } = attr { - match namespace { - Some(ns) if *ns == "style" => { - el.dyn_ref::() - .map(|f| f.style().set_property(name, value)); - } - Some(ns) => el.set_attribute_ns(Some(ns), name, value).unwrap(), - None => el.set_attribute(name, value).unwrap(), - } + minimal_bindings::setAttributeInner( + el.clone().into(), + name, + JsValue::from_str(value), + *namespace, + ); } } for child in *children { @@ -156,6 +161,8 @@ impl WebsysDom { pub fn apply_edits(&mut self, mut edits: Vec) { use Mutation::*; let i = &mut self.interpreter; + // we need to apply the mount events last, so we collect them here + let mut to_mount = Vec::new(); for edit in &edits { match edit { AppendChildren { id, m } => i.append_children(id.0 as u32, *m as u32), @@ -206,17 +213,43 @@ impl WebsysDom { }, SetText { value, id } => i.set_text(id.0 as u32, value), NewEventListener { name, id, .. } => { - i.new_event_listener(name, id.0 as u32, event_bubbles(name) as u8); - } - RemoveEventListener { name, id } => { - i.remove_event_listener(name, id.0 as u32, event_bubbles(name) as u8) + match *name { + // mounted events are fired immediately after the element is mounted. + "mounted" => { + to_mount.push(*id); + } + _ => { + i.new_event_listener(name, id.0 as u32, event_bubbles(name) as u8); + } + } } + RemoveEventListener { name, id } => match *name { + "mounted" => {} + _ => { + i.remove_event_listener(name, id.0 as u32, event_bubbles(name) as u8); + } + }, Remove { id } => i.remove(id.0 as u32), PushRoot { id } => i.push_root(id.0 as u32), } } edits.clear(); i.flush(); + + for id in to_mount { + let node = get_node(id.0 as u32); + if let Some(element) = node.dyn_ref::() { + log::info!("mounted event fired: {}", id.0); + let data: MountedData = element.into(); + let data = Rc::new(data); + let _ = self.event_channel.unbounded_send(UiEvent { + name: "mounted".to_string(), + bubbles: false, + element: id, + data, + }); + } + } } } @@ -224,6 +257,7 @@ impl WebsysDom { // We need tests that simulate clicks/etc and make sure every event type works. pub fn virtual_event_from_websys_event(event: web_sys::Event, target: Element) -> Rc { use dioxus_html::events::*; + console::log_1(&event.clone().into()); match event.type_().as_str() { "copy" | "cut" | "paste" => Rc::new(ClipboardData {}), @@ -325,64 +359,86 @@ fn read_input_to_data(target: Element) -> Rc { // try to fill in form values if let Some(form) = target.dyn_ref::() { - let elements = form.elements(); - for x in 0..elements.length() { - let element = elements.item(x).unwrap(); - if let Some(name) = element.get_attribute("name") { - let value: Option = element - .dyn_ref() - .map(|input: &web_sys::HtmlInputElement| { - match input.type_().as_str() { - "checkbox" => { - match input.checked() { - true => Some("true".to_string()), - false => Some("false".to_string()), - } - }, - "radio" => { - match input.checked() { - true => Some(input.value()), - false => None, - } - } - _ => Some(input.value()) - } - }) - .or_else(|| element.dyn_ref().map(|input: &web_sys::HtmlTextAreaElement| Some(input.value()))) - .or_else(|| element.dyn_ref().map(|input: &web_sys::HtmlSelectElement| Some(input.value()))) - .or_else(|| Some(element.dyn_ref::().unwrap().text_content())) - .expect("only an InputElement or TextAreaElement or an element with contenteditable=true can have an oninput event listener"); - if let Some(value) = value { - values.insert(name, value); + let form_data = get_form_data(form); + for value in form_data.entries().into_iter().flatten() { + if let Ok(array) = value.dyn_into::() { + if let Some(name) = array.get(0).as_string() { + if let Ok(item_values) = array.get(1).dyn_into::() { + let item_values = + item_values.iter().filter_map(|v| v.as_string()).collect(); + + values.insert(name, item_values); + } } } } } + let files = target + .dyn_ref() + .and_then(|input: &web_sys::HtmlInputElement| { + input.files().and_then(|files| { + WebFileEngine::new(files).map(|f| Arc::new(f) as Arc) + }) + }); + Rc::new(FormData { value, values, - files: None, + files, }) } +// web-sys does not expose the keys api for form data, so we need to manually bind to it +#[wasm_bindgen(inline_js = r#" + export function get_form_data(form) { + let values = new Map(); + const formData = new FormData(form); + + for (let name of formData.keys()) { + values.set(name, formData.getAll(name)); + } + + return values; + } +"#)] +extern "C" { + fn get_form_data(form: &web_sys::HtmlFormElement) -> js_sys::Map; +} + fn walk_event_for_id(event: &web_sys::Event) -> Option<(ElementId, web_sys::Element)> { - let mut target = event + let target = event .target() .expect("missing target") - .dyn_into::() - .expect("not a valid element"); + .dyn_into::() + .expect("not a valid node"); + let mut current_target_element = target.dyn_ref::().cloned(); loop { - match target.get_attribute("data-dioxus-id").map(|f| f.parse()) { - Some(Ok(id)) => return Some((ElementId(id), target)), - Some(Err(_)) => return None, + match ( + current_target_element + .as_ref() + .and_then(|el| el.get_attribute("data-dioxus-id").map(|f| f.parse())), + current_target_element, + ) { + // This node is an element, and has a dioxus id, so we can stop walking + (Some(Ok(id)), Some(target)) => return Some((ElementId(id), target)), - // walk the tree upwards until we actually find an event target - None => match target.parent_element() { - Some(parent) => target = parent, - None => return None, - }, + // Walk the tree upwards until we actually find an event target + (None, target_element) => { + let parent = match target_element.as_ref() { + Some(el) => el.parent_element(), + // if this is the first node and not an element, we need to get the parent from the target node + None => target.parent_element(), + }; + match parent { + Some(parent) => current_target_element = Some(parent), + _ => return None, + } + } + + // This node is an element with an invalid dioxus id, give up + _ => return None, } } } diff --git a/packages/web/src/file_engine.rs b/packages/web/src/file_engine.rs new file mode 100644 index 000000000..6552be084 --- /dev/null +++ b/packages/web/src/file_engine.rs @@ -0,0 +1,103 @@ +use dioxus_html::FileEngine; +use futures_channel::oneshot; +use js_sys::Uint8Array; +use wasm_bindgen::{prelude::Closure, JsCast}; +use web_sys::{File, FileList, FileReader}; + +pub(crate) struct WebFileEngine { + file_reader: FileReader, + file_list: FileList, +} + +impl WebFileEngine { + pub fn new(file_list: FileList) -> Option { + Some(Self { + file_list, + file_reader: FileReader::new().ok()?, + }) + } + + fn len(&self) -> usize { + self.file_list.length() as usize + } + + fn get(&self, index: usize) -> Option { + self.file_list.item(index as u32) + } + + fn find(&self, name: &str) -> Option { + (0..self.len()) + .filter_map(|i| self.get(i)) + .find(|f| f.name() == name) + } +} + +#[async_trait::async_trait(?Send)] +impl FileEngine for WebFileEngine { + fn files(&self) -> Vec { + (0..self.len()) + .filter_map(|i| self.get(i).map(|f| f.name())) + .collect() + } + + // read a file to bytes + async fn read_file(&self, file: &str) -> Option> { + let file = self.find(file)?; + + let file_reader = self.file_reader.clone(); + let (rx, tx) = oneshot::channel(); + let on_load: Closure = Closure::new({ + let mut rx = Some(rx); + move || { + let result = file_reader.result(); + let _ = rx + .take() + .expect("multiple files read without refreshing the channel") + .send(result); + } + }); + + self.file_reader + .set_onload(Some(on_load.as_ref().unchecked_ref())); + on_load.forget(); + self.file_reader.read_as_array_buffer(&file).ok()?; + + if let Ok(Ok(js_val)) = tx.await { + let as_u8_arr = Uint8Array::new(&js_val); + let as_u8_vec = as_u8_arr.to_vec(); + + Some(as_u8_vec) + } else { + None + } + } + + // read a file to string + async fn read_file_to_string(&self, file: &str) -> Option { + let file = self.find(file)?; + + let file_reader = self.file_reader.clone(); + let (rx, tx) = oneshot::channel(); + let on_load: Closure = Closure::new({ + let mut rx = Some(rx); + move || { + let result = file_reader.result(); + let _ = rx + .take() + .expect("multiple files read without refreshing the channel") + .send(result); + } + }); + + self.file_reader + .set_onload(Some(on_load.as_ref().unchecked_ref())); + on_load.forget(); + self.file_reader.read_as_text(&file).ok()?; + + if let Ok(Ok(js_val)) = tx.await { + js_val.as_string() + } else { + None + } + } +} diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index e208b0591..9fec0dcd6 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -61,6 +61,7 @@ use futures_util::{pin_mut, FutureExt, StreamExt}; mod cache; mod cfg; mod dom; +mod file_engine; mod hot_reload; #[cfg(feature = "hydrate")] mod rehydrate; @@ -225,7 +226,7 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop websys_dom.mount(); loop { - log::debug!("waiting for work"); + log::trace!("waiting for work"); // if virtualdom has nothing, wait for it to have something before requesting idle time // if there is work then this future resolves immediately. @@ -253,7 +254,7 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop res = rx.try_next().transpose().unwrap().ok(); } - // Todo: This is currently disabled because it has a negative impact on responce times for events but it could be re-enabled for tasks + // Todo: This is currently disabled because it has a negative impact on response times for events but it could be re-enabled for tasks // Jank free rendering // // 1. wait for the browser to give us "idle" time