Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(client/ts): port launcher & launcher_container
Elian Dorane45052cead57
diff --git a/src/public/app/services/load_results.ts b/src/public/app/services/load_results.tsindex 9d4eb9b306..47efc5fba8 100644--- a/src/public/app/services/load_results.ts+++ b/src/public/app/services/load_results.ts@@ -10,6 +10,7 @@ interface NoteRow {interface BranchRow {branchId: string;componentId: string;+ parentNoteId?: string;}export interface AttributeRow {diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.tsindex c90eb4270d..a4765c9846 100644--- a/src/public/app/types.d.ts+++ b/src/public/app/types.d.ts@@ -42,6 +42,7 @@ interface CustomGlobals {instanceName: string;appCssNoteIds: string[];triliumVersion: string;+ TRILIUM_SAFE_MODE: boolean;}type RequireMethod = (moduleName: string) => any;diff --git a/src/public/app/widgets/containers/launcher.js b/src/public/app/widgets/containers/launcher.tssimilarity index 83%rename from src/public/app/widgets/containers/launcher.jsrename to src/public/app/widgets/containers/launcher.tsindex 207cf9b1fc..4af2c31b5a 100644--- a/src/public/app/widgets/containers/launcher.js+++ b/src/public/app/widgets/containers/launcher.ts@@ -11,12 +11,22 @@ import utils from "../../services/utils.js";import TodayLauncher from "../buttons/launcher/today_launcher.js";import HistoryNavigationButton from "../buttons/history_navigation.js";import QuickSearchLauncherWidget from "../quick_search_launcher.js";+import FNote from "../../entities/fnote.js";++interface InnerWidget extends BasicWidget {+ settings?: {+ titlePlacement: "bottom"+ }+}export default class LauncherWidget extends BasicWidget {- constructor(isHorizontalLayout) {++ private innerWidget!: InnerWidget;+ private isHorizontalLayout: boolean;++ constructor(isHorizontalLayout: boolean) {super();- this.innerWidget = null;this.isHorizontalLayout = isHorizontalLayout;}@@ -28,7 +38,7 @@ export default class LauncherWidget extends BasicWidget {this.$widget = this.innerWidget.render();}- async initLauncher(note) {+ async initLauncher(note: FNote) {if (note.type !== 'launcher') {throw new Error(`Note '${note.noteId}' '${note.title}' is not a launcher even though it's in the launcher subtree`);}@@ -43,28 +53,30 @@ export default class LauncherWidget extends BasicWidget {return false;}+ let widget: BasicWidget;if (launcherType === 'command') {- this.innerWidget = this.initCommandLauncherWidget(note)+ widget = this.initCommandLauncherWidget(note).class("launcher-button");} else if (launcherType === 'note') {- this.innerWidget = new NoteLauncher(note)+ widget = new NoteLauncher(note).class("launcher-button");} else if (launcherType === 'script') {- this.innerWidget = new ScriptLauncher(note)+ widget = new ScriptLauncher(note).class("launcher-button");} else if (launcherType === 'customWidget') {- this.innerWidget = await this.initCustomWidget(note);+ widget = await this.initCustomWidget(note);} else if (launcherType === 'builtinWidget') {- this.innerWidget = this.initBuiltinWidget(note);+ widget = this.initBuiltinWidget(note);} else {throw new Error(`Unrecognized launcher type '${launcherType}' for launcher '${note.noteId}' title '${note.title}'`);}- if (!this.innerWidget) {+ if (!widget) {throw new Error(`Unknown initialization error for note '${note.noteId}', title '${note.title}'`);}- this.child(this.innerWidget);+ this.child(widget);+ this.innerWidget = widget as InnerWidget;if (this.isHorizontalLayout && this.innerWidget.settings) {this.innerWidget.settings.titlePlacement = "bottom";}@@ -72,14 +84,14 @@ export default class LauncherWidget extends BasicWidget {return true;}- initCommandLauncherWidget(note) {+ initCommandLauncherWidget(note: FNote) {return new CommandButtonWidget().title(() => note.title).icon(() => note.getIcon()).command(() => note.getLabelValue("command"));}- async initCustomWidget(note) {+ async initCustomWidget(note: FNote) {const widget = await note.getRelationTarget('widget');if (widget) {@@ -89,7 +101,7 @@ export default class LauncherWidget extends BasicWidget {}}- initBuiltinWidget(note) {+ initBuiltinWidget(note: FNote) {const builtinWidget = note.getLabelValue("builtinWidget");switch (builtinWidget) {case "calendar":@@ -98,7 +110,7 @@ export default class LauncherWidget extends BasicWidget {// || has to be inside since 0 is a valid valueconst baseSize = parseInt(note.getLabelValue("baseSize") || "40");const growthFactor = parseInt(note.getLabelValue("growthFactor") || "100");-+return new SpacerWidget(baseSize, growthFactor);case "bookmarks":return new BookmarkButtons(this.isHorizontalLayout);diff --git a/src/public/app/widgets/containers/launcher_container.js b/src/public/app/widgets/containers/launcher_container.tssimilarity index 84%rename from src/public/app/widgets/containers/launcher_container.jsrename to src/public/app/widgets/containers/launcher_container.tsindex e20969da4f..5f567e0b3f 100644--- a/src/public/app/widgets/containers/launcher_container.js+++ b/src/public/app/widgets/containers/launcher_container.ts@@ -1,10 +1,12 @@import FlexContainer from "./flex_container.js";import froca from "../../services/froca.js";-import appContext from "../../components/app_context.js";+import appContext, { EventData } from "../../components/app_context.js";import LauncherWidget from "./launcher.js";export default class LauncherContainer extends FlexContainer {- constructor(isHorizontalLayout) {+ private isHorizontalLayout: boolean;++ constructor(isHorizontalLayout: boolean) {super(isHorizontalLayout ? "row" : "column");this.id('launcher-container');@@ -66,8 +68,8 @@ export default class LauncherContainer extends FlexContainer {}}- entitiesReloadedEvent({loadResults}) {- if (loadResults.getBranchRows().find(branch => froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {+ entitiesReloadedEvent({loadResults}: EventData<"entitiesReloaded">) {+ if (loadResults.getBranchRows().find(branch => branch.parentNoteId && froca.getNoteFromCache(branch.parentNoteId)?.isLaunchBarConfig())) {// changes in note placement require reload of all launchers, all other changes are handled by individual// launchersthis.load();