1
0

Editor refact: rename Editor to Client

This commit is contained in:
Zef Hemel 2023-07-14 16:56:20 +02:00
parent f3936f9b2f
commit 16842a1c4b
20 changed files with 47 additions and 49 deletions

View File

@ -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) {

View File

@ -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";
}

View File

@ -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,

View File

@ -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[] = [];

View File

@ -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(),

View File

@ -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];

View File

@ -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) => {

View File

@ -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({

View File

@ -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<Decoration>[] = [];
const imageRegex = /!\[(?<title>[^\]]*)\]\((?<url>.+)\)/;

View File

@ -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({

View File

@ -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];

View File

@ -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(() => {

View File

@ -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,

View File

@ -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) {

View File

@ -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;
}

View File

@ -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!;

View File

@ -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();

View File

@ -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();

View File

@ -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 {

View File

@ -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
---