From f20e5f96f9dd9b8d4c99f5ed829853ae79580e04 Mon Sep 17 00:00:00 2001 From: tajniak81 <13187254+tajniak81@users.noreply.github.com> Date: Mon, 2 Nov 2026 14:35:18 +0100 Subject: [PATCH] Add search filters, space pins, find and replace and page layout - Search can be narrowed by space, author and last change; the index records a mapping version and rebuilds when it changes. - Editors can pin up to 12 pages to a space's home. - Find and replace in the editor (Ctrl+F), with match case. - Pages can be set to full width and a serif or mono font. - Tailwind now scans the editor package, so its classes are generated. - Fix golangci-lint findings, including push device names that were saved before being trimmed and capped. Co-Authored-By: Claude Opus 5.5 --- Database/pb_migrations/1763400000_pins.js | 19 ++ .../pb_migrations/1763500000_page_style.js | 21 ++ Packages/api-client/src/index.ts | 21 +- Packages/api-client/src/schema.d.ts | 147 +++++++++++++- Packages/editor/package.json | 7 +- Packages/editor/src/DocwellEditor.vue | 159 ++++++++++++++- Packages/editor/src/editor.css | 23 +++ Packages/editor/src/extensions.ts | 2 + Packages/editor/src/find.test.ts | 65 ++++++ Packages/editor/src/find.ts | 189 ++++++++++++++++++ Packages/editor/src/index.ts | 1 + Packages/editor/src/labels.ts | 25 +++ Packages/editor/vitest.config.ts | 7 + Packages/ui/src/icons.ts | 4 + Phone-App/lib/api/generated/models.dart | 70 +++++++ Phone-App/test/widget_test.dart | 3 + Server/internal/api/api.gen.go | 67 ++++++- Server/internal/convert/docx.go | 4 +- Server/internal/convert/notion.go | 3 + Server/internal/convert/transfer_test.go | 3 +- Server/internal/directory/pages.go | 28 ++- Server/internal/directory/permissions.go | 14 -- Server/internal/directory/pins.go | 108 ++++++++++ Server/internal/directory/pins_test.go | 24 +++ Server/internal/directory/search.go | 52 ++++- Server/internal/directory/search_test.go | 34 ++++ Server/internal/httpapi/search.go | 8 +- Server/internal/httpapi/spaces.go | 15 ++ Server/internal/push/push.go | 2 +- Server/internal/push/webpush.go | 7 +- Server/internal/search/search.go | 158 +++++++++++---- Server/internal/search/search_test.go | 88 +++++++- Server/internal/unfurl/unfurl.go | 4 +- .../frontend/src/components/SearchPalette.vue | 92 ++++++++- .../src/composables/useEditorHosts.ts | 17 ++ Web-App/frontend/src/locales/en.json | 38 +++- Web-App/frontend/src/locales/pl.json | 38 +++- Web-App/frontend/src/views/page/PageView.vue | 46 ++++- .../frontend/src/views/space/SpaceView.vue | 44 +++- api/openapi.yaml | 82 +++++++- package-lock.json | 4 +- 41 files changed, 1634 insertions(+), 109 deletions(-) create mode 100644 Database/pb_migrations/1763400000_pins.js create mode 100644 Database/pb_migrations/1763500000_page_style.js create mode 100644 Packages/editor/src/find.test.ts create mode 100644 Packages/editor/src/find.ts create mode 100644 Packages/editor/vitest.config.ts create mode 100644 Server/internal/directory/pins.go create mode 100644 Server/internal/directory/pins_test.go create mode 100644 Server/internal/directory/search_test.go diff --git a/Database/pb_migrations/1763400000_pins.js b/Database/pb_migrations/1763400000_pins.js new file mode 100644 index 0000000..d534257 --- /dev/null +++ b/Database/pb_migrations/1763400000_pins.js @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +/// + +// pages.pinned_at: pages pinned to their space's home, for everyone who can +// open them, in the order they were pinned (see directory/pins.go). + +migrate( + (app) => { + const pages = app.findCollectionByNameOrId("pages"); + pages.fields.add(new DateField({ name: "pinned_at" })); + app.save(pages); + }, + (app) => { + const pages = app.findCollectionByNameOrId("pages"); + pages.fields.removeByName("pinned_at"); + app.save(pages); + }, +); diff --git a/Database/pb_migrations/1763500000_page_style.js b/Database/pb_migrations/1763500000_page_style.js new file mode 100644 index 0000000..7ee47a7 --- /dev/null +++ b/Database/pb_migrations/1763500000_page_style.js @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later + +/// + +// How a page is laid out for everyone who reads it: full width instead of the +// reading column, and the body font ("" is the default sans). + +migrate( + (app) => { + const pages = app.findCollectionByNameOrId("pages"); + pages.fields.add(new BoolField({ name: "full_width" })); + pages.fields.add(new SelectField({ name: "font", maxSelect: 1, values: ["serif", "mono"] })); + app.save(pages); + }, + (app) => { + const pages = app.findCollectionByNameOrId("pages"); + pages.fields.removeByName("full_width"); + pages.fields.removeByName("font"); + app.save(pages); + }, +); diff --git a/Packages/api-client/src/index.ts b/Packages/api-client/src/index.ts index b82fbe9..0b083c1 100644 --- a/Packages/api-client/src/index.ts +++ b/Packages/api-client/src/index.ts @@ -28,6 +28,8 @@ export type PageRef = Schemas["PageRef"]; export type Page = Schemas["Page"]; export type TrashedPage = Schemas["TrashedPage"]; export type ArchivedPage = Schemas["ArchivedPage"]; +export type PinnedPage = Schemas["PinnedPage"]; +export type PageFont = Schemas["PageFont"]; export type LinkPreview = Schemas["LinkPreview"]; export type PageContent = Schemas["PageContent"]; export type PageVersion = Schemas["PageVersion"]; @@ -341,8 +343,11 @@ export function createClient(opts: ClientOptions) { groups: (id: string) => request("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/groups`), people: (id: string, q: string, limit?: number) => request("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/people${query({ q, limit })}`), - search: (id: string, q: string, limit?: number) => - request("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/search${query({ q, limit })}`), + search: (id: string, q: string, limit?: number, filter: SearchFilter = {}) => + request( + "GET", + `/api/v1/workspaces/${encodeURIComponent(id)}/search${query({ q, limit, ...filter })}`, + ), favorites: (id: string) => request("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/favorites`), templates: (id: string) => request("GET", `/api/v1/workspaces/${encodeURIComponent(id)}/templates`), recent: (id: string, limit?: number) => @@ -382,6 +387,7 @@ export function createClient(opts: ClientOptions) { post(`/api/v1/spaces/${encodeURIComponent(id)}/pages`, input), trash: (id: string) => request("GET", `/api/v1/spaces/${encodeURIComponent(id)}/trash`), archive: (id: string) => request("GET", `/api/v1/spaces/${encodeURIComponent(id)}/archive`), + pinned: (id: string) => request("GET", `/api/v1/spaces/${encodeURIComponent(id)}/pinned`), /** The whole space as a zip of Markdown or HTML files. */ export: (id: string, format: "markdown" | "html") => download(`/api/v1/spaces/${encodeURIComponent(id)}/export${query({ format })}`), @@ -396,8 +402,10 @@ export function createClient(opts: ClientOptions) { pages: { get: (id: string) => request("GET", `/api/v1/pages/${encodeURIComponent(id)}`), - update: (id: string, patch: { title?: string; icon?: string; isTemplate?: boolean }) => - request("PATCH", `/api/v1/pages/${encodeURIComponent(id)}`, patch), + update: ( + id: string, + patch: { title?: string; icon?: string; isTemplate?: boolean; fullWidth?: boolean; font?: PageFont }, + ) => request("PATCH", `/api/v1/pages/${encodeURIComponent(id)}`, patch), /** Moves a page under parent ("" = top level) at index among its other children. */ content: (id: string) => request("GET", `/api/v1/pages/${encodeURIComponent(id)}/content`), /** Replaces the page's document; content is Tiptap JSON with type "doc". */ @@ -417,6 +425,8 @@ export function createClient(opts: ClientOptions) { restore: (id: string) => post(`/api/v1/pages/${encodeURIComponent(id)}/restore`), archive: (id: string) => post(`/api/v1/pages/${encodeURIComponent(id)}/archive`), 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`), /** A web page's title, description and picture, read by docwell-server. */ preview: (url: string) => request("GET", `/api/v1/link-preview${query({ url })}`), setFavorite: (id: string, on: boolean) => @@ -483,6 +493,9 @@ export function createClient(opts: ClientOptions) { }; } +/** Optional narrowing for workspaces.search; dates are RFC 3339 times or YYYY-MM-DD days. */ +export type SearchFilter = { space?: string; author?: string; updatedAfter?: string; updatedBefore?: string }; + function query(params: Record): string { const qs = new URLSearchParams(); for (const [k, v] of Object.entries(params)) if (v !== undefined && v !== "") qs.set(k, String(v)); diff --git a/Packages/api-client/src/schema.d.ts b/Packages/api-client/src/schema.d.ts index 1be208f..941fe0d 100644 --- a/Packages/api-client/src/schema.d.ts +++ b/Packages/api-client/src/schema.d.ts @@ -749,6 +749,28 @@ export interface paths { patch?: never; trace?: never; }; + "/api/v1/spaces/{id}/pinned": { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + /** + * Pages pinned to the space's home, in the order they were pinned + * @description Pinned pages in the trash or the archive are left out until they are restored. + */ + get: operations["listPinned"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/v1/spaces/{id}/export": { parameters: { query?: never; @@ -788,7 +810,7 @@ export interface paths { delete: operations["deletePage"]; options?: never; head?: never; - /** Rename a page, change its icon, or make it a template (editor) */ + /** Rename a page, change its icon or layout, or make it a template (editor) */ patch: operations["updatePage"]; trace?: never; }; @@ -1334,6 +1356,26 @@ export interface paths { patch?: never; trace?: never; }; + "/api/v1/pages/{id}/pin": { + parameters: { + query?: never; + header?: never; + path: { + id: string; + }; + cookie?: never; + }; + get?: never; + /** Pin the page to its space's home for everyone (editor; at most 12 per space) */ + put: operations["pinPage"]; + post?: never; + /** Take the page off its space's home (editor) */ + delete: operations["unpinPage"]; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/api/v1/pages/{id}/visit": { parameters: { query?: never; @@ -1445,7 +1487,7 @@ export interface paths { }; /** * Full-text search of page titles and text, in the spaces the caller can open - * @description Trashed pages are not found. The index catches up with edits within a few seconds. + * @description Trashed pages are not found. The index catches up with edits within a few seconds. The filters narrow the results; with an empty q and at least one filter, the matching pages are listed, most recently changed first. A space the caller cannot open finds nothing. */ get: operations["searchPages"]; put?: never; @@ -2353,7 +2395,17 @@ export interface components { isTemplate: boolean; /** @description In the caller's favorites */ favorite: boolean; + /** @description When the page was pinned to its space's home; empty if not */ + pinnedAt: string; + /** @description Shown across the whole window instead of the reading column */ + fullWidth: boolean; + font: components["schemas"]["PageFont"]; }; + /** + * @description The body font for everyone reading the page; empty is the default sans + * @enum {string} + */ + PageFont: "" | "serif" | "mono"; /** @enum {string} */ PageGrantRole: "editor" | "commenter" | "viewer"; /** @@ -2440,6 +2492,13 @@ export interface components { icon: string; archivedAt: string; }; + PinnedPage: { + id: string; + title: string; + icon: string; + updated: string; + pinnedAt: string; + }; LinkPreview: { url: string; title: string; @@ -4271,6 +4330,29 @@ export interface operations { 404: components["responses"]["Error"]; }; }; + listPinned: { + 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"]["PinnedPage"][]; + }; + }; + 404: components["responses"]["Error"]; + }; + }; exportSpace: { parameters: { query?: { @@ -4361,6 +4443,9 @@ export interface operations { icon?: string; /** @description Offer the page as a template for new pages */ isTemplate?: boolean; + /** @description Use the whole window instead of the reading column */ + fullWidth?: boolean; + font?: components["schemas"]["PageFont"]; }; }; }; @@ -5265,6 +5350,55 @@ export interface operations { 404: components["responses"]["Error"]; }; }; + pinPage: { + 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"]; + }; + }; + 400: components["responses"]["Error"]; + 403: components["responses"]["Error"]; + 404: components["responses"]["Error"]; + }; + }; + unpinPage: { + 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; @@ -5419,6 +5553,14 @@ export interface operations { query: { q: string; limit?: number; + /** @description Only pages in this space */ + space?: string; + /** @description Only pages this user created or last edited */ + author?: string; + /** @description Only pages changed at or after this time (RFC 3339) or day (YYYY-MM-DD) */ + updatedAfter?: string; + /** @description Only pages changed at or before this time (RFC 3339) or the end of this day (YYYY-MM-DD) */ + updatedBefore?: string; }; header?: never; path: { @@ -5437,6 +5579,7 @@ export interface operations { "application/json": components["schemas"]["SearchResult"]; }; }; + 400: components["responses"]["Error"]; 404: components["responses"]["Error"]; }; }; diff --git a/Packages/editor/package.json b/Packages/editor/package.json index e6b728f..9ee23b7 100644 --- a/Packages/editor/package.json +++ b/Packages/editor/package.json @@ -11,6 +11,9 @@ "./provider": "./src/provider.ts", "./editor.css": "./src/editor.css" }, + "scripts": { + "test": "vitest run" + }, "dependencies": { "@docwell/ui": "*", "@excalidraw/excalidraw": "^0.18.1", @@ -42,6 +45,8 @@ }, "devDependencies": { "@types/react": "^18.3.31", - "@types/react-dom": "^18.3.7" + "@types/react-dom": "^18.3.7", + "jsdom": "^30.1.3", + "vitest": "^5.0.5" } } diff --git a/Packages/editor/src/DocwellEditor.vue b/Packages/editor/src/DocwellEditor.vue index 61fbd33..f916d43 100644 --- a/Packages/editor/src/DocwellEditor.vue +++ b/Packages/editor/src/DocwellEditor.vue @@ -4,8 +4,9 @@ import type { Editor, JSONContent } from "@tiptap/core"; import { EditorContent, useEditor } from "@tiptap/vue-3"; import { BubbleMenu } from "@tiptap/vue-3/menus"; import { DwIcon, type IconName } from "@docwell/ui"; -import { computed, onBeforeUnmount, watch } from "vue"; +import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue"; import { docwellExtensions, type CollabUser } from "./extensions"; +import { findKey } from "./find"; import type { LinkHost } from "./embeds"; import type { FileHost } from "./files"; import { englishLabels, type EditorLabels } from "./labels"; @@ -76,6 +77,10 @@ const editor = useEditor({ }), editorProps: { attributes: { class: "dw-prose" } }, onUpdate: ({ editor }) => emit("update", editor.getJSON()), + onTransaction: ({ editor }) => { + const f = findKey.getState(editor.state); + found.value = { current: f?.current ?? -1, total: f?.matches.length ?? 0 }; + }, onBlur: () => emit("blur"), }); @@ -146,11 +151,159 @@ function shouldShow({ editor: e, from, to }: { editor: Editor; from: number; to: return e.isEditable || props.canComment; } -defineExpose({ editor }); +// Find and replace (Ctrl+F / Cmd+F while editing, or openFind from the host). +const finding = ref(false); +const findText = ref(""); +const replaceText = ref(""); +const matchCase = ref(false); +const findInput = ref(null); +const found = ref({ current: -1, total: 0 }); +const findCount = computed(() => + found.value.total + ? labels.value.find.count + .replace("{current}", String(found.value.current + 1)) + .replace("{total}", String(found.value.total)) + : findText.value + ? labels.value.find.none + : "", +); + +async function openFind() { + const e = editor.value; + if (!e) return; + const { from, to } = e.state.selection; + const picked = e.state.doc.textBetween(from, to, "\n"); + if (picked && !picked.includes("\n") && picked.length <= 200) findText.value = picked; + finding.value = true; + await nextTick(); + findInput.value?.focus(); + findInput.value?.select(); + e.commands.setFind(findText.value, matchCase.value); +} + +function closeFind() { + finding.value = false; + editor.value?.chain().clearFind().focus().run(); +} + +watch([findText, matchCase], ([text, mc]) => { + if (finding.value) editor.value?.commands.setFind(text, mc); +}); + +function onFindKey(e: KeyboardEvent) { + if (e.key === "Enter") { + e.preventDefault(); + editor.value?.commands.findStep(e.shiftKey ? -1 : 1); + } else if (e.key === "Escape") { + e.preventDefault(); + closeFind(); + } +} + +function onKeydown(e: KeyboardEvent) { + if ((e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey && e.key.toLowerCase() === "f") { + e.preventDefault(); + void openFind(); + } +} + +defineExpose({ editor, openFind });