Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stop() for @beforeOpen and beforeClose event #367 #402

Merged
merged 14 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pnpm build:vfm
# Run both docs and viteplay
pnpm dev

# Run dev for vue-final-modal
pnpm dev:vfm

# Run docs: http://localhost:3000/
pnpm dev:docs

Expand Down
8 changes: 5 additions & 3 deletions docs/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ export default defineAppConfig({
docus: {
title: 'Vue Final Modal',
description: 'Vue Final Modal is the most powerful yet most light-weight modal library for Vue 3',
layout: 'docs',
layout: 'default',
image: 'https://vue-final-modal.org/preview.png',
url: 'https://vue-final-modal.org',
socials: {
twitter: '@hunterliu1003',
github: 'vue-final/vue-final-modal',
},
github: true,
aside: {
level: 1,
},
header: {
logo: true,
logo: {
dark: '/logo-new.svg',
light: '/logo-new.svg',
},
},
footer: {},
},
Expand Down
4 changes: 3 additions & 1 deletion docs/components/content/LoginFormVorms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const { value: remember, attrs: rememberAttrs } = register('remember')
</script>

<template>
<h1 class="text-2xl mb-4">Login</h1>
<h1 class="text-2xl mb-4">
Login
</h1>
<form @submit="handleSubmit">
<div class="field">
<input
Expand Down
20 changes: 0 additions & 20 deletions docs/components/content/Logo.vue

This file was deleted.

4 changes: 3 additions & 1 deletion docs/components/content/ModalBottom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ defineProps<{
<h1 class="text-xl">
{{ title }}
</h1>
<div class="text-3xl">Swipe down to close the modal</div>
<div class="text-3xl">
Swipe down to close the modal
</div>
<slot />
</VueFinalModal>
</template>
5 changes: 0 additions & 5 deletions docs/content/2.get-started/1.guide/3.migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ open()
`params` is not a good practice and hard to keep type-save in Typescript.
So if you are using `params`, you have to re-written it with [useModal()](/api/composables/use-modal) composable.

### Removed `event.stop()` from both `@before-close` and `@before-open`

`event.stop()` made the source code hard to read and maintain.
It's easy to have a condition before open or before close the modal. So it's not a required feature.

### Delete Drag & Resize

To keep vue-final-modal simple and easier to maintain, I decided to remove the Drag & Resize feature.
Expand Down
22 changes: 8 additions & 14 deletions docs/content/2.get-started/1.guide/4.types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

The exported types in VueFinalModal.

## ComponentProps

```ts
export type ComponentProps = ComponentPublicInstance['$props']
```

## ModalId

```ts
Expand All @@ -23,18 +17,18 @@ export type StyleValue = string | CSSProperties | (string | CSSProperties)[]
## ModalSlot

```ts
export interface ModalSlotOptions { component: Raw<Component>; attrs?: Record<string, any> }
export type ModalSlot = string | Component | ModalSlotOptions
export interface ModalSlotOptions { component: Raw<ComponentType>; attrs?: Record<string, any> }
export type ModalSlot = string | ComponentType | ModalSlotOptions
```

## UseModalOptions

```ts
export type UseModalOptions<P> = {
export type UseModalOptions<T extends ComponentType> = {
defaultModelValue?: boolean
keepAlive?: boolean
component?: Constructor<P>
attrs?: (RawProps & P) | ({} extends P ? null : never)
component?: T
attrs?: ComponentProps<T>
slots?: {
[key: string]: ModalSlot
}
Expand All @@ -55,11 +49,11 @@ export type UseModalOptionsPrivate = {
## UseModalReturnType

```ts
export interface UseModalReturnType<P> {
options: UseModalOptions<P> & UseModalOptionsPrivate
export interface UseModalReturnType<T extends ComponentType> {
options: UseModalOptions<T> & UseModalOptionsPrivate
open: () => Promise<string>
close: () => Promise<string>
patchOptions: (options: Partial<UseModalOptions<P>>) => void
patchOptions: (options: Partial<UseModalOptions<T>>) => void
destroy: () => void
}
```
Expand Down
6 changes: 4 additions & 2 deletions docs/content/3.api/1.components/1.vue-final-modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ When set `:preventNavigationGestures="true"`{lang=ts}, there will be two invisib

## Events

- `(e: 'beforeOpen'): void`{lang=ts}: Emits while modal is still invisible, but before transition starting.
- `(e: 'beforeOpen', event: { stop: () => void }): void`{lang=ts}: Emits while modal is still invisible, but before transition starting.
- `event.stop()` is use to prevent the modal from opening.
- `(e: 'opened'): void`{lang=ts}: Emits after modal became visible and transition ended.
- `(e: 'beforeClose'): void`{lang=ts}: Emits before modal is going to be closed.
- `(e: 'beforeClose', event: { stop: () => void }): void`{lang=ts}: Emits before modal is going to be closed.
- `event.stop()` is use to prevent the modal from closing.
- `(e: 'closed'): void`{lang=ts}: Emits right before modal is destroyed.
- `(e: 'clickOutside'): void`{lang=ts}: Emits while `.vfm` element on click.

Expand Down
1 change: 1 addition & 0 deletions docs/content/3.api/2.composables/1.use-modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const { open, close, destroy, options, patchOptions } = useModal({
clickToClose: true,
escToClose: true,
// Bind events to the modal component (VueFinalModal in this case).
// Any custom events can be listened for when prefixed with "on", e.g. "onEventName".
onBeforeOpen() { /* on before open */ },
onOpened() { /* on opened */ },
onBeforeClose() { /* on before close */ },
Expand Down
6 changes: 3 additions & 3 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"preview": "nuxi preview"
},
"devDependencies": {
"@nuxt-themes/docus": "^1.10.1",
"@nuxtjs/tailwindcss": "^6.6.4",
"nuxt": "^3.3.2"
"@nuxt-themes/docus": "^1.15.0",
"@nuxtjs/tailwindcss": "^6.10.1",
"nuxt": "^3.8.2"
},
"dependencies": {
"@vorms/core": "^1.1.0",
Expand Down
3 changes: 1 addition & 2 deletions examples/nuxt3/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default defineNuxtConfig({
extends: '@nuxt-themes/docus',
modules: ['@nuxtjs/tailwindcss'],
css: ['vue-final-modal/style.css'],
modules: ['@nuxtjs/tailwindcss', '@vue-final-modal/nuxt'],
})
6 changes: 3 additions & 3 deletions examples/nuxt3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@nuxt-themes/docus": "^1.6.0",
"@nuxtjs/tailwindcss": "^6.2.0",
"nuxt": "3.1.0"
"@nuxt-themes/docus": "^1.15.0",
"@nuxtjs/tailwindcss": "^6.10.1",
"nuxt": "3.8.2"
},
"dependencies": {
"@vue-final-modal/nuxt": "^1.0.2",
Expand Down
6 changes: 0 additions & 6 deletions examples/nuxt3/plugins/vfm.ts

This file was deleted.

19 changes: 9 additions & 10 deletions examples/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.4",
"vue": "^3.3.7",
"vue-final-modal": "^4.4.6"
},
"devDependencies": {
"@iconify/vue": "^4.0.0",
"@vitejs/plugin-vue": "^4.2.3",
"autoprefixer": "^10.4.13",
"postcss": "^8.4.21",
"tailwindcss": "^3.2.4",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vue-tsc": "^1.8.3"
"@iconify/vue": "^4.1.1",
"@vitejs/plugin-vue": "^4.5.0",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.5",
"typescript": "^5.3.2",
"vite": "^5.0.3"
}
}
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vfm",
"private": true,
"scripts": {
"dev": "concurrently \"pnpm:dev:*\"",
"dev": "concurrently \"pnpm:dev:docs\" \"pnpm:dev:viteplay\"",
"dev:docs": "pnpm --filter docs dev",
"build:docs": "pnpm --filter docs build",
"generate:docs": "pnpm --filter docs generate",
Expand All @@ -18,19 +18,18 @@
"postinstall": "pnpm build:vfm && pnpm prepare:module"
},
"dependencies": {
"vue": "^3.3.4"
"vue": "^3.3.7"
},
"devDependencies": {
"@antfu/eslint-config": "^0.37.0",
"@types/node": "^18.15.10",
"@vitejs/plugin-vue": "^4.2.3",
"@types/node": "^20.10.0",
"@vitejs/plugin-vue": "^4.5.0",
"@vue/test-utils": "^2.3.2",
"concurrently": "^7.6.0",
"concurrently": "^8.2.2",
"eslint": "^8.36.0",
"pnpm": "^8.10.2",
"sass": "^1.60.0",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vue-tsc": "^1.8.3"
"pnpm": "^8.11.0",
"typescript": "^5.3.2",
"vite": "^5.0.3",
"vue-tsc": "1.8.20"
}
}
10 changes: 5 additions & 5 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"release": "pnpm prepack && release-it"
},
"dependencies": {
"@nuxt/kit": "^3.3.2",
"@nuxt/kit": "^3.8.2",
"vue-final-modal": "^4.4.6"
},
"devDependencies": {
"@nuxt/module-builder": "^0.2.1",
"@nuxt/schema": "^3.3.2",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"nuxt": "^3.3.2",
"@nuxt/module-builder": "^0.5.4",
"@nuxt/schema": "^3.8.2",
"@nuxtjs/eslint-config-typescript": "^12.1.0",
"nuxt": "^3.8.2",
"release-it": "^16.1.3"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export default defineNuxtModule({
configKey: 'vue-final-modal',
},
setup(options, nuxt) {
const resolver = createResolver(import.meta.url)
const { resolve } = createResolver(import.meta.url)

// Transpile runtime
nuxt.options.build.transpile.push(resolver.resolve('./runtime'))
nuxt.options.build.transpile.push(resolve('./runtime'))

nuxt.hook('prepare:types', ({ references }) => {
references.push({ types: '@vue-final-modal/nuxt' })
Expand All @@ -18,7 +18,7 @@ export default defineNuxtModule({
// Add runtime plugin before the router plugin
// https://github.com/nuxt/framework/issues/9130
nuxt.hook('modules:done', () => {
addPlugin(resolver.resolve('./runtime/plugin'))
addPlugin(resolve('./runtime/plugin'))
})

nuxt.options.css.push('vue-final-modal/style.css')
Expand Down
11 changes: 6 additions & 5 deletions packages/vue-final-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "vue-final-modal",
"private": false,
"version": "4.4.6",
"type": "module",
"source": "src/index.ts",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
Expand All @@ -21,8 +22,8 @@
"dist"
],
"scripts": {
"dev": "vue-tsc --noEmit && vite build -w",
"build": "vue-tsc --noEmit && vite build && vue-tsc -p tsconfig.build-dts.json --declaration --emitDeclarationOnly && tsc-alias -p tsconfig.build-dts.json",
"dev": "vite build -w",
"build": "vite build",
"cypress:open": "cypress open --browser chrome --component",
"cypress:run": "cypress run --browser chrome --component",
"typecheck": "vue-tsc --noEmit",
Expand All @@ -37,12 +38,12 @@
"@cypress/vue": "^5.0.5",
"@release-it/conventional-changelog": "^5.1.1",
"@vue-macros/volar": "^0.8.4",
"cypress": "^12.16.0",
"cypress": "^13.6.0",
"release-it": "^16.1.3",
"tsc-alias": "^1.8.7",
"unplugin-vue-define-options": "^1.3.8",
"unplugin-vue-macros": "^2.3.0",
"vue": "^3.3.4"
"vite-plugin-dts": "^3.6.3",
"vue": "^3.3.7"
},
"peerDependencies": {
"@vueuse/core": ">=10.0.0",
Expand Down
Loading