1
0
silverbullet/web/types.ts

171 lines
3.9 KiB
TypeScript
Raw Normal View History

2023-08-20 17:54:31 +00:00
import { Manifest } from "../common/manifest.ts";
import { AppCommand } from "./hooks/command.ts";
export type PageMeta = {
name: string;
lastModified: number;
lastOpened?: number;
perm: "ro" | "rw";
} & Record<string, any>;
export type AttachmentMeta = {
name: string;
contentType: string;
lastModified: number;
size: number;
perm: "ro" | "rw";
};
// Used by FilterBox
export type FilterOption = {
name: string;
orderId?: number;
hint?: string;
} & Record<string, any>;
export type Notification = {
id: number;
message: string;
type: "info" | "error";
date: Date;
};
export type PanelMode = number;
2022-12-15 12:23:49 +00:00
export type BuiltinSettings = {
indexPage: string;
2023-08-20 17:54:31 +00:00
customStyles?: string;
plugOverrides?: Record<string, Partial<Manifest>>;
2023-05-29 07:53:49 +00:00
// Format: compatible with docker ignore
spaceIgnore?: string;
2022-12-15 12:23:49 +00:00
};
export type PanelConfig = {
mode?: PanelMode;
html?: string;
script?: string;
};
export type AppViewState = {
currentPage?: string;
2023-01-16 10:28:59 +00:00
currentPageMeta?: PageMeta;
isLoading: boolean;
showPageNavigator: boolean;
showCommandPalette: boolean;
showCommandPaletteContext?: string;
unsavedChanges: boolean;
2023-08-16 09:40:31 +00:00
syncFailures: number; // Reset everytime a sync succeeds
2023-06-14 18:58:08 +00:00
progressPerc?: number;
panels: { [key: string]: PanelConfig };
allPages: PageMeta[];
commands: Map<string, AppCommand>;
notifications: Notification[];
2022-05-16 13:09:36 +00:00
recentCommands: Map<string, Date>;
uiOptions: {
vimMode: boolean;
darkMode: boolean;
forcedROMode: boolean;
};
2022-12-21 15:08:51 +00:00
// Filter box
showFilterBox: boolean;
filterBoxLabel: string;
filterBoxPlaceHolder: string;
filterBoxOptions: FilterOption[];
filterBoxHelpText: string;
filterBoxOnSelect: (option: FilterOption | undefined) => void;
2022-12-21 15:08:51 +00: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,
unsavedChanges: false,
2023-08-16 09:40:31 +00:00
syncFailures: 0,
uiOptions: {
vimMode: false,
darkMode: false,
forcedROMode: false,
},
panels: {
lhs: {},
rhs: {},
bhs: {},
modal: {},
},
allPages: [],
commands: new Map(),
2022-05-16 13:09:36 +00:00
recentCommands: new Map(),
notifications: [],
showFilterBox: false,
filterBoxHelpText: "",
filterBoxLabel: "",
filterBoxOnSelect: () => {},
filterBoxOptions: [],
filterBoxPlaceHolder: "",
2022-12-21 15:08:51 +00:00
showPrompt: false,
showConfirm: false,
};
export type Action =
2022-05-17 09:53:17 +00:00
| { type: "page-loaded"; meta: PageMeta }
| { type: "page-loading"; name: string }
| { type: "pages-listed"; pages: PageMeta[] }
| { type: "page-changed" }
| { type: "page-saved" }
2023-08-16 09:40:31 +00:00
| { type: "sync-change"; syncSuccess: boolean }
| { type: "start-navigate" }
| { type: "stop-navigate" }
2022-05-06 16:55:04 +00:00
| {
type: "update-commands";
commands: Map<string, AppCommand>;
}
| { 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 }
| {
type: "show-panel";
id: "rhs" | "lhs" | "bhs" | "modal";
config: PanelConfig;
}
| { type: "hide-panel"; id: string }
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;
}
2022-09-16 12:26:47 +00:00
| { type: "hide-filterbox" }
2022-12-21 15:08:51 +00: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-14 18:58:08 +00:00
| { type: "set-ui-option"; key: string; value: any }
| { type: "set-progress"; progressPerc?: number };