@alifd/chat 0.3.0-beta.0 → 0.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/HTMLRenderer/index.less +0 -2
- package/es/core/variables.scss +1 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/es/markdown/index.js +44 -7
- package/es/markdown/main.scss +6 -4
- package/es/origin/index.d.ts +11 -0
- package/es/origin/index.js +19 -0
- package/es/origin/main.scss +18 -0
- package/es/origin/style.d.ts +1 -0
- package/es/origin/style.js +1 -0
- package/es/origin/types.d.ts +12 -0
- package/es/origin/types.js +1 -0
- package/lib/HTMLRenderer/index.less +0 -2
- package/lib/core/variables.scss +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -2
- package/lib/markdown/index.js +44 -7
- package/lib/markdown/main.scss +6 -4
- package/lib/origin/index.d.ts +11 -0
- package/lib/origin/index.js +22 -0
- package/lib/origin/main.scss +18 -0
- package/lib/origin/style.d.ts +1 -0
- package/lib/origin/style.js +3 -0
- package/lib/origin/types.d.ts +12 -0
- package/lib/origin/types.js +2 -0
- package/package.json +13 -1
package/es/core/variables.scss
CHANGED
package/es/index.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ export { default as ImagePreview } from './ImagePreview';
|
|
|
17
17
|
export { default as HTMLRenderer } from './HTMLRenderer';
|
|
18
18
|
export { default as Markdown } from './markdown';
|
|
19
19
|
export { default as CardLoading } from './card-loading';
|
|
20
|
+
export { default as Origin } from './origin';
|
|
20
21
|
export declare const version: string;
|
package/es/index.js
CHANGED
|
@@ -17,4 +17,5 @@ export { default as ImagePreview } from './ImagePreview';
|
|
|
17
17
|
export { default as HTMLRenderer } from './HTMLRenderer';
|
|
18
18
|
export { default as Markdown } from './markdown';
|
|
19
19
|
export { default as CardLoading } from './card-loading';
|
|
20
|
-
export
|
|
20
|
+
export { default as Origin } from './origin';
|
|
21
|
+
export const version = '0.3.0-beta.2';
|
package/es/markdown/index.js
CHANGED
|
@@ -23,6 +23,18 @@ const Markdown = forwardRef(({ className, onReady, content }, ref) => {
|
|
|
23
23
|
const containerRef = useRef(null);
|
|
24
24
|
// 处理 HTML 标签
|
|
25
25
|
const processedContent = useMemo(() => {
|
|
26
|
+
// 使用 Record 类型来定义映射关系
|
|
27
|
+
const sizeTokenToTagMap = {
|
|
28
|
+
common_hypertitle_text_style__font_size: 'h1',
|
|
29
|
+
common_largetitle_text_style__font_size: 'h1',
|
|
30
|
+
common_h1_text_style__font_size: 'h1',
|
|
31
|
+
common_h2_text_style__font_size: 'h2',
|
|
32
|
+
common_h3_text_style__font_size: 'h3',
|
|
33
|
+
common_h4_text_style__font_size: 'h4',
|
|
34
|
+
common_h5_text_style__font_size: 'h5',
|
|
35
|
+
common_body_text_style__font_size: 'span',
|
|
36
|
+
common_footnote_text_style__font_size: 'span'
|
|
37
|
+
};
|
|
26
38
|
const regex = /<font\s+([^>]+)>([^<]+)<\/font>/g;
|
|
27
39
|
return content.replace(regex, (match, attributes, text) => {
|
|
28
40
|
let sizeToken = '';
|
|
@@ -45,7 +57,10 @@ const Markdown = forwardRef(({ className, onReady, content }, ref) => {
|
|
|
45
57
|
styleParts.push(`color: var(--${colorTokenV2})`);
|
|
46
58
|
}
|
|
47
59
|
const style = styleParts.join('; ');
|
|
48
|
-
|
|
60
|
+
// 根据 sizeToken 选择适当的标签
|
|
61
|
+
const tag = sizeTokenToTagMap[sizeToken] || 'span';
|
|
62
|
+
return `<${tag} style="${style}" class="markdownFont">${text}</${tag}>`;
|
|
63
|
+
// return `<span style="${style}">${text}</span>`;
|
|
49
64
|
});
|
|
50
65
|
}, [content]);
|
|
51
66
|
// 转换表情符号
|
|
@@ -114,12 +129,34 @@ const Markdown = forwardRef(({ className, onReady, content }, ref) => {
|
|
|
114
129
|
copyButton.className = 'code-block-copy';
|
|
115
130
|
copyButton.textContent = '复制';
|
|
116
131
|
copyButton.onclick = () => {
|
|
117
|
-
navigator.clipboard.writeText
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
132
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
133
|
+
navigator.clipboard.writeText(code).then(() => {
|
|
134
|
+
copyButton.textContent = '已复制';
|
|
135
|
+
setTimeout(() => {
|
|
136
|
+
copyButton.textContent = '复制';
|
|
137
|
+
}, 1000);
|
|
138
|
+
}).catch(() => {
|
|
139
|
+
copyButton.textContent = '复制失败';
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
//有些环境还不支持navigator.clipboard,降级使用document.execCommand
|
|
144
|
+
const textArea = document.createElement('textarea');
|
|
145
|
+
textArea.value = code;
|
|
146
|
+
document.body.appendChild(textArea);
|
|
147
|
+
textArea.select();
|
|
148
|
+
try {
|
|
149
|
+
document.execCommand('copy');
|
|
150
|
+
copyButton.textContent = '已复制';
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
copyButton.textContent = '复制';
|
|
153
|
+
}, 1000);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
copyButton.textContent = '复制失败';
|
|
157
|
+
}
|
|
158
|
+
document.body.removeChild(textArea);
|
|
159
|
+
}
|
|
123
160
|
};
|
|
124
161
|
header.appendChild(languageSpan);
|
|
125
162
|
header.appendChild(copyButton);
|
package/es/markdown/main.scss
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
@import "../core/variables.scss";
|
|
2
|
+
|
|
3
|
+
$primaryColor: $color-brand1-6;
|
|
2
4
|
$alternativePrimaryColor: $primaryColor;
|
|
3
|
-
$mistPrimaryColor:
|
|
4
|
-
$mediumTextColor:
|
|
5
|
-
$subTextColor:
|
|
5
|
+
$mistPrimaryColor: $color-brand1-1;
|
|
6
|
+
$mediumTextColor: $color-text1-3;
|
|
7
|
+
$subTextColor: $color-text1-2;
|
|
6
8
|
|
|
7
9
|
@mixin f-single-line() {
|
|
8
10
|
overflow: hidden;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @component Origin
|
|
3
|
+
* @en Origin
|
|
4
|
+
* @type 通用 - Origin
|
|
5
|
+
* @when Origin
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { OriginProps } from './types';
|
|
9
|
+
export * from './types';
|
|
10
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<OriginProps & React.RefAttributes<HTMLDivElement>, "key" | keyof OriginProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, HTMLDivElement, {}>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @component Origin
|
|
3
|
+
* @en Origin
|
|
4
|
+
* @type 通用 - Origin
|
|
5
|
+
* @when Origin
|
|
6
|
+
*/
|
|
7
|
+
import React, { forwardRef } from 'react';
|
|
8
|
+
import { ConfigProvider } from '@alifd/next';
|
|
9
|
+
import cs from 'classnames';
|
|
10
|
+
import { PREFIX_DEFAULT, assignSubComponent } from '../utils';
|
|
11
|
+
const Origin = forwardRef(({ className, text }, ref) => {
|
|
12
|
+
return (React.createElement("div", { className: cs(`${PREFIX_DEFAULT}origin`, className) },
|
|
13
|
+
React.createElement("div", { className: 'origin-tip-inner' }, text)));
|
|
14
|
+
});
|
|
15
|
+
const OriginWithSub = assignSubComponent(Origin, {
|
|
16
|
+
displayName: 'Origin',
|
|
17
|
+
});
|
|
18
|
+
export * from './types';
|
|
19
|
+
export default ConfigProvider.config(OriginWithSub);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@import "../core/variables.scss";
|
|
2
|
+
|
|
3
|
+
.#{$prefix}origin {
|
|
4
|
+
display: flex;
|
|
5
|
+
justify-content: flex-end;
|
|
6
|
+
.origin-tip-inner {
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
white-space: nowrap;
|
|
9
|
+
text-overflow: ellipsis;
|
|
10
|
+
background: linear-gradient(90deg, transparent, $color-brand1-1);
|
|
11
|
+
padding: 0 16px 0 32px;
|
|
12
|
+
color: $color-text1-3;
|
|
13
|
+
min-width: 0;
|
|
14
|
+
flex: 0 1 auto;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
line-height: 20px;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './main.scss';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './main.scss';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type CommonProps } from '@alifd/next';
|
|
3
|
+
/**
|
|
4
|
+
* @api
|
|
5
|
+
*/
|
|
6
|
+
export interface OriginProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 来源的文案或者dom内容
|
|
10
|
+
*/
|
|
11
|
+
text?: string | ReactNode;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/core/variables.scss
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ export { default as ImagePreview } from './ImagePreview';
|
|
|
17
17
|
export { default as HTMLRenderer } from './HTMLRenderer';
|
|
18
18
|
export { default as Markdown } from './markdown';
|
|
19
19
|
export { default as CardLoading } from './card-loading';
|
|
20
|
+
export { default as Origin } from './origin';
|
|
20
21
|
export declare const version: string;
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.version = exports.CardLoading = exports.Markdown = exports.HTMLRenderer = exports.ImagePreview = exports.List = exports.Balloon = exports.Icon = exports.Message = exports.PersonPicker = exports.TimePicker = exports.DatePicker = exports.Input = exports.Tab = exports.Tag = exports.Text = exports.FloatButton = exports.Feedback = exports.Card = exports.Button = void 0;
|
|
3
|
+
exports.version = exports.Origin = exports.CardLoading = exports.Markdown = exports.HTMLRenderer = exports.ImagePreview = exports.List = exports.Balloon = exports.Icon = exports.Message = exports.PersonPicker = exports.TimePicker = exports.DatePicker = exports.Input = exports.Tab = exports.Tag = exports.Text = exports.FloatButton = exports.Feedback = exports.Card = exports.Button = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
var button_1 = require("./button");
|
|
6
6
|
Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return tslib_1.__importDefault(button_1).default; } });
|
|
@@ -40,4 +40,6 @@ var markdown_1 = require("./markdown");
|
|
|
40
40
|
Object.defineProperty(exports, "Markdown", { enumerable: true, get: function () { return tslib_1.__importDefault(markdown_1).default; } });
|
|
41
41
|
var card_loading_1 = require("./card-loading");
|
|
42
42
|
Object.defineProperty(exports, "CardLoading", { enumerable: true, get: function () { return tslib_1.__importDefault(card_loading_1).default; } });
|
|
43
|
-
|
|
43
|
+
var origin_1 = require("./origin");
|
|
44
|
+
Object.defineProperty(exports, "Origin", { enumerable: true, get: function () { return tslib_1.__importDefault(origin_1).default; } });
|
|
45
|
+
exports.version = '0.3.0-beta.2';
|
package/lib/markdown/index.js
CHANGED
|
@@ -26,6 +26,18 @@ const Markdown = (0, react_1.forwardRef)(({ className, onReady, content }, ref)
|
|
|
26
26
|
const containerRef = (0, react_1.useRef)(null);
|
|
27
27
|
// 处理 HTML 标签
|
|
28
28
|
const processedContent = (0, react_1.useMemo)(() => {
|
|
29
|
+
// 使用 Record 类型来定义映射关系
|
|
30
|
+
const sizeTokenToTagMap = {
|
|
31
|
+
common_hypertitle_text_style__font_size: 'h1',
|
|
32
|
+
common_largetitle_text_style__font_size: 'h1',
|
|
33
|
+
common_h1_text_style__font_size: 'h1',
|
|
34
|
+
common_h2_text_style__font_size: 'h2',
|
|
35
|
+
common_h3_text_style__font_size: 'h3',
|
|
36
|
+
common_h4_text_style__font_size: 'h4',
|
|
37
|
+
common_h5_text_style__font_size: 'h5',
|
|
38
|
+
common_body_text_style__font_size: 'span',
|
|
39
|
+
common_footnote_text_style__font_size: 'span'
|
|
40
|
+
};
|
|
29
41
|
const regex = /<font\s+([^>]+)>([^<]+)<\/font>/g;
|
|
30
42
|
return content.replace(regex, (match, attributes, text) => {
|
|
31
43
|
let sizeToken = '';
|
|
@@ -48,7 +60,10 @@ const Markdown = (0, react_1.forwardRef)(({ className, onReady, content }, ref)
|
|
|
48
60
|
styleParts.push(`color: var(--${colorTokenV2})`);
|
|
49
61
|
}
|
|
50
62
|
const style = styleParts.join('; ');
|
|
51
|
-
|
|
63
|
+
// 根据 sizeToken 选择适当的标签
|
|
64
|
+
const tag = sizeTokenToTagMap[sizeToken] || 'span';
|
|
65
|
+
return `<${tag} style="${style}" class="markdownFont">${text}</${tag}>`;
|
|
66
|
+
// return `<span style="${style}">${text}</span>`;
|
|
52
67
|
});
|
|
53
68
|
}, [content]);
|
|
54
69
|
// 转换表情符号
|
|
@@ -117,12 +132,34 @@ const Markdown = (0, react_1.forwardRef)(({ className, onReady, content }, ref)
|
|
|
117
132
|
copyButton.className = 'code-block-copy';
|
|
118
133
|
copyButton.textContent = '复制';
|
|
119
134
|
copyButton.onclick = () => {
|
|
120
|
-
navigator.clipboard.writeText
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && navigator.clipboard.writeText) {
|
|
136
|
+
navigator.clipboard.writeText(code).then(() => {
|
|
137
|
+
copyButton.textContent = '已复制';
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
copyButton.textContent = '复制';
|
|
140
|
+
}, 1000);
|
|
141
|
+
}).catch(() => {
|
|
142
|
+
copyButton.textContent = '复制失败';
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
//有些环境还不支持navigator.clipboard,降级使用document.execCommand
|
|
147
|
+
const textArea = document.createElement('textarea');
|
|
148
|
+
textArea.value = code;
|
|
149
|
+
document.body.appendChild(textArea);
|
|
150
|
+
textArea.select();
|
|
151
|
+
try {
|
|
152
|
+
document.execCommand('copy');
|
|
153
|
+
copyButton.textContent = '已复制';
|
|
154
|
+
setTimeout(() => {
|
|
155
|
+
copyButton.textContent = '复制';
|
|
156
|
+
}, 1000);
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
copyButton.textContent = '复制失败';
|
|
160
|
+
}
|
|
161
|
+
document.body.removeChild(textArea);
|
|
162
|
+
}
|
|
126
163
|
};
|
|
127
164
|
header.appendChild(languageSpan);
|
|
128
165
|
header.appendChild(copyButton);
|
package/lib/markdown/main.scss
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
@import "../core/variables.scss";
|
|
2
|
+
|
|
3
|
+
$primaryColor: $color-brand1-6;
|
|
2
4
|
$alternativePrimaryColor: $primaryColor;
|
|
3
|
-
$mistPrimaryColor:
|
|
4
|
-
$mediumTextColor:
|
|
5
|
-
$subTextColor:
|
|
5
|
+
$mistPrimaryColor: $color-brand1-1;
|
|
6
|
+
$mediumTextColor: $color-text1-3;
|
|
7
|
+
$subTextColor: $color-text1-2;
|
|
6
8
|
|
|
7
9
|
@mixin f-single-line() {
|
|
8
10
|
overflow: hidden;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @component Origin
|
|
3
|
+
* @en Origin
|
|
4
|
+
* @type 通用 - Origin
|
|
5
|
+
* @when Origin
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { OriginProps } from './types';
|
|
9
|
+
export * from './types';
|
|
10
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<OriginProps & React.RefAttributes<HTMLDivElement>, "key" | keyof OriginProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, HTMLDivElement, {}>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @component Origin
|
|
4
|
+
* @en Origin
|
|
5
|
+
* @type 通用 - Origin
|
|
6
|
+
* @when Origin
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
11
|
+
const next_1 = require("@alifd/next");
|
|
12
|
+
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const Origin = (0, react_1.forwardRef)(({ className, text }, ref) => {
|
|
15
|
+
return (react_1.default.createElement("div", { className: (0, classnames_1.default)(`${utils_1.PREFIX_DEFAULT}origin`, className) },
|
|
16
|
+
react_1.default.createElement("div", { className: 'origin-tip-inner' }, text)));
|
|
17
|
+
});
|
|
18
|
+
const OriginWithSub = (0, utils_1.assignSubComponent)(Origin, {
|
|
19
|
+
displayName: 'Origin',
|
|
20
|
+
});
|
|
21
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
22
|
+
exports.default = next_1.ConfigProvider.config(OriginWithSub);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@import "../core/variables.scss";
|
|
2
|
+
|
|
3
|
+
.#{$prefix}origin {
|
|
4
|
+
display: flex;
|
|
5
|
+
justify-content: flex-end;
|
|
6
|
+
.origin-tip-inner {
|
|
7
|
+
overflow: hidden;
|
|
8
|
+
white-space: nowrap;
|
|
9
|
+
text-overflow: ellipsis;
|
|
10
|
+
background: linear-gradient(90deg, transparent, $color-brand1-1);
|
|
11
|
+
padding: 0 16px 0 32px;
|
|
12
|
+
color: $color-text1-3;
|
|
13
|
+
min-width: 0;
|
|
14
|
+
flex: 0 1 auto;
|
|
15
|
+
font-size: 12px;
|
|
16
|
+
line-height: 20px;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './main.scss';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type CommonProps } from '@alifd/next';
|
|
3
|
+
/**
|
|
4
|
+
* @api
|
|
5
|
+
*/
|
|
6
|
+
export interface OriginProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 来源的文案或者dom内容
|
|
10
|
+
*/
|
|
11
|
+
text?: string | ReactNode;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alifd/chat",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.2",
|
|
4
4
|
"description": "A configurable component library for chat built on React.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -265,6 +265,18 @@
|
|
|
265
265
|
"./card-loading/style.js": {
|
|
266
266
|
"import": "./es/card-loading/style.js",
|
|
267
267
|
"require": "./lib/card-loading/style.js"
|
|
268
|
+
},
|
|
269
|
+
"./origin": {
|
|
270
|
+
"import": "./es/origin/index.js",
|
|
271
|
+
"require": "./lib/origin/index.js"
|
|
272
|
+
},
|
|
273
|
+
"./origin/style": {
|
|
274
|
+
"import": "./es/origin/style.js",
|
|
275
|
+
"require": "./lib/origin/style.js"
|
|
276
|
+
},
|
|
277
|
+
"./origin/style.js": {
|
|
278
|
+
"import": "./es/origin/style.js",
|
|
279
|
+
"require": "./lib/origin/style.js"
|
|
268
280
|
}
|
|
269
281
|
},
|
|
270
282
|
"files": [
|