Skip to content

Commit

Permalink
refactor: use propsReducer & componentsReducer
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Jul 14, 2023
1 parent 5188250 commit 4775f30
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 537 deletions.
69 changes: 5 additions & 64 deletions src/ui/antDesignVue/antDesignVue2/index.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
import * as vscode from 'vscode'
import { createCompletionItem } from '@vscode-use/utils'
import { componentsReducer, propsReducer } from '../../utils'

export function antDesignVue2() {
const map: any = [
]

return map.reduce((result: any, item: any) => {
const completions: any = []
const events: any = []
Object.keys(item.props!).forEach((key) => {
const value = (item.props as any)[key]
let type = vscode.CompletionItemKind.Property
if (typeof value.value === 'string')
value.value = [value.value]
else
type = vscode.CompletionItemKind.Enum
completions.push(...value.value.map((v: string) => {
const detail = []
if (value.default !== undefined && value.default !== '')
detail.push(`#### ***💎 默认值:*** \`${value.default}\``)

if (value.type)
detail.push(`#### ***💡 类型:*** \`${value.type}\``)

if (value.description)
detail.push(`#### ***🔦 说明:*** \`${value.description}\``)
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(detail.join('\n\n'))
if (value.type && value.type.includes('boolean') && value.default === 'false')
return createCompletionItem({ content: key, documentation })
return createCompletionItem({ content: `${key}="${v}"`, documentation, snippet: `${key}="$\{1:${v}\}$2"`, type })
},
))
})
if (item.events) {
events.push(...item.events.map((events: any) => {
const detail = []
let { name, description, params } = events

if (description)
detail.push(`#### ***🔦 说明:*** \`${description}\``)

if (params)
detail.push(`#### ***🔮 回调参数:*** \`${params}\``)
name = name.replace(/-(\w)/g, (_: string, v: string) => v.toUpperCase())
const snippet = `${name}="$\{1:on${name[0].toUpperCase()}${name.slice(1)}\}$2"`
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(detail.join('\n\n'))
return createCompletionItem({ content: `${name}="on${name[0].toUpperCase()}${name.slice(1)}"`, snippet, documentation, type: vscode.CompletionItemKind.Event })
},
))
}

result[item.name!] = { completions, events }
return result
}, {} as any)
return propsReducer(map)
}

