11import { ComponentResolver } from '../types'
22import { kebabCase } from '../utils'
33
4- const getSideEffects : (
5- compName : string ,
6- ) => string [ ] = ( compName ) => {
4+ function getSideEffects ( componentName : string ) {
75 const sideEffects = [
86 'view-design/dist/styles/iview.css' ,
97 'popper.js/dist/umd/popper.js' ,
108 ]
119
12- if ( / ^ T a b l e / . test ( compName ) )
10+ if ( / ^ T a b l e / . test ( componentName ) )
1311 sideEffects . push ( 'element-resize-detector' )
1412
15- if ( / ^ D a t e / . test ( compName ) )
13+ if ( / ^ D a t e / . test ( componentName ) )
1614 sideEffects . push ( 'js-calendar' )
1715
1816 return sideEffects
@@ -25,8 +23,8 @@ const matchComponents = [
2523 } ,
2624]
2725
28- const getCompDir = ( compName : string ) : string => {
29- let compPath : string | undefined
26+ function getCompDir ( compName : string ) : string {
27+ let compPath : string | undefined
3028
3129 const total = matchComponents . length
3230 for ( let i = 0 ; i < total ; i ++ ) {
@@ -36,7 +34,9 @@ const getCompDir = (compName: string): string => {
3634 break
3735 }
3836 }
39- if ( ! compPath ) compPath = kebabCase ( compName )
37+ if ( ! compPath )
38+ compPath = kebabCase ( compName )
39+
4040 return compPath
4141}
4242
@@ -49,12 +49,14 @@ const getCompDir = (compName: string): string => {
4949 * - 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.
5050 * - scroll component has a template syntax called lang='html',it is require html-loader,but vite plugin not support yet,remove it can run.
5151 */
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+ }
5860 }
5961 }
6062}
0 commit comments