1
1
import { ComponentResolver } from '../types'
2
2
import { kebabCase } from '../utils'
3
3
4
- const getSideEffects : (
5
- compName : string ,
6
- ) => string [ ] = ( compName ) => {
4
+ function getSideEffects ( componentName : string ) {
7
5
const sideEffects = [
8
6
'view-design/dist/styles/iview.css' ,
9
7
'popper.js/dist/umd/popper.js' ,
10
8
]
11
9
12
- if ( / ^ T a b l e / . test ( compName ) )
10
+ if ( / ^ T a b l e / . test ( componentName ) )
13
11
sideEffects . push ( 'element-resize-detector' )
14
12
15
- if ( / ^ D a t e / . test ( compName ) )
13
+ if ( / ^ D a t e / . test ( componentName ) )
16
14
sideEffects . push ( 'js-calendar' )
17
15
18
16
return sideEffects
@@ -25,8 +23,8 @@ const matchComponents = [
25
23
} ,
26
24
]
27
25
28
- const getCompDir = ( compName : string ) : string => {
29
- let compPath : string | undefined
26
+ function getCompDir ( compName : string ) : string {
27
+ let compPath : string | undefined
30
28
31
29
const total = matchComponents . length
32
30
for ( let i = 0 ; i < total ; i ++ ) {
@@ -36,7 +34,9 @@ const getCompDir = (compName: string): string => {
36
34
break
37
35
}
38
36
}
39
- if ( ! compPath ) compPath = kebabCase ( compName )
37
+ if ( ! compPath )
38
+ compPath = kebabCase ( compName )
39
+
40
40
return compPath
41
41
}
42
42
@@ -49,12 +49,14 @@ const getCompDir = (compName: string): string => {
49
49
* - select component render error PR: https://github.com/view-design/ViewUI/pull/944, choose can't display value,because click option trigger twice,at second time,select value turn into undefined.
50
50
* - scroll component has a template syntax called lang='html',it is require html-loader,but vite plugin not support yet,remove it can run.
51
51
*/
52
- export const ViewUiResolver = ( ) : ComponentResolver => ( name : string ) => {
53
- if ( name . match ( / ^ I [ A - Z ] / ) ) {
54
- const compName = name . slice ( 1 )
55
- return {
56
- path : `view-design/src/components/${ getCompDir ( compName ) } ` ,
57
- sideEffects : getSideEffects ( compName ) ,
52
+ export function ViewUiResolver ( ) : ComponentResolver {
53
+ return ( name : string ) => {
54
+ if ( name . match ( / ^ I [ A - Z ] / ) ) {
55
+ const compName = name . slice ( 1 )
56
+ return {
57
+ path : `view-design/src/components/${ getCompDir ( compName ) } ` ,
58
+ sideEffects : getSideEffects ( compName ) ,
59
+ }
58
60
}
59
61
}
60
62
}
0 commit comments