mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
mobile: add support in editor to fetch internal link data
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
4
apps/mobile/package-lock.json
generated
4
apps/mobile/package-lock.json
generated
@@ -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": {
|
||||
|
||||
2
packages/editor-mobile/package-lock.json
generated
2
packages/editor-mobile/package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user