feat: enhance Actions and Preview components to support SVG source copying in preview mode

This commit is contained in:
sHa
2025-05-14 22:30:20 +03:00
parent d841f27454
commit 8fb057324e
2 changed files with 56 additions and 26 deletions

View File

@@ -4,6 +4,8 @@
export let logo; export let logo;
export let onDownload; export let onDownload;
export let onCopySource = undefined;
export let inPreview = false;
// Download menu state // Download menu state
let showDownloadMenu = false; let showDownloadMenu = false;
@@ -22,6 +24,11 @@
notificationText = text; notificationText = text;
notificationType = type; notificationType = type;
showNotification = true; showNotification = true;
// Force the notification to be visible in the preview
setTimeout(() => {
showNotification = true; // Re-trigger the notification in case it was missed
}, 50);
} }
function hideNotification() { function hideNotification() {
@@ -190,11 +197,22 @@
if (logo.format !== 'SVG') return; if (logo.format !== 'SVG') return;
try { try {
const success = await copySvgSource(logo.path); // Check if we're in preview mode and have a custom handler
if (success) { if (inPreview && typeof onCopySource === 'function') {
showCopyNotification('SVG source copied!', 'success'); const success = onCopySource();
if (success) {
showCopyNotification('SVG source copied!', 'success');
} else {
showCopyNotification('Failed to copy SVG source', 'error');
}
} else { } else {
showCopyNotification('Failed to copy SVG source', 'error'); // Use the standard method for grid/list view
const success = await copySvgSource(logo.path);
if (success) {
showCopyNotification('SVG source copied!', 'success');
} else {
showCopyNotification('Failed to copy SVG source', 'error');
}
} }
} catch (err) { } catch (err) {
showCopyNotification('Error copying SVG source', 'error'); showCopyNotification('Error copying SVG source', 'error');
@@ -255,15 +273,15 @@
{/if} {/if}
</span> </span>
<div class="notification-overlay">
<Notification
<Notification text={notificationText}
text={notificationText} type={notificationType}
type={notificationType} show={showNotification}
show={showNotification} onClose={hideNotification}
onClose={hideNotification} duration={3000}
duration={3000} />
/> </div>
<style> <style>
.action-group { .action-group {
@@ -401,4 +419,11 @@
white-space: nowrap; white-space: nowrap;
} }
/* Notification styles moved to Notification.svelte */ /* Notification styles moved to Notification.svelte */
.notification-overlay {
position: fixed;
top: 20px;
right: 20px;
z-index: 10000;
pointer-events: none;
}
</style> </style>

View File

@@ -10,7 +10,6 @@
export let logo = null; export let logo = null;
export let theme; export let theme;
export let openLogoByAnchor = () => {}; export let openLogoByAnchor = () => {};
export let onCopy = () => {};
export let onDownload = (path, name) => { export let onDownload = (path, name) => {
const a = document.createElement('a'); const a = document.createElement('a');
a.href = path; a.href = path;
@@ -24,7 +23,7 @@
let svgSource = ''; let svgSource = '';
let isFetchingSvgSource = false; let isFetchingSvgSource = false;
const dispatch = createEventDispatcher(); // We no longer need the notification state and handlers since Actions component handles this const dispatch = createEventDispatcher();
function close() { function close() {
show = false; show = false;
@@ -43,21 +42,26 @@
function isSvgLogo(logo) { function isSvgLogo(logo) {
return logo && logo.format && logo.format.toLowerCase() === 'svg'; return logo && logo.format && logo.format.toLowerCase() === 'svg';
} // Function to copy SVG source from textarea
function copySvgSourceFromTextarea() {
if (svgSource) {
try {
navigator.clipboard.writeText(svgSource);
return true;
} catch (err) {
console.error('Error copying from textarea:', err);
// Show content in prompt as fallback
window.prompt('Copy the SVG source code:', svgSource);
return false;
}
}
return false;
} }
$: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme); $: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme);
$: validColorConfig = logo && typeof logo.colorConfig === 'object' && logo.colorConfig.selector ? logo.colorConfig : undefined; $: validColorConfig = logo && typeof logo.colorConfig === 'object' && logo.colorConfig.selector ? logo.colorConfig : undefined;
// Improved debug logging for color and theme
$: {
if (logo && logo.colors) {
const themeColor = getDefaultLogoColor(logo.colors, theme);
const fallbackColor = getThemeColor(logo.colors, theme);
const activeColor = logo._activeColor || themeColor;
}
}
// Sync show state with URL hash // Sync show state with URL hash
$: { $: {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
@@ -254,6 +258,8 @@
<Actions <Actions
logo={logo} logo={logo}
onDownload={onDownload} onDownload={onDownload}
onCopySource={copySvgSourceFromTextarea}
inPreview={true}
/> />
</div> </div>
</div> </div>
@@ -272,9 +278,8 @@
{/if} {/if}
</div> </div>
<style> <style>
.preview-actions-container { .preview-actions-container {
width: 100%; width: 100%;
background: var(--color-card); background: var(--color-card);