diff --git a/src/vue/components/GnToastProvider.js b/src/vue/components/GnToastProvider.js index c1a1163..7bb868a 100644 --- a/src/vue/components/GnToastProvider.js +++ b/src/vue/components/GnToastProvider.js @@ -5,7 +5,7 @@ * Exposes an imperative API via provide/inject and component expose. */ -import { defineComponent, h, provide, ref, nextTick } from "vue"; +import { defineComponent, h, provide, ref, nextTick, getCurrentInstance } from "vue"; import { cx, iconNode, normalizeVariant } from "../utils.js"; import { toastKey } from "../composables/toast-context.js"; @@ -110,6 +110,11 @@ provide(toastKey, api); expose(api); + const instance = getCurrentInstance(); + if (instance?.appContext?.app?.config?.globalProperties) { + instance.appContext.app.config.globalProperties.$vmkToasts = api; + } + const toastClass = () => { if (closing.value) return "a-hide"; if (showing.value) return "a-show"; diff --git a/src/vue/composables/toast-context.js b/src/vue/composables/toast-context.js index 7f008ce..6c08c6c 100644 --- a/src/vue/composables/toast-context.js +++ b/src/vue/composables/toast-context.js @@ -2,4 +2,4 @@ * Injection key for the toast API provided by GnToastProvider. */ -export const toastKey = Symbol("vmk-ui-kit-toast"); +export const toastKey = Symbol.for("vmk-ui-kit-toast"); diff --git a/src/vue/composables/useToast.js b/src/vue/composables/useToast.js index d6c4aa9..6c8bc21 100644 --- a/src/vue/composables/useToast.js +++ b/src/vue/composables/useToast.js @@ -5,7 +5,7 @@ * Returns no-op placeholders with a helpful error when called outside a provider. */ -import { inject } from "vue"; +import { inject, getCurrentInstance } from "vue"; import { toastKey } from "./toast-context.js"; export function useToast() { @@ -15,6 +15,15 @@ return api; } + // Fallback: look for the provider API on the app config globalProperties + // (some consumers register the plugin globally and may not have the provider + // in the exact ancestor chain due to createApp + inline templates). + const instance = getCurrentInstance(); + const globalApi = instance?.appContext?.app?.config?.globalProperties?.$vmkToasts; + if (globalApi) { + return globalApi; + } + const missingProvider = () => { throw new Error("VMK UI Kit: useToast() requires near the app root."); }; diff --git a/src/vue/utils.js b/src/vue/utils.js index fc93f1f..cf2feb5 100644 --- a/src/vue/utils.js +++ b/src/vue/utils.js @@ -121,6 +121,33 @@ check: "essentials/check", user: "essentials/user", trash: "essentials/trash", + copy: "documents-&-safety/copy", + "chart-line-up": "banking-&-finance/chart/line", + "chart-line": "banking-&-finance/chart/line", + "check-circle": "essentials/check/circle", + "chat-circle": "messages/message/circle/3", + "chat": "messages/message/circle/3", + "message": "messages/message/circle/3", + "lock-key": "documents-&-safety/lock", + lock: "documents-&-safety/lock", + "sign-in": "essentials/enter", + login: "essentials/enter", + "sign-out": "essentials/exit", + logout: "essentials/exit", + pencil: "software/pencil/circle", + "pencil-simple": "software/pencil/circle", + edit: "software/edit/1", + house: "buildings-&-landmarks/house/1", + home: "buildings-&-landmarks/house/1", + list: "essentials/list-fill", + "credit-card": "banking-&-finance/credit-card", + bell: "essentials/notification/1", + "cloud-arrow-up": "software/cloud-upload", + "cloud-upload": "software/cloud-upload", + package: "e-commerce/box-stack", + box: "e-commerce/box-stack", + gear: "essentials/gear", + settings: "essentials/gear", information: "essentials/information/circle", info: "essentials/information/circle", alert: "essentials/alert-sign",