@tauri-apps/plugin-clipboard-manager 2.0.0-beta.1 → 2.1.0-beta.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 +1 -1
- package/dist-js/index.cjs +86 -2
- package/dist-js/index.d.ts +59 -1
- package/dist-js/index.js +83 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -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,7 +25,7 @@ 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|
|
|
28
|
+
return core.invoke("plugin:clipboard-manager|write_text", {
|
|
28
29
|
data: {
|
|
29
30
|
plainText: {
|
|
30
31
|
label: opts?.label,
|
|
@@ -43,9 +44,92 @@ async function writeText(text, opts) {
|
|
|
43
44
|
* @since 2.0.0
|
|
44
45
|
*/
|
|
45
46
|
async function readText() {
|
|
46
|
-
const kind = await core.invoke("plugin:clipboard-manager|
|
|
47
|
+
const kind = await core.invoke("plugin:clipboard-manager|read_text");
|
|
47
48
|
return kind.plainText.text;
|
|
48
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets the clipboard content as Uint8Array image.
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { readImage } from '@tauri-apps/plugin-clipboard-manager';
|
|
55
|
+
*
|
|
56
|
+
* const clipboardImage = await readImage();
|
|
57
|
+
* const blob = new Blob([clipboardImage.bytes], { type: 'image' })
|
|
58
|
+
* const url = URL.createObjectURL(blob)
|
|
59
|
+
* ```
|
|
60
|
+
* @since 2.0.0
|
|
61
|
+
*/
|
|
62
|
+
async function readImage() {
|
|
63
|
+
return await core.invoke("plugin:clipboard-manager|read_image").then((rid) => new image.Image(rid));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Writes image buffer to the clipboard.
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
|
|
70
|
+
* const buffer = [
|
|
71
|
+
* // A red pixel
|
|
72
|
+
* 255, 0, 0, 255,
|
|
73
|
+
*
|
|
74
|
+
* // A green pixel
|
|
75
|
+
* 0, 255, 0, 255,
|
|
76
|
+
* ];
|
|
77
|
+
* await writeImage(buffer);
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
80
|
+
*
|
|
81
|
+
* @since 2.0.0
|
|
82
|
+
*/
|
|
83
|
+
async function writeImage(image$1) {
|
|
84
|
+
return core.invoke("plugin:clipboard-manager|write_image", {
|
|
85
|
+
data: {
|
|
86
|
+
image: {
|
|
87
|
+
image: image.transformImage(image$1),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* * Writes HTML or fallbacks to write provided plain text to the clipboard.
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager';
|
|
97
|
+
* await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');
|
|
98
|
+
* await writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>'); // Will write "<h1>Tauri is awesome</h1>" as plain text
|
|
99
|
+
* assert(await readText(), '<h1>Tauri is awesome!</h1>');
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
103
|
+
*
|
|
104
|
+
* @since 2.0.0
|
|
105
|
+
*/
|
|
106
|
+
async function writeHtml(html, altHtml) {
|
|
107
|
+
return core.invoke("plugin:clipboard-manager|write_html", {
|
|
108
|
+
data: {
|
|
109
|
+
html: {
|
|
110
|
+
html,
|
|
111
|
+
altHtml,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Clears the clipboard.
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { clear } from '@tauri-apps/plugin-clipboard-manager';
|
|
121
|
+
* await clear();
|
|
122
|
+
* ```
|
|
123
|
+
* @since 2.0.0
|
|
124
|
+
*/
|
|
125
|
+
async function clear() {
|
|
126
|
+
await core.invoke("plugin:clipboard-manager|clear");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
49
129
|
|
|
130
|
+
exports.clear = clear;
|
|
131
|
+
exports.readImage = readImage;
|
|
50
132
|
exports.readText = readText;
|
|
133
|
+
exports.writeHtml = writeHtml;
|
|
134
|
+
exports.writeImage = writeImage;
|
|
51
135
|
exports.writeText = writeText;
|
package/dist-js/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Gets the clipboard content as Uint8Array image.
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { readImage } from '@tauri-apps/plugin-clipboard-manager';
|
|
33
|
+
*
|
|
34
|
+
* const clipboardImage = await readImage();
|
|
35
|
+
* const blob = new Blob([clipboardImage.bytes], { type: 'image' })
|
|
36
|
+
* const url = URL.createObjectURL(blob)
|
|
37
|
+
* ```
|
|
38
|
+
* @since 2.0.0
|
|
39
|
+
*/
|
|
40
|
+
declare function readImage(): Promise<Image>;
|
|
41
|
+
/**
|
|
42
|
+
* Writes image buffer to the clipboard.
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
|
|
46
|
+
* const buffer = [
|
|
47
|
+
* // A red pixel
|
|
48
|
+
* 255, 0, 0, 255,
|
|
49
|
+
*
|
|
50
|
+
* // A green pixel
|
|
51
|
+
* 0, 255, 0, 255,
|
|
52
|
+
* ];
|
|
53
|
+
* await writeImage(buffer);
|
|
54
|
+
*
|
|
55
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
56
|
+
*
|
|
57
|
+
* @since 2.0.0
|
|
58
|
+
*/
|
|
59
|
+
declare function writeImage(image: string | Image | Uint8Array | ArrayBuffer | number[]): Promise<void>;
|
|
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 { Image, transformImage } 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,7 +23,7 @@ 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|
|
|
26
|
+
return invoke("plugin:clipboard-manager|write_text", {
|
|
26
27
|
data: {
|
|
27
28
|
plainText: {
|
|
28
29
|
label: opts?.label,
|
|
@@ -41,8 +42,87 @@ async function writeText(text, opts) {
|
|
|
41
42
|
* @since 2.0.0
|
|
42
43
|
*/
|
|
43
44
|
async function readText() {
|
|
44
|
-
const kind = await invoke("plugin:clipboard-manager|
|
|
45
|
+
const kind = await invoke("plugin:clipboard-manager|read_text");
|
|
45
46
|
return kind.plainText.text;
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the clipboard content as Uint8Array image.
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { readImage } from '@tauri-apps/plugin-clipboard-manager';
|
|
53
|
+
*
|
|
54
|
+
* const clipboardImage = await readImage();
|
|
55
|
+
* const blob = new Blob([clipboardImage.bytes], { type: 'image' })
|
|
56
|
+
* const url = URL.createObjectURL(blob)
|
|
57
|
+
* ```
|
|
58
|
+
* @since 2.0.0
|
|
59
|
+
*/
|
|
60
|
+
async function readImage() {
|
|
61
|
+
return await invoke("plugin:clipboard-manager|read_image").then((rid) => new Image(rid));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Writes image buffer to the clipboard.
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { writeImage } from '@tauri-apps/plugin-clipboard-manager';
|
|
68
|
+
* const buffer = [
|
|
69
|
+
* // A red pixel
|
|
70
|
+
* 255, 0, 0, 255,
|
|
71
|
+
*
|
|
72
|
+
* // A green pixel
|
|
73
|
+
* 0, 255, 0, 255,
|
|
74
|
+
* ];
|
|
75
|
+
* await writeImage(buffer);
|
|
76
|
+
*
|
|
77
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
78
|
+
*
|
|
79
|
+
* @since 2.0.0
|
|
80
|
+
*/
|
|
81
|
+
async function writeImage(image) {
|
|
82
|
+
return invoke("plugin:clipboard-manager|write_image", {
|
|
83
|
+
data: {
|
|
84
|
+
image: {
|
|
85
|
+
image: transformImage(image),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* * Writes HTML or fallbacks to write provided plain text to the clipboard.
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { writeHtml, readHtml } from '@tauri-apps/plugin-clipboard-manager';
|
|
95
|
+
* await writeHtml('<h1>Tauri is awesome!</h1>', 'plaintext');
|
|
96
|
+
* await writeHtml('<h1>Tauri is awesome!</h1>', '<h1>Tauri is awesome</h1>'); // Will write "<h1>Tauri is awesome</h1>" as plain text
|
|
97
|
+
* assert(await readText(), '<h1>Tauri is awesome!</h1>');
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
101
|
+
*
|
|
102
|
+
* @since 2.0.0
|
|
103
|
+
*/
|
|
104
|
+
async function writeHtml(html, altHtml) {
|
|
105
|
+
return invoke("plugin:clipboard-manager|write_html", {
|
|
106
|
+
data: {
|
|
107
|
+
html: {
|
|
108
|
+
html,
|
|
109
|
+
altHtml,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Clears the clipboard.
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { clear } from '@tauri-apps/plugin-clipboard-manager';
|
|
119
|
+
* await clear();
|
|
120
|
+
* ```
|
|
121
|
+
* @since 2.0.0
|
|
122
|
+
*/
|
|
123
|
+
async function clear() {
|
|
124
|
+
await invoke("plugin:clipboard-manager|clear");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
47
127
|
|
|
48
|
-
export { readText, writeText };
|
|
128
|
+
export { clear, readImage, readText, writeHtml, writeImage, writeText };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tauri-apps/plugin-clipboard-manager",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0-beta.0",
|
|
4
4
|
"license": "MIT or APACHE-2.0",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Tauri Programme within The Commons Conservancy"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tauri-apps/api": "2.0.0-beta.
|
|
23
|
+
"@tauri-apps/api": "2.0.0-beta.6"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "rollup -c"
|