cavalion-js 1.0.81 → 1.0.82
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/CHANGELOG.md +5 -1
- package/package.json +1 -1
- package/src/util/Clipboard.js +47 -0
- package/src/util/Text.js +1 -6
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
define([], () => ({
|
|
2
|
+
copy: (text) => {
|
|
3
|
+
// Use the Async Clipboard API when available. Requires a secure browsing
|
|
4
|
+
// context (i.e. HTTPS)
|
|
5
|
+
if (navigator.clipboard) {
|
|
6
|
+
return navigator.clipboard.writeText(text).then(() => text).
|
|
7
|
+
catch(function (err) {
|
|
8
|
+
throw (err !== undefined ? err : new DOMException('The request is not allowed', 'NotAllowedError'))
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// ...Otherwise, use document.execCommand() fallback
|
|
13
|
+
|
|
14
|
+
// Put the text to copy into a <span>
|
|
15
|
+
var span = document.createElement('span')
|
|
16
|
+
span.textContent = text
|
|
17
|
+
|
|
18
|
+
// Preserve consecutive spaces and newlines
|
|
19
|
+
span.style.whiteSpace = 'pre'
|
|
20
|
+
span.style.webkitUserSelect = 'auto'
|
|
21
|
+
span.style.userSelect = 'all'
|
|
22
|
+
|
|
23
|
+
// Add the <span> to the page
|
|
24
|
+
document.body.appendChild(span)
|
|
25
|
+
|
|
26
|
+
// Make a selection object representing the range of text selected by the user
|
|
27
|
+
var selection = window.getSelection()
|
|
28
|
+
var range = window.document.createRange()
|
|
29
|
+
selection.removeAllRanges()
|
|
30
|
+
range.selectNode(span)
|
|
31
|
+
selection.addRange(range)
|
|
32
|
+
|
|
33
|
+
// Copy text to the clipboard
|
|
34
|
+
var success = false
|
|
35
|
+
try {
|
|
36
|
+
success = window.document.execCommand('copy')
|
|
37
|
+
} catch(err) {
|
|
38
|
+
console.log('error', err)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Cleanup
|
|
42
|
+
selection.removeAllRanges()
|
|
43
|
+
window.document.body.removeChild(span)
|
|
44
|
+
|
|
45
|
+
return success ? Promise.resolve(text) : Promise.reject(new DOMException('The request is not allowed', 'NotAllowedError'))
|
|
46
|
+
}
|
|
47
|
+
}));
|
package/src/util/Text.js
CHANGED
|
@@ -2222,9 +2222,4 @@ diff_match_patch.patch_obj.prototype.toString = function() {
|
|
|
2222
2222
|
return diff_match_patch;
|
|
2223
2223
|
});
|
|
2224
2224
|
|
|
2225
|
-
define(
|
|
2226
|
-
|
|
2227
|
-
const dmp = require("diff-match-patch");
|
|
2228
|
-
|
|
2229
|
-
return { dmp: dmp }
|
|
2230
|
-
})
|
|
2225
|
+
define(["diff-match-patch"], (dmp) => ({ dmp: dmp }));
|