A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: add support in editor to fetch internal link data
Ammar Ahmed17864d332528
diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsxindex 1ff17d92a..b44d9318d 100644--- a/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx+++ b/apps/mobile/app/screens/editor/tiptap/use-editor-events.tsx@@ -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;diff --git a/apps/mobile/package-lock.json b/apps/mobile/package-lock.jsonindex 178caacf8..e4b1b2813 100644--- a/apps/mobile/package-lock.json+++ b/apps/mobile/package-lock.json@@ -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": {diff --git a/packages/editor-mobile/package-lock.json b/packages/editor-mobile/package-lock.jsonindex 24441ca6c..7c735f048 100644--- a/packages/editor-mobile/package-lock.json+++ b/packages/editor-mobile/package-lock.json@@ -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",diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsxindex 697893636..66893f6cf 100644--- a/packages/editor-mobile/src/components/editor.tsx+++ b/packages/editor-mobile/src/components/editor.tsx@@ -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, {attributesdiff --git a/packages/editor-mobile/src/utils/editor-events.ts b/packages/editor-mobile/src/utils/editor-events.tsindex 83b8da698..c69673eb9 100644--- a/packages/editor-mobile/src/utils/editor-events.ts+++ b/packages/editor-mobile/src/utils/editor-events.ts@@ -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;