plugin-ui-for-kzt 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 +88 -52
- package/dist/index.js +4904 -13
- package/package.json +1 -1
- package/src/components/Modal/Modal.vue +1 -1
- package/src/components/Toaster/README.md +10 -9
- package/src/plugins/modalPlugin.ts +64 -63
package/package.json
CHANGED
|
@@ -24,18 +24,19 @@
|
|
|
24
24
|
## Использование
|
|
25
25
|
|
|
26
26
|
```vue
|
|
27
|
+
|
|
27
28
|
<script setup>
|
|
28
|
-
import {
|
|
29
|
+
import {useToast} from "../../plugins/toasterPlugin";
|
|
29
30
|
|
|
30
|
-
const toast = useToast();
|
|
31
|
+
const toast = useToast();
|
|
31
32
|
|
|
32
|
-
const showSuccessToast = () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
33
|
+
const showSuccessToast = () => {
|
|
34
|
+
toast?.success("Toast on top", {
|
|
35
|
+
position: "top-left",
|
|
36
|
+
duration: 4000,
|
|
37
|
+
pauseOnHover: false,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
39
40
|
</script>
|
|
40
41
|
```
|
|
41
42
|
|
|
@@ -1,81 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {createApp, h, getCurrentInstance} from "vue";
|
|
2
|
+
import {useModalStore} from "../store/modal";
|
|
3
3
|
import Modal from "../components/Modal/Modal.vue";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import {watch} from "vue";
|
|
5
|
+
import {IModalState} from "types";
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
install(app: any) {
|
|
9
|
+
const modalStore = useModalStore();
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
// Добавление глобального метода $modal
|
|
12
|
+
app.config.globalProperties.$modal = {
|
|
13
|
+
open(name: string, options: IModalState) {
|
|
14
|
+
modalStore.openModal(name, options); // Открытие модалки через Pinia
|
|
15
|
+
console.log("Current modals:", modalStore.modals);
|
|
16
|
+
},
|
|
17
|
+
close(id: number) {
|
|
18
|
+
modalStore.closeModal(id); // Закрытие модалки через Pinia
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
// Найдем элемент с классом container
|
|
23
|
+
const modalContainer = document.createElement("div");
|
|
24
|
+
document.body.appendChild(modalContainer);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
// Реактивное обновление модалок через watch
|
|
27
|
+
watch(
|
|
28
|
+
() => modalStore.modals,
|
|
29
|
+
(newModals) => {
|
|
30
|
+
// Очищаем контейнер
|
|
31
|
+
modalContainer.innerHTML = "";
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// Добавляем модалки в DOM
|
|
34
|
+
newModals.forEach((modal) => {
|
|
35
|
+
modalContainer.dataset.modalId = String(modal.id);
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
modalContainer.addEventListener("click", (event) => {
|
|
38
|
+
console.log(`Closing modal with id: ${modal.id}`);
|
|
39
|
+
modalStore.closeModal(modal.id);
|
|
40
|
+
});
|
|
41
|
+
modalContainer.setAttribute("name", modal.name);
|
|
42
|
+
modalContainer.classList.add("modal");
|
|
43
|
+
modalContainer.addEventListener("click", () => {
|
|
44
|
+
console.log("this click on background");
|
|
45
|
+
modalStore.closeModal(modal.id);
|
|
46
|
+
if (modalStore.modals.length === 1) modalContainer.classList.remove("modal")
|
|
47
|
+
});
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
const modalApp = createApp({
|
|
50
|
+
render() {
|
|
51
|
+
return h(Modal, {
|
|
52
|
+
options: modal.options,
|
|
53
|
+
name: modal.name,
|
|
54
|
+
onClose: () => {
|
|
55
|
+
modalContainer.classList.remove("modal");
|
|
56
|
+
modalStore.closeModal(modal.id);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
modalApp.mount(modalContainer);
|
|
62
|
+
});
|
|
58
63
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
{ deep: true }
|
|
64
|
-
);
|
|
65
|
-
},
|
|
64
|
+
{deep: true}
|
|
65
|
+
);
|
|
66
|
+
},
|
|
66
67
|
};
|
|
67
68
|
|
|
68
69
|
export function useModal() {
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const instance = getCurrentInstance();
|
|
71
|
+
return instance?.appContext.config.globalProperties.$modal;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// Расширение глобального интерфейса для TypeScript
|
|
74
75
|
declare module "@vue/runtime-core" {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
interface ComponentCustomProperties {
|
|
77
|
+
$modal: {
|
|
78
|
+
open: (name: string, options?: Record<string, any>) => void;
|
|
79
|
+
close: (id: number) => void;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
81
82
|
}
|