fix: variable display in form content preview

This commit is contained in:
JzoNg 2026-01-26 13:52:05 +08:00
parent f2d98e832f
commit 824f139b46
2 changed files with 10 additions and 3 deletions

View File

@ -77,7 +77,7 @@ const FormContentPreview: FC<FormContentPreviewProps> = ({
}
const defaultInput = input.default
return (
<Note defaultInput={defaultInput!} />
<Note defaultInput={defaultInput!} nodeName={nodeName} />
)
})(),
}}

View File

@ -123,11 +123,18 @@ export const Variable: React.FC<{ path: string }> = ({ path }) => {
)
}
export const Note: React.FC<{ defaultInput: FormInputItemDefault }> = ({ defaultInput }) => {
export const Note: React.FC<{ defaultInput: FormInputItemDefault, nodeName: (nodeId: string) => string }> = ({ defaultInput, nodeName }) => {
const isVariable = defaultInput.type === 'variable'
const path = `{{#${defaultInput.selector.join('.')}#}}`
let newPath = path
if (path) {
newPath = path.replace(/#([^#.]+)([.#])/g, (match, nodeId, sep) => {
return `#${nodeName(nodeId)}${sep}`
})
}
return (
<div className="my-3 rounded-[10px] bg-components-input-bg-normal px-2.5 py-2">
{isVariable ? <Variable path={`{{${defaultInput.selector.join('.')}}}`} /> : <span>{defaultInput.value}</span>}
{isVariable ? <Variable path={newPath} /> : <span>{defaultInput.value}</span>}
</div>
)
}