Files
Docwell/Database/pb_migrations/1762700000_comments.js
T
tajniak81andClaude Opus 5.5 92cd81fd96 Add the slash menu, bubble menu, mentions and inline comments
Editor:
- "/" opens a filterable block menu (text, headings, lists, quote, code,
  divider, and image or file upload when the host can store files).
- Selecting text shows a formatting toolbar (bold, italic, strike, code,
  link) and, for anyone who may comment, a Comment button.
- "@" finds people in the page's workspace; the mention node is always in
  the schema so documents with mentions open in every client.
- The popups are plain DOM in the design system's slash-menu style, so
  the framework-free mobile bridge keeps building and can use them.
- Menu words come from the host; the web app passes English or Polish.

Inline comments (basic): commenters cannot edit the document, so a
comment's anchor is a pair of Yjs relative positions stored with the
comment rather than a mark in the text. Highlights follow local edits by
mapping and are re-resolved when comments change or remote edits arrive.
Pages get a comments panel (side column, or a bottom sheet on narrow
screens). Authors and space admins can delete comments.

Server: comments collection and endpoints, and a people lookup any
workspace member may use for mentions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:25:19 +01:00

41 lines
1.6 KiB
JavaScript

// SPDX-License-Identifier: AGPL-3.0-or-later
/// <reference path="../pb_data/types.d.ts" />
// Inline comments. A comment points at a range of the page's text through
// anchor: Yjs relative positions (encoded by the editor), which follow the
// text as people edit. Commenters cannot change the document, so the anchor
// lives here instead of as a mark in the text.
migrate(
(app) => {
const users = app.findCollectionByNameOrId("users");
const pages = app.findCollectionByNameOrId("pages");
const workspaces = app.findCollectionByNameOrId("workspaces");
app.save(
new Collection({
type: "base",
name: "comments",
fields: [
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "author", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false },
{ name: "body", type: "text", required: true, max: 5000 },
// The commented text when the comment was written.
{ name: "quote", type: "text", max: 500 },
{ name: "anchor", type: "json", maxSize: 4096 },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: ["CREATE INDEX idx_comments_page ON comments (page, created)"],
}),
);
},
(app) => {
try {
app.delete(app.findCollectionByNameOrId("comments"));
} catch (_) {}
},
);