Skip to content

Commit

Permalink
chore(bitUi): update
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Jun 27, 2024
1 parent ebe7e5f commit db9aeb2
Show file tree
Hide file tree
Showing 144 changed files with 2,143 additions and 479 deletions.
21 changes: 10 additions & 11 deletions scripts/generateIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const fsp = require('node:fs/promises')
const fg = require('fast-glob')

export async function run() {
const folder = 'src/ui/shadcnSvelte'
const lib = 'shadcnSvelte0'
const name = 'shadcnSvelte0'
const folder = 'src/ui/bitsUi'
const lib = 'bitsUi0'
const name = 'bitsUi0'
const isHyphen = false /** 生成的模板中的使用是 true ? a-affix : AAfix */
const url = path.resolve(root, `${folder}/${name}`)
const entry = await fg(['**/*.json'], { dot: true, cwd: url })
Expand All @@ -26,19 +26,18 @@ export async function run() {
= `import { componentsReducer, propsReducer } from '../../utils'
${imports.join('\n')}
export function ${name}() {
const map: any = [
const map: any = [
${entry.map((_url: string) => `${_url.split('.')[0]},`).join('\n ')}
]
]
export function ${name}() {
return propsReducer('${lib}', map, '${prefix}')
}
const componentsMap = [
${map.join('\n ')}
]
export function ${name}Components() {
const map = [
${map.join('\n ')}
]
return componentsReducer(map, ${isHyphen}, '${prefix}', '${lib}')
return componentsReducer(componentsMap, ${isHyphen}, '${prefix}', '${lib}')
}
`
fsp.writeFile(path.resolve(root, `${folder}/${name}/index.ts`), template)
Expand Down
19 changes: 11 additions & 8 deletions scripts/shadcnSvelte.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function run() {

const root = header.closest('div')
const description = root.nextElementSibling.textContent
const result = { name, props, description, link, link_zh: link, typeDetail: {}, events, methods, slots, filename: name.replace(/\.(\w)/g, (_, v) => v.toUpperCase()) }
const result = { name, props, description, link, link_zh: link, typeDetail: {}, events, methods, slots, filename: name.replace(/\.(\w)/g, (_, v) => v.toUpperCase()), suggestions: [] }
const main = Array.from(root.nextElementSibling.nextElementSibling.children)

const propsChildren = main.find(item => item.querySelector('table>thead>tr>th').textContent.trim() === 'Property')
Expand All @@ -31,13 +31,16 @@ function run() {
const type = item.children[1].textContent.split(' ')[0]
const description = item.children[2].children[0].textContent
const value = item.children[2].children[1].textContent.split(':')[1].trim().replace(/——/g, '_').replace('_ undefined', '_')
props[childname] = {
value: '',
default: value,
type,
description,
description_zh: description
}
if (childname.startsWith('on'))
events.push({ name: childname, description, description_zh: description })
else
props[childname] = {
value: '',
default: value,
type,
description,
description_zh: description
}
})
if (slotsChildren)
Array.from(slotsChildren.querySelectorAll('tbody>tr')).forEach((item) => {
Expand Down
49 changes: 49 additions & 0 deletions scripts/transformPropsOnToEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fg = require('fast-glob')
const path = require('node:path')
const root = process.cwd()
const fsp = require('node:fs/promises')

export async function run() {
const folder = 'src/ui/bitsUi'
const url = path.resolve(root, folder)
const entry = await fg(['**/*.json'], { dot: true, cwd: url })

for (const relative of entry) {
const realUrl = path.resolve(url, relative)
let jsonStr = await fsp.readFile(realUrl, 'utf8')
try {
const json = JSON.parse(jsonStr)
if (!json.props)
continue
let changed = false
const needsDeleteKeys = []
for (const k in json.props) {
if (!k.startsWith('on'))
continue
needsDeleteKeys.push(k)
const value = json.props[k]
const description = value.description
json.events.push(
{ name: k, description, description_zh: description }
)
changed = true
}
for (const item of json.events) {
if (!item.name.startsWith('on')) {
item.name = 'on'+item.name[0].toUpperCase()+item.name.slice(1)
changed = true
}
}
if (needsDeleteKeys.length) {
needsDeleteKeys.forEach(k => delete json.props[k])
}
if (changed) {
jsonStr = JSON.stringify(json, null, 2)
fsp.writeFile(realUrl, jsonStr)
}
} catch (error) {
continue
}
}
}
run()
4 changes: 4 additions & 0 deletions src/ui/bitsUi/bitsUi0/AccordionHeader.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@
"description_zh": "如果使用带有委托的 asChild 属性,则要应用于元素的构建器属性和操作。"
}
],
"suggestions": [
"AlertDialog.Title",
"AlertDialog.Description"
],
"filename": "AccordionHeader"
}
1 change: 1 addition & 0 deletions src/ui/bitsUi/bitsUi0/AccordionItem.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"description_zh": "如果使用带有委托的 asChild 属性,则要应用于元素的构建器属性和操作。"
}
],
"suggestions": ["Accordion.Trigger", "Accordion.Content"],
"filename": "AccordionItem"
}
18 changes: 10 additions & 8 deletions src/ui/bitsUi/bitsUi0/AccordionRoot.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
"description": "The active accordion item value.",
"description_zh": "活动折叠项目值。"
},
"onValueChange": {
"value": "",
"default": "_",
"type": "function",
"description": "A callback function called when the active accordion item value changes.",
"description_zh": "当活动折叠体项值更改时调用的回调函数。"
},
"asChild": {
"value": "",
"default": "false",
Expand All @@ -48,7 +41,13 @@
"link": "https://www.bits-ui.com/docs/components/accordion",
"link_zh": "https://www.bits-ui.com/docs/components/accordion",
"typeDetail": {},
"events": [],
"events": [
{
"name": "onValueChange",
"description": "A callback function called when the active accordion item value changes.",
"description_zh": "A callback function called when the active accordion item value changes."
}
],
"methods": [],
"slots": [
{
Expand All @@ -57,5 +56,8 @@
"description_zh": "如果使用带有委托的 asChild 属性,则要应用于元素的构建器属性和操作。"
}
],
"suggestions": [
"Accordion.Item"
],
"filename": "AccordionRoot"
}
12 changes: 12 additions & 0 deletions src/ui/bitsUi/bitsUi0/AlertDescription.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Alert.Description",
"props": {},
"description": "Displays a callout for user attention.",
"link": "https://shadcn-svelte.com/docs/components/alert",
"link_zh": "https://shadcn-svelte.com/docs/components/alert",
"typeDetail": {},
"events": [],
"methods": [],
"slots": [],
"filename": "AlertDescription"
}
4 changes: 4 additions & 0 deletions src/ui/bitsUi/bitsUi0/AlertDialogContent.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@
"description_zh": "如果使用带有委托的 asChild 属性,则要应用于元素的构建器属性和操作。"
}
],
"suggestions": [
"AlertDialog.Header",
"AlertDialog.Footer"
],
"filename": "AlertDialogContent"
}
31 changes: 16 additions & 15 deletions src/ui/bitsUi/bitsUi0/AlertDialogRoot.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
"description": "Whether or not the alert dialog is open.",
"description_zh": "警报对话框是否打开。"
},
"onOpenChange": {
"value": "",
"default": "_",
"type": "function",
"description": "A callback function called when the open state changes.",
"description_zh": "打开状态更改时调用的回调函数。"
},
"openFocus": {
"value": "",
"default": "_",
Expand All @@ -56,20 +49,24 @@
"type": "union",
"description": "Where to render the alert dialog when it is open. Defaults to the body. Can be disabled by passing null",
"description_zh": "警报对话框打开时的呈现位置。默认为正文。可以通过传递 null 来禁用"
},
"onOutsideClick": {
"value": "",
"default": "_",
"type": "function",
"description": "A callback function called when a click occurs outside of the element. If event.preventDefault() is called, the default behavior of closing the element will be prevented.",
"description_zh": "在元素外部发生单击时调用的回调函数。如果调用 event.preventDefault(),则将阻止关闭元素的默认行为。"
}
},
"description": "The root component used to set and manage the state of the alert dialog.",
"link": "https://www.bits-ui.com/docs/components/alert-dialog",
"link_zh": "https://www.bits-ui.com/docs/components/alert-dialog",
"typeDetail": {},
"events": [],
"events": [
{
"name": "onOpenChange",
"description": "A callback function called when the open state changes.",
"description_zh": "A callback function called when the open state changes."
},
{
"name": "onOutsideClick",
"description": "A callback function called when a click occurs outside of the element. If event.preventDefault() is called, the default behavior of closing the element will be prevented.",
"description_zh": "A callback function called when a click occurs outside of the element. If event.preventDefault() is called, the default behavior of closing the element will be prevented."
}
],
"methods": [],
"slots": [
{
Expand All @@ -78,5 +75,9 @@
"description_zh": "组件中元素的 ID,当您不一定希望提供自定义 ID,但仍希望访问正在分配的 ID(如果有)时,非常有用。"
}
],
"suggestions": [
"AlertDialog.Trigger",
"AlertDialog.Content"
],
"filename": "AlertDialogRoot"
}
24 changes: 24 additions & 0 deletions src/ui/bitsUi/bitsUi0/AlertRoot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Alert.Root",
"props": {
"variant": {
"value": "",
"default": "[]",
"type": "default/destructive",
"description": "",
"description_zh": ""
}
},
"description": "Displays a callout for user attention.",
"link": "https://shadcn-svelte.com/docs/components/alert",
"link_zh": "https://shadcn-svelte.com/docs/components/alert",
"typeDetail": {},
"events": [],
"methods": [],
"slots": [],
"suggestions": [
"Alert.Title",
"Alert.Description"
],
"filename": "AlertRoot"
}
20 changes: 20 additions & 0 deletions src/ui/bitsUi/bitsUi0/AlertTitle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Alert.Title",
"props": {
"level": {
"value": "",
"default": "[]",
"type": "h1/h2/h3/h4/h5/h6",
"description": "",
"description_zh": ""
}
},
"description": "Displays a callout for user attention.",
"link": "https://shadcn-svelte.com/docs/components/alert",
"link_zh": "https://shadcn-svelte.com/docs/components/alert",
"typeDetail": {},
"events": [],
"methods": [],
"slots": [],
"filename": "AlertTitle"
}
19 changes: 11 additions & 8 deletions src/ui/bitsUi/bitsUi0/AvatarRoot.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
"description": "The loading status of the avatars source image. You can bind a variable to track the status outside of the component and use it to show a loading indicator or error message.",
"description_zh": "头像源图像的加载状态。您可以绑定变量来跟踪组件外部的状态,并使用它来显示加载指示器或错误消息。"
},
"onLoadingStatusChange": {
"value": "",
"default": "_",
"type": "function",
"description": "A callback function called when the loading status of the image changes.",
"description_zh": "当图像的加载状态发生变化时调用的回调函数。"
},
"asChild": {
"value": "",
"default": "false",
Expand All @@ -41,7 +34,13 @@
"link": "https://www.bits-ui.com/docs/components/avatar",
"link_zh": "https://www.bits-ui.com/docs/components/avatar",
"typeDetail": {},
"events": [],
"events": [
{
"name": "onLoadingStatusChange",
"description": "A callback function called when the loading status of the image changes.",
"description_zh": "A callback function called when the loading status of the image changes."
}
],
"methods": [],
"slots": [
{
Expand All @@ -50,5 +49,9 @@
"description_zh": "如果使用带有委托的 asChild 属性,则应用于元素的其他属性。"
}
],
"suggestions": [
"Avatar.Image",
"Avatar.Fallback"
],
"filename": "AvatarRoot"
}
20 changes: 20 additions & 0 deletions src/ui/bitsUi/bitsUi0/Badge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Badge",
"props": {
"variant": {
"value": "",
"default": "[]",
"type": "default/secondary/destructive/outline",
"description": "",
"description_zh": ""
}
},
"description": "A special button component that can receive Melt UI builders for use with the asChild prop.",
"link": "https://shadcn-svelte.com/docs/components/badge",
"link_zh": "https://shadcn-svelte.com/docs/components/badge",
"typeDetail": {},
"events": [],
"methods": [],
"slots": [],
"filename": "Badge"
}
20 changes: 20 additions & 0 deletions src/ui/bitsUi/bitsUi0/BreadcrumbEllipsis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "Breadcrumb.Ellipsis",
"props": {
"el": {
"value": "",
"default": "[]",
"type": "HTMLSpanElement",
"description": "",
"description_zh": ""
}
},
"description": "A special button component that can receive Melt UI builders for use with the asChild prop.",
"link": "https://shadcn-svelte.com/docs/components/breadcrumb",
"link_zh": "https://shadcn-svelte.com/docs/components/breadcrumb",
"typeDetail": {},
"events": [],
"methods": [],
"slots": [],
"filename": "BreadcrumbEllipsis"
}
Loading

0 comments on commit db9aeb2

Please sign in to comment.