Skip to content

Commit 471519e

Browse files
feat: export typing
1 parent 47a64f5 commit 471519e

File tree

7 files changed

+33
-23
lines changed

7 files changed

+33
-23
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"files": [
1515
"dist"
1616
],
17+
"unbuild": {
18+
"failOnWarn": false
19+
},
1720
"scripts": {
1821
"prepack": "nuxt-module-build",
1922
"dev": "nuxi dev .playground",

src/module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { resolve } from 'node:path'
22
import { fileURLToPath } from 'node:url'
33
import { addImports, addPlugin, defineNuxtModule } from '@nuxt/kit'
4-
import type { NinjaToasterBaseProps } from './types'
5-
import { ModuleOptions } from '@nuxt/schema'
4+
import type { ModuleOptions, NinjaToasterBaseProps } from './types'
5+
6+
export * from './types'
67

78
export default defineNuxtModule<ModuleOptions>({
89
meta: {
@@ -50,4 +51,4 @@ declare module '@nuxt/schema' {
5051
interface AppConfigInput {
5152
toaster?: NinjaToasterBaseProps
5253
}
53-
}
54+
}

src/runtime/components/NinjaToaster.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default defineComponent({
219219
})
220220

221221
return () => {
222-
const contentSuspense = () => h(Suspense, null, [content.value])
222+
const contentSuspense = () => h(Suspense, null, content.value)
223223
const wrapper = withDirectives(
224224
h(
225225
'div',
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { useNuxtApp } from '#imports'
2+
import { NinjaToasterInstance } from '../../types'
23

3-
type NinjaToasterInstance = ReturnType<typeof createNinjaToaster>
4-
5-
export function useNinjaToaster() {
4+
export function useNinjaToaster(): NinjaToasterInstance {
65
const { $nt } = useNuxtApp()
7-
return $nt as NinjaToasterInstance
6+
return $nt
87
}

src/runtime/create.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
import { type DefineComponent, type App, type VNode, h, render } from 'vue'
1+
import { type App, type VNode, h, render } from 'vue'
22
import { defu } from 'defu'
33

4-
import type { NinjaToasterTheme, NinjaToasterBaseProps, NinjaToasterProps, NinjaToasterShow } from '../types'
4+
import type { NinjaToasterTheme, NinjaToasterBaseProps, NinjaToasterProps, NinjaToasterShow, NinjaToasterInstance, ComponentProps } from '../types'
55
import type { NinjaToasterRenderQueue } from './queue'
66
import { type NinjaToastEventBus, createEventBus } from './events'
77
import NinjaToaster from './components/NinjaToaster'
88

99
import { resolveComponent, useAppConfig, useNuxtApp } from '#imports'
10-
import type * as _AllComponents from '#components'
11-
12-
type DefaultProps = InstanceType<DefineComponent>['$props']
13-
14-
type ComponentProps<T> = T extends keyof typeof _AllComponents
15-
? Omit<InstanceType<(typeof _AllComponents)[T]>['$props'], keyof DefaultProps>
16-
: undefined
1710

1811
function createElement() {
19-
// @ts-ignore
2012
if (process.server) {
2113
return null
2214
}
@@ -56,11 +48,11 @@ function ensureClassesArray(theme?: NinjaToasterTheme) {
5648

5749
export function createNinjaToaster(
5850
createProps: Omit<NinjaToasterProps, 'content'> = {}
59-
) {
51+
): NinjaToasterInstance {
6052
const events = createEventBus()
6153
const queues: Map<string, NinjaToasterRenderQueue> = new Map()
6254

63-
function showComponent<T extends keyof typeof _AllComponents>(name: T, {
55+
function showComponent<T extends keyof typeof import('#components')>(name: T, {
6456
props,
6557
children,
6658
options,
@@ -110,7 +102,6 @@ export function createNinjaToaster(
110102
}
111103
})
112104

113-
// @ts-ignore
114105
if (process.server) {
115106
resolve({
116107
el: null,

src/runtime/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createNinjaToaster } from './create'
22

3-
// @ts-ignore
43
import { defineNuxtPlugin } from '#imports'
54

65
export default defineNuxtPlugin(() => {

src/types.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Ref, Component, TransitionProps } from 'vue'
1+
import type { VNode, DefineComponent, Ref, Component, TransitionProps } from 'vue'
22

33
export interface ModuleOptions {
44
installPlugin?: boolean
@@ -48,4 +48,21 @@ export interface NinjaToasterState {
4848
duration: number
4949
click: (event: Event) => void | Promise<void>
5050
close: () => void | Promise<void>
51+
}
52+
53+
export type DefaultProps = InstanceType<DefineComponent>['$props']
54+
55+
export type ComponentProps<T> = T extends keyof typeof import('#components')
56+
? Omit<InstanceType<(typeof import('#components'))[T]>['$props'], keyof DefaultProps>
57+
: undefined
58+
59+
export interface NinjaToasterInstance {
60+
showComponent: <T extends keyof typeof import('#components')>(name: T, params: {
61+
props?: ComponentProps<T>,
62+
children?: any
63+
options?: Omit<NinjaToasterProps, 'content'>
64+
}) => Promise<NinjaToasterShow>
65+
show: (options: NinjaToasterProps | string | number | (() => VNode)) => Promise<NinjaToasterShow>
66+
clear: (theme: NinjaToasterTheme | string) => void
67+
clearAll: () => void
5168
}

0 commit comments

Comments
 (0)