2023-05-23 18:53:53 +00:00
|
|
|
import type { FilterOption } from "../../web/types.ts";
|
2023-11-22 14:33:25 +00:00
|
|
|
import { UploadFile } from "../types.ts";
|
2022-10-10 12:50:21 +00:00
|
|
|
import { syscall } from "./syscall.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");
|
|
|
|
}
|
|
|
|
|
2022-06-23 15:08:42 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:06:32 +00:00
|
|
|
export function navigate(
|
|
|
|
name: string,
|
2022-08-30 08:44:20 +00:00
|
|
|
pos?: string | number,
|
2022-10-10 12:50:21 +00:00
|
|
|
replaceState = false,
|
2022-10-29 07:23:12 +00:00
|
|
|
newWindow = false,
|
2022-08-01 13:06:32 +00:00
|
|
|
): Promise<void> {
|
2022-10-29 07:23:12 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2023-07-26 09:22:10 +00:00
|
|
|
export function reloadUI(): Promise<void> {
|
|
|
|
return syscall("editor.reloadUI");
|
|
|
|
}
|
|
|
|
|
2023-06-13 18:47:05 +00:00
|
|
|
export function openUrl(url: string, existingWindow = false): Promise<void> {
|
|
|
|
return syscall("editor.openUrl", url, existingWindow);
|
2022-04-01 15:07:08 +00:00
|
|
|
}
|
|
|
|
|
2023-01-08 14:29:34 +00:00
|
|
|
// Force the client to download the file in dataUrl with filename as file name
|
|
|
|
export function downloadFile(filename: string, dataUrl: string): Promise<void> {
|
|
|
|
return syscall("editor.downloadFile", filename, dataUrl);
|
|
|
|
}
|
|
|
|
|
2023-11-25 12:40:27 +00:00
|
|
|
export function uploadFile(
|
|
|
|
accept?: string,
|
|
|
|
capture?: string,
|
|
|
|
): Promise<UploadFile> {
|
2023-11-22 14:33:25 +00:00
|
|
|
return syscall("editor.uploadFile", accept, capture);
|
|
|
|
}
|
|
|
|
|
2022-07-14 11:32:28 +00:00
|
|
|
export function flashNotification(
|
|
|
|
message: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
type: "info" | "error" = "info",
|
2022-07-14 11:32:28 +00:00
|
|
|
): Promise<void> {
|
|
|
|
return syscall("editor.flashNotification", message, type);
|
2022-04-01 15:07:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 12:46:52 +00:00
|
|
|
export function filterBox(
|
|
|
|
label: string,
|
|
|
|
options: FilterOption[],
|
2022-10-10 12:50:21 +00:00
|
|
|
helpText = "",
|
|
|
|
placeHolder = "",
|
2022-04-13 12:46:52 +00:00
|
|
|
): Promise<FilterOption | undefined> {
|
|
|
|
return syscall("editor.filterBox", label, options, helpText, placeHolder);
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:59:57 +00:00
|
|
|
export function showPanel(
|
2023-12-27 17:05:47 +00:00
|
|
|
id: "lhs" | "rhs" | "bhs" | "modal",
|
2022-09-30 14:59:57 +00:00
|
|
|
mode: number,
|
2022-05-09 12:59:12 +00:00
|
|
|
html: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
script = "",
|
2022-05-09 12:59:12 +00:00
|
|
|
): Promise<void> {
|
2022-09-30 14:59:57 +00:00
|
|
|
return syscall("editor.showPanel", id, mode, html, script);
|
2022-04-26 17:04:36 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 12:16:33 +00:00
|
|
|
export function hidePanel(
|
2023-12-27 17:05:47 +00:00
|
|
|
id: "lhs" | "rhs" | "bhs" | "modal",
|
2023-10-03 12:16:33 +00:00
|
|
|
): Promise<void> {
|
2022-09-30 14:59:57 +00:00
|
|
|
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,
|
2022-10-10 12:50:21 +00:00
|
|
|
text: string,
|
2022-04-01 15:07:08 +00:00
|
|
|
): Promise<void> {
|
|
|
|
return syscall("editor.replaceRange", from, to, text);
|
|
|
|
}
|
|
|
|
|
2022-11-01 14:01:28 +00:00
|
|
|
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,
|
2022-10-10 12:50:21 +00:00
|
|
|
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
|
|
|
|
2022-11-18 15:04:37 +00:00
|
|
|
export function confirm(
|
|
|
|
message: string,
|
|
|
|
): Promise<boolean> {
|
|
|
|
return syscall("editor.confirm", message);
|
|
|
|
}
|
2022-12-21 13:55:24 +00:00
|
|
|
export function getUiOption(key: string): Promise<any> {
|
|
|
|
return syscall("editor.getUiOption", key);
|
2022-12-16 11:44:04 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 13:55:24 +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
|
|
|
}
|
2023-01-23 17:52:17 +00:00
|
|
|
|
|
|
|
// Vim specific
|
|
|
|
export function vimEx(exCommand: string): Promise<any> {
|
|
|
|
return syscall("editor.vimEx", exCommand);
|
|
|
|
}
|
2023-06-14 17:27:18 +00:00
|
|
|
|
|
|
|
// Folding
|
|
|
|
|
|
|
|
export function fold() {
|
|
|
|
return syscall("editor.fold");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unfold() {
|
|
|
|
return syscall("editor.unfold");
|
|
|
|
}
|
|
|
|
|
2023-06-17 07:01:32 +00:00
|
|
|
export function toggleFold() {
|
|
|
|
return syscall("editor.toggleFold");
|
|
|
|
}
|
|
|
|
|
2023-06-14 17:27:18 +00:00
|
|
|
export function foldAll() {
|
|
|
|
return syscall("editor.foldAll");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unfoldAll() {
|
|
|
|
return syscall("editor.unfoldAll");
|
|
|
|
}
|