@dbcdk/react-components 0.0.37 → 0.0.38

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.
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { TextWrap } from 'lucide-react';
3
- import { isValidElement } from 'react';
4
- import { useMemo, useState } from 'react';
3
+ import { isValidElement, useMemo, useState } from 'react';
5
4
  import styles from './CodeBlock.module.css';
6
5
  import { Button } from '../button/Button';
7
6
  import { CopyButton } from '../copy-button/CopyButton';
@@ -11,12 +11,33 @@ export function CopyButton(props) {
11
11
  const [copied, setCopied] = useState(false);
12
12
  const handleCopy = async () => {
13
13
  try {
14
+ if (!window.isSecureContext || !navigator.clipboard) {
15
+ throw new Error('Clipboard API unavailable');
16
+ }
14
17
  await navigator.clipboard.writeText(text);
15
18
  setCopied(true);
16
19
  setTimeout(() => setCopied(false), 1000);
17
20
  }
18
21
  catch (err) {
19
- console.error('Failed to copy: ', err);
22
+ console.error('Failed to copy:', err);
23
+ try {
24
+ const textarea = document.createElement('textarea');
25
+ textarea.value = text;
26
+ textarea.setAttribute('readonly', '');
27
+ textarea.style.position = 'fixed';
28
+ textarea.style.left = '-9999px';
29
+ document.body.appendChild(textarea);
30
+ textarea.select();
31
+ const success = document.execCommand('copy');
32
+ document.body.removeChild(textarea);
33
+ if (success) {
34
+ setCopied(true);
35
+ setTimeout(() => setCopied(false), 1000);
36
+ }
37
+ }
38
+ catch (fallbackErr) {
39
+ console.error('Fallback copy failed:', fallbackErr);
40
+ }
20
41
  }
21
42
  };
22
43
  if (props.style === 'link') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",