@scaleflex/ui-tw 0.0.154 → 0.0.156
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/button/components/copy-button.js +8 -2
- package/button/components/copy-to-clipboard-button.js +8 -2
- package/package.json +2 -2
- package/utils/copy-to-clipboard.d.ts +1 -1
- package/utils/copy-to-clipboard.js +30 -25
- package/utils/use-copy-to-clipboard.d.ts +2 -1
- package/utils/use-copy-to-clipboard.js +3 -2
|
@@ -4,7 +4,7 @@ var _excluded = ["textToCopy", "copiedMessage", "tooltipDuration", "onCopy", "ch
|
|
|
4
4
|
import { Button } from '@scaleflex/ui-tw/button';
|
|
5
5
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
6
6
|
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
7
|
-
import React from 'react';
|
|
7
|
+
import React, { useRef } from 'react';
|
|
8
8
|
export function CopyButton(_ref) {
|
|
9
9
|
var textToCopy = _ref.textToCopy,
|
|
10
10
|
_ref$copiedMessage = _ref.copiedMessage,
|
|
@@ -15,10 +15,15 @@ export function CopyButton(_ref) {
|
|
|
15
15
|
children = _ref.children,
|
|
16
16
|
disabled = _ref.disabled,
|
|
17
17
|
buttonProps = _objectWithoutProperties(_ref, _excluded);
|
|
18
|
+
var buttonRef = useRef(null);
|
|
18
19
|
var _useCopyToClipboard = useCopyToClipboard({
|
|
19
20
|
copiedMessage: copiedMessage,
|
|
20
21
|
tooltipDuration: tooltipDuration,
|
|
21
|
-
onCopy: onCopy
|
|
22
|
+
onCopy: onCopy,
|
|
23
|
+
getContainer: function getContainer() {
|
|
24
|
+
var _buttonRef$current;
|
|
25
|
+
return (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.parentElement;
|
|
26
|
+
}
|
|
22
27
|
}),
|
|
23
28
|
tooltipText = _useCopyToClipboard.tooltipText,
|
|
24
29
|
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
@@ -29,6 +34,7 @@ export function CopyButton(_ref) {
|
|
|
29
34
|
variant: tooltipVariant,
|
|
30
35
|
open: open || undefined
|
|
31
36
|
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
37
|
+
ref: buttonRef,
|
|
32
38
|
"data-slot": "copy-button",
|
|
33
39
|
type: "button",
|
|
34
40
|
onClick: function onClick() {
|
|
@@ -2,7 +2,7 @@ import { Button, ButtonSize } from '@scaleflex/ui-tw/button';
|
|
|
2
2
|
import { WithTooltip } from '@scaleflex/ui-tw/tooltip';
|
|
3
3
|
import { useCopyToClipboard } from '@scaleflex/ui-tw/utils/use-copy-to-clipboard';
|
|
4
4
|
import { Copy } from 'lucide-react';
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { useRef } from 'react';
|
|
6
6
|
|
|
7
7
|
/** @deprecated Use CopyIcon instead */
|
|
8
8
|
|
|
@@ -18,10 +18,15 @@ export function CopyIcon(props) {
|
|
|
18
18
|
tooltipDuration = _props$tooltipDuratio === void 0 ? 2000 : _props$tooltipDuratio,
|
|
19
19
|
_props$disabled = props.disabled,
|
|
20
20
|
disabled = _props$disabled === void 0 ? false : _props$disabled;
|
|
21
|
+
var buttonRef = useRef(null);
|
|
21
22
|
var _useCopyToClipboard = useCopyToClipboard({
|
|
22
23
|
copiedMessage: copiedTooltip,
|
|
23
24
|
tooltipDuration: tooltipDuration,
|
|
24
|
-
initialTooltipText: initialTooltip
|
|
25
|
+
initialTooltipText: initialTooltip,
|
|
26
|
+
getContainer: function getContainer() {
|
|
27
|
+
var _buttonRef$current;
|
|
28
|
+
return (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.parentElement;
|
|
29
|
+
}
|
|
25
30
|
}),
|
|
26
31
|
tooltipText = _useCopyToClipboard.tooltipText,
|
|
27
32
|
tooltipVariant = _useCopyToClipboard.tooltipVariant,
|
|
@@ -32,6 +37,7 @@ export function CopyIcon(props) {
|
|
|
32
37
|
variant: tooltipVariant,
|
|
33
38
|
open: open || undefined
|
|
34
39
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
40
|
+
ref: buttonRef,
|
|
35
41
|
type: "button",
|
|
36
42
|
variant: "ghost-secondary",
|
|
37
43
|
size: size,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleflex/ui-tw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.156",
|
|
4
4
|
"author": "scaleflex",
|
|
5
5
|
"repository": "github:scaleflex/ui",
|
|
6
6
|
"homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@radix-ui/react-switch": "^1.0.1",
|
|
30
30
|
"@radix-ui/react-tabs": "^1.1.13",
|
|
31
31
|
"@radix-ui/react-tooltip": "^1.2.6",
|
|
32
|
-
"@scaleflex/icons-tw": "^0.0.
|
|
32
|
+
"@scaleflex/icons-tw": "^0.0.156",
|
|
33
33
|
"@tanstack/react-table": "^8.21.3",
|
|
34
34
|
"@types/lodash.merge": "^4.6.9",
|
|
35
35
|
"class-variance-authority": "^0.7.1",
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* fallback path may return `true` unreliably in some browsers — do not rely
|
|
8
8
|
* on it for critical confirmations.
|
|
9
9
|
*/
|
|
10
|
-
export declare function copyToClipboard(text: string): Promise<boolean>;
|
|
10
|
+
export declare function copyToClipboard(text: string, container?: HTMLElement | null): Promise<boolean>;
|
|
@@ -9,57 +9,62 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
9
9
|
* fallback path may return `true` unreliably in some browsers — do not rely
|
|
10
10
|
* on it for critical confirmations.
|
|
11
11
|
*/
|
|
12
|
-
export function copyToClipboard(_x) {
|
|
12
|
+
export function copyToClipboard(_x, _x2) {
|
|
13
13
|
return _copyToClipboard.apply(this, arguments);
|
|
14
14
|
}
|
|
15
15
|
function _copyToClipboard() {
|
|
16
|
-
_copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
|
|
17
|
-
var _navigator$clipboard;
|
|
18
|
-
var textarea;
|
|
16
|
+
_copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, container) {
|
|
17
|
+
var _self, _navigator$clipboard;
|
|
18
|
+
var isSecureContext, root, textarea, _window$getSelection;
|
|
19
19
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
20
|
while (1) switch (_context.prev = _context.next) {
|
|
21
21
|
case 0:
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
isSecureContext = typeof window !== 'undefined' ? window.isSecureContext : !!((_self = self) !== null && _self !== void 0 && _self.isSecureContext);
|
|
23
|
+
if (!(isSecureContext && typeof navigator !== 'undefined' && (_navigator$clipboard = navigator.clipboard) !== null && _navigator$clipboard !== void 0 && _navigator$clipboard.writeText)) {
|
|
24
|
+
_context.next = 10;
|
|
24
25
|
break;
|
|
25
26
|
}
|
|
26
|
-
_context.prev =
|
|
27
|
-
_context.next =
|
|
27
|
+
_context.prev = 2;
|
|
28
|
+
_context.next = 5;
|
|
28
29
|
return navigator.clipboard.writeText(text);
|
|
29
|
-
case
|
|
30
|
+
case 5:
|
|
30
31
|
return _context.abrupt("return", true);
|
|
31
|
-
case
|
|
32
|
-
_context.prev =
|
|
33
|
-
_context.t0 = _context["catch"](
|
|
34
|
-
case
|
|
32
|
+
case 8:
|
|
33
|
+
_context.prev = 8;
|
|
34
|
+
_context.t0 = _context["catch"](2);
|
|
35
|
+
case 10:
|
|
35
36
|
if (!(typeof document === 'undefined')) {
|
|
36
|
-
_context.next =
|
|
37
|
+
_context.next = 12;
|
|
37
38
|
break;
|
|
38
39
|
}
|
|
39
40
|
return _context.abrupt("return", false);
|
|
40
|
-
case
|
|
41
|
-
// Fallback for iframes, HTTP contexts, older browsers
|
|
41
|
+
case 12:
|
|
42
|
+
// Fallback for iframes, HTTP contexts, older browsers.
|
|
43
|
+
// Appending inside `container` (e.g. the trigger button's parent) keeps the textarea
|
|
44
|
+
// within any focus-trap scope (e.g. Radix Dialog) so focus() and execCommand work correctly.
|
|
45
|
+
root = container !== null && container !== void 0 ? container : document.body;
|
|
42
46
|
textarea = document.createElement('textarea');
|
|
43
47
|
textarea.value = text;
|
|
44
48
|
textarea.style.cssText = 'position:fixed;top:0;left:0;opacity:0;pointer-events:none';
|
|
45
|
-
|
|
46
|
-
_context.prev =
|
|
49
|
+
root.appendChild(textarea);
|
|
50
|
+
_context.prev = 17;
|
|
51
|
+
(_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 || _window$getSelection.removeAllRanges();
|
|
47
52
|
textarea.focus();
|
|
48
53
|
textarea.select();
|
|
49
54
|
return _context.abrupt("return", document.execCommand('copy'));
|
|
50
|
-
case 21:
|
|
51
|
-
_context.prev = 21;
|
|
52
|
-
_context.t1 = _context["catch"](15);
|
|
53
|
-
return _context.abrupt("return", false);
|
|
54
55
|
case 24:
|
|
55
56
|
_context.prev = 24;
|
|
56
|
-
|
|
57
|
-
return _context.
|
|
57
|
+
_context.t1 = _context["catch"](17);
|
|
58
|
+
return _context.abrupt("return", false);
|
|
58
59
|
case 27:
|
|
60
|
+
_context.prev = 27;
|
|
61
|
+
root.removeChild(textarea);
|
|
62
|
+
return _context.finish(27);
|
|
63
|
+
case 30:
|
|
59
64
|
case "end":
|
|
60
65
|
return _context.stop();
|
|
61
66
|
}
|
|
62
|
-
}, _callee, null, [[
|
|
67
|
+
}, _callee, null, [[2, 8], [17, 24, 27, 30]]);
|
|
63
68
|
}));
|
|
64
69
|
return _copyToClipboard.apply(this, arguments);
|
|
65
70
|
}
|
|
@@ -3,8 +3,9 @@ interface UseCopyToClipboardOptions {
|
|
|
3
3
|
tooltipDuration?: number;
|
|
4
4
|
initialTooltipText?: string;
|
|
5
5
|
onCopy?: () => void;
|
|
6
|
+
getContainer?: () => HTMLElement | null | undefined;
|
|
6
7
|
}
|
|
7
|
-
export declare function useCopyToClipboard({ copiedMessage, tooltipDuration, initialTooltipText, onCopy, }?: UseCopyToClipboardOptions): {
|
|
8
|
+
export declare function useCopyToClipboard({ copiedMessage, tooltipDuration, initialTooltipText, onCopy, getContainer, }?: UseCopyToClipboardOptions): {
|
|
8
9
|
tooltipText: string;
|
|
9
10
|
tooltipVariant: "default" | "success";
|
|
10
11
|
open: boolean;
|
|
@@ -11,7 +11,8 @@ export function useCopyToClipboard() {
|
|
|
11
11
|
tooltipDuration = _ref$tooltipDuration === void 0 ? 2000 : _ref$tooltipDuration,
|
|
12
12
|
_ref$initialTooltipTe = _ref.initialTooltipText,
|
|
13
13
|
initialTooltipText = _ref$initialTooltipTe === void 0 ? '' : _ref$initialTooltipTe,
|
|
14
|
-
onCopy = _ref.onCopy
|
|
14
|
+
onCopy = _ref.onCopy,
|
|
15
|
+
getContainer = _ref.getContainer;
|
|
15
16
|
var _useState = useState(initialTooltipText),
|
|
16
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
17
18
|
tooltipText = _useState2[0],
|
|
@@ -31,7 +32,7 @@ export function useCopyToClipboard() {
|
|
|
31
32
|
while (1) switch (_context.prev = _context.next) {
|
|
32
33
|
case 0:
|
|
33
34
|
_context.next = 2;
|
|
34
|
-
return copyToClipboard(text);
|
|
35
|
+
return copyToClipboard(text, getContainer === null || getContainer === void 0 ? void 0 : getContainer());
|
|
35
36
|
case 2:
|
|
36
37
|
success = _context.sent;
|
|
37
38
|
if (success) {
|