Templates 2.0 (#636)

Templates 2.0 and a whole bunch of other refactoring
This commit is contained in:
Zef Hemel
2024-01-20 19:16:07 +01:00
committed by GitHub
parent 0a6a0016a2
commit f30b1d3418
171 changed files with 2038 additions and 1628 deletions
+6
View File
@@ -11,6 +11,12 @@ export const builtinFunctions: FunctionMap = {
min(...args: number[]) {
return Math.min(...args);
},
replace(str: string, match: [string, string] | string, replace: string) {
const matcher = Array.isArray(match)
? new RegExp(match[0], match[1] + "g")
: match;
return str.replaceAll(matcher, replace);
},
toJSON(obj: any) {
return JSON.stringify(obj);
},
+4 -1
View File
@@ -191,7 +191,10 @@ export function nodeAtPos(tree: ParseTree, pos: number): ParseTree | null {
}
// Turn ParseTree back into text
export function renderToText(tree: ParseTree): string {
export function renderToText(tree?: ParseTree): string {
if (!tree) {
return "";
}
const pieces: string[] = [];
if (tree.text !== undefined) {
return tree.text;
+14
View File
@@ -39,6 +39,16 @@ export function navigate(
return syscall("editor.navigate", name, pos, replaceState, newWindow);
}
export function openPageNavigator(
mode: "page" | "template" = "page",
): Promise<void> {
return syscall("editor.openPageNavigator", mode);
}
export function openCommandPalette(): Promise<void> {
return syscall("editor.openCommandPalette");
}
export function reloadPage(): Promise<void> {
return syscall("editor.reloadPage");
}
@@ -47,6 +57,10 @@ export function reloadUI(): Promise<void> {
return syscall("editor.reloadUI");
}
export function reloadSettingsAndCommands(): Promise<void> {
return syscall("editor.reloadSettingsAndCommands");
}
export function openUrl(url: string, existingWindow = false): Promise<void> {
return syscall("editor.openUrl", url, existingWindow);
}