From 280a958a7fe08b23d48d96111b492593099c7938 Mon Sep 17 00:00:00 2001 From: Load-Ma Date: Sun, 8 Dec 2024 19:52:16 +0100 Subject: [PATCH 1/2] fix(IOS-compatibility): replacing events package by native EventTarget package --- manifest.json | 2 +- obsidian-folder-index.md | 5 ++++ package-lock.json | 4 +-- package.json | 4 +-- src/main.ts | 5 ++-- src/models/models.md | 5 ++++ src/modules/CustomEventTarget.ts | 46 ++++++++++++++++++++++++++++++++ src/modules/modules.md | 5 ++++ src/src.md | 5 ++++ src/types/types.md | 5 ++++ 10 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 obsidian-folder-index.md create mode 100644 src/models/models.md create mode 100644 src/modules/CustomEventTarget.ts create mode 100644 src/modules/modules.md create mode 100644 src/src.md create mode 100644 src/types/types.md diff --git a/manifest.json b/manifest.json index 42b416d..fed0bf0 100644 --- a/manifest.json +++ b/manifest.json @@ -8,4 +8,4 @@ "fundingUrl": "https://www.buymeacoffee.com/turulix", "isDesktopOnly": false, "version": "1.0.27" -} \ No newline at end of file +} diff --git a/obsidian-folder-index.md b/obsidian-folder-index.md new file mode 100644 index 0000000..3f049af --- /dev/null +++ b/obsidian-folder-index.md @@ -0,0 +1,5 @@ +--- +tags: MOCs +--- +```folder-index-content +``` \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3528d6e..8256fb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-sample-plugin", - "version": "1.0.22", + "version": "1.0.27", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "obsidian-sample-plugin", - "version": "1.0.22", + "version": "1.0.27", "license": "MIT", "devDependencies": { "@types/node": "16.11.6", diff --git a/package.json b/package.json index d7a210a..0206ff1 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,9 @@ "@typescript-eslint/parser": "5.2.0", "builtin-modules": "3.2.0", "esbuild": "0.13.12", + "eslint": "8.14.0", "obsidian": "latest", "tslib": "2.3.1", - "typescript": "4.4.4", - "eslint": "8.14.0" + "typescript": "4.4.4" } } diff --git a/src/main.ts b/src/main.ts index b728beb..dcb4515 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,10 @@ import {App, Plugin, PluginManifest} from 'obsidian'; import {IndexContentProcessorModule} from "./modules/IndexContentProcessorModule"; import {GraphManipulatorModule} from "./modules/GraphManipulatorModule"; -import {EventEmitter} from "events"; import {DEFAULT_SETTINGS, PluginSetting, PluginSettingsTab} from "./models/PluginSettingsTab"; import {FolderNoteModule} from "./modules/FolderNoteModule"; import {ContextMenuModule} from "./modules/ContextMenuModule"; - +import CustomEventTarget from "./modules/CustomEventTarget"; // Remember to rename these classes and interfaces! export default class FolderIndexPlugin extends Plugin { @@ -30,7 +29,7 @@ export default class FolderIndexPlugin extends Plugin { async onload() { // eslint-disable-next-line no-console console.log("Loading FolderTableContent") - this.eventManager = new EventEmitter() + this.eventManager = new CustomEventTarget() await this.loadSettings(); diff --git a/src/models/models.md b/src/models/models.md new file mode 100644 index 0000000..3f049af --- /dev/null +++ b/src/models/models.md @@ -0,0 +1,5 @@ +--- +tags: MOCs +--- +```folder-index-content +``` \ No newline at end of file diff --git a/src/modules/CustomEventTarget.ts b/src/modules/CustomEventTarget.ts new file mode 100644 index 0000000..ae97e03 --- /dev/null +++ b/src/modules/CustomEventTarget.ts @@ -0,0 +1,46 @@ +export default class CustomEventTarget extends EventTarget { + // Map to track all listeners for each event name + private listenersMap: Map = new Map(); + + emit(eventName: string, detail?: T): void { + const event = new CustomEvent(eventName, {detail}); + this.dispatchEvent(event); + } + + on(eventName: string, callback: (event: CustomEvent) => void): void { + // @ts-ignore + this.addEventListener(eventName, callback); + + // Track the listener in our map + const listeners = this.listenersMap.get(eventName) || []; + // @ts-ignore + listeners.push(callback); + this.listenersMap.set(eventName, listeners); + } + + removeAllListeners(): void { + for (const [eventName, listeners] of this.listenersMap.entries()) { + for (const listener of listeners) { + this.removeEventListener(eventName, listener); + } + } + + this.listenersMap.clear(); + } + + off(eventName: string, callback: (event: CustomEvent) => void): void { + const listeners = this.listenersMap.get(eventName); + // remove the listener we set to "off" + if (listeners) { + // @ts-ignore + const listenerIndex = listeners.indexOf(callback); + if (listenerIndex !== -1) { + // @ts-ignore + this.removeEventListener(eventName, callback); + + listeners.splice(listenerIndex, 1); + this.listenersMap.set(eventName, listeners); + } + } + } +} diff --git a/src/modules/modules.md b/src/modules/modules.md new file mode 100644 index 0000000..3f049af --- /dev/null +++ b/src/modules/modules.md @@ -0,0 +1,5 @@ +--- +tags: MOCs +--- +```folder-index-content +``` \ No newline at end of file diff --git a/src/src.md b/src/src.md new file mode 100644 index 0000000..3f049af --- /dev/null +++ b/src/src.md @@ -0,0 +1,5 @@ +--- +tags: MOCs +--- +```folder-index-content +``` \ No newline at end of file diff --git a/src/types/types.md b/src/types/types.md new file mode 100644 index 0000000..3f049af --- /dev/null +++ b/src/types/types.md @@ -0,0 +1,5 @@ +--- +tags: MOCs +--- +```folder-index-content +``` \ No newline at end of file From 7ddd7681bea7e4615c890ab032e62a5949b8bafe Mon Sep 17 00:00:00 2001 From: Load-Ma Date: Tue, 10 Dec 2024 18:15:27 +0100 Subject: [PATCH 2/2] fix(IOS-compatibility): removing .md files --- obsidian-folder-index.md | 5 ----- src/models/models.md | 5 ----- src/modules/modules.md | 5 ----- src/src.md | 5 ----- src/types/types.md | 5 ----- 5 files changed, 25 deletions(-) delete mode 100644 obsidian-folder-index.md delete mode 100644 src/models/models.md delete mode 100644 src/modules/modules.md delete mode 100644 src/src.md delete mode 100644 src/types/types.md diff --git a/obsidian-folder-index.md b/obsidian-folder-index.md deleted file mode 100644 index 3f049af..0000000 --- a/obsidian-folder-index.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -tags: MOCs ---- -```folder-index-content -``` \ No newline at end of file diff --git a/src/models/models.md b/src/models/models.md deleted file mode 100644 index 3f049af..0000000 --- a/src/models/models.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -tags: MOCs ---- -```folder-index-content -``` \ No newline at end of file diff --git a/src/modules/modules.md b/src/modules/modules.md deleted file mode 100644 index 3f049af..0000000 --- a/src/modules/modules.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -tags: MOCs ---- -```folder-index-content -``` \ No newline at end of file diff --git a/src/src.md b/src/src.md deleted file mode 100644 index 3f049af..0000000 --- a/src/src.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -tags: MOCs ---- -```folder-index-content -``` \ No newline at end of file diff --git a/src/types/types.md b/src/types/types.md deleted file mode 100644 index 3f049af..0000000 --- a/src/types/types.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -tags: MOCs ---- -```folder-index-content -``` \ No newline at end of file