Add tables, to-dos, callouts and the rest of editor parity

The editor gains the blocks and formatting it lacked next to AFFiNE:

- Tables with a header row, resizable columns, a toolbar to add, delete,
  merge and split, and rows that move by a drag grip, toolbar buttons or
  Ctrl+Alt+Up/Down.
- To-do lists (also from "[] "), callouts with an emoji and colour, and
  headings down to level 6 (Ctrl+Shift+0-6 for text and headings).
- Text colour and highlights from a fixed palette that follows the theme,
  and left, centre and right alignment.
- Optional line numbers on code blocks, with a default hosts can set.
- PDF attachments show their pages inline; pdf.js loads only then, and
  the mobile bundle leaves it out.
- The selection toolbar adds underline, colour, align, inline math, make a
  linked page and copy block link. A grip beside each block drags it and
  opens a menu: turn into, move, duplicate, copy, copy link, delete.
- The slash menu adds Today, Tomorrow, Yesterday, Now and New page.

The web app translates the new words and makes linked pages as children
of the open page. The mobile bridge gets underline, to-do, callout and
table commands, so its protocol moves to version 2 and the bundle is
rebuilt.

docwell-server's converters learn the new nodes: Markdown writes task
lists, GitHub alerts and tables and reads them back; HTML keeps colours
and alignment and reads its own output back; PDF draws tables, to-dos,
callouts and coloured text; Word import keeps tables, alignment, H4-H6
and colours; Notion import turns databases into tables and keeps
callouts and to-dos. Imported tables and H4-H6 headings no longer
collapse into paragraphs and H3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tajniak81andClaude Opus 5.5 committed 2026-11-14 12:20:08 +01:00
1 parent 3c7403ddf9
commit d28f1e02db
44 files changed
+4318 -338

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import CodeBlock, { type CodeBlockOptions } from "@tiptap/extension-code-block";
declare module "@tiptap/core" {
interface Commands<ReturnType> {
codeLineNumbers: {
/** Shows or hides line numbers on the code block at the selection. */
toggleCodeLineNumbers: () => ReturnType;
};
}
}
/** Whether a code block shows line numbers: its own choice, else the editor's default. */
export function showsLineNumbers(attr: unknown, byDefault: boolean): boolean {
return typeof attr === "boolean" ? attr : byDefault;
}
/**
* Code blocks with optional line numbers. lineNumbers is null until someone
* picks for that block, so it follows the default (lineNumbers option, e.g.
* from a workspace setting) until then.
*/
export const DocwellCodeBlock = CodeBlock.extend<CodeBlockOptions & { lineNumbers: boolean }>({
addOptions() {
return { ...this.parent!(), lineNumbers: false };
},
addAttributes() {
return {
...this.parent?.(),
lineNumbers: {
default: null,
parseHTML: (el) => {
const v = el.getAttribute("data-line-numbers");
return v === "true" ? true : v === "false" ? false : null;
},
renderHTML: (attrs) =>
typeof attrs.lineNumbers === "boolean" ? { "data-line-numbers": String(attrs.lineNumbers) } : {},
},
};
},
addCommands() {
return {
...this.parent?.(),
toggleCodeLineNumbers:
() =>
({ editor, commands }) => {
if (!editor.isActive(this.name)) return false;
const now = showsLineNumbers(editor.getAttributes(this.name).lineNumbers, this.options.lineNumbers);
return commands.updateAttributes(this.name, { lineNumbers: !now });
},
};
},
addNodeView() {
const byDefault = this.options.lineNumbers;
const prefix = this.options.languageClassPrefix ?? "language-";
return ({ node }) => {
const pre = document.createElement("pre");
pre.className = "dw-code";
const gutter = document.createElement("div");
gutter.className = "dw-code__gutter";
gutter.contentEditable = "false";
gutter.setAttribute("aria-hidden", "true");
const code = document.createElement("code");
pre.append(gutter, code);
let lines = -1;
const draw = (n: typeof node) => {
const on = showsLineNumbers(n.attrs.lineNumbers, byDefault);
pre.classList.toggle("dw-code--numbered", on);
code.className = n.attrs.language ? `${prefix}${String(n.attrs.language)}` : "";
const count = on ? n.textContent.split("\n").length : 0;
if (count !== lines) {
lines = count;
gutter.textContent = Array.from({ length: count }, (_, i) => i + 1).join("\n");
}
};
draw(node);
return {
dom: pre,
contentDOM: code,
update: (n) => {
if (n.type !== node.type) return false;
draw(n);
return true;
},
ignoreMutation: (m) => gutter.contains(m.target),
};
};
},
});