Spaces:
Running
Running
Commit ·
ee9aaf3
1
Parent(s): 04bb786
fix: resolve clipboard paste data being overwritten by defaults and improve paste reliability
Browse filesFiles changed (2)
1199 unmodified lines1200120112021203120312041205120612071208120712081209121012111212121012111212121312141215121612141215121612171218121912201219122012211222122312241222122312241225122612271228122712281229123012311232123312301231123212331234123512351236123712381199 unmodified lines };
if (type === 'condition') { nodeData.options = [ nodeData.options = initialData.options || [ { id: 'opt-yes', label: 'Так' }, { id: 'opt-no', label: 'Ні' } ]; nodeData.selectedOptions = []; nodeData.multiSelect = false; nodeData.selectedOptions = initialData.selectedOptions || []; nodeData.multiSelect = initialData.multiSelect !== undefined ? initialData.multiSelect : false; } else if (type === 'habit') { nodeData.resetRule = { type: 'daily', time: '00:00' }; nodeData.createdAt = new Date().toISOString(); nodeData.lastResetTime = new Date().toISOString(); nodeData.resetRule = initialData.resetRule || { type: 'daily', time: '00:00' }; nodeData.createdAt = initialData.createdAt || new Date().toISOString(); nodeData.lastResetTime = initialData.lastResetTime || new Date().toISOString(); } else if (type === 'comment') { nodeData.color = 'yellow'; nodeData.assignees = []; nodeData.isPinned = false; nodeData.color = initialData.color || 'yellow'; nodeData.assignees = initialData.assignees || []; nodeData.isPinned = initialData.isPinned !== undefined ? initialData.isPinned : false; } else if (type === 'image') { nodeData.url = initialData.url || ''; nodeData.width = 300; nodeData.height = 'auto'; nodeData.width = initialData.width || 300; nodeData.height = initialData.height || 'auto'; } else if (type === 'text') { nodeData.label = ''; nodeData.fontSize = 18; nodeData.textAlign = 'left'; nodeData.label = initialData.label || ''; nodeData.fontSize = initialData.fontSize || 18; nodeData.textAlign = initialData.textAlign || 'left'; } else if (type === 'path') { nodeData.path = initialData.path || ''; nodeData.strokeColor = undefined; // Use theme default nodeData.strokeWidth = 3; nodeData.strokeColor = initialData.strokeColor; // Use theme default if undefined nodeData.strokeWidth = initialData.strokeWidth || 3; } else if (type === 'sketch') { nodeData.decision = 'bottom'; nodeData.color = undefined; nodeData.assignees = []; nodeData.isPinned = false; nodeData.decision = initialData.decision || 'bottom'; nodeData.color = initialData.color; nodeData.assignees = initialData.assignees || []; nodeData.isPinned = initialData.isPinned !== undefined ? initialData.isPinned : false; } else { nodeData.decision = 'bottom'; nodeData.decision = initialData.decision || 'bottom'; }
const newNode = {1313 unmodified lines13141315131613171317131813191320132013211322132313241 unmodified line1326132713281329133013311332133313341335133613371338133913403 unmodified lines134413451346134113471348134913501 unmodified line135213531354134913551356135713581359136013551361136213631364136513661367136813691363136413701371137213731 unmodified line1375137613771378137913801381138213751383138413851313 unmodified lines useEffect(() => { const handlePasteEvent = (event) => { if (permission === 'Read') return;
// Don't paste if user is typing in an input/textarea const targetTag = event.target.tagName; if (targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable) return; const isInput = targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable; if (isInput) return;
const clipboardData = event.clipboardData || window.clipboardData; if (!clipboardData) return;1 unmodified line const items = clipboardData.items; let imageFound = false;
// Log for debugging console.log('[Paste] Event triggered', { items: items.length });
// First check for images for (const item of items) { if (item.type.indexOf('image') !== -1) { imageFound = true; event.preventDefault(); // Stop standard paste early const blob = item.getAsFile(); const reader = new FileReader(); reader.onload = (e) => {3 unmodified lines let width = img.width; let height = img.height; const MAX_SIZE = 1200;
if (width > height && width > MAX_SIZE) { height *= MAX_SIZE / width; width = MAX_SIZE;1 unmodified line width *= MAX_SIZE / height; height = MAX_SIZE; }
canvas.width = width; canvas.height = height; const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0, width, height); const compressedBase64 = canvas.toDataURL('image/jpeg', 0.8);
const x = window.__lastMouseX || window.innerWidth / 2; const y = window.__lastMouseY || window.innerHeight / 2; console.log('[Paste] Adding image node at', { x, y }); addNewNodeAt(x, y, 'image', { url: compressedBase64 }); }; img.src = e.target.result; }; reader.readAsDataURL(blob); event.preventDefault(); break; // Only paste one image at a time break; } }
1 unmodified line if (!imageFound) { const text = clipboardData.getData('text/plain'); if (text && text.trim()) { event.preventDefault(); const x = window.__lastMouseX || window.innerWidth / 2; const y = window.__lastMouseY || window.innerHeight / 2; console.log('[Paste] Adding text node at', { x, y }); addNewNodeAt(x, y, 'text', { label: text }); event.preventDefault(); } } };src/features/canvas/hooks/useCanvasLogic.js+21-21
src/pages/CanvasPage.jsx+15-8