export function antDesignVue2Components() {
return [
const map = [
['Row', '布局'],
['Col', '布局'],
['Content', '内容部分,自带默认样式,其下可嵌套任何元素,只能放在 Layout 中'],
Expand Down Expand Up @@ -138,11 +84,6 @@ export function antDesignVue2Components() {
['image', '图片'],
['backtop', '回到顶部'],
['drawer', '抽屉'],
].map(([content, detail]) => {
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(`#### ***📖 ${detail}***`)
return createCompletionItem({ content, snippet: `<${content}>$1</${content}>`, documentation, type: vscode.CompletionItemKind.TypeParameter })
})
]
return componentsReducer(map)
}
69 changes: 5 additions & 64 deletions src/ui/antDesignVue/antDesignVue3/index.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
import * as vscode from 'vscode'
import { createCompletionItem } from '@vscode-use/utils'
import { componentsReducer, propsReducer } from '../../utils'

export function antDesignVue3() {
const map: any = [
]

return map.reduce((result: any, item: any) => {
const completions: any = []
const events: any = []
Object.keys(item.props!).forEach((key) => {
const value = (item.props as any)[key]
let type = vscode.CompletionItemKind.Property
if (typeof value.value === 'string')
value.value = [value.value]
else
type = vscode.CompletionItemKind.Enum
completions.push(...value.value.map((v: string) => {
const detail = []
if (value.default !== undefined && value.default !== '')
detail.push(`#### ***💎 默认值:*** \`${value.default}\``)

if (value.type)
detail.push(`#### ***💡 类型:*** \`${value.type}\``)

if (value.description)
detail.push(`#### ***🔦 说明:*** \`${value.description}\``)
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(detail.join('\n\n'))
if (value.type && value.type.includes('boolean') && value.default === 'false')
return createCompletionItem({ content: key, documentation })
return createCompletionItem({ content: `${key}="${v}"`, documentation, snippet: `${key}="$\{1:${v}\}$2"`, type })
},
))
})
if (item.events) {
events.push(...item.events.map((events: any) => {
const detail = []
let { name, description, params } = events

if (description)
detail.push(`#### ***🔦 说明:*** \`${description}\``)

if (params)
detail.push(`#### ***🔮 回调参数:*** \`${params}\``)
name = name.replace(/-(\w)/g, (_: string, v: string) => v.toUpperCase())
const snippet = `${name}="$\{1:on${name[0].toUpperCase()}${name.slice(1)}\}$2"`
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(detail.join('\n\n'))
return createCompletionItem({ content: `${name}="on${name[0].toUpperCase()}${name.slice(1)}"`, snippet, documentation, type: vscode.CompletionItemKind.Event })
},
))
}

result[item.name!] = { completions, events }
return result
}, {} as any)
return propsReducer(map)
}

export function antDesignVue3Components() {
return [
const map = [
['Row', '布局'],
['Col', '布局'],
['Content', '内容部分,自带默认样式,其下可嵌套任何元素,只能放在 Layout 中'],
Expand Down Expand Up @@ -138,11 +84,6 @@ export function antDesignVue3Components() {
['image', '图片'],
['backtop', '回到顶部'],
['drawer', '抽屉'],
].map(([content, detail]) => {
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(`#### ***📖 ${detail}***`)
return createCompletionItem({ content, snippet: `<${content}>$1</${content}>`, documentation, type: vscode.CompletionItemKind.TypeParameter })
})
]
return componentsReducer(map)
}
33 changes: 1 addition & 32 deletions src/ui/antd/antd4/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,7 @@
"value": "",
"description": "数据化配置选项内容,支持通过 children 嵌套",
"default": "-",
"type": {
"key": {
"value": "",
"description": "唯一标志",
"default": "",
"type": "string | number"
},
"href": {
"value": "",
"description": "锚点链接",
"default": "",
"type": "string"
},
"title": {
"value": "",
"description": "文字内容",
"default": "",
"type": "ReactNode"
},
"target": {
"value": "",
"description": "该属性指定在何处显示链接的资源",
"default": "",
"type": "string"
},
"children": {
"value": "",
"description": "嵌套的 Anchor Link,注意:水平方向该属性不支持",
"default": "",
"type": "[]"
}
}
"type": ""
},
"direction": {
"value": "",
Expand Down
69 changes: 5 additions & 64 deletions src/ui/antd/antd4/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from 'vscode'
import { createCompletionItem } from '@vscode-use/utils'
import { componentsReducer, propsReducer } from '../../utils'
import Divider from './divider.json'
import Row from './row.json'
import Col from './col.json'
Expand Down Expand Up @@ -31,64 +30,11 @@ export function antd4() {
BreadCrumb,
]

return map.reduce((result: any, item: any) => {
const completions: any = []
const events: any = []
Object.keys(item.props!).forEach((key) => {
const value = (item.props as any)[key]
let type = vscode.CompletionItemKind.Property
if (typeof value.value === 'string')
value.value = [value.value]
else
type = vscode.CompletionItemKind.Enum
completions.push(...value.value.map((v: string) => {
const detail = []
if (value.default !== undefined && value.default !== '')
detail.push(`#### ***💎 默认值:*** \`${value.default}\``)

if (value.type)
detail.push(`#### ***💡 类型:*** \`${value.type}\``)

if (value.description)
detail.push(`#### ***🔦 说明:*** \`${value.description}\``)
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(detail.join('\n\n'))
if (value.type && value.type.includes('boolean') && value.default === 'false')
return createCompletionItem({ content: key, documentation })
return createCompletionItem({ content: `${key}="${v}"`, documentation, snippet: `${key}="$\{1:${v}\}$2"`, type })
},
))
})
if (item.events) {
events.push(...item.events.map((events: any) => {
const detail = []
const { name, description, params } = events

if (description)
detail.push(`#### ***🔦 说明:*** \`${description}\``)

if (params)
detail.push(`#### ***🔮 回调参数:*** \`${params}\``)

const snippet = `${name}="$\{1:handle${name.slice(2)}\}$2"`
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(detail.join('\n\n'))
return createCompletionItem({ content: `${name}="handle${name.slice(2)}"`, snippet, documentation, type: vscode.CompletionItemKind.Event })
},
))
}

result[item.name!] = { completions, events }
return result
}, {} as any)
return propsReducer(map)
}

export function antd4Components() {
return [
const map = [
['Row', '布局'],
['Col', '布局'],
['Content', '内容部分,自带默认样式,其下可嵌套任何元素,只能放在 Layout 中'],
Expand Down Expand Up @@ -164,11 +110,6 @@ export function antd4Components() {
['image', '图片'],
['backtop', '回到顶部'],
['drawer', '抽屉'],
].map(([content, detail]) => {
const documentation = new vscode.MarkdownString()
documentation.isTrusted = true
documentation.supportHtml = true
documentation.appendMarkdown(`#### ***📖 ${detail}***`)
return createCompletionItem({ content, snippet: `<${content}>$1</${content}>`, documentation, type: vscode.CompletionItemKind.TypeParameter })
})
]
return componentsReducer(map)
}
33 changes: 1 addition & 32 deletions src/ui/antd/antd5/anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,7 @@
"value": "",
"description": "数据化配置选项内容,支持通过 children 嵌套",
"default": "-",
"type": {
"key": {
"value": "",
"description": "唯一标志",
"default": "",
"type": "string | number"
},
"href": {
"value": "",
"description": "锚点链接",
"default": "",
"type": "string"
},
"title": {
"value": "",
"description": "文字内容",
"default": "",
"type": "ReactNode"
},
"target": {
"value": "",
"description": "该属性指定在何处显示链接的资源",
"default": "",
"type": "string"
},
"children": {
"value": "",
"description": "嵌套的 Anchor Link,注意:水平方向该属性不支持",
"default": "",
"type": "[]"
}
}
"type": ""
},
"direction": {
"value": "",
Expand Down
Loading

0 comments on commit 4775f30

Please sign in to comment.