Re-Export Manganis & Update Examples (#2625)

* feat: export manganis

* revision: use manganis in examples

* fix: manganis dep

* fix: workspace root finder

* fix: manganis dep

* fix: ci
This commit is contained in:
Miles Murgaw 2024-07-23 13:29:37 -04:00 committed by GitHub
parent 856fadc9d6
commit 672f4dfefc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 154 additions and 134 deletions

122
Cargo.lock generated
View file

@ -697,9 +697,9 @@ dependencies = [
[[package]]
name = "aws-lc-rs"
version = "1.8.0"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a47f2fb521b70c11ce7369a6c5fa4bd6af7e5d62ec06303875bafe7c6ba245"
checksum = "4ae74d9bd0a7530e8afd1770739ad34b36838829d6ad61818f9230f683f5ad77"
dependencies = [
"aws-lc-sys",
"mirai-annotations",
@ -709,9 +709,9 @@ dependencies = [
[[package]]
name = "aws-lc-sys"
version = "0.19.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2927c7af777b460b7ccd95f8b67acd7b4c04ec8896bf0c8e80ba30523cffc057"
checksum = "2e89b6941c2d1a7045538884d6e760ccfffdf8e1ffc2613d8efa74305e1f3752"
dependencies = [
"bindgen",
"cc",
@ -1408,9 +1408,9 @@ dependencies = [
[[package]]
name = "cargo_toml"
version = "0.20.3"
version = "0.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4895c018bb228aa6b3ba1a0285543fcb4b704734c3fb1f72afaa75aa769500c1"
checksum = "ad639525b1c67b6a298f378417b060fbc04618bea559482a8484381cce27d965"
dependencies = [
"serde",
"toml 0.8.15",
@ -1439,9 +1439,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.5"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052"
checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f"
dependencies = [
"jobserver",
"libc",
@ -2444,6 +2444,7 @@ dependencies = [
"dioxus-web",
"env_logger 0.10.2",
"futures-util",
"manganis",
"rand 0.8.5",
"serde",
"thiserror",
@ -2578,22 +2579,6 @@ dependencies = [
"quote",
]
[[package]]
name = "dioxus-core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "088daa3f45aaa729e9eef32dc0a9393dd709ee906b092089e5839cad1cad7c85"
dependencies = [
"futures-channel",
"futures-util",
"generational-box 0.5.1",
"longest-increasing-subsequence",
"rustc-hash",
"slab",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "dioxus-core"
version = "0.5.2"
@ -2621,6 +2606,23 @@ dependencies = [
"web-sys",
]
[[package]]
name = "dioxus-core"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3730d2459ab66951cedf10b09eb84141a6eda7f403c28057cbe010495be156b7"
dependencies = [
"futures-channel",
"futures-util",
"generational-box 0.5.6",
"longest-increasing-subsequence",
"rustc-hash",
"slab",
"slotmap",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "dioxus-core-macro"
version = "0.5.2"
@ -3945,15 +3947,6 @@ dependencies = [
"x11",
]
[[package]]
name = "generational-box"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f132919c96b85c02a067ceae965fd50ace57111e2f55c7384b95ac191f4d966b"
dependencies = [
"parking_lot",
]
[[package]]
name = "generational-box"
version = "0.5.2"
@ -3963,6 +3956,15 @@ dependencies = [
"rand 0.8.5",
]
[[package]]
name = "generational-box"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "557cf2cbacd0504c6bf8c29f52f8071e0de1d9783346713dc6121d7fa1e5d0e0"
dependencies = [
"parking_lot",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@ -4110,7 +4112,7 @@ dependencies = [
"gix-utils",
"itoa 1.0.11",
"thiserror",
"winnow 0.6.13",
"winnow 0.6.14",
]
[[package]]
@ -4131,7 +4133,7 @@ dependencies = [
"smallvec",
"thiserror",
"unicode-bom",
"winnow 0.6.13",
"winnow 0.6.14",
]
[[package]]
@ -4233,7 +4235,7 @@ dependencies = [
"itoa 1.0.11",
"smallvec",
"thiserror",
"winnow 0.6.13",
"winnow 0.6.14",
]
[[package]]
@ -4268,7 +4270,7 @@ dependencies = [
"gix-validate",
"memmap2",
"thiserror",
"winnow 0.6.13",
"winnow 0.6.14",
]
[[package]]
@ -5785,7 +5787,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]
[[package]]
@ -6040,23 +6042,22 @@ dependencies = [
[[package]]
name = "manganis"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c211cfb4529c79b32307b606e83a1bb15d491b3b4a1ab97159b161d7af9d1b72"
source = "git+https://github.com/DioxusLabs/manganis#8a6d74dc19072e7a650854bd722c452da51955d6"
dependencies = [
"dioxus-core 0.5.1",
"dioxus-core 0.5.6",
"manganis-macro",
]
[[package]]
name = "manganis-cli-support"
version = "0.2.4"
source = "git+https://github.com/DioxusLabs/manganis/#ad09a549775957c5ce177274cfbb6dc76c976c10"
source = "git+https://github.com/DioxusLabs/manganis#8a6d74dc19072e7a650854bd722c452da51955d6"
dependencies = [
"anyhow",
"image 0.25.1",
"imagequant",
"lightningcss",
"manganis-common 0.2.4 (git+https://github.com/DioxusLabs/manganis/)",
"manganis-common",
"mozjpeg",
"object",
"png",
@ -6074,24 +6075,7 @@ dependencies = [
[[package]]
name = "manganis-common"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "542300f1e7d9313de5b7e5b92d273ba42ab547c068d773559d616aa14987de43"
dependencies = [
"anyhow",
"base64 0.21.7",
"home",
"infer 0.11.0",
"reqwest 0.11.27",
"serde",
"toml 0.7.8",
"tracing",
"url",
]
[[package]]
name = "manganis-common"
version = "0.2.4"
source = "git+https://github.com/DioxusLabs/manganis/#ad09a549775957c5ce177274cfbb6dc76c976c10"
source = "git+https://github.com/DioxusLabs/manganis#8a6d74dc19072e7a650854bd722c452da51955d6"
dependencies = [
"anyhow",
"base64 0.21.7",
@ -6107,12 +6091,12 @@ dependencies = [
[[package]]
name = "manganis-macro"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "704a0123ac90fa630b21a04fde56c29dfd5a7665c5e8f3639567989daa2d29d1"
source = "git+https://github.com/DioxusLabs/manganis#8a6d74dc19072e7a650854bd722c452da51955d6"
dependencies = [
"manganis-common 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"manganis-common",
"proc-macro2",
"quote",
"serde_json",
"syn 2.0.71",
"tracing-subscriber",
]
@ -7313,9 +7297,9 @@ dependencies = [
[[package]]
name = "portable-atomic"
version = "1.6.0"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265"
[[package]]
name = "powerfmt"
@ -9958,7 +9942,7 @@ dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"winnow 0.6.13",
"winnow 0.6.14",
]
[[package]]
@ -11270,9 +11254,9 @@ dependencies = [
[[package]]
name = "winnow"
version = "0.6.13"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1"
checksum = "374ec40a2d767a3c1b4972d9475ecd557356637be906f2cb3f7fe17a6eb5e22f"
dependencies = [
"memchr",
]

View file

@ -105,8 +105,8 @@ wasm-bindgen-futures = "0.4.42"
html_parser = "0.7.0"
thiserror = "1.0.40"
prettyplease = { version = "0.2.16", features = ["verbatim"] }
manganis-cli-support = { git = "https://github.com/DioxusLabs/manganis/", features = ["html"] }
manganis = { version = "0.2.1" }
manganis-cli-support = { git = "hhttps://github.com/DioxusLabs/manganis", features = ["html"] }
manganis = { git = "https://github.com/DioxusLabs/manganis" }
const_format = "0.2.32"
cargo_toml = { version = "0.20.3" }
tauri-utils = { version = "=1.5.*" }

View file

@ -6,6 +6,8 @@
use dioxus::prelude::*;
use std::{collections::VecDeque, fmt::Debug, rc::Rc};
const STYLE: &str = asset!(file("./examples/assets/events.css"));
fn main() {
launch(app);
}
@ -24,7 +26,7 @@ fn app() -> Element {
};
rsx! {
style { {include_str!("./assets/events.css")} }
link { rel: "stylesheet", href: STYLE }
div { id: "container",
// focusing is necessary to catch keyboard events
div { id: "receiver", tabindex: 0,

View file

@ -12,6 +12,8 @@ use dioxus::events::*;
use dioxus::html::input_data::keyboard_types::Key;
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/calculator.css"));
fn main() {
LaunchBuilder::desktop()
.with_cfg(desktop!({
@ -52,7 +54,7 @@ fn app() -> Element {
};
rsx! {
style { {include_str!("./assets/calculator.css")} }
link { rel: "stylesheet", href: STYLE }
div { id: "wrapper",
div { class: "app",
div { class: "calculator", tabindex: "0", onkeydown: handle_key_down_event,

View file

@ -5,6 +5,8 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/clock.css"));
fn main() {
launch_desktop(app);
}
@ -36,7 +38,7 @@ fn app() -> Element {
);
rsx! {
style { {include_str!("./assets/clock.css")} }
link { rel: "stylesheet", href: STYLE }
div { id: "app",
div { id: "title", "Carpe diem 🎉" }
div { id: "clock-display", "{time}" }

View file

@ -3,9 +3,10 @@
//! This example shows how to manage focus in a Dioxus application. We implement a "roulette" that focuses on each input
//! in the grid every few milliseconds until the user interacts with the inputs.
use dioxus::prelude::*;
use std::rc::Rc;
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/roulette.css"));
fn main() {
launch_desktop(app);
@ -37,7 +38,7 @@ fn app() -> Element {
});
rsx! {
style { {include_str!("./assets/roulette.css")} }
link { rel: "stylesheet", href: STYLE }
h1 { "Input Roulette" }
button { onclick: move |_| running.toggle(), "Toggle roulette" }
div { id: "roulette-grid",

View file

@ -2,6 +2,8 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/counter.css"));
fn main() {
launch(app);
}
@ -14,7 +16,7 @@ fn app() -> Element {
let sum = use_memo(move || counters.read().iter().copied().sum::<i32>());
rsx! {
style { {include_str!("./assets/counter.css")} }
link { rel: "stylesheet", href: STYLE }
div { id: "controls",
button { onclick: move |_| counters.write().push(0), "Add counter" }

View file

@ -11,6 +11,8 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/crm.css"));
fn main() {
LaunchBuilder::new()
.with_cfg(desktop!({
@ -26,7 +28,7 @@ fn main() {
integrity: "sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5",
crossorigin: "anonymous"
}
style { {include_str!("./assets/crm.css")} }
link { rel: "stylesheet", href: STYLE }
h1 { "Dioxus CRM Example" }
Router::<Route> {}
}

View file

@ -16,8 +16,8 @@ fn main() {
fn app() -> Element {
// Breed is a signal that will be updated when the user clicks a breed in the list
// `deerhound` is just a default that we know will exist. We could also use a `None` instead
let mut breed = use_signal(|| "deerhound".to_string());
// `shiba` is just a default that we know will exist. We could also use a `None` instead
let mut breed = use_signal(|| "shiba".to_string());
// Fetch the list of breeds from the Dog API
// Since there are no dependencies, this will never restart
@ -55,7 +55,6 @@ fn app() -> Element {
};
rsx! {
style { {include_str!("./assets/dog_app.css")} }
h1 { "Select a dog breed!" }
div { height: "500px", display: "flex",
ul { width: "100px", {breed_list} }

View file

@ -7,6 +7,8 @@
use dioxus::desktop::{use_asset_handler, wry::http::Response};
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/custom_assets.css"));
fn main() {
launch_desktop(app);
}
@ -22,7 +24,7 @@ fn app() -> Element {
});
rsx! {
style { {include_str!("./assets/custom_assets.css")} }
link { rel: "stylesheet", href: STYLE }
h1 { "Dynamic Assets" }
img { src: "/logos/logo.png" }
}

View file

@ -8,6 +8,8 @@ use std::sync::Arc;
use dioxus::prelude::*;
use dioxus::{html::HasFileData, prelude::dioxus_elements::FileEngine};
const STYLE: &str = asset!(file("./examples/assets/file_upload.css"));
fn main() {
launch(app);
}
@ -41,7 +43,7 @@ fn app() -> Element {
};
rsx! {
style { {include_str!("./assets/file_upload.css")} }
link { rel: "stylesheet", href: STYLE }
h1 { "File Upload Example" }
p { "Drop a .txt, .rs, or .js file here to read it" }

View file

@ -9,10 +9,12 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/flat_router.css"));
fn main() {
launch(|| {
rsx! {
style { {include_str!("./assets/flat_router.css")} }
link { rel: "stylesheet", href: STYLE }
Router::<Route> {}
}
})

View file

@ -7,16 +7,18 @@
use dioxus::prelude::*;
fn main() {
launch(app);
}
const STYLE: &str = asset!(file("./examples/assets/counter.css"));
static COUNT: GlobalSignal<i32> = Signal::global(|| 0);
static DOUBLED_COUNT: GlobalMemo<i32> = Signal::global_memo(|| COUNT() * 2);
fn main() {
launch(app);
}
fn app() -> Element {
rsx! {
style { {include_str!("./assets/counter.css")} }
link { rel: "stylesheet", href: STYLE }
Increment {}
Decrement {}
Reset {}

View file

@ -8,13 +8,15 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/links.css"));
fn main() {
launch(app);
}
fn app() -> Element {
rsx! (
style { {include_str!("./assets/links.css")} }
link { rel: "stylesheet", href: STYLE }
Router::<Route> {}
)
}

View file

@ -7,6 +7,8 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/radio.css"));
fn main() {
launch(app);
}
@ -15,7 +17,7 @@ fn app() -> Element {
let mut state = use_signal(|| PlayerState { is_playing: false });
rsx!(
style { {include_str!("./assets/radio.css")} }
link { rel: "stylesheet", href: STYLE }
h1 {"Select an option"}
// Add some cute animations if the radio is playing!

View file

@ -8,10 +8,12 @@
use dioxus::prelude::*;
const STYLE: &str = asset!(file("./examples/assets/router.css"));
fn main() {
launch(|| {
rsx! {
style { {include_str!("./assets/router.css")} }
link { rel: "stylesheet", href: STYLE }
Router::<Route> {}
}
});

View file

@ -3,6 +3,8 @@
use dioxus::prelude::*;
use std::collections::HashMap;
const STYLE: &str = asset!(file("./examples/assets/todomvc.css"));
fn main() {
launch(app);
}
@ -63,7 +65,7 @@ fn app() -> Element {
};
rsx! {
style { {include_str!("./assets/todomvc.css")} }
link { rel: "stylesheet", href: STYLE }
section { class: "todoapp",
TodoHeader { todos }
section { class: "main",

View file

@ -135,21 +135,6 @@ name = "calculator_mutable"
path = "../../examples/calculator_mutable.rs"
doc-scrape-examples = true
[[example]]
name = "calculator"
path = "../../examples/calculator.rs"
doc-scrape-examples = true
[[example]]
name = "clock"
path = "../../examples/clock.rs"
doc-scrape-examples = true
[[example]]
name = "crm"
path = "../../examples/crm.rs"
doc-scrape-examples = true
[[example]]
name = "custom_html"
path = "../../examples/custom_html.rs"
@ -160,11 +145,6 @@ name = "custom_menu"
path = "../../examples/custom_menu.rs"
doc-scrape-examples = true
[[example]]
name = "dynamic_asset"
path = "../../examples/dynamic_asset.rs"
doc-scrape-examples = true
[[example]]
name = "errors"
path = "../../examples/errors.rs"

View file

@ -2,7 +2,12 @@ use crate::{assets::*, edits::EditQueue};
use dioxus_html::document::NATIVE_EVAL_JS;
use dioxus_interpreter_js::unified_bindings::SLEDGEHAMMER_JS;
use dioxus_interpreter_js::NATIVE_JS;
use std::path::{Component, Path, PathBuf};
use serde::Deserialize;
use std::{
path::{Component, Path, PathBuf},
process::Command,
sync::OnceLock,
};
use wry::{
http::{status::StatusCode, Request, Response},
RequestAsyncResponder, Result,
@ -108,8 +113,18 @@ fn assets_head() -> Option<String> {
fn resolve_resource(path: &Path) -> PathBuf {
let mut base_path = get_asset_root_or_default();
if running_in_dev_mode() {
base_path.push(path);
// Special handler for Manganis filesystem fallback.
// We need this since Manganis provides assets from workspace root.
if !base_path.exists() {
let workspace_root = get_workspace_root_from_cargo();
let asset_path = workspace_root.join(path);
println!("ASSET PATH: {:?}", asset_path);
return asset_path;
}
} else {
let mut resource_path = PathBuf::new();
for component in path.components() {
@ -305,3 +320,31 @@ fn get_mime_by_ext(trimmed: &Path) -> &'static str {
None => "application/octet-stream",
}
}
/// A global that stores the workspace root. Used in [`get_workspace_root_from_cargo`].
static WORKSPACE_ROOT: OnceLock<PathBuf> = OnceLock::new();
/// Describes the metadata we need from `cargo metadata`.
#[derive(Deserialize)]
struct CargoMetadata {
workspace_root: PathBuf,
}
/// Get the workspace root using `cargo metadata`. Should not be used in release mode.
pub(crate) fn get_workspace_root_from_cargo() -> PathBuf {
WORKSPACE_ROOT
.get_or_init(|| {
let out = Command::new("cargo")
.args(["metadata", "--format-version", "1", "--no-deps"])
.output()
.expect("`cargo metadata` failed to run");
let out =
String::from_utf8(out.stdout).expect("failed to parse output of `cargo metadata`");
let metadata = serde_json::from_str::<CargoMetadata>(&out)
.expect("failed to deserialize data from `cargo metadata`");
metadata.workspace_root
})
.to_owned()
}

View file

@ -24,7 +24,8 @@ dioxus-desktop = { workspace = true, default-features = true, optional = true }
dioxus-fullstack = { workspace = true, default-features = true, optional = true }
dioxus-static-site-generation = { workspace = true, optional = true }
dioxus-liveview = { workspace = true, optional = true }
dioxus-ssr ={ workspace = true, optional = true }
dioxus-ssr = { workspace = true, optional = true }
manganis = { workspace = true, optional = true }
serde = { version = "1.0.136", optional = true }
axum = { workspace = true, optional = true }
@ -33,7 +34,7 @@ axum = { workspace = true, optional = true }
dioxus-hot-reload = { workspace = true, optional = true }
[features]
default = ["macro", "html", "hot-reload", "signals", "hooks", "launch", "mounted", "file_engine", "document"]
default = ["macro", "html", "hot-reload", "signals", "hooks", "launch", "mounted", "file_engine", "document", "asset"]
minimal = ["macro", "html", "signals", "hooks", "launch"]
signals = ["dep:dioxus-signals"]
macro = ["dep:dioxus-core-macro"]
@ -42,6 +43,7 @@ hooks = ["dep:dioxus-hooks"]
hot-reload = ["dep:dioxus-hot-reload", "dioxus-web?/hot_reload", "dioxus-fullstack?/hot-reload"]
mounted = ["dioxus-web?/mounted", "dioxus-html?/mounted"]
file_engine = ["dioxus-web?/file_engine"]
asset = ["dep:manganis"]
document = ["dioxus-web?/document", "dioxus-html?/document"]
launch = ["dep:dioxus-config-macro"]

View file

@ -122,6 +122,10 @@ pub mod prelude {
#[cfg(feature = "axum")]
#[cfg_attr(docsrs, doc(cfg(feature = "axum")))]
pub use axum;
#[cfg(feature = "asset")]
#[cfg_attr(docsrs, doc(cfg(feature = "asset")))]
pub use manganis::{self, classes, mg as asset, ImageAsset, ImageType};
}
#[cfg(feature = "web")]

View file

@ -61,36 +61,17 @@ serde = { version = "1", features = ["derive"] }
[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
# Most of the examples live in the workspace. We include some here so that docs.rs can scrape our examples for better inline docs
[[example]]
name = "crm"
path = "../../examples/crm.rs"
doc-scrape-examples = true
[[example]]
name = "flat_router"
path = "../../examples/flat_router.rs"
doc-scrape-examples = true
[[example]]
name = "hash_fragment_state"
path = "../../examples/hash_fragment_state.rs"
doc-scrape-examples = true
[[example]]
name = "link"
path = "../../examples/link.rs"
doc-scrape-examples = true
[[example]]
name = "query_segment_search"
path = "../../examples/query_segment_search.rs"
doc-scrape-examples = true
[[example]]
name = "router"
path = "../../examples/router.rs"
doc-scrape-examples = true
[[example]]
name = "simple_router"
path = "../../examples/simple_router.rs"