Skip to content

⭐️⭐️⭐️ 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.

feat: paste markdown into the editors (#330)

Croffc4f5cd0166fa
diff --git a/apps/api/src/modules/documents/__tests__/integration/documents.test.ts b/apps/api/src/modules/documents/__tests__/integration/documents.test.ts
index fbf97161..a2fdf795 100644
--- a/apps/api/src/modules/documents/__tests__/integration/documents.test.ts
+++ b/apps/api/src/modules/documents/__tests__/integration/documents.test.ts
@@ -1298,6 +1298,7 @@ describe('documents', () => {
target: '_blank',
rel: 'noopener noreferrer',
class: 'docs-link',
+ title: 'Docs',
},
},
{ type: 'textStyle', attrs: { color: '#abcdef' } },
@@ -1329,6 +1330,26 @@ describe('documents', () => {
attrs: { src: `/projects/MKT/documents/1/assets/${assetId}/raw` },
},
{ type: 'image', attrs: { src: 'https://example.com/diagram.png' } },
+ {
+ type: 'bulletList',
+ attrs: { tight: true },
+ content: [
+ {
+ type: 'listItem',
+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Bullet' }] }],
+ },
+ ],
+ },
+ {
+ type: 'orderedList',
+ attrs: { start: 1, tight: true, type: null },
+ content: [
+ {
+ type: 'listItem',
+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Step' }] }],
+ },
+ ],
+ },
{
type: 'taskList',
content: [
@@ -1352,7 +1373,7 @@ describe('documents', () => {
},
{
type: 'tableCell',
- attrs: { colspan: 2, rowspan: 1, colwidth: null },
+ attrs: { colspan: 2, rowspan: 1, colwidth: null, align: 'center' },
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Cell' }] }],
},
],
@@ -1409,6 +1430,10 @@ describe('documents', () => {
withNode({ type: 'tableHeader', attrs: { rowspan: 101 } }),
withNode({ type: 'tableCell', attrs: { colwidth: [] } }),
withNode({ type: 'tableCell', attrs: { colwidth: [0] } }),
+ withNode({ type: 'tableCell', attrs: { align: 'justify' } }),
+ withNode({ type: 'bulletList', attrs: { tight: 'yes' } }),
+ withNode({ type: 'orderedList', attrs: { type: 'x' } }),
+ withMark({ type: 'link', attrs: { href: 'https://example.com', title: 'x'.repeat(1_001) } }),
withMark({ type: 'textStyle', attrs: { color: 'rgb(255, 0, 0)' } }),
withMark({ type: 'highlight', attrs: { color: '#12' } }),
withMark({ type: 'highlight', attrs: { color: '#12345' } }),
diff --git a/apps/api/src/modules/documents/service.ts b/apps/api/src/modules/documents/service.ts
index 4550508f..97fd1958 100644
--- a/apps/api/src/modules/documents/service.ts
+++ b/apps/api/src/modules/documents/service.ts
@@ -651,6 +651,8 @@ const DOCUMENT_MARK_TYPES = new Set([
'highlight',
]);
+const TEXT_ALIGN = ['left', 'center', 'right'] as const;
+
function isRecord(value: unknown): value is Record<string, unknown> {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}
@@ -681,6 +683,21 @@ function assertAllowedAttributes(
if (unknown) throw new HttpError(400, `${context} contains an unsupported "${unknown}" attr.`);
}
+function assertOptionalBoolean(value: unknown, context: string): void {
+ if (value != null && typeof value !== 'boolean') {
+ throw new HttpError(400, `${context} must be a boolean.`);
+ }
+}
+
+function assertOptionalOneOf(value: unknown, allowed: readonly string[], context: string): void {
+ if (value == null || allowed.includes(String(value))) return;
+ const list =
+ allowed.length < 3
+ ? allowed.join(' or ')
+ : `${allowed.slice(0, -1).join(', ')}, or ${allowed[allowed.length - 1]}`;
+ throw new HttpError(400, `${context} must be ${list}.`);
+}
+
function assertOptionalBoundedString(value: unknown, maximum: number, context: string): void {
if (value == null) return;
if (typeof value !== 'string' || value.length > maximum) {
@@ -764,24 +781,14 @@ function assertDocumentNodeAttributes(node: Record<string, unknown>): void {
switch (node.type) {
case 'paragraph':
assertAllowedAttributes(attrs, ['textAlign'], 'A paragraph');
- if (
- attrs.textAlign != null &&
- !['left', 'center', 'right'].includes(String(attrs.textAlign))
- ) {
- throw new HttpError(400, 'Paragraph textAlign must be left, center, or right.');
- }
+ assertOptionalOneOf(attrs.textAlign, TEXT_ALIGN, 'Paragraph textAlign');
return;
case 'heading':
assertAllowedAttributes(attrs, ['level', 'textAlign'], 'A heading');
if (!Number.isInteger(attrs.level) || Number(attrs.level) < 1 || Number(attrs.level) > 6) {
throw new HttpError(400, 'Heading level must be an integer from 1 to 6.');
}
- if (
- attrs.textAlign != null &&
- !['left', 'center', 'right'].includes(String(attrs.textAlign))
- ) {
- throw new HttpError(400, 'Heading textAlign must be left, center, or right.');
- }
+ assertOptionalOneOf(attrs.textAlign, TEXT_ALIGN, 'Heading textAlign');
return;
case 'image': {
assertAllowedAttributes(attrs, ['src', 'alt', 'title', 'width', 'style'], 'An image');
@@ -810,7 +817,8 @@ function assertDocumentNodeAttributes(node: Record<string, unknown>): void {
return;
case 'tableCell':
case 'tableHeader': {
- assertAllowedAttributes(attrs, ['colspan', 'rowspan', 'colwidth'], 'A table cell');
+ assertAllowedAttributes(attrs, ['colspan', 'rowspan', 'colwidth', 'align'], 'A table cell');
+ assertOptionalOneOf(attrs.align, TEXT_ALIGN, 'Table cell align');
for (const key of ['colspan', 'rowspan'] as const) {
const span = attrs[key];
if (
@@ -833,8 +841,14 @@ function assertDocumentNodeAttributes(node: Record<string, unknown>): void {
}
return;
}
+ case 'bulletList':
+ assertAllowedAttributes(attrs, ['tight'], 'A bullet list');
+ assertOptionalBoolean(attrs.tight, 'List tight');
+ return;
case 'orderedList':
- assertAllowedAttributes(attrs, ['start'], 'An ordered list');
+ assertAllowedAttributes(attrs, ['start', 'tight', 'type'], 'An ordered list');
+ assertOptionalBoolean(attrs.tight, 'List tight');
+ assertOptionalOneOf(attrs.type, ['a', 'A', 'i', 'I', '1'], 'Ordered-list type');
if (
attrs.start !== undefined &&
(!Number.isInteger(attrs.start) ||
@@ -857,11 +871,10 @@ function assertDocumentMarkAttributes(mark: Record<string, unknown>): void {
const attrs = documentAttributes(mark);
switch (mark.type) {
case 'link':
- assertAllowedAttributes(attrs, ['href', 'target', 'rel', 'class'], 'A link');
+ assertAllowedAttributes(attrs, ['href', 'target', 'rel', 'class', 'title'], 'A link');
+ assertOptionalBoundedString(attrs.title, 1_000, 'Link title');
assertSafeLinkHref(attrs.href);
- if (attrs.target != null && !['_blank', '_self'].includes(String(attrs.target))) {
- throw new HttpError(400, 'Link target must be _blank or _self.');
- }
+ assertOptionalOneOf(attrs.target, ['_blank', '_self'], 'Link target');
assertOptionalBoundedString(attrs.rel, 200, 'Link rel');
if (typeof attrs.rel === 'string' && !/^[a-z -]*$/i.test(attrs.rel)) {
throw new HttpError(400, 'Link rel contains unsupported characters.');
diff --git a/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts b/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts
index 73d15063..60555f22 100644
--- a/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts
+++ b/apps/api/src/modules/initiatives/__tests__/integration/initiatives.test.ts
@@ -87,6 +87,26 @@ describe('initiatives', () => {
expect(res.status).toBe(400);
});
+ it('rejects a target date before the start date on create', async () => {
+ const { asOwner } = await setup();
+ const res = await createInitiative(asOwner, {
+ title: 'Q3',
+ startDate: '2026-09-08',
+ targetDate: '2026-08-30',
+ });
+ expect(res.status).toBe(400);
+ });
+
+ it('allows a target date equal to the start date', async () => {
+ const { asOwner } = await setup();
+ const res = await createInitiative(asOwner, {
+ title: 'Q3',
+ startDate: '2026-09-08',
+ targetDate: '2026-09-08',
+ });
+ expect(res.status).toBe(201);
+ });
+
it('rejects an owner and labels from another project before creating', async () => {
const { asOwner } = await setup();
const outsider = await signUpTestUser({ name: 'Outsider' });
@@ -207,6 +227,26 @@ describe('initiatives', () => {
expect(got.data).toMatchObject({ id: created.id, title: 'Q3' });
});
+ it('rejects a target date patched before the stored start date', async () => {
+ const { asOwner } = await setup();
+ const created = (await createInitiative(asOwner, { title: 'Q3', startDate: '2026-09-08' }))
+ .data!;
+ const res = await asOwner
+ .initiatives({ initiativeId: created.id })
+ .patch({ targetDate: '2026-08-30' });
+ expect(res.status).toBe(400);
+ });
+
+ it('rejects a start date patched after the stored target date', async () => {
+ const { asOwner } = await setup();
+ const created = (await createInitiative(asOwner, { title: 'Q3', targetDate: '2026-08-30' }))
+ .data!;
+ const res = await asOwner
+ .initiatives({ initiativeId: created.id })
+ .patch({ startDate: '2026-09-08' });
+ expect(res.status).toBe(400);
+ });
+
it('returns 404 for a missing initiative', async () => {
const { asOwner } = await setup();
const res = await asOwner.initiatives({ initiativeId: 999999 }).get();
diff --git a/apps/api/src/modules/initiatives/service.ts b/apps/api/src/modules/initiatives/service.ts
index 8ce319d0..1043b5be 100644
--- a/apps/api/src/modules/initiatives/service.ts
+++ b/apps/api/src/modules/initiatives/service.ts
@@ -315,6 +315,13 @@ async function assertInitiativeLabels(projectId: number, labelIds?: number[]): P
}
}
+// ISO 'YYYY-MM-DD' strings order correctly as plain strings. One date alone, or
+// the two equal, is fine.
+function assertDateOrder(startDate?: string | null, targetDate?: string | null) {
+ if (startDate && targetDate && targetDate < startDate)
+ throw new HttpError(400, 'Target date must not precede the start date');
+}
+
async function assertInitiativeReferences(
projectId: number,
input: { ownerUserId?: string | null; labelIds?: number[] },
@@ -331,6 +338,7 @@ export async function createInitiative(
actorUserId?: string | null,
): Promise<InitiativeRow> {
await assertInitiativeReferences(projectId, input);
+ assertDateOrder(input.startDate, input.targetDate);
const [posRow] = await db
.select({ pos: sql<number>`COALESCE(MAX(${initiative.position}), 0) + 1000` })
.from(initiative)
@@ -391,6 +399,12 @@ export async function updateInitiative(
const before = beforeRows[0];
if (!before) return null;
await assertInitiativeReferences(before.projectId, patch);
+ // Each date is checked against the effective other one: a patch sets one date
+ // and leaves the stored value of the other in force.
+ assertDateOrder(
+ patch.startDate !== undefined ? patch.startDate : before.startDate,
+ patch.targetDate !== undefined ? patch.targetDate : before.targetDate,
+ );
const set: Partial<typeof initiative.$inferInsert> = {};
if (patch.title !== undefined) set.title = patch.title;
diff --git a/apps/web/src/components/common/editor/MarkdownEditor.tsx b/apps/web/src/components/common/editor/MarkdownEditor.tsx
index 34977b6e..e2e3dd8b 100644
--- a/apps/web/src/components/common/editor/MarkdownEditor.tsx
+++ b/apps/web/src/components/common/editor/MarkdownEditor.tsx
@@ -7,6 +7,7 @@ import Placeholder from '@tiptap/extension-placeholder';
import Link from '@tiptap/extension-link';
import { common, createLowlight } from 'lowlight';
import { Markdown } from 'tiptap-markdown';
+import { pasteMarkdown } from './pasteMarkdown';
import { ResizableImage } from './tiptap-image';
import { Mention } from '@/lib/tiptap-mention';
import { SlashCommand } from '@/lib/tiptap-slash-command';
@@ -150,15 +151,17 @@ export default function MarkdownEditor({
return true;
},
// A pasted screenshot or copied file arrives as clipboard files: upload
- // each and insert at the cursor, same as a drop. Plain text/html pastes
- // carry no files and fall through to tiptap's default handling.
+ // each and insert at the cursor, same as a drop.
handlePaste(view, event) {
- if (!uploadFile) return false;
const files = event.clipboardData?.files;
- if (!files || files.length === 0) return false;
- event.preventDefault();
- insertFiles(files, view.state.selection.to);
- return true;
+ if (uploadFile && files && files.length > 0) {
+ event.preventDefault();
+ insertFiles(files, view.state.selection.to);
+ return true;
+ }
+ const editor = editorRef.current;
+ if (!editor) return false;
+ return pasteMarkdown(editor, event.clipboardData);
},
},
onUpdate: ({ editor }) => {
diff --git a/apps/web/src/components/common/editor/pasteMarkdown.ts b/apps/web/src/components/common/editor/pasteMarkdown.ts
new file mode 100644
index 00000000..f80ad0e2
--- /dev/null
+++ b/apps/web/src/components/common/editor/pasteMarkdown.ts
@@ -0,0 +1,19 @@
+import type { Editor } from '@tiptap/core';
+
+// Text is pasted as markdown source, so "# Title" becomes a heading. An editor or
+// a web page also puts HTML on the clipboard, which ProseMirror would prefer and
+// which carries none of the "#" and ">" structure. Inside a code block the text
+// stays literal.
+//
+// A copy from a ProseMirror editor is the exception: it is marked with
+// data-pm-slice and its HTML is the richer source, since markdown carries neither
+// a table's alignment and widths nor a text colour.
+export function pasteMarkdown(editor: Editor, clipboard: DataTransfer | null): boolean {
+ const text = clipboard?.getData('text/plain');
+ const { selection } = editor.state;
+ if (!text || selection.$from.parent.type.spec.code) return false;
+ if (clipboard?.getData('text/html').includes('data-pm-slice')) return false;
+ // insertContentAt is the command tiptap-markdown overrides to read markdown.
+ const { from, to } = selection;
+ return editor.chain().focus().insertContentAt({ from, to }, text).run();
+}
diff --git a/apps/web/src/components/common/editor/tiptap-image.ts b/apps/web/src/components/common/editor/tiptap-image.ts
index 16c56e2e..9da39573 100644
--- a/apps/web/src/components/common/editor/tiptap-image.ts
+++ b/apps/web/src/components/common/editor/tiptap-image.ts
@@ -19,8 +19,12 @@ function markdownImage(src: string, alt: string, title: string | null): string {
// carrying either serializes as a raw <img> tag (tiptap-markdown runs html:true).
export const ResizableImage = Image.extend({
addAttributes() {
+ // The image keeps height:auto and nothing ever sets the inherited height, so
+ // it is dropped: it would otherwise reach the document JSON as `height: null`,
+ // which the API rejects as an unsupported image attr.
+ const { height: _height, ...parent }: Record<string, unknown> = this.parent?.() ?? {};
return {
- ...this.parent?.(),
+ ...parent,
// Kept so a raw <img style="max-width:50%"> keeps its sizing.
style: { default: null },
width: {
diff --git a/apps/web/src/components/common/overlay/InitiativeDialog.tsx b/apps/web/src/components/common/overlay/InitiativeDialog.tsx
index 5d7622de..f8b0879c 100644
--- a/apps/web/src/components/common/overlay/InitiativeDialog.tsx
+++ b/apps/web/src/components/common/overlay/InitiativeDialog.tsx
@@ -3,6 +3,7 @@ import { useRouter } from 'next/navigation';
import { useTranslations } from 'next-intl';
import type { Initiative, InitiativeStatus } from '@/lib/api';
import { initiativePath } from '@/utils/paths';
+import { parseDate } from '@/utils/dates';
import { useCreateInitiative, useUpdateInitiative } from '@/services/initiatives.service';
import { useProjectQuery } from '@/services/projects.service';
import Modal, { useModalFullscreen } from './Modal';
@@ -52,6 +53,11 @@ export default function InitiativeDialog({
const idleLabel = initiative ? t('form.save') : t('form.create');
const submitLabel = saving ? busyLabel : idleLabel;
+ // The calendars grey out days that would put one date on the wrong side of the
+ // other. Equal dates are allowed.
+ const latestStart = parseDate(targetDate);
+ const earliestTarget = parseDate(startDate);
+
const toggleLabel = (labelId: number) =>
setLabelIds((ids) =>
ids.includes(labelId) ? ids.filter((id) => id !== labelId) : [...ids, labelId],
@@ -130,9 +136,19 @@ export default function InitiativeDialog({
<PrioritySelect value={priority} onChange={setPriority} />
- <DatePill value={startDate} placeholder={t('startDate')} onChange={setStartDate} />
+ <DatePill
+ value={startDate}
+ placeholder={t('startDate')}
+ onChange={setStartDate}
+ disabled={latestStart ? { after: latestStart } : undefined}
+ />
- <DatePill value={targetDate} placeholder={t('targetDate')} onChange={setTargetDate} />
+ <DatePill
+ value={targetDate}
+ placeholder={t('targetDate')}
+ onChange={setTargetDate}
+ disabled={earliestTarget ? { before: earliestTarget } : undefined}
+ />
{project && project.labels.length > 0 && (
<LabelsSelect
diff --git a/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts b/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts
index 9ab4cee4..a35a3737 100644
--- a/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts
+++ b/apps/web/src/features/documents/components/DocumentMarkdownEditor.test.ts
@@ -10,6 +10,7 @@ import {
uploadAndInsertImage,
syncDocumentEditorEditable,
} from './DocumentMarkdownEditor';
+import { pasteMarkdown } from '@/components/common/editor/pasteMarkdown';
const richDocument: JSONContent = {
type: 'doc',
@@ -66,17 +67,20 @@ let previousWindow: PropertyDescriptor | undefined;
let previousDocument: PropertyDescriptor | undefined;
let previousNavigator: PropertyDescriptor | undefined;
let previousAnimationFrame: PropertyDescriptor | undefined;
+let previousNode: PropertyDescriptor | undefined;
beforeEach(() => {
previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window');
previousDocument = Object.getOwnPropertyDescriptor(globalThis, 'document');
previousNavigator = Object.getOwnPropertyDescriptor(globalThis, 'navigator');
previousAnimationFrame = Object.getOwnPropertyDescriptor(globalThis, 'requestAnimationFrame');
+ previousNode = Object.getOwnPropertyDescriptor(globalThis, 'Node');
dom = new JSDOM('<!doctype html><div id="one"></div><div id="two"></div>');
Object.defineProperties(globalThis, {
window: { configurable: true, value: dom.window },
document: { configurable: true, value: dom.window.document },
navigator: { configurable: true, value: dom.window.navigator },
+ Node: { configurable: true, value: dom.window.Node },
requestAnimationFrame: {
configurable: true,
value: (callback: FrameRequestCallback) => setTimeout(callback, 0),
@@ -91,6 +95,7 @@ afterEach(() => {
['document', previousDocument],
['navigator', previousNavigator],
['requestAnimationFrame', previousAnimationFrame],
+ ['Node', previousNode],
] as const) {
if (descriptor) Object.defineProperty(globalThis, name, descriptor);
else Reflect.deleteProperty(globalThis, name);
@@ -171,12 +176,18 @@ describe('DocumentMarkdownEditor JSON persistence', () => {
}),
editable: true,
});
+ let updates = 0;
+ editor.on('update', () => {
+ updates += 1;
+ });
syncDocumentEditorEditable(editor, false);
assert.equal(editor.isEditable, false);
syncDocumentEditorEditable(editor, true);
assert.equal(editor.isEditable, true);
+ // An update here would mark the draft dirty and autosave an unedited document.
+ assert.equal(updates, 0);
editor.destroy();
});
@@ -285,3 +296,98 @@ describe('DocumentMarkdownEditor JSON persistence', () => {
editor.destroy();
});
});
+
+describe('DocumentMarkdownEditor markdown paste', () => {
+ const editorFor = (content?: JSONContent) =>
+ new Editor({
+ element: document.querySelector('#one') as HTMLElement,
+ extensions: documentEditorExtensions({
+ placeholder: '',
+ codeBlockLabel: 'Code',
+ tableLabel: 'Table',
+ }),
+ content,
+ });
+
+ const clipboard = (text: string, html = '') =>
+ ({ getData: (type: string) => (type === 'text/plain' ? text : html) }) as DataTransfer;
+
+ it('parses pasted text as markdown', () => {
+ const editor = editorFor();
+ assert.equal(pasteMarkdown(editor, clipboard('# Title\n\n- one\n- two')), true);
+ assert.equal(editor.storage.markdown.getMarkdown(), '# Title\n\n- one\n- two');
+ editor.destroy();
+ });
+
+ it('leaves the text to ProseMirror inside a code block', () => {
+ const editor = editorFor({ type: 'doc', content: [{ type: 'codeBlock' }] });
+ editor.commands.focus();
+ assert.equal(pasteMarkdown(editor, clipboard('# Title')), false);
+ editor.destroy();
+ });
+
+ // A copy from this editor carries the whole document shape in its HTML; the
+ // plain text beside it has lost the "#" and the "-" that make it markdown.
+ it('leaves a copy from a ProseMirror editor to ProseMirror', () => {
+ const editor = editorFor();
+ const html = '<div data-pm-slice="1 1 []"><h1>Title</h1><ul><li><p>one</p></li></ul></div>';
+ assert.equal(pasteMarkdown(editor, clipboard('Title\n\none', html)), false);
+ editor.destroy();
+ });
+});
+
+describe('DocumentMarkdownEditor schema attrs', () => {
+ // The API validates the saved JSON against a per-node allowlist and rejects the
+ // whole save on any attr it does not know, null included. This pins the schema
+ // that produces that JSON: an attr added by a tiptap upgrade fails here first,
+ // and the allowlist in apps/api documents service.ts is what has to grow.
+ it('keeps every node and mark to the attrs the API accepts', () => {
+ const editor = new Editor({
+ element: document.querySelector('#one') as HTMLElement,
+ extensions: documentEditorExtensions({
+ placeholder: '',
+ codeBlockLabel: 'Code',
+ tableLabel: 'Table',
+ }),
+ });
+
+ const attrsOf = (types: Record<string, { spec: { attrs?: object } }>) =>
+ Object.fromEntries(
+ Object.entries(types).map(([name, type]) => [
+ name,
+ Object.keys(type.spec.attrs ?? {}).sort(),
+ ]),
+ );
+ assert.deepEqual(attrsOf(editor.schema.nodes), {
+ doc: [],
+ paragraph: ['textAlign'],
+ text: [],
+ blockquote: [],
+ bulletList: ['tight'],
+ orderedList: ['start', 'tight', 'type'],
+ listItem: [],
+ heading: ['level', 'textAlign'],
+ horizontalRule: [],
+ hardBreak: [],
+ codeBlock: ['language'],
+ image: ['alt', 'src', 'style', 'title', 'width'],
+ table: [],
+ tableRow: [],
+ tableHeader: ['align', 'colspan', 'colwidth', 'rowspan'],
+ tableCell: ['align', 'colspan', 'colwidth', 'rowspan'],
+ taskList: [],
+ taskItem: ['checked'],
+ });
+ assert.deepEqual(attrsOf(editor.schema.marks), {
+ bold: [],
+ italic: [],
+ strike: [],
+ code: [],
+ link: ['class', 'href', 'rel', 'target', 'title'],
+ textStyle: ['color'],
+ underline: [],
+ highlight: ['color'],
+ });
+ editor.destroy();
+ });
+});
diff --git a/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx b/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx
index 8189090e..47e03c55 100644
--- a/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx
+++ b/apps/web/src/features/documents/components/DocumentMarkdownEditor.tsx
@@ -21,6 +21,7 @@ import EditorSelectionMenu from '@/components/common/editor/EditorSelectionMenu'
import EditorTableMenu from '@/components/common/editor/EditorTableMenu';
import { ResizableImage } from '@/components/common/editor/tiptap-image';
import { MarkdownTable } from '@/components/common/editor/tiptap-table';
+import { pasteMarkdown } from '@/components/common/editor/pasteMarkdown';
import { SlashCommand } from '@/lib/tiptap-slash-command';
const lowlight = createLowlight(common);
@@ -164,18 +165,21 @@ export default function DocumentMarkdownEditor({
class: 'md-content flex-1 focus:outline-none selection:bg-primary/15',
},
handlePaste: (_view, event) => {
- const file = firstImageFile(event.clipboardData?.files);
const currentEditor = editorRef.current;
- if (!file || !onUploadImage || !currentEditor || !editableRef.current) return false;
- event.preventDefault();
- void uploadAndInsertImage(
- currentEditor,
- file,
- onUploadImage,
- currentEditor.state.selection.from,
- () => editableRef.current,
- );
- return true;
+ if (!currentEditor || !editableRef.current) return false;
+ const file = firstImageFile(event.clipboardData?.files);
+ if (file && onUploadImage) {
+ event.preventDefault();
+ void uploadAndInsertImage(
+ currentEditor,
+ file,
+ onUploadImage,
+ currentEditor.state.selection.from,
+ () => editableRef.current,
+ );
+ return true;
+ }
+ return pasteMarkdown(currentEditor, event.clipboardData);
},
handleDrop: (view, event, _slice, moved) => {
const file = firstImageFile(event.dataTransfer?.files);
@@ -223,7 +227,10 @@ export default function DocumentMarkdownEditor({
}
export function syncDocumentEditorEditable(editor: Editor | null, editable: boolean) {
- if (editor && editor.isEditable !== editable) editor.setEditable(editable);
+ // Without the second argument setEditable emits an update, which the editor
+ // reports as an edit: the draft turns dirty and autosave writes a new version of
+ // a document nobody typed in.
+ if (editor && editor.isEditable !== editable) editor.setEditable(editable, false);
}
export function insertDocumentImage(
diff --git a/apps/web/src/features/documents/components/SortableDocumentRow.tsx b/apps/web/src/features/documents/components/SortableDocumentRow.tsx
index 647940c6..af10ef8b 100644
--- a/apps/web/src/features/documents/components/SortableDocumentRow.tsx
+++ b/apps/web/src/features/documents/components/SortableDocumentRow.tsx
@@ -90,25 +90,26 @@ export default function SortableDocumentRow({
</Button>
</div>
- <Button
- type="button"
- variant="ghost"
- size="icon-xs"
- className={cn(
- 'size-6 shrink-0 text-muted-foreground',
- (!nested || !hasChildren) && 'invisible',
- )}
- aria-label={collapsed ? t('expand') : t('collapse')}
- aria-expanded={hasChildren ? !collapsed : undefined}
- onClick={onToggle}
- >
- <ChevronRight
- className={cn(
- 'size-3.5 transition-transform duration-150 rtl:rotate-180',
- !collapsed && 'rotate-90 rtl:rotate-90',
- )}
- />
- </Button>
+ {/* Only a tree keeps the slot of a page without children, to align it
+ with its siblings. A flat list has nothing to align to. */}
+ {nested && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon-xs"
+ className={cn('size-6 shrink-0 text-muted-foreground', !hasChildren && 'invisible')}
+ aria-label={collapsed ? t('expand') : t('collapse')}
+ aria-expanded={hasChildren ? !collapsed : undefined}
+ onClick={onToggle}
+ >
+ <ChevronRight
+ className={cn(
+ 'size-3.5 transition-transform duration-150 rtl:rotate-180',
+ !collapsed && 'rotate-90 rtl:rotate-90',
+ )}
+ />
+ </Button>
+ )}
<Link
href={documentPath(projectKey, document.id)}
diff --git a/apps/web/src/features/initiatives/components/detail/InitiativeHeader.tsx b/apps/web/src/features/initiatives/components/detail/InitiativeHeader.tsx
index 103500e9..69028cea 100644
--- a/apps/web/src/features/initiatives/components/detail/InitiativeHeader.tsx
+++ b/apps/web/src/features/initiatives/components/detail/InitiativeHeader.tsx
@@ -4,6 +4,7 @@ import { Info } from 'lucide-react';
import { useTranslations } from 'next-intl';
import type { Initiative, InitiativePatch, ProjectDetail } from '@/lib/api';
import { useUpdateInitiative } from '@/services/initiatives.service';
+import { parseDate } from '@/utils/dates';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import AssigneeSelect from '@/components/common/fields/AssigneeSelect';
import DatePill from '@/components/common/fields/DatePill';
@@ -16,7 +17,8 @@ import ProgressBar from '@/components/common/ProgressBar';
import InitiativeActions from './InitiativeActions';
// The initiative detail header. The pills patch the initiative inline; title and
-// description are read-only here and edited from the overflow menu dialog.
+// description are read-only here and edited from the overflow menu dialog, which
+// is also the only way in on a narrow screen, where the pills are not shown.
export default function InitiativeHeader({
initiative,
project,
@@ -27,6 +29,10 @@ export default function InitiativeHeader({
const t = useTranslations('initiatives');
const update = useUpdateInitiative(project.project.key);
const hasDescription = initiative.description.trim().length > 0;
+ // The calendars grey out days that would put one date on the wrong side of the
+ // other. Equal dates are allowed.
+ const latestStart = parseDate(initiative.targetDate);
+ const earliestTarget = parseDate(initiative.startDate);
const patch = (p: InitiativePatch) => update.mutate({ id: initiative.id, patch: p });
@@ -41,7 +47,9 @@ export default function InitiativeHeader({
<div className="flex flex-wrap items-center justify-between gap-x-2 gap-y-1.5 border-b px-6 py-2.5">
<div className="flex flex-wrap items-center gap-2">
<div className="flex items-center gap-1">
- <span className="text-sm font-semibold">{initiative.title}</span>
+ <span className="text-sm font-semibold" dir="auto">
+ {initiative.title}
+ </span>
{hasDescription && (
<Popover>
<PopoverTrigger asChild>
@@ -63,33 +71,44 @@ export default function InitiativeHeader({
)}
</div>
- <span className="mx-1 h-4 w-px bg-border" />
+ {/* Narrow screens wrap these into three rows that push the tabs off the
+ fold; there the same fields are edited from the overflow menu dialog. */}
+ <div className="hidden flex-wrap items-center gap-2 md:flex">
+ <span className="mx-1 h-4 w-px bg-border" />
- <InitiativeStatusSelect
- value={initiative.status}
- onChange={(status) => patch({ status })}
- />
- <AssigneeSelect
- assignees={project.assignees}
- value={initiative.ownerUserId}
- onChange={(ownerUserId) => patch({ ownerUserId })}
- placeholder={t('noOwner')}
- />
- <PrioritySelect
- value={initiative.priority ?? ''}
- onChange={(v) => patch({ priority: v || null })}
- />
- <DatePill
- value={initiative.targetDate}
- placeholder={t('targetDate')}
- onChange={(v) => patch({ targetDate: v })}
- />
- <LabelsSelect
- labels={project.labels}
- groups={project.labelGroups}
- value={initiative.labelIds}
- onToggle={toggleLabel}
- />
+ <InitiativeStatusSelect
+ value={initiative.status}
+ onChange={(status) => patch({ status })}
+ />
+ <AssigneeSelect
+ assignees={project.assignees}
+ value={initiative.ownerUserId}
+ onChange={(ownerUserId) => patch({ ownerUserId })}
+ placeholder={t('noOwner')}
+ />
+ <PrioritySelect
+ value={initiative.priority ?? ''}
+ onChange={(v) => patch({ priority: v || null })}
+ />
+ <DatePill
+ value={initiative.startDate}
+ placeholder={t('startDate')}
+ onChange={(v) => patch({ startDate: v })}
+ disabled={latestStart ? { after: latestStart } : undefined}
+ />
+ <DatePill
+ value={initiative.targetDate}
+ placeholder={t('targetDate')}
+ onChange={(v) => patch({ targetDate: v })}
+ disabled={earliestTarget ? { before: earliestTarget } : undefined}
+ />
+ <LabelsSelect
+ labels={project.labels}
+ groups={project.labelGroups}
+ value={initiative.labelIds}
+ onToggle={toggleLabel}
+ />
+ </div>
</div>
<div className="flex shrink-0 items-center gap-3">