[pdm-devel] [PATCH yew-comp v2 1/2] utils/tfa add recover/token panel: add copy_text_to_clipboard function

Shannon Sterz s.sterz at proxmox.com
Fri Oct 17 12:43:09 CEST 2025


On Fri Oct 17, 2025 at 11:35 AM CEST, Lukas Wagner wrote:
> The 'utils' module is getting quite large by now with many different
> kinds of helpers, maybe it is time to actually start splitting these out
> into distinct modules? For instance, in this patch series,
> you could create a new 'clipboard' module, moving *both* functions there
> and then adding a 'pub use' in 'utils' for the old, deprecated function
> for compatibility?

not opposed to that, but we might want to think about how to do that a
bit more in-depth. not sure how we want to split those up exactly.
might be better handled as a separate clean-up series for yew-comp?

> Apart from this and the minor nit below, consider this:
>
> Tested-by: Lukas Wagner <l.wagner at proxmox.com>
> Reviewed-by: Lukas Wagner <l.wagner at proxmox.com>
>
> On Tue Oct 14, 2025 at 4:37 PM CEST, Shannon Sterz wrote:
>> diff --git a/src/utils.rs b/src/utils.rs
>> index 3dfc696..f4db098 100644
>> --- a/src/utils.rs
>> +++ b/src/utils.rs
>> @@ -2,6 +2,7 @@ use std::collections::HashMap;
>>  use std::fmt::Display;
>>  use std::sync::Mutex;
>>
>> +use pwt::convert_js_error;
>>  use serde_json::Value;
>>  use wasm_bindgen::JsCast;
>>  use yew::prelude::*;
>> @@ -338,6 +339,9 @@ pub fn json_array_to_flat_string(list: &[Value]) -> String {
>>      list.join(" ")
>>  }
>>
>> +#[deprecated(
>> +    note = "This relies on the deprecated `execCommand` method. Please use `utils::copy_text_to_clipboard` instead."
>> +)]
>>  pub fn copy_to_clipboard(node_ref: &NodeRef) {
>>      if let Some(el) = node_ref.cast::<web_sys::HtmlInputElement>() {
>>          let window = gloo_utils::window();
>> @@ -356,6 +360,24 @@ pub fn copy_to_clipboard(node_ref: &NodeRef) {
>>      }
>>  }
>>
>
> Missing doc comments for a `pub` function.
>

ah true, should be

/// Copies `text` to the user's clipboard via the `Clipboard` API.
>> +pub fn copy_text_to_clipboard(text: &str) {
>> +    let text = text.to_owned();
>> +
>> +    wasm_bindgen_futures::spawn_local(async move {
>> +        let future: wasm_bindgen_futures::JsFuture = gloo_utils::window()
>> +            .navigator()
>> +            .clipboard()
>> +            .write_text(&text)
>> +            .into();
>> +
>> +        let res = future.await.map_err(convert_js_error);
>> +
>> +        if let Err(e) = res {
>> +            log::error!("could not copy to clipboard: {e:#}");
>> +        }
>> +    });
>> +}
>> +
>>  /// Set the browser window.location.href
>>  pub fn set_location_href(href: &str) {
>>      let window = gloo_utils::window();
>
>
>
> _______________________________________________
> pdm-devel mailing list
> pdm-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel





More information about the pdm-devel mailing list