chore: 去除 ansi-to-react 依赖,日志模块不再提供高亮功能 (#5376)

This commit is contained in:
吴多益 2022-09-20 09:28:58 +08:00 committed by GitHub
parent 19e0216539
commit 63e3a2bfda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 45 deletions

View File

@ -161,7 +161,7 @@ public class StreamingResponseBodyController {
## 属性表 ## 属性表
| 属性名 | 类型 | 默认值 | 说明 | | 属性名 | 类型 | 默认值 | 说明 |
| ------------ | --------- | ------ | ----------------------------------------------- | | ----------- | --------- | ------ | -------------------------------------------------------- |
| height | `number` | 500 | 展示区域高度 | | height | `number` | 500 | 展示区域高度 |
| className | `string` | | 外层 CSS 类名 | | className | `string` | | 外层 CSS 类名 |
| autoScroll | `boolean` | true | 是否自动滚动 | | autoScroll | `boolean` | true | 是否自动滚动 |
@ -170,5 +170,4 @@ public class StreamingResponseBodyController {
| source | `string` | | 接口 | | source | `string` | | 接口 |
| rowHeight | `number` | | 设置每行高度,将会开启虚拟渲染 | | rowHeight | `number` | | 设置每行高度,将会开启虚拟渲染 |
| maxLength | `number` | | 最大显示行数 | | maxLength | `number` | | 最大显示行数 |
| disableColor | `boolean` | | 关闭 ANSI 颜色支持 |
| operation | `Array` | | 可选日志操作:['stop','clear','showLineNumber','filter'] | | operation | `Array` | | 可选日志操作:['stop','clear','showLineNumber','filter'] |

View File

@ -223,7 +223,7 @@ fis.match('*.html:jsx', {
// 这些用了 esm // 这些用了 esm
fis.match( fis.match(
'{echarts/extension/**.js,zrender/**.js,ansi-to-react/lib/index.js,markdown-it-html5-media/**.js}', '{echarts/extension/**.js,zrender/**.js,markdown-it-html5-media/**.js}',
{ {
parser: fis.plugin('typescript', { parser: fis.plugin('typescript', {
sourceMap: false, sourceMap: false,

View File

@ -56,7 +56,7 @@
"rollup": "^2.60.2", "rollup": "^2.60.2",
"rollup-plugin-license": "^2.6.0", "rollup-plugin-license": "^2.6.0",
"rollup-plugin-terser": "^7.0.2", "rollup-plugin-terser": "^7.0.2",
"sass": "^1.54.0", "sass": "^1.54.9",
"sass-loader": "^12.1.0", "sass-loader": "^12.1.0",
"style-loader": "^3.2.1", "style-loader": "^3.2.1",
"stylelint": "^13.0.0", "stylelint": "^13.0.0",

View File

@ -91,7 +91,7 @@
"rollup-plugin-license": "^2.7.0", "rollup-plugin-license": "^2.7.0",
"rollup-plugin-postcss": "^4.0.2", "rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-scss": "^3.0.0", "rollup-plugin-scss": "^3.0.0",
"sass": "^1.54.0", "sass": "^1.54.9",
"ts-jest": "^28.0.3", "ts-jest": "^28.0.3",
"typescript": "^4.6.4" "typescript": "^4.6.4"
}, },

View File

@ -42,7 +42,6 @@
"dependencies": { "dependencies": {
"amis-core": "^2.2.0", "amis-core": "^2.2.0",
"amis-ui": "^2.2.0", "amis-ui": "^2.2.0",
"ansi-to-react": "^6.1.6",
"attr-accept": "2.2.2", "attr-accept": "2.2.2",
"blueimp-canvastoblob": "2.1.0", "blueimp-canvastoblob": "2.1.0",
"classnames": "2.3.1", "classnames": "2.3.1",

View File

@ -4,7 +4,6 @@
import React from 'react'; import React from 'react';
import {buildApi, isApiOutdated, Renderer, RendererProps} from 'amis-core'; import {buildApi, isApiOutdated, Renderer, RendererProps} from 'amis-core';
import {BaseSchema} from '../Schema'; import {BaseSchema} from '../Schema';
import Ansi from 'ansi-to-react';
import {Icon, SearchBox, VirtualList} from 'amis-ui'; import {Icon, SearchBox, VirtualList} from 'amis-ui';
export type LogOperation = export type LogOperation =
@ -59,11 +58,6 @@ export interface LogSchema extends BaseSchema {
*/ */
rowHeight?: number; rowHeight?: number;
/**
* ANSI
*/
disableColor?: boolean;
/** /**
* *
*/ */
@ -285,17 +279,6 @@ export class Log extends React.Component<LogProps, LogState> {
}); });
} }
renderHighlightWordWithAnsi(line: string) {
let {filterWord} = this.state;
if (filterWord === '') {
return line;
}
return line.replaceAll(
filterWord,
`\u001b[43;1m\u001b[30;1m${filterWord}\u001b[0m`
);
}
/** /**
* *
*/ */
@ -306,11 +289,7 @@ export class Log extends React.Component<LogProps, LogState> {
{showLineNumber && ( {showLineNumber && (
<span className={cx('Log-line-number')}>{index + 1} </span> <span className={cx('Log-line-number')}>{index + 1} </span>
)} )}
{disableColor ? ( {this.renderHighlightWord(line)}
this.renderHighlightWord(line)
) : (
<Ansi useClasses>{this.renderHighlightWordWithAnsi(line)}</Ansi>
)}
</div> </div>
); );
} }
@ -359,13 +338,7 @@ export class Log extends React.Component<LogProps, LogState> {
{showLineNumber && ( {showLineNumber && (
<span className={cx('Log-line-number')}>{index + 1} </span> <span className={cx('Log-line-number')}>{index + 1} </span>
)} )}
{disableColor ? ( {this.renderHighlightWord(logs[index])}
this.renderHighlightWord(logs[index])
) : (
<Ansi useClasses>
{this.renderHighlightWordWithAnsi(logs[index])}
</Ansi>
)}
</div> </div>
)} )}
/> />