h-sphere_sql-seal/src/modules/api/init.ts
Kacper Kula 285684dfc4
Refactoring Project to use proper Inversion of Control (#171)
* chore: reworking plugin internals into modules

* feat: settings module is now working, added debug module, enabled new api module

* chore: restoring external API

* feat: refactoring project to use proper inversion of control

* feat: plugins can now be loaded in any order

* chore: final file migration, all typescript is in modules now

* chore: fixing dependencies of cellParser

* feat: csv and json views are only registered when they are not colliding with other plugins

* feat: fixed library behaviour on canvas
2025-08-10 09:34:54 +01:00

55 lines
1.3 KiB
TypeScript

import { Plugin } from "obsidian";
import {
PluginRegister,
SQLSealApi,
SQLSealRegisterApi,
} from "./pluginApi/sqlSealApi";
import { makeInjector } from "@hypersphere/dity";
import { ApiModule } from "./module";
import { RendererRegistry } from "../editor/renderer/rendererRegistry";
import { SqlSealDatabase } from "../database/database";
import { ModernCellParser } from "../syntaxHighlight/cellParser/ModernCellParser";
const SQLSEAL_API_KEY = "___sqlSeal";
const SQLSEAL_QUEUED_PLUGINS = "___sqlSeal_queue";
@(makeInjector<ApiModule, "factory">()([
"plugin",
"cellParser",
"rendererRegistry",
"db",
]))
export class ApiInit {
make(
plugin: Plugin,
cellParser: ModernCellParser,
rendererRegistry: RendererRegistry,
db: SqlSealDatabase,
) {
return () => {
const api = new SQLSealRegisterApi(
plugin,
cellParser,
rendererRegistry,
db,
);
(window as any)[SQLSEAL_API_KEY] = api;
plugin.register(() => {
delete (window as any)[SQLSEAL_API_KEY];
});
const queuedPlugins = (window as any)[SQLSEAL_QUEUED_PLUGINS] as
| PluginRegister[]
| undefined;
if (!queuedPlugins) {
return;
}
queuedPlugins.forEach((pl) => {
api.registerForPluginNew(pl);
});
(window as any)[SQLSEAL_QUEUED_PLUGINS] = [];
};
}
}