Merge branch 'DioxusLabs:master' into fix-component-attribute-formatting
This commit is contained in:
14 files changed
+60
-49
No files matched your search
@@ -175,10 +175,10 @@ impl VirtualDom {
|
||||
}
|
||||
|
||||
impl ElementPath {
|
||||
pub(crate) fn is_ascendant(&self, big: &&[u8]) -> bool {
|
||||
pub(crate) fn is_decendant(&self, small: &&[u8]) -> bool {
|
||||
match *self {
|
||||
ElementPath::Deep(small) => small.len() <= big.len() && small == &big[..small.len()],
|
||||
ElementPath::Root(r) => big.len() == 1 && big[0] == r as u8,
|
||||
ElementPath::Deep(big) => small.len() <= big.len() && *small == &big[..small.len()],
|
||||
ElementPath::Root(r) => small.len() == 1 && small[0] == r as u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ pub struct LocalTaskHandle {
|
||||
|
||||
impl ArcWake for LocalTaskHandle {
|
||||
fn wake_by_ref(arc_self: &Arc<Self>) {
|
||||
arc_self
|
||||
// This can fail if the scheduler has been dropped while the application is shutting down
|
||||
let _ = arc_self
|
||||
.tx
|
||||
.unbounded_send(SchedulerMsg::TaskNotified(arc_self.id))
|
||||
.unwrap();
|
||||
.unbounded_send(SchedulerMsg::TaskNotified(arc_self.id));
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ impl VirtualDom {
|
||||
|
||||
// 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_ascendant(&this_path)
|
||||
&& target_path.is_decendant(&this_path)
|
||||
{
|
||||
listeners.push(&attr.value);
|
||||
|
||||
|
||||
@@ -271,6 +271,11 @@ impl DesktopContext {
|
||||
self.shortcut_manager.remove_shortcut(id)
|
||||
}
|
||||
|
||||
/// Remove all global shortcuts
|
||||
pub fn remove_all_shortcuts(&self) {
|
||||
self.shortcut_manager.remove_all()
|
||||
}
|
||||
|
||||
/// Push an objc view to the window
|
||||
#[cfg(target_os = "ios")]
|
||||
pub fn push_view(&self, view: objc_id::ShareId<objc::runtime::Object>) {
|
||||
|
||||
@@ -113,6 +113,18 @@ impl ShortcutRegistry {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn remove_all(&self) {
|
||||
let mut shortcuts = self.shortcuts.borrow_mut();
|
||||
shortcuts.clear();
|
||||
let _ = self.manager.borrow_mut().unregister_all();
|
||||
// prevent CTRL+R from reloading the page which breaks apps
|
||||
let _ = self.add_shortcut(
|
||||
Some(ModifiersState::CONTROL),
|
||||
KeyCode::KeyR,
|
||||
Box::new(|| {}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
|
||||
@@ -37,7 +37,16 @@ impl LiveViewPool {
|
||||
app: fn(Scope<T>) -> Element,
|
||||
props: T,
|
||||
) -> Result<(), LiveViewError> {
|
||||
match self.pool.spawn_pinned(move || run(app, props, ws)).await {
|
||||
self.launch_virtualdom(ws, move || VirtualDom::new_with_props(app, props))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn launch_virtualdom<F: FnOnce() -> VirtualDom + Send + 'static>(
|
||||
&self,
|
||||
ws: impl LiveViewSocket,
|
||||
make_app: F,
|
||||
) -> Result<(), LiveViewError> {
|
||||
match self.pool.spawn_pinned(move || run(make_app(), ws)).await {
|
||||
Ok(Ok(_)) => Ok(()),
|
||||
Ok(Err(e)) => Err(e),
|
||||
Err(_) => Err(LiveViewError::SendingFailed),
|
||||
@@ -95,14 +104,7 @@ impl<S> LiveViewSocket for S where
|
||||
/// As long as your framework can provide a Sink and Stream of Strings, you can use this function.
|
||||
///
|
||||
/// You might need to transform the error types of the web backend into the LiveView error type.
|
||||
pub async fn run<T>(
|
||||
app: Component<T>,
|
||||
props: T,
|
||||
ws: impl LiveViewSocket,
|
||||
) -> Result<(), LiveViewError>
|
||||
where
|
||||
T: Send + 'static,
|
||||
{
|
||||
pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), LiveViewError> {
|
||||
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||
let mut hot_reload_rx = {
|
||||
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
@@ -112,8 +114,6 @@ where
|
||||
rx
|
||||
};
|
||||
|
||||
let mut vdom = VirtualDom::new_with_props(app, props);
|
||||
|
||||
// todo: use an efficient binary packed format for this
|
||||
let edits = serde_json::to_string(&vdom.rebuild()).unwrap();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Dioxus Native Core
|
||||
# Dioxus Router
|
||||
|
||||
[![Crates.io][crates-badge]][crates-url]
|
||||
[![MIT licensed][mit-badge]][mit-url]
|
||||
|
||||
@@ -46,18 +46,13 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub enum RenderingMode {
|
||||
/// only 16 colors by accessed by name, no alpha support
|
||||
BaseColors,
|
||||
/// 8 bit colors, will be downsampled from rgb colors
|
||||
Ansi,
|
||||
/// 24 bit colors, most terminals support this
|
||||
#[default]
|
||||
Rgb,
|
||||
}
|
||||
|
||||
impl Default for RenderingMode {
|
||||
fn default() -> Self {
|
||||
RenderingMode::Rgb
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,9 @@ use dioxus_native_core::{
|
||||
state::NodeDepState,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
|
||||
pub(crate) enum FocusLevel {
|
||||
#[default]
|
||||
Unfocusable,
|
||||
Focusable,
|
||||
Ordered(std::num::NonZeroU16),
|
||||
@@ -53,12 +54,6 @@ impl Ord for FocusLevel {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for FocusLevel {
|
||||
fn default() -> Self {
|
||||
FocusLevel::Unfocusable
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Default)]
|
||||
pub(crate) struct Focus {
|
||||
pub level: FocusLevel,
|
||||
|
||||
@@ -20,7 +20,7 @@ pub(crate) struct NodeState {
|
||||
pub focused: bool,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
#[derive(PartialEq, Debug, Clone, Default)]
|
||||
pub(crate) enum PreventDefault {
|
||||
Focus,
|
||||
KeyPress,
|
||||
@@ -32,6 +32,7 @@ pub(crate) enum PreventDefault {
|
||||
MouseEnter,
|
||||
MouseLeave,
|
||||
MouseOut,
|
||||
#[default]
|
||||
Unknown,
|
||||
MouseOver,
|
||||
ContextMenu,
|
||||
@@ -39,12 +40,6 @@ pub(crate) enum PreventDefault {
|
||||
MouseUp,
|
||||
}
|
||||
|
||||
impl Default for PreventDefault {
|
||||
fn default() -> Self {
|
||||
PreventDefault::Unknown
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeDepState for PreventDefault {
|
||||
type DepState = ();
|
||||
type Ctx = ();
|
||||
|
||||
Reference in new issue
Block a user