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"]
|
html = ["dep:dioxus-html"]
|
||||||
hooks = ["dep:dioxus-hooks"]
|
hooks = ["dep:dioxus-hooks"]
|
||||||
devtools = ["dep:dioxus-devtools", "dioxus-web?/devtools", "dioxus-fullstack?/devtools"]
|
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"]
|
file_engine = ["dioxus-web?/file_engine"]
|
||||||
asset = ["dep:manganis"]
|
asset = ["dep:manganis"]
|
||||||
document = ["dioxus-web?/document", "dep:dioxus-document", "dep:dioxus-history"]
|
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"
|
euclid = "0.22.7"
|
||||||
enumset = "1.1.2"
|
enumset = "1.1.2"
|
||||||
keyboard-types = { version = "0.7", default-features = false }
|
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 }
|
tokio = { workspace = true, features = ["fs", "io-util"], optional = true }
|
||||||
futures-channel = { workspace = true }
|
futures-channel = { workspace = true }
|
||||||
serde_json = { version = "1", optional = true }
|
serde_json = { version = "1", optional = true }
|
||||||
@@ -41,7 +41,7 @@ tokio = { workspace = true, features = ["time"] }
|
|||||||
manganis = { workspace = true }
|
manganis = { workspace = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["serialize", "mounted", "file_engine"]
|
default = ["serialize"]
|
||||||
serialize = [
|
serialize = [
|
||||||
"dep:serde",
|
"dep:serde",
|
||||||
"dep:serde_json",
|
"dep:serde_json",
|
||||||
@@ -50,10 +50,10 @@ serialize = [
|
|||||||
"keyboard-types/serde",
|
"keyboard-types/serde",
|
||||||
"dioxus-core/serialize"
|
"dioxus-core/serialize"
|
||||||
]
|
]
|
||||||
|
# TODO: Remove the mounted feature flag in the next major release. It no longer activates any extra code
|
||||||
mounted = []
|
mounted = []
|
||||||
file_engine = [
|
# TODO: Remove the file engine feature flag in the next major release. It no longer activates any extra code
|
||||||
"dep:async-trait",
|
file_engine = []
|
||||||
]
|
|
||||||
hot-reload-context = ["dep:dioxus-rsx"]
|
hot-reload-context = ["dep:dioxus-rsx"]
|
||||||
html-to-rsx = []
|
html-to-rsx = []
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ impl DragData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl crate::HasFileData for DragData {
|
impl crate::HasFileData for DragData {
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
||||||
self.inner.files()
|
self.inner.files()
|
||||||
}
|
}
|
||||||
@@ -112,7 +111,6 @@ impl PointerInteraction for DragData {
|
|||||||
pub struct SerializedDragData {
|
pub struct SerializedDragData {
|
||||||
pub mouse: crate::point_interaction::SerializedPointInteraction,
|
pub mouse: crate::point_interaction::SerializedPointInteraction,
|
||||||
|
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
files: Option<crate::file_data::SerializedFileEngine>,
|
files: Option<crate::file_data::SerializedFileEngine>,
|
||||||
}
|
}
|
||||||
@@ -122,7 +120,6 @@ impl SerializedDragData {
|
|||||||
fn new(drag: &DragData) -> Self {
|
fn new(drag: &DragData) -> Self {
|
||||||
Self {
|
Self {
|
||||||
mouse: crate::point_interaction::SerializedPointInteraction::from(drag),
|
mouse: crate::point_interaction::SerializedPointInteraction::from(drag),
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
files: None,
|
files: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +134,6 @@ impl HasDragData for SerializedDragData {
|
|||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
impl crate::file_data::HasFileData for SerializedDragData {
|
impl crate::file_data::HasFileData for SerializedDragData {
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
||||||
self.files
|
self.files
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ impl FormData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the files of the form event
|
/// Get the files of the form event
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
pub fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
pub fn files(&self) -> Option<std::sync::Arc<dyn crate::file_data::FileEngine>> {
|
||||||
self.inner.files()
|
self.inner.files()
|
||||||
}
|
}
|
||||||
@@ -177,7 +176,6 @@ pub struct SerializedFormData {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
valid: bool,
|
valid: bool,
|
||||||
|
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
files: Option<crate::file_data::SerializedFileEngine>,
|
files: Option<crate::file_data::SerializedFileEngine>,
|
||||||
}
|
}
|
||||||
@@ -190,12 +188,10 @@ impl SerializedFormData {
|
|||||||
value,
|
value,
|
||||||
values,
|
values,
|
||||||
valid: true,
|
valid: true,
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
files: None,
|
files: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
/// Add files to the serialized form data object
|
/// Add files to the serialized form data object
|
||||||
pub fn with_files(mut self, files: crate::file_data::SerializedFileEngine) -> Self {
|
pub fn with_files(mut self, files: crate::file_data::SerializedFileEngine) -> Self {
|
||||||
self.files = Some(files);
|
self.files = Some(files);
|
||||||
@@ -208,7 +204,6 @@ impl SerializedFormData {
|
|||||||
value: data.value(),
|
value: data.value(),
|
||||||
values: data.values(),
|
values: data.values(),
|
||||||
valid: data.valid(),
|
valid: data.valid(),
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
files: {
|
files: {
|
||||||
match data.files() {
|
match data.files() {
|
||||||
Some(files) => {
|
Some(files) => {
|
||||||
@@ -234,7 +229,6 @@ impl SerializedFormData {
|
|||||||
value: data.value(),
|
value: data.value(),
|
||||||
values: data.values(),
|
values: data.values(),
|
||||||
valid: data.valid(),
|
valid: data.valid(),
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
files: None,
|
files: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +255,6 @@ impl HasFormData for SerializedFormData {
|
|||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
impl HasFileData for SerializedFormData {
|
impl HasFileData for SerializedFormData {
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
|
||||||
self.files
|
self.files
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -269,7 +262,6 @@ impl HasFileData for SerializedFormData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
impl HasFileData for FormData {
|
impl HasFileData for FormData {
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn crate::FileEngine>> {
|
||||||
self.inner.files()
|
self.inner.files()
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
pub trait HasFileData: std::any::Any {
|
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>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn FileEngine>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
/// A file engine that serializes files to bytes
|
/// A file engine that serializes files to bytes
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
|
||||||
pub struct SerializedFileEngine {
|
pub struct SerializedFileEngine {
|
||||||
@@ -17,7 +12,6 @@ pub struct SerializedFileEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl FileEngine for SerializedFileEngine {
|
impl FileEngine for SerializedFileEngine {
|
||||||
fn files(&self) -> Vec<String> {
|
fn files(&self) -> Vec<String> {
|
||||||
@@ -46,7 +40,6 @@ impl FileEngine for SerializedFileEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
pub trait FileEngine {
|
pub trait FileEngine {
|
||||||
// get a list of file names
|
// 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"] }
|
tokio-util = { version = "0.7.4", features = ["rt"] }
|
||||||
serde = { version = "1.0.151", features = ["derive"] }
|
serde = { version = "1.0.151", features = ["derive"] }
|
||||||
serde_json = "1.0.91"
|
serde_json = "1.0.91"
|
||||||
dioxus-html = { workspace = true, features = ["serialize", "mounted"] }
|
dioxus-html = { workspace = true, features = ["serialize"] }
|
||||||
dioxus-document = { workspace = true }
|
dioxus-document = { workspace = true }
|
||||||
dioxus-history = { workspace = true }
|
dioxus-history = { workspace = true }
|
||||||
rustc-hash = { workspace = true }
|
rustc-hash = { workspace = true }
|
||||||
|
|||||||
@@ -74,25 +74,31 @@ impl HasDragData for Synthetic<DragEvent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasFileData for Synthetic<DragEvent> {
|
impl HasFileData for Synthetic<DragEvent> {
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
||||||
use wasm_bindgen::JsCast;
|
#[cfg(feature = "file_engine")]
|
||||||
|
{
|
||||||
let files = self
|
use wasm_bindgen::JsCast;
|
||||||
.event
|
let files = self
|
||||||
.dyn_ref::<web_sys::DragEvent>()
|
.event
|
||||||
.and_then(|drag_event| {
|
.dyn_ref::<web_sys::DragEvent>()
|
||||||
drag_event.data_transfer().and_then(|dt| {
|
.and_then(|drag_event| {
|
||||||
dt.files().and_then(|files| {
|
drag_event.data_transfer().and_then(|dt| {
|
||||||
#[allow(clippy::arc_with_non_send_sync)]
|
dt.files().and_then(|files| {
|
||||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
#[allow(clippy::arc_with_non_send_sync)]
|
||||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
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;
|
use super::Synthetic;
|
||||||
|
|
||||||
impl HasFileData for Synthetic<web_sys::Event> {
|
impl HasFileData for Synthetic<web_sys::Event> {
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
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
|
let files = self
|
||||||
.event
|
.event
|
||||||
.dyn_ref()
|
.dyn_ref()
|
||||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||||
input.files().and_then(|files| {
|
input.files().and_then(|files| {
|
||||||
#[allow(clippy::arc_with_non_send_sync)]
|
#[allow(clippy::arc_with_non_send_sync)]
|
||||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
||||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
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 {
|
impl HasFileData for WebFormData {
|
||||||
#[cfg(feature = "file_engine")]
|
|
||||||
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
fn files(&self) -> Option<std::sync::Arc<dyn dioxus_html::FileEngine>> {
|
||||||
let files = self
|
#[cfg(feature = "file_engine")]
|
||||||
.element
|
{
|
||||||
.dyn_ref()
|
let files = self
|
||||||
.and_then(|input: &web_sys::HtmlInputElement| {
|
.element
|
||||||
input.files().and_then(|files| {
|
.dyn_ref()
|
||||||
#[allow(clippy::arc_with_non_send_sync)]
|
.and_then(|input: &web_sys::HtmlInputElement| {
|
||||||
crate::file_engine::WebFileEngine::new(files).map(|f| {
|
input.files().and_then(|files| {
|
||||||
std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>
|
#[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