@king-design/vue 3.7.0 → 3.8.0-beta.0
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/__tests__/__snapshots__/Vue Next Demos.md +399 -0
- package/components/bubble/bubble.d.ts +61 -0
- package/components/bubble/bubble.js +81 -0
- package/components/bubble/bubble.vdt.js +85 -0
- package/components/bubble/index.d.ts +1 -0
- package/components/bubble/index.js +1 -0
- package/components/bubble/index.spec.d.ts +1 -0
- package/components/bubble/index.spec.js +771 -0
- package/components/bubble/styles.d.ts +5 -0
- package/components/bubble/styles.js +53 -0
- package/components/bubble/useBubbleDisplay.d.ts +18 -0
- package/components/bubble/useBubbleDisplay.js +300 -0
- package/components/bubbleList/bubbleList.d.ts +87 -0
- package/components/bubbleList/bubbleList.js +75 -0
- package/components/bubbleList/bubbleList.vdt.js +143 -0
- package/components/bubbleList/index.d.ts +1 -0
- package/components/bubbleList/index.js +1 -0
- package/components/bubbleList/index.spec.d.ts +1 -0
- package/components/bubbleList/index.spec.js +1268 -0
- package/components/bubbleList/item.d.ts +16 -0
- package/components/bubbleList/item.js +27 -0
- package/components/bubbleList/item.vdt.js +36 -0
- package/components/bubbleList/styles.d.ts +5 -0
- package/components/bubbleList/styles.js +33 -0
- package/components/bubbleList/useBubbleList.d.ts +28 -0
- package/components/bubbleList/useBubbleList.js +455 -0
- package/components/checkbox/index.d.ts +3 -3
- package/components/fileCard/fileCard.d.ts +65 -0
- package/components/fileCard/fileCard.js +72 -0
- package/components/fileCard/fileCard.vdt.js +161 -0
- package/components/fileCard/fileCardAssets.d.ts +1 -0
- package/components/fileCard/fileCardAssets.js +54 -0
- package/components/fileCard/fileCardUtils.d.ts +14 -0
- package/components/fileCard/fileCardUtils.js +94 -0
- package/components/fileCard/index.d.ts +2 -0
- package/components/fileCard/index.js +2 -0
- package/components/fileCard/index.spec.d.ts +1 -0
- package/components/fileCard/index.spec.js +1096 -0
- package/components/fileCard/list.d.ts +29 -0
- package/components/fileCard/list.js +46 -0
- package/components/fileCard/list.vdt.js +71 -0
- package/components/fileCard/styles.d.ts +5 -0
- package/components/fileCard/styles.js +83 -0
- package/components/fileCard/useFileCard.d.ts +45 -0
- package/components/fileCard/useFileCard.js +330 -0
- package/components/fileCard/useFileCardList.d.ts +14 -0
- package/components/fileCard/useFileCardList.js +49 -0
- package/components/form/form.js +2 -1
- package/components/media/context.d.ts +6 -0
- package/components/media/context.js +2 -0
- package/components/media/group.d.ts +12 -0
- package/components/media/group.js +32 -0
- package/components/media/group.vdt.js +50 -0
- package/components/media/index.d.ts +2 -0
- package/components/media/index.js +2 -0
- package/components/media/index.spec.d.ts +1 -0
- package/components/media/index.spec.js +1691 -0
- package/components/media/media.d.ts +37 -0
- package/components/media/media.js +67 -0
- package/components/media/media.vdt.js +202 -0
- package/components/media/mediaAssets.d.ts +4 -0
- package/components/media/mediaAssets.js +9 -0
- package/components/media/mediaUtils.d.ts +6 -0
- package/components/media/mediaUtils.js +66 -0
- package/components/media/styles.d.ts +13 -0
- package/components/media/styles.js +52 -0
- package/components/media/types.d.ts +37 -0
- package/components/media/types.js +1 -0
- package/components/media/useMedia.d.ts +70 -0
- package/components/media/useMedia.js +471 -0
- package/components/media/useMediaGroup.d.ts +15 -0
- package/components/media/useMediaGroup.js +136 -0
- package/components/media/useMediaViewer.d.ts +14 -0
- package/components/media/useMediaViewer.js +129 -0
- package/components/media/viewer.d.ts +24 -0
- package/components/media/viewer.js +54 -0
- package/components/media/viewer.vdt.js +100 -0
- package/components/radio/index.d.ts +3 -3
- package/components/sender/icons.d.ts +3 -0
- package/components/sender/icons.js +17 -0
- package/components/sender/index.d.ts +1 -0
- package/components/sender/index.js +1 -0
- package/components/sender/index.spec.d.ts +1 -0
- package/components/sender/index.spec.js +1597 -0
- package/components/sender/sender.d.ts +104 -0
- package/components/sender/sender.js +111 -0
- package/components/sender/sender.vdt.js +230 -0
- package/components/sender/styles.d.ts +5 -0
- package/components/sender/styles.js +56 -0
- package/components/sender/useAutoResize.d.ts +4 -0
- package/components/sender/useAutoResize.js +99 -0
- package/components/sender/useSenderDrag.d.ts +6 -0
- package/components/sender/useSenderDrag.js +320 -0
- package/components/sender/useSenderInput.d.ts +16 -0
- package/components/sender/useSenderInput.js +101 -0
- package/components/sender/useSenderPaste.d.ts +5 -0
- package/components/sender/useSenderPaste.js +36 -0
- package/components/sender/useSenderUpload.d.ts +11 -0
- package/components/sender/useSenderUpload.js +395 -0
- package/components/skeleton/skeleton.d.ts +2 -1
- package/components/skeleton/skeleton.js +1 -1
- package/components/think/index.d.ts +1 -0
- package/components/think/index.js +1 -0
- package/components/think/index.spec.d.ts +1 -0
- package/components/think/index.spec.js +345 -0
- package/components/think/index.vdt.js +82 -0
- package/components/think/styles.d.ts +5 -0
- package/components/think/styles.js +25 -0
- package/components/think/think.d.ts +28 -0
- package/components/think/think.js +48 -0
- package/components/think/useThinkExpand.d.ts +10 -0
- package/components/think/useThinkExpand.js +56 -0
- package/components/types.d.ts +4 -2
- package/components/upload/ajaxUploader.d.ts +1 -0
- package/components/upload/ajaxUploader.js +6 -0
- package/components/xmarkdown/index.d.ts +2 -0
- package/components/xmarkdown/index.js +1 -0
- package/components/xmarkdown/index.spec.d.ts +1 -0
- package/components/xmarkdown/index.spec.js +1666 -0
- package/components/xmarkdown/markdown/codeBlockRenderer.d.ts +8 -0
- package/components/xmarkdown/markdown/codeBlockRenderer.js +52 -0
- package/components/xmarkdown/markdown/codeblock.d.ts +8 -0
- package/components/xmarkdown/markdown/codeblock.js +74 -0
- package/components/xmarkdown/markdown/highlight.d.ts +17 -0
- package/components/xmarkdown/markdown/highlight.js +83 -0
- package/components/xmarkdown/markdown/index.d.ts +14 -0
- package/components/xmarkdown/markdown/index.js +14 -0
- package/components/xmarkdown/markdown/mermaid.d.ts +8 -0
- package/components/xmarkdown/markdown/mermaid.js +104 -0
- package/components/xmarkdown/markdown/renderTree.d.ts +54 -0
- package/components/xmarkdown/markdown/renderTree.js +386 -0
- package/components/xmarkdown/markdown/renderer.d.ts +18 -0
- package/components/xmarkdown/markdown/renderer.js +461 -0
- package/components/xmarkdown/markdown/streaming.d.ts +24 -0
- package/components/xmarkdown/markdown/streaming.js +513 -0
- package/components/xmarkdown/markdown/types.d.ts +124 -0
- package/components/xmarkdown/markdown/types.js +6 -0
- package/components/xmarkdown/markdown/utils.d.ts +7 -0
- package/components/xmarkdown/markdown/utils.js +9 -0
- package/components/xmarkdown/markdown.d.ts +1 -0
- package/components/xmarkdown/markdown.js +1 -0
- package/components/xmarkdown/styles.d.ts +5 -0
- package/components/xmarkdown/styles.js +50 -0
- package/components/xmarkdown/useMermaid.d.ts +27 -0
- package/components/xmarkdown/useMermaid.js +745 -0
- package/components/xmarkdown/useXMarkdownContent.d.ts +14 -0
- package/components/xmarkdown/useXMarkdownContent.js +218 -0
- package/components/xmarkdown/useXMarkdownDisplay.d.ts +26 -0
- package/components/xmarkdown/useXMarkdownDisplay.js +569 -0
- package/components/xmarkdown/xmarkdown.d.ts +61 -0
- package/components/xmarkdown/xmarkdown.js +109 -0
- package/components/xmarkdown/xmarkdown.vdt.js +43 -0
- package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
- package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
- package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
- package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
- package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/i18n/en-US.js +29 -1
- package/dist/i18n/en-US.js.map +1 -1
- package/dist/i18n/en-US.min.js +1 -1
- package/dist/index.js +100506 -37457
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1569 -1
- package/dist/kpc.css +4 -0
- package/dist/ksyun.css +4 -0
- package/i18n/en-US.d.ts +27 -0
- package/i18n/en-US.js +29 -1
- package/index.d.ts +9 -2
- package/index.js +9 -2
- package/package.json +8 -2
- package/styles/global.js +12 -6
- package/yarn-error.log +0 -1012
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Component, TypeDefs } from 'intact-vue-next';
|
|
2
|
+
import type { Events } from '../types';
|
|
3
|
+
import type { FileCardListItem } from '../fileCard';
|
|
4
|
+
import type { RequestError } from '../upload';
|
|
5
|
+
export type SenderType = 'text' | 'image';
|
|
6
|
+
export interface SenderAttachment extends FileCardListItem {
|
|
7
|
+
uid?: number | string;
|
|
8
|
+
raw?: File;
|
|
9
|
+
relativePath?: string;
|
|
10
|
+
/** 进行中的 XHR,用于删除时 abort */
|
|
11
|
+
request?: {
|
|
12
|
+
abort(): void;
|
|
13
|
+
} | null;
|
|
14
|
+
}
|
|
15
|
+
export interface SenderUploadProps {
|
|
16
|
+
accept?: string;
|
|
17
|
+
multiple?: boolean;
|
|
18
|
+
directory?: boolean;
|
|
19
|
+
limit?: number;
|
|
20
|
+
maxSize?: number;
|
|
21
|
+
autoUpload?: boolean;
|
|
22
|
+
action?: string;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
name?: string;
|
|
25
|
+
headers?: Record<string | number, string>;
|
|
26
|
+
data?: Record<string, any> | ((file: SenderAttachment) => Record<string, any>);
|
|
27
|
+
mapAttachment?: (file: File, attachment: SenderAttachment) => Partial<SenderAttachment>;
|
|
28
|
+
withCredentials?: boolean;
|
|
29
|
+
beforeUpload?: (file: SenderAttachment, files: SenderAttachment[]) => boolean | Promise<boolean>;
|
|
30
|
+
beforeRemove?: (file: SenderAttachment, files: SenderAttachment[]) => boolean | Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
export interface SendButtonSlotParams {
|
|
33
|
+
generating: boolean;
|
|
34
|
+
disabled: boolean;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
send: () => void;
|
|
37
|
+
stopGenerate: () => void;
|
|
38
|
+
}
|
|
39
|
+
export interface MessageSendPayload {
|
|
40
|
+
value: string;
|
|
41
|
+
attachments: SenderAttachment[];
|
|
42
|
+
}
|
|
43
|
+
export interface SenderProps {
|
|
44
|
+
value?: string;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
readonly?: boolean;
|
|
48
|
+
generating?: boolean;
|
|
49
|
+
loading?: boolean;
|
|
50
|
+
type?: SenderType;
|
|
51
|
+
dragFile?: boolean;
|
|
52
|
+
pasteFile?: boolean;
|
|
53
|
+
/** 整个输入外框 `k-sender` 的宽度,数字会按 `px` 处理 */
|
|
54
|
+
width?: number | string;
|
|
55
|
+
/** 整个输入外框 `k-sender-shell` 的最大高度(非文本域单宽),未传时默认 300 */
|
|
56
|
+
maxHeight?: number | string;
|
|
57
|
+
attachments?: SenderAttachment[];
|
|
58
|
+
uploadProps?: SenderUploadProps;
|
|
59
|
+
showAttachmentsButton?: boolean;
|
|
60
|
+
submitOnEnter?: boolean;
|
|
61
|
+
clearOnSend?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface SenderEvents {
|
|
64
|
+
messageSend: [MessageSendPayload];
|
|
65
|
+
stopGenerate: [];
|
|
66
|
+
pressEnter: [KeyboardEvent];
|
|
67
|
+
focus: [FocusEvent];
|
|
68
|
+
blur: [FocusEvent];
|
|
69
|
+
attachmentClick: [SenderAttachment, MouseEvent];
|
|
70
|
+
attachmentDelete: [SenderAttachment, MouseEvent];
|
|
71
|
+
uploadProgress: [ProgressEvent, SenderAttachment];
|
|
72
|
+
uploadSuccess: [any, SenderAttachment];
|
|
73
|
+
uploadError: [Error | RequestError, SenderAttachment];
|
|
74
|
+
}
|
|
75
|
+
export interface SenderBlocks {
|
|
76
|
+
header: null;
|
|
77
|
+
beforeInput: null;
|
|
78
|
+
footer: null;
|
|
79
|
+
configure: null;
|
|
80
|
+
attachmentsButton: null;
|
|
81
|
+
sendButton: SendButtonSlotParams;
|
|
82
|
+
}
|
|
83
|
+
export declare class Sender extends Component<SenderProps, SenderEvents, SenderBlocks> {
|
|
84
|
+
static template: string | import('intact-vue-next').Template<any>;
|
|
85
|
+
static typeDefs: Required<TypeDefs<SenderProps>>;
|
|
86
|
+
static defaults: () => Partial<SenderProps>;
|
|
87
|
+
static events: Events<SenderEvents>;
|
|
88
|
+
private config;
|
|
89
|
+
private textareaRef;
|
|
90
|
+
private fileInputRef;
|
|
91
|
+
private input;
|
|
92
|
+
private autoResize;
|
|
93
|
+
private upload;
|
|
94
|
+
private dragController;
|
|
95
|
+
private pasteController;
|
|
96
|
+
focus(): void;
|
|
97
|
+
blur(): void;
|
|
98
|
+
/** 主动触发发送,等价于点击发送按钮。生成中时不会触发。 */
|
|
99
|
+
submit(): void;
|
|
100
|
+
/** 清空输入框与附件列表,并中止进行中的上传;不影响 generating / loading 等受控状态。 */
|
|
101
|
+
clear(): void;
|
|
102
|
+
/** 主动触发停止生成,等价于点击生成中的停止按钮。 */
|
|
103
|
+
stopGenerate(): void;
|
|
104
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
3
|
+
import { Component, createRef } from 'intact-vue-next';
|
|
4
|
+
import template from './sender.vdt';
|
|
5
|
+
import { useConfigContext } from '../config';
|
|
6
|
+
import { useSenderInput } from './useSenderInput';
|
|
7
|
+
import { useSenderUpload } from './useSenderUpload';
|
|
8
|
+
import { useAutoResize } from './useAutoResize';
|
|
9
|
+
import { useSenderDrag } from './useSenderDrag';
|
|
10
|
+
import { useSenderPaste } from './useSenderPaste';
|
|
11
|
+
var typeDefs = {
|
|
12
|
+
value: String,
|
|
13
|
+
placeholder: String,
|
|
14
|
+
disabled: Boolean,
|
|
15
|
+
readonly: Boolean,
|
|
16
|
+
generating: Boolean,
|
|
17
|
+
loading: Boolean,
|
|
18
|
+
type: ['text', 'image'],
|
|
19
|
+
dragFile: Boolean,
|
|
20
|
+
pasteFile: Boolean,
|
|
21
|
+
width: [String, Number],
|
|
22
|
+
maxHeight: [String, Number],
|
|
23
|
+
attachments: Array,
|
|
24
|
+
uploadProps: Object,
|
|
25
|
+
showAttachmentsButton: Boolean,
|
|
26
|
+
submitOnEnter: Boolean,
|
|
27
|
+
clearOnSend: Boolean
|
|
28
|
+
};
|
|
29
|
+
var defaults = function defaults() {
|
|
30
|
+
return {
|
|
31
|
+
value: '',
|
|
32
|
+
placeholder: undefined,
|
|
33
|
+
disabled: false,
|
|
34
|
+
readonly: false,
|
|
35
|
+
generating: false,
|
|
36
|
+
loading: false,
|
|
37
|
+
type: 'text',
|
|
38
|
+
dragFile: false,
|
|
39
|
+
pasteFile: false,
|
|
40
|
+
width: 640,
|
|
41
|
+
maxHeight: undefined,
|
|
42
|
+
attachments: undefined,
|
|
43
|
+
uploadProps: undefined,
|
|
44
|
+
showAttachmentsButton: true,
|
|
45
|
+
submitOnEnter: true,
|
|
46
|
+
clearOnSend: true
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
var events = {
|
|
50
|
+
messageSend: true,
|
|
51
|
+
stopGenerate: true,
|
|
52
|
+
pressEnter: true,
|
|
53
|
+
focus: true,
|
|
54
|
+
blur: true,
|
|
55
|
+
attachmentClick: true,
|
|
56
|
+
attachmentDelete: true,
|
|
57
|
+
uploadProgress: true,
|
|
58
|
+
uploadSuccess: true,
|
|
59
|
+
uploadError: true
|
|
60
|
+
};
|
|
61
|
+
export var Sender = /*#__PURE__*/function (_Component) {
|
|
62
|
+
_inheritsLoose(Sender, _Component);
|
|
63
|
+
function Sender() {
|
|
64
|
+
var _context;
|
|
65
|
+
var _this;
|
|
66
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
67
|
+
args[_key] = arguments[_key];
|
|
68
|
+
}
|
|
69
|
+
_this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
70
|
+
_this.config = useConfigContext();
|
|
71
|
+
_this.textareaRef = createRef();
|
|
72
|
+
_this.fileInputRef = createRef();
|
|
73
|
+
_this.input = useSenderInput(_this.textareaRef);
|
|
74
|
+
_this.autoResize = useAutoResize(_this.textareaRef);
|
|
75
|
+
_this.upload = useSenderUpload(_this.fileInputRef);
|
|
76
|
+
_this.dragController = useSenderDrag(_this.upload.addFiles);
|
|
77
|
+
_this.pasteController = useSenderPaste(_this.upload.addFiles);
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
var _proto = Sender.prototype;
|
|
81
|
+
_proto.focus = function focus() {
|
|
82
|
+
var _this$textareaRef$val;
|
|
83
|
+
(_this$textareaRef$val = this.textareaRef.value) == null || _this$textareaRef$val.focus();
|
|
84
|
+
};
|
|
85
|
+
_proto.blur = function blur() {
|
|
86
|
+
var _this$textareaRef$val2;
|
|
87
|
+
(_this$textareaRef$val2 = this.textareaRef.value) == null || _this$textareaRef$val2.blur();
|
|
88
|
+
}
|
|
89
|
+
/** 主动触发发送,等价于点击发送按钮。生成中时不会触发。 */;
|
|
90
|
+
_proto.submit = function submit() {
|
|
91
|
+
this.input.send();
|
|
92
|
+
}
|
|
93
|
+
/** 清空输入框与附件列表,并中止进行中的上传;不影响 generating / loading 等受控状态。 */;
|
|
94
|
+
_proto.clear = function clear() {
|
|
95
|
+
this.set('value', '');
|
|
96
|
+
var attachments = this.get('attachments');
|
|
97
|
+
if (attachments && attachments.length > 0) {
|
|
98
|
+
void this.upload.clearAttachments();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** 主动触发停止生成,等价于点击生成中的停止按钮。 */;
|
|
102
|
+
_proto.stopGenerate = function stopGenerate() {
|
|
103
|
+
if (!this.get('generating')) return;
|
|
104
|
+
this.input.stopGenerate();
|
|
105
|
+
};
|
|
106
|
+
return Sender;
|
|
107
|
+
}(Component);
|
|
108
|
+
Sender.template = template;
|
|
109
|
+
Sender.typeDefs = typeDefs;
|
|
110
|
+
Sender.defaults = defaults;
|
|
111
|
+
Sender.events = events;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
3
|
+
import { createElementVNode as _$ce, className as _$cn, createUnknownComponentVNode as _$cc, createVNode as _$cv, extend as _$ex, EMPTY_OBJ as _$em, noop as _$no, createCommentVNode as _$ccv } from 'intact-vue-next';
|
|
4
|
+
import { FileCardList } from '../fileCard';
|
|
5
|
+
import { Icon } from '../icon';
|
|
6
|
+
import { addStyle, getRestProps } from '../utils';
|
|
7
|
+
import { makeStyles } from './styles';
|
|
8
|
+
import { senderSendIcon, senderStopIcon, senderAttachSvg } from './icons';
|
|
9
|
+
import { _$ } from '../../i18n';
|
|
10
|
+
import { isInvalid, isNumber, noop } from 'intact-shared';
|
|
11
|
+
var _$tmp0 = {
|
|
12
|
+
'aria-hidden': 'true'
|
|
13
|
+
};
|
|
14
|
+
export default function ($props, $blocks, $__proto__) {
|
|
15
|
+
var _this = this,
|
|
16
|
+
_classNameObj,
|
|
17
|
+
_$cn2,
|
|
18
|
+
_$cn3,
|
|
19
|
+
_$cn4;
|
|
20
|
+
$blocks || ($blocks = {});
|
|
21
|
+
$props || ($props = {});
|
|
22
|
+
var $this = this;
|
|
23
|
+
var _$blocks = {};
|
|
24
|
+
var __$blocks = {};
|
|
25
|
+
var _this$input = this.input,
|
|
26
|
+
isFocus = _this$input.isFocus,
|
|
27
|
+
isDisabled = _this$input.isDisabled,
|
|
28
|
+
isGenerating = _this$input.isGenerating,
|
|
29
|
+
isLoading = _this$input.isLoading,
|
|
30
|
+
isSendButtonDisabled = _this$input.isSendButtonDisabled,
|
|
31
|
+
handleKeydown = _this$input.handleKeydown,
|
|
32
|
+
handleInput = _this$input.handleInput,
|
|
33
|
+
handleFocus = _this$input.handleFocus,
|
|
34
|
+
handleBlur = _this$input.handleBlur,
|
|
35
|
+
handleSendClick = _this$input.handleSendClick,
|
|
36
|
+
send = _this$input.send,
|
|
37
|
+
stopGenerate = _this$input.stopGenerate;
|
|
38
|
+
var _this$upload = this.upload,
|
|
39
|
+
getAcceptAttr = _this$upload.getAcceptAttr,
|
|
40
|
+
isMultiple = _this$upload.isMultiple,
|
|
41
|
+
onInputChange = _this$upload.onInputChange,
|
|
42
|
+
pickFiles = _this$upload.pickFiles,
|
|
43
|
+
removeAttachment = _this$upload.removeAttachment;
|
|
44
|
+
var dragController = this.dragController;
|
|
45
|
+
var handlePaste = this.pasteController.handlePaste;
|
|
46
|
+
var _this$get = this.get(),
|
|
47
|
+
className = _this$get.className,
|
|
48
|
+
style = _this$get.style,
|
|
49
|
+
value = _this$get.value,
|
|
50
|
+
placeholder = _this$get.placeholder,
|
|
51
|
+
readonly = _this$get.readonly,
|
|
52
|
+
width = _this$get.width,
|
|
53
|
+
maxHeight = _this$get.maxHeight,
|
|
54
|
+
type = _this$get.type,
|
|
55
|
+
enableDragFile = _this$get.dragFile,
|
|
56
|
+
attachments = _this$get.attachments,
|
|
57
|
+
showAttachmentsButton = _this$get.showAttachmentsButton,
|
|
58
|
+
uploadProps = _this$get.uploadProps;
|
|
59
|
+
var k = this.config.k;
|
|
60
|
+
var isEmptySlot = function isEmptySlot(value) {
|
|
61
|
+
if (isInvalid(value) || value === undefined || value === null || value === '') return true;
|
|
62
|
+
if (Array.isArray(value)) return value.every(function (item) {
|
|
63
|
+
return isEmptySlot(item);
|
|
64
|
+
});
|
|
65
|
+
if (value && value.type === 1) return isEmptySlot(value.children);
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
var renderSlot = function renderSlot(name) {
|
|
69
|
+
return $blocks[name] ? $blocks[name](noop) : undefined;
|
|
70
|
+
};
|
|
71
|
+
var headerSlot = renderSlot('header');
|
|
72
|
+
var footerSlot = renderSlot('footer');
|
|
73
|
+
var beforeInputSlot = renderSlot('beforeInput');
|
|
74
|
+
var configureSlot = renderSlot('configure');
|
|
75
|
+
var attachmentsButtonSlot = renderSlot('attachmentsButton');
|
|
76
|
+
var hasHeaderSlot = !isEmptySlot(headerSlot);
|
|
77
|
+
var hasFooterSlot = !isEmptySlot(footerSlot);
|
|
78
|
+
var hasBeforeInputSlot = !isEmptySlot(beforeInputSlot);
|
|
79
|
+
var hasConfigureSlot = !isEmptySlot(configureSlot);
|
|
80
|
+
var hasAttachmentsButtonSlot = !isEmptySlot(attachmentsButtonSlot);
|
|
81
|
+
var disabled = isDisabled();
|
|
82
|
+
var generating = isGenerating();
|
|
83
|
+
var loading = isLoading();
|
|
84
|
+
var sendDisabled = isSendButtonDisabled();
|
|
85
|
+
var list = attachments || [];
|
|
86
|
+
var hasAttachments = list.length > 0;
|
|
87
|
+
var limit = uploadProps && uploadProps.limit;
|
|
88
|
+
var reachLimit = limit !== undefined && limit !== null && list.length >= Number(limit);
|
|
89
|
+
var isImage = type === 'image';
|
|
90
|
+
var isDirectory = !!(uploadProps && uploadProps.directory);
|
|
91
|
+
|
|
92
|
+
// 文本模式下,所有附件统一按「文件卡」呈现,避免引入额外的文件夹展示语义。
|
|
93
|
+
// 图片模式下把 type 交给 FileCard 自动识别(基于 name/src),避免业务透传 MIME 干扰媒体类型判断。
|
|
94
|
+
var renderItems = isImage ? _mapInstanceProperty(list).call(list, function (it) {
|
|
95
|
+
return _extends({}, it, {
|
|
96
|
+
type: undefined
|
|
97
|
+
});
|
|
98
|
+
}) : _mapInstanceProperty(list).call(list, function (it) {
|
|
99
|
+
return _extends({}, it, {
|
|
100
|
+
type: 'file'
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// 图片模式即便没有附件也要展示 FileCardList,用来承载末尾的虚线 + 框。
|
|
105
|
+
var showAttachmentsArea = isImage || hasAttachments;
|
|
106
|
+
// 图片模式下不展示左下默认附件按钮,由 FileCardList 末尾的 + 框替代;用户自定义 slot 仍可保留。
|
|
107
|
+
var showDefaultAttachBtn = !isImage && !$blocks.attachmentsButton && showAttachmentsButton !== false;
|
|
108
|
+
var showAttachSlot = !isImage && hasAttachmentsButtonSlot;
|
|
109
|
+
var showToolbarLeft = showAttachSlot || showDefaultAttachBtn;
|
|
110
|
+
var onAttachmentClick = function onAttachmentClick(item, e) {
|
|
111
|
+
_this.trigger('attachmentClick', item, e);
|
|
112
|
+
};
|
|
113
|
+
var onAttachmentDelete = function onAttachmentDelete(item, e) {
|
|
114
|
+
_this.trigger('attachmentDelete', item, e);
|
|
115
|
+
removeAttachment(item);
|
|
116
|
+
};
|
|
117
|
+
var classNameObj = (_classNameObj = {}, _classNameObj[k + "-sender"] = true, _classNameObj[k + "-sender-" + type] = true, _classNameObj[k + "-sender-disabled"] = disabled, _classNameObj[className] = className, _classNameObj[makeStyles(k)] = true, _classNameObj);
|
|
118
|
+
|
|
119
|
+
// 整个输入外框 k-sender 的宽度
|
|
120
|
+
if (width != null) {
|
|
121
|
+
style = addStyle(style, {
|
|
122
|
+
width: isNumber(width) ? width + "px" : width
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 整个输入外框 k-sender-shell 的最大高度(与 props maxHeight 一致);未传时走 styles 中默认 300
|
|
127
|
+
var shellStyle = maxHeight != null ? {
|
|
128
|
+
maxHeight: isNumber(maxHeight) ? maxHeight + "px" : maxHeight
|
|
129
|
+
} : undefined;
|
|
130
|
+
var placeholderText = placeholder != null ? placeholder : _$('输入对话内容(Enter发送, Shift + Enter 换行)');
|
|
131
|
+
var defaultSendButton = _$ce(2, 'button', _$ce(2, 'img', null, 1, _$cn(k + "-sender-send-icon"), {
|
|
132
|
+
'src': generating ? senderStopIcon : senderSendIcon,
|
|
133
|
+
'alt': '',
|
|
134
|
+
'draggable': false
|
|
135
|
+
}), 2, _$cn(k + "-sender-send-btn"), {
|
|
136
|
+
'type': 'button',
|
|
137
|
+
'disabled': !generating && sendDisabled,
|
|
138
|
+
'ev-click': handleSendClick,
|
|
139
|
+
'title': generating ? _$('停止生成') : _$('发送'),
|
|
140
|
+
'aria-label': generating ? _$('停止生成') : _$('发送')
|
|
141
|
+
});
|
|
142
|
+
var defaultAttachButton = _$ce(2, 'button', null, 1, _$cn(k + "-sender-attach-btn"), {
|
|
143
|
+
'type': 'button',
|
|
144
|
+
'disabled': disabled,
|
|
145
|
+
'ev-click': pickFiles,
|
|
146
|
+
'title': isDirectory ? _$('上传文件夹') : _$('上传附件'),
|
|
147
|
+
'aria-label': isDirectory ? _$('上传文件夹') : _$('上传附件'),
|
|
148
|
+
'innerHTML': senderAttachSvg
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// type='image' 末尾的虚线 + 框,与 Upload 画廊的 + 卡片视觉等效;点击触发文件选择。
|
|
152
|
+
var imageAddBox = _$ce(2, 'div', _$cc(Icon, {
|
|
153
|
+
'className': _$cn(k + "-icon-add-bold"),
|
|
154
|
+
'size': 'large'
|
|
155
|
+
}), 2, _$cn((_$cn2 = {}, _$cn2[k + "-sender-image-add"] = true, _$cn2[k + "-sender-image-add-disabled"] = disabled, _$cn2)), {
|
|
156
|
+
'ev-click': disabled ? undefined : pickFiles,
|
|
157
|
+
'role': 'button',
|
|
158
|
+
'title': _$('上传图片'),
|
|
159
|
+
'aria-label': _$('上传图片')
|
|
160
|
+
});
|
|
161
|
+
var sendButtonSlotParams = {
|
|
162
|
+
generating: generating,
|
|
163
|
+
disabled: sendDisabled,
|
|
164
|
+
loading: loading,
|
|
165
|
+
send: send,
|
|
166
|
+
stopGenerate: stopGenerate
|
|
167
|
+
};
|
|
168
|
+
return _$cv('div', _extends({
|
|
169
|
+
'className': _$cn(classNameObj)
|
|
170
|
+
}, getRestProps(this), {
|
|
171
|
+
'style': style
|
|
172
|
+
}), [hasHeaderSlot ? _$ce(2, 'div', headerSlot, 0, _$cn(k + "-sender-header")) : undefined, _$ce(2, 'div', [showAttachmentsArea ? _$ce(2, 'div', isImage ? _$cc(FileCardList, {
|
|
173
|
+
'items': renderItems,
|
|
174
|
+
'deleteable': true,
|
|
175
|
+
'overflow': 'scrollY',
|
|
176
|
+
'ev-click': onAttachmentClick,
|
|
177
|
+
'ev-delete': onAttachmentDelete,
|
|
178
|
+
'$blocks': function ($blocks) {
|
|
179
|
+
var _$blocks = {},
|
|
180
|
+
__$blocks = _$ex({}, $blocks);
|
|
181
|
+
return (_$blocks['extension'] = function ($super) {
|
|
182
|
+
return !disabled && !reachLimit ? imageAddBox : undefined;
|
|
183
|
+
}, __$blocks['extension'] = function ($super, data) {
|
|
184
|
+
var block = $blocks['extension'];
|
|
185
|
+
var callBlock = function callBlock() {
|
|
186
|
+
return _$blocks['extension'].call($this, $super, data);
|
|
187
|
+
};
|
|
188
|
+
return block ? block.call($this, callBlock, data) : callBlock();
|
|
189
|
+
}), __$blocks;
|
|
190
|
+
}.call($this, _$em)
|
|
191
|
+
}) : _$cc(FileCardList, {
|
|
192
|
+
'items': renderItems,
|
|
193
|
+
'deleteable': true,
|
|
194
|
+
'overflow': 'scrollY',
|
|
195
|
+
'ev-click': onAttachmentClick,
|
|
196
|
+
'ev-delete': onAttachmentDelete
|
|
197
|
+
}), 2, _$cn((_$cn3 = {}, _$cn3[k + "-sender-attachments"] = true, _$cn3[k + "-sender-attachments-" + type] = true, _$cn3))) : undefined, hasBeforeInputSlot ? _$ce(2, 'div', beforeInputSlot, 0, _$cn(k + "-sender-before-input")) : undefined, _$ce(2, 'div', _$ce(256, 'textarea', null, 1, _$cn(k + "-sender-input"), {
|
|
198
|
+
'rows': 1,
|
|
199
|
+
'value': value,
|
|
200
|
+
'placeholder': placeholderText,
|
|
201
|
+
'disabled': disabled,
|
|
202
|
+
'readOnly': readonly,
|
|
203
|
+
'ev-input': handleInput,
|
|
204
|
+
'ev-keydown': handleKeydown,
|
|
205
|
+
'ev-paste': handlePaste,
|
|
206
|
+
'ev-focus': handleFocus,
|
|
207
|
+
'ev-blur': handleBlur
|
|
208
|
+
}, null, this.textareaRef), 2, _$cn(k + "-sender-input-area")), _$ce(2, 'div', [showToolbarLeft ? _$ce(2, 'div', showAttachSlot ? attachmentsButtonSlot : showDefaultAttachBtn ? defaultAttachButton : undefined, 0, _$cn(k + "-sender-toolbar-left")) : undefined, hasConfigureSlot ? _$ce(2, 'div', configureSlot, 0, _$cn(k + "-sender-toolbar-middle")) : undefined, _$ce(2, 'div', $blocks.sendButton ? (_$blocks['sendButton'] = function ($super) {
|
|
209
|
+
return null;
|
|
210
|
+
}, __$blocks['sendButton'] = function ($super, data) {
|
|
211
|
+
var block = $blocks['sendButton'];
|
|
212
|
+
var callBlock = function callBlock() {
|
|
213
|
+
return _$blocks['sendButton'].call($this, $super, data);
|
|
214
|
+
};
|
|
215
|
+
return block ? block.call($this, callBlock, data) : callBlock();
|
|
216
|
+
}, __$blocks['sendButton'](_$no, sendButtonSlotParams)) : defaultSendButton, 0, _$cn(k + "-sender-toolbar-right"))], 0, _$cn(k + "-sender-toolbar")), _$ccv(' 放末尾,避免挡住 attachments + input-area 等相邻选择器,且 absolute 不影响布局 '), _$ce(64, 'input', null, 1, _$cn(k + "-sender-file-input"), {
|
|
217
|
+
'type': 'file',
|
|
218
|
+
'accept': getAcceptAttr(),
|
|
219
|
+
'multiple': isMultiple(),
|
|
220
|
+
'directory': isDirectory ? '' : undefined,
|
|
221
|
+
'webkitdirectory': isDirectory ? '' : undefined,
|
|
222
|
+
'ev-change': onInputChange
|
|
223
|
+
}, null, this.fileInputRef)], 0, _$cn((_$cn4 = {}, _$cn4[k + "-sender-shell"] = true, _$cn4[k + "-sender-active"] = isFocus.value && !disabled, _$cn4)), {
|
|
224
|
+
'style': shellStyle
|
|
225
|
+
}), hasFooterSlot ? _$ce(2, 'div', footerSlot, 0, _$cn(k + "-sender-footer")) : undefined, enableDragFile && dragController.dragOver.value ? _$ce(2, 'div', _$ce(2, 'div', [_$cc(Icon, {
|
|
226
|
+
'className': _$cn(k + "-icon-upload"),
|
|
227
|
+
'size': 'large'
|
|
228
|
+
}), _$ce(2, 'div', _$('文件拖动到此处即可上传'), 0, _$cn(k + "-sender-drag-text"))], 4, _$cn(k + "-sender-drag-card")), 2, _$cn(k + "-sender-drag-mask"), _$tmp0) : undefined]);
|
|
229
|
+
}
|
|
230
|
+
;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { theme, setDefault } from '../../styles/theme';
|
|
3
|
+
import { deepDefaults } from '../../styles/utils';
|
|
4
|
+
import '../../styles/global';
|
|
5
|
+
import { cache } from '../utils';
|
|
6
|
+
// 用于复用的渐变色:默认态半透明,hover/active 实色,与设计稿一致。
|
|
7
|
+
var SENDER_GRADIENT_DEFAULT = 'linear-gradient(101.07deg, rgba(0, 221, 221, 0.5) -7.07%, rgba(83, 112, 255, 0.5) 48.92%, rgba(113, 47, 255, 0.5) 104.92%)';
|
|
8
|
+
var SENDER_GRADIENT_ACTIVE = 'linear-gradient(101.07deg, #00DDDD -7.07%, #5370FF 48.92%, #712FFF 104.92%)';
|
|
9
|
+
var defaults = {
|
|
10
|
+
radius: '12px',
|
|
11
|
+
// 输入框外框(k-sender-shell)统一 12,区块间距在下方用 margin 控制
|
|
12
|
+
padding: '12px',
|
|
13
|
+
// 与 useAutoResize 中 SHELL_MAX_FALLBACK 一致
|
|
14
|
+
shellMaxH: '300px',
|
|
15
|
+
gapHeaderToShell: '4px',
|
|
16
|
+
gapShellToFooter: '4px',
|
|
17
|
+
// 区块间距:附件↔上插槽 8;附件/上插槽↔文字区 16;文字区↔工具条 8
|
|
18
|
+
gapAttachToTop: '8px',
|
|
19
|
+
gapTopToInput: '16px',
|
|
20
|
+
gapInputToToolbar: '8px',
|
|
21
|
+
bg: '#FFFFFF',
|
|
22
|
+
color: theme.color.text,
|
|
23
|
+
placeholderColor: theme.color.placeholder,
|
|
24
|
+
disabledBg: theme.color.disabledBg,
|
|
25
|
+
disabledColor: theme.color.disabled,
|
|
26
|
+
fontSize: theme.fontSize,
|
|
27
|
+
lineHeight: 1.5,
|
|
28
|
+
gradientDefault: SENDER_GRADIENT_DEFAULT,
|
|
29
|
+
gradientActive: SENDER_GRADIENT_ACTIVE,
|
|
30
|
+
sendButtonSize: '32px',
|
|
31
|
+
attachButtonSize: '16px',
|
|
32
|
+
attachIconColor: '#868A9C',
|
|
33
|
+
attachIconHoverColor: theme.color.primary,
|
|
34
|
+
// type='image' 末尾的 + 框,尺寸和 FileCard image default 对齐
|
|
35
|
+
imageAddSize: '64px',
|
|
36
|
+
imageAddRadius: '4px',
|
|
37
|
+
imageAddBg: '#FFFFFF',
|
|
38
|
+
imageAddBorder: '1px dashed #D0D5E0',
|
|
39
|
+
imageAddColor: '#868A9C',
|
|
40
|
+
dragMaskBg: 'rgba(255, 255, 255, 0.72)',
|
|
41
|
+
dragCardColor: '#5370FF',
|
|
42
|
+
dragCardTextColor: theme.color.text,
|
|
43
|
+
// 与 FileCardList 一致的滚动条样式
|
|
44
|
+
scrollbarThumb: 'rgba(63, 68, 81, 0.26)',
|
|
45
|
+
scrollbarThumbHover: 'rgba(63, 68, 81, 0.42)'
|
|
46
|
+
};
|
|
47
|
+
var sender;
|
|
48
|
+
setDefault(function () {
|
|
49
|
+
sender = deepDefaults(theme, {
|
|
50
|
+
sender: defaults
|
|
51
|
+
}).sender;
|
|
52
|
+
makeStyles == null || makeStyles.clearCache();
|
|
53
|
+
});
|
|
54
|
+
export var makeStyles = cache(function makeStyles(k) {
|
|
55
|
+
return /*#__PURE__*/css("position:relative;display:flex;flex-direction:column;box-sizing:border-box;.", k, "-sender-header,.", k, "-sender-footer{box-sizing:border-box;flex:0 0 auto;}.", k, "-sender-header{margin-bottom:", sender.gapHeaderToShell, ";}.", k, "-sender-footer{margin-top:", sender.gapShellToFooter, ";}.", k, "-sender-shell{position:relative;display:flex;flex-direction:column;box-sizing:border-box;max-height:", sender.shellMaxH, ";padding:", sender.padding, ";background:", sender.bg, ";border-radius:", sender.radius, ";transition:background ", theme.transition.middle, ";min-width:0;overflow:hidden;}.", k, "-sender-shell::before{content:'';position:absolute;inset:0;padding:1px;border-radius:inherit;background:", sender.gradientDefault, ";-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);mask-composite:exclude;pointer-events:none;transition:background ", theme.transition.middle, ",opacity ", theme.transition.middle, ";}.", k, "-sender-shell:hover::before,.", k, "-sender-shell.", k, "-sender-active::before{background:", sender.gradientActive, ";}&.", k, "-sender-disabled .", k, "-sender-shell::before{opacity:0.5;}&.", k, "-sender-disabled .", k, "-sender-shell{background:", sender.disabledBg, ";}.", k, "-sender-attachments{padding:0;box-sizing:border-box;min-width:0;flex:0 0 auto;}.", k, "-sender-attachments-image .", k, "-file-card-list{min-width:0;}.", k, "-sender-before-input{margin-bottom:", sender.gapTopToInput, ";padding:0;box-sizing:border-box;flex:0 0 auto;}.", k, "-sender-attachments+.", k, "-sender-before-input{margin-top:", sender.gapAttachToTop, ";}.", k, "-sender-attachments+.", k, "-sender-input-area{margin-top:", sender.gapTopToInput, ";}.", k, "-sender-input-area{position:relative;display:flex;flex:0 0 auto;min-height:0;margin-bottom:", sender.gapInputToToolbar, ";padding:0;box-sizing:border-box;}.", k, "-sender-input{flex:1 1 auto;width:100%;min-width:0;min-height:0;border:none;outline:none;resize:none;background:transparent;color:", sender.color, ";font-family:inherit;font-size:", sender.fontSize, ";line-height:", sender.lineHeight, ";padding:0;scrollbar-width:thin;scrollbar-color:transparent transparent;}.", k, "-sender-input::-webkit-scrollbar{width:8px;}.", k, "-sender-input::-webkit-scrollbar-track{background:transparent;}.", k, "-sender-input::-webkit-scrollbar-thumb{border-radius:999px;border:2px solid transparent;background:transparent;background-clip:content-box;}.", k, "-sender-input:hover{scrollbar-color:", sender.scrollbarThumb, " transparent;}.", k, "-sender-input:hover::-webkit-scrollbar-thumb{background:", sender.scrollbarThumb, ";background-clip:content-box;}.", k, "-sender-input:hover::-webkit-scrollbar-thumb:hover{background:", sender.scrollbarThumbHover, ";background-clip:content-box;}.", k, "-sender-input::placeholder{color:", sender.placeholderColor, ";}&.", k, "-sender-disabled .", k, "-sender-input{color:", sender.disabledColor, ";cursor:not-allowed;}.", k, "-sender-toolbar{display:flex;gap:8px;padding:0;box-sizing:border-box;flex:0 0 auto;}.", k, "-sender-toolbar-left{display:flex;align-items:center;gap:8px;margin-top:8px;flex:0 0 auto;}.", k, "-sender-toolbar-right{display:flex;align-items:center;gap:8px;flex:0 0 auto;margin-left:auto;}.", k, "-sender-toolbar-middle{flex:1 1 auto;min-width:0;display:flex;align-items:flex-end;gap:8px;}.", k, "-sender-attach-btn{display:inline-flex;align-items:center;justify-content:center;width:", sender.attachButtonSize, ";height:", sender.attachButtonSize, ";border-radius:50%;background:transparent;border:none;padding:0;cursor:pointer;color:", sender.attachIconColor, ";transition:color ", theme.transition.small, ",background ", theme.transition.small, ";}.", k, "-sender-attach-btn:hover{color:", sender.attachIconHoverColor, ";}.", k, "-sender-attach-btn:disabled,&.", k, "-sender-disabled .", k, "-sender-attach-btn{color:", theme.color.disabled, ";cursor:not-allowed;background:transparent;}.", k, "-sender-attach-btn svg{display:block;}.", k, "-sender-send-btn{display:inline-flex;align-items:center;justify-content:center;width:", sender.sendButtonSize, ";height:", sender.sendButtonSize, ";background:transparent;border:none;padding:0;cursor:pointer;transition:filter ", theme.transition.small, ";}.", k, "-sender-send-btn:disabled{cursor:not-allowed;filter:opacity(0.5);}.", k, "-sender-send-btn:not(:disabled):hover{filter:opacity(0.85);}.", k, "-sender-send-icon{display:block;width:32px;height:32px;pointer-events:none;filter:drop-shadow(0 4px 8px rgba(83, 112, 255, 0.32));}.", k, "-sender-image-add{display:inline-flex;align-items:center;justify-content:center;width:", sender.imageAddSize, ";height:", sender.imageAddSize, ";box-sizing:border-box;flex:0 0 auto;border-radius:", sender.imageAddRadius, ";border:", sender.imageAddBorder, ";background:", sender.imageAddBg, ";color:", sender.imageAddColor, ";cursor:pointer;transition:border-color ", theme.transition.small, ",color ", theme.transition.small, ";}.", k, "-sender-image-add:hover{border-color:", theme.color.primary, ";color:", theme.color.primary, ";}.", k, "-sender-image-add-disabled,.", k, "-sender-image-add-disabled:hover{cursor:not-allowed;border-color:", theme.color.border, ";color:", theme.color.disabled, ";}.", k, "-sender-file-input{position:absolute;width:1px;height:1px;opacity:0;pointer-events:none;top:-9999px;left:-9999px;}.", k, "-sender-drag-mask{position:fixed;inset:0;z-index:1000;display:flex;align-items:center;justify-content:center;padding:24px;box-sizing:border-box;background:", sender.dragMaskBg, ";backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);}.", k, "-sender-drag-card{display:inline-flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;color:", sender.dragCardColor, ";}.", k, "-sender-drag-card .", k, "-icon{color:", sender.dragCardColor, ";font-size:32px;line-height:1;}.", k, "-sender-drag-text{color:", sender.dragCardTextColor, ";font-size:14px;font-weight:500;line-height:20px;}");
|
|
56
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import _Number$isFinite from "@babel/runtime-corejs3/core-js/number/is-finite";
|
|
2
|
+
import { useInstance, onMounted, onUpdated, nextTick } from 'intact-vue-next';
|
|
3
|
+
import { useConfigContext } from '../config';
|
|
4
|
+
// textarea 高度自适应:textarea 默认高 text=64、image=32;maxHeight 约束整个输入外框而非 textarea 本身。
|
|
5
|
+
var SHELL_MAX_FALLBACK = 300;
|
|
6
|
+
var TEXTAREA_MIN_TEXT = 64;
|
|
7
|
+
var TEXTAREA_MIN_IMAGE = 20;
|
|
8
|
+
export function useAutoResize(textareaRef) {
|
|
9
|
+
var instance = useInstance();
|
|
10
|
+
var _useConfigContext = useConfigContext(),
|
|
11
|
+
k = _useConfigContext.k;
|
|
12
|
+
var shell = null;
|
|
13
|
+
var scheduled = false;
|
|
14
|
+
function getShell(el) {
|
|
15
|
+
if (shell && shell.contains(el)) return shell;
|
|
16
|
+
shell = el.closest("." + k + "-sender-shell");
|
|
17
|
+
return shell;
|
|
18
|
+
}
|
|
19
|
+
function getShellMaxHeight(shell) {
|
|
20
|
+
var parsed = parseFloat(getComputedStyle(shell).maxHeight);
|
|
21
|
+
return _Number$isFinite(parsed) ? parsed : SHELL_MAX_FALLBACK;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* textarea 高暂置 0 时,外框中除可拉伸输入行以外的纵向占位(px)。
|
|
25
|
+
* maxHeight 是整框高度,需要减去这部分,才能得到 textarea 的可滚动上限。
|
|
26
|
+
*/
|
|
27
|
+
function measureNonInputBlockHeight(el, shell) {
|
|
28
|
+
var h0 = el.style.height;
|
|
29
|
+
var min0 = el.style.minHeight;
|
|
30
|
+
var max0 = el.style.maxHeight;
|
|
31
|
+
var ov0 = el.style.overflow;
|
|
32
|
+
el.style.height = '0px';
|
|
33
|
+
el.style.minHeight = '0px';
|
|
34
|
+
el.style.maxHeight = 'none';
|
|
35
|
+
el.style.overflow = 'hidden';
|
|
36
|
+
var h = shell.offsetHeight;
|
|
37
|
+
el.style.height = h0;
|
|
38
|
+
el.style.minHeight = min0;
|
|
39
|
+
el.style.maxHeight = max0;
|
|
40
|
+
el.style.overflow = ov0;
|
|
41
|
+
return h;
|
|
42
|
+
}
|
|
43
|
+
function adjust() {
|
|
44
|
+
var el = textareaRef.value;
|
|
45
|
+
if (!el) return;
|
|
46
|
+
var shell = getShell(el);
|
|
47
|
+
if (!shell) return;
|
|
48
|
+
var isImage = instance.get('type') === 'image';
|
|
49
|
+
var min = isImage ? TEXTAREA_MIN_IMAGE : TEXTAREA_MIN_TEXT;
|
|
50
|
+
/** 整框最大高度(props 或默认 300),从实际 CSS 读取,支持 50vh 等合法 CSS 值 */
|
|
51
|
+
var shellMax = getShellMaxHeight(shell);
|
|
52
|
+
var nonInputH = measureNonInputBlockHeight(el, shell);
|
|
53
|
+
var max = Math.max(8, shellMax - nonInputH);
|
|
54
|
+
el.style.height = 'auto';
|
|
55
|
+
var scroll = el.scrollHeight;
|
|
56
|
+
var next = Math.min(Math.max(min, scroll), max);
|
|
57
|
+
var nextHeight = next + "px";
|
|
58
|
+
var nextOverflowY = scroll > max ? 'auto' : 'hidden';
|
|
59
|
+
if (el.style.height !== nextHeight) {
|
|
60
|
+
el.style.height = nextHeight;
|
|
61
|
+
}
|
|
62
|
+
if (el.style.overflowY !== nextOverflowY) {
|
|
63
|
+
el.style.overflowY = nextOverflowY;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function scheduleAdjust() {
|
|
67
|
+
if (scheduled) return;
|
|
68
|
+
scheduled = true;
|
|
69
|
+
nextTick(function () {
|
|
70
|
+
scheduled = false;
|
|
71
|
+
adjust();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
onMounted(function () {
|
|
75
|
+
scheduleAdjust();
|
|
76
|
+
});
|
|
77
|
+
onUpdated(function () {
|
|
78
|
+
scheduleAdjust();
|
|
79
|
+
});
|
|
80
|
+
instance.watch('value', scheduleAdjust, {
|
|
81
|
+
inited: true,
|
|
82
|
+
presented: true
|
|
83
|
+
});
|
|
84
|
+
instance.watch('maxHeight', scheduleAdjust, {
|
|
85
|
+
inited: true,
|
|
86
|
+
presented: true
|
|
87
|
+
});
|
|
88
|
+
instance.watch('type', scheduleAdjust, {
|
|
89
|
+
inited: true,
|
|
90
|
+
presented: true
|
|
91
|
+
});
|
|
92
|
+
instance.watch('attachments', scheduleAdjust, {
|
|
93
|
+
inited: true,
|
|
94
|
+
presented: true
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
adjust: adjust
|
|
98
|
+
};
|
|
99
|
+
}
|