2022-05-16 13:09:36 +00:00
|
|
|
import { AppCommand, CommandDef } from "./hooks/command";
|
2022-04-21 11:57:45 +00:00
|
|
|
import { FilterOption, PageMeta } from "@silverbulletmd/common/types";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
|
|
|
export const slashCommandRegexp = /\/[\w\-]*/;
|
|
|
|
|
|
|
|
export type Notification = {
|
|
|
|
id: number;
|
|
|
|
message: string;
|
|
|
|
date: Date;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type AppViewState = {
|
|
|
|
currentPage?: string;
|
2022-05-17 09:53:17 +00:00
|
|
|
perm: "ro" | "rw";
|
|
|
|
|
2022-03-20 08:56:28 +00:00
|
|
|
showPageNavigator: boolean;
|
|
|
|
showCommandPalette: boolean;
|
2022-03-31 12:28:07 +00:00
|
|
|
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;
|
2022-03-20 08:56:28 +00:00
|
|
|
allPages: Set<PageMeta>;
|
|
|
|
commands: Map<string, AppCommand>;
|
|
|
|
notifications: Notification[];
|
2022-05-16 13:09:36 +00:00
|
|
|
recentCommands: Map<string, Date>;
|
2022-04-13 12:46:52 +00:00
|
|
|
|
|
|
|
showFilterBox: boolean;
|
2022-04-21 09:46:33 +00:00
|
|
|
filterBoxLabel: string;
|
2022-04-13 12:46:52 +00:00
|
|
|
filterBoxPlaceHolder: string;
|
|
|
|
filterBoxOptions: FilterOption[];
|
|
|
|
filterBoxHelpText: string;
|
|
|
|
filterBoxOnSelect: (option: FilterOption | undefined) => void;
|
2022-03-20 08:56:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const initialViewState: AppViewState = {
|
2022-05-17 09:53:17 +00:00
|
|
|
perm: "rw",
|
2022-03-20 08:56:28 +00:00
|
|
|
showPageNavigator: false,
|
|
|
|
showCommandPalette: false,
|
2022-03-31 12:28:07 +00:00
|
|
|
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: "",
|
2022-03-20 08:56:28 +00:00
|
|
|
allPages: new Set(),
|
|
|
|
commands: new Map(),
|
2022-05-16 13:09:36 +00:00
|
|
|
recentCommands: new Map(),
|
2022-03-20 08:56:28 +00:00
|
|
|
notifications: [],
|
2022-04-13 12:46:52 +00:00
|
|
|
showFilterBox: false,
|
|
|
|
filterBoxHelpText: "",
|
2022-04-21 09:46:33 +00:00
|
|
|
filterBoxLabel: "",
|
2022-04-13 12:46:52 +00:00
|
|
|
filterBoxOnSelect: () => {},
|
|
|
|
filterBoxOptions: [],
|
|
|
|
filterBoxPlaceHolder: "",
|
2022-03-20 08:56:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Action =
|
2022-05-17 09:53:17 +00:00
|
|
|
| { type: "page-loaded"; meta: PageMeta }
|
2022-03-20 08:56:28 +00:00
|
|
|
| { type: "pages-listed"; pages: Set<PageMeta> }
|
2022-03-31 12:28:07 +00:00
|
|
|
| { type: "page-changed" }
|
|
|
|
| { type: "page-saved" }
|
2022-03-20 08:56:28 +00:00
|
|
|
| { type: "start-navigate" }
|
|
|
|
| { type: "stop-navigate" }
|
2022-05-06 16:55:04 +00:00
|
|
|
| {
|
|
|
|
type: "update-commands";
|
|
|
|
commands: Map<string, AppCommand>;
|
|
|
|
}
|
2022-04-21 09:46:33 +00:00
|
|
|
| { type: "show-palette"; context?: string }
|
2022-03-20 08:56:28 +00:00
|
|
|
| { 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 }
|
2022-04-13 12:46:52 +00:00
|
|
|
| { 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 }
|
2022-04-13 12:46:52 +00:00
|
|
|
| {
|
|
|
|
type: "show-filterbox";
|
|
|
|
options: FilterOption[];
|
|
|
|
placeHolder: string;
|
|
|
|
helpText: string;
|
2022-04-21 09:46:33 +00:00
|
|
|
label: string;
|
2022-04-13 12:46:52 +00:00
|
|
|
onSelect: (option: FilterOption | undefined) => void;
|
|
|
|
}
|
|
|
|
| { type: "hide-filterbox" };
|