2022-10-10 12:50:21 +00:00
|
|
|
import { AppCommand } from "./hooks/command.ts";
|
|
|
|
import { FilterOption, PageMeta } from "../common/types.ts";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
|
|
|
export type Notification = {
|
|
|
|
id: number;
|
|
|
|
message: string;
|
2022-07-14 11:32:28 +00:00
|
|
|
type: "info" | "error";
|
2022-03-20 08:56:28 +00:00
|
|
|
date: Date;
|
|
|
|
};
|
|
|
|
|
2022-09-16 12:26:47 +00:00
|
|
|
type EditorMode = "ro" | "rw";
|
|
|
|
|
2022-09-30 14:59:57 +00:00
|
|
|
export type PanelMode = number;
|
|
|
|
|
2022-12-15 12:23:49 +00:00
|
|
|
export type BuiltinSettings = {
|
|
|
|
indexPage: string;
|
|
|
|
vimMode?: boolean;
|
|
|
|
};
|
|
|
|
|
2022-09-30 14:59:57 +00:00
|
|
|
export type PanelConfig = {
|
|
|
|
mode?: PanelMode;
|
|
|
|
html?: string;
|
|
|
|
script?: string;
|
|
|
|
};
|
|
|
|
|
2022-03-20 08:56:28 +00:00
|
|
|
export type AppViewState = {
|
|
|
|
currentPage?: string;
|
2022-11-18 15:04:37 +00:00
|
|
|
editingPageName: boolean;
|
2022-09-16 12:26:47 +00:00
|
|
|
perm: EditorMode;
|
|
|
|
forcedROMode: boolean;
|
2022-09-06 14:21:33 +00:00
|
|
|
isLoading: boolean;
|
2022-03-20 08:56:28 +00:00
|
|
|
showPageNavigator: boolean;
|
|
|
|
showCommandPalette: boolean;
|
2022-03-31 12:28:07 +00:00
|
|
|
unsavedChanges: boolean;
|
2022-09-30 14:59:57 +00:00
|
|
|
panels: { [key: string]: PanelConfig };
|
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-11-18 15:04:37 +00:00
|
|
|
editingPageName: false,
|
2022-09-16 12:26:47 +00:00
|
|
|
forcedROMode: false,
|
2022-09-06 14:21:33 +00:00
|
|
|
isLoading: false,
|
2022-03-20 08:56:28 +00:00
|
|
|
showPageNavigator: false,
|
|
|
|
showCommandPalette: false,
|
2022-03-31 12:28:07 +00:00
|
|
|
unsavedChanges: false,
|
2022-09-30 14:59:57 +00:00
|
|
|
panels: {
|
|
|
|
lhs: {},
|
|
|
|
rhs: {},
|
|
|
|
bhs: {},
|
|
|
|
modal: {},
|
|
|
|
},
|
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-09-06 14:21:33 +00:00
|
|
|
| { type: "page-loading"; name: string }
|
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
|
|
|
| {
|
2022-10-10 12:50:21 +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-09-30 14:59:57 +00:00
|
|
|
| {
|
2022-10-10 12:50:21 +00:00
|
|
|
type: "show-panel";
|
|
|
|
id: "rhs" | "lhs" | "bhs" | "modal";
|
|
|
|
config: PanelConfig;
|
|
|
|
}
|
2022-09-30 14:59:57 +00:00
|
|
|
| { type: "hide-panel"; id: string }
|
2022-05-16 13:09:36 +00:00
|
|
|
| { type: "command-run"; command: string }
|
2022-04-13 12:46:52 +00:00
|
|
|
| {
|
2022-10-10 12:50:21 +00:00
|
|
|
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-editor-ro"; enabled: boolean };
|