11/* eslint-disable @typescript-eslint/no-explicit-any */
22import type { Meta, StoryObj } from '@storybook/react';
3- import React, { useRef, useState } from 'react';
4- import { Save } from 'lucide-react';
3+ import React, { useRef, useState, useCallback } from 'react';
4+ import { Save, Copy, Check } from 'lucide-react';
55import { Button } from '../ui/button';
66import { Settings } from './index';
77import type { SettingsElement, SettingsProps } from './settings-types';
@@ -23,12 +23,39 @@ type LogEntry = {
2323};
2424
2525function EventLog({ entries }: { entries: LogEntry[] }) {
26+ const [copied, setCopied] = useState(false);
27+
28+ const handleCopy = useCallback(() => {
29+ const text = entries
30+ .map((e) => {
31+ const base = `${e.time} ${e.type === 'save' ? 'onSave' : 'onChange'} pageId="${e.pageId}"`;
32+ if (e.type === 'change') return `${base} key="${e.key}" value=${JSON.stringify(e.value)}`;
33+ if (e.type === 'save') return `${base} values=${JSON.stringify(e.values, null, 2)}`;
34+ return base;
35+ })
36+ .join('\n');
37+ navigator.clipboard.writeText(text).then(() => {
38+ setCopied(true);
39+ setTimeout(() => setCopied(false), 2000);
40+ });
41+ }, [entries]);
42+
2643 if (entries.length === 0) return null;
2744 return (
2845 <div className="mt-4 rounded-lg border border-border bg-muted/40 max-h-64 overflow-y-auto">
2946 <div className="px-3 py-2 border-b border-border bg-muted/60 flex justify-between items-center">
3047 <span className="text-xs font-semibold text-foreground">Event Log</span>
31- <span className="text-xs text-muted-foreground">{entries.length} events</span>
48+ <div className="flex items-center gap-2">
49+ <span className="text-xs text-muted-foreground">{entries.length} events</span>
50+ <button
51+ onClick={handleCopy}
52+ className="inline-flex items-center gap-1 px-1.5 py-0.5 text-xs text-muted-foreground hover:text-foreground rounded transition-colors"
53+ title="Copy full log to clipboard"
54+ >
55+ {copied ? <Check className="w-3 h-3 text-green-600" /> : <Copy className="w-3 h-3" />}
56+ {copied ? 'Copied' : 'Copy'}
57+ </button>
58+ </div>
3259 </div>
3360 {entries.length > 0 ? (
3461 <div className="divide-y divide-border">
0 commit comments