From 0e81f086c069c239e9cd56d58eb0578a1668a81b Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Mon, 3 Mar 2025 21:22:33 +0100
Subject: [PATCH 1/6] =?UTF-8?q?chore:=20=F0=9F=A4=96=20(ts)=20port=20about?=
=?UTF-8?q?=20dialog?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../widgets/dialogs/{about.js => about.ts} | 37 +++++++++++++------
1 file changed, 25 insertions(+), 12 deletions(-)
rename src/public/app/widgets/dialogs/{about.js => about.ts} (77%)
diff --git a/src/public/app/widgets/dialogs/about.js b/src/public/app/widgets/dialogs/about.ts
similarity index 77%
rename from src/public/app/widgets/dialogs/about.js
rename to src/public/app/widgets/dialogs/about.ts
index 918e725af..f77f67372 100644
--- a/src/public/app/widgets/dialogs/about.js
+++ b/src/public/app/widgets/dialogs/about.ts
@@ -5,6 +5,15 @@ import openService from "../../services/open.js";
import server from "../../services/server.js";
import utils from "../../services/utils.js";
+interface AppInfo {
+ appVersion: string;
+ dbVersion: number;
+ syncVersion: number;
+ buildDate: string;
+ buildRevision: string;
+ dataDirectory: string;
+}
+
const TPL = `
@@ -35,12 +44,10 @@ const TPL = `
${t("about.build_date")} |
|
-
| ${t("about.build_revision")} |
- |
+ |
-
| ${t("about.data_directory")} |
|
@@ -59,7 +66,14 @@ const TPL = `
`;
export default class AboutDialog extends BasicWidget {
- doRender() {
+ private $appVersion!: JQuery;
+ private $dbVersion!: JQuery;
+ private $syncVersion!: JQuery;
+ private $buildDate!: JQuery;
+ private $buildRevision!: JQuery;
+ private $dataDirectory!: JQuery;
+
+ doRender(): void {
this.$widget = $(TPL);
this.$appVersion = this.$widget.find(".app-version");
this.$dbVersion = this.$widget.find(".db-version");
@@ -69,12 +83,12 @@ export default class AboutDialog extends BasicWidget {
this.$dataDirectory = this.$widget.find(".data-directory");
}
- async refresh() {
- const appInfo = await server.get("app-info");
+ async refresh(): Promise {
+ const appInfo = await server.get("app-info");
this.$appVersion.text(appInfo.appVersion);
- this.$dbVersion.text(appInfo.dbVersion);
- this.$syncVersion.text(appInfo.syncVersion);
+ this.$dbVersion.text(appInfo.dbVersion.toString());
+ this.$syncVersion.text(appInfo.syncVersion.toString());
this.$buildDate.text(formatDateTime(appInfo.buildDate));
this.$buildRevision.text(appInfo.buildRevision);
this.$buildRevision.attr("href", `https://github.com/TriliumNext/Notes/commit/${appInfo.buildRevision}`);
@@ -84,9 +98,9 @@ export default class AboutDialog extends BasicWidget {
href: "#",
class: "tn-link",
text: appInfo.dataDirectory
- })
+ }).prop("outerHTML")
);
- this.$dataDirectory.find("a").on("click", (event) => {
+ this.$dataDirectory.find("a").on("click", (event: JQuery.ClickEvent) => {
event.preventDefault();
openService.openDirectory(appInfo.dataDirectory);
});
@@ -95,9 +109,8 @@ export default class AboutDialog extends BasicWidget {
}
}
- async openAboutDialogEvent() {
+ async openAboutDialogEvent(): Promise {
await this.refresh();
-
utils.openDialog(this.$widget);
}
}
From 55436501667297a9cd16f51d4e62efee1449cd4f Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Mon, 3 Mar 2025 23:54:09 +0100
Subject: [PATCH 2/6] =?UTF-8?q?chore:=20=F0=9F=A4=96=20(ts)=20port=20add?=
=?UTF-8?q?=5Flink=20dialog?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/public/app/types.d.ts | 2 +-
.../dialogs/{add_link.js => add_link.ts} | 50 ++++++++++++-------
2 files changed, 34 insertions(+), 18 deletions(-)
rename src/public/app/widgets/dialogs/{add_link.js => add_link.ts} (80%)
diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.ts
index a37df7f74..e4f882aeb 100644
--- a/src/public/app/types.d.ts
+++ b/src/public/app/types.d.ts
@@ -84,7 +84,7 @@ declare global {
getSelectedNotePath(): string | undefined;
getSelectedNoteId(): string | null;
setSelectedNotePath(notePath: string | null | undefined);
- getSelectedExternalLink(this: HTMLElement): string | undefined;
+ getSelectedExternalLink(): string | undefined;
setSelectedExternalLink(externalLink: string | null | undefined);
setNote(noteId: string);
markRegExp(regex: RegExp, opts: {
diff --git a/src/public/app/widgets/dialogs/add_link.js b/src/public/app/widgets/dialogs/add_link.ts
similarity index 80%
rename from src/public/app/widgets/dialogs/add_link.js
rename to src/public/app/widgets/dialogs/add_link.ts
index d60356869..36855b015 100644
--- a/src/public/app/widgets/dialogs/add_link.js
+++ b/src/public/app/widgets/dialogs/add_link.ts
@@ -3,6 +3,17 @@ import treeService from "../../services/tree.js";
import noteAutocompleteService from "../../services/note_autocomplete.js";
import utils from "../../services/utils.js";
import BasicWidget from "../basic_widget.js";
+import type { Suggestion } from "../../services/note_autocomplete.js";
+import type { default as TextTypeWidget } from "../type_widgets/editable_text.js";
+
+interface NoteAutocompleteElement extends HTMLElement {
+ getSelectedNotePath(): string | null;
+ getSelectedExternalLink(): string | null;
+}
+
+interface NoteAutocompleteEvent extends Event {
+ suggestion: Suggestion;
+}
const TPL = `
@@ -41,7 +52,7 @@ const TPL = `
@@ -56,6 +67,14 @@ const TPL = `
`;
export default class AddLinkDialog extends BasicWidget {
+ private $form!: JQuery;
+ private $autoComplete!: JQuery;
+ private $linkTitle!: JQuery;
+ private $addLinkTitleSettings!: JQuery;
+ private $addLinkTitleRadios!: JQuery;
+ private $addLinkTitleFormGroup!: JQuery;
+ private textTypeWidget: TextTypeWidget | null = null;
+
doRender() {
this.$widget = $(TPL);
this.$form = this.$widget.find(".add-link-form");
@@ -65,20 +84,17 @@ export default class AddLinkDialog extends BasicWidget {
this.$addLinkTitleRadios = this.$widget.find(".add-link-title-radios");
this.$addLinkTitleFormGroup = this.$widget.find(".add-link-title-form-group");
- /** @var TextTypeWidget */
- this.textTypeWidget = null;
-
this.$form.on("submit", () => {
if (this.$autoComplete.getSelectedNotePath()) {
this.$widget.modal("hide");
- const linkTitle = this.getLinkType() === "reference-link" ? null : this.$linkTitle.val();
+ const linkTitle = this.getLinkType() === "reference-link" ? null : this.$linkTitle.val() as string;
- this.textTypeWidget.addLink(this.$autoComplete.getSelectedNotePath(), linkTitle);
+ this.textTypeWidget?.addLink(this.$autoComplete.getSelectedNotePath()!, linkTitle);
} else if (this.$autoComplete.getSelectedExternalLink()) {
this.$widget.modal("hide");
- this.textTypeWidget.addLink(this.$autoComplete.getSelectedExternalLink(), this.$linkTitle.val());
+ this.textTypeWidget?.addLink(this.$autoComplete.getSelectedExternalLink()!, this.$linkTitle.val() as string);
} else {
logError("No link to add.");
}
@@ -87,12 +103,12 @@ export default class AddLinkDialog extends BasicWidget {
});
}
- async showAddLinkDialogEvent({ textTypeWidget, text = "" }) {
+ async showAddLinkDialogEvent({ textTypeWidget, text = "" }: { textTypeWidget: TextTypeWidget; text: string }) {
this.textTypeWidget = textTypeWidget;
this.$addLinkTitleSettings.toggle(!this.textTypeWidget.hasSelection());
- this.$addLinkTitleSettings.find("input[type=radio]").on("change", (e) => this.updateTitleSettingsVisibility(e));
+ this.$addLinkTitleSettings.find("input[type=radio]").on("change", () => this.updateTitleSettingsVisibility());
// with selection hyperlink is implied
if (this.textTypeWidget.hasSelection()) {
@@ -108,9 +124,8 @@ export default class AddLinkDialog extends BasicWidget {
this.$autoComplete.val("");
this.$linkTitle.val("");
- const setDefaultLinkTitle = async (noteId) => {
+ const setDefaultLinkTitle = async (noteId: string) => {
const noteTitle = await treeService.getNoteTitle(noteId);
-
this.$linkTitle.val(noteTitle);
};
@@ -119,7 +134,7 @@ export default class AddLinkDialog extends BasicWidget {
allowCreatingNotes: true
});
- this.$autoComplete.on("autocomplete:noteselected", (event, suggestion, dataset) => {
+ this.$autoComplete.on("autocomplete:noteselected", (event: JQuery.Event, suggestion: Suggestion) => {
if (!suggestion.notePath) {
return false;
}
@@ -133,7 +148,8 @@ export default class AddLinkDialog extends BasicWidget {
}
});
- this.$autoComplete.on("autocomplete:externallinkselected", (event, suggestion, dataset) => {
+ this.$autoComplete.on("autocomplete:externallinkselected", (event: JQuery.Event, suggestion: Suggestion) => {
+ console.log("autocomplete:externallinkselected", event, suggestion);
if (!suggestion.externalLink) {
return false;
}
@@ -143,11 +159,11 @@ export default class AddLinkDialog extends BasicWidget {
this.$linkTitle.val(suggestion.externalLink);
});
- this.$autoComplete.on("autocomplete:cursorchanged", (event, suggestion, dataset) => {
+ this.$autoComplete.on("autocomplete:cursorchanged", (event: JQuery.Event, suggestion: Suggestion) => {
if (suggestion.externalLink) {
this.$linkTitle.val(suggestion.externalLink);
} else {
- const noteId = treeService.getNoteIdFromUrl(suggestion.notePath);
+ const noteId = treeService.getNoteIdFromUrl(suggestion.notePath!);
if (noteId) {
setDefaultLinkTitle(noteId);
@@ -164,7 +180,7 @@ export default class AddLinkDialog extends BasicWidget {
this.$autoComplete.trigger("focus").trigger("select"); // to be able to quickly remove entered text
}
- getLinkType() {
+ private getLinkType() {
if (this.$autoComplete.getSelectedExternalLink()) {
return "external-link";
}
@@ -172,7 +188,7 @@ export default class AddLinkDialog extends BasicWidget {
return this.$addLinkTitleSettings.find("input[type=radio]:checked").val();
}
- updateTitleSettingsVisibility() {
+ private updateTitleSettingsVisibility() {
const linkType = this.getLinkType();
this.$addLinkTitleFormGroup.toggle(linkType !== "reference-link");
From f1f55fd4f86be823cef6f615a9078d7a0411f0a5 Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Tue, 4 Mar 2025 00:33:09 +0100
Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=F0=9F=90=9B=20fix=20add=20external?=
=?UTF-8?q?=20link?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fix can't add external link from add link dialog
---
src/public/app/services/note_autocomplete.ts | 10 +++-------
src/public/app/widgets/dialogs/add_link.ts | 5 ++---
src/public/app/widgets/type_widgets/editable_text.js | 8 ++++----
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/src/public/app/services/note_autocomplete.ts b/src/public/app/services/note_autocomplete.ts
index 7a6cc7eb3..18311733b 100644
--- a/src/public/app/services/note_autocomplete.ts
+++ b/src/public/app/services/note_autocomplete.ts
@@ -322,9 +322,7 @@ function init() {
$.fn.setSelectedNotePath = function (notePath) {
notePath = notePath || "";
-
$(this).attr(SELECTED_NOTE_PATH_KEY, notePath);
-
$(this).closest(".input-group").find(".go-to-selected-note-button").toggleClass("disabled", !notePath.trim()).attr("href", `#${notePath}`); // we also set href here so tooltip can be displayed
};
@@ -336,11 +334,9 @@ function init() {
}
};
- $.fn.setSelectedExternalLink = function (externalLink) {
- if (externalLink) {
- // TODO: This doesn't seem to do anything with the external link, is it normal?
- $(this).closest(".input-group").find(".go-to-selected-note-button").toggleClass("disabled", true);
- }
+ $.fn.setSelectedExternalLink = function (externalLink: string | null) {
+ $(this).attr(SELECTED_EXTERNAL_LINK_KEY, externalLink);
+ $(this).closest(".input-group").find(".go-to-selected-note-button").toggleClass("disabled", true);
};
$.fn.setNote = async function (noteId) {
diff --git a/src/public/app/widgets/dialogs/add_link.ts b/src/public/app/widgets/dialogs/add_link.ts
index 36855b015..ba994a1f2 100644
--- a/src/public/app/widgets/dialogs/add_link.ts
+++ b/src/public/app/widgets/dialogs/add_link.ts
@@ -88,13 +88,13 @@ export default class AddLinkDialog extends BasicWidget {
if (this.$autoComplete.getSelectedNotePath()) {
this.$widget.modal("hide");
- const linkTitle = this.getLinkType() === "reference-link" ? null : this.$linkTitle.val() as string;
+ const linkTitle = this.getLinkType() === "reference-link" ? null : this.$linkTitle.val();
this.textTypeWidget?.addLink(this.$autoComplete.getSelectedNotePath()!, linkTitle);
} else if (this.$autoComplete.getSelectedExternalLink()) {
this.$widget.modal("hide");
- this.textTypeWidget?.addLink(this.$autoComplete.getSelectedExternalLink()!, this.$linkTitle.val() as string);
+ this.textTypeWidget?.addLink(this.$autoComplete.getSelectedExternalLink()!, this.$linkTitle.val(), true);
} else {
logError("No link to add.");
}
@@ -149,7 +149,6 @@ export default class AddLinkDialog extends BasicWidget {
});
this.$autoComplete.on("autocomplete:externallinkselected", (event: JQuery.Event, suggestion: Suggestion) => {
- console.log("autocomplete:externallinkselected", event, suggestion);
if (!suggestion.externalLink) {
return false;
}
diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js
index c5f2df34b..3dca4f85e 100644
--- a/src/public/app/widgets/type_widgets/editable_text.js
+++ b/src/public/app/widgets/type_widgets/editable_text.js
@@ -290,7 +290,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
this.watchdog?.editor.editing.view.focus();
}
- show() {}
+ show() { }
getEditor() {
return this.watchdog?.editor;
@@ -337,14 +337,14 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
this.addTextToEditor(text);
}
- async addLink(notePath, linkTitle) {
+ async addLink(notePath, linkTitle, externalLink = false) {
await this.initialized;
if (linkTitle) {
if (this.hasSelection()) {
- this.watchdog.editor.execute("link", `#${notePath}`);
+ this.watchdog.editor.execute("link", externalLink ? `${notePath}` : `#${notePath}`);
} else {
- await this.addLinkToEditor(`#${notePath}`, linkTitle);
+ await this.addLinkToEditor(externalLink ? `${notePath}` : `#${notePath}`, linkTitle);
}
} else {
this.watchdog.editor.execute("referenceLink", { href: "#" + notePath });
From f1ecab84d9d203f6b85b8e68f1b30bc6d9277371 Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Tue, 4 Mar 2025 00:35:29 +0100
Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20remove=20unused?=
=?UTF-8?q?=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/public/app/widgets/dialogs/add_link.ts | 4 ----
1 file changed, 4 deletions(-)
diff --git a/src/public/app/widgets/dialogs/add_link.ts b/src/public/app/widgets/dialogs/add_link.ts
index ba994a1f2..4d8f416f4 100644
--- a/src/public/app/widgets/dialogs/add_link.ts
+++ b/src/public/app/widgets/dialogs/add_link.ts
@@ -11,10 +11,6 @@ interface NoteAutocompleteElement extends HTMLElement {
getSelectedExternalLink(): string | null;
}
-interface NoteAutocompleteEvent extends Event {
- suggestion: Suggestion;
-}
-
const TPL = `
From c4d2c2b8deff75d9245787f0d3dbe1a7964361e3 Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Tue, 4 Mar 2025 00:42:29 +0100
Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20remove=20redunda?=
=?UTF-8?q?nt=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/public/app/widgets/dialogs/add_link.ts | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/public/app/widgets/dialogs/add_link.ts b/src/public/app/widgets/dialogs/add_link.ts
index 4d8f416f4..fff519a1e 100644
--- a/src/public/app/widgets/dialogs/add_link.ts
+++ b/src/public/app/widgets/dialogs/add_link.ts
@@ -6,11 +6,6 @@ import BasicWidget from "../basic_widget.js";
import type { Suggestion } from "../../services/note_autocomplete.js";
import type { default as TextTypeWidget } from "../type_widgets/editable_text.js";
-interface NoteAutocompleteElement extends HTMLElement {
- getSelectedNotePath(): string | null;
- getSelectedExternalLink(): string | null;
-}
-
const TPL = `
@@ -64,7 +59,7 @@ const TPL = `
export default class AddLinkDialog extends BasicWidget {
private $form!: JQuery
;
- private $autoComplete!: JQuery;
+ private $autoComplete!: JQuery;
private $linkTitle!: JQuery;
private $addLinkTitleSettings!: JQuery;
private $addLinkTitleRadios!: JQuery;
From d4fe8cf4b95c69ac346faca8f7645cd6130ee970 Mon Sep 17 00:00:00 2001
From: Jin <22962980+JYC333@users.noreply.github.com>
Date: Wed, 5 Mar 2025 12:44:36 +0100
Subject: [PATCH 6/6] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20add=20event=20da?=
=?UTF-8?q?ta=20and=20remove=20redundant=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/public/app/components/app_context.ts | 13 +++++++++----
src/public/app/widgets/dialogs/about.ts | 4 ++--
src/public/app/widgets/dialogs/add_link.ts | 3 ++-
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/public/app/components/app_context.ts b/src/public/app/components/app_context.ts
index e06ee5dd7..69b153661 100644
--- a/src/public/app/components/app_context.ts
+++ b/src/public/app/components/app_context.ts
@@ -23,6 +23,7 @@ import type { Attribute } from "../services/attribute_parser.js";
import type NoteTreeWidget from "../widgets/note_tree.js";
import type { default as NoteContext, GetTextEditorCallback } from "./note_context.js";
import type TypeWidget from "../widgets/type_widgets/type_widget.js";
+import type EditableTextTypeWidget from "../widgets/type_widgets/editable_text.js";
interface Layout {
getRootWidget: (appContext: AppContext) => RootWidget;
@@ -131,10 +132,10 @@ export type CommandMappings = {
protectSubtree: ContextMenuCommandData;
unprotectSubtree: ContextMenuCommandData;
openBulkActionsDialog:
- | ContextMenuCommandData
- | {
- selectedOrActiveNoteIds?: string[];
- };
+ | ContextMenuCommandData
+ | {
+ selectedOrActiveNoteIds?: string[];
+ };
editBranchPrefix: ContextMenuCommandData;
convertNoteToAttachment: ContextMenuCommandData;
duplicateSubtree: ContextMenuCommandData;
@@ -361,6 +362,10 @@ type EventMappings = {
relationMapResetZoomIn: { ntxId: string | null | undefined };
relationMapResetZoomOut: { ntxId: string | null | undefined };
activeNoteChangedEvent: {};
+ showAddLinkDialog: {
+ textTypeWidget: EditableTextTypeWidget;
+ text: string;
+ };
};
export type EventListener = {
diff --git a/src/public/app/widgets/dialogs/about.ts b/src/public/app/widgets/dialogs/about.ts
index f77f67372..790e5e578 100644
--- a/src/public/app/widgets/dialogs/about.ts
+++ b/src/public/app/widgets/dialogs/about.ts
@@ -83,7 +83,7 @@ export default class AboutDialog extends BasicWidget {
this.$dataDirectory = this.$widget.find(".data-directory");
}
- async refresh(): Promise {
+ async refresh() {
const appInfo = await server.get("app-info");
this.$appVersion.text(appInfo.appVersion);
@@ -109,7 +109,7 @@ export default class AboutDialog extends BasicWidget {
}
}
- async openAboutDialogEvent(): Promise {
+ async openAboutDialogEvent() {
await this.refresh();
utils.openDialog(this.$widget);
}
diff --git a/src/public/app/widgets/dialogs/add_link.ts b/src/public/app/widgets/dialogs/add_link.ts
index fff519a1e..2a987d3ff 100644
--- a/src/public/app/widgets/dialogs/add_link.ts
+++ b/src/public/app/widgets/dialogs/add_link.ts
@@ -5,6 +5,7 @@ import utils from "../../services/utils.js";
import BasicWidget from "../basic_widget.js";
import type { Suggestion } from "../../services/note_autocomplete.js";
import type { default as TextTypeWidget } from "../type_widgets/editable_text.js";
+import type { EventData } from "../../components/app_context.js";
const TPL = `
@@ -94,7 +95,7 @@ export default class AddLinkDialog extends BasicWidget {
});
}
- async showAddLinkDialogEvent({ textTypeWidget, text = "" }: { textTypeWidget: TextTypeWidget; text: string }) {
+ async showAddLinkDialogEvent({ textTypeWidget, text = "" }: EventData<"showAddLinkDialog">) {
this.textTypeWidget = textTypeWidget;
this.$addLinkTitleSettings.toggle(!this.textTypeWidget.hasSelection());