Spaces:
Running
Running
Commit ·
ee9aaf3
1
Parent(s): 04bb786
fix: resolve clipboard paste data being overwritten by defaults and improve paste reliability
Browse files
src/features/canvas/hooks/useCanvasLogic.js
CHANGED
|
@@ -1200,39 +1200,39 @@ export const useCanvasLogic = (projectId, user) => {
|
|
| 1200 |
};
|
| 1201 |
|
| 1202 |
if (type === 'condition') {
|
| 1203 |
-
nodeData.options = [
|
| 1204 |
{ id: 'opt-yes', label: 'Так' },
|
| 1205 |
{ id: 'opt-no', label: 'Ні' }
|
| 1206 |
];
|
| 1207 |
-
nodeData.selectedOptions = [];
|
| 1208 |
-
nodeData.multiSelect = false;
|
| 1209 |
} else if (type === 'habit') {
|
| 1210 |
-
nodeData.resetRule = { type: 'daily', time: '00:00' };
|
| 1211 |
-
nodeData.createdAt = new Date().toISOString();
|
| 1212 |
-
nodeData.lastResetTime = new Date().toISOString();
|
| 1213 |
} else if (type === 'comment') {
|
| 1214 |
-
nodeData.color = 'yellow';
|
| 1215 |
-
nodeData.assignees = [];
|
| 1216 |
-
nodeData.isPinned = false;
|
| 1217 |
} else if (type === 'image') {
|
| 1218 |
nodeData.url = initialData.url || '';
|
| 1219 |
-
nodeData.width = 300;
|
| 1220 |
-
nodeData.height = 'auto';
|
| 1221 |
} else if (type === 'text') {
|
| 1222 |
-
nodeData.label = '';
|
| 1223 |
-
nodeData.fontSize = 18;
|
| 1224 |
-
nodeData.textAlign = 'left';
|
| 1225 |
} else if (type === 'path') {
|
| 1226 |
nodeData.path = initialData.path || '';
|
| 1227 |
-
nodeData.strokeColor =
|
| 1228 |
-
nodeData.strokeWidth = 3;
|
| 1229 |
} else if (type === 'sketch') {
|
| 1230 |
-
nodeData.decision = 'bottom';
|
| 1231 |
-
nodeData.color =
|
| 1232 |
-
nodeData.assignees = [];
|
| 1233 |
-
nodeData.isPinned = false;
|
| 1234 |
} else {
|
| 1235 |
-
nodeData.decision = 'bottom';
|
| 1236 |
}
|
| 1237 |
|
| 1238 |
const newNode = {
|
|
|
|
| 1200 |
};
|
| 1201 |
|
| 1202 |
if (type === 'condition') {
|
| 1203 |
+
nodeData.options = initialData.options || [
|
| 1204 |
{ id: 'opt-yes', label: 'Так' },
|
| 1205 |
{ id: 'opt-no', label: 'Ні' }
|
| 1206 |
];
|
| 1207 |
+
nodeData.selectedOptions = initialData.selectedOptions || [];
|
| 1208 |
+
nodeData.multiSelect = initialData.multiSelect !== undefined ? initialData.multiSelect : false;
|
| 1209 |
} else if (type === 'habit') {
|
| 1210 |
+
nodeData.resetRule = initialData.resetRule || { type: 'daily', time: '00:00' };
|
| 1211 |
+
nodeData.createdAt = initialData.createdAt || new Date().toISOString();
|
| 1212 |
+
nodeData.lastResetTime = initialData.lastResetTime || new Date().toISOString();
|
| 1213 |
} else if (type === 'comment') {
|
| 1214 |
+
nodeData.color = initialData.color || 'yellow';
|
| 1215 |
+
nodeData.assignees = initialData.assignees || [];
|
| 1216 |
+
nodeData.isPinned = initialData.isPinned !== undefined ? initialData.isPinned : false;
|
| 1217 |
} else if (type === 'image') {
|
| 1218 |
nodeData.url = initialData.url || '';
|
| 1219 |
+
nodeData.width = initialData.width || 300;
|
| 1220 |
+
nodeData.height = initialData.height || 'auto';
|
| 1221 |
} else if (type === 'text') {
|
| 1222 |
+
nodeData.label = initialData.label || '';
|
| 1223 |
+
nodeData.fontSize = initialData.fontSize || 18;
|
| 1224 |
+
nodeData.textAlign = initialData.textAlign || 'left';
|
| 1225 |
} else if (type === 'path') {
|
| 1226 |
nodeData.path = initialData.path || '';
|
| 1227 |
+
nodeData.strokeColor = initialData.strokeColor; // Use theme default if undefined
|
| 1228 |
+
nodeData.strokeWidth = initialData.strokeWidth || 3;
|
| 1229 |
} else if (type === 'sketch') {
|
| 1230 |
+
nodeData.decision = initialData.decision || 'bottom';
|
| 1231 |
+
nodeData.color = initialData.color;
|
| 1232 |
+
nodeData.assignees = initialData.assignees || [];
|
| 1233 |
+
nodeData.isPinned = initialData.isPinned !== undefined ? initialData.isPinned : false;
|
| 1234 |
} else {
|
| 1235 |
+
nodeData.decision = initialData.decision || 'bottom';
|
| 1236 |
}
|
| 1237 |
|
| 1238 |
const newNode = {
|
src/pages/CanvasPage.jsx
CHANGED
|
@@ -1314,10 +1314,11 @@ const CanvasInner = () => {
|
|
| 1314 |
useEffect(() => {
|
| 1315 |
const handlePasteEvent = (event) => {
|
| 1316 |
if (permission === 'Read') return;
|
| 1317 |
-
|
| 1318 |
// Don't paste if user is typing in an input/textarea
|
| 1319 |
const targetTag = event.target.tagName;
|
| 1320 |
-
|
|
|
|
| 1321 |
|
| 1322 |
const clipboardData = event.clipboardData || window.clipboardData;
|
| 1323 |
if (!clipboardData) return;
|
|
@@ -1325,10 +1326,15 @@ const CanvasInner = () => {
|
|
| 1325 |
const items = clipboardData.items;
|
| 1326 |
let imageFound = false;
|
| 1327 |
|
|
|
|
|
|
|
|
|
|
| 1328 |
// First check for images
|
| 1329 |
for (const item of items) {
|
| 1330 |
if (item.type.indexOf('image') !== -1) {
|
| 1331 |
imageFound = true;
|
|
|
|
|
|
|
| 1332 |
const blob = item.getAsFile();
|
| 1333 |
const reader = new FileReader();
|
| 1334 |
reader.onload = (e) => {
|
|
@@ -1338,7 +1344,7 @@ const CanvasInner = () => {
|
|
| 1338 |
let width = img.width;
|
| 1339 |
let height = img.height;
|
| 1340 |
const MAX_SIZE = 1200;
|
| 1341 |
-
|
| 1342 |
if (width > height && width > MAX_SIZE) {
|
| 1343 |
height *= MAX_SIZE / width;
|
| 1344 |
width = MAX_SIZE;
|
|
@@ -1346,22 +1352,22 @@ const CanvasInner = () => {
|
|
| 1346 |
width *= MAX_SIZE / height;
|
| 1347 |
height = MAX_SIZE;
|
| 1348 |
}
|
| 1349 |
-
|
| 1350 |
canvas.width = width;
|
| 1351 |
canvas.height = height;
|
| 1352 |
const ctx = canvas.getContext('2d');
|
| 1353 |
ctx.drawImage(img, 0, 0, width, height);
|
| 1354 |
const compressedBase64 = canvas.toDataURL('image/jpeg', 0.8);
|
| 1355 |
-
|
| 1356 |
const x = window.__lastMouseX || window.innerWidth / 2;
|
| 1357 |
const y = window.__lastMouseY || window.innerHeight / 2;
|
|
|
|
| 1358 |
addNewNodeAt(x, y, 'image', { url: compressedBase64 });
|
| 1359 |
};
|
| 1360 |
img.src = e.target.result;
|
| 1361 |
};
|
| 1362 |
reader.readAsDataURL(blob);
|
| 1363 |
-
|
| 1364 |
-
break; // Only paste one image at a time
|
| 1365 |
}
|
| 1366 |
}
|
| 1367 |
|
|
@@ -1369,10 +1375,11 @@ const CanvasInner = () => {
|
|
| 1369 |
if (!imageFound) {
|
| 1370 |
const text = clipboardData.getData('text/plain');
|
| 1371 |
if (text && text.trim()) {
|
|
|
|
| 1372 |
const x = window.__lastMouseX || window.innerWidth / 2;
|
| 1373 |
const y = window.__lastMouseY || window.innerHeight / 2;
|
|
|
|
| 1374 |
addNewNodeAt(x, y, 'text', { label: text });
|
| 1375 |
-
event.preventDefault();
|
| 1376 |
}
|
| 1377 |
}
|
| 1378 |
};
|
|
|
|
| 1314 |
useEffect(() => {
|
| 1315 |
const handlePasteEvent = (event) => {
|
| 1316 |
if (permission === 'Read') return;
|
| 1317 |
+
|
| 1318 |
// Don't paste if user is typing in an input/textarea
|
| 1319 |
const targetTag = event.target.tagName;
|
| 1320 |
+
const isInput = targetTag === 'INPUT' || targetTag === 'TEXTAREA' || event.target.isContentEditable;
|
| 1321 |
+
if (isInput) return;
|
| 1322 |
|
| 1323 |
const clipboardData = event.clipboardData || window.clipboardData;
|
| 1324 |
if (!clipboardData) return;
|
|
|
|
| 1326 |
const items = clipboardData.items;
|
| 1327 |
let imageFound = false;
|
| 1328 |
|
| 1329 |
+
// Log for debugging
|
| 1330 |
+
console.log('[Paste] Event triggered', { items: items.length });
|
| 1331 |
+
|
| 1332 |
// First check for images
|
| 1333 |
for (const item of items) {
|
| 1334 |
if (item.type.indexOf('image') !== -1) {
|
| 1335 |
imageFound = true;
|
| 1336 |
+
event.preventDefault(); // Stop standard paste early
|
| 1337 |
+
|
| 1338 |
const blob = item.getAsFile();
|
| 1339 |
const reader = new FileReader();
|
| 1340 |
reader.onload = (e) => {
|
|
|
|
| 1344 |
let width = img.width;
|
| 1345 |
let height = img.height;
|
| 1346 |
const MAX_SIZE = 1200;
|
| 1347 |
+
|
| 1348 |
if (width > height && width > MAX_SIZE) {
|
| 1349 |
height *= MAX_SIZE / width;
|
| 1350 |
width = MAX_SIZE;
|
|
|
|
| 1352 |
width *= MAX_SIZE / height;
|
| 1353 |
height = MAX_SIZE;
|
| 1354 |
}
|
| 1355 |
+
|
| 1356 |
canvas.width = width;
|
| 1357 |
canvas.height = height;
|
| 1358 |
const ctx = canvas.getContext('2d');
|
| 1359 |
ctx.drawImage(img, 0, 0, width, height);
|
| 1360 |
const compressedBase64 = canvas.toDataURL('image/jpeg', 0.8);
|
| 1361 |
+
|
| 1362 |
const x = window.__lastMouseX || window.innerWidth / 2;
|
| 1363 |
const y = window.__lastMouseY || window.innerHeight / 2;
|
| 1364 |
+
console.log('[Paste] Adding image node at', { x, y });
|
| 1365 |
addNewNodeAt(x, y, 'image', { url: compressedBase64 });
|
| 1366 |
};
|
| 1367 |
img.src = e.target.result;
|
| 1368 |
};
|
| 1369 |
reader.readAsDataURL(blob);
|
| 1370 |
+
break;
|
|
|
|
| 1371 |
}
|
| 1372 |
}
|
| 1373 |
|
|
|
|
| 1375 |
if (!imageFound) {
|
| 1376 |
const text = clipboardData.getData('text/plain');
|
| 1377 |
if (text && text.trim()) {
|
| 1378 |
+
event.preventDefault();
|
| 1379 |
const x = window.__lastMouseX || window.innerWidth / 2;
|
| 1380 |
const y = window.__lastMouseY || window.innerHeight / 2;
|
| 1381 |
+
console.log('[Paste] Adding text node at', { x, y });
|
| 1382 |
addNewNodeAt(x, y, 'text', { label: text });
|
|
|
|
| 1383 |
}
|
| 1384 |
}
|
| 1385 |
};
|