silverbullet/web/type.ts

148 lines
3.7 KiB
TypeScript
Raw Normal View History

2024-07-30 23:33:33 +08:00
import type { AppCommand } from "../lib/command.ts";
import { defaultConfig } from "../common/config.ts";
import type { FilterOption, Notification, PanelMode } from "../type/client.ts";
import type { Config } from "../type/config.ts";
import type { PageMeta } from "@silverbulletmd/silverbullet/types";
2022-12-15 20:23:49 +08:00
export type PanelConfig = {
mode?: PanelMode;
html?: string;
script?: string;
};
export type AppViewState = {
currentPage?: string;
2023-01-16 18:28:59 +08:00
currentPageMeta?: PageMeta;
2024-01-25 18:42:36 +08:00
allPages: PageMeta[];
isLoading: boolean;
isMobile: boolean;
showPageNavigator: boolean;
showCommandPalette: boolean;
showCommandPaletteContext?: string;
unsavedChanges: boolean;
2023-08-16 17:40:31 +08:00
syncFailures: number; // Reset everytime a sync succeeds
2023-06-15 02:58:08 +08:00
progressPerc?: number;
panels: { [key: string]: PanelConfig };
commands: Map<string, AppCommand>;
notifications: Notification[];
2022-05-16 21:09:36 +08:00
recentCommands: Map<string, Date>;
config: Config;
2024-01-25 18:42:36 +08:00
uiOptions: {
vimMode: boolean;
darkMode: boolean;
forcedROMode: boolean;
customStyles?: string;
};
// Page navigator mode
pageNavigatorMode: "page" | "meta" | "all";
2022-12-21 23:08:51 +08:00
// Filter box
showFilterBox: boolean;
filterBoxLabel: string;
filterBoxPlaceHolder: string;
filterBoxOptions: FilterOption[];
filterBoxHelpText: string;
filterBoxOnSelect: (option: FilterOption | undefined) => void;
2022-12-21 23:08:51 +08:00
// Prompt
showPrompt: boolean;
promptMessage?: string;
promptDefaultValue?: string;
promptCallback?: (value: string | undefined) => void;
// Confirm
showConfirm: boolean;
confirmMessage?: string;
confirmCallback?: (value: boolean) => void;
};
export const initialViewState: AppViewState = {
isLoading: false,
showPageNavigator: false,
showCommandPalette: false,
pageNavigatorMode: "page",
unsavedChanges: false,
2023-08-16 17:40:31 +08:00
syncFailures: 0,
uiOptions: {
vimMode: false,
darkMode: false,
forcedROMode: false,
},
isMobile: false,
panels: {
lhs: {},
rhs: {},
bhs: {},
modal: {},
},
config: defaultConfig,
allPages: [],
commands: new Map(),
2022-05-16 21:09:36 +08:00
recentCommands: new Map(),
notifications: [],
showFilterBox: false,
filterBoxHelpText: "",
filterBoxLabel: "",
filterBoxOnSelect: () => {},
filterBoxOptions: [],
filterBoxPlaceHolder: "",
2022-12-21 23:08:51 +08:00
showPrompt: false,
showConfirm: false,
};
export type Action =
2022-05-17 17:53:17 +08:00
| { type: "page-loaded"; meta: PageMeta }
| { type: "page-loading"; name: string }
| { type: "page-changed" }
| { type: "page-saved" }
2023-08-16 17:40:31 +08:00
| { type: "sync-change"; syncSuccess: boolean }
2024-07-13 20:55:35 +08:00
| { type: "update-current-page-meta"; meta: PageMeta }
2023-12-22 22:55:50 +08:00
| { type: "update-page-list"; allPages: PageMeta[] }
| { type: "config-loaded"; config: Config }
| { type: "start-navigate"; mode: "page" | "meta" | "all" }
| { type: "stop-navigate" }
2022-05-07 00:55:04 +08:00
| {
type: "update-commands";
commands: Map<string, AppCommand>;
}
| { type: "show-palette"; context?: string }
| { type: "hide-palette" }
| { type: "show-notification"; notification: Notification }
2022-03-28 21:25:05 +08:00
| { type: "dismiss-notification"; id: number }
| {
type: "show-panel";
id: "rhs" | "lhs" | "bhs" | "modal";
config: PanelConfig;
}
| { type: "hide-panel"; id: string }
2022-05-16 21:09:36 +08: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 20:26:47 +08:00
| { type: "hide-filterbox" }
2022-12-21 23:08:51 +08:00
| {
type: "show-prompt";
message: string;
defaultValue: string;
callback: (value: string | undefined) => void;
}
| { type: "hide-prompt" }
| {
type: "show-confirm";
message: string;
callback: (value: boolean) => void;
}
| { type: "hide-confirm" }
2023-06-15 02:58:08 +08:00
| { type: "set-ui-option"; key: string; value: any }
| { type: "set-progress"; progressPerc?: number };