⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(web): make note links clearly navigable (#367)
Ahmad Othman Ammar Adi6bf6106e0dc5
diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.cssindex dc14360a..9e78e82b 100644--- a/apps/web/src/app/globals.css+++ b/apps/web/src/app/globals.css@@ -630,9 +630,20 @@.sticker-note .md-content ul[data-type='taskList'] input[type='checkbox'] {accent-color: #000;}-/* --primary turns near-white in dark mode, which the pastel card does not follow. */-.sticker-note .md-content a {- color: inherit;+.sticker-note .md-content a[href]:not([href='']) {+ color: var(--color-blue-800);+ cursor: pointer;+ text-decoration-thickness: 1.5px;+ text-underline-offset: 3px;+}+.sticker-note .md-content a[href]:not([href='']):hover {+ color: var(--color-blue-950);+ background-color: color-mix(in oklab, var(--color-blue-800) 10%, transparent);+}+.sticker-note .md-content a[href]:not([href='']):focus-visible {+ border-radius: 2px;+ outline: 2px solid currentColor;+ outline-offset: 2px;}/* React Flow's default edge stroke is too dark on the canvas in both themes. */.react-flow__edge-path,diff --git a/apps/web/src/components/common/editor/linkKeyboardHandlers.ts b/apps/web/src/components/common/editor/linkKeyboardHandlers.tsindex 3975359e..1441869f 100644--- a/apps/web/src/components/common/editor/linkKeyboardHandlers.ts+++ b/apps/web/src/components/common/editor/linkKeyboardHandlers.ts@@ -1,11 +1,14 @@import type { EditorProps } from '@tiptap/pm/view';-import { openLinkOnEnter } from './modifierClickLink';+import { openLinkOnAuxClick, openLinkOnEnter } from './modifierClickLink';export function createLinkKeyboardHandlers(): EditorProps['handleDOMEvents'] {let focusedLink: HTMLAnchorElement | null = null;let pointerFocus = false;return {+ auxclick(view, event) {+ return openLinkOnAuxClick(event, view.dom);+ },focusin(view, event) {const target = event.target;if (target instanceof HTMLAnchorElement && !pointerFocus) focusedLink = target;diff --git a/apps/web/src/components/common/editor/modifierClickLink.ts b/apps/web/src/components/common/editor/modifierClickLink.tsindex 0aa25992..35f4ff1f 100644--- a/apps/web/src/components/common/editor/modifierClickLink.ts+++ b/apps/web/src/components/common/editor/modifierClickLink.ts@@ -5,6 +5,11 @@ export function openLinkOnModifierClick(event: MouseEvent, root: HTMLElement): breturn openLink(event, root);}+export function openLinkOnAuxClick(event: MouseEvent, root: HTMLElement): boolean {+ if (event.button !== 1) return false;+ return openLink(event, root);+}+export function openLinkOnEnter(event: KeyboardEvent,root: HTMLElement,diff --git a/apps/web/src/features/notes/components/StickerEditor.test.ts b/apps/web/src/features/notes/components/StickerEditor.test.tsnew file mode 100644index 00000000..ab8ad88b--- /dev/null+++ b/apps/web/src/features/notes/components/StickerEditor.test.ts@@ -0,0 +1,262 @@+import assert from 'node:assert/strict';+import { afterEach, beforeEach, describe, it } from 'node:test';+import { Editor } from '@tiptap/core';+import { JSDOM } from 'jsdom';+import { stickerEditorExtensions } from '../utils/stickerEditorExtensions';+import { createLinkKeyboardHandlers } from '@/components/common/editor/linkKeyboardHandlers';+import {+ openLinkOnAuxClick,+ openLinkOnModifierClick,+} from '@/components/common/editor/modifierClickLink';++let dom: JSDOM;+let editor: Editor | undefined;+let originalGlobalDescriptors: Map<string, PropertyDescriptor | undefined>;+let opened: unknown[][];+let updates: number;++beforeEach(() => {+ originalGlobalDescriptors = new Map(+ [+ 'window',+ 'document',+ 'navigator',+ 'DOMParser',+ 'Node',+ 'Element',+ 'HTMLElement',+ 'HTMLAnchorElement',+ 'getComputedStyle',+ ].map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)]),+ );+ dom = new JSDOM('<!doctype html><div></div>', {+ url: 'https://itsaplan.example/projects/API/notes',+ });+ Object.defineProperties(globalThis, {+ window: { configurable: true, value: dom.window },+ document: { configurable: true, value: dom.window.document },+ navigator: { configurable: true, value: dom.window.navigator },+ DOMParser: { configurable: true, value: dom.window.DOMParser },+ Node: { configurable: true, value: dom.window.Node },+ Element: { configurable: true, value: dom.window.Element },+ HTMLElement: { configurable: true, value: dom.window.HTMLElement },+ HTMLAnchorElement: { configurable: true, value: dom.window.HTMLAnchorElement },+ getComputedStyle: { configurable: true, value: dom.window.getComputedStyle.bind(dom.window) },+ });+ opened = [];+ updates = 0;+ dom.window.open = (...args: Parameters<typeof window.open>) => {+ opened.push(args);+ return null;+ };+});++afterEach(() => {+ editor?.destroy();+ editor = undefined;+ dom.window.close();+ for (const [name, descriptor] of originalGlobalDescriptors) {+ if (descriptor) Object.defineProperty(globalThis, name, descriptor);+ else Reflect.deleteProperty(globalThis, name);+ }+});++function createEditor(content = '[Documentation](/projects/API/work-items)') {+ editor = new Editor({+ element: dom.window.document.querySelector('div')!,+ extensions: stickerEditorExtensions('Write a note'),+ content,+ editable: true,+ onUpdate: () => updates++,+ editorProps: {+ handleClick(view, _pos, event) {+ return openLinkOnModifierClick(event, view.dom);+ },+ handleDOMEvents: createLinkKeyboardHandlers(),+ handleScrollToSelection: () => true,+ },+ });+ return editor;+}++function mouseEvent(target: Element, type: string, options: MouseEventInit = {}) {+ const event = new dom.window.MouseEvent(type, {+ bubbles: true,+ cancelable: true,+ button: 0,+ ...options,+ });+ target.dispatchEvent(event);+ return event;+}++describe('StickerEditor links', () => {+ it('registers one link extension and renders keyboard-reachable internal destinations', () => {+ const editor = createEditor();+ assert.equal(+ editor.extensionManager.extensions.filter((extension) => extension.name === 'link').length,+ 1,+ );+ const link = editor.view.dom.querySelector('a')!;+ assert.equal(link.getAttribute('href'), '/projects/API/work-items');+ assert.equal(link.getAttribute('tabindex'), '0');+ assert.equal(link.classList.contains('cursor-pointer'), true);+ assert.equal(+ editor.storage.markdown.getMarkdown(),+ '[Documentation](/projects/API/work-items)',+ );+ });++ it('preserves relative destinations in markdown and rendered links', () => {+ const editor = createEditor('[Relative](../work-items) and [Section](#details)');+ assert.deepEqual(+ [...editor.view.dom.querySelectorAll('a')].map((link) => link.getAttribute('href')),+ ['../work-items', '#details'],+ );+ assert.equal(+ editor.storage.markdown.getMarkdown(),+ '[Relative](../work-items) and [Section](#details)',+ );+ });++ it('opens an ordinary link click while the note is editable', () => {+ const editor = createEditor();+ const markdown = editor.storage.markdown.getMarkdown();+ const link = editor.view.dom.querySelector('a')!;+ const click = mouseEvent(link, 'click');+ assert.equal(openLinkOnModifierClick(click, editor.view.dom), false);+ const handled = editor.view.someProp('handleClick', (handler) =>+ handler(editor.view, 1, click),+ );+ assert.equal(handled, true);+ assert.equal(editor.isEditable, true);+ assert.equal(opened.length, 1);+ assert.equal(+ new URL(String(opened[0]?.[0]), dom.window.location.href).href,+ 'https://itsaplan.example/projects/API/work-items',+ );+ assert.equal(opened[0]?.[1], '_blank');+ assert.equal(editor.storage.markdown.getMarkdown(), markdown);+ assert.equal(updates, 0);+ });++ it('opens real rendered links with Ctrl, Cmd, or the middle mouse button', () => {+ const editor = createEditor();+ const link = editor.view.dom.querySelector('a')!;+ for (const modifier of [{ ctrlKey: true }, { metaKey: true }]) {+ const click = mouseEvent(link, 'click', modifier);+ assert.equal(+ editor.view.someProp('handleClick', (handler) => handler(editor.view, 1, click)),+ true,+ );+ assert.equal(click.defaultPrevented, true);+ }+ const middle = mouseEvent(link, 'auxclick', { button: 1 });+ assert.equal(middle.defaultPrevented, true);+ assert.deepEqual(+ opened,+ Array.from({ length: 3 }, () => [+ 'https://itsaplan.example/projects/API/work-items',+ '_blank',+ 'noopener,noreferrer',+ ]),+ );+ });++ it('does not open plain text or unsafe protocols through either click handler', () => {+ const editor = createEditor('Ordinary text\n\n[Documentation](https://example.com)');+ const paragraph = editor.view.dom.querySelector('p')!;+ const plain = mouseEvent(paragraph, 'click', { ctrlKey: true });+ assert.equal(openLinkOnModifierClick(plain, editor.view.dom), false);+ assert.equal(+ openLinkOnAuxClick(mouseEvent(paragraph, 'auxclick', { button: 1 }), editor.view.dom),+ false,+ );+ const link = editor.view.dom.querySelector('a')!;+ for (const href of ['javascript:alert(1)', 'data:text/html,unsafe', 'file:///etc/passwd']) {+ link.setAttribute('href', href);+ const click = mouseEvent(link, 'click', { ctrlKey: true });+ assert.equal(openLinkOnModifierClick(click, editor.view.dom), false);+ assert.equal(+ openLinkOnAuxClick(mouseEvent(link, 'auxclick', { button: 1 }), editor.view.dom),+ false,+ );+ }+ assert.deepEqual(opened, []);+ });++ it('does not render unsafe markdown destinations as usable links', () => {+ const editor = createEditor(+ '[Script](javascript:alert%281%29) [Data](data:text/html;base64,PHNjcmlwdD4=) [File](file:///etc/passwd) [Safe](https://example.com/docs)',+ );+ assert.deepEqual(+ [...editor.view.dom.querySelectorAll('a[href]')].map((link) => link.getAttribute('href')),+ ['https://example.com/docs'],+ );+ assert.deepEqual(opened, []);+ });++ it('opens Enter on a keyboard-focused link', () => {+ const editor = createEditor();+ const link = editor.view.dom.querySelector('a')!;+ link.focus();+ assert.equal(dom.window.document.activeElement, link);+ const enter = new dom.window.KeyboardEvent('keydown', {+ key: 'Enter',+ bubbles: true,+ cancelable: true,+ });+ link.dispatchEvent(enter);+ assert.equal(enter.defaultPrevented, true);+ assert.deepEqual(opened, [+ ['https://itsaplan.example/projects/API/work-items', '_blank', 'noopener,noreferrer'],+ ]);+ });++ it('retains keyboard link focus when the browser delivers Enter to the editing host', () => {+ const editor = createEditor();+ const link = editor.view.dom.querySelector('a')!;+ link.focus();+ editor.view.dom.focus();+ const enter = new dom.window.KeyboardEvent('keydown', {+ key: 'Enter',+ bubbles: true,+ cancelable: true,+ });+ editor.view.dom.dispatchEvent(enter);+ assert.equal(enter.defaultPrevented, true);+ assert.equal(opened.length, 1);+ });++ it('does not open a link when pointer editing focus returns Enter to the host', () => {+ const editor = createEditor();+ const link = editor.view.dom.querySelector('a')!;+ mouseEvent(link, 'pointerdown');+ link.focus();+ mouseEvent(link, 'pointerup');+ editor.view.dom.focus();+ const enter = new dom.window.KeyboardEvent('keydown', {+ key: 'Enter',+ bubbles: true,+ cancelable: true,+ });+ editor.view.dom.dispatchEvent(enter);+ assert.deepEqual(opened, []);+ });++ it('does not open links when Enter edits ordinary note content', () => {+ const editor = createEditor('Editable note content');+ editor.commands.setTextSelection(9);+ const documentBefore = editor.getJSON();+ editor.view.dom.focus();+ const enter = new dom.window.KeyboardEvent('keydown', {+ key: 'Enter',+ bubbles: true,+ cancelable: true,+ });+ editor.view.dom.dispatchEvent(enter);+ assert.deepEqual(opened, []);+ assert.notDeepEqual(editor.getJSON(), documentBefore);+ assert.equal(updates, 1);+ });+});diff --git a/apps/web/src/features/notes/components/StickerEditor.tsx b/apps/web/src/features/notes/components/StickerEditor.tsxindex 442425f6..e2271c64 100644--- a/apps/web/src/features/notes/components/StickerEditor.tsx+++ b/apps/web/src/features/notes/components/StickerEditor.tsx@@ -1,17 +1,11 @@-import { useEffect } from 'react';+import { useEffect, useMemo } from 'react';import { useEditor, EditorContent, type Editor } from '@tiptap/react';-import StarterKit from '@tiptap/starter-kit';-import Placeholder from '@tiptap/extension-placeholder';-import TaskList from '@tiptap/extension-task-list';-import TaskItem from '@tiptap/extension-task-item';-import { Markdown } from 'tiptap-markdown';import { useTranslations } from 'next-intl';import EditorLinkPreview from '@/components/common/editor/EditorLinkPreview';+import { openLinkOnModifierClick } from '@/components/common/editor/modifierClickLink';+import { createLinkKeyboardHandlers } from '@/components/common/editor/linkKeyboardHandlers';+import { stickerEditorExtensions } from '../utils/stickerEditorExtensions';-// The markdown body of a sticky note. Unlike the issue editor there is no bubble-// menu — a persistent toolbar (StickerToolbar) drives the commands — and task-// lists are enabled so a note can mix text with checkable items. Content in and-// out is markdown, matching how it is stored on the board canvas.export default function StickerEditor({value,onChange,@@ -24,17 +18,18 @@ export default function StickerEditor({editable: boolean;}) {const t = useTranslations('notes');+ const linkKeyboardHandlers = useMemo(createLinkKeyboardHandlers, []);const editor = useEditor({editable,- extensions: [- StarterKit,- Placeholder.configure({ placeholder: t('notePlaceholder') }),- TaskList,- TaskItem.configure({ nested: true }),- Markdown.configure({ html: false, breaks: true }),- ],+ extensions: stickerEditorExtensions(t('notePlaceholder')),content: value,- editorProps: { attributes: { class: 'md-content focus:outline-none' } },+ editorProps: {+ attributes: { class: 'md-content nopan focus:outline-none' },+ handleClick(view, _pos, event) {+ return openLinkOnModifierClick(event, view.dom);+ },+ handleDOMEvents: linkKeyboardHandlers,+ },onUpdate: ({ editor }) => onChange(editor.storage.markdown.getMarkdown()),});@@ -42,6 +37,10 @@ export default function StickerEditor({onReady?.(editor);}, [editor, onReady]);+ useEffect(() => {+ if (editor && editor.isEditable !== editable) editor.setEditable(editable, false);+ }, [editor, editable]);+if (!editor) return null;return (<>diff --git a/apps/web/src/features/notes/utils/stickerEditorExtensions.ts b/apps/web/src/features/notes/utils/stickerEditorExtensions.tsnew file mode 100644index 00000000..d31e96bf--- /dev/null+++ b/apps/web/src/features/notes/utils/stickerEditorExtensions.ts@@ -0,0 +1,20 @@+import StarterKit from '@tiptap/starter-kit';+import Link from '@tiptap/extension-link';+import Placeholder from '@tiptap/extension-placeholder';+import TaskList from '@tiptap/extension-task-list';+import TaskItem from '@tiptap/extension-task-item';+import { Markdown } from 'tiptap-markdown';++export function stickerEditorExtensions(placeholder: string) {+ return [+ StarterKit.configure({ link: false }),+ Link.configure({+ openOnClick: true,+ HTMLAttributes: { class: 'cursor-pointer', tabindex: '0' },+ }),+ Placeholder.configure({ placeholder }),+ TaskList,+ TaskItem.configure({ nested: true }),+ Markdown.configure({ html: false, linkify: true, breaks: true }),+ ];+}