mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
implement ui-registry for dynamic UI handler registration
This commit is contained in:
@@ -41,8 +41,8 @@
|
||||
<div id="ignis-status-label">Loading Obsidian...</div>
|
||||
</div>
|
||||
<!-- Ignis shims: must run before any Obsidian code. -->
|
||||
<script type="text/javascript" src="__IGNIS_UI_SRC__"></script>
|
||||
<script type="text/javascript" src="__SHIM_LOADER_SRC__"></script>
|
||||
<script type="text/javascript" src="__IGNIS_UI_SRC__"></script>
|
||||
<!-- Obsidian scripts injected dynamically to avoid touching their files. -->
|
||||
<script>
|
||||
(function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { showVaultManager } from "../../ui/bootstrap.js";
|
||||
import { showVaultManager } from "../ui-registry.js";
|
||||
import { vaultService } from "../../services/vault-service.js";
|
||||
|
||||
const listeners = new Map();
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
showMessageDialog,
|
||||
showConfirmDialog,
|
||||
showPromptDialog,
|
||||
} from "../../../ui/bootstrap.js";
|
||||
} from "../../ui-registry.js";
|
||||
import { inputCacheSet, inputCacheDelete } from "../../fs/input-cache.js";
|
||||
|
||||
const IMPORTS_DIR = ".obsidian/imports";
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
registerPopupWindow,
|
||||
unregisterPopupWindow,
|
||||
} from "./electron/remote/window.js";
|
||||
import { showVaultManager } from "../ui/bootstrap.js";
|
||||
import { showVaultManager } from "./ui-registry.js";
|
||||
|
||||
function installProcess() {
|
||||
window.process = processShim;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { fsShim } from "./fs/index.js";
|
||||
import { installRequestUrlShim } from "./request-url.js";
|
||||
import { vaultService } from "../services/vault-service.js";
|
||||
import { showPluginInstallDialog } from "../ui/bootstrap.js";
|
||||
import { showPluginInstallDialog } from "./ui-registry.js";
|
||||
import { registerReadTransform } from "./fs/transforms.js";
|
||||
import {
|
||||
resolveWorkspaceName,
|
||||
|
||||
@@ -3,9 +3,11 @@ import { installGlobals } from "./globals.js";
|
||||
import { installCssOverrides } from "./css-overrides.js";
|
||||
import { initialize } from "./init.js";
|
||||
import { fsShim } from "./fs/index.js";
|
||||
import { registerUI } from "./ui-registry.js";
|
||||
|
||||
// __IGNIS_VERSION__ is replaced at build time from package.json.
|
||||
window.__ignis = { version: __IGNIS_VERSION__ };
|
||||
window.__ignis_registerUI = registerUI;
|
||||
|
||||
installGlobals(); // process, Buffer, window overrides (before require so Buffer is available)
|
||||
installRequire(); // shim registry, window.require
|
||||
|
||||
26
src/shims/ui-registry.js
Normal file
26
src/shims/ui-registry.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// Use a runtime registry to avoid bloating bundles with imported component code.
|
||||
|
||||
let handlers = {};
|
||||
|
||||
export function registerUI(impls) {
|
||||
handlers = { ...handlers, ...impls };
|
||||
}
|
||||
|
||||
function proxy(name) {
|
||||
return (...args) => {
|
||||
const fn = handlers[name];
|
||||
|
||||
if (typeof fn !== "function") {
|
||||
console.warn(`[ignis] UI handler '${name}' not registered`);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return fn(...args);
|
||||
};
|
||||
}
|
||||
|
||||
export const showVaultManager = proxy("showVaultManager");
|
||||
export const showMessageDialog = proxy("showMessageDialog");
|
||||
export const showConfirmDialog = proxy("showConfirmDialog");
|
||||
export const showPluginInstallDialog = proxy("showPluginInstallDialog");
|
||||
export const showPromptDialog = proxy("showPromptDialog");
|
||||
24
src/ui/bootstrap.js
vendored
24
src/ui/bootstrap.js
vendored
@@ -1,6 +1,6 @@
|
||||
import { vaultService } from "../services/vault-service.js";
|
||||
|
||||
export function showVaultManager() {
|
||||
function showVaultManager() {
|
||||
if (document.querySelector(".vault-manager-overlay")) return;
|
||||
|
||||
new window.IgnisUI.VaultManager({
|
||||
@@ -9,7 +9,7 @@ export function showVaultManager() {
|
||||
});
|
||||
}
|
||||
|
||||
export function showMessageDialog(title, message) {
|
||||
function showMessageDialog(title, message) {
|
||||
return new Promise((resolve) => {
|
||||
const dialog = new window.IgnisUI.MessageDialog({
|
||||
target: document.body,
|
||||
@@ -23,7 +23,7 @@ export function showMessageDialog(title, message) {
|
||||
});
|
||||
}
|
||||
|
||||
export function showConfirmDialog(
|
||||
function showConfirmDialog(
|
||||
title,
|
||||
message,
|
||||
description,
|
||||
@@ -47,7 +47,7 @@ export function showConfirmDialog(
|
||||
});
|
||||
}
|
||||
|
||||
export function showPluginInstallDialog(vaultId) {
|
||||
function showPluginInstallDialog(vaultId) {
|
||||
return new Promise((resolve) => {
|
||||
const dialog = new window.IgnisUI.PluginInstallDialog({
|
||||
target: document.body,
|
||||
@@ -83,7 +83,7 @@ export function showPluginInstallDialog(vaultId) {
|
||||
});
|
||||
}
|
||||
|
||||
export function showPromptDialog(
|
||||
function showPromptDialog(
|
||||
title,
|
||||
label,
|
||||
placeholder = "",
|
||||
@@ -107,3 +107,17 @@ export function showPromptDialog(
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined" && window.__ignis_registerUI) {
|
||||
window.__ignis_registerUI({
|
||||
showVaultManager,
|
||||
showMessageDialog,
|
||||
showConfirmDialog,
|
||||
showPluginInstallDialog,
|
||||
showPromptDialog,
|
||||
});
|
||||
} else if (typeof window !== "undefined") {
|
||||
console.warn(
|
||||
"[ignis] __ignis_registerUI not available; UI handlers not registered",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import "./bootstrap.js";
|
||||
|
||||
export { default as VaultManager } from "./views/VaultManager.svelte";
|
||||
export { default as MessageDialog } from "./components/layout/MessageDialog.svelte";
|
||||
export { default as ConfirmDialog } from "./components/layout/ConfirmDialog.svelte";
|
||||
|
||||
Reference in New Issue
Block a user