1
1
import { defineComponent } from 'vue' ;
2
- import { toBaseReverse } from './utils'
2
+ import { obtainSlot , toBaseReverse } from './utils'
3
3
import { build as optionComputed } from './option/computed'
4
4
import { build as optionData } from './option/data'
5
5
import { build as optionMethodsAndLifecycle } from './option/methodsAndLifecycle'
6
6
import { build as optionRef } from './option/ref'
7
7
import { build as optionWatch , WatchConfig } from './option/watch'
8
8
import { build as optionProps , PropsConfig } from './option/props'
9
9
import { build as optionInject , InjectConfig } from './option/inject'
10
+ import { build as optionEmit } from './option/emit'
10
11
export interface OptionBuilder {
11
12
name ?: string
12
13
data ?: Record < string , any >
@@ -16,6 +17,7 @@ export interface OptionBuilder {
16
17
watch ?: Record < string , WatchConfig >
17
18
props ?: Record < string , PropsConfig >
18
19
inject ?: Record < string , InjectConfig >
20
+
19
21
}
20
22
export interface Cons { new ( ) : any , prototype : any }
21
23
function ComponentOption ( cons : Cons ) {
@@ -24,6 +26,7 @@ function ComponentOption(cons: Cons) {
24
26
optionWatch ( cons , optionBuilder )
25
27
optionProps ( cons , optionBuilder )
26
28
optionInject ( cons , optionBuilder )
29
+ optionEmit ( cons , optionBuilder )
27
30
optionMethodsAndLifecycle ( cons , optionBuilder )
28
31
optionRef ( cons , optionBuilder )
29
32
@@ -37,7 +40,7 @@ function ComponentOption(cons: Cons) {
37
40
computed : optionBuilder . computed ,
38
41
watch : optionBuilder . watch ,
39
42
props : optionBuilder . props ,
40
- inject :optionBuilder . inject ,
43
+ inject : optionBuilder . inject ,
41
44
...optionBuilder . lifecycle
42
45
}
43
46
return raw as any
@@ -47,28 +50,44 @@ export function Component(arg: Cons | {
47
50
name ?: string
48
51
emits ?: string [ ]
49
52
provide ?: Record < string , any > | Function
50
- components ?:Record < string , any >
53
+ components ?: Record < string , any >
54
+ directives ?: Record < string , any > ;
55
+ inheritAttrs ?: boolean ;
56
+ expose ?: string [ ] ;
51
57
modifier ?: ( raw : any ) => any
52
58
} ) : any {
53
59
if ( typeof arg === 'function' ) {
54
60
return defineComponent ( ComponentOption ( arg ) )
55
61
}
56
62
return function ( cons : Cons ) {
57
63
let option = ComponentOption ( cons )
64
+ const slot = obtainSlot ( cons . prototype )
58
65
if ( typeof arg . name !== 'undefined' ) {
59
66
option . name = arg . name
60
67
}
68
+
69
+ let emits = Array . from ( slot . obtainMap ( 'emits' ) . keys ( ) )
61
70
if ( Array . isArray ( arg . emits ) ) {
62
- option . emits = arg . emits
71
+ emits = Array . from ( new Set ( [ ... emits , ... arg . emits ] ) )
63
72
}
64
- if ( arg . components ) {
65
- option . components = arg . components
73
+ option . emits = emits
74
+
75
+
76
+ if ( arg . components ) {
77
+ option . components = arg . components
66
78
}
67
79
if ( arg . provide ) {
68
80
option . provide = arg . provide
69
81
}
70
-
71
-
82
+ if ( arg . directives ) {
83
+ option . directives = arg . directives
84
+ }
85
+ if ( arg . inheritAttrs ) {
86
+ option . inheritAttrs = arg . inheritAttrs
87
+ }
88
+ if ( arg . expose ) {
89
+ option . expose = arg . expose
90
+ }
72
91
if ( arg . modifier ) {
73
92
option = arg . modifier ( option )
74
93
}
0 commit comments