vue-notifyr 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
- package/src/adapters/nuxt/index.ts +3 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue")) : typeof define === "function" && define.amd ? define(["exports", "vue"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.VueNotifyr = {}, global.Vue));
|
|
3
|
-
})(this, function(exports2, vue) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("nuxt/app")) : typeof define === "function" && define.amd ? define(["exports", "vue", "nuxt/app"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.VueNotifyr = {}, global.Vue, global.app));
|
|
3
|
+
})(this, function(exports2, vue, app) {
|
|
4
4
|
"use strict";
|
|
5
5
|
const DEFAULT_OPTIONS = {
|
|
6
6
|
position: "top-center",
|
|
@@ -172,9 +172,9 @@
|
|
|
172
172
|
}
|
|
173
173
|
function createVueNotificationPlugin$1(manager = notificationManager) {
|
|
174
174
|
return {
|
|
175
|
-
install(
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
install(app2) {
|
|
176
|
+
app2.config.globalProperties.$notificationManager = manager;
|
|
177
|
+
app2.provide("notificationManager", manager);
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
180
|
}
|
|
@@ -260,14 +260,14 @@
|
|
|
260
260
|
function useNotification() {
|
|
261
261
|
return useNotificationManager();
|
|
262
262
|
}
|
|
263
|
-
defineNuxtPlugin((nuxtApp) => {
|
|
263
|
+
app.defineNuxtPlugin((nuxtApp) => {
|
|
264
264
|
nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));
|
|
265
265
|
});
|
|
266
266
|
function createVueNotificationPlugin(manager) {
|
|
267
267
|
return {
|
|
268
|
-
install(
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
install(app2) {
|
|
269
|
+
app2.config.globalProperties.$notificationManager = manager;
|
|
270
|
+
app2.provide("notificationManager", manager);
|
|
271
271
|
}
|
|
272
272
|
};
|
|
273
273
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/core/notification-manager.ts","../src/adapters/vue/index.ts","../src/adapters/vue/NotificationContainer.vue","../src/composables/useNotification.ts","../src/adapters/nuxt/index.ts"],"sourcesContent":["import type { NotificationType, NotificationOptions, NotificationItem } from '../types';\n\nconst DEFAULT_OPTIONS: Required<NotificationOptions> = {\n position: 'top-center',\n autoClose: 3000,\n progress: true,\n};\n\nexport class NotificationManager {\n private notifications: NotificationItem[] = [];\n private options: Required<NotificationOptions> = { ...DEFAULT_OPTIONS };\n private listeners: { [event: string]: Function[] } = {};\n private idCounter = 1;\n\n /**\n * Subscribe to an event.\n * @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')\n * @param callback - The callback function\n */\n on(event: string, callback: Function): void {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event].push(callback);\n }\n\n /**\n * Unsubscribe from an event.\n * @param event - The event name\n * @param callback - The callback function to remove\n */\n off(event: string, callback: Function): void {\n if (this.listeners[event]) {\n this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);\n }\n }\n\n private emit(event: string, data?: any): void {\n if (this.listeners[event]) {\n this.listeners[event].forEach((callback) => callback(data));\n }\n }\n\n /**\n * Set default options for notifications.\n * @param opts - The options to set as defaults\n */\n setDefaults(opts: NotificationOptions): void {\n this.options = { ...this.options, ...opts };\n this.emit('options-changed', this.options);\n }\n\n /**\n * Show a notification.\n * @param type - The type of notification\n * @param title - The title/message of the notification\n * @param opts - Optional override options\n */\n show(type: NotificationType, title: string, opts?: NotificationOptions): void {\n const options = { ...this.options, ...(opts || {}) };\n const item: NotificationItem = {\n id: this.idCounter++,\n type,\n title,\n options,\n createdAt: Date.now(),\n };\n this.notifications.push(item);\n this.emit('notification-added', item);\n\n if (options.autoClose !== false && typeof window !== 'undefined') {\n setTimeout(() => this.remove(item.id), options.autoClose);\n }\n }\n\n /**\n * Remove a notification by ID.\n * @param id - The ID of the notification to remove\n */\n remove(id: number): void {\n const index = this.notifications.findIndex((n) => n.id === id);\n if (index !== -1) {\n const removed = this.notifications.splice(index, 1)[0];\n this.emit('notification-removed', removed);\n }\n }\n\n /**\n * Clear all notifications.\n */\n clear(): void {\n const removed = [...this.notifications];\n this.notifications.splice(0);\n this.emit('notifications-cleared', removed);\n }\n\n /**\n * Get a copy of the current notifications.\n * @returns Array of notification items\n */\n getNotifications(): NotificationItem[] {\n return [...this.notifications];\n }\n\n /**\n * Get the current default options.\n * @returns The default options\n */\n getOptions(): Required<NotificationOptions> {\n return { ...this.options };\n }\n\n /**\n * Success notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n success(title: string, opts?: NotificationOptions): void {\n this.show('success', title, opts);\n }\n\n /**\n * Error notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n error(title: string, opts?: NotificationOptions): void {\n this.show('error', title, opts);\n }\n\n /**\n * Warning notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n warning(title: string, opts?: NotificationOptions): void {\n this.show('warning', title, opts);\n }\n\n /**\n * Info notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n info(title: string, opts?: NotificationOptions): void {\n this.show('info', title, opts);\n }\n}\n\n// Default instance for convenience\nexport const notificationManager = new NotificationManager();\n","import { reactive, watchEffect } from 'vue';\nimport { NotificationManager, notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationOptions } from '../../types';\n\nexport interface ReactiveNotificationStore {\n notifications: NotificationItem[];\n options: NotificationOptions;\n}\n\n/**\n * Create a reactive store for Vue that syncs with the NotificationManager.\n * @param manager - The NotificationManager instance (optional, uses default if not provided)\n * @returns Reactive store\n */\nexport function createReactiveNotificationStore(\n manager: NotificationManager = notificationManager\n): ReactiveNotificationStore {\n const store = reactive({\n notifications: manager.getNotifications(),\n options: manager.getOptions(),\n });\n\n // Sync notifications\n manager.on('notification-added', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notification-removed', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notifications-cleared', () => {\n store.notifications = manager.getNotifications();\n });\n\n // Sync options\n manager.on('options-changed', () => {\n store.options = manager.getOptions();\n });\n\n return store;\n}\n\n// Default reactive store\nexport const notificationStore = createReactiveNotificationStore();\n\n// Vue composable\nexport function useNotificationManager(manager: NotificationManager = notificationManager) {\n return {\n success: (title: string, opts?: NotificationOptions) => manager.success(title, opts),\n error: (title: string, opts?: NotificationOptions) => manager.error(title, opts),\n warning: (title: string, opts?: NotificationOptions) => manager.warning(title, opts),\n info: (title: string, opts?: NotificationOptions) => manager.info(title, opts),\n show: (type: string, title: string, opts?: NotificationOptions) =>\n manager.show(type as any, title, opts),\n remove: (id: number) => manager.remove(id),\n clear: () => manager.clear(),\n setDefaults: (opts: NotificationOptions) => manager.setDefaults(opts),\n getNotifications: () => manager.getNotifications(),\n getOptions: () => manager.getOptions(),\n };\n}\n\n// Vue plugin\nexport function createVueNotificationPlugin(manager: NotificationManager = notificationManager) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, ref } from 'vue';\nimport { notificationStore } from './index';\nimport { notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationPosition } from '../../types';\n\nconst isClient = ref(false);\n\nif (typeof window !== 'undefined') {\n isClient.value = true;\n}\n\nconst groups = computed<Record<NotificationPosition, NotificationItem[]>>(() => {\n const map: Record<NotificationPosition, NotificationItem[]> = {\n 'top-left': [],\n 'top-center': [],\n 'top-right': [],\n 'bottom-left': [],\n 'bottom-center': [],\n 'bottom-right': [],\n };\n for (const notification of notificationStore.notifications) {\n map[notification.options.position].push(notification);\n }\n return map;\n});\n\nfunction removeNotification(id: number) {\n notificationManager.remove(id);\n}\n</script>\n\n<template>\n <Teleport v-if=\"isClient\" to=\"body\">\n <TransitionGroup\n v-for=\"(items, pos) in groups\"\n :key=\"pos\"\n tag=\"div\"\n name=\"notification\"\n class=\"notification-list\"\n :data-position=\"pos\"\n >\n <article\n v-for=\"notification in items\"\n :key=\"notification.id\"\n class=\"notification\"\n :class=\"[\n `notification-${notification.type}`,\n {\n 'notification-auto-close':\n notification.options.progress && notification.options.autoClose !== false,\n },\n ]\"\n :data-position=\"pos\"\n >\n <div class=\"notification-content\">\n <span class=\"notification-title\">{{ notification.title }}</span>\n </div>\n\n <div\n v-if=\"notification.options.progress && notification.options.autoClose !== false\"\n class=\"notification-progress\"\n :style=\"{ animationDuration: (notification.options.autoClose || 0) + 'ms' }\"\n ></div>\n\n <div class=\"notification-close\">\n <button\n type=\"button\"\n @click=\"removeNotification(notification.id)\"\n aria-label=\"Dismiss notification\"\n >\n ×\n </button>\n </div>\n </article>\n </TransitionGroup>\n </Teleport>\n</template>\n","import { useNotificationManager } from '../adapters/vue';\n\n/**\n * Vue composable for notification management.\n * Provides a clean API to show notifications in Vue components.\n *\n * @returns Notification manager API\n */\nexport function useNotification() {\n return useNotificationManager();\n}\n","import { notificationManager } from '../../core/notification-manager';\n\n/**\n * Nuxt plugin for notification management.\n * Integrates the notification manager into Nuxt applications.\n */\nexport default defineNuxtPlugin((nuxtApp) => {\n nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));\n});\n\n/**\n * Create Vue plugin for Nuxt (internal use).\n */\nfunction createVueNotificationPlugin(manager: any) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n\n// Re-export Vue adapter functions for convenience\nexport { useNotificationManager, createReactiveNotificationStore, notificationStore } from '../vue';\n"],"names":["reactive","createVueNotificationPlugin","ref","computed","_createBlock","_Teleport","_openBlock","_createElementBlock","_Fragment","_renderList","_TransitionGroup","_createElementVNode","_toDisplayString","_normalizeStyle"],"mappings":";;;;AAEA,QAAM,kBAAiD;AAAA,IACrD,UAAU;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,EACZ;AAAA,EAEO,MAAM,oBAAoB;AAAA,IAA1B,cAAA;AACL,WAAQ,gBAAoC,CAAA;AAC5C,WAAQ,UAAyC,EAAE,GAAG,gBAAA;AACtD,WAAQ,YAA6C,CAAA;AACrD,WAAQ,YAAY;AAAA,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOpB,GAAG,OAAe,UAA0B;AAC1C,UAAI,CAAC,KAAK,UAAU,KAAK,GAAG;AAC1B,aAAK,UAAU,KAAK,IAAI,CAAA;AAAA,MAC1B;AACA,WAAK,UAAU,KAAK,EAAE,KAAK,QAAQ;AAAA,IACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,IAAI,OAAe,UAA0B;AAC3C,UAAI,KAAK,UAAU,KAAK,GAAG;AACzB,aAAK,UAAU,KAAK,IAAI,KAAK,UAAU,KAAK,EAAE,OAAO,CAAC,OAAO,OAAO,QAAQ;AAAA,MAC9E;AAAA,IACF;AAAA,IAEQ,KAAK,OAAe,MAAkB;AAC5C,UAAI,KAAK,UAAU,KAAK,GAAG;AACzB,aAAK,UAAU,KAAK,EAAE,QAAQ,CAAC,aAAa,SAAS,IAAI,CAAC;AAAA,MAC5D;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,YAAY,MAAiC;AAC3C,WAAK,UAAU,EAAE,GAAG,KAAK,SAAS,GAAG,KAAA;AACrC,WAAK,KAAK,mBAAmB,KAAK,OAAO;AAAA,IAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQA,KAAK,MAAwB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ters/vue/index.ts","../src/adapters/vue/NotificationContainer.vue","../src/composables/useNotification.ts","../src/adapters/nuxt/index.ts"],"sourcesContent":["import type { NotificationType, NotificationOptions, NotificationItem } from '../types';\n\nconst DEFAULT_OPTIONS: Required<NotificationOptions> = {\n position: 'top-center',\n autoClose: 3000,\n progress: true,\n};\n\nexport class NotificationManager {\n private notifications: NotificationItem[] = [];\n private options: Required<NotificationOptions> = { ...DEFAULT_OPTIONS };\n private listeners: { [event: string]: Function[] } = {};\n private idCounter = 1;\n\n /**\n * Subscribe to an event.\n * @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')\n * @param callback - The callback function\n */\n on(event: string, callback: Function): void {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event].push(callback);\n }\n\n /**\n * Unsubscribe from an event.\n * @param event - The event name\n * @param callback - The callback function to remove\n */\n off(event: string, callback: Function): void {\n if (this.listeners[event]) {\n this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);\n }\n }\n\n private emit(event: string, data?: any): void {\n if (this.listeners[event]) {\n this.listeners[event].forEach((callback) => callback(data));\n }\n }\n\n /**\n * Set default options for notifications.\n * @param opts - The options to set as defaults\n */\n setDefaults(opts: NotificationOptions): void {\n this.options = { ...this.options, ...opts };\n this.emit('options-changed', this.options);\n }\n\n /**\n * Show a notification.\n * @param type - The type of notification\n * @param title - The title/message of the notification\n * @param opts - Optional override options\n */\n show(type: NotificationType, title: string, opts?: NotificationOptions): void {\n const options = { ...this.options, ...(opts || {}) };\n const item: NotificationItem = {\n id: this.idCounter++,\n type,\n title,\n options,\n createdAt: Date.now(),\n };\n this.notifications.push(item);\n this.emit('notification-added', item);\n\n if (options.autoClose !== false && typeof window !== 'undefined') {\n setTimeout(() => this.remove(item.id), options.autoClose);\n }\n }\n\n /**\n * Remove a notification by ID.\n * @param id - The ID of the notification to remove\n */\n remove(id: number): void {\n const index = this.notifications.findIndex((n) => n.id === id);\n if (index !== -1) {\n const removed = this.notifications.splice(index, 1)[0];\n this.emit('notification-removed', removed);\n }\n }\n\n /**\n * Clear all notifications.\n */\n clear(): void {\n const removed = [...this.notifications];\n this.notifications.splice(0);\n this.emit('notifications-cleared', removed);\n }\n\n /**\n * Get a copy of the current notifications.\n * @returns Array of notification items\n */\n getNotifications(): NotificationItem[] {\n return [...this.notifications];\n }\n\n /**\n * Get the current default options.\n * @returns The default options\n */\n getOptions(): Required<NotificationOptions> {\n return { ...this.options };\n }\n\n /**\n * Success notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n success(title: string, opts?: NotificationOptions): void {\n this.show('success', title, opts);\n }\n\n /**\n * Error notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n error(title: string, opts?: NotificationOptions): void {\n this.show('error', title, opts);\n }\n\n /**\n * Warning notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n warning(title: string, opts?: NotificationOptions): void {\n this.show('warning', title, opts);\n }\n\n /**\n * Info notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n info(title: string, opts?: NotificationOptions): void {\n this.show('info', title, opts);\n }\n}\n\n// Default instance for convenience\nexport const notificationManager = new NotificationManager();\n","import { reactive, watchEffect } from 'vue';\nimport { NotificationManager, notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationOptions } from '../../types';\n\nexport interface ReactiveNotificationStore {\n notifications: NotificationItem[];\n options: NotificationOptions;\n}\n\n/**\n * Create a reactive store for Vue that syncs with the NotificationManager.\n * @param manager - The NotificationManager instance (optional, uses default if not provided)\n * @returns Reactive store\n */\nexport function createReactiveNotificationStore(\n manager: NotificationManager = notificationManager\n): ReactiveNotificationStore {\n const store = reactive({\n notifications: manager.getNotifications(),\n options: manager.getOptions(),\n });\n\n // Sync notifications\n manager.on('notification-added', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notification-removed', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notifications-cleared', () => {\n store.notifications = manager.getNotifications();\n });\n\n // Sync options\n manager.on('options-changed', () => {\n store.options = manager.getOptions();\n });\n\n return store;\n}\n\n// Default reactive store\nexport const notificationStore = createReactiveNotificationStore();\n\n// Vue composable\nexport function useNotificationManager(manager: NotificationManager = notificationManager) {\n return {\n success: (title: string, opts?: NotificationOptions) => manager.success(title, opts),\n error: (title: string, opts?: NotificationOptions) => manager.error(title, opts),\n warning: (title: string, opts?: NotificationOptions) => manager.warning(title, opts),\n info: (title: string, opts?: NotificationOptions) => manager.info(title, opts),\n show: (type: string, title: string, opts?: NotificationOptions) =>\n manager.show(type as any, title, opts),\n remove: (id: number) => manager.remove(id),\n clear: () => manager.clear(),\n setDefaults: (opts: NotificationOptions) => manager.setDefaults(opts),\n getNotifications: () => manager.getNotifications(),\n getOptions: () => manager.getOptions(),\n };\n}\n\n// Vue plugin\nexport function createVueNotificationPlugin(manager: NotificationManager = notificationManager) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, ref } from 'vue';\nimport { notificationStore } from './index';\nimport { notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationPosition } from '../../types';\n\nconst isClient = ref(false);\n\nif (typeof window !== 'undefined') {\n isClient.value = true;\n}\n\nconst groups = computed<Record<NotificationPosition, NotificationItem[]>>(() => {\n const map: Record<NotificationPosition, NotificationItem[]> = {\n 'top-left': [],\n 'top-center': [],\n 'top-right': [],\n 'bottom-left': [],\n 'bottom-center': [],\n 'bottom-right': [],\n };\n for (const notification of notificationStore.notifications) {\n map[notification.options.position].push(notification);\n }\n return map;\n});\n\nfunction removeNotification(id: number) {\n notificationManager.remove(id);\n}\n</script>\n\n<template>\n <Teleport v-if=\"isClient\" to=\"body\">\n <TransitionGroup\n v-for=\"(items, pos) in groups\"\n :key=\"pos\"\n tag=\"div\"\n name=\"notification\"\n class=\"notification-list\"\n :data-position=\"pos\"\n >\n <article\n v-for=\"notification in items\"\n :key=\"notification.id\"\n class=\"notification\"\n :class=\"[\n `notification-${notification.type}`,\n {\n 'notification-auto-close':\n notification.options.progress && notification.options.autoClose !== false,\n },\n ]\"\n :data-position=\"pos\"\n >\n <div class=\"notification-content\">\n <span class=\"notification-title\">{{ notification.title }}</span>\n </div>\n\n <div\n v-if=\"notification.options.progress && notification.options.autoClose !== false\"\n class=\"notification-progress\"\n :style=\"{ animationDuration: (notification.options.autoClose || 0) + 'ms' }\"\n ></div>\n\n <div class=\"notification-close\">\n <button\n type=\"button\"\n @click=\"removeNotification(notification.id)\"\n aria-label=\"Dismiss notification\"\n >\n ×\n </button>\n </div>\n </article>\n </TransitionGroup>\n </Teleport>\n</template>\n","import { useNotificationManager } from '../adapters/vue';\n\n/**\n * Vue composable for notification management.\n * Provides a clean API to show notifications in Vue components.\n *\n * @returns Notification manager API\n */\nexport function useNotification() {\n return useNotificationManager();\n}\n","import { defineNuxtPlugin } from 'nuxt/app';\nimport type { NuxtApp } from 'nuxt/app';\nimport { notificationManager } from '../../core/notification-manager';\n\n/**\n * Nuxt plugin for notification management.\n * Integrates the notification manager into Nuxt applications.\n */\nexport default defineNuxtPlugin((nuxtApp: NuxtApp) => {\n nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));\n});\n\n/**\n * Create Vue plugin for Nuxt (internal use).\n */\nfunction createVueNotificationPlugin(manager: any) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n\n// Re-export Vue adapter functions for convenience\nexport { useNotificationManager, createReactiveNotificationStore, notificationStore } from '../vue';\n"],"names":["reactive","createVueNotificationPlugin","app","ref","computed","_createBlock","_Teleport","_openBlock","_createElementBlock","_Fragment","_renderList","_TransitionGroup","_createElementVNode","_toDisplayString","_normalizeStyle","defineNuxtPlugin"],"mappings":";;;;AAEA,QAAM,kBAAiD;AAAA,IACrD,UAAU;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,EACZ;AAAA,EAEO,MAAM,oB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OxL,iBAAe;AAAA,kBAAA;oBAEhBI,IAAAA,mBAEM,OAFN,YAEM;AAAA,sBADJA,IAAAA,mBAAgE,QAAhE,YAAgEC,IAAAA,gBAA5B,aAAa,KAAK,GAAA,CAAA;AAAA,oBAAA;oBAIhD,aAAa,QAAQ,YAAY,aAAa,QAAQ,cAAS,0BADvEL,IAAAA,mBAIO,OAAA;AAAA;sBAFL,OAAM;AAAA,sBACL,OAAKM,IAAAA,eAAA,EAAA,oBAAwB,aAAa,QAAQ,aAAS,KAAA,KAAA,CAAA;AAAA,oBAAA;oBAG9DF,IAAAA,mBAQM,OARN,YAQM;AAAA,sBAPJA,IAAAA,mBAMS,UAAA;AAAA,wBALP,MAAK;AAAA,wBACJ,SAAK,CAAA,WAAE,mBAAmB,aAAa,EAAE;AAAA,wBAC1C,cAAW;AAAA,sBAAA,GACZ,OAED,GAAA,UAAA;AAAA,oBAAA;;;;;;;;;;;AChEH,WAAS,kBAAkB;AAChC,WAAO,uBAAA;AAAA,EACT;ACFeG,MAAAA,iBAAiB,CAAC,YAAqB;AACpD,YAAQ,OAAO,IAAI,4BAA4B,mBAAmB,CAAC;AAAA,EACrE,CAAC;AAKD,WAAS,4BAA4B,SAAc;AACjD,WAAO;AAAA,MACL,QAAQb,MAAU;AAChB,QAAAA,KAAI,OAAO,iBAAiB,uBAAuB;AACnD,QAAAA,KAAI,QAAQ,uBAAuB,OAAO;AAAA,MAC5C;AAAA,IAAA;AAAA,EAEJ;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { reactive, defineComponent, ref, computed, openBlock, createBlock, Teleport, createElementBlock, Fragment, renderList, TransitionGroup, withCtx, normalizeClass, createElementVNode, toDisplayString, normalizeStyle, createCommentVNode } from "vue";
|
|
2
|
+
import { defineNuxtPlugin } from "nuxt/app";
|
|
2
3
|
const DEFAULT_OPTIONS = {
|
|
3
4
|
position: "top-center",
|
|
4
5
|
autoClose: 3e3,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/core/notification-manager.ts","../src/adapters/vue/index.ts","../src/adapters/vue/NotificationContainer.vue","../src/composables/useNotification.ts","../src/adapters/nuxt/index.ts"],"sourcesContent":["import type { NotificationType, NotificationOptions, NotificationItem } from '../types';\n\nconst DEFAULT_OPTIONS: Required<NotificationOptions> = {\n position: 'top-center',\n autoClose: 3000,\n progress: true,\n};\n\nexport class NotificationManager {\n private notifications: NotificationItem[] = [];\n private options: Required<NotificationOptions> = { ...DEFAULT_OPTIONS };\n private listeners: { [event: string]: Function[] } = {};\n private idCounter = 1;\n\n /**\n * Subscribe to an event.\n * @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')\n * @param callback - The callback function\n */\n on(event: string, callback: Function): void {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event].push(callback);\n }\n\n /**\n * Unsubscribe from an event.\n * @param event - The event name\n * @param callback - The callback function to remove\n */\n off(event: string, callback: Function): void {\n if (this.listeners[event]) {\n this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);\n }\n }\n\n private emit(event: string, data?: any): void {\n if (this.listeners[event]) {\n this.listeners[event].forEach((callback) => callback(data));\n }\n }\n\n /**\n * Set default options for notifications.\n * @param opts - The options to set as defaults\n */\n setDefaults(opts: NotificationOptions): void {\n this.options = { ...this.options, ...opts };\n this.emit('options-changed', this.options);\n }\n\n /**\n * Show a notification.\n * @param type - The type of notification\n * @param title - The title/message of the notification\n * @param opts - Optional override options\n */\n show(type: NotificationType, title: string, opts?: NotificationOptions): void {\n const options = { ...this.options, ...(opts || {}) };\n const item: NotificationItem = {\n id: this.idCounter++,\n type,\n title,\n options,\n createdAt: Date.now(),\n };\n this.notifications.push(item);\n this.emit('notification-added', item);\n\n if (options.autoClose !== false && typeof window !== 'undefined') {\n setTimeout(() => this.remove(item.id), options.autoClose);\n }\n }\n\n /**\n * Remove a notification by ID.\n * @param id - The ID of the notification to remove\n */\n remove(id: number): void {\n const index = this.notifications.findIndex((n) => n.id === id);\n if (index !== -1) {\n const removed = this.notifications.splice(index, 1)[0];\n this.emit('notification-removed', removed);\n }\n }\n\n /**\n * Clear all notifications.\n */\n clear(): void {\n const removed = [...this.notifications];\n this.notifications.splice(0);\n this.emit('notifications-cleared', removed);\n }\n\n /**\n * Get a copy of the current notifications.\n * @returns Array of notification items\n */\n getNotifications(): NotificationItem[] {\n return [...this.notifications];\n }\n\n /**\n * Get the current default options.\n * @returns The default options\n */\n getOptions(): Required<NotificationOptions> {\n return { ...this.options };\n }\n\n /**\n * Success notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n success(title: string, opts?: NotificationOptions): void {\n this.show('success', title, opts);\n }\n\n /**\n * Error notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n error(title: string, opts?: NotificationOptions): void {\n this.show('error', title, opts);\n }\n\n /**\n * Warning notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n warning(title: string, opts?: NotificationOptions): void {\n this.show('warning', title, opts);\n }\n\n /**\n * Info notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n info(title: string, opts?: NotificationOptions): void {\n this.show('info', title, opts);\n }\n}\n\n// Default instance for convenience\nexport const notificationManager = new NotificationManager();\n","import { reactive, watchEffect } from 'vue';\nimport { NotificationManager, notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationOptions } from '../../types';\n\nexport interface ReactiveNotificationStore {\n notifications: NotificationItem[];\n options: NotificationOptions;\n}\n\n/**\n * Create a reactive store for Vue that syncs with the NotificationManager.\n * @param manager - The NotificationManager instance (optional, uses default if not provided)\n * @returns Reactive store\n */\nexport function createReactiveNotificationStore(\n manager: NotificationManager = notificationManager\n): ReactiveNotificationStore {\n const store = reactive({\n notifications: manager.getNotifications(),\n options: manager.getOptions(),\n });\n\n // Sync notifications\n manager.on('notification-added', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notification-removed', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notifications-cleared', () => {\n store.notifications = manager.getNotifications();\n });\n\n // Sync options\n manager.on('options-changed', () => {\n store.options = manager.getOptions();\n });\n\n return store;\n}\n\n// Default reactive store\nexport const notificationStore = createReactiveNotificationStore();\n\n// Vue composable\nexport function useNotificationManager(manager: NotificationManager = notificationManager) {\n return {\n success: (title: string, opts?: NotificationOptions) => manager.success(title, opts),\n error: (title: string, opts?: NotificationOptions) => manager.error(title, opts),\n warning: (title: string, opts?: NotificationOptions) => manager.warning(title, opts),\n info: (title: string, opts?: NotificationOptions) => manager.info(title, opts),\n show: (type: string, title: string, opts?: NotificationOptions) =>\n manager.show(type as any, title, opts),\n remove: (id: number) => manager.remove(id),\n clear: () => manager.clear(),\n setDefaults: (opts: NotificationOptions) => manager.setDefaults(opts),\n getNotifications: () => manager.getNotifications(),\n getOptions: () => manager.getOptions(),\n };\n}\n\n// Vue plugin\nexport function createVueNotificationPlugin(manager: NotificationManager = notificationManager) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, ref } from 'vue';\nimport { notificationStore } from './index';\nimport { notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationPosition } from '../../types';\n\nconst isClient = ref(false);\n\nif (typeof window !== 'undefined') {\n isClient.value = true;\n}\n\nconst groups = computed<Record<NotificationPosition, NotificationItem[]>>(() => {\n const map: Record<NotificationPosition, NotificationItem[]> = {\n 'top-left': [],\n 'top-center': [],\n 'top-right': [],\n 'bottom-left': [],\n 'bottom-center': [],\n 'bottom-right': [],\n };\n for (const notification of notificationStore.notifications) {\n map[notification.options.position].push(notification);\n }\n return map;\n});\n\nfunction removeNotification(id: number) {\n notificationManager.remove(id);\n}\n</script>\n\n<template>\n <Teleport v-if=\"isClient\" to=\"body\">\n <TransitionGroup\n v-for=\"(items, pos) in groups\"\n :key=\"pos\"\n tag=\"div\"\n name=\"notification\"\n class=\"notification-list\"\n :data-position=\"pos\"\n >\n <article\n v-for=\"notification in items\"\n :key=\"notification.id\"\n class=\"notification\"\n :class=\"[\n `notification-${notification.type}`,\n {\n 'notification-auto-close':\n notification.options.progress && notification.options.autoClose !== false,\n },\n ]\"\n :data-position=\"pos\"\n >\n <div class=\"notification-content\">\n <span class=\"notification-title\">{{ notification.title }}</span>\n </div>\n\n <div\n v-if=\"notification.options.progress && notification.options.autoClose !== false\"\n class=\"notification-progress\"\n :style=\"{ animationDuration: (notification.options.autoClose || 0) + 'ms' }\"\n ></div>\n\n <div class=\"notification-close\">\n <button\n type=\"button\"\n @click=\"removeNotification(notification.id)\"\n aria-label=\"Dismiss notification\"\n >\n ×\n </button>\n </div>\n </article>\n </TransitionGroup>\n </Teleport>\n</template>\n","import { useNotificationManager } from '../adapters/vue';\n\n/**\n * Vue composable for notification management.\n * Provides a clean API to show notifications in Vue components.\n *\n * @returns Notification manager API\n */\nexport function useNotification() {\n return useNotificationManager();\n}\n","import { notificationManager } from '../../core/notification-manager';\n\n/**\n * Nuxt plugin for notification management.\n * Integrates the notification manager into Nuxt applications.\n */\nexport default defineNuxtPlugin((nuxtApp) => {\n nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));\n});\n\n/**\n * Create Vue plugin for Nuxt (internal use).\n */\nfunction createVueNotificationPlugin(manager: any) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n\n// Re-export Vue adapter functions for convenience\nexport { useNotificationManager, createReactiveNotificationStore, notificationStore } from '../vue';\n"],"names":["createVueNotificationPlugin","_createBlock","_Teleport","_openBlock","_createElementBlock","_Fragment","_renderList","_TransitionGroup","_createElementVNode","_toDisplayString","_normalizeStyle"],"mappings":";AAEA,MAAM,kBAAiD;AAAA,EACrD,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAU;AACZ;AAEO,MAAM,oBAAoB;AAAA,EAA1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,aAAa,QAAQ,YAAY,aAAa,QAAQ,cAAS,sBADvEL,mBAIO,OAAA;AAAA;oBAFL,OAAM;AAAA,oBACL,OAAKM,eAAA,EAAA,oBAAwB,aAAa,QAAQ,aAAS,KAAA,KAAA,CAAA;AAAA,kBAAA;kBAG9DF,mBAQM,OARN,YAQM;AAAA,oBAPJA,mBAMS,UAAA;AAAA,sBALP,MAAK;AAAA,sBACJ,SAAK,CAAA,WAAE,mBAAmB,aAAa,EAAE;AAAA,sBAC1C,cAAW;AAAA,oBAAA,GACZ,OAED,GAAA,UAAA;AAAA,kBAAA;;;;;;;;;;;AChEH,SAAS,kBAAkB;AAChC,SAAO,uBAAA;AACT;ACJe,iBAAiB,CAAC,YAAY;AAC3C,UAAQ,OAAO,IAAI,4BAA4B,mBAAmB,CAAC;AACrE,CAAC;AAKD,SAAS,4BAA4B,SAAc;AACjD,SAAO;AAAA,IACL,QAAQ,KAAU;AAChB,UAAI,OAAO,iBAAiB,uBAAuB;AACnD,UAAI,QAAQ,uBAAuB,OAAO;AAAA,IAC5C;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/core/notification-manager.ts","../src/adapters/vue/index.ts","../src/adapters/vue/NotificationContainer.vue","../src/composables/useNotification.ts","../src/adapters/nuxt/index.ts"],"sourcesContent":["import type { NotificationType, NotificationOptions, NotificationItem } from '../types';\n\nconst DEFAULT_OPTIONS: Required<NotificationOptions> = {\n position: 'top-center',\n autoClose: 3000,\n progress: true,\n};\n\nexport class NotificationManager {\n private notifications: NotificationItem[] = [];\n private options: Required<NotificationOptions> = { ...DEFAULT_OPTIONS };\n private listeners: { [event: string]: Function[] } = {};\n private idCounter = 1;\n\n /**\n * Subscribe to an event.\n * @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')\n * @param callback - The callback function\n */\n on(event: string, callback: Function): void {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event].push(callback);\n }\n\n /**\n * Unsubscribe from an event.\n * @param event - The event name\n * @param callback - The callback function to remove\n */\n off(event: string, callback: Function): void {\n if (this.listeners[event]) {\n this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);\n }\n }\n\n private emit(event: string, data?: any): void {\n if (this.listeners[event]) {\n this.listeners[event].forEach((callback) => callback(data));\n }\n }\n\n /**\n * Set default options for notifications.\n * @param opts - The options to set as defaults\n */\n setDefaults(opts: NotificationOptions): void {\n this.options = { ...this.options, ...opts };\n this.emit('options-changed', this.options);\n }\n\n /**\n * Show a notification.\n * @param type - The type of notification\n * @param title - The title/message of the notification\n * @param opts - Optional override options\n */\n show(type: NotificationType, title: string, opts?: NotificationOptions): void {\n const options = { ...this.options, ...(opts || {}) };\n const item: NotificationItem = {\n id: this.idCounter++,\n type,\n title,\n options,\n createdAt: Date.now(),\n };\n this.notifications.push(item);\n this.emit('notification-added', item);\n\n if (options.autoClose !== false && typeof window !== 'undefined') {\n setTimeout(() => this.remove(item.id), options.autoClose);\n }\n }\n\n /**\n * Remove a notification by ID.\n * @param id - The ID of the notification to remove\n */\n remove(id: number): void {\n const index = this.notifications.findIndex((n) => n.id === id);\n if (index !== -1) {\n const removed = this.notifications.splice(index, 1)[0];\n this.emit('notification-removed', removed);\n }\n }\n\n /**\n * Clear all notifications.\n */\n clear(): void {\n const removed = [...this.notifications];\n this.notifications.splice(0);\n this.emit('notifications-cleared', removed);\n }\n\n /**\n * Get a copy of the current notifications.\n * @returns Array of notification items\n */\n getNotifications(): NotificationItem[] {\n return [...this.notifications];\n }\n\n /**\n * Get the current default options.\n * @returns The default options\n */\n getOptions(): Required<NotificationOptions> {\n return { ...this.options };\n }\n\n /**\n * Success notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n success(title: string, opts?: NotificationOptions): void {\n this.show('success', title, opts);\n }\n\n /**\n * Error notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n error(title: string, opts?: NotificationOptions): void {\n this.show('error', title, opts);\n }\n\n /**\n * Warning notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n warning(title: string, opts?: NotificationOptions): void {\n this.show('warning', title, opts);\n }\n\n /**\n * Info notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n info(title: string, opts?: NotificationOptions): void {\n this.show('info', title, opts);\n }\n}\n\n// Default instance for convenience\nexport const notificationManager = new NotificationManager();\n","import { reactive, watchEffect } from 'vue';\nimport { NotificationManager, notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationOptions } from '../../types';\n\nexport interface ReactiveNotificationStore {\n notifications: NotificationItem[];\n options: NotificationOptions;\n}\n\n/**\n * Create a reactive store for Vue that syncs with the NotificationManager.\n * @param manager - The NotificationManager instance (optional, uses default if not provided)\n * @returns Reactive store\n */\nexport function createReactiveNotificationStore(\n manager: NotificationManager = notificationManager\n): ReactiveNotificationStore {\n const store = reactive({\n notifications: manager.getNotifications(),\n options: manager.getOptions(),\n });\n\n // Sync notifications\n manager.on('notification-added', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notification-removed', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notifications-cleared', () => {\n store.notifications = manager.getNotifications();\n });\n\n // Sync options\n manager.on('options-changed', () => {\n store.options = manager.getOptions();\n });\n\n return store;\n}\n\n// Default reactive store\nexport const notificationStore = createReactiveNotificationStore();\n\n// Vue composable\nexport function useNotificationManager(manager: NotificationManager = notificationManager) {\n return {\n success: (title: string, opts?: NotificationOptions) => manager.success(title, opts),\n error: (title: string, opts?: NotificationOptions) => manager.error(title, opts),\n warning: (title: string, opts?: NotificationOptions) => manager.warning(title, opts),\n info: (title: string, opts?: NotificationOptions) => manager.info(title, opts),\n show: (type: string, title: string, opts?: NotificationOptions) =>\n manager.show(type as any, title, opts),\n remove: (id: number) => manager.remove(id),\n clear: () => manager.clear(),\n setDefaults: (opts: NotificationOptions) => manager.setDefaults(opts),\n getNotifications: () => manager.getNotifications(),\n getOptions: () => manager.getOptions(),\n };\n}\n\n// Vue plugin\nexport function createVueNotificationPlugin(manager: NotificationManager = notificationManager) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, ref } from 'vue';\nimport { notificationStore } from './index';\nimport { notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationPosition } from '../../types';\n\nconst isClient = ref(false);\n\nif (typeof window !== 'undefined') {\n isClient.value = true;\n}\n\nconst groups = computed<Record<NotificationPosition, NotificationItem[]>>(() => {\n const map: Record<NotificationPosition, NotificationItem[]> = {\n 'top-left': [],\n 'top-center': [],\n 'top-right': [],\n 'bottom-left': [],\n 'bottom-center': [],\n 'bottom-right': [],\n };\n for (const notification of notificationStore.notifications) {\n map[notification.options.position].push(notification);\n }\n return map;\n});\n\nfunction removeNotification(id: number) {\n notificationManager.remove(id);\n}\n</script>\n\n<template>\n <Teleport v-if=\"isClient\" to=\"body\">\n <TransitionGroup\n v-for=\"(items, pos) in groups\"\n :key=\"pos\"\n tag=\"div\"\n name=\"notification\"\n class=\"notification-list\"\n :data-position=\"pos\"\n >\n <article\n v-for=\"notification in items\"\n :key=\"notification.id\"\n class=\"notification\"\n :class=\"[\n `notification-${notification.type}`,\n {\n 'notification-auto-close':\n notification.options.progress && notification.options.autoClose !== false,\n },\n ]\"\n :data-position=\"pos\"\n >\n <div class=\"notification-content\">\n <span class=\"notification-title\">{{ notification.title }}</span>\n </div>\n\n <div\n v-if=\"notification.options.progress && notification.options.autoClose !== false\"\n class=\"notification-progress\"\n :style=\"{ animationDuration: (notification.options.autoClose || 0) + 'ms' }\"\n ></div>\n\n <div class=\"notification-close\">\n <button\n type=\"button\"\n @click=\"removeNotification(notification.id)\"\n aria-label=\"Dismiss notification\"\n >\n ×\n </button>\n </div>\n </article>\n </TransitionGroup>\n </Teleport>\n</template>\n","import { useNotificationManager } from '../adapters/vue';\n\n/**\n * Vue composable for notification management.\n * Provides a clean API to show notifications in Vue components.\n *\n * @returns Notification manager API\n */\nexport function useNotification() {\n return useNotificationManager();\n}\n","import { defineNuxtPlugin } from 'nuxt/app';\nimport type { NuxtApp } from 'nuxt/app';\nimport { notificationManager } from '../../core/notification-manager';\n\n/**\n * Nuxt plugin for notification management.\n * Integrates the notification manager into Nuxt applications.\n */\nexport default defineNuxtPlugin((nuxtApp: NuxtApp) => {\n nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));\n});\n\n/**\n * Create Vue plugin for Nuxt (internal use).\n */\nfunction createVueNotificationPlugin(manager: any) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n\n// Re-export Vue adapter functions for convenience\nexport { useNotificationManager, createReactiveNotificationStore, notificationStore } from '../vue';\n"],"names":["createVueNotificationPlugin","_createBlock","_Teleport","_openBlock","_createElementBlock","_Fragment","_renderList","_TransitionGroup","_createElementVNode","_toDisplayString","_normalizeStyle"],"mappings":";;AAEA,MAAM,kBAAiD;AAAA,EACrD,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAU;AACZ;AAEO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACL,SAAQ,gBAAoC,CAAA;AAC5C,SAAQ,UAAyC,EAAE,GAAG,gBAAA;AACtD,SAAQ,YAA6C,CAAA;AACrD,SAAQ,YAAY;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpB,GAAG,OAAe,UAA0B;AAC1C,QAAI,CAAC,KAAK,UAAU,KAAK,GAAG;AAC1B,WAAK,UAAU,KAAK,IAAI,CAAA;AAAA,IAC1B;AACA,SAAK,UAAU,KAAK,EAAE,KAAK,QAAQ;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAe,UAA0B;AAC3C,QAAI,KAAK,UAAU,KAAK,GAAG;AACzB,WAAK,UAAU,KAAK,IAAI,KAAK,UAAU,KAAK,EAAE,OAAO,CAAC,OAAO,OAAO,QA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BAA4B,SAAc;AACjD,SAAO;AAAA,IACL,QAAQ,KAAU;AAChB,UAAI,OAAO,iBAAiB,uBAAuB;AACnD,UAAI,QAAQ,uBAAuB,OAAO;AAAA,IAC5C;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-notifyr",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Framework-agnostic notification library with Vue, Nuxt, and Inertia support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -30,11 +30,15 @@
|
|
|
30
30
|
"type-check": "tsc --noEmit"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"vue": "^3.3.0"
|
|
33
|
+
"vue": "^3.3.0",
|
|
34
|
+
"nuxt": "^3.0.0"
|
|
34
35
|
},
|
|
35
36
|
"peerDependenciesMeta": {
|
|
36
37
|
"vue": {
|
|
37
38
|
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"nuxt": {
|
|
41
|
+
"optional": true
|
|
38
42
|
}
|
|
39
43
|
},
|
|
40
44
|
"license": "MIT",
|
|
@@ -62,6 +66,7 @@
|
|
|
62
66
|
"@typescript-eslint/parser": "^6.0.0",
|
|
63
67
|
"@vitejs/plugin-vue": "^5.0.0",
|
|
64
68
|
"eslint": "^8.0.0",
|
|
69
|
+
"nuxt": "^3.0.0",
|
|
65
70
|
"prettier": "^3.0.0",
|
|
66
71
|
"typescript": "^5.0.0",
|
|
67
72
|
"vite": "^5.0.0",
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from 'nuxt/app';
|
|
2
|
+
import type { NuxtApp } from 'nuxt/app';
|
|
1
3
|
import { notificationManager } from '../../core/notification-manager';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Nuxt plugin for notification management.
|
|
5
7
|
* Integrates the notification manager into Nuxt applications.
|
|
6
8
|
*/
|
|
7
|
-
export default defineNuxtPlugin((nuxtApp) => {
|
|
9
|
+
export default defineNuxtPlugin((nuxtApp: NuxtApp) => {
|
|
8
10
|
nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));
|
|
9
11
|
});
|
|
10
12
|
|