No More Collab. Fixes #449

* Fully removes real-time collaboration
* URL scheme rewrite
This commit is contained in:
Zef Hemel
2023-07-06 16:47:50 +02:00
committed by GitHub
parent 021bf7e9a4
commit fb75ea1a65
45 changed files with 380 additions and 1356 deletions
+4
View File
@@ -0,0 +1,4 @@
export function isValidPageName(name: string): boolean {
// Page can not be empty and not end with a file extension (e.g. "bla.md")
return name !== "" && !/\.[a-zA-Z]+$/.test(name);
}
+3 -4
View File
@@ -1,8 +1,7 @@
import { readYamlPage } from "./yaml_page.ts";
import { notifyUser } from "./util.ts";
import { readYamlPage } from "$sb/lib/yaml_page.ts";
import { YAML } from "$sb/plugos-syscall/mod.ts";
import { space } from "$sb/silverbullet-syscall/mod.ts";
import { editor, space } from "$sb/silverbullet-syscall/mod.ts";
/**
* Convenience function to read a specific set of settings from the `SETTINGS` page as well as default values
@@ -65,7 +64,7 @@ export async function writeSettings<T extends object>(settings: T) {
try {
readSettings = (await readYamlPage(SETTINGS_PAGE, ["yaml"])) || {};
} catch {
await notifyUser("Creating a new SETTINGS page...", "info");
await editor.flashNotification("Creating a new SETTINGS page...", "info");
}
const writeSettings: any = { ...readSettings, ...settings };
// const doc = new YAML.Document();
-36
View File
@@ -1,36 +0,0 @@
import { editor } from "$sb/silverbullet-syscall/mod.ts";
export async function replaceAsync(
str: string,
regex: RegExp,
asyncFn: (match: string, ...args: any[]) => Promise<string>,
) {
const promises: Promise<string>[] = [];
str.replace(regex, (match: string, ...args: any[]): string => {
const promise = asyncFn(match, ...args);
promises.push(promise);
return "";
});
const data = await Promise.all(promises);
return str.replace(regex, () => data.shift()!);
}
export function isServer() {
return (
typeof window === "undefined" || typeof window.document === "undefined"
); // if something defines window the same way as the browser, this will fail.
}
// this helps keep if's condition as positive
export function isBrowser() {
return !isServer();
}
export function notifyUser(message: string, type?: "info" | "error") {
if (isBrowser()) {
return editor.flashNotification(message, type);
}
const log = type === "error" ? console.error : console.log;
log(message); // we should end up sending the message to the user, users dont read logs.
return;
}
-9
View File
@@ -1,9 +0,0 @@
import { syscall } from "./syscall.ts";
export function start(serverUrl: string, token: string, username: string) {
return syscall("collab.start", serverUrl, token, username);
}
export function stop() {
return syscall("collab.stop");
}
-1
View File
@@ -3,7 +3,6 @@ export * as index from "./index.ts";
export * as markdown from "./markdown.ts";
export * as space from "./space.ts";
export * as system from "./system.ts";
export * as collab from "./collab.ts";
// Legacy redirect, use "store" in $sb/plugos-syscall/mod.ts instead
export * as clientStore from "./store.ts";
export * as sync from "./sync.ts";