mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Eight themes (nephritis, pumpkin, moderatepink, strongcyan, limegreen, relax, corteza, modern) had white text on an accent at 2.1 to 4.3:1: their accents and hover, selected and emphasis shades are darkened until it reads at 4.5:1. The filter sidebar's headings, the clear themes' quiet text and cleanlight's add-dependency link are darker. A color a member chooses is made legible: a custom theme accent or slide end is darkened under the header's white text, the text color is moved to read on the theme's surfaces and no longer reaches the header, labels and primary buttons, a dependency line is drawn at 3:1, Kanri's tag text is the better of dark and light, and a custom label, card, list or swimlane color already derives its text. All 25 themes show no colour contrast failure on the board, the sidebars, Card Settings, the card and its popups. Thanks to Samunosuke and xet7 !
387 lines
15 KiB
JavaScript
387 lines
15 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import { Utils } from '/client/lib/utils';
|
|
import { ensureContrast } from '/models/lib/contrastColor';
|
|
import { surfacesFor } from '/models/lib/uiFonts';
|
|
import { activeThemeName } from '/client/lib/activeTheme';
|
|
import {
|
|
DEPENDENCY_ICON_CHOICES,
|
|
DEPENDENCY_TYPES,
|
|
dependencyTypeMeta,
|
|
normalizeDependencies,
|
|
} from '/models/metadata/dependencies';
|
|
import { dependencyVisibility, myDependencyLines, newLineLayer, canEditBoardDependenciesHere } from '/client/lib/dependencyLayers';
|
|
|
|
// #3392: PI Program Board "Red Strings".
|
|
// Draw colored, typed connection lines (SVG paths) between cards that declare
|
|
// cardDependencies. The board stays fully usable (cards clickable) — drawing a
|
|
// new link is initiated from a small connect handle on each minicard (drag it
|
|
// onto another card, piplanning.io / Kendis / Miro style), and a link can be
|
|
// edited/deleted by clicking its line. The overlay SVG itself stays
|
|
// pointer-events:none; only the lines (and the minicard handles) capture events.
|
|
//
|
|
// Coordinates are computed from the live DOM (getBoundingClientRect of
|
|
// [data-card-id] minicards) translated into the overlay SVG's own coordinate
|
|
// space, so scrolling/resizing is handled by recomputing relative to the SVG's
|
|
// current bounding rect.
|
|
|
|
// Stable, css-safe marker id for an arrowhead of a given color.
|
|
function markerIdForColor(color) {
|
|
return `dependency-arrowhead-${String(color).replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
}
|
|
|
|
Template.dependencyOverlay.onCreated(function () {
|
|
this.lines = new ReactiveVar([]);
|
|
this.markers = new ReactiveVar([]);
|
|
this.tempLine = new ReactiveVar(null); // line being drawn while dragging
|
|
// Guard against deferred (rAF / setTimeout) callbacks touching the DOM after
|
|
// the overlay is destroyed ("Can't select in removed DomRange").
|
|
this._overlayDestroyed = false;
|
|
|
|
// Whether `el` has any on-screen area left once every scrolling/clipping
|
|
// ancestor's overflow box is accounted for. The overlay is one SVG drawn
|
|
// over the whole board (not clipped per swimlane), so without this a card
|
|
// scrolled or resized out of its swimlane's view (e.g. #6675: dragging a
|
|
// swimlane shorter) still reports its full, unclipped getBoundingClientRect
|
|
// — the line would then visibly run past that swimlane's boundary and lie
|
|
// on top of the next one, even though the card itself is not visible there.
|
|
// A dependency to/from a DIFFERENT, still-visible swimlane is unaffected:
|
|
// that swimlane's own rect clips its own card independently.
|
|
function hasVisibleArea(el) {
|
|
let rect = el.getBoundingClientRect();
|
|
let node = el.parentElement;
|
|
while (node && node !== document.body && node !== document.documentElement) {
|
|
const style = window.getComputedStyle(node);
|
|
const clipsY = /(hidden|auto|scroll|clip)/.test(style.overflowY);
|
|
const clipsX = /(hidden|auto|scroll|clip)/.test(style.overflowX);
|
|
if (clipsX || clipsY) {
|
|
const parentRect = node.getBoundingClientRect();
|
|
const top = clipsY ? Math.max(rect.top, parentRect.top) : rect.top;
|
|
const bottom = clipsY ? Math.min(rect.bottom, parentRect.bottom) : rect.bottom;
|
|
const left = clipsX ? Math.max(rect.left, parentRect.left) : rect.left;
|
|
const right = clipsX ? Math.min(rect.right, parentRect.right) : rect.right;
|
|
if (bottom <= top || right <= left) return false;
|
|
rect = { top, bottom, left, right };
|
|
}
|
|
node = node.parentElement;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Rect of a card relative to the overlay SVG, or null if not rendered or
|
|
// clipped out of view by a scrolled/resized ancestor (see hasVisibleArea).
|
|
this.rectOf = (cardId, svgRect) => {
|
|
const el = document.querySelector(`[data-card-id="${cardId}"]`);
|
|
if (!el) return null;
|
|
const r = el.getBoundingClientRect();
|
|
if (r.width === 0 && r.height === 0) return null;
|
|
if (!hasVisibleArea(el)) return null;
|
|
return { x: r.left - svgRect.left, y: r.top - svgRect.top, w: r.width, h: r.height };
|
|
};
|
|
|
|
this.recompute = () => {
|
|
if (this._overlayDestroyed || !this.view || this.view.isDestroyed) {
|
|
return;
|
|
}
|
|
const svg = this.find('.js-dependency-overlay');
|
|
if (!svg) {
|
|
return;
|
|
}
|
|
const board = Utils.getCurrentBoard();
|
|
if (!board) {
|
|
this.lines.set([]);
|
|
return;
|
|
}
|
|
|
|
const svgRect = svg.getBoundingClientRect();
|
|
const centerOf = cardId => this.rectOf(cardId, svgRect);
|
|
|
|
const cards = ReactiveCache.getCards({
|
|
boardId: board._id,
|
|
archived: false,
|
|
});
|
|
|
|
const lines = [];
|
|
const markerColors = new Set();
|
|
// #6732: the Board Dependencies (on the cards) and this user's own My
|
|
// Dependencies (in their profile), each only when this user shows it.
|
|
const shown = dependencyVisibility();
|
|
const sources = [];
|
|
if (shown.board) {
|
|
cards.forEach(card => sources.push({ cardId: card._id, layer: 'board',
|
|
deps: normalizeDependencies(card.cardDependencies) }));
|
|
}
|
|
if (shown.mine) {
|
|
myDependencyLines(board._id).forEach(row => sources.push({ cardId: row.cardId, layer: 'mine',
|
|
deps: [{ cardId: row.targetCardId, type: row.type, color: row.color, icon: row.icon }] }));
|
|
}
|
|
sources.forEach(({ cardId, layer, deps }) => {
|
|
if (deps.length === 0) {
|
|
return;
|
|
}
|
|
const sourceRect = centerOf(cardId);
|
|
if (!sourceRect) {
|
|
return;
|
|
}
|
|
deps.forEach(dep => {
|
|
const targetRect = centerOf(dep.cardId);
|
|
if (!targetRect) {
|
|
return;
|
|
}
|
|
const meta = dependencyTypeMeta(dep.type);
|
|
// Draw the arrow from the prerequisite card's right edge to the
|
|
// dependent card's left edge. For forward relations (blocks/fixes/
|
|
// duplicates/related-to) the source card is the starting end; for reverse
|
|
// relations (is-blocked-by/is-fixed-by/is-duplicated-by) the target is.
|
|
const prereq = meta.forward ? sourceRect : targetRect;
|
|
const dependent = meta.forward ? targetRect : sourceRect;
|
|
const x1 = prereq.x + prereq.w;
|
|
const y1 = prereq.y + prereq.h / 2;
|
|
const x2 = dependent.x;
|
|
const y2 = dependent.y + dependent.h / 2;
|
|
const dx = Math.max(40, Math.abs(x2 - x1) / 2);
|
|
const path = `M ${x1} ${y1} C ${x1 + dx} ${y1}, ${x2 - dx} ${y2}, ${x2} ${y2}`;
|
|
// The colour is the member's free choice (a colour wheel), drawn over the
|
|
// board: made visible against the theme's surface - a line is a graphic
|
|
// that says something, 3:1 (WCAG 1.4.11). The stored colour is untouched.
|
|
const drawColor = ensureContrast(dep.color, surfacesFor(activeThemeName()), 3);
|
|
const markerId = markerIdForColor(drawColor);
|
|
if (meta.directed) {
|
|
markerColors.add(drawColor);
|
|
}
|
|
lines.push({
|
|
path,
|
|
color: drawColor,
|
|
type: dep.type,
|
|
icon: dep.icon,
|
|
directed: meta.directed,
|
|
markerId: meta.directed ? markerId : '',
|
|
// Source card (owns the dependency) and target card.
|
|
fromId: cardId,
|
|
toId: dep.cardId,
|
|
boardId: board._id,
|
|
layer,
|
|
mine: layer === 'mine',
|
|
});
|
|
});
|
|
});
|
|
this.lines.set(lines);
|
|
this.markers.set(
|
|
[...markerColors].map(color => ({
|
|
color,
|
|
markerId: markerIdForColor(color),
|
|
})),
|
|
);
|
|
};
|
|
|
|
this.scheduleRecompute = () => {
|
|
if (this._overlayDestroyed) return;
|
|
if (this._raf) {
|
|
window.cancelAnimationFrame(this._raf);
|
|
}
|
|
this._raf = window.requestAnimationFrame(() => {
|
|
this._raf = null;
|
|
this.recompute();
|
|
});
|
|
};
|
|
});
|
|
|
|
Template.dependencyOverlay.onRendered(function () {
|
|
const instance = this;
|
|
const svg = this.find('.js-dependency-overlay');
|
|
this.scrollEl = svg ? this.firstNode.closest('.board-canvas') : null;
|
|
|
|
this.autorun(() => {
|
|
const board = Utils.getCurrentBoard();
|
|
if (board) {
|
|
ReactiveCache.getCards({ boardId: board._id, archived: false });
|
|
// The user's switches and own lines are reactive too (#6732).
|
|
dependencyVisibility();
|
|
myDependencyLines(board._id);
|
|
}
|
|
instance.scheduleRecompute();
|
|
});
|
|
|
|
this.onScroll = () => instance.scheduleRecompute();
|
|
this.onResize = () => instance.scheduleRecompute();
|
|
// #6675: dragging a swimlane's own height handle (swimlanes.js) changes no
|
|
// scroll position and fires no window resize, so without this dedicated
|
|
// event the overlay never learns a card it was drawing to/from is now
|
|
// clipped out of view.
|
|
this.onSwimlaneResize = () => instance.scheduleRecompute();
|
|
|
|
if (this.scrollEl) {
|
|
this.scrollEl.addEventListener('scroll', this.onScroll, { passive: true });
|
|
}
|
|
window.addEventListener('scroll', this.onScroll, { passive: true });
|
|
window.addEventListener('resize', this.onResize);
|
|
window.addEventListener('wekan-swimlane-resized', this.onSwimlaneResize);
|
|
|
|
// --- drag-to-connect (from a minicard's connect handle) -----------------
|
|
// Find the card under a viewport point. The overlay is pointer-events:none,
|
|
// so elementsFromPoint returns the minicards directly.
|
|
const cardIdAtPoint = (clientX, clientY) => {
|
|
const els = document.elementsFromPoint(clientX, clientY);
|
|
for (const el of els) {
|
|
if (svg && svg.contains(el)) continue;
|
|
const card = el.closest && el.closest('[data-card-id]');
|
|
if (card) return card.getAttribute('data-card-id');
|
|
}
|
|
return null;
|
|
};
|
|
|
|
this.onMouseDown = e => {
|
|
if (e.button !== 0) return;
|
|
const handle =
|
|
e.target.closest && e.target.closest('.js-dependency-connect-handle');
|
|
if (!handle) return;
|
|
const cardEl = handle.closest('[data-card-id]');
|
|
if (!cardEl) return;
|
|
// Beat the card drag-sort: capture-phase + stop propagation.
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
instance.dragSourceId = cardEl.getAttribute('data-card-id');
|
|
};
|
|
|
|
this.onMouseMove = e => {
|
|
if (!instance.dragSourceId || !svg) return;
|
|
const svgRect = svg.getBoundingClientRect();
|
|
const from = instance.rectOf(instance.dragSourceId, svgRect);
|
|
if (!from) return;
|
|
const x1 = from.x + from.w;
|
|
const y1 = from.y + from.h / 2;
|
|
const x2 = e.clientX - svgRect.left;
|
|
const y2 = e.clientY - svgRect.top;
|
|
const dx = Math.max(40, Math.abs(x2 - x1) / 2);
|
|
instance.tempLine.set(
|
|
`M ${x1} ${y1} C ${x1 + dx} ${y1}, ${x2 - dx} ${y2}, ${x2} ${y2}`,
|
|
);
|
|
};
|
|
|
|
this.onMouseUp = e => {
|
|
if (!instance.dragSourceId) return;
|
|
const sourceId = instance.dragSourceId;
|
|
instance.dragSourceId = null;
|
|
instance.tempLine.set(null);
|
|
const targetId = cardIdAtPoint(e.clientX, e.clientY);
|
|
if (targetId && targetId !== sourceId) {
|
|
// #6732: into the layer a new line goes to (client/lib/dependencyLayers.js).
|
|
const card = ReactiveCache.getCard(sourceId);
|
|
const layer = card && newLineLayer(ReactiveCache.getBoard(card.boardId));
|
|
if (layer === 'mine') {
|
|
Meteor.callAsync('setMyDependency', sourceId, targetId, {}).catch(() => {});
|
|
} else if (layer === 'board' && typeof card.addDependency === 'function') {
|
|
Promise.resolve(card.addDependency(targetId)).catch(() => {});
|
|
}
|
|
}
|
|
};
|
|
|
|
// Capture phase so the connect drag starts before the sortable grabs the card.
|
|
document.addEventListener('mousedown', this.onMouseDown, true);
|
|
document.addEventListener('mousemove', this.onMouseMove);
|
|
document.addEventListener('mouseup', this.onMouseUp);
|
|
|
|
this._initTimeout = Meteor.setTimeout(() => instance.scheduleRecompute(), 300);
|
|
});
|
|
|
|
Template.dependencyOverlay.onDestroyed(function () {
|
|
this._overlayDestroyed = true;
|
|
if (this.scrollEl) {
|
|
this.scrollEl.removeEventListener('scroll', this.onScroll);
|
|
}
|
|
window.removeEventListener('scroll', this.onScroll);
|
|
window.removeEventListener('resize', this.onResize);
|
|
window.removeEventListener('wekan-swimlane-resized', this.onSwimlaneResize);
|
|
if (this.onMouseDown) document.removeEventListener('mousedown', this.onMouseDown, true);
|
|
if (this.onMouseMove) document.removeEventListener('mousemove', this.onMouseMove);
|
|
if (this.onMouseUp) document.removeEventListener('mouseup', this.onMouseUp);
|
|
if (this._raf) {
|
|
window.cancelAnimationFrame(this._raf);
|
|
}
|
|
if (this._initTimeout) {
|
|
Meteor.clearTimeout(this._initTimeout);
|
|
}
|
|
});
|
|
|
|
Template.dependencyOverlay.helpers({
|
|
dependencyLines() {
|
|
return Template.instance().lines.get();
|
|
},
|
|
dependencyMarkers() {
|
|
return Template.instance().markers.get();
|
|
},
|
|
tempLine() {
|
|
return Template.instance().tempLine.get();
|
|
},
|
|
markerUrl() {
|
|
return this.markerId ? `url(#${this.markerId})` : '';
|
|
},
|
|
});
|
|
|
|
Template.dependencyOverlay.events({
|
|
'click .dependency-line'(event) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
// `this` is the line data object (fromId/toId/type/color/icon).
|
|
Popup.open('dependencyLine').call(this, event);
|
|
},
|
|
});
|
|
|
|
// #3392: popup to edit or delete an on-board dependency line. Data context is the
|
|
// line object { fromId, toId, type, color, icon }.
|
|
Template.dependencyLinePopup.helpers({
|
|
// #6732: a My Dependency is always its owner's to edit; a Board Dependency
|
|
// only for a role that may edit or move cards (the server checks again).
|
|
canEditLine() {
|
|
return this.layer === 'mine' || canEditBoardDependenciesHere(ReactiveCache.getBoard(this.boardId));
|
|
},
|
|
isMine() {
|
|
return this.layer === 'mine';
|
|
},
|
|
typeOption() {
|
|
const current = this.type;
|
|
return DEPENDENCY_TYPES.map(t => ({
|
|
id: t.id,
|
|
label: `dependency-type-${t.id}`,
|
|
selected: t.id === current,
|
|
}));
|
|
},
|
|
color() {
|
|
return this.color;
|
|
},
|
|
dependencyIcons() {
|
|
const current = this.icon;
|
|
return DEPENDENCY_ICON_CHOICES.map(name => ({ name, selected: name === current }));
|
|
},
|
|
});
|
|
|
|
// Each change goes to the line's own layer.
|
|
function setLineProps(line, props) {
|
|
if (line.layer === 'mine') {
|
|
return Meteor.callAsync('setMyDependency', line.fromId, line.toId, props).catch(() => {});
|
|
}
|
|
const card = ReactiveCache.getCard(line.fromId);
|
|
return card ? Promise.resolve(card.setDependencyProps(line.toId, props)).catch(() => {}) : undefined;
|
|
}
|
|
|
|
Template.dependencyLinePopup.events({
|
|
'change .js-line-type'(event) {
|
|
setLineProps(this, { type: event.currentTarget.value });
|
|
},
|
|
'change .js-line-color'(event) {
|
|
setLineProps(this, { color: event.currentTarget.value });
|
|
},
|
|
'click .js-line-icon'(event) {
|
|
setLineProps(this, { icon: event.currentTarget.dataset.icon });
|
|
},
|
|
'click .js-line-delete'() {
|
|
if (this.layer === 'mine') {
|
|
Meteor.callAsync('removeMyDependency', this.boardId, this.fromId, this.toId).catch(() => {});
|
|
} else {
|
|
const card = ReactiveCache.getCard(this.fromId);
|
|
if (card) Promise.resolve(card.removeDependency(this.toId)).catch(() => {});
|
|
}
|
|
Popup.back();
|
|
},
|
|
});
|