Files
Docwell/Packages/editor-bridge/src/protocol.ts
T
tajniak81andClaude Opus 5.5 d28f1e02db 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>
2026-11-14 12:20:08 +01:00

70 lines
2.2 KiB
TypeScript

// SPDX-License-Identifier: AGPL-3.0-or-later
// Messages between the editor page and the native app hosting it (ADR-4).
// Both directions are JSON. Keep Phone-App/lib/editor/bridge.dart in sync.
import type { JSONContent } from "@tiptap/core";
/** Formatting the native toolbar can apply. */
export type Command =
| "bold"
| "italic"
| "strike"
| "code"
| "heading1"
| "heading2"
| "heading3"
| "bulletList"
| "orderedList"
| "blockquote"
| "codeBlock"
| "underline"
| "taskList"
| "callout"
| "table"
| "undo"
| "redo";
/** A page's body font; empty is the default sans. */
export type PageFont = "" | "serif" | "mono";
/** Native app → editor, through `window.docwell.receive(json)`. */
export type HostMessage =
/**
* Sent by the host once the page has loaded; the editor answers "ready".
* The "ready" sent at start-up is lost when the host's channel is not set
* up yet, so the host asks again instead of relying on it.
*/
| { type: "hello" }
| { type: "setContent"; content: JSONContent | null }
| { type: "setEditable"; editable: boolean }
| { type: "setTheme"; dark: boolean }
/** The page's own layout: the wider column and the body font (see Page in the API). */
| { type: "setLayout"; fullWidth: boolean; font: PageFont }
| { type: "command"; command: Command }
| { type: "focus" }
| { type: "blur" }
/** Edit the live document over docwell-server's /collab WebSocket. */
| { type: "connect"; url: string; page: string; token: string; user: { name: string; color: string } };
/** What the toolbar needs to show which buttons are on. */
export interface EditorState {
active: Command[];
canUndo: boolean;
canRedo: boolean;
focused: boolean;
}
/** Editor → native app. */
export type EditorMessage =
| { type: "ready"; version: number }
| { type: "change"; content: JSONContent }
| { type: "state"; state: EditorState }
| { type: "collab"; status: string }
/** A link to a page was followed; path is an app route like "/p/<id>". */
| { type: "navigate"; path: string }
| { type: "error"; message: string };
/** Bumped when a message changes shape, so the app can refuse a stale bundle. */
export const PROTOCOL_VERSION = 2;