mirror of https://github.com/msgbyte/tailchat
				
				
				
			feat: 插件文档增加渲染图片的能力
							parent
							
								
									e0225cfb76
								
							
						
					
					
						commit
						61f4ea35c8
					
				@ -0,0 +1,11 @@
 | 
			
		||||
## 喵语翻译
 | 
			
		||||
 | 
			
		||||
允许用户将自然语言转换为加密后的喵语
 | 
			
		||||
 | 
			
		||||
在任意聊天款的右侧添加喵语翻译
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
在此输入的任意内容都会被转换为加密后的喵语言,只有安装了相同插件的用户才能翻译
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 9.6 KiB  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 4.5 KiB  | 
@ -1,3 +1,56 @@
 | 
			
		||||
import { Alert } from 'antd';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import { t } from 'tailchat-shared';
 | 
			
		||||
import { Problem } from './Problem';
 | 
			
		||||
 | 
			
		||||
export const ErrorBoundary = Alert.ErrorBoundary;
 | 
			
		||||
interface ErrorBoundaryProps {
 | 
			
		||||
  message?: React.ReactNode;
 | 
			
		||||
  description?: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class ErrorBoundary extends React.Component<
 | 
			
		||||
  ErrorBoundaryProps,
 | 
			
		||||
  {
 | 
			
		||||
    error?: Error | null;
 | 
			
		||||
    info: {
 | 
			
		||||
      componentStack?: string;
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
> {
 | 
			
		||||
  state = {
 | 
			
		||||
    error: undefined,
 | 
			
		||||
    info: {
 | 
			
		||||
      componentStack: '',
 | 
			
		||||
    },
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  componentDidCatch(error: Error | null, info: any) {
 | 
			
		||||
    this.setState({ error, info });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  render() {
 | 
			
		||||
    const { message, description, children } = this.props;
 | 
			
		||||
    const { error, info } = this.state;
 | 
			
		||||
    const componentStack =
 | 
			
		||||
      info && info.componentStack ? info.componentStack : null;
 | 
			
		||||
    const errorMessage =
 | 
			
		||||
      typeof message === 'undefined' ? (error || '').toString() : message;
 | 
			
		||||
    const errorDescription =
 | 
			
		||||
      typeof description === 'undefined' ? componentStack : description;
 | 
			
		||||
    if (error) {
 | 
			
		||||
      return (
 | 
			
		||||
        <div className="p-2">
 | 
			
		||||
          <Problem
 | 
			
		||||
            text={
 | 
			
		||||
              <>
 | 
			
		||||
                <h3>{t('页面出现了一些问题')}</h3>
 | 
			
		||||
                <p title={errorDescription ?? ''}>{errorMessage}</p>
 | 
			
		||||
              </>
 | 
			
		||||
            }
 | 
			
		||||
          />
 | 
			
		||||
        </div>
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return children;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,14 @@
 | 
			
		||||
import { markAbsoluteUrl } from '../url-helper';
 | 
			
		||||
 | 
			
		||||
describe('markAbsoluteUrl', () => {
 | 
			
		||||
  test.each([
 | 
			
		||||
    ['bar', 'https://www.example.com/foo/bar'],
 | 
			
		||||
    ['./bar', 'https://www.example.com/foo/bar'],
 | 
			
		||||
    ['../bar', 'https://www.example.com/bar'],
 | 
			
		||||
    ['/bar', 'https://www.example.com/bar'],
 | 
			
		||||
    ['https://www.baidu.com', 'https://www.baidu.com/'],
 | 
			
		||||
    ['https://www.baidu.com/search', 'https://www.baidu.com/search'],
 | 
			
		||||
  ])('%s', (input, output) => {
 | 
			
		||||
    expect(markAbsoluteUrl(input)).toBe(output);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
/**
 | 
			
		||||
 * 根据输入url返回绝对url
 | 
			
		||||
 * @param relativeUrl 相对或绝对url
 | 
			
		||||
 * @returns 绝对url
 | 
			
		||||
 */
 | 
			
		||||
export function markAbsoluteUrl(relativeUrl: string): string {
 | 
			
		||||
  return new URL(relativeUrl, location.href).href;
 | 
			
		||||
}
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue