Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and stablize the Clipboard API #3992

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
* Annotated methods in WebCodecs that throw.
[#3970](https://github.com/rustwasm/wasm-bindgen/pull/3970)

* Update and stabilize the Clipboard API.
[#3992](https://github.com/rustwasm/wasm-bindgen/pull/3992)

### Fixed

* Copy port from headless test server when using `WASM_BINDGEN_TEST_ADDRESS`.
Expand Down
1 change: 1 addition & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ ClipboardEventInit = []
ClipboardItem = []
ClipboardItemOptions = []
ClipboardPermissionDescriptor = []
ClipboardUnsanitizedFormats = []
CloseEvent = ["Event"]
CloseEventInit = []
CodecState = []
Expand Down
31 changes: 13 additions & 18 deletions crates/web-sys/src/features/gen_Clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = EventTarget , extends = :: js_sys :: Object , js_name = Clipboard , typescript_type = "Clipboard")]
Expand All @@ -12,52 +11,48 @@ extern "C" {
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type Clipboard;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = read)]
#[doc = "The `read()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`*"]
pub fn read(this: &Clipboard) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "ClipboardUnsanitizedFormats")]
# [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = read)]
#[doc = "The `read()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`, `ClipboardUnsanitizedFormats`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn read(this: &Clipboard) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
pub fn read_with_formats(
this: &Clipboard,
formats: &ClipboardUnsanitizedFormats,
) -> ::js_sys::Promise;
# [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = readText)]
#[doc = "The `readText()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/readText)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn read_text(this: &Clipboard) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = write)]
#[doc = "The `write()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn write(this: &Clipboard, data: &::wasm_bindgen::JsValue) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "Clipboard" , js_name = writeText)]
#[doc = "The `writeText()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn write_text(this: &Clipboard, data: &str) -> ::js_sys::Promise;
}
45 changes: 7 additions & 38 deletions crates/web-sys/src/features/gen_ClipboardItem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardItem , typescript_type = "ClipboardItem")]
Expand All @@ -12,64 +11,34 @@ extern "C" {
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type ClipboardItem;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "PresentationStyle")]
# [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = presentationStyle)]
#[doc = "Getter for the `presentationStyle` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/presentationStyle)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`, `PresentationStyle`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn presentation_style(this: &ClipboardItem) -> PresentationStyle;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = lastModified)]
#[doc = "Getter for the `lastModified` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/lastModified)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn last_modified(this: &ClipboardItem) -> f64;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = delayed)]
#[doc = "Getter for the `delayed` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/delayed)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn delayed(this: &ClipboardItem) -> bool;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "ClipboardItem" , js_name = types)]
#[doc = "Getter for the `types` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/types)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn types(this: &ClipboardItem) -> ::js_sys::Array;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "ClipboardItem" , js_name = getType)]
#[doc = "The `getType()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/getType)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_type(this: &ClipboardItem, type_: &str) -> ::js_sys::Promise;
# [wasm_bindgen (static_method_of = ClipboardItem , js_class = "ClipboardItem" , js_name = supports)]
#[doc = "The `supports()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/supports)"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link is generated, so that would have to be fixed in the generator.
It would be interesting to see if that is an exception for this specific static method or if this actually fixes a bug in the generator.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #4010.

