Files
Docwell/Web-App/frontend/src/composables/useEditorHosts.ts
T
tajniak81andClaude Opus 5.5 c98b127f1e
CI / go (Media) (push) Successful in 13m40s
CI / go (Server) (push) Failing after 23m20s
CI / go (Web-App) (push) Canceled after 0s
CI / frontend (push) Failing after 10m35s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / desktop (ubuntu-latest) (push) Failing after 3h4m42s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / mobile (push) Failing after 9m19s
CI / docker (push) Successful in 2h2m57s
Add columns, suggesting mode, verified pages, scanned PDF search and server translations
- Columns: /columns puts 2 to 4 columns side by side, with widths dragged
  between them; they stack on phones. HTML export and import keep them
  (also Notion column lists and Confluence page layouts).
- Suggesting mode: edits become suggested insertions and deletions that
  editors accept or reject one by one or all at once. Text only.
- Verified pages: editors verify a page for a while or without end; the
  verifier is notified when it runs out (migration 1764700000).
- Scanned PDFs attached to pages are read by AI for search where a
  workspace turns it on.
- The server writes error messages, emails, digests and phone
  notifications in English, Polish, German, French and Spanish; the apps
  send their language with each request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:38:08 +01:00

91 lines
3.4 KiB
TypeScript

// SPDX-License-Identifier: AGPL-3.0-or-later
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";
/** 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(
words("slash").map((b) => [
b,
{ label: t(`editor.blocks.${b}.label`), description: t(`editor.blocks.${b}.description`) },
]),
),
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: group("blocks", "block"),
find: group("find", "find"),
suggest: group("suggest", "suggest"),
dates: group("dates", "dates"),
database: group("database", "database"),
edgeless: group("edgeless", "edgeless"),
ai: group("ai", "ai"),
}));
}
/**
* "[[" 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 [];
const res = await api.workspaces.search(ws, query, 8);
return res.items.map((h) => ({ id: h.id, title: h.title, icon: h.icon, hint: h.spaceName }));
},
};
}
/** "@" mentions find people in the page's workspace; "@remind …" dates remind the signed-in person. */
export function useMentions(workspace: () => string | undefined): MentionHost {
const api = useApi();
const auth = useAuthStore();
return {
// Read when needed: the editor can be built before the session is loaded.
get me() {
return auth.user?.id;
},
async search(query) {
const ws = workspace();
if (!ws) return [];
const people = await api.workspaces.people(ws, query, 8);
return people.map((p) => ({ id: p.id, label: p.name || p.email, hint: p.email }));
},
};
}