@djangocfg/widget-diagram 0.1.6 → 0.1.8

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/widget-diagram",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Mermaid diagrams: typed builders that write the source, and a full-parser renderer that draws it",
5
5
  "keywords": [
6
6
  "mermaid",
@@ -48,14 +48,14 @@
48
48
  "test:watch": "vitest"
49
49
  },
50
50
  "peerDependencies": {
51
- "@djangocfg/ui-core": "^2.1.547",
51
+ "@djangocfg/ui-core": "^2.1.549",
52
52
  "lucide-react": "^0.545.0",
53
53
  "react": "^19.0.0",
54
54
  "react-dom": "^19.0.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@djangocfg/typescript-config": "^2.1.547",
58
- "@djangocfg/ui-core": "^2.1.547",
57
+ "@djangocfg/typescript-config": "^2.1.549",
58
+ "@djangocfg/ui-core": "^2.1.549",
59
59
  "@storybook/react-vite": "^10.5.0",
60
60
  "@types/node": "^25.9.5",
61
61
  "@types/react": "19.2.15",
@@ -71,7 +71,7 @@
71
71
  "access": "public"
72
72
  },
73
73
  "dependencies": {
74
- "@djangocfg/widget-kit": "^0.1.6",
74
+ "@djangocfg/widget-kit": "^0.1.8",
75
75
  "mermaid": "^11.16.0",
76
76
  "react-zoom-pan-pinch": "^3.7.0"
77
77
  }
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import React, { useState } from 'react';
3
+ import React, { useEffect, useRef, useState } from 'react';
4
4
 
5
5
  interface MermaidCodeViewerProps {
6
6
  chart: string;
@@ -13,11 +13,30 @@ export const MermaidCodeViewer: React.FC<MermaidCodeViewerProps> = ({
13
13
  }) => {
14
14
  const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview');
15
15
  const [copied, setCopied] = useState(false);
16
+ // One timer, cleared on unmount: closing the viewer within the confirm
17
+ // window left a scheduled setState behind, and copying twice stacked two.
18
+ const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
19
+
20
+ useEffect(
21
+ () => () => {
22
+ if (copiedTimerRef.current) clearTimeout(copiedTimerRef.current);
23
+ },
24
+ [],
25
+ );
16
26
 
17
27
  const handleCopy = async () => {
18
- await navigator.clipboard.writeText(chart);
28
+ try {
29
+ await navigator.clipboard.writeText(chart);
30
+ } catch {
31
+ // Denied permission or an insecure origin — no tick to show.
32
+ return;
33
+ }
19
34
  setCopied(true);
20
- setTimeout(() => setCopied(false), 2000);
35
+ if (copiedTimerRef.current) clearTimeout(copiedTimerRef.current);
36
+ copiedTimerRef.current = setTimeout(() => {
37
+ copiedTimerRef.current = null;
38
+ setCopied(false);
39
+ }, 2000);
21
40
  };
22
41
 
23
42
  return (