mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
fix(client/ts): fix build errors & define command to event bridge
This commit is contained in:
parent
cf2535cb92
commit
0221039ebe
@ -92,7 +92,7 @@ export type CommandMappings = {
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
};
|
};
|
||||||
focusAndSelectTitle: CommandData & {
|
focusAndSelectTitle: CommandData & {
|
||||||
isNewNote: boolean;
|
isNewNote?: boolean;
|
||||||
};
|
};
|
||||||
showPromptDialog: PromptDialogOptions;
|
showPromptDialog: PromptDialogOptions;
|
||||||
showInfoDialog: ConfirmWithMessageOptions;
|
showInfoDialog: ConfirmWithMessageOptions;
|
||||||
@ -277,15 +277,16 @@ export type CommandListener<T extends CommandNames> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type CommandListenerData<T extends CommandNames> = CommandMappings[T];
|
export type CommandListenerData<T extends CommandNames> = CommandMappings[T];
|
||||||
export type EventData<T extends EventNames> = EventMappings[T];
|
|
||||||
|
|
||||||
type CommandAndEventMappings = CommandMappings & EventMappings;
|
type CommandAndEventMappings = CommandMappings & EventMappings;
|
||||||
|
type EventOnlyNames = keyof EventMappings;
|
||||||
|
export type EventNames = CommandNames | EventOnlyNames;
|
||||||
|
export type EventData<T extends EventNames> = CommandAndEventMappings[T];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This type is a discriminated union which contains all the possible commands that can be triggered via {@link AppContext.triggerCommand}.
|
* This type is a discriminated union which contains all the possible commands that can be triggered via {@link AppContext.triggerCommand}.
|
||||||
*/
|
*/
|
||||||
export type CommandNames = keyof CommandMappings;
|
export type CommandNames = keyof CommandMappings;
|
||||||
export type EventNames = keyof EventMappings;
|
|
||||||
|
|
||||||
type FilterByValueType<T, ValueType> = { [K in keyof T]: T[K] extends ValueType ? K : never }[keyof T];
|
type FilterByValueType<T, ValueType> = { [K in keyof T]: T[K] extends ValueType ? K : never }[keyof T];
|
||||||
|
|
||||||
@ -378,12 +379,10 @@ class AppContext extends Component {
|
|||||||
|
|
||||||
this.child(rootWidget);
|
this.child(rootWidget);
|
||||||
|
|
||||||
this.triggerEvent("initialRenderComplete");
|
this.triggerEvent("initialRenderComplete", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove ignore once all commands are mapped out.
|
triggerEvent<K extends EventNames>(name: K, data: EventData<K>) {
|
||||||
//@ts-ignore
|
|
||||||
triggerEvent<K extends EventNames | CommandNames>(name: K, data: CommandAndEventMappings[K] = {}) {
|
|
||||||
return this.handleEvent(name, data);
|
return this.handleEvent(name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ export class TypedComponent<ChildT extends TypedComponent<ChildT>> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEvent(name: string, data: unknown): Promise<unknown> | null {
|
handleEvent<T extends EventNames>(name: T, data: EventData<T>): Promise<unknown[] | unknown> | null {
|
||||||
try {
|
try {
|
||||||
const callMethodPromise = this.initialized ? this.initialized.then(() => this.callMethod((this as any)[`${name}Event`], data)) : this.callMethod((this as any)[`${name}Event`], data);
|
const callMethodPromise = this.initialized ? this.initialized.then(() => this.callMethod((this as any)[`${name}Event`], data)) : this.callMethod((this as any)[`${name}Event`], data);
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
|
|||||||
await ws.waitForMaxKnownEntityChangeId();
|
await ws.waitForMaxKnownEntityChangeId();
|
||||||
|
|
||||||
await appContext.tabManager.getActiveContext().setNote(notePath);
|
await appContext.tabManager.getActiveContext().setNote(notePath);
|
||||||
await appContext.triggerEvent("focusAndSelectTitle");
|
await appContext.triggerEvent("focusAndSelectTitle", {});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.openTabWithNote = async (notePath, activate) => {
|
this.openTabWithNote = async (notePath, activate) => {
|
||||||
@ -472,7 +472,7 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
|
|||||||
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, { activate });
|
await appContext.tabManager.openTabWithNoteWithHoisting(notePath, { activate });
|
||||||
|
|
||||||
if (activate) {
|
if (activate) {
|
||||||
await appContext.triggerEvent("focusAndSelectTitle");
|
await appContext.triggerEvent("focusAndSelectTitle", {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -485,7 +485,7 @@ function FrontendScriptApi(this: Api, startNote: FNote, currentNote: FNote, orig
|
|||||||
await appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath });
|
await appContext.triggerCommand("openNewNoteSplit", { ntxId, notePath });
|
||||||
|
|
||||||
if (activate) {
|
if (activate) {
|
||||||
await appContext.triggerEvent("focusAndSelectTitle");
|
await appContext.triggerEvent("focusAndSelectTitle", {});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ ws.subscribeToMessages(async (message) => {
|
|||||||
if (message.type === "protectedSessionLogin") {
|
if (message.type === "protectedSessionLogin") {
|
||||||
await reloadData();
|
await reloadData();
|
||||||
|
|
||||||
await appContext.triggerEvent("frocaReloaded");
|
await appContext.triggerEvent("frocaReloaded", {});
|
||||||
|
|
||||||
appContext.triggerEvent("protectedSessionStarted");
|
appContext.triggerEvent("protectedSessionStarted", {});
|
||||||
|
|
||||||
appContext.triggerCommand("closeProtectedSessionPasswordDialog");
|
appContext.triggerCommand("closeProtectedSessionPasswordDialog");
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export default class LauncherContainer extends FlexContainer<LauncherWidget> {
|
|||||||
this.$widget.empty();
|
this.$widget.empty();
|
||||||
this.renderChildren();
|
this.renderChildren();
|
||||||
|
|
||||||
await this.handleEventInChildren("initialRenderComplete");
|
await this.handleEventInChildren("initialRenderComplete", {});
|
||||||
|
|
||||||
const activeContext = appContext.tabManager.getActiveContext();
|
const activeContext = appContext.tabManager.getActiveContext();
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import FlexContainer from "./flex_container.js";
|
import FlexContainer from "./flex_container.js";
|
||||||
import splitService from "../../services/resizer.js";
|
import splitService from "../../services/resizer.js";
|
||||||
import type RightPanelWidget from "../right_panel_widget.js";
|
import type RightPanelWidget from "../right_panel_widget.js";
|
||||||
|
import type { EventData, EventNames } from "../../components/app_context.js";
|
||||||
|
|
||||||
export default class RightPaneContainer extends FlexContainer<RightPanelWidget> {
|
export default class RightPaneContainer extends FlexContainer<RightPanelWidget> {
|
||||||
private rightPaneHidden: boolean;
|
private rightPaneHidden: boolean;
|
||||||
@ -19,7 +20,7 @@ export default class RightPaneContainer extends FlexContainer<RightPanelWidget>
|
|||||||
return super.isEnabled() && !this.rightPaneHidden && this.children.length > 0 && !!this.children.find((ch) => ch.isEnabled() && ch.canBeShown());
|
return super.isEnabled() && !this.rightPaneHidden && this.children.length > 0 && !!this.children.find((ch) => ch.isEnabled() && ch.canBeShown());
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEventInChildren(name: string, data: unknown) {
|
handleEventInChildren<T extends EventNames>(name: T, data: EventData<T>): Promise<unknown[] | unknown> | null {
|
||||||
const promise = super.handleEventInChildren(name, data);
|
const promise = super.handleEventInChildren(name, data);
|
||||||
|
|
||||||
if (["activeContextChanged", "noteSwitchedAndActivated", "noteSwitched"].includes(name)) {
|
if (["activeContextChanged", "noteSwitchedAndActivated", "noteSwitched"].includes(name)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user