@douyinfe/semi-foundation 2.88.0-alpha.7 → 2.88.0-beta.1
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/aiChatInput/foundation.ts +7 -33
- package/aiChatInput/interface.ts +4 -4
- package/aiChatInput/utils.ts +7 -35
- package/lib/cjs/aiChatInput/foundation.d.ts +0 -1
- package/lib/cjs/aiChatInput/foundation.js +6 -36
- package/lib/cjs/aiChatInput/interface.d.ts +4 -4
- package/lib/cjs/aiChatInput/utils.d.ts +3 -12
- package/lib/cjs/aiChatInput/utils.js +8 -38
- package/lib/es/aiChatInput/foundation.d.ts +0 -1
- package/lib/es/aiChatInput/foundation.js +7 -37
- package/lib/es/aiChatInput/interface.d.ts +4 -4
- package/lib/es/aiChatInput/utils.d.ts +3 -12
- package/lib/es/aiChatInput/utils.js +8 -37
- package/package.json +4 -4
|
@@ -2,7 +2,7 @@ import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
|
2
2
|
import { Attachment, BaseSkill, Suggestion, Reference, Content, LeftMenuChangeProps, MessageContent } from './interface';
|
|
3
3
|
import { isNumber, isString } from 'lodash';
|
|
4
4
|
import { cssClasses } from './constants';
|
|
5
|
-
import {
|
|
5
|
+
import { transformJSONResult } from './utils';
|
|
6
6
|
|
|
7
7
|
export interface AIChatInputAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
|
|
8
8
|
reposPopover: () => void;
|
|
@@ -16,7 +16,6 @@ export interface AIChatInputAdapter<P = Record<string, any>, S = Record<string,
|
|
|
16
16
|
manualUpload: (files: File[]) => void;
|
|
17
17
|
notifyMessageSend: (props: MessageContent) => void;
|
|
18
18
|
notifyStopGenerate: () => void;
|
|
19
|
-
notifySkillChange: (skill: BaseSkill) => void;
|
|
20
19
|
clearContent: () => void;
|
|
21
20
|
clearAttachments: () => void;
|
|
22
21
|
getRichTextDiv: () => HTMLDivElement | null;
|
|
@@ -52,7 +51,6 @@ export default class AIChatInputFoundation extends BaseFoundation<AIChatInputAda
|
|
|
52
51
|
skill: skill,
|
|
53
52
|
skillVisible: false
|
|
54
53
|
});
|
|
55
|
-
this._adapter.notifySkillChange(skill);
|
|
56
54
|
this._adapter.setContent(`<skill-slot data-value="${skill.label}"></skill-slot>`);
|
|
57
55
|
this._adapter.focusEditor();
|
|
58
56
|
}
|
|
@@ -199,27 +197,18 @@ export default class AIChatInputFoundation extends BaseFoundation<AIChatInputAda
|
|
|
199
197
|
|
|
200
198
|
handleContentChange = (content: string) => {
|
|
201
199
|
const { transformer } = this.getProps();
|
|
202
|
-
const { skill
|
|
200
|
+
const { skill } = this.getStates();
|
|
203
201
|
const editor = this._adapter.getEditor();
|
|
202
|
+
const jsonResult = editor.getJSON();
|
|
203
|
+
const finalResult = transformJSONResult(jsonResult, transformer);
|
|
204
|
+
this._adapter.notifyContentChange(finalResult);
|
|
204
205
|
const html = editor.getHTML();
|
|
205
|
-
if (Object.keys(skill).length && !html.includes('</skill-slot>')) {
|
|
206
|
+
if (content === '' && Object.keys(skill).length && !html.includes('</skill-slot>')) {
|
|
206
207
|
this.setState({
|
|
207
|
-
skill:
|
|
208
|
+
skill: {} as BaseSkill,
|
|
208
209
|
templateVisible: false
|
|
209
210
|
});
|
|
210
|
-
this._adapter.notifySkillChange(undefined);
|
|
211
|
-
this._adapter.notifyContentChange([]);
|
|
212
|
-
return;
|
|
213
|
-
} else if ((Object.keys(skill).length === 0) && html.includes('</skill-slot>')) {
|
|
214
|
-
const newSkill = findSkillSlotInString(html);
|
|
215
|
-
if (newSkill?.value !== skill?.value) {
|
|
216
|
-
this.setState({ skill: newSkill });
|
|
217
|
-
this._adapter.notifySkillChange(newSkill);
|
|
218
|
-
}
|
|
219
211
|
}
|
|
220
|
-
const jsonResult = editor.getJSON();
|
|
221
|
-
const finalResult = transformJSONResult(jsonResult, transformer);
|
|
222
|
-
this._adapter.notifyContentChange(finalResult);
|
|
223
212
|
this.setState({
|
|
224
213
|
content: jsonResult,
|
|
225
214
|
});
|
|
@@ -349,21 +338,6 @@ export default class AIChatInputFoundation extends BaseFoundation<AIChatInputAda
|
|
|
349
338
|
this.handleSend();
|
|
350
339
|
return true;
|
|
351
340
|
}
|
|
352
|
-
if (event.key === 'Enter' && event.shiftKey) {
|
|
353
|
-
/**
|
|
354
|
-
* Tiptap 默认情况下 Enter + Shift 时候是使用 <br /> 实现换行,需要通过新建 p 标签的方式换行保证
|
|
355
|
-
* 自定义的一些逻辑生效(比如零宽字符的插入),因此拦截默认操作,使用新建 p 标签方式
|
|
356
|
-
*/
|
|
357
|
-
event.preventDefault();
|
|
358
|
-
const editor = this._adapter.getEditor();
|
|
359
|
-
if (editor && editor.chain && editor.chain().splitBlock) {
|
|
360
|
-
editor.chain().focus().splitBlock().run();
|
|
361
|
-
} else if (editor && editor.view) {
|
|
362
|
-
const { state, view } = editor;
|
|
363
|
-
view.dispatch(state.tr.split(state.selection.from));
|
|
364
|
-
}
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
341
|
if (event.key !== 'Backspace') return false;
|
|
368
342
|
return false;
|
|
369
343
|
}
|
package/aiChatInput/interface.ts
CHANGED
package/aiChatInput/utils.ts
CHANGED
|
@@ -53,10 +53,11 @@ export function transformSelectSlot(obj: any) {
|
|
|
53
53
|
|
|
54
54
|
export function transformSkillSlot(obj: any) {
|
|
55
55
|
const { type, attrs } = obj;
|
|
56
|
-
const { value } = attrs;
|
|
56
|
+
const { value, info } = attrs;
|
|
57
57
|
return {
|
|
58
58
|
type,
|
|
59
|
-
value
|
|
59
|
+
value,
|
|
60
|
+
...(JSON.parse(info) ?? {}),
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -70,18 +71,14 @@ export function transformInputSlot(obj: any) {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export function transformText(obj: any) {
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
type: 'text',
|
|
76
|
-
text: text !== strings.ZERO_WIDTH_CHAR ? text : ''
|
|
77
|
-
};
|
|
74
|
+
return { ...obj };
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
export const transformMap = new Map
|
|
77
|
+
export const transformMap = new Map([
|
|
81
78
|
['text', transformText],
|
|
82
79
|
['selectSlot', transformSelectSlot],
|
|
83
80
|
['inputSlot', transformInputSlot],
|
|
84
|
-
['
|
|
81
|
+
['toolSlot', transformSkillSlot],
|
|
85
82
|
]);
|
|
86
83
|
|
|
87
84
|
export function transformJSONResult(input: any, customTransformObj: Map<string, (obj: any) => any> = new Map()) {
|
|
@@ -119,7 +116,7 @@ export function transformJSONResult(input: any, customTransformObj: Map<string,
|
|
|
119
116
|
const lastItem = output[output.length - 1];
|
|
120
117
|
if (lastItem && lastItem.type === 'text') {
|
|
121
118
|
lastItem.text += result.text;
|
|
122
|
-
} else
|
|
119
|
+
} else {
|
|
123
120
|
output.push(result);
|
|
124
121
|
}
|
|
125
122
|
} else {
|
|
@@ -140,29 +137,4 @@ export function getCustomSlotAttribute() {
|
|
|
140
137
|
'data-custom-slot': attributes.isCustomSlot ? 'true' : undefined,
|
|
141
138
|
}),
|
|
142
139
|
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function findSkillSlotInString(content: string) {
|
|
146
|
-
const reg = /<skill-slot\s+([^>]*)><\/skill-slot>/i;
|
|
147
|
-
const attrReg = /([\w-]+)=["']?([^"'\s>]+)["']?/g;
|
|
148
|
-
const match = reg.exec(content);
|
|
149
|
-
if (match) {
|
|
150
|
-
const attrsStr = match[1];
|
|
151
|
-
let attrMatch;
|
|
152
|
-
let attrs = {};
|
|
153
|
-
while ((attrMatch = attrReg.exec(attrsStr)) !== null) {
|
|
154
|
-
attrs[attrMatch[1]] = attrMatch[2];
|
|
155
|
-
}
|
|
156
|
-
if (attrs['data-value']) {
|
|
157
|
-
const obj = {
|
|
158
|
-
label: attrs['data-label'],
|
|
159
|
-
value: attrs['data-value'],
|
|
160
|
-
hasTemplate: attrs['data-template'] ? attrs['data-template'] === 'true' : undefined
|
|
161
|
-
};
|
|
162
|
-
return Object.fromEntries(
|
|
163
|
-
Object.entries(obj).filter(([key, value]) => value !== undefined)
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return undefined;
|
|
168
140
|
}
|
|
@@ -12,7 +12,6 @@ export interface AIChatInputAdapter<P = Record<string, any>, S = Record<string,
|
|
|
12
12
|
manualUpload: (files: File[]) => void;
|
|
13
13
|
notifyMessageSend: (props: MessageContent) => void;
|
|
14
14
|
notifyStopGenerate: () => void;
|
|
15
|
-
notifySkillChange: (skill: BaseSkill) => void;
|
|
16
15
|
clearContent: () => void;
|
|
17
16
|
clearAttachments: () => void;
|
|
18
17
|
getRichTextDiv: () => HTMLDivElement | null;
|
|
@@ -24,7 +24,6 @@ class AIChatInputFoundation extends _foundation.default {
|
|
|
24
24
|
skill: skill,
|
|
25
25
|
skillVisible: false
|
|
26
26
|
});
|
|
27
|
-
this._adapter.notifySkillChange(skill);
|
|
28
27
|
this._adapter.setContent(`<skill-slot data-value="${skill.label}"></skill-slot>`);
|
|
29
28
|
this._adapter.focusEditor();
|
|
30
29
|
};
|
|
@@ -168,30 +167,19 @@ class AIChatInputFoundation extends _foundation.default {
|
|
|
168
167
|
transformer
|
|
169
168
|
} = this.getProps();
|
|
170
169
|
const {
|
|
171
|
-
skill
|
|
170
|
+
skill
|
|
172
171
|
} = this.getStates();
|
|
173
172
|
const editor = this._adapter.getEditor();
|
|
173
|
+
const jsonResult = editor.getJSON();
|
|
174
|
+
const finalResult = (0, _utils.transformJSONResult)(jsonResult, transformer);
|
|
175
|
+
this._adapter.notifyContentChange(finalResult);
|
|
174
176
|
const html = editor.getHTML();
|
|
175
|
-
if (Object.keys(skill).length && !html.includes('</skill-slot>')) {
|
|
177
|
+
if (content === '' && Object.keys(skill).length && !html.includes('</skill-slot>')) {
|
|
176
178
|
this.setState({
|
|
177
|
-
skill:
|
|
179
|
+
skill: {},
|
|
178
180
|
templateVisible: false
|
|
179
181
|
});
|
|
180
|
-
this._adapter.notifySkillChange(undefined);
|
|
181
|
-
this._adapter.notifyContentChange([]);
|
|
182
|
-
return;
|
|
183
|
-
} else if (Object.keys(skill).length === 0 && html.includes('</skill-slot>')) {
|
|
184
|
-
const newSkill = (0, _utils.findSkillSlotInString)(html);
|
|
185
|
-
if ((newSkill === null || newSkill === void 0 ? void 0 : newSkill.value) !== (skill === null || skill === void 0 ? void 0 : skill.value)) {
|
|
186
|
-
this.setState({
|
|
187
|
-
skill: newSkill
|
|
188
|
-
});
|
|
189
|
-
this._adapter.notifySkillChange(newSkill);
|
|
190
|
-
}
|
|
191
182
|
}
|
|
192
|
-
const jsonResult = editor.getJSON();
|
|
193
|
-
const finalResult = (0, _utils.transformJSONResult)(jsonResult, transformer);
|
|
194
|
-
this._adapter.notifyContentChange(finalResult);
|
|
195
183
|
this.setState({
|
|
196
184
|
content: jsonResult
|
|
197
185
|
});
|
|
@@ -335,24 +323,6 @@ class AIChatInputFoundation extends _foundation.default {
|
|
|
335
323
|
this.handleSend();
|
|
336
324
|
return true;
|
|
337
325
|
}
|
|
338
|
-
if (event.key === 'Enter' && event.shiftKey) {
|
|
339
|
-
/**
|
|
340
|
-
* Tiptap 默认情况下 Enter + Shift 时候是使用 <br /> 实现换行,需要通过新建 p 标签的方式换行保证
|
|
341
|
-
* 自定义的一些逻辑生效(比如零宽字符的插入),因此拦截默认操作,使用新建 p 标签方式
|
|
342
|
-
*/
|
|
343
|
-
event.preventDefault();
|
|
344
|
-
const editor = this._adapter.getEditor();
|
|
345
|
-
if (editor && editor.chain && editor.chain().splitBlock) {
|
|
346
|
-
editor.chain().focus().splitBlock().run();
|
|
347
|
-
} else if (editor && editor.view) {
|
|
348
|
-
const {
|
|
349
|
-
state,
|
|
350
|
-
view
|
|
351
|
-
} = editor;
|
|
352
|
-
view.dispatch(state.tr.split(state.selection.from));
|
|
353
|
-
}
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
326
|
if (event.key !== 'Backspace') return false;
|
|
357
327
|
return false;
|
|
358
328
|
};
|
|
@@ -4,10 +4,10 @@ export interface RichTextJSON {
|
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
6
|
export interface BaseSkill {
|
|
7
|
-
icon
|
|
8
|
-
value
|
|
9
|
-
label
|
|
10
|
-
hasTemplate
|
|
7
|
+
icon: any;
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
hasTemplate: boolean;
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
}
|
|
13
13
|
export type Suggestion = string[] | {
|
|
@@ -6,19 +6,13 @@ export declare function transformSelectSlot(obj: any): {
|
|
|
6
6
|
type: string;
|
|
7
7
|
text: any;
|
|
8
8
|
};
|
|
9
|
-
export declare function transformSkillSlot(obj: any):
|
|
10
|
-
type: any;
|
|
11
|
-
value: any;
|
|
12
|
-
};
|
|
9
|
+
export declare function transformSkillSlot(obj: any): any;
|
|
13
10
|
export declare function transformInputSlot(obj: any): {
|
|
14
11
|
type: string;
|
|
15
12
|
text: any;
|
|
16
13
|
};
|
|
17
|
-
export declare function transformText(obj: any):
|
|
18
|
-
|
|
19
|
-
text: any;
|
|
20
|
-
};
|
|
21
|
-
export declare const transformMap: Map<string, any>;
|
|
14
|
+
export declare function transformText(obj: any): any;
|
|
15
|
+
export declare const transformMap: Map<string, typeof transformText>;
|
|
22
16
|
export declare function transformJSONResult(input: any, customTransformObj?: Map<string, (obj: any) => any>): any[];
|
|
23
17
|
export declare function getCustomSlotAttribute(): {
|
|
24
18
|
default: boolean;
|
|
@@ -27,6 +21,3 @@ export declare function getCustomSlotAttribute(): {
|
|
|
27
21
|
'data-custom-slot': string;
|
|
28
22
|
};
|
|
29
23
|
};
|
|
30
|
-
export declare function findSkillSlotInString(content: string): {
|
|
31
|
-
[k: string]: any;
|
|
32
|
-
};
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.findSkillSlotInString = findSkillSlotInString;
|
|
7
6
|
exports.getAttachmentType = getAttachmentType;
|
|
8
7
|
exports.getContentType = getContentType;
|
|
9
8
|
exports.getCustomSlotAttribute = getCustomSlotAttribute;
|
|
@@ -70,17 +69,19 @@ function transformSelectSlot(obj) {
|
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
function transformSkillSlot(obj) {
|
|
72
|
+
var _a;
|
|
73
73
|
const {
|
|
74
74
|
type,
|
|
75
75
|
attrs
|
|
76
76
|
} = obj;
|
|
77
77
|
const {
|
|
78
|
-
value
|
|
78
|
+
value,
|
|
79
|
+
info
|
|
79
80
|
} = attrs;
|
|
80
|
-
return {
|
|
81
|
+
return Object.assign({
|
|
81
82
|
type,
|
|
82
83
|
value
|
|
83
|
-
};
|
|
84
|
+
}, (_a = JSON.parse(info)) !== null && _a !== void 0 ? _a : {});
|
|
84
85
|
}
|
|
85
86
|
function transformInputSlot(obj) {
|
|
86
87
|
var _a, _b;
|
|
@@ -95,15 +96,9 @@ function transformInputSlot(obj) {
|
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
function transformText(obj) {
|
|
98
|
-
|
|
99
|
-
text
|
|
100
|
-
} = obj;
|
|
101
|
-
return {
|
|
102
|
-
type: 'text',
|
|
103
|
-
text: text !== _constants.strings.ZERO_WIDTH_CHAR ? text : ''
|
|
104
|
-
};
|
|
99
|
+
return Object.assign({}, obj);
|
|
105
100
|
}
|
|
106
|
-
const transformMap = exports.transformMap = new Map([['text', transformText], ['selectSlot', transformSelectSlot], ['inputSlot', transformInputSlot], ['
|
|
101
|
+
const transformMap = exports.transformMap = new Map([['text', transformText], ['selectSlot', transformSelectSlot], ['inputSlot', transformInputSlot], ['toolSlot', transformSkillSlot]]);
|
|
107
102
|
function transformJSONResult(input) {
|
|
108
103
|
let customTransformObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Map();
|
|
109
104
|
const output = [];
|
|
@@ -146,7 +141,7 @@ function transformJSONResult(input) {
|
|
|
146
141
|
const lastItem = output[output.length - 1];
|
|
147
142
|
if (lastItem && lastItem.type === 'text') {
|
|
148
143
|
lastItem.text += result.text;
|
|
149
|
-
} else
|
|
144
|
+
} else {
|
|
150
145
|
output.push(result);
|
|
151
146
|
}
|
|
152
147
|
} else {
|
|
@@ -165,29 +160,4 @@ function getCustomSlotAttribute() {
|
|
|
165
160
|
'data-custom-slot': attributes.isCustomSlot ? 'true' : undefined
|
|
166
161
|
})
|
|
167
162
|
};
|
|
168
|
-
}
|
|
169
|
-
function findSkillSlotInString(content) {
|
|
170
|
-
const reg = /<skill-slot\s+([^>]*)><\/skill-slot>/i;
|
|
171
|
-
const attrReg = /([\w-]+)=["']?([^"'\s>]+)["']?/g;
|
|
172
|
-
const match = reg.exec(content);
|
|
173
|
-
if (match) {
|
|
174
|
-
const attrsStr = match[1];
|
|
175
|
-
let attrMatch;
|
|
176
|
-
let attrs = {};
|
|
177
|
-
while ((attrMatch = attrReg.exec(attrsStr)) !== null) {
|
|
178
|
-
attrs[attrMatch[1]] = attrMatch[2];
|
|
179
|
-
}
|
|
180
|
-
if (attrs['data-value']) {
|
|
181
|
-
const obj = {
|
|
182
|
-
label: attrs['data-label'],
|
|
183
|
-
value: attrs['data-value'],
|
|
184
|
-
hasTemplate: attrs['data-template'] ? attrs['data-template'] === 'true' : undefined
|
|
185
|
-
};
|
|
186
|
-
return Object.fromEntries(Object.entries(obj).filter(_ref => {
|
|
187
|
-
let [key, value] = _ref;
|
|
188
|
-
return value !== undefined;
|
|
189
|
-
}));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return undefined;
|
|
193
163
|
}
|
|
@@ -12,7 +12,6 @@ export interface AIChatInputAdapter<P = Record<string, any>, S = Record<string,
|
|
|
12
12
|
manualUpload: (files: File[]) => void;
|
|
13
13
|
notifyMessageSend: (props: MessageContent) => void;
|
|
14
14
|
notifyStopGenerate: () => void;
|
|
15
|
-
notifySkillChange: (skill: BaseSkill) => void;
|
|
16
15
|
clearContent: () => void;
|
|
17
16
|
clearAttachments: () => void;
|
|
18
17
|
getRichTextDiv: () => HTMLDivElement | null;
|
|
@@ -2,7 +2,7 @@ import _isString from "lodash/isString";
|
|
|
2
2
|
import _isNumber from "lodash/isNumber";
|
|
3
3
|
import BaseFoundation from '../base/foundation';
|
|
4
4
|
import { cssClasses } from './constants';
|
|
5
|
-
import {
|
|
5
|
+
import { transformJSONResult } from './utils';
|
|
6
6
|
const prefixCls = cssClasses.PREFIX;
|
|
7
7
|
export default class AIChatInputFoundation extends BaseFoundation {
|
|
8
8
|
constructor(adapter) {
|
|
@@ -17,7 +17,6 @@ export default class AIChatInputFoundation extends BaseFoundation {
|
|
|
17
17
|
skill: skill,
|
|
18
18
|
skillVisible: false
|
|
19
19
|
});
|
|
20
|
-
this._adapter.notifySkillChange(skill);
|
|
21
20
|
this._adapter.setContent(`<skill-slot data-value="${skill.label}"></skill-slot>`);
|
|
22
21
|
this._adapter.focusEditor();
|
|
23
22
|
};
|
|
@@ -161,30 +160,19 @@ export default class AIChatInputFoundation extends BaseFoundation {
|
|
|
161
160
|
transformer
|
|
162
161
|
} = this.getProps();
|
|
163
162
|
const {
|
|
164
|
-
skill
|
|
163
|
+
skill
|
|
165
164
|
} = this.getStates();
|
|
166
165
|
const editor = this._adapter.getEditor();
|
|
166
|
+
const jsonResult = editor.getJSON();
|
|
167
|
+
const finalResult = transformJSONResult(jsonResult, transformer);
|
|
168
|
+
this._adapter.notifyContentChange(finalResult);
|
|
167
169
|
const html = editor.getHTML();
|
|
168
|
-
if (Object.keys(skill).length && !html.includes('</skill-slot>')) {
|
|
170
|
+
if (content === '' && Object.keys(skill).length && !html.includes('</skill-slot>')) {
|
|
169
171
|
this.setState({
|
|
170
|
-
skill:
|
|
172
|
+
skill: {},
|
|
171
173
|
templateVisible: false
|
|
172
174
|
});
|
|
173
|
-
this._adapter.notifySkillChange(undefined);
|
|
174
|
-
this._adapter.notifyContentChange([]);
|
|
175
|
-
return;
|
|
176
|
-
} else if (Object.keys(skill).length === 0 && html.includes('</skill-slot>')) {
|
|
177
|
-
const newSkill = findSkillSlotInString(html);
|
|
178
|
-
if ((newSkill === null || newSkill === void 0 ? void 0 : newSkill.value) !== (skill === null || skill === void 0 ? void 0 : skill.value)) {
|
|
179
|
-
this.setState({
|
|
180
|
-
skill: newSkill
|
|
181
|
-
});
|
|
182
|
-
this._adapter.notifySkillChange(newSkill);
|
|
183
|
-
}
|
|
184
175
|
}
|
|
185
|
-
const jsonResult = editor.getJSON();
|
|
186
|
-
const finalResult = transformJSONResult(jsonResult, transformer);
|
|
187
|
-
this._adapter.notifyContentChange(finalResult);
|
|
188
176
|
this.setState({
|
|
189
177
|
content: jsonResult
|
|
190
178
|
});
|
|
@@ -328,24 +316,6 @@ export default class AIChatInputFoundation extends BaseFoundation {
|
|
|
328
316
|
this.handleSend();
|
|
329
317
|
return true;
|
|
330
318
|
}
|
|
331
|
-
if (event.key === 'Enter' && event.shiftKey) {
|
|
332
|
-
/**
|
|
333
|
-
* Tiptap 默认情况下 Enter + Shift 时候是使用 <br /> 实现换行,需要通过新建 p 标签的方式换行保证
|
|
334
|
-
* 自定义的一些逻辑生效(比如零宽字符的插入),因此拦截默认操作,使用新建 p 标签方式
|
|
335
|
-
*/
|
|
336
|
-
event.preventDefault();
|
|
337
|
-
const editor = this._adapter.getEditor();
|
|
338
|
-
if (editor && editor.chain && editor.chain().splitBlock) {
|
|
339
|
-
editor.chain().focus().splitBlock().run();
|
|
340
|
-
} else if (editor && editor.view) {
|
|
341
|
-
const {
|
|
342
|
-
state,
|
|
343
|
-
view
|
|
344
|
-
} = editor;
|
|
345
|
-
view.dispatch(state.tr.split(state.selection.from));
|
|
346
|
-
}
|
|
347
|
-
return true;
|
|
348
|
-
}
|
|
349
319
|
if (event.key !== 'Backspace') return false;
|
|
350
320
|
return false;
|
|
351
321
|
};
|
|
@@ -4,10 +4,10 @@ export interface RichTextJSON {
|
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
6
6
|
export interface BaseSkill {
|
|
7
|
-
icon
|
|
8
|
-
value
|
|
9
|
-
label
|
|
10
|
-
hasTemplate
|
|
7
|
+
icon: any;
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
hasTemplate: boolean;
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
}
|
|
13
13
|
export type Suggestion = string[] | {
|
|
@@ -6,19 +6,13 @@ export declare function transformSelectSlot(obj: any): {
|
|
|
6
6
|
type: string;
|
|
7
7
|
text: any;
|
|
8
8
|
};
|
|
9
|
-
export declare function transformSkillSlot(obj: any):
|
|
10
|
-
type: any;
|
|
11
|
-
value: any;
|
|
12
|
-
};
|
|
9
|
+
export declare function transformSkillSlot(obj: any): any;
|
|
13
10
|
export declare function transformInputSlot(obj: any): {
|
|
14
11
|
type: string;
|
|
15
12
|
text: any;
|
|
16
13
|
};
|
|
17
|
-
export declare function transformText(obj: any):
|
|
18
|
-
|
|
19
|
-
text: any;
|
|
20
|
-
};
|
|
21
|
-
export declare const transformMap: Map<string, any>;
|
|
14
|
+
export declare function transformText(obj: any): any;
|
|
15
|
+
export declare const transformMap: Map<string, typeof transformText>;
|
|
22
16
|
export declare function transformJSONResult(input: any, customTransformObj?: Map<string, (obj: any) => any>): any[];
|
|
23
17
|
export declare function getCustomSlotAttribute(): {
|
|
24
18
|
default: boolean;
|
|
@@ -27,6 +21,3 @@ export declare function getCustomSlotAttribute(): {
|
|
|
27
21
|
'data-custom-slot': string;
|
|
28
22
|
};
|
|
29
23
|
};
|
|
30
|
-
export declare function findSkillSlotInString(content: string): {
|
|
31
|
-
[k: string]: any;
|
|
32
|
-
};
|
|
@@ -54,17 +54,19 @@ export function transformSelectSlot(obj) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
export function transformSkillSlot(obj) {
|
|
57
|
+
var _a;
|
|
57
58
|
const {
|
|
58
59
|
type,
|
|
59
60
|
attrs
|
|
60
61
|
} = obj;
|
|
61
62
|
const {
|
|
62
|
-
value
|
|
63
|
+
value,
|
|
64
|
+
info
|
|
63
65
|
} = attrs;
|
|
64
|
-
return {
|
|
66
|
+
return Object.assign({
|
|
65
67
|
type,
|
|
66
68
|
value
|
|
67
|
-
};
|
|
69
|
+
}, (_a = JSON.parse(info)) !== null && _a !== void 0 ? _a : {});
|
|
68
70
|
}
|
|
69
71
|
export function transformInputSlot(obj) {
|
|
70
72
|
var _a, _b;
|
|
@@ -79,15 +81,9 @@ export function transformInputSlot(obj) {
|
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
export function transformText(obj) {
|
|
82
|
-
|
|
83
|
-
text
|
|
84
|
-
} = obj;
|
|
85
|
-
return {
|
|
86
|
-
type: 'text',
|
|
87
|
-
text: text !== strings.ZERO_WIDTH_CHAR ? text : ''
|
|
88
|
-
};
|
|
84
|
+
return Object.assign({}, obj);
|
|
89
85
|
}
|
|
90
|
-
export const transformMap = new Map([['text', transformText], ['selectSlot', transformSelectSlot], ['inputSlot', transformInputSlot], ['
|
|
86
|
+
export const transformMap = new Map([['text', transformText], ['selectSlot', transformSelectSlot], ['inputSlot', transformInputSlot], ['toolSlot', transformSkillSlot]]);
|
|
91
87
|
export function transformJSONResult(input) {
|
|
92
88
|
let customTransformObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Map();
|
|
93
89
|
const output = [];
|
|
@@ -130,7 +126,7 @@ export function transformJSONResult(input) {
|
|
|
130
126
|
const lastItem = output[output.length - 1];
|
|
131
127
|
if (lastItem && lastItem.type === 'text') {
|
|
132
128
|
lastItem.text += result.text;
|
|
133
|
-
} else
|
|
129
|
+
} else {
|
|
134
130
|
output.push(result);
|
|
135
131
|
}
|
|
136
132
|
} else {
|
|
@@ -149,29 +145,4 @@ export function getCustomSlotAttribute() {
|
|
|
149
145
|
'data-custom-slot': attributes.isCustomSlot ? 'true' : undefined
|
|
150
146
|
})
|
|
151
147
|
};
|
|
152
|
-
}
|
|
153
|
-
export function findSkillSlotInString(content) {
|
|
154
|
-
const reg = /<skill-slot\s+([^>]*)><\/skill-slot>/i;
|
|
155
|
-
const attrReg = /([\w-]+)=["']?([^"'\s>]+)["']?/g;
|
|
156
|
-
const match = reg.exec(content);
|
|
157
|
-
if (match) {
|
|
158
|
-
const attrsStr = match[1];
|
|
159
|
-
let attrMatch;
|
|
160
|
-
let attrs = {};
|
|
161
|
-
while ((attrMatch = attrReg.exec(attrsStr)) !== null) {
|
|
162
|
-
attrs[attrMatch[1]] = attrMatch[2];
|
|
163
|
-
}
|
|
164
|
-
if (attrs['data-value']) {
|
|
165
|
-
const obj = {
|
|
166
|
-
label: attrs['data-label'],
|
|
167
|
-
value: attrs['data-value'],
|
|
168
|
-
hasTemplate: attrs['data-template'] ? attrs['data-template'] === 'true' : undefined
|
|
169
|
-
};
|
|
170
|
-
return Object.fromEntries(Object.entries(obj).filter(_ref => {
|
|
171
|
-
let [key, value] = _ref;
|
|
172
|
-
return value !== undefined;
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return undefined;
|
|
177
148
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.88.0-
|
|
3
|
+
"version": "2.88.0-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
7
7
|
"prepublishOnly": "npm run build:lib"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@douyinfe/semi-animation": "2.88.0-
|
|
11
|
-
"@douyinfe/semi-json-viewer-core": "2.88.0-
|
|
10
|
+
"@douyinfe/semi-animation": "2.88.0-beta.1",
|
|
11
|
+
"@douyinfe/semi-json-viewer-core": "2.88.0-beta.1",
|
|
12
12
|
"@mdx-js/mdx": "^3.0.1",
|
|
13
13
|
"async-validator": "^3.5.0",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"*.scss",
|
|
30
30
|
"*.css"
|
|
31
31
|
],
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "535d287af36ed4082c64fe4e8c65f7f2df316dad",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
35
35
|
"@babel/preset-env": "^7.15.8",
|