1
0
silverbullet/web/types.ts

116 lines
2.7 KiB
TypeScript
Raw Normal View History

import { AppCommand } from "./hooks/command.ts";
import { FilterOption, PageMeta } from "../common/types.ts";
export type Notification = {
id: number;
message: string;
type: "info" | "error";
date: Date;
};
2022-09-16 12:26:47 +00:00
type EditorMode = "ro" | "rw";
export type PanelMode = number;
2022-12-15 12:23:49 +00:00
export type BuiltinSettings = {
indexPage: string;
};
export type PanelConfig = {
mode?: PanelMode;
html?: string;
script?: string;
};
export type AppViewState = {
currentPage?: string;
editingPageName: boolean;
2022-09-16 12:26:47 +00:00
perm: EditorMode;
isLoading: boolean;
showPageNavigator: boolean;
showCommandPalette: boolean;
unsavedChanges: boolean;
panels: { [key: string]: PanelConfig };
allPages: Set<PageMeta>;
commands: Map<string, AppCommand>;
notifications: Notification[];
2022-05-16 13:09:36 +00:00
recentCommands: Map<string, Date>;
uiOptions: {
vimMode: boolean;
darkMode: boolean;
forcedROMode: boolean;
};
showFilterBox: boolean;
filterBoxLabel: string;
filterBoxPlaceHolder: string;
filterBoxOptions: FilterOption[];
filterBoxHelpText: string;
filterBoxOnSelect: (option: FilterOption | undefined) => void;
};
export const initialViewState: AppViewState = {
2022-05-17 09:53:17 +00:00
perm: "rw",
editingPageName: false,
isLoading: false,
showPageNavigator: false,
showCommandPalette: false,
unsavedChanges: false,
uiOptions: {
vimMode: false,
darkMode: false,
forcedROMode: false,
},
panels: {
lhs: {},
rhs: {},
bhs: {},
modal: {},
},
allPages: new Set(),
commands: new Map(),
2022-05-16 13:09:36 +00:00
recentCommands: new Map(),
notifications: [],
showFilterBox: false,
filterBoxHelpText: "",
filterBoxLabel: "",
filterBoxOnSelect: () => {},
filterBoxOptions: [],
filterBoxPlaceHolder: "",
};
export type Action =
2022-05-17 09:53:17 +00:00
| { type: "page-loaded"; meta: PageMeta }
| { type: "page-loading"; name: string }
| { type: "pages-listed"; pages: Set<PageMeta> }
| { type: "page-changed" }
| { type: "page-saved" }
| { type: "start-navigate" }
| { type: "stop-navigate" }
2022-05-06 16:55:04 +00:00
| {
type: "update-commands";
commands: Map<string, AppCommand>;
}
| { type: "show-palette"; context?: string }
| { type: "hide-palette" }
| { type: "show-notification"; notification: Notification }
2022-03-28 13:25:05 +00:00
| { type: "dismiss-notification"; id: number }
| {
type: "show-panel";
id: "rhs" | "lhs" | "bhs" | "modal";
config: PanelConfig;
}
| { type: "hide-panel"; id: string }
2022-05-16 13:09:36 +00:00
| { type: "command-run"; command: string }
| {
type: "show-filterbox";
options: FilterOption[];
placeHolder: string;
helpText: string;
label: string;
onSelect: (option: FilterOption | undefined) => void;
}
2022-09-16 12:26:47 +00:00
| { type: "hide-filterbox" }
| { type: "set-ui-option"; key: string; value: any };