remove the file engine feature in the html crate (#3392)
This commit is contained in:
1 parent
c2952a79f8
commit
aab1258f0e
9 files changed
+65
-66
No files matched your search
@@ -43,7 +43,7 @@ macro = ["dep:dioxus-core-macro"]
|
||||
html = ["dep:dioxus-html"]
|
||||
hooks = ["dep:dioxus-hooks"]
|
||||
devtools = ["dep:dioxus-devtools", "dioxus-web?/devtools", "dioxus-fullstack?/devtools"]
|
||||
mounted = ["dioxus-web?/mounted", "dioxus-html?/mounted"]
|
||||
mounted = ["dioxus-web?/mounted"]
|
||||
file_engine = ["dioxus-web?/file_engine"]
|
||||
asset = ["dep:manganis"]
|
||||
document = ["dioxus-web?/document", "dep:dioxus-document", "dep:dioxus-history"]
|
||||
|
||||
@@ -23,7 +23,7 @@ js-sys = { version = "0.3.56", optional = true }
|
||||
euclid = "0.22.7"
|
||||
enumset = "1.1.2"
|
||||
keyboard-types = { version = "0.7", default-features = false }
|
||||
async-trait = { version = "0.1.58", optional = true }
|
||||
async-trait = { version = "0.1.58" }
|
||||
tokio = { workspace = true, features = ["fs", "io-util"], optional = true }
|
||||
futures-channel = { workspace = true }
|
||||
serde_json = { version = "1", optional = true }
|
||||
@@ -41,7 +41,7 @@ tokio = { workspace = true, features = ["time"] }
|
||||
manganis = { workspace = true }
|
||||
|
||||
[features]
|
||||
default = ["serialize", "mounted", "file_engine"]
|
||||
default = ["serialize"]
|
||||
serialize = [
|
||||
"dep:serde",
|
||||
"dep:serde_json",
|
||||
@@ -50,10 +50,10 @@ serialize = [
|
||||
"keyboard-types/serde",
|
||||
"dioxus-core/serialize"
|
||||
]
|
||||
# TODO: Remove the mounted feature flag in the next major release. It no longer activates any extra code
|
||||
mounted = []
|
||||
file_engine = [
|
||||
"dep:async-trait",
|
||||
]
|
||||
# TODO: Remove the file engine feature flag in the next major release. It no longer activates any extra code
|
||||
file_engine = []
|
||||
hot-reload-context = ["dep:dioxus-rsx"]
|
||||
html-to-rsx = []
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ impl DragData {
|
||||
}
|
||||
|
||||
impl crate::HasFileData for DragData {
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
||||
self.inner.files()
|
||||
}
|
||||
@@ -112,7 +111,6 @@ impl PointerInteraction for DragData {
|
||||
pub struct SerializedDragData {
|
||||
pub mouse: crate::point_interaction::SerializedPointInteraction,
|
||||
|
||||
#[cfg(feature = "file_engine")]
|
||||
#[serde(default)]
|
||||
files: Option<crate::file_data::SerializedFileEngine>,
|
||||
}
|
||||
@@ -122,7 +120,6 @@ impl SerializedDragData {
|
||||
fn new(drag: &DragData) -> Self {
|
||||
Self {
|
||||
mouse: crate::point_interaction::SerializedPointInteraction::from(drag),
|
||||
#[cfg(feature = "file_engine")]
|
||||
files: None,
|
||||
}
|
||||
}
|
||||
@@ -137,7 +134,6 @@ impl HasDragData for SerializedDragData {
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl crate::file_data::HasFileData for SerializedDragData {
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
||||
self.files
|
||||
.as_ref()
|
||||
|
||||
@@ -105,7 +105,6 @@ impl FormData {
|
||||
}
|
||||
|
||||
/// Get the files of the form event
|
||||
#[cfg(feature = "file_engine")]
|
||||
pub fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
||||
self.inner.files()
|
||||
}
|
||||
@@ -177,7 +176,6 @@ pub struct SerializedFormData {
|
||||
#[serde(default)]
|
||||
valid: bool,
|
||||
|
||||
#[cfg(feature = "file_engine")]
|
||||
#[serde(default)]
|
||||
files: Option<crate::file_data::SerializedFileEngine>,
|
||||
}
|
||||
@@ -190,12 +188,10 @@ impl SerializedFormData {
|
||||
value,
|
||||
values,
|
||||
valid: true,
|
||||
#[cfg(feature = "file_engine")]
|
||||
files: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "file_engine")]
|
||||
/// Add files to the serialized form data object
|
||||
pub fn with_files(mut self, files: crate::file_data::SerializedFileEngine) -> Self {
|
||||
self.files = Some(files);
|
||||
@@ -208,7 +204,6 @@ impl SerializedFormData {
|
||||
value: data.value(),
|
||||
values: data.values(),
|
||||
valid: data.valid(),
|
||||
#[cfg(feature = "file_engine")]
|
||||
files: {
|
||||
match data.files() {
|
||||
Some(files) => {
|
||||
@@ -234,7 +229,6 @@ impl SerializedFormData {
|
||||
value: data.value(),
|
||||
values: data.values(),
|
||||
valid: data.valid(),
|
||||
#[cfg(feature = "file_engine")]
|
||||
files: None,
|
||||
}
|
||||
}
|
||||
@@ -261,7 +255,6 @@ impl HasFormData for SerializedFormData {
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl HasFileData for SerializedFormData {
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
|
||||
self.files
|
||||
.as_ref()
|
||||
@@ -269,7 +262,6 @@ impl HasFileData for SerializedFormData {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "file_engine")]
|
||||
impl HasFileData for FormData {
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
|
||||
self.inner.files()
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
pub trait HasFileData: std::any::Any {
|
||||
// NOTE: The methods of this trait are config'ed out instead of the trait
|
||||
// itself because several other traits inherit from this trait and there isn't a clean way to
|
||||
// conditionally inherit from a trait based on a config.
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn FileEngine>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "file_engine")]
|
||||
/// A file engine that serializes files to bytes
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct SerializedFileEngine {
|
||||
@@ -17,7 +12,6 @@ pub struct SerializedFileEngine {
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
#[cfg(feature = "file_engine")]
|
||||
#[async_trait::async_trait(?Send)]
|
||||
impl FileEngine for SerializedFileEngine {
|
||||
fn files(&self) -> Vec<String> {
|
||||
@@ -46,7 +40,6 @@ impl FileEngine for SerializedFileEngine {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "file_engine")]
|
||||
#[async_trait::async_trait(?Send)]
|
||||
pub trait FileEngine {
|
||||
// get a list of file names
|
||||
|
||||
@@ -22,7 +22,7 @@ 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 = { workspace = true, features = ["serialize", "mounted"] }
|
||||
dioxus-html = { workspace = true, features = ["serialize"] }
|
||||
dioxus-document = { workspace = true }
|
||||
dioxus-history = { workspace = true }
|
||||
rustc-hash = { workspace = true }
|
||||
|
||||
@@ -74,25 +74,31 @@ impl HasDragData for Synthetic<DragEvent> {
|
||||
}
|
||||
|
||||
impl HasFileData for Synthetic<DragEvent> {
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
let files = self
|
||||
.event
|
||||
.dyn_ref::<web_sys::DragEvent>()
|
||||
.and_then(|drag_event| {
|
||||
drag_event.data_transfer().and_then(|dt| {
|
||||
dt.files().and_then(|files| {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
||||
#[cfg(feature = "file_engine")]
|
||||
{
|
||||
use wasm_bindgen::JsCast;
|
||||
let files = self
|
||||
.event
|
||||
.dyn_ref::<web_sys::DragEvent>()
|
||||
.and_then(|drag_event| {
|
||||
drag_event.data_transfer().and_then(|dt| {
|
||||
dt.files().and_then(|files| {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||
std::sync::Arc::new(f)
|
||||
as std::sync::Arc<dyn dioxus_html::FileEngine>
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
files
|
||||
files
|
||||
}
|
||||
#[cfg(not(feature = "file_engine"))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,22 +3,28 @@ use dioxus_html::HasFileData;
|
||||
use super::Synthetic;
|
||||
|
||||
impl HasFileData for Synthetic<web_sys::Event> {
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
||||
use wasm_bindgen::JsCast;
|
||||
#[cfg(feature = "file_engine")]
|
||||
{
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
let files = self
|
||||
.event
|
||||
.dyn_ref()
|
||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||
input.files().and_then(|files| {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
||||
let files = self
|
||||
.event
|
||||
.dyn_ref()
|
||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||
input.files().and_then(|files| {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
files
|
||||
files
|
||||
}
|
||||
#[cfg(not(feature = "file_engine"))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,21 +106,27 @@ impl HasFormData for WebFormData {
|
||||
}
|
||||
|
||||
impl HasFileData for WebFormData {
|
||||
#[cfg(feature = "file_engine")]
|
||||
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
||||
let files = self
|
||||
.element
|
||||
.dyn_ref()
|
||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||
input.files().and_then(|files| {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
||||
#[cfg(feature = "file_engine")]
|
||||
{
|
||||
let files = self
|
||||
.element
|
||||
.dyn_ref()
|
||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||
input.files().and_then(|files| {
|
||||
#[allow(clippy::arc_with_non_send_sync)]
|
||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
files
|
||||
files
|
||||
}
|
||||
#[cfg(not(feature = "file_engine"))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user