@equinor/echo-framework 0.7.10 → 0.7.11
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/src/utils/copyText.js +26 -6
- package/package.json +1 -1
|
@@ -10,28 +10,34 @@ var toastActions = require('../services/eventHubActions/toastActions.js');
|
|
|
10
10
|
|
|
11
11
|
function copyText(event) {
|
|
12
12
|
return _tslib.__awaiter(this, void 0, void 0, /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
13
|
-
var target, text;
|
|
13
|
+
var target, isMarkElement, text;
|
|
14
14
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
15
|
while (1) {
|
|
16
16
|
switch (_context.prev = _context.next) {
|
|
17
17
|
case 0:
|
|
18
18
|
target = event === null || event === void 0 ? void 0 : event.target;
|
|
19
|
-
|
|
19
|
+
isMarkElement = target.nodeName === 'MARK';
|
|
20
|
+
|
|
21
|
+
if (isMarkElement && target.parentElement) {
|
|
22
|
+
target = target.parentElement;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
text = getTextContentBySubTree(target);
|
|
20
26
|
|
|
21
27
|
if (!text) {
|
|
22
|
-
_context.next =
|
|
28
|
+
_context.next = 8;
|
|
23
29
|
break;
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
_context.next =
|
|
32
|
+
_context.next = 7;
|
|
27
33
|
return navigator.clipboard.writeText(text);
|
|
28
34
|
|
|
29
|
-
case
|
|
35
|
+
case 7:
|
|
30
36
|
toastActions.displayToast({
|
|
31
37
|
message: "Text copied to clipboard: ".concat(text)
|
|
32
38
|
});
|
|
33
39
|
|
|
34
|
-
case
|
|
40
|
+
case 8:
|
|
35
41
|
case "end":
|
|
36
42
|
return _context.stop();
|
|
37
43
|
}
|
|
@@ -40,4 +46,18 @@ function copyText(event) {
|
|
|
40
46
|
}));
|
|
41
47
|
}
|
|
42
48
|
|
|
49
|
+
function getTextContentBySubTree(element) {
|
|
50
|
+
var child = element.firstChild;
|
|
51
|
+
if (!child) return;
|
|
52
|
+
var texts = [];
|
|
53
|
+
|
|
54
|
+
while (child) {
|
|
55
|
+
if (child.nodeName === 'MARK' && child.textContent) texts.push(child.textContent);
|
|
56
|
+
if (child.nodeType === Node.TEXT_NODE && child.nodeValue) texts.push(child.nodeValue);
|
|
57
|
+
child = child.nextSibling;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return texts.join('');
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
exports.copyText = copyText;
|