fix(svg-draw): реально отключаем перетаскивание карточки при рисовании

Прошлый гард не работал: dragstart срабатывает на самой карточке (draggable=true), а не на
svg, поэтому e.target.closest(.svgdraw-host) был null. Теперь на pointerdown снимаем
draggable с ближайшего предка-карточки и возвращаем на pointerup — холст рисует, а не тащит блок.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maxim Dolgolyov
2026-06-03 20:23:27 +03:00
parent 2f47edbc72
commit 7e640e4207
+17
View File
@@ -200,8 +200,23 @@
/* ── drawing interaction ──────────────────────────────────────── */
let drawing = false, startP = null, curEl = null, penPts = null, dragMode = null, dragStart = null, selStartXY = null;
/* The host lesson block-card is draggable=true and hijacks mouse-drag on the
canvas — and its dragstart fires on the CARD (not the svg), so it can't be
cancelled here. Fix: disable the nearest draggable ancestor while a pointer
is down on the canvas, restore on release. */
let _dragAnc = null;
function suppressAncestorDrag() {
const a = svg.closest && svg.closest('[draggable="true"]');
if (a) { _dragAnc = a; a.setAttribute('draggable', 'false'); }
}
function restoreAncestorDrag() {
if (_dragAnc) { _dragAnc.setAttribute('draggable', 'true'); _dragAnc = null; }
}
document.addEventListener('pointerup', restoreAncestorDrag);
svg.addEventListener('pointerdown', function (evt) {
if (evt.button !== 0) return;
suppressAncestorDrag();
const p = svgPoint(evt);
if (state.tool === 'select') {
@@ -274,6 +289,7 @@
});
function endDraw(evt) {
restoreAncestorDrag();
if (dragMode === 'move') { dragMode = null; commit(); return; }
if (!drawing) return;
drawing = false;
@@ -466,6 +482,7 @@
function destroy() {
document.removeEventListener('keydown', onKey);
document.removeEventListener('pointerup', restoreAncestorDrag);
if (root.parentNode) root.parentNode.removeChild(root);
}