Skip to content

Commit

Permalink
feat: 优化组件提示模块,根据类型有更好的提示选择
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Aug 3, 2024
1 parent 65a73aa commit af43980
Show file tree
Hide file tree
Showing 411 changed files with 6,124 additions and 3,570 deletions.
80 changes: 48 additions & 32 deletions scripts/tinyVue.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,40 @@ function run() {
})

Array.from(propsChildren).forEach((item) => {
let prop = item.children[0].textContent.replace('*', '')
const description = item.children[3].textContent
const type = item.children[1].textContent.replace(/\n/g, '')
let value = item.children[2].textContent
if (prop === 'style')
prop = ':style'
else if (
type === 'number' || type === 'object'
)
prop = `:${prop}`

if (prop === 'model-value (v-model)' || prop === 'model-value' || prop === 'modelValue / v-model')
prop = 'v-model'
else
prop = prop.replace(/([\w-]+) \(v-model\)/, 'v-model:$1')
if (type === 'boolean' && (value === '' || value === '-'))
value = 'false'
else if (type === 'CSSProperties' && !prop.startsWith(':'))
prop = `:${prop}`

props[prop] = {
default: value,
value: '',
type,
description,
description_zh: description,
}
Array.from($0.closest('tbody').children).forEach(item => {
let children = Array.from(item.children)
let prop = children[0].textContent.replace('*', '')
if (!prop) {
children = children.slice(1)
prop = children[0].textContent.replace('*', '')
}
const description = children[3].textContent
const type = children[1].textContent.replace(/\n/g, '')
let value = children[2].textContent
if (prop === 'style')
prop = ':style'
else if (
type === 'number' || type === 'object'
)
prop = `:${prop}`

if (prop === 'model-value (v-model)' || prop === 'model-value' || prop === 'modelValue / v-model')
prop = 'v-model'
else
prop = prop.replace(/([\w-]+) \(v-model\)/, 'v-model:$1')
if (type === 'boolean' && (value === '' || value === '-'))
value = 'false'
else if (type === 'CSSProperties' && !prop.startsWith(':'))
prop = `:${prop}`

props[prop] = {
default: value,
value: '',
type,
description,
description_zh: description,
}
})
})

Array.from(eventsChildren).forEach((item) => {
Expand Down Expand Up @@ -105,10 +112,15 @@ function run() {
function getProps() {
const props = {}
Array.from($0.closest('tbody').children).forEach(item => {
let prop = item.children[0].textContent.replace('*', '')
const description = item.children[3].textContent
const type = item.children[1].textContent.replace(/\n/g, '')
let value = item.children[2].textContent
let children = Array.from(item.children)
let prop = children[0].textContent.replace('*', '')
if (!prop) {
children = children.slice(1)
prop = children[0].textContent.replace('*', '')
}
const description = children[3].textContent
const type = children[1].textContent.replace(/\n/g, '')
let value = children[2].textContent
if (prop === 'style')
prop = ':style'
else if (
Expand Down Expand Up @@ -192,8 +204,12 @@ function copyToClipboard(text) {
const cwd = process.cwd()
function arrayGenerateFile(array) {
const baseSrc = 'src/ui/tinyVue/tinyVue3'
array.forEach(item => {
array.forEach(async item => {
const url = path.resolve(cwd, baseSrc, `${item.filename}.json`)
// 兼容 suggestions
const fileContent = JSON.parse(await fsp.readFile(url, 'utf-8'))
const suggestions = fileContent.suggestions || []
item.suggestions = suggestions
fsp.writeFile(url, JSON.stringify(item, null, 2), 'utf-8')
})
}
Expand Down
Loading

0 comments on commit af43980

Please sign in to comment.