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 lines1200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381199 unmodified lines};if (type === 'condition') {nodeData.options = [{ id: 'opt-yes', label: 'Так' },{ id: 'opt-no', label: 'Ні' }];nodeData.selectedOptions = [];nodeData.multiSelect = false;} else if (type === 'habit') {nodeData.resetRule = { type: 'daily', time: '00:00' };nodeData.createdAt = new Date().toISOString();nodeData.lastResetTime = new Date().toISOString();} else if (type === 'comment') {nodeData.color = 'yellow';nodeData.assignees = [];nodeData.isPinned = false;} else if (type === 'image') {nodeData.url = initialData.url || '';nodeData.width = 300;nodeData.height = 'auto';} else if (type === 'text') {nodeData.label = '';nodeData.fontSize = 18;nodeData.textAlign = 'left';} else if (type === 'path') {nodeData.path = initialData.path || '';nodeData.strokeColor = undefined; // Use theme defaultnodeData.strokeWidth = 3;} else if (type === 'sketch') {nodeData.decision = 'bottom';nodeData.color = undefined;nodeData.assignees = [];nodeData.isPinned = false;} else {nodeData.decision = 'bottom';}const newNode = {1199 unmodified lines1200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381199 unmodified lines};if (type === 'condition') {nodeData.options = initialData.options || [{ id: 'opt-yes', label: 'Так' },{ id: 'opt-no', label: 'Ні' }];nodeData.selectedOptions = initialData.selectedOptions || [];nodeData.multiSelect = initialData.multiSelect !== undefined ? initialData.multiSelect : false;} else if (type === 'habit') {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 = 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 = initialData.width || 300;nodeData.height = initialData.height || 'auto';} else if (type === 'text') {nodeData.label = initialData.label || '';nodeData.fontSize = initialData.fontSize || 18;nodeData.textAlign = initialData.textAlign || 'left';} else if (type === 'path') {nodeData.path = initialData.path || '';nodeData.strokeColor = initialData.strokeColor; // Use theme default if undefinednodeData.strokeWidth = initialData.strokeWidth || 3;} else if (type === 'sketch') {nodeData.decision = initialData.decision || 'bottom';nodeData.color = initialData.color;nodeData.assignees = initialData.assignees || [];nodeData.isPinned = initialData.isPinned !== undefined ? initialData.isPinned : false;} else {nodeData.decision = initialData.decision || 'bottom';}const newNode = {
1313 unmodified lines13141315131613171318131913201321132213231 unmodified line13251326132713281329133013311332133313343 unmodified lines13381339134013411342134313441 unmodified line13461347134813491350135113521353135413551356135713581359136013611362136313641365136613671 unmodified line13691370137113721373137413751376137713781313 unmodified linesuseEffect(() => {const handlePasteEvent = (event) => {if (permission === 'Read') return;// Don't paste if user is typing in an input/textareaconst targetTag = event.target.tagName;if (targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable) return;const clipboardData = event.clipboardData || window.clipboardData;if (!clipboardData) return;1 unmodified lineconst items = clipboardData.items;let imageFound = false;// First check for imagesfor (const item of items) {if (item.type.indexOf('image') !== -1) {imageFound = true;const blob = item.getAsFile();const reader = new FileReader();reader.onload = (e) => {3 unmodified lineslet 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 linewidth *= 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;addNewNodeAt(x, y, 'image', { url: compressedBase64 });};img.src = e.target.result;};reader.readAsDataURL(blob);event.preventDefault();break; // Only paste one image at a time}}1 unmodified lineif (!imageFound) {const text = clipboardData.getData('text/plain');if (text && text.trim()) {const x = window.__lastMouseX || window.innerWidth / 2;const y = window.__lastMouseY || window.innerHeight / 2;addNewNodeAt(x, y, 'text', { label: text });event.preventDefault();}}};1313 unmodified lines131413151316131713181319132013211322132313241 unmodified line1326132713281329133013311332133313341335133613371338133913403 unmodified lines13441345134613471348134913501 unmodified line13521353135413551356135713581359136013611362136313641365136613671368136913701371137213731 unmodified line137513761377137813791380138113821383138413851313 unmodified linesuseEffect(() => {const handlePasteEvent = (event) => {if (permission === 'Read') return;// Don't paste if user is typing in an input/textareaconst targetTag = event.target.tagName;const isInput = targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable;if (isInput) return;const clipboardData = event.clipboardData || window.clipboardData;if (!clipboardData) return;1 unmodified lineconst items = clipboardData.items;let imageFound = false;// Log for debuggingconsole.log('[Paste] Event triggered', { items: items.length });// First check for imagesfor (const item of items) {if (item.type.indexOf('image') !== -1) {imageFound = true;event.preventDefault(); // Stop standard paste earlyconst blob = item.getAsFile();const reader = new FileReader();reader.onload = (e) => {3 unmodified lineslet 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 linewidth *= 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);break;}}1 unmodified lineif (!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 });}}};
src/features/canvas/hooks/useCanvasLogic.js+21-21
src/pages/CanvasPage.jsx+15-8