Skip to content

Commit

Permalink
chore: improve playground code
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Nov 23, 2021
1 parent 0f316ea commit 6df7210
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions formily/antd/playground/widgets/MarkupSchemaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export interface IMarkupSchemaWidgetProps {
const transformToMarkupSchemaCode = (tree: TreeNode) => {
const printAttribute = (node: TreeNode) => {
if (!node) return ''
return `${Object.keys({ ...node.props, name: node.props.name || node.id })
const props = { ...node.props }
if (node.depth !== 0) {
props.name = node.props.name || node.id
}
return `${Object.keys(props)
.map((key) => {
if (
key === 'x-designable-id' ||
Expand All @@ -20,7 +24,7 @@ const transformToMarkupSchemaCode = (tree: TreeNode) => {
key === 'type'
)
return ''
const value = node.props[key]
const value = props[key]
if (isPlainObj(value) && isEmpty(value)) return ''
if (typeof value === 'string') return `${key}="${value}"`
return `${key}={${JSON.stringify(value)}}`
Expand Down
6 changes: 5 additions & 1 deletion formily/next/playground/widgets/MarkupSchemaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export interface IMarkupSchemaWidgetProps {
const transformToMarkupSchemaCode = (tree: TreeNode) => {
const printAttribute = (node: TreeNode) => {
if (!node) return ''
return `${Object.keys({ ...node.props, name: node.props.name || node.id })
const props = { ...node.props }
if (node.depth !== 0) {
props.name = node.props.name || node.id
}
return `${Object.keys(props)
.map((key) => {
if (
key === 'x-designable-id' ||
Expand Down

0 comments on commit 6df7210

Please sign in to comment.