@tauri-apps/plugin-clipboard-manager 2.0.0-beta.1 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
18
18
 
19
19
  ```toml
20
20
  [dependencies]
21
- tauri-plugin-clipboard-manager = "2.0.0-beta"
21
+ tauri-plugin-clipboard-manager = "2.0.0-rc"
22
22
  # alternatively with Git:
23
23
  tauri-plugin-clipboard-manager = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
24
24
  ```
@@ -60,7 +60,7 @@ fn main() {
60
60
  Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
61
61
 
62
62
  ```javascript
63
- import { writeText, readText } from "@tauri-apps/plugin-clipboard-manager";
63
+ import { writeText, readText, writeHtml, readHtml, clear } from "@tauri-apps/plugin-clipboard-manager";
64
64
  await writeText("Tauri is awesome!");
65
65
  assert(await readText(), "Tauri is awesome!");
66
66
  ```
package/dist-js/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@tauri-apps/api/core');
4
+ var image = require('@tauri-apps/api/image');
4
5
 
5
6
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
6
7
  // SPDX-License-Identifier: Apache-2.0
@@ -24,13 +25,9 @@ var core = require('@tauri-apps/api/core');
24
25
  * @since 2.0.0
25
26
  */
26
27
  async function writeText(text, opts) {
27
- return core.invoke("plugin:clipboard-manager|write", {
28
- data: {
29
- plainText: {
30
- label: opts?.label,
31
- text,
32
- },
33
- },
28
+ await core.invoke("plugin:clipboard-manager|write_text", {
29
+ label: opts?.label,
30
+ text,
34
31
  });
35
32
  }
36
33
  /**
@@ -43,9 +40,82 @@ async function writeText(text, opts) {
43
40
  * @since 2.0.0
44
41
  */
45
42
  async function readText() {
46
- const kind = await core.invoke("plugin:clipboard-manager|read");
47
- return kind.plainText.text;
43
+ return await core.invoke("plugin:clipboard-manager|read_text");
44
+ }
45
+ /**
46
+ * Writes image buffer to the clipboard.
47
+ * @example
48
+ * ```typescript
49
+ * import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
50
+ * const buffer = [
51
+ * // A red pixel
52
+ * 255, 0, 0, 255,
53
+ *
54
+ * // A green pixel
55
+ * 0, 255, 0, 255,
56
+ * ];
57
+ * await writeImage(buffer);
58
+ *
59
+ * @returns A promise indicating the success or failure of the operation.
60
+ *
61
+ * @since 2.0.0
62
+ */
63
+ async function writeImage(image$1) {
64
+ await core.invoke("plugin:clipboard-manager|write_image", {
65
+ image: image.transformImage(image$1),
66
+ });
67
+ }
68
+ /**
69
+ * Gets the clipboard content as Uint8Array image.
70
+ * @example
71
+ * ```typescript
72
+ * import { readImage } from '@tauri-apps/plugin-clipboard-manager';
73
+ *
74
+ * const clipboardImage = await readImage();
75
+ * const blob = new Blob([clipboardImage.bytes], { type: 'image' })
76
+ * const url = URL.createObjectURL(blob)
77
+ * ```
78
+ * @since 2.0.0
79
+ */
80
+ async function readImage() {
81
+ return await core.invoke("plugin:clipboard-manager|read_image").then((rid) => new image.Image(rid));
82
+ }
83
+ /**
84
+ * * Writes HTML or fallbacks to write provided plain text to the clipboard.
85
+ * @example
86
+ * ```typescript
87
+ * import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager';
88
+ * await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');
89
+ * await writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>'); // Will write "<h1>Tauri is awesome</h1>" as plain text
90
+ * assert(await readText(), '<h1>Tauri is awesome!</h1>');
91
+ * ```
92
+ *
93
+ * @returns A promise indicating the success or failure of the operation.
94
+ *
95
+ * @since 2.0.0
96
+ */
97
+ async function writeHtml(html, altHtml) {
98
+ await core.invoke("plugin:clipboard-manager|write_html", {
99
+ html,
100
+ altHtml,
101
+ });
102
+ }
103
+ /**
104
+ * Clears the clipboard.
105
+ * @example
106
+ * ```typescript
107
+ * import { clear } from '@tauri-apps/plugin-clipboard-manager';
108
+ * await clear();
109
+ * ```
110
+ * @since 2.0.0
111
+ */
112
+ async function clear() {
113
+ await core.invoke("plugin:clipboard-manager|clear");
48
114
  }
49
115
 
116
+ exports.clear = clear;
117
+ exports.readImage = readImage;
50
118
  exports.readText = readText;
119
+ exports.writeHtml = writeHtml;
120
+ exports.writeImage = writeImage;
51
121
  exports.writeText = writeText;
@@ -1,3 +1,4 @@
1
+ import { Image } from "@tauri-apps/api/image";
1
2
  /**
2
3
  * Writes plain text to the clipboard.
3
4
  * @example
@@ -24,4 +25,61 @@ declare function writeText(text: string, opts?: {
24
25
  * @since 2.0.0
25
26
  */
26
27
  declare function readText(): Promise<string>;
27
- export { writeText, readText };
28
+ /**
29
+ * Writes image buffer to the clipboard.
30
+ * @example
31
+ * ```typescript
32
+ * import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
33
+ * const buffer = [
34
+ * // A red pixel
35
+ * 255, 0, 0, 255,
36
+ *
37
+ * // A green pixel
38
+ * 0, 255, 0, 255,
39
+ * ];
40
+ * await writeImage(buffer);
41
+ *
42
+ * @returns A promise indicating the success or failure of the operation.
43
+ *
44
+ * @since 2.0.0
45
+ */
46
+ declare function writeImage(image: string | Image | Uint8Array | ArrayBuffer | number[]): Promise<void>;
47
+ /**
48
+ * Gets the clipboard content as Uint8Array image.
49
+ * @example
50
+ * ```typescript
51
+ * import { readImage } from '@tauri-apps/plugin-clipboard-manager';
52
+ *
53
+ * const clipboardImage = await readImage();
54
+ * const blob = new Blob([clipboardImage.bytes], { type: 'image' })
55
+ * const url = URL.createObjectURL(blob)
56
+ * ```
57
+ * @since 2.0.0
58
+ */
59
+ declare function readImage(): Promise<Image>;
60
+ /**
61
+ * * Writes HTML or fallbacks to write provided plain text to the clipboard.
62
+ * @example
63
+ * ```typescript
64
+ * import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager';
65
+ * await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');
66
+ * await writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>'); // Will write "<h1>Tauri is awesome</h1>" as plain text
67
+ * assert(await readText(), '<h1>Tauri is awesome!</h1>');
68
+ * ```
69
+ *
70
+ * @returns A promise indicating the success or failure of the operation.
71
+ *
72
+ * @since 2.0.0
73
+ */
74
+ declare function writeHtml(html: string, altHtml?: string): Promise<void>;
75
+ /**
76
+ * Clears the clipboard.
77
+ * @example
78
+ * ```typescript
79
+ * import { clear } from '@tauri-apps/plugin-clipboard-manager';
80
+ * await clear();
81
+ * ```
82
+ * @since 2.0.0
83
+ */
84
+ declare function clear(): Promise<void>;
85
+ export { writeText, readText, writeHtml, clear, readImage, writeImage };
package/dist-js/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { invoke } from '@tauri-apps/api/core';
2
+ import { transformImage, Image } from '@tauri-apps/api/image';
2
3
 
3
4
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
4
5
  // SPDX-License-Identifier: Apache-2.0
@@ -22,13 +23,9 @@ import { invoke } from '@tauri-apps/api/core';
22
23
  * @since 2.0.0
23
24
  */
24
25
  async function writeText(text, opts) {
25
- return invoke("plugin:clipboard-manager|write", {
26
- data: {
27
- plainText: {
28
- label: opts?.label,
29
- text,
30
- },
31
- },
26
+ await invoke("plugin:clipboard-manager|write_text", {
27
+ label: opts?.label,
28
+ text,
32
29
  });
33
30
  }
34
31
  /**
@@ -41,8 +38,77 @@ async function writeText(text, opts) {
41
38
  * @since 2.0.0
42
39
  */
43
40
  async function readText() {
44
- const kind = await invoke("plugin:clipboard-manager|read");
45
- return kind.plainText.text;
41
+ return await invoke("plugin:clipboard-manager|read_text");
42
+ }
43
+ /**
44
+ * Writes image buffer to the clipboard.
45
+ * @example
46
+ * ```typescript
47
+ * import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
48
+ * const buffer = [
49
+ * // A red pixel
50
+ * 255, 0, 0, 255,
51
+ *
52
+ * // A green pixel
53
+ * 0, 255, 0, 255,
54
+ * ];
55
+ * await writeImage(buffer);
56
+ *
57
+ * @returns A promise indicating the success or failure of the operation.
58
+ *
59
+ * @since 2.0.0
60
+ */
61
+ async function writeImage(image) {
62
+ await invoke("plugin:clipboard-manager|write_image", {
63
+ image: transformImage(image),
64
+ });
65
+ }
66
+ /**
67
+ * Gets the clipboard content as Uint8Array image.
68
+ * @example
69
+ * ```typescript
70
+ * import { readImage } from '@tauri-apps/plugin-clipboard-manager';
71
+ *
72
+ * const clipboardImage = await readImage();
73
+ * const blob = new Blob([clipboardImage.bytes], { type: 'image' })
74
+ * const url = URL.createObjectURL(blob)
75
+ * ```
76
+ * @since 2.0.0
77
+ */
78
+ async function readImage() {
79
+ return await invoke("plugin:clipboard-manager|read_image").then((rid) => new Image(rid));
80
+ }
81
+ /**
82
+ * * Writes HTML or fallbacks to write provided plain text to the clipboard.
83
+ * @example
84
+ * ```typescript
85
+ * import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager';
86
+ * await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');
87
+ * await writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>'); // Will write "<h1>Tauri is awesome</h1>" as plain text
88
+ * assert(await readText(), '<h1>Tauri is awesome!</h1>');
89
+ * ```
90
+ *
91
+ * @returns A promise indicating the success or failure of the operation.
92
+ *
93
+ * @since 2.0.0
94
+ */
95
+ async function writeHtml(html, altHtml) {
96
+ await invoke("plugin:clipboard-manager|write_html", {
97
+ html,
98
+ altHtml,
99
+ });
100
+ }
101
+ /**
102
+ * Clears the clipboard.
103
+ * @example
104
+ * ```typescript
105
+ * import { clear } from '@tauri-apps/plugin-clipboard-manager';
106
+ * await clear();
107
+ * ```
108
+ * @since 2.0.0
109
+ */
110
+ async function clear() {
111
+ await invoke("plugin:clipboard-manager|clear");
46
112
  }
47
113
 
48
- export { readText, writeText };
114
+ export { clear, readImage, readText, writeHtml, writeImage, writeText };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-clipboard-manager",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-rc.0",
4
4
  "license": "MIT or APACHE-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"
7
7
  ],
8
+ "repository": "https://github.com/tauri-apps/plugins-workspace",
8
9
  "type": "module",
9
10
  "types": "./dist-js/index.d.ts",
10
11
  "main": "./dist-js/index.cjs",
@@ -14,15 +15,15 @@
14
15
  "import": "./dist-js/index.js",
15
16
  "require": "./dist-js/index.cjs"
16
17
  },
18
+ "scripts": {
19
+ "build": "rollup -c"
20
+ },
17
21
  "files": [
18
22
  "dist-js",
19
23
  "README.md",
20
24
  "LICENSE"
21
25
  ],
22
26
  "dependencies": {
23
- "@tauri-apps/api": "2.0.0-beta.2"
24
- },
25
- "scripts": {
26
- "build": "rollup -c"
27
+ "@tauri-apps/api": "^2.0.0-rc.0"
27
28
  }
28
- }
29
+ }