@bbn/bbn 1.0.385 → 1.0.386
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/dist/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/fn/browser/copy.d.ts +1 -14
- package/dist/fn/browser/copy.js +22 -2
- package/package.json +1 -1
|
@@ -1,14 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copies to the clipboard the value of the given string.
|
|
3
|
-
* @method copy
|
|
4
|
-
* @global
|
|
5
|
-
* ``` javascript
|
|
6
|
-
* let myVal = 'the value you want to copy to clipbord';
|
|
7
|
-
* bbn.fn.copy(myVal);
|
|
8
|
-
*
|
|
9
|
-
* ```
|
|
10
|
-
* @memberof bbn.fn
|
|
11
|
-
* @param {String} st The string to copy.
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export default function copy(st: any): Promise<unknown>;
|
|
1
|
+
export default function copy(st: any, dispatch: any): Promise<unknown>;
|
package/dist/fn/browser/copy.js
CHANGED
|
@@ -13,7 +13,17 @@ import isFunction from '../type/isFunction.js';
|
|
|
13
13
|
* @param {String} st The string to copy.
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
var fire = function (st) {
|
|
17
|
+
var transfer = new DataTransfer();
|
|
18
|
+
transfer.setData("text/plain", st);
|
|
19
|
+
var copyEvent = new ClipboardEvent('copy', {
|
|
20
|
+
bubbles: true,
|
|
21
|
+
cancelable: true,
|
|
22
|
+
clipboardData: transfer
|
|
23
|
+
});
|
|
24
|
+
document.dispatchEvent(copyEvent);
|
|
25
|
+
};
|
|
26
|
+
export default function copy(st, dispatch) {
|
|
17
27
|
return new Promise(function (resolve) {
|
|
18
28
|
var _a;
|
|
19
29
|
if (st) {
|
|
@@ -26,13 +36,20 @@ export default function copy(st) {
|
|
|
26
36
|
else if (isObject(st) && isFunction(st.toBlob)) {
|
|
27
37
|
st.toBlob(function (blob) {
|
|
28
38
|
var _a;
|
|
29
|
-
|
|
39
|
+
var item = new ClipboardItem((_a = {}, _a[blob.type.toString()] = blob, _a));
|
|
40
|
+
navigator.clipboard.write([item]).then(function () {
|
|
41
|
+
if (dispatch) {
|
|
42
|
+
fire(st);
|
|
43
|
+
}
|
|
30
44
|
resolve(true);
|
|
31
45
|
});
|
|
32
46
|
});
|
|
33
47
|
}
|
|
34
48
|
else {
|
|
35
49
|
navigator.clipboard.writeText(st);
|
|
50
|
+
if (dispatch) {
|
|
51
|
+
fire(st);
|
|
52
|
+
}
|
|
36
53
|
resolve(true);
|
|
37
54
|
}
|
|
38
55
|
return;
|
|
@@ -44,6 +61,9 @@ export default function copy(st) {
|
|
|
44
61
|
input.select();
|
|
45
62
|
document.execCommand('copy');
|
|
46
63
|
document.body.removeChild(input);
|
|
64
|
+
if (dispatch) {
|
|
65
|
+
fire(st);
|
|
66
|
+
}
|
|
47
67
|
resolve(true);
|
|
48
68
|
}
|
|
49
69
|
resolve(false);
|