Skip to content

Commit 89e168a

Browse files
authored
feat: view-ui resolver (unplugin#101)
1 parent 42ec317 commit 89e168a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/resolvers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './vuetify'
66
export * from './vueuse'
77
export * from './naive-ui'
88
export * from './varlet-ui'
9+
export * from './view-ui'

src/resolvers/view-ui.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { ComponentResolver } from '../types'
2+
import { kebabCase } from '../utils'
3+
4+
const getSideEffects: (
5+
compName: string,
6+
) => string[] = (compName) => {
7+
const sideEffects = [
8+
'view-design/dist/styles/iview.css',
9+
'popper.js/dist/umd/popper.js',
10+
]
11+
12+
if (/^Table/.test(compName))
13+
sideEffects.push('element-resize-detector')
14+
15+
if (/^Date/.test(compName))
16+
sideEffects.push('js-calendar')
17+
18+
return sideEffects
19+
}
20+
21+
const matchComponents = [
22+
{
23+
pattern: /^List/,
24+
compDir: 'list',
25+
},
26+
]
27+
28+
const getCompDir = (compName: string): string => {
29+
let compPath: string|undefined
30+
31+
const total = matchComponents.length
32+
for (let i = 0; i < total; i++) {
33+
const matcher = matchComponents[i]
34+
if (compName.match(matcher.pattern)) {
35+
compPath = `${matcher.compDir}/${kebabCase(compName)}.vue`
36+
break
37+
}
38+
}
39+
if (!compPath) compPath = kebabCase(compName)
40+
return compPath
41+
}
42+
43+
/**
44+
* Resolver for View UI
45+
* @requires @originjs/vite-plugin-commonjs
46+
* @author @nabaonan
47+
* @link https://www.iviewui.com/
48+
* @description has known problems list below
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+
* - 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+
*/
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),
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy