Skip to content

Open source personal finance application

feat(settings): add extension slot for layers

Ilya Komichev112b5bf33eb2
diff --git a/app/app/components/ExtensionSlot.vue b/app/app/components/ExtensionSlot.vue
new file mode 100644
index 00000000..f01a5a0e
--- /dev/null
+++ b/app/app/components/ExtensionSlot.vue
@@ -0,0 +1,18 @@
+<script setup lang="ts">
+// Renders every extension registered for `name` (see useExtensions). Each is
+// wrapped in an error boundary so a broken extension from a layer can never
+// take down the host page.
+const { name } = defineProps<{ name: string }>()
+
+const extensions = useExtensions(name)
+</script>
+
+<template>
+ <NuxtErrorBoundary
+ v-for="ext in extensions"
+ :key="ext.id"
+ >
+ <component :is="ext.component" />
+ <template #error />
+ </NuxtErrorBoundary>
+</template>
diff --git a/app/app/composables/useExtensions.ts b/app/app/composables/useExtensions.ts
new file mode 100644
index 00000000..a05d7a9d
--- /dev/null
+++ b/app/app/composables/useExtensions.ts
@@ -0,0 +1,40 @@
+import type { Component } from 'vue'
+
+// Extension points for layers built on top of this app (e.g. premium). A layer
+// registers components into a named slot from a plugin; host pages render the
+// slot via <ExtensionSlot name="..." />. The base app ships no extensions, so a
+// slot renders nothing unless a layer fills it.
+
+export type Extension = {
+ component: Component
+ // Stable id - registration is idempotent (survives HMR / plugin re-runs).
+ id: string
+ // Lower renders first. Native cards aren't in the registry; pick a value
+ // relative to where the <ExtensionSlot> sits on the page. Default 100.
+ order?: number
+ // Optional extra gate, evaluated reactively. The component's own per-user
+ // gating (if any) still applies on top of this.
+ visible?: () => boolean
+}
+
+// Session-lifetime singleton (SPA, one client). reactive() so a registration
+// that lands after a slot has mounted still updates the view.
+const registry = reactive(new Map<string, Map<string, Extension>>())
+
+export function registerExtension(slot: string, extension: Extension): void {
+ if (!registry.has(slot))
+ registry.set(slot, new Map())
+ // Keyed by id, so registering the same extension twice is a no-op overwrite.
+ registry.get(slot)!.set(extension.id, extension)
+}
+
+export function useExtensions(slot: string) {
+ return computed<Extension[]>(() => {
+ const bucket = registry.get(slot)
+ if (!bucket)
+ return []
+ return [...bucket.values()]
+ .filter(e => (e.visible ? e.visible() : true))
+ .sort((a, b) => (a.order ?? 100) - (b.order ?? 100))
+ })
+}
diff --git a/app/app/pages/settings.vue b/app/app/pages/settings.vue
index 7ecd7370..df224f85 100644
--- a/app/app/pages/settings.vue
+++ b/app/app/pages/settings.vue
@@ -83,6 +83,9 @@ function onGenerateDemoData() {
</button>
</UiSettingsCard>
+ <!-- Extension point for layers (e.g. premium Telegram card) -->
+ <ExtensionSlot name="settings" />
+
<!-- Demo -->
<UiSettingsCard
v-if="isDemo"