Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
Paste into a page's text fields: raea's pages get Blitz's shell provider with the clipboard (Shane 11-09: "make sure i can paste text into any text field")
shinyobjectzbb1d2bd0d5f7
diff --git a/Cargo.lock b/Cargo.lockindex 6cc392dc..b74082ca 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -14392,8 +14392,10 @@ dependencies = ["base64 0.22.1","bevy","blitz-dom",+ "blitz-html","blitz-traits","image",+ "keyboard-types","raea-io-media","raea-io-net-calls","raea-io-os",diff --git a/engine/page/host/Cargo.toml b/engine/page/host/Cargo.tomlindex 2c747cdc..bb08d1e7 100644--- a/engine/page/host/Cargo.toml+++ b/engine/page/host/Cargo.toml@@ -62,3 +62,6 @@ ignored = ["raea-io-media"]# T2b and T2d: the recorded net and system calls (tests/net_calls.rs)raea-io-net-calls = { path = "../../../io/net/calls", features = ["serve"] }raea-io-os = { path = "../../../io/os", features = ["recorded"] }+# a page's field pasted into (src/shell.rs's test)+blitz-html = "=0.3.0-beta.4"+keyboard-types = "0.8"diff --git a/engine/page/host/src/lib.rs b/engine/page/host/src/lib.rsindex 50d0ef1a..efbbc43e 100644--- a/engine/page/host/src/lib.rs+++ b/engine/page/host/src/lib.rs@@ -12,6 +12,7 @@ pub use raea_page_stage as stage;pub mod inject;pub mod mcp;pub mod page;+pub mod shell;pub mod tree;use std::time::Duration;@@ -54,6 +55,10 @@ impl Plugin for HostPlugin {// the pointer is fed by inject.rs: headless, picking's own mouse reader would place it on the window, not its// image; on screen, inject::window_pointer reads the window's events as that reader does, with a trackpad's// deltas in points+ // a text field's copy, cut and paste reach the clipboard (src/shell.rs), unless the app gave its pages a shell+ if !app.world().contains_resource::<raea_sys_page::PageShell>() {+ app.insert_resource(raea_sys_page::PageShell(std::sync::Arc::new(shell::Shell)));+ }app.insert_resource(PointerInputSettings { is_mouse_enabled: false, is_touch_enabled: false }).insert_resource(inject::Clicks::new(self.double_click)).insert_resource(LaunchSize(self.size))diff --git a/engine/page/host/src/shell.rs b/engine/page/host/src/shell.rsnew file mode 100644index 00000000..28535b52--- /dev/null+++ b/engine/page/host/src/shell.rs@@ -0,0 +1,81 @@+//! The shell a page's documents are made with (raea-sys-page's PageShell): the clipboard, so a text field's Cmd+C,+//! Cmd+X and Cmd+V reach it. Blitz's default shell has none, so a paste into any field of raea.app inserted nothing+//! (Shane 11-09: "make sure i can paste text into any text field"). It's raea-io-os's clipboard: the system's in the+//! window, the process's own headless, as navigator.clipboard's is.++use blitz_traits::shell::{ClipboardError, ShellProvider};++/// Blitz's shell for raea's pages: the clipboard, and the rest left as Blitz's default has them+pub struct Shell;++impl ShellProvider for Shell {+ fn get_clipboard_text(&self) -> Result<String, ClipboardError> {+ raea_io_os::clipboard_text().map_err(|_| ClipboardError)+ }++ fn set_clipboard_text(&self, text: String) -> Result<(), ClipboardError> {+ raea_io_os::set_clipboard_text(text).map_err(|_| ClipboardError)+ }+}++#[cfg(test)]+mod tests {+ use std::sync::Arc;++ use bevy::prelude::*;+ use blitz_dom::{BaseDocument, EventDriver, NoopEventHandler};+ use blitz_traits::NodeId;+ use blitz_traits::events::{BlitzKeyEvent, KeyState, UiEvent};+ use keyboard_types::{Code, Key, Location, Modifiers};+ use raea_sys_page::{Page, PageShell};++ /// A page with one field, made with the App's providers and `shell`, the field focused.+ fn field(shell: Option<PageShell>) -> (BaseDocument, NodeId) {+ let mut app = App::new();+ if let Some(s) = shell {+ app.insert_resource(s);+ }+ let at = Page { size: UVec2::new(400, 300), scale: 1.0 };+ let config = raea_sys_page::providers::config_in(app.world(), at, None);+ let html = r#"<body style="margin:0"><input id="f" value="ab" style="display:block;width:200px;height:30px"></body>"#;+ let mut doc = blitz_html::HtmlDocument::from_html(html, config).into_inner();+ doc.resolve(0.0);+ let f = doc.get_element_by_id("f").unwrap();+ doc.set_focus_to(f);+ (doc, f)+ }++ /// Cmd and `c` pressed, as raea's window hands Blitz a key (runtime/dom bridge.rs WindowInput: Super is META)+ fn cmd(doc: &mut BaseDocument, c: &str) {+ let ev = BlitzKeyEvent { key: Key::Character(c.into()), code: Code::KeyV, modifiers: Modifiers::META, location: Location::Standard, is_auto_repeating: false, is_composing: false, state: KeyState::Pressed, text: None };+ EventDriver::new(doc, NoopEventHandler).handle_ui_event(UiEvent::KeyDown(ev));+ }++ fn value(doc: &BaseDocument, f: NodeId) -> String {+ doc.get_node(f).unwrap().element_data().unwrap().text_input_data().unwrap().editor.raw_text().to_string()+ }++ /// Cmd+V in a field pastes the clipboard's text at the caret, and Cmd+A, Cmd+C copies the field's; without+ /// the shell (Blitz's default) the paste inserts nothing, which raea.app's fields did before+ #[test]+ fn a_field_pastes_and_copies_through_the_clipboard() {+ // the process's own clipboard: the test never touches the Mac's+ raea_io_os::set_headless();+ raea_io_os::set_clipboard_text("sunmelt".into()).unwrap();++ let (mut bare, f) = field(None);+ cmd(&mut bare, "v");+ assert_eq!(value(&bare, f), "ab", "Blitz's default shell has no clipboard");++ let (mut doc, f) = field(Some(PageShell(Arc::new(super::Shell))));+ cmd(&mut doc, "v");+ // focused from code, the caret is at the field's start+ assert_eq!(value(&doc, f), "sunmeltab");++ cmd(&mut doc, "a");+ cmd(&mut doc, "c");+ raea_io_os::set_clipboard_text(String::new()).unwrap();+ cmd(&mut doc, "c");+ assert_eq!(raea_io_os::clipboard_text().unwrap(), "sunmeltab");+ }+}diff --git a/io/os/src/lib.rs b/io/os/src/lib.rsindex d1a9679a..f101f94f 100644--- a/io/os/src/lib.rs+++ b/io/os/src/lib.rs@@ -128,6 +128,17 @@ fn open(args: &Value) -> Result<Value, String> {opener::open(url).map(|()| Value::Null).map_err(|e| format!("os.open {url}: {e}"))}+/// The clipboard's text ("" when it holds none): the system's, or the process's own when headless. A page's text+/// field pastes from it (engine/page/host shell.rs, Blitz's shell provider).+pub fn clipboard_text() -> Result<String, String> {+ clipboard(None).map(|v| v.as_str().unwrap_or_default().to_string())+}++/// `text` onto the clipboard: the system's, or the process's own when headless.+pub fn set_clipboard_text(text: String) -> Result<(), String> {+ clipboard(Some(text)).map(|_| ())+}+/// The clipboard's text, or `text` written to it: the process's own when headless.fn clipboard(text: Option<String>) -> Result<Value, String> {static OWN: Mutex<String> = Mutex::new(String::new());diff --git a/systems/page/src/lib.rs b/systems/page/src/lib.rsindex a30c0d94..1e12e061 100644--- a/systems/page/src/lib.rs+++ b/systems/page/src/lib.rs@@ -25,7 +25,7 @@ pub use blitz_dom::not_applied; // what the page asked for and didn't get, said/// Blitz's extension points as Bevy resources (S6d)pub mod providers;pub mod widgets;-pub use providers::{PageFonts, PageHtmlParser, PageNavigation, PageNet};+pub use providers::{PageFonts, PageHtmlParser, PageNavigation, PageNet, PageShell};pub use raea_sys_page_ops as ops;pub mod view3d;diff --git a/systems/page/src/providers.rs b/systems/page/src/providers.rsindex 6c43c722..b4aa7d38 100644--- a/systems/page/src/providers.rs+++ b/systems/page/src/providers.rs@@ -9,6 +9,8 @@//! blitz-html's while iframes are on (RAEA_PAGE_IFRAMES).//! - [`PageFonts`]: the font collection (B0d's: one a process, shared with bevy_text). A document given faces of its//! own keeps them.+//! - [`PageShell`]: the shell provider, which holds the clipboard a text field's Cmd+C, Cmd+X and Cmd+V use. Blitz's+//! default has none (a paste inserted nothing); raea-page-host inserts one on raea-io-os's clipboard.//!//! Each takes effect for the documents made after it's inserted; a document already open keeps what it was made with,//! as a Blitz document does.@@ -19,6 +21,7 @@ use bevy::prelude::*;use blitz_dom::{DocumentConfig, FontContext, HtmlParserProvider};use blitz_traits::navigation::NavigationProvider;use blitz_traits::net::NetProvider;+use blitz_traits::shell::ShellProvider;use crate::Page;@@ -34,6 +37,10 @@ pub struct PageNavigation(pub Arc<dyn NavigationProvider>);#[derive(Resource, Clone)]pub struct PageHtmlParser(pub Arc<dyn HtmlParserProvider + Send + Sync>);+/// The shell provider a page's document reaches the system through: the clipboard (a text field's copy, cut and paste)+#[derive(Resource, Clone)]+pub struct PageShell(pub Arc<dyn ShellProvider>);+/// The font collection a page's document draws its text with, unless it's given faces of its own#[derive(Resource, Clone)]pub struct PageFonts(pub FontContext);@@ -61,6 +68,9 @@ pub fn config_in(world: &World, at: Page, fonts: Option<FontContext>) -> Documenif let Some(parser) = world.get_resource::<PageHtmlParser>() {config.html_parser_provider = Some(parser.0.clone());}+ if let Some(shell) = world.get_resource::<PageShell>() {+ config.shell_provider = Some(shell.0.clone());+ }config.font_ctx = fonts;if config.font_ctx.is_none()&& let Some(PageFonts(own)) = world.get_resource::<PageFonts>()@@ -90,13 +100,16 @@ mod tests {defaults(&mut app);let at = Page { size: UVec2::new(100, 100), scale: 1.0 };let config = config_in(app.world(), at, None);- assert!(config.net_provider.is_some() && config.navigation_provider.is_none() && config.font_ctx.is_none());+ assert!(config.net_provider.is_some() && config.navigation_provider.is_none() && config.font_ctx.is_none() && config.shell_provider.is_none());let nav: Arc<dyn NavigationProvider> = Arc::new(Heard(Default::default()));app.insert_resource(PageNavigation(nav.clone()));app.insert_resource(PageFonts(FontContext::default()));+ let shell: Arc<dyn ShellProvider> = Arc::new(blitz_traits::shell::DummyShellProvider);+ app.insert_resource(PageShell(shell.clone()));let config = config_in(app.world(), at, None);assert!(Arc::ptr_eq(config.navigation_provider.as_ref().unwrap(), &nav));+ assert!(Arc::ptr_eq(config.shell_provider.as_ref().unwrap(), &shell));assert!(config.font_ctx.is_some());// defaults leave a provider the App put in first