chore(utils): 代码格式调整
This commit is contained in:
parent
a3901d9c19
commit
1e18564352
@ -9,107 +9,107 @@
|
|||||||
const matchComponents = [
|
const matchComponents = [
|
||||||
{
|
{
|
||||||
pattern: /^LayAvatarList$/,
|
pattern: /^LayAvatarList$/,
|
||||||
styleDir: 'avatar',
|
styleDir: "avatar",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayBreadcrumb|LayBreadcrumbItem)$/,
|
pattern: /^(LayBreadcrumb|LayBreadcrumbItem)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayCarousel|LayCarouselItem)$/,
|
pattern: /^(LayCarousel|LayCarouselItem)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayCheckbox|LayCheckboxGroup)$/,
|
pattern: /^(LayCheckbox|LayCheckboxGroup)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayCol$/,
|
pattern: /^LayCol$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayCollapse|LayCollapseItem)$/,
|
pattern: /^(LayCollapse|LayCollapseItem)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
// 无 css
|
// 无 css
|
||||||
{
|
{
|
||||||
pattern: /^LayCountUp$/,
|
pattern: /^LayCountUp$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayDropdown|LayDropdownItem)$/,
|
pattern: /^(LayDropdown|LayDropdownItem)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
// 可能有未拆分的
|
// 可能有未拆分的
|
||||||
{
|
{
|
||||||
pattern: /^(LayForm|LayFormItem)$/,
|
pattern: /^(LayForm|LayFormItem)$/,
|
||||||
styleDir: 'formItem',
|
styleDir: "formItem",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayHeader)$/,
|
pattern: /^(LayHeader)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayLine$/,
|
pattern: /^LayLine$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayLogo$/,
|
pattern: /^LayLogo$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayMenuItem|LaySubMenu)$/,
|
pattern: /^(LayMenuItem|LaySubMenu)$/,
|
||||||
styleDir: 'menu',
|
styleDir: "menu",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayPage$/,
|
pattern: /^LayPage$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayProgress$/,
|
pattern: /^LayProgress$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayRadio$/,
|
pattern: /^LayRadio$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayScroll$/,
|
pattern: /^LayScroll$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LaySelectOption$/,
|
pattern: /^LaySelectOption$/,
|
||||||
styleDir: 'select',
|
styleDir: "select",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LaySkeletonItem$/,
|
pattern: /^LaySkeletonItem$/,
|
||||||
styleDir: 'skeleton',
|
styleDir: "skeleton",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LaySplitPanelItem$/,
|
pattern: /^LaySplitPanelItem$/,
|
||||||
styleDir: 'splitPanel',
|
styleDir: "splitPanel",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayStepItem$/,
|
pattern: /^LayStepItem$/,
|
||||||
styleDir: 'step',
|
styleDir: "step",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LaySwitch$/,
|
pattern: /^LaySwitch$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^(LayTab|LayTabItem)$/,
|
pattern: /^(LayTab|LayTabItem)$/,
|
||||||
styleDir: '',
|
styleDir: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayTimelineItem$/,
|
pattern: /^LayTimelineItem$/,
|
||||||
styleDir: 'timeline',
|
styleDir: "timeline",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^LayTolltip$/,
|
pattern: /^LayTolltip$/,
|
||||||
styleDir: 'popper',
|
styleDir: "popper",
|
||||||
},
|
},
|
||||||
]
|
];
|
||||||
|
|
||||||
export interface LayuiVueResolverOptions {
|
export interface LayuiVueResolverOptions {
|
||||||
/**
|
/**
|
||||||
@ -117,7 +117,7 @@ export interface LayuiVueResolverOptions {
|
|||||||
*
|
*
|
||||||
* @default 'css'
|
* @default 'css'
|
||||||
*/
|
*/
|
||||||
importStyle?: boolean | 'css'
|
importStyle?: boolean | "css";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* resolve `@layui/layui-vue' icons
|
* resolve `@layui/layui-vue' icons
|
||||||
@ -125,47 +125,46 @@ export interface LayuiVueResolverOptions {
|
|||||||
*
|
*
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
resolveIcons?: boolean
|
resolveIcons?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* exclude components that do not require automatic import
|
* exclude components that do not require automatic import
|
||||||
* @default []
|
* @default []
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
exclude?: string[]
|
exclude?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const libRE = /^Lay[A-Z]/
|
const libRE = /^Lay[A-Z]/;
|
||||||
const layerRE = /^(layer|LayLayer)$/
|
const layerRE = /^(layer|LayLayer)$/;
|
||||||
const iconsRE = /^([A-Z][\w]+Icon|LayIcon)$/
|
const iconsRE = /^([A-Z][\w]+Icon|LayIcon)$/;
|
||||||
const esComponentsFolder = '@layui/layui-vue/es'
|
const esComponentsFolder = "@layui/layui-vue/es";
|
||||||
|
|
||||||
function lowerCamelCase(str: string) {
|
function lowerCamelCase(str: string) {
|
||||||
return str.charAt(0).toLowerCase() + str.slice(1)
|
return str.charAt(0).toLowerCase() + str.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSideEffects(importName: string, options: LayuiVueResolverOptions) {
|
function getSideEffects(importName: string, options: LayuiVueResolverOptions) {
|
||||||
const { importStyle = true } = options
|
const { importStyle = true } = options;
|
||||||
if (!importStyle) return
|
if (!importStyle) return;
|
||||||
|
|
||||||
let styleDir: string | undefined = undefined
|
let styleDir: string | undefined = undefined;
|
||||||
if (importName.match(iconsRE)) {
|
if (importName.match(iconsRE)) {
|
||||||
return `@layui/icons-vue/lib/index.css`
|
return `@layui/icons-vue/lib/index.css`;
|
||||||
} else if (importName.match(layerRE)) {
|
} else if (importName.match(layerRE)) {
|
||||||
return `@layui/layer-vue/lib/index.css`
|
return `@layui/layer-vue/lib/index.css`;
|
||||||
} else if (importName.match(libRE)) {
|
} else if (importName.match(libRE)) {
|
||||||
styleDir = lowerCamelCase(importName.slice(3))// LayBackTop -> backTop
|
styleDir = lowerCamelCase(importName.slice(3)); // LayBackTop -> backTop
|
||||||
for (const item of matchComponents) {
|
for (const item of matchComponents) {
|
||||||
if (item.pattern.test(importName)) {
|
if (item.pattern.test(importName)) {
|
||||||
styleDir = item.styleDir
|
styleDir = item.styleDir;
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME 临时方案,部分组件样式未拆分
|
// FIXME 临时方案,部分组件样式未拆分
|
||||||
// return styleDir ? `${esComponentsFolder}/${styleDir}/index.css` : `@layui/layui-vue/lib/index.css`
|
// return styleDir ? `${esComponentsFolder}/${styleDir}/index.css` : `@layui/layui-vue/lib/index.css`
|
||||||
return styleDir ? `${esComponentsFolder}/${styleDir}/index.css` : undefined
|
return styleDir ? `${esComponentsFolder}/${styleDir}/index.css` : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveComponent(name: string, options: LayuiVueResolverOptions) {
|
function resolveComponent(name: string, options: LayuiVueResolverOptions) {
|
||||||
@ -174,20 +173,20 @@ function resolveComponent(name: string, options: LayuiVueResolverOptions) {
|
|||||||
let sideEffects: string | string[] | undefined;
|
let sideEffects: string | string[] | undefined;
|
||||||
|
|
||||||
if (options.resolveIcons && name.match(iconsRE)) {
|
if (options.resolveIcons && name.match(iconsRE)) {
|
||||||
importName = name
|
importName = name;
|
||||||
path = `@layui/icons-vue`
|
path = `@layui/icons-vue`;
|
||||||
sideEffects = getSideEffects(name, options)
|
sideEffects = getSideEffects(name, options);
|
||||||
} else if (name.match(layerRE)) {
|
} else if (name.match(layerRE)) {
|
||||||
importName = name
|
importName = name;
|
||||||
path = `@layui/layer-vue`
|
path = `@layui/layer-vue`;
|
||||||
sideEffects = getSideEffects(name, options)
|
sideEffects = getSideEffects(name, options);
|
||||||
} else if (name.match(libRE) && !options?.exclude?.includes(name)) {
|
} else if (name.match(libRE) && !options?.exclude?.includes(name)) {
|
||||||
importName = name;
|
importName = name;
|
||||||
path = `@layui/layui-vue`
|
path = `@layui/layui-vue`;
|
||||||
sideEffects = getSideEffects(name, options)
|
sideEffects = getSideEffects(name, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
return importName ? { importName, path, sideEffects } : null
|
return importName ? { importName, path, sideEffects } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,9 +197,9 @@ function resolveComponent(name: string, options: LayuiVueResolverOptions) {
|
|||||||
*/
|
*/
|
||||||
export function LayuiVueResolver(options: LayuiVueResolverOptions = {}) {
|
export function LayuiVueResolver(options: LayuiVueResolverOptions = {}) {
|
||||||
return {
|
return {
|
||||||
type: 'component',
|
type: "component",
|
||||||
resolve: (name: string) => {
|
resolve: (name: string) => {
|
||||||
return resolveComponent(name, options)
|
return resolveComponent(name, options);
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user