2022-03-29 09:21:32 +00:00
|
|
|
import { AppCommand } from "./hooks/command";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
|
|
|
export type PageMeta = {
|
|
|
|
name: string;
|
|
|
|
lastModified: number;
|
|
|
|
version?: number;
|
|
|
|
lastOpened?: number;
|
2022-03-31 12:28:07 +00:00
|
|
|
created?: boolean;
|
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;
|
|
|
|
showPageNavigator: boolean;
|
|
|
|
showCommandPalette: boolean;
|
2022-03-31 12:28:07 +00:00
|
|
|
unsavedChanges: boolean;
|
2022-03-28 13:25:05 +00:00
|
|
|
showRHS: boolean;
|
|
|
|
rhsHTML: string;
|
2022-03-20 08:56:28 +00:00
|
|
|
allPages: Set<PageMeta>;
|
|
|
|
commands: Map<string, AppCommand>;
|
|
|
|
notifications: Notification[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const initialViewState: AppViewState = {
|
|
|
|
showPageNavigator: false,
|
|
|
|
showCommandPalette: false,
|
2022-03-31 12:28:07 +00:00
|
|
|
unsavedChanges: false,
|
2022-03-28 13:25:05 +00:00
|
|
|
showRHS: false,
|
|
|
|
rhsHTML: "<h1>Loading...</h1>",
|
2022-03-20 08:56:28 +00:00
|
|
|
allPages: new Set(),
|
|
|
|
commands: new Map(),
|
|
|
|
notifications: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Action =
|
|
|
|
| { type: "page-loaded"; name: string }
|
|
|
|
| { 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" }
|
|
|
|
| { type: "update-commands"; commands: Map<string, AppCommand> }
|
|
|
|
| { type: "show-palette" }
|
|
|
|
| { type: "hide-palette" }
|
|
|
|
| { type: "show-notification"; notification: Notification }
|
2022-03-28 13:25:05 +00:00
|
|
|
| { type: "dismiss-notification"; id: number }
|
|
|
|
| { type: "show-rhs"; html: string }
|
|
|
|
| { type: "hide-rhs" };
|