Files
Docwell/Web-App/frontend/src/platform.ts
T
tajniak81andClaude Opus 5.5 40d515d15b Add toggles, embeds, link cards, block links, archive, version diff, space export and desktop 1.0
Editor:
- Toggles (Tiptap Details). Open state is per reader, not saved.
- Embeds for YouTube, Vimeo, Loom, Figma, CodePen, Spotify, Google Docs
  and Maps, in sandboxed frames. Other addresses become link cards.
- Link cards with title, description and picture read by docwell-server
  (GET /link-preview). The fetcher refuses private, loopback, link-local
  and CGNAT addresses after DNS resolution, redirects included.
- Block links: a margin button gives a block a short id and copies
  /p/<id>#b-<block>. Opening one jumps to the block and flashes it.
- Markdown, HTML and PDF exports handle the new blocks; HTML import reads
  <details> as a toggle.

Pages and spaces:
- History gets a Changes view: block and word diff against the previous
  version or the page as it is now.
- Archive: archived pages leave the tree and become read-only but stay
  readable; a space's Archive lists them with Unarchive. New migration
  (pages.archived_at) and page.archived / page.unarchived webhook events.
- Full space export (GET /spaces/{id}/export): a zip of Markdown or HTML
  files with subpages in folders, an index, and attachments under _files/.
  Links between exported pages and to attachments become relative paths.

Desktop 1.0:
- Several servers, each with its own sign-in; old settings files carry over.
- Session tokens in the system keychain (go-keyring), moved out of
  localStorage on first start.
- Native menu bar (File, Edit, View, Window, Help) with a Server submenu.
- docwell:// links may point at a block.
- Release workflow builds Windows NSIS, macOS DMG and Linux deb, rpm and
  AppImage installers and attaches them to the release;
  build/set-version.mjs stamps the version into their metadata.

Not yet run: the release workflow, the desktop menus by eye, and macOS or
Linux builds.

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

87 lines
2.9 KiB
TypeScript

// SPDX-License-Identifier: AGPL-3.0-or-later
import { inject, type InjectionKey } from "vue";
/** Runtime settings the app needs to reach docwell-server. */
export interface RuntimeConfig {
/** Base URL of docwell-server; "" means same origin (docwell-web proxy). */
apiUrl: string;
collabUrl: string;
version: string;
/** Where the Draw.io editor is loaded from (default https://embed.diagrams.net). */
drawioUrl?: string;
}
/** Keeps the session token. The browser uses localStorage; the desktop app the system keychain. */
export interface TokenStore {
get(): string | null;
set(token: string | null): void;
}
/** A docwell-server the desktop app can sign in to. */
export interface ServerEntry {
id: string;
name: string;
url: string;
}
/**
* The desktop app's saved servers. Adding one or switching reloads the
* window, which then talks to the newly active server with its own session.
*/
export interface ServerHost {
list(): Promise<{ servers: ServerEntry[]; active: string }>;
add(name: string, url: string): Promise<void>;
rename(id: string, name: string): Promise<void>;
/** Forgets a server and signs out of it. */
remove(id: string): Promise<void>;
switchTo(id: string): Promise<void>;
}
/** Menu commands a host can send: the native menu bar on the desktop. */
export type AppCommand = "new-page" | "search" | "toggle-sidebar";
/**
* Differences between hosts that run this app: browser (docwell-web),
* Desktop-App (Wails) and the Phone-App editor WebView.
*/
export interface Platform {
kind: "web" | "desktop" | "mobile";
loadConfig(): Promise<RuntimeConfig>;
/** Calls open with an app route (e.g. "/p/abc") when the OS opens a docwell:// link. */
onOpenRoute?(open: (route: string) => void): void;
/** The address to share for an app route, e.g. a copied link to a block. */
pageUrl(route: string): string;
/** Where the session token is kept; without it, localStorage. */
tokenStore?(): Promise<TokenStore>;
/** Calls run with each command from the host's own menus. */
onCommand?(run: (command: AppCommand) => void): void;
/** The servers to choose from (desktop only). */
servers?: ServerHost;
}
export const webPlatform: Platform = {
kind: "web",
async loadConfig() {
const res = await fetch("/config.json", { cache: "no-cache" });
if (!res.ok || !res.headers.get("content-type")?.includes("json")) {
// Vite dev server: no docwell-web in front (its SPA fallback answers with
// index.html), so use the dev proxy.
return { apiUrl: "", collabUrl: "", version: "dev" };
}
return (await res.json()) as RuntimeConfig;
},
pageUrl: (route) => location.origin + route,
};
export const platformKey: InjectionKey<Platform> = Symbol("platform");
export const configKey: InjectionKey<RuntimeConfig> = Symbol("config");
export function usePlatform(): Platform {
return inject(platformKey)!;
}
export function useRuntimeConfig(): RuntimeConfig {
return inject(configKey)!;
}