1
0
silverbullet/packages/web/types.ts

102 lines
2.7 KiB
TypeScript
Raw Normal View History

2022-05-16 13:09:36 +00:00
import { AppCommand, CommandDef } from "./hooks/command";
import { FilterOption, PageMeta } from "@silverbulletmd/common/types";
export const slashCommandRegexp = /\/[\w\-]*/;
export type Notification = {
id: number;
message: string;
date: Date;
};
2022-05-06 16:55:04 +00:00
export type ActionButton = {
label: string;
tooltip?: string;
orderId?: number;
run: () => void;
};
export type AppViewState = {
currentPage?: string;
showPageNavigator: boolean;
showCommandPalette: boolean;
unsavedChanges: boolean;
2022-04-04 16:33:13 +00:00
showLHS: number; // 0 = hide, > 0 = flex
showRHS: number; // 0 = hide, > 0 = flex
2022-04-26 17:04:36 +00:00
showBHS: number;
2022-03-28 13:25:05 +00:00
rhsHTML: string;
2022-04-04 16:33:13 +00:00
lhsHTML: string;
2022-04-26 17:04:36 +00:00
bhsHTML: string;
2022-05-09 12:59:12 +00:00
rhsScript?: string;
lhsScript?: string;
bhsScript?: string;
allPages: Set<PageMeta>;
commands: Map<string, AppCommand>;
notifications: Notification[];
2022-05-06 16:55:04 +00:00
actionButtons: ActionButton[];
2022-05-16 13:09:36 +00:00
recentCommands: Map<string, Date>;
showFilterBox: boolean;
filterBoxLabel: string;
filterBoxPlaceHolder: string;
filterBoxOptions: FilterOption[];
filterBoxHelpText: string;
filterBoxOnSelect: (option: FilterOption | undefined) => void;
};
export const initialViewState: AppViewState = {
showPageNavigator: false,
showCommandPalette: false,
unsavedChanges: false,
2022-04-04 16:33:13 +00:00
showLHS: 0,
showRHS: 0,
2022-04-26 17:04:36 +00:00
showBHS: 0,
2022-04-04 16:33:13 +00:00
rhsHTML: "",
lhsHTML: "",
2022-04-26 17:04:36 +00:00
bhsHTML: "",
allPages: new Set(),
commands: new Map(),
2022-05-16 13:09:36 +00:00
recentCommands: new Map(),
notifications: [],
2022-05-06 16:55:04 +00:00
actionButtons: [],
showFilterBox: false,
filterBoxHelpText: "",
filterBoxLabel: "",
filterBoxOnSelect: () => {},
filterBoxOptions: [],
filterBoxPlaceHolder: "",
};
export type Action =
| { type: "page-loaded"; 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>;
actionButtons: ActionButton[];
}
| { 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 }
2022-05-09 12:59:12 +00:00
| { type: "show-rhs"; html: string; flex: number; script?: string }
2022-04-04 16:33:13 +00:00
| { type: "hide-rhs" }
2022-05-09 12:59:12 +00:00
| { type: "show-lhs"; html: string; flex: number; script?: string }
| { type: "hide-lhs" }
2022-05-09 12:59:12 +00:00
| { type: "show-bhs"; html: string; flex: number; script?: string }
2022-04-26 17:04:36 +00:00
| { type: "hide-bhs" }
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;
}
| { type: "hide-filterbox" };