dm-vue3-ui
Version:
This Components Library will help get you started developing in Vue 3.
145 lines (144 loc) • 3.3 kB
JavaScript
const primitiveNames = [
"Button",
"Catalogue",
"CronPicker",
"DatePicker",
"PreviewCode",
"MultipleFilter",
"Modal",
"Drawer",
"CronTab",
"Switch"
];
const matchComponents = [
{
pattern: /^Button/,
styleDir: "button"
},
{
pattern: /^Catalogue/,
styleDir: "catalogue"
},
{
pattern: /^CronPicker/,
styleDir: "cron-picker"
},
{
pattern: /^DatePicker/,
styleDir: "date-picker"
},
{
pattern: /^PreviewCode/,
styleDir: "preview-code"
},
{
pattern: /^Modal/,
styleDir: "modal"
},
{
pattern: /^Drawer/,
styleDir: "drawer"
},
{
pattern: /^CronTab/,
styleDir: "cron-tab"
},
{
pattern: /^Switch/,
styleDir: "switch"
}
];
function getStyleDir(compName) {
let styleDir;
const total = matchComponents.length;
for (let i = 0; i < total; i++) {
const matcher = matchComponents[i];
if (compName.match(matcher.pattern)) {
styleDir = matcher.styleDir;
break;
}
}
if (!styleDir)
styleDir = kebabCase(compName);
return styleDir;
}
function getSideEffects(compName, options) {
const { importStyle = true } = options;
if (!importStyle)
return;
const lib = options.cjs ? "lib" : "es";
const packageName = (options == null ? void 0 : options.packageName) || "dm-vue3-ui";
if (importStyle) {
const styleDir = getStyleDir(compName);
return `${packageName}/${lib}/${styleDir}/index.css`;
}
}
let DmUINames;
function genDmUINames(primitiveNames2) {
DmUINames = new Set(primitiveNames2);
}
genDmUINames(primitiveNames);
function isDmUI(compName) {
return DmUINames.has(compName);
}
function getImportName(compName) {
return compName;
}
function kebabCase(key) {
const result = key.replace(/([A-Z])/g, " $1").trim();
return result.split(" ").join("-").toLowerCase();
}
function resolveDirective(name, options) {
if (!options.directives)
return;
const { packageName = "dm-vue3-ui" } = options;
const directives = {
Loading: { importName: "DmLoading", styleName: "loading" }
};
const directive = directives[name];
if (!directive)
return;
return {
name: directive.importName,
from: `${packageName}`
};
}
function resolveComponent(name, options) {
var _a;
const originPrefix = options.prefix ?? "Dm";
const { cjs = false, packageName = "dm-vue3-ui" } = options;
if (options.resolveIcons && name.match(/(Outlined|Filled|TwoTone)$/)) {
return {
name,
from: "@ant-design/icons-vue"
};
}
const [compName, prefix] = [name.slice(originPrefix.length), name.slice(0, originPrefix.length)];
if (prefix === originPrefix && isDmUI(compName) && !((_a = options == null ? void 0 : options.exclude) == null ? void 0 : _a.includes(compName))) {
const path = `${packageName}/${cjs ? "lib" : "es"}`;
return {
name: getImportName(compName),
from: path,
sideEffects: getSideEffects(compName, options)
};
}
}
function DmVue3Resolver(options = {}) {
return [
{
type: "component",
resolve: (name) => {
return resolveComponent(name, options);
}
},
{
type: "directive",
resolve: (name) => {
return resolveDirective(name, options);
}
}
];
}
export {
DmVue3Resolver as default
};