1
0
silverbullet/plug-api/silverbullet-syscall/editor.ts

126 lines
3.1 KiB
TypeScript
Raw Normal View History

import { syscall } from "./syscall.ts";
import { FilterOption } from "../../common/types.ts";
2022-04-01 15:07:08 +00:00
export function getCurrentPage(): Promise<string> {
return syscall("editor.getCurrentPage");
}
2022-04-24 16:06:34 +00:00
export function setPage(newName: string): Promise<void> {
return syscall("editor.setPage", newName);
}
2022-04-01 15:07:08 +00:00
export function getText(): Promise<string> {
return syscall("editor.getText");
}
export function getCursor(): Promise<number> {
return syscall("editor.getCursor");
}
export function getSelection(): Promise<{ from: number; to: number }> {
return syscall("editor.getSelection");
}
export function setSelection(from: number, to: number): Promise<void> {
return syscall("editor.setSelection", from, to);
}
2022-04-01 15:07:08 +00:00
export function save(): Promise<void> {
return syscall("editor.save");
}
export function navigate(
name: string,
2022-08-30 08:44:20 +00:00
pos?: string | number,
replaceState = false,
newWindow = false,
): Promise<void> {
return syscall("editor.navigate", name, pos, replaceState, newWindow);
2022-04-01 15:07:08 +00:00
}
export function reloadPage(): Promise<void> {
return syscall("editor.reloadPage");
}
export function openUrl(url: string): Promise<void> {
return syscall("editor.openUrl", url);
}
export function flashNotification(
message: string,
type: "info" | "error" = "info",
): Promise<void> {
return syscall("editor.flashNotification", message, type);
2022-04-01 15:07:08 +00:00
}
export function filterBox(
label: string,
options: FilterOption[],
helpText = "",
placeHolder = "",
): Promise<FilterOption | undefined> {
return syscall("editor.filterBox", label, options, helpText, placeHolder);
}
export function showPanel(
id: "lhs" | "rhs" | "bhs" | "modal",
mode: number,
2022-05-09 12:59:12 +00:00
html: string,
script = "",
2022-05-09 12:59:12 +00:00
): Promise<void> {
return syscall("editor.showPanel", id, mode, html, script);
2022-04-26 17:04:36 +00:00
}
export function hidePanel(id: "lhs" | "rhs" | "bhs" | "modal"): Promise<void> {
return syscall("editor.hidePanel", id);
2022-04-26 17:04:36 +00:00
}
2022-04-01 15:07:08 +00:00
export function insertAtPos(text: string, pos: number): Promise<void> {
return syscall("editor.insertAtPos", text, pos);
}
export function replaceRange(
from: number,
to: number,
text: string,
2022-04-01 15:07:08 +00:00
): Promise<void> {
return syscall("editor.replaceRange", from, to, text);
}
export function moveCursor(pos: number, center = false): Promise<void> {
return syscall("editor.moveCursor", pos, center);
2022-04-01 15:07:08 +00:00
}
export function insertAtCursor(text: string): Promise<void> {
return syscall("editor.insertAtCursor", text);
}
export function dispatch(change: any): Promise<void> {
return syscall("editor.dispatch", change);
}
export function prompt(
message: string,
defaultValue = "",
2022-04-01 15:07:08 +00:00
): Promise<string | undefined> {
return syscall("editor.prompt", message, defaultValue);
}
2022-09-16 12:26:47 +00:00
export function confirm(
message: string,
): Promise<boolean> {
return syscall("editor.confirm", message);
}
2022-09-16 12:26:47 +00:00
export function enableReadOnlyMode(enabled: boolean) {
return syscall("editor.enableReadOnlyMode", enabled);
}
2022-12-16 11:44:04 +00:00
export function getUiOption(key: string): Promise<any> {
return syscall("editor.getUiOption", key);
2022-12-16 11:44:04 +00:00
}
export function setUiOption(key: string, value: any): Promise<void> {
return syscall("editor.setUiOption", key, value);
2022-12-16 11:44:04 +00:00
}