Skip to content

Commit 961ba29

Browse files
committed
Native: Split dioxus-native-dom crate out of dioxus-native
Signed-off-by: Nico Burns <[email protected]>
1 parent 5495bce commit 961ba29

File tree

10 files changed

+130
-64
lines changed

10 files changed

+130
-64
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ members = [
6969
"packages/logger",
7070
"packages/config-macros",
7171
"packages/native",
72+
"packages/native-dom",
7273
"packages/asset-resolver",
7374
"packages/depinfo",
7475
"packages/server",
@@ -175,6 +176,7 @@ dioxus_server_macro = { path = "packages/server-macro", version = "0.7.0-alpha.2
175176
dioxus-dx-wire-format = { path = "packages/dx-wire-format", version = "0.7.0-alpha.2" }
176177
dioxus-logger = { path = "packages/logger", version = "0.7.0-alpha.2" }
177178
dioxus-native = { path = "packages/native", version = "0.7.0-alpha.2" }
179+
dioxus-native-dom = { path = "packages/native-dom", version = "0.7.0-alpha.2" }
178180
dioxus-asset-resolver = { path = "packages/asset-resolver", version = "0.7.0-alpha.2" }
179181
dioxus-config-macros = { path = "packages/config-macros", version = "0.7.0-alpha.2" }
180182
const-serialize = { path = "packages/const-serialize", version = "0.7.0-alpha.2" }

packages/native-dom/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[package]
2+
name = "dioxus-native-dom"
3+
version = { workspace = true }
4+
authors = ["Jonathan Kelley", "Nico Burns"]
5+
edition = "2021"
6+
description = "Core headless native renderer for Dioxus based on blitz"
7+
license = "MIT OR Apache-2.0"
8+
repository = "https://github.com/DioxusLabs/dioxus/"
9+
homepage = "https://dioxuslabs.com/learn/0.6/getting_started"
10+
keywords = ["dom", "ui", "gui", "react"]
11+
12+
[features]
13+
default = ["accessibility", "tracing", "svg", "system-fonts"]
14+
svg = ["blitz-dom/svg"]
15+
accessibility = ["blitz-dom/accessibility"]
16+
tracing = ["dep:tracing", "blitz-dom/tracing"]
17+
system-fonts = ["blitz-dom/system_fonts"]
18+
autofocus = []
19+
20+
[dependencies]
21+
# Blitz dependencies
22+
blitz-dom = { version = "=0.1.0-alpha.5", default-features = false }
23+
blitz-traits = { version = "=0.1.0-alpha.5" }
24+
25+
# DioxusLabs dependencies
26+
dioxus-core = { workspace = true }
27+
dioxus-html = { workspace = true }
28+
29+
# Windowing & Input
30+
keyboard-types = { workspace = true }
31+
32+
33+
# Other dependencies
34+
tracing = { workspace = true, optional = true }
35+
rustc-hash = { workspace = true }
36+
futures-util = { workspace = true }
37+
38+
[package.metadata.docs.rs]
39+
all-features = true
40+
rustdoc-args = ["--cfg", "docsrs"]

packages/native/src/dioxus_document.rs renamed to packages/native-dom/src/dioxus_document.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Integration between Dioxus and Blitz
2-
use blitz_dom::Attribute;
3-
use futures_util::{pin_mut, FutureExt};
4-
use std::ops::{Deref, DerefMut};
5-
use std::{any::Any, collections::HashMap, rc::Rc, sync::Arc};
2+
use crate::events::{BlitzKeyboardData, NativeClickData, NativeConverter, NativeFormData};
3+
use crate::mutation_writer::{DioxusState, MutationWriter};
4+
use crate::qual_name;
5+
use crate::NodeId;
66

7+
use blitz_dom::Attribute;
78
use blitz_dom::{
89
net::Resource, BaseDocument, Document, EventDriver, EventHandler, Node, DEFAULT_CSS,
910
};
@@ -15,11 +16,9 @@ use blitz_traits::{
1516

1617
use dioxus_core::{ElementId, Event, VirtualDom};
1718
use dioxus_html::{set_event_converter, PlatformEventData};
18-
19-
use crate::events::{BlitzKeyboardData, NativeClickData, NativeConverter, NativeFormData};
20-
use crate::mutation_writer::{DioxusState, MutationWriter};
21-
use crate::qual_name;
22-
use crate::NodeId;
19+
use futures_util::{pin_mut, FutureExt};
20+
use std::ops::{Deref, DerefMut};
21+
use std::{any::Any, collections::HashMap, rc::Rc, sync::Arc};
2322

2423
fn wrap_event_data<T: Any>(value: T) -> Rc<dyn Any> {
2524
Rc::new(PlatformEventData::new(Box::new(value)))
@@ -36,9 +35,9 @@ fn get_dioxus_id(node: &Node) -> Option<ElementId> {
3635
}
3736

3837
pub struct DioxusDocument {
39-
pub(crate) vdom: VirtualDom,
40-
pub(crate) vdom_state: DioxusState,
41-
pub(crate) inner: BaseDocument,
38+
pub inner: BaseDocument,
39+
pub vdom: VirtualDom,
40+
pub vdom_state: DioxusState,
4241

4342
#[allow(unused)]
4443
pub(crate) html_element_id: NodeId,

packages/native/src/events.rs renamed to packages/native-dom/src/events.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use dioxus_html::{
66
InteractionElementOffset, InteractionLocation, ModifiersInteraction, PointerInteraction,
77
},
88
AnimationData, ClipboardData, CompositionData, DragData, FocusData, FormData, FormValue,
9-
HasFileData, HasFormData, HasMouseData, HtmlEventConverter, ImageData, KeyboardData, MediaData,
10-
MountedData, MouseData, PlatformEventData, PointerData, ResizeData, ScrollData, SelectionData,
11-
ToggleData, TouchData, TransitionData, VisibleData, WheelData,
9+
HasFileData, HasFocusData, HasFormData, HasKeyboardData, HasMouseData, HtmlEventConverter,
10+
ImageData, KeyboardData, MediaData, MountedData, MouseData, PlatformEventData, PointerData,
11+
ResizeData, ScrollData, SelectionData, ToggleData, TouchData, TransitionData, VisibleData,
12+
WheelData,
1213
};
13-
use dioxus_html::{HasFocusData, HasKeyboardData};
1414
use keyboard_types::{Code, Key, Location, Modifiers};
1515
use std::any::Any;
1616
use std::collections::HashMap;

packages/native-dom/src/lib.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#![cfg_attr(docsrs, feature(doc_cfg))]
2+
3+
//! Core headless native renderer for Dioxus.
4+
//!
5+
//! ## Feature flags
6+
//! - `default`: Enables the features listed below.
7+
//! - `accessibility`: Enables [`accesskit`](https://docs.rs/accesskit/latest/accesskit/) accessibility support.
8+
//! - `hot-reload`: Enables hot-reloading of Dioxus RSX.
9+
//! - `menu`: Enables the [`muda`](https://docs.rs/muda/latest/muda/) menubar.
10+
//! - `tracing`: Enables tracing support.
11+
12+
mod dioxus_document;
13+
mod events;
14+
mod mutation_writer;
15+
pub use dioxus_document::DioxusDocument;
16+
17+
use blitz_dom::{ns, LocalName, Namespace, QualName};
18+
type NodeId = usize;
19+
20+
pub(crate) fn qual_name(local_name: &str, namespace: Option<&str>) -> QualName {
21+
QualName {
22+
prefix: None,
23+
ns: namespace.map(Namespace::from).unwrap_or(ns!(html)),
24+
local: LocalName::from(local_name),
25+
}
26+
}
27+
28+
// Syntax sugar to make tracing calls less noisy in function below
29+
macro_rules! trace {
30+
($pattern:literal) => {{
31+
#[cfg(feature = "tracing")]
32+
tracing::info!($pattern);
33+
}};
34+
($pattern:literal, $item1:expr) => {{
35+
#[cfg(feature = "tracing")]
36+
tracing::info!($pattern, $item1);
37+
}};
38+
($pattern:literal, $item1:expr, $item2:expr) => {{
39+
#[cfg(feature = "tracing")]
40+
tracing::info!($pattern, $item1, $item2);
41+
}};
42+
($pattern:literal, $item1:expr, $item2:expr, $item3:expr) => {{
43+
#[cfg(feature = "tracing")]
44+
tracing::info!($pattern, $item1, $item2);
45+
}};
46+
($pattern:literal, $item1:expr, $item2:expr, $item3:expr, $item4:expr) => {{
47+
#[cfg(feature = "tracing")]
48+
tracing::info!($pattern, $item1, $item2, $item3, $item4);
49+
}};
50+
}
51+
pub(crate) use trace;

packages/native/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ blitz-shell = { version = "=0.1.0-alpha.5", default-features = false }
3232
# DioxusLabs dependencies
3333
dioxus-core = { workspace = true }
3434
dioxus-html = { workspace = true }
35+
dioxus-native-dom = { workspace = true }
3536
dioxus-asset-resolver = { workspace = true }
3637
dioxus-cli-config = { workspace = true, optional = true }
3738
dioxus-devtools = { workspace = true, optional = true }

packages/native/src/dioxus_application.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use winit::event_loop::{ActiveEventLoop, EventLoopProxy};
88
use winit::window::WindowId;
99

1010
use crate::DioxusNativeWindowRenderer;
11-
use crate::{
12-
contexts::DioxusNativeDocument, mutation_writer::MutationWriter, BlitzShellEvent,
13-
DioxusDocument, WindowConfig,
14-
};
11+
use crate::{contexts::DioxusNativeDocument, BlitzShellEvent, DioxusDocument, WindowConfig};
1512

1613
/// Dioxus-native specific event type
1714
pub enum DioxusNativeEvent {
@@ -138,9 +135,7 @@ impl ApplicationHandler<BlitzShellEvent> for DioxusNativeApplication {
138135
.in_runtime(move || ScopeId::ROOT.provide_context(renderer));
139136

140137
// Queue rebuild
141-
let mut writer = MutationWriter::new(&mut doc.inner, &mut doc.vdom_state);
142-
doc.vdom.rebuild(&mut writer);
143-
drop(writer);
138+
doc.initial_build();
144139

145140
// And then request redraw
146141
window.request_redraw();

packages/native/src/lib.rs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,22 @@
1212
mod assets;
1313
mod contexts;
1414
mod dioxus_application;
15-
mod dioxus_document;
1615
mod dioxus_renderer;
17-
mod events;
18-
mod mutation_writer;
16+
17+
#[doc(inline)]
18+
pub use dioxus_native_dom::*;
1919

2020
pub use anyrender_vello::{
2121
wgpu_context::DeviceHandle, CustomPaintCtx, CustomPaintSource, TextureHandle,
2222
};
23-
use assets::DioxusNativeNetProvider;
24-
use blitz_dom::{ns, LocalName, Namespace, QualName};
2523
pub use dioxus_application::{DioxusNativeApplication, DioxusNativeEvent};
26-
pub use dioxus_document::DioxusDocument;
2724
pub use dioxus_renderer::{use_wgpu, DioxusNativeWindowRenderer, Features, Limits};
25+
use assets::DioxusNativeNetProvider;
2826

2927
use blitz_shell::{create_default_event_loop, BlitzShellEvent, Config, WindowConfig};
3028
use dioxus_core::{ComponentFunction, Element, VirtualDom};
3129
use std::any::Any;
3230

33-
type NodeId = usize;
34-
3531
/// Launch an interactive HTML/CSS renderer driven by the Dioxus virtualdom
3632
pub fn launch(app: fn() -> Element) {
3733
launch_cfg(app, vec![], vec![])
@@ -135,36 +131,3 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
135131
// Run event loop
136132
event_loop.run_app(&mut application).unwrap();
137133
}
138-
139-
pub(crate) fn qual_name(local_name: &str, namespace: Option<&str>) -> QualName {
140-
QualName {
141-
prefix: None,
142-
ns: namespace.map(Namespace::from).unwrap_or(ns!(html)),
143-
local: LocalName::from(local_name),
144-
}
145-
}
146-
147-
// Syntax sugar to make tracing calls less noisy in function below
148-
macro_rules! trace {
149-
($pattern:literal) => {{
150-
#[cfg(feature = "tracing")]
151-
tracing::info!($pattern);
152-
}};
153-
($pattern:literal, $item1:expr) => {{
154-
#[cfg(feature = "tracing")]
155-
tracing::info!($pattern, $item1);
156-
}};
157-
($pattern:literal, $item1:expr, $item2:expr) => {{
158-
#[cfg(feature = "tracing")]
159-
tracing::info!($pattern, $item1, $item2);
160-
}};
161-
($pattern:literal, $item1:expr, $item2:expr, $item3:expr) => {{
162-
#[cfg(feature = "tracing")]
163-
tracing::info!($pattern, $item1, $item2);
164-
}};
165-
($pattern:literal, $item1:expr, $item2:expr, $item3:expr, $item4:expr) => {{
166-
#[cfg(feature = "tracing")]
167-
tracing::info!($pattern, $item1, $item2, $item3, $item4);
168-
}};
169-
}
170-
pub(crate) use trace;

0 commit comments

Comments
 (0)