From c98b127f1e31b4b6b3acd43e793c644657c39b38 Mon Sep 17 00:00:00 2001 From: tajniak81 <13187254+tajniak81@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:38:08 +0100 Subject: [PATCH] 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 --- .../1764700000_verified_pages.js | 62 +++ Docs-Site/guide/using-docwell.md | 29 +- Packages/api-client/src/index.ts | 14 + Packages/api-client/src/schema.d.ts | 97 ++++- Packages/editor/src/DocwellEditor.vue | 116 ++++- Packages/editor/src/columns.test.ts | 100 +++++ Packages/editor/src/columns.ts | 340 +++++++++++++++ Packages/editor/src/editor.css | 113 +++++ Packages/editor/src/extensions.ts | 7 + Packages/editor/src/index.ts | 1 + Packages/editor/src/labels.ts | 34 ++ Packages/editor/src/slash.ts | 8 + Packages/editor/src/suggest.test.ts | 137 ++++++ Packages/editor/src/suggest.ts | 411 ++++++++++++++++++ Packages/ui/src/icons.ts | 1 + Phone-App/lib/api/docwell_api.dart | 7 + Phone-App/lib/api/generated/models.dart | 66 ++- Phone-App/lib/l10n.dart | 5 + .../lib/screens/notifications_screen.dart | 1 + Server/admin/src/session.ts | 3 +- Server/cmd/docwell-server/main.go | 4 + Server/internal/ai/profiles.go | 3 + Server/internal/ai/scans.go | 56 +++ Server/internal/api/api.gen.go | 61 ++- Server/internal/auth/auth.go | 7 + Server/internal/convert/columns.go | 183 ++++++++ Server/internal/convert/columns_test.go | 79 ++++ Server/internal/convert/docx_export.go | 2 +- Server/internal/convert/export.go | 7 +- Server/internal/convert/import.go | 20 +- Server/internal/convert/pdf.go | 2 +- Server/internal/convert/suggest.go | 99 +++++ Server/internal/convert/suggest_test.go | 52 +++ Server/internal/directory/invites.go | 9 +- Server/internal/directory/notify.go | 87 ++-- Server/internal/directory/notify_test.go | 2 +- Server/internal/directory/pages.go | 13 +- Server/internal/directory/verify.go | 131 ++++++ Server/internal/directory/verify_test.go | 36 ++ Server/internal/httpapi/ai.go | 3 +- Server/internal/httpapi/auth.go | 15 +- Server/internal/httpapi/lang.go | 56 +++ Server/internal/httpapi/router.go | 2 +- Server/internal/httpapi/spaces.go | 16 + Server/internal/i18n/catalog/de.json | 262 +++++++++++ Server/internal/i18n/catalog/es.json | 262 +++++++++++ Server/internal/i18n/catalog/fr.json | 262 +++++++++++ Server/internal/i18n/catalog/pl.json | 262 +++++++++++ Server/internal/i18n/i18n.go | 247 +++++++++++ Server/internal/i18n/i18n_test.go | 168 +++++++ Server/internal/mail/mail.go | 20 +- Server/internal/mail/templates/digest.de.html | 11 + Server/internal/mail/templates/digest.de.txt | 9 + Server/internal/mail/templates/digest.es.html | 11 + Server/internal/mail/templates/digest.es.txt | 9 + Server/internal/mail/templates/digest.fr.html | 11 + Server/internal/mail/templates/digest.fr.txt | 9 + Server/internal/mail/templates/digest.pl.html | 11 + Server/internal/mail/templates/digest.pl.txt | 9 + Server/internal/mail/templates/invite.de.html | 4 + Server/internal/mail/templates/invite.de.txt | 6 + Server/internal/mail/templates/invite.es.html | 4 + Server/internal/mail/templates/invite.es.txt | 6 + Server/internal/mail/templates/invite.fr.html | 4 + Server/internal/mail/templates/invite.fr.txt | 6 + Server/internal/mail/templates/invite.pl.html | 4 + Server/internal/mail/templates/invite.pl.txt | 6 + Server/internal/mail/templates/test.de.html | 2 + Server/internal/mail/templates/test.de.txt | 2 + Server/internal/mail/templates/test.es.html | 2 + Server/internal/mail/templates/test.es.txt | 2 + Server/internal/mail/templates/test.fr.html | 2 + Server/internal/mail/templates/test.fr.txt | 2 + Server/internal/mail/templates/test.pl.html | 2 + Server/internal/mail/templates/test.pl.txt | 2 + Server/internal/pbschema/schema.json | 56 ++- Server/internal/search/files.go | 57 ++- Server/internal/search/files_test.go | 12 + Server/internal/search/scans.go | 223 ++++++++++ Server/internal/search/scans_test.go | 152 +++++++ Server/internal/search/search.go | 12 +- Server/internal/settings/settings.go | 3 +- Web-App/frontend/src/app.ts | 4 +- .../frontend/src/components/PageVerify.vue | 105 +++++ .../src/components/ai/WorkspaceAI.vue | 14 + .../src/composables/useEditorHosts.ts | 1 + Web-App/frontend/src/locales/de.json | 58 +++ Web-App/frontend/src/locales/en.json | 58 +++ Web-App/frontend/src/locales/es.json | 58 +++ Web-App/frontend/src/locales/fr.json | 58 +++ Web-App/frontend/src/locales/pl.json | 58 +++ .../frontend/src/views/NotificationsView.vue | 12 +- Web-App/frontend/src/views/page/PageView.vue | 33 ++ api/openapi.yaml | 64 ++- 94 files changed, 5042 insertions(+), 112 deletions(-) create mode 100644 Database/pb_migrations/1764700000_verified_pages.js create mode 100644 Packages/editor/src/columns.test.ts create mode 100644 Packages/editor/src/columns.ts create mode 100644 Packages/editor/src/suggest.test.ts create mode 100644 Packages/editor/src/suggest.ts create mode 100644 Server/internal/ai/scans.go create mode 100644 Server/internal/convert/columns.go create mode 100644 Server/internal/convert/columns_test.go create mode 100644 Server/internal/convert/suggest.go create mode 100644 Server/internal/convert/suggest_test.go create mode 100644 Server/internal/directory/verify.go create mode 100644 Server/internal/directory/verify_test.go create mode 100644 Server/internal/httpapi/lang.go create mode 100644 Server/internal/i18n/catalog/de.json create mode 100644 Server/internal/i18n/catalog/es.json create mode 100644 Server/internal/i18n/catalog/fr.json create mode 100644 Server/internal/i18n/catalog/pl.json create mode 100644 Server/internal/i18n/i18n.go create mode 100644 Server/internal/i18n/i18n_test.go create mode 100644 Server/internal/mail/templates/digest.de.html create mode 100644 Server/internal/mail/templates/digest.de.txt create mode 100644 Server/internal/mail/templates/digest.es.html create mode 100644 Server/internal/mail/templates/digest.es.txt create mode 100644 Server/internal/mail/templates/digest.fr.html create mode 100644 Server/internal/mail/templates/digest.fr.txt create mode 100644 Server/internal/mail/templates/digest.pl.html create mode 100644 Server/internal/mail/templates/digest.pl.txt create mode 100644 Server/internal/mail/templates/invite.de.html create mode 100644 Server/internal/mail/templates/invite.de.txt create mode 100644 Server/internal/mail/templates/invite.es.html create mode 100644 Server/internal/mail/templates/invite.es.txt create mode 100644 Server/internal/mail/templates/invite.fr.html create mode 100644 Server/internal/mail/templates/invite.fr.txt create mode 100644 Server/internal/mail/templates/invite.pl.html create mode 100644 Server/internal/mail/templates/invite.pl.txt create mode 100644 Server/internal/mail/templates/test.de.html create mode 100644 Server/internal/mail/templates/test.de.txt create mode 100644 Server/internal/mail/templates/test.es.html create mode 100644 Server/internal/mail/templates/test.es.txt create mode 100644 Server/internal/mail/templates/test.fr.html create mode 100644 Server/internal/mail/templates/test.fr.txt create mode 100644 Server/internal/mail/templates/test.pl.html create mode 100644 Server/internal/mail/templates/test.pl.txt create mode 100644 Server/internal/search/scans.go create mode 100644 Server/internal/search/scans_test.go create mode 100644 Web-App/frontend/src/components/PageVerify.vue diff --git a/Database/pb_migrations/1764700000_verified_pages.js b/Database/pb_migrations/1764700000_verified_pages.js new file mode 100644 index 0000000..d76dc1f --- /dev/null +++ b/Database/pb_migrations/1764700000_verified_pages.js @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +/// + +// Verified pages: an editor vouches that a page is correct, for a while. +// +// - pages.verified_by and verified_at: who verified the page and when; empty +// when nobody has. +// - pages.verified_until: when the verification runs out; empty for one that +// does not expire. +// - pages.verify_notified_at: when the verifier was told it ran out, so they +// hear once; verifying again clears it. +// - notifications gain the verify_expired type. + +migrate( + (app) => { + const users = app.findCollectionByNameOrId("users"); + const pages = app.findCollectionByNameOrId("pages"); + pages.fields.add(new RelationField({ name: "verified_by", collectionId: users.id, maxSelect: 1, cascadeDelete: false })); + pages.fields.add(new DateField({ name: "verified_at" })); + pages.fields.add(new DateField({ name: "verified_until" })); + pages.fields.add(new DateField({ name: "verify_notified_at" })); + pages.indexes.push("CREATE INDEX idx_pages_verified_until ON pages (verified_until)"); + app.save(pages); + + const notifications = app.findCollectionByNameOrId("notifications"); + notifications.fields.getByName("type").values = [ + "comment", + "reply", + "mention", + "share", + "resolved", + "reminder", + "join_request", + "join_approved", + "join_declined", + "verify_expired", + ]; + app.save(notifications); + }, + (app) => { + const pages = app.findCollectionByNameOrId("pages"); + for (const name of ["verified_by", "verified_at", "verified_until", "verify_notified_at"]) { + pages.fields.removeByName(name); + } + pages.indexes = pages.indexes.filter((i) => !i.includes("idx_pages_verified_until")); + app.save(pages); + const notifications = app.findCollectionByNameOrId("notifications"); + notifications.fields.getByName("type").values = [ + "comment", + "reply", + "mention", + "share", + "resolved", + "reminder", + "join_request", + "join_approved", + "join_declined", + ]; + app.save(notifications); + }, +); diff --git a/Docs-Site/guide/using-docwell.md b/Docs-Site/guide/using-docwell.md index 7a9fda7..63722a2 100644 --- a/Docs-Site/guide/using-docwell.md +++ b/Docs-Site/guide/using-docwell.md @@ -15,6 +15,7 @@ Pages save as you type, and everyone with the page open sees changes and cursors | To | Do this | | --- | --- | | Insert a heading, list, to-do list, table, callout, quote, code block, divider, image or file | Type `/` and pick from the menu (keep typing to filter); headings 4–6 are under **Other headings** | +| Put blocks side by side | Type `/columns` and pick 2, 3 or 4 columns; drag the line between two columns to change their widths, and **+** at the right edge adds a column (Ctrl+Alt+→). Backspace in an empty column removes it. On phones the columns stack | | Start a to-do list | Type `[] ` at the start of a line | | Format text, colour or highlight it, align it, or add a link | Select it and use the toolbar that appears | | Move, duplicate, turn into another kind, or delete a block | Point at it and drag the ⠿ grip in the margin, or click the grip for a menu | @@ -32,6 +33,23 @@ Pages save as you type, and everyone with the page open sees changes and cursors **History** in the page header lists saved versions; you can view any of them and restore it. Restoring keeps the current text as a version too. +### Suggesting edits + +Choose **Suggest edits** in the ⋯ menu to propose changes instead of making them. What you type is underlined in +green and what you delete stays, struck through in red, until someone accepts or rejects it. Click a suggestion to +see who made it and when, and to **Accept** or **Reject** it; the bar above the page counts the open suggestions and +has **Accept all** and **Reject all**. Anyone who can edit the page can decide. Deleting your own suggested text +simply removes it. Only text is tracked: splitting or joining paragraphs and formatting change directly. Suggesting +mode is for you alone and ends when you leave the page (**Edit directly** in the same menu turns it off). Exports +to Markdown, Word and PDF show the page without the open suggestions; HTML keeps them. + +### Verified pages + +Editors can choose **Verify page** in the ⋯ menu to say a page is correct, for a week, a month, three or six +months, a year or with no end date. Everyone sees **Verified by …** under the title; once the time runs out it reads +**Verification ran out**, and the person who verified it gets a notification (and an email, unless they turned that +kind off). Click the badge to verify it again or remove the verification. + A synced page is read-only where it is shown: open it to edit it. People who cannot open that page see only its title. **Account → Editor** sets, for this device, the text size, whether new pages start full width or titled with today's date, whether properties and the pages that link here show, and line numbers in code blocks. @@ -127,8 +145,9 @@ the **Comments** panel. People with the *commenter* role can comment without bei admins can delete comments. The **Inbox** lists your notifications. Under its settings you choose whether they also come by email, and which -kinds (mentions, comments, replies, resolved threads, shared pages, reminders, people asking to join a workspace you -manage). +kinds (mentions, comments, replies, resolved threads, shared pages, reminders, verifications that ran out, people +asking to join a workspace you manage). Emails and phone notifications are written in the language you last used +Docwell in. ## Finding things @@ -136,11 +155,13 @@ Press **Ctrl+K** (⌘K on a Mac) or click **Search** in the sidebar. With nothin visited last; type to search titles and text in every space you can open. The filters narrow results by space, tag, author or date. Star a page (☆ in the header) to keep it under **Favorites** in the sidebar. -Search also reads the files attached to pages: the text of PDFs (not scanned ones, which have no text), Word +Search also reads the files attached to pages: the text of PDFs, Word (`.docx`), HTML and text files such as Markdown or CSV, up to 25 MB each, and their names. A match shows the file with 📎 and the page it is on; it opens that page. Only files the page still links to are found, so a file removed from its page drops out of search. Files are read once, a few seconds after they are uploaded; after an upgrade, the -files already on the server are read in the background. +files already on the server are read in the background. Scanned PDFs have no text of their own: a workspace admin +can turn on **Read scanned PDFs for search** under *Workspace settings → AI*, and AI then writes out each one once +(a few a minute), which uses the workspace's AI tokens. ## AI diff --git a/Packages/api-client/src/index.ts b/Packages/api-client/src/index.ts index 87327bc..76b9492 100644 --- a/Packages/api-client/src/index.ts +++ b/Packages/api-client/src/index.ts @@ -222,6 +222,8 @@ export interface ClientOptions { token?: () => string | null | undefined; /** Called when the server rejects the token (401 on an authenticated call). */ onUnauthorized?: () => void; + /** The language the app shows (en, pl, …): sent as Accept-Language, so the server's messages match it. */ + locale?: () => string | null | undefined; fetch?: typeof fetch; } @@ -235,6 +237,8 @@ export function createClient(opts: ClientOptions) { const headers: Record = { Accept: "application/json" }; const token = opts.token?.(); if (token) headers.Authorization = `Bearer ${token}`; + const locale = opts.locale?.(); + if (locale) headers["Accept-Language"] = locale; if (body !== undefined) headers["Content-Type"] = "application/json"; const res = await doFetch(base + path, { @@ -258,6 +262,8 @@ export function createClient(opts: ClientOptions) { const headers: Record = {}; const token = opts.token?.(); if (token) headers.Authorization = `Bearer ${token}`; + const locale = opts.locale?.(); + if (locale) headers["Accept-Language"] = locale; const res = await doFetch(base + path, { headers }); if (!res.ok) { const data = res.headers.get("content-type")?.includes("application/json") ? await res.json() : await res.text(); @@ -276,6 +282,8 @@ export function createClient(opts: ClientOptions) { const headers: Record = { Accept: "text/event-stream", "Content-Type": "application/json" }; const token = opts.token?.(); if (token) headers.Authorization = `Bearer ${token}`; + const locale = opts.locale?.(); + if (locale) headers["Accept-Language"] = locale; const res = await doFetch(base + path, { method: "POST", headers, body: JSON.stringify(body), signal }); if (!res.ok || !res.body) { const data = res.headers.get("content-type")?.includes("application/json") ? await res.json() : await res.text(); @@ -291,6 +299,8 @@ export function createClient(opts: ClientOptions) { const headers: Record = { Accept: "application/json" }; const token = opts.token?.(); if (token) headers.Authorization = `Bearer ${token}`; + const locale = opts.locale?.(); + if (locale) headers["Accept-Language"] = locale; const res = await doFetch(base + path, { method: "POST", headers, body: form }); const data = res.headers.get("content-type")?.includes("application/json") ? await res.json() : await res.text(); if (!res.ok) { @@ -786,6 +796,10 @@ export function createClient(opts: ClientOptions) { unarchive: (id: string) => post(`/api/v1/pages/${encodeURIComponent(id)}/unarchive`), pin: (id: string) => request("PUT", `/api/v1/pages/${encodeURIComponent(id)}/pin`), unpin: (id: string) => request("DELETE", `/api/v1/pages/${encodeURIComponent(id)}/pin`), + /** Verifies the page for days days, or without end for 0 (editor). */ + verify: (id: string, days: number) => + request("PUT", `/api/v1/pages/${encodeURIComponent(id)}/verify`, { days }), + unverify: (id: string) => request("DELETE", `/api/v1/pages/${encodeURIComponent(id)}/verify`), /** * A web page's title, description and picture, read by docwell-server. * With a workspace, its GitHub, Linear and Figma tokens reach private items. diff --git a/Packages/api-client/src/schema.d.ts b/Packages/api-client/src/schema.d.ts index a756068..5882352 100644 --- a/Packages/api-client/src/schema.d.ts +++ b/Packages/api-client/src/schema.d.ts @@ -1418,6 +1418,29 @@ export interface paths { patch?: never; trace?: never; }; + "/api/v1/pages/{id}/verify": { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + get?: never; + /** + * Verify the page as the caller, for some days or without end (editor) + * @description Verifying again replaces the earlier verification. When it runs out, the caller gets a verify_expired notification. + */ + put: operations["verifyPage"]; + post?: never; + /** Take the page's verification off (editor) */ + delete: operations["unverifyPage"]; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/v1/pages/{id}/visit": { parameters: { query?: never; @@ -3707,6 +3730,21 @@ export interface components { journalDate: string; createdBy: components["schemas"]["PageUser"]; lastEditedBy: components["schemas"]["PageUser"]; + verification: components["schemas"]["PageVerification"]; + }; + /** @description Whether someone vouched for the page; at is empty when nobody has */ + PageVerification: { + by: components["schemas"]["PageUser"]; + /** @description When the page was verified; empty if it is not */ + at: string; + /** @description When the verification runs out; empty when it does not */ + until: string; + /** @description The verification ran out (until has passed) */ + expired: boolean; + }; + VerifyPage: { + /** @description How many days the verification lasts; 0 for one that does not run out */ + days: number; }; /** * @description The view a page opens in for everyone, its text or the edgeless canvas; "?mode=" in an address overrides it @@ -4361,10 +4399,10 @@ export interface components { watching: boolean; }; /** - * @description The join_* types are about a workspace and have no page + * @description The join_* types are about a workspace and have no page; verify_expired tells the person who verified a page that it ran out * @enum {string} */ - NotificationType: "comment" | "reply" | "mention" | "share" | "resolved" | "reminder" | "join_request" | "join_approved" | "join_declined"; + NotificationType: "comment" | "reply" | "mention" | "share" | "resolved" | "reminder" | "join_request" | "join_approved" | "join_declined" | "verify_expired"; Notification: { id: string; type: components["schemas"]["NotificationType"]; @@ -4702,6 +4740,8 @@ export interface components { ignored: string[]; /** @description Tokens the workspace may use per month; 0 is no cap */ monthlyTokenLimit: number; + /** @description Have a document-reading model write out scanned PDFs attached to pages */ + readScans: boolean; }; /** * @description openai is any OpenAI-compatible API @@ -7368,6 +7408,59 @@ export interface operations { 404: components["responses"]["Error"]; }; }; + verifyPage: { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": components["schemas"]["VerifyPage"]; + }; + }; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["Page"]; + }; + }; + 400: components["responses"]["Error"]; + 403: components["responses"]["Error"]; + 404: components["responses"]["Error"]; + }; + }; + unverifyPage: { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": components["schemas"]["Page"]; + }; + }; + 403: components["responses"]["Error"]; + 404: components["responses"]["Error"]; + }; + }; recordPageVisit: { parameters: { query?: never; diff --git a/Packages/editor/src/DocwellEditor.vue b/Packages/editor/src/DocwellEditor.vue index 54ee06d..45614fa 100644 --- a/Packages/editor/src/DocwellEditor.vue +++ b/Packages/editor/src/DocwellEditor.vue @@ -4,7 +4,7 @@ import type { Editor, JSONContent } from "@tiptap/core"; import { EditorContent, useEditor } from "@tiptap/vue-3"; import { BubbleMenu } from "@tiptap/vue-3/menus"; import { CellSelection } from "@tiptap/pm/tables"; -import { DwIcon, type IconName } from "@docwell/ui"; +import { DwButton, DwIcon, type IconName } from "@docwell/ui"; import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue"; import { aiActions, type AiAction, type AiHost } from "./ai"; import { copyBlockLink } from "./blocklinks"; @@ -17,6 +17,7 @@ import { englishLabels, type EditorLabels } from "./labels"; import type { MentionHost } from "./mention"; import { createLinkedPage, type PageHost } from "./pagelinks"; import type { CollabProvider } from "./provider"; +import { suggestionAt, suggestionsOf, type Suggestion, type SuggestionAuthor } from "./suggest"; import type { SyncedPageHost } from "./syncedpage"; import type * as Y from "yjs"; @@ -53,6 +54,8 @@ const props = withDefaults( ai?: AiHost; /** Edits this fragment of a document instead (a note on the canvas), without carets. */ fragment?: { doc: Y.Doc; fragment: Y.XmlFragment }; + /** Suggesting mode: edits become suggestions made by this person. */ + suggesting?: SuggestionAuthor | null; }>(), { editable: true }, ); @@ -97,20 +100,70 @@ const editor = useEditor({ onOpenDate: props.journals ? (date) => emit("navigate", `/journal/${date}`) : undefined, labels: props.labels, onCommentSelect: (id) => emit("comment-select", id), + onSuggestionSelect: (id, el) => pickSuggestion(id, el), onError: (e) => emit("error", e), }), editorProps: { attributes: { class: "dw-prose" } }, onUpdate: ({ editor }) => emit("update", editor.getJSON()), - onTransaction: ({ editor }) => { + onCreate: ({ editor }) => { + if (props.suggesting) editor.commands.setSuggesting(props.suggesting); + suggestions.value = suggestionsOf(editor.state.doc); + }, + onTransaction: ({ editor, transaction }) => { + if (transaction.docChanged) { + suggestions.value = suggestionsOf(editor.state.doc); + if (picked.value && !suggestions.value.some((s) => s.id === picked.value!.s.id)) picked.value = null; + } const f = findKey.getState(editor.state); found.value = { current: f?.current ?? -1, total: f?.matches.length ?? 0 }; }, onBlur: () => emit("blur"), onSelectionUpdate: ({ editor }) => { if (editor.state.selection.empty) panel.value = null; + // The card stays while the caret is in its suggestion (clicking it moves the caret there). + if (picked.value && suggestionAt(editor.state, editor.state.selection.head) !== picked.value.s.id) + picked.value = null; }, }); +// Suggesting mode: the open suggestions, and the one whose card is showing. +const suggestions = ref([]); +const picked = ref<{ s: Suggestion; top: number; left: number } | null>(null); +const root = ref(null); +watch( + () => props.suggesting, + (a) => editor.value?.commands.setSuggesting(a ?? null), +); +function pickSuggestion(id: string, el: HTMLElement) { + // After the click's own selection change, which closes any open card. + void nextTick(() => { + const s = suggestions.value.find((x) => x.id === id); + const host = root.value?.getBoundingClientRect(); + if (!s || !host) return; + const r = el.getBoundingClientRect(); + picked.value = { + s, + top: r.bottom - host.top + 6, + left: Math.max(0, Math.min(r.left - host.left, host.width - 288)), + }; + }); +} +function decide(accept: boolean, id?: string) { + const c = editor.value?.chain().focus(); + if (!c) return; + if (id) (accept ? c.acceptSuggestion(id) : c.rejectSuggestion(id)).run(); + else (accept ? c.acceptAllSuggestions() : c.rejectAllSuggestions()).run(); + picked.value = null; +} +const suggestionCount = computed(() => + suggestions.value.length === 1 + ? labels.value.suggest.one + : labels.value.suggest.count.replace("{n}", String(suggestions.value.length)), +); +const when = (at: number) => + at ? new Intl.DateTimeFormat(labels.value.locale, { dateStyle: "medium", timeStyle: "short" }).format(at) : ""; +const short = (text: string) => (text.length > 120 ? text.slice(0, 117) + "…" : text); + watch( () => props.editable, (v) => editor.value?.setEditable(v), @@ -436,7 +489,64 @@ defineExpose({ editor, openFind });