Skip to content

Commit e528f81

Browse files
committed
fix: update StSayHello component registration and type definitions
1 parent d59c0cb commit e528f81

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

src/components.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { Plugin } from 'vue'
12
import StSayHello from './say-hello'
23

34
export * from './say-hello'
45

56
export const components = [
67
StSayHello,
7-
]
8+
] as Plugin[]
89

910
export default components

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export * from './resolver'
77
const installer = createInstaller(components)
88

99
export const install = installer.install
10+
export const version = installer.version
1011

1112
export default installer

src/say-hello/SayHello.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<script lang="ts" setup>
2+
defineOptions({
3+
name: 'StSayHello',
4+
})
5+
26
const { name } = defineProps<{
37
name: string
48
}>()

src/say-hello/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { InstallWithSFC } from '../utils'
12
import { installWithSFC } from '../utils'
23
import SayHello from './SayHello.vue'
34

45
export type SayHelloInstance = InstanceType<typeof SayHello>
56

6-
export const StSayHello = installWithSFC(SayHello)
7+
export const StSayHello: InstallWithSFC<typeof SayHello> = installWithSFC(SayHello)
78

89
export default StSayHello

src/utils/installer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import type { Plugin } from 'vue'
1+
import type { App, Plugin } from 'vue'
22
import type { InstallOptions } from './types'
33
import { version } from '../../package.json'
44
import { provideGlobalConfig } from './global-config'
55

6-
export const INSTALLED_KEY = Symbol('STARTER_LIB_VUE3_INSTALLED_KEY')
6+
export const INSTALLED_KEY = Symbol('INSTALLED_KEY')
77

8-
export function createInstaller(components: Plugin[] = []): { install: (app: any, options?: InstallOptions) => void, version: string } {
9-
const install = (app: any, options?: InstallOptions): void => {
8+
declare module 'vue' {
9+
interface App {
10+
[INSTALLED_KEY]?: boolean
11+
}
12+
}
13+
14+
export function createInstaller(components: Plugin[] = []): { install: (app: App, options?: InstallOptions) => void, version: string } {
15+
const install = (app: App, options?: InstallOptions): void => {
1016
if (app[INSTALLED_KEY])
1117
return
1218

src/utils/types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import type { App, AppContext, InjectionKey, Plugin, Ref } from 'vue'
1+
import type { App, InjectionKey, Plugin, Ref } from 'vue'
22

33
export type MaybeRef<T> = T | Ref<T>
44

55
export interface InstallOptions {
6-
zIndex?: MaybeRef<number>
76
size?: MaybeRef<string>
87
}
98

109
export type ProvideFn = (<T>(key: string | InjectionKey<T>, value: T) => App<any>) | (<T>(key: string | number | InjectionKey<T>, value: T) => void) | undefined
1110

1211
export type InstallWithSFC<T> = T & Plugin
13-
14-
export type InstallWithContext<T> = InstallWithSFC<T> & {
15-
_context: AppContext | null
16-
}

src/utils/with-install.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
import type { App } from 'vue'
2-
import type { InstallWithContext, InstallWithSFC } from './types'
2+
import type { InstallWithSFC } from './types'
33

44
export function installWithSFC<T, E extends Record<string, any>>(main: T, extra?: E): InstallWithSFC<T> & E {
5-
(main as InstallWithSFC<T>).install = (app: App): void => {
6-
for (const comp of [main, ...Object.values(extra ?? {})])
5+
;(main as InstallWithSFC<T>).install = (app: App): void => {
6+
for (const comp of [main, ...Object.values(extra ?? {})]) {
77
app.component(comp.name, comp)
8+
}
89
}
9-
1010
if (extra) {
11-
for (const [key, comp] of Object.entries(extra))
12-
(main as any)[key] = comp
11+
for (const [key, comp] of Object.entries(extra)) {
12+
;(main as any)[key] = comp
13+
}
1314
}
1415
return main as InstallWithSFC<T> & E
1516
}
16-
17-
export function installWithFunction<T>(fn: T, name: string): InstallWithContext<T> {
18-
(fn as InstallWithSFC<T>).install = (app: App) => {
19-
; (fn as InstallWithContext<T>)._context = app._context
20-
app.config.globalProperties[name] = fn
21-
}
22-
23-
return fn as InstallWithContext<T>
24-
}

src/volar.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
declare module '@vue/runtime-core' {
1+
declare module 'vue' {
22
export interface GlobalComponents {
3-
SayHello: typeof import('starter-lib-vue3')['SayHello']
3+
StSayHello: typeof import('starter-lib-vue3')['StSayHello']
44
}
55
}
66

0 commit comments

Comments
 (0)