From 6df7210eb3cb8b995fcd756d501d2a88352d5ba9 Mon Sep 17 00:00:00 2001 From: "zhili.wzl" Date: Tue, 23 Nov 2021 13:17:51 +0800 Subject: [PATCH] chore: improve playground code --- formily/antd/playground/widgets/MarkupSchemaWidget.tsx | 8 ++++++-- formily/next/playground/widgets/MarkupSchemaWidget.tsx | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/formily/antd/playground/widgets/MarkupSchemaWidget.tsx b/formily/antd/playground/widgets/MarkupSchemaWidget.tsx index 7d92daa40..6e52c4e0e 100644 --- a/formily/antd/playground/widgets/MarkupSchemaWidget.tsx +++ b/formily/antd/playground/widgets/MarkupSchemaWidget.tsx @@ -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' || @@ -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)}}` diff --git a/formily/next/playground/widgets/MarkupSchemaWidget.tsx b/formily/next/playground/widgets/MarkupSchemaWidget.tsx index aa95bb6a2..f805d8f45 100644 --- a/formily/next/playground/widgets/MarkupSchemaWidget.tsx +++ b/formily/next/playground/widgets/MarkupSchemaWidget.tsx @@ -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' ||