Skip to content

Commit

Permalink
Update and stabilize widely supported parts of the Clipboard API
Browse files Browse the repository at this point in the history
  • Loading branch information
evilpie committed Jun 30, 2024
1 parent ad82651 commit 6fcf2d4
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 207 deletions.
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 widely supported parts of 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: 0 additions & 1 deletion crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ ClipboardEvent = ["Event"]
ClipboardEventInit = []
ClipboardItem = []
ClipboardItemOptions = []
ClipboardPermissionDescriptor = []
CloseEvent = ["Event"]
CloseEventInit = []
CodecState = []
Expand Down
20 changes: 0 additions & 20 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,33 @@ 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`*"]
#[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)]
# [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;
}
38 changes: 0 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,27 @@ 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;
}
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
61 changes: 0 additions & 61 deletions crates/web-sys/src/features/gen_ClipboardPermissionDescriptor.rs

This file was deleted.

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: 0 additions & 7 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,6 @@ mod gen_ClipboardItemOptions;
#[allow(unused_imports)]
pub use gen_ClipboardItemOptions::*;

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

#[cfg(feature = "CloseEvent")]
#[allow(non_snake_case)]
mod gen_CloseEvent;
Expand Down
55 changes: 55 additions & 0 deletions crates/web-sys/webidls/enabled/Clipboard.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* -*- 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
*/

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

typedef Promise<(DOMString or Blob)> ClipboardItemData;

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

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

Promise<Blob> getType(DOMString type);

// Not supported by WebKit
// 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);
};

// There is no consensus by browsers to implement this API.
// See https://github.com/w3c/clipboard-apis/pull/197.
// dictionary ClipboardUnsanitizedFormats {
// sequence<DOMString> unsanitized;
// };

// Also Chrome-only
// dictionary ClipboardPermissionDescriptor : PermissionDescriptor {
// boolean allowWithoutGesture = false;
// };
Loading

0 comments on commit 6fcf2d4

Please sign in to comment.