mobile: add support in editor to fetch internal link data

This commit is contained in:
Ammar Ahmed
2026-04-02 13:32:03 +05:00
parent 47b2569b29
commit 17864d3325
5 changed files with 65 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* eslint-disable no-case-declarations */
/* eslint-disable @typescript-eslint/no-var-requires */
import { isFeatureAvailable, useAreFeaturesAvailable } from "@notesnook/common";
import { ItemReference } from "@notesnook/core";
import { ItemReference, parseInternalLink } from "@notesnook/core";
import type { Attachment } from "@notesnook/editor";
import { EditorEvents } from "@notesnook/editor-mobile/src/utils/editor-events";
import { NativeEvents } from "@notesnook/editor-mobile/src/utils/native-events";
@@ -471,9 +471,8 @@ export const useEditorEvents = (
relationType: "from",
title: strings.dataTypesPluralCamelCase.reminder(),
onAdd: async () => {
const reminderFeature = await isFeatureAvailable(
"activeReminders"
);
const reminderFeature =
await isFeatureAvailable("activeReminders");
if (!reminderFeature.isAllowed) {
ToastManager.show({
type: "info",
@@ -533,7 +532,59 @@ export const useEditorEvents = (
downloadAttachment((editorMessage.value as Attachment)?.hash, true);
break;
}
case EditorEvents.getLinkData: {
const url = (editorMessage.value as any)?.url as string;
const link = parseInternalLink(url);
if (!link) return;
switch (link.type) {
case "note":
case "notebook":
case "tag": {
const table =
link.type === "note"
? "notes"
: link.type === "notebook"
? "notebooks"
: "tags";
const item = await db
.sql()
.selectFrom(table)
.where("id", "=", link.id)
.select("title")
.executeTakeFirst();
editor.postMessage(NativeEvents.resolve, {
resolverId: editorMessage.resolverId,
data: {
type: link.type,
title: item?.title || ""
}
});
break;
}
case "color": {
const color = await db
.sql()
.selectFrom("colors")
.where("id", "=", link.id)
.select(["title", "colorCode"])
.executeTakeFirst();
editor.postMessage(NativeEvents.resolve, {
resolverId: editorMessage.resolverId,
data: {
type: "color",
title: color?.title || "",
metadata: {
colorCode: color?.colorCode || ""
}
}
});
}
}
break;
}
case EditorEvents.getAttachmentData: {
const data = (editorMessage.value as any)?.attachment as Attachment;

View File

@@ -1,12 +1,12 @@
{
"name": "@notesnook/mobile",
"version": "3.3.17",
"version": "3.3.18",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@notesnook/mobile",
"version": "3.3.17",
"version": "3.3.18",
"hasInstallScript": true,
"license": "GPL-3.0-or-later",
"dependencies": {

View File

@@ -68,7 +68,7 @@
"@notesnook/intl": "file:../intl",
"@notesnook/theme": "file:../theme",
"@notesnook/ui": "file:../ui",
"@social-embed/lib": "^0.1.0-next.7",
"@social-embed/lib": "^0.1.0-next.11",
"@tiptap/core": "2.6.6",
"@tiptap/extension-blockquote": "^2.6.6",
"@tiptap/extension-bullet-list": "^2.6.6",

View File

@@ -162,6 +162,11 @@ const Tiptap = ({
attachment
) as Promise<string | undefined>;
},
getLinkData: (url: string) => {
return postAsyncWithTimeout(EditorEvents.getLinkData, {
url: url
});
},
createInternalLink(attributes) {
return postAsyncWithTimeout(EditorEvents.createInternalLink, {
attributes

View File

@@ -55,5 +55,6 @@ export const EditorEvents = {
goForward: "editor-events:go-forward",
saveScroll: "editor-events:save-scroll",
newNote: "editor-events:new-note",
downloadCsv: "editor-events:download-csv"
downloadCsv: "editor-events:download-csv",
getLinkData: "editor-events:get-link-data"
} as const;