import { escapeHtml } from "../lib/html.ts"; import { t } from "../lib/i18n/index.ts"; import { editNoteUrl, noteUrl } from "../lib/urls.ts"; import type { WikiIdentity } from "../lib/wiki-identity.ts"; import { type LayoutOptions, layout } from "./layout.ts"; import { inputClass, primaryButtonClass, THEME } from "./theme/index.ts"; export interface CollabEditOptions { enabled: boolean; /** WebSocket path for the collab session (client prepends ws(s)://host). */ wsPath: string; /** Current editor's identity, for presence/awareness. */ did: string; handle: string; displayName: string; /** Profile picture URL, broadcast to peers for the presence cluster. */ avatar: string; /** Where to navigate after save/discard. */ noteUrl: string; } export function editNotePage( wiki: WikiIdentity, noteSlug: string, noteTitle: string, currentContent: string, options?: LayoutOptions, collab?: CollabEditOptions, ): string { const locale = options?.locale ?? "en"; const msg = t(locale); const collabAttrs = collab?.enabled ? ` data-collab="1" data-collab-ws="${escapeHtml(collab.wsPath)}" data-collab-connecting="${escapeHtml(msg.editor.collabConnecting)}" data-collab-you="${escapeHtml(msg.editor.collabYou)}" data-collab-live="${escapeHtml(msg.editor.collabLive)}" data-collab-editing="${escapeHtml(msg.editor.collabEditing)}" data-did="${escapeHtml(collab.did)}" data-handle="${escapeHtml(collab.handle)}" data-display-name="${escapeHtml(collab.displayName)}" data-avatar="${escapeHtml(collab.avatar)}" data-note-url="${escapeHtml(collab.noteUrl)}"` : ""; // Presence cluster, parked at the right end of the title row. Rendered hidden, // then revealed by renderPresence() in editor.ts once the collab socket is // connected — including solo, where the lone avatar confirms live sync is on. // It's shrink-0, so the title (flex-1) yields just the space it needs. The node // is removed entirely if collaboration falls back to plain (non-live) mode. const collabPresence = collab?.enabled ? `
` : ""; // The editor/preview panes size themselves (see editor.ts), so the form just // flows in document order — the action bar can never be clipped on short // viewports the way the old viewport-pinned, overflow-hidden form could be. const formHtml = ` `; return layout(`${msg.wiki.edit} ${noteTitle}`, formHtml, { ...options, wikiName: wiki.name, wikiSlug: wiki.slug, ownerHandle: wiki.handle, noindex: true, }); }