Merge branch 'master' into jk/liveview-pool

This commit is contained in:
Jonathan Kelley committed 2023-03-13 21:45:27 -04:00
commit 55446c184c
11 files changed
+27 -40

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@
<span> | </span> <span> | </span>
<a href="https://github.com/DioxusLabs/example-projects"> Examples </a> <a href="https://github.com/DioxusLabs/example-projects"> Examples </a>
<span> | </span> <span> | </span>
<a href="https://dioxuslabs.com/guide/en/"> Guide </a> <a href="https://dioxuslabs.com/docs/0.3/guide/en/"> Guide </a>
<span> | </span> <span> | </span>
<a href="https://github.com/DioxusLabs/dioxus/blob/master/notes/README/ZH_CN.md"> 中文 </a> <a href="https://github.com/DioxusLabs/dioxus/blob/master/notes/README/ZH_CN.md"> 中文 </a>
<span> | </span> <span> | </span>
@@ -14,7 +14,7 @@ For example, if many components need to access an `AppSettings` struct, you can
## Custom Hook Logic ## Custom Hook Logic
You can use [`cx.use_hook`](https://docs.rs/dioxus/latest/dioxus/prelude/struct.Scope.html#method.use_hook) to build your own hooks. In fact, this is what all the standard hooks are built on! You can use [`cx.use_hook`](https://docs.rs/dioxus/latest/dioxus/prelude/struct.ScopeState.html#method.use_hook) to build your own hooks. In fact, this is what all the standard hooks are built on!
`use_hook` accepts a single closure for initializing the hook. It will be only run the first time the component is rendered. The return value of that closure will be used as the value of the hook – Dioxus will take it, and store it for as long as the component is alive. On every render (not just the first one!), you will get a reference to this value. `use_hook` accepts a single closure for initializing the hook. It will be only run the first time the component is rendered. The return value of that closure will be used as the value of the hook – Dioxus will take it, and store it for as long as the component is alive. On every render (not just the first one!), you will get a reference to this value.
+6 -5
View File
@@ -1,10 +1,11 @@
# Dioxus Router: Introduction # Dioxus Router: Introduction
Whether or not you're building a website, desktop app, or mobile app, organizing your app's views into "pages" can be an effective method for organization and maintainability. Whether or not you're building a website, desktop app, or mobile app, organizing your app's views into "pages" can be an effective method for organization and maintainability.
Dioxus comes with a router built-in. To start utilizing Dioxus Router, enable the ``router`` feature in your ``Cargo.toml`` file. The `dioxus-router` crate contains the Router module. To add it to your project run:
```toml
[dependencies] cargo add dioxus-router
dioxus = { version = "x.x.x", features = [.., "router"] }
``` > **Be sure to include the `web` feature (`--feature web`) for deployment into a browser!**
In this book you'll find a short [guide](./guide/index.md) to get up to speed with Dioxus Router, as well as the router's [reference](./reference/index.md). In this book you'll find a short [guide](./guide/index.md) to get up to speed with Dioxus Router, as well as the router's [reference](./reference/index.md).
+3 -3
View File
@@ -175,10 +175,10 @@ impl VirtualDom {
} }
impl ElementPath { impl ElementPath {
pub(crate) fn is_ascendant(&self, big: &&[u8]) -> bool { pub(crate) fn is_decendant(&self, small: &&[u8]) -> bool {
match *self { match *self {
ElementPath::Deep(small) => small.len() <= big.len() && small == &big[..small.len()], ElementPath::Deep(big) => small.len() <= big.len() && *small == &big[..small.len()],
ElementPath::Root(r) => big.len() == 1 && big[0] == r as u8, ElementPath::Root(r) => small.len() == 1 && small[0] == r as u8,
} }
} }
} }
+3 -3
View File
@@ -72,9 +72,9 @@ pub struct LocalTaskHandle {
impl ArcWake for LocalTaskHandle { impl ArcWake for LocalTaskHandle {
fn wake_by_ref(arc_self: &Arc<Self>) { 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 .tx
.unbounded_send(SchedulerMsg::TaskNotified(arc_self.id)) .unbounded_send(SchedulerMsg::TaskNotified(arc_self.id));
.unwrap();
} }
} }
+1 -1
View File
@@ -396,7 +396,7 @@ impl VirtualDom {
// Remove the "on" prefix if it exists, TODO, we should remove this and settle on one // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one
if attr.name.trim_start_matches("on") == name if attr.name.trim_start_matches("on") == name
&& target_path.is_ascendant(&this_path) && target_path.is_decendant(&this_path)
{ {
listeners.push(&attr.value); listeners.push(&attr.value);
+5 -4
View File
@@ -357,10 +357,11 @@ class Interpreter {
if (event.type === "click") { if (event.type === "click") {
// todo call prevent default if it's the right type of event // todo call prevent default if it's the right type of event
if (shouldPreventDefault !== `onclick`) { let a_element = target.closest("a");
if (target.tagName === "A") { if (a_element != null) {
event.preventDefault(); event.preventDefault();
const href = target.getAttribute("href"); if (shouldPreventDefault !== `onclick` && a_element.getAttribute(`dioxus-prevent-default`) !== `onclick`) {
const href = a_element.getAttribute("href");
if (href !== "" && href !== null && href !== undefined) { if (href !== "" && href !== null && href !== undefined) {
window.ipc.postMessage( window.ipc.postMessage(
serializeIpcMessage("browser_open", { href }) serializeIpcMessage("browser_open", { href })
+1 -1
View File
@@ -1,4 +1,4 @@
# Dioxus Native Core # Dioxus Router
[![Crates.io][crates-badge]][crates-url] [![Crates.io][crates-badge]][crates-url]
[![MIT licensed][mit-badge]][mit-url] [![MIT licensed][mit-badge]][mit-url]
+2 -7
View File
@@ -46,18 +46,13 @@ impl Default for Config {
} }
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy, Default)]
pub enum RenderingMode { pub enum RenderingMode {
/// only 16 colors by accessed by name, no alpha support /// only 16 colors by accessed by name, no alpha support
BaseColors, BaseColors,
/// 8 bit colors, will be downsampled from rgb colors /// 8 bit colors, will be downsampled from rgb colors
Ansi, Ansi,
/// 24 bit colors, most terminals support this /// 24 bit colors, most terminals support this
#[default]
Rgb, Rgb,
} }
impl Default for RenderingMode {
fn default() -> Self {
RenderingMode::Rgb
}
}
+2 -7
View File
@@ -14,8 +14,9 @@ use dioxus_native_core::{
state::NodeDepState, state::NodeDepState,
}; };
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]
pub(crate) enum FocusLevel { pub(crate) enum FocusLevel {
#[default]
Unfocusable, Unfocusable,
Focusable, Focusable,
Ordered(std::num::NonZeroU16), 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)] #[derive(Clone, PartialEq, Debug, Default)]
pub(crate) struct Focus { pub(crate) struct Focus {
pub level: FocusLevel, pub level: FocusLevel,
+2 -7
View File
@@ -20,7 +20,7 @@ pub(crate) struct NodeState {
pub focused: bool, pub focused: bool,
} }
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone, Default)]
pub(crate) enum PreventDefault { pub(crate) enum PreventDefault {
Focus, Focus,
KeyPress, KeyPress,
@@ -32,6 +32,7 @@ pub(crate) enum PreventDefault {
MouseEnter, MouseEnter,
MouseLeave, MouseLeave,
MouseOut, MouseOut,
#[default]
Unknown, Unknown,
MouseOver, MouseOver,
ContextMenu, ContextMenu,
@@ -39,12 +40,6 @@ pub(crate) enum PreventDefault {
MouseUp, MouseUp,
} }
impl Default for PreventDefault {
fn default() -> Self {
PreventDefault::Unknown
}
}
impl NodeDepState for PreventDefault { impl NodeDepState for PreventDefault {
type DepState = (); type DepState = ();
type Ctx = (); type Ctx = ();