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:
1 parent
3c7403ddf9
commit
d28f1e02db
44 files changed
+4318
-338
No files matched your search
@@ -1,122 +1,63 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import type { EditorLabels, MentionHost, PageHost } from "@docwell/editor";
|
||||
import { englishLabels, type EditorLabels, type MentionHost, type PageHost } from "@docwell/editor";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useApi } from "../api";
|
||||
import { useAuthStore } from "../stores/auth";
|
||||
import { useSpacesStore } from "../stores/spaces";
|
||||
|
||||
const blocks = [
|
||||
"text",
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"bullet",
|
||||
"ordered",
|
||||
"quote",
|
||||
"code",
|
||||
"divider",
|
||||
"image",
|
||||
"file",
|
||||
"toc",
|
||||
"math",
|
||||
"mathInline",
|
||||
"mermaid",
|
||||
"drawio",
|
||||
"excalidraw",
|
||||
"pageLink",
|
||||
"toggle",
|
||||
"embed",
|
||||
"linkCard",
|
||||
];
|
||||
const blockWords = [
|
||||
"edit",
|
||||
"done",
|
||||
"cancel",
|
||||
"save",
|
||||
"remove",
|
||||
"saving",
|
||||
"latex",
|
||||
"mermaid",
|
||||
"mermaidError",
|
||||
"emptyDrawio",
|
||||
"emptyExcalidraw",
|
||||
"loadFailed",
|
||||
"toc",
|
||||
"tocEmpty",
|
||||
"expand",
|
||||
"collapse",
|
||||
"embed",
|
||||
"embedUrl",
|
||||
"embedInvalid",
|
||||
"linkUrl",
|
||||
"copyBlockLink",
|
||||
] as const;
|
||||
|
||||
const findWords = [
|
||||
"find",
|
||||
"replace",
|
||||
"previous",
|
||||
"next",
|
||||
"replaceOne",
|
||||
"replaceAll",
|
||||
"matchCase",
|
||||
"close",
|
||||
"count",
|
||||
"none",
|
||||
] as const;
|
||||
|
||||
const dateWords = [
|
||||
"today",
|
||||
"tomorrow",
|
||||
"yesterday",
|
||||
"nextWeek",
|
||||
"remindWord",
|
||||
"remindMe",
|
||||
"reminderAt",
|
||||
"someoneElse",
|
||||
"edit",
|
||||
] as const;
|
||||
/** Groups of editor words, each looked up as editor.<group>.<word>; the words are the English labels' keys. */
|
||||
const words = <K extends keyof EditorLabels>(group: K) => Object.keys(englishLabels[group] as object);
|
||||
|
||||
/** The editor's menu and button words in the app's language. */
|
||||
export function useEditorLabels() {
|
||||
const { t, locale } = useI18n();
|
||||
// Placeholders the editor fills in itself pass through as they are.
|
||||
const keep = { current: "{current}", total: "{total}", n: "{n}" };
|
||||
const group = <K extends keyof EditorLabels>(name: K, prefix: string) =>
|
||||
Object.fromEntries(words(name).map((w) => [w, t(`editor.${prefix}.${w}`, keep)])) as EditorLabels[K];
|
||||
return computed<EditorLabels>(() => ({
|
||||
locale: locale.value,
|
||||
slashMenu: t("editor.slashMenu"),
|
||||
noMatches: t("editor.noMatches"),
|
||||
slash: Object.fromEntries(
|
||||
blocks.map((b) => [
|
||||
words("slash").map((b) => [
|
||||
b,
|
||||
{ label: t(`editor.blocks.${b}.label`), description: t(`editor.blocks.${b}.description`) },
|
||||
]),
|
||||
),
|
||||
format: {
|
||||
bold: t("editor.format.bold"),
|
||||
italic: t("editor.format.italic"),
|
||||
strike: t("editor.format.strike"),
|
||||
code: t("editor.format.code"),
|
||||
link: t("editor.format.link"),
|
||||
linkPrompt: t("editor.format.linkPrompt"),
|
||||
comment: t("editor.format.comment"),
|
||||
},
|
||||
format: group("format", "format"),
|
||||
colors: group("colors", "colors"),
|
||||
table: group("table", "table"),
|
||||
blockMenu: group("blockMenu", "blockMenu"),
|
||||
mentions: t("editor.mentions"),
|
||||
noPeople: t("editor.noPeople"),
|
||||
pageLinks: t("editor.pageLinks"),
|
||||
noPages: t("editor.noPages"),
|
||||
blocks: Object.fromEntries(blockWords.map((w) => [w, t(`editor.block.${w}`)])) as EditorLabels["blocks"],
|
||||
// The editor fills in {current} and {total} itself, so they pass through.
|
||||
find: Object.fromEntries(
|
||||
findWords.map((w) => [w, t(`editor.find.${w}`, { current: "{current}", total: "{total}" })]),
|
||||
) as EditorLabels["find"],
|
||||
dates: Object.fromEntries(dateWords.map((w) => [w, t(`editor.dates.${w}`)])) as EditorLabels["dates"],
|
||||
blocks: group("blocks", "block"),
|
||||
find: group("find", "find"),
|
||||
dates: group("dates", "dates"),
|
||||
}));
|
||||
}
|
||||
|
||||
/** "[[" page links find pages in the page's workspace through search. */
|
||||
export function usePageLinks(workspace: () => string | undefined): PageHost {
|
||||
/**
|
||||
* "[[" page links find pages in the page's workspace through search. With
|
||||
* parent, the editor can also make new pages, as children of that page.
|
||||
*/
|
||||
export function usePageLinks(
|
||||
workspace: () => string | undefined,
|
||||
parent?: () => { space: string; id: string } | undefined,
|
||||
): PageHost {
|
||||
const api = useApi();
|
||||
const spaces = useSpacesStore();
|
||||
return {
|
||||
async create(title) {
|
||||
const at = parent?.();
|
||||
if (!at) throw new Error("no page to add the new page to");
|
||||
const page = await spaces.createPage(at.space, at.id, title || undefined);
|
||||
return { id: page.id, title: page.title, icon: page.icon };
|
||||
},
|
||||
async search(query) {
|
||||
const ws = workspace();
|
||||
if (!ws || !query.trim()) return [];
|
||||
|
||||
Reference in new issue
Block a user