diff --git a/web/boot.ts b/web/boot.ts index a13169e..d3144e8 100644 --- a/web/boot.ts +++ b/web/boot.ts @@ -1,16 +1,14 @@ import { safeRun } from "../common/util.ts"; -import { Editor } from "./editor.ts"; +import { Client } from "./client.ts"; safeRun(async () => { - console.log("Booting"); + console.log("Booting SilverBullet..."); - const editor = new Editor( + const client = new Client( document.getElementById("sb-root")!, ); - - window.editor = editor; - - await editor.init(); + await client.init(); + window.client = client; }); if (navigator.serviceWorker) { diff --git a/web/editor.ts b/web/client.ts similarity index 99% rename from web/editor.ts rename to web/client.ts index 8b4c5d7..9bcc41d 100644 --- a/web/editor.ts +++ b/web/client.ts @@ -4,7 +4,6 @@ import { CompletionResult, EditorView, gitIgnoreCompiler, - runScopeHandlers, syntaxTree, } from "../common/deps.ts"; import { Space } from "./space.ts"; @@ -44,12 +43,12 @@ declare global { silverBulletConfig: { spaceFolderPath: string; }; - editor: Editor; + client: Client; } } // TODO: Oh my god, need to refactor this -export class Editor { +export class Client { editorView?: EditorView; pageNavigator?: PathPageNavigator; @@ -293,7 +292,7 @@ export class Editor { this.ui.viewDispatch({ type: "sync-change", synced: true }); }); - this.eventHook.addLocalListener("sync:error", (name) => { + this.eventHook.addLocalListener("sync:error", (_name) => { this.ui.viewDispatch({ type: "sync-change", synced: false }); }); this.eventHook.addLocalListener("sync:conflict", (name) => { @@ -316,7 +315,7 @@ export class Editor { try { settingsText = (await this.space.readPage("SETTINGS")).text; - } catch (e: any) { + } catch { console.log("No SETTINGS page, falling back to default"); settingsText = "```yaml\nindexPage: index\n```\n"; } diff --git a/web/client_system.ts b/web/client_system.ts index 5bb301c..1c30dcf 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -10,7 +10,7 @@ import assetSyscalls from "../plugos/syscalls/asset.ts"; import { eventSyscalls } from "../plugos/syscalls/event.ts"; import { storeSyscalls } from "../plugos/syscalls/store.dexie_browser.ts"; import { SysCallMapping, System } from "../plugos/system.ts"; -import type { Editor } from "./editor.ts"; +import type { Client } from "./client.ts"; import { CodeWidgetHook } from "./hooks/code_widget.ts"; import { CommandHook } from "./hooks/command.ts"; import { SlashCommandHook } from "./hooks/slash_command.ts"; @@ -42,7 +42,7 @@ export class ClientSystem { mdExtensions: MDExt[] = []; constructor( - private editor: Editor, + private editor: Client, private kvStore: DexieKVStore, private dbPrefix: string, private eventHook: EventHook, diff --git a/web/cm_plugins/admonition.ts b/web/cm_plugins/admonition.ts index e80e4b4..f176427 100644 --- a/web/cm_plugins/admonition.ts +++ b/web/cm_plugins/admonition.ts @@ -6,7 +6,7 @@ import { syntaxTree, WidgetType, } from "../deps.ts"; -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { decoratorStateField, isCursorInRange } from "./util.ts"; type AdmonitionType = "note" | "warning"; @@ -97,7 +97,7 @@ function extractAdmonitionFields(rawText: string): AdmonitionFields | null { return null; } -export function admonitionPlugin(editor: Editor) { +export function admonitionPlugin(editor: Client) { return decoratorStateField((state: EditorState) => { const widgets: any[] = []; diff --git a/web/cm_plugins/clean.ts b/web/cm_plugins/clean.ts index 9aabba5..65f2656 100644 --- a/web/cm_plugins/clean.ts +++ b/web/cm_plugins/clean.ts @@ -1,6 +1,6 @@ import type { ClickEvent } from "../../plug-api/app_event.ts"; import type { Extension } from "../deps.ts"; -import type { Editor } from "../editor.ts"; +import type { Client } from "../client.ts"; import { blockquotePlugin } from "./block_quote.ts"; import { admonitionPlugin } from "./admonition.ts"; import { directivePlugin } from "./directive.ts"; @@ -14,7 +14,7 @@ import { cleanWikiLinkPlugin } from "./wiki_link.ts"; import { cleanCommandLinkPlugin } from "./command_link.ts"; import { fencedCodePlugin } from "./fenced_code.ts"; -export function cleanModePlugins(editor: Editor) { +export function cleanModePlugins(editor: Client) { return [ linkPlugin(), directivePlugin(), diff --git a/web/cm_plugins/command_link.ts b/web/cm_plugins/command_link.ts index 9f2f7dd..cfb0eab 100644 --- a/web/cm_plugins/command_link.ts +++ b/web/cm_plugins/command_link.ts @@ -1,7 +1,7 @@ import { commandLinkRegex } from "../../common/markdown_parser/parser.ts"; import { ClickEvent } from "$sb/app_event.ts"; import { Decoration, syntaxTree } from "../deps.ts"; -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { ButtonWidget, decoratorStateField, @@ -12,7 +12,7 @@ import { /** * Plugin to hide path prefix when the cursor is not inside. */ -export function cleanCommandLinkPlugin(editor: Editor) { +export function cleanCommandLinkPlugin(editor: Client) { return decoratorStateField((state) => { const widgets: any[] = []; // let parentRange: [number, number]; diff --git a/web/cm_plugins/editor_paste.ts b/web/cm_plugins/editor_paste.ts index 69f63e6..c436a3a 100644 --- a/web/cm_plugins/editor_paste.ts +++ b/web/cm_plugins/editor_paste.ts @@ -1,6 +1,6 @@ import { EditorView, syntaxTree, ViewPlugin, ViewUpdate } from "../deps.ts"; import { maximumAttachmentSize } from "../../common/types.ts"; -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; // We use turndown to convert HTML to Markdown import TurndownService from "https://cdn.skypack.dev/turndown@7.1.1"; @@ -80,7 +80,7 @@ export const pasteLinkExtension = ViewPlugin.fromClass( }, ); -export function attachmentExtension(editor: Editor) { +export function attachmentExtension(editor: Client) { let shiftDown = false; return EditorView.domEventHandlers({ dragover: (event) => { diff --git a/web/cm_plugins/fenced_code.ts b/web/cm_plugins/fenced_code.ts index da58147..77dab6a 100644 --- a/web/cm_plugins/fenced_code.ts +++ b/web/cm_plugins/fenced_code.ts @@ -1,7 +1,7 @@ import { WidgetContent } from "../../plug-api/app_event.ts"; import { panelHtml } from "../components/panel.tsx"; import { Decoration, EditorState, syntaxTree, WidgetType } from "../deps.ts"; -import type { Editor } from "../editor.ts"; +import type { Client } from "../client.ts"; import { CodeWidgetCallback } from "../hooks/code_widget.ts"; import { decoratorStateField, @@ -13,7 +13,7 @@ class IFrameWidget extends WidgetType { constructor( readonly from: number, readonly to: number, - readonly editor: Editor, + readonly editor: Client, readonly bodyText: string, readonly codeWidgetCallback: CodeWidgetCallback, ) { @@ -94,7 +94,7 @@ class IFrameWidget extends WidgetType { } } -export function fencedCodePlugin(editor: Editor) { +export function fencedCodePlugin(editor: Client) { return decoratorStateField((state: EditorState) => { const widgets: any[] = []; syntaxTree(state).iterate({ diff --git a/web/cm_plugins/inline_image.ts b/web/cm_plugins/inline_image.ts index de93f61..4db2d50 100644 --- a/web/cm_plugins/inline_image.ts +++ b/web/cm_plugins/inline_image.ts @@ -8,7 +8,7 @@ import { import { decoratorStateField } from "./util.ts"; import type { Space } from "../space.ts"; -import type { Editor } from "../editor.ts"; +import type { Client } from "../client.ts"; class InlineImageWidget extends WidgetType { constructor( @@ -53,7 +53,7 @@ class InlineImageWidget extends WidgetType { } } -export function inlineImagesPlugin(editor: Editor) { +export function inlineImagesPlugin(editor: Client) { return decoratorStateField((state: EditorState) => { const widgets: Range[] = []; const imageRegex = /!\[(?[^\]]*)\]\((?<url>.+)\)/; diff --git a/web/cm_plugins/table.ts b/web/cm_plugins/table.ts index 2ce78fb..0dbe873 100644 --- a/web/cm_plugins/table.ts +++ b/web/cm_plugins/table.ts @@ -8,12 +8,12 @@ import { import { renderMarkdownToHtml } from "../../plugs/markdown/markdown_render.ts"; import { ParseTree } from "$sb/lib/tree.ts"; import { lezerToParseTree } from "../../common/markdown_parser/parse_tree.ts"; -import type { Editor } from "../editor.ts"; +import type { Client } from "../client.ts"; class TableViewWidget extends WidgetType { constructor( readonly pos: number, - readonly editor: Editor, + readonly editor: Client, readonly t: ParseTree, ) { super(); @@ -48,7 +48,7 @@ class TableViewWidget extends WidgetType { } } -export function tablePlugin(editor: Editor) { +export function tablePlugin(editor: Client) { return decoratorStateField((state: EditorState) => { const widgets: any[] = []; syntaxTree(state).iterate({ diff --git a/web/cm_plugins/wiki_link.ts b/web/cm_plugins/wiki_link.ts index 71e9b25..a0e3596 100644 --- a/web/cm_plugins/wiki_link.ts +++ b/web/cm_plugins/wiki_link.ts @@ -1,7 +1,7 @@ import { pageLinkRegex } from "../../common/markdown_parser/parser.ts"; import { ClickEvent } from "../../plug-api/app_event.ts"; import { Decoration, syntaxTree } from "../deps.ts"; -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { decoratorStateField, invisibleDecoration, @@ -12,7 +12,7 @@ import { /** * Plugin to hide path prefix when the cursor is not inside. */ -export function cleanWikiLinkPlugin(editor: Editor) { +export function cleanWikiLinkPlugin(editor: Client) { return decoratorStateField((state) => { const widgets: any[] = []; // let parentRange: [number, number]; diff --git a/web/components/panel.tsx b/web/components/panel.tsx index 4c3fc1c..b3403a2 100644 --- a/web/components/panel.tsx +++ b/web/components/panel.tsx @@ -1,5 +1,5 @@ import { useEffect, useRef } from "../deps.ts"; -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { PanelConfig } from "../types.ts"; export const panelHtml = `<!DOCTYPE html> @@ -98,7 +98,7 @@ export function Panel({ editor, }: { config: PanelConfig; - editor: Editor; + editor: Client; }) { const iFrameRef = useRef<HTMLIFrameElement>(null); useEffect(() => { diff --git a/web/editor_state.ts b/web/editor_state.ts index 660cd70..4a232c6 100644 --- a/web/editor_state.ts +++ b/web/editor_state.ts @@ -49,7 +49,7 @@ import { xmlLanguage, yamlLanguage, } from "../common/deps.ts"; -import { Editor } from "./editor.ts"; +import { Client } from "./client.ts"; import { vim } from "./deps.ts"; import { inlineImagesPlugin } from "./cm_plugins/inline_image.ts"; import { cleanModePlugins } from "./cm_plugins/clean.ts"; @@ -63,7 +63,7 @@ import { } from "./cm_plugins/editor_paste.ts"; export function createEditorState( - editor: Editor, + editor: Client, pageName: string, text: string, readOnly: boolean, diff --git a/web/editor_ui.tsx b/web/editor_ui.tsx index 46df8ba..f25ba62 100644 --- a/web/editor_ui.tsx +++ b/web/editor_ui.tsx @@ -15,7 +15,7 @@ import { useEffect, useReducer, } from "./deps.ts"; -import type { Editor } from "./editor.ts"; +import type { Client } from "./client.ts"; import { Panel } from "./components/panel.tsx"; import { h } from "./deps.ts"; @@ -23,7 +23,7 @@ export class MainUI { viewState: AppViewState = initialViewState; viewDispatch: (action: Action) => void = () => {}; - constructor(private editor: Editor) { + constructor(private editor: Client) { // Make keyboard shortcuts work even when the editor is in read only mode or not focused globalThis.addEventListener("keydown", (ev) => { if (!editor.editorView?.hasFocus) { diff --git a/web/hooks/slash_command.ts b/web/hooks/slash_command.ts index 75eb4a1..96026aa 100644 --- a/web/hooks/slash_command.ts +++ b/web/hooks/slash_command.ts @@ -2,7 +2,7 @@ import { Hook, Manifest } from "../../plugos/types.ts"; import { System } from "../../plugos/system.ts"; import { Completion, CompletionContext, CompletionResult } from "../deps.ts"; import { safeRun } from "../../common/util.ts"; -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { syntaxTree } from "../deps.ts"; export type SlashCommandDef = { @@ -24,9 +24,9 @@ const slashCommandRegexp = /([^\w:]|^)\/[\w\-]*/; export class SlashCommandHook implements Hook<SlashCommandHookT> { slashCommands = new Map<string, AppSlashCommand>(); - private editor: Editor; + private editor: Client; - constructor(editor: Editor) { + constructor(editor: Client) { this.editor = editor; } diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index 0b17152..adcef34 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -1,4 +1,4 @@ -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { EditorView, foldAll, @@ -13,7 +13,7 @@ import { import { SysCallMapping } from "../../plugos/system.ts"; import type { FilterOption } from "../types.ts"; -export function editorSyscalls(editor: Editor): SysCallMapping { +export function editorSyscalls(editor: Client): SysCallMapping { const syscalls: SysCallMapping = { "editor.getCurrentPage": (): string => { return editor.currentPage!; diff --git a/web/syscalls/space.ts b/web/syscalls/space.ts index 17e85fb..644b079 100644 --- a/web/syscalls/space.ts +++ b/web/syscalls/space.ts @@ -1,8 +1,8 @@ -import { Editor } from "../editor.ts"; +import { Client } from "../client.ts"; import { SysCallMapping } from "../../plugos/system.ts"; import { AttachmentMeta, PageMeta } from "../types.ts"; -export function spaceSyscalls(editor: Editor): SysCallMapping { +export function spaceSyscalls(editor: Client): SysCallMapping { return { "space.listPages": (): Promise<PageMeta[]> => { return editor.space.fetchPageList(); diff --git a/web/syscalls/sync.ts b/web/syscalls/sync.ts index d1e220e..c08857a 100644 --- a/web/syscalls/sync.ts +++ b/web/syscalls/sync.ts @@ -1,7 +1,7 @@ import { SysCallMapping } from "../../plugos/system.ts"; -import type { Editor } from "../editor.ts"; +import type { Client } from "../client.ts"; -export function syncSyscalls(editor: Editor): SysCallMapping { +export function syncSyscalls(editor: Client): SysCallMapping { return { "sync.isSyncing": (): Promise<boolean> => { return editor.syncService.isSyncing(); diff --git a/web/syscalls/system.ts b/web/syscalls/system.ts index 05235c9..d372f45 100644 --- a/web/syscalls/system.ts +++ b/web/syscalls/system.ts @@ -1,10 +1,10 @@ import type { Plug } from "../../plugos/plug.ts"; import { SysCallMapping, System } from "../../plugos/system.ts"; -import type { Editor } from "../editor.ts"; +import type { Client } from "../client.ts"; import { CommandDef } from "../hooks/command.ts"; export function systemSyscalls( - editor: Editor, + editor: Client, system: System<any>, ): SysCallMapping { return { diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 3339b1c..cc6b9ab 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -9,6 +9,7 @@ release. * **Bug fix**: Renaming of pages now works again on iOS * Backlinks (as queried via the `link` data source) now contains richer data, namely `inDirective` (if the link appears in the context of a directive) and `alias` (if the backlink has an alias name). This also fixes not updating page references inside directives. This introduced a backwards incompatible data. To update your indexes, please run {[Space: Reindex]} on your clients (once). * Added {[Debug: Reset Client]} command that flushes the local databases and caches (and service worker) for debugging purposes. +* Big internal code refactor ---