+3
-3
@@ -2,8 +2,8 @@ import { Editor } from "./editor.tsx";
|
||||
import { parseYamlSettings, safeRun } from "../common/util.ts";
|
||||
import { Space } from "../common/spaces/space.ts";
|
||||
import { HttpSpacePrimitives } from "../common/spaces/http_space_primitives.ts";
|
||||
import { PlugSpacePrimitives } from "../server/hooks/plug_space_primitives.ts";
|
||||
import { PageNamespaceHook } from "../server/hooks/page_namespace.ts";
|
||||
import { PlugSpacePrimitives } from "../common/spaces/plug_space_primitives.ts";
|
||||
import { PageNamespaceHook } from "../common/hooks/page_namespace.ts";
|
||||
import { SilverBulletHooks } from "../common/manifest.ts";
|
||||
import { System } from "../plugos/system.ts";
|
||||
import { BuiltinSettings } from "./types.ts";
|
||||
@@ -19,7 +19,7 @@ safeRun(async () => {
|
||||
let settingsPageText = "";
|
||||
try {
|
||||
settingsPageText = (
|
||||
await httpPrimitives.readFile("SETTINGS.md", "string")
|
||||
await httpPrimitives.readFile("SETTINGS.md", "utf8")
|
||||
).data as string;
|
||||
} catch (e: any) {
|
||||
console.error("No settings page found", e.message);
|
||||
|
||||
+3
-1
@@ -97,6 +97,7 @@ import type {
|
||||
} from "../plug-api/app_event.ts";
|
||||
import { CodeWidgetHook } from "./hooks/code_widget.ts";
|
||||
import { sandboxFetchSyscalls } from "../plugos/syscalls/fetch.ts";
|
||||
import { syncSyscalls } from "../common/syscalls/sync.ts";
|
||||
|
||||
const frontMatterRegex = /^---\n(.*?)---\n/ms;
|
||||
|
||||
@@ -195,6 +196,7 @@ export class Editor {
|
||||
markdownSyscalls(buildMarkdown(this.mdExtensions)),
|
||||
sandboxSyscalls(this.system),
|
||||
assetSyscalls(this.system),
|
||||
syncSyscalls(this.space.spacePrimitives),
|
||||
collabSyscalls(this),
|
||||
);
|
||||
|
||||
@@ -659,7 +661,7 @@ export class Editor {
|
||||
await this.system.unloadAll();
|
||||
console.log("(Re)loading plugs");
|
||||
await Promise.all((await this.space.listPlugs()).map(async (plugName) => {
|
||||
const { data } = await this.space.readAttachment(plugName, "string");
|
||||
const { data } = await this.space.readAttachment(plugName, "utf8");
|
||||
await this.system.load(JSON.parse(data as string), createSandbox);
|
||||
}));
|
||||
this.rebuildEditorState();
|
||||
|
||||
+13
-64
@@ -1,70 +1,19 @@
|
||||
import { Editor } from "../editor.tsx";
|
||||
import { SysCallMapping } from "../../plugos/system.ts";
|
||||
import { AttachmentMeta, PageMeta } from "../../common/types.ts";
|
||||
import {
|
||||
FileData,
|
||||
FileEncoding,
|
||||
} from "../../common/spaces/space_primitives.ts";
|
||||
|
||||
import commonSpaceSyscalls from "../../common/syscalls/space.ts";
|
||||
|
||||
export function spaceSyscalls(editor: Editor): SysCallMapping {
|
||||
return {
|
||||
"space.listPages": (): PageMeta[] => {
|
||||
return [...editor.space.listPages()];
|
||||
},
|
||||
"space.readPage": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
): Promise<string> => {
|
||||
return (await editor.space.readPage(name)).text;
|
||||
},
|
||||
"space.getPageMeta": async (_ctx, name: string): Promise<PageMeta> => {
|
||||
return await editor.space.getPageMeta(name);
|
||||
},
|
||||
"space.writePage": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
text: string,
|
||||
): Promise<PageMeta> => {
|
||||
return await editor.space.writePage(name, text);
|
||||
},
|
||||
"space.deletePage": async (_ctx, name: string) => {
|
||||
// If we're deleting the current page, navigate to the index page
|
||||
if (editor.currentPage === name) {
|
||||
await editor.navigate("");
|
||||
}
|
||||
// Remove page from open pages in editor
|
||||
editor.openPages.delete(name);
|
||||
console.log("Deleting page");
|
||||
await editor.space.deletePage(name);
|
||||
},
|
||||
"space.listPlugs": (): Promise<string[]> => {
|
||||
return editor.space.listPlugs();
|
||||
},
|
||||
"space.listAttachments": (): Promise<AttachmentMeta[]> => {
|
||||
return editor.space.fetchAttachmentList();
|
||||
},
|
||||
"space.readAttachment": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
): Promise<FileData> => {
|
||||
return (await editor.space.readAttachment(name, "dataurl")).data;
|
||||
},
|
||||
"space.getAttachmentMeta": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
): Promise<AttachmentMeta> => {
|
||||
return await editor.space.getAttachmentMeta(name);
|
||||
},
|
||||
"space.writeAttachment": async (
|
||||
_ctx,
|
||||
name: string,
|
||||
encoding: FileEncoding,
|
||||
data: FileData,
|
||||
): Promise<AttachmentMeta> => {
|
||||
return await editor.space.writeAttachment(name, encoding, data);
|
||||
},
|
||||
"space.deleteAttachment": async (_ctx, name: string) => {
|
||||
await editor.space.deleteAttachment(name);
|
||||
},
|
||||
const syscalls = commonSpaceSyscalls(editor.space);
|
||||
syscalls["space.deletePage"] = async (_ctx, name: string) => {
|
||||
// If we're deleting the current page, navigate to the index page
|
||||
if (editor.currentPage === name) {
|
||||
await editor.navigate("");
|
||||
}
|
||||
// Remove page from open pages in editor
|
||||
editor.openPages.delete(name);
|
||||
console.log("Deleting page");
|
||||
await editor.space.deletePage(name);
|
||||
};
|
||||
return syscalls;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ export type PanelMode = number;
|
||||
|
||||
export type BuiltinSettings = {
|
||||
indexPage: string;
|
||||
syncUrl?: string;
|
||||
};
|
||||
|
||||
export type PanelConfig = {
|
||||
|
||||
Reference in New Issue
Block a user