#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItem`*"]
pub fn supports(type_: &str) -> bool;
}
13 changes: 0 additions & 13 deletions crates/web-sys/src/features/gen_ClipboardItemOptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,36 @@
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardItemOptions)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ClipboardItemOptions` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItemOptions`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type ClipboardItemOptions;
#[cfg(feature = "PresentationStyle")]
#[wasm_bindgen(method, setter = "presentationStyle")]
fn presentation_style_shim(this: &ClipboardItemOptions, val: PresentationStyle);
}
#[cfg(web_sys_unstable_apis)]
impl ClipboardItemOptions {
#[doc = "Construct a new `ClipboardItemOptions`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItemOptions`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "PresentationStyle")]
#[doc = "Change the `presentationStyle` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardItemOptions`, `PresentationStyle`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn presentation_style(&mut self, val: PresentationStyle) -> &mut Self {
self.presentation_style_shim(val);
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for ClipboardItemOptions {
fn default() -> Self {
Self::new()
Expand Down
50 changes: 50 additions & 0 deletions crates/web-sys/src/features/gen_ClipboardUnsanitizedFormats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = ClipboardUnsanitizedFormats)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `ClipboardUnsanitizedFormats` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardUnsanitizedFormats`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type ClipboardUnsanitizedFormats;
#[wasm_bindgen(method, setter = "unsanitized")]
fn unsanitized_shim(this: &ClipboardUnsanitizedFormats, val: &::wasm_bindgen::JsValue);
}
#[cfg(web_sys_unstable_apis)]
impl ClipboardUnsanitizedFormats {
#[doc = "Construct a new `ClipboardUnsanitizedFormats`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardUnsanitizedFormats`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `unsanitized` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `ClipboardUnsanitizedFormats`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn unsanitized(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
self.unsanitized_shim(val);
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for ClipboardUnsanitizedFormats {
fn default() -> Self {
Self::new()
}
}
20 changes: 8 additions & 12 deletions crates/web-sys/src/features/gen_Navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ extern "C" {
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Navigator`*"]
pub type Navigator;
#[cfg(feature = "Clipboard")]
# [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = clipboard)]
#[doc = "Getter for the `clipboard` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`, `Navigator`*"]
pub fn clipboard(this: &Navigator) -> Clipboard;
#[cfg(feature = "Permissions")]
# [wasm_bindgen (structural , catch , method , getter , js_class = "Navigator" , js_name = permissions)]
#[doc = "Getter for the `permissions` field of this object."]
Expand Down Expand Up @@ -126,18 +134,6 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn bluetooth(this: &Navigator) -> Option<Bluetooth>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "Clipboard")]
# [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = clipboard)]
#[doc = "Getter for the `clipboard` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Clipboard`, `Navigator`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn clipboard(this: &Navigator) -> Option<Clipboard>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "MediaSession")]
# [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = mediaSession)]
#[doc = "Getter for the `mediaSession` field of this object."]
Expand Down
4 changes: 0 additions & 4 deletions crates/web-sys/src/features/gen_PresentationStyle.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `PresentationStyle` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `PresentationStyle`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PresentationStyle {
Unspecified = "unspecified",
Expand Down
7 changes: 7 additions & 0 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,13 @@ mod gen_ClipboardPermissionDescriptor;
#[allow(unused_imports)]
pub use gen_ClipboardPermissionDescriptor::*;

#[cfg(feature = "ClipboardUnsanitizedFormats")]
#[allow(non_snake_case)]
mod gen_ClipboardUnsanitizedFormats;
#[cfg(feature = "ClipboardUnsanitizedFormats")]
#[allow(unused_imports)]
pub use gen_ClipboardUnsanitizedFormats::*;

#[cfg(feature = "CloseEvent")]
#[allow(non_snake_case)]
mod gen_CloseEvent;
Expand Down
54 changes: 54 additions & 0 deletions crates/web-sys/webidls/enabled/Clipboard.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Clipboard API and events
* Editor’s Draft, 4 June 2024
*
* The origin of this IDL file is:
* https://w3c.github.io/clipboard-apis/#idl-index
*/

dictionary ClipboardEventInit : EventInit {
DataTransfer? clipboardData = null;
};

[Exposed=Window]
interface ClipboardEvent : Event {
constructor(DOMString type, optional ClipboardEventInit eventInitDict = {});
readonly attribute DataTransfer? clipboardData;
};

partial interface Navigator {
[SecureContext, SameObject] readonly attribute Clipboard clipboard;
};

typedef Promise<(DOMString or Blob)> ClipboardItemData;

[SecureContext, Exposed=Window]
interface ClipboardItem {
[Throws]
constructor(record<DOMString, ClipboardItemData> items,
optional ClipboardItemOptions options = {});

readonly attribute PresentationStyle presentationStyle;
readonly attribute FrozenArray<DOMString> types;

Promise<Blob> getType(DOMString type);

static boolean supports(DOMString type);
};

enum PresentationStyle { "unspecified", "inline", "attachment" };

dictionary ClipboardItemOptions {
PresentationStyle presentationStyle = "unspecified";
};

typedef sequence<ClipboardItem> ClipboardItems;

[SecureContext, Exposed=Window]
interface Clipboard : EventTarget {
Promise<ClipboardItems> read(optional ClipboardUnsanitizedFormats formats = {});
Promise<DOMString> readText();
Promise<undefined> write(ClipboardItems data);
Promise<undefined> writeText(DOMString data);
};
Loading