mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-11-30 02:08:12 +08:00
refactor(build): optimize the conversion of attributes in documents (#9970)
This commit is contained in:
parent
ae67a610bd
commit
ec65bf9626
@ -23,7 +23,7 @@
|
||||
"@vitejs/plugin-vue": "^2.3.3",
|
||||
"@vitejs/plugin-vue-jsx": "^1.3.10",
|
||||
"chalk": "^5.0.1",
|
||||
"components-helper": "^2.1.2",
|
||||
"components-helper": "^2.1.3",
|
||||
"consola": "^2.15.3",
|
||||
"esbuild": "^0.14.47",
|
||||
"fast-glob": "^3.2.11",
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
getTypeSymbol,
|
||||
hyphenate,
|
||||
isCommonType,
|
||||
isEnumType,
|
||||
isUnionType,
|
||||
main,
|
||||
} from 'components-helper'
|
||||
@ -25,7 +24,7 @@ import type {
|
||||
} from 'components-helper'
|
||||
|
||||
const typeMap = {
|
||||
vue: ['Component', 'VNode'],
|
||||
vue: ['Component', 'VNode', 'CSSProperties', 'StyleValue'],
|
||||
}
|
||||
|
||||
const reComponentName: ReComponentName = (title) =>
|
||||
@ -48,13 +47,14 @@ const reWebTypesSource: ReWebTypesSource = (title) => {
|
||||
return { symbol }
|
||||
}
|
||||
|
||||
const reAttribute: ReAttribute = (value, key, _, title) => {
|
||||
const reAttribute: ReAttribute = (value, key) => {
|
||||
const str = value
|
||||
.replace(/^\*\*(.*)\*\*$/, (_, item) => item)
|
||||
.replace(/^`(.*)`$/, (_, item) => item)
|
||||
.replace(/^\*\*(.*)\*\*$/, '$1')
|
||||
.replace(/^`(.*)`$/, '$1')
|
||||
.replace(/^~~(.*)~~$/, '')
|
||||
.replaceAll(/<del>.*<\/del>/g, '')
|
||||
|
||||
if (title === 'Events' && key === 'Name' && /^(-|—)$/.test(str)) {
|
||||
if (key === 'Name' && /^(-|—)$/.test(str)) {
|
||||
return 'default'
|
||||
} else if (str === '' || /^(-|—)$/.test(str)) {
|
||||
return undefined
|
||||
@ -74,8 +74,13 @@ const reAttribute: ReAttribute = (value, key, _, title) => {
|
||||
return str
|
||||
.replaceAll(/\bfunction(\(.*\))?(:\s*\w+)?\b/gi, 'Function')
|
||||
.replaceAll(/\bdate\b/g, 'Date')
|
||||
.replaceAll(/\bstring \| Component\b/g, 'string / Component')
|
||||
.replaceAll(/\([^)]*\)(?!\s*=>)/g, '')
|
||||
.replaceAll(/(<[^>]*>|\{[^}]*}|\([^)]*\))/g, (item) => {
|
||||
return item.replaceAll(/(\/|\|)/g, '=_0!')
|
||||
})
|
||||
.replaceAll(/(\b\w+)\s*\|/g, '$1 /')
|
||||
.replaceAll(/\|\s*(\b\w+)/g, '/ $1')
|
||||
.replaceAll(/=_0!/g, '|')
|
||||
} else if (key === 'Accepted Values') {
|
||||
return /\[.+\]\(.+\)/.test(str) || /^\*$/.test(str)
|
||||
? undefined
|
||||
@ -94,20 +99,12 @@ const reAttribute: ReAttribute = (value, key, _, title) => {
|
||||
}
|
||||
|
||||
const reWebTypesType: ReWebTypesType = (type) => {
|
||||
const isEnum = isEnumType(type)
|
||||
const isTuple = /^\[.*\]$/.test(type)
|
||||
const isArrowFunction = /^\(.*\)\s*=>\s*\w+/.test(type)
|
||||
const isPublicType = isCommonType(type)
|
||||
const symbol = getTypeSymbol(type)
|
||||
const isUnion = isUnionType(symbol)
|
||||
const module = findModule(type)
|
||||
const module = findModule(symbol)
|
||||
|
||||
return isEnum ||
|
||||
isTuple ||
|
||||
isArrowFunction ||
|
||||
isPublicType ||
|
||||
!symbol ||
|
||||
isUnion
|
||||
return isPublicType || !symbol || isUnion
|
||||
? type
|
||||
: { name: type, source: { symbol, module } }
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ importers:
|
||||
'@vitejs/plugin-vue': ^2.3.3
|
||||
'@vitejs/plugin-vue-jsx': ^1.3.10
|
||||
chalk: ^5.0.1
|
||||
components-helper: ^2.1.2
|
||||
components-helper: ^2.1.3
|
||||
consola: ^2.15.3
|
||||
esbuild: ^0.14.47
|
||||
fast-glob: ^3.2.11
|
||||
@ -264,7 +264,7 @@ importers:
|
||||
'@vitejs/plugin-vue': 2.3.3_vue@3.2.37
|
||||
'@vitejs/plugin-vue-jsx': 1.3.10
|
||||
chalk: 5.0.1
|
||||
components-helper: 2.1.2
|
||||
components-helper: 2.1.3
|
||||
consola: 2.15.3
|
||||
esbuild: 0.14.47
|
||||
fast-glob: 3.2.11
|
||||
@ -5050,8 +5050,8 @@ packages:
|
||||
resolution: {integrity: sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==}
|
||||
dev: false
|
||||
|
||||
/components-helper/2.1.2:
|
||||
resolution: {integrity: sha512-KGzom/KUa/y8nL59Q+XPV/ARiHzVIAR1AJlJEmrV4zCJBVCXqbvGbpFxdtEugy6mICBrWdpeDzcewzwCjHewyw==}
|
||||
/components-helper/2.1.3:
|
||||
resolution: {integrity: sha512-t3PFNxbtPtzAY2GEoJBq6OipxwunqZKvaohkRL2uPK5hsuekM47RzhfxPxIqZ9Kd6Nnc2rTUaDnjx9gz2dImEQ==}
|
||||
engines: {node: '>10.0.0'}
|
||||
dependencies:
|
||||
fast-glob: 3.2.11
|
||||
|
Loading…
Reference in New Issue
Block a user