Fix: Windows File Drag-N-Drop (#3046)
* fix: windows file drop * update: tokio + fix eval
This commit is contained in:
1 parent
519ec9d294
commit
0995b5d2c5
17 files changed
+143
-20
No files matched your search
Generated
+2
-2
@@ -11007,9 +11007,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.39.2"
|
version = "1.40.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1"
|
checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|||||||
+3
-3
@@ -115,7 +115,7 @@ askama_escape = "0.10.3"
|
|||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-futures = "0.2.5"
|
tracing-futures = "0.2.5"
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
tokio = "1.28"
|
tokio = "1.40"
|
||||||
slab = "0.4.2"
|
slab = "0.4.2"
|
||||||
slotmap = { version = "1.0.7", features = ["serde"] }
|
slotmap = { version = "1.0.7", features = ["serde"] }
|
||||||
futures-channel = "0.3.21"
|
futures-channel = "0.3.21"
|
||||||
@@ -243,7 +243,7 @@ web-time = "1.1.0"
|
|||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||||
getrandom = { version = "0.2.12", features = ["js"] }
|
getrandom = { version = "0.2.12", features = ["js"] }
|
||||||
tokio = { version = "1.16.1", default-features = false, features = [
|
tokio = { version = "1.40", default-features = false, features = [
|
||||||
"sync",
|
"sync",
|
||||||
"macros",
|
"macros",
|
||||||
"io-util",
|
"io-util",
|
||||||
@@ -252,7 +252,7 @@ tokio = { version = "1.16.1", default-features = false, features = [
|
|||||||
] }
|
] }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
|
||||||
tokio = { version = "1.16.1", features = ["full"] }
|
tokio = { version = "1.40", features = ["full"] }
|
||||||
|
|
||||||
# To make most examples faster to compile, we split out assets and http-related stuff
|
# To make most examples faster to compile, we split out assets and http-related stuff
|
||||||
# This trims off like 270 dependencies, leading to a significant speedup in compilation time
|
# This trims off like 270 dependencies, leading to a significant speedup in compilation time
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.52"
|
anyhow = "1.0.52"
|
||||||
pretty_env_logger = "0.5.0"
|
pretty_env_logger = "0.5.0"
|
||||||
tokio = { version = "1.12.0", features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
dioxus = { workspace = true, features = ["desktop"] }
|
dioxus = { workspace = true, features = ["desktop"] }
|
||||||
wifiscanner = "0.5.1"
|
wifiscanner = "0.5.1"
|
||||||
futures-channel = "0.3.19"
|
futures-channel = "0.3.19"
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ futures-util = { workspace = true, features = ["async-await-macro"] }
|
|||||||
notify = { workspace = true, features = ["serde"] }
|
notify = { workspace = true, features = ["serde"] }
|
||||||
html_parser = { workspace = true }
|
html_parser = { workspace = true }
|
||||||
cargo_metadata = "0.18.1"
|
cargo_metadata = "0.18.1"
|
||||||
tokio = { version = "1.16.1", features = ["fs", "sync", "rt", "macros", "process", "rt-multi-thread"] }
|
tokio = { workspace = true, features = ["fs", "sync", "rt", "macros", "process", "rt-multi-thread"] }
|
||||||
tokio-stream = "0.1.15"
|
tokio-stream = "0.1.15"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ tokio = { workspace = true, features = [
|
|||||||
"time",
|
"time",
|
||||||
"macros",
|
"macros",
|
||||||
"fs",
|
"fs",
|
||||||
|
"io-util",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
webbrowser = "0.8.0"
|
webbrowser = "0.8.0"
|
||||||
infer = "0.11.0"
|
infer = "0.11.0"
|
||||||
|
|||||||
@@ -308,11 +308,13 @@ impl App {
|
|||||||
let view = self.webviews.get_mut(&window).unwrap();
|
let view = self.webviews.get_mut(&window).unwrap();
|
||||||
|
|
||||||
let event = dioxus_core::Event::new(data as Rc<dyn Any>, event_bubbles);
|
let event = dioxus_core::Event::new(data as Rc<dyn Any>, event_bubbles);
|
||||||
|
|
||||||
|
let runtime = view.dom.runtime();
|
||||||
if event_name == "change&input" {
|
if event_name == "change&input" {
|
||||||
view.dom.runtime().handle_event("input", event.clone(), id);
|
runtime.handle_event("input", event.clone(), id);
|
||||||
view.dom.runtime().handle_event("change", event, id);
|
runtime.handle_event("change", event, id);
|
||||||
} else {
|
} else {
|
||||||
view.dom.runtime().handle_event(event_name, event, id);
|
runtime.handle_event(event_name, event, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,20 @@ pub enum UserWindowEvent {
|
|||||||
Poll(WindowId),
|
Poll(WindowId),
|
||||||
|
|
||||||
/// Handle an ipc message eminating from the window.postMessage of a given webview
|
/// Handle an ipc message eminating from the window.postMessage of a given webview
|
||||||
Ipc { id: WindowId, msg: IpcMessage },
|
Ipc {
|
||||||
|
id: WindowId,
|
||||||
|
msg: IpcMessage,
|
||||||
|
},
|
||||||
|
|
||||||
/// Handle a hotreload event, basically telling us to update our templates
|
/// Handle a hotreload event, basically telling us to update our templates
|
||||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||||
HotReloadEvent(dioxus_devtools::DevserverMsg),
|
HotReloadEvent(dioxus_devtools::DevserverMsg),
|
||||||
|
|
||||||
|
// Windows-only drag-n-drop fix events.
|
||||||
|
WindowsDragDrop(WindowId),
|
||||||
|
WindowsDragOver(WindowId, i32, i32),
|
||||||
|
WindowsDragLeave(WindowId),
|
||||||
|
|
||||||
/// Create a new window
|
/// Create a new window
|
||||||
NewWindow,
|
NewWindow,
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::{
|
|||||||
ipc::{IpcMethod, UserWindowEvent},
|
ipc::{IpcMethod, UserWindowEvent},
|
||||||
};
|
};
|
||||||
use dioxus_core::*;
|
use dioxus_core::*;
|
||||||
|
use dioxus_document::eval;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use tao::event::{Event, StartCause, WindowEvent};
|
use tao::event::{Event, StartCause, WindowEvent};
|
||||||
|
|
||||||
@@ -44,6 +45,44 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, desktop_config: Conf
|
|||||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||||
UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg),
|
UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg),
|
||||||
|
|
||||||
|
// Windows-only drag-n-drop fix events. We need to call the interpreter drag-n-drop code.
|
||||||
|
UserWindowEvent::WindowsDragDrop(id) => {
|
||||||
|
if let Some(webview) = app.webviews.get(&id) {
|
||||||
|
webview.dom.in_runtime(|| {
|
||||||
|
ScopeId::ROOT.in_runtime(|| {
|
||||||
|
eval("window.interpreter.handleWindowsDragDrop();");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserWindowEvent::WindowsDragLeave(id) => {
|
||||||
|
if let Some(webview) = app.webviews.get(&id) {
|
||||||
|
webview.dom.in_runtime(|| {
|
||||||
|
ScopeId::ROOT.in_runtime(|| {
|
||||||
|
eval("window.interpreter.handleWindowsDragLeave();");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserWindowEvent::WindowsDragOver(id, x_pos, y_pos) => {
|
||||||
|
if let Some(webview) = app.webviews.get(&id) {
|
||||||
|
webview.dom.in_runtime(|| {
|
||||||
|
ScopeId::ROOT.in_runtime(|| {
|
||||||
|
let e = eval(
|
||||||
|
r#"
|
||||||
|
const xPos = await dioxus.recv();
|
||||||
|
const yPos = await dioxus.recv();
|
||||||
|
window.interpreter.handleWindowsDragOver(xPos, yPos)
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
_ = e.send(x_pos);
|
||||||
|
_ = e.send(y_pos);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UserWindowEvent::Ipc { id, msg } => match msg.method() {
|
UserWindowEvent::Ipc { id, msg } => match msg.method() {
|
||||||
IpcMethod::Initialize => app.handle_initialize_msg(id),
|
IpcMethod::Initialize => app.handle_initialize_msg(id),
|
||||||
IpcMethod::FileDialog => app.handle_file_dialog_msg(msg, id),
|
IpcMethod::FileDialog => app.handle_file_dialog_msg(msg, id),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ use futures_util::{pin_mut, FutureExt};
|
|||||||
use std::cell::OnceCell;
|
use std::cell::OnceCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{rc::Rc, task::Waker};
|
use std::{rc::Rc, task::Waker};
|
||||||
use wry::{RequestAsyncResponder, WebContext, WebViewBuilder};
|
use wry::{DragDropEvent, RequestAsyncResponder, WebContext, WebViewBuilder};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct WebviewEdits {
|
pub(crate) struct WebviewEdits {
|
||||||
@@ -236,10 +236,42 @@ impl WebviewInstance {
|
|||||||
|
|
||||||
let file_drop_handler = {
|
let file_drop_handler = {
|
||||||
to_owned![file_hover];
|
to_owned![file_hover];
|
||||||
move |evt| {
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
let (proxy, window_id) = (shared.proxy.to_owned(), window.id());
|
||||||
|
|
||||||
|
move |evt: DragDropEvent| {
|
||||||
// Update the most recent file drop event - when the event comes in from the webview we can use the
|
// Update the most recent file drop event - when the event comes in from the webview we can use the
|
||||||
// most recent event to build a new event with the files in it.
|
// most recent event to build a new event with the files in it.
|
||||||
|
#[cfg(not(windows))]
|
||||||
file_hover.set(evt);
|
file_hover.set(evt);
|
||||||
|
|
||||||
|
// Windows webview blocks HTML-native events when the drop handler is provided.
|
||||||
|
// The problem is that the HTML-native events don't provide the file, so we need this.
|
||||||
|
// Solution: this glue code to mimic drag drop events.
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
file_hover.set(evt.clone());
|
||||||
|
|
||||||
|
match evt {
|
||||||
|
wry::DragDropEvent::Drop {
|
||||||
|
paths: _,
|
||||||
|
position: _,
|
||||||
|
} => {
|
||||||
|
_ = proxy.send_event(UserWindowEvent::WindowsDragDrop(window_id));
|
||||||
|
}
|
||||||
|
wry::DragDropEvent::Over { position } => {
|
||||||
|
_ = proxy.send_event(UserWindowEvent::WindowsDragOver(
|
||||||
|
window_id, position.0, position.1,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
wry::DragDropEvent::Leave => {
|
||||||
|
_ = proxy.send_event(UserWindowEvent::WindowsDragLeave(window_id));
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ futures-util = { workspace = true, default-features = false }
|
|||||||
dioxus-core = { workspace = true }
|
dioxus-core = { workspace = true }
|
||||||
dioxus = { workspace = true }
|
dioxus = { workspace = true }
|
||||||
web-sys = { version = "0.3.64", features = ["Document", "Window", "Element"] }
|
web-sys = { version = "0.3.64", features = ["Document", "Window", "Element"] }
|
||||||
tokio = { version = "1.0", features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
function setAttributeInner(node,field,value,ns){if(ns==="style"){node.style.setProperty(field,value);return}if(ns){node.setAttributeNS(ns,field,value);return}switch(field){case"value":if(node.value!==value)node.value=value;break;case"initial_value":node.defaultValue=value;break;case"checked":node.checked=truthy(value);break;case"initial_checked":node.defaultChecked=truthy(value);break;case"selected":node.selected=truthy(value);break;case"initial_selected":node.defaultSelected=truthy(value);break;case"dangerous_inner_html":node.innerHTML=value;break;default:if(!truthy(value)&&isBoolAttr(field))node.removeAttribute(field);else node.setAttribute(field,value)}}function truthy(val){return val==="true"||val===!0}function isBoolAttr(field){switch(field){case"allowfullscreen":case"allowpaymentrequest":case"async":case"autofocus":case"autoplay":case"checked":case"controls":case"default":case"defer":case"disabled":case"formnovalidate":case"hidden":case"ismap":case"itemscope":case"loop":case"multiple":case"muted":case"nomodule":case"novalidate":case"open":case"playsinline":case"readonly":case"required":case"reversed":case"selected":case"truespeed":case"webkitdirectory":return!0;default:return!1}}function retrieveFormValues(form){const formData=new FormData(form),contents={};return formData.forEach((value,key)=>{if(contents[key])contents[key].push(value);else contents[key]=[value]}),{valid:form.checkValidity(),values:contents}}export{setAttributeInner,retrieveFormValues};
|
function setAttributeInner(node,field,value,ns){if(ns==="style"){node.style.setProperty(field,value);return}if(ns){node.setAttributeNS(ns,field,value);return}switch(field){case"value":if(node.value!==value)node.value=value;break;case"initial_value":node.defaultValue=value;break;case"checked":node.checked=truthy(value);break;case"initial_checked":node.defaultChecked=truthy(value);break;case"selected":node.selected=truthy(value);break;case"initial_selected":node.defaultSelected=truthy(value);break;case"dangerous_inner_html":node.innerHTML=value;break;default:if(!truthy(value)&&isBoolAttr(field))node.removeAttribute(field);else node.setAttribute(field,value)}}var truthy=function(val){return val==="true"||val===!0},isBoolAttr=function(field){switch(field){case"allowfullscreen":case"allowpaymentrequest":case"async":case"autofocus":case"autoplay":case"checked":case"controls":case"default":case"defer":case"disabled":case"formnovalidate":case"hidden":case"ismap":case"itemscope":case"loop":case"multiple":case"muted":case"nomodule":case"novalidate":case"open":case"playsinline":case"readonly":case"required":case"reversed":case"selected":case"truespeed":case"webkitdirectory":return!0;default:return!1}};function retrieveFormValues(form){const formData=new FormData(form),contents={};return formData.forEach((value,key)=>{if(contents[key])contents[key].push(value);else contents[key]=[value]}),{valid:form.checkValidity(),values:contents}}export{setAttributeInner,retrieveFormValues};
|
||||||
@@ -1 +1 @@
|
|||||||
function setAttributeInner(node,field,value,ns){if(ns==="style"){node.style.setProperty(field,value);return}if(ns){node.setAttributeNS(ns,field,value);return}switch(field){case"value":if(node.value!==value)node.value=value;break;case"initial_value":node.defaultValue=value;break;case"checked":node.checked=truthy(value);break;case"initial_checked":node.defaultChecked=truthy(value);break;case"selected":node.selected=truthy(value);break;case"initial_selected":node.defaultSelected=truthy(value);break;case"dangerous_inner_html":node.innerHTML=value;break;default:if(!truthy(value)&&isBoolAttr(field))node.removeAttribute(field);else node.setAttribute(field,value)}}function truthy(val){return val==="true"||val===!0}function isBoolAttr(field){switch(field){case"allowfullscreen":case"allowpaymentrequest":case"async":case"autofocus":case"autoplay":case"checked":case"controls":case"default":case"defer":case"disabled":case"formnovalidate":case"hidden":case"ismap":case"itemscope":case"loop":case"multiple":case"muted":case"nomodule":case"novalidate":case"open":case"playsinline":case"readonly":case"required":case"reversed":case"selected":case"truespeed":case"webkitdirectory":return!0;default:return!1}}class BaseInterpreter{global;local;root;handler;resizeObserver;nodes;stack;templates;m;constructor(){}initialize(root,handler=null){this.global={},this.local={},this.root=root,this.nodes=[root],this.stack=[root],this.templates={},this.handler=handler}handleResizeEvent(entry){const target=entry.target;let event=new CustomEvent("resize",{bubbles:!1,detail:entry});target.dispatchEvent(event)}createObserver(element){if(!this.resizeObserver)this.resizeObserver=new ResizeObserver((entries)=>{for(let entry of entries)this.handleResizeEvent(entry)});this.resizeObserver.observe(element)}removeObserver(element){if(this.resizeObserver)this.resizeObserver.unobserve(element)}createListener(event_name,element,bubbles){if(bubbles)if(this.global[event_name]===void 0)this.global[event_name]={active:1,callback:this.handler},this.root.addEventListener(event_name,this.handler);else this.global[event_name].active++;else{const id=element.getAttribute("data-dioxus-id");if(!this.local[id])this.local[id]={};element.addEventListener(event_name,this.handler)}if(event_name=="resize")this.createObserver(element)}removeListener(element,event_name,bubbles){if(bubbles)this.removeBubblingListener(event_name);else this.removeNonBubblingListener(element,event_name)}removeBubblingListener(event_name){if(this.global[event_name].active--,this.global[event_name].active===0)this.root.removeEventListener(event_name,this.global[event_name].callback),delete this.global[event_name]}removeNonBubblingListener(element,event_name){const id=element.getAttribute("data-dioxus-id");if(delete this.local[id][event_name],Object.keys(this.local[id]).length===0)delete this.local[id];element.removeEventListener(event_name,this.handler)}removeAllNonBubblingListeners(element){const id=element.getAttribute("data-dioxus-id");delete this.local[id]}getNode(id){return this.nodes[id]}pushRoot(node){this.stack.push(node)}appendChildren(id,many){const root=this.nodes[id],els=this.stack.splice(this.stack.length-many);for(let k=0;k<many;k++)root.appendChild(els[k])}loadChild(ptr,len){let node=this.stack[this.stack.length-1],ptr_end=ptr+len;for(;ptr<ptr_end;ptr++){let end=this.m.getUint8(ptr);for(node=node.firstChild;end>0;end--)node=node.nextSibling}return node}saveTemplate(nodes,tmpl_id){this.templates[tmpl_id]=nodes}hydrate_node(hydrateNode,ids){const split=hydrateNode.getAttribute("data-node-hydration").split(","),id=ids[parseInt(split[0])];if(this.nodes[id]=hydrateNode,split.length>1){hydrateNode.listening=split.length-1,hydrateNode.setAttribute("data-dioxus-id",id.toString());for(let j=1;j<split.length;j++){const split2=split[j].split(":"),event_name=split2[0],bubbles=split2[1]==="1";this.createListener(event_name,hydrateNode,bubbles)}}}hydrate(ids,underNodes){for(let i=0;i<underNodes.length;i++){const under=underNodes[i];if(under instanceof HTMLElement){if(under.getAttribute("data-node-hydration"))this.hydrate_node(under,ids);const hydrateNodes=under.querySelectorAll("[data-node-hydration]");for(let i2=0;i2<hydrateNodes.length;i2++)this.hydrate_node(hydrateNodes[i2],ids)}const treeWalker=document.createTreeWalker(under,NodeFilter.SHOW_COMMENT);while(treeWalker.currentNode){const currentNode=treeWalker.currentNode;if(currentNode.nodeType===Node.COMMENT_NODE){const id=currentNode.textContent,placeholderSplit=id.split("placeholder");if(placeholderSplit.length>1){if(this.nodes[ids[parseInt(placeholderSplit[1])]]=currentNode,!treeWalker.nextNode())break;continue}const textNodeSplit=id.split("node-id");if(textNodeSplit.length>1){let next=currentNode.nextSibling;currentNode.remove();let commentAfterText,textNode;if(next.nodeType===Node.COMMENT_NODE){const newText=next.parentElement.insertBefore(document.createTextNode(""),next);commentAfterText=next,textNode=newText}else textNode=next,commentAftLine truncated
|
function setAttributeInner(node,field,value,ns){if(ns==="style"){node.style.setProperty(field,value);return}if(ns){node.setAttributeNS(ns,field,value);return}switch(field){case"value":if(node.value!==value)node.value=value;break;case"initial_value":node.defaultValue=value;break;case"checked":node.checked=truthy(value);break;case"initial_checked":node.defaultChecked=truthy(value);break;case"selected":node.selected=truthy(value);break;case"initial_selected":node.defaultSelected=truthy(value);break;case"dangerous_inner_html":node.innerHTML=value;break;default:if(!truthy(value)&&isBoolAttr(field))node.removeAttribute(field);else node.setAttribute(field,value)}}var truthy=function(val){return val==="true"||val===!0},isBoolAttr=function(field){switch(field){case"allowfullscreen":case"allowpaymentrequest":case"async":case"autofocus":case"autoplay":case"checked":case"controls":case"default":case"defer":case"disabled":case"formnovalidate":case"hidden":case"ismap":case"itemscope":case"loop":case"multiple":case"muted":case"nomodule":case"novalidate":case"open":case"playsinline":case"readonly":case"required":case"reversed":case"selected":case"truespeed":case"webkitdirectory":return!0;default:return!1}};class BaseInterpreter{global;local;root;handler;resizeObserver;nodes;stack;templates;m;constructor(){}initialize(root,handler=null){this.global={},this.local={},this.root=root,this.nodes=[root],this.stack=[root],this.templates={},this.handler=handler}handleResizeEvent(entry){const target=entry.target;let event=new CustomEvent("resize",{bubbles:!1,detail:entry});target.dispatchEvent(event)}createObserver(element){if(!this.resizeObserver)this.resizeObserver=new ResizeObserver((entries)=>{for(let entry of entries)this.handleResizeEvent(entry)});this.resizeObserver.observe(element)}removeObserver(element){if(this.resizeObserver)this.resizeObserver.unobserve(element)}createListener(event_name,element,bubbles){if(bubbles)if(this.global[event_name]===void 0)this.global[event_name]={active:1,callback:this.handler},this.root.addEventListener(event_name,this.handler);else this.global[event_name].active++;else{const id=element.getAttribute("data-dioxus-id");if(!this.local[id])this.local[id]={};element.addEventListener(event_name,this.handler)}if(event_name=="resize")this.createObserver(element)}removeListener(element,event_name,bubbles){if(bubbles)this.removeBubblingListener(event_name);else this.removeNonBubblingListener(element,event_name)}removeBubblingListener(event_name){if(this.global[event_name].active--,this.global[event_name].active===0)this.root.removeEventListener(event_name,this.global[event_name].callback),delete this.global[event_name]}removeNonBubblingListener(element,event_name){const id=element.getAttribute("data-dioxus-id");if(delete this.local[id][event_name],Object.keys(this.local[id]).length===0)delete this.local[id];element.removeEventListener(event_name,this.handler)}removeAllNonBubblingListeners(element){const id=element.getAttribute("data-dioxus-id");delete this.local[id]}getNode(id){return this.nodes[id]}pushRoot(node){this.stack.push(node)}appendChildren(id,many){const root=this.nodes[id],els=this.stack.splice(this.stack.length-many);for(let k=0;k<many;k++)root.appendChild(els[k])}loadChild(ptr,len){let node=this.stack[this.stack.length-1],ptr_end=ptr+len;for(;ptr<ptr_end;ptr++){let end=this.m.getUint8(ptr);for(node=node.firstChild;end>0;end--)node=node.nextSibling}return node}saveTemplate(nodes,tmpl_id){this.templates[tmpl_id]=nodes}hydrate_node(hydrateNode,ids){const split=hydrateNode.getAttribute("data-node-hydration").split(","),id=ids[parseInt(split[0])];if(this.nodes[id]=hydrateNode,split.length>1){hydrateNode.listening=split.length-1,hydrateNode.setAttribute("data-dioxus-id",id.toString());for(let j=1;j<split.length;j++){const split2=split[j].split(":"),event_name=split2[0],bubbles=split2[1]==="1";this.createListener(event_name,hydrateNode,bubbles)}}}hydrate(ids,underNodes){for(let i=0;i<underNodes.length;i++){const under=underNodes[i];if(under instanceof HTMLElement){if(under.getAttribute("data-node-hydration"))this.hydrate_node(under,ids);const hydrateNodes=under.querySelectorAll("[data-node-hydration]");for(let i2=0;i2<hydrateNodes.length;i2++)this.hydrate_node(hydrateNodes[i2],ids)}const treeWalker=document.createTreeWalker(under,NodeFilter.SHOW_COMMENT);while(treeWalker.currentNode){const currentNode=treeWalker.currentNode;if(currentNode.nodeType===Node.COMMENT_NODE){const id=currentNode.textContent,placeholderSplit=id.split("placeholder");if(placeholderSplit.length>1){if(this.nodes[ids[parseInt(placeholderSplit[1])]]=currentNode,!treeWalker.nextNode())break;continue}const textNodeSplit=id.split("node-id");if(textNodeSplit.length>1){let next=currentNode.nextSibling;currentNode.remove();let commentAfterText,textNode;if(next.nodeType===Node.COMMENT_NODE){const newText=next.parentElement.insertBefore(document.createTextNode(""),next);commentAfterText=next,textNode=newText}else textNode=next,commLine truncated
|
||||||
@@ -1 +1 @@
|
|||||||
[6449103750905854967, 4461869229701639737, 13069001215487072322, 8716623267269178440, 5336385715226370016, 14456089431355876478, 11703635120274352436, 5052021921702764563, 17534315583914394253, 5638004933879392817]
|
[6449103750905854967, 4461869229701639737, 13069001215487072322, 8716623267269178440, 5336385715226370016, 14456089431355876478, 16535067064964671079, 5052021921702764563, 17534315583914394253, 5638004933879392817]
|
||||||
@@ -1 +1 @@
|
|||||||
function retrieveValues(event,target){let contents={values:{}},form=target.closest("form");if(form){if(event.type==="input"||event.type==="change"||event.type==="submit"||event.type==="reset"||event.type==="click")contents=retrieveFormValues(form)}return contents}function retrieveFormValues(form){const formData=new FormData(form),contents={};return formData.forEach((value,key)=>{if(contents[key])contents[key].push(value);else contents[key]=[value]}),{valid:form.checkValidity(),values:contents}}function retrieveSelectValue(target){let options=target.selectedOptions,values=[];for(let i=0;i<options.length;i++)values.push(options[i].value);return values}function serializeEvent(event,target){let contents={},extend=(obj)=>contents={...contents,...obj};if(event instanceof WheelEvent)extend(serializeWheelEvent(event));if(event instanceof MouseEvent)extend(serializeMouseEvent(event));if(event instanceof KeyboardEvent)extend(serializeKeyboardEvent(event));if(event instanceof InputEvent)extend(serializeInputEvent(event,target));if(event instanceof PointerEvent)extend(serializePointerEvent(event));if(event instanceof AnimationEvent)extend(serializeAnimationEvent(event));if(event instanceof TransitionEvent)extend({property_name:event.propertyName,elapsed_time:event.elapsedTime,pseudo_element:event.pseudoElement});if(event instanceof CompositionEvent)extend({data:event.data});if(event instanceof DragEvent)extend(serializeDragEvent(event));if(event instanceof FocusEvent)extend({});if(event instanceof ClipboardEvent)extend({});if(event instanceof CustomEvent){const detail=event.detail;if(detail instanceof ResizeObserverEntry)extend(serializeResizeEventDetail(detail))}if(typeof TouchEvent!=="undefined"&&event instanceof TouchEvent)extend(serializeTouchEvent(event));if(event.type==="submit"||event.type==="reset"||event.type==="click"||event.type==="change"||event.type==="input")extend(serializeInputEvent(event,target));if(event instanceof DragEvent);return contents}function toSerializableResizeObserverSize(size,is_inline_width){return[is_inline_width?size.inlineSize:size.blockSize,is_inline_width?size.blockSize:size.inlineSize]}function serializeResizeEventDetail(detail){let is_inline_width=!0;if(detail.target instanceof HTMLElement){if(window.getComputedStyle(detail.target).getPropertyValue("writing-mode")!=="horizontal-tb")is_inline_width=!1}return{border_box_size:detail.borderBoxSize!==void 0?toSerializableResizeObserverSize(detail.borderBoxSize[0],is_inline_width):detail.contentRect,content_box_size:detail.contentBoxSize!==void 0?toSerializableResizeObserverSize(detail.contentBoxSize[0],is_inline_width):detail.contentRect,content_rect:detail.contentRect}}function serializeInputEvent(event,target){let contents={};if(target instanceof HTMLElement){let values=retrieveValues(event,target);contents.values=values.values,contents.valid=values.valid}if(event.target instanceof HTMLInputElement){let target2=event.target,value=target2.value??target2.textContent??"";if(target2.type==="checkbox")value=target2.checked?"true":"false";else if(target2.type==="radio")value=target2.value;contents.value=value}if(event.target instanceof HTMLTextAreaElement)contents.value=event.target.value;if(event.target instanceof HTMLSelectElement)contents.value=retrieveSelectValue(event.target).join(",");if(contents.value===void 0)contents.value="";return contents}function serializeWheelEvent(event){return{delta_x:event.deltaX,delta_y:event.deltaY,delta_z:event.deltaZ,delta_mode:event.deltaMode}}function serializeTouchEvent(event){return{alt_key:event.altKey,ctrl_key:event.ctrlKey,meta_key:event.metaKey,shift_key:event.shiftKey,changed_touches:event.changedTouches,target_touches:event.targetTouches,touches:event.touches}}function serializePointerEvent(event){return{alt_key:event.altKey,button:event.button,buttons:event.buttons,client_x:event.clientX,client_y:event.clientY,ctrl_key:event.ctrlKey,meta_key:event.metaKey,page_x:event.pageX,page_y:event.pageY,screen_x:event.screenX,screen_y:event.screenY,shift_key:event.shiftKey,pointer_id:event.pointerId,width:event.width,height:event.height,pressure:event.pressure,tangential_pressure:event.tangentialPressure,tilt_x:event.tiltX,tilt_y:event.tiltY,twist:event.twist,pointer_type:event.pointerType,is_primary:event.isPrimary}}function serializeMouseEvent(event){return{alt_key:event.altKey,button:event.button,buttons:event.buttons,client_x:event.clientX,client_y:event.clientY,ctrl_key:event.ctrlKey,meta_key:event.metaKey,offset_x:event.offsetX,offset_y:event.offsetY,page_x:event.pageX,page_y:event.pageY,screen_x:event.screenX,screen_y:event.screenY,shift_key:event.shiftKey}}function serializeKeyboardEvent(event){return{char_code:event.charCode,is_composing:event.isComposing,key:event.key,alt_key:event.altKey,ctrl_key:event.ctrlKey,meta_key:event.metaKey,key_code:event.keyCode,shift_key:event.shiftKey,location:event.location,repeat:event.repeat,which:event.which,code:event.code}}function serializeAnimationEvent(eLine truncated
|
function retrieveValues(event,target){let contents={values:{}},form=target.closest("form");if(form){if(event.type==="input"||event.type==="change"||event.type==="submit"||event.type==="reset"||event.type==="click")contents=retrieveFormValues(form)}return contents}function retrieveFormValues(form){const formData=new FormData(form),contents={};return formData.forEach((value,key)=>{if(contents[key])contents[key].push(value);else contents[key]=[value]}),{valid:form.checkValidity(),values:contents}}function retrieveSelectValue(target){let options=target.selectedOptions,values=[];for(let i=0;i<options.length;i++)values.push(options[i].value);return values}function serializeEvent(event,target){let contents={},extend=(obj)=>contents={...contents,...obj};if(event instanceof WheelEvent)extend(serializeWheelEvent(event));if(event instanceof MouseEvent)extend(serializeMouseEvent(event));if(event instanceof KeyboardEvent)extend(serializeKeyboardEvent(event));if(event instanceof InputEvent)extend(serializeInputEvent(event,target));if(event instanceof PointerEvent)extend(serializePointerEvent(event));if(event instanceof AnimationEvent)extend(serializeAnimationEvent(event));if(event instanceof TransitionEvent)extend({property_name:event.propertyName,elapsed_time:event.elapsedTime,pseudo_element:event.pseudoElement});if(event instanceof CompositionEvent)extend({data:event.data});if(event instanceof DragEvent)extend(serializeDragEvent(event));if(event instanceof FocusEvent)extend({});if(event instanceof ClipboardEvent)extend({});if(event instanceof CustomEvent){const detail=event.detail;if(detail instanceof ResizeObserverEntry)extend(serializeResizeEventDetail(detail))}if(typeof TouchEvent!=="undefined"&&event instanceof TouchEvent)extend(serializeTouchEvent(event));if(event.type==="submit"||event.type==="reset"||event.type==="click"||event.type==="change"||event.type==="input")extend(serializeInputEvent(event,target));if(event instanceof DragEvent);return contents}var toSerializableResizeObserverSize=function(size,is_inline_width){return[is_inline_width?size.inlineSize:size.blockSize,is_inline_width?size.blockSize:size.inlineSize]};function serializeResizeEventDetail(detail){let is_inline_width=!0;if(detail.target instanceof HTMLElement){if(window.getComputedStyle(detail.target).getPropertyValue("writing-mode")!=="horizontal-tb")is_inline_width=!1}return{border_box_size:detail.borderBoxSize!==void 0?toSerializableResizeObserverSize(detail.borderBoxSize[0],is_inline_width):detail.contentRect,content_box_size:detail.contentBoxSize!==void 0?toSerializableResizeObserverSize(detail.contentBoxSize[0],is_inline_width):detail.contentRect,content_rect:detail.contentRect}}var serializeInputEvent=function(event,target){let contents={};if(target instanceof HTMLElement){let values=retrieveValues(event,target);contents.values=values.values,contents.valid=values.valid}if(event.target instanceof HTMLInputElement){let target2=event.target,value=target2.value??target2.textContent??"";if(target2.type==="checkbox")value=target2.checked?"true":"false";else if(target2.type==="radio")value=target2.value;contents.value=value}if(event.target instanceof HTMLTextAreaElement)contents.value=event.target.value;if(event.target instanceof HTMLSelectElement)contents.value=retrieveSelectValue(event.target).join(",");if(contents.value===void 0)contents.value="";return contents},serializeWheelEvent=function(event){return{delta_x:event.deltaX,delta_y:event.deltaY,delta_z:event.deltaZ,delta_mode:event.deltaMode}},serializeTouchEvent=function(event){return{alt_key:event.altKey,ctrl_key:event.ctrlKey,meta_key:event.metaKey,shift_key:event.shiftKey,changed_touches:event.changedTouches,target_touches:event.targetTouches,touches:event.touches}},serializePointerEvent=function(event){return{alt_key:event.altKey,button:event.button,buttons:event.buttons,client_x:event.clientX,client_y:event.clientY,ctrl_key:event.ctrlKey,meta_key:event.metaKey,page_x:event.pageX,page_y:event.pageY,screen_x:event.screenX,screen_y:event.screenY,shift_key:event.shiftKey,pointer_id:event.pointerId,width:event.width,height:event.height,pressure:event.pressure,tangential_pressure:event.tangentialPressure,tilt_x:event.tiltX,tilt_y:event.tiltY,twist:event.twist,pointer_type:event.pointerType,is_primary:event.isPrimary}},serializeMouseEvent=function(event){return{alt_key:event.altKey,button:event.button,buttons:event.buttons,client_x:event.clientX,client_y:event.clientY,ctrl_key:event.ctrlKey,meta_key:event.metaKey,offset_x:event.offsetX,offset_y:event.offsetY,page_x:event.pageX,page_y:event.pageY,screen_x:event.screenX,screen_y:event.screenY,shift_key:event.shiftKey}},serializeKeyboardEvent=function(event){return{char_code:event.charCode,is_composing:event.isComposing,key:event.key,alt_key:event.altKey,ctrl_key:event.ctrlKey,meta_key:event.metaKey,key_code:event.keyCode,shift_key:event.shiftKey,location:event.location,repeat:event.repeat,which:event.which,code:event.code}},serializeAnimationELine truncated
|
||||||
@@ -167,6 +167,47 @@ export class NativeInterpreter extends JSChannel_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows drag-n-drop fix code. Called by wry drag-n-drop handler over the event loop.
|
||||||
|
handleWindowsDragDrop() {
|
||||||
|
if (window.dxDragLastElement) {
|
||||||
|
const dragLeaveEvent = new DragEvent("dragleave", { bubbles: true, cancelable: true });
|
||||||
|
window.dxDragLastElement.dispatchEvent(dragLeaveEvent);
|
||||||
|
|
||||||
|
let data = new DataTransfer();
|
||||||
|
|
||||||
|
// We need to mimic that there are actually files in this event for our native file engine to pick it up.
|
||||||
|
const file = new File(["content"], "file.txt", { type: "text/plain" });
|
||||||
|
data.items.add(file);
|
||||||
|
|
||||||
|
const dragDropEvent = new DragEvent("drop", { bubbles: true, cancelable: true, dataTransfer: data });
|
||||||
|
window.dxDragLastElement.dispatchEvent(dragDropEvent);
|
||||||
|
window.dxDragLastElement = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleWindowsDragOver(xPos, yPos) {
|
||||||
|
const element = document.elementFromPoint(xPos, yPos);
|
||||||
|
|
||||||
|
if (element != window.dxDragLastElement) {
|
||||||
|
if (window.dxDragLastElement) {
|
||||||
|
const dragLeaveEvent = new DragEvent("dragleave", { bubbles: true, cancelable: true });
|
||||||
|
window.dxDragLastElement.dispatchEvent(dragLeaveEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dragOverEvent = new DragEvent("dragover", { bubbles: true, cancelable: true });
|
||||||
|
element.dispatchEvent(dragOverEvent);
|
||||||
|
window.dxDragLastElement = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleWindowsDragLeave() {
|
||||||
|
if (window.dxDragLastElement) {
|
||||||
|
const dragLeaveEvent = new DragEvent("dragleave", { bubbles: true, cancelable: true });
|
||||||
|
window.dxDragLastElement.dispatchEvent(dragLeaveEvent);
|
||||||
|
window.dxDragLastElement = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ignore the fact the base interpreter uses ptr + len but we use array...
|
// ignore the fact the base interpreter uses ptr + len but we use array...
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
loadChild(array: number[]) {
|
loadChild(array: number[]) {
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ publish = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
dioxus = { workspace = true }
|
dioxus = { workspace = true }
|
||||||
dioxus-liveview = { workspace = true, features = ["axum"] }
|
dioxus-liveview = { workspace = true, features = ["axum"] }
|
||||||
tokio = { version = "1.19.2", features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
axum = { workspace = true, features = ["ws"] }
|
axum = { workspace = true, features = ["ws"] }
|
||||||
@@ -26,7 +26,7 @@ warnings = { workspace = true }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dioxus = { workspace = true }
|
dioxus = { workspace = true }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
simple_logger = "4.2.0"
|
simple_logger = "4.2.0"
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
|
|||||||
Reference in new issue
Block a user