From 43042deec98493990ea3203ce39fde4e142cefb8 Mon Sep 17 00:00:00 2001 From: Doug Stephen Date: Mon, 17 Feb 2025 14:05:18 -0600 Subject: [PATCH 1/3] feat: Add obisidian API's free functions to API Adds the obsidian free functions to the `app` object under the `functions` object. --- src/main.ts | 15 +++++++++++++++ src/typings/obsidian-ex.d.ts | 1 + 2 files changed, 16 insertions(+) diff --git a/src/main.ts b/src/main.ts index 936aabb2e..325c2093a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,8 @@ import { createElement, render } from "preact"; import { DEFAULT_SETTINGS, Settings } from "settings"; import { IndexStatusBar } from "ui/index-status"; +import * as _Obsidian from "obsidian"; + /** Reactive data engine for your Obsidian.md vault. */ export default class DatacorePlugin extends Plugin { /** Plugin-wide default settings. */ @@ -17,6 +19,19 @@ export default class DatacorePlugin extends Plugin { public api: DatacoreApi; async onload() { + const obsidianFreeFunctions: Record = {}; + for (const property in _Obsidian) { + const mod = _Obsidian as Record; + if (mod[property] && typeof mod[property] === "function") { + const fun = mod[property]; + const isClass = !!Object.keys(fun.prototype).length || /^[A-Z]/.test(property); + if (!isClass) { + obsidianFreeFunctions[property] = fun; + } + } + } + this.app.functions = obsidianFreeFunctions; + this.settings = Object.assign({}, DEFAULT_SETTINGS, (await this.loadData()) ?? {}); this.addSettingTab(new GeneralSettingsTab(this.app, this)); diff --git a/src/typings/obsidian-ex.d.ts b/src/typings/obsidian-ex.d.ts index 80ce8d328..2d8ffab2a 100644 --- a/src/typings/obsidian-ex.d.ts +++ b/src/typings/obsidian-ex.d.ts @@ -17,6 +17,7 @@ declare module "obsidian" { } interface App { appId?: string; + functions: Record; plugins: { enabledPlugins: Set; plugins: { From 50e4bdfeeee05f7d9ab96ba3eeb1969c4fdd00ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Thu, 22 Jan 2026 16:44:54 -0500 Subject: [PATCH 2/3] Update src/main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 325c2093a..21075c153 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,7 @@ export default class DatacorePlugin extends Plugin { } } } - this.app.functions = obsidianFreeFunctions; + window.obsidian = obsidianFreeFunctions; this.settings = Object.assign({}, DEFAULT_SETTINGS, (await this.loadData()) ?? {}); this.addSettingTab(new GeneralSettingsTab(this.app, this)); From 69a95c27c230d921eaab6b0067b9e7b5e2001b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Thu, 22 Jan 2026 16:50:50 -0500 Subject: [PATCH 3/3] update main.ts --- src/main.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/main.ts b/src/main.ts index d7fae0cc4..9c430ec35 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import { Datacore } from "index/datacore"; import { DateTime } from "luxon"; import { App, Plugin, PluginSettingTab, Setting } from "obsidian"; import { DEFAULT_SETTINGS, Settings } from "settings"; +import * as _obsidian from "obsidian"; /** @internal Reactive data engine for your Obsidian.md vault. */ export default class DatacorePlugin extends Plugin { @@ -15,18 +16,8 @@ export default class DatacorePlugin extends Plugin { public api: DatacoreApi; async onload() { - const obsidianFreeFunctions: Record = {}; - for (const property in _Obsidian) { - const mod = _Obsidian as Record; - if (mod[property] && typeof mod[property] === "function") { - const fun = mod[property]; - const isClass = !!Object.keys(fun.prototype).length || /^[A-Z]/.test(property); - if (!isClass) { - obsidianFreeFunctions[property] = fun; - } - } - } - window.obsidian = obsidianFreeFunctions; + + window.obsidian = _obsidian; this.settings = Object.assign({}, DEFAULT_SETTINGS, (await this.loadData()) ?? {}); this.addSettingTab(new GeneralSettingsTab(this.app, this));