vue-toastflow 0.0.4 → 0.0.6
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/package.json +17 -3
- package/src/components/Toast.vue +658 -660
- package/src/components/ToastContainer.vue +352 -354
- package/src/symbols.ts +6 -4
- package/src/toast.ts +37 -26
package/src/symbols.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {InjectionKey} from "vue";
|
|
2
|
-
import type {ToastStore} from "toastflow-core";
|
|
3
|
-
|
|
4
|
-
export const toastStoreKey: InjectionKey<ToastStore> = Symbol(
|
|
1
|
+
import type { InjectionKey } from "vue";
|
|
2
|
+
import type { ToastStore } from "toastflow-core";
|
|
3
|
+
|
|
4
|
+
export const toastStoreKey: InjectionKey<ToastStore> = Symbol.for(
|
|
5
|
+
"vue-toastflow.toast-store",
|
|
6
|
+
);
|
package/src/toast.ts
CHANGED
|
@@ -1,29 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ToastConfig,
|
|
3
|
-
ToastContentInput,
|
|
4
|
-
ToastEvent,
|
|
5
|
-
ToastId,
|
|
6
|
-
ToastLoadingConfig,
|
|
7
|
-
ToastLoadingInput,
|
|
8
|
-
ToastLoadingResult,
|
|
9
|
-
ToastShowInput,
|
|
10
|
-
ToastState,
|
|
11
|
-
ToastStore,
|
|
12
|
-
ToastUpdateInput,
|
|
13
|
-
} from "toastflow-core";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
1
|
+
import type {
|
|
2
|
+
ToastConfig,
|
|
3
|
+
ToastContentInput,
|
|
4
|
+
ToastEvent,
|
|
5
|
+
ToastId,
|
|
6
|
+
ToastLoadingConfig,
|
|
7
|
+
ToastLoadingInput,
|
|
8
|
+
ToastLoadingResult,
|
|
9
|
+
ToastShowInput,
|
|
10
|
+
ToastState,
|
|
11
|
+
ToastStore,
|
|
12
|
+
ToastUpdateInput,
|
|
13
|
+
} from "toastflow-core";
|
|
14
|
+
|
|
15
|
+
const GLOBAL_STORE_KEY = "__vue_toastflow_store__";
|
|
16
|
+
type GlobalWithStore = typeof globalThis & { [GLOBAL_STORE_KEY]?: ToastStore };
|
|
17
|
+
|
|
18
|
+
let globalStore: ToastStore | null = null;
|
|
19
|
+
|
|
20
|
+
export function setToastStore(store: ToastStore) {
|
|
21
|
+
globalStore = store;
|
|
22
|
+
try {
|
|
23
|
+
(globalThis as GlobalWithStore)[GLOBAL_STORE_KEY] = store;
|
|
24
|
+
} catch {
|
|
25
|
+
// ignore if globalThis is not writable
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getToastStore(): ToastStore {
|
|
30
|
+
if (!globalStore) {
|
|
31
|
+
globalStore = (globalThis as GlobalWithStore)[GLOBAL_STORE_KEY] ?? null;
|
|
32
|
+
}
|
|
33
|
+
if (!globalStore) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"[vue-toastflow] Toast store not initialized. Did you install the plugin?",
|
|
36
|
+
);
|
|
37
|
+
}
|
|
27
38
|
return globalStore;
|
|
28
39
|
}
|
|
29
40
|
|