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 some more files
Elian Doran2828b39f4872
diff --git a/src/public/app/components/entrypoints.ts b/src/public/app/components/entrypoints.tsindex 69651de17f..d4c8b600ec 100644--- a/src/public/app/components/entrypoints.ts+++ b/src/public/app/components/entrypoints.ts@@ -13,7 +13,7 @@ import { t } from "../services/i18n.js";import type FNote from "../entities/fnote.js";// TODO: Move somewhere else nicer.-export type SqlExecuteResults = unknown[];+export type SqlExecuteResults = string[][][];// TODO: Deduplicate with server.interface SqlExecuteResponse {diff --git a/src/public/app/services/branches.ts b/src/public/app/services/branches.tsindex 18bae35294..b6f562f7c9 100644--- a/src/public/app/services/branches.ts+++ b/src/public/app/services/branches.ts@@ -252,7 +252,7 @@ async function cloneNoteToBranch(childNoteId: string, parentBranchId: string, pr}}-async function cloneNoteToParentNote(childNoteId: string, parentNoteId: string, prefix: string) {+async function cloneNoteToParentNote(childNoteId: string, parentNoteId: string, prefix?: string) {const resp = await server.put<Response>(`notes/${childNoteId}/clone-to-note/${parentNoteId}`, {prefix: prefix});diff --git a/src/public/app/widgets/search_result.js b/src/public/app/widgets/search_result.tssimilarity index 75%rename from src/public/app/widgets/search_result.jsrename to src/public/app/widgets/search_result.tsindex d18efff18d..d1f72f08bf 100644--- a/src/public/app/widgets/search_result.js+++ b/src/public/app/widgets/search_result.ts@@ -1,6 +1,8 @@import { t } from "../services/i18n.js";import NoteContextAwareWidget from "./note_context_aware_widget.js";import NoteListRenderer from "../services/note_list_renderer.js";+import type FNote from "../entities/fnote.js";+import type { EventData } from "../components/app_context.js";const TPL = `<div class="search-result-widget">@@ -11,32 +13,37 @@ const TPL = `min-height: 0;overflow: auto;}-+.search-result-widget .note-list {padding: 10px;}-+.search-no-results, .search-not-executed-yet {margin: 20px;padding: 20px;}</style>-+<div class="search-no-results alert alert-info">${t("search_result.no_notes_found")}</div>-+<div class="search-not-executed-yet alert alert-info">${t("search_result.search_not_executed")}</div>-+<div class="search-result-widget-content"></div></div>`;export default class SearchResultWidget extends NoteContextAwareWidget {++ private $content!: JQuery<HTMLElement>;+ private $noResults!: JQuery<HTMLElement>;+ private $notExecutedYet!: JQuery<HTMLElement>;+isEnabled() {- return super.isEnabled() && this.note.type === "search";+ return super.isEnabled() && this.note?.type === "search";}doRender() {@@ -47,7 +54,7 @@ export default class SearchResultWidget extends NoteContextAwareWidget {this.$notExecutedYet = this.$widget.find(".search-not-executed-yet");}- async refreshWithNote(note) {+ async refreshWithNote(note: FNote) {this.$content.empty();this.$noResults.toggle(note.getChildNoteIds().length === 0 && !!note.searchResultsLoaded);this.$notExecutedYet.toggle(!note.searchResultsLoaded);@@ -56,7 +63,7 @@ export default class SearchResultWidget extends NoteContextAwareWidget {await noteListRenderer.renderList();}- searchRefreshedEvent({ ntxId }) {+ searchRefreshedEvent({ ntxId }: EventData<"searchRefreshed">) {if (!this.isNoteContext(ntxId)) {return;}@@ -64,8 +71,8 @@ export default class SearchResultWidget extends NoteContextAwareWidget {this.refresh();}- notesReloadedEvent({ noteIds }) {- if (noteIds.includes(this.noteId)) {+ notesReloadedEvent({ noteIds }: EventData<"notesReloaded">) {+ if (this.noteId && noteIds.includes(this.noteId)) {this.refresh();}}diff --git a/src/public/app/widgets/shared_info.js b/src/public/app/widgets/shared_info.tssimilarity index 82%rename from src/public/app/widgets/shared_info.jsrename to src/public/app/widgets/shared_info.tsindex e80a5d7606..64b5c568fd 100644--- a/src/public/app/widgets/shared_info.js+++ b/src/public/app/widgets/shared_info.ts@@ -2,6 +2,8 @@ import NoteContextAwareWidget from "./note_context_aware_widget.js";import options from "../services/options.js";import attributeService from "../services/attributes.js";import { t } from "../services/i18n.js";+import type FNote from "../entities/fnote.js";+import type { EventData } from "../components/app_context.js";const TPL = `<div class="shared-info-widget alert alert-warning use-tn-links">@@ -18,8 +20,12 @@ const TPL = `</div>`;export default class SharedInfoWidget extends NoteContextAwareWidget {++ private $sharedLink!: JQuery<HTMLElement>;+ private $sharedText!: JQuery<HTMLElement>;+isEnabled() {- return super.isEnabled() && this.noteId !== "_share" && this.note.hasAncestor("_share");+ return super.isEnabled() && this.noteId !== "_share" && this.note?.hasAncestor("_share");}doRender() {@@ -29,7 +35,7 @@ export default class SharedInfoWidget extends NoteContextAwareWidget {this.contentSized();}- async refreshWithNote(note) {+ async refreshWithNote(note: FNote) {const syncServerHost = options.get("syncServerHost");let link;@@ -53,7 +59,7 @@ export default class SharedInfoWidget extends NoteContextAwareWidget {this.$sharedLink.attr("href", link).text(link);}- getShareId(note) {+ getShareId(note: FNote) {if (note.hasOwnedLabel("shareRoot")) {return "";}@@ -61,8 +67,8 @@ export default class SharedInfoWidget extends NoteContextAwareWidget {return note.getOwnedLabelValue("shareAlias") || note.noteId;}- entitiesReloadedEvent({ loadResults }) {- if (loadResults.getAttributeRows().find((attr) => attr.name.startsWith("_share") && attributeService.isAffecting(attr, this.note))) {+ entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {+ if (loadResults.getAttributeRows().find((attr) => attr.name?.startsWith("_share") && attributeService.isAffecting(attr, this.note))) {this.refresh();} else if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId)) {this.refresh();diff --git a/src/public/app/widgets/shared_switch.js b/src/public/app/widgets/shared_switch.tssimilarity index 76%rename from src/public/app/widgets/shared_switch.jsrename to src/public/app/widgets/shared_switch.tsindex 90d2e7e9e3..20e954efa4 100644--- a/src/public/app/widgets/shared_switch.js+++ b/src/public/app/widgets/shared_switch.ts@@ -5,10 +5,15 @@ import utils from "../services/utils.js";import syncService from "../services/sync.js";import dialogService from "../services/dialog.js";import { t } from "../services/i18n.js";+import type FNote from "../entities/fnote.js";+import type { EventData } from "../components/app_context.js";export default class SharedSwitchWidget extends SwitchWidget {+isEnabled() {- return super.isEnabled() && !["root", "_share", "_hidden"].includes(this.noteId) && !this.noteId.startsWith("_options");+ return super.isEnabled()+ && !["root", "_share", "_hidden"].includes(this.noteId ?? "")+ && !this.noteId?.startsWith("_options");}doRender() {@@ -25,19 +30,23 @@ export default class SharedSwitchWidget extends SwitchWidget {}async switchOn() {+ if (!this.noteId) {+ return;+ }+await branchService.cloneNoteToParentNote(this.noteId, "_share");syncService.syncNow(true);}async switchOff() {- const shareBranch = this.note.getParentBranches().find((b) => b.parentNoteId === "_share");+ const shareBranch = this.note?.getParentBranches().find((b) => b.parentNoteId === "_share");if (!shareBranch) {return;}- if (this.note.getParentBranches().length === 1) {+ if (this.note?.getParentBranches().length === 1) {if (!(await dialogService.confirm(t("shared_switch.shared-branch")))) {return;}@@ -48,7 +57,7 @@ export default class SharedSwitchWidget extends SwitchWidget {syncService.syncNow(true);}- async refreshWithNote(note) {+ async refreshWithNote(note: FNote) {const isShared = note.hasAncestor("_share");const canBeUnshared = isShared && note.getParentBranches().find((b) => b.parentNoteId === "_share");const switchDisabled = isShared && !canBeUnshared;@@ -64,7 +73,7 @@ export default class SharedSwitchWidget extends SwitchWidget {}}- entitiesReloadedEvent({ loadResults }) {+ entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {if (loadResults.getBranchRows().find((b) => b.noteId === this.noteId)) {this.refresh();}diff --git a/src/public/app/widgets/sql_result.js b/src/public/app/widgets/sql_result.tssimilarity index 89%rename from src/public/app/widgets/sql_result.jsrename to src/public/app/widgets/sql_result.tsindex 7fcbff4409..a75dcb9c4b 100644--- a/src/public/app/widgets/sql_result.js+++ b/src/public/app/widgets/sql_result.ts@@ -1,3 +1,4 @@+import type { EventData } from "../components/app_context.js";import { t } from "../services/i18n.js";import NoteContextAwareWidget from "./note_context_aware_widget.js";@@ -21,6 +22,10 @@ const TPL = `</div>`;export default class SqlResultWidget extends NoteContextAwareWidget {++ private $resultContainer!: JQuery<HTMLElement>;+ private $noRowsAlert!: JQuery<HTMLElement>;+isEnabled() {return this.note && this.note.mime === "text/x-sqlite;schema=trilium" && super.isEnabled();}@@ -32,7 +37,7 @@ export default class SqlResultWidget extends NoteContextAwareWidget {this.$noRowsAlert = this.$widget.find(".sql-query-no-rows");}- async sqlQueryResultsEvent({ ntxId, results }) {+ async sqlQueryResultsEvent({ ntxId, results }: EventData<"sqlQueryResults">) {if (!this.isNoteContext(ntxId)) {return;}diff --git a/src/public/app/widgets/sql_table_schemas.js b/src/public/app/widgets/sql_table_schemas.tssimilarity index 84%rename from src/public/app/widgets/sql_table_schemas.jsrename to src/public/app/widgets/sql_table_schemas.tsindex e5fafb01fa..e21fc8abc6 100644--- a/src/public/app/widgets/sql_table_schemas.js+++ b/src/public/app/widgets/sql_table_schemas.ts@@ -1,6 +1,7 @@import { t } from "../services/i18n.js";import NoteContextAwareWidget from "./note_context_aware_widget.js";import server from "../services/server.js";+import type FNote from "../entities/fnote.js";const TPL = `<div class="sql-table-schemas-widget">@@ -38,7 +39,19 @@ const TPL = `<span class="sql-table-schemas"></span></div>`;+interface SchemaResponse {+ name: string;+ columns: {+ name: string;+ type: string;+ }[];+}+export default class SqlTableSchemasWidget extends NoteContextAwareWidget {++ private tableSchemasShown?: boolean;+ private $sqlConsoleTableSchemas!: JQuery<HTMLElement>;+isEnabled() {return this.note && this.note.mime === "text/x-sqlite;schema=trilium" && super.isEnabled();}@@ -50,14 +63,14 @@ export default class SqlTableSchemasWidget extends NoteContextAwareWidget {this.$sqlConsoleTableSchemas = this.$widget.find(".sql-table-schemas");}- async refreshWithNote(note) {+ async refreshWithNote(note: FNote) {if (this.tableSchemasShown) {return;}this.tableSchemasShown = true;- const tableSchema = await server.get("sql/schema");+ const tableSchema = await server.get<SchemaResponse[]>("sql/schema");for (const table of tableSchema) {const $tableLink = $('<button class="btn">').text(table.name);@@ -73,7 +86,6 @@ export default class SqlTableSchemasWidget extends NoteContextAwareWidget {$tableLink.tooltip({html: true,placement: "bottom",- boundary: "window",title: $table[0].outerHTML,sanitize: false});diff --git a/src/public/app/widgets/switch.ts b/src/public/app/widgets/switch.tsindex 63fd23fce8..9e7d61bf15 100644--- a/src/public/app/widgets/switch.ts+++ b/src/public/app/widgets/switch.ts@@ -131,7 +131,7 @@ export default class SwitchWidget extends NoteContextAwareWidget {protected switchOffName = "";protected switchOffTooltip = "";- private disabledTooltip = "";+ protected disabledTooltip = "";private currentState = false;diff --git a/src/public/app/widgets/title_bar_buttons.js b/src/public/app/widgets/title_bar_buttons.tssimilarity index 100%rename from src/public/app/widgets/title_bar_buttons.jsrename to src/public/app/widgets/title_bar_buttons.tsdiff --git a/src/public/app/widgets/type_widgets/empty.js b/src/public/app/widgets/type_widgets/empty.tssimilarity index 92%rename from src/public/app/widgets/type_widgets/empty.jsrename to src/public/app/widgets/type_widgets/empty.tsindex fa73ea5ff4..8338f53ae0 100644--- a/src/public/app/widgets/type_widgets/empty.js+++ b/src/public/app/widgets/type_widgets/empty.ts@@ -3,6 +3,7 @@ import TypeWidget from "./type_widget.js";import appContext from "../../components/app_context.js";import searchService from "../../services/search.js";import { t } from "../../services/i18n.js";+import type FNote from "../../entities/fnote.js";const TPL = `<div class="note-detail-empty note-detail-printable">@@ -13,7 +14,7 @@ const TPL = `flex-wrap: wrap;justify-content: space-evenly;}-+.workspace-notes .workspace-note {width: 130px;text-align: center;@@ -40,7 +41,7 @@ const TPL = `.empty-tab-search .input-clearer-button {border-bottom-right-radius: 0;}-+.workspace-icon {text-align: center;font-size: 500%;@@ -58,6 +59,11 @@ const TPL = `</div>`;export default class EmptyTypeWidget extends TypeWidget {++ private $autoComplete!: JQuery<HTMLElement>;+ private $results!: JQuery<HTMLElement>;+ private $workspaceNotes!: JQuery<HTMLElement>;+static getType() {return "empty";}@@ -74,7 +80,7 @@ export default class EmptyTypeWidget extends TypeWidget {hideGoToSelectedNoteButton: true,allowCreatingNotes: true,allowJumpToSearchNotes: true,- container: this.$results+ container: this.$results[0]}).on("autocomplete:noteselected", function (event, suggestion, dataset) {if (!suggestion.notePath) {@@ -90,7 +96,7 @@ export default class EmptyTypeWidget extends TypeWidget {super.doRender();}- async doRefresh(note) {+ async doRefresh(note: FNote) {const workspaceNotes = await searchService.searchForNotes("#workspace #!template");this.$workspaceNotes.empty();diff --git a/src/public/app/widgets/type_widgets/image.js b/src/public/app/widgets/type_widgets/image.tssimilarity index 82%rename from src/public/app/widgets/type_widgets/image.jsrename to src/public/app/widgets/type_widgets/image.tsindex 208c1c1ad8..e235abaef3 100644--- a/src/public/app/widgets/type_widgets/image.js+++ b/src/public/app/widgets/type_widgets/image.ts@@ -3,6 +3,8 @@ import TypeWidget from "./type_widget.js";import libraryLoader from "../../services/library_loader.js";import imageContextMenuService from "../../menus/image_context_menu.js";import imageService from "../../services/image.js";+import type FNote from "../../entities/fnote.js";+import type { EventData } from "../../components/app_context.js";const TPL = `<div class="note-detail-image note-detail-printable">@@ -10,11 +12,11 @@ const TPL = `.type-image .note-detail {height: 100%;}-+.note-detail-image {- height: 100%;+ height: 100%;}-+.note-detail-image-wrapper {position: relative;display: flex;@@ -23,7 +25,7 @@ const TPL = `justify-content: center;height: 100%;}-+.note-detail-image-view {display: block;width: auto;@@ -39,6 +41,10 @@ const TPL = `</div>`;class ImageTypeWidget extends TypeWidget {++ private $imageWrapper!: JQuery<HTMLElement>;+ private $imageView!: JQuery<HTMLElement>;+static getType() {return "image";}@@ -61,11 +67,11 @@ class ImageTypeWidget extends TypeWidget {super.doRender();}- async doRefresh(note) {+ async doRefresh(note: FNote) {this.$imageView.prop("src", utils.createImageSrcUrl(note));}- copyImageReferenceToClipboardEvent({ ntxId }) {+ copyImageReferenceToClipboardEvent({ ntxId }: EventData<"copyImageReferenceToClipboard">) {if (!this.isNoteContext(ntxId)) {return;}@@ -73,7 +79,7 @@ class ImageTypeWidget extends TypeWidget {imageService.copyImageReferenceToClipboard(this.$imageWrapper);}- async entitiesReloadedEvent({ loadResults }) {+ async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {if (loadResults.isNoteReloaded(this.noteId)) {this.refresh();}diff --git a/src/public/app/widgets/type_widgets/render.js b/src/public/app/widgets/type_widgets/render.tssimilarity index 78%rename from src/public/app/widgets/type_widgets/render.jsrename to src/public/app/widgets/type_widgets/render.tsindex 27772c74ce..2c0bcfdf8e 100644--- a/src/public/app/widgets/type_widgets/render.js+++ b/src/public/app/widgets/type_widgets/render.ts@@ -1,6 +1,8 @@import renderService from "../../services/render.js";import TypeWidget from "./type_widget.js";import { t } from "../../services/i18n.js";+import type FNote from "../../entities/fnote.js";+import type { EventData } from "../../components/app_context.js";const TPL = `<div class="note-detail-render note-detail-printable">@@ -20,6 +22,10 @@ const TPL = `</div>`;export default class RenderTypeWidget extends TypeWidget {++ private $noteDetailRenderHelp!: JQuery<HTMLElement>;+ private $noteDetailRenderContent!: JQuery<HTMLElement>;+static getType() {return "render";}@@ -32,7 +38,7 @@ export default class RenderTypeWidget extends TypeWidget {super.doRender();}- async doRefresh(note) {+ async doRefresh(note: FNote) {this.$widget.show();this.$noteDetailRenderHelp.hide();@@ -48,12 +54,12 @@ export default class RenderTypeWidget extends TypeWidget {}renderActiveNoteEvent() {- if (this.noteContext.isActive()) {+ if (this.noteContext?.isActive()) {this.refresh();}}- async executeWithContentElementEvent({ resolve, ntxId }) {+ async executeWithContentElementEvent({ resolve, ntxId }: EventData<"executeWithContentElement">) {if (!this.isNoteContext(ntxId)) {return;}diff --git a/src/public/app/widgets/watched_file_update_status.js b/src/public/app/widgets/watched_file_update_status.tssimilarity index 71%rename from src/public/app/widgets/watched_file_update_status.jsrename to src/public/app/widgets/watched_file_update_status.tsindex d73746b86d..e65edc376e 100644--- a/src/public/app/widgets/watched_file_update_status.js+++ b/src/public/app/widgets/watched_file_update_status.ts@@ -3,6 +3,8 @@ import NoteContextAwareWidget from "./note_context_aware_widget.js";import server from "../services/server.js";import fileWatcher from "../services/file_watcher.js";import dayjs from "dayjs";+import type { EventData } from "../components/app_context.js";+import type FNote from "../entities/fnote.js";const TPL = `<div class="dropdown watched-file-update-status-widget alert alert-warning">@@ -12,21 +14,30 @@ const TPL = `contain: none;}</style>-- <p>${t("watched_file_update_status.file_last_modified", { count: "" })}</p>++ <p>${t("watched_file_update_status.file_last_modified")}</p><div style="display: flex; flex-direction: row; justify-content: space-evenly;"><button class="btn btn-sm file-upload-button">${t("watched_file_update_status.upload_modified_file")}</button>-+<button class="btn btn-sm ignore-this-change-button">${t("watched_file_update_status.ignore_this_change")}</button></div></div>`;export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidget {++ private $filePath!: JQuery<HTMLElement>;+ private $fileLastModified!: JQuery<HTMLElement>;+ private $fileUploadButton!: JQuery<HTMLElement>;+ private $ignoreThisChangeButton!: JQuery<HTMLElement>;+isEnabled() {const { entityType, entityId } = this.getEntity();- return super.isEnabled() && !!fileWatcher.getFileModificationStatus(entityType, entityId);+ return super.isEnabled()+ && !!entityType+ && !!entityId+ && !!fileWatcher.getFileModificationStatus(entityType, entityId);}doRender() {@@ -43,7 +54,9 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidgefilePath: this.$filePath.text()});- fileWatcher.fileModificationUploaded(entityType, entityId);+ if (entityType && entityId) {+ fileWatcher.fileModificationUploaded(entityType, entityId);+ }this.refresh();});@@ -51,13 +64,18 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidgethis.$ignoreThisChangeButton.on("click", () => {const { entityType, entityId } = this.getEntity();- fileWatcher.ignoreModification(entityType, entityId);+ if (entityType && entityId) {+ fileWatcher.ignoreModification(entityType, entityId);+ }this.refresh();});}- async refreshWithNote(note) {+ async refreshWithNote(note: FNote) {const { entityType, entityId } = this.getEntity();+ if (!entityType || !entityId) {+ return;+ }const status = fileWatcher.getFileModificationStatus(entityType, entityId);this.$filePath.text(status.filePath);@@ -71,7 +89,7 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidgeconst { viewScope } = this.noteContext;- if (viewScope.viewMode === "attachments" && viewScope.attachmentId) {+ if (viewScope?.viewMode === "attachments" && viewScope.attachmentId) {return {entityType: "attachments",entityId: viewScope.attachmentId@@ -84,7 +102,7 @@ export default class WatchedFileUpdateStatusWidget extends NoteContextAwareWidge}}- openedFileUpdatedEvent(data) {+ openedFileUpdatedEvent(data: EventData<"openedFileUpdated">) {console.log(data);const { entityType, entityId } = this.getEntity();