Files
wekan/client/lib/newDrawing.js
T
Lauri Ojansivu 54726264d3 Drawing: a new drawing from Add Card and Add attachment, saved as SVG; an eraser and palm rejection.
#6802 asks for handwriting with a pen, saved as a card attachment, and
started while the card is created:

- Add attachment / Drawing, and Add Card's Drawing button (shown while
  the composer adds ONE card: the card is added, opened, and the drawing
  starts on it), open a NEW drawing on the whole window - the Drawing
  popup maximized, without the card's earlier drawings - saved as an SVG
  attachment of the card, its lines kept on the card for editing.
- The eraser takes away every line it touches (measured to the line's
  segments, its width included); Clear now has the trash icon.
- Palm rejection: once a pen has drawn, a touch does not, and while one
  pointer draws no other starts a line. A failed pointer capture no
  longer stops a line from starting.
- A Drawing popup opened from the card menu, which replaces the menu in
  the same popup, now opens maximized when it was left maximized.

The openers live in client/lib/newDrawing.js, which touches no template:
importing the popup's own module from attachments.js ran it before
cardDetails.jade had defined the template, and the client did not start.
Eraser is in every language. docs/Features/Cards/Drawing.md describes
it all. tests/cardDrawingPen.test.cjs tests the eraser and palm rejection
as pure functions and pins the new flows;
tests/playwright/specs/card-drawing-pen.e2e.js draws and saves both new
drawings to SVG attachments, erases a line and rejects a palm in a
browser.

Thanks to mimZD and xet7 !

Fixes #6802.
2026-10-25 06:32:28 +02:00

41 lines
1.9 KiB
JavaScript

import { Session } from 'meteor/session';
// #6802: opening a NEW drawing - the whole window, saved as an SVG attachment
// (cardDrawing.js) - from Add Card and from Add attachment. This module draws
// nothing and defines no template, so it can be imported from anywhere: the
// Drawing popup's own module touches Template.cardDrawingPopup when it is
// loaded, and importing THAT from attachments.js ran it before cardDetails.jade
// had defined the template, and the client did not start.
// #6802: open a NEW drawing of the card, maximized - the whole window - and
// saved as an SVG attachment of the card. The popup is anchored to `opener`, or
// to the opened card.
export function openNewDrawing(cardId, opener) {
if (!cardId) return;
const el = opener || document.querySelector('.js-card-details') || document.body;
Popup.open('cardDrawing', { dataContext: { _id: cardId, drawingNewFile: true } })({
currentTarget: el, target: el, preventDefault() {}, stopPropagation() {},
});
}
// #6802: after Add Card's Drawing button the new card is being opened; the
// drawing opens over it once its window is there (or after 5 s, anchored to the
// page, so it opens in any case).
export function openNewDrawingWhenOpen(cardId) {
const started = Date.now();
const tick = () => {
// The NEW card is the one on the route, and its window is drawn - an
// earlier card's window may still be there for a moment.
const routed = Session.get('currentCard') === cardId || window.location.pathname.includes(cardId);
const details = document.querySelector('.js-card-details');
if ((routed && details) || Date.now() - started > 5000) {
// A beat more, so opening the card does not close the popup it just got.
setTimeout(() => openNewDrawing(cardId, details || undefined), 250);
return;
}
setTimeout(tick, 100);
};
setTimeout(tick, 0);
}