jenesius-vue-modal
Advanced tools
Comparing version 1.7.1 to 1.7.2
@@ -8,4 +8,6 @@ import closeModal from "./methods/closeModal"; | ||
import onBeforeModalClose from "./hooks/onBeforeModalClose"; | ||
import getCurrentModal from "./methods/getCurrentModal"; | ||
import closeById from "./methods/closeById"; | ||
import WidgetModalContainer from "./components/WidgetModalContainer.vue"; | ||
import useModalRouter from "./routerIntegration"; | ||
export { closeModal, popModal, pushModal, openModal, modalQueue, config, WidgetModalContainer as container, onBeforeModalClose, useModalRouter }; | ||
export { closeModal, popModal, pushModal, openModal, modalQueue, config, WidgetModalContainer as container, onBeforeModalClose, useModalRouter, getCurrentModal, closeById }; |
@@ -8,2 +8,2 @@ import Modal, { ModalOptions } from "../utils/Modal"; | ||
* */ | ||
export default function _addModal(component: any, params: any, options: ModalOptions): Modal; | ||
export default function _addModal(component: any, params: any, options: Partial<ModalOptions>): Modal; |
import { IEventClose } from "../utils/event-close"; | ||
/** | ||
* @description Closing modal window by id. Is local methods (Not for export in index file) | ||
* @description Closing modal window by id. Only this method allows you to change the properties of the event-close. | ||
* */ | ||
export default function closeById(id: number, options?: Partial<IEventClose>): Promise<void>; |
@@ -131,2 +131,3 @@ /** | ||
backgroundClose: boolean; | ||
readonly isRoute: boolean; | ||
close: () => Promise<void>; | ||
@@ -133,0 +134,0 @@ onclose: import("../utils/types").GuardFunction; |
@@ -11,2 +11,2 @@ import Modal, { ModalOptions } from "../utils/Modal"; | ||
* */ | ||
export default function openModal(component: any, props?: any, options?: ModalOptions): Promise<Modal>; | ||
export default function openModal(component: any, props?: any, options?: Partial<ModalOptions>): Promise<Modal>; |
@@ -5,2 +5,2 @@ import Modal, { ModalOptions } from "../utils/Modal"; | ||
* */ | ||
export default function pushModal(component: any, props?: any, options?: ModalOptions): Promise<Modal>; | ||
export default function pushModal(component: any, props?: any, options?: Partial<ModalOptions>): Promise<Modal>; |
import { ModalOptions } from "./Modal"; | ||
export default function DtoModalOptions(options: ModalOptions): { | ||
backgroundClose: boolean; | ||
}; | ||
export default function DtoModalOptions(options: Partial<ModalOptions>): ModalOptions; |
@@ -7,3 +7,4 @@ /** | ||
export interface ModalOptions { | ||
backgroundClose?: boolean; | ||
backgroundClose: boolean; | ||
isRoute: boolean; | ||
} | ||
@@ -34,2 +35,6 @@ export default class Modal { | ||
/** | ||
* @description If modal was opened like Route instance (useModalRouter) the value is true, otherwise false. | ||
*/ | ||
readonly isRoute: boolean; | ||
/** | ||
* Создаёт объект управления модальным окном. | ||
@@ -43,3 +48,3 @@ * Для управления идентификатором используется статическое поле modalId. | ||
* */ | ||
constructor(component: Component | any, props: any, options: ModalOptions); | ||
constructor(component: Component | any, props: any, options: Partial<ModalOptions>); | ||
/** | ||
@@ -46,0 +51,0 @@ * @description Method for closing the modal window |
@@ -139,2 +139,3 @@ /** | ||
backgroundClose: boolean; | ||
readonly isRoute: boolean; | ||
close: () => Promise<void>; | ||
@@ -141,0 +142,0 @@ onclose: import("./types").GuardFunction; |
/*! | ||
* jenesius-vue-modal v1.7.1 | ||
* jenesius-vue-modal v1.7.2 | ||
* (c) 2022 Jenesius | ||
@@ -426,3 +426,3 @@ * @license MIT | ||
/** | ||
* @description Closing modal window by id. Is local methods (Not for export in index file) | ||
* @description Closing modal window by id. Only this method allows you to change the properties of the event-close. | ||
* */ | ||
@@ -470,5 +470,7 @@ | ||
var output = { | ||
backgroundClose: configuration.backgroundClose | ||
backgroundClose: configuration.backgroundClose, | ||
isRoute: false | ||
}; | ||
if (options.backgroundClose !== undefined) output.backgroundClose = options.backgroundClose; | ||
if (options.isRoute) output.isRoute = options.isRoute; | ||
return output; | ||
@@ -502,2 +504,7 @@ } | ||
this.backgroundClose = true; | ||
/** | ||
* @description If modal was opened like Route instance (useModalRouter) the value is true, otherwise false. | ||
*/ | ||
this.isRoute = false; | ||
this.id = Modal.modalId++; | ||
@@ -538,2 +545,3 @@ this.component = component; | ||
this.backgroundClose = dtoOptions.backgroundClose; | ||
this.isRoute = dtoOptions.isRoute; | ||
} | ||
@@ -659,2 +667,6 @@ /** | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return closeModal().then(function () { | ||
@@ -1024,3 +1036,5 @@ if (modalQueue.value.length) throw ModalError.QueueNoEmpty(); | ||
return (_a = state.router) === null || _a === void 0 ? void 0 : _a.currentRoute.value.params; | ||
}))]; | ||
}), { | ||
isRoute: true | ||
})]; | ||
@@ -1102,5 +1116,7 @@ case 1: | ||
useModalRouter.init = init; | ||
exports.closeById = closeById; | ||
exports.closeModal = closeModal; | ||
exports.config = config; | ||
exports.container = WidgetModalContainer; | ||
exports.getCurrentModal = getCurrentModal; | ||
exports.modalQueue = modalQueue; | ||
@@ -1107,0 +1123,0 @@ exports.onBeforeModalClose = onBeforeModalClose; |
{ | ||
"name": "jenesius-vue-modal", | ||
"version": "1.7.1", | ||
"version": "1.7.2", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Simple modal plugin for Vue3", |
import {mount} from "@vue/test-utils"; | ||
import router from "./router"; | ||
import {nextTick} from "vue"; | ||
import {modalQueue, useModalRouter} from "../../plugin/index"; | ||
import {getCurrentModal, modalQueue, useModalRouter} from "../../plugin/index"; | ||
import wait from "../wait"; | ||
import App from "./App.vue"; | ||
import Modal from "../../plugin/utils/Modal"; | ||
import {render} from "@testing-library/vue"; | ||
@@ -119,21 +121,32 @@ beforeEach(async () => { | ||
it("Back", async () => { | ||
await router.push("/"); | ||
await router.isReady(); | ||
const wrapper = await render(App, {global: {plugins: [router]}}) | ||
//console.log("Start", router.currentRoute.value.path); | ||
await router.push("/users/3"); | ||
const wrapper = await mount(App, {global: {plugins: [router]}}); | ||
await wait(); | ||
// console.log(".", router.currentRoute.value.path); | ||
await nextTick(); | ||
await router.push("/users/3"); | ||
expect(wrapper.container.textContent).toBe("user-3"); | ||
await nextTick(); | ||
await router.back() | ||
await wait(); | ||
expect(wrapper.text()).toBe("user-3"); | ||
// console.log("..", router.currentRoute.value.path); | ||
await router.go(-1); | ||
expect(wrapper.container.textContent).toBe("Test"); | ||
}) | ||
it("Modal.isRoute should be true, when modal was opened by RouterIntegration", async () => { | ||
await router.push("/"); | ||
await router.isReady(); | ||
const wrapper = await mount(App, {global: {plugins: [router]}}); | ||
await nextTick(); | ||
await wait(); | ||
expect(wrapper.text()).toBe("Test"); | ||
await router.push("/router-simple-modal"); | ||
await wait(); | ||
const modal = getCurrentModal() as Modal; | ||
expect(modal.isRoute).toBe(true); | ||
}) | ||
}); |
@@ -1,2 +0,2 @@ | ||
import {createRouter, createWebHistory} from "vue-router"; | ||
import {createRouter, createWebHashHistory} from "vue-router"; | ||
import {useModalRouter} from "../../plugin/index"; | ||
@@ -9,3 +9,3 @@ import ModalRoute from "./ModalRoute.vue"; | ||
const router = createRouter({ | ||
history: createWebHistory(), | ||
history: createWebHashHistory(), | ||
routes: [ | ||
@@ -12,0 +12,0 @@ { |
@@ -51,3 +51,8 @@ import {mount} from "@vue/test-utils"; | ||
}) | ||
test('Modal.isRoute should be false by default', async () => { | ||
const modal = await openModal(ModalTitle); | ||
expect(modal.isRoute).toBe(false); | ||
}) | ||
}) |
@@ -37,3 +37,2 @@ import {mount} from "@vue/test-utils"; | ||
onBeforeModalClose(() => { | ||
console.log("Return false") | ||
return false; | ||
@@ -46,5 +45,2 @@ }) | ||
await closeModal() | ||
.then(() => { | ||
console.log("Easy close") | ||
}) | ||
.catch(() => { | ||
@@ -51,0 +47,0 @@ console.log(modalQueue.value.length) |
106522
2530