From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id C9EBD1FF0BA for ; Thu, 20 Aug 2026 10:17:58 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 618602157A; Thu, 20 Aug 2026 10:17:58 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH yew-widget-toolkit 1/3] state: event: add helpers for custom DOM events Date: Thu, 20 Aug 2026 10:17:37 +0200 Message-ID: <20260820081746.989972-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260820081746.989972-1-d.csapak@proxmox.com> References: <20260820081746.989972-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.863 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: FPFTGE5PRRC443RQTANEKZRIRT4GQRTP X-Message-ID-Hash: FPFTGE5PRRC443RQTANEKZRIRT4GQRTP X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Creating and dispatching custom events is currently open coded, e.g. for the `pwt-theme-changed` event. Provide small wrappers so that further users do not have to repeat the window/document lookup and the JS error conversion. Signed-off-by: Dominik Csapak --- src/state/event.rs | 24 ++++++++++++++++++++++++ src/state/mod.rs | 3 +++ 2 files changed, 27 insertions(+) create mode 100644 src/state/event.rs diff --git a/src/state/event.rs b/src/state/event.rs new file mode 100644 index 0000000..8566071 --- /dev/null +++ b/src/state/event.rs @@ -0,0 +1,24 @@ +//! Helpers to create and dispatch custom DOM events. + +use anyhow::{Error, format_err}; +use web_sys::Event; + +/// Create a custom [Event] with the given name. +pub fn create_custom_event(name: &str) -> Result { + Event::new(name).map_err(crate::convert_js_error) +} + +/// Dispatch a custom event with the given name on the document. +/// +/// The event is only delivered to listeners in the current document, so listeners in other +/// browser tabs or windows are not notified. +pub fn dispatch_custom_event(name: &str) -> Result<(), Error> { + let document = web_sys::window() + .and_then(|window| window.document()) + .ok_or_else(|| format_err!("no document available"))?; + + document + .dispatch_event(&create_custom_event(name)?) + .map(|_| ()) + .map_err(crate::convert_js_error) +} diff --git a/src/state/mod.rs b/src/state/mod.rs index 86d6b7f..6f99c7e 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -7,6 +7,9 @@ use serde::{Serialize, de::DeserializeOwned}; mod data_store; pub use data_store::{DataNode, DataNodeDerefGuard, DataStore}; +mod event; +pub use event::{create_custom_event, dispatch_custom_event}; + mod loader; pub use loader::{Loader, LoaderState}; -- 2.47.3