vue-toastflow 0.0.2 → 0.0.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/README.md +1 -11
- package/package.json +1 -1
- package/src/components/ToastContainer.vue +7 -3
- package/src/toast.ts +80 -80
package/README.md
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<img src="../../images/banner.png" alt="Toastflow banner" width="900" />
|
|
5
|
-
</p>
|
|
1
|
+
https://github.com/adrianjanocko/toastflow
|
|
6
2
|
|
|
7
3
|
<h1 align="center">Toastflow</h1>
|
|
8
4
|
<p align="center">
|
|
@@ -11,12 +7,6 @@
|
|
|
11
7
|
|
|
12
8
|
---
|
|
13
9
|
|
|
14
|
-
## Preview
|
|
15
|
-
|
|
16
|
-
<p align="center">
|
|
17
|
-
<img src="../../images/showcase.png" alt="Toastflow showcase" width="850" />
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
10
|
## Usage (Vue.js 3 Composition API)
|
|
21
11
|
|
|
22
12
|
### Quick start
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
|
2
|
+
import { computed, inject, onMounted, onUnmounted, ref, watch } from "vue";
|
|
3
3
|
import Toast from "./Toast.vue";
|
|
4
4
|
import type {
|
|
5
5
|
ToastAnimation,
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
ToastPosition,
|
|
10
10
|
ToastStore,
|
|
11
11
|
} from "toastflow-core";
|
|
12
|
-
import {
|
|
12
|
+
import { toastStoreKey } from "../symbols";
|
|
13
13
|
|
|
14
14
|
const positions: ToastPosition[] = [
|
|
15
15
|
"top-left",
|
|
@@ -20,7 +20,11 @@ const positions: ToastPosition[] = [
|
|
|
20
20
|
"bottom-right",
|
|
21
21
|
];
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const injectedStore = inject<ToastStore | null>(toastStoreKey, null);
|
|
24
|
+
if (!injectedStore) {
|
|
25
|
+
throw new Error("[vue-toastflow] Plugin not installed");
|
|
26
|
+
}
|
|
27
|
+
const store: ToastStore = injectedStore;
|
|
24
28
|
|
|
25
29
|
const toasts = ref<ToastInstance[]>([]);
|
|
26
30
|
|
package/src/toast.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
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
|
-
let globalStore: ToastStore | null = null;
|
|
16
|
-
|
|
17
|
-
export function setToastStore(store: ToastStore) {
|
|
18
|
-
globalStore = store;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function getToastStore(): ToastStore {
|
|
22
|
-
if (!globalStore) {
|
|
23
|
-
throw new Error(
|
|
24
|
-
"[vue-toastflow] Toast store not initialized. Did you install the plugin?",
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return globalStore;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const toast = {
|
|
31
|
-
getState(): ToastState {
|
|
32
|
-
return getToastStore().getState();
|
|
33
|
-
},
|
|
34
|
-
subscribeEvents(listener: (event: ToastEvent) => void): () => void {
|
|
35
|
-
return getToastStore().subscribeEvents(listener);
|
|
36
|
-
},
|
|
37
|
-
show(options: ToastShowInput): ToastId {
|
|
38
|
-
return getToastStore().show(options);
|
|
39
|
-
},
|
|
40
|
-
loading<T>(
|
|
41
|
-
input: ToastLoadingInput<T>,
|
|
42
|
-
config: ToastLoadingConfig<T>,
|
|
43
|
-
): ToastLoadingResult<T> {
|
|
44
|
-
return getToastStore().loading(input, config);
|
|
45
|
-
},
|
|
46
|
-
update(id: ToastId, options: ToastUpdateInput): void {
|
|
47
|
-
return getToastStore().update(id, options);
|
|
48
|
-
},
|
|
49
|
-
dismiss(id: ToastId): void {
|
|
50
|
-
return getToastStore().dismiss(id);
|
|
51
|
-
},
|
|
52
|
-
dismissAll(): void {
|
|
53
|
-
return getToastStore().dismissAll();
|
|
54
|
-
},
|
|
55
|
-
pause(id: ToastId): void {
|
|
56
|
-
return getToastStore().pause(id);
|
|
57
|
-
},
|
|
58
|
-
resume(id: ToastId): void {
|
|
59
|
-
return getToastStore().resume(id);
|
|
60
|
-
},
|
|
61
|
-
getConfig(): ToastConfig {
|
|
62
|
-
return getToastStore().getConfig();
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
toast(options: ToastContentInput): ToastId {
|
|
66
|
-
return getToastStore().show({ ...options, type: "default" });
|
|
67
|
-
},
|
|
68
|
-
success(options: ToastContentInput): ToastId {
|
|
69
|
-
return getToastStore().show({ ...options, type: "success" });
|
|
70
|
-
},
|
|
71
|
-
error(options: ToastContentInput): ToastId {
|
|
72
|
-
return getToastStore().show({ ...options, type: "error" });
|
|
73
|
-
},
|
|
74
|
-
info(options: ToastContentInput): ToastId {
|
|
75
|
-
return getToastStore().show({ ...options, type: "info" });
|
|
76
|
-
},
|
|
77
|
-
warning(options: ToastContentInput): ToastId {
|
|
78
|
-
return getToastStore().show({ ...options, type: "warning" });
|
|
79
|
-
},
|
|
80
|
-
};
|
|
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
|
+
let globalStore: ToastStore | null = null;
|
|
16
|
+
|
|
17
|
+
export function setToastStore(store: ToastStore) {
|
|
18
|
+
globalStore = store;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getToastStore(): ToastStore {
|
|
22
|
+
if (!globalStore) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
"[vue-toastflow] Toast store not initialized. Did you install the plugin?",
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return globalStore;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const toast = {
|
|
31
|
+
getState(): ToastState {
|
|
32
|
+
return getToastStore().getState();
|
|
33
|
+
},
|
|
34
|
+
subscribeEvents(listener: (event: ToastEvent) => void): () => void {
|
|
35
|
+
return getToastStore().subscribeEvents(listener);
|
|
36
|
+
},
|
|
37
|
+
show(options: ToastShowInput): ToastId {
|
|
38
|
+
return getToastStore().show(options);
|
|
39
|
+
},
|
|
40
|
+
loading<T>(
|
|
41
|
+
input: ToastLoadingInput<T>,
|
|
42
|
+
config: ToastLoadingConfig<T>,
|
|
43
|
+
): ToastLoadingResult<T> {
|
|
44
|
+
return getToastStore().loading(input, config);
|
|
45
|
+
},
|
|
46
|
+
update(id: ToastId, options: ToastUpdateInput): void {
|
|
47
|
+
return getToastStore().update(id, options);
|
|
48
|
+
},
|
|
49
|
+
dismiss(id: ToastId): void {
|
|
50
|
+
return getToastStore().dismiss(id);
|
|
51
|
+
},
|
|
52
|
+
dismissAll(): void {
|
|
53
|
+
return getToastStore().dismissAll();
|
|
54
|
+
},
|
|
55
|
+
pause(id: ToastId): void {
|
|
56
|
+
return getToastStore().pause(id);
|
|
57
|
+
},
|
|
58
|
+
resume(id: ToastId): void {
|
|
59
|
+
return getToastStore().resume(id);
|
|
60
|
+
},
|
|
61
|
+
getConfig(): ToastConfig {
|
|
62
|
+
return getToastStore().getConfig();
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
toast(options: ToastContentInput): ToastId {
|
|
66
|
+
return getToastStore().show({ ...options, type: "default" });
|
|
67
|
+
},
|
|
68
|
+
success(options: ToastContentInput): ToastId {
|
|
69
|
+
return getToastStore().show({ ...options, type: "success" });
|
|
70
|
+
},
|
|
71
|
+
error(options: ToastContentInput): ToastId {
|
|
72
|
+
return getToastStore().show({ ...options, type: "error" });
|
|
73
|
+
},
|
|
74
|
+
info(options: ToastContentInput): ToastId {
|
|
75
|
+
return getToastStore().show({ ...options, type: "info" });
|
|
76
|
+
},
|
|
77
|
+
warning(options: ToastContentInput): ToastId {
|
|
78
|
+
return getToastStore().show({ ...options, type: "warning" });
|
|
79
|
+
},
|
|
80
|
+
};
|