@djangocfg/ui-core 2.1.580 → 2.1.582
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/ui-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.582",
|
|
4
4
|
"description": "Pure React UI component library without Next.js dependencies - for Electron, Vite, CRA apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui-components",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"check:contrast": "node scripts/check-preset-contrast.mjs"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
|
133
|
-
"@djangocfg/i18n": "^2.1.
|
|
133
|
+
"@djangocfg/i18n": "^2.1.582",
|
|
134
134
|
"consola": "^3.4.2",
|
|
135
135
|
"lucide-react": "^0.545.0",
|
|
136
136
|
"moment": "^2.30.1",
|
|
@@ -206,9 +206,9 @@
|
|
|
206
206
|
"vaul": "1.1.2"
|
|
207
207
|
},
|
|
208
208
|
"devDependencies": {
|
|
209
|
-
"@djangocfg/eslint-config": "^2.1.
|
|
210
|
-
"@djangocfg/i18n": "^2.1.
|
|
211
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
209
|
+
"@djangocfg/eslint-config": "^2.1.582",
|
|
210
|
+
"@djangocfg/i18n": "^2.1.582",
|
|
211
|
+
"@djangocfg/typescript-config": "^2.1.582",
|
|
212
212
|
"@storybook/react-vite": "^10.5.0",
|
|
213
213
|
"@types/node": "^24.13.3",
|
|
214
214
|
"@types/react": "19.2.15",
|
|
@@ -4,6 +4,7 @@ import { Check, Copy } from 'lucide-react';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
|
|
6
6
|
import { useAppT } from '@djangocfg/i18n';
|
|
7
|
+
import { copyText } from '../../../lib/clipboard';
|
|
7
8
|
import { cn } from '../../../lib/utils';
|
|
8
9
|
import { Button } from '../../forms/button';
|
|
9
10
|
|
|
@@ -44,14 +45,10 @@ const CopyButton = React.forwardRef<HTMLButtonElement, CopyButtonProps>(
|
|
|
44
45
|
const [copied, setCopied] = React.useState(false)
|
|
45
46
|
|
|
46
47
|
const handleCopy = async () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
setTimeout(() => setCopied(false), successDuration)
|
|
52
|
-
} catch (err) {
|
|
53
|
-
console.error('Failed to copy:', err)
|
|
54
|
-
}
|
|
48
|
+
if (!(await copyText(value))) return
|
|
49
|
+
setCopied(true)
|
|
50
|
+
onCopy?.(value)
|
|
51
|
+
setTimeout(() => setCopied(false), successDuration)
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
const hasLabel = !!children
|
package/src/hooks/dom/useCopy.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
4
|
|
|
5
|
+
import { copyText } from '../../lib/clipboard';
|
|
5
6
|
import { useToast } from '../feedback/useToast';
|
|
6
7
|
|
|
7
8
|
interface UseCopyOptions {
|
|
@@ -18,15 +19,10 @@ export const useCopy = (options: UseCopyOptions = {}) => {
|
|
|
18
19
|
} = options;
|
|
19
20
|
|
|
20
21
|
const copyToClipboard = useCallback(async (text: string, customSuccessMessage?: string) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error('Failed to copy:', error);
|
|
27
|
-
toast.error(errorMessage);
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
22
|
+
const copied = await copyText(text);
|
|
23
|
+
if (copied) toast.success(customSuccessMessage || successMessage);
|
|
24
|
+
else toast.error(errorMessage);
|
|
25
|
+
return copied;
|
|
30
26
|
}, [toast, successMessage, errorMessage]);
|
|
31
27
|
|
|
32
28
|
return { copyToClipboard };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy text from a click handler. Returns whether it landed.
|
|
3
|
+
*
|
|
4
|
+
* The Clipboard API first. When it is refused — an embedded browser that
|
|
5
|
+
* denies `clipboard-write`, a plain-http page, a document without focus — a
|
|
6
|
+
* hidden textarea and `execCommand('copy')`, which those browsers still honour
|
|
7
|
+
* within the same user gesture. Measured in the Claude desktop browser pane:
|
|
8
|
+
* `writeText` rejects with "Write permission denied", the fallback succeeds.
|
|
9
|
+
*/
|
|
10
|
+
export async function copyText(text: string): Promise<boolean> {
|
|
11
|
+
try {
|
|
12
|
+
await navigator.clipboard.writeText(text);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return copyWithTextarea(text);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function copyWithTextarea(text: string): boolean {
|
|
20
|
+
if (typeof document === 'undefined') return false;
|
|
21
|
+
const area = document.createElement('textarea');
|
|
22
|
+
area.value = text;
|
|
23
|
+
area.setAttribute('readonly', '');
|
|
24
|
+
area.style.position = 'fixed';
|
|
25
|
+
area.style.opacity = '0';
|
|
26
|
+
document.body.appendChild(area);
|
|
27
|
+
area.select();
|
|
28
|
+
try {
|
|
29
|
+
return document.execCommand('copy');
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
} finally {
|
|
33
|
+
area.remove();
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/lib/index.ts
CHANGED
|
@@ -15,5 +15,6 @@ export * from "./styles";
|
|
|
15
15
|
export * from "./compose-refs";
|
|
16
16
|
export * from "./get-element-ref";
|
|
17
17
|
export * from "./compose-event-handlers";
|
|
18
|
+
export { copyText } from "./clipboard";
|
|
18
19
|
export { createContext } from "./create-context";
|
|
19
20
|
export { getIntensity } from "./intensity";
|