diff --git a/packages/client/src/schema-component/antd/input/ReadPretty.tsx b/packages/client/src/schema-component/antd/input/ReadPretty.tsx index cf3043101..b1826c7ae 100644 --- a/packages/client/src/schema-component/antd/input/ReadPretty.tsx +++ b/packages/client/src/schema-component/antd/input/ReadPretty.tsx @@ -4,11 +4,14 @@ import cls from 'classnames'; import React from 'react'; import { useCompile } from '../..'; import { EllipsisWithTooltip } from './EllipsisWithTooltip'; +import { HTMLEncode } from './shared'; type Composed = { Input: React.FC; URL: React.FC; - TextArea: React.FC; + TextArea: React.FC< + TextAreaProps & { ellipsis?: any; text?: any; addonBefore?: any; suffix?: any; addonAfter?: any; autop?: boolean } + >; }; export const ReadPretty: Composed = () => null; @@ -30,11 +33,18 @@ ReadPretty.Input = (props) => { ReadPretty.TextArea = (props) => { const prefixCls = usePrefixCls('description-textarea', props); const compile = useCompile(); + const value = compile(props.value ?? ''); + const values = HTMLEncode(value).split('\n').join('
'); + const content = ( + +
+ + ); return (
{props.addonBefore} {props.prefix} - {compile(props.value)} + {content} {props.suffix} {props.addonAfter}
diff --git a/packages/client/src/schema-component/antd/input/demos/demo2.tsx b/packages/client/src/schema-component/antd/input/demos/demo2.tsx index 1287bb838..c4a041f4e 100644 --- a/packages/client/src/schema-component/antd/input/demos/demo2.tsx +++ b/packages/client/src/schema-component/antd/input/demos/demo2.tsx @@ -16,7 +16,7 @@ const schema = { 'x-decorator': 'FormItem', 'x-component': 'Input.TextArea', 'x-reactions': { - target: '*(read1,read2)', + target: '*(read1,read2,read3)', fulfill: { state: { value: '{{$self.value}}', @@ -43,6 +43,17 @@ const schema = { ellipsis: true, }, }, + read3: { + interface: 'string', + type: 'string', + title: `Read pretty(autop)`, + 'x-read-pretty': true, + 'x-decorator': 'FormItem', + 'x-component': 'Input.TextArea', + 'x-component-props': { + autop: true, + }, + }, }, }; diff --git a/packages/client/src/schema-component/antd/input/shared.ts b/packages/client/src/schema-component/antd/input/shared.ts new file mode 100644 index 000000000..55fd09837 --- /dev/null +++ b/packages/client/src/schema-component/antd/input/shared.ts @@ -0,0 +1,7 @@ +export function HTMLEncode(html: string) { + let temp = document.createElement('div'); + temp.textContent != null ? (temp.textContent = html) : (temp.innerText = html); + const output = temp.innerHTML; + temp = null; + return output; +}